Saving works. (very badly :/ )

This commit is contained in:
2023-12-31 15:13:06 +01:00
parent d80b41ebda
commit 845e33479a
3 changed files with 108 additions and 39 deletions
+11 -12
View File
@@ -93,11 +93,10 @@ return:
popa popa
mov ax, 0x2000 mov ax, 0x2000
mov es, bx mov es, ax
xor bx, bx xor bx, bx
mov ds, ax mov ds, ax
mov es, ax
mov fs, ax mov fs, ax
mov gs, ax mov gs, ax
jmp 0x2000:0x0000 jmp 0x2000:0x0000
@@ -115,12 +114,12 @@ save:
mov byte dl, [driveNum] mov byte dl, [driveNum]
push word filename push word filename
; TODO: More filetypes other than .bin ; TODO: More filetypes other than .bin
push word binFile push word binFile ; Filetype
push word 1 ; TODO: Dynamic filesize push word 1 ; TODO: Dynamic filesize
push word 0x8000 ; Program location (this segment) push word 0x8000 ; Program location (this segment)
push word hexCode push word hexCode ; Offset (hex code location)
call saveFile ; Returns exit code in al call saveFile ; Returns exit code in al
add sp, 8 ; Stack bs add sp, 10 ; Stack bs
cmp al, 0 ; Won't be 1 (File not found) so must be disk error cmp al, 0 ; Won't be 1 (File not found) so must be disk error
jne .error jne .error
@@ -142,14 +141,12 @@ open:
je getHexCh je getHexCh
; Call loadFile ; Call loadFile
; TODO: The same stuff as in save
mov byte dl, [driveNum] mov byte dl, [driveNum]
push word filename push word filename
push word 0x8000 push 0x8000
push word hexCode push hexCode
call loadFile call loadFile
add sp, 8
add sp, 6 ; Stack bs
cmp al, 1 cmp al, 1
je .notFound je .notFound
@@ -159,10 +156,10 @@ open:
jmp getHexCh jmp getHexCh
.notFound: .notFound:
mov si, notFoundMsg mov si, notFoundMsg
jmp .error jmp .err
.diskErr: .diskErr:
mov si, diskErrMsg mov si, diskErrMsg
.error: .err:
mov di, 0x0f00 mov di, 0x0f00
call drawString call drawString
jmp getHexCh jmp getHexCh
@@ -175,6 +172,7 @@ open:
; ;
getFilename: getFilename:
pusha pusha
push es
mov di, 0x0f00 ; Last line mov di, 0x0f00 ; Last line
call drawString ; si should contain the string call drawString ; si should contain the string
@@ -226,6 +224,7 @@ getFilename:
xor dx, dx ; 0,0 xor dx, dx ; 0,0
int 0x10 int 0x10
pop es
popa popa
ret ret
+12
View File
@@ -259,6 +259,18 @@ shutdown:
; File list (ls) ; File list (ls)
; ;
fileList: fileList:
mov bx, FILETAB_LOC
mov es, bx
xor bx, bx
mov al, 2 ; Read from disk
mov byte dl, [driveNum]
mov ch, 0 ; Cylinder
mov dh, 0 ; Head
mov cl, 2 ; Sector
mov al, 1 ; Read 1 sector
int 0x13 ; Move filetable to es:bx
mov si, fileListMsg mov si, fileListMsg
call print call print
+85 -27
View File
@@ -13,7 +13,12 @@ loadFile:
; Func prologue ; Func prologue
push bp push bp
mov bp, sp mov bp, sp
pusha push bx
push fs
push cx
push dx
push si
push es
mov byte [diskNum], dl mov byte [diskNum], dl
mov bx, [bp+4] ; dest Offset mov bx, [bp+4] ; dest Offset
@@ -24,19 +29,25 @@ loadFile:
mov di, fileName mov di, fileName
.getFilename: .getFilename:
lodsb ; mov byte al, [si]; inc si lodsb ; mov byte al, [si]; inc si
cmp al, 0 ; End of filename cmp al, 0 ; End of fileName
dec si ; Fill the rest with Null je .filenamePad
stosb stosb
loop .getFilename loop .getFilename
jmp .filenameDone
.filenamePad:
dec si ; Fill the rest with Null
.filenamePadLoop:
stosb
loop .filenamePadLoop
.filenameDone:
mov ax, FILETAB_LOC mov ax, FILETAB_LOC
mov es, ax mov es, ax
xor di, di ; es:di - Filetable location xor di, di ; es:di - Filetable location
mov si, fileName mov si, fileName
.fileNameCheck: .fileNameCheck:
mov al, [di] mov al, [es:di]
cmp al, 0 ; End of filetable cmp al, 0 ; End of filetable
je .notFound je .notFound ; File doesn't exist, create new one
cmp al, [si] cmp al, [si]
je .beginCmp je .beginCmp
@@ -59,7 +70,7 @@ loadFile:
.redoCheck: .redoCheck:
mov si, fileName mov si, fileName
pop di pop di
inc di add di, 16
jmp .fileNameCheck jmp .fileNameCheck
.notFound: .notFound:
mov byte [exitCode], NOT_FOUND mov byte [exitCode], NOT_FOUND
@@ -77,14 +88,14 @@ loadFile:
mov dl, [diskNum] mov dl, [diskNum]
int 0x13 int 0x13
push fs mov ax, fs
mov es, ax
mov ch, 0 ; Cylinder mov ch, 0 ; Cylinder
mov dh, 0 ; Head mov dh, 0 ; Head
mov cl, [es:di] ; Sector mov cl, [es:di] ; Sector
inc di inc di
mov al, [es:di] ; Length in sectors mov al, [es:di] ; Length in sectors
mov ah, 2 ; Read from disk mov ah, 2 ; Read from disk
pop es ; es:bx - Destination
int 0x13 int 0x13
jnc .done jnc .done
@@ -92,7 +103,12 @@ loadFile:
mov byte [exitCode], DISK_ERROR mov byte [exitCode], DISK_ERROR
.done: .done:
; Func epilogue ; Func epilogue
popa pop es
pop si
pop dx
pop cx
pop fs
pop bx
mov sp, bp mov sp, bp
pop bp pop bp
mov byte al, [exitCode] mov byte al, [exitCode]
@@ -115,7 +131,12 @@ saveFile:
; Func prologue ; Func prologue
push bp push bp
mov bp, sp mov bp, sp
pusha push bx
push fs
push cx
push dx
push si
push es
mov byte [diskNum], dl mov byte [diskNum], dl
mov bx, [bp+4] ; src Offset mov bx, [bp+4] ; src Offset
@@ -127,14 +148,10 @@ saveFile:
mov byte [filesize], cl mov byte [filesize], cl
mov si, ax
mov di, filetype mov di, filetype
mov cx, 3 mov cx, 3
.filetype: rep movsb
lodsb
cmp al, 0 ; End of fileName
dec si ; Fill the rest with Null
stosb
loop .getFilename
mov si, [bp+12] ; Filename mov si, [bp+12] ; Filename
mov cx, 10 mov cx, 10
@@ -142,21 +159,29 @@ saveFile:
.getFilename: .getFilename:
lodsb ; mov byte al, [si]; inc si lodsb ; mov byte al, [si]; inc si
cmp al, 0 ; End of fileName cmp al, 0 ; End of fileName
dec si ; Fill the rest with Null je .filenamePad
stosb stosb
loop .getFilename loop .getFilename
jmp .filenameDone
.filenamePad:
dec si ; Fill the rest with Null
.filenamePadLoop:
stosb
loop .filenamePadLoop
.filenameDone:
mov ax, FILETAB_LOC mov ax, FILETAB_LOC
mov es, ax mov es, ax
xor di, di ; es:di - Filetable location xor di, di ; es:di - Filetable location
mov si, fileName mov si, fileName
.fileNameCheck: .fileNameCheck:
mov byte al, [es:di+14] mov byte al, [es:di+14] ; Starting sector
mov byte [availableSector], al cmp al, 0 ; No file, create one
mov byte al, [es:di+15] je createFile
add byte [availableSector], al
mov al, [di] add byte al, [es:di+15] ; Filesize
mov byte [availableSector], al
mov al, [es:di]
cmp al, 0 ; End of filetable cmp al, 0 ; End of filetable
je createFile ; File doesn't exist, create new one je createFile ; File doesn't exist, create new one
@@ -214,6 +239,16 @@ saveFile:
jmp return ; TODO: Fix this jmp return ; TODO: Fix this
createFile: ; Appends a file to the filetable. createFile: ; Appends a file to the filetable.
mov di, FILETAB_LOC
mov es, di
xor di, di
.filetabEnd: ; Move to the end of filetable
cmp byte [es:di], 0
je .filetabEndDone
add di, 16
jmp .filetabEnd
.filetabEndDone:
mov cx, 10 mov cx, 10
mov si, fileName mov si, fileName
rep movsb ; Append the fileName rep movsb ; Append the fileName
@@ -221,6 +256,7 @@ createFile: ; Appends a file to the filetable.
mov si, filetype mov si, filetype
rep movsb ; Append the extension rep movsb ; Append the extension
mov byte [es:di], 0 ; Number of entries mov byte [es:di], 0 ; Number of entries
inc di
mov byte al, [availableSector] mov byte al, [availableSector]
stosb ; Starting sector stosb ; Starting sector
mov byte al, [filesize] mov byte al, [filesize]
@@ -228,13 +264,15 @@ createFile: ; Appends a file to the filetable.
; Write changed filetable to disk ; Write changed filetable to disk
;! If filetable size changes, this will have to change (probably) ;! If filetable size changes, this will have to change (probably)
mov bx, FILETAB_LOC
mov es, bx
xor bx, bx ; es:bx - Filetable location xor bx, bx ; es:bx - Filetable location
mov dl, [diskNum] mov dl, [diskNum]
mov ah, 3 ; Write to disk mov ah, 3 ; Write to disk
mov al, 1 ; Write 1 sector mov al, 1 ; Write 1 sector
mov ch, 0 ; Cylinder mov ch, 0 ; Cylinder
mov dh, 0 ; Head mov dh, 0 ; Head
mov cl, 1 ; Sector mov cl, 2 ; Sector
int 0x13 int 0x13
jnc writeFileData jnc writeFileData
@@ -243,7 +281,7 @@ createFile: ; Appends a file to the filetable.
jmp returnToCaller jmp returnToCaller
writeFileData: ; Writes file data to the disk writeFileData: ; Writes file data to the disk
mov ax, fs ; Source segment mov ax, 0x8000 ; Source segment
mov es, ax mov es, ax
pop bx ; es:bx - Source pop bx ; es:bx - Source
mov ah, 3 ; Write to disk mov ah, 3 ; Write to disk
@@ -260,12 +298,32 @@ writeFileData: ; Writes file data to the disk
returnToCaller: returnToCaller:
; Func epilogue ; Func epilogue
popa pop es
pop si
pop dx
pop cx
pop fs
pop bx
mov sp, bp mov sp, bp
pop bp pop bp
mov byte al, [exitCode] mov byte al, [exitCode]
ret ret
debug:
pusha
mov ah, 0x0e
mov bl, 0x1f
mov bh, 0
.loop:
lodsb ; Load [si] into al; Increment si
or al, al
jz .done
int 0x10
jmp .loop
.done:
popa
ret
;; Variables ;; Variables
availableSector: db 0 availableSector: db 0
exitCode: db 0 exitCode: db 0