Skip to main content

Emulator: System Calls

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

The CLEAR system call will remove all text and attributes from the screen, and set the cursor to top-left (0,0). 

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.

Table of System Calls

GETCH

Polls the keyboard for a key press, and returns the 16-bit value, ASCII in LSB if MSB is 0

Blocking mode

0 if no character pressed and non-blocking, otherwise the key pressed

SETCH

Prints a character at the text cursor position and increments the cursor

Character

-

PRINT

Prints a null-terminated string from X at the text cursor position and increments the cursor accordingly

Null-terminated string starting at X

-

SETCURSOR

Sets the current text cursor position

16-bit X and Y coordinates for the cursor

0 if valid

SETATTR

Sets the current text attribute flags

16-bit field for text attribute flags

-

SETATTRC

Sets the text attribute of the character under the cursor

16-bit field for text attribute flags

-

CLEAR

Clears the screen of text and attributes, and sets the cursor to 0,0

-

-

GETCURSOR

Gets the current text cursor position

-

16-bit X and Y coordinates for the cursor


GRAPHICSTART

Begins a graphics session in the provided mode, with the framebuffer at the address in X. Can be called at any time, and will override the current graphics session, if any. Can be used for double buffering or animation.

Graphics mode

0 on success, error otherwise

GRAPHICEND

Ends all graphics sessions, returning to the text display

-

-

Graphics Mode Table

Bits

Name

Possible values

6-4

Colour depth

000 = 1bpp

001 = 2bpp

010 = 4bpp

011 = 8bpp

1xx = reserved

3

Border enabled

0 = black border

1 = green border

(if applicable)

2-0

Resolution

000 = 120x80

001 = 192x128

010 = 240x160

011 = 320x240

100 = 480x320

101 = reserved

110 = reserved

111 = reserved

Comments

Popular posts from this blog

Am I Jonesing for the Internet?

I’m feeling a little agitated and jittery today. My internet access is down due to some nasty snow and wind. Are the two related? They might be. I know I’m certainly missing my twitter friends and feeling less in touch with the world. How long is this weather going to hold? I can’t look that up. Sure, I could pull out a radio and listen in, if I had one. I might somewhere, but I’m at the mercy of the broadcaster to decide when to report the weather and how much of it to report. Some argue that internet access should be a basic human right. Does this point of view hold water? I suppose it could be argued that since the internet allows us to draw together into a larger community that it is an essential part of improving the human condition. Its use in political organizing and to connect dissidents in repressive regimes can certainly help make the case for it as a basic human right. Is the jitteriness really from not having the internet? My doctor did just increase my dose of modafi

What Kind of Games?

I started programming when I was young, with the hopes of writing video games. I think a lot of kids start that way. When you like something, or someone, you try to emulate what you’re seeing. But how has that early dream turned out? They tell writers to write what they know. It’s good advice. How can you write about life in the Serengeti without have someone to give you a first hand account or having been there yourself? You can always use your imagination, and that’s all you can really do when writing fantasy or science fiction. It works for writing video games. How can you expect to write a genre you don’t immerse yourself in? These days I spend most of my gaming time playing casual games. I’m busy doing other things, and don’t want to spend long stretches just sitting at the console or computer. Recently I read an article about the kind of video games the most people tend to flock to. Typically they’re games that are relatively simple and involve sorting things in some way. It

Piet - an esoteric programming language

There’s a certain group of programmers out there that like to come up with programming languages just for the fun of it. Some of them have profanity as their names , and some are based on internet memes . Whatever the case may be, some individual out there enjoyed thinking up the language, and many of these languages are actually useable. One esoteric language that stands out, for me, at least, is Piet , created by David Morgan-Mar. Based on the idea of making programs that look like abstract art, Piet allows the programmer to express their software in the form of coloured blocks. Numbers are represented by blocks of pixels containing a pixel count equal to the number itself. Operations are performed by changes in hue or darkness. As an example, here is a Piet program I wrote to output the string “Hello World”. This image is in fact the entirety of the program, and can be run in any of the Piet interpreters out there. Other examples of Hello World programs are available on David’s si