You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.0KB

  1. ; Cycle counter for timing checks, on CIA2 timer A (unused by this game; the KERNAL only
  2. ; uses it for RS-232). Counts system clock cycles, at most 65535 between start and read.
  3. ;
  4. ; C prototypes (cycles.h):
  5. ; void cycles_start(void);
  6. ; unsigned cycles_read(void); /* cycles since cycles_start(), including call overhead */
  7. .export _cycles_start, _cycles_read
  8. CIA2_TA_LO = $DD04
  9. CIA2_TA_HI = $DD05
  10. CIA2_CRA = $DD0E
  11. .segment "CODE"
  12. _cycles_start:
  13. lda #$00
  14. sta CIA2_CRA ; stop timer A
  15. lda #$FF
  16. sta CIA2_TA_LO ; latch = $FFFF
  17. sta CIA2_TA_HI
  18. lda #%00010001 ; force load, start, continuous, count system clock
  19. sta CIA2_CRA
  20. rts
  21. _cycles_read:
  22. lda #$00
  23. sta CIA2_CRA ; stop, so the two bytes belong together
  24. lda CIA2_TA_LO ; elapsed = $FFFF - timer = timer XOR $FFFF
  25. eor #$FF
  26. pha
  27. lda CIA2_TA_HI
  28. eor #$FF
  29. tax
  30. pla
  31. rts

Powered by TurnKey Linux.