More performance stuff

Still can't get 50fps on an A500 but this is good enough for now.
This commit is contained in:
John Bintz 2024-09-22 07:32:13 -04:00
parent bd035eaea1
commit 6b86be00d4
4 changed files with 62 additions and 10 deletions

51
bun.c
View File

@ -56,6 +56,33 @@ struct BunClear {
uint8_t *coolbunPlaneStarts[3][2]; uint8_t *coolbunPlaneStarts[3][2];
uint16_t bunRightSide_bltalwmPrecalc[16];
uint16_t bunLeftSide_bltalwmPrecalc[16];
void precalculateBunBLTALWM() {
int shift, j;
uint16_t bltalwm;
for (shift = 0; shift < 16; ++shift) {
// right
bltalwm = 0x0000;
for (j = 0; j < 15 - shift; ++j) {
bltalwm += (1 << (15 - j));
}
bunRightSide_bltalwmPrecalc[shift] = bltalwm;
//left
bltalwm = 0x0000;
for (j = 0; j <= 15 - shift; ++j) {
bltalwm += (1 << j);
}
bunLeftSide_bltalwmPrecalc[shift] = bltalwm;
}
}
void bun_offRightSide( void bun_offRightSide(
int plusXValue, int plusXValue,
int y, int y,
@ -75,10 +102,14 @@ void bun_offRightSide(
bunClear->widthWords = 2 - wordShift; bunClear->widthWords = 2 - wordShift;
bunClear->direction = BLITTER_ASCENDING; bunClear->direction = BLITTER_ASCENDING;
bltalwm = bunRightSide_bltalwmPrecalc[shift];
/*
bltalwm = 0x0000; bltalwm = 0x0000;
for (i = 0; i <= 15 - shift; ++i) { for (i = 0; i <= 15 - shift; ++i) {
bltalwm += (1 << (15 - i)); bltalwm += (1 << (15 - i));
} }
*/
bltcon0 = BLTCON0(0xf0, 1, 0, 0, 1, shift); bltcon0 = BLTCON0(0xf0, 1, 0, 0, 1, shift);
bltcon1 = BLTCON1(bunClear->direction, shift); bltcon1 = BLTCON1(bunClear->direction, shift);
@ -130,10 +161,14 @@ void bun_offLeftSide(
bunClear->widthWords = 2 - wordShift; bunClear->widthWords = 2 - wordShift;
bunClear->direction = BLITTER_DESCENDING; bunClear->direction = BLITTER_DESCENDING;
bltalwm = bunLeftSide_bltalwmPrecalc[shift];
/*
bltalwm = 0x0000; bltalwm = 0x0000;
for (i = 0; i <= 15 - shift; ++i) { for (i = 0; i <= 15 - shift; ++i) {
bltalwm += (1 << i); bltalwm += (1 << i);
} }
*/
bltcon0 = BLTCON0(0xf0, 1, 0, 0, 1, shift); bltcon0 = BLTCON0(0xf0, 1, 0, 0, 1, shift);
bltcon1 = BLTCON1(bunClear->direction, shift); bltcon1 = BLTCON1(bunClear->direction, shift);
@ -215,6 +250,8 @@ void bun_anywhere(
} }
} }
#define ENABLE_RENDER_BUN_CHECKING (0)
void renderBun( void renderBun(
int x, int x,
int y, int y,
@ -224,14 +261,17 @@ void renderBun(
) { ) {
/** /**
* Conditions that will cause the program to crash if met. If your bun * Conditions that will cause the program to crash if met. If your bun
* isn't rendering, it's due to here. * isn't rendering, it's due to here. Turn off checking once you know
* everything is solid to save some CPU.
* *
* TODO: Handle top/bottom off-screen as well. * TODO: Handle top/bottom off-screen as well.
*/ */
if (x < -31) return; if (ENABLE_RENDER_BUN_CHECKING) {
if (x > screenDefinition->width + 31) return; if (x < -31) return;
if (y < 1) return; if (x > screenDefinition->width + 31) return;
if (y > screenDefinition->height - COOL_BUN_HEIGHT - 1) return; if (y < 1) return;
if (y > screenDefinition->height - COOL_BUN_HEIGHT - 1) return;
}
if (x < 0) { if (x < 0) {
bun_offLeftSide( bun_offLeftSide(
@ -348,6 +388,7 @@ void setupBunRenderer(
buildBunAngleAdjustments(); buildBunAngleAdjustments();
calculateAllBunPositions(screenDefinition); calculateAllBunPositions(screenDefinition);
precalculateBunRenderInfo(); precalculateBunRenderInfo();
precalculateBunBLTALWM();
} }
/** /**

7
main.c
View File

@ -30,8 +30,11 @@
#include "bun.h" #include "bun.h"
/** /**
* This barely gets 50fps but I'm leaving it for now. Potential improvements: * This barely gets 50fps on an A1200 but I'm leaving it for now. Potential improvements:
* *
* [ ] Precalculate even more of bun.c. This may get 50fps on an A500 if I do this.
* It would require more significant caching of as much stuff as possible.
* The A500 is spending entirely too much time on CPU tasks.
* [ ] Topaz re-rendering is limited to squares or rows that changed in the last frame. * [ ] Topaz re-rendering is limited to squares or rows that changed in the last frame.
* I tried this once but I need a more precise way of redrawing those areas. * I tried this once but I need a more precise way of redrawing those areas.
* [ ] Cool bun clears and re-renders happen in the same pass. * [ ] Cool bun clears and re-renders happen in the same pass.
@ -368,7 +371,7 @@ int main(void) {
if ((ciaa.ciapra >> 6) != 3) break; if ((ciaa.ciapra >> 6) != 3) break;
i++; i++;
i %= FRAMES_FOR_SCREEN; if (i > FRAMES_FOR_SCREEN) i = 0;
} }
giveBackSystem(); giveBackSystem();

View File

@ -21,6 +21,7 @@ void allocateDoubleBufferedScreenMemory(
uint8_t bitplanes uint8_t bitplanes
) { ) {
unsigned char *memory; unsigned char *memory;
int buffer, plane;
screenDefinition->width = width; screenDefinition->width = width;
screenDefinition->height = height; screenDefinition->height = height;
@ -38,6 +39,14 @@ void allocateDoubleBufferedScreenMemory(
screenDefinition->nextBitplaneAdvance = screenDefinition->byteWidth * height; screenDefinition->nextBitplaneAdvance = screenDefinition->byteWidth * height;
screenDefinition->nextBufferAdvance = screenDefinition->nextBitplaneAdvance * bitplanes; screenDefinition->nextBufferAdvance = screenDefinition->nextBitplaneAdvance * bitplanes;
for (buffer = 0; buffer < 2; ++buffer) {
for (plane = 0; plane < bitplanes; ++plane) {
screenDefinition->bufferPlanes[buffer][plane] = screenDefinition->memoryStart +
buffer * screenDefinition->nextBufferAdvance +
plane * screenDefinition->nextBitplaneAdvance;
}
}
setActiveScreenBuffer(screenDefinition, activeScreenBufferDetails, 0); setActiveScreenBuffer(screenDefinition, activeScreenBufferDetails, 0);
} }
@ -59,9 +68,7 @@ void setActiveScreenBuffer(
currentScreen->currentBuffer = buffer; currentScreen->currentBuffer = buffer;
for (plane = 0; plane < screenDefinition->bitplanes; ++plane) { for (plane = 0; plane < screenDefinition->bitplanes; ++plane) {
currentScreen->planes[plane] = screenDefinition->memoryStart + currentScreen->planes[plane] = screenDefinition->bufferPlanes[buffer][plane];
buffer * screenDefinition->nextBufferAdvance +
plane * screenDefinition->nextBitplaneAdvance;
} }
} }

View File

@ -17,6 +17,7 @@ struct ScreenDefinition {
uint16_t byteWidth; uint16_t byteWidth;
uint16_t nextBitplaneAdvance; uint16_t nextBitplaneAdvance;
uint16_t nextBufferAdvance; uint16_t nextBufferAdvance;
unsigned char *bufferPlanes[2][8];
}; };
struct ActiveScreenBufferDetails { struct ActiveScreenBufferDetails {