uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 358a902c16d0fb26ac9f8fd1db8aeeadc0c627a6
parent d3aaf705f33c4b3a2ffe619b8d4f122433d506fc
Author: Andrew Alderwick <andrew@alderwick.co.uk>
Date:   Wed,  7 Jul 2021 21:20:14 +0100

Ported remaining examples to new simplified Console device

Diffstat:
Mprojects/examples/devices/console.lib.tal | 59++++++++++++++++++++++++++++++++---------------------------
Mprojects/examples/devices/file.tal | 15++++++++++++---
2 files changed, 44 insertions(+), 30 deletions(-)

diff --git a/projects/examples/devices/console.lib.tal b/projects/examples/devices/console.lib.tal @@ -1,12 +1,12 @@ ( dev/console ) %RTN { JMP2r } -%PRINT { .Console/string DEO2 } -%BR { #0a .Console/char DEO } +%PRINT { ;print JSR2 } +%BR { #0a .Console/write DEO } ( devices ) -|10 @Console [ &pad $8 &char $1 &byte $1 &short $2 &string $2 ] +|10 @Console [ &pad $8 &write $1 ] ( variables ) @@ -18,46 +18,51 @@ |0100 ( -> ) - ;char-txt PRINT #42 .Console/char DEO BR - ;byte-txt PRINT #ab .Console/byte DEO BR - ;short-txt PRINT #cdef .Console/short DEO2 BR - ;string-txt PRINT ;hello-word .Console/string DEO2 BR + ;char-txt PRINT #42 .Console/write DEO BR + ;byte-txt PRINT #ab ;print-byte JSR2 BR + ;short-txt PRINT #cdef ;print-short JSR2 BR + ;string-txt PRINT ;hello-word ;print JSR2 BR ;hello-word ;print JSR2 - #ffff ;print-hexadecimal JSR2 + #ffff ;print-short JSR2 ;is-word ;print JSR2 - #ffff ;print-decimal JSR2 + #ffff ;print-short-decimal JSR2 BRK -@print ( addr -- ) +@print ( addr* -- ) &loop - ( send ) DUP2 LDA .Console/char DEO + ( send ) DUP2 LDA .Console/write DEO ( incr ) #0001 ADD2 ( loop ) DUP2 LDA ,&loop JCN POP2 RTN -@print-hexadecimal ( short -- ) - LIT '0 .Console/char DEO - LIT 'x .Console/char DEO - DUP2 #0c SFT2 ,&digit JSR - DUP2 #08 SFT2 ,&digit JSR - DUP2 #04 SFT2 ,&digit JSR - ,&digit JSR +@print-short ( short* -- ) + LIT '0 .Console/write DEO + LIT 'x .Console/write DEO + OVR #04 SFT ,&hex JSR + SWP #0f AND ,&hex JSR + DUP #04 SFT ,&hex JSR + #0f AND ,&hex JMP + + &hex + #30 ADD DUP #39 GTH #27 MUL ADD .Console/write DEO RTN - &digit - #0f AND DUP #0a LTH ,&not-alpha JCN - #27 ADD - &not-alpha - LIT '0 ADD .Console/char DEO - POP +@print-byte ( byte -- ) + LIT '0 .Console/write DEO + LIT 'x .Console/write DEO + DUP #04 SFT ,&hex JSR + #0f AND ,&hex JMP + + &hex + #30 ADD DUP #39 GTH #27 MUL ADD .Console/write DEO RTN -@print-decimal ( short -- ) +@print-short-decimal ( short -- ) #00 .number/started STZ DUP2 #2710 DIV2 DUP2 ,&digit JSR #2710 MUL2 SUB2 DUP2 #03e8 DIV2 DUP2 ,&digit JSR #03e8 MUL2 SUB2 @@ -65,7 +70,7 @@ RTN DUP2 #000a DIV2 DUP2 ,&digit JSR #000a MUL2 SUB2 ,&digit JSR .number/started LDZ ,&end JCN - LIT '0 .Console/char DEO + LIT '0 .Console/write DEO &end RTN @@ -73,7 +78,7 @@ RTN SWP POP DUP .number/started LDZ ORA #02 JCN POP JMP2r - LIT '0 ADD .Console/char DEO + LIT '0 ADD .Console/write DEO #01 .number/started STZ RTN diff --git a/projects/examples/devices/file.tal b/projects/examples/devices/file.tal @@ -6,7 +6,7 @@ ( devices ) |00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] -|10 @Console [ &pad $8 &char $1 &byte $1 &short $2 &string $2 ] +|10 @Console [ &pad $8 &write $1 ] |20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ] |a0 @File [ &vector $2 &success $2 &offset $2 &pad $2 &name $2 &length $2 &load $2 &save $2 ] @@ -30,13 +30,13 @@ .File/success DEI2 ORA ;on-success JCN2 - ;failedtxt .Console/string DEO2 + ;failedtxt ;print-string JSR2 BRK @on-success ( -> ) - ;successtxt .Console/string DEO2 + ;successtxt ;print-string JSR2 ( draw image ) MEMORY .Screen/addr DEO2 @@ -62,6 +62,15 @@ BRK BRK +@print-string ( ptr* -- ) + LDAk DUP ,&keep-going JCN + POP POP2 JMP2r + + &keep-going + .Console/write DEO + #0001 ADD2 + ,print-string JMP + @successtxt "Success! 09 $1 @failedtxt "Failed. 09 $1