Three pages of bitmap space to draw on. Possible DMA bug.
This commit is contained in:
parent
47a9dee1ab
commit
3b08bc45c8
3 changed files with 112 additions and 76 deletions
|
@ -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<TEXTCOLORS_COUNT; l++)
|
||||
defineGraphicsColor(l,
|
||||
bitmapDefineColor(l,
|
||||
textColors[l].r,
|
||||
textColors[l].g,
|
||||
textColors[l].b);
|
||||
|
||||
l = 0;
|
||||
while (1) {
|
||||
setGraphicsColor(c++);
|
||||
bitmapSetColor(c++);
|
||||
if (c == TEXTCOLORS_COUNT) c = 0;
|
||||
|
||||
switch (l) {
|
||||
case 0:
|
||||
bitmapSetPage(1);
|
||||
bitmapShowPage(0);
|
||||
l = 1;
|
||||
break;
|
||||
case 1:
|
||||
bitmapSetPage(2);
|
||||
bitmapShowPage(1);
|
||||
l = 2;
|
||||
break;
|
||||
case 2:
|
||||
bitmapSetPage(0);
|
||||
bitmapShowPage(2);
|
||||
l = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
x = rndRead() % mx;
|
||||
y = rndRead() % my;
|
||||
x2 = rndRead() % mx;
|
||||
y2 = rndRead() % my;
|
||||
|
||||
/*
|
||||
setTextColor(WHITE, BLACK);
|
||||
print("c = "); printInt(c);
|
||||
print(" ("); printInt(x);
|
||||
print("x"); printInt(y);
|
||||
print(")-("); printInt(x2);
|
||||
print("x"); printInt(y2);
|
||||
print(")\n");
|
||||
*/
|
||||
|
||||
line(x, y, x2, y2);
|
||||
bitmapLine(x, y, x2, y2);
|
||||
}
|
||||
|
||||
/*
|
||||
for (y=0; y<my; y++) {
|
||||
setGraphicsColor(c);
|
||||
c++; // Let it roll over.
|
||||
for (x=0; x<mx; x++) {
|
||||
putpixel(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
for (l=0; l<TEXTCOLORS_COUNT; l++) {
|
||||
setGraphicsColor(l);
|
||||
clearBitmap();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
|
117
f256lib/bitmap.c
117
f256lib/bitmap.c
|
@ -25,21 +25,23 @@
|
|||
#include "dma.h"
|
||||
|
||||
|
||||
static int16_t _MAX_X = 320;
|
||||
static int16_t _MAX_Y = 240;
|
||||
static uint32_t _BITMAP_BASE = 0x10000;
|
||||
static byte _color = 255;
|
||||
static uint16_t _MAX_X;
|
||||
static uint16_t _MAX_Y;
|
||||
static uint32_t _PAGE_SIZE;
|
||||
static uint32_t _BITMAP_BASE[3]; // Maximum of 3 pages possible.
|
||||
static byte _color;
|
||||
static byte _page;
|
||||
|
||||
|
||||
char error;
|
||||
|
||||
|
||||
void clearBitmap(void) {
|
||||
dmaFill(_BITMAP_BASE, (uint32_t)_MAX_X * (uint32_t)_MAX_Y, _color);
|
||||
void bitmapClear(void) {
|
||||
dmaFill(_BITMAP_BASE[_page], _PAGE_SIZE, _color);
|
||||
}
|
||||
|
||||
|
||||
void defineGraphicsColor(byte slot, byte r, byte g, byte b) {
|
||||
void bitmapDefineColor(byte slot, byte r, byte g, byte b) {
|
||||
byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
|
||||
byte *write;
|
||||
|
||||
|
@ -55,20 +57,20 @@ void defineGraphicsColor(byte slot, byte r, byte g, byte b) {
|
|||
}
|
||||
|
||||
|
||||
void getBitmapResolution(int16_t *x, int16_t *y) {
|
||||
void bitmapGetResolution(uint16_t *x, uint16_t *y) {
|
||||
*x = _MAX_X;
|
||||
*y = _MAX_Y;
|
||||
}
|
||||
|
||||
|
||||
void line(int16_t x1, int16_t y1, int16_t x2, int16_t y2) {
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
int16_t dx;
|
||||
int16_t dy;
|
||||
int16_t incX;
|
||||
int16_t incY;
|
||||
int16_t balance;
|
||||
void bitmapLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
int16_t dx;
|
||||
int16_t dy;
|
||||
int16_t incX;
|
||||
int16_t incY;
|
||||
int16_t balance;
|
||||
|
||||
if (x2 >= 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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue