time.xyw
time.xyw.include "lib/macros.xyw"
; Main program
print-clock JSRw
set-timer JSRw
HLT
.include "lib/putd.xyw"
; Print current time every second
; --
.label on-timer
CR
; print current time
print-clock JSRw
; reset timer
set-timer JSRw
RTS
; Set on_timer handler and start timer for 1 second
; --
.label set-timer
; reset on_timer handler
on-timer clock.on_timer STW
; reset timer for 1 second
$0100 clock.timer STW
RTS
; Print current time in HH:MM:SS format
; --
.label print-clock
clock.hour LDB
ZEROPADx JSRw
$3A PUTC
clock.minute LDB
ZEROPADx JSRw
$3A PUTC
clock.second LDB
ZEROPADx JSRw
RTS
; Print an 8bit integer as decimal, with leading zero if less than 10
; a8 -[x]-
.label ZEROPADx
POPx PSHx $0A LTH put-zero JCNw
.label put-digit
PSHx putd JSRw
RTS
.label put-zero
$30 PUTC
put-digit JMPw