Previous 199869 Revisions Next

r20344 Saturday 19th January, 2013 at 15:01:05 UTC by David Haywood
vboy: create flipped copies of tiles when data is written in order to simplify codepath of high frequency per-pixel tile lookups.
[src/mess/drivers]vboy.c

trunk/src/mess/drivers/vboy.c
r20343r20344
3939#define WRITE_OVR_TEMPDRAW_MAP(woffs, wdat) m_ovr_tempdraw_map[(woffs) & 0x3f] = wdat;
4040#define READ_OVR_TEMPDRAW_MAP(roffs) m_ovr_tempdraw_map[(roffs) & 0x3f];
4141
42#define READ_FONT(roffs) m_font[(roffs) & 0x3fff]
42#define READ_FONT(roffs) m_font[(roffs)&0x1ffff]
4343
44// bit of magic here, we also write pre-flipped copies of the data to extra ram we've allocated
45// to simplify the draw loop (we can just pass the flip / unused bits as the upper character bits)
46// (all TILE words are in the format of ccxy -ttt tttt tttt
47//   where 'c' = palette, 'x/y' are flips, '-' is unused(?) and 't' is your basic tile number
48
49#define WRITE_FONT(woffs) \
50   COMBINE_DATA(&m_font[woffs]); /* normal */ \
51   UINT16 dat = m_font[woffs]; \
52   m_font[((woffs) + 0x4000)] = dat;     /* normal */ \
53   m_font[((woffs) + 0x8000) ^ 7] = dat; /* flip y */ \
54   m_font[((woffs) + 0xc000) ^ 7] = dat; /* flip y */ \
55   dat = BITSWAP16(dat,1,0,3,2,5,4,7,6,9,8,11,10,13,12,15,14);  \
56   m_font[((woffs) + 0x10000)] = dat;     /* flip x */ \
57   m_font[((woffs) + 0x14000)] = dat;     /* flip x */ \
58   m_font[((woffs) + 0x18000) ^ 7] = dat; /* flip x+y */ \
59   m_font[((woffs) + 0x1c000) ^ 7] = dat; /* flip x+y */ \
60
61
62
4463/* FIXME: most if not all of these must be UINT8 */
4564struct vboy_regs_t
4665{
r20343r20344
179198   DECLARE_READ32_MEMBER(sram_r);
180199   DECLARE_WRITE32_MEMBER(sram_w);
181200
182   void put_obj(bitmap_ind16 &bitmap, const rectangle &cliprect, int x, int y, UINT16 code, bool flipx, bool flipy, UINT8 pal);
183   void fill_ovr_char(UINT16 code, bool flipx, bool flipy, UINT8 pal);
201   void put_obj(bitmap_ind16 &bitmap, const rectangle &cliprect, int x, int y, UINT16 code, UINT8 pal);
202   void fill_ovr_char(UINT16 code, UINT8 pal);
184203   INT8 get_bg_map_pixel(int num, int xpos, int ypos);
185204   void draw_bg_map(bitmap_ind16 &bitmap, const rectangle &cliprect, UINT16 param_base, int mode, int gx, int gp, int gy, int mx, int mp, int my,int h, int w,
186205                                 UINT16 x_mask, UINT16 y_mask, UINT8 ovr, bool right, int bg_map_num);
r20343r20344
214233   m_r_frame_0 = auto_alloc_array_clear(machine(), UINT8, 0x6000);
215234   m_r_frame_1 = auto_alloc_array_clear(machine(), UINT8, 0x6000);
216235
217   m_font  = auto_alloc_array_clear(machine(), UINT16, 0x8000 >> 1);
236   m_font  = auto_alloc_array_clear(machine(), UINT16, (0x8000 >> 1)*4 * 2);
218237   m_bgmap = auto_alloc_array(machine(), UINT16, 0x20000 >> 1);
219238}
220239
221void vboy_state::put_obj(bitmap_ind16 &bitmap, const rectangle &cliprect, int x, int y, UINT16 code, bool flipx, bool flipy, UINT8 pal)
240void vboy_state::put_obj(bitmap_ind16 &bitmap, const rectangle &cliprect, int x, int y, UINT16 code, UINT8 pal)
222241{
223242   UINT16 data;
224243   UINT8 yi, xi, dat, col;
225244
226245   for (yi = 0; yi < 8; yi++)
227246   {
228      if (!flipy)
229            data = READ_FONT(code * 8 + yi);
230      else
231            data = READ_FONT(code * 8 + (7-yi));
247      data = READ_FONT(code * 8 + yi);
232248
233249      for (xi = 0; xi < 8; xi++)
234250      {
235251         int res_x,res_y;
236252
237         if (!flipx)
238            dat = ((data >> (xi << 1)) & 0x03);
239         else
240            dat = ((data >> ((7-xi) << 1)) & 0x03);
253         dat = ((data >> (xi << 1)) & 0x03);
241254
242255         res_x = x + xi;
243256         res_y = y + yi;
r20343r20344
255268
256269
257270
258void vboy_state::fill_ovr_char(UINT16 code, bool flipx, bool flipy, UINT8 pal)
271void vboy_state::fill_ovr_char(UINT16 code, UINT8 pal)
259272{
260273   UINT16 data;
261274   UINT8 yi, xi, dat;
r20343r20344
263276
264277   for (yi = 0; yi < 8; yi++)
265278   {
266      if (!flipy)
267            data = READ_FONT(code * 8 + yi);
268      else
269            data = READ_FONT(code * 8 + (7-yi));
279      data = READ_FONT(code * 8 + yi);
270280
271281      for (xi = 0; xi < 8; xi++)
272282      {
273         if (!flipx)
274            dat = ((data >> (xi << 1)) & 0x03);
275         else
276            dat = ((data >> ((7-xi) << 1)) & 0x03);
277
283         dat = ((data >> (xi << 1)) & 0x03);
278284         col = (pal >> (dat*2)) & 3;
279285
280286         if(dat == 0)
r20343r20344
285291   }
286292}
287293
288INT8 vboy_state::get_bg_map_pixel(int num, int xpos, int ypos)
294inline INT8 vboy_state::get_bg_map_pixel(int num, int xpos, int ypos)
289295{
296//   g_profiler.start(PROFILER_USER1);
290297   int x, y;
291298   UINT8 stepx, stepy;
292299
293300   y = ypos >>3;
294301   x = xpos >>3;
295302
296   // Fill background map
297//   for (y = 0; y < scy; y++)
298   {
299//      for (x = 0; x < scx; x++)
300      {
301         stepx = (x & 0x1c0) >> 6;
302         stepy = ((y & 0x1c0) >> 6) * (stepx+1);
303         UINT16 val = READ_BGMAP((x & 0x3f) + (64 * (y & 0x3f)) + ((num + stepx + stepy) * 0x1000));
304         int flipx = BIT(val,13);
305         int flipy = BIT(val,12);
306         int pal = m_vip_regs.GPLT[(val >> 14) & 3];
307         int code = val & 0x7ff;
303   stepx = (x & 0x1c0) >> 6;
304   stepy = ((y & 0x1c0) >> 6) * (stepx+1);
305   UINT16 val = READ_BGMAP((x & 0x3f) + (64 * (y & 0x3f)) + ((num + stepx + stepy) * 0x1000));
306   int pal = m_vip_regs.GPLT[(val >> 14) & 3];
307   int code = val & 0x3fff;
308308
309         //put_char(x * 8, y * 8, , , , );
310         {
311            UINT16 data;
312            UINT8 yi, xi, dat;
313            int col;
309   UINT16 data;
310   UINT8 yi, xi, dat;
314311
315         //   for (yi = 0; yi < 8; yi++)
316            yi = ypos & 7;
312   yi = ypos & 7;
313   data = READ_FONT(code * 8 + yi);
314   xi = xpos & 7;
315   dat = ((data >> (xi << 1)) & 0x03);
317316
318            {
319               if (!flipy)
320                     data = READ_FONT(code * 8 + yi);
321               else
322                     data = READ_FONT(code * 8 + (7-yi));
323
324               //for (xi = 0; xi < 8; xi++)
325               xi = xpos & 7;
326               {
327                  //int res_x,res_y;
328
329                  if (!flipx)
330                     dat = ((data >> (xi << 1)) & 0x03);
331                  else
332                     dat = ((data >> ((7-xi) << 1)) & 0x03);
333
334                  //res_x = x + xi;
335                  //res_y = y + yi;
336
337                  col = (pal >> (dat*2)) & 3;
338
339                  if(dat == 0)
340                     col = -1;
341
342                  return col;
343                  //WRITE_BG_TEMPDRAW_MAP(res_y*0x1000+res_x, col);
344               }
345            }
346         }
347
348      }
317   if(dat == 0)
318   {
319      //g_profiler.stop();
320      return -1;
349321   }
322   //   g_profiler.stop();
323   return (pal >> (dat*2)) & 3;
350324}
351325
352326void vboy_state::draw_bg_map(bitmap_ind16 &bitmap, const rectangle &cliprect, UINT16 param_base, int mode, int gx, int gp, int gy, int mx, int mp, int my, int h, int w,
353327                                       UINT16 x_mask, UINT16 y_mask, UINT8 ovr, bool right, int bg_map_num)
354328{
329//   g_profiler.start(PROFILER_USER2);
355330   int x,y;
356331
357332   for(y=0;y<=h;y++)
r20343r20344
381356
382357
383358         int pix = 0;
384         if(ovr && (src_x > x_mask || src_y > y_mask || src_x < 0 || src_y < 0))
359         if(ovr)
385360         {
386            pix = READ_OVR_TEMPDRAW_MAP((src_y & 7)*8+(src_x & 7));
361            if ((src_x > x_mask || src_y > y_mask || src_x < 0 || src_y < 0))
362            {
363               g_profiler.start(PROFILER_USER3);
364               pix = READ_OVR_TEMPDRAW_MAP((src_y & 7)*8+(src_x & 7));
365               g_profiler.stop();
366            }
367            else
368            {
369               pix = get_bg_map_pixel(bg_map_num, src_x & x_mask, src_y & y_mask);
370            }
387371         }
388372         else
389373         {
r20343r20344
394378            bitmap.pix16(y1, x1) = machine().pens[pix & 3];
395379      }
396380   }
381//   g_profiler.stop();
397382}
398383
399384void vboy_state::draw_affine_map(bitmap_ind16 &bitmap, const rectangle &cliprect, UINT16 param_base, int gx, int gp, int gy, int h, int w,
400385                                          UINT16 x_mask, UINT16 y_mask, UINT8 ovr, bool right, int bg_map_num)
401386{
387//   g_profiler.start(PROFILER_USER3);
402388   int x,y;
403389
404390   for(y=0;y<=h;y++)
r20343r20344
437423               bitmap.pix16(y1, x1) = machine().pens[pix & 3];
438424      }
439425   }
426//   g_profiler.stop();
440427}
441428
442429/*
r20343r20344
481468   if (mode < 2) // Normal / HBias Mode
482469   {
483470      if(ovr)
484         fill_ovr_char(ovr_char & 0x7ff,BIT(ovr_char,13), BIT(ovr_char,12), m_vip_regs.GPLT[(ovr_char >> 14) & 3]);
471         fill_ovr_char(ovr_char & 0x3fff, m_vip_regs.GPLT[(ovr_char >> 14) & 3]);
485472
486473      if (lon && (!right))
487474      {
488         //fill_bg_map(bg_map_num, scx, scy);
489475         draw_bg_map(bitmap, cliprect, param_base, mode, gx, gp, gy, mx, mp, my, h,w, scx*8-1, scy*8-1, ovr, right, bg_map_num);
490476      }
491477
492478      if (ron && (right))
493479      {
494         //fill_bg_map(bg_map_num, scx, scy);
495480         draw_bg_map(bitmap, cliprect, param_base, mode, gx, gp, gy, mx, mp, my, h,w, scx*8-1, scy*8-1, ovr, right, bg_map_num);
496481      }
497482   }
498483   else if (mode==2) // Affine Mode
499484   {
500485      if(ovr)
501         fill_ovr_char(ovr_char & 0x7ff,BIT(ovr_char,13), BIT(ovr_char,12), m_vip_regs.GPLT[(ovr_char >> 14) & 3]);
486         fill_ovr_char(ovr_char & 0x3fff, m_vip_regs.GPLT[(ovr_char >> 14) & 3]);
502487
503488      if (lon && (!right))
504489      {
505         //fill_bg_map(bg_map_num, scx, scy);
506490         draw_affine_map(bitmap, cliprect, param_base, gx, gp, gy, h,w, scx*8-1, scy*8-1, ovr, right, bg_map_num);
507491      }
508492
509493      if (ron && (right))
510494      {
511         //fill_bg_map(bg_map_num, scx, scy);
512495         draw_affine_map(bitmap, cliprect, param_base, gx, gp, gy, h,w, scx*8-1, scy*8-1, ovr, right, bg_map_num);
513496      }
514497   }
r20343r20344
540523         UINT8 jron = (READ_OBJECTS(start_ndx+1) & 0x4000) >> 14;
541524
542525         if (!right && jlon)
543            put_obj(bitmap, cliprect, (jx-jp) & 0x1ff, jy, val & 0x7ff, BIT(val,13), BIT(val,12), m_vip_regs.JPLT[(val>>14) & 3]);
526            put_obj(bitmap, cliprect, (jx-jp) & 0x1ff, jy, val & 0x3fff, m_vip_regs.JPLT[(val>>14) & 3]);
544527
545528         if(right && jron)
546            put_obj(bitmap, cliprect, (jx+jp) & 0x1ff, jy, val & 0x7ff, BIT(val,13), BIT(val,12), m_vip_regs.JPLT[(val>>14) & 3]);
529            put_obj(bitmap, cliprect, (jx+jp) & 0x1ff, jy, val & 0x3fff, m_vip_regs.JPLT[(val>>14) & 3]);
547530
548531         i --;
549532         i &= 0x3ff;
r20343r20344
10441027
10451028WRITE16_MEMBER( vboy_state::vboy_font0_w )
10461029{
1047   COMBINE_DATA(&m_font[offset]);
1030   WRITE_FONT(offset);
10481031}
10491032
10501033WRITE16_MEMBER( vboy_state::vboy_font1_w )
10511034{
1052   COMBINE_DATA(&m_font[offset+0x1000]);
1035   WRITE_FONT(offset+0x1000);
10531036}
10541037
10551038WRITE16_MEMBER( vboy_state::vboy_font2_w )
10561039{
1057   COMBINE_DATA(&m_font[offset+0x2000]);
1040   WRITE_FONT(offset+0x2000);
10581041}
10591042
10601043WRITE16_MEMBER( vboy_state::vboy_font3_w )
10611044{
1062   COMBINE_DATA(&m_font[offset+0x3000]);
1045   WRITE_FONT(offset+0x3000);
10631046}
10641047
10651048READ16_MEMBER( vboy_state::vboy_font0_r )

Previous 199869 Revisions Next


© 1997-2024 The MAME Team