# HG changeset patch # User John Tsiombikas # Date 1501112082 -10800 # Node ID b98fa9b135eaf6dc101401c5715e280471673bdd # Parent b5d609c7161d7790e5ecbfb621e75288d3f98385 first version which looks good diff -r b5d609c7161d -r b98fa9b135ea src/copper.c --- a/src/copper.c Wed Jul 26 08:45:20 2017 +0300 +++ b/src/copper.c Thu Jul 27 02:34:42 2017 +0300 @@ -5,8 +5,7 @@ #include "copper.h" #include "hwregs.h" -uint32_t *copperlist; -static uint32_t *copperlist_end; +uint32_t *copperlist, *copperlist_end; static uint32_t *copmem, *curlist; static void *savedlist, *savedview; static int mode, copmem_size; diff -r b5d609c7161d -r b98fa9b135ea src/copper.h --- a/src/copper.h Wed Jul 26 08:45:20 2017 +0300 +++ b/src/copper.h Thu Jul 27 02:34:42 2017 +0300 @@ -3,7 +3,7 @@ #include "inttypes.h" -#define COPPER_MOVE(reg, data) (((uint32_t)(reg) << 16) | (data)) +#define COPPER_MOVE(reg, data) (((uint32_t)(reg) << 16) | ((uint32_t)(data) & 0xffff)) #define COPPER_WAIT(x, y) \ (0x0001fffe | ((uint32_t)((x) + 0x81) << 16) | ((uint32_t)((y) + 0x2c) << 24)) #define COPPER_WAIT_OVERSCAN(x, y) \ @@ -13,7 +13,7 @@ (0x0001ff00 | ((uint32_t)(s) << 24)) #define COPPER_END 0xfffffffe -extern uint32_t *copperlist; +extern uint32_t *copperlist, *copperlist_end; enum { COPPER_SINGLE = 1, diff -r b5d609c7161d -r b98fa9b135ea src/data.s --- a/src/data.s Wed Jul 26 08:45:20 2017 +0300 +++ b/src/data.s Thu Jul 27 02:34:42 2017 +0300 @@ -3,3 +3,8 @@ public _backdrop _backdrop: incbin "data/backdrop2.img" + + cnop 0,4 + public _grid +_grid: + incbin "data/grid8.img" diff -r b5d609c7161d -r b98fa9b135ea src/main.c --- a/src/main.c Wed Jul 26 08:45:20 2017 +0300 +++ b/src/main.c Thu Jul 27 02:34:42 2017 +0300 @@ -16,6 +16,37 @@ static uint16_t prev_intena, prev_intreq, prev_adkcon, prev_dmacon; extern uint32_t backdrop; +extern uint32_t grid; + +static uint32_t backdrop_addr = (uint32_t)&backdrop; +static uint32_t grid_addr = (uint32_t)&grid; + +static uint16_t *grid_pal; + +#define MAX_GRID_SHADES 6 +static uint32_t *cplist_pal[MAX_GRID_SHADES]; + +#define MAX_SKY_SHADES 32 +static uint16_t sky_color[] = { + 0x204, + 0x306, + 0x307, + 0x408, 0x408, + 0x509, + 0x50a, + 0x60b, 0x60b, + 0x60c, 0x60c, + 0x70c, 0x70c, + 0x80c, + 0x80d, + 0x90d, 0x90d, + 0xa0d, + 0xb0c, 0xb0c, 0xb0c, + 0xc0c, 0xc0c, + 0xd0c, 0xd0c, + 0xd0b, 0xd0b, 0xd0b, 0xd0b, + 0xe0a, 0xe0a, 0xe0a +}; int init(void); void cleanup(void); @@ -24,7 +55,10 @@ int main(void) { - int x, y; + int i, j, x, y; + long frameno = 0; + uint16_t tmpcol; + uint16_t *cplptr; if(init() == -1) { return 1; @@ -32,7 +66,28 @@ while(!mouse_state(&x, &y)) { wait_vblank(); - REG32_BPL1PT = (uint32_t)&backdrop; + + if((frameno++ & 1) == 0) { + tmpcol = grid_pal[7]; + for(i=7; i>2; i--) { + grid_pal[i] = grid_pal[i - 1]; + } + grid_pal[2] = tmpcol; + } + + for(i=0; i> 8) * (i + 1) / MAX_GRID_SHADES; + uint16_t g = ((grid_pal[j] & 0xf0) >> 4) * (i + 1) / MAX_GRID_SHADES; + uint16_t b = (grid_pal[j] & 0xf) * (i + 1) / MAX_GRID_SHADES; + + cplptr[1] = (r << 8) | (g << 4) | b; + cplptr += 2; + } + } } cleanup(); @@ -41,9 +96,10 @@ int init(void) { - int i, x, y, bit; + int i, j, x, y, bit; unsigned char *fbptr; unsigned char tmp; + uint32_t grid_bpl0_addr, grid_bpl1_addr, grid_bpl2_addr; Forbid(); @@ -70,17 +126,49 @@ REG_DDFSTART = 0x38; REG_DDFSTOP = 0xd0; - /* populate palette */ - REG_COLOR0 = 0; - REG_COLOR1 = 0xfff; + grid_pal = (uint16_t*)(grid_addr + BPLSIZE * 3); + + grid_bpl0_addr = grid_addr; + grid_bpl1_addr = grid_addr + BPLSIZE; + grid_bpl2_addr = grid_addr + BPLSIZE * 2; + + for(i=0; i<8; i++) { + REG_COLOR_PTR[i] = grid_pal[i]; + } wait_vblank(); - REG32_BPL1PT = (uint32_t)&backdrop; + add_copper(COPPER_MOVE(REGN_BPLCON0, BPLCON0_COUNT(1) | BPLCON0_COLOR)); + add_copper(COPPER_MOVE(REGN_BPL1PTH, backdrop_addr >> 16)); + add_copper(COPPER_MOVE(REGN_BPL1PTL, backdrop_addr)); - add_copper(COPPER_VWAIT(40)); - add_copper(COPPER_MOVE(REGN_COLOR1, 0xf80)); - add_copper(COPPER_VWAIT(45)); - add_copper(COPPER_MOVE(REGN_COLOR1, 0xfff)); + add_copper(COPPER_MOVE(REGN_COLOR1, sky_color[0])); + + for(i=0; i> 16)); + add_copper(COPPER_MOVE(REGN_BPL1PTL, grid_bpl0_addr)); + add_copper(COPPER_MOVE(REGN_BPL2PTH, grid_bpl1_addr >> 16)); + add_copper(COPPER_MOVE(REGN_BPL2PTL, grid_bpl1_addr)); + add_copper(COPPER_MOVE(REGN_BPL3PTH, grid_bpl2_addr >> 16)); + add_copper(COPPER_MOVE(REGN_BPL3PTL, grid_bpl2_addr)); + + add_copper(COPPER_VWAIT(128)); + add_copper(COPPER_MOVE(REGN_BPLCON0, BPLCON0_COUNT(3) | BPLCON0_COLOR)); + + add_copper(COPPER_MOVE(REGN_COLOR0, grid_pal[0])); + for(i=0; i