This post will cover some basic I/O system calls, enough to implement a game or two, other than sound support or holotape support. The holotape calls required a little more explanation, and the sound system data is more complex than for the calls covered here.
Prerequisites
Hopefully you've read the post on running code in the emulator. It describes the easiest, fastest way to get your code running.
Console Calls
In the Clear
Character I/O
The only console input system call is GETCH. It takes a byte off the stack as the blocking mode (=0 no blocking, != 0 blocking), grabs a key from the input queue and returns a 16-bit value indicating which character was pressed. If the MSB is 0 then the LSB contains the ASCII value.
There are two output calls, SETCH and PRINT. They both increment the cursor to the next character after their output is printed to screen at the current character. SETCH takes a single-byte ASCII character, whereas PRINT takes a null-terminated string starting at the location pointed to by the X register.
Cursor Control
The cursor location consists of 16-bit X and Y coordinates, within the space of the coordinate space of the text screen.
To set the cursor, call SETCURSOR with the desired X and Y coordinates on the stack. If the operation worked, the byte 0 will be on top of the stack.
To get the current position of the cursor, call GETCURSOR. The X and Y coordinates will be on the top of the stack after executing this system call.
Screen Attributes
Each character on the screen has an attribute. The current possible attributes are "dim" and "inverted." These are combined in a bit mask, where the second least-significant-bit represents the "dim" attribute, and the least-significant-bit represents "inverted."
SETATTR changes the default attribute for new characters written to screen. This does not change the attributes of any character, but any further characters will have these attributes.
SETATTRC sets the attributes on the character currently under the cursor. This does not affect the attributes of any subsequent character output.
Graphics Calls
Use GRAPHICSTART to begin a graphics session. The value in X will be used as the starting address for the framebuffer, and the byte passed on the stack will be used to set the graphics mode. See the table below for the possible values of the mode byte.
On return, the system call places a byte on the stack. If the graphics mode is available, this byte is 0. If the byte describes a non-existent mode, or the mode requires more memory than is available to the system, then the byte is non-zero.
Depths less than 8 bpp store their values packed into a byte. For example, if using the 1 bpp mode, each byte of graphics memory will contain 8 pixels.
There is currently no blitter library yet, so it's a roll-your-own situation.
Comments