mirror of
https://github.com/irmen/prog8.git
synced 2024-11-22 15:33:02 +00:00
added c64.RDTIM16() utility routine to just get the lower 16 bits of the jiffy clock
This commit is contained in:
parent
5a846bdeb5
commit
f0930d8a18
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 '_'
|
||||
|
@ -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: ")
|
||||
|
@ -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")
|
||||
|
Binary file not shown.
@ -19,9 +19,10 @@ main {
|
||||
|
||||
sub start() {
|
||||
float time=0.0
|
||||
ubyte timer_jiffies
|
||||
|
||||
repeat {
|
||||
c64.SETTIM(0,0,0)
|
||||
|
||||
rotate_vertices(time)
|
||||
txt.clear_screenchars(' ')
|
||||
draw_edges()
|
||||
@ -30,17 +31,11 @@ main {
|
||||
txt.plot(0,0)
|
||||
txt.print("3d cube! floats. ")
|
||||
|
||||
%asm {{
|
||||
stx P8ZP_SCRATCH_REG
|
||||
jsr c64.RDTIM ; A/X/Y
|
||||
sta timer_jiffies
|
||||
lda #0
|
||||
jsr c64.SETTIM
|
||||
ldx P8ZP_SCRATCH_REG
|
||||
}}
|
||||
txt.print_ub(timer_jiffies)
|
||||
|
||||
ubyte jiffies = lsb(c64.RDTIM16())
|
||||
txt.print_ub(jiffies)
|
||||
txt.print(" jiffies/fr = ")
|
||||
txt.print_ub(60/timer_jiffies)
|
||||
txt.print_ub(60/jiffies)
|
||||
txt.print(" fps")
|
||||
|
||||
;test_stack.test()
|
||||
|
@ -37,25 +37,12 @@ main {
|
||||
angley+=217
|
||||
anglez+=452
|
||||
|
||||
wait_a_little_bit()
|
||||
c64.wait(2)
|
||||
|
||||
; test_stack.test()
|
||||
}
|
||||
}
|
||||
|
||||
sub wait_a_little_bit() {
|
||||
%asm {{
|
||||
stx P8ZP_SCRATCH_REG
|
||||
lda #0
|
||||
jsr c64.SETTIM
|
||||
- jsr c64.RDTIM
|
||||
cmp #1
|
||||
bne -
|
||||
ldx P8ZP_SCRATCH_REG
|
||||
rts
|
||||
}}
|
||||
}
|
||||
|
||||
sub rotate_vertices(ubyte ax, ubyte ay, ubyte az) {
|
||||
; rotate around origin (0,0,0)
|
||||
|
||||
|
@ -1,57 +0,0 @@
|
||||
%import syslib
|
||||
%import textio
|
||||
%import floats
|
||||
%zeropage basicsafe
|
||||
|
||||
; Note: this program is compatible with C64 and CX16.
|
||||
|
||||
main {
|
||||
|
||||
sub start() {
|
||||
|
||||
txt.lowercase()
|
||||
|
||||
; use optimized routine to write text
|
||||
txt.print("Hello!\n")
|
||||
|
||||
; use iteration to write text
|
||||
str question = "How are you?\n"
|
||||
ubyte char
|
||||
for char in question
|
||||
txt.chrout(char)
|
||||
|
||||
; use indexed loop to write characters
|
||||
str bye = "Goodbye!\n"
|
||||
for char in 0 to len(bye)-1
|
||||
txt.chrout(bye[char])
|
||||
|
||||
ubyte time_lo
|
||||
ubyte time_mid
|
||||
ubyte time_hi
|
||||
|
||||
%asm {{
|
||||
stx P8ZP_SCRATCH_REG
|
||||
jsr c64.RDTIM ; A/X/Y
|
||||
sta time_lo
|
||||
stx time_mid
|
||||
sty time_hi
|
||||
ldx P8ZP_SCRATCH_REG
|
||||
}}
|
||||
|
||||
float clock_seconds = ((mkword(time_mid, time_lo) as float) + (time_hi as float)*65536.0) / 60
|
||||
float hours = floor(clock_seconds / 3600)
|
||||
clock_seconds -= hours*3600
|
||||
float minutes = floor(clock_seconds / 60)
|
||||
clock_seconds = floor(clock_seconds - minutes * 60.0)
|
||||
|
||||
txt.print("system time (jiffy clock) is ")
|
||||
floats.print_f(hours)
|
||||
txt.chrout(':')
|
||||
floats.print_f(minutes)
|
||||
txt.chrout(':')
|
||||
floats.print_f(clock_seconds)
|
||||
txt.chrout('\n')
|
||||
|
||||
txt.print("bye!\n")
|
||||
}
|
||||
}
|
@ -40,20 +40,7 @@ main {
|
||||
}
|
||||
}
|
||||
|
||||
ubyte time_lo
|
||||
ubyte time_mid
|
||||
ubyte time_hi
|
||||
|
||||
%asm {{
|
||||
stx P8ZP_SCRATCH_REG
|
||||
jsr c64.RDTIM ; A/X/Y
|
||||
sta time_lo
|
||||
stx time_mid
|
||||
sty time_hi
|
||||
ldx P8ZP_SCRATCH_REG
|
||||
}}
|
||||
|
||||
float duration = ((mkword(time_mid, time_lo) as float) + (time_hi as float)*65536.0) / 60
|
||||
float duration = (c64.RDTIM16() as float) / 60
|
||||
txt.plot(0, 21)
|
||||
txt.print("finished in ")
|
||||
floats.print_f(duration)
|
||||
|
@ -8,34 +8,15 @@ main {
|
||||
|
||||
sub start () {
|
||||
uword current_time
|
||||
uword secs
|
||||
const uword test_value = 1261
|
||||
|
||||
current_time = test_value
|
||||
secs = current_time / 60
|
||||
current_time = (current_time - secs*60)*1000/60
|
||||
txt.print_uw(secs)
|
||||
txt.chrout('.')
|
||||
if current_time<10
|
||||
txt.chrout('0')
|
||||
if current_time<100
|
||||
txt.chrout('0')
|
||||
txt.print_uw(current_time)
|
||||
txt.chrout('\n')
|
||||
|
||||
current_time = test_value
|
||||
secs = current_time / 60
|
||||
current_time = current_time - secs*60
|
||||
current_time *= 1000
|
||||
current_time /= 60
|
||||
txt.print_uw(secs)
|
||||
txt.chrout('.')
|
||||
if current_time<10
|
||||
txt.chrout('0')
|
||||
if current_time<100
|
||||
txt.chrout('0')
|
||||
txt.print_uw(current_time)
|
||||
txt.chrout('\n')
|
||||
repeat {
|
||||
current_time = c64.RDTIM16()
|
||||
txt.print_uw(current_time)
|
||||
txt.chrout('\n')
|
||||
repeat 20000 {
|
||||
current_time++
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
; found = strfind("irmen de jong", ' ')
|
||||
|
Loading…
Reference in New Issue
Block a user