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

Return to the regular view of this page.

Sinclair ZX Spectrum OS

Notes about the Sinclair ZX Spectrum operating system & memory

CC BY-SA

Peter Mount, Area51.dev & Contributors

Sinclair ZX Spectrum OS

Notes about the Sinclair ZX Spectrum operating system & memory

TitleSinclair ZX Spectrum OS
SubtitleNotes about the Sinclair ZX Spectrum operating system & memory
AuthorPeter Mount, Area51.dev & Contributors
CopyrightCC BY-SA

CC BY-SA version 4.0 license

You are free to:

  1. Share — copy and redistribute the material in any medium or format
  2. Adapt — remix, transform, and build upon the material or any purpose, even commercially.

This license is acceptable for Free Cultural Works.

The licensor cannot revoke these freedoms as long as you follow the license terms.

Under the following terms:

  1. Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  2. ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
  3. No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.

Notices:

You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation.

No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material.

You can read the full license here: https://creativecommons.org/licenses/by-sa/4.0/

Table of Contents

1 - Spectrum Memory Map Overview

Spectrum Memory Map

The following table is an overview of the Spectrum Memory map for both 48K and 128K/+2 machines. The +2A and +3 are similar to the 128K but have additional ROM's and alternate all RAM memory layouts. The specifics for the individual machines are listed in their own sections.

Address 48K 128K / +2
0000 ROM ROM 0
128K Editor
ROM 1
48K Editor
1000
2000
3000
4000 Screen RAM Bank 5
5000 OS vars & free memory
6000
7000
8000 free memory RAM Bank 2
9000
A000
B000
C000 RAM Bank 0 RAM Bank 1 RAM Bank 2 RAM Bank 3 RAM Bank 4 RAM Bank 5
Screen #1
RAM Bank 6 RAM Bank 7
Screen #2
D000
E000
F000

Memory Contention

Some memory is contended with the ULA, with the latter having priority whenever the screen is being updated. Time critical code needs to run in uncontended RAM.

On the 48K memory between 0x4000…0x7FFF is contended with the ULS whilst 0x8000…0xFFFF is not.

On the 128K and +2, odd numbered RAM banks are contended with the ULA. Time critical code should run in even numbered RAM banks.

1.1 - Spectrum +2A/+3 Memory Map

Spectrum +2A/+3 Memory Map

The memory of the +2A and +3 are similar to the 128K and +2. The main difference is that these models have four ROMs rather than two and additional memory configurations.

The memory is paged by writing to port 0x7FFD and port 0x1FFD. Port 0x7FFD is almost identical to the 128 except that ROM is now the lower bit.

Both of these ports are write only, so a copy is stored in ram at address 0x5B5C for 7FFD and 0x5B67 for port 1FFD.

Port 7 6 5 4 3 2 1 0 Ram Copy
1FFD Printer
Strobe
Disk
Motor
1ROM 0 5B67
Memory Mode 1
7FFD DIS 0ROM SCR RAM 5B5C

Plus 3

On the Plus 3 ram bankes 1, 3, 4 and 6 are used for the disk cache and RAM disk. Bank 7 contains the editor scratch pads and +3DOS workspace.

1.2 - Spectrum 128K/+2 Memory Map

Spectrum 128K/+2 Memory Map

The memory of the 128K and +2 is organised like below. Note the +2A and +3 are different.

0000
3FFF
ROM 0
128k Editor
ROM 1
48K Basic
4000
7FFF
Bank 5
Screen #1
8000
BFFF
Bank 2
 
C000
FFFF
Bank 0
 
Bank 1
 
Bank 2
 
Bank 3
 
Bank 4
 
Bank 5
Screen #1
Bank 6
 
Bank 7
Screen #2

RAM Banks 1, 3, 4 and 6 and most of 7 are used for the ram disk. The rest of bank 7 contains editor scratch pads.

The memory is paged by writing to port 0x7FFD.

This port is write only, so a copy is stored in ram at address 0x5B5C.

Port 7 6 5 4 3 2 1 0 Ram Copy
7FFD DIS ROM SCR RAM 5B5C
Typical bank switch on a 128:
LDA,(0x5B5C)Get previous port value
AND0xF8
OR4Select bank 4
LDBC,0x7FFDPort address
DIDisable interrupts
LD(0x5B5C),AUpdate memory copy of port
OUT(C),A
EIEnable interrupts

Notes:

  1. Odd ram banks are contended with the ULA (even though it can only use banks 5 and 7).
  2. Even banks are not contended so time critical code should run within those banks.
  3. Bank 5 is always mapped at 4000 and Bank 2 at 8000 regardless of what bank is mapped at C000
  4. Selecting the alternate screen in Bank 7 only tells the ULA to use it. It will not be placed at 4000

1.3 - Spectrum 48K Memory Map

Spectrum 48K Memory Map
Address Content
0x0000 ROM
0x4000 Screen Memory Contended RAM
0x5800 Screen Colour data
0x5B00 Printer buffer
0x5C00 System Variables
0x5CC0 Reserved
0x5CCB Available Memory
0x8000 Un-Contended RAM
0xA000
0xC000
0xE000
0xFF58 Reserved
0xFFFF

1.4 - Spectrum Basic Memory Map

Spectrum Basic Memory Map

The following table shows the memory map of the Spectrum as seen by BASIC.

Address 48K 128K
4000 Display File
5800 Display Attributes
5B00 Printer Buffer
5C00 System variables
5CB6
CHANS
Channel Information
PROG 0x80h
Basic Program
VARS Variables
0x80h
Command or program line being edited
NL
0x80h
WORKSP INPUT data
NL
Temporary workspace
STKBOT Calculator stack
STKEND
Spare
SP Machine stack
  Gosub stack
RAMTOP
0x3E
UDG User defined graphics
PRAMT

2 - OS Calls

Operating System calls

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

2.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.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

2.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.

2.4 - ERROR

Error restart
Function AddressDescription
RST_1 0008Report an error

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

2.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.

2.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.

2.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.

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.

3 - Screen

The Spectrum’s screen memory layout

Screen Layout

The screen has a fixed resolution of 256x192 pixels or 32x24 characters. Colour is restricted to 8x8 pixel squares equivalent to each character.

It is located in memory at address 0x4000…0x5AFF and is split into two parts:

Address Name Content
4000 DISPLAYFILE Screen Memory
57FF
5800 DISPLAYATTR Screen Colour data
5AFF

128K Spectrum's

The 128K Spectrum's have a second screen in RAM Bank #7 which can be used as an alternate to the default one which is in RAM Bank #5. The memory layout is the same except for where it appears in the memory map.

This section will refer to the default memory location as used by all Spectrum's.

If you want to use the alternate screen then you need to change the base address to that of the correct bank. These are shown in the memory map's:

3.1 - Display File

The display pixel format
AddressLenNameDescription
40006144DISPLAYFILEThe start of the standard Spectrum's standard screen

The display file contains the pixel data for the screen.

Arranged in a map of 192 rows, each 32 bytes long. Each byte contains 8 pixels.

Be aware, the rows are not stored linearly, but in a way that has been optimised for the ULA.

The first 256 bytes in memory represents the first byte of each character in the first 8 rows, then the second byte of each character, and so on. Once the first 8 rows have been done it repeats twice more for the next 8 rows then the last 8.

Although the memory map for the spectrum screen seems weird with its layout, it's actually pretty logical. You can tell this weirdness is down to how the ULA works internally.

Calculating the characters address

If you have:

then you can calculate the address using the following table:

Screen Address
MSB LSB
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 1 0 R4 R3 N2 N1 N0 R2 R1 R0 C4 C3 C2 C1 C0

The formula is simple: $$ Address = \left( \overbrace{ ( 0x40 | ( R \And 0x18 ) | N ) }^{MSB} \ll 8 \right) | \left( \overbrace{ ( ( R \And 0x07) \ll 5 ) | C }^{LSB} \right) $$

Pseudo code:
1lsb := ((R << 5) AND 0xC0) OR C
2msb := 0x40 OR (R AND 0x18) OR N
Machine Code:

An example routine in Z80 Machine Code for this calculation is available to download.

Addresses of bytes within the same character

If you calculate the address of the top row of the character (i.e. N=0) then, when rendering the character to the screen you just need to increment the upper byte of the address.

This works as the lower 3 bits of the upper byte represent the row for the character.

The adjacent table shows the addresses for each row of the first 5 characters on row 0 of the screen.

Char Row Address
Char 0 Char 1 Char 2 Char 3 Char 4
0 4000 4001 4002 4003 4004
1 4100 4101 4102 4103 4104
2 4200 4201 4202 4203 4204
3 4300 4301 4302 4303 4304
4 4400 4401 4402 4403 4404
5 4500 4501 4502 4503 4504
6 4600 4601 4602 4603 4604
7 4700 4701 4702 4703 4704

Get address of the next character

You can get the address of the next character simply by adding one to the lower byte of the address. Be careful however when wrapping around the end of the line as, after the first 8 lines the address will fail.

Ideally you should calculate the address again at the start of each line.

This might explain why the original spectrum editor was 8 lines long, as you only needed to set the high byte to an appropriate 8-line block in memory and set the low byte to the offset in the line being edited to get that characters screen address.

A simple 256 character editor

As mentioned above, you could use one third of the screen as a simple editor which is capable of displaying 256 characters.

Address MSB Rows Screen position
4000 0x40 0 7 Top third
4800 0x48 8 15 Middle third
5000 0x50 16 23 Bottom third

As long as you restrict yourself to one third of the screen you can simply calculate the address within this simple editor by selecting the high byte for the required section of the screen and use the characters position in the line as the low byte.

3.2 - Display Attributes

The display attributes specifying colour information
AddressLenNameDescription
5800768DISPLAYATTRThe display attributes holding colour information

The display attribute section contains the colour information and occupies addresses 0x5800…0x5AFF.

It's a direct map of the characters on the screen, arranged in 24 rows, each 32 characters long. Each byte consists of the Foreground (INK) and Background (PAPER) colour for all pixels contained within the equivalent position in the Display File.

4 - System Variables

