};
/* palette data */
+//unsigned char bgtile_pal[] = {
+// 0x65, 0x06, 0x67, 0x06, 0x79, 0x07, 0x8c, 0x08, 0xff, 0x0f, 0xff, 0x0f,
+// 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f,
+// 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f
+//};
+
unsigned char bgtile_pal[] = {
- 0x65, 0x06, 0x67, 0x06, 0x79, 0x07, 0x8c, 0x08, 0xff, 0x0f, 0xff, 0x0f,
- 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f,
- 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f
+ 0x00, 0x00, 0x67, 0x06, 0x79, 0x07, 0x8c, 0x08, 0x00, 0x00, 0x12, 0x0b,
+ 0x00, 0x00, 0x10, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
*keyboard_intr++ = (&dummyS_isr);
*keyboard_intr = (0x2000);
- outport(IO_INT_ENABLE, INT_VBLANK_START);
+ //outport(IO_INT_ENABLE, INT_VBLANK_START);
//outport(IO_INT_ENABLE, INT_KEY_PRESS);
__asm__("sti");
}
unsigned width;
unsigned height;
unsigned bpp;
+ unsigned char * data;
+ SDL_Colour * palette;
+ unsigned short outpal[8];
} swan_gfx_t;
void set_info(swan_gfx_t * gfx, SDL_Surface * img)
/* set userdata to iterate */
SDL_LockSurface(img);
img->userdata = img->pixels;
+ gfx->data = (unsigned char *) img->userdata;
+ gfx->palette = img->format->palette->colors;
SDL_UnlockSurface(img);
+
}
-void generate_4bpp_tile(unsigned char *buf, void * userdata,
+void generate_4bpp_tile(unsigned char *buf, swan_gfx_t * gfx,
bool packed)
{
- unsigned char * ptr = (unsigned char *) userdata;
+ unsigned char * ptr = gfx->data;
for (int i = 0; i < TILE_SZ; i+=4) {
for (int j = 0; j < 4; ++j) {
if (packed) { /* packed format */
+ gfx->outpal[ptr[0]] = (gfx->palette[ptr[0]].r >> 4) << 8 |
+ (gfx->palette[ptr[0]].g >> 4) << 4 |
+ gfx->palette[ptr[0]].b >> 4;
buf[i+j] = ptr[0] << 4;
buf[i+j] |= ptr[1];
ptr += 2;
int main(int argc, char *argv[])
{
SDL_Surface * rawbmp;
- FILE * ostream;
+ FILE * gfxstream;
+ FILE * palstream;
int opt;
char * infile;
char outfile[256];
}
if (!bout)
- ostream = fopen("out.gfx", "w");
+ gfxstream = fopen("out.gfx", "w");
else {
printf("opening %s\n", outfile);
- ostream = fopen(outfile, "w");
+ gfxstream = fopen(outfile, "w");
}
- if (!ostream) {
+ if (!gfxstream) {
fprintf(stderr, "can not open file for writing!\n");
exit(EXIT_FAILURE);
}
unsigned nr_tiles = 1;
for (int i = 0; i < nr_tiles; ++i) {
- generate_4bpp_tile(tile_buf, rawbmp->userdata, true);
- int ret = fwrite(tile_buf, sizeof(unsigned char), TILE_SZ, ostream);
+ generate_4bpp_tile(tile_buf, gfx, true);
+ int ret = fwrite(tile_buf, sizeof(unsigned char), TILE_SZ, gfxstream);
if (ret != TILE_SZ) {
fprintf(stderr, "failed to convert, only write %d instead of %d\n", ret, TILE_SZ);
goto cleanup;
}
}
+
+ palstream = fopen("out.pal", "w");
+ if (!palstream) {
+ fprintf(stderr, "can not open file for writing!\n");
+ exit(EXIT_FAILURE);
+ }
+
+ fwrite(gfx->outpal, sizeof(unsigned short), 8, palstream);
+ const short fill = 0xFFFF;
+ for (int i = 0; i < 8; ++i)
+ fwrite(&fill, sizeof(unsigned short), 1, palstream);
cleanup:
free(gfx);
SDL_FreeSurface(rawbmp);
- fclose(ostream);
+ fclose(gfxstream);
+ fclose(palstream);
}