137 lines
1.6 KiB
NASM
137 lines
1.6 KiB
NASM
|
; Memory layout:
|
||
|
%define self 0x00600 ; 1 sector
|
||
|
%define prog 0x07C00 ; 1 sector
|
||
|
|
||
|
; FDC fields in VBR
|
||
|
%define spt (prog + 0x18)
|
||
|
%define nos (prog + 0x1A)
|
||
|
%define po (prog + 0x1C)
|
||
|
|
||
|
org self
|
||
|
cpu 8086
|
||
|
|
||
|
init:
|
||
|
cli
|
||
|
|
||
|
; Stack grows down from PSP + 64k
|
||
|
xor ax, ax
|
||
|
mov ss, ax
|
||
|
mov sp, ax
|
||
|
|
||
|
push dx
|
||
|
|
||
|
; Relocate from [prog] to [self]
|
||
|
mov ds, ax
|
||
|
mov es, ax
|
||
|
mov si, prog
|
||
|
mov di, self
|
||
|
mov cx, 0x100
|
||
|
rep movsw
|
||
|
|
||
|
jmp 0:main
|
||
|
|
||
|
main:
|
||
|
mov bp, 0x3335
|
||
|
mov si, part1
|
||
|
mov cx, 4
|
||
|
.loop:
|
||
|
test BYTE [si], 0x80
|
||
|
jnz loadpart
|
||
|
add si, 0x10
|
||
|
loop .loop
|
||
|
jmp error
|
||
|
|
||
|
loadpart:
|
||
|
; transfer starting address into DAP
|
||
|
push si
|
||
|
add si, 0x08
|
||
|
mov di, dap.blocknum
|
||
|
movsw
|
||
|
movsw
|
||
|
pop si
|
||
|
|
||
|
; load sector
|
||
|
push si
|
||
|
mov si, dap
|
||
|
mov bp, 0x3336
|
||
|
mov ah, 0x42
|
||
|
stc
|
||
|
int 0x13
|
||
|
jc error
|
||
|
pop si
|
||
|
|
||
|
cmp BYTE [si+4], 0x01
|
||
|
jne jump
|
||
|
|
||
|
adjust:
|
||
|
push dx
|
||
|
|
||
|
mov bp, 0x3337
|
||
|
mov ah, 0x08
|
||
|
stc
|
||
|
int 0x13
|
||
|
jc error
|
||
|
|
||
|
; update sectors per track
|
||
|
xor ax, ax
|
||
|
mov al, cl
|
||
|
mov [spt], ax
|
||
|
|
||
|
; update number of sides
|
||
|
xor ax, ax
|
||
|
mov al, dh
|
||
|
mov [nos], ax
|
||
|
|
||
|
; update partition offset
|
||
|
push si
|
||
|
add si, 0x08
|
||
|
mov di, po
|
||
|
movsw
|
||
|
movsw
|
||
|
pop si
|
||
|
|
||
|
pop dx
|
||
|
|
||
|
jump:
|
||
|
jmp 0:prog
|
||
|
|
||
|
error:
|
||
|
mov ax, bp
|
||
|
mov ah, 0x0e
|
||
|
mov bx, 7
|
||
|
int 0x10
|
||
|
mov al, 0x21
|
||
|
int 0x10
|
||
|
xor ax, ax
|
||
|
int 0x16
|
||
|
int 0x19
|
||
|
|
||
|
dap:
|
||
|
.size:
|
||
|
db 0
|
||
|
db 0
|
||
|
.count:
|
||
|
dw 1
|
||
|
.buffer:
|
||
|
dw prog
|
||
|
dw 0
|
||
|
.blocknum:
|
||
|
dq 0
|
||
|
|
||
|
times (0x1BE - ($-$$)) db 0
|
||
|
part1:
|
||
|
db 0x80
|
||
|
.chs_start:
|
||
|
db 0xFF, 0xFF, 0xFF
|
||
|
.type:
|
||
|
db 0x01
|
||
|
.chs_end:
|
||
|
db 0xFF, 0xFF, 0xFF
|
||
|
.begin:
|
||
|
dd 1
|
||
|
.end:
|
||
|
dd (FLOPPY * 2)
|
||
|
|
||
|
times (0x1FE - ($-$$)) db 0
|
||
|
dw 0xAA55
|