amiga_boottest

view src/main.c @ 4:995d42b33974

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