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
15

What a Call Leaves Behind, and What Goes Wrong

Introduction

DISKMON has called the MOS without checking anything. Two questions every call raises: which of my registers are still mine afterwards, and how do I know it worked?

What Call 162 Keeps

After call 162, IX, IY and the alternate registers (AF', BC', DE', HL') are as you left them. A, BC, DE and HL are not - keep anything you need in them on the stack, as READDIR will in S16.

Did It Work?

The Z flag. Set, the sector was read. Clear, it was not. Test it with JP NZ straight after the call.

Do not test A for 0: a successful read leaves A = 80h. On failure A holds an error number, the same one the MOS leaves in its scratch-pad at FB56h:

NumberMeans
3No sector: the ID is not on that track, or the track is not on the disc
1Bad data

When a sector will not read, the MOS tries again - several seconds of trying - before it gives up and returns. It prints nothing: deciding what to do is your program's job. That is the great difference from the BDOS in S12.

One case does not come back at all: asking for a drive with no disc in it. Make sure there is a disc there.

The Code

DISCERR prints the number and, for 3 and 1, what it means. S jumps there on NZ:

After the line CMDS1: CALL READSEC, add:

        JP NZ,DISCERR

After the line JP CMDS1, add:

; DISCERR: the MOS said no. A holds its error number.
DISCERR: PUSH AF
        LD HL,DERRM
        CALL PRINT
        POP AF
        PUSH AF
        CALL PHEX
        POP AF
        CP 3
        LD HL,NOSECM
        JP Z,DONE
        CP 1
        LD HL,BADM
        JP Z,DONE
        JP CRMAIN

After the line SSEC: DEFB 0, add:

DERRM:  DEFB 'DISC ERROR ',0
NOSECM: DEFB ': NO SECTOR',13,10,0
BADM:   DEFB ': BAD DATA',13,10,0

Run it on a copy of PRIMER.DSK:

S 1 2 10
S 1 40 0

What you should see (each after a pause while the MOS tries)

> S 1 2 10
DISC ERROR 03: NO SECTOR
> S 1 40 0
DISC ERROR 03: NO SECTOR
>

There is no sector 10 on an Einstein track, and no track 40.

Change One Thing

  • Put PUSH IX / POP IX round the RST 8 in READSEC. Is it needed?
  • Change JP NZ,DISCERR to JP C,DISCERR. What will S 1 2 10 do?

When It Goes Wrong

SymptomCause
DISKMON stops responding after S 1 ...No disc in drive 1: the call never returns. Reset MAME

Summary

Call 162 keeps IX, IY and the alternate set; the Z flag says whether it read the sector; on failure A (and FB56h) holds the reason, and your program decides what to do.

Next

S16: DISKMON reads the directory itself and lists the files.

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.