Skip to content

Commit

Permalink
Add syslibs. experimental, not part of the main build.
Browse files Browse the repository at this point in the history
  • Loading branch information
beckadamtheinventor committed Jul 28, 2024
1 parent 2828e7c commit 01bf859
Show file tree
Hide file tree
Showing 11 changed files with 405 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@
/src/data/updates.asm
/src/os
/src/os.inc
/tests
/syslib
/tests
32 changes: 32 additions & 0 deletions syslib/_.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
include "../src/include/ez80.inc"
include "../src/include/ti84pceg.inc"
include "../bos.inc"
syscalllib "_"
export_ptr bos._MemClear, "MemClear"
export_ptr bos._PushOP1, "PushOP1"
export_ptr bos._PopOP1, "PopOP1"
export_ptr bos._Mov9ToOP1, "Mov9ToOP1"
export_ptr bos._CpHLDE, "CpHLDE"
export_ptr bos._Mov8b, "Mov8b"
export_ptr bos._ChkFindSym, "ChkFindSym"
export_ptr bos._LoadDEInd_s, "LoadDEInd_s"
export_ptr bos._EnoughMem, "EnoughMem"
export_ptr bos._InsertMem, "InsertMem"
export_ptr bos._SetHLUTo0, "SetHLUTo0"
export_ptr bos._PutS, "PutS"
export_ptr bos._GetCSC, "GetCSC"
export_ptr bos._NewLine, "NewLine"
export_ptr bos._ClrScrn, "ClrScrn"
export_ptr bos._HomeUp, "HomeUp"
export_ptr bos._ErrMemory, "ErrMemory"
export_ptr bos._DrawStatusBar, "DrawStatusBar"
export_ptr bos._UsbPowerVbus, "UsbPowerVbus"
export_ptr bos._UsbUnpowerVbus, "UsbUnpowerVbus"
export_ptr bos._LoadLibraryOP1, "LoadLibraryOP1"
export_ptr bos._DelVar, "DelVar"
export_ptr bos._CreateVar, "CreateVar"
export_ptr bos._SetCursorPos, "SetCursorPos"
export_ptr bos._OP1ToPath, "OP1ToPath"
export_ptr bos._UnpackUpdates, "UnpackUpdates"
export_ptr bos._SearchSymTable, "SearchSymTable"
end syscalllib
48 changes: 48 additions & 0 deletions syslib/fs.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
include "../src/include/ez80.inc"
include "../src/include/ti84pceg.inc"
include "../bos.inc"
syscalllib "fs"
export_ptr bos.fs_OpenFile, "OpenFile"
export_ptr bos.fs_GetSectorAddress, "GetSectorAddress"
export_ptr bos.fs_CheckDirExists, "CheckDirExists"
export_ptr bos.fs_CeilDivBySector, "CeilDivBySector"
export_ptr bos.fs_CopyFileName, "CopyFileName"
export_ptr bos.fs_Read, "Read"
export_ptr bos.fs_Write, "Write"
export_ptr bos.fs_CreateRamFile, "CreateRamFile"
export_ptr bos.fs_AllocRam, "AllocRam"
export_ptr bos.fs_CreateFile, "CreateFile"
export_ptr bos.fs_AbsPath, "AbsPath"
export_ptr bos.fs_MultByBytesPerSector, "MultByBytesPerSector"
export_ptr bos.fs_OpenFileInDir, "OpenFileInDir"
export_ptr bos.fs_SetSize, "SetSize"
export_ptr bos.fs_WriteFile, "WriteFile"
export_ptr bos.fs_DeleteFile, "DeleteFile"
export_ptr bos.fs_InitClusterMap, "InitClusterMap"
export_ptr bos.fs_PathLen, "PathLen"
export_ptr bos.fs_ParentDir, "ParentDir"
export_ptr bos.fs_StrToFileEntry, "StrToFileEntry"
export_ptr bos.fs_DirList, "DirList"
export_ptr bos.fs_CopyFile, "CopyFile"
export_ptr bos.fs_GetSector, "GetSector"
export_ptr bos.fs_WriteByte, "WriteByte"
export_ptr bos.fs_RenameFile, "RenameFile"
export_ptr bos.fs_CreateDir, "CreateDir"
export_ptr bos.fs_SanityCheck, "SanityCheck"
export_ptr bos.fs_GetFilePtrRaw, "GetFilePtrRaw"
export_ptr bos.fs_GarbageCollect, "GarbageCollect"
export_ptr bos.fs_WriteNewFile, "WriteNewFile"
export_ptr bos.fs_GetFreeSpace, "GetFreeSpace"
export_ptr bos.fs_GetFDPtrRaw, "GetFDPtrRaw"
export_ptr bos.fs_GetFDLenRaw, "GetFDLenRaw"
export_ptr bos.fs_JoinPath, "JoinPath"
export_ptr bos.fs_BaseName, "BaseName"
export_ptr bos.fs_MoveFile, "MoveFile"
export_ptr bos.fs_WriteDirectly, "WriteDirectly"
export_ptr bos.fs_GetFilePtr, "GetFilePtr"
export_ptr bos.fs_GetFDPtr, "GetFDPtr"
export_ptr bos.fs_GetFDLen, "GetFDLen"
export_ptr bos.fs_ArcUnarcFD, "ArcUnarcFD"
export_ptr bos.fs_Rename, "Rename"
export_ptr bos.fs_AllocChk, "AllocChk"
end syscalllib
35 changes: 35 additions & 0 deletions syslib/gfx.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
include "../src/include/ez80.inc"
include "../src/include/ti84pceg.inc"
include "../bos.inc"
syscalllib "gfx"
export_ptr bos.gfx_BlitBuffer, "BlitBuffer"
export_ptr bos.gfx_PrintString, "PrintString"
export_ptr bos.gfx_BufClear, "BufClear"
export_ptr bos.gfx_LcdClear, "LcdClear"
export_ptr bos.gfx_SetDraw, "SetDraw"
export_ptr bos.gfx_SwapTextColors, "SwapTextColors"
export_ptr bos.gfx_SetFont, "SetFont"
export_ptr bos.gfx_SetDefaultFont, "SetDefaultFont"
export_ptr bos.gfx_Compute, "Compute"
export_ptr bos.gfx_FillRectangle, "FillRectangle"
export_ptr bos.gfx_FillScreen, "FillScreen"
export_ptr bos.gfx_GetFontPtr, "GetFontPtr"
export_ptr bos.gfx_HorizLine, "HorizLine"
export_ptr bos.gfx_InitStdPalette, "InitStdPalette"
export_ptr bos.gfx_NextLine, "NextLine"
export_ptr bos.gfx_PrintChar, "PrintChar"
export_ptr bos.gfx_PrintHexA, "PrintHexA"
export_ptr bos.gfx_PrintUInt, "PrintUInt"
export_ptr bos.gfx_Rectangle, "Rectangle"
export_ptr bos.gfx_Set8bpp, "Set8bpp"
export_ptr bos.gfx_Set16bpp, "Set16bpp"
export_ptr bos.gfx_SetTextXY, "SetTextXY"
export_ptr bos.gfx_Sprite, "Sprite"
export_ptr bos.gfx_Sprite2x, "Sprite2x"
export_ptr bos.gfx_VertLine, "VertLine"
export_ptr bos.gfx_PrintStringXY, "PrintStringXY"
export_ptr bos.gfx_GetTextX, "GetTextX"
export_ptr bos.gfx_GetTextY, "GetTextY"
export_ptr bos.gfx_BlitScreen, "BlitScreen"
export_ptr bos.gfx_ZeroVRAM, "ZeroVRAM"
end syscalllib
16 changes: 16 additions & 0 deletions syslib/gui.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include "../src/include/ez80.inc"
include "../src/include/ti84pceg.inc"
include "../bos.inc"
syscalllib "gui"
export_ptr bos.gui_DrawConsoleWindow, "DrawConsoleWindow"
export_ptr bos.gui_Input, "Input"
export_ptr bos.gui_NewLine, "NewLine"
export_ptr bos.gui_Print, "Print"
export_ptr bos.gui_PrintInt, "PrintInt"
export_ptr bos.gui_Scroll, "Scroll"
export_ptr bos.gui_InputNoClear, "InputNoClear"
export_ptr bos.gui_PrintChar, "PrintChar"
export_ptr bos.gui_PrintString, "PrintString"
export_ptr bos.gui_PrintLine, "PrintLine"
export_ptr bos.gui_PrintUInt, "PrintUInt"
end syscalllib
6 changes: 6 additions & 0 deletions syslib/os.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include "../src/include/ez80.inc"
include "../src/include/ti84pceg.inc"
include "../bos.inc"
syscalllib "os"
export_ptr bos.os_GetOSInfo, "GetOSInfo"
end syscalllib
6 changes: 6 additions & 0 deletions syslib/sc.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include "../src/include/ez80.inc"
include "../src/include/ti84pceg.inc"
include "../bos.inc"
syscalllib "sc"
export_ptr bos.sc_HandleSysCall, "HandleSysCall"
end syscalllib
196 changes: 196 additions & 0 deletions syslib/str.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
include "../src/include/ez80.inc"
include "../src/include/ti84pceg.inc"
include "../bos.inc"
syscalllib "str"

