They use registers A0-A2 and D0-D2 as scratch registers. If
you are programming in machine language and your pro
gram uses these registers, you must save their contents be
fore making a GEMDOS call and restore them after the call
terminates. Each of the GEMDOS routines is associated with
a command number, and some of the routines require com
mand parameters that specify more precisely what they
should do. For example, the GEMDOS function to write a
character to the console screen has a command number of 2.
It requires a single command parameter that tells the func
tion which character to print.
To call a GEMDOS function from machine language, you
must push the command parameters onto the stack, followed
by the command number, and execute a TRAP #1 statement.
The TRAP #1 instruction puts the program into supervisor
mode, and begins executing the instructions found at the ad
dress stored in exception vector 33, whose address is 132
($84). This exception vector contains the address of the GEM
DOS handler, which reads the command number on the top
of the stack, and directs program execution to the appropri
ate function. When the function terminates, the program re
turns to user mode, and the results, if any, are returned in
register DO. In most cases, the value is returned as a long-
word, but there are exceptions. Some error codes are re
turned as words, so it's best to test only the low-order words
when checking for errors. You should also be aware that
sometimes a GEMDOS function will return a BIOS error
number (between - 1 and -3 1 ). When a GEMDOS function
call is completed, the calling program has the responsibility
to adjust the stack in order to remove the command parame
ters and command number.
routines can be called from user mode.
237