I compile a bloadable .bin file with SDCC. After the bload"",r basic command, the program boots on page 2, then it mounts ram on all 4 pages and hooks directly 38h address (for interrupts).
Then, every time it needs to read from disk, it mounts disk rom on page 1 and calls 4010H. Results are:
- when it reads data from disk to page 2 it works fine.
- when it reads data from disk to page 3 it works fine unless it doesn't overwrite the stack and the memory beyond the stack.
- when it reads data from disk to page 0 the application crashes (even if it doesn't touch the interrupts hook area).
- when i relocate the stack in order to gain a few memory, the application always crashes, no matter where i read data and where i relocate the stack.
I suspect disk rom relies somehow on main bios and its environment, however, does anyone know something more? Unfortunatly i could not find anything about eventual constraints.
This is the routine i use, it does need 3 global variables to be set:
unsigned short start_sector;
unsigned char number_of_sectors;
unsigned short memory_address;
The routine:
__asm__ ("push af"); __asm__ ("push bc"); __asm__ ("push de"); // stack registers
__asm__ ("push hl"); __asm__ ("push ix"); __asm__ ("push iy"); // otherwise it won't work
__asm__ ("ld hl,(_start_sector)"); __asm__ ("ld d,h"); __asm__ ("ld e,l");
__asm__ ("ld hl,(_memory_address)");
__asm__ ("ld a,(_number_of_sectors)"); __asm__ ("ld b,a");
__asm__ ("ld a,#249"); __asm__ ("ld c,a"); // 248 for 360 kb disk
__asm__ ("ld a,#0"); __asm__ ("neg");
__asm__ ("call #16400");
__asm__ ("pop iy"); __asm__ ("pop ix"); __asm__ ("pop hl");
__asm__ ("pop de"); __asm__ ("pop bc"); __asm__ ("pop af");