diff --git a/README b/README index 6fd9304..bb3e3f8 100644 --- a/README +++ b/README @@ -27,6 +27,7 @@ At a minimum, you should run the following: ./build-llvm-mos.sh all ./build-merlin.sh ./update-defines.sh + ./build-tools.sh SCRIPTS diff --git a/examples/pgztest/pgztest.c b/examples/pgztest/pgztest.c index d6d3016..3c9c67f 100644 --- a/examples/pgztest/pgztest.c +++ b/examples/pgztest/pgztest.c @@ -38,16 +38,18 @@ void bitmap(void) { byte l; byte c = 0; - textPrint("\n"); +// textPrint("\n"); for (l=0; l= x1) { dx = x2 - x1; @@ -152,33 +132,14 @@ void bitmapLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) { bitmapPutPixelIOSet(x, y); } - if (SWAP_SLOT == MMU_MEM_BANK_6) { - POKE(MMU_MEM_BANK_6, ram); // Restore slot 6. - POKE(MMU_IO_CTRL, mmu); // Restore MMU state. - asm("cli"); - } + SWAP_IO_SHUTDOWN(); } void bitmapPutPixel(uint16_t x, uint16_t y) { - byte mmu; - byte ram; - - // Hoping the compiler optimizes this out when not needed. :-) - if (SWAP_SLOT == MMU_MEM_BANK_6) { - mmu = PEEK(MMU_IO_CTRL); // Get current MMU state. - ram = PEEK(MMU_MEM_BANK_6); // Get current slot 6 contents. - asm("sei"); - POKE(MMU_IO_CTRL, 4); // Turn off I/O window. - } - + SWAP_IO_SETUP(); bitmapPutPixelIOSet(x, y); - - if (SWAP_SLOT == MMU_MEM_BANK_6) { - POKE(MMU_MEM_BANK_6, ram); // Restore slot 6. - POKE(MMU_IO_CTRL, mmu); // Restore MMU state. - asm("cli"); - } + SWAP_IO_SHUTDOWN(); } diff --git a/f256lib/f256.c b/f256lib/f256.c index 8a6a2ce..d54e445 100644 --- a/f256lib/f256.c +++ b/f256lib/f256.c @@ -39,11 +39,9 @@ void f256Init(void) { POKE(MMU_IO_CTRL, MMU_IO_PAGE_0); POKE(VKY_MSTR_CTRL_0, 63); // Enable text and all graphics. - //POKE(VKY_MSTR_CTRL_1, 0); - //POKE(VKY_MSTR_CTRL_1, 20); // Enable FON_OVLY and DBL_Y. - POKE(VKY_MSTR_CTRL_1, 4); // Enable DBL_Y. POKE(MMU_MEM_CTRL, 0xb3); // MLUT editing enabled, editing 3, 3 is active. + // Set all memory slots to be CPU memory. POKE(MMU_MEM_BANK_0, 0); POKE(MMU_MEM_BANK_1, 1); @@ -61,34 +59,25 @@ void f256Init(void) { tileReset(); spriteReset(); + // Make font taller for us blind people. + textSetDouble(false, true); + randomSeed(0); //***TODO*** Use clock or something. } byte FAR_PEEK(uint32_t address) { byte block; - byte mmu; - byte ram; byte result; - // Hoping the compiler optimizes this out when not needed. :-) - if (SWAP_SLOT == MMU_MEM_BANK_6) { - mmu = PEEK(MMU_IO_CTRL); // Get current MMU state. - ram = PEEK(MMU_MEM_BANK_6); // Get current slot 6 contents. - asm("sei"); - POKE(MMU_IO_CTRL, 4); // Turn off I/O window. - } + SWAP_IO_SETUP(); block = address / EIGHTK; address &= 0x1FFF; // Find offset into this block. POKE(SWAP_SLOT, block); result = PEEK(SWAP_ADDR + address); - if (SWAP_SLOT == MMU_MEM_BANK_6) { - POKE(MMU_MEM_BANK_6, ram); // Restore slot 6. - POKE(MMU_IO_CTRL, mmu); // Restore MMU state. - asm("cli"); - } + SWAP_IO_SHUTDOWN(); return result; } diff --git a/f256lib/f256.h b/f256lib/f256.h index 9490d1f..b38e60b 100644 --- a/f256lib/f256.h +++ b/f256lib/f256.h @@ -58,7 +58,32 @@ typedef unsigned char bool; // Our stuff. #define SWAP_SLOT MMU_MEM_BANK_5 -#define SWAP_ADDR 0xa000 +#define SWAP_ADDR ((SWAP_SLOT - MMU_MEM_BANK_0) * 0x2000) + +// This is an attempt to allow us to free up slot 5 and use slot 6 for paging +// RAM in and out. Currently, it does not work. +#if SWAP_SLOT == MMU_MEM_BANK_6 + +#define SWAP_IO_SETUP() \ + byte sios_mmu = PEEK(MMU_IO_CTRL); \ + byte sios_ram = PEEK(MMU_MEM_BANK_6); \ + ({ \ + asm("sei"); \ + POKE(MMU_IO_CTRL, 4); \ + }) + +#define SWAP_IO_SHUTDOWN() ({ \ + POKE(MMU_MEM_BANK_6, sios_ram); \ + POKE(MMU_IO_CTRL, sios_mmu); \ + asm("cli"); \ +}) + +#else + +#define SWAP_IO_SETUP() +#define SWAP_IO_SHUTDOWN() + +#endif // Things not in the Merlin defs. @@ -76,6 +101,14 @@ typedef unsigned char bool; #define VKY_TS6_SQUARE (VKY_TS6_ADDR_H+1) #define VKY_TS7_SQUARE (VKY_TS7_ADDR_H+1) +#define JOY_UP 1 +#define JOY_DOWN 2 +#define JOY_LEFT 4 +#define JOY_RIGHT 8 +#define JOY_BUTTON_1 16 +#define JOY_BUTTON_2 32 +#define JOY_BUTTON_3 64 + typedef struct colorS { byte r; @@ -100,6 +133,15 @@ typedef struct colorS { #define PEEKD(addy) ((uint32_t)*(volatile uint32_t *)(addy)) #define POKED(addy,value) (*(volatile uint32_t *)(addy) = (value)) +// Bit fun. +#define LOW_BYTE(v) ((byte)(x)) +#define HIGH_BYTE(v) ((byte)(((uint16_t)(x)) >> 8)) +#define SWAP_NIBBLES(x) ((x & 0x0F) << 4 | (x & 0xF0) >> 4) +#define CHECK_BIT(x, pos) (x & (1UL << pos)) +#define TOGGLE_BIT(x, pos) (x ^= (1U << pos)) +#define CLEAR_BIT(x, pos) (x &= (~(1U << pos))) +#define SET_BIT(x, pos) (x |= (1U << pos)) + void f256Init(void); byte FAR_PEEK(uint32_t address); diff --git a/f256lib/text.c b/f256lib/text.c index 1553a09..fbd268f 100644 --- a/f256lib/text.c +++ b/f256lib/text.c @@ -225,3 +225,8 @@ void textSetCursor(byte c) { POKE(VKY_CRSR_CHAR, c); // Set cursor shape. (199 = Checkerboard) } } + + +void textSetDouble(bool x, bool y) { + POKE(VKY_MSTR_CTRL_1, (PEEK(VKY_MSTR_CTRL_1) & 0xf9) | (x << 1) | (y << 2)); +} diff --git a/f256lib/text.h b/f256lib/text.h index 96f2627..cf0ff5b 100644 --- a/f256lib/text.h +++ b/f256lib/text.h @@ -68,6 +68,7 @@ void textPrintInt(int32_t value); void textReset(void); void textSetColor(byte f, byte b); void textSetCursor(byte c); +void textSetDouble(bool x, bool y); #ifdef __cplusplus