System variables
Function AddressDescription
SWAP 5B00Paging subroutine
STOO 5B10Paging subroutine. Entered with interrupts disabled and AF, BC on the stack.
YOUNGER 5B21Paging subroutine
REGNUOY 5B2APaging subroutine
ONERR 5B3APaging subroutine
RAMRST 5B5DRST 8 instruction used by ROM 1 to report old errors to ROM 3
AddressLenNameDescriptionDefault
5B522OLDHLTemp store while switching roms
5B542OLDBCTemp store while switching roms
5B562OLDAFTemp store while switching roms
5B582TARGETSubroutine address in ROM 3
5B5A2RETADDRReturn address in ROM1
5B5C1BANKMCopy last byte output to Port 7FFD
5B5E1RAMERRError passed from ROM 1 to 3 via RAMRST. Also used by SAVE/LOAD as temp drive store
5B5F2BAUDRS232 bit period in T states/26. Set by FORMAT LINE
5B612SERFLSecond-character-received flag & data
5B631COLCurrent column from 1 to width
5B641WIDTHPaper column width80
5B651TVPARSNumber of inline parameters expected by RS232
5B661FLAGS3Various Flags
Bit 2 Set when tokens are expanded on printing
Bit 3 Set if print output is RS232
Bit 4 Set if a disk interface is present
Bit 5 Set if drive B: is present
5B671BANK678Copy of last byte output to port 1FFD
5B681XLOCHold X location when using the unexpanded COPY command
5B691YLOCHold Y location when using the unexpanded COPY command
5B6A2OLDSPOld SP (stack pointer) when TSTACK is in use.
5B6C2SYNRETReturn address for ONERR
5B6E5LASTTVLast value printed by calculator
5B732RCLINECurrent line being renumbered
5B752RCSTARTStarting line number for renumbering10
5B772RCSTEPIncremental value for renumbering10
5B791LODDRVDrive for LOAD VERIFY or MERGE
A Drive A
B Drive B
M Ram Disk
T For tape
5B7A1SAVDRVDrive for SAVE
A Drive A
B Drive B
M Ram Disk
T For tape
5B7B1DUMPLFHolds the number of 1/216ths user for line feeds in 'COPY EXP'. If a dump cannot fit A4 set to 8 to reduce size of dump.9
5B7C8STRIP1Stripe 1 bitmap
5B848STRIP2Strip2 2 bitmap. Extends to 5B8B
5BFF-115TSTACKTemp stack (Grows DOWN from here). Used when Page 7 is switched in at top of memory while editing or using +3DOS. It can grow down to STRIP1 safely giving 115 bytes
5C008KSTATEUsed for reading keyboard
5C081LASTKStores newly pressed key
5C091REPDELTime in 1/50s before key repeats35
5C0A1REPPERDelay in 1/50s between key repeats5
5C0D1KDATAStores 2nd byte of colour controls entered from keyboard
5C0E2TVDATAStores bytes of colour, AT and TAB controls going to TV
5C1038STRMSAddresses of channels attached to streams
5C362CHARS256 less than address of character set starting with space and up to (C).
5C381RASPLength of warning buzz
5C391PIPLength of keyboard click
5C3A1ERRNR1 less than report code. Starts at 255 for -1
5C3B1FLAGSVarious flags for BASIC
5C3C1TVFLAGFlags associated with the TV
5C3D2ERRSPAddress of item on machine stack to be used as error return
5C3F2LISTSPAddress of return address from automatic listing
5C411MODESpecifies K, L, C, E or G cursor
5C422NEWPPCLine to be jumped to
5C441NSPPCStatement number in line to be jumped to. Poking first NEWPPC then NSPPC forces a jump to a specific statement in a line.
5C452PPCLine number of statement currently being executed
5C471SUBPPCNumber within line of statement currently being executed
5C481BORDCRBorder colour multiplied by 8; also contains attributes normally used for lower half of the screen
5C492EPPCNumber of current line (with program cursor)
5C4B2VARSAddress of variables
5C4D2DESTAddress of variable in assignment
5C4F2CHANSAddress of channel data
5C512CHURCHLAddress of information currently being used for IO
5C532PROGAddress of BASIC program
5C552NXTLINAddress of next line in program
5C572DATADDAddress of terminator of last DATA item
5C592ELINEAddress of command being typed in
5C5B2KCURAddress of cursor
5C5D2CHADDAddress of next character after the argument of PEEK or the NEWLINE at the end of a POKE statement.
5C5F2XPTRAddress of character after the [] marker
5C612WORKSPAddress of temporary workspace
5C632STKBOTAddress of bottom of calculator stack
5C652STKENDAddress of start of space space
5C671BREGCalculators B register
5C682MEMAddress of area used for calculators memory, usually MEMBOTMEMBOT
5C6A1FLAGS2More flags
Bit 3 Set when CAPS SHIFT or CAPS LOCK is on
5C6B1DFSZNumber of lines (including one blank) in lower part of the screen
5C6C2STOPNumber of the top program line in automatic listings
5C6E2OLDPPCLine number to which CONTINUE jumps
5C701OSPPCNumber within line of statement to which CONTINUE jumps
5C711FLAGXVarious flags
5C722STRLENLength of string type destination in assignment
5C742TADDRAddress of next item in syntax table
5C762SEEDThe seed for the RNG. Variable set using RANDOMIZE
5C783FRAMES3 byte (least significant first) frame counter incremented every 20ms
5C7B2UDGAddress of first user defined graphic
5C7D1COORDXX coordinate of last point plotted
5C7E1COORDYY coordinate of last point plotted
5C7F1PPOSN33 column number of printer position
5C802PRCCFull address of next position for LPRINT. Only used for ZX printer, not in 128K mode.
5C822ECHOE33 column number & 24 line number of end of input buffer
5C842DFCCAddress in display file of PRINT position
5C862DFCCLLike DFCC but for lower part of screen
5C882SPOSN33 col & 24 line number for PRINT position
5C8A2SPOSNLLike SPOSN but for lower part of screen
5C8C1SCRCTCounts scrolls, always 1 more than number of scrolls to perform before scroll.
5C8D1ATTRPPermanent current colours
5C8E1MASKPUsed for transparent colour. Any bit that is 1 shows bit taken from screen and not ATTRP
5C8F1ATTRTLike ATTRP but for temporary colours
5C901MASKTLike MASKP but for temporary colours
5C911PFLAGMore flags
5C9230MEMBOTCalculators memory area used to store numbers not convenient to store on the calculator stack
5CB02NMIADDAddress of users NMI routine. Older machines NMI didn't work well so was marked as UNUSED so can cause issues on +3 if user code uses this
5CB22RAMTOPAddress of last byte of BASIC system area
5CB42PRAMTAddress of last byte of physical RAM
5CB6SYSVARENDStart of Channel information, usually value in (CHANS)
5CC012RESERVED_MMAPMarked reserved in 48k memory map
5CCBBASE_AVAIL_MEMBase of available memory

Notes:

  1. Variables between 5B00 and 5BFF are new to 128k & +3. On 48K it is the printer buffer & sometimes used for code but will break newer machines.
  2. Last variable is at 5CB4 so from 5CB6 up is free according to +3 docs but 48k docs don't show that
  3. 5CC0 to 5CCA is marked as reserved in some 48K docs
  4. 48K memory maps show 5CCB as start of memory

5 - Basic

Notes on BASIC for the Spectrum

5.1 - Basic Tokens

Tokens used to store BASIC programs in memory
NameValueDescription
BAS_CODE175CODE
BAS_CLEAR253CLEAR statement
BAS_LOAD239LOAD statement
BAS_PRINT245PRINT statement
BAS_RANDOMIZE249RANDOMIZE statement
BAS_USR192USR function

BASIC Tokens

This table is currently incomplete, but it is enough for the Machine Code examples.

6 - +3 DOS

Notes on the Disk Operating System for the Plus 3

+3DOS is the Disk Operating System of the Spectrum +3. It is contained in ROM 2 on those machines and provides support for:

Spectrum +2A

The +2A (not the +2) has the exact same ROM's as the +3, it just has a Cassette tape instead of a 3" floppy drive. As such, +3DOS is available but only provides:

Another method to determine if a machine is a +3 or a +2A is to inspect bit 4 of FLAGS3 (0x5B66). If the bit is set then a disk interface is present, hence a +3. If the bit is reset then no disk is present, hence a +2A or a +3 with no disk interface or the interface disabled.

CP/M File compatibility

+3DOS uses the CP/M file structure, subject to the following restrictions:

6.1 - Essential API

+3DOS Essential API

6.1.1 - DOS_INITIALISE

Initialise +3DOS
Function AddressDescription
DOS_INITIALISE 0100Initialise +3DOS

Synopsys

Entry Parameters

None

Exit Parameters

If OK:
Carry true
A corrupt
Otherwise:
Carry false
A=Error code
Always:
BC DE HL IX corrupt, all other registers preserved.

6.1.2 - DOS_VERSION

Get the DOS issue and version numbers
Function AddressDescription
DOS_VERSION 0103Return DOS issue and version numbers

Synopsys

Get the DOS issue and version numbers.

Entry Parameters

None

Exit Parameters

If OK:
D = Issue
E = Version (within issue)
Otherwise:
Carry false
A=Error code
Always:
BC DE HL IX corrupt, all other registers preserved.

6.1.3 - DOS_OPEN

Open and/or Create a file
Function AddressDescription
DOS_OPEN 0106Open and/or Create a file

Synopsys

Create and/or open a file

Entry Parameters

Register Content
B File number 0…15
C Access mode required
D Create action
E Open action
HL Address of filename, no wildcards. Terminated with 0xFF

Exit Parameters

If file newly created:
Carry true
Zero true
A corrupt
If existing file opened:
Carry true
Zero false
A corrupt
Otherwise:
Carry false
A=Error code
Always:
BC DE HL IX corrupt, all other registers preserved.
Open Action
0Error - File already exists.
1 Open the file, read the header (if any).
Position file pointer after header.
2 Open the file, ignore any header.
Position file pointer at 000000h (0).
3 Assume given filename is 'filename.type'.
  1. Erase 'filename.BAK' (if it exists).
  2. Rename 'filename.type' to 'filename.BAK'.
  3. Follow create action.
4 Erase existing version.
Follow create action.
Create Action
0Error - File does not exists.
1 Create and open new file with a header.
Position file pointer after header.
2 Create and open new file without a header.
Position file pointer at 000000h (0).
Note: The original +3 Manual doesn't mention that the filename needs to be terminated with a 0xFF byte.

This was only discovered during testing by looking at the ROM 2 disassembly.

6.1.4 - DOS_CLOSE

Close a file
Function AddressDescription
DOS_CLOSE 0109Close a file

Synopsys

Close a file

Entry Parameters

Register Content
B File number 0…15

Exit Parameters

If OK:
Carry true
A corrupt
Otherwise:
Carry false
A=Error code
Always:
BC DE HL IX corrupt, all other registers preserved.

6.1.5 - DOS_ABANDON

Abandon a file
Function AddressDescription
DOS_ABANDON 010CAbandon a file

Synopsys

Abandon a file

Similar to DOS CLOSE, except that any header, or data, or directory data yet to be written to disk is discarded. This routine should only be used to force a file closed in the event that DOS CLOSE is unable to close the file (for example, if the media is damaged or permanently changed or removed).

Entry Parameters

Register Content
B File number 0…15

Exit Parameters

If OK:
Carry true
A corrupt
Otherwise:
Carry false
A=Error code
Always:
BC DE HL IX corrupt, all other registers preserved.

6.1.6 - DOS_REF_HEAD

Point to header data for this file
Function AddressDescription
DOS_REF_HEAD 010FPoint to header data for this file

Synopsys

Point at the header data for this file.

The header data area is 8 bytes long and may be used by the caller for any purpose whatsoever. It is available even if the file does not have a header; however, only files with a header and opened with write access will have the header data recorded on disk.

Note that +3 BASIC uses these 8 bytes (see the note under DOS OPEN which gives the details). If creating a file that will subsequently be LOADed within BASIC, then those bytes should be filled with the relevant values.

Entry Parameters

Register Content
B File number 0…15

Exit Parameters

If OK:
Carry true
A corrupt
IX = Address of header data
Otherwise:
Carry false
A = Error code
IX corrupt
Always:
BC DE HL corrupt, all other registers preserved.
The original manual doesn't mention exactly what IX points to after this call.

The address in IX is the +3 BASIC Header structure which is 8 bytes long. (IX+0) is the file type, (IX+1) the file length and (IX+3) param 1.

6.1.7 - DOS_READ

Read bytes from a file into memory
Function AddressDescription
DOS_READ 0112Read bytes from a file into memory

Synopsys

Read bytes from a file into memory, advancing the file pointer in the process.

