sys: implement boot sector code plus target track calculation
This commit is contained in:
parent
b8672f0011
commit
cfadc73493
100
src/sys.asm
100
src/sys.asm
@ -6,6 +6,9 @@ fcb1 equ 0x5C
|
||||
%include "scan.inc"
|
||||
%include "print.inc"
|
||||
|
||||
drvnum db 0
|
||||
track dw 39
|
||||
|
||||
main mov di, 0x81
|
||||
mov al, 0x20
|
||||
mov ch, 0
|
||||
@ -17,6 +20,7 @@ main mov di, 0x81
|
||||
mov dx, ax
|
||||
test dx, ~0x83
|
||||
jnz drverr
|
||||
mov byte [drvnum], dl
|
||||
test dl, 0x80
|
||||
jz floppy
|
||||
call drverr
|
||||
@ -25,15 +29,71 @@ drverr call putsh
|
||||
db "Failed to access drive", 0x0A, 0x0D, 0
|
||||
int 0x20
|
||||
|
||||
; read bios parameter block
|
||||
floppy mov ax, 0x0201
|
||||
mov cx, 0x0001
|
||||
mov dh, 0
|
||||
mov bx, bs
|
||||
mov bx, prog
|
||||
int 0x13
|
||||
jc drverr
|
||||
mov ax, [bs+0x18]
|
||||
|
||||
; calculate start of cluster area
|
||||
mov ax, [prog+0x011] ; number of dir entries
|
||||
mov cl, 5
|
||||
shl ax, cl
|
||||
mov bx, [prog+0x0B] ; bytes per sector
|
||||
div bx
|
||||
; TODO: abort if dx is not zero
|
||||
mov cx, ax
|
||||
mov ax, [prog+0x016] ; logical sectors per fat
|
||||
; TODO: abort if ax is zero (=large FAT32)
|
||||
mov bl, [prog+0x010]
|
||||
mov bh, 0
|
||||
mul bx
|
||||
add ax, cx
|
||||
add ax, [prog+0x00E] ; reserved sectors
|
||||
mov si, ax
|
||||
|
||||
; calculate sector offset of target track
|
||||
mov ax, [prog+0x018]
|
||||
mul word [prog+0x01A]
|
||||
mul word [track]
|
||||
|
||||
; calculate cluster offset of target track
|
||||
sub ax, si
|
||||
mov bl, [prog+0x00D] ; sectors per cluster
|
||||
mov bh, 0
|
||||
call debug
|
||||
div bx
|
||||
call debug
|
||||
|
||||
ret
|
||||
; TODO:
|
||||
; calculate cluster offset of target track
|
||||
; calculate cluster length of target track
|
||||
; calculate offset into fat table
|
||||
; load part of fat table spanning our track
|
||||
; check that all relevant clusters are 0 or 0xFFF7
|
||||
; set all relevant clusters to 0xFFF7
|
||||
; track is now available for direct writing
|
||||
|
||||
; set up boot code
|
||||
mov di, prog
|
||||
mov ax, 0x7FEB
|
||||
stosw
|
||||
mov byte [di], 0x80
|
||||
add di, 0x7F - b_ld + b_rst
|
||||
mov si, b_rst
|
||||
mov cx, b_end - b_rst
|
||||
rep movsb
|
||||
|
||||
; write back bootsector
|
||||
mov ax, 0x0301
|
||||
mov cx, 0x0001
|
||||
mov dh, 0
|
||||
mov bx, prog
|
||||
int 0x13
|
||||
jc drverr
|
||||
|
||||
mov dx, fcb1
|
||||
mov ah, 0xF
|
||||
@ -67,21 +127,35 @@ floppy mov ax, 0x0201
|
||||
.cok nop
|
||||
mov ax, si
|
||||
sub ax, args
|
||||
add ax, 0x1FF
|
||||
mov cl, 9
|
||||
shr ax, cl
|
||||
call debug
|
||||
call putsh
|
||||
db "yay", 0x0A,0x0D,0
|
||||
|
||||
ret
|
||||
; mov ax, 0x0201
|
||||
; mov cx, 0x0001
|
||||
; mov dh, 0
|
||||
; mov bx, bs
|
||||
; int 0x13
|
||||
; mov ax, [bs+0x18]
|
||||
;.ret ret
|
||||
|
||||
; code to copy into boot sector
|
||||
b_rst mov ah, 0
|
||||
int 0x13
|
||||
b_ld mov ax, 0x60
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov ss, ax
|
||||
xor sp, sp
|
||||
mov ax, 0x0208 ; read, 8 sectors
|
||||
b_len equ $ - 2
|
||||
mov cx, 0x2701 ; track 39, sector 1
|
||||
b_trck equ $ - 1
|
||||
b_strt equ $ - 2
|
||||
mov dh, 0 ; head 0
|
||||
xor bx, bx ; es:bx=0x60:0
|
||||
int 0x13
|
||||
jc b_rst
|
||||
mov byte [4], dl
|
||||
jmp 0x60:0x100
|
||||
b_end equ $
|
||||
|
||||
align 2
|
||||
bs equ $
|
||||
psp equ bs + 0x200
|
||||
psp equ $
|
||||
args equ psp + 0x80
|
||||
prog equ psp + 0x100
|
||||
|
Loading…
Reference in New Issue
Block a user