; Exports must follow code labels otherwise this doesn't build for some reason

str_readid:
call ti._frameset0
ld de,(ix+9)
ld hl,(ix+12)
or a,a
sbc hl,de ; len - offset
jr c,str_readline.fail
push hl
pop bc
ld hl,(ix+6)
add hl,de ; src + offset
push hl
jr .loop.entry
.loop:
ld a,(hl)
sub a,'0'
cp a,10
jr nc,.done
.loop.entry:
ld a,(hl)
cp a,'_'
jr z,.loop.next
sub a,'A'
cp a,26
jr c,.loop.next
sub a,$20
cp a,26
jr nc,.done
.loop.next:
cpi
jp pe,.loop
.done:
pop de
or a,a
sbc hl,de ; end - start
jr z,str_readline.line_len_0
inc hl ; +1 for null terminator
push de
jr internal.malloc_and_return_ldir_string

str_readlineuntil:
call ti._frameset0
ld a,(ix+15)
jr str_readline.entry_a

str_readuntil:
call ti._frameset0
ld a,(ix+15)
scf
jr str_readline.entry_af

str_readline:
ld a,$A ; newline
.entry_a:
or a,a
.entry_af:
push af
ld de,(ix+9)
ld hl,(ix+12)
or a,a
sbc hl,de ; len - offset
jr c,.fail
push hl
pop bc
ld hl,(ix+6)
add hl,de ; src + offset
pop af
push hl
; or a,a
call .entry
add hl,bc
or a,a
sbc hl,bc
jr z,.line_len_0
internal.malloc_and_return_ldir_string:=$
push hl
call bos.sys_Malloc
ex hl,de
pop bc ; length of line
pop hl ; pointer to start of line
jr c,.fail
util.return_ldir_string:=$
push de
ldir
xor a,a
ld (de),a
pop hl
pop ix
ret