This routine does not consider any soft-EOF in the file. Attempting to read past the EOF will produce an error.

Entry Parameters

Register Content
B File number 0…15
C Page number for addresses 0xC000…0xFFFF
DE Number of bytes to read. 0 means 64K
HL Address of where to write the bytes to

Exit Parameters

If OK:
Carry true
A corrupt
DE corrupt
Otherwise:
Carry false
A = Error code
DE = Number of bytes remaining unread
Always:
BC HL IX corrupt, all other registers preserved.

The value of C is only used when HL is within the upper 16K of memory (0xC000…0xFFFF). If HL is in this range then C is the RAM bank to use. For most purposes C should be set to 0 which is the default RAM bank mapped to that region.

6.1.8 - DOS_Write

Read bytes from a file into memory
Function AddressDescription
DOS_WRITE 0115Write bytes from memory into a file

Synopsys

Write bytes from memory into a file, advancing the file pointer in the process.

Entry Parameters

Register Content
B File number 0…15
C Page number for addresses 0xC000…0xFFFF
DE Number of bytes to write. 0 means 64K
HL Address of where to read the bytes from

Exit Parameters

If OK:
Carry true
A corrupt
DE corrupt
Otherwise:
Carry false
A = Error code
DE = Number of bytes remaining unwritten
Always:
BC HL IX corrupt, all other registers preserved.

The value of C is only used when HL is within the upper 16K of memory (0xC000…0xFFFF). If HL is in this range then C is the RAM bank to use. For most purposes C should be set to 0 which is the default RAM bank mapped to that region.

6.1.9 - DOS_READ_BYTE

Read byte from a file, check for soft-EOF
Function AddressDescription
DOS_READ_BYTE 0118Read byte from a file, check for soft-EOF

Synopsys

Read a byte from a file, advancing the file pointer in the process. It tests for a soft EOF (0x1A) but it is possible to read past this. Reading to the hard EOF will return an error.

Entry Parameters

Register Content
B File number 0…15

Exit Parameters

If OK - not soft-EOF (0x1A)
Carry true
Zero false
A corrupt
C Byte read
If OK - soft-EOF (0x1A)
Carry true
Zero true
A corrupt
C Byte read
Otherwise:
Carry false
A = Error code
C corrupt
Always:
BC DE HL IX corrupt, all other registers preserved.

6.1.10 - DOS_WRITE_BYTE

Write byte to a file
Function AddressDescription
DOS_WRITE_BYTE 011BWrite byte to a file

Synopsys

Write a byte to a file, advancing the file pointer in the process.

Entry Parameters

Register Content
B File number 0…15
C Byte to write

Exit Parameters

If OK
Carry true
A corrupt
Otherwise:
Carry false
A = Error code
Always:
BC DE HL IX corrupt, all other registers preserved.

6.1.11 - DOS_CATALOG

Get the disk catalog
Function AddressDescription
DOS_CATALOG 011EGet the disk catalog

Synopsys

Fills a buffer with part of the directory (sorted).

The filename specifies the drive, user and a (possibly ambiguous) filename.

Since the size of a directory is variable (and may be quite large), this routine permits the directory to be catalogued in a number of small sections. The caller passes a buffer pre-loaded with the first required filename, or zeroes for the start of the directory. The buffer is loaded with part (or all, if it fits) of the directory sorted in ASCII order. If more of the directory is required, this routine is re-called with the buffer re-initialised with the last file previously returned. This procedure is followed repeatedly until all of the directory has been catalogued.

Note that +3DOS format disks (which are the same as single-sided, single track AMSTRAD PCW range format disks) may have a maximum of 64 directory entries.

Entry Parameters

Register Content
B n+1 size of buffer in entries, must be >= 2
C Filter:
Bit 0 = include system files if set
Bits 1…7 reserved
DE Address of buffer, first entry initialised
HL Address of filename, wildcards permitted

Exit Parameters

If OK:
Carry true
A corrupt
B number of completed entries in buffer, 0…n.
If B=n then there may be more entries for subsequent calls
Otherwise:
Carry false
A=Error code
B corrupt
Always:
C DE HL IX corrupt, all other registers preserved.

Buffer format

The buffer passed to this routine consists of 2 or more entries, with the first one initialised with the first filename required. It is valid for the first entry to be all zero's.

If the buffer is too small for the directory then it can be called again with entry 0 being a copy of entry n from the previous call.

Directory Entry Format
Bytes Length Content
078 Filename in ASCII, left justified, space padding
8103 Type in ASCII, left justified, space padding
11122 File size in KB

The file size is the disk space allocated, not the actual file size.

6.1.12 - DOS_FREE_SPACE

Get free space on drive
Function AddressDescription
DOS_FREE_SPACE 0121Get free space on drive

Synopsys

Return the amount of free space on a drive.

Entry Parameters

Register Content
A Drive letter A…P

Exit Parameters

If OK:
Carry true
A corrupt
HL = Free space in KB
Otherwise:
Carry false
A=Error code
HL corrupt
Always:
BC DE IX corrupt, all other registers preserved.

6.1.13 - DOS_DELETE

Delete a file
Function AddressDescription
DOS_DELETE 0124Delete a file

Synopsys

Delete an existing file.

The file must not be open on any file number.

Entry Parameters

Register Content
HL Address of filename, wildcards are permitted.

Exit Parameters

If OK:
Carry true
A corrupt
Otherwise:
Carry false
A=Error code
Always:
BC DE HL IX corrupt, all other registers preserved.

6.1.14 - DOS_RENAME

Rename a file
Function AddressDescription
DOS_RENAME 0127Get free space on drive

Synopsys

Return the amount of free space on a drive.

Entry Parameters

Register Content
A Drive letter A…P

Exit Parameters

If OK:
Carry true
A corrupt
HL = Free space in KB
Otherwise:
Carry false
A=Error code
HL corrupt
Always:
BC DE IX corrupt, all other registers preserved.

6.1.15 - DOS_BOOT

Boot from disk
Function AddressDescription
DOS_BOOT 012ABoot from disk

Synopsys

Boot from Disk

This routine loads a single bootstrap sector from the disk in drive A: into memory and enters it. This is for loading games or other operating systems.

Entry Parameters

None

Exit Parameters

If OK:
No exit as the bootstrap has taken over
Otherwise:
Carry false
A=Error code
Always:
BC DE HL IX corrupt, all other registers preserved.

Bootstrap environment

When the bootstrap runs with the following memory configuration:

The bootstrap sector is on side 0, track 0, sector 1 of the disk. It is loaded into memory at 0xFE00 and entered at 0xFE10. Interrupts are disabled, and SP = 0xFE00.

The sum of all bytes in the sector must equal 3 MOD 256. Byte 15 in the sector can be used to adjust the sum to achive this. Bytes 0…15 of the sector hold the disk specification.

Memory Range RAM Bank
0x00000x3FFFBank 4
0x40000x7FFFBank 7
0x80000xBFFFBank 6
0xC0000xFFFFBank 3

6.1.16 - DOS_SET_DRIVE

Set the default drive
Function AddressDescription
DOS_SET_DRIVE 012DSet the default drive

Synopsys

Set the default drive (i.e. the drive implied by all filenames that do not specify a drive).

The default drive is initially A:

Does not access the drive, but merely checks that there is a driver for it (which does not imply that the drive exists).

This only affects routines that take filename parameters.

Entry Parameters

Register Content
A Drive letter A…P, 0xFF to get the default drive

Exit Parameters

If OK:
Carry true
A = default drive
Otherwise:
Carry false
A=Error code
Always:
BC DE HL IX corrupt, all other registers preserved.

6.1.17 - DOS_SET_USER

Set the default user
Function AddressDescription
DOS_SET_USER 0130Set the default user

Synopsys

Set the default user area, i.e. the user area implied by all filenames that do not specify a user number.

The default user number is initially 0.

This only affects routines that take filename parameters.

Entry Parameters

Register Content
A User 0…15, 0xFF to get the default user

Exit Parameters

If OK:
Carry true
A = default user
Otherwise:
Carry false
A=Error code
Always:
BC DE HL IX corrupt, all other registers preserved.

6.2 - Additional API

+3DOS Additional API

6.2.1 - DOS_GET_POSITION

Get the file pointer
Function AddressDescription
DOS_GET_POSITION 0133Get the file pointer

Synopsys

Returns the current position in the file

Entry Parameters

Register Content
B File number 0…15

Exit Parameters

If OK
Carry true
A corrupt
E HL = File pointer 0x000000…0xFFFFFF (16Mb)
E is most significant byte, L least
Otherwise:
Carry false
A = Error code
E HL = Corrupt
Always:
BC D IX corrupt, all other registers preserved.

6.2.2 - DOS_SET_POSITION

Set the file pointer
Function AddressDescription
DOS_SET_POSITION 0136Set the file pointer

Synopsys

Sets the file pointer. This does not access the disk, nor does it check if the file pointer is >= 8 megabytes.

Entry Parameters

Register Content
B File number 0…15
E HL File pointer 0x000000…0xFFFFFF (16Mb)
E is most significant byte, L least

Exit Parameters

If OK
Carry true
A corrupt
Otherwise:
Carry false
A = Error code
Always:
BC DE HL IX corrupt, all other registers preserved.

6.2.3 - DOS_GET_EOF

Get the end of file (EOF) position
Function AddressDescription
DOS_GET_EOF 0139Get the end of file (EOF) position

Synopsys

Get the end of file (EOF) file position greater than all written byte positions. Does not affect the file pointer. Does not consider soft-EOF.

Entry Parameters

Register Content
B File number 0…15

Exit Parameters

If OK
Carry true
A corrupt
E HL = File pointer 0x000000…0xFFFFFF (16Mb)
E is most significant byte, L least
Otherwise:
Carry false
A = Error code
E HL = Corrupt
Always:
BC D IX corrupt, all other registers preserved.

6.2.4 - DOS_GET_1346

Get current cache/ramdisk location
Function AddressDescription
DOS_GET_1346 013CSet current cache/ramdisk location

Synopsys

Get the current location of the cache and RAMdisk.

Pages 1, 3, 4, 6 are considered as an array of 128 sector buffers (numbered 0...127), each of 512 bytes. The cache and RAMdisk occupy two separate (contiguous) areas of this array.

Any unused sector buffers may be used by the caller.

Note that the sizes may be smaller than those specified in DOS_SET_1346, as there is an (unpublished) maximum size of cache and a minimum size of RAMdisk (4 sectors).

Entry Parameters

None

Exit Parameters

D = First buffer of cache
E = Number of cache sector buffers
H = First buffer of RAM disk
L = Number of RAM disk sector buffers
Always:
AF BC IX corrupt, all other registers preserved.

6.2.5 - DOS_SET_1346

Rebuild the sector cache and RAM disk
Function AddressDescription
DOS_SET_1346 013FRebuild the sector cache and RAM disk

Synopsys

Rebuild the sector cache and RAM disk.

This routine is used to make some store available to the user, or to return store to DOS. Note that if the RAM disk is moved, or its size is changed, then all files thereon are erased.

Pages 1, 3, 4, 6 are considered as an array of 128 sector buffers (numbered 0...127), each of 512 bytes. The cache and RAMdisk occupy two separate (contiguous) areas of this array.

The location and size of the cache and RAMdisk can be specified separately; any remaining buffers are unused by DOS and are available to the caller.

Note that the sizes actually used may be smaller than those specified as in practice, there is a maximum cache size and a minimum size of RAMdisk (4 sectors).

