diff --git a/examples/pgztest/foenixmgr.ini b/examples/pgztest/foenixmgr.ini new file mode 100644 index 0000000..c4e107a --- /dev/null +++ b/examples/pgztest/foenixmgr.ini @@ -0,0 +1,6 @@ +[DEFAULT] +port=COM3 +labels=sample.lbl +flash_address=380000 +chunk_size=1024 +cpu=65816 diff --git a/examples/pgztest/pgztest.c b/examples/pgztest/pgztest.c index b99ecfc..ef08bf1 100644 --- a/examples/pgztest/pgztest.c +++ b/examples/pgztest/pgztest.c @@ -2,7 +2,7 @@ int main(void) { - cls(); - print("F256 LIVES!"); + reset(); + //print("F256 LIVES!"); return 0; } diff --git a/examples/pgztest/run.sh b/examples/pgztest/run.sh new file mode 100755 index 0000000..d89e9ed --- /dev/null +++ b/examples/pgztest/run.sh @@ -0,0 +1,2 @@ +#!/bin/bash +python ../../FoenixMgr/FoenixMgr/fnxmgr.py --port /dev/ttyUSB1 --run-pgz pgztest.pgz diff --git a/f256lib/f256.c b/f256lib/f256.c index 2ab3758..05bf9fc 100644 --- a/f256lib/f256.c +++ b/f256lib/f256.c @@ -3,63 +3,74 @@ char error; - -#define MAX_COL 80 -#define MAX_ROW 60 +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 char row = 0; -static char col = 0; -static char *line = (char *)TEXT_MATRIX; +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 = (char *)TEXT_MATRIX; - unsigned char mmu; + 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 < 80*60; i++) { - *vram++ = 32; - } - - row = col = 0; - line = (char *)TEXT_MATRIX; + for (i = 0; i < _MAX_COL*_MAX_ROW; i++) *vram++ = 32; POKE(MMU_IO_CTRL, mmu); // Restore MMU state. - POKE(CURSOR_SETTINGS, 9); // Disable cursor flash. - POKE(CURSOR_CHARACTER, '_'); // Set cursor shape. + gotoxy(0, 0); +} - POKE(CURSOR_X_LOW, col); // Set cursor X position. + +// 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); - POKE(CURSOR_Y_LOW, row); // Set cursor Y position. + _row = y; + POKE(CURSOR_Y_LOW, _row); // Set cursor Y position. POKE(CURSOR_Y_HIGH, 0); - POKE(0xd011, 0); -} - - -static void scroll() { - int i; - char *vram = (char *)TEXT_MATRIX; - - for (i = 0; i < 80*59; i++) { - vram[i] = vram[i+80]; - } - vram += i; - for (i = 0; i < 80; i++) { - *vram++ = 32; - } + POKE(MMU_IO_CTRL, mmu); // Restore MMU state. } +// Print a string to the screen. void print(char *message) { - int x = 0; - unsigned char mmu; + 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. @@ -67,22 +78,27 @@ void print(char *message) { while (message[x] != 0) { switch (message[x]) { default: - line[col] = message[x]; - col++; - if (col != MAX_COL) { - break; - } + vram[_col] = message[x]; + _col++; + if (_col != _MAX_COL) break; // Fall through. case 10: case 13: - col = 0; - row++; - if (row == MAX_ROW) { - scroll(); - row--; + _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; } - line += 80; + vram += _MAX_COL; break; } x++; @@ -90,6 +106,25 @@ void print(char *message) { POKE(MMU_IO_CTRL, mmu); // Restore MMU state. - POKE(CURSOR_X_LOW, col); - POKE(CURSOR_Y_LOW, row); + 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(); } diff --git a/f256lib/f256.h b/f256lib/f256.h index e0ee4aa..432fcd4 100644 --- a/f256lib/f256.h +++ b/f256lib/f256.h @@ -35,6 +35,10 @@ extern "C" #define VICKY_GR_CLUT_3 0xdc00 // I/O Page 1 */ + +typedef unsigned char byte; + + #define TEXT_MATRIX 0xc000 // I/O Page 2 #define TEXT_COLOR_MATRIX 0xc000 // I/O Page 3 #define TEXT_LUT_FOREGROUND 0xd800 // I/O Page 0 @@ -49,8 +53,8 @@ extern "C" #define CURSOR_Y_LOW 0xd016 #define CURSOR_Y_HIGH 0xd017 -#define PEEK(addy) ((unsigned char)*(volatile unsigned char *)(addy)) -#define POKE(addy, value) (*(volatile unsigned char *)(addy) = (value)) +#define PEEK(addy) ((byte)*(volatile byte *)(addy)) +#define POKE(addy, value) (*(volatile byte *)(addy) = (value)) #define VECTOR(member) (size_t)(&((struct call *)0xff00)->member) #define EVENT(member) (size_t)(&((struct events *)0)->member) #define CALL(fn) \ @@ -67,8 +71,33 @@ extern struct event_t event; // The event struct is allocated in crt0. extern char error; +// Apple IIgs Colors, because that's how we roll. +typedef enum textColorsE { + BLACK, + DEEP_RED, + DARK_BLUE, + PURPLE, + DARK_GREEN, + DARK_GRAY, + MEDIUM_BLUE, + LIGHT_BLUE, + BROWN, + ORANGE, + LIGHT_GRAY, + PINK, + LIGHT_GREEN, + YELLOW, + AQUAMARINE, + WHITE +} textColorsT; + +extern uint32_t textColors[16]; + + void cls(void); +void gotoxy(byte x, byte y); void print(char *message); +void reset(void); #ifdef __cplusplus