X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=retrocrawl;a=blobdiff_plain;f=src%2Fgame.c;fp=src%2Fgame.c;h=37c39b2e252255fc5987f11acbedc36e8fc6091d;hp=97c1895be7f7647790e37fbbba43332d541b3a0b;hb=196421f047414a192f285c8e98346a4595da2d46;hpb=af94a88e5de76c4b00df102f82643b4b64cb529a diff --git a/src/game.c b/src/game.c index 97c1895..37c39b2 100644 --- a/src/game.c +++ b/src/game.c @@ -1,6 +1,7 @@ #include #include "game.h" #include "gfx.h" +#include "copper.h" #include "data.h" #include "hwregs.h" /* XXX */ @@ -10,9 +11,22 @@ void draw_tile(int tid, int x, int y, int light); +static uint16_t *sprdata[NUM_HWSPRITES]; +static uint16_t nullspr[] = { + 0x2000, 0x2100, + 0x0000, 0x0000, + 0x0000, 0x0000 +}; + +#define SPR_POS(x, y) \ + (((uint16_t)((x) + 0x40) & 0xff) | ((uint16_t)((y) + 0x2c) << 8)) + int game_init(void) { + int i, sprpos[] = {136, 76}; + uint32_t nullspr_addr = (intptr_t)nullspr; + REG_COLOR0 = 0x221; REG_COLOR1 = 0x222; REG_COLOR2 = 0x332; @@ -22,6 +36,42 @@ int game_init(void) REG_COLOR6 = 0x654; REG_COLOR7 = 0x765; + for(i=0; i<16; i++) { + REG_COLOR_PTR[i + 16] = sprpal[i]; + } + + sprdata[0] = spr0a; + sprdata[1] = spr0b; + sprdata[2] = spr1a; + sprdata[3] = spr1b; + sprdata[4] = spr2a; + sprdata[5] = spr2b; + + for(i=0; i<8; i++) { + int reg = REGN_SPR0PTH + i * 4; + if(i < NUM_HWSPRITES) { + uint16_t sx, sy, vstop; + /* initialize active sprites, and set the sprite pointers */ + uint32_t addr = (intptr_t)sprdata[i]; + add_copper(COPPER_MOVE(reg, addr >> 16)); + add_copper(COPPER_MOVE(reg + 2, addr)); + + sx = 0x80 + sprpos[0] + (i >> 1) * 16; + sy = 0x2c + sprpos[1]; + vstop = sy + SPRITE_HEIGHT; + + sprdata[i][0] = (sx >> 1) | (sy << 8); + sprdata[i][1] = (vstop << 8) | ((vstop >> 7) & 2) | + (sx & 1) | ((i & 1) ? 0x80 : 0); + } else { + /* point the sprite pointers to the null sprite for the rest */ + add_copper(COPPER_MOVE(reg, nullspr_addr >> 16)); + add_copper(COPPER_MOVE(reg + 2, nullspr_addr)); + } + } + + *copperlist_end = COPPER_END; + return 0; } @@ -32,6 +82,8 @@ void game_draw(void) { int i, j, xoffs, yoffs, ntiles; + /* reset sprite data */ + yoffs = 0; for(i=0; i