diff --git a/examples/pgztest/pgztest.c b/examples/pgztest/pgztest.c index 708effb..c0f6f18 100644 --- a/examples/pgztest/pgztest.c +++ b/examples/pgztest/pgztest.c @@ -38,53 +38,48 @@ void bitmap(void) { byte l; byte c = 0; - resetGraphics(); - getBitmapResolution(&mx, &my); + bitmapReset(); + + bitmapGetResolution(&mx, &my); mx--; my--; for (l=0; l= x1) { dx = x2 - x1; @@ -94,7 +96,7 @@ void line(int16_t x1, int16_t y1, int16_t x2, int16_t y2) { balance = dy - dx; dx <<= 1; while (x != x2) { - putpixel(x, y); + bitmapPutPixel(x, y); if (balance >= 0) { y += incY; balance -= dx; @@ -102,13 +104,13 @@ void line(int16_t x1, int16_t y1, int16_t x2, int16_t y2) { balance += dy; x += incX; } - putpixel(x, y); + bitmapPutPixel(x, y); } else { dx <<= 1; balance = dx - dy; dy <<= 1; while (y != y2) { - putpixel(x, y); + bitmapPutPixel(x, y); if (balance >= 0) { x += incX; balance -= dy; @@ -116,19 +118,19 @@ void line(int16_t x1, int16_t y1, int16_t x2, int16_t y2) { balance += dx; y += incY; } - putpixel(x, y); + bitmapPutPixel(x, y); } } -void putpixel(int16_t x, int16_t y) { +void bitmapPutPixel(uint16_t x, uint16_t y) { uint32_t pixelRAM; byte block; // We only map 8k of the bitmap into CPU RAM at once. // We use slot 5 for this. We need to figure out // where our pixel lands and bring that into RAM. - pixelRAM = _BITMAP_BASE + ((int32_t)y * (int32_t)_MAX_X) + (int32_t)x; + pixelRAM = _BITMAP_BASE[_page] + ((int32_t)y * (int32_t)_MAX_X) + (int32_t)x; block = pixelRAM / 0x2000; pixelRAM &= 0x1FFF; // Find offset into this block. POKE(MMU_MEM_BANK_5, block); @@ -137,39 +139,76 @@ void putpixel(int16_t x, int16_t y) { } -void resetGraphics(void) { - byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state. - int x; +void bitmapReset(void) { + byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state. + int x; + uint32_t realSize; + uint32_t pageBlocks; + uint32_t eightK = 0x2000; _MAX_X = 320; _MAX_Y = 240; - _BITMAP_BASE = 0x10000; + _PAGE_SIZE = (uint32_t)_MAX_X * (uint32_t)_MAX_Y; + + // I could hardcode this, but this preserves the math so I don't forget later. + pageBlocks = _PAGE_SIZE / eightK; + if ((pageBlocks * eightK) != _PAGE_SIZE) { + // Fractional pageBlock. Round up. + pageBlocks++; + } + realSize = pageBlocks * eightK; + + _BITMAP_BASE[0] = 0x10000; + _BITMAP_BASE[1] = _BITMAP_BASE[0] + realSize; // Page 2 = 0x24000 + _BITMAP_BASE[2] = _BITMAP_BASE[1] + realSize; // Page 3 = 0x38000 + + print("\nbase0 = "); printInt(_BITMAP_BASE[0]); + print("\nbase1 = "); printInt(_BITMAP_BASE[1]); + print("\nbase2 = "); printInt(_BITMAP_BASE[2]); + + // Set palette to a gradient so there's at least *something*. + for (x=0; x<256; x++) bitmapDefineColor(x, x, x, x); POKE(MMU_IO_CTRL, MMU_IO_PAGE_0); // Swap I/O page 0 into bank 6. POKE(VKY_LAYER_CTRL_0, 16); // Bitmaps on all layers. POKE(VKY_LAYER_CTRL_1, 1); // Bitmaps on all layers. - POKE(VKY_BM1_CTRL, 0); // Disable bitmap 1. - POKE(VKY_BM2_CTRL, 0); // Disable bitmap 2. - // Set up bitmap 0. - POKE(VKY_BM0_CTRL, 1); // Enable bitmap 0, GLUT 0. - POKEA(VKY_BM0_ADDR_L, _BITMAP_BASE); // Location of bitmap data. - //POKE(VKY_BM0_ADDR_L, _BITMAP_BASE & 0xFF); // Location of bitmap data. - //POKE(VKY_BM0_ADDR_M, (_BITMAP_BASE >> 8) & 0xFF); // Location of bitmap data. - //POKE(VKY_BM0_ADDR_H, (_BITMAP_BASE >> 16) & 0xFF); // Location of bitmap data. + // Turn everthing on for setup. + POKE(VKY_BM0_CTRL, 1); + POKE(VKY_BM1_CTRL, 1); + POKE(VKY_BM2_CTRL, 1); + + // Set up bitmap memory. + POKEA(VKY_BM0_ADDR_L, _BITMAP_BASE[0]); // Location of bitmap data. + POKEA(VKY_BM1_ADDR_L, _BITMAP_BASE[1]); // Location of bitmap data. + POKEA(VKY_BM2_ADDR_L, _BITMAP_BASE[2]); // Location of bitmap data. + + // Enable the first bitmap. + bitmapShowPage(0); POKE(MMU_IO_CTRL, mmu); // Restore MMU state. - // Set palette to a gradient so there's at least *something*. - for (x=0; x<256; x++) defineGraphicsColor(x, x, x, x); - + // Clear all pages. _color = 0; - clearBitmap(); + for (_page=0; _page<3; _page++) bitmapClear(); + _page = 0; _color = 255; } -void setGraphicsColor(byte c) { +void bitmapSetColor(byte c) { _color = c; } + + +void bitmapSetPage(byte p) { + _page = p; +} + + +void bitmapShowPage(byte p) { + POKE(VKY_BM0_CTRL, p == 0 ? 1 : 0); // Enable bitmap 0, GLUT 0. + POKE(VKY_BM1_CTRL, p == 1 ? 1 : 0); + POKE(VKY_BM2_CTRL, p == 2 ? 1 : 0); +} diff --git a/f256lib/bitmap.h b/f256lib/bitmap.h index 323c09e..e93dd7d 100644 --- a/f256lib/bitmap.h +++ b/f256lib/bitmap.h @@ -34,13 +34,15 @@ extern "C" #include "f256.h" -void clearBitmap(void); -void defineGraphicsColor(byte slot, byte r, byte g, byte b); -void getBitmapResolution(int16_t *x, int16_t *y); -void line(int16_t x1, int16_t y1, int16_t x2, int16_t y2); -void putpixel(int16_t x, int16_t y); -void resetGraphics(void); -void setGraphicsColor(byte c); +void bitmapClear(void); +void bitmapDefineColor(byte slot, byte r, byte g, byte b); +void bitmapGetResolution(uint16_t *x, uint16_t *y); +void bitmapLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2); +void bitmapPutPixel(uint16_t x, uint16_t y); +void bitmapReset(void); +void bitmapSetColor(byte c); +void bitmapSetPage(byte p); +void bitmapShowPage(byte p); #ifdef __cplusplus