diff --git a/bun.c b/bun.c index d000357..df79fbf 100644 --- a/bun.c +++ b/bun.c @@ -1,6 +1,18 @@ +// Custom +#include + +// WaitBlit() +#include + +// AllocMem(), FreeMem() +#include +#include + #include "screen.h" #include "bun.h" +#include "system/system.h" +// linked as raw bytes in assembler extern unsigned char far coolbun[]; unsigned char *coolbunArea; @@ -9,18 +21,28 @@ unsigned char *coolbunArea; #define COOL_BUN_WIDTH_BYTES (COOL_BUN_WIDTH / 8) #define COOL_BUN_HEIGHT (32) #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_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() { unsigned char *currentCoolBunArea, *currentCoolBun; + unsigned int x, y, plane; coolbunArea = AllocMem(COOL_BUN_MEMORY_SIZE, MEMF_CHIP | MEMF_CLEAR); + currentCoolBunArea = coolbunArea; currentCoolBun = coolbun; - currentCoolBunArea = coolbunArea; - + /* 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) { @@ -28,28 +50,32 @@ void setupBun() { } } } + */ + + CopyMem(coolbun, coolbunArea, COOL_BUN_MEMORY_SIZE); } void teardownBun() { 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 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.bltcon0 = BLTCON0(0xc0, 0, 1, 0, 1, shift); + custom.bltcon1 = BLTCON1(0, shift); custom.bltadat = 0xffff; - 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; + custom.bltbpt = coolbunArea + + plane * COOL_BUN_PLANE_SIZE; + custom.bltdpt = currentScreen->planes[plane] + + (y * currentScreen->byteWidth) + + currentScreen->byteWidth - COOL_BUN_WIDTH_BYTES + + wordShift * 2; custom.bltafwm = 0xffff; bltalwm = 0x0000; @@ -59,7 +85,8 @@ void bun_offRightSide(int plusXValue, int y, struct ScreenSetup *screenSetup) { custom.bltalwm = bltalwm; 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); @@ -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) { unsigned char plane; 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 custom.bltadat = 0xffff; // 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 - 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; bltalwm = 0x0000; @@ -103,7 +130,7 @@ void bun_offLeftSide(int minusXValue, int y, struct CurrentScreen *currentScreen custom.bltalwm = bltalwm; 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); @@ -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 shift = x & 15; 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 // they do need the scratch area though - custom.bltcon0 = 0xc0 + (1 << 8) + (1 << 10) + (shift << 12); - custom.bltcon1 = (shift << 12); + custom.bltcon0 = BLTCON0(0xc0, 0, 1, 0, 1, shift); + custom.bltcon1 = BLTCON1(0, shift); 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; + custom.bltdpt = currentScreen->planes[plane] + + WORD_ALIGNED_BYTE_POSITION(currentScreen->pixelWidth, x, y); // custom.bltdpt = screenSetup.memoryStart; custom.bltafwm = 0xffff; @@ -135,8 +163,9 @@ void bun_anywhere(int x, int y, struct ScreenSetup *screenSetup) { } else { custom.bltalwm = 0xffff; } + 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); WaitBlit(); @@ -157,7 +186,7 @@ void renderBun(int x, int y, struct CurrentScreen *currentScreen) { if (x < 0) { 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); } else { bun_anywhere(x, y, currentScreen); diff --git a/bun.h b/bun.h index 9cdc378..946c1b2 100644 --- a/bun.h +++ b/bun.h @@ -4,7 +4,7 @@ #include "screen.h" void setupBun(); -void renderBun(int x, int y, struct ScreenSetup *screenSetup); +void renderBun(int x, int y, struct CurrentScreen *currentScreen); void teardownBun(); #endif diff --git a/main b/main index 3aeb5e4..13f8c51 100755 Binary files a/main and b/main differ diff --git a/main.c b/main.c index 9d01e32..b53b1bb 100644 --- a/main.c +++ b/main.c @@ -46,12 +46,10 @@ int main(void) { colors[2] = 0x0fff; colors[3] = 0x000f; + setupBun(); setupScreen(&screenSetup, SCREEN_WIDTH, SCREEN_HEIGHT, 3); setupInitialCurrentScreen(&screenSetup, ¤tScreen); - teardownScreen(&screenSetup); - return 0; - // blitter copy the first bitplane row down to the second copperlist = prepareNewCopperlist(); @@ -59,8 +57,10 @@ int main(void) { takeOverSystem(); 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 = addColorsToCopperlist(currentCopperlist, colors, 16); *(currentCopperlist++) = custom_color; @@ -107,7 +107,7 @@ int main(void) { } */ - renderBun(i, 45, &screenSetup); + renderBun(i, 45, ¤tScreen); } for (i = 0; i < 100; ++i) { @@ -116,7 +116,7 @@ int main(void) { giveBackSystem(); - freeScreen(&screenSetup); + teardownScreen(&screenSetup); freeCopperlist(copperlist); diff --git a/system/blitter.h b/system/blitter.h index 48a4b4e..6cb5d92 100644 --- a/system/blitter.h +++ b/system/blitter.h @@ -4,9 +4,8 @@ #include "types.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 { unsigned char *target; uint16_t drawAreaWidth; @@ -77,5 +76,6 @@ void blit_marquee( uint16_t ey, uint16_t ty ); +*/ #endif diff --git a/system/system.h b/system/system.h index 91e9549..2ca58d3 100644 --- a/system/system.h +++ b/system/system.h @@ -4,6 +4,9 @@ #include "types.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 // copperlist @@ -14,7 +17,7 @@ extern uint16_t* addColorsToCopperlist(uint16_t *copperlist, color_t[], int coun extern void takeOverSystem(void); extern void giveBackSystem(void); -extern void setUpDisplay(struct ScreenSetup *); +extern void setUpDisplay(uint32_t bitplaneCount); extern void myWaitBlit(void); extern uint16_t WaitBOF(uint16_t line); diff --git a/system/system.s b/system/system.s index 3831408..678407b 100644 --- a/system/system.s +++ b/system/system.s @@ -205,28 +205,30 @@ _endCopperlist: RTS -; @stack *ScreenSetup +; @stack bitplaneCount _setUpDisplay: - MOVE.L 4(A7),A0 + MOVE.L D2,-(SP) + MOVE.L 4(A7),D2 - LEA _custom,A1 + LEA _custom,A1 - MOVEQ #0,D0 - MOVE.W #BPLCON0_COLOR,D0 - MOVEQ #0,D1 - MOVE.W ScreenSetup_bitplanes(A0),D1 - AND.W #$7,D1 - ROL.W #8,D1 - ROL.W #4,D1 - ADD.W D1,D0 - MOVE.W D0,bplcon0(A1) + MOVEQ #0,D0 + MOVE.W #BPLCON0_COLOR,D0 + MOVEQ #0,D1 + MOVE.W D2,D1 + AND.W #$7,D1 + ROL.W #8,D1 + ROL.W #4,D1 + ADD.W D1,D0 + MOVE.W D0,bplcon0(A1) - MOVE.W #0,bplcon1(A1) - MOVE.W #0,bpl1mod(A1) - MOVE.W #$2c21,diwstrt(A1) - MOVE.W #$2cc1,diwstop(A1) - MOVE.W #$0038,ddfstrt(A1) - MOVE.W #$00d0,ddfstop(A1) + MOVE.W #0,bplcon1(A1) + MOVE.W #0,bpl1mod(A1) + MOVE.W #$2c21,diwstrt(A1) + MOVE.W #$2cc1,diwstop(A1) + MOVE.W #$0038,ddfstrt(A1) + MOVE.W #$00d0,ddfstop(A1) + MOVE.L (SP)+,D2 RTS diff --git a/types.h b/types.h index 6e14f83..314a17e 100644 --- a/types.h +++ b/types.h @@ -4,6 +4,7 @@ #include typedef unsigned short color_t; +typedef unsigned long uint32_t; typedef unsigned short uint16_t; typedef unsigned char uint8_t; typedef signed char int8_t;