all repos — xyw @ 9f4ba1cb0a2a468ccc1f1af4ed7a54cbb10c87c5

A minimal virtual machine and assembler for terminals.

Refactoring with macros.
h3rald h3rald@h3rald.com
Fri, 06 Feb 2026 08:30:48 +0100
commit

9f4ba1cb0a2a468ccc1f1af4ed7a54cbb10c87c5

parent

09909160cf03d85143caee8059e5d650b24658ac

M examples/_macros.xywexamples/_macros.xyw

@@ -40,3 +40,12 @@ .macro beeper.state $40

.macro beeper.samples $41 .macro beeper.n_samples $43 .macro beeper.on_stop $45 + +; Other macros +.macro MOD DIV POP +.macro LBYTE SWP POP +.macro PUTC $11 STB +.macro NL $0A PUTC +.macro SP $20 PUTC +.macro arg.sep $1E +.macro arg.end $1D
M examples/d6.xywexamples/d6.xyw

@@ -1,12 +1,8 @@

.include "_macros.xyw" ; Get random number and calculate modulo 6 -system.random LDB $6 DIV POP +system.random LDB $6 MOD ; Print result+1 and new line -$31 ADD terminal.output STB -$0A terminal.output STB - -; Terminate -$0 system.state STB - +$31 ADD PUTC +NL
M examples/factorial16.xywexamples/factorial16.xyw

@@ -3,7 +3,7 @@

; Main program: calculate and print factorial of 7 $00 $07 fact JSRw PUTDw JSRw -$0A terminal.output STB +NL end JMPw ; Factorial subroutine

@@ -14,7 +14,7 @@ POPxyw

.label fact.loop ; Need to work with 16-bit comparisons ; but JCN only works with 8-bit values, so remove high byte first - PSHyw $00 $00 EQUw SWP POP fact.end0 JCNw + PSHyw $00 $00 EQUw LBYTE fact.end0 JCNw PSHyw $00 $01 EQUw SWP POP fact.end1 JCNw ; Decrement y and multiply DECyw PSHxw PSHyw MULxw POPxw
M examples/factorial8.xywexamples/factorial8.xyw

@@ -3,7 +3,7 @@

; Main program: calculate and print factorial of 5 $5 fact JSRw PUTD JSRw -$0A terminal.output STB +NL end JMPw ; Factorial subroutine
M xyw-vscode/syntaxes/xyw.tmLanguage.jsonxyw-vscode/syntaxes/xyw.tmLanguage.json

@@ -161,8 +161,13 @@ "match": "\\b(system|terminal|file|clock|beeper|)\\.[a-zA-Z0-9_.\\-]*\\b"

}, { "comment": "Library subroutines", - "name": "keyword.other.library.xyw", + "name": "support.class.subroutine.xyw", "match": "\\b(PUTD|PUTDw|PUTS)\\b" + }, + { + "comment": "Other library macros", + "name": "support.class.macro.xyw", + "match": "\\b(LBYTE|SP|NL|PUTC|MOD|arg.sep|arg.end)\\b" }, { "comment": "Label/macro references: starts with letter/underscore, can contain letters, numbers, underscores, dashes, or dots",
M xyw.vimxyw.vim

@@ -36,6 +36,9 @@

" Library subroutines syntax match xywLibrary "\<\(PUTD\|PUTDw\|PUTS\)\>" +" Library macros +syntax match xywLibrary "\<\(LBYTE\|SP\|NL\|MOD\|arg.end\|arg.sep\)\>" + " Instructions - BRK and RTS have no modifiers syntax match xywInstruction "\<\(BRK\|RTS\)\>"

@@ -58,7 +61,7 @@ highlight default link xywEscape SpecialChar

highlight default link xywHexNumber Number highlight default link xywBinNumber Number highlight default link xywInstruction Statement -highlight default link xywLibrary Keyword +highlight default link xywLibrary Constant highlight default link xywDeviceId Type highlight default link xywIdentifier Identifier