Merge read/write to modify_sector

This commit is contained in:
shikhin 2023-03-16 16:12:22 +05:30
parent d6dc33f164
commit 400f282725
1 changed files with 19 additions and 47 deletions

View File

@ -171,24 +171,31 @@ read_sectors:
push ax
push cx
push bx
push di
xor di, di
.loop:
call read_sector
call modify_sector
inc ax
add bx, 512
loop .loop
pop di
pop bx
pop cx
pop ax
ret
; in:
; ax = LBA of sector
; out:
; cx, dx = appropriately set for int 0x13
; ax clobbered
prepare_geometry:
; ax = LBA of first sector
;; bl = drive number, use [boot_disk] for now
; es:bx = output buffer
; di = 0x0100 for write, 0x0000 for read
modify_sector:
push ax
push cx
push dx
mov cx, 18
div cx
@ -206,21 +213,10 @@ prepare_geometry:
; dl = drive number
mov dl, [boot_disk]
ret
; in:
; ax = LBA of first sector
;; bl = drive number, use [boot_disk] for now
; es:bx = output buffer
read_sector:
push ax
push cx
push dx
call prepare_geometry
.retry:
mov ax, 0x0201 ; read one sector
mov ax, 0x0201 ; read/write one sector
add ax, di
int 0x13
jc .error
@ -237,32 +233,6 @@ read_sector:
int 0x10
jmp .retry
; in:
; ax = LBA of first sector
;; bl = drive number, use [boot_disk] for now
; es:bx = input buffer
write_sector:
push ax
push cx
push dx
call prepare_geometry
.retry:
mov ax, 0x0301 ; write one sector
int 0x13
jc .error
pop dx
pop cx
pop ax
ret
.error:
xor ah, ah
int 0x10
jmp .retry
; ------------------------------------------------------------------
; Filesystem
; ------------------------------------------------------------------
@ -290,7 +260,8 @@ open_file:
;mov ax, 1
mov al, 1
mov bx, DIRENTS
call read_sector
xor di, di
call modify_sector
mov ax, 2
mov di, bx
@ -336,7 +307,8 @@ open_file:
push ax
mov ax, 1
;mov bx, DIRENTS
call write_sector
mov di, 0x0100 ; write
call modify_sector
pop ax
;mov cx, 1