all repos — xyw @ f7ccbf798fee75d4683cbd94112348d3160bfc57

A minimal virtual machine and assembler for terminals.

Implemented clock example with timer
h3rald h3rald@h3rald.com
Mon, 09 Feb 2026 10:17:28 +0100
commit

f7ccbf798fee75d4683cbd94112348d3160bfc57

parent

d8f399a70a8224df2cbac96afb3c501e112bf371

2 files changed, 41 insertions(+), 11 deletions(-)

jump to
M examples/clock.xywexamples/clock.xyw

@@ -1,16 +1,47 @@

.include "lib/macros.xyw" -clock.hour LDB -ZEROPADx JSRw -$3A PUTC -clock.minute LDB -ZEROPADx JSRw -$3A PUTC -clock.second LDB -ZEROPADx JSRw -NL +.macro CR $0D PUTC + +; Main program +print-clock JSRw +set-timer JSRw end JMPw +.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

@@ -21,5 +52,4 @@ .label put-zero

$30 PUTC put-digit JMPw -.include "lib/putd.xyw" .label end
M examples/lib/macros.xywexamples/lib/macros.xyw

@@ -23,7 +23,7 @@ .macro clock.weekday $24

.macro clock.hour $25 .macro clock.minute $26 .macro clock.second $27 -.macro clock.timer $29 +.macro clock.timer $28 .macro clock.on_timer $2A ;file