; Cycle counter for timing checks, on CIA2 timer A (unused by this game; the KERNAL only ; uses it for RS-232). Counts system clock cycles, at most 65535 between start and read. ; ; C prototypes (cycles.h): ; void cycles_start(void); ; unsigned cycles_read(void); /* cycles since cycles_start(), including call overhead */ .export _cycles_start, _cycles_read CIA2_TA_LO = $DD04 CIA2_TA_HI = $DD05 CIA2_CRA = $DD0E .segment "CODE" _cycles_start: lda #$00 sta CIA2_CRA ; stop timer A lda #$FF sta CIA2_TA_LO ; latch = $FFFF sta CIA2_TA_HI lda #%00010001 ; force load, start, continuous, count system clock sta CIA2_CRA rts _cycles_read: lda #$00 sta CIA2_CRA ; stop, so the two bytes belong together lda CIA2_TA_LO ; elapsed = $FFFF - timer = timer XOR $FFFF eor #$FF pha lda CIA2_TA_HI eor #$FF tax pla rts