diff --git a/32x50 b/32x50 index d1d709a..45f17fa 100755 Binary files a/32x50 and b/32x50 differ diff --git a/32x50_bun.c b/32x50_bun.c index f5582e0..a7caefe 100644 --- a/32x50_bun.c +++ b/32x50_bun.c @@ -4,24 +4,31 @@ */ #include +#include + +#include #include "system/system.h" #include "system/copper.h" +#include "system/blitter.h" #include "screen.h" extern struct Custom far custom; +extern struct CIA far ciaa; uint16_t custom_color = (uint16_t)offsetof(Custom, color); uint16_t custom_sprite = (uint16_t)offsetof(Custom, sprpt); uint16_t custom_sprite_control = (uint16_t)offsetof(Custom, spr); +extern unsigned char chip coolbun[]; + int main(void) { struct ScreenDefinition screenDefinition; struct ActiveScreenBufferDetails activeScreenBufferDetails; uint16_t *copperlist, *currentCopperlist; void *copperlistBitplanePointers[8][2]; - int i; + int i, plane; allocateDoubleBufferedScreenMemory( &screenDefinition, @@ -43,6 +50,7 @@ int main(void) { COPPERLIST_MOVE(currentCopperlist, custom_color, 0x3a6); COPPERLIST_MOVE(currentCopperlist, custom_color + 2, 0x000); COPPERLIST_MOVE(currentCopperlist, custom_color + 4, 0xfff); + currentCopperlist = setUpEmptySpritesInCopperlist(currentCopperlist); endCopperlist(currentCopperlist); @@ -51,8 +59,27 @@ int main(void) { setCopperlist(copperlist); setUpDisplay((uint32_t)screenDefinition.bitplanes); - for (i = 0; i < 100000; ++i) { + // Render a bun at 32x50 + for (plane = 0; plane < 2; ++plane) { + custom.bltcon0 = BLTCON0(0xf0, 1, 0, 0, 1, 0); + custom.bltcon1 = BLTCON1(BLITTER_ASCENDING, 0); + + custom.bltapt = coolbun + (plane * 4 * 32); + custom.bltdpt = activeScreenBufferDetails.planes[plane] + (50 * 320 / 8) + 32 / 8; + custom.bltafwm = 0xffff; + custom.bltalwm = 0xffff; + + custom.bltamod = 0; + custom.bltdmod = 40 - 4; + + custom.bltsize = 2 + (32 << 6); + + WaitBlit(); + } + + while (1) { + if ((ciaa.ciapra >> 6) != 3) break; } giveBackSystem(); diff --git a/33x50 b/33x50 new file mode 100755 index 0000000..80367b7 Binary files /dev/null and b/33x50 differ diff --git a/33x50_bun.c b/33x50_bun.c new file mode 100644 index 0000000..b5ceba7 --- /dev/null +++ b/33x50_bun.c @@ -0,0 +1,127 @@ +/** +* What do we need +* * [ ] screen setup +*/ + +#include +#include + +#include + +#include "system/system.h" +#include "system/copper.h" +#include "system/blitter.h" + +#include "screen.h" + +extern struct Custom far custom; +extern struct CIA far ciaa; + +uint16_t custom_color = (uint16_t)offsetof(Custom, color); +uint16_t custom_sprite = (uint16_t)offsetof(Custom, sprpt); +uint16_t custom_sprite_control = (uint16_t)offsetof(Custom, spr); + +extern unsigned char chip coolbun[]; + +int main(void) { + struct ScreenDefinition screenDefinition; + struct ActiveScreenBufferDetails activeScreenBufferDetails; + uint16_t *copperlist, *currentCopperlist; + void *copperlistBitplanePointers[8][2]; + int i, plane, x, y, dirX, dirY, shift, byteX; + + allocateDoubleBufferedScreenMemory( + &screenDefinition, + &activeScreenBufferDetails, + 320, + 256, + 2 + ); + + copperlist = prepareNewCopperlist(300); + + currentCopperlist = addDisplayToCopperlist( + copperlist, + &screenDefinition, + &activeScreenBufferDetails, + &copperlistBitplanePointers + ); + + COPPERLIST_MOVE(currentCopperlist, custom_color, 0x3a6); + COPPERLIST_MOVE(currentCopperlist, custom_color + 2, 0x000); + COPPERLIST_MOVE(currentCopperlist, custom_color + 4, 0xfff); + currentCopperlist = setUpEmptySpritesInCopperlist(currentCopperlist); + + endCopperlist(currentCopperlist); + + takeOverSystem(); + + setCopperlist(copperlist); + setUpDisplay((uint32_t)screenDefinition.bitplanes); + + // Render a bun at 32x50 + + x = 32; + y = 50; + dirX = 1; + dirY = 1; + + while (1) { + WaitTOF(); + + swapCurrentScreenBuffer(&screenDefinition, &activeScreenBufferDetails); + + shift = x & 15; + byteX = (x >> 4 * 2); + + for (plane = 0; plane < 2; ++plane) { + custom.bltcon0 = BLTCON0(0xf0, 1, 0, 0, 1, shift); + custom.bltcon1 = BLTCON1(BLITTER_ASCENDING, 0); + + custom.bltapt = coolbun + (plane * 4 * 32); + custom.bltdpt = activeScreenBufferDetails.planes[plane] + (y * 320 / 8) + byteX; + custom.bltafwm = 0xffff; + + if (shift == 0) { + custom.bltalwm = 0xffff;; + } else { + custom.bltalwm = 0x0000; + } + + custom.bltamod = shift ? -2 : 0; + custom.bltdmod = 40 - (shift ? 6 : 4); + + custom.bltsize = (shift ? 3 : 2) + (32 << 6); + + WaitBlit(); + } + + x += dirX; + if (x == 320 - 32) { + x -= 1; + dirX = -dirX; + } + if (x < 0) { + x = 0; + dirX = -dirX; + } + + y += dirY; + if (y == 256 - 32) { + y -= 1; + dirY = -dirY; + } + if (y > 0) { + y = 0; + dirY -= dirY; + } + + if ((ciaa.ciapra >> 6) != 3) break; + } + + giveBackSystem(); + + freeCopperlist(copperlist); + + teardownScreen(&screenDefinition); +} diff --git a/NOTES.md b/NOTES.md deleted file mode 100644 index bd2475e..0000000 --- a/NOTES.md +++ /dev/null @@ -1 +0,0 @@ -* [ ] Move bun calculation to separate file for CuTest and vamos diff --git a/README.md b/README.md index 40c2274..d002a4d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,35 @@ +## Cool Bun Demo + +![demo](./demo.gif) + +Built for [The Obligatory Amiga Blitter Video](https://makertube.net/w/eV545ku522sRq8CTcxDuFZ). + ## Running -`main` +* `main`: Main demo +* `32x50`, `33x50`, `left_side`, `right_side`: Rendering Cool Bun in various + locations on screen. +* `any_position`: Cool Bun flies around like a DVD player pause screen. -This will get 50FPS on an 020, and 25 or lower on an 68EC020 and below. +This will get 50 fps on an 020, and 25 or lower on an 68EC020 and below. + +## Building + +### Vamos + +You'll want [Vamos](https://github.com/cnvogelg/amitools/blob/master/docs/vamos.md) +and [SAS/C](https://www.amigaclub.be/blog/steffest/2/amiga-c%20compilers) +on Vamos's path: + +``` +# main +ruby ./image_converter.rb && touch images.s && vamos -- smake + +# any others +vamos -- smake +``` + +## Performance The best way I can think of to make this way faster is for a script in Ruby or Python to calculate every blitter register for every frame of data @@ -10,13 +37,3 @@ for bun renders and clears, store that in a list of words, and rip through those lists in Assembler, shotgunning the values directly into the registers without the C code needing to track bun positions and bun clears. That's a project for another day. - -## Building - -### Vamos - -You'll want Vamos and SAS/C on Vamos's path: - -``` -ruby ./image_converter.rb && touch images.s && vamos -- smake -``` diff --git a/any_position b/any_position new file mode 100755 index 0000000..2fb25b3 Binary files /dev/null and b/any_position differ diff --git a/any_position.c b/any_position.c new file mode 100644 index 0000000..b669b82 --- /dev/null +++ b/any_position.c @@ -0,0 +1,144 @@ +/** +* What do we need +* * [ ] screen setup +*/ + +#include +#include + +#include + +#include "system/system.h" +#include "system/copper.h" +#include "system/blitter.h" + +#include "screen.h" + +extern struct Custom far custom; +extern struct CIA far ciaa; + +uint16_t custom_color = (uint16_t)offsetof(Custom, color); +uint16_t custom_sprite = (uint16_t)offsetof(Custom, sprpt); +uint16_t custom_sprite_control = (uint16_t)offsetof(Custom, spr); + +extern unsigned char chip coolbun[]; + +int main(void) { + struct ScreenDefinition screenDefinition; + struct ActiveScreenBufferDetails activeScreenBufferDetails; + uint16_t *copperlist, *currentCopperlist; + void *copperlistBitplanePointers[8][2]; + int i, plane, x, y, dirX, dirY, shift, byteX, clearY; + + allocateDoubleBufferedScreenMemory( + &screenDefinition, + &activeScreenBufferDetails, + 320, + 256, + 2 + ); + + copperlist = prepareNewCopperlist(300); + + currentCopperlist = addDisplayToCopperlist( + copperlist, + &screenDefinition, + &activeScreenBufferDetails, + &copperlistBitplanePointers + ); + + COPPERLIST_MOVE(currentCopperlist, custom_color, 0x3a6); + COPPERLIST_MOVE(currentCopperlist, custom_color + 2, 0x000); + COPPERLIST_MOVE(currentCopperlist, custom_color + 4, 0xfff); + currentCopperlist = setUpEmptySpritesInCopperlist(currentCopperlist); + + endCopperlist(currentCopperlist); + + takeOverSystem(); + + setCopperlist(copperlist); + setUpDisplay((uint32_t)screenDefinition.bitplanes); + + // Render a bun at 32x50 + + x = 32; + y = 50; + dirX = 1; + dirY = 1; + + while (1) { + WaitTOF(); + + swapCurrentScreenBuffer(&screenDefinition, &activeScreenBufferDetails); + + shift = x & 15; + byteX = ((x >> 4) * 2); + clearY = y - 4; + if (clearY < 0) clearY = 0; + if (clearY + 40 > 255) clearY = 255 - 40; + + for (plane = 0; plane < 2; ++plane) { + custom.bltcon0 = BLTCON0(0xc0, 0, 0, 0, 1, 0); + custom.bltcon1 = 0; + + custom.bltadat = 0x0000; + custom.bltdpt = activeScreenBufferDetails.planes[plane] + (clearY * 320 / 8); + custom.bltafwm = 0xffff; + custom.bltalwm = 0xffff; + custom.bltsize = BLTSIZE(20, 40); + custom.bltdmod = 0; + + WaitBlit(); + } + + for (plane = 0; plane < 2; ++plane) { + custom.bltcon0 = BLTCON0(0xf0, 1, 0, 0, 1, shift); + custom.bltcon1 = BLTCON1(BLITTER_ASCENDING, 0); + + custom.bltapt = coolbun + (plane * 4 * 32); + custom.bltdpt = activeScreenBufferDetails.planes[plane] + (y * 320 / 8) + byteX; + custom.bltafwm = 0xffff; + + if (shift == 0) { + custom.bltalwm = 0xffff;; + } else { + custom.bltalwm = 0x0000; + } + + custom.bltamod = shift ? -2 : 0; + custom.bltdmod = 40 - (shift ? 6 : 4); + + custom.bltsize = (shift ? 3 : 2) + (32 << 6); + + WaitBlit(); + } + + x += dirX; + if (x == 320 - 32) { + x -= 1; + dirX = -dirX; + } + if (x < 0) { + x = 0; + dirX = -dirX; + } + + y += dirY; + if (y == 256 - 32) { + y -= 1; + dirY = -dirY; + } + if (y < 0) { + y = 0; + dirY = -dirY; + } + + if ((ciaa.ciapra >> 6) != 3) break; + } + + giveBackSystem(); + + freeCopperlist(copperlist); + + teardownScreen(&screenDefinition); +} diff --git a/demo.gif b/demo.gif new file mode 100644 index 0000000..719271e Binary files /dev/null and b/demo.gif differ diff --git a/left_side b/left_side new file mode 100755 index 0000000..294cd1b Binary files /dev/null and b/left_side differ diff --git a/left_side.c b/left_side.c new file mode 100644 index 0000000..e00d684 --- /dev/null +++ b/left_side.c @@ -0,0 +1,90 @@ +/** +* What do we need +* * [ ] screen setup +*/ + +#include +#include + +#include + +#include "system/system.h" +#include "system/copper.h" +#include "system/blitter.h" + +#include "screen.h" + +extern struct Custom far custom; +extern struct CIA far ciaa; + +uint16_t custom_color = (uint16_t)offsetof(Custom, color); +uint16_t custom_sprite = (uint16_t)offsetof(Custom, sprpt); +uint16_t custom_sprite_control = (uint16_t)offsetof(Custom, spr); + +extern unsigned char chip coolbun[]; + +int main(void) { + struct ScreenDefinition screenDefinition; + struct ActiveScreenBufferDetails activeScreenBufferDetails; + uint16_t *copperlist, *currentCopperlist; + void *copperlistBitplanePointers[8][2]; + int i, plane; + + allocateDoubleBufferedScreenMemory( + &screenDefinition, + &activeScreenBufferDetails, + 320, + 256, + 2 + ); + + copperlist = prepareNewCopperlist(300); + + currentCopperlist = addDisplayToCopperlist( + copperlist, + &screenDefinition, + &activeScreenBufferDetails, + &copperlistBitplanePointers + ); + + COPPERLIST_MOVE(currentCopperlist, custom_color, 0x3a6); + COPPERLIST_MOVE(currentCopperlist, custom_color + 2, 0x000); + COPPERLIST_MOVE(currentCopperlist, custom_color + 4, 0xfff); + currentCopperlist = setUpEmptySpritesInCopperlist(currentCopperlist); + + endCopperlist(currentCopperlist); + + takeOverSystem(); + + setCopperlist(copperlist); + setUpDisplay((uint32_t)screenDefinition.bitplanes); + + // Render a cut off bun at -8x50 + + for (plane = 0; plane < 2; ++plane) { + custom.bltcon0 = BLTCON0(0xf0, 1, 0, 0, 1, 8); + custom.bltcon1 = BLTCON1(BLITTER_DESCENDING, 8); + + custom.bltapt = coolbun + (plane * 4 * 32) + (31 * 4) + 2; + custom.bltdpt = activeScreenBufferDetails.planes[plane] + ((50 + 31) * 320 / 8) + 2; + custom.bltafwm = 0xffff; + custom.bltalwm = 0x00ff; + + custom.bltamod = 0; + custom.bltdmod = 40 - 4; + + custom.bltsize = 2 + (32 << 6); + + WaitBlit(); + } + + while (1) { + if ((ciaa.ciapra >> 6) != 3) break; + } + + giveBackSystem(); + + freeCopperlist(copperlist); + + teardownScreen(&screenDefinition); +} diff --git a/right_side b/right_side new file mode 100755 index 0000000..e390f9a Binary files /dev/null and b/right_side differ diff --git a/right_side.c b/right_side.c new file mode 100644 index 0000000..f603d24 --- /dev/null +++ b/right_side.c @@ -0,0 +1,90 @@ +/** +* What do we need +* * [ ] screen setup +*/ + +#include +#include + +#include + +#include "system/system.h" +#include "system/copper.h" +#include "system/blitter.h" + +#include "screen.h" + +extern struct Custom far custom; +extern struct CIA far ciaa; + +uint16_t custom_color = (uint16_t)offsetof(Custom, color); +uint16_t custom_sprite = (uint16_t)offsetof(Custom, sprpt); +uint16_t custom_sprite_control = (uint16_t)offsetof(Custom, spr); + +extern unsigned char chip coolbun[]; + +int main(void) { + struct ScreenDefinition screenDefinition; + struct ActiveScreenBufferDetails activeScreenBufferDetails; + uint16_t *copperlist, *currentCopperlist; + void *copperlistBitplanePointers[8][2]; + int i, plane; + + allocateDoubleBufferedScreenMemory( + &screenDefinition, + &activeScreenBufferDetails, + 320, + 256, + 2 + ); + + copperlist = prepareNewCopperlist(300); + + currentCopperlist = addDisplayToCopperlist( + copperlist, + &screenDefinition, + &activeScreenBufferDetails, + &copperlistBitplanePointers + ); + + COPPERLIST_MOVE(currentCopperlist, custom_color, 0x3a6); + COPPERLIST_MOVE(currentCopperlist, custom_color + 2, 0x000); + COPPERLIST_MOVE(currentCopperlist, custom_color + 4, 0xfff); + currentCopperlist = setUpEmptySpritesInCopperlist(currentCopperlist); + + endCopperlist(currentCopperlist); + + takeOverSystem(); + + setCopperlist(copperlist); + setUpDisplay((uint32_t)screenDefinition.bitplanes); + + // Render a cut off bun at -8x50 + + for (plane = 0; plane < 2; ++plane) { + custom.bltcon0 = BLTCON0(0xf0, 1, 0, 0, 1, 8); + custom.bltcon1 = BLTCON1(BLITTER_ASCENDING, 8); + + custom.bltapt = coolbun + (plane * 4 * 32); + custom.bltdpt = activeScreenBufferDetails.planes[plane] + (50 * 320 / 8) + (40 - 4); + custom.bltafwm = 0xffff; + custom.bltalwm = 0xff00; + + custom.bltamod = 0; + custom.bltdmod = 40 - 4; + + custom.bltsize = 2 + (32 << 6); + + WaitBlit(); + } + + while (1) { + if ((ciaa.ciapra >> 6) != 3) break; + } + + giveBackSystem(); + + freeCopperlist(copperlist); + + teardownScreen(&screenDefinition); +} diff --git a/smakefile b/smakefile index 5a5cf93..8f95720 100644 --- a/smakefile +++ b/smakefile @@ -1,5 +1,9 @@ MAIN_OBJS = main.o images.o system.lib screen.o bun.o -32_objs = 32x50_bun.o system.lib screen.o +32_objs = 32x50_bun.o system.lib screen.o images.o +33_objs = 33x50_bun.o system.lib screen.o images.o +left_side_objs = left_side.o system.lib screen.o images.o +right_side_objs = right_side.o system.lib screen.o images.o +any_position = any_position.o system.lib screen.o images.o all: main @@ -18,6 +22,18 @@ main: $(MAIN_OBJS) 32x50: $(32_objs) sc link to 32x50 $(32_objs) +33x50: $(33_objs) + sc link to 33x50 $(33_objs) + +left_side: $(left_side_objs) + sc link to left_side $(left_side_objs) + +right_side: $(right_side_objs) + sc link to right_side $(right_side_objs) + +any_position: $(any_position) + sc link to any_position $(any_position) + test: bun_test.o bun.o sc link to bun_test identifierlength=32 math=standard bun_test.o bun.o cutest/CuTest.c