static void draw_one_sprite(sprite_params_data data, uint[] dest, int xclip, int scanline) { int xstep = data.xscale; int xoffs = data.xoffs; int xcurr, offset; UIntSubArray src; /* xoffs of -1 means don't draw */ if (xoffs == -1) return; /* clip to the road */ xcurr = 0; if (xoffs < xclip) { /* the pixel clock starts on xoffs regardless of clipping; take this into account */ xcurr = ((xclip - xoffs) * xstep) & 0xffff; xoffs = xclip; } /* compute the current data offset */ scanline = ((scanline - data.miny) * data.yscale) >> 16; offset = data.offset + (scanline + 1) * data.rowbytes; /* determine the bitmap location */ src = new UIntSubArray(data._base, (int)(offset & 0x7fff)); /* loop over columns */ while (xoffs < VIEW_WIDTH) { uint srcval = src[xcurr >> 16]; /* stop on the end-of-row signal */ if (srcval == 0x12345678) break; dest[xoffs++] |= srcval; xcurr += xstep; } }
public override int vh_start() { uint[] sprite_expand = new uint[16]; _BytePtr src; /* allocate the expanded sprite data */ int sprite_length = Mame.memory_region_length(Mame.REGION_GFX1); int sprite_bank_size = sprite_length / 8; sprite_expanded_data = new uint[sprite_length*2]; /* allocate the expanded background data */ int back_length = Mame.memory_region_length(Mame.REGION_GFX3); back_expanded_data = new ushort[back_length/2]; /* allocate the expanded road palette */ road_expanded_palette = new ushort[0x40]; /* determine ROM/PROM addresses */ sprite_gfxdata = Mame.memory_region(Mame.REGION_GFX1); sprite_priority = new _BytePtr(Mame.memory_region(Mame.REGION_PROMS), 0x0200); road_gfxdata = Mame.memory_region(Mame.REGION_GFX2); road_palette = new _BytePtr(Mame.memory_region(Mame.REGION_PROMS), 0x0b00); road_enable_collide = new _BytePtr(Mame.memory_region(Mame.REGION_PROMS), 0x0b40); back_gfxdata = Mame.memory_region(Mame.REGION_GFX3); back_palette = new _BytePtr(Mame.memory_region(Mame.REGION_PROMS), 0x0a00); overall_priority = new _BytePtr(Mame.memory_region(Mame.REGION_PROMS), 0x0600); collision_map = new _BytePtr(Mame.memory_region(Mame.REGION_PROMS), 0x0b60); /* compute the sprite expansion array */ for (int i = 0; i < 16; i++) { uint value = 0; if ((i & 1) != 0) value |= 0x00000001; if ((i & 2) != 0) value |= 0x00000100; if ((i & 4) != 0) value |= 0x00010000; if ((i & 8) != 0) value |= 0x01000000; /* special value for the end-of-row */ if ((i & 0x0c) == 0x04) value = 0x12345678; sprite_expand[i] = value; } /* expand the sprite ROMs */ src = new _BytePtr(sprite_gfxdata); //dst = sprite_expanded_data; for (int i = 0; i < 8; i++) { int di = 0; /* expand this bank */ for (int j = 0; j < sprite_bank_size; j++) { sprite_expanded_data[di++] = sprite_expand[src[0] >> 4]; sprite_expanded_data[di++] = sprite_expand[src[0] & 15]; src.offset++; } /* shift for the next bank */ for (int j = 0; j < 16; j++) if (sprite_expand[j] != 0x12345678) sprite_expand[j] <<= 1; } /* expand the background ROMs */ src = new _BytePtr(back_gfxdata); //bdst = back_expanded_data; int bdi = 0; for (int i = 0; i < back_length / 2; i++, src.offset++) { int bits1 = src[0]; int bits2 = src[back_length / 2]; int newbits = 0; for (int j = 0; j < 8; j++) { newbits |= ((bits1 >> (j ^ 7)) & 1) << (j * 2); newbits |= ((bits2 >> (j ^ 7)) & 1) << (j * 2 + 1); } back_expanded_data[bdi++] = (ushort)newbits; } /* expand the road palette */ src = road_palette; //bdst = road_expanded_palette; bdi = 0; for (int i = 0; i < 0x20; i++, src.offset++) road_expanded_palette[bdi++] = (ushort)(src[0] | (src[0x20] << 8)); /* set the default drawing parameters */ startx = game_clip.min_x; starty = game_clip.min_y; deltax = deltay = 1; adjusted_clip = game_clip; /* adjust our parameters for the specified orientation */ if (Mame.Machine.orientation != 0) { if ((Mame.Machine.orientation & Mame.ORIENTATION_SWAP_XY) != 0) { int temp = startx; startx = starty; starty = temp; temp = adjusted_clip.min_x; adjusted_clip.min_x = adjusted_clip.min_y; adjusted_clip.min_y = temp; temp = adjusted_clip.max_x; adjusted_clip.max_x = adjusted_clip.max_y; adjusted_clip.max_y = temp; } if ((Mame.Machine.orientation & Mame.ORIENTATION_FLIP_X) != 0) { startx = adjusted_clip.max_x; if ((Mame.Machine.orientation & Mame.ORIENTATION_SWAP_XY) == 0) deltax = -deltax; else deltay = -deltay; } if ((Mame.Machine.orientation & Mame.ORIENTATION_FLIP_Y) != 0) { starty = adjusted_clip.max_y; if ((Mame.Machine.orientation & Mame.ORIENTATION_SWAP_XY) == 0) deltay = -deltay; else deltax = -deltax; } } /* other stuff */ drew_frame = false; for (int i = 0; i < 16; i++) sprite_params[i] = new sprite_params_data(); /* return success */ return 0; }