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@4
|
5 #include "serial.h"
|
nuclear@1
|
6
|
nuclear@4
|
7 #define SCR_W 336
|
nuclear@4
|
8 #define SCR_H 256
|
nuclear@4
|
9 #define HMOD ((SCR_W - 320) / 8)
|
nuclear@4
|
10
|
nuclear@4
|
11 #define BPLSZ (SCR_W / 8 * SCR_H)
|
nuclear@4
|
12 static unsigned char fb0[BPLSZ + 3 * SCR_W];
|
nuclear@1
|
13
|
nuclear@2
|
14 extern uint16_t dbgval;
|
nuclear@2
|
15
|
nuclear@2
|
16 #define wait_vpos(x) \
|
nuclear@2
|
17 asm volatile ( \
|
nuclear@2
|
18 "0: move.l 0xdff004, %%d0\n\t" \
|
nuclear@2
|
19 "and.l #0x1ff00, %%d0\n\t" \
|
nuclear@2
|
20 "cmp.l %0, %%d0\n\t" \
|
nuclear@2
|
21 "bne 0b\n\t" \
|
nuclear@2
|
22 :: "i"((x) << 8) : "%d0")
|
nuclear@2
|
23
|
nuclear@2
|
24 #define wait_vblank() wait_vpos(300)
|
nuclear@2
|
25 #define wait_scanline(x) wait_vpos((x) + 0x2c)
|
nuclear@2
|
26
|
nuclear@2
|
27 #define clear_bpl(p) \
|
nuclear@2
|
28 asm volatile ( \
|
nuclear@2
|
29 "move.l %0, %%a0\n\t" \
|
nuclear@2
|
30 "move.l %1, %%d0\n\t" \
|
nuclear@2
|
31 "0: clr.l (%%a0)+\n\t" \
|
nuclear@2
|
32 "dbra %%d0, 0b\n\t" \
|
nuclear@2
|
33 :: "a"(p), "i"(BPLSZ / 4 - 1) \
|
nuclear@2
|
34 : "a0", "d0")
|
nuclear@2
|
35
|
nuclear@2
|
36 static uint32_t coplist[] = {
|
nuclear@4
|
37 0, 0, 0, 0, /* placeholder of bitplane pointer setting */
|
nuclear@3
|
38
|
nuclear@3
|
39 COPPER_MOVE(REGN_COLOR0, 0x234),
|
nuclear@3
|
40 COPPER_VWAIT(15),
|
nuclear@3
|
41 COPPER_MOVE(REGN_COLOR0, 0x012),
|
nuclear@3
|
42 COPPER_VWAIT(20),
|
nuclear@3
|
43 COPPER_MOVE(REGN_COLOR0, 0x235),
|
nuclear@3
|
44
|
nuclear@3
|
45 COPPER_OVERFLOW,
|
nuclear@3
|
46
|
nuclear@3
|
47 COPPER_VWAIT(220),
|
nuclear@3
|
48 COPPER_MOVE(REGN_COLOR0, 0x346),
|
nuclear@3
|
49 COPPER_VWAIT(225),
|
nuclear@3
|
50 COPPER_MOVE(REGN_COLOR0, 0x234),
|
nuclear@3
|
51
|
nuclear@2
|
52 COPPER_END
|
nuclear@2
|
53 };
|
nuclear@2
|
54
|
nuclear@1
|
55 int main(void)
|
nuclear@1
|
56 {
|
nuclear@3
|
57 int32_t x = 0, y = 0;
|
nuclear@3
|
58
|
nuclear@4
|
59 ser_init(38400);
|
nuclear@4
|
60 ser_print("Amiga debug console initialized\n");
|
nuclear@4
|
61
|
nuclear@1
|
62 REG_INTENA = SETBITS(INTEN_VERTB | INTEN_MASTER);
|
nuclear@1
|
63
|
nuclear@1
|
64 REG_DMACON = CLRBITS(DMA_ALL);
|
nuclear@4
|
65 REG_BPLCON0 = BPLCON0_COUNT(2) | BPLCON0_COLOR;
|
nuclear@4
|
66 REG_BPLCON1 = 0xfa;
|
nuclear@4
|
67 REG_BPL1MOD = HMOD - 2;
|
nuclear@4
|
68 REG_BPL2MOD = HMOD - 2;
|
nuclear@1
|
69 REG_DIWSTART = 0x2981;
|
nuclear@1
|
70 REG_DIWSTOP = 0x29c1;
|
nuclear@4
|
71 REG_DDFSTART = 0x30;
|
nuclear@1
|
72 REG_DDFSTOP = 0xd0;
|
nuclear@1
|
73
|
nuclear@3
|
74 REG_COLOR0 = 0x235;
|
nuclear@4
|
75 REG_COLOR1 = 0x2e5;
|
nuclear@4
|
76 REG_COLOR2 = 0x113;
|
nuclear@4
|
77 REG_COLOR3 = 0x2e5;
|
nuclear@1
|
78
|
nuclear@1
|
79 wait_vblank();
|
nuclear@4
|
80 coplist[0] = COPPER_MOVE(REGN_BPL1PTH, ((uint32_t)fb0 + 3 * SCR_W / 8) >> 16);
|
nuclear@4
|
81 coplist[1] = COPPER_MOVE(REGN_BPL1PTL, (uint32_t)fb0 + 3 * SCR_W / 8);
|
nuclear@4
|
82 coplist[2] = COPPER_MOVE(REGN_BPL2PTH, (uint32_t)fb0 >> 16);
|
nuclear@4
|
83 coplist[3] = COPPER_MOVE(REGN_BPL2PTL, (uint32_t)fb0);
|
nuclear@2
|
84 REG32_COP1LC = (uint32_t)coplist;
|
nuclear@2
|
85 REG_COPJMP1 = 0;
|
nuclear@1
|
86
|
nuclear@2
|
87 REG_DMACON = SETBITS(DMA_BPL | DMA_COPPER | DMA_MASTER);
|
nuclear@1
|
88
|
nuclear@3
|
89 srand(0);
|
nuclear@3
|
90
|
nuclear@3
|
91 #define CDF0 655
|
nuclear@3
|
92 #define CDF1 56361
|
nuclear@3
|
93 #define CDF2 60948
|
nuclear@3
|
94
|
nuclear@2
|
95 for(;;) {
|
nuclear@3
|
96 int sel = rand() & 0xffff;
|
nuclear@3
|
97 int32_t px, py;
|
nuclear@3
|
98 unsigned char *pptr;
|
nuclear@3
|
99
|
nuclear@3
|
100 if(sel < CDF0) {
|
nuclear@3
|
101 x = 0;
|
nuclear@3
|
102 y = (y >> 8) * (10486 >> 8);
|
nuclear@3
|
103 } else if(sel < CDF1) {
|
nuclear@3
|
104 int32_t nx = (x >> 8) * (55705 >> 8) + (y >> 8) * (2621 >> 8);
|
nuclear@3
|
105 y = (y >> 8) * (55705 >> 8) - (x >> 8) * (2621 >> 8) + 104857;
|
nuclear@3
|
106 x = nx;
|
nuclear@3
|
107 } else if(sel < CDF2) {
|
nuclear@3
|
108 int32_t nx = (x >> 8) * (13107 >> 8) - (y >> 8) * (17039 >> 8);
|
nuclear@3
|
109 y = (x >> 8) * (15073 >> 8) + (y >> 8) * (14417 >> 8) + 104857;
|
nuclear@3
|
110 x = nx;
|
nuclear@3
|
111 } else {
|
nuclear@3
|
112 int32_t nx = (y >> 8) * (18350 >> 8) - (x >> 8) * (9830 >> 8);
|
nuclear@3
|
113 y = (x >> 8) * (17039 >> 8) + (y >> 8) * (15728 >> 8) + 28835;
|
nuclear@3
|
114 x = nx;
|
nuclear@3
|
115 }
|
nuclear@3
|
116
|
nuclear@3
|
117 px = (y >> 11);
|
nuclear@3
|
118 py = 128 - (x >> 11);
|
nuclear@3
|
119
|
nuclear@3
|
120 if(py >= 0) {
|
nuclear@4
|
121 pptr = fb0 + (py * SCR_W + px) / 8;
|
nuclear@3
|
122 *pptr = *pptr | (0x80 >> (px & 7));
|
nuclear@3
|
123 }
|
nuclear@3
|
124
|
nuclear@4
|
125 if((REG_CIAA_PORTA & CIAA_PA_FIR0) == 0) {
|
nuclear@4
|
126 ser_print("restarting fractal\n");
|
nuclear@4
|
127 wait_vblank();
|
nuclear@4
|
128 clear_bpl(fb0);
|
nuclear@4
|
129 }
|
nuclear@2
|
130 }
|
nuclear@1
|
131
|
nuclear@1
|
132 return 0;
|
nuclear@1
|
133 }
|