Previous 199869 Revisions Next

r21027 Wednesday 13th February, 2013 at 13:19:20 UTC by Miodrag Milanović
Modernization of drivers part 22 (no whatsnew)
[src/mame/drivers]aristmk4.c atarisy4.c bfcobra.c bfm_sc1.c bfm_sc2.c bfmsys85.c calchase.c chanbara.c cntsteer.c cobra.c cops.c deco156.c deco_ld.c diverboy.c egghunt.c enigma2.c firebeat.c firefox.c galpani3.c hornet.c igs011.c igs017.c igs_m027.c konamigq.c konamigv.c konamim2.c m63.c maxaflex.c mediagx.c mgolf.c mpu3.c mpu4vid.c mwarr.c olibochu.c pcxt.c pengadvb.c popobear.c queen.c royalmah.c sandscrp.c sangho.c sbrkout.c sfkick.c silvmil.c

trunk/src/mame/drivers/igs_m027.c
r21026r21027
6969   UINT32 screen_update_igs_majhong(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
7070   UINT32 screen_update_fearless(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
7171   INTERRUPT_GEN_MEMBER(igs_majhong_interrupt);
72   void sdwx_gfx_decrypt();
73   void pgm_create_dummy_internal_arm_region();
7274};
7375
7476
r21026r21027
278280
279281
280282
281static void sdwx_gfx_decrypt(running_machine &machine)
283void igs_m027_state::sdwx_gfx_decrypt()
282284{
283285   int i;
284286   unsigned rom_size = 0x80000;
285   UINT8 *src = (UINT8 *) (machine.root_device().memregion("gfx1")->base());
286   UINT8 *result_data = auto_alloc_array(machine, UINT8, rom_size);
287   UINT8 *src = (UINT8 *) (machine().root_device().memregion("gfx1")->base());
288   UINT8 *result_data = auto_alloc_array(machine(), UINT8, rom_size);
287289
288290   for (i=0; i<rom_size; i++)
289291      result_data[i] = src[BITSWAP24(i, 23,22,21,20,19,18,17,16,15,14,13,12,11,8,7,6,10,9,5,4,3,2,1,0)];
r21026r21027
295297      memcpy(src+i+0x100,result_data+i+0x080,0x80);
296298      memcpy(src+i+0x180,result_data+i+0x180,0x80);
297299   }
298   auto_free(machine, result_data);
300   auto_free(machine(), result_data);
299301}
300302
301303/***************************************************************************
r21026r21027
840842
841843
842844
843static void pgm_create_dummy_internal_arm_region(running_machine &machine)
845void igs_m027_state::pgm_create_dummy_internal_arm_region()
844846{
845   UINT16 *temp16 = (UINT16 *)machine.root_device().memregion("maincpu")->base();
847   UINT16 *temp16 = (UINT16 *)machine().root_device().memregion("maincpu")->base();
846848
847849   // fill with RX 14
848850   int i;
r21026r21027
875877DRIVER_INIT_MEMBER(igs_m027_state,sdwx)
876878{
877879   sdwx_decrypt(machine());
878   sdwx_gfx_decrypt(machine());
879   pgm_create_dummy_internal_arm_region(machine());
880   sdwx_gfx_decrypt();
881   pgm_create_dummy_internal_arm_region();
880882}
881883
882884DRIVER_INIT_MEMBER(igs_m027_state,klxyj)
883885{
884886   klxyj_decrypt(machine());
885887   //sdwx_gfx_decrypt(machine());
886   pgm_create_dummy_internal_arm_region(machine());
888   pgm_create_dummy_internal_arm_region();
887889}
888890
889891DRIVER_INIT_MEMBER(igs_m027_state,chessc2)
890892{
891893   chessc2_decrypt(machine());
892894   //sdwx_gfx_decrypt(machine());
893   pgm_create_dummy_internal_arm_region(machine());
895   pgm_create_dummy_internal_arm_region();
894896}
895897
896898DRIVER_INIT_MEMBER(igs_m027_state,hauntedh)
897899{
898900   hauntedh_decrypt(machine());
899901   //sdwx_gfx_decrypt(machine());
900   pgm_create_dummy_internal_arm_region(machine());
902   pgm_create_dummy_internal_arm_region();
901903}
902904
903905DRIVER_INIT_MEMBER(igs_m027_state,fearless)
904906{
905907   fearless_decrypt(machine());
906908   //sdwx_gfx_decrypt(machine());
907   pgm_create_dummy_internal_arm_region(machine());
909   pgm_create_dummy_internal_arm_region();
908910}
909911
910912
r21026r21027
912914{
913915   lhzb4_decrypt(machine());
914916   //sdwx_gfx_decrypt(machine());
915   pgm_create_dummy_internal_arm_region(machine());
917   pgm_create_dummy_internal_arm_region();
916918}
917919
918920DRIVER_INIT_MEMBER(igs_m027_state,mgfx)
919921{
920922   mgfx_decrypt(machine());
921923   //sdwx_gfx_decrypt(machine());
922   pgm_create_dummy_internal_arm_region(machine());
924   pgm_create_dummy_internal_arm_region();
923925}
924926
925927DRIVER_INIT_MEMBER(igs_m027_state,lhzb3)
926928{
927929   lhzb3_decrypt(machine());
928930   //sdwx_gfx_decrypt(machine());
929   pgm_create_dummy_internal_arm_region(machine());
931   pgm_create_dummy_internal_arm_region();
930932}
931933
932934DRIVER_INIT_MEMBER(igs_m027_state,sddz)
933935{
934936   sddz_decrypt(machine());
935937   //sdwx_gfx_decrypt(machine());
936   pgm_create_dummy_internal_arm_region(machine());
938   pgm_create_dummy_internal_arm_region();
937939}
938940
939941DRIVER_INIT_MEMBER(igs_m027_state,gonefsh2)
940942{
941943   gonefsh2_decrypt(machine());
942944   //sdwx_gfx_decrypt(machine());
943   pgm_create_dummy_internal_arm_region(machine());
945   pgm_create_dummy_internal_arm_region();
944946}
945947
946948DRIVER_INIT_MEMBER(igs_m027_state,bigd2)
947949{
948950   big2_decrypt(machine());
949951   //sdwx_gfx_decrypt(machine());
950   pgm_create_dummy_internal_arm_region(machine());
952   pgm_create_dummy_internal_arm_region();
951953}
952954
953955/***************************************************************************
trunk/src/mame/drivers/aristmk4.c
r21026r21027
326326   TIMER_CALLBACK_MEMBER(coin_input_reset);
327327   TIMER_CALLBACK_MEMBER(hopper_reset);
328328   TIMER_DEVICE_CALLBACK_MEMBER(aristmk4_pf);
329   inline void uBackgroundColour();
329330};
330331
331332/* Partial Cashcade protocol */
r21026r21027
340341   }
341342}
342343
343INLINE void uBackgroundColour(running_machine &machine)
344void aristmk4_state::uBackgroundColour()
344345{
345   aristmk4_state *state = machine.driver_data<aristmk4_state>();
346346
347347   /* SW7 can be set when the main door is open, this allows the colours for the background
348348   to be adjusted whilst the machine is running.
r21026r21027
350350   There are 4 possible combinations for colour select via SW7, colours vary based on software installed.
351351   */
352352
353   switch(state->ioport("SW7")->read())
353   switch(ioport("SW7")->read())
354354   {
355355   case 0x00:
356356      // restore defaults
357      memcpy(state->m_shapeRomPtr,state->m_shapeRom, sizeof(state->m_shapeRom)); // restore defaults, both switches off
357      memcpy(m_shapeRomPtr,m_shapeRom, sizeof(m_shapeRom)); // restore defaults, both switches off
358358                                 // OE enabled on both shapes
359359      break;
360360   case 0x01:
361361      // unselect U22 via SW7. OE on U22 is low.
362      memset(&state->m_shapeRomPtr[0x4000],0xff,0x2000);          // fill unused space with 0xff
363      memcpy(&state->m_shapeRomPtr[0xa000],&state->m_shapeRom[0xa000], 0x2000); // restore defaults here
362      memset(&m_shapeRomPtr[0x4000],0xff,0x2000);          // fill unused space with 0xff
363      memcpy(&m_shapeRomPtr[0xa000],&m_shapeRom[0xa000], 0x2000); // restore defaults here
364364      break;
365365   case 0x02:
366366      // unselect U47 via SW7. OE on U47 is low.
367      memcpy(&state->m_shapeRomPtr[0x4000],&state->m_shapeRom[0x4000], 0x2000);
368      memset(&state->m_shapeRomPtr[0xa000],0xff,0x2000);
367      memcpy(&m_shapeRomPtr[0x4000],&m_shapeRom[0x4000], 0x2000);
368      memset(&m_shapeRomPtr[0xa000],0xff,0x2000);
369369      break;
370370   case 0x03:
371371      // unselect U47 & U22 via SW7. Both output enable low.
372      memset(&state->m_shapeRomPtr[0x4000],0xff,0x2000);
373      memset(&state->m_shapeRomPtr[0xa000],0xff,0x2000);
372      memset(&m_shapeRomPtr[0x4000],0xff,0x2000);
373      memset(&m_shapeRomPtr[0xa000],0xff,0x2000);
374374      break;
375375   }
376376}
r21026r21027
393393      color = ((m_mkiv_vram[count]) & 0xe0) >> 5;
394394         tile = (m_mkiv_vram[count+1]|m_mkiv_vram[count]<<8) & 0x3ff;
395395         bgtile = (m_mkiv_vram[count+1]|m_mkiv_vram[count]<<8) & 0xff; // first 256 tiles
396         uBackgroundColour(machine());   // read sw7
396         uBackgroundColour();   // read sw7
397397         gfx->decode(bgtile);    // force the machine to update only the first 256 tiles.
398398                        // as we only update the background, not the entire display.
399399         flipx = ((m_mkiv_vram[count]) & 0x04);
trunk/src/mame/drivers/olibochu.c
r21026r21027
8888   virtual void palette_init();
8989   UINT32 screen_update_olibochu(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
9090   TIMER_DEVICE_CALLBACK_MEMBER(olibochu_scanline);
91   void draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect );
9192};
9293
9394
r21026r21027
168169   m_bg_tilemap = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(olibochu_state::get_bg_tile_info),this), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);
169170}
170171
171static void draw_sprites( running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect )
172void olibochu_state::draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect )
172173{
173   olibochu_state *state = machine.driver_data<olibochu_state>();
174   UINT8 *spriteram = state->m_spriteram;
175   UINT8 *spriteram_2 = state->m_spriteram2;
174   UINT8 *spriteram = m_spriteram;
175   UINT8 *spriteram_2 = m_spriteram2;
176176   int offs;
177177
178178   /* 16x16 sprites */
179   for (offs = 0; offs < state->m_spriteram.bytes(); offs += 4)
179   for (offs = 0; offs < m_spriteram.bytes(); offs += 4)
180180   {
181181      int attr = spriteram[offs + 1];
182182      int code = spriteram[offs];
r21026r21027
186186      int sx = spriteram[offs + 3];
187187      int sy = ((spriteram[offs + 2] + 8) & 0xff) - 8;
188188
189      if (state->flip_screen())
189      if (flip_screen())
190190      {
191191         sx = 240 - sx;
192192         sy = 240 - sy;
r21026r21027
195195      }
196196
197197      drawgfx_transpen(bitmap, cliprect,
198         machine.gfx[1],
198         machine().gfx[1],
199199         code, color,
200200         flipx, flipy,
201201         sx, sy, 0);
202202   }
203203
204204   /* 8x8 sprites */
205   for (offs = 0; offs < state->m_spriteram2.bytes(); offs += 4)
205   for (offs = 0; offs < m_spriteram2.bytes(); offs += 4)
206206   {
207207      int attr = spriteram_2[offs + 1];
208208      int code = spriteram_2[offs];
r21026r21027
212212      int sx = spriteram_2[offs + 3];
213213      int sy = spriteram_2[offs + 2];
214214
215      if (state->flip_screen())
215      if (flip_screen())
216216      {
217217         sx = 248 - sx;
218218         sy = 248 - sy;
r21026r21027
221221      }
222222
223223      drawgfx_transpen(bitmap, cliprect,
224         machine.gfx[0],
224         machine().gfx[0],
225225         code, color,
226226         flipx, flipy,
227227         sx, sy, 0);
r21026r21027
231231UINT32 olibochu_state::screen_update_olibochu(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
232232{
233233   m_bg_tilemap->draw(bitmap, cliprect, 0, 0);
234   draw_sprites(machine(), bitmap, cliprect);
234   draw_sprites(bitmap, cliprect);
235235   return 0;
236236}
237237
trunk/src/mame/drivers/deco_ld.c
r21026r21027
148148   virtual void machine_start();
149149   UINT32 screen_update_rblaster(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
150150   INTERRUPT_GEN_MEMBER(sound_interrupt);
151   void draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cliprect, UINT8 *spriteram, UINT16 tile_bank );
151152};
152153
153static void draw_sprites(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect, UINT8 *spriteram, UINT16 tile_bank )
154void deco_ld_state::draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cliprect, UINT8 *spriteram, UINT16 tile_bank )
154155{
155   gfx_element *gfx = machine.gfx[1];
156   gfx_element *gfx = machine().gfx[1];
156157   int i,spr_offs,x,y,col,fx,fy;
157158
158159   /*
r21026r21027
202203
203204   bitmap.fill(0, cliprect);
204205
205   draw_sprites(machine(), bitmap,cliprect,m_vram1,0x000);
206   draw_sprites(machine(), bitmap,cliprect,m_vram0,0x100);
206   draw_sprites(bitmap,cliprect,m_vram1,0x000);
207   draw_sprites(bitmap,cliprect,m_vram0,0x100);
207208
208209   for (y=0;y<32;y++)
209210   {
trunk/src/mame/drivers/sfkick.c
r21026r21027
8080   DECLARE_DRIVER_INIT(sfkick);
8181   virtual void machine_reset();
8282   TIMER_DEVICE_CALLBACK_MEMBER(sfkick_interrupt);
83   void sfkick_remap_banks();
84   void sfkick_bank_set(int num, int data);
8385};
8486
8587
r21026r21027
105107   return 0xff;
106108}
107109
108static void sfkick_remap_banks(running_machine &machine)
110void sfkick_state::sfkick_remap_banks()
109111{
110   sfkick_state *state = machine.driver_data<sfkick_state>();
111112   /* 0000-3ffff */
112   switch(state->m_bank_cfg&3)
113   switch(m_bank_cfg&3)
113114   {
114115      case 0: /* bios */
115116      {
116         UINT8 *mem = state->memregion("bios")->base();
117         state->membank("bank1")->set_base(mem);
118         state->membank("bank2")->set_base(mem+0x2000);
117         UINT8 *mem = memregion("bios")->base();
118         membank("bank1")->set_base(mem);
119         membank("bank2")->set_base(mem+0x2000);
119120      }
120121      break;
121122
122123      case 1: /* ext rom */
123124      {
124         UINT8 *mem = machine.root_device().memregion("extrom")->base();
125         state->membank("bank1")->set_base(mem+0x4000);
126         state->membank("bank2")->set_base(mem+0x6000);
125         UINT8 *mem = machine().root_device().memregion("extrom")->base();
126         membank("bank1")->set_base(mem+0x4000);
127         membank("bank2")->set_base(mem+0x6000);
127128      }
128129      break;
129130
130131      case 2: /* banked */
131132      {
132         UINT8 *mem = machine.root_device().memregion("banked")->base();
133         state->membank("bank1")->set_base(mem+0x2000*state->m_bank[0]);
134         state->membank("bank2")->set_base(mem+0x2000*state->m_bank[1]);
133         UINT8 *mem = machine().root_device().memregion("banked")->base();
134         membank("bank1")->set_base(mem+0x2000*m_bank[0]);
135         membank("bank2")->set_base(mem+0x2000*m_bank[1]);
135136      }
136137      break;
137138
138139      case 3: /* unknown */
139140      {
140         UINT8 *mem = machine.root_device().memregion("banked")->base();
141         state->membank("bank1")->set_base(mem+0x18000);
142         state->membank("bank2")->set_base(mem+0x18000);
141         UINT8 *mem = machine().root_device().memregion("banked")->base();
142         membank("bank1")->set_base(mem+0x18000);
143         membank("bank2")->set_base(mem+0x18000);
143144      }
144145      break;
145146   }
146147
147148   /* 4000-7ffff */
148   switch((state->m_bank_cfg>>2)&3)
149   switch((m_bank_cfg>>2)&3)
149150   {
150151      case 0: /* bios - upper part */
151152      {
152         UINT8 *mem = machine.root_device().memregion("bios")->base();
153         state->membank("bank3")->set_base(mem+0x4000);
154         state->membank("bank4")->set_base(mem+0x6000);
153         UINT8 *mem = machine().root_device().memregion("bios")->base();
154         membank("bank3")->set_base(mem+0x4000);
155         membank("bank4")->set_base(mem+0x6000);
155156      }
156157      break;
157158
158159      case 1:  /* unknown */
159160      case 3:
160161      {
161         UINT8 *mem = machine.root_device().memregion("banked")->base();
162         state->membank("bank3")->set_base(mem+0x18000);
163         state->membank("bank4")->set_base(mem+0x18000);
162         UINT8 *mem = machine().root_device().memregion("banked")->base();
163         membank("bank3")->set_base(mem+0x18000);
164         membank("bank4")->set_base(mem+0x18000);
164165      }
165166      break;
166167
167168      case 2: /* banked */
168169      {
169         UINT8 *mem = machine.root_device().memregion("banked")->base();
170         state->membank("bank3")->set_base(mem+0x2000*state->m_bank[2]);
171         state->membank("bank4")->set_base(mem+0x2000*state->m_bank[3]);
170         UINT8 *mem = machine().root_device().memregion("banked")->base();
171         membank("bank3")->set_base(mem+0x2000*m_bank[2]);
172         membank("bank4")->set_base(mem+0x2000*m_bank[3]);
172173      }
173174      break;
174175   }
175176
176177   /* 8000-bffff */
177   switch((state->m_bank_cfg>>4)&3)
178   switch((m_bank_cfg>>4)&3)
178179   {
179180      case 0: /* cartridge */
180181      {
181         UINT8 *mem = machine.root_device().memregion("cartridge")->base();
182         state->membank("bank5")->set_base(mem+0x4000);
183         state->membank("bank6")->set_base(mem+0x6000);
182         UINT8 *mem = machine().root_device().memregion("cartridge")->base();
183         membank("bank5")->set_base(mem+0x4000);
184         membank("bank6")->set_base(mem+0x6000);
184185      }
185186      break;
186187
187188      case 1: /* unknown */
188189      case 3:
189190      {
190         UINT8 *mem = machine.root_device().memregion("banked")->base();
191         state->membank("bank5")->set_base(mem+0x18000);
192         state->membank("bank6")->set_base(mem+0x18000);
191         UINT8 *mem = machine().root_device().memregion("banked")->base();
192         membank("bank5")->set_base(mem+0x18000);
193         membank("bank6")->set_base(mem+0x18000);
193194      }
194195      break;
195196
196197      case 2: /* banked */
197198      {
198         UINT8 *mem = machine.root_device().memregion("banked")->base();
199         state->membank("bank5")->set_base(mem+0x2000*state->m_bank[4]);
200         state->membank("bank6")->set_base(mem+0x2000*state->m_bank[5]);
199         UINT8 *mem = machine().root_device().memregion("banked")->base();
200         membank("bank5")->set_base(mem+0x2000*m_bank[4]);
201         membank("bank6")->set_base(mem+0x2000*m_bank[5]);
201202      }
202203      break;
203204   }
204205
205206   /* c000-fffff */
206   switch((state->m_bank_cfg>>6)&3)
207   switch((m_bank_cfg>>6)&3)
207208   {
208209      case 0: /* unknown */
209210      case 1:
210211      {
211         UINT8 *mem = machine.root_device().memregion("banked")->base();
212         state->membank("bank7")->set_base(mem+0x18000);
213         state->membank("bank8")->set_base(mem+0x18000);
212         UINT8 *mem = machine().root_device().memregion("banked")->base();
213         membank("bank7")->set_base(mem+0x18000);
214         membank("bank8")->set_base(mem+0x18000);
214215      }
215216      break;
216217
217218      case 2: /* banked */
218219      {
219         UINT8 *mem = machine.root_device().memregion("banked")->base();
220         state->membank("bank7")->set_base(mem+0x2000*state->m_bank[6]);
221         state->membank("bank8")->set_base(mem+0x2000*state->m_bank[7]);
220         UINT8 *mem = machine().root_device().memregion("banked")->base();
221         membank("bank7")->set_base(mem+0x2000*m_bank[6]);
222         membank("bank8")->set_base(mem+0x2000*m_bank[7]);
222223      }
223224      break;
224225
225226      case 3: /* RAM */
226227      {
227         state->membank("bank7")->set_base(state->m_main_mem);
228         state->membank("bank8")->set_base(state->m_main_mem+0x2000);
228         membank("bank7")->set_base(m_main_mem);
229         membank("bank8")->set_base(m_main_mem+0x2000);
229230      }
230231      break;
231232   }
r21026r21027
234235WRITE8_MEMBER(sfkick_state::ppi_port_a_w)
235236{
236237   m_bank_cfg=data;
237   sfkick_remap_banks(machine());
238   sfkick_remap_banks();
238239}
239240
240static void sfkick_bank_set(running_machine &machine,int num, int data)
241void sfkick_state::sfkick_bank_set(int num, int data)
241242{
242   sfkick_state *state = machine.driver_data<sfkick_state>();
243243   /* ignore bit 1 */
244244   data&=0xf;
245245   num&=5;
246   state->m_bank[num]=data;
246   m_bank[num]=data;
247247   num|=2;
248   state->m_bank[num]=data;
249   sfkick_remap_banks(machine);
248   m_bank[num]=data;
249   sfkick_remap_banks();
250250}
251251
252252WRITE8_MEMBER(sfkick_state::page0_w)
r21026r21027
255255   {
256256      if(offset<0x2000)
257257      {
258         sfkick_bank_set(machine(),0,data);
258         sfkick_bank_set(0,data);
259259      }
260260      else
261261      {
262         sfkick_bank_set(machine(),1,data);
262         sfkick_bank_set(1,data);
263263      }
264264   }
265265}
r21026r21027
270270   {
271271      if(offset<0x2000)
272272      {
273         sfkick_bank_set(machine(),2,data);
273         sfkick_bank_set(2,data);
274274      }
275275      else
276276      {
277         sfkick_bank_set(machine(),3,data);
277         sfkick_bank_set(3,data);
278278      }
279279   }
280280}
r21026r21027
285285   {
286286      if(offset<0x2000)
287287      {
288         sfkick_bank_set(machine(),4,data);
288         sfkick_bank_set(4,data);
289289      }
290290      else
291291      {
292         sfkick_bank_set(machine(),5,data);
292         sfkick_bank_set(5,data);
293293      }
294294   }
295295}
r21026r21027
300300   {
301301      if(offset<0x2000)
302302      {
303         sfkick_bank_set(machine(),6,data);
303         sfkick_bank_set(6,data);
304304      }
305305      else
306306      {
307         sfkick_bank_set(machine(),7,data);
307         sfkick_bank_set(7,data);
308308      }
309309   }
310310   else
r21026r21027
447447   m_bank[5]=0;
448448   m_bank[6]=0;
449449   m_bank[7]=0;
450   sfkick_remap_banks(machine());
450   sfkick_remap_banks();
451451}
452452
453453TIMER_DEVICE_CALLBACK_MEMBER(sfkick_state::sfkick_interrupt)
trunk/src/mame/drivers/sangho.c
r21026r21027
6868   DECLARE_MACHINE_RESET(pzlestar);
6969   DECLARE_MACHINE_RESET(sexyboom);
7070   TIMER_DEVICE_CALLBACK_MEMBER(sangho_interrupt);
71   void pzlestar_map_banks();
72   void sexyboom_map_bank(int bank);
7173};
7274
7375
74static void pzlestar_map_banks(running_machine &machine)
76void sangho_state::pzlestar_map_banks()
7577{
76   sangho_state *state = machine.driver_data<sangho_state>();
7778   int slot_select;
7879
7980   // page 0
80   slot_select = (state->m_pzlestar_mem_bank >> 0) & 0x03;
81   slot_select = (m_pzlestar_mem_bank >> 0) & 0x03;
8182   switch(slot_select)
8283   {
8384      case 0:
84         machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x0000, 0x3fff, "bank1");
85         machine.device("maincpu")->memory().space(AS_PROGRAM).install_write_bank(0x0000, 0x3fff, "bank5");
86         state->membank("bank1")->set_base(state->m_ram);
87         state->membank("bank5")->set_base(state->m_ram);
85         machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x0000, 0x3fff, "bank1");
86         machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_bank(0x0000, 0x3fff, "bank5");
87         membank("bank1")->set_base(m_ram);
88         membank("bank5")->set_base(m_ram);
8889         break;
8990      case 2:
90         machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x0000, 0x3fff, "bank1");
91         machine.device("maincpu")->memory().space(AS_PROGRAM).unmap_write(0x0000, 0x3fff);
92         state->membank("bank1")->set_base(state->memregion("user1")->base()+ 0x10000);
91         machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x0000, 0x3fff, "bank1");
92         machine().device("maincpu")->memory().space(AS_PROGRAM).unmap_write(0x0000, 0x3fff);
93         membank("bank1")->set_base(memregion("user1")->base()+ 0x10000);
9394         break;
9495      case 1:
9596      case 3:
96         machine.device("maincpu")->memory().space(AS_PROGRAM).unmap_read(0x0000, 0x3fff);
97         machine.device("maincpu")->memory().space(AS_PROGRAM).unmap_write(0x0000, 0x3fff);
97         machine().device("maincpu")->memory().space(AS_PROGRAM).unmap_read(0x0000, 0x3fff);
98         machine().device("maincpu")->memory().space(AS_PROGRAM).unmap_write(0x0000, 0x3fff);
9899         break;
99100   }
100101
101102   // page 1
102   slot_select = (state->m_pzlestar_mem_bank >> 2) & 0x03;
103   slot_select = (m_pzlestar_mem_bank >> 2) & 0x03;
103104   switch(slot_select)
104105   {
105106      case 0:
106         machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x4000, 0x7fff, "bank2");
107         machine.device("maincpu")->memory().space(AS_PROGRAM).install_write_bank(0x4000, 0x7fff, "bank6");
108         state->membank("bank2")->set_base(state->m_ram + 0x4000);
109         state->membank("bank6")->set_base(state->m_ram + 0x4000);
107         machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x4000, 0x7fff, "bank2");
108         machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_bank(0x4000, 0x7fff, "bank6");
109         membank("bank2")->set_base(m_ram + 0x4000);
110         membank("bank6")->set_base(m_ram + 0x4000);
110111         break;
111112      case 2:
112         machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x4000, 0x7fff, "bank2");
113         machine.device("maincpu")->memory().space(AS_PROGRAM).unmap_write(0x4000, 0x7fff);
114         state->membank("bank2")->set_base(machine.root_device().memregion("user1")->base()+ 0x18000);
113         machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x4000, 0x7fff, "bank2");
114         machine().device("maincpu")->memory().space(AS_PROGRAM).unmap_write(0x4000, 0x7fff);
115         membank("bank2")->set_base(machine().root_device().memregion("user1")->base()+ 0x18000);
115116         break;
116117      case 3:
117         machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x4000, 0x7fff, "bank2");
118         machine.device("maincpu")->memory().space(AS_PROGRAM).unmap_write(0x4000, 0x7fff);
119         state->membank("bank2")->set_base(machine.root_device().memregion("user1")->base()+ 0x20000 + (state->m_pzlestar_rom_bank*0x8000) + 0x4000);
118         machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x4000, 0x7fff, "bank2");
119         machine().device("maincpu")->memory().space(AS_PROGRAM).unmap_write(0x4000, 0x7fff);
120         membank("bank2")->set_base(machine().root_device().memregion("user1")->base()+ 0x20000 + (m_pzlestar_rom_bank*0x8000) + 0x4000);
120121         break;
121122      case 1:
122         machine.device("maincpu")->memory().space(AS_PROGRAM).unmap_read(0x4000, 0x7fff);
123         machine.device("maincpu")->memory().space(AS_PROGRAM).unmap_write(0x4000, 0x7fff);
123         machine().device("maincpu")->memory().space(AS_PROGRAM).unmap_read(0x4000, 0x7fff);
124         machine().device("maincpu")->memory().space(AS_PROGRAM).unmap_write(0x4000, 0x7fff);
124125         break;
125126   }
126127
127128   // page 2
128   slot_select = (state->m_pzlestar_mem_bank >> 4) & 0x03;
129   slot_select = (m_pzlestar_mem_bank >> 4) & 0x03;
129130   switch(slot_select)
130131   {
131132      case 0:
132         machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x8000, 0xbfff, "bank3");
133         machine.device("maincpu")->memory().space(AS_PROGRAM).install_write_bank(0x8000, 0xbfff, "bank7");
134         state->membank("bank3")->set_base(state->m_ram + 0x8000);
135         state->membank("bank7")->set_base(state->m_ram + 0x8000);
133         machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x8000, 0xbfff, "bank3");
134         machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_bank(0x8000, 0xbfff, "bank7");
135         membank("bank3")->set_base(m_ram + 0x8000);
136         membank("bank7")->set_base(m_ram + 0x8000);
136137         break;
137138      case 3:
138         machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x8000, 0xbfff, "bank3");
139         machine.device("maincpu")->memory().space(AS_PROGRAM).unmap_write(0x8000, 0xbfff);
140         state->membank("bank3")->set_base(machine.root_device().memregion("user1")->base()+ 0x20000 + (state->m_pzlestar_rom_bank*0x8000));
139         machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x8000, 0xbfff, "bank3");
140         machine().device("maincpu")->memory().space(AS_PROGRAM).unmap_write(0x8000, 0xbfff);
141         membank("bank3")->set_base(machine().root_device().memregion("user1")->base()+ 0x20000 + (m_pzlestar_rom_bank*0x8000));
141142         break;
142143      case 1:
143144      case 2:
144         machine.device("maincpu")->memory().space(AS_PROGRAM).unmap_read(0x8000, 0xbfff);
145         machine.device("maincpu")->memory().space(AS_PROGRAM).unmap_write(0x8000, 0xbfff);
145         machine().device("maincpu")->memory().space(AS_PROGRAM).unmap_read(0x8000, 0xbfff);
146         machine().device("maincpu")->memory().space(AS_PROGRAM).unmap_write(0x8000, 0xbfff);
146147         break;
147148   }
148149
149150   // page 3
150   slot_select = (state->m_pzlestar_mem_bank >> 6) & 0x03;
151   slot_select = (m_pzlestar_mem_bank >> 6) & 0x03;
151152   switch(slot_select)
152153   {
153154      case 0:
154         machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0xc000, 0xffff, "bank4");
155         machine.device("maincpu")->memory().space(AS_PROGRAM).install_write_bank(0xc000, 0xffff, "bank8");
156         state->membank("bank4")->set_base(state->m_ram + 0xc000);
157         state->membank("bank8")->set_base(state->m_ram + 0xc000);
155         machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0xc000, 0xffff, "bank4");
156         machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_bank(0xc000, 0xffff, "bank8");
157         membank("bank4")->set_base(m_ram + 0xc000);
158         membank("bank8")->set_base(m_ram + 0xc000);
158159         break;
159160      case 1:
160161      case 2:
161162      case 3:
162         machine.device("maincpu")->memory().space(AS_PROGRAM).unmap_read(0xc000, 0xffff);
163         machine.device("maincpu")->memory().space(AS_PROGRAM).unmap_write(0xc000, 0xffff);
163         machine().device("maincpu")->memory().space(AS_PROGRAM).unmap_read(0xc000, 0xffff);
164         machine().device("maincpu")->memory().space(AS_PROGRAM).unmap_write(0xc000, 0xffff);
164165         break;
165166   }
166167
r21026r21027
170171{
171172   logerror("rom bank %02x\n", data);
172173   m_pzlestar_rom_bank = data;
173   pzlestar_map_banks(machine());
174   pzlestar_map_banks();
174175}
175176
176177WRITE8_MEMBER(sangho_state::pzlestar_mem_bank_w)
177178{
178179   logerror("mem bank %02x\n", data);
179180   m_pzlestar_mem_bank = data;
180   pzlestar_map_banks(machine());
181   pzlestar_map_banks();
181182}
182183
183184READ8_MEMBER(sangho_state::pzlestar_mem_bank_r)
r21026r21027
185186   return m_pzlestar_mem_bank;
186187}
187188
188static void sexyboom_map_bank(running_machine &machine, int bank)
189void sangho_state::sexyboom_map_bank(int bank)
189190{
190   sangho_state *state = machine.driver_data<sangho_state>();
191191   UINT8 banknum, banktype;
192192   char read_bank_name[6], write_bank_name[6];
193193
194   banknum = state->m_sexyboom_bank[bank*2];
195   banktype = state->m_sexyboom_bank[bank*2 + 1];
194   banknum = m_sexyboom_bank[bank*2];
195   banktype = m_sexyboom_bank[bank*2 + 1];
196196   sprintf(read_bank_name, "bank%d", bank+1);
197197   sprintf(write_bank_name, "bank%d", bank+1+4);
198198
r21026r21027
201201      if (banknum & 0x80)
202202      {
203203         // ram
204         state->membank(read_bank_name)->set_base(&state->m_ram[(banknum & 0x7f) * 0x4000]);
205         machine.device("maincpu")->memory().space(AS_PROGRAM).install_write_bank(bank*0x4000, (bank+1)*0x4000 - 1, write_bank_name );
206         state->membank(write_bank_name)->set_base(&state->m_ram[(banknum & 0x7f) * 0x4000]);
204         membank(read_bank_name)->set_base(&m_ram[(banknum & 0x7f) * 0x4000]);
205         machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_bank(bank*0x4000, (bank+1)*0x4000 - 1, write_bank_name );
206         membank(write_bank_name)->set_base(&m_ram[(banknum & 0x7f) * 0x4000]);
207207      }
208208      else
209209      {
210210         // rom 0
211         state->membank(read_bank_name)->set_base(machine.root_device().memregion("user1")->base()+0x4000*banknum);
212         machine.device("maincpu")->memory().space(AS_PROGRAM).unmap_write(bank*0x4000, (bank+1)*0x4000 - 1);
211         membank(read_bank_name)->set_base(machine().root_device().memregion("user1")->base()+0x4000*banknum);
212         machine().device("maincpu")->memory().space(AS_PROGRAM).unmap_write(bank*0x4000, (bank+1)*0x4000 - 1);
213213      }
214214   }
215215   else if (banktype == 0x82)
216216   {
217      state->membank(read_bank_name)->set_base(machine.root_device().memregion("user1")->base()+0x20000+banknum*0x4000);
218      machine.device("maincpu")->memory().space(AS_PROGRAM).unmap_write(bank*0x4000, (bank+1)*0x4000 - 1);
217      membank(read_bank_name)->set_base(machine().root_device().memregion("user1")->base()+0x20000+banknum*0x4000);
218      machine().device("maincpu")->memory().space(AS_PROGRAM).unmap_write(bank*0x4000, (bank+1)*0x4000 - 1);
219219   }
220220   else if (banktype == 0x80)
221221   {
222      state->membank(read_bank_name)->set_base(machine.root_device().memregion("user1")->base()+0x120000+banknum*0x4000);
223      machine.device("maincpu")->memory().space(AS_PROGRAM).unmap_write(bank*0x4000, (bank+1)*0x4000 - 1);
222      membank(read_bank_name)->set_base(machine().root_device().memregion("user1")->base()+0x120000+banknum*0x4000);
223      machine().device("maincpu")->memory().space(AS_PROGRAM).unmap_write(bank*0x4000, (bank+1)*0x4000 - 1);
224224   }
225225   else
226226   {
r21026r21027
231231WRITE8_MEMBER(sangho_state::sexyboom_bank_w)
232232{
233233   m_sexyboom_bank[offset] = data;
234   sexyboom_map_bank(machine(), offset>>1);
234   sexyboom_map_bank(offset>>1);
235235}
236236
237237static ADDRESS_MAP_START( sangho_map, AS_PROGRAM, 8, sangho_state )
r21026r21027
382382MACHINE_RESET_MEMBER(sangho_state,pzlestar)
383383{
384384   m_pzlestar_mem_bank = 2;
385   pzlestar_map_banks(machine());
385   pzlestar_map_banks();
386386}
387387
388388MACHINE_RESET_MEMBER(sangho_state,sexyboom)
r21026r21027
395395   m_sexyboom_bank[5] = 0x00;
396396   m_sexyboom_bank[6] = 0x80;
397397   m_sexyboom_bank[7] = 0x01;
398   sexyboom_map_bank(machine(), 0);
399   sexyboom_map_bank(machine(), 1);
400   sexyboom_map_bank(machine(), 2);
401   sexyboom_map_bank(machine(), 3);
398   sexyboom_map_bank(0);
399   sexyboom_map_bank(1);
400   sexyboom_map_bank(2);
401   sexyboom_map_bank(3);
402402}
403403
404404static void msx_vdp_interrupt(device_t *, v99x8_device &device, int i)
trunk/src/mame/drivers/mgolf.c
r21026r21027
4040   virtual void palette_init();
4141   UINT32 screen_update_mgolf(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
4242   TIMER_CALLBACK_MEMBER(interrupt_callback);
43   void update_plunger(  );
44   double calc_plunger_pos();
4345};
4446
4547
r21026r21027
9294}
9395
9496
95static void update_plunger( running_machine &machine )
97void mgolf_state::update_plunger(  )
9698{
97   mgolf_state *state = machine.driver_data<mgolf_state>();
98   UINT8 val = state->ioport("BUTTON")->read();
99   UINT8 val = ioport("BUTTON")->read();
99100
100   if (state->m_prev != val)
101   if (m_prev != val)
101102   {
102103      if (val == 0)
103104      {
104         state->m_time_released = machine.time();
105         m_time_released = machine().time();
105106
106         if (!state->m_mask)
107            state->m_maincpu->set_input_line(INPUT_LINE_NMI, PULSE_LINE);
107         if (!m_mask)
108            m_maincpu->set_input_line(INPUT_LINE_NMI, PULSE_LINE);
108109      }
109110      else
110         state->m_time_pushed = machine.time();
111         m_time_pushed = machine().time();
111112
112      state->m_prev = val;
113      m_prev = val;
113114   }
114115}
115116
r21026r21027
118119{
119120   int scanline = param;
120121
121   update_plunger(machine());
122   update_plunger();
122123
123124   generic_pulse_irq_line(*m_maincpu, 0, 1);
124125
r21026r21027
131132}
132133
133134
134static double calc_plunger_pos(running_machine &machine)
135double mgolf_state::calc_plunger_pos()
135136{
136   mgolf_state *state = machine.driver_data<mgolf_state>();
137   return (machine.time().as_double() - state->m_time_released.as_double()) * (state->m_time_released.as_double() - state->m_time_pushed.as_double() + 0.2);
137   return (machine().time().as_double() - m_time_released.as_double()) * (m_time_released.as_double() - m_time_pushed.as_double() + 0.2);
138138}
139139
140140
r21026r21027
163163
164164READ8_MEMBER(mgolf_state::mgolf_misc_r)
165165{
166   double plunger = calc_plunger_pos(machine()); /* see Video Pinball */
166   double plunger = calc_plunger_pos(); /* see Video Pinball */
167167
168168   UINT8 val = ioport("61")->read();
169169
trunk/src/mame/drivers/sbrkout.c
r21026r21027
6969   UINT32 screen_update_sbrkout(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
7070   TIMER_CALLBACK_MEMBER(scanline_callback);
7171   TIMER_CALLBACK_MEMBER(pot_trigger_callback);
72   void update_nmi_state();
7273};
7374
7475
r21026r21027
201202}
202203
203204
204static void update_nmi_state(running_machine &machine)
205void sbrkout_state::update_nmi_state()
205206{
206   sbrkout_state *state = machine.driver_data<sbrkout_state>();
207   if ((state->m_pot_trigger[0] & ~state->m_pot_mask[0]) | (state->m_pot_trigger[1] & ~state->m_pot_mask[1]))
208      machine.device("maincpu")->execute().set_input_line(INPUT_LINE_NMI, ASSERT_LINE);
207   if ((m_pot_trigger[0] & ~m_pot_mask[0]) | (m_pot_trigger[1] & ~m_pot_mask[1]))
208      machine().device("maincpu")->execute().set_input_line(INPUT_LINE_NMI, ASSERT_LINE);
209209   else
210      machine.device("maincpu")->execute().set_input_line(INPUT_LINE_NMI, CLEAR_LINE);
210      machine().device("maincpu")->execute().set_input_line(INPUT_LINE_NMI, CLEAR_LINE);
211211}
212212
213213
214214TIMER_CALLBACK_MEMBER(sbrkout_state::pot_trigger_callback)
215215{
216216   m_pot_trigger[param] = 1;
217   update_nmi_state(machine());
217   update_nmi_state();
218218}
219219
220220
r21026r21027
222222{
223223   m_pot_mask[0] = ~offset & 1;
224224   m_pot_trigger[0] = 0;
225   update_nmi_state(machine());
225   update_nmi_state();
226226}
227227
228228
r21026r21027
230230{
231231   m_pot_mask[1] = ~offset & 1;
232232   m_pot_trigger[1] = 0;
233   update_nmi_state(machine());
233   update_nmi_state();
234234}
235235
236236
trunk/src/mame/drivers/mwarr.c
r21026r21027
100100   virtual void machine_reset();
101101   virtual void video_start();
102102   UINT32 screen_update_mwarr(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
103   void draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect );
103104};
104105
105106
r21026r21027
404405   save_item(NAME(m_sprites_buffer));
405406}
406407
407static void draw_sprites( running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect )
408void mwarr_state::draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect )
408409{
409   mwarr_state *state = machine.driver_data<mwarr_state>();
410   const UINT16 *source = state->m_sprites_buffer + 0x800 - 4;
411   const UINT16 *finish = state->m_sprites_buffer;
412   gfx_element *gfx = machine.gfx[0];
410   const UINT16 *source = m_sprites_buffer + 0x800 - 4;
411   const UINT16 *finish = m_sprites_buffer;
412   gfx_element *gfx = machine().gfx[0];
413413   int x, y, color, flipx, dy, pri, pri_mask, i;
414414
415415   while (source >= finish)
r21026r21027
437437                     color,
438438                     flipx,0,
439439                     x,y+i*16,
440                     machine.priority_bitmap,pri_mask,0 );
440                     machine().priority_bitmap,pri_mask,0 );
441441
442442            /* wrap around x */
443443            pdrawgfx_transpen( bitmap,
r21026r21027
447447                     color,
448448                     flipx,0,
449449                     x-1024,y+i*16,
450                     machine.priority_bitmap,pri_mask,0 );
450                     machine().priority_bitmap,pri_mask,0 );
451451
452452            /* wrap around y */
453453            pdrawgfx_transpen( bitmap,
r21026r21027
457457                     color,
458458                     flipx,0,
459459                     x,y-512+i*16,
460                     machine.priority_bitmap,pri_mask,0 );
460                     machine().priority_bitmap,pri_mask,0 );
461461
462462            /* wrap around x & y */
463463            pdrawgfx_transpen( bitmap,
r21026r21027
467467                     color,
468468                     flipx,0,
469469                     x-1024,y-512+i*16,
470                     machine.priority_bitmap,pri_mask,0 );
470                     machine().priority_bitmap,pri_mask,0 );
471471         }
472472      }
473473
r21026r21027
525525   m_mlow_tilemap->draw(bitmap, cliprect, 0, 0x02);
526526   m_mhigh_tilemap->draw(bitmap, cliprect, 0, 0x04);
527527   m_tx_tilemap->draw(bitmap, cliprect, 0, 0x10);
528   draw_sprites(machine(), bitmap, cliprect);
528   draw_sprites(bitmap, cliprect);
529529   return 0;
530530}
531531
trunk/src/mame/drivers/calchase.c
r21026r21027
182182   virtual void machine_start();
183183   virtual void machine_reset();
184184   IRQ_CALLBACK_MEMBER(irq_callback);
185   void intel82439tx_init();
185186};
186187
187188
r21026r21027
368369   state->m_mxtc_config_reg[reg] = data;
369370}
370371
371static void intel82439tx_init(running_machine &machine)
372void calchase_state::intel82439tx_init()
372373{
373   calchase_state *state = machine.driver_data<calchase_state>();
374   state->m_mxtc_config_reg[0x60] = 0x02;
375   state->m_mxtc_config_reg[0x61] = 0x02;
376   state->m_mxtc_config_reg[0x62] = 0x02;
377   state->m_mxtc_config_reg[0x63] = 0x02;
378   state->m_mxtc_config_reg[0x64] = 0x02;
379   state->m_mxtc_config_reg[0x65] = 0x02;
374   m_mxtc_config_reg[0x60] = 0x02;
375   m_mxtc_config_reg[0x61] = 0x02;
376   m_mxtc_config_reg[0x62] = 0x02;
377   m_mxtc_config_reg[0x63] = 0x02;
378   m_mxtc_config_reg[0x64] = 0x02;
379   m_mxtc_config_reg[0x65] = 0x02;
380380}
381381
382382static UINT32 intel82439tx_pci_r(device_t *busdevice, device_t *device, int function, int reg, UINT32 mem_mask)
r21026r21027
968968
969969   init_pc_common(machine(), PCCOMMON_KEYBOARD_AT, calchase_set_keyb_int);
970970
971   intel82439tx_init(machine());
971   intel82439tx_init();
972972
973973   kbdc8042_init(machine(), &at8042);
974974
trunk/src/mame/drivers/popobear.c
r21026r21027
9797   virtual void video_start();
9898   UINT32 screen_update_popobear(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
9999   TIMER_DEVICE_CALLBACK_MEMBER(popobear_irq);
100   void draw_layer(bitmap_ind16 &bitmap,const rectangle &cliprect, UINT8 layer_n);
101   void draw_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect);
100102};
101103
102104void popobear_state::video_start()
103105{
104106}
105107
106static void draw_layer(running_machine &machine, bitmap_ind16 &bitmap,const rectangle &cliprect, UINT8 layer_n)
108void popobear_state::draw_layer(bitmap_ind16 &bitmap,const rectangle &cliprect, UINT8 layer_n)
107109{
108   popobear_state *state = machine.driver_data<popobear_state>();
109110   // ERROR: This cast is NOT endian-safe without the use of BYTE/WORD/DWORD_XOR_* macros!
110   UINT8* vram = reinterpret_cast<UINT8 *>(state->m_vram.target());
111   UINT16* vreg = (UINT16 *)state->m_vregs;
111   UINT8* vram = reinterpret_cast<UINT8 *>(m_vram.target());
112   UINT16* vreg = (UINT16 *)m_vregs;
112113   int count;
113114   const UINT8 vreg_base[] = { 0x10/2, 0x14/2 };
114115   int xscroll,yscroll;
115116
116//  count = (state->m_vregs[vreg_base[layer_n]]<<5);
117//  count = (m_vregs[vreg_base[layer_n]]<<5);
117118//  count &= 0xfc000;
118119   count = (0xf0000+layer_n*0x4000);
119120   if(layer_n & 2)
r21026r21027
154155               color = (vram[((xi+yi*1024)+xtile+ytile) & 0xfffff] & 0xff);
155156
156157               if(cliprect.contains(xoffs+1, yoffs) && color)
157                  bitmap.pix16(yoffs, xoffs+1) = machine.pens[color];
158                  bitmap.pix16(yoffs, xoffs+1) = machine().pens[color];
158159
159160               if(cliprect.contains(xoffs+1, yoffs+512) && color)
160                  bitmap.pix16(yoffs+512, xoffs+1) = machine.pens[color];
161                  bitmap.pix16(yoffs+512, xoffs+1) = machine().pens[color];
161162
162163               //if(cliprect.contains(xoffs+1, yoffs+256) && color)
163               //  bitmap.pix16(yoffs+512, xoffs+1) = machine.pens[color];
164               //  bitmap.pix16(yoffs+512, xoffs+1) = machine().pens[color];
164165
165166               color = (vram[((xi+1+yi*1024)+xtile+ytile) & 0xfffff] & 0xff);
166167
167168               if(cliprect.contains(xoffs, yoffs) && color)
168                  bitmap.pix16(yoffs, xoffs) = machine.pens[color];
169                  bitmap.pix16(yoffs, xoffs) = machine().pens[color];
169170
170171               if(cliprect.contains(xoffs, yoffs+512) && color)
171                  bitmap.pix16(yoffs+512, xoffs) = machine.pens[color];
172                  bitmap.pix16(yoffs+512, xoffs) = machine().pens[color];
172173            }
173174         }
174175
r21026r21027
177178   }
178179}
179180
180static void draw_sprites(running_machine &machine, bitmap_ind16 &bitmap,const rectangle &cliprect)
181void popobear_state::draw_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect)
181182{
182   popobear_state *state = machine.driver_data<popobear_state>();
183183   // ERROR: This cast is NOT endian-safe without the use of BYTE/WORD/DWORD_XOR_* macros!
184   UINT8* vram = reinterpret_cast<UINT8 *>(state->m_spr.target());
184   UINT8* vram = reinterpret_cast<UINT8 *>(m_spr.target());
185185   int i;
186186   #if 0
187187   static int bank_test = 1;
188188
189   if(machine.input().code_pressed_once(KEYCODE_Z))
189   if(machine().input().code_pressed_once(KEYCODE_Z))
190190      bank_test<<=1;
191191
192   if(machine.input().code_pressed_once(KEYCODE_X))
192   if(machine().input().code_pressed_once(KEYCODE_X))
193193      bank_test>>=1;
194194
195195   popmessage("%02x",bank_test);
r21026r21027
242242            y_res = (y_dir) ? y+(height - yi) : y+yi;
243243
244244            if(cliprect.contains(x_res, y_res) && color)
245               bitmap.pix16(y_res, x_res) = machine.pens[color+0x100+color_bank];
245               bitmap.pix16(y_res, x_res) = machine().pens[color+0x100+color_bank];
246246
247247            color = (vram[spr_num+1] & 0xff);
248248            x_res = (x_dir) ? x+1+(width - xi) : x+0+xi;
249249            y_res = (y_dir) ? y+(height - yi) : y+yi;
250250
251251            if(cliprect.contains(x_res, y_res) && color)
252               bitmap.pix16(y_res, x_res) = machine.pens[color+0x100+color_bank];
252               bitmap.pix16(y_res, x_res) = machine().pens[color+0x100+color_bank];
253253
254254            spr_num+=2;
255255         }
r21026r21027
263263
264264   //popmessage("%04x",m_vregs[0/2]);
265265
266   draw_layer(machine(),bitmap,cliprect,3);
267   draw_layer(machine(),bitmap,cliprect,2);
268   draw_layer(machine(),bitmap,cliprect,1);
269   draw_layer(machine(),bitmap,cliprect,0);
270   draw_sprites(machine(),bitmap,cliprect);
266   draw_layer(bitmap,cliprect,3);
267   draw_layer(bitmap,cliprect,2);
268   draw_layer(bitmap,cliprect,1);
269   draw_layer(bitmap,cliprect,0);
270   draw_sprites(bitmap,cliprect);
271271
272272   return 0;
273273}
trunk/src/mame/drivers/egghunt.c
r21026r21027
8080   virtual void machine_reset();
8181   virtual void video_start();
8282   UINT32 screen_update_egghunt(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
83   void draw_sprites( bitmap_ind16 &bitmap,const rectangle &cliprect );
8384};
8485
8586
86static void draw_sprites( running_machine &machine, bitmap_ind16 &bitmap,const rectangle &cliprect )
87void egghunt_state::draw_sprites( bitmap_ind16 &bitmap,const rectangle &cliprect )
8788{
88   egghunt_state *state = machine.driver_data<egghunt_state>();
8989   int flipscreen = 0;
9090   int offs, sx, sy;
9191
9292   for (offs = 0x1000 - 0x40; offs >= 0; offs -= 0x20)
9393   {
94      int code = state->m_spram[offs];
95      int attr = state->m_spram[offs + 1];
94      int code = m_spram[offs];
95      int attr = m_spram[offs + 1];
9696      int color = attr & 0x0f;
97      sx = state->m_spram[offs + 3] + ((attr & 0x10) << 4);
98      sy = ((state->m_spram[offs + 2] + 8) & 0xff) - 8;
97      sx = m_spram[offs + 3] + ((attr & 0x10) << 4);
98      sy = ((m_spram[offs + 2] + 8) & 0xff) - 8;
9999      code += (attr & 0xe0) << 3;
100100
101101      if (attr & 0xe0)
102102      {
103         switch(state->m_gfx_banking & 0x30)
103         switch(m_gfx_banking & 0x30)
104104         {
105105   //          case 0x00:
106106   //          case 0x10: code += 0; break;
r21026r21027
114114         sx = 496 - sx;
115115         sy = 240 - sy;
116116      }
117      drawgfx_transpen(bitmap,cliprect,machine.gfx[1],
117      drawgfx_transpen(bitmap,cliprect,machine().gfx[1],
118118               code,
119119               color,
120120               flipscreen,flipscreen,
r21026r21027
183183UINT32 egghunt_state::screen_update_egghunt(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
184184{
185185   m_bg_tilemap->draw(bitmap, cliprect, 0, 0);
186   draw_sprites(machine(), bitmap, cliprect);
186   draw_sprites(bitmap, cliprect);
187187   return 0;
188188}
189189
trunk/src/mame/drivers/bfcobra.c
r21026r21027
8989#define M6809_XTAL  1000000
9090
9191
92/*
93    Function prototypes
94*/
95INLINE void z80_bank(running_machine &machine, int num, int data);
9692
97
9893/***************************************************************************
9994
10095    Split into video\cobra.c !
r21026r21027
308303   void exec_w_phase(UINT8 data);
309304   void init_ram();
310305   void command_phase(struct fdc_t &fdc, UINT8 data);
306   inline UINT8* blitter_get_addr(UINT32 addr);
307   inline void z80_bank(int num, int data);
308   UINT8 exec_r_phase(void);
309   UINT8 results_phase(void);
311310};
312311
313312
r21026r21027
434433   return 0;
435434}
436435
437INLINE UINT8* blitter_get_addr(running_machine &machine, UINT32 addr)
436UINT8* bfcobra_state::blitter_get_addr(UINT32 addr)
438437{
439   bfcobra_state *state = machine.driver_data<bfcobra_state>();
440438   if (addr < 0x10000)
441439   {
442440      /* Is this region fixed? */
443      return (UINT8*)(state->memregion("user1")->base() + addr);
441      return (UINT8*)(memregion("user1")->base() + addr);
444442   }
445443   else if(addr < 0x20000)
446444   {
447445      addr &= 0xffff;
448      addr += (state->m_bank_data[0] & 1) ? 0x10000 : 0;
446      addr += (m_bank_data[0] & 1) ? 0x10000 : 0;
449447
450      return (UINT8*)(machine.root_device().memregion("user1")->base() + addr + ((state->m_bank_data[0] >> 1) * 0x20000));
448      return (UINT8*)(machine().root_device().memregion("user1")->base() + addr + ((m_bank_data[0] >> 1) * 0x20000));
451449   }
452450   else if (addr >= 0x20000 && addr < 0x40000)
453451   {
454      return (UINT8*)&state->m_video_ram[addr - 0x20000];
452      return (UINT8*)&m_video_ram[addr - 0x20000];
455453   }
456454   else
457455   {
458      return (UINT8*)&state->m_work_ram[addr - 0x40000];
456      return (UINT8*)&m_work_ram[addr - 0x40000];
459457   }
460458}
461459
r21026r21027
467465*/
468466void bfcobra_state::RunBlit(address_space &space)
469467{
470#define BLITPRG_READ(x)     blitter.x = *(blitter_get_addr(space.machine(), blitter.program.addr++))
468#define BLITPRG_READ(x)     blitter.x = *(blitter_get_addr(blitter.program.addr++))
471469
472470   struct blitter_t &blitter = m_blitter;
473471   int cycles_used = 0;
r21026r21027
577575                  blitter.source.addr0 -=blitter.step;
578576               }
579577
580               *blitter_get_addr(space.machine(), blitter.dest.addr) = blitter.pattern;
578               *blitter_get_addr( blitter.dest.addr) = blitter.pattern;
581579               cycles_used++;
582580
583581            } while (--innercnt);
r21026r21027
591589
592590            if (LOOPTYPE == 3 && innercnt == blitter.innercnt)
593591            {
594               srcdata = *(blitter_get_addr(space.machine(), blitter.source.addr & 0xfffff));
592               srcdata = *(blitter_get_addr( blitter.source.addr & 0xfffff));
595593               blitter.source.loword++;
596594               cycles_used++;
597595            }
r21026r21027
601599            {
602600               if (LOOPTYPE == 0 || LOOPTYPE == 1)
603601               {
604                  srcdata = *(blitter_get_addr(space.machine(), blitter.source.addr & 0xfffff));
602                  srcdata = *(blitter_get_addr( blitter.source.addr & 0xfffff));
605603                  cycles_used++;
606604
607605                  if (blitter.modectl & MODE_SSIGN)
r21026r21027
616614            /* Read destination pixel? */
617615            if (LOOPTYPE == 0)
618616            {
619               dstdata = *blitter_get_addr(space.machine(), blitter.dest.addr & 0xfffff);
617               dstdata = *blitter_get_addr( blitter.dest.addr & 0xfffff);
620618               cycles_used++;
621619            }
622620
r21026r21027
685683                      The existing destination pixel is used as a lookup
686684                      into the table and the colours is replaced.
687685                  */
688                  UINT8 dest = *blitter_get_addr(space.machine(), blitter.dest.addr);
689                  UINT8 newcol = *(blitter_get_addr(space.machine(), (blitter.source.addr + dest) & 0xfffff));
686                  UINT8 dest = *blitter_get_addr( blitter.dest.addr);
687                  UINT8 newcol = *(blitter_get_addr( (blitter.source.addr + dest) & 0xfffff));
690688
691                  *blitter_get_addr(space.machine(), blitter.dest.addr) = newcol;
689                  *blitter_get_addr( blitter.dest.addr) = newcol;
692690                  cycles_used += 3;
693691               }
694692               else
r21026r21027
707705                  if (blitter.compfunc & CMPFUNC_LOG0)
708706                     final_result |= ~result & ~dstdata;
709707
710                  *blitter_get_addr(space.machine(), blitter.dest.addr) = final_result;
708                  *blitter_get_addr( blitter.dest.addr) = final_result;
711709                  cycles_used++;
712710               }
713711            }
r21026r21027
956954
957955         data &= 0x3f;
958956         m_bank_data[offset] = data;
959         z80_bank(machine(), offset, data);
957         z80_bank(offset, data);
960958         break;
961959      }
962960
r21026r21027
10311029   }
10321030}
10331031
1034INLINE void z80_bank(running_machine &machine, int num, int data)
1032void bfcobra_state::z80_bank(int num, int data)
10351033{
1036   bfcobra_state *state = machine.driver_data<bfcobra_state>();
10371034   static const char * const bank_names[] = { "bank1", "bank2", "bank3" };
10381035
10391036   if (data < 0x08)
10401037   {
1041      UINT32 offset = ((state->m_bank_data[0] >> 1) * 0x20000) + ((0x4000 * data) ^ ((state->m_bank_data[0] & 1) ? 0 : 0x10000));
1038      UINT32 offset = ((m_bank_data[0] >> 1) * 0x20000) + ((0x4000 * data) ^ ((m_bank_data[0] & 1) ? 0 : 0x10000));
10421039
1043      state->membank(bank_names[num - 1])->set_base(machine.root_device().memregion("user1")->base() + offset);
1040      membank(bank_names[num - 1])->set_base(machine().root_device().memregion("user1")->base() + offset);
10441041   }
10451042   else if (data < 0x10)
10461043   {
1047      state->membank(bank_names[num - 1])->set_base(&state->m_video_ram[(data - 0x08) * 0x4000]);
1044      membank(bank_names[num - 1])->set_base(&m_video_ram[(data - 0x08) * 0x4000]);
10481045   }
10491046   else
10501047   {
1051      state->membank(bank_names[num - 1])->set_base(&state->m_work_ram[(data - 0x10) * 0x4000]);
1048      membank(bank_names[num - 1])->set_base(&m_work_ram[(data - 0x10) * 0x4000]);
10521049   }
10531050}
10541051
10551052WRITE8_MEMBER(bfcobra_state::rombank_w)
10561053{
10571054   m_bank_data[0] = data;
1058   z80_bank(machine(), 1, m_bank_data[1]);
1059   z80_bank(machine(), 2, m_bank_data[2]);
1060   z80_bank(machine(), 3, m_bank_data[3]);
1055   z80_bank(1, m_bank_data[1]);
1056   z80_bank(2, m_bank_data[2]);
1057   z80_bank(3, m_bank_data[3]);
10611058}
10621059
10631060
r21026r21027
12971294}
12981295
12991296#ifdef UNUSED_FUNCTION
1300UINT8 exec_r_phase(void)
1297UINT8 bfcobra_state::exec_r_phase(void)
13011298{
13021299   return 0;
13031300}
r21026r21027
13081305}
13091306
13101307#ifdef UNUSED_FUNCTION
1311UINT8 results_phase(void)
1308UINT8 bfcobra_state::results_phase(void)
13121309{
13131310   return 0;
13141311}
trunk/src/mame/drivers/m63.c
r21026r21027
186186   UINT32 screen_update_m63(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
187187   INTERRUPT_GEN_MEMBER(snd_irq);
188188   INTERRUPT_GEN_MEMBER(vblank_irq);
189   void draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect );
189190};
190191
191192
r21026r21027
313314   m_fg_tilemap->set_transparent_pen(0);
314315}
315316
316static void draw_sprites( running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect )
317void m63_state::draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect )
317318{
318   m63_state *state = machine.driver_data<m63_state>();
319319   int offs;
320320
321   for (offs = 0; offs < state->m_spriteram.bytes(); offs += 4)
321   for (offs = 0; offs < m_spriteram.bytes(); offs += 4)
322322   {
323      int code = state->m_spriteram[offs + 1] | ((state->m_spriteram[offs + 2] & 0x10) << 4);
324      int color = (state->m_spriteram[offs + 2] & 0x0f) + (state->m_pal_bank << 4);
325      int flipx = state->m_spriteram[offs + 2] & 0x20;
323      int code = m_spriteram[offs + 1] | ((m_spriteram[offs + 2] & 0x10) << 4);
324      int color = (m_spriteram[offs + 2] & 0x0f) + (m_pal_bank << 4);
325      int flipx = m_spriteram[offs + 2] & 0x20;
326326      int flipy = 0;
327      int sx = state->m_spriteram[offs + 3];
328      int sy = state->m_sy_offset - state->m_spriteram[offs];
327      int sx = m_spriteram[offs + 3];
328      int sy = m_sy_offset - m_spriteram[offs];
329329
330      if (state->flip_screen())
330      if (flip_screen())
331331      {
332332         sx = 240 - sx;
333         sy = state->m_sy_offset - sy;
333         sy = m_sy_offset - sy;
334334         flipx = !flipx;
335335         flipy = !flipy;
336336      }
337337
338338      drawgfx_transpen(bitmap, cliprect,
339         machine.gfx[2],
339         machine().gfx[2],
340340         code, color,
341341         flipx, flipy,
342342         sx, sy, 0);
r21026r21027
345345      if (sx > 0xf0)
346346      {
347347         drawgfx_transpen(bitmap, cliprect,
348         machine.gfx[2],
348         machine().gfx[2],
349349         code, color,
350350         flipx, flipy,
351351         sx - 0x100, sy, 0);
r21026r21027
362362      m_bg_tilemap->set_scrolly(col, m_scrollram[col * 8]);
363363
364364   m_bg_tilemap->draw(bitmap, cliprect, 0, 0);
365   draw_sprites(machine(), bitmap, cliprect);
365   draw_sprites(bitmap, cliprect);
366366   m_fg_tilemap->draw(bitmap, cliprect, 0, 0);
367367   return 0;
368368}
trunk/src/mame/drivers/bfm_sc1.c
r21026r21027
181181   virtual void machine_reset();
182182   INTERRUPT_GEN_MEMBER(timer_irq);
183183   void sc1_common_init(int reels, int decrypt, int defaultbank);
184   void Scorpion1_SetSwitchState(int strobe, int data, int state);
185   int Scorpion1_GetSwitchState(int strobe, int data);
186   int sc1_find_project_string( );
184187};
185188
186189#define VFD_RESET  0x20
r21026r21027
192195
193196///////////////////////////////////////////////////////////////////////////
194197
195static void Scorpion1_SetSwitchState(bfm_sc1_state *drvstate, int strobe, int data, int state)
198void bfm_sc1_state::Scorpion1_SetSwitchState(int strobe, int data, int state)
196199{
197   if ( state ) drvstate->m_sc1_Inputs[strobe] |=  (1<<data);
198   else         drvstate->m_sc1_Inputs[strobe] &= ~(1<<data);
200   if ( state ) m_sc1_Inputs[strobe] |=  (1<<data);
201   else         m_sc1_Inputs[strobe] &= ~(1<<data);
199202}
200203
201204///////////////////////////////////////////////////////////////////////////
202205#ifdef UNUSED_FUNCTION
203static int Scorpion1_GetSwitchState(bfm_sc1_state *drvstate, int strobe, int data)
206int bfm_sc1_state::Scorpion1_GetSwitchState(int strobe, int data)
204207{
205208   int state = 0;
206209
207   if ( strobe < 7 && data < 8 ) state = (drvstate->sc1_Inputs[strobe] & (1<<data))?1:0;
210   if ( strobe < 7 && data < 8 ) state = (sc1_Inputs[strobe] & (1<<data))?1:0;
208211
209212   return state;
210213}
r21026r21027
11711174}
11721175
11731176
1174int sc1_find_project_string(running_machine &machine )
1177int bfm_sc1_state::sc1_find_project_string( )
11751178{
11761179   // search for the project string to find the title (usually just at ff00)
11771180   char title_string[7][32] = { "PROJECT NUMBER", "PROJECT PR", "PROJECT ", "CASH ON THE NILE 2", "PR6121", "CHINA TOWN\x0d\x0a", "PROJECTNUMBER" };
1178   UINT8 *src = machine.root_device().memregion( "maincpu" )->base();
1179   int size = machine.root_device().memregion( "maincpu" )->bytes();
1181   UINT8 *src = machine().root_device().memregion( "maincpu" )->base();
1182   int size = machine().root_device().memregion( "maincpu" )->bytes();
11801183
11811184   for (int search=0;search<7;search++)
11821185   {
r21026r21027
12521255   sc1_common_init(3,1, 3);
12531256   adder2_decode_char_roms(machine()); // decode GFX roms
12541257   MechMtr_config(machine(),8);
1255   sc1_find_project_string(machine());
1258   sc1_find_project_string();
12561259}
12571260
12581261DRIVER_INIT_MEMBER(bfm_sc1_state,lotse)
12591262{
12601263   sc1_common_init(6,1, 3);
12611264   MechMtr_config(machine(),8);
1262   sc1_find_project_string(machine());
1265   sc1_find_project_string();
12631266}
12641267
12651268DRIVER_INIT_MEMBER(bfm_sc1_state,lotse_bank0)
12661269{
12671270   sc1_common_init(6,1, 0);
12681271   MechMtr_config(machine(),8);
1269   sc1_find_project_string(machine());
1272   sc1_find_project_string();
12701273}
12711274
12721275
r21026r21027
12741277{
12751278   sc1_common_init(6,0, 3);
12761279   MechMtr_config(machine(),8);
1277   sc1_find_project_string(machine());
1280   sc1_find_project_string();
12781281}
12791282
12801283DRIVER_INIT_MEMBER(bfm_sc1_state,nocrypt_bank0)
12811284{
12821285   sc1_common_init(6,0, 0);
12831286   MechMtr_config(machine(),8);
1284   sc1_find_project_string(machine());
1287   sc1_find_project_string();
12851288}
12861289
12871290
r21026r21027
12911294{
12921295   sc1_common_init(6,0, 3);
12931296   MechMtr_config(machine(),8);
1294   sc1_find_project_string(machine());
1297   sc1_find_project_string();
12951298}
12961299
12971300/////////////////////////////////////////////////////////////////////////////////////
r21026r21027
13011304   sc1_common_init(6,1, 3);
13021305   MechMtr_config(machine(),8);
13031306
1304   Scorpion1_SetSwitchState(this,3,2,1);
1305   Scorpion1_SetSwitchState(this,3,3,1);
1306   Scorpion1_SetSwitchState(this,3,6,1);
1307   Scorpion1_SetSwitchState(this,4,1,1);
1308   sc1_find_project_string(machine());
1307   Scorpion1_SetSwitchState(3,2,1);
1308   Scorpion1_SetSwitchState(3,3,1);
1309   Scorpion1_SetSwitchState(3,6,1);
1310   Scorpion1_SetSwitchState(4,1,1);
1311   sc1_find_project_string();
13091312}
13101313
13111314
trunk/src/mame/drivers/cops.c
r21026r21027
8888
8989   void laserdisc_w(UINT8 data);
9090   void laserdisc_response_w(UINT8 data);
91   DECLARE_PALETTE_INIT( cops );
9192};
9293
9394void cops_state::video_start()
r21026r21027
617618}
618619
619620
620static PALETTE_INIT( cops )
621PALETTE_INIT_MEMBER( cops_state,cops )
621622{
622623}
623624
r21026r21027
635636   MCFG_SCREEN_SIZE(32*8, 32*8)
636637   MCFG_SCREEN_VISIBLE_AREA(0*8, 32*8-1, 2*8, 30*8-1)
637638
638   MCFG_PALETTE_INIT(cops)
639   MCFG_PALETTE_INIT_OVERRIDE(cops_state,cops)
639640   MCFG_PALETTE_LENGTH(8)
640641
641642   /* via */
trunk/src/mame/drivers/mediagx.c
r21026r21027
200200   DECLARE_READ32_MEMBER(speedup11_r);
201201   TIMER_DEVICE_CALLBACK_MEMBER(sound_timer_callback);
202202   IRQ_CALLBACK_MEMBER(irq_callback);
203   void draw_char(bitmap_rgb32 &bitmap, const rectangle &cliprect, gfx_element *gfx, int ch, int att, int x, int y);
204   void draw_framebuffer(bitmap_rgb32 &bitmap, const rectangle &cliprect);
205   void draw_cga(bitmap_rgb32 &bitmap, const rectangle &cliprect);
206   void ad1847_reg_write(int reg, UINT8 data);
207   inline UINT32 generic_speedup(address_space &space, int idx);
208   void report_speedups();
209   void install_speedups(const speedup_entry *entries, int count);
210   void init_mediagx();
203211};
204212
205213// Display controller registers
r21026r21027
252260   }
253261}
254262
255static void draw_char(bitmap_rgb32 &bitmap, const rectangle &cliprect, gfx_element *gfx, int ch, int att, int x, int y)
263void mediagx_state::draw_char(bitmap_rgb32 &bitmap, const rectangle &cliprect, gfx_element *gfx, int ch, int att, int x, int y)
256264{
257265   int i,j;
258266   const UINT8 *dp;
r21026r21027
278286   }
279287}
280288
281static void draw_framebuffer(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect)
289void mediagx_state::draw_framebuffer(bitmap_rgb32 &bitmap, const rectangle &cliprect)
282290{
283   mediagx_state *state = machine.driver_data<mediagx_state>();
284291   int i, j;
285292   int width, height;
286   int line_delta = (state->m_disp_ctrl_reg[DC_LINE_DELTA] & 0x3ff) * 4;
293   int line_delta = (m_disp_ctrl_reg[DC_LINE_DELTA] & 0x3ff) * 4;
287294
288   width = (state->m_disp_ctrl_reg[DC_H_TIMING_1] & 0x7ff) + 1;
289   if (state->m_disp_ctrl_reg[DC_TIMING_CFG] & 0x8000)     // pixel double
295   width = (m_disp_ctrl_reg[DC_H_TIMING_1] & 0x7ff) + 1;
296   if (m_disp_ctrl_reg[DC_TIMING_CFG] & 0x8000)     // pixel double
290297   {
291298      width >>= 1;
292299   }
293300   width += 4;
294301
295   height = (state->m_disp_ctrl_reg[DC_V_TIMING_1] & 0x7ff) + 1;
302   height = (m_disp_ctrl_reg[DC_V_TIMING_1] & 0x7ff) + 1;
296303
297   if ( (width != state->m_frame_width || height != state->m_frame_height) &&
304   if ( (width != m_frame_width || height != m_frame_height) &&
298305         (width > 1 && height > 1 && width <= 640 && height <= 480) )
299306   {
300307      rectangle visarea;
301308
302      state->m_frame_width = width;
303      state->m_frame_height = height;
309      m_frame_width = width;
310      m_frame_height = height;
304311
305312      visarea.set(0, width - 1, 0, height - 1);
306      machine.primary_screen->configure(width, height * 262 / 240, visarea, machine.primary_screen->frame_period().attoseconds);
313      machine().primary_screen->configure(width, height * 262 / 240, visarea, machine().primary_screen->frame_period().attoseconds);
307314   }
308315
309   if (state->m_disp_ctrl_reg[DC_OUTPUT_CFG] & 0x1)        // 8-bit mode
316   if (m_disp_ctrl_reg[DC_OUTPUT_CFG] & 0x1)        // 8-bit mode
310317   {
311      UINT8 *framebuf = (UINT8*)&state->m_vram[state->m_disp_ctrl_reg[DC_FB_ST_OFFSET]/4];
312      UINT8 *pal = state->m_pal;
318      UINT8 *framebuf = (UINT8*)&m_vram[m_disp_ctrl_reg[DC_FB_ST_OFFSET]/4];
319      UINT8 *pal = m_pal;
313320
314      for (j=0; j < state->m_frame_height; j++)
321      for (j=0; j < m_frame_height; j++)
315322      {
316323         UINT32 *p = &bitmap.pix32(j);
317324         UINT8 *si = &framebuf[j * line_delta];
318         for (i=0; i < state->m_frame_width; i++)
325         for (i=0; i < m_frame_width; i++)
319326         {
320327            int c = *si++;
321328            int r = pal[(c*3)+0] << 2;
r21026r21027
328335   }
329336   else            // 16-bit
330337   {
331      UINT16 *framebuf = (UINT16*)&state->m_vram[state->m_disp_ctrl_reg[DC_FB_ST_OFFSET]/4];
338      UINT16 *framebuf = (UINT16*)&m_vram[m_disp_ctrl_reg[DC_FB_ST_OFFSET]/4];
332339
333340      // RGB 5-6-5 mode
334      if ((state->m_disp_ctrl_reg[DC_OUTPUT_CFG] & 0x2) == 0)
341      if ((m_disp_ctrl_reg[DC_OUTPUT_CFG] & 0x2) == 0)
335342      {
336         for (j=0; j < state->m_frame_height; j++)
343         for (j=0; j < m_frame_height; j++)
337344         {
338345            UINT32 *p = &bitmap.pix32(j);
339346            UINT16 *si = &framebuf[j * (line_delta/2)];
340            for (i=0; i < state->m_frame_width; i++)
347            for (i=0; i < m_frame_width; i++)
341348            {
342349               UINT16 c = *si++;
343350               int r = ((c >> 11) & 0x1f) << 3;
r21026r21027
351358      // RGB 5-5-5 mode
352359      else
353360      {
354         for (j=0; j < state->m_frame_height; j++)
361         for (j=0; j < m_frame_height; j++)
355362         {
356363            UINT32 *p = &bitmap.pix32(j);
357364            UINT16 *si = &framebuf[j * (line_delta/2)];
358            for (i=0; i < state->m_frame_width; i++)
365            for (i=0; i < m_frame_width; i++)
359366            {
360367               UINT16 c = *si++;
361368               int r = ((c >> 10) & 0x1f) << 3;
r21026r21027
369376   }
370377}
371378
372static void draw_cga(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect)
379void mediagx_state::draw_cga(bitmap_rgb32 &bitmap, const rectangle &cliprect)
373380{
374   mediagx_state *state = machine.driver_data<mediagx_state>();
375381   int i, j;
376   gfx_element *gfx = machine.gfx[0];
377   UINT32 *cga = state->m_cga_ram;
382   gfx_element *gfx = machine().gfx[0];
383   UINT32 *cga = m_cga_ram;
378384   int index = 0;
379385
380386   for (j=0; j < 25; j++)
r21026r21027
397403{
398404   bitmap.fill(0, cliprect);
399405
400   draw_framebuffer(machine(), bitmap, cliprect);
406   draw_framebuffer( bitmap, cliprect);
401407
402408   if (m_disp_ctrl_reg[DC_OUTPUT_CFG] & 0x1)   // don't show MDA text screen on 16-bit mode. this is basically a hack
403409   {
404      draw_cga(machine(), bitmap, cliprect);
410      draw_cga(bitmap, cliprect);
405411   }
406412   return 0;
407413}
r21026r21027
749755   m_dacr_ptr = 0;
750756}
751757
752static void ad1847_reg_write(running_machine &machine, int reg, UINT8 data)
758void mediagx_state::ad1847_reg_write(int reg, UINT8 data)
753759{
754   mediagx_state *state = machine.driver_data<mediagx_state>();
755760   static const int divide_factor[] = { 3072, 1536, 896, 768, 448, 384, 512, 2560 };
756761
757762   switch (reg)
r21026r21027
760765      {
761766         if (data & 0x1)
762767         {
763            state->m_ad1847_sample_rate = 16934400 / divide_factor[(data >> 1) & 0x7];
768            m_ad1847_sample_rate = 16934400 / divide_factor[(data >> 1) & 0x7];
764769         }
765770         else
766771         {
767            state->m_ad1847_sample_rate = 24576000 / divide_factor[(data >> 1) & 0x7];
772            m_ad1847_sample_rate = 24576000 / divide_factor[(data >> 1) & 0x7];
768773         }
769774
770         dmadac_set_frequency(&state->m_dmadac[0], 2, state->m_ad1847_sample_rate);
775         dmadac_set_frequency(&m_dmadac[0], 2, m_ad1847_sample_rate);
771776
772777         if (data & 0x20)
773778         {
r21026r21027
782787
783788      default:
784789      {
785         state->m_ad1847_regs[reg] = data;
790         m_ad1847_regs[reg] = data;
786791         break;
787792      }
788793   }
r21026r21027
818823   else if (offset == 3)
819824   {
820825      int reg = (data >> 8) & 0xf;
821      ad1847_reg_write(machine(), reg, data & 0xff);
826      ad1847_reg_write(reg, data & 0xff);
822827   }
823828}
824829
r21026r21027
12331238   pic8259_ir1_w(state->m_pic8259_1, _state);
12341239}
12351240
1236static void init_mediagx(running_machine &machine)
1241void mediagx_state::init_mediagx()
12371242{
1238   mediagx_state *state = machine.driver_data<mediagx_state>();
1243   m_frame_width = m_frame_height = 1;
12391244
1240   state->m_frame_width = state->m_frame_height = 1;
1245   init_pc_common(machine(), PCCOMMON_KEYBOARD_AT,mediagx_set_keyb_int);
12411246
1242   init_pc_common(machine, PCCOMMON_KEYBOARD_AT,mediagx_set_keyb_int);
1243
1244   kbdc8042_init(machine, &at8042);
1247   kbdc8042_init(machine(), &at8042);
12451248}
12461249
12471250#if SPEEDUP_HACKS
12481251
1249INLINE UINT32 generic_speedup(address_space &space, int idx)
1252UINT32 mediagx_state::generic_speedup(address_space &space, int idx)
12501253{
1251   mediagx_state *state = space.machine().driver_data<mediagx_state>();
1252
1253   if (space.device().safe_pc() == state->m_speedup_table[idx].pc)
1254   if (space.device().safe_pc() == m_speedup_table[idx].pc)
12541255   {
1255      state->m_speedup_hits[idx]++;
1256      m_speedup_hits[idx]++;
12561257      space.device().execute().spin_until_interrupt();
12571258   }
1258   return state->m_main_ram[state->m_speedup_table[idx].offset/4];
1259   return m_main_ram[m_speedup_table[idx].offset/4];
12591260}
12601261
12611262READ32_MEMBER(mediagx_state::speedup0_r) { return generic_speedup(space, 0); }
r21026r21027
12791280};
12801281
12811282#ifdef MAME_DEBUG
1282static void report_speedups(running_machine &machine)
1283void mediagx_state::report_speedups()
12831284{
1284   mediagx_state *state = machine.driver_data<mediagx_state>();
12851285   int i;
12861286
1287   for (i = 0; i < state->m_speedup_count; i++)
1288      printf("Speedup %2d: offs=%06X pc=%06X hits=%d\n", i, state->m_speedup_table[i].offset, state->m_speedup_table[i].pc, state->m_speedup_hits[i]);
1287   for (i = 0; i < m_speedup_count; i++)
1288      printf("Speedup %2d: offs=%06X pc=%06X hits=%d\n", i, m_speedup_table[i].offset, m_speedup_table[i].pc, m_speedup_hits[i]);
12891289}
12901290#endif
12911291
1292static void install_speedups(running_machine &machine, const speedup_entry *entries, int count)
1292void mediagx_state::install_speedups(const speedup_entry *entries, int count)
12931293{
1294   mediagx_state *state = machine.driver_data<mediagx_state>();
12951294   int i;
12961295
12971296   assert(count < ARRAY_LENGTH(speedup_handlers));
12981297
1299   state->m_speedup_table = entries;
1300   state->m_speedup_count = count;
1298   m_speedup_table = entries;
1299   m_speedup_count = count;
13011300
13021301   for (i = 0; i < count; i++) {
13031302      read32_delegate func = speedup_handlers[i].func;
1304      func.late_bind(*state);
1305      machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(entries[i].offset, entries[i].offset + 3, func);
1303      func.late_bind(*this);
1304      machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(entries[i].offset, entries[i].offset + 3, func);
13061305   }
13071306
13081307#ifdef MAME_DEBUG
1309   machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(report_speedups), &machine));
1308   machine().add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(report_speedups), &machine));
13101309#endif
13111310}
13121311
r21026r21027
13281327
13291328DRIVER_INIT_MEMBER(mediagx_state,a51site4)
13301329{
1331   init_mediagx(machine());
1330   init_mediagx();
13321331
13331332#if SPEEDUP_HACKS
1334   install_speedups(machine(), a51site4_speedups, ARRAY_LENGTH(a51site4_speedups));
1333   install_speedups(a51site4_speedups, ARRAY_LENGTH(a51site4_speedups));
13351334#endif
13361335}
13371336
trunk/src/mame/drivers/firebeat.c
r21026r21027
239239   DECLARE_WRITE32_MEMBER(ppc_spu_share_w);
240240   DECLARE_READ16_MEMBER(spu_unk_r);
241241   TIMER_CALLBACK_MEMBER(keyboard_timer_callback);
242   void gcu_draw_object(bitmap_ind16 &bitmap, const rectangle &cliprect, int chip, UINT32 *cmd);
243   void gcu_fill_rect(bitmap_ind16 &bitmap, const rectangle &cliprect, UINT32 *cmd);
244   void gcu_draw_character(bitmap_ind16 &bitmap, const rectangle &cliprect, int chip, UINT32 *cmd);
245   void gcu_exec_display_list(bitmap_ind16 &bitmap, const rectangle &cliprect, int chip, UINT32 address);
246   UINT32 update_screen(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int chip);
247   UINT32 GCU_r(int chip, UINT32 offset, UINT32 mem_mask);
248   void GCU_w(int chip, UINT32 offset, UINT32 data, UINT32 mem_mask);
249   void atapi_cause_irq();
250   void atapi_clear_irq();
251   void atapi_init();
252   void atapi_reset();
253   UINT16 atapi_command_reg_r(int reg);
254   void atapi_command_reg_w(int reg, UINT16 data);
255   UINT16 atapi_control_reg_r(int reg);
256   void atapi_control_reg_w(int reg, UINT16 data);
257   void set_ibutton(UINT8 *data);
258   int ibutton_w(UINT8 data);
259   void init_lights(write32_delegate out1, write32_delegate out2, write32_delegate out3);
260   void init_firebeat();
261   void init_keyboard();
242262};
243263
244264
r21026r21027
255275}
256276
257277
258static void gcu_draw_object(running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect, int chip, UINT32 *cmd)
278void firebeat_state::gcu_draw_object(bitmap_ind16 &bitmap, const rectangle &cliprect, int chip, UINT32 *cmd)
259279{
260   firebeat_state *state = machine.driver_data<firebeat_state>();
261280   // 0x00: xxx----- -------- -------- --------   command type
262281   // 0x00: -------- xxxxxxxx xxxxxxxx xxxxxxxx   object data address in vram
263282
r21026r21027
287306
288307   int i, j;
289308   int u, v;
290   UINT16 *vr = (UINT16*)state->m_gcu[chip].vram;
309   UINT16 *vr = (UINT16*)m_gcu[chip].vram;
291310
292311   if (xscale == 0 || yscale == 0)
293312   {
r21026r21027
409428   }
410429}
411430
412static void gcu_fill_rect(bitmap_ind16 &bitmap, const rectangle &cliprect, UINT32 *cmd)
431void firebeat_state::gcu_fill_rect(bitmap_ind16 &bitmap, const rectangle &cliprect, UINT32 *cmd)
413432{
414433   int i, j;
415434   int x1, y1, x2, y2;
r21026r21027
456475   }
457476}
458477
459static void gcu_draw_character(running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect, int chip, UINT32 *cmd)
478void firebeat_state::gcu_draw_character(bitmap_ind16 &bitmap, const rectangle &cliprect, int chip, UINT32 *cmd)
460479{
461   firebeat_state *state = machine.driver_data<firebeat_state>();
462480   // 0x00: xxx----- -------- -------- --------   command type
463481   // 0x00: -------- xxxxxxxx xxxxxxxx xxxxxxxx   character data address in vram
464482
r21026r21027
477495   UINT32 address      = cmd[0] & 0xffffff;
478496   UINT16 color[4];
479497
480   UINT16 *vr = (UINT16*)state->m_gcu[chip].vram;
498   UINT16 *vr = (UINT16*)m_gcu[chip].vram;
481499
482500   color[0] = (cmd[2] >> 16) & 0xffff;
483501   color[1] = (cmd[2] >>  0) & 0xffff;
r21026r21027
505523   }
506524}
507525
508static void gcu_exec_display_list(running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect, int chip, UINT32 address)
526void firebeat_state::gcu_exec_display_list(bitmap_ind16 &bitmap, const rectangle &cliprect, int chip, UINT32 address)
509527{
510   firebeat_state *state = machine.driver_data<firebeat_state>();
511528   int counter = 0;
512529   int end = 0;
513530
r21026r21027
517534   {
518535      int command;
519536      UINT32 cmd[4];
520      cmd[0] = state->m_gcu[chip].vram[i+0];
521      cmd[1] = state->m_gcu[chip].vram[i+1];
522      cmd[2] = state->m_gcu[chip].vram[i+2];
523      cmd[3] = state->m_gcu[chip].vram[i+3];
537      cmd[0] = m_gcu[chip].vram[i+0];
538      cmd[1] = m_gcu[chip].vram[i+1];
539      cmd[2] = m_gcu[chip].vram[i+2];
540      cmd[3] = m_gcu[chip].vram[i+3];
524541
525542      command = (cmd[0] >> 29) & 0x7;
526543
r21026r21027
533550
534551         case 0x1:       // Branch
535552         {
536            gcu_exec_display_list(machine, bitmap, cliprect, chip, cmd[0] & 0xffffff);
553            gcu_exec_display_list(bitmap, cliprect, chip, cmd[0] & 0xffffff);
537554            break;
538555         }
539556
r21026r21027
556573
557574         case 0x5:       // Draw object
558575         {
559            gcu_draw_object(machine, bitmap, cliprect, chip, cmd);
576            gcu_draw_object(bitmap, cliprect, chip, cmd);
560577            break;
561578         }
562579
563580         case 0x7:       // Draw 8x8 Character (2-bits per pixel)
564581         {
565            gcu_draw_character(machine, bitmap, cliprect, chip, cmd);
582            gcu_draw_character(bitmap, cliprect, chip, cmd);
566583            break;
567584         }
568585
r21026r21027
576593   };
577594}
578595
579static UINT32 update_screen(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int chip)
596UINT32 firebeat_state::update_screen(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int chip)
580597{
581   firebeat_state *state = screen.machine().driver_data<firebeat_state>();
582
583598   bitmap.fill(0, cliprect);
584599
585600   if ((mame_strnicmp(screen.machine().system().name, "popn", 4) == 0) || (mame_strnicmp(screen.machine().system().name, "bm3", 3) == 0))
586601   {
587      gcu_exec_display_list(screen.machine(), bitmap, cliprect, chip, 0x1f80000);
602      gcu_exec_display_list( bitmap, cliprect, chip, 0x1f80000);
588603   }
589604   else
590605   {
591      if (state->m_layer >= 2)
606      if (m_layer >= 2)
592607      {
593         gcu_exec_display_list(screen.machine(), bitmap, cliprect, chip, 0x8000);
594         gcu_exec_display_list(screen.machine(), bitmap, cliprect, chip, 0x0000);
595         gcu_exec_display_list(screen.machine(), bitmap, cliprect, chip, 0x10000);
608         gcu_exec_display_list(bitmap, cliprect, chip, 0x8000);
609         gcu_exec_display_list(bitmap, cliprect, chip, 0x0000);
610         gcu_exec_display_list(bitmap, cliprect, chip, 0x10000);
596611      }
597      else if (state->m_layer == 0)
612      else if (m_layer == 0)
598613      {
599         gcu_exec_display_list(screen.machine(), bitmap, cliprect, chip, 0x200000);
614         gcu_exec_display_list(bitmap, cliprect, chip, 0x200000);
600615
601         //gcu_exec_display_list(screen.machine(), bitmap, cliprect, chip, 0x186040);
616         //gcu_exec_display_list(bitmap, cliprect, chip, 0x186040);
602617      }
603      else if (state->m_layer == 1)
618      else if (m_layer == 1)
604619      {
605         gcu_exec_display_list(screen.machine(), bitmap, cliprect, chip, 0x1d0800);
620         gcu_exec_display_list(bitmap, cliprect, chip, 0x1d0800);
606621
607         gcu_exec_display_list(screen.machine(), bitmap, cliprect, chip, 0x1a9440);
622         gcu_exec_display_list(bitmap, cliprect, chip, 0x1a9440);
608623      }
609624   }
610625
611   state->m_tick++;
612   if (state->m_tick >= 5)
626   m_tick++;
627   if (m_tick >= 5)
613628   {
614      state->m_tick = 0;
629      m_tick = 0;
615630      if (screen.machine().input().code_pressed(KEYCODE_0))
616631      {
617         state->m_layer++;
618         if (state->m_layer > 2)
632         m_layer++;
633         if (m_layer > 2)
619634         {
620            state->m_layer = 0;
635            m_layer = 0;
621636         }
622637      }
623638
r21026r21027
629644
630645          for (i=0; i < 0x2000000/4; i++)
631646          {
632              fputc((state->m_gcu[0].vram[i] >> 24) & 0xff, file);
633              fputc((state->m_gcu[0].vram[i] >> 16) & 0xff, file);
634              fputc((state->m_gcu[0].vram[i] >> 8) & 0xff, file);
635              fputc((state->m_gcu[0].vram[i] >> 0) & 0xff, file);
647              fputc((m_gcu[0].vram[i] >> 24) & 0xff, file);
648              fputc((m_gcu[0].vram[i] >> 16) & 0xff, file);
649              fputc((m_gcu[0].vram[i] >> 8) & 0xff, file);
650              fputc((m_gcu[0].vram[i] >> 0) & 0xff, file);
636651          }
637652
638653          fclose(file);
r21026r21027
640655
641656          for (i=0; i < 0x2000000/4; i++)
642657          {
643              fputc((state->m_gcu[1].vram[i] >> 24) & 0xff, file);
644              fputc((state->m_gcu[1].vram[i] >> 16) & 0xff, file);
645              fputc((state->m_gcu[1].vram[i] >> 8) & 0xff, file);
646              fputc((state->m_gcu[1].vram[i] >> 0) & 0xff, file);
658              fputc((m_gcu[1].vram[i] >> 24) & 0xff, file);
659              fputc((m_gcu[1].vram[i] >> 16) & 0xff, file);
660              fputc((m_gcu[1].vram[i] >> 8) & 0xff, file);
661              fputc((m_gcu[1].vram[i] >> 0) & 0xff, file);
647662          }
648663
649664          fclose(file);
r21026r21027
657672UINT32 firebeat_state::screen_update_firebeat_0(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect){ return update_screen(screen, bitmap, cliprect, 0); }
658673UINT32 firebeat_state::screen_update_firebeat_1(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect){ return update_screen(screen, bitmap, cliprect, 1); }
659674
660static UINT32 GCU_r(running_machine &machine, int chip, UINT32 offset, UINT32 mem_mask)
675UINT32 firebeat_state::GCU_r(int chip, UINT32 offset, UINT32 mem_mask)
661676{
662   firebeat_state *state = machine.driver_data<firebeat_state>();
663677   int reg = offset * 4;
664678
665679   /* VRAM Read */
666680   if (reg >= 0x80 && reg < 0x100)
667681   {
668      return state->m_gcu[chip].vram[state->m_gcu[chip].vram_read_address + ((reg/4) - 0x20)];
682      return m_gcu[chip].vram[m_gcu[chip].vram_read_address + ((reg/4) - 0x20)];
669683   }
670684
671685   switch(reg)
r21026r21027
681695   return 0xffffffff;
682696}
683697
684static void GCU_w(running_machine &machine, int chip, UINT32 offset, UINT32 data, UINT32 mem_mask)
698void firebeat_state::GCU_w(int chip, UINT32 offset, UINT32 data, UINT32 mem_mask)
685699{
686   firebeat_state *state = machine.driver_data<firebeat_state>();
687700   int reg = offset * 4;
688701
689702   if (reg != 0x70 && chip == 0)
690703   {
691      //printf("%s:gcu%d_w: %08X, %08X, %08X at %08X\n", machine.describe_context(), chip, data, offset, mem_mask);
704      //printf("%s:gcu%d_w: %08X, %08X, %08X at %08X\n", machine().describe_context(), chip, data, offset, mem_mask);
692705      //logerror("%s:gcu%d_w: %08X, %08X, %08X at %08X\n", cmachine->describe_context(), hip, data, offset, mem_mask);
693706   }
694707
r21026r21027
698711         /* IRQ clear/enable; ppd writes bit off then on in response to interrupt */
699712         /* it enables bits 0x41, but 0x01 seems to be the one it cares about */
700713         if (ACCESSING_BITS_16_31 && (data & 0x0001) == 0)
701            machine.device("maincpu")->execute().set_input_line(INPUT_LINE_IRQ0, CLEAR_LINE);
714            machine().device("maincpu")->execute().set_input_line(INPUT_LINE_IRQ0, CLEAR_LINE);
702715         break;
703716
704717      case 0x30:
r21026r21027
706719      //case 0x38:
707720      //case 0x3c:
708721      {
709         COMBINE_DATA( &state->m_gcu[chip].visible_area );
722         COMBINE_DATA( &m_gcu[chip].visible_area );
710723         if (ACCESSING_BITS_0_15)
711724         {
712            screen_device_iterator iter(machine.root_device());
725            screen_device_iterator iter(machine().root_device());
713726            screen_device *screen = iter.byindex(chip);
714727
715728            if (screen != NULL)
r21026r21027
717730               rectangle visarea = screen->visible_area();
718731               int width, height;
719732
720               width = (state->m_gcu[chip].visible_area & 0xffff);
721               height = (state->m_gcu[chip].visible_area >> 16) & 0xffff;
733               width = (m_gcu[chip].visible_area & 0xffff);
734               height = (m_gcu[chip].visible_area >> 16) & 0xffff;
722735
723736               visarea.max_x = width-1;
724737               visarea.max_y = height-1;
r21026r21027
732745      case 0x40:      /* framebuffer config */
733746         // HACK: switch display lists at the right times for the ParaParaParadise games until we
734747         // do the video emulation properly
735         if (mame_strnicmp(machine.system().name, "pp", 2) == 0)
748         if (mame_strnicmp(machine().system().name, "pp", 2) == 0)
736749         {
737750            switch (data)
738751            {
739752               case 0x00080000:    // post
740                  state->m_layer = 0;
753                  m_layer = 0;
741754                  break;
742755
743756               case 0x00008400:    // startup tests
744                  if (state->m_layer != 2)
757                  if (m_layer != 2)
745758                  {
746                     state->m_layer = 1;
759                     m_layer = 1;
747760                  }
748761                  break;
749762
750763               case 0x00068400:    // game & svc menu
751                  state->m_layer = 2;
764                  m_layer = 2;
752765                  break;
753766            }
754767         }
755         else if (mame_strnicmp(machine.system().name, "kbm", 3) == 0)
768         else if (mame_strnicmp(machine().system().name, "kbm", 3) == 0)
756769         {
757770            switch (data)
758771            {
759772               case 0x00080000:    // post
760                  state->m_layer = 0;
773                  m_layer = 0;
761774                  break;
762775
763776               case 0x0000c400:    // game & svn menu
764                  state->m_layer = 2;
777                  m_layer = 2;
765778                  break;
766779            }
767780         }
r21026r21027
771784      //  break;
772785
773786      case 0x5c:      /* VRAM Read Address */
774         state->m_gcu[chip].vram_read_address = (data & 0xffffff) / 2;
787         m_gcu[chip].vram_read_address = (data & 0xffffff) / 2;
775788         break;
776789
777790      case 0x60:      /* VRAM FIFO Write Address */
778         state->m_gcu[chip].vram_write_fifo_address = (data & 0xffffff) / 2;
791         m_gcu[chip].vram_write_fifo_address = (data & 0xffffff) / 2;
779792
780793   //      printf("gcu%d_w: %08X, %08X, %08X\n", chip, data, offset, mem_mask);
781794         break;
r21026r21027
786799      }
787800
788801      case 0x70:      /* VRAM FIFO Write */
789         state->m_gcu[chip].vram[state->m_gcu[chip].vram_write_fifo_address] = data;
790         state->m_gcu[chip].vram_write_fifo_address++;
802         m_gcu[chip].vram[m_gcu[chip].vram_write_fifo_address] = data;
803         m_gcu[chip].vram_write_fifo_address++;
791804         break;
792805
793806      default:
r21026r21027
798811
799812READ32_MEMBER(firebeat_state::gcu0_r)
800813{
801   return GCU_r(space.machine(), 0, offset, mem_mask);
814   return GCU_r(0, offset, mem_mask);
802815}
803816
804817WRITE32_MEMBER(firebeat_state::gcu0_w)
805818{
806   GCU_w(space.machine(), 0, offset, data, mem_mask);
819   GCU_w(0, offset, data, mem_mask);
807820}
808821
809822READ32_MEMBER(firebeat_state::gcu1_r)
810823{
811   return GCU_r(space.machine(), 1, offset, mem_mask);
824   return GCU_r(1, offset, mem_mask);
812825}
813826
814827WRITE32_MEMBER(firebeat_state::gcu1_w)
815828{
816   GCU_w(space.machine(), 1, offset, data, mem_mask);
829   GCU_w(1, offset, data, mem_mask);
817830}
818831
819832/*****************************************************************************/
r21026r21027
824837
825838   if (ACCESSING_BITS_24_31)
826839   {
827      r |= (space.machine().root_device().ioport("IN0")->read() & 0xff) << 24;
840      r |= (machine().root_device().ioport("IN0")->read() & 0xff) << 24;
828841   }
829842   if (ACCESSING_BITS_8_15)
830843   {
831      r |= (space.machine().root_device().ioport("IN1")->read() & 0xff) << 8;
844      r |= (machine().root_device().ioport("IN1")->read() & 0xff) << 8;
832845   }
833846   if (ACCESSING_BITS_0_7)
834847   {
835      r |= (space.machine().root_device().ioport("IN2")->read() & 0xff);
848      r |= (machine().root_device().ioport("IN2")->read() & 0xff);
836849   }
837850
838851   return r;
r21026r21027
842855{
843856   if (offset == 0)
844857   {
845      return space.machine().root_device().ioport("SENSOR1")->read() | 0x01000100;
858      return machine().root_device().ioport("SENSOR1")->read() | 0x01000100;
846859   }
847860   else
848861   {
849      return space.machine().root_device().ioport("SENSOR2")->read() | 0x01000100;
862      return machine().root_device().ioport("SENSOR2")->read() | 0x01000100;
850863   }
851864}
852865
r21026r21027
9941007#define ATAPI_REG_CMDSTATUS 7
9951008
9961009
997static void atapi_cause_irq(running_machine &machine)
1010void firebeat_state::atapi_cause_irq()
9981011{
999   machine.device("maincpu")->execute().set_input_line(INPUT_LINE_IRQ4, ASSERT_LINE);
1012   machine().device("maincpu")->execute().set_input_line(INPUT_LINE_IRQ4, ASSERT_LINE);
10001013}
10011014
1002static void atapi_clear_irq(running_machine &machine)
1015void firebeat_state::atapi_clear_irq()
10031016{
1004   machine.device("maincpu")->execute().set_input_line(INPUT_LINE_IRQ4, CLEAR_LINE);
1017   machine().device("maincpu")->execute().set_input_line(INPUT_LINE_IRQ4, CLEAR_LINE);
10051018}
10061019
1007static void atapi_init(running_machine &machine)
1020void firebeat_state::atapi_init()
10081021{
1009   firebeat_state *state = machine.driver_data<firebeat_state>();
1010   memset(state->m_atapi_regs, 0, sizeof(state->m_atapi_regs));
1022   memset(m_atapi_regs, 0, sizeof(m_atapi_regs));
10111023
1012   state->m_atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
1013   state->m_atapi_regs[ATAPI_REG_ERRFEAT] = 1;
1014   state->m_atapi_regs[ATAPI_REG_COUNTLOW] = 0x14;
1015   state->m_atapi_regs[ATAPI_REG_COUNTHIGH] = 0xeb;
1024   m_atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
1025   m_atapi_regs[ATAPI_REG_ERRFEAT] = 1;
1026   m_atapi_regs[ATAPI_REG_COUNTLOW] = 0x14;
1027   m_atapi_regs[ATAPI_REG_COUNTHIGH] = 0xeb;
10161028
1017   state->m_atapi_data_ptr = 0;
1018   state->m_atapi_cdata_wait = 0;
1029   m_atapi_data_ptr = 0;
1030   m_atapi_cdata_wait = 0;
10191031
1020   state->m_atapi_device_data[0] = machine.device<scsihle_device>( "scsi0" );
1021   state->m_atapi_device_data[1] = machine.device<scsihle_device>( "scsi1" );
1032   m_atapi_device_data[0] = machine().device<scsihle_device>( "scsi0" );
1033   m_atapi_device_data[1] = machine().device<scsihle_device>( "scsi1" );
10221034}
10231035
1024static void atapi_reset(running_machine &machine)
1036void firebeat_state::atapi_reset()
10251037{
1026   firebeat_state *state = machine.driver_data<firebeat_state>();
10271038   logerror("ATAPI reset\n");
10281039
1029   state->m_atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
1030   state->m_atapi_regs[ATAPI_REG_ERRFEAT] = 1;
1031   state->m_atapi_regs[ATAPI_REG_COUNTLOW] = 0x14;
1032   state->m_atapi_regs[ATAPI_REG_COUNTHIGH] = 0xeb;
1040   m_atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
1041   m_atapi_regs[ATAPI_REG_ERRFEAT] = 1;
1042   m_atapi_regs[ATAPI_REG_COUNTLOW] = 0x14;
1043   m_atapi_regs[ATAPI_REG_COUNTHIGH] = 0xeb;
10331044
1034   state->m_atapi_data_ptr = 0;
1035   state->m_atapi_cdata_wait = 0;
1045   m_atapi_data_ptr = 0;
1046   m_atapi_cdata_wait = 0;
10361047}
10371048
10381049
10391050
1040static UINT16 atapi_command_reg_r(running_machine &machine, int reg)
1051UINT16 firebeat_state::atapi_command_reg_r(int reg)
10411052{
1042   firebeat_state *state = machine.driver_data<firebeat_state>();
10431053   int i, data;
10441054
10451055//  printf("ATAPI: Command reg read %d\n", reg);
r21026r21027
10471057   if (reg == ATAPI_REG_DATA)
10481058   {
10491059      // assert IRQ and drop DRQ
1050      if (state->m_atapi_data_ptr == 0)
1060      if (m_atapi_data_ptr == 0)
10511061      {
10521062         //printf("ATAPI: dropping DRQ\n");
1053         atapi_cause_irq(machine);
1054         state->m_atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
1063         atapi_cause_irq();
1064         m_atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
10551065
10561066         // get the data from the device
1057         state->m_atapi_device_data[state->m_atapi_drivesel]->ReadData( state->m_temp_data, state->m_atapi_xferlen );
1067         m_atapi_device_data[m_atapi_drivesel]->ReadData( m_temp_data, m_atapi_xferlen );
10581068
10591069         // fix it up in an endian-safe way
1060         for (i = 0; i < state->m_atapi_xferlen; i += 2)
1070         for (i = 0; i < m_atapi_xferlen; i += 2)
10611071         {
1062            state->m_atapi_data[i/2] = state->m_temp_data[i+0] | state->m_temp_data[i+1]<<8;
1072            m_atapi_data[i/2] = m_temp_data[i+0] | m_temp_data[i+1]<<8;
10631073         }
10641074      }
10651075
1066      data = state->m_atapi_data[state->m_atapi_data_ptr];
1067//      printf("ATAPI: %d, packet read = %04x\n", state->m_atapi_data_ptr, state->m_atapi_data[state->m_atapi_data_ptr]);
1068      state->m_atapi_data_ptr++;
1076      data = m_atapi_data[m_atapi_data_ptr];
1077//      printf("ATAPI: %d, packet read = %04x\n", m_atapi_data_ptr, m_atapi_data[m_atapi_data_ptr]);
1078      m_atapi_data_ptr++;
10691079
1070      if (state->m_atapi_xfermod && state->m_atapi_data_ptr == (state->m_atapi_xferlen/2))
1080      if (m_atapi_xfermod && m_atapi_data_ptr == (m_atapi_xferlen/2))
10711081      {
10721082         //printf("ATAPI: DRQ interrupt\n");
1073         atapi_cause_irq(machine);
1074         state->m_atapi_regs[ATAPI_REG_CMDSTATUS] |= ATAPI_STAT_DRQ;
1075         state->m_atapi_data_ptr = 0;
1083         atapi_cause_irq();
1084         m_atapi_regs[ATAPI_REG_CMDSTATUS] |= ATAPI_STAT_DRQ;
1085         m_atapi_data_ptr = 0;
10761086
1077         if (state->m_atapi_xfermod > 63488)
1087         if (m_atapi_xfermod > 63488)
10781088         {
1079            state->m_atapi_xfermod = state->m_atapi_xfermod - 63488;
1080            state->m_atapi_xferlen = 63488;
1089            m_atapi_xfermod = m_atapi_xfermod - 63488;
1090            m_atapi_xferlen = 63488;
10811091         }
10821092         else
10831093         {
1084            state->m_atapi_xferlen = state->m_atapi_xfermod;
1085            state->m_atapi_xfermod = 0;
1094            m_atapi_xferlen = m_atapi_xfermod;
1095            m_atapi_xfermod = 0;
10861096         }
10871097
1088         //printf("ATAPI Transfer: %d, %d, %d\n", atapi_transfer_length, state->m_atapi_xfermod, state->m_atapi_xferlen);
1098         //printf("ATAPI Transfer: %d, %d, %d\n", atapi_transfer_length, m_atapi_xfermod, m_atapi_xferlen);
10891099
1090         state->m_atapi_regs[ATAPI_REG_COUNTLOW] = state->m_atapi_xferlen & 0xff;
1091         state->m_atapi_regs[ATAPI_REG_COUNTHIGH] = (state->m_atapi_xferlen>>8)&0xff;
1100         m_atapi_regs[ATAPI_REG_COUNTLOW] = m_atapi_xferlen & 0xff;
1101         m_atapi_regs[ATAPI_REG_COUNTHIGH] = (m_atapi_xferlen>>8)&0xff;
10921102      }
10931103      return data;
10941104   }
10951105   else
10961106   {
10971107      if (reg == ATAPI_REG_CMDSTATUS)
1098         atapi_clear_irq(machine);
1099      return state->m_atapi_regs[reg];
1108         atapi_clear_irq();
1109      return m_atapi_regs[reg];
11001110   }
11011111}
11021112
1103static void atapi_command_reg_w(running_machine &machine, int reg, UINT16 data)
1113void firebeat_state::atapi_command_reg_w(int reg, UINT16 data)
11041114{
1105   firebeat_state *state = machine.driver_data<firebeat_state>();
11061115   int i;
11071116
11081117   if (reg == ATAPI_REG_DATA)
11091118   {
11101119//      printf("%s:ATAPI: packet write %04x\n", device->machine().describe_context(), data);
1111      state->m_atapi_data[state->m_atapi_data_ptr] = data;
1112      state->m_atapi_data_ptr++;
1120      m_atapi_data[m_atapi_data_ptr] = data;
1121      m_atapi_data_ptr++;
11131122
1114      if (state->m_atapi_cdata_wait)
1123      if (m_atapi_cdata_wait)
11151124      {
1116//          printf("ATAPI: waiting, ptr %d wait %d\n", state->m_atapi_data_ptr, state->m_atapi_cdata_wait);
1117         if (state->m_atapi_data_ptr == state->m_atapi_cdata_wait)
1125//          printf("ATAPI: waiting, ptr %d wait %d\n", m_atapi_data_ptr, m_atapi_cdata_wait);
1126         if (m_atapi_data_ptr == m_atapi_cdata_wait)
11181127         {
11191128            // decompose SCSI packet into proper byte order
1120            for (i = 0; i < state->m_atapi_cdata_wait; i += 2)
1129            for (i = 0; i < m_atapi_cdata_wait; i += 2)
11211130            {
1122               state->m_atapi_scsi_packet[i] = state->m_atapi_data[i/2]&0xff;
1123               state->m_atapi_scsi_packet[i+1] = state->m_atapi_data[i/2]>>8;
1131               m_atapi_scsi_packet[i] = m_atapi_data[i/2]&0xff;
1132               m_atapi_scsi_packet[i+1] = m_atapi_data[i/2]>>8;
11241133            }
11251134
11261135            // send it to the device
1127            state->m_atapi_device_data[state->m_atapi_drivesel]->WriteData( state->m_atapi_scsi_packet, state->m_atapi_cdata_wait );
1136            m_atapi_device_data[m_atapi_drivesel]->WriteData( m_atapi_scsi_packet, m_atapi_cdata_wait );
11281137
11291138            // assert IRQ
1130            atapi_cause_irq(machine);
1139            atapi_cause_irq();
11311140
11321141            // not sure here, but clear DRQ at least?
1133            state->m_atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
1142            m_atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
11341143         }
11351144      }
11361145
1137      if ((!state->m_atapi_cdata_wait) && (state->m_atapi_data_ptr == 6))
1146      if ((!m_atapi_cdata_wait) && (m_atapi_data_ptr == 6))
11381147      {
11391148         int phase;
11401149
11411150         // reset data pointer for reading SCSI results
1142         state->m_atapi_data_ptr = 0;
1151         m_atapi_data_ptr = 0;
11431152
1144         state->m_atapi_regs[ATAPI_REG_CMDSTATUS] |= ATAPI_STAT_BSY;
1153         m_atapi_regs[ATAPI_REG_CMDSTATUS] |= ATAPI_STAT_BSY;
11451154
11461155         // assert IRQ
1147         atapi_cause_irq(machine);
1156         atapi_cause_irq();
11481157
11491158         // decompose SCSI packet into proper byte order
11501159         for (i = 0; i < 16; i += 2)
11511160         {
1152            state->m_atapi_scsi_packet[i+0] = state->m_atapi_data[i/2]&0xff;
1153            state->m_atapi_scsi_packet[i+1] = state->m_atapi_data[i/2]>>8;
1161            m_atapi_scsi_packet[i+0] = m_atapi_data[i/2]&0xff;
1162            m_atapi_scsi_packet[i+1] = m_atapi_data[i/2]>>8;
11541163         }
11551164
11561165         // send it to the SCSI device
1157         state->m_atapi_device_data[state->m_atapi_drivesel]->SetCommand( state->m_atapi_scsi_packet, 12 );
1158         state->m_atapi_device_data[state->m_atapi_drivesel]->ExecCommand( &state->m_atapi_xferlen );
1159         state->m_atapi_device_data[state->m_atapi_drivesel]->GetPhase( &phase );
1166         m_atapi_device_data[m_atapi_drivesel]->SetCommand( m_atapi_scsi_packet, 12 );
1167         m_atapi_device_data[m_atapi_drivesel]->ExecCommand( &m_atapi_xferlen );
1168         m_atapi_device_data[m_atapi_drivesel]->GetPhase( &phase );
11601169
1161         if (state->m_atapi_xferlen != -1)
1170         if (m_atapi_xferlen != -1)
11621171         {
1163            logerror("ATAPI: SCSI command %02x returned %d bytes from the device\n", state->m_atapi_data[0]&0xff, state->m_atapi_xferlen);
1172            logerror("ATAPI: SCSI command %02x returned %d bytes from the device\n", m_atapi_data[0]&0xff, m_atapi_xferlen);
11641173
11651174            // store the returned command length in the ATAPI regs, splitting into
11661175            // multiple transfers if necessary
11671176
1168            state->m_atapi_xfermod = 0;
1169            if (state->m_atapi_xferlen > 63488)
1177            m_atapi_xfermod = 0;
1178            if (m_atapi_xferlen > 63488)
11701179            {
1171               state->m_atapi_xfermod = state->m_atapi_xferlen - 63488;
1172               state->m_atapi_xferlen = 63488;
1180               m_atapi_xfermod = m_atapi_xferlen - 63488;
1181               m_atapi_xferlen = 63488;
11731182            }
11741183
1175//              printf("ATAPI Transfer: %d, %d\n", state->m_atapi_xfermod, state->m_atapi_xferlen);
1184//              printf("ATAPI Transfer: %d, %d\n", m_atapi_xfermod, m_atapi_xferlen);
11761185
1177            state->m_atapi_regs[ATAPI_REG_COUNTLOW] = state->m_atapi_xferlen & 0xff;
1178            state->m_atapi_regs[ATAPI_REG_COUNTHIGH] = (state->m_atapi_xferlen>>8)&0xff;
1186            m_atapi_regs[ATAPI_REG_COUNTLOW] = m_atapi_xferlen & 0xff;
1187            m_atapi_regs[ATAPI_REG_COUNTHIGH] = (m_atapi_xferlen>>8)&0xff;
11791188
11801189            switch( phase )
11811190            {
11821191            case SCSI_PHASE_DATAOUT:
1183               state->m_atapi_data_ptr = 0;
1184               state->m_atapi_cdata_wait = state->m_atapi_xferlen;
1185               logerror("ATAPI: Waiting for %x bytes of data\n", state->m_atapi_cdata_wait);
1192               m_atapi_data_ptr = 0;
1193               m_atapi_cdata_wait = m_atapi_xferlen;
1194               logerror("ATAPI: Waiting for %x bytes of data\n", m_atapi_cdata_wait);
11861195               break;
11871196            }
11881197
11891198            // perform special ATAPI processing of certain commands
1190            //if (state->m_atapi_drivesel==1) logerror("!!!ATAPI COMMAND %x\n", state->m_atapi_data[0]&0xff);
1191            switch (state->m_atapi_data[0]&0xff)
1199            //if (m_atapi_drivesel==1) logerror("!!!ATAPI COMMAND %x\n", m_atapi_data[0]&0xff);
1200            switch (m_atapi_data[0]&0xff)
11921201            {
11931202               case 0x55:  // MODE SELECT
1194                  state->m_atapi_cdata_wait = state->m_atapi_data[4]/2;
1195                  state->m_atapi_data_ptr = 0;
1196                  logerror("ATAPI: Waiting for %x bytes of MODE SELECT data\n", state->m_atapi_cdata_wait);
1203                  m_atapi_cdata_wait = m_atapi_data[4]/2;
1204                  m_atapi_data_ptr = 0;
1205                  logerror("ATAPI: Waiting for %x bytes of MODE SELECT data\n", m_atapi_cdata_wait);
11971206                  break;
11981207
11991208
12001209               case 0xa8:  // READ (12)
12011210                  // indicate data ready: set DRQ and DMA ready, and IO in INTREASON
1202                  state->m_atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_SERVDSC;
1203                  state->m_atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO;
1211                  m_atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_SERVDSC;
1212                  m_atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO;
12041213
12051214                  fatalerror("ATAPI: DMA read command attempted\n");
12061215                  break;
r21026r21027
12101219               case 0xa5: // PLAY AUDIO
12111220               case 0x1b: // START_STOP_UNIT
12121221               case 0x4e: // STOPPLAY_SCAN
1213                  state->m_atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
1222                  m_atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
12141223                  break;
12151224            }
12161225         }
r21026r21027
12181227         {
12191228//              printf("ATAPI: SCSI device returned error!\n");
12201229
1221            state->m_atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_CHECK;
1222            state->m_atapi_regs[ATAPI_REG_ERRFEAT] = 0x50;  // sense key = ILLEGAL REQUEST
1223            state->m_atapi_regs[ATAPI_REG_COUNTLOW] = 0;
1224            state->m_atapi_regs[ATAPI_REG_COUNTHIGH] = 0;
1230            m_atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_CHECK;
1231            m_atapi_regs[ATAPI_REG_ERRFEAT] = 0x50;  // sense key = ILLEGAL REQUEST
1232            m_atapi_regs[ATAPI_REG_COUNTLOW] = 0;
1233            m_atapi_regs[ATAPI_REG_COUNTHIGH] = 0;
12251234         }
12261235      }
12271236   }
12281237   else
12291238   {
12301239      data &= 0xff;
1231      state->m_atapi_regs[reg] = data;
1240      m_atapi_regs[reg] = data;
12321241//      printf("ATAPI: Command reg %d = %02X\n", reg, data);
12331242
12341243      switch(reg)
12351244      {
12361245         case ATAPI_REG_DRIVESEL:
1237            state->m_atapi_drivesel = (data >> 4) & 0x1;
1246            m_atapi_drivesel = (data >> 4) & 0x1;
12381247            break;
12391248
12401249         case ATAPI_REG_CMDSTATUS:
r21026r21027
12461255                  break;
12471256
12481257               case 0x08:      /* ATAPI Soft Reset */
1249                  atapi_reset(machine);
1258                  atapi_reset();
12501259                  break;
12511260
12521261               case 0xa0:      /* ATAPI Packet */
1253                  state->m_atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_BSY | ATAPI_STAT_DRQ;
1254                  state->m_atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_COMMAND;
1262                  m_atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_BSY | ATAPI_STAT_DRQ;
1263                  m_atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_COMMAND;
12551264
1256                  state->m_atapi_data_ptr = 0;
1257                  state->m_atapi_cdata_wait = 0;
1265                  m_atapi_data_ptr = 0;
1266                  m_atapi_cdata_wait = 0;
12581267                  break;
12591268
12601269               default:
r21026r21027
12651274   }
12661275}
12671276
1268static UINT16 atapi_control_reg_r(running_machine &machine, int reg)
1277UINT16 firebeat_state::atapi_control_reg_r(int reg)
12691278{
1270   firebeat_state *state = machine.driver_data<firebeat_state>();
12711279   UINT16 value;
12721280   switch(reg)
12731281   {
12741282      case 0x6:
12751283      {
1276         value = state->m_atapi_regs[ATAPI_REG_CMDSTATUS];
1277         if (state->m_atapi_regs[ATAPI_REG_CMDSTATUS] & ATAPI_STAT_BSY)
1284         value = m_atapi_regs[ATAPI_REG_CMDSTATUS];
1285         if (m_atapi_regs[ATAPI_REG_CMDSTATUS] & ATAPI_STAT_BSY)
12781286         {
1279            state->m_atapi_regs[ATAPI_REG_CMDSTATUS] ^= ATAPI_STAT_BSY;
1287            m_atapi_regs[ATAPI_REG_CMDSTATUS] ^= ATAPI_STAT_BSY;
12801288         }
12811289         return value;
12821290      }
r21026r21027
12891297   return 0;
12901298}
12911299
1292static void atapi_control_reg_w(running_machine &machine, int reg, UINT16 data)
1300void firebeat_state::atapi_control_reg_w(int reg, UINT16 data)
12931301{
12941302   switch(reg)
12951303   {
r21026r21027
12971305      {
12981306         if (data & 0x4)
12991307         {
1300            atapi_reset(machine);
1308            atapi_reset();
13011309         }
13021310         break;
13031311      }
r21026r21027
13151323//  printf("atapi_command_r: %08X, %08X\n", offset, mem_mask);
13161324   if (ACCESSING_BITS_16_31)
13171325   {
1318      r = atapi_command_reg_r(space.machine(), offset*2);
1326      r = atapi_command_reg_r(offset*2);
13191327      return ATAPI_ENDIAN(r) << 16;
13201328   }
13211329   else
13221330   {
1323      r = atapi_command_reg_r(space.machine(), (offset*2) + 1);
1331      r = atapi_command_reg_r((offset*2) + 1);
13241332      return ATAPI_ENDIAN(r) << 0;
13251333   }
13261334}
r21026r21027
13311339
13321340   if (ACCESSING_BITS_16_31)
13331341   {
1334      atapi_command_reg_w(space.machine(), offset*2, ATAPI_ENDIAN((data >> 16) & 0xffff));
1342      atapi_command_reg_w(offset*2, ATAPI_ENDIAN((data >> 16) & 0xffff));
13351343   }
13361344   else
13371345   {
1338      atapi_command_reg_w(space.machine(), (offset*2) + 1, ATAPI_ENDIAN((data >> 0) & 0xffff));
1346      atapi_command_reg_w((offset*2) + 1, ATAPI_ENDIAN((data >> 0) & 0xffff));
13391347   }
13401348}
13411349
r21026r21027
13471355
13481356   if (ACCESSING_BITS_16_31)
13491357   {
1350      r = atapi_control_reg_r(space.machine(), offset*2);
1358      r = atapi_control_reg_r(offset*2);
13511359      return ATAPI_ENDIAN(r) << 16;
13521360   }
13531361   else
13541362   {
1355      r = atapi_control_reg_r(space.machine(), (offset*2) + 1);
1363      r = atapi_control_reg_r((offset*2) + 1);
13561364      return ATAPI_ENDIAN(r) << 0;
13571365   }
13581366}
r21026r21027
13611369{
13621370   if (ACCESSING_BITS_16_31)
13631371   {
1364      atapi_control_reg_w(space.machine(), offset*2, ATAPI_ENDIAN(data >> 16) & 0xff);
1372      atapi_control_reg_w(offset*2, ATAPI_ENDIAN(data >> 16) & 0xff);
13651373   }
13661374   else
13671375   {
1368      atapi_control_reg_w(space.machine(), (offset*2) + 1, ATAPI_ENDIAN(data >> 0) & 0xff);
1376      atapi_control_reg_w((offset*2) + 1, ATAPI_ENDIAN(data >> 0) & 0xff);
13691377   }
13701378}
13711379
r21026r21027
21662174
21672175
21682176
2169static void set_ibutton(firebeat_state *state, UINT8 *data)
2177void firebeat_state::set_ibutton(UINT8 *data)
21702178{
21712179   int i, j;
21722180
r21026r21027
21752183      // identifier
21762184      for (j=0; j < 8; j++)
21772185      {
2178         state->m_ibutton.subkey[i].identifier[j] = *data++;
2186         m_ibutton.subkey[i].identifier[j] = *data++;
21792187      }
21802188
21812189      // password
21822190      for (j=0; j < 8; j++)
21832191      {
2184         state->m_ibutton.subkey[i].password[j] = *data++;
2192         m_ibutton.subkey[i].password[j] = *data++;
21852193      }
21862194
21872195      // data
21882196      for (j=0; j < 48; j++)
21892197      {
2190         state->m_ibutton.subkey[i].data[j] = *data++;
2198         m_ibutton.subkey[i].data[j] = *data++;
21912199      }
21922200   }
21932201}
21942202
2195static int ibutton_w(running_machine &machine, UINT8 data)
2203int firebeat_state::ibutton_w(UINT8 data)
21962204{
2197   firebeat_state *state = machine.driver_data<firebeat_state>();
21982205   int r = -1;
21992206
2200   switch (state->m_ibutton_state)
2207   switch (m_ibutton_state)
22012208   {
22022209      case DS1991_STATE_NORMAL:
22032210      {
r21026r21027
22262233            case 0x66:          // DS1991 Read SubKey
22272234            {
22282235               r = 0x66;
2229               state->m_ibutton_state = DS1991_STATE_READ_SUBKEY;
2230               state->m_ibutton_read_subkey_ptr = 0;
2236               m_ibutton_state = DS1991_STATE_READ_SUBKEY;
2237               m_ibutton_read_subkey_ptr = 0;
22312238               break;
22322239            }
22332240            case 0xcc:          // DS1991 skip rom
22342241            {
22352242               r = 0xcc;
2236               state->m_ibutton_state = DS1991_STATE_NORMAL;
2243               m_ibutton_state = DS1991_STATE_NORMAL;
22372244               break;
22382245            }
22392246            default:
r21026r21027
22472254
22482255      case DS1991_STATE_READ_SUBKEY:
22492256      {
2250         if (state->m_ibutton_read_subkey_ptr == 0)      // Read SubKey, 2nd command byte
2257         if (m_ibutton_read_subkey_ptr == 0)      // Read SubKey, 2nd command byte
22512258         {
22522259            int subkey = (data >> 6) & 0x3;
22532260      //      printf("iButton SubKey %d\n", subkey);
r21026r21027
22552262
22562263            if (subkey < 3)
22572264            {
2258               memcpy(&state->m_ibutton_subkey_data[0],  state->m_ibutton.subkey[subkey].identifier, 8);
2259               memcpy(&state->m_ibutton_subkey_data[8],  state->m_ibutton.subkey[subkey].password, 8);
2260               memcpy(&state->m_ibutton_subkey_data[16], state->m_ibutton.subkey[subkey].data, 0x30);
2265               memcpy(&m_ibutton_subkey_data[0],  m_ibutton.subkey[subkey].identifier, 8);
2266               memcpy(&m_ibutton_subkey_data[8],  m_ibutton.subkey[subkey].password, 8);
2267               memcpy(&m_ibutton_subkey_data[16], m_ibutton.subkey[subkey].data, 0x30);
22612268            }
22622269            else
22632270            {
2264               memset(&state->m_ibutton_subkey_data[0], 0, 0x40);
2271               memset(&m_ibutton_subkey_data[0], 0, 0x40);
22652272            }
22662273         }
2267         else if (state->m_ibutton_read_subkey_ptr == 1) // Read SubKey, 3rd command byte
2274         else if (m_ibutton_read_subkey_ptr == 1) // Read SubKey, 3rd command byte
22682275         {
22692276            r = data;
22702277         }
22712278         else
22722279         {
2273            r = state->m_ibutton_subkey_data[state->m_ibutton_read_subkey_ptr-2];
2280            r = m_ibutton_subkey_data[m_ibutton_read_subkey_ptr-2];
22742281         }
2275         state->m_ibutton_read_subkey_ptr++;
2276         if (state->m_ibutton_read_subkey_ptr >= 0x42)
2282         m_ibutton_read_subkey_ptr++;
2283         if (m_ibutton_read_subkey_ptr >= 0x42)
22772284         {
2278            state->m_ibutton_state = DS1991_STATE_NORMAL;
2285            m_ibutton_state = DS1991_STATE_NORMAL;
22792286         }
22802287         break;
22812288      }
r21026r21027
22862293
22872294static void security_w(device_t *device, UINT8 data)
22882295{
2289   int r = ibutton_w(device->machine(), data);
2296   firebeat_state *state = device->machine().driver_data<firebeat_state>();
2297   int r = state->ibutton_w(data);
22902298   if (r >= 0)
22912299      ppc4xx_spu_receive_byte(device->machine().device("maincpu"), r);
22922300}
22932301
22942302/*****************************************************************************/
22952303
2296static void init_lights(running_machine &machine, write32_delegate out1, write32_delegate out2, write32_delegate out3)
2304void firebeat_state::init_lights(write32_delegate out1, write32_delegate out2, write32_delegate out3)
22972305{
2298   firebeat_state *state = machine.driver_data<firebeat_state>();
2299   if(out1.isnull()) out1 = write32_delegate(FUNC(firebeat_state::lamp_output_w),state);
2300   if(out2.isnull()) out2 = write32_delegate(FUNC(firebeat_state::lamp_output2_w),state);
2301   if(out3.isnull()) out3 = write32_delegate(FUNC(firebeat_state::lamp_output3_w),state);
2306   if(out1.isnull()) out1 = write32_delegate(FUNC(firebeat_state::lamp_output_w),this);
2307   if(out2.isnull()) out2 = write32_delegate(FUNC(firebeat_state::lamp_output2_w),this);
2308   if(out3.isnull()) out3 = write32_delegate(FUNC(firebeat_state::lamp_output3_w),this);
23022309
2303   machine.device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x7d000804, 0x7d000807, out1);
2304   machine.device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x7d000320, 0x7d000323, out2);
2305   machine.device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x7d000324, 0x7d000327, out3);
2310   machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x7d000804, 0x7d000807, out1);
2311   machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x7d000320, 0x7d000323, out2);
2312   machine().device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x7d000324, 0x7d000327, out3);
23062313}
23072314
2308static void init_firebeat(running_machine &machine)
2315void firebeat_state::init_firebeat()
23092316{
2310   firebeat_state *state = machine.driver_data<firebeat_state>();
2311   UINT8 *rom = state->memregion("user2")->base();
2317   UINT8 *rom = memregion("user2")->base();
23122318
2313   atapi_init(machine);
2319   atapi_init();
23142320
2315   pc16552d_init(machine, 0, 19660800, comm_uart_irq_callback, 0);     // Network UART
2316   pc16552d_init(machine, 1, 24000000, midi_uart_irq_callback, 0);     // MIDI UART
2321   pc16552d_init(machine(), 0, 19660800, comm_uart_irq_callback, 0);     // Network UART
2322   pc16552d_init(machine(), 1, 24000000, midi_uart_irq_callback, 0);     // MIDI UART
23172323
2318   state->m_extend_board_irq_enable = 0x3f;
2319   state->m_extend_board_irq_active = 0x00;
2324   m_extend_board_irq_enable = 0x3f;
2325   m_extend_board_irq_active = 0x00;
23202326
2321   state->m_cur_cab_data = cab_data;
2327   m_cur_cab_data = cab_data;
23222328
2323   ppc4xx_spu_set_tx_handler(machine.device("maincpu"), security_w);
2329   ppc4xx_spu_set_tx_handler(machine().device("maincpu"), security_w);
23242330
2325   set_ibutton(state, rom);
2331   set_ibutton(rom);
23262332
2327   init_lights(machine, write32_delegate(), write32_delegate(), write32_delegate());
2333   init_lights(write32_delegate(), write32_delegate(), write32_delegate());
23282334}
23292335
23302336DRIVER_INIT_MEMBER(firebeat_state,ppp)
23312337{
2332   init_firebeat(machine());
2333   init_lights(machine(), write32_delegate(FUNC(firebeat_state::lamp_output_ppp_w),this), write32_delegate(FUNC(firebeat_state::lamp_output2_ppp_w),this), write32_delegate(FUNC(firebeat_state::lamp_output3_ppp_w),this));
2338   init_firebeat();
2339   init_lights(write32_delegate(FUNC(firebeat_state::lamp_output_ppp_w),this), write32_delegate(FUNC(firebeat_state::lamp_output2_ppp_w),this), write32_delegate(FUNC(firebeat_state::lamp_output3_ppp_w),this));
23342340}
23352341
23362342DRIVER_INIT_MEMBER(firebeat_state,ppd)
23372343{
2338   init_firebeat(machine());
2339   init_lights(machine(), write32_delegate(FUNC(firebeat_state::lamp_output_ppp_w),this), write32_delegate(FUNC(firebeat_state::lamp_output2_ppp_w),this), write32_delegate(FUNC(firebeat_state::lamp_output3_ppp_w),this));
2344   init_firebeat();
2345   init_lights(write32_delegate(FUNC(firebeat_state::lamp_output_ppp_w),this), write32_delegate(FUNC(firebeat_state::lamp_output2_ppp_w),this), write32_delegate(FUNC(firebeat_state::lamp_output3_ppp_w),this));
23402346
23412347   m_cur_cab_data = ppd_cab_data;
23422348}
23432349
2344static void init_keyboard(running_machine &machine)
2350void firebeat_state::init_keyboard()
23452351{
2346   firebeat_state *state = machine.driver_data<firebeat_state>();
23472352   // set keyboard timer
2348   state->m_keyboard_timer = machine.scheduler().timer_alloc(timer_expired_delegate(FUNC(firebeat_state::keyboard_timer_callback),state));
2349   state->m_keyboard_timer->adjust(attotime::from_msec(10), 0, attotime::from_msec(10));
2353   m_keyboard_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(firebeat_state::keyboard_timer_callback),this));
2354   m_keyboard_timer->adjust(attotime::from_msec(10), 0, attotime::from_msec(10));
23502355}
23512356
23522357DRIVER_INIT_MEMBER(firebeat_state,kbm)
23532358{
2354   init_firebeat(machine());
2355   init_lights(machine(), write32_delegate(FUNC(firebeat_state::lamp_output_kbm_w),this), write32_delegate(), write32_delegate());
2359   init_firebeat();
2360   init_lights(write32_delegate(FUNC(firebeat_state::lamp_output_kbm_w),this), write32_delegate(), write32_delegate());
23562361
2357   init_keyboard(machine());
2362   init_keyboard();
23582363
23592364   m_cur_cab_data = kbm_cab_data;
23602365}
trunk/src/mame/drivers/queen.c
r21026r21027
9191   virtual void machine_start();
9292   virtual void machine_reset();
9393   IRQ_CALLBACK_MEMBER(irq_callback);
94   void intel82439tx_init();
9495};
9596
9697
r21026r21027
134135   state->m_mxtc_config_reg[reg] = data;
135136}
136137
137static void intel82439tx_init(running_machine &machine)
138void queen_state::intel82439tx_init()
138139{
139   queen_state *state = machine.driver_data<queen_state>();
140   state->m_mxtc_config_reg[0x60] = 0x02;
141   state->m_mxtc_config_reg[0x61] = 0x02;
142   state->m_mxtc_config_reg[0x62] = 0x02;
143   state->m_mxtc_config_reg[0x63] = 0x02;
144   state->m_mxtc_config_reg[0x64] = 0x02;
145   state->m_mxtc_config_reg[0x65] = 0x02;
140   m_mxtc_config_reg[0x60] = 0x02;
141   m_mxtc_config_reg[0x61] = 0x02;
142   m_mxtc_config_reg[0x62] = 0x02;
143   m_mxtc_config_reg[0x63] = 0x02;
144   m_mxtc_config_reg[0x64] = 0x02;
145   m_mxtc_config_reg[0x65] = 0x02;
146146}
147147
148148static UINT32 intel82439tx_pci_r(device_t *busdevice, device_t *device, int function, int reg, UINT32 mem_mask)
r21026r21027
521521   init_pc_common(machine(), PCCOMMON_KEYBOARD_AT, queen_set_keyb_int);
522522
523523   m_maincpu->set_irq_acknowledge_callback(device_irq_acknowledge_delegate(FUNC(queen_state::irq_callback),this));
524   intel82439tx_init(machine());
524   intel82439tx_init();
525525
526526   kbdc8042_init(machine(), &at8042);
527527}
trunk/src/mame/drivers/igs011.c
r21026r21027
205205   UINT32 screen_update_igs011(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
206206   void screen_eof_vbowl(screen_device &screen, bool state);
207207   INTERRUPT_GEN_MEMBER(lhb_vblank_irq);
208   void wlcc_decrypt();
209   void lhb_decrypt();
210   void drgnwrld_type3_decrypt();
211   void drgnwrld_type2_decrypt();
212   void drgnwrld_type1_decrypt();
213   void lhb2_decrypt();
214   void nkishusp_decrypt();
215   void vbowlj_decrypt();
216   void dbc_decrypt();
217   void ryukobou_decrypt();
218   void lhb2_decrypt_gfx();
219   void drgnwrld_gfx_decrypt();
208220};
209221
210222
r21026r21027
586598
587599***************************************************************************/
588600
589static void wlcc_decrypt(running_machine &machine)
601void igs011_state::wlcc_decrypt()
590602{
591603   int i;
592   UINT16 *src = (UINT16 *) (machine.root_device().memregion("maincpu")->base());
604   UINT16 *src = (UINT16 *) (machine().root_device().memregion("maincpu")->base());
593605
594606   int rom_size = 0x80000;
595607
r21026r21027
610622}
611623
612624
613static void lhb_decrypt(running_machine &machine)
625void igs011_state::lhb_decrypt()
614626{
615627   int i;
616   UINT16 *src = (UINT16 *) (machine.root_device().memregion("maincpu")->base());
628   UINT16 *src = (UINT16 *) (machine().root_device().memregion("maincpu")->base());
617629
618630   int rom_size = 0x80000;
619631
r21026r21027
635647}
636648
637649
638static void drgnwrld_type3_decrypt(running_machine &machine)
650void igs011_state::drgnwrld_type3_decrypt()
639651{
640652   int i;
641   UINT16 *src = (UINT16 *) (machine.root_device().memregion("maincpu")->base());
653   UINT16 *src = (UINT16 *) (machine().root_device().memregion("maincpu")->base());
642654
643655   int rom_size = 0x80000;
644656
r21026r21027
663675   }
664676}
665677
666static void drgnwrld_type2_decrypt(running_machine &machine)
678void igs011_state::drgnwrld_type2_decrypt()
667679{
668680   int i;
669   UINT16 *src = (UINT16 *) (machine.root_device().memregion("maincpu")->base());
681   UINT16 *src = (UINT16 *) (machine().root_device().memregion("maincpu")->base());
670682
671683   int rom_size = 0x80000;
672684
r21026r21027
696708   }
697709}
698710
699static void drgnwrld_type1_decrypt(running_machine &machine)
711void igs011_state::drgnwrld_type1_decrypt()
700712{
701713   int i;
702   UINT16 *src = (UINT16 *) (machine.root_device().memregion("maincpu")->base());
714   UINT16 *src = (UINT16 *) (machine().root_device().memregion("maincpu")->base());
703715
704716   int rom_size = 0x80000;
705717
r21026r21027
725737}
726738
727739
728static void lhb2_decrypt(running_machine &machine)
740void igs011_state::lhb2_decrypt()
729741{
730742   int i,j;
731743   int rom_size = 0x80000;
732   UINT16 *src = (UINT16 *) (machine.root_device().memregion("maincpu")->base());
733   UINT16 *result_data = auto_alloc_array(machine, UINT16, rom_size/2);
744   UINT16 *src = (UINT16 *) (machine().root_device().memregion("maincpu")->base());
745   UINT16 *result_data = auto_alloc_array(machine(), UINT16, rom_size/2);
734746
735747   for (i=0; i<rom_size/2; i++)
736748   {
r21026r21027
752764
753765   memcpy(src,result_data,rom_size);
754766
755   auto_free(machine, result_data);
767   auto_free(machine(), result_data);
756768}
757769
758770
759771// xor similar to ryukobou (both sets are Japan), address scrambling from lhb2
760static void nkishusp_decrypt(running_machine &machine)
772void igs011_state::nkishusp_decrypt()
761773{
762774   int i,j;
763775   int rom_size = 0x80000;
764   UINT16 *src = (UINT16 *) (machine.root_device().memregion("maincpu")->base());
765   UINT16 *result_data = auto_alloc_array(machine, UINT16, rom_size/2);
776   UINT16 *src = (UINT16 *) (machine().root_device().memregion("maincpu")->base());
777   UINT16 *result_data = auto_alloc_array(machine(), UINT16, rom_size/2);
766778
767779   for (i=0; i<rom_size/2; i++)
768780   {
r21026r21027
792804
793805   memcpy(src,result_data,rom_size);
794806
795   auto_free(machine, result_data);
807   auto_free(machine(), result_data);
796808}
797809
798810
799static void vbowlj_decrypt(running_machine &machine)
811void igs011_state::vbowlj_decrypt()
800812{
801813   int i;
802   UINT16 *src = (UINT16 *) (machine.root_device().memregion("maincpu")->base());
814   UINT16 *src = (UINT16 *) (machine().root_device().memregion("maincpu")->base());
803815
804816   int rom_size = 0x80000;
805817
r21026r21027
830842}
831843
832844
833static void dbc_decrypt(running_machine &machine)
845void igs011_state::dbc_decrypt()
834846{
835847   int i;
836   UINT16 *src = (UINT16 *) (machine.root_device().memregion("maincpu")->base());
848   UINT16 *src = (UINT16 *) (machine().root_device().memregion("maincpu")->base());
837849
838850   int rom_size = 0x80000;
839851
r21026r21027
880892}
881893
882894
883static void ryukobou_decrypt(running_machine &machine)
895void igs011_state::ryukobou_decrypt()
884896{
885897   int i;
886   UINT16 *src = (UINT16 *) machine.root_device().memregion("maincpu")->base();
898   UINT16 *src = (UINT16 *) machine().root_device().memregion("maincpu")->base();
887899   int rom_size = 0x80000;
888900
889901   for (i=0; i<rom_size/2; i++)
r21026r21027
911923***************************************************************************/
912924
913925
914static void lhb2_decrypt_gfx(running_machine &machine)
926void igs011_state::lhb2_decrypt_gfx()
915927{
916928   int i;
917929   unsigned rom_size = 0x200000;
918   UINT8 *src = (UINT8 *) (machine.root_device().memregion("blitter")->base());
919   UINT8 *result_data = auto_alloc_array(machine, UINT8, rom_size);
930   UINT8 *src = (UINT8 *) (machine().root_device().memregion("blitter")->base());
931   UINT8 *result_data = auto_alloc_array(machine(), UINT8, rom_size);
920932
921933   for (i=0; i<rom_size; i++)
922934      result_data[i] = src[BITSWAP24(i, 23,22,21,20, 19, 17,16,15, 13,12, 10,9,8,7,6,5,4, 2,1, 3, 11, 14, 18, 0)];
923935
924936   memcpy(src,result_data,rom_size);
925937
926   auto_free(machine, result_data);
938   auto_free(machine(), result_data);
927939}
928940
929static void drgnwrld_gfx_decrypt(running_machine &machine)
941void igs011_state::drgnwrld_gfx_decrypt()
930942{
931943   int i;
932944   unsigned rom_size = 0x400000;
933   UINT8 *src = (UINT8 *) (machine.root_device().memregion("blitter")->base());
934   UINT8 *result_data = auto_alloc_array(machine, UINT8, rom_size);
945   UINT8 *src = (UINT8 *) (machine().root_device().memregion("blitter")->base());
946   UINT8 *result_data = auto_alloc_array(machine(), UINT8, rom_size);
935947
936948   for (i=0; i<rom_size; i++)
937949      result_data[i] = src[BITSWAP24(i, 23,22,21,20,19,18,17,16,15, 12, 13, 14, 11,10,9,8,7,6,5,4,3,2,1,0)];
938950
939951   memcpy(src,result_data,rom_size);
940952
941   auto_free(machine, result_data);
953   auto_free(machine(), result_data);
942954}
943955
944956
r21026r21027
18991911{
19001912//  UINT16 *rom = (UINT16 *) machine().root_device().memregion("maincpu")->base();
19011913
1902   drgnwrld_type1_decrypt(machine());
1903   drgnwrld_gfx_decrypt(machine());
1914   drgnwrld_type1_decrypt();
1915   drgnwrld_gfx_decrypt();
19041916/*
19051917    // PROTECTION CHECKS
19061918    rom[0x032ee/2]  =   0x606c;     // 0032EE: 676C        beq 335c     (ASIC11 CHECK PORT ERROR 3)
r21026r21027
19251937{
19261938//  UINT16 *rom = (UINT16 *) machine().root_device().memregion("maincpu")->base();
19271939
1928   drgnwrld_type1_decrypt(machine());
1929   drgnwrld_gfx_decrypt(machine());
1940   drgnwrld_type1_decrypt();
1941   drgnwrld_gfx_decrypt();
19301942/*
19311943    // PROTECTION CHECKS
19321944    rom[0x032ee/2]  =   0x606c;     // 0032EE: 676C        beq 335c     (ASIC11 CHECK PORT ERROR 3)
r21026r21027
19501962{
19511963//  UINT16 *rom = (UINT16 *) machine().root_device().memregion("maincpu")->base();
19521964
1953   drgnwrld_type2_decrypt(machine());
1954   drgnwrld_gfx_decrypt(machine());
1965   drgnwrld_type2_decrypt();
1966   drgnwrld_gfx_decrypt();
19551967   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0xd4c0, 0xd4ff, read16_delegate(FUNC(igs011_state::drgnwrldv21_igs011_prot2_r), this));
19561968/*
19571969    // PROTECTION CHECKS
r21026r21027
19791991{
19801992//  UINT16 *rom = (UINT16 *) machine().root_device().memregion("maincpu")->base();
19811993
1982   drgnwrld_type3_decrypt(machine());
1983   drgnwrld_gfx_decrypt(machine());
1994   drgnwrld_type3_decrypt();
1995   drgnwrld_gfx_decrypt();
19841996/*
19851997    // PROTECTION CHECKS
19861998    rom[0x033d2/2]  =   0x606c;     // 0033D2: 676C        beq 3440     (ASIC11 CHECK PORT ERROR 3)
r21026r21027
20062018{
20072019//  UINT16 *rom = (UINT16 *) machine().root_device().memregion("maincpu")->base();
20082020
2009   drgnwrld_type3_decrypt(machine());
2010   drgnwrld_gfx_decrypt(machine());
2021   drgnwrld_type3_decrypt();
2022   drgnwrld_gfx_decrypt();
20112023/*
20122024    // PROTECTION CHECKS
20132025    // bp 33d2; bp 11c74; bp 23d2a; bp 23f68; bp 240d4; bp 242ac; bp 244b2; bp 24630; bp 24886; bp 24aca; bp 24d46; bp 24f8e; bp 254ba; bp 26a52; bp 276a0; bp 2a86e
r21026r21027
20332045
20342046DRIVER_INIT_MEMBER(igs011_state,drgnwrldv11h)
20352047{
2036   drgnwrld_type1_decrypt(machine());
2037   drgnwrld_gfx_decrypt(machine());
2048   drgnwrld_type1_decrypt();
2049   drgnwrld_gfx_decrypt();
20382050
20392051   // PROTECTION CHECKS
20402052   // the protection checks are already patched out like we do!
r21026r21027
20442056{
20452057//  UINT16 *rom = (UINT16 *) machine().root_device().memregion("maincpu")->base();
20462058
2047   drgnwrld_type1_decrypt(machine());
2048   drgnwrld_gfx_decrypt(machine());
2059   drgnwrld_type1_decrypt();
2060   drgnwrld_gfx_decrypt();
20492061/*
20502062    // PROTECTION CHECKS
20512063    // bp 33d2; bp 23d0e; bp 23f58; bp 240d0; bp 242a8; bp 244ae; bp 2462c; bp 24882; bp 24ac6; bp 24d42; bp 24f8a; bp 254b6; bp 2a23a
r21026r21027
20702082{
20712083//  UINT16 *rom = (UINT16 *) machine().root_device().memregion("maincpu")->base();
20722084
2073   lhb_decrypt(machine());
2085   lhb_decrypt();
20742086
20752087   // PROTECTION CHECKS
20762088//  rom[0x2eef6/2]  =   0x4e75;     // 02EEF6: 4E56 FE00    link A6, #-$200  (fills palette with pink otherwise)
r21026r21027
20802092{
20812093//  UINT16 *rom = (UINT16 *) machine().root_device().memregion("maincpu")->base();
20822094
2083   lhb_decrypt(machine());
2095   lhb_decrypt();
20842096
20852097   // PROTECTION CHECKS
20862098//  rom[0x2e988/2]  =   0x4e75;     // 02E988: 4E56 FE00    link A6, #-$200  (fills palette with pink otherwise)
r21026r21027
20902102{
20912103//  UINT16 *rom = (UINT16 *) machine().root_device().memregion("maincpu")->base();
20922104
2093   dbc_decrypt(machine());
2105   dbc_decrypt();
20942106
20952107   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x10600, 0x107ff, read16_delegate(FUNC(igs011_state::dbc_igs011_prot2_r), this));
20962108/*
r21026r21027
21202132{
21212133//  UINT16 *rom = (UINT16 *) machine().root_device().memregion("maincpu")->base();
21222134
2123   ryukobou_decrypt(machine());
2135   ryukobou_decrypt();
21242136
21252137   machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x10600, 0x107ff, read16_delegate(FUNC(igs011_state::ryukobou_igs011_prot2_r), this));
21262138
r21026r21027
21332145{
21342146//  UINT16 *rom = (UINT16 *) machine().root_device().memregion("maincpu")->base();
21352147
2136   lhb_decrypt(machine());
2148   lhb_decrypt();
21372149/*
21382150    // PROTECTION CHECKS
21392151    rom[0x00502/2]  =   0x6006;     // 000502: 6050         bra 554
r21026r21027
21672179{
21682180//  UINT16 *rom = (UINT16 *) machine().root_device().memregion("maincpu")->base();
21692181
2170   wlcc_decrypt(machine());
2182   wlcc_decrypt();
21712183/*
21722184    // PROTECTION CHECKS
21732185    rom[0x16b96/2]  =   0x6000;     // 016B96: 6700 02FE    beq 16e96  (fills palette with red otherwise)
r21026r21027
21912203{
21922204//  UINT16 *rom = (UINT16 *) machine().root_device().memregion("maincpu")->base();
21932205
2194   lhb2_decrypt(machine());
2195   lhb2_decrypt_gfx(machine());
2206   lhb2_decrypt();
2207   lhb2_decrypt_gfx();
21962208/*
21972209    // PROTECTION CHECKS
21982210    rom[0x034f4/2]  =   0x4e71;     // 0034F4: 660E    bne 3504   (rom test, fills palette with white otherwise)
r21026r21027
22162228   UINT8  *gfx = (UINT8 *)  machine().root_device().memregion("blitter")->base();
22172229   int i;
22182230
2219   vbowlj_decrypt(machine());
2231   vbowlj_decrypt();
22202232
22212233   for (i = 0x400000-1; i >= 0; i--)
22222234   {
r21026r21027
22422254   UINT8  *gfx = (UINT8 *)  machine().root_device().memregion("blitter")->base();
22432255   int i;
22442256
2245   vbowlj_decrypt(machine());
2257   vbowlj_decrypt();
22462258
22472259   for (i = 0x400000-1; i >= 0; i--)
22482260   {
r21026r21027
22632275{
22642276   UINT16 *rom = (UINT16 *) machine().root_device().memregion("maincpu")->base();
22652277
2266   nkishusp_decrypt(machine());
2267   lhb2_decrypt_gfx(machine());
2278   nkishusp_decrypt();
2279   lhb2_decrypt_gfx();
22682280
22692281   // PROTECTION CHECKS (similar to lhb2)
22702282
trunk/src/mame/drivers/bfmsys85.c
r21026r21027
113113   virtual void machine_start();
114114   virtual void machine_reset();
115115   INTERRUPT_GEN_MEMBER(timer_irq);
116   int b85_find_project_string( );
116117};
117118
118119#define MASTER_CLOCK    (XTAL_4MHz)
r21026r21027
676677ROM_END
677678
678679
679int b85_find_project_string(running_machine &machine )
680int bfmsys85_state::b85_find_project_string( )
680681{
681682   // search for the project string to find the title (usually just at ff00)
682683   char title_string[7][32] = { "PROJECT NUMBER", "PROJECT PR", "PROJECT ", "CASH ON THE NILE 2", "PR6121", "CHINA TOWN\x0d\x0a", "PROJECTNUMBER" };
683   UINT8 *src = machine.root_device().memregion( "maincpu" )->base();
684   int size = machine.root_device().memregion( "maincpu" )->bytes();
684   UINT8 *src = machine().root_device().memregion( "maincpu" )->base();
685   int size = machine().root_device().memregion( "maincpu" )->bytes();
685686
686687   for (int search=0;search<7;search++)
687688   {
r21026r21027
754755DRIVER_INIT_MEMBER(bfmsys85_state,decode)
755756{
756757   bfm_decode_mainrom(machine(),"maincpu", m_codec_data);
757   b85_find_project_string(machine());
758   b85_find_project_string();
758759}
759760
760761DRIVER_INIT_MEMBER(bfmsys85_state,nodecode)
761762{
762   b85_find_project_string(machine());
763   b85_find_project_string();
763764}
764765
765766// PROJECT NUMBER 5539  2P CASH EXPLOSION  GAME No 39-350-190 -   29-MAR-1989 11:45:25
trunk/src/mame/drivers/konamigv.c
r21026r21027
170170   DECLARE_DRIVER_INIT(konamigv);
171171   DECLARE_DRIVER_INIT(btchamp);
172172   DECLARE_MACHINE_START(konamigv);
173   void scsi_dma_read( UINT32 *p_n_psxram, UINT32 n_address, INT32 n_size );
174   void scsi_dma_write( UINT32 *p_n_psxram, UINT32 n_address, INT32 n_size );
173175};
174176
175177/* EEPROM handlers */
r21026r21027
210212
211213/* SCSI */
212214
213static void scsi_dma_read( konamigv_state *state, UINT32 *p_n_psxram, UINT32 n_address, INT32 n_size )
215void konamigv_state::scsi_dma_read( UINT32 *p_n_psxram, UINT32 n_address, INT32 n_size )
214216{
215   UINT8 *sector_buffer = state->m_sector_buffer;
217   UINT8 *sector_buffer = m_sector_buffer;
216218   int i;
217219   int n_this;
218220
219221   while( n_size > 0 )
220222   {
221      if( n_size > sizeof( state->m_sector_buffer ) / 4 )
223      if( n_size > sizeof( m_sector_buffer ) / 4 )
222224      {
223         n_this = sizeof( state->m_sector_buffer ) / 4;
225         n_this = sizeof( m_sector_buffer ) / 4;
224226      }
225227      else
226228      {
r21026r21027
229231      if( n_this < 2048 / 4 )
230232      {
231233         /* non-READ commands */
232         state->m_am53cf96->dma_read_data( n_this * 4, sector_buffer );
234         m_am53cf96->dma_read_data( n_this * 4, sector_buffer );
233235      }
234236      else
235237      {
236238         /* assume normal 2048 byte data for now */
237         state->m_am53cf96->dma_read_data( 2048, sector_buffer );
239         m_am53cf96->dma_read_data( 2048, sector_buffer );
238240         n_this = 2048 / 4;
239241      }
240242      n_size -= n_this;
r21026r21027
254256   }
255257}
256258
257static void scsi_dma_write( konamigv_state *state, UINT32 *p_n_psxram, UINT32 n_address, INT32 n_size )
259void konamigv_state::scsi_dma_write( UINT32 *p_n_psxram, UINT32 n_address, INT32 n_size )
258260{
259   UINT8 *sector_buffer = state->m_sector_buffer;
261   UINT8 *sector_buffer = m_sector_buffer;
260262   int i;
261263   int n_this;
262264
263265   while( n_size > 0 )
264266   {
265      if( n_size > sizeof( state->m_sector_buffer ) / 4 )
267      if( n_size > sizeof( m_sector_buffer ) / 4 )
266268      {
267         n_this = sizeof( state->m_sector_buffer ) / 4;
269         n_this = sizeof( m_sector_buffer ) / 4;
268270      }
269271      else
270272      {
r21026r21027
284286         n_this--;
285287      }
286288
287      state->m_am53cf96->dma_write_data( n_this * 4, sector_buffer );
289      m_am53cf96->dma_write_data( n_this * 4, sector_buffer );
288290   }
289291}
290292
r21026r21027
307309   MCFG_CPU_ADD( "maincpu", CXD8530BQ, XTAL_67_7376MHz )
308310   MCFG_CPU_PROGRAM_MAP( konamigv_map )
309311
310   MCFG_PSX_DMA_CHANNEL_READ( "maincpu", 5, psx_dma_read_delegate( FUNC( scsi_dma_read ), (konamigv_state *) owner ) )
311   MCFG_PSX_DMA_CHANNEL_WRITE( "maincpu", 5, psx_dma_write_delegate( FUNC( scsi_dma_write ), (konamigv_state *) owner ) )
312   MCFG_PSX_DMA_CHANNEL_READ( "maincpu", 5, psx_dma_read_delegate( FUNC( konamigv_state::scsi_dma_read ), (konamigv_state *) owner ) )
313   MCFG_PSX_DMA_CHANNEL_WRITE( "maincpu", 5, psx_dma_write_delegate( FUNC( konamigv_state::scsi_dma_write ), (konamigv_state *) owner ) )
312314
313315   MCFG_MACHINE_START_OVERRIDE(konamigv_state, konamigv )
314316
trunk/src/mame/drivers/hornet.c
r21026r21027
372372   UINT32 screen_update_hornet(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
373373   UINT32 screen_update_hornet_2board(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
374374   TIMER_CALLBACK_MEMBER(irq_off);
375   int jvs_encode_data(UINT8 *in, int length);
376   int jvs_decode_data(UINT8 *in, UINT8 *out, int length);
377   void jamma_jvs_cmd_exec();
375378};
376379
377380
r21026r21027
11401143
11411144/*****************************************************************************/
11421145
1143static void jamma_jvs_cmd_exec(running_machine &machine);
1144
11451146static void jamma_jvs_w(device_t *device, UINT8 data)
11461147{
11471148   hornet_state *state = device->machine().driver_data<hornet_state>();
r21026r21027
11511152   state->m_jvs_sdata_ptr++;
11521153
11531154   if (state->m_jvs_sdata_ptr >= 3 && state->m_jvs_sdata_ptr >= 3 + state->m_jvs_sdata[2])
1154      jamma_jvs_cmd_exec(device->machine());
1155      state->jamma_jvs_cmd_exec();
11551156}
11561157
1157static int jvs_encode_data(running_machine &machine, UINT8 *in, int length)
1158int hornet_state::jvs_encode_data(UINT8 *in, int length)
11581159{
11591160   int inptr = 0;
11601161   int sum = 0;
r21026r21027
11651166      if (b == 0xe0)
11661167      {
11671168         sum += 0xd0 + 0xdf;
1168         ppc4xx_spu_receive_byte(machine.device("maincpu"), 0xd0);
1169         ppc4xx_spu_receive_byte(machine.device("maincpu"), 0xdf);
1169         ppc4xx_spu_receive_byte(machine().device("maincpu"), 0xd0);
1170         ppc4xx_spu_receive_byte(machine().device("maincpu"), 0xdf);
11701171      }
11711172      else if (b == 0xd0)
11721173      {
11731174         sum += 0xd0 + 0xcf;
1174         ppc4xx_spu_receive_byte(machine.device("maincpu"), 0xd0);
1175         ppc4xx_spu_receive_byte(machine.device("maincpu"), 0xcf);
1175         ppc4xx_spu_receive_byte(machine().device("maincpu"), 0xd0);
1176         ppc4xx_spu_receive_byte(machine().device("maincpu"), 0xcf);
11761177      }
11771178      else
11781179      {
11791180         sum += b;
1180         ppc4xx_spu_receive_byte(machine.device("maincpu"), b);
1181         ppc4xx_spu_receive_byte(machine().device("maincpu"), b);
11811182      }
11821183   }
11831184   return sum;
11841185}
11851186
1186static int jvs_decode_data(UINT8 *in, UINT8 *out, int length)
1187int hornet_state::jvs_decode_data(UINT8 *in, UINT8 *out, int length)
11871188{
11881189   int outptr = 0;
11891190   int inptr = 0;
r21026r21027
12051206   return outptr;
12061207}
12071208
1208static void jamma_jvs_cmd_exec(running_machine &machine)
1209void hornet_state::jamma_jvs_cmd_exec()
12091210{
1210   hornet_state *state = machine.driver_data<hornet_state>();
12111211   UINT8 byte_num;
12121212   UINT8 data[1024], rdata[1024];
12131213#if 0
r21026r21027
12161216   int rdata_ptr;
12171217   int sum;
12181218
1219//  sync = state->m_jvs_sdata[0];
1220//  node = state->m_jvs_sdata[1];
1221   byte_num = state->m_jvs_sdata[2];
1219//  sync = m_jvs_sdata[0];
1220//  node = m_jvs_sdata[1];
1221   byte_num = m_jvs_sdata[2];
12221222
12231223#if 0
12241224   length =
12251225#endif
1226      jvs_decode_data(&state->m_jvs_sdata[3], data, byte_num-1);
1226      jvs_decode_data(&m_jvs_sdata[3], data, byte_num-1);
12271227#if 0
12281228   printf("jvs input data:\n");
12291229   for (i=0; i < byte_num; i++)
12301230   {
1231      printf("%02X ", state->m_jvs_sdata[3+i]);
1231      printf("%02X ", m_jvs_sdata[3+i]);
12321232   }
12331233   printf("\n");
12341234
r21026r21027
12711271
12721272   // write jvs return data
12731273   sum = 0x00 + (rdata_ptr+1);
1274   ppc4xx_spu_receive_byte(machine.device("maincpu"), 0xe0);           // sync
1275   ppc4xx_spu_receive_byte(machine.device("maincpu"), 0x00);           // node
1276   ppc4xx_spu_receive_byte(machine.device("maincpu"), rdata_ptr + 1);  // num of bytes
1277   sum += jvs_encode_data(machine, rdata, rdata_ptr);
1278   ppc4xx_spu_receive_byte(machine.device("maincpu"), sum - 1);        // checksum
1274   ppc4xx_spu_receive_byte(machine().device("maincpu"), 0xe0);           // sync
1275   ppc4xx_spu_receive_byte(machine().device("maincpu"), 0x00);           // node
1276   ppc4xx_spu_receive_byte(machine().device("maincpu"), rdata_ptr + 1);  // num of bytes
1277   sum += jvs_encode_data(rdata, rdata_ptr);
1278   ppc4xx_spu_receive_byte(machine().device("maincpu"), sum - 1);        // checksum
12791279
1280   state->m_jvs_sdata_ptr = 0;
1280   m_jvs_sdata_ptr = 0;
12811281}
12821282
12831283/*****************************************************************************/
trunk/src/mame/drivers/pcxt.c
r21026r21027
126126   virtual void machine_reset();
127127   UINT32 screen_update_tetriskr(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
128128   IRQ_CALLBACK_MEMBER(irq_callback);
129   UINT8 pcxt_speaker_get_spk();
130   void pcxt_speaker_set_spkrdata(UINT8 data);
131   void pcxt_speaker_set_input(UINT8 data);
129132};
130133
131134UINT32 pcxt_state::screen_update_tetriskr(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
r21026r21027
235238*********************************/
236239
237240// pc_speaker_get_spk, pc_speaker_set_spkrdata, and pc_speaker_set_input already exists in MESS, can the implementations be merged?
238UINT8 pcxt_speaker_get_spk(running_machine &machine)
241UINT8 pcxt_state::pcxt_speaker_get_spk()
239242{
240   pcxt_state *state = machine.driver_data<pcxt_state>();
241   return state->m_pc_spkrdata & state->m_pc_input;
243   return m_pc_spkrdata & m_pc_input;
242244}
243245
244void pcxt_speaker_set_spkrdata(running_machine &machine, UINT8 data)
246void pcxt_state::pcxt_speaker_set_spkrdata(UINT8 data)
245247{
246   device_t *speaker = machine.device("speaker");
247   pcxt_state *state = machine.driver_data<pcxt_state>();
248   state->m_pc_spkrdata = data ? 1 : 0;
249   speaker_level_w( speaker, pcxt_speaker_get_spk(machine) );
248   device_t *speaker = machine().device("speaker");
249   m_pc_spkrdata = data ? 1 : 0;
250   speaker_level_w( speaker, pcxt_speaker_get_spk() );
250251}
251252
252void pcxt_speaker_set_input(running_machine &machine, UINT8 data)
253void pcxt_state::pcxt_speaker_set_input(UINT8 data)
253254{
254   device_t *speaker = machine.device("speaker");
255   pcxt_state *state = machine.driver_data<pcxt_state>();
256   state->m_pc_input = data ? 1 : 0;
257   speaker_level_w( speaker, pcxt_speaker_get_spk(machine) );
255   device_t *speaker = machine().device("speaker");
256   m_pc_input = data ? 1 : 0;
257   speaker_level_w( speaker, pcxt_speaker_get_spk() );
258258}
259259
260260
261261WRITE_LINE_MEMBER(pcxt_state::ibm5150_pit8253_out2_changed)
262262{
263   pcxt_speaker_set_input( machine(), state );
263   pcxt_speaker_set_input( state );
264264}
265265
266266
r21026r21027
330330{
331331   /* PPI controller port B*/
332332   pit8253_gate2_w(m_pit8253, BIT(data, 0));
333   pcxt_speaker_set_spkrdata( machine(), data & 0x02 );
333   pcxt_speaker_set_spkrdata( data & 0x02 );
334334   m_port_b_data = data;
335335// device_t *beep = machine().device("beep");
336336// device_t *cvsd = machine().device("cvsd");
trunk/src/mame/drivers/sandscrp.c
r21026r21027
112112   UINT32 screen_update_sandscrp(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
113113   void screen_eof_sandscrp(screen_device &screen, bool state);
114114   INTERRUPT_GEN_MEMBER(sandscrp_interrupt);
115   void update_irq_state();
115116};
116117
117118
r21026r21027
149150
150151
151152/* Update the IRQ state based on all possible causes */
152static void update_irq_state(running_machine &machine)
153void sandscrp_state::update_irq_state()
153154{
154   sandscrp_state *state = machine.driver_data<sandscrp_state>();
155   if (state->m_vblank_irq || state->m_sprite_irq || state->m_unknown_irq)
156      machine.device("maincpu")->execute().set_input_line(1, ASSERT_LINE);
155   if (m_vblank_irq || m_sprite_irq || m_unknown_irq)
156      machine().device("maincpu")->execute().set_input_line(1, ASSERT_LINE);
157157   else
158      machine.device("maincpu")->execute().set_input_line(1, CLEAR_LINE);
158      machine().device("maincpu")->execute().set_input_line(1, CLEAR_LINE);
159159}
160160
161161
r21026r21027
164164INTERRUPT_GEN_MEMBER(sandscrp_state::sandscrp_interrupt)
165165{
166166   m_vblank_irq = 1;
167   update_irq_state(machine());
167   update_irq_state();
168168}
169169
170170
r21026r21027
175175   {
176176      device_t *pandora = machine().device("pandora");
177177      m_sprite_irq = 1;
178      update_irq_state(machine());
178      update_irq_state();
179179      pandora_eof(pandora);
180180   }
181181}
r21026r21027
202202      if (data & 0x20)    m_vblank_irq  = 0;
203203   }
204204
205   update_irq_state(machine());
205   update_irq_state();
206206}
207207
208208
trunk/src/mame/drivers/firefox.c
r21026r21027
100100   virtual void video_start();
101101   UINT32 screen_update_firefox(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
102102   TIMER_DEVICE_CALLBACK_MEMBER(video_timer_callback);
103   void set_rgba( int start, int index, unsigned char *palette_ram );
104   void firq_gen(phillips_22vp931_device &laserdisc, int state);
103105};
104106
105107
r21026r21027
258260   machine().device("maincpu")->execute().set_input_line(M6809_IRQ_LINE, ASSERT_LINE );
259261}
260262
261static void set_rgba( running_machine &machine, int start, int index, unsigned char *palette_ram )
263void firefox_state::set_rgba( int start, int index, unsigned char *palette_ram )
262264{
263265   int r = palette_ram[ index ];
264266   int g = palette_ram[ index + 256 ];
265267   int b = palette_ram[ index + 512 ];
266268   int a = ( b & 3 ) * 0x55;
267269
268   palette_set_color( machine, start + index, MAKE_ARGB( a, r, g, b ) );
270   palette_set_color( machine(), start + index, MAKE_ARGB( a, r, g, b ) );
269271}
270272
271273WRITE8_MEMBER(firefox_state::tile_palette_w)
272274{
273275   m_tile_palette[ offset ] = data;
274   set_rgba( machine(), 0, offset & 0xff, m_tile_palette );
276   set_rgba( 0, offset & 0xff, m_tile_palette );
275277}
276278
277279WRITE8_MEMBER(firefox_state::sprite_palette_w)
278280{
279281   m_sprite_palette[ offset ] = data;
280   set_rgba( machine(), 256, offset & 0xff, m_sprite_palette );
282   set_rgba( 256, offset & 0xff, m_sprite_palette );
281283}
282284
283285WRITE8_MEMBER(firefox_state::firefox_objram_bank_w)
r21026r21027
476478
477479
478480
479static void firq_gen(running_machine &machine, phillips_22vp931_device &laserdisc, int state)
481void firefox_state::firq_gen(phillips_22vp931_device &laserdisc, int state)
480482{
481483   if (state)
482      machine.device("maincpu")->execute().set_input_line(M6809_FIRQ_LINE, ASSERT_LINE );
484      machine().device("maincpu")->execute().set_input_line(M6809_FIRQ_LINE, ASSERT_LINE );
483485}
484486
485487
r21026r21027
489491   m_nvram_1c = machine().device<x2212_device>("nvram_1c");
490492   m_nvram_1d = machine().device<x2212_device>("nvram_1d");
491493
492   m_laserdisc->set_data_ready_callback(phillips_22vp931_device::data_ready_delegate(FUNC(firq_gen), &machine()));
494   m_laserdisc->set_data_ready_callback(phillips_22vp931_device::data_ready_delegate(FUNC(firefox_state::firq_gen), this));
493495
494496   m_control_num = 0;
495497   m_sprite_bank = 0;
trunk/src/mame/drivers/deco156.c
r21026r21027
5959   virtual void video_start();
6060   UINT32 screen_update_wcvol95(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
6161   INTERRUPT_GEN_MEMBER(deco32_vbl_interrupt);
62   void descramble_sound( const char *tag );
6263};
6364
6465
r21026r21027
617618
618619/**********************************************************************************/
619620
620static void descramble_sound( running_machine &machine, const char *tag )
621void deco156_state::descramble_sound( const char *tag )
621622{
622   UINT8 *rom = machine.root_device().memregion(tag)->base();
623   int length = machine.root_device().memregion(tag)->bytes();
624   UINT8 *buf1 = auto_alloc_array(machine, UINT8, length);
623   UINT8 *rom = machine().root_device().memregion(tag)->base();
624   int length = machine().root_device().memregion(tag)->bytes();
625   UINT8 *buf1 = auto_alloc_array(machine(), UINT8, length);
625626   UINT32 x;
626627
627628   for (x = 0; x < length; x++)
r21026r21027
640641
641642   memcpy(rom,buf1,length);
642643
643   auto_free(machine, buf1);
644   auto_free(machine(), buf1);
644645}
645646
646647DRIVER_INIT_MEMBER(deco156_state,hvysmsh)
647648{
648649   deco56_decrypt_gfx(machine(), "gfx1"); /* 141 */
649650   deco156_decrypt(machine());
650   descramble_sound(machine(), "oki2");
651   descramble_sound("oki2");
651652}
652653
653654DRIVER_INIT_MEMBER(deco156_state,wcvol95)
654655{
655656   deco56_decrypt_gfx(machine(), "gfx1"); /* 141 */
656657   deco156_decrypt(machine());
657   descramble_sound(machine(), "ymz");
658   descramble_sound("ymz");
658659}
659660
660661
trunk/src/mame/drivers/konamim2.c
r21026r21027
251251   virtual void video_start();
252252   UINT32 screen_update_m2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
253253   INTERRUPT_GEN_MEMBER(m2);
254   void cde_init();
255   void cde_handle_command();
256   void cde_handle_reports();
257   void cde_dma_transfer(address_space &space, int channel, int next);
254258};
255259
256260
r21026r21027
487491
488492
489493
490static void cde_init(running_machine &machine)
494void konamim2_state::cde_init()
491495{
492   konamim2_state *state = machine.driver_data<konamim2_state>();
493   cdrom_file *cdfile = cdrom_open(get_disk_handle(machine, ":cdrom"));
496   cdrom_file *cdfile = cdrom_open(get_disk_handle(machine(), ":cdrom"));
494497
495498   const cdrom_toc *toc = cdrom_get_toc(cdfile);
496499
497500   if (cdfile)
498501   {
499      memcpy(&state->m_cde_toc, toc, sizeof(cdrom_toc));
502      memcpy(&m_cde_toc, toc, sizeof(cdrom_toc));
500503
501504      /*
502505      printf("%d tracks\n", toc->numtrks);
r21026r21027
511514      cdrom_close(cdfile);
512515   }
513516
514   state->m_cde_drive_state = CDE_DRIVE_STATE_PAUSED;
517   m_cde_drive_state = CDE_DRIVE_STATE_PAUSED;
515518
516   state->m_cde_num_status_bytes = 0;
517   state->m_cde_status_byte_ptr = 0;
518   state->m_cde_command_byte_ptr = 0;
519   m_cde_num_status_bytes = 0;
520   m_cde_status_byte_ptr = 0;
521   m_cde_command_byte_ptr = 0;
519522
520   state->m_cde_response = 0;
523   m_cde_response = 0;
521524
522   state->m_cde_enable_qchannel_reports = 0;
523   state->m_cde_enable_seek_reports = 0;
525   m_cde_enable_qchannel_reports = 0;
526   m_cde_enable_seek_reports = 0;
524527
525   state->m_cde_qchannel_offset = 0;
528   m_cde_qchannel_offset = 0;
526529}
527530
528static void cde_handle_command(running_machine &machine)
531void konamim2_state::cde_handle_command()
529532{
530   konamim2_state *state = machine.driver_data<konamim2_state>();
531   switch (state->m_cde_command_bytes[0])
533   switch (m_cde_command_bytes[0])
532534   {
533535      case 0x04:      // Set Speed
534536      {
535         state->m_cde_num_status_bytes = 1;
537         m_cde_num_status_bytes = 1;
536538
537         state->m_cde_status_bytes[0] = 0x04;
538         state->m_cde_status_byte_ptr = 0;
539         m_cde_status_bytes[0] = 0x04;
540         m_cde_status_byte_ptr = 0;
539541
540//          mame_printf_debug("CDE: SET SPEED %02X, %02X\n", state->m_cde_command_bytes[1], state->m_cde_command_bytes[2]);
542//          mame_printf_debug("CDE: SET SPEED %02X, %02X\n", m_cde_command_bytes[1], m_cde_command_bytes[2]);
541543         break;
542544      }
543545      case 0x06:      // Audio Format / Data Format
544546      {
545         state->m_cde_num_status_bytes = 1;
547         m_cde_num_status_bytes = 1;
546548
547         state->m_cde_status_bytes[0] = 0x06;
548         state->m_cde_status_byte_ptr = 0;
549         m_cde_status_bytes[0] = 0x06;
550         m_cde_status_byte_ptr = 0;
549551
550         if (state->m_cde_command_bytes[1] == 0x00)      // Audio Format
552         if (m_cde_command_bytes[1] == 0x00)      // Audio Format
551553         {
552554//              mame_printf_debug("CDE: AUDIO FORMAT\n");
553555         }
554         else if (state->m_cde_command_bytes[1] == 0x78) // Data Format
556         else if (m_cde_command_bytes[1] == 0x78) // Data Format
555557         {
556558//              mame_printf_debug("CDE: DATA FORMAT\n");
557559         }
558560         else
559561         {
560            fatalerror("CDE: unknown command %02X, %02X\n", state->m_cde_command_bytes[0], state->m_cde_command_bytes[1]);
562            fatalerror("CDE: unknown command %02X, %02X\n", m_cde_command_bytes[0], m_cde_command_bytes[1]);
561563         }
562564         break;
563565      }
564566      case 0x08:      // Pause / Eject / Play
565567      {
566         state->m_cde_num_status_bytes = 1;
568         m_cde_num_status_bytes = 1;
567569
568         state->m_cde_status_bytes[0] = 0x08;
569         state->m_cde_status_byte_ptr = 0;
570         m_cde_status_bytes[0] = 0x08;
571         m_cde_status_byte_ptr = 0;
570572
571         if (state->m_cde_command_bytes[1] == 0x00)      // Eject
573         if (m_cde_command_bytes[1] == 0x00)      // Eject
572574         {
573575//              mame_printf_debug("CDE: EJECT command\n");
574576         }
575         else if (state->m_cde_command_bytes[1] == 0x02) // Pause
577         else if (m_cde_command_bytes[1] == 0x02) // Pause
576578         {
577579//              mame_printf_debug("CDE: PAUSE command\n");
578            state->m_cde_drive_state = CDE_DRIVE_STATE_PAUSED;
580            m_cde_drive_state = CDE_DRIVE_STATE_PAUSED;
579581         }
580         else if (state->m_cde_command_bytes[1] == 0x03) // Play
582         else if (m_cde_command_bytes[1] == 0x03) // Play
581583         {
582584//              mame_printf_debug("CDE: PLAY command\n");
583585         }
584586         else
585587         {
586            fatalerror("CDE: unknown command %02X, %02X\n", state->m_cde_command_bytes[0], state->m_cde_command_bytes[1]);
588            fatalerror("CDE: unknown command %02X, %02X\n", m_cde_command_bytes[0], m_cde_command_bytes[1]);
587589         }
588590         break;
589591      }
590592      case 0x09:      // Seek
591593      {
592         state->m_cde_num_status_bytes = 1;
594         m_cde_num_status_bytes = 1;
593595
594         state->m_cde_status_bytes[0] = 0x1b;
595         state->m_cde_status_byte_ptr = 0;
596         m_cde_status_bytes[0] = 0x1b;
597         m_cde_status_byte_ptr = 0;
596598
597         state->m_cde_drive_state = CDE_DRIVE_STATE_SEEK_DONE;
599         m_cde_drive_state = CDE_DRIVE_STATE_SEEK_DONE;
598600
599//          mame_printf_debug("CDE: SEEK %08X\n", (state->m_cde_command_bytes[1] << 16) | (state->m_cde_command_bytes[2] << 8) | (state->m_cde_command_bytes[3]));
601//          mame_printf_debug("CDE: SEEK %08X\n", (m_cde_command_bytes[1] << 16) | (m_cde_command_bytes[2] << 8) | (m_cde_command_bytes[3]));
600602         break;
601603      }
602604      case 0x0b:      // Get Drive State
603605      {
604         state->m_cde_num_status_bytes = 0x3;
606         m_cde_num_status_bytes = 0x3;
605607
606         state->m_cde_status_bytes[0] = 0x0b;
607         state->m_cde_status_bytes[1] = 0x1b;
608         state->m_cde_status_bytes[2] = state->m_cde_drive_state;
609         state->m_cde_status_byte_ptr = 0;
608         m_cde_status_bytes[0] = 0x0b;
609         m_cde_status_bytes[1] = 0x1b;
610         m_cde_status_bytes[2] = m_cde_drive_state;
611         m_cde_status_byte_ptr = 0;
610612
611         if (state->m_cde_command_bytes[1] & 0x02)
613         if (m_cde_command_bytes[1] & 0x02)
612614         {
613            state->m_cde_enable_seek_reports = 1;
615            m_cde_enable_seek_reports = 1;
614616         }
615617         else
616618         {
617            state->m_cde_enable_seek_reports = 0;
619            m_cde_enable_seek_reports = 0;
618620         }
619621
620//          mame_printf_debug("CDE: GET DRIVE STATE %02X\n", state->m_cde_command_bytes[1]);
622//          mame_printf_debug("CDE: GET DRIVE STATE %02X\n", m_cde_command_bytes[1]);
621623         break;
622624      }
623625      case 0x0c:      // ?
624626      {
625         state->m_cde_num_status_bytes = 1;
627         m_cde_num_status_bytes = 1;
626628
627         state->m_cde_status_bytes[0] = 0x0c;
628         state->m_cde_status_byte_ptr = 0;
629         m_cde_status_bytes[0] = 0x0c;
630         m_cde_status_byte_ptr = 0;
629631
630         if (state->m_cde_command_bytes[1] == 0x02)
632         if (m_cde_command_bytes[1] == 0x02)
631633         {
632            state->m_cde_enable_qchannel_reports = 1;
633            state->m_cde_drive_state = CDE_DRIVE_STATE_PAUSED;
634            m_cde_enable_qchannel_reports = 1;
635            m_cde_drive_state = CDE_DRIVE_STATE_PAUSED;
634636         }
635         else if (state->m_cde_command_bytes[0] == 0x00)
637         else if (m_cde_command_bytes[0] == 0x00)
636638         {
637            state->m_cde_enable_qchannel_reports = 0;
639            m_cde_enable_qchannel_reports = 0;
638640         }
639641
640//          mame_printf_debug("CDE: UNKNOWN CMD 0x0c %02X\n", state->m_cde_command_bytes[1]);
642//          mame_printf_debug("CDE: UNKNOWN CMD 0x0c %02X\n", m_cde_command_bytes[1]);
641643         break;
642644      }
643645      case 0x0d:      // Get Switch State
644646      {
645         state->m_cde_num_status_bytes = 0x4;
647         m_cde_num_status_bytes = 0x4;
646648
647         state->m_cde_status_bytes[0] = 0x0d;
648         state->m_cde_status_bytes[1] = 0x1d;
649         state->m_cde_status_bytes[2] = 0x02;
650         state->m_cde_status_byte_ptr = 0;
649         m_cde_status_bytes[0] = 0x0d;
650         m_cde_status_bytes[1] = 0x1d;
651         m_cde_status_bytes[2] = 0x02;
652         m_cde_status_byte_ptr = 0;
651653
652//          mame_printf_debug("CDE: GET SWITCH STATE %02X\n", state->m_cde_command_bytes[1]);
654//          mame_printf_debug("CDE: GET SWITCH STATE %02X\n", m_cde_command_bytes[1]);
653655         break;
654656      }
655657      case 0x21:      // Mech type
656658      {
657         state->m_cde_num_status_bytes = 0x8;
659         m_cde_num_status_bytes = 0x8;
658660
659         state->m_cde_status_bytes[0] = 0x21;
660         state->m_cde_status_bytes[1] = 0xff;
661         state->m_cde_status_bytes[2] = 0x08;        // Max Speed
662         state->m_cde_status_bytes[3] = 0xff;
663         state->m_cde_status_bytes[4] = 0xff;
664         state->m_cde_status_bytes[5] = 0xff;
665         state->m_cde_status_bytes[6] = 0xff;
666         state->m_cde_status_bytes[7] = 0xff;
661         m_cde_status_bytes[0] = 0x21;
662         m_cde_status_bytes[1] = 0xff;
663         m_cde_status_bytes[2] = 0x08;        // Max Speed
664         m_cde_status_bytes[3] = 0xff;
665         m_cde_status_bytes[4] = 0xff;
666         m_cde_status_bytes[5] = 0xff;
667         m_cde_status_bytes[6] = 0xff;
668         m_cde_status_bytes[7] = 0xff;
667669
668         state->m_cde_status_byte_ptr = 0;
670         m_cde_status_byte_ptr = 0;
669671
670//          mame_printf_debug("CDE: MECH TYPE %02X, %02X, %02X\n", state->m_cde_command_bytes[1], state->m_cde_command_bytes[2], state->m_cde_command_bytes[3]);
672//          mame_printf_debug("CDE: MECH TYPE %02X, %02X, %02X\n", m_cde_command_bytes[1], m_cde_command_bytes[2], m_cde_command_bytes[3]);
671673         break;
672674      }
673675      case 0x83:      // Read ID
674676      {
675         state->m_cde_num_status_bytes = 0xc;
677         m_cde_num_status_bytes = 0xc;
676678
677         state->m_cde_status_bytes[0] = 0x03;
678         state->m_cde_status_bytes[1] = 0xff;
679         state->m_cde_status_bytes[2] = 0xff;
680         state->m_cde_status_bytes[3] = 0xff;
681         state->m_cde_status_bytes[4] = 0xff;
682         state->m_cde_status_bytes[5] = 0xff;
683         state->m_cde_status_bytes[6] = 0xff;
684         state->m_cde_status_bytes[7] = 0xff;
685         state->m_cde_status_bytes[8] = 0xff;
686         state->m_cde_status_bytes[9] = 0xff;
687         state->m_cde_status_bytes[10] = 0xff;
688         state->m_cde_status_bytes[11] = 0xff;
679         m_cde_status_bytes[0] = 0x03;
680         m_cde_status_bytes[1] = 0xff;
681         m_cde_status_bytes[2] = 0xff;
682         m_cde_status_bytes[3] = 0xff;
683         m_cde_status_bytes[4] = 0xff;
684         m_cde_status_bytes[5] = 0xff;
685         m_cde_status_bytes[6] = 0xff;
686         m_cde_status_bytes[7] = 0xff;
687         m_cde_status_bytes[8] = 0xff;
688         m_cde_status_bytes[9] = 0xff;
689         m_cde_status_bytes[10] = 0xff;
690         m_cde_status_bytes[11] = 0xff;
689691
690         state->m_cde_status_byte_ptr = 0;
692         m_cde_status_byte_ptr = 0;
691693
692694//          mame_printf_debug("CDE: READ ID\n");
693695         break;
694696      }
695697      default:
696698      {
697         fatalerror("CDE: unknown command %08X\n", state->m_cde_command_bytes[0]);
699         fatalerror("CDE: unknown command %08X\n", m_cde_command_bytes[0]);
698700         break;
699701      }
700702   }
701703}
702704
703static void cde_handle_reports(running_machine &machine)
705void konamim2_state::cde_handle_reports()
704706{
705   konamim2_state *state = machine.driver_data<konamim2_state>();
706   switch (state->m_cde_command_bytes[0])
707   switch (m_cde_command_bytes[0])
707708   {
708709      case 0x09:
709710      {
710         if (state->m_cde_enable_seek_reports)
711         if (m_cde_enable_seek_reports)
711712         {
712            state->m_cde_num_status_bytes = 0x2;
713            state->m_cde_status_bytes[0] = 0x02;
713            m_cde_num_status_bytes = 0x2;
714            m_cde_status_bytes[0] = 0x02;
714715
715            state->m_cde_status_byte_ptr = 0;
716            m_cde_status_byte_ptr = 0;
716717
717            state->m_cde_command_bytes[0] = 0x0c;
718            m_cde_command_bytes[0] = 0x0c;
718719
719720//              mame_printf_debug("CDE: SEEK REPORT\n");
720721         }
r21026r21027
723724
724725      case 0x0b:
725726      {
726         if (state->m_cde_enable_qchannel_reports)
727         if (m_cde_enable_qchannel_reports)
727728         {
728729            int track, num_tracks;
729730
730            num_tracks = state->m_cde_toc.numtrks;
731            track = state->m_cde_qchannel_offset % (num_tracks+3);
731            num_tracks = m_cde_toc.numtrks;
732            track = m_cde_qchannel_offset % (num_tracks+3);
732733
733            state->m_cde_num_status_bytes = 0xb;
734            state->m_cde_status_bytes[0] = 0x1c;
734            m_cde_num_status_bytes = 0xb;
735            m_cde_status_bytes[0] = 0x1c;
735736
736737            /*
737            state->m_cde_status_bytes[1] = 0x0;      // q-Mode
738            state->m_cde_status_bytes[2] = 0x0;      // TNO
739            state->m_cde_status_bytes[3] = 0x0;      // Index / Pointer
740            state->m_cde_status_bytes[4] = 0x0;      // Min
741            state->m_cde_status_bytes[5] = 0x0;      // Sec
742            state->m_cde_status_bytes[6] = 0x0;      // Frac
743            state->m_cde_status_bytes[7] = 0x0;      // Zero
744            state->m_cde_status_bytes[8] = 0x0;      // A-Min
745            state->m_cde_status_bytes[9] = 0x0;      // A-Sec
746            state->m_cde_status_bytes[10] = 0x0;     // A-Frac
738            m_cde_status_bytes[1] = 0x0;      // q-Mode
739            m_cde_status_bytes[2] = 0x0;      // TNO
740            m_cde_status_bytes[3] = 0x0;      // Index / Pointer
741            m_cde_status_bytes[4] = 0x0;      // Min
742            m_cde_status_bytes[5] = 0x0;      // Sec
743            m_cde_status_bytes[6] = 0x0;      // Frac
744            m_cde_status_bytes[7] = 0x0;      // Zero
745            m_cde_status_bytes[8] = 0x0;      // A-Min
746            m_cde_status_bytes[9] = 0x0;      // A-Sec
747            m_cde_status_bytes[10] = 0x0;     // A-Frac
747748            */
748749
749750            if (track < num_tracks)
750751            {
751               int time = lba_to_msf(state->m_cde_toc.tracks[track].physframeofs);
752               int time = lba_to_msf(m_cde_toc.tracks[track].physframeofs);
752753
753               state->m_cde_status_bytes[1] = 0x41;                    // q-Mode
754               state->m_cde_status_bytes[2] = 0x0;                 // TNO (Lead-in track)
755               state->m_cde_status_bytes[3] = track+1;             // Pointer
756               state->m_cde_status_bytes[4] = 0x0;                 // Min
757               state->m_cde_status_bytes[5] = 0x0;                 // Sec
758               state->m_cde_status_bytes[6] = 0x0;                 // Frac
759               state->m_cde_status_bytes[7] = 0x0;                 // Zero
760               state->m_cde_status_bytes[8] = (time >> 16) & 0xff; // P-Min
761               state->m_cde_status_bytes[9] = (time >>  8) & 0xff; // P-Sec
762               state->m_cde_status_bytes[10] = time & 0xff;            // P-Frac
754               m_cde_status_bytes[1] = 0x41;                    // q-Mode
755               m_cde_status_bytes[2] = 0x0;                 // TNO (Lead-in track)
756               m_cde_status_bytes[3] = track+1;             // Pointer
757               m_cde_status_bytes[4] = 0x0;                 // Min
758               m_cde_status_bytes[5] = 0x0;                 // Sec
759               m_cde_status_bytes[6] = 0x0;                 // Frac
760               m_cde_status_bytes[7] = 0x0;                 // Zero
761               m_cde_status_bytes[8] = (time >> 16) & 0xff; // P-Min
762               m_cde_status_bytes[9] = (time >>  8) & 0xff; // P-Sec
763               m_cde_status_bytes[10] = time & 0xff;            // P-Frac
763764            }
764765            else
765766            {
766767               if (track == num_tracks+0)
767768               {
768                  state->m_cde_status_bytes[1] = 0x41;                    // q-Mode / Control
769                  state->m_cde_status_bytes[2] = 0x0;                 // TNO (Lead-in track)
770                  state->m_cde_status_bytes[3] = 0xa0;                    // Pointer
771                  state->m_cde_status_bytes[4] = 0x0;                 // Min
772                  state->m_cde_status_bytes[5] = 0x0;                 // Sec
773                  state->m_cde_status_bytes[6] = 0x0;                 // Frac
774                  state->m_cde_status_bytes[7] = 0x0;                 // Zero
775                  state->m_cde_status_bytes[8] = 1;                   // P-Min
776                  state->m_cde_status_bytes[9] = 0x0;                 // P-Sec
777                  state->m_cde_status_bytes[10] = 0x0;                    // P-Frac
769                  m_cde_status_bytes[1] = 0x41;                    // q-Mode / Control
770                  m_cde_status_bytes[2] = 0x0;                 // TNO (Lead-in track)
771                  m_cde_status_bytes[3] = 0xa0;                    // Pointer
772                  m_cde_status_bytes[4] = 0x0;                 // Min
773                  m_cde_status_bytes[5] = 0x0;                 // Sec
774                  m_cde_status_bytes[6] = 0x0;                 // Frac
775                  m_cde_status_bytes[7] = 0x0;                 // Zero
776                  m_cde_status_bytes[8] = 1;                   // P-Min
777                  m_cde_status_bytes[9] = 0x0;                 // P-Sec
778                  m_cde_status_bytes[10] = 0x0;                    // P-Frac
778779               }
779780               else if (track == num_tracks+1)
780781               {
781                  state->m_cde_status_bytes[1] = 0x41;                    // q-Mode / Control
782                  state->m_cde_status_bytes[2] = 0x0;                 // TNO (Lead-in track)
783                  state->m_cde_status_bytes[3] = 0xa1;                    // Pointer
784                  state->m_cde_status_bytes[4] = 0x0;                 // Min
785                  state->m_cde_status_bytes[5] = 0x0;                 // Sec
786                  state->m_cde_status_bytes[6] = 0x0;                 // Frac
787                  state->m_cde_status_bytes[7] = 0x0;                 // Zero
788                  state->m_cde_status_bytes[8] = num_tracks;          // P-Min
789                  state->m_cde_status_bytes[9] = 0x0;                 // P-Sec
790                  state->m_cde_status_bytes[10] = 0x0;                    // P-Frac
782                  m_cde_status_bytes[1] = 0x41;                    // q-Mode / Control
783                  m_cde_status_bytes[2] = 0x0;                 // TNO (Lead-in track)
784                  m_cde_status_bytes[3] = 0xa1;                    // Pointer
785                  m_cde_status_bytes[4] = 0x0;                 // Min
786                  m_cde_status_bytes[5] = 0x0;                 // Sec
787                  m_cde_status_bytes[6] = 0x0;                 // Frac
788                  m_cde_status_bytes[7] = 0x0;                 // Zero
789                  m_cde_status_bytes[8] = num_tracks;          // P-Min
790                  m_cde_status_bytes[9] = 0x0;                 // P-Sec
791                  m_cde_status_bytes[10] = 0x0;                    // P-Frac
791792               }
792793               else
793794               {
794                  int leadout_lba = state->m_cde_toc.tracks[num_tracks-1].physframeofs + state->m_cde_toc.tracks[num_tracks-1].frames;
795                  int leadout_lba = m_cde_toc.tracks[num_tracks-1].physframeofs + m_cde_toc.tracks[num_tracks-1].frames;
795796                  int leadout_time = lba_to_msf(leadout_lba);
796797
797                  state->m_cde_status_bytes[1] = 0x41;                    // q-Mode / Control
798                  state->m_cde_status_bytes[2] = 0x0;                 // TNO (Lead-in track)
799                  state->m_cde_status_bytes[3] = 0xa2;                    // Pointer
800                  state->m_cde_status_bytes[4] = 0x0;                 // Min
801                  state->m_cde_status_bytes[5] = 0x0;                 // Sec
802                  state->m_cde_status_bytes[6] = 0x0;                 // Frac
803                  state->m_cde_status_bytes[7] = 0x0;                 // Zero
804                  state->m_cde_status_bytes[8] = (leadout_time >> 16) & 0xff; // P-Min
805                  state->m_cde_status_bytes[9] = (leadout_time >>  8) & 0xff; // P-Sec
806                  state->m_cde_status_bytes[10] = leadout_time & 0xff;            // P-Frac
798                  m_cde_status_bytes[1] = 0x41;                    // q-Mode / Control
799                  m_cde_status_bytes[2] = 0x0;                 // TNO (Lead-in track)
800                  m_cde_status_bytes[3] = 0xa2;                    // Pointer
801                  m_cde_status_bytes[4] = 0x0;                 // Min
802                  m_cde_status_bytes[5] = 0x0;                 // Sec
803                  m_cde_status_bytes[6] = 0x0;                 // Frac
804                  m_cde_status_bytes[7] = 0x0;                 // Zero
805                  m_cde_status_bytes[8] = (leadout_time >> 16) & 0xff; // P-Min
806                  m_cde_status_bytes[9] = (leadout_time >>  8) & 0xff; // P-Sec
807                  m_cde_status_bytes[10] = leadout_time & 0xff;            // P-Frac
807808               }
808809            }
809810
810            state->m_cde_qchannel_offset++;
811            m_cde_qchannel_offset++;
811812
812            state->m_cde_status_byte_ptr = 0;
813            state->m_cde_command_bytes[0] = 0x0c;
813            m_cde_status_byte_ptr = 0;
814            m_cde_command_bytes[0] = 0x0c;
814815
815816//              mame_printf_debug("CDE: QCHANNEL REPORT\n");
816817            break;
r21026r21027
819820   }
820821}
821822
822static void cde_dma_transfer(address_space &space, int channel, int next)
823void konamim2_state::cde_dma_transfer(address_space &space, int channel, int next)
823824{
824   konamim2_state *state = space.machine().driver_data<konamim2_state>();
825825   UINT32 address;
826826   //int length;
827827   int i;
828828
829829   if (next)
830830   {
831      address = state->m_cde_dma[channel].next_dst_addr;
832      //length = state->m_cde_dma[channel].next_length;
831      address = m_cde_dma[channel].next_dst_addr;
832      //length = m_cde_dma[channel].next_length;
833833   }
834834   else
835835   {
836      address = state->m_cde_dma[channel].dst_addr;
837      //length = state->m_cde_dma[channel].length;
836      address = m_cde_dma[channel].dst_addr;
837      //length = m_cde_dma[channel].length;
838838   }
839839
840   for (i=0; i < state->m_cde_dma[channel].next_length; i++)
840   for (i=0; i < m_cde_dma[channel].next_length; i++)
841841   {
842842      space.write_byte(address, 0xff);        // TODO: do the real transfer...
843843      address++;
r21026r21027
883883
884884            if (!m_cde_response)
885885            {
886               cde_handle_reports(machine());
886               cde_handle_reports();
887887
888888         //      m_cde_command_byte_ptr = 0;
889889         //      m_cde_command_bytes[m_cde_command_byte_ptr++] = 0x1c;
r21026r21027
944944         {
945945            if (m_cde_response)
946946            {
947               cde_handle_command(machine());
947               cde_handle_command();
948948
949949               m_cde_response = 0;
950950            }
r21026r21027
12991299{
13001300   m_unk3 = U64(0xffffffffffffffff);
13011301   m_unk20004 = 0;
1302   cde_init(machine());
1302   cde_init();
13031303}
13041304
13051305GAME( 1997, polystar, 0,        m2, m2, konamim2_state, m2, ROT0, "Konami", "Tobe! Polystars (ver JAA)", GAME_NOT_WORKING | GAME_NO_SOUND )
trunk/src/mame/drivers/royalmah.c
r21026r21027
200200   INTERRUPT_GEN_MEMBER(suzume_irq);
201201   INTERRUPT_GEN_MEMBER(mjtensin_interrupt);
202202   TIMER_DEVICE_CALLBACK_MEMBER(janptr96_interrupt);
203   void mjtensin_update_rombank();
204   void cafetime_update_rombank();
203205};
204206
205207
r21026r21027
10561058   return 0xff;
10571059}
10581060
1059static void mjtensin_update_rombank(running_machine &machine)
1061void royalmah_state::mjtensin_update_rombank()
10601062{
1061   royalmah_state *state = machine.driver_data<royalmah_state>();
1062   state->membank("bank1")->set_base(state->memregion("maincpu")->base() + 0x10000 + state->m_rombank * 0x8000 );
1063   membank("bank1")->set_base(memregion("maincpu")->base() + 0x10000 + m_rombank * 0x8000 );
10631064}
10641065WRITE8_MEMBER(royalmah_state::mjtensin_p4_w)
10651066{
10661067   m_rombank = (m_rombank & 0xf0) | (data & 0x0f);
1067   mjtensin_update_rombank(machine());
1068   mjtensin_update_rombank();
10681069}
10691070WRITE8_MEMBER(royalmah_state::mjtensin_6ff3_w)
10701071{
10711072   m_rombank = (data << 4) | (m_rombank & 0x0f);
1072   mjtensin_update_rombank(machine());
1073   mjtensin_update_rombank();
10731074}
10741075
10751076static ADDRESS_MAP_START( mjtensin_map, AS_PROGRAM, 8, royalmah_state )
r21026r21027
10981099                                Mahjong Cafe Time
10991100****************************************************************************/
11001101
1101static void cafetime_update_rombank(running_machine &machine)
1102void royalmah_state::cafetime_update_rombank()
11021103{
1103   royalmah_state *state = machine.driver_data<royalmah_state>();
1104   state->membank("bank1")->set_base(state->memregion("maincpu")->base() + 0x10000 + state->m_rombank * 0x8000 );
1104   membank("bank1")->set_base(memregion("maincpu")->base() + 0x10000 + m_rombank * 0x8000 );
11051105}
11061106WRITE8_MEMBER(royalmah_state::cafetime_p4_w)
11071107{
11081108   m_rombank = (m_rombank & 0xf0) | (data & 0x0f);
1109   cafetime_update_rombank(machine());
1109   cafetime_update_rombank();
11101110}
11111111WRITE8_MEMBER(royalmah_state::cafetime_p3_w)
11121112{
11131113   m_rombank = (m_rombank & 0x0f) | ((data & 0x0c) << 2);
1114   cafetime_update_rombank(machine());
1114   cafetime_update_rombank();
11151115}
11161116
11171117WRITE8_MEMBER(royalmah_state::cafetime_dsw_w)
trunk/src/mame/drivers/igs017.c
r21026r21027
159159   TIMER_DEVICE_CALLBACK_MEMBER(irqblocka_interrupt);
160160   TIMER_DEVICE_CALLBACK_MEMBER(mgcs_interrupt);
161161   TIMER_DEVICE_CALLBACK_MEMBER(mgdh_interrupt);
162   void expand_sprites();
163   void draw_sprite(bitmap_ind16 &bitmap,const rectangle &cliprect, int sx, int sy, int dimx, int dimy, int flipx, int flipy, int color, int addr);
164   void draw_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect);
165   int debug_viewer(bitmap_ind16 &bitmap,const rectangle &cliprect);
166   void decrypt_program_rom(int mask, int a7, int a6, int a5, int a4, int a3, int a2, int a1, int a0);
167   void iqblocka_patch_rom();
168   void tjsb_decrypt_sprites();
169   void mgcs_decrypt_program_rom();
170   void mgcs_decrypt_tiles();
171   void mgcs_flip_sprites();
172   void mgcs_patch_rom();
173   void starzan_decrypt(UINT8 *ROM, int size, bool isOpcode);
174   void lhzb2_patch_rom();
175   void lhzb2_decrypt_tiles();
176   void lhzb2_decrypt_sprites();
177   void slqz2_patch_rom();
178   void slqz2_decrypt_tiles();
162179};
163180
164181
r21026r21027
249266
250267// Eeach 16 bit word in the sprites gfx roms contains three 5 bit pens: x-22222-11111-00000 (little endian!).
251268// This routine expands each word into three bytes.
252static void expand_sprites(running_machine &machine)
269void igs017_state::expand_sprites()
253270{
254   igs017_state *state = machine.driver_data<igs017_state>();
255   UINT8 *rom  =   state->memregion("sprites")->base();
256   int size    =   state->memregion("sprites")->bytes();
271   UINT8 *rom  =   memregion("sprites")->base();
272   int size    =   memregion("sprites")->bytes();
257273   int i;
258274
259   state->m_sprites_gfx_size   =   size / 2 * 3;
260   state->m_sprites_gfx        =   auto_alloc_array(machine, UINT8, state->m_sprites_gfx_size);
275   m_sprites_gfx_size   =   size / 2 * 3;
276   m_sprites_gfx        =   auto_alloc_array(machine(), UINT8, m_sprites_gfx_size);
261277
262278   for (i = 0; i < size / 2 ; i++)
263279   {
264280      UINT16 pens = (rom[i*2+1] << 8) | rom[i*2];
265281
266      state->m_sprites_gfx[i * 3 + 0] = (pens >>  0) & 0x1f;
267      state->m_sprites_gfx[i * 3 + 1] = (pens >>  5) & 0x1f;
268      state->m_sprites_gfx[i * 3 + 2] = (pens >> 10) & 0x1f;
282      m_sprites_gfx[i * 3 + 0] = (pens >>  0) & 0x1f;
283      m_sprites_gfx[i * 3 + 1] = (pens >>  5) & 0x1f;
284      m_sprites_gfx[i * 3 + 2] = (pens >> 10) & 0x1f;
269285   }
270286}
271287
r21026r21027
281297   m_debug_addr = 0;
282298   m_debug_width = 512;
283299
284   expand_sprites(machine());
300   expand_sprites();
285301}
286302
287303/***************************************************************************
r21026r21027
317333
318334***************************************************************************/
319335
320static void draw_sprite(running_machine &machine, bitmap_ind16 &bitmap,const rectangle &cliprect, int sx, int sy, int dimx, int dimy, int flipx, int flipy, int color, int addr)
336void igs017_state::draw_sprite(bitmap_ind16 &bitmap,const rectangle &cliprect, int sx, int sy, int dimx, int dimy, int flipx, int flipy, int color, int addr)
321337{
322   igs017_state *state = machine.driver_data<igs017_state>();
323338   // prepare GfxElement on the fly
324339
325340   // Bounds checking
326   if ( addr + dimx * dimy >= state->m_sprites_gfx_size )
341   if ( addr + dimx * dimy >= m_sprites_gfx_size )
327342      return;
328343
329   gfx_element gfx(machine, state->m_sprites_gfx + addr, dimx, dimy, dimx, 0x100, 32);
344   gfx_element gfx(machine(), m_sprites_gfx + addr, dimx, dimy, dimx, 0x100, 32);
330345
331346   drawgfx_transpen(   bitmap,cliprect, &gfx,
332347            0, color,
r21026r21027
334349            sx, sy, 0x1f    );
335350}
336351
337static void draw_sprites(running_machine &machine, bitmap_ind16 &bitmap,const rectangle &cliprect)
352void igs017_state::draw_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect)
338353{
339   igs017_state *state = machine.driver_data<igs017_state>();
340   UINT8 *s    =   state->m_spriteram;
341   UINT8 *end  =   state->m_spriteram + 0x800;
354   UINT8 *s    =   m_spriteram;
355   UINT8 *end  =   m_spriteram + 0x800;
342356
343357   for ( ; s < end; s += 8 )
344358   {
r21026r21027
365379
366380      color = (s[7] & 0xe0) >> 5;
367381
368      draw_sprite(machine, bitmap, cliprect, sx, sy, dimx, dimy, flipx, flipy, color, addr);
382      draw_sprite(bitmap, cliprect, sx, sy, dimx, dimy, flipx, flipy, color, addr);
369383   }
370384}
371385
372386// A simple gfx viewer (toggle with T)
373static int debug_viewer(running_machine &machine, bitmap_ind16 &bitmap,const rectangle &cliprect)
387int igs017_state::debug_viewer(bitmap_ind16 &bitmap,const rectangle &cliprect)
374388{
375389#ifdef MAME_DEBUG
376   igs017_state *state = machine.driver_data<igs017_state>();
377   if (machine.input().code_pressed_once(KEYCODE_T))   state->m_toggle = 1-state->m_toggle;
378   if (state->m_toggle)    {
379      int h = 256, w = state->m_debug_width, a = state->m_debug_addr;
390   if (machine().input().code_pressed_once(KEYCODE_T))   m_toggle = 1-m_toggle;
391   if (m_toggle)    {
392      int h = 256, w = m_debug_width, a = m_debug_addr;
380393
381      if (machine.input().code_pressed(KEYCODE_O))        w += 1;
382      if (machine.input().code_pressed(KEYCODE_I))        w -= 1;
394      if (machine().input().code_pressed(KEYCODE_O))        w += 1;
395      if (machine().input().code_pressed(KEYCODE_I))        w -= 1;
383396
384      if (machine.input().code_pressed(KEYCODE_U))        w += 8;
385      if (machine.input().code_pressed(KEYCODE_Y))        w -= 8;
397      if (machine().input().code_pressed(KEYCODE_U))        w += 8;
398      if (machine().input().code_pressed(KEYCODE_Y))        w -= 8;
386399
387      if (machine.input().code_pressed(KEYCODE_RIGHT))    a += 1;
388      if (machine.input().code_pressed(KEYCODE_LEFT))     a -= 1;
400      if (machine().input().code_pressed(KEYCODE_RIGHT))    a += 1;
401      if (machine().input().code_pressed(KEYCODE_LEFT))     a -= 1;
389402
390      if (machine.input().code_pressed(KEYCODE_DOWN))     a += w;
391      if (machine.input().code_pressed(KEYCODE_UP))       a -= w;
403      if (machine().input().code_pressed(KEYCODE_DOWN))     a += w;
404      if (machine().input().code_pressed(KEYCODE_UP))       a -= w;
392405
393      if (machine.input().code_pressed(KEYCODE_PGDN))     a += w * h;
394      if (machine.input().code_pressed(KEYCODE_PGUP))     a -= w * h;
406      if (machine().input().code_pressed(KEYCODE_PGDN))     a += w * h;
407      if (machine().input().code_pressed(KEYCODE_PGUP))     a -= w * h;
395408
396409      if (a < 0)      a = 0;
397      if (a > state->m_sprites_gfx_size)  a = state->m_sprites_gfx_size;
410      if (a > m_sprites_gfx_size)  a = m_sprites_gfx_size;
398411
399412      if (w <= 0)     w = 0;
400413      if (w > 1024)   w = 1024;
r21026r21027
403416
404417      draw_sprite(machine, bitmap, cliprect, 0,0, w,h, 0,0, 0, a);
405418
406      popmessage("a: %08X w: %03X p: %02x-%02x-%02x",a,w,state->m_sprites_gfx[a/3*3+0],state->m_sprites_gfx[a/3*3+1],state->m_sprites_gfx[a/3*3+2]);
407      state->m_debug_addr = a;
408      state->m_debug_width = w;
419      popmessage("a: %08X w: %03X p: %02x-%02x-%02x",a,w,m_sprites_gfx[a/3*3+0],m_sprites_gfx[a/3*3+1],m_sprites_gfx[a/3*3+2]);
420      m_debug_addr = a;
421      m_debug_width = w;
409422      osd_sleep(200000);
410423      return 1;
411424   }
r21026r21027
428441   }
429442#endif
430443
431   if (debug_viewer(machine(), bitmap,cliprect))
444   if (debug_viewer(bitmap,cliprect))
432445      return 0;
433446
434447   bitmap.fill(get_black_pen(machine()), cliprect);
r21026r21027
438451
439452   if (layers_ctrl & 1)    m_bg_tilemap->draw(bitmap, cliprect, TILEMAP_DRAW_OPAQUE, 0);
440453
441   if (layers_ctrl & 4)    draw_sprites(machine(), bitmap, cliprect);
454   if (layers_ctrl & 4)    draw_sprites(bitmap, cliprect);
442455
443456   if (layers_ctrl & 2)    m_fg_tilemap->draw(bitmap, cliprect, 0, 0);
444457
r21026r21027
449462                                Decryption
450463***************************************************************************/
451464
452static void decrypt_program_rom(running_machine &machine, int mask, int a7, int a6, int a5, int a4, int a3, int a2, int a1, int a0)
465void igs017_state::decrypt_program_rom(int mask, int a7, int a6, int a5, int a4, int a3, int a2, int a1, int a0)
453466{
454   int length = machine.root_device().memregion("maincpu")->bytes();
455   UINT8 *rom = machine.root_device().memregion("maincpu")->base();
456   UINT8 *tmp = auto_alloc_array(machine, UINT8, length);
467   int length = machine().root_device().memregion("maincpu")->bytes();
468   UINT8 *rom = machine().root_device().memregion("maincpu")->base();
469   UINT8 *tmp = auto_alloc_array(machine(), UINT8, length);
457470   int i;
458471
459472   // decrypt the program ROM
r21026r21027
502515
503516// iqblocka
504517
505static void iqblocka_patch_rom(running_machine &machine)
518void igs017_state::iqblocka_patch_rom()
506519{
507   UINT8 *rom = machine.root_device().memregion("maincpu")->base();
520   UINT8 *rom = machine().root_device().memregion("maincpu")->base();
508521
509522//  rom[0x7b64] = 0xc9;
510523
r21026r21027
529542
530543DRIVER_INIT_MEMBER(igs017_state,iqblocka)
531544{
532   decrypt_program_rom(machine(), 0x11, 7, 6, 5, 4, 3, 2, 1, 0);
533   iqblocka_patch_rom(machine());
545   decrypt_program_rom(0x11, 7, 6, 5, 4, 3, 2, 1, 0);
546   iqblocka_patch_rom();
534547}
535548
536549// iqblockf
537550
538551DRIVER_INIT_MEMBER(igs017_state,iqblockf)
539552{
540   decrypt_program_rom(machine(), 0x11, 7, 6, 5, 4, 3, 2, 1, 0);
541//  iqblockf_patch_rom(machine());
553   decrypt_program_rom(0x11, 7, 6, 5, 4, 3, 2, 1, 0);
554//  iqblockf_patch_rom();
542555}
543556
544557// tjsb
545558
546static void tjsb_decrypt_sprites(running_machine &machine)
559void igs017_state::tjsb_decrypt_sprites()
547560{
548   int length = machine.root_device().memregion("sprites")->bytes();
549   UINT8 *rom = machine.root_device().memregion("sprites")->base();
550   UINT8 *tmp = auto_alloc_array(machine, UINT8, length);
561   int length = machine().root_device().memregion("sprites")->bytes();
562   UINT8 *rom = machine().root_device().memregion("sprites")->base();
563   UINT8 *tmp = auto_alloc_array(machine(), UINT8, length);
551564   int i, addr;
552565
553566   // address lines swap
r21026r21027
570583
571584DRIVER_INIT_MEMBER(igs017_state,tjsb)
572585{
573   decrypt_program_rom(machine(), 0x05, 7, 6, 3, 2, 5, 4, 1, 0);
586   decrypt_program_rom(0x05, 7, 6, 3, 2, 5, 4, 1, 0);
574587
575   tjsb_decrypt_sprites(machine());
588   tjsb_decrypt_sprites();
576589}
577590
578591
579592// mgcs
580593
581static void mgcs_decrypt_program_rom(running_machine &machine)
594void igs017_state::mgcs_decrypt_program_rom()
582595{
583596   int i;
584   UINT16 *src = (UINT16 *)machine.root_device().memregion("maincpu")->base();
597   UINT16 *src = (UINT16 *)machine().root_device().memregion("maincpu")->base();
585598
586599   int rom_size = 0x80000;
587600
r21026r21027
628641   }
629642}
630643
631static void mgcs_decrypt_tiles(running_machine &machine)
644void igs017_state::mgcs_decrypt_tiles()
632645{
633   int length = machine.root_device().memregion("tilemaps")->bytes();
634   UINT8 *rom = machine.root_device().memregion("tilemaps")->base();
635   UINT8 *tmp = auto_alloc_array(machine, UINT8, length);
646   int length = machine().root_device().memregion("tilemaps")->bytes();
647   UINT8 *rom = machine().root_device().memregion("tilemaps")->base();
648   UINT8 *tmp = auto_alloc_array(machine(), UINT8, length);
636649   int i;
637650
638651   memcpy(tmp,rom,length);
r21026r21027
642655      rom[i] = tmp[addr];
643656   }
644657
645   auto_free(machine, tmp);
658   auto_free(machine(), tmp);
646659}
647660
648static void mgcs_flip_sprites(running_machine &machine)
661void igs017_state::mgcs_flip_sprites()
649662{
650   int length = machine.root_device().memregion("sprites")->bytes();
651   UINT8 *rom = machine.root_device().memregion("sprites")->base();
663   int length = machine().root_device().memregion("sprites")->bytes();
664   UINT8 *rom = machine().root_device().memregion("sprites")->base();
652665   int i;
653666
654667   for (i = 0;i < length;i+=2)
r21026r21027
666679   }
667680}
668681
669static void mgcs_patch_rom(running_machine &machine)
682void igs017_state::mgcs_patch_rom()
670683{
671   UINT16 *rom = (UINT16 *)machine.root_device().memregion("maincpu")->base();
684   UINT16 *rom = (UINT16 *)machine().root_device().memregion("maincpu")->base();
672685
673686   rom[0x4e036/2] = 0x6006;
674687
r21026r21027
681694
682695DRIVER_INIT_MEMBER(igs017_state,mgcs)
683696{
684   mgcs_decrypt_program_rom(machine());
685   mgcs_patch_rom(machine());
697   mgcs_decrypt_program_rom();
698   mgcs_patch_rom();
686699
687   mgcs_decrypt_tiles(machine());
688   mgcs_flip_sprites(machine());
700   mgcs_decrypt_tiles();
701   mgcs_flip_sprites();
689702}
690703
691704
r21026r21027
741754
742755// decryption is incomplete: data decryption is correct but opcodes are encrypted differently.
743756
744static void starzan_decrypt(UINT8 *ROM, int size, bool isOpcode)
757void igs017_state::starzan_decrypt(UINT8 *ROM, int size, bool isOpcode)
745758{
746759   for(int i=0; i<size; i++)
747760   {
r21026r21027
802815
803816   machine().device("maincpu")->memory().space(AS_PROGRAM).set_decrypted_region(0x00000, 0x3ffff, code);
804817
805   mgcs_flip_sprites(machine());
818   mgcs_flip_sprites();
806819}
807820
808821
r21026r21027
896909      src[i] = x;
897910   }
898911
899   mgcs_flip_sprites(machine());
912   mgcs_flip_sprites();
900913}
901914
902915DRIVER_INIT_MEMBER(igs017_state,mgdh)
r21026r21027
913926// lhzb2
914927
915928
916static void lhzb2_patch_rom(running_machine &machine)
929void igs017_state::lhzb2_patch_rom()
917930{
918   UINT16 *rom = (UINT16 *)machine.root_device().memregion("maincpu")->base();
931   UINT16 *rom = (UINT16 *)machine().root_device().memregion("maincpu")->base();
919932
920933   // Prot. checks:
921934   rom[0x14786/2] = 0x6044;    // 014786: 6744    beq $147cc
r21026r21027
924937   rom[0x0b48a/2] = 0x604e;    // 00B48A: 674E    beq $b4da
925938}
926939
927static void lhzb2_decrypt_tiles(running_machine &machine)
940void igs017_state::lhzb2_decrypt_tiles()
928941{
929   int length = machine.root_device().memregion("tilemaps")->bytes();
930   UINT8 *rom = machine.root_device().memregion("tilemaps")->base();
931   UINT8 *tmp = auto_alloc_array(machine, UINT8, length);
942   int length = machine().root_device().memregion("tilemaps")->bytes();
943   UINT8 *rom = machine().root_device().memregion("tilemaps")->base();
944   UINT8 *tmp = auto_alloc_array(machine(), UINT8, length);
932945   int i;
933946
934947   int addr;
r21026r21027
939952      rom[i] = tmp[addr];
940953   }
941954
942   auto_free(machine, tmp);
955   auto_free(machine(), tmp);
943956}
944957
945static void lhzb2_decrypt_sprites(running_machine &machine)
958void igs017_state::lhzb2_decrypt_sprites()
946959{
947   int length = machine.root_device().memregion("sprites")->bytes();
948   UINT8 *rom = machine.root_device().memregion("sprites")->base();
949   UINT8 *tmp = auto_alloc_array(machine, UINT8, length);
960   int length = machine().root_device().memregion("sprites")->bytes();
961   UINT8 *rom = machine().root_device().memregion("sprites")->base();
962   UINT8 *tmp = auto_alloc_array(machine(), UINT8, length);
950963   int i, addr;
951964
952965   // address lines swap
r21026r21027
10531066      src[i] = x;
10541067   }
10551068
1056   lhzb2_decrypt_tiles(machine());
1057   lhzb2_decrypt_sprites(machine());
1058   lhzb2_patch_rom(machine());
1069   lhzb2_decrypt_tiles();
1070   lhzb2_decrypt_sprites();
1071   lhzb2_patch_rom();
10591072}
10601073
10611074
r21026r21027
11191132      src[i] = x;
11201133   }
11211134
1122   lhzb2_decrypt_tiles(machine());
1123   lhzb2_decrypt_sprites(machine());
1135   lhzb2_decrypt_tiles();
1136   lhzb2_decrypt_sprites();
11241137}
11251138
11261139
11271140//slqz2
11281141
1129static void slqz2_patch_rom(running_machine &machine)
1142void igs017_state::slqz2_patch_rom()
11301143{
1131   UINT16 *rom = (UINT16 *)machine.root_device().memregion("maincpu")->base();
1144   UINT16 *rom = (UINT16 *)machine().root_device().memregion("maincpu")->base();
11321145
11331146   // Prot. checks:
11341147   rom[0x1489c/2] = 0x6044;    // 01489C: 6744    beq $148e2
r21026r21027
11371150   rom[0x0b77a/2] = 0x604e;    // 00B77A: 674E    beq $b7ca
11381151}
11391152
1140static void slqz2_decrypt_tiles(running_machine &machine)
1153void igs017_state::slqz2_decrypt_tiles()
11411154{
1142   int length = machine.root_device().memregion("tilemaps")->bytes();
1143   UINT8 *rom = machine.root_device().memregion("tilemaps")->base();
1144   UINT8 *tmp = auto_alloc_array(machine, UINT8, length);
1155   int length = machine().root_device().memregion("tilemaps")->bytes();
1156   UINT8 *rom = machine().root_device().memregion("tilemaps")->base();
1157   UINT8 *tmp = auto_alloc_array(machine(), UINT8, length);
11451158   int i;
11461159
11471160   memcpy(tmp,rom,length);
r21026r21027
11511164      rom[i] = tmp[addr];
11521165   }
11531166
1154   auto_free(machine, tmp);
1167   auto_free(machine(), tmp);
11551168}
11561169
11571170DRIVER_INIT_MEMBER(igs017_state,slqz2)
r21026r21027
12301243      src[i] = x;
12311244   }
12321245
1233   slqz2_decrypt_tiles(machine());
1234   lhzb2_decrypt_sprites(machine());
1235   slqz2_patch_rom(machine());
1246   slqz2_decrypt_tiles();
1247   lhzb2_decrypt_sprites();
1248   slqz2_patch_rom();
12361249}
12371250
12381251/***************************************************************************
trunk/src/mame/drivers/cobra.c
r21026r21027
395395   void gfx_write_reg(running_machine &machine, UINT64 data);
396396
397397   void display(bitmap_rgb32 *bitmap, const rectangle &cliprect);
398
398   inline rgb_t texture_fetch(UINT32 *texture, int u, int v, int width, int format);
399399private:
400400   bitmap_rgb32 *m_framebuffer;
401401   bitmap_rgb32 *m_backbuffer;
r21026r21027
724724   UINT32 screen_update_cobra(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
725725   INTERRUPT_GEN_MEMBER(cobra_vblank);
726726   void cobra_video_exit();
727   int decode_debug_state_value(int v);
727728};
728729
729730void cobra_renderer::render_color_scan(INT32 scanline, const extent_t &extent, const cobra_polydata &extradata, int threadid)
r21026r21027
772773   }
773774}
774775
775INLINE rgb_t texture_fetch(UINT32 *texture, int u, int v, int width, int format)
776rgb_t cobra_renderer::texture_fetch(UINT32 *texture, int u, int v, int width, int format)
776777{
777778   UINT32 texel = texture[((v * width) + u) / 2];
778779
r21026r21027
10201021
10211022/*****************************************************************************/
10221023
1023static int decode_debug_state_value(int v)
1024int cobra_state::decode_debug_state_value(int v)
10241025{
10251026   switch (v)
10261027   {
trunk/src/mame/drivers/cntsteer.c
r21026r21027
9393   UINT32 screen_update_cntsteer(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
9494   UINT32 screen_update_zerotrgt(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
9595   INTERRUPT_GEN_MEMBER(sound_interrupt);
96   void zerotrgt_draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect );
97   void cntsteer_draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect );
98   void zerotrgt_rearrange_gfx( int romsize, int romarea );
9699};
97100
98101
r21026r21027
174177[2] xxxx xxxx X attribute
175178[3] xxxx xxxx sprite number
176179*/
177static void zerotrgt_draw_sprites( running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect )
180void cntsteer_state::zerotrgt_draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect )
178181{
179   cntsteer_state *state = machine.driver_data<cntsteer_state>();
180182   int offs;
181183
182184   for (offs = 0; offs < 0x200; offs += 4)
183185   {
184186      int multi, fx, fy, sx, sy, code, color;
185187
186      if ((state->m_spriteram[offs + 1] & 1) == 1)
188      if ((m_spriteram[offs + 1] & 1) == 1)
187189         continue;
188190
189      code = state->m_spriteram[offs + 3] + ((state->m_spriteram[offs + 1] & 0xc0) << 2);
190      sx = (state->m_spriteram[offs + 2]);
191      sy = 0xf0 - state->m_spriteram[offs];
192      color = 0x10 + ((state->m_spriteram[offs + 1] & 0x20) >> 4) + ((state->m_spriteram[offs + 1] & 0x8)>>3);
191      code = m_spriteram[offs + 3] + ((m_spriteram[offs + 1] & 0xc0) << 2);
192      sx = (m_spriteram[offs + 2]);
193      sy = 0xf0 - m_spriteram[offs];
194      color = 0x10 + ((m_spriteram[offs + 1] & 0x20) >> 4) + ((m_spriteram[offs + 1] & 0x8)>>3);
193195
194      fx = !(state->m_spriteram[offs + 1] & 0x04);
195      fy = (state->m_spriteram[offs + 1] & 0x02);
196      fx = !(m_spriteram[offs + 1] & 0x04);
197      fy = (m_spriteram[offs + 1] & 0x02);
196198
197      multi = state->m_spriteram[offs + 1] & 0x10;
199      multi = m_spriteram[offs + 1] & 0x10;
198200
199      if (state->m_flipscreen)
201      if (m_flipscreen)
200202      {
201203         sy = 240 - sy;
202204         sx = 240 - sx;
r21026r21027
209211      {
210212         if (fy)
211213         {
212            drawgfx_transpen(bitmap, cliprect, machine.gfx[1], code, color, fx, fy, sx, sy, 0);
213            drawgfx_transpen(bitmap, cliprect, machine.gfx[1], code + 1, color, fx, fy, sx, sy - 16, 0);
214            drawgfx_transpen(bitmap, cliprect, machine().gfx[1], code, color, fx, fy, sx, sy, 0);
215            drawgfx_transpen(bitmap, cliprect, machine().gfx[1], code + 1, color, fx, fy, sx, sy - 16, 0);
214216         }
215217         else
216218         {
217            drawgfx_transpen(bitmap, cliprect, machine.gfx[1], code, color, fx, fy, sx, sy - 16, 0);
218            drawgfx_transpen(bitmap, cliprect, machine.gfx[1], code + 1, color, fx, fy, sx, sy, 0);
219            drawgfx_transpen(bitmap, cliprect, machine().gfx[1], code, color, fx, fy, sx, sy - 16, 0);
220            drawgfx_transpen(bitmap, cliprect, machine().gfx[1], code + 1, color, fx, fy, sx, sy, 0);
219221         }
220222      }
221223      else
222         drawgfx_transpen(bitmap, cliprect, machine.gfx[1], code, color, fx, fy, sx, sy, 0);
224         drawgfx_transpen(bitmap, cliprect, machine().gfx[1], code, color, fx, fy, sx, sy, 0);
223225   }
224226}
225227
r21026r21027
232234     ---- --xx tile bank
233235*/
234236
235static void cntsteer_draw_sprites( running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect )
237void cntsteer_state::cntsteer_draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect )
236238{
237   cntsteer_state *state = machine.driver_data<cntsteer_state>();
238239   int offs;
239240
240241   for (offs = 0; offs < 0x80; offs += 4)
241242   {
242243      int multi, fx, fy, sx, sy, code, color;
243244
244      if ((state->m_spriteram[offs + 0] & 1) == 0)
245      if ((m_spriteram[offs + 0] & 1) == 0)
245246         continue;
246247
247      code = state->m_spriteram[offs + 1] + ((state->m_spriteram[offs + 0x80] & 0x03) << 8);
248      sx = 0x100 - state->m_spriteram[offs + 3];
249      sy = 0x100 - state->m_spriteram[offs + 2];
250      color = 0x10 + ((state->m_spriteram[offs + 0x80] & 0x70) >> 4);
248      code = m_spriteram[offs + 1] + ((m_spriteram[offs + 0x80] & 0x03) << 8);
249      sx = 0x100 - m_spriteram[offs + 3];
250      sy = 0x100 - m_spriteram[offs + 2];
251      color = 0x10 + ((m_spriteram[offs + 0x80] & 0x70) >> 4);
251252
252      fx = (state->m_spriteram[offs + 0] & 0x04);
253      fy = (state->m_spriteram[offs + 0] & 0x02);
253      fx = (m_spriteram[offs + 0] & 0x04);
254      fy = (m_spriteram[offs + 0] & 0x02);
254255
255      multi = state->m_spriteram[offs + 0] & 0x10;
256      multi = m_spriteram[offs + 0] & 0x10;
256257
257      if (state->m_flipscreen)
258      if (m_flipscreen)
258259      {
259260         sy = 240 - sy;
260261         sx = 240 - sx;
r21026r21027
267268      {
268269         if (fy)
269270         {
270            drawgfx_transpen(bitmap, cliprect, machine.gfx[1], code, color, fx, fy, sx, sy, 0);
271            drawgfx_transpen(bitmap, cliprect, machine.gfx[1], code + 1, color, fx, fy, sx, sy - 16, 0);
271            drawgfx_transpen(bitmap, cliprect, machine().gfx[1], code, color, fx, fy, sx, sy, 0);
272            drawgfx_transpen(bitmap, cliprect, machine().gfx[1], code + 1, color, fx, fy, sx, sy - 16, 0);
272273         }
273274         else
274275         {
275            drawgfx_transpen(bitmap, cliprect, machine.gfx[1], code, color, fx, fy, sx, sy - 16, 0);
276            drawgfx_transpen(bitmap, cliprect, machine.gfx[1], code + 1, color, fx, fy, sx, sy, 0);
276            drawgfx_transpen(bitmap, cliprect, machine().gfx[1], code, color, fx, fy, sx, sy - 16, 0);
277            drawgfx_transpen(bitmap, cliprect, machine().gfx[1], code + 1, color, fx, fy, sx, sy, 0);
277278         }
278279      }
279280      else
280         drawgfx_transpen(bitmap, cliprect, machine.gfx[1], code, color, fx, fy, sx, sy, 0);
281         drawgfx_transpen(bitmap, cliprect, machine().gfx[1], code, color, fx, fy, sx, sy, 0);
281282   }
282283}
283284
r21026r21027
324325                  0, 0);
325326   }
326327
327   zerotrgt_draw_sprites(machine(), bitmap, cliprect);
328   zerotrgt_draw_sprites(bitmap, cliprect);
328329   m_fg_tilemap->draw(bitmap, cliprect, 0, 0);
329330
330331   return 0;
r21026r21027
371372                  0, 0);
372373   }
373374
374   cntsteer_draw_sprites(machine(), bitmap, cliprect);
375   cntsteer_draw_sprites(bitmap, cliprect);
375376   m_fg_tilemap->draw(bitmap, cliprect, 0, 0);
376377
377378   return 0;
r21026r21027
11391140
11401141/***************************************************************************/
11411142
1142static void zerotrgt_rearrange_gfx( running_machine &machine, int romsize, int romarea )
1143void cntsteer_state::zerotrgt_rearrange_gfx( int romsize, int romarea )
11431144{
1144   UINT8 *src = machine.root_device().memregion("gfx4")->base();
1145   UINT8 *dst = machine.root_device().memregion("gfx3")->base();
1145   UINT8 *src = machine().root_device().memregion("gfx4")->base();
1146   UINT8 *dst = machine().root_device().memregion("gfx3")->base();
11461147   int rm;
11471148   int cnt1;
11481149
r21026r21027
11741175
11751176DRIVER_INIT_MEMBER(cntsteer_state,zerotrgt)
11761177{
1177   zerotrgt_rearrange_gfx(machine(), 0x02000, 0x10000);
1178   zerotrgt_rearrange_gfx(0x02000, 0x10000);
11781179}
11791180
11801181
trunk/src/mame/drivers/galpani3.c
r21026r21027
114114   virtual void video_start();
115115   UINT32 screen_update_galpani3(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
116116   TIMER_DEVICE_CALLBACK_MEMBER(galpani3_vblank);
117   int gp3_is_alpha_pen(int pen);
117118};
118119
119120
r21026r21027
150151
151152
152153
153static int gp3_is_alpha_pen(running_machine &machine, int pen)
154int galpani3_state::gp3_is_alpha_pen(int pen)
154155{
155   galpani3_state *state = machine.driver_data<galpani3_state>();
156156   UINT16 dat = 0;
157157
158158   if (pen<0x4000)
159159   {
160      dat = state->m_generic_paletteram_16[pen];
160      dat = m_generic_paletteram_16[pen];
161161   }
162162   else if (pen<0x4100)
163163   {
164      dat = state->m_grap2_0->m_framebuffer_palette[pen&0xff];
164      dat = m_grap2_0->m_framebuffer_palette[pen&0xff];
165165   }
166166   else if (pen<0x4200)
167167   {
168      dat = state->m_grap2_1->m_framebuffer_palette[pen&0xff];
168      dat = m_grap2_1->m_framebuffer_palette[pen&0xff];
169169   }
170170   else if (pen<0x4300)
171171   {
172      dat = state->m_grap2_2->m_framebuffer_palette[pen&0xff];
172      dat = m_grap2_2->m_framebuffer_palette[pen&0xff];
173173   }
174174   else if (pen<0x4301)
175175   {
176      dat = state->m_grap2_0->m_framebuffer_bgcol;
176      dat = m_grap2_0->m_framebuffer_bgcol;
177177   }
178178   else if (pen<0x4302)
179179   {
180      dat = state->m_grap2_1->m_framebuffer_bgcol;
180      dat = m_grap2_1->m_framebuffer_bgcol;
181181   }
182182   else if (pen<0x4303)
183183   {
184      dat = state->m_grap2_2->m_framebuffer_bgcol;
184      dat = m_grap2_2->m_framebuffer_bgcol;
185185   }
186186
187187   if (dat&0x8000) return 1;
r21026r21027
259259                  UINT16 pen = dat1+0x4000;
260260                  UINT32 pal = paldata[pen];
261261
262                  if (gp3_is_alpha_pen(machine(), pen))
262                  if (gp3_is_alpha_pen(pen))
263263                  {
264264                     int r,g,b;
265265                     r = (pal & 0x00ff0000)>>16;
r21026r21027
287287                  UINT16 pen = dat2+0x4100;
288288                  UINT32 pal = paldata[pen];
289289
290                  if (gp3_is_alpha_pen(machine(), pen))
290                  if (gp3_is_alpha_pen(pen))
291291                  {
292292                     int r,g,b;
293293                     r = (pal & 0x00ff0000)>>16;
trunk/src/mame/drivers/maxaflex.c
r21026r21027
6060   DECLARE_DRIVER_INIT(a600xl);
6161   DECLARE_MACHINE_RESET(supervisor_board);
6262   TIMER_DEVICE_CALLBACK_MEMBER(mcu_timer_proc);
63   int atari_input_disabled();
6364};
6465
6566
r21026r21027
263264      machine().device("mcu")->execute().set_input_line(M6805_IRQ_LINE, HOLD_LINE );
264265}
265266
266int atari_input_disabled(running_machine &machine)
267int maxaflex_state::atari_input_disabled()
267268{
268   maxaflex_state *state = machine.driver_data<maxaflex_state>();
269   return (state->m_portB_out & 0x80) == 0x00;
269   return (m_portB_out & 0x80) == 0x00;
270270}
271271
272272
r21026r21027
373373
374374READ8_MEMBER(maxaflex_state::maxaflex_atari_pia_pa_r)
375375{
376   return atari_input_disabled(machine()) ? 0xFF : machine().root_device().ioport("djoy_0_1")->read_safe(0);
376   return atari_input_disabled() ? 0xFF : machine().root_device().ioport("djoy_0_1")->read_safe(0);
377377}
378378
379379READ8_MEMBER(maxaflex_state::maxaflex_atari_pia_pb_r)
380380{
381   return atari_input_disabled(machine()) ? 0xFF : machine().root_device().ioport("djoy_2_3")->read_safe(0);
381   return atari_input_disabled() ? 0xFF : machine().root_device().ioport("djoy_2_3")->read_safe(0);
382382}
383383
384384
trunk/src/mame/drivers/chanbara.c
r21026r21027
9393   virtual void video_start();
9494   virtual void palette_init();
9595   UINT32 screen_update_chanbara(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
96   void draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect );
9697};
9798
9899
r21026r21027
159160   m_bg_tilemap->set_transparent_pen(0);
160161}
161162
162static void draw_sprites( running_machine &machine, bitmap_ind16 &bitmap, const rectangle &cliprect )
163void chanbara_state::draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect )
163164{
164   chanbara_state *state = machine.driver_data<chanbara_state>();
165165   int offs;
166166
167167   for (offs = 0; offs < 0x80; offs += 4)
168168   {
169      if (state->m_spriteram[offs + 0x80] & 0x80)
169      if (m_spriteram[offs + 0x80] & 0x80)
170170      {
171         int attr = state->m_spriteram[offs + 0];
172         int code = state->m_spriteram[offs + 1];
173         int color = state->m_spriteram[offs + 0x80] & 0x1f;
171         int attr = m_spriteram[offs + 0];
172         int code = m_spriteram[offs + 1];
173         int color = m_spriteram[offs + 0x80] & 0x1f;
174174         int flipx = 0;
175175         int flipy = attr & 2;
176         int sx = 240 - state->m_spriteram[offs + 3];
177         int sy = 232 - state->m_spriteram[offs + 2];
176         int sx = 240 - m_spriteram[offs + 3];
177         int sy = 232 - m_spriteram[offs + 2];
178178
179179         sy+=16;
180180
181         if (state->m_spriteram[offs + 0x80] & 0x10) code += 0x200;
182         if (state->m_spriteram[offs + 0x80] & 0x20) code += 0x400;
183         if (state->m_spriteram[offs + 0x80] & 0x40) code += 0x100;
181         if (m_spriteram[offs + 0x80] & 0x10) code += 0x200;
182         if (m_spriteram[offs + 0x80] & 0x20) code += 0x400;
183         if (m_spriteram[offs + 0x80] & 0x40) code += 0x100;
184184
185185         if (attr & 0x10)
186186         {
187187            if (!flipy)
188188            {
189               drawgfx_transpen(bitmap, cliprect, machine.gfx[1], code, color, flipx, flipy, sx, sy-16, 0);
190               drawgfx_transpen(bitmap, cliprect, machine.gfx[1], code+1, color, flipx, flipy, sx, sy, 0);
189               drawgfx_transpen(bitmap, cliprect, machine().gfx[1], code, color, flipx, flipy, sx, sy-16, 0);
190               drawgfx_transpen(bitmap, cliprect, machine().gfx[1], code+1, color, flipx, flipy, sx, sy, 0);
191191            }
192192            else
193193            {
194               drawgfx_transpen(bitmap, cliprect, machine.gfx[1], code, color, flipx, flipy, sx, sy, 0);
195               drawgfx_transpen(bitmap, cliprect, machine.gfx[1], code+1, color, flipx, flipy, sx, sy-16, 0);
194               drawgfx_transpen(bitmap, cliprect, machine().gfx[1], code, color, flipx, flipy, sx, sy, 0);
195               drawgfx_transpen(bitmap, cliprect, machine().gfx[1], code+1, color, flipx, flipy, sx, sy-16, 0);
196196            }
197197         }
198198         else
199199         {
200            drawgfx_transpen(bitmap, cliprect, machine.gfx[1], code, color, flipx, flipy, sx, sy, 0);
200            drawgfx_transpen(bitmap, cliprect, machine().gfx[1], code, color, flipx, flipy, sx, sy, 0);
201201         }
202202      }
203203   }
r21026r21027
207207{
208208   m_bg2_tilemap->set_scrolly(0, m_scroll | (m_scrollhi << 8));
209209   m_bg2_tilemap->draw(bitmap, cliprect, 0, 0);
210   draw_sprites(machine(), bitmap, cliprect);
210   draw_sprites(bitmap, cliprect);
211211   m_bg_tilemap->draw(bitmap, cliprect, 0, 0);
212212   return 0;
213213}
trunk/src/mame/drivers/mpu4vid.c
r21026r21027
298298   DECLARE_WRITE8_MEMBER(vid_o2_callback);
299299   DECLARE_WRITE8_MEMBER(vid_o3_callback);
300300   DECLARE_READ8_MEMBER(pia_ic5_porta_track_r);
301   void mpu4vid_char_cheat( int address);
301302};
302303
303304
r21026r21027
20182019   m_current_chr_table = prizeinv_data;
20192020}
20202021
2021void mpu4vid_char_cheat(running_machine& machine, int address)
2022void mpu4vid_state::mpu4vid_char_cheat( int address)
20222023{
2023   mpu4_state *state = machine.driver_data<mpu4_state>();
2024   UINT8* cheattable = state->memregion( "video" )->base()+address;
2025   state->m_current_chr_table = blank_data;
2024   UINT8* cheattable = memregion( "video" )->base()+address;
2025   m_current_chr_table = blank_data;
20262026   for (int i=0;i<72;i++)
20272027   {
2028      state->m_current_chr_table[i].response = cheattable++[0];
2029      state->m_current_chr_table[i].call = cheattable++[0];
2028      m_current_chr_table[i].response = cheattable++[0];
2029      m_current_chr_table[i].call = cheattable++[0];
20302030   }
20312031}
20322032
20332033DRIVER_INIT_MEMBER(mpu4vid_state,v4barqst)
20342034{
2035   mpu4vid_char_cheat(machine(),0x154);
2035   mpu4vid_char_cheat(0x154);
20362036}
20372037
20382038DRIVER_INIT_MEMBER(mpu4vid_state,v4barqst2)
20392039{
2040   mpu4vid_char_cheat(machine(),0x15c);
2040   mpu4vid_char_cheat(0x15c);
20412041}
20422042
20432043DRIVER_INIT_MEMBER(mpu4vid_state,v4wize)
20442044{
2045   mpu4vid_char_cheat(machine(),0x16c);
2045   mpu4vid_char_cheat(0x16c);
20462046}
20472047
20482048DRIVER_INIT_MEMBER(mpu4vid_state,v4cmazeb)
20492049{
2050   mpu4vid_char_cheat(machine(),0x4c6);
2050   mpu4vid_char_cheat(0x4c6);
20512051}
20522052
20532053DRIVER_INIT_MEMBER(mpu4vid_state,v4opt3)
20542054{
2055   mpu4vid_char_cheat(machine(),0x164);
2055   mpu4vid_char_cheat(0x164);
20562056}
20572057
20582058
trunk/src/mame/drivers/silvmil.c
r21026r21027
113113   virtual void machine_reset();
114114   virtual void video_start();
115115   UINT32 screen_update_silvmil(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
116   void tumblepb_gfx1_rearrange();
116117};
117118
118119
r21026r21027
394395ROM_END
395396
396397
397static void tumblepb_gfx1_rearrange(running_machine &machine)
398void silvmil_state::tumblepb_gfx1_rearrange()
398399{
399   UINT8 *rom = machine.root_device().memregion("gfx1")->base();
400   int len = machine.root_device().memregion("gfx1")->bytes();
400   UINT8 *rom = machine().root_device().memregion("gfx1")->base();
401   int len = machine().root_device().memregion("gfx1")->bytes();
401402   int i;
402403
403404   /* gfx data is in the wrong order */
r21026r21027
417418
418419DRIVER_INIT_MEMBER(silvmil_state,silvmil)
419420{
420   tumblepb_gfx1_rearrange(machine());
421   tumblepb_gfx1_rearrange();
421422}
422423
423424GAME( 1995, silvmil, 0, silvmil, silvmil, silvmil_state, silvmil, ROT270, "Para", "Silver Millennium", 0 )
trunk/src/mame/drivers/pengadvb.c
r21026r21027
4747   virtual void machine_start();
4848   virtual void machine_reset();
4949   void pengadvb_postload();
50   void mem_map_banks();
51   void pengadvb_decrypt(const char* region);
5052};
5153
5254
5355
54static void mem_map_banks(running_machine &machine)
56void pengadvb_state::mem_map_banks()
5557{
56   pengadvb_state *state = machine.driver_data<pengadvb_state>();
5758   /*  memorymap: (rest is assumed unmapped)
5859       slot 0
5960           0000-7fff   BIOS ROM
r21026r21027
6465   */
6566
6667   // page 0 (0000-3fff)
67   switch(state->m_mem_map & 3)
68   switch(m_mem_map & 3)
6869   {
6970      case 0:
7071         // BIOS
71         machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x0000, 0x3fff, "bank1" );
72         state->membank("bank1")->set_base(state->memregion("maincpu")->base());
72         machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x0000, 0x3fff, "bank1" );
73         membank("bank1")->set_base(memregion("maincpu")->base());
7374         break;
7475
7576      default:
76         machine.device("maincpu")->memory().space(AS_PROGRAM).unmap_read(0x0000, 0x3fff);
77         machine().device("maincpu")->memory().space(AS_PROGRAM).unmap_read(0x0000, 0x3fff);
7778         break;
7879   }
7980
8081   // page 1 (4000-7fff)
81   switch(state->m_mem_map >> 2 & 3)
82   switch(m_mem_map >> 2 & 3)
8283   {
8384      case 0:
8485         // BIOS
85         machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x4000, 0x5fff, "bank21" );
86         machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x6000, 0x7fff, "bank22" );
87         state->membank("bank21")->set_base(machine.root_device().memregion("maincpu")->base() + 0x4000);
88         state->membank("bank22")->set_base(machine.root_device().memregion("maincpu")->base() + 0x4000 + 0x2000);
86         machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x4000, 0x5fff, "bank21" );
87         machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x6000, 0x7fff, "bank22" );
88         membank("bank21")->set_base(machine().root_device().memregion("maincpu")->base() + 0x4000);
89         membank("bank22")->set_base(machine().root_device().memregion("maincpu")->base() + 0x4000 + 0x2000);
8990         break;
9091
9192      case 1:
9293         // game
93         machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x4000, 0x5fff, "bank21" );
94         machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x6000, 0x7fff, "bank22" );
95         state->membank("bank21")->set_base(machine.root_device().memregion("game")->base() + state->m_mem_banks[0]*0x2000);
96         state->membank("bank22")->set_base(machine.root_device().memregion("game")->base() + state->m_mem_banks[1]*0x2000);
94         machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x4000, 0x5fff, "bank21" );
95         machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x6000, 0x7fff, "bank22" );
96         membank("bank21")->set_base(machine().root_device().memregion("game")->base() + m_mem_banks[0]*0x2000);
97         membank("bank22")->set_base(machine().root_device().memregion("game")->base() + m_mem_banks[1]*0x2000);
9798         break;
9899
99100      default:
100         machine.device("maincpu")->memory().space(AS_PROGRAM).unmap_read(0x4000, 0x7fff);
101         machine().device("maincpu")->memory().space(AS_PROGRAM).unmap_read(0x4000, 0x7fff);
101102         break;
102103   }
103104
104105   // page 2 (8000-bfff)
105   switch(state->m_mem_map >> 4 & 3)
106   switch(m_mem_map >> 4 & 3)
106107   {
107108      case 1:
108109         // game
109         machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x8000, 0x9fff, "bank31" );
110         machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0xa000, 0xbfff, "bank32" );
111         state->membank("bank31")->set_base(machine.root_device().memregion("game")->base() + state->m_mem_banks[2]*0x2000);
112         state->membank("bank32")->set_base(machine.root_device().memregion("game")->base() + state->m_mem_banks[3]*0x2000);
110         machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0x8000, 0x9fff, "bank31" );
111         machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0xa000, 0xbfff, "bank32" );
112         membank("bank31")->set_base(machine().root_device().memregion("game")->base() + m_mem_banks[2]*0x2000);
113         membank("bank32")->set_base(machine().root_device().memregion("game")->base() + m_mem_banks[3]*0x2000);
113114         break;
114115
115116      default:
116         machine.device("maincpu")->memory().space(AS_PROGRAM).unmap_read(0x8000, 0xbfff);
117         machine().device("maincpu")->memory().space(AS_PROGRAM).unmap_read(0x8000, 0xbfff);
117118         break;
118119   }
119120
120121   // page 3 (c000-ffff)
121   switch(state->m_mem_map >> 6 & 3)
122   switch(m_mem_map >> 6 & 3)
122123   {
123124      case 3:
124125         // RAM
125         machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0xc000, 0xffff, "bank4" );
126         state->membank("bank4")->set_base(state->m_main_mem);
126         machine().device("maincpu")->memory().space(AS_PROGRAM).install_read_bank(0xc000, 0xffff, "bank4" );
127         membank("bank4")->set_base(m_main_mem);
127128         break;
128129
129130      default:
130         machine.device("maincpu")->memory().space(AS_PROGRAM).unmap_read(0xc000, 0xffff);
131         machine().device("maincpu")->memory().space(AS_PROGRAM).unmap_read(0xc000, 0xffff);
131132         break;
132133   }
133134}
r21026r21027
144145   {
145146      // ROM bankswitch
146147      m_mem_banks[(offset - 0x4000) >> 13] = data & 0xf;
147      mem_map_banks(machine());
148      mem_map_banks();
148149   }
149150}
150151
r21026r21027
210211   if (data != m_mem_map)
211212   {
212213      m_mem_map = data;
213      mem_map_banks(machine());
214      mem_map_banks();
214215   }
215216}
216217
r21026r21027
247248
248249void pengadvb_state::pengadvb_postload()
249250{
250   mem_map_banks(machine());
251   mem_map_banks();
251252}
252253
253254void pengadvb_state::machine_start()
r21026r21027
262263{
263264   m_mem_map = 0;
264265   m_mem_banks[0] = m_mem_banks[1] = m_mem_banks[2] = m_mem_banks[3] = 0;
265   mem_map_banks(machine());
266   mem_map_banks();
266267}
267268
268269
r21026r21027
287288   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
288289MACHINE_CONFIG_END
289290
290static void pengadvb_decrypt(running_machine &machine, const char* region)
291void pengadvb_state::pengadvb_decrypt(const char* region)
291292{
292   UINT8 *mem = machine.root_device().memregion(region)->base();
293   int memsize = machine.root_device().memregion(region)->bytes();
293   UINT8 *mem = machine().root_device().memregion(region)->base();
294   int memsize = machine().root_device().memregion(region)->bytes();
294295   UINT8 *buf;
295296   int i;
296297
r21026r21027
301302   }
302303
303304   // address line swap
304   buf = auto_alloc_array(machine, UINT8, memsize);
305   buf = auto_alloc_array(machine(), UINT8, memsize);
305306   memcpy(buf, mem, memsize);
306307   for ( i = 0; i < memsize; i++ )
307308   {
308309      mem[i] = buf[BITSWAP24(i,23,22,21,20,19,18,17,16,15,14,13,5,11,10,9,8,7,6,12,4,3,2,1,0)];
309310   }
310   auto_free(machine, buf);
311   auto_free(machine(), buf);
311312}
312313
313314DRIVER_INIT_MEMBER(pengadvb_state,pengadvb)
314315{
315   pengadvb_decrypt(machine(), "maincpu");
316   pengadvb_decrypt(machine(), "game");
316   pengadvb_decrypt("maincpu");
317   pengadvb_decrypt("game");
317318
318319   m_main_mem = auto_alloc_array(machine(), UINT8, 0x4000);
319320}
trunk/src/mame/drivers/konamigq.c
r21026r21027
8484   DECLARE_DRIVER_INIT(konamigq);
8585   DECLARE_MACHINE_START(konamigq);
8686   DECLARE_MACHINE_RESET(konamigq);
87   void scsi_dma_read( UINT32 *p_n_psxram, UINT32 n_address, INT32 n_size );
88   void scsi_dma_write( UINT32 *p_n_psxram, UINT32 n_address, INT32 n_size );
8789};
8890
8991/* Sound */
r21026r21027
250252
251253/* SCSI */
252254
253static void scsi_dma_read( konamigq_state *state, UINT32 *p_n_psxram, UINT32 n_address, INT32 n_size )
255void konamigq_state::scsi_dma_read( UINT32 *p_n_psxram, UINT32 n_address, INT32 n_size )
254256{
255   UINT8 *sector_buffer = state->m_sector_buffer;
257   UINT8 *sector_buffer = m_sector_buffer;
256258   int i;
257259   int n_this;
258260
259261   while( n_size > 0 )
260262   {
261      if( n_size > sizeof( state->m_sector_buffer ) / 4 )
263      if( n_size > sizeof( m_sector_buffer ) / 4 )
262264      {
263         n_this = sizeof( state->m_sector_buffer ) / 4;
265         n_this = sizeof( m_sector_buffer ) / 4;
264266      }
265267      else
266268      {
267269         n_this = n_size;
268270      }
269      state->m_am53cf96->dma_read_data( n_this * 4, sector_buffer );
271      m_am53cf96->dma_read_data( n_this * 4, sector_buffer );
270272      n_size -= n_this;
271273
272274      i = 0;
r21026r21027
284286   }
285287}
286288
287static void scsi_dma_write( konamigq_state *state, UINT32 *p_n_psxram, UINT32 n_address, INT32 n_size )
289void konamigq_state::scsi_dma_write( UINT32 *p_n_psxram, UINT32 n_address, INT32 n_size )
288290{
289291}
290292
r21026r21027
310312   MCFG_CPU_ADD( "maincpu", CXD8530BQ, XTAL_67_7376MHz )
311313   MCFG_CPU_PROGRAM_MAP( konamigq_map )
312314
313   MCFG_PSX_DMA_CHANNEL_READ( "maincpu", 5, psx_dma_read_delegate( FUNC( scsi_dma_read ), (konamigq_state *) owner ) )
314   MCFG_PSX_DMA_CHANNEL_WRITE( "maincpu", 5, psx_dma_write_delegate( FUNC( scsi_dma_write ), (konamigq_state *) owner ) )
315   MCFG_PSX_DMA_CHANNEL_READ( "maincpu", 5, psx_dma_read_delegate( FUNC( konamigq_state::scsi_dma_read ), (konamigq_state *) owner ) )
316   MCFG_PSX_DMA_CHANNEL_WRITE( "maincpu", 5, psx_dma_write_delegate( FUNC( konamigq_state::scsi_dma_write ), (konamigq_state *) owner ) )
315317
316318   MCFG_CPU_ADD( "soundcpu", M68000, 8000000 )
317319   MCFG_CPU_PROGRAM_MAP( konamigq_sound_map)
trunk/src/mame/drivers/bfm_sc2.c
r21026r21027
304304   DECLARE_MACHINE_START(sc2dmd);
305305   DECLARE_MACHINE_RESET(dm01_init);
306306   INTERRUPT_GEN_MEMBER(timer_irq);
307   void on_scorpion2_reset();
308   void Scorpion2_SetSwitchState(int strobe, int data, int state);
309   int Scorpion2_GetSwitchState(int strobe, int data);
310   void e2ram_reset();
311   int recAck(int changed, int data);
312   int read_e2ram();
313   int sc2_find_project_string( );
314   void sc2_common_init(int decrypt);
315   void adder2_common_init();
316   void sc2awp_common_init(int reels, int decrypt);
317   void sc2awpdmd_common_init(int reels, int decrypt);
307318};
308319
309320
r21026r21027
320331
321332#define MASTER_CLOCK        (XTAL_8MHz)
322333
323// local prototypes ///////////////////////////////////////////////////////
324
325static int  read_e2ram(running_machine &machine);
326static void e2ram_reset(running_machine &machine);
327
328334/*      INPUTS layout
329335
330336     b7 b6 b5 b4 b3 b2 b1 b0
r21026r21027
347353// called if board is reset ///////////////////////////////////////////////
348354///////////////////////////////////////////////////////////////////////////
349355
350static void on_scorpion2_reset(running_machine &machine)
356void bfm_sc2_state::on_scorpion2_reset()
351357{
352   bfm_sc2_state *state = machine.driver_data<bfm_sc2_state>();
353   state->m_mmtr_latch        = 0;
354   state->m_triac_latch       = 0;
355   state->m_irq_status        = 0;
356   state->m_is_timer_enabled  = 1;
357   state->m_coin_inhibits     = 0;
358   state->m_irq_timer_stat    = 0;
359   state->m_expansion_latch   = 0;
360   state->m_global_volume     = 0;
361   state->m_volume_override   = 0;
362   state->m_triac_select      = 0;
363   state->m_pay_latch         = 0;
358   m_mmtr_latch        = 0;
359   m_triac_latch       = 0;
360   m_irq_status        = 0;
361   m_is_timer_enabled  = 1;
362   m_coin_inhibits     = 0;
363   m_irq_timer_stat    = 0;
364   m_expansion_latch   = 0;
365   m_global_volume     = 0;
366   m_volume_override   = 0;
367   m_triac_select      = 0;
368   m_pay_latch         = 0;
364369
365   state->m_reel12_latch      = 0;
366   state->m_reel34_latch      = 0;
367   state->m_reel56_latch      = 0;
370   m_reel12_latch      = 0;
371   m_reel34_latch      = 0;
372   m_reel56_latch      = 0;
368373
369   state->m_hopper_running    = 0;  // for video games
370   state->m_hopper_coin_sense = 0;
374   m_hopper_running    = 0;  // for video games
375   m_hopper_coin_sense = 0;
371376
372   state->m_slide_states[0] = 0;
373   state->m_slide_states[1] = 0;
374   state->m_slide_states[2] = 0;
375   state->m_slide_states[3] = 0;
376   state->m_slide_states[4] = 0;
377   state->m_slide_states[5] = 0;
377   m_slide_states[0] = 0;
378   m_slide_states[1] = 0;
379   m_slide_states[2] = 0;
380   m_slide_states[3] = 0;
381   m_slide_states[4] = 0;
382   m_slide_states[5] = 0;
378383
379   e2ram_reset(machine);
384   e2ram_reset();
380385
381   machine.device("ymsnd")->reset();
386   machine().device("ymsnd")->reset();
382387
383388   // reset stepper motors /////////////////////////////////////////////////
384389   {
385390      int pattern =0, i;
386391
387      for ( i = 0; i < state->m_reels; i++)
392      for ( i = 0; i < m_reels; i++)
388393      {
389394         stepper_reset_position(i);
390395         if ( stepper_optic_state(i) ) pattern |= 1<<i;
391396      }
392397
393      state->m_optic_pattern = pattern;
398      m_optic_pattern = pattern;
394399
395400   }
396401
397   state->m_locked        = 0;
402   m_locked        = 0;
398403
399404   // make sure no inputs are overidden ////////////////////////////////////
400   memset(state->m_input_override, 0, sizeof(state->m_input_override));
405   memset(m_input_override, 0, sizeof(m_input_override));
401406
402407   // init rom bank ////////////////////////////////////////////////////////
403408
404409   {
405      UINT8 *rom = machine.root_device().memregion("maincpu")->base();
410      UINT8 *rom = machine().root_device().memregion("maincpu")->base();
406411
407      state->membank("bank1")->configure_entries(0, 4, &rom[0x00000], 0x02000);
412      membank("bank1")->configure_entries(0, 4, &rom[0x00000], 0x02000);
408413
409      state->membank("bank1")->set_entry(3);
414      membank("bank1")->set_entry(3);
410415   }
411416}
412417
413418///////////////////////////////////////////////////////////////////////////
414419
415void Scorpion2_SetSwitchState(running_machine &machine, int strobe, int data, int state)
420void bfm_sc2_state::Scorpion2_SetSwitchState(int strobe, int data, int state)
416421{
417   bfm_sc2_state *drvstate = machine.driver_data<bfm_sc2_state>();
418422   if ( strobe < 11 && data < 8 )
419423   {
420424      if ( strobe < 8 )
421425      {
422         drvstate->m_input_override[strobe] |= (1<<data);
426         m_input_override[strobe] |= (1<<data);
423427
424         if ( state ) drvstate->m_sc2_Inputs[strobe] |=  (1<<data);
425         else         drvstate->m_sc2_Inputs[strobe] &= ~(1<<data);
428         if ( state ) m_sc2_Inputs[strobe] |=  (1<<data);
429         else         m_sc2_Inputs[strobe] &= ~(1<<data);
426430      }
427431      else
428432      {
429433         if ( data > 2 )
430434         {
431            drvstate->m_input_override[strobe-8+4] |= (1<<(data+2));
435            m_input_override[strobe-8+4] |= (1<<(data+2));
432436
433            if ( state ) drvstate->m_sc2_Inputs[strobe-8+4] |=  (1<<(data+2));
434            else         drvstate->m_sc2_Inputs[strobe-8+4] &= ~(1<<(data+2));
437            if ( state ) m_sc2_Inputs[strobe-8+4] |=  (1<<(data+2));
438            else         m_sc2_Inputs[strobe-8+4] &= ~(1<<(data+2));
435439         }
436440         else
437441         {
438            drvstate->m_input_override[strobe-8] |= (1<<(data+5));
442            m_input_override[strobe-8] |= (1<<(data+5));
439443
440            if ( state ) drvstate->m_sc2_Inputs[strobe-8] |=  (1 << (data+5));
441            else         drvstate->m_sc2_Inputs[strobe-8] &= ~(1 << (data+5));
444            if ( state ) m_sc2_Inputs[strobe-8] |=  (1 << (data+5));
445            else         m_sc2_Inputs[strobe-8] &= ~(1 << (data+5));
442446         }
443447      }
444448   }
r21026r21027
446450
447451///////////////////////////////////////////////////////////////////////////
448452
449int Scorpion2_GetSwitchState(running_machine &machine, int strobe, int data)
453int bfm_sc2_state::Scorpion2_GetSwitchState(int strobe, int data)
450454{
451   bfm_sc2_state *drvstate = machine.driver_data<bfm_sc2_state>();
452455   int state = 0;
453456
454457   if ( strobe < 11 && data < 8 )
455458   {
456459      if ( strobe < 8 )
457460      {
458         state = (drvstate->m_sc2_Inputs[strobe] & (1<<data) ) ? 1 : 0;
461         state = (m_sc2_Inputs[strobe] & (1<<data) ) ? 1 : 0;
459462      }
460463      else
461464      {
462465         if ( data > 2 )
463466         {
464            state = (drvstate->m_sc2_Inputs[strobe-8+4] & (1<<(data+2)) ) ? 1 : 0;
467            state = (m_sc2_Inputs[strobe-8+4] & (1<<(data+2)) ) ? 1 : 0;
465468         }
466469         else
467470         {
468            state = (drvstate->m_sc2_Inputs[strobe-8] & (1 << (data+5)) ) ? 1 : 0;
471            state = (m_sc2_Inputs[strobe-8] & (1 << (data+5)) ) ? 1 : 0;
469472         }
470473      }
471474   }
r21026r21027
915918               {
916919                  int strobe = m_slide_pay_sensor[slide]>>4, data = m_slide_pay_sensor[slide]&0x0F;
917920
918                  Scorpion2_SetSwitchState(machine(), strobe, data, 0);
921                  Scorpion2_SetSwitchState(strobe, data, 0);
919922               }
920923               m_slide_states[slide] = 1;
921924            }
r21026r21027
928931               {
929932                  int strobe = m_slide_pay_sensor[slide]>>4, data = m_slide_pay_sensor[slide]&0x0F;
930933
931                  Scorpion2_SetSwitchState(machine(), strobe, data, 1);
934                  Scorpion2_SetSwitchState(strobe, data, 1);
932935               }
933936               m_slide_states[slide] = 0;
934937            }
r21026r21027
10631066
10641067   if ( offset == 7 )
10651068   {
1066      result = (result & 0xFE) | read_e2ram(machine());
1069      result = (result & 0xFE) | read_e2ram();
10671070   }
10681071
10691072   return result;
r21026r21027
10861089#define SDA 0x02    //SDA pin (data)
10871090
10881091
1089static void e2ram_reset(running_machine &machine)
1092void bfm_sc2_state::e2ram_reset()
10901093{
1091   bfm_sc2_state *state = machine.driver_data<bfm_sc2_state>();
1092   state->m_e2reg   = 0;
1093   state->m_e2state = 0;
1094   state->m_e2address = 0;
1095   state->m_e2rw    = 0;
1096   state->m_e2data_pin = 0;
1097   state->m_e2data  = (SDA|SCL);
1098   state->m_e2dummywrite = 0;
1099   state->m_e2data_to_read = 0;
1094   m_e2reg   = 0;
1095   m_e2state = 0;
1096   m_e2address = 0;
1097   m_e2rw    = 0;
1098   m_e2data_pin = 0;
1099   m_e2data  = (SDA|SCL);
1100   m_e2dummywrite = 0;
1101   m_e2data_to_read = 0;
11001102}
11011103
11021104int bfm_sc2_state::recdata(int changed, int data)
r21026r21027
11311133   return res;
11321134}
11331135
1134static int recAck(int changed, int data)
1136int bfm_sc2_state::recAck(int changed, int data)
11351137{
11361138   int result = 0;
11371139
r21026r21027
13931395   }
13941396}
13951397
1396static int read_e2ram(running_machine &machine)
1398int bfm_sc2_state::read_e2ram()
13971399{
1398   bfm_sc2_state *state = machine.driver_data<bfm_sc2_state>();
1399   LOG(("e2ram: r %d (%02X) \n", state->m_e2data_pin, state->m_e2data_to_read ));
1400   LOG(("e2ram: r %d (%02X) \n", m_e2data_pin, m_e2data_to_read ));
14001401
1401   return state->m_e2data_pin;
1402   return m_e2data_pin;
14021403}
14031404
14041405
r21026r21027
14091410{
14101411   // reset the board //////////////////////////////////////////////////////
14111412
1412   on_scorpion2_reset(machine());
1413   on_scorpion2_reset();
14131414   m_vfd0->reset();
14141415   m_vfd1->reset();
14151416
r21026r21027
21872188
21882189
21892190
2190int sc2_find_project_string(running_machine &machine )
2191int bfm_sc2_state::sc2_find_project_string( )
21912192{
21922193   // search for the project string to find the title (usually just at ff00)
21932194   char title_string[4][32] = { "PROJECT NUMBER", "PROJECT PR", "PROJECT ", "CASH ON THE NILE 2" };
2194   UINT8 *src = machine.root_device().memregion( "maincpu" )->base();
2195   int size = machine.root_device().memregion( "maincpu" )->bytes();
2195   UINT8 *src = machine().root_device().memregion( "maincpu" )->base();
2196   int size = machine().root_device().memregion( "maincpu" )->bytes();
21962197
21972198   for (int search=0;search<4;search++)
21982199   {
r21026r21027
22622263}
22632264
22642265
2265static void sc2_common_init(running_machine &machine, int decrypt)
2266void bfm_sc2_state::sc2_common_init(int decrypt)
22662267{
2267   bfm_sc2_state *state = machine.driver_data<bfm_sc2_state>();
22682268
2269   if (decrypt) bfm_decode_mainrom(machine, "maincpu", state->m_codec_data);         // decode main rom
2269   if (decrypt) bfm_decode_mainrom(machine(), "maincpu", m_codec_data);         // decode main rom
22702270
2271   memset(state->m_sc2_Inputs, 0, sizeof(state->m_sc2_Inputs));  // clear all inputs
2271   memset(m_sc2_Inputs, 0, sizeof(m_sc2_Inputs));  // clear all inputs
22722272}
22732273
2274static void adder2_common_init(running_machine &machine)
2274void bfm_sc2_state::adder2_common_init()
22752275{
2276   bfm_sc2_state *state = machine.driver_data<bfm_sc2_state>();
22772276   UINT8 *pal;
22782277
2279   pal = state->memregion("proms")->base();
2278   pal = memregion("proms")->base();
22802279   if ( pal )
22812280   {
2282      memcpy(state->m_key, pal, 8);
2281      memcpy(m_key, pal, 8);
22832282   }
22842283}
22852284
r21026r21027
22872286
22882287DRIVER_INIT_MEMBER(bfm_sc2_state,quintoon)
22892288{
2290   sc2_common_init(machine(), 1);
2289   sc2_common_init( 1);
22912290   adder2_decode_char_roms(machine());
22922291   MechMtr_config(machine(),8);                    // setup mech meters
22932292
22942293   m_has_hopper = 0;
22952294
2296   Scorpion2_SetSwitchState(machine(),3,0,1);  // tube1 level switch
2297   Scorpion2_SetSwitchState(machine(),3,1,1);  // tube2 level switch
2298   Scorpion2_SetSwitchState(machine(),3,2,1);  // tube3 level switch
2295   Scorpion2_SetSwitchState(3,0,1);  // tube1 level switch
2296   Scorpion2_SetSwitchState(3,1,1);  // tube2 level switch
2297   Scorpion2_SetSwitchState(3,2,1);  // tube3 level switch
22992298
2300   Scorpion2_SetSwitchState(machine(),5,2,1);
2301   Scorpion2_SetSwitchState(machine(),6,4,1);
2299   Scorpion2_SetSwitchState(5,2,1);
2300   Scorpion2_SetSwitchState(6,4,1);
23022301
23032302   m_sc2_show_door   = 1;
23042303   m_sc2_door_state  = 0x41;
r21026r21027
23082307
23092308DRIVER_INIT_MEMBER(bfm_sc2_state,pyramid)
23102309{
2311   sc2_common_init(machine(), 1);
2310   sc2_common_init(1);
23122311   adder2_decode_char_roms(machine());         // decode GFX roms
2313   adder2_common_init(machine());
2312   adder2_common_init();
23142313
23152314   m_has_hopper = 1;
23162315
2317   Scorpion2_SetSwitchState(machine(),3,0,1);  // tube1 level switch
2318   Scorpion2_SetSwitchState(machine(),3,1,1);  // tube2 level switch
2319   Scorpion2_SetSwitchState(machine(),3,2,1);  // tube3 level switch
2316   Scorpion2_SetSwitchState(3,0,1);  // tube1 level switch
2317   Scorpion2_SetSwitchState(3,1,1);  // tube2 level switch
2318   Scorpion2_SetSwitchState(3,2,1);  // tube3 level switch
23202319
23212320   m_sc2_show_door   = 1;
23222321   m_sc2_door_state  = 0x41;
r21026r21027
23252324
23262325DRIVER_INIT_MEMBER(bfm_sc2_state,sltsbelg)
23272326{
2328   sc2_common_init(machine(), 1);
2327   sc2_common_init(1);
23292328   adder2_decode_char_roms(machine());         // decode GFX roms
2330   adder2_common_init(machine());
2329   adder2_common_init();
23312330
23322331   m_has_hopper = 1;
23332332
r21026r21027
23392338
23402339DRIVER_INIT_MEMBER(bfm_sc2_state,adder_dutch)
23412340{
2342   sc2_common_init(machine(), 1);
2341   sc2_common_init(1);
23432342   adder2_decode_char_roms(machine());         // decode GFX roms
2344   adder2_common_init(machine());
2343   adder2_common_init();
23452344
23462345   m_has_hopper = 0;
23472346
2348   Scorpion2_SetSwitchState(machine(),3,0,1);  // tube1 level switch
2349   Scorpion2_SetSwitchState(machine(),3,1,1);  // tube2 level switch
2350   Scorpion2_SetSwitchState(machine(),3,2,1);  // tube3 level switch
2347   Scorpion2_SetSwitchState(3,0,1);  // tube1 level switch
2348   Scorpion2_SetSwitchState(3,1,1);  // tube2 level switch
2349   Scorpion2_SetSwitchState(3,2,1);  // tube3 level switch
23512350
23522351   m_sc2_show_door   = 1;
23532352   m_sc2_door_state  = 0x41;
r21026r21027
23572356
23582357DRIVER_INIT_MEMBER(bfm_sc2_state,gldncrwn)
23592358{
2360   sc2_common_init(machine(), 1);
2359   sc2_common_init(1);
23612360   adder2_decode_char_roms(machine());         // decode GFX roms
2362   adder2_common_init(machine());
2361   adder2_common_init();
23632362
23642363   m_has_hopper = 0;
23652364
2366   Scorpion2_SetSwitchState(machine(),3,0,1);  // tube1 level switch
2367   Scorpion2_SetSwitchState(machine(),3,1,1);  // tube2 level switch
2368   Scorpion2_SetSwitchState(machine(),3,2,1);  // tube3 level switch
2365   Scorpion2_SetSwitchState(3,0,1);  // tube1 level switch
2366   Scorpion2_SetSwitchState(3,1,1);  // tube2 level switch
2367   Scorpion2_SetSwitchState(3,2,1);  // tube3 level switch
23692368
23702369   m_sc2_show_door   = 0;
23712370   m_sc2_door_state  = 0x41;
r21026r21027
26622661
26632662static void bfmdm01_busy(running_machine &machine, int state)
26642663{
2665   Scorpion2_SetSwitchState(machine, 4,4, state?0:1);
2664   bfm_sc2_state *drvstate = machine.driver_data<bfm_sc2_state>();
2665   drvstate->Scorpion2_SetSwitchState(4,4, state?0:1);
26662666}
26672667
26682668static const bfmdm01_interface dm01_interface =
r21026r21027
26732673/* machine init (called only once) */
26742674MACHINE_RESET_MEMBER(bfm_sc2_state,awp_init)
26752675{
2676   on_scorpion2_reset(machine());
2676   on_scorpion2_reset();
26772677   m_vfd0->reset();
26782678   m_vfd1->reset();
26792679}
r21026r21027
26812681
26822682MACHINE_RESET_MEMBER(bfm_sc2_state,dm01_init)
26832683{
2684   on_scorpion2_reset(machine());
2684   on_scorpion2_reset();
26852685}
26862686
26872687
r21026r21027
38313831   MCFG_CPU_PERIODIC_INT(bfm_dm01_vbl, 1500 )          /* generate 1500 NMI's per second ?? what is the exact freq?? */
38323832MACHINE_CONFIG_END
38333833
3834static void sc2awp_common_init(running_machine &machine,int reels, int decrypt)
3834void bfm_sc2_state::sc2awp_common_init(int reels, int decrypt)
38353835{
3836   bfm_sc2_state *state = machine.driver_data<bfm_sc2_state>();
38373836
38383837   int n;
3839   sc2_common_init(machine, decrypt);
3838   sc2_common_init(decrypt);
38403839   /* setup n default 96 half step reels */
38413840
3842   state->m_reels=reels;
3841   m_reels=reels;
38433842
38443843   for ( n = 0; n < reels; n++ )
38453844   {
3846      stepper_config(machine, n, &starpoint_interface_48step);
3845      stepper_config(machine(), n, &starpoint_interface_48step);
38473846   }
38483847}
38493848
3850static void sc2awpdmd_common_init(running_machine &machine,int reels, int decrypt)
3849void bfm_sc2_state::sc2awpdmd_common_init(int reels, int decrypt)
38513850{
3852   bfm_sc2_state *state = machine.driver_data<bfm_sc2_state>();
38533851
38543852   int n;
3855   BFM_dm01_config(machine, &dm01_interface);
3856   sc2_common_init(machine, decrypt);
3853   BFM_dm01_config(machine(), &dm01_interface);
3854   sc2_common_init(decrypt);
38573855   /* setup n default 96 half step reels */
38583856
3859   state->m_reels=reels;
3857   m_reels=reels;
38603858
38613859   for ( n = 0; n < reels; n++ )
38623860   {
3863      stepper_config(machine, n, &starpoint_interface_48step);
3861      stepper_config(machine(), n, &starpoint_interface_48step);
38643862   }
38653863}
38663864
r21026r21027
38683866
38693867DRIVER_INIT_MEMBER(bfm_sc2_state,bbrkfst)
38703868{
3871   sc2awp_common_init(machine(),5, 1);
3869   sc2awp_common_init(5, 1);
38723870   MechMtr_config(machine(),8);
38733871
38743872   m_has_hopper = 0;
38753873
3876   Scorpion2_SetSwitchState(machine(),4,0, 1);   /* GBP1 Low Level Switch */
3877   Scorpion2_SetSwitchState(machine(),4,1, 1);   /* 20p Low Level Switch */
3878   Scorpion2_SetSwitchState(machine(),4,2, 1);   /* Token Front Low Level Switch */
3879   Scorpion2_SetSwitchState(machine(),4,3, 1);   /* Token Rear  Low Level Switch */
3880   Scorpion2_SetSwitchState(machine(),4,4, 1);
3881   Scorpion2_SetSwitchState(machine(),6,0, 0);
3882   Scorpion2_SetSwitchState(machine(),6,1, 1);
3883   Scorpion2_SetSwitchState(machine(),6,2, 0);
3884   Scorpion2_SetSwitchState(machine(),6,3, 1);
3874   Scorpion2_SetSwitchState(4,0, 1);   /* GBP1 Low Level Switch */
3875   Scorpion2_SetSwitchState(4,1, 1);   /* 20p Low Level Switch */
3876   Scorpion2_SetSwitchState(4,2, 1);   /* Token Front Low Level Switch */
3877   Scorpion2_SetSwitchState(4,3, 1);   /* Token Rear  Low Level Switch */
3878   Scorpion2_SetSwitchState(4,4, 1);
3879   Scorpion2_SetSwitchState(6,0, 0);
3880   Scorpion2_SetSwitchState(6,1, 1);
3881   Scorpion2_SetSwitchState(6,2, 0);
3882   Scorpion2_SetSwitchState(6,3, 1);
38853883
3886   sc2_find_project_string(machine());
3884   sc2_find_project_string();
38873885}
38883886
38893887DRIVER_INIT_MEMBER(bfm_sc2_state,drwho_common)
r21026r21027
38923890
38933891   m_has_hopper = 0;
38943892
3895   Scorpion2_SetSwitchState(machine(),4,0, 0);   /* GBP1 Low Level Switch */
3896   Scorpion2_SetSwitchState(machine(),4,1, 0);   /* 20p Low Level Switch */
3897   Scorpion2_SetSwitchState(machine(),4,2, 0);   /* Token Front Low Level Switch */
3898   Scorpion2_SetSwitchState(machine(),4,3, 0);   /* Token Rear  Low Level Switch */
3899   Scorpion2_SetSwitchState(machine(),7,0, 0);   /* GBP1 High Level Switch */
3900   Scorpion2_SetSwitchState(machine(),7,1, 0);   /* 20P High Level Switch */
3901   Scorpion2_SetSwitchState(machine(),7,2, 0);   /* Token Front High Level Switch */
3902   Scorpion2_SetSwitchState(machine(),7,3, 0);   /* Token Rear High Level Switch */
3893   Scorpion2_SetSwitchState(4,0, 0);   /* GBP1 Low Level Switch */
3894   Scorpion2_SetSwitchState(4,1, 0);   /* 20p Low Level Switch */
3895   Scorpion2_SetSwitchState(4,2, 0);   /* Token Front Low Level Switch */
3896   Scorpion2_SetSwitchState(4,3, 0);   /* Token Rear  Low Level Switch */
3897   Scorpion2_SetSwitchState(7,0, 0);   /* GBP1 High Level Switch */
3898   Scorpion2_SetSwitchState(7,1, 0);   /* 20P High Level Switch */
3899   Scorpion2_SetSwitchState(7,2, 0);   /* Token Front High Level Switch */
3900   Scorpion2_SetSwitchState(7,3, 0);   /* Token Rear High Level Switch */
39033901
3904   sc2_find_project_string(machine());
3902   sc2_find_project_string();
39053903}
39063904
39073905DRIVER_INIT_MEMBER(bfm_sc2_state,drwho)
39083906{
3909   sc2awp_common_init(machine(),6, 1);
3907   sc2awp_common_init(6, 1);
39103908   DRIVER_INIT_CALL(drwho_common);
39113909}
39123910
39133911DRIVER_INIT_MEMBER(bfm_sc2_state,drwhon)
39143912{
3915   sc2awp_common_init(machine(),4, 0);
3913   sc2awp_common_init(4, 0);
39163914   DRIVER_INIT_CALL(drwho_common);
39173915}
39183916
39193917
39203918DRIVER_INIT_MEMBER(bfm_sc2_state,focus)
39213919{
3922   sc2awp_common_init(machine(),6, 1);
3920   sc2awp_common_init(6, 1);
39233921   MechMtr_config(machine(),5);
3924   sc2_find_project_string(machine());
3922   sc2_find_project_string();
39253923}
39263924
39273925DRIVER_INIT_MEMBER(bfm_sc2_state,cpeno1)
39283926{
3929   sc2awpdmd_common_init(machine(),6, 1);
3927   sc2awpdmd_common_init(6, 1);
39303928
39313929   MechMtr_config(machine(),5);
39323930
3933   Scorpion2_SetSwitchState(machine(),3,3,1);  /*  5p play */
3934   Scorpion2_SetSwitchState(machine(),3,4,1);  /* 20p play */
3931   Scorpion2_SetSwitchState(3,3,1);  /*  5p play */
3932   Scorpion2_SetSwitchState(3,4,1);  /* 20p play */
39353933
3936   Scorpion2_SetSwitchState(machine(),4,0,1);  /* pay tube low (1 pound front) */
3937   Scorpion2_SetSwitchState(machine(),4,1,1);  /* pay tube low (20p) */
3938   Scorpion2_SetSwitchState(machine(),4,2,1);  /* pay tube low (?1 right) */
3939   Scorpion2_SetSwitchState(machine(),4,3,1);  /* pay tube low (?1 left) */
3934   Scorpion2_SetSwitchState(4,0,1);  /* pay tube low (1 pound front) */
3935   Scorpion2_SetSwitchState(4,1,1);  /* pay tube low (20p) */
3936   Scorpion2_SetSwitchState(4,2,1);  /* pay tube low (?1 right) */
3937   Scorpion2_SetSwitchState(4,3,1);  /* pay tube low (?1 left) */
39403938
3941   Scorpion2_SetSwitchState(machine(),5,0,1);  /* pay sensor (GBP1 front) */
3942   Scorpion2_SetSwitchState(machine(),5,1,1);  /* pay sensor (20 p) */
3943   Scorpion2_SetSwitchState(machine(),5,2,1);  /* pay sensor (1 right) */
3944   Scorpion2_SetSwitchState(machine(),5,3,1);  /* pay sensor (?1 left) */
3945   Scorpion2_SetSwitchState(machine(),5,4,1);  /* payout unit present */
3939   Scorpion2_SetSwitchState(5,0,1);  /* pay sensor (GBP1 front) */
3940   Scorpion2_SetSwitchState(5,1,1);  /* pay sensor (20 p) */
3941   Scorpion2_SetSwitchState(5,2,1);  /* pay sensor (1 right) */
3942   Scorpion2_SetSwitchState(5,3,1);  /* pay sensor (?1 left) */
3943   Scorpion2_SetSwitchState(5,4,1);  /* payout unit present */
39463944
39473945   m_slide_pay_sensor[0] = 0x50;
39483946   m_slide_pay_sensor[1] = 0x51;
r21026r21027
39513949   m_slide_pay_sensor[4] = 0;
39523950   m_slide_pay_sensor[5] = 0;
39533951
3954   Scorpion2_SetSwitchState(machine(),6,0,1);  /* ? percentage key */
3955   Scorpion2_SetSwitchState(machine(),6,1,1);
3956   Scorpion2_SetSwitchState(machine(),6,2,1);
3957   Scorpion2_SetSwitchState(machine(),6,3,1);
3958   Scorpion2_SetSwitchState(machine(),6,4,1);
3952   Scorpion2_SetSwitchState(6,0,1);  /* ? percentage key */
3953   Scorpion2_SetSwitchState(6,1,1);
3954   Scorpion2_SetSwitchState(6,2,1);
3955   Scorpion2_SetSwitchState(6,3,1);
3956   Scorpion2_SetSwitchState(6,4,1);
39593957
3960   Scorpion2_SetSwitchState(machine(),7,0,0);  /* GBP1 High Level Switch  */
3961   Scorpion2_SetSwitchState(machine(),7,1,0);  /* 20P High Level Switch */
3962   Scorpion2_SetSwitchState(machine(),7,2,0);  /* Token Front High Level Switch */
3963   Scorpion2_SetSwitchState(machine(),7,3,0);  /* Token Rear High Level Switch */
3958   Scorpion2_SetSwitchState(7,0,0);  /* GBP1 High Level Switch  */
3959   Scorpion2_SetSwitchState(7,1,0);  /* 20P High Level Switch */
3960   Scorpion2_SetSwitchState(7,2,0);  /* Token Front High Level Switch */
3961   Scorpion2_SetSwitchState(7,3,0);  /* Token Rear High Level Switch */
39643962
39653963   m_sc2_show_door   = 1;
39663964   m_sc2_door_state  = 0x31;
39673965
39683966   m_has_hopper = 0;
3969   sc2_find_project_string(machine());
3967   sc2_find_project_string();
39703968}
39713969
39723970DRIVER_INIT_MEMBER(bfm_sc2_state,ofah)
39733971{
3974   sc2awpdmd_common_init(machine(),4, 1);
3972   sc2awpdmd_common_init(4, 1);
39753973
3976   Scorpion2_SetSwitchState(machine(),4,0,1);  /* pay tube low (1 pound front) */
3977   Scorpion2_SetSwitchState(machine(),4,1,1);  /* pay tube low (20p) */
3978   Scorpion2_SetSwitchState(machine(),4,2,1);  /* pay tube low (?1 right) */
3979   Scorpion2_SetSwitchState(machine(),4,3,1);  /* pay tube low (?1 left) */
3974   Scorpion2_SetSwitchState(4,0,1);  /* pay tube low (1 pound front) */
3975   Scorpion2_SetSwitchState(4,1,1);  /* pay tube low (20p) */
3976   Scorpion2_SetSwitchState(4,2,1);  /* pay tube low (?1 right) */
3977   Scorpion2_SetSwitchState(4,3,1);  /* pay tube low (?1 left) */
39803978
3981   Scorpion2_SetSwitchState(machine(),6,0,0);  /* ? percentage key */
3982   Scorpion2_SetSwitchState(machine(),6,1,1);
3983   Scorpion2_SetSwitchState(machine(),6,2,0);
3984   Scorpion2_SetSwitchState(machine(),6,3,1);
3979   Scorpion2_SetSwitchState(6,0,0);  /* ? percentage key */
3980   Scorpion2_SetSwitchState(6,1,1);
3981   Scorpion2_SetSwitchState(6,2,0);
3982   Scorpion2_SetSwitchState(6,3,1);
39853983
39863984   MechMtr_config(machine(),3);
3987   sc2_find_project_string(machine());
3985   sc2_find_project_string();
39883986}
39893987
39903988DRIVER_INIT_MEMBER(bfm_sc2_state,prom)
39913989{
3992   sc2awpdmd_common_init(machine(),6, 1);
3990   sc2awpdmd_common_init(6, 1);
39933991
3994   Scorpion2_SetSwitchState(machine(),4,0,1);  /* pay tube low (1 pound front) */
3995   Scorpion2_SetSwitchState(machine(),4,1,1);  /* pay tube low (20p) */
3996   Scorpion2_SetSwitchState(machine(),4,2,1);  /* pay tube low (?1 right) */
3997   Scorpion2_SetSwitchState(machine(),4,3,1);  /* pay tube low (?1 left) */
3992   Scorpion2_SetSwitchState(4,0,1);  /* pay tube low (1 pound front) */
3993   Scorpion2_SetSwitchState(4,1,1);  /* pay tube low (20p) */
3994   Scorpion2_SetSwitchState(4,2,1);  /* pay tube low (?1 right) */
3995   Scorpion2_SetSwitchState(4,3,1);  /* pay tube low (?1 left) */
39983996
3999   Scorpion2_SetSwitchState(machine(),6,0,0);  /* ? percentage key */
4000   Scorpion2_SetSwitchState(machine(),6,1,1);
4001   Scorpion2_SetSwitchState(machine(),6,2,0);
4002   Scorpion2_SetSwitchState(machine(),6,3,1);
3997   Scorpion2_SetSwitchState(6,0,0);  /* ? percentage key */
3998   Scorpion2_SetSwitchState(6,1,1);
3999   Scorpion2_SetSwitchState(6,2,0);
4000   Scorpion2_SetSwitchState(6,3,1);
40034001
40044002   MechMtr_config(machine(),3);
4005   sc2_find_project_string(machine());
4003   sc2_find_project_string();
40064004}
40074005
40084006DRIVER_INIT_MEMBER(bfm_sc2_state,bfmcgslm)
40094007{
4010   sc2awp_common_init(machine(),6, 1);
4008   sc2awp_common_init(6, 1);
40114009   MechMtr_config(machine(),8);
40124010   m_has_hopper = 0;
4013   sc2_find_project_string(machine());
4011   sc2_find_project_string();
40144012}
40154013
40164014DRIVER_INIT_MEMBER(bfm_sc2_state,luvjub)
40174015{
4018   sc2awpdmd_common_init(machine(),6, 1);
4016   sc2awpdmd_common_init(6, 1);
40194017
40204018   MechMtr_config(machine(),8);
40214019   m_has_hopper = 0;
40224020
4023   Scorpion2_SetSwitchState(machine(),3,0,1);
4024   Scorpion2_SetSwitchState(machine(),3,1,1);
4021   Scorpion2_SetSwitchState(3,0,1);
4022   Scorpion2_SetSwitchState(3,1,1);
40254023
4026   Scorpion2_SetSwitchState(machine(),4,0,1);
4027   Scorpion2_SetSwitchState(machine(),4,1,1);
4028   Scorpion2_SetSwitchState(machine(),4,2,1);
4029   Scorpion2_SetSwitchState(machine(),4,3,1);
4024   Scorpion2_SetSwitchState(4,0,1);
4025   Scorpion2_SetSwitchState(4,1,1);
4026   Scorpion2_SetSwitchState(4,2,1);
4027   Scorpion2_SetSwitchState(4,3,1);
40304028
4031   Scorpion2_SetSwitchState(machine(),6,0,1);
4032   Scorpion2_SetSwitchState(machine(),6,1,1);
4033   Scorpion2_SetSwitchState(machine(),6,2,1);
4034   Scorpion2_SetSwitchState(machine(),6,3,0);
4029   Scorpion2_SetSwitchState(6,0,1);
4030   Scorpion2_SetSwitchState(6,1,1);
4031   Scorpion2_SetSwitchState(6,2,1);
4032   Scorpion2_SetSwitchState(6,3,0);
40354033
4036   Scorpion2_SetSwitchState(machine(),7,0,0);
4037   Scorpion2_SetSwitchState(machine(),7,1,0);
4038   Scorpion2_SetSwitchState(machine(),7,2,0);
4039   Scorpion2_SetSwitchState(machine(),7,3,0);
4040   sc2_find_project_string(machine());
4034   Scorpion2_SetSwitchState(7,0,0);
4035   Scorpion2_SetSwitchState(7,1,0);
4036   Scorpion2_SetSwitchState(7,2,0);
4037   Scorpion2_SetSwitchState(7,3,0);
4038   sc2_find_project_string();
40414039}
40424040
40434041
trunk/src/mame/drivers/enigma2.c
r21026r21027
9393   UINT32 screen_update_enigma2a(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
9494   TIMER_CALLBACK_MEMBER(interrupt_clear_callback);
9595   TIMER_CALLBACK_MEMBER(interrupt_assert_callback);
96   inline UINT16 vpos_to_vysnc_chain_counter( int vpos );
97   inline int vysnc_chain_counter_to_vpos( UINT16 counter );
98   void create_interrupt_timers(  );
99   void start_interrupt_timers(  );
100   void get_pens(pen_t *pens);
96101};
97102
98103
r21026r21027
103108 *************************************/
104109
105110
106INLINE UINT16 vpos_to_vysnc_chain_counter( int vpos )
111UINT16 enigma2_state::vpos_to_vysnc_chain_counter( int vpos )
107112{
108113   return vpos + VCOUNTER_START;
109114}
110115
111116
112INLINE int vysnc_chain_counter_to_vpos( UINT16 counter )
117int enigma2_state::vysnc_chain_counter_to_vpos( UINT16 counter )
113118{
114119   return counter - VCOUNTER_START;
115120}
r21026r21027
144149}
145150
146151
147static void create_interrupt_timers( running_machine &machine )
152void enigma2_state::create_interrupt_timers(  )
148153{
149   enigma2_state *state = machine.driver_data<enigma2_state>();
150   state->m_interrupt_clear_timer = machine.scheduler().timer_alloc(timer_expired_delegate(FUNC(enigma2_state::interrupt_clear_callback),state));
151   state->m_interrupt_assert_timer = machine.scheduler().timer_alloc(timer_expired_delegate(FUNC(enigma2_state::interrupt_assert_callback),state));
154   m_interrupt_clear_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(enigma2_state::interrupt_clear_callback),this));
155   m_interrupt_assert_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(enigma2_state::interrupt_assert_callback),this));
152156}
153157
154158
155static void start_interrupt_timers( running_machine &machine )
159void enigma2_state::start_interrupt_timers(  )
156160{
157   enigma2_state *state = machine.driver_data<enigma2_state>();
158161   int vpos = vysnc_chain_counter_to_vpos(INT_TRIGGER_COUNT_1);
159   state->m_interrupt_assert_timer->adjust(machine.primary_screen->time_until_pos(vpos));
162   m_interrupt_assert_timer->adjust(machine().primary_screen->time_until_pos(vpos));
160163}
161164
162165
163166
164167void enigma2_state::machine_start()
165168{
166   create_interrupt_timers(machine());
169   create_interrupt_timers();
167170
168171   m_maincpu = machine().device<cpu_device>("maincpu");
169172   m_audiocpu = machine().device<cpu_device>("audiocpu");
r21026r21027
185188   m_sound_latch = 0;
186189   m_blink_count = 0;
187190
188   start_interrupt_timers(machine());
191   start_interrupt_timers();
189192}
190193
191194
r21026r21027
195198 *
196199 *************************************/
197200
198static void get_pens(pen_t *pens)
201void enigma2_state::get_pens(pen_t *pens)
199202{
200203   offs_t i;
201204
trunk/src/mame/drivers/mpu3.c
r21026r21027
188188   TIMER_CALLBACK_MEMBER(ic21_timeout);
189189   TIMER_DEVICE_CALLBACK_MEMBER(gen_50hz);
190190   TIMER_DEVICE_CALLBACK_MEMBER(ic10_callback);
191   void update_triacs();
192   void mpu3_stepper_reset();
193   void ic11_update(mpu3_state *state);
194   void ic21_output(mpu3_state *state,int data);
195   void ic21_setup(mpu3_state *state);
196   void mpu3_config_common();
191197};
192198
193199#define DISPLAY_PORT 0
r21026r21027
195201#define BWB_FUNCTIONALITY 2
196202
197203
198static void update_triacs(running_machine &machine)
204void mpu3_state::update_triacs()
199205{
200   mpu3_state *state = machine.driver_data<mpu3_state>();
201206   int i,triacdata;
202207
203   triacdata=state->m_triac_ic3 + (state->m_triac_ic4 << 8) + (state->m_triac_ic5 << 9);
208   triacdata=m_triac_ic3 + (m_triac_ic4 << 8) + (m_triac_ic5 << 9);
204209
205210   for (i = 0; i < 8; i++)
206211   {
r21026r21027
209214}
210215
211216/* called if board is reset */
212static void mpu3_stepper_reset(running_machine &machine)
217void mpu3_state::mpu3_stepper_reset()
213218{
214   mpu3_state *state = machine.driver_data<mpu3_state>();
215219   int pattern = 0,reel;
216220   for (reel = 0; reel < 6; reel++)
217221   {
218222      stepper_reset_position(reel);
219223      if (stepper_optic_state(reel)) pattern |= 1<<reel;
220224   }
221   state->m_optic_pattern = pattern;
225   m_optic_pattern = pattern;
222226}
223227
224228void mpu3_state::machine_reset()
225229{
226230   m_vfd->reset();
227231
228   mpu3_stepper_reset(machine());
232   mpu3_stepper_reset();
229233
230234   m_lamp_strobe   = 0;
231235   m_led_strobe    = 0;
r21026r21027
292296
293297It is used as a multiplexer for the LEDs, lamp selects and inputs.*/
294298
295static void ic11_update(mpu3_state *state)
299void mpu3_state::ic11_update(mpu3_state *state)
296300{
297   if (!state->m_IC11G2A)
301   if (!m_IC11G2A)
298302   {
299      if (!state->m_IC11G2B)
303      if (!m_IC11G2B)
300304      {
301         if (state->m_IC11G1)
305         if (m_IC11G1)
302306         {
303            if ( state->m_IC11GA )  state->m_input_strobe |= 0x01;
304            else                    state->m_input_strobe &= ~0x01;
307            if ( m_IC11GA )  m_input_strobe |= 0x01;
308            else                    m_input_strobe &= ~0x01;
305309
306            if ( state->m_IC11GB )  state->m_input_strobe |= 0x02;
307            else                    state->m_input_strobe &= ~0x02;
310            if ( m_IC11GB )  m_input_strobe |= 0x02;
311            else                    m_input_strobe &= ~0x02;
308312
309            if ( state->m_IC11GC )  state->m_input_strobe |= 0x04;
310            else                    state->m_input_strobe &= ~0x04;
313            if ( m_IC11GC )  m_input_strobe |= 0x04;
314            else                    m_input_strobe &= ~0x04;
311315         }
312316      }
313317   }
314318   else
315   if ((state->m_IC11G2A)||(state->m_IC11G2B)||(!state->m_IC11G1))
319   if ((m_IC11G2A)||(m_IC11G2B)||(!m_IC11G1))
316320   {
317      state->m_input_strobe = 0x00;
321      m_input_strobe = 0x00;
318322   }
319323}
320324
r21026r21027
338342
339343This seems less stable than the revised version used in MPU4
340344*/
341static void ic21_output(mpu3_state *state,int data)
345void mpu3_state::ic21_output(mpu3_state *state,int data)
342346{
343   state->m_IC11G1 = data;
347   m_IC11G1 = data;
344348   ic11_update(state);
345349}
346350
347static void ic21_setup(mpu3_state *state)
351void mpu3_state::ic21_setup(mpu3_state *state)
348352{
349   if (state->m_IC11GA)
353   if (m_IC11GA)
350354   {
351355      {
352         state->m_ic11_active=1;
356         m_ic11_active=1;
353357         ic21_output(state,1);
354         state->m_ic21_timer->adjust(attotime::from_nsec( (0.34 * 47 * 2200000) *(1+(1/47))));
358         m_ic21_timer->adjust(attotime::from_nsec( (0.34 * 47 * 2200000) *(1+(1/47))));
355359      }
356360   }
357361}
r21026r21027
783787};
784788
785789/* Common configurations */
786static void mpu3_config_common(running_machine &machine)
790void mpu3_state::mpu3_config_common()
787791{
788   mpu3_state *state = machine.driver_data<mpu3_state>();
789   state->m_ic21_timer = machine.scheduler().timer_alloc(timer_expired_delegate(FUNC(mpu3_state::ic21_timeout),state));
792   m_ic21_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mpu3_state::ic21_timeout),this));
790793}
791794
792795void mpu3_state::machine_start()
793796{
794   mpu3_config_common(machine());
797   mpu3_config_common();
795798
796799   /* setup 8 mechanical meters */
797800   MechMtr_config(machine(),8);
r21026r21027
861864   m_signal_50hz = m_signal_50hz?0:1;
862865   machine().device<ptm6840_device>("ptm_ic2")->set_c1(m_signal_50hz);
863866   machine().device<pia6821_device>("pia_ic3")->cb1_w(~m_signal_50hz);
864   update_triacs(machine());
867   update_triacs();
865868}
866869
867870TIMER_DEVICE_CALLBACK_MEMBER(mpu3_state::ic10_callback)
trunk/src/mame/drivers/diverboy.c
r21026r21027
7171   virtual void machine_start();
7272   virtual void video_start();
7373   UINT32 screen_update_diverboy(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
74   void draw_sprites(  bitmap_ind16 &bitmap, const rectangle &cliprect );
7475};
7576
7677
r21026r21027
7879{
7980}
8081
81static void draw_sprites( running_machine& machine, bitmap_ind16 &bitmap, const rectangle &cliprect )
82void diverboy_state::draw_sprites(  bitmap_ind16 &bitmap, const rectangle &cliprect )
8283{
83   diverboy_state *state = machine.driver_data<diverboy_state>();
84   UINT16 *source = state->m_spriteram;
85   UINT16 *finish = source + (state->m_spriteram.bytes() / 2);
84   UINT16 *source = m_spriteram;
85   UINT16 *finish = source + (m_spriteram.bytes() / 2);
8686
8787   while (source < finish)
8888   {
r21026r21027
100100
101101      bank = (source[1] & 0x0002) >> 1;
102102
103      if (!flash || (machine.primary_screen->frame_number() & 1))
103      if (!flash || (machine().primary_screen->frame_number() & 1))
104104      {
105         drawgfx_transpen(bitmap,cliprect,machine.gfx[bank],
105         drawgfx_transpen(bitmap,cliprect,machine().gfx[bank],
106106               number,
107107               colr,
108108               0,0,
r21026r21027
117117UINT32 diverboy_state::screen_update_diverboy(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
118118{
119119//  bitmap.fill(get_black_pen(machine()), cliprect);
120   draw_sprites(machine(), bitmap, cliprect);
120   draw_sprites(bitmap, cliprect);
121121   return 0;
122122}
123123
trunk/src/mame/drivers/atarisy4.c
r21026r21027
6060   DECLARE_MACHINE_RESET(airrace);
6161   UINT32 screen_update_atarisy4(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
6262   INTERRUPT_GEN_MEMBER(vblank_int);
63   void image_mem_to_screen( bool clip);
64   void draw_polygon(UINT16 color);
65   void execute_gpu_command();
66   inline UINT8 hex_to_ascii(UINT8 in);
67   void load_ldafile(address_space &space, const UINT8 *file);
68   void load_hexfile(address_space &space, const UINT8 *file);
6369};
6470
6571
r21026r21027
207213   return (y * 4096) + offset + x;
208214}
209215
210static void image_mem_to_screen(atarisy4_state *state, bool clip)
216void atarisy4_state::image_mem_to_screen(bool clip)
211217{
212218   INT16 y = gpu.gr[1] - 0x200;
213219   UINT16 h = gpu.gr[3];
r21026r21027
230236         {
231237            if (x >= 0 && x <= 511)
232238            {
233               UINT16 pix = state->m_screen_ram[xy_to_screen_addr(x,y) >> 1];
239               UINT16 pix = m_screen_ram[xy_to_screen_addr(x,y) >> 1];
234240
235241               if (x & 1)
236242                  pix = (pix & (0x00ff)) | gpu.idr << 8;
237243               else
238244                  pix = (pix & (0xff00)) | gpu.idr;
239245
240               state->m_screen_ram[xy_to_screen_addr(x,y) >> 1] = pix;
246               m_screen_ram[xy_to_screen_addr(x,y) >> 1] = pix;
241247            }
242248            ++x;
243249         }
r21026r21027
266272   }
267273}
268274
269static void draw_polygon(atarisy4_state *state, UINT16 color)
275void atarisy4_state::draw_polygon(UINT16 color)
270276{
271277   int i;
272278   rectangle clip;
273279   poly_vertex v1, v2, v3;
274   poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(state->m_poly);
280   poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(m_poly);
275281
276282   clip.set(0, 511, 0, 511);
277283
278284   extra->color = color;
279   extra->screen_ram = state->m_screen_ram;
285   extra->screen_ram = m_screen_ram;
280286
281287   v1.x = gpu.points[0].x;
282288   v1.y = gpu.points[0].y;
r21026r21027
290296      v3.x = gpu.points[i].x;
291297      v3.y = gpu.points[i].y;
292298
293      poly_render_triangle(state->m_poly, 0, clip, draw_scanline, 1, &v1, &v2, &v3);
299      poly_render_triangle(m_poly, 0, clip, draw_scanline, 1, &v1, &v2, &v3);
294300      v2 = v3;
295301   }
296302}
r21026r21027
323329    PFVR    0x2B    Polygon vector relative
324330    PFC     0x2C    Polygon close
325331*/
326void execute_gpu_command(running_machine &machine)
332void atarisy4_state::execute_gpu_command()
327333{
328   atarisy4_state *state = machine.driver_data<atarisy4_state>();
329334   switch (gpu.ecr)
330335   {
331336      case 0x04:
r21026r21027
378383
379384         for (i = 0; i < gpu.gr[3]; ++i)
380385         {
381            UINT16 val = state->m_screen_ram[offset >> 1];
386            UINT16 val = m_screen_ram[offset >> 1];
382387            val >>= (~offset & 1) << 3;
383388
384389            if (gpu.gr[4] & 0x10)
385               state->m_r_color_table[table_offs] = val;
390               m_r_color_table[table_offs] = val;
386391            if (gpu.gr[4] & 0x20)
387               state->m_g_color_table[table_offs] = val;
392               m_g_color_table[table_offs] = val;
388393            if (gpu.gr[4] & 0x40)
389               state->m_b_color_table[table_offs] = val;
394               m_b_color_table[table_offs] = val;
390395
391396            /* Update */
392            palette_set_color(machine, table_offs, MAKE_RGB(state->m_r_color_table[table_offs], state->m_g_color_table[table_offs], state->m_b_color_table[table_offs]));
397            palette_set_color(machine(), table_offs, MAKE_RGB(m_r_color_table[table_offs], m_g_color_table[table_offs], m_b_color_table[table_offs]));
393398
394399            ++table_offs;
395400            ++offset;
r21026r21027
399404      }
400405      case 0x20:
401406      {
402         image_mem_to_screen(state, false);
407         image_mem_to_screen(false);
403408         break;
404409      }
405410      case 0x21:
406411      {
407         image_mem_to_screen(state, true);
412         image_mem_to_screen(true);
408413         break;
409414      }
410415      case 0x28:
r21026r21027
439444      }
440445      case 0x2c:
441446      {
442         draw_polygon(state, gpu.gr[2]);
443         poly_wait(state->m_poly, "Normal");
447         draw_polygon(gpu.gr[2]);
448         poly_wait(m_poly, "Normal");
444449         break;
445450      }
446451      default:
r21026r21027
476481      case 0x17:
477482      {
478483         gpu.ecr = data;
479         execute_gpu_command(machine());
484         execute_gpu_command();
480485         break;
481486      }
482487      case 0x1a:  gpu.far = data;     break;
r21026r21027
795800 *
796801 *************************************/
797802
798INLINE UINT8 hex_to_ascii(UINT8 in)
803UINT8 atarisy4_state::hex_to_ascii(UINT8 in)
799804{
800805   if (in < 0x3a)
801806      return in - 0x30;
r21026r21027
805810      return in;
806811}
807812
808void load_ldafile(address_space &space, const UINT8 *file)
813void atarisy4_state::load_ldafile(address_space &space, const UINT8 *file)
809814{
810815#define READ_CHAR()     file[i++]
811816   int i = 0;
r21026r21027
859864}
860865
861866/* Load memory space with data from a Tektronix-Extended HEX file */
862void load_hexfile(address_space &space, const UINT8 *file)
867void atarisy4_state::load_hexfile(address_space &space, const UINT8 *file)
863868{
864869#define READ_HEX_CHAR()     hex_to_ascii(file[i++])
865870

Previous 199869 Revisions Next


© 1997-2024 The MAME Team