diff --git a/examples/tilemap/u5map.c b/examples/tilemap/u5map.c index 291a0c1..cdca0d5 100644 --- a/examples/tilemap/u5map.c +++ b/examples/tilemap/u5map.c @@ -32,20 +32,20 @@ int main(void) { - byte x; - byte r; - byte g; - byte b; - byte *c; + byte x; + byte r; + byte g; + byte b; + uint32_t c; f256Init(); // Set up CLUT0. - c = (byte *)TILES_CLUT; + c = TILES_CLUT; for (x=0; x<16; x++) { - b = *c++; - g = *c++; - r = *c++; + b = FAR_PEEK(c++); + g = FAR_PEEK(c++); + r = FAR_PEEK(c++); c++; graphicsDefineColor(0, x, r, g, b); } diff --git a/f256lib/f256.c b/f256lib/f256.c index ffb0458..2d3f1c8 100644 --- a/f256lib/f256.c +++ b/f256lib/f256.c @@ -63,3 +63,32 @@ void f256Init(void) { 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. + } + + 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"); + } + + return result; +} diff --git a/f256lib/f256.h b/f256lib/f256.h index 7a2a0ae..9490d1f 100644 --- a/f256lib/f256.h +++ b/f256lib/f256.h @@ -102,6 +102,7 @@ typedef struct colorS { void f256Init(void); +byte FAR_PEEK(uint32_t address); #include "kernel.h"