Atari ST series Technical Reference Manual page 20

Hide thumbs Also See for ST series:
Table of Contents

Advertisement

To call a BIOS function from machine language, you
must push the command parameters onto the stack, followed
by the command number, and execute a TRAP #13 state­
ment. The TRAP #13 instruction puts the program into su­
pervisor mode and begins executing the instructions found at
the address stored in exception vector 45, whose address is
180 ($B4). This exception vector contains the address of the
BIOS handler, which reads the command number on the top
of the stack and directs program execution to the appropriate
function. When the function terminates, the program returns
to user mode, and the results, if any, are returned in register
DO. When a BIOS function call is completed, the calling pro­
gram is responsible for adjusting the stack to remove the
command parameters and command number. You should
note that the BIOS changes the command number and return
address on the stack.
The following program fragment demonstrates sending
the character X to the console device using BIOS command
number 3:
move.w
# /X/, — (sp)
move.w
# 2 , —(sp)
move.w
# 3 , — (sp)
trap
# 1 3
addq.l
#6,sp
Calling the BIOS routines from C is much simpler. Most
C compilers come with a library routine called bios(), which
stacks the parameters and executes the TRAP #13 instruc­
tion. For example, the sample call illustrated above could be
accomplished in C by the single statement
bios(3,2/X');
Since it's easier to remember a command name than a
command number, most C compilers include a header file
called OSBIND.H which defines macros for all of the BIOS
functions. For example, the macro definition for BIOS com­
mand 3 is
#defme Bconout(a,b)
Therefore, after you #include OSBINDS.H in your pro­
gram, call your sample function like this:
Bconout(2,'X');
12
CHAPTER 2
* push character value on stack
* push console device number on stack
* push BIOS command number on stack
* call BIOS handler
* pop parameters (6 bytes) off stack
bios(3,a,b)

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents