Skip to content

Commit

Permalink
Generate internal routine defines for easier debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
beckadamtheinventor committed Aug 25, 2024
1 parent a70a7fa commit 44a040e
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 11 deletions.
71 changes: 71 additions & 0 deletions build_bos_internal_inc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/python3
import os

def error(e):
print("Something went wrong!")
print("Error:",e)
quit()

def fwalk(d, ext=None):
for root, dirs, files in os.walk(d):
for file in files:
if ext is not None:
if "." not in file:
continue
x = file.rsplit(".", maxsplit=1)[1]
if x.lower() != ext.lower():
continue
yield root.replace("\\","/")+"/"+file

def build_internal_inc():
print("Building bos_internal.inc")

o = []
sourcelist = list(fwalk("src", "asm"))
# print("\n".join(sourcelist))
for fname in sourcelist:
with open(fname) as f:
curglob = ""
data = f.read().split("\n")
for line in data:
if ":" in line:
if ";" in line:
if line.find(":") > line.find(";"):
continue
if line.startswith("."):
lbl, _ = line.split(":", maxsplit=1)
lbl = curglob + lbl
else:
lbl, _ = line.split(":", maxsplit=1)
curglob = lbl
else:
continue
# print(lbl)
if not all([c.isalnum() or c in '_.' for c in lbl]):
continue
o.append("if defined "+lbl)
o.append("_n_"+lbl+" strcalc "+lbl)
o.append("db '_"+lbl+" := ', _n_"+lbl+",$A")
o.append("end if")

with open("obj/gen_internal.inc", "w") as f:
f.write("""
macro org? a
virtual at a
end macro
include '../src/main.asm'
end virtual
calminstruction (var) strcalc? val
compute val, val ; compute expression
arrange val, val ; convert result to a decimal token
stringify val ; convert decimal token to string
publish var, val
end calminstruction
"""+"\n".join(o))

os.system("fasmg obj/gen_internal.inc bin/bos_internal.inc")


if __name__=='__main__':
build_internal_inc()

1 change: 1 addition & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ includes:
$(CP) $(call NATIVEPATH,src/data/adrive/osrt.inc) $(call NATIVEPATH,$(FSSRC)/fs/bin/include/osrt.inc)
$(CP) $(call NATIVEPATH,src/data/adrive/osrt.inc) $(call NATIVEPATH,$(FSSRC)/fs/lib/include/osrt.inc)
python build_bos_src.py
python build_bos_internal_inc.py

# Rule to create object and binary directories
objdirs:
Expand Down
2 changes: 1 addition & 1 deletion src/data/buildno.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.19.1112 alpha
1.19.1114 alpha
8 changes: 6 additions & 2 deletions src/sys/GetRandomAddress.asm
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ sys_GetRandomAddress:
call .test_byte ; run a total of 513 times

ex hl,de
ld bc,31*8/3 ; change the 31 if the number of tests changes
ld bc,31*8/4 ; change the 31 if the number of tests changes
xor a,a
sbc hl,bc
ret c
jr c,.return_default
add hl,bc

lea hl, iy+0
Expand All @@ -33,6 +33,10 @@ sys_GetRandomAddress:
inc a
ret

.return_default:
ld hl,$D65800
ret

; test byte at hl, set iy=hl if entropy is better
.test_byte:
push de
Expand Down
16 changes: 8 additions & 8 deletions src/threading/HandleInstruction.asm
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ HandleInstruction:
cp a,$C5
jr z,_HandleThreadSpawn
ld hl,threading_enabled
or a,a
jr z,_DisableThreading
inc a
jr z,_DisableThreading
dec a
jr z,_EnableThreading
cp a,$76 + 1
cp a,$76
jr z,_SleepThread
cp a,$E7 + 1
cp a,$E7
jr z,_WakeThread
cp a,$EF + 1
cp a,$EF
jr z,_EnableOSThreading
cp a,$C1 + 1
cp a,$C1
jq z,th_HandleNextThread
cp a,$C9 + 1
cp a,$C9
jq z,th_EndThread
cp a,$F7 + 1
cp a,$F7
ret nz
ld a,(threading_enabled)
cp a,threadOSRoutines
Expand Down
1 change: 1 addition & 0 deletions src/threading/HandleInterrupt.asm
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ th_HandleNextThread:
.nosave:
call th_FindNextThread
ld (current_thread),a
or a,a
sbc hl,hl
ld l,a
add hl,hl
Expand Down

0 comments on commit 44a040e

Please sign in to comment.