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
|
|
|
|
2022-04-23 00:15:51 +00:00
|
|
|
%import conv
|
2023-12-26 22:37:59 +00:00
|
|
|
%option ignore_unused
|
2022-03-18 23:57:35 +00:00
|
|
|
|
|
|
|
txt {
|
|
|
|
|
2023-03-11 15:05:45 +00:00
|
|
|
sub width() -> ubyte {
|
|
|
|
return 80 ; just some chosen value for the 'width' of the console
|
|
|
|
}
|
|
|
|
|
|
|
|
sub height() -> ubyte {
|
|
|
|
return 30 ; just some chosen value for the 'height' of the console
|
|
|
|
}
|
|
|
|
|
2022-03-18 23:57:35 +00:00
|
|
|
sub clear_screen() {
|
2022-04-30 22:09:03 +00:00
|
|
|
str @shared sequence = "\x1b[2J\x1B[H"
|
2022-09-30 12:05:11 +00:00
|
|
|
%ir {{
|
2023-04-10 14:59:08 +00:00
|
|
|
load.w r65535,txt.clear_screen.sequence
|
2023-05-12 21:26:36 +00:00
|
|
|
syscall 3 (r65535.w)
|
2022-04-30 22:09:03 +00:00
|
|
|
}}
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub nl() {
|
2024-02-21 16:35:37 +00:00
|
|
|
chrout('\n')
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub spc() {
|
2024-02-21 16:35:37 +00:00
|
|
|
chrout(' ')
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
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-09-30 12:05:11 +00:00
|
|
|
%ir {{
|
2023-04-10 14:59:08 +00:00
|
|
|
loadm.b r65535,txt.chrout.char
|
2023-05-12 21:26:36 +00:00
|
|
|
syscall 2 (r65535.b)
|
2022-04-30 22:09:03 +00:00
|
|
|
}}
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
2024-02-21 16:35:37 +00:00
|
|
|
sub bell() {
|
|
|
|
chrout(7)
|
|
|
|
}
|
|
|
|
|
2022-03-18 23:57:35 +00:00
|
|
|
sub print (str text) {
|
2022-09-30 12:05:11 +00:00
|
|
|
%ir {{
|
2023-04-10 14:59:08 +00:00
|
|
|
loadm.w r65535,txt.print.text
|
2023-05-12 21:26:36 +00:00
|
|
|
syscall 3 (r65535.w)
|
2022-04-30 22:09:03 +00:00
|
|
|
}}
|
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)
|
2022-04-23 00:15:51 +00:00
|
|
|
conv.str_ub0(value)
|
|
|
|
print(conv.string_out)
|
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
|
2022-04-23 00:15:51 +00:00
|
|
|
conv.str_ub(value)
|
|
|
|
print(conv.string_out)
|
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-04-23 00:15:51 +00:00
|
|
|
conv.str_b(value)
|
|
|
|
print(conv.string_out)
|
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('$')
|
2022-04-23 00:15:51 +00:00
|
|
|
conv.str_ubhex(value)
|
|
|
|
print(conv.string_out)
|
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
|
2022-04-08 22:49:23 +00:00
|
|
|
if prefix
|
|
|
|
chrout('%')
|
2022-04-23 00:15:51 +00:00
|
|
|
conv.str_ubbin(value)
|
|
|
|
print(conv.string_out)
|
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
|
2022-04-08 22:49:23 +00:00
|
|
|
if prefix
|
|
|
|
chrout('%')
|
2022-04-23 00:15:51 +00:00
|
|
|
conv.str_uwbin(value)
|
|
|
|
print(conv.string_out)
|
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-04-23 00:15:51 +00:00
|
|
|
if prefix
|
|
|
|
chrout('$')
|
|
|
|
conv.str_uwhex(value)
|
|
|
|
print(conv.string_out)
|
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)
|
2022-04-23 00:15:51 +00:00
|
|
|
conv.str_uw0(value)
|
|
|
|
print(conv.string_out)
|
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-04-23 00:15:51 +00:00
|
|
|
conv.str_uw(value)
|
|
|
|
print(conv.string_out)
|
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-04-23 00:15:51 +00:00
|
|
|
conv.str_w(value)
|
|
|
|
print(conv.string_out)
|
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!
|
2022-09-30 12:05:11 +00:00
|
|
|
%ir {{
|
2023-05-12 21:26:36 +00:00
|
|
|
loadm.w r65534,txt.input_chars.buffer
|
2023-04-10 16:43:51 +00:00
|
|
|
load.b r65535,80
|
2023-05-12 21:26:36 +00:00
|
|
|
syscall 6 (r65534.w, r65535.b): r0.b
|
2023-04-11 20:28:19 +00:00
|
|
|
returnr.b r0
|
2022-04-30 22:09:03 +00:00
|
|
|
}}
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|
|
|
|
|
2022-09-25 18:21:35 +00:00
|
|
|
sub plot (ubyte col, ubyte row) {
|
|
|
|
; use ANSI escape sequence to position the cursor
|
|
|
|
txt.chrout(27)
|
|
|
|
txt.chrout('[')
|
|
|
|
txt.print_ub(row)
|
|
|
|
txt.chrout(';')
|
|
|
|
txt.print_ub(col)
|
|
|
|
txt.chrout('H')
|
|
|
|
}
|
|
|
|
|
|
|
|
sub setchr (ubyte col, ubyte row, ubyte char) {
|
|
|
|
plot(col, row)
|
|
|
|
txt.chrout(char)
|
|
|
|
}
|
|
|
|
|
2024-02-07 21:36:43 +00:00
|
|
|
sub petscii2scr(ubyte petscii_char) -> ubyte {
|
|
|
|
; -- convert petscii character to screencode
|
|
|
|
byte[8] offsets = [128, 0, 64, 32, 64, 192, 128, 128]
|
|
|
|
return petscii_char ^ offsets[petscii_char>>5]
|
|
|
|
}
|
|
|
|
|
|
|
|
sub petscii2scr_str(str petscii_string) {
|
|
|
|
; -- convert petscii string to screencodes string
|
|
|
|
cx16.r0 = petscii_string
|
|
|
|
while @(cx16.r0)!=0 {
|
|
|
|
@(cx16.r0) = petscii2scr(@(cx16.r0))
|
|
|
|
cx16.r0++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-18 23:57:35 +00:00
|
|
|
}
|