Assembly Disc Access Primer, a TatungBytes course: DISKMON reading the hidden sector IDs of the course's own practice disc, on a rainbow sunburst
← Back to Modules
module
30

Appendix II: The MOS Disc Calls, the Scratch-Pad and the Controller

The Scratch-Pad

AddressHolds
FB50hDrive (0, 1)
FB51hTrack (0-39)
FB52hSector ID - any byte
FB53h-FB54hAddress of the 512 bytes, low byte first
FB56hThe last error number (can be 3 even after a read that succeeded on a retry)
FB57hTries left: 0Ah after a first-time success
FB58h + driveThe MOS's note of where that drive's head is
FBB0hThe step rate, used with Restore and Seek

The Sector Calls

CallDoesNotes
RST 8 / DEFB 162Read one sector to FB53hStraight there, not via FE00h; any address tested
RST 8 / DEFB 163Write one sector from FB53hOn the disc when it returns. MAME: .mfi only (.dsk gives error 1)
RST 8 / DEFB 164Read a run: A drive, HL start, DE end, C track, B sectorConsecutive IDs, on to sector 0 of the next track; a sector at every 512 bytes whose address is below DE; A = 0

Success: the Z flag set (call 162 leaves A = 80h). Failure: Z clear, A = the error number - 3 for a sector that cannot be found (missing, ID not on the track, track 40), 1 for bad data - after several seconds of retries; nothing on screen. A call on an empty drive does not return.

Registers: call 162 keeps IX, IY and the alternate set, and changes A, BC, DE and HL.

The 128-Byte Calls

Calls that read a disc 128 bytes at a time.

CallGive it
RST 8 / DEFB 182 (B6h)C = drive
RST 8 / DEFB 183 (B7h)C = track
RST 8 / DEFB 184 (B8h)C = 128-byte sector, 0-39
RST 8 / DEFB 185 (B9h)BC = where the 128 bytes go
RST 8 / DEFB 186 (BAh)read: A = 0

Sector n is the (n mod 4)th quarter of 512-byte sector n ÷ 4. The whole 512-byte sector is read into FE00h-FFFFh and the quarter copied out.

Booting

Track 0 sector 0 starts with: start (2 bytes), end (2), jump (2), side (1). At power-on with a disc in drive 0 the MOS loads whole sectors, in ID order from track 0 sector 0, from start to cover end - the header included - and jumps; SP = FCFFh. No DOS: 0005h holds FFh, CALL 5 stops in the MOS's register display. Memory 0100h-FAFFh is the program's.

The Floppy Controller (WD1770)

PortWriteRead
23hDrive: 1 = drive 0, 2 = drive 1
18hCommandStatus: bit 0 busy, bit 1 a byte waiting
19hTrack register
1AhSector ID to find
1BhTrack to seek toA byte from the disc
CommandDoesSeen
00h (OR step rate)Restore: head to track 0status A4h; track register 0
10h (OR step rate)Seek to the track in 1Bhstatus A0h; track register = the track
C0hRead Address: the next ID field, 6 bytes (track, side, ID, size code 2, two check bytes)repeated: the track's IDs in the order they pass the head
80hRead Sector with the ID in 1Ah: 512 bytes from 1Bhstatus 80h

Wait for busy to come on after a command, then off. Take each byte when bit 1 is set, with interrupts off. Move a head yourself and the MOS's note at FB58h + drive is wrong: put the head back, or update the note.

Get the Newsletter

New guides, disk images and community finds, roughly once a quarter. No spam, we promise, this isn't Tatung's marketing department.
Your subscription could not be saved. Please try again.
Your subscription has been successful.

Newsletter

Subscribe to our newsletter and stay updated.

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.