gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > calling BIOS functions in C++ ... how?

#1001 - animension - Mon Jan 13, 2003 7:03 am

How does one go about calling built-in BIOS functions like SWI 6 (DIV)? Is ASM the only way to do this? And if so, how does one incorporate this into an inline form in C++ code?

Say you had a function:

unsigned short BIOS_DIVIDE(unsigned short a, unsigned short b);

How would you inline the ASM and how would you know which registers hold what value? If this needs to go into the ASM forum my apologies.

#1014 - anli - Mon Jan 13, 2003 12:27 pm

Here is an answer I was giving in the graphics forum on the question
how to call the lz decompression routines from C/C++-code.

Put this in an assembler file:

Code:

.GLOBAL LZ77UnCompVram
.GLOBAL LZ77UnCompWram
LZ77UnCompVram:
swi 18
bx lr

LZ77UnCompWram:
swi 17
bx lr


This file is assembled like this:
For arm mode:
Code:

as -marm7tdmi file.s


For thumb mode:
Code:

as -mthumb file.s


This produces a file.o.

Now add this to your C code:
Code:

extern void LZ77UnCompWram(void *src, void *dest);
extern void LZ77UnCompVram(void *src, void *dest);

Now, you have two extra functions to play with. The "V" version is
used when you are decompressing to video memory.

Dont forget to add file.o on the command line to your linker.

/anli