Skip to content

Commit

Permalink
Refactor driver/device files and handling
Browse files Browse the repository at this point in the history
  • Loading branch information
beckadamtheinventor committed Jul 3, 2024
1 parent e9ca64f commit aab4e37
Show file tree
Hide file tree
Showing 28 changed files with 219 additions and 71 deletions.
5 changes: 3 additions & 2 deletions bos.inc
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ namespace bos
?sys_Free := $22528
?sys_CallExecuteFile := $2252C
?sys_JumpExecuteFile := $22530
?sys_OpenDevice := $22534
?drv_InitDevice := $22534
?fs_CopyFile := $22538
;DONOTHING := $2253C
;DONOTHING := $22540
Expand Down Expand Up @@ -556,6 +556,7 @@ namespace bos
?text_flags := ti.appData+63 ; 1 byte. Instructs the OS character printing routines
?gfx_routine_temp := ti.appData+64 ; 16 bytes, temp location for graphics routines
?LastExitCode := ti.appData+80 ; 4 bytes, stores the exit code of the last program that finished executing
?stdout_fd_ptr := ti.appData+84 ; 3 bytes, stores pointer to stdout device descriptor
?ScrapByte := ti.flashByte
?ScrapWord := ti.scrapMem
?ScrapMem := ti.scrapMem
Expand Down Expand Up @@ -661,7 +662,7 @@ namespace bos
?device_JumpDeleteFile := 40
?device_JumpReadFile := 44
?device_JumpWriteFile := 48
?device_CodeStart := 32
?device_CodeStart := 52
?device_Header.len := 1
?device_Flags.len := 1
?device_Type.len := 1
Expand Down
4 changes: 2 additions & 2 deletions bos.src
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
public _sys_Free
public _sys_CallExecuteFile
public _sys_JumpExecuteFile
public _sys_OpenDevice
public _drv_InitDevice
public _fs_CopyFile
public _fs_GetSector
public _fs_WriteByte
Expand Down Expand Up @@ -266,7 +266,7 @@ _fs_DirList := $22524
_sys_Free := $22528
_sys_CallExecuteFile := $2252C
_sys_JumpExecuteFile := $22530
_sys_OpenDevice := $22534
_drv_InitDevice := $22534
_fs_CopyFile := $22538
_fs_GetSector := $22548
_fs_WriteByte := $2254C
Expand Down
19 changes: 19 additions & 0 deletions src/boot.asm
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,25 @@ os_return_soft:
call os_check_recovery_key
call _ResetAndBuildVAT

ld hl,str_DevNull
call drv_InitDevice.entryhl

ld hl,str_DevLcd
call drv_InitDevice.entryhl

ld hl,str_DevStdout
push hl
call drv_InitDevice.entryhl
call nc,fs_OpenFile
pop bc
jr c,.nostdout
call sys_SearchDeviceTable.entryhl
jr nz,.hasstdout
sbc hl,hl
.hasstdout:
ld (stdout_fd_ptr),hl
.nostdout:

; ld hl,str_AutoExtractOptFile
; push hl
; call fs_OpenFile
Expand Down
2 changes: 2 additions & 0 deletions src/data/adrive/src/fs/bin/dump.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
db $18,$04,"FEX",0
ret
17 changes: 10 additions & 7 deletions src/data/adrive/src/fs/bin/explorer/files.asm
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,11 @@ explorer_paste_file:

