code restructured
This commit is contained in:
parent
391c03b8aa
commit
098b3f3ebf
79
bun.c
79
bun.c
|
@ -1,6 +1,18 @@
|
||||||
|
// Custom
|
||||||
|
#include <hardware/custom.h>
|
||||||
|
|
||||||
|
// WaitBlit()
|
||||||
|
#include <clib/graphics_protos.h>
|
||||||
|
|
||||||
|
// AllocMem(), FreeMem()
|
||||||
|
#include <clib/exec_protos.h>
|
||||||
|
#include <exec/memory.h>
|
||||||
|
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "bun.h"
|
#include "bun.h"
|
||||||
|
#include "system/system.h"
|
||||||
|
|
||||||
|
// linked as raw bytes in assembler
|
||||||
extern unsigned char far coolbun[];
|
extern unsigned char far coolbun[];
|
||||||
|
|
||||||
unsigned char *coolbunArea;
|
unsigned char *coolbunArea;
|
||||||
|
@ -9,18 +21,28 @@ unsigned char *coolbunArea;
|
||||||
#define COOL_BUN_WIDTH_BYTES (COOL_BUN_WIDTH / 8)
|
#define COOL_BUN_WIDTH_BYTES (COOL_BUN_WIDTH / 8)
|
||||||
#define COOL_BUN_HEIGHT (32)
|
#define COOL_BUN_HEIGHT (32)
|
||||||
#define COOL_BUN_PLANES (2)
|
#define COOL_BUN_PLANES (2)
|
||||||
|
#define COOL_BUN_LAST_ROW (COOL_BUN_HEIGHT - 1)
|
||||||
|
#define COOL_BUN_LAST_ROW_BYTES (COOL_BUN_LAST_ROW * COOL_BUN_WIDTH_BYTES)
|
||||||
|
|
||||||
#define COOL_BUN_PLANE_SIZE (COOL_BUN_WIDTH_BYTES * COOL_BUN_HEIGHT)
|
#define COOL_BUN_PLANE_SIZE (COOL_BUN_WIDTH_BYTES * COOL_BUN_HEIGHT)
|
||||||
#define COOL_BUN_MEMORY_SIZE (COOL_BUN_PLANE_SIZE * COOL_BUN_PLANES)
|
#define COOL_BUN_MEMORY_SIZE (COOL_BUN_PLANE_SIZE * COOL_BUN_PLANES)
|
||||||
|
|
||||||
|
#define BLTCON0( \
|
||||||
|
minterm, aChan, bChan, cChan, dChan, shift \
|
||||||
|
) (minterm + (aChan << 11) + (bChan << 10) + (cChan << 9) + (dChan << 8) + (shift << 12))
|
||||||
|
#define BLTCON1(descending, shift) ((descending << 1) + (shift << 12))
|
||||||
|
|
||||||
|
extern struct Custom far custom;
|
||||||
|
|
||||||
void setupBun() {
|
void setupBun() {
|
||||||
unsigned char *currentCoolBunArea, *currentCoolBun;
|
unsigned char *currentCoolBunArea, *currentCoolBun;
|
||||||
|
unsigned int x, y, plane;
|
||||||
|
|
||||||
coolbunArea = AllocMem(COOL_BUN_MEMORY_SIZE, MEMF_CHIP | MEMF_CLEAR);
|
coolbunArea = AllocMem(COOL_BUN_MEMORY_SIZE, MEMF_CHIP | MEMF_CLEAR);
|
||||||
|
currentCoolBunArea = coolbunArea;
|
||||||
currentCoolBun = coolbun;
|
currentCoolBun = coolbun;
|
||||||
|
|
||||||
currentCoolBunArea = coolbunArea;
|
/*
|
||||||
|
|
||||||
for (plane = 0; plane < COOL_BUN_PLANES; ++plane) {
|
for (plane = 0; plane < COOL_BUN_PLANES; ++plane) {
|
||||||
for (y = 0; y < COOL_BUN_HEIGHT; ++y) {
|
for (y = 0; y < COOL_BUN_HEIGHT; ++y) {
|
||||||
for (x = 0; x < COOL_BUN_WIDTH_BYTES; ++x) {
|
for (x = 0; x < COOL_BUN_WIDTH_BYTES; ++x) {
|
||||||
|
@ -28,28 +50,32 @@ void setupBun() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
CopyMem(coolbun, coolbunArea, COOL_BUN_MEMORY_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void teardownBun() {
|
void teardownBun() {
|
||||||
FreeMem(coolbunArea, COOL_BUN_MEMORY_SIZE);
|
FreeMem(coolbunArea, COOL_BUN_MEMORY_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bun_offRightSide(int plusXValue, int y, struct ScreenSetup *screenSetup) {
|
void bun_offRightSide(int plusXValue, int y, struct CurrentScreen *currentScreen) {
|
||||||
uint8_t i, plane = 0;
|
uint8_t i, plane = 0;
|
||||||
uint8_t shift = plusXValue & 15;
|
uint8_t shift = plusXValue & 15;
|
||||||
uint8_t wordShift = (plusXValue >> 4);
|
uint8_t wordShift = (plusXValue >> 4);
|
||||||
uint16_t bltalwm;
|
uint16_t bltalwm;
|
||||||
|
|
||||||
for (plane = 0; plane < 2; ++plane) {
|
for (plane = 0; plane < 2; ++plane) {
|
||||||
custom.bltcon0 = 0xc0 + (1 << 8) + (1 << 10) + (shift << 12);
|
custom.bltcon0 = BLTCON0(0xc0, 0, 1, 0, 1, shift);
|
||||||
custom.bltcon1 = (shift << 12);
|
custom.bltcon1 = BLTCON1(0, shift);
|
||||||
|
|
||||||
custom.bltadat = 0xffff;
|
custom.bltadat = 0xffff;
|
||||||
custom.bltbpt = coolbunArea + plane * COOL_BUN_PLANE_SIZE;
|
custom.bltbpt = coolbunArea +
|
||||||
custom.bltdpt = screenSetup->memoryStart +
|
plane * COOL_BUN_PLANE_SIZE;
|
||||||
plane * screenSetup->nextBitplaneAdvance +
|
custom.bltdpt = currentScreen->planes[plane] +
|
||||||
(y * screenSetup.width + screenSetup.width - COOL_BUN_WIDTH) / 8
|
(y * currentScreen->byteWidth) +
|
||||||
+ wordShift * 2;
|
currentScreen->byteWidth - COOL_BUN_WIDTH_BYTES +
|
||||||
|
wordShift * 2;
|
||||||
|
|
||||||
custom.bltafwm = 0xffff;
|
custom.bltafwm = 0xffff;
|
||||||
bltalwm = 0x0000;
|
bltalwm = 0x0000;
|
||||||
|
@ -59,7 +85,8 @@ void bun_offRightSide(int plusXValue, int y, struct ScreenSetup *screenSetup) {
|
||||||
custom.bltalwm = bltalwm;
|
custom.bltalwm = bltalwm;
|
||||||
|
|
||||||
custom.bltbmod = wordShift * 2;
|
custom.bltbmod = wordShift * 2;
|
||||||
custom.bltdmod = (screenSetup.width - COOL_BUN_WIDTH) / 8 + wordShift * 2;
|
custom.bltdmod = currentScreen->byteWidth - COOL_BUN_WIDTH_BYTES +
|
||||||
|
wordShift * 2;
|
||||||
|
|
||||||
custom.bltsize = 2 - wordShift + (COOL_BUN_HEIGHT << 6);
|
custom.bltsize = 2 - wordShift + (COOL_BUN_HEIGHT << 6);
|
||||||
|
|
||||||
|
@ -67,11 +94,6 @@ void bun_offRightSide(int plusXValue, int y, struct ScreenSetup *screenSetup) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BLTCON0( \
|
|
||||||
minterm, aChan, bChan, cChan, dChan, shift \
|
|
||||||
) (minterm + (aChan << 11) + (bChan << 10) + (cChan << 9) + (dChan << 8) + (shift << 12)
|
|
||||||
#define BLTCON1(descending, shift) ((descending << 1) + (shift << 12))
|
|
||||||
|
|
||||||
void bun_offLeftSide(int minusXValue, int y, struct CurrentScreen *currentScreen) {
|
void bun_offLeftSide(int minusXValue, int y, struct CurrentScreen *currentScreen) {
|
||||||
unsigned char plane;
|
unsigned char plane;
|
||||||
uint8_t shift = minusXValue & 15;
|
uint8_t shift = minusXValue & 15;
|
||||||
|
@ -90,10 +112,15 @@ void bun_offLeftSide(int minusXValue, int y, struct CurrentScreen *currentScreen
|
||||||
// a has a mask we're shifting
|
// a has a mask we're shifting
|
||||||
custom.bltadat = 0xffff;
|
custom.bltadat = 0xffff;
|
||||||
// b has bun data
|
// b has bun data
|
||||||
custom.bltbpt = coolbunArea + 2 + ((COOL_BUN_HEIGHT - 1) * 4) + plane * COOL_BUN_PLANE_SIZE;
|
custom.bltbpt = coolbunArea + 2 +
|
||||||
|
COOL_BUN_LAST_ROW_BYTES +
|
||||||
|
plane * COOL_BUN_PLANE_SIZE;
|
||||||
|
|
||||||
// d is the part on screen
|
// 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.bltdpt = currentScreen->planes[plane] +
|
||||||
|
(currentScreen->byteWidth * (y + COOL_BUN_LAST_ROW)) +
|
||||||
|
2 -
|
||||||
|
wordShift * 2;
|
||||||
|
|
||||||
custom.bltafwm = 0xffff;
|
custom.bltafwm = 0xffff;
|
||||||
bltalwm = 0x0000;
|
bltalwm = 0x0000;
|
||||||
|
@ -103,7 +130,7 @@ void bun_offLeftSide(int minusXValue, int y, struct CurrentScreen *currentScreen
|
||||||
custom.bltalwm = bltalwm;
|
custom.bltalwm = bltalwm;
|
||||||
|
|
||||||
custom.bltbmod = wordShift * 2;
|
custom.bltbmod = wordShift * 2;
|
||||||
custom.bltdmod = screenSetup.width / 8 - 4 + wordShift * 2;
|
custom.bltdmod = currentScreen->byteWidth - 4 + wordShift * 2;
|
||||||
|
|
||||||
custom.bltsize = 2 - wordShift + (COOL_BUN_HEIGHT << 6);
|
custom.bltsize = 2 - wordShift + (COOL_BUN_HEIGHT << 6);
|
||||||
|
|
||||||
|
@ -111,7 +138,7 @@ void bun_offLeftSide(int minusXValue, int y, struct CurrentScreen *currentScreen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bun_anywhere(int x, int y, struct ScreenSetup *screenSetup) {
|
void bun_anywhere(int x, int y, struct CurrentScreen *currentScreen) {
|
||||||
uint8_t plane;
|
uint8_t plane;
|
||||||
uint8_t shift = x & 15;
|
uint8_t shift = x & 15;
|
||||||
uint8_t needsExtraWord = shift != 0;
|
uint8_t needsExtraWord = shift != 0;
|
||||||
|
@ -121,12 +148,13 @@ void bun_anywhere(int x, int y, struct ScreenSetup *screenSetup) {
|
||||||
|
|
||||||
// buns will never interfere with a background so they don't need a mask
|
// buns will never interfere with a background so they don't need a mask
|
||||||
// they do need the scratch area though
|
// they do need the scratch area though
|
||||||
custom.bltcon0 = 0xc0 + (1 << 8) + (1 << 10) + (shift << 12);
|
custom.bltcon0 = BLTCON0(0xc0, 0, 1, 0, 1, shift);
|
||||||
custom.bltcon1 = (shift << 12);
|
custom.bltcon1 = BLTCON1(0, shift);
|
||||||
|
|
||||||
custom.bltadat = 0xffff;
|
custom.bltadat = 0xffff;
|
||||||
custom.bltbpt = coolbunArea + plane * COOL_BUN_PLANE_SIZE;
|
custom.bltbpt = coolbunArea + plane * COOL_BUN_PLANE_SIZE;
|
||||||
custom.bltdpt = screenSetup.memoryStart + WORD_ALIGNED_BYTE_POSITION(screenSetup.width, x, y) + screenSetup.nextBitplaneAdvance * plane;
|
custom.bltdpt = currentScreen->planes[plane] +
|
||||||
|
WORD_ALIGNED_BYTE_POSITION(currentScreen->pixelWidth, x, y);
|
||||||
|
|
||||||
// custom.bltdpt = screenSetup.memoryStart;
|
// custom.bltdpt = screenSetup.memoryStart;
|
||||||
custom.bltafwm = 0xffff;
|
custom.bltafwm = 0xffff;
|
||||||
|
@ -135,8 +163,9 @@ void bun_anywhere(int x, int y, struct ScreenSetup *screenSetup) {
|
||||||
} else {
|
} else {
|
||||||
custom.bltalwm = 0xffff;
|
custom.bltalwm = 0xffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
custom.bltbmod = -(needsExtraWord * 2);
|
custom.bltbmod = -(needsExtraWord * 2);
|
||||||
custom.bltdmod = (screenSetup.width / 8) - COOL_BUN_WIDTH_BYTES - (needsExtraWord * 2);
|
custom.bltdmod = currentScreen->byteWidth - COOL_BUN_WIDTH_BYTES - (needsExtraWord * 2);
|
||||||
custom.bltsize = (2 + needsExtraWord) + (COOL_BUN_HEIGHT << 6);
|
custom.bltsize = (2 + needsExtraWord) + (COOL_BUN_HEIGHT << 6);
|
||||||
|
|
||||||
WaitBlit();
|
WaitBlit();
|
||||||
|
@ -157,7 +186,7 @@ void renderBun(int x, int y, struct CurrentScreen *currentScreen) {
|
||||||
|
|
||||||
if (x < 0) {
|
if (x < 0) {
|
||||||
bun_offLeftSide(-x, y, currentScreen);
|
bun_offLeftSide(-x, y, currentScreen);
|
||||||
} else if (x > screenSetup.width - COOL_BUN_WIDTH) {
|
} else if (x > currentScreen->pixelWidth - COOL_BUN_WIDTH) {
|
||||||
bun_offRightSide(x - (currentScreen->pixelWidth - COOL_BUN_WIDTH), y, currentScreen);
|
bun_offRightSide(x - (currentScreen->pixelWidth - COOL_BUN_WIDTH), y, currentScreen);
|
||||||
} else {
|
} else {
|
||||||
bun_anywhere(x, y, currentScreen);
|
bun_anywhere(x, y, currentScreen);
|
||||||
|
|
2
bun.h
2
bun.h
|
@ -4,7 +4,7 @@
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
|
|
||||||
void setupBun();
|
void setupBun();
|
||||||
void renderBun(int x, int y, struct ScreenSetup *screenSetup);
|
void renderBun(int x, int y, struct CurrentScreen *currentScreen);
|
||||||
void teardownBun();
|
void teardownBun();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
12
main.c
12
main.c
|
@ -46,12 +46,10 @@ int main(void) {
|
||||||
colors[2] = 0x0fff;
|
colors[2] = 0x0fff;
|
||||||
colors[3] = 0x000f;
|
colors[3] = 0x000f;
|
||||||
|
|
||||||
|
setupBun();
|
||||||
setupScreen(&screenSetup, SCREEN_WIDTH, SCREEN_HEIGHT, 3);
|
setupScreen(&screenSetup, SCREEN_WIDTH, SCREEN_HEIGHT, 3);
|
||||||
setupInitialCurrentScreen(&screenSetup, ¤tScreen);
|
setupInitialCurrentScreen(&screenSetup, ¤tScreen);
|
||||||
|
|
||||||
teardownScreen(&screenSetup);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
// blitter copy the first bitplane row down to the second
|
// blitter copy the first bitplane row down to the second
|
||||||
|
|
||||||
copperlist = prepareNewCopperlist();
|
copperlist = prepareNewCopperlist();
|
||||||
|
@ -59,8 +57,10 @@ int main(void) {
|
||||||
takeOverSystem();
|
takeOverSystem();
|
||||||
|
|
||||||
setCopperlist(copperlist);
|
setCopperlist(copperlist);
|
||||||
setUpDisplay(&screenSetup);
|
setUpDisplay((uint32_t)screenSetup.bitplanes);
|
||||||
|
|
||||||
|
// TODO: [ ] A struct that can be filled with the locations in the copperlist where
|
||||||
|
// bitplane addresses go
|
||||||
currentCopperlist = addDisplayToCopperlist(copperlist, &screenSetup);
|
currentCopperlist = addDisplayToCopperlist(copperlist, &screenSetup);
|
||||||
//currentCopperlist = addColorsToCopperlist(currentCopperlist, colors, 16);
|
//currentCopperlist = addColorsToCopperlist(currentCopperlist, colors, 16);
|
||||||
*(currentCopperlist++) = custom_color;
|
*(currentCopperlist++) = custom_color;
|
||||||
|
@ -107,7 +107,7 @@ int main(void) {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
renderBun(i, 45, &screenSetup);
|
renderBun(i, 45, ¤tScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 100; ++i) {
|
for (i = 0; i < 100; ++i) {
|
||||||
|
@ -116,7 +116,7 @@ int main(void) {
|
||||||
|
|
||||||
giveBackSystem();
|
giveBackSystem();
|
||||||
|
|
||||||
freeScreen(&screenSetup);
|
teardownScreen(&screenSetup);
|
||||||
|
|
||||||
freeCopperlist(copperlist);
|
freeCopperlist(copperlist);
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,8 @@
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
|
|
||||||
#define WORD_ALIGNED_BYTE_POSITION(width, x, y) (((width * y + x) >> 3) & 0xfffe)
|
|
||||||
#define WORD_ALIGNED_BYTE_X(x) (((x) >> 3) & 0xfffe)
|
|
||||||
|
|
||||||
|
/*
|
||||||
struct BlitAreaDetails {
|
struct BlitAreaDetails {
|
||||||
unsigned char *target;
|
unsigned char *target;
|
||||||
uint16_t drawAreaWidth;
|
uint16_t drawAreaWidth;
|
||||||
|
@ -77,5 +76,6 @@ void blit_marquee(
|
||||||
uint16_t ey,
|
uint16_t ey,
|
||||||
uint16_t ty
|
uint16_t ty
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
|
|
||||||
|
#define WORD_ALIGNED_BYTE_POSITION(width, x, y) (((width * y + x) >> 3) & 0xfffe)
|
||||||
|
#define WORD_ALIGNED_BYTE_X(x) (((x) >> 3) & 0xfffe)
|
||||||
|
|
||||||
// this needs to be kept in sync with the XDEFs in system.s
|
// this needs to be kept in sync with the XDEFs in system.s
|
||||||
|
|
||||||
// copperlist
|
// copperlist
|
||||||
|
@ -14,7 +17,7 @@ extern uint16_t* addColorsToCopperlist(uint16_t *copperlist, color_t[], int coun
|
||||||
|
|
||||||
extern void takeOverSystem(void);
|
extern void takeOverSystem(void);
|
||||||
extern void giveBackSystem(void);
|
extern void giveBackSystem(void);
|
||||||
extern void setUpDisplay(struct ScreenSetup *);
|
extern void setUpDisplay(uint32_t bitplaneCount);
|
||||||
|
|
||||||
extern void myWaitBlit(void);
|
extern void myWaitBlit(void);
|
||||||
extern uint16_t WaitBOF(uint16_t line);
|
extern uint16_t WaitBOF(uint16_t line);
|
||||||
|
|
|
@ -205,16 +205,17 @@ _endCopperlist:
|
||||||
|
|
||||||
RTS
|
RTS
|
||||||
|
|
||||||
; @stack *ScreenSetup
|
; @stack bitplaneCount
|
||||||
_setUpDisplay:
|
_setUpDisplay:
|
||||||
MOVE.L 4(A7),A0
|
MOVE.L D2,-(SP)
|
||||||
|
MOVE.L 4(A7),D2
|
||||||
|
|
||||||
LEA _custom,A1
|
LEA _custom,A1
|
||||||
|
|
||||||
MOVEQ #0,D0
|
MOVEQ #0,D0
|
||||||
MOVE.W #BPLCON0_COLOR,D0
|
MOVE.W #BPLCON0_COLOR,D0
|
||||||
MOVEQ #0,D1
|
MOVEQ #0,D1
|
||||||
MOVE.W ScreenSetup_bitplanes(A0),D1
|
MOVE.W D2,D1
|
||||||
AND.W #$7,D1
|
AND.W #$7,D1
|
||||||
ROL.W #8,D1
|
ROL.W #8,D1
|
||||||
ROL.W #4,D1
|
ROL.W #4,D1
|
||||||
|
@ -227,6 +228,7 @@ _setUpDisplay:
|
||||||
MOVE.W #$2cc1,diwstop(A1)
|
MOVE.W #$2cc1,diwstop(A1)
|
||||||
MOVE.W #$0038,ddfstrt(A1)
|
MOVE.W #$0038,ddfstrt(A1)
|
||||||
MOVE.W #$00d0,ddfstop(A1)
|
MOVE.W #$00d0,ddfstop(A1)
|
||||||
|
MOVE.L (SP)+,D2
|
||||||
|
|
||||||
RTS
|
RTS
|
||||||
|
|
||||||
|
|
1
types.h
1
types.h
|
@ -4,6 +4,7 @@
|
||||||
#include <exec/types.h>
|
#include <exec/types.h>
|
||||||
|
|
||||||
typedef unsigned short color_t;
|
typedef unsigned short color_t;
|
||||||
|
typedef unsigned long uint32_t;
|
||||||
typedef unsigned short uint16_t;
|
typedef unsigned short uint16_t;
|
||||||
typedef unsigned char uint8_t;
|
typedef unsigned char uint8_t;
|
||||||
typedef signed char int8_t;
|
typedef signed char int8_t;
|
||||||
|
|
Loading…
Reference in New Issue