prog8/compiler/res/prog8lib/virtual/textio.p8

112 lines
2.4 KiB
Plaintext
Raw Normal View History

2022-03-23 00:52:01 +00:00
; Prog8 definitions for the Text I/O console routines for the Virtual Machine
;
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
%import conv
txt {
sub clear_screen() {
2022-04-05 18:46:34 +00:00
void syscall1(3, "\x1b[2J\x1B[H")
}
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
}
sub chrout(ubyte char) {
2022-04-05 18:46:34 +00:00
void syscall1(2, char)
}
sub print (str text) {
2022-04-05 18:46:34 +00:00
void syscall1(3, text)
}
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)
conv.str_ub0(value)
print(conv.string_out)
}
sub print_ub (ubyte value) {
2022-03-23 00:52:01 +00:00
; ---- print the ubyte in decimal form, without left padding 0s
conv.str_ub(value)
print(conv.string_out)
}
sub print_b (byte value) {
2022-03-23 00:52:01 +00:00
; ---- print the byte in decimal form, without left padding 0s
conv.str_b(value)
print(conv.string_out)
}
sub print_ubhex (ubyte value, ubyte prefix) {
2022-03-23 00:52:01 +00:00
; ---- print the ubyte in hex form
if prefix
chrout('$')
conv.str_ubhex(value)
print(conv.string_out)
}
sub print_ubbin (ubyte value, ubyte prefix) {
2022-03-23 00:52:01 +00:00
; ---- print the ubyte in binary form
2022-04-08 22:49:23 +00:00
if prefix
chrout('%')
conv.str_ubbin(value)
print(conv.string_out)
}
sub print_uwbin (uword value, ubyte prefix) {
2022-03-23 00:52:01 +00:00
; ---- print the uword in binary form
2022-04-08 22:49:23 +00:00
if prefix
chrout('%')
conv.str_uwbin(value)
print(conv.string_out)
}
sub print_uwhex (uword value, ubyte prefix) {
2022-03-23 00:52:01 +00:00
; ---- print the uword in hexadecimal form (4 digits)
if prefix
chrout('$')
conv.str_uwhex(value)
print(conv.string_out)
}
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)
conv.str_uw0(value)
print(conv.string_out)
}
sub print_uw (uword value) {
2022-03-23 00:52:01 +00:00
; ---- print the uword in decimal form, without left padding 0s
conv.str_uw(value)
print(conv.string_out)
}
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
conv.str_w(value)
print(conv.string_out)
}
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!
2022-04-05 18:46:34 +00:00
return syscall1(6, buffer)
}
}