mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 11:16:42 +01:00
add graphicsText mode and finish font_palette example
This commit is contained in:
@@ -5,24 +5,38 @@ import "env.printString" fn printString(i32);
|
|||||||
import "env.printChar" fn printChar(i32);
|
import "env.printChar" fn printChar(i32);
|
||||||
import "env.setCursorPosition" fn setCursor(i32, i32);
|
import "env.setCursorPosition" fn setCursor(i32, i32);
|
||||||
import "env.setTextColor" fn setTextColor(i32);
|
import "env.setTextColor" fn setTextColor(i32);
|
||||||
|
import "env.line" fn line(f32, f32, f32, f32, i32);
|
||||||
|
import "env.isButtonTriggered" fn triggered(i32) -> i32;
|
||||||
|
|
||||||
|
global mut mode: i32 = 0;
|
||||||
|
|
||||||
export fn upd() {
|
export fn upd() {
|
||||||
cls(0);
|
cls(0);
|
||||||
|
|
||||||
printString(0);
|
if triggered(4) {
|
||||||
|
mode = !mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTextColor(15);
|
||||||
|
printString(mode * 0x20000);
|
||||||
|
|
||||||
let y: i32;
|
let y: i32;
|
||||||
loop y {
|
loop y {
|
||||||
setCursor(y + 2, 3);
|
line(0 as f32, (y * 9 + 39) as f32, (14+16*9) as f32, (y * 9 + 39) as f32, 1);
|
||||||
|
line((y * 9 + 15) as f32, 24 as f32, (y * 9 + 15) as f32, (38+16*9) as f32, 1);
|
||||||
|
setTextColor(15);
|
||||||
|
setCursor(y * 9 + 16, 24);
|
||||||
let lazy hexChar = select(y < 10, y + 48, y + 87);
|
let lazy hexChar = select(y < 10, y + 48, y + 87);
|
||||||
printChar(hexChar);
|
printChar(hexChar);
|
||||||
setCursor(0, y + 5);
|
setCursor(0, y * 9 + 24+16);
|
||||||
printChar(hexChar);
|
printChar(hexChar);
|
||||||
printChar(32);
|
|
||||||
let x = 0;
|
let x = 0;
|
||||||
loop x {
|
loop x {
|
||||||
// setTextColor(x + y * 16);
|
setCursor(x * 9 + 16, y * 9 + 24+16);
|
||||||
printChar(x + y * 16);
|
setTextColor(select(mode, x + y * 16, -9));
|
||||||
|
if y >= 2 | mode {
|
||||||
|
printChar(select(mode, 0xa4, x + y * 16));
|
||||||
|
}
|
||||||
branch_if (x := x + 1) < 16: x;
|
branch_if (x := x + 1) < 16: x;
|
||||||
}
|
}
|
||||||
branch_if (y := y + 1) < 16: y;
|
branch_if (y := y + 1) < 16: y;
|
||||||
@@ -30,5 +44,9 @@ export fn upd() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data 0 {
|
data 0 {
|
||||||
"Default font:" i8(0)
|
"Default font: (press " i8(0xcc) " for palette)" i8(5, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
data 0x20000 {
|
||||||
|
"Default palette: (press " i8(0xcc) " for font)" i8(5, 0)
|
||||||
}
|
}
|
||||||
Binary file not shown.
@@ -59,6 +59,7 @@ export fn cls(col: i32) {
|
|||||||
let i: i32;
|
let i: i32;
|
||||||
textCursorX = 0;
|
textCursorX = 0;
|
||||||
textCursorY = 0;
|
textCursorY = 0;
|
||||||
|
graphicsText = 0;
|
||||||
col = (col & 255) * 0x1010101;
|
col = (col & 255) * 0x1010101;
|
||||||
loop pixels {
|
loop pixels {
|
||||||
i!120 = col;
|
i!120 = col;
|
||||||
@@ -226,9 +227,15 @@ global mut textCursorX = 0;
|
|||||||
global mut textCursorY = 0;
|
global mut textCursorY = 0;
|
||||||
global mut textColor = 15;
|
global mut textColor = 15;
|
||||||
global mut bgColor = 0;
|
global mut bgColor = 0;
|
||||||
|
global mut graphicsText = 0;
|
||||||
|
|
||||||
export fn printChar(char: i32) {
|
export fn printChar(char: i32) {
|
||||||
if char == 10 | textCursorX >= 320 {
|
if char == 4 | char == 5 {
|
||||||
|
graphicsText = char == 5;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if char == 10 | (!graphicsText & textCursorX >= 320) {
|
||||||
textCursorX = 0;
|
textCursorX = 0;
|
||||||
textCursorY = textCursorY + 8;
|
textCursorY = textCursorY + 8;
|
||||||
return;
|
return;
|
||||||
@@ -238,9 +245,18 @@ export fn printChar(char: i32) {
|
|||||||
loop rows {
|
loop rows {
|
||||||
let bits = (char * 8 + y)?0x13400;
|
let bits = (char * 8 + y)?0x13400;
|
||||||
let x = 0;
|
let x = 0;
|
||||||
loop pixels {
|
if graphicsText {
|
||||||
setPixel(textCursorX + x, textCursorY + y, select((bits := bits << 1) & 256, textColor, bgColor));
|
loop pixels {
|
||||||
branch_if (x := x + 1) < 8: pixels;
|
if (bits := bits << 1) & 256 {
|
||||||
|
setPixel(textCursorX + x, textCursorY + y, textColor);
|
||||||
|
}
|
||||||
|
branch_if (x := x + 1) < 8: pixels;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
loop pixels {
|
||||||
|
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;
|
branch_if (y := y + 1) < 8: rows;
|
||||||
}
|
}
|
||||||
@@ -281,8 +297,9 @@ export fn setBackgroundColor(col: i32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export fn setCursorPosition(x: i32, y: i32) {
|
export fn setCursorPosition(x: i32, y: i32) {
|
||||||
textCursorX = x * 8;
|
let lazy scale = select(graphicsText, 1, 8);
|
||||||
textCursorY = y * 8;
|
textCursorX = x * scale;
|
||||||
|
textCursorY = y * scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////
|
///////////
|
||||||
|
|||||||
Reference in New Issue
Block a user