all repos — xyw @ 9c362232dc125ebcfd7e1badd0421e89b2e6092b

A minimal virtual machine and assembler for terminals.

examples/time.xyw

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
.include "lib/macros.xyw"

; 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
  .label put-digit
    PSHx putd JSRw
    CLRx
    RTS
  .label put-zero
    $30 PUTC
    put-digit JMPw

.label end