amiga_cyberspace
diff src/main.c @ 2:b98fa9b135ea
first version which looks good
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 27 Jul 2017 02:34:42 +0300 |
parents | b5d609c7161d |
children | 200e512488e4 |
line diff
1.1 --- a/src/main.c Wed Jul 26 08:45:20 2017 +0300 1.2 +++ b/src/main.c Thu Jul 27 02:34:42 2017 +0300 1.3 @@ -16,6 +16,37 @@ 1.4 static uint16_t prev_intena, prev_intreq, prev_adkcon, prev_dmacon; 1.5 1.6 extern uint32_t backdrop; 1.7 +extern uint32_t grid; 1.8 + 1.9 +static uint32_t backdrop_addr = (uint32_t)&backdrop; 1.10 +static uint32_t grid_addr = (uint32_t)&grid; 1.11 + 1.12 +static uint16_t *grid_pal; 1.13 + 1.14 +#define MAX_GRID_SHADES 6 1.15 +static uint32_t *cplist_pal[MAX_GRID_SHADES]; 1.16 + 1.17 +#define MAX_SKY_SHADES 32 1.18 +static uint16_t sky_color[] = { 1.19 + 0x204, 1.20 + 0x306, 1.21 + 0x307, 1.22 + 0x408, 0x408, 1.23 + 0x509, 1.24 + 0x50a, 1.25 + 0x60b, 0x60b, 1.26 + 0x60c, 0x60c, 1.27 + 0x70c, 0x70c, 1.28 + 0x80c, 1.29 + 0x80d, 1.30 + 0x90d, 0x90d, 1.31 + 0xa0d, 1.32 + 0xb0c, 0xb0c, 0xb0c, 1.33 + 0xc0c, 0xc0c, 1.34 + 0xd0c, 0xd0c, 1.35 + 0xd0b, 0xd0b, 0xd0b, 0xd0b, 1.36 + 0xe0a, 0xe0a, 0xe0a 1.37 +}; 1.38 1.39 int init(void); 1.40 void cleanup(void); 1.41 @@ -24,7 +55,10 @@ 1.42 1.43 int main(void) 1.44 { 1.45 - int x, y; 1.46 + int i, j, x, y; 1.47 + long frameno = 0; 1.48 + uint16_t tmpcol; 1.49 + uint16_t *cplptr; 1.50 1.51 if(init() == -1) { 1.52 return 1; 1.53 @@ -32,7 +66,28 @@ 1.54 1.55 while(!mouse_state(&x, &y)) { 1.56 wait_vblank(); 1.57 - REG32_BPL1PT = (uint32_t)&backdrop; 1.58 + 1.59 + if((frameno++ & 1) == 0) { 1.60 + tmpcol = grid_pal[7]; 1.61 + for(i=7; i>2; i--) { 1.62 + grid_pal[i] = grid_pal[i - 1]; 1.63 + } 1.64 + grid_pal[2] = tmpcol; 1.65 + } 1.66 + 1.67 + for(i=0; i<MAX_GRID_SHADES; i++) { 1.68 + cplptr = (uint16_t*)cplist_pal[i]; 1.69 + for(j=1; j<8; j++) { 1.70 + /*uint16_t foo = 15 * (i + 1) / MAX_GRID_SHADES; 1.71 + cplptr[1] = (foo << 8) | (foo << 4) | foo;*/ 1.72 + uint16_t r = ((grid_pal[j] & 0xf00) >> 8) * (i + 1) / MAX_GRID_SHADES; 1.73 + uint16_t g = ((grid_pal[j] & 0xf0) >> 4) * (i + 1) / MAX_GRID_SHADES; 1.74 + uint16_t b = (grid_pal[j] & 0xf) * (i + 1) / MAX_GRID_SHADES; 1.75 + 1.76 + cplptr[1] = (r << 8) | (g << 4) | b; 1.77 + cplptr += 2; 1.78 + } 1.79 + } 1.80 } 1.81 1.82 cleanup(); 1.83 @@ -41,9 +96,10 @@ 1.84 1.85 int init(void) 1.86 { 1.87 - int i, x, y, bit; 1.88 + int i, j, x, y, bit; 1.89 unsigned char *fbptr; 1.90 unsigned char tmp; 1.91 + uint32_t grid_bpl0_addr, grid_bpl1_addr, grid_bpl2_addr; 1.92 1.93 Forbid(); 1.94 1.95 @@ -70,17 +126,49 @@ 1.96 REG_DDFSTART = 0x38; 1.97 REG_DDFSTOP = 0xd0; 1.98 1.99 - /* populate palette */ 1.100 - REG_COLOR0 = 0; 1.101 - REG_COLOR1 = 0xfff; 1.102 + grid_pal = (uint16_t*)(grid_addr + BPLSIZE * 3); 1.103 + 1.104 + grid_bpl0_addr = grid_addr; 1.105 + grid_bpl1_addr = grid_addr + BPLSIZE; 1.106 + grid_bpl2_addr = grid_addr + BPLSIZE * 2; 1.107 + 1.108 + for(i=0; i<8; i++) { 1.109 + REG_COLOR_PTR[i] = grid_pal[i]; 1.110 + } 1.111 1.112 wait_vblank(); 1.113 - REG32_BPL1PT = (uint32_t)&backdrop; 1.114 + add_copper(COPPER_MOVE(REGN_BPLCON0, BPLCON0_COUNT(1) | BPLCON0_COLOR)); 1.115 + add_copper(COPPER_MOVE(REGN_BPL1PTH, backdrop_addr >> 16)); 1.116 + add_copper(COPPER_MOVE(REGN_BPL1PTL, backdrop_addr)); 1.117 1.118 - add_copper(COPPER_VWAIT(40)); 1.119 - add_copper(COPPER_MOVE(REGN_COLOR1, 0xf80)); 1.120 - add_copper(COPPER_VWAIT(45)); 1.121 - add_copper(COPPER_MOVE(REGN_COLOR1, 0xfff)); 1.122 + add_copper(COPPER_MOVE(REGN_COLOR1, sky_color[0])); 1.123 + 1.124 + for(i=0; i<MAX_SKY_SHADES; i++) { 1.125 + add_copper(COPPER_VWAIT(i * 128 / MAX_SKY_SHADES)); 1.126 + add_copper(COPPER_MOVE(REGN_COLOR1, sky_color[i])); 1.127 + } 1.128 + 1.129 + add_copper(COPPER_VWAIT(125)); 1.130 + add_copper(COPPER_MOVE(REGN_BPLCON0, BPLCON0_COLOR)); 1.131 + 1.132 + add_copper(COPPER_MOVE(REGN_BPL1PTH, grid_bpl0_addr >> 16)); 1.133 + add_copper(COPPER_MOVE(REGN_BPL1PTL, grid_bpl0_addr)); 1.134 + add_copper(COPPER_MOVE(REGN_BPL2PTH, grid_bpl1_addr >> 16)); 1.135 + add_copper(COPPER_MOVE(REGN_BPL2PTL, grid_bpl1_addr)); 1.136 + add_copper(COPPER_MOVE(REGN_BPL3PTH, grid_bpl2_addr >> 16)); 1.137 + add_copper(COPPER_MOVE(REGN_BPL3PTL, grid_bpl2_addr)); 1.138 + 1.139 + add_copper(COPPER_VWAIT(128)); 1.140 + add_copper(COPPER_MOVE(REGN_BPLCON0, BPLCON0_COUNT(3) | BPLCON0_COLOR)); 1.141 + 1.142 + add_copper(COPPER_MOVE(REGN_COLOR0, grid_pal[0])); 1.143 + for(i=0; i<MAX_GRID_SHADES; i++) { 1.144 + add_copper(COPPER_VWAIT(128 + i * 64 / MAX_GRID_SHADES)); 1.145 + cplist_pal[i] = copperlist_end; /* save this copperlist pointer */ 1.146 + for(j=1; j<8; j++) { 1.147 + add_copper(COPPER_MOVE(REGN_COLOR(j), 0)); 1.148 + } 1.149 + } 1.150 add_copper(COPPER_END); 1.151 1.152 REG_DMACON = SETBITS(DMA_BPL | DMA_COPPER | DMA_MASTER);