rdos/boot/chs.inc

47 lines
1.2 KiB
PHP

fix_chs:
mov ah, 0x08
int 0x13
jc chs_end ; skip if function does not exist
inc dh
mov [cs:fdc.nos], dh
push cx
and cx, 0x003F
mov [cs:fdc.spt], cx ; no adjustment because sectors are 1-indexed
pop ax
xchg al, ah
mov cl,6
shr ah,cl
inc ax ; convert from maximum number (0-based) to total number (1-based) of cylinders
mul word [cs:fdc.nos] ; number of tracks = number of cylinders * heads
mul word [cs:fdc.spt] ; number of sectors = number of tracks * sectors per track
mov [cs:fdc.ts], ax
jmp chs_end
; Load a single sector into memory
; Does not return on error
; in dx:ax sector number (will be trashed)
; es:bx buffer
load_sector:
push cx
div word [cs:fdc.spt] ; ax:temp = (lba / spt)
inc dx ; dx:sector = (lba % spt) + 1
mov cl, dl ; sector number
xor dx, dx
div word [cs:fdc.nos] ; ax:cylinder = (tmp / heads)
; dx:head = (tmp % heads)
mov ch, al ; cylinder number
mov dh, dl ; head number
mov dl, [cs:fdc.drv] ; driver number
mov ax, 0x0201 ; ah=0x02 al=0x01
int 0x13
jc disk_error
; return
pop cx
ret
disk_error:
xchg al, ah
call error
db "DISK ERROR", 0
chs_end: