amiga_cyberspace

changeset 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
files src/copper.c src/copper.h src/data.s src/main.c
diffstat 4 files changed, 107 insertions(+), 15 deletions(-) [+]
line diff
     1.1 --- a/src/copper.c	Wed Jul 26 08:45:20 2017 +0300
     1.2 +++ b/src/copper.c	Thu Jul 27 02:34:42 2017 +0300
     1.3 @@ -5,8 +5,7 @@
     1.4  #include "copper.h"
     1.5  #include "hwregs.h"
     1.6  
     1.7 -uint32_t *copperlist;
     1.8 -static uint32_t *copperlist_end;
     1.9 +uint32_t *copperlist, *copperlist_end;
    1.10  static uint32_t *copmem, *curlist;
    1.11  static void *savedlist, *savedview;
    1.12  static int mode, copmem_size;
     2.1 --- a/src/copper.h	Wed Jul 26 08:45:20 2017 +0300
     2.2 +++ b/src/copper.h	Thu Jul 27 02:34:42 2017 +0300
     2.3 @@ -3,7 +3,7 @@
     2.4  
     2.5  #include "inttypes.h"
     2.6  
     2.7 -#define COPPER_MOVE(reg, data)	(((uint32_t)(reg) << 16) | (data))
     2.8 +#define COPPER_MOVE(reg, data)	(((uint32_t)(reg) << 16) | ((uint32_t)(data) & 0xffff))
     2.9  #define COPPER_WAIT(x, y) \
    2.10  	(0x0001fffe | ((uint32_t)((x) + 0x81) << 16) | ((uint32_t)((y) + 0x2c) << 24))
    2.11  #define COPPER_WAIT_OVERSCAN(x, y) \
    2.12 @@ -13,7 +13,7 @@
    2.13  	(0x0001ff00 | ((uint32_t)(s) << 24))
    2.14  #define COPPER_END				0xfffffffe
    2.15  
    2.16 -extern uint32_t *copperlist;
    2.17 +extern uint32_t *copperlist, *copperlist_end;
    2.18  
    2.19  enum {
    2.20  	COPPER_SINGLE = 1,
     3.1 --- a/src/data.s	Wed Jul 26 08:45:20 2017 +0300
     3.2 +++ b/src/data.s	Thu Jul 27 02:34:42 2017 +0300
     3.3 @@ -3,3 +3,8 @@
     3.4  	public _backdrop
     3.5  _backdrop:
     3.6  	incbin "data/backdrop2.img"
     3.7 +
     3.8 +	cnop 0,4
     3.9 +	public _grid
    3.10 +_grid:
    3.11 +	incbin "data/grid8.img"
     4.1 --- a/src/main.c	Wed Jul 26 08:45:20 2017 +0300
     4.2 +++ b/src/main.c	Thu Jul 27 02:34:42 2017 +0300
     4.3 @@ -16,6 +16,37 @@
     4.4  static uint16_t prev_intena, prev_intreq, prev_adkcon, prev_dmacon;
     4.5  
     4.6  extern uint32_t backdrop;
     4.7 +extern uint32_t grid;
     4.8 +
     4.9 +static uint32_t backdrop_addr = (uint32_t)&backdrop;
    4.10 +static uint32_t grid_addr = (uint32_t)&grid;
    4.11 +
    4.12 +static uint16_t *grid_pal;
    4.13 +
    4.14 +#define MAX_GRID_SHADES		6
    4.15 +static uint32_t *cplist_pal[MAX_GRID_SHADES];
    4.16 +
    4.17 +#define MAX_SKY_SHADES		32
    4.18 +static uint16_t sky_color[] = {
    4.19 +	0x204,
    4.20 +	0x306,
    4.21 +	0x307,
    4.22 +	0x408, 0x408,
    4.23 +	0x509,
    4.24 +	0x50a,
    4.25 +	0x60b, 0x60b,
    4.26 +	0x60c, 0x60c,
    4.27 +	0x70c, 0x70c,
    4.28 +	0x80c,
    4.29 +	0x80d,
    4.30 +	0x90d, 0x90d,
    4.31 +	0xa0d,
    4.32 +	0xb0c, 0xb0c, 0xb0c,
    4.33 +	0xc0c, 0xc0c,
    4.34 +	0xd0c, 0xd0c,
    4.35 +	0xd0b, 0xd0b, 0xd0b, 0xd0b,
    4.36 +	0xe0a, 0xe0a, 0xe0a
    4.37 +};
    4.38  
    4.39  int init(void);
    4.40  void cleanup(void);
    4.41 @@ -24,7 +55,10 @@
    4.42  
    4.43  int main(void)
    4.44  {
    4.45 -	int x, y;
    4.46 +	int i, j, x, y;
    4.47 +	long frameno = 0;
    4.48 +	uint16_t tmpcol;
    4.49 +	uint16_t *cplptr;
    4.50  
    4.51  	if(init() == -1) {
    4.52  		return 1;
    4.53 @@ -32,7 +66,28 @@
    4.54  
    4.55  	while(!mouse_state(&x, &y)) {
    4.56  		wait_vblank();
    4.57 -		REG32_BPL1PT = (uint32_t)&backdrop;
    4.58 +
    4.59 +		if((frameno++ & 1) == 0) {
    4.60 +			tmpcol = grid_pal[7];
    4.61 +			for(i=7; i>2; i--) {
    4.62 +				grid_pal[i] = grid_pal[i - 1];
    4.63 +			}
    4.64 +			grid_pal[2] = tmpcol;
    4.65 +		}
    4.66 +
    4.67 +		for(i=0; i<MAX_GRID_SHADES; i++) {
    4.68 +			cplptr = (uint16_t*)cplist_pal[i];
    4.69 +			for(j=1; j<8; j++) {
    4.70 +				/*uint16_t foo = 15 * (i + 1) / MAX_GRID_SHADES;
    4.71 +				cplptr[1] = (foo << 8) | (foo << 4) | foo;*/
    4.72 +				uint16_t r = ((grid_pal[j] & 0xf00) >> 8) * (i + 1) / MAX_GRID_SHADES;
    4.73 +				uint16_t g = ((grid_pal[j] & 0xf0) >> 4) * (i + 1) / MAX_GRID_SHADES;
    4.74 +				uint16_t b = (grid_pal[j] & 0xf) * (i + 1) / MAX_GRID_SHADES;
    4.75 +
    4.76 +				cplptr[1] = (r << 8) | (g << 4) | b;
    4.77 +				cplptr += 2;
    4.78 +			}
    4.79 +		}
    4.80  	}
    4.81  
    4.82  	cleanup();
    4.83 @@ -41,9 +96,10 @@
    4.84  
    4.85  int init(void)
    4.86  {
    4.87 -	int i, x, y, bit;
    4.88 +	int i, j, x, y, bit;
    4.89  	unsigned char *fbptr;
    4.90  	unsigned char tmp;
    4.91 +	uint32_t grid_bpl0_addr, grid_bpl1_addr, grid_bpl2_addr;
    4.92  
    4.93  	Forbid();
    4.94  
    4.95 @@ -70,17 +126,49 @@
    4.96  	REG_DDFSTART = 0x38;
    4.97  	REG_DDFSTOP = 0xd0;
    4.98  
    4.99 -	/* populate palette */
   4.100 -	REG_COLOR0 = 0;
   4.101 -	REG_COLOR1 = 0xfff;
   4.102 +	grid_pal = (uint16_t*)(grid_addr + BPLSIZE * 3);
   4.103 +
   4.104 +	grid_bpl0_addr = grid_addr;
   4.105 +	grid_bpl1_addr = grid_addr + BPLSIZE;
   4.106 +	grid_bpl2_addr = grid_addr + BPLSIZE * 2;
   4.107 +
   4.108 +	for(i=0; i<8; i++) {
   4.109 +		REG_COLOR_PTR[i] = grid_pal[i];
   4.110 +	}
   4.111  
   4.112  	wait_vblank();
   4.113 -	REG32_BPL1PT = (uint32_t)&backdrop;
   4.114 +	add_copper(COPPER_MOVE(REGN_BPLCON0, BPLCON0_COUNT(1) | BPLCON0_COLOR));
   4.115 +	add_copper(COPPER_MOVE(REGN_BPL1PTH, backdrop_addr >> 16));
   4.116 +	add_copper(COPPER_MOVE(REGN_BPL1PTL, backdrop_addr));
   4.117  
   4.118 -	add_copper(COPPER_VWAIT(40));
   4.119 -	add_copper(COPPER_MOVE(REGN_COLOR1, 0xf80));
   4.120 -	add_copper(COPPER_VWAIT(45));
   4.121 -	add_copper(COPPER_MOVE(REGN_COLOR1, 0xfff));
   4.122 +	add_copper(COPPER_MOVE(REGN_COLOR1, sky_color[0]));
   4.123 +
   4.124 +	for(i=0; i<MAX_SKY_SHADES; i++) {
   4.125 +		add_copper(COPPER_VWAIT(i * 128 / MAX_SKY_SHADES));
   4.126 +		add_copper(COPPER_MOVE(REGN_COLOR1, sky_color[i]));
   4.127 +	}
   4.128 +
   4.129 +	add_copper(COPPER_VWAIT(125));
   4.130 +	add_copper(COPPER_MOVE(REGN_BPLCON0, BPLCON0_COLOR));
   4.131 +
   4.132 +	add_copper(COPPER_MOVE(REGN_BPL1PTH, grid_bpl0_addr >> 16));
   4.133 +	add_copper(COPPER_MOVE(REGN_BPL1PTL, grid_bpl0_addr));
   4.134 +	add_copper(COPPER_MOVE(REGN_BPL2PTH, grid_bpl1_addr >> 16));
   4.135 +	add_copper(COPPER_MOVE(REGN_BPL2PTL, grid_bpl1_addr));
   4.136 +	add_copper(COPPER_MOVE(REGN_BPL3PTH, grid_bpl2_addr >> 16));
   4.137 +	add_copper(COPPER_MOVE(REGN_BPL3PTL, grid_bpl2_addr));
   4.138 +
   4.139 +	add_copper(COPPER_VWAIT(128));
   4.140 +	add_copper(COPPER_MOVE(REGN_BPLCON0, BPLCON0_COUNT(3) | BPLCON0_COLOR));
   4.141 +
   4.142 +	add_copper(COPPER_MOVE(REGN_COLOR0, grid_pal[0]));
   4.143 +	for(i=0; i<MAX_GRID_SHADES; i++) {
   4.144 +		add_copper(COPPER_VWAIT(128 + i * 64 / MAX_GRID_SHADES));
   4.145 +		cplist_pal[i] = copperlist_end;	/* save this copperlist pointer */
   4.146 +		for(j=1; j<8; j++) {
   4.147 +			add_copper(COPPER_MOVE(REGN_COLOR(j), 0));
   4.148 +		}
   4.149 +	}
   4.150  	add_copper(COPPER_END);
   4.151  
   4.152  	REG_DMACON = SETBITS(DMA_BPL | DMA_COPPER | DMA_MASTER);