126 lines
3.5 KiB
C
126 lines
3.5 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.
|
|
*/
|
|
|
|
|
|
#include "bitmap.h"
|
|
|
|
|
|
static int _MAX_X = 320;
|
|
static int _MAX_Y = 200;
|
|
static uint32_t _BITMAP_BASE = 0x10000;
|
|
static byte _color = 255;
|
|
|
|
|
|
char error;
|
|
|
|
|
|
void clear(void) {
|
|
int x;
|
|
int y;
|
|
|
|
//***TODO*** Use DMA
|
|
|
|
// This is just test code.
|
|
for (y=0; y<_MAX_Y; y++) {
|
|
for (x=0; x<_MAX_X; x++) {
|
|
putpixel(x, y);
|
|
}
|
|
_color++; // Let it roll over.
|
|
}
|
|
}
|
|
|
|
|
|
void defineGraphicsColor(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 *)VKY_GR_CLUT_0 + slot * 4;
|
|
*write++ = b;
|
|
*write++ = g;
|
|
*write++ = r;
|
|
*write++ = 0xff;
|
|
|
|
POKE(MMU_IO_CTRL, mmu); // Restore MMU state.
|
|
}
|
|
|
|
|
|
void putpixel(int x, int 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 + (y * _MAX_X) + x;
|
|
block = pixelRAM / 0x2000;
|
|
POKE(MMU_MEM_BANK_5, block);
|
|
//pixelRAM -= 0x2000 * block; // Find offset into this block.
|
|
pixelRAM &= 0x1FFF;
|
|
POKE(0xa000 + pixelRAM, _color);
|
|
POKE(MMU_MEM_BANK_5, 5);
|
|
}
|
|
|
|
|
|
void resetGraphics(void) {
|
|
byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
|
|
byte x;
|
|
int y;
|
|
|
|
_MAX_X = 320;
|
|
_MAX_Y = 200;
|
|
_BITMAP_BASE = 0x10000;
|
|
_color = 255;
|
|
|
|
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.
|
|
//POKED(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.
|
|
|
|
// Set palette to a gradient so there's at least *something*.
|
|
for (x=0; x<=255; x++) defineGraphicsColor(x, x, x, x);
|
|
|
|
clear();
|
|
|
|
/*
|
|
POKE(MMU_MEM_BANK_5, 8);
|
|
for (y=0; y<8192; y++) POKE(0xa000 + y, 255);
|
|
POKE(MMU_MEM_BANK_5, 5);
|
|
*/
|
|
|
|
POKE(MMU_IO_CTRL, mmu); // Restore MMU state.
|
|
}
|
|
|
|
|
|
void setGraphicsColor(byte c) {
|
|
_color = c;
|
|
}
|