Separate out headers for structures

This commit is contained in:
Nero 2019-10-30 13:10:23 +00:00
parent a49e3b2610
commit b164c79f42
5 changed files with 87 additions and 24 deletions

View File

@ -50,7 +50,7 @@ com/%.com: com/%.asm
$(NASM) $(NASM_ARGS) -o $@ $<
bdos/%.bin: bdos/%.asm lib/*.asm
$(NASM) $(NASM_ARGS) -o $@ -I bdos $<
$(NASM) $(NASM_ARGS) -o $@ $<
bios/%.bin: bios/%.asm
$(NASM) $(NASM_ARGS) -o $@ $<

View File

@ -1,18 +1,15 @@
ORG BDOS
%include "bios/header.asm"
%include "hdr/bios.asm"
%include "hdr/fcb.asm"
%include "hdr/bpb.asm"
DISKBUF: EQU (BDOS-0x200) ; deblocking
STACK: EQU (DISKBUF) ; grows down
DEFDRV: EQU 4
DISKBPB: EQU (DISKBUF-21) ; BPB of the current driv
DISKDRV: EQU (DISKBPB-1) ; BYTE denoting drive of current fcb
STACK: EQU (DISKDRV & 0xFFFE) ; even address, grows down
FCB_DRV: EQU 0 ; BYTE 0=A: 1=B: 2=C: ...
FCB_NAM: EQU 1 ; 8 BYTES, space padded
FCB_EXT: EQU 9 ; 3 BYTES, space padded
FCB_TYP: EQU 12 ; 1 for regular file
FCB_BLK: EQU 13 ; current 128b block in sector
FCB_CLU: EQU 14 ; current sector
FCB_LFT: EQU 16 ; bytes left to read in current file
DEFDRV: EQU 4 ; default drive when opening a FCB
SYSCALL:
TEST CL, CL
@ -25,8 +22,9 @@ SYSCALL:
JE PUTS
CMP CL, 10
JE GETS
STC
RET
CMP CL, 11
JE STATUS
JMP SYSCALL2
SETUP:
MOV SP, STACK
@ -34,16 +32,10 @@ SETUP:
MOV CX, DISKBUF
CALL SETDMA
MOV DL, BYTE [DEFDRV]
ADD DL, '@'
CALL PUTC
MOV DL, '>'
CALL PUTC
MOV CL, 0x00
CALL LOADBPB
MOV DX, 0x7F
MOV BYTE [0x7F], 0x2F
MOV BYTE [0x80], 2
CALL GETS
MOV AX, [DISKBPB]
INT3
@ -63,8 +55,7 @@ GETC:
ret
PUTC:
CALL CONOUT
RET
JMP CONOUT
PUTS:
PUSH SI
@ -134,3 +125,53 @@ GETS_BS:
CALL PUTC
DEC CL
JMP GETS_L
STATUS:
JMP CONST
SYSCALL2:
CMP CL, 13
JE DISKRST
CMP CL, 14
JE SETDEFDSK
CMP CL, 15
RET
DISKRST:
MOV BYTE [DISKDRV], 0xFF
RET
SETDEFDSK:
MOV BYTE [DEFDRV], DL
RET
; IN CL drive num
LOADBPB:
PUSH CX
CALL SELDSK
; first track
MOV CX, 0
CALL SETTRK
; first sector
MOV CX, 1
CALL SETSEC
; into default diskbuf
MOV CX, DISKBUF
CALL SETDMA
CALL READ
; copy BPB
PUSH SI
PUSH DI
MOV CX, 21
MOV SI, DISKBUF+0x0B
MOV DI, DISKBPB
REP MOVSB
POP DI
POP SI
; store drive number
POP CX
MOV BYTE [DISKDRV], CL
RET
FCBOPEN:
RET

12
hdr/bpb.asm Normal file
View File

@ -0,0 +1,12 @@
; BPB from first sector on FAT fs, starting 0x0B
BPB_SS: EQU 0 ; WORD sector size
BPB_SC: EQU 2 ; BYTE sectors per cluster
BPB_RSC: EQU 3 ; WORD reserved sector count
BPB_FN: EQU 5 ; BYTE number of FATs
BPB_RDE: EQU 6 ; WORD number of root directory entries
BPB_TS: EQU 8 ; WORD total number of sectors
BPB_MI: EQU 10 ; BYTE medium identifier
BPB_SF: EQU 11 ; WORD sectors per FAT
BPB_SPT: EQU 13 ; WORD sectors per track
BPB_NOS: EQU 15 ; WORD number of sides/heads
BPB_PO: EQU 17 ; DWORD partition offset

10
hdr/fcb.asm Normal file
View File

@ -0,0 +1,10 @@
; File control block
FCB_DRV: EQU 0 ; BYTE 0=A: 1=B: 2=C: ...
FCB_NAM: EQU 1 ; 8 BYTES, space padded
FCB_EXT: EQU 9 ; 3 BYTES, space padded
FCB_TYP: EQU 12 ; BYTE FCB type
; TYP=1: regular file
FCB_BLK: EQU 13 ; current 128b block in sector
FCB_CLU: EQU 14 ; current sector
FCB_LFT: EQU 16 ; bytes left to read in current file
FCB_END: EQU 20 ; FCB length