From e6a14422966604c0f951ff0f9d1c481251fca2d9 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 3 Jan 2021 02:45:25 +0100 Subject: [PATCH] sys.wait() no longer resets the jiffyclock to zero --- compiler/res/prog8lib/c64/syslib.p8 | 10 +++++++--- compiler/res/prog8lib/cx16/syslib.p8 | 9 ++++++--- docs/source/todo.rst | 1 - examples/test.p8 | 8 +++----- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/compiler/res/prog8lib/c64/syslib.p8 b/compiler/res/prog8lib/c64/syslib.p8 index 3648c0583..8bc9b4bf7 100644 --- a/compiler/res/prog8lib/c64/syslib.p8 +++ b/compiler/res/prog8lib/c64/syslib.p8 @@ -485,11 +485,15 @@ sys { } sub wait(uword jiffies) { - c64.SETTIM(0,0,0) ; TODO do the wait without resetting the jiffy clock - while c64.RDTIM16() < jiffies { - ; wait till the time catches up + ; --- wait approximately the given number of jiffies (1/60th seconds) + repeat jiffies { + ubyte jiff = lsb(c64.RDTIM16()) + while jiff==lsb(c64.RDTIM16()) { + ; wait until 1 jiffy has passed + } } } + } cx16 { diff --git a/compiler/res/prog8lib/cx16/syslib.p8 b/compiler/res/prog8lib/cx16/syslib.p8 index 1ab32856c..aa8dfed87 100644 --- a/compiler/res/prog8lib/cx16/syslib.p8 +++ b/compiler/res/prog8lib/cx16/syslib.p8 @@ -474,9 +474,12 @@ sys { } sub wait(uword jiffies) { - c64.SETTIM(0,0,0) ; TODO do the wait without resetting the jiffy clock - while c64.RDTIM16() < jiffies { - ; wait till the time catches up + ; --- wait approximately the given number of jiffies (1/60th seconds) + repeat jiffies { + ubyte jiff = lsb(c64.RDTIM16()) + while jiff==lsb(c64.RDTIM16()) { + ; wait until 1 jiffy has passed + } } } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index d5513513a..94dbd5acb 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,7 +3,6 @@ TODO ==== - move all str* builtin functions to a str library module -- make the syslib.wait() functions not reset the jiffy clock to 0 - 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/test.p8 b/examples/test.p8 index e9fb7a997..e104cf37e 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,6 +1,6 @@ %import test_stack %import textio -%zeropage full +%zeropage basicsafe %option no_sysinit main { @@ -8,13 +8,11 @@ main { sub start () { uword current_time - repeat 5 { + repeat 6 { current_time = c64.RDTIM16() txt.print_uw(current_time) txt.chrout('\n') - repeat 60000 { - current_time++ - } + sys.wait(30) }