Clean out that stab at targeted cleanups

I needed to write way more code to get that working right
This commit is contained in:
John Bintz 2024-09-22 06:39:50 -04:00
parent 1dfbec0252
commit 634bdd884e
3 changed files with 18 additions and 303 deletions

37
bun.c
View File

@ -419,42 +419,5 @@ void renderBunFrame(
hasBunClear[bunRenderer->activeScreenBufferDetails->currentBuffer] = 1;
}
void calculateNeededRedrawRanges(
int frame,
uint16_t redrawRanges[BUN_COUNT][4]
) {
int i, sx, sy, ex, ey, tmp;
int thisFrame = frame % FRAMES_FOR_SCREEN;
int lastFrame = (frame + FRAMES_FOR_SCREEN - 1) % FRAMES_FOR_SCREEN;
for (i = 0; i < BUN_COUNT; ++i) {
sx = allBunPositionsByFrame[lastFrame][i][0];
if (
allBunPositionsByFrame[lastFrame][i][1] <
allBunPositionsByFrame[thisFrame][i][1]
) {
sy = allBunPositionsByFrame[lastFrame][i][1];
ey = allBunPositionsByFrame[thisFrame][i][1] + COOL_BUN_HEIGHT;
} else {
sy = allBunPositionsByFrame[thisFrame][i][1];
ey = allBunPositionsByFrame[lastFrame][i][1] + COOL_BUN_HEIGHT;
}
ex = allBunPositionsByFrame[thisFrame][i][0] + COOL_BUN_WIDTH;
if (sx > ex) {
tmp = sx;
sx = ex;
ex = tmp;
}
redrawRanges[i][0] = sx;
redrawRanges[i][1] = sy;
redrawRanges[i][2] = ex;
redrawRanges[i][3] = ey;
}
}
void teardownBunRenderer() {
}

266
main.c
View File

