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 = { syscalls = {
'open_file': None, 'open_file': None,
'read_sectors': None, 'modify_sectors': None,
'draw_rect': None, 'draw_rect': None,
} }

View File

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

View File

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

View File

@ -49,7 +49,8 @@ initialize:
mov bp, PONYDOS_SEG mov bp, PONYDOS_SEG
mov es, bp mov es, bp
mov bx, GLOBAL_WALLPAPER 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 ; Put window 1 in the window chain
mov ax, cs mov ax, cs