A cache size of 0 will still work but will seriously impair the floppy disk performance.

This routine will fail if there are any files open on drive M:

Entry Parameters

Register Content
D First buffer for cache
E Number of cache sector buffers
H First buffer for RAM disk
L Number of RAM disk sector buffers
Note: E + L <= 128

Exit Parameters

If OK
Carry true
A corrupt
Otherwise:
Carry false
A = Error code
Always:
BC DE HL IX corrupt, all other registers preserved.

6.2.6 - DOS_FLUSH

Write any pending data to this drive
Function AddressDescription
DOS_FLUSH 0142Write any pending data to this drive

Synopsys

Write any pending headers, data, directory entries for this drive.

This routine ensures that the disk is up-to-date. It can be called at any time, even when files are open.

Entry Parameters

Register Content
A Drive A…P

Exit Parameters

If OK
Carry true
A corrupt
Otherwise:
Carry false
A = Error code
Always:
BC DE HL IX corrupt, all other registers preserved.

6.2.7 - DOS_SET_ACCESS

Change access mode of an open file
Function AddressDescription
DOS_SET_ACCESS 0145Change access mode of an open file

Synopsys

Try to change the access mode of an open file.

This routine will fail if the file is already open, in an incompatible access mode, or if write access is required for a read-only file or disk.

Entry Parameters

Register Content
B File number 0…15
C Access mode required:
Bits 0…2:
1 = exclusive read
2 = exclusive write
3 = exclusive read/write
5 = shared read
Bits 3…7 =0 as reserved

Exit Parameters

If OK
Carry true
A corrupt
Otherwise:
Carry false
A = Error code
Always:
BC DE HL IX corrupt, all other registers preserved.

6.2.8 - DOS_SET_ATTRIBUTES

Set a files attributes
Function AddressDescription
DOS_SET_ATTRIBUTES 0148Set a files attributes

Synopsys

Set a file's attributes.

Only the file attributes f1'...f4', t1'...t3' can be set or cleared. The interface attributes f5'...f8' are always 0.

This routine first sets the attributes specified in D, then clears those attributes specified in E, i.e. E has priority.

Entry Parameters

Register Content
D Attributes to set
E Attributes to clear
HL Address of filename, wildcards permitted

Exit Parameters

If OK
Carry true
A corrupt
Otherwise:
Carry false
A = Error code
Always:
BC DE HL IX corrupt, all other registers preserved.
Bit definitions for Attributes
Bit Attribute Bit Attribute
0t3Archive 3f4
1t2System 4f3
2t1Read Only 5f2
6f1

6.2.9 - DOS_OPEN_DRIVE

Open drive as a single file
Function AddressDescription
DOS_OPEN_DRIVE 014BOpen drive as a single file

Synopsys

Open the disk in this drive as a single file.

The whole disk is presented as a single file regardless of any real files on the disk. This routine can be used to examine/poke directories, files, etc. It should not be used by the uninitiated, the faint-hearted, or by anyone who values their files!

Sets file pointer to 0x000000 (0).

If there are any files open on this drive from other file numbers with shared-read access, then the disk can only be opened with shared-read access from this file number.

If there are any file open on this drive from other file numbers with exclusive access, then the disk cannot be opened from this file number.

Entry Parameters

Register Content
A Drive A…P
B File number 0…15
C Access mode required: Bits 0…2:
1 = exclusive read
2 = exclusive write
3 = exclusive read/write
5 = shared read
All other bits are reserved

Exit Parameters

If OK
Carry true
A corrupt
Otherwise:
Carry false
A = Error code
Always:
BC DE HL corrupt, all other registers preserved.

6.2.10 - DOS_SET_MESSAGE

Enable/disable disk error messages
Function AddressDescription
DOS_SET_MESSAGE 014EEnable/disable disk error messages

Synopsys

Enable/disable disk error messages.

This should be used to make +3DOS aware of your own ALERT subroutine. When +3DOS detects an error, it will call your ALERT subroutine, passing to it the values documented below. The ALERT subroutine should print the text of the message that +3DOS passes it, then should wait for the user to press a key. If the key is in the reply string (that +3DOS also passes - version V1.0 only), then a 'ret' should be made with A = 0, 1 or 2, or containing the character (depending on the version of +3DOS).

Entry Parameters

Register Content
A Enable 0xff or disable 0x00
HL Address of ALERT routine if enabled

Exit Parameters

HL = address of previous ALERT routine, 0 if none
Always:
AF BC DE IX corrupt, all other registers preserved.

ALERT implementations

Note that if you are substituting your own ALERT subroutine, the 'entry conditions' are the conditions passed to your subroutine and the 'exit conditions' are the values that your subroutine must produce and the registers you are allowed to corrupt.

There are two routine interfaces for ALERT, depending on which version of +3DOS is installed.

If you provide an ALERT function, you should have two subroutines, or one with switchable entry and exit conditions, and check the +3DOS version number before deciding which one to use.

+3DOS V1.0

Entry Parameters

Register Content
DE Address of reply string in page 7 terminated by 0xFF
HL Address of error message in page 7 terminated by 0xFF

Exit Parameters

A = Reply character
Always:
F BC DE HL IX corrupt, all other registers preserved.

+3DOS V1.1 and above

The second version allows the user to provide non-UK error messages and is generally more flexible, is present in +3DOS versions V1.1 and upwards.

Entry Parameters

Register Content
B Error number
C Drive A…P
D Logical track if required by message
E Logical sector if required by message
HL Address of UK error message in page 7 terminated by 0xFF

Exit Parameters

A = Reply
0 = cancel
1 = retry
2 = ignore
Always:
F BC DE HL IX corrupt, all other registers preserved.

6.2.11 - DOS_REF_XDPB

Point at XDPB for this drive
Function AddressDescription
DOS_REF_XDPB 0151Point at XDPB for this drive

Synopsys

Point at the XDPB for this drive. (The XDPB is required by the floppy disk driver routines.)

Entry Parameters

Register Content
A Drive letter A…P

Exit Parameters

If OK:
Carry true
A corrupt
IX = Address of XDPB
Otherwise:
Carry false
A=Error code
IX corrupt
Always:
BC DE HL corrupt, all other registers preserved.

6.2.12 - DOS_MAP_B

Map drive B to unit 0 or 1
Function AddressDescription
DOS_MAP_A 0154Map drive B to unit 0 or 1

Synopsys

Map drive B: to unit 0 or unit 1. This routine will fail if drive B: has files open.

If mapping B: to unit 0, then each time unit 0 is accessed, a check is made that the drive mapping is correct. If it isn't, then a reverse call to CHANGE DISK is made, to ask the user to change the disk in unit 0.

If mapping B: to unit 1, then if unit 1 does not exist, drive B: is disabled.

Entry Parameters

Register Content
C Unit 0 or 1
HL Address of change disk routine if unit = 0

Exit Parameters

If OK:
Carry true
A corrupt
HL = Address of previous change disk routine, 0 if none
Otherwise:
Carry false
A corrupt
HL corrupt
Always:
BC DE IX corrupt, all other registers preserved.

Change Disk routine

If you are substituting your own CHANGE DISK subroutine, the 'entry conditions' are the conditions passed to your subroutine, and the 'exit conditions' are registers you are allowed to corrupt.

Entry Parameters

Register Content
A Logical drive A…P
HL Address of message in page 7 terminated by 0xFF

Exit Parameters

Always:
AF BC DE IX corrupt, all other registers preserved.

6.3 - Low Level API

+3DOS Low Level API

The following are the floppy disk driver routines. The unit number is 0…3 for the uPD765A. On the +3, unit 0 is drive A: and unit 1 is drive B:, or optionally, both A: and B: may be mapped onto unit 0. Units 2 and 3 are not used.

With the exception of DD_INTERFACE, none of these routines may be called if the floppy disk interface is not present.

All routines assume that interrupts are enabled on entry, and will still be enabled on exit.

6.3.1 - DD_INTERFACE

Check for the disk drive interface
Function AddressDescription
DD_INTERFACE 0157Check for the disk drive interface

Synopsys

Is the floppy disk drive interface present?

This information is also held by BASIC in bit 4 of the FLAGS3 system variable.

Entry Parameters

None

Exit Parameters

If present
Carry true
Otherwise:
Carry false
Always:
A BC DE HL IX corrupt, all other registers preserved.

6.3.2 - DD_INIT

Initialise the disk driver
Function AddressDescription
DD_INIT 015AInitialise the disk driver

Synopsys

Initialise the disk driver

Entry Parameters

None

Exit Parameters

Always:
AF BC DE HL IX corrupt, all other registers preserved.

6.3.3 - DD_SETUP

Setup disk parameters
Function AddressDescription
DD_SETUP 015DSetup disk parameters

Synopsys

Set up disk parameters. Send a specify command.

Entry Parameters

Register Content
HL Address of parameter block

Exit Parameters

Always:
AF BC DE HL IX corrupt, all other registers preserved.
Parameter Block
Byte Content
0Motor on time, unit=100ms
1Motor off time, unit=100ms
2Write off time, unit=10ms
3Head settle time, unit=ms
4Step rate, unit=ms
5Head unload time, unit=32ms, 32…480
6(Head load time *2)+1, unit=4ms, 4…508

6.3.4 - DD_SET_RETRY

Set try/retry count
Function AddressDescription
DD_SET_RETRY 0160Set try/retry count

Synopsys

Set the try and retry count. A value of 1 will try the operation once with no retries.

Entry Parameters

Register Content
A Try/Retry count >= 1

Exit Parameters

Always:
AF BC DE HL IX corrupt, all other registers preserved.

6.3.5 - DD_READ_SECTOR

Read a sector
Function AddressDescription
DD_READ_SECTOR 0163Read a sector

Synopsys

Read a sector

Entry Parameters

Register Content
B Page for 0xC000…0xFFFF
C Unit 0 or 1
D Logical track, 0 base
E logical sector, 0 base
HL Address of buffer
IX Address of XDPB

Exit Parameters

If OK:
Carry true
A corrupt
Otherwise:
Carry false
A = Error code
Always:
BC DE HL IX corrupt, all other registers preserved.

6.3.6 - DD_WRITE_SECTOR

Write a sector
Function AddressDescription
DD_WRITE_SECTOR 0166Write a sector

Synopsys

Write a sector

Entry Parameters

Register Content
B Page for 0xC000…0xFFFF
C Unit 0 or 1
D Logical track, 0 base
E logical sector, 0 base
HL Address of buffer
IX Address of XDPB

Exit Parameters

If OK:
Carry true
A corrupt
Otherwise:
Carry false
A = Error code
Always:
BC DE HL IX corrupt, all other registers preserved.

6.3.7 - DD_CHECK_SECTOR

Check a sector
Function AddressDescription
DD_CHECK_SECTOR 0169Check a sector

Synopsys

Check a sector. (Uses the uPD765A scan equal command.)

Checks that the sector on disk is the same as the copy in memory.

Note that FFh (255) on disk or in memory always matches anything (see uPD765A specification for further details).

Entry Parameters

Register Content
B Page for 0xC000…0xFFFF
C Unit 0 or 1
D Logical track, 0 base
E logical sector, 0 base
HL Address of buffer
IX Address of XDPB

Exit Parameters

If OK & Equal:
Carry true
Zero true
A corrupt
If OK & Not Equal:
Carry true
Zero false
A corrupt
Otherwise:
Carry false
A = Error code
Always:
BC DE HL IX corrupt, all other registers preserved.

