In my last MSXgl update, I said I found a technique to remove 100% of the C language overhead on calling some BIOS functions.
I don't know if anyone is interested but just in case, here is the explanation. ^^
The idea is to "cast" an address with the signature of a C function so that the calling code initializes the registers properly before calling the BIOS function.
For example, the function GTSTCK
(00D5h
) which returns the status of the joystick, takes its input parameter in register A and returns its final value in register A. Among the possible function signatures, (u8(*)(u8))
uses these same registers (u8
is unsigned char
).
Thus, with this function definition...
inline u8 Bios_GetJoystickDirection(u8 port) { return ((u8(*)(u8))R_GTSTCK)(port); }
...the calling code will put the port number into A, call the GTSTCK
function, then read the result into A.
Since the function is inline, we gain C typing verification, while having zero C overhead.
Obviously, this only works with BIOS routines that use registers for which there is a C function signature. There are few of them, but by playing with the sdcccall1
and z88dk_fastcall
calling conventions, we still have some possibilities.
In the case of a z88dk_fastcall
signature you have to use a typedef
to define the signature before you can use it.
Here is a summary of all possible the combinations: