Using routines in the BASIC ROM

All aspects of programming on the Commander X16.
Post Reply
Martin Schmalenbach
Posts: 138
Joined: Tue Jul 21, 2020 10:08 pm

Using routines in the BASIC ROM

Post by Martin Schmalenbach »

Hi.

In the C64 BASIC2 ROM there is a routine at $A38A. It is called FNDFOR, and amongst its functions is the ability to be used to help remove the last GOSUB's return address from BASIC's stack. In BASIC2 I'd simply SYS to the address at REMGSB to call it.

Code: Select all

REMGSB  LDA #$FF
        STA $4A
        JSR $A38A
        TXS
        CMP #$8D
        BNE ERROR
        PLA
        PLA
        PLA
        PLA
        PLA
        RTS
ERROR   JMP $A8E0
The ZP variable used by C64's version of basic at $49-$4A is at $E5 in the X16 - that's a simple change, if the *.sym files that come with the emulator are correct.

But for the routines at $A38A (FNDFOR) and $A8E0 (14 bytes in from RETURN) will I instead need to use routines in the X16 BASIC ROM that reside at $C5B8 and $CC64 respectively? Again, this is based on info extracted from the *.sym files.

I'm asking because when I disassemble the BASIC ROM (Bank 4, right?) at these locations, I'm seeing quite different code...

Thanks in advance!
Ender
Posts: 220
Joined: Sat May 09, 2020 9:32 pm

Re: Using routines in the BASIC ROM

Post by Ender »

From what I can tell, looking at the file's history on github, there hasn't been a change to that function since it was first added from Michael Steil's cbm source (except to change it from upper case to lower case). So the code should be pretty much identical... Are you sure you were looking at the right bank in the disassembler (by typing "d 4c5b8")? By the way, the address is $C5C0 for me. When I look at it in the disassembler it matches what I see on github.
Martin Schmalenbach
Posts: 138
Joined: Tue Jul 21, 2020 10:08 pm

Re: Using routines in the BASIC ROM

Post by Martin Schmalenbach »

Thanks for that extra info - no, I’m not convinced I’ve been looking at the right ROM bank!

I’ll try your example with MON - I’d forgotten that you can specify the bank address when providing an address!

Cheers
Ender
Posts: 220
Joined: Sat May 09, 2020 9:32 pm

Re: Using routines in the BASIC ROM

Post by Ender »

Martin Schmalenbach wrote: Fri Jul 07, 2023 1:30 am Thanks for that extra info - no, I’m not convinced I’ve been looking at the right ROM bank!

I’ll try your example with MON - I’d forgotten that you can specify the bank address when providing an address!

Cheers
Oh, sorry, the example I gave was for using the emulator's debugger (if you run with "-debug", and then hit F12). I think with MON you have to switch to the bank with the "O" command, so "O04" followed by "D C5B8".
Martin Schmalenbach
Posts: 138
Joined: Tue Jul 21, 2020 10:08 pm

Re: Using routines in the BASIC ROM

Post by Martin Schmalenbach »

Yup - that's working - I can see it as expected - I'm getting the same results as you - thanks again for your help!
Post Reply