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