This the multi-page printable view of this section.Click here to print.

Return to the regular view of this page.

OS Calls

Operating System calls

Table of Contents

Unlike most manufacturers, the spectrum rom doesn't have many standard rom entry points with most of them undocumented. This meant that the addresses changed between the different machines.

For example, all 48K Spectrum's had the same ROM, so you were almost guaranteed to be able to use the same routine on different machines. However, the 128K introduced 2 roms so there had to be differences. With the +2A/+3 came 4 roms and to complicate things there exists an English and Spanish version of these roms with different addresses.

Unless otherwise specified, the entry points in this section will be for the 48K Spectrum as that has more documentation available.

The only common entry points (known so far) are the RST entry points, as these are also used by the processor's RST instruction.

Restart RST

Calculator Enter the floating point calculator
Collect Character restarts Collect Character and Collect Next Character restarts
ERROR Error restart
Make BC Spaces Creates BC free locations in the workspace
Maskable Interrupt The Maskable Interrupt Handler
PRINT_A Write A to current output channel
START Restart the machine

Issues with RST instructions

Even this isn't standardised in documentation, with some calls referenced by different numbers.

For example, the calculator is referenced as RST 5, RST 40 and RST $28 in different places even though they are identical instructions.

Address OP Code RST Instruction Action
48K 128K +2 +2A/+3
0000 C7 RST 0 Reset machine
0008 CF RST 1 RST 8 Error handler Unavailable Error handler
0010 D7 RST 2 RST $10 RST 16 Print A
0018 DF RST 3 RST $18 RST 24 Get Character
0020 E7 RST 4 RST $20 RST 32
0028 EF RST 5 RST $28 RST 40 Calculator Call ROM1 Call ROM3
0030 F7 RST 6 RST $30 RST 48 Reserve Workspace Unavailable as used by RST 5
0038 FF RST 7 RST $38 RST 56 Maskable Interrupt Handler

A 128K machine running in 48K mode will have the RST instructions as the 48K machine.

Screen

Clear the screen Clear the whole display area

OS Vector Table

On the 128K and +2 Spectrum's there is a vector table at 0x0100 to common routines.

Previously the ROM was just a single program and not an Operating System.

This table is not present on the 48K nor is it on the +2A and +3 Spectrum's
Routine Vector Table
Address Routine
128K +2
0100 BASIC interpreter parser
0103 Line Run entry point
0106 Transfer bytes to logical RAM bank 4
0109 Transfer bytes from logical RAM bank 4
010C 128K error routine
010F Error routine
0112 Return statement
0115 Next statement
0118 Scan Keyboard
011B Play music strings
011E MIDI byte output
0121 RS232 byte input
0124 RS232 text output
0127 RS232 byte output
012A COPY screen dump
012D RST 5 keypad scan routine in ROM 1

1 - Calculator

Enter the floating point calculator
Function AddressDescription
RST_5 0028FP Calculator
This entry point is only available on the 48K Spectrum.

The only way to use this on later Spectrum's is to page in the 48K ROM before making the call.

RST 5 on a 48K Spectrum enters the floating point calculator.

2 - Clear the screen

Clear the whole display area
Function AddressDescription
CL_ALL 0DAFClear the screen

This entry point is only available on the 48K Spectrum.

The only way to use this on later Spectrum's is to page in the 48K ROM before making the call.

It's advisable to write your own as noted below.

This entry point clears the screen.

Unless you need to keep compatibility with BASIC, it's better and faster to use your own routine for this. An example of how to do this is available in the examples section: Clear Screen Example

3 - Collect Character restarts

Collect Character and Collect Next Character restarts
Function AddressDescription
RST_3 0018Collect character
RST_4 0020Collect Next character

RST 3 returns the character addressed by CHADD returning it if it's printable. If it is not printable then CHADD is incremented until a printable character is found.

RST 4 increments CHADD first before returning the next printable character.

These two resets are used in multiple places in the ROM, the BASIC tokenizer being one of them.

4 - ERROR

Error restart
Function AddressDescription
RST_1 0008Report an error

RST 1 can be used to stop a program with an error

5 - Make BC Spaces

Creates BC free locations in the workspace
Function AddressDescription
RST_6 0030FP Calculator

RST 6 reserves memory in the workspace

On Entry

BC holds the number of bytes to create

On Exit

DE holds the first byte of the new free space.

HL holds the last byte of the new free space.

6 - Maskable Interrupt

The Maskable Interrupt Handler
Function AddressDescription
RST_7 0038Maskable Interrupt Handler

RST 7 is also the Maskable Interrupt handler

It increments the real time clock in the FRAMES variable once every 20ms (UK).

It also scans the keyboard.

7 - PRINT_A

Write A to current output channel
Function AddressDescription
RST_2 0010Print A to the output stream

RST 2 is usually used to write to the current channel, usually the screen.

Internally, RST 2 calls the routine in the CHURCHL vector, returning with all registers preserved unless an error occurred.

Implementing custom channels

Because the rom code uses the CHURCHL vector you can easily replace the current output channel with your own code.

My Teletext emulator does this to allow code to write to the new screen using RST 2.

8 - START

Restart the machine
Function AddressDescription
RST_0 0000Start the computer

Called when the machine is first started, RST 0 can be used to restart the machine.