Skip to content

Commit

Permalink
Many small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
beckadamtheinventor committed Sep 7, 2024
1 parent 44a040e commit f29465b
Show file tree
Hide file tree
Showing 34 changed files with 1,823 additions and 1,168 deletions.
2 changes: 2 additions & 0 deletions bos.inc
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ namespace bos
?sys_ExecBegin := $226E0
?sys_ExecContinue := $226E4
?fs_IsOSBackupPresent := $226E8
?util_SHA256 := $226EC
; end of jump table
;-------------------------------------------------------------------------------
; OS memory areas and misc defines
Expand Down Expand Up @@ -580,6 +581,7 @@ namespace bos
?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
?random_source_ptr := ti.appData+87 ; 3 bytes, stores pointer to random source address
?variable_sym_list_ptr := ti.appData+90 ; 3 bytes, stores pointer to symbol list containing variables for command processing
?ScrapByte := ti.flashByte
?ScrapWord := ti.scrapMem
?ScrapMem := ti.scrapMem
Expand Down
2 changes: 2 additions & 0 deletions bos.src
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
public _sys_ExecBegin
public _sys_ExecContinue
public _fs_IsOSBackupPresent
public _util_SHA256
_boot_os := $20108
_handle_interrupt := $2010C
_HandleInstruction := $20110
Expand Down Expand Up @@ -374,6 +375,7 @@ _sys_ExecData := $226DC
_sys_ExecBegin := $226E0
_sys_ExecContinue := $226E4
_fs_IsOSBackupPresent := $226E8
_util_SHA256 := $226EC

