More code cleanups
This commit is contained in:
parent
c1d9f23026
commit
d89d68c115
183
main.c
183
main.c
@ -13,6 +13,7 @@
|
|||||||
#include "system/blitter.h"
|
#include "system/blitter.h"
|
||||||
#include "system/copper.h"
|
#include "system/copper.h"
|
||||||
#include "system/system.h"
|
#include "system/system.h"
|
||||||
|
#include "system/sprite.h"
|
||||||
|
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
@ -24,8 +25,6 @@ extern struct CIA far ciaa;
|
|||||||
// change to 0 to not render sprites
|
// change to 0 to not render sprites
|
||||||
#define RENDER_SPRITES (1)
|
#define RENDER_SPRITES (1)
|
||||||
|
|
||||||
volatile short *dbg = (volatile short *)0x100;
|
|
||||||
|
|
||||||
struct ScreenDefinition screenDefinition;
|
struct ScreenDefinition screenDefinition;
|
||||||
struct ActiveScreenBufferDetails activeScreenBufferDetails;
|
struct ActiveScreenBufferDetails activeScreenBufferDetails;
|
||||||
|
|
||||||
@ -38,19 +37,10 @@ struct ActiveScreenBufferDetails activeScreenBufferDetails;
|
|||||||
*/
|
*/
|
||||||
void *copperlistBitplanePointers[8][2];
|
void *copperlistBitplanePointers[8][2];
|
||||||
|
|
||||||
#define offsetof(s, m) &((struct s *)0)->m
|
|
||||||
uint16_t custom_color = (uint16_t)offsetof(Custom, color);
|
uint16_t custom_color = (uint16_t)offsetof(Custom, color);
|
||||||
uint16_t custom_sprite = (uint16_t)offsetof(Custom, sprpt);
|
uint16_t custom_sprite = (uint16_t)offsetof(Custom, sprpt);
|
||||||
uint16_t custom_sprite_control = (uint16_t)offsetof(Custom, spr);
|
uint16_t custom_sprite_control = (uint16_t)offsetof(Custom, spr);
|
||||||
|
|
||||||
#define SPRPOS(x, y) (((y & 0xff) << 8) + ((x & 0x1fe) >> 1))
|
|
||||||
#define SPRCTL(x, y, height) ( \
|
|
||||||
((height & 0xff) << 8) + \
|
|
||||||
((y & 0x100) >> 6) + \
|
|
||||||
((height & 0x100) >> 7) + \
|
|
||||||
(x & 1) \
|
|
||||||
)
|
|
||||||
|
|
||||||
extern uint8_t chip TopazBitplanes[];
|
extern uint8_t chip TopazBitplanes[];
|
||||||
extern uint16_t chip CopperColors[];
|
extern uint16_t chip CopperColors[];
|
||||||
extern uint16_t chip SpriteCopperlist[];
|
extern uint16_t chip SpriteCopperlist[];
|
||||||
@ -61,6 +51,8 @@ extern uint8_t chip MaskBitplane[];
|
|||||||
#define TOPAZ_WIDTH_BYTES (TOPAZ_WIDTH_PIXELS / 8)
|
#define TOPAZ_WIDTH_BYTES (TOPAZ_WIDTH_PIXELS / 8)
|
||||||
#define TOPAZ_WIDTH_WORDS (TOPAZ_WIDTH_PIXELS / 16)
|
#define TOPAZ_WIDTH_WORDS (TOPAZ_WIDTH_PIXELS / 16)
|
||||||
|
|
||||||
|
#define BLTSIZE(w, h) (w + (h << 6))
|
||||||
|
|
||||||
void renderTopaz(void) {
|
void renderTopaz(void) {
|
||||||
int plane;
|
int plane;
|
||||||
|
|
||||||
@ -84,7 +76,7 @@ void renderTopaz(void) {
|
|||||||
custom.bltbmod = 0;
|
custom.bltbmod = 0;
|
||||||
custom.bltcmod = bltcmod;
|
custom.bltcmod = bltcmod;
|
||||||
custom.bltdmod = bltcmod;
|
custom.bltdmod = bltcmod;
|
||||||
custom.bltsize = TOPAZ_WIDTH_WORDS + (256 << 6);
|
custom.bltsize = BLTSIZE(TOPAZ_WIDTH_WORDS, 256);
|
||||||
|
|
||||||
bltbpt += TOPAZ_WIDTH_BYTES * 256;
|
bltbpt += TOPAZ_WIDTH_BYTES * 256;
|
||||||
|
|
||||||
@ -92,10 +84,96 @@ void renderTopaz(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
#define COPPERLIST_SIZE (10000)
|
||||||
uint16_t *copperlist, *currentCopperlist, *currentCopperColors, result, *currentSpriteCopperlist;
|
|
||||||
|
uint16_t *copperlist;
|
||||||
|
|
||||||
|
void buildCopperlist(void) {
|
||||||
uint32_t spriteDataPointer;
|
uint32_t spriteDataPointer;
|
||||||
int i, x, y, height, plane;
|
uint16_t *currentCopperlist,
|
||||||
|
*currentCopperColors,
|
||||||
|
*currentSpriteCopperlist;
|
||||||
|
int i, j, y;
|
||||||
|
uint16_t spriteSetupRegisters[3];
|
||||||
|
|
||||||
|
copperlist = prepareNewCopperlist(COPPERLIST_SIZE);
|
||||||
|
|
||||||
|
currentCopperlist = addDisplayToCopperlist(
|
||||||
|
copperlist,
|
||||||
|
&screenDefinition,
|
||||||
|
&activeScreenBufferDetails,
|
||||||
|
&copperlistBitplanePointers
|
||||||
|
);
|
||||||
|
|
||||||
|
currentCopperColors = CopperColors;
|
||||||
|
currentSpriteCopperlist = SpriteCopperlist;
|
||||||
|
|
||||||
|
COPPERLIST_MOVE(currentCopperlist, custom_color, 0x3a6);
|
||||||
|
COPPERLIST_MOVE(currentCopperlist, custom_color + 2, 0x000);
|
||||||
|
COPPERLIST_MOVE(currentCopperlist, custom_color + 4, 0xfff);
|
||||||
|
|
||||||
|
if (RENDER_SPRITES) {
|
||||||
|
for (i = 0; i < 8; ++i) {
|
||||||
|
spriteDataPointer = (uint32_t)&SpriteData;
|
||||||
|
spriteDataPointer += ((256 + 2) * 4) * i;
|
||||||
|
|
||||||
|
COPPERLIST_MOVE_POINTER(
|
||||||
|
currentCopperlist,
|
||||||
|
custom_sprite + i * 4,
|
||||||
|
spriteDataPointer
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf("Skipping render\n");
|
||||||
|
currentCopperlist = setUpEmptySpritesInCopperlist(currentCopperlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (y = 0; y < 256; ++y) {
|
||||||
|
if (RENDER_SPRITES) {
|
||||||
|
for (i = 0; i < 8; ++i) {
|
||||||
|
spriteSetupRegisters[0] = custom_color + 32 + (
|
||||||
|
// sprite color group
|
||||||
|
(i / 2) * 4 +
|
||||||
|
// 0 is transparent
|
||||||
|
1 +
|
||||||
|
i % 2
|
||||||
|
) * 2;
|
||||||
|
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++)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf("Skipping render\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 3; i < 8; ++i) {
|
||||||
|
COPPERLIST_MOVE(
|
||||||
|
currentCopperlist,
|
||||||
|
custom_color + (i * 2),
|
||||||
|
*(currentCopperColors++)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
COPPERLIST_WAIT(
|
||||||
|
currentCopperlist,
|
||||||
|
(31 + (256 / 4)),
|
||||||
|
(44 + y),
|
||||||
|
0xFFFE
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
endCopperlist(currentCopperlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
int i;
|
||||||
|
|
||||||
struct BunRenderer bunRenderer;
|
struct BunRenderer bunRenderer;
|
||||||
|
|
||||||
@ -135,79 +213,8 @@ int main(void) {
|
|||||||
&activeScreenBufferDetails
|
&activeScreenBufferDetails
|
||||||
);
|
);
|
||||||
|
|
||||||
// blitter copy the first bitplane row down to the second
|
buildCopperlist();
|
||||||
|
|
||||||
copperlist = prepareNewCopperlist(10000);
|
|
||||||
|
|
||||||
currentCopperlist = addDisplayToCopperlist(
|
|
||||||
copperlist,
|
|
||||||
&screenDefinition,
|
|
||||||
&activeScreenBufferDetails,
|
|
||||||
&copperlistBitplanePointers
|
|
||||||
);
|
|
||||||
|
|
||||||
currentCopperColors = CopperColors;
|
|
||||||
currentSpriteCopperlist = SpriteCopperlist;
|
|
||||||
|
|
||||||
*(currentCopperlist++) = custom_color + 2;
|
|
||||||
*(currentCopperlist++) = 0x000;
|
|
||||||
|
|
||||||
*(currentCopperlist++) = custom_color + 4;
|
|
||||||
*(currentCopperlist++) = 0xfff;
|
|
||||||
|
|
||||||
if (RENDER_SPRITES) {
|
|
||||||
for (i = 0; i < 8; ++i) {
|
|
||||||
spriteDataPointer = (uint32_t)&SpriteData;
|
|
||||||
spriteDataPointer += ((256 + 2) * 4) * i;
|
|
||||||
|
|
||||||
*(currentCopperlist++) = custom_sprite + i * 4;
|
|
||||||
*(currentCopperlist++) = (spriteDataPointer >> 16);
|
|
||||||
|
|
||||||
*(currentCopperlist++) = custom_sprite + 2 + i * 4;
|
|
||||||
*(currentCopperlist++) = (spriteDataPointer & 0xffff);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
printf("Skipping render\n");
|
|
||||||
currentCopperlist = setUpEmptySpritesInCopperlist(currentCopperlist);
|
|
||||||
}
|
|
||||||
|
|
||||||
*(currentCopperlist++) = custom_color;
|
|
||||||
*(currentCopperlist++) = 0x3a6;
|
|
||||||
|
|
||||||
for (y = 0; y < 256; ++y) {
|
|
||||||
if (RENDER_SPRITES) {
|
|
||||||
for (i = 0; i < 8; ++i) {
|
|
||||||
// set sprite color
|
|
||||||
*(currentCopperlist++) = custom_color + 32 + (
|
|
||||||
// sprite color group
|
|
||||||
(i / 2) * 4 +
|
|
||||||
// 0 is transparent
|
|
||||||
1 +
|
|
||||||
i % 2
|
|
||||||
) * 2;
|
|
||||||
*(currentCopperlist++) = *(currentSpriteCopperlist++);
|
|
||||||
|
|
||||||
// set sprite position
|
|
||||||
*(currentCopperlist++) = custom_sprite_control + i * 8;
|
|
||||||
*(currentCopperlist++) = *(currentSpriteCopperlist++);
|
|
||||||
|
|
||||||
*(currentCopperlist++) = custom_sprite_control + i * 8 + 2;
|
|
||||||
*(currentCopperlist++) = *(currentSpriteCopperlist++);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
printf("Skipping render\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 3; i < 8; ++i) {
|
|
||||||
*(currentCopperlist++) = custom_color + (i * 2);
|
|
||||||
*(currentCopperlist++) = *(currentCopperColors++);
|
|
||||||
}
|
|
||||||
|
|
||||||
*(currentCopperlist++) = 1 + ((31 + (256 / 4)) << 1) + ((44 + y) << 8);
|
|
||||||
*(currentCopperlist++) = 0xFFFE;
|
|
||||||
}
|
|
||||||
|
|
||||||
endCopperlist(currentCopperlist);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
copperlist debugging
|
copperlist debugging
|
||||||
@ -248,7 +255,7 @@ int main(void) {
|
|||||||
|
|
||||||
if ((ciaa.ciapra >> 6) != 3) break;
|
if ((ciaa.ciapra >> 6) != 3) break;
|
||||||
|
|
||||||
//i++;
|
i++;
|
||||||
i %= FRAMES_FOR_SCREEN;
|
i %= FRAMES_FOR_SCREEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,8 +8,8 @@ all: main
|
|||||||
.s.o:
|
.s.o:
|
||||||
genam -l $*.s
|
genam -l $*.s
|
||||||
|
|
||||||
system.lib: system/system.o system/copper.o system/blitter.o
|
system.lib: system/system.o system/copper.o system/blitter.o system/debug.o
|
||||||
sc objectlibrary=system.lib system/system.o system/copper.o system/blitter.o
|
sc objectlibrary=system.lib system/system.o system/copper.o system/blitter.o system/debug.o
|
||||||
|
|
||||||
main: $(MAIN_OBJS)
|
main: $(MAIN_OBJS)
|
||||||
sc link to main math=standard $(MAIN_OBJS)
|
sc link to main math=standard $(MAIN_OBJS)
|
||||||
|
@ -3,6 +3,28 @@
|
|||||||
|
|
||||||
#include "../types.h"
|
#include "../types.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets register to value over two Copper words.
|
||||||
|
* Side-effect: Advances ptr by 4.
|
||||||
|
*/
|
||||||
|
#define COPPERLIST_MOVE(ptr,register,value) \
|
||||||
|
*(ptr++) = register; \
|
||||||
|
*(ptr++) = value;
|
||||||
|
|
||||||
|
#define COPPERLIST_WAIT(ptr,x,y,mask) \
|
||||||
|
*(ptr++) = 1 + (x << 1) + (y << 8); \
|
||||||
|
*(ptr++) = mask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets high/low registers to pointer value over four Copper words.
|
||||||
|
* Side-effect: Advances ptr by 8.
|
||||||
|
*/
|
||||||
|
#define COPPERLIST_MOVE_POINTER(ptr,register,pointerValue) \
|
||||||
|
*(ptr++) = register; \
|
||||||
|
*(ptr++) = (pointerValue >> 16); \
|
||||||
|
*(ptr++) = register + 2; \
|
||||||
|
*(ptr++) = (pointerValue & 0xffff);
|
||||||
|
|
||||||
uint16_t * prepareNewCopperlist(uint16_t size_b);
|
uint16_t * prepareNewCopperlist(uint16_t size_b);
|
||||||
void setCopperlist(uint16_t *copperlist);
|
void setCopperlist(uint16_t *copperlist);
|
||||||
void freeCopperlist(uint16_t *copperlist);
|
void freeCopperlist(uint16_t *copperlist);
|
||||||
|
11
system/debug.c
Normal file
11
system/debug.c
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include "debug.h"
|
||||||
|
|
||||||
|
volatile short *dbg = (volatile short *)0x100;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a two-word write watch in the UAE debugger at memory location 0x100
|
||||||
|
* and call this function.
|
||||||
|
*/
|
||||||
|
void triggerUAEDebugger() {
|
||||||
|
*(dbg) = 0;
|
||||||
|
}
|
6
system/debug.h
Normal file
6
system/debug.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef __SYSTEM_DEBUG__
|
||||||
|
#define __SYSTEM_DEBUG__
|
||||||
|
|
||||||
|
void triggerUAEDebugger(void);
|
||||||
|
|
||||||
|
#endif
|
7
system/sprite.h
Normal file
7
system/sprite.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#define SPRPOS(x, y) (((y & 0xff) << 8) + ((x & 0x1fe) >> 1))
|
||||||
|
#define SPRCTL(x, y, height) ( \
|
||||||
|
((height & 0xff) << 8) + \
|
||||||
|
((y & 0x100) >> 6) + \
|
||||||
|
((height & 0x100) >> 7) + \
|
||||||
|
(x & 1) \
|
||||||
|
)
|
8
types.h
8
types.h
@ -3,6 +3,14 @@
|
|||||||
|
|
||||||
#include <exec/types.h>
|
#include <exec/types.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the offset from the beginning of a struct. Useful for building
|
||||||
|
* references to custom chip registers dynamically for copperlists.
|
||||||
|
*
|
||||||
|
* @see Custom
|
||||||
|
*/
|
||||||
|
#define offsetof(s, m) &((struct s *)0)->m
|
||||||
|
|
||||||
typedef unsigned short color_t;
|
typedef unsigned short color_t;
|
||||||
typedef unsigned long uint32_t;
|
typedef unsigned long uint32_t;
|
||||||
typedef unsigned short uint16_t;
|
typedef unsigned short uint16_t;
|
||||||
|
Loading…
Reference in New Issue
Block a user