Previous 199869 Revisions Next

r25429 Thursday 26th September, 2013 at 01:29:17 UTC by David Haywood
de-duplicate some code
[src/mame/drivers]unico.c
[src/mame/includes]unico.h
[src/mame/video]unico.c

trunk/src/mame/video/unico.c
r25428r25429
9696   SET_TILE_INFO_MEMBER(1, code, attr & 0x1f, TILE_FLIPYX( attr >> 5 ));
9797}
9898
99TILE_GET_INFO_MEMBER(unico_state::get_tile_info32)
100{
101   UINT32 *vram = (UINT32 *)tilemap.user_data();
102   UINT16 code = vram[tile_index] >> 16;
103   UINT16 attr = vram[tile_index] & 0xff;
104   SET_TILE_INFO_MEMBER(1, code, attr & 0x1f, TILE_FLIPYX( attr >> 5 ));
105}
99READ16_MEMBER(unico_state::unico_vram_r) { return m_vram[offset]; }
106100
107101WRITE16_MEMBER(unico_state::unico_vram_w)
108102{
r25428r25429
112106   m_tilemap[tile]->mark_tile_dirty((offset & 0x1fff)/2);
113107}
114108
115WRITE32_MEMBER(unico_state::unico_vram32_w)
116{
117   UINT32 *vram = m_vram32;
118   int tile = ((offset / 0x1000) + 1) % 3;
119   COMBINE_DATA(&vram[offset]);
120   m_tilemap[tile]->mark_tile_dirty((offset & 0xfff));
121}
122109
110READ16_MEMBER(unico_state::unico_scroll_r) { return m_scroll[offset]; }
111WRITE16_MEMBER(unico_state::unico_scroll_w) { COMBINE_DATA(&m_scroll[offset]); }
112READ16_MEMBER(unico_state::unico_spriteram_r) { return m_spriteram[offset]; }
113WRITE16_MEMBER(unico_state::unico_spriteram_w)  { COMBINE_DATA(&m_spriteram[offset]); }
123114
124115
116
125117/***************************************************************************
126118
127119
r25428r25429
133125
134126VIDEO_START_MEMBER(unico_state,unico)
135127{
128   m_vram   = auto_alloc_array_clear(machine(), UINT16, 0xc000 / 2);
129   m_scroll = auto_alloc_array_clear(machine(), UINT16, 0x18 / 2);
130   m_spriteram = auto_alloc_array_clear(machine(), UINT16, 0x800 / 2);
131
132   save_pointer(NAME(m_vram), 0xc000/2);
133   save_pointer(NAME(m_scroll), 0x18/2);
134   save_pointer(NAME(m_spriteram), 0x800/2);
135
136136   m_tilemap[0] = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(unico_state::get_tile_info),this),TILEMAP_SCAN_ROWS,
137137                           16,16,  0x40, 0x40);
138138
r25428r25429
162162   m_tilemap[2]->set_transparent_pen(0x00);
163163}
164164
165VIDEO_START_MEMBER(unico_state,zeropnt2)
166{
167   m_tilemap[0] = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(unico_state::get_tile_info32),this),TILEMAP_SCAN_ROWS,
168                           16,16,  0x40, 0x40);
169165
170   m_tilemap[1] = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(unico_state::get_tile_info32),this),TILEMAP_SCAN_ROWS,
171                           16,16,  0x40, 0x40);
172166
173   m_tilemap[2] = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(unico_state::get_tile_info32),this),TILEMAP_SCAN_ROWS,
174                           16,16,  0x40, 0x40);
175167
176   m_tilemap[0]->set_user_data(&m_vram32[0x8000/4]);
177   m_tilemap[1]->set_user_data(&m_vram32[0x0000/4]);
178   m_tilemap[2]->set_user_data(&m_vram32[0x4000/4]);
179
180   m_sprites_scrolldx = -0x3f;
181   m_sprites_scrolldy = -0x0e;
182
183   m_tilemap[0]->set_scrolldx(-0x32,0);
184   m_tilemap[1]->set_scrolldx(-0x30,0);
185   m_tilemap[2]->set_scrolldx(-0x2e,0);
186
187   m_tilemap[0]->set_scrolldy(-0x0f,0);
188   m_tilemap[1]->set_scrolldy(-0x0f,0);
189   m_tilemap[2]->set_scrolldy(-0x0f,0);
190
191   m_tilemap[0]->set_transparent_pen(0x00);
192   m_tilemap[1]->set_transparent_pen(0x00);
193   m_tilemap[2]->set_transparent_pen(0x00);
194}
195
196
197
198168/***************************************************************************
199169
200170                                Sprites Drawing
r25428r25429
223193   int offs;
224194
225195   /* Draw them backwards, for pdrawgfx */
226   for ( offs = (m_spriteram.bytes()-8)/2; offs >= 0 ; offs -= 8/2 )
196   for ( offs = (0x800-8)/2; offs >= 0 ; offs -= 8/2 )
227197   {
228198      int x, startx, endx, incx;
229199
r25428r25429
271241   }
272242}
273243
274void unico_state::zeropnt2_draw_sprites(screen_device &screen, bitmap_ind16 &bitmap,const rectangle &cliprect)
275{
276   UINT32 *spriteram32 = reinterpret_cast<UINT32 *>(m_spriteram.target());
277   int offs;
278244
279   /* Draw them backwards, for pdrawgfx */
280   for ( offs = (m_spriteram.bytes()-8)/4; offs >= 0 ; offs -= 8/4 )
281   {
282      int x, startx, endx, incx;
283
284      int sx          =   spriteram32[ offs + 0 ] >> 16;
285      int sy          =   spriteram32[ offs + 0 ] & 0xffff;
286      int code        =   spriteram32[ offs + 1 ] >> 16;
287      int attr        =   spriteram32[ offs + 1 ] & 0xffff;
288
289      int flipx       =   attr & 0x020;
290      int flipy       =   attr & 0x040;   // not sure
291
292      int dimx        =   ((attr >> 8) & 0xf) + 1;
293
294      int priority    =   ((attr >> 12) & 0x3);
295      int pri_mask;
296
297      switch( priority )
298      {
299         case 0:     pri_mask = 0xfe;    break;  // below all
300         case 1:     pri_mask = 0xf0;    break;  // above layer 0
301         case 2:     pri_mask = 0xfc;    break;  // above layer 1
302         default:
303         case 3:     pri_mask = 0x00;            // above all
304      }
305
306      sx  +=  m_sprites_scrolldx;
307      sy  +=  m_sprites_scrolldy;
308
309      sx  =   (sx & 0x1ff) - (sx & 0x200);
310      sy  =   (sy & 0x1ff) - (sy & 0x200);
311
312      if (flipx)  {   startx = sx+(dimx-1)*16;    endx = sx-16;       incx = -16; }
313      else        {   startx = sx;                endx = sx+dimx*16;  incx = +16; }
314
315      for (x = startx ; x != endx ; x += incx)
316      {
317         pdrawgfx_transpen(  bitmap, cliprect, machine().gfx[0],
318                  code++,
319                  attr & 0x1f,
320                  flipx, flipy,
321                  x, sy,
322                  screen.priority(),
323                  pri_mask,0x00   );
324      }
325   }
326}
327
328
329
330245/***************************************************************************
331246
332247
r25428r25429
373288
374289   return 0;
375290}
376
377UINT32 unico_state::screen_update_zeropnt2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
378{
379   int layers_ctrl = -1;
380
381   m_tilemap[0]->set_scrollx(0, m_scroll32[0] >> 16);
382   m_tilemap[0]->set_scrolly(0, m_scroll32[0] & 0xffff);
383
384   m_tilemap[1]->set_scrollx(0, m_scroll32[2] & 0xffff);
385   m_tilemap[1]->set_scrolly(0, m_scroll32[5] >> 16);
386
387   m_tilemap[2]->set_scrollx(0, m_scroll32[2] >> 16);
388   m_tilemap[2]->set_scrolly(0, m_scroll32[1] >> 16);
389
390#ifdef MAME_DEBUG
391if ( machine().input().code_pressed(KEYCODE_Z) || machine().input().code_pressed(KEYCODE_X) )
392{
393   int msk = 0;
394   if (machine().input().code_pressed(KEYCODE_Q))  msk |= 1;
395   if (machine().input().code_pressed(KEYCODE_W))  msk |= 2;
396   if (machine().input().code_pressed(KEYCODE_E))  msk |= 4;
397   if (machine().input().code_pressed(KEYCODE_A))  msk |= 8;
398   if (msk != 0) layers_ctrl &= msk;
399}
400#endif
401
402   /* The background color is the first of the last palette */
403   bitmap.fill(0x1f00, cliprect);
404   screen.priority().fill(0, cliprect);
405
406   if (layers_ctrl & 1)    m_tilemap[0]->draw(screen, bitmap, cliprect, 0,1);
407   if (layers_ctrl & 2)    m_tilemap[1]->draw(screen, bitmap, cliprect, 0,2);
408   if (layers_ctrl & 4)    m_tilemap[2]->draw(screen, bitmap, cliprect, 0,4);
409
410   /* Sprites are drawn last, using pdrawgfx */
411   if (layers_ctrl & 8)    zeropnt2_draw_sprites(screen,bitmap,cliprect);
412
413   return 0;
414}
trunk/src/mame/includes/unico.h
r25428r25429
66public:
77   unico_state(const machine_config &mconfig, device_type type, const char *tag)
88      : driver_device(mconfig, type, tag),
9      m_vram(*this, "vram"),
10      m_scroll(*this, "scroll"),
11      m_vram32(*this, "vram32"),
12      m_scroll32(*this, "scroll32"),
13      m_spriteram(*this, "spriteram", 0),
149      m_maincpu(*this, "maincpu"),
1510      m_oki(*this, "oki"),
1611      m_eeprom(*this, "eeprom") { }
1712
18   optional_shared_ptr<UINT16> m_vram;
19   optional_shared_ptr<UINT16> m_scroll;
20   optional_shared_ptr<UINT32> m_vram32;
21   optional_shared_ptr<UINT32> m_scroll32;
13   UINT16* m_vram;
14   UINT16* m_scroll;
2215   tilemap_t *m_tilemap[3];
2316   int m_sprites_scrolldx;
2417   int m_sprites_scrolldy;
25   optional_shared_ptr<UINT16> m_spriteram;
18   UINT16* m_spriteram;
2619   DECLARE_WRITE16_MEMBER(zeropnt_sound_bank_w);
2720   DECLARE_READ16_MEMBER(unico_gunx_0_msb_r);
2821   DECLARE_READ16_MEMBER(unico_guny_0_msb_r);
r25428r25429
3629   DECLARE_WRITE32_MEMBER(zeropnt2_leds_w);
3730   DECLARE_WRITE16_MEMBER(unico_palette_w);
3831   DECLARE_WRITE32_MEMBER(unico_palette32_w);
32   DECLARE_READ16_MEMBER(unico_vram_r);
3933   DECLARE_WRITE16_MEMBER(unico_vram_w);
40   DECLARE_WRITE32_MEMBER(unico_vram32_w);
34   DECLARE_READ16_MEMBER(unico_scroll_r);
35   DECLARE_WRITE16_MEMBER(unico_scroll_w);
36   DECLARE_READ16_MEMBER(unico_spriteram_r);
37   DECLARE_WRITE16_MEMBER(unico_spriteram_w);
38
4139   DECLARE_WRITE16_MEMBER(burglarx_sound_bank_w);
4240   DECLARE_WRITE32_MEMBER(zeropnt2_eeprom_w);
4341   TILE_GET_INFO_MEMBER(get_tile_info);
44   TILE_GET_INFO_MEMBER(get_tile_info32);
4542   DECLARE_MACHINE_RESET(unico);
4643   DECLARE_VIDEO_START(unico);
4744   DECLARE_MACHINE_RESET(zeropt);
48   DECLARE_VIDEO_START(zeropnt2);
4945   UINT32 screen_update_unico(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
50   UINT32 screen_update_zeropnt2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
5146   void unico_draw_sprites(screen_device &screen, bitmap_ind16 &bitmap,const rectangle &cliprect);
52   void zeropnt2_draw_sprites(screen_device &screen, bitmap_ind16 &bitmap,const rectangle &cliprect);
5347   required_device<cpu_device> m_maincpu;
5448   optional_device<okim6295_device> m_oki;
5549   optional_device<eeprom_serial_93cxx_device> m_eeprom;
trunk/src/mame/drivers/unico.c
r25428r25429
6565   AM_RANGE(0x80001a, 0x80001b) AM_READ_PORT("DSW1")
6666   AM_RANGE(0x80001c, 0x80001d) AM_READ_PORT("DSW2")
6767   AM_RANGE(0x800030, 0x800031) AM_WRITENOP                                                // ? 0
68   AM_RANGE(0x80010c, 0x800121) AM_WRITEONLY AM_SHARE("scroll")                // Scroll
68   AM_RANGE(0x80010c, 0x800121) AM_READWRITE( unico_scroll_r, unico_scroll_w )               // Scroll
6969   AM_RANGE(0x800188, 0x800189) AM_DEVREADWRITE8("oki", okim6295_device, read, write, 0x00ff)  // Sound
7070   AM_RANGE(0x80018a, 0x80018b) AM_DEVWRITE8("ymsnd", ym3812_device, write_port_w, 0xff00)
7171   AM_RANGE(0x80018c, 0x80018d) AM_DEVREADWRITE8("ymsnd", ym3812_device, status_port_r, control_port_w, 0xff00)
7272   AM_RANGE(0x80018e, 0x80018f) AM_WRITE(burglarx_sound_bank_w)                    //
7373   AM_RANGE(0x8001e0, 0x8001e1) AM_WRITENOP                                                // IRQ Ack
74   AM_RANGE(0x904000, 0x90ffff) AM_RAM_WRITE(unico_vram_w) AM_SHARE("vram")        // Layers 1, 2, 0
74   AM_RANGE(0x904000, 0x90ffff) AM_READWRITE( unico_vram_r, unico_vram_w )         // Layers 1, 2, 0
7575   AM_RANGE(0x920000, 0x923fff) AM_RAM                                                     // ? 0
76   AM_RANGE(0x930000, 0x9307ff) AM_RAM AM_SHARE("spriteram")   // Sprites
76   AM_RANGE(0x930000, 0x9307ff) AM_READWRITE( unico_spriteram_r, unico_spriteram_w )   // Sprites
7777   AM_RANGE(0x940000, 0x947fff) AM_RAM_WRITE(unico_palette_w) AM_SHARE("paletteram")   // Palette
7878ADDRESS_MAP_END
7979
r25428r25429
149149   AM_RANGE(0x800018, 0x800019) AM_READ_PORT("INPUTS")
150150   AM_RANGE(0x80001a, 0x80001b) AM_READ_PORT("DSW1")
151151   AM_RANGE(0x80001c, 0x80001d) AM_READ_PORT("DSW2")
152   AM_RANGE(0x80010c, 0x800121) AM_WRITEONLY AM_SHARE("scroll")    // Scroll
152   AM_RANGE(0x80010c, 0x800121) AM_READWRITE( unico_scroll_r, unico_scroll_w )   // Scroll
153153   AM_RANGE(0x800170, 0x800171) AM_READ(unico_guny_0_msb_r         )   // Light Guns
154154   AM_RANGE(0x800174, 0x800175) AM_READ(unico_gunx_0_msb_r         )   //
155155   AM_RANGE(0x800178, 0x800179) AM_READ(unico_guny_1_msb_r         )   //
r25428r25429
159159   AM_RANGE(0x80018c, 0x80018d) AM_DEVREADWRITE8("ymsnd", ym3812_device, status_port_r, control_port_w, 0xff00)
160160   AM_RANGE(0x80018e, 0x80018f) AM_WRITE(zeropnt_sound_bank_w              )   //
161161   AM_RANGE(0x8001e0, 0x8001e1) AM_WRITEONLY   // ? IRQ Ack
162   AM_RANGE(0x904000, 0x90ffff) AM_RAM_WRITE(unico_vram_w) AM_SHARE("vram")    // Layers 1, 2, 0
162   AM_RANGE(0x904000, 0x90ffff) AM_READWRITE( unico_vram_r, unico_vram_w )     // Layers 1, 2, 0
163163   AM_RANGE(0x920000, 0x923fff) AM_RAM // ? 0
164   AM_RANGE(0x930000, 0x9307ff) AM_RAM AM_SHARE("spriteram")   // Sprites
164   AM_RANGE(0x930000, 0x9307ff) AM_READWRITE( unico_spriteram_r, unico_spriteram_w )   // Sprites
165165   AM_RANGE(0x940000, 0x947fff) AM_RAM_WRITE(unico_palette_w) AM_SHARE("paletteram")   // Palette
166166ADDRESS_MAP_END
167167
r25428r25429
222222   AM_RANGE(0x800030, 0x800033) AM_DEVREADWRITE8("oki2", okim6295_device, read, write, 0x00ff0000  )   //
223223   AM_RANGE(0x800034, 0x800037) AM_WRITE(zeropnt2_sound_bank_w             )   //
224224   AM_RANGE(0x800038, 0x80003b) AM_WRITE(zeropnt2_leds_w                   )   // ?
225   AM_RANGE(0x80010c, 0x800123) AM_WRITEONLY AM_SHARE("scroll32")  // Scroll
225   AM_RANGE(0x80010c, 0x800123) AM_READWRITE16( unico_scroll_r, unico_scroll_w, 0xffffffff )   // Scroll
226226   AM_RANGE(0x800140, 0x800143) AM_READ(zeropnt2_guny_0_msb_r          )   // Light Guns
227227   AM_RANGE(0x800144, 0x800147) AM_READ(zeropnt2_gunx_0_msb_r          )   //
228228   AM_RANGE(0x800148, 0x80014b) AM_READ(zeropnt2_guny_1_msb_r          )   //
r25428r25429
232232   AM_RANGE(0x80015c, 0x80015f) AM_READ_PORT("BUTTONS")
233233   AM_RANGE(0x8001e0, 0x8001e3) AM_WRITENOP                                    // ? IRQ Ack
234234   AM_RANGE(0x8001f0, 0x8001f3) AM_WRITE(zeropnt2_eeprom_w)                    // EEPROM
235   AM_RANGE(0x904000, 0x90ffff) AM_RAM_WRITE(unico_vram32_w) AM_SHARE("vram32")    // Layers 1, 2, 0
235   AM_RANGE(0x904000, 0x90ffff) AM_READWRITE16( unico_vram_r, unico_vram_w, 0xffffffff )     // Layers 1, 2, 0
236236   AM_RANGE(0x920000, 0x923fff) AM_RAM                                         // ? 0
237   AM_RANGE(0x930000, 0x9307ff) AM_RAM AM_SHARE("spriteram")   // Sprites
237   AM_RANGE(0x930000, 0x9307ff) AM_READWRITE16( unico_spriteram_r, unico_spriteram_w, 0xffffffff )   // Sprites
238238   AM_RANGE(0x940000, 0x947fff) AM_RAM_WRITE(unico_palette32_w) AM_SHARE("paletteram") // Palette
239239   AM_RANGE(0xfe0000, 0xffffff) AM_RAM                                         // RAM
240240ADDRESS_MAP_END
r25428r25429
673673   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
674674   MCFG_SCREEN_SIZE(0x180, 0xe0)
675675   MCFG_SCREEN_VISIBLE_AREA(0, 0x180-1, 0, 0xe0-1)
676   MCFG_SCREEN_UPDATE_DRIVER(unico_state, screen_update_zeropnt2)
676   MCFG_SCREEN_UPDATE_DRIVER(unico_state, screen_update_unico)
677677
678678   MCFG_GFXDECODE(unico)
679679   MCFG_PALETTE_LENGTH(8192)
680680
681   MCFG_VIDEO_START_OVERRIDE(unico_state,zeropnt2)
681   MCFG_VIDEO_START_OVERRIDE(unico_state,unico)
682682
683683   /* sound hardware */
684684   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")

Previous 199869 Revisions Next


© 1997-2024 The MAME Team