158 lines
2.2 KiB
NASM
158 lines
2.2 KiB
NASM
|
; SPDX-License-Identifier: MIT
|
||
|
; Copyright (c) 2021 Juhani 'nortti' Krekelä.
|
||
|
|
||
|
iosegment equ 60h
|
||
|
dossegment equ iosegment + 1*1024/16 ; DOS starts 1KiB after IO system
|
||
|
|
||
|
dos segment at dossegment
|
||
|
org 0
|
||
|
dosinit proc far
|
||
|
dosinit endp
|
||
|
dos ends
|
||
|
|
||
|
code segment
|
||
|
code ends
|
||
|
|
||
|
constants segment
|
||
|
constants ends
|
||
|
|
||
|
data segment
|
||
|
data ends
|
||
|
|
||
|
iogroup group code, constants, data
|
||
|
|
||
|
code segment
|
||
|
assume cs:iogroup, ds:iogroup, es:iogroup
|
||
|
org 0
|
||
|
|
||
|
; Jump table
|
||
|
jmp init
|
||
|
jmp status
|
||
|
jmp getch
|
||
|
jmp putch
|
||
|
jmp unimplemented ; Output to printer
|
||
|
jmp unimplemented ; Serial read
|
||
|
jmp unimplemented ; Serial write
|
||
|
jmp diskread
|
||
|
jmp diskwrite
|
||
|
jmp diskchange
|
||
|
jmp setdate
|
||
|
jmp settime
|
||
|
jmp gettime
|
||
|
jmp flush
|
||
|
jmp mapdev
|
||
|
|
||
|
init:
|
||
|
cld
|
||
|
|
||
|
cli
|
||
|
mov ax, cs
|
||
|
mov ds, ax
|
||
|
mov es, ax
|
||
|
; Put setup stack just below 32K
|
||
|
xor ax, ax
|
||
|
mov ss, ax
|
||
|
mov sp, 8000h
|
||
|
sti
|
||
|
|
||
|
; Figure out memory size
|
||
|
int 12h
|
||
|
; AX = memory size in kilobytes
|
||
|
; We want it in paragraphs
|
||
|
; There are 64 paragraphs in a kilobyte
|
||
|
mov cx, 64
|
||
|
shl al, cl
|
||
|
; Memory size is passed in dx
|
||
|
mov dx, ax
|
||
|
|
||
|
; Disk table is passed in si
|
||
|
mov si, offset iogroup:disks_table
|
||
|
|
||
|
call dosinit
|
||
|
|
||
|
mov al, 'c'
|
||
|
jmp error
|
||
|
|
||
|
; OUT:
|
||
|
; al = character if any
|
||
|
; zf = there were no characters
|
||
|
status proc far
|
||
|
; TODO: Implement
|
||
|
xor ax, ax
|
||
|
test ax, ax
|
||
|
ret
|
||
|
status endp
|
||
|
|
||
|
getch:
|
||
|
mov al, 'g'
|
||
|
jmp error
|
||
|
|
||
|
; IN:
|
||
|
; ax = character
|
||
|
putch proc far
|
||
|
push ax
|
||
|
mov ah, 0eh
|
||
|
int 10h
|
||
|
pop ax
|
||
|
ret
|
||
|
putch endp
|
||
|
|
||
|
diskread:
|
||
|
mov al, 'r'
|
||
|
jmp error
|
||
|
diskwrite:
|
||
|
mov al, 'w'
|
||
|
jmp error
|
||
|
diskchange:
|
||
|
mov al, 'c'
|
||
|
jmp error
|
||
|
setdate:
|
||
|
mov al, 'd'
|
||
|
jmp error
|
||
|
settime:
|
||
|
mov al, 't'
|
||
|
jmp error
|
||
|
gettime:
|
||
|
mov al, 'T'
|
||
|
jmp error
|
||
|
flush:
|
||
|
mov al, 'f'
|
||
|
jmp error
|
||
|
|
||
|
mapdev:
|
||
|
mov al, 'm'
|
||
|
jmp error
|
||
|
|
||
|
unimplemented:
|
||
|
mov al, '@'
|
||
|
|
||
|
error:
|
||
|
mov ah, 0eh
|
||
|
int 10h
|
||
|
|
||
|
hang:
|
||
|
hlt
|
||
|
jmp hang
|
||
|
|
||
|
code ends
|
||
|
|
||
|
constants segment
|
||
|
|
||
|
disks_table:
|
||
|
db 1 ; 1 drive
|
||
|
|
||
|
db 0 ; Physical drive 0
|
||
|
dw offset iogroup:parameters_320k
|
||
|
|
||
|
parameters_320k:
|
||
|
dw 512 ; Sector size in bytes
|
||
|
db 2 ; Sectors per cluster
|
||
|
dw 1 ; Number of reserved sectors
|
||
|
dw 2 ; Number of FATs
|
||
|
dw 112 ; Number of directory entries
|
||
|
dw 320*2 ; Number of sectors
|
||
|
|
||
|
constants ends
|
||
|
|
||
|
end
|