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

Return to the regular view of this page.

Essential API

+3DOS Essential API

Table of Contents

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.

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.

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.

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.

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

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.

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.

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.

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.

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.

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.

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.

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.

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

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.

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.