Skip to content

Commit

Permalink
Clean up CopList interface (backported from 839fddd)
Browse files Browse the repository at this point in the history
 * Replace CopInit with CopListReset.
 * NewCopList initialises the list by default (as if CopListReset was called).
 * Replace CopEnd with CopListFinish that returns copper list pointer.
 * Clean up MakeCopperList in the effects.
 * Panic if used more copper list entries than available.
 * Fix double buffering in some effects.
  • Loading branch information
cahirwpz committed Dec 16, 2023
1 parent a015394 commit 0bc9420
Show file tree
Hide file tree
Showing 54 changed files with 337 additions and 389 deletions.
9 changes: 4 additions & 5 deletions effects/anim-polygons/anim-polygons.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ static short maybeSkipFrame = 0;
/* Reading polygon data */
static short current_frame = 0;

static void MakeCopperList(CopListT *cp) {
CopInit(cp);
static CopListT *MakeCopperList(void) {
CopListT *cp = NewCopList(100 + gradient.height * (gradient.width + 1));
bplptr = CopSetupBitplanes(cp, screen, DEPTH);
{
short *pixels = gradient.pixels;
Expand All @@ -37,7 +37,7 @@ static void MakeCopperList(CopListT *cp) {
for (j = 0; j < 16; j++) CopSetColor(cp, j, *pixels++);
}
}
CopEnd(cp);
return CopListFinish(cp);
}

static void Init(void) {
Expand All @@ -46,8 +46,7 @@ static void Init(void) {
BitmapClear(screen);

SetupPlayfield(MODE_LORES, DEPTH, X(0), Y(YOFF), WIDTH, HEIGHT);
cp = NewCopList(100 + gradient.height * (gradient.width + 1));
MakeCopperList(cp);
cp = MakeCopperList();
CopListActivate(cp);
EnableDMA(DMAF_RASTER);
}
Expand Down
17 changes: 5 additions & 12 deletions effects/anim/anim.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,21 @@ typedef struct {
#include "data/running-pal.c"
#include "data/running.c"

static void Load(void) {
screen = NewBitmap(WIDTH, HEIGHT, DEPTH + 1, BM_CLEAR);
static void Init(void) {
screen = NewBitmap(WIDTH, HEIGHT, DEPTH + 1, 0);

Log("Animation has %d frames %d x %d.\n",
running.count, running.width, running.height);
}

static void UnLoad(void) {
DeleteBitmap(screen);
}

static void Init(void) {
EnableDMA(DMAF_BLITTER);
BitmapClear(screen);

SetupPlayfield(MODE_LORES, DEPTH, X(0), Y(0), WIDTH, HEIGHT);
LoadPalette(&running_pal, 0);

cp = NewCopList(100);
CopInit(cp);
bplptr = CopSetupBitplanes(cp, screen, DEPTH);
CopEnd(cp);

CopListFinish(cp);
CopListActivate(cp);
EnableDMA(DMAF_RASTER);
}
Expand All @@ -54,6 +46,7 @@ static void Kill(void) {
DisableDMA(DMAF_COPPER | DMAF_RASTER | DMAF_BLITTER);

DeleteCopList(cp);
DeleteBitmap(screen);
}

static void DrawSpans(u_char *bpl) {
Expand Down Expand Up @@ -109,4 +102,4 @@ static void Render(void) {
active = (active + 1) % (DEPTH + 1);
}

EFFECT(Anim, Load, UnLoad, Init, Kill, Render, NULL);
EFFECT(Anim, NULL, NULL, Init, Kill, Render, NULL);
38 changes: 16 additions & 22 deletions effects/ball/ball.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ static PixmapT *chunky;
static BitmapT *bitmap;
static SprDataT *sprdat;
static SpriteT sprite[2][8];
static CopInsPairT *sprptr;

#include "data/dragon-bg.c"
#include "data/texture-15.c"
#include "data/ball.c"

static u_short active = 0;
static CopListT *cp;
static short active = 0;
static CopListT *cp[2];

#define UVMapRenderSize (WIDTH * HEIGHT / 2 * 10 + 2)
void (*UVMapRender)(u_char *chunky asm("a0"),
Expand Down Expand Up @@ -79,18 +78,15 @@ static void MakeUVMapRenderCode(void) {
*code++ = 0x4e75; /* rts */
}

static void MakeCopperList(CopListT *cp) {
CopInit(cp);
CopSetupBitplanes(cp, &background, S_DEPTH);
sprptr = CopSetupSprites(cp);
CopEnd(cp);

{
short i;
static CopListT *MakeCopperList(int active) {
CopListT *cp = NewCopList(80);
CopInsPairT *sprptr = CopSetupSprites(cp);
short i;

for (i = 0; i < 8; i++)
CopInsSetSprite(&sprptr[i], &sprite[active][i]);
}
CopSetupBitplanes(cp, &background, S_DEPTH);
for (i = 0; i < 8; i++)
CopInsSetSprite(&sprptr[i], &sprite[active][i]);
return CopListFinish(cp);
}

static void Init(void) {
Expand Down Expand Up @@ -127,17 +123,18 @@ static void Init(void) {
LoadPalette(&background_pal, 0);
LoadPalette(&texture_pal, 16);

cp = NewCopList(80);
MakeCopperList(cp);
CopListActivate(cp);
cp[0] = MakeCopperList(0);
cp[1] = MakeCopperList(1);
CopListActivate(cp[0]);

EnableDMA(DMAF_RASTER | DMAF_SPRITE);
}

static void Kill(void) {
DisableDMA(DMAF_COPPER | DMAF_RASTER | DMAF_BLITTER | DMAF_SPRITE);

DeleteCopList(cp);
DeleteCopList(cp[0]);
DeleteCopList(cp[1]);
DeletePixmap(textureHi);
DeletePixmap(textureLo);
MemFree(UVMapRender);
Expand Down Expand Up @@ -308,7 +305,6 @@ static void BitmapToSprite(BitmapT *input, SpriteT sprite[8]) {
static void PositionSprite(SpriteT sprite[8], short xo, short yo) {
short x = X((S_WIDTH - WIDTH) / 2) + xo;
short y = Y((S_HEIGHT - HEIGHT) / 2) + yo;
CopInsPairT *ptr = sprptr;
short n = 4;

while (--n >= 0) {
Expand All @@ -318,9 +314,6 @@ static void PositionSprite(SpriteT sprite[8], short xo, short yo) {
SpriteUpdatePos(spr0, x, y);
SpriteUpdatePos(spr1, x, y);

CopInsSetSprite(ptr++, spr0);
CopInsSetSprite(ptr++, spr1);

x += 16;
}
}
Expand All @@ -340,6 +333,7 @@ static void Render(void) {
ChunkyToPlanar(chunky, bitmap);
BitmapToSprite(bitmap, sprite[active]);
PositionSprite(sprite[active], xo / 2, yo / 2);
CopListActivate(cp[active]);
}
ProfilerStop(UVMapRender);

Expand Down
9 changes: 4 additions & 5 deletions effects/blurred/blurred.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ static CopListT *cp;

static short iterCount = 0;

static void MakeCopperList(CopListT *cp) {
static CopListT *MakeCopperList(void) {
CopListT *cp = NewCopList(200);
short i;

CopInit(cp);
bplptr[0] = CopSetupBitplanes(cp, screen[active], DEPTH);
CopWait(cp, Y(-18), 0);
CopLoadPal(cp, &blurred_1_pal, 0);
Expand All @@ -43,7 +43,7 @@ static void MakeCopperList(CopListT *cp) {
if (bplptr[1])
bplptr[1] = ins;
}
CopEnd(cp);
return CopListFinish(cp);
}

static void Init(void) {
Expand All @@ -70,8 +70,7 @@ static void Init(void) {

SetupPlayfield(MODE_LORES, DEPTH, X(0), Y(0), WIDTH, HEIGHT);

cp = NewCopList(200);
MakeCopperList(cp);
cp = MakeCopperList();
CopListActivate(cp);
EnableDMA(DMAF_RASTER);
}
Expand Down
9 changes: 4 additions & 5 deletions effects/blurred3d/blurred3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ static void UnLoad(void) {
ResetMesh3D(mesh);
}

static void MakeCopperList(CopListT *cp) {
CopInit(cp);
static CopListT *MakeCopperList(void) {
CopListT *cp = NewCopList(80 + gradient.height * (gradient.width + 1));
bplptr = CopSetupBitplanes(cp, screen[0], DEPTH);

{
Expand All @@ -62,7 +62,7 @@ static void MakeCopperList(CopListT *cp) {
}
}

CopEnd(cp);
return CopListFinish(cp);
}

static void Init(void) {
Expand All @@ -78,8 +78,7 @@ static void Init(void) {

SetupPlayfield(MODE_LORES, DEPTH, X(STARTX), Y(STARTY), WIDTH, HEIGHT * 5 / 4);

cp = NewCopList(80 + gradient.height * (gradient.width + 1));
MakeCopperList(cp);
cp = MakeCopperList();
CopListActivate(cp);
EnableDMA(DMAF_RASTER);
}
Expand Down
9 changes: 4 additions & 5 deletions effects/bobs3d/bobs3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ static int active = 0;

static Mesh3D *mesh = &pilka;

static void MakeCopperList(CopListT *cp) {
CopInit(cp);
static CopListT *MakeCopperList(void) {
CopListT *cp = NewCopList(80);
CopWait(cp, Y(-1), 0);
bplptr = CopSetupBitplanes(cp, screen[1], DEPTH);
CopEnd(cp);
return CopListFinish(cp);
}

static void Init(void) {
Expand All @@ -38,8 +38,7 @@ static void Init(void) {
SetupPlayfield(MODE_LORES, DEPTH, X(32), Y(0), WIDTH, HEIGHT);
LoadPalette(&bobs_pal, 0);

cp = NewCopList(80);
MakeCopperList(cp);
cp = MakeCopperList();
CopListActivate(cp);
EnableDMA(DMAF_RASTER | DMAF_BLITTER | DMAF_BLITHOG);
}
Expand Down
9 changes: 4 additions & 5 deletions effects/bumpmap-rgb/bumpmap-rgb.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ static void ChunkyToPlanar(void) {
ClearIRQ(INTF_BLIT);
}

static void MakeCopperList(CopListT *cp) {
static CopListT *MakeCopperList(void) {
CopListT *cp = NewCopList(1200);
short i;

CopInit(cp);
bplptr = CopSetupBitplanes(cp, screen[active], DEPTH);
CopLoadColor(cp, 0, 15, 0);
for (i = 0; i < HEIGHT * 4; i++) {
Expand All @@ -279,7 +279,7 @@ static void MakeCopperList(CopListT *cp) {
/* Alternating shift by one for bitplane data. */
CopMove16(cp, bplcon1, (i & 1) ? 0x0022 : 0x0000);
}
CopEnd(cp);
return CopListFinish(cp);
}

static void Init(void) {
Expand All @@ -299,8 +299,7 @@ static void Init(void) {
custom->bpldat[4] = 0x7777; // rgbb: 0111
custom->bpldat[5] = 0xcccc; // rgbb: 1100

cp = NewCopList(1200);
MakeCopperList(cp);
cp = MakeCopperList();
CopListActivate(cp);

EnableDMA(DMAF_RASTER);
Expand Down
4 changes: 1 addition & 3 deletions effects/butterfly-gears/butterfly-gears.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ static void InitCopperListBall(CopListT *cp, int y, int yInc) {

static void MakeBallCopperList(BallCopListT *ballCp) {
CopListT *cp = NewCopList(INSTRUCTIONS_PER_BALL * 2 + 100);
ballCp->cp = cp;
CopInit(cp);
CopMove16(cp, dmacon, DMAF_SETCLR | DMAF_RASTER);
CopLoadPal(cp, &testscreen_pal, 0);
CopSetupBitplanes(cp, &testscreen, testscreen.depth);
Expand All @@ -117,7 +115,7 @@ static void MakeBallCopperList(BallCopListT *ballCp) {
ballCp->lowestBallCopper = cp->curr;
InitCopperListBall(cp, Y0 + 166, 1);

CopEnd(cp);
ballCp->cp = CopListFinish(cp);
}

static void Init(void) {
Expand Down
5 changes: 2 additions & 3 deletions effects/circles/circles.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ static CopListT *cp;

static void Init(void) {
screen = NewBitmap(WIDTH, HEIGHT, DEPTH, BM_CLEAR);
cp = NewCopList(100);

SetupPlayfield(MODE_LORES, DEPTH, X(0), Y(0), WIDTH, HEIGHT);
SetColor(0, 0x000);
SetColor(1, 0xfff);

CopInit(cp);
cp = NewCopList(100);
CopSetupBitplanes(cp, screen, DEPTH);
CopEnd(cp);
CopListFinish(cp);

CopListActivate(cp);
EnableDMA(DMAF_RASTER);
Expand Down
25 changes: 13 additions & 12 deletions effects/credits/credits.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
#define DEPTH 4

static BitmapT *foreground;
static CopListT *cp0, *cp1;
static CopListT *cp[2];
static const BitmapT *lower;
static const PaletteT *lower_pal;
static Point2D lower_pos;
static Area2D lower_area;
static short active = 0;

/* 'credits_logo' and 'txt_*' must have empty 16 pixels on the left and on the
* right. Otherwise Display Data Fetcher will show some artifact when image
Expand Down Expand Up @@ -53,7 +54,7 @@ static const BitmapT *member[5] = {
#define FLOOR_Y Y(64)

static void MakeCopperList(CopListT *cp) {
CopInit(cp);
CopListReset(cp);
CopSetupDisplayWindow(cp, MODE_LORES, X(0), Y(0), 320, 256);
CopMove16(cp, dmacon, DMAF_RASTER);

Expand Down Expand Up @@ -112,7 +113,7 @@ static void MakeCopperList(CopListT *cp) {
CopMove16(cp, dmacon, DMAF_RASTER);
}

CopEnd(cp);
CopListFinish(cp);
}

static void Init(void) {
Expand All @@ -122,17 +123,17 @@ static void Init(void) {

lower = NULL;

cp0 = NewCopList(300);
cp1 = NewCopList(300);
MakeCopperList(cp0);
CopListActivate(cp0);
cp[0] = NewCopList(300);
cp[1] = NewCopList(300);
MakeCopperList(cp[0]);
CopListActivate(cp[0]);
EnableDMA(DMAF_RASTER | DMAF_BLITTER | DMAF_BLITHOG);
}

static void Kill(void) {
DisableDMA(DMAF_RASTER | DMAF_BLITTER | DMAF_BLITHOG);
DeleteCopList(cp0);
DeleteCopList(cp1);
DeleteCopList(cp[0]);
DeleteCopList(cp[1]);
DeleteBitmap(foreground);
}

Expand Down Expand Up @@ -180,10 +181,10 @@ static void Render(void) {
lower = NULL;
}

MakeCopperList(cp1);
CopListRun(cp1);
MakeCopperList(cp[active]);
CopListRun(cp[active]);
TaskWaitVBlank();
swapr(cp0, cp1);
active ^= 1;
}

EFFECT(Credits, NULL, NULL, Init, Kill, Render, NULL);
Loading

0 comments on commit 0bc9420

Please sign in to comment.