Direct Disk Sector Reader

Type
Utility
Category
Disk utility
Author
David Small
Published in
The Creative Atari (Creative Computing Press, 1983), "Atari Diskfile Tutorial – Part III", Program 1
Year
1983
Language
Atari BASIC
Requirements
Any Atari 8-bit, Atari BASIC, Atari 810 or compatible disk drive as D1:

About the program

Part III of The Creative Atari's disk tutorial goes underneath DOS. A disk is just 720 sectors of 128 bytes, and the operating system has a resident disk handler that will fetch any one of them on request. To use it, you fill in the Device Control Block (DCB) at location 768 and call the handler's entry point, DSKINV. Program 1, dated 21 December 1981 in its REMs and written by David Small, does exactly that from BASIC. Type a sector number and it shows you what is stored there: boot code, the VTOC, directory entries or file data, complete with the three DOS link bytes at the end of each sector.

What you need

  • Any Atari 8-bit with Atari BASIC.
  • A disk drive set up as drive 1, with a disk in it. The program only reads, never writes, so any disk is safe. On an emulator, attach an ATR image to D1:.

Typing it in

Plain ASCII, 38 lines. Lines 230–270 build a five-byte machine-language routine one character at a time with CHR$, so there are no special characters to type. Line 50 fills the 128-byte buffer with spaces. Make sure the quotes contain exactly one space.

How to use it

RUN it and type a sector number (1–720) at the prompt. The program prints "DISK STATUS=" (1 means OK) and then the sector's 128 bytes as characters. Good sectors to try: 1–3 (the boot sectors), 360 (the DOS 2 VTOC, which holds the free-sector map) and 361–368 (the directory, where you can read the file names). It then asks for another sector. Press BREAK to stop.

The data is printed raw. A byte that happens to be a control code, such as 125 (clear screen) or 156 (delete line), is executed by the screen editor, so the display can jump about. That is normal.

How it works

  • The DCB is at 768–779 ($300–$30B). Line 20 sets the unit number (DUNIT, 769) to 1, and line 30 sets the command (DCOMND, 770) to 82, which is $52, "get sector". The article's table also lists $50/$57 (put sector without/with verify), $53 (status) and $21 (format).
  • Lines 60–100 put the address of BUFFER$ into DBUFLO/DBUFHI (772–773), so the sector lands directly in the string.
  • Lines 140–170 split the sector number into DAUX1/DAUX2 (778–779).
  • Lines 230–270 make CALL$ = PLA, JSR $E453, RTS. The PLA discards BASIC's USR argument count, and $E453 is DSKINV, the OS disk-handler entry. (The REM says "JMP", but the code is a JSR followed by RTS.)
  • After the call, line 310 reads the result code from DSTATS (771).

Variations to try

  • Print the bytes as numbers (FOR I=1 TO 128:? ASC(BUFFER$(I,I));" ";:NEXT I) for a proper hex/decimal dump without control-code surprises.
  • Decode the last three bytes of a DOS file sector, as the article's Table 2 describes. Byte 126 holds the file number (six bits) plus the top two bits of the forward pointer to the next sector, byte 127 holds the rest of that pointer, and byte 128 counts the bytes used in a short (not completely full) sector.
  • With command 87 ($57, put sector with verify) you could write sectors too. Only try that on a scratch disk!

Listing

5 REM SAMPLE PROGRAM TO DO DIRECT
6 REM DISK I/O. DAVID SMALL,12/21/81
7 REM
10 DCB=768:REM START OF DISK DC3
20 POKE DCB+1,1:REM DISK 1
30 POKE DCB+2,82:REM $52 = GET SECTOR
35 REM *** GET 128 BYTE OPEN BUFFER
40 DIM BUFFER$(128)
45 DIM CALL$(10)
50 FOR X=1 TO 128:BUFFER$(X)=" ":NEXT X
60 ADDR=ADR(BUFFER$)
70 ADDRHI=INT(ADDR/256)
80 ADDRLO=ADDR-(ADDRHI*256)
90 POKE DCB+4,ADDRLO:REM BUFFER ADR LOW
100 POKE DCB+5,ADDRHI:REM BUFFER ADR HI
110 REM *** SECTOR NUMBER ***
120 PRINT "INPUT SECTOR NUMBER"
130 INPUT SECTOR
140 SECTORHI=INT(SECTOR/256)
150 SECTORLO=SECTOR-(SECTORHI*256)
160 POKE DCB+10,SECTORLO
170 POKE DCB+11,SECTORHI
200 REM *** BUILD SHORT ASSY PROGRAM
210 REM *** OF PLA, JMP DSKINV.
230 CALL$(1)=CHR$(104):REM PLA
240 CALL$(2)=CHR$(32):REM JSR
250 CALL$(3)=CHR$(83):REM $53
260 CALL$(4)=CHR$(228):REM $E4
270 CALL$(5)=CHR$(96):REM RTS
300 X=USR(ADR(CALL$))
310 DSTATS=PEEK(DCB+3)
320 PRINT "DISK STATUS=";DSTATS;" (1=OK)"
330 PRINT "DATA:"
340 PRINT BUFFER$
341 REM *** CLEAN OUT BUFFER$
342 FOR X=1 TO 128:BUFFER$(X)=" ":NEXT X
350 GOTO 110
400 END

Credits