112 lines
2.8 KiB
C
112 lines
2.8 KiB
C
/*
|
|
* 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.
|
|
*/
|
|
|
|
|
|
#ifndef WITHOUT_GRAPHICS
|
|
|
|
|
|
#ifndef F256LIB_AMALGAMATED_BUILD
|
|
#include "f_graphics.h"
|
|
#endif
|
|
|
|
|
|
void graphicsDefineColor(byte clut, byte slot, byte r, byte g, byte b) {
|
|
byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
|
|
byte *write;
|
|
uint16_t gclut;
|
|
|
|
switch (clut) {
|
|
case 0:
|
|
gclut = VKY_GR_CLUT_0;
|
|
break;
|
|
case 1:
|
|
gclut = VKY_GR_CLUT_1;
|
|
break;
|
|
case 2:
|
|
gclut = VKY_GR_CLUT_2;
|
|
break;
|
|
case 3:
|
|
gclut = VKY_GR_CLUT_3;
|
|
break;
|
|
}
|
|
|
|
POKE(MMU_IO_CTRL, MMU_IO_PAGE_1); // Swap I/O page 1 into bank 6.
|
|
|
|
// This doesn't work for some reason.
|
|
//write = (byte *)mathUnsignedAddition((uint32_t)gclut, mathUnsignedMultiply((uint16_t)slot, (uint16_t)4));
|
|
|
|
write = (byte *)gclut + (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;
|
|
|
|
// Set palettes to a gradient so there's at least *something*.
|
|
for (y=0; y<4; y++) {
|
|
for (x=0; x<256; x++) {
|
|
graphicsDefineColor(y, x, x, x, x);
|
|
}
|
|
}
|
|
|
|
graphicsSetLayerBitmap(0, 0);
|
|
graphicsSetLayerBitmap(1, 1);
|
|
graphicsSetLayerBitmap(2, 2);
|
|
}
|
|
|
|
|
|
void graphicsSetLayerBitmap(byte layer, byte which) {
|
|
switch (layer) {
|
|
case 0:
|
|
POKE(VKY_LAYER_CTRL_0, (PEEK(VKY_LAYER_CTRL_0) & 0xf0) | which);
|
|
break;
|
|
case 1:
|
|
POKE(VKY_LAYER_CTRL_0, (PEEK(VKY_LAYER_CTRL_0) & 0x0f) | (which << 4));
|
|
break;
|
|
case 2:
|
|
POKE(VKY_LAYER_CTRL_1, which); //***TODO*** This doesn't work?
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
void graphicsSetLayerTile(byte layer, byte which) {
|
|
graphicsSetLayerBitmap(layer, which + 4);
|
|
}
|
|
|
|
|
|
void graphicsWaitVerticalBlank(void) {
|
|
//***TODO*** This assumes we're 60hz with graphics enabled.
|
|
while (PEEKW(RAST_ROW_L) != 482)
|
|
// Spin our wheels.
|
|
;
|
|
}
|
|
|
|
|
|
#endif
|