#include #include #include #include #include #include #include #include #include "system/blitter.h" #include "system/copper.h" #include "system/system.h" #include "screen.h" #include "types.h" #include "bun.h" extern struct Custom far custom; extern struct CIA far ciaa; // this should be large enough to hold one bitplane of the largest object // you are blitting, plus one additional word on each side #define SCRATCH_AREA_WIDTH_BYTES (8) #define SCRATCH_AREA_HEIGHT_ROWS (34) #define SCRATCH_AREA_MEMORY_SIZE (SCRATCH_AREA_WIDTH_BYTES * SCRATCH_AREA_HEIGHT_ROWS) volatile short *dbg = (volatile short *)0x100; unsigned char *scratchArea; struct ScreenSetup screenSetup; struct CurrentScreen currentScreen; void *copperlistBitplanePointers[8][2]; void *copperlistSpritePointers[8]; #define offsetof(s, m) &((struct s *)0)->m 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); uint16_t spritePositionsEachLine[256][2]; void calculageSpritePositionsEachLine() { int i; for (i = 0; i < 255; ++i) { } } #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 uint16_t chip CopperColors[]; extern uint16_t chip SpriteCopperlist[]; extern uint16_t chip SpriteData[]; extern uint16_t chip MaskBitplane[]; int main(void) { uint16_t *copperlist, *currentCopperlist, *currentCopperColors, result, *currentSpriteCopperlist; uint32_t spriteDataPointer; int i, x, y, height, plane; struct BunRenderer bunRenderer; color_t colors[8]; colors[0] = 0x09b8; colors[1] = 0x0000; colors[2] = 0x0fff; colors[3] = 0x000f; printf("%x\n", &SpriteData); printf("setting up, i haven't crashed...yet.\n"); setupScreen(&screenSetup, SCREEN_WIDTH, SCREEN_HEIGHT, 3); setupInitialCurrentScreen(&screenSetup, ¤tScreen); setupBunRenderer(&bunRenderer, &screenSetup, ¤tScreen); // blitter copy the first bitplane row down to the second copperlist = prepareNewCopperlist(); takeOverSystem(); setCopperlist(copperlist); setUpDisplay((uint32_t)screenSetup.bitplanes); currentCopperlist = addDisplayToCopperlist( copperlist, &screenSetup, ¤tScreen, &copperlistBitplanePointers ); currentCopperlist = setUpEmptySpritesInCopperlist(currentCopperlist); currentCopperColors = CopperColors; currentSpriteCopperlist = SpriteCopperlist; *(currentCopperlist++) = custom_color + 2; *(currentCopperlist++) = 0x000; *(currentCopperlist++) = custom_color + 4; *(currentCopperlist++) = 0xfff; 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); } *(currentCopperlist++) = custom_color; *(currentCopperlist++) = 0x3a6; for (y = 0; y < 256; ++y) { for (i = 0; i < 8; ++i) { *(currentCopperlist++) = custom_color + 32 + ( // sprite color group (i / 2) * 4 + // 0 is transparent 1 + i % 2 ) * 2; *(currentCopperlist++) = *(currentSpriteCopperlist++); //*(currentCopperlist++) = 0xf0f; //currentSpriteCopperlist++; *(currentCopperlist++) = custom_sprite_control + i * 8; *(currentCopperlist++) = *(currentSpriteCopperlist++); *(currentCopperlist++) = custom_sprite_control + i * 8 + 2; *(currentCopperlist++) = *(currentSpriteCopperlist++); } for (i = 3; i < 8; ++i) { *(currentCopperlist++) = custom_color + (i * 2); *(currentCopperlist++) = *(currentCopperColors++); } *(currentCopperlist++) = 1 + ((31 + (256 / 4)) << 1) + ((44 + y) << 8); *(currentCopperlist++) = 0xFFFE; /* *(currentCopperlist++) = custom_color; *(currentCopperlist++) = 0x9b8; */ /* *(currentCopperlist++) = 1 + (1 << 1) + ((44 + y) << 8); *(currentCopperlist++) = 0xFFFE; */ /* *(currentCopperlist++) = 1 + ((31 + (320 / 4)) << 1) + ((44 + y) << 8); *(currentCopperlist++) = 0xFFFE; *(currentCopperlist++) = custom_color; *(currentCopperlist++) = 0x000; */ } endCopperlist(currentCopperlist); i = 0; while (1) { swapCurrentScreenBuffer(&screenSetup, ¤tScreen); clearCurrentBuns(&bunRenderer); /* for (plane = 0; plane < 2; ++plane) { custom.bltcon0 = 0xc0 + (1 << 8); custom.bltcon1 = 0; custom.bltadat = 0x0000; custom.bltafwm = 0xffff; custom.bltalwm = 0xffff; custom.bltdpt = currentScreen.planes[plane]; custom.bltdmod = 0; custom.bltsize = screenSetup.byteWidth / 2 + (screenSetup.height << 6); WaitBlit(); } */ renderBunFrame(i, &bunRenderer); /* */ for (plane = 0; plane < 3; ++plane) { custom.bltcon0 = 0xca + (1 << 8) + (1 << 9) + (1 << 10) + (1 << 11); custom.bltcon1 = 0; custom.bltafwm = 0xffff; custom.bltalwm = 0xffff; custom.bltapt = MaskBitplane; custom.bltbpt = TopazBitplanes + (plane * 32 * 256); custom.bltcpt = currentScreen.planes[plane]; custom.bltdpt = currentScreen.planes[plane]; custom.bltamod = 0; custom.bltbmod = 0; custom.bltcmod = screenSetup.byteWidth - 32; custom.bltdmod = screenSetup.byteWidth - 32; custom.bltsize = 16 + (256 << 6); WaitBlit(); } /* *(SpriteData) = SPRPOS(250, 44); *(SpriteData + 1) = SPRCTL(250, 44, 44 + 257); */ updateDisplayInCopperList( &screenSetup, ¤tScreen, copperlistBitplanePointers ); WaitTOF(); if ((ciaa.ciapra >> 6) != 3) break; i++; i %= FRAMES_FOR_SCREEN; } /* for (i = 0; i < 200; ++i) { WaitTOF(); } */ giveBackSystem(); teardownScreen(&screenSetup); /* for (i = 0; i < 50; ++i) { printf("%x %x\n", copperlist[i * 2], copperlist[i * 2 + 1]); } */ printf("%x %x", SPRPOS(250, 44), SPRCTL(250, 44, 44 + 256)); freeCopperlist(copperlist); teardownBunRenderer(); return 0; }