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
27

What Is on This Track?

Introduction

Every sector on the disc carries an ID field in front of it: the track, the side, the sector's ID and its size. The controller reads these all the time as the disc turns, to find the sector it has been asked for. One command hands them to you.

Read Address

Write C0h to port 18h and the controller waits for the next ID field to come round, then gives you its six bytes, one at a time through port 1Bh:

ByteHolds
0Track
1Side
2Sector ID
3Size code (2 for 512 bytes)
4-5A check value

Each time status bit 1 is set, a byte is waiting at 1Bh: read it. When bit 0 (busy) goes off, the command is over.

Do it again and you get the next ID round the track - so twenty in a row give you the track's IDs in order, twice over, starting from wherever the head happened to be. That order is what neither the BDOS nor the MOS can tell you.

The Message

The person who protected Dragon's Lair hid a message in its IDs: read round the tracks in order, they begin Congratulations! Award yourself ONE Hacking-point! - and the game's loader uses the same text as its list of sectors to read, so a copy made with ordinary sector numbers will not load. A BASIC program of the time can find which IDs a track has, by asking for each of the 256 possible IDs in turn - minutes per track, and in alphabetical order. A machine-code program with Read Address gets them in the order they go round, in a moment.

SECRET.DSK has a message of its own on tracks 30 to 33.

The Code

I d t: select, Restore, Seek to t, twenty Read Addresses - keeping byte 2 of each - then put the head back where the MOS thinks it is, and show the IDs as characters and in hex.

After the line JP Z,CMDG, add:

        CP 'I'
        JP Z,CMDI

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

; I d t: the IDs on drive d's track t, in the order they pass the head,
; with Read Address - twenty of them, so you see the round twice.
CMDI:   CALL GETNUM
        JP C,WHAT
        LD (SDRV),A
        CALL GETNUM
        JP C,WHAT
        LD (STRK),A
        CALL FDCSEL
        CALL FDCHOME
        CALL FDCSEEK
        LD HL,RECBUF
        LD B,20
CMDI1:  PUSH BC
        LD A,0C0H               ; Read Address: 6 bytes from the next ID
        OUT (18H),A
        CALL BUSYON
        LD DE,RECBUF+120        ; the 6 bytes land here
        LD B,6
CMDI2:  IN A,(18H)
        BIT 1,A                 ; bit 1: a byte is waiting
        JR NZ,CMDI3
        BIT 0,A
        JR NZ,CMDI2
        JR CMDI4
CMDI3:  IN A,(1BH)
        LD (DE),A
        INC DE
        DJNZ CMDI2
CMDI4:  CALL FDCWAIT
        LD A,(RECBUF+122)       ; the third byte is the sector ID
        LD (HL),A
        INC HL
        POP BC
        DJNZ CMDI1
        CALL PUTBACK
        LD HL,IDSM
        CALL PRINT
        LD HL,RECBUF            ; as characters...
        LD B,20
CMDI5:  LD A,(HL)
        CALL PCHAR
        INC HL
        DJNZ CMDI5
        CALL NEWLINE
        LD HL,RECBUF            ; ...and in hex
        LD BC,20
        CALL SHOWBLK
        JP MAIN

After the line TRIESM: DEFB 'TRIES ',0, add:

IDSM:   DEFB 'IDS: ',0

Run it with a copy of SECRET.DSK in drive 1:

I 1 30
I 1 31
I 1 32
I 1 33

What you should see

> I 1 30
IDS: WELL DONE:WELL DONE:
0000 57 45 4C 4C 20 44 4F 4E WELL DON
0008 45 3A 57 45 4C 4C 20 44 E:WELL D
0010 4F 4E 45 3A             ONE:
> I 1 31
IDS:  HAVE  YOU HAVE  YOU
0000 20 48 41 56 45 20 20 59  HAVE  Y
0008 4F 55 20 48 41 56 45 20 OU HAVE
0010 20 59 4F 55              YOU
> I 1 32
IDS:  THE FOUND THE FOUND
0000 20 54 48 45 20 46 4F 55  THE FOU
0008 4E 44 20 54 48 45 20 46 ND THE F
0010 4F 55 4E 44             OUND
> I 1 33
IDS: N IDSHIDDEN IDSHIDDE
0000 4E 20 49 44 53 48 49 44 N IDSHID
0008 44 45 4E 20 49 44 53 48 DEN IDSH
0010 49 44 44 45             IDDE
>

Each track's ten IDs, round twice, starting wherever the head came in. Find where each round begins, and read them in turn.

Change One Thing

  • I 0 2 - the system disc's directory track. What order do its IDs go round in?
  • Keep all six bytes of each Read Address instead of only byte 2, and show them. What are the track, side and size codes of SECRET.DSK's track 32?

Summary

Read Address gives the next ID field under the head. Repeated, it lists a track's real IDs in their real order - and that is how a message hidden in sector IDs is read.

Next

S28 reads a sector's 512 bytes through the ports, the last thing the MOS was doing for you.

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.