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

Return to the regular view of this page.

Low Level API

+3DOS Low Level API

Table of Contents

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.

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.

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.

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

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.

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

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.

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

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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

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

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.

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.

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.