Skip to content

Instantly share code, notes, and snippets.

@ox
Created August 13, 2021 22:26
Show Gist options
  • Save ox/0f7bb945b7caf8b730b2dbe4b60ebdd2 to your computer and use it in GitHub Desktop.
Save ox/0f7bb945b7caf8b730b2dbe4b60ebdd2 to your computer and use it in GitHub Desktop.
Classic guess the number game written in Uxntal
( guess-number.tal )
%RTN { JMP2r }
%PRINT { ;print JSR2 }
%BR { #0a .Console/write DEO }
%BREAKPOINT { #0101 #0e DEO2 }
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ]
|b0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ]
|0000
@number $1
|0100 ( -> )
( set system colors )
#2ce9 .System/r DEO2
#01c0 .System/g DEO2
#2ce5 .System/b DEO2
( grab the seconds from the time,
take the bottom nibble 0 - 15,
subtract 6 if the number is more than 10
)
.DateTime/second DEI #0f AND DUP #0a LTH ,&store JCN #06 SUB &store .number STZ
;intro PRINT BR POP
;prompt PRINT POP
;game-loop .Console/vector DEO2
BRK
@game-loop ( -> )
.Console/read DEI
DUP #0a EQU ,&try JCN ( skip carriage return )
#30 SUB ( convert from ascii to bin )
DUP ( grab a copy )
.number LDZ NEQ ,&wrong JCN ( is this the right number? )
;right PRINT BR ( yay you guessed it! )
#0000 .Console/vector DEO2 ( clear out console vector handler )
BRK
&wrong
#30 ADD DUP .Console/write DEO ( print the number again )
;wrong PRINT BR POP ( say it's wrong )
;prompt PRINT ( prompt for a new answer )
&try
BRK
@print ( addr* -- )
&loop
( send ) DUP2 LDA .Console/write DEO
( incr ) #0001 ADD2
( loop ) DUP2 LDA ,&loop JCN
POP
RTN
@intro "Guess 20 "the 20 "number! 00
@prompt "> 20 00
@wrong 20 "is 20 "wrong 00
@right "You 20 "win! 00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment