X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=retrocrawl;a=blobdiff_plain;f=tools%2Fconv_sprite.c;fp=tools%2Fconv_sprite.c;h=ff50a6a8bf29809263ed3628a3453487c7b24dda;hp=0000000000000000000000000000000000000000;hb=af94a88e5de76c4b00df102f82643b4b64cb529a;hpb=87c45ef8c82a3925719cbf2024e5932208b244ce diff --git a/tools/conv_sprite.c b/tools/conv_sprite.c new file mode 100644 index 0000000..ff50a6a --- /dev/null +++ b/tools/conv_sprite.c @@ -0,0 +1,90 @@ +#include +#include +#include +#include + +#include HDRFILE + +#define MAX_SPRITE_WIDTH 16 + +static void conv_sprite(int slice, unsigned char *img, int width, int height, int pitch); +static void conv_img_data(int sub, uint16_t *out, unsigned char *img, int width, + int height, int pitch); + +int main(int argc, char **argv) +{ + int i, nslices; + + nslices = (width + MAX_SPRITE_WIDTH - 1) / MAX_SPRITE_WIDTH; + fprintf(stderr, "source image: %dx%d. splitting into %d slices\n", + width, height, nslices); + + printf("\t.data\n\n"); + + for(i=0; i MAX_SPRITE_WIDTH) spr_w = MAX_SPRITE_WIDTH; + + conv_sprite(i, header_data + xstart, spr_w, height, width); + } + + printf("\n\t.global sprpal\n"); + printf("sprpal:\n"); + for(i=0; i<16; i++) { + int r = header_data_cmap[i][0] >> 4; + int g = header_data_cmap[i][1] >> 4; + int b = header_data_cmap[i][2] >> 4; + unsigned int col = ((r & 0xf) << 8) | ((g & 0xf) << 4) | (b & 0xf); + printf("\t.short 0x%03x\n", col); + } +} + +static void conv_sprite(int slice, unsigned char *img, int width, int height, int pitch) +{ + int i, j; + uint16_t *sprdata; + + for(i=0; i<2; i++) { + printf("\n\t.global spr%d%c\n", slice, i == 0 ? 'a' : 'b'); + printf("spr%d%c:\n", slice, i == 0 ? 'a' : 'b'); + printf("\t.short 0\n"); /* position x/y */ + printf("\t.short 0\n"); /* vstop */ + + sprdata = malloc(height * 2 * sizeof *sprdata); + conv_img_data(i, sprdata, img, width, height, pitch); + + for(j=0; j> inshift) & 1); + bit1 = (bit1 << 1) | ((img[j] >> (inshift + 1)) & 1); + } + if(width < MAX_SPRITE_WIDTH) { + bit0 <<= MAX_SPRITE_WIDTH - width; + bit1 <<= MAX_SPRITE_WIDTH - width; + } + *out++ = bit0; + *out++ = bit1; + img += pitch; + } +} +