Library now assumes I/O page 0 is active at all times. Cube using math coprocessor for multiplication.

This commit is contained in:
Scott Duensing 2024-01-07 19:13:36 -06:00
parent a36ef5c495
commit f642221028
8 changed files with 81 additions and 64 deletions

View file

@ -32,8 +32,11 @@
#define TO_DBL(x) (((double)x)/(double)(1<<FIX_PREC))
#define TO_LONG(x) ((x)/(1<<FIX_PREC))
#define fix_mul(a,b) ((a * b) >> FIX_PREC)
#define fix_sqr(a) ((a * a) >> FIX_PREC)
int16_t _remainder;
#define fix_mul(a,b) (mathSignedMultiply(a, b) >> FIX_PREC)
#define fix_sqr(a) (mathSignedMultiply(a, a) >> FIX_PREC)
//#define fix_div(a,b) mathSignedDivision((a << FIX_PREC), b, &_remainder)
#define fix_div(a,b) ((a << FIX_PREC) / b)
#define SIN_SIZE 512

View file

@ -156,7 +156,6 @@ void bitmapPutPixel(uint16_t x, uint16_t y) {
void bitmapReset(void) {
byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
int x;
uint32_t realSize;
uint32_t pageBlocks;
@ -186,8 +185,6 @@ void bitmapReset(void) {
// 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, 2); // Bitmaps on all layers.
@ -204,8 +201,6 @@ void bitmapReset(void) {
// Enable the first bitmap.
bitmapShowPage(0);
POKE(MMU_IO_CTRL, mmu); // Restore MMU state.
// Clear all pages.
_color = 0;
for (_page=0; _page<3; _page++) bitmapClear();

View file

@ -28,10 +28,6 @@ static void dmaWait(void);
void dmaFill(uint32_t start, uint32_t length, byte value) {
byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
POKE(MMU_IO_CTRL, MMU_IO_PAGE_0); // Swap I/O page 0 into bank 6.
POKE(DMA_CTRL, DMA_CTRL_FILL | DMA_CTRL_ENABLE);
POKE(DMA_FILL_VAL, value);
POKEA(DMA_DST_ADDR, start);
@ -39,17 +35,11 @@ void dmaFill(uint32_t start, uint32_t length, byte value) {
POKE(DMA_CTRL, PEEK(DMA_CTRL) | DMA_CTRL_START);
dmaWait();
POKE(MMU_IO_CTRL, mmu); // Restore MMU state.
}
void dma2dFill(uint32_t start, uint16_t width, uint16_t height, uint16_t stride, byte value) {
byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
POKE(MMU_IO_CTRL, MMU_IO_PAGE_0); // Swap I/O page 0 into bank 6.
POKE(DMA_CTRL, DMA_CTRL_2D | DMA_CTRL_ENABLE);
POKE(DMA_FILL_VAL, value);
POKEA(DMA_DST_ADDR, start);
@ -59,8 +49,6 @@ void dma2dFill(uint32_t start, uint16_t width, uint16_t height, uint16_t stride,
POKE(DMA_CTRL, PEEK(DMA_CTRL) | DMA_CTRL_START);
dmaWait();
POKE(MMU_IO_CTRL, mmu); // Restore MMU state.
}

View file

@ -26,18 +26,15 @@
#include "text.c"
#include "bitmap.c"
#include "dma.c"
#include "math.h"
#include "math.c"
char error;
void f256Init(void) {
byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
asm("sei");
POKE(MMU_IO_CTRL, MMU_IO_PAGE_0); // Swap I/O page 0 into bank 6.
// Swap I/O page 0 into bank 6. This is our normal state.
POKE(MMU_IO_CTRL, MMU_IO_PAGE_0);
//POKE(VKY_MSTR_CTRL_0, 1); // Enable text.
//POKE(VKY_MSTR_CTRL_0, 12); // Enable bitmaps.
@ -46,8 +43,6 @@ void f256Init(void) {
//POKE(VKY_MSTR_CTRL_1, 20); // Enable FON_OVLY and DBL_Y.
POKE(VKY_MSTR_CTRL_1, 4); // Enable DBL_Y.
POKE(MMU_IO_CTRL, mmu); // Restore MMU state.
POKE(MMU_MEM_CTRL, 0xb3); // MLUT editing enabled, editing 3, 3 is active.
// Set all memory slots to be CPU memory.
POKE(MMU_MEM_BANK_0, 0);
@ -55,7 +50,7 @@ void f256Init(void) {
POKE(MMU_MEM_BANK_2, 2);
POKE(MMU_MEM_BANK_3, 3);
POKE(MMU_MEM_BANK_4, 4);
POKE(MMU_MEM_BANK_5, 5);
POKE(MMU_MEM_BANK_5, 5); // Don't use this - it's for the library.
// MMU_MEM_BANK_6 is always mapped to I/O.
// MMU_MEM_BANK_7 belongs to the MicroKernel.
@ -67,37 +62,22 @@ void f256Init(void) {
uint16_t randomRead(void) {
byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
uint16_t result;
POKE(MMU_IO_CTRL, MMU_IO_PAGE_0); // Swap I/O page 0 into bank 6.
POKE(VKY_RND_CTRL, 1); // Enable.
result = PEEKW(VKY_RNDL);
POKE(MMU_IO_CTRL, mmu); // Restore MMU state.
return result;
}
void randomSeed(uint16_t seed) {
byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
POKE(MMU_IO_CTRL, MMU_IO_PAGE_0); // Swap I/O page 0 into bank 6.
POKEW(VKY_SEEDL, seed);
POKE(VKY_RND_CTRL, 3); // Enable, load seed.
POKE(MMU_IO_CTRL, mmu); // Restore MMU state.
}
void waitVerticalBlank(void) {
byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
POKE(MMU_IO_CTRL, MMU_IO_PAGE_0); // Swap I/O page 0 into bank 6.
//***TODO*** This assumes we're 60hz with graphics enabled.
while (PEEKW(RAST_ROW_L) == 482)
// Spin our wheels.
@ -105,6 +85,4 @@ void waitVerticalBlank(void) {
while (PEEKW(RAST_ROW_L) != 482)
// Spin our wheels.
;
POKE(MMU_IO_CTRL, mmu); // Restore MMU state.
}

View file

@ -77,7 +77,7 @@ typedef struct colorS {
#define POKEA(addy, value) POKE(addy, value & 0xFF); POKE(addy + 1, (value >> 8) & 0xFF); POKE(addy + 2, (value >> 16) & 0xFF)
// Double-word (four bytes)
#define PEEKD(addy) ((uint_32)*(volatile uint32_t *)(addy))
#define PEEKD(addy) ((uint32_t)*(volatile uint32_t *)(addy))
#define POKED(addy,value) (*(volatile uint32_t *)(addy) = (value))
#define VECTOR(member) (size_t)(&((struct call *)0xff00)->member)

View file

@ -22,3 +22,67 @@
#include "math.h"
int16_t mathSignedDivision(int16_t a, int16_t b, int16_t *remainder) {
byte signA = 0; // Zero indicates positive.
byte signB = 0;
int16_t r;
if (a < 0) {
signA = 1;
a = -a;
}
if (b < 0) {
signB = 1;
b = -b;
}
POKEW(DIVU_DEN_L, b);
POKEW(DIVU_NUM_L, a);
r = PEEKW(QUOU_LL);
*remainder = PEEKW(REMU_HL);
if (signA + signB == 1) r = -r;
return r;
}
int32_t mathSignedMultiply(int16_t a, int16_t b) {
byte signA = 0; // Zero indicates positive.
byte signB = 0;
int32_t r;
if (a < 0) {
signA = 1;
a = -a;
}
if (b < 0) {
signB = 1;
b = -b;
}
POKEW(MULU_A_L, a);
POKEW(MULU_B_L, b);
r = PEEKD(MULU_LL);
if (signA + signB == 1) r = -r;
return r;
}
uint16_t mathUnSignedDivision(uint16_t a, uint16_t b, uint16_t *remainder) {
POKEW(DIVU_DEN_L, b);
POKEW(DIVU_NUM_L, a);
*remainder = PEEKW(REMU_HL);
return PEEKW(QUOU_LL);
}
uint32_t mathUnsignedMultiply(uint16_t a, uint16_t b) {
POKEW(MULU_A_L, a);
POKEW(MULU_B_L, b);
return PEEKD(MULU_LL);
}

View file

@ -34,6 +34,12 @@ extern "C"
#include "f256.h"
int16_t mathSignedDivision(int16_t a, int16_t b, int16_t *remainder);
int32_t mathSignedMultiply(int16_t a, int16_t b);
uint16_t mathUnSignedDivision(uint16_t a, uint16_t b, uint16_t *remainder);
uint32_t mathUnsignedMultiply(uint16_t a, uint16_t b);
#ifdef __cplusplus
}
#endif

View file

@ -55,8 +55,8 @@ static byte _ccolor = 240;
// Clear screen to current text attributes.
void textClear(void) {
int i;
byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
int i;
volatile byte *vram = (byte *)TEXT_MATRIX;
POKE(MMU_IO_CTRL, MMU_IO_TEXT); // Swap I/O page 2 into bank 6.
@ -74,11 +74,8 @@ void textClear(void) {
// Define text color.
void textDefineColor(byte slot, byte fr, byte fg, byte fb, byte br, byte bg, byte bb) {
byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
byte *write;
POKE(MMU_IO_CTRL, MMU_IO_PAGE_0); // Swap I/O page 0 into bank 6.
write = (byte *)VKY_TXT_FGLUT + slot * 4;
*write++ = fb;
*write++ = fg;
@ -90,18 +87,11 @@ void textDefineColor(byte slot, byte fr, byte fg, byte fb, byte br, byte bg, byt
*write++ = bg;
*write++ = br;
*write++ = 0xff;
POKE(MMU_IO_CTRL, mmu); // Restore MMU state.
}
// Move cursor.
void textGotoXY(byte x, byte y) {
byte mmu;
mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
POKE(MMU_IO_CTRL, MMU_IO_PAGE_0); // Swap I/O page 0 into bank 6.
_col = x;
POKE(VKY_CRSR_X_L, _col); // Set cursor X position.
POKE(VKY_CRSR_X_H, 0);
@ -109,8 +99,6 @@ void textGotoXY(byte x, byte y) {
_row = y;
POKE(VKY_CRSR_Y_L, _row); // Set cursor Y position.
POKE(VKY_CRSR_Y_H, 0);
POKE(MMU_IO_CTRL, mmu); // Restore MMU state.
}
@ -188,7 +176,6 @@ void textPrintInt(int32_t value){
// Reset display to text, "standard" colors.
void textReset(void) {
byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
byte x;
byte y;
@ -199,8 +186,6 @@ void textReset(void) {
_bcolor = 0;
_ccolor = 240;
POKE(MMU_IO_CTRL, MMU_IO_PAGE_0); // Swap I/O page 0 into bank 6.
POKE(VKY_CRSR_CTRL, 3); // Enable cursor, 1/2s flash.
POKE(VKY_CRSR_CHAR, '_'); // Set cursor shape. (199 = Checkerboard)
@ -214,8 +199,6 @@ void textReset(void) {
textColors[x].g,
textColors[x].b);
POKE(MMU_IO_CTRL, mmu); // Restore MMU state.
textClear();
}