6.3.8 - DD_FORMAT

Format a track
Function AddressDescription
DD_FORMAT 016CFormat a track

Synopsys

Format a track. (Uses the uPD765A format track command.)

Entry Parameters

Register Content
B Page for 0xC000…0xFFFF
C Unit 0 or 1
D Logical track, 0 base
E Filler byte, usually 0xE5
HL Address of format buffer
IX Address of XDPB

Exit Parameters

If OK:
Carry true
A corrupt
Otherwise:
Carry false
A = Error code
Always:
BC DE HL IX corrupt, all other registers preserved.

Format buffer

The format buffer contains 4 bytes for each sector:

Byte Content Range
CTrack Number0…39
HHead NumberAlways 0 on a standard +3 single sided drive
RSector Number0…255
NLog2(sectorSize)-72 for 512 byte sectors

6.3.9 - DD_READ_ID

Read a sector identifier
Function AddressDescription
DD_READ_ID 016FRead a sector identifier

Synopsys

Read a sector identifier

Entry Parameters

Register Content
C Unit 0 or 1
D Logical track, 0 base
IX Address of XDPB

Exit Parameters

If OK:
Carry true
A = sector number from identifier
Otherwise:
Carry false
A = Error code
Always:
HL = Address of result buffer in page 7
BC DE IX corrupt, all other registers preserved.

6.3.10 - DD_TEST_UNSUITABLE

Check disk is suitable to write to
Function AddressDescription
DD_TEST_UNSUITABLE 0172Check disk is suitable to write to

Synopsys

Check that disk is suitable to write to. A single track disk will not work in a double track drive, and vice versa.

Entry Parameters

Register Content
C Unit 0 or 1
IX Address of XDPB

Exit Parameters

If OK:
Carry true
A corrupt
Otherwise:
Carry false
A = Error code
Always:
BC DE HL IX corrupt, all other registers preserved.

6.3.11 - DD_LOGIN

Log in a new disk
Function AddressDescription
DD_LOGIN 0175Login a new disk

Synopsys

Log in a new disk. Initialise the XDPB. This routine does not affect or consider the freeze flag.

Entry Parameters

Register Content
C Unit 0 or 1
IX Address of XDPB

Exit Parameters

If OK:
Carry true
A = Disk type
DE = Size of allocation vector
HL = Size of hash table
Otherwise:
Carry false
A = Error code
DE HL corrupt
Always:
BC IX corrupt, all other registers preserved.

6.3.12 - DD_SEL_FORMAT

Select a standard format
Function AddressDescription
DD_SEL_FORMAT 0178Select a standard format

Synopsys

Initialise an XDPB for a standard format. This routine does not affect or consider the freeze flag.

Entry Parameters

Register Content
A Disk type:
0 = Spectrum +3 (Amstrad PCW DD, SS, ST)
1 = Amstrad CPC range system format
2 = Amstrad CPC range data-only format
3 = Amstrad PCW range DD, SS, DT
Any other value returns an error
IX Address of XDPB

Exit Parameters

If OK:
Carry true
A = Disk type
DE = Size of 2 bit allocation vector
HL = Size of hash table
Otherwise:
Carry false
A = Error code
DE HL corrupt
Always:
BC IX corrupt, all other registers preserved.

6.3.13 - DD_ASK_1

Check to see if unit 1 is present
Function AddressDescription
DD_ASK_1 017BCheck to see if unit 1 is present

Synopsys

Check to see if unit 1 is present. BASIC holds this information in bit 5 of the FLAGS3 system variable.

Turn motor on.

Fetch drive status.

If unit 1 is not-ready and write-protected, then unit 1 is missing. Start motor off timeout.

Note that this routine can be fooled by disks which are almost, but not quite, inserted in the drive.

This routine assumes that when a disk is not in the drive, then write-protect is true. This is indeed the case for 3 inch and 8 inch disk drives, but is not the case for 5 1/4 inch disk drives.

Entry Parameters

None

Exit Parameters

If unit 1 present:
Carry true
Otherwise:
Carry false
Always:
A BC DE HL IX corrupt, all other registers preserved.

6.3.14 - DD_DRIVE_STATUS

Check drive status
Function AddressDescription
DD_DRIVE_STATUS 017ECheck drive status

Synopsys

Issue a sense drive status command.

Entry Parameters

Register Content
C Unit/head
Bits 0…1 Unit 0…3
Bit 2 Head
Bits 3…7 = 0

Exit Parameters

A = ST3 status register 3 of uPD765A
Always:
F BC DE HL IX corrupt, all other registers preserved.

6.3.15 - DD_EQUIPMENT

Ask what type of drive
Function AddressDescription
DD_EQUIPMENT 0181Ask what type of drive

Synopsys

Ask what type of drive this is (i.e. single/double track, single/double sided).

Track information can only be determined once a disk has been seen and had its type identified during logging in.

Side information can only be detected after a double sided disk has been seen and has its type identified during logging in.

Entry Parameters

Register Content
C Unit 0 or 1
IX Address of XDPB

Exit Parameters

Carry true
A = Side/track information
bits 0…1 side information: 0 = unknown, 1 = single sided, 2 = double sided
bits 2…3 track information: 0 = unknown, 1 = single track, 2 = double track
Always:
F BC DE HL IX corrupt, all other registers preserved.

6.3.16 - DD_ENCODE

Set copy protection encode routine
Function AddressDescription
DD_ENCODE 0184Set copy protection encode routine

Synopsys

Set the copy protection ENCODE subroutine.

Copy protected disks have some of their track and sector numbers encoded on disk. Before each disk access, the ENCODE subroutine is called to encode the physical track and sector numbers.

These encoded track and sector numbers must match those in the sector identifier.

Note that tracks 0…2 on either side of a disk should not be encoded.

Entry Parameters

Register Content
A Enable 0xFF or disable 0x00
HL If enabled address of ENCODE routine

Exit Parameters

HL = Address of previous encode routine, 0 if none
Always:
AF BC DE IX corrupt, all other registers preserved.

ENCODE routine

If you are substituting your own ENCODE subroutine, the 'entry conditions' are the conditions passed to your subroutine, and the 'exit conditions' are the values that your subroutine must produce and the registers you are allowed to corrupt.

Entry Parameters

Register Content
C Unit/Side
Bits 0…1 = unit, Bit 2 = side
D Physical track
E Physical sector
IX Address of DPB

Exit Parameters

D = Encoded physical track
E = Encoded physical sector
Always:
AF corrupt, all other registers preserved.

6.3.17 - DD_L_XDPB

Initialise XDPB for a given format
Function AddressDescription
DD_L_XDPB 0187Initialise XDPB for a given format

Synopsys

Initialise an XDPB for a given format.

This routine does not affect or consider the freeze flag.

Entry Parameters

Register Content
DE Address of source disk specification
IX Address of destination XDPB

Exit Parameters

If OK:
Carry true
A = Disk type recorded on disk
DE = Size of allocation vector
HL = Size of hash table
Otherwise:
Carry false
A = Error code
DE HL corrupt
Always:
BC IX corrupt, all other registers preserved.

6.3.18 - DD_L_DPB

Initialise DPB for a given format
Function AddressDescription
DD_L_DPB 018AInitialise DPB for a given format

Synopsys

Initialise an DPB for a given format.

This routine does not affect or consider the freeze flag.

Entry Parameters

Register Content
DE Address of source disk specification
IX Address of destination DPB

Exit Parameters

If OK:
Carry true
A = Disk type recorded on disk
DE = Size of allocation vector
HL = Size of hash table
Otherwise:
Carry false
A = Error code
DE HL corrupt
Always:
BC IX corrupt, all other registers preserved.

6.3.19 - DD_L_SEEK

Seek to required track
Function AddressDescription
DD_L_SEEK 018DSeek to required track

Synopsys

Seek to required track. Retry if failure.

Entry Parameters

Register Content
C Unit/head: Bits 0…1 unit, Bit 2 head
D Track
IX Address of destination XDPB

Exit Parameters

If OK:
Carry true
A corrupt
Otherwise:
Carry false
A = Error code
Always:
BC DE HL IX corrupt, all other registers preserved.

6.3.20 - DD_L_READ

Low level uPD765A read command
Function AddressDescription
DD_L_READ 0190Low level uPD765A read command

Synopsys

Low level uPD765A read command.

Entry Parameters

Register Content
HL Address of parameter block

Exit Parameters

HL = Address of result buffer in page 7
Always:
AF BC DE IX corrupt, all other registers preserved.
Parameter Block Format
Bytes Length Content
001 Page for 0xC000…0xFFFF
122 Address of buffer
342 Number of bytes to transfer
551 Number of command bytes n
65+nn Command bytes

6.3.21 - DD_L_WRITE

Low level uPD765A write command
Function AddressDescription
DD_L_WRITE 0193Low level uPD765A write command

Synopsys

Low level uPD765A write command.

Entry Parameters

Register Content
HL Address of parameter block

Exit Parameters

HL = Address of result buffer in page 7
Always:
AF BC DE IX corrupt, all other registers preserved.
Parameter Block Format
Bytes Length Content
001 Page for 0xC000…0xFFFF
122 Address of buffer
342 Number of bytes to transfer
551 Number of command bytes n
65+nn Command bytes

6.3.22 - DD_L_ON_MOTOR

Turn on motor
Function AddressDescription
DD_L_ON_MOTOR 0196Turn on motor

Synopsys

Turn on the motor. Wait for the motor on time as set by DD SETUP.

Entry Parameters

None

Exit Parameters

Always:
AF BC DE HL IX corrupt, all other registers preserved.

6.3.23 - DD_L_T_OFF_MOTOR

Start motor off timeout
Function AddressDescription
DD_L_T_OFF_MOTOR 0199Start motor off timeout

Synopsys

Start motor off timeout.

Entry Parameters

None

Exit Parameters

Always:
AF BC DE HL IX corrupt, all other registers preserved.

6.3.24 - DD_L_OFF_MOTOR

Turn off motor
Function AddressDescription
DD_L_OFF_MOTOR 019CTurn off motor

Synopsys

Turn off the motor.

Entry Parameters

None

Exit Parameters

Always:
AF BC DE HL IX corrupt, all other registers preserved.

6.4 - +3DOS File Header

The +3DOS File Header

Tape files have headers which contain some system information. +3DOS files may, or may not, have headers. All files created by BASIC's SAVE command will have headers.

The +3DOS header mechanism provides a dedicated 8 byte area in each headed file reserved for BASIC's use. The remainder of the header is reserved for +3DOS. This 8 byte header is utilised in files created by BASIC commands (see DOS OPEN description).

+3DOS files may have a single header in the first 128 bytes of the file - the header record. These headers are detected by a 'signature' and checksum. If the signature and checksum are as expected, then a header is present; if not, there is no header. Thus, it is possible, but unlikely, that a file without a header could be mistaken for one with a header.

+3DOS File Header
Bytes Length Content
078+3DOS Signature"PLUS3DOS"
81Soft-EOF0x1A
91Issue0x01
101Version0x00
11144Length of file including header
15228+3 BASIC Header
23126104Reserved0x00
1271ChecksumSum bytes 0…126 AND 0xFF
+3 BASIC Header
Bytes Length Content
01File Type
122File Length
342Param 1
562Param 2
71Unused = 0x00
BASIC File Type
Type File Description Param 1 Param 2
0 BASIC Program Line number to start Start of variable area relative to program start
1 Number Array Variable name, e.g. if DIM a() then this is 0x80 a=0x81, y=0x99
2 Character Array Variable name, e.g. if DIM a$() then this is 0x80 a=0xC1, y=0xD9
3 CODE Start when saved 32768