push hl
call bos.fs_BaseName
push hl
ld de,str_DestinationFilePrompt
call explorer_input_file_name
push hl
or a,a
jq z,.cancel
ex (sp),hl
jr z,.cancel
ld hl,(explorer_dirname_buffer)
push hl
call bos.fs_ParentDir
Expand All @@ -111,18 +110,22 @@ explorer_paste_file:
ld hl,0
.destfile:=$-3
add hl,bc
or a,a
xor a,a
sbc hl,bc
ret z ; return if failed to get destination file name
ld a,0
or a,0
explorer_cut_file_indicator:=$-1
or a,a
jq z,.copy
; or a,a
jr z,.copy
push hl,bc
call bos.fs_MoveFile
scf
sbc hl,hl
ld de,(bos.copy_buffer)
ld (bos.copy_buffer),hl
push de
call bos.sys_Free
pop bc
.cancel:
pop bc,bc
ret
Expand Down
5 changes: 3 additions & 2 deletions src/data/adrive/src/fs/bin/include/bos.inc
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ namespace bos
?sys_Free := $22528
?sys_CallExecuteFile := $2252C
?sys_JumpExecuteFile := $22530
?sys_OpenDevice := $22534
?drv_InitDevice := $22534
?fs_CopyFile := $22538
;DONOTHING := $2253C
;DONOTHING := $22540
Expand Down Expand Up @@ -556,6 +556,7 @@ namespace bos
?text_flags := ti.appData+63 ; 1 byte. Instructs the OS character printing routines
?gfx_routine_temp := ti.appData+64 ; 16 bytes, temp location for graphics routines
?LastExitCode := ti.appData+80 ; 4 bytes, stores the exit code of the last program that finished executing
?stdout_fd_ptr := ti.appData+84 ; 3 bytes, stores pointer to stdout device descriptor
?ScrapByte := ti.flashByte
?ScrapWord := ti.scrapMem
?ScrapMem := ti.scrapMem
Expand Down Expand Up @@ -661,7 +662,7 @@ namespace bos
?device_JumpDeleteFile := 40
?device_JumpReadFile := 44
?device_JumpWriteFile := 48
?device_CodeStart := 32
?device_CodeStart := 52
?device_Header.len := 1
?device_Flags.len := 1
?device_Type.len := 1
Expand Down
3 changes: 2 additions & 1 deletion src/data/adrive/src/fs/bin/include/defines.inc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ saved_LcdUpbase := ti.appData+60 ; 3 bytes, saves LcdUpbase during sector
text_flags := ti.appData+63 ; 1 byte. Instructs the OS character printing routines
gfx_routine_temp := ti.appData+64 ; 16 bytes, temp location for graphics routines
LastExitCode := ti.appData+80 ; 4 bytes, stores the exit code of the last program that finished executing
stdout_fd_ptr := ti.appData+84 ; 3 bytes, stores pointer to stdout device descriptor

ScrapByte := ti.flashByte
ScrapWord := ti.scrapMem
Expand Down Expand Up @@ -189,7 +190,7 @@ device_JumpCreateFile := 36
device_JumpDeleteFile := 40
device_JumpReadFile := 44
device_JumpWriteFile := 48
device_CodeStart := 32
device_CodeStart := 52
; device file field lengths
device_Header.len := 1
Expand Down
4 changes: 2 additions & 2 deletions src/data/adrive/src/fs/dev/lcd.asm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

; /dev/lcd device type memory, r/w + DMA r/w + Init + Deinit, version 2, handling no interrupts.
device_file devtMemory, mDeviceReadable or mDeviceWritable or mDeviceHasDMA or mDeviceDMAReadable or mDeviceDMAWritable or mDeviceInit or mDeviceDeinit, 2, deviceIntNone
; /dev/lcd device type memory, r/w + DMA r/w + Init, version 2, handling no interrupts.
device_file devtMemory, mDeviceReadable or mDeviceWritable or mDeviceHasDMA or mDeviceDMAReadable or mDeviceDMAWritable or mDeviceNeedsInit, 2, deviceIntNone
export device_JumpInit, dev_lcd_init
export device_JumpDeinit, dev_lcd_deinit
export device_JumpGetDMA, dev_lcd_get_address
Expand Down
14 changes: 4 additions & 10 deletions src/data/adrive/src/fs/dev/null.asm
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ dev_null_get_location:
ld hl,$FF0000
ret
dev_null_read:
pop hl,de,bc
push bc,de,hl
pop hl,bc,de
push de,bc,hl
ld hl,$FF0000
ldir
ret
dev_null_write: ; dummy write
pop hl,de,bc
push bc,de,hl
add hl,bc
ex hl,de
ld hl,$FF0000
add hl,bc
ex hl,de
ld bc,0
pop bc,de,hl
push hl,de,bc
ret
end device_file
5 changes: 3 additions & 2 deletions src/data/adrive/src/fs/lib/include/bos.inc
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ namespace bos
?sys_Free := $22528
?sys_CallExecuteFile := $2252C
?sys_JumpExecuteFile := $22530
?sys_OpenDevice := $22534
?drv_InitDevice := $22534
?fs_CopyFile := $22538
;DONOTHING := $2253C
;DONOTHING := $22540
Expand Down Expand Up @@ -556,6 +556,7 @@ namespace bos
?text_flags := ti.appData+63 ; 1 byte. Instructs the OS character printing routines
?gfx_routine_temp := ti.appData+64 ; 16 bytes, temp location for graphics routines
?LastExitCode := ti.appData+80 ; 4 bytes, stores the exit code of the last program that finished executing
?stdout_fd_ptr := ti.appData+84 ; 3 bytes, stores pointer to stdout device descriptor
?ScrapByte := ti.flashByte
?ScrapWord := ti.scrapMem
?ScrapMem := ti.scrapMem
Expand Down Expand Up @@ -661,7 +662,7 @@ namespace bos
?device_JumpDeleteFile := 40
?device_JumpReadFile := 44
?device_JumpWriteFile := 48
?device_CodeStart := 32
?device_CodeStart := 52
?device_Header.len := 1
?device_Flags.len := 1
?device_Type.len := 1
Expand Down
3 changes: 2 additions & 1 deletion src/data/adrive/src/fs/lib/include/defines.inc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ saved_LcdUpbase := ti.appData+60 ; 3 bytes, saves LcdUpbase during sector
text_flags := ti.appData+63 ; 1 byte. Instructs the OS character printing routines
gfx_routine_temp := ti.appData+64 ; 16 bytes, temp location for graphics routines
LastExitCode := ti.appData+80 ; 4 bytes, stores the exit code of the last program that finished executing
stdout_fd_ptr := ti.appData+84 ; 3 bytes, stores pointer to stdout device descriptor

ScrapByte := ti.flashByte
ScrapWord := ti.scrapMem
Expand Down Expand Up @@ -189,7 +190,7 @@ device_JumpCreateFile := 36
device_JumpDeleteFile := 40
device_JumpReadFile := 44
device_JumpWriteFile := 48
device_CodeStart := 32
device_CodeStart := 52
; device file field lengths
device_Header.len := 1
Expand Down
16 changes: 16 additions & 0 deletions src/data/adrive/src/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include 'include/ez80.inc'
include 'include/ti84pceg.inc'
include 'include/bosfs.inc'
include 'include/bos.inc'
include 'include/defines.inc'


org $040000+bos.fs_directory_size
Expand Down Expand Up @@ -39,6 +40,12 @@ fs_dir lib_dir
fs_entry libload_v15, "LibLoad", "v15", f_system
end fs_dir

; "/dev/" directory
fs_dir dev_dir
fs_sfentry _dev_null, "null", "", f_system+f_subfile
fs_sfentry _dev_lcd, "lcd", "", f_system+f_subfile
end fs_dir

;"/bin/" directory
fs_dir bin_dir
; fs_sfentry writeinto_exe, ">", "", f_system+f_subfile
Expand Down Expand Up @@ -90,6 +97,7 @@ fs_dir bin_dir
fs_entry os_internal_subfiles, "osfiles", "dat", f_system
end fs_dir


fs_file os_internal_subfiles

fs_subfile gc_cmd, sbin_dir
Expand Down Expand Up @@ -216,6 +224,14 @@ fs_file os_internal_subfiles
include 'fs/bin/asmcomp.asm'
end fs_subfile

fs_subfile _dev_null, dev_dir
include 'fs/dev/null.asm'
end fs_subfile

fs_subfile _dev_lcd, dev_dir
include 'fs/dev/lcd.asm'
end fs_subfile

; fs_subfile json_exe, bin_dir
; include 'fs/bin/json.asm'
; end fs_subfile
Expand Down
3 changes: 2 additions & 1 deletion src/data/root_dir_data.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
fs_root_dir_data:
db "bin ", $14, $0C,$00, $00,$03
db "bin ", $14, $10,$00, $00,$01
db "dev ", $14, $0C,$00, $00,$01
db "lib ", $14, $08,$00, $00,$01
db "sbin ", $14, $04,$00, $00,$01
.len:=$-.
14 changes: 10 additions & 4 deletions src/data/strings.asm
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ fs_file_data_syscalls.zlen:=$-.
; db "/",$F2,"OS/ELEVATED",0
; str_AutoExtractOptFile:
; db "/EXTRACT.OPT",0
str_DevNull:
db "/dev/null",0
str_DevLcd:
db "/dev/lcd",0
str_DevStdout:
db "/dev/stdout",0
str_sbin_dir:
db "sbin",0
str_var_tivars:
Expand All @@ -238,10 +244,10 @@ string_lib_var:
db "/var/LIB",0
string_var_dir:
db "/var/",0
str_var_index_name:
db "/tmp/cache"
.num:
db "000.dat",0
; str_var_index_name:
; db "/tmp/cache"
; .num:
; db "000.dat",0
str_ram_fs_device:
db "/dev/ramfs",0
str_ExtractingFiles:
Expand Down
9 changes: 9 additions & 0 deletions src/drv.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

; BOS device routines

include 'drv/InitDevice.asm'
include 'drv/GetDMA.asm'
include 'drv/GetChar.asm'
include 'drv/PutChar.asm'
include 'drv/Read.asm'
include 'drv/Write.asm'
25 changes: 25 additions & 0 deletions src/drv/GetChar.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
;@DOES Read a character from a device file given a descriptor
;@INPUT int drv_GetChar(void* fd);
;@OUTPUT Data (usually a character) read from device.
drv_GetChar:
pop bc,hl
push hl,bc
.entryhl:
ld bc,device_JumpRead
add hl,bc
ld a,(hl)
cp a,$C3
ret nz
ld de,0
push de ; push stack memory to read into
push de ; offset 0
inc e
push de ; length 1
ex hl,de
ld hl,6
add hl,sp
push hl ; push pointer to stack memory to read into
ex hl,de
call sys_jphl
pop bc,bc,bc,hl
ret
14 changes: 14 additions & 0 deletions src/drv/GetDMA.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
;@DOES Return a pointer to a device's physical memory address
;@INPUT void *drv_GetDMA(void* fd);
;@OUTPUT pointer to address, 0 if not applicable.
drv_GetDMA:
pop bc,hl
push hl,bc
.entryhl:
ld bc,device_JumpGetDMA
drv.common_no_args:
add hl,bc
ld a,(hl)
cp a,$C3
ret nz
jp (hl)
20 changes: 8 additions & 12 deletions src/sys/OpenDevice.asm → src/drv/InitDevice.asm
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

;@DOES Initialize a device (if needed) and return a device structure.
;@INPUT device_t *sys_OpenDevice(const char *name);
;@OUTPUT pointer to device structure. (file data)
;@OUTPUT hl=-1 and Cf set if failed.
sys_OpenDevice:
;@DOES Initialize a device (if needed)
;@INPUT int drv_InitDevice(const char *name);
;@OUTPUT depends on device, usually -1 and Cf set if failed.
drv_InitDevice:
pop bc,hl
push hl,bc
.entryhl:
Expand All @@ -22,14 +20,12 @@ sys_OpenDevice:
ret nz ; don't reinit an already initialized device
call sys_AppendDeviceTable.entryhl
ret z
push hl
assert device_Flags = 1
inc hl
bit bDeviceNeedsInit,(hl)
ld bc,6
add hl,bc
call nz,sys_jphl
pop hl
ret
ret z
ld bc,device_JumpInit - 1
jr drv.common_no_args
.fail:
scf
sbc hl,hl
Expand Down
Loading

0 comments on commit aab4e37

Please sign in to comment.