amiga_boottest

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