nuclear@1: #include "hwregs.h" nuclear@1: #include "intr.h" nuclear@1: #include "copper.h" nuclear@3: #include "rng.h" nuclear@4: #include "serial.h" nuclear@1: nuclear@4: #define SCR_W 336 nuclear@4: #define SCR_H 256 nuclear@4: #define HMOD ((SCR_W - 320) / 8) nuclear@4: nuclear@4: #define BPLSZ (SCR_W / 8 * SCR_H) nuclear@4: static unsigned char fb0[BPLSZ + 3 * SCR_W]; nuclear@1: nuclear@2: extern uint16_t dbgval; nuclear@2: nuclear@2: #define wait_vpos(x) \ nuclear@2: asm volatile ( \ nuclear@2: "0: move.l 0xdff004, %%d0\n\t" \ nuclear@2: "and.l #0x1ff00, %%d0\n\t" \ nuclear@2: "cmp.l %0, %%d0\n\t" \ nuclear@2: "bne 0b\n\t" \ nuclear@2: :: "i"((x) << 8) : "%d0") nuclear@2: nuclear@2: #define wait_vblank() wait_vpos(300) nuclear@2: #define wait_scanline(x) wait_vpos((x) + 0x2c) nuclear@2: nuclear@2: #define clear_bpl(p) \ nuclear@2: asm volatile ( \ nuclear@2: "move.l %0, %%a0\n\t" \ nuclear@2: "move.l %1, %%d0\n\t" \ nuclear@2: "0: clr.l (%%a0)+\n\t" \ nuclear@2: "dbra %%d0, 0b\n\t" \ nuclear@2: :: "a"(p), "i"(BPLSZ / 4 - 1) \ nuclear@2: : "a0", "d0") nuclear@2: nuclear@2: static uint32_t coplist[] = { nuclear@4: 0, 0, 0, 0, /* placeholder of bitplane pointer setting */ nuclear@3: nuclear@3: COPPER_MOVE(REGN_COLOR0, 0x234), nuclear@3: COPPER_VWAIT(15), nuclear@3: COPPER_MOVE(REGN_COLOR0, 0x012), nuclear@3: COPPER_VWAIT(20), nuclear@3: COPPER_MOVE(REGN_COLOR0, 0x235), nuclear@3: nuclear@3: COPPER_OVERFLOW, nuclear@3: nuclear@3: COPPER_VWAIT(220), nuclear@3: COPPER_MOVE(REGN_COLOR0, 0x346), nuclear@3: COPPER_VWAIT(225), nuclear@3: COPPER_MOVE(REGN_COLOR0, 0x234), nuclear@3: nuclear@2: COPPER_END nuclear@2: }; nuclear@2: nuclear@1: int main(void) nuclear@1: { nuclear@3: int32_t x = 0, y = 0; nuclear@3: nuclear@4: ser_init(38400); nuclear@4: ser_print("Amiga debug console initialized\n"); nuclear@4: nuclear@1: REG_INTENA = SETBITS(INTEN_VERTB | INTEN_MASTER); nuclear@1: nuclear@1: REG_DMACON = CLRBITS(DMA_ALL); nuclear@4: REG_BPLCON0 = BPLCON0_COUNT(2) | BPLCON0_COLOR; nuclear@4: REG_BPLCON1 = 0xfa; nuclear@4: REG_BPL1MOD = HMOD - 2; nuclear@4: REG_BPL2MOD = HMOD - 2; nuclear@1: REG_DIWSTART = 0x2981; nuclear@1: REG_DIWSTOP = 0x29c1; nuclear@4: REG_DDFSTART = 0x30; nuclear@1: REG_DDFSTOP = 0xd0; nuclear@1: nuclear@3: REG_COLOR0 = 0x235; nuclear@4: REG_COLOR1 = 0x2e5; nuclear@4: REG_COLOR2 = 0x113; nuclear@4: REG_COLOR3 = 0x2e5; nuclear@1: nuclear@1: wait_vblank(); nuclear@4: coplist[0] = COPPER_MOVE(REGN_BPL1PTH, ((uint32_t)fb0 + 3 * SCR_W / 8) >> 16); nuclear@4: coplist[1] = COPPER_MOVE(REGN_BPL1PTL, (uint32_t)fb0 + 3 * SCR_W / 8); nuclear@4: coplist[2] = COPPER_MOVE(REGN_BPL2PTH, (uint32_t)fb0 >> 16); nuclear@4: coplist[3] = COPPER_MOVE(REGN_BPL2PTL, (uint32_t)fb0); nuclear@2: REG32_COP1LC = (uint32_t)coplist; nuclear@2: REG_COPJMP1 = 0; nuclear@1: nuclear@2: REG_DMACON = SETBITS(DMA_BPL | DMA_COPPER | DMA_MASTER); nuclear@1: nuclear@3: srand(0); nuclear@3: nuclear@3: #define CDF0 655 nuclear@3: #define CDF1 56361 nuclear@3: #define CDF2 60948 nuclear@3: nuclear@2: for(;;) { nuclear@3: int sel = rand() & 0xffff; nuclear@3: int32_t px, py; nuclear@3: unsigned char *pptr; nuclear@3: nuclear@3: if(sel < CDF0) { nuclear@3: x = 0; nuclear@3: y = (y >> 8) * (10486 >> 8); nuclear@3: } else if(sel < CDF1) { nuclear@3: int32_t nx = (x >> 8) * (55705 >> 8) + (y >> 8) * (2621 >> 8); nuclear@3: y = (y >> 8) * (55705 >> 8) - (x >> 8) * (2621 >> 8) + 104857; nuclear@3: x = nx; nuclear@3: } else if(sel < CDF2) { nuclear@3: int32_t nx = (x >> 8) * (13107 >> 8) - (y >> 8) * (17039 >> 8); nuclear@3: y = (x >> 8) * (15073 >> 8) + (y >> 8) * (14417 >> 8) + 104857; nuclear@3: x = nx; nuclear@3: } else { nuclear@3: int32_t nx = (y >> 8) * (18350 >> 8) - (x >> 8) * (9830 >> 8); nuclear@3: y = (x >> 8) * (17039 >> 8) + (y >> 8) * (15728 >> 8) + 28835; nuclear@3: x = nx; nuclear@3: } nuclear@3: nuclear@3: px = (y >> 11); nuclear@3: py = 128 - (x >> 11); nuclear@3: nuclear@3: if(py >= 0) { nuclear@4: pptr = fb0 + (py * SCR_W + px) / 8; nuclear@3: *pptr = *pptr | (0x80 >> (px & 7)); nuclear@3: } nuclear@3: nuclear@4: if((REG_CIAA_PORTA & CIAA_PA_FIR0) == 0) { nuclear@4: ser_print("restarting fractal\n"); nuclear@4: wait_vblank(); nuclear@4: clear_bpl(fb0); nuclear@4: } nuclear@2: } nuclear@1: nuclear@1: return 0; nuclear@1: }