Load and execute command.com

This commit is contained in:
Juhani Krekelä 2021-09-26 11:46:50 +03:00
parent 1967c06b85
commit 68030372b7
1 changed files with 97 additions and 15 deletions

112
io.asm
View File

@ -64,14 +64,26 @@ init:
shl ax, cl
; Memory size is passed in dx
mov dx, ax
call hexprint16
call newline
; Disk table is passed in si
mov si, offset iogroup:disks_table
call dosinit
; Memory for command.com is at ds, save for later and revert ds
push ds
; Memory for command.com is at ds, with PSP already set up
; Retrieve amount of memory in the program segment
mov cx, word ptr ds:6
; Set up DTA
mov dx, 100h
mov ah, 1ah
int 21h
; Save command.com's segment for later and revert ds for opening the FCB
mov bx, ds
mov ax, cs
mov ds, ax
@ -79,15 +91,67 @@ init:
mov dx, offset iogroup:command_fcb
mov ah, 0fh
int 21h
test al, al
jnz open_error
mov al, '+'
jmp unfinished
mov ah, 0eh
int 10h
; Set random record field 0
mov word ptr command_fcb+33, 0
mov word ptr command_fcb+35, 0
; Set record size to 1 byte
mov word ptr command_fcb+14, 1
; Read command.com into memory
mov ah, 27h
int 21h
jcxz read_error
cmp al, 1
jne read_error
mov ax, cx
call hexprint16
mov al, '.'
mov ah, 0eh
int 10h
; Set up segments for command.com
mov ds, bx
mov es, bx
mov ss, bx
mov sp, 5ch ; Microsoft's documentation says to use this
; Put a zero at top of the stack
xor ax, ax
push ax
; Set default DTA
mov dx, 80h
mov ah, 1ah
int 21h
; Jump to command.com
push bx
mov ax, 100h
push ax
trampoline proc far
ret
trampoline endp
; TODO: Better error reporting
open_error:
mov al, '-'
jmp unfinished
read_error:
mov al, '!'
unfinished:
mov ah, 0eh
@ -146,7 +210,24 @@ diskread proc far
int 10h
pop ax
call far_caller
push ax
call hexprint8
call space
mov ax, ds
call hexprint16
call space
mov ax, bx
call hexprint16
call space
mov ax, cx
call hexprint16
call space
mov ax, dx
call hexprint16
call newline
pop ax
; TODO: Everything except sregs can be trashed
push es
push ax
push bx
@ -190,6 +271,11 @@ diskread proc far
jmp try_sector_read
sector_read_fail:
mov al, ah
call hexprint8;debg
mov al, '?'
mov ah, 0eh
int 10h
pop cx
pop ax
@ -201,6 +287,7 @@ diskread proc far
pop es
mov al, 12 ; TODO: Don't hardcode
stc
ret
sector_read_success:
@ -219,6 +306,7 @@ diskread proc far
pop ax
pop es
clc
ret
diskread endp
@ -256,10 +344,10 @@ chs proc
; cylinder (track)
mov ch, al
;shr ax, 1
;shr ax, 1
;and al, 0c0h
;or cl, al
shr ax, 1
shr ax, 1
and al, 0c0h
or cl, al
mov ax, dx
pop dx
@ -280,13 +368,8 @@ diskwrite:
; cf = 0 -> al = driver num
; cf = 1 -> al = disk error code
diskchange proc far
push ax
mov ax, 0e00h + 'd'
int 10h
pop ax
call far_caller
; TODO: Implement
mov ax, 0100h
mov ax, 0000h
clc
ret
diskchange endp
@ -320,7 +403,6 @@ flush endp
mapdev proc far
; TODO: Implement
xor al, al
ret
mapdev endp