#include "f256.h" 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 }; static byte _MAX_COL = 80; static byte _MAX_ROW = 60; static byte _row = 0; static byte _col = 0; // Clear screen, do not change text attributes. void cls(void) { int i; char *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. for (i = 0; i < _MAX_COL*_MAX_ROW; i++) *vram++ = 32; POKE(MMU_IO_CTRL, mmu); // Restore MMU state. gotoxy(0, 0); } // Move cursor. void gotoxy(byte x, byte y) { byte mmu; mmu = PEEK(MMU_IO_CTRL); // Get current MMU state. POKE(MMU_IO_CTRL, 2); // Swap I/O page 2 into bank 6. _col = x; POKE(CURSOR_X_LOW, _col); // Set cursor X position. POKE(CURSOR_X_HIGH, 0); _row = y; POKE(CURSOR_Y_LOW, _row); // Set cursor Y position. POKE(CURSOR_Y_HIGH, 0); POKE(MMU_IO_CTRL, mmu); // Restore MMU state. } // Print a string to the screen. void print(char *message) { int x = 0; int i = 0; char *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. while (message[x] != 0) { switch (message[x]) { default: vram[_col] = message[x]; _col++; if (_col != _MAX_COL) break; // Fall through. case 10: case 13: _col = 0; _row++; 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]; // Clear bottom line. vram += i; for (i = 0; i < _MAX_COL; i++) *vram++ = 32; // Set up on bottom line. _row--; vram = (byte *)TEXT_MATRIX + _MAX_COL * (_MAX_ROW - 2) + 1; break; } vram += _MAX_COL; break; } x++; } POKE(MMU_IO_CTRL, mmu); // Restore MMU state. POKE(CURSOR_X_LOW, _col); POKE(CURSOR_Y_LOW, _row); } // Reset display to text, "standard" colors. void reset(void) { byte mmu; mmu = PEEK(MMU_IO_CTRL); // Get current MMU state. POKE(MMU_IO_CTRL, 2); // Swap I/O page 2 into bank 6. _MAX_COL = 80; _MAX_ROW = 60; POKE(CURSOR_SETTINGS, 9); // Disable cursor flash. POKE(CURSOR_CHARACTER, '_'); // Set cursor shape. POKE(MMU_IO_CTRL, mmu); // Restore MMU state. cls(); }