in benchmark-c routines, use same CIA timer as the original C code did so the program size is better comparable

This commit is contained in:
Irmen de Jong
2025-12-08 01:08:33 +01:00
parent 2ccfb2ac90
commit feb0774bbd
16 changed files with 288 additions and 71 deletions
+148 -39
View File
@@ -1,48 +1,157 @@
%import textio
%zeropage basicsafe
%option no_sysinit
main {
sub start() {
ubyte[256] @shared array1
ubyte[256] @shared array2
ubyte[256] @shared array3
cia.calibrate()
setvalues()
readvalues()
printvalues()
sys.wait(280)
sub setvalues() {
poke(&array2 + 255, 99)
poke(&array2 + 256, 88)
poke(&array2 + $3000, 77)
}
sub readvalues() {
%ir {{
loadm.b r1007,main.start.array2+255
storem.b r1007,$ff02
load.w r1009,main.start.array2
add.w r1009,#$0100
loadi.b r1008,r1009
storem.b r1008,$ff04
load.w r1011,main.start.array2
add.w r1011,#$3000
loadi.b r1010,r1011
storem.b r1010,$ff06
return
}}
; cx16.r0L = array2[255]
; cx16.r1L = @(&array2 + 256)
; cx16.r2L = @(&array2 + $3000)
}
sub printvalues() {
txt.print_ub(cx16.r0L)
txt.spc()
txt.print_ub(cx16.r1L)
txt.spc()
txt.print_ub(cx16.r2L)
}
cia.print_time()
}
}
cia {
ubyte freq
const ubyte CNT = 200
sub calibrate() {
txt.print("calibrating frequency: ")
tod_init(0)
txt.print_ub(tod_freq())
txt.print(" hz\n")
tod_reset()
}
sub print_time() {
uword t = tod_get10()
txt.print("(cia) time: ")
txt.print_uw(t / 10)
txt.chrout('.')
txt.print_uw(t % 10)
txt.print(" sec.\n")
}
sub tod_reset() {
; set the tod to 0
c64.CIA2TODHR = 0
c64.CIA2TODMIN = 0
c64.CIA2TODSEC = 0
c64.CIA2TOD10 = 0
}
sub tod_get10() -> uword {
ubyte h, m, s, t
uword time
h = c64.CIA2TODHR
m = c64.CIA2TODMIN
s = c64.CIA2TODSEC
t = c64.CIA2TOD10
time = t
time += (s & $0f) * 10
time += (s >> 4) * 100
time += (m & $0f) * 600
time += (m >> 4) * 6000
return time
}
sub tod_init(ubyte f) {
if (f == 0)
freq = tod_detect_freq()
else
freq = f
if (freq == 50)
c64.CIA2CRA |= $80
else
c64.CIA2CRA &= $7f
}
sub tod_freq() -> ubyte {
return freq
}
sub tod_detect_freq() -> ubyte {
uword cbl
c64.CIA2CRB = $40 ; stop timer
c64.CIA2CRA = $80 ; stop timer
; set ta to overflow every 10000 count (~= 10ms)
c64.CIA2TAL = $10
c64.CIA2TAH = $27
c64.CIA2TBL = CNT
c64.CIA2TBH = 0
tod_reset()
c64.CIA2CRB = $41 ; input from tim1 overflow, continuous, start timer
c64.CIA2CRA = $81 ; start timer, continuous tod 50HZ
while c64.CIA2TODSEC == 0 {
; wait for tod to count 1s
}
; cal=CIA2.ta_lo;
; cah=CIA2.ta_hi;
cbl = c64.CIA2TBL
; cbh=CIA2.tb_hi;
; printf("count2 = %d %d %d %d\n",cah, cal, cbh, cbl);
; printf("elapsed ~= %d0ms\n",CNT-cbl);
if (CNT - cbl) > 90
return 50
else
return 60
}
}
;
;
;main {
; sub start() {
; ubyte[256] @shared array1
; ubyte[256] @shared array2
; ubyte[256] @shared array3
;
; setvalues()
; readvalues()
; printvalues()
;
; sub setvalues() {
; poke(&array2 + 255, 99)
; poke(&array2 + 256, 88)
; poke(&array2 + $3000, 77)
; }
;
; sub readvalues() {
; %ir {{
;loadm.b r1007,main.start.array2+255
;storem.b r1007,$ff02
;load.w r1009,main.start.array2
;add.w r1009,#$0100
;loadi.b r1008,r1009
;storem.b r1008,$ff04
;load.w r1011,main.start.array2
;add.w r1011,#$3000
;loadi.b r1010,r1011
;storem.b r1010,$ff06
;return
; }}
;; cx16.r0L = array2[255]
;; cx16.r1L = @(&array2 + 256)
;; cx16.r2L = @(&array2 + $3000)
; }
;
; sub printvalues() {
; txt.print_ub(cx16.r0L)
; txt.spc()
; txt.print_ub(cx16.r1L)
; txt.spc()
; txt.print_ub(cx16.r2L)
; }
; }
;}