buns can march
This commit is contained in:
parent
f86ecfb349
commit
b06af2cb4a
4
NOTES.md
4
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
|
||||
|
101
bun.c
101
bun.c
@ -1,3 +1,5 @@
|
||||
#include <math.h>
|
||||
|
||||
// Custom
|
||||
#include <hardware/custom.h>
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
38
bun.h
38
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
|
||||
|
30
bun_test.c
Normal file
30
bun_test.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#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;
|
||||
}
|
57
main.c
57
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,
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user