217 lines
2.3 KiB
NASM
217 lines
2.3 KiB
NASM
ORG BIOS
|
|
CPU 8086
|
|
|
|
DISKCX: EQU 0x8
|
|
DISKDX: EQU 0xA
|
|
DISKBX: EQU 0xC
|
|
|
|
JMP NEAR BOOT
|
|
JMP NEAR WBOOT
|
|
JMP NEAR CONST
|
|
JMP NEAR CONIN
|
|
JMP NEAR CONOUT
|
|
JMP NEAR LIST
|
|
JMP NEAR PUNCH
|
|
JMP NEAR READER
|
|
JMP NEAR HOME
|
|
JMP NEAR SELDSK
|
|
JMP NEAR SETTRK
|
|
JMP NEAR SETSEC
|
|
JMP NEAR SETDMA
|
|
JMP NEAR READ
|
|
JMP NEAR WRITE
|
|
JMP NEAR LISTST
|
|
|
|
BOOT:
|
|
MOV AL, 0x86
|
|
CALL MSG
|
|
DB "BIOS", 0
|
|
|
|
WBOOT:
|
|
XOR CX, CX
|
|
JMP BDOS
|
|
RET
|
|
|
|
; CHAR I/O
|
|
CONST:
|
|
MOV AH, 1
|
|
INT 0x16
|
|
JZ .END
|
|
MOV AL, 0xFF
|
|
RET
|
|
.END:
|
|
XOR AL, AL
|
|
RET
|
|
|
|
CONIN:
|
|
XOR AX, AX
|
|
INT 0x16
|
|
TEST AL, AL
|
|
JZ CONIN
|
|
RET
|
|
|
|
MSG:
|
|
POP SI
|
|
.LOOP:
|
|
MOV DL, BYTE [SI]
|
|
INC SI
|
|
TEST DL, DL
|
|
JZ .END
|
|
CALL CONOUT
|
|
JMP .LOOP
|
|
.END:
|
|
MOV DL, 0x20
|
|
CALL CONOUT
|
|
CALL PRINTAL
|
|
MOV DL, 0x0A
|
|
CALL CONOUT
|
|
MOV DL, 0x0D
|
|
CALL CONOUT
|
|
PUSH SI
|
|
RET
|
|
|
|
PRINTAL:
|
|
PUSH AX
|
|
PUSH DX
|
|
AAM 16
|
|
MOV DL, AH
|
|
CALL PRINTNIB
|
|
MOV DL, AL
|
|
CALL PRINTNIB
|
|
POP DX
|
|
POP AX
|
|
RET
|
|
|
|
PRINTNIB:
|
|
ADD DL, 0x30
|
|
CMP DL, 0x3a
|
|
JL CONOUT
|
|
ADD DL, 0x07
|
|
|
|
CONOUT:
|
|
PUSH AX
|
|
PUSH BX
|
|
MOV AH, 0x0E
|
|
MOV AL, DL
|
|
XOR BX, BX
|
|
INT 0x10
|
|
POP BX
|
|
POP AX
|
|
RET
|
|
|
|
LIST:
|
|
PUSH DX
|
|
XOR AH, AH
|
|
MOV AL, DL
|
|
INT 0x17
|
|
POP DX
|
|
RET
|
|
|
|
LISTST:
|
|
STC
|
|
RET
|
|
|
|
PUNCH:
|
|
STC
|
|
RET
|
|
|
|
READER:
|
|
STC
|
|
RET
|
|
|
|
; DISK I/O
|
|
HOME:
|
|
RET
|
|
|
|
SELDSK:
|
|
MOV BYTE [DISKDX], CL
|
|
XOR BX, BX
|
|
RET
|
|
|
|
SETTRK:
|
|
PUSH CX
|
|
PUSH DX
|
|
|
|
MOV DX, CX
|
|
; CH for headnum, CL for SAL
|
|
MOV CX, 0x0006
|
|
|
|
; Take off LSB as head number
|
|
XOR CH, CH
|
|
RCR DX, 1
|
|
RCL CH, 1
|
|
MOV BYTE [DISKDX+1], CH
|
|
|
|
; DX is sector number now
|
|
; Shift into format for int13
|
|
; DX ------9876543210
|
|
SAL DX, CL
|
|
; DX 9876543210------
|
|
ROL DX, 1
|
|
ROL DX, 1
|
|
; DX 76543210------98
|
|
SAL DL, CL
|
|
; DX 7654321098------
|
|
AND WORD [DISKCX], 0x003F
|
|
OR WORD [DISKCX], DX
|
|
|
|
POP DX
|
|
POP CX
|
|
RET
|
|
|
|
SETSEC:
|
|
AND WORD [DISKCX], 0xFFA0
|
|
OR BYTE [DISKCX], CL
|
|
RET
|
|
|
|
SETDMA:
|
|
MOV WORD [DISKBX], CX
|
|
RET
|
|
|
|
READ:
|
|
PUSH CX
|
|
PUSH DX
|
|
PUSH BX
|
|
|
|
MOV AX, 0x0201
|
|
MOV CX, [DISKCX]
|
|
MOV DX, [DISKDX]
|
|
MOV BX, [DISKBX]
|
|
INT 0x13
|
|
XCHG AH, AL
|
|
|
|
POP BX
|
|
POP DX
|
|
POP CX
|
|
|
|
JC DISKERR
|
|
RET
|
|
|
|
WRITE:
|
|
PUSH CX
|
|
PUSH DX
|
|
PUSH BX
|
|
|
|
MOV AX, 0x0301
|
|
MOV CX, [DISKCX]
|
|
MOV DX, [DISKDX]
|
|
MOV BX, [DISKBX]
|
|
INT 0x13
|
|
XCHG AH, AL
|
|
|
|
POP BX
|
|
POP DX
|
|
POP CX
|
|
|
|
JC DISKERR
|
|
RET
|
|
|
|
DISKERR:
|
|
PUSHF
|
|
PUSH SI
|
|
CALL MSG
|
|
DB "DISKERR", 0
|
|
POP SI
|
|
POPF
|
|
RET
|