2024-04-30 02:12:48 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <clib/exec_protos.h>
|
|
|
|
#include <clib/graphics_protos.h>
|
|
|
|
#include <exec/exec.h>
|
|
|
|
|
|
|
|
#include <hardware/custom.h>
|
|
|
|
#include <hardware/dmabits.h>
|
|
|
|
|
2024-05-27 18:58:13 +00:00
|
|
|
#include <graphics/gfx.h>
|
|
|
|
|
2024-05-27 20:50:56 +00:00
|
|
|
#include "system/blitter.h"
|
|
|
|
#include "system/copper.h"
|
|
|
|
#include "system/system.h"
|
|
|
|
|
2024-05-02 16:52:06 +00:00
|
|
|
#include "screen.h"
|
|
|
|
#include "types.h"
|
2024-04-30 02:12:48 +00:00
|
|
|
|
2024-05-02 16:52:06 +00:00
|
|
|
extern struct Custom far custom;
|
2024-05-27 18:58:13 +00:00
|
|
|
extern unsigned char far coolbun[];
|
2024-04-30 02:12:48 +00:00
|
|
|
|
2024-05-27 18:58:13 +00:00
|
|
|
#define COOL_BUN_WIDTH (32)
|
|
|
|
#define COOL_BUN_WIDTH_BYTES (COOL_BUN_WIDTH / 8)
|
|
|
|
#define COOL_BUN_HEIGHT (32)
|
|
|
|
#define COOL_BUN_PLANES (2)
|
|
|
|
|
|
|
|
#define COOL_BUN_PLANE_SIZE (COOL_BUN_WIDTH_BYTES * COOL_BUN_HEIGHT)
|
|
|
|
#define COOL_BUN_MEMORY_SIZE (COOL_BUN_PLANE_SIZE * COOL_BUN_PLANES)
|
|
|
|
|
|
|
|
// this should be large enough to hold one bitplane of the largest object
|
|
|
|
// you are blitting, plus one additional word on each side
|
|
|
|
#define SCRATCH_AREA_WIDTH_BYTES (8)
|
|
|
|
#define SCRATCH_AREA_HEIGHT_ROWS (34)
|
|
|
|
#define SCRATCH_AREA_MEMORY_SIZE (SCRATCH_AREA_WIDTH_BYTES * SCRATCH_AREA_HEIGHT_ROWS)
|
|
|
|
|
|
|
|
volatile short *dbg = (volatile short *)0x100;
|
|
|
|
|
|
|
|
unsigned char *coolbunArea;
|
|
|
|
unsigned char *scratchArea;
|
|
|
|
struct ScreenSetup screenSetup;
|
|
|
|
|
|
|
|
void bun_offRightSide(int plusXValue, int y) {
|
|
|
|
uint8_t i, plane = 0;
|
|
|
|
uint8_t shift = plusXValue & 15;
|
|
|
|
uint8_t wordShift = (plusXValue >> 4);
|
|
|
|
uint16_t bltalwm;
|
|
|
|
|
|
|
|
for (plane = 0; plane < 2; ++plane) {
|
|
|
|
custom.bltcon0 = 0xc0 + (1 << 8) + (1 << 10) + (shift << 12);
|
|
|
|
custom.bltcon1 = (shift << 12);
|
|
|
|
|
|
|
|
custom.bltadat = 0xffff;
|
2024-05-27 20:50:56 +00:00
|
|
|
custom.bltbpt = coolbunArea + plane * COOL_BUN_PLANE_SIZE;
|
|
|
|
custom.bltdpt = screenSetup.memoryStart + plane * screenSetup.nextBitplaneAdvance + (y * screenSetup.width + screenSetup.width - COOL_BUN_WIDTH) / 8 + wordShift * 2;
|
2024-05-27 18:58:13 +00:00
|
|
|
|
2024-05-27 20:50:56 +00:00
|
|
|
custom.bltafwm = 0xffff;
|
|
|
|
bltalwm = 0x0000;
|
|
|
|
for (i = 0; i < 15 - shift; ++i) {
|
|
|
|
bltalwm += (1 << (15 - i));
|
2024-05-27 18:58:13 +00:00
|
|
|
}
|
|
|
|
custom.bltalwm = bltalwm;
|
|
|
|
|
|
|
|
custom.bltbmod = wordShift * 2;
|
2024-05-27 20:50:56 +00:00
|
|
|
custom.bltdmod = (screenSetup.width - COOL_BUN_WIDTH) / 8 + wordShift * 2;
|
2024-05-27 18:58:13 +00:00
|
|
|
|
2024-05-27 20:50:56 +00:00
|
|
|
custom.bltsize = 2 - wordShift + (COOL_BUN_HEIGHT << 6);
|
2024-05-27 18:58:13 +00:00
|
|
|
|
|
|
|
WaitBlit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bun_offLeftSide(int minusXValue, int y) {
|
|
|
|
unsigned char plane;
|
|
|
|
uint8_t shift = minusXValue & 15;
|
|
|
|
uint8_t wordShift = (minusXValue >> 4);
|
|
|
|
uint8_t i;
|
|
|
|
uint16_t bltalwm;
|
|
|
|
|
2024-05-27 20:50:56 +00:00
|
|
|
// y can't be 0 otherwise we will corrupt memory for now
|
|
|
|
if (y == 0) return;
|
2024-05-27 18:58:13 +00:00
|
|
|
|
2024-05-27 20:50:56 +00:00
|
|
|
for (plane = 0; plane < 2; ++plane) {
|
|
|
|
// shift left, so desccending
|
2024-05-27 18:58:13 +00:00
|
|
|
custom.bltcon0 = 0xc0 + (1 << 8) + (1 << 10) + (shift << 12);
|
|
|
|
custom.bltcon1 = (1 << 1) + (shift << 12);
|
|
|
|
|
2024-05-27 20:50:56 +00:00
|
|
|
// a has a mask we're shifting
|
2024-05-27 18:58:13 +00:00
|
|
|
custom.bltadat = 0xffff;
|
2024-05-27 20:50:56 +00:00
|
|
|
// b has bun data
|
|
|
|
custom.bltbpt = coolbunArea + 2 + ((COOL_BUN_HEIGHT - 1) * 4) + plane * COOL_BUN_PLANE_SIZE;
|
2024-05-27 18:58:13 +00:00
|
|
|
|
2024-05-27 20:50:56 +00:00
|
|
|
// d is the part on screen
|
|
|
|
custom.bltdpt = screenSetup.memoryStart + screenSetup.nextBitplaneAdvance * plane + (screenSetup.width * (y + COOL_BUN_HEIGHT - 1) / 8) + 2 - wordShift * 2;
|
|
|
|
|
|
|
|
custom.bltafwm = 0xffff;
|
|
|
|
bltalwm = 0x0000;
|
|
|
|
for (i = 0; i < 15 - shift; ++i) {
|
|
|
|
bltalwm += (1 << i);
|
2024-05-27 18:58:13 +00:00
|
|
|
}
|
|
|
|
custom.bltalwm = bltalwm;
|
|
|
|
|
|
|
|
custom.bltbmod = wordShift * 2;
|
2024-05-27 20:50:56 +00:00
|
|
|
custom.bltdmod = screenSetup.width / 8 - 4 + wordShift * 2;
|
2024-05-27 18:58:13 +00:00
|
|
|
|
2024-05-27 20:50:56 +00:00
|
|
|
custom.bltsize = 2 - wordShift + (COOL_BUN_HEIGHT << 6);
|
2024-05-27 18:58:13 +00:00
|
|
|
|
|
|
|
WaitBlit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bun_anywhere(int x, int y) {
|
|
|
|
uint8_t plane;
|
|
|
|
uint8_t shift = x & 15;
|
|
|
|
uint8_t needsExtraWord = shift != 0;
|
|
|
|
|
|
|
|
for (plane = 0; plane < 2; ++plane) {
|
|
|
|
// if we extend the bun area by a word, we only need one write
|
|
|
|
|
|
|
|
// buns will never interfere with a background so they don't need a mask
|
|
|
|
// they do need the scratch area though
|
2024-05-27 20:50:56 +00:00
|
|
|
custom.bltcon0 = 0xc0 + (1 << 8) + (1 << 10) + (shift << 12);
|
|
|
|
custom.bltcon1 = (shift << 12);
|
|
|
|
|
|
|
|
custom.bltadat = 0xffff;
|
|
|
|
custom.bltbpt = coolbunArea + plane * COOL_BUN_PLANE_SIZE;
|
|
|
|
custom.bltdpt = screenSetup.memoryStart + WORD_ALIGNED_BYTE_POSITION(screenSetup.width, x, y) + screenSetup.nextBitplaneAdvance * plane;
|
2024-05-27 18:58:13 +00:00
|
|
|
|
|
|
|
// custom.bltdpt = screenSetup.memoryStart;
|
|
|
|
custom.bltafwm = 0xffff;
|
2024-05-27 20:50:56 +00:00
|
|
|
if (needsExtraWord) {
|
|
|
|
custom.bltalwm = 0x0000;
|
|
|
|
} else {
|
|
|
|
custom.bltalwm = 0xffff;
|
|
|
|
}
|
|
|
|
custom.bltbmod = -(needsExtraWord * 2);
|
|
|
|
custom.bltdmod = (screenSetup.width / 8) - COOL_BUN_WIDTH_BYTES - (needsExtraWord * 2);
|
|
|
|
custom.bltsize = (2 + needsExtraWord) + (COOL_BUN_HEIGHT << 6);
|
2024-05-27 18:58:13 +00:00
|
|
|
|
|
|
|
WaitBlit();
|
2024-05-27 20:50:56 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-27 18:58:13 +00:00
|
|
|
|
2024-05-27 20:50:56 +00:00
|
|
|
void renderBun(int x, int y) {
|
|
|
|
if (x < -31) return;
|
|
|
|
if (x > screenSetup.width + 31) return;
|
|
|
|
if (y < 1) return;
|
|
|
|
if (y > screenSetup.height - COOL_BUN_HEIGHT - 1) return;
|
|
|
|
|
|
|
|
if (x < 0) {
|
|
|
|
bun_offLeftSide(-x, y);
|
|
|
|
} else if (x > screenSetup.width - COOL_BUN_WIDTH) {
|
|
|
|
bun_offRightSide(x - (screenSetup.width - COOL_BUN_WIDTH), y);
|
|
|
|
} else {
|
|
|
|
bun_anywhere(x, y);
|
2024-05-27 18:58:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-30 02:12:48 +00:00
|
|
|
int main(void) {
|
2024-05-02 16:52:06 +00:00
|
|
|
uint16_t *copperlist, *currentCopperlist;
|
2024-05-27 18:58:13 +00:00
|
|
|
int i, x, y, plane, result;
|
|
|
|
int blitShiftRight, memoryXOffset, blitWidth;
|
|
|
|
|
|
|
|
int bunPosition = -31;
|
|
|
|
|
2024-04-30 02:12:48 +00:00
|
|
|
color_t colors[16];
|
|
|
|
|
2024-05-27 18:58:13 +00:00
|
|
|
unsigned char *currentCoolBunArea, *currentCoolBun;
|
2024-05-02 16:52:06 +00:00
|
|
|
|
2024-05-27 18:58:13 +00:00
|
|
|
coolbunArea = AllocMem(COOL_BUN_MEMORY_SIZE, MEMF_CHIP | MEMF_CLEAR);
|
|
|
|
currentCoolBun = coolbun;
|
2024-05-02 16:52:06 +00:00
|
|
|
|
2024-05-27 18:58:13 +00:00
|
|
|
scratchArea = AllocMem(SCRATCH_AREA_MEMORY_SIZE, MEMF_CHIP | MEMF_CLEAR);
|
|
|
|
|
|
|
|
colors[0] = 0x09b8;
|
|
|
|
colors[1] = 0x0000;
|
|
|
|
colors[2] = 0x0fff;
|
2024-04-30 02:12:48 +00:00
|
|
|
colors[3] = 0x000f;
|
|
|
|
|
2024-05-02 16:52:06 +00:00
|
|
|
prepareScreen(&screenSetup, SCREEN_WIDTH, SCREEN_HEIGHT, 4);
|
|
|
|
allocateScreenMemory(&screenSetup);
|
|
|
|
|
2024-05-27 18:58:13 +00:00
|
|
|
currentCoolBunArea = coolbunArea;
|
2024-05-02 16:52:06 +00:00
|
|
|
|
2024-05-27 18:58:13 +00:00
|
|
|
for (plane = 0; plane < COOL_BUN_PLANES; ++plane) {
|
|
|
|
for (y = 0; y < COOL_BUN_HEIGHT; ++y) {
|
|
|
|
for (x = 0; x < COOL_BUN_WIDTH_BYTES; ++x) {
|
|
|
|
*(currentCoolBunArea++) = *(currentCoolBun++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-30 02:12:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
// blitter copy the first bitplane row down to the second
|
|
|
|
|
2024-05-02 16:52:06 +00:00
|
|
|
copperlist = prepareNewCopperlist();
|
2024-04-30 02:12:48 +00:00
|
|
|
|
2024-05-02 16:52:06 +00:00
|
|
|
takeOverSystem();
|
|
|
|
|
|
|
|
setCopperlist(copperlist);
|
|
|
|
setUpDisplay(&screenSetup);
|
|
|
|
|
|
|
|
currentCopperlist = addDisplayToCopperlist(copperlist, &screenSetup);
|
|
|
|
currentCopperlist = addColorsToCopperlist(currentCopperlist, colors, 16);
|
|
|
|
endCopperlist(currentCopperlist);
|
|
|
|
|
2024-05-27 20:50:56 +00:00
|
|
|
for (i = -31; i < screenSetup.width - 1; ++i) {
|
|
|
|
y = WaitBOF(250);
|
2024-05-27 18:58:13 +00:00
|
|
|
for (plane = 0; plane < 2; ++plane) {
|
2024-05-27 20:50:56 +00:00
|
|
|
custom.bltcon0 = 0xc0 + (1 << 8);
|
2024-05-27 18:58:13 +00:00
|
|
|
custom.bltcon1 = 0;
|
|
|
|
custom.bltadat = 0x0000;
|
|
|
|
custom.bltafwm = 0xffff;
|
|
|
|
custom.bltalwm = 0xffff;
|
2024-05-27 20:50:56 +00:00
|
|
|
custom.bltdpt = screenSetup.memoryStart + (45 * screenSetup.width) / 8 + plane * screenSetup.nextBitplaneAdvance;
|
|
|
|
custom.bltdmod = 0;
|
|
|
|
custom.bltsize = 20 + (COOL_BUN_MEMORY_SIZE << 6);
|
2024-05-27 18:58:13 +00:00
|
|
|
WaitBlit();
|
|
|
|
}
|
|
|
|
|
2024-05-27 20:50:56 +00:00
|
|
|
renderBun(i, 45);
|
2024-04-30 02:12:48 +00:00
|
|
|
}
|
|
|
|
|
2024-05-02 16:52:06 +00:00
|
|
|
giveBackSystem();
|
2024-04-30 02:12:48 +00:00
|
|
|
|
2024-05-02 16:52:06 +00:00
|
|
|
freeScreenMemory(&screenSetup);
|
2024-04-30 02:12:48 +00:00
|
|
|
|
2024-05-02 16:52:06 +00:00
|
|
|
freeCopperlist(copperlist);
|
2024-04-30 02:12:48 +00:00
|
|
|
|
2024-05-27 18:58:13 +00:00
|
|
|
FreeMem(coolbunArea, COOL_BUN_MEMORY_SIZE);
|
|
|
|
FreeMem(scratchArea, SCRATCH_AREA_MEMORY_SIZE);
|
2024-05-02 16:52:06 +00:00
|
|
|
|
2024-04-30 02:12:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|