all repos — xyw @ 72c00afbbe49afa44632bb40550d12161656b892

A minimal virtual machine and assembler for terminals.

Modified stack notation
h3rald h3rald@h3rald.com
Fri, 14 Aug 2026 13:13:01 +0200
commit

72c00afbbe49afa44632bb40550d12161656b892

parent

8e8d91d36f3689745d535f61f3dc52c025bd719d

M examples/clock-repl.xywexamples/clock-repl.xyw

@@ -13,7 +13,7 @@ .include "lib/putd.xyw"

.include "lib/puts.xyw" ; Register keypress and timer handlers, start 1-second timer -; -- +; -> .label setup-handlers on-keypress terminal.on_keypress STW on-timer clock.on_timer STW

@@ -21,14 +21,14 @@ $0100 clock.timer STW

RTS ; Timer handler: redraw the prompt line with updated clock -; -- +; -> .label on-timer redraw-line JSRw $0100 clock.timer STW RTS ; Keypress handler -; -- +; -> .label on-keypress terminal.input LDB ; Enter

@@ -50,11 +50,12 @@ ; Echo the character

PUTC RTS +; a8 -> .label on-ignore POP RTS ; Enter: echo back the line -; -- +; a8 -> .label on-enter POP NL

@@ -68,7 +69,7 @@ print-prompt JSRw

RTS ; Backspace: remove last character -; -- +; a8 -> .label on-backspace POP buf-len LDBw $00 EQU on-backspace.done JCNw

@@ -78,7 +79,7 @@ .label on-backspace.done

RTS ; Print the clock prompt: [HH:MM:SS] > -; -- +; -> .label print-prompt $5B PUTC clock.hour LDB ZEROPADx JSRw

@@ -90,7 +91,7 @@ $5D PUTC SP $3E PUTC SP

RTS ; Redraw current line in-place: CR + prompt + buffer + clear-to-EOL -; -- +; -> .label redraw-line $0D PUTC print-prompt JSRw

@@ -100,7 +101,7 @@ $1B PUTC $5B PUTC $4B PUTC

RTS ; Print buffer contents (buf[0..len-1]) -; -[xw, y]- +; -> .label print-buffer buf POPxw buf-len LDBw POPy

@@ -113,7 +114,7 @@ .label print-buffer.done

RTS ; Print 8-bit value with leading zero if < 10 -; a8 -[x]- +; a8 -> .label ZEROPADx POPx PSHx $0A LTH zeropad.zero JCNw .label zeropad.digit
M examples/factorial16.xywexamples/factorial16.xyw

@@ -7,7 +7,7 @@ NL

HLT ; Factorial subroutine -; a16 -[xy]- +; a16 -> .label fact ; Save argument to both registers POPxyw
M examples/factorial8.xywexamples/factorial8.xyw

@@ -7,7 +7,7 @@ NL

HLT ; Factorial subroutine -; a8 -[xy]- +; a8 -> .label fact ; Save argument to both registers POPxy
M examples/helloworld.xywexamples/helloworld.xyw

@@ -2,8 +2,8 @@ ; main program

hello print JSRw HLT -; a16 -- ; printing subroutine +; a16 -> .label print ; store top of stack to register XW POPxw
M examples/korobeiniki.xywexamples/korobeiniki.xyw

@@ -12,7 +12,7 @@ ; Store address of start song in xw

start-song POPxw ; Process <length> <pitch> pairs until end-song -; a16 b16 -[xw]- +; a16 b16 -> .label play ; Set length LDWxw beeper.length STW
M examples/lib/contains.xywexamples/lib/contains.xyw

@@ -2,7 +2,7 @@ ; <str> <fragment> contains -> $00|$01

; xw -> index of string ; yw -> index of fragment ; y -> internal index within fragment -; a16 b16 -[xxwyw]- a8 +; a16 b16 -> a8 .label contains POPyw POPxw ; save both addresses to xw and yw $00 POPy ; set y to zero
M examples/lib/equals.xywexamples/lib/equals.xyw

@@ -1,7 +1,5 @@

-; .include "lib/macros.xyw" - ; Check if two strings are equal -; a16 b16 -- a8 +; a16 b16 -> a8 .label equals ; save addresses to registers POPyw POPxw
M examples/lib/length.xywexamples/lib/length.xyw

