-static int gd_i[4];
-static int gd_c[4];
-static int gd_ia, gd_ca;
-static int colour_index = 0;
-static int32 zadd;
-static uint32 z_i[4];
-
-static uint32 a1_clip_x, a1_clip_y;
-
-static uint8 blitter_code_cache[4096];
-static uint8 * blitter_ptr;
-uint8 blitter_working = 0;
-
-typedef void (blitter_fn)(void);
-
-typedef struct s_blitter_cache
-{
- uint32 hashcode;
- uint8 * code;
- uint32 ready;
- uint8 used;
- struct s_blitter_cache * next;
- struct s_blitter_cache * prev;
-} s_blitter_code_cache;
-
-s_blitter_cache * blitter_cache[256];
-
-uint8 blitter_cache_init = 0;
-static uint8 BPP_LUT[8] = { 1, 2, 4, 8, 16, 32, 0, 0 };
-
-FILE * blitters_code_fp;
-FILE * blitters_code_init_fp;
-
-//////////////////////////////////////////////////////////////////////////////
-// build C code for the specified blitter
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
-void blitter_gen_c_code(FILE *fp, uint32 cmd,uint32 hashcode)
-{
- static uint8 inhibit_modified=0;
-
- fprintf(fp,"#ifndef blitter_code_0x%.8x\n",hashcode);
- fprintf(fp,"#define blitter_code_0x%.8x\n",hashcode);
-
- fprintf(fp,"void blitter_0x%.8x(void)\n",hashcode);
- fprintf(fp,"{\n");
- fprintf(fp,"\twhile (outer_loop--)\n");
- fprintf(fp,"\t{\n");
- fprintf(fp,"\t\tinner_loop=n_pixels;\n");
- fprintf(fp,"\t\twhile (inner_loop--)\n");
- fprintf(fp,"\t\t{\n");
- fprintf(fp,"\t\t\tuint32 srcdata = 0;\n");
- fprintf(fp,"\t\t\tuint32 srczdata = 0;\n");
- fprintf(fp,"\t\t\tuint32 dstdata = 0;\n");
- fprintf(fp,"\t\t\tuint32 dstzdata = 0;\n");
- fprintf(fp,"\t\t\tuint32 writedata = 0;\n");
- fprintf(fp,"\t\t\tuint32 inhibit = 0;\n");
-
- char *src;
- char *dst;
- uint32 src_flags;
- uint32 dst_flags;
-
- if (!DSTA2)
- {
- src="a2";
- dst="a1";
- src_flags=A2_FLAGS;
- dst_flags=A1_FLAGS;
- }
- else
- {
- src="a1";
- dst="a2";
- src_flags=A1_FLAGS;
- dst_flags=A2_FLAGS;
- }
-
- // load src data and Z
- if (SRCEN)
- {
- fprintf(fp, "\t\t\tsrcdata = READ_PIXEL_%i(%s);\n", BPP_LUT[(((REG(dst_flags)) >> 3) & 0x07)], src);
- if (SRCENZ)
- fprintf(fp,"\t\t\tsrczdata = READ_ZDATA_%i(%s);\n",BPP_LUT[(((REG(dst_flags))>>3)&0x07)],src);
- else
- if (cmd & 0x001c020)
- fprintf(fp,"\t\t\tsrczdata = READ_RDATA_%i(SRCZINT, %s, %s_phrase_mode);\n",BPP_LUT[(((REG(src_flags))>>3)&0x07)],src,src);
- }
- else
- {
- fprintf(fp,"\t\t\tsrcdata = READ_RDATA_%i(SRCDATA, %s, %s_phrase_mode);\n",BPP_LUT[(((REG(dst_flags))>>3)&0x07)],src,src);
- if (cmd & 0x001c020)
- fprintf(fp,"\t\t\tsrczdata = READ_RDATA_%i(SRCZINT, %s, %s_phrase_mode);\n",BPP_LUT[(((REG(dst_flags))>>3)&0x07)],src,src);
- }
-
- // load dst data and Z
- if (DSTEN)
- {
- fprintf(fp,"\t\t\tdstdata = READ_PIXEL_%i(%s);\n",BPP_LUT[(((REG(dst_flags))>>3)&0x07)],dst);
- if (DSTENZ)
- fprintf(fp,"\t\t\tdstzdata = READ_ZDATA_%i(%s);\n",BPP_LUT[(((REG(dst_flags))>>3)&0x07)],dst);
- else
- fprintf(fp,"\t\t\tdstzdata = READ_RDATA_%i(DSTZ, %s, %s_phrase_mode);\n",BPP_LUT[(((REG(dst_flags))>>3)&0x07)],dst,dst);
- }
- else
- {
- fprintf(fp,"\t\t\tdstdata = READ_RDATA_%i(DSTDATA, %s, %s_phrase_mode);\n",BPP_LUT[(((REG(dst_flags))>>3)&0x07)],dst,dst);
-
- if (DSTENZ)
- fprintf(fp,"\t\t\tdstzdata = READ_RDATA_%i(DSTZ, %s, %s_phrase_mode);\n",BPP_LUT[(((REG(dst_flags))>>3)&0x07)],dst,dst);
- }
-
- // a1 clipping
- if ((cmd & 0x00000040)&&(!DSTA2))
-
- {
- fprintf(fp,"\t\t\tif (a1_x < 0 || a1_y < 0 || (a1_x >> 16) >= (REG(A1_CLIP) & 0x7fff) || (a1_y >> 16) >= ((REG(A1_CLIP) >> 16) & 0x7fff)) inhibit = 1;\n");
- inhibit_modified=1;
- }
- if(GOURZ)
- {
- fprintf(fp,"\t\t\tsrczdata=z_i[colour_index]>>16;\n");
- }
- // apply z comparator
- if (Z_OP_INF) { fprintf(fp,"\t\t\tif (srczdata < dstzdata) inhibit = 1;\n"); inhibit_modified=1;}
- if (Z_OP_EQU) { fprintf(fp,"\t\t\tif (srczdata == dstzdata) inhibit = 1;\n"); inhibit_modified=1;}
- if (Z_OP_SUP) { fprintf(fp,"\t\t\tif (srczdata > dstzdata) inhibit = 1;\n"); inhibit_modified=1;}
-
- // apply data comparator
- if (DCOMPEN)
- {
- if (!CMPDST)
- {
- // compare source pixel with pattern pixel
- fprintf(fp,"\t\t\tif (srcdata == READ_RDATA_%i(PATTERNDATA, %s,%s_phrase_mode)) inhibit=1;\n",BPP_LUT[(((REG(dst_flags))>>3)&0x07)],src,src);
- inhibit_modified=1;
- }
- else
- {
- // compare destination pixel with pattern pixel
- fprintf(fp,"\t\t\tif (dstdata == READ_RDATA_%i(PATTERNDATA, %s,%s_phrase_mode)) inhibit=1;\n",BPP_LUT[(((REG(dst_flags))>>3)&0x07)],dst,dst);
- inhibit_modified=1;
- }
- }
-
- // compute the write data and store
- if (inhibit_modified) fprintf(fp,"\t\t\tif (!inhibit)\n\t\t\t{\n");
- if (PATDSEL)
- {
- // use pattern data for write data
- fprintf(fp,"\t\t\t\twritedata= READ_RDATA_%i(PATTERNDATA, %s, %s_phrase_mode);\n",BPP_LUT[(((REG(dst_flags))>>3)&0x07)],dst,dst);
- }
- else
- if (INTADD)
- {
- // intensity addition
- fprintf(fp,"\t\t\t\twritedata = (srcdata & 0xff) + (dstdata & 0xff);\n");
- if (!(TOPBEN))
- fprintf(fp,"\t\t\t\tif (writedata > 0xff) writedata = 0xff;\n");
-
- fprintf(fp,"\t\t\t\twritedata |= (srcdata & 0xf00) + (dstdata & 0xf00);\n");
- if (!(TOPNEN)) fprintf(fp,"\t\t\t\tif (writedata > 0xfff) writedata = 0xfff;\n");
- fprintf(fp,"\t\t\t\twritedata |= (srcdata & 0xf000) + (dstdata & 0xf000);\n");
- }
- else
- {
- if (LFU_NAN) fprintf(fp,"\t\t\t\twritedata |= ~srcdata & ~dstdata;\n");
- if (LFU_NA) fprintf(fp,"\t\t\t\twritedata |= ~srcdata & dstdata;\n");
- if (LFU_AN) fprintf(fp,"\t\t\t\twritedata |= srcdata & ~dstdata;\n");
- if (LFU_A) fprintf(fp,"\t\t\t\twritedata |= srcdata & dstdata;\n");
- }
- if(GOURD)
- {
- fprintf(fp,"\t\t\t\twritedata = ((gd_c[colour_index])<<8)|(gd_i[colour_index]>>16);\n");
- }
- if(SRCSHADE)
- {
- fprintf(fp,"\t\t\t\t{\n");
- fprintf(fp,"\t\t\t\tint intensity = srcdata & 0xFF;\n");
- fprintf(fp,"\t\t\t\tint ia = gd_ia >> 16;\n");
- fprintf(fp,"\t\t\t\tif(ia & 0x80)\n");
- fprintf(fp,"\t\t\t\t ia = 0xFFFFFF00 | ia;\n");
- fprintf(fp,"\t\t\t\tintensity += ia;\n");
- fprintf(fp,"\t\t\t\tif(intensity < 0)\n");
- fprintf(fp,"\t\t\t\t intensity = 0;\n");
- fprintf(fp,"\t\t\t\tif(intensity > 0xFF)\n");
- fprintf(fp,"\t\t\t\t intensity = 0xFF;\n");
- fprintf(fp,"\t\t\t\twritedata = (srcdata & 0xFF00) | intensity;\n");
- fprintf(fp,"\t\t\t\t}\n");
- }
- if (inhibit_modified)
- {
- fprintf(fp,"\t\t\t} else { srczdata=dstzdata; writedata=dstdata; }\n");
- }