nuclear@1: #include "hwregs.h" nuclear@1: #include "intr.h" nuclear@1: #include "copper.h" nuclear@3: #include "rng.h" nuclear@1: nuclear@1: #define BPLSZ (320 / 8 * 256) nuclear@1: static unsigned char fb0[BPLSZ]; 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@2: COPPER_MOVE(REGN_BPL1PTH, 0), nuclear@2: COPPER_MOVE(REGN_BPL1PTL, 0), 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@1: REG_INTENA = SETBITS(INTEN_VERTB | INTEN_MASTER); nuclear@1: nuclear@1: REG_DMACON = CLRBITS(DMA_ALL); nuclear@2: REG_BPLCON0 = BPLCON0_COUNT(1) | BPLCON0_COLOR; nuclear@1: REG_BPLCON1 = 0; nuclear@1: REG_DIWSTART = 0x2981; nuclear@1: REG_DIWSTOP = 0x29c1; nuclear@1: REG_DDFSTART = 0x38; nuclear@1: REG_DDFSTOP = 0xd0; nuclear@1: nuclear@3: REG_COLOR0 = 0x235; nuclear@3: REG_COLOR1 = 0x2f5; nuclear@1: nuclear@1: wait_vblank(); nuclear@2: coplist[0] = COPPER_MOVE(REGN_BPL1PTH, (uint32_t)fb0 >> 16); nuclear@2: coplist[1] = COPPER_MOVE(REGN_BPL1PTL, (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@3: pptr = fb0 + (py * 320 + px) / 8; nuclear@3: *pptr = *pptr | (0x80 >> (px & 7)); nuclear@3: } nuclear@3: nuclear@2: wait_vblank(); nuclear@2: } nuclear@1: nuclear@1: return 0; nuclear@1: }