From f0930d8a18a36a1dfae64821e1881d8ce2f1b32c Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 2 Jan 2021 20:59:48 +0100 Subject: [PATCH] added c64.RDTIM16() utility routine to just get the lower 16 bits of the jiffy clock --- compiler/res/prog8lib/c64/syslib.p8 | 29 ++++++++------ compiler/res/prog8lib/cx16/syslib.p8 | 31 +++++++++------ docs/source/todo.rst | 3 +- examples/assembler/assem.p8 | 12 +----- examples/balls.p8 | 10 +---- examples/compiled/hello.prg | Bin 968 -> 0 bytes examples/cube3d-float.p8 | 17 +++----- examples/cube3d-gfx.p8 | 15 +------ examples/hello.p8 | 57 --------------------------- examples/mandelbrot.p8 | 15 +------ examples/test.p8 | 35 ++++------------ 11 files changed, 56 insertions(+), 168 deletions(-) delete mode 100644 examples/compiled/hello.prg delete mode 100644 examples/hello.p8 diff --git a/compiler/res/prog8lib/c64/syslib.p8 b/compiler/res/prog8lib/c64/syslib.p8 index 7065169d3..b5c4ef011 100644 --- a/compiler/res/prog8lib/c64/syslib.p8 +++ b/compiler/res/prog8lib/c64/syslib.p8 @@ -245,6 +245,20 @@ asmsub STOP2() -> ubyte @A { }} } +asmsub RDTIM16() -> uword @AY { + ; -- like RDTIM() but only returning the lower 16 bits for convenience + %asm {{ + stx P8ZP_SCRATCH_REG + jsr c64.RDTIM + pha + txa + tay + pla + ldx P8ZP_SCRATCH_REG + rts + }} +} + ; ---- C64 specific system utility routines: ---- @@ -291,18 +305,9 @@ asmsub reset_system() { } sub wait(uword jiffies) { - uword current_time = 0 - c64.SETTIM(0,0,0) - - while current_time < jiffies { - ; read clock - %asm {{ - stx P8ZP_SCRATCH_REG - jsr c64.RDTIM - sta current_time - stx current_time+1 - ldx P8ZP_SCRATCH_REG - }} + c64.SETTIM(0,0,0) ; TODO do the wait without resetting the jiffy clock + while c64.RDTIM16() < jiffies { + ; wait till the time catches up } } diff --git a/compiler/res/prog8lib/cx16/syslib.p8 b/compiler/res/prog8lib/cx16/syslib.p8 index f7a840ed5..19acdf1a2 100644 --- a/compiler/res/prog8lib/cx16/syslib.p8 +++ b/compiler/res/prog8lib/cx16/syslib.p8 @@ -73,6 +73,22 @@ asmsub STOP2() -> ubyte @A { }} } + +asmsub RDTIM16() -> uword @AY { + ; -- like RDTIM() but only returning the lower 16 bits for convenience + %asm {{ + phx + jsr c64.RDTIM + pha + txa + tay + pla + plx + rts + }} +} + + } cx16 { @@ -415,18 +431,9 @@ _loop ldy #0 sub wait(uword jiffies) { - uword current_time = 0 - c64.SETTIM(0,0,0) - - while current_time < jiffies { - ; read clock - %asm {{ - phx - jsr c64.RDTIM - sta current_time - stx current_time+1 - plx - }} + c64.SETTIM(0,0,0) ; TODO do the wait without resetting the jiffy clock + while c64.RDTIM16() < jiffies { + ; wait till the time catches up } } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 23534c9be..b8e3392e1 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -2,8 +2,9 @@ TODO ==== -- add syslib.rdtim16() function to wrap the RDTIM to read only the lower 16 bits of the jiffyclock - fix examples. - move all str* builtin functions to a str library module +- make the syslib.wait() functions not reset the jiffy clock to 0 +- move wait() and others? to sys.* block to unify them from c64.* and cx16.* separation - detect variables that are written but never read - mark those as unused too and remove them, such as uword unused = memory("unused222", 20) - also remove the memory slab allocation - hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine) - make it possible to use cpu opcodes such as 'nop' as variable names by prefixing all asm vars with something such as '_' diff --git a/examples/assembler/assem.p8 b/examples/assembler/assem.p8 index 8a1391398..a5f00327c 100644 --- a/examples/assembler/assem.p8 +++ b/examples/assembler/assem.p8 @@ -42,7 +42,6 @@ main { txt.print_uw(amount) txt.print(" mnemonics") - uword current_time = 0 c64.SETTIM(0,0,0) uword total = 0 @@ -58,16 +57,7 @@ main { } } - ; read clock back - %asm {{ - phx - jsr c64.RDTIM - sta current_time - stx current_time+1 - plx - }} - - + uword current_time = c64.RDTIM16() txt.print("\nDone.\nValid: ") txt.print_uw(valid) txt.print("\ninvalid: ") diff --git a/examples/balls.p8 b/examples/balls.p8 index 0bbcfb4f6..fc0cfb23a 100644 --- a/examples/balls.p8 +++ b/examples/balls.p8 @@ -85,15 +85,7 @@ main { ;txt.print_uw(frame) } - ; read clock - uword jiffies - %asm {{ - stx P8ZP_SCRATCH_REG - jsr c64.RDTIM - sta jiffies - stx jiffies+1 - ldx P8ZP_SCRATCH_REG - }} + uword jiffies = c64.RDTIM16() txt.print("\nbenchmark: ") txt.print_uw(jiffies) txt.print(" jiffies for 1000 frames.\n") diff --git a/examples/compiled/hello.prg b/examples/compiled/hello.prg deleted file mode 100644 index c0f1c4aaa2fc2f750f40c4711e9c2d98e2bed6be..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 968 zcmZXSPfQa*6vl_H!geNsc&mwrM?wOe1XQS?f-S`qmn;E{_F`5&7!M{MJa~{ql5RDI zK}(Q$!899aoWqhx{ZlDiyjUAU8^VE@=*cJtMU06TOx8DB+gjbjy#3z(-ZyV%UyXV| z{aE)1I@-GY(0vbvNAy#E2t**aGi>M2@2y>>`zc0P$z?` z?KnFPCWUopJD?W6ZwJ-F7eP!qPhU36>;iqG?(F?UwTO!8dUM*GjVbWKG3#T~(b=Rj zKfO>tN7f$Bk$ev3>B20E96X>RonVlnaFv11#A;FWG0~3uzoTwQQSqvr-%5C8UWS`2 zrdXZGZDf*)kS`Sy?P}Q6XRm88oVKLhMrQF(0=ddg|2p=R9AyoXQdbJl_&jsB|GSH# zJ$CT}`x>WqC*@1b?xH-!Y(M2snSGSTsz;E_K+Yj+7{lUgB%QtBq6qm-qxCp+-(dBco%XAs7n}g`j0HJTMS}pr!{;w?cRn zNH(NtI#OBvESww(K}0{(%gJk9?=MytoyzNtO>xj9qS>s0r~`K$m~ccbhk~f%F^?d; zu>e=7FMZAsw|LwmzVQ~tuzdxuhx-bK>4_={^2D=Ki=Ac*KaGi^@75|=iz$xF}`&SwJ-o9oe#!QLwJa=J6(f4lyky