diff --git a/NOTES.md b/NOTES.md index d22c3ea..bd2475e 100644 --- a/NOTES.md +++ b/NOTES.md @@ -1,3 +1 @@ -Left off at implementing asm routine for injecting point in -copperlist ram where bitplane pointers are going for -easy replacement for double buffering. +* [ ] Move bun calculation to separate file for CuTest and vamos diff --git a/bun.c b/bun.c index 8c6ccd9..2dd2bce 100644 --- a/bun.c +++ b/bun.c @@ -1,3 +1,5 @@ +#include + // Custom #include @@ -193,3 +195,102 @@ void renderBun( } } +short int allBunPositionsByFrame[FRAMES_FOR_SCREEN][BUN_COUNT][2]; + +void calculateAllBunPositions( + struct ScreenSetup *screenSetup +) { + int frame; + + for (frame = 0; frame < FRAMES_FOR_SCREEN; ++frame) { + calculateBunPositions( + frame, + allBunPositionsByFrame[frame], + screenSetup + ); + } +} + +#define MAX_SINE_WAVE_CHANGE (20) + +int bunAngleAdjustments[BUN_COUNT]; + +void buildBunAngleAdjustments() { + int row, column, current, angleAdjustment; + for (current = 0; current < BUN_COUNT; ++current) { + angleAdjustment = 0; + if (current % 2 == 1) angleAdjustment += 180; + if (current / 4 == 1) angleAdjustment += 90; + + bunAngleAdjustments[current] = angleAdjustment; + } +} + +void calculateBunPositions( + uint16_t frame, + short int bunPositions[BUN_COUNT][2], + struct ScreenSetup *screenSetup +) { + int x, y, row, column, current; + float angle, startAngle; + + frame %= FRAMES_FOR_SCREEN; + + startAngle = (float)(frame % BUN_WAVE_LENGTH) * 360 / BUN_WAVE_LENGTH; + + for (current = 0; current < BUN_COUNT; ++current) { + row = current / 4; + column = current % 4; + angle = startAngle + bunAngleAdjustments[current]; + + x = column * BUN_TOTAL_HORIZ_DISTANCE + ((float)frame * BUN_MAX_RANGE / FRAMES_FOR_SCREEN); + if (row == 1) { + x += BUN_TOTAL_HORIZ_DISTANCE / 2; + } + x %= BUN_MAX_RANGE; + x -= 31; + + angle = angle * PI / 180; + + y = BUN_ROW_START + + row * BUN_TOTAL_VERT_DISTANCE + + sin(angle) * MAX_SINE_WAVE_CHANGE; + + bunPositions[current][0] = x; + bunPositions[current][1] = y; + } +} + +void setupBunRenderer( + struct BunRenderer *bunRenderer, + struct ScreenSetup *screenSetup, + struct CurrentScreen *currentScreen) { + bunRenderer->screenSetup = screenSetup; + bunRenderer->currentScreen = currentScreen; + + setupBun(); + buildBunAngleAdjustments(); + calculateAllBunPositions(screenSetup); +} + +void renderBunFrame( + int frame, + struct BunRenderer *bunRenderer +) { + int bun; + + frame %= FRAMES_FOR_SCREEN; + + for (bun = 0; bun < BUN_COUNT; ++bun) { + renderBun( + allBunPositionsByFrame[frame][bun][0], + allBunPositionsByFrame[frame][bun][1], + bunRenderer->screenSetup, + bunRenderer->currentScreen + ); + } +} + +void teardownBunRenderer() { + teardownBun(); +} diff --git a/bun.h b/bun.h index a275440..8dfc3fe 100644 --- a/bun.h +++ b/bun.h @@ -13,13 +13,47 @@ #define COOL_BUN_PLANE_SIZE (COOL_BUN_WIDTH_BYTES * COOL_BUN_HEIGHT) #define COOL_BUN_MEMORY_SIZE (COOL_BUN_PLANE_SIZE * COOL_BUN_PLANES) -void setupBun(void); +#define BUN_MAX_RANGE (31 + 320) + +#define BUN_COUNT (12) +#define BUN_SPEED (1) + +#define BUN_HORIZ_DISTANCE_BETWEEN_BUNS ((BUN_MAX_RANGE / 4) - COOL_BUN_WIDTH) +#define BUN_TOTAL_HORIZ_DISTANCE (BUN_HORIZ_DISTANCE_BETWEEN_BUNS + COOL_BUN_WIDTH) +#define BUN_ROW_START (30) +#define BUN_VERT_DISTANCE_BETWEEN_BUNS (20) +#define BUN_TOTAL_VERT_DISTANCE (COOL_BUN_HEIGHT + BUN_VERT_DISTANCE_BETWEEN_BUNS) +#define FRAME_MAX (BUN_TOTAL_HORIZ_DISTANCE / BUN_SPEED) + +#define FRAMES_FOR_SCREEN (90) +#define BUN_WAVE_LENGTH (FRAMES_FOR_SCREEN / 2) + +struct BunRenderer { + struct ScreenSetup *screenSetup; + struct CurrentScreen *currentScreen; +}; + +void setupBunRenderer( + struct BunRenderer *, + struct ScreenSetup *, + struct CurrentScreen * +); + +void renderBunFrame( + int frame, + struct BunRenderer * +); + void renderBun( int x, int y, struct ScreenSetup *screenSetup, struct CurrentScreen *currentScreen ); -void teardownBun(void); +void calculateBunPositions( + uint16_t frame, + short int bunPositions[BUN_COUNT][2], + struct ScreenSetup *screenSetup +); #endif diff --git a/bun_test b/bun_test new file mode 100755 index 0000000..0e58ab8 Binary files /dev/null and b/bun_test differ diff --git a/bun_test.c b/bun_test.c new file mode 100644 index 0000000..b89e020 --- /dev/null +++ b/bun_test.c @@ -0,0 +1,30 @@ +#include + +#include "bun.h" +#include "cutest/CuTest.h" + +void *coolbun; + +void TBun_calculateBunPositions(CuTest *tc) { + printf("wow\n"); +} + +CuSuite *BunSuite() { + CuSuite *suite = CuSuiteNew(); + + SUITE_ADD_TEST(suite, TBun_calculateBunPositions); +} + +int main(void) { + CuString *output = CuStringNew(); + CuSuite *suite = CuSuiteNew(); + + CuSuiteAddSuite(suite, BunSuite()); + + CuSuiteRun(suite); + CuSuiteSummary(suite, output); + CuSuiteDetails(suite, output); + printf("%s\n", output->buffer); + + return 0; +} diff --git a/main b/main index 4cb5827..9b30975 100755 Binary files a/main and b/main differ diff --git a/main.c b/main.c index 667cf46..9dbfc8e 100644 --- a/main.c +++ b/main.c @@ -37,52 +37,16 @@ void *copperlistSpritePointers[8]; uint16_t custom_color = (uint16_t)offsetof(Custom, color); uint16_t custom_sprite = (uint16_t)offsetof(Custom, sprpt); -#define BUN_COUNT (12) -#define BUN_SPEED (2) - short int bunPositions[BUN_COUNT][2]; -#define BUN_MAX_RANGE (31 + 320 - 1) - -#define BUN_HORIZ_DISTANCE_BETWEEN_BUNS ((BUN_MAX_RANGE / 4) - COOL_BUN_WIDTH) -#define BUN_TOTAL_HORIZ_DISTANCE (BUN_HORIZ_DISTANCE_BETWEEN_BUNS + COOL_BUN_WIDTH) -#define BUN_ROW_START (10) -#define BUN_VERT_DISTANCE_BETWEEN_BUNS (20) -#define BUN_TOTAL_VERT_DISTANCE (COOL_BUN_HEIGHT + BUN_VERT_DISTANCE_BETWEEN_BUNS) -#define FRAME_MAX (BUN_TOTAL_HORIZ_DISTANCE / BUN_SPEED) - -void calculateBunPositions( - uint16_t frame, - short int bunPositions[BUN_COUNT][2], - struct ScreenSetup *screenSetup -) { - int x, y, row, column, current; - - frame %= FRAME_MAX; - - for (current = 0; current < BUN_COUNT; ++current) { - row = current / 4; - column = current % 4; - - x = column * BUN_TOTAL_HORIZ_DISTANCE + frame * BUN_SPEED; - if (row == 1) { - //x += BUN_TOTAL_HORIZ_DISTANCE / 2; - } - x %= BUN_MAX_RANGE; - x -= 31; - y = BUN_ROW_START + row * BUN_TOTAL_VERT_DISTANCE; - - bunPositions[current][0] = x; - bunPositions[current][1] = y; - } -} - int main(void) { uint16_t *copperlist, *currentCopperlist, result; int i, j, x, y, plane; int blitShiftRight, memoryXOffset, blitWidth; uint32_t wow, wow2; + struct BunRenderer bunRenderer; + color_t colors[8]; colors[0] = 0x09b8; @@ -90,10 +54,14 @@ int main(void) { colors[2] = 0x0fff; colors[3] = 0x000f; + printf("setting up, i haven't crashed...yet.\n"); + setupBun(); setupScreen(&screenSetup, SCREEN_WIDTH, SCREEN_HEIGHT, 3); setupInitialCurrentScreen(&screenSetup, ¤tScreen); + setupBunRenderer(&bunRenderer, &screenSetup, ¤tScreen); + // blitter copy the first bitplane row down to the second copperlist = prepareNewCopperlist(); @@ -138,9 +106,7 @@ int main(void) { endCopperlist(currentCopperlist); - for (i = 0; i < FRAME_MAX * 6; ++i) { - calculateBunPositions(i, bunPositions, &screenSetup); - + for (i = 0; i < 200; ++i) { swapCurrentScreenBuffer(&screenSetup, ¤tScreen); for (plane = 0; plane < 2; ++plane) { @@ -155,14 +121,7 @@ int main(void) { WaitBlit(); } - for (j = 0; j < BUN_COUNT; ++j) { - renderBun( - bunPositions[j][0], - bunPositions[j][1], - &screenSetup, - ¤tScreen - ); - } + renderBunFrame(i, &bunRenderer); updateDisplayInCopperList( &screenSetup, diff --git a/smakefile b/smakefile index 2d770f7..62587b1 100644 --- a/smakefile +++ b/smakefile @@ -12,8 +12,8 @@ system.lib: system/system.o system/copper.o system/blitter.o sc objectlibrary=system.lib system/system.o system/copper.o system/blitter.o main: $(MAIN_OBJS) - sc link to main $(MAIN_OBJS) + sc link to main math=standard $(MAIN_OBJS) -test: blitter_test.o blitter.o system.o - sc link to blitter_test identifierlength=32 math=standard blitter_test.o blitter.o cutest/CuTest.c system.o +test: bun_test.o bun.o + sc link to bun_test identifierlength=32 math=standard bun_test.o bun.o cutest/CuTest.c