@@ -1,7 +1,5 @@

-; .include "lib/macros.xyw" - ; returns the length of a string (max: 255) -; a16 -[xxw]- a8 +; a16 -> a8 .label length POPxw ; store start address $00 POPx ; counter
M examples/lib/lengthw.xywexamples/lib/lengthw.xyw

@@ -1,5 +1,5 @@

-; returns the length of a string (max: 255) -; a16 -[xwyw]- b16 +; returns the length of a string +; a16 -> b16 .label lengthw POPxw ; store start address $0000 POPyw ; counter
M examples/lib/lowcase.xywexamples/lib/lowcase.xyw

@@ -1,7 +1,5 @@

-;.include "lib/macros.xyw" - ; Convert a string to lowercase -; a16 -[xw]- +; a16 -> .label lowcase ; store index POPxw
M examples/lib/oneof.xywexamples/lib/oneof.xyw

@@ -1,7 +1,5 @@

-; .include "lib/macros.xyw" - ; Checks if char a16 is one of chars in b16 (string) -; a16 b16 -[xwyw]- a8 +; a16 b16 -> a8 .label oneof POPyw POPxw
M examples/lib/osdetect.xywexamples/lib/osdetect.xyw

@@ -1,10 +1,9 @@

-; UNTESTED ; .include "lib/macros.xyw" ; .include "lib/lowcase.xyw" ; .include "lib/contains.xyw" ; Pushes address to OS identifier -; -- a16 +; -> a16 .label osdetect ; Set command to execute osdetect.cmd file.path STW
M examples/lib/putd.xywexamples/lib/putd.xyw

@@ -1,7 +1,5 @@

-; .include "lib/macros.xyw" - ; Print an 8bit integer as decimal -; a8 -[x]- +; a8 -> .label putd POPx ; If value is less than 10, print single digit
M examples/lib/putdw.xywexamples/lib/putdw.xyw

@@ -1,7 +1,7 @@

; .include "lib/macros.xyw" ; Print a 16bit integer as decimal -; a16 -[x]- +; a16 -> .label putdw POPxw ; If value is less than 10, print single digit
M examples/lib/puts.xywexamples/lib/puts.xyw

@@ -1,7 +1,7 @@

; .include "lib/macros.xyw" ; Print a string starting at address -; a16 -[xw]- +; a16 -> .label puts POPxw .label puts.loop
M examples/lib/upcase.xywexamples/lib/upcase.xyw

@@ -1,7 +1,5 @@

-;.include "lib/macros.xyw" - ; Convert a string to uppercase -; a16 -[xw]- +; a16 -> .label upcase ; store index POPxw
M examples/on-error.xywexamples/on-error.xyw

@@ -8,7 +8,7 @@ $10 $00 DIV

HLT ; on_error handler -; -- +; -> .label on_error system.error LDB $01 EQU on_error.div-by-zero.print JCNw unknown-error puts JSRw
M examples/print-args.xywexamples/print-args.xyw

@@ -6,7 +6,7 @@ ; End program

HLT ; on_argument event handler -; -[x]- +; -> .label print-args terminal.input POPx ; If end of argument, print new line and end
M examples/print-stdin.xywexamples/print-stdin.xyw

@@ -6,7 +6,7 @@ ; End program

HLT ; on_keypress event handler -; -- +; -> .label print-key ; Print typed character terminal.input LDB PUTC
M examples/time.xywexamples/time.xyw

@@ -8,7 +8,7 @@

.include "lib/putd.xyw" ; Print current time every second -; -- +; -> .label on-timer CR ; print current time

@@ -18,7 +18,7 @@ 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

@@ -27,7 +27,7 @@ $0100 clock.timer STW

RTS ; Print current time in HH:MM:SS format -; -- +; -> .label print-clock clock.hour LDB ZEROPADx JSRw

@@ -40,7 +40,7 @@ ZEROPADx JSRw

RTS ; Print an 8bit integer as decimal, with leading zero if less than 10 -; a8 -[x]- +; a8 -> .label ZEROPADx POPx PSHx $0A LTH put-zero JCNw .label put-digit