public ram_executable
public ram_executable_at
Expand Down
36 changes: 26 additions & 10 deletions docs/syscalls.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@
<tr><td><a href="#sys_Free">bos.sys_Free</a></td><td><a href="#sys_Free">022528</a></td></tr>
<tr><td><a href="#sys_CallExecuteFile">bos.sys_CallExecuteFile</a></td><td><a href="#sys_CallExecuteFile">02252C</a></td></tr>
<tr><td><a href="#sys_JumpExecuteFile">bos.sys_JumpExecuteFile</a></td><td><a href="#sys_JumpExecuteFile">022530</a></td></tr>
<tr><td><a href="#sys_OpenDevice">bos.sys_OpenDevice</a></td><td><a href="#sys_OpenDevice">022534</a></td></tr>
<tr><td><a href="#drv_InitDevice">bos.drv_InitDevice</a></td><td><a href="#drv_InitDevice">022534</a></td></tr>
<tr><td><a href="#fs_CopyFile">bos.fs_CopyFile</a></td><td><a href="#fs_CopyFile">022538</a></td></tr>
<tr class="no_op"></tr><td><a href="#DONOTHING">bos.DONOTHING</a></td><td><a href="#DONOTHING">02253C</a></td></tr>
<tr class="no_op"></tr><td><a href="#DONOTHING">bos.DONOTHING</a></td><td><a href="#DONOTHING">022540</a></td></tr>
<tr class="no_op"></tr><td><a href="#DONOTHING">bos.DONOTHING</a></td><td><a href="#DONOTHING">022544</a></td></tr>
<tr><td><a href="#sys_GetRandomAddress">bos.sys_GetRandomAddress</a></td><td><a href="#sys_GetRandomAddress">02253C</a></td></tr>
<tr><td><a href="#sys_Random8">bos.sys_Random8</a></td><td><a href="#sys_Random8">022540</a></td></tr>
<tr><td><a href="#sys_Random32">bos.sys_Random32</a></td><td><a href="#sys_Random32">022544</a></td></tr>
<tr><td><a href="#fs_GetSector">bos.fs_GetSector</a></td><td><a href="#fs_GetSector">022548</a></td></tr>
<tr><td><a href="#fs_WriteByte">bos.fs_WriteByte</a></td><td><a href="#fs_WriteByte">02254C</a></td></tr>
<tr><td><a href="#fs_RenameFile">bos.fs_RenameFile</a></td><td><a href="#fs_RenameFile">022550</a></td></tr>
Expand Down Expand Up @@ -192,6 +192,7 @@
<tr><td><a href="#sys_ExecBegin">bos.sys_ExecBegin</a></td><td><a href="#sys_ExecBegin">0226E0</a></td></tr>
<tr><td><a href="#sys_ExecContinue">bos.sys_ExecContinue</a></td><td><a href="#sys_ExecContinue">0226E4</a></td></tr>
<tr><td><a href="#fs_IsOSBackupPresent ">bos.fs_IsOSBackupPresent </a></td><td><a href="#fs_IsOSBackupPresent ">0226E8</a></td></tr>
<tr><td><a href="#util_SHA256">bos.util_SHA256</a></td><td><a href="#util_SHA256">0226EC</a></td></tr>
</table><div id="boot_os "><h1>boot_os </h1> <h3>syscall Adress 020108</h3>
<table><th>What it does</th><th>Inputs</th><th>Outputs</th><th>Destroys</th><th>Notes</th>
</table></div><div id="handle_interrupt"><h1>handle_interrupt</h1> <h3>syscall Adress 02010C</h3>
Expand Down Expand Up @@ -463,7 +464,7 @@
</td></tr>
</table></div><div id="_DelVar"><h1>_DelVar</h1> <h3>syscall Adress 0224FC</h3>
<table><th>What it does</th><th>Inputs</th><th>Outputs</th><th>Destroys</th><th>Notes</th>
<tr><td>delete a file in the /usr/tivars/ directory</td><td>OP1 = type byte, 8 byte name of var to delete</td><td>Cf set if failed</td><td></td><td>
<tr><td>delete a variable in ram from the VAT</td><td>OP1 = type byte, 8 byte name of var to delete</td><td>Cf set if failed</td><td></td><td>
</td></tr>
</table></div><div id="_CreateVar"><h1>_CreateVar</h1> <h3>syscall Adress 022500</h3>
<table><th>What it does</th><th>Inputs</th><th>Outputs</th><th>Destroys</th><th>Notes</th>
Expand Down Expand Up @@ -524,15 +525,26 @@
<tr><td>Jump execution to an executable file</td><td>hl = file to execute<br>
de = arguments</td><td></td><td></td><td>
</td></tr>
</table></div><div id="sys_OpenDevice"><h1>sys_OpenDevice</h1> <h3>syscall Adress 022534</h3>
</table></div><div id="drv_InitDevice"><h1>drv_InitDevice</h1> <h3>syscall Adress 022534</h3>
<table><th>What it does</th><th>Inputs</th><th>Outputs</th><th>Destroys</th><th>Notes</th>
<tr><td>Initialize a device (if needed) and return a device structure.</td><td>device_t *sys_OpenDevice(const char *name);</td><td>pointer to device structure. (file data)<br>
hl=-1 and Cf set if failed.</td><td></td><td>
<tr><td>Initialize a device (if needed)</td><td>int drv_InitDevice(const char *name);</td><td>depends on device, usually -1 and Cf set if failed.</td><td></td><td>
</td></tr>
</table></div><div id="fs_CopyFile"><h1>fs_CopyFile</h1> <h3>syscall Adress 022538</h3>
<table><th>What it does</th><th>Inputs</th><th>Outputs</th><th>Destroys</th><th>Notes</th>
<tr><td>Copy a file given paths and return a file descriptor.</td><td>void *fs_CopyFile(const char *src, const char *dest);</td><td>file descriptor of new file. Returns 0 if failed.</td><td></td><td>
</td></tr>
</table></div><div id="sys_GetRandomAddress"><h1>sys_GetRandomAddress</h1> <h3>syscall Adress 02253C</h3>
<table><th>What it does</th><th>Inputs</th><th>Outputs</th><th>Destroys</th><th>Notes</th>
<tr><td>Find the best unmapped address to sample random numbers from.</td><td>void* sys_GetRandomAddress();</td><td>HL = address</td><td></td><td>
</td></tr>
</table></div><div id="sys_Random8"><h1>sys_Random8</h1> <h3>syscall Adress 022540</h3>
<table><th>What it does</th><th>Inputs</th><th>Outputs</th><th>Destroys</th><th>Notes</th>
<tr><td>Return a random 8-bit number.</td><td>uint8_t sys_Random8();</td><td>A = number</td><td></td><td>
</td></tr>
</table></div><div id="sys_Random32"><h1>sys_Random32</h1> <h3>syscall Adress 022544</h3>
<table><th>What it does</th><th>Inputs</th><th>Outputs</th><th>Destroys</th><th>Notes</th>
<tr><td>Return a random 32-bit number.</td><td>uint32_t sys_Random32();</td><td>EUHL = number</td><td></td><td>
</td></tr>
</table></div><div id="fs_GetSector"><h1>fs_GetSector</h1> <h3>syscall Adress 022548</h3>
<table><th>What it does</th><th>Inputs</th><th>Outputs</th><th>Destroys</th><th>Notes</th>
<tr><td>get the sector a given address lies within</td><td>int fs_GetSector(void *address);</td><td></td><td></td><td>
Expand Down Expand Up @@ -863,7 +875,7 @@
</td></tr>
</table></div><div id="_SearchSymTable"><h1>_SearchSymTable</h1> <h3>syscall Adress 02269C</h3>
<table><th>What it does</th><th>Inputs</th><th>Outputs</th><th>Destroys</th><th>Notes</th>
<tr><td>Search the symbol table (VAT) for a file specified in OP1</td><td>Same as ti.ChkFindSym, except that 0xFF is treated as a wildcard.</td><td>Same as ti.ChkFindSym.</td><td></td><td>
<tr><td>Search the symbol table (VAT) for a file specified in OP1</td><td>Same as ti.ChkFindSym, except that 0xFF is treated as a wildcard.</td><td>Same as ti.ChkFindSym. DE = data pointer, HL = VAT pointer.</td><td></td><td>
</td></tr>
</table></div><div id="fs_Rename"><h1>fs_Rename</h1> <h3>syscall Adress 0226A0</h3>
<table><th>What it does</th><th>Inputs</th><th>Outputs</th><th>Destroys</th><th>Notes</th>
Expand Down Expand Up @@ -897,7 +909,7 @@
</td></tr>
</table></div><div id="util_InitAllocSymList"><h1>util_InitAllocSymList</h1> <h3>syscall Adress 0226C0</h3>
<table><th>What it does</th><th>Inputs</th><th>Outputs</th><th>Destroys</th><th>Notes</th>
<tr><td>Allocate and initialize a Symbol list.</td><td>symlist *util_InitSymList(void);</td><td>Pointer to new Symbol list. 0 if failed.</td><td></td><td>
<tr><td>Allocate and initialize a Symbol list.</td><td>symlist *util_InitAllocSymList(void);</td><td>Pointer to new Symbol list. 0 if failed.</td><td></td><td>
All this does is allocate 6 bytes and set to 0. The memory location doesn't matter as long as it's in RAM and initialized to 0.</td></tr>
</table></div><div id="util_AppendSymList"><h1>util_AppendSymList</h1> <h3>syscall Adress 0226C4</h3>
<table><th>What it does</th><th>Inputs</th><th>Outputs</th><th>Destroys</th><th>Notes</th>
Expand Down Expand Up @@ -941,4 +953,8 @@
</td></tr>
</table></div><div id="fs_IsOSBackupPresent "><h1>fs_IsOSBackupPresent </h1> <h3>syscall Adress 0226E8</h3>
<table><th>What it does</th><th>Inputs</th><th>Outputs</th><th>Destroys</th><th>Notes</th>
</table></div><div id="util_SHA256"><h1>util_SHA256</h1> <h3>syscall Adress 0226EC</h3>
<table><th>What it does</th><th>Inputs</th><th>Outputs</th><th>Destroys</th><th>Notes</th>
<tr><td>Compute a SHA256 hash for some data, writing the 32-byte result to a buffer.</td><td>void util_SHA256(void* buffer, void* data, unsigned int len);</td><td>Nothing.</td><td></td><td>
</td></tr>
</table></div></body></html>
2 changes: 2 additions & 0 deletions src/boot.asm
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ os_return_soft:

