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

Living with Bipolar Disorder

Feeling down when something bad happens is normal. Feeling elated when something good happens is great. Bipolar disorder is neither. Previously referred to as manic depressive disorder, bipolar disorder consists of mood episodes ranging from deep, dark depression to the sense of invincibility and superiority that is characteristic of a manic phase. It disrupts the lives of those who suffer from it and all those around them. Luckily, however, with the right course of treatment it can be kept under control. Bipolar disorder has been found to be linked genetically and physiologically to schizophrenia. A person suffering from bipolar disorder can experience the same sort of hallucinations and delusions as someone with schizophrenia. Both have a genetic component, with a number of genes interacting to create a pre-disposition to these disorders. The families of those afflicted often include others with one of these disorders, mood disorders or alcoholism. Depression is a common symptom ...

Losing a loved one, as an atheist

When I was around 11 or 12, I started to question the received wisdom that there was a deity. I came to the conclusion that all signs pointed to no. Do I outright, unequivocally and without reservation deny the existence of such an entity? No. However, I don’t see it as a likely scenario, and until I’m presented with hard evidence, I have enough reason to say that there isn’t. Some people take comfort in their religious beliefs, especially their belief in an afterlife. I have no interest in an afterlife, either for myself of my loved ones. In the past five years I’ve lost both my grandmother and mother, both of whom I loved dearly. No amount of belief in an afterlife would soothe my pain. I mourn at the fact that they are lost from my life, right here, right now. I imagine it’s the same even for those who believe that the dead pass on to somewhere else. You can’t escape the fact that their tangible presence is forever gone from your life. Unless you believe in ghosts, but that’s a ...

If I Grow Up

I’ve figured out what I want to be if I grow up: a writer. In fact, by writing this I’m living the dream, aren’t I? I guess things have been building up to this my whole life; I’ve been reading since I could, and writing even when I didn’t have to. Whatever my mood has been, as long as it wasn’t too severe, I’ve always written. When I was down, I wrote depressing poetry or prose. When I was up, I wrote whatever popped into my head. Now that I’m stable, I can take the time to write coherent, sensible articles. What are you going to write? It’s a good question, and I like it quite a bit. I’m going to write articles here, like the ones I’ve written so far. I’m going to write for HandmadeNews.org , with my first article there out just recently. I’ll always be writing emails. Sometimes I’ll write things down in my notebooks. If I feel like my writing is worthy of it, I might write a screenplay Josh Olson would enjoy reading. I wont bring it to him to read, though. If it’s good enough ...