Page 1 of 1

Using routines in the BASIC ROM

Posted: Wed Jul 05, 2023 7:17 pm
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!

Re: Using routines in the BASIC ROM

Posted: Fri Jul 07, 2023 1:15 am
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.

Re: Using routines in the BASIC ROM

Posted: Fri Jul 07, 2023 1:30 am
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

Re: Using routines in the BASIC ROM

Posted: Fri Jul 07, 2023 1:51 am
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".

Re: Using routines in the BASIC ROM

Posted: Fri Jul 07, 2023 5:15 am
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!