I am trying to use the sub-ROM graphical functions, specially the BLTVD, but for any "BLT" one I always get a "Syntax error in 0" or "Type mismatch in 0" or things like that.
My code for calling is this:
Header:
typedef struct { byte a; word hl, de, bc; byte f; } CpuRegisters;
Code. The calling convention is passing parameters in stack from left to right. The "callee" means the function itself restores the stack.
#define EXPTBL 0xFCC1 #define CALSLT 0x001C ; void call_bios(address routine_address, CpuRegisters *registers) __smallc __z88dkcallee; public _call_bios _call_bios: ; extract values pop bc ; ret pop iy ; IY = *registers pop ix ; IX = routine_address push bc ; ret call load_regs push iy ld iy, (EXPTBL - 1) call CALSLT pop iy call save_regs ret ; void call_subrom(address routine_address, CpuRegisters *registers) __smallc __z88dk_callee; ; wrapper for calsub public _call_subrom _call_subrom: ; extract values pop bc ; ret pop iy ; IY = *registers pop ix ; IX = routine_address push bc ; ret call load_regs push iy ; save *registers index call calsub ; copy return values pop iy ; restore *registers index call save_regs ret load_regs: ; copy values to registers ld a, (iy) ld l, (iy + 1) ld h, (iy + 2) ld e, (iy + 3) ld d, (iy + 4) ld c, (iy + 5) ld b, (iy + 6) ret save_regs: ; copy registers to memory ld (iy), a ld (iy + 1), l ld (iy + 2), h ld (iy + 3), e ld (iy + 4), d ld (iy + 5), c ld (iy + 6), b push af ; save F pop bc ld (iy + 7), c ret ; CALSUB ; ; In: IX = address of routine in MSX2 SUBROM ; AF, HL, DE, BC = parameters for the routine ; ; Out: AF, HL, DE, BC = depending on the routine ; ; Changes: IX, IY, AF', BC', DE', HL' ; ; Call MSX2 subrom from MSXDOS. Should work with all versions of MSXDOS. ; ; Notice: NMI hook will be changed. This should pose no problem as NMI is ; not supported on the MSX at all. ; ;#define CALSLT 0x001C #define NMI 0x0066 #define EXTROM 0x015f ;#define EXPTBL 0xfcc1 #define H_NMI 0xfdd6 ; calsub: exx ex af,af' ; store all registers ld hl,EXTROM push hl ld hl,0xC300 push hl ; push NOP ; JP EXTROM push ix ld hl,0x21DD push hl ; push LD IX, ld hl,0x3333 push hl ; push INC SP; INC SP ld hl,0 add hl,sp ; HL = offset of routine ld a,0xC3 ld (H_NMI),a ld (H_NMI+1),hl ; JP in NMI hook ex af,af' exx ; restore all registers ld ix,NMI ld iy,(EXPTBL-1) call CALSLT ; call NMI-hook via NMI entry in ROMBIOS ; NMI-hook will call SUBROM exx ex af,af' ; store all returned registers ld hl,10 add hl,sp ld sp,hl ; remove routine from stack ex af,af' exx ; restore all returned registers ret
I think the parameters are located properly (many times I reverse them because the little/big Endian...).
Tested with many other BIOS and sub-ROM functions, and seems to work fine. Tested with:
- Functions without parameters, like INIPLT or TOTEXT.
- Functions with parameter in A, like CHGMOD or CHGMDP.
- Functions with parameter in HL, like NRDVRM.
- Functions reading parameters from RAM, like INITXT.
All works fine.
But any graphical one don't work, tested with:
NVBXLN, NVBXFL: does nothing.
BLTMD, BLTVD: the "Syntax error 0" message.
More interesting about getting that message because I change to SC5 (with CHGMOD) before using them, so don't know how it writes it.