diff --git a/examples/curlywas/font_palette.uw8 b/examples/curlywas/font_palette.uw8 index df3de4c..7cb199a 100644 --- a/examples/curlywas/font_palette.uw8 +++ b/examples/curlywas/font_palette.uw8 @@ -5,24 +5,38 @@ 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); +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() { cls(0); - printString(0); + if triggered(4) { + mode = !mode; + } + + setTextColor(15); + printString(mode * 0x20000); let y: i32; 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); printChar(hexChar); - setCursor(0, y + 5); + setCursor(0, y * 9 + 24+16); printChar(hexChar); - printChar(32); let x = 0; loop x { -// setTextColor(x + y * 16); - printChar(x + y * 16); + setCursor(x * 9 + 16, y * 9 + 24+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 (y := y + 1) < 16: y; @@ -30,5 +44,9 @@ export fn upd() { } 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) } \ No newline at end of file diff --git a/platform/bin/platform.uw8 b/platform/bin/platform.uw8 index 3109472..ae99f36 100644 Binary files a/platform/bin/platform.uw8 and b/platform/bin/platform.uw8 differ diff --git a/platform/src/platform.cwa b/platform/src/platform.cwa index c2ffa81..2b600cf 100644 --- a/platform/src/platform.cwa +++ b/platform/src/platform.cwa @@ -59,6 +59,7 @@ export fn cls(col: i32) { let i: i32; textCursorX = 0; textCursorY = 0; + graphicsText = 0; col = (col & 255) * 0x1010101; loop pixels { i!120 = col; @@ -226,9 +227,15 @@ global mut textCursorX = 0; global mut textCursorY = 0; global mut textColor = 15; global mut bgColor = 0; +global mut graphicsText = 0; 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; textCursorY = textCursorY + 8; return; @@ -238,9 +245,18 @@ export fn printChar(char: i32) { loop rows { let bits = (char * 8 + y)?0x13400; let x = 0; - loop pixels { - setPixel(textCursorX + x, textCursorY + y, select((bits := bits << 1) & 256, textColor, bgColor)); - branch_if (x := x + 1) < 8: pixels; + if graphicsText { + loop 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; } @@ -281,8 +297,9 @@ export fn setBackgroundColor(col: i32) { } export fn setCursorPosition(x: i32, y: i32) { - textCursorX = x * 8; - textCursorY = y * 8; + let lazy scale = select(graphicsText, 1, 8); + textCursorX = x * scale; + textCursorY = y * scale; } ///////////