Begin work on filesystem support
This commit is contained in:
parent
9d2021cf1f
commit
d6dc33f164
2
Makefile
2
Makefile
|
@ -9,7 +9,7 @@ all: ponydos.img
|
||||||
ponydos.img: ponydos.bin wallpaper.bin
|
ponydos.img: ponydos.bin wallpaper.bin
|
||||||
rw -i /dev/zero -o $@ -c 1440K
|
rw -i /dev/zero -o $@ -c 1440K
|
||||||
rw -i ponydos.bin -o $@
|
rw -i ponydos.bin -o $@
|
||||||
rw -i wallpaper.bin -o $@ -O 512
|
rw -i wallpaper.bin -o $@ -O 1024
|
||||||
|
|
||||||
.asm.bin:
|
.asm.bin:
|
||||||
$(NASM) -fbin -o $@ $<
|
$(NASM) -fbin -o $@ $<
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
; TODO: have tooling for this
|
||||||
|
|
||||||
|
; 128 sector files, starting at 2
|
||||||
|
|
||||||
|
; dirent:
|
||||||
|
; 2 bytes size in 512B sectors, 0 for end of listing
|
||||||
|
; 30 bytes null-terminated name
|
||||||
|
|
||||||
|
wallpaper:
|
||||||
|
dw 8
|
||||||
|
db 'wallpaper.bin', 0
|
||||||
|
times 512+32-($-$$) db 0
|
||||||
|
|
||||||
|
times 1024-($-$$) db 0
|
171
ponydos.asm
171
ponydos.asm
|
@ -8,12 +8,14 @@ ROWS equ 25
|
||||||
|
|
||||||
WALLPAPER equ 0x500
|
WALLPAPER equ 0x500
|
||||||
|
|
||||||
|
DIRENTS equ 0x2000
|
||||||
|
DIRENT_SIZE equ 32
|
||||||
|
FILE_MAX_SIZE equ 128
|
||||||
|
|
||||||
jmp 0:start
|
jmp 0:start
|
||||||
start:
|
start:
|
||||||
cld
|
cld
|
||||||
|
|
||||||
cli
|
|
||||||
|
|
||||||
; Set up segments and stack
|
; Set up segments and stack
|
||||||
mov ax, cs
|
mov ax, cs
|
||||||
mov ds, ax
|
mov ds, ax
|
||||||
|
@ -21,12 +23,10 @@ start:
|
||||||
mov ss, ax
|
mov ss, ax
|
||||||
mov sp, $$
|
mov sp, $$
|
||||||
|
|
||||||
sti
|
|
||||||
|
|
||||||
; Clear BSS
|
; Clear BSS
|
||||||
|
;xor al, al
|
||||||
mov di, _bss_start
|
mov di, _bss_start
|
||||||
mov cx, _bss_end - _bss_start
|
mov cx, _bss_end - _bss_start
|
||||||
xor al, al
|
|
||||||
rep stosb
|
rep stosb
|
||||||
|
|
||||||
mov [boot_disk], dl
|
mov [boot_disk], dl
|
||||||
|
@ -65,11 +65,11 @@ initialize_mouse:
|
||||||
.done:
|
.done:
|
||||||
|
|
||||||
load_wallpaper:
|
load_wallpaper:
|
||||||
mov ax, 1
|
mov si, wallpaper_name
|
||||||
mov bl, [boot_disk]
|
call open_file
|
||||||
mov cx, 8
|
mov bx, WALLPAPER
|
||||||
mov di, WALLPAPER
|
|
||||||
call read_sectors
|
call read_sectors
|
||||||
|
; TODO: error management? Surely this works...
|
||||||
|
|
||||||
initialize_screen:
|
initialize_screen:
|
||||||
; Disable text cursor
|
; Disable text cursor
|
||||||
|
@ -164,35 +164,31 @@ flip_mouse_cursor:
|
||||||
|
|
||||||
; in:
|
; in:
|
||||||
; ax = LBA of first sector
|
; ax = LBA of first sector
|
||||||
; 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:di = output buffer
|
; es:bx = output buffer
|
||||||
read_sectors:
|
read_sectors:
|
||||||
push ax
|
push ax
|
||||||
push cx
|
push cx
|
||||||
push di
|
push bx
|
||||||
|
|
||||||
.loop:
|
.loop:
|
||||||
call read_sector
|
call read_sector
|
||||||
inc ax
|
inc ax
|
||||||
add di, 512
|
add bx, 512
|
||||||
loop .loop
|
loop .loop
|
||||||
|
|
||||||
pop di
|
pop bx
|
||||||
pop cx
|
pop cx
|
||||||
pop ax
|
pop ax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; in:
|
; in:
|
||||||
; ax = LBA of first sector
|
; ax = LBA of sector
|
||||||
; bl = drive number
|
; out:
|
||||||
; es:di = output buffer
|
; cx, dx = appropriately set for int 0x13
|
||||||
read_sector:
|
; ax clobbered
|
||||||
push ax
|
prepare_geometry:
|
||||||
push bx
|
|
||||||
push cx
|
|
||||||
push dx
|
|
||||||
|
|
||||||
mov cx, 18
|
mov cx, 18
|
||||||
div cx
|
div cx
|
||||||
|
|
||||||
|
@ -209,10 +205,19 @@ read_sector:
|
||||||
mov ch, al
|
mov ch, al
|
||||||
|
|
||||||
; dl = drive number
|
; dl = drive number
|
||||||
mov dl, bl
|
mov dl, [boot_disk]
|
||||||
|
ret
|
||||||
|
|
||||||
; es:bx = output buffer
|
; in:
|
||||||
mov bx, di
|
; 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 one sector
|
||||||
|
@ -221,7 +226,6 @@ read_sector:
|
||||||
|
|
||||||
pop dx
|
pop dx
|
||||||
pop cx
|
pop cx
|
||||||
pop bx
|
|
||||||
pop ax
|
pop ax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
@ -233,6 +237,112 @@ 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
|
||||||
|
; ------------------------------------------------------------------
|
||||||
|
|
||||||
|
wallpaper_name: db 'wallpaper.bin', 0
|
||||||
|
|
||||||
|
; in:
|
||||||
|
; es:si = file name
|
||||||
|
; out:
|
||||||
|
; ax = LBA of first sector, 0 if no space left
|
||||||
|
; cx = length in sectors
|
||||||
|
open_file:
|
||||||
|
push si
|
||||||
|
push di
|
||||||
|
push bx
|
||||||
|
|
||||||
|
; Stolen from https://stackoverflow.com/a/72746473, get strlen in cx
|
||||||
|
mov di, si
|
||||||
|
mov cx, -1
|
||||||
|
xor ax, ax
|
||||||
|
repne scasb
|
||||||
|
not cx
|
||||||
|
dec cx
|
||||||
|
|
||||||
|
;mov ax, 1
|
||||||
|
mov al, 1
|
||||||
|
mov bx, DIRENTS
|
||||||
|
call read_sector
|
||||||
|
|
||||||
|
mov ax, 2
|
||||||
|
mov di, bx
|
||||||
|
.loop:
|
||||||
|
cmp word [di], 0
|
||||||
|
je .create_file
|
||||||
|
|
||||||
|
inc di
|
||||||
|
inc di
|
||||||
|
|
||||||
|
push cx
|
||||||
|
push di
|
||||||
|
push si
|
||||||
|
repe cmpsb
|
||||||
|
pop si
|
||||||
|
pop di
|
||||||
|
pop cx
|
||||||
|
je .success
|
||||||
|
|
||||||
|
add ax, FILE_MAX_SIZE
|
||||||
|
add di, DIRENT_SIZE - 2
|
||||||
|
cmp di, DIRENTS + 0x200
|
||||||
|
jl .loop
|
||||||
|
|
||||||
|
.error:
|
||||||
|
xor ax, ax
|
||||||
|
; Return with mangled cx
|
||||||
|
.success:
|
||||||
|
mov cx, [di - 2]
|
||||||
|
.return:
|
||||||
|
pop bx
|
||||||
|
pop di
|
||||||
|
pop si
|
||||||
|
ret
|
||||||
|
|
||||||
|
.create_file:
|
||||||
|
; TODO: zero out the sector for this file?
|
||||||
|
inc word [di]
|
||||||
|
inc di
|
||||||
|
inc di
|
||||||
|
rep movsb
|
||||||
|
|
||||||
|
push ax
|
||||||
|
mov ax, 1
|
||||||
|
;mov bx, DIRENTS
|
||||||
|
call write_sector
|
||||||
|
pop ax
|
||||||
|
|
||||||
|
;mov cx, 1
|
||||||
|
mov cl, 1
|
||||||
|
jmp .return
|
||||||
|
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
; Mouse callback
|
; Mouse callback
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
|
@ -315,6 +425,7 @@ mouse_handler:
|
||||||
; Debug routines
|
; Debug routines
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
|
|
||||||
|
%if 0
|
||||||
hexprint16:
|
hexprint16:
|
||||||
xchg ah, al
|
xchg ah, al
|
||||||
call hexprint8
|
call hexprint8
|
||||||
|
@ -347,15 +458,19 @@ hexprint4:
|
||||||
hang:
|
hang:
|
||||||
hlt
|
hlt
|
||||||
jmp hang
|
jmp hang
|
||||||
|
%endif
|
||||||
|
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
; Padding and boot sector signature
|
; Padding and boot sector signature
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
|
|
||||||
times 510-($-$$) db 0
|
times 510-($-$$) db 0
|
||||||
|
|
||||||
db 0x55
|
db 0x55
|
||||||
db 0xaa
|
db 0xaa
|
||||||
|
|
||||||
|
%include "filesystem.asm"
|
||||||
|
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
; Zero-initialized variables
|
; Zero-initialized variables
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
|
@ -372,4 +487,4 @@ mouse_row resw 1
|
||||||
|
|
||||||
boot_disk resb 1
|
boot_disk resb 1
|
||||||
|
|
||||||
_bss_end:
|
_bss_end:
|
Loading…
Reference in New Issue