Reorder disk access and fix missing si setting

This commit is contained in:
Nero 2020-04-16 23:04:06 +02:00
parent 27e4dec580
commit 70a675442a

View File

@ -143,32 +143,16 @@ drvoff: dd 0 ; partition offset
drvpos: dd 0 ; absolute physical sector number
buffer: times 512 db 0
; Select active drive
; IN dl drive number A=0, B=1, C=2, ...
select: mov [drvnum], dl
push es
xor ax, ax
push cs
pop es
stosw
stosw
stosw
stosw
pop es
call read
call ldbpb
ret
; load bpb from buffer to bpb
ldbpb: push ds
push es
mov ax, cs
mov si, buffer+0x0B
mov di, bpb
mov cx, bpb_len
rep movsb
pop es
pop ds
; Convert between drive number and BIOS dl
; Bidirectional mapping
; 0 <-> 0, 1 <-> 1, 2 <-> 0x80, 3 <-> 0x81
dnconv: mov cx, 7
ror dx, 1
rol dl, 1
dncl: rcl dl, 1
rcr dh, 1
loop dncl
xchg dh, dl
ret
; Set sector number
@ -183,9 +167,9 @@ read: ; this uses the EBIOS extensions
xor ax, ax
push ax
push ax
mov ax, [drvpos+2]
mov ax, [cs:drvpos+2]
push ax
mov ax, [drvpos]
mov ax, [cs:drvpos]
push ax
; dword target buffer
@ -203,25 +187,41 @@ read: ; this uses the EBIOS extensions
mov si, sp
mov ah, 0x42
mov dl, [drvnum]
mov dl, [cs:drvnum]
call dnconv
stc
int 0x13
add sp, di
ret
; Convert between drive number and BIOS dl
; Bidirectional mapping
; 0 <-> 0, 1 <-> 1, 2 <-> 0x80, 3 <-> 0x81
dnconv: mov cx, 7
ror dx, 1
rol dl, 1
dncl: rcl dl, 1
rcr dh, 1
loop dncl
xchg dh, dl
; Select active drive
; IN dl drive number A=0, B=1, C=2, ...
select: mov [cs:drvnum], dl
ret
push es
xor ax, ax
push cs
pop es
mov si, drvoff
stosw
stosw
stosw
stosw
pop es
call read
; load bpb from buffer to bpb
ldbpb: push ds
push es
mov ax, cs
mov ds, ax
mov es, ax
mov si, buffer+0x0B
mov di, bpb
mov cx, bpb_len
rep movsb
pop es
pop ds
ret
init: cli
@ -232,7 +232,6 @@ init: cli
xor sp, sp
call dnconv
int 3
call select
int 3
mov ax, [cs:bpb+bpb_ss]