Notes

6.5 - Error Codes

The +3DOS Error Codes

When a call to a +3DOS API fails then the carry flag will be false and the Accumulator will contain the error code. The errors are in two categories, Recoverable (Green) and Non-recoverable (Red):

Code Error
00x00Drive not ready
10x01Disk is write protected
20x02Seek fail
30x03CRC data error
40x04No data
50x05Missing address mark
60x06Unrecognised disk format
70x07Unknown disk error
80x08Disk changed whilst +3DOS was using it
90x09Unsuitable media for drive
200x14Bad filename
210x15Bad parameter
220x16Drive not found
230x17File not found
240x18File already exists
250x19End of file
260x1ADisk full
270x1BDirectory full
280x1CRead-only file
290x1DFile number not open (or open with wrong access)
300x1EAccess denied (file is in use already)
310x1FCannot rename between drives
320x20Extent missing (which should be there)
330x21Uncached (software error)
340x22File too big (trying to read or write past 8 megabytes)
350x23Disk not bootable (boot sector is not acceptable to DOS BOOT)
360x24Drive in use (trying to re-map or remove a drive with files open)

7 - reference

7.1 - API by Address

API by Address
Function AddressDescription
RST_0 0000Start the computer
RST_1 0008Report an error
RST_2 0010Print A to the output stream
RST_3 0018Collect character
RST_4 0020Collect Next character
RST_5 0028FP Calculator
RST_6 0030FP Calculator
RST_7 0038Maskable Interrupt Handler
DOS_INITIALISE 0100Initialise +3DOS
DOS_VERSION 0103Return DOS issue and version numbers
DOS_OPEN 0106Open and/or Create a file
DOS_CLOSE 0109Close a file
DOS_ABANDON 010CAbandon a file
DOS_REF_HEAD 010FPoint to header data for this file
DOS_READ 0112Read bytes from a file into memory
DOS_WRITE 0115Write bytes from memory into a file
DOS_READ_BYTE 0118Read byte from a file, check for soft-EOF
DOS_WRITE_BYTE 011BWrite byte to a file
DOS_CATALOG 011EGet the disk catalog
DOS_FREE_SPACE 0121Get free space on drive
DOS_DELETE 0124Delete a file
DOS_RENAME 0127Get free space on drive
DOS_BOOT 012ABoot from disk
DOS_SET_DRIVE 012DSet the default drive
DOS_SET_USER 0130Set the default user
DOS_GET_POSITION 0133Get the file pointer
DOS_SET_POSITION 0136Set the file pointer
DOS_GET_EOF 0139Get the end of file (EOF) position
DOS_GET_1346 013CSet current cache/ramdisk location
DOS_SET_1346 013FRebuild the sector cache and RAM disk
DOS_FLUSH 0142Write any pending data to this drive
DOS_SET_ACCESS 0145Change access mode of an open file
DOS_SET_ATTRIBUTES 0148Set a files attributes
DOS_OPEN_DRIVE 014BOpen drive as a single file
DOS_SET_MESSAGE 014EEnable/disable disk error messages
DOS_REF_XDPB 0151Point at XDPB for this drive
DOS_MAP_A 0154Map drive B to unit 0 or 1
DD_INTERFACE 0157Check for the disk drive interface
DD_INIT 015AInitialise the disk driver
DD_SETUP 015DSetup disk parameters
DD_SET_RETRY 0160Set try/retry count
DD_READ_SECTOR 0163Read a sector
DD_WRITE_SECTOR 0166Write a sector
DD_CHECK_SECTOR 0169Check a sector
DD_FORMAT 016CFormat a track
DD_READ_ID 016FRead a sector identifier
DD_TEST_UNSUITABLE 0172Check disk is suitable to write to
DD_LOGIN 0175Login a new disk
DD_SEL_FORMAT 0178Select a standard format
DD_ASK_1 017BCheck to see if unit 1 is present
DD_DRIVE_STATUS 017ECheck drive status
DD_EQUIPMENT 0181Ask what type of drive
DD_ENCODE 0184Set copy protection encode routine
DD_L_XDPB 0187Initialise XDPB for a given format
DD_L_DPB 018AInitialise DPB for a given format
DD_L_SEEK 018DSeek to required track
DD_L_READ 0190Low level uPD765A read command
DD_L_WRITE 0193Low level uPD765A write command
DD_L_ON_MOTOR 0196Turn on motor
DD_L_T_OFF_MOTOR 0199Start motor off timeout
DD_L_OFF_MOTOR 019CTurn off motor
CL_ALL 0DAFClear the screen
SWAP 5B00Paging subroutine
STOO 5B10Paging subroutine. Entered with interrupts disabled and AF, BC on the stack.
YOUNGER 5B21Paging subroutine
REGNUOY 5B2APaging subroutine
ONERR 5B3APaging subroutine
RAMRST 5B5DRST 8 instruction used by ROM 1 to report old errors to ROM 3

7.2 - API by Name

API by Name
Function AddressDescription
CL_ALL 0DAFClear the screen
DD_ASK_1 017BCheck to see if unit 1 is present
DD_CHECK_SECTOR 0169Check a sector
DD_DRIVE_STATUS 017ECheck drive status
DD_ENCODE 0184Set copy protection encode routine
DD_EQUIPMENT 0181Ask what type of drive
DD_FORMAT 016CFormat a track
DD_INIT 015AInitialise the disk driver
DD_INTERFACE 0157Check for the disk drive interface
DD_L_DPB 018AInitialise DPB for a given format
DD_L_OFF_MOTOR 019CTurn off motor
DD_L_ON_MOTOR 0196Turn on motor
DD_L_READ 0190Low level uPD765A read command
DD_L_SEEK 018DSeek to required track
DD_L_T_OFF_MOTOR 0199Start motor off timeout
DD_L_WRITE 0193Low level uPD765A write command
DD_L_XDPB 0187Initialise XDPB for a given format
DD_LOGIN 0175Login a new disk
DD_READ_ID 016FRead a sector identifier
DD_READ_SECTOR 0163Read a sector
DD_SEL_FORMAT 0178Select a standard format
DD_SET_RETRY 0160Set try/retry count
DD_SETUP 015DSetup disk parameters
DD_TEST_UNSUITABLE 0172Check disk is suitable to write to
DD_WRITE_SECTOR 0166Write a sector
DOS_ABANDON 010CAbandon a file
DOS_BOOT 012ABoot from disk
DOS_CATALOG 011EGet the disk catalog
DOS_CLOSE 0109Close a file
DOS_DELETE 0124Delete a file
DOS_FLUSH 0142Write any pending data to this drive
DOS_FREE_SPACE 0121Get free space on drive
DOS_GET_1346 013CSet current cache/ramdisk location
DOS_GET_EOF 0139Get the end of file (EOF) position
DOS_GET_POSITION 0133Get the file pointer
DOS_INITIALISE 0100Initialise +3DOS
DOS_MAP_A 0154Map drive B to unit 0 or 1
DOS_OPEN 0106Open and/or Create a file
DOS_OPEN_DRIVE 014BOpen drive as a single file
DOS_READ 0112Read bytes from a file into memory
DOS_READ_BYTE 0118Read byte from a file, check for soft-EOF
DOS_REF_HEAD 010FPoint to header data for this file
DOS_REF_XDPB 0151Point at XDPB for this drive
DOS_RENAME 0127Get free space on drive
DOS_SET_1346 013FRebuild the sector cache and RAM disk
DOS_SET_ACCESS 0145Change access mode of an open file
DOS_SET_ATTRIBUTES 0148Set a files attributes
DOS_SET_DRIVE 012DSet the default drive
DOS_SET_MESSAGE 014EEnable/disable disk error messages
DOS_SET_POSITION 0136Set the file pointer
DOS_SET_USER 0130Set the default user
DOS_VERSION 0103Return DOS issue and version numbers
DOS_WRITE 0115Write bytes from memory into a file
DOS_WRITE_BYTE 011BWrite byte to a file
ONERR 5B3APaging subroutine
RAMRST 5B5DRST 8 instruction used by ROM 1 to report old errors to ROM 3
REGNUOY 5B2APaging subroutine
RST_0 0000Start the computer
RST_1 0008Report an error
RST_2 0010Print A to the output stream
RST_3 0018Collect character
RST_4 0020Collect Next character
RST_5 0028FP Calculator
RST_6 0030FP Calculator
RST_7 0038Maskable Interrupt Handler
STOO 5B10Paging subroutine. Entered with interrupts disabled and AF, BC on the stack.
SWAP 5B00Paging subroutine
YOUNGER 5B21Paging subroutine

7.3 - include

7.3.1 - BeebASM

Files for the BeebASM assembler

7.3.1.1 - api

Generated file for beebasm
; *************************************************************************** ; API for Sinclair ZX Spectrum OS ; Notes about the Sinclair ZX Spectrum operating system & memory ; Author: Peter Mount, Area51.dev & Contributors ; ; URL: https://area51.dev/sinclair/spectrum/ ; ; Modified: Sun, 23 Jan 2022 17:05:58 UTC ; ; Current version: https://area51.dev/sinclair/spectrum/reference/include/beebasm/api.asm ; *************************************************************************** DOS_FLUSH = &142 ; Write any pending data to this drive DOS_GET_1346 = &13C ; Set current cache/ramdisk location DOS_GET_EOF = &139 ; Get the end of file (EOF) position DOS_GET_POSITION = &133 ; Get the file pointer DOS_MAP_A = &154 ; Map drive B to unit 0 or 1 DOS_OPEN_DRIVE = &14B ; Open drive as a single file DOS_REF_XDPB = &151 ; Point at XDPB for this drive DOS_SET_1346 = &13F ; Rebuild the sector cache and RAM disk DOS_SET_ACCESS = &145 ; Change access mode of an open file DOS_SET_ATTRIBUTES = &148 ; Set a files attributes DOS_SET_MESSAGE = &14E ; Enable/disable disk error messages DOS_SET_POSITION = &136 ; Set the file pointer DOS_ABANDON = &10C ; Abandon a file DOS_BOOT = &12A ; Boot from disk DOS_CATALOG = &11E ; Get the disk catalog DOS_CLOSE = &109 ; Close a file DOS_DELETE = &124 ; Delete a file DOS_FREE_SPACE = &121 ; Get free space on drive DOS_INITIALISE = &100 ; Initialise +3DOS DOS_OPEN = &106 ; Open and/or Create a file DOS_READ = &112 ; Read bytes from a file into memory DOS_READ_BYTE = &118 ; Read byte from a file, check for soft-EOF DOS_REF_HEAD = &10F ; Point to header data for this file DOS_RENAME = &127 ; Get free space on drive DOS_SET_DRIVE = &12D ; Set the default drive DOS_SET_USER = &130 ; Set the default user DOS_VERSION = &103 ; Return DOS issue and version numbers DOS_WRITE = &115 ; Write bytes from memory into a file DOS_WRITE_BYTE = &11B ; Write byte to a file DD_ASK_1 = &17B ; Check to see if unit 1 is present DD_CHECK_SECTOR = &169 ; Check a sector DD_DRIVE_STATUS = &17E ; Check drive status DD_ENCODE = &184 ; Set copy protection encode routine DD_EQUIPMENT = &181 ; Ask what type of drive DD_FORMAT = &16C ; Format a track DD_INIT = &15A ; Initialise the disk driver DD_INTERFACE = &157 ; Check for the disk drive interface DD_L_DPB = &18A ; Initialise DPB for a given format DD_L_OFF_MOTOR = &19C ; Turn off motor DD_L_ON_MOTOR = &196 ; Turn on motor DD_L_READ = &190 ; Low level uPD765A read command DD_L_SEEK = &18D ; Seek to required track DD_L_T_OFF_MOTOR = &199 ; Start motor off timeout DD_L_WRITE = &193 ; Low level uPD765A write command DD_L_XDPB = &187 ; Initialise XDPB for a given format DD_LOGIN = &175 ; Login a new disk DD_READ_ID = &16F ; Read a sector identifier DD_READ_SECTOR = &163 ; Read a sector DD_SEL_FORMAT = &178 ; Select a standard format DD_SET_RETRY = &160 ; Set try/retry count DD_SETUP = &15D ; Setup disk parameters DD_TEST_UNSUITABLE = &172 ; Check disk is suitable to write to DD_WRITE_SECTOR = &166 ; Write a sector RST_6 = &30 ; FP Calculator RST_5 = &28 ; FP Calculator CL_ALL = &DAF ; Clear the screen RST_3 = &18 ; Collect character RST_4 = &20 ; Collect Next character RST_1 = &8 ; Report an error RST_7 = &38 ; Maskable Interrupt Handler RST_2 = &10 ; Print A to the output stream RST_0 = &0 ; Start the computer SWAP = &5B00 ; Paging subroutine STOO = &5B10 ; Paging subroutine. Entered with interrupts disabled and AF, BC on the stack. YOUNGER = &5B21 ; Paging subroutine REGNUOY = &5B2A ; Paging subroutine ONERR = &5B3A ; Paging subroutine RAMRST = &5B5D ; RST 8 instruction used by ROM 1 to report old errors to ROM 3

7.3.1.2 - headers

Generated file for beebasm
; *************************************************************************** ; Headers for Sinclair ZX Spectrum OS ; Notes about the Sinclair ZX Spectrum operating system & memory ; Author: Peter Mount, Area51.dev & Contributors ; ; URL: https://area51.dev/sinclair/spectrum/ ; ; Modified: Sun, 23 Jan 2022 17:05:58 UTC ; ; Current version: https://area51.dev/sinclair/spectrum/reference/include/beebasm/headers.asm ; *************************************************************************** ; Tokens used to store BASIC programs in memory BAS_CODE = &AF ; CODE BAS_CLEAR = &FD ; CLEAR statement BAS_LOAD = &EF ; LOAD statement BAS_PRINT = &F5 ; PRINT statement BAS_RANDOMIZE = &F9 ; RANDOMIZE statement BAS_USR = &C0 ; USR function ; The display attributes specifying colour information DISPLAYATTR = &5800 ; The display attributes holding colour information ; The display pixel format DISPLAYFILE = &4000 ; The start of the standard Spectrum's standard screen ; System variables OLDHL = &5B52 ; Temp store while switching roms OLDBC = &5B54 ; Temp store while switching roms OLDAF = &5B56 ; Temp store while switching roms TARGET = &5B58 ; Subroutine address in ROM 3 RETADDR = &5B5A ; Return address in ROM1 BANKM = &5B5C ; Copy last byte output to Port 7FFD RAMERR = &5B5E ; Error passed from ROM 1 to 3 via RAMRST. Also used by SAVE/LOAD as temp drive store BAUD = &5B5F ; RS232 bit period in T states/26. Set by FORMAT LINE SERFL = &5B61 ; Second-character-received flag & data COL = &5B63 ; Current column from 1 to width WIDTH = &5B64 ; Paper column width TVPARS = &5B65 ; Number of inline parameters expected by RS232 FLAGS3 = &5B66 ; Various Flags BANK678 = &5B67 ; Copy of last byte output to port 1FFD XLOC = &5B68 ; Hold X location when using the unexpanded COPY command YLOC = &5B69 ; Hold Y location when using the unexpanded COPY command OLDSP = &5B6A ; Old SP (stack pointer) when TSTACK is in use. SYNRET = &5B6C ; Return address for ONERR LASTTV = &5B6E ; Last value printed by calculator RCLINE = &5B73 ; Current line being renumbered RCSTART = &5B75 ; Starting line number for renumbering RCSTEP = &5B77 ; Incremental value for renumbering LODDRV = &5B79 ; Drive for LOAD VERIFY or MERGE SAVDRV = &5B7A ; Drive for SAVE DUMPLF = &5B7B ; Holds the number of 1/216ths user for line feeds in 'COPY EXP'. If a dump cannot fit A4 set to 8 to reduce size of dump. STRIP1 = &5B7C ; Stripe 1 bitmap STRIP2 = &5B84 ; Strip2 2 bitmap. Extends to 5B8B TSTACK = &5BFF ; Temp stack (Grows DOWN from here). Used when Page 7 is switched in at top of memory while editing or using +3DOS. It can grow down to STRIP1 safely giving 115 bytes KSTATE = &5C00 ; Used for reading keyboard LASTK = &5C08 ; Stores newly pressed key REPDEL = &5C09 ; Time in 1/50s before key repeats REPPER = &5C0A ; Delay in 1/50s between key repeats KDATA = &5C0D ; Stores 2nd byte of colour controls entered from keyboard TVDATA = &5C0E ; Stores bytes of colour, AT and TAB controls going to TV STRMS = &5C10 ; Addresses of channels attached to streams CHARS = &5C36 ; 256 less than address of character set starting with space and up to (C). RASP = &5C38 ; Length of warning buzz PIP = &5C39 ; Length of keyboard click ERRNR = &5C3A ; 1 less than report code. Starts at 255 for -1 FLAGS = &5C3B ; Various flags for BASIC TVFLAG = &5C3C ; Flags associated with the TV ERRSP = &5C3D ; Address of item on machine stack to be used as error return LISTSP = &5C3F ; Address of return address from automatic listing MODE = &5C41 ; Specifies K, L, C, E or G cursor NEWPPC = &5C42 ; Line to be jumped to NSPPC = &5C44 ; Statement number in line to be jumped to. Poking first NEWPPC then NSPPC forces a jump to a specific statement in a line. PPC = &5C45 ; Line number of statement currently being executed SUBPPC = &5C47 ; Number within line of statement currently being executed BORDCR = &5C48 ; Border colour multiplied by 8; also contains attributes normally used for lower half of the screen EPPC = &5C49 ; Number of current line (with program cursor) VARS = &5C4B ; Address of variables DEST = &5C4D ; Address of variable in assignment CHANS = &5C4F ; Address of channel data CHURCHL = &5C51 ; Address of information currently being used for IO PROG = &5C53 ; Address of BASIC program NXTLIN = &5C55 ; Address of next line in program DATADD = &5C57 ; Address of terminator of last DATA item ELINE = &5C59 ; Address of command being typed in KCUR = &5C5B ; Address of cursor CHADD = &5C5D ; Address of next character after the argument of PEEK or the NEWLINE at the end of a POKE statement. XPTR = &5C5F ; Address of character after the [] marker WORKSP = &5C61 ; Address of temporary workspace STKBOT = &5C63 ; Address of bottom of calculator stack STKEND = &5C65 ; Address of start of space space BREG = &5C67 ; Calculators B register MEM = &5C68 ; Address of area used for calculators memory, usually MEMBOT FLAGS2 = &5C6A ; More flags DFSZ = &5C6B ; Number of lines (including one blank) in lower part of the screen STOP = &5C6C ; Number of the top program line in automatic listings OLDPPC = &5C6E ; Line number to which CONTINUE jumps OSPPC = &5C70 ; Number within line of statement to which CONTINUE jumps FLAGX = &5C71 ; Various flags STRLEN = &5C72 ; Length of string type destination in assignment TADDR = &5C74 ; Address of next item in syntax table SEED = &5C76 ; The seed for the RNG. Variable set using RANDOMIZE FRAMES = &5C78 ; 3 byte (least significant first) frame counter incremented every 20ms UDG = &5C7B ; Address of first user defined graphic COORDX = &5C7D ; X coordinate of last point plotted COORDY = &5C7E ; Y coordinate of last point plotted PPOSN = &5C7F ; 33 column number of printer position PRCC = &5C80 ; Full address of next position for LPRINT. Only used for ZX printer, not in 128K mode. ECHOE = &5C82 ; 33 column number & 24 line number of end of input buffer DFCC = &5C84 ; Address in display file of PRINT position DFCCL = &5C86 ; Like DFCC but for lower part of screen SPOSN = &5C88 ; 33 col & 24 line number for PRINT position SPOSNL = &5C8A ; Like SPOSN but for lower part of screen SCRCT = &5C8C ; Counts scrolls, always 1 more than number of scrolls to perform before scroll. ATTRP = &5C8D ; Permanent current colours MASKP = &5C8E ; Used for transparent colour. Any bit that is 1 shows bit taken from screen and not ATTRP ATTRT = &5C8F ; Like ATTRP but for temporary colours MASKT = &5C90 ; Like MASKP but for temporary colours PFLAG = &5C91 ; More flags MEMBOT = &5C92 ; Calculators memory area used to store numbers not convenient to store on the calculator stack NMIADD = &5CB0 ; Address of users NMI routine. Older machines NMI didn't work well so was marked as UNUSED so can cause issues on +3 if user code uses this RAMTOP = &5CB2 ; Address of last byte of BASIC system area PRAMT = &5CB4 ; Address of last byte of physical RAM SYSVAREND = &5CB6 ; Start of Channel information, usually value in (CHANS) RESERVED_MMAP = &5CC0 ; Marked reserved in 48k memory map BASE_AVAIL_MEM = &5CCB ; Base of available memory

7.3.2 - ZAsm

Files for the ZAsm assembler

7.3.2.1 - api

