2

I used to use the BRK instruction when debugging on the C64.

However, when I bank out ROM with...

lda #$35        // Bank out kernal and basic
sta $01         // $e000-$ffff

...the BRK instruction (unsurprisingly) doesn't take me to the BASIC screen anymore. I bank out ROM to free up all available CPU cycles for my raster interrupts.

What would you recommend for breaking either into the BASIC screen or into the monitor when ROM is not mapped?

I use KickAssembler and run on the VICE emulator.

2
  • 2
    What do you mean by "I bank out ROM to free up all available CPU cycles [...]"? I'm sure you get just as many cycles whether the ROMs are paged in or not. Commented May 16, 2018 at 8:32
  • Hmm, I think you’re right. The main thing I’m doing is to hook my irqs into $fffe instead of $0314 (?), ie. bypassing the rom irq handler. But I guess I don’t actually need to bank out ROM to hook into $fffe.
    – Nurpax
    Commented May 16, 2018 at 9:04

1 Answer 1

4

You can still use the BRK instruction. But the reason you're not getting to BASIC is because the KERNAL is banked out.

When the 6502 executes a BRK instruction, the processor jumps to a routine specified by an address stored inside the KERNAL ROM. If you look at addresses $FFFE-$FFFF, in the KERNAL ROM you'll find that these point to a routine. When BRK is executed, the CPU will start running that routine. So what you need to do is when the turn the KERNAL off, you need to store the address of your interrupt handler in $FFFE-$FFFF. Then when you execute BRK your interrupt handler will be the next thing to run.

But I wouldn't really recommend this approach to return to BASIC. If you are doing raster tricks or using interrupts for anything else, it can be tricky and wasteful for the interrupt handler to try and determine if it needs to return to BASIC.

To your question:

What would you recommend for breaking either into the BASIC screen or into the monitor when ROM is not mapped?

I would recommend SHIFT+RESTORE. The RESTORE key performs an NMI, so it will invoke a routine of your choosing, (which is not your interrupt handler). That routine can see if the SHIFT key is also pressed, and if so, can re-engage BASIC and KERNAL and jump to there. Of course, you can also jump to that routine under software control.

2
  • 1
    Thanks! I was unclear about the need for going back to BASIC. I'm not really after a clean exit, I was just using BRK as kind of a poor man's debugger to see what branches are taken. But looks like I can either fix BRK to not hang (as per your answer), use SHIFT-RESTORE or maybe just switch to using the break() macro from goatpower.org/projects-releases/….
    – Nurpax
    Commented May 16, 2018 at 8:23
  • 1
    In that case, since you ask what I would recommend: definitely learn how to use a decent debugger. VICE comes with a good one. It'll save you a lot of time Commented May 16, 2018 at 8:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .