sample-code/ascii: Use as casting to print the entire printable ASCII range

This commit is contained in:
John 2024-07-26 06:10:59 -05:00
parent 38a5d31b08
commit 3aef055739

28
sample-code/ascii.cl Normal file
View File

@ -0,0 +1,28 @@
//! Prints out the characters in the ASCII printable range
//! in the format of a hex-dump
// TODO: Convenient stuff like this in the stdlib
const HEX_LUT: [char; 16] = [
'0', '1', '2', '3', //
'4', '5', '6', '7', //
'8', '9', 'a', 'b', //
'c', 'd', 'e', 'f', //
];
fn ascii() {
for row in 0..6 {
for col in 0..16 {
if col == 8 {
print(' ')
}
let i = 0x20 + row * 16 + col
print(HEX_LUT[(i >> 4) & 0xf], HEX_LUT[i & 0xf], ' ')
}
print(" |")
for col in 0..16 {
let i = 0x20 + row * 16 + col
print(i as char)
}
println("|")
}
}