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
13

Your First Sector

Introduction

Part two let the BDOS do all the work: you named a file, it found it. Now DISKMON goes to the MOS - the routines in the Einstein's ROM, there whether or not a DOS is loaded. The MOS does not know about files. It reads sectors.

The Scratch-Pad and Call 162

The MOS keeps a small working area in memory from FB00h, the scratch-pad. Five bytes of it say which sector to read and where to put it:

AddressHolds
FB50hThe drive: 0 or 1
FB51hThe track: 0-39
FB52hThe sector's ID
FB53h-FB54hWhere the 512 bytes go: low byte first

Fill them in, then RST 8 with DEFB 162, and the sector is read straight to that address.

The Code

S d t s: three numbers into SDRV, STRK and SSEC (GETDTS), then READSEC - SETPAD copies them into the scratch-pad with SECBUF as the address - and SHOWBLK shows the 512 bytes, 128 at a time.

After the line JP Z,CMDP, add:

        CP 'S'
        JP Z,CMDS

After the last line of NEEDDOS (RET), add:

; ----------------------------------------------------------------- MOS
; S d t s: read drive d, track t, sector s and show it.
CMDS:   CALL GETDTS
        JP C,WHAT
CMDS1:  CALL READSEC

After the line CMDS1: CALL READSEC, add:

        LD HL,SECBUF
        LD BC,512
        CALL SHOWBLK
        JP MAIN

; GETDTS: drive, track, sector from the line into SDRV, STRK, SSEC.
GETDTS: CALL GETNUM
        RET C
        LD (SDRV),A
        CALL GETNUM
        RET C
        LD (STRK),A

After the line LD (STRK),A, add:

        CALL GETNUM
        RET C
        LD (SSEC),A
        RET

; READSEC: MOS call 162 - the sector in SDRV/STRK/SSEC to SECBUF.
; Z set if it was read.
READSEC: CALL SETPAD
        RST 8
        DEFB 162
        RET

; SETPAD: the MOS's scratch-pad: drive, track, sector, address.
SETPAD: LD A,(SDRV)
        LD (0FB50H),A
        LD A,(STRK)
        LD (0FB51H),A
        LD A,(SSEC)
        LD (0FB52H),A
        LD HL,SECBUF
        LD (0FB53H),HL
        RET

After the line NOEXTM: DEFB 'NO SUCH EXTENT',13,10,0, add:

SDRV:   DEFB 0
STRK:   DEFB 0
SSEC:   DEFB 0

Run it on a copy of PRIMER.DSK:

S 1 2 0

Press a key at each (KEY).

What you should see - the first 128 bytes:

> S 1 2 0
0000 00 50 4F 45 4D 20 20 20 .POEM
0008 20 54 58 54 00 00 00 03  TXT....
0010 01 00 00 00 00 00 00 00 ........
0018 00 00 00 00 00 00 00 00 ........
0020 00 52 4F 4F 4D 53 20 20 .ROOMS
0028 20 44 41 54 00 00 00 80  DAT....
0030 02 00 03 00 04 00 05 00 ........
0038 06 00 07 00 08 00 09 00 ........
0040 00 52 4F 4F 4D 53 20 20 .ROOMS
0048 20 44 41 54 01 00 00 48  DAT...H
0050 0A 00 0B 00 0C 00 0D 00 ........
0058 0E 00 00 00 00 00 00 00 ........
0060 00 44 49 53 4B 4D 4F 4E .DISKMON
0068 20 43 4F 4D 00 00 00 0B  COM....
0070 0F 00 00 00 00 00 00 00 ........
0078 00 00 00 00 00 00 00 00 ........
  (KEY)

That is the directory - track 2, sector 0 - exactly as edisc.py dump PRIMER.DSK 2 0 shows it, with DISKMON.COM in the fourth entry. No FCB, no open, no DOS call: DISKMON asked the MOS for a sector and got it.

Change One Thing

  • S 1 2 1. What should the next 512 bytes of the directory hold on a disc with four files?
  • Find POEM.TXT's block number in what you just read. Which track and sector hold its text (S3)? Read it with S.
  • S 0 2 0. Whose directory is that?

Summary

Five scratch-pad bytes and RST 8 / DEFB 162 read any sector to any address. DISKMON can now look at a disc's raw bytes.

Next

S14 reads sectors whose IDs are not in order, and steps through a disc.

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.