2024-04-30 02:12:48 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2024-09-22 10:31:08 +00:00
|
|
|
#include <clib/alib_protos.h>
|
|
|
|
#include <clib/dos_protos.h>
|
2024-04-30 02:12:48 +00:00
|
|
|
#include <clib/exec_protos.h>
|
|
|
|
#include <clib/graphics_protos.h>
|
2024-09-22 10:31:08 +00:00
|
|
|
|
2024-04-30 02:12:48 +00:00
|
|
|
#include <exec/exec.h>
|
2024-09-22 10:31:08 +00:00
|
|
|
#include <exec/types.h>
|
|
|
|
#include <exec/memory.h>
|
|
|
|
#include <exec/interrupts.h>
|
|
|
|
|
|
|
|
#include <devices/input.h>
|
2024-04-30 02:12:48 +00:00
|
|
|
|
|
|
|
#include <hardware/custom.h>
|
|
|
|
#include <hardware/dmabits.h>
|
2024-06-11 02:04:40 +00:00
|
|
|
#include <hardware/cia.h>
|
2024-04-30 02:12:48 +00:00
|
|
|
|
2024-09-22 10:31:08 +00:00
|
|
|
#include <intuition/intuition.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-09-19 17:03:46 +00:00
|
|
|
#include "system/sprite.h"
|
2024-05-27 20:50:56 +00:00
|
|
|
|
2024-05-02 16:52:06 +00:00
|
|
|
#include "screen.h"
|
|
|
|
#include "types.h"
|
2024-05-28 12:02:28 +00:00
|
|
|
#include "bun.h"
|
2024-04-30 02:12:48 +00:00
|
|
|
|
2024-05-02 16:52:06 +00:00
|
|
|
extern struct Custom far custom;
|
2024-06-11 02:04:40 +00:00
|
|
|
extern struct CIA far ciaa;
|
2024-05-27 18:58:13 +00:00
|
|
|
|
2024-09-12 12:26:53 +00:00
|
|
|
// change to 0 to not render sprites
|
|
|
|
#define RENDER_SPRITES (1)
|
|
|
|
|
2024-09-19 11:47:48 +00:00
|
|
|
struct ScreenDefinition screenDefinition;
|
|
|
|
struct ActiveScreenBufferDetails activeScreenBufferDetails;
|
2024-09-19 12:09:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The locations within the copperlist data where the bitplanes are referenced.
|
|
|
|
* We change these areas of memory directly to implement double buffering.
|
|
|
|
* Addresses are to the high, then low, word of the plane memory address in the copperlist.
|
|
|
|
*
|
|
|
|
* @see addDisplayToCopperlist
|
|
|
|
*/
|
2024-06-01 11:42:11 +00:00
|
|
|
void *copperlistBitplanePointers[8][2];
|
2024-05-27 18:58:13 +00:00
|
|
|
|
2024-05-28 12:02:28 +00:00
|
|
|
uint16_t custom_color = (uint16_t)offsetof(Custom, color);
|
2024-06-01 11:42:11 +00:00
|
|
|
uint16_t custom_sprite = (uint16_t)offsetof(Custom, sprpt);
|
2024-06-02 20:03:16 +00:00
|
|
|
uint16_t custom_sprite_control = (uint16_t)offsetof(Custom, spr);
|
|
|
|
|
2024-06-11 02:04:40 +00:00
|
|
|
extern uint8_t chip TopazBitplanes[];
|
|
|
|
extern uint16_t chip CopperColors[];
|
|
|
|
extern uint16_t chip SpriteCopperlist[];
|
|
|
|
extern uint16_t chip SpriteData[];
|
2024-07-17 11:08:59 +00:00
|
|
|
extern uint8_t chip MaskBitplane[];
|
2024-06-11 02:04:40 +00:00
|
|
|
|
2024-06-13 16:30:39 +00:00
|
|
|
#define TOPAZ_WIDTH_PIXELS (160)
|
|
|
|
#define TOPAZ_WIDTH_BYTES (TOPAZ_WIDTH_PIXELS / 8)
|
|
|
|
#define TOPAZ_WIDTH_WORDS (TOPAZ_WIDTH_PIXELS / 16)
|
|
|
|
|
2024-09-19 17:03:46 +00:00
|
|
|
#define BLTSIZE(w, h) (w + (h << 6))
|
|
|
|
|
2024-06-13 13:01:22 +00:00
|
|
|
void renderTopaz(void) {
|
|
|
|
int plane;
|
|
|
|
|
|
|
|
uint16_t bltcon0, bltcmod;
|
|
|
|
uint8_t *bltbpt;
|
|
|
|
|
|
|
|
bltcon0 = 0xca + (1 << 8) + (1 << 9) + (1 << 10) + (1 << 11);
|
2024-09-19 11:47:48 +00:00
|
|
|
bltcmod = screenDefinition.byteWidth - TOPAZ_WIDTH_BYTES;
|
2024-06-13 13:01:22 +00:00
|
|
|
bltbpt = TopazBitplanes;
|
|
|
|
|
|
|
|
for (plane = 0; plane < 3; ++plane) {
|
|
|
|
custom.bltcon0 = bltcon0;
|
|
|
|
custom.bltcon1 = 0;
|
|
|
|
custom.bltafwm = 0xffff;
|
|
|
|
custom.bltalwm = 0xffff;
|
|
|
|
custom.bltapt = MaskBitplane;
|
|
|
|
custom.bltbpt = bltbpt;
|
2024-09-19 11:47:48 +00:00
|
|
|
custom.bltcpt = activeScreenBufferDetails.planes[plane] + 8;
|
|
|
|
custom.bltdpt = activeScreenBufferDetails.planes[plane] + 8;
|
2024-06-13 13:01:22 +00:00
|
|
|
custom.bltamod = 0;
|
|
|
|
custom.bltbmod = 0;
|
|
|
|
custom.bltcmod = bltcmod;
|
|
|
|
custom.bltdmod = bltcmod;
|
2024-09-19 17:03:46 +00:00
|
|
|
custom.bltsize = BLTSIZE(TOPAZ_WIDTH_WORDS, 256);
|
2024-06-13 13:01:22 +00:00
|
|
|
|
2024-06-13 16:30:39 +00:00
|
|
|
bltbpt += TOPAZ_WIDTH_BYTES * 256;
|
2024-06-13 13:01:22 +00:00
|
|
|
|
|
|
|
WaitBlit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-22 10:31:08 +00:00
|
|
|
|
|
|
|
void renderMostlyTopaz(void) {
|
|
|
|
int plane;
|
|
|
|
|
|
|
|
uint16_t bltcon0, bltcmod;
|
|
|
|
uint8_t *bltbpt;
|
|
|
|
|
|
|
|
bltcon0 = 0xca + (1 << 8) + (1 << 9) + (1 << 10) + (1 << 11);
|
|
|
|
bltcmod = screenDefinition.byteWidth - TOPAZ_WIDTH_BYTES;
|
|
|
|
bltbpt = TopazBitplanes;
|
|
|
|
|
|
|
|
for (plane = 0; plane < 2; ++plane) {
|
|
|
|
custom.bltcon0 = bltcon0;
|
|
|
|
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.bltamod = 0;
|
|
|
|
custom.bltbmod = 0;
|
|
|
|
custom.bltcmod = bltcmod;
|
|
|
|
custom.bltdmod = bltcmod;
|
|
|
|
custom.bltsize = BLTSIZE(TOPAZ_WIDTH_WORDS, 196);
|
|
|
|
|
|
|
|
bltbpt += TOPAZ_WIDTH_BYTES * 256;
|
|
|
|
|
|
|
|
WaitBlit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-19 17:03:46 +00:00
|
|
|
#define COPPERLIST_SIZE (10000)
|
2024-06-02 18:37:37 +00:00
|
|
|
|
2024-09-19 17:03:46 +00:00
|
|
|
uint16_t *copperlist;
|
2024-04-30 02:12:48 +00:00
|
|
|
|
2024-09-19 17:03:46 +00:00
|
|
|
void buildCopperlist(void) {
|
|
|
|
uint32_t spriteDataPointer;
|
|
|
|
uint16_t *currentCopperlist,
|
|
|
|
*currentCopperColors,
|
|
|
|
*currentSpriteCopperlist;
|
|
|
|
int i, j, y;
|
|
|
|
uint16_t spriteSetupRegisters[3];
|
2024-04-30 02:12:48 +00:00
|
|
|
|
2024-09-19 17:03:46 +00:00
|
|
|
copperlist = prepareNewCopperlist(COPPERLIST_SIZE);
|
2024-04-30 02:12:48 +00:00
|
|
|
|
2024-06-01 11:42:11 +00:00
|
|
|
currentCopperlist = addDisplayToCopperlist(
|
|
|
|
copperlist,
|
2024-09-19 11:47:48 +00:00
|
|
|
&screenDefinition,
|
|
|
|
&activeScreenBufferDetails,
|
2024-06-01 11:42:11 +00:00
|
|
|
&copperlistBitplanePointers
|
|
|
|
);
|
|
|
|
|
2024-06-11 02:04:40 +00:00
|
|
|
currentCopperColors = CopperColors;
|
|
|
|
currentSpriteCopperlist = SpriteCopperlist;
|
2024-05-28 12:02:28 +00:00
|
|
|
|
2024-09-19 17:03:46 +00:00
|
|
|
COPPERLIST_MOVE(currentCopperlist, custom_color, 0x3a6);
|
|
|
|
COPPERLIST_MOVE(currentCopperlist, custom_color + 2, 0x000);
|
|
|
|
COPPERLIST_MOVE(currentCopperlist, custom_color + 4, 0xfff);
|
2024-05-28 12:02:28 +00:00
|
|
|
|
2024-09-12 12:26:53 +00:00
|
|
|
if (RENDER_SPRITES) {
|
|
|
|
for (i = 0; i < 8; ++i) {
|
|
|
|
spriteDataPointer = (uint32_t)&SpriteData;
|
|
|
|
spriteDataPointer += ((256 + 2) * 4) * i;
|
2024-06-02 20:03:16 +00:00
|
|
|
|
2024-09-19 17:03:46 +00:00
|
|
|
COPPERLIST_MOVE_POINTER(
|
|
|
|
currentCopperlist,
|
|
|
|
custom_sprite + i * 4,
|
|
|
|
spriteDataPointer
|
|
|
|
);
|
2024-09-12 12:26:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
currentCopperlist = setUpEmptySpritesInCopperlist(currentCopperlist);
|
2024-06-11 02:04:40 +00:00
|
|
|
}
|
2024-06-02 20:03:16 +00:00
|
|
|
|
2024-05-28 12:02:28 +00:00
|
|
|
for (y = 0; y < 256; ++y) {
|
2024-09-12 12:26:53 +00:00
|
|
|
if (RENDER_SPRITES) {
|
|
|
|
for (i = 0; i < 8; ++i) {
|
2024-09-19 17:03:46 +00:00
|
|
|
spriteSetupRegisters[0] = custom_color + 32 + (
|
2024-09-12 12:26:53 +00:00
|
|
|
// sprite color group
|
|
|
|
(i / 2) * 4 +
|
|
|
|
// 0 is transparent
|
|
|
|
1 +
|
|
|
|
i % 2
|
|
|
|
) * 2;
|
2024-09-19 17:03:46 +00:00
|
|
|
spriteSetupRegisters[1] = custom_sprite_control + i * 8;
|
|
|
|
spriteSetupRegisters[2] = custom_sprite_control + i * 8 + 2;
|
|
|
|
|
|
|
|
for (j = 0; j < 3; ++j) {
|
|
|
|
COPPERLIST_MOVE(
|
|
|
|
currentCopperlist,
|
|
|
|
spriteSetupRegisters[j],
|
|
|
|
*(currentSpriteCopperlist++)
|
|
|
|
);
|
|
|
|
}
|
2024-09-12 12:26:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
2024-09-22 10:31:08 +00:00
|
|
|
//printf("Skipping render\n");
|
2024-06-11 02:04:40 +00:00
|
|
|
}
|
2024-06-03 16:46:32 +00:00
|
|
|
|
2024-06-11 02:04:40 +00:00
|
|
|
for (i = 3; i < 8; ++i) {
|
2024-09-19 17:03:46 +00:00
|
|
|
COPPERLIST_MOVE(
|
|
|
|
currentCopperlist,
|
|
|
|
custom_color + (i * 2),
|
|
|
|
*(currentCopperColors++)
|
|
|
|
);
|
2024-06-03 16:46:32 +00:00
|
|
|
}
|
2024-06-02 20:03:16 +00:00
|
|
|
|
2024-09-19 17:03:46 +00:00
|
|
|
COPPERLIST_WAIT(
|
|
|
|
currentCopperlist,
|
|
|
|
(31 + (256 / 4)),
|
|
|
|
(44 + y),
|
|
|
|
0xFFFE
|
|
|
|
);
|
2024-05-28 12:02:28 +00:00
|
|
|
}
|
|
|
|
|
2024-05-02 16:52:06 +00:00
|
|
|
endCopperlist(currentCopperlist);
|
2024-09-19 17:03:46 +00:00
|
|
|
}
|
|
|
|
|
2024-09-22 10:31:08 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-20 01:51:45 +00:00
|
|
|
void renderTopazPartials(
|
|
|
|
uint16_t redrawRanges[BUN_COUNT][4]
|
|
|
|
) {
|
2024-09-22 10:31:08 +00:00
|
|
|
int plane, i, topazX, screenX;
|
2024-09-20 01:51:45 +00:00
|
|
|
|
|
|
|
uint16_t bltcon0;
|
|
|
|
uint16_t bltamod, bltbmod, bltcmod, bltdmod;
|
|
|
|
uint16_t width, height, bltsize;
|
2024-09-22 10:31:08 +00:00
|
|
|
uint32_t bltapt, bltbpt, bltcpt, bltdpt;
|
2024-09-20 01:51:45 +00:00
|
|
|
|
|
|
|
bltcon0 = 0xca + (1 << 8) + (1 << 9) + (1 << 10) + (1 << 11);
|
|
|
|
|
2024-09-22 10:31:08 +00:00
|
|
|
WaitTOF();
|
2024-09-20 01:51:45 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
) {
|
2024-09-22 10:31:08 +00:00
|
|
|
width = redrawRanges[i][2] - redrawRanges[i][0] + 16;
|
2024-09-20 01:51:45 +00:00
|
|
|
height = redrawRanges[i][3] - redrawRanges[i][1];
|
|
|
|
topazX = redrawRanges[i][0] - 64;
|
2024-09-22 10:31:08 +00:00
|
|
|
screenX = redrawRanges[i][0];
|
2024-09-20 01:51:45 +00:00
|
|
|
|
|
|
|
if (topazX < 0) {
|
2024-09-22 10:31:08 +00:00
|
|
|
//printf("Too far left, adjusting...\n");
|
2024-09-20 01:51:45 +00:00
|
|
|
topazX += 16;
|
2024-09-22 10:31:08 +00:00
|
|
|
screenX += 16;
|
|
|
|
width -= 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (topazX + width > 64 + TOPAZ_WIDTH_PIXELS) {
|
|
|
|
//printf("Too far right, adjusting...\n");
|
2024-09-20 01:51:45 +00:00
|
|
|
width -= 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
bltapt = redrawRanges[i][1] * TOPAZ_WIDTH_BYTES + (topazX >> 4) * 2;
|
|
|
|
bltbpt = bltapt;
|
2024-09-22 10:31:08 +00:00
|
|
|
bltcpt = redrawRanges[i][1] * screenDefinition.byteWidth + (screenX >> 4) * 2;
|
2024-09-20 01:51:45 +00:00
|
|
|
bltdpt = bltcpt;
|
|
|
|
|
|
|
|
bltamod = TOPAZ_WIDTH_BYTES - (width >> 4) * 2;
|
|
|
|
bltbmod = bltamod;
|
|
|
|
bltcmod = screenDefinition.byteWidth - (width >> 4) * 2;
|
|
|
|
bltdmod = bltcmod;
|
|
|
|
|
|
|
|
bltsize = BLTSIZE((width >> 4), height);
|
2024-09-22 10:31:08 +00:00
|
|
|
/*
|
2024-09-20 01:51:45 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2024-09-22 10:31:08 +00:00
|
|
|
printf("MaskBitplane: %d\n", MaskBitplane);
|
|
|
|
printf("TopazBitplanes: %d\n", TopazBitplanes);
|
|
|
|
printf("ActiveScreenBuffer Plane 0: %d\n", activeScreenBufferDetails.planes[0]);
|
|
|
|
|
2024-09-20 01:51:45 +00:00
|
|
|
printf("BLTAPT: %d\n", bltapt);
|
2024-09-22 10:31:08 +00:00
|
|
|
printf("BLTAPT src: %d\n", bltapt + (uint32_t)MaskBitplane);
|
2024-09-20 01:51:45 +00:00
|
|
|
printf("BLTBPT: %d\n", bltbpt);
|
2024-09-22 10:31:08 +00:00
|
|
|
printf("BLTBPT src: %d\n", bltbpt + (uint32_t)TopazBitplanes);
|
2024-09-20 01:51:45 +00:00
|
|
|
printf("BLTCPT: %d\n", bltcpt);
|
2024-09-22 10:31:08 +00:00
|
|
|
printf("BLTCPT src: %d\n", bltcpt + (uint32_t)activeScreenBufferDetails.planes[0] + 8);
|
2024-09-20 01:51:45 +00:00
|
|
|
printf("BLTDPT: %d\n", bltdpt);
|
2024-09-22 10:31:08 +00:00
|
|
|
printf("BLTDPT src: %d\n", bltdpt + (uint32_t)activeScreenBufferDetails.planes[0] + 8);
|
2024-09-20 01:51:45 +00:00
|
|
|
|
|
|
|
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);
|
2024-09-22 10:31:08 +00:00
|
|
|
*/
|
2024-09-20 01:51:45 +00:00
|
|
|
|
2024-09-22 10:31:08 +00:00
|
|
|
bltapt += (uint32_t)MaskBitplane;
|
|
|
|
bltbpt += (uint32_t)TopazBitplanes;
|
|
|
|
|
|
|
|
for (plane = 0; plane < 2; ++plane) {
|
2024-09-20 01:51:45 +00:00
|
|
|
custom.bltcon0 = bltcon0;
|
|
|
|
custom.bltcon1 = 0;
|
|
|
|
custom.bltafwm = 0xffff;
|
|
|
|
custom.bltalwm = 0xffff;
|
2024-09-22 10:31:08 +00:00
|
|
|
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;
|
2024-09-20 01:51:45 +00:00
|
|
|
custom.bltcmod = bltcmod;
|
2024-09-22 10:31:08 +00:00
|
|
|
custom.bltdmod = bltdmod;
|
|
|
|
custom.bltsize = bltsize;
|
2024-09-20 01:51:45 +00:00
|
|
|
|
|
|
|
WaitBlit();
|
|
|
|
}
|
2024-09-22 10:31:08 +00:00
|
|
|
|
|
|
|
break;
|
2024-09-20 01:51:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-22 10:31:08 +00:00
|
|
|
static struct MsgPort *keyboardMessagePort = NULL;
|
|
|
|
static struct IOStdReq *keyboardIO = NULL;
|
|
|
|
static struct Interrupt keyboardInterrupt;
|
|
|
|
|
|
|
|
extern far ULONG keyboardPressed;
|
|
|
|
|
|
|
|
extern struct InputEvent * __asm stupidKeyboardHandler(
|
|
|
|
register __a0 struct InputEvent *input,
|
|
|
|
register __a1 APTR id
|
|
|
|
);
|
|
|
|
|
|
|
|
void setupKeyboard(void) {
|
|
|
|
if (keyboardMessagePort = CreatePort(NULL, NULL)) {
|
|
|
|
if (keyboardIO = (struct IOStdReq *)CreateExtIO(
|
|
|
|
keyboardMessagePort,
|
|
|
|
sizeof(struct IOStdReq)
|
|
|
|
)) {
|
|
|
|
// OpenDevice returns 0 if successful
|
|
|
|
if (!OpenDevice(
|
|
|
|
"input.device",
|
|
|
|
0,
|
|
|
|
(struct IORequest *)keyboardIO,
|
|
|
|
0
|
|
|
|
)) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
keyboardIO->io_Data = (void *)&keyboardInterrupt;
|
|
|
|
keyboardIO->io_Command = IND_ADDHANDLER;
|
|
|
|
|
|
|
|
DoIO((struct IORequest *)keyboardIO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void teardownKeyboard(void) {
|
|
|
|
if (keyboardIO) {
|
|
|
|
keyboardIO->io_Data = (void *)&keyboardInterrupt;
|
|
|
|
keyboardIO->io_Command = IND_REMHANDLER;
|
|
|
|
DoIO((struct IORequest *)keyboardIO);
|
|
|
|
CloseDevice((struct IORequest *)keyboardIO);
|
|
|
|
DeleteIORequest((struct IORequest *)keyboardIO);
|
|
|
|
keyboardIO = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (keyboardMessagePort) {
|
|
|
|
DeleteMsgPort(keyboardMessagePort);
|
|
|
|
keyboardMessagePort = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-19 17:03:46 +00:00
|
|
|
int main(void) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
struct BunRenderer bunRenderer;
|
2024-09-20 01:51:45 +00:00
|
|
|
uint16_t redrawRanges[BUN_COUNT][4];
|
2024-09-19 17:03:46 +00:00
|
|
|
|
2024-09-22 10:31:08 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
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;
|
|
|
|
*/
|
|
|
|
|
2024-09-19 17:03:46 +00:00
|
|
|
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");
|
|
|
|
printf("It's a combination of C (SAS/C) and Assembler (DevPac), with a Ruby\n");
|
|
|
|
printf("script to do some image processing. The screen only uses three\n");
|
|
|
|
printf("bitplanes -- one color is the background, two colors are the flying\n");
|
|
|
|
printf("cool bun logo white and black, and the remaining 5 colors are used\n");
|
|
|
|
printf("by the Topaz smiling art. The Ruby script will process the PNG file\n");
|
|
|
|
printf("and figure out the best 5 colors (plus b&w) for that line of the\n");
|
|
|
|
printf("image, setting the colors via copperlist for that line.\n");
|
|
|
|
printf("It also builds the clipping mask for the blitter.\n\n");
|
|
|
|
|
|
|
|
printf("And, I'm also using sprites to add more colors to the Topaz art.\n");
|
|
|
|
printf("The Ruby script will figure out what small areas of each line weren't\n");
|
|
|
|
printf("covered by the bitplane colors and use the 8 available sprites,\n");
|
|
|
|
printf("changing the colors on each line via copper, to fill in the gaps.\n");
|
|
|
|
printf("Cool buns are animated via blitter rather than sprites, but I\n");
|
|
|
|
printf("managed to get it to run at a decent speed regardless.\n");
|
|
|
|
|
|
|
|
printf("\nEnjoy, and thanks for watching!\n");
|
|
|
|
printf("John (theindustriousrabbit.com)\n\n");
|
|
|
|
|
|
|
|
allocateDoubleBufferedScreenMemory(
|
|
|
|
&screenDefinition,
|
|
|
|
&activeScreenBufferDetails,
|
|
|
|
SCREEN_WIDTH,
|
|
|
|
SCREEN_HEIGHT,
|
|
|
|
3
|
|
|
|
);
|
|
|
|
|
|
|
|
setupBunRenderer(
|
|
|
|
&bunRenderer,
|
|
|
|
&screenDefinition,
|
|
|
|
&activeScreenBufferDetails
|
|
|
|
);
|
|
|
|
|
|
|
|
buildCopperlist();
|
|
|
|
|
2024-05-02 16:52:06 +00:00
|
|
|
|
2024-09-22 10:31:08 +00:00
|
|
|
|
2024-09-12 12:26:53 +00:00
|
|
|
/*
|
|
|
|
copperlist debugging
|
|
|
|
for (i = 0; i < 20; ++i) {
|
|
|
|
printf(
|
|
|
|
"%x %x %x %x\n",
|
|
|
|
*(copperlist + (i * 4)),
|
|
|
|
*(copperlist + (i * 4) + 1),
|
|
|
|
*(copperlist + (i * 4) + 2),
|
|
|
|
*(copperlist + (i * 4) + 3)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
*/
|
2024-09-22 10:31:08 +00:00
|
|
|
setupKeyboard();
|
2024-06-14 13:16:01 +00:00
|
|
|
takeOverSystem();
|
|
|
|
|
|
|
|
setCopperlist(copperlist);
|
2024-09-19 11:47:48 +00:00
|
|
|
setUpDisplay((uint32_t)screenDefinition.bitplanes);
|
2024-06-14 13:16:01 +00:00
|
|
|
|
2024-09-20 01:51:45 +00:00
|
|
|
renderTopaz();
|
|
|
|
swapCurrentScreenBuffer(&screenDefinition, &activeScreenBufferDetails);
|
|
|
|
renderTopaz();
|
|
|
|
swapCurrentScreenBuffer(&screenDefinition, &activeScreenBufferDetails);
|
|
|
|
|
2024-09-22 10:31:08 +00:00
|
|
|
updateDisplayInCopperList(
|
|
|
|
&screenDefinition,
|
|
|
|
&activeScreenBufferDetails,
|
|
|
|
copperlistBitplanePointers
|
|
|
|
);
|
|
|
|
|
2024-06-11 02:04:40 +00:00
|
|
|
i = 0;
|
|
|
|
|
2024-09-22 10:31:08 +00:00
|
|
|
while (1) {
|
|
|
|
WaitTOF();
|
2024-09-20 01:51:45 +00:00
|
|
|
|
2024-09-19 11:47:48 +00:00
|
|
|
swapCurrentScreenBuffer(&screenDefinition, &activeScreenBufferDetails);
|
2024-05-28 12:02:28 +00:00
|
|
|
|
2024-06-13 09:55:29 +00:00
|
|
|
|
2024-09-20 01:51:45 +00:00
|
|
|
clearCurrentBuns(&bunRenderer);
|
2024-06-11 02:04:40 +00:00
|
|
|
renderBunFrame(i, &bunRenderer);
|
|
|
|
|
2024-09-22 10:31:08 +00:00
|
|
|
/*
|
|
|
|
calculateNeededRedrawRanges(i, redrawRanges);
|
|
|
|
renderTopazPartials(redrawRanges);
|
|
|
|
*/
|
|
|
|
renderMostlyTopaz();
|
|
|
|
|
|
|
|
//WaitTOF();
|
|
|
|
|
2024-06-13 13:01:22 +00:00
|
|
|
|
2024-06-01 11:42:11 +00:00
|
|
|
updateDisplayInCopperList(
|
2024-09-19 11:47:48 +00:00
|
|
|
&screenDefinition,
|
|
|
|
&activeScreenBufferDetails,
|
2024-06-01 11:42:11 +00:00
|
|
|
copperlistBitplanePointers
|
|
|
|
);
|
2024-06-11 02:04:40 +00:00
|
|
|
|
2024-09-22 10:31:08 +00:00
|
|
|
//WaitBOF(100);
|
|
|
|
|
|
|
|
//WaitTOF();
|
2024-06-13 16:30:39 +00:00
|
|
|
|
2024-09-22 10:31:08 +00:00
|
|
|
if (keyboardPressed) {
|
|
|
|
i++;
|
|
|
|
}
|
2024-06-11 02:04:40 +00:00
|
|
|
if ((ciaa.ciapra >> 6) != 3) break;
|
|
|
|
|
2024-09-19 17:03:46 +00:00
|
|
|
i++;
|
2024-09-22 10:31:08 +00:00
|
|
|
i %= FRAMES_FOR_SCREEN;
|
2024-05-28 12:02:28 +00:00
|
|
|
}
|
2024-05-27 18:58:13 +00:00
|
|
|
|
2024-05-02 16:52:06 +00:00
|
|
|
giveBackSystem();
|
2024-09-22 10:31:08 +00:00
|
|
|
teardownKeyboard();
|
2024-04-30 02:12:48 +00:00
|
|
|
|
2024-09-19 11:47:48 +00:00
|
|
|
teardownScreen(&screenDefinition);
|
2024-06-11 02:04:40 +00:00
|
|
|
|
2024-05-02 16:52:06 +00:00
|
|
|
freeCopperlist(copperlist);
|
2024-04-30 02:12:48 +00:00
|
|
|
|
2024-06-02 18:42:36 +00:00
|
|
|
teardownBunRenderer();
|
2024-06-01 12:19:10 +00:00
|
|
|
|
2024-04-30 02:12:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|