Created
March 9, 2024 02:13
-
-
Save Ismael-VC/fefddc2505ef1bd5825409d0e34c9562 to your computer and use it in GitHub Desktop.
ASCII to Morse code in Uxntal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%d { #010e DEO } | |
|20 @SP |0a @CR |06 @morse-align | |
|100 | |
;ascii-str print-ascii>morse | |
BRK | |
@print-ascii>morse | |
&while ( str* -- ) | |
LDAk DUP is-digit ?{ | |
print-morse-digit !&continue | |
} DUP is-space ?{ | |
POP morse-space !&continue | |
} DUP is-newline ?{ | |
POP cr !&continue | |
} DUP is-alpha ?{ | |
print-morse-char | |
} | |
&continue | |
INC LDAk ?&while | |
POP2 | |
JMP2r | |
@print-str ( str* -- ) | |
&while | |
LDAk emit | |
INC LDAk ?&while | |
POP2 | |
.SP emit | |
JMP2r | |
@print-morse-digit ( digit -- ) | |
#30 SUB .morse-align MUL | |
#00 SWP ;morse ADD2 | |
print-str | |
JMP2r | |
@print-morse-char ( char -- ) | |
( ;is-alpha/is-lowercase LDA #41 SUB ) | |
#30 SUB .morse-align MUL | |
#00 SWP ;morse ADD2 | |
print-str | |
JMP2r | |
@emit ( char -- ) #18 DEO JMP2r | |
@cr ( -- ) #0a emit JMP2r | |
@is-newline ( char -- !f ) #0a EQU #00 EQU JMP2r | |
@is-space ( char -- !f ) #20 EQU #00 EQU JMP2r | |
@morse-space ( -- ) #2020 emit emit JMP2r | |
@is-digit ( char -- !f ) | |
DUP #2f GTH SWP #3a LTH AND #00 EQU | |
JMP2r | |
@is-uppercase ( char -- !f ) | |
#40 GTH SWP #5b LTH AND #00 EQU | |
JMP2r | |
@is-lowercase ( char -- !f ) | |
#60 GTH SWP #7b LTH AND #00 EQU | |
JMP2r | |
@is-alpha ( char -- !f ) | |
DUPk DUP is-uppercase | |
ROT ROT is-lowercase DUP ,&lowercase? STR | |
ORA #00 EQU | |
JMP2r | |
&lowercase? $1 | |
@ascii-str | |
"1337 20 "PRINT -SP "ASCII -SP "to -SP "Morse -SP "code. -CR $1 | |
@morse | |
&0 "----- $1 &1 ".---- $1 &2 "..--- $1 &3 "...-- $1 | |
&4 "....- $1 &5 "..... $1 &6 "-.... $1 &7 "--... $1 | |
&8 "---.. $1 &9 "----. $1 | |
&A ".- $4 &B "-... $2 &C "-.-. $2 &D "-.. $3 | |
&E ". $5 &F "..-. $2 &G "--. $3 &H ".... $2 | |
&I ".. $4 &J ".--- $2 &K "-.- $3 &L ".-.. $2 | |
&M "-- $4 &N "-. $4 &O "--- $3 &P ".--. $2 | |
&Q "--.- $2 &R ".-. $3 &S "... $3 &T "- $5 | |
&U "..- $3 &V "...- $2 &W ".-- $3 &X "-..- $2 | |
&Y "-.-- $2 &Z "--.. $2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment