Skip to content

Commit

Permalink
Start migrating osrt libraries to syscall libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
beckadamtheinventor committed Jul 28, 2024
1 parent aab4e37 commit 2828e7c
Show file tree
Hide file tree
Showing 21 changed files with 631 additions and 142 deletions.
69 changes: 46 additions & 23 deletions bos.inc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@


;-------------------------------------------------------------------------------
; Executable formats
;-------------------------------------------------------------------------------
Expand Down Expand Up @@ -67,6 +68,8 @@ macro flash_executable? header:1
else
opcode lhs,rhs
end match
else if args relativeto flashexecbase
opcode args - flashexecbase
else
opcode args
end if
Expand All @@ -93,48 +96,65 @@ end macro
;-------------------------------------------------------------------------------
; Syscall library macro
;-------------------------------------------------------------------------------
macro syscalllib?
macro syscalllib? sclname
local exports
db "SCL",0
local flashexecbase
element flashexecbase
virtual
exports.area::
end virtual
virtual at 0
macro export? routine
virtual exports.area
if defined routine.ramroutine
db 2
else
db 1
end if
dw routine
db `routine, 0
end virtual
end macro
macro export_named? routine, name
virtual as "h"
header.area::
end virtual
virtual as "src"
symbols.area::
end virtual
virtual at flashexecbase-5
db "SCL",0
macro export? routine, name, hname, hdef&
virtual exports.area
if defined routine.ramroutine
db 2
else
db 1
end if
dw routine
dw routine-flashexecbase
db name, 0
end virtual
virtual header.area
db hdef
db $A
end virtual
virtual symbols.area
db "public _", hname,$A
db '_',hname,' := syscall "',sclname,'/',name,'"',$A
end virtual
end macro
macro export_data? data, name
macro export_data? data, name, hname, hdef&
virtual exports.area
db 3
dw data
dw data-flashexecbase
db name, 0
end virtual
virtual header.area
db hdef
db $A
end virtual
end macro
macro export_ptr? routine, name
macro export_ptr? routine, name, hname, hdef&
virtual exports.area
db 8
dl routine
db name, 0
end virtual
virtual header.area
db hdef
db $A
end virtual
virtual symbols.area
db "public _", hname,$A
db '_',hname,' := syscall "',sclname,'/',name,'"',$A
end virtual
end macro
macro ram_routine? routine, ramloc
routine.ramroutine:
Expand Down Expand Up @@ -179,8 +199,8 @@ macro syscalllib?
purge export?
purge end?.syscalllib?
end macro
iterate each, call,jp,jq,ld,syscall
macro each? args&
iterate opcode, call,jp,jq,ld,syscall
macro opcode? args&
match lhs=,rhs, args
match (val), lhs
if val relativeto flashexecbase
Expand Down Expand Up @@ -215,9 +235,11 @@ macro syscalllib?
else
opcode lhs
end if
else if args relativeto flashexecbase
opcode args - flashexecbase
else
opcode args
end match
end if
end macro
end iterate
end macro
Expand Down Expand Up @@ -579,7 +601,8 @@ namespace bos
?reservedRAM := ti.ramCodeTop
?bos_UserMem := $D1A881
?ram_fs_start := end_of_usermem-$10
?end_of_usermem := open_device_table
?end_of_usermem := malloc_cache-$400
?bos_basic_vars := malloc_cache-$400
?open_device_table := malloc_cache-$380
?open_device_table.len := $80
?op_stack_bot := malloc_cache-$300
Expand Down
66 changes: 44 additions & 22 deletions build_bos_inc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def build_bos_inc():

with open(path.join(path.dirname(__file__), "bos.inc"),"w") as f:
f.write("""
;-------------------------------------------------------------------------------
; Executable formats
;-------------------------------------------------------------------------------
Expand Down Expand Up @@ -98,6 +99,8 @@ def build_bos_inc():
else
opcode lhs,rhs
end match
else if args relativeto flashexecbase
opcode args - flashexecbase
else
opcode args
end if
Expand All @@ -124,48 +127,65 @@ def build_bos_inc():
;-------------------------------------------------------------------------------
; Syscall library macro
;-------------------------------------------------------------------------------
macro syscalllib?
macro syscalllib? sclname
local exports
db "SCL",0
local flashexecbase
element flashexecbase
virtual
exports.area::
end virtual
virtual at 0
macro export? routine
virtual exports.area
if defined routine.ramroutine
db 2
else
db 1
end if
dw routine
db `routine, 0
end virtual
end macro
macro export_named? routine, name
virtual as "h"
header.area::
end virtual
virtual as "src"
symbols.area::
end virtual
virtual at flashexecbase-5
db "SCL",0
macro export? routine, name, hname, hdef&
virtual exports.area
if defined routine.ramroutine
db 2
else
db 1
end if
dw routine
dw routine-flashexecbase
db name, 0
end virtual
virtual header.area
db hdef
db $A
end virtual
virtual symbols.area
db "public _", hname,$A
db '_',hname,' := syscall "',sclname,'/',name,'"',$A
end virtual
end macro
macro export_data? data, name
macro export_data? data, name, hname, hdef&
virtual exports.area
db 3
dw data
dw data-flashexecbase
db name, 0
end virtual
virtual header.area
db hdef
db $A
end virtual
end macro
macro export_ptr? routine, name
macro export_ptr? routine, name, hname, hdef&
virtual exports.area
db 8
dl routine
db name, 0
end virtual
virtual header.area
db hdef
db $A
end virtual
virtual symbols.area
db "public _", hname,$A
db '_',hname,' := syscall "',sclname,'/',name,'"',$A
end virtual
end macro
macro ram_routine? routine, ramloc
routine.ramroutine:
Expand Down Expand Up @@ -210,8 +230,8 @@ def build_bos_inc():
purge export?
purge end?.syscalllib?
end macro
iterate each, call,jp,jq,ld,syscall
macro each? args&
iterate opcode, call,jp,jq,ld,syscall
macro opcode? args&
match lhs=,rhs, args
match (val), lhs
if val relativeto flashexecbase
Expand Down Expand Up @@ -246,9 +266,11 @@ def build_bos_inc():
else
opcode lhs
end if
else if args relativeto flashexecbase
opcode args - flashexecbase
else
opcode args
end match
end if
end macro
end iterate
end macro
Expand Down
24 changes: 17 additions & 7 deletions src/compatibility/_Str.asm
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,38 @@ _StrCopy:
inc de
jr .


; compare B bytes from data at HL and DE
_StrCmpre:
ld a,(de)
cp a,(hl)
sub a,(hl)
ret nz
inc hl
inc de
djnz .
ret

; compare strings HL and DE
; stop at null terminator without comparing
_StrCmpre0:
ld a,(de)
sub a,(hl)
ret nz
or a,(hl)
ret z
inc de
inc hl
jr .

; return length of string HL in BC
_StrLength:
push af,hl
xor a,a
xor a,a ; A = 0
ld c,a
mlt bc
mlt bc ; BC = ? * 0 --> 0
cpir
scf
sbc hl,hl
sbc hl,bc
ex (sp),hl
pop bc,af
ret
Loading

0 comments on commit 2828e7c

Please sign in to comment.