yeah it kinda works

This commit is contained in:
John Bintz 2024-05-27 16:50:56 -04:00
parent 2b24ebc602
commit 7374d8cad0
6 changed files with 85 additions and 328 deletions

BIN
main

Binary file not shown.

386
main.c
View File

@ -9,27 +9,16 @@
#include <graphics/gfx.h> #include <graphics/gfx.h>
#include "blitter.h" #include "system/blitter.h"
#include "copper.h" #include "system/copper.h"
#include "system/system.h"
#include "screen.h" #include "screen.h"
#include "types.h" #include "types.h"
#include "system.h"
extern struct Custom far custom; extern struct Custom far custom;
extern unsigned char far coolbun[]; extern unsigned char far coolbun[];
void writeSomethingToScreen(struct ScreenSetup *screenSetup) {
*(screenSetup->memoryStart) = 255;
*(screenSetup->memoryStart + 8) = 0xAA;
*(screenSetup->memoryStart + 16) = 0xF0;
*(screenSetup->memoryStart + SCREEN_WIDTH * SCREEN_HEIGHT / 8 + 4) = 255;
}
// [ ] increase the size of the bun area
// [ ] ensure the area has the correct data
// [ ] fix existing edge writes to work
// [ ] change non-edge write to use only bun area
#define COOL_BUN_WIDTH (32) #define COOL_BUN_WIDTH (32)
#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)
@ -50,24 +39,6 @@ unsigned char *coolbunArea;
unsigned char *scratchArea; unsigned char *scratchArea;
struct ScreenSetup screenSetup; struct ScreenSetup screenSetup;
void clearScratchArea() {
custom.bltcon0 = 0xf0 + (1 << 8);
custom.bltcon1 = 0;
custom.bltadat = 0x0000;
custom.bltafwm = 0xffff;
custom.bltalwm = 0xffff;
custom.bltdpt = scratchArea;
custom.bltamod = 0;
custom.bltdmod = 0;
custom.bltsize = (4) + (32 << 6);
WaitBlit();
}
void bun_offRightSide(int plusXValue, int y) { void bun_offRightSide(int plusXValue, int y) {
uint8_t i, plane = 0; uint8_t i, plane = 0;
uint8_t shift = plusXValue & 15; uint8_t shift = plusXValue & 15;
@ -75,51 +46,24 @@ void bun_offRightSide(int plusXValue, int y) {
uint16_t bltalwm; uint16_t bltalwm;
for (plane = 0; plane < 2; ++plane) { for (plane = 0; plane < 2; ++plane) {
clearScratchArea();
// step 2: copy bun to scratch area that aligns right edge to word edge
// right shift so it's ascending.
custom.bltcon0 = 0xc0 + (1 << 8) + (1 << 10) + (shift << 12); custom.bltcon0 = 0xc0 + (1 << 8) + (1 << 10) + (shift << 12);
custom.bltcon1 = (shift << 12); custom.bltcon1 = (shift << 12);
custom.bltadat = 0xffff; custom.bltadat = 0xffff;
custom.bltafwm = 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;
bltalwm = 0xffff; custom.bltafwm = 0xffff;
for (i = 0; i < shift; ++i) { bltalwm = 0x0000;
bltalwm -= (1 << i); for (i = 0; i < 15 - shift; ++i) {
bltalwm += (1 << (15 - i));
} }
custom.bltalwm = bltalwm; custom.bltalwm = bltalwm;
custom.bltbpt = coolbunArea + (plane * COOL_BUN_WIDTH_BYTES * COOL_BUN_HEIGHT);
custom.bltdpt = scratchArea + 2 + (wordShift * 2);
custom.bltamod = 0;
custom.bltbmod = wordShift * 2; custom.bltbmod = wordShift * 2;
custom.bltdmod = SCRATCH_AREA_WIDTH_BYTES - 4 + (wordShift * 2); custom.bltdmod = (screenSetup.width - COOL_BUN_WIDTH) / 8 + wordShift * 2;
// TODO: [ ] handle a scroll larger than 16px custom.bltsize = 2 - wordShift + (COOL_BUN_HEIGHT << 6);
custom.bltsize = (2 - wordShift) + (32 << 6);
WaitBlit();
// step 3: copy the cropped bun image to the main screen, already left
// aligned and with no fear of wraparound
// since buns are the back layer, we shouldn't need to preserve the
// background, so no c channel needed.
//
// y repeats go here. all buns are x aligned for simplicity.
custom.bltcon0 = 0xf0 + (1 << 8) + (1 << 11);
custom.bltcon1 = 0;
custom.bltapt = scratchArea + 2 + (wordShift * 2);
custom.bltafwm = 0xffff;
custom.bltalwm = 0xffff;
custom.bltdpt = screenSetup.memoryStart + 30 + (wordShift * 2) + (screenSetup.nextBitplaneAdvance * plane) + (screenSetup.width / 8 * y);
custom.bltamod = 4 + (wordShift * 2);
custom.bltdmod = (screenSetup.width / 8) - 4 + (wordShift * 2);
custom.bltsize = (2 - wordShift) + (32 << 6);
WaitBlit(); WaitBlit();
} }
@ -131,65 +75,34 @@ void bun_offLeftSide(int minusXValue, int y) {
uint8_t wordShift = (minusXValue >> 4); uint8_t wordShift = (minusXValue >> 4);
uint8_t i; uint8_t i;
uint16_t bltalwm; uint16_t bltalwm;
/**
* This is a three step process, repeated for each bitplane: // y can't be 0 otherwise we will corrupt memory for now
* if (y == 0) return;
* * clean out the scratch plane
* * copy the bun graphic shifted left so that the third blit...
* * can pick up just that area and stamp it down.
*/
for (plane = 0; plane < 2; ++plane) { for (plane = 0; plane < 2; ++plane) {
// step 1: clear the scratch area // shift left, so desccending
// no modifications here!
clearScratchArea();
// step 2: copy the bun image to the scratch area in a way that aligns
// the cutoff point to a word edge. this requires a left shift, so
// it's descending.
custom.bltcon0 = 0xc0 + (1 << 8) + (1 << 10) + (shift << 12); custom.bltcon0 = 0xc0 + (1 << 8) + (1 << 10) + (shift << 12);
custom.bltcon1 = (1 << 1) + (shift << 12); custom.bltcon1 = (1 << 1) + (shift << 12);
// a has a mask we're shifting
custom.bltadat = 0xffff; custom.bltadat = 0xffff;
custom.bltafwm = 0xffff; // b has bun data
custom.bltbpt = coolbunArea + 2 + ((COOL_BUN_HEIGHT - 1) * 4) + plane * COOL_BUN_PLANE_SIZE;
bltalwm = 0xffff; // d is the part on screen
for (i = 0; i < shift; ++i) { custom.bltdpt = screenSetup.memoryStart + screenSetup.nextBitplaneAdvance * plane + (screenSetup.width * (y + COOL_BUN_HEIGHT - 1) / 8) + 2 - wordShift * 2;
bltalwm -= (1 << (15 - i));
custom.bltafwm = 0xffff;
bltalwm = 0x0000;
for (i = 0; i < 15 - shift; ++i) {
bltalwm += (1 << i);
} }
custom.bltalwm = bltalwm; custom.bltalwm = bltalwm;
// TODO: [ ] handle a scroll larger than 16px
custom.bltbpt = coolbunArea + 2 + ((COOL_BUN_HEIGHT - 1) * COOL_BUN_WIDTH_BYTES) + (plane * COOL_BUN_WIDTH_BYTES * COOL_BUN_HEIGHT);
custom.bltdpt = scratchArea + 4 - (wordShift * 2) + ((COOL_BUN_HEIGHT - 1) * SCRATCH_AREA_WIDTH_BYTES);
custom.bltamod = 0;
custom.bltbmod = wordShift * 2; custom.bltbmod = wordShift * 2;
custom.bltdmod = SCRATCH_AREA_WIDTH_BYTES - 4 + (wordShift * 2); custom.bltdmod = screenSetup.width / 8 - 4 + wordShift * 2;
// TODO: [ ] handle a scroll larger than 16px custom.bltsize = 2 - wordShift + (COOL_BUN_HEIGHT << 6);
custom.bltsize = (2 - wordShift) + (32 << 6);
WaitBlit();
// step 3: copy the cropped bun image to the main screen, already left
// aligned and with no fear of wraparound
// since buns are the back layer, we shouldn't need to preserve the
// background, so no c channel needed.
//
// y repeats go here. all buns are x aligned for simplicity.
custom.bltcon0 = 0xf0 + (1 << 8) + (1 << 11);
custom.bltcon1 = 0;
custom.bltapt = scratchArea + 2;
custom.bltafwm = 0xffff;
custom.bltalwm = 0xffff;
custom.bltdpt = screenSetup.memoryStart + (screenSetup.nextBitplaneAdvance * plane) + (screenSetup.width / 8 * y);
custom.bltamod = 4 + (wordShift * 2);
custom.bltdmod = (screenSetup.width / 8) - 4 + (wordShift * 2);
custom.bltsize = (2 - wordShift) + (32 << 6);
WaitBlit(); WaitBlit();
} }
@ -205,29 +118,40 @@ void bun_anywhere(int x, int y) {
// 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 = 0xf0 + (1 << 8) + (1 << 11) + (shift << 12); custom.bltcon0 = 0xc0 + (1 << 8) + (1 << 10) + (shift << 12);
custom.bltcon1 = 0; 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;
custom.bltapt = coolbunArea + (COOL_BUN_HEIGHT * COOL_BUN_WIDTH_BYTES * plane);
custom.bltdpt = scratchArea + 2;
// custom.bltdpt = screenSetup.memoryStart; // custom.bltdpt = screenSetup.memoryStart;
custom.bltafwm = 0xffff; custom.bltafwm = 0xffff;
if (needsExtraWord) {
custom.bltalwm = 0x0000;
} else {
custom.bltalwm = 0xffff; custom.bltalwm = 0xffff;
custom.bltamod = 0; }
custom.bltdmod = 4 - (needsExtraWord * 2); custom.bltbmod = -(needsExtraWord * 2);
custom.bltsize = (2 + needsExtraWord) + (32 << 6); custom.bltdmod = (screenSetup.width / 8) - COOL_BUN_WIDTH_BYTES - (needsExtraWord * 2);
custom.bltsize = (2 + needsExtraWord) + (COOL_BUN_HEIGHT << 6);
WaitBlit(); WaitBlit();
}
}
custom.bltcon0 = 0xf0 + (1 << 8) + (1 << 11); void renderBun(int x, int y) {
custom.bltcon1 = 0; if (x < -31) return;
custom.bltapt = scratchArea + 2; if (x > screenSetup.width + 31) return;
custom.bltdpt = screenSetup.memoryStart + WORD_ALIGNED_BYTE_POSITION(screenSetup.width, x, y) + (screenSetup.nextBitplaneAdvance * plane); if (y < 1) return;
custom.bltamod = 2; if (y > screenSetup.height - COOL_BUN_HEIGHT - 1) return;
custom.bltdmod = 40 - 6;
custom.bltsize = (3) + (32 << 6);
WaitBlit(); 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);
} }
} }
@ -279,199 +203,21 @@ int main(void) {
currentCopperlist = addColorsToCopperlist(currentCopperlist, colors, 16); currentCopperlist = addColorsToCopperlist(currentCopperlist, colors, 16);
endCopperlist(currentCopperlist); endCopperlist(currentCopperlist);
custom.bltcon0 = 0xc0 + (1 << 10) + (1 << 8); for (i = -31; i < screenSetup.width - 1; ++i) {
custom.bltcon1 = (8 << 12); y = WaitBOF(250);
custom.bltadat = 0xffff;
custom.bltafwm = 0x00ff;
custom.bltalwm = 0x0000;
custom.bltbpt = coolbunArea;
custom.bltdpt = screenSetup.memoryStart + (40 * 10 + 36);
custom.bltbmod = -2;
custom.bltdmod = 40 - 6;
custom.bltsize = (3) + (32 << 6);
WaitBlit();
custom.bltcon0 = 0xc0 + (1 << 10) + (1 << 8);
custom.bltcon1 = (15 << 12);
custom.bltadat = 0xffff;
custom.bltafwm = 0x0001;
custom.bltalwm = 0x0000;
custom.bltbpt = coolbunArea;
custom.bltdpt = screenSetup.memoryStart + (40 * 45 + 36);
custom.bltbmod = -2;
custom.bltdmod = 40 - 6;
custom.bltsize = (3) + (32 << 6);
WaitBlit();
custom.bltcon0 = 0xc0 + (1 << 10) + (1 << 8);
custom.bltcon1 = (8 << 12);
custom.bltadat = 0xffff;
custom.bltafwm = 0x00ff;
custom.bltalwm = 0x0000;
custom.bltbpt = coolbunArea;
custom.bltdpt = screenSetup.memoryStart + (40 * 80 + 38);
custom.bltbmod = 0;
custom.bltdmod = 40 - 4;
custom.bltsize = (2) + (32 << 6);
WaitBlit();
/*
for (bunPosition = -31; bunPosition < screenSetup.width + 31; ++bunPosition) {
for (plane = 0; plane < 2; ++plane) { for (plane = 0; plane < 2; ++plane) {
custom.bltcon0 = 0xf0 + (1 << 11); custom.bltcon0 = 0xc0 + (1 << 8);
custom.bltcon1 = 0; custom.bltcon1 = 0;
custom.bltadat = 0x0000; custom.bltadat = 0x0000;
custom.bltdpt = screenSetup.memoryStart;
custom.bltafwm = 0xffff; custom.bltafwm = 0xffff;
custom.bltalwm = 0xffff; custom.bltalwm = 0xffff;
custom.bltsize = (20) + (256 << 6); custom.bltdpt = screenSetup.memoryStart + (45 * screenSetup.width) / 8 + plane * screenSetup.nextBitplaneAdvance;
custom.bltdmod = 0;
custom.bltsize = 20 + (COOL_BUN_MEMORY_SIZE << 6);
WaitBlit(); WaitBlit();
} }
if (bunPosition < 0) { renderBun(i, 45);
//bun_offLeftSide(abs(bunPosition), 100);
} else if (bunPosition >= screenSetup.width) {
//bun_offRightSide(bunPosition - screenSetup.width - 1, 100);
} else {
bun_anywhere(bunPosition, 100);
}
WaitTOF();
WaitTOF();
}
/*
for (i = 0; i < 32; ++i) {
for (plane = 0; plane < 2; ++plane) {
custom.bltcon0 = 0xf0 + (1 << 8);
custom.bltcon1 = 0;
custom.bltadat = 0x0000;
custom.bltdpt = screenSetup.memoryStart;
custom.bltafwm = 0x0000;
custom.bltalwm = 0x0000;
custom.bltsize = (20) + (256 << 6);
WaitBlit();
}
bun_offLeftSide(i, 100);
bun_offRightSide(i, 100);
WaitTOF();
WaitTOF();
}
/*
// left shift this over 8 so it's "against the edge"
custom.bltcon0 = 0xc0 + (1 << 8) + (1 << 10) + (1 << 11) + (0 << 12);
custom.bltcon1 = (1 << 1) + (0 << 12);
custom.bltafwm = 0xffff;
custom.bltalwm = 0xffff;
custom.bltapt = coolbunScratchArea + 4 + (32 * 8);
custom.bltbpt = coolbunScratchArea + 4 + (31 * 8);
custom.bltdpt = screenSetup.memoryStart + 2 + (32 * 40);
custom.bltamod = -4;
custom.bltbmod = 4;
custom.bltdmod = 40 - 4;
custom.bltsize = (2) + (32 << 6);
WaitBlit();
/*
// left shift this over 8 so it's "against the edge"
custom.bltcon0 = 0xc0 + (1 << 8) + (1 << 10) + (1 << 11) + (abs(x) << 12);
custom.bltcon1 = (1 << 1) + (abs(x) << 12);
custom.bltafwm = 0xffff;
custom.bltalwm = 0xffff;
custom.bltapt = coolbunScratchArea + 2 + (32 * 8) + 4;
custom.bltbpt = coolbunScratchArea + 2 + 4 + (31 * 8);
custom.bltdpt = screenSetup.memoryStart + 4 + (31 * 40);
custom.bltamod = -6;
custom.bltbmod = 2;
custom.bltdmod = 40 - 6;
custom.bltsize = (1) + (32 << 6);
WaitBlit();
*/
WaitTOF();
/*
for (x = -15; x < 0; ++x) {
custom.bltcon0 = 0xf0 + (1 << 8);
custom.bltcon1 = 0;
custom.bltadat = 0xffff;
result = 0xffff;
for (i = 0; i < abs(x); ++i) {
result -= (1 << (15 - i));
}
custom.bltafwm = result;
custom.bltalwm = 0xffff;
custom.bltdpt = coolbunScratchArea + 2 + (32 * 8);
custom.bltsize = (2) + (1 << 6);
WaitBlit();
// left shift this over 8 so it's "against the edge"
custom.bltcon0 = 0xc0 + (1 << 8) + (1 << 10) + (1 << 11) + (abs(x) << 12);
custom.bltcon1 = (1 << 1) + (abs(x) << 12);
custom.bltafwm = 0xffff;
custom.bltalwm = 0xffff;
custom.bltapt = coolbunScratchArea + 2 + (32 * 8) + 4;
custom.bltbpt = coolbunScratchArea + 2 + 4 + (31 * 8);
custom.bltdpt = screenSetup.memoryStart + 4 + (31 * 40);
custom.bltamod = -6;
custom.bltbmod = 2;
custom.bltdmod = 40 - 6;
custom.bltsize = (3) + (32 << 6);
WaitBlit();
WaitTOF();
}
/*
for (x = 15; x < 17; ++x) {
for (plane = 0; plane < COOL_BUN_PLANES; ++plane) {
blitShiftRight = x & 15;
memoryXOffset = (x >> 3) & 0xfffe;
blitWidth = (blitShiftRight > 0) ? 6 : 4;
custom.bltcon0 = 0xf0 + (1 << 8) + (1 << 11) + (blitShiftRight << 12);
custom.bltcon1 = 0;
custom.bltapt = coolbunScratchArea + 2 + (COOL_BUN_PLANE_SIZE * plane);
custom.bltdpt = screenSetup.memoryStart + memoryXOffset + screenSetup.nextBitplaneAdvance * plane;
custom.bltafwm = 0xffff;
custom.bltalwm = 0xffff;
custom.bltamod = 8 - blitWidth;
custom.bltdmod = 40 - blitWidth;
custom.bltsize = (blitWidth / 2) + (32 << 6);
WaitBlit();
}
WaitTOF();
}
*/
for (i = 0; i < 100; ++i) {
WaitTOF();
} }
giveBackSystem(); giveBackSystem();
@ -480,16 +226,6 @@ int main(void) {
freeCopperlist(copperlist); freeCopperlist(copperlist);
for (y = 0; y < 32; ++y) {
for (x = 0; x < SCRATCH_AREA_WIDTH_BYTES; ++x) {
printf("%d ", scratchArea[y * SCRATCH_AREA_WIDTH_BYTES + x]);
}
printf("\n");
}
printf("%d\n", 16 & 15);
FreeMem(coolbunArea, COOL_BUN_MEMORY_SIZE); FreeMem(coolbunArea, COOL_BUN_MEMORY_SIZE);
FreeMem(scratchArea, SCRATCH_AREA_MEMORY_SIZE); FreeMem(scratchArea, SCRATCH_AREA_MEMORY_SIZE);

View File

@ -30,4 +30,5 @@ void prepareScreen(
screenSetup->height = height; screenSetup->height = height;
screenSetup->bitplanes = bitplanes; screenSetup->bitplanes = bitplanes;
screenSetup->nextBitplaneAdvance = width * height / 8; screenSetup->nextBitplaneAdvance = width * height / 8;
screenSetup->currentBuffer = 0;
} }

View File

@ -9,13 +9,14 @@ struct ScreenSetup {
short int bitplanes; short int bitplanes;
unsigned char *memoryStart; unsigned char *memoryStart;
short int nextBitplaneAdvance; short int nextBitplaneAdvance;
};
short int currentBuffer;
};
#define SCREEN_WIDTH (320) #define SCREEN_WIDTH (320)
#define SCREEN_HEIGHT (256) #define SCREEN_HEIGHT (256)
#define TOTAL_SCREEN_SETUP_SIZE(s) ((s->width / 8) * s->height * s->bitplanes) #define TOTAL_SCREEN_SETUP_SIZE(s) ((s->width / 8) * s->height * s->bitplanes * 2)
void allocateScreenMemory(struct ScreenSetup *screenSetup); void allocateScreenMemory(struct ScreenSetup *screenSetup);
void freeScreenMemory(struct ScreenSetup *screenSetup); void freeScreenMemory(struct ScreenSetup *screenSetup);

View File

@ -17,5 +17,6 @@ extern void giveBackSystem(void);
extern void setUpDisplay(struct ScreenSetup *); extern void setUpDisplay(struct ScreenSetup *);
extern void myWaitBlit(void); extern void myWaitBlit(void);
extern uint16_t WaitBOF(uint16_t line);
#endif #endif

View File

@ -6,6 +6,7 @@
XDEF _addColorsToCopperlist XDEF _addColorsToCopperlist
XDEF _endCopperlist XDEF _endCopperlist
XDEF _myWaitBlit XDEF _myWaitBlit
XDEF _WaitBOF
XREF _custom XREF _custom
@ -243,6 +244,23 @@ _myWaitBlit:
.done: .done:
RTS RTS
_WaitBOF:
MOVE.W 6(A7),D1
ROL.W #8,D1
MOVE.L $dff004,D0
AND.L #$1ff00,D0
CMP.L D1,D0
BNE.B _WaitBOF
.loop2:
MOVE.L $dff004,D0
AND.L #$1ff00,D0
CMP.L D1,D0
BEQ.B .loop2
RTS
CNOP 0,4 CNOP 0,4
OldView dc.l 0 OldView dc.l 0
OldCopper dc.l 0 OldCopper dc.l 0