Hi all,
I've been struggling for a couple of weeks now with the CBM API "loadfile" located at address $FFD5 ... I got some of it working, but the API seems to do some weird things, or it's me, or it's the compiler, or it's the emulator.
So I decided to make a demo program, that you can try out, and follow the below to simulate the issue ...
The program loads a TEXT file, reads it into banked memory (A000). The file contains the words "HELLO WORLD", and a 0x00 hex to end properly the string. This file is read using the cbm_k_load routine which is implemented in assembler.
The issue that I'm having is, I cannot seem to debug the rom of the x16. In one of my more complicated programs, the load file api seems to fail with error code 4, (file not found), but only when i have a lot of code added.
So, i wanted to debug the rom and see what is the issue, but that does not seem to work properly. So who can help out?
Please find the attached files load.prg, TEXT. Put those in a folder, and start the X16 emulator from that folder using x16emu -prg load.prg -run -debug. I've also added the source code files for reference: load.c and load.asm.
When you run the program, it will immediately jump into the debugger of the CX16, because in the call to the
char status = cx16_LoadFileBanked(8, "TEXT", loadtext)
routine, it will call the cbm_k_load routing, which has a STP opcode has been placed that makes the assembly break and boot up the debugger. (look at the .byte $db !).
char cbm_k_load(char* address, char verify) {
char status;
asm {
//LOAD. Load or verify file. (Must call SETLFS and SETNAM beforehands.)
// Input: A: 0 = Load, 1-255 = Verify; X/Y = Load address (if secondary address = 0).
// Output: Carry: 0 = No errors, 1 = Error; A = KERNAL error code (if Carry = 1); X/Y = Address of last byte loaded/verified (if Carry = 0).
.byte $db
ldx address
ldy address+1
lda verify
jsr $ffd5
bcs error
lda #$ff
error:
sta status
}
return status;
}
Anyway, so when the program executes, you get this display:
As you can see, the disassembly in the x16 monitor matches the assembly statements of the cbm_k_load routine nicely! Now we will try to debug the ROM API of the CX16, that loads the file ...
Using the X16 monitor, we will walk the assembler. We use F11 only, so this will make the JSR and JMP routines to follow and "jump into" each routine. Press F11 x 3 times. Now we get the following situation:
We are right at the verge to call the "load file" API of the CBM kernal architecture. Let's do that, and jump "into" this JSR routine. Now you get this:
You can see, we've landed at address 00:FFD5, which contains a vector jump to the actual routine that implements this load file. So here, we would expect to jump to address $D949.
Before we do that, let's first inspect what assembly is at address $D949! This is done using the x16 monitor command d $d949. Which seems to work nicely. We get the following result, but note that the program counter (PC) is still at FFD5!
This disassembly matches very nice the ROM code that is programmed in the X16 ROM, which is located here:
x16-rom/load.s at master · commanderx16/x16-rom (github.com)
The disassemly shows the statements starting from the loadsp label in the assembly source code of the x16-rom load.s routine:
...
Now comes the weird thing!
Now, we will step "into" the JMP statement, so we will follow the disassembly to routine D949! This does strange things in the X16 monitor, don't understand... We get this:
tax ???? Where's the code? Where are the routines?
So my question is: How can we debug ROM code of the X16?
Would somebody be able to try and do the same, who has a solution to allow to debug the ROM of the X16?
Sven