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
22

Data on Demand

Introduction

Blackwater Hall keeps its text on disc and reads a record whenever it needs one, with BDOS function 33. DISKMON's R did the same in S9. With no DOS there is no function 33, but there is everything it did.

Record Number to Sector

A file's records are numbered from 0. With 128 records to an extent, 16 to a block and 4 to a sector:

StepSumRecord 150
Extentrecord ÷ 1281
Record in the extentrecord mod 12822
Which of the entry's 8 blocks(record mod 128) ÷ 161 - the second
Which of the block's 4 sectors(record mod 16) ÷ 41
Where in the sector(record mod 4) × 128256

Each divisor is a power of two, so the sums are shifts and masks - no DIV10 needed until the block becomes a track and sector (S17's BLKSEC). If the record in the extent is not less than the entry's record count, there is no such record.

The Code

After the line JP Z,CMDB, add:

        CP 'J'
        JP Z,CMDJ

After the last line of CMDB1 (JP DONE), add:

; J d name n: record n of a file, found by hand - Blackwater's way of
; reading its data, with no DOS.
CMDJ:   CALL FINDSET
        CALL GETNUM
        JP C,WHAT
        LD (RECNO),HL
        ADD HL,HL               ; extent = record / 128
        LD A,H
        LD (EXTENT),A
        CALL FINDEXT
        LD HL,NOEXTM
        JP NZ,DONE
        LD A,(RECNO)
        AND 7FH                 ; record within the extent
        CP (IX+15)
        LD HL,NORECM
        JP NC,DONE
        LD C,A
        RRCA                    ; block index = (record mod 128) / 16
        RRCA
        RRCA
        RRCA
        AND 07H
        ADD A,A
        ADD A,16
        LD E,A
        LD D,0
        PUSH IX
        POP HL
        ADD HL,DE
        LD E,(HL)
        INC HL
        LD D,(HL)
        LD A,C                  ; sector within the block = (record mod 16) / 4
        RRCA
        RRCA
        AND 03H
        PUSH BC
        LD C,A
        CALL BLKSEC
        CALL READSEC
        POP BC
        JP NZ,DISCERR
        LD A,C                  ; place in the sector = (record mod 4) x 128
        AND 03H
        LD H,A
        LD L,0
        SRL H
        RR L
        LD DE,SECBUF
        ADD HL,DE
        LD BC,128
        CALL SHOWBLK
        JP MAIN

After the line STOPM: DEFB 'STOPPED',13,10,0, add:

RECNO:  DEFW 0

Run it booted from work.mfi (S20, B from this version):

J 0 ROOMS.DAT 150
J 0 ROOMS.DAT 200
L 0 POEM.TXT

What you should see

> J 0 ROOMS.DAT 150
0000 52 4F 4F 4D 20 31 35 30 ROOM 150
0008 3A 20 41 20 44 55 53 54 : A DUST
0010 59 20 48 41 4C 4C 2E 20 Y HALL.
0018 20 20 20 20 20 20 20 20
0020 20 20 20 20 20 20 20 20
0028 20 20 20 20 20 20 20 20
0030 20 20 20 20 20 20 20 20
0038 20 20 20 20 20 20 20 20
0040 20 20 20 20 20 20 20 20
0048 20 20 20 20 20 20 20 20
0050 20 20 20 20 20 20 20 20
0058 20 20 20 20 20 20 20 20
0060 20 20 20 20 20 20 20 20
0068 20 20 20 20 20 20 20 20
0070 20 20 20 20 20 20 20 20
0078 20 20 20 20 20 20 20 20
>

The same 128 bytes R read through the BDOS in S9. Then:

> J 0 ROOMS.DAT 200
NO SUCH RECORD
> L 0 POEM.TXT
THE DISC
Forty tracks go round and round,
ten sectors on each one;
the directory shows what can be found,
and blocks say where they've gone.

Ask the DOS and it will look
the name up for you, line by line;
or read the sectors like a book
and all the work is yours and mine.

>

Change One Thing

  • Work out by hand where record 37 of ROOMS.DAT is, then check with J and with S.
  • J reads a whole sector to get one record. If you wanted records 148, 149, 150 and 151, how many sectors would you need to read?

Summary

Record number → extent, block, sector, offset: five small sums, and DISKMON fetches any record of any file with no DOS at all.

Next

S23 looks back at what the DOS was doing, and on to Part five.

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.