new sprite system first successfull test
[retrocrawl] / src / game.c
index 37c39b2..89b4e5a 100644 (file)
@@ -3,6 +3,7 @@
 #include "gfx.h"
 #include "copper.h"
 #include "data.h"
+#include "sprite.h"
 
 #include "hwregs.h"    /* XXX */
 
 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))
 
+/* hardcoded test sprite */
+static struct sprite test_sprite;
 
 int game_init(void)
 {
-       int i, sprpos[] = {136, 76};
-       uint32_t nullspr_addr = (intptr_t)nullspr;
+       int i;
 
        REG_COLOR0 = 0x221;
        REG_COLOR1 = 0x222;
@@ -47,31 +41,15 @@ int game_init(void)
        sprdata[4] = spr2a;
        sprdata[5] = spr2b;
 
+       test_sprite.width = test_sprite.height = 48;
+       test_sprite.origx = 24;
+       test_sprite.origy = 24;
+       test_sprite.img = test_sprite.mask = 0;
+       test_sprite.hwslices = 3;
        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));
-               }
+               test_sprite.hwspr[i] = i < 6 ? sprdata[i] : 0;
        }
 
-       *copperlist_end = COPPER_END;
-
        return 0;
 }
 
@@ -82,8 +60,6 @@ void game_draw(void)
 {
        int i, j, xoffs, yoffs, ntiles;
 
-       /* reset sprite data */
-
        yoffs = 0;
        for(i=0; i<YTILES; i++) {
                xoffs = i & 1 ? TILE_W / 2 : 0;
@@ -94,6 +70,10 @@ void game_draw(void)
                }
                yoffs += TILE_H / 2;
        }
+
+       begin_sprites();
+       draw_sprite(&test_sprite, 160, 100);
+       end_sprites();
 }