call os_check_recovery_key
call sys_FreeAll
call util_InitAllocSymList
ld (variable_sym_list_ptr),hl

call os_check_recovery_key
call fs_SanityCheck
Expand Down
1 change: 1 addition & 0 deletions src/compatibility.inc
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ include 'compatibility/_slow_GetCSC.asm'
include 'compatibility/_GetVATEntryNFromPtr.asm'
include 'compatibility/_GetVATEntryN.asm'
include 'compatibility/_RclAns.asm'
include 'compatibility/_GetVarLength.asm'
44 changes: 10 additions & 34 deletions src/compatibility/_AddVATEntry.asm
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ _AddVATEntry:
ld (hl),c
inc hl
ld (hl),b
dec hl
inc hl
inc iyl
.dont_write_length:
ld de,(ti.pTemp)
push de,hl,bc
push de,hl
ld hl,ti.OP1
ld a,(hl)
ld (de),a
Expand All @@ -43,56 +43,32 @@ _AddVATEntry:
dec de
ld (de),a
inc hl
push hl
ld bc,8
push bc
cpir
pop hl
scf
sbc hl,bc
ex (sp),hl
pop bc
ld a,c
pop bc
ex hl,de
; ld (hl),c ; data length low byte
; dec hl
; ld (hl),b ; data length high byte
; dec hl
pop bc ; data pointer
dec hl
ld (hl),c
dec hl
ld (hl),b
dec hl
pop bc
ld (hl),bc ; data pointer
push hl
ld c,a
call _SetAToBCU
ld (hl),a
ld b,a
ld a,iyl ; check if we need to write a name length byte
or a,a
jr nz,.write_name_length
ex hl,de
ld b,3
jr .copy_name_loop
.write_name_length:
ld (hl),c ; var name length byte
ld (hl),b ; var name length byte
dec hl
ex hl,de
ld b,c
.copy_name_loop:
dec de
ld a,(hl)
ld (de),a
inc hl
djnz .copy_name_loop
pop hl
; reverse the endianness of the data pointer
ld a,(hl)
inc hl
inc hl
ld b,(hl)
ld (hl),a
dec hl
dec hl
ld (hl),b

