diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 5f45b2e..d629735 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -40,6 +40,9 @@ void *gint_stack_top = NULL; /* kinit(): Install and start gint */ void kinit(void) { + /* Figure out which CASIOWIN API to use based on the OS type. */ + gint_set_CASIOWIN_API(0); + #if GINT_HW_FX /* On fx-9860G, VBR is loaded at the end of the user RAM. On SH4, the end of the user RAM hosts the stack, for which we leave 12 kB diff --git a/src/kernel/kernel.h b/src/kernel/kernel.h index 3efc8cb..a5b5952 100644 --- a/src/kernel/kernel.h +++ b/src/kernel/kernel.h @@ -18,4 +18,7 @@ void kinit(void); /* kquit(): Quit gint and give back control to the system */ void kquit(void); +/* Select the CASIOWIN API for syscalls. */ +void gint_set_CASIOWIN_API(int API); + #endif /* GINT_CORE_KERNEL */ diff --git a/src/kernel/osmenu.c b/src/kernel/osmenu.c index ea503cd..22afa1a 100644 --- a/src/kernel/osmenu.c +++ b/src/kernel/osmenu.c @@ -122,11 +122,6 @@ void gint_osmenu_native(void) } #endif - /* Mysteriously crashes when coming back; might be useful another time - instead of GetKeyWait() - int C=0x04, R=0x09; - __SpecialMatrixCodeProcessing(&C, &R); */ - __osmenu_id = __Timer_Install(0, __osmenu_handler, 0 /* ms */); if(__osmenu_id <= 0) return; __Timer_Start(__osmenu_id); diff --git a/src/kernel/syscalls.S b/src/kernel/syscalls.S index 387e18f..4c819c7 100644 --- a/src/kernel/syscalls.S +++ b/src/kernel/syscalls.S @@ -144,82 +144,107 @@ syscall_table: #endif /* GINT_OS_FX */ #if GINT_OS_CG +#define CASIOWIN_API_VERSIONS 2 +.global _gint_set_CASIOWIN_API -/* Dynamic allocation */ +/* System for dynamically selecting between the syscall and fixed version of + each function based on the OS version. + @r0: Internal function ID (from table below) */ +_CASIOWIN_call: + mov #(4*CASIOWIN_API_VERSIONS), r1 + mulu.w r0, r1 + mov.l 3f, r0 + mov.l @r0, r2 + sts macl, r1 -___malloc: - syscall(0x1f44) -___free: - syscall(0x1f42) -___realloc: - syscall(0x1f46) + /* API version 0 is the normal syscall table */ + tst r2, r2 + mova .CASIOWIN_TABLE, r0 + bt.s 1f + mov.l @(r0, r1), r0 -/* BFile driver */ + /* Other API versions are the direct calls */ + jmp @r0 + nop -_BFile_Remove: - syscall(0x1db4) -_BFile_Rename: - syscall(0x1db3) -_BFile_Create: - syscall(0x1dae) -_BFile_Open: - mov #0, r6 - syscall(0x1da3) -_BFile_Close: - syscall(0x1da4) -_BFile_Size: - syscall(0x1da6) -_BFile_Seek: - syscall(0x1da9) -_BFile_GetPos: - syscall(0x1dab) -_BFile_Write: - syscall(0x1daf) -_BFile_Read: - syscall(0x1dac) -_BFile_FindFirst: - syscall(0x1db6) -_BFile_FindNext: - syscall(0x1db8) -_BFile_FindClose: - syscall(0x1dba) +1: mov.l 2f, r1 + jmp @r1 + nop -/* Return to menu */ +2: .long 0x80020070 -___Timer_Install: - syscall(0x8d9) -___Timer_Start: - syscall(0x8db) -___Timer_Stop: - syscall(0x8dc) -___Timer_Deinstall: - syscall(0x8da) -___PutKeyCode: - syscall(0x12c6) -___GetKeyWait: - syscall(0x12bf) -___ClearKeyBuffer: - syscall(0x12c7) -___GetVRAMAddress: - syscall(0x1e6) -___ConfigureStatusArea: - syscall(0x2b7) -___SetQuitHandler: - syscall(0x1e6e) +_gint_set_CASIOWIN_API: + mov.l 3f, r0 + rts + mov.l r4, @r0 -.global ___SpecialMatrixCodeProcessing -___SpecialMatrixCodeProcessing: - syscall(0x1e60) +.balign 4 +3: .long .CASIOWIN_API -/* Reset */ +.CASIOWIN_TABLE: + .long 0x1f44, 0x00000000 /* malloc */ + .long 0x1f42, 0x00000000 /* free */ + .long 0x1f46, 0x00000000 /* realloc */ + .long 0x1db4, 0x00000000 /* BFile_Remove */ + .long 0x1db3, 0x00000000 /* BFile_Rename */ + .long 0x1dae, 0x00000000 /* BFile_Create */ + .long 0x1da3, 0x00000000 /* BFile_Open */ + .long 0x1da4, 0x00000000 /* BFile_Close */ + .long 0x1da6, 0x00000000 /* BFile_Size */ + .long 0x1da9, 0x00000000 /* BFile_Seek */ + .long 0x1dab, 0x00000000 /* BFile_GetPos */ + .long 0x1daf, 0x00000000 /* BFile_Write */ + .long 0x1dac, 0x00000000 /* BFile_Read */ + .long 0x1db6, 0x00000000 /* BFile_FindFirst */ + .long 0x1db8, 0x00000000 /* BFile_FindNext */ + .long 0x1dba, 0x00000000 /* BFile_FindClose */ + .long 0x08d9, 0x00000000 /* Timer_Install */ + .long 0x08db, 0x00000000 /* Timer_Start */ + .long 0x08dc, 0x00000000 /* Timer_Stop */ + .long 0x08da, 0x00000000 /* Timer_Deinstall */ + .long 0x12c6, 0x00000000 /* PutKeyCode */ + .long 0x12bf, 0x00000000 /* GetKeyWait */ + .long 0x12c7, 0x00000000 /* ClearKeyBuffer */ + .long 0x01e6, 0x00000000 /* GetVRAMAddress */ + .long 0x02b7, 0x00000000 /* ConfigureStatusArea */ + .long 0x1e6e, 0x00000000 /* SetQuitHandler */ + .long 0x1839, 0x00000000 /* PowerOff */ + .long 0x1187, 0x00000000 /* Reset */ -___PowerOff: - syscall(0x1839) -___Reset: - syscall(0x1187) +#define casiowin_call(id) bra _CASIOWIN_call; mov id, r0 -syscall_table: - .long 0x80020070 +___malloc: casiowin_call(#0) +___free: casiowin_call(#1) +___realloc: casiowin_call(#2) +_BFile_Remove: casiowin_call(#3) +_BFile_Rename: casiowin_call(#4) +_BFile_Create: casiowin_call(#5) +_BFile_Open: mov #0, r6; casiowin_call(#6) +_BFile_Close: casiowin_call(#7) +_BFile_Size: casiowin_call(#8) +_BFile_Seek: casiowin_call(#9) +_BFile_GetPos: casiowin_call(#10) +_BFile_Write: casiowin_call(#11) +_BFile_Read: casiowin_call(#12) +_BFile_FindFirst: casiowin_call(#13) +_BFile_FindNext: casiowin_call(#14) +_BFile_FindClose: casiowin_call(#15) +___Timer_Install: casiowin_call(#16) +___Timer_Start: casiowin_call(#17) +___Timer_Stop: casiowin_call(#18) +___Timer_Deinstall: casiowin_call(#19) +___PutKeyCode: casiowin_call(#20) +___GetKeyWait: casiowin_call(#21) +___ClearKeyBuffer: casiowin_call(#22) +___GetVRAMAddress: casiowin_call(#23) +___ConfigureStatusArea: casiowin_call(#24) +___SetQuitHandler: casiowin_call(#25) +___PowerOff: casiowin_call(#26) +___Reset: casiowin_call(#27) + +.data +.CASIOWIN_API: + .long 0 #endif /* GINT_OS_CG */