amiga_boottest

annotate src/main.c @ 3:555b986cc420

IFS
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 22 Feb 2018 14:46:32 +0200
parents 58ebd84822e7
children 995d42b33974
rev   line source
nuclear@1 1 #include "hwregs.h"
nuclear@1 2 #include "intr.h"
nuclear@1 3 #include "copper.h"
nuclear@3 4 #include "rng.h"
nuclear@1 5
nuclear@1 6 #define BPLSZ (320 / 8 * 256)
nuclear@1 7 static unsigned char fb0[BPLSZ];
nuclear@1 8
nuclear@2 9 extern uint16_t dbgval;
nuclear@2 10
nuclear@2 11 #define wait_vpos(x) \
nuclear@2 12 asm volatile ( \
nuclear@2 13 "0: move.l 0xdff004, %%d0\n\t" \
nuclear@2 14 "and.l #0x1ff00, %%d0\n\t" \
nuclear@2 15 "cmp.l %0, %%d0\n\t" \
nuclear@2 16 "bne 0b\n\t" \
nuclear@2 17 :: "i"((x) << 8) : "%d0")
nuclear@2 18
nuclear@2 19 #define wait_vblank() wait_vpos(300)
nuclear@2 20 #define wait_scanline(x) wait_vpos((x) + 0x2c)
nuclear@2 21
nuclear@2 22 #define clear_bpl(p) \
nuclear@2 23 asm volatile ( \
nuclear@2 24 "move.l %0, %%a0\n\t" \
nuclear@2 25 "move.l %1, %%d0\n\t" \
nuclear@2 26 "0: clr.l (%%a0)+\n\t" \
nuclear@2 27 "dbra %%d0, 0b\n\t" \
nuclear@2 28 :: "a"(p), "i"(BPLSZ / 4 - 1) \
nuclear@2 29 : "a0", "d0")
nuclear@2 30
nuclear@2 31 static uint32_t coplist[] = {
nuclear@2 32 COPPER_MOVE(REGN_BPL1PTH, 0),
nuclear@2 33 COPPER_MOVE(REGN_BPL1PTL, 0),
nuclear@3 34
nuclear@3 35 COPPER_MOVE(REGN_COLOR0, 0x234),
nuclear@3 36 COPPER_VWAIT(15),
nuclear@3 37 COPPER_MOVE(REGN_COLOR0, 0x012),
nuclear@3 38 COPPER_VWAIT(20),
nuclear@3 39 COPPER_MOVE(REGN_COLOR0, 0x235),
nuclear@3 40
nuclear@3 41 COPPER_OVERFLOW,
nuclear@3 42
nuclear@3 43 COPPER_VWAIT(220),
nuclear@3 44 COPPER_MOVE(REGN_COLOR0, 0x346),
nuclear@3 45 COPPER_VWAIT(225),
nuclear@3 46 COPPER_MOVE(REGN_COLOR0, 0x234),
nuclear@3 47
nuclear@2 48 COPPER_END
nuclear@2 49 };
nuclear@2 50
nuclear@1 51 int main(void)
nuclear@1 52 {
nuclear@3 53 int32_t x = 0, y = 0;
nuclear@3 54
nuclear@1 55 REG_INTENA = SETBITS(INTEN_VERTB | INTEN_MASTER);
nuclear@1 56
nuclear@1 57 REG_DMACON = CLRBITS(DMA_ALL);
nuclear@2 58 REG_BPLCON0 = BPLCON0_COUNT(1) | BPLCON0_COLOR;
nuclear@1 59 REG_BPLCON1 = 0;
nuclear@1 60 REG_DIWSTART = 0x2981;
nuclear@1 61 REG_DIWSTOP = 0x29c1;
nuclear@1 62 REG_DDFSTART = 0x38;
nuclear@1 63 REG_DDFSTOP = 0xd0;
nuclear@1 64
nuclear@3 65 REG_COLOR0 = 0x235;
nuclear@3 66 REG_COLOR1 = 0x2f5;
nuclear@1 67
nuclear@1 68 wait_vblank();
nuclear@2 69 coplist[0] = COPPER_MOVE(REGN_BPL1PTH, (uint32_t)fb0 >> 16);
nuclear@2 70 coplist[1] = COPPER_MOVE(REGN_BPL1PTL, (uint32_t)fb0);
nuclear@2 71 REG32_COP1LC = (uint32_t)coplist;
nuclear@2 72 REG_COPJMP1 = 0;
nuclear@1 73
nuclear@2 74 REG_DMACON = SETBITS(DMA_BPL | DMA_COPPER | DMA_MASTER);
nuclear@1 75
nuclear@3 76 srand(0);
nuclear@3 77
nuclear@3 78 #define CDF0 655
nuclear@3 79 #define CDF1 56361
nuclear@3 80 #define CDF2 60948
nuclear@3 81
nuclear@2 82 for(;;) {
nuclear@3 83 int sel = rand() & 0xffff;
nuclear@3 84 int32_t px, py;
nuclear@3 85 unsigned char *pptr;
nuclear@3 86
nuclear@3 87 if(sel < CDF0) {
nuclear@3 88 x = 0;
nuclear@3 89 y = (y >> 8) * (10486 >> 8);
nuclear@3 90 } else if(sel < CDF1) {
nuclear@3 91 int32_t nx = (x >> 8) * (55705 >> 8) + (y >> 8) * (2621 >> 8);
nuclear@3 92 y = (y >> 8) * (55705 >> 8) - (x >> 8) * (2621 >> 8) + 104857;
nuclear@3 93 x = nx;
nuclear@3 94 } else if(sel < CDF2) {
nuclear@3 95 int32_t nx = (x >> 8) * (13107 >> 8) - (y >> 8) * (17039 >> 8);
nuclear@3 96 y = (x >> 8) * (15073 >> 8) + (y >> 8) * (14417 >> 8) + 104857;
nuclear@3 97 x = nx;
nuclear@3 98 } else {
nuclear@3 99 int32_t nx = (y >> 8) * (18350 >> 8) - (x >> 8) * (9830 >> 8);
nuclear@3 100 y = (x >> 8) * (17039 >> 8) + (y >> 8) * (15728 >> 8) + 28835;
nuclear@3 101 x = nx;
nuclear@3 102 }
nuclear@3 103
nuclear@3 104 px = (y >> 11);
nuclear@3 105 py = 128 - (x >> 11);
nuclear@3 106
nuclear@3 107 if(py >= 0) {
nuclear@3 108 pptr = fb0 + (py * 320 + px) / 8;
nuclear@3 109 *pptr = *pptr | (0x80 >> (px & 7));
nuclear@3 110 }
nuclear@3 111
nuclear@2 112 wait_vblank();
nuclear@2 113 }
nuclear@1 114
nuclear@1 115 return 0;
nuclear@1 116 }