Don't assume things about ds/es

This commit is contained in:
shikhin 2023-03-16 21:22:41 +05:30
parent 2a3200fc73
commit 565fff50b4
1 changed files with 17 additions and 6 deletions

View File

@ -195,8 +195,13 @@ modify_sector:
push ax push ax
push cx push cx
push dx push dx
push ds
mov cx, 18 xor cx, cx
mov ds, cx
;mov cx, 18
mov cl, 18
div cx div cx
; cl = sector (1…18) ; cl = sector (1…18)
@ -212,7 +217,7 @@ modify_sector:
mov ch, al mov ch, al
; dl = drive number ; dl = drive number
mov dl, [boot_disk] mov dl, [ds:boot_disk]
.retry: .retry:
mov ax, 0x0201 ; read/write one sector mov ax, 0x0201 ; read/write one sector
@ -220,6 +225,7 @@ modify_sector:
int 0x13 int 0x13
jc .error jc .error
pop ds
pop dx pop dx
pop cx pop cx
pop ax pop ax
@ -240,7 +246,7 @@ modify_sector:
wallpaper_name: db 'wallpaper.bin', 0 wallpaper_name: db 'wallpaper.bin', 0
; in: ; in:
; es:si = file name ; ds:si = file name
; out: ; out:
; ax = LBA of first sector, 0 if no space left ; ax = LBA of first sector, 0 if no space left
; cx = length in sectors ; cx = length in sectors
@ -248,8 +254,11 @@ open_file:
push si push si
push di push di
push bx push bx
push es
; Stolen from https://stackoverflow.com/a/72746473, get strlen in cx ; Stolen from https://stackoverflow.com/a/72746473, get strlen in cx
mov cx, ds
mov es, cx
mov di, si mov di, si
mov cx, -1 mov cx, -1
xor ax, ax xor ax, ax
@ -257,6 +266,7 @@ open_file:
not cx not cx
dec cx dec cx
mov es, ax
;mov ax, 1 ;mov ax, 1
mov al, 1 mov al, 1
mov bx, DIRENTS mov bx, DIRENTS
@ -266,7 +276,7 @@ open_file:
mov ax, 2 mov ax, 2
mov di, bx mov di, bx
.loop: .loop:
cmp word [di], 0 cmp word [es:di], 0
je .create_file je .create_file
inc di inc di
@ -290,8 +300,9 @@ open_file:
xor ax, ax xor ax, ax
; Return with mangled cx ; Return with mangled cx
.success: .success:
mov cx, [di - 2] mov cx, [es:di - 2]
.return: .return:
pop es
pop bx pop bx
pop di pop di
pop si pop si
@ -299,7 +310,7 @@ open_file:
.create_file: .create_file:
; TODO: zero out the sector for this file? ; TODO: zero out the sector for this file?
inc word [di] inc word [es:di]
inc di inc di
inc di inc di
rep movsb rep movsb