Generated file for zasm
; *************************************************************************** ; API for Sinclair ZX Spectrum OS ; Notes about the Sinclair ZX Spectrum operating system & memory ; Author: Peter Mount, Area51.dev & Contributors ; ; URL: https://area51.dev/sinclair/spectrum/ ; ; Modified: Sun, 23 Jan 2022 17:05:58 UTC ; ; Current version: https://area51.dev/sinclair/spectrum/reference/include/zasm/api.z80 ; *************************************************************************** DOS_FLUSH equ &142 ; Write any pending data to this drive DOS_GET_1346 equ &13C ; Set current cache/ramdisk location DOS_GET_EOF equ &139 ; Get the end of file (EOF) position DOS_GET_POSITION equ &133 ; Get the file pointer DOS_MAP_A equ &154 ; Map drive B to unit 0 or 1 DOS_OPEN_DRIVE equ &14B ; Open drive as a single file DOS_REF_XDPB equ &151 ; Point at XDPB for this drive DOS_SET_1346 equ &13F ; Rebuild the sector cache and RAM disk DOS_SET_ACCESS equ &145 ; Change access mode of an open file DOS_SET_ATTRIBUTES equ &148 ; Set a files attributes DOS_SET_MESSAGE equ &14E ; Enable/disable disk error messages DOS_SET_POSITION equ &136 ; Set the file pointer DOS_ABANDON equ &10C ; Abandon a file DOS_BOOT equ &12A ; Boot from disk DOS_CATALOG equ &11E ; Get the disk catalog DOS_CLOSE equ &109 ; Close a file DOS_DELETE equ &124 ; Delete a file DOS_FREE_SPACE equ &121 ; Get free space on drive DOS_INITIALISE equ &100 ; Initialise +3DOS DOS_OPEN equ &106 ; Open and/or Create a file DOS_READ equ &112 ; Read bytes from a file into memory DOS_READ_BYTE equ &118 ; Read byte from a file, check for soft-EOF DOS_REF_HEAD equ &10F ; Point to header data for this file DOS_RENAME equ &127 ; Get free space on drive DOS_SET_DRIVE equ &12D ; Set the default drive DOS_SET_USER equ &130 ; Set the default user DOS_VERSION equ &103 ; Return DOS issue and version numbers DOS_WRITE equ &115 ; Write bytes from memory into a file DOS_WRITE_BYTE equ &11B ; Write byte to a file DD_ASK_1 equ &17B ; Check to see if unit 1 is present DD_CHECK_SECTOR equ &169 ; Check a sector DD_DRIVE_STATUS equ &17E ; Check drive status DD_ENCODE equ &184 ; Set copy protection encode routine DD_EQUIPMENT equ &181 ; Ask what type of drive DD_FORMAT equ &16C ; Format a track DD_INIT equ &15A ; Initialise the disk driver DD_INTERFACE equ &157 ; Check for the disk drive interface DD_L_DPB equ &18A ; Initialise DPB for a given format DD_L_OFF_MOTOR equ &19C ; Turn off motor DD_L_ON_MOTOR equ &196 ; Turn on motor DD_L_READ equ &190 ; Low level uPD765A read command DD_L_SEEK equ &18D ; Seek to required track DD_L_T_OFF_MOTOR equ &199 ; Start motor off timeout DD_L_WRITE equ &193 ; Low level uPD765A write command DD_L_XDPB equ &187 ; Initialise XDPB for a given format DD_LOGIN equ &175 ; Login a new disk DD_READ_ID equ &16F ; Read a sector identifier DD_READ_SECTOR equ &163 ; Read a sector DD_SEL_FORMAT equ &178 ; Select a standard format DD_SET_RETRY equ &160 ; Set try/retry count DD_SETUP equ &15D ; Setup disk parameters DD_TEST_UNSUITABLE equ &172 ; Check disk is suitable to write to DD_WRITE_SECTOR equ &166 ; Write a sector RST_6 equ &30 ; FP Calculator RST_5 equ &28 ; FP Calculator CL_ALL equ &DAF ; Clear the screen RST_3 equ &18 ; Collect character RST_4 equ &20 ; Collect Next character RST_1 equ &8 ; Report an error RST_7 equ &38 ; Maskable Interrupt Handler RST_2 equ &10 ; Print A to the output stream RST_0 equ &0 ; Start the computer SWAP equ &5B00 ; Paging subroutine STOO equ &5B10 ; Paging subroutine. Entered with interrupts disabled and AF, BC on the stack. YOUNGER equ &5B21 ; Paging subroutine REGNUOY equ &5B2A ; Paging subroutine ONERR equ &5B3A ; Paging subroutine RAMRST equ &5B5D ; RST 8 instruction used by ROM 1 to report old errors to ROM 3

7.3.2.2 - headers

Generated file for zasm
; *************************************************************************** ; Headers for Sinclair ZX Spectrum OS ; Notes about the Sinclair ZX Spectrum operating system & memory ; Author: Peter Mount, Area51.dev & Contributors ; ; URL: https://area51.dev/sinclair/spectrum/ ; ; Modified: Sun, 23 Jan 2022 17:05:58 UTC ; ; Current version: https://area51.dev/sinclair/spectrum/reference/include/zasm/headers.z80 ; *************************************************************************** ; Tokens used to store BASIC programs in memory BAS_CODE equ &AF ; CODE BAS_CLEAR equ &FD ; CLEAR statement BAS_LOAD equ &EF ; LOAD statement BAS_PRINT equ &F5 ; PRINT statement BAS_RANDOMIZE equ &F9 ; RANDOMIZE statement BAS_USR equ &C0 ; USR function ; The display attributes specifying colour information DISPLAYATTR equ &5800 ; The display attributes holding colour information ; The display pixel format DISPLAYFILE equ &4000 ; The start of the standard Spectrum's standard screen ; System variables OLDHL equ &5B52 ; Temp store while switching roms OLDBC equ &5B54 ; Temp store while switching roms OLDAF equ &5B56 ; Temp store while switching roms TARGET equ &5B58 ; Subroutine address in ROM 3 RETADDR equ &5B5A ; Return address in ROM1 BANKM equ &5B5C ; Copy last byte output to Port 7FFD RAMERR equ &5B5E ; Error passed from ROM 1 to 3 via RAMRST. Also used by SAVE/LOAD as temp drive store BAUD equ &5B5F ; RS232 bit period in T states/26. Set by FORMAT LINE SERFL equ &5B61 ; Second-character-received flag & data COL equ &5B63 ; Current column from 1 to width WIDTH equ &5B64 ; Paper column width TVPARS equ &5B65 ; Number of inline parameters expected by RS232 FLAGS3 equ &5B66 ; Various Flags BANK678 equ &5B67 ; Copy of last byte output to port 1FFD XLOC equ &5B68 ; Hold X location when using the unexpanded COPY command YLOC equ &5B69 ; Hold Y location when using the unexpanded COPY command OLDSP equ &5B6A ; Old SP (stack pointer) when TSTACK is in use. SYNRET equ &5B6C ; Return address for ONERR LASTTV equ &5B6E ; Last value printed by calculator RCLINE equ &5B73 ; Current line being renumbered RCSTART equ &5B75 ; Starting line number for renumbering RCSTEP equ &5B77 ; Incremental value for renumbering LODDRV equ &5B79 ; Drive for LOAD VERIFY or MERGE SAVDRV equ &5B7A ; Drive for SAVE DUMPLF equ &5B7B ; Holds the number of 1/216ths user for line feeds in 'COPY EXP'. If a dump cannot fit A4 set to 8 to reduce size of dump. STRIP1 equ &5B7C ; Stripe 1 bitmap STRIP2 equ &5B84 ; Strip2 2 bitmap. Extends to 5B8B TSTACK equ &5BFF ; Temp stack (Grows DOWN from here). Used when Page 7 is switched in at top of memory while editing or using +3DOS. It can grow down to STRIP1 safely giving 115 bytes KSTATE equ &5C00 ; Used for reading keyboard LASTK equ &5C08 ; Stores newly pressed key REPDEL equ &5C09 ; Time in 1/50s before key repeats REPPER equ &5C0A ; Delay in 1/50s between key repeats KDATA equ &5C0D ; Stores 2nd byte of colour controls entered from keyboard TVDATA equ &5C0E ; Stores bytes of colour, AT and TAB controls going to TV STRMS equ &5C10 ; Addresses of channels attached to streams CHARS equ &5C36 ; 256 less than address of character set starting with space and up to (C). RASP equ &5C38 ; Length of warning buzz PIP equ &5C39 ; Length of keyboard click ERRNR equ &5C3A ; 1 less than report code. Starts at 255 for -1 FLAGS equ &5C3B ; Various flags for BASIC TVFLAG equ &5C3C ; Flags associated with the TV ERRSP equ &5C3D ; Address of item on machine stack to be used as error return LISTSP equ &5C3F ; Address of return address from automatic listing MODE equ &5C41 ; Specifies K, L, C, E or G cursor NEWPPC equ &5C42 ; Line to be jumped to NSPPC equ &5C44 ; Statement number in line to be jumped to. Poking first NEWPPC then NSPPC forces a jump to a specific statement in a line. PPC equ &5C45 ; Line number of statement currently being executed SUBPPC equ &5C47 ; Number within line of statement currently being executed BORDCR equ &5C48 ; Border colour multiplied by 8; also contains attributes normally used for lower half of the screen EPPC equ &5C49 ; Number of current line (with program cursor) VARS equ &5C4B ; Address of variables DEST equ &5C4D ; Address of variable in assignment CHANS equ &5C4F ; Address of channel data CHURCHL equ &5C51 ; Address of information currently being used for IO PROG equ &5C53 ; Address of BASIC program NXTLIN equ &5C55 ; Address of next line in program DATADD equ &5C57 ; Address of terminator of last DATA item ELINE equ &5C59 ; Address of command being typed in KCUR equ &5C5B ; Address of cursor CHADD equ &5C5D ; Address of next character after the argument of PEEK or the NEWLINE at the end of a POKE statement. XPTR equ &5C5F ; Address of character after the [] marker WORKSP equ &5C61 ; Address of temporary workspace STKBOT equ &5C63 ; Address of bottom of calculator stack STKEND equ &5C65 ; Address of start of space space BREG equ &5C67 ; Calculators B register MEM equ &5C68 ; Address of area used for calculators memory, usually MEMBOT FLAGS2 equ &5C6A ; More flags DFSZ equ &5C6B ; Number of lines (including one blank) in lower part of the screen STOP equ &5C6C ; Number of the top program line in automatic listings OLDPPC equ &5C6E ; Line number to which CONTINUE jumps OSPPC equ &5C70 ; Number within line of statement to which CONTINUE jumps FLAGX equ &5C71 ; Various flags STRLEN equ &5C72 ; Length of string type destination in assignment TADDR equ &5C74 ; Address of next item in syntax table SEED equ &5C76 ; The seed for the RNG. Variable set using RANDOMIZE FRAMES equ &5C78 ; 3 byte (least significant first) frame counter incremented every 20ms UDG equ &5C7B ; Address of first user defined graphic COORDX equ &5C7D ; X coordinate of last point plotted COORDY equ &5C7E ; Y coordinate of last point plotted PPOSN equ &5C7F ; 33 column number of printer position PRCC equ &5C80 ; Full address of next position for LPRINT. Only used for ZX printer, not in 128K mode. ECHOE equ &5C82 ; 33 column number & 24 line number of end of input buffer DFCC equ &5C84 ; Address in display file of PRINT position DFCCL equ &5C86 ; Like DFCC but for lower part of screen SPOSN equ &5C88 ; 33 col & 24 line number for PRINT position SPOSNL equ &5C8A ; Like SPOSN but for lower part of screen SCRCT equ &5C8C ; Counts scrolls, always 1 more than number of scrolls to perform before scroll. ATTRP equ &5C8D ; Permanent current colours MASKP equ &5C8E ; Used for transparent colour. Any bit that is 1 shows bit taken from screen and not ATTRP ATTRT equ &5C8F ; Like ATTRP but for temporary colours MASKT equ &5C90 ; Like MASKP but for temporary colours PFLAG equ &5C91 ; More flags MEMBOT equ &5C92 ; Calculators memory area used to store numbers not convenient to store on the calculator stack NMIADD equ &5CB0 ; Address of users NMI routine. Older machines NMI didn't work well so was marked as UNUSED so can cause issues on +3 if user code uses this RAMTOP equ &5CB2 ; Address of last byte of BASIC system area PRAMT equ &5CB4 ; Address of last byte of physical RAM SYSVAREND equ &5CB6 ; Start of Channel information, usually value in (CHANS) RESERVED_MMAP equ &5CC0 ; Marked reserved in 48k memory map BASE_AVAIL_MEM equ &5CCB ; Base of available memory