rdos/bdos/8086.asm

178 lines
2.3 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
DISKDRV: EQU (DISKBPB-1) ; BYTE denoting drive of current fcb
STACK: EQU (DISKDRV & 0xFFFE) ; even address, grows down
2019-10-30 14:10:23 +01:00
DEFDRV: EQU 4 ; default drive when opening a FCB
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-10-30 14:10:23 +01:00
MOV CL, 0x00
CALL LOADBPB
2019-10-30 14:10:23 +01:00
MOV AX, [DISKBPB]
INT3
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
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