07-08-2023, 08:52 AM
A simple ASCII Table.
ESC - End Program
Arrow keys to select the character
ESC - End Program
Arrow keys to select the character
Code: (Select All)
' instructs the compiler to require variable declaration
OPTION _EXPLICIT
' Control function off to set all characters
_CONTROLCHR OFF
' dimension variables
DIM winX AS _UNSIGNED INTEGER
DIM winY AS _UNSIGNED INTEGER
DIM i AS _UNSIGNED _BYTE
DIM x AS _UNSIGNED _BYTE
DIM y AS _UNSIGNED _BYTE
DIM selx AS _UNSIGNED _BYTE
DIM sely AS _UNSIGNED _BYTE
DIM keyin AS STRING
' Create window area with colors
COLOR 4, 7
winX = 14
winY = 4
FOR y = winY + 0 TO winY + 16
FOR x = winX + 0 TO winX + 16 * 3
LOCATE y, x: PRINT SPACE$(2);
NEXT x
NEXT y
' Create table info
FOR i = 0 TO 15
LOCATE winY, winX + (i * 3) + 3: PRINT "0" + HEX$(i);
LOCATE winY + i + 1, winX: PRINT HEX$(i) + "0";
NEXT i
' Create ASCII characters
' Init values for the table of ASCII chars
COLOR 0, 7
winX = winX + 1
winY = winY + 1
DO
' Output of all ASCII characters in the table
x = 0
y = winY
FOR i = 0 TO 255
IF selx = x AND sely = y - winY THEN COLOR 7, 2 ELSE COLOR 0, 7
LOCATE y, winX + (x * 3) + 3: PRINT CHR$(i);
x = x + 1
IF x = 16 THEN
x = 0
y = y + 1
END IF
NEXT i
' Output of decimal and hex value of current char
COLOR 0, 7
LOCATE winY + 16, winX - 1: PRINT SPACE$(25);
LOCATE winY + 16, winX - 1: PRINT "ASCII: DEC(" + LTRIM$(STR$(sely * 16 + selx)) + ") HEX(" + HEX$(sely * 16 + selx) + ")";
' Key Input
DO
keyin = INKEY$
LOOP WHILE keyin = ""
' Arrow keys to select the current char
IF keyin = CHR$(0) + CHR$(77) THEN IF selx >= 15 THEN selx = 0 ELSE selx = selx + 1
IF keyin = CHR$(0) + CHR$(75) THEN IF selx <= 0 THEN selx = 15 ELSE selx = selx - 1
IF keyin = CHR$(0) + CHR$(80) THEN IF sely >= 15 THEN sely = 0 ELSE sely = sely + 1
IF keyin = CHR$(0) + CHR$(72) THEN IF sely <= 0 THEN sely = 15 ELSE sely = sely - 1
' ESC to end the program
LOOP WHILE keyin <> CHR$(27)