dec de
ld (ti.pTemp),de ; save new end of VAT
Expand All @@ -116,7 +92,7 @@ _AddVATEntry:
or a,a ; unset the carry flag
pop hl
ccf ; set the carry flag
ret nz
ret nz ; return with carry flag set if malloc cache indicates the block is allocated
ccf ; unset the carry flag
ret

Expand Down
41 changes: 33 additions & 8 deletions src/compatibility/_DelVar.asm
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,45 @@ _DelVarA:
ld (fsOP1),a
jq _DelVar

;@DOES delete a file in the /usr/tivars/ directory
;@DOES delete a variable in ram from the VAT
;@INPUT OP1 = type byte, 8 byte name of var to delete
;@OUTPUT Cf set if failed
;DESTROYS All
_DelVar:
call _OP1ToPath
ret c
call _SearchSymTable
push hl
call fs_DeleteFile
ex hl,de
mlt de
ld e,(hl)
inc hl
ld d,(hl)
dec hl
inc de
inc de
call _DelMem ; delete the data from usermem
pop hl
push hl
ld bc,-6
add hl,bc
ld b,(hl)
.bypassname:
dec hl
djnz .bypassname
pop de
push hl
or a,a
sbc hl,de ; hl = length of VAT entry to delete
ex (sp),hl
push af,hl
call sys_Free
pop bc,af,hl
pop bc
; TODO
; push hl,bc,de
; call ti._memmove ; shift the VAT upwards if needed, overwriting the desired entry
; pop bc,bc,bc
; ret
; .move_last_entry:
; ld (ti.pTemp),bc
ret



30 changes: 30 additions & 0 deletions src/compatibility/_GetVarLength.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
;@DOES return the length in bytes of a given variable in the VAT
;@INPUT HL = VAT pointer
;@OUTPUT HL = size. Cf set if failed.
_GetVarLength:
ld de,(ti.pTemp)
call _CpHLDE
ret c
ld a,(hl)
cp a,ti.AppVarObj
jr z,.file_like_type
cp a,ti.ProgObj
jr z,.file_like_type
cp a,ti.ProtProgObj
jr z,.file_like_type
scf
ret
.file_like_type:
dec hl
dec hl
dec hl
ld e,(hl)
dec hl
ld d,(hl)
dec hl
ld a,(hl)
call _SetDEUToA
ex hl,de
ld hl,(hl)
ex.s de,hl
ret
2 changes: 1 addition & 1 deletion src/compatibility/_SearchSymTable.asm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;@DOES Search the symbol table (VAT) for a file specified in OP1
;@INPUT Same as ti.ChkFindSym, except that 0xFF is treated as a wildcard.
;@OUTPUT Same as ti.ChkFindSym.
;@OUTPUT Same as ti.ChkFindSym. DE = data pointer, HL = VAT pointer.
;@DESTROYS af, bc, iy
_SearchSymTable:
ld iy,(ti.progPtr)
Expand Down
7 changes: 5 additions & 2 deletions src/compatibility/_SetRRUToR.asm
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ _SetBCUToA:
push hl
ld h,b
ld l,c
jr _SetDEUToA._SetHLUToA_popHL
call _SetHLUToA
ex (sp),hl
pop bc
ret

_SetDEUToB:
ld a,b
_SetDEUToA:
push hl
ex hl,de
._SetHLUToA_popHL:
call _SetHLUToA
ex hl,de
pop hl
ret

Expand Down
Loading

0 comments on commit f29465b

Please sign in to comment.