Hello Z80 friends
I made something like this: (with help from Geco and loader.asm he provided)
PROGRAM.COM
PROGRAM.BIN
When .COM is executed, we set the screen memory to be [ 0000 - 3FFF ] and .BIN is loaded in memory like this:
# [0x4000 - 0x40FF] => 256 bytes for NOTHING!
can be used if needed
# [0x4100 - 0x4200] => 257 bytes of value 0x46 so any address in range [0x4100 - 0x41FF] will point to 0x4646
# [0x4201 - 0x4645] => 1157 bytes of free space (use for stack)
# [0x4646 - 0x4648] => 3 bytes for "JMP ABCD" instruction where ABCD is address of interrupt handler function to be set
# [0x4649 - 0x7FFF] => 14775 bytes for program
Then, jump to 0x4649 will happen and the program will do this:
- setup interrupt mode 2 and SP to align with the memory layout provided
- load EP1.BIN of size 16384 to memory [0x8000 - 0xBFFF]
- load EP2.BIN of size 4954 to memory [0xC000 - 0x....]
So basically, loader "PROGRAM.COM" loaded loader "PROGRAM.BIN" which loaded program "EP" which is split to "EP1.BIN" + "EP2.BIN"
After this, relevant memory would be:
# [0x8000 - 0x80FF] => 256 bytes for video mask table
# [0x8100 - 0x8200] => 257 bytes of value 0x86 so any address in range [0x8100 - 0x81FF] will point to 0x8686
# [0x8201 - 0x8685] => 1157 bytes of free space (use for stack)
# [0x8686 - 0x8688] => 3 bytes for "JMP ABCD" instruction where ABCD is address of interrupt handler function to be set
# [0x8689 - 0xFFFF] => 31095 bytes for program
When finally this is done, we jump to program "EP" start (0x8689) and all is executed correctly.
PROBLEM: If I add *one more byte* to "EP2.BIN" the "EP" program does not work! As if I have overwritten some part of memory which is used. (that would be ~54106 or ~0xD35A)
QUESTION: Do you have idea what might be wrong? Maybe I did not moved screen memory correctly or something with the disabling OS or something with interrupts? I really am out of my options, so anyone can help it would be great!
QUESTION: Do you have better idea? Do I need to use interrupt mode 2? I wanted to have at least 32K of main program in one continuous segment [0x8000 - 0xFFFF], 16K of screen memory [0x0000 - 0x3FFF] and 16K of swappable memory in the second block [0x4000 - 0x7FFF] => this is most important as I want to have the same logic for CPC and bankswitching on CPC is much simpler if you want to switch this block.
I could send source but it would be my last option as it involves too much and build process is just too complex (a lot of tools, scripting, cpctelera patches, ...) and it also requires external hardware to test (SF3 or RSF3), as I am actually loading EP1.BIN and EP2.BIN with SF3 from the internet...