2022-03-23 00:52:01 +00:00
|
|
|
; Prog8 definitions for the Text I/O console routines for the Virtual Machine
|
2022-03-18 23:57:35 +00:00
|
|
|
;
|
|
|
|
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
|
|
|
|
|
|
|
|
%import syslib
|
|
|
|
|
|
|
|
|
|
|
|
txt {
|
|
|
|
|
|
|
|
sub clear_screen() {
|
2022-03-24 23:17:41 +00:00
|
|
|
syscall1(3, "\x1b[2J\x1B[H")
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub nl() {
|
|
|
|
txt.chrout('\n')
|
|
|
|
}
|
|
|
|
|
|
|
|
sub spc() {
|
|
|
|
txt.chrout(' ')
|
|
|
|
}
|
|
|
|
|
2022-03-27 15:46:15 +00:00
|
|
|
sub lowercase() {
|
|
|
|
; not supported
|
|
|
|
}
|
|
|
|
|
|
|
|
sub uppercase() {
|
|
|
|
; not supported
|
|
|
|
}
|
|
|
|
|
2022-03-18 23:57:35 +00:00
|
|
|
sub chrout(ubyte char) {
|
2022-03-23 00:52:01 +00:00
|
|
|
syscall1(2, char)
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub print (str text) {
|
2022-03-23 00:52:01 +00:00
|
|
|
syscall1(3, text)
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub print_ub0 (ubyte value) {
|
2022-03-23 00:52:01 +00:00
|
|
|
; ---- print the ubyte in A in decimal form, with left padding 0s (3 positions total)
|
|
|
|
; TODO use conv module?
|
|
|
|
ubyte hundreds = value / 100
|
|
|
|
value -= hundreds*100
|
|
|
|
ubyte tens = value / 10
|
|
|
|
value -= tens*10
|
|
|
|
chrout(hundreds+'0')
|
|
|
|
chrout(tens+'0')
|
|
|
|
chrout(value+'0')
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub print_ub (ubyte value) {
|
2022-03-23 00:52:01 +00:00
|
|
|
; ---- print the ubyte in decimal form, without left padding 0s
|
|
|
|
; TODO use conv module?
|
|
|
|
ubyte hundreds = value / 100
|
|
|
|
value -= hundreds*100
|
|
|
|
ubyte tens = value / 10
|
|
|
|
value -= tens*10
|
|
|
|
if hundreds
|
|
|
|
goto print_hundreds
|
|
|
|
if tens
|
|
|
|
goto print_tens
|
|
|
|
goto print_ones
|
|
|
|
print_hundreds:
|
|
|
|
chrout(hundreds+'0')
|
|
|
|
print_tens:
|
|
|
|
chrout(tens+'0')
|
|
|
|
print_ones:
|
|
|
|
chrout(value+'0')
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub print_b (byte value) {
|
2022-03-23 00:52:01 +00:00
|
|
|
; ---- print the byte in decimal form, without left padding 0s
|
2022-03-27 23:49:43 +00:00
|
|
|
if value<0 {
|
|
|
|
chrout('-')
|
|
|
|
value = -value
|
|
|
|
}
|
|
|
|
print_ub(value as ubyte)
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
2022-03-27 13:23:32 +00:00
|
|
|
str hex_digits = "0123456789abcdef"
|
|
|
|
|
2022-03-18 23:57:35 +00:00
|
|
|
sub print_ubhex (ubyte value, ubyte prefix) {
|
2022-03-23 00:52:01 +00:00
|
|
|
; ---- print the ubyte in hex form
|
2022-03-27 13:23:32 +00:00
|
|
|
if prefix
|
|
|
|
chrout('$')
|
|
|
|
|
|
|
|
chrout(hex_digits[value>>4])
|
|
|
|
chrout(hex_digits[value&15])
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub print_ubbin (ubyte value, ubyte prefix) {
|
2022-03-23 00:52:01 +00:00
|
|
|
; ---- print the ubyte in binary form
|
|
|
|
; TODO use conv module?
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub print_uwbin (uword value, ubyte prefix) {
|
2022-03-23 00:52:01 +00:00
|
|
|
; ---- print the uword in binary form
|
|
|
|
; TODO use conv module?
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub print_uwhex (uword value, ubyte prefix) {
|
2022-03-23 00:52:01 +00:00
|
|
|
; ---- print the uword in hexadecimal form (4 digits)
|
2022-03-27 13:23:32 +00:00
|
|
|
print_ubhex(msb(value), true)
|
|
|
|
print_ubhex(lsb(value), false)
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub print_uw0 (uword value) {
|
2022-03-23 00:52:01 +00:00
|
|
|
; ---- print the uword value in decimal form, with left padding 0s (5 positions total)
|
|
|
|
; TODO use conv module?
|
2022-03-27 09:48:44 +00:00
|
|
|
ubyte tenthousands = (value / 10000) as ubyte
|
|
|
|
value -= 10000*tenthousands
|
|
|
|
ubyte thousands = (value / 1000) as ubyte
|
|
|
|
value -= 1000*thousands
|
|
|
|
ubyte hundreds = (value / 100) as ubyte
|
|
|
|
value -= 100 as uword * hundreds
|
|
|
|
ubyte tens = (value / 10) as ubyte
|
|
|
|
value -= 10*tens
|
2022-03-23 00:52:01 +00:00
|
|
|
chrout(tenthousands+'0')
|
|
|
|
chrout(thousands+'0')
|
|
|
|
chrout(hundreds+'0')
|
|
|
|
chrout(tens+'0')
|
|
|
|
chrout(value as ubyte + '0')
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub print_uw (uword value) {
|
2022-03-23 00:52:01 +00:00
|
|
|
; ---- print the uword in decimal form, without left padding 0s
|
2022-03-27 09:48:44 +00:00
|
|
|
ubyte tenthousands = (value / 10000) as ubyte
|
|
|
|
value -= 10000*tenthousands
|
|
|
|
ubyte thousands = (value / 1000) as ubyte
|
|
|
|
value -= 1000*thousands
|
|
|
|
ubyte hundreds = (value / 100) as ubyte
|
|
|
|
value -= 100 as uword * hundreds
|
|
|
|
ubyte tens = (value / 10) as ubyte
|
|
|
|
value -= 10*tens
|
2022-03-23 00:52:01 +00:00
|
|
|
if tenthousands
|
|
|
|
goto print_tenthousands
|
|
|
|
if thousands
|
|
|
|
goto print_thousands
|
|
|
|
if hundreds
|
|
|
|
goto print_hundreds
|
|
|
|
if tens
|
|
|
|
goto print_tens
|
|
|
|
goto print_ones
|
|
|
|
print_tenthousands:
|
|
|
|
chrout(tenthousands+'0')
|
|
|
|
print_thousands:
|
|
|
|
chrout(thousands+'0')
|
|
|
|
print_hundreds:
|
|
|
|
chrout(hundreds+'0')
|
|
|
|
print_tens:
|
|
|
|
chrout(tens+'0')
|
|
|
|
print_ones:
|
|
|
|
chrout(value as ubyte + '0')
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub print_w (word value) {
|
2022-03-23 00:52:01 +00:00
|
|
|
; ---- print the (signed) word in decimal form, without left padding 0's
|
2022-03-27 23:49:43 +00:00
|
|
|
if value<0 {
|
|
|
|
chrout('-')
|
|
|
|
value = -value
|
|
|
|
}
|
|
|
|
print_uw(value as uword)
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub input_chars (uword buffer) -> ubyte {
|
2022-03-23 00:52:01 +00:00
|
|
|
; ---- Input a string (max. 80 chars) from the keyboard. Returns length of input. (string is terminated with a 0 byte as well)
|
|
|
|
; It assumes the keyboard is selected as I/O channel!
|
|
|
|
; TODO
|
|
|
|
return 0
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|