Previous 199869 Revisions Next

r33381 Saturday 15th November, 2014 at 09:22:56 UTC by Alex W. Jackson
goldngam.c, popobear.c: fix unsafe casts pointed out by Aaron comments; the other driver with such comments, crystal.c, is a lost cause (nw)
[src/mame/drivers]goldngam.c popobear.c

trunk/src/mame/drivers/goldngam.c
r241892r241893
264264
265265UINT32 goldngam_state::screen_update_goldngam(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
266266{
267   int x, y;
268
269   // ERROR: This cast is NOT endian-safe without the use of BYTE/WORD/DWORD_XOR_* macros!
270   UINT8 *tmp = reinterpret_cast<UINT8 *>(m_videoram.target());
271267   int index = 0;
272268
273   for(y = 0; y < 512; ++y)
269   for(int y = 0; y < 512; ++y)
274270   {
275      for(x = 0; x < 384; ++x)
271      for(int x = 0; x < 384; x += 2)
276272      {
277         bitmap.pix16(y, x) = tmp[index ^ 1]; /* swapped bytes in 16 bit word */
273         UINT16 word = m_videoram[index];
274         bitmap.pix16(y, x) = word >> 8;
275         bitmap.pix16(y, x+1) = word & 0xff;
278276         ++index;
279277      }
280278   }
trunk/src/mame/drivers/popobear.c
r241892r241893
8989      : driver_device(mconfig, type, tag),
9090      m_maincpu(*this,"maincpu"),
9191      m_spr(*this, "spr"),
92      m_vram(*this, "vram"),
9293      m_vregs(*this, "vregs"),
9394      m_gfxdecode(*this, "gfxdecode"),
9495      m_palette(*this, "palette")
r241892r241893
9899      tilemap_base[1] = 0xf4000;
99100      tilemap_base[2] = 0xf8000;
100101      tilemap_base[3] = 0xfc000;
101
102      tilemap_size[0] = 0x04000;
103      tilemap_size[1] = 0x04000;
104      tilemap_size[2] = 0x04000;
105      tilemap_size[3] = 0x04000;
106102   }
107103
108104   required_device<cpu_device> m_maincpu;
109105   required_shared_ptr<UINT16> m_spr;
106   required_shared_ptr<UINT16> m_vram;
110107   required_shared_ptr<UINT16> m_vregs;
111108   optional_device<gfxdecode_device> m_gfxdecode;
112109   required_device<palette_device> m_palette;
113110
114   UINT16* m_vram;
115   UINT16* m_vram_rearranged;
111   dynamic_array<UINT16> m_vram_rearranged;
116112
117113   int tilemap_base[4];
118   int tilemap_size[4];
119114
120115   DECLARE_READ8_MEMBER(popo_620000_r);
121116   DECLARE_WRITE8_MEMBER(popobear_irq_ack_w);
r241892r241893
124119   TIMER_DEVICE_CALLBACK_MEMBER(popobear_irq);
125120   void draw_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect);
126121
127   int m_gfx_index;
128122   tilemap_t    *m_bg_tilemap[4];
129123   TILE_GET_INFO_MEMBER(get_popobear_bg0_tile_info);
130124   TILE_GET_INFO_MEMBER(get_popobear_bg1_tile_info);
r241892r241893
149143
150144
151145      COMBINE_DATA(&m_vram_rearranged[swapped_offset]);
152      m_gfxdecode->gfx(m_gfx_index)->mark_dirty((swapped_offset)/32);
146      m_gfxdecode->gfx(0)->mark_dirty((swapped_offset)/32);
153147
154148      // unfortunately tilemaps and tilegfx share the same ram so we're always dirty if we write to RAM
155149      m_bg_tilemap[0]->mark_all_dirty();
r241892r241893
158152      m_bg_tilemap[3]->mark_all_dirty();
159153
160154   }
161   DECLARE_READ16_MEMBER(popo_vram_r) { return m_vram[offset]; }
162155
163156};
164157
r241892r241893
166159static const gfx_layout popobear_char_layout =
167160{
168161   8,8,
169   0x4000,
162   RGN_FRAC(1,1),
170163   8,
171164   { 0,1,2,3,4,5,6,7 },
172165   { STEP8(0, 8) },
r241892r241893
174167   8*64
175168};
176169
170GFXDECODE_START(popobear)
171   GFXDECODE_RAM( "vram", 0, popobear_char_layout, 0, 1 )
172GFXDECODE_END
177173
178174TILE_GET_INFO_MEMBER(popobear_state::get_popobear_bg0_tile_info)
179175{
r241892r241893
212208
213209void popobear_state::video_start()
214210{
215   /* find first empty slot to decode gfx */
216   for (m_gfx_index = 0; m_gfx_index < MAX_GFX_ELEMENTS; m_gfx_index++)
217      if (m_gfxdecode->gfx(m_gfx_index) == 0)
218         break;
211   m_vram_rearranged.resize(0x100000 / 2);
219212
220   assert(m_gfx_index != MAX_GFX_ELEMENTS);
213   m_gfxdecode->gfx(0)->set_source(reinterpret_cast<UINT8 *>(&m_vram_rearranged[0]));
221214
222   m_vram = auto_alloc_array_clear(machine(), UINT16, 0x100000/2);
223   m_vram_rearranged = auto_alloc_array_clear(machine(), UINT16, 0x100000/2);
224
225
226   /* create the char set (gfx will then be updated dynamically from RAM) */
227   m_gfxdecode->set_gfx(m_gfx_index, global_alloc(gfx_element(m_palette, popobear_char_layout, (UINT8 *)m_vram_rearranged, NATIVE_ENDIAN_VALUE_LE_BE(8,0), m_palette->entries() / 16, 0)));
228
229215   m_bg_tilemap[0] = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(popobear_state::get_popobear_bg0_tile_info),this), TILEMAP_SCAN_ROWS, 8, 8, 128, 64);
230216   m_bg_tilemap[1] = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(popobear_state::get_popobear_bg1_tile_info),this), TILEMAP_SCAN_ROWS, 8, 8, 128, 64);
231217   m_bg_tilemap[2] = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(popobear_state::get_popobear_bg2_tile_info),this), TILEMAP_SCAN_ROWS, 8, 8, 128, 64);
r241892r241893
243229
244230void popobear_state::draw_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect)
245231{
246   // ERROR: This cast is NOT endian-safe without the use of BYTE/WORD/DWORD_XOR_* macros!
247232   UINT8* vram = reinterpret_cast<UINT8 *>(m_spr.target());
248233   int i;
249234
r241892r241893
264249      /* 0x*29 = 32 x 32 */
265250      for(i = 0x800-8;i >= 0; i-=8)
266251      {
267         int y = vram[i+0x7f800+2]|(vram[i+0x7f800+3]<<8);
268         int x = vram[i+0x7f800+4]|(vram[i+0x7f800+5]<<8);
269         int spr_num = vram[i+0x7f800+6]|(vram[i+0x7f800+7]<<8);
270         int param = vram[i+0x7f800+0]|(vram[i+0x7f800+1]<<8);
252         UINT16 *sprdata = &m_spr[(0x7f800 + i) / 2];
271253
254         int param = sprdata[0];
272255         int pri = (param & 0x0f00)>>8;
273256
274257         // we do this because it's sprite<->sprite priority,
275258         if (pri!=drawpri)
276259            continue;
277260
261         int y = sprdata[1];
262         int x = sprdata[2];
263         int spr_num = sprdata[3];
264
278265         int width = 8 << ((param & 0x30)>>4);
279266         int height = width; // sprites are always square?
280267
r241892r241893
327314
328315            for(int xi=0;xi<width;xi++)
329316            {
330               UINT8 pix = (vram[spr_num^1] & 0xff);
317               UINT8 pix = vram[BYTE_XOR_BE(spr_num)];
331318               int x_draw = (x_dir) ? x+((width-1) - xi) : x+xi;
332319
333320               if(cliprect.contains(x_draw, y_draw))
r241892r241893
479466   AM_RANGE(0x000000, 0x03ffff) AM_ROM
480467   AM_RANGE(0x210000, 0x21ffff) AM_RAM
481468   AM_RANGE(0x280000, 0x2fffff) AM_RAM AM_SHARE("spr") // unknown boundaries, 0x2ff800 contains a sprite list, lower area = sprite gfx
482   AM_RANGE(0x300000, 0x3fffff) AM_READWRITE( popo_vram_r, popo_vram_w ) // tile definitions + tilemaps
469   AM_RANGE(0x300000, 0x3fffff) AM_RAM_WRITE( popo_vram_w ) AM_SHARE("vram") // tile definitions + tilemaps
483470
484471
485472   /* Most if not all of these are vregs */
r241892r241893
660647
661648   MCFG_SPEAKER_STANDARD_MONO("mono")
662649
663   MCFG_GFXDECODE_ADD("gfxdecode", "palette", empty)
650   MCFG_GFXDECODE_ADD("gfxdecode", "palette", popobear)
664651
665652   MCFG_SOUND_ADD("ymsnd", YM2413, XTAL_42MHz/16)  // XTAL CORRECT, DIVISOR GUESSED
666653   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)


Previous 199869 Revisions Next


© 1997-2024 The MAME Team