rdos/bdos/8086.asm

234 lines
3.1 KiB
NASM
Raw Normal View History

ORG BDOS
2019-10-30 14:10:23 +01:00
%include "hdr/bios.asm"
%include "hdr/fcb.asm"
%include "hdr/bpb.asm"
DISKBUF: EQU (BDOS-0x200) ; deblocking
2019-10-30 14:10:23 +01:00
DISKBPB: EQU (DISKBUF-21) ; BPB of the current driv
2019-11-04 14:10:50 +01:00
DISKDRV: EQU (DISKBPB-1) ; BYTE denoting drive of current fcb (1=A, ...)
2019-10-30 14:10:23 +01:00
STACK: EQU (DISKDRV & 0xFFFE) ; even address, grows down
2019-11-04 14:10:50 +01:00
DEFDRV: EQU 4 ; default drive when opening a FCB (1=A, ...)
SYSCALL:
TEST CL, CL
JE SETUP
CMP CL, 1
JE GETC
CMP CL, 2
JE PUTC
CMP CL, 9
JE PUTS
CMP CL, 10
JE GETS
2019-10-30 14:10:23 +01:00
CMP CL, 11
JE STATUS
JMP SYSCALL2
SETUP:
MOV SP, STACK
MOV BYTE [DEFDRV], 0x01
MOV CX, DISKBUF
CALL SETDMA
2019-11-04 14:10:50 +01:00
SUB SP, 0x20
MOV BX, SP
CALL FCBOPEN
CLI
HALT:
HLT
JMP HALT
GETC:
CALL CONIN
TEST AL, AL
JZ GETC
PUSH DX
MOV DL, AL
CALL CONOUT
POP DX
ret
PUTC:
2019-10-30 14:10:23 +01:00
JMP CONOUT
PUTS:
PUSH SI
MOV SI, DX
PUTS_L:
MOV DL, BYTE [SI]
CMP DL, '$'
JZ PUTS_E
CALL CONOUT
INC SI
JMP PUTS_L
PUTS_E:
POP SI
RET
; BX base ptr to buffer
; CH maximum BL
; CL minimum BL
GETS:
PUSH AX
PUSH CX
PUSH DX
PUSH BX
; BX is base pointer
MOV BX, DX
; CL is maximum, CH is current position
MOV CX, [BX]
XOR CH, CH
; BX starts at actual character area
ADD BX, 2
GETS_L:
; Read and maybe handle control chars
CALL GETC
CMP AL, 0x0D
JE GETS_E
CMP AL, 8
JE GETS_BS
; Store character
PUSH BX
ADD BL, CH
ADC BH, 0
MOV [BX], AL
POP BX
; Loop if we arent full yet
INC CH
CMP CH, CL
JC GETS_L
GETS_E:
; Append LF to CR
MOV DL, 0x0A
CALL PUTC
; Write back length data
SUB BX, 2
MOV [BX], CX
; Restore registers
POP BX
POP DX
POP CX
POP AX
ret
GETS_BS:
TEST CH, CH
JZ GETS_L
MOV DL, 0x20
CALL PUTC
MOV DL, 8
CALL PUTC
DEC CL
JMP GETS_L
2019-10-30 14:10:23 +01:00
STATUS:
JMP CONST
SYSCALL2:
CMP CL, 13
JE DISKRST
CMP CL, 14
JE SETDEFDSK
CMP CL, 15
2019-11-04 14:10:50 +01:00
JE FCBOPEN
RET:
2019-10-30 14:10:23 +01:00
RET
DISKRST:
MOV BYTE [DISKDRV], 0xFF
RET
SETDEFDSK:
MOV BYTE [DEFDRV], DL
RET
2019-11-04 14:10:50 +01:00
FCBOPEN:
MOV CL, BYTE [BX]
TEST CL, CL
JNZ NODEFDRV
MOV CL, BYTE [DEFDRV]
MOV BYTE [BX], CL
NODEFDRV:
CALL LOADBPB
CALL FATSIZE
ADD DX, WORD [DISKBPB+BPB_RSC]
CALL SETLSEC
CALL READ
MOV AX, [DISKBUF]
INT3
; TODO: search for file in rootdir
; TODO: init cluster number
RET
; Set logical sector number
; IN DX sector number
SETLSEC:
PUSH AX
PUSH CX
PUSH DX
XOR AX, AX
XCHG AX, DX
DIV WORD [DISKBPB+BPB_SPT]
MOV CX, AX
CALL SETTRK
MOV CX, DX
INC CX
CALL SETSEC
POP DX
POP CX
POP AX
RET
; OUT DX number of sectors by all FATs
FATSIZE:
PUSH AX
MOV DL, BYTE [DISKBPB+BPB_FN]
MOV AL, BYTE [DISKBPB+BPB_SF]
MUL DL
XCHG AX, DX
POP AX
RET
; IN CL drive num, 1=A, 2=B, 3=C
2019-10-30 14:10:23 +01:00
LOADBPB:
2019-11-04 14:10:50 +01:00
CMP BYTE [DISKDRV], CL
JE RET
2019-10-30 14:10:23 +01:00
PUSH CX
2019-11-04 14:10:50 +01:00
DEC CL
2019-10-30 14:10:23 +01:00
CALL SELDSK
; first track
MOV CX, 0
CALL SETTRK
; first sector
MOV CX, 1
CALL SETSEC
; into default diskbuf
MOV CX, DISKBUF
CALL SETDMA
2019-11-04 14:10:50 +01:00
POP CX
2019-10-30 14:10:23 +01:00
CALL READ
2019-11-04 14:10:50 +01:00
JC DISKRST
2019-10-30 14:10:23 +01:00
; copy BPB
2019-11-04 14:10:50 +01:00
PUSH CX
2019-10-30 14:10:23 +01:00
PUSH SI
PUSH DI
MOV CX, 21
MOV SI, DISKBUF+0x0B
MOV DI, DISKBPB
REP MOVSB
POP DI
POP SI
POP CX
2019-11-04 14:10:50 +01:00
; store drive number
MOV BYTE [DISKDRV], CL
2019-10-30 14:10:23 +01:00
RET