more font and text functions

This commit is contained in:
2021-12-08 23:59:58 +01:00
parent 1e9910a983
commit ed24904d60
7 changed files with 54 additions and 6 deletions

View File

@@ -0,0 +1,34 @@
import "env.memory" memory(4);
import "env.cls" fn cls(i32);
import "env.printString" fn printString(i32);
import "env.printChar" fn printChar(i32);
import "env.setCursorPosition" fn setCursor(i32, i32);
import "env.setTextColor" fn setTextColor(i32);
export fn upd() {
cls(0);
printString(0);
let y: i32;
loop y {
setCursor(y + 2, 3);
let lazy hexChar = select(y < 10, y + 48, y + 87);
printChar(hexChar);
setCursor(0, y + 5);
printChar(hexChar);
printChar(32);
let x = 0;
loop x {
// setTextColor(x + y * 16);
printChar(x + y * 16);
branch_if (x := x + 1) < 16: x;
}
branch_if (y := y + 1) < 16: y;
}
}
data 0 {
"Default font:" i8(0)
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

View File

@@ -55,9 +55,6 @@ export fn fmod(a: f32, b: f32) -> f32 {
// DRAWING //
/////////////
global mut textCursorX = 0;
global mut textCursorY = 0;
export fn cls(col: i32) {
let i: i32;
textCursorX = 0;
@@ -142,7 +139,10 @@ export fn circle(cx: f32, cy: f32, radius: f32, col: i32) {
// TEXT //
//////////
global mut textCursorX = 0;
global mut textCursorY = 0;
global mut textColor = 15;
global mut bgColor = 0;
export fn printChar(char: i32) {
if char == 10 | textCursorX >= 320 {
@@ -156,9 +156,7 @@ export fn printChar(char: i32) {
let bits = (char * 8 + y)?0x13400;
let x = 0;
loop pixels {
if (bits := bits << 1) & 256 {
setPixel(textCursorX + x, textCursorY + y, textColor);
}
setPixel(textCursorX + x, textCursorY + y, select((bits := bits << 1) & 256, textColor, bgColor));
branch_if (x := x + 1) < 8: pixels;
}
branch_if (y := y + 1) < 8: rows;
@@ -191,6 +189,19 @@ export fn printInt(num: i32) {
printString(p);
}
export fn setTextColor(col: i32) {
textColor = col;
}
export fn setBackgroundColor(col: i32) {
bgColor = col;
}
export fn setCursorPosition(x: i32, y: i32) {
textCursorX = x * 8;
textCursorY = y * 8;
}
///////////
// SETUP //
///////////

View File

@@ -84,6 +84,9 @@ impl BaseModule {
add_function(&mut functions, &type_map, "printChar", &[I32], None);
add_function(&mut functions, &type_map, "printString", &[I32], None);
add_function(&mut functions, &type_map, "printInt", &[I32], None);
add_function(&mut functions, &type_map, "setTextColor", &[I32], None);
add_function(&mut functions, &type_map, "setBackgroundColor", &[I32], None);
add_function(&mut functions, &type_map, "setCursorPosition", &[I32, I32], None);
for i in functions.len()..64 {
add_function(