@ -94,6 +94,7 @@ void renderTopaz(void) {
}
}
#define MOSTLY_TOPAZ_TOP_BOTTOM_CROP (30)
void renderMostlyTopaz(void) {
int plane;
@ -110,15 +111,15 @@ void renderMostlyTopaz(void) {
custom.bltcon1 = 0;
custom.bltafwm = 0xffff;
custom.bltalwm = 0xffff;
custom.bltapt = MaskBitplane + (30 * TOPAZ_WIDTH_BYTES);
custom.bltbpt = bltbpt + (30 * TOPAZ_WIDTH_BYTES);
custom.bltcpt = 30 * screenDefinition.byteWidth + activeScreenBufferDetails.planes[plane] + 8;
custom.bltdpt = 30 * screenDefinition.byteWidth + activeScreenBufferDetails.planes[plane] + 8;
custom.bltapt = MaskBitplane + (MOSTLY_TOPAZ_TOP_BOTTOM_CROP * TOPAZ_WIDTH_BYTES);
custom.bltbpt = bltbpt + (MOSTLY_TOPAZ_TOP_BOTTOM_CROP * TOPAZ_WIDTH_BYTES);
custom.bltcpt = MOSTLY_TOPAZ_TOP_BOTTOM_CROP * screenDefinition.byteWidth + activeScreenBufferDetails.planes[plane] + 8;
custom.bltdpt = MOSTLY_TOPAZ_TOP_BOTTOM_CROP * screenDefinition.byteWidth + activeScreenBufferDetails.planes[plane] + 8;
custom.bltamod = 0;
custom.bltbmod = 0;
custom.bltcmod = bltcmod;
custom.bltdmod = bltcmod;
custom.bltsize = BLTSIZE(TOPAZ_WIDTH_WORDS, 196);
custom.bltsize = BLTSIZE(TOPAZ_WIDTH_WORDS, 256 - MOSTLY_TOPAZ_TOP_BOTTOM_CROP * 2);
bltbpt += TOPAZ_WIDTH_BYTES * 256;
@ -213,189 +214,13 @@ void buildCopperlist(void) {
endCopperlist(currentCopperlist);
}
uint16_t renderPartialAreas[BUN_COUNT][5];
void calculateTopazRenderPartialAreas(
uint16_t redrawRanges[BUN_COUNT][4]
) {
int topazX;
uint16_t i, width, height, screenX;
for (i = 0; i < BUN_COUNT; ++i) {
renderPartialAreas[i][0] = 0;
if (redrawRanges[i][2] - redrawRanges[i][0] < TOPAZ_WIDTH_PIXELS) {
if (
(redrawRanges[i][2] > 64 && redrawRanges[i][0] < (64 + TOPAZ_WIDTH_PIXELS)) ||
(redrawRanges[i][0] < (64 + TOPAZ_WIDTH_PIXELS) && redrawRanges[i][2] > 64)
) {
width = redrawRanges[i][2] - redrawRanges[i][0] + 16;
height = redrawRanges[i][3] - redrawRanges[i][1];
topazX = redrawRanges[i][0] - 64;
screenX = redrawRanges[i][0];
if (topazX < 0) {
//printf("Too far left, adjusting...\n");
topazX += 16;
screenX += 16;
width -= 16;
}
if (topazX + width > 64 + TOPAZ_WIDTH_PIXELS) {
//printf("Too far right, adjusting...\n");
width -= 16;
}
renderPartialAreas[i][0] = width;
renderPartialAreas[i][1] = height;
renderPartialAreas[i][2] = topazX;
renderPartialAreas[i][3] = screenX;
renderPartialAreas[i][4] = redrawRanges[i][1];
}
}
}
}
void calculateTopazRenderPartialBlitterSettings() {
uint16_t bltapt, bltcpt, bltamod, bltcmod, bltsize;
int i;
for (i = 0; i < BUN_COUNT; ++i) {
if (renderPartialAreas[i][0] == 0) continue;
bltapt = renderPartialAreas[i][4] * TOPAZ_WIDTH_BYTES + (renderPartialAreas[i][2] >> 4) * 2;
bltcpt = renderPartialAreas[i][4] * screenDefinition.byteWidth + (renderPartialAreas[i][3] >> 4) * 2;
printf("%d, %d\n", screenDefinition.byteWidth, renderPartialAreas[i][0]);
bltamod = TOPAZ_WIDTH_BYTES - (renderPartialAreas[i][0] >> 4) * 2;
bltcmod = screenDefinition.byteWidth - (renderPartialAreas[i][0] >> 4) * 2;
bltsize = BLTSIZE((renderPartialAreas[i][0] >> 4), renderPartialAreas[i][1]);
renderPartialAreas[i][0] = bltapt;
renderPartialAreas[i][1] = bltcpt;
renderPartialAreas[i][2] = bltamod;
renderPartialAreas[i][3] = bltcmod;
renderPartialAreas[i][4] = bltsize;
}
}
void renderTopazPartials(
uint16_t redrawRanges[BUN_COUNT][4]
) {
int plane, i, topazX, screenX;
uint16_t bltcon0;
uint16_t bltamod, bltbmod, bltcmod, bltdmod;
uint16_t width, height, bltsize;
uint32_t bltapt, bltbpt, bltcpt, bltdpt;
bltcon0 = 0xca + (1 << 8) + (1 << 9) + (1 << 10) + (1 << 11);
WaitTOF();
for (i = 0; i < BUN_COUNT; ++i) {
if (redrawRanges[i][2] - redrawRanges[i][0] < TOPAZ_WIDTH_PIXELS) {
if (
(redrawRanges[i][2] > 64 && redrawRanges[i][0] < (64 + TOPAZ_WIDTH_PIXELS)) ||
(redrawRanges[i][0] < (64 + TOPAZ_WIDTH_PIXELS) && redrawRanges[i][2] > 64)
) {
width = redrawRanges[i][2] - redrawRanges[i][0] + 16;
height = redrawRanges[i][3] - redrawRanges[i][1];
topazX = redrawRanges[i][0] - 64;
screenX = redrawRanges[i][0];
if (topazX < 0) {
//printf("Too far left, adjusting...\n");
topazX += 16;
screenX += 16;
width -= 16;
}
if (topazX + width > 64 + TOPAZ_WIDTH_PIXELS) {
//printf("Too far right, adjusting...\n");
width -= 16;
}
bltapt = redrawRanges[i][1] * TOPAZ_WIDTH_BYTES + (topazX >> 4) * 2;
bltbpt = bltapt;
bltcpt = redrawRanges[i][1] * screenDefinition.byteWidth + (screenX >> 4) * 2;
bltdpt = bltcpt;
bltamod = TOPAZ_WIDTH_BYTES - (width >> 4) * 2;
bltbmod = bltamod;
bltcmod = screenDefinition.byteWidth - (width >> 4) * 2;
bltdmod = bltcmod;
bltsize = BLTSIZE((width >> 4), height);
/*
printf(
"Coords: %d, %d -> %d, %d\n",
redrawRanges[i][0],
redrawRanges[i][1],
redrawRanges[i][2],
redrawRanges[i][3]
);
printf("topazX: %d\n", topazX);
printf("width: %d\n", width);
printf("MaskBitplane: %d\n", MaskBitplane);
printf("TopazBitplanes: %d\n", TopazBitplanes);
printf("ActiveScreenBuffer Plane 0: %d\n", activeScreenBufferDetails.planes[0]);
printf("BLTAPT: %d\n", bltapt);
printf("BLTAPT src: %d\n", bltapt + (uint32_t)MaskBitplane);
printf("BLTBPT: %d\n", bltbpt);
printf("BLTBPT src: %d\n", bltbpt + (uint32_t)TopazBitplanes);
printf("BLTCPT: %d\n", bltcpt);
printf("BLTCPT src: %d\n", bltcpt + (uint32_t)activeScreenBufferDetails.planes[0] + 8);
printf("BLTDPT: %d\n", bltdpt);
printf("BLTDPT src: %d\n", bltdpt + (uint32_t)activeScreenBufferDetails.planes[0] + 8);
printf("BLTAMOD: %d\n", bltamod);
printf("BLTBMOD: %d\n", bltbmod);
printf("BLTCMOD: %d\n", bltcmod);
printf("BLTDMOD: %d\n", bltdmod);
printf("BLTSIZE: %d, %d\n", (width >> 4), height);
*/
bltapt += (uint32_t)MaskBitplane;
bltbpt += (uint32_t)TopazBitplanes;
for (plane = 0; plane < 2; ++plane) {
custom.bltcon0 = bltcon0;
custom.bltcon1 = 0;
custom.bltafwm = 0xffff;
custom.bltalwm = 0xffff;
custom.bltapt = bltapt;
custom.bltbpt = bltbpt + (plane * TOPAZ_WIDTH_BYTES * 256);
custom.bltcpt = bltcpt + activeScreenBufferDetails.planes[plane];
custom.bltdpt = bltdpt + activeScreenBufferDetails.planes[plane];
custom.bltamod = bltamod;
custom.bltbmod = bltbmod;
custom.bltcmod = bltcmod;
custom.bltdmod = bltdmod;
custom.bltsize = bltsize;
WaitBlit();
}
break;
}
}
}
}
static struct MsgPort *keyboardMessagePort = NULL;
static struct IOStdReq *keyboardIO = NULL;
static struct Interrupt keyboardInterrupt;
extern far ULONG keyboardPressed;
extern struct InputEvent * __asm stupidKeyboardHandler(
extern struct InputEvent * __asm KeyboardHandler(
register __a0 struct InputEvent *input,
register __a1 APTR id
);
@ -416,7 +241,7 @@ void setupKeyboard(void) {
keyboardInterrupt.is_Node.ln_Type = NT_INTERRUPT;
keyboardInterrupt.is_Node.ln_Pri = 100;
keyboardInterrupt.is_Node.ln_Name = (STRPTR)"cool bun";
keyboardInterrupt.is_Code = (void (*)())&stupidKeyboardHandler;
keyboardInterrupt.is_Code = (void (*)())&KeyboardHandler;
keyboardIO->io_Data = (void *)&keyboardInterrupt;
keyboardIO->io_Command = IND_ADDHANDLER;
@ -449,62 +274,6 @@ int main(void) {
struct BunRenderer bunRenderer;
uint16_t redrawRanges[BUN_COUNT][4];
/*
allocateDoubleBufferedScreenMemory(
&screenDefinition,
&activeScreenBufferDetails,
SCREEN_WIDTH,
SCREEN_HEIGHT,
3
);
setupBunRenderer(
&bunRenderer,
&screenDefinition,
&activeScreenBufferDetails
);
calculateNeededRedrawRanges(i, redrawRanges);
calculateTopazRenderPartialAreas(redrawRanges);
printf("********\n");
for (i = 0; i < BUN_COUNT; ++i) {
if (renderPartialAreas[i][0] == 0) continue;
printf(
"%d, %d, %d, %d, %d\n",
renderPartialAreas[i][0],
renderPartialAreas[i][1],
renderPartialAreas[i][2],
renderPartialAreas[i][3],
renderPartialAreas[i][4]
);
}
calculateTopazRenderPartialBlitterSettings();
printf("********\n");
for (i = 0; i < BUN_COUNT; ++i) {
if (renderPartialAreas[i][0] == 0) continue;
printf(
"%d, %d, %d, %d, %x\n",
renderPartialAreas[i][0],
renderPartialAreas[i][1],
renderPartialAreas[i][2],
renderPartialAreas[i][3],
renderPartialAreas[i][4]
);
}
teardownScreen(&screenDefinition);
return 0;
*/
printf("\nCool bun blitter, copper, and sprite demo by John Bintz\n");
printf("\n");
printf("This is my first real go at writing graphics code for the Amiga.\n");
@ -543,8 +312,6 @@ int main(void) {
buildCopperlist();
/*
copperlist debugging
for (i = 0; i < 20; ++i) {
@ -581,32 +348,17 @@ int main(void) {
swapCurrentScreenBuffer(&screenDefinition, &activeScreenBufferDetails);
clearCurrentBuns(&bunRenderer);
renderBunFrame(i, &bunRenderer);
/*
calculateNeededRedrawRanges(i, redrawRanges);
renderTopazPartials(redrawRanges);
*/
renderMostlyTopaz();
//WaitTOF();
updateDisplayInCopperList(
&screenDefinition,
&activeScreenBufferDetails,
copperlistBitplanePointers
);
//WaitBOF(100);
//WaitTOF();
if (keyboardPressed) {
i++;
}
if (keyboardPressed) break;
if ((ciaa.ciapra >> 6) != 3) break;
i++;

View File

@ -9,7 +9,7 @@
XDEF _endCopperlist
XDEF _myWaitBlit
XDEF _WaitBOF
XDEF _stupidKeyboardHandler
XDEF _KeyboardHandler
XDEF _keyboardPressed
@ -82,14 +82,14 @@ SOFFSET SET SOFFSET+(8*4)
; @register A0 struct InputEvent *
; @register A1 extra data about the event
; @output D0 The value of A0
_stupidKeyboardHandler:
_KeyboardHandler:
; @stack [RA,A0,current node]
MOVE.L A0,-(SP)
MOVE.L #0,-(SP)
_stupidKeyboardHandler_CheckLoop:
_KeyboardHandler_CheckLoop:
CMP.B #IECLASS_RAWKEY,ie_Class(A0)
BNE.S _stupidKeyboardHandler_NextEvent
BNE.S _KeyboardHandler_NextEvent
MOVE.W ie_Code(A0),D0
AND.W #IECODE_UP_PREFIX,D0
@ -100,12 +100,12 @@ _stupidKeyboardHandler_CheckLoop:
; else:
; change the A0 in the stack above it
TST.L (SP)
BNE.S _stupidKeyboardHandler_hasLastEvent
BNE.S _KeyboardHandler_hasLastEvent
MOVE.L (A0),4(SP)
BRA.S _stupidKeyboardHandler_NextEvent
BRA.S _KeyboardHandler_NextEvent
_stupidKeyboardHandler_hasLastEvent:
_KeyboardHandler_hasLastEvent:
; put the next event in the first pointer of the
; last event
MOVE.L A1,-(SP)
@ -113,14 +113,14 @@ _stupidKeyboardHandler_hasLastEvent:
MOVE.L (A0),(A1)
MOVE.L (SP)+,A1
_stupidKeyboardHandler_NextEvent:
_KeyboardHandler_NextEvent:
; next event is in first long of struct
MOVE.L (A0),D0
; store current node in stack
MOVE.L A0,(SP)
MOVE.L D0,A0
BNE.S _stupidKeyboardHandler_CheckLoop
BNE.S _KeyboardHandler_CheckLoop
MOVE.L (SP)+,D0
MOVE.L (SP)+,D0
RTS