137 lines
1.8 KiB
NASM
137 lines
1.8 KiB
NASM
ORG BDOS
|
|
|
|
%include "bios/header.asm"
|
|
|
|
DISKBUF: EQU (BDOS-0x200) ; deblocking
|
|
STACK: EQU (DISKBUF) ; grows down
|
|
DEFDRV: EQU 4
|
|
|
|
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
|
|
|
|
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
|
|
STC
|
|
RET
|
|
|
|
SETUP:
|
|
MOV SP, STACK
|
|
MOV BYTE [DEFDRV], 0x01
|
|
MOV CX, DISKBUF
|
|
CALL SETDMA
|
|
|
|
MOV DL, BYTE [DEFDRV]
|
|
ADD DL, '@'
|
|
CALL PUTC
|
|
MOV DL, '>'
|
|
CALL PUTC
|
|
|
|
MOV DX, 0x7F
|
|
MOV BYTE [0x7F], 0x2F
|
|
MOV BYTE [0x80], 2
|
|
CALL GETS
|
|
|
|
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:
|
|
CALL CONOUT
|
|
RET
|
|
|
|
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
|