[Pipeline] bmp2arr: Move C type generation into a single function

Part of P0205, funded by [Anonymous] and Yanga.
This commit is contained in:
nmlgc 2022-07-16 00:46:56 +02:00
parent 47dc6a6285
commit caf48cf3ef
1 changed files with 19 additions and 24 deletions

View File

@ -268,42 +268,37 @@ static int memcpy32to1(unsigned char *dst,unsigned char *src,unsigned int w) {
return -1;
}
static void saveout_write_c_type(struct rec98_bmp2arr_task *t,struct saveout_ctx *sctx) {
fprintf(sctx->fp,"const unsigned char %s",t->output_symname != NULL ? t->output_symname : "untitled");
if (t->flags & PRESHIFT_OUTER)
fprintf(sctx->fp,"[8/*PRESHIFT*/]");
fprintf(sctx->fp,"[%d]",sctx->ssrows * sctx->sscols);
if (t->flags & PRESHIFT_INNER)
fprintf(sctx->fp,"[8/*PRESHIFT*/]");
fprintf(sctx->fp,"[%d/*%d bytes x %d rows*/]",sctx->bytesperrow * t->sprite_height,sctx->bytesperrow,t->sprite_height);
}
static int saveout_write_prologue(struct rec98_bmp2arr_task *t,struct saveout_ctx *sctx) {
if (t->output_type == REC98_OUT_C) {
fprintf(sctx->fp,"/* Generated by bmp2arr from %s, do not modify directly. */\n",t->input_bmp);
fprintf(sctx->fp,"/* Sprite sheet: %d sprites (%d x %d) of %d x %d sprites. */\n",sctx->sscols * sctx->ssrows,sctx->sscols,sctx->ssrows,t->sprite_width,t->sprite_height);
fprintf(sctx->fp,"\n");
fprintf(sctx->fp,"const unsigned char %s",t->output_symname != NULL ? t->output_symname : "untitled");
if (t->flags & PRESHIFT_OUTER)
fprintf(sctx->fp,"[8/*PRESHIFT*/]");
fprintf(sctx->fp,"[%d]",sctx->ssrows * sctx->sscols);
if (t->flags & PRESHIFT_INNER)
fprintf(sctx->fp,"[8/*PRESHIFT*/]");
fprintf(sctx->fp,"[%d/*%d bytes x %d rows*/] = {\n",
sctx->bytesperrow * t->sprite_height,sctx->bytesperrow,t->sprite_height);
saveout_write_c_type(t,sctx);
fprintf(sctx->fp," = {\n");
}
else if (t->output_type == REC98_OUT_ASM) {
fprintf(sctx->fp,"; Generated by bmp2arr from %s, do not modify directly.\n",t->input_bmp);
fprintf(sctx->fp,"; Sprite sheet: %d sprites (%d x %d) of %d x %d sprites.\n",sctx->sscols * sctx->ssrows,sctx->sscols,sctx->ssrows,t->sprite_width,t->sprite_height);
fprintf(sctx->fp,"\n");
fprintf(sctx->fp,"; const unsigned char %s",t->output_symname != NULL ? t->output_symname : "untitled");
if (t->flags & PRESHIFT_OUTER)
fprintf(sctx->fp,"[8/*PRESHIFT*/]");
fprintf(sctx->fp,"[%d]",sctx->ssrows * sctx->sscols);
if (t->flags & PRESHIFT_INNER)
fprintf(sctx->fp,"[8/*PRESHIFT*/]");
fprintf(sctx->fp,"[%d/*%d bytes x %d rows*/];\n",
sctx->bytesperrow * t->sprite_height,sctx->bytesperrow,t->sprite_height);
fprintf(sctx->fp,"; ");
saveout_write_c_type(t,sctx);
fprintf(sctx->fp,";\n");
fprintf(sctx->fp,"public %s\n",t->output_symname != NULL ? t->output_symname : "untitled");
fprintf(sctx->fp,"label %s byte\n",t->output_symname != NULL ? t->output_symname : "untitled");