diff --git a/examples/pgztest/build.sh b/examples/pgztest/build.sh index d4a79bc..ace5133 100755 --- a/examples/pgztest/build.sh +++ b/examples/pgztest/build.sh @@ -9,6 +9,7 @@ START=0x2000 echo "__f256_start = ${START};" > ${SETTINGS} mos-f256k-clang \ + -fno-builtin-memset \ -I${F256}/include \ -I${F256}/f256lib \ -o pgztest \ @@ -24,5 +25,5 @@ ${F256}/header/header \ pgztest.bin ${START} #llvm-nm pgztest.elf -llvm-objdump -d --print-imm-hex pgztest.elf -hexdump -C pgztest.pgz +#llvm-objdump -d --print-imm-hex pgztest.elf +#hexdump -C pgztest.pgz diff --git a/examples/pgztest/pgztest.c b/examples/pgztest/pgztest.c index e240c27..43684dd 100644 --- a/examples/pgztest/pgztest.c +++ b/examples/pgztest/pgztest.c @@ -3,6 +3,8 @@ int main(void) { reset(); - print("F256 LIVES!"); + print("F256 LIVES!\n"); + setTextColor(LIGHT_GREEN, BLACK); + print("Green!"); return 0; } diff --git a/f256lib/f256.c b/f256lib/f256.c index a86988e..7bc24d9 100644 --- a/f256lib/f256.c +++ b/f256lib/f256.c @@ -3,23 +3,23 @@ char error; -uint32_t textColors[16] = { - 0xff000000, // 0 Black - 0xffdd0033, // 1 Deep Red - 0xff000099, // 2 Dark Blue - 0xffdd22dd, // 3 Purple - 0xff007722, // 4 Dark Green - 0xff555555, // 5 Dark Gray - 0xff2222ff, // 6 Medium Blue - 0xff66aaff, // 7 Light Blue - 0xff885500, // 8 Brown - 0xffff6600, // 9 Orange - 0xffaaaaaa, // A Light Gray - 0xffff9988, // B Pink - 0xff00dd00, // C Light Green - 0xffffff00, // D Yellow - 0xff55ff99, // E Aquamarine - 0xffffffff // F White +colorT textColors[16] = { + { 0x00, 0x00, 0x00 }, // 0 Black + { 0xdd, 0x00, 0x33 }, // 1 Deep Red + { 0x00, 0x00, 0x99 }, // 2 Dark Blue + { 0xdd, 0x22, 0xdd }, // 3 Purple + { 0x00, 0x77, 0x22 }, // 4 Dark Green + { 0x55, 0x55, 0x55 }, // 5 Dark Gray + { 0x22, 0x22, 0xff }, // 6 Medium Blue + { 0x66, 0xaa, 0xff }, // 7 Light Blue + { 0x88, 0x55, 0x00 }, // 8 Brown + { 0xff, 0x66, 0x00 }, // 9 Orange + { 0xaa, 0xaa, 0xaa }, // A Light Gray + { 0xff, 0x99, 0x88 }, // B Pink + { 0x00, 0xdd, 0x00 }, // C Light Green + { 0xff, 0xff, 0x00 }, // D Yellow + { 0x55, 0xff, 0x99 }, // E Aquamarine + { 0xff, 0xff, 0xff } // F White }; @@ -27,39 +27,68 @@ static byte _MAX_COL = 80; static byte _MAX_ROW = 60; static byte _row = 0; static byte _col = 0; +static byte _fcolor = 15; +static byte _bcolor = 0; +static byte _ccolor = 240; -// Clear screen, does not change text attributes. +// Clear screen to current text attributes. void cls(void) { int i; byte *vram = (byte *)TEXT_MATRIX; - byte mmu; - - mmu = PEEK(MMU_IO_CTRL); // Get current MMU state. - POKE(MMU_IO_CTRL, 2); // Swap I/O page 2 into bank 6. + byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state. + POKE(MMU_IO_CTRL, MMU_IO_TEXT); // Swap I/O page 2 into bank 6. for (i = 0; i < _MAX_COL * _MAX_ROW; i++) *vram++ = 32; + POKE(MMU_IO_CTRL, MMU_IO_COLOR); // Swap I/O page 3 into bank 6. + vram = (byte *)TEXT_MATRIX; + for (i = 0; i < _MAX_COL * _MAX_ROW; i++) *vram++ = _ccolor; + POKE(MMU_IO_CTRL, mmu); // Restore MMU state. gotoxy(0, 0); } +// Define text color. +void defineTextColor(byte slot, byte fr, byte fg, byte fb, byte br, byte bg, byte bb) { + byte mmu; + byte *write; + + mmu = PEEK(MMU_IO_CTRL); // Get current MMU state. + POKE(MMU_IO_CTRL, MMU_IO_PAGE_0); // Swap I/O page 0 into bank 6. + + write = (byte *)VKY_TXT_FGLUT + slot * 4; + *write++ = fb; + *write++ = fg; + *write++ = fr; + *write++ = 0xff; + + write = (byte *)VKY_TXT_BGLUT + slot * 4; + *write++ = bb; + *write++ = bg; + *write++ = br; + *write++ = 0xff; + + POKE(MMU_IO_CTRL, mmu); // Restore MMU state. +} + + // Move cursor. void gotoxy(byte x, byte y) { byte mmu; mmu = PEEK(MMU_IO_CTRL); // Get current MMU state. - POKE(MMU_IO_CTRL, 0); // Swap I/O page 0 into bank 6. + POKE(MMU_IO_CTRL, MMU_IO_PAGE_0); // Swap I/O page 0 into bank 6. _col = x; - POKE(CURSOR_X_LOW, _col); // Set cursor X position. - POKE(CURSOR_X_HIGH, 0); + POKE(VKY_CRSR_X_L, _col); // Set cursor X position. + POKE(VKY_CRSR_X_H, 0); _row = y; - POKE(CURSOR_Y_LOW, _row); // Set cursor Y position. - POKE(CURSOR_Y_HIGH, 0); + POKE(VKY_CRSR_Y_L, _row); // Set cursor Y position. + POKE(VKY_CRSR_Y_H, 0); POKE(MMU_IO_CTRL, mmu); // Restore MMU state. } @@ -69,15 +98,17 @@ void gotoxy(byte x, byte y) { void print(char *message) { int x = 0; int i = 0; - byte *vram = (byte *)TEXT_MATRIX + _col * _row; - byte mmu; - - mmu = PEEK(MMU_IO_CTRL); // Get current MMU state. - POKE(MMU_IO_CTRL, 2); // Swap I/O page 2 into bank 6. + int j = 0; + byte *vram = (byte *)TEXT_MATRIX + _col + (_MAX_COL * _row); + byte *save = 0; + byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state. while (message[x] != 0) { switch (message[x]) { default: + POKE(MMU_IO_CTRL, MMU_IO_COLOR); // Swap I/O page 3 into bank 6. + vram[_col] = _ccolor; + POKE(MMU_IO_CTRL, MMU_IO_TEXT); // Swap I/O page 2 into bank 6. vram[_col] = message[x]; _col++; if (_col != _MAX_COL) break; @@ -89,9 +120,18 @@ void print(char *message) { if (_row == _MAX_ROW) { // Scroll contents up one line. vram = (byte *)TEXT_MATRIX; - for (i = 0; i < _MAX_COL * (_MAX_ROW - 1); i++) vram[i] = vram[i+_MAX_COL]; + POKE(MMU_IO_CTRL, MMU_IO_COLOR); // Swap I/O page 3 into bank 6. + for (j=0; j<2; j++) { + for (i = 0; i < _MAX_COL * (_MAX_ROW - 1); i++) vram[i] = vram[i+_MAX_COL]; + POKE(MMU_IO_CTRL, MMU_IO_TEXT); // Swap I/O page 2 into bank 6. + } // Clear bottom line. vram += i; + save = vram; + POKE(MMU_IO_CTRL, MMU_IO_COLOR); // Swap I/O page 3 into bank 6. + for (i = 0; i < _MAX_COL; i++) *vram++ = _ccolor; + POKE(MMU_IO_CTRL, MMU_IO_TEXT); // Swap I/O page 2 into bank 6. + vram = save; for (i = 0; i < _MAX_COL; i++) *vram++ = 32; // Set up on bottom line. _row--; @@ -112,10 +152,12 @@ void print(char *message) { // Reset display to text, "standard" colors. void reset(void) { - byte mmu; + byte mmu; + byte x; + byte y; mmu = PEEK(MMU_IO_CTRL); // Get current MMU state. - POKE(MMU_IO_CTRL, 2); // Swap I/O page 2 into bank 6. + POKE(MMU_IO_CTRL, MMU_IO_TEXT); // Swap I/O page 2 into bank 6. // If we set 0xD000 to 0x01 and 0xD001 to 0x00, that will put us into text mode at 80 × 60. POKE(VKY_MSTR_CTRL_0, 1); @@ -124,11 +166,33 @@ void reset(void) { _MAX_COL = 80; _MAX_ROW = 60; - POKE(MMU_IO_CTRL, 0); // Swap I/O page 0 into bank 6. - POKE(CURSOR_SETTINGS, 9); // Disable cursor flash. - POKE(CURSOR_CHARACTER, '_'); // Set cursor shape. (199 = Checkerboard) + _fcolor = 15; + _bcolor = 0; + _ccolor = 240; + + POKE(MMU_IO_CTRL, MMU_IO_PAGE_0); // Swap I/O page 0 into bank 6. + + POKE(VKY_CRSR_CTRL, 3); // Enable cursor, 1/2s flash. + POKE(VKY_CRSR_CHAR, '_'); // Set cursor shape. (199 = Checkerboard) + + // Set up default text colors. + for (x=0; x