.line_len_0:
ld hl,$FF0000
db $01 ; ld bc,... dummify or a / sbc hl
.fail:
or a,a
sbc hl,hl
ld sp,ix
pop ix
ret

; if Cf set as input this will check for character in a and newline, otherwise just a
; input hl pointer to data, bc length of data
; returns length of line in hl
.entry:
jr c,.entry.check_two
cpir
jr .entry.exit
.entry.check_two:
ld e,a
cp a,(hl)
jr z,.entry.exit
ld a,(hl)
cp a,e
jr z,.entry.exit
ld a,e
cpi
jp pe,.entry.check_two
.entry.exit:
push bc
pop hl
ret

str_sub:
call ti._frameset0
ld hl,(ix+6) ; str
push hl
call ti._strlen
ex hl,de
ld bc,(ix+12) ; length
ld hl,(ix+9) ; start
add hl,bc
or a,a
sbc hl,de
add hl,de
pop de
jr nc,.fail
add hl,de
util.malloc_bc_and_copy_from_hl:=$
push hl,bc
call bos.sys_Malloc
ex hl,de
pop bc,hl
jr c,.fail
push de
ldir
pop hl
db $01 ; dummify or a,a / sbc hl,hl
.fail:
or a,a
sbc hl,hl
pop ix
ret

mem_dup:
call ti._frameset0
ld hl,(ix+6)
ld bc,(ix+9)
jr util.malloc_bc_and_copy_from_hl


str_dup:
ld hl,6
add hl,sp
ld hl,(hl)
push hl
call ti._strlen
push hl
call bos.sys_Malloc
ex hl,de
pop bc,hl
jr c,.fail
push de
ldir
pop hl
ret
.fail:
or a,a
sbc hl,hl
ret

export str_sub, "sub", "strsub", "// output copied substring or 0 if start+length > strlen(str) or if malloc failed.",$A,"char *strsub(const char *str, const size_t start, const size_t length);"
export str_dup, "dup", "strdup", "// output copied substring or 0 if malloc failed.",$A,"char *strdup(const char *str);"
export mem_dup, "mdup", "memdup", "// Malloc a copy of len bytes at mem. Returns 0 if failed.",$A,"void *memdup(const void *mem, const size_t len);"
export str_readline, "rdln", "str_readline", "char *str_readline(const char *src, const size_t offset, const size_t len);"
export str_readuntil, "rdun", "str_readuntil", "char *str_readuntil(const char *src, const size_t offset, const size_t len, char end);"
export str_readlineuntil, "rdlnun", "str_readlineuntil", "char *str_readlineuntil(const char *src, const size_t offset, const size_t len, char end);"
export str_readid, "rdid", "str_readid", "char *str_readid(const char *src, const size_t offset, const size_t len);"

end syscalllib
Loading

0 comments on commit 01bf859

Please sign in to comment.