Switch from read_sectors to modify_sectors; return dirent in open_file

This commit is contained in:
shikhin 2023-03-19 20:09:35 +05:30
parent 4cd5c0632a
commit b3df18bb04
4 changed files with 22 additions and 22 deletions

View File

@ -2,7 +2,7 @@ import sys
syscalls = {
'open_file': None,
'read_sectors': None,
'modify_sectors': None,
'draw_rect': None,
}

View File

@ -11,7 +11,6 @@ org 0x7c00
COLUMNS equ 80
ROWS equ 25
DIRENTS equ 0x2000
DIRENT_SIZE equ 32
FILE_MAX_SIZE equ 128
@ -65,7 +64,8 @@ load_shell:
mov si, shell_name
call 0:open_file
xor bx, bx
call 0:read_sectors
xor di, di ; read
call 0:modify_sectors
; TODO: error management? Surely this works...
xor ax, ax ; WM_INITIALIZE
@ -231,11 +231,11 @@ flip_mouse_cursor:
;; bl = drive number
; cx = number of sectors to read (must be at least 1)
; es:bx = output buffer
; di = 0x0100 for write, 0x0000 for read
; [Far calls only]
read_sectors:
modify_sectors:
pusha
xor di, di
.loop:
call modify_sector
inc ax
@ -299,10 +299,10 @@ shell_name db 'shell.bin', 0
; out:
; ax = LBA of first sector, 0 if no space left
; cx = length in sectors
; di = dirent address (in GLOBAL_DIRENTS)
; [Far calls only]
open_file:
push si
push di
push bx
push es
@ -319,7 +319,7 @@ open_file:
mov es, ax
;mov ax, 1
mov al, 1
mov bx, DIRENTS
mov bx, GLOBAL_DIRENTS
xor di, di
call modify_sector
@ -329,48 +329,46 @@ open_file:
cmp word [es:di], 0
je .create_file
pusha
inc di
inc di
pusha
repe cmpsb
popa
je .success
add ax, FILE_MAX_SIZE
add di, DIRENT_SIZE - 2
cmp di, DIRENTS + 0x200
add di, DIRENT_SIZE
cmp di, GLOBAL_DIRENTS + 0x200
jl .loop
.error:
xor ax, ax
; Return with mangled cx
; Return with mangled cx, di
.success:
mov cx, [es:di - 2]
mov cx, [es:di]
.return:
pop es
pop bx
pop di
pop si
retf
.create_file:
; TODO: zero out the sector for this file?
inc word [es:di]
pusha
inc di
inc di
rep movsb
push ax
mov ax, 1
;mov bx, DIRENTS
;mov bx, GLOBAL_DIRENTS
mov di, 0x0100 ; write
call modify_sector
pop ax
;mov cx, 1
mov cl, 1
jmp .return
popa
jmp .success
; ------------------------------------------------------------------
; Mouse callback

View File

@ -1,6 +1,7 @@
PONYDOS_SEG equ 0
GLOBAL_WALLPAPER equ 0x500
GLOBAL_DIRENTS equ 0x2000
WM_INITIALIZE equ 0
WM_PAINT equ 1

View File

@ -49,7 +49,8 @@ initialize:
mov bp, PONYDOS_SEG
mov es, bp
mov bx, GLOBAL_WALLPAPER
call PONYDOS_SEG:SYS_READ_SECTORS
xor di, di ; read
call PONYDOS_SEG:SYS_MODIFY_SECTORS
; Put window 1 in the window chain
mov ax, cs