/* * Copyright (c) 2024 Scott Duensing, scott@kangaroopunch.com * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #include "graphics.h" void graphicsDefineColor(uint16_t clut, byte slot, byte r, byte g, byte b) { byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state. byte *write; POKE(MMU_IO_CTRL, MMU_IO_PAGE_1); // Swap I/O page 1 into bank 6. write = (byte *)mathUnsignedAddition(clut, mathUnsignedMultiply(slot, 4)); *write++ = b; *write++ = g; *write++ = r; *write++ = 0xff; POKE(MMU_IO_CTRL, mmu); // Restore MMU state. } void graphicsReset() { int16_t x; byte y; uint16_t cluts[] = { GRAPHICS_CLUT_0, GRAPHICS_CLUT_1, GRAPHICS_CLUT_2, GRAPHICS_CLUT_3 }; // Set palettes to a gradient so there's at least *something*. for (y=0; y<4; y++) { for (x=0; x<256; x++) { graphicsDefineColor(cluts[y], x, x, x, x); } } graphicsSetLayerType(0, GRAPHICS_BITMAP_0); graphicsSetLayerType(1, GRAPHICS_BITMAP_1); graphicsSetLayerType(2, GRAPHICS_BITMAP_2); } void graphicsSetLayerType(byte layer, byte what) { switch (layer) { case 0: POKE(VKY_LAYER_CTRL_0, (PEEK(VKY_LAYER_CTRL_0) & 0xf0) | what); break; case 1: POKE(VKY_LAYER_CTRL_0, (PEEK(VKY_LAYER_CTRL_0) & 0x0f) | (what << 4)); break; case 2: POKE(VKY_LAYER_CTRL_1, what); break; } } void graphicsWaitVerticalBlank(void) { //***TODO*** This assumes we're 60hz with graphics enabled. while (PEEKW(RAST_ROW_L) != 482) // Spin our wheels. ; }