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
28

A Sector by Hand

Introduction

There is one thing left that the MOS does for DISKMON: actually reading a sector's bytes. Here it is, with the controller and nothing else.

Read Sector

  1. Select the drive, put the head on the track (S25).
  2. Write the sector's ID to port 1Ah.
  3. Write 80h, Read Sector, to port 18h.
  4. Loop: whenever status bit 1 is set, take a byte from 1Bh and store it; when bit 0 goes off, stop.

The disc does not wait. Once the sector starts passing under the head the bytes come one after another, and each must be taken before the next arrives - so the loop is short, and interrupts are off. DISKMON counts the bytes, so you can see that all 512 arrived, and shows the final status.

The Code

H d t s - the sector may be a number or a letter, as for S:

After the line JP Z,CMDI, add:

        CP 'H'
        JP Z,CMDH

After the last line of CMDI5 (JP MAIN), add:

; H d t s: read a sector through the controller's ports, byte by byte.
CMDH:   CALL GETDTS
        JP C,WHAT
        CALL FDCSEL
        CALL FDCHOME
        CALL FDCSEEK
        LD A,(SSEC)
        OUT (1AH),A             ; the ID to look for
        LD HL,SECBUF
        LD DE,0
        LD A,80H                ; Read Sector
        OUT (18H),A
        CALL BUSYON
CMDH1:  IN A,(18H)
        BIT 1,A
        JR NZ,CMDH2
        BIT 0,A
        JR NZ,CMDH1
        JR CMDH3
CMDH2:  IN A,(1BH)
        LD (HL),A
        INC HL
        INC DE
        JR CMDH1
CMDH3:  LD (COUNT),DE
        PUSH AF
        CALL PUTBACK
        LD HL,STATM
        CALL PRINT
        POP AF
        CALL PHEX
        LD HL,BYTESM
        CALL PRINT
        LD HL,(COUNT)
        CALL PDEC
        CALL NEWLINE
        LD HL,SECBUF
        LD BC,512
        CALL SHOWBLK
        JP MAIN

After the line IDSM: DEFB 'IDS: ',0, add:

STATM:  DEFB 'STATUS ',0
BYTESM: DEFB ' BYTES ',0

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

H 1 30 W

What you should see

> H 1 30 W
STATUS 80 BYTES 512
0000 54 52 41 43 4B 20 33 30 TRACK 30
0008 3A 20 54 48 49 53 20 53 : THIS S
0010 45 43 54 4F 52 27 53 20 ECTOR'S
0018 49 44 20 49 53 20 27 57 ID IS 'W
0020 27 20 28 35 37 48 29 0D ' (57H).
0028 0A 1A 1A 1A 1A 1A 1A 1A ........
0030 1A 1A 1A 1A 1A 1A 1A 1A ........
0038 1A 1A 1A 1A 1A 1A 1A 1A ........
0040 1A 1A 1A 1A 1A 1A 1A 1A ........
0048 1A 1A 1A 1A 1A 1A 1A 1A ........
0050 1A 1A 1A 1A 1A 1A 1A 1A ........
0058 1A 1A 1A 1A 1A 1A 1A 1A ........
0060 1A 1A 1A 1A 1A 1A 1A 1A ........
0068 1A 1A 1A 1A 1A 1A 1A 1A ........
0070 1A 1A 1A 1A 1A 1A 1A 1A ........
0078 1A 1A 1A 1A 1A 1A 1A 1A ........
  (KEY)

512 bytes, status 80h, and the same sector S 1 30 W read through the MOS in S24.

Change One Thing

  • H 1 2 0, then S 1 2 0. Should the two show the same bytes?
  • Take out CALL PUTBACK in CMDH, run H 1 30 W, then S 1 3 0. How many tries will S report (S26)?

Summary

Read Sector, with the bytes taken one by one at port 1Bh: DISKMON reads a sector with no help from the BDOS or the MOS.

Next

That is the whole of DISKMON. Appendix III has it in full; Appendices I and II gather what the primer measured about the BDOS and the MOS.

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.