Previous 15994 Revisions Next

r2763 Thursday 29th May, 2008 at 10:41:36 UTC by Nathan Woods
Updated to MAME 0.125u3 core
[docs]messnew.txt
[src/emu]cheat.c cpuexec.c cpuintrf.c cpuintrf.h driver.h emuopts.c emuopts.h info.c inptport.c inptport.h memory.h tokenize.h ui.c uimenu.c validity.c video.c
[src/emu/cpu]drcbec.c drcbex64.c drcbex86.c drcfe.c drcfe.h drcuml.c drcuml.h drcumld.c drcumlsh.h x86emit.h
[src/emu/cpu/cop400]410ops.c 420ops.c cop400.h cop410.c cop420.c cop420ds.c
[src/emu/cpu/h6280]h6280.c
[src/emu/cpu/i386]i386.c
[src/emu/cpu/m6502]m4510.c
[src/emu/cpu/mips]mips3.c mips3.h mips3com.c mips3com.h mips3drc.c
[src/emu/cpu/powerpc]ppc_mem.c
[src/emu/cpu/z180]z180.c
[src/emu/debug]debugcmd.c debugcpu.c debugcpu.h debugvw.c
[src/emu/drivers]empty.c xtal.h
[src/emu/machine]8257dma.c eeprom.c eeprom.h generic.c generic.h
[src/lib/util]astring.c astring.h
[src/mame]mamedriv.c
[src/mame/drivers]20pacgal.c aerofgt.c aleck64.c ampoker2.c asterix.c astrocorp.c astrof.c ataxx.c backfire.c bking.c cave.c cbasebal.c cidelsa.c clshroad.c coolridr.c cps1.c cps2.c darkhors.c dcheese.c ddenlovr.c deco156.c deco32.c deco_mlc.c djmain.c dkong.c eolith.c eolith16.c equites.c esd16.c f-32.c fromanc2.c gaelco3d.c galpani2.c gijoe.c gottlieb.c groundfx.c gticlub.c gunbustr.c hng64.c hornet.c hyprduel.c inufuku.c jackpool.c jpmimpct.c kaneko16.c kickgoal.c kinst.c konamigq.c konamigv.c konamigx.c konamim2.c leland.c lethal.c limenko.c lordgun.c magic10.c megadriv.c metro.c midas.c mitchell.c model2.c model3.c moo.c mystwarr.c namcos2.c namcos21.c namcos22.c namcos23.c naomi.c onetwo.c othunder.c overdriv.c pacman.c peplus.c pirates.c playmark.c plygonet.c pntnpuzl.c policetr.c portrait.c powerbal.c psikyo4.c psikyosh.c rabbit.c raiden2.c rainbow.c rbmk.c rpunch.c rungun.c scramble.c seattle.c segae.c segas16b.c segas32.c seibuspi.c seta2.c shisen.c simpl156.c snk.c ssv.c stlforce.c stv.c stvinit.c superchs.c taito_b.c taito_f3.c taito_z.c taitojc.c tecmosys.c tmaster.c tmnt.c toaplan2.c ultrsprt.c undrfire.c unico.c vamphalf.c vegas.c vendetta.c wilytowr.c xexex.c xmen.c xorworld.c yumefuda.c zaccaria.c zaxxon.c zr107.c
[src/mame/includes]namcos2.h psikyosh.h
[src/mame/machine]cps2crpt.c decoprot.c gaelco2.c leland.c namcos1.c simpsons.c ticket.c ticket.h
[src/mame/video]aerofgt.c ampoker2.c cps1.c digdug.c galaga.c goldstar.c konamiic.c m62.c mappy.c tmnt.c xevious.c
[src/mess/drivers]ip20.c ip22.c n64.c
[src/osd/winui]mui_util.c

src/mame/machine/leland.c
r2762r2763
672672
673673void leland_init_eeprom(UINT8 default_val, const UINT16 *data, UINT8 serial_offset, UINT8 serial_type)
674674{
675   static const struct EEPROM_interface eeprom_interface =
675   static const eeprom_interface eeprom_intf =
676676   {
677677      6,
678678      16,
r2762r2763
752752      }
753753   }
754754
755   EEPROM_init(&eeprom_interface);
755   eeprom_init(&eeprom_intf);
756756}
757757
758758
r2762r2763
765765
766766void ataxx_init_eeprom(UINT8 default_val, const UINT16 *data, UINT8 serial_offset)
767767{
768   static const struct EEPROM_interface eeprom_interface =
768   static const eeprom_interface eeprom_intf =
769769   {
770770      7,
771771      16,
r2762r2763
829829      eeprom_data[0x7f * 2 + 0] = (sum >> 8) & 0xff;
830830      eeprom_data[0x7f * 2 + 1] = sum & 0xff;
831831
832      EEPROM_init(&eeprom_interface);
832      eeprom_init(&eeprom_intf);
833833   }
834834}
835835
r2762r2763
845845{
846846   int port = input_port_read_indexed(machine, 2);
847847   if (LOG_EEPROM) logerror("%04X:EE read\n", safe_activecpu_get_pc());
848   return (port & ~0x01) | EEPROM_read_bit();
848   return (port & ~0x01) | eeprom_read_bit();
849849}
850850
851851
r2762r2763
853853{
854854   if (LOG_EEPROM) logerror("%04X:EE write %d%d%d\n", safe_activecpu_get_pc(),
855855         (data >> 6) & 1, (data >> 5) & 1, (data >> 4) & 1);
856   EEPROM_write_bit     ((data & 0x10) >> 4);
857   EEPROM_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
858   EEPROM_set_cs_line  ((~data & 0x40) ? ASSERT_LINE : CLEAR_LINE);
856   eeprom_write_bit     ((data & 0x10) >> 4);
857   eeprom_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
858   eeprom_set_cs_line  ((~data & 0x40) ? ASSERT_LINE : CLEAR_LINE);
859859}
860860
861861
r2762r2763
896896{
897897   if (read_or_write)
898898   {
899      EEPROM_save(file);
899      eeprom_save(file);
900900      mame_fwrite(file, battery_ram, LELAND_BATTERY_RAM_SIZE);
901901   }
902902   else if (file)
903903   {
904      EEPROM_load(file);
904      eeprom_load(file);
905905      mame_fread(file, battery_ram, LELAND_BATTERY_RAM_SIZE);
906906   }
907907   else
908908   {
909      EEPROM_set_data(eeprom_data, 64*2);
909      eeprom_set_data(eeprom_data, 64*2);
910910      memset(battery_ram, 0x00, LELAND_BATTERY_RAM_SIZE);
911911   }
912912}
r2762r2763
916916{
917917   if (read_or_write)
918918   {
919      EEPROM_save(file);
919      eeprom_save(file);
920920      mame_fwrite(file, battery_ram, LELAND_BATTERY_RAM_SIZE);
921921   }
922922   else if (file)
923923   {
924      EEPROM_load(file);
924      eeprom_load(file);
925925      mame_fread(file, battery_ram, LELAND_BATTERY_RAM_SIZE);
926926   }
927927   else
928928   {
929      EEPROM_set_data(eeprom_data, 128*2);
929      eeprom_set_data(eeprom_data, 128*2);
930930      memset(battery_ram, 0x00, LELAND_BATTERY_RAM_SIZE);
931931   }
932932}
r2762r2763
11701170      case 0x11:   /* /GIN1 */
11711171         result = input_port_read_indexed(machine, 3);
11721172         if (LOG_EEPROM) logerror("%04X:EE read\n", safe_activecpu_get_pc());
1173         result = (result & ~0x01) | EEPROM_read_bit();
1173         result = (result & ~0x01) | eeprom_read_bit();
11741174         break;
11751175
11761176      default:
r2762r2763
11931193
11941194         if (LOG_EEPROM) logerror("%04X:EE write %d%d%d\n", safe_activecpu_get_pc(),
11951195               (data >> 6) & 1, (data >> 5) & 1, (data >> 4) & 1);
1196         EEPROM_write_bit     ((data & 0x10) >> 4);
1197         EEPROM_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
1198         EEPROM_set_cs_line  ((~data & 0x40) ? ASSERT_LINE : CLEAR_LINE);
1196         eeprom_write_bit     ((data & 0x10) >> 4);
1197         eeprom_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
1198         eeprom_set_cs_line  ((~data & 0x40) ? ASSERT_LINE : CLEAR_LINE);
11991199         break;
12001200
12011201      case 0x0a:   /* /OGIA */
src/mame/machine/ticket.c
r2762r2763
8181   return dispenser[1].status;
8282}
8383
84CUSTOM_INPUT( ticket_dispenser_0_port_r )
85{
86   return dispenser[0].status ? 1 : 0;
87}
88
89CUSTOM_INPUT( ticket_dispenser_1_port_r )
90{
91   return dispenser[1].status ? 1 : 0;
92}
93
8494/***************************************************************************
8595  ticket_dispenser_w
8696***************************************************************************/
src/mame/machine/ticket.h
r2762r2763
2828READ8_HANDLER( ticket_dispenser_0_r );
2929READ8_HANDLER( ticket_dispenser_1_r );
3030
31CUSTOM_INPUT( ticket_dispenser_0_port_r );
32CUSTOM_INPUT( ticket_dispenser_1_port_r );
3133
34
3235/***************************************************************************
3336  ticket_dispenser_w
3437***************************************************************************/
src/mame/machine/namcos1.c
r2762r2763
117117
118118
119119
120static int key_id,key_reg,key_rng,key_swap4_arg,key_swap4,key_bottom4,key_top4;
120static int key_id, key_reg, key_rng, key_swap4_arg, key_swap4, key_bottom4, key_top4;
121static unsigned int key_quotient, key_reminder, key_numerator_high_word;
121122static UINT8 key[8];
122123
123124
r2762r2763
276277
277278  Key custom type 2 (CUS151 - CUS155)
278279
279  16/16 bit division + key no.
280  16/16 or 32/16 bit division + key no.
280281
282  it's not entirely understood how the 32/16 division works. Only galaga88
283  seems to use it.
284
281285*****************************************************************************/
282286
283287/*
r2762r2763
313317CPU #1 PC cbe8: keychip read 0003
314318
315319mmaze: (CUS152)
316CPU #0 PC 60f3: keychip write 0004=5b
320CPU #0 PC 60f3: keychip write 0004=5b [operating mode?]
317321CPU #0 PC 60fe: keychip write 0000=00
318322CPU #0 PC 60fe: keychip write 0001=01
319323CPU #0 PC 6101: keychip write 0002=00
r2762r2763
361365CPU #0 PC db22: keychip read 0001
362366CPU #0 PC db2b: keychip read 0002
363367CPU #0 PC db2b: keychip read 0003
364CPU #0 PC e136: keychip write 0004=0c
368CPU #0 PC e136: keychip write 0004=0c [operating mode?]
365369
370then a 32/16 bit division is used to calculate the hit ratio at the end of the game:
371CPU #0 PC ef6f: keychip write 0004=2d [operating mode?]
372CPU #0 PC ef76: keychip write 0000=01 \ denominator
373CPU #0 PC ef76: keychip write 0001=37 /
374CPU #0 PC ef7c: keychip write 0002=00 \ numerator high word
375CPU #0 PC ef7c: keychip write 0003=03 /
376CPU #0 PC ef81: keychip write 0004=0c [operating mode?]
377CPU #0 PC ef87: keychip write 0002=b1 \ numerator low word
378CPU #0 PC ef87: keychip write 0003=50 /
379CPU #0 PC ef8a: keychip read 0002
380CPU #0 PC ef8a: keychip read 0003
381
366382ws: (CUS154)
367383CPU #0 PC e052: keychip write 0004=d3 [operating mode?]
368384CPU #0 PC e82a: keychip read 0004     [AND #$3F = key no.]
r2762r2763
378394CPU #0 PC db5a: keychip read 0001
379395CPU #0 PC db63: keychip read 0002
380396CPU #0 PC db63: keychip read 0003
381CPU #0 PC db70: keychip write 0004=0b
397CPU #0 PC db70: keychip write 0004=0b [operating mode?]
382398CPU #0 PC db77: keychip write 0000=ff
383399CPU #0 PC db77: keychip write 0001=ff
384400CPU #0 PC db7e: keychip write 0002=ff
r2762r2763
387403CPU #0 PC db82: keychip read 0001
388404CPU #0 PC db8b: keychip read 0002
389405CPU #0 PC db8b: keychip read 0003
390CPU #0 PC db95: keychip write 0004=03
406CPU #0 PC db95: keychip write 0004=03 [operating mode?]
391407CPU #0 PC e552: keychip read 0004     [AND #$3F = key no.]
392408CPU #0 PC e560: keychip write 0000=00
393409CPU #0 PC e560: keychip write 0001=73
r2762r2763
404420{
405421//  logerror("CPU #%d PC %04x: keychip read %04x\n",cpu_getactivecpu(),activecpu_get_pc(),offset);
406422
423   key_numerator_high_word = 0;
424
407425   if (offset < 4)
408426   {
409      int d = (key[0] << 8) | key[1];
410      int n = (key[2] << 8) | key[3];
411      int q,r;
412
413      if (d)
414      {
415         q = n / d;
416         r = n % d;
417      }
418      else
419      {
420         q = 0xffff;
421         r = 0x00;
422      }
423
424      if (offset == 0) return r >> 8;
425      if (offset == 1) return r & 0xff;
426      if (offset == 2) return q >> 8;
427      if (offset == 3) return q & 0xff;
427      if (offset == 0) return key_reminder >> 8;
428      if (offset == 1) return key_reminder & 0xff;
429      if (offset == 2) return key_quotient >> 8;
430      if (offset == 3) return key_quotient & 0xff;
428431   }
429432   else if (offset == 4)
430433      return key_id;
r2762r2763
437440//  logerror("CPU #%d PC %04x: keychip write %04x=%02x\n",cpu_getactivecpu(),activecpu_get_pc(),offset,data);
438441
439442   if (offset < 5)
443   {
440444      key[offset] = data;
445
446      if (offset == 3)
447      {
448         unsigned int d = (key[0] << 8) | key[1];
449         unsigned int n = (key_numerator_high_word << 16) | (key[2] << 8) | key[3];
450
451         if (d)
452         {
453            key_quotient = n / d;
454            key_reminder = n % d;
455         }
456         else
457         {
458            key_quotient = 0xffff;
459            key_reminder = 0x0000;
460         }
461
462//  logerror("calculating division: %08x / %04x = %04x, %04x\n", n, d, key_quotient, key_reminder);
463
464         key_numerator_high_word = (key[2] << 8) | key[3];
465      }
466   }
441467}
442468
443469
src/mame/machine/gaelco2.c
r2762r2763
164164
165165***************************************************************************/
166166
167static const struct EEPROM_interface gaelco2_eeprom_interface =
167static const eeprom_interface gaelco2_eeprom_interface =
168168{
169169   8,            /* address bits */
170170   16,            /* data bits */
r2762r2763
180180NVRAM_HANDLER( gaelco2 )
181181{
182182   if (read_or_write){
183      EEPROM_save(file);
183      eeprom_save(file);
184184   } else {
185      EEPROM_init(&gaelco2_eeprom_interface);
185      eeprom_init(&gaelco2_eeprom_interface);
186186
187      if (file) EEPROM_load(file);
187      if (file) eeprom_load(file);
188188   }
189189}
190190
r2762r2763
193193   /* bit 6 is EEPROM data (DOUT) */
194194   /* bit 7 is EEPROM ready */
195195   /* bits 0-5, COINSW, STARTSW & Service */
196   return (1 << 7) | (EEPROM_read_bit() << 6) | (input_port_read_indexed(machine, 2) & 0x3f);
196   return (1 << 7) | (eeprom_read_bit() << 6) | (input_port_read_indexed(machine, 2) & 0x3f);
197197}
198198
199199WRITE16_HANDLER( gaelco2_eeprom_cs_w )
200200{
201201   /* bit 0 is CS (active low) */
202   EEPROM_set_cs_line((data & 0x01) ? CLEAR_LINE : ASSERT_LINE);
202   eeprom_set_cs_line((data & 0x01) ? CLEAR_LINE : ASSERT_LINE);
203203}
204204
205205WRITE16_HANDLER( gaelco2_eeprom_sk_w )
206206{
207207   /* bit 0 is SK (active high) */
208   EEPROM_set_clock_line((data & 0x01) ? ASSERT_LINE : CLEAR_LINE);
208   eeprom_set_clock_line((data & 0x01) ? ASSERT_LINE : CLEAR_LINE);
209209}
210210
211211WRITE16_HANDLER( gaelco2_eeprom_data_w )
212212{
213213   /* bit 0 is EEPROM data (DIN) */
214   EEPROM_write_bit(data & 0x01);
214   eeprom_write_bit(data & 0x01);
215215}
216216
217217/***************************************************************************
src/mame/machine/decoprot.c
r2762r2763
13051305
13061306//  case 0x582: return input_port_read_indexed(machine, 0); /* IN0 */
13071307//  case 0x672: return input_port_read_indexed(machine, 1); /* IN1 */
1308//  case 0x04c: return EEPROM_read_bit();
1308//  case 0x04c: return eeprom_read_bit();
13091309
13101310   case 0x468:
13111311      val=DECO_PORT(0x570);
r2762r2763
16541654   {
16551655   case 0x582: return (input_port_read_indexed(machine, 0)<<16) | 0xffff; /* IN0 */
16561656   case 0x672: return (input_port_read_indexed(machine, 1)<<16) | 0xffff; /* IN1 */
1657   case 0x04c: return (EEPROM_read_bit()<<16) | 0xffff;
1657   case 0x04c: return (eeprom_read_bit()<<16) | 0xffff;
16581658   }
16591659
16601660   /* Handle 'one shots' - writing data to an address, then immediately reading it back */
src/mame/machine/cps2crpt.c
r2762r2763
941941   { "mmatrix",  { 0xac9ebd79,0x410467df }, 0x180000 },   // B6C0 B447 BACF  cmpa.w  D0,A3   cmp.w   D7,D2   cmpa.w  A7,A5
942942   { "mmatrixj", { 0x4df81e95,0x72ed9823 }, 0x180000 },   // B6C0 B447 BACF  cmpa.w  D0,A3   cmp.w   D7,D2   cmpa.w  A7,A5
943943   { "mpang",    { 0x95f741c6,0xe547a21b }, 0x100000 },   // 0C84 347D 89A3  cmpi.l  #$347D89A3,D4
944   { "mpangu",   { 0x95f741c6,0xe547a21b }, 0x100000 },   // 0C84 347D 89A3  cmpi.l  #$347D89A3,D4
944945   { "mpangj",   { 0x95f741c6,0xe547a21b }, 0x100000 },   // 0C84 347D 89A3  cmpi.l  #$347D89A3,D4
945946   { "pzloop2",  { 0xa054f812,0xc40d36b4 }, 0x400000 },   // 0C82 9A73 15F1  cmpi.l  #$9A7315F1,D2
946947   { "pzloop2j", { 0xa054f812,0xc40d36b4 }, 0x400000 },   // 0C82 9A73 15F1  cmpi.l  #$9A7315F1,D2
src/mame/machine/simpsons.c
r2762r2763
1919static int init_eeprom_count;
2020
2121
22static const struct EEPROM_interface eeprom_interface =
22static const eeprom_interface eeprom_intf =
2323{
2424   7,            /* address bits */
2525   8,            /* data bits */
r2762r2763
3333NVRAM_HANDLER( simpsons )
3434{
3535   if (read_or_write)
36      EEPROM_save(file);
36      eeprom_save(file);
3737   else
3838   {
39      EEPROM_init(&eeprom_interface);
39      eeprom_init(&eeprom_intf);
4040
4141      if (file)
4242      {
4343         init_eeprom_count = 0;
44         EEPROM_load(file);
44         eeprom_load(file);
4545      }
4646      else
4747         init_eeprom_count = 10;
r2762r2763
5252{
5353   int res;
5454
55   res = (EEPROM_read_bit() << 4);
55   res = (eeprom_read_bit() << 4);
5656
5757   res |= 0x20;//konami_eeprom_ack() << 5; /* add the ack */
5858
r2762r2763
7171   if ( data == 0xff )
7272      return;
7373
74   EEPROM_write_bit(data & 0x80);
75   EEPROM_set_cs_line((data & 0x08) ? CLEAR_LINE : ASSERT_LINE);
76   EEPROM_set_clock_line((data & 0x10) ? ASSERT_LINE : CLEAR_LINE);
74   eeprom_write_bit(data & 0x80);
75   eeprom_set_cs_line((data & 0x08) ? CLEAR_LINE : ASSERT_LINE);
76   eeprom_set_clock_line((data & 0x10) ? ASSERT_LINE : CLEAR_LINE);
7777
7878   simpsons_video_banking( machine, data & 3 );
7979
src/mame/mamedriv.c
r2762r2763
13561356   DRIVER( shtridra )   /* (c) 1984 Seibu Kaihatsu */
13571357   DRIVER( wilytowr )   /* M63 (c) 1984 */
13581358   DRIVER( atomboy )   /* M63 (c) 1985 Irem + Memetron license */
1359   DRIVER( atomboya )   /* M63 (c) 1985 Irem + Memetron license */
13591360   DRIVER( fghtbskt )   /* (c) 1984 Paradise Co. Ltd. */
13601361   /* M62 */
13611362   DRIVER( kungfum )   /* (c) 1984 */
r2762r2763
26882689   DRIVER( mmatrixj )   /* 12/04/2000 (c) 2000 Takumi (Japan) */
26892690   DRIVER( 1944 )      /* 20/06/2000 (c) 2000 Eighting/Raizing (US) */
26902691   DRIVER( 1944j )      /* 20/06/2000 (c) 2000 Eighting/Raizing (Japan) */
2691   DRIVER( mpang )      /* 10/10/2000 (c) 2000 Mitchell (US) */
2692   DRIVER( mpang )      /* 10/10/2000 (c) 2000 Mitchell (Euro) */
2693   DRIVER( mpangu )   /* 10/10/2000 (c) 2000 Mitchell (US) */
26922694   DRIVER( mpangj )   /* 11/10/2000 (c) 2000 Mitchell (Japan) */
26932695   DRIVER( progear )   /* 17/01/2001 (c) 2001 Cave (US) */
26942696   DRIVER( progearj )   /* 17/01/2001 (c) 2001 Cave (Japan) */
r2762r2763
37713773   DRIVER( vf2b )      /* 1995 */
37723774   DRIVER( vf2o )      /* 1995 */
37733775   DRIVER( vcop2 )      /* 1995 */
3774   DRIVER( dynamcop )   /* 1996 */
3775   DRIVER( dyndeka2 )   /* 1996 */
37763776   DRIVER( doaa )      /* 1996 */
37773777   DRIVER( zeroguna )   /* 1997 */
3778   DRIVER( dynamcop )   /* 1998 */
3779   DRIVER( dyndeka2 )   /* 1998 */
37783780   DRIVER( pltkidsa )   /* 1998 */
37793781
37803782   /* Model 2B-CRX (SHARC, SCSP sound board) */
r2762r2763
37843786   DRIVER( gunblade )   /* 1995 */
37853787   DRIVER( indy500 )   /* 1995 */
37863788   DRIVER( skytargt )   /* 1995 */
3787   DRIVER( dynmcopb )   /* 1996 */
37883789   DRIVER( schamp )   /* 1996 */
37893790   DRIVER( lastbrnx )   /* 1996 */
37903791   DRIVER( lastbrnj )   /* 1996 */
r2762r2763
37933794   DRIVER( von )      /* 1996 */
37943795   DRIVER( vonusa )   /* 1996 */
37953796   DRIVER( dynabb )   /* 1996 */
3796   DRIVER( dyndek2b )   /* 1996 */
37973797   DRIVER( zerogun )   /* 1997 */
37983798   DRIVER( zerogunj )   /* 1997 */
3799   DRIVER( dynmcopb )   /* 1998 */
3800   DRIVER( dyndek2b )   /* 1998 */
37993801   DRIVER( pltkids )   /* 1998 */
38003802
38013803   /* Model 2C-CRX (TGPx4, SCSP sound board) */
r2762r2763
38053807   DRIVER( overrev )   /* 1997 */
38063808   DRIVER( topskatr )   /* 1997 */
38073809   DRIVER( bel )      /* 1998 */
3810   DRIVER( dynmcopc )   /* 1998 */
38083811
38093812   /* Sega Model 3 Games */
38103813
r2762r2763
75437546   DRIVER( trivialp )   /* (c) 1996 */
75447547   DRIVER( scrabble )   /* (c) 1997 */
75457548   DRIVER( hngmnjpm )   /* (c) 1998 */
7549   DRIVER( coronatn )   /* (c) 1999 */
75467550
75477551   /* Other Games */
75487552   DRIVER( astinvad )   /* (c) 1980 Stern */
r2762r2763
77727776   DRIVER( funybubc )   /* (c) 1999 Comad Industries */
77737777   DRIVER( dcheese )   /* (c) 1993 HAR */
77747778   DRIVER( lottof2 )   /* (c) 1993 HAR */
7775   DRIVER( fredmem )   /* (c) 1993 HAR */
7779   DRIVER( fredmem )   /* (c) 1994 Coastal Amusements */
7780   DRIVER( fredmeus )   /* (c) 1994 Coastal Amusements */
7781   DRIVER( fredmeuk )  /* (c) 1994 Coastal Amusements */
7782   DRIVER( fredmemj )   /* (c) 1994 Coastal Amusements */
7783   DRIVER( fredmemc )  /* (c) 1994 Coastal Amusements */
7784   DRIVER( fredmesp )  /* (c) 1994 Coastal Amusements */
7785   DRIVER( cecmatch )  /* (c) 1993 Coastal Amusements */
77767786   DRIVER( f15se )      /* (c) 1991 Microprose */
77777787   DRIVER( f15se21 )   /* (c) 1991 Microprose */
77787788   DRIVER( botss )      /* (c) 1992 Microprose */
r2762r2763
79247934   DRIVER( attckufo )   /* (c) 1980 Ryoto Electric Co. */
79257935   DRIVER( fortecar )
79267936   DRIVER( jackpool )   /* (c) 1997 Electronic Projects */
7927   DRIVER( suprpool )   /* (c) 1997 Nazionale Elettronica Giochi S.A.S. */
79287937   DRIVER( murogem )   /* ??? */
79297938   DRIVER( murogema )   /* ??? */
79307939   DRIVER( lasvegas )   /* hack */
r2762r2763
79357944   DRIVER( magic10 )   /* (c) 1995 A.W.P. Games */
79367945   DRIVER( magic10a )   /* (c) 1995 A.W.P. Games */
79377946   DRIVER( magic102 )   /* (c) 1997 ABM Games */
7947   DRIVER( suprpool )   /* (c) 1997 Nazionale Elettronica Giochi S.A.S. */
79387948   DRIVER( dwarfd )   /* (c) 198? Electro-Sports */
79397949   DRIVER( trvquest )   /* (c) 1984 Sunn / Techstar */
79407950   DRIVER( wheelfir )   /* (c) 199? TCH */
r2762r2763
80548064   DRIVER( peps0615 )   /* (c) 1996 IGT - International Gaming Technology */
80558065   DRIVER( peps0716 )   /* (c) 1996 IGT - International Gaming Technology */
80568066   DRIVER( pexp0019 )   /* (c) 1995 IGT - International Gaming Technology */
8067   DRIVER( pexp0112 )   /* (c) 1995 IGT - International Gaming Technology */
80578068   DRIVER( pexs0006 )   /* (c) 1997 IGT - International Gaming Technology */
80588069   DRIVER( pexmp006 )   /* (c) 1997 IGT - International Gaming Technology */
80598070   DRIVER( mirage )   /* (c) 1994 Mitchell */
src/mame/includes/psikyosh.h
r2762r2763
1010VIDEO_UPDATE( psikyosh );
1111VIDEO_EOF( psikyosh );
1212
13enum { EEPROM_0=0, EEPROM_DEFAULT=1, EEPROM_DARAKU, EEPROM_S1945III, EEPROM_DRAGNBLZ, EEPROM_GNBARICH, EEPROM_USER1, EEPROM_MJGTASTE };
13enum { eeprom_0=0, eeprom_DEFAULT=1, eeprom_DARAKU, eeprom_S1945III, eeprom_DRAGNBLZ, eeprom_GNBARICH, eeprom_USER1, eeprom_MJGTASTE };
1414
1515/* Psikyo PS6406B */
1616#define FLIPSCREEN (((psikyosh_vidregs[3] & 0x0000c000) == 0x0000c000) ? 1:0)
src/mame/includes/namcos2.h
r2762r2763
145145/**************************************************************/
146146/*  EEPROM memory function handlers                           */
147147/**************************************************************/
148#define NAMCOS2_68K_EEPROM_W   namcos2_68k_eeprom_w
149#define NAMCOS2_68K_EEPROM_R   namcos2_68k_eeprom_r
148#define NAMCOS2_68K_eeprom_W   namcos2_68k_eeprom_w
149#define NAMCOS2_68K_eeprom_R   namcos2_68k_eeprom_r
150150NVRAM_HANDLER( namcos2 );
151151WRITE16_HANDLER( namcos2_68k_eeprom_w );
152152READ16_HANDLER( namcos2_68k_eeprom_r );
src/mame/video/xevious.c
r2762r2763
450450         color = spriteram[offs + 1] & 0x7f;
451451         flipx = spriteram_3[offs] & 4;
452452         flipy = spriteram_3[offs] & 8;
453
454         sx = spriteram_2[offs + 1] - 40 + 0x100*(spriteram_3[offs + 1] & 1);
455         sy = 28*8-spriteram_2[offs]-1;
456
453457         if (flip_screen_get())
454458         {
455459            flipx = !flipx;
456460            flipy = !flipy;
461            sy += 48;
457462         }
458         sx = spriteram_2[offs + 1] - 40 + 0x100*(spriteram_3[offs + 1] & 1);
459         sy = 28*8-spriteram_2[offs]-1;
460463
461464         transmask = colortable_get_transpen_mask(machine->colortable, machine->gfx[bank], color, 0x80);
462465
src/mame/video/aerofgt.c
r2762r2763
66UINT16 *aerofgt_spriteram1,*aerofgt_spriteram2,*aerofgt_spriteram3;
77UINT16 *wbbc97_bitmapram;
88size_t aerofgt_spriteram1_size,aerofgt_spriteram2_size,aerofgt_spriteram3_size;
9UINT16 *spikes91_tx_tilemap_ram;
910
1011static UINT8 gfxbank[8];
1112static UINT16 bg1scrollx,bg1scrolly,bg2scrollx,bg2scrolly,wbbc97_bitmap_enable;
r2762r2763
1617static int sprite_gfx;
1718static int spikes91_lookup;
1819
19
2020/***************************************************************************
2121
2222  Callbacks for the TileMap code
r2762r2763
573573
574574      if (!code) continue;
575575
576      xpos = (aerofgt_spriteram3[i + 2] & 0x01ff) - 13;
576      xpos = (aerofgt_spriteram3[i + 2] & 0x01ff) - 16;
577577      ypos = 256 - (aerofgt_spriteram3[i + 1] & 0x00ff) - 26;
578578      flipy = 0;
579579      flipx = aerofgt_spriteram3[i + 3] & 0x8000;
r2762r2763
737737VIDEO_UPDATE( spikes91 )
738738{
739739   int i,scrolly;
740   int y,x;
741   int count;
742   const gfx_element *gfx = screen->machine->gfx[0];
740743
741744   tilemap_set_scroll_rows(bg1_tilemap,256);
742745   scrolly = bg1scrolly;
r2762r2763
747750
748751   tilemap_draw(bitmap,cliprect,bg1_tilemap,0,0);
749752   spikes91_draw_sprites(screen->machine,bitmap,cliprect);
753
754   /* we could use a tilemap, but it's easier to just do it here */
755   count = 0;
756   for (y=0;y<32;y++)
757   {
758      for (x=0;x<64;x++)
759      {
760         UINT16 tileno = spikes91_tx_tilemap_ram[count]&0x1fff;
761         UINT16 colour = spikes91_tx_tilemap_ram[count]&0xe000;
762         drawgfx(bitmap,gfx,
763               tileno,
764               colour>>13,
765               0,0,
766               (x*8)+24,(y*8)+8,
767               cliprect,TRANSPARENCY_PEN,15);
768
769         count++;
770
771      }
772
773   }
774
750775   return 0;
751776}
752777
src/mame/video/goldstar.c
r2762r2763
6666      sx = offs % 64;
6767      sy = offs / 64;
6868
69      drawgfx(bitmap,screen->machine->gfx[0],
69      drawgfx(tmpbitmap4,screen->machine->gfx[0],
7070            videoram[offs] + ((colorram[offs] & 0xf0) << 4),
7171            colorram[offs] & 0x0f,
7272            0,0,
src/mame/video/cps1.c
r2762r2763
423423#define CPS_B_21_QS3 0x0e,0x0c00,  -1,  -1,  -1,  -1,  0x2c, -1,  -1,   0x12,{0x14,0x16,0x08,0x0a},0x0c, {0x04,0x02,0x20,0x00,0x00}
424424#define CPS_B_21_QS4 0x2e,0x0c01,  -1,  -1,  -1,  -1,  0x1c,0x1e,0x08,  0x16,{0x00,0x02,0x28,0x2a},0x2c, {0x04,0x08,0x10,0x00,0x00}
425425#define CPS_B_21_QS5 0x1e,0x0c02,  -1,  -1,  -1,  -1,  0x0c, -1,  -1,   0x2a,{0x2c,0x2e,0x30,0x32},0x1c, {0x04,0x08,0x10,0x00,0x00}
426#define HACK_B_1      -1,   -1,    -1,  -1,  -1,  -1,   -1,  -1,  -1,   0x14,{0x12,0x10,0x0e,0x0c},0x1c, {0xff,0xff,0xff,0x00,0x00}
426#define HACK_B_1      -1,   -1,    -1,  -1,  -1,  -1,   -1,  -1,  -1,   0x14,{0x12,0x10,0x0e,0x0c},0x0a, {0x0e,0x0e,0x0e,0x30,0x30}
427427
428428/*
429429CPS_B_21_DEF is CPS-B-21 at default settings (no battery)
r2762r2763
14831483   if (offset == CPS1_PALETTE_BASE)
14841484      cps1_build_palette(machine, cps1_base(CPS1_PALETTE_BASE,cps1_palette_align));
14851485
1486   // pzloop2 write to register 24 on startup. This is probably just a bug.
1487   if (offset == 0x24/2 && cps_version == 2)
1488      return;
1489
14861490   if (offset > CPS1_VIDEOCONTROL)
14871491      popmessage("write to CPS-A register %02x contact MAMEDEV", offset*2);
14881492}
r2762r2763
15071511            cps1_cps_b_regs[cps1_game_config->mult_factor2/2]) >> 16;
15081512
15091513   if (offset == cps1_game_config->in2_addr/2)   /* Extra input ports (on C-board) */
1510      return input_port_read(machine, "IN2");
1514   {
1515      if (cps1_game_config->bootleg_kludge == 1)
1516         return input_port_read(machine, "IN2") << 8;
1517      else
1518         return input_port_read(machine, "IN2");
1519   }
15111520
15121521   if (offset == cps1_game_config->in3_addr/2)   /* Player 4 controls (on C-board) ("Captain Commando") */
15131522      return input_port_read(machine, "IN3");
15141523
15151524   if (cps_version == 2)
15161525   {
1526      if (offset == 0x10/2)
1527      {
1528         // UNKNOWN--only mmatrix appears to read this, and I'm not sure if the result is actuallyused
1529         return cps1_cps_b_regs[0x10/2];
1530      }
15171531      if (offset == 0x12/2)
15181532      {
15191533         return cps1_cps_b_regs[0x12/2];
r2762r2763
15841598         offset != cps1_game_config->priority[2]/2 &&
15851599         offset != cps1_game_config->priority[3]/2 &&
15861600         offset != cps1_game_config->palette_control/2 &&
1587         offset != cps1_game_config->out2_addr/2)
1601         offset != cps1_game_config->out2_addr/2 &&
1602         !cps1_game_config->bootleg_kludge)
15881603      popmessage("CPS-B write %04x to port %02x contact MAMEDEV", data, offset*2);
15891604}
15901605
r2762r2763
17631778   enablemask = cps1_game_config->layer_enable_mask[0] | cps1_game_config->layer_enable_mask[1]
17641779         | cps1_game_config->layer_enable_mask[2]
17651780         | cps1_game_config->layer_enable_mask[3] | cps1_game_config->layer_enable_mask[4];
1766   if (((layercontrol & ~enablemask) & 0xc03e) != 0)
1781   if (((layercontrol & ~enablemask) & 0x003e) != 0)
17671782      popmessage("layer %02x contact MAMEDEV",layercontrol&0xc03f);
17681783}
17691784
src/mame/video/tmnt.c
r2762r2763
468468      /* bit 0 is data */
469469      /* bit 1 is cs (active low) */
470470      /* bit 2 is clock (active high) */
471      EEPROM_write_bit(data & 0x01);
472      EEPROM_set_cs_line((data & 0x02) ? CLEAR_LINE : ASSERT_LINE);
473      EEPROM_set_clock_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE);
471      eeprom_write_bit(data & 0x01);
472      eeprom_set_cs_line((data & 0x02) ? CLEAR_LINE : ASSERT_LINE);
473      eeprom_set_clock_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE);
474474
475475      /* bits 3-4 control palette dimming */
476476      /* 4 = DIMPOL = when set, negate SHAD */
src/mame/video/ampoker2.c
r2762r2763
77    Company:    Novomatic.
88    Year:       1990.
99
10    Original preliminary driver:   Curt Coder.
11    Rewrite and additional work:   Roberto Fresca, with a lot of help of Grull Osgo.
10    Driver by Roberto Fresca, with a lot of help of Grull Osgo.
11    Based on a preliminary work of Curt Coder.
1212
1313
1414    --- Supported Sets ---
1515
16    Old name | New name | Relation | Description
16    Set Name | Relation | Description
1717    --------------------------------------------
18    ampokr2b   ampoker2   parent     American Poker II.
19      ----     ampkr2b1   clone      American Poker II (bootleg, set 1).
20    ampokr2a   ampkr2b2   clone      American Poker II (bootleg, set 2).
21    ampoker2   ampkr2b3   clone      American Poker II (bootleg, set 3).
22    ampokr2c   pkrdewin   clone      Poker De Win.
23      ----     ampkr95    clone      American Poker 95.
24      ----     sigmapkr   parent     Sigma Poker.
25      ----     sigma2k    parent     Sigma Poker 2000.
18    ampoker2   parent     American Poker II.
19    ampkr2b1   clone      American Poker II (bootleg, set 1).
20    ampkr2b2   clone      American Poker II (bootleg, set 2).
21    ampkr2b3   clone      American Poker II (bootleg, set 3).
22    pkrdewin   clone      Poker De Win.
23    ampkr95    clone      American Poker 95.
24    sigmapkr   parent     Sigma Poker.
25    sigma2k    parent     Sigma Poker 2000.
2626
2727
28*********************************************************************************
29
30
31    Resistor Network
32    ----------------
33
34    The following diagram is related to taiwanese and argentine PCBs.
35
36
37    82S147AN
38   +---------+
39   |         |    470
40   | O1-Pin06|---/\/\/\----+---> BLUE
41   |         |    220      |
42   | O2-Pin07|---/\/\/\----+
43   |         |    1K
44   | O3-Pin08|---/\/\/\----+---> GREEN
45   |         |    470      |
46   | O4-Pin09|---/\/\/\----+
47   |         |    220      |
48   | O5-Pin11|---/\/\/\----+
49   |         |    1K
50   | O6-Pin12|---/\/\/\----+---> RED
51   |         |    470      |
52   | O7-Pin13|---/\/\/\----+
53   |         |    220      |
54   | O8-Pin14|---/\/\/\----+
55   |         |
56   +---------+
57
58
59   All colors are directly routed to the edge connector.
60   There are not pull-up or pull-down resistors.
61
62
2863********************************************************************************/
2964
3065
3166#include "driver.h"
67#include "video/resnet.h"
3268
3369static tilemap *bg_tilemap;
3470
3571
3672PALETTE_INIT( ampoker2 )
3773{
38   int i;
39
4074/*    - bits -
4175      76543210
4276      RRRGGGBB
4377*/
78   int i;
79   static const int resistances_rg[3] = { 1000, 470, 220 };
80   static const int resistances_b [2] = { 470, 220 };
81   double weights_r[3], weights_g[3], weights_b[2];
82
83   compute_resistor_weights(0,   255,   -1.0,
84         3,   resistances_rg,   weights_r,   0,   0,
85         3,   resistances_rg,   weights_g,   0,   0,
86         2,   resistances_b,   weights_b,   0,   0);
87
88
4489   for (i = 0; i < machine->config->total_colors; i++)
4590   {
4691      int bit0, bit1, bit2, r, g, b;
4792
4893      /* blue component */
49      bit0 = 0;
50      bit1 = (*color_prom >> 0) & 0x01;
51      bit2 = (*color_prom >> 1) & 0x01;
52      b =  ( 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2);
53
94      bit0 = (color_prom[i] >> 0) & 0x01;
95      bit1 = (color_prom[i] >> 1) & 0x01;
96      b = combine_2_weights(weights_b, bit0, bit1);
5497      /* green component */
55      bit0 = (*color_prom >> 2) & 0x01;
56      bit1 = (*color_prom >> 3) & 0x01;
57      bit2 = (*color_prom >> 4) & 0x01;
58      g =  ( 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2);
59
98      bit0 = (color_prom[i] >> 2) & 0x01;
99      bit1 = (color_prom[i] >> 3) & 0x01;
100      bit2 = (color_prom[i] >> 4) & 0x01;
101      g = combine_3_weights(weights_g, bit0, bit1, bit2);
60102      /* red component */
61      bit0 = (*color_prom >> 5) & 0x01;
62      bit1 = (*color_prom >> 6) & 0x01;
63      bit2 = (*color_prom >> 7) & 0x01;
64      r = ( 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2);
103      bit0 = (color_prom[i] >> 5) & 0x01;
104      bit1 = (color_prom[i] >> 6) & 0x01;
105      bit2 = (color_prom[i] >> 7) & 0x01;
106      r = combine_3_weights(weights_r, bit0, bit1, bit2);
65107
66      palette_set_color(machine, i, MAKE_RGB(r, g, b));
67
68      color_prom++;
108      palette_set_color(machine,i,MAKE_RGB(r,g,b));
69109   }
70110}
71111
r2762r2763
81121   int attr = videoram[offs + 1];
82122   int code = videoram[offs];
83123   int color = attr;
84   code=code+(256*(color & 0x03));   /* code = color.bit1 + color.bit0 + code */
85   color= color >> 1;            /* color = color - bit0 (bit1..bit7) */
124   code = code + (256 * (color & 0x03));   /* code = color.bit1 + color.bit0 + code */
125   color = color >> 1;                       /* color = color - bit0 (bit1..bit7) */
86126
87127   SET_TILE_INFO(0, code, color, 0);
88128}
r2762r2763
93133   int attr = videoram[offs + 1];
94134   int code = videoram[offs];
95135   int color = attr;
96   code=code+(256*(color & 0x0f));   /* the game use 2 extra bits */
97   color= color >> 1;
136   code = code + (256 * (color & 0x0f));   /* the game uses 2 extra bits */
137   color = color >> 1;
98138
99139   SET_TILE_INFO(0, code, color, 0);
100140}
src/mame/video/m62.c
r2762r2763
664664
665665VIDEO_UPDATE( ldrun4 )
666666{
667   tilemap_set_scrollx( m62_background, 0, m62_background_hscroll );
667   tilemap_set_scrollx( m62_background, 0, m62_background_hscroll-2 );
668668
669669   tilemap_draw( bitmap, cliprect, m62_background, 0, 0 );
670670   draw_sprites( screen->machine, bitmap, cliprect, 0x1f, 0x00, 0x00 );
src/mame/video/galaga.c
r2762r2763
516516      int sizey = (spriteram_3[offs] & 0x08) >> 3;
517517      int x,y;
518518
519      sy -= 16 * sizey;
520      sy = (sy & 0xff) - 32;   // fix wraparound
521
519522      if (flip_screen_get())
520523      {
521524         flipx ^= 1;
522525         flipy ^= 1;
526         sy += 48;
523527      }
524528
525      sy -= 16 * sizey;
526      sy = (sy & 0xff) - 32;   // fix wraparound
527
528529      for (y = 0;y <= sizey;y++)
529530      {
530531         for (x = 0;x <= sizex;x++)
src/mame/video/konamiic.c
r2762r2763
64346434
64356435static int K056832_update_linemap(running_machine *machine, bitmap_t *bitmap, int page, int flags)
64366436{
6437#define LINE_WIDTH 512
64386437
6439#define DRAW_PIX(N) \
6440   pen = src_ptr[N]; \
6441   if (pen) \
6442   { pen += basepen; xpr_ptr[count+N] = TILEMAP_PIXEL_LAYER0; dst_ptr[count+N] = pen; } else \
6443   { xpr_ptr[count+N] = 0; }
6444
6445   rectangle zerorect;
6446   tilemap *tmap;
6447   bitmap_t *pixmap, *xprmap;
6448   UINT8 *xprdata;
6449   const gfx_element *src_gfx;
6450
6451   UINT32 *dirty;
6452   int all_dirty, line;
6453   int offs, mask;
6454
6455   const pen_t *pal_ptr;
6456   const UINT8  *src_base, *src_ptr;
6457   UINT8  *xpr_ptr;
6458   UINT16 *dst_ptr;
6459   UINT16 pen, basepen;
6460   int count, src_pitch, src_modulo;
6461   int   dst_pitch;
6462
6463   UINT8 code_transparent, code_opaque;
6464
64656438   if (K056832_PageTileMode[page]) return(0);
64666439   if (!K056832_linemap_enabled) return(1);
64676440
6468   tmap = K056832_tilemap[page];
6469   pixmap  = K056832_pixmap[page];
6470   xprmap  = tilemap_get_flagsmap(tmap);
6471   xprdata = tilemap_get_tile_flags(tmap);
64726441
6473   dirty = K056832_LineDirty[page];
6474   all_dirty = K056832_AllLinesDirty[page];
6475
6476   if (all_dirty)
64776442   {
6478      dirty[7]=dirty[6]=dirty[5]=dirty[4]=dirty[3]=dirty[2]=dirty[1]=dirty[0] = 0;
6479      K056832_AllLinesDirty[page] = 0;
64806443
6481      // force tilemap into a clean, static state
6482      // *really ugly but it minimizes alteration to tilemap.c
6483      memset (&zerorect, 0, sizeof(rectangle));   // zero dimension
6484      tilemap_draw(bitmap, &zerorect, tmap, 0, 0);   // dummy call to reset tile_dirty_map
6485      fillbitmap(xprmap, 0, 0);                  // reset pixel transparency_bitmap;
6486      memset(xprdata, TILEMAP_PIXEL_LAYER0, 0x800);   // reset tile transparency_data;
6487   }
6488   else
6489   {
6490      if (!(dirty[0]|dirty[1]|dirty[2]|dirty[3]|dirty[4]|dirty[5]|dirty[6]|dirty[7])) return(0);
6491   }
6444      rectangle zerorect;
6445      tilemap *tmap;
6446      UINT32 *dirty;
6447      int all_dirty;
6448      bitmap_t* xprmap;
6449      UINT8 *xprdata;
64926450
6493   pal_ptr    = machine->pens;
6494   src_gfx    = machine->gfx[K056832_gfxnum];
6495   src_base   = src_gfx->gfxdata;
6496   src_pitch  = src_gfx->line_modulo;
6497   src_modulo = src_gfx->char_modulo;
6498   xpr_ptr    = (UINT8*)xprmap->base + LINE_WIDTH;
6499   dst_ptr    = (UINT16*)pixmap->base + LINE_WIDTH;
6500   dst_pitch  = pixmap->rowpixels;
6451      tmap = K056832_tilemap[page];
6452      xprmap  = tilemap_get_flagsmap(tmap);
6453      xprdata = tilemap_get_tile_flags(tmap);
65016454
6502   for (line=0; line<256; xpr_ptr+=dst_pitch, dst_ptr+=dst_pitch, line++)
6503   {
6504      tile_data *tileinfo = {0};
6505      if (!all_dirty)
6455      dirty = K056832_LineDirty[page];
6456      all_dirty = K056832_AllLinesDirty[page];
6457
6458      if (all_dirty)
65066459      {
6507         offs = line >> 5;
6508         mask = 1 << (line & 0x1f);
6509         if (!(dirty[offs] & mask)) continue;
6510         dirty[offs] ^= mask;
6460         dirty[7]=dirty[6]=dirty[5]=dirty[4]=dirty[3]=dirty[2]=dirty[1]=dirty[0] = 0;
6461         K056832_AllLinesDirty[page] = 0;
6462
6463         // force tilemap into a clean, static state
6464         // *really ugly but it minimizes alteration to tilemap.c
6465         memset (&zerorect, 0, sizeof(rectangle));   // zero dimension
6466         tilemap_draw(bitmap, &zerorect, tmap, 0, 0);   // dummy call to reset tile_dirty_map
6467         fillbitmap(xprmap, 0, 0);                  // reset pixel transparency_bitmap;
6468         memset(xprdata, TILEMAP_PIXEL_LAYER0, 0x800);   // reset tile transparency_data;
65116469      }
6470      else
6471      {
6472         if (!(dirty[0]|dirty[1]|dirty[2]|dirty[3]|dirty[4]|dirty[5]|dirty[6]|dirty[7])) return(0);
6473      }
65126474
6513      K056832_get_tile_info(machine, tileinfo, line, page);
6514      src_ptr = tileinfo->pen_data;//src_base + ((tileinfo->tile_number & ~7) << 6);
6515      basepen = tileinfo->palette_base;
6516      code_transparent = tileinfo->category;
6517      code_opaque = code_transparent | TILEMAP_PIXEL_LAYER0;
6518      count = -LINE_WIDTH;
6475#if 0   /* this code is broken.. really broken .. gijoe uses it for some line/column scroll style effects (lift level of attract mode)
6476            we REALLY shouldn't be writing directly back into the pixmap, surely this should
6477            be done when rendering instead
65196478
6520      do
6479        */
65216480      {
6522         DRAW_PIX(0)
6523         DRAW_PIX(1)
6524         DRAW_PIX(2)
6525         DRAW_PIX(3)
6526         DRAW_PIX(4)
6527         DRAW_PIX(5)
6528         DRAW_PIX(6)
6529         DRAW_PIX(7)
65306481
6531         src_ptr += 8;
6482
6483         bitmap_t *pixmap;
6484
6485         UINT8 code_transparent, code_opaque;
6486         const pen_t *pal_ptr;
6487         const UINT8  *src_base, *src_ptr;
6488         UINT8  *xpr_ptr;
6489         UINT16 *dst_ptr;
6490         UINT16 pen, basepen;
6491         int count, src_pitch, src_modulo;
6492         int   dst_pitch;
6493         int line;
6494         const gfx_element *src_gfx;
6495         int offs, mask;
6496
6497         #define LINE_WIDTH 512
6498
6499         #define DRAW_PIX(N) \
6500            pen = src_ptr[N]; \
6501            if (pen) \
6502            { pen += basepen; xpr_ptr[count+N] = TILEMAP_PIXEL_LAYER0; dst_ptr[count+N] = pen; } else \
6503            { xpr_ptr[count+N] = 0; }
6504
6505         pixmap  = K056832_pixmap[page];
6506         pal_ptr    = machine->pens;
6507         src_gfx    = machine->gfx[K056832_gfxnum];
6508         src_base   = src_gfx->gfxdata;
6509         src_pitch  = src_gfx->line_modulo;
6510         src_modulo = src_gfx->char_modulo;
6511         dst_pitch  = pixmap->rowpixels;
6512
6513         for (line=0; line<256; line++)
6514         {
6515
6516
6517            tile_data tileinfo = {0};
6518
6519            dst_ptr = BITMAP_ADDR16(pixmap, line, 0);
6520            xpr_ptr = BITMAP_ADDR8(xprmap, line, 0);
6521
6522            if (!all_dirty)
6523            {
6524               offs = line >> 5;
6525               mask = 1 << (line & 0x1f);
6526               if (!(dirty[offs] & mask)) continue;
6527               dirty[offs] ^= mask;
6528            }
6529
6530            for (count = 0; count < LINE_WIDTH; count+=8)
6531            {
6532               K056832_get_tile_info(machine, &tileinfo, line, page);
6533               basepen = tileinfo.palette_base;
6534               code_transparent = tileinfo.category;
6535               code_opaque = code_transparent | TILEMAP_PIXEL_LAYER0;
6536
6537               src_ptr = tileinfo.pen_data + count*8;//src_base + ((tileinfo.tile_number & ~7) << 6);
6538
6539               DRAW_PIX(0)
6540               DRAW_PIX(1)
6541               DRAW_PIX(2)
6542               DRAW_PIX(3)
6543               DRAW_PIX(4)
6544               DRAW_PIX(5)
6545               DRAW_PIX(6)
6546               DRAW_PIX(7)
6547            }
6548         }
6549
6550         #undef LINE_WIDTH
6551         #undef DRAW_PIX
65326552      }
6533      while (count += 8);
6553#endif
6554
65346555   }
65356556
65366557   return(0);
6537
6538#undef LINE_WIDTH
6539#undef DRAW_PIX
65406558}
65416559
65426560void K056832_tilemap_draw(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int layer, int flags, UINT32 priority)
src/mame/video/digdug.c
r2762r2763
277277      if (size)
278278         sprite = (sprite & 0xc0) | ((sprite & ~0xc0) << 2);
279279
280      sy -= 16 * size;
281      sy = (sy & 0xff) - 32;   // fix wraparound
282
280283      if (flip_screen_get())
281284      {
282285         flipx ^= 1;
283286         flipy ^= 1;
287         sy += 48;
284288      }
285289
286      sy -= 16 * size;
287      sy = (sy & 0xff) - 32;   // fix wraparound
288
289290      for (y = 0;y <= size;y++)
290291      {
291292         for (x = 0;x <= size;x++)
src/mame/video/mappy.c
r2762r2763
427427         sprite &= ~sizex;
428428         sprite &= ~(sizey << 1);
429429
430         sy -= 16 * sizey;
431         sy = (sy & 0xff) - 32;   // fix wraparound
432
430433         if (flip_screen_get())
431434         {
432435            flipx ^= 1;
433436            flipy ^= 1;
437            sy += 40;
434438         }
435439
436         sy -= 16 * sizey;
437         sy = (sy & 0xff) - 32;   // fix wraparound
438
439440         for (y = 0;y <= sizey;y++)
440441         {
441442            for (x = 0;x <= sizex;x++)
r2762r2763
502503         int sizey = size[(spriteram_3[offs] & 0x30) >> 4];
503504         int x,y;
504505
506         sy -= 8 * sizey;
507         sy = (sy & 0xff) - 32;   // fix wraparound
508
505509         if (flip_screen_get())
506510         {
507511            flipx ^= 1;
508512            flipy ^= 1;
513            sy += 40;
509514         }
510515
511         sy -= 8 * sizey;
512         sy = (sy & 0xff) - 32;   // fix wraparound
513
514516         for (y = 0;y <= sizey;y++)
515517         {
516518            for (x = 0;x <= sizex;x++)
r2762r2763
533535{
534536   int x,y;
535537
538   tilemap_set_scrolldx(bg_tilemap, 0, 96);
539   tilemap_set_scrolldy(bg_tilemap, 0, 0);
540
536541   tilemap_draw(bitmap,cliprect,bg_tilemap,TILEMAP_DRAW_OPAQUE | TILEMAP_DRAW_ALL_CATEGORIES,0);
537542
538543   fillbitmap(sprite_bitmap,15,cliprect);
r2762r2763
559564   /* flip screen control is embedded in RAM */
560565   flip_screen_set(mappy_spriteram[0x1f7f-0x800] & 1);
561566
567   tilemap_set_scrolldx(bg_tilemap, 0, 96);
568   tilemap_set_scrolldy(bg_tilemap, 0, 0);
569
562570   tilemap_draw(bitmap,cliprect,bg_tilemap,TILEMAP_DRAW_OPAQUE | TILEMAP_DRAW_ALL_CATEGORIES,0);
563571
564572   phozon_draw_sprites(screen->machine,bitmap,cliprect);
r2762r2763
572580{
573581   int offs;
574582
583   tilemap_set_scrolldx(bg_tilemap, 0, 96);
584   tilemap_set_scrolldy(bg_tilemap, 0, 0);
585
575586   for (offs = 2;offs < 34;offs++)
576587      tilemap_set_scrolly(bg_tilemap,offs,mappy_scroll);
577588
src/mame/drivers/mitchell.c
r2762r2763
139139
140140***************************************************************************/
141141
142static const struct EEPROM_interface eeprom_interface =
142static const eeprom_interface eeprom_intf =
143143{
144144   6,      /* address bits */
145145   16,      /* data bits */
r2762r2763
156156{
157157   if (read_or_write)
158158   {
159      EEPROM_save(file);               /* EEPROM */
159      eeprom_save(file);               /* EEPROM */
160160      if (nvram_size)   /* Super Pang, Block Block */
161161         mame_fwrite(file,nvram,nvram_size);   /* NVRAM */
162162   }
163163   else
164164   {
165      EEPROM_init(&eeprom_interface);
165      eeprom_init(&eeprom_intf);
166166
167167      if (file)
168168      {
169169         init_eeprom_count = 0;
170         EEPROM_load(file);               /* EEPROM */
170         eeprom_load(file);               /* EEPROM */
171171         if (nvram_size)   /* Super Pang, Block Block */
172172            mame_fread(file,nvram,nvram_size);   /* NVRAM */
173173      }
r2762r2763
180180{
181181   int bit;
182182
183   bit = EEPROM_read_bit() << 7;
183   bit = eeprom_read_bit() << 7;
184184
185185   /* bits 0 and (sometimes) 3 are checked in the interrupt handler. */
186186   /* Maybe they are vblank related, but I'm not sure. */
r2762r2763
198198
199199static WRITE8_HANDLER( eeprom_cs_w )
200200{
201   EEPROM_set_cs_line(data ? CLEAR_LINE : ASSERT_LINE);
201   eeprom_set_cs_line(data ? CLEAR_LINE : ASSERT_LINE);
202202}
203203
204204static WRITE8_HANDLER( eeprom_clock_w )
205205{
206   EEPROM_set_clock_line(data ? CLEAR_LINE : ASSERT_LINE);
206   eeprom_set_clock_line(data ? CLEAR_LINE : ASSERT_LINE);
207207}
208208
209209static WRITE8_HANDLER( eeprom_serial_w )
210210{
211   EEPROM_write_bit(data);
211   eeprom_write_bit(data);
212212}
213213
214214
src/mame/drivers/rainbow.c
r2762r2763
648648MACHINE_DRIVER_END
649649
650650
651/* Jumping The pcb has 2 xtals, 24MHz and 18,432MHz */
651652static MACHINE_DRIVER_START( jumping )
652653
653654   /* basic machine hardware */
654   MDRV_CPU_ADD(M68000, 8000000)
655   MDRV_CPU_ADD(M68000, XTAL_24MHz/3)   /* not verified but matches original */
655656   MDRV_CPU_PROGRAM_MAP(jumping_readmem,jumping_writemem)
656657   MDRV_CPU_VBLANK_INT("main", irq4_line_hold)
657658
658   MDRV_CPU_ADD(Z80, 4000000)
659   MDRV_CPU_ADD(Z80, XTAL_18_432MHz/6)   /* not verified but music tempo matches original */
659660   MDRV_CPU_PROGRAM_MAP(jumping_sound_readmem,jumping_sound_writemem)
660661
661662   MDRV_INTERLEAVE(10)   /* 10 CPU slices per frame - enough ? */
r2762r2763
677678   /* sound hardware */
678679   MDRV_SPEAKER_STANDARD_MONO("mono")
679680
680   MDRV_SOUND_ADD(YM2203, 3579545)
681   MDRV_SOUND_ADD(YM2203, XTAL_18_432MHz/6)   /* not verified */
681682   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.30)
682683
683   MDRV_SOUND_ADD(YM2203, 3579545)
684   MDRV_SOUND_ADD(YM2203, XTAL_18_432MHz/6)   /* not verified */
684685   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.30)
685686MACHINE_DRIVER_END
686687
src/mame/drivers/deco_mlc.c
r2762r2763
117117
118118static READ32_HANDLER( avengrs_control_r )
119119{
120   return (input_port_read_indexed(machine, 1)<<16) | (EEPROM_read_bit()<<23) | input_port_read_indexed(machine, 0);
120   return (input_port_read_indexed(machine, 1)<<16) | (eeprom_read_bit()<<23) | input_port_read_indexed(machine, 0);
121121}
122122
123123static READ32_HANDLER(test2_r)
r2762r2763
145145   if (ACCESSING_BITS_8_15) {
146146      UINT8 ebyte=(data>>8)&0xff;
147147//      if (ebyte&0x80) {
148         EEPROM_set_clock_line((ebyte & 0x2) ? ASSERT_LINE : CLEAR_LINE);
149         EEPROM_write_bit(ebyte & 0x1);
150         EEPROM_set_cs_line((ebyte & 0x4) ? CLEAR_LINE : ASSERT_LINE);
148         eeprom_set_clock_line((ebyte & 0x2) ? ASSERT_LINE : CLEAR_LINE);
149         eeprom_write_bit(ebyte & 0x1);
150         eeprom_set_cs_line((ebyte & 0x4) ? CLEAR_LINE : ASSERT_LINE);
151151//      }
152152   }
153153   else if (ACCESSING_BITS_0_7) {
src/mame/drivers/rungun.c
r2762r2763
5757static int rng_z80_control;
5858static int rng_sound_status;
5959
60static const struct EEPROM_interface eeprom_interface =
60static const eeprom_interface eeprom_intf =
6161{
6262   7,         /* address bits */
6363   8,         /* data bits */
r2762r2763
7171static NVRAM_HANDLER( rungun )
7272{
7373   if (read_or_write)
74      EEPROM_save(file);
74      eeprom_save(file);
7575   else
7676   {
77      EEPROM_init(&eeprom_interface);
77      eeprom_init(&eeprom_intf);
7878
7979      if (file)
8080      {
8181         init_eeprom_count = 0;
82         EEPROM_load(file);
82         eeprom_load(file);
8383      }
8484      else
8585         init_eeprom_count = 10;
r2762r2763
124124      case 0x06/2:
125125         if (ACCESSING_BITS_0_7)
126126         {
127            data = input_port_read_indexed(machine, 1) | EEPROM_read_bit();
127            data = input_port_read_indexed(machine, 1) | eeprom_read_bit();
128128
129129            if (init_eeprom_count)
130130            {
r2762r2763
147147   {
148148      case 0x08/2:
149149         /*
150                bit0  : EEPROM_write_bit
151                bit1  : EEPROM_set_cs_line
152                bit2  : EEPROM_set_clock_line
150                bit0  : eeprom_write_bit
151                bit1  : eeprom_set_cs_line
152                bit2  : eeprom_set_clock_line
153153                bit3  : coin counter?
154154                bit7  : set before massive memory writes
155155                bit10 : IRQ5 ACK
156156            */
157157         if (ACCESSING_BITS_0_7)
158158         {
159            EEPROM_write_bit((data & 0x01) ? 1 : 0);
160            EEPROM_set_cs_line((data & 0x02) ? CLEAR_LINE : ASSERT_LINE);
161            EEPROM_set_clock_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE);
159            eeprom_write_bit((data & 0x01) ? 1 : 0);
160            eeprom_set_cs_line((data & 0x02) ? CLEAR_LINE : ASSERT_LINE);
161            eeprom_set_clock_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE);
162162         }
163163
164164         if (!(data & 0x40))
src/mame/drivers/aerofgt.c
r2762r2763
7070extern UINT16 *aerofgt_spriteram1,*aerofgt_spriteram2,*aerofgt_spriteram3;
7171extern UINT16 *wbbc97_bitmapram;
7272extern size_t aerofgt_spriteram1_size,aerofgt_spriteram2_size,aerofgt_spriteram3_size;
73extern UINT16 *spikes91_tx_tilemap_ram;
7374
7475WRITE16_HANDLER( aerofgt_bg1videoram_w );
7576WRITE16_HANDLER( aerofgt_bg2videoram_w );
r2762r2763
200201   AM_RANGE(0x200000, 0x203fff) AM_RAM AM_BASE(&aerofgt_spriteram1) AM_SIZE(&aerofgt_spriteram1_size)
201202   AM_RANGE(0xc04000, 0xc04001) AM_WRITENOP
202203   AM_RANGE(0xff8000, 0xff8fff) AM_RAM_WRITE(aerofgt_bg1videoram_w) AM_BASE(&aerofgt_bg1videoram)
203   AM_RANGE(0xffc000, 0xffcbff) AM_RAM AM_BASE(&aerofgt_spriteram3) AM_SIZE(&aerofgt_spriteram3_size)
204
205   AM_RANGE(0xffa000, 0xffbfff) AM_RAM AM_BASE(&spikes91_tx_tilemap_ram)
206
207   AM_RANGE(0xffc000, 0xffcfff) AM_RAM AM_BASE(&aerofgt_spriteram3) AM_SIZE(&aerofgt_spriteram3_size)
204208   //AM_RANGE(0xffd200, 0xffd201) AM_WRITE(pspikesb_gfxbank_w)
205209   AM_RANGE(0xffd000, 0xffdfff) AM_RAM AM_BASE(&aerofgt_rasterram)   /* bg1 scroll registers */
206210   AM_RANGE(0xffe000, 0xffefff) AM_RAM_WRITE(paletteram16_xRRRRRGGGGGBBBBB_word_w) AM_BASE(&paletteram16)
r2762r2763
13711375   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
13721376   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
13731377   MDRV_SCREEN_SIZE(64*8, 32*8)
1374   MDRV_SCREEN_VISIBLE_AREA(0*8+4, 44*8+4-1, 0*8, 30*8-1)
1378   MDRV_SCREEN_VISIBLE_AREA(0*8, 320-1, 0*8+4, 224+4-1)
13751379   MDRV_GFXDECODE(spikes91)
13761380   MDRV_PALETTE_LENGTH(2048)
13771381
src/mame/drivers/ultrsprt.c
r2762r2763
5151   UINT32 r = 0;
5252
5353   if (ACCESSING_BITS_24_31)
54      r |= (((EEPROM_read_bit()) << 1) | (input_port_read_indexed(machine, 6) << 3)) << 24;
54      r |= (((eeprom_read_bit()) << 1) | (input_port_read_indexed(machine, 6) << 3)) << 24;
5555
5656   return r;
5757}
r2762r2763
6060{
6161   if (ACCESSING_BITS_24_31)
6262   {
63      EEPROM_write_bit((data & 0x01000000) ? 1 : 0);
64      EEPROM_set_clock_line((data & 0x02000000) ? CLEAR_LINE : ASSERT_LINE);
65      EEPROM_set_cs_line((data & 0x04000000) ? CLEAR_LINE : ASSERT_LINE);
63      eeprom_write_bit((data & 0x01000000) ? 1 : 0);
64      eeprom_set_clock_line((data & 0x02000000) ? CLEAR_LINE : ASSERT_LINE);
65      eeprom_set_cs_line((data & 0x04000000) ? CLEAR_LINE : ASSERT_LINE);
6666   }
6767}
6868
r2762r2763
190190{
191191   if (read_or_write)
192192   {
193      EEPROM_save(file);
193      eeprom_save(file);
194194   }
195195   else
196196   {
197      EEPROM_init(&eeprom_interface_93C46);
197      eeprom_init(&eeprom_interface_93C46);
198198      if (file)
199199      {
200         EEPROM_load(file);
200         eeprom_load(file);
201201      }
202202   }
203203}
src/mame/drivers/simpl156.c
r2762r2763
137137
138138static READ32_HANDLER( simpl156_inputs_read )
139139{
140   int eep = EEPROM_read_bit();
140   int eep = eeprom_read_bit();
141141   UINT32 returndata;
142142
143143   returndata = input_port_read_indexed(machine, 0)^0xffff0000;
r2762r2763
184184
185185   OKIM6295_set_bank_base(1, 0x40000 * (data & 0x7) );
186186
187   EEPROM_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
188   EEPROM_write_bit(data & 0x10);
189   EEPROM_set_cs_line((data & 0x40) ? CLEAR_LINE : ASSERT_LINE);
187   eeprom_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
188   eeprom_write_bit(data & 0x10);
189   eeprom_set_cs_line((data & 0x40) ? CLEAR_LINE : ASSERT_LINE);
190190}
191191
192192
r2762r2763
458458static NVRAM_HANDLER( simpl156 )
459459{
460460   if (read_or_write)
461      EEPROM_save(file);
461      eeprom_save(file);
462462   else
463463   {
464      EEPROM_init(&eeprom_interface_93C46);// 93c45
464      eeprom_init(&eeprom_interface_93C46);// 93c45
465465
466      if (file) EEPROM_load(file);
466      if (file) eeprom_load(file);
467467      else
468468      {
469469         if (simpl156_default_eeprom)   /* Set the EEPROM to Factory Defaults */
470            EEPROM_set_data(simpl156_default_eeprom,0x100);
470            eeprom_set_data(simpl156_default_eeprom,0x100);
471471      }
472472   }
473473}
src/mame/drivers/bking.c
r2762r2763
262262   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 )
263263   PORT_BIT( 0xfc, IP_ACTIVE_HIGH, IPT_UNUSED )
264264
265   /* continue inputs are labelled in schematics. */
266   /* They are not connected though to any button */
267
265268   PORT_START  /* IN1 */
266269   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START1 )
267270   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START2 )
268   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START1 ) /* Continue 1 */
269   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START2 ) /* Continue 2 */
271   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED ) /* Continue 1 */
272   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED ) /* Continue 2 */
270273   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_SERVICE1 )
271274   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_TILT )
272275   PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED ) /* Not Connected */
src/mame/drivers/galpani2.c
r2762r2763
3838static UINT16 eeprom_word;
3939static READ16_HANDLER(galpani2_eeprom_r)
4040{
41   return (eeprom_word & ~1) | (EEPROM_read_bit() & 1);
41   return (eeprom_word & ~1) | (eeprom_read_bit() & 1);
4242}
4343
4444static WRITE16_HANDLER(galpani2_eeprom_w)
r2762r2763
4747   if ( ACCESSING_BITS_0_7 )
4848   {
4949      // latch the bit
50      EEPROM_write_bit(data & 0x02);
50      eeprom_write_bit(data & 0x02);
5151
5252      // reset line asserted: reset.
53      EEPROM_set_cs_line((data & 0x08) ? CLEAR_LINE : ASSERT_LINE );
53      eeprom_set_cs_line((data & 0x08) ? CLEAR_LINE : ASSERT_LINE );
5454
5555      // clock line asserted: write latch or select next bit to read
56      EEPROM_set_clock_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE );
56      eeprom_set_clock_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE );
5757   }
5858}
5959
src/mame/drivers/hornet.c
r2762r2763
11/*  Konami Hornet System
2
32    Driver by Ville Linde
43
54
5    Konami 'Hornet' Hardware
6    Konami, 1997-1999
67
8    Known games on this hardware include....
9
10    Game                             (C)      Year
11    ----------------------------------------------
12    Gradius 4 : Fukkatsu             Konami   1999
13    NBA Play by Play                 Konami   1998
14    Silent Scope                     Konami   1999
15    Silent Scope 2 : Fatal Judgement Konami   2000
16    Silent Scope 2 : Dark Silhouette Konami   2000
17    Terraburst                       Konami   1998
18
719    Hardware overview:
820
921    GN715 CPU Board:
r2762r2763
3143
3244
3345    Hardware configurations:
46    ------------------------
3447
35    Game             | ID        | CPU PCB      | CG Board(s)   | LAN PCB
36    ---------------------------------------------------------------------------
37    Gradius 4        | GX837     | GN715(A)     | GN715(B)      |
38    NBA Play by Play | GX778     | GN715(A)     | GN715(B)      |
39    Silent Scope     | GQ830     | GN715(A)     | 2x GN715(B)   |
40    Silent Scope 2   | GQ931     | GN715(A)     | 2x GQ871(B)   | GQ931(H)
48    Game              KONAMI ID  CPU PCB    GFX Board(s)  LAN PCB
49    --------------------------------------------------------------
50    Gradius 4         GX837      GN715(A)   GN715(B)
51    NBA Play By Play  GX778      GN715(A)   GN715(B)
52    Silent Scope      GQ830      GN715(A)   2x GN715(B)
53    Silent Scope 2    GQ931      GN715(A)   2x GQ871(B)   GQ931(H)
4154
4255
56    PCB Layouts
57    -----------
4358
44
45    Top Board GN715 PWB(A)A
59    Top Board
60    GN715 PWB(A)A
4661    |--------------------------------------------------------------|
47    |                                                              |
48    |                                                        PAL   |
49    |               PAL               68EC000          837A08.7S   |
50    |NE5532         PAL                                            |
51    |                         DRM1M4SJ8                            |
52    |NE5532                                                        |
53    |     SM5877              RF5C400                              |
54    |                                                              |
62    | SP485CS CN10       CN11        CN9          JP8 JP9 JP10 JP11|
63    |CN19                                                    PAL1  |
64    |CN21       JP13 PAL2             68EC000          EPROM.7S    |
65    |   NE5532       PAL3                                      CN12|
66    |           JP12  JP16    DRM1M4SJ8                        CN13|
67    |   NE5532                            MASKROM.9P    MASKROM.9T |
68    |     SM5877 JP15         RF5C400                              |
69    |CN18                                 MASKROM.12P   MASKROM.12T|
5570    |     SM5877     16.9344MHz                                    |
56    |                SRAM256K               837A10.14P  837A05.14T |
71    |CN14            SRAM256K             MASKROM.14P  MASKROM.14T|
5772    |                                                              |
58    |                SRAM256K               837A09.16P  837A04.16T |
73    |CN16            SRAM256K             MASKROM.16P  MASKROM.16T|
5974    |  ADC12138                                                    |
60    |             056800                                           |
75    |             056800            JP5                            |
76    |                               JP4                            |
77    |                      MACH111  JP3                |---------| |
78    |   TEST_SW                         EPROM.22P      |         | |
79    |CN1                   DRAM16X16                   |PPC403GA | |
80    |                                   EPROM.25P      |         | |
81    |                                                  |         | |
82    |                      DRAM16X16    EPROM.27P      |---------| |
83    | 4AK16                                                     JP6|
6184    |                                                              |
62    |                      MACH111                                 |
63    |                                                              |
64    |                      DRAM16X16                      PPC403GA |
65    |                                   837C01.27P                 |
66    |                                                              |
67    |                      DRAM16X16                               |
68    | 4AK16                                                        |
69    |                                                              |
70    |                                                              |
71    | 0038323  PAL                                        7.3728MHz|
72    | E9825                                                        |
85    |CN3                                                           |
86    | 0038323  PAL4                                       7.3728MHz|
87    | E9825    058232           CN2                                |
7388    |                                                     50.000MHz|
74    |                                                              |
75    |M48T58Y-70PC1                                        64.000MHz|
89    |    RESET_SW               CN5                    JP1  JP2    |
90    |M48T58Y-70PC1  CN4                 CN6               64.000MHz|
7691    |--------------------------------------------------------------|
77
7892    Notes:
79        DRM1M4SJ8 = Fujitsu 81C4256 DRAM (SOJ24)
80        SRAM256K = Cypress CY7C199 SRAM (SOJ28)
81        DRAM16X16 = Fujitsu 8118160A-60 DRAM (SOJ42)
82        0038323 E9825 = SOIC8, I've seen a similar chip in the security cart of System573
83        M48T58Y-70PC1 = ST Timekeeper RAM
93          DRM1M4SJ8 - Fujitsu 81C4256 256Kx4 DRAM (SOJ24)
94           SRAM256K - Cypress CY7C199 32kx8 SRAM (SOJ28)
95          DRAM16X16 - Fujitsu 8118160A-60 16megx16 DRAM (SOJ42)
96      0038323 E9825 - SOIC8 (Secured PIC?). I've seen a similar chip in the security cart of System573
97      M48T58Y-70PC1 - ST Timekeeper RAM
98            RF5C400 - Ricoh RF5C400 PCM 32Ch, 44.1 kHz Stereo, 3D Effect Spatializer, clock input 16.9344MHz
99             056800 - Konami Custom (QFP80)
100             058232 - Konami Custom Ceramic Package (SIL14)
101           ADC12138 - National Semiconductor ADC12138 A/D Converter, 12-bit + Serial I/O With MUX (SOP28)
102            MACH111 - AMD MACH111 CPLD (Stamped 'N676A1', PLCC44)
103            68EC000 - Motorola MC68EC000, running at 16.0MHz (64/4)
104           PPC403GA - IBM PowerPC 403GA CPU, clock input 32.0MHz (QFP160)
105           SM5877AM - Nippon Precision Circuits 3rd Order 2-Channel D/A Converter (SOIC24)
106              4AK16 - Hitachi 4AK16 Silicon N-Channel Power MOS FET Array (SIL10)
107           NE5532AN - Philips, Dual Low-Noise High-Speed Audio OP Amp (DIP8)
108            SP485CS - Sipex SP485CS Low Power Half Duplex RS485 Transceiver (DIP8)
109               PAL1 - AMD PALCE16V8 (stamped 'N676A4', DIP20)
110               PAL2 - AMD PALCE16V8 (stamped 'N676A2', DIP20)
111               PAL3 - AMD PALCE16V8 (stamped 'N676A3', DIP20)
112               PAL4 - AMD PALCE16V8 (stamped 'N676A5', DIP20)
113                JP1 -       25M O O-O 32M
114                JP2 -       25M O O-O 32M
115                JP3 -        RW O O O RO
116                JP4 - PROG  32M O O-O 16M
117                JP5 - DATA  32M O-O O 16M
118                JP6 - BOOT   16 O-O O 32
119                JP7 - SRC DOUT2 O O-O 0
120                JP8 -   64M&32M O-O O 16M
121                JP9 -       64M O O-O 32M&16M
122               JP10 -   64M&32M O-O O 16M
123               JP11 -       64M O O-O 32M&16M
124               JP12 -      THRU O-O O SP
125               JP13 -      THRU O-O O SP
126               JP14 - WDT       O O
127               JP15 -      MONO O-O O SURR
128               JP16 -      HIGH O O O MID (N/C LOW)
129       CN1 THRU CN3 - Multi-pin Flat Cable Connector
130                CN4 - Multi-pin Connector for Network PCB
131                CN5 - Multi-pin Flat Cable Connector
132                CN6 - 96-Pin To Lower PCB, Joining Connector
133       CN7 THRU CN8 - Not used
134      CN9 THRU CN11 - 6-Pin Power Connectors
135               CN19 - USB Connector
136               CN21 - 5-Pin Analog Controls Connector (Tied to USB Connector via the Filter Board)
137               CN18 - RCA Mono Audio OUT
138        CN14 & CN16 - RCA Stereo Audio OUT
84139
85140
86    Bottom Board GN715 PWB(B)A
141    ROM Usage
142    ---------
143                 |------------------------------- ROM Locations ----------------------------------|
144    Game         27P     25P  22P   16P     14P     12P     9P      16T     14T     12T  9T  7S
145    -----------------------------------------------------------------------------------------------
146    Gradius 4    837C01  -    -     837A09  837A10  -       778A12  837A04  837A05  -    -   837A08
147    NBA P/Play   778A01  -    -     778A09  778A10  778A11  778A12  778A04  778A05  -    -   778A08
148    S/Scope      830B01  -    -     830A09  830A10  -       -       -       -       -    -   830A08
149    S/Scope 2    931D01  -    -     931A09  931A10  931A11  -       931A04  -       -    -   931A08
150    Terraburst
151
152
153    Bottom Board
154    GN715 PWB(B)A
87155    |--------------------------------------------------------------|
88    |                                                              |
89    |JP1                                          4M EDO   4M EDO  |
90    |                                                              |
91    |  4M EDO 4M EDO      TEXELFX                                  |
92    |                                                       4M EDO |
93    |  4M EDO 4M EDO                  PIXELFX               4M EDO |
94    |                                                              |
95    |  4M EDO 4M EDO                                KONAMI         |
96    |                                   50MHz       0000033906     |
97    |  4M EDO 4M EDO                                               |
98    |                       256KSRAM 256KSRAM                      |
99    |                                                              |
156    |CN4        CN2    CN8               CN6                    CN5|
157    |JP1                 |---------|              4M_EDO   4M_EDO  |
158    |                    |         |     |----------|              |
159    |  4M_EDO 4M_EDO     | TEXELFX |     |          |              |
160    |                    |         |     | PIXELFX  |       4M_EDO |
161    |  4M_EDO 4M_EDO     |         |     |          |       4M_EDO |
162    |                    |---------|     |          | |--------|   |
163    |  4M_EDO 4M_EDO                     |----------| |KONAMI  |   |
164    |CN3                                50MHz JP7     |33906   |   |
165    |  4M_EDO 4M_EDO                          JP6     |        |   |
166    |                       256KSRAM 256KSRAM         |--------|   |
167    |CN7                                                           |
100168    |         AV9170                     1MSRAM 1MSRAM             |
101169    | MC44200                                                      |
102170    |                       256KSRAM 256KSRAM                      |
103171    |                                    1MSRAM 1MSRAM             |
104    |                                               837A13.24U     |
105    |  KONAMI    MACH111                                 837A15.24V|
106    |  0000037122                        1MSRAM 1MSRAM             |
107    |                       ADSP-21062                             |
108    |                       SHARC    36.00MHz                      |
109    |1MSRAM                              1MSRAM 1MSRAM             |
110    |                                                              |
111    |1MSRAM                  PAL  PAL                              |
112    |           256KSRAM                            837A14.32U     |
113    |1MSRAM     256KSRAM                                 837A16.32V|
114    |           256KSRAM                                           |
172    |  |-------|                                    MASKROM.24U    |
173    |  |KONAMI |  MACH111  |-------------|              MASKROM.24V|
174    |  |37122  |           |ANALOG       |   1MSRAM 1MSRAM         |
175    |  |       |           |DEVICES      |                         |
176    |  |-------|       JP5 |ADSP-21062   |   36.00MHz              |
177    |1MSRAM                |SHARC        |   1MSRAM 1MSRAM         |
178    |                      |             |                         |
179    |1MSRAM                |             |                         |
180    |           256KSRAM   |-------------|          MASKROM.32U    |
181    |1MSRAM     256KSRAM                                MASKROM.32V|
182    |           256KSRAM     PAL1  PAL2            JP4             |
115183    |1MSRAM                                                        |
116    |           JP2                                                |
184    |           JP2                 CN1            JP3             |
117185    |--------------------------------------------------------------|
118
119186    Notes:
120        4M EDO = SM81C256K16CJ-35 RAM 66MHz
121        1MSRAM = CY7C109-25VC
122        256KSRAM = W24257AJ-15
123        TEXELFX = 3DFX 500-0004-02 BD0665.1 TMU (QFP208)
124        PIXELFX = 3DFX 500-0003-03 F001701.1 FBI (QFP240)
125        JP1 = Jumper set to SCR. Alt. setting is TWN
126        JP2 = Jumper set for MASTER, Alt. setting SLAVE
187          4M_EDO - Silicon Magic SM81C256K16CJ-35 EDO DRAM 66MHz (SOJ40)
188          1MSRAM - Cypress CY7C109-25VC 1Meg SRAM (SOJ32)
189        256KSRAM - Winbond W24257AJ-15 256K SRAM (SOJ28)
190         TEXELFX - 3DFX 500-0004-02 BD0665.1 TMU (QFP208)
191         PIXELFX - 3DFX 500-0003-03 F001701.1 FBI (QFP240)
192      0000037122 - Konami Custom (QFP208)
193       MC44200FT - Motorola MC44200FT 3 Channel Video D/A Converter (QFP44)
194         MACH111 - AMD MACH111 CPLD (Stamped 'N715B1', PLCC44)
195          AV9170 - Integrated Circuit Systems Inc. Clock Multiplier (SOIC8)
196            PAL1 - AMD PALCE16V8 (stamped 'N676B4', DIP20)
197            PAL2 - AMD PALCE16V8 (stamped 'N676B5', DIP20)
198             JP1 -    SCR O O-O TWN
199             JP2 - MASTER O-O O SLAVE
200             JP3 -    16M O O-O 32M
201             JP4 -    32M O-O O 16M
202             JP5 -  ASYNC O O-O SYNC
203             JP6 -    DSP O O-O ADCK
204             JP7 -    MCK O-O O SCK
205             CN1 - 96 Pin To Lower PCB, Joining Connector
206             CN2 - 8-Pin RGB OUT
207             CN3 - 15-Pin DSUB VGA Video MAIN OUT
208             CN4 - 6-Pin Power Connector
209             CN5 - 4-Pin Power Connector
210             CN6 - 2-Pin Connector (Not Used)
211             CN7 - 15-Pin DSUB VGA Video MAIN OUT
212             CN8 - 6-Pin Connector (Not Used)
127213
214    ROM Usage
215    ---------
216                 |------ ROM Locations -------|
217    Game         24U     24V     32U     32V
218    -------------------------------------------
219    Gradius 4    837A13  837A15  837A14  837A16
220    NBA P/Play   778A13  778A15  778A14  778A16
221    S/Scope      -       -       -       -          (no ROMs, not used)
222    S/Scope 2    -       -       -       -          (no ROMs, not used)
223    Terraburst
128224
129225
226
130227    LAN PCB: GQ931 PWB(H)      (C) 1999 Konami
131228    ------------------------------------------
132229
r2762r2763
161258    37D  set to Slave
162259
163260
164
165261    1 x 64.0000MHz
166262    1 x 36.0000MHz  (to 27L, ADSP)
167263
src/mame/drivers/policetr.c
r2762r2763
147147
148148static READ32_HANDLER( port1_r )
149149{
150   return (input_port_read_indexed(machine, 1) << 16) | (EEPROM_read_bit() << 29);
150   return (input_port_read_indexed(machine, 1) << 16) | (eeprom_read_bit() << 29);
151151}
152152
153153
r2762r2763
180180   /* handle EEPROM I/O */
181181   if (ACCESSING_BITS_16_23)
182182   {
183      EEPROM_write_bit(data & 0x00800000);
184      EEPROM_set_cs_line((data & 0x00200000) ? CLEAR_LINE : ASSERT_LINE);
185      EEPROM_set_clock_line((data & 0x00400000) ? ASSERT_LINE : CLEAR_LINE);
183      eeprom_write_bit(data & 0x00800000);
184      eeprom_set_cs_line((data & 0x00200000) ? CLEAR_LINE : ASSERT_LINE);
185      eeprom_set_clock_line((data & 0x00400000) ? ASSERT_LINE : CLEAR_LINE);
186186   }
187187
188188   /* toggling BSMT off then on causes a reset */
r2762r2763
269269 *
270270 *************************************/
271271
272static const struct EEPROM_interface eeprom_interface_policetr =
272static const eeprom_interface eeprom_interface_policetr =
273273{
274274   8,            // address bits 8
275275   16,            // data bits    16
r2762r2763
284284static NVRAM_HANDLER( policetr )
285285{
286286   if (read_or_write)
287      EEPROM_save(file);
287      eeprom_save(file);
288288   else
289289   {
290      EEPROM_init(&eeprom_interface_policetr);
291      if (file)   EEPROM_load(file);
290      eeprom_init(&eeprom_interface_policetr);
291      if (file)   eeprom_load(file);
292292   }
293293}
294294
src/mame/drivers/seibuspi.c
r2762r2763
883883   // tile banks
884884   if( ACCESSING_BITS_16_23 ) {
885885      rf2_set_layer_banks(data >> 16);
886      EEPROM_write_bit((data & 0x800000) ? 1 : 0);
887      EEPROM_set_clock_line((data & 0x400000) ? ASSERT_LINE : CLEAR_LINE);
888      EEPROM_set_cs_line((data & 0x200000) ? CLEAR_LINE : ASSERT_LINE);
886      eeprom_write_bit((data & 0x800000) ? 1 : 0);
887      eeprom_set_clock_line((data & 0x400000) ? ASSERT_LINE : CLEAR_LINE);
888      eeprom_set_cs_line((data & 0x200000) ? CLEAR_LINE : ASSERT_LINE);
889889   }
890890
891891   // oki banking
r2762r2763
930930static READ32_HANDLER( spi_controls2_r )
931931{
932932   if( ACCESSING_BITS_0_7 ) {
933      return ((input_port_read_indexed(machine, 2) | 0xffffff00) & ~0x40) | (EEPROM_read_bit() << 6);
933      return ((input_port_read_indexed(machine, 2) | 0xffffff00) & ~0x40) | (eeprom_read_bit() << 6);
934934   }
935935   return 0xffffffff;
936936}
r2762r2763
17001700}
17011701
17021702/* this is a 93C46 but with reset delay */
1703static const struct EEPROM_interface eeprom_interface =
1703static const eeprom_interface eeprom_intf =
17041704{
17051705   6,            /* address bits */
17061706   16,            /* data bits */
r2762r2763
17161716static NVRAM_HANDLER( sxx2f )
17171717{
17181718   if( read_or_write ) {
1719      EEPROM_save(file);
1719      eeprom_save(file);
17201720   } else {
1721      EEPROM_init(&eeprom_interface);
1721      eeprom_init(&eeprom_intf);
17221722
17231723      if(file)
1724         EEPROM_load(file);
1724         eeprom_load(file);
17251725   }
17261726}
17271727
src/mame/drivers/seta2.c
r2762r2763
490490{
491491   if (read_or_write)
492492   {
493      EEPROM_save(file);
493      eeprom_save(file);
494494   }
495495   else
496496   {
497      EEPROM_init(&eeprom_interface_93C46);
497      eeprom_init(&eeprom_interface_93C46);
498498      if (file)
499499      {
500         EEPROM_load(file);
500         eeprom_load(file);
501501      }
502502      else
503503      {
504504         int length;
505505         UINT8 *dat;
506506
507         dat = EEPROM_get_data_pointer(&length);
507         dat = eeprom_get_data_pointer(&length);
508508         dat[0]=0x70;
509509         dat[1]=0x08;
510510      }
r2762r2763
513513
514514static READ16_HANDLER( gundamex_eeprom_r )
515515{
516   return ((EEPROM_read_bit() & 1)) << 3;
516   return ((eeprom_read_bit() & 1)) << 3;
517517}
518518
519519static WRITE16_HANDLER( gundamex_eeprom_w )
520520{
521      EEPROM_set_clock_line((data & 0x2) ? ASSERT_LINE : CLEAR_LINE);
522      EEPROM_write_bit(data & 0x1);
523      EEPROM_set_cs_line((data & 0x4) ? CLEAR_LINE : ASSERT_LINE);
521      eeprom_set_clock_line((data & 0x2) ? ASSERT_LINE : CLEAR_LINE);
522      eeprom_write_bit(data & 0x1);
523      eeprom_set_cs_line((data & 0x4) ? CLEAR_LINE : ASSERT_LINE);
524524}
525525
526526static ADDRESS_MAP_START( gundamex_readmem, ADDRESS_SPACE_PROGRAM, 16 )
src/mame/drivers/megadriv.c
r2762r2763
16961696   PORT_DIPSETTING(    0x05, DEF_STR( 1C_5C ) )
16971697   PORT_DIPSETTING(    0x06, DEF_STR( 1C_6C ) )
16981698    PORT_DIPSETTING(    0x07, DEF_STR( 1C_7C ) )
1699   PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_SPECIAL )         /* to avoid it being changed and corrupting Coinage settings */
1699   //PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_SPECIAL )         /* to avoid it being changed and corrupting Coinage settings */
17001700   PORT_DIPNAME( 0x30, 0x00, DEF_STR( Difficulty ) )       /* code at 0x1b2680 */
17011701   PORT_DIPSETTING(    0x10, DEF_STR( Easy ) )             /* "PRACTICE" */
17021702   PORT_DIPSETTING(    0x00, DEF_STR( Normal ) )           /* "NORMAL" */
src/mame/drivers/undrfire.c
r2762r2763
256256   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
257257};
258258
259static const struct EEPROM_interface undrfire_eeprom_interface =
259static const eeprom_interface undrfire_eeprom_interface =
260260{
261261   6,            /* address bits */
262262   16,            /* data bits */
r2762r2763
270270static NVRAM_HANDLER( undrfire )
271271{
272272   if (read_or_write)
273      EEPROM_save(file);
273      eeprom_save(file);
274274   else {
275      EEPROM_init(&undrfire_eeprom_interface);
275      eeprom_init(&undrfire_eeprom_interface);
276276      if (file)
277         EEPROM_load(file);
277         eeprom_load(file);
278278      else
279         EEPROM_set_data(default_eeprom,128);  /* Default the gun setup values */
279         eeprom_set_data(default_eeprom,128);  /* Default the gun setup values */
280280   }
281281}
282282
r2762r2763
292292      case 0x00:
293293      {
294294         return (input_port_read_indexed(machine,0) << 16) | input_port_read_indexed(machine,1) |
295              (EEPROM_read_bit() << 7) | frame_counter;
295              (eeprom_read_bit() << 7) | frame_counter;
296296      }
297297
298298      case 0x01:
r2762r2763
317317
318318         if (ACCESSING_BITS_0_7)
319319         {
320            EEPROM_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
321            EEPROM_write_bit(data & 0x40);
322            EEPROM_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
320            eeprom_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
321            eeprom_write_bit(data & 0x40);
322            eeprom_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
323323            return;
324324         }
325325
src/mame/drivers/deco32.c
r2762r2763
351351   switch (offset) {
352352   case 0: return 0xffff0000 | input_port_read_indexed(machine, 0);
353353   case 1: return 0xffff0000 | input_port_read_indexed(machine, 1); //check top bits??
354   case 2: return 0xfffffffe | EEPROM_read_bit();
354   case 2: return 0xfffffffe | eeprom_read_bit();
355355   }
356356
357357   return 0xffffffff;
r2762r2763
360360static WRITE32_HANDLER( fghthist_eeprom_w )
361361{
362362   if (ACCESSING_BITS_0_7) {
363      EEPROM_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
364      EEPROM_write_bit(data & 0x10);
365      EEPROM_set_cs_line((data & 0x40) ? CLEAR_LINE : ASSERT_LINE);
363      eeprom_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
364      eeprom_write_bit(data & 0x10);
365      eeprom_set_cs_line((data & 0x40) ? CLEAR_LINE : ASSERT_LINE);
366366   }
367367   else if (!ACCESSING_BITS_8_15)
368368   {
r2762r2763
429429
430430static READ32_HANDLER( dragngun_eeprom_r )
431431{
432   return 0xfffffffe | EEPROM_read_bit();
432   return 0xfffffffe | eeprom_read_bit();
433433}
434434
435435static WRITE32_HANDLER( dragngun_eeprom_w )
436436{
437437   if (ACCESSING_BITS_0_7) {
438      EEPROM_set_clock_line((data & 0x2) ? ASSERT_LINE : CLEAR_LINE);
439      EEPROM_write_bit(data & 0x1);
440      EEPROM_set_cs_line((data & 0x4) ? CLEAR_LINE : ASSERT_LINE);
438      eeprom_set_clock_line((data & 0x2) ? ASSERT_LINE : CLEAR_LINE);
439      eeprom_write_bit(data & 0x1);
440      eeprom_set_cs_line((data & 0x4) ? CLEAR_LINE : ASSERT_LINE);
441441      return;
442442   }
443443   logerror("%08x:Write control 1 %08x %08x\n",activecpu_get_pc(),offset,data);
r2762r2763
489489   static int pendingCommand=0; /* 1 = read, 2 = write */
490490   static int readBitCount=0;
491491   static int byteAddr=0;
492   UINT8 *eeprom=EEPROM_get_data_pointer(0);
492   UINT8 *eeprom=eeprom_get_data_pointer(0);
493493
494494   /* Eprom in low byte */
495495   if (mem_mask==0x000000ff) { /* Byte write to low byte only (different from word writing including low byte) */
r2762r2763
625625   switch (offset<<1) {
626626   case 0x280: return input_port_read_indexed(machine, 0) << 16| 0xffff; /* IN0 */
627627   case 0x4c4: return input_port_read_indexed(machine, 1) << 16| 0xffff; /* IN1 */
628   case 0x35a: return (EEPROM_read_bit()<< 16) | 0xffff; // Debug switch in low word??
628   case 0x35a: return (eeprom_read_bit()<< 16) | 0xffff; // Debug switch in low word??
629629   }
630630
631631   //logerror("%08x: Read unmapped prot %08x (%08x)\n",activecpu_get_pc(),offset<<1,mem_mask);
r2762r2763
637637{
638638   if (ACCESSING_BITS_0_7)
639639   {
640      EEPROM_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
641      EEPROM_write_bit(data & 0x10);
642      EEPROM_set_cs_line((data & 0x40) ? CLEAR_LINE : ASSERT_LINE);
640      eeprom_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
641      eeprom_write_bit(data & 0x10);
642      eeprom_set_cs_line((data & 0x40) ? CLEAR_LINE : ASSERT_LINE);
643643
644644      deco32_pri_w(machine,0,data&0x3,0xffffffff); /* Bit 0 - layer priority toggle, Bit 1 - BG2/3 Joint mode (8bpp) */
645645   }
r2762r2763
18361836   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
18371837};
18381838
1839static const struct EEPROM_interface eeprom_interface_tattass =
1839static const eeprom_interface eeprom_interface_tattass =
18401840{
18411841   10,            // address bits 10  ==> } 1024 byte eprom
18421842   8,            // data bits    8
r2762r2763
18451845static NVRAM_HANDLER(tattass)
18461846{
18471847   if (read_or_write)
1848      EEPROM_save(file);
1848      eeprom_save(file);
18491849   else
18501850   {
18511851      int len;
1852      EEPROM_init(&eeprom_interface_tattass);
1853      if (file) EEPROM_load(file);
1854      else memcpy(EEPROM_get_data_pointer(&len),tattass_default_eprom,0x160);
1852      eeprom_init(&eeprom_interface_tattass);
1853      if (file) eeprom_load(file);
1854      else memcpy(eeprom_get_data_pointer(&len),tattass_default_eprom,0x160);
18551855   }
18561856}
18571857
src/mame/drivers/zaxxon.c
r2762r2763
342342 *************************************/
343343
344344static UINT8 int_enabled;
345static UINT8 coin_status[3];
346static UINT8 coin_enable[3];
345347
346348static UINT8 razmataz_dial_pos[2];
347349static UINT16 razmataz_counter;
r2762r2763
388390{
389391   /* register for save states */
390392   state_save_register_global(int_enabled);
393   state_save_register_global_array(coin_status);
394   state_save_register_global_array(coin_enable);
391395}
392396
393397
r2762r2763
453457}
454458
455459
456static WRITE8_HANDLER( zaxxon_coin_lockout_w )
460// There is no external coin lockout circuitry; instead, the pcb simply latches
461// the coin input, which then needs to be explicitly cleared by the game.
462static WRITE8_HANDLER( zaxxon_coin_enable_w )
457463{
458   if (offset < 2)
459      coin_lockout_w(offset, ~data & 0x01);
460   else
461      service_coin_lockout_w(offset, ~data & 0x01);
464   coin_enable[offset] = data & 1;
465   if (!coin_enable[offset])
466      coin_status[offset] = 0;
462467}
463468
464469
470static INPUT_CHANGED( zaxxon_coin_inserted )
471{
472   if (newval)
473      coin_status[(int)param] = coin_enable[(int)param];
474}
465475
466476
477static CUSTOM_INPUT( zaxxon_coin_r )
478{
479   return coin_status[(int)param];
480}
481
482
483
467484/*************************************
468485 *
469486 *  Main CPU memory handlers
r2762r2763
481498   AM_RANGE(0xc002, 0xc002) AM_MIRROR(0x18fc) AM_READ_PORT("DSW02")
482499   AM_RANGE(0xc003, 0xc003) AM_MIRROR(0x18fc) AM_READ_PORT("DSW03")
483500   AM_RANGE(0xc100, 0xc100) AM_MIRROR(0x18ff) AM_READ_PORT("SW100")
484   AM_RANGE(0xc000, 0xc002) AM_MIRROR(0x18f8) AM_WRITE(zaxxon_coin_lockout_w)
501   AM_RANGE(0xc000, 0xc002) AM_MIRROR(0x18f8) AM_WRITE(zaxxon_coin_enable_w)
485502   AM_RANGE(0xc003, 0xc004) AM_MIRROR(0x18f8) AM_WRITE(zaxxon_coin_counter_w)
486503   AM_RANGE(0xc006, 0xc006) AM_MIRROR(0x18f8) AM_WRITE(zaxxon_flipscreen_w)
487504   AM_RANGE(0xe03c, 0xe03f) AM_MIRROR(0x1f00) AM_DEVREADWRITE(PPI8255, "ppi8255", ppi8255_r, ppi8255_w)
r2762r2763
504521   AM_RANGE(0xc002, 0xc002) AM_MIRROR(0x1fc4) AM_READ_PORT("DSW02")
505522   AM_RANGE(0xc003, 0xc003) AM_MIRROR(0x1fc4) AM_READ_PORT("DSW03")
506523   AM_RANGE(0xc008, 0xc008) AM_MIRROR(0x1fc7) AM_READ_PORT("SW100")
507   AM_RANGE(0xc018, 0xc01a) AM_MIRROR(0x1fc0) AM_WRITE(zaxxon_coin_lockout_w)
524   AM_RANGE(0xc018, 0xc01a) AM_MIRROR(0x1fc0) AM_WRITE(zaxxon_coin_enable_w)
508525   AM_RANGE(0xc01b, 0xc01c) AM_MIRROR(0x1fc0) AM_WRITE(zaxxon_coin_counter_w)
509526   AM_RANGE(0xc01d, 0xc01d) AM_MIRROR(0x1fc0) AM_WRITE(zaxxon_bg_enable_w)
510527   AM_RANGE(0xc01e, 0xc01e) AM_MIRROR(0x1fc0) AM_WRITE(zaxxon_flipscreen_w)
r2762r2763
558575   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_START1 )
559576   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_START2 )
560577   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_UNUSED )
561   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_IMPULSE(1)
562   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_COIN2 ) PORT_IMPULSE(1)
563   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_SERVICE1 ) PORT_IMPULSE(1)
578   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(zaxxon_coin_r, (void *)0)
579   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(zaxxon_coin_r, (void *)1)
580   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(zaxxon_coin_r, (void *)2)
564581
582   PORT_START_TAG("COIN")
583   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 )    PORT_CHANGED(zaxxon_coin_inserted, (void *)0)
584   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 )    PORT_CHANGED(zaxxon_coin_inserted, (void *)1)
585   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_SERVICE1 ) PORT_CHANGED(zaxxon_coin_inserted, (void *)2)
586
565587   PORT_START_TAG("SERVICESW")
566588   PORT_SERVICE_NO_TOGGLE( 0x01, IP_ACTIVE_HIGH ) PORT_CHANGED(service_switch, 0)
567589
r2762r2763
742764
743765   PORT_START_TAG("SW100")
744766   PORT_BIT( 0x1f, IP_ACTIVE_HIGH, IPT_UNUSED )
745   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_IMPULSE(1)
746   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_COIN2 ) PORT_IMPULSE(1)
747   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_SERVICE1 ) PORT_IMPULSE(1)
767   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(zaxxon_coin_r, (void *)0)
768   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(zaxxon_coin_r, (void *)1)
769   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(zaxxon_coin_r, (void *)2)
748770
771   PORT_START_TAG("COIN")
772   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 )    PORT_CHANGED(zaxxon_coin_inserted, (void *)0)
773   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 )    PORT_CHANGED(zaxxon_coin_inserted, (void *)1)
774   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_SERVICE1 ) PORT_CHANGED(zaxxon_coin_inserted, (void *)2)
775
749776   PORT_START_TAG("SERVICESW")
750777   PORT_SERVICE_NO_TOGGLE( 0x01, IP_ACTIVE_HIGH )
751778
src/mame/drivers/aleck64.c
r2762r2763
408408INPUT_PORTS_END
409409
410410/* ?? */
411static const struct mips3_config config =
411static const mips3_config config =
412412{
413413   16384,            /* code cache size */
414414   8192,            /* data cache size */
src/mame/drivers/astrof.c
r2762r2763
131131{
132132   UINT32 ret;
133133
134   /* on an upright cabinets, a single set of controls
134   /* on an upright cabinet, a single set of controls
135135       is connected to both sets of pins on the edge
136136       connector */
137137   if (input_port_read(field->port->machine, "CAB"))
r2762r2763
143143}
144144
145145
146static CUSTOM_INPUT( tomahawk_controls_r )
147{
148   UINT32 ret;
146149
150   /* on a cocktail cabinet, two sets of controls are
151       multiplexed on a single set of inputs
152         (not verified on pcb) */
153
154   if (flipscreen)
155      ret = input_port_read(field->port->machine, "P2");
156   else
157      ret = input_port_read(field->port->machine, "P1");
158
159   return ret;
160}
161
162
163
147164/*************************************
148165 *
149166 *  Video system
r2762r2763
223240
224241static WRITE8_HANDLER( video_control_1_w )
225242{
226   flipscreen = ((data >> 0) & 0x01) & input_port_read(machine, "FLIP");
243   flipscreen = ((data >> 0) & 0x01) & input_port_read(machine, "CAB");
227244
228245   /* this ties to the CLR pin of the shift registers */
229246   screen_off = (data & 0x02) ? TRUE : FALSE;
r2762r2763
523540   AM_RANGE(0x8005, 0x8005) AM_MIRROR(0x1ff8) AM_READWRITE(SMH_NOP, tomahawk_video_control_2_w)
524541   AM_RANGE(0x8006, 0x8006) AM_MIRROR(0x1ff8) AM_READWRITE(SMH_NOP, tomahawk_audio_w)
525542   AM_RANGE(0x8007, 0x8007) AM_MIRROR(0x1ff8) AM_READWRITE(SMH_NOP, SMH_RAM) AM_BASE(&tomahawk_protection)
526   AM_RANGE(0xa000, 0xa000) AM_MIRROR(0x1ff8) AM_READ_PORT("IN") AM_WRITE(SMH_NOP)
527   AM_RANGE(0xa001, 0xa001) AM_MIRROR(0x1ff8) AM_READ_PORT("DSW") AM_WRITE(SMH_NOP)
543   AM_RANGE(0xa000, 0xa000) AM_MIRROR(0x1ff8) AM_READ_PORT("IN") AM_WRITENOP
544   AM_RANGE(0xa001, 0xa001) AM_MIRROR(0x1ff8) AM_READ_PORT("DSW") AM_WRITENOP
528545   AM_RANGE(0xa002, 0xa002) AM_MIRROR(0x1ff8) AM_READWRITE(irq_clear_r, SMH_NOP)
529546   AM_RANGE(0xa003, 0xa003) AM_MIRROR(0x1ff8) AM_READWRITE(tomahawk_protection_r, SMH_NOP)
530547   AM_RANGE(0xa004, 0xa007) AM_MIRROR(0x1ff8) AM_NOP
r2762r2763
546563   PORT_BIT( 0x1c, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(astrof_p1_controls_r, 0)
547564   PORT_BIT( 0xe0, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(astrof_p2_controls_r, 0)
548565
566   PORT_START_TAG("P1")
567   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_2WAY
568   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_2WAY
569   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON1 )
570   PORT_BIT( 0xf8, IP_ACTIVE_HIGH, IPT_UNUSED )
571
572   PORT_START_TAG("P2")
573   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_2WAY PORT_COCKTAIL
574   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_2WAY PORT_COCKTAIL
575   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
576   PORT_BIT( 0xf8, IP_ACTIVE_HIGH, IPT_UNUSED )
577
549578   PORT_START_TAG("DSW")
550579   PORT_DIPNAME( 0x03, 0x00, DEF_STR( Lives ) ) PORT_DIPLOCATION("SW:1,2")
551580   PORT_DIPSETTING(    0x00, "3" )
r2762r2763
567596   PORT_DIPSETTING(    0x40, DEF_STR( Hard ) )
568597   PORT_BIT ( 0x80, IP_ACTIVE_LOW, IPT_VBLANK )
569598
570   PORT_START_TAG("P1")
571   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_2WAY
572   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_2WAY
573   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON1 )
574   PORT_BIT( 0xf8, IP_ACTIVE_HIGH, IPT_UNUSED )
599   PORT_START_TAG("CAB")
600   PORT_DIPNAME( 0x01, 0x00, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("SW:8")
601   PORT_DIPSETTING(    0x00, DEF_STR( Upright ) )
602   PORT_DIPSETTING(    0x01, DEF_STR( Cocktail ) )
603   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
575604
576   PORT_START_TAG("P2")
577   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_2WAY PORT_COCKTAIL
578   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_2WAY PORT_COCKTAIL
579   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
580   PORT_BIT( 0xf8, IP_ACTIVE_HIGH, IPT_UNUSED )
581
582605   PORT_START_TAG("COIN")
583606   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_CHANGED(coin_inserted, 0)
584607   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SERVICE1 ) PORT_CHANGED(service_coin_inserted, 0)
585608   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
586
587   PORT_START_TAG("FLIP")
588   PORT_DIPNAME( 0x01, 0x00, "Flip Screen for Player 2" )
589   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
590   PORT_DIPSETTING(    0x01, DEF_STR( On ) )
591   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
592
593   PORT_START_TAG("CAB")
594   PORT_CONFNAME( 0x01, 0x00, DEF_STR( Cabinet ) )
595   PORT_CONFSETTING(    0x00, DEF_STR( Upright ) )
596   PORT_CONFSETTING(    0x01, DEF_STR( Cocktail ) )
597   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
598609INPUT_PORTS_END
599610
600611
r2762r2763
605616   PORT_BIT( 0x1c, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(astrof_p1_controls_r, 0)
606617   PORT_BIT( 0xe0, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(astrof_p2_controls_r, 0)
607618
619   PORT_START_TAG("P1")
620   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_2WAY
621   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_2WAY
622   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON1 )
623   PORT_BIT( 0xf8, IP_ACTIVE_HIGH, IPT_UNUSED )
624
625   PORT_START_TAG("P2")
626   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_2WAY PORT_COCKTAIL
627   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_2WAY PORT_COCKTAIL
628   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_COCKTAIL
629   PORT_BIT( 0xf8, IP_ACTIVE_HIGH, IPT_UNUSED )
630
608631   PORT_START_TAG("DSW")
609632   PORT_DIPNAME( 0x03, 0x00, DEF_STR( Lives ) ) PORT_DIPLOCATION("SW:1,2")
610633   PORT_DIPSETTING(    0x00, "3" )
r2762r2763
626649   PORT_DIPSETTING(    0x40, DEF_STR( Hard ) )
627650   PORT_BIT ( 0x80, IP_ACTIVE_LOW, IPT_VBLANK )
628651
629   PORT_START_TAG("P1")
630   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_2WAY
631   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_2WAY
632   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON1 )
633   PORT_BIT( 0xf8, IP_ACTIVE_HIGH, IPT_UNUSED )
652   PORT_START_TAG("CAB")
653   PORT_DIPNAME( 0x01, 0x00, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("SW:8")
654   PORT_DIPSETTING(    0x00, DEF_STR( Upright ) )
655   PORT_DIPSETTING(    0x01, DEF_STR( Cocktail ) )
656   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
634657
635   PORT_START_TAG("P2")
636   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_2WAY PORT_COCKTAIL
637   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_2WAY PORT_COCKTAIL
638   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_COCKTAIL
639   PORT_BIT( 0xf8, IP_ACTIVE_HIGH, IPT_UNUSED )
640
641658   PORT_START_TAG("COIN")
642659   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_CHANGED(coin_inserted, 0)
643660   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SERVICE1 ) PORT_CHANGED(service_coin_inserted, 0)
644661   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
645
646   PORT_START_TAG("FLIP")
647   PORT_DIPNAME( 0x01, 0x00, "Flip Screen for Player 2" ) PORT_DIPLOCATION("SW:8")
648   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
649   PORT_DIPSETTING(    0x01, DEF_STR( On ) )
650   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
651
652   PORT_START_TAG("CAB")
653   PORT_CONFNAME( 0x01, 0x00, DEF_STR( Cabinet ) )
654   PORT_CONFSETTING(    0x00, DEF_STR( Upright ) )
655   PORT_CONFSETTING(    0x01, DEF_STR( Cocktail ) )
656   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
657662INPUT_PORTS_END
658663
659664
r2762r2763
664669   PORT_BIT( 0x1c, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(astrof_p1_controls_r, 0)
665670   PORT_BIT( 0xe0, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(astrof_p2_controls_r, 0)
666671
672   PORT_START_TAG("P1")
673   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_2WAY
674   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_2WAY
675   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON1 )
676   PORT_BIT( 0xf8, IP_ACTIVE_HIGH, IPT_UNUSED )
677
678   PORT_START_TAG("P2")
679   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_2WAY PORT_COCKTAIL
680   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_2WAY PORT_COCKTAIL
681   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
682   PORT_BIT( 0xf8, IP_ACTIVE_HIGH, IPT_UNUSED )
683
667684   PORT_START_TAG("DSW")
668   PORT_DIPNAME( 0x01, 0x00, DEF_STR( Unknown ) )   /* most likely not used */
685   PORT_DIPNAME( 0x01, 0x00, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW:1")   /* most likely not used */
669686   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
670687   PORT_DIPSETTING(    0x01, DEF_STR( On ) )
671   PORT_DIPNAME( 0x02, 0x00, DEF_STR( Lives ) )
688   PORT_DIPNAME( 0x02, 0x00, DEF_STR( Lives ) ) PORT_DIPLOCATION("SW:2")
672689   PORT_DIPSETTING(    0x00, "3" )
673690   PORT_DIPSETTING(    0x02, "5" )
674   PORT_DIPNAME( 0x0c, 0x00, DEF_STR( Coinage ) )
691   PORT_DIPNAME( 0x0c, 0x00, DEF_STR( Coinage ) ) PORT_DIPLOCATION("SW:3,4")
675692   PORT_DIPSETTING(    0x08, DEF_STR( 2C_1C ) )
676693  /*PORT_DIPSETTING(    0x0c, DEF_STR( 2C_1C ) )*/
677694   PORT_DIPSETTING(    0x00, DEF_STR( 1C_1C ) )
678695   PORT_DIPSETTING(    0x04, DEF_STR( 1C_2C ) )
679   PORT_DIPNAME( 0x30, 0x00, DEF_STR( Bonus_Life ) )
696   PORT_DIPNAME( 0x30, 0x00, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("SW:5,6")
680697   PORT_DIPSETTING(    0x00, "1500" )
681698   PORT_DIPSETTING(    0x10, "2000" )
682699   PORT_DIPSETTING(    0x20, "2500" )
683700   PORT_DIPSETTING(    0x30, "3000" )
684   PORT_DIPNAME( 0x40, 0x00, DEF_STR( Unknown ) )   /* most likely not used */
701   PORT_DIPNAME( 0x40, 0x00, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW:7")   /* most likely not used */
685702   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
686703   PORT_DIPSETTING(    0x40, DEF_STR( On ) )
687704   PORT_BIT ( 0x80, IP_ACTIVE_LOW, IPT_VBLANK )
688705
689   PORT_START_TAG("P1")
690   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_2WAY
691   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_2WAY
692   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON1 )
693   PORT_BIT( 0xf8, IP_ACTIVE_HIGH, IPT_UNUSED )
706   PORT_START_TAG("CAB")
707   PORT_DIPNAME( 0x01, 0x00, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("SW:8")
708   PORT_DIPSETTING(    0x00, DEF_STR( Upright ) )
709   PORT_DIPSETTING(    0x01, DEF_STR( Cocktail ) )
710   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
694711
695   PORT_START_TAG("P2")
696   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_2WAY PORT_COCKTAIL
697   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_2WAY PORT_COCKTAIL
698   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
699   PORT_BIT( 0xf8, IP_ACTIVE_HIGH, IPT_UNUSED )
700
701712   PORT_START_TAG("COIN")
702713   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_CHANGED(coin_inserted, 0)
703714   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SERVICE1 ) PORT_CHANGED(service_coin_inserted, 0)
704715   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
705
706   PORT_START_TAG("FLIP")
707   PORT_DIPNAME( 0x01, 0x00, "Flip Screen for Player 2" )
708   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
709   PORT_DIPSETTING(    0x01, DEF_STR( On ) )
710   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
711
712   PORT_START_TAG("CAB")
713   PORT_CONFNAME( 0x01, 0x00, DEF_STR( Cabinet ) )
714   PORT_CONFSETTING(    0x00, DEF_STR( Upright ) )
715   PORT_CONFSETTING(    0x01, DEF_STR( Cocktail ) )
716   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
717716INPUT_PORTS_END
718717
719718
r2762r2763
724723   PORT_BIT( 0x1c, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(astrof_p1_controls_r, 0)
725724   PORT_BIT( 0xe0, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(astrof_p2_controls_r, 0)
726725
726   PORT_START_TAG("P1")
727   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_2WAY
728   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_2WAY
729   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON1 )
730   PORT_BIT( 0xf8, IP_ACTIVE_HIGH, IPT_UNUSED )
731
732   PORT_START_TAG("P2")
733   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_2WAY PORT_COCKTAIL
734   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_2WAY PORT_COCKTAIL
735   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
736   PORT_BIT( 0xf8, IP_ACTIVE_HIGH, IPT_UNUSED )
737
727738   PORT_START_TAG("DSW")
728   PORT_DIPNAME( 0x01, 0x00, DEF_STR( Unknown ) )   /* used */
739   PORT_DIPNAME( 0x01, 0x00, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW:1")   /* used */
729740   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
730741   PORT_DIPSETTING(    0x01, DEF_STR( On ) )
731   PORT_DIPNAME( 0x02, 0x00, DEF_STR( Lives ) )
742   PORT_DIPNAME( 0x02, 0x00, DEF_STR( Lives ) ) PORT_DIPLOCATION("SW:2")
732743   PORT_DIPSETTING(    0x00, "3" )
733744   PORT_DIPSETTING(    0x02, "5" )
734   PORT_DIPNAME( 0x0c, 0x00, DEF_STR( Coinage ) )
745   PORT_DIPNAME( 0x0c, 0x00, DEF_STR( Coinage ) ) PORT_DIPLOCATION("SW:3,4")
735746   PORT_DIPSETTING(    0x08, DEF_STR( 2C_1C ) )
736747  /*PORT_DIPSETTING(    0x0c, DEF_STR( 2C_1C ) )*/
737748   PORT_DIPSETTING(    0x00, DEF_STR( 1C_1C ) )
738749   PORT_DIPSETTING(    0x04, DEF_STR( 1C_2C ) )
739   PORT_DIPNAME( 0x30, 0x00, DEF_STR( Bonus_Life ) )
750   PORT_DIPNAME( 0x30, 0x00, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("SW:5,6")
740751   PORT_DIPSETTING(    0x00, "2000" )
741752   PORT_DIPSETTING(    0x10, "3000" )
742753   PORT_DIPSETTING(    0x20, "4000" )
743754   PORT_DIPSETTING(    0x30, "5000" )
744   PORT_DIPNAME( 0x40, 0x00, DEF_STR( Unknown ) )   /* used */
755   PORT_DIPNAME( 0x40, 0x00, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW:7")   /* used */
745756   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
746757   PORT_DIPSETTING(    0x40, DEF_STR( On ) )
747758   PORT_BIT ( 0x80, IP_ACTIVE_LOW, IPT_VBLANK )
748759
749   PORT_START_TAG("P1")
750   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_2WAY
751   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_2WAY
752   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON1 )
753   PORT_BIT( 0xf8, IP_ACTIVE_HIGH, IPT_UNUSED )
760   PORT_START_TAG("CAB")
761   PORT_DIPNAME( 0x01, 0x00, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("SW:8")
762   PORT_DIPSETTING(    0x00, DEF_STR( Upright ) )
763   PORT_DIPSETTING(    0x01, DEF_STR( Cocktail ) )
764   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
754765
755   PORT_START_TAG("P2")
756   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_2WAY PORT_COCKTAIL
757   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_2WAY PORT_COCKTAIL
758   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
759   PORT_BIT( 0xf8, IP_ACTIVE_HIGH, IPT_UNUSED )
760
761766   PORT_START_TAG("COIN")
762767   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_CHANGED(coin_inserted, 0)
763768   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SERVICE1 ) PORT_CHANGED(service_coin_inserted, 0)
764769   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
765
766   PORT_START_TAG("FLIP")
767   PORT_DIPNAME( 0x01, 0x00, "Flip Screen for Player 2" )
768   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
769   PORT_DIPSETTING(    0x01, DEF_STR( On ) )
770   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
771
772   PORT_START_TAG("CAB")
773   PORT_CONFNAME( 0x01, 0x00, DEF_STR( Cabinet ) )
774   PORT_CONFSETTING(    0x00, DEF_STR( Upright ) )
775   PORT_CONFSETTING(    0x01, DEF_STR( Cocktail ) )
776   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
777770INPUT_PORTS_END
778771
779772
780773static INPUT_PORTS_START( tomahawk )
781774   PORT_START_TAG("IN")
775   PORT_BIT( 0x1f, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(tomahawk_controls_r, 0)
776   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START1 )
777   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START2 )
778     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
779
780   PORT_START_TAG("P1")
782781   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY
783782   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_4WAY
784783   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY
785784   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_4WAY
786785   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
787   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START1 )
788   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START2 )
789     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
786   PORT_BIT( 0xe0, IP_ACTIVE_HIGH, IPT_UNUSED )
790787
788   PORT_START_TAG("P2")
789   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY PORT_COCKTAIL
790   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_4WAY PORT_COCKTAIL
791   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY PORT_COCKTAIL
792   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_4WAY PORT_COCKTAIL
793   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
794   PORT_BIT( 0xe0, IP_ACTIVE_HIGH, IPT_UNUSED )
795
791796     PORT_START_TAG("DSW")
792797   PORT_DIPNAME( 0x03, 0x00, DEF_STR( Lives ) ) PORT_DIPLOCATION("SW:1,2")
793798   PORT_DIPSETTING(    0x00, "3" )
r2762r2763
809814   PORT_DIPSETTING(    0x40, DEF_STR( Hard ) )
810815   PORT_BIT ( 0x80, IP_ACTIVE_LOW, IPT_VBLANK )
811816
817   PORT_START_TAG("CAB")
818   PORT_DIPNAME( 0x01, 0x00, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("SW:8")
819   PORT_DIPSETTING(    0x00, DEF_STR( Upright ) )
820   PORT_DIPSETTING(    0x01, DEF_STR( Cocktail ) )
821   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
822
812823   PORT_START_TAG("COIN")
813824   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_CHANGED(coin_inserted, 0)
814825   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SERVICE1 ) PORT_CHANGED(service_coin_inserted, 0)
815826   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
816
817   PORT_START_TAG("FLIP")
818   PORT_CONFNAME( 0x01, 0x00, DEF_STR( Cabinet ) )
819   PORT_CONFSETTING(    0x00, DEF_STR( Upright ) )
820   PORT_CONFSETTING(    0x01, DEF_STR( Cocktail ) )
821   PORT_BIT( 0xfe, IP_ACTIVE_HIGH, IPT_UNUSED )
822827INPUT_PORTS_END
823828
824829
r2762r2763
12181223 *
12191224 *************************************/
12201225
1221GAME( 1979, astrof,   0,        astrof,   astrof,   0,       ROT90, "Data East",   "Astro Fighter (set 1)", GAME_SUPPORTS_SAVE )
1222GAME( 1979, astrof2,  astrof,   astrof,   astrof,   0,       ROT90, "Data East",   "Astro Fighter (set 2)", GAME_SUPPORTS_SAVE )
1223GAME( 1979, astrof3,  astrof,   astrof,   astrof,   0,       ROT90, "Data East",   "Astro Fighter (set 3)", GAME_SUPPORTS_SAVE )
1224GAME( 1979, abattle,  astrof,   abattle,  abattle,  abattle, ROT90, "Sidam",      "Astro Battle (set 1)", GAME_SUPPORTS_SAVE )
1225GAME( 1979, abattle2, astrof,   abattle,  abattle,  abattle, ROT90, "Sidam",      "Astro Battle (set 2)", GAME_SUPPORTS_SAVE )
1226GAME( 1979, astrof,   0,        astrof,   astrof,   0,       ROT90, "Data East",   "Astro Fighter (set 1)", GAME_SUPPORTS_SAVE )
1227GAME( 1979, astrof2,  astrof,   astrof,   astrof,   0,       ROT90, "Data East",   "Astro Fighter (set 2)", GAME_SUPPORTS_SAVE )
1228GAME( 1979, astrof3,  astrof,   astrof,   astrof,   0,       ROT90, "Data East",   "Astro Fighter (set 3)", GAME_SUPPORTS_SAVE )
1229GAME( 1979, abattle,  astrof,   abattle,  abattle,  abattle, ROT90, "Sidam",       "Astro Battle (set 1)", GAME_SUPPORTS_SAVE )
1230GAME( 1979, abattle2, astrof,   abattle,  abattle,  abattle, ROT90, "Sidam",       "Astro Battle (set 2)", GAME_SUPPORTS_SAVE )
12261231GAME( 1979, afire,    astrof,   abattle,  abattle,  afire,   ROT90, "Rene Pierre", "Astro Fire", GAME_SUPPORTS_SAVE )
12271232GAME( 1979, acombat,  astrof,   abattle,  abattle,  afire,   ROT90, "bootleg",     "Astro Combat (newer, CB)", GAME_SUPPORTS_SAVE )
12281233GAME( 1979, acombato, astrof,   abattle,  abattle,  afire,   ROT90, "bootleg",     "Astro Combat (older, PZ)", GAME_SUPPORTS_SAVE )
src/mame/drivers/vegas.c
r2762r2763
22172217 *
22182218 *************************************/
22192219
2220static const struct mips3_config config =
2220static const mips3_config config =
22212221{
22222222   16384,         /* code cache size */
22232223   16384,         /* data cache size */
src/mame/drivers/xorworld.c
r2762r2763
5151{
5252   if (read_or_write)
5353   {
54      EEPROM_save(file);
54      eeprom_save(file);
5555   }
5656   else
5757   {
58      EEPROM_init(&eeprom_interface_93C46);
58      eeprom_init(&eeprom_interface_93C46);
5959
6060      if (file)
6161      {
62         EEPROM_load(file);
62         eeprom_load(file);
6363      }
6464   }
6565}
r2762r2763
7777/* the EEPROM is read thru bit 4 */
7878static READ16_HANDLER( xorworld_input_r )
7979{
80   return input_port_read_indexed(machine, 0) | ((EEPROM_read_bit() & 0x01) << 4);
80   return input_port_read_indexed(machine, 0) | ((eeprom_read_bit() & 0x01) << 4);
8181}
8282
8383static WRITE16_HANDLER( eeprom_chip_select_w )
8484{
8585   /* bit 0 is CS (active low) */
86   EEPROM_set_cs_line((data & 0x01) ? CLEAR_LINE : ASSERT_LINE);
86   eeprom_set_cs_line((data & 0x01) ? CLEAR_LINE : ASSERT_LINE);
8787}
8888
8989static WRITE16_HANDLER( eeprom_serial_clock_w )
9090{
9191   /* bit 0 is SK (active high) */
92   EEPROM_set_clock_line((data & 0x01) ? ASSERT_LINE : CLEAR_LINE);
92   eeprom_set_clock_line((data & 0x01) ? ASSERT_LINE : CLEAR_LINE);
9393}
9494
9595static WRITE16_HANDLER( eeprom_data_w )
9696{
9797   /* bit 0 is EEPROM data (DIN) */
98   EEPROM_write_bit(data & 0x01);
98   eeprom_write_bit(data & 0x01);
9999}
100100
101101
src/mame/drivers/gticlub.c
r2762r2763
138138/******************************************************************/
139139
140140/* 93C56 EEPROM */
141static const struct EEPROM_interface eeprom_interface =
141static const eeprom_interface eeprom_intf =
142142{
143143   8,            /* address bits */
144144   16,            /* data bits */
r2762r2763
157157   {
158158      if (file)
159159      {
160         EEPROM_save(file);
160         eeprom_save(file);
161161      }
162162   }
163163   else
164164   {
165      EEPROM_init(&eeprom_interface);
165      eeprom_init(&eeprom_intf);
166166      if (file)
167167      {
168         EEPROM_load(file);
168         eeprom_load(file);
169169      }
170170      else
171171      {
r2762r2763
180180            eepdata[0x5] = 0x72;
181181         }
182182
183         EEPROM_set_data(eepdata, 0x200);
183         eeprom_set_data(eepdata, 0x200);
184184      }
185185   }
186186}
r2762r2763
311311         // a = ADC readout
312312         // e = EEPROM data out
313313
314         UINT32 eeprom_bit = (EEPROM_read_bit() << 1);
314         UINT32 eeprom_bit = (eeprom_read_bit() << 1);
315315         UINT32 adc_bit = (adc1038_do_r() << 2);
316316         r |= (eeprom_bit | adc_bit) << 24;
317317      }
r2762r2763
338338      }
339339      if( ACCESSING_BITS_0_7 )
340340      {
341         EEPROM_write_bit((data & 0x01) ? 1 : 0);
342         EEPROM_set_clock_line((data & 0x02) ? ASSERT_LINE : CLEAR_LINE);
343         EEPROM_set_cs_line((data & 0x04) ? CLEAR_LINE : ASSERT_LINE);
341         eeprom_write_bit((data & 0x01) ? 1 : 0);
342         eeprom_set_clock_line((data & 0x02) ? ASSERT_LINE : CLEAR_LINE);
343         eeprom_set_cs_line((data & 0x04) ? CLEAR_LINE : ASSERT_LINE);
344344      }
345345   }
346346   if( offset == 1 )
src/mame/drivers/dkong.c
r2762r2763
10861086   PORT_DIPSETTING(    0x05, DEF_STR( 1C_5C ) )
10871087   PORT_DIPSETTING(    0x07, DEF_STR( 1C_6C ) )
10881088   PORT_DIPUNKNOWN_DIPLOC( 0x08, 0x00, "SW2:!4" )
1089   PORT_DIPUNKNOWN_DIPLOC( 0x08, 0x00, "SW2:!5" )
1090   PORT_DIPUNKNOWN_DIPLOC( 0x08, 0x00, "SW2:!6" )
1089   PORT_DIPUNKNOWN_DIPLOC( 0x10, 0x00, "SW2:!5" )
1090   PORT_DIPUNKNOWN_DIPLOC( 0x20, 0x00, "SW2:!6" )
10911091   PORT_SERVICE_DIPLOC( 0x40, IP_ACTIVE_HIGH, "SW2:!7" )
10921092   PORT_DIPNAME( 0x80, 0x00, DEF_STR( Cabinet ) )         PORT_DIPLOCATION("SW2:!8")
10931093   PORT_DIPSETTING(    0x00, DEF_STR( Upright ) )
src/mame/drivers/ddenlovr.c
r2762r2763
339339
340340INLINE void log_draw_error(int src, int cmd)
341341{
342#ifdef MAME_DEBUG
342343   popmessage("%06x: warning unknown pixel command %02x",src,cmd);
344#endif
343345   logerror("%06x: warning unknown pixel command %02x\n",src,cmd);
344346}
345347
src/mame/drivers/kaneko16.c
r2762r2763
320320
321321static READ8_HANDLER( kaneko16_eeprom_r )
322322{
323   return EEPROM_read_bit() & 1;
323   return eeprom_read_bit() & 1;
324324}
325325
326326static WRITE8_HANDLER( kaneko16_eeprom_reset_w )
327327{
328328   // reset line asserted: reset.
329   EEPROM_set_cs_line((data & 0x01) ? CLEAR_LINE : ASSERT_LINE );
329   eeprom_set_cs_line((data & 0x01) ? CLEAR_LINE : ASSERT_LINE );
330330}
331331
332332static WRITE16_HANDLER( kaneko16_eeprom_w )
r2762r2763
334334   if (ACCESSING_BITS_0_7)
335335   {
336336      // latch the bit
337      EEPROM_write_bit(data & 0x02);
337      eeprom_write_bit(data & 0x02);
338338
339339      // reset line asserted: reset.
340//      EEPROM_set_cs_line((data & 0x00) ? CLEAR_LINE : ASSERT_LINE );
340//      eeprom_set_cs_line((data & 0x00) ? CLEAR_LINE : ASSERT_LINE );
341341
342342      // clock line asserted: write latch or select next bit to read
343      EEPROM_set_clock_line((data & 0x01) ? ASSERT_LINE : CLEAR_LINE );
343      eeprom_set_clock_line((data & 0x01) ? ASSERT_LINE : CLEAR_LINE );
344344   }
345345
346346   if (ACCESSING_BITS_8_15)
src/mame/drivers/20pacgal.c
r2762r2763
9494 *
9595 *************************************/
9696
97static const struct EEPROM_interface eeprom_interface =
97static const eeprom_interface eeprom_intf =
9898{
9999   7,            /* address bits */
100100   8,            /* data bits */
r2762r2763
109109static NVRAM_HANDLER( eeprom )
110110{
111111   if (read_or_write)
112      EEPROM_save(file);
112      eeprom_save(file);
113113   else
114114   {
115      EEPROM_init(&eeprom_interface);
115      eeprom_init(&eeprom_intf);
116116
117117      if (file)
118         EEPROM_load(file);
118         eeprom_load(file);
119119   }
120120}
121121
r2762r2763
123123static READ8_HANDLER( eeprom_r )
124124{
125125   /* bit 7 is EEPROM data */
126   return EEPROM_read_bit() << 7;
126   return eeprom_read_bit() << 7;
127127}
128128
129129
r2762r2763
132132   /* bit 7 is data */
133133   /* bit 6 is clock (active high) */
134134   /* bit 5 is cs (active low) */
135   EEPROM_write_bit(data & 0x80);
136   EEPROM_set_cs_line((data & 0x20) ? CLEAR_LINE : ASSERT_LINE);
137   EEPROM_set_clock_line((data & 0x40) ? ASSERT_LINE : CLEAR_LINE);
135   eeprom_write_bit(data & 0x80);
136   eeprom_set_cs_line((data & 0x20) ? CLEAR_LINE : ASSERT_LINE);
137   eeprom_set_clock_line((data & 0x40) ? ASSERT_LINE : CLEAR_LINE);
138138}
139139
140140
src/mame/drivers/limenko.c
r2762r2763
3838
3939static READ32_HANDLER( port2_r )
4040{
41   return (EEPROM_read_bit() << 23) | (input_port_read_indexed(machine, 2) & ~(1<<23));
41   return (eeprom_read_bit() << 23) | (input_port_read_indexed(machine, 2) & ~(1<<23));
4242}
4343
4444static WRITE32_HANDLER( eeprom_w )
4545{
4646   // data & 0x80000 -> video disabled?
4747
48   EEPROM_write_bit(data & 0x40000);
49   EEPROM_set_cs_line((data & 0x10000) ? CLEAR_LINE : ASSERT_LINE );
50   EEPROM_set_clock_line((data & 0x20000) ? ASSERT_LINE : CLEAR_LINE );
48   eeprom_write_bit(data & 0x40000);
49   eeprom_set_cs_line((data & 0x10000) ? CLEAR_LINE : ASSERT_LINE );
50   eeprom_set_clock_line((data & 0x20000) ? ASSERT_LINE : CLEAR_LINE );
5151}
5252
5353static WRITE32_HANDLER( limenko_coincounter_w )
src/mame/drivers/taito_b.c
r2762r2763
383383
384384***************************************************************************/
385385
386static const struct EEPROM_interface eeprom_interface =
386static const eeprom_interface eeprom_intf =
387387{
388388   6,            /* address bits */
389389   16,            /* data bits */
r2762r2763
397397static NVRAM_HANDLER( taito_b )
398398{
399399   if (read_or_write)
400      EEPROM_save(file);
400      eeprom_save(file);
401401   else
402402   {
403      EEPROM_init(&eeprom_interface);
403      eeprom_init(&eeprom_intf);
404404      if (file)
405405      {
406         EEPROM_load(file);
406         eeprom_load(file);
407407      }
408408   }
409409}
r2762r2763
412412{
413413   int res;
414414
415   res = (EEPROM_read_bit() & 0x01);
415   res = (eeprom_read_bit() & 0x01);
416416   res |= input_port_read_indexed(machine,1) & 0xfe; /* coin inputs */
417417
418418   return res;
r2762r2763
443443      /* bit 7 - set all the time (Chip Select?) */
444444
445445      /* EEPROM */
446      EEPROM_write_bit(data & 0x04);
447      EEPROM_set_clock_line((data & 0x08) ? ASSERT_LINE : CLEAR_LINE);
448      EEPROM_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
446      eeprom_write_bit(data & 0x04);
447      eeprom_set_clock_line((data & 0x08) ? ASSERT_LINE : CLEAR_LINE);
448      eeprom_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
449449   }
450450}
451451
src/mame/drivers/cps1.c
r2762r2763
167167   return (in << 8) | 0xff;
168168}
169169
170READ16_HANDLER( cps1_hack_dsw_r )
171{
172   static const char *const dswname[] = { "IN0", "DSWA", "DSWB", "DSWC" };
173   int in = input_port_read(machine, dswname[offset]);
174   return (in << 8) | in;
175}
176
170177READ16_HANDLER( cps1_in1_r )
171178{
172179   return input_port_read(machine, "IN1");
r2762r2763
174181
175182READ16_HANDLER( cps1_in2_r )
176183{
177   int buttons = input_port_read(machine, "IN2");
178   return buttons << 8 | buttons;
184   return input_port_read(machine, "IN2");
179185}
180186
181187READ16_HANDLER( cps1_in3_r )
182188{
183   int buttons = input_port_read(machine, "IN3");
184   return buttons << 8 | buttons;
189   return input_port_read(machine, "IN3");
185190}
186191
187192
r2762r2763
347352********************************************************************/
348353
349354#ifndef MESS
350static const struct EEPROM_interface qsound_eeprom_interface =
355static const eeprom_interface qsound_eeprom_interface =
351356{
352357   7,      /* address bits */
353358   8,      /* data bits */
r2762r2763
356361   "0111"   /* erase command */
357362};
358363
359static const struct EEPROM_interface pang3_eeprom_interface =
364static const eeprom_interface pang3_eeprom_interface =
360365{
361366   6,      /* address bits */
362367   16,      /* data bits */
r2762r2763
368373static NVRAM_HANDLER( qsound )
369374{
370375   if (read_or_write)
371      EEPROM_save(file);
376      eeprom_save(file);
372377   else
373378   {
374      EEPROM_init(&qsound_eeprom_interface);
379      eeprom_init(&qsound_eeprom_interface);
375380
376381      if (file)
377         EEPROM_load(file);
382         eeprom_load(file);
378383   }
379384}
380385
381386static NVRAM_HANDLER( pang3 )
382387{
383388   if (read_or_write)
384      EEPROM_save(file);
389      eeprom_save(file);
385390   else
386391   {
387      EEPROM_init(&pang3_eeprom_interface);
392      eeprom_init(&pang3_eeprom_interface);
388393
389394      if (file)
390         EEPROM_load(file);
395         eeprom_load(file);
391396   }
392397}
393398#endif
394399
395400READ16_HANDLER( cps1_eeprom_port_r )
396401{
397   return EEPROM_read_bit();
402   return eeprom_read_bit();
398403}
399404
400405WRITE16_HANDLER( cps1_eeprom_port_w )
r2762r2763
406411        bit 6 = clock
407412        bit 7 = cs
408413        */
409      EEPROM_write_bit(data & 0x01);
410      EEPROM_set_cs_line((data & 0x80) ? CLEAR_LINE : ASSERT_LINE);
411      EEPROM_set_clock_line((data & 0x40) ? ASSERT_LINE : CLEAR_LINE);
414      eeprom_write_bit(data & 0x01);
415      eeprom_set_cs_line((data & 0x80) ? CLEAR_LINE : ASSERT_LINE);
416      eeprom_set_clock_line((data & 0x40) ? ASSERT_LINE : CLEAR_LINE);
412417   }
413418}
414419
r2762r2763
754759   PORT_DIPSETTING(    0x02, "4" )
755760   PORT_DIPSETTING(    0x01, "5" )
756761   PORT_DIPSETTING(    0x00, "6" )
757   PORT_DIPUNUSED_DIPLOC( 0x40, 0x40, "SW(C):3" )
758   PORT_DIPUNUSED_DIPLOC( 0x80, 0x80, "SW(C):4" )
762   PORT_DIPUNUSED_DIPLOC( 0x04, 0x04, "SW(C):3" )
763   PORT_DIPUNUSED_DIPLOC( 0x08, 0x08, "SW(C):4" )
759764   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Flip_Screen ) )      PORT_DIPLOCATION("SW(C):5")
760765   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
761766   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
r2762r2763
826831   PORT_DIPSETTING(    0x03, "3" )
827832   PORT_DIPSETTING(    0x02, "4" )
828833   PORT_DIPSETTING(    0x01, "5" )
829   PORT_DIPUNUSED_DIPLOC( 0x40, 0x40, "SW(C):3" )
830   PORT_DIPUNUSED_DIPLOC( 0x80, 0x80, "SW(C):4" )
834   PORT_DIPUNUSED_DIPLOC( 0x04, 0x04, "SW(C):3" )
835   PORT_DIPUNUSED_DIPLOC( 0x08, 0x08, "SW(C):4" )
831836   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Flip_Screen ) )         PORT_DIPLOCATION("SW(C):5")
832837   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
833838   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
r2762r2763
25202525   PORT_START_TAG("DSWA")
25212526   CPS1_COINAGE_2( "SW(A)" )
25222527   PORT_DIPUNUSED_DIPLOC( 0x08, 0x08, "SW(A):4" )
2523   PORT_DIPUNUSED_DIPLOC( 0x08, 0x08, "SW(A):5" )
2524   PORT_DIPUNUSED_DIPLOC( 0x08, 0x08, "SW(A):6" )
2528   PORT_DIPUNUSED_DIPLOC( 0x10, 0x10, "SW(A):5" )
2529   PORT_DIPUNUSED_DIPLOC( 0x20, 0x20, "SW(A):6" )
25252530   PORT_DIPNAME( 0x40, 0x40, "2 Coins to Start, 1 to Continue" )   PORT_DIPLOCATION("SW(A):7")
25262531   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
25272532   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
r2762r2763
52005205   ROM_LOAD( "nm_31.13c",  0x20000, 0x20000, CRC(2650a0a8) SHA1(e9e8cc1b27a2cb3e87124061fabcf42982f0611f) )   // == nm_19.12c
52015206ROM_END
52025207
5208/*
5209B-Board 90629B
5210
5211for gfx can use either mask ROMs (HN62404P-17) in the upper four rows, or
5212EPROMS (HN27C4096G-15) in the lower four rows.
5213
5214euro version has mask ROMs laid out like this:
5215sf2-5m.4a  in socket 2
5216sf2-7m.6a  in socket 4
5217sf2-1m.3a  in socket 1
5218sf2-3m.5a  in socket 3
5219sf2-6m.4c  in socket 11
5220sf2-8m.6c  in socket 13
5221sf2-2m.3c  in socket 10
5222sf2-4m.5c  in socket 12
5223sf2-13m.4d in socket 21
5224sf2-15m.6d in socket 23
5225sf2-9m.3d  in socket 20
5226sf2-11m.5d in socket 22
5227
5228the Japanese version has EPROMS laid out like this:
5229sf2_06.8a
5230sf2_08.10a
5231sf2_05.7a
5232sf2_07.9a
5233sf2_15.8c
5234sf2_17.10c
5235sf2_14.7c
5236sf2_16.9c
5237sf2_25.8d
5238sf2_27.10d
5239sf2_24.7d
5240sf2_26.9d
5241*/
5242
52035243ROM_START( sf2 )
52045244   ROM_REGION( CODE_SIZE, REGION_CPU1, 0 )      /* 68000 code */
52055245   ROM_LOAD16_BYTE( "sf2e.30g",      0x00000, 0x20000, CRC(fe39ee33) SHA1(22558eb15e035b09b80935a32b8425d91cd79669) )   // matches sf2u.30i
r2762r2763
77547794   DRIVER_INIT_CALL(cps1);
77557795}
77567796
7797static DRIVER_INIT( sf2hack )
7798{
7799   /* some SF2 hacks have some inputs wired to the LSB instead of MSB */
7800   memory_install_read16_handler (machine, 0, ADDRESS_SPACE_PROGRAM, 0x800018, 0x80001f, 0, 0, cps1_hack_dsw_r);
7801
7802   DRIVER_INIT_CALL(cps1);
7803}
7804
77577805static DRIVER_INIT( wof )
77587806{
77597807   wof_decode();
r2762r2763
78947942GAME( 1992, sf2m1,    sf2ce,    cps1_12MHz, sf2,      cps1,     ROT0,   "bootleg","Street Fighter II' - Champion Edition (M1)", GAME_NOT_WORKING )
78957943GAME( 1992, sf2m2,    sf2ce,    cps1_12MHz, sf2,      cps1,     ROT0,   "bootleg","Street Fighter II' - Champion Edition (M2)", GAME_NOT_WORKING )
78967944GAME( 1992, sf2m3,    sf2ce,    cps1_12MHz, sf2,      cps1,     ROT0,   "bootleg","Street Fighter II' - Champion Edition (M3)", GAME_NOT_WORKING )
7897GAME( 1992, sf2m4,    sf2ce,    cps1_12MHz, sf2j,     cps1,     ROT0,   "bootleg","Street Fighter II' - Champion Edition (M4)", 0 )
7898GAME( 1992, sf2m5,    sf2ce,    cps1_12MHz, sf2,      cps1,     ROT0,   "bootleg","Street Fighter II' - Champion Edition (M5)", 0 )
7899GAME( 1992, sf2m6,    sf2ce,    cps1_12MHz, sf2,      cps1,     ROT0,   "bootleg","Street Fighter II' - Champion Edition (M6)", 0 )
7900GAME( 1992, sf2m7,    sf2ce,    cps1_12MHz, sf2,      cps1,     ROT0,   "bootleg","Street Fighter II' - Champion Edition (M7)", 0 )
7901GAME( 1992, sf2yyc,   sf2ce,    cps1_12MHz, sf2,      cps1,     ROT0,   "bootleg","Street Fighter II' - Champion Edition (YYC)", 0 )
7902GAME( 1992, sf2koryu, sf2ce,    cps1_12MHz, sf2,      cps1,     ROT0,   "bootleg","Street Fighter II' - Champion Edition (Kouryu)", 0 )
7945GAME( 1992, sf2m4,    sf2ce,    cps1_12MHz, sf2j,     sf2hack,  ROT0,   "bootleg","Street Fighter II' - Champion Edition (M4)", 0 )
7946GAME( 1992, sf2m5,    sf2ce,    cps1_12MHz, sf2,      sf2hack,  ROT0,   "bootleg","Street Fighter II' - Champion Edition (M5)", 0 )
7947GAME( 1992, sf2m6,    sf2ce,    cps1_12MHz, sf2,      sf2hack,  ROT0,   "bootleg","Street Fighter II' - Champion Edition (M6)", 0 )
7948GAME( 1992, sf2m7,    sf2ce,    cps1_12MHz, sf2,      sf2hack,  ROT0,   "bootleg","Street Fighter II' - Champion Edition (M7)", 0 )
7949GAME( 1992, sf2yyc,   sf2ce,    cps1_12MHz, sf2,      sf2hack,  ROT0,   "bootleg","Street Fighter II' - Champion Edition (YYC)", 0 )
7950GAME( 1992, sf2koryu, sf2ce,    cps1_12MHz, sf2,      sf2hack,  ROT0,   "bootleg","Street Fighter II' - Champion Edition (Kouryu)", 0 )
79037951GAME( 1992, varth,    0,        cps1_12MHz, varth,    cps1,     ROT270, "Capcom", "Varth - Operation Thunderstorm (World 920714)" , 0)      // "ETC"    12MHz not verified but game slows down at 10MHz
79047952GAME( 1992, varthr1,  varth,    cps1_12MHz, varth,    cps1,     ROT270, "Capcom", "Varth - Operation Thunderstorm (World 920612)" , 0)      // "ETC"
79057953GAME( 1992, varthu,   varth,    cps1_12MHz, varth,    cps1,     ROT270, "Capcom (Romstar license)", "Varth - Operation Thunderstorm (US 920612)", 0 )
src/mame/drivers/gaelco3d.c
r2762r2763
264264static READ16_HANDLER( eeprom_data_r )
265265{
266266   UINT16 result = 0xffff;
267   if (EEPROM_read_bit())
267   if (eeprom_read_bit())
268268      result ^= 0x0004;
269269   logerror("eeprom_data_r(%02X)\n", result);
270270   return result;
r2762r2763
274274static WRITE16_HANDLER( eeprom_data_w )
275275{
276276   if (ACCESSING_BITS_0_7)
277      EEPROM_write_bit(data & 0x01);
277      eeprom_write_bit(data & 0x01);
278278}
279279
280280
281281static WRITE16_HANDLER( eeprom_clock_w )
282282{
283283   if (ACCESSING_BITS_0_7)
284      EEPROM_set_clock_line((data & 0x01) ? ASSERT_LINE : CLEAR_LINE);
284      eeprom_set_clock_line((data & 0x01) ? ASSERT_LINE : CLEAR_LINE);
285285}
286286
287287
288288static WRITE16_HANDLER( eeprom_cs_w )
289289{
290290   if (ACCESSING_BITS_0_7)
291      EEPROM_set_cs_line((data & 0x01) ? CLEAR_LINE : ASSERT_LINE);
291      eeprom_set_cs_line((data & 0x01) ? CLEAR_LINE : ASSERT_LINE);
292292}
293293
294294
src/mame/drivers/kickgoal.c
r2762r2763
447447static NVRAM_HANDLER( kickgoal )
448448{
449449   if (read_or_write)
450      EEPROM_save(file);
450      eeprom_save(file);
451451   else
452452   {
453      EEPROM_init(&eeprom_interface_93C46);
453      eeprom_init(&eeprom_interface_93C46);
454454
455      if (file) EEPROM_load(file);
455      if (file) eeprom_load(file);
456456      else
457457      {
458458         if (kickgoal_default_eeprom)   /* Sane Defaults */
459            EEPROM_set_data(kickgoal_default_eeprom,kickgoal_default_eeprom_length);
459            eeprom_set_data(kickgoal_default_eeprom,kickgoal_default_eeprom_length);
460460      }
461461   }
462462}
r2762r2763
467467{
468468   if (ACCESSING_BITS_0_7)
469469   {
470      return EEPROM_read_bit();
470      return eeprom_read_bit();
471471   }
472472   return 0;
473473}
r2762r2763
480480      switch (offset)
481481      {
482482         case 0:
483            EEPROM_set_cs_line((data & 0x0001) ? CLEAR_LINE : ASSERT_LINE);
483            eeprom_set_cs_line((data & 0x0001) ? CLEAR_LINE : ASSERT_LINE);
484484            break;
485485         case 1:
486            EEPROM_set_clock_line((data & 0x0001) ? ASSERT_LINE : CLEAR_LINE);
486            eeprom_set_clock_line((data & 0x0001) ? ASSERT_LINE : CLEAR_LINE);
487487            break;
488488         case 2:
489            EEPROM_write_bit(data & 0x0001);
489            eeprom_write_bit(data & 0x0001);
490490            break;
491491      }
492492   }
src/mame/drivers/snk.c
r2762r2763
889889
890890   MDRV_PALETTE_INIT(aso)
891891   MDRV_VIDEO_START(snk)
892   MDRV_VIDEO_UPDATE(tnk3)
892   MDRV_VIDEO_UPDATE(athena)
893893
894894   /* sound hardware */
895895   MDRV_SPEAKER_STANDARD_MONO("mono")
src/mame/drivers/hyprduel.c
r2762r2763
1010OSC:  4.0000MHz, 20.0000MHz, 26.6660MHz
1111Imagetek Inc 14220 071
1212
13
14Magical Error wo Sagase
15(c)1993? Technosoft / Jaleco
16TEC5000(Japan)
17
18TMP68000N-10 x2
19YM2413
20OKI M6295
21OSC:  3.579545MHz, 4.0000MHz, 20.0000MHz, 26.6660MHz
22Imagetek Inc 14220 071
23
1324--
1425driver by Eisuke Watanabe
1526based on driver from drivers/metro.c by Luca Elia
r2762r2763
823834
824835ROM_START( hyprduel )
825836   ROM_REGION( 0x80000, REGION_CPU1, 0 )
826   ROM_LOAD16_BYTE( "hd_prg2.rom", 0x000000, 0x40000, CRC(c7402722) SHA1(e385676cdcee65a3ddf07791d82a1fe83ba1b3e2) )
827   ROM_LOAD16_BYTE( "hd_prg1.rom", 0x000001, 0x40000, CRC(d8297c2b) SHA1(2e23c5b1784d0a465c0c0dc3ca28505689a8b16c) )
837   ROM_LOAD16_BYTE( "24.u24", 0x000000, 0x40000, CRC(c7402722) SHA1(e385676cdcee65a3ddf07791d82a1fe83ba1b3e2) ) /* Also silk screened as position 10 */
838   ROM_LOAD16_BYTE( "23.u23", 0x000001, 0x40000, CRC(d8297c2b) SHA1(2e23c5b1784d0a465c0c0dc3ca28505689a8b16c) ) /* Also silk screened as position  9 */
828839
829840   ROM_REGION( 0x400000, REGION_GFX1, 0 )   /* Gfx + Prg + Data (Addressable by CPU & Blitter) */
830   ROMX_LOAD( "hyper-1.4", 0x000000, 0x100000, CRC(4b3b2d3c) SHA1(5e9e8ec853f71aeff3910b93dadbaeae2b61717b) , ROM_GROUPWORD | ROM_SKIP(6) )
831   ROMX_LOAD( "hyper-2.6", 0x000002, 0x100000, CRC(dc230116) SHA1(a3c447657d8499764f52c81382961f425c56037b) , ROM_GROUPWORD | ROM_SKIP(6) )
832   ROMX_LOAD( "hyper-3.3", 0x000004, 0x100000, CRC(2d770dd0) SHA1(27f9e7f67e96210d3710ab4f940c5d7ae13f8bbf) , ROM_GROUPWORD | ROM_SKIP(6) )
833   ROMX_LOAD( "hyper-4.5", 0x000006, 0x100000, CRC(f88c6d33) SHA1(277b56df40a17d7dd9f1071b0d498635a5b783cd) , ROM_GROUPWORD | ROM_SKIP(6) )
841   ROMX_LOAD( "ts_hyper-1.u74", 0x000000, 0x100000, CRC(4b3b2d3c) SHA1(5e9e8ec853f71aeff3910b93dadbaeae2b61717b) , ROM_GROUPWORD | ROM_SKIP(6) )
842   ROMX_LOAD( "ts_hyper-2.u75", 0x000002, 0x100000, CRC(dc230116) SHA1(a3c447657d8499764f52c81382961f425c56037b) , ROM_GROUPWORD | ROM_SKIP(6) )
843   ROMX_LOAD( "ts_hyper-3.u76", 0x000004, 0x100000, CRC(2d770dd0) SHA1(27f9e7f67e96210d3710ab4f940c5d7ae13f8bbf) , ROM_GROUPWORD | ROM_SKIP(6) )
844   ROMX_LOAD( "ts_hyper-4.u77", 0x000006, 0x100000, CRC(f88c6d33) SHA1(277b56df40a17d7dd9f1071b0d498635a5b783cd) , ROM_GROUPWORD | ROM_SKIP(6) )
834845
835846   ROM_REGION( 0x40000, REGION_SOUND1, 0 )   /* Samples */
836   ROM_LOAD( "97.11", 0x00000, 0x40000, CRC(bf3f8574) SHA1(9e743f05e53256c886d43e1f0c43d7417134b9b3) )
847   ROM_LOAD( "97.u97", 0x00000, 0x40000, CRC(bf3f8574) SHA1(9e743f05e53256c886d43e1f0c43d7417134b9b3) ) /* Also silk screened as position 11 */
837848ROM_END
838849
839850ROM_START( hyprdelj )
840851   ROM_REGION( 0x80000, REGION_CPU1, 0 )
841   ROM_LOAD16_BYTE( "u24a.10", 0x000000, 0x40000, CRC(2458f91d) SHA1(c75c7bccc84738e29b35667793491a1213aea1da) )
842   ROM_LOAD16_BYTE( "u23a.9",  0x000001, 0x40000, CRC(98aedfca) SHA1(42028e57ac79473cde683be2100b953ff3b2b345) )
852   ROM_LOAD16_BYTE( "24a.u24", 0x000000, 0x40000, CRC(2458f91d) SHA1(c75c7bccc84738e29b35667793491a1213aea1da) ) /* Also silk screened as position 10 */
853   ROM_LOAD16_BYTE( "23a.u23", 0x000001, 0x40000, CRC(98aedfca) SHA1(42028e57ac79473cde683be2100b953ff3b2b345) ) /* Also silk screened as position  9 */
843854
844855   ROM_REGION( 0x400000, REGION_GFX1, 0 )   /* Gfx + Prg + Data (Addressable by CPU & Blitter) */
845   ROMX_LOAD( "hyper-1.4", 0x000000, 0x100000, CRC(4b3b2d3c) SHA1(5e9e8ec853f71aeff3910b93dadbaeae2b61717b) , ROM_GROUPWORD | ROM_SKIP(6) )
846   ROMX_LOAD( "hyper-2.6", 0x000002, 0x100000, CRC(dc230116) SHA1(a3c447657d8499764f52c81382961f425c56037b) , ROM_GROUPWORD | ROM_SKIP(6) )
847   ROMX_LOAD( "hyper-3.3", 0x000004, 0x100000, CRC(2d770dd0) SHA1(27f9e7f67e96210d3710ab4f940c5d7ae13f8bbf) , ROM_GROUPWORD | ROM_SKIP(6) )
848   ROMX_LOAD( "hyper-4.5", 0x000006, 0x100000, CRC(f88c6d33) SHA1(277b56df40a17d7dd9f1071b0d498635a5b783cd) , ROM_GROUPWORD | ROM_SKIP(6) )
856   ROMX_LOAD( "ts_hyper-1.u74", 0x000000, 0x100000, CRC(4b3b2d3c) SHA1(5e9e8ec853f71aeff3910b93dadbaeae2b61717b) , ROM_GROUPWORD | ROM_SKIP(6) )
857   ROMX_LOAD( "ts_hyper-2.u75", 0x000002, 0x100000, CRC(dc230116) SHA1(a3c447657d8499764f52c81382961f425c56037b) , ROM_GROUPWORD | ROM_SKIP(6) )
858   ROMX_LOAD( "ts_hyper-3.u76", 0x000004, 0x100000, CRC(2d770dd0) SHA1(27f9e7f67e96210d3710ab4f940c5d7ae13f8bbf) , ROM_GROUPWORD | ROM_SKIP(6) )
859   ROMX_LOAD( "ts_hyper-4.u77", 0x000006, 0x100000, CRC(f88c6d33) SHA1(277b56df40a17d7dd9f1071b0d498635a5b783cd) , ROM_GROUPWORD | ROM_SKIP(6) )
849860
850861   ROM_REGION( 0x40000, REGION_SOUND1, 0 )   /* Samples */
851   ROM_LOAD( "97.11", 0x00000, 0x40000, CRC(bf3f8574) SHA1(9e743f05e53256c886d43e1f0c43d7417134b9b3) )
862   ROM_LOAD( "97.u97", 0x00000, 0x40000, CRC(bf3f8574) SHA1(9e743f05e53256c886d43e1f0c43d7417134b9b3) ) /* Also silk screened as position 11 */
852863ROM_END
853864
854865ROM_START( magerror )
855866   ROM_REGION( 0x80000, REGION_CPU1, 0 )
856   ROM_LOAD16_BYTE( "u24.10", 0x000000, 0x40000, CRC(5e78027f) SHA1(053374942bc545a92cc6f6ab6784c4626e4ec9e1) )
857   ROM_LOAD16_BYTE( "u23.9",  0x000001, 0x40000, CRC(7271ec70) SHA1(bd7666390b70821f90ba976a3afe3194fb119478) )
867   ROM_LOAD16_BYTE( "24.u24", 0x000000, 0x40000, CRC(5e78027f) SHA1(053374942bc545a92cc6f6ab6784c4626e4ec9e1) ) /* Also silk screened as position 10 */
868   ROM_LOAD16_BYTE( "23.u23", 0x000001, 0x40000, CRC(7271ec70) SHA1(bd7666390b70821f90ba976a3afe3194fb119478) ) /* Also silk screened as position  9 */
858869
859870   ROM_REGION( 0x400000, REGION_GFX1, 0 )   /* Gfx + Prg + Data (Addressable by CPU & Blitter) */
860   ROMX_LOAD( "mr01.u76", 0x000004, 0x100000, CRC(6cc3b928) SHA1(f19d0add314867bfb7dcefe8e7a2d50a84530df7) , ROM_GROUPWORD | ROM_SKIP(6) )
861   ROMX_LOAD( "mr03.u77", 0x000006, 0x100000, CRC(6b1eb0ea) SHA1(6167a61562ef28147a7917c692f181f3fc2d5be6) , ROM_GROUPWORD | ROM_SKIP(6) )
862   ROMX_LOAD( "mr02.u74", 0x000000, 0x100000, CRC(f7ba06fb) SHA1(e1407b0d03863f434b68183c01e8547612e5c5fd) , ROM_GROUPWORD | ROM_SKIP(6) )
863   ROMX_LOAD( "mr04.u75", 0x000002, 0x100000, CRC(8c114d15) SHA1(4eb1f82e7992deb126633287cb4fd2a6d215346c) , ROM_GROUPWORD | ROM_SKIP(6) )
871   ROMX_LOAD( "mr93046-02.u74", 0x000000, 0x100000, CRC(f7ba06fb) SHA1(e1407b0d03863f434b68183c01e8547612e5c5fd) , ROM_GROUPWORD | ROM_SKIP(6) )
872   ROMX_LOAD( "mr93046-04.u75", 0x000002, 0x100000, CRC(8c114d15) SHA1(4eb1f82e7992deb126633287cb4fd2a6d215346c) , ROM_GROUPWORD | ROM_SKIP(6) )
873   ROMX_LOAD( "mr93046-01.u76", 0x000004, 0x100000, CRC(6cc3b928) SHA1(f19d0add314867bfb7dcefe8e7a2d50a84530df7) , ROM_GROUPWORD | ROM_SKIP(6) )
874   ROMX_LOAD( "mr93046-03.u77", 0x000006, 0x100000, CRC(6b1eb0ea) SHA1(6167a61562ef28147a7917c692f181f3fc2d5be6) , ROM_GROUPWORD | ROM_SKIP(6) )
864875
865876   ROM_REGION( 0x40000, REGION_SOUND1, 0 )   /* Samples */
866   ROM_LOAD( "u97.11", 0x00000, 0x40000, CRC(2e62bca8) SHA1(191fff11186dbbc1d9d9f3ba1b6e17c38a7d2d1d) )
877   ROM_LOAD( "97.u97", 0x00000, 0x40000, CRC(2e62bca8) SHA1(191fff11186dbbc1d9d9f3ba1b6e17c38a7d2d1d) ) /* Also silk screened as position 11 */
867878ROM_END
868879
869880GAME( 1993, hyprduel, 0,        hyprduel, hyprduel, hyprduel, ROT0, "Technosoft", "Hyper Duel (Japan set 1)", 0 )
870881GAME( 1993, hyprdelj, hyprduel, hyprduel, hyprduel, hyprduel, ROT0, "Technosoft", "Hyper Duel (Japan set 2)", 0 )
871882
872GAME( 199?, magerror, 0,        magerror, hyprduel, hyprduel, ROT0, "Technosoft / Jaleco", "Search for the Magical Error", GAME_NOT_WORKING )
883GAME( 199?, magerror, 0,        magerror, hyprduel, hyprduel, ROT0, "Technosoft / Jaleco", "Magical Error wo Sagase", GAME_NOT_WORKING )
src/mame/drivers/f-32.c
r2762r2763
4545
4646static READ32_HANDLER( eeprom_r )
4747{
48   return EEPROM_read_bit();
48   return eeprom_read_bit();
4949}
5050
5151static WRITE32_HANDLER( eeprom_bit_w )
5252{
53   EEPROM_write_bit(data & 0x01);
53   eeprom_write_bit(data & 0x01);
5454}
5555
5656static WRITE32_HANDLER( eeprom_cs_line_w )
5757{
58   EEPROM_set_cs_line( (data & 0x01) ? CLEAR_LINE : ASSERT_LINE );
58   eeprom_set_cs_line( (data & 0x01) ? CLEAR_LINE : ASSERT_LINE );
5959}
6060
6161static WRITE32_HANDLER( eeprom_clock_line_w )
6262{
63   EEPROM_set_clock_line( (~data & 0x01) ? ASSERT_LINE : CLEAR_LINE );
63   eeprom_set_clock_line( (~data & 0x01) ? ASSERT_LINE : CLEAR_LINE );
6464}
6565
6666
src/mame/drivers/model2.c
r2762r2763
425425{
426426   if(ACCESSING_BITS_0_7) {
427427      model2_ctrlmode = data & 0x01;
428      EEPROM_write_bit(data & 0x20);
429      EEPROM_set_clock_line((data & 0x80) ? ASSERT_LINE : CLEAR_LINE);
430      EEPROM_set_cs_line((data & 0x40) ? CLEAR_LINE : ASSERT_LINE);
428      eeprom_write_bit(data & 0x20);
429      eeprom_set_clock_line((data & 0x80) ? ASSERT_LINE : CLEAR_LINE);
430      eeprom_set_cs_line((data & 0x40) ? CLEAR_LINE : ASSERT_LINE);
431431   }
432432}
433433
r2762r2763
442442   else
443443   {
444444      ret &= ~0x00300000;
445      return ret | 0x00100000 | (EEPROM_read_bit() << 21);
445      return ret | 0x00100000 | (eeprom_read_bit() << 21);
446446   }
447447}
448448static READ32_HANDLER(ctrl1_r)
r2762r2763
25122512  epr-20939.14    epr-20943.14    epr-20976.14    epr-20935.14
25132513  epr-20940.15    epr-20944.15    epr-20977.15    epr-20936.15
25142514  epr-20941.16    epr-20945.16    epr-20978.16    epr-20937.16
2515Model2c:
2516  epr-20950.13    epr-20954.13    epr-20979.13    epr-20946.13
2517  epr-20951.14    epr-20955.14    epr-20980.14    epr-20947.14
2518  epr-20952.15    epr-20956.15    epr-20981.15    epr-20948.15
2519  epr-20953.16    epr-20967.16    epr-20982.16    epr-20949.16
25152520
25162521* The numbers for the Japan sets were not listed, but are shown for comparision
25172522
r2762r2763
27062711   ROM_LOAD("mpr-20815.37", 0x600000, 0x200000, CRC(1b5aaae4) SHA1(32b4bf6c096fdccdd5d8f1ddb6c27d3389a52234) )
27072712ROM_END
27082713
2714ROM_START( dynmcopc )
2715   ROM_REGION( 0x200000, REGION_CPU1, 0 ) // i960 program
2716   ROM_LOAD32_WORD("epr-20952.15", 0x000000, 0x080000, CRC(ec8bc896) SHA1(85deb1dc1348730a0c9b6ce3679582e7894ff2ed) ) /* Dynamite Cop MODEL2C (USA Ver.) */
2717   ROM_LOAD32_WORD("epr-20953.16", 0x000002, 0x080000, CRC(a8276ffd) SHA1(9bea99c043775c00742c20e2f917d211dca09cc5) )
2718   ROM_LOAD32_WORD("epr-20950.13", 0x100000, 0x080000, CRC(618a68bf) SHA1(3022283dded4d08d790d034b6d543c0397b5bf5a) ) /* same as epr-20932.14 listed above */
2719   ROM_LOAD32_WORD("epr-20951.14", 0x100002, 0x080000, CRC(13abe49c) SHA1(a741a0205c1b3664ab4d09d6d991a768269a79ea) ) /* same as epr-20933.15 listed above */
2720
2721   ROM_REGION32_LE( 0x2000000, REGION_USER1, 0 ) // Data
2722   ROM_LOAD32_WORD("mpr-20797.10", 0x0000000, 0x400000, CRC(87bab1e4) SHA1(af2b2d82364621a1528d6ed59fbfbf15dc93ee72) ) /* Located at position 11 on 2C-CRX rom board */
2723   ROM_LOAD32_WORD("mpr-20798.11", 0x0000002, 0x400000, CRC(40dd752b) SHA1(8c2e210ac7c7b133ba9befc79a07c4ca6b4e3f18) ) /* Located at position 12 on 2C-CRX rom board */
2724   ROM_LOAD32_WORD("mpr-20795.8",  0x0800000, 0x400000, CRC(0ef85e12) SHA1(97c657edd98cde6f0780a04a7711e5b370087a60) ) /* Located at position  9 on 2C-CRX rom board */
2725   ROM_LOAD32_WORD("mpr-20796.9",  0x0800002, 0x400000, CRC(870139cb) SHA1(24fda2cd458cf7a3db485564c02ac61d30cbdf5e) ) /* Located at position 10 on 2C-CRX rom board */
2726   ROM_LOAD32_WORD("mpr-20793.6",  0x1000000, 0x400000, CRC(42ea08f8) SHA1(e70b55709067628ea0bf3f5190a300100b61eed1) ) /* Located at position  7 on 2C-CRX rom board */
2727   ROM_LOAD32_WORD("mpr-20794.7",  0x1000002, 0x400000, CRC(8e5cd1db) SHA1(d90e86d38bda12f2d0f99e23a42928f05bde3ea8) ) /* Located at position  8 on 2C-CRX rom board */
2728   ROM_LOAD32_WORD("mpr-20791.4",  0x1800000, 0x400000, CRC(4883d0df) SHA1(b98af63e81f6c1b2766d7e96acbd1821bba000d4) ) /* Located at position  5 on 2C-CRX rom board */
2729   ROM_LOAD32_WORD("mpr-20792.5",  0x1800002, 0x400000, CRC(47becfa2) SHA1(a333885872a64b322f3cb464a70352d73654b1b3) ) /* Located at position  6 on 2C-CRX rom board */
2730
2731   ROM_REGION( 0x800000, REGION_CPU3, ROMREGION_ERASE00 ) // TGPx4 program (COPRO sockets)
2732
2733   ROM_REGION( 0x2000000, REGION_USER2, 0 ) // Models
2734   ROM_LOAD32_WORD("mpr-20799.16", 0x0000000, 0x400000, CRC(424571bf) SHA1(18a4e8d0e968fff3b645b59a0023b0ef38d51924) ) /* Located at position 17 on 2C-CRX rom board */
2735   ROM_LOAD32_WORD("mpr-20803.20", 0x0000002, 0x400000, CRC(61a8ad52) SHA1(0215b5de6d10f0852ac0ca4e10475e10243e39c7) ) /* Located at position 21 on 2C-CRX rom board */
2736   ROM_LOAD32_WORD("mpr-20800.17", 0x0800000, 0x400000, CRC(3c2ee808) SHA1(dc0c470c6b410ab991ef0e09ce1cc0f63c8a204d) ) /* Located at position 18 on 2C-CRX rom board */
2737   ROM_LOAD32_WORD("mpr-20804.21", 0x0800002, 0x400000, CRC(03b35cb8) SHA1(7bd2ae89f9cc7c0570dbaffe5f54aea2dfa1b39e) ) /* Located at position 22 on 2C-CRX rom board */
2738   ROM_LOAD32_WORD("mpr-20801.18", 0x1000000, 0x400000, CRC(c6914173) SHA1(d0861366c4123c833a325df5345f951386a94d1a) ) /* Located at position 19 on 2C-CRX rom board */
2739   ROM_LOAD32_WORD("mpr-20805.22", 0x1000002, 0x400000, CRC(f6605ede) SHA1(7c95bfe2e95bae3d59c3c9efe1f40b5bc292ad44) ) /* Located at position 23 on 2C-CRX rom board */
2740   ROM_LOAD32_WORD("mpr-20802.19", 0x1800000, 0x400000, CRC(d11b5267) SHA1(b90909849fbe0f62d5ec7c38608c84e7fa845ebf) ) /* Located at position 20 on 2C-CRX rom board */
2741   ROM_LOAD32_WORD("mpr-20806.23", 0x1800002, 0x400000, CRC(0c942073) SHA1(5f32a56857e2213b110c32deea184dba882e34b8) ) /* Located at position 24 on 2C-CRX rom board */
2742
2743   ROM_REGION( 0x1000000, REGION_USER3, 0 ) // Textures
2744   ROM_LOAD32_WORD("mpr-20809.25", 0x0000000, 0x400000, CRC(3b7b4622) SHA1(c6f1a1fd2684f352d3846b7f859b0405fa2d667a) ) /* Located at position 27 on 2C-CRX rom board */
2745   ROM_LOAD32_WORD("mpr-20807.24", 0x0000002, 0x400000, CRC(1241e0f2) SHA1(3f7fa1d7d3d398bc8d5295bc1df6fe11405d20d9) ) /* Located at position 25 on 2C-CRX rom board */
2746   ROM_LOAD32_WORD("mpr-20810.27", 0x0800000, 0x400000, CRC(838a10a7) SHA1(a658f1864829058b1d419e7c001e47cd0ab06a20) ) /* Located at position 28 on 2C-CRX rom board */
2747   ROM_LOAD32_WORD("mpr-20808.26", 0x0800002, 0x400000, CRC(706bd495) SHA1(f857b303afda6301b19d97dfe5c313126261716e) ) /* Located at position 26 on 2C-CRX rom board */
2748
2749   ROM_REGION( 0x100000, REGION_CPU2, 0 ) // Sound program
2750   ROM_LOAD16_WORD_SWAP("epr-20811.30", 0x080000,  0x80000, CRC(a154b83e) SHA1(2640c6b6966f4a888329e583b6b713bd0e779b6b) ) /* Located at position 31 on 2C-CRX rom board */
2751
2752   ROM_REGION( 0x800000, REGION_SOUND1, 0 ) // Samples
2753   ROM_LOAD("mpr-20812.31", 0x000000, 0x200000, CRC(695b6088) SHA1(09682d18144e60d740a9d7a3e19db6f76fa581f1) ) /* Located at position 32 on 2C-CRX rom board */
2754   ROM_LOAD("mpr-20813.32", 0x200000, 0x200000, CRC(1908679c) SHA1(32913385f09da2e43af0c4a4612b955527bfe759) ) /* Located at position 33 on 2C-CRX rom board */
2755   ROM_LOAD("mpr-20814.36", 0x400000, 0x200000, CRC(e8ebc74c) SHA1(731ce721bb9e148f3a9f7fbe569522567a681c4e) ) /* Located at position 34 on 2C-CRX rom board */
2756   ROM_LOAD("mpr-20815.37", 0x600000, 0x200000, CRC(1b5aaae4) SHA1(32b4bf6c096fdccdd5d8f1ddb6c27d3389a52234) ) /* Located at position 35 on 2C-CRX rom board */
2757ROM_END
2758
27092759ROM_START( schamp )
27102760   ROM_REGION( 0x200000, REGION_CPU1, 0 ) // i960 program
27112761   ROM_LOAD32_WORD("epr-19001.15", 0x000000, 0x080000, CRC(9b088511) SHA1(20718d985d14f4d2b1b8e982bfbebddd73cdb972) )
r2762r2763
30913141   ROM_LOAD("mpr-18244.35", 0x0600000, 0x200000, CRC(bfa75beb) SHA1(fec89260d887e90ee9c2803e2eaf937cf9bfa10b) )
30923142ROM_END
30933143
3144/*
3145Behind Enemy Lines
3146Sega, 1998
3147
3148This game runs on Sega Model2 C-CRX hardware
3149
3150PCB No: 837-12469-01
3151CPU   : intel i960
3152SOUND : MC68EC000FN12
3153OSC   : 32.000MHz (x3), 50.000MHz, 20.000MHz, 45.158MHz
3154DIPSW : 8 position (x1)
3155RAM   : M5M44170CJ (x2), HM514270CJ7 (x1), HM538254BJ-7 (x4), N341256SJ-15 (x10)
3156        UM62256EM-70LL (x4), TC18128CFWL-80V (x12), TC55V328AJ-15 (x3)
3157        CY7C185-25VC (x7), CY7C188-25VC (x2), dt71256 (x4), BR6265BF-10SL (x2)
3158        65256BLFP-10T (x2), LH521002AK-20 (x16)
3159
3160CUSTOM: SEGA 315-5687   (128 QFP)
3161        FUJITSU MB86235 (x2, 208 QFP)
3162        SEGA 315-5673   (240 QFP)
3163        SEGA 315-5798   (304 QFP)
3164        SEGA 315-5799   (368 QFP)
3165        SEGA 315-5725   (x2, 144 QFP)
3166        SEGA 315-5292A  (160 QFP)
3167        SEGA 315-5648   (64 QFP)
3168        SEGA 315-5672   (196 QFP)
3169        SEGA 315-5649   (100 QFP)
3170PAL   : 315-5879
3171OTHER : D71051GU-10
3172        LATTICE PLSI 2032 80LJ D702S08 (x2)
3173        TDA1386T
3174
3175Note: All epr* ROMs are 27C1024
3176      All mpr* ROMs are 16M MASK
3177
3178[JUMPERS]
3179JP1     2-3
3180JP2     1-2
3181JP3     2-3
3182JP4     1-2
3183JP5     1-2
3184JP6     1-2
3185JP7     1-2
3186JP8     2-3
3187JP9     2-3
3188JP10    1-2
3189JP11    1-2
3190JP12    1-2
3191JP13    1-2
3192JP14    1-2
3193JP15    2-3
3194JP16    1-2
3195JP17    1-2
3196JP18    1-2
3197JP19    1-2
3198JP20    2-3
3199JP21    2-3
3200JP22    2-3
3201JP23    2-3
3202JP24    2-3
3203*/
30943204ROM_START( bel )
30953205   ROM_REGION( 0x200000, REGION_CPU1, 0 ) // i960 program
30963206   ROM_LOAD32_WORD("epr-20225.15",   0x000000, 0x020000, CRC(4abc6b59) SHA1(cc6da75aafcbbc86720435182a66e8de065c8e99) )
r2762r2763
39654075}
39664076
39674077// Model 2 (TGPs, Model 1 sound board)
3968GAME( 1993, daytona,         0, model2o, daytona, 0, ROT0, "Sega", "Daytona USA (Japan)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3969GAME( 1993, daytonas,  daytona, model2o, daytona, 0, ROT0, "Sega", "Daytona USA (With Saturn Adverts)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3970GAME( 1993, daytonat,  daytona, model2o, daytona, 0, ROT0, "Sega", "Daytona USA (Japan, Turbo hack)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4078GAME( 1993, daytona,         0, model2o, daytona, 0,        ROT0, "Sega", "Daytona USA (Japan)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4079GAME( 1993, daytonas,  daytona, model2o, daytona, 0,        ROT0, "Sega", "Daytona USA (With Saturn Adverts)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4080GAME( 1993, daytonat,  daytona, model2o, daytona, 0,        ROT0, "Sega", "Daytona USA (Japan, Turbo hack)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
39714081GAME( 1993, daytonam,  daytona, model2o, daytona, daytonam, ROT0, "Sega", "Daytona USA (Japan, To The MAXX)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3972GAME( 1994, desert,          0, model2o, desert, 0, ROT0, "Sega/Martin Marietta", "Desert Tank", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3973GAME( 1994, vcop,            0, model2o, daytona, 0, ROT0, "Sega", "Virtua Cop", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4082GAME( 1994, desert,          0, model2o, desert,  0,        ROT0, "Sega/Martin Marietta", "Desert Tank", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4083GAME( 1994, vcop,            0, model2o, daytona, 0,        ROT0, "Sega", "Virtua Cop", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
39744084
39754085// Model 2A-CRX (TGPs, SCSP sound board)
3976GAME( 1995, manxtt,          0, model2a, model2, 0, ROT0, "Sega", "Manx TT Superbike", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3977GAME( 1995, motoraid,        0, model2a, model2, 0, ROT0, "Sega", "Motoraid", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3978GAME( 1995, srallyc,         0, model2a, model2, 0, ROT0, "Sega", "Sega Rally Championship", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3979GAME( 1995, vf2,             0, model2a, model2, 0, ROT0, "Sega", "Virtua Fighter 2 (ver 2.1)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3980GAME( 1995, vf2b,          vf2, model2a, model2, 0, ROT0, "Sega", "Virtua Fighter 2 (ver B)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3981GAME( 1995, vf2o,          vf2, model2a, model2, 0, ROT0, "Sega", "Virtua Fighter 2", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3982GAME( 1995, vcop2,           0, model2a, model2, 0, ROT0, "Sega", "Virtua Cop 2", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3983GAME( 1995, skytargt,        0, model2a, model2, 0, ROT0, "Sega", "Sky Target", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3984GAME( 1996, dynamcop,        0, model2a, model2, genprot, ROT0, "Sega", "Dynamite Cop (Model 2A)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3985GAME( 1996, dyndeka2, dynamcop, model2a, model2, genprot, ROT0, "Sega", "Dynamite Deka 2 (Japan, Model 2A)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3986GAME( 1996, doaa,          doa, model2a, model2, doa, ROT0, "Sega", "Dead or Alive (Model 2A)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4086GAME( 1995, manxtt,          0, model2a, model2, 0,       ROT0, "Sega", "Manx TT Superbike", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4087GAME( 1995, motoraid,        0, model2a, model2, 0,       ROT0, "Sega", "Motoraid", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4088GAME( 1995, srallyc,         0, model2a, model2, 0,       ROT0, "Sega", "Sega Rally Championship", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4089GAME( 1995, vf2,             0, model2a, model2, 0,       ROT0, "Sega", "Virtua Fighter 2 (ver 2.1)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4090GAME( 1995, vf2b,          vf2, model2a, model2, 0,       ROT0, "Sega", "Virtua Fighter 2 (ver B)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4091GAME( 1995, vf2o,          vf2, model2a, model2, 0,       ROT0, "Sega", "Virtua Fighter 2", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4092GAME( 1995, vcop2,           0, model2a, model2, 0,       ROT0, "Sega", "Virtua Cop 2", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4093GAME( 1995, skytargt,        0, model2a, model2, 0,       ROT0, "Sega", "Sky Target", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4094GAME( 1996, doaa,          doa, model2a, model2, doa,     ROT0, "Sega", "Dead or Alive (Model 2A)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
39874095GAME( 1997, zeroguna,  zerogun, model2a, model2, zerogun, ROT0, "Psikyo", "Zero Gunner (Model 2A)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4096GAME( 1998, dynamcop,        0, model2a, model2, genprot, ROT0, "Sega", "Dynamite Cop (Export, Model 2A)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4097GAME( 1998, dyndeka2, dynamcop, model2a, model2, genprot, ROT0, "Sega", "Dynamite Deka 2 (Japan, Model 2A)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
39884098GAME( 1998, pltkidsa,  pltkids, model2a, model2, pltkids, ROT0, "Psikyo", "Pilot Kids (Model 2A)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
39894099
39904100// Model 2B-CRX (SHARC, SCSP sound board)
3991GAME( 1994, vstriker,        0, model2b, model2, 0, ROT0, "Sega", "Virtua Striker (Rev A)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3992GAME( 1994, vstrikro, vstriker, model2b, model2, 0, ROT0, "Sega", "Virtua Striker", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3993GAME( 1995, fvipers,         0, model2b, model2, 0, ROT0, "Sega", "Fighting Vipers", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3994GAME( 1995, gunblade,        0, model2b, model2, 0, ROT0, "Sega", "Gunblade NY", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3995GAME( 1995, indy500,         0, model2b, model2, 0, ROT0, "Sega", "Indianapolis 500", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3996GAME( 1996, dynmcopb, dynamcop, model2b, model2, genprot, ROT0, "Sega", "Dynamite Cop (Model 2B)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3997GAME( 1996, dyndek2b, dynamcop, model2b, model2, genprot, ROT0, "Sega", "Dynamite Deka 2 (Japan, Model 2B)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3998GAME( 1996, schamp,          0, model2b, model2, 0, ROT0, "Sega", "Sonic The Fighters", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
3999GAME( 1996, lastbrnx,        0, model2b, model2, 0, ROT0, "Sega", "Last Bronx (Export, Rev A)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4000GAME( 1996, lastbrnj, lastbrnx, model2b, model2, 0, ROT0, "Sega", "Last Bronx (Japan, Rev A)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4001GAME( 1996, doa,             0, model2b, model2, doa, ROT0, "Sega", "Dead or Alive (Model 2B)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4002GAME( 1996, sgt24h,          0, model2b, model2, sgt24h, ROT0, "Jaleco", "Super GT 24h", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4003GAME( 1996, von,             0, model2b, model2, 0, ROT0, "Sega", "Virtual On Cyber Troopers (Japan, Rev B)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4004GAME( 1996, vonusa,        von, model2b, model2, 0, ROT0, "Sega", "Virtual On Cyber Troopers (US, Rev B)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4005GAME( 1996, dynabb,          0, model2b, model2, 0, ROT0, "Sega", "Dynamite Baseball '97", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4101GAME( 1994, vstriker,        0, model2b, model2, 0,       ROT0, "Sega", "Virtua Striker (Rev A)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4102GAME( 1994, vstrikro, vstriker, model2b, model2, 0,       ROT0, "Sega", "Virtua Striker", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4103GAME( 1995, fvipers,         0, model2b, model2, 0,       ROT0, "Sega", "Fighting Vipers", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4104GAME( 1995, gunblade,        0, model2b, model2, 0,       ROT0, "Sega", "Gunblade NY", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4105GAME( 1995, indy500,         0, model2b, model2, 0,       ROT0, "Sega", "Indianapolis 500", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4106GAME( 1996, schamp,          0, model2b, model2, 0,       ROT0, "Sega", "Sonic The Fighters", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4107GAME( 1996, lastbrnx,        0, model2b, model2, 0,       ROT0, "Sega", "Last Bronx (Export, Rev A)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4108GAME( 1996, lastbrnj, lastbrnx, model2b, model2, 0,       ROT0, "Sega", "Last Bronx (Japan, Rev A)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4109GAME( 1996, doa,             0, model2b, model2, doa,     ROT0, "Sega", "Dead or Alive (Model 2B)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4110GAME( 1996, sgt24h,          0, model2b, model2, sgt24h,  ROT0, "Jaleco", "Super GT 24h", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4111GAME( 1996, von,             0, model2b, model2, 0,       ROT0, "Sega", "Virtual On Cyber Troopers (Japan, Rev B)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4112GAME( 1996, vonusa,        von, model2b, model2, 0,       ROT0, "Sega", "Virtual On Cyber Troopers (US, Rev B)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4113GAME( 1996, dynabb,          0, model2b, model2, 0,       ROT0, "Sega", "Dynamite Baseball '97", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
40064114GAME( 1997, zerogun,         0, model2b, model2, zerogun, ROT0, "Psikyo", "Zero Gunner (Model 2B)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
40074115GAME( 1997, zerogunj,  zerogun, model2b, model2, zerogun, ROT0, "Psikyo", "Zero Gunner (Japan Model 2B)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4116GAME( 1998, dynmcopb, dynamcop, model2b, model2, genprot, ROT0, "Sega", "Dynamite Cop (Export, Model 2B)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4117GAME( 1998, dyndek2b, dynamcop, model2b, model2, genprot, ROT0, "Sega", "Dynamite Deka 2 (Japan, Model 2B)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
40084118GAME( 1998, pltkids,         0, model2b, model2, pltkids, ROT0, "Psikyo", "Pilot Kids (Model 2B)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
40094119
40104120// Model 2C-CRX (TGPx4, SCSP sound board)
r2762r2763
40144124GAME( 1997, overrev,         0, model2c, model2, 0, ROT0, "Jaleco", "Over Rev", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
40154125GAME( 1997, topskatr,        0, model2c, model2, 0, ROT0, "Sega", "Top Skater", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
40164126GAME( 1998, bel,             0, model2c, bel,    0, ROT0, "Sega/EPL Productions", "Behind Enemy Lines", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
4127GAME( 1998, dynmcopc, dynamcop, model2c, model2, 0, ROT0, "Sega", "Dynamite Cop (USA, Model 2C)", GAME_NOT_WORKING|GAME_IMPERFECT_GRAPHICS )
40174128
src/mame/drivers/ataxx.c
r2762r2763
100100
101101/* Helps document the input ports. */
102102#define IPT_SLAVEHALT    IPT_SPECIAL
103#define IPT_EEPROM_DATA   IPT_SPECIAL
103#define IPT_eeprom_DATA   IPT_SPECIAL
104104
105105
106106static INPUT_PORTS_START( ataxx )
r2762r2763
120120   PORT_BIT( 0xfc, IP_ACTIVE_LOW, IPT_UNUSED )
121121
122122   PORT_START      /* 0x20 */
123   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_EEPROM_DATA )
123   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_eeprom_DATA )
124124   PORT_BIT( 0xfe, IP_ACTIVE_LOW, IPT_UNUSED )
125125
126126   PORT_START      /* 0x00 - analog X */
r2762r2763
151151    PORT_BIT( 0xfc, IP_ACTIVE_LOW, IPT_UNUSED )
152152
153153   PORT_START      /* 0x20 */
154   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_EEPROM_DATA )
154   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_eeprom_DATA )
155155   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
156156    PORT_SERVICE_NO_TOGGLE( 0x04, IP_ACTIVE_LOW )
157157   PORT_BIT( 0xf8, IP_ACTIVE_LOW, IPT_UNUSED )
r2762r2763
203203    PORT_BIT( 0xfc, IP_ACTIVE_LOW, IPT_UNUSED )
204204
205205   PORT_START      /* 0x20 */
206   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_EEPROM_DATA )
206   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_eeprom_DATA )
207207   PORT_BIT( 0xfe, IP_ACTIVE_LOW, IPT_UNUSED )
208208
209209   PORT_START      /* Analog wheel 1 */
r2762r2763
249249    PORT_BIT( 0xfc, IP_ACTIVE_LOW, IPT_UNUSED )
250250
251251   PORT_START      /* 0x20 */
252   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_EEPROM_DATA )
252   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_eeprom_DATA )
253253   PORT_BIT( 0xfe, IP_ACTIVE_LOW, IPT_UNUSED )
254254
255255    PORT_START      /* 0x0D */
src/mame/drivers/leland.c
r2762r2763
122122
123123/* Helps document the input ports. */
124124#define IPT_SLAVEHALT    IPT_SPECIAL
125#define IPT_EEPROM_DATA   IPT_SPECIAL
125#define IPT_eeprom_DATA   IPT_SPECIAL
126126
127127
128128static INPUT_PORTS_START( cerberus )      /* complete, verified from code */
r2762r2763
144144   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
145145
146146   PORT_START      /* 0x91 */
147   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_EEPROM_DATA )
147   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_eeprom_DATA )
148148   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_VBLANK )
149149   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START2 ) PORT_PLAYER(1)
150150   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 ) PORT_PLAYER(1)
r2762r2763
190190   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(1)
191191
192192   PORT_START      /* 0xD1 */
193   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_EEPROM_DATA )
193   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_eeprom_DATA )
194194   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_VBLANK )
195195   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START2 )
196196   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 )
r2762r2763
223223   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("Aim") PORT_PLAYER(1)
224224
225225   PORT_START      /* 0x91 */
226   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_EEPROM_DATA )
226   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_eeprom_DATA )
227227   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_VBLANK )
228228   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START2 ) PORT_PLAYER(1)
229229   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 ) PORT_PLAYER(1)
r2762r2763
261261   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON2 )      /* redundant inputs */
262262
263263   PORT_START      /* 0xD1 */
264   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_EEPROM_DATA )
264   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_eeprom_DATA )
265265   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_VBLANK )
266266   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START2 ) PORT_PLAYER(1)
267267   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 ) PORT_PLAYER(1)
r2762r2763
297297   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON2 )
298298
299299   PORT_START      /* 0xD1 */
300   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_EEPROM_DATA )
300   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_eeprom_DATA )
301301   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_VBLANK )
302302   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START2 ) PORT_PLAYER(1)
303303   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 ) PORT_PLAYER(1)
r2762r2763
332332   PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNUSED )
333333
334334   PORT_START      /* 0x91 */
335   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_EEPROM_DATA )
335   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_eeprom_DATA )
336336   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_VBLANK )
337337   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START2 )
338338   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 )
r2762r2763
367367   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("Run/Cutoff") PORT_PLAYER(1)
368368
369369   PORT_START      /* 0x51/D1 */
370   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_EEPROM_DATA )
370   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_eeprom_DATA )
371371   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_VBLANK )
372372   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START2 ) PORT_PLAYER(1)
373373   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 ) PORT_PLAYER(1)
r2762r2763
404404   PORT_BIT( 0xe0, 0x00, IPT_PEDAL ) PORT_MINMAX(0x00,0xe0) PORT_SENSITIVITY(100) PORT_KEYDELTA(64) PORT_PLAYER(2)
405405
406406   PORT_START      /* 0xD1 */
407   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_EEPROM_DATA )
407   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_eeprom_DATA )
408408   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_VBLANK )
409409   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START2 )
410410   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 )
r2762r2763
442442   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1)
443443
444444   PORT_START      /* 0x91 */
445   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_EEPROM_DATA )
445   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_eeprom_DATA )
446446   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_VBLANK )
447447   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START2 )
448448   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 )
r2762r2763
484484   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1)
485485
486486   PORT_START      /* 0x91 */
487   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_EEPROM_DATA )
487   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_eeprom_DATA )
488488   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_VBLANK )
489489   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START2 )
490490   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 )
r2762r2763
542542   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1)
543543
544544   PORT_START      /* 0x91 */
545   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_EEPROM_DATA )
545   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_eeprom_DATA )
546546   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_VBLANK )
547547   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
548548   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 )
r2762r2763
597597   PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNUSED )
598598
599599   PORT_START      /* 0xD1 */
600   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_EEPROM_DATA )
600   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_eeprom_DATA )
601601   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_VBLANK )
602602   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
603603   PORT_SERVICE_NO_TOGGLE( 0x08, IP_ACTIVE_LOW )
r2762r2763
647647   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2)
648648
649649   PORT_START      /* 0x51 */
650   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_EEPROM_DATA )
650   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_eeprom_DATA )
651651   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_VBLANK )
652652   PORT_SERVICE_NO_TOGGLE( 0x04, IP_ACTIVE_LOW )
653653   PORT_BIT( 0xf8, IP_ACTIVE_LOW, IPT_UNUSED )
src/mame/drivers/cps2.c
r2762r2763
698698 *
699699 *************************************/
700700
701static const struct EEPROM_interface cps2_eeprom_interface =
701static const eeprom_interface cps2_eeprom_interface =
702702{
703703   6,      /* address bits */
704704   16,      /* data bits */
r2762r2763
710710static NVRAM_HANDLER( cps2 )
711711{
712712   if (read_or_write)
713      EEPROM_save(file);
713      eeprom_save(file);
714714   else
715715   {
716        EEPROM_init(&cps2_eeprom_interface);
716        eeprom_init(&cps2_eeprom_interface);
717717
718718      if (file)
719         EEPROM_load(file);
719         eeprom_load(file);
720720   }
721721}
722722
723static CUSTOM_INPUT( cps2_eeprom_port_r )
724{
725    return EEPROM_read_bit();
726}
727
728723static WRITE16_HANDLER( cps2_eeprom_port_w )
729724{
730725    if (ACCESSING_BITS_8_15)
r2762r2763
739734   /* bit 7 - */
740735
741736   /* EEPROM */
742   EEPROM_write_bit(data & 0x1000);
743   EEPROM_set_clock_line((data & 0x2000) ? ASSERT_LINE : CLEAR_LINE);
744   EEPROM_set_cs_line((data & 0x4000) ? CLEAR_LINE : ASSERT_LINE);
737   eeprom_write_bit(data & 0x1000);
738   eeprom_set_clock_line((data & 0x2000) ? ASSERT_LINE : CLEAR_LINE);
739   eeprom_set_cs_line((data & 0x4000) ? CLEAR_LINE : ASSERT_LINE);
745740   }
746741
747742   if (ACCESSING_BITS_0_7)
r2762r2763
955950    PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(4)
956951
957952    PORT_START_TAG("IN2")      /* IN2 (0x20) */
958    PORT_BIT( 0x0001, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(cps2_eeprom_port_r, NULL)
953    PORT_BIT( 0x0001, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(eeprom_bit_r, NULL)
959954   PORT_SERVICE_NO_TOGGLE( 0x0002, IP_ACTIVE_LOW )
960955    PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_SERVICE1 )
961956    PORT_BIT( 0x00f8, IP_ACTIVE_LOW, IPT_UNKNOWN )
r2762r2763
41444139
41454140ROM_START( mpang )
41464141   ROM_REGION( CODE_SIZE, REGION_CPU1, 0 )      /* 68000 code */
4142   ROM_LOAD16_WORD_SWAP( "mpne.03c", 0x000000, 0x80000, CRC(fe16fc9f) SHA1(be22bf8a0abd53d2e7ebc12d3d0020bf799a25e9) )
4143   ROM_LOAD16_WORD_SWAP( "mpne.04c", 0x080000, 0x80000, CRC(2cc5ec22) SHA1(c188349c26a64bad325cfa218849ed1e94303087) )
4144
4145   ROM_REGION( 0x1000000, REGION_GFX1, 0 )
4146   ROMX_LOAD( "mpn-simm.01c",   0x0000000, 0x200000, CRC(388db66b) SHA1(7416cce3d0dbea71c92ea9f72f5536146f757b45) , ROM_GROUPBYTE | ROM_SKIP(7) ) // ROM on a simm
4147   ROMX_LOAD( "mpn-simm.01d",   0x0000001, 0x200000, CRC(aff1b494) SHA1(d376c02ce01e71a7707d3d3fe5b0ae59ce781686) , ROM_GROUPBYTE | ROM_SKIP(7) ) // ROM on a simm
4148   ROMX_LOAD( "mpn-simm.01a",   0x0000002, 0x200000, CRC(a9c4857b) SHA1(66f538105c710d1480141e48a15b1a760f5ce985) , ROM_GROUPBYTE | ROM_SKIP(7) ) // ROM on a simm
4149   ROMX_LOAD( "mpn-simm.01b",   0x0000003, 0x200000, CRC(f759df22) SHA1(1678e3e819dd808f3a6fdd52b7c933eac4777b5b) , ROM_GROUPBYTE | ROM_SKIP(7) ) // ROM on a simm
4150   ROMX_LOAD( "mpn-simm.03c",   0x0000004, 0x200000, CRC(dec6b720) SHA1(331776e1cba3fb82071e7c2195dc4ae27b3613a2) , ROM_GROUPBYTE | ROM_SKIP(7) ) // ROM on a simm
4151   ROMX_LOAD( "mpn-simm.03d",   0x0000005, 0x200000, CRC(f8774c18) SHA1(58e0ea4dd62e39bcfaa3a2be4ef08eb2f0bd3c00) , ROM_GROUPBYTE | ROM_SKIP(7) ) // ROM on a simm
4152   ROMX_LOAD( "mpn-simm.03a",   0x0000006, 0x200000, CRC(c2aea4ec) SHA1(f5e2a815fa802598611efa48e5de97e929155e77) , ROM_GROUPBYTE | ROM_SKIP(7) ) // ROM on a simm
4153   ROMX_LOAD( "mpn-simm.03b",   0x0000007, 0x200000, CRC(84d6dc33) SHA1(f5ababb479facc08c425381570644230c09334e7) , ROM_GROUPBYTE | ROM_SKIP(7) ) // ROM on a simm
4154
4155   ROM_REGION( QSOUND_SIZE, REGION_CPU2, 0 ) /* 64k for the audio CPU (+banks) */
4156   ROM_LOAD( "mpn.01",   0x00000, 0x08000, CRC(90c7adb6) SHA1(a2653e977e5e0457b249e098e5ca0abc93dac336) )
4157   ROM_CONTINUE(         0x10000, 0x18000 )
4158
4159   ROM_REGION( 0x400000, REGION_SOUND1, 0 ) /* QSound samples */
4160   ROM_LOAD16_WORD_SWAP( "mpn-simm.05a",   0x000000, 0x200000, CRC(318a2e21) SHA1(c573cd88f8279a062c73ef1d79cd8421dbdcd93e) ) // ROM on a simm
4161   ROM_LOAD16_WORD_SWAP( "mpn-simm.05b",   0x200000, 0x200000, CRC(5462f4e8) SHA1(299fbdab700e735e6395c5d9e3f079bb2e3dbd73) ) // ROM on a simm
4162ROM_END
4163
4164ROM_START( mpangu )
4165   ROM_REGION( CODE_SIZE, REGION_CPU1, 0 )      /* 68000 code */
41474166   ROM_LOAD16_WORD_SWAP( "mpn.03", 0x000000, 0x80000, CRC(6e7ed03c) SHA1(3562362d9573252d4d19dbfd0ec7e47e9eaa5f46) ) /* USA version, but has no "u" in label code */
41484167   ROM_LOAD16_WORD_SWAP( "mpn.04", 0x080000, 0x80000, CRC(de079131) SHA1(95da2a03cb642963aabfebd8337003961ca4db71) )
41494168
r2762r2763
73937412
73947413/* Games released on CPS-2 hardware by Mitchell */
73957414
7396GAME( 2000, mpang,    0,        cps2, cps2_2p1b, cps2,     ROT0,   "Mitchell, distributed by Capcom", "Mighty! Pang (USA 001010)", 0 )
7415GAME( 2000, mpang,    0,        cps2, cps2_2p1b, cps2,     ROT0,   "Mitchell, distributed by Capcom", "Mighty! Pang (Euro 001010)", 0 )
7416GAME( 2000, mpangu,   mpang,    cps2, cps2_2p1b, cps2,     ROT0,   "Mitchell, distributed by Capcom", "Mighty! Pang (USA 001010)", 0 )
73977417GAME( 2000, mpangj,   mpang,    cps2, cps2_2p1b, cps2,     ROT0,   "Mitchell, distributed by Capcom", "Mighty! Pang (Japan 001011)", 0 )
73987418GAME( 2001, pzloop2,  0,        cps2, pzloop2,   pzloop2,  ROT0,   "Mitchell, distributed by Capcom", "Puzz Loop 2 (Euro 010302)", 0 )
73997419GAME( 2001, pzloop2j, pzloop2,  cps2, pzloop2,   pzloop2,  ROT0,   "Mitchell, distributed by Capcom", "Puzz Loop 2 (Japan 010205)", 0 )
src/mame/drivers/lordgun.c
r2762r2763
110110
111111static READ8_HANDLER( lordgun_eeprom_r )
112112{
113   return input_port_read_indexed(machine, 0) | ((EEPROM_read_bit() & 1) << 7);
113   return input_port_read_indexed(machine, 0) | ((eeprom_read_bit() & 1) << 7);
114114}
115115
116116static WRITE8_HANDLER( lordgun_eeprom_w )
r2762r2763
132132         lordgun_update_gun(machine, i);
133133
134134   // latch the bit
135   EEPROM_write_bit(data & 0x40);
135   eeprom_write_bit(data & 0x40);
136136
137137   // reset line asserted: reset.
138   EEPROM_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE );
138   eeprom_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE );
139139
140140   // clock line asserted: write latch or select next bit to read
141   EEPROM_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE );
141   eeprom_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE );
142142
143143   lordgun_whitescreen = data & 0x80;
144144
src/mame/drivers/magic10.c
r2762r2763
463463   ROM_LOAD( "7.u32",        0x00000, 0x40000, CRC(47804af7) SHA1(602dc0361869b52532e2adcb0de3cbdd042761b3) )
464464ROM_END
465465
466/*
467
468Super Pool
469
470ABM (Nazionale Elettronica Giochi S.A.S.), 1998.
4719743 Rev.01
472
4731x MC68HC000P10
4741x ACTEL A1020B-PL84C
4751x HD6473308CP10 (label says: do not remove version 1.2)
4761x U6295 (sound)
4771x LM358N (sound)
4781x TDA2003 (sound)
4791x oscillator 20.000MHz
4801x oscillator 30.0000MHz
4811x blu resonator 1000J (close to sound)
482
4831x M27C2001 (1) (Sound)
4842x TMS27C010A (2,3) (main)
4854x TMS27C010A (4,5,6,7) (gfx)
4861x PALCE22V10H (not dumped)
4871x PALCE16V8H (not dumped)
488
4891x 28x2 JAMMA edge connector
4901x 12 legs connector (J1)
4911x trimmer (volume)
4921x 8x2 switches dip
4931x lithium battery
494
495*/
496
497ROM_START( suprpool )
498   ROM_REGION( 0x40000, REGION_CPU1, 0 ) /* 68000 Code */
499   ROM_LOAD16_BYTE( "2-1.22a.u3", 0x00000, 0x20000,CRC(5d15037a) SHA1(74cab79a1b08910267262a4c6b501126a4df6cda) )
500   ROM_LOAD16_BYTE( "3-1.22a.u2", 0x00001, 0x20000,CRC(c762cd1c) SHA1(ee05a9e8147d613eb14333e6e7b743fc05982e7c) )
501
502   ROM_REGION( 0x80000, REGION_GFX1, 0 ) /* Sprites */
503   ROM_LOAD( "7.u35", 0x00000, 0x20000,  CRC(357d145f) SHA1(9fea0d0c5d6c27bf520c4f81eb0f48a65ff60142) )
504   ROM_LOAD( "6.u36", 0x20000, 0x20000,  CRC(c4448813) SHA1(6e168eb8503b852179f2d743f1cba935592e0a60) )
505   ROM_LOAD( "5.u37", 0x40000, 0x20000,  CRC(6e99af07) SHA1(85e7a76724fd9ce8d07b5088cb6e0d933fd95692) )
506   ROM_LOAD( "4.u38", 0x60000, 0x20000,  CRC(0660a169) SHA1(1cb34b3da4b144028519a3c5b32ef7da44af0624) )
507
508   ROM_REGION( 0x080000, REGION_SOUND1, 0 ) /* Samples */
509   ROM_LOAD( "1.u32", 0x00000, 0x40000, CRC(47804af7) SHA1(602dc0361869b52532e2adcb0de3cbdd042761b3) )
510ROM_END
511
466512static DRIVER_INIT( magic10 )
467513{
468514   layer2_offset[0] = 32;
r2762r2763
475521   layer2_offset[1] = 20;
476522}
477523
478GAME( 1995, magic10,   0,       magic10,   magic10,   magic10,   ROT0, "A.W.P. Games", "Magic's 10 (ver. 16.55)", 0 )
479GAME( 1995, magic10a,  magic10, magic10a,  magic10,   magic10,   ROT0, "A.W.P. Games", "Magic's 10 (ver. 16.45)", 0 )
480GAME( 1997, magic102,  0,       magic102,  magic102,  magic102,  ROT0, "ABM Games",    "Magic's 10 2 (ver 1.1)", GAME_NOT_WORKING )
524GAME( 1995, magic10,   0,       magic10,   magic10,   magic10,   ROT0, "A.W.P. Games", "Magic's 10 (ver. 16.55)",  0 )
525GAME( 1995, magic10a,  magic10, magic10a,  magic10,   magic10,   ROT0, "A.W.P. Games", "Magic's 10 (ver. 16.45)",  0 )
526GAME( 1997, magic102,  0,       magic102,  magic102,  magic102,  ROT0, "ABM Games",    "Magic's 10 2 (ver 1.1)",   GAME_NOT_WORKING )
527GAME( 1997, suprpool,  0,       magic102,  magic102,  magic102,  ROT0, "ABM Games",    "Super Pool (9743 Rev.01)", GAME_NOT_WORKING )
src/mame/drivers/tmnt.c
r2762r2763
455455static int init_eeprom_count;
456456
457457
458static const struct EEPROM_interface eeprom_interface =
458static const eeprom_interface eeprom_intf =
459459{
460460   7,            /* address bits */
461461   8,            /* data bits */
r2762r2763
469469static NVRAM_HANDLER( eeprom )
470470{
471471   if (read_or_write)
472      EEPROM_save(file);
472      eeprom_save(file);
473473   else
474474   {
475      EEPROM_init(&eeprom_interface);
475      eeprom_init(&eeprom_intf);
476476
477477      if (file)
478478      {
479479         init_eeprom_count = 0;
480         EEPROM_load(file);
480         eeprom_load(file);
481481      }
482482      else
483483         init_eeprom_count = 10;
r2762r2763
507507
508508   /* bit 0 is EEPROM data */
509509   /* bit 1 is EEPROM ready */
510   res = EEPROM_read_bit() | input_port_read_indexed(machine,3);
510   res = eeprom_read_bit() | input_port_read_indexed(machine,3);
511511   return res;
512512}
513513
r2762r2763
520520   /* bit 1 is EEPROM ready */
521521   /* bit 2 is VBLANK (???) */
522522   /* bit 7 is service button */
523   res = EEPROM_read_bit() | input_port_read_indexed(machine,3);
523   res = eeprom_read_bit() | input_port_read_indexed(machine,3);
524524   if (init_eeprom_count)
525525   {
526526      init_eeprom_count--;
r2762r2763
539539   /* bit 1 is EEPROM ready */
540540   /* bit 2 is VBLANK (???) */
541541   /* bit 3 is service button */
542   res = EEPROM_read_bit() | input_port_read_indexed(machine,3);
542   res = eeprom_read_bit() | input_port_read_indexed(machine,3);
543543   if (init_eeprom_count)
544544   {
545545      init_eeprom_count--;
r2762r2763
556556      /* bit 0 is data */
557557      /* bit 1 is cs (active low) */
558558      /* bit 2 is clock (active high) */
559      EEPROM_write_bit(data & 0x01);
560      EEPROM_set_cs_line((data & 0x02) ? CLEAR_LINE : ASSERT_LINE);
561      EEPROM_set_clock_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE);
559      eeprom_write_bit(data & 0x01);
560      eeprom_set_cs_line((data & 0x02) ? CLEAR_LINE : ASSERT_LINE);
561      eeprom_set_clock_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE);
562562   }
563563}
564564
565565WRITE16_HANDLER( ssriders_eeprom_w );   /* in video/tmnt.c */
566566
567567
568static const struct EEPROM_interface thndrx2_eeprom_interface =
568static const eeprom_interface thndrx2_eeprom_interface =
569569{
570570   7,            /* address bits */
571571   8,            /* data bits */
r2762r2763
579579static NVRAM_HANDLER( thndrx2 )
580580{
581581   if (read_or_write)
582      EEPROM_save(file);
582      eeprom_save(file);
583583   else
584584   {
585      EEPROM_init(&thndrx2_eeprom_interface);
585      eeprom_init(&thndrx2_eeprom_interface);
586586
587587      if (file)
588588      {
589589         init_eeprom_count = 0;
590         EEPROM_load(file);
590         eeprom_load(file);
591591      }
592592      else
593593         init_eeprom_count = 10;
r2762r2763
616616   /* bit 1 is EEPROM ready */
617617   /* bit 3 is VBLANK (???) */
618618   /* bit 7 is service button */
619   res = (EEPROM_read_bit() << 8) | input_port_read_indexed(machine,1);
619   res = (eeprom_read_bit() << 8) | input_port_read_indexed(machine,1);
620620   toggle ^= 0x0800;
621621   return (res ^ toggle);
622622}
r2762r2763
630630      /* bit 0 is data */
631631      /* bit 1 is cs (active low) */
632632      /* bit 2 is clock (active high) */
633      EEPROM_write_bit(data & 0x01);
634      EEPROM_set_cs_line((data & 0x02) ? CLEAR_LINE : ASSERT_LINE);
635      EEPROM_set_clock_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE);
633      eeprom_write_bit(data & 0x01);
634      eeprom_set_cs_line((data & 0x02) ? CLEAR_LINE : ASSERT_LINE);
635      eeprom_set_clock_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE);
636636
637637      /* bit 5 triggers IRQ on sound cpu */
638638      if (last == 0 && (data & 0x20) != 0)
r2762r2763
663663{
664664   /* bit 8 is EEPROM data */
665665   /* bit 9 is EEPROM ready */
666   return (EEPROM_read_bit() << 8) | input_port_read_indexed(machine,1);
666   return (eeprom_read_bit() << 8) | input_port_read_indexed(machine,1);
667667}
668668
669669static WRITE16_HANDLER( prmrsocr_eeprom_w )
r2762r2763
678678      /* bit 8 is data */
679679      /* bit 9 is cs (active low) */
680680      /* bit 10 is clock (active high) */
681      EEPROM_write_bit(data & 0x0100);
682      EEPROM_set_cs_line((data & 0x0200) ? CLEAR_LINE : ASSERT_LINE);
683      EEPROM_set_clock_line((data & 0x0400) ? ASSERT_LINE : CLEAR_LINE);
681      eeprom_write_bit(data & 0x0100);
682      eeprom_set_cs_line((data & 0x0200) ? CLEAR_LINE : ASSERT_LINE);
683      eeprom_set_clock_line((data & 0x0400) ? ASSERT_LINE : CLEAR_LINE);
684684   }
685685}
686686
src/mame/drivers/jpmimpct.c
r2762r2763
55    driver by Phil Bennett
66
77    Games supported:
8        * Coronation Street Quiz Game
89        * Cluedo (3 sets)
910        * Hangman
1011        * Scrabble
1112        * Trivial Pursuit
1213
1314    ROMS wanted:
14        * Coronation Street
1515        * Snakes and Ladders
1616
1717    Known issues:
r2762r2763
735735   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME( "'1'" )
736736INPUT_PORTS_END
737737
738static INPUT_PORTS_START( coronatn )
739   IMPACT_STANDARD
740
741   PORT_START_TAG("COINS")
742   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_IMPULSE(1) PORT_NAME( "Coin: 1 pound" )
743   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_IMPULSE(1) PORT_NAME( "Coin: 50p" )
744   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN3 ) PORT_IMPULSE(1) PORT_NAME( "Coin: 20p" )
745   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_COIN4 ) PORT_IMPULSE(1) PORT_NAME( "Coin: 10p" )
746   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_COIN5 ) PORT_IMPULSE(1) PORT_NAME( "Token: 20" )
747   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_COIN6 ) PORT_IMPULSE(1) PORT_NAME( "Coin: 5p" )
748   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
749   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
750
751   PORT_START_TAG("SW2")
752   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME( "Ask Ken" )
753   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME( "Collect" )
754   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME( "'1'" )
755   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME( "'2'" )
756   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME( "'3'" )
757   PORT_BIT( 0xe0, IP_ACTIVE_LOW, IPT_UNUSED )
758INPUT_PORTS_END
759
738760static INPUT_PORTS_START( cluedo )
739761   IMPACT_STANDARD
740762
r2762r2763
966988   ROM_LOAD( "tp-snd.bin", 0x000000, 0x80000, CRC(7e2cb00a) SHA1(670ee5dd5c60313676b9271901b4df9e6ebd5955) )
967989ROM_END
968990
991ROM_START( scrabble )
992   ROM_REGION( 0x1000000, REGION_CPU1, 0 )
993   ROM_LOAD16_BYTE( "1562.bin", 0x000000, 0x080000, CRC(d7303b98) SHA1(46e8ed04c8fdc092b7d8910d3e3f6cc62f691646) )
994   ROM_LOAD16_BYTE( "1563.bin", 0x000001, 0x080000, CRC(77f61ba1) SHA1(276dc8b2c23880740309c456d4e4b2eae249cdde) )
995   ROM_FILL(                    0x100000, 0x100000, 0xff )
996
997   ROM_LOAD16_BYTE( "scra-q1.bin", 0xc00000, 0x080000, CRC(bcbc6328) SHA1(cbf8901e80e7bc1f82f6f7d4d5f6a658af98a6f9) )
998   ROM_LOAD16_BYTE( "scra-q2.bin", 0xc00001, 0x080000, CRC(c2147999) SHA1(f21dc0f3f4ba0d6304801bc492a759534447d747) )
999   ROM_LOAD16_BYTE( "scra-q3.bin", 0xd00000, 0x080000, CRC(622cebb9) SHA1(9b7c2204462d4912462bad6c4dcf096abe1381bb) )
1000   ROM_LOAD16_BYTE( "scra-q4.bin", 0xd00001, 0x080000, CRC(fd4b587b) SHA1(e29512a075fbc511271d6902c8900a9b0261355c) )
1001   ROM_LOAD16_BYTE( "scra-q5.bin", 0xe00000, 0x080000, CRC(fbc28978) SHA1(ce2549da858888d49677ec982ab3c21cf292939b) )
1002   ROM_LOAD16_BYTE( "scra-q6.bin", 0xe00001, 0x080000, CRC(8b792c9c) SHA1(9a5cc6c4d7e807cbabd174ab7454cdaa93dc3cec) )
1003   ROM_FILL(                       0xf00000, 0x100000, 0xff )
1004
1005   ROM_REGION16_LE( 0x200000, REGION_USER1, 0 )
1006   ROM_LOAD16_BYTE( "scra-g1.bin", 0x000000, 0x100000, CRC(04a17df9) SHA1(c215c90d8add3ff608c24aac242369874f6bf9d7) )
1007   ROM_LOAD16_BYTE( "scra-g2.bin", 0x000001, 0x100000, CRC(724375e6) SHA1(709211a2d7b86f4e83c94a37010fe61ef9a734de) )
1008
1009   ROM_REGION( 0x80000, REGION_SOUND1, 0 )
1010   ROM_LOAD( "scra-snd.bin", 0x000000, 0x80000, CRC(287759ef) SHA1(bd37500689b7b2fb4fbc65056e92486c0c00ff61) )
1011ROM_END
1012
9691013ROM_START( hngmnjpm )
9701014   ROM_REGION( 0x1000000, REGION_CPU1, 0 )
9711015   ROM_LOAD16_BYTE( "20264.bin", 0x000000, 0x080000, CRC(50074528) SHA1(8128b2270518af873df4b94d50c5c9849dda3e42) )
r2762r2763
9981042   ROM_LOAD( "mem-2.bin", 0x0000, 0x0157, CRC(92832445) SHA1(b6edcc6d4f721f0e91e9fcf322163db017afaee1) )
9991043ROM_END
10001044
1001ROM_START( scrabble )
1045ROM_START( coronatn )
10021046   ROM_REGION( 0x1000000, REGION_CPU1, 0 )
1003   ROM_LOAD16_BYTE( "1562.bin", 0x000000, 0x080000, CRC(d7303b98) SHA1(46e8ed04c8fdc092b7d8910d3e3f6cc62f691646) )
1004   ROM_LOAD16_BYTE( "1563.bin", 0x000001, 0x080000, CRC(77f61ba1) SHA1(276dc8b2c23880740309c456d4e4b2eae249cdde) )
1005   ROM_FILL(                    0x100000, 0x100000, 0xff )
1047   ROM_LOAD16_BYTE( "20824.bin", 0x000000, 0x080000, CRC(f5cc07cb) SHA1(45b83829ba9bd5f22c2978bbde9c0e25c476e719) )
1048   ROM_LOAD16_BYTE( "20825.bin", 0x000001, 0x080000, CRC(2e749edf) SHA1(12b24836a71085aef8ca1bc61e6671f8d6e1908c) )
1049   ROM_FILL(                     0x100000, 0x100000, 0xff )
10061050
1007   ROM_LOAD16_BYTE( "scra-q1.bin", 0xc00000, 0x080000, CRC(bcbc6328) SHA1(cbf8901e80e7bc1f82f6f7d4d5f6a658af98a6f9) )
1008   ROM_LOAD16_BYTE( "scra-q2.bin", 0xc00001, 0x080000, CRC(c2147999) SHA1(f21dc0f3f4ba0d6304801bc492a759534447d747) )
1009   ROM_LOAD16_BYTE( "scra-q3.bin", 0xd00000, 0x080000, CRC(622cebb9) SHA1(9b7c2204462d4912462bad6c4dcf096abe1381bb) )
1010   ROM_LOAD16_BYTE( "scra-q4.bin", 0xd00001, 0x080000, CRC(fd4b587b) SHA1(e29512a075fbc511271d6902c8900a9b0261355c) )
1011   ROM_LOAD16_BYTE( "scra-q5.bin", 0xe00000, 0x080000, CRC(fbc28978) SHA1(ce2549da858888d49677ec982ab3c21cf292939b) )
1012   ROM_LOAD16_BYTE( "scra-q6.bin", 0xe00001, 0x080000, CRC(8b792c9c) SHA1(9a5cc6c4d7e807cbabd174ab7454cdaa93dc3cec) )
1013   ROM_FILL(                       0xf00000, 0x100000, 0xff )
1051   ROM_LOAD16_BYTE( "cs-q1.bin", 0xc00000, 0x080000, CRC(beef496a) SHA1(6089ee8b0821d5b8cb8f724748888a0915083622) )
1052   ROM_LOAD16_BYTE( "cs-q2.bin", 0xc00001, 0x080000, CRC(16f88f36) SHA1(78c829d837cc09fdd1119ba73168d272843f7f50) )
1053   ROM_LOAD16_BYTE( "cs-q3.bin", 0xd00000, 0x080000, CRC(1d412b03) SHA1(2400fa776effeb2ab21234a6ecf183ed0cffa92e) )
1054   ROM_LOAD16_BYTE( "cs-q4.bin", 0xd00001, 0x080000, CRC(55c23ab9) SHA1(0eaa8c88315ef4544f1d1ef2fec2c6edc3589db3) )
1055   ROM_LOAD16_BYTE( "cs-q5.bin", 0xe00000, 0x080000, CRC(289f4db0) SHA1(8eca9df9e278bf77be4b2aad4c80ea6a1880fe96) )
1056   ROM_LOAD16_BYTE( "cs-q6.bin", 0xe00001, 0x080000, CRC(791d9d39) SHA1(44f3dcbfe8523118d52785844e103a480e8e13b5) )
10141057
10151058   ROM_REGION16_LE( 0x200000, REGION_USER1, 0 )
1016   ROM_LOAD16_BYTE( "scra-g1.bin", 0x000000, 0x100000, CRC(04a17df9) SHA1(c215c90d8add3ff608c24aac242369874f6bf9d7) )
1017   ROM_LOAD16_BYTE( "scra-g2.bin", 0x000001, 0x100000, CRC(724375e6) SHA1(709211a2d7b86f4e83c94a37010fe61ef9a734de) )
1059   ROM_LOAD16_BYTE( "cs-ag1.bin", 0x000000, 0x100000, CRC(7ce449cc) SHA1(408e1405c80e623ee120cea65760ca9a8554cc29) )
1060   ROM_LOAD16_BYTE( "cs-ag2.bin", 0x000001, 0x100000, CRC(7026df0c) SHA1(a000d72c06ad37879673324880fb0e715f55788e) )
10181061
10191062   ROM_REGION( 0x80000, REGION_SOUND1, 0 )
1020   ROM_LOAD( "scra-snd.bin", 0x000000, 0x80000, CRC(287759ef) SHA1(bd37500689b7b2fb4fbc65056e92486c0c00ff61) )
1063   ROM_LOAD( "cs-sound.bin", 0x000000, 0x80000, CRC(96ea4e9f) SHA1(a5443d893f38f3e279f2eb9f4500547e7b8efa37) )
10211064ROM_END
10221065
1023
10241066/*************************************
10251067 *
10261068 *  Game driver(s)
10271069 *
10281070 *************************************/
10291071
1030GAME( 1995, cluedo,   0,      jpmimpct, cluedo,   0, ROT0, "JPM", "Cluedo (prod. 2D)",          GAME_IMPERFECT_GRAPHICS | GAME_SUPPORTS_SAVE )
1031GAME( 1995, cluedo2c, cluedo, jpmimpct, cluedo,   0, ROT0, "JPM", "Cluedo (prod. 2C)",          GAME_IMPERFECT_GRAPHICS | GAME_SUPPORTS_SAVE )
1032GAME( 1995, cluedo2,  cluedo, jpmimpct, cluedo,   0, ROT0, "JPM", "Cluedo (prod. 2)",            GAME_IMPERFECT_GRAPHICS | GAME_SUPPORTS_SAVE )
1033GAME( 1996, trivialp, 0,      jpmimpct, trivialp, 0, ROT0, "JPM", "Trivial Pursuit (prod. 1D)", GAME_SUPPORTS_SAVE )
1034GAME( 1997, scrabble, 0,      jpmimpct, scrabble, 0, ROT0, "JPM", "Scrabble (rev. F)",          GAME_SUPPORTS_SAVE )
1035GAME( 1998, hngmnjpm, 0,      jpmimpct, hngmnjpm, 0, ROT0, "JPM", "Hangman (JPM)",              GAME_SUPPORTS_SAVE )
1072GAME( 1995, cluedo,   0,      jpmimpct, cluedo,   0, ROT0, "JPM", "Cluedo (prod. 2D)",           GAME_IMPERFECT_GRAPHICS | GAME_SUPPORTS_SAVE )
1073GAME( 1995, cluedo2c, cluedo, jpmimpct, cluedo,   0, ROT0, "JPM", "Cluedo (prod. 2C)",           GAME_IMPERFECT_GRAPHICS | GAME_SUPPORTS_SAVE )
1074GAME( 1995, cluedo2,  cluedo, jpmimpct, cluedo,   0, ROT0, "JPM", "Cluedo (prod. 2)",             GAME_IMPERFECT_GRAPHICS | GAME_SUPPORTS_SAVE )
1075GAME( 1996, trivialp, 0,      jpmimpct, trivialp, 0, ROT0, "JPM", "Trivial Pursuit (prod. 1D)",  GAME_SUPPORTS_SAVE )
1076GAME( 1997, scrabble, 0,      jpmimpct, scrabble, 0, ROT0, "JPM", "Scrabble (rev. F)",           GAME_SUPPORTS_SAVE )
1077GAME( 1998, hngmnjpm, 0,      jpmimpct, hngmnjpm, 0, ROT0, "JPM", "Hangman (JPM)",               GAME_SUPPORTS_SAVE )
1078GAME( 1999, coronatn, 0,      jpmimpct, coronatn, 0, ROT0, "JPM", "Coronation Street Quiz Game", GAME_SUPPORTS_SAVE )
src/mame/drivers/raiden2.c
r2762r2763
19271927static NVRAM_HANDLER( rdx_v33 )
19281928{
19291929   if (read_or_write)
1930      EEPROM_save(file);
1930      eeprom_save(file);
19311931   else
19321932   {
1933      EEPROM_init(&eeprom_interface_93C46);
1933      eeprom_init(&eeprom_interface_93C46);
19341934
1935      if (file) EEPROM_load(file);
1935      if (file) eeprom_load(file);
19361936      else
19371937      {
1938         EEPROM_set_data(r2_v33_default_eeprom_type1,32);
1938         eeprom_set_data(r2_v33_default_eeprom_type1,32);
19391939      }
19401940   }
19411941}
r2762r2763
19451945{
19461946   if (ACCESSING_BITS_0_7)
19471947   {
1948      EEPROM_set_clock_line((data & 0x10) ? ASSERT_LINE : CLEAR_LINE);
1949      EEPROM_write_bit(data & 0x20);
1950      EEPROM_set_cs_line((data & 0x08) ? CLEAR_LINE : ASSERT_LINE);
1948      eeprom_set_clock_line((data & 0x10) ? ASSERT_LINE : CLEAR_LINE);
1949      eeprom_write_bit(data & 0x20);
1950      eeprom_set_cs_line((data & 0x08) ? CLEAR_LINE : ASSERT_LINE);
19511951
19521952      if (data&0xc7) logerror("eeprom_w extra bits used %04x\n",data);
19531953   }
r2762r2763
19591959
19601960static READ16_HANDLER( rdx_v33_eeprom_r )
19611961{
1962   return input_port_read_indexed(machine, 0) | (EEPROM_read_bit()<<4);
1962   return input_port_read_indexed(machine, 0) | (eeprom_read_bit()<<4);
19631963}
19641964
19651965
src/mame/drivers/scramble.c
r2762r2763
17771777
17781778static const struct AY8910interface triplep_ay8910_interface =
17791779{
1780   0
1780   AY8910_LEGACY_OUTPUT,
1781   AY8910_DEFAULT_LOADS,
1782   NULL,
1783   NULL,
17811784};
17821785
17831786
r2762r2763
21352138   /* sound hardware */
21362139   MDRV_SOUND_MODIFY("8910.1")
21372140   MDRV_SOUND_CONFIG(triplep_ay8910_interface)
2138   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.33)
2141   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
21392142
21402143   MDRV_SOUND_REMOVE("8910.2")
21412144MACHINE_DRIVER_END
src/mame/drivers/taitojc.c
r2762r2763
428428      {
429429         if (ACCESSING_BITS_24_31)
430430         {
431            UINT32 data = EEPROM_read_bit() & 1;
431            UINT32 data = eeprom_read_bit() & 1;
432432            data |= input_port_read_indexed(machine, 0) & 0xfe;
433433            r |= data << 24;
434434         }
r2762r2763
484484      {
485485         if (ACCESSING_BITS_24_31)
486486         {
487            EEPROM_set_clock_line(((data >> 24) & 0x08) ? ASSERT_LINE : CLEAR_LINE);
488            EEPROM_write_bit(((data >> 24) & 0x04) ? 1 : 0);
489            EEPROM_set_cs_line(((data >> 24) & 0x10) ? CLEAR_LINE : ASSERT_LINE);
487            eeprom_set_clock_line(((data >> 24) & 0x08) ? ASSERT_LINE : CLEAR_LINE);
488            eeprom_write_bit(((data >> 24) & 0x04) ? 1 : 0);
489            eeprom_set_cs_line(((data >> 24) & 0x10) ? CLEAR_LINE : ASSERT_LINE);
490490         }
491491         return;
492492      }
src/mame/drivers/ampoker2.c
r2762r2763
77    Company:    Novomatic.
88    Year:       1990.
99
10    Original preliminary driver:   Curt Coder.
11    Rewrite and additional work:   Roberto Fresca, with a lot of help of Grull Osgo.
10    Driver by Roberto Fresca, with a lot of help of Grull Osgo.
11    Based on a preliminary work of Curt Coder.
1212
1313
1414    --- Supported Sets ---
1515
16    Old name | New name | Relation | Description
16    Set Name | Relation | Description
1717    --------------------------------------------
18    ampokr2b   ampoker2   parent     American Poker II.
19      ----     ampkr2b1   clone      American Poker II (bootleg, set 1).
20    ampokr2a   ampkr2b2   clone      American Poker II (bootleg, set 2).
21    ampoker2   ampkr2b3   clone      American Poker II (bootleg, set 3).
22    ampokr2c   pkrdewin   clone      Poker De Win.
23      ----     ampkr95    clone      American Poker 95.
24      ----     sigmapkr   parent     Sigma Poker.
25      ----     sigma2k    parent     Sigma Poker 2000.
18    ampoker2   parent     American Poker II.
19    ampkr2b1   clone      American Poker II (bootleg, set 1).
20    ampkr2b2   clone      American Poker II (bootleg, set 2).
21    ampkr2b3   clone      American Poker II (bootleg, set 3).
22    pkrdewin   clone      Poker De Win.
23    ampkr95    clone      American Poker 95.
24    sigmapkr   parent     Sigma Poker.
25    sigma2k    parent     Sigma Poker 2000.
2626
2727
2828*********************************************************************************
r2762r2763
102102*********************************************************************************
103103
104104
105    --- Technical Notes (in progress) ---
105    *** Technical Notes (in progress) ***
106106
107107
108108
r2762r2763
140140    --------------
141141
142142
143    - CPU:            1x Z80@4MHZ or compatible.
144    - Video:          TTL Logic Raster - 6 Mhz Dot Clock
145    - Osc:            6.000 Mhz Xtal.
143    - CPU:            1x Z80 @ 3 MHz.
144    - Video:          TTL Logic Raster - 6 MHz Dot Clock.
145    - Osc:            6.000 MHz Xtal.
146146    - RAM:            1x 6116 (4Kx8) Static RAM.
147147    - VRAM            2x 2016 (4Kx8) Static RAM.
148    - I/O:            8x 74251 ; 8x 74259 (Multiplex 8 Ports > 1 Bit).
149    - PRG ROMs:       1x 27c512 (64Kx8) EPROM or similar.
150    - GFX ROMs:       1x 27c128 (16Kx8) EPROM or similar.
148    - I/O:            8x 74LS251; 8x 74LS259 (Multiplex 8 Ports > 1 Bit).
149    - PRG ROMs:       1x 27C512 (64Kx8) EPROM or similar.
150    - GFX ROMs:       1x 27C128 (16Kx8) EPROM or similar.
151151    - Color PROM:     1x 82S147AN.
152152    - Sound:          1x AY-3-8910.
153    - Backup Battery: 1x 3.6 Volt Ni-CD.
154    - DIP Switches:   1x 8 Positions.
155    - Watchdog:       1x TL7705 (Texas Instruments) Refresh: 200 Ms.
153    - Backup Battery: 1x NI-CD 3.6 Volt.
154    - DIP Switches:   1x 8 switches.
155    - Watchdog:       1x TL7705 (Texas Instruments). Refresh: 200 Ms.
156156
157157
158158    Taiwanese PCB Layout:
r2762r2763
164164    | |______|  _________    _________   |______________|   _________   ________  __ |
165165    |          | 74LS74A |  | DM7407N |  _______________   | 74LS163 | | 74LS00 ||74||
166166    |          |_________|  |_________| |               |  |_________| |________||LS||
167    |  ___________________   _________  |    27C512     |   _________   ________ |08||
168    | |                   | | MC14020 | |_______________|  | 74LS163 | | 74LS157||__||
169    | |BATTERY NI-CD 3.6V | |_________|                    |_________| |________|    |
170    | |___________________|  ___________   _____________    _________   ________     |
171    |____                   | 74LS244   | |   74LS245   |  | 74LS163 | | 74LS157|    |
172         |                  |___________| |_____________|  |_________| |________|    |
167    | ____________________   _________  |    27C512     |   _________   ________ |08||
168    ||                    | | MC14020 | |_______________|  | 74LS163 | | 74LS157||__||
169    || NI-CD 3.6V BATTERY | |_________|                    |_________| |________|    |
170    ||____________________|  __________    _____________    _________   ________     |
171    |____                   | 74LS244  |  |   74LS245   |  | 74LS163 | | 74LS157|    |
172         |                  |__________|  |_____________|  |_________| |________|    |
173173     ____|                                                                           |
174174    |_28_                         ______________________    _________   ________     |
175175    |____                        |       - Z80A -       |  | 74LS74  | | 74LS157|    |
r2762r2763
180180    |____                    |___________|  |____________|  ________    __________   |
181181    |____                     ___________     __________   | 74LS02 |  |D4016CX-20|  |
182182    |____                    | TD62003AP |   | 74LS251P |  |________|  |__________|  |
183    |____                    |___________|   |__________|   __________________       |
184    |____                     ___________     __________   | AY-3-8910        |      |
185    |____                    | 74LS259N  |   | 74LS251P |  | KC89C72 / YM2149F|      |
186    |____                    |___________|   |__________|  |__________________|      |
187    |____                     ___________     __________    _________   __________   |
188    |____                    | 74LS259N  |   | 74LS251P |  | 82S147AN| | 74LS245  |  |
189    |____                    |___________|   |__________|  |_________| |__________|  |
183    |____                    |___________|   |__________|   ____________________     |
184    |____                     ___________     __________   |AY-3-8910 / YM2149F |    |
185    |____                    | 74LS259N  |   | 74LS251P |  |    or KC89C72      |    |
186    |____                    |___________|   |__________|  |____________________|    |
187    |____                     ___________     __________    __________   _________   |
188    |____                    | 74LS259N  |   | 74LS251P |  | 82S147AN | | 74LS245 |  |
189    |____                    |___________|   |__________|  |__________| |_________|  |
190190    |____                     ___________     __________    _________                |
191191    |____                    | 74LS259N  |   | 74LS251P |  | 74LS377 |               |
192192    |____                    |___________|   |__________|  |_________|               |
r2762r2763
206206
207207
208208
209    The main clock (6 MHz.) is generated with a crystal and 74LS04 inverters. This frequency is
210    used as the pixel clock, then is divided by 2 in a flip-flop (7474) and again to the video
211    stage like DOT/2 (the video hardware uses a 3 MHz clock synchronous to the pixel clock).
209212
210*********************************************************************************
213    Once again this 3 MHz clock signal is further divided by 2 through a flip-flop (7474) to get
214    the 1.5 MHz for the AY8910.
211215
216    The 4020 is clocked at 1.5 MHz. The Q10 output (pin 14) is approximately 1464.84 Hz. Using
217    an oscilloscope, I measured a value of 60 uS = 1538 Hz. We used a NMI period of 1536 Hz due
218    to a better binary composition (1024+512).
212219
213    Dumper Notes (old)
214    ------------------
220    Inputs/Ouputs are driven through 74LS251 and 74LS259 multiplexers. Each one handles 1 bit
221    from data bus, and there are many devices as addressed ports (8x 74LS251 and 8x 74LS259).
215222
216    American Poker
217    WB 5300 IS SAME AS Winbond WF19054 and YM2149F (AY891X?)
218    CPU TMPZ84C00AP OR LH0080A
219    XTAL 6.000
220    1 DIP x 8
221    RAM 6116
222    LH 5116D X2
223    Input ports are mapped to offsets 0xC410 through 0xC417. Output ports are mapped to 0xC4000
224    to 0xC407 and are polled/updated during NMI.
223225
224    ---------------------------------------------
226    These 1-bit controls are relative to buttons, keys, lights and counters. Other output ports
227    like watchdog or PSG (AY8910) are operated directly.
225228
226    Crystal 6.000 MHz
227    CPU         Sharp LH0080B Z80B-CPU 9241 1 B
228    Sound       OKI M5255 9203
229    RAM         2x TMM2015AP-15 (2048x8)
230    PAL         PAL?????16VE??? 022J????  P.M.REG
231    PROM        Philips N82S147AN PTH6708 9518nl
232    EPROM       Intel D27128-4 T8180760S
233                AMD AM27C512-205DC 916LADL
234    Chip?       Sanyo ?????
235229
236    7 unmarked chips
237230
231    Resistor Network
232    ----------------
233
234    The following diagram is related to taiwanese and argentine PCBs.
235
236
237    82S147AN
238   +---------+
239   |         |    470
240   | O1-Pin06|---/\/\/\----+---> BLUE
241   |         |    220      |
242   | O2-Pin07|---/\/\/\----+
243   |         |    1K
244   | O3-Pin08|---/\/\/\----+---> GREEN
245   |         |    470      |
246   | O4-Pin09|---/\/\/\----+
247   |         |    220      |
248   | O5-Pin11|---/\/\/\----+
249   |         |    1K
250   | O6-Pin12|---/\/\/\----+---> RED
251   |         |    470      |
252   | O7-Pin13|---/\/\/\----+
253   |         |    220      |
254   | O8-Pin14|---/\/\/\----+
255   |         |
256   +---------+
257
258
259   All colors are directly routed to the edge connector.
260   There are not pull-up or pull-down resistors.
261
262
238263*********************************************************************************
239264
240265
241266    --- DRIVER UPDATES ---
242267
243268
269    [2008-05-23]
270
271    - Reworked the color routines switching to resnet system.
272    - Added a resistor network diagram.
273    - Switch to pre-defined crystal value.
274    - Changed the WATCHDOG_TIME_INIT to be based on miliseconds instead of hertz.
275    - Other minor cleanup/fixes.
276    - Updated technical notes.
277
278
244279    [2007-11-15]
245280
246281    ******** REWRITE ********
r2762r2763
289324    - Analyze the write to port 0x21 after reset.
290325
291326
292
293327*********************************************************************************/
294328
295329
296#define MASTER_CLOCK   6000000    /* 6 Mhz */
330#define MASTER_CLOCK   XTAL_6MHz
297331
298332#include "driver.h"
299333#include "sound/ay8910.h"
r2762r2763
494528--------------------------------------------------*/
495529{
496530   /* watchdog sometimes stop to work */
497   if (( (data >> 3) & 0x01) == 0)      /* check for refresh value (0x08h) */
531
532   if (((data >> 3) & 0x01) == 0)      /* check for refresh value (0x08) */
498533   {
499534      watchdog_reset(machine);
500//      fprintf(stdout,"Watchdog\n");
535//      popmessage("%02x", data);
501536   }
537   else
538   {
539//      popmessage("%02x", data);
540   }
502541}
503542
504543
r2762r2763
538577ADDRESS_MAP_END
539578
540579
541
542580/*************************
543581*      Input ports       *
544582*************************/
r2762r2763
862900   MDRV_CPU_PROGRAM_MAP(ampoker2_map, 0)
863901   MDRV_CPU_IO_MAP(ampoker2_io_map, 0)
864902   MDRV_CPU_PERIODIC_INT(nmi_line_pulse, 1536)
865   MDRV_WATCHDOG_TIME_INIT(UINT64_ATTOTIME_IN_HZ( 5 ))   /* 200 ms, measured */
866   //MDRV_WATCHDOG_VBLANK_INIT(8)
903   MDRV_WATCHDOG_TIME_INIT(UINT64_ATTOTIME_IN_MSEC(200))   /* 200 ms, measured */
867904
868905   MDRV_NVRAM_HANDLER(generic_0fill)
869906
r2762r2763
886923
887924   /* sound hardware */
888925   MDRV_SPEAKER_STANDARD_MONO("mono")
889   MDRV_SOUND_ADD(AY8910,MASTER_CLOCK/4)   /* 1.5 MHz, verified against the real thing */
926   MDRV_SOUND_ADD(AY8910,MASTER_CLOCK/4)   /* 1.5 MHz, measured */
890927   MDRV_SOUND_CONFIG(ay8910_interface)
891928   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.30)
892929MACHINE_DRIVER_END
src/mame/drivers/playmark.c
r2762r2763
9797
9898***************************************************************************/
9999
100static const struct EEPROM_interface eeprom_interface =
100static const eeprom_interface eeprom_intf =
101101{
102102   6,            /* address bits */
103103   16,            /* data bits */
r2762r2763
114114{
115115   if (read_or_write)
116116   {
117      EEPROM_save(file);
117      eeprom_save(file);
118118   }
119119   else
120120   {
121      EEPROM_init(&eeprom_interface);
121      eeprom_init(&eeprom_intf);
122122
123123      if (file)
124         EEPROM_load(file);
124         eeprom_load(file);
125125      else
126126      {
127127         UINT8 init[128];
128128         memset(init,0,128);
129         EEPROM_set_data(init,128);
129         eeprom_set_data(init,128);
130130      }
131131   }
132132}
r2762r2763
135135{
136136   int bit;
137137
138   bit = EEPROM_read_bit() << 7;
138   bit = eeprom_read_bit() << 7;
139139
140140   return (input_port_read_indexed(machine, 0) & 0x7f) | bit;
141141}
r2762r2763
144144{
145145   int bit;
146146
147   bit = EEPROM_read_bit() << 7;
147   bit = eeprom_read_bit() << 7;
148148
149149   return (input_port_read_indexed(machine, 2) & 0x7f) | bit;
150150}
r2762r2763
160160      coin_counter_w(3,data & 0x08);
161161
162162      /* bits 5-7 control EEPROM */
163      EEPROM_set_cs_line((data & 0x20) ? CLEAR_LINE : ASSERT_LINE);
164      EEPROM_write_bit(data & 0x80);
165      EEPROM_set_clock_line((data & 0x40) ? CLEAR_LINE : ASSERT_LINE);
163      eeprom_set_cs_line((data & 0x20) ? CLEAR_LINE : ASSERT_LINE);
164      eeprom_write_bit(data & 0x80);
165      eeprom_set_clock_line((data & 0x40) ? CLEAR_LINE : ASSERT_LINE);
166166   }
167167}
168168
r2762r2763
172172   {
173173      coin_counter_w(0,data & 0x20);
174174
175      EEPROM_set_cs_line((data & 1) ? CLEAR_LINE : ASSERT_LINE);
176      EEPROM_write_bit(data & 4);
177      EEPROM_set_clock_line((data & 2) ? ASSERT_LINE : CLEAR_LINE );
175      eeprom_set_cs_line((data & 1) ? CLEAR_LINE : ASSERT_LINE);
176      eeprom_write_bit(data & 4);
177      eeprom_set_clock_line((data & 2) ? ASSERT_LINE : CLEAR_LINE );
178178   }
179179}
180180
src/mame/drivers/esd16.c
r2762r2763
131131{
132132   if (ACCESSING_BITS_8_15)
133133   {
134      return ((EEPROM_read_bit() & 0x01) << 15);
134      return ((eeprom_read_bit() & 0x01) << 15);
135135   }
136136
137137//  logerror("(0x%06x) unk EEPROM read: %04x\n", activecpu_get_pc(), mem_mask);
r2762r2763
143143   if (ACCESSING_BITS_8_15)
144144   {
145145      // data line
146      EEPROM_write_bit((data & 0x0400) >> 6);
146      eeprom_write_bit((data & 0x0400) >> 6);
147147
148148      // clock line asserted.
149      EEPROM_set_clock_line((data & 0x0200) ? ASSERT_LINE : CLEAR_LINE );
149      eeprom_set_clock_line((data & 0x0200) ? ASSERT_LINE : CLEAR_LINE );
150150
151151      // reset line asserted: reset.
152      EEPROM_set_cs_line((data & 0x0100) ? CLEAR_LINE : ASSERT_LINE );
152      eeprom_set_cs_line((data & 0x0100) ? CLEAR_LINE : ASSERT_LINE );
153153   }
154154
155155//  logerror("(0x%06x) Unk EEPROM write: %04x %04x\n", activecpu_get_pc(), data, mem_mask);
src/mame/drivers/model3.c
r2762r2763
917917/*****************************************************************************/
918918
919919/* this is a 93C46 but with reset delay that is needed by Lost World */
920static const struct EEPROM_interface eeprom_interface =
920static const eeprom_interface eeprom_intf =
921921{
922922   6,            /* address bits */
923923   16,            /* data bits */
r2762r2763
933933static void eeprom_handler(mame_file *file,int read_or_write)
934934{
935935   if (read_or_write)
936      EEPROM_save(file);
936      eeprom_save(file);
937937   else
938938   {
939      EEPROM_init(&eeprom_interface);
940      if (file)   EEPROM_load(file);
939      eeprom_init(&eeprom_intf);
940      if (file)   eeprom_load(file);
941941   }
942942}
943943
r2762r2763
10571057         else if (ACCESSING_BITS_24_31)
10581058         {
10591059            if(model3_controls_bank & 0x1) {
1060               eeprom_bit = EEPROM_read_bit() << 5;
1060               eeprom_bit = eeprom_read_bit() << 5;
10611061               return ((input_port_read_indexed(machine, 1) & ~0x20) | eeprom_bit) << 24;
10621062            }
10631063            else {
r2762r2763
11271127         if (ACCESSING_BITS_56_63)
11281128         {
11291129            int reg = (data >> 56) & 0xff;
1130            EEPROM_write_bit((reg & 0x20) ? 1 : 0);
1131            EEPROM_set_clock_line((reg & 0x80) ? ASSERT_LINE : CLEAR_LINE);
1132            EEPROM_set_cs_line((reg & 0x40) ? CLEAR_LINE : ASSERT_LINE);
1130            eeprom_write_bit((reg & 0x20) ? 1 : 0);
1131            eeprom_set_clock_line((reg & 0x80) ? ASSERT_LINE : CLEAR_LINE);
1132            eeprom_set_cs_line((reg & 0x40) ? CLEAR_LINE : ASSERT_LINE);
11331133            model3_controls_bank = reg & 0xff;
11341134         }
11351135         return;
src/mame/drivers/namcos21.c
r2762r2763
10871087static ADDRESS_MAP_START( namcos21_68k_master, ADDRESS_SPACE_PROGRAM, 16 )
10881088   AM_RANGE(0x000000, 0x0fffff) AM_READ(SMH_ROM) AM_WRITE(SMH_ROM)
10891089   AM_RANGE(0x100000, 0x10ffff) AM_READ(SMH_RAM) AM_WRITE(SMH_RAM) /* private work RAM */
1090   AM_RANGE(0x180000, 0x183fff) AM_READ(NAMCOS2_68K_EEPROM_R) AM_WRITE(NAMCOS2_68K_EEPROM_W)// AM_BASE(&namcos2_eeprom) AM_SIZE(&namcos2_eeprom_size)
1090   AM_RANGE(0x180000, 0x183fff) AM_READ(NAMCOS2_68K_eeprom_R) AM_WRITE(NAMCOS2_68K_eeprom_W)// AM_BASE(&namcos2_eeprom) AM_SIZE(&namcos2_eeprom_size)
10911091   AM_RANGE(0x1c0000, 0x1fffff) AM_READ(namcos2_68k_master_C148_r) AM_WRITE(namcos2_68k_master_C148_w)
10921092ADDRESS_MAP_END
10931093
r2762r2763
13331333static ADDRESS_MAP_START( am_master_winrun, ADDRESS_SPACE_PROGRAM, 16 )
13341334   AM_RANGE(0x000000, 0x03ffff) AM_READ(SMH_ROM) AM_WRITE(SMH_ROM)
13351335   AM_RANGE(0x100000, 0x10ffff) AM_READ(SMH_RAM) AM_WRITE(SMH_RAM) /* work RAM */
1336   AM_RANGE(0x180000, 0x183fff) AM_READ(NAMCOS2_68K_EEPROM_R) AM_WRITE(NAMCOS2_68K_EEPROM_W)// AM_BASE(&namcos2_eeprom) AM_SIZE(&namcos2_eeprom_size)
1336   AM_RANGE(0x180000, 0x183fff) AM_READ(NAMCOS2_68K_eeprom_R) AM_WRITE(NAMCOS2_68K_eeprom_W)// AM_BASE(&namcos2_eeprom) AM_SIZE(&namcos2_eeprom_size)
13371337   AM_RANGE(0x1c0000, 0x1fffff) AM_READ(namcos2_68k_master_C148_r) AM_WRITE(namcos2_68k_master_C148_w)
13381338   AM_RANGE(0x250000, 0x25ffff) AM_READ(SMH_RAM) AM_WRITE(SMH_RAM) AM_BASE( &winrun_polydata )
13391339   AM_RANGE(0x260000, 0x26ffff) AM_READ(SMH_RAM) AM_WRITE(SMH_RAM) /* unused? */
r2762r2763
14481448static ADDRESS_MAP_START( driveyes_68k_master, ADDRESS_SPACE_PROGRAM, 16 )
14491449   AM_RANGE(0x000000, 0x03ffff) AM_READ(SMH_ROM) AM_WRITE(SMH_ROM)
14501450   AM_RANGE(0x100000, 0x10ffff) AM_READ(SMH_RAM) AM_WRITE(SMH_RAM) /* private work RAM */
1451   AM_RANGE(0x180000, 0x183fff) AM_READ(NAMCOS2_68K_EEPROM_R) AM_WRITE(NAMCOS2_68K_EEPROM_W)// AM_BASE(&namcos2_eeprom) AM_SIZE(&namcos2_eeprom_size)
1451   AM_RANGE(0x180000, 0x183fff) AM_READ(NAMCOS2_68K_eeprom_R) AM_WRITE(NAMCOS2_68K_eeprom_W)// AM_BASE(&namcos2_eeprom) AM_SIZE(&namcos2_eeprom_size)
14521452   AM_RANGE(0x1c0000, 0x1fffff) AM_READ(namcos2_68k_master_C148_r) AM_WRITE(namcos2_68k_master_C148_w)
14531453ADDRESS_MAP_END
14541454
src/mame/drivers/kinst.c
r2762r2763
667667 *
668668 *************************************/
669669
670static const struct mips3_config config =
670static const mips3_config config =
671671{
672672   16384,            /* code cache size */
673673   16384            /* data cache size */
src/mame/drivers/cbasebal.c
r2762r2763
9393
9494***************************************************************************/
9595
96static const struct EEPROM_interface eeprom_interface =
96static const eeprom_interface eeprom_intf =
9797{
9898   6,      /* address bits */
9999   16,      /* data bits */
r2762r2763
106106static NVRAM_HANDLER( cbasebal )
107107{
108108   if (read_or_write)
109      EEPROM_save(file);
109      eeprom_save(file);
110110   else
111111   {
112      EEPROM_init(&eeprom_interface);
112      eeprom_init(&eeprom_intf);
113113
114114      if (file)
115         EEPROM_load(file);
115         eeprom_load(file);
116116   }
117117}
118118
119static READ8_HANDLER( eeprom_r )
120{
121   int bit;
122
123   bit = EEPROM_read_bit() << 7;
124
125   return (input_port_read_indexed(machine, 2) & 0x7f) | bit;
126}
127
128119static WRITE8_HANDLER( eeprom_cs_w )
129120{
130   EEPROM_set_cs_line(data ? CLEAR_LINE : ASSERT_LINE);
121   eeprom_set_cs_line(data ? CLEAR_LINE : ASSERT_LINE);
131122}
132123
133124static WRITE8_HANDLER( eeprom_clock_w )
134125{
135   EEPROM_set_clock_line(data ? CLEAR_LINE : ASSERT_LINE);
126   eeprom_set_clock_line(data ? CLEAR_LINE : ASSERT_LINE);
136127}
137128
138129static WRITE8_HANDLER( eeprom_serial_w )
139130{
140   EEPROM_write_bit(data);
131   eeprom_write_bit(data);
141132}
142133
143134
r2762r2763
163154   AM_RANGE(0x0a, 0x0b) AM_WRITE(cbasebal_scrolly_w)
164155   AM_RANGE(0x10, 0x10) AM_READ(input_port_0_r)
165156   AM_RANGE(0x11, 0x11) AM_READ(input_port_1_r)
166   AM_RANGE(0x12, 0x12) AM_READ(eeprom_r)
157   AM_RANGE(0x12, 0x12) AM_READ(input_port_2_r)
167158   AM_RANGE(0x13, 0x13) AM_WRITE(cbasebal_gfxctrl_w)
168159   AM_RANGE(0x14, 0x14) AM_WRITE(cbasebal_coinctrl_w)
169160ADDRESS_MAP_END
r2762r2763
198189   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_START2 )
199190   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START1 )
200191   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_VBLANK )      /* ? */
201   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_UNKNOWN )   /* EEPROM data */
192   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(eeprom_bit_r, NULL)
202193INPUT_PORTS_END
203194
204195
src/mame/drivers/xexex.c
r2762r2763
8585static emu_timer *dmadelay_timer;
8686
8787
88static const struct EEPROM_interface eeprom_interface =
88static const eeprom_interface eeprom_intf =
8989{
9090   7,            /* address bits */
9191   8,            /* data bits */
r2762r2763
9999static NVRAM_HANDLER( xexex )
100100{
101101   if (read_or_write)
102      EEPROM_save(file);
102      eeprom_save(file);
103103   else
104104   {
105      EEPROM_init(&eeprom_interface);
105      eeprom_init(&eeprom_intf);
106106
107107      if (file)
108108      {
109109         init_eeprom_count = 0;
110         EEPROM_load(file);
110         eeprom_load(file);
111111      }
112112      else
113113         init_eeprom_count = 10;
r2762r2763
207207   /* bit 0 is EEPROM data */
208208   /* bit 1 is EEPROM ready */
209209   /* bit 3 is service button */
210   res = EEPROM_read_bit() | input_port_read_indexed(machine,1);
210   res = eeprom_read_bit() | input_port_read_indexed(machine,1);
211211
212212   if (init_eeprom_count)
213213   {
r2762r2763
227227   /* bit 6  is enable irq 5 */
228228   /* bit 11 is watchdog */
229229
230   EEPROM_write_bit(cur_control2 & 0x01);
231   EEPROM_set_cs_line((cur_control2 & 0x02) ? CLEAR_LINE : ASSERT_LINE);
232   EEPROM_set_clock_line((cur_control2 & 0x04) ? ASSERT_LINE : CLEAR_LINE);
230   eeprom_write_bit(cur_control2 & 0x01);
231   eeprom_set_cs_line((cur_control2 & 0x02) ? CLEAR_LINE : ASSERT_LINE);
232   eeprom_set_clock_line((cur_control2 & 0x04) ? ASSERT_LINE : CLEAR_LINE);
233233
234234   /* bit 8 = enable sprite ROM reading */
235235   K053246_set_OBJCHA_line((cur_control2 & 0x0100) ? ASSERT_LINE : CLEAR_LINE);
src/mame/drivers/konamigq.c
r2762r2763
107107{
108108   if( read_or_write )
109109   {
110      EEPROM_save( file );
110      eeprom_save( file );
111111   }
112112   else
113113   {
114      EEPROM_init( &eeprom_interface_93C46 );
114      eeprom_init( &eeprom_interface_93C46 );
115115      if( file )
116116      {
117         EEPROM_load( file );
117         eeprom_load( file );
118118      }
119119      else
120120      {
r2762r2763
130130            0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
131131         };
132132
133         EEPROM_set_data( def_eeprom, 128 );
133         eeprom_set_data( def_eeprom, 128 );
134134      }
135135   }
136136}
137137
138138static WRITE32_HANDLER( eeprom_w )
139139{
140   EEPROM_write_bit( ( data & 0x01 ) ? 1 : 0 );
141   EEPROM_set_clock_line( ( data & 0x04 ) ? ASSERT_LINE : CLEAR_LINE );
142   EEPROM_set_cs_line( ( data & 0x02 ) ? CLEAR_LINE : ASSERT_LINE );
140   eeprom_write_bit( ( data & 0x01 ) ? 1 : 0 );
141   eeprom_set_clock_line( ( data & 0x04 ) ? ASSERT_LINE : CLEAR_LINE );
142   eeprom_set_cs_line( ( data & 0x02 ) ? CLEAR_LINE : ASSERT_LINE );
143143   cpunum_set_input_line(machine, 1, INPUT_LINE_RESET, ( data & 0x40 ) ? CLEAR_LINE : ASSERT_LINE );
144144}
145145
146static CUSTOM_INPUT( eeprom_bit_r )
147{
148   return EEPROM_read_bit();
149}
150
151146/* PCM RAM */
152147
153148static UINT8 *m_p_n_pcmram;
src/mame/drivers/toaplan2.c
r2762r2763
12951295
12961296
12971297
1298static const struct EEPROM_interface eeprom_interface_93C66 =
1298static const eeprom_interface eeprom_interface_93C66 =
12991299{
13001300   /* Pin 6 of the 93C66 is connected to Gnd!
13011301       So it's configured for 512 bytes */
r2762r2763
13171317   /* Pin 6 of 93C66 is connected to Gnd! */
13181318
13191319   if (read_or_write)
1320      EEPROM_save(file);
1320      eeprom_save(file);
13211321   else
13221322   {
1323      EEPROM_init(&eeprom_interface_93C66);
1323      eeprom_init(&eeprom_interface_93C66);
13241324
1325      if (file) EEPROM_load(file);
1325      if (file) eeprom_load(file);
13261326      else
13271327      {
13281328         if (bbakraid_unlimited_ver == 1)
1329            EEPROM_set_data(bbakraid_unlimited_nvram, sizeof(bbakraid_unlimited_nvram));
1329            eeprom_set_data(bbakraid_unlimited_nvram, sizeof(bbakraid_unlimited_nvram));
13301330      }
13311331   }
13321332}
r2762r2763
13411341    */
13421342
13431343   int data;
1344   data  = ((EEPROM_read_bit() & 0x01) << 4);
1344   data  = ((eeprom_read_bit() & 0x01) << 4);
13451345   data |= ((raizing_Z80_busreq >> 4) & 0x01);   /* Loop BUSRQ to BUSAK */
13461346
13471347   return data;
r2762r2763
13561356   if ( ACCESSING_BITS_0_7 )
13571357   {
13581358      // chip select
1359      EEPROM_set_cs_line((data & 0x01) ? CLEAR_LINE : ASSERT_LINE );
1359      eeprom_set_cs_line((data & 0x01) ? CLEAR_LINE : ASSERT_LINE );
13601360
13611361      // latch the bit
1362      EEPROM_write_bit( (data & 0x04) >> 2 );
1362      eeprom_write_bit( (data & 0x04) >> 2 );
13631363
13641364      // clock line asserted: write latch or select next bit to read
1365      EEPROM_set_clock_line((data & 0x08) ? ASSERT_LINE : CLEAR_LINE );
1365      eeprom_set_clock_line((data & 0x08) ? ASSERT_LINE : CLEAR_LINE );
13661366   }
13671367   raizing_Z80_busreq = data & 0x10;   /* see bbakraid_nvram_r above */
13681368}
src/mame/drivers/seattle.c
r2762r2763
24422442 *
24432443 *************************************/
24442444
2445static const struct mips3_config config =
2445static const mips3_config config =
24462446{
24472447   16384,      /* code cache size */
24482448   16384,      /* data cache size */
src/mame/drivers/portrait.c
r2762r2763
276276   /* sound hardware */
277277   MDRV_SPEAKER_STANDARD_MONO("mono")
278278
279   MDRV_SOUND_ADD(TMS5220, 640000) // actually it uses a tms5200 chip
279   MDRV_SOUND_ADD(TMS5200, 640000)
280280   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
281281MACHINE_DRIVER_END
282282
src/mame/drivers/tmaster.c
r2762r2763
457457
458458// NVRAM
459459
460static const struct EEPROM_interface galgames_eeprom_interface =
460static const eeprom_interface galgames_eeprom_interface =
461461{
462462   10,               // address bits 10
463463   8,               // data bits    8
r2762r2763
472472
473473static READ16_HANDLER( galgames_eeprom_r )
474474{
475   return EEPROM_read_bit() ? 0x80 : 0x00;
475   return eeprom_read_bit() ? 0x80 : 0x00;
476476}
477477
478478static WRITE16_HANDLER( galgames_eeprom_w )
r2762r2763
483483   if ( ACCESSING_BITS_0_7 )
484484   {
485485      // latch the bit
486      EEPROM_write_bit(data & 0x0001);
486      eeprom_write_bit(data & 0x0001);
487487
488488      // clock line asserted: write latch or select next bit to read
489      EEPROM_set_clock_line((data & 0x0002) ? ASSERT_LINE : CLEAR_LINE );
489      eeprom_set_clock_line((data & 0x0002) ? ASSERT_LINE : CLEAR_LINE );
490490   }
491491}
492492
493493static NVRAM_HANDLER( galgames )
494494{
495495   if (read_or_write)
496      EEPROM_save(file);
496      eeprom_save(file);
497497   else
498498   {
499      EEPROM_init(&galgames_eeprom_interface);
500      if (file)   EEPROM_load(file);
499      eeprom_init(&galgames_eeprom_interface);
500      if (file)   eeprom_load(file);
501501   }
502502}
503503
r2762r2763
548548
549549   // 7 resets the eeprom
550550   if (ACCESSING_BITS_0_7)
551      EEPROM_set_cs_line(((data&0xff) == 0x07) ? ASSERT_LINE : CLEAR_LINE);
551      eeprom_set_cs_line(((data&0xff) == 0x07) ? ASSERT_LINE : CLEAR_LINE);
552552}
553553
554554static READ16_HANDLER( galgames_cart_clock_r )
src/mame/drivers/namcos22.c
r2762r2763
141141 *  VIDEO 2D, 3D, 4D (RGB Gamma LUT ROM)
142142 *
143143 *  RR1.GAM (for Ridge Racer 1/2, Rave Racer)
144 **********************************************************************************************************
145 *
146 * Namco Super System 22 Hardware Overview (last updated 22-01-2006 at 1:30am)
147 * ---------------------------------------
148 *
149 * Note! This document will be updated from time to time when more dumps are available.
150 *
151 * This document covers all the known Namco Super System 22 games, including....
152 * Air Combat 22    (C) Namco, 1995
153 * Alpine Racer 1   (C) Namco, 1995
154 * Alpine Racer 2   (C) Namco, 1996
155 * Alpine Surfer    (C) Namco, 1996
156 * !Aqua Jet        (C) Namco, 1996
157 * *Armidillo Racing(C) Namco, 1997
158 * Cyber Cycles     (C) Namco, 1995
159 * *Dirt Dash       (C) Namco, 1995
160 * Prop Cycle       (C) Namco, 1996
161 * Time Crisis      (C) Namco, 1995
162 * !Tokyo Wars      (C) Namco, 1996
163 *
164 * ! - denotes secured but not dumped yet.
165 * * - denotes not dumped yet. If you can help with the remaining undumped SS22 games,
166 *     please contact http://www.mameworld.net/gurudumps/
167 *
168 * The Namco Super System 22 System comprises 4 PCB's plugged into a motherboard. The motherboard contains only
169 * some slots and connectors. The 4 PCB's are housed in a metal box with a large fan on the side. The fan mostly cools
170 * the video board as these are known to run hot and commonly fail, especially now the system is 10 years+ old.
171 *
172 * CPU PCB   - There are three known revisions of this PCB. Two of them have an extra connector for an
173 *             auxillary PCB. One of the others doesnt have that connector but they are otherwise identical.
174 *             All PCBs can be swapped to any game and it will work. However, ALL required IC's must be swapped.
175 *             This includes Program ROM PCB, socketed Keycus IC, socketed DATA ROM and socketed WAVE ROM(s).
176 *             On most games the EEPROM will re-init itself on bootup. On the others, the EEPROM can re-init itself
177 *             to defaults by holding down SERVICE + TEST on power-up. All games are swappable to ANY CPU PCB and will
178 *             run ok (all dumped games have been swapped/tested and work fine)
179 * DSP PCB   - There is only 1 revision of this PCB. All games use the exact same PCB. The DSP PCB can be swapped to
180 *             any other game and works fine (all dumped games tested)
181 * MROM PCB  - The PCB is identical for each game, but the ROMs on it and the number of ROMs vary per game. (a few of
182 *             the dumped games have had their surface mounted ROMs swapped to other PCBs and worked fine)
183 * VIDEO PCB - There are three known revisions of this PCB. They're mostly identical apart from some component shuffling
184 *             and in the earlier versions (A & B), an Altera FPGA chip is used instead of a Namco custom chip.
185 *             All revisions of the Video PCBs are swappable and fully compatible with any SS22 game.
186 * MOTHER PCB- There are probably 3 revisions of this PCB, but only the original revision and (C) are documented here.
187 *             The differences are very minor, just the amount of connectors on the PCB. The Mother PCB is swappable to
188 *             any game as long as the required connectors for that game are present on the PCB. (all dumped games tested
189 *             and worked fine)
190 *
191 * Each game has a 2 or 3 digit letter code assigned to it. Then a number 1 or 2, Then a Rev. A/B/C/D which denotes the
192 * software revision.
193 * The 1 denotes a Japanese version. 2 denotes a World version. So far there are no other numbers used other than 1 or 2.
194 * For World versions, usually only the main program uses a '2', the rest of the ROM labels use the Japanese region code '1'.
195 * There is one exception so far. The World version of Alpine Racer 2, which uses a World version DATA ROM, and also one
196 * of the WAVE ROMs is a World version, but one Japanese WAVE ROM is also used.
197 * See the CPU PCB, Program ROM Daughterboard and MROM PCB texts below for more details on ROM usage.
198 *
199 * CPU PCB
200 * -------
201 * 1st Revision
202 * SYSTEM SUPER22 CPU PCB 8646960102 (8646970102)
203 *
204 * 2nd Revision
205 * SYSTEM SUPER22 CPU(B) PCB 8646962600 (8646972600)
206 *
207 * 3rd Revision
208 * SYSTEM SUPER22 CPU(B) PCB 8646962600 (8646972601) <-- very minor?
209 * |--------------------------------------------------------------|
210 * |      J6                         JC410               3771     |
211 * |  N341256(x4)                                           DSW(4)|
212 * |                               |-------|                     |--|
213 * |                               |MC68EC |                     |  |
214 * |                               |020FG25|                     |  |
215 * |   *1                          |-------|                     |  |
216 * |           DSW(8)        SS22C2         |------|             |  |
217 * |                                        | C383 |             |  |
218 * |   CAT28C64    KEYCUS    SS22C1         |      |             |  |
219 * |                                        |------|             |  |
220 * |              |-------|                                      |  |
221 * |     N341256  |       |                 |------|             |  |
222 * | *3  N341256  | C405  |                 | 139  |             |--|
223 * |              |       |       CY7C182   |      |              |
224 * | *2           |-------|                 |------|              |
225 * |                                                             |--|
226 * |        40.000MHz                         137                |  |
227 * |                                                             |  |
228 * |              DATA.8K         JP1        49.152MHz           |  |
229 * |     |------|                 |-------|             4558     |  |
230 * |     | C352 |      JP2        |M37710 |                      |  |
231 * |     |      |                 |S4BFP  |                      |  |
232 * |     |------|                 |-------|                      |  |
233 * |LED(x8)                                                      |  |
234 * |        J11         SS22C4                MB87078            |  |
235 * |      WAVEA.2L                                      4558     |--|
236 * | JP3                                                          |
237 * |      WAVEB.1L                LC78815M      LC78815M          |
238 * |--------------------------------------------------------------|
239 * (logic chips omitted from the PCB layout)
240 *
241 * Notes:
242 *       J6           : Custom Namco connector for plug-in program ROM PCB
243 *       J11          : Custom Namco connector for optional plug-in WAVE ROM PCB (holds some SOP44 MASKROMs)
244 *       JC410        : Custom Namco connector for Optional plug-in Auxillary PCB (e.g. Gun Control PCB used in Time Crisis
245 *                      etc)
246 *                      The connector is populated only on the 2nd revision CPU (B) PCB 8646962600 (8646972600)
247 *                      and 3rd Revision CPU (B) PCB 8646962600 (8646972601)
248 *       JP1          : Jumper for configuration of M37710 (tied to pins 26 & 27 of M37710). Set to 1-2
249 *       JP2          : Jumper for configuration of DATA ROM. Set to 1-2 (labelled '4M'), alt. setting 2-3 (labelled '1M/2M')
250 *       JP3          : Jumper for configuration of WAVE ROM. Set to 2-3 (labelled '42P32M'), alt. setting 1-2
251 *                      (labelled 'OTHER'). 'OTHER' is used when the WAVE ROMs are 16MBit. If the WAVE ROMs are 32MBit
252 *                      (i.e. JP3 = 2-3), they're programmed in BYTE mode.
253 *       M37710       : Mitsubishi M37710 CPU. Used on SS22 as the sound CPU. Does not have internal ROM (QFP80)
254 *       MB87078      : Fujitsu MB87078 electronic volume control IC (SOIC24)
255 *       4558         : Op Amp (SOIC8)
256 *       LC78815M     : Sanyo LC78815M 2-channel 16-bit D/A converter (x2, SOIC20)
257 *       3771         : Fujitsu MB3771 master reset IC (SOIC8)
258 *       DSW(4)       : 4 position DIP Switch (1,2,3 are ON, 4 is OFF)
259 *       DSW(8)       : 8 position DIP Switch (All OFF)
260 *       N341256      : NKK N341256 32k x8 SRAM (x6, SOJ28)
261 *       CY7C182      : Cypress 8k x9 SRAM (SOJ28)
262 *       MC68EC020FG25: Main CPU, Motorola 68EC020FG25 (QFP100), running at 24.576MHz. Clock source is Namco
263 *                      custom clock divider 137. 68EC020 clock = Master Clock of 49.152MHz / 2
264 *       C383         : Namco custom C383 (QFP100)
265 *       139          : Namco custom 139 Serial Controller Interface IC (QFP64). NOTE! On some PCB's this chip
266 *                      has been replaced by a custom C422 chip, though the PCB number is the same. Which means probably
267 *                      the function of this chip matches 139
268 *       137          : Namco custom clock divider IC (DIP28)
269 *       C405         : Namco custom C405 (QFP176)
270 *       C352         : Namco custom C352 PCM sound chip (QFP100)
271 *       SS22C1       : PALCE 22V10H (PLCC28, labelled 'SS22C1')
272 *       SS22C2       : PALCE 22V10H (PLCC28, labelled 'SS22C2')
273 *       SS22C4       : PALCE 22V10H (PLCC28, labelled 'SS22C4')
274 *       CAT28C64     : Catalyst Semiconductor Inc. CAT28C64 8k x8 EEPROM (DIP28)
275 *       LEDS         : 8 LEDs of various colors flash (in various pretty patterns) when the CPU PCB is active.
276 *       KEYCUS       : Namco custom (DIP32)
277 *                                          Air Combat 22    = none
278 *                                          Alpine Racer 1   = C391
279 *                                          Alpine Racer 2   = C434
280 *                                          Alpine Surfer    = C425
281 *                                          Aqua Jet         =
282 *                                          Armidillo Racing =
283 *                                          Cyber Cycles     = C389
284 *                                          Dirt Dash        =
285 *                                          Prop Cycle       = C428
286 *                                          Time Crisis      = C419
287 *                                          Tokyo Wars       =
288 *
289 *      *1            : Unpopulated position for PAL16V8 (PLCC20)
290 *      *2            : Unpopulated position for Fujitsu MB86601 (QFP100)
291 *      *3            : Unpopulated position for 32MHz OSC
292 *      DATA.8K       : ST Microelectronics M27C4096 256k x16 EPROM (DIP40, labelled with the gamecode + 'DATA')
293 *                      Game                EPROM label
294 *                      -------------------------------
295 *                      Air Combat 22      'ACS1 DATA'
296 *                      Alpine Racer 1     'AR1 DATA B'
297 *                      Alpine Racer 2     'ARS2 DATA'
298 *                      Alpine Surfer      'AF1 DATA'
299 *                      Aqua Jet
300 *                      Armidillo Racing
301 *                      Cyber Cycles       'CB1 DATA B'
302 *                      Dirt Dash
303 *                      Prop Cycle         'PR1 DATA'
304 *                      Time Crisis        'TS1 DATA'
305 *                      Tokyo Wars
306 *
307 *      WAVEA.2L   \
308 *      WAVEB.1L   /  : 16M/32M WAVE MASKROMs. If 32MBit DIP42, they're programmed in BYTE mode (DIP42/SOP44)
309 *                      Game                Wave A        Wave B        Type
310 *                      ----------------------------------------------------------------------------
311 *                      Air Combat 22      'ACS1 WAVE0', 'ACS1 WAVE1' , both SOP44 32M MASKROMs
312 *                      Alpine Racer 1     'AR1 WAVEA' ,              , DIP42 16M MASKROM
313 *                      Alpine Racer 2     'ARS1 WAVEA', 'ARS2 WAVE B', both DIP42 32M MASKROMs
314 *                      Alpine Surfer      'AF1 WAVEA' ,              , DIP42 32M MASKROM
315 *                      Aqua Jet
316 *                      Armidillo Racing
317 *                      Cyber Cycles       'CB1 WAVEA', 'CB1 WAVEB'   , WAVE A DIP42 32M MASKROM, WAVE B DIP42 16M MASKROM
318 *                      Dirt Dash
319 *                      Prop Cycle         'PR1 WAVE A', 'PR1 WAVE B' , both DIP42 32M MASKROM
320 *                      Time Crisis        'TS1 WAVE A', 'TS1 WAVE B' , WAVE A DIP42 32M MASKROM, WAVE B DIP42 16M MASKROM
321 *                      Tokyo Wars
322 *
323 *
324 *
325 * PROGRAM ROM Daughterboard PCB
326 * -----------------------------
327 * This PCB holds the main program ROMs. There is a small sticker on each PCB stating the game code and software revision.
328 * The actual ROMs are not marked with any codes except the manufacturer's part number.
329 * There are 4 known types of program daughterboards used on SS22 games (so far). The most common is the first type.
330 * The PCB is very small (approx 2" x 3") containing one custom connector and some FlashROMs, and a PAL (in some cases).
331 * The ones that contain a PAL are approx 3" x 3".
332 *
333 * Type 1
334 * SYSTEM SUPER22 MPM(F) PCB 8646961600 (8646971600)
335 * |-------------------------|
336 * |                         |
337 * |                         |
338 * | ROM1  ROM2  ROM3  ROM4  |
339 * |                         |
340 * |                         |
341 * |  |-------------------|  |
342 * |  |-------------------|  |
343 * |-------------------------|
344 * Notes:
345 *       ROMx: Intel E28F008SA 8MBit FlashROM (x4, TSOP40)
346 *
347 *       This PCB is used on:
348 *                           Game          Software revision
349 *                           -------------------------------
350 *                           Air Combat 22 'ACS1 Ver.B'
351 *                           Alpine Racer  'AR2 Ver.C'
352 *                           Alpine Racer  'AR2 Ver.D'
353 *                           Cyber Cycles  'CB2 Ver.C'
354 *                           Prop Cycle    'PR2 Ver.A'
355 *                           Time Crisis   'TS2 Ver.B'
356 *
357 * Type 2
358 * SYSTEM SUPER22 MPM(F16) PCB 8646962500 (8646972500)
359 * |-------------------------|
360 * |                         |
361 * |                         |
362 * |      ROM1     ROM2      |
363 * |                         |
364 * |                         |
365 * |                         |
366 * |  |-------------------|  |
367 * |  |-------------------|  |
368 * |-------------------------|
369 * Notes:
370 *       ROMx: Intel E28F016SA 16MBit FlashROMs (x2, TSOP56)
371 *
372 *       This PCB is used on:
373 *                           Game          Software revision
374 *                           -------------------------------
375 *                           Time Crisis   'TS2 Ver.A'
376 *
377 * Type 3
378 * SYSTEM SUPER22 MPM(F16X4) PCB 8646962901 (8646972901)
379 * |-------------------------|
380 * |SS22P1B                  |
381 * |                         |
382 * |        IC4_LM    IC5_UU |
383 * |                         |
384 * |                         |
385 * |  IC2_LL     IC3_UM      |
386 * |                         |
387 * |                         |
388 * |  |-------------------|  |
389 * |  |-------------------|  |
390 * |-------------------------|
391 * Notes:
392 *       ICx*   : Intel E28F016SA 16MBit FlashROMs (x4, TSOP56)
393 *       SS22P1B: PALCE16V8H (PLCC20, labelled 'SS22P1B')
394 *
395 *        This PCB is used on:
396 *                            Game           Software revision
397 *                            -------------------------------
398 *                            Alpine Racer 2 'ARS2 Ver.B'
399 *
400 * Type 4
401 * SYSTEM SUPER22 MPM(F16X4F) PCB 8646963500 (8646973500)
402 * |-------------------------|
403 * |SS22P1B                  |
404 * |                         |
405 * |                         |
406 * | IC2_LL     IC4_UM       |
407 * |                         |
408 * |      IC3_LM      IC5_UU |
409 * |                         |
410 * |                         |
411 * |  |-------------------|  |
412 * |  |-------------------|  |
413 * |-------------------------|
414 * Notes:
415 *       ICx    : Fujutsu 29F016 16MBit FlashROMs (x4, TSOP48)
416 *       SS22P1B: PALCE16V8H (PLCC20, labelled 'SS22P1B')
417 *                There is a small mod on this PAL as follows....
418 *                - Pin 8 is lifted and the pad on the PCB at pin 8
419 *                  is tied to pin 16 of the PAL (no other pins are lifted)
420 *                - The lifted pin 8 is tied to the MPM PCB connector on pin 1
421 *                  That pin traces to pin 6 (OUTPUT Y) of a 74F08 at 15F on the CPU board
422 *                  Pins 4 (INPUT A) & 5 (INPUT B) of the 74F08 at 15F trace to Namco custom
423 *                  IC C383 pins 53 (A INPUT) & 52 (B INPUT)
424 *
425 *
426 *        This PCB is used on:
427 *                            Game          Software revision
428 *                            -------------------------------
429 *                            Alpine Surfer 'AF2 Ver.A'
430 *
431 *
432 *
433 * Auxillary PCB (connector JC410 on the CPU PCB is used only on Time Crisis so far)
434 * -------------
435 * V159 GUN POINT PCB 244790102 (2447970102)
436 * |---------------------------------|
437 * |                                 |
438 * |                      25.175MHz  |
439 * |                                 |
440 * |                                 |
441 * |                                 |
442 * |                                 |
443 * |                                 |
444 * |                                 |
445 * |                               J2|
446 * |                                 |
447 * |                                 |
448 * |                                 |
449 * |                                 |
450 * |                                 |
451 * |                                 |
452 * |                J1               |
453 * |---------------------------------|
454 * Notes:
455 *       There isn't much on this PCB other than 2 connectors and an oscillator plus a large amount of logic chips.
456 *       J1 : Connector joining Gun PCB to a connector on the metal box (which joins to the gun interface PCB in the
457 *            cab which supplies 24V for the soleniod in the guns)
458 *       J2 : Connector joining to the CPU PCB (to JC410)
459 *
460 *
461 *
462 * DSP PCB
463 * -------
464 * SYSTEM SUPER22 DSP PCB 8646960302 (8646970302)
465 *   |--------------------------------------------------------------|
466 *   | N341256     |-------|   SS22D1    N341256     |-------|      |
467 *   | N341256     |       |             N341256     |       |      |
468 *   | |---------| | C71   |                         | C405  |     |--|
469 * |--||         | |       |                         |       |     |  |
470 * |  ||  C396   | |-------|                         |-------|     |  |
471 * |  ||         |                                                 |  |
472 * |J ||         |           N341256                 |-------|     |  |
473 * |D ||---------|           N341256                 |       |     |  |
474 * |3 | |-------|                          N341256   | C405  |     |  |
475 * |  | |       |                                    |       |     |  |
476 * |  | | C71   |  |---------|                       |-------|     |  |
477 * |--| |       |  |         |             |------|                |  |
478 *   |  |-------|  |  342    |             | C379 |                |--|
479 *   |  |------|   |         |             |      |                 |
480 *   |  | C199 |   |         |             |------|  N341256        |
481 *   |  |      |   |---------|                       N341256       |--|
482 *   |  |------|                                                   |  |
483 *   |   |-----|      SS22D5  SS22D4B    40MHz     |---------|     |  |
484 *   |   |C353 |                                   |         |     |  |
485 *   |   |-----|                                   |  C300   |     |  |
486 *   |LED(x8)         SS22D2  SS22D3               |         |     |  |
487 *   |   |-----|                                   |         |     |  |
488 *   |   | 402 |  |---------|                      |---------|     |  |
489 *   |   |-----|  |         |                                      |  |
490 *   |            |  C403   |    KM681000   KM681000   KM681000    |  |
491 *   |   |-----|  |         |                                      |--|
492 *   |   | 402 |  |         |    KM681000   KM681000   KM681000     |
493 *   |   |-----|  |---------|                                       |
494 *   |--------------------------------------------------------------|
495 * (logic chips omitted from the PCB layout)
496 *
497 * Notes:
498 *       JD3          : Custom Namco connector joining this PCB to the MROM PCB with a special flat cable known as a
499 *                      'DHD harness'
500 *       N341256      : NKK N341256 32k x8 SRAM (x9, SOJ28)
501 *       KM681000     : Samsung Electronics KM681000 128k x8 SRAM (x6, SOP32)
502 *       342          : Namco custom 342  (QFP160)
503 *       402          : Namco custom 402  (x2, TQFP144)
504 *       C71          : Namco custom C71, actually a Texas Instruments 320C25 DSP (x2, PLCC68)
505 *       C199         : Namco custom C199 (QFP100)
506 *       C300         : Namco custom C300 (QFP160)
507 *       C353         : Namco custom C353 (QFP120)
508 *       C379         : Namco custom C379 (QFP64)
509 *       C396         : Namco custom C396 (QFP160)
510 *       C403         : Namco custom C403 (QFP136)
511 *       C405         : Namco custom C396 (x2, QFP176)
512 *       SS22D1       : PALCE 20V8H (PLCC28, labelled 'SS22D1')
513 *       SS22D2       : PALCE 16V8H (PLCC20, labelled 'SS22D2')
514 *       SS22D3       : PALCE 16V8H (PLCC20, labelled 'SS22D3')
515 *       SS22D4B      : PALCE 16V8H (PLCC20, labelled 'SS22D4B')
516 *       SS22D5       : PALCE 16V8H (PLCC20, labelled 'SS22D5')
517 *       LEDS         : 8 red LEDs flash (in various pretty patterns) when the DSP PCB is active.
518 *
519 *
520 *
521 * ROM PCB
522 * -------
523 * SYSTEM SUPER22 MROM PCB 8646960400 (8646970400)
524 *   |--------------------------------------------------------------|
525 *   | SS22M3      TC551001(x3)                                     |
526 *   | JP13                                 CG7.19D    CG5.19B      |
527 *   |  PTR-L0.18K  PTR-M0.18J  PTR-U0.18F                          |
528 * |--|                                     CG6.18D    CG4.18B      |
529 * |  | PTR-L1.16K  PTR-M1.16J  PTR-U1.16F                   CG6.18A|
530 * |  |                                     CG5.16D    CG3.16B      |
531 * |J | PTR-L2.15K  PTR-M2.15J  PTR-U2.15F                   CG7.15A|
532 * |R |                                     CG4.14D    CG2.14B      |
533 * |4 | PTR-L3.14K  PTR-M3.14J  PTR-U3.14F                      JP1 |
534 * |  |  SCG0.12L              SCG0.12F JP4 CG3.13D    CG1.13B  JP2 |
535 * |  |                                 JP5                     JP3 |
536 * |--|              SCG7.10J           JP6 CG2.12D    CG0.12B      |
537 *   |   SCG1.10L              SCG1.10F                      SS22M1 |
538 *   |                                      CG1.10D    SS22M2       |
539 *   |                                                              |
540 *   |   SCG2.8L     JP10      SCG2.8F      CG0.8D                 |--|
541 * |--|              JP11                                          |  |
542 * |  |              JP12                                          |  |
543 * |  |  SCG3.7L               SCG3.7F      SS22M2     CCR-L.7B    |  |
544 * |J |                                                            |  |
545 * |R |                                                CCR-H.5B    |  |
546 * |3 |  SCG4.5L               SCG4.5F                             |  |
547 * |  |              JP7                                           |  |
548 * |  |              JP8                                           |  |
549 * |--|  SCG5.3L     JP9       SCG5.3F      CCR-L.3D               |  |
550 *   |                                                             |--|
551 *   |               SCG7.1J                CCR-H.1D                |
552 *   |   SCG6.1L               SCG6.1F                              |
553 *   |--------------------------------------------------------------|
554 * (logic chips omitted from the PCB layout)
555 *
556 * Notes:
557 *       Namco SS22 MROM PCBs have 2 identical sets of CG*, SCG* and CCR-L/CCR-H ROMs on the PCB.
558 *       The Japanese region code '1' is appended to all game codes on all MROMs.
559 *
560 *       JR3, JR4     : Custom Namco connector joining this PCB to the VIDEO & DSP PCBs with a special flat cable known
561 *                      as a 'DHD harness'
562 *       SS22M1       : PALCE 16V8H (PLCC20, labelled 'SS22M1')
563 *       SS22M2       : PALCE 20V8H (x2, PLCC28, labelled 'SS22M2')
564 *       SS22M3       : PALCE 16V8H (PLCC20, labelled 'SS22M3')
565 *       TC551001     : Toshiba TC551001 128k x8 SRAM (SOP32)
566 *       JP1, JP2, JP3: Jumpers to configure CG* ROMs.  Hardwired to '16M' on the PCB. Alt. setting '32M'
567 *       JP4, JP5, JP6: Jumpers to configure CG* ROMs.  Hardwired to '16M' on the PCB. Alt. setting '32M'
568 *       JP7, JP8, JP9: Jumpers to configure SCG* ROMs. Hardwired to '16M' on the PCB. Alt. setting '32M'
569 *    JP10, JP11, JP12: Jumpers to configure SCG* ROMs. Hardwired to '16M' on the PCB. Alt. setting '32M'
570 *       JP13         : Jumper  to configure PTR* ROMs. Hardwired to '4M'  on the PCB. Alt. setting '8M'
571 *
572 * Game               ROMs populated
573 * ---------------------------------------------------------
574 * Air Combat 22      ACS1CCRH.5B, ACS1CCRH.1D    4M SOP32
575 *                    ACS1CCRL.7B, ACS1CCRL.3D   16M SOP44
576 *                    ACS1CG0.12B, ACS1CG0.8D        "
577 *                    ACS1CG1.13B, ACS1CG1.10D       "
578 *                    ACS1CG2.14B, ACS1CG2.12D       "
579 *                    ACS1CG3.16B, ACS1CG3.13D       "
580 *                    ACS1CG4.18B, ACS1CG4.14D       "
581 *                    ACS1CG5.19B, ACS1CG5.16D       "
582 *                    ACS1CG6.18A, ACS1CG6.18D       "
583 *                    ACS1CG7.15A, ACS1CG7.19D       "
584 *                    ACS1SCG0.12F,ACS1SCG0.12L      "
585 *                    ACS1SCG1.10F,ACS1SCG1.10L      "
586 *                    ACS1PTRU0.18F               4M SOP32
587 *                    ACS1PTRU1.16F                  "
588 *                    ACS1PTRU2.15F                  "
589 *                    ACS1PTRU3.14F                  "
590 *                    ACS1PTRM0.18J                  "
591 *                    ACS1PTRM1.16J                  "
592 *                    ACS1PTRM2.15J                  "
593 *                    ACS1PTRM3.14J                  "
594 *                    ACS1PTRL0.18K                  "
595 *                    ACS1PTRL1.16K                  "
596 *                    ACS1PTRL2.15K                  "
597 *                    ACS1PTRL3.14K                  "
598 *
599 * Alpine Racer 1     AR1CCRH.5B, AR1CCRH.1D      4M SOP32
600 *                    AR1CCRL.7B, AR1CCRL.3D     16M SOP44
601 *                    AR1CG0.12B, AR1CG0.8D          "
602 *                    AR1CG1.13B, AR1CG1.10D         "
603 *                    AR1CG2.14B, AR1CG2.12D         "
604 *                    AR1CG3.16B, AR1CG3.13D         "
605 *                    AR1CG4.18B, AR1CG4.14D         "
606 *                    AR1CG5.19B, AR1CG5.16D         "
607 *                    AR1CG6.18A, AR1CG6.18D         "
608 *                    AR1CG7.15A, AR1CG7.19D         "
609 *                    AR1SCG0.12F,AR1SCG0.12L        "
610 *                    AR1SCG1.10F,AR1SCG1.10L        "
611 *                    AR1PTRU0.18F                4M SOP32
612 *                    AR1PTRU1.16F                   "
613 *                    AR1PTRU2.15F                   "
614 *                    AR1PTRU3.14F                   "
615 *                    AR1PTRM0.18J                   "
616 *                    AR1PTRM1.16J                   "
617 *                    AR1PTRM2.15J                   "
618 *                    AR1PTRM3.14J                   "
619 *                    AR1PTRL0.18K                   "
620 *                    AR1PTRL1.16K                   "
621 *                    AR1PTRL2.15K                   "
622 *                    AR1PTRL3.14K                   "
623 *
624 * Alpine Racer 2     ARS1CCRH.5B, ARS1CCRH.1D    4M SOP32
625 *                    ARS1CCRL.7B, ARS1CCRL.3D   16M SOP44
626 *                    ARS1CG0.12B, ARS1CG0.8D        "
627 *                    ARS1CG1.13B, ARS1CG1.10D       "
628 *                    ARS1CG2.14B, ARS1CG2.12D       "
629 *                    ARS1CG3.16B, ARS1CG3.13D       "
630 *                    ARS1CG4.18B, ARS1CG4.14D       "
631 *                    ARS1CG5.19B, ARS1CG5.16D       "
632 *                    ARS1SCG0.12F,ARS1SCG0.12L      "
633 *                    ARS1PTRU0.18F               4M SOP32
634 *                    ARS1PTRU1.16F                  "
635 *                    ARS1PTRU2.15F                  "
636 *                    ARS1PTRU3.14F                  "
637 *                    ARS1PTRM0.18J                  "
638 *                    ARS1PTRM1.16J                  "
639 *                    ARS1PTRM2.15J                  "
640 *                    ARS1PTRM3.14J                  "
641 *                    ARS1PTRL0.18K                  "
642 *                    ARS1PTRL1.16K                  "
643 *                    ARS1PTRL2.15K                  "
644 *                    ARS1PTRL3.14K                  "
645 *
646 * Alpine Surfer      AF1CCRH.5B, AF1CCRH.1D      4M SOP32
647 *                    AF1CCRL.7B, AF1CCRL.3D     16M SOP44
648 *                    AF1CG0.12B, AF1CG0.8D          "
649 *                    AF1CG1.13B, AF1CG1.10D         "
650 *                    AF1CG2.14B, AF1CG2.12D         "
651 *                    AF1CG3.16B, AF1CG3.13D         "
652 *                    AF1CG4.18B, AF1CG4.14D         "
653 *                    AF1SCG0B.12F,AF1SCG0B.12L      "
654 *                    AF1PTRU0.18F                4M SOP32
655 *                    AF1PTRU1.16F                   "
656 *                    AF1PTRM0.18J                   "
657 *                    AF1PTRM1.16J                   "
658 *                    AF1PTRL0.18K                   "
659 *                    AF1PTRL1.16K                   "
660 *
661 * Aqua Jet           N/A
662 *
663 * Armidillo Racing   N/A
664 *
665 * Cyber Cycles       CB1CCRH.5B, CB1CCRH.1D      4M SOP32
666 *                    CB1CCRL.7B, CB1CCRL.3D     16M SOP44
667 *                    CB1CG0.12B, CB1CG0.8D          "
668 *                    CB1CG1.13B, CB1CG1.10D         "
669 *                    CB1CG2.14B, CB1CG2.12D         "
670 *                    CB1CG3.16B, CB1CG3.13D         "
671 *                    CB1CG4.18B, CB1CG4.14D         "
672 *                    CB1CG5.19B, CB1CG5.16D         "
673 *                    CB1CG6.18A, CB1CG6.18D         "
674 *                    CB1SCG0.12F,CB1SCG0.12L        "
675 *                    CB1SCG1.10F,CB1SCG1.10L        "
676 *                    CB1PTRU0.18F                4M SOP32
677 *                    CB1PTRU1.16F                   "
678 *                    CB1PTRU2.15F                   "
679 *                    CB1PTRU3.14F                   "
680 *                    CB1PTRM0.18J                   "
681 *                    CB1PTRM1.16J                   "
682 *                    CB1PTRM2.15J                   "
683 *                    CB1PTRM3.14J                   "
684 *                    CB1PTRL0.18K                   "
685 *                    CB1PTRL1.16K                   "
686 *                    CB1PTRL2.15K                   "
687 *                    CB1PTRL3.14K                   "
688 *
689 * Dirt Dash          N/A
690 *
691 * Prop Cycle         PR1CCRH.5B, PR1CCRH.1D      4M SOP32
692 *                    PR1CCRL.7B, PR1CCRL.3D     16M SOP44
693 *                    PR1CG0.12B, PR1CG0.8D          "
694 *                    PR1CG1.13B, PR1CG1.10D         "
695 *                    PR1CG2.14B, PR1CG2.12D         "
696 *                    PR1CG3.16B, PR1CG3.13D         "
697 *                    PR1CG4.18B, PR1CG4.14D         "
698 *                    PR1CG5.19B, PR1CG5.16D         "
699 *                    PR1CG6.18A, PR1CG6.18D         "
700 *                    PR1CG7.15A, PR1CG7.19D         "
701 *                    PR1SCG0.12F,PR1SCG0.12L        "
702 *                    PR1SCG1.10F,PR1SCG1.10L        "
703 *                    PR1PTRU0.18F                4M SOP32
704 *                    PR1PTRU1.16F                   "
705 *                    PR1PTRU2.15F                   "
706 *                    PR1PTRM0.18J                   "
707 *                    PR1PTRM1.16J                   "
708 *                    PR1PTRM2.15J                   "
709 *                    PR1PTRL0.18K                   "
710 *                    PR1PTRL1.16K                   "
711 *                    PR1PTRL2.15K                   "
712 *
713 * Time Crisis        TS1CCRH.5B, TS1CCRH.1D      4M SOP32
714 *                    TS1CCRL.7B, TS1CCRL.3D     16M SOP44
715 *                    TS1CG0.12B, TS1CG0.8D          "
716 *                    TS1CG1.13B, TS1CG1.10D         "
717 *                    TS1CG2.14B, TS1CG2.12D         "
718 *                    TS1CG3.16B, TS1CG3.13D         "
719 *                    TS1CG4.18B, TS1CG4.14D         "
720 *                    TS1CG5.19B, TS1CG5.16D         "
721 *                    TS1CG6.18A, TS1CG6.18D         "
722 *                    TS1CG7.15A, TS1CG7.19D         "
723 *                    TS1SCG0.12F,TS1SCG0.12L        "
724 *                    TS1SCG1.10F,TS1SCG1.10L        "
725 *                    TS1SCG2.8F, TS1SCG2.8L         "
726 *                    TS1SCG3.7F, TS1SCG3.7L         "
727 *                    TS1SCG4.5F, TS1SCG4.5L         "
728 *                    TS1SCG5.3F, TS1SCG5.3L         "
729 *                    TS1PTRU0.18F                4M SOP32
730 *                    TS1PTRU1.16F                   "
731 *                    TS1PTRU2.15F                   "
732 *                    TS1PTRM0.18J                   "
733 *                    TS1PTRM1.16J                   "
734 *                    TS1PTRM2.15J                   "
735 *                    TS1PTRL0.18K                   "
736 *                    TS1PTRL1.16K                   "
737 *                    TS1PTRL2.15K                   "
738 *
739 * Tokyo Wars         N/A
740 *
741 *
742 *
743 * VIDEO PCB
744 * ---------
745 * 1st Revision
746 * SYSTEM SUPER22 VIDEO 8646960204 (8646970204)
747 *
748 * 2nd Revision
749 * SYSTEM SUPER22 VIDEO(B) 8646961200 (8646971200)
750 *
751 * 3rd Revision (PCB layout shown below)
752 * SYSTEM SUPER22 VIDEO(C) 8646962700 (8646972700)
753 *   |--------------------------------------------------------------|
754 *   |                                                              |
755 *   |                    HM534251BJ-8(x22)                         |
756 *   |                                                   |-----|   |--|
757 *   |  |---------| |---------| |---------| |---------|  |C401 |   |  |
758 *   |  |         | |         | |         | |         |  |-----|   |  |
759 *   |  |   304   | |   304   | |   304   | |   304   |            |  |
760 *   |  |         | |         | |         | |         |  |-----|   |  |
761 *   |  |         | |         | |         | |         |  |C400 |   |  |
762 *   |  |---------| |---------| |---------| |---------|  |-----|   |  |
763 *   |  N341256      |-----| |-----| |-----| |-----|               |  |
764 *   |  N341256      |C407 | |C401 | |C401 | |C401 |  |---------|  |  |
765 *   |               |-----| |-----| |-----| |-----|  |         |  |  |
766 *   |   |---------|                                  |  C399   |  |--|
767 *   |   |         |         |-----| |-----| |-----|  |         |   |
768 *   |   |  C387   |         |C400 | |C400 | |C400 |  |         |   |
769 *   |   |         |         |-----| |-----| |-----|  |---------|  |--|
770 * |--|  |         |                    |-----|            N341256 |  |
771 * |  |  |---------|                    |C406 |  |-----|   N341256 |  |
772 * |  |  |-----|                        |-----|  |C381 |           |  |
773 * |J |  |C381 |                |---------|      |-----|           |  |
774 * |V |  |-----|      N341256   |         |                LC321664|  |
775 * |3 |     51.2MHz   N341256   |  C404   |      |---------|       |  |
776 * |  | |---------| |---------| |         |      |         |       |  |
777 * |  | |         | |         | |         |      |  C361   |       |  |
778 * |--| |  C374   | |  C395   | |---------|      |         |       |  |
779 *   |  |         | |         | N341256          |         |       |--|
780 *   |  |         | |         | N341256          |---------|        |
781 *   |  |---------| |---------| N341256                    CXD1178Q |
782 *   |--------------------------------------------------------------|
783 * (logic chips omitted from the PCB layout)
784 *
785 * Notes:
786 *       JV3          : Custom Namco connector joining this PCB to the MROM PCB with a special flat cable known
787 *                      as a 'DHD harness'
788 *       N341256      : NKK N341256 32k x8 SRAM (x9, SOJ28)
789 *       HM534251BJ-8 : Hitachi HM534251BJ-8 256k x4 FASTPAGE DRAM (x22, SOJ28)
790 *       LC321664     : Sanyo LC321664 64k x16 DRAM (SOJ40)
791 *       CXD1178Q     : Sony CXD1178Q 8-bit RGB 3-channel D/A converter (QFP48)
792 *       304          : Namco custom 304  (x4, QFP120)
793 *       C361         : Namco custom C361 (QFP120)
794 *       C374         : Namco custom C374 (QFP160)
795 *       C381         : Namco custom C381 (x2, QFP144)
796 *       C387         : Namco custom C387 (QFP160)
797 *       C395         : Namco custom C395 (QFP168)
798 *       C399         : Namco custom C399 (QFP160)
799 *       C400         : Namco custom C400 (x4, QFP100)
800 *                      - x3 on 1st Revision
801 *       C401         : Namco custom C401 (x4, QFP64)
802 *                      - x5 on 1st Revision
803 *       C404         : Namco custom C404 (QFP208)
804 *       C406         : Namco custom C406 (TQFP120)
805 *       C407         : Namco custom C407 (QFP64) NOTE! On Revision A & B, this position is populated by an
806 *                                                      Altera EPM7064 PLCC84 FPGA labelled 'SS22V1B'
807 *                                                      The Altera chip runs very hot and fails quite often.
808 *                                                      The failure of this chip is the primary cause of
809 *                                                      video faults on Namco Super System 22 PCBs.
810 *                                                      (Second reasons for video faults are most likely attributed
811 *                                                      to failure of RAM on this PCB)
812 *
813 *
814 * Motherboard PCB
815 * ---------------
816 * 1st Revision
817 * SYSTEM SUPER22 MOTHER PCB 8646960602 (8646970602)
818 *
819 * 2nd Revision
820 * SYSTEM SUPER22 MOTHER(B) PCB (number not known)
821 *
822 * 3rd Revision
823 * SYSTEM SUPER22 MOTHER(C) PCB 8646960602 (8646970602)
824 * |------------------------------------------------------------------|
825 * | J1                  J2           J4           J6           J8    |
826 * |           J10                           J5   IC2     J7          |
827 * |                     J3          IC3          IC1              J9 |
828 * |                                                                  |
829 * | JC2 |---------------------|        |---------------------|JC1    |
830 * |     |---------------------|        |---------------------|       |
831 * |                                                                  |
832 * | JD2 |---------------------|        |---------------------|JD1    |
833 * |     |---------------------|        |---------------------|       |
834 * |                                                                  |
835 * |                                    |---------------------|JR1    |
836 * |                                    |---------------------|       |
837 * |                                                                  |
838 * | JV2 |---------------------|        |---------------------|JV1    |
839 * |     |---------------------|        |---------------------|       |
840 * |------------------------------------------------------------------|
841 * Notes:
842 *       IC1     : LB1233 (DIP8)
843 *       IC2, IC3: LB1235 (DIP8)
844 *
845 *       JC1, JC2: Connectors to plug in CPU PCB
846 *       JD1, JD2: Connectors to plug in DSP PCB
847 *       JR1     : Connector  to plug in MROM PCB
848 *       JV1, JV2: Connectors to plug in VIDEO PCB
849 *
850 *       J1 : 9 pin power input socket   Pin  Use
851 *                                      -----------
852 *                                       1   +5V
853 *                                       2   +5V
854 *                                       3   +5V
855 *                                       4   NC
856 *                                       5   Ground
857 *                                       6   Ground
858 *                                       7   Ground
859 *                                       8   NC
860 *                                       9   +12V
861 *
862 *       J2 : 9 pin link connector   Pin  Use
863 *                                   --------------
864 *                                   1   Ring In+
865 *                                   2   Ring In-
866 *                                   3   Ring Out2+
867 *                                   4   Ground
868 *                                   5   /RXD+ (NC)
869 *                                   6   /RXD- (NC)
870 *                                   7   /TXD  (NC)
871 *                                   8   GND   (NC)
872 *                                   9   +5V   (NC)
873 *
874 *       J3 : 9 pin socket   Pin  Use
875 *                           -------------------
876 *                            1   Service Credit
877 *                            2   Test
878 *                            3   NC
879 *                            4   +12V
880 *                            5   Counter
881 *                            6   NC
882 *                            7   Ground
883 *                            8   Coin Sw
884 *                            9   NC
885 *
886 *       J4 : 8 pin connector  Pin  Use
887 *                             -------------------------------------
888 *                              1   Start
889 *                              2   Left select
890 *                              3   Right select
891 *                              4   Safety Free Controls (Ski's etc)
892 *                              5   Safety Lock Controls (Ski's etc)
893 *                              6   NC
894 *                              7   Ground
895 *                              8   Ground
896 *
897 *       J5 : 15 pin socket   Pin  Use
898 *                            ---------------
899 *                            1   Relay1
900 *                            2   Relay1
901 *                            3   Mute
902 *                            4   Mid Light
903 *                            5   Left Light
904 *                            6   Right Light
905 *                            7   NC
906 *                            8   NC
907 *                            9   NC
908 *                            10  NC
909 *                            11  NC
910 *                            12  NC
911 *                            13  +12V
912 *                            14  +5V
913 *                            15  NC
914 *
915 *       J6 : 12 pin audio output connector  Pin  Use
916 *                                           ----------
917 *                                            1   SPKL+
918 *                                            2   SPKL-
919 *                                            3   SPKR+
920 *                                            4   SPKR-
921 *                                            5   NC
922 *                                            6   NC
923 *                                            7   NC
924 *                                            8   NC
925 *                                            9   NC
926 *                                            10  NC
927 *                                            11  NC
928 *                                            12  NC
929 *
930 *       J7 : 12 pin analog controls socket   Pin  Use
931 *                                            ---------------------------
932 *                                             1   +5V
933 *                                             2   5K Ohm Potentiometer 1 (Side Swing on Alpine Racer, Alpine Surfer etc)
934 *                                             3   5K Ohm Potentiometer 2 (Tilt on Alpine Racer, Alpine Surfer etc)
935 *                                             4   GND                    (Other games may use more/different pots or no pots)
936 *                                             5   NC
937 *                                             6   NC
938 *                                             7   NC
939 *                                             8   NC
940 *                                             9   NC
941 *                                             10  NC
942 *                                             11  NC
943 *                                             12  NC
944 *
945 *       J8 : 10 pin connector (not used?)
946 *
947 *       J9 : 6 pin video output socket   Pin  Use
948 *                                        ---------
949 *                                         1   Red
950 *                                         2   Green
951 *                                         3   Blue
952 *                                         4   Composite Sync (VSync 15kHz interlaced)
953 *                                         5   Ground
954 *                                         6   NC
955 *
956 *       J10: 16 pin flat cable connector (only populated on Mother(C) PCB, use not known)
957 *
958 *
959 *
960 * AMP PCB
961 * -------
962 * SYSTEM SUPER22 AMP(4) PCB 8647960100 (8647970100) (sticker 'AMP(2) PCB 8647961100')
963 * |-----------------------------------|
964 * |J1  J2   LA4705  J3   *1    *2   J5|
965 * |                                   |
966 * |-----------------------------------|
967 * Notes:
968 *       LA4705: 2-channel 15W Power Amp
969 *       J1    : 3 pin power input socket   Pin  Use
970 *                                          -----------
971 *                                           1   +12V
972 *                                           2   Ground
973 *                                           3   NC
974 *
975 *       J2    : 4 pin dual speaker output socket   Pin  Use
976 *                                                  ---------
977 *                                                   1   SP1+
978 *                                                   2   SP1-
979 *                                                   3   SP2+
980 *                                                   4   SP2-
981 *
982 *       J3    : 8 pin sound data input connector from Mother PCB J6   Pin  Use
983 *                                                                     ----------
984 *                                                                      1   SPKL+
985 *                                                                      2   SPKL-
986 *                                                                      3   SPKR+
987 *                                                                      4   SPKR-
988 *                                                                      5   NC
989 *                                                                      6   NC
990 *                                                                      7   NC
991 *                                                                      8   NC
992 *
993 *       *1    : Unpopulated position for a 2nd LA4705 Power Amp
994 *       *2    : J4 - Unpopulated position for another 4 pin dual speaker output socket
995 *       J5    : 2 pin connector used for sound mute  Pin  Use
996 *                                                    -----------
997 *                                                     1   Mute
998 *                                                     2   Ground
144999 */
1451000
1461001#include "driver.h"
r2762r2763
23793234   ROM_LOAD( "ar1wavea.2l", 0, 0x200000, CRC(dbf64562) SHA1(454fd7d5b860f0e5557d8900393be95d6c992ad1) )
23803235ROM_END
23813236
2382/*
2383 Alpine Racer (VER. D)
2384 Namco, 1995
2385
2386  Player stands on steps, steering left/right.
2387  Inner edge allows quick movement.
2388
2389  The "viewpoint" button is used to select game mode
2390  and to change camera placement during gameplay.
2391
23921ST PCB
2393-------
2394PCB NO: SYSTEM SUPER22 CPU PCB 8646960102 (8646970102)
2395CPU   : 68EC020FG25
2396OSCs  : 40.000MHz, 49.1520MHz
2397RAMs  : IS61C256AH-20J (x2), CY7C182-25VC (x1)
2398DIPSW : 8 Position (x1), 4 Position (x1)
2399PALs  : PALCE 22V10H-15JC/4 (x3, labelled SS22C1, SS22C2, SS22C4)
2400CUSTOM: C352 (100 PIN PQFP)
2401        C405 (176 PIN PQFP)
2402        C391 (KEYCUS)
2403        137
2404        139  (64 PIN PQFP)
2405        C383 (100 PIN PQFP)
2406        M37710S4BFP (80 PIN PQFP)
2407OTHER : AT28C64 (EEPROM)
2408ROMs  : AR1DATAB.8K (near C405, 27C4096)
2409        AR1WAVEA.2L (near C352, 16M MASK)
2410
2411        Tiny ROM PCB labelled AR2 VER. D
2412        SYSTEM SUPER22 MPM(F) PCB 8646961600 (8646971600)
2413        containing main program ....
2414                                     ROM1.BIN (INTEL FLASH, TYPE E28F008SA, TSOP40)
2415                                     ROM2.BIN         "
2416                                     ROM3.BIN         "
2417                                     ROM4.BIN         "
2418
2419
2420
24212ND PCB
2422-------
2423PCB NO: SYSTEM SUPER22 DSP PCB 8646960302 (8646970302)
2424OSC   : 40.0000MHz
2425PALs  : PALCE20V8H (Labelled SS22D1)
2426        PALCE16V8  (x4, Labelled SS22D2, SS22D3, SS22D4, SS22D5)
2427RAMs  : CY7C199-25VC (x9), M5M51008AFP-70L (x6)
2428CUSTOM: C396 (160 PIN PQFP)
2429        C71  (x2, 68 PIN PLCC)
2430        C199 (100 PIN PQFP)
2431        C353 (120 PIN PQFP)
2432        C402 (x2, 144 PIN PQFP)
2433        C403 (136 PIN PQFP)
2434        C300 (160 PIN PQFP)
2435        C342 (160 PIN PQFP)
2436        C405 (x2, 176 PIN PQFP)
2437        C379 (64 PIN PQFP)
2438
2439
2440
24413RD PCB
2442-------
2443
2444PCB No: SYSTEM SUPER22 MROM PCB 8646960400 (8646970400)
2445PALs  : Labelled SS22M3, SS22M2, SS22M2 & SS22M1
2446RAMs  : TC551001BFL-70L (x3)
2447ROMs  : GFX....MANY, MANY, MANY! All ROMs are surface mounted
2448
2449                                  Type
2450        ----------------------------------
2451        ar1ccrl.7b = ar1ccrl.3d   16M SOP44
2452        ar1ccrh.5b = ar1ccrh.1d   4M SOP32
2453
2454        ar1cg1.13b = ar1cg1.10d   16M SOP44
2455        ar1cg2.14b = ar1cg2.12d      "
2456        ar1cg3.16b = ar1cg3.13d      "
2457        ar1cg4.18b = ar1cg4.14d      "
2458        ar1cg5.19b = ar1cg5.16d      "
2459        ar1cg6.18a = ar1cg6.18d      "
2460        ar1cg7.15a = ar1cg7.19d      "
2461
2462        ar1scg0.12f= ar1scg0.12l  16M SOP44 (These have identical halves but)
2463        ar1scg1.10f= ar1scg1.10l     "      (     they *are* 16M ROMs       )
2464
2465        ar1ptr*                   4M SOP32
2466
2467
2468
24694TH PCB
2470-------
2471PCB NO: SYSTEM SUPER22 VIDEO 8646960204 (8646970204)
2472OSC   : 51.2000MHz (near PLCC84)
2473RAMs  : KM424C257 (x22), IS61C256 (x7), LC321664 (x1)
2474CUSTOM: 304 (x4, 120 PIN PQFP)
2475        361 (120 PIN PQFP)
2476        374 (160 PIN PQFP)
2477        381 (x2, 144 PIN PQFP)
2478        395 (? - forgot to note leg count!)
2479        397 (160 PIN PQFP)
2480        399 (160 PIN PQFP)
2481        400 (x3, 100 PIN PQFP)
2482        401 (x5, 64 PIN PQFP)
2483        404 (208 PIN PQFP)
2484        406 (120 PIN PQFP)
2485        SONY CXD1178Q (48 PIN PQFP)
2486        ALTERA EPM7064LC84-15 (84 PIN PLCC)
2487*/
24883237ROM_START( alpinerd )
24893238   ROM_REGION( 0x400000, REGION_CPU1, 0 ) /* main program */
24903239   ROM_LOAD32_BYTE( "ar2ver-d.1", 0x00003, 0x100000, CRC(fa3380b9) SHA1(2a46988745bd2672f8082399a68ae0d0ab3d28f2) )
src/mame/drivers/ssv.c
r2762r2763
365365static NVRAM_HANDLER( gdfs )
366366{
367367   if (read_or_write)
368      EEPROM_save(file);
368      eeprom_save(file);
369369   else
370370   {
371      EEPROM_init(&eeprom_interface_93C46);
371      eeprom_init(&eeprom_interface_93C46);
372372
373      if (file) EEPROM_load(file);
373      if (file) eeprom_load(file);
374374      else
375375      {
376376         /* Set the EEPROM to Factory Defaults */
r2762r2763
491491
492492static READ16_HANDLER( gdfs_eeprom_r )
493493{
494   return (((gdfs_lightgun_select & 1) ? 0 : 0xff) ^ input_port_read_indexed(machine, 5 + gdfs_lightgun_select)) | (EEPROM_read_bit() << 8);
494   return (((gdfs_lightgun_select & 1) ? 0 : 0xff) ^ input_port_read_indexed(machine, 5 + gdfs_lightgun_select)) | (eeprom_read_bit() << 8);
495495}
496496
497497static WRITE16_HANDLER( gdfs_eeprom_w )
r2762r2763
507507//      data & 0x0001 ?
508508
509509      // latch the bit
510      EEPROM_write_bit(data & 0x4000);
510      eeprom_write_bit(data & 0x4000);
511511
512512      // reset line asserted: reset.
513      EEPROM_set_cs_line((data & 0x1000) ? CLEAR_LINE : ASSERT_LINE );
513      eeprom_set_cs_line((data & 0x1000) ? CLEAR_LINE : ASSERT_LINE );
514514
515515      // clock line asserted: write latch or select next bit to read
516      EEPROM_set_clock_line((data & 0x2000) ? ASSERT_LINE : CLEAR_LINE );
516      eeprom_set_clock_line((data & 0x2000) ? ASSERT_LINE : CLEAR_LINE );
517517
518518      if (!(data_old & 0x0800) && (data & 0x0800))   // rising clock
519519         gdfs_lightgun_select = (data & 0x0300) >> 8;
src/mame/drivers/metro.c
r2762r2763
14231423
14241424static READ16_HANDLER( gakusai_eeprom_r )
14251425{
1426   return EEPROM_read_bit() & 1;
1426   return eeprom_read_bit() & 1;
14271427}
14281428
14291429static WRITE16_HANDLER( gakusai_eeprom_w )
r2762r2763
14311431   if (ACCESSING_BITS_0_7)
14321432   {
14331433      // latch the bit
1434      EEPROM_write_bit(data & 0x01);
1434      eeprom_write_bit(data & 0x01);
14351435
14361436      // reset line asserted: reset.
1437      EEPROM_set_cs_line((data & 0x04) ? CLEAR_LINE : ASSERT_LINE );
1437      eeprom_set_cs_line((data & 0x04) ? CLEAR_LINE : ASSERT_LINE );
14381438
14391439      // clock line asserted: write latch or select next bit to read
1440      EEPROM_set_clock_line((data & 0x02) ? ASSERT_LINE : CLEAR_LINE );
1440      eeprom_set_clock_line((data & 0x02) ? ASSERT_LINE : CLEAR_LINE );
14411441   }
14421442}
14431443
r2762r2763
15521552static READ16_HANDLER( dokyusp_eeprom_r )
15531553{
15541554   // clock line asserted: write latch or select next bit to read
1555   EEPROM_set_clock_line(CLEAR_LINE);
1556   EEPROM_set_clock_line(ASSERT_LINE);
1555   eeprom_set_clock_line(CLEAR_LINE);
1556   eeprom_set_clock_line(ASSERT_LINE);
15571557
1558   return EEPROM_read_bit() & 1;
1558   return eeprom_read_bit() & 1;
15591559}
15601560
15611561static WRITE16_HANDLER( dokyusp_eeprom_bit_w )
r2762r2763
15631563   if (ACCESSING_BITS_0_7)
15641564   {
15651565      // latch the bit
1566      EEPROM_write_bit(data & 0x01);
1566      eeprom_write_bit(data & 0x01);
15671567
15681568      // clock line asserted: write latch or select next bit to read
1569      EEPROM_set_clock_line(CLEAR_LINE);
1570      EEPROM_set_clock_line(ASSERT_LINE);
1569      eeprom_set_clock_line(CLEAR_LINE);
1570      eeprom_set_clock_line(ASSERT_LINE);
15711571   }
15721572}
15731573
r2762r2763
15761576   if (ACCESSING_BITS_0_7)
15771577   {
15781578      // reset line asserted: reset.
1579      EEPROM_set_cs_line((data & 0x01) ? CLEAR_LINE : ASSERT_LINE);
1579      eeprom_set_cs_line((data & 0x01) ? CLEAR_LINE : ASSERT_LINE);
15801580   }
15811581}
15821582
r2762r2763
41924192   static const UINT8 def_data[] = {0x00,0xe0};
41934193
41944194   if (read_or_write)
4195      EEPROM_save(file);
4195      eeprom_save(file);
41964196   else
41974197   {
4198      EEPROM_init(&eeprom_interface_93C46);
4199      if (file)   EEPROM_load(file);
4200      else      EEPROM_set_data(def_data,sizeof(def_data)/sizeof(def_data[0]));
4198      eeprom_init(&eeprom_interface_93C46);
4199      if (file)   eeprom_load(file);
4200      else      eeprom_set_data(def_data,sizeof(def_data)/sizeof(def_data[0]));
42014201   }
42024202}
42034203
src/mame/drivers/zaccaria.c
r2762r2763
685685   MDRV_SOUND_ADD(DAC, 0)
686686   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.80)
687687
688   MDRV_SOUND_ADD(TMS5220, XTAL_640kHz)
689/* not right, frequency measured is 560khz. There is no resonator, the clock is obtained from discrete components. We wait for schematics */
688   /* There is no xtal, the clock is obtained from a RC oscillator as shown in the TMS5220 datasheet (R=100kOhm C=22pF) */
689   /* 162kHz measured on pin 3 20 minutesa fter power on. Clock would then be 162*4=648kHz. */
690   MDRV_SOUND_ADD(TMS5200, 640000)
690691   MDRV_SOUND_CONFIG(tms5220_interface)
691692   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.80)
692693MACHINE_DRIVER_END
src/mame/drivers/yumefuda.c
r2762r2763
139139
140140static WRITE8_HANDLER( eeprom_w )
141141{
142   EEPROM_write_bit(data & 0x04);
143   EEPROM_set_cs_line((data & 0x02) ? CLEAR_LINE : ASSERT_LINE);
144   EEPROM_set_clock_line((data & 0x08) ? ASSERT_LINE : CLEAR_LINE);
142   eeprom_write_bit(data & 0x04);
143   eeprom_set_cs_line((data & 0x02) ? CLEAR_LINE : ASSERT_LINE);
144   eeprom_set_clock_line((data & 0x08) ? ASSERT_LINE : CLEAR_LINE);
145145}
146146
147147static WRITE8_HANDLER( port_c0_w )
r2762r2763
152152
153153static READ8_HANDLER( eeprom_r )
154154{
155   return ((~EEPROM_read_bit()&0x01)<<6) | (0xff&~0x40);
155   return ((~eeprom_read_bit()&0x01)<<6) | (0xff&~0x40);
156156}
157157
158158static UINT8 mux_data;
src/mame/drivers/eolith.c
r2762r2763
6767#include "eolithsp.h"
6868
6969// It's configured for 512 bytes
70static const struct EEPROM_interface eeprom_interface_93C66 =
70static const eeprom_interface eeprom_interface_93C66 =
7171{
7272   9,            // address bits 9
7373   8,            // data bits    8
r2762r2763
8383static NVRAM_HANDLER( eolith )
8484{
8585   if (read_or_write)
86      EEPROM_save(file);
86      eeprom_save(file);
8787   else
8888   {
89      EEPROM_init(&eeprom_interface_93C66);
90      if (file)   EEPROM_load(file);
89      eeprom_init(&eeprom_interface_93C66);
90      if (file)   eeprom_load(file);
9191   }
9292}
9393
r2762r2763
104104    */
105105   eolith_speedup_read();
106106
107   return (input_port_read_indexed(machine, 0) & ~0x308) | (EEPROM_read_bit() << 3) | (mame_rand(machine) & 0x300);
107   return (input_port_read_indexed(machine, 0) & ~0x308) | (eeprom_read_bit() << 3) | (mame_rand(machine) & 0x300);
108108}
109109
110110static WRITE32_HANDLER( systemcontrol_w )
r2762r2763
113113   coin_counter_w(0, data & coin_counter_bit);
114114   set_led_status(0, data & 1);
115115
116   EEPROM_write_bit(data & 0x08);
117   EEPROM_set_cs_line((data & 0x02) ? CLEAR_LINE : ASSERT_LINE);
118   EEPROM_set_clock_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE);
116   eeprom_write_bit(data & 0x08);
117   eeprom_set_cs_line((data & 0x02) ? CLEAR_LINE : ASSERT_LINE);
118   eeprom_set_clock_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE);
119119
120120   // bit 0x100 and 0x040 ?
121121}
src/mame/drivers/namcos23.c
r2762r2763
4141
4242/*
4343
44Namco System 23 and Super System 23 Hardware Overview (last updated 27th February, 2006 at 5.26pm)
45Namco, 1997 - 2000
46
47Note! This document is a Work-In-Progress and will be updated from time to time when more dumps are available.
48
49This document covers all the known Namco System 23 / Super System 23 games, including....
50*Angler King      Namco, 1999    System 23
51*Final Furlong    Namco, 1997    System 23
52*Gunmen Wars      Namco, 1998    System 23
53*Motocross Go!    Namco, 1997    System 23
54*Panic Park       Namco, 1998    System 23
55Rapid River       Namco, 1997    System 23 (Actually Namco "Gorgon" hardware)
56Time Crisis II    Namco, 1997    System 23
57*Underground King Namco, 1998    System 23
58*Downhill Bikers  Namco, 199?    System 23
59GP 500            Namco, 1999    Super System 23
60*Crisis Zone      Namco, 2000    Super System 23
61Final Furlong 2   Namco, 1999    Super System 23
62*Guitar Jam       Namco, 1999    Super System 23
63*Race On!         Namco, 1998    Super System 23
64
65* - denotes not dumped yet (and hardware type not confirmed). If you can help with the remaining undumped S23/SS23 games,
66    please contact me at http://www.mameworld.net/gurudumps/
67
68The system comprises the following main boards....
69- EMI PCB                          Small PCB with some connectors, including power in, video out, network in/out, sound out (to AMP PCB)
70- BASS AMP PCB                     Power AMP PCB for general sounds and bass
71- SYSTEM23 MAIN PCB                Main PCB for System 23        \
72  or SystemSuper23 MAIN(1) PCB     Main PCB for Super System 23  / Note the 2 main boards are similar, but not exactly the same.
73- MSPM(FRA) PCB                    A small plug-in daughterboard that holds FLASHROMs containing Main CPU and Sub CPU programs
74- FCA PCB                          Controls & I/O interface board. Contains mostly transistors, caps, resistors, several connectors and an MCU.
75                                   The MCU is different for EACH game and the FCA PCBs are not interchangeable between different games.
76                                   If the FCA PCB is not connected, the game will not advance past the 3rd screen shown below.
77- SYSTEM23 MEM(M) PCB              Holds MASKROMs for GFX/Sound and associated logic
78                                   Note that in Super System23, the MEM(M) PCB is re-used from System23.
79                                   On Super System23, there is a sticker over the System23 part labelled 'SystemSuper23'
80
81The metal box housing these PCB's is approximately the same size as Super System 22. However, the box is mostly
82empty. All of the CPU/Video/DSP hardware is located on the main PCB which is the same size as the
83Super System 22 CPU board. The ROM PCB is half the size of the Super System22 ROM PCB. The ROM positions on it
84can be configured for either 32MBit or 64MBit SOP44 MASK ROMs with a maximum capacity of 1664MBits.
85The system also uses a dual pipeline graphics bus similar to Super System 22 and has two copies of the graphics ROMs
86on the PCB.
87The System 23 hardware is the first NAMCO system to require an external 3.3V power source. Previously the 3.3volts
88was derived from a 5v to 3.3v regulator on systems such as System10/11/12 etc.
89The KEYCUS chip is the familiar MACH211 PLCC44 IC as used on System12. The sound system is also taken from System12.
90
91On bootup, the following happens (on GP500)...
92
931st screen - Black screen with white text
94                               "SYSTEM 23 BOOTING     "
95                               "SDRAM CHECKING A0xx000" (xx = slowly counts up to 3F, from 00), then OK ('CHECKING' is in yellow text, 'OK' is in green text)
96   As the SDRAM is being checked, the LEDS 1 to 8 turn off in sequence from 8 to 1.
97
982nd screen - Black screen with white text
99                               "S.S.23 POWER ON TEST      xxxx"  (xxxx = numbers count up rapidly from 0000)
100                               "(C) NAMCO                     "
101                               "                     VER. 1.16"
102   As these checks happen, the LEDs 1 to 8 flash on/off
103
1043rd screen - Black screen with white text
105                               "S.S.23 POWER ON TEST      xxxx"  (xxxx = numbers count up rapidly from 0000)
106                               "SUBCPU INITIALIZING ....      "
107                               "SUBCPU PROGRAM Ver. 0211      "
108
109   and a PACMAN eating dots along the bottom of the screen from left to right.
110   As these checks happen, the LEDs 1 to 8 simultaneously flash on/off in various patterns.
111
112   - On System23, the bootup sequence is shorter. The screen remains blank while the SDRAM is being checked. LEDS 1-8 turn off in sequence 8-1
113     After that, the bootup sequence is mostly the same as SS23.
114
115
44116PCB Layouts
45117-----------
46118
r2762r2763
86158|                                                             *KM681000      |
87159|                                                       HM5216165  HM5216165 |
88160|----------------------------------------------------------------------------|
161Notes:
162      * - These parts are underneath the PCB.
89163
164      Main Parts List:
90165
166      CPU
167      ---
168          NKK NR4650 - R4600-based 64bit RISC CPU (Main CPU, QFP208, clock input source = CY2291)
169          H8/3002    - Hitachi H8/3002 HD6413002F17 (Sound CPU, QFP100, running at 14.7456MHz)
170
171      RAM
172      ---
173          N341256    - NKK 32k x8 SRAM (x9, SOJ28)
174          LC35256    - Sanyo 32k x8 SRAM (SOP28)
175          KM416S1020 - Samsung 1M x16 SDRAM (x2, TSOP48)
176          M5M4V4265  - Mitsubishi 256k x16 DRAM (x2, TSOP40/44)
177          LC321664   - Sanyo 64k x16 EDO DRAM (SOJ40)
178          HM5216165  - Hitachi 1M x16 SDRAM (x2, TSOP48)
179          KM681000   - Samsung 128k x8 SRAM (x2, SOP32)
180          CY7C182    - Cypress 8k x9 SRAM (SOJ28)
181
182      Namco Customs
183      -------------
184                    C352 (QFP100)
185                    C361 (QFP120)
186                    C403 (QFP136)
187                    C404 (QFP208)
188                    C412 (QFP256)
189                    C413 (QFP208)
190                    C416 (QFP176)
191                    C417 (QFP208)
192                    C421 (QFP208)
193                    C422 (QFP64)
194                    C435 (x2, QFP144)
195
196      Other ICs
197      ---------
198               XC95108  - Xilinx XC95108 In-System Programmable CPLD (QFP100, labelled 'S23MA9B')
199               DS8921   - National RS422/423 Differential Line Driver and Receiver Pair (SOIC8)
200               CXD1178Q - SONY CXD1178Q  8-bit RGB 3-channel D/A converter (QFP48)
201               PAL(1)   - PALCE16V8H (PLCC20, stamped 'PAD23')
202               PAL(2)   - PALCE22V10H (PLCC28, stamped 'S23MA5')
203               PAL(3)   - PALCE22V10H (PLCC28, stamped 'SS23MA6B')
204               MAX734   - MAX734 +12V 120mA Flash Memory Programming Supply Switching Regulator (SOIC8)
205               PST575   - PST575 System Reset IC (SOIC4)
206               3414     - NJM3414 70mA Dual Op Amp (x2, SOIC8)
207               LM358    - National LM358 Low Power Dual Operational Amplifier (SOIC8)
208               MB87078  - Fujitsu MB87078 Electronic Volume Control IC (SOIC24)
209               MB88347  - Fujitsu MB88347 8bit 8 channel D/A converter with OP AMP output buffers (SOIC16)
210               ADM485   - Analog Devices Low Power EIA RS485 transceiver (SOIC8)
211               CXA1779P - SONY CXA1779P TV/Video circuit RGB Pre-Driver (DIP28)
212               CY2291   - Cypress CY2291 Three-PLL General Purpose EPROM Programmable Clock Generator (SOIC20)
213               2061ASC-1- IC Designs 2061ASC-1 clock Generator IC (SOIC16, also found on Namco System 11 PCBs)
214               R4543    - EPSON Real Time Clock Module (SOIC14)
215               IDT7200  - Integrated Devices Technology IDT7200 256 x9 CMOS Asynchronous FIFO
216
217      Misc
218      ----
219          J18   - Connector for MSPM(FRA) PCB
220          J5    - Connector for EMI PCB
221          J12   - 6-pin connector for In-System Programming of the XC95108 IC
222          J14 \
223          J15 \
224          J16 \
225          J17 \ - Connectors for MEM(M) PCB
226          SW2   - 2 position DIP Switch
227          SW3   - 2 position DIP Switch
228          SW4   - 8 position DIP Switch
229
230
91231SystemSuper23 MAIN(1) PCB 8672960904 8672960104 (8672970104)
92232|----------------------------------------------------------------------------|
93233|       J5                    3V_BATT                                        |
r2762r2763
253393      Game           Code and revision
254394      --------------------------------
255395      GP500          5GP3 Ver.C
396Other games dumps with unknown PCB information....
256397
398      Game             Code and revision
399      ----------------------------------
400      Final Furlong 2  FFS1 Ver.?
401      Final Furlong 2  FFS2 Ver.?
257402
403
258404ROM PCB
259405-------
260406
261Printed on the PCB      - 8660960601 (8660970601) SYSTEM23 MEM(M) PCB
262Sticker (GP500)         - 8672961100
263Sticker (Time Crisis 2) - 8660962302
407Printed on the PCB        - 8660960601 (8660970601) SYSTEM23 MEM(M) PCB
408Sticker (GP500)           - 8672961100
409Sticker (Time Crisis 2)   - 8660962302
410Sticker (Final Furlong 2) - ??????????
264411|----------------------------------------------------------------------------|
265412| KEYCUS    MTBH.2M      CGLL.4M        CGLL.5M         CCRL.7M       PAL(3) |
266413|                                                                            |
r2762r2763
306453      PAL(1)   - PALCE20V8H  (PLCC28, stamped 'SS22M2')  \ Both identical
307454      PAL(2)   - PALCE20V8H  (PLCC28, stamped 'SS22M2')  /
308455      PAL(3)   - PALCE16V8H  (PLCC20, stamped 'SS22M1')
309      PAL(4)   - PALCE16V8H  (PLCC20, labelled 'SS23MM1')
456      PAL(4)   - PALCE16V8H  (PLCC20, stamped 'SS23MM1')
310457                 Note this PAL is not populated when used on Super System 23
311458
312459      All ROMs are SOP44 MaskROMs
313460      Note: ROMs at locations 7M, 7K, 5M, 5K, 5J & 5F are not included in the archive since they're copies of
314            other ROMs which are included in the archive.
315            Each ROM is stamped with the Namco game code, then the ROM-use code (such as CCRL, CCRH, PT* or MT*).
461            other ROMs which are included in the archive. However, they are populated on the PCB.
462            Each ROM is stamped with the Namco Game Code, then the ROM-use code (such as CCRL, CCRH, PT* or MT*).
316463
317                           MaskROM
318            Game           Code     Keycus
319            -------------------------------
320            GP500          5GP1     KC029
321            Time Crisis 2  TSS1     KC010
322        Final Furlong 2 ????     ?????
464                            Game
465            Game            Code     Keycus    Notes
466            ---------------------------------------------------------
467            GP500           5GP1     KC029     -
468            Time Crisis 2   TSS1     KC010     3A and 3C not populated. i.e. PT3L & PT3H is not used.
469            Final Furlong 2 FFS1     KC???     -
470
471
472I/O PCBs
473--------
474
475FCA PCB  8662969102 (8662979102)
476(Used with GP500)
477|---------------------------------------------------|
478| J101                J106                          |
479|            4.9152MHz                              |
480|    DSW(6)                                         |
481| LED2              |-----|                         |
482|                   | MCU |                         |
483|     LEDS3-10      |     |                         |
484|  PIC16F84         |-----|                         |
485|   JP1 LED1                           ADM485       |
486|                                                   |
487|                     J102              J104        |
488|---------------------------------------------------|
489Notes:
490      J101     - 6 pin connector for power input
491      J102     - 60 pin flat cable connector
492      J104     - 5 pin connector
493      J106     - 30 pin flat cable connector
494      JP1      - 3 pin jumper, set to 'NORM'. Alt setting 'WR'
495      3771     - Fujitsu MB3771 System Reset IC (SOIC8)
496      PIC16F84 - Microchip PIC16F84 Programmable Interrupt Controller stamped 'CAP10' (SOIC20)
497      MCU      - Fujitsu MB90F574 Microcontroller, stamped 'FCAF10' (QFP120)
498      ADM485   - Analog Devices ADM485 +5V Low Power EIA RS-485 Transceiver (SOIC8)
323499*/
324500
325501
r2762r2763
8361012   GFXDECODE_ENTRY( 0, 0, namcos23_cg_layout,  0, 0x80 )
8371013GFXDECODE_END
8381014
839static const struct mips3_config config =
1015static const mips3_config config =
8401016{
8411017   8192,            /* code cache size - VERIFIED */
8421018   8192            /* data cache size - VERIFIED */
r2762r2763
9751151        ROM_LOAD16_WORD_SWAP( "5gp3verc.3",   0x000000, 0x080000, CRC(b323abdf) SHA1(8962e39b48a7074a2d492afb5db3f5f3e5ae2389) )
9761152
9771153   ROM_REGION( 0x2000000, REGION_GFX1, 0 )   /* sprite? tilemap? tiles */
978   ROM_LOAD16_BYTE( "5gp1mtal.2h",  0x0000000, 0x800000, CRC(1bb00c7b) SHA1(922be45d57330c31853b2dc1642c589952b09188) )
1154      ROM_LOAD16_BYTE( "5gp1mtal.2h",  0x0000000, 0x800000, CRC(1bb00c7b) SHA1(922be45d57330c31853b2dc1642c589952b09188) )
9791155        ROM_LOAD16_BYTE( "5gp1mtah.2j",  0x0000001, 0x800000, CRC(246e4b7a) SHA1(75743294b8f48bffb84f062febfbc02230d49ce9) )
9801156
9811157      /* COMMON FUJII YASUI WAKAO KURE INOUE
r2762r2763
9971173   ROM_REGION32_LE( 0x2000000, REGION_GFX4, 0 )   /* 3D model data */
9981174        ROM_LOAD32_WORD( "5gp1pt0l.7c",  0x0000000, 0x400000, CRC(a0ece0a1) SHA1(b7aab2d78e1525f865214c7de387ccd585de5d34) )
9991175        ROM_LOAD32_WORD( "5gp1pt0h.7a",  0x0000002, 0x400000, CRC(5746a8cd) SHA1(e70fc596ab9360f474f716c73d76cb9851370c76) )
1000
10011176        ROM_LOAD32_WORD( "5gp1pt1l.5c",  0x0800000, 0x400000, CRC(80b25ad2) SHA1(e9a03fe5bb4ce925f7218ab426ed2a1ca1a26a62) )
10021177        ROM_LOAD32_WORD( "5gp1pt1h.5a",  0x0800002, 0x400000, CRC(b1feb5df) SHA1(45db259215511ac3e472895956f70204d4575482) )
1003
1004   ROM_LOAD32_WORD( "5gp1pt2l.4c",  0x1000000, 0x400000, CRC(9289dbeb) SHA1(ec546ad3b1c90609591e599c760c70049ba3b581) )
1178      ROM_LOAD32_WORD( "5gp1pt2l.4c",  0x1000000, 0x400000, CRC(9289dbeb) SHA1(ec546ad3b1c90609591e599c760c70049ba3b581) )
10051179        ROM_LOAD32_WORD( "5gp1pt2h.4a",  0x1000002, 0x400000, CRC(9a693771) SHA1(c988e04cd91c3b7e75b91376fd73be4a7da543e7) )
1006
1007   ROM_LOAD32_WORD( "5gp1pt3l.3c",  0x1800000, 0x400000, CRC(480b120d) SHA1(6c703550faa412095d9633cf508050614e15fbae) )
1180      ROM_LOAD32_WORD( "5gp1pt3l.3c",  0x1800000, 0x400000, CRC(480b120d) SHA1(6c703550faa412095d9633cf508050614e15fbae) )
10081181        ROM_LOAD32_WORD( "5gp1pt3h.3a",  0x1800002, 0x400000, CRC(26eaa400) SHA1(0157b76fffe81b40eb970e84c98398807ced92c4) )
10091182
10101183   ROM_REGION( 0x1000000, REGION_SOUND1, 0 ) /* C352 PCM samples */
r2762r2763
10321205        ROM_LOAD( "ffs1cgll.4m",  0x1000000, 0x800000, CRC(171bba76) SHA1(4a63a1f34de8f341a0ef9b499a21e8fec758e1cd) )
10331206        ROM_LOAD( "ffs1cglm.4k",  0x1800000, 0x800000, CRC(48acf207) SHA1(ea902efdd94aba34dadb20762219d2d25441d199) )
10341207
1035   ROM_REGION( 0x600000, REGION_GFX3, 0 )   /* texture tilemap */
1208   ROM_REGION( 0x400000, REGION_GFX3, 0 )   /* texture tilemap */
10361209        ROM_LOAD( "ffs1ccrl.7f",  0x000000, 0x200000, CRC(ffbcfec1) SHA1(9ab25f1543da4b72784eec93985abaa2e1dafc83) )
10371210        ROM_LOAD( "ffs1ccrh.7e",  0x200000, 0x200000, CRC(8be4aeb4) SHA1(ec344f6fba42092083e737e436451f5d7be12c15) )
10381211
r2762r2763
10711244        ROM_LOAD( "ffs1cgll.4m",  0x1000000, 0x800000, CRC(171bba76) SHA1(4a63a1f34de8f341a0ef9b499a21e8fec758e1cd) )
10721245        ROM_LOAD( "ffs1cglm.4k",  0x1800000, 0x800000, CRC(48acf207) SHA1(ea902efdd94aba34dadb20762219d2d25441d199) )
10731246
1074   ROM_REGION( 0x600000, REGION_GFX3, 0 )   /* texture tilemap */
1247   ROM_REGION( 0x400000, REGION_GFX3, 0 )   /* texture tilemap */
10751248        ROM_LOAD( "ffs1ccrl.7f",  0x000000, 0x200000, CRC(ffbcfec1) SHA1(9ab25f1543da4b72784eec93985abaa2e1dafc83) )
10761249        ROM_LOAD( "ffs1ccrh.7e",  0x200000, 0x200000, CRC(8be4aeb4) SHA1(ec344f6fba42092083e737e436451f5d7be12c15) )
10771250
r2762r2763
10911264ROM_END
10921265
10931266/* Games */
1094//GAME( 199?, downhbkr,  0,         s23, ss23, ss23, ROT0, "Namco",  "Downhill Bikers (DH3 Ver.A)", GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION | GAME_IMPERFECT_SOUND )
1267//GAME( 199?, downhbkr,  0,      s23, ss23, ss23, ROT0, "Namco",  "Downhill Bikers (DH3 Ver.A)", GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION | GAME_IMPERFECT_SOUND )
10951268GAME( 1997, timecrs2, 0,         s23, ss23, ss23, ROT0, "Namco", "Time Crisis 2", GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION | GAME_IMPERFECT_SOUND )
10961269GAME( 1999, gp500,    0,        ss23, ss23, ss23, ROT0, "Namco", "GP500", GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION | GAME_IMPERFECT_SOUND )
10971270GAME( 1999, finfurl2, 0,        ss23, ss23, ss23, ROT0, "Namco", "Final Furlong 2 (World)", GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION | GAME_IMPERFECT_SOUND )
src/mame/drivers/inufuku.c
r2762r2763
157157   UINT16 inputport;
158158
159159   soundflag = pending_command ? 0x0000 : 0x0080;   // bit7
160   eeprom = (EEPROM_read_bit() & 1) << 6;         // bit6
160   eeprom = (eeprom_read_bit() & 1) << 6;         // bit6
161161   inputport = input_port_read_indexed(machine, 4) & 0xff3f;         // bit5-0
162162
163163   return (soundflag | eeprom | inputport);
r2762r2763
166166static WRITE16_HANDLER( inufuku_eeprom_w )
167167{
168168   // latch the bit
169   EEPROM_write_bit(data & 0x0800);
169   eeprom_write_bit(data & 0x0800);
170170
171171   // reset line asserted: reset.
172   EEPROM_set_cs_line((data & 0x2000) ? CLEAR_LINE : ASSERT_LINE);
172   eeprom_set_cs_line((data & 0x2000) ? CLEAR_LINE : ASSERT_LINE);
173173
174174   // clock line asserted: write latch or select next bit to read
175   EEPROM_set_clock_line((data & 0x1000) ? ASSERT_LINE : CLEAR_LINE);
175   eeprom_set_clock_line((data & 0x1000) ? ASSERT_LINE : CLEAR_LINE);
176176}
177177
178178
src/mame/drivers/onetwo.c
r2762r2763
3333
3434COR_x are LN60G resitor packs
3535
36-------------------------------------
37
38Note: this is quite clearly a 'Korean bootleg' of Shisensho - Joshiryo-Hen / Match-It
39
3640*/
3741
3842#include "driver.h"
r2762r2763
183187   PORT_DIPNAME( 0x02, 0x00, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("SW2:2")
184188   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
185189   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
186   PORT_DIPNAME( 0x04, 0x04, "Coin Chute" ) PORT_DIPLOCATION("SW2:3")
190   PORT_DIPNAME( 0x04, 0x00, "Coin Chute" ) PORT_DIPLOCATION("SW2:3")
187191   PORT_DIPSETTING(    0x04, "Common" )
188192   PORT_DIPSETTING(    0x00, "Separate" )
189193   PORT_DIPNAME( 0x08, 0x08, "Nude Pictures" ) PORT_DIPLOCATION("SW2:4")
src/mame/drivers/plygonet.c
r2762r2763
7070static UINT16 *dsp56k_bank02_ram ;
7171static UINT16 *dsp56k_bank04_ram ;
7272
73static const struct EEPROM_interface eeprom_interface =
73static const eeprom_interface eeprom_intf =
7474{
7575   7,         /* address bits */
7676   8,         /* data bits */
r2762r2763
8484static NVRAM_HANDLER( polygonet )
8585{
8686   if (read_or_write)
87      EEPROM_save(file);
87      eeprom_save(file);
8888   else
8989   {
90      EEPROM_init(&eeprom_interface);
90      eeprom_init(&eeprom_intf);
9191
9292      if (file)
9393      {
9494         init_eeprom_count = 0;
95         EEPROM_load(file);
95         eeprom_load(file);
9696      }
9797      else
9898         init_eeprom_count = 10;
r2762r2763
103103{
104104   if (ACCESSING_BITS_0_15)
105105   {
106      return 0x0200 | (EEPROM_read_bit()<<8);
106      return 0x0200 | (eeprom_read_bit()<<8);
107107   }
108108   else
109109   {
r2762r2763
122122{
123123   if (ACCESSING_BITS_24_31)
124124   {
125      EEPROM_write_bit((data & 0x01000000) ? ASSERT_LINE : CLEAR_LINE);
126      EEPROM_set_cs_line((data & 0x02000000) ? CLEAR_LINE : ASSERT_LINE);
127      EEPROM_set_clock_line((data & 0x04000000) ? ASSERT_LINE : CLEAR_LINE);
125      eeprom_write_bit((data & 0x01000000) ? ASSERT_LINE : CLEAR_LINE);
126      eeprom_set_cs_line((data & 0x02000000) ? CLEAR_LINE : ASSERT_LINE);
127      eeprom_set_clock_line((data & 0x04000000) ? ASSERT_LINE : CLEAR_LINE);
128128      return;
129129   }
130130
src/mame/drivers/naomi.c
r2762r2763
649649   static UINT8 eeprom_romboard[20+48] = {0x19,0x00,0xaa,0x55,0,0,0,0,0,0,0,0,0x69,0x79,0x68,0x6b,0x74,0x6d,0x68,0x6d};
650650
651651   if (read_or_write)
652      /*EEPROM_save(file)*/;
652      /*eeprom_save(file)*/;
653653   else
654654   {
655      EEPROM_init(&eeprom_interface_93C46);
655      eeprom_init(&eeprom_interface_93C46);
656656      /*if (file)
657            EEPROM_load(file);
657            eeprom_load(file);
658658        else*/
659      EEPROM_set_data((UINT8 *)"\011\241                              0000000000000000", 48);  // 2*checksum 30*unknown 16*serial
659      eeprom_set_data((UINT8 *)"\011\241                              0000000000000000", 48);  // 2*checksum 30*unknown 16*serial
660660      x76f100_init( 0, eeprom_romboard );
661661      memcpy(eeprom_romboard+20,"\241\011                              0000000000000000",48);
662662   }
r2762r2763
667667   int res;
668668
669669   /* bit 3 is EEPROM data */
670   res = EEPROM_read_bit() << 4;
670   res = eeprom_read_bit() << 4;
671671   return res;
672672}
673673
r2762r2763
676676   /* bit 4 is data */
677677   /* bit 2 is clock */
678678   /* bit 5 is cs */
679   EEPROM_write_bit(data & 0x8);
680   EEPROM_set_cs_line((data & 0x20) ? CLEAR_LINE : ASSERT_LINE);
681   EEPROM_set_clock_line((data & 0x4) ? ASSERT_LINE : CLEAR_LINE);
679   eeprom_write_bit(data & 0x8);
680   eeprom_set_cs_line((data & 0x20) ? CLEAR_LINE : ASSERT_LINE);
681   eeprom_set_clock_line((data & 0x4) ? ASSERT_LINE : CLEAR_LINE);
682682}
683683
684684static ADDRESS_MAP_START( naomi_map, ADDRESS_SPACE_PROGRAM, 64 )
src/mame/drivers/powerbal.c
r2762r2763
2727static int xoffset;
2828static int yoffset;
2929
30static const struct EEPROM_interface eeprom_interface =
30static const eeprom_interface eeprom_intf =
3131{
3232   6,            /* address bits */
3333   16,            /* data bits */
r2762r2763
4444{
4545   if (read_or_write)
4646   {
47      EEPROM_save(file);
47      eeprom_save(file);
4848   }
4949   else
5050   {
51      EEPROM_init(&eeprom_interface);
51      eeprom_init(&eeprom_intf);
5252
5353      if (file)
54         EEPROM_load(file);
54         eeprom_load(file);
5555      else
5656      {
5757         UINT8 init[128];
5858         memset(init,0,128);
59         EEPROM_set_data(init,128);
59         eeprom_set_data(init,128);
6060      }
6161   }
6262}
6363
6464static READ16_HANDLER( magicstk_port2_r )
6565{
66   return (input_port_read_indexed(machine, 2) & 0xfe) | EEPROM_read_bit();
66   return (input_port_read_indexed(machine, 2) & 0xfe) | eeprom_read_bit();
6767}
6868
6969static WRITE16_HANDLER( magicstk_coin_eeprom_w )
r2762r2763
7272   {
7373      coin_counter_w(0,data & 0x20);
7474
75      EEPROM_set_cs_line((data & 8) ? CLEAR_LINE : ASSERT_LINE);
76      EEPROM_write_bit(data & 2);
77      EEPROM_set_clock_line((data & 4) ? CLEAR_LINE : ASSERT_LINE);
75      eeprom_set_cs_line((data & 8) ? CLEAR_LINE : ASSERT_LINE);
76      eeprom_write_bit(data & 2);
77      eeprom_set_clock_line((data & 4) ? CLEAR_LINE : ASSERT_LINE);
7878   }
7979}
8080
src/mame/drivers/stv.c
r2762r2763
521521      return_data = input_port_read_indexed(machine, 0);
522522
523523   if (offset == 0x77)//PDR2 read
524      return_data=  (0xfe | EEPROM_read_bit());
524      return_data=  (0xfe | eeprom_read_bit());
525525
526526//  if (offset == 0x33) //country code
527527//      return_data = input_port_read_indexed(machine, 7);
r2762r2763
545545
546546   if(offset == 0x75)
547547   {
548      EEPROM_set_clock_line((data & 0x08) ? ASSERT_LINE : CLEAR_LINE);
549      EEPROM_write_bit(data & 0x10);
550      EEPROM_set_cs_line((data & 0x04) ? CLEAR_LINE : ASSERT_LINE);
548      eeprom_set_clock_line((data & 0x08) ? ASSERT_LINE : CLEAR_LINE);
549      eeprom_write_bit(data & 0x10);
550      eeprom_set_cs_line((data & 0x04) ? CLEAR_LINE : ASSERT_LINE);
551551
552552
553553//      if (data & 0x01)
src/mame/drivers/vamphalf.c
r2762r2763
106106static READ16_HANDLER( eeprom_r )
107107{
108108   if(offset)
109      return EEPROM_read_bit();
109      return eeprom_read_bit();
110110   else
111111      return 0;
112112}
113113
114114static READ32_HANDLER( eeprom32_r )
115115{
116   return EEPROM_read_bit();
116   return eeprom_read_bit();
117117}
118118
119119static WRITE16_HANDLER( eeprom_w )
120120{
121121   if(offset)
122122   {
123      EEPROM_write_bit(data & 0x01);
124      EEPROM_set_cs_line((data & 0x04) ? CLEAR_LINE : ASSERT_LINE );
125      EEPROM_set_clock_line((data & 0x02) ? ASSERT_LINE : CLEAR_LINE );
123      eeprom_write_bit(data & 0x01);
124      eeprom_set_cs_line((data & 0x04) ? CLEAR_LINE : ASSERT_LINE );
125      eeprom_set_clock_line((data & 0x02) ? ASSERT_LINE : CLEAR_LINE );
126126   }
127127}
128128
129129static WRITE32_HANDLER( eeprom32_w )
130130{
131   EEPROM_write_bit(data & 0x01);
132   EEPROM_set_cs_line((data & 0x04) ? CLEAR_LINE : ASSERT_LINE );
133   EEPROM_set_clock_line((data & 0x02) ? ASSERT_LINE : CLEAR_LINE );
131   eeprom_write_bit(data & 0x01);
132   eeprom_set_cs_line((data & 0x04) ? CLEAR_LINE : ASSERT_LINE );
133   eeprom_set_clock_line((data & 0x02) ? ASSERT_LINE : CLEAR_LINE );
134134}
135135
136136static WRITE32_HANDLER( finalgdr_eeprom_w )
137137{
138   EEPROM_write_bit(data & 0x4000);
139   EEPROM_set_cs_line((data & 0x1000) ? CLEAR_LINE : ASSERT_LINE );
140   EEPROM_set_clock_line((data & 0x2000) ? ASSERT_LINE : CLEAR_LINE );
138   eeprom_write_bit(data & 0x4000);
139   eeprom_set_cs_line((data & 0x1000) ? CLEAR_LINE : ASSERT_LINE );
140   eeprom_set_clock_line((data & 0x2000) ? ASSERT_LINE : CLEAR_LINE );
141141}
142142
143143static WRITE16_HANDLER( flipscreen_w )
r2762r2763
493493   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_UNKNOWN )
494494   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_SERVICE1 )
495495   PORT_SERVICE_NO_TOGGLE( 0x0080, IP_ACTIVE_LOW )
496   PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNKNOWN )
496   PORT_BIT( 0xff00, IP_ACTIVE_LOW, IPT_UNKNOWN )
497497INPUT_PORTS_END
498498
499499
r2762r2763
538538static NVRAM_HANDLER( 93C46_vamphalf )
539539{
540540   if (read_or_write)
541      EEPROM_save(file);
541      eeprom_save(file);
542542   else
543543   {
544      EEPROM_init(&eeprom_interface_93C46);
544      eeprom_init(&eeprom_interface_93C46);
545545      if (file)
546546      {
547         EEPROM_load(file);
547         eeprom_load(file);
548548      }
549549      else
550550      {
551         if (!strcmp(machine->gamedrv->name,"suplup")) EEPROM_set_data(suplup_default_nvram,128);
552         if (!strcmp(machine->gamedrv->name,"misncrft")) EEPROM_set_data(misncrft_default_nvram,128);
551         if (!strcmp(machine->gamedrv->name,"suplup")) eeprom_set_data(suplup_default_nvram,128);
552         if (!strcmp(machine->gamedrv->name,"misncrft")) eeprom_set_data(misncrft_default_nvram,128);
553553      }
554554   }
555555}
r2762r2763
558558{
559559   if (read_or_write)
560560   {
561      EEPROM_save(file);
561      eeprom_save(file);
562562      mame_fwrite(file, finalgdr_backupram, 0x80*0x100);
563563   }
564564   else
565565   {
566      EEPROM_init(&eeprom_interface_93C46);
566      eeprom_init(&eeprom_interface_93C46);
567567      if (file)
568568      {
569         EEPROM_load(file);
569         eeprom_load(file);
570570         mame_fread(file, finalgdr_backupram, 0x80*0x100);
571571      }
572572   }
src/mame/drivers/fromanc2.c
r2762r2763
174174   cflag = (((fromanc2_subcpu_int_flag & 1) << 4) |
175175          ((fromanc2_subcpu_nmi_flag & 1) << 6) |
176176          ((fromanc2_sndcpu_nmi_flag & 1) << 5));
177   eeprom = (EEPROM_read_bit() & 1) << 7;      // EEPROM DATA
177   eeprom = (eeprom_read_bit() & 1) << 7;      // EEPROM DATA
178178   coinsw = input_port_read_indexed(machine, 0) & 0x030f;         // COIN, TEST
179179
180180   return (cflag | eeprom | coinsw);
r2762r2763
185185   UINT16 cflag, coinsw, eeprom;
186186
187187   cflag = (fromanc2_sndcpu_nmi_flag & 1) << 5;
188   eeprom = (EEPROM_read_bit() & 1) << 7;      // EEPROM DATA
188   eeprom = (eeprom_read_bit() & 1) << 7;      // EEPROM DATA
189189   coinsw = input_port_read_indexed(machine, 0) & 0x001f;         // COIN, TEST
190190
191191   return (cflag | eeprom | coinsw);
r2762r2763
195195{
196196   if (ACCESSING_BITS_8_15) {
197197      // latch the bit
198      EEPROM_write_bit(data & 0x0100);
198      eeprom_write_bit(data & 0x0100);
199199
200200      // reset line asserted: reset.
201      EEPROM_set_cs_line((data & 0x0400) ? CLEAR_LINE : ASSERT_LINE);
201      eeprom_set_cs_line((data & 0x0400) ? CLEAR_LINE : ASSERT_LINE);
202202
203203      // clock line asserted: write latch or select next bit to read
204      EEPROM_set_clock_line((data & 0x0200) ? ASSERT_LINE : CLEAR_LINE);
204      eeprom_set_clock_line((data & 0x0200) ? ASSERT_LINE : CLEAR_LINE);
205205   }
206206}
207207
r2762r2763
211211      fromancr_gfxbank_w(data & 0xfff8);
212212
213213      // latch the bit
214      EEPROM_write_bit(data & 0x0001);
214      eeprom_write_bit(data & 0x0001);
215215
216216      // reset line asserted: reset.
217      EEPROM_set_cs_line((data & 0x0004) ? CLEAR_LINE : ASSERT_LINE);
217      eeprom_set_cs_line((data & 0x0004) ? CLEAR_LINE : ASSERT_LINE);
218218
219219      // clock line asserted: write latch or select next bit to read
220      EEPROM_set_clock_line((data & 0x0002) ? ASSERT_LINE : CLEAR_LINE);
220      eeprom_set_clock_line((data & 0x0002) ? ASSERT_LINE : CLEAR_LINE);
221221   }
222222}
223223
r2762r2763
225225{
226226   if (ACCESSING_BITS_0_7) {
227227      // latch the bit
228      EEPROM_write_bit(data & 0x0004);
228      eeprom_write_bit(data & 0x0004);
229229
230230      // reset line asserted: reset.
231      EEPROM_set_cs_line((data & 0x0001) ? CLEAR_LINE : ASSERT_LINE);
231      eeprom_set_cs_line((data & 0x0001) ? CLEAR_LINE : ASSERT_LINE);
232232
233233      // clock line asserted: write latch or select next bit to read
234      EEPROM_set_clock_line((data & 0x0002) ? ASSERT_LINE : CLEAR_LINE);
234      eeprom_set_clock_line((data & 0x0002) ? ASSERT_LINE : CLEAR_LINE);
235235   }
236236}
237237
src/mame/drivers/unico.c
r2762r2763
217217static READ32_HANDLER( zeropnt2_coins_r )         { return (input_port_read(machine, "IN0") << 16) | 0xffff; }
218218static READ32_HANDLER( zeropnt2_dsw1_r )         { return (input_port_read(machine, "DSW1") << 16) | 0xffff; }
219219static READ32_HANDLER( zeropnt2_dsw2_r )         { return (input_port_read(machine, "DSW2") << 16) | 0xffff; }
220static READ32_HANDLER( zeropnt2_buttons_r )         { return ((input_port_read(machine, "IN7") | ((EEPROM_read_bit() & 0x01) << 7)) << 16) | 0xffff; }
220static READ32_HANDLER( zeropnt2_buttons_r )         { return ((input_port_read(machine, "IN7") | ((eeprom_read_bit() & 0x01) << 7)) << 16) | 0xffff; }
221221
222222static READ32_HANDLER( zeropnt2_gunx_0_msb_r )      { return (unico_gunx_0_msb_r(machine,0,0xffff)-0x0800) << 16; }
223223static READ32_HANDLER( zeropnt2_guny_0_msb_r )      { return (unico_guny_0_msb_r(machine,0,0xffff)+0x0800) << 16; }
r2762r2763
262262   if ( ACCESSING_BITS_24_31 )
263263   {
264264      // latch the bit
265      EEPROM_write_bit(data & 0x04000000);
265      eeprom_write_bit(data & 0x04000000);
266266
267267      // reset line asserted: reset.
268      EEPROM_set_cs_line((data & 0x01000000) ? CLEAR_LINE : ASSERT_LINE);
268      eeprom_set_cs_line((data & 0x01000000) ? CLEAR_LINE : ASSERT_LINE);
269269
270270      // clock line asserted: write latch or select next bit to read
271      EEPROM_set_clock_line((data & 0x02000000) ? ASSERT_LINE : CLEAR_LINE );
271      eeprom_set_clock_line((data & 0x02000000) ? ASSERT_LINE : CLEAR_LINE );
272272   }
273273}
274274
r2762r2763
642642}
643643
644644
645static const struct EEPROM_interface zeropnt2_eeprom_interface =
645static const eeprom_interface zeropnt2_eeprom_interface =
646646{
647647   7,            // address bits 7
648648   8,            // data bits    8
r2762r2763
658658static NVRAM_HANDLER( zeropnt2 )
659659{
660660   if (read_or_write)
661      EEPROM_save(file);
661      eeprom_save(file);
662662   else
663663   {
664      EEPROM_init(&zeropnt2_eeprom_interface);
665      if (file)   EEPROM_load(file);
664      eeprom_init(&zeropnt2_eeprom_interface);
665      if (file)   eeprom_load(file);
666666   }
667667}
668668
src/mame/drivers/superchs.c
r2762r2763
116116   {
117117      case 0x00:
118118         return (input_port_read_indexed(machine,0) << 16) | input_port_read_indexed(machine,1) |
119              (EEPROM_read_bit() << 7);
119              (eeprom_read_bit() << 7);
120120
121121      case 0x01:
122122         return coin_word<<16;
r2762r2763
149149
150150         if (ACCESSING_BITS_0_7)
151151         {
152            EEPROM_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
153            EEPROM_write_bit(data & 0x40);
154            EEPROM_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
152            eeprom_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
153            eeprom_write_bit(data & 0x40);
154            eeprom_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
155155            return;
156156         }
157157
r2762r2763
374374   f3_68681_reset();
375375}
376376
377static const struct EEPROM_interface superchs_eeprom_interface =
377static const eeprom_interface superchs_eeprom_interface =
378378{
379379   6,            /* address bits */
380380   16,            /* data bits */
r2762r2763
399399static NVRAM_HANDLER( superchs )
400400{
401401   if (read_or_write)
402      EEPROM_save(file);
402      eeprom_save(file);
403403   else
404404   {
405      EEPROM_init(&superchs_eeprom_interface);
405      eeprom_init(&superchs_eeprom_interface);
406406
407407      if (file)
408         EEPROM_load(file);
408         eeprom_load(file);
409409      else
410         EEPROM_set_data(default_eeprom,128);  /* Default the wheel setup values */
410         eeprom_set_data(default_eeprom,128);  /* Default the wheel setup values */
411411   }
412412}
413413
src/mame/drivers/deco156.c
r2762r2763
152152
153153static READ32_HANDLER(hvysmsh_eeprom_r)
154154{
155   return (EEPROM_read_bit()<<24) | input_port_read_indexed(machine, 0) | (input_port_read_indexed(machine, 1)<<16);
155   return (eeprom_read_bit()<<24) | input_port_read_indexed(machine, 0) | (input_port_read_indexed(machine, 1)<<16);
156156}
157157
158158static WRITE32_HANDLER(hvysmsh_eeprom_w)
r2762r2763
161161
162162      OKIM6295_set_bank_base(1, 0x40000 * (data & 0x7) );
163163
164      EEPROM_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
165      EEPROM_write_bit(data & 0x10);
166      EEPROM_set_cs_line((data & 0x40) ? CLEAR_LINE : ASSERT_LINE);
164      eeprom_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
165      eeprom_write_bit(data & 0x10);
166      eeprom_set_cs_line((data & 0x40) ? CLEAR_LINE : ASSERT_LINE);
167167   }
168168}
169169
r2762r2763
195195
196196static READ32_HANDLER(wcvol95_eeprom_r)
197197{
198   return (EEPROM_read_bit()<<24) | input_port_read_indexed(machine, 0) | ((input_port_read_indexed(machine, 1)&0xff)<<16);
198   return (eeprom_read_bit()<<24) | input_port_read_indexed(machine, 0) | ((input_port_read_indexed(machine, 1)&0xff)<<16);
199199}
200200
201201static WRITE32_HANDLER(wcvol95_eeprom_w)
202202{
203203   if (ACCESSING_BITS_0_7) {
204      EEPROM_set_clock_line((data & 0x2) ? ASSERT_LINE : CLEAR_LINE);
205      EEPROM_write_bit(data & 0x1);
206      EEPROM_set_cs_line((data & 0x4) ? CLEAR_LINE : ASSERT_LINE);
204      eeprom_set_clock_line((data & 0x2) ? ASSERT_LINE : CLEAR_LINE);
205      eeprom_write_bit(data & 0x1);
206      eeprom_set_cs_line((data & 0x4) ? CLEAR_LINE : ASSERT_LINE);
207207   }
208208}
209209
src/mame/drivers/othunder.c
r2762r2763
323323   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
324324};
325325
326static const struct EEPROM_interface eeprom_interface =
326static const eeprom_interface eeprom_intf =
327327{
328328   6,            /* address bits */
329329   16,            /* data bits */
r2762r2763
337337static NVRAM_HANDLER( othunder )
338338{
339339   if (read_or_write)
340      EEPROM_save(file);
340      eeprom_save(file);
341341   else
342342   {
343      EEPROM_init(&eeprom_interface);
343      eeprom_init(&eeprom_intf);
344344
345345      if (file)
346         EEPROM_load(file);
346         eeprom_load(file);
347347      else
348         EEPROM_set_data(default_eeprom,128);  /* Default the gun setup values */
348         eeprom_set_data(default_eeprom,128);  /* Default the gun setup values */
349349   }
350350}
351351
352352static int eeprom_r(void)
353353{
354   return (EEPROM_read_bit() & 0x01)<<7;
354   return (eeprom_read_bit() & 0x01)<<7;
355355}
356356
357357
r2762r2763
378378if (data & 4)
379379   popmessage("OBPRI SET!");
380380
381            EEPROM_write_bit(data & 0x40);
382            EEPROM_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
383            EEPROM_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
381            eeprom_write_bit(data & 0x40);
382            eeprom_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
383            eeprom_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
384384            break;
385385
386386         default:
src/mame/drivers/psikyo4.c
r2762r2763
160160   GFXDECODE_ENTRY( REGION_GFX1, 0, layout_16x16x8, 0x000, 0x80 ) // 8bpp tiles
161161GFXDECODE_END
162162
163static const struct EEPROM_interface eeprom_interface_93C56 =
163static const eeprom_interface eeprom_interface_93C56 =
164164{
165165   8,      // address bits 8
166166   8,      // data bits    8
r2762r2763
177177{
178178   if (read_or_write)
179179   {
180      EEPROM_save(file);
180      eeprom_save(file);
181181   }
182182   else
183183   {
184      EEPROM_init(&eeprom_interface_93C56);
184      eeprom_init(&eeprom_interface_93C56);
185185      if (file)
186186      {
187         EEPROM_load(file);
187         eeprom_load(file);
188188      }
189189      else   // these games want the eeprom all zeros by default
190190      {
191191         int length;
192192         UINT8 *dat;
193193
194         dat = EEPROM_get_data_pointer(&length);
194         dat = eeprom_get_data_pointer(&length);
195195         memset(dat, 0, length);
196196      }
197197   }
r2762r2763
201201{
202202   if (ACCESSING_BITS_16_31)
203203   {
204      EEPROM_write_bit((data & 0x00200000) ? 1 : 0);
205      EEPROM_set_cs_line((data & 0x00800000) ? CLEAR_LINE : ASSERT_LINE);
206      EEPROM_set_clock_line((data & 0x00400000) ? ASSERT_LINE : CLEAR_LINE);
204      eeprom_write_bit((data & 0x00200000) ? 1 : 0);
205      eeprom_set_cs_line((data & 0x00800000) ? CLEAR_LINE : ASSERT_LINE);
206      eeprom_set_clock_line((data & 0x00400000) ? ASSERT_LINE : CLEAR_LINE);
207207
208208      return;
209209   }
r2762r2763
215215{
216216   if (ACCESSING_BITS_16_31)
217217   {
218      return ((EEPROM_read_bit() << 20)); /* EEPROM */
218      return ((eeprom_read_bit() << 20)); /* EEPROM */
219219   }
220220
221221//  logerror("Unk EEPROM read mask %x\n", mem_mask);
src/mame/drivers/namcos2.c
r2762r2763
601601static ADDRESS_MAP_START( master_default_am, ADDRESS_SPACE_PROGRAM, 16 )
602602   AM_RANGE(0x000000, 0x03ffff) AM_READ(SMH_ROM) AM_WRITE(SMH_ROM)
603603   AM_RANGE(0x100000, 0x10ffff) AM_READ(NAMCOS2_68K_MASTER_RAM_R) AM_WRITE(NAMCOS2_68K_MASTER_RAM_W)
604   AM_RANGE(0x180000, 0x183fff) AM_READ(NAMCOS2_68K_EEPROM_R) AM_WRITE(NAMCOS2_68K_EEPROM_W)
604   AM_RANGE(0x180000, 0x183fff) AM_READ(NAMCOS2_68K_eeprom_R) AM_WRITE(NAMCOS2_68K_eeprom_W)
605605   AM_RANGE(0x1c0000, 0x1fffff) AM_READ(namcos2_68k_master_C148_r) AM_WRITE(namcos2_68k_master_C148_w)
606606ADDRESS_MAP_END
607607
r2762r2763
619619static ADDRESS_MAP_START( master_finallap_am, ADDRESS_SPACE_PROGRAM, 16 )
620620   AM_RANGE(0x000000, 0x03ffff) AM_READ(SMH_ROM) AM_WRITE(SMH_ROM)
621621   AM_RANGE(0x100000, 0x10ffff) AM_READ(NAMCOS2_68K_MASTER_RAM_R) AM_WRITE(NAMCOS2_68K_MASTER_RAM_W)
622   AM_RANGE(0x180000, 0x183fff) AM_READ(NAMCOS2_68K_EEPROM_R) AM_WRITE(NAMCOS2_68K_EEPROM_W)
622   AM_RANGE(0x180000, 0x183fff) AM_READ(NAMCOS2_68K_eeprom_R) AM_WRITE(NAMCOS2_68K_eeprom_W)
623623   AM_RANGE(0x1c0000, 0x1fffff) AM_READ(namcos2_68k_master_C148_r) AM_WRITE(namcos2_68k_master_C148_w)
624624ADDRESS_MAP_END
625625
r2762r2763
641641static ADDRESS_MAP_START( master_sgunner_am, ADDRESS_SPACE_PROGRAM, 16 )
642642   AM_RANGE(0x000000, 0x03ffff) AM_READ(SMH_ROM) AM_WRITE(SMH_ROM)
643643   AM_RANGE(0x100000, 0x10ffff) AM_READ(NAMCOS2_68K_MASTER_RAM_R) AM_WRITE(NAMCOS2_68K_MASTER_RAM_W)
644   AM_RANGE(0x180000, 0x183fff) AM_READ(NAMCOS2_68K_EEPROM_R) AM_WRITE(NAMCOS2_68K_EEPROM_W)
644   AM_RANGE(0x180000, 0x183fff) AM_READ(NAMCOS2_68K_eeprom_R) AM_WRITE(NAMCOS2_68K_eeprom_W)
645645   AM_RANGE(0x1c0000, 0x1fffff) AM_READ(namcos2_68k_master_C148_r) AM_WRITE(namcos2_68k_master_C148_w)
646646ADDRESS_MAP_END
647647
r2762r2763
664664static ADDRESS_MAP_START( master_metlhawk_am, ADDRESS_SPACE_PROGRAM, 16 )
665665   AM_RANGE(0x000000, 0x03ffff) AM_READ(SMH_ROM) AM_WRITE(SMH_ROM)
666666   AM_RANGE(0x100000, 0x10ffff) AM_READ(NAMCOS2_68K_MASTER_RAM_R) AM_WRITE(NAMCOS2_68K_MASTER_RAM_W)
667   AM_RANGE(0x180000, 0x183fff) AM_READ(NAMCOS2_68K_EEPROM_R) AM_WRITE(NAMCOS2_68K_EEPROM_W)
667   AM_RANGE(0x180000, 0x183fff) AM_READ(NAMCOS2_68K_eeprom_R) AM_WRITE(NAMCOS2_68K_eeprom_W)
668668   AM_RANGE(0x1c0000, 0x1fffff) AM_READ(namcos2_68k_master_C148_r) AM_WRITE(namcos2_68k_master_C148_w)
669669ADDRESS_MAP_END
670670
r2762r2763
692692static ADDRESS_MAP_START( master_luckywld_am, ADDRESS_SPACE_PROGRAM, 16 )
693693   AM_RANGE(0x000000, 0x03ffff) AM_READ(SMH_ROM) AM_WRITE(SMH_ROM)
694694   AM_RANGE(0x100000, 0x10ffff) AM_READ(NAMCOS2_68K_MASTER_RAM_R) AM_WRITE(NAMCOS2_68K_MASTER_RAM_W)
695   AM_RANGE(0x180000, 0x183fff) AM_READ(NAMCOS2_68K_EEPROM_R) AM_WRITE(NAMCOS2_68K_EEPROM_W)
695   AM_RANGE(0x180000, 0x183fff) AM_READ(NAMCOS2_68K_eeprom_R) AM_WRITE(NAMCOS2_68K_eeprom_W)
696696   AM_RANGE(0x1c0000, 0x1fffff) AM_READ(namcos2_68k_master_C148_r) AM_WRITE(namcos2_68k_master_C148_w)
697697ADDRESS_MAP_END
698698
src/mame/drivers/tecmosys.c
r2762r2763
311311
312312static READ16_HANDLER( eeprom_r )
313313{
314    return ((EEPROM_read_bit() & 0x01) << 11);
314    return ((eeprom_read_bit() & 0x01) << 11);
315315}
316316
317317
r2762r2763
339339{
340340   if ( ACCESSING_BITS_8_15 )
341341   {
342      EEPROM_write_bit(data & 0x0800);
343      EEPROM_set_cs_line((data & 0x0200) ? CLEAR_LINE : ASSERT_LINE );
344      EEPROM_set_clock_line((data & 0x0400) ? CLEAR_LINE: ASSERT_LINE );
342      eeprom_write_bit(data & 0x0800);
343      eeprom_set_cs_line((data & 0x0200) ? CLEAR_LINE : ASSERT_LINE );
344      eeprom_set_clock_line((data & 0x0400) ? CLEAR_LINE: ASSERT_LINE );
345345   }
346346}
347347
src/mame/drivers/konamigv.c
r2762r2763
138138{
139139   if( read_or_write )
140140   {
141      EEPROM_save( file );
141      eeprom_save( file );
142142   }
143143   else
144144   {
145      EEPROM_init( &eeprom_interface_93C46 );
145      eeprom_init( &eeprom_interface_93C46 );
146146
147147      if( file )
148148      {
149         EEPROM_load( file );
149         eeprom_load( file );
150150      }
151151      else
152152      {
153         EEPROM_set_data( memory_region( REGION_USER2 ), memory_region_length( REGION_USER2 ) );
153         eeprom_set_data( memory_region( REGION_USER2 ), memory_region_length( REGION_USER2 ) );
154154      }
155155   }
156156}
157157
158static CUSTOM_INPUT( eeprom_bit_r )
159{
160   return EEPROM_read_bit();
161}
162
163158static WRITE32_HANDLER( eeprom_w )
164159{
165   EEPROM_write_bit((data&0x01) ? 1 : 0);
166   EEPROM_set_clock_line((data&0x04) ? ASSERT_LINE : CLEAR_LINE);
167   EEPROM_set_cs_line((data&0x02) ? CLEAR_LINE : ASSERT_LINE);
160   eeprom_write_bit((data&0x01) ? 1 : 0);
161   eeprom_set_clock_line((data&0x04) ? ASSERT_LINE : CLEAR_LINE);
162   eeprom_set_cs_line((data&0x02) ? CLEAR_LINE : ASSERT_LINE);
168163}
169164
170165static WRITE32_HANDLER( mb89371_w )
src/mame/drivers/stlforce.c
r2762r2763
8686
8787static READ16_HANDLER( stlforce_input_port_1_r )
8888{
89   return (input_port_read_indexed(machine, 1) & ~0x40) | (EEPROM_read_bit() << 6);
89   return (input_port_read_indexed(machine, 1) & ~0x40) | (eeprom_read_bit() << 6);
9090}
9191
9292static WRITE16_HANDLER( eeprom_w )
9393{
9494   if( ACCESSING_BITS_0_7 )
9595   {
96      EEPROM_write_bit(data & 0x01);
97      EEPROM_set_cs_line((data & 0x02) ? CLEAR_LINE : ASSERT_LINE );
98      EEPROM_set_clock_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE );
96      eeprom_write_bit(data & 0x01);
97      eeprom_set_cs_line((data & 0x02) ? CLEAR_LINE : ASSERT_LINE );
98      eeprom_set_clock_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE );
9999   }
100100}
101101
r2762r2763
223223static NVRAM_HANDLER( stlforce )
224224{
225225   if (read_or_write)
226      EEPROM_save(file);
226      eeprom_save(file);
227227   else
228228   {
229      EEPROM_init(&eeprom_interface_93C46);
229      eeprom_init(&eeprom_interface_93C46);
230230      if (file)
231231      {
232         EEPROM_load(file);
232         eeprom_load(file);
233233      }
234234      else
235235      {
236         EEPROM_set_data(default_eeprom,128);
236         eeprom_set_data(default_eeprom,128);
237237      }
238238   }
239239}
src/mame/drivers/zr107.c
r2762r2763
191191   {
192192      if (ACCESSING_BITS_24_31)
193193      {
194         r |= ((adc083x_sars_read(0) << 5) | (EEPROM_read_bit() << 4)) << 24;
194         r |= ((adc083x_sars_read(0) << 5) | (eeprom_read_bit() << 4)) << 24;
195195      }
196196   }
197197   //mame_printf_debug("sysreg_r: %08X, %08X at %08X\n", offset, mem_mask, activecpu_get_pc());
r2762r2763
212212      }
213213      if (ACCESSING_BITS_0_7)
214214      {
215         EEPROM_write_bit((data & 0x1) ? 1 : 0);
216         EEPROM_set_clock_line((data & 0x2) ? ASSERT_LINE : CLEAR_LINE);
217         EEPROM_set_cs_line((data & 0x4) ? CLEAR_LINE : ASSERT_LINE);
215         eeprom_write_bit((data & 0x1) ? 1 : 0);
216         eeprom_set_clock_line((data & 0x2) ? ASSERT_LINE : CLEAR_LINE);
217         eeprom_set_cs_line((data & 0x4) ? CLEAR_LINE : ASSERT_LINE);
218218
219219         if (data & 0x10)
220220            cpunum_set_input_line(machine, 1, INPUT_LINE_RESET, CLEAR_LINE);
src/mame/drivers/segae.c
r2762r2763
17001700   PORT_DIPNAME( 0x02, 0x00, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("SW2:2")
17011701   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
17021702   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1703   PORT_DIPUNUSED_DIPLOC( 0x40, 0x40, "SW2:3" )
1704   PORT_DIPUNUSED_DIPLOC( 0x80, 0x80, "SW2:4" )
1703   PORT_DIPUNUSED_DIPLOC( 0x04, 0x04, "SW2:3" )
1704   PORT_DIPUNUSED_DIPLOC( 0x08, 0x08, "SW2:4" )
17051705   PORT_DIPNAME( 0x30, 0x30, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SW2:5,6")
17061706   PORT_DIPSETTING(    0x20, DEF_STR( Easy ) )
17071707   PORT_DIPSETTING(    0x30, DEF_STR( Normal ) )
src/mame/drivers/midas.c
r2762r2763
180180
181181static READ16_HANDLER( livequiz_eeprom_r )
182182{
183   return input_port_read_indexed(machine, 2) | (EEPROM_read_bit() << 3);
183   return input_port_read_indexed(machine, 2) | (eeprom_read_bit() << 3);
184184}
185185
186186static WRITE16_HANDLER( livequiz_eeprom_w )
r2762r2763
188188   if (ACCESSING_BITS_0_7)
189189   {
190190      // latch the bit
191      EEPROM_write_bit(data & 0x04);
191      eeprom_write_bit(data & 0x04);
192192
193193      // reset line asserted: reset.
194      EEPROM_set_cs_line((data & 0x01) ? CLEAR_LINE : ASSERT_LINE );
194      eeprom_set_cs_line((data & 0x01) ? CLEAR_LINE : ASSERT_LINE );
195195
196196      // clock line asserted: write latch or select next bit to read
197      EEPROM_set_clock_line((data & 0x02) ? ASSERT_LINE : CLEAR_LINE );
197      eeprom_set_clock_line((data & 0x02) ? ASSERT_LINE : CLEAR_LINE );
198198   }
199199}
200200
src/mame/drivers/overdriv.c
r2762r2763
9797};
9898
9999
100static const struct EEPROM_interface eeprom_interface =
100static const eeprom_interface eeprom_intf =
101101{
102102   6,            /* address bits */
103103   16,            /* data bits */
r2762r2763
111111static NVRAM_HANDLER( overdriv )
112112{
113113   if (read_or_write)
114      EEPROM_save(file);
114      eeprom_save(file);
115115   else
116116   {
117      EEPROM_init(&eeprom_interface);
117      eeprom_init(&eeprom_intf);
118118
119119      if (file)
120         EEPROM_load(file);
120         eeprom_load(file);
121121      else
122         EEPROM_set_data(default_eeprom,sizeof(default_eeprom));
122         eeprom_set_data(default_eeprom,sizeof(default_eeprom));
123123   }
124124}
125125
r2762r2763
129129
130130//logerror("%06x eeprom_r\n",activecpu_get_pc());
131131   /* bit 6 is EEPROM data */
132   res = (EEPROM_read_bit() << 6) | input_port_read_indexed(machine,0);
132   res = (eeprom_read_bit() << 6) | input_port_read_indexed(machine,0);
133133
134134   return res;
135135}
r2762r2763
142142      /* bit 0 is data */
143143      /* bit 1 is clock (active high) */
144144      /* bit 2 is cs (active low) */
145      EEPROM_write_bit(data & 0x01);
146      EEPROM_set_cs_line((data & 0x04) ? CLEAR_LINE : ASSERT_LINE);
147      EEPROM_set_clock_line((data & 0x02) ? ASSERT_LINE : CLEAR_LINE);
145      eeprom_write_bit(data & 0x01);
146      eeprom_set_cs_line((data & 0x04) ? CLEAR_LINE : ASSERT_LINE);
147      eeprom_set_clock_line((data & 0x02) ? ASSERT_LINE : CLEAR_LINE);
148148   }
149149}
150150
src/mame/drivers/jackpool.c
r2762r2763
216216   ROM_LOAD( "jpc7", 0xc0000, 0x40000,  CRC(b1d40623) SHA1(fb76ae6b53474bd4bee19dbce9537da0f2b63ff4) )
217217ROM_END
218218
219ROM_START( suprpool )
220   ROM_REGION( 0x40000, REGION_CPU1, 0 ) /* 68000 Code */
221   ROM_LOAD16_BYTE( "3-1.22a.u2", 0x00001, 0x20000,CRC(c762cd1c) SHA1(ee05a9e8147d613eb14333e6e7b743fc05982e7c) )
222   ROM_LOAD16_BYTE( "2-1.22a.u3", 0x00000, 0x20000,CRC(5d15037a) SHA1(74cab79a1b08910267262a4c6b501126a4df6cda) )
223
224   ROM_REGION( 0x080000, REGION_SOUND1, 0 ) /* Samples */
225   ROM_LOAD( "1.u32", 0x00000, 0x40000, CRC(47804af7) SHA1(602dc0361869b52532e2adcb0de3cbdd042761b3) )
226
227   ROM_REGION( 0x80000, REGION_GFX1, 0 ) /* Sprites */
228   ROM_LOAD( "4.u38", 0x00000, 0x20000,  CRC(0660a169) SHA1(1cb34b3da4b144028519a3c5b32ef7da44af0624) )
229   ROM_LOAD( "5.u37", 0x20000, 0x20000,  CRC(6e99af07) SHA1(85e7a76724fd9ce8d07b5088cb6e0d933fd95692) )
230   ROM_LOAD( "6.u36", 0x40000, 0x20000,  CRC(c4448813) SHA1(6e168eb8503b852179f2d743f1cba935592e0a60) )
231   ROM_LOAD( "7.u35", 0x60000, 0x20000,  CRC(357d145f) SHA1(9fea0d0c5d6c27bf520c4f81eb0f48a65ff60142) )
232ROM_END
233
234219GAME( 1997, jackpool, 0, jackpool, jackpool, 0, ROT0, "Electronic Projects", "Jackpot Pool (Italy, bootleg)",GAME_NOT_WORKING )
235GAME( 1997, suprpool, 0, jackpool, jackpool, 0, ROT0, "Nazionale Elettronica Giochi S.A.S.", "Super Pool (Italy)",GAME_NOT_WORKING )
src/mame/drivers/xmen.c
r2762r2763
3939static int init_eeprom_count;
4040
4141
42static const struct EEPROM_interface eeprom_interface =
42static const eeprom_interface eeprom_intf =
4343{
4444   7,            /* address bits */
4545   8,            /* data bits */
r2762r2763
5353static NVRAM_HANDLER( xmen )
5454{
5555   if (read_or_write)
56      EEPROM_save(file);
56      eeprom_save(file);
5757   else
5858   {
59      EEPROM_init(&eeprom_interface);
59      eeprom_init(&eeprom_intf);
6060
6161      if (file)
6262      {
6363         init_eeprom_count = 0;
64         EEPROM_load(file);
64         eeprom_load(file);
6565      }
6666      else
6767         init_eeprom_count = 10;
r2762r2763
7676   /* bit 6 is EEPROM data */
7777   /* bit 7 is EEPROM ready */
7878   /* bit 14 is service button */
79   res = (EEPROM_read_bit() << 6) | input_port_read_indexed(machine,2);
79   res = (eeprom_read_bit() << 6) | input_port_read_indexed(machine,2);
8080   if (init_eeprom_count)
8181   {
8282      init_eeprom_count--;
r2762r2763
9393   /* bit 6 is EEPROM data */
9494   /* bit 7 is EEPROM ready */
9595   /* bit 14 is service button */
96   res = (EEPROM_read_bit() << 6) | input_port_read_indexed(machine,2);
96   res = (eeprom_read_bit() << 6) | input_port_read_indexed(machine,2);
9797   if (init_eeprom_count)
9898   {
9999      init_eeprom_count--;
r2762r2763
114114      /* bit 2 is data */
115115      /* bit 3 is clock (active high) */
116116      /* bit 4 is cs (active low) */
117      EEPROM_write_bit(data & 0x04);
118      EEPROM_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
119      EEPROM_set_clock_line((data & 0x08) ? ASSERT_LINE : CLEAR_LINE);
117      eeprom_write_bit(data & 0x04);
118      eeprom_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
119      eeprom_set_clock_line((data & 0x08) ? ASSERT_LINE : CLEAR_LINE);
120120   }
121121   if (ACCESSING_BITS_8_15)
122122   {
src/mame/drivers/lethal.c
r2762r2763
194194   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
195195};
196196
197static const struct EEPROM_interface eeprom_interface =
197static const eeprom_interface eeprom_intf =
198198{
199199   7,         /* address bits */
200200   8,         /* data bits */
r2762r2763
208208static NVRAM_HANDLER( lethalen )
209209{
210210   if (read_or_write)
211      EEPROM_save(file);
211      eeprom_save(file);
212212   else
213213   {
214      EEPROM_init(&eeprom_interface);
214      eeprom_init(&eeprom_intf);
215215
216216      if (file)
217217      {
218218         init_eeprom_count = 0;
219         EEPROM_load(file);
219         eeprom_load(file);
220220      }
221221      else
222222      {
223223         init_eeprom_count = 10;
224         EEPROM_set_data(lethalen_default_eeprom,48);
224         eeprom_set_data(lethalen_default_eeprom,48);
225225
226226      }
227227   }
r2762r2763
229229
230230static READ8_HANDLER( control2_r )
231231{
232   return 0x02 | EEPROM_read_bit() | (input_port_read_indexed(machine, 1) & 0xf0);
232   return 0x02 | eeprom_read_bit() | (input_port_read_indexed(machine, 1) & 0xf0);
233233}
234234
235235static WRITE8_HANDLER( control2_w )
r2762r2763
244244
245245   cur_control2 = data;
246246
247   EEPROM_write_bit(cur_control2 & 0x01);
248   EEPROM_set_cs_line((cur_control2 & 0x02) ? CLEAR_LINE : ASSERT_LINE);
249   EEPROM_set_clock_line((cur_control2 & 0x04) ? ASSERT_LINE : CLEAR_LINE);
247   eeprom_write_bit(cur_control2 & 0x01);
248   eeprom_set_cs_line((cur_control2 & 0x02) ? CLEAR_LINE : ASSERT_LINE);
249   eeprom_set_clock_line((cur_control2 & 0x04) ? ASSERT_LINE : CLEAR_LINE);
250250}
251251
252252static INTERRUPT_GEN(lethalen_interrupt)
src/mame/drivers/gunbustr.c
r2762r2763
9292      case 0x00:
9393      {
9494         return (input_port_read_indexed(machine,0) << 16) | input_port_read_indexed(machine,1) |
95              (EEPROM_read_bit() << 7);
95              (eeprom_read_bit() << 7);
9696      }
9797
9898      case 0x01:
r2762r2763
130130
131131         if (ACCESSING_BITS_0_7)
132132         {
133            EEPROM_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
134            EEPROM_write_bit(data & 0x40);
135            EEPROM_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
133            eeprom_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
134            eeprom_write_bit(data & 0x40);
135            eeprom_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
136136            return;
137137         }
138138         return;
r2762r2763
347347   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
348348};
349349
350static const struct EEPROM_interface gunbustr_eeprom_interface =
350static const eeprom_interface gunbustr_eeprom_interface =
351351{
352352   6,            /* address bits */
353353   16,            /* data bits */
r2762r2763
361361static NVRAM_HANDLER( gunbustr )
362362{
363363   if (read_or_write)
364      EEPROM_save(file);
364      eeprom_save(file);
365365   else {
366      EEPROM_init(&gunbustr_eeprom_interface);
366      eeprom_init(&gunbustr_eeprom_interface);
367367      if (file)
368         EEPROM_load(file);
368         eeprom_load(file);
369369      else
370         EEPROM_set_data(default_eeprom,128);  /* Default the gun setup values */
370         eeprom_set_data(default_eeprom,128);  /* Default the gun setup values */
371371   }
372372}
373373
src/mame/drivers/taito_z.c
r2762r2763
957957   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
958958};
959959
960static const struct EEPROM_interface eeprom_interface =
960static const eeprom_interface eeprom_intf =
961961{
962962   6,            /* address bits */
963963   16,            /* data bits */
r2762r2763
971971static NVRAM_HANDLER( spacegun )
972972{
973973   if (read_or_write)
974      EEPROM_save(file);
974      eeprom_save(file);
975975   else
976976   {
977      EEPROM_init(&eeprom_interface);
977      eeprom_init(&eeprom_intf);
978978
979979      if (file)
980         EEPROM_load(file);
980         eeprom_load(file);
981981      else
982         EEPROM_set_data(default_eeprom,128);  /* Default the gun setup values */
982         eeprom_set_data(default_eeprom,128);  /* Default the gun setup values */
983983   }
984984}
985985
986986static int eeprom_r(void)
987987{
988   return (EEPROM_read_bit() & 0x01)<<7;
988   return (eeprom_read_bit() & 0x01)<<7;
989989}
990990
991991#if 0
r2762r2763
10081008            x0000000    (unused)                  */
10091009
10101010         COMBINE_DATA(&eep_latch);
1011         EEPROM_write_bit(data & 0x40);
1012         EEPROM_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
1013         EEPROM_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
1011         eeprom_write_bit(data & 0x40);
1012         eeprom_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
1013         eeprom_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
10141014         break;
10151015
10161016      default:
src/mame/drivers/pntnpuzl.c
r2762r2763
124124#include "machine/eeprom.h"
125125
126126
127static const struct EEPROM_interface eeprom_interface =
127static const eeprom_interface eeprom_intf =
128128{
129129   6,            /* address bits */
130130   16,            /* data bits */
r2762r2763
138138static NVRAM_HANDLER( pntnpuzl )
139139{
140140   if (read_or_write)
141      EEPROM_save(file);
141      eeprom_save(file);
142142   else
143143   {
144      EEPROM_init(&eeprom_interface);
144      eeprom_init(&eeprom_intf);
145145
146146      if (file)
147         EEPROM_load(file);
147         eeprom_load(file);
148148      else
149149      {
150150         int length;
151151         UINT8 *dat;
152152
153         dat = EEPROM_get_data_pointer(&length);
153         dat = eeprom_get_data_pointer(&length);
154154         memset(dat, 0, length);
155155      }
156156   }
r2762r2763
161161static READ16_HANDLER( pntnpuzl_eeprom_r )
162162{
163163   /* bit 11 is EEPROM data */
164   return (pntnpuzl_eeprom & 0xf4ff) | (EEPROM_read_bit()<<11) | (input_port_read_indexed(machine, 3) & 0x0300);
164   return (pntnpuzl_eeprom & 0xf4ff) | (eeprom_read_bit()<<11) | (input_port_read_indexed(machine, 3) & 0x0300);
165165}
166166
167167static WRITE16_HANDLER( pntnpuzl_eeprom_w )
r2762r2763
172172   /* bit 13 is clock (active high) */
173173   /* bit 14 is cs (active high) */
174174
175   EEPROM_write_bit(data & 0x1000);
176   EEPROM_set_cs_line((data & 0x4000) ? CLEAR_LINE : ASSERT_LINE);
177   EEPROM_set_clock_line((data & 0x2000) ? ASSERT_LINE : CLEAR_LINE);
175   eeprom_write_bit(data & 0x1000);
176   eeprom_set_cs_line((data & 0x4000) ? CLEAR_LINE : ASSERT_LINE);
177   eeprom_set_clock_line((data & 0x2000) ? ASSERT_LINE : CLEAR_LINE);
178178}
179179
180180
src/mame/drivers/gijoe.c
r2762r2763
5252static int init_eeprom_count;
5353static emu_timer *dmadelay_timer;
5454
55static const struct EEPROM_interface eeprom_interface =
55static const eeprom_interface eeprom_intf =
5656{
5757   7,            /* address bits */
5858   8,            /* data bits */
r2762r2763
6666#if 0
6767static void eeprom_init(void)
6868{
69   EEPROM_init(&eeprom_interface);
69   eeprom_init(&eeprom_intf);
7070   init_eeprom_count = 0;
7171}
7272#endif
r2762r2763
7474static NVRAM_HANDLER( gijoe )
7575{
7676   if (read_or_write)
77      EEPROM_save(file);
77      eeprom_save(file);
7878   else
7979   {
80      EEPROM_init(&eeprom_interface);
80      eeprom_init(&eeprom_intf);
8181
8282      if (file)
8383      {
8484         init_eeprom_count = 0;
85         EEPROM_load(file);
85         eeprom_load(file);
8686      }
8787      else
8888         init_eeprom_count = 2720;
r2762r2763
9696   /* bit 8  is EEPROM data */
9797   /* bit 9  is EEPROM ready */
9898   /* bit 11 is service button */
99   res = (EEPROM_read_bit()<<8) | input_port_read_indexed(machine,0);
99   res = (eeprom_read_bit()<<8) | input_port_read_indexed(machine,0);
100100
101101   if (init_eeprom_count)
102102   {
r2762r2763
122122      /* bit 5  is enable irq 6 */
123123      /* bit 7  (unknown: enable irq 5?) */
124124
125      EEPROM_write_bit(data & 0x01);
126      EEPROM_set_cs_line((data & 0x02) ? CLEAR_LINE : ASSERT_LINE);
127      EEPROM_set_clock_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE);
125      eeprom_write_bit(data & 0x01);
126      eeprom_set_cs_line((data & 0x02) ? CLEAR_LINE : ASSERT_LINE);
127      eeprom_set_clock_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE);
128128      cur_control2 = data;
129129
130130      /* bit 6 = enable sprite ROM reading */
src/mame/drivers/wilytowr.c
r2762r2763
506506static MACHINE_DRIVER_START( wilytowr )
507507
508508   /* basic machine hardware */
509   MDRV_CPU_ADD(Z80,4000000)   /* 4 MHz ???? */
509   MDRV_CPU_ADD(Z80,12000000/4)     /* 3 MHz */
510510   MDRV_CPU_PROGRAM_MAP(wilytowr_map,0)
511511   MDRV_CPU_VBLANK_INT("main", nmi_line_pulse)
512512
513513   /* audio CPU */
514   MDRV_CPU_ADD(I8039,8000000)   /* ????? */
514   MDRV_CPU_ADD(I8039,12000000/4)   /* ????? */
515515   MDRV_CPU_PROGRAM_MAP(i8039_map,0)
516516   MDRV_CPU_IO_MAP(i8039_port_map,0)
517517
r2762r2763
635635   ROM_LOAD( "wt_a-4m.bin",  0x8000, 0x2000, CRC(c1f8a7d5) SHA1(4307e7604aec728a1f5b0e6a0d6c9f4d37084da3) )
636636   ROM_LOAD( "wt_a-4n.bin",  0xa000, 0x2000, CRC(b212f7d2) SHA1(dd1c35559982e8bbcb0e778c733a3afb5b6611df) )
637637
638   ROM_REGION( 0x2000, REGION_CPU2, 0 )   /* 8039 */
639   ROM_LOAD( "wt_a-4d-b.bin",  0x0000, 0x2000, CRC(793ea53f) SHA1(9dbff5e011a1f1f48aad68f8e5b02bcdb86c182a) ) /* 2764 ROM, Also had a red dot on label */
640
641   ROM_REGION( 0x2000, REGION_GFX1, ROMREGION_DISPOSE )
642   /* '3' character is bad, but ROMs have been verified on four boards */
643   ROM_LOAD( "wt_b-5e.bin",  0x0000, 0x1000, CRC(fe45df43) SHA1(9586a5728069e0c293bd17d4663305ce5758ca01) )
644   ROM_LOAD( "wt_b-5f.bin",  0x1000, 0x1000, CRC(87a17eff) SHA1(cee2ba2889baf08dc6ee1c8e9150bd277f343be9) )
645
646   ROM_REGION( 0x6000, REGION_GFX2, ROMREGION_DISPOSE )
647   ROM_LOAD( "wt_b-5a.bin",  0x0000, 0x2000, CRC(da22c452) SHA1(bd921baa12087e996d07625e05eda00981608655) )
648   ROM_LOAD( "wt_b-5b.bin",  0x2000, 0x2000, CRC(4fb25a1f) SHA1(0f90fb3b373760c33ba9be3b56b917eca92c9700) )
649   ROM_LOAD( "wt_b-5d.bin",  0x4000, 0x2000, CRC(75be2604) SHA1(fe1f110e188aa34a04a9f43412a8308240391fcf) )
650
651   ROM_REGION( 0xc000, REGION_GFX3, ROMREGION_DISPOSE )
652   ROM_LOAD( "wt_a-3j-b.bin",  0x0000, 0x2000, CRC(996470f1) SHA1(c0c787a73535917d1314bb2e1e9056aea9859205) ) /* All these ROMs are 2764 type/size */
653   ROM_LOAD( "wt_a-3k-b.bin",  0x2000, 0x2000, CRC(8f4ec45c) SHA1(525393e0555e1aa24df74e8095da216f02fe3c65) )
654   ROM_LOAD( "wt_a-3m-b.bin",  0x4000, 0x2000, CRC(4ac40358) SHA1(c71bd62ef1e8d008abd468c193e67b278599a5f3) )
655   ROM_LOAD( "wt_a-3n-b.bin",  0x6000, 0x2000, CRC(709eef5b) SHA1(95beadcf876a2549836329521f1293634413e983) )
656   ROM_LOAD( "wt_a-3p-b.bin",  0x8000, 0x2000, CRC(3018b840) SHA1(77df9d4f1c8d76d30c435d03d51ef9e7509fab9c) )
657   ROM_LOAD( "wt_a-3s-b.bin",  0xa000, 0x2000, CRC(05a251d4) SHA1(1cd9102871507ab988d5fe799024d63b93807448) )
658
659   ROM_REGION( 0x1000, REGION_USER1, 0 )   /* unknown; sound? */
660   ROM_LOAD( "wt_a-6d.bin",  0x0000, 0x1000, CRC(a5dde29b) SHA1(8f7545d2022da7c98d47112179dce717f6c3c5e2) )
661
662   ROM_REGION( 0x0320, REGION_PROMS, 0 )
663   ROM_LOAD( "wt_a-5s-b.bpr", 0x0000, 0x0100, CRC(991e2a04) SHA1(a70525948ad85ad898e0d8a25fb6d1639a4ec133) )   /* red    TBP24S10 (read as 82s129) */
664   ROM_LOAD( "wt_a-5r-b.bpr", 0x0100, 0x0100, CRC(fb3822b7) SHA1(bb1ecdd0156acc16bef3c9072e496e4f544b5d9d) )   /* green  TBP24S10 (read as 82s129) */
665   ROM_LOAD( "wt_a-5p-b.bpr", 0x0200, 0x0100, CRC(95849f7d) SHA1(ad031d6035045b19c1cd65ac6a78c5aa4b647cd6) )   /* blue   TBP24S10 (read as 82s129) */
666   ROM_LOAD( "wt_b-9l-.bpr",  0x0300, 0x0020, CRC(d2728744) SHA1(e6b1a570854ca90326414874432ab03ec85b9c8e) )   /* char palette */
667ROM_END
668
669ROM_START( atomboya )
670   ROM_REGION( 0x10000, REGION_CPU1, 0 )
671   ROM_LOAD( "wt_a-4e.bin",  0x0000, 0x2000, CRC(f7978185) SHA1(6a108d1e9b1a81cedf865aba3998748dcf1d55ef) )
672   ROM_LOAD( "wt_a-4h.bin",  0x2000, 0x2000, CRC(0ca9950b) SHA1(d6583fcdf17d16a8884932695caa9c5587a20795) )
673   ROM_LOAD( "wt_a-4j.bin",  0x4000, 0x2000, CRC(1badbc65) SHA1(e0768f2cd7bbe8908fd68ff6d54dbef84cc7de4c) )
674   ROM_LOAD( "wt_a-4k.bin",  0x6000, 0x2000, CRC(5a341f75) SHA1(9e1a180e37aaa0afbf8ff45219be40d3f75fe60a) )
675   ROM_LOAD( "wt_a-4m.bin",  0x8000, 0x2000, CRC(c1f8a7d5) SHA1(4307e7604aec728a1f5b0e6a0d6c9f4d37084da3) )
676   ROM_LOAD( "wt_a-4n.bin",  0xa000, 0x2000, CRC(b212f7d2) SHA1(dd1c35559982e8bbcb0e778c733a3afb5b6611df) )
677
638678   ROM_REGION( 0x1000, REGION_CPU2, 0 )   /* 8039 */
639679   ROM_LOAD( "wt_a-4d.bin",  0x0000, 0x1000, CRC(3d43361e) SHA1(2977df9f90d9d214909c56ab44c40ab45fd90675) )
640680
r2762r2763
721761}
722762
723763GAME( 1984, wilytowr, 0,        wilytowr, wilytowr, wilytowr, ROT180, "Irem",                    "Wily Tower", GAME_NO_SOUND )
724GAME( 1985, atomboy,  wilytowr, wilytowr, wilytowr, wilytowr, ROT180, "Irem (Memetron license)", "Atomic Boy", GAME_NO_SOUND )
764GAME( 1985, atomboy,  wilytowr, wilytowr, wilytowr, wilytowr, ROT180, "Irem (Memetron license)", "Atomic Boy (revision B)", GAME_NO_SOUND )
765GAME( 1985, atomboya, wilytowr, wilytowr, wilytowr, wilytowr, ROT180, "Irem (Memetron license)", "Atomic Boy (revision A)", GAME_NO_SOUND )
725766GAME( 1984, fghtbskt, 0,        fghtbskt, fghtbskt, fghtbskt, ROT0,   "Paradise Co. Ltd.",       "Fighting Basketball", GAME_IMPERFECT_SOUND )
src/mame/drivers/segas32.c
r2762r2763
584584 *
585585 *************************************/
586586
587static CUSTOM_INPUT( eeprom_bit_r )
588{
589   return EEPROM_read_bit();
590}
591
592
593587static UINT16 common_io_chip_r(running_machine *machine, int which, offs_t offset, UINT16 mem_mask)
594588{
595589   offset &= 0x1f/2;
r2762r2763
664658      case 0x06/2:
665659         if (which == 0)
666660         {
667            EEPROM_write_bit(data & 0x80);
668            EEPROM_set_cs_line((data & 0x20) ? CLEAR_LINE : ASSERT_LINE);
669            EEPROM_set_clock_line((data & 0x40) ? ASSERT_LINE : CLEAR_LINE);
661            eeprom_write_bit(data & 0x80);
662            eeprom_set_cs_line((data & 0x20) ? CLEAR_LINE : ASSERT_LINE);
663            eeprom_set_clock_line((data & 0x40) ? ASSERT_LINE : CLEAR_LINE);
670664         }
671665/*            coin_lockout_w(1 + 2*which, data & 0x08);
672666            coin_lockout_w(0 + 2*which, data & 0x04);*/
r2762r2763
681675         else
682676         {
683677            /* multi-32 EEPROM access */
684            EEPROM_write_bit(data & 0x80);
685            EEPROM_set_cs_line((data & 0x20) ? CLEAR_LINE : ASSERT_LINE);
686            EEPROM_set_clock_line((data & 0x40) ? ASSERT_LINE : CLEAR_LINE);
678            eeprom_write_bit(data & 0x80);
679            eeprom_set_cs_line((data & 0x20) ? CLEAR_LINE : ASSERT_LINE);
680            eeprom_set_clock_line((data & 0x40) ? ASSERT_LINE : CLEAR_LINE);
687681         }
688682         break;
689683
r2762r2763
11611155static NVRAM_HANDLER( system32 )
11621156{
11631157   if (read_or_write)
1164      EEPROM_save(file);
1158      eeprom_save(file);
11651159   else
11661160   {
1167      EEPROM_init(&eeprom_interface_93C46);
1161      eeprom_init(&eeprom_interface_93C46);
11681162
11691163      if (file)
1170         EEPROM_load(file);
1164         eeprom_load(file);
11711165      else if (system32_default_eeprom != NULL)
1172         EEPROM_set_data(system32_default_eeprom, 0x80);
1166         eeprom_set_data(system32_default_eeprom, 0x80);
11731167   }
11741168}
11751169
src/mame/drivers/psikyosh.c
r2762r2763
318318   GFXDECODE_ENTRY( REGION_GFX1, 0, layout_16x16x8, 0x000, 0x100 ) // 8bpp tiles
319319GFXDECODE_END
320320
321static const struct EEPROM_interface eeprom_interface_93C56 =
321static const eeprom_interface eeprom_interface_93C56 =
322322{
323323   8,      // address bits 8
324324   8,      // data bits    8
r2762r2763
335335{
336336   if (read_or_write)
337337   {
338      EEPROM_save(file);
338      eeprom_save(file);
339339   }
340340   else
341341   {
342      EEPROM_init(&eeprom_interface_93C56);
342      eeprom_init(&eeprom_interface_93C56);
343343      if (file)
344344      {
345         EEPROM_load(file);
345         eeprom_load(file);
346346      }
347347      else   // these games want the eeprom all zeros by default
348348      {
349349         int length;
350350         UINT8 *dat;
351351
352         dat = EEPROM_get_data_pointer(&length);
352         dat = eeprom_get_data_pointer(&length);
353353         memset(dat, 0, length);
354354
355          if (use_factory_eeprom!=EEPROM_0) /* Set the EEPROM to Factory Defaults for games needing them*/
355          if (use_factory_eeprom!=eeprom_0) /* Set the EEPROM to Factory Defaults for games needing them*/
356356          {
357357            UINT8 eeprom_data[0x100];
358358            int i;
r2762r2763
361361
362362            memcpy(eeprom_data, factory_eeprom, 0x10);
363363
364              if (use_factory_eeprom==EEPROM_DARAKU) /* Daraku, replace top 10 bytes with defaults (different to other games) */
364              if (use_factory_eeprom==eeprom_DARAKU) /* Daraku, replace top 10 bytes with defaults (different to other games) */
365365                memcpy(eeprom_data, daraku_eeprom, 0x10);
366366
367            if (use_factory_eeprom==EEPROM_S1945III) /* S1945iii suffers from corruption on highscore unless properly initialised at the end of the eeprom */
367            if (use_factory_eeprom==eeprom_S1945III) /* S1945iii suffers from corruption on highscore unless properly initialised at the end of the eeprom */
368368                memcpy(eeprom_data+0xf0, s1945iii_eeprom, 0x10);
369369
370             if (use_factory_eeprom==EEPROM_DRAGNBLZ) /* Dragnblz too */
370             if (use_factory_eeprom==eeprom_DRAGNBLZ) /* Dragnblz too */
371371                memcpy(eeprom_data+0xf0, dragnblz_eeprom, 0x10);
372372
373             if (use_factory_eeprom==EEPROM_GNBARICH) /* Might as well do Gnbarich as well, otherwise the highscore is incorrect */
373             if (use_factory_eeprom==eeprom_GNBARICH) /* Might as well do Gnbarich as well, otherwise the highscore is incorrect */
374374                memcpy(eeprom_data+0xf0, gnbarich_eeprom, 0x10);
375375
376             if (use_factory_eeprom==EEPROM_MJGTASTE) /* We don't emulate the Mahjong panel yet, so default it to joystick */
376             if (use_factory_eeprom==eeprom_MJGTASTE) /* We don't emulate the Mahjong panel yet, so default it to joystick */
377377            {
378378                memcpy(eeprom_data+0x00, mjgtaste_eeprom, 0x10);
379379               memcpy(eeprom_data+0xf0, mjgtaste_eeprom, 0x10);
380380            }
381381
382            EEPROM_set_data(eeprom_data,0x100);
382            eeprom_set_data(eeprom_data,0x100);
383383         }
384384      }
385385   }
r2762r2763
389389{
390390   if (ACCESSING_BITS_24_31)
391391   {
392      EEPROM_write_bit((data & 0x20000000) ? 1 : 0);
393      EEPROM_set_cs_line((data & 0x80000000) ? CLEAR_LINE : ASSERT_LINE);
394      EEPROM_set_clock_line((data & 0x40000000) ? ASSERT_LINE : CLEAR_LINE);
392      eeprom_write_bit((data & 0x20000000) ? 1 : 0);
393      eeprom_set_cs_line((data & 0x80000000) ? CLEAR_LINE : ASSERT_LINE);
394      eeprom_set_clock_line((data & 0x40000000) ? ASSERT_LINE : CLEAR_LINE);
395395
396396      return;
397397   }
r2762r2763
403403{
404404   if (ACCESSING_BITS_24_31)
405405   {
406      return ((EEPROM_read_bit() << 28) | (input_port_read_indexed(machine, 4) << 24)); /* EEPROM | Region */
406      return ((eeprom_read_bit() << 28) | (input_port_read_indexed(machine, 4) << 24)); /* EEPROM | Region */
407407   }
408408
409409   logerror("Unk EEPROM read mask %x\n", mem_mask);
r2762r2763
12301230static DRIVER_INIT( soldivid )
12311231{
12321232   memory_install_read32_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x600000c, 0x600000f, 0, 0, soldivid_speedup_r );
1233   use_factory_eeprom=EEPROM_0;
1233   use_factory_eeprom=eeprom_0;
12341234}
12351235
12361236static DRIVER_INIT( s1945ii )
12371237{
12381238   memory_install_read32_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x600000c, 0x600000f, 0, 0, s1945ii_speedup_r );
1239   use_factory_eeprom=EEPROM_DEFAULT;
1239   use_factory_eeprom=eeprom_DEFAULT;
12401240}
12411241
12421242static DRIVER_INIT( daraku )
r2762r2763
12441244   UINT8 *RAM = memory_region(REGION_CPU1);
12451245   memory_set_bankptr(1,&RAM[0x100000]);
12461246   memory_install_read32_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x600000c, 0x600000f, 0, 0, daraku_speedup_r );
1247   use_factory_eeprom=EEPROM_DARAKU;
1247   use_factory_eeprom=eeprom_DARAKU;
12481248}
12491249
12501250static DRIVER_INIT( sbomberb )
12511251{
12521252   memory_install_read32_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x600000c, 0x600000f, 0, 0, sbomberb_speedup_r );
1253   use_factory_eeprom=EEPROM_DEFAULT;
1253   use_factory_eeprom=eeprom_DEFAULT;
12541254}
12551255
12561256static DRIVER_INIT( gunbird2 )
r2762r2763
12581258   UINT8 *RAM = memory_region(REGION_CPU1);
12591259   memory_set_bankptr(1,&RAM[0x100000]);
12601260   memory_install_read32_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x604000c, 0x604000f, 0, 0, gunbird2_speedup_r );
1261   use_factory_eeprom=EEPROM_DEFAULT;
1261   use_factory_eeprom=eeprom_DEFAULT;
12621262}
12631263
12641264static DRIVER_INIT( s1945iii )
r2762r2763
12661266   UINT8 *RAM = memory_region(REGION_CPU1);
12671267   memory_set_bankptr(1,&RAM[0x100000]);
12681268   memory_install_read32_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x606000c, 0x606000f, 0, 0, s1945iii_speedup_r );
1269   use_factory_eeprom=EEPROM_S1945III;
1269   use_factory_eeprom=eeprom_S1945III;
12701270}
12711271
12721272static DRIVER_INIT( dragnblz )
12731273{
12741274   memory_install_read32_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x606000c, 0x606000f, 0, 0, dragnblz_speedup_r );
1275   use_factory_eeprom=EEPROM_DRAGNBLZ;
1275   use_factory_eeprom=eeprom_DRAGNBLZ;
12761276}
12771277
12781278static DRIVER_INIT( gnbarich )
12791279{
12801280   memory_install_read32_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x606000c, 0x606000f, 0, 0, gnbarich_speedup_r );
1281   use_factory_eeprom=EEPROM_GNBARICH;
1281   use_factory_eeprom=eeprom_GNBARICH;
12821282}
12831283
12841284static DRIVER_INIT( mjgtaste )
12851285{
12861286   memory_install_read32_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x606000c, 0x606000f, 0, 0, mjgtaste_speedup_r );
1287   use_factory_eeprom=EEPROM_MJGTASTE;
1287   use_factory_eeprom=eeprom_MJGTASTE;
12881288   /* needs to install mahjong controls too (can select joystick in test mode tho) */
12891289}
12901290
src/mame/drivers/darkhors.c
r2762r2763
200200
201201***************************************************************************/
202202
203static const struct EEPROM_interface eeprom_interface =
203static const eeprom_interface eeprom_intf =
204204{
205205   7,            // address bits 7
206206   8,            // data bits    8
r2762r2763
217217static NVRAM_HANDLER( darkhors )
218218{
219219   if (read_or_write)
220      EEPROM_save(file);
220      eeprom_save(file);
221221   else
222222   {
223      EEPROM_init(&eeprom_interface);
223      eeprom_init(&eeprom_intf);
224224
225      if (file) EEPROM_load(file);
225      if (file) eeprom_load(file);
226226      else
227227      {
228228         // Set the EEPROM to Factory Defaults
229         EEPROM_set_data(memory_region(REGION_USER1),(1<<7));
229         eeprom_set_data(memory_region(REGION_USER1),(1<<7));
230230      }
231231   }
232232}
233233
234static READ32_HANDLER( darkhors_eeprom_r )
235{
236   // bit 31?
237   return input_port_read_indexed(machine, 4) | ((EEPROM_read_bit() & 1) << (7+16));
238}
239
240234static WRITE32_HANDLER( darkhors_eeprom_w )
241235{
242236   if (data & ~0xff000000)
r2762r2763
245239   if ( ACCESSING_BITS_24_31 )
246240   {
247241      // latch the bit
248      EEPROM_write_bit(data & 0x04000000);
242      eeprom_write_bit(data & 0x04000000);
249243
250244      // reset line asserted: reset.
251      EEPROM_set_cs_line((data & 0x01000000) ? CLEAR_LINE : ASSERT_LINE );
245      eeprom_set_cs_line((data & 0x01000000) ? CLEAR_LINE : ASSERT_LINE );
252246
253247      // clock line asserted: write latch or select next bit to read
254      EEPROM_set_clock_line((data & 0x02000000) ? ASSERT_LINE : CLEAR_LINE );
248      eeprom_set_clock_line((data & 0x02000000) ? ASSERT_LINE : CLEAR_LINE );
255249   }
256250}
257251
r2762r2763
315309static ADDRESS_MAP_START( darkhors_readmem, ADDRESS_SPACE_PROGRAM, 32 )
316310   AM_RANGE(0x000000, 0x0fffff) AM_READ( SMH_ROM               )
317311   AM_RANGE(0x400000, 0x41ffff) AM_READ( SMH_RAM               )
318   AM_RANGE(0x4e0080, 0x4e0083) AM_READ( darkhors_eeprom_r         )
312   AM_RANGE(0x4e0080, 0x4e0083) AM_READ( input_port_4_dword_r      )
319313   AM_RANGE(0x580000, 0x580003) AM_READ( input_port_0_dword_r      )
320314   AM_RANGE(0x580004, 0x580007) AM_READ( input_port_1_dword_r      )
321315   AM_RANGE(0x580008, 0x58000b) AM_READ( darkhors_input_sel_r      )
r2762r2763
390384   PORT_BIT( 0x00100000, IP_ACTIVE_LOW,  IPT_SERVICE  ) PORT_NAME(DEF_STR( Test )) PORT_CODE(KEYCODE_F1) // test
391385   PORT_BIT( 0x00200000, IP_ACTIVE_LOW,  IPT_UNKNOWN  )   // door 1
392386   PORT_BIT( 0x00400000, IP_ACTIVE_LOW,  IPT_UNKNOWN  )   // door 2
393   PORT_BIT( 0x00800000, IP_ACTIVE_HIGH, IPT_SPECIAL  )   // eeprom
387   PORT_BIT( 0x00800000, IP_ACTIVE_HIGH, IPT_SPECIAL  ) PORT_CUSTOM(eeprom_bit_r, NULL)
394388   PORT_BIT( 0x01000000, IP_ACTIVE_LOW,  IPT_START1   )   // start
395389   PORT_BIT( 0x02000000, IP_ACTIVE_LOW,  IPT_OTHER ) PORT_NAME("P1 Payout") PORT_CODE(KEYCODE_LCONTROL)   // payout
396390   PORT_BIT( 0x04000000, IP_ACTIVE_LOW,  IPT_OTHER ) PORT_NAME("P1 Cancel") PORT_CODE(KEYCODE_LALT)      // cancel
src/mame/drivers/equites.c
r2762r2763
146146  Sprite y scaling is slightly wrong and leaves gaps in tall objects.
147147  Note that sprites are 30x30 instead of 32x32.
148148
149- The "road" background in splndrbt is slightly wrong. Apparently, the black lines
150  visible in some parts of the background should never disappear in the distance.
151  Currently, they may or may not disappear depending on the X position.
152
149153- Need to use different default volumes for various games, especially gekisou
150154  where the car noise is really unpleasant with the default settings.
151155
src/mame/drivers/mystwarr.c
r2762r2763
5555static INT32 init_eeprom_count;
5656static UINT8 mw_irq_control;
5757
58static const struct EEPROM_interface eeprom_interface =
58static const eeprom_interface eeprom_intf =
5959{
6060   7,         /* address bits */
6161   8,         /* data bits */
r2762r2763
6868
6969/* Gaiapolis and Polygonet Commanders use the ER5911,
7070   but the command formats are slightly different.  Why? */
71static const struct EEPROM_interface eeprom_interface_gaia =
71static const eeprom_interface eeprom_intf_gaia =
7272{
7373   7,         /* address bits */
7474   8,         /* data bits */
r2762r2763
8282static NVRAM_HANDLER(mystwarr)
8383{
8484   if (read_or_write)
85      EEPROM_save(file);
85      eeprom_save(file);
8686   else
8787   {
88      EEPROM_init(&eeprom_interface);
88      eeprom_init(&eeprom_intf);
8989
9090      if (file)
9191      {
9292         init_eeprom_count = 0;
93         EEPROM_load(file);
93         eeprom_load(file);
9494      }
9595      else
9696         init_eeprom_count = 10;
r2762r2763
100100static NVRAM_HANDLER(gaiapols)
101101{
102102   if (read_or_write)
103      EEPROM_save(file);
103      eeprom_save(file);
104104   else
105105   {
106      EEPROM_init(&eeprom_interface_gaia);
106      eeprom_init(&eeprom_intf_gaia);
107107
108108      if (file)
109109      {
110110         init_eeprom_count = 0;
111         EEPROM_load(file);
111         eeprom_load(file);
112112      }
113113      else
114114         init_eeprom_count = 10;
r2762r2763
119119{
120120   if (ACCESSING_BITS_0_7)
121121   {
122      int res = input_port_read_indexed(machine, 1) | EEPROM_read_bit();
122      int res = input_port_read_indexed(machine, 1) | eeprom_read_bit();
123123
124124      if (init_eeprom_count)
125125      {
r2762r2763
139139{
140140   if (ACCESSING_BITS_0_7)
141141   {
142      int res = input_port_read_indexed(machine, 1) | EEPROM_read_bit();
142      int res = input_port_read_indexed(machine, 1) | eeprom_read_bit();
143143
144144      if (init_eeprom_count)
145145      {
r2762r2763
159159{
160160   if (ACCESSING_BITS_8_15)
161161   {
162      EEPROM_write_bit((data&0x0100) ? 1 : 0);
163      EEPROM_set_cs_line((data&0x0200) ? CLEAR_LINE : ASSERT_LINE);
164      EEPROM_set_clock_line((data&0x0400) ? ASSERT_LINE : CLEAR_LINE);
162      eeprom_write_bit((data&0x0100) ? 1 : 0);
163      eeprom_set_cs_line((data&0x0200) ? CLEAR_LINE : ASSERT_LINE);
164      eeprom_set_clock_line((data&0x0400) ? ASSERT_LINE : CLEAR_LINE);
165165      return;
166166   }
167167
r2762r2763
173173{
174174   if (ACCESSING_BITS_8_15)
175175   {
176      return (input_port_read_indexed(machine, 1) | EEPROM_read_bit())<<8;
176      return (input_port_read_indexed(machine, 1) | eeprom_read_bit())<<8;
177177   }
178178
179179   return input_port_read_indexed(machine, 3);
r2762r2763
183183{
184184   if (ACCESSING_BITS_0_7)
185185   {
186      EEPROM_write_bit((data&0x01) ? 1 : 0);
187      EEPROM_set_cs_line((data&0x02) ? CLEAR_LINE : ASSERT_LINE);
188      EEPROM_set_clock_line((data&0x04) ? ASSERT_LINE : CLEAR_LINE);
186      eeprom_write_bit((data&0x01) ? 1 : 0);
187      eeprom_set_cs_line((data&0x02) ? CLEAR_LINE : ASSERT_LINE);
188      eeprom_set_clock_line((data&0x04) ? ASSERT_LINE : CLEAR_LINE);
189189      return;
190190   }
191191}
src/mame/drivers/djmain.c
r2762r2763
16101610   ROM_LOAD16_BYTE( "c01jaa10.27d", 0x100001, 0x80000, CRC(C9927749) SHA1(c2644877bda483e241381265e723ea8ab8357761) )
16111611
16121612   DISK_REGION( REGION_DISKS )         /* IDE HARD DRIVE */
1613   DISK_IMAGE( "c01jaa11", 0, NO_DUMP )
1613   DISK_IMAGE( "c01jaa11", 0, MD5(ab47c58c0eda12c591d20013e16525f0) SHA1(f7e19e590005201d859f9a4ced8edf7fe88099f6) )   /* ver 1.00 JA */
16141614   // this image has not been verified
16151615   //DISK_IMAGE( "c01jaa11", 0, MD5(8bb7e6b6bc63cac8a4f2997307c25748) )    /* ver 1.00 JA */
16161616ROM_END
r2762r2763
19571957GAME( 2000, bmcorerm, 0,        djmain,   beatmania, bmcorerm,  ROT0, "Konami", "beatmania CORE REMIX (ver JA-A)", 0 )
19581958GAME( 2001, bm6thmix, 0,        djmain,   beatmania, bm6thmix,  ROT0, "Konami", "beatmania 6th MIX (ver JA-A)", 0 )
19591959GAME( 2001, bm7thmix, 0,        djmain,   beatmania, bm7thmix,  ROT0, "Konami", "beatmania 7th MIX (ver JA-B)", 0 )
1960GAME( 2002, bmfinal,  0,        djmain,   beatmania, bmfinal,   ROT0, "Konami", "beatmania THE FINAL (ver JA-A)", GAME_NOT_WORKING ) // missing hd
1960GAME( 2002, bmfinal,  0,        djmain,   beatmania, bmfinal,   ROT0, "Konami", "beatmania THE FINAL (ver JA-A)", 0 )
19611961
19621962#if 0
19631963// for reference, these sets have not been verified
src/mame/drivers/peplus.c
r2762r2763
9494          peps0615     2
9595          peps0716     2
9696          pexp0019     2
97          pexp0112     2
9798          pexs0006     2
9899          pexmp006     2
99100
r2762r2763
199200
200201/* Static Variables */
201202#define CMOS_NVRAM_SIZE     0x2000
202#define EEPROM_NVRAM_SIZE   0x200 // 4k Bit
203#define eeprom_NVRAM_SIZE   0x200 // 4k Bit
203204
204205
205206/*****************
r2762r2763
534535      last_cycles = activecpu_gettotalcycles();
535536   } else {
536537      /* Process Next Coin Optic State */
537      if (curr_cycles - last_cycles > 20000 && coin_state != 0) {
538      if (curr_cycles - last_cycles > 600000 && coin_state != 0) {
538539         coin_state++;
539540         if (coin_state > 5)
540541            coin_state = 0;
r2762r2763
752753   AM_RANGE(0xd000, 0xdfff) AM_RAM AM_READWRITE(peplus_sd000_r, peplus_sd000_w) AM_BASE(&sd000_ram)
753754
754755   // DUART
755   AM_RANGE(0xe000, 0xe00a) AM_READWRITE(peplus_duart_r, peplus_duart_w)
756   AM_RANGE(0xe000, 0xe00f) AM_READWRITE(peplus_duart_r, peplus_duart_w)
756757
757758    // Superboard Data
758759   AM_RANGE(0xf000, 0xffff) AM_RAM AM_READWRITE(peplus_sf000_r, peplus_sf000_w) AM_BASE(&sf000_ram)
r2762r2763
770771*      Input ports       *
771772*************************/
772773
774static CUSTOM_INPUT( peplus_input_r )
775{
776    UINT8 inp_ret = 0x00;
777    UINT8 inp_read = input_port_read(field->port->machine, param);
778
779    if (inp_read & 0x01) inp_ret = 0x01;
780    if (inp_read & 0x02) inp_ret = 0x02;
781    if (inp_read & 0x04) inp_ret = 0x03;
782    if (inp_read & 0x08) inp_ret = 0x04;
783    if (inp_read & 0x10) inp_ret = 0x05;
784    if (inp_read & 0x20) inp_ret = 0x06;
785    if (inp_read & 0x40) inp_ret = 0x07;
786
787    return inp_ret;
788}
789
773790static INPUT_PORTS_START( peplus )
774791   /* IN0 has to be defined for each kind of game */
775792
r2762r2763
793810   PORT_DIPUNUSED( 0x80, IP_ACTIVE_LOW )
794811INPUT_PORTS_END
795812
796
797/*************************
798*      Input ports       *
799*************************/
800
801/* Fake inputs to only map what is needed */
802813static INPUT_PORTS_START( peplus_schip )
803   PORT_START_TAG("IN0")
814   PORT_INCLUDE(peplus)
815   PORT_START_TAG("IN_BANK1")
804816   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1  ) PORT_NAME("Jackpot Reset") PORT_CODE(KEYCODE_L)
805817   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON2  ) PORT_NAME("Self Test") PORT_CODE(KEYCODE_K)
806   PORT_BIT( 0x03, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
818    PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
819    PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
820   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
821   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
822    PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
823
824    PORT_START_TAG("IN_BANK2")
825   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON9  ) PORT_NAME("Deal-Spin-Start") PORT_CODE(KEYCODE_Q)
826   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
807827   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
808   PORT_BIT( 0x05, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
809   PORT_BIT( 0x06, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
810   PORT_BIT( 0x07, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
811   PORT_BIT( 0x08, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
812   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON9  ) PORT_NAME("Deal-Spin-Start") PORT_CODE(KEYCODE_Q)
828   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
829   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
813830   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
814   PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
815   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
816   PORT_BIT( 0x50, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
817   PORT_BIT( 0x60, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
818   PORT_BIT( 0x70, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
831    PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
832
833    PORT_START_TAG("IN0")
834    PORT_BIT( 0x07, IP_ACTIVE_LOW,  IPT_SPECIAL  ) PORT_CUSTOM(peplus_input_r, "IN_BANK1")
835    PORT_BIT( 0x08, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
836    PORT_BIT( 0x70, IP_ACTIVE_LOW,  IPT_SPECIAL  ) PORT_CUSTOM(peplus_input_r, "IN_BANK2")
819837   PORT_BIT( 0x80, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
820
821   PORT_START_TAG("SW1")
822   PORT_DIPNAME( 0x01, 0x01, "Line Frequency" )
823   PORT_DIPSETTING(    0x01, "60HZ" )
824   PORT_DIPSETTING(    0x00, "50HZ" )
825   PORT_DIPUNUSED( 0x02, IP_ACTIVE_LOW )
826   PORT_DIPUNUSED( 0x04, IP_ACTIVE_LOW )
827   PORT_DIPUNUSED( 0x08, IP_ACTIVE_LOW )
828   PORT_DIPUNUSED( 0x10, IP_ACTIVE_LOW )
829   PORT_DIPUNUSED( 0x20, IP_ACTIVE_LOW )
830   PORT_DIPUNUSED( 0x40, IP_ACTIVE_LOW )
831   PORT_DIPUNUSED( 0x80, IP_ACTIVE_LOW )
832838INPUT_PORTS_END
833839
834840static INPUT_PORTS_START( peplus_poker )
835841   PORT_INCLUDE(peplus)
836842
837   PORT_START_TAG("IN0")
843   PORT_START_TAG("IN_BANK1")
838844   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1  ) PORT_NAME("Jackpot Reset") PORT_CODE(KEYCODE_L)
839845   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON2  ) PORT_NAME("Self Test") PORT_CODE(KEYCODE_K)
840   PORT_BIT( 0x03, IP_ACTIVE_HIGH, IPT_BUTTON3  ) PORT_NAME("Hold 1") PORT_CODE(KEYCODE_Z)
841   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON4  ) PORT_NAME("Hold 2") PORT_CODE(KEYCODE_X)
842   PORT_BIT( 0x05, IP_ACTIVE_HIGH, IPT_BUTTON5  ) PORT_NAME("Hold 3") PORT_CODE(KEYCODE_C)
843   PORT_BIT( 0x06, IP_ACTIVE_HIGH, IPT_BUTTON6  ) PORT_NAME("Hold 4") PORT_CODE(KEYCODE_V)
844   PORT_BIT( 0x07, IP_ACTIVE_LOW,  IPT_BUTTON7  ) PORT_NAME("Hold 5") PORT_CODE(KEYCODE_B)
845   PORT_BIT( 0x08, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
846   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON9  ) PORT_NAME("Deal-Spin-Start") PORT_CODE(KEYCODE_Q)
847   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON10 ) PORT_NAME("Max Bet") PORT_CODE(KEYCODE_W)
848   PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
849   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON12 ) PORT_NAME("Play Credit") PORT_CODE(KEYCODE_R)
850   PORT_BIT( 0x50, IP_ACTIVE_HIGH, IPT_BUTTON13 ) PORT_NAME("Cashout") PORT_CODE(KEYCODE_T)
851   PORT_BIT( 0x60, IP_ACTIVE_HIGH, IPT_BUTTON14 ) PORT_NAME("Change Request") PORT_CODE(KEYCODE_Y)
852   PORT_BIT( 0x70, IP_ACTIVE_LOW,  IPT_BUTTON15 ) PORT_NAME("Bill Acceptor") PORT_CODE(KEYCODE_U)
853   PORT_BIT( 0x80, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
854INPUT_PORTS_END
846    PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON3  ) PORT_NAME("Hold 1") PORT_CODE(KEYCODE_Z)
847    PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_BUTTON4  ) PORT_NAME("Hold 2") PORT_CODE(KEYCODE_X)
848   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON5  ) PORT_NAME("Hold 3") PORT_CODE(KEYCODE_C)
849   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON6  ) PORT_NAME("Hold 4") PORT_CODE(KEYCODE_V)
850    PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON7  ) PORT_NAME("Hold 5") PORT_CODE(KEYCODE_B)
855851
856/* same as peplus_poker with additionnal fake option to enable the "Autohold" feature */
857static INPUT_PORTS_START( peplus_pokah )
858   PORT_INCLUDE(peplus_poker)
852    PORT_START_TAG("IN_BANK2")
853   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON9  ) PORT_NAME("Deal-Spin-Start") PORT_CODE(KEYCODE_Q)
854   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON10 ) PORT_NAME("Max Bet") PORT_CODE(KEYCODE_W)
855   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
856   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_BUTTON12 ) PORT_NAME("Play Credit") PORT_CODE(KEYCODE_R)
857   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON13 ) PORT_NAME("Cashout") PORT_CODE(KEYCODE_T)
858   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON14 ) PORT_NAME("Change Request") PORT_CODE(KEYCODE_Y)
859    PORT_BIT( 0x40, IP_ACTIVE_HIGH,  IPT_BUTTON15 ) PORT_NAME("Bill Acceptor") PORT_CODE(KEYCODE_U)
859860
860   /* If you change this option, you'll have to delete the .nv file next time you launch the game ! */
861   PORT_START_TAG("AUTOHOLD")
862   PORT_CONFNAME( 0x01, 0x00, "Enable Autohold Feature" )
863   PORT_CONFSETTING(    0x00, DEF_STR( No ) )
864   PORT_CONFSETTING(    0x01, DEF_STR( Yes ) )
861    PORT_START_TAG("IN0")
862    PORT_BIT( 0x07, IP_ACTIVE_LOW,  IPT_SPECIAL  ) PORT_CUSTOM(peplus_input_r, "IN_BANK1")
863    PORT_BIT( 0x08, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
864    PORT_BIT( 0x70, IP_ACTIVE_LOW,  IPT_SPECIAL  ) PORT_CUSTOM(peplus_input_r, "IN_BANK2")
865   PORT_BIT( 0x80, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
865866INPUT_PORTS_END
866867
867868static INPUT_PORTS_START( peplus_bjack )
868869   PORT_INCLUDE(peplus)
869870
870   PORT_START_TAG("IN0")
871   PORT_START_TAG("IN_BANK1")
871872   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1  ) PORT_NAME("Jackpot Reset") PORT_CODE(KEYCODE_L)
872873   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON2  ) PORT_NAME("Self Test") PORT_CODE(KEYCODE_K)
873   PORT_BIT( 0x03, IP_ACTIVE_HIGH, IPT_BUTTON3  ) PORT_NAME("Surrender") PORT_CODE(KEYCODE_Z)
874   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON4  ) PORT_NAME("Stand") PORT_CODE(KEYCODE_X)
875   PORT_BIT( 0x05, IP_ACTIVE_HIGH, IPT_BUTTON5  ) PORT_NAME("Insurance") PORT_CODE(KEYCODE_C)
876   PORT_BIT( 0x06, IP_ACTIVE_HIGH, IPT_BUTTON6  ) PORT_NAME("Double Down") PORT_CODE(KEYCODE_V)
877   PORT_BIT( 0x07, IP_ACTIVE_LOW,  IPT_BUTTON7  ) PORT_NAME("Split") PORT_CODE(KEYCODE_B)
878   PORT_BIT( 0x08, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
879   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON9  ) PORT_NAME("Deal-Spin-Start") PORT_CODE(KEYCODE_Q)
880   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON10 ) PORT_NAME("Max Bet") PORT_CODE(KEYCODE_W)
881   PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
882   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON12 ) PORT_NAME("Play Credit") PORT_CODE(KEYCODE_R)
883   PORT_BIT( 0x50, IP_ACTIVE_HIGH, IPT_BUTTON13 ) PORT_NAME("Cashout") PORT_CODE(KEYCODE_T)
884   PORT_BIT( 0x60, IP_ACTIVE_HIGH, IPT_BUTTON14 ) PORT_NAME("Change Request") PORT_CODE(KEYCODE_Y)
885   PORT_BIT( 0x70, IP_ACTIVE_LOW,  IPT_BUTTON15 ) PORT_NAME("Bill Acceptor") PORT_CODE(KEYCODE_U)
874    PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON3  ) PORT_NAME("Surrender") PORT_CODE(KEYCODE_Z)
875    PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_BUTTON4  ) PORT_NAME("Stand") PORT_CODE(KEYCODE_X)
876   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON5  ) PORT_NAME("Insurance") PORT_CODE(KEYCODE_C)
877   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON6  ) PORT_NAME("Double Down") PORT_CODE(KEYCODE_V)
878    PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON7  ) PORT_NAME("Split") PORT_CODE(KEYCODE_B)
879
880    PORT_START_TAG("IN_BANK2")
881   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON9  ) PORT_NAME("Deal-Spin-Start") PORT_CODE(KEYCODE_Q)
882   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON10 ) PORT_NAME("Max Bet") PORT_CODE(KEYCODE_W)
883   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
884   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_BUTTON12 ) PORT_NAME("Play Credit") PORT_CODE(KEYCODE_R)
885   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON13 ) PORT_NAME("Cashout") PORT_CODE(KEYCODE_T)
886   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON14 ) PORT_NAME("Change Request") PORT_CODE(KEYCODE_Y)
887    PORT_BIT( 0x40, IP_ACTIVE_HIGH,  IPT_BUTTON15 ) PORT_NAME("Bill Acceptor") PORT_CODE(KEYCODE_U)
888
889    PORT_START_TAG("IN0")
890    PORT_BIT( 0x07, IP_ACTIVE_LOW,  IPT_SPECIAL  ) PORT_CUSTOM(peplus_input_r, "IN_BANK1")
891    PORT_BIT( 0x08, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
892    PORT_BIT( 0x70, IP_ACTIVE_LOW,  IPT_SPECIAL  ) PORT_CUSTOM(peplus_input_r, "IN_BANK2")
886893   PORT_BIT( 0x80, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
887894INPUT_PORTS_END
888895
889896static INPUT_PORTS_START( peplus_keno )
890897   PORT_INCLUDE(peplus)
891898
892   PORT_START_TAG("IN0")
899    PORT_START_TAG("IN_BANK1")
893900   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1  ) PORT_NAME("Jackpot Reset") PORT_CODE(KEYCODE_L)
894901   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON2  ) PORT_NAME("Self Test") PORT_CODE(KEYCODE_K)
895   PORT_BIT( 0x03, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
902    PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
903    PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
904   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
905   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
906    PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON7  ) PORT_NAME("Erase") PORT_CODE(KEYCODE_B)
907
908    PORT_START_TAG("IN_BANK2")
909   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON9  ) PORT_NAME("Deal-Spin-Start") PORT_CODE(KEYCODE_Q)
910   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON10 ) PORT_NAME("Max Bet") PORT_CODE(KEYCODE_W)
896911   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
897   PORT_BIT( 0x05, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
898   PORT_BIT( 0x06, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
899   PORT_BIT( 0x07, IP_ACTIVE_LOW,  IPT_BUTTON7  ) PORT_NAME("Erase") PORT_CODE(KEYCODE_B)
900   PORT_BIT( 0x08, IP_ACTIVE_LOW,  IPT_BUTTON8  ) PORT_NAME("Light Pen") PORT_CODE(KEYCODE_A)
901   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON9  ) PORT_NAME("Deal-Spin-Start") PORT_CODE(KEYCODE_Q)
902   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON10 ) PORT_NAME("Max Bet") PORT_CODE(KEYCODE_W)
903   PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
904   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON12 ) PORT_NAME("Play Credit") PORT_CODE(KEYCODE_R)
905   PORT_BIT( 0x50, IP_ACTIVE_HIGH, IPT_BUTTON13 ) PORT_NAME("Cashout") PORT_CODE(KEYCODE_T)
906   PORT_BIT( 0x60, IP_ACTIVE_HIGH, IPT_BUTTON14 ) PORT_NAME("Change Request") PORT_CODE(KEYCODE_Y)
907   PORT_BIT( 0x70, IP_ACTIVE_LOW,  IPT_BUTTON15 ) PORT_NAME("Bill Acceptor") PORT_CODE(KEYCODE_U)
908   PORT_BIT( 0x80, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
912   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_BUTTON12 ) PORT_NAME("Play Credit") PORT_CODE(KEYCODE_R)
913   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON13 ) PORT_NAME("Cashout") PORT_CODE(KEYCODE_T)
914   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON14 ) PORT_NAME("Change Request") PORT_CODE(KEYCODE_Y)
915    PORT_BIT( 0x40, IP_ACTIVE_HIGH,  IPT_BUTTON15 ) PORT_NAME("Bill Acceptor") PORT_CODE(KEYCODE_U)
909916
910917    PORT_START_TAG("TOUCH_X")
911918    PORT_BIT( 0xff, 0x08, IPT_LIGHTGUN_X ) PORT_MINMAX(0x00, 0x28) PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(25) PORT_KEYDELTA(13)
912919    PORT_START_TAG("TOUCH_Y")
913920   PORT_BIT( 0xff, 0x08, IPT_LIGHTGUN_Y ) PORT_MINMAX(0x00, 0x19) PORT_CROSSHAIR(Y, -1.0, 0.0, 0) PORT_SENSITIVITY(25) PORT_KEYDELTA(13)
921
922    PORT_START_TAG("IN0")
923    PORT_BIT( 0x07, IP_ACTIVE_LOW,  IPT_SPECIAL  ) PORT_CUSTOM(peplus_input_r, "IN_BANK1")
924    PORT_BIT( 0x08, IP_ACTIVE_LOW,  IPT_UNKNOWN  ) PORT_NAME("Light Pen") PORT_CODE(KEYCODE_A)
925    PORT_BIT( 0x70, IP_ACTIVE_LOW,  IPT_SPECIAL  ) PORT_CUSTOM(peplus_input_r, "IN_BANK2")
926   PORT_BIT( 0x80, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
914927INPUT_PORTS_END
915928
916929static INPUT_PORTS_START( peplus_slots )
917930   PORT_INCLUDE(peplus)
918931
919   PORT_START_TAG("IN0")
932   PORT_START_TAG("IN_BANK1")
920933   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1  ) PORT_NAME("Jackpot Reset") PORT_CODE(KEYCODE_L)
921934   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON2  ) PORT_NAME("Self Test") PORT_CODE(KEYCODE_K)
922   PORT_BIT( 0x03, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
935    PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
936    PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
937   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
938   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
939    PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
940
941    PORT_START_TAG("IN_BANK2")
942   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON9  ) PORT_NAME("Deal-Spin-Start") PORT_CODE(KEYCODE_Q)
943   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON10 ) PORT_NAME("Max Bet") PORT_CODE(KEYCODE_W)
923944   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
924   PORT_BIT( 0x05, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
925   PORT_BIT( 0x06, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
926   PORT_BIT( 0x07, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
927   PORT_BIT( 0x08, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
928   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON9  ) PORT_NAME("Deal-Spin-Start") PORT_CODE(KEYCODE_Q)
929   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON10 ) PORT_NAME("Max Bet") PORT_CODE(KEYCODE_W)
930   PORT_BIT( 0x30, IP_ACTIVE_HIGH, IPT_UNKNOWN  )
931   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON12 ) PORT_NAME("Play Credit") PORT_CODE(KEYCODE_R)
932   PORT_BIT( 0x50, IP_ACTIVE_HIGH, IPT_BUTTON13 ) PORT_NAME("Cashout") PORT_CODE(KEYCODE_T)
933   PORT_BIT( 0x60, IP_ACTIVE_HIGH, IPT_BUTTON14 ) PORT_NAME("Change Request") PORT_CODE(KEYCODE_Y)
934   PORT_BIT( 0x70, IP_ACTIVE_LOW,  IPT_BUTTON15 ) PORT_NAME("Bill Acceptor") PORT_CODE(KEYCODE_U)
945   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_BUTTON12 ) PORT_NAME("Play Credit") PORT_CODE(KEYCODE_R)
946   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON13 ) PORT_NAME("Cashout") PORT_CODE(KEYCODE_T)
947   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON14 ) PORT_NAME("Change Request") PORT_CODE(KEYCODE_Y)
948    PORT_BIT( 0x40, IP_ACTIVE_HIGH,  IPT_BUTTON15 ) PORT_NAME("Bill Acceptor") PORT_CODE(KEYCODE_U)
949
950    PORT_START_TAG("IN0")
951    PORT_BIT( 0x07, IP_ACTIVE_LOW,  IPT_SPECIAL  ) PORT_CUSTOM(peplus_input_r, "IN_BANK1")
952    PORT_BIT( 0x08, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
953    PORT_BIT( 0x70, IP_ACTIVE_LOW,  IPT_SPECIAL  ) PORT_CUSTOM(peplus_input_r, "IN_BANK2")
935954   PORT_BIT( 0x80, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
936955INPUT_PORTS_END
937956
957/* same as peplus_poker with additionnal fake option to enable the "Autohold" feature */
958static INPUT_PORTS_START( peplus_pokah )
959   PORT_INCLUDE(peplus_poker)
938960
961   /* If you change this option, you'll have to delete the .nv file next time you launch the game ! */
962   PORT_START_TAG("AUTOHOLD")
963   PORT_CONFNAME( 0x01, 0x00, "Enable Autohold Feature" )
964   PORT_CONFSETTING(    0x00, DEF_STR( No ) )
965   PORT_CONFSETTING(    0x01, DEF_STR( Yes ) )
966INPUT_PORTS_END
939967
968
940969/*************************
941970*     Machine Reset      *
942971*************************/
r2762r2763
10161045   i8051_set_eram_iaddr_callback(peplus_external_ram_iaddr);
10171046
10181047    /* EEPROM is a X2404P 4K-bit Serial I2C Bus */
1019   i2cmem_init(0, I2CMEM_SLAVE_ADDRESS, 8, EEPROM_NVRAM_SIZE, NULL);
1048   i2cmem_init(0, I2CMEM_SLAVE_ADDRESS, 8, eeprom_NVRAM_SIZE, NULL);
10201049
10211050   /* default : no address to patch in program RAM to enable autohold feature */
10221051   autohold_addr = 0;
r2762r2763
12241253   ROM_LOAD( "cap2234.u43", 0x0000, 0x0100, CRC(a930e283) SHA1(61bce50fa13b3e980ece3e72d068835e19bd5049) )
12251254ROM_END
12261255
1256ROM_START( pexp0112 ) /* Superboard : White Hot Aces Poker (XP000112) */
1257   ROM_REGION( 0x10000, REGION_CPU1, 0 )
1258   ROM_LOAD( "xp000112.u67",   0x00000, 0x10000, CRC(c1ae96ad) SHA1(da109602f0fbe9b225cdcd60be0613fd41014864) )
1259
1260   ROM_REGION( 0x10000, REGION_USER1, 0 )
1261   ROM_LOAD( "x002035p.u66",   0x00000, 0x10000, CRC(dc3f0742) SHA1(d57cf3353b81f41895458019e47203f98645f17a) )
1262
1263   ROM_REGION( 0x100000, REGION_GFX1, ROMREGION_DISPOSE )
1264   ROM_LOAD( "mro-cg2324.u77",    0x00000, 0x8000, CRC(6eceef42) SHA1(a2ddd2a3290c41e510f483c6b633fe0002694d0b) )
1265   ROM_LOAD( "mgo-cg2324.u78",    0x08000, 0x8000, CRC(26d0acbe) SHA1(09a9127deb88185cd5b748bac657461eadb2f48f) )
1266   ROM_LOAD( "mbo-cg2324.u79",    0x10000, 0x8000, CRC(47baee32) SHA1(d8af09022ccb5fc06aa3aa4c200a734b66cbee00) )
1267   ROM_LOAD( "mxo-cg2324.u80",    0x18000, 0x8000, CRC(60449fc0) SHA1(251d1e04786b70c1d2bc7b02f3b69cd58ac76398) )
1268
1269   ROM_REGION( 0x100, REGION_PROMS, 0 )
1270   ROM_LOAD( "cap2174.u43", 0x0000, 0x0100, CRC(cbff3f26) SHA1(9e145676f2871c2369042a13cbeabb7efe2728e1) )
1271ROM_END
1272
12271273ROM_START( pexs0006 ) /* Superboard : Triple Triple Diamond Slots (XS000006) */
12281274   ROM_REGION( 0x10000, REGION_CPU1, 0 )
12291275   ROM_LOAD( "xs000006.u67",   0x00000, 0x10000, CRC(4b11ca18) SHA1(f64a1fbd089c01bc35a5484e60b8834a2db4a79f) )
r2762r2763
12871333
12881334/* Superboard : poker */
12891335GAMEL(1995, pexp0019, 0,      peplus,  peplus_poker, peplussb, ROT0,  "IGT - International Gaming Technology", "Player's Edge Plus (XP000019) Deuces Wild Poker",           0,   layout_pe_poker )
1336GAMEL(1995, pexp0112, 0,      peplus,  peplus_poker, peplussb, ROT0,  "IGT - International Gaming Technology", "Player's Edge Plus (XP000112) White Hot Aces Poker",        0,   layout_pe_poker )
12901337
12911338/* Superboard : multi-poker */
12921339GAMEL(1995, pexmp006, 0,      peplus,  peplus_poker, peplussb, ROT0,  "IGT - International Gaming Technology", "Player's Edge Plus (XMP00006) Multi-Poker",                 0,   layout_pe_poker )
src/mame/drivers/konamigx.c
r2762r2763
465465static NVRAM_HANDLER(konamigx_93C46)
466466{
467467   if (read_or_write)
468      EEPROM_save(file);
468      eeprom_save(file);
469469   else
470470   {
471      EEPROM_init(&eeprom_interface_93C46);
471      eeprom_init(&eeprom_interface_93C46);
472472
473473      if (file)
474474      {
475475         init_eeprom_count = 0;
476         EEPROM_load(file);
476         eeprom_load(file);
477477      }
478478      else
479479         init_eeprom_count = 10;
r2762r2763
489489   //      excpuint stat, objdma stat, eeprom do
490490
491491   // note: racin' force expects bit 1 of the eeprom port to toggle
492   return(input_port_read_indexed(machine, 6)<<24 | input_port_read_indexed(machine, 7)<<16 | input_port_read_indexed(machine, 0)<<8 | EEPROM_read_bit() | gx_rdport1_3);
492   return(input_port_read_indexed(machine, 6)<<24 | input_port_read_indexed(machine, 7)<<16 | input_port_read_indexed(machine, 0)<<8 | eeprom_read_bit() | gx_rdport1_3);
493493}
494494
495495static WRITE32_HANDLER( eeprom_w )
r2762r2763
510510          bit 0: eeprom data
511511        */
512512
513      EEPROM_write_bit((odata&0x01) ? 1 : 0);
514      EEPROM_set_cs_line((odata&0x02) ? CLEAR_LINE : ASSERT_LINE);
515      EEPROM_set_clock_line((odata&0x04) ? ASSERT_LINE : CLEAR_LINE);
513      eeprom_write_bit((odata&0x01) ? 1 : 0);
514      eeprom_set_cs_line((odata&0x02) ? CLEAR_LINE : ASSERT_LINE);
515      eeprom_set_clock_line((odata&0x04) ? ASSERT_LINE : CLEAR_LINE);
516516
517517      konamigx_wrport1_0 = odata;
518518   }
src/mame/drivers/stvinit.c
r2762r2763
146146NVRAM_HANDLER( stv )
147147{
148148   if (read_or_write)
149      EEPROM_save(file);
149      eeprom_save(file);
150150   else
151151   {
152      EEPROM_init(&eeprom_interface_93C46);
152      eeprom_init(&eeprom_interface_93C46);
153153
154      if (file) EEPROM_load(file);
154      if (file) eeprom_load(file);
155155      else
156156      {
157157         if (stv_default_eeprom)   /* Set the EEPROM to Factory Defaults */
158            EEPROM_set_data(stv_default_eeprom,stv_default_eeprom_length);
158            eeprom_set_data(stv_default_eeprom,stv_default_eeprom_length);
159159      }
160160   }
161161}
src/mame/drivers/gottlieb.c
r2762r2763
664664   PORT_DIPNAME( 0x80, 0x00, "SW8" )
665665   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
666666   PORT_DIPSETTING(    0x80, DEF_STR( On ) )
667   PORT_BIT( 0xe0, IP_ACTIVE_LOW, IPT_UNUSED )
668/* 0x40 must be connected to the IP16 line */
667   /* 0x40 must be connected to the IP16 line */
669668
670669   PORT_START_TAG("IN1")
671670   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_START1 )
src/mame/drivers/asterix.c
r2762r2763
2323static UINT8 cur_control2;
2424static int init_eeprom_count;
2525
26static const struct EEPROM_interface eeprom_interface =
26static const eeprom_interface eeprom_intf =
2727{
2828   7,            /* address bits */
2929   8,            /* data bits */
r2762r2763
3737#if 0
3838static void eeprom_init(void)
3939{
40   EEPROM_init(&eeprom_interface);
40   eeprom_init(&eeprom_intf);
4141   init_eeprom_count = 0;
4242}
4343#endif
r2762r2763
4545static NVRAM_HANDLER( asterix )
4646{
4747   if (read_or_write)
48      EEPROM_save(file);
48      eeprom_save(file);
4949   else
5050   {
51      EEPROM_init(&eeprom_interface);
51      eeprom_init(&eeprom_intf);
5252
5353      if (file)
5454      {
5555         init_eeprom_count = 0;
56         EEPROM_load(file);
56         eeprom_load(file);
5757      }
5858      else
5959         init_eeprom_count = 10;
r2762r2763
6767   /* bit 8  is EEPROM data */
6868   /* bit 9  is EEPROM ready */
6969   /* bit 10 is service button */
70   res = (EEPROM_read_bit()<<8) | input_port_read_indexed(machine,1);
70   res = (eeprom_read_bit()<<8) | input_port_read_indexed(machine,1);
7171
7272   if (init_eeprom_count)
7373   {
r2762r2763
9696      /* bit 1 is cs (active low) */
9797      /* bit 2 is clock (active high) */
9898
99      EEPROM_write_bit(data & 0x01);
100      EEPROM_set_cs_line((data & 0x02) ? CLEAR_LINE : ASSERT_LINE);
101      EEPROM_set_clock_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE);
99      eeprom_write_bit(data & 0x01);
100      eeprom_set_cs_line((data & 0x02) ? CLEAR_LINE : ASSERT_LINE);
101      eeprom_set_clock_line((data & 0x04) ? ASSERT_LINE : CLEAR_LINE);
102102
103103      /* bit 5 is select tile bank */
104104      K056832_set_tile_bank((data & 0x20) >> 5);
src/mame/drivers/hng64.c
r2762r2763
14221422
14231423
14241424/* ?? */
1425static const struct mips3_config config =
1425static const mips3_config config =
14261426{
14271427   16384,            /* code cache size */
14281428   16384            /* data cache size */
src/mame/drivers/moo.c
r2762r2763
6060static UINT16 cur_control2;
6161
6262
63static const struct EEPROM_interface eeprom_interface =
63static const eeprom_interface eeprom_intf =
6464{
6565   7,         /* address bits */
6666   8,         /* data bits */
r2762r2763
7474static NVRAM_HANDLER( moo )
7575{
7676   if (read_or_write)
77      EEPROM_save(file);
77      eeprom_save(file);
7878   else
7979   {
80      EEPROM_init(&eeprom_interface);
80      eeprom_init(&eeprom_intf);
8181
8282      if (file)
8383      {
8484         init_eeprom_count = 0;
85         EEPROM_load(file);
85         eeprom_load(file);
8686      }
8787      else
8888         init_eeprom_count = 10;
r2762r2763
9797   /* bit 1 is EEPROM ready */
9898   /* bit 3 is service button */
9999   /* bits 4-7 are DIP switches */
100   res = EEPROM_read_bit() | input_port_read_indexed(machine, 1);
100   res = eeprom_read_bit() | input_port_read_indexed(machine, 1);
101101
102102   if (init_eeprom_count)
103103   {
r2762r2763
125125
126126   COMBINE_DATA(&cur_control2);
127127
128   EEPROM_write_bit(cur_control2 & 0x01);
129   EEPROM_set_cs_line((cur_control2 & 0x02) ? CLEAR_LINE : ASSERT_LINE);
130   EEPROM_set_clock_line((cur_control2 & 0x04) ? ASSERT_LINE : CLEAR_LINE);
128   eeprom_write_bit(cur_control2 & 0x01);
129   eeprom_set_cs_line((cur_control2 & 0x02) ? CLEAR_LINE : ASSERT_LINE);
130   eeprom_set_clock_line((cur_control2 & 0x04) ? ASSERT_LINE : CLEAR_LINE);
131131
132132   if (data & 0x100)
133133   {
src/mame/drivers/eolith16.c
r2762r2763
1919static int vbuffer = 0;
2020
2121// It's configured for 512 bytes
22static const struct EEPROM_interface eeprom_interface_93C66 =
22static const eeprom_interface eeprom_interface_93C66 =
2323{
2424   9,            // address bits 9
2525   8,            // data bits    8
r2762r2763
3535   vbuffer = (data & 0x80) >> 7;
3636   coin_counter_w(0, data & 1);
3737
38   EEPROM_write_bit(data & 0x40);
39   EEPROM_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
40   EEPROM_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
38   eeprom_write_bit(data & 0x40);
39   eeprom_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
40   eeprom_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
4141
4242   //data & 0x100 and data & 0x004 always set
4343}
r2762r2763
4545static READ16_HANDLER( eolith16_custom_r )
4646{
4747   eolith_speedup_read();
48   return (input_port_read_indexed(machine, 0) & ~0x10) | (EEPROM_read_bit() << 4);
48   return (input_port_read_indexed(machine, 0) & ~0x10) | (eeprom_read_bit() << 4);
4949}
5050
5151
r2762r2763
129129static NVRAM_HANDLER( eolith16_eeprom )
130130{
131131   if (read_or_write)
132      EEPROM_save(file);
132      eeprom_save(file);
133133   else
134134   {
135      EEPROM_init(&eeprom_interface_93C66);
136      if (file)   EEPROM_load(file);
135      eeprom_init(&eeprom_interface_93C66);
136      if (file)   eeprom_load(file);
137137   }
138138}
139139
src/mame/drivers/groundfx.c
r2762r2763
127127   0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
128128};
129129
130static const struct EEPROM_interface groundfx_eeprom_interface =
130static const eeprom_interface groundfx_eeprom_interface =
131131{
132132   6,            /* address bits */
133133   16,            /* data bits */
r2762r2763
141141static NVRAM_HANDLER( groundfx )
142142{
143143   if (read_or_write)
144      EEPROM_save(file);
144      eeprom_save(file);
145145   else {
146      EEPROM_init(&groundfx_eeprom_interface);
146      eeprom_init(&groundfx_eeprom_interface);
147147      if (file)
148         EEPROM_load(file);
148         eeprom_load(file);
149149      else
150         EEPROM_set_data(default_eeprom,128);  /* Default the gun setup values */
150         eeprom_set_data(default_eeprom,128);  /* Default the gun setup values */
151151   }
152152}
153153
r2762r2763
164164      case 0x00:
165165      {
166166         return (input_port_read_indexed(machine,0) << 16) | input_port_read_indexed(machine,1) |
167              (EEPROM_read_bit() << 7) | frame_counter;
167              (eeprom_read_bit() << 7) | frame_counter;
168168      }
169169
170170      case 0x01:
r2762r2763
189189
190190         if (ACCESSING_BITS_0_7)
191191         {
192            EEPROM_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
193            EEPROM_write_bit(data & 0x40);
194            EEPROM_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
192            eeprom_set_clock_line((data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
193            eeprom_write_bit(data & 0x40);
194            eeprom_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
195195            return;
196196         }
197197
src/mame/drivers/cidelsa.c
r2762r2763
1212    TODO:
1313
1414    - move set_cpu_mode timer call to MDRV
15    - fix COP420 core to get sound in Draco
1615
1716*/
1817
r2762r2763
708707   MDRV_SPEAKER_STANDARD_MONO("mono")
709708
710709   MDRV_SOUND_ADD(CDP1869, DRACO_CHR2)
711   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
712710
713711   MDRV_SOUND_ADD(AY8910, DRACO_SND_CHR1)
714712   MDRV_SOUND_CONFIG(ay8910_interface)
r2762r2763
764762GAME( 1980, destryer, 0,       destryer, destryer, 0, ROT90, "Cidelsa", "Destroyer (Cidelsa) (set 1)", GAME_IMPERFECT_SOUND | GAME_SUPPORTS_SAVE )
765763GAME( 1980, destryea, destryer, destryea, destryer, 0, ROT90, "Cidelsa", "Destroyer (Cidelsa) (set 2)", GAME_IMPERFECT_SOUND | GAME_SUPPORTS_SAVE )
766764GAME( 1981, altair,   0,       altair,   altair,   0, ROT90, "Cidelsa", "Altair", GAME_IMPERFECT_SOUND | GAME_SUPPORTS_SAVE )
767GAME( 1981, draco,    0,       draco,    draco,    0, ROT90, "Cidelsa", "Draco", GAME_IMPERFECT_COLORS | GAME_IMPERFECT_SOUND | GAME_SUPPORTS_SAVE )
765GAME( 1981, draco,    0,       draco,    draco,    0, ROT90, "Cidelsa", "Draco", GAME_IMPERFECT_COLORS | GAME_SUPPORTS_SAVE )
src/mame/drivers/vendetta.c
r2762r2763
112112static int init_eeprom_count;
113113
114114
115static const struct EEPROM_interface eeprom_interface =
115static const eeprom_interface eeprom_intf =
116116{
117117   7,            /* address bits */
118118   8,            /* data bits */
r2762r2763
126126static NVRAM_HANDLER( vendetta )
127127{
128128   if (read_or_write)
129      EEPROM_save(file);
129      eeprom_save(file);
130130   else
131131   {
132      EEPROM_init(&eeprom_interface);
132      eeprom_init(&eeprom_intf);
133133
134134      if (file)
135135      {
136136         init_eeprom_count = 0;
137         EEPROM_load(file);
137         eeprom_load(file);
138138      }
139139      else
140140         init_eeprom_count = 1000;
r2762r2763
145145{
146146   int res;
147147
148   res = EEPROM_read_bit();
148   res = eeprom_read_bit();
149149
150150   res |= 0x02;//konami_eeprom_ack() << 5; /* add the ack */
151151
r2762r2763
176176      return;
177177
178178   /* EEPROM */
179   EEPROM_write_bit(data & 0x20);
180   EEPROM_set_clock_line((data & 0x10) ? ASSERT_LINE : CLEAR_LINE);
181   EEPROM_set_cs_line((data & 0x08) ? CLEAR_LINE : ASSERT_LINE);
179   eeprom_write_bit(data & 0x20);
180   eeprom_set_clock_line((data & 0x10) ? ASSERT_LINE : CLEAR_LINE);
181   eeprom_set_cs_line((data & 0x08) ? CLEAR_LINE : ASSERT_LINE);
182182
183183   irq_enabled = ( data >> 6 ) & 1;
184184
src/mame/drivers/segas16b.c
r2762r2763
110110
111111The system consists of a main board and a ROM board. Many games are protected, either with a Hitachi FD1094
112112or an Intel 8751 MCU. The games can be swapped to any main board by exchanging ROM boards and protection chips.
113The games are generally tied to its 'type' ROM board, though there are some games that are available on more
114than one type of ROM board.
113The games are generally tied to their 'type' ROM board and can not be ROM swapped to other ROM boards, though
114there are some games that are available on more than one type of ROM board.
115115
116116
117117PCB Layout
r2762r2763
173173ROM Boards
174174----------
175175
176171-5521 (SYSTEM16B TYPE)
177|-------------------------------|
178|16    SCR03      SCR13         |
179|                               |
180|15    SCR02      SCR12         |
181|  CN3                     CN1  |
182|14|-| SCR01      SCR11    |-|  |
183|  | |                     | |  |
184|13| | *          OBJ7-E   | |  |
185|  | |                     | |  |
186|12| | SPEECH1    OBJ6-E   | |  |
187|  | |                     | |  |
188|11| | SPEECH0    OBJ5-E   | |  |
189|  | |                     | |  |
190|10|-| S-PROG     OBJ4-E   |-|  |
191|            S2          74LS138|
192|9   74F139  S1   315-5298    S6|
193|                             S5|
194|8     ROM1-E     OBJ3-E      S4|
195|                             S3|
196|7 CN4 ROM0-E     OBJ2-E   CN2  |
197|  |-|                     |-|  |
198|6 | | ROM1-O     OBJ1-E   | |  |
199|  | |                     | |  |
200|5 | | ROM0-O     OBJ0-E   | |  |
201|  | |                     | |  |
202|4 | | OBJ7-O     OBJ3-O   | |  |
203|  | |                     | |  |
204|3 | | OBJ6-O     OBJ2-O   | |  |
205|  |-|                     |-|  |
206|2     OBJ5-O     OBJ1-O        |
207|                            S7 |
208|1     OBJ4-O     OBJ0-O        |
209|        A          B         C |
210|-------------------------------|
211Notes:
212            * - Empty position, no socket
213        S1/S2 - Jumpers to configure 68k program ROM size
214                S1 shorted = 512K
215                S2 shorted = 1M
216
217     S3/4/5/6 - Jumpers to configure object ROM size
218                S3 + S6 + S7 shorted = 512K or 1M
219                S4 + S5 shorted = 2M
220
221     315-5298 - Signetics PLS153F Field Programmable Logic Array stamped '315-5298' (DIP20)
222
223
224Games that use this ROM board...
225-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
226Altered Beast    |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
227CPU  - 68000     |--------------------------------------------------------------------------------------------------------------------------------------|
2288751 - 317-0076  |EPR11717 EPR11718 EPR11719 -        EPR11882 -        EPR11883 -        EPR11671 EPR11672 EPR11673          EPR11722 EPR11723 EPR11724|
229                 |--------------------------------------------------------------------------------------------------------------------------------------|
230                 |                                                                                                                                      |
231                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
232                 |--------------------------------------------------------------------------------------------------------------------------------------|
233                 |EPR11725 EPR11726 EPR11727 EPR11728 EPR11729 EPR11730 EPR11731 EPR11732 EPR11733 EPR11734 EPR11735 -        EPR11736 EPR11737 EPR11738|
234-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
235
236-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
237Altered Beast    |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
238CPU  -           |--------------------------------------------------------------------------------------------------------------------------------------|
2398751 -           |EPR11717 EPR11718 EPR11719 -        EPR11739 -        EPR11740 -        EPR11671 EPR11672 EPR11673          EPR11722 EPR11723 EPR11724|
240                 |--------------------------------------------------------------------------------------------------------------------------------------|
241                 |                                                                                                                                      |
242                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
243                 |--------------------------------------------------------------------------------------------------------------------------------------|
244                 |EPR11725 EPR11726 EPR11727 EPR11728 EPR11729 EPR11730 EPR11731 EPR11732 EPR11733 EPR11734 EPR11735 -        EPR11736 EPR11737 EPR11738|
245-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
246
247-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
248Altered Beast    |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
249CPU  -           |--------------------------------------------------------------------------------------------------------------------------------------|
2508751 -           |EPR11717 EPR11718 EPR11719 -        EPR11522 -        EPR11523 -        EPR11671 EPR11672 EPR11673          EPR11722 EPR11723 EPR11724|
251                 |--------------------------------------------------------------------------------------------------------------------------------------|
252                 |                                                                                                                                      |
253                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
254                 |--------------------------------------------------------------------------------------------------------------------------------------|
255                 |EPR11725 EPR11726 EPR11727 EPR11728 EPR11729 EPR11730 EPR11731 EPR11732 EPR11733 EPR11734 EPR11735 -        EPR11736 EPR11737 EPR11738|
256-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
257
258-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
259Golden Axe       |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
260CPU  - 317-0121  |--------------------------------------------------------------------------------------------------------------------------------------|
2618751 -           |-        -        -        -        EPR12539 EPR12519 EPR12540 EPR12521 EPR12390 MPR12384 -                 MPR12385 MPR12386 MPR12387|
262                 |--------------------------------------------------------------------------------------------------------------------------------------|
263                 |                                                                                                                                      |
264                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
265                 |--------------------------------------------------------------------------------------------------------------------------------------|
266                 |MPR12378 MPR12380 MPR12382 -        MPR12379 MPR12381 MPR12383 -        -        -        -        -        -        -        -       |
267-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
268
269-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
270Jyuohki          |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
271CPU  -           |--------------------------------------------------------------------------------------------------------------------------------------|
2728751 -           |EPR11717 EPR11718 EPR11719 -        EPR11720 -        EPR11721 -        EPR11671 EPR11672 EPR11673          EPR11722 EPR11723 EPR11724|
273                 |--------------------------------------------------------------------------------------------------------------------------------------|
274                 |                                                                                                                                      |
275                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
276                 |--------------------------------------------------------------------------------------------------------------------------------------|
277                 |EPR11725 EPR11726 EPR11727 EPR11728 EPR11729 EPR11730 EPR11731 EPR11732 EPR11733 EPR11734 EPR11735 -        EPR11736 EPR11737 EPR11738|
278-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
279
280-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
281Heavyweight Champ|A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
282CPU  - 68000     |--------------------------------------------------------------------------------------------------------------------------------------|
2838751 -           |-        -        -        -        EPR11238 -        EPR11239 -        EPR      EPR      EPR               EPR      EPR      EPR     |
284                 |--------------------------------------------------------------------------------------------------------------------------------------|
285                 |                                                                                                                                      |
286                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
287                 |--------------------------------------------------------------------------------------------------------------------------------------|
288                 |EPR      EPR      EPR      EPR      EPR      EPR      EPR      EPR      -        -        -         -       EPR      EPR      EPR     |
289-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
290
291-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
292Ryu Kyu          |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
293CPU  - 317-5023  |--------------------------------------------------------------------------------------------------------------------------------------|
2948751 -           |-        -        -        -        EPR13347 -        -        EPR13348 EPR13349 EPR13350 -                 EPR13351 EPR13352 EPR13353|
295                 |--------------------------------------------------------------------------------------------------------------------------------------|
296                 |                                                                                                                                      |
297                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
298                 |--------------------------------------------------------------------------------------------------------------------------------------|
299                 |EPR13354 EPR13355 -        -        EPR13356 EPR13357 -        -        -        -         -       -        -        -         -      |
300-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
301
302-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
303Tetris           |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
304CPU  - 317-0092  |--------------------------------------------------------------------------------------------------------------------------------------|
3058751 -           |-        -        -        -        EPR12192 -        EPR12193 -        EPR12168 -        -                 EPR12165 EPR12166 EPR12167|
306                 |--------------------------------------------------------------------------------------------------------------------------------------|
307                 |                                                                                                                                      |
308                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
309                 |--------------------------------------------------------------------------------------------------------------------------------------|
310                 |EPR      -        -        -        EPR      -        -        -        -        -        -        -        -        -        -       |
311-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
312
313-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
314Dynamite Dux     |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
315CPU  - 317-0096  |--------------------------------------------------------------------------------------------------------------------------------------|
3168751 -           |-        -        -        -        EPR11190 EPR11913 EPR11191 EPR11915 EPR11916 -        -                 MPR11917 MPR11918 MPR11919|
317                 |--------------------------------------------------------------------------------------------------------------------------------------|
318                 |                                                                                                                                      |
319                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
320                 |--------------------------------------------------------------------------------------------------------------------------------------|
321                 |MPR11920 MPR11921 -        -        MPR11922 MPR11923 -        -        -        -        -        -        -        -        -       |
322-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
323
324-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
325Golden Axe       |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
326CPU  -           |--------------------------------------------------------------------------------------------------------------------------------------|
3278751 -           |-        -        -        -        EPR12522 EPR12519 EPR12523 EPR12521 EPR12390 MPR12384 -                 MPR12385 MPR12386 MPR12387|
328                 |--------------------------------------------------------------------------------------------------------------------------------------|
329                 |                                                                                                                                      |
330                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
331                 |--------------------------------------------------------------------------------------------------------------------------------------|
332                 |MPR12378 MPR12380 MPR12382 -        MPR12379 MPR12381 MPR12383 -        -        -        -        -        -        -        -       |
333-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
334
335
176336171-5358 (SYSTEM16B TYPE)
177337|-------------------------------|
178338|11    S-PROG4    SCR03         |
r2762r2763
384544                 |--------------------------------------------------------------------------------------------------|
385545                 |EPR      EPR      EPR      -        EPR      EPR      EPR      -        EPR      EPR      EPR     |
386546-----------------|--------------------------------------------------------------------------------------------------|
387                  Locations are correct but no Sega part numbers known for this version!
547                  Locations are correct but Sega part numbers unknown for this version!
388548
389
390171-5521 (SYSTEM16B TYPE)
549171-5797 (SYSTEM 16B TYPE)
391550|-------------------------------|
392|16    SCR03      SCR13         |
393551|                               |
394|15    SCR02      SCR12         |
552|                               |
553|                               |
395554|  CN3                     CN1  |
396|14|-| SCR01      SCR11    |-|  |
555|13|-| S-PROG0    SCR03    |-|  |
397556|  | |                     | |  |
398|13| | *          OBJ7-E   | |  |
399557|  | |                     | |  |
400|12| | SPEECH1    OBJ6-E   | |  |
558|12| | SPEECH1    SCR02    | |  |
401559|  | |                     | |  |
402|11| | SPEECH0    OBJ5-E   | |  |
403560|  | |                     | |  |
404|10|-| S-PROG     OBJ4-E   |-|  |
405|            S2          74LS138|
406|9   74F139  S1   315-5298    S6|
407|                             S5|
408|8     ROM1-E     OBJ3-E      S4|
409|                             S3|
410|7 CN4 ROM0-E     OBJ2-E   CN2  |
561|11| | S-PROG1    SCR01    | |  |
562|  | |                     | |  |
563|  | |S11 S12 S13  S1 S2 S3| |  |
564|10|-|S14 S15 S16  S4 S5 S6|-|  |
565|                               |
566|                  315-5298     |
567|9     |-------| 74LS08  10MHz  |
568|      |315-   | 74LS14 74HC139 |
569|      |   5250|                |
570|8     |       |  OBJ3-E        |
571|      |-------|                |
572|7 CN4            OBJ3-O   CN2  |
411573|  |-|                     |-|  |
412|6 | | ROM1-O    OBJ1-E   | |  |
574|6 | | 74HC139    OBJ2-E   | |  |
413575|  | |                     | |  |
414|5 | | ROM0-O     OBJ0-E   | |  |
415|  | |                     | |  |
416|4 | | OBJ7-O     OBJ3-O   | |  |
417|  | |                     | |  |
418|3 | | OBJ6-O     OBJ2-O   | |  |
576|5 | | |-------|  OBJ2-O   | |  |
577|  | | |*315-  |           | |  |
578|4 | | |   5248|  OBJ1-E   | |  |
579|  | | |       |           | |  |
580|3 | | |-------|  OBJ1-O   | |  |
419581|  |-|                     |-|  |
420|2     OBJ5-O     OBJ1-O        |
421|                            S7 |
422|1     OBJ4-O     OBJ0-O        |
423|        A          B         C |
582|2     ROM0-E     OBJ0-E     S7 |
583|                            S8 |
584|1     ROM0-O     OBJ0-O     S9 |
585|        A          B        S10|
424586|-------------------------------|
425587Notes:
426            * - Empty position, no socket
427        S1/S2 - Jumpers to configure 68k program ROM size
428                S1 shorted = 512K
429                S2 shorted = 1M
588       * - This IC underneath the PCB
589315-5298 - Signetics PLS153F Field Programmable Logic Array stamped '315-5298' (DIP20)
590315-5248 - Custom Sega IC (QFP100)
591315-5250 - Custom Sega IC (QFP120)
592  S1-S16 - Jumpers to configure ROM sizes               //usage TODO
593           Jumpers are either shorted or not shorted.
594           In the tables below, the listed jumpers per game are the shorted ones, the unlisted ones are not shorted.
430595
431     S3/4/5/6 - Jumpers to configure object ROM size
432                S3 + S6 + S7 shorted = 512K or 1M
433                S4 + S5 shorted = 2M
434596
435     315-5298 - Signetics PLS153F Field Programmable Logic Array stamped '315-5298' (DIP20)
436
437
438597Games that use this ROM board...
439-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
440Altered Beast    |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
441CPU  - 68000     |--------------------------------------------------------------------------------------------------------------------------------------|
4428751 - 317-0076  |EPR11717 EPR11718 EPR11719 -        EPR11882 -        EPR11883 -        EPR11671 EPR11672 EPR11673          EPR11722 EPR11723 EPR11724|
443                 |--------------------------------------------------------------------------------------------------------------------------------------|
444                 |                                                                                                                                      |
445                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
446                 |--------------------------------------------------------------------------------------------------------------------------------------|
447                 |EPR11725 EPR11726 EPR11727 EPR11728 EPR11729 EPR11730 EPR11731 EPR11732 EPR11733 EPR11734 EPR11735 -        EPR11736 EPR11737 EPR11738|
448-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
598-----------------|--------------------------------------------------------------------------------------------------|
599Golden Axe       |A1       A2                                                             A11      A12      A13     |
600CPU  - 317-0110  |--------------------------------------------------------------------------------------------------|
6018751 -           |EPR12388 EPR12389                                                       MPR12384 -        EPR12390|
602                 |--------------------------------------------------------------------------------------------------|
603                 |                                                                                                  |
604S2  S3  S5       |B1       B2       B3       B4       B5       B6       B7       B8       B11      B12      B13     |
605S7  S9  S12      |--------------------------------------------------------------------------------------------------|
606S13 S15          |EPR11290 EPR11291 EPR11292 EPR11293 EPR11294 EPR11295 EPR11296 EPR11297 EPR12385 EPR12386 EPR12387|
607-----------------|--------------------------------------------------------------------------------------------------|
449608
450-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
451Altered Beast    |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
452CPU  -           |--------------------------------------------------------------------------------------------------------------------------------------|
4538751 -           |EPR11717 EPR11718 EPR11719 -        EPR11739 -        EPR11740 -        EPR11671 EPR11672 EPR11673          EPR11722 EPR11723 EPR11724|
454                 |--------------------------------------------------------------------------------------------------------------------------------------|
455                 |                                                                                                                                      |
456                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
457                 |--------------------------------------------------------------------------------------------------------------------------------------|
458                 |EPR11725 EPR11726 EPR11727 EPR11728 EPR11729 EPR11730 EPR11731 EPR11732 EPR11733 EPR11734 EPR11735 -        EPR11736 EPR11737 EPR11738|
459-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
609-----------------|--------------------------------------------------------------------------------------------------|
610Golden Axe       |A1       A2                                                             A11      A12      A13     |
611CPU  - 317-0122  |--------------------------------------------------------------------------------------------------|
6128751 -           |EPR12542 EPR12543                                                       MPR12384 -        EPR12390|
613                 |--------------------------------------------------------------------------------------------------|
614                 |                                                                                                  |
615S2  S3  S5       |B1       B2       B3       B4       B5       B6       B7       B8       B11      B12      B13     |
616S7  S9  S12      |--------------------------------------------------------------------------------------------------|
617S13 S15          |EPR11290 EPR11291 EPR11292 EPR11293 EPR11294 EPR11295 EPR11296 EPR11297 EPR12385 EPR12386 EPR12387|
618-----------------|--------------------------------------------------------------------------------------------------|
460619
461-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
462Altered Beast    |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
463CPU  -           |--------------------------------------------------------------------------------------------------------------------------------------|
4648751 -           |EPR11717 EPR11718 EPR11719 -        EPR11522 -        EPR11523 -        EPR11671 EPR11672 EPR11673          EPR11722 EPR11723 EPR11724|
465                 |--------------------------------------------------------------------------------------------------------------------------------------|
466                 |                                                                                                                                      |
467                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
468                 |--------------------------------------------------------------------------------------------------------------------------------------|
469                 |EPR11725 EPR11726 EPR11727 EPR11728 EPR11729 EPR11730 EPR11731 EPR11732 EPR11733 EPR11734 EPR11735 -        EPR11736 EPR11737 EPR11738|
470-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
620-----------------|--------------------------------------------------------------------------------------------------|
621Golden Axe       |A1       A2                                                             A11      A12      A13     |
622CPU  - 317-0123A |--------------------------------------------------------------------------------------------------|
6238751 -           |EPR12544 EPR12545                                                       MPR12384 -        EPR12390|
624                 |--------------------------------------------------------------------------------------------------|
625                 |                                                                                                  |
626S2  S3  S5       |B1       B2       B3       B4       B5       B6       B7       B8       B11      B12      B13     |
627S7  S9  S12      |--------------------------------------------------------------------------------------------------|
628S13 S15          |EPR11290 EPR11291 EPR11292 EPR11293 EPR11294 EPR11295 EPR11296 EPR11297 EPR12385 EPR12386 EPR12387|
629-----------------|--------------------------------------------------------------------------------------------------|
471630
472-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
473Golden Axe       |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
474CPU  - 317-0121  |--------------------------------------------------------------------------------------------------------------------------------------|
4758751 -           |-        -        -        -        EPR12539 EPR12519 EPR12540 EPR12521 EPR12390 MPR12384 -                 MPR12385 MPR12386 MPR12387|
476                 |--------------------------------------------------------------------------------------------------------------------------------------|
477                 |                                                                                                                                      |
478                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
479                 |--------------------------------------------------------------------------------------------------------------------------------------|
480                 |MPR12378 MPR12380 MPR12382 -        MPR12379 MPR12381 MPR12383 -        -        -        -        -        -        -        -       |
481-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
631-----------------|--------------------------------------------------------------------------------------------------|
632Toryumon         |A1       A2                                                             A11      A12      A13     |
633CPU  - 68000     |--------------------------------------------------------------------------------------------------|
6348751 -           |EPR17688 EPR17689                                                       EPR17690 -        EPR17691|
635                 |--------------------------------------------------------------------------------------------------|
636                 |                                                                                                  |
637                 |B1       B2       B3       B4       B5       B6       B7       B8       B11      B12      B13     |
638                 |--------------------------------------------------------------------------------------------------|
639                 |EPR17692 EPR17693 EPR17694 EPR17695 EPR17696 EPR17697 EPR17698 EPR17699 EPR17700 EPR17701 EPR17702|
640-----------------|--------------------------------------------------------------------------------------------------|
482641
483-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
484Jyuohki          |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
485CPU  -           |--------------------------------------------------------------------------------------------------------------------------------------|
4868751 -           |EPR11717 EPR11718 EPR11719 -        EPR11720 -        EPR11721 -        EPR11671 EPR11672 EPR11673          EPR11722 EPR11723 EPR11724|
487                 |--------------------------------------------------------------------------------------------------------------------------------------|
488                 |                                                                                                                                      |
489                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
490                 |--------------------------------------------------------------------------------------------------------------------------------------|
491                 |EPR11725 EPR11726 EPR11727 EPR11728 EPR11729 EPR11730 EPR11731 EPR11732 EPR11733 EPR11734 EPR11735 -        EPR11736 EPR11737 EPR11738|
492-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
642-----------------|--------------------------------------------------------------------------------------------------|
643E-Swat           |A1       A2                                                             A11      A12      A13     |
644CPU  - 317-0129  |--------------------------------------------------------------------------------------------------|
6458751 -           |EPR12656 EPR12657                                                       EPR12616 -        EPR12617|
646                 |--------------------------------------------------------------------------------------------------|
647                 |                                                                                                  |
648                 |B1       B2       B3       B4       B5       B6       B7       B8       B11      B12      B13     |
649                 |--------------------------------------------------------------------------------------------------|
650                 |MPR12618 MPR12619 MPR12620 MPR12621 MPR12622 MPR12623 -        -        EPR12624 EPR12625 EPR12626|
651-----------------|--------------------------------------------------------------------------------------------------|
493652
494-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
495Heavyweight Champ|A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
496CPU  - 68000     |--------------------------------------------------------------------------------------------------------------------------------------|
4978751 -           |-        -        -        -        EPR11238 -        EPR11239 -        EPR      EPR      EPR               EPR      EPR      EPR     |
498                 |--------------------------------------------------------------------------------------------------------------------------------------|
499                 |                                                                                                                                      |
500                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
501                 |--------------------------------------------------------------------------------------------------------------------------------------|
502                 |EPR      EPR      EPR      EPR      EPR      EPR      EPR      EPR      -        -        -         -       EPR      EPR      EPR     |
503-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
653-----------------|--------------------------------------------------------------------------------------------------|
654E-Swat           |A1       A2                                                             A11      A12      A13     |
655CPU  - 317-0130  |--------------------------------------------------------------------------------------------------|
6568751 -           |EPR12658 EPR12659                                                       EPR12616 -        EPR12617|
657                 |--------------------------------------------------------------------------------------------------|
658                 |                                                                                                  |
659                 |B1       B2       B3       B4       B5       B6       B7       B8       B11      B12      B13     |
660                 |--------------------------------------------------------------------------------------------------|
661                 |MPR12618 MPR12619 MPR12620 MPR12621 MPR12622 MPR12623 -        -        MPR12624 MPR12625 MPR12626|
662-----------------|--------------------------------------------------------------------------------------------------|
504663
505-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
506Ryu Kyu          |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
507CPU  - 317-5023  |--------------------------------------------------------------------------------------------------------------------------------------|
5088751 -           |-        -        -        -        EPR13347 -        -        EPR13348 EPR13349 EPR13350 -                 EPR13351 EPR13352 EPR13353|
509                 |--------------------------------------------------------------------------------------------------------------------------------------|
510                 |                                                                                                                                      |
511                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
512                 |--------------------------------------------------------------------------------------------------------------------------------------|
513                 |EPR13354 EPR13355 -        -        EPR13356 EPR13357 -        -        -        -         -       -        -        -         -      |
514-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
664-----------------|--------------------------------------------------------------------------------------------------|
665MVP              |A1       A2                                                             A11      A12      A13     |
666CPU  - 317-0143  |--------------------------------------------------------------------------------------------------|
6678751 - none      |EPR12999 EPR13000                                                       EPR13001 -        EPR13002|
668                 |--------------------------------------------------------------------------------------------------|
669                 |                                                                                                  |
670                 |B1       B2       B3       B4       B5       B6       B7       B8       B11      B12      B13     |
671                 |--------------------------------------------------------------------------------------------------|
672                 |MPR13003 MPR13004 MPR13005 MPR13006 MPR13007 MPR13008 MPR13009 MPR13010 MPR13011 MPR13012 MPR13013|
673-----------------|--------------------------------------------------------------------------------------------------|
515674
516-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
517Tetris           |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
518CPU  - 317-0092  |--------------------------------------------------------------------------------------------------------------------------------------|
5198751 -           |-        -        -        -        EPR12192 -        EPR12193 -        EPR12168 -        -                 EPR12165 EPR12166 EPR12167|
520                 |--------------------------------------------------------------------------------------------------------------------------------------|
521                 |                                                                                                                                      |
522                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
523                 |--------------------------------------------------------------------------------------------------------------------------------------|
524                 |EPR      -        -        -        EPR      -        -        -        -        -        -        -        -        -        -       |
525-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
526675
527-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
528Dynamite Dux     |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
529CPU  - 317-0096  |--------------------------------------------------------------------------------------------------------------------------------------|
5308751 -           |-        -        -        -        EPR11190 EPR11913 EPR11191 EPR11915 EPR11916 -        -                 MPR11917 MPR11918 MPR11919|
531                 |--------------------------------------------------------------------------------------------------------------------------------------|
532                 |                                                                                                                                      |
533                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
534                 |--------------------------------------------------------------------------------------------------------------------------------------|
535                 |MPR11920 MPR11921 -        -        MPR11922 MPR11923 -        -        -        -        -        -        -        -        -       |
536-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
537
538-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
539Golden Axe       |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
540CPU  -           |--------------------------------------------------------------------------------------------------------------------------------------|
5418751 -           |-        -        -        -        EPR12522 EPR12519 EPR12523 EPR12521 EPR12390 MPR12384 -                 MPR12385 MPR12386 MPR12387|
542                 |--------------------------------------------------------------------------------------------------------------------------------------|
543                 |                                                                                                                                      |
544                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
545                 |--------------------------------------------------------------------------------------------------------------------------------------|
546                 |MPR12378 MPR12380 MPR12382 -        MPR12379 MPR12381 MPR12383 -        -        -        -        -        -        -        -       |
547-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
548
549
550676171-5704 (SYSTEM 16B TYPE)
551677|--------------------------------|
552678|16    SCR03      SCR13          |
r2762r2763
630756-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
631757Aurial           |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
632758CPU  - 317-0168  |--------------------------------------------------------------------------------------------------------------------------------------|
6338751 -           |EPR13440 EPR13441 EPR13442 EPR13443 EPR13468 EPR13445 EPR13469 EPR13447 EPR13448 MPR13449                   EPR13450 EPR13451 EPR13452|
7598751 -           |EPR13440 EPR13441 EPR13442 EPR13443 EPR13468 EPR13445 EPR13469 EPR13447 EPR13448 MPR13449 MPR12461          EPR13450 EPR13451 EPR13452|
634760                 |--------------------------------------------------------------------------------------------------------------------------------------|
635761                 |                                                                                                                                      |
636762                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
r2762r2763
693819                 |EPR11725 EPR11726 EPR11727 EPR11728 EPR11729 EPR11730 EPR11731 EPR11732 EPR11733 EPR11734 EPR11735 -        EPR11736 EPR11737 EPR11738|
694820-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
695821
696Also on 171-5704 - Tetris(?)
822-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
823Wrestle War      |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
824CPU  - 68000     |--------------------------------------------------------------------------------------------------------------------------------------|
8258751 - 317-0103  |OPR12141 OPR12142 -        -        EPR12371 EPR12144 EPR12372 EPR12146 EPR12147 MPR12148 MPR12149          MPR12150 MPR12151 MPR12152|
826                 |--------------------------------------------------------------------------------------------------------------------------------------|
827                 |                                                                                                                                      |
828                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
829S2 S3 S6 S7 S9   |--------------------------------------------------------------------------------------------------------------------------------------|
830S11 S13 S15 S17  |MPR12153 MPR12154 MPR12155 OPR12156 MPR12157 MPR12158 MPR12159 OPR12160 OPR12161 OPR12162 -        -        -        -        -       |
831-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
697832
833-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
834MVP              |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
835CPU  - 317-0142  |--------------------------------------------------------------------------------------------------------------------------------------|
8368751 - none      |EPR12962 EPR12963 EPR12964 -        EPR12965 EPR12966 EPR12967 EPR12968 EPR12969 EPR12970 -                 EPR12971 EPR12972 EPR12973|
837                 |--------------------------------------------------------------------------------------------------------------------------------------|
838                 |                                                                                                                                      |
839                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
840                 |--------------------------------------------------------------------------------------------------------------------------------------|
841                 |EPR12974 EPR12975 EPR12976 -        EPR12977 EPR12978 EPR12979 -        EPR12980 EPR12981 EPR12982 -        EPR12983 EPR12984 EPR12985|
842-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
698843
699171-5797 (SYSTEM 16B TYPE)
700|-------------------------------|
701|                               |
702|                               |
703|                               |
704|  CN3                     CN1  |
705|13|-| S-PROG0    SCR03    |-|  |
706|  | |                     | |  |
707|  | |                     | |  |
708|12| | SPEECH1    SCR02    | |  |
709|  | |                     | |  |
710|  | |                     | |  |
711|11| | S-PROG1    SCR01    | |  |
712|  | |                     | |  |
713|  | |S11 S12 S13  S1 S2 S3| |  |
714|10|-|S14 S15 S16  S4 S5 S6|-|  |
715|                               |
716|                  315-5298     |
717|9     |-------| 74LS08  10MHz  |
718|      |315-   | 74LS14 74HC139 |
719|      |   5250|                |
720|8     |       |  OBJ3-E        |
721|      |-------|                |
722|7 CN4            OBJ3-O   CN2  |
723|  |-|                     |-|  |
724|6 | | 74HC139    OBJ2-E   | |  |
725|  | |                     | |  |
726|5 | | |-------|  OBJ2-O   | |  |
727|  | | |*315-  |           | |  |
728|4 | | |   5248|  OBJ1-E   | |  |
729|  | | |       |           | |  |
730|3 | | |-------|  OBJ1-O   | |  |
731|  |-|                     |-|  |
732|2     ROM0-E     OBJ0-E     S7 |
733|                            S8 |
734|1     ROM0-O     OBJ0-O     S9 |
735|        A          B        S10|
736|-------------------------------|
737Notes:
738       * - This IC underneath the PCB
739315-5298 - Signetics PLS153F Field Programmable Logic Array stamped '315-5298' (DIP20)
740315-5248 - Custom Sega IC (QFP100)
741315-5250 - Custom Sega IC (QFP120)
742  S1-S16 - Jumpers to configure ROM sizes               //usage TODO
743           Jumpers are either shorted or not shorted.
744           In the tables below, the listed jumpers per game are the shorted ones, the unlisted ones are not shorted.
844-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
845Riot City        |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
846CPU  - 68000     |--------------------------------------------------------------------------------------------------------------------------------------|
8478751 -           |-        -        -        -        EPR14610 EPR14611 EPR14612 EPR14613 EPR14614 EPR14615 -                 EPR14616 EPR14617 EPR14618|
848                 |--------------------------------------------------------------------------------------------------------------------------------------|
849                 |                                                                                                                                      |
850                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
851                 |--------------------------------------------------------------------------------------------------------------------------------------|
852                 |EPR14619 EPR14620 EPR14621 -        EPR14622 EPR14623 EPR14624 -        -        -        -        -        EPR14625 EPR14626 EPR14627|
853-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
745854
855-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
856Tetris           |A1       A2       A3       A4       A5       A6       A7       A8       A10      A11      A12               A14      A15      A16     |
857CPU  - 317-0092  |--------------------------------------------------------------------------------------------------------------------------------------|
8588751 -           |-        -        -        -        EPR12192 -        EPR12193 -        EPR12168 -        -                 EPR12165 EPR12166 EPR12167|
859                 |--------------------------------------------------------------------------------------------------------------------------------------|
860                 |                                                                                                                                      |
861                 |B1       B2       B3       B4       B5       B6       B7       B8       B10      B11      B12      B13      B14      B15      B16     |
862                 |--------------------------------------------------------------------------------------------------------------------------------------|
863                 |EPR      -        -        -        EPR      -        -        -        -        -        -        -        -        -        -       |
864-----------------|--------------------------------------------------------------------------------------------------------------------------------------|
865                  Sega part number for B1 & B5 unknown
746866
747Games that use this ROM board...
748-----------------|--------------------------------------------------------------------------------------------------|
749Golden Axe       |A1       A2                                                             A11      A12      A13     |
750CPU  - 317-0110  |--------------------------------------------------------------------------------------------------|
7518751 -           |EPR12388 EPR12389                                                       MPR12384 -        EPR12390|
752                 |--------------------------------------------------------------------------------------------------|
753                 |                                                                                                  |
754S2  S3  S5       |B1       B2       B3       B4       B5       B6       B7       B8       B11      B12      B13     |
755S7  S9  S12      |--------------------------------------------------------------------------------------------------|
756S13 S15          |EPR11290 EPR11291 EPR11292 EPR11293 EPR11294 EPR11295 EPR11296 EPR11297 EPR12385 EPR12386 EPR12387|
757-----------------|--------------------------------------------------------------------------------------------------|
867***************************************************************************/
758868
759-----------------|--------------------------------------------------------------------------------------------------|
760Golden Axe       |A1       A2                                                             A11      A12      A13     |
761CPU  - 317-0122  |--------------------------------------------------------------------------------------------------|
7628751 -           |EPR12542 EPR12543                                                       MPR12384 -        EPR12390|
763                 |--------------------------------------------------------------------------------------------------|
764                 |                                                                                                  |
765S2  S3  S5       |B1       B2       B3       B4       B5       B6       B7       B8       B11      B12      B13     |
766S7  S9  S12      |--------------------------------------------------------------------------------------------------|
767S13 S15          |EPR11290 EPR11291 EPR11292 EPR11293 EPR11294 EPR11295 EPR11296 EPR11297 EPR12385 EPR12386 EPR12387|
768-----------------|--------------------------------------------------------------------------------------------------|
769869
770-----------------|--------------------------------------------------------------------------------------------------|
771Golden Axe       |A1       A2                                                             A11      A12      A13     |
772CPU  - 317-0123A |--------------------------------------------------------------------------------------------------|
7738751 -           |EPR12544 EPR12545                                                       MPR12384 -        EPR12390|
774                 |--------------------------------------------------------------------------------------------------|
775                 |                                                                                                  |
776S2  S3  S5       |B1       B2       B3       B4       B5       B6       B7       B8       B11      B12      B13     |
777S7  S9  S12      |--------------------------------------------------------------------------------------------------|
778S13 S15          |EPR11290 EPR11291 EPR11292 EPR11293 EPR11294 EPR11295 EPR11296 EPR11297 EPR12385 EPR12386 EPR12387|
779-----------------|--------------------------------------------------------------------------------------------------|
780
781-----------------|--------------------------------------------------------------------------------------------------|
782Toryumon         |A1       A2                                                             A11      A12      A13     |
783CPU  - 68000     |--------------------------------------------------------------------------------------------------|
7848751 -           |EPR17688 EPR17689                                                       EPR17690 -        EPR17691|
785                 |--------------------------------------------------------------------------------------------------|
786                 |                                                                                                  |
787                 |B1       B2       B3       B4       B5       B6       B7       B8       B11      B12      B13     |
788                 |--------------------------------------------------------------------------------------------------|
789                 |EPR17692 EPR17693 EPR17694 EPR17695 EPR17696 EPR17697 EPR17698 EPR17699 EPR17700 EPR17701 EPR17702|
790-----------------|--------------------------------------------------------------------------------------------------|
791
792-----------------|--------------------------------------------------------------------------------------------------|
793E-Swat           |A1       A2                                                             A11      A12      A13     |
794CPU  - 317-0129  |--------------------------------------------------------------------------------------------------|
7958751 -           |EPR12656 EPR12657                                                       EPR12616 -        EPR12617|
796                 |--------------------------------------------------------------------------------------------------|
797                 |                                                                                                  |
798                 |B1       B2       B3       B4       B5       B6       B7       B8       B11      B12      B13     |
799                 |--------------------------------------------------------------------------------------------------|
800                 |MPR12618 MPR12619 MPR12620 MPR12621 MPR12622 MPR12623 -        -        EPR12624 EPR12625 EPR12626|
801-----------------|--------------------------------------------------------------------------------------------------|
802
803-----------------|--------------------------------------------------------------------------------------------------|
804E-Swat           |A1       A2                                                             A11      A12      A13     |
805CPU  - 317-0130  |--------------------------------------------------------------------------------------------------|
8068751 -           |EPR12658 EPR12659                                                       EPR12616 -        EPR12617|
807                 |--------------------------------------------------------------------------------------------------|
808                 |                                                                                                  |
809                 |B1       B2       B3       B4       B5       B6       B7       B8       B11      B12      B13     |
810                 |--------------------------------------------------------------------------------------------------|
811                 |MPR12618 MPR12619 MPR12620 MPR12621 MPR12622 MPR12623 -        -        EPR12624 EPR12625 EPR12626|
812-----------------|--------------------------------------------------------------------------------------------------|
813
814
815
816
817Unknown Rom Boards
818------------------
819Wrestle War (171-5704 or 171-5521)    custom cpu 317-0143    Riot City (171-5704 or 171-5521)
820Sega 1987/88                          mvp                   (c)1991 SEGA/WESTONE
821System 16 Type B board
822                                      13000.rom              CPU   : 68000 Z-80B
823                                      12999.rom              SOUND : YM2151 uPD7759
824                                                             OSC.  : 20.000MHz 8.0000MHz
825Filename  Function                    13011.rom                      (SYSTEM 16B)
826                                      13012.rom
827WW.A1     Object 4 - Odd              13013.rom              EPR14610.BIN ; MAIN PRG
828WW.A2     Object 5 - Odd                                     EPR14611.BIN ;  |
829WW.A5     Program 68000 0 - Odd       13010.rom              EPR14612.BIN ;  |
830WW.A6     Program 68000 1 - Odd       13009.rom              EPR14613.BIN ; /
831WW.A7     Program 68000 0 - Even      13006.rom              EPR14614.BIN ; SOUND PRG
832WW.A8     Program 68000 1 - Even      13003.rom              EPR14615.BIN ; VOICE DATA
833WW.A10    Program Z80                 13007.rom              EPR14616.BIN ; SCR CHR
834WW.A11    Speech 0                    13004.rom              EPR14617.BIN ;  |
835WW.A12    Speech 1                    13008.rom              EPR14618.BIN ;  |
836WW.A14    Screen 0                    13005.rom              EPR14625.BIN ;  |
837WW.A15    Screen 1                                           EPR14626.BIN ;  |
838WW.A16    Screen 2                    13002.rom              EPR14627.BIN ; /
839                                      13001.rom              EPR14619.BIN ; OBJ CHR (ODD)
840WW.B1     Object 0 - Odd                                     EPR14620.BIN ;  |
841WW.B2     Object 1 - Odd                                     EPR14621.BIN ;  |
842WW.B3     Object 2 - Odd                                     EPR14622.BIN ; OBJ CHR (EVEN)
843WW.B4     Object 3 - Odd                                     EPR14623.BIN ;  |
844WW.B5     Object 0 - Even                                    EPR14624.BIN ; /
845WW.B6     Object 1 - Even
846WW.B7     Object 2 - Even
847WW.B8     Object 3 - Even
848WW.B10    Object 4 - Even
849WW.B11    Object 5 - Even
850
851*/
852
853870#include "driver.h"
854871#include "deprecat.h"
855872#include "system16.h"
src/mame/drivers/taito_f3.c
r2762r2763
5555   switch (offset)
5656   {
5757      case 0x0: /* MSW: Test switch, coins, eeprom access, LSW: Player Buttons, Start, Tilt, Service */
58         e=EEPROM_read_bit();
58         e=eeprom_read_bit();
5959         e=e|(e<<8);
6060         return ((e | input_port_read_indexed(machine, 2) | (input_port_read_indexed(machine, 2)<<8))<<16) /* top byte may be mirror of bottom byte??  see bubblem */
6161               | input_port_read_indexed(machine, 1);
r2762r2763
9898         return;
9999      case 0x04: /* Eeprom */
100100         if (ACCESSING_BITS_0_7) {
101            EEPROM_set_clock_line((data & 0x08) ? ASSERT_LINE : CLEAR_LINE);
102            EEPROM_write_bit(data & 0x04);
103            EEPROM_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
101            eeprom_set_clock_line((data & 0x08) ? ASSERT_LINE : CLEAR_LINE);
102            eeprom_write_bit(data & 0x04);
103            eeprom_set_cs_line((data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
104104         }
105105         return;
106106      case 0x05:   /* Player 3 & 4 coin counters */
r2762r2763
408408static NVRAM_HANDLER( taito_f3 )
409409{
410410   if (read_or_write)
411      EEPROM_save(file);
411      eeprom_save(file);
412412   else
413413   {
414414      static const UINT8 recalh_eeprom[128] =   {
r2762r2763
424424
425425      // RecalH does not initialise it's eeprom on first boot, so we provide one.
426426      // Same applies to gseeker.
427      EEPROM_init(&eeprom_interface_93C46);
427      eeprom_init(&eeprom_interface_93C46);
428428      if (file)
429         EEPROM_load(file);
429         eeprom_load(file);
430430      else if (f3_game==RECALH)
431         EEPROM_set_data(recalh_eeprom,128);
431         eeprom_set_data(recalh_eeprom,128);
432432      else if (f3_game==GSEEKER)
433         EEPROM_set_data(recalh_eeprom,128);
433         eeprom_set_data(recalh_eeprom,128);
434434   }
435435}
436436
src/mame/drivers/clshroad.c
r2762r2763
2020#include "driver.h"
2121#include "sound/custom.h"
2222
23static UINT8 *clshroad_sharedram;
24
2523/* Variables & functions defined in video: */
2624
2725extern UINT8 *clshroad_vram_0, *clshroad_vram_1;
r2762r2763
4947}
5048
5149
52/* Shared RAM with the sound CPU */
53
54static READ8_HANDLER ( clshroad_sharedram_r )   {   return clshroad_sharedram[offset];   }
55static WRITE8_HANDLER( clshroad_sharedram_w )   {   clshroad_sharedram[offset] = data;   }
56
5750static READ8_HANDLER( clshroad_input_r )
5851{
5952   return   ((~input_port_read(machine, "IN0") & (1 << offset)) ? 1 : 0) |
r2762r2763
6356}
6457
6558
66static ADDRESS_MAP_START( clshroad_readmem, ADDRESS_SPACE_PROGRAM, 8 )
67   AM_RANGE(0x0000, 0x7fff) AM_READ(SMH_ROM            )   // ROM
68   AM_RANGE(0x8000, 0x95ff) AM_READ(SMH_RAM            )   // Work   RAM
69   AM_RANGE(0x9600, 0x97ff) AM_READ(clshroad_sharedram_r   )   // Shared RAM
70   AM_RANGE(0x9800, 0x9dff) AM_READ(SMH_RAM            )   // Work   RAM
71   AM_RANGE(0x9e00, 0x9fff) AM_READ(SMH_RAM            )   // Sprite RAM
72   AM_RANGE(0xa100, 0xa107) AM_READ(clshroad_input_r      )   // Inputs
73   AM_RANGE(0xa800, 0xafff) AM_READ(SMH_RAM            )   // Layer  1
74   AM_RANGE(0xc000, 0xc7ff) AM_READ(SMH_RAM            )   // Layers 0
59static ADDRESS_MAP_START( clshroad_map, ADDRESS_SPACE_PROGRAM, 8 )
60   AM_RANGE(0x0000, 0x7fff) AM_ROM
61   AM_RANGE(0x8000, 0x95ff) AM_RAM
62   AM_RANGE(0x9600, 0x97ff) AM_RAM AM_SHARE(1)
63   AM_RANGE(0x9800, 0x9dff) AM_RAM
64   AM_RANGE(0x9e00, 0x9fff) AM_RAM AM_BASE(&spriteram) AM_SIZE(&spriteram_size)
65   AM_RANGE(0xa001, 0xa001) AM_WRITENOP   // ? Interrupt related
66   AM_RANGE(0xa004, 0xa004) AM_WRITE(clshroad_flipscreen_w)
67   AM_RANGE(0xa100, 0xa107) AM_READ(clshroad_input_r)
68   AM_RANGE(0xa800, 0xafff) AM_RAM_WRITE(clshroad_vram_1_w) AM_BASE(&clshroad_vram_1)   // Layer 1
69   AM_RANGE(0xb000, 0xb003) AM_WRITEONLY AM_BASE(&clshroad_vregs)   // Scroll
70   AM_RANGE(0xc000, 0xc7ff) AM_RAM_WRITE(clshroad_vram_0_w) AM_BASE(&clshroad_vram_0)   // Layer 0
7571ADDRESS_MAP_END
7672
77static ADDRESS_MAP_START( clshroad_writemem, ADDRESS_SPACE_PROGRAM, 8 )
78   AM_RANGE(0x0000, 0x7fff) AM_WRITE(SMH_ROM                           )   // ROM
79   AM_RANGE(0x8000, 0x95ff) AM_WRITE(SMH_RAM                           )   // Work   RAM
80   AM_RANGE(0x9600, 0x97ff) AM_WRITE(clshroad_sharedram_w) AM_BASE(&clshroad_sharedram   )   // Shared RAM
81   AM_RANGE(0x9800, 0x9dff) AM_WRITE(SMH_RAM                           )   // Work   RAM
82   AM_RANGE(0x9e00, 0x9fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram) AM_SIZE(&spriteram_size      )   // Sprite RAM
83   AM_RANGE(0xa001, 0xa001) AM_WRITE(SMH_NOP                           )   // ? Interrupt related
84   AM_RANGE(0xa004, 0xa004) AM_WRITE(clshroad_flipscreen_w                  )   // Flip Screen
85   AM_RANGE(0xa800, 0xafff) AM_WRITE(clshroad_vram_1_w) AM_BASE(&clshroad_vram_1      )   // Layer 1
86   AM_RANGE(0xb000, 0xb003) AM_WRITE(SMH_RAM) AM_BASE(&clshroad_vregs               )   // Scroll
87   AM_RANGE(0xc000, 0xc7ff) AM_WRITE(clshroad_vram_0_w) AM_BASE(&clshroad_vram_0      )   // Layers 0
88ADDRESS_MAP_END
89
90static ADDRESS_MAP_START( clshroad_sound_readmem, ADDRESS_SPACE_PROGRAM, 8 )
91   AM_RANGE(0x0000, 0x1fff) AM_READ(SMH_ROM            )   // ROM
92   AM_RANGE(0x9600, 0x97ff) AM_READ(clshroad_sharedram_r   )   // Shared RAM
93ADDRESS_MAP_END
94
95static ADDRESS_MAP_START( clshroad_sound_writemem, ADDRESS_SPACE_PROGRAM, 8 )
96   AM_RANGE(0x0000, 0x1fff) AM_WRITE(SMH_ROM            )   // ROM
73static ADDRESS_MAP_START( clshroad_sound_map, ADDRESS_SPACE_PROGRAM, 8 )
74   AM_RANGE(0x0000, 0x1fff) AM_ROM
9775   AM_RANGE(0x4000, 0x7fff) AM_WRITE(wiping_sound_w) AM_BASE(&wiping_soundregs)
98   AM_RANGE(0x9600, 0x97ff) AM_WRITE(clshroad_sharedram_w   )   // Shared RAM
99   AM_RANGE(0xa003, 0xa003) AM_WRITE(SMH_NOP            )   // ? Interrupt related
76   AM_RANGE(0x9600, 0x97ff) AM_RAM AM_SHARE(1)
77   AM_RANGE(0xa003, 0xa003) AM_WRITENOP   // ? Interrupt related
10078ADDRESS_MAP_END
10179
10280
r2762r2763
282260
283261static GFXDECODE_START( firebatl )
284262   GFXDECODE_ENTRY( REGION_GFX1, 0, layout_16x16x4,   0, 16 ) // [0] Sprites
285   GFXDECODE_ENTRY( REGION_GFX2, 0, layout_16x16x4,    16,  1 ) // [1] Layer 0
263   GFXDECODE_ENTRY( REGION_GFX2, 0, layout_16x16x4, 16,  1 ) // [1] Layer 0
286264   GFXDECODE_ENTRY( REGION_GFX3, 0, layout_8x8x2,   512, 64 ) // [2] Layer 1
287265GFXDECODE_END
288266
289267static GFXDECODE_START( clshroad )
290   GFXDECODE_ENTRY( REGION_GFX1, 0, layout_16x16x4, 0, 16 ) // [0] Sprites
268   GFXDECODE_ENTRY( REGION_GFX1, 0, layout_16x16x4,    0, 16 ) // [0] Sprites
291269   GFXDECODE_ENTRY( REGION_GFX2, 0, layout_16x16x4, 0x90,  1 ) // [1] Layer 0
292   GFXDECODE_ENTRY( REGION_GFX3, 0, layout_8x8x4,   0, 16 ) // [2] Layer 1
270   GFXDECODE_ENTRY( REGION_GFX3, 0, layout_8x8x4,      0, 16 ) // [2] Layer 1
293271GFXDECODE_END
294272
295273
r2762r2763
305283
306284   /* basic machine hardware */
307285   MDRV_CPU_ADD(Z80, 3000000)   /* ? */
308   MDRV_CPU_PROGRAM_MAP(clshroad_readmem,clshroad_writemem)
286   MDRV_CPU_PROGRAM_MAP(clshroad_map,0)
309287   MDRV_CPU_VBLANK_INT("main", irq0_line_hold)   /* IRQ, no NMI */
310288
311289   MDRV_CPU_ADD(Z80, 3000000)   /* ? */
312290   /* audio CPU */
313   MDRV_CPU_PROGRAM_MAP(clshroad_sound_readmem,clshroad_sound_writemem)
291   MDRV_CPU_PROGRAM_MAP(clshroad_sound_map,0)
314292   MDRV_CPU_VBLANK_INT("main", irq0_line_hold)   /* IRQ, no NMI */
315293
316294   MDRV_MACHINE_RESET(clshroad)
r2762r2763
341319static MACHINE_DRIVER_START( clshroad )
342320
343321   /* basic machine hardware */
344   MDRV_CPU_ADD(Z80, 18432000/6)   /* ? */
345   MDRV_CPU_PROGRAM_MAP(clshroad_readmem,clshroad_writemem)
322   MDRV_CPU_ADD(Z80, 18432000/4)   /* ? real speed unknown. 3MHz is too low and causes problems */
323   MDRV_CPU_PROGRAM_MAP(clshroad_map,0)
346324   MDRV_CPU_VBLANK_INT("main", irq0_line_hold)   /* IRQ, no NMI */
347325
348326   MDRV_CPU_ADD(Z80, 18432000/6)   /* ? */
349327   /* audio CPU */
350   MDRV_CPU_PROGRAM_MAP(clshroad_sound_readmem,clshroad_sound_writemem)
328   MDRV_CPU_PROGRAM_MAP(clshroad_sound_map,0)
351329   MDRV_CPU_VBLANK_INT("main", irq0_line_hold)   /* IRQ, no NMI */
352330
353331   MDRV_MACHINE_RESET(clshroad)
src/mame/drivers/pacman.c
r2762r2763
19741974   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY PORT_COCKTAIL
19751975   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY PORT_COCKTAIL
19761976   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
1977   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START1 )
1978   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 )
1979   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START2 )
1980   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON2 )
1977   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 ) // and start1
1978   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON2 ) // and start2
19811979   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Cabinet ) )
19821980   PORT_DIPSETTING(    0x80, DEF_STR( Upright ) )
19831981   PORT_DIPSETTING(    0x00, DEF_STR( Cocktail ) )
r2762r2763
29402938   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT )   PORT_4WAY PORT_COCKTAIL
29412939   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT )   PORT_4WAY PORT_COCKTAIL
29422940   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN )   PORT_4WAY PORT_COCKTAIL
2943   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
2941   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
29442942   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START1 ) PORT_NAME( "Start" )
29452943   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START2 ) PORT_NAME( "Select" )
2946   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
2944   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
29472945
29482946   PORT_START_TAG("DSW 1")
29492947   PORT_DIPNAME( 0x03, 0x03, "Display" )
src/mame/drivers/dcheese.c
r2762r2763
88        * Double Cheese
99        * Lotto Fun 2
1010        * Fred Flintstones' Memory Match
11        * ChuckECheese's Match Game
1112
1213    Known bugs:
1314        * Test/tilt buttons seem to be swapped compared to test mode
r2762r2763
2021      allow the wheel to start spinning.  This is most likely to stop
2122      people from rigging the game.
2223
23    [fredmem]
24    [fredmem / cecmatch]
2425    * Controls are set up as a 3 x 3 matrix of buttons that match the 9
2526      positions on the screen.
2627
r2762r2763
126127 *
127128 *************************************/
128129
129static READ16_HANDLER( port_0_r )
130static CUSTOM_INPUT( sound_latch_state_r )
130131{
131   return (input_port_read_indexed(machine, 0) & 0xff7f) | (EEPROM_read_bit() << 7);
132   return soundlatch_full;
132133}
133134
134135
135static READ16_HANDLER( port_2_r )
136{
137   return (input_port_read_indexed(machine, 2) & 0xff1f) | (!soundlatch_full << 7) | (ticket_dispenser_r(machine, 0) >> 2);
138}
139
140
141136static WRITE16_HANDLER( eeprom_control_w )
142137{
143138   /* toggles bit $0100 very frequently while waiting for things */
144139   /* bits $0080-$0010 are probably lamps */
145140   if (ACCESSING_BITS_0_7)
146141   {
147      EEPROM_set_cs_line(~data & 8);
148      EEPROM_write_bit(data & 2);
149      EEPROM_set_clock_line(data & 4);
142      eeprom_set_cs_line(~data & 8);
143      eeprom_write_bit(data & 2);
144      eeprom_set_clock_line(data & 4);
150145      ticket_dispenser_w(machine, 0, (data & 1) << 7);
151146   }
152147}
r2762r2763
222217   ADDRESS_MAP_UNMAP_HIGH
223218   AM_RANGE(0x000000, 0x03ffff) AM_ROM
224219   AM_RANGE(0x100000, 0x10ffff) AM_RAM
225   AM_RANGE(0x200000, 0x200001) AM_READWRITE(port_0_r, watchdog_reset16_w)
220   AM_RANGE(0x200000, 0x200001) AM_READWRITE(input_port_0_word_r, watchdog_reset16_w)
226221   AM_RANGE(0x220000, 0x220001) AM_READWRITE(input_port_1_word_r, madmax_blitter_color_w)
227   AM_RANGE(0x240000, 0x240001) AM_READWRITE(port_2_r, eeprom_control_w)
222   AM_RANGE(0x240000, 0x240001) AM_READWRITE(input_port_2_word_r, eeprom_control_w)
228223   AM_RANGE(0x260000, 0x26001f) AM_WRITE(madmax_blitter_xparam_w)
229224   AM_RANGE(0x280000, 0x28001f) AM_WRITE(madmax_blitter_yparam_w)
230225   AM_RANGE(0x2a0000, 0x2a003f) AM_READWRITE(madmax_blitter_vidparam_r, madmax_blitter_vidparam_w)
r2762r2763
265260   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_SERVICE )      /* says tilt */
266261   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_TILT )         /* says test */
267262   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_SERVICE1 )
268   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_SPECIAL )      /* EEPROM data */
263   PORT_BIT( 0x0080, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(eeprom_bit_r, NULL)
269264   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_UNUSED )
270265   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON3 )      /* bump left */
271266   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON4 )      /* bump right */
r2762r2763
279274
280275   PORT_START   /* 240000 */
281276   PORT_BIT( 0x001f, IP_ACTIVE_LOW, IPT_UNKNOWN )      /* low 5 bits read as a unit */
282   PORT_BIT( 0x0020, IP_ACTIVE_HIGH, IPT_SPECIAL )      /* ticket status */
277   PORT_BIT( 0x0020, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(ticket_dispenser_0_port_r, NULL)
283278   PORT_BIT( 0x0040, IP_ACTIVE_HIGH, IPT_SPECIAL )      /* sound->main buffer status (0=empty) */
284   PORT_BIT( 0x0080, IP_ACTIVE_HIGH, IPT_SPECIAL )      /* main->sound buffer status (1=empty) */
279   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_SPECIAL ) PORT_CUSTOM(sound_latch_state_r, NULL)
285280   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_UNUSED )
286281   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_VOLUME_DOWN )
287282   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_UNUSED )
r2762r2763
312307   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_SERVICE )
313308   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_TILT )
314309   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_SERVICE1 )
315   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_SPECIAL )      /* EEPROM data */
310   PORT_BIT( 0x0080, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(eeprom_bit_r, NULL)
316311   PORT_BIT( 0x1f00, IP_ACTIVE_LOW, IPT_UNUSED )
317312   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON1 )      /* button */
318313   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON2 )      /* ticket */
r2762r2763
323318
324319   PORT_START   /* 240000 */
325320   PORT_BIT( 0x001f, IP_ACTIVE_LOW, IPT_UNKNOWN )      /* low 5 bits read as a unit */
326   PORT_BIT( 0x0020, IP_ACTIVE_HIGH, IPT_SPECIAL )      /* ticket status */
321   PORT_BIT( 0x0020, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(ticket_dispenser_0_port_r, NULL)
327322   PORT_BIT( 0x0040, IP_ACTIVE_HIGH, IPT_SPECIAL )      /* sound->main buffer status (0=empty) */
328   PORT_BIT( 0x0080, IP_ACTIVE_HIGH, IPT_SPECIAL )      /* main->sound buffer status (1=empty) */
323   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_SPECIAL ) PORT_CUSTOM(sound_latch_state_r, NULL)
329324   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_UNUSED )
330325   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_VOLUME_DOWN )
331326   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_UNUSED )
r2762r2763
355350   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_SERVICE )
356351   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_TILT )
357352   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_SERVICE1 )
358   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_SPECIAL )      /* EEPROM data */
353   PORT_BIT( 0x0080, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(eeprom_bit_r, NULL)
359354   PORT_BIT( 0x1f00, IP_ACTIVE_LOW, IPT_UNUSED )
360355   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_CODE(KEYCODE_5_PAD)
361356   PORT_BIT( 0xc000, IP_ACTIVE_LOW, IPT_UNUSED )
r2762r2763
365360
366361   PORT_START   /* 240000 */
367362   PORT_BIT( 0x001f, IP_ACTIVE_LOW, IPT_UNKNOWN )      /* low 5 bits read as a unit */
368   PORT_BIT( 0x0020, IP_ACTIVE_HIGH, IPT_SPECIAL )      /* ticket status */
363   PORT_BIT( 0x0020, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(ticket_dispenser_0_port_r, NULL)
369364   PORT_BIT( 0x0040, IP_ACTIVE_HIGH, IPT_SPECIAL )      /* sound->main buffer status (0=empty) */
370   PORT_BIT( 0x0080, IP_ACTIVE_HIGH, IPT_SPECIAL )      /* main->sound buffer status (1=empty) */
365   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_SPECIAL ) PORT_CUSTOM(sound_latch_state_r, NULL)
371366   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_UNUSED )
372367   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_VOLUME_DOWN )
373368   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_UNUSED )
r2762r2763
590585ROM_END
591586
592587
588ROM_START( fredmeus )
589   ROM_REGION( 0x40000, REGION_CPU1, 0 ) /* 68k */
590   ROM_LOAD16_BYTE( "u104.us.hiscore", 0x00000, 0x20000, CRC(4460c690) SHA1(08fec2704baac4b83add8f1d5936f15336a67599) ) /* Program 0 - V2.0 at U104 */
591   ROM_LOAD16_BYTE( "u103.us.hiscore", 0x00001, 0x20000, CRC(ff5bfdc3) SHA1(c38b856d6a74df68bfc6fb15b521180f78742d45) ) /* Program 1 - V2.0 at U103 */
593592
593   ROM_REGION( 0x10000, REGION_CPU2, 0 ) /* M6809 */
594   ROM_LOAD( "prog.102", 0x00000, 0x10000, CRC(b1526a1a) SHA1(456c44a0a908b3cd054b7c6741d7a1033c9b12fb) ) /* Sound Program 6809 code at U102 */
595
596   ROM_REGION( 0x200000, REGION_GFX1, 0 )
597   ROM_LOAD( "art-rom.123", 0x000000, 0x80000, CRC(48133505) SHA1(60f69b053e67256928db57e0a5335bbd5a72ddfc) ) /* Graphics / Art at U123 */
598   ROM_LOAD( "art-rom.125", 0x080000, 0x80000, CRC(8181e154) SHA1(4d16b84ad52d8e3d3bcad3fdf5f8da23df198d46) ) /* Graphics / Art at U125 */
599   ROM_LOAD( "art-rom.127", 0x100000, 0x80000, CRC(93095f3b) SHA1(de746829e04bf153024e94e6ef0ceffb1eae2b14) ) /* Graphics / Art at U127 */
600   ROM_LOAD( "art-rom.129", 0x180000, 0x80000, CRC(d5715a02) SHA1(b7d9d29f2fc5d74adff1fefce312e6472c0f7565) ) /* Graphics / Art at U129 */
601
602   ROM_REGION( 0x400000, REGION_SOUND1, 0 )
603   ROM_LOAD( "arom0", 0x000000, 0x80000, CRC(3b85ea34) SHA1(0a68e7df20a2c36e230c7935415dd5068c338669) )
604   ROM_RELOAD(        0x080000, 0x80000 )
605   ROM_LOAD( "arom1", 0x100000, 0x80000, CRC(405df3d4) SHA1(190b928789a879408beadd1647136bd85b018c63) )
606   ROM_RELOAD(        0x180000, 0x80000 )
607   ROM_LOAD( "arom2", 0x200000, 0x80000, CRC(48ecd5c9) SHA1(6aad371db7b658454c5feed548ffd19b81a8fcf4) )
608   ROM_RELOAD(        0x280000, 0x80000 )
609   ROM_LOAD( "arom3", 0x300000, 0x80000, CRC(411900b0) SHA1(ddc5b387c89baab0fd5c654f3768c6e27972c06a) )
610   ROM_RELOAD(        0x380000, 0x80000 )
611
612   ROM_REGION16_LE( 0x20000, REGION_USER1, 0 )
613   ROM_LOAD16_BYTE( "0.144", 0x00000, 0x10000, CRC(793c4bda) SHA1(5a8a2981b48922f4d9e617a9bf9ef6a47ab702b7) ) /* Pallette - 0 at U144 */
614   ROM_LOAD16_BYTE( "1.145", 0x00001, 0x10000, CRC(fe2c3521) SHA1(896e53427c7831620ca565be9c0b76aabc36b9f4) ) /* Pallette - 1 at U145 */
615
616   ROM_REGION( 0x100, REGION_USER2, 0 )
617   ROM_LOAD16_BYTE( "93c46.u158", 0x00000, 0x0080, CRC(a40a7b87) SHA1(3632b7538b3bf41ee0cbe7541a0f5951f70b4a9b) ) /* EEPROM data at U158 */
618ROM_END
619
620ROM_START( fredmeuk )
621   ROM_REGION( 0x40000, REGION_CPU1, 0 ) /* 68k */
622   ROM_LOAD16_BYTE( "u104.uk", 0x00000, 0x20000, CRC(e810daab) SHA1(99be21eb5df49fd8b665935c774798be270e0f27) ) /* Program 0 - V2.0 at U104 */
623   ROM_LOAD16_BYTE( "u103.uk", 0x00001, 0x20000, CRC(0f2e65fb) SHA1(533a45d2de0ee3c306197d2559355c3193f9ac6b) ) /* Program 1 - V2.0 at U103 */
624
625   ROM_REGION( 0x10000, REGION_CPU2, 0 ) /* M6809 */
626   ROM_LOAD( "prog.102", 0x00000, 0x10000, CRC(b1526a1a) SHA1(456c44a0a908b3cd054b7c6741d7a1033c9b12fb) ) /* Sound Program 6809 code at U102 */
627
628   ROM_REGION( 0x200000, REGION_GFX1, 0 )
629   ROM_LOAD( "art-rom.123", 0x000000, 0x80000, CRC(48133505) SHA1(60f69b053e67256928db57e0a5335bbd5a72ddfc) ) /* Graphics / Art at U123 */
630   ROM_LOAD( "art-rom.125", 0x080000, 0x80000, CRC(8181e154) SHA1(4d16b84ad52d8e3d3bcad3fdf5f8da23df198d46) ) /* Graphics / Art at U125 */
631   ROM_LOAD( "art-rom.127", 0x100000, 0x80000, CRC(93095f3b) SHA1(de746829e04bf153024e94e6ef0ceffb1eae2b14) ) /* Graphics / Art at U127 */
632   ROM_LOAD( "art-rom.129", 0x180000, 0x80000, CRC(d5715a02) SHA1(b7d9d29f2fc5d74adff1fefce312e6472c0f7565) ) /* Graphics / Art at U129 */
633
634   ROM_REGION( 0x400000, REGION_SOUND1, 0 )
635   ROM_LOAD( "arom0", 0x000000, 0x80000, CRC(3b85ea34) SHA1(0a68e7df20a2c36e230c7935415dd5068c338669) )
636   ROM_RELOAD(        0x080000, 0x80000 )
637   ROM_LOAD( "arom1", 0x100000, 0x80000, CRC(405df3d4) SHA1(190b928789a879408beadd1647136bd85b018c63) )
638   ROM_RELOAD(        0x180000, 0x80000 )
639   ROM_LOAD( "arom2", 0x200000, 0x80000, CRC(48ecd5c9) SHA1(6aad371db7b658454c5feed548ffd19b81a8fcf4) )
640   ROM_RELOAD(        0x280000, 0x80000 )
641   ROM_LOAD( "arom3", 0x300000, 0x80000, CRC(411900b0) SHA1(ddc5b387c89baab0fd5c654f3768c6e27972c06a) )
642   ROM_RELOAD(        0x380000, 0x80000 )
643
644   ROM_REGION16_LE( 0x20000, REGION_USER1, 0 )
645   ROM_LOAD16_BYTE( "0.144", 0x00000, 0x10000, CRC(793c4bda) SHA1(5a8a2981b48922f4d9e617a9bf9ef6a47ab702b7) ) /* Pallette - 0 at U144 */
646   ROM_LOAD16_BYTE( "1.145", 0x00001, 0x10000, CRC(fe2c3521) SHA1(896e53427c7831620ca565be9c0b76aabc36b9f4) ) /* Pallette - 1 at U145 */
647
648   ROM_REGION( 0x100, REGION_USER2, 0 )
649   ROM_LOAD16_BYTE( "93c46.u158", 0x00000, 0x0080, CRC(a40a7b87) SHA1(3632b7538b3bf41ee0cbe7541a0f5951f70b4a9b) ) /* EEPROM data at U158 */
650ROM_END
651
652/* Japan version, has a High Score table instead of tickets */
653ROM_START( fredmemj )
654   ROM_REGION( 0x40000, REGION_CPU1, 0 ) /* 68k */
655   ROM_LOAD16_BYTE( "prog0_japan.104", 0x00000, 0x20000, CRC(4f5e947e) SHA1(14c19832f98a14293a66e64d2d86e8c5cc8a9324) ) /* Program 0 - V2.0 at U104 */
656   ROM_LOAD16_BYTE( "prog1_japan.103", 0x00001, 0x20000, CRC(2df6affb) SHA1(d1d28090a857cb0b0464986c446b189e7911d3d3) ) /* Program 1 - V2.0 at U103 */
657
658   ROM_REGION( 0x10000, REGION_CPU2, 0 ) /* M6809 */
659   ROM_LOAD( "prog.102", 0x00000, 0x10000, CRC(b1526a1a) SHA1(456c44a0a908b3cd054b7c6741d7a1033c9b12fb) ) /* Sound Program 6809 code at U102 */
660
661   ROM_REGION( 0x200000, REGION_GFX1, 0 )
662   ROM_LOAD( "art-rom.123", 0x000000, 0x80000, CRC(48133505) SHA1(60f69b053e67256928db57e0a5335bbd5a72ddfc) ) /* Graphics / Art at U123 */
663   ROM_LOAD( "art-rom_japan.125", 0x080000, 0x80000, CRC(7bfd9b92) SHA1(306f276cf4574587fb4421c2b214522ee2b53774) ) /* Graphics / Art at U125 */
664   ROM_LOAD( "art-rom.127", 0x100000, 0x80000, CRC(93095f3b) SHA1(de746829e04bf153024e94e6ef0ceffb1eae2b14) ) /* Graphics / Art at U127 */
665   ROM_LOAD( "art-rom_japan.129", 0x180000, 0x80000, CRC(aaaddc7b) SHA1(27e4d31a904a451249affda2226c6556e24bfaf6) ) /* Graphics / Art at U129 */
666
667   ROM_REGION( 0x400000, REGION_SOUND1, 0 )
668   ROM_LOAD( "arom0", 0x000000, 0x80000, CRC(3b85ea34) SHA1(0a68e7df20a2c36e230c7935415dd5068c338669) )
669   ROM_RELOAD(        0x080000, 0x80000 )
670   ROM_LOAD( "arom1", 0x100000, 0x80000, CRC(405df3d4) SHA1(190b928789a879408beadd1647136bd85b018c63) )
671   ROM_RELOAD(        0x180000, 0x80000 )
672   ROM_LOAD( "arom2", 0x200000, 0x80000, CRC(48ecd5c9) SHA1(6aad371db7b658454c5feed548ffd19b81a8fcf4) )
673   ROM_RELOAD(        0x280000, 0x80000 )
674   ROM_LOAD( "arom3", 0x300000, 0x80000, CRC(411900b0) SHA1(ddc5b387c89baab0fd5c654f3768c6e27972c06a) )
675   ROM_RELOAD(        0x380000, 0x80000 )
676
677   ROM_REGION16_LE( 0x20000, REGION_USER1, 0 )
678   ROM_LOAD16_BYTE( "0.144", 0x00000, 0x10000, CRC(793c4bda) SHA1(5a8a2981b48922f4d9e617a9bf9ef6a47ab702b7) ) /* Pallette - 0 at U144 */
679   ROM_LOAD16_BYTE( "1.145", 0x00001, 0x10000, CRC(fe2c3521) SHA1(896e53427c7831620ca565be9c0b76aabc36b9f4) ) /* Pallette - 1 at U145 */
680
681   ROM_REGION( 0x100, REGION_USER2, 0 )
682   ROM_LOAD16_BYTE( "93c46.u158", 0x00000, 0x0080, CRC(a40a7b87) SHA1(3632b7538b3bf41ee0cbe7541a0f5951f70b4a9b) ) /* EEPROM data at U158 */
683ROM_END
684
685ROM_START( fredmemc )
686   ROM_REGION( 0x40000, REGION_CPU1, 0 ) /* 68k */
687   ROM_LOAD16_BYTE( "u104.mandarin", 0x00000, 0x20000, CRC(f46e4af6) SHA1(3bc5a7e7db7bcf86e4e8ab5df0c8bff89398d8c5) ) /* Program 0 - V2.0 at U104 */
688   ROM_LOAD16_BYTE( "u103.mandarin", 0x00001, 0x20000, CRC(160a7f47) SHA1(14704d1618320b2155c6387d03ac006b3b64fc58) ) /* Program 1 - V2.0 at U103 */
689
690   ROM_REGION( 0x10000, REGION_CPU2, 0 ) /* M6809 */
691   ROM_LOAD( "prog.102", 0x00000, 0x10000, CRC(b1526a1a) SHA1(456c44a0a908b3cd054b7c6741d7a1033c9b12fb) ) /* Sound Program 6809 code at U102 */
692
693   ROM_REGION( 0x200000, REGION_GFX1, 0 )
694   ROM_LOAD( "art-rom.123", 0x000000, 0x80000, CRC(48133505) SHA1(60f69b053e67256928db57e0a5335bbd5a72ddfc) ) /* Graphics / Art at U123 */
695   ROM_LOAD( "art-rom.125.mandarin", 0x080000, 0x80000, CRC(780c06fa) SHA1(34aa420fb8a628b8cb92b0975e602d8c676c608a) ) /* Graphics / Art at U125 */
696   ROM_LOAD( "art-rom.127", 0x100000, 0x80000, CRC(93095f3b) SHA1(de746829e04bf153024e94e6ef0ceffb1eae2b14) ) /* Graphics / Art at U127 */
697   ROM_LOAD( "art-rom.129.mandarin", 0x180000, 0x80000, CRC(31444b3f) SHA1(dd3930fd784e685a05b7fc8039e6542710861ae5) ) /* Graphics / Art at U129 */
698
699   ROM_REGION( 0x400000, REGION_SOUND1, 0 )
700   ROM_LOAD( "arom0", 0x000000, 0x80000, CRC(3b85ea34) SHA1(0a68e7df20a2c36e230c7935415dd5068c338669) )
701   ROM_RELOAD(        0x080000, 0x80000 )
702   ROM_LOAD( "arom1", 0x100000, 0x80000, CRC(405df3d4) SHA1(190b928789a879408beadd1647136bd85b018c63) )
703   ROM_RELOAD(        0x180000, 0x80000 )
704   ROM_LOAD( "arom2", 0x200000, 0x80000, CRC(48ecd5c9) SHA1(6aad371db7b658454c5feed548ffd19b81a8fcf4) )
705   ROM_RELOAD(        0x280000, 0x80000 )
706   ROM_LOAD( "arom3", 0x300000, 0x80000, CRC(411900b0) SHA1(ddc5b387c89baab0fd5c654f3768c6e27972c06a) )
707   ROM_RELOAD(        0x380000, 0x80000 )
708
709   ROM_REGION16_LE( 0x20000, REGION_USER1, 0 )
710   ROM_LOAD16_BYTE( "0.144", 0x00000, 0x10000, CRC(793c4bda) SHA1(5a8a2981b48922f4d9e617a9bf9ef6a47ab702b7) ) /* Pallette - 0 at U144 */
711   ROM_LOAD16_BYTE( "1.145", 0x00001, 0x10000, CRC(fe2c3521) SHA1(896e53427c7831620ca565be9c0b76aabc36b9f4) ) /* Pallette - 1 at U145 */
712
713   ROM_REGION( 0x100, REGION_USER2, 0 )
714   ROM_LOAD16_BYTE( "93c46.u158", 0x00000, 0x0080, CRC(a40a7b87) SHA1(3632b7538b3bf41ee0cbe7541a0f5951f70b4a9b) ) /* EEPROM data at U158 */
715ROM_END
716
717ROM_START( fredmesp )
718   ROM_REGION( 0x40000, REGION_CPU1, 0 ) /* 68k */
719   ROM_LOAD16_BYTE( "u104.spanish", 0x00000, 0x20000, CRC(ba150de6) SHA1(57aedc2c96309d6b5b67090e24e1e672404d34bf) ) /* Program 0 - V2.0 at U104 */
720   ROM_LOAD16_BYTE( "u103.spanish", 0x00001, 0x20000, CRC(4af72eb0) SHA1(c0addfc2900fb41c24ecf9b052ef1854206a4cba) ) /* Program 1 - V2.0 at U103 */
721
722   ROM_REGION( 0x10000, REGION_CPU2, 0 ) /* M6809 */
723   ROM_LOAD( "prog.102", 0x00000, 0x10000, CRC(b1526a1a) SHA1(456c44a0a908b3cd054b7c6741d7a1033c9b12fb) ) /* Sound Program 6809 code at U102 */
724
725   ROM_REGION( 0x200000, REGION_GFX1, 0 )
726   ROM_LOAD( "art-rom.123", 0x000000, 0x80000, CRC(48133505) SHA1(60f69b053e67256928db57e0a5335bbd5a72ddfc) ) /* Graphics / Art at U123 */
727   ROM_LOAD( "art-rom.125.spanish", 0x080000, 0x80000, CRC(3ee88ec8) SHA1(24f3d548fe47b92d68904e1cd6233f75b109772c) ) /* Graphics / Art at U125 */
728   ROM_LOAD( "art-rom.127", 0x100000, 0x80000, CRC(93095f3b) SHA1(de746829e04bf153024e94e6ef0ceffb1eae2b14) ) /* Graphics / Art at U127 */
729   ROM_LOAD( "art-rom.129.spanish", 0x180000, 0x80000, CRC(8f0fa246) SHA1(10eef16f41c82224d369fd6b7c2fa9212e22fb42) ) /* Graphics / Art at U129 */
730
731   ROM_REGION( 0x400000, REGION_SOUND1, 0 )
732   ROM_LOAD( "arom0", 0x000000, 0x80000, CRC(3b85ea34) SHA1(0a68e7df20a2c36e230c7935415dd5068c338669) )
733   ROM_RELOAD(        0x080000, 0x80000 )
734   ROM_LOAD( "arom1", 0x100000, 0x80000, CRC(405df3d4) SHA1(190b928789a879408beadd1647136bd85b018c63) )
735   ROM_RELOAD(        0x180000, 0x80000 )
736   ROM_LOAD( "arom2", 0x200000, 0x80000, CRC(48ecd5c9) SHA1(6aad371db7b658454c5feed548ffd19b81a8fcf4) )
737   ROM_RELOAD(        0x280000, 0x80000 )
738   ROM_LOAD( "arom3", 0x300000, 0x80000, CRC(411900b0) SHA1(ddc5b387c89baab0fd5c654f3768c6e27972c06a) )
739   ROM_RELOAD(        0x380000, 0x80000 )
740
741   ROM_REGION16_LE( 0x20000, REGION_USER1, 0 )
742   ROM_LOAD16_BYTE( "0.144", 0x00000, 0x10000, CRC(793c4bda) SHA1(5a8a2981b48922f4d9e617a9bf9ef6a47ab702b7) ) /* Pallette - 0 at U144 */
743   ROM_LOAD16_BYTE( "1.145", 0x00001, 0x10000, CRC(fe2c3521) SHA1(896e53427c7831620ca565be9c0b76aabc36b9f4) ) /* Pallette - 1 at U145 */
744
745   ROM_REGION( 0x100, REGION_USER2, 0 )
746   ROM_LOAD16_BYTE( "93c46.u158", 0x00000, 0x0080, CRC(a40a7b87) SHA1(3632b7538b3bf41ee0cbe7541a0f5951f70b4a9b) ) /* EEPROM data at U158 */
747ROM_END
748
749
750ROM_START( cecmatch )
751   ROM_REGION( 0x40000, REGION_CPU1, 0 ) /* 68k */
752   ROM_LOAD16_BYTE( "prog0.104", 0x00000, 0x20000, CRC(b13585e2) SHA1(dbf6db79e319157b5ac540471348682b45508c1f) ) /* Program 0 - V2.0 at U104 */
753   ROM_LOAD16_BYTE( "prog1.103", 0x00001, 0x20000, CRC(5baf4f50) SHA1(e7529a4cffa292a491093a74f9ea49f59e41617f) ) /* Program 1 - V2.0 at U103 */
754
755   ROM_REGION( 0x10000, REGION_CPU2, 0 ) /* M6809 */
756   ROM_LOAD( "prog.102", 0x00000, 0x8000, CRC(d452ccf4) SHA1(7de9a4f39bf0ba448fe4ebeb459e98a1910a66be) ) /* Sound Program 6809 code at U102 */
757   ROM_RELOAD(0x8000,0x8000)
758
759   ROM_REGION( 0x100000, REGION_GFX1, ROMREGION_ERASEFF )
760   ROM_LOAD( "art-rom.123", 0x000000, 0x40000, CRC(1bab1a52) SHA1(f713ba1bc755c41d38d9846444d753c9c7fb1f9d) ) /* Graphics / Art at U123 */
761   ROM_LOAD( "art-rom.127", 0x040000, 0x40000, CRC(dc9be2ca) SHA1(d5059a49a3aad309e242c9c4791d10aa5ecd5d1a) ) /* Graphics / Art at U127 */
762   ROM_LOAD( "art-rom.125", 0x080000, 0x40000, CRC(7abe18d9) SHA1(c5a582ded7c1b0a02847b342111c64ac0ccb70c2) ) /* Graphics / Art at U125 */
763
764   ROM_REGION( 0x400000, REGION_SOUND1, 0 )
765   ROM_LOAD( "arom0", 0x000000, 0x40000, CRC(82129830) SHA1(2fa3a32ac4f81dd9c2ab11f34257df4074447f3a))
766   ROM_RELOAD(        0x040000, 0x40000 )
767   ROM_RELOAD(        0x080000, 0x40000 )
768   ROM_RELOAD(        0x0c0000, 0x40000 )
769   ROM_LOAD( "arom1", 0x100000, 0x40000, CRC(0d07ac31) SHA1(f1721c34d076a1695f01b90e99428736471cae49) )
770   ROM_RELOAD(        0x140000, 0x40000 )
771   ROM_RELOAD(        0x180000, 0x40000 )
772   ROM_RELOAD(        0x1c0000, 0x40000 )
773   ROM_LOAD( "arom2", 0x200000, 0x40000, CRC(625f3bf5) SHA1(e6a2ca8e105327d8f6a8245483dab29fe1b513fa) )
774   ROM_RELOAD(        0x240000, 0x40000 )
775   ROM_RELOAD(        0x280000, 0x40000 )
776   ROM_RELOAD(        0x2c0000, 0x40000 )
777   ROM_LOAD( "arom3", 0x300000, 0x40000, CRC(f3c9d554) SHA1(55daf85cec511010832d1d65bc734ec0c19b7c3f) )
778   ROM_RELOAD(        0x340000, 0x40000 )
779   ROM_RELOAD(        0x380000, 0x40000 )
780   ROM_RELOAD(        0x3c0000, 0x40000 )
781
782   ROM_REGION16_LE( 0x20000, REGION_USER1, 0 )
783   ROM_LOAD16_BYTE( "0.144", 0x00000, 0x10000, CRC(69b3cc85) SHA1(05f7204ac961274b5d2f42cc6c0d06e5fa146aef)) /* Pallette - 0 at U144 */
784   ROM_LOAD16_BYTE( "1.145", 0x00001, 0x10000, CRC(e64a8511) SHA1(0e3a1fe936c841b8acfb150bf63e564b1dec2363) ) /* Pallette - 1 at U145 */
785ROM_END
786
787
788
594789/*************************************
595790 *
596791 *  Driver configuration
r2762r2763
610805 *
611806 *************************************/
612807
613GAME( 1993, dcheese, 0, dcheese, dcheese, dcheese, ROT90, "HAR", "Double Cheese", GAME_SUPPORTS_SAVE )
614GAME( 1993, lottof2, 0, dcheese, lottof2, dcheese, ROT0,  "HAR", "Lotto Fun 2", GAME_SUPPORTS_SAVE )
615GAME( 1994, fredmem, 0, fredmem, fredmem, dcheese, ROT0,  "Coastal Amusements", "Fred Flintstones' Memory Match", GAME_SUPPORTS_SAVE )
808GAME( 1993, dcheese,  0,       dcheese, dcheese, dcheese, ROT90, "HAR", "Double Cheese", GAME_SUPPORTS_SAVE )
809GAME( 1993, lottof2,  0,       dcheese, lottof2, dcheese, ROT0,  "HAR", "Lotto Fun 2", GAME_SUPPORTS_SAVE )
810GAME( 1993, cecmatch, 0,       fredmem, fredmem, dcheese, ROT0,  "Coastal Amusements", "ChuckECheese's Match Game", GAME_SUPPORTS_SAVE )
811GAME( 1994, fredmem,  0,       fredmem, fredmem, dcheese, ROT0,  "Coastal Amusements", "Fred Flintstones' Memory Match (World?, Ticket version, 3/17/95)", GAME_SUPPORTS_SAVE )
812GAME( 1994, fredmeus, fredmem, fredmem, fredmem, dcheese, ROT0,  "Coastal Amusements", "Fred Flintstones' Memory Match (US, High Score version, 3/10/95)", GAME_SUPPORTS_SAVE )
813GAME( 1994, fredmeuk, fredmem, fredmem, fredmem, dcheese, ROT0,  "Coastal Amusements", "Fred Flintstones' Memory Match (UK, 3/17/95)", GAME_SUPPORTS_SAVE )
814GAME( 1994, fredmemj, fredmem, fredmem, fredmem, dcheese, ROT0,  "Coastal Amusements", "Fred Flintstones' Memory Match (Japan, High Score version, 3/20/95)", GAME_SUPPORTS_SAVE )
815GAME( 1994, fredmemc, fredmem, fredmem, fredmem, dcheese, ROT0,  "Coastal Amusements", "Fred Flintstones' Memory Match (Mandarin Chinese, 3/17/95)", GAME_SUPPORTS_SAVE )
816GAME( 1994, fredmesp, fredmem, fredmem, fredmem, dcheese, ROT0,  "Coastal Amusements", "Fred Flintstones' Memory Match (Spanish, 3/17/95)", GAME_SUPPORTS_SAVE )
817
src/mame/drivers/konamim2.c
r2762r2763
1/*  Konami M2 Hardware
1/*
2Konami M2 Hardware
3Preliminary driver by Ville Linde
24
3    Preliminary driver by Ville Linde
45
5    Games on this hardware:
6    =======================
6Konami M2 Hardware Overview
7Konami, 1997-1998
78
8    Game                 | Konami ID
9    ---------------------------------
10    Evil Night           | GN810
11    Heat of Eleven '98   | GX703
12    Tobe! Polystars      | GX623
13    Battle Tryst         | G?636
9This hardware is 3DO-based with two IBM Power PC CPUs.
1410
15*/
11There were only 5 known games on this hardware. They include....
1612
17/*
18Tobe! PolyStars
19Konami, 1997
13Game                                                 Year    CD Codes     Konami Part#
14--------------------------------------------------------------------------------------
15Battle Tryst                                         1998    636JAC02
16Evil Night                                           1998    810UBA02
17Hell Night ((alt. Region title, same as Evil Night)  1998    810EAA02
18Heat Of Eleven '98                                   1998    703EAA02
19Polystars                                            1997    623JAA02     003894
20Total Vice                                           1997    639AAB01
2021
21This game runs on 3DO-based Konami M2 hardware.
2222
23PCB Layout
24----------
23PCB Layouts
24-----------
2525
2626Top Board
2727
r2762r2763
6767|       NJM5532D                    9.83MHz                |
6868|                                   19.66MHz               |
6969|J                |--------|   93C46.7K                    |-|
70|A                | 058232 |                623B01.8Q      | |
70|A                | 058232 |                BOOTROM.8Q     | |
7171|M                |--------|   |------|                    | |
7272|M       |------|              |003461|                    | |
7373|A       |056879|              |      |                    | |CN15
r2762r2763
7979|                                                          |
8080|----------------------------------------------------------|
8181Notes:
82      056879   - Konami custom IC, location 10E (QFP120)
83      058232   - Konami custom ceramic flat pack IC, DAC?
84      003461   - Konami custom IC, location 11K (QFP100)
85      CN16     - 4 pin connector for CD-DA in from CDROM
86      CN15     - Standard (PC-compatible) 40 pin IDE CDROM flat cable connector and 4 pin power plug connector,
87                 connected to Panasonic CR-583 8-speed CDROM drive.
88                 CDROM disc contains 1 data track & 24 audio tracks. Total Capacity: 581 MBytes
89                 Konami part number: 003894
90                 Software revision: 623JAA02
91      LA4705   - LA4705 Power Amplifier
92      623B01.8Q- 16MBit MASKROM. Location 8Q (DIP42)
93      93C46.7K - 128bytes x8bit Serial EEPROM. Location 7K (DIP8)
94      DSW      - 8 position dip switch
82      056879     - Konami custom IC, location 10E (QFP120)
83      058232     - Konami custom ceramic flat pack IC, DAC?
84      003461     - Konami custom IC, location 11K (QFP100)
85      CN16       - 4 pin connector for CD-DA in from CDROM
86      CN15       - Standard (PC-compatible) 40 pin IDE CDROM flat cable connector and 4 pin power plug connector,
87                   connected to Panasonic CR-583 8-speed CDROM drive.
88      LA4705     - LA4705 Power Amplifier
89      DSW        - 8 position dip switch
90      BOOTROM.8Q - 16MBit MASKROM. Location 8Q (DIP42)
91                   Battle Tryst       - 636A01.8Q
92                   Evil Night         -       .8Q
93                   Heat Of Eleven '98 -       .8Q
94                   Polystars          - 623B01.8Q
95                   Total Vice         -       .8Q
96      93C46.7K   - 128bytes x8bit Serial EEPROM. Location 7K (DIP8)
97                   NOTE! There is very mild protection to stop game-swapping. It is based on the information in the EEPROM
98                   being the same as the Time Keeper NVRAM.
99                   For example, in Evil Night, the first line of the NVRAM in hex is 474E38313000000019984541410002A601FEFE01
100                   Looking at it in ascii:  GN810.....EAA.......
101                   Hex 474E383130 = GN810
102                   1998 = the year of the game
103                   Hex 454141 = EAA (the version = europe english)
104                   The numbers after this appear to be unimportant (at least with regards to swapping games anyway).
105                   All the other data after the first line is used for high scores tables etc.
106                   The important part is that the data in the EEPROM should be the same as the NVRAM, but the EEPROM data
107                   is byte-swapped! If the two don't match, the check on 7K or the NVRAM will fail and the PCB will reboot
108                   forever.
95109
110Some lower boards have two connectors underneath for a protection sub-board or sound board. These are detailed below....
111
112GX636-PWB(A) (C) 1997 KONAMI CO., LTD.
113|-------------------------|
114| CN4 CN3  |---------|    |
115|          |---------|CN2 |
116|          PAL            |
117|                         |
118|             NVRAM       |
119|                         |
120|          |---------|    |
121|          |---------|CN1 |
122|-------------------------|
123Notes:
124      NVRAM  - With Heat of Eleven '98, uses Dallas DS1643 NonVolatile TimeKeeping RAM
125               With Battle Tryst, uses ST M48T58Y-70PC1 NonVolatile TimeKeeping RAM
126               With Poly Stars, a sub board is not used at all
127      PAL    - PALCE16V8Q, stamped 'X636A1'
128      CN3    - 4-pin sound cable tied to CN16 (CD-DA Input) on main lower board
129      CN4    - 4-pin sound cable tied to CDROM analog audio output connector
130
131GQ639 PWB 403327(A)
132|-----------------------------------------|
133|       639JAA02.xx                       |
134|                                         |
135|                                         |
136|                   |---------|           |
137|                   |---------|           |
138|                                         |
139|                                         |
140|               PAL                       |
141|                                         |
142|                                         |
143|                                         |
144|                                         |
145|                   |---------|           |
146|      YMZ280B      |---------|           |
147|                                         |
148|      16.9344MHz                         |
149|                                         |
150|                                         |
151|-----------------------------------------|
152Notes:
153      This PCB is used on Total Vice only.
154      639JAA02.xx - 8MBit Sound data ROM (DIP42)
155      PAL         - PAL16V8H stampd '       '
156
157
158PWB0000047043 (C) 1998 KONAMI CO., LTD.
159|-----------------------------------------|
160| CN4     CN3                             |
161|                                         |
162|                                         |
163|                   |---------|           |
164|                   |---------|           |
165|        16.9344MHz              M48T58Y  |
166|                      PAL                |
167|          YMZ280B                        |
168|                                         |
169|                                         |
170|                                         |
171|                                         |
172|                   |---------|           |
173|                   |---------|           |
174|                                         |
175|                                         |
176|                                         |
177|              810A03.16H                 |
178|-----------------------------------------|
179Notes:
180      This PCB is used on Evil Night/Hell Night only.
181      810A03.16H - 16MBit Sound data ROM (DIP42, byte mode)
182      PAL        - PAL16V8H stamped 'N810B1'
183      M48T58Y    - ST M48T58Y-70PC1 NonVolatile TimeKeeping RAM
184      CN3        - 4-pin sound cable tied to CN16 (CD-DA Input) on main lower board
185      CN4        - 4-pin sound cable tied to CDROM analog audio output connector
96186*/
97187
188
98189#include "driver.h"
99190#include "cdrom.h"
100191#include "cpu/powerpc/ppc.h"
src/mame/drivers/cave.c
r2762r2763
308308static int cave_default_eeprom_length;
309309static int cave_region_byte;
310310
311static READ16_HANDLER( cave_input1_r )
312{
313   return input_port_read_indexed(machine, 1) | ((EEPROM_read_bit() & 0x01) << 11);
314}
315
316static READ16_HANDLER( guwange_input1_r )
317{
318   return input_port_read_indexed(machine, 1) | ((EEPROM_read_bit() & 0x01) << 7);
319}
320
321311static READ16_HANDLER( gaia_dsw_r )
322312{
323313   return input_port_read_indexed(machine, 2) | (input_port_read_indexed(machine, 3) << 8);
r2762r2763
336326      coin_counter_w(0, data & 0x1000);
337327
338328      // latch the bit
339      EEPROM_write_bit(data & 0x0800);
329      eeprom_write_bit(data & 0x0800);
340330
341331      // reset line asserted: reset.
342      EEPROM_set_cs_line((data & 0x0200) ? CLEAR_LINE : ASSERT_LINE );
332      eeprom_set_cs_line((data & 0x0200) ? CLEAR_LINE : ASSERT_LINE );
343333
344334      // clock line asserted: write latch or select next bit to read
345      EEPROM_set_clock_line((data & 0x0400) ? ASSERT_LINE : CLEAR_LINE );
335      eeprom_set_clock_line((data & 0x0400) ? ASSERT_LINE : CLEAR_LINE );
346336   }
347337}
348338
r2762r2763
357347   if ( ACCESSING_BITS_8_15 )  // even address
358348   {
359349      // latch the bit
360      EEPROM_write_bit(data & 0x0800);
350      eeprom_write_bit(data & 0x0800);
361351
362352      // reset line asserted: reset.
363      EEPROM_set_cs_line((data & 0x0200) ? CLEAR_LINE : ASSERT_LINE );
353      eeprom_set_cs_line((data & 0x0200) ? CLEAR_LINE : ASSERT_LINE );
364354
365355      // clock line asserted: write latch or select next bit to read
366      EEPROM_set_clock_line((data & 0x0400) ? CLEAR_LINE: ASSERT_LINE );
356      eeprom_set_clock_line((data & 0x0400) ? CLEAR_LINE: ASSERT_LINE );
367357   }
368358}
369359
r2762r2763
380370      coin_counter_w(0, data & 0x0001);
381371
382372      // latch the bit
383      EEPROM_write_bit(data & 0x80);
373      eeprom_write_bit(data & 0x80);
384374
385375      // reset line asserted: reset.
386      EEPROM_set_cs_line((data & 0x20) ? CLEAR_LINE : ASSERT_LINE );
376      eeprom_set_cs_line((data & 0x20) ? CLEAR_LINE : ASSERT_LINE );
387377
388378      // clock line asserted: write latch or select next bit to read
389      EEPROM_set_clock_line((data & 0x40) ? ASSERT_LINE : CLEAR_LINE );
379      eeprom_set_clock_line((data & 0x40) ? ASSERT_LINE : CLEAR_LINE );
390380   }
391381}
392382
r2762r2763
415405      if (~data & 0x0100)
416406      {
417407         // latch the bit
418         EEPROM_write_bit(data & 0x0800);
408         eeprom_write_bit(data & 0x0800);
419409
420410         // reset line asserted: reset.
421         EEPROM_set_cs_line((data & 0x0200) ? CLEAR_LINE : ASSERT_LINE );
411         eeprom_set_cs_line((data & 0x0200) ? CLEAR_LINE : ASSERT_LINE );
422412
423413         // clock line asserted: write latch or select next bit to read
424         EEPROM_set_clock_line((data & 0x0400) ? ASSERT_LINE : CLEAR_LINE );
414         eeprom_set_clock_line((data & 0x0400) ? ASSERT_LINE : CLEAR_LINE );
425415      }
426416   }
427417}
r2762r2763
429419static NVRAM_HANDLER( cave )
430420{
431421   if (read_or_write)
432      EEPROM_save(file);
422      eeprom_save(file);
433423   else
434424   {
435      EEPROM_init(&eeprom_interface_93C46);
425      eeprom_init(&eeprom_interface_93C46);
436426
437      if (file) EEPROM_load(file);
427      if (file) eeprom_load(file);
438428      else
439429      {
440430         if (cave_default_eeprom)   /* Set the EEPROM to Factory Defaults */
441            EEPROM_set_data(cave_default_eeprom,cave_default_eeprom_length);
431            eeprom_set_data(cave_default_eeprom,cave_default_eeprom_length);
442432      }
443433   }
444434}
445435
446static const struct EEPROM_interface eeprom_interface_93C46_8bit =
436static const eeprom_interface eeprom_interface_93C46_8bit =
447437{
448438   7,            // address bits 7
449439   8,            // data bits    8
r2762r2763
460450static NVRAM_HANDLER( korokoro )
461451{
462452   if (read_or_write)
463      EEPROM_save(file);
453      eeprom_save(file);
464454   else
465455   {
466      EEPROM_init(&eeprom_interface_93C46_8bit);
456      eeprom_init(&eeprom_interface_93C46_8bit);
467457
468      if (file) EEPROM_load(file);
458      if (file) eeprom_load(file);
469459      else
470460      {
471461         if (cave_default_eeprom)   /* Set the EEPROM to Factory Defaults */
472            EEPROM_set_data(cave_default_eeprom,cave_default_eeprom_length);
462            eeprom_set_data(cave_default_eeprom,cave_default_eeprom_length);
473463      }
474464   }
475465}
r2762r2763
506496/**/AM_RANGE(0x900000, 0x900005) AM_READ(SMH_RAM            )   // Layer 0 Control
507497/**/AM_RANGE(0xa00000, 0xa00005) AM_READ(SMH_RAM            )   // Layer 1 Control
508498   AM_RANGE(0xb00000, 0xb00001) AM_READ(input_port_0_word_r   )   // Inputs
509   AM_RANGE(0xb00002, 0xb00003) AM_READ(cave_input1_r         )   // Inputs + EEPROM
499   AM_RANGE(0xb00002, 0xb00003) AM_READ(input_port_1_word_r   )   // Inputs + EEPROM
510500ADDRESS_MAP_END
511501
512502static ADDRESS_MAP_START( dfeveron_writemem, ADDRESS_SPACE_PROGRAM, 16 )
r2762r2763
545535/**/AM_RANGE(0xb00000, 0xb00005) AM_READ(SMH_RAM            )   // Layer 2 Control
546536/**/AM_RANGE(0xc00000, 0xc0ffff) AM_READ(SMH_RAM            )   // Palette
547537   AM_RANGE(0xd00000, 0xd00001) AM_READ(input_port_0_word_r   )   // Inputs
548   AM_RANGE(0xd00002, 0xd00003) AM_READ(cave_input1_r         )   // Inputs + EEPROM
538   AM_RANGE(0xd00002, 0xd00003) AM_READ(input_port_1_word_r   )   // Inputs + EEPROM
549539ADDRESS_MAP_END
550540
551541static ADDRESS_MAP_START( ddonpach_writemem, ADDRESS_SPACE_PROGRAM, 16 )
r2762r2763
611601   AM_RANGE(0xb00000, 0xb00001) AM_READ(OKIM6295_status_0_lsb_r   )   // M6295
612602   AM_RANGE(0xb00010, 0xb00011) AM_READ(OKIM6295_status_1_lsb_r   )   //
613603   AM_RANGE(0xc00000, 0xc00001) AM_READ(input_port_0_word_r      )   // Inputs
614   AM_RANGE(0xc00002, 0xc00003) AM_READ(cave_input1_r            )   // Inputs + EEPROM
604   AM_RANGE(0xc00002, 0xc00003) AM_READ(input_port_1_word_r      )   // Inputs + EEPROM
615605ADDRESS_MAP_END
616606
617607static ADDRESS_MAP_START( donpachi_writemem, ADDRESS_SPACE_PROGRAM, 16 )
r2762r2763
653643/**/AM_RANGE(0xb00000, 0xb00005) AM_READ(SMH_RAM            )   // Layer 2 Control
654644/**/AM_RANGE(0xc00000, 0xc0ffff) AM_READ(SMH_RAM            )   // Palette
655645   AM_RANGE(0xd00000, 0xd00001) AM_READ(input_port_0_word_r   )   // Inputs
656   AM_RANGE(0xd00002, 0xd00003) AM_READ(cave_input1_r         )   // Inputs + EEPROM
646   AM_RANGE(0xd00002, 0xd00003) AM_READ(input_port_1_word_r   )   // Inputs + EEPROM
657647ADDRESS_MAP_END
658648
659649static ADDRESS_MAP_START( esprade_writemem, ADDRESS_SPACE_PROGRAM, 16 )
r2762r2763
741731/**/AM_RANGE(0xb00000, 0xb00005) AM_READ(SMH_RAM            )   // Layer 2 Control
742732/**/AM_RANGE(0xc00000, 0xc0ffff) AM_READ(SMH_RAM            )   // Palette
743733   AM_RANGE(0xd00010, 0xd00011) AM_READ(input_port_0_word_r   )   // Inputs
744   AM_RANGE(0xd00012, 0xd00013) AM_READ(guwange_input1_r      )   // Inputs + EEPROM
734   AM_RANGE(0xd00012, 0xd00013) AM_READ(input_port_1_word_r   )   // Inputs + EEPROM
745735ADDRESS_MAP_END
746736
747737static ADDRESS_MAP_START( guwange_writemem, ADDRESS_SPACE_PROGRAM, 16 )
r2762r2763
781771/**/AM_RANGE(0xb80000, 0xb80005) AM_READ(SMH_RAM            )   // Layer 1 Control
782772/**/AM_RANGE(0xc00000, 0xc00005) AM_READ(SMH_RAM            )   // Layer 2 Control
783773   AM_RANGE(0xc80000, 0xc80001) AM_READ(input_port_0_word_r   )   // Inputs
784   AM_RANGE(0xc80002, 0xc80003) AM_READ(cave_input1_r         )   // Inputs + EEPROM
774   AM_RANGE(0xc80002, 0xc80003) AM_READ(input_port_1_word_r   )   // Inputs + EEPROM
785775/**/AM_RANGE(0xf00000, 0xf07fff) AM_READ(SMH_RAM            )   // Sprites
786776/**/AM_RANGE(0xf08000, 0xf0ffff) AM_READ(SMH_RAM            )   // Sprites?
787777ADDRESS_MAP_END
r2762r2763
857847      hopper = data & 0x0100;   // ???
858848
859849      // latch the bit
860      EEPROM_write_bit(data & 0x4000);
850      eeprom_write_bit(data & 0x4000);
861851
862852      // reset line asserted: reset.
863      EEPROM_set_cs_line((data & 0x1000) ? CLEAR_LINE : ASSERT_LINE );
853      eeprom_set_cs_line((data & 0x1000) ? CLEAR_LINE : ASSERT_LINE );
864854
865855      // clock line asserted: write latch or select next bit to read
866      EEPROM_set_clock_line((data & 0x2000) ? ASSERT_LINE : CLEAR_LINE );
856      eeprom_set_clock_line((data & 0x2000) ? ASSERT_LINE : CLEAR_LINE );
867857   }
868858}
869859
870static READ16_HANDLER( korokoro_input0_r )
860static CUSTOM_INPUT( korokoro_hopper_r )
871861{
872   return input_port_read_indexed(machine, 0) | (hopper ? 0 : 0x8000);
862   return hopper ? 1 : 0;
873863}
874864
875static READ16_HANDLER( korokoro_input1_r )
876{
877   return input_port_read_indexed(machine, 1) | ((EEPROM_read_bit() & 0x01) << 12);
878}
879
880865static ADDRESS_MAP_START( korokoro_readmem, ADDRESS_SPACE_PROGRAM, 16 )
881866   AM_RANGE(0x000000, 0x07ffff) AM_READ( SMH_ROM            )   // ROM
882867//  AM_RANGE(0x100000, 0x107fff) AM_READ( SMH_RAM             )   // Layer 0
r2762r2763
885870   AM_RANGE(0x1c0000, 0x1c0007) AM_READ( cave_irq_cause_r      )   // IRQ Cause
886871//  AM_RANGE(0x200000, 0x207fff) AM_READ( SMH_RAM             )   // Palette
887872//  AM_RANGE(0x240000, 0x240003) AM_READ( cave_sound_r          )   // YMZ280
888   AM_RANGE(0x280000, 0x280001) AM_READ( korokoro_input0_r      )   // Inputs + ???
889   AM_RANGE(0x280002, 0x280003) AM_READ( korokoro_input1_r      )   // Inputs + EEPROM
873   AM_RANGE(0x280000, 0x280001) AM_READ( input_port_0_word_r   )   // Inputs + ???
874   AM_RANGE(0x280002, 0x280003) AM_READ( input_port_1_word_r   )   // Inputs + EEPROM
890875   AM_RANGE(0x300000, 0x30ffff) AM_READ( SMH_RAM            )   // RAM
891876ADDRESS_MAP_END
892877
r2762r2763
921906/**/AM_RANGE(0x600000, 0x600005) AM_READ(SMH_RAM            )   // Layer 1 Control
922907/**/AM_RANGE(0x700000, 0x700005) AM_READ(SMH_RAM            )   // Layer 0 Control
923908   AM_RANGE(0x800000, 0x800001) AM_READ(input_port_0_word_r   )   // Inputs
924   AM_RANGE(0x800002, 0x800003) AM_READ(cave_input1_r         )   // Inputs + EEPROM
909   AM_RANGE(0x800002, 0x800003) AM_READ(input_port_1_word_r   )   // Inputs + EEPROM
925910/**/AM_RANGE(0xc08000, 0xc0ffff) AM_READ(SMH_RAM            )   // Palette
926911   AM_RANGE(0xd00000, 0xd7ffff) AM_READ(SMH_BANK1         )   // ROM
927912ADDRESS_MAP_END
r2762r2763
967952/**/AM_RANGE(0xb80000, 0xb80005) AM_READ(SMH_RAM            )   // Layer 1 Control
968953/**/AM_RANGE(0xc00000, 0xc00005) AM_READ(SMH_RAM            )   // Layer 2 Control
969954   AM_RANGE(0xc80000, 0xc80001) AM_READ(input_port_0_word_r   )   // Inputs
970   AM_RANGE(0xc80002, 0xc80003) AM_READ(cave_input1_r         )   // Inputs + EEPROM
955   AM_RANGE(0xc80002, 0xc80003) AM_READ(input_port_1_word_r   )   // Inputs + EEPROM
971956   AM_RANGE(0xf00000, 0xf07fff) AM_READ(SMH_RAM            )   // Sprites
972957   AM_RANGE(0xf08000, 0xf0ffff) AM_READ(SMH_RAM            )   // RAM
973958ADDRESS_MAP_END
r2762r2763
1002987
1003988static READ16_HANDLER( pwrinst2_eeprom_r )
1004989{
1005   return ~8 + ((EEPROM_read_bit() & 1) ? 8 : 0);
990   return ~8 + ((eeprom_read_bit() & 1) ? 8 : 0);
1006991}
1007992
1008993INLINE void vctrl_w(UINT16 *VCTRL, ATTR_UNUSED offs_t offset, ATTR_UNUSED UINT16 data, ATTR_UNUSED UINT16 mem_mask)
r2762r2763
11061091   AM_RANGE(0x508000, 0x50ffff) AM_READ(SMH_RAM            )   // Sprites?
11071092   AM_RANGE(0x510000, 0x510001) AM_READ(SMH_RAM            )   // (agallet)
11081093   AM_RANGE(0x600000, 0x600001) AM_READ(sailormn_input0_r      )   // Inputs + Watchdog!
1109   AM_RANGE(0x600002, 0x600003) AM_READ(cave_input1_r         )   // Inputs + EEPROM
1094   AM_RANGE(0x600002, 0x600003) AM_READ(input_port_1_word_r   )   // Inputs + EEPROM
11101095   AM_RANGE(0x800000, 0x887fff) AM_READ(SMH_RAM            )   // Layer 0
11111096   AM_RANGE(0x880000, 0x887fff) AM_READ(SMH_RAM            )   // Layer 1
11121097   AM_RANGE(0x900000, 0x907fff) AM_READ(SMH_RAM            )   // Layer 2
r2762r2763
11591144/**/AM_RANGE(0x700000, 0x700005) AM_READ(SMH_RAM            )   // Layer 0 Control
11601145/**/AM_RANGE(0x800000, 0x80ffff) AM_READ(SMH_RAM            )   // Palette
11611146   AM_RANGE(0x900000, 0x900001) AM_READ(input_port_0_word_r   )   // Inputs
1162   AM_RANGE(0x900002, 0x900003) AM_READ(cave_input1_r         )   // Inputs + EEPROM
1147   AM_RANGE(0x900002, 0x900003) AM_READ(input_port_1_word_r   )   // Inputs + EEPROM
11631148ADDRESS_MAP_END
11641149
11651150static ADDRESS_MAP_START( uopoko_writemem, ADDRESS_SPACE_PROGRAM, 16 )
r2762r2763
14971482   PORT_BIT(  0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
14981483   PORT_BIT(  0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1)
14991484   PORT_BIT(  0x0080, IP_ACTIVE_LOW, IPT_START1  )
1500
15011485   PORT_BIT(  0x0100, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_IMPULSE(6)
15021486   PORT_SERVICE_NO_TOGGLE(0x0200, IP_ACTIVE_LOW )
15031487   PORT_BIT(  0x0400, IP_ACTIVE_LOW, IPT_UNKNOWN )   // sw? exit service mode
r2762r2763
15161500   PORT_BIT(  0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
15171501   PORT_BIT(  0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2)
15181502   PORT_BIT(  0x0080, IP_ACTIVE_LOW, IPT_START2  )
1519
15201503   PORT_BIT(  0x0100, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_IMPULSE(6)
15211504   PORT_BIT(  0x0200, IP_ACTIVE_LOW,  IPT_SERVICE1)
15221505   PORT_BIT(  0x0400, IP_ACTIVE_LOW,  IPT_UNKNOWN )
1523   PORT_BIT(  0x0800, IP_ACTIVE_HIGH, IPT_SPECIAL )   // eeprom bit
1506   PORT_BIT(  0x0800, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(eeprom_bit_r, NULL)
15241507   PORT_BIT(  0x1000, IP_ACTIVE_LOW,  IPT_UNKNOWN )
15251508   PORT_BIT(  0x2000, IP_ACTIVE_LOW,  IPT_UNKNOWN )
15261509   PORT_BIT(  0x4000, IP_ACTIVE_LOW,  IPT_UNKNOWN )
r2762r2763
15331516
15341517   PORT_MODIFY("IN0")   // IN0 - Player 1 + 2
15351518   PORT_BIT(  0x0080, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1)
1536
15371519   PORT_BIT(  0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2)
15381520   PORT_BIT(  0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN    ) PORT_PLAYER(2)
15391521   PORT_BIT(  0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2)
r2762r2763
15521534   PORT_BIT(  0x0020, IP_ACTIVE_LOW, IPT_START2 )
15531535   PORT_BIT(  0x0040, IP_ACTIVE_LOW, IPT_UNKNOWN )
15541536   PORT_BIT(  0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN )
1555
15561537   PORT_BIT(  0x0100, IP_ACTIVE_LOW, IPT_UNKNOWN )
15571538   PORT_BIT(  0x0200, IP_ACTIVE_LOW, IPT_UNKNOWN )
15581539   PORT_BIT(  0x0800, IP_ACTIVE_LOW, IPT_UNKNOWN )
r2762r2763
16861667   PORT_BIT(  0x0020, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1)
16871668   PORT_BIT(  0x0040, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
16881669   PORT_BIT(  0x0080, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1)
1689
16901670   PORT_BIT(  0x0100, IP_ACTIVE_LOW, IPT_START2  )
16911671   PORT_BIT(  0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    ) PORT_PLAYER(2)
16921672   PORT_BIT(  0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2)
r2762r2763
17041684   PORT_BIT(  0x0010, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
17051685   PORT_BIT(  0x0020, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
17061686   PORT_BIT(  0x0040, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
1707   PORT_BIT(  0x0080, IP_ACTIVE_HIGH, IPT_SPECIAL )   // eeprom bit
1708
1687   PORT_BIT(  0x0080, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(eeprom_bit_r, NULL)
17091688   PORT_BIT(  0x0100, IP_ACTIVE_LOW, IPT_UNKNOWN )
17101689   PORT_BIT(  0x0200, IP_ACTIVE_LOW, IPT_UNKNOWN )
17111690   PORT_BIT(  0x0400, IP_ACTIVE_LOW, IPT_UNKNOWN )
r2762r2763
17271706   PORT_BIT(  0x0020, IP_ACTIVE_LOW, IPT_UNKNOWN )
17281707   PORT_BIT(  0x0040, IP_ACTIVE_LOW, IPT_UNKNOWN )
17291708   PORT_BIT(  0x0080, IP_ACTIVE_LOW, IPT_UNKNOWN )
1730
17311709   PORT_BIT(  0x0100, IP_ACTIVE_LOW, IPT_UNKNOWN )
17321710   PORT_BIT(  0x0200, IP_ACTIVE_LOW, IPT_UNKNOWN )
17331711   PORT_BIT(  0x0400, IP_ACTIVE_LOW, IPT_UNKNOWN )
r2762r2763
17351713   PORT_BIT(  0x1000, IP_ACTIVE_LOW, IPT_SERVICE2)   // service medal out?
17361714   PORT_SERVICE( 0x2000, IP_ACTIVE_LOW )
17371715   PORT_BIT(  0x4000, IP_ACTIVE_LOW, IPT_SERVICE1)   // service coin
1738   PORT_BIT(  0x8000, IP_ACTIVE_HIGH, IPT_SPECIAL)   // motor / hopper status ???
1716   PORT_BIT(  0x8000, IP_ACTIVE_LOW, IPT_SPECIAL)   PORT_CUSTOM(korokoro_hopper_r, NULL) // motor / hopper status ???
17391717
17401718   PORT_START_TAG("IN1")   // IN1
17411719   PORT_BIT(  0x0001, IP_ACTIVE_LOW,  IPT_UNKNOWN )
r2762r2763
17461724   PORT_BIT(  0x0020, IP_ACTIVE_LOW,  IPT_UNKNOWN )
17471725   PORT_BIT(  0x0040, IP_ACTIVE_LOW,  IPT_UNKNOWN )
17481726   PORT_BIT(  0x0080, IP_ACTIVE_LOW,  IPT_UNKNOWN )
1749
17501727   PORT_BIT(  0x0100, IP_ACTIVE_LOW,  IPT_UNKNOWN )
17511728   PORT_BIT(  0x0200, IP_ACTIVE_LOW,  IPT_UNKNOWN )
17521729   PORT_BIT(  0x0400, IP_ACTIVE_LOW,  IPT_UNKNOWN )
17531730   PORT_BIT(  0x0800, IP_ACTIVE_LOW,  IPT_UNKNOWN )
1754   PORT_BIT(  0x1000, IP_ACTIVE_HIGH, IPT_SPECIAL )   // eeprom bit
1731   PORT_BIT(  0x1000, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(eeprom_bit_r, NULL)
17551732   PORT_BIT(  0x2000, IP_ACTIVE_LOW,  IPT_UNKNOWN )
17561733   PORT_BIT(  0x4000, IP_ACTIVE_LOW,  IPT_UNKNOWN )
17571734   PORT_BIT(  0x8000, IP_ACTIVE_LOW,  IPT_UNKNOWN )
r2762r2763
19831960   /* modify the eeprom on a reset with the desired region for the games that have the
19841961       region factory set in eeprom */
19851962   if (cave_region_byte >= 0)
1986      EEPROM_get_data_pointer(0)[cave_region_byte] =  input_port_read_indexed(machine, 2);
1963      eeprom_get_data_pointer(0)[cave_region_byte] =  input_port_read_indexed(machine, 2);
19871964}
19881965
19891966static const struct YMZ280Binterface ymz280b_intf =
src/mame/drivers/rbmk.c
r2762r2763
8787
8888static READ16_HANDLER( eeprom_r )
8989{
90   return (EEPROM_read_bit() << 15)|(input_port_read_indexed(machine,3)&0x7fff);
90   return (eeprom_read_bit() << 15)|(input_port_read_indexed(machine,3)&0x7fff);
9191}
9292
9393static WRITE16_HANDLER( eeprom_w )
r2762r2763
9595   //bad ?
9696   if( ACCESSING_BITS_0_7 )
9797   {
98      EEPROM_write_bit(data & 0x04);
99      EEPROM_set_cs_line((data & 0x01) ? CLEAR_LINE:ASSERT_LINE );
98      eeprom_write_bit(data & 0x04);
99      eeprom_set_cs_line((data & 0x01) ? CLEAR_LINE:ASSERT_LINE );
100100
101      EEPROM_set_clock_line((data & 0x02) ? ASSERT_LINE : CLEAR_LINE );
101      eeprom_set_clock_line((data & 0x02) ? ASSERT_LINE : CLEAR_LINE );
102102   }
103103}
104104
r2762r2763
480480static NVRAM_HANDLER( syf )
481481{
482482   if (read_or_write)
483      EEPROM_save(file);
483      eeprom_save(file);
484484   else
485485   {
486      EEPROM_init(&eeprom_interface_93C46);
486      eeprom_init(&eeprom_interface_93C46);
487487      if (file)
488488      {
489         EEPROM_load(file);
489         eeprom_load(file);
490490      }
491491      else
492492      {
493         EEPROM_set_data(memory_region(REGION_USER2),128);
493         eeprom_set_data(memory_region(REGION_USER2),128);
494494      }
495495   }
496496}
src/mame/drivers/rpunch.c
r2762r2763
755755 *
756756 *************************************/
757757
758GAME( 1987, rabiolep, 0,        rpunch,   rabiolep, rabiolep, ROT0, "V-System Co.", "Rabio Lepus (Japan)", 0 )
759GAME( 1987, rpunch,   rabiolep, rpunch,   rpunch,   rabiolep, ROT0, "V-System Co. (Bally/Midway/Sente license)", "Rabbit Punch (US)", 0 )
760GAME( 1989, svolley,  0,        rpunch,   svolley,  svolley,  ROT0, "V-System Co.", "Super Volleyball (Japan)", 0 )
761GAME( 1989, svolleyk, svolley,  rpunch,   svolley,  svolley,  ROT0, "V-System Co.", "Super Volleyball (Korea)", 0 )
762GAME( 1989, svolleyu, svolley,  rpunch,   svolley,  svolley,  ROT0, "V-System Co. (Data East license)", "Super Volleyball (US)", 0 )
758GAME( 1987, rabiolep, 0,        rpunch,   rabiolep, rabiolep, ROT0, "V-System Co.", "Rabio Lepus (Japan)", GAME_NO_COCKTAIL )
759GAME( 1987, rpunch,   rabiolep, rpunch,   rpunch,   rabiolep, ROT0, "V-System Co. (Bally/Midway/Sente license)", "Rabbit Punch (US)", GAME_NO_COCKTAIL )
760GAME( 1989, svolley,  0,        rpunch,   svolley,  svolley,  ROT0, "V-System Co.", "Super Volleyball (Japan)", GAME_NO_COCKTAIL )
761GAME( 1989, svolleyk, svolley,  rpunch,   svolley,  svolley,  ROT0, "V-System Co.", "Super Volleyball (Korea)", GAME_NO_COCKTAIL )
762GAME( 1989, svolleyu, svolley,  rpunch,   svolley,  svolley,  ROT0, "V-System Co. (Data East license)", "Super Volleyball (US)", GAME_NO_COCKTAIL )
src/mame/drivers/rabbit.c
r2762r2763
450450
451451   rv = (input_port_read_indexed(machine, 1)<<16)|(input_port_read_indexed(machine, 0));
452452   rv &= ~1;
453   rv |= EEPROM_read_bit();   // as per code at 4d932
453   rv |= eeprom_read_bit();   // as per code at 4d932
454454   return rv;
455455}
456456
r2762r2763
460460
461461   rv = (input_port_read_indexed(machine, 1)<<16)|(input_port_read_indexed(machine, 0));
462462   rv &= ~0x80;
463   rv |= (EEPROM_read_bit()<<7);   // as per code at 778
463   rv |= (eeprom_read_bit()<<7);   // as per code at 778
464464   return rv;
465465}
466466
r2762r2763
725725   if (mem_mask == 0xff000000)
726726   {
727727      // latch the bit
728      EEPROM_write_bit(data & 0x01000000);
728      eeprom_write_bit(data & 0x01000000);
729729
730730      // reset line asserted: reset.
731      EEPROM_set_cs_line((data & 0x04000000) ? CLEAR_LINE : ASSERT_LINE );
731      eeprom_set_cs_line((data & 0x04000000) ? CLEAR_LINE : ASSERT_LINE );
732732
733733      // clock line asserted: write latch or select next bit to read
734      EEPROM_set_clock_line((data & 0x02000000) ? ASSERT_LINE : CLEAR_LINE );
734      eeprom_set_clock_line((data & 0x02000000) ? ASSERT_LINE : CLEAR_LINE );
735735   }
736736}
737737
src/mame/drivers/backfire.c
r2762r2763
230230{
231231   /* some kind of screen indicator?  checked by backfira set before it will boot */
232232   int backfire_screen = mame_rand(machine)&1;
233   return ((EEPROM_read_bit()<<24) | input_port_read_indexed(machine, 0) | (input_port_read_indexed(machine, 3)<<16)) ^  (backfire_screen << 26) ;
233   return ((eeprom_read_bit()<<24) | input_port_read_indexed(machine, 0) | (input_port_read_indexed(machine, 3)<<16)) ^  (backfire_screen << 26) ;
234234}
235235
236236static READ32_HANDLER(backfire_control2_r)
237237{
238238//  logerror("%08x:Read eprom %08x (%08x)\n",activecpu_get_pc(),offset<<1,mem_mask);
239   return (EEPROM_read_bit()<<24) | input_port_read_indexed(machine, 1) | (input_port_read_indexed(machine, 1)<<16);
239   return (eeprom_read_bit()<<24) | input_port_read_indexed(machine, 1) | (input_port_read_indexed(machine, 1)<<16);
240240}
241241
242242#ifdef UNUSED_FUNCTION
243243static READ32_HANDLER(backfire_control3_r)
244244{
245245//  logerror("%08x:Read eprom %08x (%08x)\n",activecpu_get_pc(),offset<<1,mem_mask);
246   return (EEPROM_read_bit()<<24) | input_port_read_indexed(machine, 2) | (input_port_read_indexed(machine, 2)<<16);
246   return (eeprom_read_bit()<<24) | input_port_read_indexed(machine, 2) | (input_port_read_indexed(machine, 2)<<16);
247247}
248248#endif
249249
r2762r2763
252252{
253253   logerror("%08x:write eprom %08x (%08x) %08x\n",activecpu_get_pc(),offset<<1,mem_mask,data);
254254   if (ACCESSING_BITS_0_7) {
255      EEPROM_set_clock_line((data & 0x2) ? ASSERT_LINE : CLEAR_LINE);
256      EEPROM_write_bit(data & 0x1);
257      EEPROM_set_cs_line((data & 0x4) ? CLEAR_LINE : ASSERT_LINE);
255      eeprom_set_clock_line((data & 0x2) ? ASSERT_LINE : CLEAR_LINE);
256      eeprom_write_bit(data & 0x1);
257      eeprom_set_cs_line((data & 0x4) ? CLEAR_LINE : ASSERT_LINE);
258258   }
259259}
260260
src/mame/drivers/pirates.c
r2762r2763
103103
104104
105105
106static const struct EEPROM_interface eeprom_interface =
106static const eeprom_interface eeprom_intf =
107107{
108108   6,            /* address bits */
109109   16,            /* data bits */
r2762r2763
116116
117117static NVRAM_HANDLER( pirates )
118118{
119   if (read_or_write) EEPROM_save(file);
119   if (read_or_write) eeprom_save(file);
120120   else
121121   {
122      EEPROM_init(&eeprom_interface);
123      if (file) EEPROM_load(file);
122      eeprom_init(&eeprom_intf);
123      if (file) eeprom_load(file);
124124   }
125125}
126126
r2762r2763
129129   if (ACCESSING_BITS_0_7)
130130   {
131131      /* bits 0-2 control EEPROM */
132      EEPROM_write_bit(data & 0x04);
133      EEPROM_set_cs_line((data & 0x01) ? CLEAR_LINE : ASSERT_LINE);
134      EEPROM_set_clock_line((data & 0x02) ? ASSERT_LINE : CLEAR_LINE);
132      eeprom_write_bit(data & 0x04);
133      eeprom_set_cs_line((data & 0x01) ? CLEAR_LINE : ASSERT_LINE);
134      eeprom_set_clock_line((data & 0x02) ? ASSERT_LINE : CLEAR_LINE);
135135
136136      /* bit 6 selects oki bank */
137137      OKIM6295_set_bank_base(0, (data & 0x40) ? 0x40000 : 0x00000);
r2762r2763
170170      bit = 1;
171171
172172   /* bit 4 is EEPROM data, bit 7 is protection */
173   return input_port_read_indexed(machine,1) | (EEPROM_read_bit() << 4) | (bit << 7);
173   return input_port_read_indexed(machine,1) | (eeprom_read_bit() << 4) | (bit << 7);
174174}
175175
176176
src/mame/drivers/astrocorp.c
r2762r2763
9595
9696static READ16_HANDLER( astrocorp_eeprom_r )
9797{
98   return 0xfff7 | (EEPROM_read_bit() << 3);
98   return 0xfff7 | (eeprom_read_bit() << 3);
9999}
100100
101101static WRITE16_HANDLER( astrocorp_eeprom_w )
r2762r2763
103103   if (ACCESSING_BITS_0_7)
104104   {
105105      // latch the bit
106      EEPROM_write_bit(data & 0x01);
106      eeprom_write_bit(data & 0x01);
107107
108108      // reset line asserted: reset.
109      EEPROM_set_cs_line((data & 0x04) ? CLEAR_LINE : ASSERT_LINE );
109      eeprom_set_cs_line((data & 0x04) ? CLEAR_LINE : ASSERT_LINE );
110110
111111      // clock line asserted: write latch or select next bit to read
112      EEPROM_set_clock_line((data & 0x02) ? ASSERT_LINE : CLEAR_LINE );
112      eeprom_set_clock_line((data & 0x02) ? ASSERT_LINE : CLEAR_LINE );
113113   }
114114}
115115
r2762r2763
236236static NVRAM_HANDLER( showhand )
237237{
238238   if (read_or_write)
239      EEPROM_save(file);
239      eeprom_save(file);
240240   else
241241   {
242      EEPROM_init(&eeprom_interface_93C46);
242      eeprom_init(&eeprom_interface_93C46);
243243
244      if (file) EEPROM_load(file);
244      if (file) eeprom_load(file);
245245      else
246246      {
247247         /* Set the EEPROM to Factory Defaults */
248         EEPROM_set_data((UINT8*)showhand_default_eeprom,sizeof(showhand_default_eeprom));
248         eeprom_set_data((UINT8*)showhand_default_eeprom,sizeof(showhand_default_eeprom));
249249      }
250250   }
251251}
src/mame/drivers/coolridr.c
r2762r2763
11/*
2x
2
33Sega System H1
44preliminary
55
r2762r2763
1111-- readme --
1212
1313Cool Riders by SEGA 1995
14
15SYSTEM H1 CPU Board :
16
14SYSTEM H1 CPU Board
15-------------------
1716Processors :
18
1917Hitachi SH2 HD6417095
20
2118Toshiba TMP68HC000N-16
22
2319Hitachi SH7032 HD6417032F20
2420
25Eprom : Ep17662.12
21Eprom :
22Ep17662.12
2623
2724SEGA CUSTOM IC :
28
29315-5687 (x2) (SCSP)
30
25315-5687 (x2)
3126315-5757
32
3327315-5758
34
3528315-5849
36
3729315-5800 GAL16V8B
38
3930315-5801 GAL16V8B
40
4131315-5802 GAL16V8B
4232
43SYSTEM H1 VIDEO BOARD :
44
33SYSTEM H1 VIDEO BOARD
34---------------------
4535SEGA CUSTOM IC :
46
4736315-5648 (x4)
48
4937315-5691
50
5138315-5692
52
5339315-5693 (x2)
54
5540315-5694
56
5741315-5695 (x2)
58
5942315-5696 (x2)
60
6143315-5697
62
6344315-5698
64
6545315-5803 GAL16V8B
66
6746315-5864 GAL16V8B
6847
6948*/
src/mame/drivers/shisen.c
r2762r2763
181181   PORT_DIPNAME( 0x02, 0x00, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("SW2:2")
182182   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
183183   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
184   PORT_DIPNAME( 0x04, 0x04, "Coin Chute" ) PORT_DIPLOCATION("SW2:3")
184   PORT_DIPNAME( 0x04, 0x00, "Coin Chute" ) PORT_DIPLOCATION("SW2:3")
185185   PORT_DIPSETTING(    0x04, "Common" )
186186   PORT_DIPSETTING(    0x00, "Separate" )
187187   PORT_DIPNAME( 0x08, 0x08, "Nude Pictures" ) PORT_DIPLOCATION("SW2:4")
src/osd/winui/mui_util.c
r2762r2763
433433         if (gamedrv->ipt != NULL)
434434         {
435435            const input_port_config *port;
436            input_ports = input_port_config_alloc(gamedrv->ipt);
436            input_ports = input_port_config_alloc(gamedrv->ipt, NULL, 0);
437437           
438438            for (port = input_ports; port != NULL; port = port->next)
439439            {
src/emu/debug/debugcpu.c
r2762r2763
223223      debug_cpuinfo[cpunum].temp_breakpoint_pc = ~0;
224224
225225      /* fetch the memory accessors */
226      debug_cpuinfo[cpunum].translate = (int (*)(int, offs_t *))cpunum_get_info_fct(cpunum, CPUINFO_PTR_TRANSLATE);
227      debug_cpuinfo[cpunum].read = (int (*)(int, UINT32, int, UINT64 *))cpunum_get_info_fct(cpunum, CPUINFO_PTR_READ);
228      debug_cpuinfo[cpunum].write = (int (*)(int, UINT32, int, UINT64))cpunum_get_info_fct(cpunum, CPUINFO_PTR_WRITE);
229      debug_cpuinfo[cpunum].readop = (int (*)(UINT32, int, UINT64 *))cpunum_get_info_fct(cpunum, CPUINFO_PTR_READOP);
226      debug_cpuinfo[cpunum].translate = (cpu_translate_func)cpunum_get_info_fct(cpunum, CPUINFO_PTR_TRANSLATE);
227      debug_cpuinfo[cpunum].read = (cpu_read_func)cpunum_get_info_fct(cpunum, CPUINFO_PTR_READ);
228      debug_cpuinfo[cpunum].write = (cpu_write_func)cpunum_get_info_fct(cpunum, CPUINFO_PTR_WRITE);
229      debug_cpuinfo[cpunum].readop = (cpu_readop_func)cpunum_get_info_fct(cpunum, CPUINFO_PTR_READOP);
230230
231231      /* allocate a symbol table */
232232      debug_cpuinfo[cpunum].symtable = symtable_alloc(global_symtable);
r2762r2763
16371637   memory_set_debugger_access(1);
16381638
16391639   /* translate if necessary; if not mapped, return 0xff */
1640   if (apply_translation && info->translate != NULL && !(*info->translate)(spacenum, &address))
1640   if (apply_translation && info->translate != NULL && !(*info->translate)(spacenum, TRANSLATE_READ_DEBUG, &address))
16411641      result = 0xff;
16421642
16431643   /* if there is a custom read handler, and it returns TRUE, use that value */
r2762r2763
16881688      memory_set_debugger_access(1);
16891689
16901690      /* translate if necessary; if not mapped, return 0xffff */
1691      if (apply_translation && info->translate != NULL && !(*info->translate)(spacenum, &address))
1691      if (apply_translation && info->translate != NULL && !(*info->translate)(spacenum, TRANSLATE_READ_DEBUG, &address))
16921692         result = 0xffff;
16931693
16941694      /* if there is a custom read handler, and it returns TRUE, use that value */
r2762r2763
17411741      memory_set_debugger_access(1);
17421742
17431743      /* translate if necessary; if not mapped, return 0xffffffff */
1744      if (apply_translation && info->translate != NULL && !(*info->translate)(spacenum, &address))
1744      if (apply_translation && info->translate != NULL && !(*info->translate)(spacenum, TRANSLATE_READ_DEBUG, &address))
17451745         result = 0xffffffff;
17461746
17471747      /* if there is a custom read handler, and it returns TRUE, use that value */
r2762r2763
17941794      memory_set_debugger_access(1);
17951795
17961796      /* translate if necessary; if not mapped, return 0xffffffffffffffff */
1797      if (apply_translation && info->translate != NULL && !(*info->translate)(spacenum, &address))
1797      if (apply_translation && info->translate != NULL && !(*info->translate)(spacenum, TRANSLATE_READ_DEBUG, &address))
17981798         result = ~(UINT64)0;
17991799
18001800      /* if there is a custom read handler, and it returns TRUE, use that value */
r2762r2763
18291829   memory_set_debugger_access(1);
18301830
18311831   /* translate if necessary; if not mapped, we're done */
1832   if (apply_translation && info->translate != NULL && !(*info->translate)(spacenum, &address))
1832   if (apply_translation && info->translate != NULL && !(*info->translate)(spacenum, TRANSLATE_WRITE_DEBUG, &address))
18331833      ;
18341834
18351835   /* if there is a custom write handler, and it returns TRUE, use that */
r2762r2763
18801880      memory_set_debugger_access(1);
18811881
18821882      /* translate if necessary; if not mapped, we're done */
1883      if (apply_translation && info->translate && !(*info->translate)(spacenum, &address))
1883      if (apply_translation && info->translate && !(*info->translate)(spacenum, TRANSLATE_WRITE_DEBUG, &address))
18841884         ;
18851885
18861886      /* if there is a custom write handler, and it returns TRUE, use that */
r2762r2763
19321932      memory_set_debugger_access(1);
19331933
19341934      /* translate if necessary; if not mapped, we're done */
1935      if (apply_translation && info->translate && !(*info->translate)(spacenum, &address))
1935      if (apply_translation && info->translate && !(*info->translate)(spacenum, TRANSLATE_WRITE_DEBUG, &address))
19361936         ;
19371937
19381938      /* if there is a custom write handler, and it returns TRUE, use that */
r2762r2763
19831983      memory_set_debugger_access(1);
19841984
19851985      /* translate if necessary; if not mapped, we're done */
1986      if (apply_translation && info->translate && !(*info->translate)(spacenum, &address))
1986      if (apply_translation && info->translate && !(*info->translate)(spacenum, TRANSLATE_WRITE_DEBUG, &address))
19871987         ;
19881988
19891989      /* if there is a custom write handler, and it returns TRUE, use that */
r2762r2763
20372037   }
20382038
20392039   /* translate to physical first */
2040   if (info->translate && !(*info->translate)(ADDRESS_SPACE_PROGRAM, &address))
2040   if (info->translate && !(*info->translate)(ADDRESS_SPACE_PROGRAM, TRANSLATE_FETCH_DEBUG, &address))
20412041      return ~(UINT64)0 & (~(UINT64)0 >> (64 - 8*size));
20422042
20432043   /* keep in physical range */
src/emu/debug/debugvw.c
r2762r2763
13591359
13601360         /* get the disassembly, but only if mapped */
13611361         instlen = 1;
1362         if (!cpuinfo->translate || (*cpuinfo->translate)(ADDRESS_SPACE_PROGRAM, &pcbyte))
1362         if (cpuinfo->translate == NULL || (*cpuinfo->translate)(ADDRESS_SPACE_PROGRAM, TRANSLATE_FETCH_DEBUG, &pcbyte))
13631363            instlen = activecpu_dasm(dasmbuffer, testpc & addrmask, &opbuf[1000 + testpc - startpc], &argbuf[1000 + testpc - startpc]) & DASMFLAG_LENGTHMASK;
13641364
13651365         /* count this one */
r2762r2763
15371537
15381538      /* make sure we can translate the address */
15391539      tempaddr = pcbyte;
1540      if (!cpuinfo->translate || (*cpuinfo->translate)(ADDRESS_SPACE_PROGRAM, &tempaddr))
1540      if (cpuinfo->translate == NULL || (*cpuinfo->translate)(ADDRESS_SPACE_PROGRAM, TRANSLATE_FETCH_DEBUG, &tempaddr))
15411541      {
15421542         UINT8 opbuf[64], argbuf[64];
15431543
r2762r2763
27702770                     if (curaddr > maxaddr)
27712771                        len += sprintf(&data[len], "   ");
27722772                     else if (memdata->raw_base != NULL || memdata->no_translation ||
2773                            cpuinfo->translate == NULL || (*cpuinfo->translate)(memdata->spacenum, &curaddr))
2773                            cpuinfo->translate == NULL || (*cpuinfo->translate)(memdata->spacenum, TRANSLATE_READ_DEBUG, &curaddr))
27742774                        len += sprintf(&data[len], "%02X ", memory_read_byte(memdata, addrbyte + i, !memdata->no_translation));
27752775                     else
27762776                        len += sprintf(&data[len], "** ");
r2762r2763
27842784                     if (curaddr > maxaddr)
27852785                        len += sprintf(&data[len], "      ");
27862786                     else if (memdata->raw_base != NULL || memdata->no_translation ||
2787                            cpuinfo->translate == NULL || (*cpuinfo->translate)(memdata->spacenum, &curaddr))
2787                            cpuinfo->translate == NULL || (*cpuinfo->translate)(memdata->spacenum, TRANSLATE_READ_DEBUG, &curaddr))
27882788                        len += sprintf(&data[len], " %04X ", memory_read_word(memdata, addrbyte + 2 * i, !memdata->no_translation));
27892789                     else
27902790                        len += sprintf(&data[len], " **** ");
r2762r2763
27982798                     if (curaddr > maxaddr)
27992799                        len += sprintf(&data[len], "            ");
28002800                     else if (memdata->raw_base != NULL || memdata->no_translation ||
2801                            cpuinfo->translate == NULL || (*cpuinfo->translate)(memdata->spacenum, &curaddr))
2801                            cpuinfo->translate == NULL || (*cpuinfo->translate)(memdata->spacenum, TRANSLATE_READ_DEBUG, &curaddr))
28022802                        len += sprintf(&data[len], "  %08X  ", memory_read_dword(memdata, addrbyte + 4 * i, !memdata->no_translation));
28032803                     else
28042804                        len += sprintf(&data[len], "  ********  ");
r2762r2763
28122812                     if (curaddr > maxaddr)
28132813                        len += sprintf(&data[len], "                        ");
28142814                     else if (memdata->raw_base != NULL || memdata->no_translation ||
2815                            cpuinfo->translate == NULL || (*cpuinfo->translate)(memdata->spacenum, &curaddr))
2815                            cpuinfo->translate == NULL || (*cpuinfo->translate)(memdata->spacenum, TRANSLATE_READ_DEBUG, &curaddr))
28162816                     {
28172817                        UINT64 qword = memory_read_qword(memdata, addrbyte + 8 * i, !memdata->no_translation);
28182818                        len += sprintf(&data[len], "    %08X%08X    ", (UINT32)(qword >> 32), (UINT32)qword);
r2762r2763
28662866                     if (curaddr > maxaddr)
28672867                        len += sprintf(&data[len], "   ");
28682868                     else if (memdata->raw_base != NULL || memdata->no_translation ||
2869                            cpuinfo->translate == NULL || (*cpuinfo->translate)(memdata->spacenum, &curaddr))
2869                            cpuinfo->translate == NULL || (*cpuinfo->translate)(memdata->spacenum, TRANSLATE_READ_DEBUG, &curaddr))
28702870                        len += sprintf(&data[len], "%02X ", memory_read_byte(memdata, addrbyte + i, !memdata->no_translation));
28712871                     else
28722872                        len += sprintf(&data[len], "** ");
r2762r2763
28802880                     if (curaddr > maxaddr)
28812881                        len += sprintf(&data[len], "      ");
28822882                     else if (memdata->raw_base != NULL || memdata->no_translation ||
2883                            cpuinfo->translate == NULL || (*cpuinfo->translate)(memdata->spacenum, &curaddr))
2883                            cpuinfo->translate == NULL || (*cpuinfo->translate)(memdata->spacenum, TRANSLATE_READ_DEBUG, &curaddr))
28842884                        len += sprintf(&data[len], " %04X ", memory_read_word(memdata, addrbyte + 2 * i, !memdata->no_translation));
28852885                     else
28862886                        len += sprintf(&data[len], " **** ");
r2762r2763
28942894                     if (curaddr > maxaddr)
28952895                        len += sprintf(&data[len], "            ");
28962896                     else if (memdata->raw_base != NULL || memdata->no_translation ||
2897                            cpuinfo->translate == NULL || (*cpuinfo->translate)(memdata->spacenum, &curaddr))
2897                            cpuinfo->translate == NULL || (*cpuinfo->translate)(memdata->spacenum, TRANSLATE_READ_DEBUG, &curaddr))
28982898                        len += sprintf(&data[len], "  %08X  ", memory_read_dword(memdata, addrbyte + 4 * i, !memdata->no_translation));
28992899                     else
29002900                        len += sprintf(&data[len], "  ********  ");
r2762r2763
29082908                     if (curaddr > maxaddr)
29092909                        len += sprintf(&data[len], "                        ");
29102910                     else if (memdata->raw_base != NULL || memdata->no_translation ||
2911                            cpuinfo->translate == NULL || (*cpuinfo->translate)(memdata->spacenum, &curaddr))
2911                            cpuinfo->translate == NULL || (*cpuinfo->translate)(memdata->spacenum, TRANSLATE_READ_DEBUG, &curaddr))
29122912                     {
29132913                        UINT64 qword = memory_read_qword(memdata, addrbyte + 8 * i, !memdata->no_translation);
29142914                        len += sprintf(&data[len], "    %08X%08X    ", (UINT32)(qword >> 32), (UINT32)qword);
src/emu/debug/debugcpu.h
r2762r2763
122122   UINT32         pc_history_index;         /* current history index */
123123   int            hotspot_count;            /* number of hotspots */
124124   int            hotspot_threshhold;         /* threshhold for the number of hits to print */
125   int            (*translate)(int space, offs_t *address);/* address translation routine */
126   int          (*read)(int space, UINT32 offset, int size, UINT64 *value); /* memory read routine */
127   int            (*write)(int space, UINT32 offset, int size, UINT64 value); /* memory write routine */
128   int            (*readop)(UINT32 offset, int size, UINT64 *value);   /* opcode read routine */
125   cpu_translate_func translate;            /* address translation routine */
126   cpu_read_func   read;                   /* memory read routine */
127   cpu_write_func   write;                  /* memory write routine */
128   cpu_readop_func   readop;                  /* opcode read routine */
129129   int            (*instrhook)(offs_t pc);   /* per-instruction callback hook */
130130};
131131
src/emu/debug/debugcmd.c
r2762r2763
14901490               if (i + j <= endoffset)
14911491               {
14921492                  offs_t curaddr = i + j;
1493                  if (!info->translate || (*info->translate)(spacenum, &curaddr))
1493                  if (info->translate == NULL || (*info->translate)(spacenum, TRANSLATE_READ, &curaddr))
14941494                  {
14951495                     UINT8 byte = debug_read_byte(ref, i + j, TRUE);
14961496                     outdex += sprintf(&output[outdex], " %02X", byte);
r2762r2763
15091509               if (i + j <= endoffset)
15101510               {
15111511                  offs_t curaddr = i + j;
1512                  if (!info->translate || (*info->translate)(spacenum, &curaddr))
1512                  if (info->translate == NULL || (*info->translate)(spacenum, TRANSLATE_READ_DEBUG, &curaddr))
15131513                  {
15141514                     UINT16 word = debug_read_word(ref, i + j, TRUE);
15151515                     outdex += sprintf(&output[outdex], " %04X", word);
r2762r2763
15281528               if (i + j <= endoffset)
15291529               {
15301530                  offs_t curaddr = i + j;
1531                  if (!info->translate || (*info->translate)(spacenum, &curaddr))
1531                  if (info->translate == NULL || (*info->translate)(spacenum, TRANSLATE_READ_DEBUG, &curaddr))
15321532                  {
15331533                     UINT32 dword = debug_read_dword(ref, i + j, TRUE);
15341534                     outdex += sprintf(&output[outdex], " %08X", dword);
r2762r2763
15471547               if (i + j <= endoffset)
15481548               {
15491549                  offs_t curaddr = i + j;
1550                  if (!info->translate || (*info->translate)(spacenum, &curaddr))
1550                  if (info->translate == NULL || (*info->translate)(spacenum, TRANSLATE_READ_DEBUG, &curaddr))
15511551                  {
15521552                     UINT64 qword = debug_read_qword(ref, i + j, TRUE);
15531553                     outdex += sprintf(&output[outdex], " %08X%08X", (UINT32)(qword >> 32), (UINT32)qword);
r2762r2763
15681568         for (j = 0; j < 16 && (i + j) <= endoffset; j++)
15691569         {
15701570            offs_t curaddr = i + j;
1571            if (!info->translate || (*info->translate)(spacenum, &curaddr))
1571            if (info->translate == NULL || (*info->translate)(spacenum, TRANSLATE_READ_DEBUG, &curaddr))
15721572            {
15731573               UINT8 byte = debug_read_byte(ref, i + j, TRUE);
15741574               outdex += sprintf(&output[outdex], "%c", (byte >= 32 && byte < 128) ? byte : '.');
r2762r2763
17591759
17601760      /* make sure we can translate the address */
17611761      tempaddr = pcbyte;
1762      if (!info->translate || (*info->translate)(ADDRESS_SPACE_PROGRAM, &tempaddr))
1762      if (info->translate == NULL || (*info->translate)(ADDRESS_SPACE_PROGRAM, TRANSLATE_FETCH_DEBUG, &tempaddr))
17631763      {
17641764         UINT8 opbuf[64], argbuf[64];
17651765
r2762r2763
20632063
20642064   /* do the translation first */
20652065   taddress = ADDR2BYTE_MASKED(address, info, spacenum);
2066   if (info->translate)
2066   if (info->translate != NULL)
20672067   {
2068      if ((*info->translate)(spacenum, &taddress))
2068      if ((*info->translate)(spacenum, TRANSLATE_READ_DEBUG, &taddress))
20692069         debug_console_printf("%08X logical -> %08X physical\n", (UINT32)address, BYTE2ADDR(taddress, info, spacenum));
20702070      else
20712071      {
src/emu/cpu/z180/z180.c
r2762r2763
23382338}
23392339
23402340/* logical to physical address translation */
2341static int z180_translate(int space, offs_t *addr)
2341static int z180_translate(int space, int intention, offs_t *addr)
23422342{
23432343   if (space == ADDRESS_SPACE_PROGRAM)
23442344   {
23452345      *addr = MMU_REMAP_ADDR(*addr);
23462346   }
2347   return 1;
2347   return TRUE;
23482348}
23492349
23502350/**************************************************************************
src/emu/cpu/drcfe.c
r2762r2763
88    Released for general non-commercial use under the MAME license
99    Visit http://mamedev.org for licensing and usage restrictions.
1010
11****************************************************************************
12
13    Future improvements/changes:
14
15    * change from detecting live to detecting unnecessary
16        - at the end of sequence: mustupdate.all = TRUE;
17        - scan backwards:
18            inst.mustupdate = inst.update & mustupdate;
19            if (inst.modified.reg) mustupdate.reg = FALSE;
20            if (inst.used.reg) mustupdate.reg = TRUE;
21
22     * rename UINT64 gpr, fpr to UINT32 reg[4]
23
1124***************************************************************************/
1225
1326#include <stddef.h>
r2762r2763
175188
176189const opcode_desc *drcfe_describe_code(drcfe_state *drcfe, offs_t startpc)
177190{
178   offs_t minpc = startpc - drcfe->window_start;
179   offs_t maxpc = startpc + drcfe->window_end;
191   offs_t minpc = startpc - MIN(drcfe->window_start, startpc);
192   offs_t maxpc = startpc + MIN(drcfe->window_end, 0xffffffff - startpc);
180193   pc_stack_entry pcstack[MAX_STACK_DEPTH];
181194   pc_stack_entry *pcstackptr = &pcstack[0];
182195   opcode_desc **tailptr;
r2762r2763
274287   desc->targetpc = BRANCH_TARGET_DYNAMIC;
275288
276289   /* compute the physical PC */
277   if (drcfe->translate != NULL && !(*drcfe->translate)(ADDRESS_SPACE_PROGRAM, &desc->physpc))
290   if (drcfe->translate != NULL && !(*drcfe->translate)(ADDRESS_SPACE_PROGRAM, TRANSLATE_FETCH, &desc->physpc))
278291   {
279292      /* uh-oh: a page fault; leave the description empty and just if this is the first instruction, leave it empty and */
280293      /* mark as needing to validate; otherwise, just end the sequence here */
src/emu/cpu/drcuml.c
r2762r2763
1818
1919    * Extend registers to 16? Depends on if PPC can use them
2020
21    * Support for FPU exceptions
22
2123    * New instructions?
24        - FDRNDS dst,src
25            round to single-precision
26
27        - FCOPYI, ICOPYF
28            copy raw between float and integer registers
29
2230        - VALID opcode_desc,handle,param
2331            checksum/compare code referenced by opcode_desc; if not
2432            matching, generate exception with handle,param
r2762r2763
226234   OPVALID_ENTRY_3(WRITE8,    8, NONE,  IMV4,  IANY4, IANY)
227235   OPVALID_ENTRY_4(WRIT8M,    8, NONE,  IMV4,  IANY4, IANY,  IANY)
228236   OPVALID_ENTRY_3(FLAGS,   4|8, NONE,  IRM,   IMV,   MEM)
237   OPVALID_ENTRY_2(SETC,    4|8, NONE,  IANY,  IANY)
229238   OPVALID_ENTRY_2(MOV,     4|8, COND,  IRM,   IANY)
230239   OPVALID_ENTRY_2(ZEXT1,   4|8, NONE,  IRM,   IANY4)
231240   OPVALID_ENTRY_2(ZEXT2,   4|8, NONE,  IRM,   IANY4)
r2762r2763
249258   OPVALID_ENTRY_3(OR,      4|8, SZ,    IRM,   IANY,  IANY)
250259   OPVALID_ENTRY_3(XOR,     4|8, SZ,    IRM,   IANY,  IANY)
251260   OPVALID_ENTRY_2(LZCNT,   4|8, NONE,  IRM,   IANY)
261   OPVALID_ENTRY_2(BSWAP,   4|8, NONE,  IRM,   IANY)
252262   OPVALID_ENTRY_3(SHL,     4|8, SZC,   IRM,   IANY,  IANY)
253263   OPVALID_ENTRY_3(SHR,     4|8, SZC,   IRM,   IANY,  IANY)
254264   OPVALID_ENTRY_3(SAR,     4|8, SZC,   IRM,   IANY,  IANY)
src/emu/cpu/drcfe.h
r2762r2763
5656#define OPFLAG_CAN_EXPOSE_EXTERNAL_INT   0x00000040      /* instruction can expose an external interrupt */
5757#define OPFLAG_CAN_CAUSE_EXCEPTION      0x00000080      /* instruction may generate exception */
5858#define OPFLAG_WILL_CAUSE_EXCEPTION      0x00000100      /* instruction will generate exception */
59#define OPFLAG_PRIVILEGED            0x00000200      /* instruction is privileged */
5960
6061/* opcode virtual->physical translation flags */
61#define OPFLAG_VALIDATE_TLB            0x00000200      /* instruction must validate TLB before execution */
62#define OPFLAG_MODIFIES_TRANSLATION      0x00000400      /* instruction modifies the TLB */
63#define OPFLAG_COMPILER_PAGE_FAULT      0x00000800      /* compiler hit a page fault when parsing */
64#define OPFLAG_COMPILER_UNMAPPED      0x00001000      /* compiler hit unmapped memory when parsing */
62#define OPFLAG_VALIDATE_TLB            0x00000400      /* instruction must validate TLB before execution */
63#define OPFLAG_MODIFIES_TRANSLATION      0x00000800      /* instruction modifies the TLB */
64#define OPFLAG_COMPILER_PAGE_FAULT      0x00001000      /* compiler hit a page fault when parsing */
65#define OPFLAG_COMPILER_UNMAPPED      0x00002000      /* compiler hit unmapped memory when parsing */
6566
6667/* opcode flags */
67#define OPFLAG_INVALID_OPCODE         0x00002000      /* instruction is invalid */
68#define OPFLAG_VIRTUAL_NOOP            0x00004000      /* instruction is a virtual no-op */
68#define OPFLAG_INVALID_OPCODE         0x00004000      /* instruction is invalid */
69#define OPFLAG_VIRTUAL_NOOP            0x00008000      /* instruction is a virtual no-op */
6970
7071/* opcode sequence flow flags */
71#define OPFLAG_REDISPATCH            0x00008000      /* instruction must redispatch after completion */
72#define OPFLAG_RETURN_TO_START         0x00010000      /* instruction must jump back to the beginning after completion */
73#define OPFLAG_END_SEQUENCE            0x00020000      /* this is the last instruction in a sequence */
74#define OPFLAG_CAN_CHANGE_MODES         0x00040000      /* instruction can change modes */
72#define OPFLAG_REDISPATCH            0x00010000      /* instruction must redispatch after completion */
73#define OPFLAG_RETURN_TO_START         0x00020000      /* instruction must jump back to the beginning after completion */
74#define OPFLAG_END_SEQUENCE            0x00040000      /* this is the last instruction in a sequence */
75#define OPFLAG_CAN_CHANGE_MODES         0x00080000      /* instruction can change modes */
7576
7677/* execution semantics */
7778#define OPFLAG_READS_MEMORY            0x00080000      /* instruction reads memory */
src/emu/cpu/drcuml.h
r2762r2763
208208   DRCUML_OP_WRIT4M,      /* WRIT4M  space,dst,mask,src1    */
209209   DRCUML_OP_WRITE8,      /* WRITE8  space,dst,src1         */
210210   DRCUML_OP_WRIT8M,      /* WRIT8M  space,dst,mask,src1    */
211   DRCUML_OP_SETC,         /* SETC    src,bitnum             */
211212   DRCUML_OP_FLAGS,      /* FLAGS   dst,mask,table         */
212213   DRCUML_OP_MOV,         /* MOV     dst,src[,c]            */
213214   DRCUML_OP_ZEXT1,      /* ZEXT1   dst,src                */
r2762r2763
232233   DRCUML_OP_OR,         /* OR      dst,src1,src2[,f]      */
233234   DRCUML_OP_XOR,         /* XOR     dst,src1,src2[,f]      */
234235   DRCUML_OP_LZCNT,      /* LZCNT   dst,src                */
236   DRCUML_OP_BSWAP,      /* BSWAP   dst,src                */
235237   DRCUML_OP_SHL,         /* SHL     dst,src,count[,f]      */
236238   DRCUML_OP_SHR,         /* SHR     dst,src,count[,f]      */
237239   DRCUML_OP_SAR,         /* SAR     dst,src,count[,f]      */
src/emu/cpu/i386/i386.c
r2762r2763
729729
730730/*************************************************************************/
731731
732static int translate_address_cb(int space, offs_t *addr)
732static int translate_address_cb(int space, int intention, offs_t *addr)
733733{
734734   int result = 1;
735735   if (space == ADDRESS_SPACE_PROGRAM)
src/emu/cpu/drcbex64.c
r2762r2763
428428static x86code *op_write8(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
429429static x86code *op_writ8m(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
430430static x86code *op_flags(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
431static x86code *op_setc(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
431432static x86code *op_mov(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
432433static x86code *op_zext1(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
433434static x86code *op_zext2(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
r2762r2763
451452static x86code *op_or(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
452453static x86code *op_xor(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
453454static x86code *op_lzcnt(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
455static x86code *op_bswap(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
454456static x86code *op_shl(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
455457static x86code *op_shr(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
456458static x86code *op_sar(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
r2762r2763
546548   { DRCUML_OP_WRITE8,  op_write8 },   /* WRITE8  space,dst,src1         */
547549   { DRCUML_OP_WRIT8M,  op_writ8m },   /* WRIT8M  space,dst,mask,src1    */
548550   { DRCUML_OP_FLAGS,   op_flags },   /* FLAGS   dst,mask,table         */
551   { DRCUML_OP_SETC,    op_setc },      /* FLAGS   src,bitnum             */
549552   { DRCUML_OP_MOV,     op_mov },      /* MOV     dst,src[,c]            */
550553   { DRCUML_OP_ZEXT1,   op_zext1 },   /* ZEXT1   dst,src                */
551554   { DRCUML_OP_ZEXT2,   op_zext2 },   /* ZEXT2   dst,src                */
r2762r2763
569572   { DRCUML_OP_OR,      op_or },      /* OR      dst,src1,src2[,f]      */
570573   { DRCUML_OP_XOR,     op_xor },      /* XOR     dst,src1,src2[,f]      */
571574   { DRCUML_OP_LZCNT,   op_lzcnt },   /* LZCNT   dst,src[,f]            */
575   { DRCUML_OP_BSWAP,   op_bswap },   /* BSWAP   dst,src                */
572576   { DRCUML_OP_SHL,     op_shl },      /* SHL     dst,src,count[,f]      */
573577   { DRCUML_OP_SHR,     op_shr },      /* SHR     dst,src,count[,f]      */
574578   { DRCUML_OP_SAR,     op_sar },      /* SAR     dst,src,count[,f]      */
r2762r2763
48184822
48194823
48204824/*-------------------------------------------------
4825    op_setc - process a SETC opcode
4826-------------------------------------------------*/
4827
4828static x86code *op_setc(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
4829{
4830   drcuml_parameter srcp, bitp;
4831
4832   /* validate instruction */
4833   assert(inst->size == 4 || inst->size == 8);
4834   assert(inst->condflags == DRCUML_COND_ALWAYS);
4835
4836   /* normalize parameters */
4837   param_normalize_2(drcbe, inst, &srcp, PTYPE_MRI, &bitp, PTYPE_MRI);
4838
4839   /* degenerate case: source is immediate */
4840   if (srcp.type == DRCUML_PTYPE_IMMEDIATE && bitp.type == DRCUML_PTYPE_IMMEDIATE)
4841   {
4842      if (srcp.value & ((UINT64)1 << bitp.value))
4843         emit_stc(&dst);
4844      else
4845         emit_clc(&dst);
4846      return dst;
4847   }
4848
4849   /* load non-immediate bit numbers into a register */
4850   if (bitp.type != DRCUML_PTYPE_IMMEDIATE)
4851   {
4852      emit_mov_r32_p32(drcbe, &dst, REG_ECX, &bitp);
4853      emit_and_r32_imm(&dst, REG_ECX, inst->size * 8 - 1);
4854   }
4855
4856   /* 32-bit form */
4857   if (inst->size == 4)
4858   {
4859      if (bitp.type == DRCUML_PTYPE_IMMEDIATE)
4860      {
4861         if (srcp.type == DRCUML_PTYPE_MEMORY)
4862            emit_bt_m32_imm(&dst, MABS(srcp.value), bitp.value);               // bt     [srcp],bitp
4863         else if (srcp.type == DRCUML_PTYPE_INT_REGISTER)
4864            emit_bt_r32_imm(&dst, srcp.value, bitp.value);                     // bt     srcp,bitp
4865      }
4866      else
4867      {
4868         if (srcp.type == DRCUML_PTYPE_MEMORY)
4869            emit_bt_m32_r32(&dst, MABS(srcp.value), REG_ECX);                  // bt     [srcp],ecx
4870         else if (srcp.type == DRCUML_PTYPE_INT_REGISTER)
4871            emit_bt_r32_r32(&dst, srcp.value, REG_ECX);                        // bt     srcp,ecx
4872      }
4873   }
4874
4875   /* 64-bit form */
4876   else
4877   {
4878      if (bitp.type == DRCUML_PTYPE_IMMEDIATE)
4879      {
4880         if (srcp.type == DRCUML_PTYPE_MEMORY)
4881            emit_bt_m64_imm(&dst, MABS(srcp.value), bitp.value);               // bt     [srcp],bitp
4882         else if (srcp.type == DRCUML_PTYPE_INT_REGISTER)
4883            emit_bt_r64_imm(&dst, srcp.value, bitp.value);                     // bt     srcp,bitp
4884      }
4885      else
4886      {
4887         if (srcp.type == DRCUML_PTYPE_MEMORY)
4888            emit_bt_m64_r64(&dst, MABS(srcp.value), REG_ECX);                  // bt     [srcp],ecx
4889         else if (srcp.type == DRCUML_PTYPE_INT_REGISTER)
4890            emit_bt_r64_r64(&dst, srcp.value, REG_ECX);                        // bt     srcp,ecx
4891      }
4892   }
4893   return dst;
4894}
4895
4896
4897/*-------------------------------------------------
48214898    op_mov - process a MOV opcode
48224899-------------------------------------------------*/
48234900
r2762r2763
62716348
62726349
62736350/*-------------------------------------------------
6351    op_bswap - process a BSWAP opcode
6352-------------------------------------------------*/
6353
6354static x86code *op_bswap(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
6355{
6356   drcuml_parameter dstp, srcp;
6357   int dstreg;
6358
6359   /* validate instruction */
6360   assert(inst->size == 4 || inst->size == 8);
6361   assert(inst->condflags == 0);
6362
6363   /* normalize parameters */
6364   param_normalize_2(drcbe, inst, &dstp, PTYPE_MR, &srcp, PTYPE_MRI);
6365
6366   /* degenerate cases -- convert to a move */
6367   if (srcp.type == DRCUML_PTYPE_IMMEDIATE && inst->condflags == 0)
6368   {
6369      if (inst->size == 4)
6370         return convert_to_mov_imm(drcbe, dst, inst, &dstp, FLIPENDIAN_INT32(srcp.value));
6371      else if (inst->size == 8)
6372         return convert_to_mov_imm(drcbe, dst, inst, &dstp, FLIPENDIAN_INT64(srcp.value));
6373   }
6374
6375   /* pick a target register for the general case */
6376   dstreg = param_select_register(REG_RAX, &dstp, &srcp);
6377
6378   /* 32-bit form */
6379   if (inst->size == 4)
6380   {
6381      emit_mov_r32_p32(drcbe, &dst, dstreg, &srcp);                           // mov   dstreg,src1p
6382      emit_bswap_r32(&dst, dstreg);                                       // bswap dstreg
6383      emit_mov_p32_r32(drcbe, &dst, &dstp, dstreg);                           // mov   dstp,dstreg
6384   }
6385
6386   /* 64-bit form */
6387   else if (inst->size == 8)
6388   {
6389      emit_mov_r64_p64(drcbe, &dst, dstreg, &srcp);                           // mov   dstreg,src1p
6390      emit_bswap_r64(&dst, dstreg);                                       // bswap dstreg
6391      emit_mov_p64_r64(drcbe, &dst, &dstp, dstreg);                           // mov   dstp,dstreg
6392   }
6393   return dst;
6394}
6395
6396
6397/*-------------------------------------------------
62746398    op_shl - process a SHL opcode
62756399-------------------------------------------------*/
62766400
src/emu/cpu/drcbec.c
r2762r2763
720720            PARAM0 = (PARAM0 & ~PARAM1) | (inst[2].puint32[flags & 0x1f] & PARAM1);
721721            break;
722722
723         case MAKE_OPCODE_SHORT(DRCUML_OP_SETC, 4, 0):      /* SETC    src,bitnum             */
724            flags = (flags & ~DRCUML_FLAG_C) | ((PARAM0 >> (PARAM1 & 31)) & DRCUML_FLAG_C);
725            break;
726
723727         case MAKE_OPCODE_SHORT(DRCUML_OP_MOV, 4, 1):      /* MOV     dst,src[,c]            */
724728            if (OPCODE_FAIL_CONDITION(opcode, flags))
725729               break;
r2762r2763
905909            PARAM0 = temp32;
906910            break;
907911
908         case MAKE_OPCODE_SHORT(DRCUML_OP_LZCNT, 4, 0):      /* LZCNT   dst,src[,f]            */
912         case MAKE_OPCODE_SHORT(DRCUML_OP_LZCNT, 4, 0):      /* LZCNT   dst,src                */
909913            PARAM0 = count_leading_zeros(PARAM1);
910914            break;
911915
912         case MAKE_OPCODE_SHORT(DRCUML_OP_LZCNT, 4, 1):
913            temp32 = count_leading_zeros(PARAM1);
914            flags = (temp32 == 0) ? DRCUML_FLAG_Z : 0;
915            PARAM0 = temp32;
916         case MAKE_OPCODE_SHORT(DRCUML_OP_BSWAP, 4, 0):      /* BSWAP   dst,src                */
917            temp32 = PARAM1;
918            PARAM0 = FLIPENDIAN_INT32(temp32);
916919            break;
917920
918921         case MAKE_OPCODE_SHORT(DRCUML_OP_SHL, 4, 0):      /* SHL     dst,src,count[,f]      */
r2762r2763
11381141            DPARAM0 = (DPARAM0 & ~DPARAM1) | (inst[2].puint64[flags & 0x0f] & DPARAM1);
11391142            break;
11401143
1144         case MAKE_OPCODE_SHORT(DRCUML_OP_SETC, 8, 0):      /* DSETC   src,bitnum             */
1145            flags = (flags & ~DRCUML_FLAG_C) | ((DPARAM0 >> (DPARAM1 & 63)) & DRCUML_FLAG_C);
1146            break;
1147
11411148         case MAKE_OPCODE_SHORT(DRCUML_OP_MOV, 8, 1):      /* DMOV    dst,src[,c]            */
11421149            if (OPCODE_FAIL_CONDITION(opcode, flags))
11431150               break;
r2762r2763
13211328            DPARAM0 = temp64;
13221329            break;
13231330
1324         case MAKE_OPCODE_SHORT(DRCUML_OP_LZCNT, 8, 0):      /* DLZCNT  dst,src[,f]            */
1331         case MAKE_OPCODE_SHORT(DRCUML_OP_LZCNT, 8, 0):      /* DLZCNT  dst,src                */
13251332            if ((UINT32)(DPARAM1 >> 32) != 0)
13261333               DPARAM0 = count_leading_zeros(DPARAM1 >> 32);
13271334            else
13281335               DPARAM0 = 32 + count_leading_zeros(DPARAM1);
13291336            break;
13301337
1331         case MAKE_OPCODE_SHORT(DRCUML_OP_LZCNT, 8, 1):
1332            if ((UINT32)(DPARAM1 >> 32) != 0)
1333               temp32 = count_leading_zeros(DPARAM1 >> 32);
1334            else
1335               temp32 = 32 + count_leading_zeros(DPARAM1);
1336            flags = (temp32 == 0) ? DRCUML_FLAG_Z : 0;
1337            DPARAM0 = temp32;
1338         case MAKE_OPCODE_SHORT(DRCUML_OP_BSWAP, 8, 0):      /* DBSWAP  dst,src                */
1339            temp64 = DPARAM1;
1340            DPARAM0 = FLIPENDIAN_INT64(temp64);
13381341            break;
13391342
13401343         case MAKE_OPCODE_SHORT(DRCUML_OP_SHL, 8, 0):      /* DSHL    dst,src,count[,f]      */
src/emu/cpu/cop400/cop420ds.c
r2762r2763
216216         {
217217            sprintf(buffer, "LEI %u", next_opcode & 0xF);
218218         }
219         else if (next_opcode >= 0x81 && next_opcode <= 0x88)
219         else if (next_opcode >= 0x80 && next_opcode <= 0x8F)
220220         {
221221            sprintf(buffer, "LBI 0,%u", next_opcode & 0xF);
222222         }
223         else if (next_opcode >= 0x91 && next_opcode <= 0x98)
223         else if (next_opcode >= 0x90 && next_opcode <= 0x9F)
224224         {
225225            sprintf(buffer, "LBI 1,%u", next_opcode & 0xF);
226226         }
227         else if (next_opcode >= 0xA1 && next_opcode <= 0xA8)
227         else if (next_opcode >= 0xA0 && next_opcode <= 0xAF)
228228         {
229229            sprintf(buffer, "LBI 2,%u", next_opcode & 0xF);
230230         }
231         else if (next_opcode >= 0xB1 && next_opcode <= 0xB8)
231         else if (next_opcode >= 0xB0 && next_opcode <= 0xBF)
232232         {
233233            sprintf(buffer, "LBI 3,%u", next_opcode & 0xF);
234234         }
r2762r2763
236236         {
237237            switch (next_opcode)
238238            {
239            case 0x00:
240               sprintf(buffer, "INIL");
241               break;
242
243239            case 0x01:
244240               sprintf(buffer, "SKGBZ 0");
245241               break;
r2762r2763
264260               sprintf(buffer, "ININ");
265261               break;
266262
263            case 0x29:
264               sprintf(buffer, "INIL");
265               break;
266
267267            case 0x2A:
268268               sprintf(buffer, "ING");
269269               break;
src/emu/cpu/cop400/410ops.c
r2762r2763
3535
3636#define IN_G()         IN(COP400_PORT_G)
3737#define IN_L()         IN(COP400_PORT_L)
38#define IN_SI()         IN(COP400_PORT_SIO)
38#define IN_SI()         BIT(IN(COP400_PORT_SIO), 0)
39#define IN_CKO()      BIT(IN(COP400_PORT_CKO), 0)
3940#define OUT_G(A)      OUT(COP400_PORT_G, (A) & R.G_mask)
4041#define OUT_L(A)      OUT(COP400_PORT_L, (A))
4142#define OUT_D(A)      OUT(COP400_PORT_D, (A) & R.D_mask)
r2762r2763
5758
5859   if (BIT(EN, 0))
5960   {
60      /* SIO is a binary counter */
61      /*
6162
62      // serial input
63            SIO is an asynchronous binary counter decrementing its value by one upon each low-going pulse ("1" to "0") occurring on the SI input.
64            Each pulse must remain at each logic level at least two instruction cycles. SK outputs the value of the C upon the execution of an XAS
65            and remains latched until the execution of another XAS instruction. The SO output is equal to the value of EN3.
6366
64      int si = IN_SI();
67      */
6568
66      if (R.last_si && !si)
67      {
68         SIO--;
69         SIO &= 0x0f;
70      }
71
72      R.last_si = si;
73
7469      // serial output
7570
7671      OUT_SO(BIT(EN, 3));
r2762r2763
7873      // serial clock
7974
8075      OUT_SK(SKL);
76
77      // serial input
78
79      R.si <<= 1;
80      R.si = (R.si & 0x0e) | IN_SI();
81
82      if ((R.si & 0x0f) == 0x0c) // 1100
83      {
84         SIO--;
85         SIO &= 0x0f;
86      }
8187   }
8288   else
8389   {
84      /* SIO is a shift register */
90      /*
8591
92            SIO is a serial shift register, shifting continuously left each instruction cycle time. The data present at SI goes into the least
93            significant bit of SIO: SO can be enabled to output the most significant bit of SIO each cycle time. SK output becomes a logic-
94            controlled clock, providing a SYNC signal each instruction time. It will start outputting a SYNC pulse upon the execution of an XAS
95            instruction with C = "1," stopping upon the execution of a subsequent XAS with C = "0".
96
97            If EN0 is changed from "1" to "0" ("0" to "1") the SK output will change from "1" to SYNC (SYNC to "1") without the execution of
98            an XAS instruction.
99
100        */
101
86102      // serial output
87103
88104      if (BIT(EN, 3))
r2762r2763
94110         OUT_SO(0);
95111      }
96112
97      SIO <<= 1;
98
99      // serial input
100
101      SIO = (SIO & 0x0e) | BIT(IN_SI(), 0);
102
103113      // serial clock
104114
105115      if (SKL)
106116      {
107         OUT_SK(1);
117         OUT_SK(1); // SYNC
108118      }
109119      else
110120      {
111121         OUT_SK(0);
112122      }
123
124      // serial input
125
126      SIO = ((SIO << 1) | IN_SI()) & 0x0f;
113127   }
114128
115129   cpuintrf_pop_context();
r2762r2763
403417   {
404418      // JSRP
405419      UINT8 a = opcode & 0x3f;
406      PUSH(PC + 1);
420      PUSH(PC);
407421      PC = 0x80 | a;
408422   }
409423}
r2762r2763
530544
531545INSTRUCTION(lqid)
532546{
533   PUSH(PC + 1);
547   PUSH(PC);
534548   PC = (PC & 0x300) | (A << 4) | RAM_R(B);
535549   WRITE_Q(ROM(PC));
536550   POP();
src/emu/cpu/cop400/cop410.c
r2762r2763
1414    TODO:
1515
1616    - remove LBIops
17    - JP/JSR/JSRP
17    - run all test suites
1818
1919*/
2020
r2762r2763
4949   UINT8   skip, skipLBI;
5050   UINT8   G_mask;
5151   UINT8   D_mask;
52   int      last_si;
52   UINT8   si;
5353} COP410_Regs;
5454
5555static COP410_Regs R;
r2762r2763
162162   {1, lbi         },{1, lbi      },{1, lbi      },{1, lbi         },{1, lbi      },{1, lbi      },{1, lbi      },{1, lbi      },
163163   {0, illegal      },{1, skmbz1   },{0, illegal   },{1, skmbz3      },{1, xis      },{1, ld      },{1, x         },{1, xds      },
164164   {1, lbi         },{1, lbi      },{1, lbi      },{1, lbi         },{1, lbi      },{1, lbi      },{1, lbi      },{1, lbi      },
165   {1, skc         },{1, ske      },{1, sc      },{2, cop410_op23   },{1, xis      },{1, ld      },{1, x         },{1, xds       },
165   {1, skc         },{1, ske      },{1, sc      },{1, cop410_op23   },{1, xis      },{1, ld      },{1, x         },{1, xds       },
166166   {1, lbi         },{1, lbi      },{1, lbi      },{1, lbi         },{1, lbi      },{1, lbi      },{1, lbi      },{1, lbi      },
167   {1, asc         },{1, add      },{1, rc      },{2, cop410_op33   },{1, xis      },{1, ld      },{1, x         },{1, xds      },
167   {1, asc         },{1, add      },{1, rc      },{1, cop410_op33   },{1, xis      },{1, ld      },{1, x         },{1, xds      },
168168   {1, lbi         },{1, lbi      },{1, lbi      },{1, lbi         },{1, lbi      },{1, lbi      },{1, lbi      },{1, lbi      },
169169
170170   {1, comp      },{0, illegal   },{1, rmb2      },{1, rmb3         },{1, nop      },{1, rmb1      },{1, smb2      },{1, smb1      },
r2762r2763
245245   state_save_register_item("cop410", index, skipLBI);
246246   state_save_register_item("cop410", index, R.G_mask);
247247   state_save_register_item("cop410", index, R.D_mask);
248   state_save_register_item("cop410", index, R.last_si);
248   state_save_register_item("cop410", index, R.si);
249249}
250250
251251static void cop411_init(int index, int clock, const void *config, int (*irqcallback)(int))
src/emu/cpu/cop400/420ops.c
r2762r2763
230230    Hex Code:           33 29
231231    Binary:
232232
233    Data Flow:          IL3,"1","0",IL0 -> A
233    Data Flow:          IL3,CKO,"0",IL0 -> A
234234
235235    Description:        Input IL Latches to A
236236
r2762r2763
238238
239239INSTRUCTION(inil)
240240{
241   // NOT PROPERLY IMPLEMENTED
241   A = (IL & 0x09) | IN_CKO() << 2;
242242
243   A = (IN_IN() & 0x09) | 0x04;
243   IL = 0;
244244}
245245
246246/*
r2762r2763
260260
261261INSTRUCTION(cop421_inil)
262262{
263   // NOT PROPERLY IMPLEMENTED
264
265   A = 0;
263   A = IN_CKO() << 2;
266264}
267265
268266/*
src/emu/cpu/cop400/cop420.c
r2762r2763
1313
1414    TODO:
1515
16    - run interrupt test suite
17    - run production test suite
1618    - remove LBIops
17    - INIL
1819
1920*/
2021
r2762r2763
5253   UINT8   G_mask;
5354   UINT8   D_mask;
5455   UINT4   IL;
55   int      last_si;
56   UINT4   in[4];
57   UINT8   si;
5658   int      last_skip;
5759} COP420_Regs;
5860
r2762r2763
6567
6668static emu_timer *cop420_serial_timer;
6769static emu_timer *cop420_counter_timer;
70static emu_timer *cop420_inil_timer;
6871
6972#include "420ops.c"
7073
r2762r2763
118121
119122static const s_opcode opcode_33_map[256]=
120123{
121   {1, inil       },{1, skgbz0    },{1, illegal    },{1, skgbz2    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },
124   {1, illegal      },{1, skgbz0    },{1, illegal    },{1, skgbz2    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },
122125   {1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },
123126   {1, illegal    },{1, skgbz1    },{1, illegal    },{1, skgbz3    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },
124127   {1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },
125128   {1, illegal    },{1, skgz       },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },
126   {1, inin       },{1, illegal    },{1, ing       },{1, illegal    },{1, cqma       },{1, illegal    },{1, inl       },{1, illegal    },
129   {1, inin       },{1, inil       },{1, ing       },{1, illegal    },{1, cqma       },{1, illegal    },{1, inl       },{1, illegal    },
127130   {1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },
128131   {1, illegal    },{1, illegal    },{1, omg       },{1, illegal    },{1, camq       },{1, illegal    },{1, obd       },{1, illegal    },
129132
r2762r2763
136139   {1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },
137140   {1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },
138141
139   {1, illegal    },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },
140   {1, lbi          },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },
141   {1, illegal    },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },
142   {1, lbi          },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },
143   {1, illegal    },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },
144   {1, lbi          },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },
145   {1, illegal    },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },
146   {1, lbi          },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },
142   {1, lbi          },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },
143   {1, lbi          },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },
144   {1, lbi          },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },
145   {1, lbi          },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },
146   {1, lbi          },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },
147   {1, lbi          },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },
148   {1, lbi          },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },
149   {1, lbi          },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },{1, lbi       },
147150
148151   {1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },
149152   {1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },{1, illegal    },
r2762r2763
168171   {1, lbi         },{1, lbi      },{1, lbi      },{1, lbi         },{1, lbi      },{1, lbi      },{1, lbi      },{1, lbi      },
169172   {1, casc      },{1, skmbz1   },{1, xabr      },{1, skmbz3      },{1, xis      },{1, ld      },{1, x         },{1, xds      },
170173   {1, lbi         },{1, lbi      },{1, lbi      },{1, lbi         },{1, lbi      },{1, lbi      },{1, lbi      },{1, lbi      },
171   {1, skc         },{1, ske      },{1, sc      },{2, cop420_op23   },{1, xis      },{1, ld      },{1, x         },{1, xds       },
174   {1, skc         },{1, ske      },{1, sc      },{1, cop420_op23   },{1, xis      },{1, ld      },{1, x         },{1, xds       },
172175   {1, lbi         },{1, lbi      },{1, lbi      },{1, lbi         },{1, lbi      },{1, lbi      },{1, lbi      },{1, lbi      },
173   {1, asc         },{1, add      },{1, rc      },{2, cop420_op33     },{1, xis      },{1, ld      },{1, x         },{1, xds      },
176   {1, asc         },{1, add      },{1, rc      },{1, cop420_op33     },{1, xis      },{1, ld      },{1, x         },{1, xds      },
174177   {1, lbi         },{1, lbi      },{1, lbi      },{1, lbi         },{1, lbi      },{1, lbi      },{1, lbi      },{1, lbi      },
175178
176179   {1, comp      },{1, skt      },{1, rmb2      },{1, rmb3         },{1, nop      },{1, rmb1      },{1, smb2      },{1, smb1      },
r2762r2763
232235   }
233236}
234237
238/* IN Latches */
239
240static TIMER_CALLBACK(cop420_inil_tick)
241{
242   UINT8 in = IN_IN();
243   int i;
244
245   for (i = 0; i < 4; i++)
246   {
247      R.in[i] = (R.in[i] << 1) | BIT(in, i);
248
249      if ((R.in[i] & 0x07) == 0x04) // 100
250      {
251         IL |= (1 << i);
252      }
253   }
254}
255
235256/****************************************************************************
236257 * Initialize emulation
237258 ****************************************************************************/
r2762r2763
247268   timer_adjust_periodic(cop420_serial_timer, attotime_zero, index, ATTOTIME_IN_HZ(clock));
248269
249270   cop420_counter_timer = timer_alloc(cop420_counter_tick, NULL);
250   timer_adjust_periodic(cop420_counter_timer, attotime_zero, index, ATTOTIME_IN_HZ(clock / 1024));
271   timer_adjust_periodic(cop420_counter_timer, attotime_zero, index, ATTOTIME_IN_HZ(clock));
251272
273   cop420_inil_timer = timer_alloc(cop420_inil_tick, NULL);
274   timer_adjust_periodic(cop420_inil_timer, attotime_zero, index, ATTOTIME_IN_HZ(clock));
275
252276   for (i=0; i<256; i++) InstLen[i]=1;
253277
254278   InstLen[0x60] = InstLen[0x61] = InstLen[0x62] = InstLen[0x63] =
r2762r2763
262286   for (i=0x38; i<0x40; i++) LBIops[i] = 1;
263287
264288   for (i=0; i<256; i++) LBIops33[i] = 0;
265   for (i=0x81; i<0x89; i++) LBIops33[i] = 1;
266   for (i=0x91; i<0x99; i++) LBIops33[i] = 1;
267   for (i=0xa1; i<0xa9; i++) LBIops33[i] = 1;
268   for (i=0xb1; i<0xb9; i++) LBIops33[i] = 1;
289   for (i=0x80; i<0xc0; i++) LBIops33[i] = 1;
269290
270291   state_save_register_item("cop420", index, PC);
271292   state_save_register_item("cop420", index, R.PREVPC);
r2762r2763
286307   state_save_register_item("cop420", index, R.counter);
287308   state_save_register_item("cop420", index, R.G_mask);
288309   state_save_register_item("cop420", index, R.D_mask);
289   state_save_register_item("cop420", index, R.last_si);
310   state_save_register_item("cop420", index, R.si);
290311   state_save_register_item("cop420", index, R.last_skip);
312   state_save_register_item_array("cop420", index, R.in);
291313}
292314
293315static void cop422_init(int index, int clock, const void *config, int (*irqcallback)(int))
r2762r2763
373395
374396         // check for interrupt
375397
376         if (BIT(EN, 1))
398         if (BIT(EN, 1) && BIT(IL, 1))
377399         {
378            UINT8 in = IN_IN();
400            void *function = opcode_map[ROM(PC)].function;
379401
380            if (BIT(IL, 1) && !BIT(in, 1))
402            if ((function != jp) &&   (function != jmp) && (function != jsr))
381403            {
382               void *function = opcode_map[ROM(PC)].function;
404               // store skip logic
405               R.last_skip = skip;
406               skip = 0;
383407
384               if ((function != jp) &&   (function != jmp) && (function != jsr))
385               {
386                  // store skip logic
387                  R.last_skip = skip;
388                  skip = 0;
408               // push next PC
409               PUSH(PC + 1);
389410
390                  // push next PC
391                  PUSH(PC + 1);
411               // jump to interrupt service routine
412               PC = 0x0ff;
392413
393                  // jump to interrupt service routine
394                  PC = 0x0ff;
395
396                  // disable interrupt
397                  EN &= ~0x02;
398               }
414               // disable interrupt
415               EN &= ~0x02;
399416            }
400417
401            IL = in;
418            IL &= ~2;
402419         }
403420
404421         // skip next instruction?
src/emu/cpu/cop400/cop400.h
r2762r2763
1818#define   COP400_PORT_IN   0x103
1919#define   COP400_PORT_SK   0x104
2020#define   COP400_PORT_SIO   0x105
21#define   COP400_PORT_CKO   0x106
2122
2223enum {
2324   COP400_PC=1,
src/emu/cpu/m6502/m4510.c
r2762r2763
371371   AM_RANGE(0x0000, 0x0001) AM_READWRITE(m4510_read_0000, m4510_write_0000)
372372ADDRESS_MAP_END
373373
374static int m4510_translate(int space, offs_t *addr)
374static int m4510_translate(int space, int intention, offs_t *addr)
375375{
376376   if (space == ADDRESS_SPACE_PROGRAM)
377377      *addr = M4510_MEM(*addr);
378   return 1;
378   return TRUE;
379379}
380380
381381/**************************************************************************
src/emu/cpu/powerpc/ppc_mem.c
r2762r2763
297297}
298298
299299#if (HAS_PPC602||HAS_PPC603)
300static int ppc_translate_address_cb(int space, offs_t *addr)
300static int ppc_translate_address_cb(int space, int intention, offs_t *addr)
301301{
302302   int success = 1;
303303
src/emu/cpu/drcumlsh.h
r2762r2763
151151#define UML_READ1S(block, dst, space, src1)               do { drcuml_block_append_3(block, DRCUML_OP_READ1S,  4, IF_ALWAYS,  dst, IMM(ADDRESS_SPACE_##space), src1); } while (0)
152152#define UML_READ2U(block, dst, space, src1)               do { drcuml_block_append_3(block, DRCUML_OP_READ2U,  4, IF_ALWAYS,  dst, IMM(ADDRESS_SPACE_##space), src1); } while (0)
153153#define UML_READ2S(block, dst, space, src1)               do { drcuml_block_append_3(block, DRCUML_OP_READ2S,  4, IF_ALWAYS,  dst, IMM(ADDRESS_SPACE_##space), src1); } while (0)
154#define UML_READ2M(block, dst, space, src1, mask)         do { drcuml_block_append_4(block, DRCUML_OP_READ2M,  4, IF_ALWAYS,  dst, IMM(ADDRESS_SPACE_##space), src1, mask); } while (0)
154155#define UML_READ4(block, dst, space, src1)               do { drcuml_block_append_3(block, DRCUML_OP_READ4U,  4, IF_ALWAYS,  dst, IMM(ADDRESS_SPACE_##space), src1); } while (0)
155156#define UML_READ4M(block, dst, space, src1, mask)         do { drcuml_block_append_4(block, DRCUML_OP_READ4M,  4, IF_ALWAYS,  dst, IMM(ADDRESS_SPACE_##space), src1, mask); } while (0)
156157
157158#define UML_WRITE1(block, space, dst, src1)               do { drcuml_block_append_3(block, DRCUML_OP_WRITE1,  4, IF_ALWAYS,  IMM(ADDRESS_SPACE_##space), dst, src1); } while (0)
158159#define UML_WRITE2(block, space, dst, src1)               do { drcuml_block_append_3(block, DRCUML_OP_WRITE2,  4, IF_ALWAYS,  IMM(ADDRESS_SPACE_##space), dst, src1); } while (0)
160#define UML_WRIT2M(block, space, dst, mask, src1)         do { drcuml_block_append_4(block, DRCUML_OP_WRIT2M,  4, IF_ALWAYS,  IMM(ADDRESS_SPACE_##space), dst, mask, src1); } while (0)
159161#define UML_WRITE4(block, space, dst, src1)               do { drcuml_block_append_3(block, DRCUML_OP_WRITE4,  4, IF_ALWAYS,  IMM(ADDRESS_SPACE_##space), dst, src1); } while (0)
160162#define UML_WRIT4M(block, space, dst, mask, src1)         do { drcuml_block_append_4(block, DRCUML_OP_WRIT4M,  4, IF_ALWAYS,  IMM(ADDRESS_SPACE_##space), dst, mask, src1); } while (0)
161163
162164#define UML_FLAGS(block, dst, mask, table)               do { drcuml_block_append_3(block, DRCUML_OP_FLAGS,   4, IF_ALWAYS,  dst, IMM(mask), MEM(table)); } while (0)
165#define UML_SETC(block, src, bitnum)                  do { drcuml_block_append_2(block, DRCUML_OP_SETC,    4, IF_ALWAYS,  src, bitnum); } while (0)
163166
164167#define UML_MOV(block, dst, src1)                     do { drcuml_block_append_2(block, DRCUML_OP_MOV,     4, IF_ALWAYS,  dst, src1); } while (0)
165168#define UML_MOVc(block, cond, dst, src1)               do { drcuml_block_append_2(block, DRCUML_OP_MOV,     4, cond,       dst, src1); } while (0)
r2762r2763
211214#define UML_XOR(block, dst, src1, src2)                  do { drcuml_block_append_3(block, DRCUML_OP_XOR,     4, FLAGS_NONE, dst, src1, src2); } while (0)
212215#define UML_XORf(block, dst, src1, src2, flags)            do { drcuml_block_append_3(block, DRCUML_OP_XOR,     4, flags,      dst, src1, src2); } while (0)
213216
217#define UML_LZCNT(block, dst, src)                     do { drcuml_block_append_2(block, DRCUML_OP_LZCNT,   4, FLAGS_NONE, dst, src); } while (0)
218#define UML_BSWAP(block, dst, src)                     do { drcuml_block_append_2(block, DRCUML_OP_BSWAP,   4, FLAGS_NONE, dst, src); } while (0)
219
214220#define UML_SHL(block, dst, src, count)                  do { drcuml_block_append_3(block, DRCUML_OP_SHL,     4, FLAGS_NONE, dst, src, count); } while (0)
215221#define UML_SHLf(block, dst, src, count, flags)            do { drcuml_block_append_3(block, DRCUML_OP_SHL,     4, flags,      dst, src, count); } while (0)
216222
src/emu/cpu/mips/mips3com.h
r2762r2763
2222#define MIPS3_MIN_PAGE_SIZE         (1 << MIPS3_MIN_PAGE_SHIFT)
2323#define MIPS3_MIN_PAGE_MASK         (MIPS3_MIN_PAGE_SIZE - 1)
2424#define MIPS3_MAX_PADDR_SHIFT      32
25#define MIPS3_TLB_ENTRIES         48
2526
2627/* cycle parameters */
2728#define MIPS3_COUNT_READ_CYCLES      250
r2762r2763
159160    STRUCTURES & TYPEDEFS
160161***************************************************************************/
161162
162/* memory access function table */
163typedef struct _memory_accessors memory_accessors;
164struct _memory_accessors
165{
166   UINT8         (*readbyte)(offs_t);
167   UINT16         (*readhalf)(offs_t);
168   UINT32         (*readword)(offs_t);
169   UINT32         (*readword_masked)(offs_t, UINT32);
170   UINT64         (*readdouble)(offs_t);
171   UINT64         (*readdouble_masked)(offs_t, UINT64);
172   void         (*writebyte)(offs_t, UINT8);
173   void         (*writehalf)(offs_t, UINT16);
174   void         (*writeword)(offs_t, UINT32);
175   void         (*writeword_masked)(offs_t, UINT32, UINT32);
176   void         (*writedouble)(offs_t, UINT64);
177   void         (*writedouble_masked)(offs_t, UINT64, UINT64);
178};
179
180
181163/* MIPS3 TLB entry */
182164typedef struct _mips3_tlb_entry mips3_tlb_entry;
183165struct _mips3_tlb_entry
r2762r2763
188170};
189171
190172
173/* forward declaration of implementation-specific state */
174typedef struct _mips3imp_state mips3imp_state;
175
176
191177/* MIPS3 state */
192178typedef struct _mips3_state mips3_state;
193179struct _mips3_state
r2762r2763
212198
213199   /* memory accesses */
214200   UINT8         bigendian;
215   memory_accessors memory;
201   data_accessors   memory;
216202
217203   /* cache memory */
218204   UINT32 *      icache;
r2762r2763
221207   size_t         dcache_size;
222208
223209   /* MMU */
224   mips3_tlb_entry tlb[48];
210   mips3_tlb_entry tlb[MIPS3_TLB_ENTRIES];
225211   UINT32 *      tlb_table;
212
213   /* for use by specific implementations */
214   mips3imp_state *impstate;
226215};
227216
228217
r2762r2763
231220    FUNCTION PROTOTYPES
232221***************************************************************************/
233222
234size_t mips3com_init(mips3_state *mips, mips3_flavor flavor, int bigendian, int index, int clock, const struct mips3_config *config, int (*irqcallback)(int), void *memory);
223size_t mips3com_init(mips3_state *mips, mips3_flavor flavor, int bigendian, int index, int clock, const mips3_config *config, int (*irqcallback)(int), void *memory);
235224void mips3com_reset(mips3_state *mips);
236225#ifdef ENABLE_DEBUGGER
237226offs_t mips3com_dasm(mips3_state *mips, char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram);
r2762r2763
241230void mips3com_map_tlb_entries(mips3_state *mips);
242231void mips3com_unmap_tlb_entries(mips3_state *mips);
243232void mips3com_recompute_tlb_table(mips3_state *mips);
244int mips3com_translate_address(mips3_state *mips, int space, offs_t *address);
233int mips3com_translate_address(mips3_state *mips, int space, int intention, offs_t *address);
245234void mips3com_tlbr(mips3_state *mips);
246235void mips3com_tlbwi(mips3_state *mips);
247236void mips3com_tlbwr(mips3_state *mips);
src/emu/cpu/mips/mips3.h
r2762r2763
204204    STRUCTURES
205205***************************************************************************/
206206
207struct mips3_config
207typedef struct _mips3_config mips3_config;
208struct _mips3_config
208209{
209210   size_t      icache;                     /* code cache size */
210211   size_t      dcache;                     /* data cache size */
r2762r2763
250251
251252/* fix me -- how do we make this work?? */
252253#define MIPS3DRC_STRICT_VERIFY      0x0001         /* verify all instructions */
253#define MIPS3DRC_STRICT_COP0      0x0002         /* validate all COP0 instructions */
254#define MIPS3DRC_STRICT_COP1      0x0004         /* validate all COP1 instructions */
255#define MIPS3DRC_STRICT_COP2      0x0008         /* validate all COP2 instructions */
256#define MIPS3DRC_FLUSH_PC         0x0020         /* flush the PC value before each memory access */
257#define MIPS3DRC_CHECK_OVERFLOWS   0x0040         /* actually check overflows on add/sub instructions */
254#define MIPS3DRC_STRICT_COP1      0x0002         /* validate all COP1 instructions */
255#define MIPS3DRC_STRICT_COP2      0x0004         /* validate all COP2 instructions */
256#define MIPS3DRC_FLUSH_PC         0x0008         /* flush the PC value before each memory access */
257#define MIPS3DRC_CHECK_OVERFLOWS   0x0010         /* actually check overflows on add/sub instructions */
258258
259#define MIPS3DRC_COMPATIBLE_OPTIONS   (MIPS3DRC_STRICT_VERIFY | MIPS3DRC_STRICT_COP0 | MIPS3DRC_STRICT_COP1 | MIPS3DRC_STRICT_COP2 | MIPS3DRC_FLUSH_PC)
259#define MIPS3DRC_COMPATIBLE_OPTIONS   (MIPS3DRC_STRICT_VERIFY | MIPS3DRC_STRICT_COP1 | MIPS3DRC_STRICT_COP2 | MIPS3DRC_FLUSH_PC)
260260#define MIPS3DRC_FASTEST_OPTIONS   (0)
261261
262262
src/emu/cpu/mips/mips3drc.c
r2762r2763
9797#define LOPTR(x)            ((UINT32 *)(x) + 1)
9898#endif
9999
100#define R32(reg)            mips3.regmaplo[reg].type, mips3.regmaplo[reg].value
100#define R32(reg)            mips3->impstate->regmaplo[reg].type, mips3->impstate->regmaplo[reg].value
101101#define LO32               R32(REG_LO)
102102#define HI32               R32(REG_HI)
103#define CPR032(reg)            MEM(LOPTR(&mips3.core->cpr[0][reg]))
104#define CCR032(reg)            MEM(LOPTR(&mips3.core->ccr[0][reg]))
105#define FPR32(reg)            MEM(((mips3.cstate->mode & 1) == 0) ? &((float *)&mips3.core->cpr[1][0])[reg] : (float *)&mips3.core->cpr[1][reg])
106#define CCR132(reg)            MEM(LOPTR(&mips3.core->ccr[1][reg]))
107#define CPR232(reg)            MEM(LOPTR(&mips3.core->cpr[2][reg]))
108#define CCR232(reg)            MEM(LOPTR(&mips3.core->ccr[2][reg]))
103#define CPR032(reg)            MEM(LOPTR(&mips3->cpr[0][reg]))
104#define CCR032(reg)            MEM(LOPTR(&mips3->ccr[0][reg]))
105#define FPR32(reg)            MEM(((mips3->impstate->mode & 1) == 0) ? &((float *)&mips3->cpr[1][0])[reg] : (float *)&mips3->cpr[1][reg])
106#define CCR132(reg)            MEM(LOPTR(&mips3->ccr[1][reg]))
107#define CPR232(reg)            MEM(LOPTR(&mips3->cpr[2][reg]))
108#define CCR232(reg)            MEM(LOPTR(&mips3->ccr[2][reg]))
109109
110#define R64(reg)            mips3.regmap[reg].type, mips3.regmap[reg].value
110#define R64(reg)            mips3->impstate->regmap[reg].type, mips3->impstate->regmap[reg].value
111111#define LO64               R64(REG_LO)
112112#define HI64               R64(REG_HI)
113#define CPR064(reg)            MEM(&mips3.core->cpr[0][reg])
114#define CCR064(reg)            MEM(&mips3.core->ccr[0][reg])
115#define FPR64(reg)            MEM(((mips3.cstate->mode & 1) == 0) ? (double *)&mips3.core->cpr[1][(reg)/2] : (double *)&mips3.core->cpr[1][reg])
116#define CCR164(reg)            MEM(&mips3.core->ccr[1][reg])
117#define CPR264(reg)            MEM(&mips3.core->cpr[2][reg])
118#define CCR264(reg)            MEM(&mips3.core->ccr[2][reg])
113#define CPR064(reg)            MEM(&mips3->cpr[0][reg])
114#define CCR064(reg)            MEM(&mips3->ccr[0][reg])
115#define FPR64(reg)            MEM(((mips3->impstate->mode & 1) == 0) ? (double *)&mips3->cpr[1][(reg)/2] : (double *)&mips3->cpr[1][reg])
116#define CCR164(reg)            MEM(&mips3->ccr[1][reg])
117#define CPR264(reg)            MEM(&mips3->cpr[2][reg])
118#define CCR264(reg)            MEM(&mips3->ccr[2][reg])
119119
120#define FCCMASK(which)         fcc_mask[(mips3.core->flavor < MIPS3_TYPE_MIPS_IV) ? 0 : ((which) & 7)]
120#define FCCMASK(which)         fcc_mask[(mips3->flavor < MIPS3_TYPE_MIPS_IV) ? 0 : ((which) & 7)]
121121
122122
123123
r2762r2763
157157};
158158
159159
160/* cache-based state */
161typedef struct _mips3_cache_state mips3_cache_state;
162struct _mips3_cache_state
160/* MIPS3 registers */
161struct _mips3imp_state
163162{
163   /* core state */
164   drccache *         cache;                  /* pointer to the DRC code cache */
165   drcuml_state *      drcuml;                  /* DRC UML generator state */
166   drcfe_state *      drcfe;                  /* pointer to the DRC front-end state */
167   UINT32            drcoptions;               /* configurable DRC options */
168
169   /* internal stuff */
170   UINT8            cache_dirty;            /* true if we need to flush the cache */
171
164172   /* parameters for subroutines */
165173   UINT64            numcycles;               /* return value from gettotalcycles */
166174   UINT32            mode;                  /* current global mode */
r2762r2763
178186   UINT32            c_ult_table[32];         /* FLAGS table for c_ult */
179187   UINT32            c_ole_table[32];         /* FLAGS table for c_ole */
180188   UINT32            c_ule_table[32];         /* FLAGS table for c_ule */
181};
182189
183
184/* MIPS3 registers */
185typedef struct _mips3_regs mips3_regs;
186struct _mips3_regs
187{
188   /* core state */
189   drccache *         cache;                  /* pointer to the DRC code cache */
190   drcuml_state *      drcuml;                  /* DRC UML generator state */
191   drcfe_state *      drcfe;                  /* pointer to the DRC front-end state */
192   UINT32            drcoptions;               /* configurable DRC options */
193   mips3_state *      core;                  /* pointer to the core MIPS3 state */
194   mips3_cache_state *   cstate;                  /* state that needs to live in the cache */
195
196   /* internal stuff */
197   UINT8            cache_dirty;            /* true if we need to flush the cache */
198
199190   /* register mappings */
200191   drcuml_parameter   regmap[34];               /* parameter to register mappings for all 32 integer registers */
201192   drcuml_parameter   regmaplo[34];            /* parameter to register mappings for all 32 integer registers */
r2762r2763
275266    PRIVATE GLOBAL VARIABLES
276267***************************************************************************/
277268
278static mips3_regs mips3;
269static mips3_state *mips3;
279270
280271
281272/* bit indexes for various FCCs */
r2762r2763
661652{
662653   int regnum;
663654
664   for (regnum = 0; regnum < ARRAY_LENGTH(mips3.regmap); regnum++)
665      if (mips3.regmap[regnum].type == DRCUML_PTYPE_INT_REGISTER)
666         UML_DMOV(block, IREG(mips3.regmap[regnum].value - DRCUML_REG_I0), MEM(&mips3.core->r[regnum]));
655   for (regnum = 0; regnum < ARRAY_LENGTH(mips3->impstate->regmap); regnum++)
656      if (mips3->impstate->regmap[regnum].type == DRCUML_PTYPE_INT_REGISTER)
657         UML_DMOV(block, IREG(mips3->impstate->regmap[regnum].value - DRCUML_REG_I0), MEM(&mips3->r[regnum]));
667658}
668659
669660
r2762r2763
676667{
677668   int regnum;
678669
679   for (regnum = 0; regnum < ARRAY_LENGTH(mips3.regmap); regnum++)
680      if (mips3.regmap[regnum].type == DRCUML_PTYPE_INT_REGISTER)
681         UML_DMOV(block, MEM(&mips3.core->r[regnum]), IREG(mips3.regmap[regnum].value - DRCUML_REG_I0));
670   for (regnum = 0; regnum < ARRAY_LENGTH(mips3->impstate->regmap); regnum++)
671      if (mips3->impstate->regmap[regnum].type == DRCUML_PTYPE_INT_REGISTER)
672         UML_DMOV(block, MEM(&mips3->r[regnum]), IREG(mips3->impstate->regmap[regnum].value - DRCUML_REG_I0));
682673}
683674
684675
r2762r2763
691682    mips3_init - initialize the processor
692683-------------------------------------------------*/
693684
694static void mips3_init(mips3_flavor flavor, int bigendian, int index, int clock, const struct mips3_config *config, int (*irqcallback)(int))
685static void mips3_init(mips3_flavor flavor, int bigendian, int index, int clock, const mips3_config *config, int (*irqcallback)(int))
695686{
696687   drcfe_config feconfig =
697688   {
r2762r2763
700691      COMPILE_MAX_SEQUENCE,      /* maximum instructions to include in a sequence */
701692      mips3fe_describe         /* callback to describe a single instruction */
702693   };
694   drccache *cache;
703695   drcbe_info beinfo;
704696   UINT32 flags = 0;
705697   size_t extrasize;
r2762r2763
710702    extrasize = mips3com_init(NULL, flavor, bigendian, index, clock, config, irqcallback, NULL);
711703
712704   /* allocate enough space for the cache and the core */
713   mips3.cache = drccache_alloc(CACHE_SIZE + sizeof(*mips3.core) + extrasize);
714   if (mips3.cache == NULL)
715      fatalerror("Unable to allocate cache of size %d", (UINT32)(CACHE_SIZE + sizeof(*mips3.core) + extrasize));
705   cache = drccache_alloc(CACHE_SIZE + sizeof(*mips3) + extrasize);
706   if (cache == NULL)
707      fatalerror("Unable to allocate cache of size %d", (UINT32)(CACHE_SIZE + sizeof(*mips3) + extrasize));
716708
717709   /* allocate the core and the extra memory */
718   mips3.core = drccache_memory_alloc_near(mips3.cache, sizeof(*mips3.core));
719   extramem = drccache_memory_alloc(mips3.cache, extrasize);
710   mips3 = drccache_memory_alloc_near(cache, sizeof(*mips3));
711   memset(mips3, 0, sizeof(*mips3));
712   extramem = drccache_memory_alloc(cache, extrasize);
713   memset(extramem, 0, extrasize);
720714
721715   /* initialize the core */
722   mips3com_init(mips3.core, flavor, bigendian, index, clock, config, irqcallback, extramem);
716   mips3com_init(mips3, flavor, bigendian, index, clock, config, irqcallback, extramem);
723717
724   /* allocate memory for cache-local state and initialize it */
725   mips3.cstate = drccache_memory_alloc_near(mips3.cache, sizeof(*mips3.cstate));
726   memset(mips3.cstate, 0, sizeof(*mips3.cstate));
727   memcpy(mips3.cstate->fpmode, fpmode_source, sizeof(fpmode_source));
728   memcpy(mips3.cstate->slt_table, slt_table_source, sizeof(slt_table_source));
729   memcpy(mips3.cstate->sltu_table, sltu_table_source, sizeof(sltu_table_source));
730   memcpy(mips3.cstate->c_un_table, c_un_table_source, sizeof(c_un_table_source));
731   memcpy(mips3.cstate->c_eq_table, c_eq_table_source, sizeof(c_eq_table_source));
732   memcpy(mips3.cstate->c_ueq_table, c_ueq_table_source, sizeof(c_ueq_table_source));
733   memcpy(mips3.cstate->c_olt_table, c_olt_table_source, sizeof(c_olt_table_source));
734   memcpy(mips3.cstate->c_ult_table, c_ult_table_source, sizeof(c_ult_table_source));
735   memcpy(mips3.cstate->c_ole_table, c_ole_table_source, sizeof(c_ole_table_source));
736   memcpy(mips3.cstate->c_ule_table, c_ule_table_source, sizeof(c_ule_table_source));
718   /* allocate the implementation-specific state from the full cache */
719   mips3->impstate = drccache_memory_alloc_near(cache, sizeof(*mips3->impstate));
720   memset(mips3->impstate, 0, sizeof(*mips3->impstate));
721   mips3->impstate->cache = cache;
737722
738723   /* initialize the UML generator */
739724   if (FORCE_C_BACKEND)
r2762r2763
742727      flags |= DRCUML_OPTION_LOG_UML;
743728   if (LOG_NATIVE)
744729      flags |= DRCUML_OPTION_LOG_NATIVE;
745   mips3.drcuml = drcuml_alloc(mips3.cache, flags, 8, 32, 2);
746   if (mips3.drcuml == NULL)
730   mips3->impstate->drcuml = drcuml_alloc(cache, flags, 8, 32, 2);
731   if (mips3->impstate->drcuml == NULL)
747732      fatalerror("Error initializing the UML");
748733
749734   /* initialize the front-end helper */
750735   if (SINGLE_INSTRUCTION_MODE)
751736      feconfig.max_sequence = 1;
752   mips3.drcfe = drcfe_init(&feconfig, mips3.core);
737   mips3->impstate->drcfe = drcfe_init(&feconfig, mips3);
753738
739   /* allocate memory for cache-local state and initialize it */
740   memcpy(mips3->impstate->fpmode, fpmode_source, sizeof(fpmode_source));
741   memcpy(mips3->impstate->slt_table, slt_table_source, sizeof(slt_table_source));
742   memcpy(mips3->impstate->sltu_table, sltu_table_source, sizeof(sltu_table_source));
743   memcpy(mips3->impstate->c_un_table, c_un_table_source, sizeof(c_un_table_source));
744   memcpy(mips3->impstate->c_eq_table, c_eq_table_source, sizeof(c_eq_table_source));
745   memcpy(mips3->impstate->c_ueq_table, c_ueq_table_source, sizeof(c_ueq_table_source));
746   memcpy(mips3->impstate->c_olt_table, c_olt_table_source, sizeof(c_olt_table_source));
747   memcpy(mips3->impstate->c_ult_table, c_ult_table_source, sizeof(c_ult_table_source));
748   memcpy(mips3->impstate->c_ole_table, c_ole_table_source, sizeof(c_ole_table_source));
749   memcpy(mips3->impstate->c_ule_table, c_ule_table_source, sizeof(c_ule_table_source));
750
754751   /* compute the register parameters */
755752   for (regnum = 0; regnum < 34; regnum++)
756753   {
757      mips3.regmap[regnum].type = (regnum == 0) ? DRCUML_PTYPE_IMMEDIATE : DRCUML_PTYPE_MEMORY;
758      mips3.regmap[regnum].value = (regnum == 0) ? 0 : (FPTR)&mips3.core->r[regnum];
759      mips3.regmaplo[regnum].type = (regnum == 0) ? DRCUML_PTYPE_IMMEDIATE : DRCUML_PTYPE_MEMORY;
760      mips3.regmaplo[regnum].value = (regnum == 0) ? 0 : (FPTR)LOPTR(&mips3.core->r[regnum]);
754      mips3->impstate->regmap[regnum].type = (regnum == 0) ? DRCUML_PTYPE_IMMEDIATE : DRCUML_PTYPE_MEMORY;
755      mips3->impstate->regmap[regnum].value = (regnum == 0) ? 0 : (FPTR)&mips3->r[regnum];
756      mips3->impstate->regmaplo[regnum].type = (regnum == 0) ? DRCUML_PTYPE_IMMEDIATE : DRCUML_PTYPE_MEMORY;
757      mips3->impstate->regmaplo[regnum].value = (regnum == 0) ? 0 : (FPTR)LOPTR(&mips3->r[regnum]);
761758   }
762759
763760   /* if we have registers to spare, assign r2, r3, r4 to leftovers */
764761   if (!DISABLE_FAST_REGISTERS)
765762   {
766      drcuml_get_backend_info(mips3.drcuml, &beinfo);
763      drcuml_get_backend_info(mips3->impstate->drcuml, &beinfo);
767764      if (beinfo.direct_iregs > 4)
768765      {
769         mips3.regmap[2].type = mips3.regmaplo[2].type = DRCUML_PTYPE_INT_REGISTER;
770         mips3.regmap[2].value = mips3.regmaplo[2].value = DRCUML_REG_I4;
766         mips3->impstate->regmap[2].type = mips3->impstate->regmaplo[2].type = DRCUML_PTYPE_INT_REGISTER;
767         mips3->impstate->regmap[2].value = mips3->impstate->regmaplo[2].value = DRCUML_REG_I4;
771768      }
772769      if (beinfo.direct_iregs > 5)
773770      {
774         mips3.regmap[3].type = mips3.regmaplo[3].type = DRCUML_PTYPE_INT_REGISTER;
775         mips3.regmap[3].value = mips3.regmaplo[3].value = DRCUML_REG_I5;
771         mips3->impstate->regmap[3].type = mips3->impstate->regmaplo[3].type = DRCUML_PTYPE_INT_REGISTER;
772         mips3->impstate->regmap[3].value = mips3->impstate->regmaplo[3].value = DRCUML_REG_I5;
776773      }
777774      if (beinfo.direct_iregs > 6)
778775      {
779         mips3.regmap[4].type = mips3.regmaplo[4].type = DRCUML_PTYPE_INT_REGISTER;
780         mips3.regmap[4].value = mips3.regmaplo[4].value = DRCUML_REG_I6;
776         mips3->impstate->regmap[4].type = mips3->impstate->regmaplo[4].type = DRCUML_PTYPE_INT_REGISTER;
777         mips3->impstate->regmap[4].value = mips3->impstate->regmaplo[4].value = DRCUML_REG_I6;
781778      }
782779   }
783780
784781   /* mark the cache dirty so it is updated on next execute */
785   mips3.cache_dirty = TRUE;
782   mips3->impstate->cache_dirty = TRUE;
786783}
787784
788785
r2762r2763
793790static void mips3_reset(void)
794791{
795792   /* reset the common code and mark the cache dirty */
796   mips3com_reset(mips3.core);
797   mips3.cstate->mode = (MODE_KERNEL << 1) | 0;
798   mips3.cache_dirty = TRUE;
793   mips3com_reset(mips3);
794   mips3->impstate->mode = (MODE_KERNEL << 1) | 0;
795   mips3->impstate->cache_dirty = TRUE;
799796}
800797
801798
r2762r2763
806803
807804static int mips3_execute(int cycles)
808805{
809   drcuml_state *drcuml = mips3.drcuml;
806   drcuml_state *drcuml = mips3->impstate->drcuml;
810807   int execute_result;
811808
812809   /* reset the cache if dirty */
813   if (mips3.cache_dirty)
810   if (mips3->impstate->cache_dirty)
814811      code_flush_cache(drcuml);
815   mips3.cache_dirty = FALSE;
812   mips3->impstate->cache_dirty = FALSE;
816813
817814   /* execute */
818   mips3.core->icount = cycles;
815   mips3->icount = cycles;
819816   do
820817   {
821818      /* run as much as we can */
822      execute_result = drcuml_execute(drcuml, mips3.entry);
819      execute_result = drcuml_execute(drcuml, mips3->impstate->entry);
823820
824821      /* if we need to recompile, do it */
825822      if (execute_result == EXECUTE_MISSING_CODE)
826         code_compile_block(drcuml, mips3.cstate->mode, mips3.core->pc);
823         code_compile_block(drcuml, mips3->impstate->mode, mips3->pc);
827824      else if (execute_result == EXECUTE_UNMAPPED_CODE)
828         fatalerror("Attempted to execute unmapped code at PC=%08X\n", mips3.core->pc);
825         fatalerror("Attempted to execute unmapped code at PC=%08X\n", mips3->pc);
829826      else if (execute_result == EXECUTE_RESET_CACHE)
830827         code_flush_cache(drcuml);
831828
832829   } while (execute_result != EXECUTE_OUT_OF_CYCLES);
833830
834831   /* return the number of cycles executed */
835   return cycles - mips3.core->icount;
832   return cycles - mips3->icount;
836833}
837834
838835
r2762r2763
843840static void mips3_exit(void)
844841{
845842   /* clean up the DRC */
846   drcfe_exit(mips3.drcfe);
847   drcuml_free(mips3.drcuml);
848   drccache_free(mips3.cache);
843   drcfe_exit(mips3->impstate->drcfe);
844   drcuml_free(mips3->impstate->drcuml);
845   drccache_free(mips3->impstate->cache);
849846}
850847
851848
r2762r2763
857854static void mips3_get_context(void *dst)
858855{
859856   if (dst != NULL)
860      *(mips3_regs *)dst = mips3;
857      *(mips3_state **)dst = mips3;
861858}
862859
863860
r2762r2763
869866static void mips3_set_context(void *src)
870867{
871868   if (src != NULL)
872      mips3 = *(mips3_regs *)src;
869      mips3 = *(mips3_state **)src;
873870}
874871
875872
r2762r2763
878875    address translation
879876-------------------------------------------------*/
880877
881static int mips3_translate(int space, offs_t *address)
878static int mips3_translate(int space, int intention, offs_t *address)
882879{
883   return mips3com_translate_address(mips3.core, space, address);
880   return mips3com_translate_address(mips3, space, intention, address);
884881}
885882
886883
r2762r2763
891888#ifdef ENABLE_DEBUGGER
892889static offs_t mips3_dasm(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram)
893890{
894   return mips3com_dasm(mips3.core, buffer, pc, oprom, opram);
891   return mips3com_dasm(mips3, buffer, pc, oprom, opram);
895892}
896893#endif /* ENABLE_DEBUGGER */
897894
898895
899896
897/*-------------------------------------------------
898    mips3_set_info - set information about a given
899    CPU instance
900-------------------------------------------------*/
900901
902static void mips3_set_info(UINT32 state, cpuinfo *info)
903{
904   switch (state)
905   {
906      /* --- the following bits of info are set as 64-bit signed integers --- */
907      case CPUINFO_INT_MIPS3_DRC_OPTIONS:            mips3->impstate->drcoptions = info->i;            break;
908
909      case CPUINFO_INT_MIPS3_FASTRAM_SELECT:         if (info->i >= 0 && info->i < MIPS3_MAX_FASTRAM) mips3->impstate->fastram_select = info->i; mips3->impstate->cache_dirty = TRUE; break;
910      case CPUINFO_INT_MIPS3_FASTRAM_START:         mips3->impstate->fastram[mips3->impstate->fastram_select].start = info->i; mips3->impstate->cache_dirty = TRUE; break;
911      case CPUINFO_INT_MIPS3_FASTRAM_END:            mips3->impstate->fastram[mips3->impstate->fastram_select].end = info->i; mips3->impstate->cache_dirty = TRUE; break;
912      case CPUINFO_INT_MIPS3_FASTRAM_READONLY:      mips3->impstate->fastram[mips3->impstate->fastram_select].readonly = info->i; mips3->impstate->cache_dirty = TRUE; break;
913
914      case CPUINFO_INT_MIPS3_HOTSPOT_SELECT:         if (info->i >= 0 && info->i < MIPS3_MAX_HOTSPOTS) mips3->impstate->hotspot_select = info->i; mips3->impstate->cache_dirty = TRUE; break;
915      case CPUINFO_INT_MIPS3_HOTSPOT_PC:            mips3->impstate->hotspot[mips3->impstate->hotspot_select].pc = info->i; mips3->impstate->cache_dirty = TRUE; break;
916      case CPUINFO_INT_MIPS3_HOTSPOT_OPCODE:         mips3->impstate->hotspot[mips3->impstate->hotspot_select].opcode = info->i; mips3->impstate->cache_dirty = TRUE; break;
917      case CPUINFO_INT_MIPS3_HOTSPOT_CYCLES:         mips3->impstate->hotspot[mips3->impstate->hotspot_select].cycles = info->i; mips3->impstate->cache_dirty = TRUE; break;
918
919      /* --- the following bits of info are set as pointers to data or functions --- */
920      case CPUINFO_PTR_MIPS3_FASTRAM_BASE:         mips3->impstate->fastram[mips3->impstate->fastram_select].base = info->p;   break;
921
922      /* --- everything else is handled generically --- */
923      default:                              mips3com_set_info(mips3, state, info);   break;
924   }
925}
926
927
928/*-------------------------------------------------
929    mips3_get_info - return information about a
930    given CPU instance
931-------------------------------------------------*/
932
933static void mips3_get_info(UINT32 state, cpuinfo *info)
934{
935   switch (state)
936   {
937      /* --- the following bits of info are returned as 64-bit signed integers --- */
938      case CPUINFO_INT_CONTEXT_SIZE:               info->i = sizeof(mips3);            break;
939      case CPUINFO_INT_PREVIOUSPC:               /* not implemented */               break;
940
941      /* --- the following bits of info are returned as pointers to data or functions --- */
942      case CPUINFO_PTR_SET_INFO:                  info->setinfo = mips3_set_info;         break;
943      case CPUINFO_PTR_GET_CONTEXT:               info->getcontext = mips3_get_context;   break;
944      case CPUINFO_PTR_SET_CONTEXT:               info->setcontext = mips3_set_context;   break;
945      case CPUINFO_PTR_INIT:                     /* provided per-CPU */               break;
946      case CPUINFO_PTR_RESET:                     info->reset = mips3_reset;            break;
947      case CPUINFO_PTR_EXIT:                     info->exit = mips3_exit;            break;
948      case CPUINFO_PTR_EXECUTE:                  info->execute = mips3_execute;         break;
949#ifdef ENABLE_DEBUGGER
950      case CPUINFO_PTR_DISASSEMBLE:               info->disassemble = mips3_dasm;         break;
951#endif /* ENABLE_DEBUGGER */
952      case CPUINFO_PTR_TRANSLATE:                  info->translate = mips3_translate;      break;
953
954      /* --- the following bits of info are returned as NULL-terminated strings --- */
955      case CPUINFO_STR_CORE_FILE:                  strcpy(info->s, __FILE__);            break;
956
957      /* --- everything else is handled generically --- */
958      default:                              mips3com_get_info(mips3, state, info); break;
959   }
960}
961
962
963
901964/***************************************************************************
902965    CACHE MANAGEMENT
903966***************************************************************************/
r2762r2763
9401003   /* add subroutines for memory accesses */
9411004   for (mode = 0; mode < 3; mode++)
9421005   {
943      static_generate_memory_accessor(drcuml, mode, 1, FALSE, FALSE, "read8",       &mips3.read8[mode]);
944      static_generate_memory_accessor(drcuml, mode, 1, TRUE,  FALSE, "write8",      &mips3.write8[mode]);
945      static_generate_memory_accessor(drcuml, mode, 2, FALSE, FALSE, "read16",      &mips3.read16[mode]);
946      static_generate_memory_accessor(drcuml, mode, 2, TRUE,  FALSE, "write16",     &mips3.write16[mode]);
947      static_generate_memory_accessor(drcuml, mode, 4, FALSE, FALSE, "read32",      &mips3.read32[mode]);
948      static_generate_memory_accessor(drcuml, mode, 4, FALSE, TRUE,  "read32mask",  &mips3.read32mask[mode]);
949      static_generate_memory_accessor(drcuml, mode, 4, TRUE,  FALSE, "write32",     &mips3.write32[mode]);
950      static_generate_memory_accessor(drcuml, mode, 4, TRUE,  TRUE,  "write32mask", &mips3.write32mask[mode]);
951      static_generate_memory_accessor(drcuml, mode, 8, FALSE, FALSE, "read64",      &mips3.read64[mode]);
952      static_generate_memory_accessor(drcuml, mode, 8, FALSE, TRUE,  "read64mask",  &mips3.read64mask[mode]);
953      static_generate_memory_accessor(drcuml, mode, 8, TRUE,  FALSE, "write64",     &mips3.write64[mode]);
954      static_generate_memory_accessor(drcuml, mode, 8, TRUE,  TRUE,  "write64mask", &mips3.write64mask[mode]);
1006      static_generate_memory_accessor(drcuml, mode, 1, FALSE, FALSE, "read8",       &mips3->impstate->read8[mode]);
1007      static_generate_memory_accessor(drcuml, mode, 1, TRUE,  FALSE, "write8",      &mips3->impstate->write8[mode]);
1008      static_generate_memory_accessor(drcuml, mode, 2, FALSE, FALSE, "read16",      &mips3->impstate->read16[mode]);
1009      static_generate_memory_accessor(drcuml, mode, 2, TRUE,  FALSE, "write16",     &mips3->impstate->write16[mode]);
1010      static_generate_memory_accessor(drcuml, mode, 4, FALSE, FALSE, "read32",      &mips3->impstate->read32[mode]);
1011      static_generate_memory_accessor(drcuml, mode, 4, FALSE, TRUE,  "read32mask",  &mips3->impstate->read32mask[mode]);
1012      static_generate_memory_accessor(drcuml, mode, 4, TRUE,  FALSE, "write32",     &mips3->impstate->write32[mode]);
1013      static_generate_memory_accessor(drcuml, mode, 4, TRUE,  TRUE,  "write32mask", &mips3->impstate->write32mask[mode]);
1014      static_generate_memory_accessor(drcuml, mode, 8, FALSE, FALSE, "read64",      &mips3->impstate->read64[mode]);
1015      static_generate_memory_accessor(drcuml, mode, 8, FALSE, TRUE,  "read64mask",  &mips3->impstate->read64mask[mode]);
1016      static_generate_memory_accessor(drcuml, mode, 8, TRUE,  FALSE, "write64",     &mips3->impstate->write64[mode]);
1017      static_generate_memory_accessor(drcuml, mode, 8, TRUE,  TRUE,  "write64mask", &mips3->impstate->write64mask[mode]);
9551018   }
9561019}
9571020
r2762r2763
9711034   jmp_buf errorbuf;
9721035
9731036   /* get a description of this sequence */
974   desclist = drcfe_describe_code(mips3.drcfe, pc);
1037   desclist = drcfe_describe_code(mips3->impstate->drcfe, pc);
9751038   if (LOG_UML || LOG_NATIVE)
9761039      log_opcode_desc(drcuml, desclist, 0);
9771040
r2762r2763
10141077      else
10151078      {
10161079         UML_LABEL(block, seqhead->pc | 0x80000000);                        // label   seqhead->pc | 0x80000000
1017         UML_HASHJMP(block, IMM(mips3.cstate->mode), IMM(seqhead->pc), mips3.nocode);
1080         UML_HASHJMP(block, IMM(mips3->impstate->mode), IMM(seqhead->pc), mips3->impstate->nocode);
10181081                                                               // hashjmp <mode>,seqhead->pc,nocode
10191082         continue;
10201083      }
r2762r2763
10441107
10451108      /* if the last instruction can change modes, use a variable mode; otherwise, assume the same mode */
10461109      if (seqlast->flags & OPFLAG_CAN_CHANGE_MODES)
1047         UML_HASHJMP(block, MEM(&mips3.cstate->mode), IMM(nextpc), mips3.nocode);// hashjmp <mode>,nextpc,nocode
1110         UML_HASHJMP(block, MEM(&mips3->impstate->mode), IMM(nextpc), mips3->impstate->nocode);
1111                                                               // hashjmp <mode>,nextpc,nocode
10481112      else if (seqlast->next == NULL || seqlast->next->pc != nextpc)
1049         UML_HASHJMP(block, IMM(mips3.cstate->mode), IMM(nextpc), mips3.nocode);   // hashjmp <mode>,nextpc,nocode
1113         UML_HASHJMP(block, IMM(mips3->impstate->mode), IMM(nextpc), mips3->impstate->nocode);
1114                                                               // hashjmp <mode>,nextpc,nocode
10501115   }
10511116
10521117   /* end the sequence */
r2762r2763
10781143
10791144static void cfunc_printf_exception(void *param)
10801145{
1081   printf("Exception: EPC=%08X Cause=%08X BadVAddr=%08X Jmp=%08X\n", (UINT32)mips3.core->cpr[0][COP0_EPC], (UINT32)mips3.core->cpr[0][COP0_Cause], (UINT32)mips3.core->cpr[0][COP0_BadVAddr], mips3.core->pc);
1082   cfunc_printf_probe((void *)(FPTR)mips3.core->cpr[0][COP0_EPC]);
1146   printf("Exception: EPC=%08X Cause=%08X BadVAddr=%08X Jmp=%08X\n", (UINT32)mips3->cpr[0][COP0_EPC], (UINT32)mips3->cpr[0][COP0_Cause], (UINT32)mips3->cpr[0][COP0_BadVAddr], mips3->pc);
1147   cfunc_printf_probe((void *)(FPTR)mips3->cpr[0][COP0_EPC]);
10831148}
10841149
10851150
r2762r2763
10911156static void cfunc_printf_debug(void *param)
10921157{
10931158   const char *format = param;
1094   printf(format, mips3.cstate->arg0, mips3.cstate->arg1);
1159   printf(format, mips3->impstate->arg0, mips3->impstate->arg1);
10951160}
10961161
10971162
r2762r2763
11061171
11071172   printf(" PC=%08X          r1=%08X%08X  r2=%08X%08X  r3=%08X%08X\n",
11081173      pc,
1109      (UINT32)(mips3.core->r[1] >> 32), (UINT32)mips3.core->r[1],
1110      (UINT32)(mips3.core->r[2] >> 32), (UINT32)mips3.core->r[2],
1111      (UINT32)(mips3.core->r[3] >> 32), (UINT32)mips3.core->r[3]);
1174      (UINT32)(mips3->r[1] >> 32), (UINT32)mips3->r[1],
1175      (UINT32)(mips3->r[2] >> 32), (UINT32)mips3->r[2],
1176      (UINT32)(mips3->r[3] >> 32), (UINT32)mips3->r[3]);
11121177   printf(" r4=%08X%08X  r5=%08X%08X  r6=%08X%08X  r7=%08X%08X\n",
1113      (UINT32)(mips3.core->r[4] >> 32), (UINT32)mips3.core->r[4],
1114      (UINT32)(mips3.core->r[5] >> 32), (UINT32)mips3.core->r[5],
1115      (UINT32)(mips3.core->r[6] >> 32), (UINT32)mips3.core->r[6],
1116      (UINT32)(mips3.core->r[7] >> 32), (UINT32)mips3.core->r[7]);
1178      (UINT32)(mips3->r[4] >> 32), (UINT32)mips3->r[4],
1179      (UINT32)(mips3->r[5] >> 32), (UINT32)mips3->r[5],
1180      (UINT32)(mips3->r[6] >> 32), (UINT32)mips3->r[6],
1181      (UINT32)(mips3->r[7] >> 32), (UINT32)mips3->r[7]);
11171182   printf(" r8=%08X%08X  r9=%08X%08X r10=%08X%08X r11=%08X%08X\n",
1118      (UINT32)(mips3.core->r[8] >> 32), (UINT32)mips3.core->r[8],
1119      (UINT32)(mips3.core->r[9] >> 32), (UINT32)mips3.core->r[9],
1120      (UINT32)(mips3.core->r[10] >> 32), (UINT32)mips3.core->r[10],
1121      (UINT32)(mips3.core->r[11] >> 32), (UINT32)mips3.core->r[11]);
1183      (UINT32)(mips3->r[8] >> 32), (UINT32)mips3->r[8],
1184      (UINT32)(mips3->r[9] >> 32), (UINT32)mips3->r[9],
1185      (UINT32)(mips3->r[10] >> 32), (UINT32)mips3->r[10],
1186      (UINT32)(mips3->r[11] >> 32), (UINT32)mips3->r[11]);
11221187   printf("r12=%08X%08X r13=%08X%08X r14=%08X%08X r15=%08X%08X\n",
1123      (UINT32)(mips3.core->r[12] >> 32), (UINT32)mips3.core->r[12],
1124      (UINT32)(mips3.core->r[13] >> 32), (UINT32)mips3.core->r[13],
1125      (UINT32)(mips3.core->r[14] >> 32), (UINT32)mips3.core->r[14],
1126      (UINT32)(mips3.core->r[15] >> 32), (UINT32)mips3.core->r[15]);
1188      (UINT32)(mips3->r[12] >> 32), (UINT32)mips3->r[12],
1189      (UINT32)(mips3->r[13] >> 32), (UINT32)mips3->r[13],
1190      (UINT32)(mips3->r[14] >> 32), (UINT32)mips3->r[14],
1191      (UINT32)(mips3->r[15] >> 32), (UINT32)mips3->r[15]);
11271192   printf("r16=%08X%08X r17=%08X%08X r18=%08X%08X r19=%08X%08X\n",
1128      (UINT32)(mips3.core->r[16] >> 32), (UINT32)mips3.core->r[16],
1129      (UINT32)(mips3.core->r[17] >> 32), (UINT32)mips3.core->r[17],
1130      (UINT32)(mips3.core->r[18] >> 32), (UINT32)mips3.core->r[18],
1131      (UINT32)(mips3.core->r[19] >> 32), (UINT32)mips3.core->r[19]);
1193      (UINT32)(mips3->r[16] >> 32), (UINT32)mips3->r[16],
1194      (UINT32)(mips3->r[17] >> 32), (UINT32)mips3->r[17],
1195      (UINT32)(mips3->r[18] >> 32), (UINT32)mips3->r[18],
1196      (UINT32)(mips3->r[19] >> 32), (UINT32)mips3->r[19]);
11321197   printf("r20=%08X%08X r21=%08X%08X r22=%08X%08X r23=%08X%08X\n",
1133      (UINT32)(mips3.core->r[20] >> 32), (UINT32)mips3.core->r[20],
1134      (UINT32)(mips3.core->r[21] >> 32), (UINT32)mips3.core->r[21],
1135      (UINT32)(mips3.core->r[22] >> 32), (UINT32)mips3.core->r[22],
1136      (UINT32)(mips3.core->r[23] >> 32), (UINT32)mips3.core->r[23]);
1198      (UINT32)(mips3->r[20] >> 32), (UINT32)mips3->r[20],
1199      (UINT32)(mips3->r[21] >> 32), (UINT32)mips3->r[21],
1200      (UINT32)(mips3->r[22] >> 32), (UINT32)mips3->r[22],
1201      (UINT32)(mips3->r[23] >> 32), (UINT32)mips3->r[23]);
11371202   printf("r24=%08X%08X r25=%08X%08X r26=%08X%08X r27=%08X%08X\n",
1138      (UINT32)(mips3.core->r[24] >> 32), (UINT32)mips3.core->r[24],
1139      (UINT32)(mips3.core->r[25] >> 32), (UINT32)mips3.core->r[25],
1140      (UINT32)(mips3.core->r[26] >> 32), (UINT32)mips3.core->r[26],
1141      (UINT32)(mips3.core->r[27] >> 32), (UINT32)mips3.core->r[27]);
1203      (UINT32)(mips3->r[24] >> 32), (UINT32)mips3->r[24],
1204      (UINT32)(mips3->r[25] >> 32), (UINT32)mips3->r[25],
1205      (UINT32)(mips3->r[26] >> 32), (UINT32)mips3->r[26],
1206      (UINT32)(mips3->r[27] >> 32), (UINT32)mips3->r[27]);
11421207   printf("r28=%08X%08X r29=%08X%08X r30=%08X%08X r31=%08X%08X\n",
1143      (UINT32)(mips3.core->r[28] >> 32), (UINT32)mips3.core->r[28],
1144      (UINT32)(mips3.core->r[29] >> 32), (UINT32)mips3.core->r[29],
1145      (UINT32)(mips3.core->r[30] >> 32), (UINT32)mips3.core->r[30],
1146      (UINT32)(mips3.core->r[31] >> 32), (UINT32)mips3.core->r[31]);
1208      (UINT32)(mips3->r[28] >> 32), (UINT32)mips3->r[28],
1209      (UINT32)(mips3->r[29] >> 32), (UINT32)mips3->r[29],
1210      (UINT32)(mips3->r[30] >> 32), (UINT32)mips3->r[30],
1211      (UINT32)(mips3->r[31] >> 32), (UINT32)mips3->r[31]);
11471212   printf(" hi=%08X%08X  lo=%08X%08X\n",
1148      (UINT32)(mips3.core->r[REG_HI] >> 32), (UINT32)mips3.core->r[REG_HI],
1149      (UINT32)(mips3.core->r[REG_LO] >> 32), (UINT32)mips3.core->r[REG_LO]);
1213      (UINT32)(mips3->r[REG_HI] >> 32), (UINT32)mips3->r[REG_HI],
1214      (UINT32)(mips3->r[REG_LO] >> 32), (UINT32)mips3->r[REG_LO]);
11501215}
11511216
11521217
r2762r2763
11581223static void cfunc_unimplemented(void *param)
11591224{
11601225   UINT32 opcode = (FPTR)param;
1161   fatalerror("PC=%08X: Unimplemented op %08X (%02X,%02X)", mips3.core->pc, opcode, opcode >> 26, opcode & 0x3f);
1226   fatalerror("PC=%08X: Unimplemented op %08X (%02X,%02X)", mips3->pc, opcode, opcode >> 26, opcode & 0x3f);
11621227}
11631228
11641229
r2762r2763
11861251   block = drcuml_block_begin(drcuml, 20, &errorbuf);
11871252
11881253   /* forward references */
1189   alloc_handle(drcuml, &mips3.exception_norecover[EXCEPTION_INTERRUPT], "interrupt_norecover");
1190   alloc_handle(drcuml, &mips3.nocode, "nocode");
1254   alloc_handle(drcuml, &mips3->impstate->exception_norecover[EXCEPTION_INTERRUPT], "interrupt_norecover");
1255   alloc_handle(drcuml, &mips3->impstate->nocode, "nocode");
11911256
1192   alloc_handle(drcuml, &mips3.entry, "entry");
1193   UML_HANDLE(block, mips3.entry);                                       // handle  entry
1257   alloc_handle(drcuml, &mips3->impstate->entry, "entry");
1258   UML_HANDLE(block, mips3->impstate->entry);                              // handle  entry
11941259
11951260   /* reset the FPU mode */
11961261   UML_AND(block, IREG(0), CCR132(31), IMM(3));                           // and     i0,ccr1[31],3
1197   UML_LOAD1U(block, IREG(0), &mips3.cstate->fpmode[0], IREG(0));               // load1u  i0,fpmode,i0
1262   UML_LOAD1U(block, IREG(0), &mips3->impstate->fpmode[0], IREG(0));            // load1u  i0,fpmode,i0
11981263   UML_SETFMOD(block, IREG(0));                                       // setfmod i0
11991264
12001265   /* load fast integer registers */
r2762r2763
12081273   UML_JMPc(block, IF_Z, skip);                                       // jmp     skip,Z
12091274   UML_TEST(block, CPR032(COP0_Status), IMM(SR_EXL | SR_ERL));                  // test    [Status],SR_EXL | SR_ERL
12101275   UML_JMPc(block, IF_NZ, skip);                                       // jmp     skip,NZ
1211   UML_MOV(block, IREG(0), MEM(&mips3.core->pc));                           // mov     i0,pc
1276   UML_MOV(block, IREG(0), MEM(&mips3->pc));                              // mov     i0,pc
12121277   UML_MOV(block, IREG(1), IMM(0));                                    // mov     i1,0
1213   UML_CALLH(block, mips3.exception_norecover[EXCEPTION_INTERRUPT]);            // callh   exception_norecover
1278   UML_CALLH(block, mips3->impstate->exception_norecover[EXCEPTION_INTERRUPT]);   // callh   exception_norecover
12141279   UML_LABEL(block, skip);                                          // skip:
12151280
12161281   /* generate a hash jump via the current mode and PC */
1217   UML_HASHJMP(block, MEM(&mips3.cstate->mode), MEM(&mips3.core->pc), mips3.nocode);// hashjmp <mode>,<pc>,nocode
1218
1282   UML_HASHJMP(block, MEM(&mips3->impstate->mode), MEM(&mips3->pc), mips3->impstate->nocode);
1283                                                               // hashjmp <mode>,<pc>,nocode
12191284   drcuml_block_end(block);
12201285}
12211286
r2762r2763
12381303   block = drcuml_block_begin(drcuml, 10, &errorbuf);
12391304
12401305   /* generate a hash jump via the current mode and PC */
1241   alloc_handle(drcuml, &mips3.nocode, "nocode");
1242   UML_HANDLE(block, mips3.nocode);                                    // handle  nocode
1306   alloc_handle(drcuml, &mips3->impstate->nocode, "nocode");
1307   UML_HANDLE(block, mips3->impstate->nocode);                              // handle  nocode
12431308   UML_GETEXP(block, IREG(0));                                          // getexp  i0
1244   UML_MOV(block, MEM(&mips3.core->pc), IREG(0));                           // mov     [pc],i0
1309   UML_MOV(block, MEM(&mips3->pc), IREG(0));                              // mov     [pc],i0
12451310   save_fast_iregs(block);
12461311   UML_EXIT(block, IMM(EXECUTE_MISSING_CODE));                              // exit    EXECUTE_MISSING_CODE
12471312
r2762r2763
12671332   block = drcuml_block_begin(drcuml, 10, &errorbuf);
12681333
12691334   /* generate a hash jump via the current mode and PC */
1270   alloc_handle(drcuml, &mips3.out_of_cycles, "out_of_cycles");
1271   UML_HANDLE(block, mips3.out_of_cycles);                                 // handle  out_of_cycles
1335   alloc_handle(drcuml, &mips3->impstate->out_of_cycles, "out_of_cycles");
1336   UML_HANDLE(block, mips3->impstate->out_of_cycles);                        // handle  out_of_cycles
12721337   UML_GETEXP(block, IREG(0));                                          // getexp  i0
1273   UML_MOV(block, MEM(&mips3.core->pc), IREG(0));                           // mov     <pc>,i0
1338   UML_MOV(block, MEM(&mips3->pc), IREG(0));                              // mov     <pc>,i0
12741339   save_fast_iregs(block);
12751340   UML_EXIT(block, IMM(EXECUTE_OUT_OF_CYCLES));                           // exit    EXECUTE_OUT_OF_CYCLES
12761341
r2762r2763
12931358      fatalerror("Unrecoverable error in static_generate_tlb_mismatch");
12941359
12951360   /* forward references */
1296   alloc_handle(drcuml, &mips3.exception[EXCEPTION_TLBLOAD], "exception_tlbload");
1297   alloc_handle(drcuml, &mips3.exception[EXCEPTION_TLBLOAD_FILL], "exception_tlbload_fill");
1361   alloc_handle(drcuml, &mips3->impstate->exception[EXCEPTION_TLBLOAD], "exception_tlbload");
1362   alloc_handle(drcuml, &mips3->impstate->exception[EXCEPTION_TLBLOAD_FILL], "exception_tlbload_fill");
12981363
12991364   /* begin generating */
13001365   block = drcuml_block_begin(drcuml, 20, &errorbuf);
13011366
13021367   /* generate a hash jump via the current mode and PC */
1303   alloc_handle(drcuml, &mips3.tlb_mismatch, "tlb_mismatch");
1304   UML_HANDLE(block, mips3.tlb_mismatch);                                 // handle  tlb_mismatch
1368   alloc_handle(drcuml, &mips3->impstate->tlb_mismatch, "tlb_mismatch");
1369   UML_HANDLE(block, mips3->impstate->tlb_mismatch);                        // handle  tlb_mismatch
13051370   UML_RECOVER(block, IREG(0), MAPVAR_PC);                                 // recover i0,PC
1306   UML_MOV(block, MEM(&mips3.core->pc), IREG(0));                           // mov     <pc>,i0
1371   UML_MOV(block, MEM(&mips3->pc), IREG(0));                              // mov     <pc>,i0
13071372   UML_SHR(block, IREG(1), IREG(0), IMM(12));                              // shr     i1,i0,12
1308   UML_LOAD4(block, IREG(1), mips3.core->tlb_table, IREG(1));                  // load4   i1,[tlb_table],i1
1373   UML_LOAD4(block, IREG(1), mips3->tlb_table, IREG(1));                     // load4   i1,[tlb_table],i1
13091374   if (PRINTF_MMU)
13101375   {
1311      UML_MOV(block, MEM(&mips3.cstate->arg0), IREG(0));                     // mov     [arg0],i0
1312      UML_MOV(block, MEM(&mips3.cstate->arg1), IREG(1));                     // mov     [arg1],i1
1376      UML_MOV(block, MEM(&mips3->impstate->arg0), IREG(0));                  // mov     [arg0],i0
1377      UML_MOV(block, MEM(&mips3->impstate->arg1), IREG(1));                  // mov     [arg1],i1
13131378      UML_CALLC(block, cfunc_printf_debug, "TLB mismatch @ %08X (ent=%08X)\n");   // callc   printf_debug
13141379   }
13151380   UML_TEST(block, IREG(1), IMM(TLB_VALID));                              // test    i1,TLB_VALID
13161381   UML_JMPc(block, IF_NZ, 1);                                          // jmp     1,nz
13171382   UML_TEST(block, IREG(1), IMM(TLB_PRESENT));                              // test    i1,TLB_PRESENT
1318   UML_EXHc(block, IF_NZ, mips3.exception[EXCEPTION_TLBLOAD], IREG(0));         // exh     exception[TLBLOAD],i0,nz
1319   UML_EXH(block, mips3.exception[EXCEPTION_TLBLOAD_FILL], IREG(0));            // exh     exception[TLBLOAD_FILL],i0
1383   UML_EXHc(block, IF_NZ, mips3->impstate->exception[EXCEPTION_TLBLOAD], IREG(0));   // exh     exception[TLBLOAD],i0,nz
1384   UML_EXH(block, mips3->impstate->exception[EXCEPTION_TLBLOAD_FILL], IREG(0));   // exh     exception[TLBLOAD_FILL],i0
13201385   UML_LABEL(block, 1);                                          // 1:
13211386   save_fast_iregs(block);
13221387   UML_EXIT(block, IMM(EXECUTE_MISSING_CODE));                              // exit    EXECUTE_MISSING_CODE
r2762r2763
13321397
13331398static void static_generate_exception(drcuml_state *drcuml, UINT8 exception, int recover, const char *name)
13341399{
1335   drcuml_codehandle **exception_handle = recover ? &mips3.exception[exception] : &mips3.exception_norecover[exception];
1400   drcuml_codehandle **exception_handle = recover ? &mips3->impstate->exception[exception] : &mips3->impstate->exception_norecover[exception];
13361401   UINT32 offset = 0x180;
13371402   drcuml_codelabel next = 1;
13381403   drcuml_block *block;
r2762r2763
14051470   UML_MOVc(block, IF_Z, IREG(0), IMM(0x80000000 + offset));                  // mov     i0,0x80000000 + offset,z
14061471
14071472   /* adjust cycles */
1408   UML_SUBf(block, MEM(&mips3.core->icount), MEM(&mips3.core->icount), IREG(1), FLAGS_S); // sub icount,icount,cycles,S
1409   UML_EXHc(block, IF_S, mips3.out_of_cycles, IREG(0));                     // exh     out_of_cycles,i0
1473   UML_SUBf(block, MEM(&mips3->icount), MEM(&mips3->icount), IREG(1), FLAGS_S);    // sub icount,icount,cycles,S
1474   UML_EXHc(block, IF_S, mips3->impstate->out_of_cycles, IREG(0));               // exh     out_of_cycles,i0
14101475
1411   UML_HASHJMP(block, MEM(&mips3.cstate->mode), IREG(0), mips3.nocode);         // hashjmp <mode>,i0,nocode
1476   UML_HASHJMP(block, MEM(&mips3->impstate->mode), IREG(0), mips3->impstate->nocode);// hashjmp <mode>,i0,nocode
14121477
14131478   drcuml_block_end(block);
14141479}
r2762r2763
14231488   /* on entry, address is in I0; data for writes is in I1; mask for accesses is in I2 */
14241489   /* on exit, read result is in I0 */
14251490   /* routine trashes I0-I3 */
1426   drcuml_codehandle *exception_tlb = mips3.exception[iswrite ? EXCEPTION_TLBSTORE : EXCEPTION_TLBLOAD];
1427   drcuml_codehandle *exception_tlbfill = mips3.exception[iswrite ? EXCEPTION_TLBSTORE_FILL : EXCEPTION_TLBLOAD_FILL];
1428   drcuml_codehandle *exception_addrerr = mips3.exception[iswrite ? EXCEPTION_ADDRSTORE : EXCEPTION_ADDRLOAD];
1491   drcuml_codehandle *exception_tlb = mips3->impstate->exception[iswrite ? EXCEPTION_TLBSTORE : EXCEPTION_TLBLOAD];
1492   drcuml_codehandle *exception_tlbfill = mips3->impstate->exception[iswrite ? EXCEPTION_TLBSTORE_FILL : EXCEPTION_TLBLOAD_FILL];
1493   drcuml_codehandle *exception_addrerr = mips3->impstate->exception[iswrite ? EXCEPTION_ADDRSTORE : EXCEPTION_ADDRLOAD];
14291494   drcuml_block *block;
14301495   jmp_buf errorbuf;
14311496   int tlbmiss = 0;
r2762r2763
14641529
14651530   /* general case: assume paging and perform a translation */
14661531   UML_SHR(block, IREG(3), IREG(0), IMM(12));                              // shr     i3,i0,12
1467   UML_LOAD4(block, IREG(3), mips3.core->tlb_table, IREG(3));                  // load4   i3,[tlb_table],i3
1532   UML_LOAD4(block, IREG(3), mips3->tlb_table, IREG(3));                     // load4   i3,[tlb_table],i3
14681533   UML_TEST(block, IREG(3), IMM(iswrite ? TLB_DIRTY : TLB_VALID));               // test    i3,iswrite ? TLB_DIRTY : TLB_VALID
14691534   UML_JMPc(block, IF_Z, tlbmiss = label++);                              // jmp     tlbmiss,z
14701535   UML_INSERT(block, IREG(0), IREG(3), IMM(0), IMM(0xfffff000));               // insert  i0,i3,0,0xfffff000
14711536
14721537   for (ramnum = 0; ramnum < MIPS3_MAX_FASTRAM; ramnum++)
1473      if (!Machine->debug_mode && mips3.fastram[ramnum].base != NULL && (!iswrite || !mips3.fastram[ramnum].readonly))
1538      if (!Machine->debug_mode && mips3->impstate->fastram[ramnum].base != NULL && (!iswrite || !mips3->impstate->fastram[ramnum].readonly))
14741539      {
1475         void *fastbase = (UINT8 *)mips3.fastram[ramnum].base - mips3.fastram[ramnum].start;
1540         void *fastbase = (UINT8 *)mips3->impstate->fastram[ramnum].base - mips3->impstate->fastram[ramnum].start;
14761541         UINT32 skip = label++;
1477         if (mips3.fastram[ramnum].end != 0xffffffff)
1542         if (mips3->impstate->fastram[ramnum].end != 0xffffffff)
14781543         {
1479            UML_CMP(block, IREG(0), IMM(mips3.fastram[ramnum].end));         // cmp     i0,end
1544            UML_CMP(block, IREG(0), IMM(mips3->impstate->fastram[ramnum].end));   // cmp     i0,end
14801545            UML_JMPc(block, IF_A, skip);                              // ja      skip
14811546         }
1482         if (mips3.fastram[ramnum].start != 0x00000000)
1547         if (mips3->impstate->fastram[ramnum].start != 0x00000000)
14831548         {
1484            UML_CMP(block, IREG(0), IMM(mips3.fastram[ramnum].start));         // cmp     i0,fastram_start
1549            UML_CMP(block, IREG(0), IMM(mips3->impstate->fastram[ramnum].start));// cmp     i0,fastram_start
14851550            UML_JMPc(block, IF_B, skip);                              // jb      skip
14861551         }
14871552
r2762r2763
14891554         {
14901555            if (size == 1)
14911556            {
1492               UML_XOR(block, IREG(0), IREG(0), IMM(mips3.core->bigendian ? BYTE4_XOR_BE(0) : BYTE4_XOR_LE(0)));
1557               UML_XOR(block, IREG(0), IREG(0), IMM(mips3->bigendian ? BYTE4_XOR_BE(0) : BYTE4_XOR_LE(0)));
14931558                                                               // xor     i0,i0,bytexor
14941559               UML_LOAD1U(block, IREG(0), fastbase, IREG(0));               // load1u  i0,fastbase,i0
14951560            }
14961561            else if (size == 2)
14971562            {
14981563               UML_SHR(block, IREG(0), IREG(0), IMM(1));                  // shr     i0,i0,1
1499               UML_XOR(block, IREG(0), IREG(0), IMM(mips3.core->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0)));
1564               UML_XOR(block, IREG(0), IREG(0), IMM(mips3->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0)));
15001565                                                               // xor     i0,i0,bytexor
15011566               UML_LOAD2U(block, IREG(0), fastbase, IREG(0));               // load2u  i0,fastbase,i0
15021567            }
r2762r2763
15091574            {
15101575               UML_SHR(block, IREG(0), IREG(0), IMM(3));                  // shr     i0,i0,3
15111576               UML_DLOAD8(block, IREG(0), fastbase, IREG(0));               // dload8  i0,fastbase,i0
1512               UML_DROR(block, IREG(0), IREG(0), IMM(32 * (mips3.core->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0))));
1577               UML_DROR(block, IREG(0), IREG(0), IMM(32 * (mips3->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0))));
15131578                                                               // dror    i0,i0,32*bytexor
15141579            }
15151580            UML_RET(block);                                          // ret
r2762r2763
15181583         {
15191584            if (size == 1)
15201585            {
1521               UML_XOR(block, IREG(0), IREG(0), IMM(mips3.core->bigendian ? BYTE4_XOR_BE(0) : BYTE4_XOR_LE(0)));
1586               UML_XOR(block, IREG(0), IREG(0), IMM(mips3->bigendian ? BYTE4_XOR_BE(0) : BYTE4_XOR_LE(0)));
15221587                                                               // xor     i0,i0,bytexor
15231588               UML_STORE1(block, fastbase, IREG(0), IREG(1));               // store1  fastbase,i0,i1
15241589            }
15251590            else if (size == 2)
15261591            {
15271592               UML_SHR(block, IREG(0), IREG(0), IMM(1));                  // shr     i0,i0,1
1528               UML_XOR(block, IREG(0), IREG(0), IMM(mips3.core->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0)));
1593               UML_XOR(block, IREG(0), IREG(0), IMM(mips3->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0)));
15291594                                                               // xor     i0,i0,bytexor
15301595               UML_STORE2(block, fastbase, IREG(0), IREG(1));               // store2  fastbase,i0,i1
15311596            }
r2762r2763
15441609            else if (size == 8)
15451610            {
15461611               UML_SHR(block, IREG(0), IREG(0), IMM(3));                  // shr     i0,i0,3
1547               UML_DROR(block, IREG(1), IREG(1), IMM(32 * (mips3.core->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0))));
1612               UML_DROR(block, IREG(1), IREG(1), IMM(32 * (mips3->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0))));
15481613                                                               // dror    i1,i1,32*bytexor
15491614               if (ismasked)
15501615               {
1551                  UML_DROR(block, IREG(2), IREG(2), IMM(32 * (mips3.core->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0))));
1616                  UML_DROR(block, IREG(2), IREG(2), IMM(32 * (mips3->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0))));
15521617                                                               // dror    i2,i2,32*bytexor
15531618                  UML_DLOAD8(block, IREG(3), fastbase, IREG(0));            // dload8  i3,fastbase,i0
15541619                  UML_DINSERT(block, IREG(3), IREG(1), IMM(0), IREG(2));      // dinsert i3,i1,0,i2
r2762r2763
16211686      if (iswrite)
16221687      {
16231688         UML_TEST(block, IREG(3), IMM(TLB_VALID));                        // test    i3,TLB_VALID
1624         UML_EXHc(block, IF_NZ, mips3.exception[EXCEPTION_TLBMOD], IREG(0));      // exh     tlbmod,i0,nz
1689         UML_EXHc(block, IF_NZ, mips3->impstate->exception[EXCEPTION_TLBMOD], IREG(0));
1690                                                               // exh     tlbmod,i0,nz
16251691      }
16261692      UML_TEST(block, IREG(3), IMM(TLB_PRESENT));                           // test    i3,TLB_PRESENT
16271693      UML_EXHc(block, IF_NZ, exception_tlb, IREG(0));                        // exh     tlb,i0,nz
r2762r2763
16481714   UML_TEST(block, IREG(0), IMM(SR_EXL | SR_ERL));                           // test    i0,SR_EXL | SR_ERL
16491715   UML_MOVc(block, IF_NZ, IREG(2), IMM(0));                              // mov     i2,0,nz
16501716   UML_INSERT(block, IREG(2), IREG(0), IMM(32-26), IMM(0x01));                  // insert  i2,i0,32-26,0x01
1651   UML_MOV(block, MEM(&mips3.cstate->mode), IREG(2));                        // mov     [mode],i2
1717   UML_MOV(block, MEM(&mips3->impstate->mode), IREG(2));                     // mov     [mode],i2
16521718}
16531719
16541720
r2762r2763
16711737      UML_JMPc(block, IF_Z, skip = compiler->labelnum++);                     // jmp     skip,Z
16721738      UML_MOV(block, IREG(0), PARAM(ptype, pvalue));                        // mov     i0,nextpc
16731739      UML_MOV(block, IREG(1), IMM(compiler->cycles));                        // mov     i1,cycles
1674      UML_CALLH(block, mips3.exception_norecover[EXCEPTION_INTERRUPT]);         // callh   interrupt_norecover
1740      UML_CALLH(block, mips3->impstate->exception_norecover[EXCEPTION_INTERRUPT]);// callh   interrupt_norecover
16751741      UML_LABEL(block, skip);                                       // skip:
16761742   }
16771743
r2762r2763
16901756      UML_JMPc(block, IF_NZ, skip);                                    // jmp     skip,NZ
16911757      UML_MOV(block, IREG(0), PARAM(ptype, pvalue));                        // mov     i0,nextpc
16921758      UML_MOV(block, IREG(1), IMM(compiler->cycles));                        // mov     i1,cycles
1693      UML_CALLH(block, mips3.exception_norecover[EXCEPTION_INTERRUPT]);         // callh   interrupt_norecover
1759      UML_CALLH(block, mips3->impstate->exception_norecover[EXCEPTION_INTERRUPT]);// callh   interrupt_norecover
16941760      UML_LABEL(block, skip);                                       // skip:
16951761   }
16961762
16971763   /* account for cycles */
16981764   if (compiler->cycles > 0)
16991765   {
1700      UML_SUBf(block, MEM(&mips3.core->icount), MEM(&mips3.core->icount), MAPVAR_CYCLES, allow_exception ? FLAGS_S : 0);
1766      UML_SUBf(block, MEM(&mips3->icount), MEM(&mips3->icount), MAPVAR_CYCLES, allow_exception ? FLAGS_S : 0);
17011767                                                               // sub     icount,icount,cycles,S
17021768      UML_MAPVAR(block, MAPVAR_CYCLES, 0);                              // mapvar  cycles,0
17031769      if (allow_exception)
1704         UML_EXHc(block, IF_S, mips3.out_of_cycles, PARAM(ptype, pvalue));      // exh     out_of_cycles,nextpc
1770         UML_EXHc(block, IF_S, mips3->impstate->out_of_cycles, PARAM(ptype, pvalue));
1771                                                               // exh     out_of_cycles,nextpc
17051772   }
17061773   compiler->cycles = 0;
17071774}
r2762r2763
17191786      UML_COMMENT(block, "[Validation for %08X]", seqhead->pc);               // comment
17201787
17211788   /* loose verify or single instruction: just compare and fail */
1722   if (!(mips3.drcoptions & MIPS3DRC_STRICT_VERIFY) || seqhead->next == NULL)
1789   if (!(mips3->impstate->drcoptions & MIPS3DRC_STRICT_VERIFY) || seqhead->next == NULL)
17231790   {
17241791      if (!(seqhead->flags & OPFLAG_VIRTUAL_NOOP))
17251792      {
17261793         UML_LOAD4(block, IREG(0), seqhead->opptr.l, IMM(0));               // load4   i0,*opptr
17271794         UML_CMP(block, IREG(0), IMM(*seqhead->opptr.l));                  // cmp     i0,*opptr
1728         UML_EXHc(block, IF_NE, mips3.nocode, IMM(epc(seqhead)));            // exne    nocode,seqhead->pc
1795         UML_EXHc(block, IF_NE, mips3->impstate->nocode, IMM(epc(seqhead)));      // exne    nocode,seqhead->pc
17291796      }
17301797   }
17311798
r2762r2763
17361803      for (curdesc = seqhead->next; curdesc != seqlast->next; curdesc = curdesc->next)
17371804         if (!(curdesc->flags & OPFLAG_VIRTUAL_NOOP))
17381805         {
1739            UML_LOAD4(block, IREG(0), curdesc->opptr.l, IMM(0));               // load4   i0,*opptr
1740            UML_CMP(block, IREG(0), IMM(*curdesc->opptr.l));                  // cmp     i0,*opptr
1741            UML_EXHc(block, IF_NE, mips3.nocode, IMM(epc(seqhead)));            // exne    nocode,seqhead->pc
1806            UML_LOAD4(block, IREG(0), curdesc->opptr.l, IMM(0));            // load4   i0,*opptr
1807            UML_CMP(block, IREG(0), IMM(*curdesc->opptr.l));               // cmp     i0,*opptr
1808            UML_EXHc(block, IF_NE, mips3->impstate->nocode, IMM(epc(seqhead)));   // exne    nocode,seqhead->pc
17421809         }
17431810#else
17441811      UINT32 sum = 0;
r2762r2763
17471814      for (curdesc = seqhead->next; curdesc != seqlast->next; curdesc = curdesc->next)
17481815         if (!(curdesc->flags & OPFLAG_VIRTUAL_NOOP))
17491816         {
1750            UML_LOAD4(block, IREG(1), curdesc->opptr.l, IMM(0));               // load4   i1,*opptr
1751            UML_ADD(block, IREG(0), IREG(0), IREG(1));                        // add     i0,i0,i1
1817            UML_LOAD4(block, IREG(1), curdesc->opptr.l, IMM(0));            // load4   i1,*opptr
1818            UML_ADD(block, IREG(0), IREG(0), IREG(1));                     // add     i0,i0,i1
17521819            sum += *curdesc->opptr.l;
17531820         }
17541821      UML_CMP(block, IREG(0), IMM(sum));                                 // cmp     i0,sum
1755      UML_EXHc(block, IF_NE, mips3.nocode, IMM(epc(seqhead)));               // exne    nocode,seqhead->pc
1822      UML_EXHc(block, IF_NE, mips3->impstate->nocode, IMM(epc(seqhead)));         // exne    nocode,seqhead->pc
17561823#endif
17571824   }
17581825}
r2762r2763
17811848
17821849   /* is this a hotspot? */
17831850   for (hotnum = 0; hotnum < MIPS3_MAX_HOTSPOTS; hotnum++)
1784      if (mips3.hotspot[hotnum].pc != 0 && desc->pc == mips3.hotspot[hotnum].pc && *desc->opptr.l == mips3.hotspot[hotnum].opcode)
1851      if (mips3->impstate->hotspot[hotnum].pc != 0 && desc->pc == mips3->impstate->hotspot[hotnum].pc && *desc->opptr.l == mips3->impstate->hotspot[hotnum].opcode)
17851852      {
1786         compiler->cycles += mips3.hotspot[hotnum].cycles;
1853         compiler->cycles += mips3->impstate->hotspot[hotnum].cycles;
17871854         break;
17881855      }
17891856
r2762r2763
17971864   /* if we are debugging, call the debugger */
17981865   if (Machine->debug_mode)
17991866   {
1800      UML_MOV(block, MEM(&mips3.core->pc), IMM(desc->pc));                  // mov     [pc],desc->pc
1867      UML_MOV(block, MEM(&mips3->pc), IMM(desc->pc));                        // mov     [pc],desc->pc
18011868      save_fast_iregs(block);
18021869      UML_DEBUG(block, IMM(desc->pc));                                 // debug   desc->pc
18031870   }
r2762r2763
18051872   /* if we hit an unmapped address, fatal error */
18061873   if (desc->flags & OPFLAG_COMPILER_UNMAPPED)
18071874   {
1808      UML_MOV(block, MEM(&mips3.core->pc), IMM(desc->pc));                  // mov     [pc],desc->pc
1875      UML_MOV(block, MEM(&mips3->pc), IMM(desc->pc));                        // mov     [pc],desc->pc
18091876      save_fast_iregs(block);
18101877      UML_EXIT(block, IMM(EXECUTE_UNMAPPED_CODE));                        // exit    EXECUTE_UNMAPPED_CODE
18111878   }
r2762r2763
18151882   {
18161883      if (PRINTF_MMU)
18171884      {
1818         UML_MOV(block, MEM(&mips3.cstate->arg0), IMM(desc->pc));            // mov     [arg0],desc->pc
1885         UML_MOV(block, MEM(&mips3->impstate->arg0), IMM(desc->pc));            // mov     [arg0],desc->pc
18191886         UML_CALLC(block, cfunc_printf_debug, "Compiler page fault @ %08X\n");   // callc   printf_debug
18201887      }
1821      UML_EXH(block, mips3.tlb_mismatch, IMM(0));                           // exh     tlb_mismatch,0
1888      UML_EXH(block, mips3->impstate->tlb_mismatch, IMM(0));                  // exh     tlb_mismatch,0
18221889   }
18231890
18241891   /* validate our TLB entry at this PC; if we fail, we need to handle it */
18251892   if ((desc->flags & OPFLAG_VALIDATE_TLB) && (desc->pc < 0x80000000 || desc->pc >= 0xc0000000))
18261893   {
18271894      /* if we currently have a valid TLB read entry, we just verify */
1828      if (mips3.core->tlb_table[desc->pc >> 12] & TLB_VALID)
1895      if (mips3->tlb_table[desc->pc >> 12] & TLB_VALID)
18291896      {
18301897         if (PRINTF_MMU)
18311898         {
1832            UML_MOV(block, MEM(&mips3.cstate->arg0), IMM(desc->pc));         // mov     [arg0],desc->pc
1899            UML_MOV(block, MEM(&mips3->impstate->arg0), IMM(desc->pc));         // mov     [arg0],desc->pc
18331900            UML_CALLC(block, cfunc_printf_debug, "Checking TLB at @ %08X\n");   // callc   printf_debug
18341901         }
1835         UML_LOAD4(block, IREG(0), &mips3.core->tlb_table[desc->pc >> 12], IMM(0));// load4   i0,tlb_table[desc->pc >> 12]
1836         UML_CMP(block, IREG(0), IMM(mips3.core->tlb_table[desc->pc >> 12]));   // cmp     i0,*tlbentry
1837         UML_EXHc(block, IF_NE, mips3.tlb_mismatch, IMM(0));                  // exh     tlb_mismatch,0,NE
1902         UML_LOAD4(block, IREG(0), &mips3->tlb_table[desc->pc >> 12], IMM(0));   // load4   i0,tlb_table[desc->pc >> 12]
1903         UML_CMP(block, IREG(0), IMM(mips3->tlb_table[desc->pc >> 12]));         // cmp     i0,*tlbentry
1904         UML_EXHc(block, IF_NE, mips3->impstate->tlb_mismatch, IMM(0));         // exh     tlb_mismatch,0,NE
18381905      }
18391906
18401907      /* otherwise, we generate an unconditional exception */
r2762r2763
18421909      {
18431910         if (PRINTF_MMU)
18441911         {
1845            UML_MOV(block, MEM(&mips3.cstate->arg0), IMM(desc->pc));         // mov     [arg0],desc->pc
1912            UML_MOV(block, MEM(&mips3->impstate->arg0), IMM(desc->pc));         // mov     [arg0],desc->pc
18461913            UML_CALLC(block, cfunc_printf_debug, "No valid TLB @ %08X\n");      // callc   printf_debug
18471914         }
1848         UML_EXH(block, mips3.tlb_mismatch, IMM(0));                        // exh     tlb_mismatch,0
1915         UML_EXH(block, mips3->impstate->tlb_mismatch, IMM(0));               // exh     tlb_mismatch,0
18491916      }
18501917   }
18511918
18521919   /* if this is an invalid opcode, generate the exception now */
18531920   if (desc->flags & OPFLAG_INVALID_OPCODE)
1854      UML_EXH(block, mips3.exception[EXCEPTION_INVALIDOP], IMM(0));            // exh     invalidop,0
1921      UML_EXH(block, mips3->impstate->exception[EXCEPTION_INVALIDOP], IMM(0));   // exh     invalidop,0
18551922
18561923   /* otherwise, unless this is a virtual no-op, it's a regular instruction */
18571924   else if (!(desc->flags & OPFLAG_VIRTUAL_NOOP))
r2762r2763
18591926      /* compile the instruction */
18601927      if (!generate_opcode(block, compiler, desc))
18611928      {
1862         UML_MOV(block, MEM(&mips3.core->pc), IMM(desc->pc));               // mov     [pc],desc->pc
1863         UML_CALLC(block, cfunc_unimplemented, (void *)(FPTR)*desc->opptr.l);         // callc   cfunc_unimplemented
1929         UML_MOV(block, MEM(&mips3->pc), IMM(desc->pc));                     // mov     [pc],desc->pc
1930         UML_CALLC(block, cfunc_unimplemented, (void *)(FPTR)*desc->opptr.l);   // callc   cfunc_unimplemented
18641931      }
18651932   }
18661933}
r2762r2763
18901957      if (desc->flags & OPFLAG_INTRABLOCK_BRANCH)
18911958         UML_JMP(block, desc->targetpc | 0x80000000);                     // jmp     desc->targetpc | 0x80000000
18921959      else
1893         UML_HASHJMP(block, IMM(mips3.cstate->mode), IMM(desc->targetpc), mips3.nocode);
1960         UML_HASHJMP(block, IMM(mips3->impstate->mode), IMM(desc->targetpc), mips3->impstate->nocode);
18941961                                                               // hashjmp <mode>,desc->targetpc,nocode
18951962   }
18961963   else
18971964   {
18981965      generate_update_cycles(block, &compiler_temp, R32(RSREG), TRUE);
18991966                                                               // <subtract cycles>
1900      UML_HASHJMP(block, IMM(mips3.cstate->mode), R32(RSREG), mips3.nocode);      // hashjmp <mode>,<rsreg>,nocode
1967      UML_HASHJMP(block, IMM(mips3->impstate->mode), R32(RSREG), mips3->impstate->nocode);
1968                                                               // hashjmp <mode>,<rsreg>,nocode
19011969   }
19021970
19031971   /* update the label */
r2762r2763
19902058         return TRUE;
19912059
19922060      case 0x08:   /* ADDI - MIPS I */
1993         if (mips3.drcoptions & MIPS3DRC_CHECK_OVERFLOWS)
2061         if (mips3->impstate->drcoptions & MIPS3DRC_CHECK_OVERFLOWS)
19942062         {
19952063            UML_ADDf(block, IREG(0), R32(RSREG), IMM(SIMMVAL), FLAGS_V);      // add     i0,<rsreg>,SIMMVAL,V
1996            UML_EXHc(block, IF_V, mips3.exception[EXCEPTION_OVERFLOW], IMM(0));   // exh    overflow,0
2064            UML_EXHc(block, IF_V, mips3->impstate->exception[EXCEPTION_OVERFLOW], IMM(0));
2065                                                               // exh    overflow,0
19972066         }
19982067         else
19992068            UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));               // add     i0,<rsreg>,SIMMVAL
r2762r2763
20102079         return TRUE;
20112080
20122081      case 0x18:   /* DADDI - MIPS III */
2013         if (mips3.drcoptions & MIPS3DRC_CHECK_OVERFLOWS)
2082         if (mips3->impstate->drcoptions & MIPS3DRC_CHECK_OVERFLOWS)
20142083         {
20152084            UML_DADDf(block, IREG(0), R64(RSREG), IMM(SIMMVAL), FLAGS_V);      // dadd    i0,<rsreg>,SIMMVAL,V
2016            UML_EXHc(block, IF_V, mips3.exception[EXCEPTION_OVERFLOW], IMM(0));   // exh    overflow,0
2085            UML_EXHc(block, IF_V, mips3->impstate->exception[EXCEPTION_OVERFLOW], IMM(0));
2086                                                               // exh    overflow,0
20172087         }
20182088         else
20192089            UML_DADD(block, IREG(0), R64(RSREG), IMM(SIMMVAL));               // dadd    i0,<rsreg>,SIMMVAL
r2762r2763
20452115         if (RTREG != 0)
20462116         {
20472117            UML_DCMP(block, R64(RSREG), IMM(SIMMVAL));                     // dcmp    <rsreg>,SIMMVAL
2048            UML_DFLAGS(block, R64(RTREG), (UINT64)~0, mips3.cstate->slt_table);   // dflags  <rtreg>,~0,slt_table
2118            UML_DFLAGS(block, R64(RTREG), (UINT64)~0, mips3->impstate->slt_table);
2119                                                               // dflags  <rtreg>,~0,slt_table
20492120         }
20502121         return TRUE;
20512122
r2762r2763
20532124         if (RTREG != 0)
20542125         {
20552126            UML_DCMP(block, R64(RSREG), IMM(SIMMVAL));                     // dcmp    <rsreg>,SIMMVAL
2056            UML_DFLAGS(block, R64(RTREG), (UINT64)~0, mips3.cstate->sltu_table);// dflags  <rtreg>,~0,sltu_table
2127            UML_DFLAGS(block, R64(RTREG), (UINT64)~0, mips3->impstate->sltu_table);
2128                                                               // dflags  <rtreg>,~0,sltu_table
20572129         }
20582130         return TRUE;
20592131
r2762r2763
20622134
20632135      case 0x20:   /* LB - MIPS I */
20642136         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
2065         UML_CALLH(block, mips3.read8[mips3.cstate->mode >> 1]);               // callh   read8
2137         UML_CALLH(block, mips3->impstate->read8[mips3->impstate->mode >> 1]);   // callh   read8
20662138         if (RTREG != 0)
20672139            UML_DSEXT1(block, R64(RTREG), IREG(0));                        // dsext1  <rtreg>,i0
20682140         if (!in_delay_slot)
r2762r2763
20712143
20722144      case 0x21:   /* LH - MIPS I */
20732145         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
2074         UML_CALLH(block, mips3.read16[mips3.cstate->mode >> 1]);            // callh   read16
2146         UML_CALLH(block, mips3->impstate->read16[mips3->impstate->mode >> 1]);   // callh   read16
20752147         if (RTREG != 0)
20762148            UML_DSEXT2(block, R64(RTREG), IREG(0));                        // dsext2  <rtreg>,i0
20772149         if (!in_delay_slot)
r2762r2763
20802152
20812153      case 0x23:   /* LW - MIPS I */
20822154         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
2083         UML_CALLH(block, mips3.read32[mips3.cstate->mode >> 1]);            // callh   read32
2155         UML_CALLH(block, mips3->impstate->read32[mips3->impstate->mode >> 1]);   // callh   read32
20842156         if (RTREG != 0)
20852157            UML_DSEXT4(block, R64(RTREG), IREG(0));                        // dsext4  <rtreg>,i0
20862158         if (!in_delay_slot)
r2762r2763
20892161
20902162      case 0x24:   /* LBU - MIPS I */
20912163         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
2092         UML_CALLH(block, mips3.read8[mips3.cstate->mode >> 1]);               // callh   read8
2164         UML_CALLH(block, mips3->impstate->read8[mips3->impstate->mode >> 1]);   // callh   read8
20932165         if (RTREG != 0)
20942166            UML_DZEXT1(block, R64(RTREG), IREG(0));                        // dzext1  <rtreg>,i0
20952167         if (!in_delay_slot)
r2762r2763
20982170
20992171      case 0x25:   /* LHU - MIPS I */
21002172         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
2101         UML_CALLH(block, mips3.read16[mips3.cstate->mode >> 1]);            // callh   read16
2173         UML_CALLH(block, mips3->impstate->read16[mips3->impstate->mode >> 1]);   // callh   read16
21022174         if (RTREG != 0)
21032175            UML_DZEXT2(block, R64(RTREG), IREG(0));                        // dzext2  <rtreg>,i0
21042176         if (!in_delay_slot)
r2762r2763
21072179
21082180      case 0x27:   /* LWU - MIPS III */
21092181         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
2110         UML_CALLH(block, mips3.read32[mips3.cstate->mode >> 1]);            // callh   read32
2182         UML_CALLH(block, mips3->impstate->read32[mips3->impstate->mode >> 1]);   // callh   read32
21112183         if (RTREG != 0)
21122184            UML_DZEXT4(block, R64(RTREG), IREG(0));                        // dzext4  <rtreg>,i0
21132185         if (!in_delay_slot)
r2762r2763
21162188
21172189      case 0x37:   /* LD - MIPS III */
21182190         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
2119         UML_CALLH(block, mips3.read64[mips3.cstate->mode >> 1]);            // callh   read64
2191         UML_CALLH(block, mips3->impstate->read64[mips3->impstate->mode >> 1]);   // callh   read64
21202192         if (RTREG != 0)
21212193            UML_DMOV(block, R64(RTREG), IREG(0));                        // dmov    <rtreg>,i0
21222194         if (!in_delay_slot)
r2762r2763
21262198      case 0x22:   /* LWL - MIPS I */
21272199         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
21282200         UML_SHL(block, IREG(1), IREG(0), IMM(3));                        // shl     i1,i0,3
2129         if (!mips3.core->bigendian)
2201         if (!mips3->bigendian)
21302202            UML_XOR(block, IREG(1), IREG(1), IMM(0x18));                  // xor     i1,i1,0x18
21312203         UML_SHR(block, IREG(2), IMM(~0), IREG(1));                        // shr     i2,~0,i1
2132         UML_CALLH(block, mips3.read32mask[mips3.cstate->mode >> 1]);         // callh   read32mask
2204         UML_CALLH(block, mips3->impstate->read32mask[mips3->impstate->mode >> 1]);
2205                                                               // callh   read32mask
21332206         if (RTREG != 0)
21342207         {
21352208            UML_SHL(block, IREG(2), IMM(~0), IREG(1));                     // shl     i2,~0,i1
r2762r2763
21442217      case 0x26:   /* LWR - MIPS I */
21452218         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
21462219         UML_SHL(block, IREG(1), IREG(0), IMM(3));                        // shl     i1,i0,3
2147         if (mips3.core->bigendian)
2220         if (mips3->bigendian)
21482221            UML_XOR(block, IREG(1), IREG(1), IMM(0x18));                  // xor     i1,i1,0x18
21492222         UML_SHL(block, IREG(2), IMM(~0), IREG(1));                        // shl     i2,~0,i1
2150         UML_CALLH(block, mips3.read32mask[mips3.cstate->mode >> 1]);         // callh   read32mask
2223         UML_CALLH(block, mips3->impstate->read32mask[mips3->impstate->mode >> 1]);
2224                                                               // callh   read32mask
21512225         if (RTREG != 0)
21522226         {
21532227            UML_SHR(block, IREG(2), IMM(~0), IREG(1));                     // shr     i2,~0,i1
r2762r2763
21632237      case 0x1a:   /* LDL - MIPS III */
21642238         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
21652239         UML_SHL(block, IREG(1), IREG(0), IMM(3));                        // shl     i1,i0,3
2166         if (!mips3.core->bigendian)
2240         if (!mips3->bigendian)
21672241            UML_XOR(block, IREG(1), IREG(1), IMM(0x38));                  // xor     i1,i1,0x38
21682242         UML_DSHR(block, IREG(2), IMM((UINT64)~0), IREG(1));                  // dshr    i2,~0,i1
2169         UML_CALLH(block, mips3.read64mask[mips3.cstate->mode >> 1]);         // callh   read64mask
2243         UML_CALLH(block, mips3->impstate->read64mask[mips3->impstate->mode >> 1]);
2244                                                               // callh   read64mask
21702245         if (RTREG != 0)
21712246         {
21722247            UML_DSHL(block, IREG(2), IMM((UINT64)~0), IREG(1));               // dshl    i2,~0,i1
r2762r2763
21792254      case 0x1b:   /* LDR - MIPS III */
21802255         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
21812256         UML_SHL(block, IREG(1), IREG(0), IMM(3));                        // shl     i1,i0,3
2182         if (mips3.core->bigendian)
2257         if (mips3->bigendian)
21832258            UML_XOR(block, IREG(1), IREG(1), IMM(0x38));                  // xor     i1,i1,0x38
21842259         UML_DSHL(block, IREG(2), IMM((UINT64)~0), IREG(1));                  // dshl    i2,~0,i1
2185         UML_CALLH(block, mips3.read64mask[mips3.cstate->mode >> 1]);         // callh   read64mask
2260         UML_CALLH(block, mips3->impstate->read64mask[mips3->impstate->mode >> 1]);
2261                                                               // callh   read64mask
21862262         if (RTREG != 0)
21872263         {
21882264            UML_DSHR(block, IREG(2), IMM((UINT64)~0), IREG(1));               // dshr    i2,~0,i1
r2762r2763
21952271
21962272      case 0x31:   /* LWC1 - MIPS I */
21972273         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
2198         UML_CALLH(block, mips3.read32[mips3.cstate->mode >> 1]);            // callh   read32
2274         UML_CALLH(block, mips3->impstate->read32[mips3->impstate->mode >> 1]);   // callh   read32
21992275         UML_MOV(block, FPR32(RTREG), IREG(0));                           // mov     <cpr1_rt>,i0
22002276         if (!in_delay_slot)
22012277            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
r2762r2763
22032279
22042280      case 0x35:   /* LDC1 - MIPS III */
22052281         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
2206         UML_CALLH(block, mips3.read64[mips3.cstate->mode >> 1]);            // callh   read64
2282         UML_CALLH(block, mips3->impstate->read64[mips3->impstate->mode >> 1]);   // callh   read64
22072283         UML_DMOV(block, FPR64(RTREG), IREG(0));                           // dmov    <cpr1_rt>,i0
22082284         if (!in_delay_slot)
22092285            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
r2762r2763
22112287
22122288      case 0x32:   /* LWC2 - MIPS I */
22132289         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
2214         UML_CALLH(block, mips3.read32[mips3.cstate->mode >> 1]);            // callh   read32
2290         UML_CALLH(block, mips3->impstate->read32[mips3->impstate->mode >> 1]);   // callh   read32
22152291         UML_DZEXT4(block, CPR264(RTREG), IREG(0));                        // dzext4  <cpr2_rt>,i0
22162292         if (!in_delay_slot)
22172293            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
r2762r2763
22192295
22202296      case 0x36:   /* LDC2 - MIPS II */
22212297         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
2222         UML_CALLH(block, mips3.read64[mips3.cstate->mode >> 1]);            // callh   read64
2298         UML_CALLH(block, mips3->impstate->read64[mips3->impstate->mode >> 1]);   // callh   read64
22232299         UML_DMOV(block, CPR264(RTREG), IREG(0));                        // dmov    <cpr2_rt>,i0
22242300         if (!in_delay_slot)
22252301            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
r2762r2763
22312307      case 0x28:   /* SB - MIPS I */
22322308         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
22332309         UML_MOV(block, IREG(1), R32(RTREG));                           // mov     i1,<rtreg>
2234         UML_CALLH(block, mips3.write8[mips3.cstate->mode >> 1]);            // callh   write8
2310         UML_CALLH(block, mips3->impstate->write8[mips3->impstate->mode >> 1]);   // callh   write8
22352311         if (!in_delay_slot)
22362312            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
22372313         return TRUE;
r2762r2763
22392315      case 0x29:   /* SH - MIPS I */
22402316         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
22412317         UML_MOV(block, IREG(1), R32(RTREG));                           // mov     i1,<rtreg>
2242         UML_CALLH(block, mips3.write16[mips3.cstate->mode >> 1]);            // callh   write16
2318         UML_CALLH(block, mips3->impstate->write16[mips3->impstate->mode >> 1]);   // callh   write16
22432319         if (!in_delay_slot)
22442320            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
22452321         return TRUE;
r2762r2763
22472323      case 0x2b:   /* SW - MIPS I */
22482324         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
22492325         UML_MOV(block, IREG(1), R32(RTREG));                           // mov     i1,<rtreg>
2250         UML_CALLH(block, mips3.write32[mips3.cstate->mode >> 1]);            // callh   write32
2326         UML_CALLH(block, mips3->impstate->write32[mips3->impstate->mode >> 1]);   // callh   write32
22512327         if (!in_delay_slot)
22522328            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
22532329         return TRUE;
r2762r2763
22552331      case 0x3f:   /* SD - MIPS III */
22562332         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
22572333         UML_DMOV(block, IREG(1), R64(RTREG));                           // dmov    i1,<rtreg>
2258         UML_CALLH(block, mips3.write64[mips3.cstate->mode >> 1]);            // callh   write64
2334         UML_CALLH(block, mips3->impstate->write64[mips3->impstate->mode >> 1]);   // callh   write64
22592335         if (!in_delay_slot)
22602336            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
22612337         return TRUE;
r2762r2763
22642340         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
22652341         UML_SHL(block, IREG(3), IREG(0), IMM(3));                        // shl     i3,i0,3
22662342         UML_MOV(block, IREG(1), R32(RTREG));                           // mov     i1,<rtreg>
2267         if (!mips3.core->bigendian)
2343         if (!mips3->bigendian)
22682344            UML_XOR(block, IREG(3), IREG(3), IMM(0x18));                  // xor     i3,i3,0x18
22692345         UML_SHR(block, IREG(2), IMM(~0), IREG(3));                        // shr     i2,~0,i3
22702346         UML_SHR(block, IREG(1), IREG(1), IREG(3));                        // shr     i1,i1,i3
2271         UML_CALLH(block, mips3.write32mask[mips3.cstate->mode >> 1]);         // callh   write32mask
2347         UML_CALLH(block, mips3->impstate->write32mask[mips3->impstate->mode >> 1]);
2348                                                               // callh   write32mask
22722349         if (!in_delay_slot)
22732350            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
22742351         return TRUE;
r2762r2763
22772354         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
22782355         UML_SHL(block, IREG(3), IREG(0), IMM(3));                        // shl     i3,i0,3
22792356         UML_MOV(block, IREG(1), R32(RTREG));                           // mov     i1,<rtreg>
2280         if (mips3.core->bigendian)
2357         if (mips3->bigendian)
22812358            UML_XOR(block, IREG(3), IREG(3), IMM(0x18));                  // xor     i3,i3,0x18
22822359         UML_SHL(block, IREG(2), IMM(~0), IREG(3));                        // shl     i2,~0,i3
22832360         UML_SHL(block, IREG(1), IREG(1), IREG(3));                        // shl     i1,i1,i3
2284         UML_CALLH(block, mips3.write32mask[mips3.cstate->mode >> 1]);         // callh   write32mask
2361         UML_CALLH(block, mips3->impstate->write32mask[mips3->impstate->mode >> 1]);
2362                                                               // callh   write32mask
22852363         if (!in_delay_slot)
22862364            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
22872365         return TRUE;
r2762r2763
22902368         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
22912369         UML_SHL(block, IREG(3), IREG(0), IMM(3));                        // shl     i3,i0,3
22922370         UML_DMOV(block, IREG(1), R64(RTREG));                           // dmov    i1,<rtreg>
2293         if (!mips3.core->bigendian)
2371         if (!mips3->bigendian)
22942372            UML_XOR(block, IREG(3), IREG(3), IMM(0x38));                  // xor     i3,i3,0x38
22952373         UML_DSHR(block, IREG(2), IMM((UINT64)~0), IREG(3));                  // dshr    i2,~0,i3
22962374         UML_DSHR(block, IREG(1), IREG(1), IREG(3));                        // dshr    i1,i1,i3
2297         UML_CALLH(block, mips3.write64mask[mips3.cstate->mode >> 1]);         // callh   write64mask
2375         UML_CALLH(block, mips3->impstate->write64mask[mips3->impstate->mode >> 1]);
2376                                                               // callh   write64mask
22982377         if (!in_delay_slot)
22992378            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
23002379         return TRUE;
r2762r2763
23032382         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
23042383         UML_SHL(block, IREG(3), IREG(0), IMM(3));                        // shl     i3,i0,3
23052384         UML_DMOV(block, IREG(1), R64(RTREG));                           // dmov    i1,<rtreg>
2306         if (mips3.core->bigendian)
2385         if (mips3->bigendian)
23072386            UML_XOR(block, IREG(3), IREG(3), IMM(0x38));                  // xor     i3,i3,0x38
23082387         UML_DSHL(block, IREG(2), IMM((UINT64)~0), IREG(3));                  // dshl    i2,~0,i3
23092388         UML_DSHL(block, IREG(1), IREG(1), IREG(3));                        // dshl    i1,i1,i3
2310         UML_CALLH(block, mips3.write64mask[mips3.cstate->mode >> 1]);         // callh   write64mask
2389         UML_CALLH(block, mips3->impstate->write64mask[mips3->impstate->mode >> 1]);
2390                                                               // callh   write64mask
23112391         if (!in_delay_slot)
23122392            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
23132393         return TRUE;
r2762r2763
23152395      case 0x39:   /* SWC1 - MIPS I */
23162396         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
23172397         UML_MOV(block, IREG(1), FPR32(RTREG));                           // mov     i1,<cpr1_rt>
2318         UML_CALLH(block, mips3.write32[mips3.cstate->mode >> 1]);            // callh   write32
2398         UML_CALLH(block, mips3->impstate->write32[mips3->impstate->mode >> 1]);   // callh   write32
23192399         if (!in_delay_slot)
23202400            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
23212401         return TRUE;
r2762r2763
23232403      case 0x3d:   /* SDC1 - MIPS III */
23242404         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
23252405         UML_DMOV(block, IREG(1), FPR64(RTREG));                           // dmov    i1,<cpr1_rt>
2326         UML_CALLH(block, mips3.write64[mips3.cstate->mode >> 1]);            // callh   write64
2406         UML_CALLH(block, mips3->impstate->write64[mips3->impstate->mode >> 1]);   // callh   write64
23272407         if (!in_delay_slot)
23282408            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
23292409         return TRUE;
r2762r2763
23312411      case 0x3a:   /* SWC2 - MIPS I */
23322412         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
23332413         UML_MOV(block, IREG(1), CPR232(RTREG));                           // mov     i1,<cpr2_rt>
2334         UML_CALLH(block, mips3.write32[mips3.cstate->mode >> 1]);            // callh   write32
2414         UML_CALLH(block, mips3->impstate->write32[mips3->impstate->mode >> 1]);   // callh   write32
23352415         if (!in_delay_slot)
23362416            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
23372417         return TRUE;
r2762r2763
23392419      case 0x3e:   /* SDC2 - MIPS II */
23402420         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
23412421         UML_DMOV(block, IREG(1), CPR264(RTREG));                        // dmov    i1,<cpr2_rt>
2342         UML_CALLH(block, mips3.write64[mips3.cstate->mode >> 1]);            // callh   write64
2422         UML_CALLH(block, mips3->impstate->write64[mips3->impstate->mode >> 1]);   // callh   write64
23432423         if (!in_delay_slot)
23442424            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
23452425         return TRUE;
r2762r2763
23642444         return generate_cop1x(block, compiler, desc);
23652445
23662446      case 0x12:   /* COP2 - MIPS I */
2367         UML_EXH(block, mips3.exception[EXCEPTION_INVALIDOP], IMM(0));            // exh     invalidop,0
2447         UML_EXH(block, mips3->impstate->exception[EXCEPTION_INVALIDOP], IMM(0));// exh     invalidop,0
23682448         return TRUE;
23692449
23702450
r2762r2763
24922572      /* ----- basic arithmetic ----- */
24932573
24942574      case 0x20:   /* ADD - MIPS I */
2495         if (mips3.drcoptions & MIPS3DRC_CHECK_OVERFLOWS)
2575         if (mips3->impstate->drcoptions & MIPS3DRC_CHECK_OVERFLOWS)
24962576         {
24972577            UML_ADDf(block, IREG(0), R32(RSREG), R32(RTREG), FLAGS_V);         // add     i0,<rsreg>,<rtreg>,V
2498            UML_EXHc(block, IF_V, mips3.exception[EXCEPTION_OVERFLOW], IMM(0));   // exh     overflow,0,V
2578            UML_EXHc(block, IF_V, mips3->impstate->exception[EXCEPTION_OVERFLOW], IMM(0));
2579                                                               // exh     overflow,0,V
24992580            if (RDREG != 0)
25002581               UML_DSEXT4(block, R64(RDREG), IREG(0));                     // dsext4  <rdreg>,i0
25012582         }
r2762r2763
25152596         return TRUE;
25162597
25172598      case 0x2c:   /* DADD - MIPS III */
2518         if (mips3.drcoptions & MIPS3DRC_CHECK_OVERFLOWS)
2599         if (mips3->impstate->drcoptions & MIPS3DRC_CHECK_OVERFLOWS)
25192600         {
25202601            UML_DADDf(block, IREG(0), R64(RSREG), R64(RTREG), FLAGS_V);         // dadd    i0,<rsreg>,<rtreg>,V
2521            UML_EXHc(block, IF_V, mips3.exception[EXCEPTION_OVERFLOW], IMM(0));   // exh     overflow,0,V
2602            UML_EXHc(block, IF_V, mips3->impstate->exception[EXCEPTION_OVERFLOW], IMM(0));
2603                                                               // exh     overflow,0,V
25222604            if (RDREG != 0)
25232605               UML_DMOV(block, R64(RDREG), IREG(0));                     // dmov    <rdreg>,i0
25242606         }
r2762r2763
25322614         return TRUE;
25332615
25342616      case 0x22:   /* SUB - MIPS I */
2535         if (mips3.drcoptions & MIPS3DRC_CHECK_OVERFLOWS)
2617         if (mips3->impstate->drcoptions & MIPS3DRC_CHECK_OVERFLOWS)
25362618         {
25372619            UML_SUBf(block, IREG(0), R32(RSREG), R32(RTREG), FLAGS_V);         // sub     i0,<rsreg>,<rtreg>,V
2538            UML_EXHc(block, IF_V, mips3.exception[EXCEPTION_OVERFLOW], IMM(0));   // exh     overflow,0,V
2620            UML_EXHc(block, IF_V, mips3->impstate->exception[EXCEPTION_OVERFLOW], IMM(0));
2621                                                               // exh     overflow,0,V
25392622            if (RDREG != 0)
25402623               UML_DSEXT4(block, R64(RDREG), IREG(0));                     // dsext4  <rdreg>,i0
25412624         }
r2762r2763
25552638         return TRUE;
25562639
25572640      case 0x2e:   /* DSUB - MIPS III */
2558         if (mips3.drcoptions & MIPS3DRC_CHECK_OVERFLOWS)
2641         if (mips3->impstate->drcoptions & MIPS3DRC_CHECK_OVERFLOWS)
25592642         {
25602643            UML_DSUBf(block, IREG(0), R64(RSREG), R64(RTREG), FLAGS_V);         // dsub    i0,<rsreg>,<rtreg>,V
2561            UML_EXHc(block, IF_V, mips3.exception[EXCEPTION_OVERFLOW], IMM(0));   // exh     overflow,0,V
2644            UML_EXHc(block, IF_V, mips3->impstate->exception[EXCEPTION_OVERFLOW], IMM(0));
2645                                                               // exh     overflow,0,V
25622646            if (RDREG != 0)
25632647               UML_DMOV(block, R64(RDREG), IREG(0));                     // dmov    <rdreg>,i0
25642648         }
r2762r2763
26442728         if (RDREG != 0)
26452729         {
26462730            UML_DCMP(block, R64(RSREG), R64(RTREG));                     // dcmp    <rsreg>,<rtreg>
2647            UML_DFLAGS(block, R64(RDREG), (UINT64)~0, mips3.cstate->slt_table);   // dflags  <rdreg>,~0,slt_table
2731            UML_DFLAGS(block, R64(RDREG), (UINT64)~0, mips3->impstate->slt_table);// dflags  <rdreg>,~0,slt_table
26482732         }
26492733         return TRUE;
26502734
r2762r2763
26522736         if (RDREG != 0)
26532737         {
26542738            UML_DCMP(block, R64(RSREG), R64(RTREG));                     // dcmp    <rsreg>,<rtreg>
2655            UML_DFLAGS(block, R64(RDREG), (UINT64)~0, mips3.cstate->sltu_table);// dflags  <rdreg>,~0,sltu_table
2739            UML_DFLAGS(block, R64(RDREG), (UINT64)~0, mips3->impstate->sltu_table);// dflags  <rdreg>,~0,sltu_table
26562740         }
26572741         return TRUE;
26582742
r2762r2763
26612745
26622746      case 0x30:   /* TGE - MIPS II */
26632747         UML_DCMP(block, R64(RSREG), R64(RTREG));                        // dcmp    <rsreg>,<rtreg>
2664         UML_EXHc(block, IF_GE, mips3.exception[EXCEPTION_TRAP], IMM(0));      // exh     trap,0,GE
2748         UML_EXHc(block, IF_GE, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh     trap,0,GE
26652749         return TRUE;
26662750
26672751      case 0x31:   /* TGEU - MIPS II */
26682752         UML_DCMP(block, R64(RSREG), R64(RTREG));                        // dcmp    <rsreg>,<rtreg>
2669         UML_EXHc(block, IF_AE, mips3.exception[EXCEPTION_TRAP], IMM(0));      // exh     trap,0,AE
2753         UML_EXHc(block, IF_AE, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh     trap,0,AE
26702754         return TRUE;
26712755
26722756      case 0x32:   /* TLT - MIPS II */
26732757         UML_DCMP(block, R64(RSREG), R64(RTREG));                        // dcmp    <rsreg>,<rtreg>
2674         UML_EXHc(block, IF_L, mips3.exception[EXCEPTION_TRAP], IMM(0));         // exh     trap,0,LT
2758         UML_EXHc(block, IF_L, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh     trap,0,LT
26752759         return TRUE;
26762760
26772761      case 0x33:   /* TLTU - MIPS II */
26782762         UML_DCMP(block, R64(RSREG), R64(RTREG));                        // dcmp    <rsreg>,<rtreg>
2679         UML_EXHc(block, IF_B, mips3.exception[EXCEPTION_TRAP], IMM(0));         // exh     trap,0,B
2763         UML_EXHc(block, IF_B, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh     trap,0,B
26802764         return TRUE;
26812765
26822766      case 0x34:   /* TEQ - MIPS II */
26832767         UML_DCMP(block, R64(RSREG), R64(RTREG));                        // dcmp    <rsreg>,<rtreg>
2684         UML_EXHc(block, IF_E, mips3.exception[EXCEPTION_TRAP], IMM(0));         // exh     trap,0,E
2768         UML_EXHc(block, IF_E, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh     trap,0,E
26852769         return TRUE;
26862770
26872771      case 0x36:   /* TNE - MIPS II */
26882772         UML_DCMP(block, R64(RSREG), R64(RTREG));                        // dcmp    <rsreg>,<rtreg>
2689         UML_EXHc(block, IF_NE, mips3.exception[EXCEPTION_TRAP], IMM(0));      // exh     trap,0,NE
2773         UML_EXHc(block, IF_NE, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh     trap,0,NE
26902774         return TRUE;
26912775
26922776
r2762r2763
27322816      /* ----- system calls ----- */
27332817
27342818      case 0x0c:   /* SYSCALL - MIPS I */
2735         UML_EXH(block, mips3.exception[EXCEPTION_SYSCALL], IMM(0));            // exh     syscall,0
2819         UML_EXH(block, mips3->impstate->exception[EXCEPTION_SYSCALL], IMM(0));   // exh     syscall,0
27362820         return TRUE;
27372821
27382822      case 0x0d:   /* BREAK - MIPS I */
2739         UML_EXH(block, mips3.exception[EXCEPTION_BREAK], IMM(0));            // exh     break,0
2823         UML_EXH(block, mips3->impstate->exception[EXCEPTION_BREAK], IMM(0));   // exh     break,0
27402824         return TRUE;
27412825
27422826
r2762r2763
28162900
28172901      case 0x08:   /* TGEI */
28182902         UML_DCMP(block, R64(RSREG), IMM(SIMMVAL));                        // dcmp    <rsreg>,SIMMVAL
2819         UML_EXHc(block, IF_GE, mips3.exception[EXCEPTION_TRAP], IMM(0));      // exh     trap,0,GE
2903         UML_EXHc(block, IF_GE, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh     trap,0,GE
28202904         return TRUE;
28212905
28222906      case 0x09:   /* TGEIU */
28232907         UML_DCMP(block, R64(RSREG), IMM(SIMMVAL));                        // dcmp    <rsreg>,SIMMVAL
2824         UML_EXHc(block, IF_AE, mips3.exception[EXCEPTION_TRAP], IMM(0));      // exh     trap,0,AE
2908         UML_EXHc(block, IF_AE, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh     trap,0,AE
28252909         return TRUE;
28262910
28272911      case 0x0a:   /* TLTI */
28282912         UML_DCMP(block, R64(RSREG), IMM(SIMMVAL));                        // dcmp    <rsreg>,SIMMVAL
2829         UML_EXHc(block, IF_L, mips3.exception[EXCEPTION_TRAP], IMM(0));         // exh     trap,0,L
2913         UML_EXHc(block, IF_L, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh     trap,0,L
28302914         return TRUE;
28312915
28322916      case 0x0b:   /* TLTIU */
28332917         UML_DCMP(block, R64(RSREG), IMM(SIMMVAL));                        // dcmp    <rsreg>,SIMMVAL
2834         UML_EXHc(block, IF_B, mips3.exception[EXCEPTION_TRAP], IMM(0));         // exh     trap,0,B
2918         UML_EXHc(block, IF_B, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh     trap,0,B
28352919         return TRUE;
28362920
28372921      case 0x0c:   /* TEQI */
28382922         UML_DCMP(block, R64(RSREG), IMM(SIMMVAL));                        // dcmp    <rsreg>,SIMMVAL
2839         UML_EXHc(block, IF_E, mips3.exception[EXCEPTION_TRAP], IMM(0));         // exh     trap,0,E
2923         UML_EXHc(block, IF_E, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh     trap,0,E
28402924         return TRUE;
28412925
28422926      case 0x0e:   /* TNEI */
28432927         UML_DCMP(block, R64(RSREG), IMM(SIMMVAL));                        // dcmp    <rsreg>,SIMMVAL
2844         UML_EXHc(block, IF_NE, mips3.exception[EXCEPTION_TRAP], IMM(0));      // exh     trap,0,NE
2928         UML_EXHc(block, IF_NE, mips3->impstate->exception[EXCEPTION_TRAP], IMM(0));// exh     trap,0,NE
28452929         return TRUE;
28462930   }
28472931   return FALSE;
r2762r2763
28592943   UINT8 opswitch = op & 0x1f;
28602944
28612945   /* only enabled on IDT processors */
2862   if (mips3.core->flavor != MIPS3_TYPE_R4650)
2946   if (mips3->flavor != MIPS3_TYPE_R4650)
28632947      return FALSE;
28642948
28652949   switch (opswitch)
r2762r2763
29243008         generate_update_mode(block);
29253009         UML_XOR(block, IREG(0), IREG(0), IREG(1));                        // xor     i0,i0,i1
29263010         UML_TEST(block, IREG(0), IMM(0x8000));                           // test    i0,0x8000
2927         UML_CALLCc(block, IF_NZ, mips3com_update_cycle_counting, mips3.core);   // callc   mips3com_update_cycle_counting,mips.core,NZ
3011         UML_CALLCc(block, IF_NZ, mips3com_update_cycle_counting, mips3);      // callc   mips3com_update_cycle_counting,mips.core,NZ
29283012         compiler->checkints = TRUE;
29293013         if (!in_delay_slot)
29303014            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
r2762r2763
29333017      case COP0_Count:
29343018         generate_update_cycles(block, compiler, IMM(desc->pc), !in_delay_slot);   // <subtract cycles>
29353019         UML_MOV(block, CPR032(COP0_Count), IREG(0));                     // mov     [Count],i0
2936         UML_CALLC(block, cfunc_get_cycles, &mips3.cstate->numcycles);         // callc   cfunc_get_cycles,&mips3.numcycles
3020         UML_CALLC(block, cfunc_get_cycles, &mips3->impstate->numcycles);      // callc   cfunc_get_cycles,&mips3->impstate->numcycles
29373021         UML_DZEXT4(block, IREG(0), IREG(0));                           // dzext4  i0,i0
29383022         UML_DADD(block, IREG(0), IREG(0), IREG(0));                        // dadd    i0,i0,i0
2939         UML_DSUB(block, MEM(&mips3.core->count_zero_time), MEM(&mips3.cstate->numcycles), IREG(0));
2940                                                               // dsub    [count_zero_time],[mips3.numcycles],i0
2941         UML_CALLC(block, mips3com_update_cycle_counting, mips3.core);         // callc   mips3com_update_cycle_counting,mips.core
3023         UML_DSUB(block, MEM(&mips3->count_zero_time), MEM(&mips3->impstate->numcycles), IREG(0));
3024                                                               // dsub    [count_zero_time],[mips3->impstate->numcycles],i0
3025         UML_CALLC(block, mips3com_update_cycle_counting, mips3);            // callc   mips3com_update_cycle_counting,mips.core
29423026         return TRUE;
29433027
29443028      case COP0_Compare:
29453029         generate_update_cycles(block, compiler, IMM(desc->pc), !in_delay_slot);   // <subtract cycles>
29463030         UML_MOV(block, CPR032(COP0_Compare), IREG(0));                     // mov     [Compare],i0
29473031         UML_AND(block, CPR032(COP0_Cause), CPR032(COP0_Cause), IMM(~0x8000));   // and     [Cause],[Cause],~0x8000
2948         UML_CALLC(block, mips3com_update_cycle_counting, mips3.core);         // callc   mips3com_update_cycle_counting,mips.core
3032         UML_CALLC(block, mips3com_update_cycle_counting, mips3);            // callc   mips3com_update_cycle_counting,mips.core
29493033         return TRUE;
29503034
29513035      case COP0_PRId:
r2762r2763
29603044         UML_MOV(block, CPR032(reg), IREG(0));                           // mov     cpr0[reg],i0
29613045         UML_TEST(block, IREG(1), IMM(0xff));                           // test    i1,0xff
29623046         UML_JMPc(block, IF_Z, link = compiler->labelnum++);                  // jmp     link,z
2963         UML_CALLC(block, mips3com_unmap_tlb_entries, mips3.core);            // callc   mips3com_unmap_tlb_entries
2964         UML_CALLC(block, mips3com_map_tlb_entries, mips3.core);               // callc   mips3com_map_tlb_entries
3047         UML_CALLC(block, mips3com_unmap_tlb_entries, mips3);               // callc   mips3com_unmap_tlb_entries
3048         UML_CALLC(block, mips3com_map_tlb_entries, mips3);                  // callc   mips3com_map_tlb_entries
29653049         UML_LABEL(block, link);                                    // link:
29663050         return TRUE;
29673051
r2762r2763
29853069   {
29863070      case COP0_Count:
29873071         generate_update_cycles(block, compiler, IMM(desc->pc), FALSE);         // <subtract cycles>
2988         UML_CALLC(block, cfunc_get_cycles, &mips3.cstate->numcycles);         // callc   cfunc_get_cycles,&mips3.numcycles
2989         UML_DSUB(block, IREG(0), MEM(&mips3.cstate->numcycles), MEM(&mips3.core->count_zero_time));
3072         UML_CALLC(block, cfunc_get_cycles, &mips3->impstate->numcycles);      // callc   cfunc_get_cycles,&mips3->impstate->numcycles
3073         UML_DSUB(block, IREG(0), MEM(&mips3->impstate->numcycles), MEM(&mips3->count_zero_time));
29903074                                                               // dsub    i0,[numcycles],[count_zero_time]
29913075         UML_DSHR(block, IREG(0), IREG(0), IMM(1));                        // dshr    i0,i0,1
29923076         UML_DSEXT4(block, IREG(0), IREG(0));                           // dsext4  i0,i0
r2762r2763
29943078
29953079      case COP0_Random:
29963080         generate_update_cycles(block, compiler, IMM(desc->pc), FALSE);         // <subtract cycles>
2997         UML_CALLC(block, cfunc_get_cycles, &mips3.cstate->numcycles);         // callc   cfunc_get_cycles,&mips3.numcycles
2998         UML_DSUB(block, IREG(0), MEM(&mips3.cstate->numcycles), MEM(&mips3.core->count_zero_time));
3081         UML_CALLC(block, cfunc_get_cycles, &mips3->impstate->numcycles);      // callc   cfunc_get_cycles,&mips3->impstate->numcycles
3082         UML_DSUB(block, IREG(0), MEM(&mips3->impstate->numcycles), MEM(&mips3->count_zero_time));
29993083                                                               // dsub    i0,[numcycles],[count_zero_time]
30003084         UML_AND(block, IREG(1), CPR032(COP0_Wired), IMM(0x3f));               // and     i1,[Wired],0x3f
30013085         UML_SUBf(block, IREG(2), IMM(48), IREG(1), FLAGS_BE);               // sub     i2,48,i1,ALL
r2762r2763
30253109{
30263110   UINT32 op = *desc->opptr.l;
30273111   UINT8 opswitch = RSREG;
3028   drcuml_codelabel okay;
30293112   int skip;
30303113
3031   /* generate an exception if COP0 is disabled or we are not in kernel mode */
3032   UML_TEST(block, CPR032(COP0_Status), IMM(SR_KSU_MASK));                     // test    [Status],SR_KSU_MASK
3033   UML_JMPc(block, IF_Z, okay = compiler->labelnum++);                        // jmp     okay,Z
3034   UML_TEST(block, CPR032(COP0_Status), IMM(SR_COP0));                        // test    [Status],SR_COP0
3035   UML_EXHc(block, IF_Z, mips3.exception[EXCEPTION_BADCOP], IMM(0));            // exh     cop,0,Z
3036   UML_LABEL(block, okay);                                          // okay:
3114   /* generate an exception if COP0 is disabled unless we are in kernel mode */
3115   if ((mips3->impstate->mode >> 1) != MODE_KERNEL)
3116   {
3117      UML_TEST(block, CPR032(COP0_Status), IMM(SR_COP0));                     // test    [Status],SR_COP0
3118      UML_EXHc(block, IF_Z, mips3->impstate->exception[EXCEPTION_BADCOP], IMM(0));// exh     cop,0,Z
3119   }
30373120
30383121   switch (opswitch)
30393122   {
r2762r2763
30913174         switch (op & 0x01ffffff)
30923175         {
30933176            case 0x01:   /* TLBR */
3094               UML_CALLC(block, mips3com_tlbr, mips3.core);               // callc   mips3com_tlbr,mips3.core
3177               UML_CALLC(block, mips3com_tlbr, mips3);                     // callc   mips3com_tlbr,mips3
30953178               return TRUE;
30963179
30973180            case 0x02:   /* TLBWI */
3098               UML_CALLC(block, mips3com_tlbwi, mips3.core);               // callc   mips3com_tlbwi,mips3.core
3181               UML_CALLC(block, mips3com_tlbwi, mips3);                  // callc   mips3com_tlbwi,mips3
30993182               return TRUE;
31003183
31013184            case 0x06:   /* TLBWR */
3102               UML_CALLC(block, mips3com_tlbwr, mips3.core);               // callc   mips3com_tlbwr,mips3.core
3185               UML_CALLC(block, mips3com_tlbwr, mips3);                  // callc   mips3com_tlbwr,mips3
31033186               return TRUE;
31043187
31053188            case 0x08:   /* TLBP */
3106               UML_CALLC(block, mips3com_tlbp, mips3.core);               // callc   mips3com_tlbp,mips3.core
3189               UML_CALLC(block, mips3com_tlbp, mips3);                     // callc   mips3com_tlbp,mips3
31073190               return TRUE;
31083191
31093192            case 0x18:   /* ERET */
r2762r2763
31153198               generate_update_mode(block);
31163199               compiler->checkints = TRUE;
31173200               generate_update_cycles(block, compiler, CPR032(COP0_EPC), TRUE);// <subtract cycles>
3118               UML_HASHJMP(block, MEM(&mips3.cstate->mode), CPR032(COP0_EPC), mips3.nocode);
3201               UML_HASHJMP(block, MEM(&mips3->impstate->mode), CPR032(COP0_EPC), mips3->impstate->nocode);
31193202                                                               // hashjmp <mode>,[EPC],nocode
31203203               UML_LABEL(block, skip);                              // skip:
31213204               UML_AND(block, IREG(0), IREG(0), IMM(~SR_ERL));               // and     i0,i0,~SR_ERL
r2762r2763
31243207               compiler->checkints = TRUE;
31253208               generate_update_cycles(block, compiler, CPR032(COP0_ErrorPC), TRUE);
31263209                                                               // <subtract cycles>
3127               UML_HASHJMP(block, MEM(&mips3.cstate->mode), CPR032(COP0_ErrorPC), mips3.nocode);
3210               UML_HASHJMP(block, MEM(&mips3->impstate->mode), CPR032(COP0_ErrorPC), mips3->impstate->nocode);
31283211                                                               // hashjmp <mode>,[EPC],nocode
31293212               return TRUE;
31303213
r2762r2763
31543237   int condition;
31553238
31563239   /* generate an exception if COP1 is disabled */
3157   if (mips3.drcoptions & MIPS3DRC_STRICT_COP1)
3240   if (mips3->impstate->drcoptions & MIPS3DRC_STRICT_COP1)
31583241   {
31593242      UML_TEST(block, CPR032(COP0_Status), IMM(SR_COP1));                     // test    [Status],SR_COP1
3160      UML_EXHc(block, IF_Z, mips3.exception[EXCEPTION_BADCOP], IMM(0));         // exh     cop,0,Z
3243      UML_EXHc(block, IF_Z, mips3->impstate->exception[EXCEPTION_BADCOP], IMM(0));// exh     cop,0,Z
31613244   }
31623245
31633246   switch (RSREG)
r2762r2763
31953278            UML_TEST(block, IREG(0), IMM(3));                           // test    i0,3
31963279            UML_JMPc(block, IF_Z, skip = compiler->labelnum++);               // jmp     skip,Z
31973280            UML_AND(block, IREG(0), CCR132(31), IMM(3));                  // and     i0,ccr1[31],3
3198            UML_LOAD1U(block, IREG(0), &mips3.cstate->fpmode[0], IREG(0));      // load1u  i0,fpmode,i0
3281            UML_LOAD1U(block, IREG(0), &mips3->impstate->fpmode[0], IREG(0));   // load1u  i0,fpmode,i0
31993282            UML_SETFMOD(block, IREG(0));                              // setfmod i0
32003283            UML_LABEL(block, skip);                                 // skip:
32013284         }
r2762r2763
34253508                  UML_FSCMP(block, FPR32(FSREG), FPR32(FTREG));            // fscmp   <fsreg>,<ftreg>
34263509               else            /* C.UN.D - MIPS I */
34273510                  UML_FDCMP(block, FPR64(FSREG), FPR64(FTREG));            // fdcmp   <fsreg>,<ftreg>
3428               UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3.cstate->c_un_table);
3511               UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3->impstate->c_un_table);
34293512                                                               // flags   ccr31,fccmask[op],c_eq_table
34303513               return TRUE;
34313514
r2762r2763
34353518                  UML_FSCMP(block, FPR32(FSREG), FPR32(FTREG));            // fscmp   <fsreg>,<ftreg>
34363519               else            /* C.EQ.D - MIPS I */
34373520                  UML_FDCMP(block, FPR64(FSREG), FPR64(FTREG));            // fdcmp   <fsreg>,<ftreg>
3438               UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3.cstate->c_eq_table);
3521               UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3->impstate->c_eq_table);
34393522                                                               // flags   ccr31,fccmask[op],c_eq_table
34403523               return TRUE;
34413524
r2762r2763
34453528                  UML_FSCMP(block, FPR32(FSREG), FPR32(FTREG));            // fscmp   <fsreg>,<ftreg>
34463529               else            /* C.UEQ.D - MIPS I */
34473530                  UML_FDCMP(block, FPR64(FSREG), FPR64(FTREG));            // fdcmp   <fsreg>,<ftreg>
3448               UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3.cstate->c_ueq_table);
3531               UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3->impstate->c_ueq_table);
34493532                                                               // flags   ccr31,fccmask[op],c_eq_table
34503533               return TRUE;
34513534
r2762r2763
34553538                  UML_FSCMP(block, FPR32(FSREG), FPR32(FTREG));            // fscmp   <fsreg>,<ftreg>
34563539               else            /* C.OLT.D - MIPS I */
34573540                  UML_FDCMP(block, FPR64(FSREG), FPR64(FTREG));            // fdcmp   <fsreg>,<ftreg>
3458               UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3.cstate->c_olt_table);
3541               UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3->impstate->c_olt_table);
34593542                                                               // flags   ccr31,fccmask[op],c_lt_table
34603543               return TRUE;
34613544
r2762r2763
34653548                  UML_FSCMP(block, FPR32(FSREG), FPR32(FTREG));            // fscmp   <fsreg>,<ftreg>
34663549               else            /* C.ULT.D - MIPS I */
34673550                  UML_FDCMP(block, FPR64(FSREG), FPR64(FTREG));            // fdcmp   <fsreg>,<ftreg>
3468               UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3.cstate->c_ult_table);
3551               UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3->impstate->c_ult_table);
34693552                                                               // flags   ccr31,fccmask[op],c_lt_table
34703553               return TRUE;
34713554
r2762r2763
34753558                  UML_FSCMP(block, FPR32(FSREG), FPR32(FTREG));            // fscmp   <fsreg>,<ftreg>
34763559               else            /* C.OLE.D - MIPS I */
34773560                  UML_FDCMP(block, FPR64(FSREG), FPR64(FTREG));            // fdcmp   <fsreg>,<ftreg>
3478               UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3.cstate->c_ole_table);
3561               UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3->impstate->c_ole_table);
34793562                                                               // flags   ccr31,fccmask[op],c_le_table
34803563               return TRUE;
34813564
r2762r2763
34853568                  UML_FSCMP(block, FPR32(FSREG), FPR32(FTREG));            // fscmp   <fsreg>,<ftreg>
34863569               else            /* C.ULE.D - MIPS I */
34873570                  UML_FDCMP(block, FPR64(FSREG), FPR64(FTREG));            // fdcmp   <fsreg>,<ftreg>
3488               UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3.cstate->c_ule_table);
3571               UML_FLAGS(block, CCR132(31), FCCMASK(op >> 8), mips3->impstate->c_ule_table);
34893572                                                               // flags   ccr31,fccmask[op],c_le_table
34903573               return TRUE;
34913574         }
r2762r2763
35093592   int in_delay_slot = ((desc->flags & OPFLAG_IN_DELAY_SLOT) != 0);
35103593   UINT32 op = *desc->opptr.l;
35113594
3512   if (mips3.drcoptions & MIPS3DRC_STRICT_COP1)
3595   if (mips3->impstate->drcoptions & MIPS3DRC_STRICT_COP1)
35133596   {
35143597      UML_TEST(block, CPR032(COP0_Status), IMM(SR_COP1));                     // test    [Status],SR_COP1
3515      UML_EXHc(block, IF_Z, mips3.exception[EXCEPTION_BADCOP], IMM(0));         // exh     cop,0,Z
3598      UML_EXHc(block, IF_Z, mips3->impstate->exception[EXCEPTION_BADCOP], IMM(0));// exh     cop,0,Z
35163599   }
35173600
35183601   switch (op & 0x3f)
35193602   {
35203603      case 0x00:      /* LWXC1 - MIPS IV */
35213604         UML_ADD(block, IREG(0), R32(RSREG), R32(RTREG));                  // add     i0,<rsreg>,<rtreg>
3522         UML_CALLH(block, mips3.read32[mips3.cstate->mode >> 1]);            // callh   read32
3605         UML_CALLH(block, mips3->impstate->read32[mips3->impstate->mode >> 1]);   // callh   read32
35233606         UML_MOV(block, FPR32(RDREG), IREG(0));                           // mov     <cpr1_rd>,i0
35243607         if (!in_delay_slot)
35253608            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
r2762r2763
35273610
35283611      case 0x01:      /* LDXC1 - MIPS IV */
35293612         UML_ADD(block, IREG(0), R32(RSREG), R32(RTREG));                  // add     i0,<rsreg>,<rtreg>
3530         UML_CALLH(block, mips3.read64[mips3.cstate->mode >> 1]);            // callh   read64
3613         UML_CALLH(block, mips3->impstate->read64[mips3->impstate->mode >> 1]);   // callh   read64
35313614         UML_DMOV(block, FPR64(RDREG), IREG(0));                           // dmov    <cpr1_rd>,i0
35323615         if (!in_delay_slot)
35333616            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
r2762r2763
35363619      case 0x08:      /* SWXC1 - MIPS IV */
35373620         UML_ADD(block, IREG(0), R32(RSREG), R32(RTREG));                  // add     i0,<rsreg>,<rtreg>
35383621         UML_MOV(block, IREG(1), FPR32(RTREG));                           // mov     i1,<cpr1_rt>
3539         UML_CALLH(block, mips3.write32[mips3.cstate->mode >> 1]);            // callh   write32
3622         UML_CALLH(block, mips3->impstate->write32[mips3->impstate->mode >> 1]);   // callh   write32
35403623         if (!in_delay_slot)
35413624            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
35423625         return TRUE;
r2762r2763
35443627      case 0x09:      /* SDXC1 - MIPS IV */
35453628         UML_ADD(block, IREG(0), R32(RSREG), R32(RTREG));                  // add     i0,<rsreg>,<rtreg>
35463629         UML_DMOV(block, IREG(1), FPR64(RTREG));                           // dmov    i1,<cpr1_rt>
3547         UML_CALLH(block, mips3.write64[mips3.cstate->mode >> 1]);            // callh   write64
3630         UML_CALLH(block, mips3->impstate->write64[mips3->impstate->mode >> 1]);   // callh   write64
35483631         if (!in_delay_slot)
35493632            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
35503633         return TRUE;
r2762r2763
37563839
37573840
37583841/***************************************************************************
3759    GENERIC GET/SET INFO
3760***************************************************************************/
3761
3762static void mips3_set_info(UINT32 state, cpuinfo *info)
3763{
3764   switch (state)
3765   {
3766      /* --- the following bits of info are set as 64-bit signed integers --- */
3767      case CPUINFO_INT_MIPS3_DRC_OPTIONS:            mips3.drcoptions = info->i;            break;
3768
3769      case CPUINFO_INT_MIPS3_FASTRAM_SELECT:         if (info->i >= 0 && info->i < MIPS3_MAX_FASTRAM) mips3.fastram_select = info->i; mips3.cache_dirty = TRUE; break;
3770      case CPUINFO_INT_MIPS3_FASTRAM_START:         mips3.fastram[mips3.fastram_select].start = info->i; mips3.cache_dirty = TRUE; break;
3771      case CPUINFO_INT_MIPS3_FASTRAM_END:            mips3.fastram[mips3.fastram_select].end = info->i; mips3.cache_dirty = TRUE; break;
3772      case CPUINFO_INT_MIPS3_FASTRAM_READONLY:      mips3.fastram[mips3.fastram_select].readonly = info->i; mips3.cache_dirty = TRUE; break;
3773
3774      case CPUINFO_INT_MIPS3_HOTSPOT_SELECT:         if (info->i >= 0 && info->i < MIPS3_MAX_HOTSPOTS) mips3.hotspot_select = info->i; mips3.cache_dirty = TRUE; break;
3775      case CPUINFO_INT_MIPS3_HOTSPOT_PC:            mips3.hotspot[mips3.hotspot_select].pc = info->i; mips3.cache_dirty = TRUE; break;
3776      case CPUINFO_INT_MIPS3_HOTSPOT_OPCODE:         mips3.hotspot[mips3.hotspot_select].opcode = info->i; mips3.cache_dirty = TRUE; break;
3777      case CPUINFO_INT_MIPS3_HOTSPOT_CYCLES:         mips3.hotspot[mips3.hotspot_select].cycles = info->i; mips3.cache_dirty = TRUE; break;
3778
3779      /* --- the following bits of info are set as pointers to data or functions --- */
3780      case CPUINFO_PTR_MIPS3_FASTRAM_BASE:         mips3.fastram[mips3.fastram_select].base = info->p;   break;
3781
3782      /* --- everything else is handled generically --- */
3783      default:                              mips3com_set_info(mips3.core, state, info);   break;
3784   }
3785}
3786
3787
3788static void mips3_get_info(UINT32 state, cpuinfo *info)
3789{
3790   switch (state)
3791   {
3792      /* --- the following bits of info are returned as 64-bit signed integers --- */
3793      case CPUINFO_INT_CONTEXT_SIZE:               info->i = sizeof(mips3);            break;
3794      case CPUINFO_INT_PREVIOUSPC:               /* not implemented */               break;
3795
3796      /* --- the following bits of info are returned as pointers to data or functions --- */
3797      case CPUINFO_PTR_SET_INFO:                  info->setinfo = mips3_set_info;         break;
3798      case CPUINFO_PTR_GET_CONTEXT:               info->getcontext = mips3_get_context;   break;
3799      case CPUINFO_PTR_SET_CONTEXT:               info->setcontext = mips3_set_context;   break;
3800      case CPUINFO_PTR_INIT:                     /* provided per-CPU */               break;
3801      case CPUINFO_PTR_RESET:                     info->reset = mips3_reset;            break;
3802      case CPUINFO_PTR_EXIT:                     info->exit = mips3_exit;            break;
3803      case CPUINFO_PTR_EXECUTE:                  info->execute = mips3_execute;         break;
3804#ifdef ENABLE_DEBUGGER
3805      case CPUINFO_PTR_DISASSEMBLE:               info->disassemble = mips3_dasm;         break;
3806#endif /* ENABLE_DEBUGGER */
3807      case CPUINFO_PTR_TRANSLATE:                  info->translate = mips3_translate;      break;
3808
3809      /* --- the following bits of info are returned as NULL-terminated strings --- */
3810      case CPUINFO_STR_CORE_FILE:                  strcpy(info->s, __FILE__);            break;
3811
3812      /* --- everything else is handled generically --- */
3813      default:                              mips3com_get_info(mips3.core, state, info); break;
3814   }
3815}
3816
3817
3818
3819/***************************************************************************
38203842    R4600 VARIANTS
38213843***************************************************************************/
38223844
src/emu/cpu/mips/mips3com.c
r2762r2763
3232
3333
3434/***************************************************************************
35    PRIVATE GLOBAL VARIABLES
36***************************************************************************/
37
38static const memory_accessors be_memory =
39{
40   program_read_byte_32be,
41   program_read_word_32be,
42   program_read_dword_32be,
43   program_read_dword_masked_32be,
44   program_read_qword_32be,
45   program_read_qword_masked_32be,
46
47   program_write_byte_32be,
48   program_write_word_32be,
49   program_write_dword_32be,
50   program_write_dword_masked_32be,
51   program_write_qword_32be,
52   program_write_qword_masked_32be
53};
54
55static const memory_accessors le_memory =
56{
57   program_read_byte_32le,
58   program_read_word_32le,
59   program_read_dword_32le,
60   program_read_dword_masked_32le,
61   program_read_qword_32le,
62   program_read_qword_masked_32le,
63
64   program_write_byte_32le,
65   program_write_word_32le,
66   program_write_dword_32le,
67   program_write_dword_masked_32le,
68   program_write_qword_32le,
69   program_write_qword_masked_32le
70};
71
72
73
74/***************************************************************************
7535    INITIALIZATION AND SHUTDOWN
7636***************************************************************************/
7737
r2762r2763
8040    structure based on the configured type
8141-------------------------------------------------*/
8242
83size_t mips3com_init(mips3_state *mips, mips3_flavor flavor, int bigendian, int index, int clock, const struct mips3_config *config, int (*irqcallback)(int), void *memory)
43size_t mips3com_init(mips3_state *mips, mips3_flavor flavor, int bigendian, int index, int clock, const mips3_config *config, int (*irqcallback)(int), void *memory)
8444{
8545   int tlbindex;
8646
r2762r2763
9959   mips->system_clock = config->system_clock;
10060
10161   /* set up the endianness */
102   if (mips->bigendian)
103      mips->memory = be_memory;
104   else
105      mips->memory = le_memory;
62   mips->memory = *memory_get_accessors(ADDRESS_SPACE_PROGRAM, 32, mips->bigendian ? CPU_IS_BE : CPU_IS_LE);
10663
10764   /* allocate memory */
10865   mips->icache = memory;
r2762r2763
300257    from logical to physical
301258-------------------------------------------------*/
302259
303int mips3com_translate_address(mips3_state *mips, int space, offs_t *address)
260int mips3com_translate_address(mips3_state *mips, int space, int intention, offs_t *address)
304261{
305262   /* only applies to the program address space */
306263   if (space == ADDRESS_SPACE_PROGRAM)
src/emu/cpu/mips/mips3.c
r2762r2763
290290}
291291
292292
293static int mips3_translate(int space, offs_t *address)
293static int mips3_translate(int space, int intention, offs_t *address)
294294{
295295   /* common translate */
296   return mips3com_translate_address(&mips3.core, space, address);
296   return mips3com_translate_address(&mips3.core, space, intention, address);
297297}
298298
299299
src/emu/cpu/drcumld.c
r2762r2763
122122   { DRCUML_OP_WRITE8,      "!write8",   { output_param_space, output_param, output_param } },
123123   { DRCUML_OP_WRIT8M,      "!writ8m",   { output_param_space, output_param, output_param, output_param } },
124124   { DRCUML_OP_FLAGS,      "!flags",   { output_param, output_param, output_param } },
125   { DRCUML_OP_SETC,      "!setc",   { output_param, output_param } },
125126   { DRCUML_OP_MOV,      "!mov",      { output_param, output_param, output_cond } },
126127   { DRCUML_OP_ZEXT1,      "!zext1",   { output_param, output_param } },
127128   { DRCUML_OP_ZEXT2,      "!zext2",   { output_param, output_param } },
r2762r2763
145146   { DRCUML_OP_OR,         "!or",      { output_param, output_param, output_param, output_flags } },
146147   { DRCUML_OP_XOR,      "!xor",      { output_param, output_param, output_param, output_flags } },
147148   { DRCUML_OP_LZCNT,      "!lzcnt",   { output_param, output_param } },
149   { DRCUML_OP_BSWAP,      "!bswap",   { output_param, output_param } },
148150   { DRCUML_OP_SHL,      "!shl",      { output_param, output_param, output_param, output_flags } },
149151   { DRCUML_OP_SHR,      "!shr",      { output_param, output_param, output_param, output_flags } },
150152   { DRCUML_OP_SAR,      "!sar",      { output_param, output_param, output_param, output_flags } },
src/emu/cpu/x86emit.h
r2762r2763
15681568INLINE void emit_int_3(x86code **emitptr)  { emit_op_simple(emitptr, OP_INT_3, OP_32BIT); }
15691569INLINE void emit_ret(x86code **emitptr)    { emit_op_simple(emitptr, OP_RETN, OP_32BIT); }
15701570INLINE void emit_cdq(x86code **emitptr)    { emit_op_simple(emitptr, OP_CDQ, OP_32BIT); }
1571INLINE void emit_clc(x86code **emitptr)    { emit_op_simple(emitptr, OP_CLC, OP_32BIT); }
1572INLINE void emit_stc(x86code **emitptr)    { emit_op_simple(emitptr, OP_STC, OP_32BIT); }
15711573INLINE void emit_cmc(x86code **emitptr)    { emit_op_simple(emitptr, OP_CMC, OP_32BIT); }
15721574INLINE void emit_pushf(x86code **emitptr)  { emit_op_simple(emitptr, OP_PUSHF_Fv, OP_32BIT); }
15731575INLINE void emit_popf(x86code **emitptr)   { emit_op_simple(emitptr, OP_POPF_Fv, OP_32BIT); }
src/emu/cpu/drcbex86.c
r2762r2763
314314static x86code *op_write8(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
315315static x86code *op_writ8m(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
316316static x86code *op_flags(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
317static x86code *op_setc(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
317318static x86code *op_mov(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
318319static x86code *op_zext1(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
319320static x86code *op_zext2(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
r2762r2763
337338static x86code *op_or(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
338339static x86code *op_xor(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
339340static x86code *op_lzcnt(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
341static x86code *op_bswap(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
340342static x86code *op_shl(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
341343static x86code *op_shr(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
342344static x86code *op_sar(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
r2762r2763
432434   { DRCUML_OP_WRITE8,  op_write8 },   /* WRITE8  space,dst,src1         */
433435   { DRCUML_OP_WRIT8M,  op_writ8m },   /* WRIT8M  space,dst,mask,src1    */
434436   { DRCUML_OP_FLAGS,   op_flags },   /* FLAGS   dst,mask,table         */
437   { DRCUML_OP_SETC,    op_setc },      /* FLAGS   src,bitnum             */
435438   { DRCUML_OP_MOV,     op_mov },      /* MOV     dst,src[,c]            */
436439   { DRCUML_OP_ZEXT1,   op_zext1 },   /* ZEXT1   dst,src                */
437440   { DRCUML_OP_ZEXT2,   op_zext2 },   /* ZEXT2   dst,src                */
r2762r2763
455458   { DRCUML_OP_OR,      op_or },      /* OR      dst,src1,src2[,f]      */
456459   { DRCUML_OP_XOR,     op_xor },      /* XOR     dst,src1,src2[,f]      */
457460   { DRCUML_OP_LZCNT,   op_lzcnt },   /* LZCNT   dst,src                */
461   { DRCUML_OP_BSWAP,   op_bswap },   /* BSWAP   dst,src                */
458462   { DRCUML_OP_SHL,     op_shl },      /* SHL     dst,src,count[,f]      */
459463   { DRCUML_OP_SHR,     op_shr },      /* SHR     dst,src,count[,f]      */
460464   { DRCUML_OP_SAR,     op_sar },      /* SAR     dst,src,count[,f]      */
r2762r2763
48794883
48804884
48814885/*-------------------------------------------------
4886    op_setc - process a SETC opcode
4887-------------------------------------------------*/
4888
4889static x86code *op_setc(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
4890{
4891   drcuml_parameter srcp, bitp;
4892
4893   /* validate instruction */
4894   assert(inst->size == 4 || inst->size == 8);
4895   assert(inst->condflags == DRCUML_COND_ALWAYS);
4896
4897   /* normalize parameters */
4898   param_normalize_2(drcbe, inst, &srcp, PTYPE_MRI, &bitp, PTYPE_MRI);
4899
4900   /* degenerate case: source is immediate */
4901   if (srcp.type == DRCUML_PTYPE_IMMEDIATE && bitp.type == DRCUML_PTYPE_IMMEDIATE)
4902   {
4903      if (srcp.value & ((UINT64)1 << bitp.value))
4904         emit_stc(&dst);
4905      else
4906         emit_clc(&dst);
4907      return dst;
4908   }
4909
4910   /* load non-immediate bit numbers into a register */
4911   if (bitp.type != DRCUML_PTYPE_IMMEDIATE)
4912   {
4913      emit_mov_r32_p32(drcbe, &dst, REG_ECX, &bitp);
4914      emit_and_r32_imm(&dst, REG_ECX, inst->size * 8 - 1);
4915   }
4916
4917   /* 32-bit form */
4918   if (inst->size == 4)
4919   {
4920      if (bitp.type == DRCUML_PTYPE_IMMEDIATE)
4921      {
4922         if (srcp.type == DRCUML_PTYPE_MEMORY)
4923            emit_bt_m32_imm(&dst, MABS(srcp.value), bitp.value);               // bt     [srcp],bitp
4924         else if (srcp.type == DRCUML_PTYPE_INT_REGISTER)
4925            emit_bt_r32_imm(&dst, srcp.value, bitp.value);                     // bt     srcp,bitp
4926      }
4927      else
4928      {
4929         if (srcp.type == DRCUML_PTYPE_MEMORY)
4930            emit_bt_m32_r32(&dst, MABS(srcp.value), REG_ECX);                  // bt     [srcp],ecx
4931         else if (srcp.type == DRCUML_PTYPE_INT_REGISTER)
4932            emit_bt_r32_r32(&dst, srcp.value, REG_ECX);                        // bt     [srcp],ecx
4933      }
4934   }
4935
4936   /* 64-bit form */
4937   else
4938   {
4939      if (bitp.type == DRCUML_PTYPE_IMMEDIATE)
4940      {
4941         if (srcp.type == DRCUML_PTYPE_MEMORY)
4942            emit_bt_m32_imm(&dst, MABS(srcp.value), bitp.value);               // bt     [srcp],bitp
4943         else if (srcp.type == DRCUML_PTYPE_INT_REGISTER && bitp.value < 32)
4944            emit_bt_r32_imm(&dst, srcp.value, bitp.value);                     // bt     srcp,bitp
4945         else if (srcp.type == DRCUML_PTYPE_INT_REGISTER && bitp.value >= 32)
4946            emit_bt_m32_imm(&dst, MABS(drcbe->reghi[srcp.value]), bitp.value - 32);   // bt     [srcp.hi],bitp
4947      }
4948      else
4949      {
4950         if (srcp.type == DRCUML_PTYPE_MEMORY)
4951            emit_bt_m32_r32(&dst, MABS(srcp.value), REG_ECX);                  // bt     [srcp],ecx
4952         else if (srcp.type == DRCUML_PTYPE_INT_REGISTER)
4953         {
4954            emit_mov_m32_r32(&dst, MABS(drcbe->reglo[srcp.value]), srcp.value);      // mov    [srcp.lo],srcp
4955            emit_bt_m32_r32(&dst, MABS(drcbe->reglo[srcp.value]), REG_ECX);         // bt     [srcp],ecx
4956         }
4957      }
4958   }
4959   return dst;
4960}
4961
4962
4963/*-------------------------------------------------
48824964    op_mov - process a MOV opcode
48834965-------------------------------------------------*/
48844966
r2762r2763
49635045      }
49645046
49655047      /* immediate to memory */
4966      else if (dstp.type == DRCUML_PTYPE_MEMORY && srcp.type == DRCUML_PTYPE_INT_REGISTER)
5048      else if (dstp.type == DRCUML_PTYPE_MEMORY && srcp.type == DRCUML_PTYPE_IMMEDIATE)
49675049      {
49685050         emit_mov_m32_imm(&dst, MABS(dstp.value), srcp.value);                  // mov   [dstp],srcp
49695051         emit_mov_m32_imm(&dst, MABS(dstp.value + 4), srcp.value >> 32);            // mov   [dstp+4],srcp >> 32
r2762r2763
63986480   param_normalize_2(drcbe, inst, &dstp, PTYPE_MR, &srcp, PTYPE_MRI);
63996481
64006482   /* degenerate cases -- convert to a move */
6401   if (srcp.type == DRCUML_PTYPE_IMMEDIATE && inst->condflags == 0)
6483   if (srcp.type == DRCUML_PTYPE_IMMEDIATE && inst->condflags == 0 && inst->size == 4)
64026484      return convert_to_mov_imm(drcbe, dst, inst, &dstp, count_leading_zeros(srcp.value));
64036485
64046486   /* pick a target register for the general case */
r2762r2763
64356517
64366518
64376519/*-------------------------------------------------
6520    op_bswap - process a BSWAP opcode
6521-------------------------------------------------*/
6522
6523static x86code *op_bswap(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
6524{
6525   drcuml_parameter dstp, srcp;
6526   int dstreg;
6527
6528   /* validate instruction */
6529   assert(inst->size == 4 || inst->size == 8);
6530   assert(inst->condflags == 0);
6531
6532   /* normalize parameters */
6533   param_normalize_2(drcbe, inst, &dstp, PTYPE_MR, &srcp, PTYPE_MRI);
6534
6535   /* degenerate cases -- convert to a move */
6536   if (srcp.type == DRCUML_PTYPE_IMMEDIATE && inst->condflags == 0)
6537   {
6538      if (inst->size == 4)
6539         return convert_to_mov_imm(drcbe, dst, inst, &dstp, FLIPENDIAN_INT32(srcp.value));
6540      else if (inst->size == 8)
6541         return convert_to_mov_imm(drcbe, dst, inst, &dstp, FLIPENDIAN_INT64(srcp.value));
6542   }
6543
6544   /* pick a target register for the general case */
6545   dstreg = param_select_register(REG_EAX, &dstp, &srcp);
6546
6547   /* 32-bit form */
6548   if (inst->size == 4)
6549   {
6550      emit_mov_r32_p32(drcbe, &dst, dstreg, &srcp);                           // mov   dstreg,src1p
6551      emit_bswap_r32(&dst, dstreg);                                       // bswap dstreg
6552      emit_mov_p32_r32(drcbe, &dst, &dstp, dstreg);                           // mov   dstp,dstreg
6553   }
6554
6555   /* 64-bit form */
6556   else if (inst->size == 8)
6557   {
6558      emit_mov_r64_p64(drcbe, &dst, REG_EDX, dstreg, &srcp);                     // mov   dstreg:edx,srcp
6559      emit_bswap_r32(&dst, dstreg);                                       // bswap dstreg
6560      emit_bswap_r32(&dst, REG_EDX);                                       // bswap edx
6561      emit_mov_p64_r64(drcbe, &dst, &dstp, REG_EDX, dstreg);                     // mov   dstp,dstreg:edx
6562   }
6563   return dst;
6564}
6565
6566
6567/*-------------------------------------------------
64386568    op_shl - process a SHL opcode
64396569-------------------------------------------------*/
64406570
src/emu/cpu/h6280/h6280.c
r2762r2763
379379   }
380380}
381381
382static int h6280_translate(int space, offs_t *addr)
382static int h6280_translate(int space, int intention, offs_t *addr)
383383{
384384   if (space == ADDRESS_SPACE_PROGRAM)
385385      *addr = TRANSLATED(*addr);
386   return 1;
386   return TRUE;
387387}
388388
389389UINT8 h6280io_get_buffer()
src/emu/info.c
r2762r2763
846846   /* temporary hook until MESS device transition is complete */
847847   mess_devices_setup(config, game);
848848#endif /* MESS */
849   portconfig = input_port_config_alloc(game->ipt);
849   portconfig = input_port_config_alloc(game->ipt, NULL, 0);
850850
851851   /* print the header and the game name */
852852   fprintf(out, "\t<" XML_TOP);
src/emu/emuopts.c
r2762r2763
6464   { "autosave",                    "0",         OPTION_BOOLEAN,    "enable automatic restore at startup, and automatic save at exit time" },
6565   { "playback;pb",                 NULL,        0,                 "playback an input file" },
6666   { "record;rec",                  NULL,        0,                 "record an input file" },
67   { "snapname",                    "%g/%i",     0,                 "override of the default snapshot naming; %g == gamename, %i == index" },
6768   { "mngwrite",                    NULL,        0,                 "optional filename to write a MNG movie of the current session" },
6869   { "aviwrite",                    NULL,        0,                 "optional filename to write an AVI movie of the current session" },
6970   { "wavwrite",                    NULL,        0,                 "optional filename to write a WAV file of the current session" },
src/emu/emuopts.h
r2762r2763
6363#define OPTION_AUTOSAVE            "autosave"
6464#define OPTION_PLAYBACK            "playback"
6565#define OPTION_RECORD            "record"
66#define OPTION_SNAPNAME            "snapname"
6667#define OPTION_MNGWRITE            "mngwrite"
6768#define OPTION_AVIWRITE            "aviwrite"
6869#define OPTION_WAVWRITE            "wavwrite"
src/emu/uimenu.c
r2762r2763
186186static void input_menu_toggle_none_default(input_seq *selected_seq, input_seq *original_seq, const input_seq *selected_defseq);
187187static int input_menu_compare_items(const void *i1, const void *i2);
188188static void switches_menu_add_item(ui_menu_item *item, const input_field_config *field);
189static void switches_menu_select_previous(const input_field_config *field);
190static void switches_menu_select_next(const input_field_config *field);
191189static void analog_menu_add_item(ui_menu_item *item, const input_field_config *field, const char *append_string, int which_item);
192190
193191/* DIP switch helpers */
r2762r2763
10901088   /* handle left/right arrows */
10911089   if (input_ui_pressed(machine, IPT_UI_LEFT) && (item_list[selected].flags & MENU_FLAG_LEFT_ARROW))
10921090   {
1093      switches_menu_select_previous(selected_field);
1091      input_field_select_previous_setting(selected_field);
10941092      changed = TRUE;
10951093   }
10961094   if (input_ui_pressed(machine, IPT_UI_RIGHT) && (item_list[selected].flags & MENU_FLAG_RIGHT_ARROW))
10971095   {
1098      switches_menu_select_next(selected_field);
1096      input_field_select_next_setting(selected_field);
10991097      changed = TRUE;
11001098   }
11011099
1100   /* select resets to the default value */
1101   if (input_ui_pressed(machine, IPT_UI_SELECT))
1102   {
1103      input_field_user_settings settings;
1104      input_field_get_user_settings(selected_field, &settings);
1105      settings.value = selected_field->defvalue;
1106      input_field_set_user_settings(selected_field, &settings);
1107   }
1108
11021109   /* update the selection to match the existing entry in case things got shuffled */
11031110   /* due to conditional DIPs changing things */
11041111   if (changed)
r2762r2763
20892096
20902097
20912098/*-------------------------------------------------
2092    switches_menu_select_previous - select the
2093    previous item in the switches list
2094-------------------------------------------------*/
2095
2096static void switches_menu_select_previous(const input_field_config *field)
2097{
2098   const input_setting_config *setting, *prevsetting;
2099   input_field_user_settings settings;
2100   int found_match = FALSE;
2101
2102   /* get the current configured settings */
2103   input_field_get_user_settings(field, &settings);
2104
2105   /* scan the list of settings looking for a match on the current value */
2106   prevsetting = NULL;
2107   for (setting = field->settinglist; setting != NULL; setting = setting->next)
2108   {
2109      if (setting->value == settings.value)
2110      {
2111         found_match = TRUE;
2112         if (prevsetting != NULL)
2113            break;
2114      }
2115      if (input_condition_true(field->port->machine, &setting->condition))
2116         prevsetting = setting;
2117   }
2118
2119   /* if we didn't find a matching value, select the first */
2120   if (!found_match)
2121   {
2122      for (prevsetting = field->settinglist; prevsetting != NULL; prevsetting = prevsetting->next)
2123         if (input_condition_true(field->port->machine, &prevsetting->condition))
2124            break;
2125   }
2126
2127   /* update the value to the previous one */
2128   if (prevsetting != NULL)
2129      settings.value = prevsetting->value;
2130   input_field_set_user_settings(field, &settings);
2131}
2132
2133
2134/*-------------------------------------------------
2135    switches_menu_select_next - select the
2136    next item in the switches list
2137-------------------------------------------------*/
2138
2139static void switches_menu_select_next(const input_field_config *field)
2140{
2141   const input_setting_config *setting, *nextsetting;
2142   input_field_user_settings settings;
2143
2144   /* get the current configured settings */
2145   input_field_get_user_settings(field, &settings);
2146
2147   /* scan the list of settings looking for a match on the current value */
2148   nextsetting = NULL;
2149   for (setting = field->settinglist; setting != NULL; setting = setting->next)
2150      if (setting->value == settings.value)
2151         break;
2152
2153   /* if we found one, scan forward for the next valid one */
2154   if (setting != NULL)
2155      for (nextsetting = setting->next; nextsetting != NULL; nextsetting = nextsetting->next)
2156         if (input_condition_true(field->port->machine, &nextsetting->condition))
2157            break;
2158
2159   /* if we hit the end, search from the beginning */
2160   if (nextsetting == NULL)
2161      for (nextsetting = field->settinglist; nextsetting != NULL; nextsetting = nextsetting->next)
2162         if (input_condition_true(field->port->machine, &nextsetting->condition))
2163            break;
2164
2165   /* update the value to the previous one */
2166   if (nextsetting != NULL)
2167      settings.value = nextsetting->value;
2168   input_field_set_user_settings(field, &settings);
2169}
2170
2171
2172/*-------------------------------------------------
21732099    analog_menu_add_item - add an item to the
21742100    analog controls menu
21752101-------------------------------------------------*/
src/emu/video.c
r2762r2763
22142214
22152215static file_error mame_fopen_next(running_machine *machine, const char *pathoption, const char *extension, mame_file **file)
22162216{
2217   const char *snapname = options_get_string(mame_options(), OPTION_SNAPNAME);
2218   astring *snapstr = astring_alloc();
2219   astring *fname = astring_alloc();
22172220   file_error filerr;
2218   char *fname;
2219   int seq;
2221   int index;
22202222
2221   /* allocate temp space for the name */
2222   fname = malloc_or_die(strlen(machine->basename) + 1 + 10 + strlen(extension) + 1);
2223   /* handle defaults */
2224   if (snapname == NULL || snapname[0] == 0)
2225      snapname = "%g/%i";
2226   astring_cpyc(snapstr, snapname);
22232227
2224   /* try until we succeed */
2225   for (seq = 0; ; seq++)
2228   /* strip any extension in the provided name and add our own */
2229   index = astring_rchr(snapstr, 0, '.');
2230   if (index != -1)
2231      astring_substr(snapstr, 0, index);
2232   astring_catc(snapstr, ".");
2233   astring_catc(snapstr, extension);
2234
2235   /* substitute path and gamename up front */
2236   astring_replacec(snapstr, 0, "/", PATH_SEPARATOR);
2237   astring_replacec(snapstr, 0, "%g", machine->basename);
2238
2239   /* determine if the template has an index; if not, we always use the same name */
2240   if (astring_findc(snapstr, 0, "%i") == -1)
2241      astring_cpy(fname, snapstr);
2242
2243   /* otherwise, we scan for the next available filename */
2244   else
22262245   {
2227      sprintf(fname, "%s" PATH_SEPARATOR "%04d.%s", machine->basename, seq, extension);
2228      filerr = mame_fopen(pathoption, fname, OPEN_FLAG_READ, file);
2229      if (filerr != FILERR_NONE)
2230         break;
2231      mame_fclose(*file);
2246      int seq;
2247
2248      /* try until we succeed */
2249      for (seq = 0; ; seq++)
2250      {
2251         char seqtext[10];
2252
2253         /* make text for the sequence number */
2254         sprintf(seqtext, "%04d", seq);
2255
2256         /* build up the filename */
2257         astring_cpy(fname, snapstr);
2258         astring_replacec(fname, 0, "%i", seqtext);
2259
2260         /* try to open the file; stop when we fail */
2261         filerr = mame_fopen(pathoption, astring_c(fname), OPEN_FLAG_READ, file);
2262         if (filerr != FILERR_NONE)
2263            break;
2264         mame_fclose(*file);
2265      }
22322266   }
22332267
22342268   /* create the final file */
2235    filerr = mame_fopen(pathoption, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, file);
2269    filerr = mame_fopen(pathoption, astring_c(fname), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, file);
22362270
22372271    /* free the name and get out */
2238    free(fname);
2272    astring_free(fname);
2273    astring_free(snapstr);
22392274    return filerr;
22402275}
22412276
src/emu/memory.h
r2762r2763
786786
787787/* common shortcuts */
788788#define AM_READWRITE(_read,_write)         AM_READ(_read) AM_WRITE(_write)
789#define AM_READWRITE8(_read,_write,_shift)   AM_READ8(_read,_shift) AM_WRITE8(_write,_shift)
790#define AM_READWRITE16(_read,_write,_shift)   AM_READ16(_read,_shift) AM_WRITE16(_write,_shift)
791#define AM_READWRITE32(_read,_write,_shift)   AM_READ32(_read,_shift) AM_WRITE32(_write,_shift)
789#define AM_READWRITE8(_read,_write,_mask)   AM_READ8(_read,_mask) AM_WRITE8(_write,_mask)
790#define AM_READWRITE16(_read,_write,_mask)   AM_READ16(_read,_mask) AM_WRITE16(_write,_mask)
791#define AM_READWRITE32(_read,_write,_mask)   AM_READ32(_read,_mask) AM_WRITE32(_write,_mask)
792792
793793#define AM_DEVREADWRITE(_type,_tag,_read,_write) AM_DEVREAD(_type,_tag,_read) AM_DEVWRITE(_type,_tag,_write)
794#define AM_DEVREADWRITE8(_type,_tag,_read,_write,_shift) AM_DEVREAD8(_type,_tag,_read,_shift) AM_DEVWRITE8(_type,_tag,_write,_shift)
795#define AM_DEVREADWRITE16(_type,_tag,_read,_write,_shift) AM_DEVREAD16(_type,_tag,_read,_shift) AM_DEVWRITE16(_type,_tag,_write,_shift)
796#define AM_DEVREADWRITE32(_type,_tag,_read,_write,_shift) AM_DEVREAD32(_type,_tag,_read,_shift) AM_DEVWRITE32(_type,_tag,_write,_shift)
794#define AM_DEVREADWRITE8(_type,_tag,_read,_write,_mask) AM_DEVREAD8(_type,_tag,_read,_mask) AM_DEVWRITE8(_type,_tag,_write,_mask)
795#define AM_DEVREADWRITE16(_type,_tag,_read,_write,_mask) AM_DEVREAD16(_type,_tag,_read,_mask) AM_DEVWRITE16(_type,_tag,_write,_mask)
796#define AM_DEVREADWRITE32(_type,_tag,_read,_write,_mask) AM_DEVREAD32(_type,_tag,_read,_mask) AM_DEVWRITE32(_type,_tag,_write,_mask)
797797
798798#define AM_ROM                        AM_READ(SMH_ROM)
799799#define AM_ROMBANK(_bank)               AM_READ(SMH_BANK(_bank))
src/emu/inptport.c
r2762r2763
101101#include "deprecat.h"
102102#include <ctype.h>
103103#include <time.h>
104#include <stdarg.h>
104105
105106#ifdef MESS
106107#include "inputx.h"
r2762r2763
208209   input_port_value         value;            /* current value of this port */
209210   UINT8                  impulse;         /* counter for impulse controls */
210211   UINT8                  last;            /* were we pressed last time? */
211   UINT8                  toggle;            /* current toggle state */
212212   UINT8                  joydir;            /* digital joystick direction index */
213213   char *                  name;            /* overridden name */
214214};
r2762r2763
482482static int frame_get_digital_field_state(const input_field_config *field);
483483
484484/* port configuration helpers */
485static input_port_config *port_config_detokenize(input_port_config *listhead, const input_port_token *ipt);
485static input_port_config *port_config_detokenize(input_port_config *listhead, const input_port_token *ipt, char *errorbuf, int errorbuflen);
486486static input_port_config *port_config_alloc(const input_port_config **listhead);
487487static void port_config_free(const input_port_config **portptr);
488488static input_port_config *port_config_find(const input_port_config *listhead, const char *tag);
489489static input_field_config *field_config_alloc(input_port_config *port, int type, input_port_value defvalue, input_port_value maskbits);
490static void field_config_insert(input_field_config *field, input_port_value *disallowedbits, char *errorbuf, int errorbuflen);
490491static void field_config_free(input_field_config **fieldptr);
491492static input_setting_config *setting_config_alloc(input_field_config *field, input_port_value value, const char *name);
492493static void setting_config_free(input_setting_config **settingptr);
493static const input_field_diplocation *diplocation_list_alloc(const input_field_config *field, const char *location);
494static const input_field_diplocation *diplocation_list_alloc(const input_field_config *field, const char *location, char *errorbuf, int errorbuflen);
494495static void diplocation_free(input_field_diplocation **diplocptr);
495496
496497/* tokenization helpers */
r2762r2763
597598}
598599
599600
601/*-------------------------------------------------
602    get_port_tag - return a guaranteed tag for
603    a port
604-------------------------------------------------*/
600605
606INLINE const char *get_port_tag(const input_port_config *port, char *tempbuffer)
607{
608   const input_port_config *curport;
609   int index = 0;
610
611   if (port->tag != NULL)
612      return port->tag;
613   for (curport = port->machine->portconfig; curport != NULL; curport = curport->next)
614   {
615      if (curport == port)
616         break;
617      index++;
618   }
619   sprintf(tempbuffer, "(PORT#%d)", index);
620   return tempbuffer;
621}
622
623
624/*-------------------------------------------------
625    error_buf_append - append text to an error
626    buffer
627-------------------------------------------------*/
628
629INLINE void *error_buf_append(char *errorbuf, int errorbuflen, const char *format, ...)
630{
631   int curlen = (errorbuf != NULL) ? strlen(errorbuf) : 0;
632   int bytesleft = errorbuflen - curlen;
633   va_list va;
634
635   va_start(va, format);
636   if (strlen(format) + 25 < bytesleft)
637      vsprintf(&errorbuf[curlen], format, va);
638   va_end(va);
639
640   return NULL;
641}
642
643
644/*-------------------------------------------------
645    condition_equal - TRUE if two conditions are
646    equivalent
647-------------------------------------------------*/
648
649INLINE int condition_equal(const input_condition *cond1, const input_condition *cond2)
650{
651   return (cond1->mask == cond2->mask && cond1->value == cond2->value && cond1->condition == cond2->condition && strcmp(cond1->tag, cond2->tag) == 0);
652}
653
654
655
601656/***************************************************************************
602657    CORE SYSTEM MANAGEMENT
603658***************************************************************************/
r2762r2763
610665time_t input_port_init(running_machine *machine, const input_port_token *tokens)
611666{
612667   input_port_private *portdata;
668   char errorbuf[1024];
613669   time_t basetime;
614670
615671   /* allocate memory for our data structure */
r2762r2763
627683   /* if we have a token list, proceed */
628684   if (tokens != NULL)
629685   {
630      machine->portconfig = input_port_config_alloc(tokens);
686      machine->portconfig = input_port_config_alloc(tokens, errorbuf, sizeof(errorbuf));
687      if (errorbuf[0] != 0)
688         mame_printf_error("Input port errors:\n%s", errorbuf);
689      if (machine->portconfig == NULL)
690         fatalerror("Unable to construct input ports!");
631691      init_port_state(machine);
632692   }
633693
r2762r2763
669729    input ports from the given token list
670730-------------------------------------------------*/
671731
672const input_port_config *input_port_config_alloc(const input_port_token *tokens)
732const input_port_config *input_port_config_alloc(const input_port_token *tokens, char *errorbuf, int errorbuflen)
673733{
674   return port_config_detokenize(NULL, tokens);
734   if (errorbuf != NULL)
735      *errorbuf = 0;
736   return port_config_detokenize(NULL, tokens, errorbuf, errorbuflen);
675737}
676738
677739
678740/*-------------------------------------------------
679    input_port_config_alloc - free memory
741    input_port_config_free - free memory
680742    allocated from input_port_alloc
681743-------------------------------------------------*/
682744
r2762r2763
841903}
842904
843905
906/*-------------------------------------------------
907    input_field_select_previous_setting - select
908    the previous item for a DIP switch or
909    configuration field
910-------------------------------------------------*/
844911
912void input_field_select_previous_setting(const input_field_config *field)
913{
914   const input_setting_config *setting, *prevsetting;
915   int found_match = FALSE;
916
917   /* only makes sense if we have settings */
918   assert(field->settinglist != NULL);
919
920   /* scan the list of settings looking for a match on the current value */
921   prevsetting = NULL;
922   for (setting = field->settinglist; setting != NULL; setting = setting->next)
923      if (input_condition_true(field->port->machine, &setting->condition))
924      {
925         if (setting->value == field->state->value)
926         {
927            found_match = TRUE;
928            if (prevsetting != NULL)
929               break;
930         }
931         prevsetting = setting;
932      }
933
934   /* if we didn't find a matching value, select the first */
935   if (!found_match)
936   {
937      for (prevsetting = field->settinglist; prevsetting != NULL; prevsetting = prevsetting->next)
938         if (input_condition_true(field->port->machine, &prevsetting->condition))
939            break;
940   }
941
942   /* update the value to the previous one */
943   if (prevsetting != NULL)
944      field->state->value = prevsetting->value;
945}
946
947
948/*-------------------------------------------------
949    input_field_select_next_setting - select the
950    next item for a DIP switch or
951    configuration field
952-------------------------------------------------*/
953
954void input_field_select_next_setting(const input_field_config *field)
955{
956   const input_setting_config *setting, *nextsetting;
957
958   /* only makes sense if we have settings */
959   assert(field->settinglist != NULL);
960
961   /* scan the list of settings looking for a match on the current value */
962   nextsetting = NULL;
963   for (setting = field->settinglist; setting != NULL; setting = setting->next)
964      if (input_condition_true(field->port->machine, &setting->condition))
965         if (setting->value == field->state->value)
966            break;
967
968   /* if we found one, scan forward for the next valid one */
969   if (setting != NULL)
970      for (nextsetting = setting->next; nextsetting != NULL; nextsetting = nextsetting->next)
971         if (input_condition_true(field->port->machine, &nextsetting->condition))
972            break;
973
974   /* if we hit the end, search from the beginning */
975   if (nextsetting == NULL)
976      for (nextsetting = field->settinglist; nextsetting != NULL; nextsetting = nextsetting->next)
977         if (input_condition_true(field->port->machine, &nextsetting->condition))
978            break;
979
980   /* update the value to the previous one */
981   if (nextsetting != NULL)
982      field->state->value = nextsetting->value;
983}
984
985
986
845987/***************************************************************************
846988    ACCESSORS FOR INPUT TYPES
847989***************************************************************************/
r2762r2763
10781220         result = (result & ~custom->field->mask) | ((newbits << custom->shift) & custom->field->mask);
10791221      }
10801222
1081
10821223   /* update VBLANK bits */
10831224   if (port->state->vblank != 0)
10841225   {
r2762r2763
21622303      return FALSE;
21632304#endif /* MESS */
21642305
2165   /* skip locked-out coin inputs */
2166   if (field->type >= IPT_COIN1 && field->type <= IPT_COIN8 && coinlockedout[field->type - IPT_COIN1])
2167   {
2168      ui_popup_time(3, "Coinlock disabled %s.", input_field_name(field));
2169      return FALSE;
2170   }
2171
2172   /* skip locked-out service inputs */
2173   if (field->type >= IPT_SERVICE1 && field->type <= IPT_SERVICE4 && servicecoinlockedout[field->type - IPT_SERVICE1])
2174   {
2175      ui_popup_time(3, "Coinlock disabled %s.", input_field_name(field));
2176      return FALSE;
2177   }
2178
21792306   /* if this is a switch-down event, handle impulse and toggle */
21802307   if (changed && curstate)
21812308   {
r2762r2763
21832310      if (field->impulse != 0 && field->state->impulse == 0)
21842311         field->state->impulse = field->impulse;
21852312
2186      /* toggle controls: flip the toggle state */
2313      /* toggle controls: flip the toggle state or advance to the next setting */
21872314      if (field->flags & FIELD_FLAG_TOGGLE)
2188         field->state->toggle = !field->state->toggle;
2315      {
2316         if (field->settinglist == NULL)
2317            field->state->value ^= field->mask;
2318         else
2319            input_field_select_next_setting(field);
2320      }
21892321   }
21902322
21912323   /* update the current state with the impulse state */
2192   if (field->impulse != 0 && field->state->impulse != 0)
2324   if (field->impulse != 0)
21932325   {
2194      field->state->impulse--;
2195      curstate = TRUE;
2326      if (field->state->impulse != 0)
2327      {
2328         field->state->impulse--;
2329         curstate = TRUE;
2330      }
2331      else
2332         curstate = FALSE;
21962333   }
21972334
2198   /* update the current state with the toggle state */
2335   /* for toggle switches, the current value is folded into the port's default value */
2336   /* so we always return FALSE here */
21992337   if (field->flags & FIELD_FLAG_TOGGLE)
2200      curstate = field->state->toggle;
2338      curstate = FALSE;
22012339
22022340   /* additional logic to restrict digital joysticks */
22032341   if (curstate && field->state->joystick != NULL && field->way != 16)
r2762r2763
22072345         curstate = FALSE;
22082346   }
22092347
2348   /* skip locked-out coin inputs */
2349   if (curstate && field->type >= IPT_COIN1 && field->type <= IPT_COIN8 && coinlockedout[field->type - IPT_COIN1])
2350   {
2351      ui_popup_time(3, "Coinlock disabled %s.", input_field_name(field));
2352      return FALSE;
2353   }
22102354   return curstate;
22112355}
22122356
r2762r2763
22212365    detokenize a series of input port tokens
22222366-------------------------------------------------*/
22232367
2224static input_port_config *port_config_detokenize(input_port_config *listhead, const input_port_token *ipt)
2368static input_port_config *port_config_detokenize(input_port_config *listhead, const input_port_token *ipt, char *errorbuf, int errorbuflen)
22252369{
22262370   UINT32 entrytype = INPUT_TOKEN_INVALID;
22272371   input_setting_config *cursetting = NULL;
22282372   input_field_config *curfield = NULL;
22292373   input_port_config *curport = NULL;
2374   input_port_value maskbits = 0;
22302375
22312376   /* loop over tokens until we hit the end */
22322377   while (entrytype != INPUT_TOKEN_END)
r2762r2763
22472392
22482393         /* including */
22492394         case INPUT_TOKEN_INCLUDE:
2250            listhead = port_config_detokenize(listhead, TOKEN_GET_PTR(ipt, tokenptr));
2395            if (curfield != NULL)
2396               field_config_insert(curfield, &maskbits, errorbuf, errorbuflen);
2397            maskbits = 0;
2398
2399            listhead = port_config_detokenize(listhead, TOKEN_GET_PTR(ipt, tokenptr), errorbuf, errorbuflen);
2400            curport = NULL;
2401            curfield = NULL;
2402            cursetting = NULL;
22512403            break;
22522404
22532405         /* start of a new input port */
22542406         case INPUT_TOKEN_START:
22552407         case INPUT_TOKEN_START_TAG:
2408            if (curfield != NULL)
2409               field_config_insert(curfield, &maskbits, errorbuf, errorbuflen);
2410            maskbits = 0;
2411
22562412            curport = port_config_alloc((const input_port_config **)&listhead);
22572413            if (entrytype == INPUT_TOKEN_START_TAG)
22582414               curport->tag = TOKEN_GET_STRING(ipt);
r2762r2763
22622418
22632419         /* modify an existing port */
22642420         case INPUT_TOKEN_MODIFY:
2421            if (curfield != NULL)
2422               field_config_insert(curfield, &maskbits, errorbuf, errorbuflen);
2423            maskbits = 0;
2424
22652425            curport = port_config_find(listhead, TOKEN_GET_STRING(ipt));
2426            curfield = NULL;
2427            cursetting = NULL;
22662428            break;
22672429
22682430         /* input field definition */
22692431         case INPUT_TOKEN_FIELD:
2270            if (curport == NULL)
2271               fatalerror("INPUT_TOKEN_FIELD encountered with no active port");
2272
22732432            TOKEN_UNGET_UINT32(ipt);
22742433            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, type, 24);
22752434            TOKEN_GET_UINT64_UNPACK2(ipt, mask, 32, defval, 32);
22762435
2436            if (curport == NULL)
2437               return error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_FIELD encountered with no active port (mask=%X defval=%X)\n", mask, defval);
2438
2439            if (curfield != NULL)
2440               field_config_insert(curfield, &maskbits, errorbuf, errorbuflen);
22772441            curfield = field_config_alloc(curport, type, defval, mask);
22782442            cursetting = NULL;
22792443            break;
22802444
22812445         /* field or setting condition */
22822446         case INPUT_TOKEN_CONDITION:
2447            TOKEN_UNGET_UINT32(ipt);
22832448            if (curfield == NULL && cursetting == NULL)
2284               fatalerror("INPUT_TOKEN_CONDITION encountered with no active field or setting");
2285
2286            TOKEN_UNGET_UINT32(ipt);
2449            {
2450               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_CONDITION encountered with no active field or setting\n");
2451               TOKEN_SKIP_UINT32(ipt);
2452               TOKEN_SKIP_UINT64(ipt);
2453               break;
2454            }
22872455            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, condition.condition, 24);
22882456            TOKEN_GET_UINT64_UNPACK2(ipt, condition.mask, 32, condition.value, 32);
22892457            condition.tag = TOKEN_GET_STRING(ipt);
r2762r2763
23042472         case INPUT_TOKEN_PLAYER7:
23052473         case INPUT_TOKEN_PLAYER8:
23062474            if (curfield == NULL)
2307               fatalerror("INPUT_TOKEN_PLAYERn encountered with no active field");
2475            {
2476               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_PLAYERn encountered with no active field\n");
2477               break;
2478            }
23082479            curfield->player = entrytype - INPUT_TOKEN_PLAYER1;
23092480            break;
23102481
23112482         /* field category */
23122483         case INPUT_TOKEN_CATEGORY:
2484            TOKEN_UNGET_UINT32(ipt);
23132485            if (curfield == NULL)
2314               fatalerror("INPUT_TOKEN_CATEGORY encountered with no active field");
2315            TOKEN_UNGET_UINT32(ipt);
2486            {
2487               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_CATEGORY encountered with no active field\n");
2488               TOKEN_SKIP_UINT32(ipt);
2489               break;
2490            }
23162491            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, curfield->category, 24);
23172492            break;
23182493
23192494         /* field flags */
23202495         case INPUT_TOKEN_UNUSED:
23212496            if (curfield == NULL)
2322               fatalerror("INPUT_TOKEN_UNUSED encountered with no active field");
2497            {
2498               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_UNUSED encountered with no active field\n");
2499               break;
2500            }
23232501            curfield->flags |= FIELD_FLAG_UNUSED;
23242502            break;
23252503
23262504         case INPUT_TOKEN_COCKTAIL:
23272505            if (curfield == NULL)
2328               fatalerror("INPUT_TOKEN_COCKTAIL encountered with no active field");
2506            {
2507               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_COCKTAIL encountered with no active field\n");
2508               break;
2509            }
23292510            curfield->flags |= FIELD_FLAG_COCKTAIL;
23302511            curfield->player = 1;
23312512            break;
23322513
23332514         case INPUT_TOKEN_ROTATED:
23342515            if (curfield == NULL)
2335               fatalerror("INPUT_TOKEN_ROTATED encountered with no active field");
2516            {
2517               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_ROTATED encountered with no active field\n");
2518               break;
2519            }
23362520            curfield->flags |= FIELD_FLAG_ROTATED;
23372521            break;
23382522
23392523         case INPUT_TOKEN_TOGGLE:
23402524            if (curfield == NULL)
2341               fatalerror("INPUT_TOKEN_TOGGLE encountered with no active field");
2525            {
2526               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_TOGGLE encountered with no active field\n");
2527               break;
2528            }
23422529            curfield->flags |= FIELD_FLAG_TOGGLE;
23432530            break;
23442531
23452532         /* field impulse */
23462533         case INPUT_TOKEN_IMPULSE:
2534            TOKEN_UNGET_UINT32(ipt);
23472535            if (curfield == NULL)
2348               fatalerror("INPUT_TOKEN_IMPULSE encountered with no active field");
2349            TOKEN_UNGET_UINT32(ipt);
2536            {
2537               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_IMPULSE encountered with no active field\n");
2538               TOKEN_SKIP_UINT32(ipt);
2539               break;
2540            }
23502541            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, curfield->impulse, 24);
23512542            break;
23522543
23532544         /* field name */
23542545         case INPUT_TOKEN_NAME:
23552546            if (curfield == NULL)
2356               fatalerror("INPUT_TOKEN_NAME encountered with no active field");
2547            {
2548               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_NAME encountered with no active field\n");
2549               TOKEN_SKIP_STRING(ipt);
2550               break;
2551            }
23572552            curfield->name = input_port_string_from_token(*ipt++);
23582553            break;
23592554
23602555         /* field code sequence */
23612556         case INPUT_TOKEN_CODE:
2557            TOKEN_UNGET_UINT32(ipt);
23622558            if (curfield == NULL)
2363               fatalerror("INPUT_TOKEN_CODE encountered with no active field");
2364
2365            TOKEN_UNGET_UINT32(ipt);
2559            {
2560               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_CODE encountered with no active field\n");
2561               TOKEN_SKIP_UINT64(ipt);
2562               break;
2563            }
23662564            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, val, 32);
2367
23682565            input_seq_append_or(&curfield->seq[SEQ_TYPE_STANDARD], val);
23692566            break;
23702567
23712568         /* field custom callback */
23722569         case INPUT_TOKEN_CUSTOM:
23732570            if (curfield == NULL)
2374               fatalerror("INPUT_TOKEN_CUSTOM encountered with no active field");
2571            {
2572               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_CUSTOM encountered with no active field\n");
2573               TOKEN_SKIP_PTR(ipt);
2574               TOKEN_SKIP_PTR(ipt);
2575               break;
2576            }
23752577            curfield->custom = TOKEN_GET_PTR(ipt, customptr);
23762578            curfield->custom_param = (void *)TOKEN_GET_PTR(ipt, voidptr);
23772579            break;
r2762r2763
23792581         /* field changed callback */
23802582         case INPUT_TOKEN_CHANGED:
23812583            if (curfield == NULL)
2382               fatalerror("INPUT_TOKEN_CHANGED encountered with no active field");
2584            {
2585               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_CHANGED encountered with no active field\n");
2586               TOKEN_SKIP_PTR(ipt);
2587               TOKEN_SKIP_PTR(ipt);
2588               break;
2589            }
23832590            curfield->changed = TOKEN_GET_PTR(ipt, changedptr);
23842591            curfield->changed_param = (void *)TOKEN_GET_PTR(ipt, voidptr);
23852592            break;
r2762r2763
23872594         /* DIP switch location */
23882595         case INPUT_TOKEN_DIPLOCATION:
23892596            if (curfield == NULL)
2390               fatalerror("INPUT_TOKEN_DIPLOCATION encountered with no active field");
2391            curfield->diploclist = diplocation_list_alloc(curfield, TOKEN_GET_STRING(ipt));
2597            {
2598               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_DIPLOCATION encountered with no active field\n");
2599               TOKEN_SKIP_STRING(ipt);
2600               break;
2601            }
2602            curfield->diploclist = diplocation_list_alloc(curfield, TOKEN_GET_STRING(ipt), errorbuf, errorbuflen);
23922603            break;
23932604
23942605         /* joystick flags */
r2762r2763
23972608         case INPUT_TOKEN_8WAY:
23982609         case INPUT_TOKEN_16WAY:
23992610            if (curfield == NULL)
2400               fatalerror("INPUT_TOKEN_nWAY encountered with no active field");
2611            {
2612               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_nWAY encountered with no active field\n");
2613               break;
2614            }
24012615            curfield->way = 2 << (entrytype - INPUT_TOKEN_2WAY);
24022616            break;
24032617
24042618         /* (MESS) natural keyboard support */
24052619         case INPUT_TOKEN_CHAR:
2620            TOKEN_UNGET_UINT32(ipt);
24062621            if (curfield == NULL)
2407               fatalerror("INPUT_TOKEN_CHAR encountered with no active field");
2408
2409            TOKEN_UNGET_UINT32(ipt);
2622            {
2623               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_CHAR encountered with no active field\n");
2624               TOKEN_SKIP_UINT64(ipt);
2625               break;
2626            }
24102627            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, val, 32);
2411
24122628            for (index = 0; index < ARRAY_LENGTH(curfield->chars); index++)
24132629               if (curfield->chars[index] == 0)
24142630               {
r2762r2763
24202636         /* analog minimum/maximum */
24212637         case INPUT_TOKEN_MINMAX:
24222638            if (curfield == NULL)
2423               fatalerror("INPUT_TOKEN_MINMAX encountered with no active field");
2639            {
2640               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_MINMAX encountered with no active field\n");
2641               TOKEN_SKIP_UINT64(ipt);
2642               break;
2643            }
24242644            TOKEN_GET_UINT64_UNPACK2(ipt, curfield->min, 32, curfield->max, 32);
24252645            break;
24262646
24272647         /* analog sensitivity */
24282648         case INPUT_TOKEN_SENSITIVITY:
2649            TOKEN_UNGET_UINT32(ipt);
24292650            if (curfield == NULL)
2430               fatalerror("INPUT_TOKEN_SENSITIVITY encountered with no active field");
2431            TOKEN_UNGET_UINT32(ipt);
2651            {
2652               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_SENSITIVITY encountered with no active field\n");
2653               TOKEN_SKIP_UINT32(ipt);
2654               break;
2655            }
24322656            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, curfield->sensitivity, 24);
24332657            break;
24342658
24352659         /* analog keyboard delta */
24362660         case INPUT_TOKEN_KEYDELTA:
2661            TOKEN_UNGET_UINT32(ipt);
24372662            if (curfield == NULL)
2438               fatalerror("INPUT_TOKEN_KEYDELTA encountered with no active field");
2439            TOKEN_UNGET_UINT32(ipt);
2663            {
2664               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_KEYDELTA encountered with no active field\n");
2665               TOKEN_SKIP_UINT32(ipt);
2666               break;
2667            }
24402668            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, curfield->delta, -24);
24412669            curfield->centerdelta = curfield->delta;
24422670            break;
24432671
24442672         /* analog autocenter delta */
24452673         case INPUT_TOKEN_CENTERDELTA:
2674            TOKEN_UNGET_UINT32(ipt);
24462675            if (curfield == NULL)
2447               fatalerror("INPUT_TOKEN_CENTERDELTA encountered with no active field");
2448            TOKEN_UNGET_UINT32(ipt);
2676            {
2677               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_CENTERDELTA encountered with no active field\n");
2678               TOKEN_SKIP_UINT32(ipt);
2679               break;
2680            }
24492681            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, curfield->centerdelta, -24);
24502682            break;
24512683
24522684         /* analog reverse flags */
24532685         case INPUT_TOKEN_REVERSE:
24542686            if (curfield == NULL)
2455               fatalerror("INPUT_TOKEN_REVERSE encountered with no active field");
2687            {
2688               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_REVERSE encountered with no active field\n");
2689               break;
2690            }
24562691            curfield->flags |= ANALOG_FLAG_REVERSE;
24572692            break;
24582693
24592694         case INPUT_TOKEN_RESET:
24602695            if (curfield == NULL)
2461               fatalerror("INPUT_TOKEN_RESET encountered with no active field");
2696            {
2697               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_RESET encountered with no active field\n");
2698               break;
2699            }
24622700            curfield->flags |= ANALOG_FLAG_RESET;
24632701            break;
24642702
24652703         case INPUT_TOKEN_WRAPS:
24662704            if (curfield == NULL)
2467               fatalerror("INPUT_TOKEN_WRAPS encountered with no active field");
2705               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_WRAPS encountered with no active field\n");
24682706            curfield->flags |= ANALOG_FLAG_WRAPS;
24692707            break;
24702708
24712709         case INPUT_TOKEN_INVERT:
24722710            if (curfield == NULL)
2473               fatalerror("INPUT_TOKEN_INVERT encountered with no active field");
2711            {
2712               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_INVERT encountered with no active field\n");
2713               break;
2714            }
24742715            curfield->flags |= ANALOG_FLAG_INVERT;
24752716            break;
24762717
24772718         /* analog crosshair parameters */
24782719         case INPUT_TOKEN_CROSSHAIR:
2720            TOKEN_UNGET_UINT32(ipt);
24792721            if (curfield == NULL)
2480               fatalerror("INPUT_TOKEN_CROSSHAIR encountered with no active field");
2481
2482            TOKEN_UNGET_UINT32(ipt);
2722            {
2723               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_CROSSHAIR encountered with no active field\n");
2724               TOKEN_SKIP_UINT32(ipt);
2725               TOKEN_SKIP_UINT64(ipt);
2726               break;
2727            }
24832728            TOKEN_GET_UINT32_UNPACK3(ipt, entrytype, 8, curfield->crossaxis, 4, curfield->crossaltaxis, -20);
24842729            TOKEN_GET_UINT64_UNPACK2(ipt, curfield->crossscale, -32, curfield->crossoffset, -32);
2485
24862730            curfield->crossaltaxis *= 1.0f / 65536.0f;
24872731            curfield->crossscale *= 1.0f / 65536.0f;
24882732            curfield->crossoffset *= 1.0f / 65536.0f;
r2762r2763
24902734
24912735         /* analog decrement sequence */
24922736         case INPUT_TOKEN_CODE_DEC:
2737            TOKEN_UNGET_UINT32(ipt);
24932738            if (curfield == NULL)
2494               fatalerror("INPUT_TOKEN_CODE_DEC encountered with no active field");
2739            {
2740               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_CODE_DEC encountered with no active field\n");
2741               TOKEN_SKIP_UINT64(ipt);
2742               break;
2743            }
24952744            index = entrytype - INPUT_TOKEN_CODE;
2496
2497            TOKEN_UNGET_UINT32(ipt);
24982745            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, val, 32);
2499
25002746            input_seq_append_or(&curfield->seq[SEQ_TYPE_DECREMENT], val);
25012747            break;
25022748
25032749         /* analog increment sequence */
25042750         case INPUT_TOKEN_CODE_INC:
2751            TOKEN_UNGET_UINT32(ipt);
25052752            if (curfield == NULL)
2506               fatalerror("INPUT_TOKEN_CODE_INC encountered with no active field");
2753            {
2754               TOKEN_SKIP_UINT64(ipt);
2755               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_CODE_INC encountered with no active field\n");
2756               break;
2757            }
25072758            index = entrytype - INPUT_TOKEN_CODE;
2508
2509            TOKEN_UNGET_UINT32(ipt);
25102759            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, val, 32);
2511
25122760            input_seq_append_or(&curfield->seq[SEQ_TYPE_INCREMENT], val);
25132761            break;
25142762
2515         /* analog wraps flag */
2516
2763         /* analog full turn count */
25172764         case INPUT_TOKEN_FULL_TURN_COUNT:
2765            TOKEN_UNGET_UINT32(ipt);
25182766            if (curfield == NULL)
2519               fatalerror("INPUT_TOKEN_FULL_TURN_COUNT encountered with no active field");
2520            TOKEN_UNGET_UINT32(ipt);
2767            {
2768               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_FULL_TURN_COUNT encountered with no active field\n");
2769               TOKEN_SKIP_UINT32(ipt);
2770               break;
2771            }
25212772            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, curfield->full_turn_count, 24);
25222773            break;
25232774
25242775         case INPUT_TOKEN_POSITIONS:
2776            TOKEN_UNGET_UINT32(ipt);
25252777            if (curfield == NULL)
2526               fatalerror("INPUT_TOKEN_POSITIONS encountered with no active field");
2527            TOKEN_UNGET_UINT32(ipt);
2778            {
2779               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_POSITIONS encountered with no active field\n");
2780               TOKEN_SKIP_UINT32(ipt);
2781               break;
2782            }
25282783            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, curfield->max, 24);
25292784            break;
25302785
25312786         case INPUT_TOKEN_REMAP_TABLE:
25322787            if (curfield == NULL)
2533               fatalerror("INPUT_TOKEN_REMAP_TABLE encountered with no active field");
2788            {
2789               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_REMAP_TABLE encountered with no active field\n");
2790               TOKEN_SKIP_PTR(ipt);
2791               break;
2792            }
25342793            curfield->remap_table = TOKEN_GET_PTR(ipt, ui32ptr);
25352794            break;
25362795
25372796         /* DIP switch definition */
25382797         case INPUT_TOKEN_DIPNAME:
25392798            if (curport == NULL)
2540               fatalerror("INPUT_TOKEN_DIPNAME encountered with no active port");
2541
2799            {
2800               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_DIPNAME encountered with no active port\n");
2801               TOKEN_SKIP_UINT64(ipt);
2802               TOKEN_SKIP_STRING(ipt);
2803               break;
2804            }
25422805            TOKEN_GET_UINT64_UNPACK2(ipt, mask, 32, defval, 32);
2543
2806            if (curfield != NULL)
2807               field_config_insert(curfield, &maskbits, errorbuf, errorbuflen);
25442808            curfield = field_config_alloc(curport, IPT_DIPSWITCH, defval, mask);
25452809            cursetting = NULL;
2546
25472810            curfield->name = input_port_string_from_token(*ipt++);
25482811            break;
25492812
25502813         /* DIP switch setting */
25512814         case INPUT_TOKEN_DIPSETTING:
2815            TOKEN_UNGET_UINT32(ipt);
25522816            if (curfield == NULL)
2553               fatalerror("INPUT_TOKEN_DIPSETTING encountered with no active field");
2554
2555            TOKEN_UNGET_UINT32(ipt);
2817            {
2818               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_DIPSETTING encountered with no active field\n");
2819               TOKEN_SKIP_UINT64(ipt);
2820               TOKEN_SKIP_STRING(ipt);
2821               break;
2822            }
25562823            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, defval, 32);
2557
25582824            cursetting = setting_config_alloc(curfield, defval & curfield->mask, input_port_string_from_token(*ipt++));
25592825            break;
25602826
25612827         /* special DIP switch with on/off values */
25622828         case INPUT_TOKEN_SPECIAL_ONOFF:
2563            if (curport == NULL)
2564               fatalerror("INPUT_TOKEN_SPECIAL_ONOFF encountered with no active port");
2565
25662829            TOKEN_UNGET_UINT32(ipt);
25672830            TOKEN_GET_UINT32_UNPACK3(ipt, entrytype, 8, hasdiploc, 1, temptoken.i, 23);
25682831            TOKEN_GET_UINT64_UNPACK2(ipt, mask, 32, defval, 32);
25692832
2833            if (curport == NULL)
2834            {
2835               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_SPECIAL_ONOFF encountered with no active port\n");
2836               TOKEN_SKIP_UINT32(ipt);
2837               TOKEN_SKIP_UINT64(ipt);
2838               if (hasdiploc)
2839                  TOKEN_SKIP_STRING(ipt);
2840               break;
2841            }
2842            if (curfield != NULL)
2843               field_config_insert(curfield, &maskbits, errorbuf, errorbuflen);
25702844            curfield = field_config_alloc(curport, IPT_DIPSWITCH, defval, mask);
25712845            cursetting = NULL;
25722846
r2762r2763
25772851               curfield->seq[SEQ_TYPE_STANDARD].code[0] = KEYCODE_F2;
25782852            }
25792853            if (hasdiploc)
2580               curfield->diploclist = diplocation_list_alloc(curfield, TOKEN_GET_STRING(ipt));
2854               curfield->diploclist = diplocation_list_alloc(curfield, TOKEN_GET_STRING(ipt), errorbuf, errorbuflen);
25812855
25822856            temptoken.i = INPUT_STRING_Off;
25832857            cursetting = setting_config_alloc(curfield, defval & mask, input_port_string_from_token(temptoken));
r2762r2763
25892863         /* configuration definition */
25902864         case INPUT_TOKEN_CONFNAME:
25912865            if (curport == NULL)
2592               fatalerror("INPUT_TOKEN_CONFNAME encountered with no active port");
2593
2866            {
2867               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_CONFNAME encountered with no active port\n");
2868               TOKEN_SKIP_UINT64(ipt);
2869               TOKEN_SKIP_STRING(ipt);
2870               break;
2871            }
25942872            TOKEN_GET_UINT64_UNPACK2(ipt, mask, 32, defval, 32);
2595
2873            if (curfield != NULL)
2874               field_config_insert(curfield, &maskbits, errorbuf, errorbuflen);
25962875            curfield = field_config_alloc(curport, IPT_CONFIG, defval, mask);
25972876            cursetting = NULL;
2598
25992877            curfield->name = input_port_string_from_token(*ipt++);
26002878            break;
26012879
26022880         /* configuration setting */
26032881         case INPUT_TOKEN_CONFSETTING:
2882            TOKEN_UNGET_UINT32(ipt);
26042883            if (curfield == NULL)
2605               fatalerror("INPUT_TOKEN_CONFSETTING encountered with no active field");
2606
2607            TOKEN_UNGET_UINT32(ipt);
2884            {
2885               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_CONFSETTING encountered with no active field\n");
2886               TOKEN_SKIP_UINT64(ipt);
2887               TOKEN_SKIP_STRING(ipt);
2888               break;
2889            }
26082890            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, defval, 32);
2609
26102891            cursetting = setting_config_alloc(curfield, defval & curfield->mask, input_port_string_from_token(*ipt++));
26112892            break;
26122893
26132894         /* configuration definition */
26142895         case INPUT_TOKEN_CATEGORY_NAME:
26152896            if (curport == NULL)
2616               fatalerror("INPUT_TOKEN_CATEGORY_NAME encountered with no active port");
2617
2897            {
2898               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_CATEGORY_NAME encountered with no active port\n");
2899               TOKEN_SKIP_UINT64(ipt);
2900               TOKEN_SKIP_STRING(ipt);
2901               break;
2902            }
26182903            TOKEN_GET_UINT64_UNPACK2(ipt, mask, 32, defval, 32);
2619
2904            if (curfield != NULL)
2905               field_config_insert(curfield, &maskbits, errorbuf, errorbuflen);
26202906            curfield = field_config_alloc(curport, IPT_CATEGORY, defval, mask);
26212907            cursetting = NULL;
2622
26232908            curfield->name = input_port_string_from_token(*ipt++);
26242909            break;
26252910
26262911         /* configuration setting */
26272912         case INPUT_TOKEN_CATEGORY_SETTING:
2913            TOKEN_UNGET_UINT32(ipt);
26282914            if (curfield == NULL)
2629               fatalerror("INPUT_TOKEN_CATEGORY_SETTING encountered with no active field");
2630
2631            TOKEN_UNGET_UINT32(ipt);
2915            {
2916               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_CATEGORY_SETTING encountered with no active field\n");
2917               TOKEN_SKIP_UINT64(ipt);
2918               TOKEN_SKIP_STRING(ipt);
2919               break;
2920            }
26322921            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, defval, 32);
2633
26342922            cursetting = setting_config_alloc(curfield, defval & curfield->mask, input_port_string_from_token(*ipt++));
26352923            break;
26362924
26372925         /* analog adjuster definition */
26382926         case INPUT_TOKEN_ADJUSTER:
2927            TOKEN_UNGET_UINT32(ipt);
26392928            if (curport == NULL)
2640               fatalerror("INPUT_TOKEN_ADJUSTER encountered with no active port");
2641
2642            TOKEN_UNGET_UINT32(ipt);
2929            {
2930               error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_ADJUSTER encountered with no active port\n");
2931               TOKEN_SKIP_UINT64(ipt);
2932               TOKEN_SKIP_STRING(ipt);
2933               break;
2934            }
26432935            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, defval, 32);
2644
2936            if (curfield != NULL)
2937               field_config_insert(curfield, &maskbits, errorbuf, errorbuflen);
26452938            curfield = field_config_alloc(curport, IPT_ADJUSTER, defval, 0xff);
26462939            cursetting = NULL;
2647
26482940            curfield->name = TOKEN_GET_STRING(ipt);
26492941            break;
26502942
26512943         default:
2652            fatalerror("Invalid token %d in input ports\n", entrytype);
2944            error_buf_append(errorbuf, errorbuflen, "Invalid token %d in input ports\n", entrytype);
26532945            break;
26542946      }
26552947   }
26562948
2949   /* insert any pending fields */
2950   if (curfield != NULL)
2951      field_config_insert(curfield, &maskbits, errorbuf, errorbuflen);
2952
26572953   return listhead;
26582954}
26592955
r2762r2763
27233019
27243020/*-------------------------------------------------
27253021    field_config_alloc - allocate a new input
2726    port field config, replacing any intersecting
2727    fields already present and inserting at the
2728    correct sorted location
3022    port field config
27293023-------------------------------------------------*/
27303024
27313025static input_field_config *field_config_alloc(input_port_config *port, int type, input_port_value defvalue, input_port_value maskbits)
27323026{
3027   input_field_config *config;
3028   int seqtype;
3029
3030   /* allocate memory */
3031   config = malloc_or_die(sizeof(*config));
3032   memset(config, 0, sizeof(*config));
3033
3034   /* fill in the basic field values */
3035   config->port = port;
3036   config->type = type;
3037   config->mask = maskbits;
3038   config->defvalue = defvalue & maskbits;
3039   config->max = maskbits;
3040   for (seqtype = 0; seqtype < ARRAY_LENGTH(config->seq); seqtype++)
3041      input_seq_set_1(&config->seq[seqtype], SEQCODE_DEFAULT);
3042
3043   return config;
3044}
3045
3046
3047/*-------------------------------------------------
3048    field_config_insert - insert an allocated
3049    input port field config, replacing any
3050    intersecting fields already present and
3051    inserting at the correct sorted location
3052-------------------------------------------------*/
3053
3054static void field_config_insert(input_field_config *field, input_port_value *disallowedbits, char *errorbuf, int errorbuflen)
3055{
27333056   const input_field_config * const *scanfieldptr;
27343057   const input_field_config * const *scanfieldnextptr;
27353058   input_field_config *config;
27363059   input_port_value lowbit;
2737   int seqtype;
27383060
3061   /* verify against the disallowed bits, but only if we are condition-free */
3062   if (field->condition.condition == PORTCOND_ALWAYS)
3063   {
3064      if ((field->mask & *disallowedbits) != 0)
3065         error_buf_append(errorbuf, errorbuflen, "INPUT_TOKEN_FIELD specifies duplicate port bits (mask=%X)\n", field->mask);
3066      *disallowedbits |= field->mask;
3067   }
3068
27393069   /* first modify/nuke any entries that intersect our maskbits */
2740   for (scanfieldptr = &port->fieldlist; *scanfieldptr != NULL; scanfieldptr = scanfieldnextptr)
3070   for (scanfieldptr = &field->port->fieldlist; *scanfieldptr != NULL; scanfieldptr = scanfieldnextptr)
27413071   {
27423072      scanfieldnextptr = &(*scanfieldptr)->next;
2743      if (((*scanfieldptr)->mask & maskbits) != 0)
3073      if (((*scanfieldptr)->mask & field->mask) != 0 && (field->condition.condition == PORTCOND_ALWAYS || condition_equal(&(*scanfieldptr)->condition, &field->condition)))
27443074      {
27453075         /* reduce the mask of the field we found */
27463076         config = (input_field_config *)*scanfieldptr;
2747         config->mask &= ~maskbits;
3077         config->mask &= ~field->mask;
27483078
27493079         /* if the new entry fully overrides the previous one, we nuke */
27503080         if (config->mask == 0)
r2762r2763
27563086   }
27573087
27583088   /* make a mask of just the low bit */
2759   lowbit = (maskbits ^ (maskbits - 1)) & maskbits;
3089   lowbit = (field->mask ^ (field->mask - 1)) & field->mask;
27603090
27613091   /* scan forward to find where to insert ourselves */
2762   for (scanfieldptr = (const input_field_config * const *)&port->fieldlist; *scanfieldptr != NULL; scanfieldptr = &(*scanfieldptr)->next)
3092   for (scanfieldptr = (const input_field_config * const *)&field->port->fieldlist; *scanfieldptr != NULL; scanfieldptr = &(*scanfieldptr)->next)
27633093      if ((*scanfieldptr)->mask > lowbit)
27643094         break;
27653095
2766   /* allocate memory */
2767   config = malloc_or_die(sizeof(*config));
2768   memset(config, 0, sizeof(*config));
2769
2770   /* fill in the basic field values */
2771   config->port = port;
2772   config->type = type;
2773   config->mask = maskbits;
2774   config->defvalue = defvalue & maskbits;
2775   config->max = maskbits;
2776   for (seqtype = 0; seqtype < ARRAY_LENGTH(config->seq); seqtype++)
2777      input_seq_set_1(&config->seq[seqtype], SEQCODE_DEFAULT);
2778
27793096   /* insert it into the list */
2780   config->next = *scanfieldptr;
2781   *(input_field_config **)scanfieldptr = config;
2782
2783   return config;
3097   field->next = *scanfieldptr;
3098   *(input_field_config **)scanfieldptr = field;
27843099}
27853100
27863101
r2762r2763
28583173    descriptions
28593174-------------------------------------------------*/
28603175
2861static const input_field_diplocation *diplocation_list_alloc(const input_field_config *field, const char *location)
3176static const input_field_diplocation *diplocation_list_alloc(const input_field_config *field, const char *location, char *errorbuf, int errorbuflen)
28623177{
28633178   input_field_diplocation *head = NULL;
28643179   input_field_diplocation **tailptr = &head;
r2762r2763
29103225      {
29113226         char *namecopy;
29123227         if (lastname == NULL)
2913            fatalerror("Switch location '%s' missing switch name!", location);
3228         {
3229            error_buf_append(errorbuf, errorbuflen, "Switch location '%s' missing switch name!\n", location);
3230            lastname = (char *)"UNK";
3231         }
29143232         (*tailptr)->swname = namecopy = malloc_or_die(strlen(lastname) + 1);
29153233         strcpy(namecopy, lastname);
29163234      }
r2762r2763
29253243
29263244      /* now scan the switch number */
29273245      if (sscanf(number, "%d", &val) != 1)
2928         fatalerror("Switch location '%s' has invalid format!", location);
2929      (*tailptr)->swnum = val;
3246         error_buf_append(errorbuf, errorbuflen, "Switch location '%s' has invalid format!\n", location);
3247      else
3248         (*tailptr)->swnum = val;
29303249
29313250      /* advance to the next item */
29323251      curentry = comma;
r2762r2763
29393258   for (bits = 0, temp = field->mask; temp != 0 && bits < 32; bits++)
29403259      temp &= temp - 1;
29413260   if (bits != entries)
2942      fatalerror("Switch location '%s' does not describe enough bits for mask %X\n", location, field->mask);
3261      error_buf_append(errorbuf, errorbuflen, "Switch location '%s' does not describe enough bits for mask %X\n", location, field->mask);
29433262   return head;
29443263}
29453264
r2762r2763
32183537   input_port_value mask, defvalue;
32193538   const input_field_config *field;
32203539   const input_port_config *port;
3540   char tempbuffer[20];
32213541   const char *tag;
32223542
32233543   /* read the mask, index, and defvalue attributes */
r2762r2763
32273547
32283548   /* find the port we want; if no tag, search them all */
32293549   for (port = machine->portconfig; port != NULL; port = port->next)
3230      if (tag == NULL || (port->tag != NULL && strcmp(port->tag, tag) == 0))
3550      if (tag == NULL || strcmp(get_port_tag(port, tempbuffer), tag) == 0)
32313551         for (field = port->fieldlist; field != NULL; field = field->next)
32323552
32333553            /* find the matching mask and defvalue */
r2762r2763
34203740               xml_data_node *portnode = xml_add_child(parentnode, "port", NULL);
34213741               if (portnode != NULL)
34223742               {
3743                  char tempbuffer[20];
3744
34233745                  /* add the identifying information and attributes */
3424                  xml_set_attribute(portnode, "tag", port->tag);
3746                  xml_set_attribute(portnode, "tag", get_port_tag(port, tempbuffer));
34253747                  xml_set_attribute(portnode, "type", input_field_type_to_token(machine, field->type, field->player));
34263748                  xml_set_attribute_int(portnode, "mask", field->mask);
34273749                  xml_set_attribute_int(portnode, "defvalue", field->defvalue & field->mask);
src/emu/machine/generic.c
r2762r2763
2424UINT32 dispensed_tickets;
2525UINT32 coin_count[COIN_COUNTERS];
2626UINT32 coinlockedout[COIN_COUNTERS];
27UINT32 servicecoinlockedout[COIN_COUNTERS];
2827static UINT32 lastcoin[COIN_COUNTERS];
2928
3029/* generic NVRAM */
r2762r2763
7069   {
7170      lastcoin[counternum] = 0;
7271      coinlockedout[counternum] = 0;
73      servicecoinlockedout[counternum] = 0;
7472   }
7573
7674   /* register coin save state */
7775   state_save_register_item_array("coin", 0, coin_count);
7876   state_save_register_item_array("coin", 0, coinlockedout);
79   state_save_register_item_array("coin", 0, servicecoinlockedout);
8077   state_save_register_item_array("coin", 0, lastcoin);
8178
8279   /* reset NVRAM size and pointers */
r2762r2763
212209
213210
214211/*-------------------------------------------------
215    service_coin_lockout_w - locks out one coin input
216-------------------------------------------------*/
217
218void service_coin_lockout_w(int num,int on)
219{
220   if (num >= COIN_COUNTERS) return;
221
222   servicecoinlockedout[num] = on;
223}
224
225
226/*-------------------------------------------------
227212    coin_lockout_global_w - locks out all the coin
228213    inputs
229214-------------------------------------------------*/
src/emu/machine/generic.h
r2762r2763
3939extern UINT32 dispensed_tickets;
4040extern UINT32 coin_count[COIN_COUNTERS];
4141extern UINT32 coinlockedout[COIN_COUNTERS];
42extern UINT32 servicecoinlockedout[COIN_COUNTERS];
4342
4443extern size_t generic_nvram_size;
4544extern UINT8 *generic_nvram;
r2762r2763
6867/* enable/disable coin lockout for a particular coin */
6968void coin_lockout_w(int num, int on);
7069
71/* enable/disable coin lockout for a particular coin */
72void service_coin_lockout_w(int num, int on);
73
7470/* enable/disable global coin lockout */
7571void coin_lockout_global_w(int on);
7672
src/emu/machine/eeprom.c
r2762r2763
77#define SERIAL_BUFFER_LENGTH 40
88#define MEMORY_SIZE 1024
99
10static const struct EEPROM_interface *intf;
10static const eeprom_interface *intf;
1111
1212static int serial_count;
1313static UINT8 serial_buffer[SERIAL_BUFFER_LENGTH];
r2762r2763
2020static int reset_delay;
2121
2222/*
23    EEPROM_command_match:
23    eeprom_command_match:
2424
2525    Try to match the first (len) digits in the EEPROM serial buffer
2626    string (*buf) with  an EEPROM command string (*cmd).
r2762r2763
3535
3636    Note: (cmd) may be NULL. Return 0 (no match) in this case.
3737*/
38static int EEPROM_command_match(const char *buf, const char *cmd, int len)
38static int eeprom_command_match(const char *buf, const char *cmd, int len)
3939{
4040   if ( cmd == 0 )   return 0;
4141   if ( len == 0 )   return 0;
r2762r2763
7777}
7878
7979
80const struct EEPROM_interface eeprom_interface_93C46 =
80const eeprom_interface eeprom_interface_93C46 =
8181{
8282   6,            // address bits 6
8383   16,            // data bits    16
r2762r2763
9191//  "*10010xxxx"    // erase all    1 00 10xxxx
9292};
9393
94const struct EEPROM_interface eeprom_interface_93C66B =
94const eeprom_interface eeprom_interface_93C66B =
9595{
9696   8,            /* address bits */
9797   16,            /* data bits */
r2762r2763
108108NVRAM_HANDLER( 93C46 )
109109{
110110   if (read_or_write)
111      EEPROM_save(file);
111      eeprom_save(file);
112112   else
113113   {
114      EEPROM_init(&eeprom_interface_93C46);
115      if (file)   EEPROM_load(file);
114      eeprom_init(&eeprom_interface_93C46);
115      if (file)   eeprom_load(file);
116116   }
117117}
118118
119119NVRAM_HANDLER( 93C66B )
120120{
121121   if (read_or_write)
122      EEPROM_save(file);
122      eeprom_save(file);
123123   else
124124   {
125      EEPROM_init(&eeprom_interface_93C66B);
126      if (file)   EEPROM_load(file);
125      eeprom_init(&eeprom_interface_93C66B);
126      if (file)   eeprom_load(file);
127127   }
128128}
129129
130void EEPROM_init(const struct EEPROM_interface *interface)
130void eeprom_init(const eeprom_interface *interface)
131131{
132132   intf = interface;
133133
r2762r2763
159159   state_save_register_global(eeprom_read_address);
160160}
161161
162static void EEPROM_write(int bit)
162static void eeprom_write(int bit)
163163{
164164   LOG(("EEPROM write bit %d\n",bit));
165165
r2762r2763
173173   serial_buffer[serial_count] = 0;   /* nul terminate so we can treat it as a string */
174174
175175   if ( (serial_count > intf->address_bits) &&
176         EEPROM_command_match((char*)serial_buffer,intf->cmd_read,strlen((char*)serial_buffer)-intf->address_bits) )
176         eeprom_command_match((char*)serial_buffer,intf->cmd_read,strlen((char*)serial_buffer)-intf->address_bits) )
177177   {
178178      int i,address;
179179
r2762r2763
194194logerror("EEPROM read %04x from address %02x\n",eeprom_data_bits,address);
195195   }
196196   else if ( (serial_count > intf->address_bits) &&
197              EEPROM_command_match((char*)serial_buffer,intf->cmd_erase,strlen((char*)serial_buffer)-intf->address_bits) )
197              eeprom_command_match((char*)serial_buffer,intf->cmd_erase,strlen((char*)serial_buffer)-intf->address_bits) )
198198   {
199199      int i,address;
200200
r2762r2763
220220      serial_count = 0;
221221   }
222222   else if ( (serial_count > (intf->address_bits + intf->data_bits)) &&
223              EEPROM_command_match((char*)serial_buffer,intf->cmd_write,strlen((char*)serial_buffer)-(intf->address_bits + intf->data_bits)) )
223              eeprom_command_match((char*)serial_buffer,intf->cmd_write,strlen((char*)serial_buffer)-(intf->address_bits + intf->data_bits)) )
224224   {
225225      int i,address,data;
226226
r2762r2763
251251logerror("Error: EEPROM is locked\n");
252252      serial_count = 0;
253253   }
254   else if ( EEPROM_command_match((char*)serial_buffer,intf->cmd_lock,strlen((char*)serial_buffer)) )
254   else if ( eeprom_command_match((char*)serial_buffer,intf->cmd_lock,strlen((char*)serial_buffer)) )
255255   {
256256logerror("EEPROM lock\n");
257257      locked = 1;
258258      serial_count = 0;
259259   }
260   else if ( EEPROM_command_match((char*)serial_buffer,intf->cmd_unlock,strlen((char*)serial_buffer)) )
260   else if ( eeprom_command_match((char*)serial_buffer,intf->cmd_unlock,strlen((char*)serial_buffer)) )
261261   {
262262logerror("EEPROM unlock\n");
263263      locked = 0;
r2762r2763
265265   }
266266}
267267
268static void EEPROM_reset(void)
268static void eeprom_reset(void)
269269{
270270if (serial_count)
271271   logerror("EEPROM reset, buffer = %s\n",serial_buffer);
r2762r2763
276276}
277277
278278
279void EEPROM_write_bit(int bit)
279void eeprom_write_bit(int bit)
280280{
281281   LOG(("write bit %d\n",bit));
282282   latch = bit;
283283}
284284
285int EEPROM_read_bit(void)
285int eeprom_read_bit(void)
286286{
287287   int res;
288288
r2762r2763
305305   return res;
306306}
307307
308void EEPROM_set_cs_line(int state)
308CUSTOM_INPUT( eeprom_bit_r )
309309{
310   return eeprom_read_bit();
311}
312
313void eeprom_set_cs_line(int state)
314{
310315   LOG(("set reset line %d\n",state));
311316   reset_line = state;
312317
313318   if (reset_line != CLEAR_LINE)
314      EEPROM_reset();
319      eeprom_reset();
315320}
316321
317void EEPROM_set_clock_line(int state)
322void eeprom_set_clock_line(int state)
318323{
319324   LOG(("set clock line %d\n",state));
320325   if (state == PULSE_LINE || (clock_line == CLEAR_LINE && state != CLEAR_LINE))
r2762r2763
337342            eeprom_clock_count++;
338343         }
339344         else
340            EEPROM_write(latch);
345            eeprom_write(latch);
341346      }
342347   }
343348
r2762r2763
345350}
346351
347352
348void EEPROM_load(mame_file *f)
353void eeprom_load(mame_file *f)
349354{
350355   mame_fread(f,eeprom_data,(1 << intf->address_bits) * intf->data_bits / 8);
351356}
352357
353void EEPROM_save(mame_file *f)
358void eeprom_save(mame_file *f)
354359{
355360   mame_fwrite(f,eeprom_data,(1 << intf->address_bits) * intf->data_bits / 8);
356361}
357362
358void EEPROM_set_data(const UINT8 *data, int length)
363void eeprom_set_data(const UINT8 *data, int length)
359364{
360365   memcpy(eeprom_data, data, length);
361366}
362367
363UINT8 * EEPROM_get_data_pointer(int * length)
368UINT8 * eeprom_get_data_pointer(int * length)
364369{
365370   if(length)
366371      *length = MEMORY_SIZE;
src/emu/machine/8257dma.c
r2762r2763
44
55    For datasheet http://www.threedee.com/jcm/library/index.html
66
7    2008/05     Miodrag Milanovic
8
9        - added support for autoload mode
10        - fixed bug in calculating count
11
712    2007/11     couriersud
813
914        - architecture copied from 8237 DMA
r2762r2763
165170   }
166171   if (done)
167172   {
173      if ((channel==2) && DMA_MODE_AUTOLOAD(dma[which].mode)) {
174         /* in case of autoload at the end channel 3 info is */
175         /* copied to channel 2 info                         */
176         dma[which].registers[4] = dma[which].registers[6];
177         dma[which].registers[5] = dma[which].registers[7];
178      }
168179      if (dma[which].intf->out_tc_func[channel])
169180         dma[which].intf->out_tc_func[channel](CLEAR_LINE);
170181   }
r2762r2763
305316         dma[which].registers[offset] |= ((UINT16) data) << 8;
306317      else
307318         dma[which].registers[offset] = data;
319
320      if (DMA_MODE_AUTOLOAD(dma[which].mode)) {
321         /* in case of autoload when inserting channel 2 info */
322         /* it is automaticaly copied to channel 3 info       */
323         switch(offset) {
324            case 4:
325            case 5:
326               if (dma[which].msb)
327                  dma[which].registers[offset+2] |= ((UINT16) data) << 8;
328               else
329                  dma[which].registers[offset+2] = data;
330         }
331      }
332
308333      prepare_msb_flip(which);
309334      break;
310335
311336   case 8:
312337      /* DMA mode register */
313      if (DMA_MODE_AUTOLOAD(data)   )
314         fatalerror("8257: Autoload not supported!\n");
315338      dma[which].mode = data;
316339      break;
317340
r2762r2763
334357   {
335358      dma[which].drq |= 0x01 << channel;
336359      dma[which].address[channel] =  dma[which].registers[channel * 2];
337      dma[which].count[channel] =  dma[which].registers[channel * 2 + 1] & 0x3FF;
360      dma[which].count[channel] =  dma[which].registers[channel * 2 + 1] & 0x3FFF;
338361      dma[which].rwmode[channel] =  dma[which].registers[channel * 2 + 1] >> 14;
339362      /* clear channel TC */
340363      dma[which].status &= ~(0x01 << channel);
src/emu/machine/eeprom.h
r2762r2763
1#ifndef EEPROM_H
2#define EEPROM_H
1#ifndef eeprom_H
2#define eeprom_H
33
4struct EEPROM_interface
4typedef struct _eeprom_interface eeprom_interface;
5struct _eeprom_interface
56{
67   int address_bits;   /* EEPROM has 2^address_bits cells */
78   int data_bits;      /* every cell has this many bits (8 or 16) */
r2762r2763
1112   const char *cmd_lock;   /*   lock command string, or 0 if n/a */
1213   const char *cmd_unlock;   /* unlock command string, or 0 if n/a */
1314   int enable_multi_read;/* set to 1 to enable multiple values to be read from one read command */
14   int reset_delay;   /* number of times EEPROM_read_bit() should return 0 after a reset, */
15   int reset_delay;   /* number of times eeprom_read_bit() should return 0 after a reset, */
1516                  /* before starting to return 1. */
1617};
1718
1819
19void EEPROM_init(const struct EEPROM_interface *interface);
20void eeprom_init(const eeprom_interface *interface);
2021
21void EEPROM_write_bit(int bit);
22int EEPROM_read_bit(void);
23void EEPROM_set_cs_line(int state);
24void EEPROM_set_clock_line(int state);
22void eeprom_write_bit(int bit);
23int eeprom_read_bit(void);
24CUSTOM_INPUT( eeprom_bit_r );
25void eeprom_set_cs_line(int state);
26void eeprom_set_clock_line(int state);
2527
26void EEPROM_load(mame_file *file);
27void EEPROM_save(mame_file *file);
28void eeprom_load(mame_file *file);
29void eeprom_save(mame_file *file);
2830
29void EEPROM_set_data(const UINT8 *data, int length);
30UINT8 * EEPROM_get_data_pointer(int * length);
31void eeprom_set_data(const UINT8 *data, int length);
32UINT8 * eeprom_get_data_pointer(int * length);
3133
3234/* 93C46 */
33extern const struct EEPROM_interface eeprom_interface_93C46;
35extern const eeprom_interface eeprom_interface_93C46;
3436NVRAM_HANDLER( 93C46 );
3537
3638/* 93C66B */
37extern const struct EEPROM_interface eeprom_interface_93C66B;
39extern const eeprom_interface eeprom_interface_93C66B;
3840NVRAM_HANDLER( 93C66B );
3941
4042#endif
src/emu/inptport.h
r2762r2763
936936/* ----- port configurations ----- */
937937
938938/* allocate a list of input ports from the given token list */
939const input_port_config *input_port_config_alloc(const input_port_token *tokens);
939const input_port_config *input_port_config_alloc(const input_port_token *tokens, char *errorbuf, int errorbuflen);
940940
941941/* free memory allocated from input_port_alloc */
942942void input_port_config_free(const input_port_config *portlist);
r2762r2763
988988/* modify the current settings for the given input field */
989989void input_field_set_user_settings(const input_field_config *field, const input_field_user_settings *settings);
990990
991/* select the previous item for a DIP switch or configuration field */
992void input_field_select_previous_setting(const input_field_config *field);
991993
994/* select the next item for a DIP switch or configuration field */
995void input_field_select_next_setting(const input_field_config *field);
992996
997
993998/* ----- user interface sequence reading ----- */
994999
9951000/* return TRUE if a key down for the given user interface sequence is detected */
src/emu/cpuintrf.c
r2762r2763
12691269   else
12701270      pc >>= shift;
12711271   if (cpu[activecpu].intf.translate)
1272      (*cpu[activecpu].intf.translate)(ADDRESS_SPACE_PROGRAM, &pc);
1272      (*cpu[activecpu].intf.translate)(ADDRESS_SPACE_PROGRAM, TRANSLATE_FETCH, &pc);
12731273   return pc;
12741274}
12751275
r2762r2763
15261526   else
15271527      pc >>= shift;
15281528   if (cpu[activecpu].intf.translate)
1529      (*cpu[activecpu].intf.translate)(ADDRESS_SPACE_PROGRAM, &pc);
1529      (*cpu[activecpu].intf.translate)(ADDRESS_SPACE_PROGRAM, TRANSLATE_FETCH, &pc);
15301530   cpuintrf_pop_context();
15311531   return pc;
15321532}
src/emu/cpuexec.c
r2762r2763
777777
778778         /* start the interrupt counter */
779779         if (!(cpu[cpunum].suspend & SUSPEND_REASON_DISABLE))
780            cpu[cpunum].iloops = config->vblank_interrupts_per_frame - 1;
780            cpu[cpunum].iloops = 0;
781781         else
782782            cpu[cpunum].iloops = -1;
783783
r2762r2763
799799            if (!cpunum_is_suspended(cpunum, SUSPEND_REASON_HALT | SUSPEND_REASON_RESET | SUSPEND_REASON_DISABLE))
800800            {
801801               cpuintrf_push_context(cpunum);
802               (*device->machine->config->cpu[cpunum].vblank_interrupt)(device->machine, cpunum);
802               (*config->vblank_interrupt)(device->machine, cpunum);
803803               cpuintrf_pop_context();
804804            }
805805
r2762r2763
824824static TIMER_CALLBACK( trigger_partial_frame_interrupt )
825825{
826826   int cpunum = param;
827   const cpu_config *config = machine->config->cpu + cpunum;
827828
829   if (cpu[cpunum].iloops == 0)
830      cpu[cpunum].iloops = config->vblank_interrupts_per_frame;
831
828832   cpu[cpunum].iloops--;
829833
830834   /* call the interrupt handler */
831835   if (!cpunum_is_suspended(cpunum, SUSPEND_REASON_HALT | SUSPEND_REASON_RESET | SUSPEND_REASON_DISABLE))
832836   {
833837      cpuintrf_push_context(cpunum);
834      (*machine->config->cpu[cpunum].vblank_interrupt)(machine, cpunum);
838      (*config->vblank_interrupt)(machine, cpunum);
835839      cpuintrf_pop_context();
836840   }
837841
838842   /* more? */
839   if (cpu[cpunum].iloops > 0)
843   if (cpu[cpunum].iloops > 1)
840844      timer_adjust_oneshot(cpu[cpunum].partial_frame_timer, cpu[cpunum].partial_frame_period, cpunum);
841845}
842846
src/emu/cpuintrf.h
r2762r2763
124124   CPUINFO_PTR_EXECUTE,                        /* R/O: int (*execute)(int cycles) */
125125   CPUINFO_PTR_BURN,                           /* R/O: void (*burn)(int cycles) */
126126   CPUINFO_PTR_DISASSEMBLE,                     /* R/O: offs_t (*disassemble)(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram) */
127   CPUINFO_PTR_TRANSLATE,                        /* R/O: int (*translate)(int space, offs_t *address) */
127   CPUINFO_PTR_TRANSLATE,                        /* R/O: int (*translate)(int space, int intention, offs_t *address) */
128128   CPUINFO_PTR_READ,                           /* R/O: int (*read)(int space, UINT32 offset, int size, UINT64 *value) */
129129   CPUINFO_PTR_WRITE,                           /* R/O: int (*write)(int space, UINT32 offset, int size, UINT64 value) */
130130   CPUINFO_PTR_READOP,                           /* R/O: int (*readop)(UINT32 offset, int size, UINT64 *value) */
r2762r2763
178178};
179179
180180
181/* Translation intentions */
182#define TRANSLATE_TYPE_MASK      0x03      /* read write or fetch */
183#define TRANSLATE_USER_MASK      0x04      /* user mode or fully privileged */
184#define TRANSLATE_DEBUG_MASK   0x08      /* debug mode (no side effects) */
185
186#define TRANSLATE_READ         0         /* translate for read */
187#define TRANSLATE_WRITE         1         /* translate for write */
188#define TRANSLATE_FETCH         2         /* translate for instruction fetch */
189#define TRANSLATE_READ_USER      (TRANSLATE_READ | TRANSLATE_USER_MASK)
190#define TRANSLATE_WRITE_USER   (TRANSLATE_WRITE | TRANSLATE_USER_MASK)
191#define TRANSLATE_FETCH_USER   (TRANSLATE_FETCH | TRANSLATE_USER_MASK)
192#define TRANSLATE_READ_DEBUG   (TRANSLATE_READ | TRANSLATE_DEBUG_MASK)
193#define TRANSLATE_WRITE_DEBUG   (TRANSLATE_WRITE | TRANSLATE_DEBUG_MASK)
194#define TRANSLATE_FETCH_DEBUG   (TRANSLATE_FETCH | TRANSLATE_DEBUG_MASK)
195
196
181197/* Disassembler constants */
182198#define DASMFLAG_SUPPORTED      0x80000000   /* are disassembly flags supported? */
183199#define DASMFLAG_STEP_OUT      0x40000000   /* this instruction should be the end of a step out sequence */
r2762r2763
208224typedef int   (*cpu_execute_func)(int cycles);
209225typedef void (*cpu_burn_func)(int cycles);
210226typedef offs_t (*cpu_disassemble_func)(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram);
211typedef int   (*cpu_translate_func)(int space, offs_t *address);
227typedef int   (*cpu_translate_func)(int space, int intention, offs_t *address);
212228typedef int   (*cpu_read_func)(int space, UINT32 offset, int size, UINT64 *value);
213229typedef int   (*cpu_write_func)(int space, UINT32 offset, int size, UINT64 value);
214230typedef int   (*cpu_readop_func)(UINT32 offset, int size, UINT64 *value);
src/emu/ui.c
r2762r2763
15791579      numitems = cpu_gettotalcpu();
15801580      for (item = 0; item < numitems; item++)
15811581         slider_config(&slider_list[slider_count++], 10, 1000, 2000, 1, slider_overclock, (void *)(FPTR)item);
1582
1583      /* add refresh rate tweaker */
1584      slider_config(&slider_list[slider_count++], -10000, 0, 10000, 1000, slider_refresh, NULL);
15851582   }
15861583
15871584   for (item = 0; item < numscreens; item++)
r2762r2763
15941591      int defyoffset = floor(scrconfig->yoffset * 1000.0f + 0.5f);
15951592      void *param = (void *)screen;
15961593
1594      /* add refresh rate tweaker */
1595      if (options_get_bool(mame_options(), OPTION_CHEAT))
1596         slider_config(&slider_list[slider_count++], -10000, 0, 10000, 1000, slider_refresh, param);
1597
15971598      /* add standard brightness/contrast/gamma controls per-screen */
15981599      slider_config(&slider_list[slider_count++], 100, 1000, 2000, 10, slider_brightness, param);
15991600      slider_config(&slider_list[slider_count++], 100, 1000, 2000, 50, slider_contrast, param);
src/emu/tokenize.h
r2762r2763
128128#define TOKEN_UNGET_UINT32(tp)      ((tp)--)
129129#define TOKEN_UNGET_UINT64(tp)      ((tp) -= 8 / sizeof(FPTR))
130130
131/* token skip primitives */
132#define TOKEN_SKIP_PTR(tp)         ((tp)++)
133#define TOKEN_SKIP_STRING(tp)      ((tp)++)
134#define TOKEN_SKIP_UINT32(tp)      ((tp)++)
135#define TOKEN_SKIP_UINT64(tp)      ((tp) += 8 / sizeof(FPTR))
136
131137/* extract a value from a fixed number of bits; if bits is negative, treat it as a signed value */
132138#define UNSHIFT_AND_MASK32(src, val, bits, shift)   do { \
133139   if ((bits) < 0) \
src/emu/driver.h
r2762r2763
206206
207207/* this allows to leave the INIT field empty in the GAME() macro call */
208208#define driver_init_0 0
209#define ipt_0 0
209210
210211
211212
src/emu/cheat.c
r2762r2763
3939                                    k##name##_ShiftedMask = (int)(0xFFFFFFFF >> (32 - (start - end + 1))),   \
4040                                    k##name##_Mask = (int)(k##name##_ShiftedMask << k##name##_Shift)
4141
42#define kRegionListLength                  (REGION_MAX - REGION_INVALID)
42#define REGION_LIST_LENGTH                  (REGION_MAX - REGION_INVALID)
43#define VALID_CPU(cpu)                     (cpu < cpu_gettotalcpu())
4344
45#define ADD_MENU_2_ITEMS(name, sub_name)      do { menu_item[total] = name; menu_sub_item[total] = sub_name; total++; } while(0)
46#define TERMINATE_MENU_2_ITEMS               do { menu_item[total] = NULL; menu_sub_item[total] = NULL; } while(0)
47
48#define ADD_MENU_3_ITEMS(name, sub_name, enum)   do { menu_item[total] = name; menu_sub_item[total] = sub_name; menu_index[total] = enum; total++; } while(0)
49
50#define   ADJUST_CURSOR(sel, total)            if(sel < 0) sel = 0; else if(sel > (total - 1)) sel = (total - 1);
51#define   CURSOR_TO_NEXT(sel, total)            if(++sel > (total - 1)) sel = 0;
52#define   CURSOR_TO_PREVIOUS(sel, total)         if(--sel < 0) sel = (total - 1);
53#define   CURSOR_PAGE_UP(sel)                  sel -= visible_items; if(sel < 0) sel = 0;
54#define CURSOR_PAGE_DOWN(sel, total)         sel += visible_items; if(sel >= total) sel = (total - 1);
55
4456/***************************************************************************
4557    CONSTANTS
4658***************************************************************************/
4759
48#define CHEAT_FILENAME_MAX_LEN               255
60#define CHEAT_FILENAME_MAX_LEN               (255)
61#define CHEAT_MENU_DEPTH                  (8)
62#ifdef MESS
63#define DEFAULT_CHEAT_OPTIONS               (0x4F)
64#else
65#define DEFAULT_CHEAT_OPTIONS               (0xF)
66#endif
67#define DEFAULT_MESSAGE_TIME               (50)
68#define VARIABLE_MAX_ARRAY                  (0x0F)      // NOTE : Move code can accept max 16 variables as destination
69#define CHEAT_RETURN_VALUE                  (0xFF)
70#define CUSTOM_CODE                        (0xFF)
4971
5072/********** BIT FIELD **********/
5173
5274enum
5375{
54   /* cheat code */
76   /* type field */
5577   DEFINE_BITFIELD_ENUM(OneShot,               0,   0),
78   DEFINE_BITFIELD_ENUM(DelayEnable,            1,   1),
79   DEFINE_BITFIELD_ENUM(PrefillEnable,            2,   2),
80   DEFINE_BITFIELD_ENUM(Return,               3,   3),
81   DEFINE_BITFIELD_ENUM(RestoreValue,            4,   4),
82   DEFINE_BITFIELD_ENUM(DataRead,               5,   5),      // 0 = field, 1 = variable
83   DEFINE_BITFIELD_ENUM(AddressRead,            6,   7),      // 0 = field, 1 = indirect address from variable, 2 = variable
84   DEFINE_BITFIELD_ENUM(CodeParameter,            8,   11),
85   DEFINE_BITFIELD_ENUM(CodeType,               12,   15),
86   DEFINE_BITFIELD_ENUM(Link,                  16,   17),   // 0 = master, 1 = link, 2 = sub link for label-selection, 3 = copy link for VWrite, VRWrite
87   DEFINE_BITFIELD_ENUM(LinkValueSelectBCD,      18,   18),   // used by VWrite (link)
88   DEFINE_BITFIELD_ENUM(LinkValueSelectNegative,   19,   19),   // used by VWrite (link)
89   DEFINE_BITFIELD_ENUM(PopupParameter,         18,   19),   // used by Popup
90   DEFINE_BITFIELD_ENUM(AddressSize,            20,   21),
91   DEFINE_BITFIELD_ENUM(IndexSize,               22,   23),   // used by IWrite, VWrite, Move, Popup
92   DEFINE_BITFIELD_ENUM(CPURegion,               24, 31),   // extract to CPU/Region field
93
94   /* extend field */
95   DEFINE_BITFIELD_ENUM(LSB16,                  0,   15),   // lower 4 bytes
96   DEFINE_BITFIELD_ENUM(MSB16,                  16,   31),   // upper 4 bytes
97
98   /* value-select master code */
99   DEFINE_BITFIELD_ENUM(ValueSelectMinimumDisplay,   8,   8),
100   DEFINE_BITFIELD_ENUM(ValueSelectMinimum,      9,   9),
101   DEFINE_BITFIELD_ENUM(ValueSelectBCD,         10,   10),
102   DEFINE_BITFIELD_ENUM(ValueSelectNegative,      11,   11),
103
104   /* watch code */
105   DEFINE_BITFIELD_ENUM(WatchDisplayFormat,      8,   9),      // from type field
106   DEFINE_BITFIELD_ENUM(WatchShowLabel,         10,   10),   //
107   DEFINE_BITFIELD_ENUM(WatchNumElements,         0,   7),      // from data field
108   DEFINE_BITFIELD_ENUM(WatchSkip,               8,   15),   //
109   DEFINE_BITFIELD_ENUM(WatchElementsPerLine,      16,   23),   //
110   DEFINE_BITFIELD_ENUM(WatchAddValue,            24,   31),   //
111
112   /* label-selection */
113   DEFINE_BITFIELD_ENUM(LabelSelectUseSelector,   4,   4),
114   DEFINE_BITFIELD_ENUM(LabelSelectQuickClose,      5,   5),
115
116   /* cpu/region field */
117   DEFINE_BITFIELD_ENUM(CPUIndex,               0,   3),      // cpu region
118   DEFINE_BITFIELD_ENUM(AddressSpace,            4,   6),      // cpu region
119   DEFINE_BITFIELD_ENUM(RegionIndex,            0,   6),      // non-cpu region
120   DEFINE_BITFIELD_ENUM(RegionFlag,            7,   7),      // 0 = cpu, 1 = non-cpu
121
122   /* old code */
123//  DEFINE_BITFIELD_ENUM(OneShot,                   0,  0),
56124   DEFINE_BITFIELD_ENUM(Type,                  1,   2),
57125   DEFINE_BITFIELD_ENUM(Operation,               3,   4),
58126   DEFINE_BITFIELD_ENUM(TypeParameter,            5,   7),
r2762r2763
73141   DEFINE_BITFIELD_ENUM(LocationParameter,         24,   28),
74142   DEFINE_BITFIELD_ENUM(LocationType,            29,   31),
75143
76   /* watch (unused ?) */
77//  DEFINE_BITFIELD_ENUM(Watch_AddValue,            0,  15),
78//  DEFINE_BITFIELD_ENUM(Watch_Label,               16, 17),
79//  DEFINE_BITFIELD_ENUM(Watch_DisplayType,         18, 19),
144   /* location parameter extention (relative address, memory accessor) */
145   DEFINE_BITFIELD_ENUM(LocationParameterOption,   24,   25),
146   DEFINE_BITFIELD_ENUM(LocationParameterCPU,      26,   28),
80147
81148   /* command */
82   DEFINE_BITFIELD_ENUM(AutoSaveEnabled,         0,   0),
83   DEFINE_BITFIELD_ENUM(SearchBox,               1,   2),      // 0 = Minimum, 1 = Classic, 2 = Advanced
84   DEFINE_BITFIELD_ENUM(DontPrintNewLabels,      3,   3),      // in options menu, it is reverted.
149   DEFINE_BITFIELD_ENUM(SearchBox,               0,   1),
150   DEFINE_BITFIELD_ENUM(DontPrintNewLabels,      2,   2),      // in options menu, it is reversed display
151   DEFINE_BITFIELD_ENUM(AutoSaveEnabled,         3,   3),
85152   DEFINE_BITFIELD_ENUM(ActivationKeyMessage,      4,   4),
86153   DEFINE_BITFIELD_ENUM(LoadOldFormat,            5,   5),
87   DEFINE_BITFIELD_ENUM(Debug,                  6,   6)
154#ifdef MESS
155   DEFINE_BITFIELD_ENUM(SharedCode,            6,   6)
156#endif
88157};
89158
90159/********** OPERATION **********/
91160
161enum{      // address space for RAM region
162   kAddressSpace_Program = 0,
163   kAddressSpace_DataSpace,
164   kAddressSpace_IOSpace,
165   kAddressSpace_OpcodeRAM,
166   kAddressSpace_MappedMemory,
167   kAddressSpace_DirectMemory,
168   kAddressSpace_EEPROM };
169
170enum{      // code types
171   kCodeType_Write = 0,      // EF = Mask
172   kCodeType_IWrite,         // EF = Index
173   kCodeType_RWrite,         // EF = Count/Skip
174   kCodeType_CWrite,         // EF = Condition
175   kCodeType_VWrite,         // EF = Index
176   kCodeType_VRWrite,         // EF = Count/Skip
177   kCodeType_PDWWrite,         // EF = 2nd Data
178   kCodeType_Move,            // EF = Index
179   kCodeType_Branch,         // EF = Jump Code
180   kCodeType_Loop,            // EF = Index
181   kCodeType_Unused1,
182   kCodeType_Unused2,
183   kCodeType_Unused3,
184   kCodeType_Unused4,
185   kCodeType_Popup,         // EF = Index
186   kCodeType_Watch };         // EF = X and Y Position
187
188enum{      // parameter for IWrite
189   kIWrite_Write = 0,
190   kIWrite_BitSet,
191   kIWrite_BitClear,
192   kIWrite_LimitedMask };
193
194enum{      // conditions for CWrite, Branch, Popup
195   kCondition_Equal = 0,
196   kCondition_NotEqual,
197   kCondition_Less,
198   kCondition_LessOrEqual,
199   kCondition_Greater,
200   kCondition_GreaterOrEqual,
201   kCondition_BitSet,
202   kCondition_BitClear,
203   kCondition_Unused1,
204   kCondition_Unused2,
205   kCondition_Unused3,
206   kCondition_Unused4,
207   kCondition_PreviousValue,
208   kCondition_KeyPressedOnce,
209   kCondition_KeyPressedRepeat,
210   kCondition_True };
211
212enum{      // popup parameter
213   kPopup_Label = 0,
214   kPopup_Value,
215   kPopup_LabelValue,
216   kPopup_ValueLabel };
217
218enum{      // parameter for custom
219   kCustomCode_NoAction = 0,
220   kCustomCode_Comment,
221   kCustomCode_Separator,
222   kCustomCode_LabelSelect,
223   kCustomCode_Layer,
224   kCustomCode_Unused1,
225   kCustomCode_Unused2,
226   kCustomCode_Unused3,
227   kCustomCode_ActivationKey1,
228   kCustomCode_ActivationKey2,
229   kCustomCode_PreEnable,
230   kCustomCode_OverClock,
231   kCustomCode_RefreshRate };
232
233enum{      // link level
234   kLink_Master = 0,
235   kLink_Link,
236   kLink_SubLink,
237   kLink_CopyLink };
238
239enum{      // address read from
240   kReadFrom_Address = 0,         // $xxxx
241   kReadFrom_Index,            // $Vx
242   kReadFrom_Variable };         // Vx
243
92244enum      // types
93245{
94246   kType_NormalOrDelay = 0,
r2762r2763
103255   kOperation_AddSubtract,
104256   kOperation_ForceRange,
105257   kOperation_SetOrClearBits,
106   kOperation_WriteMatch,
107   // kOperation_Unused5,
108   // kOperation_Unused6,
109   kOperation_None = 7
258   kOperation_Unused4,
259   kOperation_Unused5,
260   kOperation_Unused6,
261   kOperation_None
110262};
111263
112264//enum      // prefills (unused?)
r2762r2763
124276   kLocation_HandlerMemory,
125277   kLocation_Custom,
126278   kLocation_IndirectIndexed,
127   kLocation_ProgramSpace
279   kLocation_Unused5,
280   kLocation_Unused6,
281   kLocation_Unused7
128282};
129283
130284enum      // location parameters
r2762r2763
138292   kCustomLocation_RefreshRate
139293};
140294
141enum      // flags for action
295enum      // memory accessor parameters
142296{
143   /* set for wait for modification or ignore if decrementing cheats when
144       the targeted value has changed
145       cleared after the operation is performed */
146   kActionFlag_WasModified =      1 << 0,
297   kMemoryLocation_DirectAccess = 0,
298   kMemoryLocation_DataSpace,
299   kMemoryLocation_IOSpace,
300   kMemoryLocation_OpbaseRAM
301};
147302
303enum      // action flags
304{
305   /* set if this code is not the newest format */
306   kActionFlag_OldFormat =         1 << 0,
307
308   /* set if this code doesn't need to read/write a value */
309   kActionFlag_NoAction =         1 << 1,
310
311   /* set if this code is custom cheat */
312   kActionFlag_Custom =         1 << 2,
313
148314   /* set for one shot cheats after the operation is performed */
149   kActionFlag_OperationDone =      1 << 1,
315   kActionFlag_OperationDone =      1 << 3,
150316
151   /* set if the extendData field is being used by something other than a mask value */
152   kActionFlag_IgnoreMask =      1 << 2,
317   /* set if the extendData field is being used by index adress reading (IWrite, VWrite, Move, Loop, Popup)*/
318   kActionFlag_IndexAddress =      1 << 4,
153319
320   /* set if the code needs to check the condition (CWrite, Branch, Popup) */
321   kActionFlag_CheckCondition =   1 << 5,
322
323   /* set if the code needs to repeat writing (RWrite, VRWrite) */
324   kActionFlag_Repeat =         1 << 6,
325
326   /* set if the extendData field is being used by 2nd data (PDWWrite) */
327   kActionFlag_PDWWrite =         1 << 7,
328
154329   /* set if the lastValue field contains valid data and can be restored if needed */
155   kActionFlag_LastValueGood =      1 << 3,
330   kActionFlag_LastValueGood =      1 << 8,
156331
157332   /* set after value changes from prefill value */
158   kActionFlag_PrefillDone =      1 << 4,
333   kActionFlag_PrefillDone =      1 << 9,
159334
160335   /* set after prefill value written */
161   kActionFlag_PrefillWritten =   1 << 5,
336   kActionFlag_PrefillWritten =   1 << 10,
162337
338   /* set if the code is a label for label-selection code */
339   kActionFlag_IsLabel =         1 << 11,
340
341   /* set when read/write a data after 1st read/write and clear after 2nd read/write (PDWWrite) */
342   kActionFlag_IsFirst =         1 << 12,
343
163344   /* masks */
164   kActionFlag_StateMask =         kActionFlag_OperationDone |
345   kActionFlag_StateMask =         kActionFlag_OperationDone |      // used in ResetAction() to clear specified flags
165346                           kActionFlag_LastValueGood |
166347                           kActionFlag_PrefillDone |
167348                           kActionFlag_PrefillWritten,
168   kActionFlag_InfoMask =         kActionFlag_WasModified |
169                           kActionFlag_IgnoreMask,
170   kActionFlag_PersistentMask =   kActionFlag_LastValueGood
349   kActionFlag_InfoMask =         kActionFlag_IndexAddress,      // ??? unused ???
350   kActionFlag_PersistentMask =   kActionFlag_OldFormat |         // used in UpdateCheatInfo() to clear other flags
351                           kActionFlag_LastValueGood
171352};
172353
173enum      // flags for entry
354enum      // entry flags
174355{
175356   /* true when the cheat is active */
176357   kCheatFlag_Active =               1 << 0,
r2762r2763
178359   /* true if the cheat is entirely one shot */
179360   kCheatFlag_OneShot =            1 << 1,
180361
181   /* true if the cheat will work with one shot in special case */
182   kCheatFlag_DoOneShot =            1 << 2,
183
184362   /* true if the cheat is entirely null (ex. a comment) */
185   kCheatFlag_Null =               1 << 3,
363   kCheatFlag_Null =               1 << 2,
186364
365   /* true if the cheat is multi-comment code */
366   kCheatFlag_ExtendComment =         1 << 3,
367
368   /* true if the cheat is specified separator */
369   kCheatFlag_Separator =            1 << 4,
370
187371   /* true if the cheat contains a user-select element */
188   kCheatFlag_UserSelect =            1 << 4,
372   kCheatFlag_UserSelect =            1 << 5,
189373
190374   /* true if the cheat is a select cheat */
191   kCheatFlag_Select =               1 << 5,
375   kCheatFlag_Select =               1 << 6,
192376
377   /* true if the cheat is layer index cheat */
378   kCheatFlag_LayerIndex =            1 << 7,
379
380   /* true if selected code is layer index cheat */
381   kCheatFlag_LayerSelected =         1 << 8,
382
193383   /* true if the cheat has been assigned an 1st activation key */
194   kCheatFlag_HasActivationKey1 =      1 << 6,
384   kCheatFlag_HasActivationKey1 =      1 << 9,
195385
196386   /* true if the cheat has been assigned an 2nd activation key */
197   kCheatFlag_HasActivationKey2 =      1 << 7,
387   kCheatFlag_HasActivationKey2 =      1 << 10,
198388
199   /* true if the activation key is being pressed */
200   kCheatFlag_ActivationKeyPressed =   1 << 8,
389   /* true if the cheat is not the newest format */
390   kCheatFlag_OldFormat =            1 << 11,
201391
202   /* true if the cheat has been edited or is a new cheat */
203   kCheatFlag_Dirty =               1 << 9,
392   /* true if wrong cheat code */
393   kCheatFlag_HasWrongCode =         1 << 12,
204394
395   /* true if the cheat has been edited or is a new cheat
396       checked at auto-save then save the code if true */
397   kCheatFlag_Dirty =               1 << 13,
398
205399   /* masks */
206   kCheatFlag_StateMask =         kCheatFlag_Active |
207                           kCheatFlag_DoOneShot,
208   kCheatFlag_InfoMask =         kCheatFlag_OneShot |
209                           kCheatFlag_DoOneShot |
400   kCheatFlag_StateMask =         kCheatFlag_Active,               // used in ResetAction() and DeactivateCheat() to clear specified flag
401   kCheatFlag_InfoMask =         kCheatFlag_OneShot |            // used in UpdateCheatInfo() to detect specified flags
210402                           kCheatFlag_Null |
403                           kCheatFlag_ExtendComment |
404                           kCheatFlag_Separator |
211405                           kCheatFlag_UserSelect |
212406                           kCheatFlag_Select |
407                           kCheatFlag_LayerIndex |
408                           kCheatFlag_OldFormat,
409   kCheatFlag_PersistentMask =      kCheatFlag_Active |               // used in UpdateCheatInfo() to extract specified flags
213410                           kCheatFlag_HasActivationKey1 |
214411                           kCheatFlag_HasActivationKey2 |
215                           kCheatFlag_ActivationKeyPressed,
216   kCheatFlag_PersistentMask =      kCheatFlag_Active |
217                           kCheatFlag_DoOneShot |
218                           kCheatFlag_HasActivationKey1 |
219                           kCheatFlag_HasActivationKey2 |
220                           kCheatFlag_ActivationKeyPressed |
221412                           kCheatFlag_Dirty
222413};
223414
r2762r2763
261452
262453enum      // default search regions
263454{
264   kSearchSpeed_Fast = 0,      // RAM + some banks
265   kSearchSpeed_Medium,      // RAM + BANKx
266   kSearchSpeed_Slow,         // all memory areas except ROM, NOP, and custom handlers
267   kSearchSpeed_VerySlow,      // all memory areas except ROM and NOP
268   kSearchSpeed_AllMemory,      // entire CPU address space
455   ksearch_speed_Fast = 0,      // RAM + some banks
456   ksearch_speed_Medium,      // RAM + BANKx
457   ksearch_speed_Slow,         // all memory areas except ROM, NOP, and custom handlers
458   ksearch_speed_VerySlow,      // all memory areas except ROM and NOP
459   ksearch_speed_AllMemory,      // entire CPU address space
460   ksearch_speed_UserDefined,   // user defined region
269461
270   kSearchSpeed_Max = kSearchSpeed_AllMemory
462   ksearch_speed_Max
271463};
272464
273465/********** SEARCH **********/
r2762r2763
282474   kSearchOperand_Max = kSearchOperand_Value
283475};
284476
285enum      // bits
477enum      // length
286478{
287479   kSearchSize_8Bit = 0,
288480   kSearchSize_16Bit,
r2762r2763
316508   kHorizontalSlowKeyRepeatRate =   8
317509};
318510
319enum
511enum      // search menu
320512{
321513   kSearchBox_Minimum = 0,
322   kSearchBox_Classic,
514   kSearchBox_Standard,
323515   kSearchBox_Advanced
324516};
325517
518enum      // load flags
519{
520   kLoadFlag_CheatOption   = 1,
521   kLoadFlag_CheatCode      = 1 << 1,
522   kLoadFlag_UserRegion   = 1 << 2
523};
524
525enum      // message types
526{
527   kCheatMessage_None = 0,
528   kCheatMessage_ReloadCheatOption,
529   kCheatMessage_ReloadCheatCode,
530   kCheatMessage_ReloadUserRegion,
531   kCheatMessage_FailedToLoadDatabase,
532   kCheatMessage_CheatFound,
533   kCheatMessage_1CheatFound,
534   kCheatMessage_SucceededToSave,
535   kCheatMessage_FailedToSave,
536   kCheatMessage_AllCheatSaved,
537   kCheatMessage_ActivationKeySaved,
538   kCheatMessage_NoActivationKey,
539   kCheatMessage_PreEnableSaved,
540   kCheatMessage_SucceededToAdd,
541   kCheatMessage_FailedToAdd,
542   kCheatMessage_SucceededToDelete,
543   kCheatMessage_FailedToDelete,
544   kCheatMessage_NoSearchRegion,
545   kCheatMessage_RestoreValue,
546   kCheatMessage_NoOldValue,
547   kCheatMessage_InitializeMemory,
548   kCheatMessage_InvalidatedRegion,
549   kCheatMessage_DebugOnly,
550   kCheatMessage_WrongCode,
551
552   kCheatMessage_Max
553};
554
555enum{      // error flags
556   kErrorFlag_InvalidLocationType      = 1,      // old
557   kErrorFlag_InvalidOperation         = 1 << 1,   // old
558   kErrorFlag_InvalidCodeType         = 1 << 2,   // new
559   kErrorFlag_InvalidCondition         = 1 << 3,   // new
560   kErrorFlag_InvalidCodeOption      = 1 << 4,   // new
561   kErrorFlag_ConflictedExtendField   = 1 << 5,   // old
562   kErrorFlag_InvalidRange            = 1 << 6,
563   kErrorFlag_NoRestorePreviousValue   = 1 << 7,
564   kErrorFlag_NoLabel               = 1 << 8,
565   kErrorFlag_ConflictedSelects      = 1 << 9,
566   kErrorFlag_CopyLinkWithoutSelect   = 1 << 10,   // new
567   kErrorFlag_InvalidDataField         = 1 << 11,
568   kErrorFlag_InvalidExtendDataField   = 1 << 12,
569   kErrorFlag_ForbittenVariable      = 1 << 13,   // new
570   kErrorFlag_NoSelectableValue      = 1 << 14,
571   kErrorFlag_NoRepeatCount         = 1 << 15,   // new
572   kErrorFlag_UndefinedAddressRead      = 1 << 16,   // new
573   kErrorFlag_AddressVariableOutRange   = 1 << 17,   // new
574   kErrorFlag_DataVariableOutRange      = 1 << 18,   // new
575   kErrorFlag_OutOfCPURegion         = 1 << 19,
576   kErrorFlag_InvalidCPURegion         = 1 << 20,
577   kErrorFlag_InvalidAddressSpace      = 1 << 21,   // new
578   kErrorFlag_RegionOutOfRange         = 1 << 22,
579   kErrorFlag_InvalidCustomCode      = 1 << 23,   // new
580
581   kErrorFlag_Max                  = 24 };
582
326583/***************************************************************************
327584    TYPE DEFINITIONS
328585***************************************************************************/
r2762r2763
331588
332589struct CheatAction
333590{
334   UINT32   type;
335   UINT32   address;
336   UINT32   data;
337   UINT32   extendData;
338   UINT32   originalDataField;
591   UINT32   type;               // packed several information (cpu/region, address size, operation and parameters and so on)
592   UINT8   region;               // the number of cpu or region. in case of cpu, it has a kind of an address space together
593   UINT32   address;            // address. it is changeable by RWrite in the cheat core
594   UINT32   originalAddress;      // address. it is for edit/view/save
595   UINT32   data;               // data. it is changeable by VWrite/VRWrite in the cheat core
596   UINT32   originalDataField;      // data. it is for edit/view/save
597   UINT32   extendData;            // extend parameter. it is different using by each operations
339598
340   INT32   frameTimer;
341   UINT32   lastValue;
599   INT32   frameTimer;            // timer for delay, keep
600   UINT32   * lastValue;         // back up value before cheating to restore value. PDWWrite uses 2 and RWrite uses about a counter
342601
343   UINT32   flags;
602   UINT32   flags;               // internal flags
344603
345   UINT8   ** cachedPointer;
346   UINT32   cachedOffset;
604   UINT8   ** cachedPointer;      // pointer for data, I/O space or non-cpu region
605   UINT32   cachedOffset;         // offset for mapped memory
347606
348   char   * optionalName;
607   char   * optionalName;         // name to display in edit/view menu. Action doesn't have a comment
349608};
350609
351610typedef struct CheatAction   CheatAction;
r2762r2763
354613
355614struct CheatEntry
356615{
357   char         * name;
358   char         * comment;
616   char         * name;               // name to display in list menu
617   char         * comment;            // comment
359618
360   INT32         actionListLength;
619   INT32         actionListLength;      // minimum length = 1
361620   CheatAction      * actionList;
362621
363   int            activationKey1;
364   int            activationKey2;
622   int            activationKey1;         // activation key index for 1st key
623   int            activationKey2;         // activation key index for 2nd key
365624
366   UINT32         flags;
367   int            selection;
625   int            selection;            // for label-select to set selected label number
626   int            labelIndexLength;      // minimum length = 1
627   int            * labelIndex;         // label index table
628   int            layerIndex;            // layer index for enable/disable menu
629
630   UINT32         flags;               // internal flags
368631};
369632
370633typedef struct CheatEntry   CheatEntry;
r2762r2763
386649   INT8         dataShift;
387650   UINT32         xor;
388651
389   UINT8         locationType;
390
391652   float         x, y;
392653
393654   CheatEntry *   linkedCheat;
r2762r2763
399660
400661/********** REGION **********/
401662
402struct SearchRegion
663typedef struct _search_region search_region;
664struct _search_region
403665{
404666   UINT32   address;
405667   UINT32   length;
406668
407   UINT8   targetType;
408   UINT8   targetIdx;
669   UINT8   target_type;
670   UINT8   target_idx;
409671
410672   UINT8   flags;
411673
412   UINT8   * cachedPointer;
674   UINT8   ** cached_pointer;
413675   const address_map_entry
414         * writeHandler;
676         * write_handler;
415677
416678   UINT8   * first;
417679   UINT8   * last;
418680
419681   UINT8   * status;
420682
421   UINT8   * backupLast;
422   UINT8   * backupStatus;
683   UINT8   * backup_last;
684   UINT8   * backup_status;
423685
424   char   name[32];      // 12345678 - 12345678 BANK31
686   char   name[64];
425687
426   UINT32   numResults;
427   UINT32   oldNumResults;
688   UINT32   num_results;
689   UINT32   old_num_results;
428690};
429691
430typedef struct SearchRegion   SearchRegion;
431
432692/********** SEARCH **********/
433693
434struct OldSearchOptions
694typedef struct _old_search_options old_search_options;
695struct _old_search_options
435696{
436   UINT8   status;
437   UINT8   energy;
438   UINT8   operand;
697   INT8   comparison;
439698   UINT32   value;
699   INT8   sign;
440700   UINT32   delta;
441701};
442702
443typedef struct OldSearchOptions   OldSearchOptions;
444
445struct SearchInfo
703typedef struct _search_info search_info;
704struct _search_info
446705{
447   INT32            regionListLength;
448   SearchRegion      * regionList;
706   INT32            region_list_length;
707   search_region      *region_list;
449708
450   char            * name;
709   char            *name;         /* search info name used in select_region() */
451710
452   INT8            bytes;         // 0 = 1, 1 = 2, 2 = 3, 3 = 4, 4 = bit
711   INT8            bytes;         /* 0 = 1, 1 = 2, 2 = 3, 3 = 4, 4 = bit */
453712   UINT8            swap;
454713   UINT8            sign;
455714   INT8            lhs;
456715   INT8            rhs;
457716   INT8            comparison;
458717
459   UINT8            targetType;      // cpu/region
460   UINT8            targetIdx;      // cpu or region index
718   UINT8            target_type;      /* is cpu or region? */
719   UINT8            target_idx;         /* index for cpu or region */
461720
462721   UINT32            value;
463722
464   UINT8            searchSpeed;
723   INT8            search_speed;
465724
466   UINT32            numResults;
467   UINT32            oldNumResults;
725   UINT32            num_results;
726   UINT32            old_num_results;
468727
469   INT32            currentRegionIdx;
470   INT32            currentResultsPage;
728   INT32            current_region_idx;
729   INT32            current_results_page;
471730
472   UINT8            backupValid;
731   UINT8            backup_valid;
473732
474   OldSearchOptions   oldOptions;
733   old_search_options   old_options;
475734};
476735
477typedef struct SearchInfo   SearchInfo;
478
479736/********** CPU **********/
480737
481struct CPUInfo
738typedef struct _cpu_region_info cpu_region_info;
739struct _cpu_region_info
482740{
483   UINT8   type;
484   UINT8   dataBits;
485   UINT8   addressBits;
486   UINT8   addressCharsNeeded;
487   UINT32   addressMask;
488   UINT8   endianness;
489   UINT8   addressShift;
741   UINT8   type;               /* cpu or region type */
742   UINT8   data_bits;            /* data bits */
743   UINT8   address_bits;         /* address bits */
744   UINT8   address_chars_needed;   /* length of address */
745   UINT32   address_mask;         /* address mask */
746   UINT8   endianness;            /* endianness */
747   UINT8   address_shift;         /* address shift */
490748};
491749
492typedef struct CPUInfo   CPUInfo;
750/********** STRINGS **********/
493751
494/********** MENU **********/
495
496struct MenuStringList
752typedef struct _menu_string_list menu_string_list;
753struct _menu_string_list
497754{
498   const char   ** mainList;   // editable menu item lists
499   const char   ** subList;
500   char      * flagList;
755   const char   **main_list;   /* main item field in menu items */
756   const char   **sub_list;      /* sub item field in menu items */
757   char      *flag_list;      /* flag of highlight for sub menu field */
501758
502   char   ** mainStrings;      // lists of useable strings
503   char   ** subStrings;
759   char   **main_strings;      /* strings buffer 1 */
760   char   **sub_strings;      /* strings buffer 2 */
504761
505   char   * buf;            // string storage
762   char   *buf;            /* internal buffer? (only used in rebuild_string_tables()) */
506763
507   UINT32   length;            // number of menu items supported
508   UINT32   numStrings;         // number of strings supported
509   UINT32   mainStringLength;   // max length of main string
510   UINT32   subStringLength;   // max length of sub string
764   UINT32   length;            /* number of total menu items */
765   UINT32   num_strings;      /* number of strings buffer */
766   UINT32   main_string_length;   /* length of string in strings buffer 1 */
767   UINT32   sub_string_length;   /* length of string in strings buffer 2 */
511768};
512769
513typedef struct MenuStringList   MenuStringList;
770/********** MENUS **********/
514771
515struct MenuItemInfoStruct
772/* NOTE : _cheat_menu_item_info is used in the edit menu right now */
773typedef struct _cheat_menu_item_info cheat_menu_item_info;
774struct _cheat_menu_item_info
516775{
517   UINT32   subcheat;
518   UINT32   fieldType;
519   UINT32   extraData;
776   UINT32   sub_cheat;      /* the number of an item */
777   UINT32   field_type;      /* field type of an item */
778   UINT32   extra_data;      /* it stores an extra data but NOT read (so I don't know how to use)*/
520779};
521780
522typedef struct MenuItemInfoStruct   MenuItemInfoStruct;
781typedef struct _cheat_menu_stack cheat_menu_stack;
782typedef int (*cheat_menu_handler)(running_machine *machine, cheat_menu_stack *menu);
783struct _cheat_menu_stack
784{
785   cheat_menu_handler   handler;      /* menu handler for cheat */
786   cheat_menu_handler   return_handler;   /* menu handler to return menu */
787   int               sel;         /* current cursor position */
788   int               pre_sel;      /* selected item in previous menu */
789   UINT8            first_time;      /* flags to first setting (1 = first, 0 = not first) */
790};
523791
792/********** FORMAT **********/
793typedef const struct _cheat_format cheat_format;
794struct _cheat_format
795{
796   const char *   format_string;         /* string templete of a format */
797   UINT8         arguments_matched;      /* valid arguments of a format */
798   UINT8         length_matched;         /* valid length of a parameter */
799   UINT8         comment_matched;      /* valid argument to add comment */
800};
801
802static const struct _cheat_format cheat_format_table[] =
803{
804      /* option - :_command:TYPE */
805   {   ":_command:%[^:\n\r]",                                    1,   8,   0   },
806#ifdef MESS
807      /* code (new) - >MACHINE_NAME:CRC:TYPE:ADDRESS:DATA:EXTEND_DATA:(DESCRIPTION:COMMENT) */
808   {   ">%8[^:\n\r]:%8X:%8X:%X:%8[^:\n\r]:%8[^:\n\r]:%[^:\n\r]:%[^:\n\r]",   6,   8,   8   },
809      /* code (old) - :MACHINE_NAME:CRC:TYPE:ADDRESS:DATA:EXTEND_DATA:(DESCRIPTION:COMMENT) */
810   {   ":%8s:%8X:%8X:%X:%8[^:\n\r]:%8[^:\n\r]:%[^:\n\r]:%[^:\n\r]",      6,   8,   0   },
811      /* code (older) - :MACHINE_NAME:CRC:CPU:ADDRESS:DATA:TYPE:(DESCRIPTION:COMMENT) */
812   {   "%8[^:\n\r]:%8X:%d:%X:%X:%d:%[^:\n\r]:%[^:\n\r]",               5,   0,   8   },
813      /* user region - :MACHINE_NAME:CRC:CPU:ADDRESS_SPACE:START_ADDRESS:END_ADDRESS:STATUS:(DESCRIPTION) */
814   {   ">%8[^:\n\r]:%8X:%2X:%2X:%X:%X:%1X:%[^:\n\r]",                  7,   0,   0   },
815#else
816      /* code (new) - >GAME_NAME:TYPE:ADDRESS:DATA:EXTEND_DATA:(DESCRIPTION:COMMENT) */
817   {   ">%8[^:\n\r]:%8X:%X:%8[^:\n\r]:%8[^:\n\r]:%[^:\n\r]:%[^:\n\r]",      5,   8,   7   },
818      /* code (old) - :GAME_NAME:TYPE:ADDRESS:DATA:EXTEND_DATA:(DESCRIPTION:COMMENT) */
819   {   ":%8s:%8X:%X:%8[^:\n\r]:%8[^:\n\r]:%[^:\n\r]:%[^:\n\r]",         5,   8,   0   },
820      /* code (older) - :GAME_NAME:CPU:ADDRESS:DATA:TYPE:(DESCRIPTION:COMMENT) */
821   {   "%8[^:\n\r]:%d:%X:%X:%d:%[^:\n\r]:%[^:\n\r]",                  4,   0,   7   },
822      /* user region - :GAME_NAME:CPU:ADDRESS_SPACE:START_ADDRESS:END_ADDRESS:STATUS:(DESCRIPTION) */
823   {   ">%8[^:\n\r]:%2X:%2X:%X:%X:%1X:%[^:\n\r]",                     6,   0,   0   },
824#endif   /* MESS */
825   /* end of table */
826   {   0   }
827};
828
524829/***************************************************************************
525830    EXPORTED VARIABLES
526831***************************************************************************/
r2762r2763
534839static emu_timer         * periodic_timer;
535840
536841static CheatEntry         * cheatList = NULL;
537static INT32            cheatListLength = 0;
842static INT32            cheatListLength = 0;      // NOTE : 0 means no cheat entry and error
538843
539844static WatchInfo         * watchList = NULL;
540845static INT32            watchListLength = 0;
541846
542static SearchInfo         * searchList = NULL;
543static INT32            searchListLength = 0;
544static INT32            currentSearchIdx = 0;
847static search_info         *search_list = NULL;
848static INT32            search_list_length = 0;
849static INT32            current_search_idx = 0;
545850
546static CPUInfo            cpuInfoList[MAX_CPU];
547static CPUInfo            regionInfoList[kRegionListLength];
851static cpu_region_info      cpu_info_list[MAX_CPU];
852static cpu_region_info      region_info_list[REGION_LIST_LENGTH];
548853
549//static int                    cheatEngineWasActive = 0;
550854static int               foundCheatDatabase = 0;
551855static int               cheatsDisabled = 0;
552856static int               watchesDisabled = 0;
553857
554static int               fullMenuPageHeight = 0;
858static int               fullMenuPageHeight;
859static int               visible_items;
555860
556861static char               mainDatabaseName[CHEAT_FILENAME_MAX_LEN + 1];
557862
558static MenuStringList      menuStrings;
863static menu_string_list      menu_strings;
559864
560static MenuItemInfoStruct   * menuItemInfo;
865static cheat_menu_item_info   * menu_item_info;
561866static INT32            menuItemInfoLength = 0;
562867
563static UINT32            cheatOptions = 2;
868static UINT8            editActive;
869static INT8               editCursor;
564870
565static const char *const kCheatNameTemplates[] =
566{
567    "Infinite Credits",
568   "Infinite Time",
569   "Infinite Lives",
570   "Infinite Energy",
571   "Invincibility",
572   "Infinite Time PL1",
573   "Infinite Lives PL1",
574   "Infinite Energy PL1",
575   "Drain all Energy Now! PL1",
576   "Invincibility PL1",
577   "Infinite Time PL2",
578   "Infinite Lives PL2",
579   "Infinite Energy PL2",
580   "Drain all Energy Now! PL2",
581   "Invincibility PL2",
582   "Infinite Ammo",
583   "Infinite Bombs",
584   "Select starting level",
585   "Rapid Fire",
586   "Infinite Ammo PL1",
587   "Infinite Bombs PL1",
588   "Select Score PL1",
589   "Rapid Fire PL1",
590   "Infinite Ammo PL2",
591   "Infinite Bombs PL2",
592   "Select Score PL2",
593   "Rapid Fire PL2",
594   "Display the Correct Answer",
595   "Infinite ",
596   "Always have ",
597   "Get ",
598   "Lose ",
599   "Finish this ",
600   "---> <ENTER> To Edit <---",
601   "\0"
602};
871static INT8               stack_index;
872static cheat_menu_stack      menu_stack[CHEAT_MENU_DEPTH];
603873
604static CPUInfo rawCPUInfo =
874static int               cheatVariable[VARIABLE_MAX_ARRAY] = { 0 };
875
876static UINT32            cheatOptions;
877static UINT32            driverSpecifiedFlag;
878static UINT8            messageType;
879static UINT8            messageTimer;
880
881static cpu_region_info raw_cpu_info =
605882{
606   0,         // type
607   8,         // dataBits
608   8,         // addressBits
609   1,         // addressCharsNeeded
610   CPU_IS_BE   // endianness
883   0,         /* type */
884   8,         /* data_bits */
885   8,         /* address_bits */
886   1,         /* address_chars_needed */
887   CPU_IS_BE,   /* endianness */
888   0,         /* address_shift */
611889};
612890
613891static const int kSearchByteIncrementTable[] =
r2762r2763
7231001   0x01
7241002};
7251003
1004static const UINT32 kIncrementValueTable[] =
1005{
1006   0x00000001,
1007   0x00000010,
1008   0x00000100,
1009   0x00001000,
1010   0x00010000,
1011   0x00100000,
1012   0x01000000,
1013   0x10000000
1014};
1015
1016static const UINT32 kIncrementMaskTable[] =
1017{
1018   0x0000000F,
1019   0x000000F0,
1020   0x00000F00,
1021   0x0000F000,
1022   0x000F0000,
1023   0x00F00000,
1024   0x0F000000,
1025   0xF0000000
1026};
1027
1028static const UINT32 kIncrementDecTable[] =
1029{
1030   0x00000009,
1031   0x00000090,
1032   0x00000900,
1033   0x00009000,
1034   0x00090000,
1035   0x00900000,
1036   0x09000000,
1037   0x90000000
1038};
1039
1040static const char *const kRegionNames[] = {
1041   "INVALID",
1042   "CPU1",      "CPU2",      "CPU3",      "CPU4",      "CPU5",      "CPU6",      "CPU7",      "CPU8",      // 01-08    [01-08] : CPU
1043   "GFX1",      "GFX2",      "GFX3",      "GFX4",      "GFX5",      "GFX6",      "GFX7",      "GFX8",      // 09-16    [08-10] : GFX
1044   "PROMS",                                                                  // 17       [11]    : PROMS
1045   "SOUND1",   "SOUND2",   "SOUND3",   "SOUND4",   "SOUND5",   "SOUND6",   "SOUND7",   "SOUND8",   // 18-25    [12-19] : SOUND
1046   "USER1",   "USER2",   "USER3",   "USER4",   "USER5",   "USER6",   "USER7",   "USER8",   // 26-45    [1A-2D] : USER
1047   /* USER9 - PLDS are undefined in old format */
1048   "USER9",   "USER10",   "USER11",   "USER12",   "USER13",   "USER14",   "USER15",   "USER16",
1049   "USER17",   "USER18",   "USER19",   "USER20",
1050   "DISKS",                                                                  // 46       [2E]    : DISKS
1051   "PLDS" };                                                                  // 47       [2F]    : PLDS
1052
1053static const char *const kNumbersTable[] = {
1054   "0",   "1",   "2",   "3",   "4",   "5",   "6",   "7",
1055   "8",   "9",   "10",   "11",   "12",   "13",   "14",   "15",
1056   "16",   "17",   "18",   "19",   "20",   "21",   "22",   "23",
1057   "24",   "25",   "26",   "27",   "28",   "29",   "30",   "31" };
1058
1059static const char *const kByteSizeStringList[] =
1060{
1061   "8 Bit",
1062   "16 Bit",
1063   "24 Bit",
1064   "32 Bit"
1065};
1066
7261067static const char *const kWatchLabelStringList[] =
7271068{
7281069   "None",
r2762r2763
7421083    FUNCTION PROTOTYPES
7431084***************************************************************************/
7441085
745/********** MAIN **********/
7461086static TIMER_CALLBACK( cheat_periodic );
7471087static void    cheat_exit(running_machine *machine);
7481088
r2762r2763
7511091static int      ControlKeyPressed(void);
7521092static int      AltKeyPressed(void);
7531093
754static int      UIPressedRepeatThrottle(running_machine *machine, int code, int baseSpeed);
1094static int      ui_pressed_repeat_throttle(running_machine *machine, int code, int base_speed);
7551095
756/********** DIRECT KEY INPUT **********/
757static int      ReadHexInput(void);
758
759static char *   DoDynamicEditTextField(char * buf);
1096/********** KEY INPUT **********/
1097static int      read_hex_input(void);
1098#if 0
1099static char      *DoDynamicEditTextField(char * buf);
1100#endif
7601101static void      DoStaticEditTextField(char * buf, int size);
761static UINT32   DoEditHexField(running_machine *machine, UINT32 data);
1102static UINT32   do_edit_hex_field(running_machine *machine, UINT32 data);
7621103static UINT32   DoEditHexFieldSigned(UINT32 data, UINT32 mask);
7631104static INT32   DoEditDecField(INT32 data, INT32 min, INT32 max);
1105static UINT32   DoIncrementHexField(UINT32 data, UINT8 digits);
1106static UINT32   DoDecrementHexField(UINT32 data, UINT8 digits);
1107static UINT32   DoIncrementHexFieldSigned(UINT32 data, UINT8 digits, UINT8 bytes);
1108static UINT32   DoDecrementHexFieldSigned(UINT32 data, UINT8 digits, UINT8 bytes);
1109static UINT32   DoIncrementDecField(UINT32 data, UINT8 digits);
1110static UINT32   DoDecrementDecField(UINT32 data, UINT8 digits);
7641111
765/********** VALUE SHIFT OR CONVERTION **********/
766static UINT32   DoShift(UINT32 input, INT8 shift);
767
1112/********** VALUE CONVERTER **********/
7681113static UINT32   BCDToDecimal(UINT32 value);
7691114static UINT32   DecimalToBCD(UINT32 value);
7701115
7711116/********** STRINGS **********/
772static void      RebuildStringTables(void);
773static void      RequestStrings(UINT32 length, UINT32 numStrings, UINT32 mainStringLength, UINT32 subStringLength);
774static void      InitStringTable(void);
775static void      FreeStringTable(void);
1117static void      rebuild_string_tables(void);
1118static void      request_strings(UINT32 length, UINT32 num_strings, UINT32 main_string_length, UINT32 sub_string_length);
1119static void      init_string_table(void);
1120static void      free_string_table(void);
7761121
777static char *   CreateStringCopy(char * buf);
1122static char      *create_string_copy(char *buf);
7781123
1124/********** MENU EXPORTER **********/
1125static void      old_style_menu(const char **items, const char **sub_items, char *flag, int selected, int arrowize_subitem);
1126
1127/********** MENU STACK **********/
1128static void      init_cheat_menu_stack(void);
1129static void      cheat_menu_stack_push(cheat_menu_handler new_handler, cheat_menu_handler ret_handler, int selection);
1130static void      cheat_menu_stack_pop(void);
1131static void      free_cheat_menu_stack(void);
1132
7791133/********** ADDITIONAL MENU FOR CHEAT **********/
780static INT32   UserSelectValueMenu(running_machine *machine, int selection, CheatEntry * entry);
1134static int      user_select_value_menu(running_machine *machine, cheat_menu_stack *menu);
1135static int      user_select_label_menu(running_machine *machine, cheat_menu_stack *menu);
1136static int      comment_menu(running_machine *machine, cheat_menu_stack *menu);
1137static int      extend_comment_menu(running_machine *machine, cheat_menu_stack *menu);
7811138
7821139/********** CHEAT MENU **********/
783static int      EnableDisableCheatMenu(running_machine *machine, int selection, int firstTime);
784static int      AddEditCheatMenu(running_machine *machine, int selection);
785static int      EditCheatMenu(running_machine *machine, CheatEntry * entry, int index, int selection);
1140static int      cheat_main_menu(running_machine *machine, cheat_menu_stack *menu);
1141static int      enable_disable_cheat_menu(running_machine *machine, cheat_menu_stack *menu);
1142static int      add_edit_cheat_menu(running_machine *machine, cheat_menu_stack *menu);
1143static int      command_add_edit_menu(running_machine *machine, cheat_menu_stack *menu);
1144static int      edit_cheat_menu(running_machine *machine, cheat_menu_stack *menu);
1145static int      view_cheat_menu(running_machine *machine, cheat_menu_stack *menu);
1146static int      analyse_cheat_menu(running_machine *machine, cheat_menu_stack *menu);
7861147
787static int      DoSearchMenuMinimum(running_machine *machine, int selection);   // minimum mode
788static int      DoSearchMenuClassic(running_machine *machine, int selection);   // classic mode
789static int      DoSearchMenu(running_machine *machine, int selection);         // advanced mode
790static int      SelectSearchRegions(running_machine *machine, int selection, SearchInfo * search);
791static int      ViewSearchResults(running_machine *machine, int selection, int firstTime);
1148static int      search_minimum_menu(running_machine *machine, cheat_menu_stack *menu);
1149static int      search_standard_menu(running_machine *machine, cheat_menu_stack *menu);
1150static int      search_advanced_menu(running_machine *machine, cheat_menu_stack *menu);
1151static int      select_search_region_menu(running_machine *machine, cheat_menu_stack *menu);
1152static int      view_search_result_menu(running_machine *machine, cheat_menu_stack *menu);
7921153
793static int      ChooseWatch(running_machine *machine, int selection);
794static int      EditWatch(running_machine *machine, WatchInfo * entry, int selection);
1154static int      choose_watch_menu(running_machine *machine, cheat_menu_stack *menu);
1155static int      command_watch_menu(running_machine *machine, cheat_menu_stack *menu);
1156static int      edit_watch_menu(running_machine *machine, cheat_menu_stack *menu);
7951157
796static int      SelectOptions(running_machine *machine, int selection);
797static int      SelectSearch(running_machine *machine, int selection);
1158static int      select_option_menu(running_machine *machine, cheat_menu_stack *menu);
1159static int      select_search_menu(running_machine *machine, cheat_menu_stack *menu);
7981160
1161#ifdef MAME_DEBUG
1162static int      check_activation_key_code_menu(running_machine *machine, cheat_menu_stack *menu);
1163static int      view_cpu_region_info_list_menu(running_machine *machine, cheat_menu_stack *menu);
1164static int      debug_cheat_menu(running_machine *machine, cheat_menu_stack *menu);
1165#endif
1166
7991167/********** ENTRY LIST **********/
8001168static void      ResizeCheatList(UINT32 newLength);
8011169static void      ResizeCheatListNoDispose(UINT32 newLength);
r2762r2763
8041172static void      DeleteCheatAt(UINT32 idx);
8051173
8061174static void      DisposeCheat(CheatEntry * entry);
807static CheatEntry *   GetNewCheat(void);
1175static CheatEntry
1176            *GetNewCheat(void);
8081177
8091178/********** ACTION LIST **********/
8101179static void      ResizeCheatActionList(CheatEntry * entry, UINT32 newLength);
1180#if 0
8111181static void      ResizeCheatActionListNoDispose(CheatEntry * entry, UINT32 newLength);
8121182
8131183static void      AddActionBefore(CheatEntry * entry, UINT32 idx);
8141184static void      DeleteActionAt(CheatEntry * entry, UINT32 idx);
1185#endif
8151186static void      DisposeAction(CheatAction * action);
8161187
8171188/********** WATCH LIST **********/
r2762r2763
8221193static void      AddWatchBefore(UINT32 idx);
8231194static void      DeleteWatchAt(UINT32 idx);
8241195static void      DisposeWatch(WatchInfo * watch);
825static WatchInfo *   GetUnusedWatch(void);
1196static WatchInfo
1197            *GetUnusedWatch(void);
8261198
8271199static void      AddCheatFromWatch(WatchInfo * watch);
8281200static void      SetupCheatFromWatchAsWatch(CheatEntry * entry, WatchInfo * watch);
8291201
1202static void      ResetWatch(WatchInfo * watch);
1203
8301204/********** SEARCH LIST **********/
831static void      ResizeSearchList(UINT32 newLength);
832static void      ResizeSearchListNoDispose(UINT32 newLength);
1205static void      resize_search_list(UINT32 newLength);
1206#if 0
1207static void      resize_search_list_no_dispose(UINT32 new_length);
1208static void      add_search_before(UINT32 idx);
1209static void      delete_search_at(UINT32 idx);
1210#endif
1211static void      init_search(search_info *info);
8331212
834static void      AddSearchBefore(UINT32 idx);
835static void      DeleteSearchAt(UINT32 idx);
1213static void      dispose_search_reigons(search_info *info);
1214static void      dispose_search(search_info *info);
1215static search_info
1216            *get_current_search(void);
8361217
837static void      InitSearch(SearchInfo * info);
1218static void      fill_buffer_from_region(search_region *region, UINT8 *buf);
1219static UINT32   read_region_data(search_region *region, UINT32 offset, UINT8 size, UINT8 swap);
8381220
839static void      DisposeSearchRegions(SearchInfo * info);
840static void      DisposeSearch(UINT32 idx);
841static SearchInfo *   GetCurrentSearch(void);
1221static void      backup_search(search_info *info);
1222static void      restore_search_backup(search_info *info);
1223static void      backup_region(search_region *region);
1224static void      restore_region_backup(search_region *region);
1225static UINT8   default_enable_region(running_machine *machine, search_region *region, search_info *info);
1226static void      set_search_region_default_name(search_region *region);
1227static void      allocate_search_regions(search_info *info);
1228static void      build_search_regions(running_machine *machine, search_info *info);
8421229
843static void      FillBufferFromRegion(SearchRegion * region, UINT8 * buf);
844static UINT32   ReadRegionData(SearchRegion * region, UINT32 offset, UINT8 size, UINT8 swap);
845
846static void      BackupSearch(SearchInfo * info);
847static void      RestoreSearchBackup(SearchInfo * info);
848static void      BackupRegion(SearchRegion * region);
849static void      RestoreRegionBackup(SearchRegion * region);
850static void      SetSearchRegionDefaultName(SearchRegion * region);
851static void      AllocateSearchRegions(SearchInfo * info);
852static void      BuildSearchRegions(running_machine *machine, SearchInfo * info);
853
854/********** CODE LOADER **********/
1230/********** LOADER **********/
8551231static int      ConvertOldCode(int code, int cpu, int * data, int * extendData);
856static void      HandleLocalCommandCheat(running_machine *machine, UINT32 type, UINT32 address, UINT32 data, UINT32 extendData, char * name, char * description);
1232static int      ConvertToNewCode(CheatAction * action);
1233static void      HandleLocalCommandCheat(running_machine *machine, int cpu, int type, int address, int data, UINT8 format);
8571234
858static void      LoadCheatFile(running_machine *machine, char * fileName);
859static void      LoadCheatDatabase(running_machine *machine);
1235static void      LoadCheatOption(char * fileName);
1236static void      LoadCheatCode(running_machine *machine, char * fileName);
1237static void      LoadUserDefinedSearchRegion(running_machine *machine, char * fileName);
1238static void      LoadCheatDatabase(running_machine *machine, UINT8 flags);
8601239
8611240static void      DisposeCheatDatabase(void);
8621241static void      ReloadCheatDatabase(running_machine *machine);
8631242
864static void      SaveCheat(running_machine *machine, CheatEntry * entry, int selection, int saveCode);
1243/********** SAVER **********/
1244static void      SaveCheatCode(running_machine *machine, CheatEntry * entry);
1245static void      SaveActivationKey(running_machine *machine, CheatEntry * entry, int entryIndex);
1246static void      SavePreEnable(running_machine *machine, CheatEntry * entry, int entryIndex);
1247static void      SaveCheatOptions(void);
1248static void      SaveDescription(running_machine *machine);
8651249static void      DoAutoSaveCheats(running_machine *machine);
8661250
8671251/********** CODE ADDITION **********/
868static void      AddCheatFromResult(SearchInfo * search, SearchRegion * region, UINT32 address);
869static void      AddCheatFromFirstResult(SearchInfo * search);
870static void      AddWatchFromResult(SearchInfo * search, SearchRegion * region, UINT32 address);
1252static void      AddCheatFromResult(search_info *search, search_region *region, UINT32 address);
1253static void      AddCheatFromFirstResult(search_info *search);
1254static void      AddWatchFromResult(search_info *search, search_region *region, UINT32 address);
8711255
8721256/********** SEARCH **********/
873static UINT32   SearchSignExtend(SearchInfo * search, UINT32 value);
874static UINT32   ReadSearchOperand(UINT8 type, SearchInfo * search, SearchRegion * region, UINT32 address);
875static UINT32   ReadSearchOperandBit(UINT8 type, SearchInfo * search, SearchRegion * region, UINT32 address);
876static UINT8   DoSearchComparison(SearchInfo * search, UINT32 lhs, UINT32 rhs);
877static UINT32   DoSearchComparisonBit(SearchInfo * search, UINT32 lhs, UINT32 rhs);
878//static UINT8  IsRegionOffsetValid(SearchInfo * search, SearchRegion * region, UINT32 offset);
1257static UINT32   search_sign_extend(search_info *search, UINT32 value);
1258static UINT32   read_search_operand(UINT8 type, search_info *search, search_region *region, UINT32 address);
1259static UINT32   read_search_operand_bit(UINT8 type, search_info *search, search_region *region, UINT32 address);
1260static UINT8   do_search_comparison(search_info *search, UINT32 lhs, UINT32 rhs);
1261static UINT32   do_search_comparison_bit(search_info *search, UINT32 lhs, UINT32 rhs);
1262#if 0
1263static UINT8  is_region_offset_valid(search_info *search, search_region *region, UINT32 offset);
1264#else
1265#define is_region_offset_valid is_region_offset_valid_bit /* ????? */
1266#endif
1267static UINT8   is_region_offset_valid_bit(search_info *search, search_region *region, UINT32 offset);
1268static void      invalidate_region_offset(search_info *search, search_region *region, UINT32 offset);
1269static void      invalidate_region_offset_bit(search_info *search, search_region *region, UINT32 offset, UINT32 invalidate);
1270static void      invalidate_entire_region(search_info *search, search_region *region);
8791271
880#define IsRegionOffsetValid   IsRegionOffsetValidBit
1272static void      init_new_search(search_info *search);
1273static void      update_search(search_info *search);
8811274
882static UINT8   IsRegionOffsetValidBit(SearchInfo * search, SearchRegion * region, UINT32 offset);
883static void      InvalidateRegionOffset(SearchInfo * search, SearchRegion * region, UINT32 offset);
884static void      InvalidateRegionOffsetBit(SearchInfo * search, SearchRegion * region, UINT32 offset, UINT32 invalidate);
885static void      InvalidateEntireRegion(SearchInfo * search, SearchRegion * region);
1275static void      do_search(search_info *search);
8861276
887static void      InitializeNewSearch(SearchInfo * search);
888static void      UpdateSearch(SearchInfo * search);
889
890static void      DoSearch(SearchInfo * search);
891
892/********** MEMORY ACCESSORS  **********/
1277/********** MEMORY ACCESSOR **********/
8931278static UINT8 **   LookupHandlerMemory(UINT8 cpu, UINT32 address, UINT32 * outRelativeAddress);
1279static UINT8 **   GetMemoryRegionBasePointer(UINT8 cpu, UINT8 space, UINT32 address);
8941280
8951281static UINT32   DoCPURead(UINT8 cpu, UINT32 address, UINT8 bytes, UINT8 swap);
896static UINT32   DoMemoryRead(UINT8 * buf, UINT32 address, UINT8 bytes, UINT8 swap, CPUInfo * info);
1282static UINT32   DoMemoryRead(UINT8 * buf, UINT32 address, UINT8 bytes, UINT8 swap, cpu_region_info *info);
8971283static void      DoCPUWrite(UINT32 data, UINT8 cpu, UINT32 address, UINT8 bytes, UINT8 swap);
898static void      DoMemoryWrite(UINT32 data, UINT8 * buf, UINT32 address, UINT8 bytes, UINT8 swap, CPUInfo * info);
1284static void      DoMemoryWrite(UINT32 data, UINT8 * buf, UINT32 address, UINT8 bytes, UINT8 swap, cpu_region_info *info);
8991285
900/********** CPU **********/
901static UINT8   CPUNeedsSwap(UINT8 cpu);
902static UINT8   RegionNeedsSwap(UINT8 region);
903
904static CPUInfo *   GetCPUInfo(UINT8 cpu);
905static CPUInfo *   GetRegionCPUInfo(UINT8 region);
906
907static UINT32   SwapAddress(UINT32 address, UINT8 dataSize, CPUInfo * info);
908
9091286static UINT32   ReadData(CheatAction * action);
9101287static void      WriteData(CheatAction * action, UINT32 data);
9111288
r2762r2763
9141291static void      AddActionWatch(CheatAction * action, CheatEntry * entry);
9151292static void      RemoveAssociatedWatches(CheatEntry * entry);
9161293
1294/********** ACTIVE/DEACTIVE ENTRY **********/
9171295static void      ResetAction(CheatAction * action);
9181296static void      ActivateCheat(CheatEntry * entry);
9191297static void      DeactivateCheat(CheatEntry * entry);
9201298static void      TempDeactivateCheat(CheatEntry * entry);
9211299
1300/********** OPERATION CORE **********/
9221301static void      cheat_periodicOperation(CheatAction * action);
923static void      cheat_periodicAction(running_machine *machine, CheatAction * action);
1302static UINT8   cheat_periodicCondition(CheatAction * action);
1303static int      cheat_periodicAction(running_machine *machine, CheatAction * action, int selection);
9241304static void      cheat_periodicEntry(running_machine *machine, CheatEntry * entry);
9251305
1306/********** CONFIGURE ENTRY **********/
9261307static void      UpdateAllCheatInfo(void);
9271308static void      UpdateCheatInfo(CheatEntry * entry, UINT8 isLoadTime);
1309static UINT32   AnalyseCodeFormat(CheatEntry * entry, CheatAction * action);
1310static void      CheckCodeFormat(CheatEntry * entry);
1311static void      BuildLabelIndexTable(CheatEntry *entry);
1312static void      SetLayerIndex(void);
9281313
929static int      IsAddressInRange(CheatAction * action, UINT32 length);
1314/********** OTHER STUFF **********/
1315static void      DisplayCheatMessage(void);
1316static UINT8   get_address_length(UINT8 region);
1317static char *   get_region_name(UINT8 region);
1318static void      build_cpu_region_info_list(running_machine *machine);
9301319
931static void      BuildCPUInfoList(running_machine *machine);
1320/***************************************************************************
1321    INLINE FUNCTIONS
1322***************************************************************************/
9321323
1324/*-------------
1325  GetCPUInfo
1326-------------*/
1327
1328INLINE cpu_region_info *get_cpu_info(UINT8 cpu)
1329{
1330   if(VALID_CPU(EXTRACT_FIELD(cpu, CPUIndex)))
1331      return &cpu_info_list[cpu];
1332
1333   return NULL;
1334}
1335
1336/*-------------------
1337  GetRegionCPUInfo
1338-------------------*/
1339
1340INLINE cpu_region_info *get_region_info(UINT8 region)
1341{
1342   if(region >= REGION_CPU1 && region < REGION_MAX)
1343      return &region_info_list[region - REGION_INVALID];
1344
1345   return NULL;
1346}
1347
1348/*-------------------------
1349  get_cpu_or_region_info
1350-------------------------*/
1351
1352INLINE cpu_region_info *get_cpu_or_region_info(UINT8 cpu_region)
1353{
1354   if(TEST_FIELD(cpu_region, RegionFlag))
1355      return get_region_info(cpu_region);
1356   else
1357      return get_cpu_info(cpu_region);
1358}
1359
1360/*-----------------
1361  cpu_needs_swap
1362-----------------*/
1363
1364INLINE UINT8 cpu_needs_swap(UINT8 cpu)
1365{
1366   return cpu_info_list[cpu].endianness | 1;
1367}
1368
1369/*--------------------
1370  region_needs_swap
1371--------------------*/
1372
1373INLINE UINT8 region_needs_swap(UINT8 region)
1374{
1375   cpu_region_info *temp = get_region_info(region);
1376
1377   if(temp)
1378      return temp->endianness | 1;
1379
1380   return 0;
1381}
1382
1383/*--------------
1384  SwapAddress
1385--------------*/
1386
1387INLINE UINT32 SwapAddress(UINT32 address, UINT8 dataSize, cpu_region_info *info)
1388{
1389   switch(info->data_bits)
1390   {
1391      case 16:
1392         if(info->endianness == CPU_IS_BE)
1393            return BYTE_XOR_BE(address);
1394         else
1395            return BYTE_XOR_LE(address);
1396
1397      case 32:
1398         if(info->endianness == CPU_IS_BE)
1399            return BYTE4_XOR_BE(address);
1400         else
1401            return BYTE4_XOR_LE(address);
1402   }
1403
1404   return address;
1405}
1406
1407/*-------------------
1408  IsAddressInRange
1409-------------------*/
1410
1411INLINE int IsAddressInRange(CheatAction * action, UINT32 length)
1412{
1413   return ((action->address + EXTRACT_FIELD(action->type, AddressSize) + 1) <= length);
1414}
1415
1416/*----------
1417  DoShift
1418----------*/
1419
1420INLINE UINT32 DoShift(UINT32 input, INT8 shift)
1421{
1422   if(shift > 0)
1423      return input >> shift;
1424   else
1425      return input << -shift;
1426}
1427
1428/***************************************************************************
1429    KEY HANDLER
1430***************************************************************************/
1431
9331432/*--------------------------------------------------------------
9341433  special key handler - check pressing shift, ctrl or alt key
9351434--------------------------------------------------------------*/
r2762r2763
11561655
11571656#endif
11581657
1159/*-------------------------------------
1160  old_style_menu - export menu items
1161-------------------------------------*/
1658/*---------------------------------------------------
1659  ui_pressed_repeat_throttle - key repeat handling
1660---------------------------------------------------*/
11621661
1163static void old_style_menu(const char **items, const char **subitems, char *flag, int selected, int arrowize_subitem)
1662static int ui_pressed_repeat_throttle(running_machine *machine, int code, int base_speed)
11641663{
1165   static ui_menu_item item_list[1000];
1166   int menu_items;
1664   int pressed = 0;
1665   const int delay_ramp_timer = 10;
1666   static int last_code = -1;
1667   static int last_speed = -1;
1668   static int increment_timer = 0;
11671669
1168   for (menu_items = 0; items[menu_items]; menu_items++)
1169   {
1170      item_list[menu_items].text = items[menu_items];
1171      item_list[menu_items].subtext = subitems ? subitems[menu_items] : NULL;
1172      item_list[menu_items].flags = 0;
1173      if (flag && flag[menu_items])
1174         item_list[menu_items].flags |= MENU_FLAG_INVERT;
1175      if (menu_items == selected)
1176      {
1177         if (arrowize_subitem & 1)
1178            item_list[menu_items].flags |= MENU_FLAG_LEFT_ARROW;
1179         if (arrowize_subitem & 2)
1180            item_list[menu_items].flags |= MENU_FLAG_RIGHT_ARROW;
1181      }
1182   }
1183   ui_menu_draw(item_list, menu_items, selected, NULL);
1184}
1185
1186/*-------------------------------------------------
1187  UIPressedRepoeatThrottle - key repeat handling
1188-------------------------------------------------*/
1189
1190static int UIPressedRepeatThrottle(running_machine *machine, int code, int baseSpeed)
1191{
1192   static int   lastCode = -1;
1193   static int   lastSpeed = -1;
1194   static int   incrementTimer = 0;
1195   int         pressed = 0;
1196
1197   const int   kDelayRampTimer = 10;
1198
11991670   if(input_type_pressed(machine, code, 0))
12001671   {
1201      if(lastCode != code)         // different key pressed
1672      if(last_code != code)
12021673      {
1203         lastCode = code;
1204         lastSpeed = baseSpeed;
1205         incrementTimer = kDelayRampTimer * lastSpeed;
1674         /* pressed different key */
1675         last_code = code;
1676         last_speed = base_speed;
1677         increment_timer = delay_ramp_timer * last_speed;
12061678      }
1207      else                     // same key pressed
1679      else
12081680      {
1209         incrementTimer--;
1681         /* hold the same key */
1682         increment_timer--;
12101683
1211         if(incrementTimer <= 0)
1684         if(increment_timer <= 0)
12121685         {
1213            incrementTimer = kDelayRampTimer * lastSpeed;
1686            increment_timer = delay_ramp_timer * last_speed;
12141687
1215            lastSpeed /= 2;
1688            last_speed /= 2;
12161689
1217            if(lastSpeed < 1)
1218               lastSpeed = 1;
1690            if(last_speed < 1)
1691               last_speed = 1;
12191692
12201693            pressed = 1;
12211694         }
r2762r2763
12231696   }
12241697   else
12251698   {
1226      if(lastCode == code)
1227         lastCode = -1;
1699      if(last_code == code)
1700         last_code = -1;
12281701   }
12291702
1230   return input_ui_pressed_repeat(machine, code, lastSpeed);
1703   return input_ui_pressed_repeat(machine, code, last_speed);
12311704}
12321705
1233/*---------------------------------
1234  ReadHexInput - check hex input
1235---------------------------------*/
1706/*-----------------------------------
1707  read_hex_input - check hex input
1708-----------------------------------*/
12361709
1237static int ReadHexInput(void)
1710static int read_hex_input(void)
12381711{
1239   int   i;
1712   int i;
12401713
12411714   for(i = 0; i < 10; i++)
12421715   {
r2762r2763
12621735/*-----------------------------------------------------------------
12631736  DoDynamicEditTextField - edit text field with direct key input
12641737-----------------------------------------------------------------*/
1265
1738#if 0
12661739static char * DoDynamicEditTextField(char * buf)
12671740{
1268   char   code = osd_readkey_unicode(0) & 0xFF;
1741   char code = osd_readkey_unicode(0) & 0xFF;
12691742
12701743   if(code == 0x08)
12711744   {
1272      /* ----- backspace ----- */
1745      /* backspace */
12731746      if(buf)
12741747      {
12751748         size_t   length = strlen(buf);
r2762r2763
12951768      {
12961769         if(buf)
12971770         {
1298            size_t   length = strlen(buf);
1771            size_t length = strlen(buf);
12991772
13001773            buf = realloc(buf, length + 2);
13011774
r2762r2763
13141787
13151788   return buf;
13161789}
1317
1790#endif
13181791/*------------------------
13191792  DoStaticEditTextField
13201793------------------------*/
r2762r2763
13311804
13321805   if(code == 0x08)
13331806   {
1807      /* back space */
13341808      if(length > 0)
1335      {
13361809         buf[length - 1] = 0;
1337      }
13381810   }
13391811   else if(isprint(code))
13401812   {
r2762r2763
13461818   }
13471819}
13481820
1349/*------------------------------------------------------------------
1350  DoEditHexField - edit hex field with direct key input (unsigned)
1351------------------------------------------------------------------*/
1821/*----------------------------------------------------------------------
1822  do_edit_hex_field - edit hex field with direct key input (unsigned)
1823----------------------------------------------------------------------*/
13521824
1353static UINT32 DoEditHexField(running_machine *machine, UINT32 data)
1825static UINT32 do_edit_hex_field(running_machine *machine, UINT32 data)
13541826{
1355   INT8   key;
1827   INT8 key;
13561828
13571829   if(input_code_pressed_once(KEYCODE_BACKSPACE))
13581830   {
1359      /* ----- backspace ----- */
1831      /* back space */
13601832      data >>= 4;
1361
13621833      return data;
13631834   }
1364   else
1835   else if(input_ui_pressed(machine, IPT_UI_CLEAR))
13651836   {
1366      if(input_ui_pressed(machine, IPT_UI_CLEAR))
1367      {
1368         data = 0;
1369
1370         return data;
1371      }
1837      /* data clear */
1838      data = 0;
1839      return data;
13721840   }
13731841
1374   key = ReadHexInput();
1842   key = read_hex_input();
13751843
13761844   if(key != -1)
13771845   {
r2762r2763
13941862   if(isNegative)
13951863      data |= mask;
13961864
1397   key = ReadHexInput();
1865   key = read_hex_input();
13981866
13991867   if(key != -1)
14001868   {
r2762r2763
14221890
14231891static INT32 DoEditDecField(INT32 data, INT32 min, INT32 max)
14241892{
1425   char   code = osd_readkey_unicode(0) & 0xFF;
1893   char code = osd_readkey_unicode(0) & 0xFF;
14261894
14271895   if((code >= '0') && (code <= '9'))
14281896   {
r2762r2763
14351903         data = -data;
14361904      else
14371905      {
1438         /* ----- backspace ----- */
1906         /* backspace */
14391907         if(code == 0x08)
14401908            data /= 10;
14411909      }
14421910   }
14431911
1444   /* ----- adjust value ----- */
1912   /* adjust value */
14451913   if(data < min)
14461914      data = min;
14471915   if(data > max)
r2762r2763
14501918   return data;
14511919}
14521920
1453/***************************************************************************
1454    INITIALIZATION
1455***************************************************************************/
1921/*--------------------------------------------------------------------------------
1922  DoIncrementHexField - increment a specified value in hex field with arrow key
1923--------------------------------------------------------------------------------*/
14561924
1457/*---------------------------------------
1458  cheat_init - initialize cheat system
1459---------------------------------------*/
1460
1461void cheat_init(running_machine *machine)
1925static UINT32 DoIncrementHexField(UINT32 data, UINT8 digits)
14621926{
1463   /* ----- initialize lists ----- */
1464   cheatList =            NULL;
1465   cheatListLength =      0;
1927   data =   ((data & ~kIncrementMaskTable[digits]) |
1928         (((data & kIncrementMaskTable[digits]) + kIncrementValueTable[digits]) &
1929         kIncrementMaskTable[digits]));
14661930
1467   watchList =            NULL;
1468   watchListLength =      0;
1931   return data;
1932}
14691933
1470   searchList =         NULL;
1471   searchListLength =      0;
1934/*--------------------------------------------------------------------------------
1935  DoDecrementHexField - decrement a specified value in hex field with arrow key
1936--------------------------------------------------------------------------------*/
14721937
1473#ifdef MESS
1474   InitMessCheats(machine);
1475#endif
1938static UINT32 DoDecrementHexField(UINT32 data, UINT8 digits)
1939{
1940   data =   ((data & ~kIncrementMaskTable[digits]) |
1941         (((data & kIncrementMaskTable[digits]) - kIncrementValueTable[digits]) &
1942         kIncrementMaskTable[digits]));
14761943
1477   /* ----- initialize flags ----- */
1478   currentSearchIdx =         0;
1479   foundCheatDatabase =      0;
1480   cheatsDisabled =         0;
1481   watchesDisabled =         0;
1482   cheatOptions =            2;
1944   return data;
1945}
14831946
1484   fullMenuPageHeight =   floor(1.0f / ui_get_line_height()) - 1;
1947/*--------------------------------------------------------------------------------------
1948  DoIncrementHexFieldSigned - increment a specified value in hex field with arrow key
1949--------------------------------------------------------------------------------------*/
14851950
1486   /* ----- initialize CPU info for cheat system ----- */
1487   BuildCPUInfoList(machine);
1951static UINT32 DoIncrementHexFieldSigned(UINT32 data, UINT8 digits, UINT8 bytes)
1952{
1953   UINT32 newData = data;
14881954
1489   /* ----- load cheat database ----- */
1490   LoadCheatDatabase(machine);
1955   if(data & kSearchByteSignBitTable[bytes])
1956   {
1957      /* MINUS */
1958      newData =   ((newData & ~kIncrementMaskTable[digits]) |
1959               (((newData & kIncrementMaskTable[digits]) - kIncrementValueTable[digits]) &
1960               kIncrementMaskTable[digits]));
14911961
1492   ResizeSearchList(1);
1493   ResizeWatchList(20);
1962      if(newData & kSearchByteSignBitTable[bytes])
1963         newData = ((data & ~kIncrementMaskTable[digits]) | (newData & kIncrementMaskTable[digits]));
1964   }
1965   else
1966   {
1967      /* PLUS */
1968      newData =   ((newData & ~kIncrementMaskTable[digits]) |
1969               (((newData & kIncrementMaskTable[digits]) + kIncrementValueTable[digits]) &
1970               kIncrementMaskTable[digits]));
14941971
1495   /* ----- initialize search regions ----- */
1496   BuildSearchRegions(machine, GetCurrentSearch());
1497   AllocateSearchRegions(GetCurrentSearch());
1972      if(!(newData & kSearchByteSignBitTable[bytes]))
1973         newData = ((data & ~kIncrementMaskTable[digits]) | (newData & kIncrementMaskTable[digits]));
1974   }
14981975
1499   /* ----- initialize string table ----- */
1500   InitStringTable();
1501
1502   periodic_timer = timer_alloc(cheat_periodic, NULL);
1503   timer_adjust_periodic(periodic_timer, video_screen_get_frame_period(machine->primary_screen), 0, video_screen_get_frame_period(machine->primary_screen));
1504
1505   add_exit_callback(machine, cheat_exit);
1976   return newData;
15061977}
15071978
1508/*---------------------------------
1509  cheat_exit - free cheat system
1510---------------------------------*/
1979/*--------------------------------------------------------------------------------------
1980  DoDecrementHexFieldSigned - decrement a specified value in hex field with arrow key
1981--------------------------------------------------------------------------------------*/
15111982
1512static void cheat_exit(running_machine *machine)
1983static UINT32 DoDecrementHexFieldSigned(UINT32 data, UINT8 digits, UINT8 bytes)
15131984{
1514   int   i;
1985   UINT32 newData = data;
15151986
1516   /* ----- save all cheats automatically if needed ----- */
1517   if(TEST_FIELD(cheatOptions, AutoSaveEnabled))
1518      DoAutoSaveCheats(machine);
1519
1520   /* ----- free database ----- */
1521   DisposeCheatDatabase();
1522
1523   /* ----- free watch lists ----- */
1524   if(watchList)
1987   if(data & kSearchByteSignBitTable[bytes])
15251988   {
1526      for(i = 0; i < watchListLength; i++)
1527         DisposeWatch(&watchList[i]);
1989      /* MINUS */
1990      newData =   ((newData & ~kIncrementMaskTable[digits]) |
1991               (((newData & kIncrementMaskTable[digits]) + kIncrementValueTable[digits]) &
1992               kIncrementMaskTable[digits]));
15281993
1529      free(watchList);
1530
1531      watchList = NULL;
1994      if(newData & kSearchByteSignBitTable[bytes])
1995         newData = ((data & ~kIncrementMaskTable[digits]) | (newData & kIncrementMaskTable[digits]));
15321996   }
1533
1534   /* ----- free search lists ----- */
1535   if(searchList)
1997   else
15361998   {
1537      for(i = 0; i < searchListLength; i++)
1538         DisposeSearch(i);
1999      /* PLUS */
2000      newData =   ((newData & ~kIncrementMaskTable[digits]) |
2001               (((newData & kIncrementMaskTable[digits]) - kIncrementValueTable[digits]) &
2002               kIncrementMaskTable[digits]));
15392003
1540      free(searchList);
1541
1542      searchList = NULL;
2004      if(!(newData & kSearchByteSignBitTable[bytes]))
2005         newData = ((data & ~kIncrementMaskTable[digits]) | (newData & kIncrementMaskTable[digits]));
15432006   }
15442007
1545   /* ----- free string table ----- */
1546   FreeStringTable();
2008   return newData;
2009}
15472010
1548   free(menuItemInfo);
1549   menuItemInfo = NULL;
2011/*--------------------------------------------------------------------------------
2012  DoIncrementDecField - increment a specified value in dec field with arrow key
2013--------------------------------------------------------------------------------*/
15502014
1551#ifdef MESS
1552   StopMessCheats();
1553#endif
2015static UINT32 DoIncrementDecField(UINT32 data, UINT8 digits)
2016{
2017   UINT32 value = data & kIncrementMaskTable[digits];
15542018
1555   /* ----- free flags ----- */
1556   cheatListLength =         0;
1557   watchListLength =         0;
1558   searchListLength =         0;
1559   currentSearchIdx =         0;
1560//  cheatEngineWasActive =      0;
1561   foundCheatDatabase =      0;
1562   cheatsDisabled =         0;
1563   watchesDisabled =         0;
1564   mainDatabaseName[0] =      0;
1565   menuItemInfoLength =      0;
1566   cheatOptions =            0;
2019   if(value >= kIncrementDecTable[digits])
2020      value = 0;
2021   else
2022      value += kIncrementValueTable[digits];
2023
2024   return ((data & ~kIncrementMaskTable[digits]) | value);
15672025}
15682026
1569/*-----------------------------------------------------
1570  cheat_menu - management for the cheat general menu
1571-----------------------------------------------------*/
2027/*--------------------------------------------------------------------------------
2028  DoDecrementDecField - increment a specified value in dec field with arrow key
2029--------------------------------------------------------------------------------*/
15722030
1573int cheat_menu(running_machine *machine, int selection)
2031static UINT32 DoDecrementDecField(UINT32 data, UINT8 digits)
15742032{
1575   enum
1576   {
1577      kMenu_EnableDisable = 0,
1578      kMenu_AddEdit,
1579      kMenu_Search,
1580      kMenu_ChooseWatch,
1581      kMenu_ReloadDatabase,
1582      kMenu_Options,
1583      kMenu_Return,
2033   UINT32 value = data & kIncrementMaskTable[digits];
15842034
1585      kMenu_Max
1586   };
2035   if(!value)
2036      value = kIncrementDecTable[digits];
2037   else
2038      value -= kIncrementValueTable[digits];
15872039
1588   ui_menu_item   menu_item[kMenu_Max];
2040   return ((data & ~kIncrementMaskTable[digits]) | value);
2041}
15892042
1590   INT32         sel;
1591   UINT8         total = 0;
2043/***************************************************************************
2044    INITIALIZATION
2045***************************************************************************/
15922046
1593   static INT32   submenu_choice = 0;
1594   static int      firstEntry = 0;
1595   static int      lastPstn = 0;
2047/*---------------------------------------
2048  cheat_init - initialize cheat system
2049---------------------------------------*/
15962050
1597   /* ----- allocate memory for item list ----- */
1598   memset(menu_item, 0, sizeof(menu_item));
2051void cheat_init(running_machine *machine)
2052{
2053   /* initialize lists */
2054   cheatList         = NULL;
2055   cheatListLength      = 0;
15992056
1600//  cheatEngineWasActive = 1;
2057   watchList         = NULL;
2058   watchListLength      = 0;
16012059
1602   sel = lastPstn;
2060   search_list = NULL;
2061   search_list_length = 0;
16032062
1604   /********** SUB MENU **********/
1605   if(submenu_choice)
1606   {
1607      switch(sel)
1608      {
1609         case kMenu_EnableDisable:
1610            submenu_choice = EnableDisableCheatMenu(machine, submenu_choice, firstEntry);
1611            break;
2063#ifdef MESS
2064   InitMessCheats(machine);
2065#endif
16122066
1613         case kMenu_AddEdit:
1614            submenu_choice = AddEditCheatMenu(machine, submenu_choice);
1615            break;
2067   /* initialize flags */
2068   current_search_idx   = 0;
2069   foundCheatDatabase   = 0;
2070   cheatsDisabled      = 0;
2071   watchesDisabled      = 0;
2072   editActive         = 0;
2073   editCursor         = 0;
2074   cheatOptions      = DEFAULT_CHEAT_OPTIONS;
2075   driverSpecifiedFlag   = 0;
16162076
1617         case kMenu_Search:
1618            switch(EXTRACT_FIELD(cheatOptions, SearchBox))
1619            {
1620               case kSearchBox_Minimum:
1621                  submenu_choice = DoSearchMenuMinimum(machine, submenu_choice);
1622                  break;
2077   fullMenuPageHeight = visible_items = floor(1.0f / ui_get_line_height()) - 1;
16232078
1624               case kSearchBox_Classic:
1625                  submenu_choice = DoSearchMenuClassic(machine, submenu_choice);
1626                  break;
2079   /* initialize CPU/Region info for cheat system */
2080   build_cpu_region_info_list(machine);
16272081
1628               case kSearchBox_Advanced:
1629                  submenu_choice = DoSearchMenu(machine, submenu_choice);
1630                  break;
1631            }
1632            break;
2082   /* set cheat list from database */
2083   LoadCheatDatabase(machine, kLoadFlag_CheatOption | kLoadFlag_CheatCode);
16332084
1634         case kMenu_ChooseWatch:
1635            submenu_choice = ChooseWatch(machine, submenu_choice);
1636            break;
2085   /* set default search and watch lists */
2086   resize_search_list(1);
2087   ResizeWatchList(fullMenuPageHeight - 1);
16372088
1638         case kMenu_Options:
1639            submenu_choice = SelectOptions(machine, submenu_choice);
1640            break;
1641      }
2089   /* build search region */
2090   {
2091      search_info *info = get_current_search();
16422092
1643      firstEntry = 0;
2093      /* attemp to load user region */
2094      LoadCheatDatabase(machine, kLoadFlag_UserRegion);
16442095
1645      /* ----- quick menu switching ------ */
1646      if(submenu_choice < 0)
2096      /* if no user region or fail to load the database, attempt to build default region */
2097      if(info->region_list_length)
2098         info->search_speed = ksearch_speed_UserDefined;
2099      else
16472100      {
1648         switch(submenu_choice)
1649         {
1650            case -1:
1651               lastPstn = kMenu_EnableDisable;
1652               break;
1653
1654            case -2:
1655               lastPstn = kMenu_AddEdit;
1656               break;
1657
1658            case -3:
1659               lastPstn = kMenu_Search;
1660               break;
1661
1662            case -4:
1663               lastPstn = kMenu_ChooseWatch;
1664               break;
1665
1666            default:
1667               ui_popup_time(1, "undefined menu switching : %x", submenu_choice);
1668         }
1669
1670         submenu_choice = 1;
2101         info->search_speed = ksearch_speed_VerySlow;
2102         build_search_regions(machine, info);
16712103      }
16722104
1673      return sel + 1;
2105      /* memory allocation for search region */
2106      allocate_search_regions(info);
16742107   }
16752108
1676   /********** MENU CONSTRUCION **********/
1677   menu_item[total++].text = "Enable/Disable a Cheat";            // Enable/Disable a Cheat
2109   /* initialize string table */
2110   init_string_table();
16782111
1679   menu_item[total++].text = "Add/Edit a Cheat";         // Add/Edit a Cheat
2112   /* initialize cheat menu stack */
2113   init_cheat_menu_stack();
16802114
1681   switch(EXTRACT_FIELD(cheatOptions, SearchBox))                  // Search a Cheat
16822115   {
1683      case kSearchBox_Minimum:
1684         menu_item[total++].text = "Search a Cheat (Minimum Mode)";
1685         break;
2116      astring * sourceName;
16862117
1687      case kSearchBox_Classic:
1688         menu_item[total++].text = "Search a Cheat (Classic Mode)";
1689         break;
2118      sourceName = core_filename_extract_base(astring_alloc(), machine->gamedrv->source_file, TRUE);
16902119
1691      case kSearchBox_Advanced:
1692         menu_item[total++].text = "Search a Cheat (Advanced Mode)";
1693         break;
2120      if(!strcmp(astring_c(sourceName), "neodrvr"))
2121         driverSpecifiedFlag |= 1;
2122      else if(!strcmp(astring_c(sourceName), "cps2"))
2123         driverSpecifiedFlag |= 2;
2124      else if(!strcmp(astring_c(sourceName), "cps3"))
2125         driverSpecifiedFlag |= 4;
2126
2127      astring_free(sourceName);
16942128   }
16952129
1696   menu_item[total++].text = "Configure Watchpoints";            // Configure Watchpoints
2130   /* NOTE : disable all cheat messages in initializing so that message parameters should be initialized here */
2131   messageType      = 0;
2132   messageTimer   = 0;
16972133
1698   menu_item[total++].text = "Reload Database";         // Reload Cheat Database
2134   periodic_timer = timer_alloc(cheat_periodic, NULL);
2135   timer_adjust_periodic(periodic_timer, video_screen_get_frame_period(machine->primary_screen), 0, video_screen_get_frame_period(machine->primary_screen));
16992136
1700   menu_item[total++].text = "Options";               // Options
2137   add_exit_callback(machine, cheat_exit);
2138}
17012139
1702   menu_item[total++].text = "Return to Main Menu";         // return to the MAME general menu
2140/*---------------------------------
2141  cheat_exit - free cheat system
2142---------------------------------*/
17032143
1704   menu_item[total].text = NULL;                              // terminate array
2144static void cheat_exit(running_machine *machine)
2145{
2146   int i;
17052147
1706   /* ----- adjust cursor postion ----- */
1707   if(sel < 0)
1708      sel = 0;
1709   if(sel > (total - 1))
1710      sel = total - 1;
2148   /* save all cheats automatically if needed */
2149   if(TEST_FIELD(cheatOptions, AutoSaveEnabled))
2150      DoAutoSaveCheats(machine);
17112151
1712   /* ----- print it ----- */
1713   ui_menu_draw(menu_item, total, sel, NULL);
2152   /* free database */
2153   DisposeCheatDatabase();
17142154
1715   /********** KEY HANDLING **********/
1716   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
2155   /* free watch lists */
2156   if(watchList)
17172157   {
1718      if(sel < (total - 1))
1719         sel++;
1720      else
1721         sel = 0;
1722   }
2158      for(i = 0; i < watchListLength; i++)
2159         DisposeWatch(&watchList[i]);
17232160
1724   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
1725   {
1726      if(sel > 0)
1727         sel--;
1728      else
1729         sel = total - 1;
2161      free(watchList);
2162
2163      watchList = NULL;
17302164   }
17312165
1732   if(input_ui_pressed(machine, IPT_UI_SELECT))
2166   /* free search lists */
2167   if(search_list)
17332168   {
1734      switch(sel)
1735      {
1736         case kMenu_Return:
1737            submenu_choice = 0;
1738            sel = -1;
1739            lastPstn = 0;      // if cursor is now on the return item, adjust cursor keeper
1740            break;
2169      for(i = 0; i < search_list_length; i++)
2170         dispose_search(&search_list[i]);
17412171
1742         case kMenu_ReloadDatabase:
1743            ReloadCheatDatabase(machine);
1744            break;
2172      free(search_list);
17452173
1746         default:
1747            firstEntry = 1;
1748            submenu_choice = 1;
1749            break;
1750      }
2174      search_list = NULL;
17512175   }
17522176
1753   if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT))
1754      ReloadCheatDatabase(machine);
2177   /* free string table */
2178   free_string_table();
17552179
1756   if(input_ui_pressed(machine, IPT_UI_CANCEL))
1757   {
1758      if(sel == kMenu_Return)
1759         lastPstn = 0;         // if cursor is now on the return item, adjust cursor keeper
2180   /* free cheat menu stack */
2181   free_cheat_menu_stack();
17602182
1761      sel = -1;
1762   }
2183   free(menu_item_info);
2184   menu_item_info = NULL;
17632185
1764   /* ----- keep current cursor position ----- */
1765   if(sel >= 0)
1766      lastPstn = sel;
2186#ifdef MESS
2187   StopMessCheats();
2188#endif
17672189
1768   return sel + 1;
2190   /* free flags */
2191   cheatListLength      = 0;
2192   watchListLength      = 0;
2193   search_list_length   = 0;
2194   current_search_idx   = 0;
2195   foundCheatDatabase   = 0;
2196   cheatsDisabled      = 0;
2197   watchesDisabled      = 0;
2198   mainDatabaseName[0]   = 0;
2199   menuItemInfoLength   = 0;
2200   cheatVariable[0]   = 0;
2201   cheatOptions      = 0;
2202   driverSpecifiedFlag   = 0;
2203   messageType         = 0;
2204   messageTimer      = 0;
17692205}
17702206
1771/*----------
1772  DoShift
1773----------*/
2207/*----------------------------------
2208  cheat_menu - handle cheat menus
2209----------------------------------*/
17742210
1775static UINT32 DoShift(UINT32 input, INT8 shift)
2211int cheat_menu(running_machine *machine, int selection)
17762212{
1777   if(shift > 0)
1778      return input >> shift;
1779   else
1780      return input << -shift;
2213   cheat_menu_stack *menu = &menu_stack[stack_index];
2214
2215   /* handle cheat message */
2216   DisplayCheatMessage();
2217
2218   /* handle cheat menu */
2219   selection = (*menu->handler)(machine, menu);
2220
2221   if(selection == 0)
2222   {
2223      if(stack_index)
2224         /* return previous "cheat" menu */
2225         cheat_menu_stack_pop();
2226      else
2227         /* return MAME general menu */
2228         return selection;
2229   }
2230
2231   return selection + 1;
17812232}
17822233
17832234/*----------------------------------------
r2762r2763
17862237
17872238static UINT32 BCDToDecimal(UINT32 value)
17882239{
1789   UINT32   accumulator = 0;
1790   UINT32   multiplier = 1;
17912240   int      i;
2241   UINT32   accumulator   = 0;
2242   UINT32   multiplier   = 1;
17922243
17932244   for(i = 0; i < 8; i++)
17942245   {
r2762r2763
18072258
18082259static UINT32 DecimalToBCD(UINT32 value)
18092260{
1810   UINT32   accumulator = 0;
1811   UINT32   divisor = 10;
18122261   int      i;
2262   UINT32   accumulator   = 0;
2263   UINT32   divisor      = 10;
18132264
18142265   for(i = 0; i < 8; i++)
18152266   {
r2762r2763
18272278   return accumulator;
18282279}
18292280
1830/*----------------------
1831  RebuildStringTables
1832----------------------*/
2281/*-----------------------------------------------------------------
2282  rebuild_string_tables - memory allocation for menu string list
2283-----------------------------------------------------------------*/
18332284
1834static void RebuildStringTables(void)
2285static void rebuild_string_tables(void)
18352286{
1836   UINT32   storageNeeded, i;
1837   char   * traverse;
2287   UINT32 i;
2288   UINT32 storage_needed;
2289   char *traverse;
18382290
1839   storageNeeded =            (menuStrings.mainStringLength + menuStrings.subStringLength) * menuStrings.numStrings;
2291   /* calculate length of total buffer */
2292   storage_needed = (menu_strings.main_string_length + menu_strings.sub_string_length) * menu_strings.num_strings;
18402293
1841   menuStrings.mainList =      (const char **)   realloc((char *)   menuStrings.mainList,      sizeof(char *) * menuStrings.length);
1842   menuStrings.subList =      (const char **)   realloc((char *)   menuStrings.subList,      sizeof(char *) * menuStrings.length);
1843   menuStrings.flagList =                  realloc(         menuStrings.flagList,      sizeof(char)   * menuStrings.length);
1844   menuStrings.mainStrings =               realloc(         menuStrings.mainStrings,   sizeof(char *) * menuStrings.numStrings);
1845   menuStrings.subStrings =               realloc(         menuStrings.subStrings,      sizeof(char *) * menuStrings.numStrings);
1846   menuStrings.buf =                     realloc(         menuStrings.buf,         sizeof(char)   * storageNeeded);
2294   /* allocate memory for all items */
2295   menu_strings.main_list =   (const char **)   realloc((char *)   menu_strings.main_list,      sizeof(char *)   * menu_strings.length);
2296   menu_strings.sub_list =      (const char **)   realloc((char *)   menu_strings.sub_list,      sizeof(char *)   * menu_strings.length);
2297   menu_strings.flag_list =               realloc(         menu_strings.flag_list,      sizeof(char)   * menu_strings.length);
2298   menu_strings.main_strings =               realloc(         menu_strings.main_strings,   sizeof(char *)   * menu_strings.num_strings);
2299   menu_strings.sub_strings =               realloc(         menu_strings.sub_strings,   sizeof(char *)   * menu_strings.num_strings);
2300   menu_strings.buf =                     realloc(         menu_strings.buf,         sizeof(char)   * storage_needed);
18472301
1848   if(   (!menuStrings.mainList && menuStrings.length) ||
1849      (!menuStrings.subList && menuStrings.length) ||
1850      (!menuStrings.flagList && menuStrings.length) ||
1851      (!menuStrings.mainStrings && menuStrings.numStrings) ||
1852      (!menuStrings.subStrings && menuStrings.numStrings) ||
1853      (!menuStrings.buf && storageNeeded))
2302   if(   (menu_strings.main_list == NULL && menu_strings.length) ||
2303      (menu_strings.sub_list == NULL && menu_strings.length) ||
2304      (menu_strings.flag_list == NULL && menu_strings.length) ||
2305      (menu_strings.main_strings == NULL && menu_strings.num_strings) ||
2306      (menu_strings.sub_strings == NULL && menu_strings.num_strings) ||
2307      (menu_strings.buf == NULL && storage_needed))
18542308   {
1855      fatalerror(   "cheat: memory allocation error\n"
2309      fatalerror(   "cheat: [string table] memory allocation error\n"
18562310               "   length =         %.8X\n"
1857               "   numStrings =      %.8X\n"
1858               "   mainStringLength =   %.8X\n"
1859               "   subStringLength =   %.8X\n"
2311               "   num_strings =      %.8X\n"
2312               "   main_stringLength =   %.8X\n"
2313               "   sub_string_length =   %.8X\n"
18602314               "%p %p %p %p %p %p\n",
1861               menuStrings.length,
1862               menuStrings.numStrings,
1863               menuStrings.mainStringLength,
1864               menuStrings.subStringLength,
2315               menu_strings.length,
2316               menu_strings.num_strings,
2317               menu_strings.main_string_length,
2318               menu_strings.sub_string_length,
18652319
1866               menuStrings.mainList,
1867               menuStrings.subList,
1868               menuStrings.flagList,
1869               menuStrings.mainStrings,
1870               menuStrings.subStrings,
1871               menuStrings.buf);
2320               menu_strings.main_list,
2321               menu_strings.sub_list,
2322               menu_strings.flag_list,
2323               menu_strings.main_strings,
2324               menu_strings.sub_strings,
2325               menu_strings.buf);
18722326   }
18732327
1874   traverse = menuStrings.buf;
2328   traverse = menu_strings.buf;
18752329
1876   for(i = 0; i < menuStrings.numStrings; i++)
2330   /* allocate string buffer to list */
2331   for(i = 0; i < menu_strings.num_strings; i++)
18772332   {
1878      menuStrings.mainStrings[i] = traverse;
1879      traverse += menuStrings.mainStringLength;
1880
1881      menuStrings.subStrings[i] = traverse;
1882      traverse += menuStrings.subStringLength;
2333      menu_strings.main_strings[i] = traverse;
2334      traverse += menu_strings.main_string_length;
2335      menu_strings.sub_strings[i] = traverse;
2336      traverse += menu_strings.sub_string_length;
18832337   }
18842338}
18852339
1886/*-----------------------------------------------------------
1887  RequestStrings - check list length and rebuild if needed
1888-----------------------------------------------------------*/
2340/*------------------------------------------------------------
2341  request_strings - check string list and rebuild if needed
2342------------------------------------------------------------*/
18892343
1890static void RequestStrings(UINT32 length, UINT32 numStrings, UINT32 mainStringLength, UINT32 subStringLength)
2344static void request_strings(UINT32 length, UINT32 num_strings, UINT32 main_string_length, UINT32 sub_string_length)
18912345{
1892   UINT8   changed = 0;
2346   UINT8 changed = 0;
18932347
1894   if(menuStrings.length < length)
2348   /* total items */
2349   if(menu_strings.length < length)
18952350   {
1896      menuStrings.length = length;
1897
2351      menu_strings.length = length;
18982352      changed = 1;
18992353   }
19002354
1901   if(menuStrings.numStrings < numStrings)
2355   /* total buffer items */
2356   if(menu_strings.num_strings < num_strings)
19022357   {
1903      menuStrings.numStrings = numStrings;
1904
2358      menu_strings.num_strings = num_strings;
19052359      changed = 1;
19062360   }
19072361
1908   if(menuStrings.mainStringLength < mainStringLength)
2362   /* length of buffer 1*/
2363   if(menu_strings.main_string_length < main_string_length)
19092364   {
1910      menuStrings.mainStringLength = mainStringLength;
1911
2365      menu_strings.main_string_length = main_string_length;
19122366      changed = 1;
19132367   }
19142368
1915   if(menuStrings.subStringLength < subStringLength)
2369   /* length of buffer 2 */
2370   if(menu_strings.sub_string_length < sub_string_length)
19162371   {
1917      menuStrings.subStringLength = subStringLength;
1918
2372      menu_strings.sub_string_length = sub_string_length;
19192373      changed = 1;
19202374   }
19212375
19222376   if(changed)
1923      RebuildStringTables();
2377      rebuild_string_tables();
19242378}
19252379
1926/*------------------
1927  InitStringTable
1928------------------*/
2380/*----------------------------------------------
2381  init_string_table - initialize string table
2382----------------------------------------------*/
19292383
1930static void InitStringTable(void)
2384static void init_string_table(void)
19312385{
1932   memset(&menuStrings, 0, sizeof(MenuStringList));
2386   memset(&menu_strings, 0, sizeof(menu_string_list));
19332387}
19342388
1935/*------------------
1936  FreeStringTable
1937------------------*/
2389/*----------------------------------------
2390  free_string_table - free string table
2391----------------------------------------*/
19382392
1939static void FreeStringTable(void)
2393static void free_string_table(void)
19402394{
1941   free((char *)menuStrings.mainList);
1942   free((char *)menuStrings.subList);
1943   free(menuStrings.flagList);
1944   free(menuStrings.mainStrings);
1945   free(menuStrings.subStrings);
1946   free(menuStrings.buf);
2395   free((char *)   menu_strings.main_list);
2396   free((char *)   menu_strings.sub_list);
2397   free(         menu_strings.flag_list);
2398   free(         menu_strings.main_strings);
2399   free(         menu_strings.sub_strings);
2400   free(         menu_strings.buf);
19472401
1948   memset(&menuStrings, 0, sizeof(MenuStringList));
2402   memset(&menu_strings, 0, sizeof(menu_string_list));
19492403}
19502404
1951/*---------------------------------------------------------------------------
1952  CreateStringCopy - copy stirng. It is only called on LoadCheatFile() now
1953---------------------------------------------------------------------------*/
2405/*-----------------------------------
2406  create_string_copy - copy stirng
2407-----------------------------------*/
19542408
1955static char * CreateStringCopy(char * buf)
2409static char *create_string_copy(char *buf)
19562410{
1957   char   * temp = NULL;
2411   char *temp = NULL;
19582412
19592413   if(buf)
19602414   {
1961      size_t   length = strlen(buf) + 1;
2415      /* allocate memory */
2416      size_t length = strlen(buf) + 1;
2417      temp = malloc_or_die(length);
19622418
1963      temp = malloc(length);
1964
2419      /* copy memory for string */
19652420      if(temp)
19662421         memcpy(temp, buf, length);
19672422   }
r2762r2763
19692424   return temp;
19702425}
19712426
1972/*------------------------------------------------------------
1973  UserSelectValueMenu - management for value-selection menu
1974------------------------------------------------------------*/
2427/*--------------------------------------------------
2428  old_style_menu - export menu items to draw menu
2429--------------------------------------------------*/
19752430
1976static INT32 UserSelectValueMenu(running_machine *machine, int selection, CheatEntry * entry)
2431static void old_style_menu(const char **items, const char **sub_items, char *flag, int selected, int arrowize_subitem)
19772432{
1978   char               buf[2048];
1979   int                  sel;
1980   CheatAction            * action;
1981   static INT32         value = -1;
1982   static int            firstTime = 1;
1983   int                  delta = 0;
1984   int                  displayValue;
1985   int                  keyValue;
1986   int                  forceUpdate = 0;
2433   int menu_items;
2434   static ui_menu_item item_list[1000];
19872435
1988   sel =      selection - 1;
2436   for(menu_items = 0; items[menu_items]; menu_items++)
2437   {
2438      item_list[menu_items].text = items[menu_items];
2439      item_list[menu_items].subtext = sub_items ? sub_items[menu_items] : NULL;
2440      item_list[menu_items].flags = 0;
19892441
1990   action = &entry->actionList[0];
2442      /* set a highlight for sub-item */
2443      if(flag && flag[menu_items])
2444         item_list[menu_items].flags |= MENU_FLAG_INVERT;
19912445
1992   /* ----- if we're just entering, save the value ----- */
1993   if(firstTime)
2446      /* set an arrow for sub-item */
2447      if(menu_items == selected)
2448      {
2449         if (arrowize_subitem & 1)
2450            item_list[menu_items].flags |= MENU_FLAG_LEFT_ARROW;
2451         if (arrowize_subitem & 2)
2452            item_list[menu_items].flags |= MENU_FLAG_RIGHT_ARROW;
2453      }
2454   }
2455
2456   visible_items = ui_menu_draw(item_list, menu_items, selected, NULL);
2457}
2458
2459/*-------------------------------------------------------
2460  init_cheat_menu_stack - initilalize cheat menu stack
2461-------------------------------------------------------*/
2462
2463static void init_cheat_menu_stack(void)
2464{
2465   cheat_menu_stack *menu = &menu_stack[stack_index = 0];
2466
2467   menu->handler = cheat_main_menu;
2468   menu->sel = 0;
2469   menu->pre_sel = 0;
2470   menu->first_time = 1;
2471}
2472
2473/*-----------------------------------------------------
2474  cheat_menu_stack_push - push a menu onto the stack
2475-----------------------------------------------------*/
2476
2477static void cheat_menu_stack_push(cheat_menu_handler new_handler, cheat_menu_handler ret_handler, int selection)
2478{
2479   cheat_menu_stack *menu = &menu_stack[++stack_index];
2480
2481   assert(stack_index < CHEAT_MENU_DEPTH);
2482
2483   menu->handler = new_handler;
2484   menu->return_handler = ret_handler;
2485   menu->sel = 0;
2486   menu->pre_sel = selection;
2487   menu->first_time = 1;
2488   editActive = 0;
2489}
2490
2491/*---------------------------------------------------
2492  cheat_menu_stack_pop - pop a menu from the stack
2493---------------------------------------------------*/
2494
2495static void cheat_menu_stack_pop(void)
2496{
2497   int i;
2498
2499   assert(stack_index > 0);
2500
2501   /* NOTE : cheat menu supports deep-return */
2502   for(i = stack_index; i > 0; i--)
2503      if(menu_stack[stack_index].return_handler == menu_stack[i].handler)
2504         break;
2505
2506   stack_index = i;
2507}
2508
2509/*-----------------------------------------------------
2510  free_cheat_menu_stack - reset the cheat menu stack
2511-----------------------------------------------------*/
2512
2513static void free_cheat_menu_stack(void)
2514{
2515   int i;
2516   cheat_menu_stack *menu;
2517
2518   for(i = 0; i < CHEAT_MENU_DEPTH; i++)
19942519   {
1995      UINT32   min = EXTRACT_FIELD(action->type, UserSelectMinimum);
1996      UINT32   max = action->originalDataField + min;
2520      menu = &menu_stack[i];
19972521
1998      value = ReadData(action);
2522      menu->handler = NULL;
2523      menu->return_handler = NULL;
2524      menu->pre_sel = 0;
2525      menu->first_time = 0;
2526   }
19992527
2000      /* ----- and check for valid BCD values ----- */
2001      if(TEST_FIELD(action->type, UserSelectBCD))
2528   stack_index = 0;
2529}
2530
2531/*---------------------------------------------------------------
2532  user_select_value_menu - management for value-selection menu
2533---------------------------------------------------------------*/
2534
2535static int user_select_value_menu(running_machine *machine, cheat_menu_stack *menu)
2536{
2537   int            i;
2538   UINT8         isBCD;
2539   UINT32         min;
2540   UINT32         max;
2541   static int      master         = 0;
2542   static int      displayValue   = -1;
2543   char         buf[256];
2544   char *         stringsBuf      = buf;
2545   CheatEntry *   entry         = &cheatList[menu->pre_sel];
2546   CheatAction *   action         = NULL;
2547
2548   /* first setting 1 : search master code of value-selection */
2549   if(menu->first_time)
2550   {
2551      for(i = 0; i < entry->actionListLength; i++)
20022552      {
2003         value = BCDToDecimal(value);
2004         value = DecimalToBCD(value);
2553         /* get value selection master code */
2554         if(   EXTRACT_FIELD(entry->actionList[i].type, CodeType) == kCodeType_VWrite ||
2555            EXTRACT_FIELD(entry->actionList[i].type, CodeType) == kCodeType_VRWrite)
2556         {
2557            master = i;
2558            break;
2559         }
20052560      }
2561   }
20062562
2007      if(value < min)
2008         value = max;
2009      if(value > max)
2010         value = min;
2563   action = &entry->actionList[master];
20112564
2012      action->data = value;
2013      firstTime = 0;
2014   }
2565   if(TEST_FIELD(action->type, ValueSelectMinimumDisplay) || TEST_FIELD(action->type, ValueSelectMinimum))
2566      min = 1;
2567   else
2568      min = 0;
20152569
2016   displayValue = value;
2570   max      = action->originalDataField + min;
2571   isBCD   = EXTRACT_FIELD(action->type, ValueSelectBCD);
20172572
2018   /* ----- if the minimum display value is one, add one to the display value ----- */
2019   if(TEST_FIELD(action->type, UserSelectMinimumDisplay))
2573   /* first setting 2 : save the value */
2574   if(menu->first_time)
20202575   {
2021      if(TEST_FIELD(action->type, UserSelectBCD))
2022         displayValue = BCDToDecimal(displayValue);         // bcd -> dec
2576      displayValue = isBCD ? DecimalToBCD(BCDToDecimal(ReadData(action))) : ReadData(action);
20232577
2024      displayValue++;
2578      if(displayValue < min)
2579         displayValue = min;
2580      else if(displayValue > max)
2581         displayValue = max;
2582      else if(TEST_FIELD(action->type, ValueSelectMinimumDisplay))
2583         displayValue++;
20252584
2026      if(TEST_FIELD(action->type, UserSelectBCD))
2027         displayValue = DecimalToBCD(displayValue);         // dec -> bcd
2585      menu->first_time = 0;
20282586   }
20292587
2030   /* ----- print it ----- */
2031   if(TEST_FIELD(action->type, UserSelectBCD))
2032      sprintf(buf, "\tSelect a value\n\t%.2X\n", displayValue);
2588   /* ##### MENU CONSTRACTION ##### */
2589   stringsBuf += sprintf(stringsBuf, "\t%s\n\t", entry->name);
2590
2591   if(editActive)
2592   {
2593      for(i = kSearchByteDigitsTable[EXTRACT_FIELD(action->type, AddressSize)] - 1; i >= 0; i--)
2594      {
2595         if(i == editCursor)
2596            stringsBuf += sprintf(stringsBuf, "[%X]", (displayValue & kIncrementMaskTable[i]) / kIncrementValueTable[i]);
2597         else
2598            stringsBuf += sprintf(stringsBuf, "%X", (displayValue & kIncrementMaskTable[i]) / kIncrementValueTable[i]);
2599      }
2600   }
20332601   else
2034      sprintf(buf, "\tSelect a value\n\t%.2X (%d)\n", displayValue, displayValue);
2602      stringsBuf += sprintf(stringsBuf, "%.*X", kSearchByteDigitsTable[EXTRACT_FIELD(action->type, AddressSize)], displayValue);
20352603
2036   /* ----- create fake menu strings ----- */
2037   strcat(buf, "\t OK ");
2604   if(TEST_FIELD(action->type, ValueSelectNegative))
2605      stringsBuf += sprintf(   stringsBuf, " <%.*X>",
2606                        kSearchByteDigitsTable[EXTRACT_FIELD(action->type, AddressSize)],
2607                        (~displayValue + 1) & kSearchByteMaskTable[EXTRACT_FIELD(action->type, AddressSize)]);
20382608
2039   /* ----- print it ----- */
2609   if(!isBCD)
2610      stringsBuf += sprintf(stringsBuf, " (%d)", displayValue);
2611
2612   stringsBuf += sprintf(stringsBuf, "\n\t OK ");
2613
2614   /* print it */
20402615   ui_draw_message_window(buf);
20412616
20422617   /********** KEY HANDLING **********/
2043   if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
2044      delta = -1;
2618   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kHorizontalFastKeyRepeatRate))
2619   {
2620      if(editActive)
2621      {
2622         if(displayValue == max)
2623            displayValue = min;
2624         else
2625         {
2626            displayValue = isBCD ? DoIncrementDecField(displayValue, editCursor) : DoIncrementHexField(displayValue, editCursor);
20452627
2046   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
2047      delta = 1;
2048
2049   if(input_ui_pressed(machine, IPT_UI_SELECT))
2628            if(displayValue > max)
2629               displayValue = max;
2630         }
2631      }
2632   }
2633   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kHorizontalFastKeyRepeatRate))
20502634   {
2051      /* ### redundant?? probably can be removed ### */
2052      if(!firstTime)
2635      if(editActive)
20532636      {
2054         int   i;
2637         if(displayValue == min)
2638            displayValue = max;
20552639
2056         /* ----- copy data field if copy previous value ----- */
2057         for(i = 0; i < entry->actionListLength; i++)
2640         else
20582641         {
2059            CheatAction   * traverse = &entry->actionList[i];
2642            displayValue = isBCD ? DoDecrementDecField(displayValue, editCursor) : DoDecrementHexField(displayValue, editCursor);
20602643
2061            INT32   copyValue = value;
2644            if(displayValue > max)
2645               displayValue = max;
2646         }
2647      }
2648   }
2649   else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
2650   {
2651      if(editActive)
2652      {
2653         if(++editCursor > kSearchByteDigitsTable[EXTRACT_FIELD(action->type, AddressSize)] - 1)
2654            editCursor = 0;
2655      }
2656      else
2657      {
2658         if(displayValue-- == min)
2659            displayValue = max;
20622660
2063            if(TEST_FIELD(traverse->type, LinkEnable) && TEST_FIELD(traverse->type, LinkCopyPreviousValue))
2064            {
2065               INT32 newData = traverse->originalDataField;
2661         if(isBCD)
2662            displayValue = DecimalToBCD(BCDToDecimal(displayValue));
2663      }
2664   }
2665   else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
2666   {
2667      if(editActive)
2668      {
2669         if(--editCursor < 0)
2670            editCursor = kSearchByteDigitsTable[EXTRACT_FIELD(action->type, AddressSize)] - 1;
2671      }
2672      else
2673      {
2674         if(++displayValue > max)
2675            displayValue = min;
20662676
2067               if(TEST_FIELD(traverse->type, UserSelectBCD))
2068               {
2069                  copyValue = BCDToDecimal(value);
2070                  copyValue = DecimalToBCD(value);
2677         if(isBCD)
2678            displayValue = DecimalToBCD(BCDToDecimal(displayValue));
2679      }
2680   }
2681   else if(input_ui_pressed(machine, IPT_UI_SELECT))
2682   {
2683      int i;
20712684
2072                  newData = BCDToDecimal(newData);
2073                  newData = DecimalToBCD(newData);
2074               }
2685      if(editActive)
2686         editActive = 0;
20752687
2076               copyValue += newData;
2688      /* adjust a value */
2689      if(TEST_FIELD(action->type, ValueSelectMinimumDisplay))
2690         displayValue--;
20772691
2078               if(TEST_FIELD(traverse->type, UserSelectBCD))
2079               {
2080                  copyValue = BCDToDecimal(copyValue);
2081                  copyValue = DecimalToBCD(copyValue);
2082               }
2692      if(TEST_FIELD(action->type, ValueSelectMinimum) && !displayValue)
2693         displayValue = 1;
2694
2695      if(TEST_FIELD(action->type, ValueSelectNegative) && displayValue)
2696         displayValue = (~displayValue + 1) & kSearchByteMaskTable[EXTRACT_FIELD(action->type, AddressSize)];
2697
2698      /* copy value */
2699      for(i = 0; i < entry->actionListLength; i++)
2700      {
2701         CheatAction * destination = &entry->actionList[i];
2702
2703         int copyValue = displayValue;
2704
2705         if(   EXTRACT_FIELD(destination->type, CodeType) == kCodeType_VWrite ||
2706            EXTRACT_FIELD(destination->type, CodeType) == kCodeType_VRWrite)
2707         {
2708            destination->data = displayValue;
2709         }
2710         else if(EXTRACT_FIELD(destination->type, Link) == kLink_CopyLink)
2711         {
2712            int newData = destination->originalDataField;
2713
2714            if(TEST_FIELD(destination->type, LinkValueSelectBCD))
2715            {
2716               copyValue   = BCDToDecimal(DecimalToBCD(copyValue));
2717               newData      = BCDToDecimal(DecimalToBCD(newData));
20832718            }
20842719
2085            if(!i || TEST_FIELD(traverse->type, LinkCopyPreviousValue))
2086               traverse->data = copyValue;
2720            copyValue += newData;
2721
2722            if(TEST_FIELD(destination->type, LinkValueSelectBCD))
2723               copyValue = DecimalToBCD(BCDToDecimal(copyValue));
2724
2725            if(TEST_FIELD(destination->type, LinkValueSelectNegative))
2726               copyValue = (~copyValue + 1) & kSearchByteMaskTable[EXTRACT_FIELD(destination->type, AddressSize)];
2727
2728            destination->data = copyValue;
20872729         }
2088
2089         ActivateCheat(entry);
20902730      }
20912731
2092      firstTime = 1;
2093      sel = -1;
2732      ActivateCheat(entry);
2733
2734      menu->sel = -1;
20942735   }
2736   else if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT))
2737   {
2738      editActive ^= 1;
2739      editCursor = 0;
2740   }
2741   else if(input_ui_pressed(machine, IPT_UI_CANCEL))
2742   {
2743      if(editActive)
2744         editActive = 0;
2745      else
2746         menu->sel = -1;
2747   }
20952748
2096   if(input_ui_pressed(machine, IPT_UI_CANCEL))
2749   /* ##### EDIT ##### */
2750   if(!editActive)
20972751   {
2098      firstTime = 1;
2099      sel = -1;
2752      UINT32 temp;
2753
2754      temp         = displayValue;
2755      displayValue   = do_edit_hex_field(machine, displayValue) & kCheatSizeMaskTable[EXTRACT_FIELD(action->type, AddressSize)];
2756
2757      if(displayValue != temp)
2758      {
2759         if(isBCD)
2760            displayValue = DecimalToBCD(BCDToDecimal(displayValue));
2761
2762         if(displayValue < min)   displayValue = max;
2763         if(displayValue > max)   displayValue = min;
2764      }
21002765   }
21012766
2102   /* ----- get other key inputs ----- */
2103   keyValue = ReadHexInput();
2767   return menu->sel + 1;
2768}
21042769
2105   /* ----- BCD check for input key ----- */
2106   if((keyValue != -1) && TEST_FIELD(action->type, UserSelectBCD) && ((keyValue < 0 ) || (keyValue > 9)))
2107      keyValue = -1;
2770/*------------------------------------------------------------
2771  user_select_label_menu - management for label-select menu
2772------------------------------------------------------------*/
21082773
2109   /* ----- if we got a key ----- */
2110   if(keyValue != -1)
2774static int user_select_label_menu(running_machine *machine, cheat_menu_stack *menu)
2775{
2776   int            i;
2777   UINT8         total   = 0;
2778   const char      ** menuItem;
2779   char         ** buf;
2780   CheatEntry      * entry   = &cheatList[menu->pre_sel];
2781
2782   /* required items = (total items + return + terminator) & (strings buf * total items [max chars = 100]) */
2783   request_strings(entry->actionListLength + 2, entry->actionListLength, 100, 0);
2784   menuItem   = menu_strings.main_list;
2785   buf         = menu_strings.main_strings;
2786
2787   /* first setting : compute cursor position from previous menu */
2788   if(menu->first_time)
21112789   {
2112      /* ----- add it ----- */
2113      value <<= 4;
2790      menu->sel = entry->flags & kCheatFlag_OneShot ? entry->selection - 1 : entry->selection;
2791      menu->first_time = 0;
2792   }
21142793
2115      switch(EXTRACT_FIELD(action->type, BytesUsed))
2794   /********** MENU CONSTRUCTION **********/
2795   for(i = 0; i < entry->labelIndexLength; i++)
2796   {
2797      if(!i)
21162798      {
2117         case 0: // 8 bit
2118            value &= 0xF0;
2119            break;
2120         case 1: // 16 bit
2121            value &= 0xFFF0;
2122            break;
2123         case 2: // 24 bit
2124            value &= 0xFFFFF0;
2125            break;
2126         case 3: // 32 bit
2127            value &= 0xFFFFFFF0;
2128            break;
2799         if(!(entry->flags & kCheatFlag_OneShot))
2800         {
2801            /* add "OFF" item if not one shot at the first time */
2802            if(!entry->selection)
2803               sprintf(buf[total], "[ Off ]");
2804            else
2805               sprintf(buf[total], "Off");
2806
2807            menuItem[total] = buf[total];
2808            total++;
2809         }
2810
2811         continue;
21292812      }
2813      else if(i == entry->selection)
2814         sprintf(buf[total], "[ %s ]", entry->actionList[entry->labelIndex[i]].optionalName);
2815      else
2816         sprintf(buf[total], "%s", entry->actionList[entry->labelIndex[i]].optionalName);
21302817
2131      value |= keyValue & 0x0F;
2132
2133      delta = 0;
2134      forceUpdate = 1;
2818      menuItem[total] = buf[total];
2819      total++;
21352820   }
21362821
2137   /* ----- wrap-around with BCD stuff. ### this is a really bad way to do this ----- */
2138   if(delta || forceUpdate)
2139   {
2140      INT32   min = EXTRACT_FIELD(action->type, UserSelectMinimum);
2141      INT32   max = action->originalDataField + min;
2822   /* ##### RETURN ##### */
2823   menuItem[total++] = "Return to Prior Menu";
21422824
2143      if(TEST_FIELD(action->type, UserSelectBCD))
2144         value = BCDToDecimal(value);
2825   /* ##### TERMINATE ARRAY ##### */
2826   menuItem[total] = NULL;
21452827
2146      value += delta;
2828   /* adjust current cursor position */
2829   ADJUST_CURSOR(menu->sel, total)
21472830
2148      if(TEST_FIELD(action->type, UserSelectBCD))
2149         value = DecimalToBCD(value);
2831   /* draw it */
2832   old_style_menu(menuItem, NULL, NULL, menu->sel, 0);
21502833
2151      if(value < min)
2152         value = max;
2153      if(value > max)
2154         value = min;
2834   /********** KEY HANDLING **********/
2835   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
2836   {
2837      CURSOR_TO_PREVIOUS(menu->sel, total)
21552838   }
2839   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
2840   {
2841      CURSOR_TO_NEXT(menu->sel, total)
2842   }
2843   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
2844   {
2845      CURSOR_PAGE_UP(menu->sel);
2846   }
2847   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
2848   {
2849      CURSOR_PAGE_DOWN(menu->sel, total)
2850   }
2851   else if(input_ui_pressed(machine, IPT_UI_SELECT))
2852   {
2853      if(menu->sel != total - 1)
2854      {
2855         entry->selection = entry->flags & kCheatFlag_OneShot ? menu->sel + 1 : menu->sel;
21562856
2157   return sel + 1;
2857         /* set new label index */
2858         if(entry->selection)
2859            ActivateCheat(entry);
2860         else
2861            DeactivateCheat(entry);
2862
2863         /* NOTE : the index number of master code should be stored into 1st table */
2864         if(TEST_FIELD(entry->actionList[entry->labelIndex[0]].type, LabelSelectQuickClose))
2865            menu->sel = -1;
2866      }
2867      else
2868         menu->sel = -1;
2869   }
2870   else if(input_ui_pressed(machine, IPT_UI_CANCEL))
2871      menu->sel = -1;
2872
2873   return menu->sel + 1;
21582874}
21592875
2160/*-------------------------------------------------
2161  CommentMenu - management comment for code menu
2162-------------------------------------------------*/
2876/*------------------------------------------------
2877  comment_menu - management simple comment menu
2878------------------------------------------------*/
21632879
2164static INT32 CommentMenu(running_machine *machine, int selection, CheatEntry * entry)
2880static int comment_menu(running_machine *machine, cheat_menu_stack *menu)
21652881{
2166   char   buf[2048];
2167   int      sel;
2882   char      buf[2048];
21682883   const char   * comment;
2884   CheatEntry   * entry = &cheatList[menu->pre_sel];
21692885
2170   if(!entry)
2171      return 0;
2886   /* first setting : NONE */
2887   if(menu->first_time)
2888      menu->first_time = 0;
21722889
2173   sel = selection - 1;
2174
21752890   /********** MENU CONSTRUCTION **********/
21762891   if(entry->comment && entry->comment[0])
21772892      comment = entry->comment;
21782893   else
2179      comment = "(none)";
2894      comment = "this code doesn't have a comment";
21802895
21812896   sprintf(buf, "%s\n\t OK ", comment);
21822897
2183   /* ----- print it ----- */
2898   /* print it */
21842899   ui_draw_message_window(buf);
21852900
21862901   /********** KEY HANDLING **********/
21872902   if(input_ui_pressed(machine, IPT_UI_SELECT) || input_ui_pressed(machine, IPT_UI_CANCEL))
2188      sel = -1;
2903      menu->sel = -1;
21892904
2190   return sel + 1;
2905   return menu->sel + 1;
21912906}
21922907
2193/*--------------------------------------------------------------
2194  EnableDisableCheatMenu - management for Enable/Disable menu
2195--------------------------------------------------------------*/
2908/*-----------------------------------------------------------
2909  extend_comment_menu - management multi-line comment menu
2910-----------------------------------------------------------*/
21962911
2197static int EnableDisableCheatMenu(running_machine *machine, int selection, int firstTime)
2912static int extend_comment_menu(running_machine *machine, cheat_menu_stack *menu)
21982913{
2199   INT32         sel;
2200   static INT32   submenu_choice = 0;
2201   static INT32   submenu_id = 0;      // 0 = none, 1 = comment, 2 = value-selection, 3 = editCheat
2202   const char      ** menu_item;
2203   const char      ** menu_subitem;
2204   char         * flagBuf;
2205   INT32         i;
2206   INT32         total = 0;
2914   int         i;
2915   UINT8      total   = 0;
2916   const char   ** menuItem;
2917   char      ** buf;
2918   CheatEntry   * entry   = &cheatList[menu->pre_sel];
22072919
2208   CheatEntry      * entry;
2920   if(!entry->actionListLength)
2921      return 0;
22092922
2210   RequestStrings(cheatListLength + 5, 0, 0, 0);
2923   /* first setting : NONE */
2924   if(menu->first_time)
2925      menu->first_time = 0;
22112926
2212   menu_item = menuStrings.mainList;
2213   menu_subitem = menuStrings.subList;
2214   flagBuf = menuStrings.flagList;
2927   /* required items = (display comment lines + return + terminator) & (strings buf * display comment lines [max char = 100]) */
2928   request_strings(entry->actionListLength + 1, entry->actionListLength - 1, 100, 0);
2929   menuItem    = menu_strings.main_list;
2930   buf         = menu_strings.main_strings;
22152931
2216   sel = selection - 1;
2932   /********** MENU CONSTRUCTION **********/
2933   for(i = 1; i < entry->actionListLength; i++)
2934   {
2935      CheatAction * action = &entry->actionList[i];
22172936
2218   /********** SUB MENU **********/
2219   if(submenu_choice)
2937      /* NOTE : don't display the comment in master code */
2938      if(i)
2939      {
2940         sprintf(buf[total], "%s", action->optionalName);
2941         menuItem[total] = buf[total];
2942         total++;
2943      }
2944   }
2945
2946   /* ##### OK ##### */
2947   menuItem[total++] = "OK";
2948
2949   /* ##### TERMINATE ARRAY ##### */
2950   menuItem[total] = NULL;
2951
2952   /* adjust cursor position */
2953   ADJUST_CURSOR(menu->sel, total)
2954
2955   /* draw it */
2956   old_style_menu(menuItem, NULL, NULL, menu->sel, 0);
2957
2958   /********** KEY HANDLING **********/
2959   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
22202960   {
2221      switch(submenu_id)
2961      CURSOR_TO_PREVIOUS(menu->sel, total)
2962   }
2963   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
2964   {
2965      CURSOR_TO_NEXT(menu->sel, total)
2966   }
2967   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
2968   {
2969      CURSOR_PAGE_UP(menu->sel)
2970   }
2971   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
2972   {
2973      CURSOR_PAGE_DOWN(menu->sel, total)
2974   }
2975   else if(input_ui_pressed(machine, IPT_UI_SELECT) || input_ui_pressed(machine, IPT_UI_CANCEL))
2976      menu->sel = -1;
2977
2978   return menu->sel + 1;
2979}
2980
2981/*------------------------------------------------------
2982  cheat_main_menu - management for cheat general menu
2983------------------------------------------------------*/
2984
2985static int cheat_main_menu(running_machine *machine, cheat_menu_stack *menu)
2986{
2987   enum
2988   {
2989      kMenu_EnableDisable = 0,
2990      kMenu_AddEdit,
2991      kMenu_Search,
2992      kMenu_ViewResult,
2993      kMenu_ChooseWatch,
2994      kMenu_Options,
2995#ifdef MAME_DEBUG
2996      kMenu_Debug,
2997#endif
2998      kMenu_Return,
2999      kMenu_Max
3000   };
3001
3002   UINT8         total      = 0;
3003   ui_menu_item   menu_item[kMenu_Max + 1];
3004
3005   /* allocate memory for item list */
3006   memset(menu_item, 0, sizeof(menu_item));
3007
3008   /* first setting : NONE */
3009   if(menu->first_time)
3010      menu->first_time = 0;
3011
3012   /********** MENU CONSTRUCION **********/
3013   /* ##### Enable/Disable a Cheat ##### */
3014   menu_item[total++].text = "Enable/Disable a Cheat";
3015
3016   /* ##### Add/Edit a Cheat ##### */
3017   menu_item[total++].text = "Add/Edit a Cheat";
3018
3019   /* ##### Search a Cheat ##### */
3020   switch(EXTRACT_FIELD(cheatOptions, SearchBox))
3021   {
3022      case kSearchBox_Minimum:
3023         menu_item[total++].text = "Search a Cheat (Minimum Mode)";
3024         break;
3025
3026      case kSearchBox_Standard:
3027         menu_item[total++].text = "Search a Cheat (Standard Mode)";
3028         break;
3029
3030      case kSearchBox_Advanced:
3031         menu_item[total++].text = "Search a Cheat (Advanced Mode)";
3032         break;
3033
3034      default:
3035         menu_item[total++].text = "Unknown Search Menu";
3036   }
3037
3038   /* ##### View Last Result ##### */
3039   menu_item[total++].text = "View Last Results";
3040
3041   /* ##### Configure Watchpoints ##### */
3042   menu_item[total++].text = "Configure Watchpoints";
3043
3044   /* ##### Options ##### */
3045   menu_item[total++].text = "Options";
3046
3047#ifdef MAME_DEBUG
3048   /* ##### Debug  ##### */
3049   menu_item[total++].text = "Debug Viewer";
3050#endif
3051
3052   /* ##### Return to the MAME general menu ##### */
3053   menu_item[total++].text = "Return to Main Menu";
3054
3055   /* ##### Terminate Array ##### */
3056   menu_item[total].text = NULL;
3057
3058   ADJUST_CURSOR(menu->sel, total)
3059
3060   /* print it */
3061   ui_menu_draw(menu_item, total, menu->sel, NULL);
3062
3063   /********** KEY HANDLING **********/
3064   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
3065   {
3066      CURSOR_TO_PREVIOUS(menu->sel, total)
3067   }
3068   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
3069   {
3070      CURSOR_TO_NEXT(menu->sel, total)
3071   }
3072   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
3073   {
3074      CURSOR_PAGE_UP(menu->sel)
3075   }
3076   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
3077   {
3078      CURSOR_PAGE_DOWN(menu->sel, total)
3079   }
3080   else if(input_ui_pressed(machine, IPT_UI_SELECT))
3081   {
3082      switch(menu->sel)
22223083      {
2223         case 1:
2224            submenu_choice = CommentMenu(machine, submenu_choice, &cheatList[sel]);
3084         case kMenu_EnableDisable:
3085            cheat_menu_stack_push(enable_disable_cheat_menu, cheat_main_menu, menu->sel);
22253086            break;
22263087
2227         case 2:
2228            submenu_choice = UserSelectValueMenu(machine, submenu_choice, &cheatList[sel]);
3088         case kMenu_AddEdit:
3089            cheat_menu_stack_push(add_edit_cheat_menu, cheat_main_menu, 0);
22293090            break;
22303091
2231         case 3:
2232            submenu_choice = EditCheatMenu(machine, &cheatList[sel], sel, submenu_choice);
3092         case kMenu_Search:
3093            switch(EXTRACT_FIELD(cheatOptions, SearchBox))
3094            {
3095               case kSearchBox_Minimum:
3096                  cheat_menu_stack_push(search_minimum_menu, menu->handler, menu->sel);
3097                  break;
3098
3099               case kSearchBox_Standard:
3100                  cheat_menu_stack_push(search_standard_menu, menu->handler, menu->sel);
3101                  break;
3102
3103               case kSearchBox_Advanced:
3104                  cheat_menu_stack_push(search_advanced_menu, menu->handler, menu->sel);
3105            }
22333106            break;
22343107
2235         default:
2236            submenu_choice = 0;
3108         case kMenu_ViewResult:
3109            cheat_menu_stack_push(view_search_result_menu, menu->handler, menu->sel);
3110            break;
3111
3112         case kMenu_ChooseWatch:
3113            cheat_menu_stack_push(choose_watch_menu, menu->handler, menu->sel);
3114            break;
3115
3116         case kMenu_Options:
3117            cheat_menu_stack_push(select_option_menu, menu->handler, menu->sel);
3118            break;
3119
3120#ifdef MAME_DEBUG
3121         case kMenu_Debug:
3122            cheat_menu_stack_push(debug_cheat_menu, menu->handler, menu->sel);
3123            break;
3124#endif
3125         case kMenu_Return:
3126            menu->sel = -1;
22373127      }
3128   }
3129   else if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT))
3130   {
3131      ReloadCheatDatabase(machine);
3132   }
3133   else if(input_ui_pressed(machine, IPT_UI_CANCEL))
3134   {
3135      menu->sel = -1;
3136   }
22383137
2239      /* ----- meaningless ? because no longer return with sel = -1 (pressed UI_CONFIG in submenu) ----- */
2240//      if(submenu_choice == -1)
2241//      {
2242//          submenu_choice = 0;
2243//          sel = -2;
2244//      }
3138   return menu->sel + 1;
3139}
22453140
2246      return sel + 1;
3141/*-----------------------------------------------------------------
3142  enable_disable_cheat_menu - management for Enable/Disable menu
3143-----------------------------------------------------------------*/
3144
3145static int enable_disable_cheat_menu(running_machine *machine, cheat_menu_stack *menu)
3146{
3147   int            i;
3148   UINT8         total         = 0;
3149   UINT8         length         = cheatListLength ? cheatListLength : 2;
3150   UINT8         isEmpty         = 0;
3151   UINT8 *         menuIndex;
3152   static INT8      currentLayer;
3153   const char      ** menu_item;
3154   const char      ** menu_subitem;
3155   char         * flagBuf;
3156   CheatEntry      * entry;
3157
3158   /* first setting : always starts with root layer level */
3159   if(menu->first_time)
3160   {
3161      currentLayer = 0;
3162      menu->first_time = 0;
22473163   }
22483164
3165   /* required items = total codes + return + terminator */
3166   request_strings(length + 2, 0, 0, 0);
3167
3168   menu_item      = menu_strings.main_list;
3169   menu_subitem   = menu_strings.sub_list;
3170   flagBuf         = menu_strings.flag_list;
3171
3172   menuIndex = malloc_or_die(sizeof(INT8) * (length + 1));
3173   memset(menuIndex, 0, sizeof(INT8) * (length + 1));
3174
22493175   /********** MENU CONSTRUCTION **********/
22503176   for(i = 0; i < cheatListLength; i++)
22513177   {
2252      CheatEntry   * traverse = &cheatList[i];
3178      CheatEntry * traverse   = &cheatList[i];
22533179
2254      /* ----- get code title ----- */
2255      if(traverse->name)
2256         menu_item[total] = traverse->name;
2257      else
2258         menu_item[total] = "null name";
3180      if(total >= fullMenuPageHeight) break;
22593181
2260      menu_subitem[total] = NULL;
2261
2262      /* ----- get subitem ----- */
2263      if(traverse->flags & kCheatFlag_Select)         // label-selection gets sub-lebel name or "OFF"
3182      /* when return to previous layer, set cursor position to previous layer label code */
3183      if(traverse->flags & kCheatFlag_LayerSelected)
22643184      {
2265         /* ----- no "OFF" item if one shot ----- */
2266         if((traverse->flags & kCheatFlag_OneShot) && !traverse->selection)
2267            traverse->selection = 1;               // adjust to 1st linked-code
3185         menu->sel = total;
3186         traverse->flags &= ~kCheatFlag_LayerSelected;
3187      }
22683188
2269         /* ----- set sub-label name or "OFF" to subitem ----- */
2270         if(traverse->selection && (traverse->selection < traverse->actionListLength))
2271            menu_subitem[total] = traverse->actionList[traverse->selection].optionalName;
2272         else
2273            menu_subitem[total] = "Off";
2274      }
2275      else                     // others get "ON" or "OFF"
3189      if(traverse->layerIndex == currentLayer)
22763190      {
2277         /* ----- add subitems for all cheats that are not comments ----- */
2278         if(!(traverse->flags & kCheatFlag_Null))
3191         /* ##### SEPARAOTR ##### */
3192         if(traverse->flags & kCheatFlag_Separator)
22793193         {
2280            if(traverse->flags & kCheatFlag_OneShot)
2281               menu_subitem[total] = "Set";
3194            menu_item[total] = MENU_SEPARATOR_ITEM;
3195            menu_subitem[total] = NULL;
3196            menuIndex[total++] = i;
3197         }
3198         else
3199         {
3200            /* ##### NAME ##### */
3201            if(traverse->name)
3202               menu_item[total] = traverse->name;
22823203            else
3204               menu_item[total] = "null name";
3205
3206            /* ##### SUB ITEM ##### */
3207            if(traverse->flags & kCheatFlag_HasWrongCode)
22833208            {
2284               if(traverse->flags & kCheatFlag_Active)
3209               /* "LOCKED" if wrong code */
3210               menu_subitem[total] = "Locked";
3211               traverse->selection = 0;
3212            }
3213            else if(traverse->flags & kCheatFlag_Select)
3214            {
3215               /* label or "OFF" if label-selection though one-shot should ignore "OFF" */
3216               if(traverse->selection)
3217                  menu_subitem[total] = traverse->actionList[traverse->labelIndex[traverse->selection]].optionalName;
3218               else
3219                  menu_subitem[total] = "Off";
3220            }
3221            else if(traverse->flags & kCheatFlag_ExtendComment)
3222            {
3223               /* "READ" if extend comment code */
3224               menu_subitem[total] = "Read";
3225            }
3226            else if(traverse->flags & kCheatFlag_LayerIndex)
3227            {
3228               /* ">>>" (next layer) if layer label code */
3229               menu_subitem[total] = ">>>";
3230            }
3231            else if(!(traverse->flags & kCheatFlag_Null))
3232            {
3233               /* otherwise, add sub-items */
3234               if(traverse->flags & kCheatFlag_OneShot)
3235                  menu_subitem[total] = "Set";
3236               else if(traverse->flags & kCheatFlag_Active)
22853237                  menu_subitem[total] = "On";
22863238               else
22873239                  menu_subitem[total] = "Off";
22883240            }
3241
3242            /* set highlight flag if comment is set */
3243            if(traverse->comment && traverse->comment[0])
3244               flagBuf[total] = 1;
3245            else
3246               flagBuf[total] = 0;
3247            menuIndex[total++] = i;
22893248         }
22903249      }
2291
2292      /* ----- get comment flag ----- */
2293      if(traverse->comment && traverse->comment[0])
2294         flagBuf[total++] = 1;
2295      else
2296         flagBuf[total++] = 0;
3250      else if(traverse->flags & kCheatFlag_LayerIndex)
3251      {
3252         if(currentLayer == traverse->actionList[0].data)
3253         {
3254            /* specified handling previous layer label code with "<<<" (previous layer) */
3255            if(traverse->comment)
3256               menu_item[total] = traverse->comment;
3257            else
3258               menu_item[total] = "Return to Prior Layer";
3259            menu_subitem[total] = "<<<";
3260            flagBuf[total] = 0;
3261            menuIndex[total++] = i;
3262         }
3263      }
22973264   }
22983265
2299   /* ----- if no code, set special message ----- */
2300   if(cheatListLength == 0)
3266   /* if no code, set special message */
3267   if(!cheatListLength)
23013268   {
2302      if(foundCheatDatabase)         // the database found but no code
3269      if(foundCheatDatabase)
23033270      {
2304         menu_item[total] = "there are no cheats for this game";
2305         menu_subitem[total] = NULL;
2306         flagBuf[total++] = 0;
3271         /* the database is found but no code */
3272         menu_item[total]   = "there are no cheats for this game";
3273         menu_subitem[total]   = NULL;
3274         menuIndex[total]   = total;
3275         flagBuf[total++]   = 0;
3276         isEmpty            = 1;
23073277      }
2308      else               // the database itself not found
3278      else
23093279      {
2310         menu_item[total] = "cheat database not found";
2311         menu_subitem[total] = NULL;
2312         flagBuf[total++] = 0;
3280         /* the database itself is not found */
3281         menu_item[total]   = "cheat database not found";
3282         menu_subitem[total]   = NULL;
3283         menuIndex[total]   = total;
3284         flagBuf[total++]   = 0;
23133285
2314         menu_item[total] = "unzip it and place it in the MAME directory";
2315         menu_subitem[total] = NULL;
2316         flagBuf[total++] = 0;
3286         menu_item[total]   = "unzip it and place it in the MAME directory";
3287         menu_subitem[total]   = NULL;
3288         menuIndex[total]   = total;
3289         flagBuf[total++]   = 0;
3290         isEmpty            = 2;
23173291      }
23183292   }
3293   else if(currentLayer && total == 1)
3294   {
3295      /* selected layer doesn't have code */
3296      menu_item[total]   = "selected layer doesn't have sub code";
3297      menu_subitem[total]   = NULL;
3298      menuIndex[total]   = menuIndex[total - 1];
3299      flagBuf[total++]   = 0;
3300      isEmpty = 3;
3301   }
23193302
2320   /* ----- set return item ----- */
2321   menu_item[total] = "Return to Prior Menu";
3303   /* ##### RETURN ##### */
3304   if(currentLayer)
3305      menu_item[total] = "Return to Root Layer";
3306   else
3307      menu_item[total] = "Return to Prior Menu";
23223308   menu_subitem[total] = NULL;
23233309   flagBuf[total++] = 0;
23243310
2325   menu_item[total] = 0;   // terminate array
2326   menu_subitem[total] = 0;
3311   /* ##### TERMINATE ARRAY ##### */
3312   menu_item[total] = NULL;
3313   menu_subitem[total] = NULL;
23273314   flagBuf[total] = 0;
23283315
2329   /* ----- adjust cursor position ----- */
2330   if(sel < 0)
2331      sel = 0;
2332   if(sel > (total - 1))
2333      sel = total - 1;
3316   /* adjust cursor position */
3317   switch(isEmpty)
3318   {
3319      default:
3320         ADJUST_CURSOR(menu->sel, total)
23343321
2335   /* ----- if cursor is on comment code, skip it ----- */
2336   if(cheatListLength && firstTime)
2337   {
2338      while((sel < total - 1) && (cheatList[sel].flags & kCheatFlag_Null))
2339         sel++;
3322         /* if cursor is on comment code, skip it */
3323         while(menu->sel < total - 1 && (cheatList[menuIndex[menu->sel]].flags & kCheatFlag_Null))
3324            menu->sel++;
3325         break;
3326
3327      case 1:
3328      case 2:
3329         /* no database or code, unselectable message line */
3330         menu->sel = total - 1;
3331         break;
3332
3333      case 3:
3334         /* no code in sub layer, unselectable message line */
3335         if(menu->sel == 1)
3336            menu->sel = 0;
23403337   }
23413338
2342   /* ----- draw it ----- */
2343   old_style_menu(menu_item, menu_subitem, flagBuf, sel, 0);
3339   /* draw it */
3340   old_style_menu(menu_item, menu_subitem, flagBuf, menu->sel, 3);
23443341
23453342   /********** KEY HANDLING **********/
2346   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
3343   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
23473344   {
2348      sel++;
3345      switch(isEmpty)
3346      {
3347         default:
3348            CURSOR_TO_PREVIOUS(menu->sel, total)
3349            if(cheatListLength)
3350            {
3351               /* if cursor is on comment code, skip it */
3352               for(i = 0; (i < fullMenuPageHeight / 2) && menu->sel != total - 1 && (cheatList[menuIndex[menu->sel]].flags & kCheatFlag_Null); i++)
3353               {
3354                  if(--menu->sel < 0)
3355                     menu->sel = total - 1;
3356               }
3357            }
3358            break;
23493359
2350      if(sel >= total)
2351         sel = 0;
3360         case 1:
3361            break;
23523362
2353      if(cheatListLength)
2354      {
2355         /* ----- if cursor is on comment code, skip it ----- */
2356         for(i = 0; (i < fullMenuPageHeight / 2) && (sel < total - 1) && (cheatList[sel].flags & kCheatFlag_Null); i++)
2357            sel++;
3363         case 2:
3364            if(menu->sel)
3365               menu->sel = 0;
3366            else
3367               menu->sel = 2;
23583368      }
23593369   }
2360
2361   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
3370   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
23623371   {
2363      sel--;
2364
2365      if(sel < 0)
2366         sel = total - 1;
2367      else
3372      switch(isEmpty)
23683373      {
2369         if(cheatListLength)
2370         {
2371            /* ----- if cursor is on comment code, skip it ----- */
2372            for(i = 0; (i < fullMenuPageHeight / 2) && (sel != total - 1) && (cheatList[sel].flags & kCheatFlag_Null); i++)
3374         default:
3375            CURSOR_TO_NEXT(menu->sel, total)
3376            if(cheatListLength)
23733377            {
2374               sel--;
3378               /* if cursor is on comment code, skip it */
3379               for(i = 0; (i < fullMenuPageHeight / 2) && menu->sel < total - 1 && (cheatList[menuIndex[menu->sel]].flags & kCheatFlag_Null); i++)
3380                  menu->sel++;
3381            }
23753382
2376               if(sel < 0)
2377                  sel = total - 1;
2378            }
2379         }
3383         case 1:
3384            break;
3385
3386         case 2:
3387            if(menu->sel)
3388               menu->sel = 0;
3389            else
3390               menu->sel = 2;
23803391      }
23813392   }
2382
2383   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
3393   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
23843394   {
2385      sel -= fullMenuPageHeight;
2386
2387      if(sel < 0)
2388         sel = 0;
3395      CURSOR_PAGE_UP(menu->sel)
23893396   }
2390
2391   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
3397   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
23923398   {
2393      sel += fullMenuPageHeight;
2394
2395      if(sel >= total)
2396         sel = total - 1;
3399      CURSOR_PAGE_DOWN(menu->sel, total)
23973400   }
23983401
2399   if((sel >= 0) && (sel < cheatListLength))
2400      entry = &cheatList[sel];
3402   if(menu->sel >= 0 && menu->sel < total - 1)
3403      entry = &cheatList[menuIndex[menu->sel]];
24013404   else
24023405      entry = NULL;
24033406
2404   if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
3407   if(entry && !(entry->flags & kCheatFlag_Null) && !(entry->flags & kCheatFlag_ExtendComment) && !(entry->flags & kCheatFlag_HasWrongCode))
24053408   {
2406      if((sel < (total - 1)) && entry)
3409      UINT8 toggle = 0;
3410
3411      if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
24073412      {
2408         if(entry->flags & kCheatFlag_Select)      // label-selection
3413         if(entry->flags & kCheatFlag_Select)
24093414         {
2410            /* ----- move selection to unLinkExtension code or last linked-code ----- */
2411            do{
2412               entry->selection--;
3415            if(TEST_FIELD(entry->actionList[entry->labelIndex[0]].type, LabelSelectUseSelector))
3416            {
3417               /* activate label selector */
3418               cheat_menu_stack_push(user_select_label_menu, menu->handler, menu->sel);
3419            }
3420            else
3421            {
3422               /* select previous label */
3423               if(--entry->selection < 0)
3424                  entry->selection = entry->labelIndexLength - 1;
24133425
2414               if(entry->flags & kCheatFlag_OneShot)
2415               {
2416                  if(entry->selection <= 0)
2417                     entry->selection = entry->actionListLength - 1;      // first -> last
2418
2419                  /* ----- no action when press arrow key ----- */
2420                  entry->flags &= ~kCheatFlag_DoOneShot;
2421               }
2422               else
2423               {
2424                  if(entry->selection < 0)
2425                     entry->selection = entry->actionListLength - 1;      // OFF -> last
2426
2427                  if(entry->selection == 0)
2428                     DeactivateCheat(entry);      // OFF
2429                  else
2430                  {
2431                     if(!TEST_FIELD(entry->actionList[entry->selection].type, LinkExtension))
2432                        ActivateCheat(entry);   // ON
2433                  }
2434               }
2435            }while(entry->selection && TEST_FIELD(entry->actionList[entry->selection].type, LinkExtension));
3426               /* NOTE : one shot cheat should not be activated by changing label */
3427               if(!entry->labelIndex[entry->selection])
3428                  DeactivateCheat(entry);
3429               else if(!(entry->flags & kCheatFlag_OneShot) && !(entry->flags & kCheatFlag_Active))
3430                  ActivateCheat(entry);
3431            }
24363432         }
2437         else                  // others
3433         else if(entry->flags & kCheatFlag_LayerIndex)
24383434         {
2439            if(!(entry->flags & kCheatFlag_Null) && !(entry->flags & kCheatFlag_OneShot))
3435            /* change layer level */
3436            toggle = 2;
3437         }
3438         else if(!(entry->flags & kCheatFlag_OneShot))
3439         {
3440            /* toggle ON/OFF */
3441            toggle = 1;
3442         }
3443      }
3444      else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
3445      {
3446         if(entry->flags & kCheatFlag_Select)
3447         {
3448            /* label-selection special handling */
3449            if(TEST_FIELD(entry->actionList[entry->labelIndex[0]].type, LabelSelectUseSelector))
24403450            {
2441               int active = entry->flags & kCheatFlag_Active;
3451               /* activate label selector */
3452               cheat_menu_stack_push(user_select_label_menu, menu->handler, menu->sel);
3453            }
3454            else
3455            {
3456               /* select next label index */
3457               if(++entry->selection >= entry->labelIndexLength)
3458                  entry->selection = 0;
24423459
2443               active ^= 0x01;
2444
2445               /* ----- get the user's selected value if needed ----- */
2446               if((entry->flags & kCheatFlag_UserSelect) && active)
2447               {
2448                  submenu_id = 2;
2449                  submenu_choice = 1;
2450               }
2451               else
2452               {
2453                  if(active)
2454                     ActivateCheat(entry);      // ON
2455                  else
2456                     DeactivateCheat(entry);      // OFF
2457               }
3460               /* NOTE : one shot cheat should not be activated by changing label */
3461               if(!entry->labelIndex[entry->selection])
3462                  DeactivateCheat(entry);
3463               else if(!(entry->flags & kCheatFlag_OneShot) && !(entry->flags & kCheatFlag_Active))
3464                  ActivateCheat(entry);
24583465            }
24593466         }
3467         else if(entry->flags & kCheatFlag_LayerIndex)
3468         {
3469            /* change layer level */
3470            toggle = 2;
3471         }
3472         else if(!(entry->flags & kCheatFlag_OneShot))
3473         {
3474            /* toggle ON/OFF */
3475            toggle = 1;
3476         }
24603477      }
2461   }
24623478
2463   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
2464   {
2465      if((sel < (total - 1)) && entry)
3479      switch(toggle)
24663480      {
2467         if(entry->flags & kCheatFlag_Select)      // label-selection
2468         {
2469            /* ----- move selection to unLinkExtension code or 1st code ----- */
2470            do{
2471               entry->selection++;
2472
2473               if(entry->flags & kCheatFlag_OneShot)
2474               {
2475                  if(entry->selection >= entry->actionListLength)
2476                  {
2477                     entry->selection = 1;      // last -> first
2478
2479                     if(entry->selection >= entry->actionListLength)
2480                        entry->selection = 0;
2481                  }
2482                  /* ----- no action when press arrow key ----- */
2483                  entry->flags &= ~kCheatFlag_DoOneShot;
2484               }
2485               else            // others
2486               {
2487                  if(entry->selection >= entry->actionListLength)
2488                  {
2489                     entry->selection = 0;      // last -> OFF
2490
2491                     DeactivateCheat(entry);      // OFF
2492                  }
2493                  else
2494                  {
2495                     if(!TEST_FIELD(entry->actionList[entry->selection].type, LinkExtension))
2496                        ActivateCheat(entry);   // ON
2497                  }
2498               }
2499            }while(entry->selection && TEST_FIELD(entry->actionList[entry->selection].type, LinkExtension));
2500         }
2501         else
2502         {
2503            if(!(entry->flags & kCheatFlag_Null) && !(entry->flags & kCheatFlag_OneShot))
3481         case 1:
25043482            {
2505               int active = entry->flags & kCheatFlag_Active;
3483               int active = (entry->flags & kCheatFlag_Active) ^ 1;
25063484
2507               active ^= 0x01;      // toggle On and OFF
2508
2509               /* ----- get the user's selected value if needed ----- */
25103485               if((entry->flags & kCheatFlag_UserSelect) && active)
25113486               {
2512                  submenu_id = 2;
2513                  submenu_choice = 1;
3487                  /* activate value-selection menu */
3488                  cheat_menu_stack_push(user_select_value_menu, menu->handler, menu->sel);
25143489               }
25153490               else
25163491               {
25173492                  if(active)
2518                     ActivateCheat(entry);      // ON
3493                     ActivateCheat(entry);
25193494                  else
2520                     DeactivateCheat(entry);      // OFF
3495                     DeactivateCheat(entry);
25213496               }
25223497            }
2523         }
3498            break;
3499
3500         case 2:
3501            {
3502               /* go to next/previous layer level */
3503               if(entry->actionList[0].data == currentLayer)
3504                  currentLayer = entry->actionList[0].address;
3505               else
3506                  currentLayer = entry->actionList[0].data;
3507
3508               entry->flags |= kCheatFlag_LayerSelected;
3509            }
3510            break;
3511
3512         default:
3513            break;
25243514      }
25253515   }
25263516
25273517   if(input_ui_pressed(machine, IPT_UI_SELECT))
25283518   {
2529      if(sel == (total - 1))
3519      if(!entry)
25303520      {
2531         /* ----- return to prior menu ----- */
2532         submenu_choice = 0;
2533         sel = -1;
3521         if(currentLayer)
3522            currentLayer = menu->sel = 0;
3523         else
3524            menu->sel = -1;
25343525      }
2535      else
3526      else if(!(entry->flags & kCheatFlag_Null))
25363527      {
2537         if((sel < (total - 1)) && entry)
3528         if(ShiftKeyPressed() && (entry->comment && entry->comment[0]))
25383529         {
2539            if(ShiftKeyPressed())
2540            {
2541               if(entry->comment && entry->comment[0])
2542               {
2543                  /* ----- display comment ------ */
2544                  submenu_id = 1;
2545                  submenu_choice = 1;
2546               }
2547               else
2548                  goto doActivate;
2549            }
3530            /* display comment */
3531            cheat_menu_stack_push(comment_menu, menu->handler, menu->sel);
3532         }
3533         else if(entry->flags & kCheatFlag_ExtendComment)
3534         {
3535            /* activate extend comment menu */
3536            cheat_menu_stack_push(extend_comment_menu, menu->handler, menu->sel);
3537         }
3538         else if(entry->flags & kCheatFlag_UserSelect)
3539         {
3540            /* activate value-selection menu */
3541            cheat_menu_stack_push(user_select_value_menu, menu->handler, menu->sel);
3542         }
3543         else if((entry->flags & kCheatFlag_Select) && TEST_FIELD(entry->actionList[entry->labelIndex[0]].type, LabelSelectUseSelector))
3544         {
3545            /* activate label selector */
3546            cheat_menu_stack_push(user_select_label_menu, menu->handler, menu->sel);
3547         }
3548         else if(entry->flags & kCheatFlag_LayerIndex)
3549         {
3550            /* go to next/previous layer level */
3551            if(entry->actionList[0].data == currentLayer)
3552               currentLayer = entry->actionList[0].address;
25503553            else
2551            {
2552               doActivate:
3554               currentLayer = entry->actionList[0].data;
25533555
2554               if(entry->flags & kCheatFlag_UserSelect)
2555               {
2556                  /* ----- value-selection menu ----- */
2557                  submenu_id = 2;
2558                  submenu_choice = 1;
2559               }
2560               else
2561               {
2562                  ActivateCheat(entry);      // ON
2563
2564                  /* ----- set do one shot flag if label-selection ----- */
2565                  if((entry->flags & kCheatFlag_Select) && (entry->flags & kCheatFlag_OneShot))
2566                     entry->flags |= kCheatFlag_DoOneShot;
2567
2568                  /* ----- display one shot message if one shot ----- */
2569                  if(entry->flags & kCheatFlag_OneShot)
2570                     ui_popup_time(1, "%s activated", entry->name);
2571               }
2572            }
3556            entry->flags |= kCheatFlag_LayerSelected;
25733557         }
3558         else if(entry->flags & kCheatFlag_HasWrongCode)
3559         {
3560            /* analyse wrong format code */
3561            cheat_menu_stack_push(analyse_cheat_menu, menu->handler, menu->sel);
3562         }
3563         else
3564         {
3565            /* activate selected code */
3566            ActivateCheat(entry);
3567         }
25743568      }
25753569   }
2576
2577   if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE))
2578      WatchCheatEntry(entry, 0);
2579
2580   if(ShiftKeyPressed())
3570   else if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))
25813571   {
2582      if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))         // shift + save = save all codes
3572      if(ShiftKeyPressed())
25833573      {
3574         /* shift + save : save all codes */
25843575         for(i = 0; i < cheatListLength; i++)
2585            SaveCheat(machine, &cheatList[i], 0, 0);
3576            SaveCheatCode(machine, &cheatList[i]);
25863577
2587         ui_popup_time(1, "%d cheats saved", cheatListLength);
3578         messageTimer = DEFAULT_MESSAGE_TIME;
3579         messageType = kCheatMessage_AllCheatSaved;
25883580      }
2589
2590      if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT))         // shift + add = add new emypty code
2591         AddCheatBefore(sel);
2592
2593      if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))      // shift + delete = delete selected code
2594         DeleteCheatAt(sel);
3581      else if(ControlKeyPressed())
3582      {
3583         /* ctrl + save : save activation key */
3584         SaveActivationKey(machine, entry, menuIndex[menu->sel]);
3585      }
3586      else if(AltKeyPressed())
3587      {
3588         /* alt + save : save pre-enable */
3589         SavePreEnable(machine, entry, menuIndex[menu->sel]);
3590      }
25953591   }
2596   else
3592   else if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT))
25973593   {
2598      if(ControlKeyPressed())
3594      AddCheatBefore(menuIndex[menu->sel]);
3595   }
3596   else if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
3597   {
3598      if(entry)
3599         DeleteCheatAt(menuIndex[menu->sel]);
3600      else
25993601      {
2600         if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))      // ctrl + save = save activation key
2601         {
2602            if((entry->flags & kCheatFlag_HasActivationKey1) || (entry->flags & kCheatFlag_HasActivationKey2))
2603            {
2604               SaveCheat(machine, entry, sel, 1);
2605
2606               ui_popup_time(1, "activation key saved");
2607            }
2608            else
2609               ui_popup_time(1, "no activation key");
2610         }
3602         messageType      = kCheatMessage_FailedToDelete;
3603         messageTimer   = DEFAULT_MESSAGE_TIME;
26113604      }
2612      else
3605   }
3606   else if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT))
3607   {
3608      if(entry)
26133609      {
2614         if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))
2615            SaveCheat(machine, entry, 0, 0);         // save current entry
3610         cheat_menu_stack_push(command_add_edit_menu, menu->handler, menu->sel);
26163611      }
26173612   }
2618
2619   if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT) && entry)      // edit selected code
3613   else if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE))
26203614   {
2621      submenu_id = 3;
2622      submenu_choice = 1;
3615      WatchCheatEntry(entry, 0);
26233616   }
2624
2625   if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT))
3617   else if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT))
3618   {
26263619      ReloadCheatDatabase(machine);
3620   }
3621   else if(input_ui_pressed(machine, IPT_UI_CANCEL))
3622   {
3623      /* NOTE : cancel button return cheat main menu directly */
3624      menu->sel = -1;
3625   }
26273626
2628   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate))
2629      /* ----- quick menu switch : enable/disable -> add/edit ----- */
2630      sel = -3;
3627   free(menuIndex);
26313628
2632   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate))
2633      /* ----- quick menu switch : enable/disable -> watchpoint list ----- */
2634      sel = -5;
2635
2636   if(input_ui_pressed(machine, IPT_UI_CANCEL))
2637      sel = -1;
2638
2639   return sel + 1;
3629   return menu->sel + 1;
26403630}
26413631
2642/*--------------------------------------------------------
2643  AddEditCheatMenu - management for Add/Edit cheat menu
2644--------------------------------------------------------*/
3632/*-----------------------------------------------------------
3633  add_edit_cheat_menu - management for Add/Edit cheat menu
3634-----------------------------------------------------------*/
26453635
2646static int AddEditCheatMenu(running_machine *machine, int selection)
3636static int add_edit_cheat_menu(running_machine *machine, cheat_menu_stack *menu)
26473637{
2648   INT32         sel;
2649   static INT32   submenuChoice = 0;
2650   static INT32   submenuCheat = 0;
3638   int            i;
3639   UINT8         total         = 0;
26513640   const char      ** menu_item;
2652   INT32         i;
2653   INT32         total = 0;
26543641   CheatEntry      * entry;
26553642
2656   sel = selection - 1;
3643   /* first setting : NONE */
3644   if(menu->first_time)
3645      menu->first_time = 0;
26573646
2658   RequestStrings(cheatListLength + 2, 0, 0, 0);
3647   /* required items = total codes + return + terminator */
3648   request_strings(cheatListLength + 2, 0, 0, 0);
3649   menu_item = menu_strings.main_list;
26593650
2660   menu_item = menuStrings.mainList;
2661
2662   /********** SUB MENU **********/
2663   if(submenuChoice)
2664   {
2665      submenuChoice = EditCheatMenu(machine, &cheatList[submenuCheat], submenuCheat, submenuChoice);
2666
2667      /* ----- meaningless ? because no longer return with sel = -1 (pressed UI_CONFIG in submenu) ----- */
2668//      if(submenuChoice == -1)
2669//      {
2670//          submenuChoice = 0;
2671//          sel = -2;
2672//      }
2673
2674      return sel + 1;
2675   }
2676
26773651   /********** MENU CONSTRUCTION **********/
26783652   for(i = 0; i < cheatListLength; i++)
26793653   {
2680      CheatEntry   * traverse = &cheatList[i];
3654      CheatEntry * traverse = &cheatList[i];
26813655
3656      /* ##### NAME ##### */
26823657      if(traverse->name)
2683         menu_item[total++] = traverse->name;      // code title
3658         menu_item[total++] = traverse->name;
26843659      else
26853660         menu_item[total++] = "(none)";
26863661   }
26873662
2688   menu_item[total++] = "Return to Prior Menu";      // return
3663   /* ##### RETURN ##### */
3664   menu_item[total++] = "Return to Prior Menu";
26893665
2690   menu_item[total] = NULL;               // terminate array
3666   /* ##### TERMINATE ARRAY ##### */
3667   menu_item[total] = NULL;
26913668
2692   /* ----- adjust current cursor position ----- */
2693   if(sel < 0)
2694      sel = 0;
2695   if(sel >= total)
2696      sel = total - 1;
3669   /* adjust cursor position */
3670   ADJUST_CURSOR(menu->sel, total)
26973671
2698   /* ----- draw it ----- */
2699   old_style_menu(menu_item, NULL, NULL, sel, 0);
3672   /* draw it */
3673   old_style_menu(menu_item, NULL, NULL, menu->sel, 0);
27003674
3675   if(menu->sel < total - 1)
3676      entry = &cheatList[menu->sel];
3677   else
3678      entry = NULL;
3679
27013680   /********** KEY HANDLING **********/
2702   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
3681   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
27033682   {
2704      sel++;
2705
2706      if(sel >= total)
2707         sel = 0;
3683      CURSOR_TO_PREVIOUS(menu->sel, total)
27083684   }
2709
2710   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
3685   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
27113686   {
2712      sel--;
2713
2714      if(sel < 0)
2715         sel = total - 1;
3687      CURSOR_TO_NEXT(menu->sel, total)
27163688   }
2717
2718   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
3689   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
27193690   {
2720      sel -= fullMenuPageHeight;
2721
2722      if(sel < 0)
2723         sel = 0;
3691      CURSOR_PAGE_UP(menu->sel)
27243692   }
2725
2726   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
3693   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
27273694   {
2728      sel += fullMenuPageHeight;
2729
2730      if(sel >= total)
2731         sel = total - 1;
3695      CURSOR_PAGE_DOWN(menu->sel, total)
27323696   }
2733
2734   if(sel < (total - 1))
2735      entry = &cheatList[sel];
2736   else
2737      entry = NULL;
2738
2739   if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))
3697   else if(input_ui_pressed(machine, IPT_UI_SELECT))
27403698   {
2741      if(ShiftKeyPressed())
3699      if(entry)
27423700      {
2743         for(i = 0; i < cheatListLength; i++)      // shift + save = save all codes
2744            SaveCheat(machine, &cheatList[i], 0, 0);
2745
2746         ui_popup_time(1, "%d cheats saved", cheatListLength);
3701         if(entry->flags & kCheatFlag_HasWrongCode)
3702         {
3703            cheat_menu_stack_push(analyse_cheat_menu, menu->handler, menu->sel);
3704         }
3705         else
3706            cheat_menu_stack_push(command_add_edit_menu, menu->handler, menu->sel);
27473707      }
27483708      else
3709         menu->sel = -1;
3710   }
3711   else if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT))
3712   {
3713      ReloadCheatDatabase(machine);
3714   }
3715   else if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT))
3716   {
3717      if(entry)
27493718      {
2750         if(ControlKeyPressed())
3719         if(entry->flags & kCheatFlag_HasWrongCode)
27513720         {
2752            if((entry->flags & kCheatFlag_HasActivationKey1) || (entry->flags & kCheatFlag_HasActivationKey2))
2753            {
2754               SaveCheat(machine, entry, sel, 1);   // ctrl + save = save activation key
2755
2756               ui_popup_time(1, "activation key saved");
2757            }
2758            else
2759               ui_popup_time(1, "no activation key");
3721            cheat_menu_stack_push(analyse_cheat_menu, menu->handler, menu->sel);
27603722         }
27613723         else
2762            SaveCheat(machine, entry, 0, 0);      // save current entry
3724            cheat_menu_stack_push(command_add_edit_menu, menu->handler, menu->sel);
27633725      }
27643726   }
2765
2766   if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT))
2767      AddCheatBefore(sel);         // insert empty code
2768
2769   if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
2770      DeleteCheatAt(sel);         // delete selected code
2771
2772   if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE))
2773      WatchCheatEntry(entry, 0);            // watch selected code
2774
2775   if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT))      // edit selected code
3727   else if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT))
27763728   {
2777      /* ----- if selected item is not return, go to edit menu ----- */
2778      if(sel < (total - 1))
2779      {
2780         submenuCheat = sel;
2781         submenuChoice = 1;
2782      }
3729      AddCheatBefore(menu->sel);
27833730   }
2784
2785   if(input_ui_pressed(machine, IPT_UI_SELECT))
3731   else if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
27863732   {
2787      /* ----- if selected item is return, return previous menu ----- */
2788      if(sel >= (total - 1))
3733      DeleteCheatAt(menu->sel);
3734   }
3735   else if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))
3736   {
3737      if(ShiftKeyPressed())
27893738      {
2790         submenuChoice = 0;
2791         sel = -1;
3739         /* shift + save = save all codes */
3740         for(i = 0; i < cheatListLength; i++)
3741            SaveCheatCode(machine, &cheatList[i]);
3742
3743         messageTimer   = DEFAULT_MESSAGE_TIME;
3744         messageType      = kCheatMessage_AllCheatSaved;
27923745      }
2793      /* ----- otherwise, go to edit menu (same as pressing edit key) ----- */
3746      else if(ControlKeyPressed())
3747      {
3748         if((entry->flags & kCheatFlag_HasActivationKey1) || (entry->flags & kCheatFlag_HasActivationKey2))
3749            /* ctrl + save = save activation key */
3750            SaveActivationKey(machine, entry, menu->sel);
3751      }
3752      else if(AltKeyPressed())
3753      {
3754         /* alt + save = save pre-enable code */
3755         SavePreEnable(machine, entry, menu->sel);
3756      }
27943757      else
27953758      {
2796         submenuCheat = sel;
2797         submenuChoice = 1;
3759         SaveCheatCode(machine, entry);
27983760      }
27993761   }
3762   else if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE))
3763   {
3764      WatchCheatEntry(entry, 0);
3765   }
3766   else if(input_ui_pressed(machine, IPT_UI_CANCEL))
3767   {
3768      menu->sel = -1;
3769   }
28003770
2801   if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT))
2802      ReloadCheatDatabase(machine);
3771   return menu->sel + 1;
3772}
28033773
2804   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate))
2805      /* ----- quick menu switch : add/edit -> search ----- */
2806      sel = -4;
3774/*-----------------------------------------------------------
3775  command_add_edit_menu - management for code command menu
3776-----------------------------------------------------------*/
28073777
2808   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate))
2809      /* ----- quick menu switch : add/edit -> enable/disable ----- */
2810      sel = -2;
3778static int command_add_edit_menu(running_machine *machine, cheat_menu_stack *menu)
3779{
3780   enum{
3781      kMenu_EditCheat = 0,
3782      kMenu_ReloadDatabase,
3783      kMenu_WatchCheat,
3784      kMenu_SaveCheat,
3785      kMenu_SaveActivationKey,
3786      kMenu_SavePreEnable,
3787      kMenu_SaveAllCodes,
3788      kMenu_AddCode,
3789      kMenu_DeleteCode,
3790#ifdef MAME_DEBUG
3791      kMenu_ConvertFormat,
3792      kMenu_AnalyseCode,
3793#endif
3794      kMenu_Return,
3795      kMenu_Max };
28113796
2812   if(input_ui_pressed(machine, IPT_UI_CANCEL))
2813      sel = -1;
3797   int            i;
3798   UINT8         total = 0;
3799   ui_menu_item   menu_item[kMenu_Max + 1];
3800   CheatEntry      *entry = &cheatList[menu->pre_sel];
28143801
2815   return sel + 1;
3802   memset(menu_item, 0, sizeof(menu_item));
3803
3804   /* first setting : NONE */
3805   if(menu->first_time)
3806      menu->first_time = 0;
3807
3808   /********** MENU CONSTRUCION **********/
3809   if(entry->flags & kCheatFlag_OldFormat)
3810      menu_item[total++].text = "Edit Code";
3811   else
3812      menu_item[total++].text = "View Code";
3813   menu_item[total++].text = "Reload Database";
3814   menu_item[total++].text = "Watch Code";
3815   menu_item[total++].text = "Save Code";
3816   menu_item[total++].text = "Save Activation Key";
3817   menu_item[total++].text = "Save PreEnable";
3818   menu_item[total++].text = "Save All Codes";
3819   menu_item[total++].text = "Add New Code";
3820   menu_item[total++].text = "Delete Code";
3821#ifdef MAME_DEBUG
3822   if(entry->flags & kCheatFlag_OldFormat)
3823      menu_item[total++].text = "Convert To New Format";
3824   else
3825      menu_item[total++].text = "Convert To Old Format";
3826   menu_item[total++].text = "Analyse Code";
3827#endif
3828   menu_item[total++].text = "Return to Prior Menu";
3829   menu_item[total].text = NULL;
3830
3831   /* adjust cursor position */
3832   ADJUST_CURSOR(menu->sel, total)
3833
3834   /* print it */
3835   ui_menu_draw(menu_item, total, menu->sel, NULL);
3836
3837   /********** KEY HANDLING **********/
3838   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
3839   {
3840      CURSOR_TO_PREVIOUS(menu->sel, total)
3841   }
3842   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
3843   {
3844      CURSOR_TO_NEXT(menu->sel, total)
3845   }
3846   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
3847   {
3848      CURSOR_PAGE_UP(menu->sel)
3849   }
3850   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
3851   {
3852      CURSOR_PAGE_DOWN(menu->sel, total)
3853   }
3854   else if(input_ui_pressed(machine, IPT_UI_SELECT))
3855   {
3856      switch(menu->sel)
3857      {
3858         case kMenu_EditCheat:
3859            if(entry->flags & kCheatFlag_OldFormat)
3860               cheat_menu_stack_push(edit_cheat_menu, menu->return_handler, menu->pre_sel);
3861            else
3862               cheat_menu_stack_push(view_cheat_menu, menu->return_handler, menu->pre_sel);
3863            break;
3864
3865         case kMenu_ReloadDatabase:
3866            ReloadCheatDatabase(machine);
3867            cheat_menu_stack_pop();
3868            break;
3869
3870         case kMenu_WatchCheat:
3871            WatchCheatEntry(entry, 0);
3872            break;
3873
3874         case kMenu_SaveCheat:
3875            SaveCheatCode(machine, entry);
3876            break;
3877
3878         case kMenu_SaveActivationKey:
3879            SaveActivationKey(machine, entry, menu->pre_sel);
3880            break;
3881
3882         case kMenu_SavePreEnable:
3883            SavePreEnable(machine, entry, menu->pre_sel);
3884            break;
3885
3886         case kMenu_SaveAllCodes:
3887            {
3888               for(i = 0; i < cheatListLength; i++)
3889                  SaveCheatCode(machine, &cheatList[i]);
3890
3891               messageTimer   = DEFAULT_MESSAGE_TIME;
3892               messageType      = kCheatMessage_AllCheatSaved;
3893            }
3894            break;
3895
3896         case kMenu_AddCode:
3897            AddCheatBefore(menu->pre_sel);
3898            menu->sel = -1;
3899            break;
3900
3901         case kMenu_DeleteCode:
3902            DeleteCheatAt(menu->pre_sel);
3903            menu->sel = -1;
3904            break;
3905
3906#ifdef MAME_DEBUG
3907         case kMenu_ConvertFormat:
3908            if(!(entry->flags & kCheatFlag_OldFormat))
3909            {
3910               for(i = 0; i < entry->actionListLength; i++)
3911               {
3912                  entry->actionList[i].flags |= kActionFlag_OldFormat;
3913                  UpdateCheatInfo(entry, 0);
3914               }
3915            }
3916            else
3917            {
3918               for(i = 0; i < entry->actionListLength; i++)
3919               {
3920                  entry->actionList[i].flags &= ~kActionFlag_OldFormat;
3921                  UpdateCheatInfo(entry, 0);
3922               }
3923            }
3924            break;
3925
3926         case kMenu_AnalyseCode:
3927            cheat_menu_stack_push(analyse_cheat_menu, menu->return_handler, menu->pre_sel);
3928            break;
3929#endif
3930         case kMenu_Return:
3931            menu->sel = -1;
3932            break;
3933      }
3934   }
3935   else if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT))
3936   {
3937      ReloadCheatDatabase(machine);
3938   }
3939   else if(input_ui_pressed(machine, IPT_UI_CANCEL) || input_ui_pressed(machine, IPT_UI_LEFT) || input_ui_pressed(machine, IPT_UI_RIGHT))
3940   {
3941      menu->sel = -1;
3942   }
3943
3944   return menu->sel + 1;
28163945}
28173946
2818/*------------------------------------------------
2819  EditCheatMenu - management for edit code menu
2820------------------------------------------------*/
3947/*--------------------------------------------------
3948  edit_cheat_menu - management for edit code menu
3949--------------------------------------------------*/
28213950
2822static int EditCheatMenu(running_machine *machine, CheatEntry * entry, int index, int selection)
3951static int edit_cheat_menu(running_machine *machine, cheat_menu_stack *menu)
28233952{
3953#if 0
28243954   static const char *const kTypeNames[] =
28253955   {
28263956      "Normal/Delay",
r2762r2763
28313961      "Select"
28323962   };
28333963
2834   static const char *const kNumbersTable[] =
2835   {
2836      "0",   "1",   "2",   "3",   "4",   "5",   "6",   "7",
2837      "8",   "9",   "10",   "11",   "12",   "13",   "14",   "15",
2838      "16",   "17",   "18",   "19",   "20",   "21",   "22",   "23",
2839      "24",   "25",   "26",   "27",   "28",   "29",   "30",   "31"
2840   };
2841
28423964   static const char *const kOperationNames[] =
28433965   {
28443966      "Write",
28453967      "Add/Subtract",
28463968      "Force Range",
28473969      "Set/Clear Bits",
2848      "Write If Match",
3970      "Unused (4)",
28493971      "Unused (5)",
28503972      "Unused (6)",
28513973      "Null"
r2762r2763
28773999      "Swap"
28784000   };
28794001
2880   static const char *const kRegionNames[] =
2881   {
2882      "CPU1",      "CPU2",      "CPU3",      "CPU4",      "CPU5",      "CPU6",      "CPU7",      "CPU8",
2883      "GFX1",      "GFX2",      "GFX3",      "GFX4",      "GFX5",      "GFX6",      "GFX7",      "GFX8",
2884      "PROMS",
2885      "SOUND1",   "SOUND2",   "SOUND3",   "SOUND4",   "SOUND5",   "SOUND6",   "SOUND7",   "SOUND8",
2886      "USER1",   "USER2",   "USER3",   "USER4",   "USER5",   "USER6",   "USER7",   "USER8"
2887   };
2888
28894002   static const char *const kLocationNames[] =
28904003   {
28914004      "Normal",
r2762r2763
28934006      "Mapped Memory",
28944007      "Custom",
28954008      "Relative Address",
2896      "Program Space",
2897      "Unused (6)",
2898      "Unused (7)"
4009      "Unused (5)", "Unused (6)", "Unused (7)"
28994010   };
29004011
29014012   static const char *const kCustomLocationNames[] =
r2762r2763
29114022      "Unused (28)",   "Unused (29)",   "Unused (30)",   "Unused (31)"
29124023   };
29134024
2914   static const char *const kSizeNames[] =
2915   {
2916      "8 Bit",
2917      "16 Bit",
2918      "24 Bit",
2919      "32 Bit"
2920   };
2921
29224025   enum
29234026   {
29244027      kType_Name = 0,               //  text        name
r2762r2763
29314034                              //  NOTE:   read from base cheat (for idx == 0)
29324035      kType_ActivationKey2,         //  key         2nd activationKey
29334036                              //  NOTE:   read from base cheat (for idx == 0)
2934         // if(idx > 0 && (cheat[0].type == Select))
2935         kType_LinkExtension,      //  select      LinkExtension       Off - On
2936      kType_Type,                  //  select      Type                Normal/Delay - Wait - Ignore Decrement - Watch -
2937                              //                                  Comment - Select
2938                              //  NOTE: also uses location type field for comment and select
2939      // if((Type != Comment) && (Type != Select))
2940         // if(Type != Watch)
2941            kType_OneShot,         //  select      OneShot             Off - On
2942            kType_RestorePreviousValue,
2943                              //  select      RestorePreviousValue
2944                              //                                  Off - On
2945         // if((Type == Normal/Delay) || (Type == Wait))
2946            kType_Delay,         //  value       TypeParameter       0 - 7
2947         // if(Type == Ignore Decrement)
2948            kType_IgnoreDecrementBy,//  value       TypeParameter       0 - 7
4037      kType_Code,                  //  value       Type Field
4038                              //  NOTE:   it's debug display so that must not modify directly
4039      kType_Link,                  //  select      Link                  Off - On
4040      kType_LinkExtension,         //  select      Link Extension        Off - On
4041      kType_Type,                  //  select      Type                  Normal/Delay - Watch - Comment - (label) Select
4042      kType_OneShot,               //  select      OneShot               Off - On
4043      kType_RestorePreviousValue,      //  select      RestorePreviousValue  Off - On
4044         // if(Type != Ignore Decrement)
4045         kType_Delay,            //  value       TypeParameter         0 - 7
4046         // else
4047         kType_IgnoreDecrementBy,   //  value       TypeParameter         0 - 7
29494048         // if(Type == Watch)
2950            kType_WatchSize,      //  value       Data                0x01 - 0xFF (stored as 0x00 - 0xFE)
4049         kType_WatchSize,         //  value       Data                  0x01 - 0xFF (stored as 0x00 - 0xFE)
29514050                              //  NOTE: value is packed in to 0x000000FF
2952            kType_WatchSkip,      //  value       Data                0x00 - 0xFF
4051         kType_WatchSkip,         //  value       Data                  0x00 - 0xFF
29534052                              //  NOTE: value is packed in to 0x0000FF00
2954            kType_WatchPerLine,      //  value       Data                0x00 - 0xFF
4053         kType_WatchPerLine,         //  value       Data                  0x00 - 0xFF
29554054                              //  NOTE: value is packed in to 0x00FF0000
2956            kType_WatchAddValue,   //  value       Data                -0x80 - 0x7F
4055         kType_WatchAddValue,      //  value       Data                  -0x80 - 0x7F
29574056                              //  NOTE: value is packed in to 0xFF000000
2958            kType_WatchFormat,      //  select      TypeParameter       Hex - Decimal - Binary - ASCII
4057         kType_WatchFormat,         //  select      TypeParameter         Hex - Decimal - Binary - ASCII
29594058                              //  NOTE: value is packed in to 0x03
2960            kType_WatchLabel,      //  select      TypeParameter       Off - On
4059         kType_WatchLabel,         //  select      TypeParameter         Off - On
29614060                              //  NOTE: value is packed in to 0x04
2962            // and set operation to null
2963         // else
2964            kType_Operation,      //  select      Operation           Write - Add/Subtract - Force Range - Set/Clear Bits - Match to Write -
2965                              //                                  Null
2966         // if((Operation == Write) && (LocationType != Relative Address))
2967            kType_WriteMask,      //  value       extendData          0x00000000 - 0xFFFFFFFF
2968         // if(Operation == Add/Subtract)
2969            kType_AddSubtract,      //  select      OperationParameter  Add - Subtract
2970            // if(LocationType != Relative Address)
2971               // if(OperationParameter == Add)
2972                  kType_AddMaximum,
2973                              //  value       extendData          0x00000000 - 0xFFFFFFFF
2974               // else
2975                  kType_SubtractMinimum,
2976                              //  value       extendData          0x00000000 - 0xFFFFFFFF
2977         // if((Operation == Force Range) && (LocationType != Relative Address))
2978            kType_RangeMinimum,      //  value       extendData          0x00 - 0xFF / 0xFFFF
4061      kType_Operation,            //  select      Operation             Write - Add/Subtract - Force Range - Set/Clear Bits
4062      kType_OperationExtend,         //  select      Operation Extend      Off - On
4063                              //  NOTE: Operation Extend is unused right now
4064         // if(LocationType != Relative Address && Operation == Write)
4065         kType_WriteMask,         //  value       extendData            0x00000000 - 0xFFFFFFFF
4066         // if(LocationType != Relative Address && Operation == Add/Subtract)
4067         kType_AddSubtract,         //  select      OperationParameter    Add - Subtract
4068            // if(OperationParameter == Add)
4069            kType_AddMaximum,      //  value       extendData            0x00000000 - 0xFFFFFFFF
4070            // else
4071            kType_SubtractMinimum,   //  value       extendData            0x00000000 - 0xFFFFFFFF
4072         // if(LocationType != Relative Address && Operation == Force Range)
4073         kType_RangeMinimum,         //  value       extendData            0x00 - 0xFF / 0xFFFF
29794074                              //  NOTE: value is packed in to upper byte of extendData (as a word)
2980            kType_RangeMaximum,      //  value       extendData          0x00 - 0xFF / 0xFFFF
4075         kType_RangeMaximum,         //  value       extendData            0x00 - 0xFF / 0xFFFF
29814076                              //  NOTE: value is packed in to lower byte of extendData (as a word)
29824077         // if(Operation == Set/Clear)
2983            kType_SetClear,         //  select      OperationParameter  Set - Clear
2984         // if(Operation == Match to Write)
2985            kType_WriteMatch,      //  value       extendData          0x00000000 - 0xFFFFFFFF
2986         // if((Operation != Null) || (Type == Watch))
2987            // if(Type != Watch)
2988               kType_Data,
2989               kType_UserSelect,      //  select      UserSelectEnable    Off - On
2990               // if(UserSelect == On)
2991                  kType_UserSelectMinimumDisp,
2992                                 //  value       UserSelectMinimumDisplay
2993                                 //                                  0 - 1
2994                  kType_UserSelectMinimum,
2995                                 //  value       UserSelectMinimum   0 - 1
2996                  kType_UserSelectBCD,//  select      UserSelectBCD       Off - On
2997                  kType_Prefill,      //  select      UserSelectPrefill   None - FF - 00 - 01
2998               // if(idx > 0)
2999                  kType_CopyPrevious,   //  select      LinkCopyPreviousValue
3000                              //                                  Off - On
3001            kType_ByteLength,      //  value       BytesUsed           1 - 4
3002            // if(bytesUsed > 0)
3003               kType_Endianness,   //  select      Endianness          Normal - Swap
3004            kType_LocationType,      //  select      LocationType        Normal - Region - Mapped Memory - EEPROM -
3005                              //                                  Relative Address - Program Space
3006                              //  NOTE: also uses LocationParameter for EEPROM type
3007            // if((LocationType == Normal) || (LocationType == HandlerMemory) || (LocationType == ProgramSpace)
3008               kType_CPU,         //  value       LocationParameter   0 - 31
3009            // if(LocationType == Region)
3010               kType_Region,      //  select      LocationParameter   CPU1 - CPU2 - CPU3 - CPU4 - CPU5 - CPU6 - CPU7 -
3011                              //                                  CPU8 - GFX1 - GFX2 - GFX3 - GFX4 - GFX5 - GFX6 -
3012                              //                                  GFX7 - GFX8 - PROMS - SOUND1 - SOUND2 - SOUND3 -
3013                              //                                  SOUND4 - SOUND5 - SOUND6 - SOUND7 - SOUND8 -
3014                              //                                  USER1 - USER2 - USER3 - USER4 - USER5 - USER6 -
3015                              //                                  USER7
3016            // if(LocationType == RelativeAddress)
3017               kType_PackedCPU,   //  value       LocationParameter   0 - 7
4078         kType_SetClear,            //  select      OperationParameter    Set - Clear
4079      kType_Data,
4080      kType_UserSelect,            //  select      UserSelectEnable      Off - On
4081      kType_UserSelectMinimumDisp,   //  value       UserSelectMinimumDisplay  Off - On
4082      kType_UserSelectMinimum,      //  value       UserSelectMinimum     0 - 1
4083      kType_UserSelectBCD,         //  select      UserSelectBCD         Off - On
4084      kType_CopyPrevious,            //  select      LinkCopyPreviousValue Off - On
4085      kType_Prefill,               //  select      UserSelectPrefill     None - FF - 00 - 01
4086      kType_ByteLength,            //  value       BytesUsed             1 - 4
4087      kType_Endianness,            //  select      Endianness            Normal - Swap
4088      kType_LocationType,            //  select      LocationType          Normal - Region - Mapped Memory - EEPROM - Relative Address
4089         // if(LocationType != Region && LocationType != Relative Address)
4090         kType_CPU,               //  value       LocationParameter     0 - 31
4091         // if(LocationType == Region)
4092         kType_Region,            //  select      LocationParameter     CPU1 - CPU2 - CPU3 - CPU4 - CPU5 - CPU6 - CPU7 -
4093                              //                                    CPU8 - GFX1 - GFX2 - GFX3 - GFX4 - GFX5 - GFX6 -
4094                              //                                    GFX7 - GFX8 - PROMS - SOUND1 - SOUND2 - SOUND3 -
4095                              //                                    SOUND4 - SOUND5 - SOUND6 - SOUND7 - SOUND8 -
4096                              //                                    USER1 - USER2 - USER3 - USER4 - USER5 - USER6 -
4097                              //                                    USER7
4098                              //  NOTE: old format doesn't support USER8 - PLDS
4099         // if(LocationType == Relative Address)
4100         kType_PackedCPU,         //  value       LocationParameter     0 - 7
30184101                              //  NOTE: packed in to upper three bits of LocationParameter
3019               kType_PackedSize,   //  value       LocationParameter   1 - 4
4102         kType_PackedSize,         //  value       LocationParameter     1 - 4
30204103                              //  NOTE: packed in to lower two bits of LocationParameter
3021               kType_AddressIndex,   //  value       extendData          -0x80000000 - 0x7FFFFFFF
3022            kType_Address,
4104         kType_AddressIndex,         //  value       extendData            -0x80000000 - 0x7FFFFFFF
4105      kType_Address,
30234106
30244107      kType_Return,
30254108      kType_Divider,
r2762r2763
30274110      kType_Max
30284111   };
30294112
3030   INT32            sel;
4113   int               i;
4114   int               sel            = selection - 1;
4115   int               total         = 0;
4116   UINT8            dirty         = 0;
4117   static UINT8      editActive      = 0;
30314118   const char         ** menuItem;
30324119   const char         ** menuSubItem;
30334120   char            * flagBuf;
30344121   char            ** extendDataBuf;      // FFFFFFFF (-80000000)
30354122   char            ** addressBuf;         // FFFFFFFF
30364123   char            ** dataBuf;            // 80000000 (-2147483648)
4124   char            ** typeBuf;            // FFFFFFFF
30374125   char            ** watchSizeBuf;      // FF
30384126   char            ** watchSkipBuf;      // FF
30394127   char            ** watchPerLineBuf;      // FF
30404128   char            ** watchAddValueBuf;   // FF
3041   INT32            i;
3042   INT32            total = 0;
3043   MenuItemInfoStruct   * info = NULL;
3044   CheatAction         * action = NULL;
3045   UINT8            isSelect = 0;
3046   static UINT8      editActive = 0;
3047   UINT32            increment = 1;
3048   UINT8            dirty = 0;
3049   static INT32      currentNameTemplate = 0;
30504129
3051   astring *         temp_string_1 = astring_alloc();
3052   astring *         temp_string_2 = astring_alloc();
4130   menu_item_info      * info = NULL;
4131   CheatAction         * action      = NULL;
4132   astring            * tempString1   = astring_alloc();      // activation key 1
4133   astring            * tempString2   = astring_alloc();      // activation key 2
30534134
30544135   if(!entry)
30554136      return 0;
30564137
3057   /********** MENU CONSTRUCTION **********/
30584138   if(menuItemInfoLength < (kType_Max * entry->actionListLength) + 2)
30594139   {
30604140      menuItemInfoLength = (kType_Max * entry->actionListLength) + 2;
30614141
3062      menuItemInfo = realloc(menuItemInfo, menuItemInfoLength * sizeof(MenuItemInfoStruct));
4142      menuItemInfo = realloc(menuItemInfo, menuItemInfoLength * sizeof(menu_item_info));
30634143   }
30644144
3065   RequestStrings((kType_Max * entry->actionListLength) + 2, 7 * entry->actionListLength, 24, 0);
4145   request_strings((kType_Max * entry->actionListLength) + 2, 8 * entry->actionListLength, 32, 0);
30664146
3067   menuItem =         menuStrings.mainList;
3068   menuSubItem =      menuStrings.subList;
3069   flagBuf =         menuStrings.flagList;
3070   extendDataBuf =      &menuStrings.mainStrings[entry->actionListLength * 0];
3071   addressBuf =      &menuStrings.mainStrings[entry->actionListLength * 1];
3072   dataBuf =         &menuStrings.mainStrings[entry->actionListLength * 2];
3073   watchSizeBuf =      &menuStrings.mainStrings[entry->actionListLength * 3];   // these fields are wasteful
3074   watchSkipBuf =      &menuStrings.mainStrings[entry->actionListLength * 4];   // but the alternative is even more ugly
3075   watchPerLineBuf =   &menuStrings.mainStrings[entry->actionListLength * 5];
3076   watchAddValueBuf =   &menuStrings.mainStrings[entry->actionListLength * 6];
4147   menuItem         = menu_strings.main_list;
4148   menuSubItem         = menu_strings.sub_list;
4149   flagBuf            = menu_strings.flag_list;
4150   extendDataBuf      = &menu_strings.main_strings[entry->actionListLength * 0];
4151   addressBuf         = &menu_strings.main_strings[entry->actionListLength * 1];
4152   dataBuf            = &menu_strings.main_strings[entry->actionListLength * 2];
4153   typeBuf            = &menu_strings.main_strings[entry->actionListLength * 3];
4154   watchSizeBuf      = &menu_strings.main_strings[entry->actionListLength * 4];   // these fields are wasteful
4155   watchSkipBuf      = &menu_strings.main_strings[entry->actionListLength * 5];   // but the alternative is even more ugly
4156   watchPerLineBuf      = &menu_strings.main_strings[entry->actionListLength * 6];   //
4157   watchAddValueBuf   = &menu_strings.main_strings[entry->actionListLength * 7];   //
30774158
3078   sel = selection - 1;
3079
30804159   memset(flagBuf, 0, (kType_Max * entry->actionListLength) + 2);
30814160
3082   /* ----- create menu items ----- */
4161   /********** MENU CONSTRUCTION **********/
4162   /* create menu items */
30834163   for(i = 0; i < entry->actionListLength; i++)
30844164   {
30854165      CheatAction   * traverse = &entry->actionList[i];
30864166
3087      UINT32   type =               EXTRACT_FIELD(traverse->type, Type);
3088      UINT32   typeParameter =         EXTRACT_FIELD(traverse->type, TypeParameter);
3089      UINT32   operation =            EXTRACT_FIELD(traverse->type, Operation) |
3090                              EXTRACT_FIELD(traverse->type, OperationExtend) << 2;
3091      UINT32   operationParameter =   EXTRACT_FIELD(traverse->type, OperationParameter);
3092      UINT32   locationType =         EXTRACT_FIELD(traverse->type, LocationType);
3093      UINT32   locationParameter =      EXTRACT_FIELD(traverse->type, LocationParameter);
4167      UINT32   type               = EXTRACT_FIELD(traverse->type, Type);
4168      UINT32   typeParameter         = EXTRACT_FIELD(traverse->type, TypeParameter);
4169      UINT32   operation            = EXTRACT_FIELD(traverse->type, Operation) | EXTRACT_FIELD(traverse->type, OperationExtend) << 2;
4170      UINT32   operationParameter      = EXTRACT_FIELD(traverse->type, OperationParameter);
4171      UINT32   locationType         = EXTRACT_FIELD(traverse->type, LocationType);
4172      UINT32   locationParameter      = EXTRACT_FIELD(traverse->type, LocationParameter);
30944173
3095      UINT8      wasCommentOrSelect =   0;
4174      /* create item if label-select, extend comment or condition */
4175      if(!i)
4176      {
4177         /* do name field */
4178         menuItemInfo[total].sub_cheat = i;
4179         menuItemInfo[total].field_type = kType_Name;
4180         menuItem[total] = "Name";
30964181
3097      if(isSelect)
4182         if(entry->name)
4183            menuSubItem[total++] = entry->name;
4184         else
4185            menuSubItem[total++] = "(none)";
4186      }
4187      else
30984188      {
3099         /* ----- do extend name field ----- */
3100         menuItemInfo[total].subcheat = i;
3101         menuItemInfo[total].fieldType = kType_ExtendName;
4189         /* do label name field */
4190         menuItemInfo[total].sub_cheat = i;
4191         menuItemInfo[total].field_type = kType_ExtendName;
31024192         menuItem[total] = "Name";
31034193
31044194         if(traverse->optionalName)
r2762r2763
31074197            menuSubItem[total++] = "(none)";
31084198      }
31094199
3110      /* ----- create items if 1st code ----- */
3111      if(i == 0)
4200      if(!i)
31124201      {
3113         {
3114            /* ----- do name field ----- */
3115            menuItemInfo[total].subcheat = i;
3116            menuItemInfo[total].fieldType = kType_Name;
3117            menuItem[total] = "Name";
4202         /* do comment field */
4203         menuItemInfo[total].sub_cheat = i;
4204         menuItemInfo[total].field_type = kType_Comment;
4205         menuItem[total] = "Comment";
31184206
3119            if(entry->name)
3120               menuSubItem[total++] = entry->name;
3121            else
3122               menuSubItem[total++] = "(none)";
3123         }
4207         if(entry->comment)
4208            menuSubItem[total++] = entry->comment;
4209         else
4210            menuSubItem[total++] = "(none)";
4211      }
31244212
3125         {
3126            /* ----- do comment field ----- */
3127            menuItemInfo[total].subcheat = i;
3128            menuItemInfo[total].fieldType = kType_Comment;
3129            menuItem[total] = "Comment";
4213      {
4214         /* do 1st (previous-selection) activation key field */
4215         menuItemInfo[total].sub_cheat = i;
4216         menuItemInfo[total].field_type = kType_ActivationKey1;
31304217
3131            if(entry->comment)
3132               menuSubItem[total++] = entry->comment;
3133            else
3134               menuSubItem[total++] = "(none)";
3135         }
4218         if(locationType == kLocation_Custom && locationParameter == kCustomLocation_Select)
4219            menuItem[total] = "Activation Key - Prev";
4220         else
4221            menuItem[total] = "Activation Key - 1st";
31364222
3137         {
3138            /* ----- do 1st activation key field ----- */
3139            menuItemInfo[total].subcheat = i;
3140            menuItemInfo[total].fieldType = kType_ActivationKey1;
3141            menuItem[total] = "Activation Key (1st)";
4223         if(entry->flags & kCheatFlag_HasActivationKey1)
4224            menuSubItem[total++] = astring_c(input_code_name(tempString1, entry->activationKey1));
4225         else
4226            menuSubItem[total++] = "(none)";
4227      }
31424228
3143            if((entry->flags & kCheatFlag_HasActivationKey1))
3144               menuSubItem[total++] = astring_c(input_code_name(temp_string_1, entry->activationKey1));
3145            else
3146               menuSubItem[total++] = "(none)";
3147         }
4229      {
4230         /* do 2nd (next-selection) activation key field */
4231         menuItemInfo[total].sub_cheat = i;
4232         menuItemInfo[total].field_type = kType_ActivationKey2;
31484233
3149         {
3150            /* ----- do 2nd activation key field ----- */
3151            menuItemInfo[total].subcheat = i;
3152            menuItemInfo[total].fieldType = kType_ActivationKey2;
3153            menuItem[total] = "Activation Key (2nd)";
4234         if(locationType == kLocation_Custom && locationParameter == kCustomLocation_Select)
4235            menuItem[total] = "Activation Key - Next";
4236         else
4237            menuItem[total] = "Activation Key - 2nd";
31544238
3155            if((entry->flags & kCheatFlag_HasActivationKey2))
3156               menuSubItem[total++] = astring_c(input_code_name(temp_string_2, entry->activationKey2));
3157            else
3158               menuSubItem[total++] = "(none)";
3159         }
4239         if(entry->flags & kCheatFlag_HasActivationKey2)
4240            menuSubItem[total++] = astring_c(input_code_name(tempString2, entry->activationKey2));
4241         else
4242            menuSubItem[total++] = "(none)";
4243      }
31604244
3161         /* ----- is this label-selection cheat ? ----- */
3162         if((locationType == kLocation_Custom) && (locationParameter == kCustomLocation_Select))
3163            isSelect = 1;
4245      {
4246         /* do type code field */
4247         menuItemInfo[total].sub_cheat = i;
4248         menuItemInfo[total].field_type = kType_Code;
4249         menuItem[total] = "Code";
4250
4251         sprintf(typeBuf[i], "%8.8X", traverse->type);
4252         menuSubItem[total++] = typeBuf[i];
31644253      }
31654254
3166      /* ----- create item if linked code on label-selection ----- */
3167      if(i && isSelect)
31684255      {
3169         /* ----- do link extension field ----- */
3170         menuItemInfo[total].subcheat = i;
3171         menuItemInfo[total].fieldType = kType_LinkExtension;
4256         /* do link field */
4257         menuItemInfo[total].sub_cheat = i;
4258         menuItemInfo[total].field_type = kType_Link;
4259         menuItem[total] = "Link";
4260         menuSubItem[total++] = TEST_FIELD(traverse->type, LinkEnable) ? "On" : "Off";
4261      }
4262
4263      {
4264         /* do link extension field */
4265         menuItemInfo[total].sub_cheat = i;
4266         menuItemInfo[total].field_type = kType_LinkExtension;
31724267         menuItem[total] = "Link Extension";
31734268         menuSubItem[total++] = TEST_FIELD(traverse->type, LinkExtension) ? "On" : "Off";
31744269      }
31754270
31764271      {
3177         /* ----- do type field ----- */
3178         menuItemInfo[total].subcheat = i;
3179         menuItemInfo[total].fieldType = kType_Type;
4272         /* do type field */
4273         menuItemInfo[total].sub_cheat = i;
4274         menuItemInfo[total].field_type = kType_Type;
31804275         menuItem[total] = "Type";
31814276
3182         if(locationType == kLocation_Custom)
3183         {
3184            if(locationParameter == kCustomLocation_Comment)
3185            {
3186               /* ----- comment ----- */
3187               wasCommentOrSelect = 1;
3188
3189               menuSubItem[total++] = kTypeNames[4];
3190            }
3191            else
3192            {
3193               if(locationParameter == kCustomLocation_Select)
3194               {
3195                  /* ----- label-selection ----- */
3196                  wasCommentOrSelect = 1;
3197
3198                  menuSubItem[total++] = kTypeNames[5];
3199               }
3200               else
3201                  menuSubItem[total++] = kTypeNames[type & 3];
3202            }
3203         }
4277         if(locationType == kLocation_Custom && locationParameter == kCustomLocation_Comment)
4278            menuSubItem[total++] = kTypeNames[4];
4279         else if(locationType == kLocation_Custom && locationParameter == kCustomLocation_Select)
4280            menuSubItem[total++] = kTypeNames[5];
32044281         else
32054282            menuSubItem[total++] = kTypeNames[type & 3];
32064283      }
32074284
3208      /* ----- create items if not comment or label-selection ----- */
3209      if(!wasCommentOrSelect)
32104285      {
3211         if(type != kType_Watch)
3212         {
3213            {
3214               /* ----- do one shot field ----- */
3215               menuItemInfo[total].subcheat = i;
3216               menuItemInfo[total].fieldType = kType_OneShot;
3217               menuItem[total] = "One Shot";
3218               menuSubItem[total++] = TEST_FIELD(traverse->type, OneShot) ? "On" : "Off";
3219            }
4286         /* do one shot field */
4287         menuItemInfo[total].sub_cheat = i;
4288         menuItemInfo[total].field_type = kType_OneShot;
4289         menuItem[total] = "One Shot";
4290         menuSubItem[total++] = TEST_FIELD(traverse->type, OneShot) ? "On" : "Off";
4291      }
32204292
3221            {
3222               /* ----- do restore previous value field ----- */
3223               menuItemInfo[total].subcheat = i;
3224               menuItemInfo[total].fieldType = kType_RestorePreviousValue;
3225               menuItem[total] = "Restore Previous Value";
3226               menuSubItem[total++] = TEST_FIELD(traverse->type, RestorePreviousValue) ? "On" : "Off";
3227            }
3228         }
4293      {
4294         /* do restore previous value field */
4295         menuItemInfo[total].sub_cheat = i;
4296         menuItemInfo[total].field_type = kType_RestorePreviousValue;
4297         menuItem[total] = "Restore Previous Value";
4298         menuSubItem[total++] = TEST_FIELD(traverse->type, RestorePreviousValue) ? "On" : "Off";
4299      }
32294300
3230         if((type == kType_NormalOrDelay) || (type == kType_WaitForModification))
4301      switch(type)
4302      {
4303         default:
32314304         {
3232            /* ----- do delay field ----- */
3233            menuItemInfo[total].subcheat = i;
3234            menuItemInfo[total].fieldType = kType_Delay;
4305            /* do delay field */
4306            menuItemInfo[total].sub_cheat = i;
4307            menuItemInfo[total].field_type = kType_Delay;
32354308
3236            if(   TEST_FIELD(traverse->type, OneShot) && TEST_FIELD(traverse->type, RestorePreviousValue) &&
3237               EXTRACT_FIELD(traverse->type, TypeParameter))
4309            if(TEST_FIELD(traverse->type, OneShot) && TEST_FIELD(traverse->type, RestorePreviousValue) && EXTRACT_FIELD(traverse->type, TypeParameter))
32384310               menuItem[total] = "Keep";
32394311            else
32404312               menuItem[total] = "Delay";
32414313
32424314            menuSubItem[total++] = kNumbersTable[typeParameter];
32434315         }
4316         break;
32444317
3245         if(type == kType_IgnoreIfDecrementing)
4318         case kType_IgnoreIfDecrementing:
32464319         {
3247            /* ----- do ignore decrement by field ----- */
3248            menuItemInfo[total].subcheat = i;
3249            menuItemInfo[total].fieldType = kType_IgnoreDecrementBy;
4320            /* do ignore decrement by field */
4321            menuItemInfo[total].sub_cheat = i;
4322            menuItemInfo[total].field_type = kType_IgnoreDecrementBy;
32504323            menuItem[total] = "Ignore Decrement By";
32514324            menuSubItem[total++] = kNumbersTable[typeParameter];
32524325         }
4326         break;
32534327
3254         if(type == kType_Watch)
4328         case kType_Watch:
32554329         {
3256            {
3257               /* ----- do watch size field ----- */
3258               sprintf(watchSizeBuf[i], "%d", (traverse->originalDataField & 0xFF) + 1);
4330            /* do watch size field */
4331            sprintf(watchSizeBuf[i], "%d", (traverse->originalDataField & 0xFF) + 1);
32594332
3260               menuItemInfo[total].subcheat = i;
3261               menuItemInfo[total].fieldType = kType_WatchSize;
3262               menuItem[total] = "Watch Size";
3263               menuSubItem[total++] = watchSizeBuf[i];
3264            }
4333            menuItemInfo[total].sub_cheat = i;
4334            menuItemInfo[total].field_type = kType_WatchSize;
4335            menuItem[total] = "Watch Size";
4336            menuSubItem[total++] = watchSizeBuf[i];
4337         }
32654338
3266            {
3267               /* ----- do watch skip field ----- */
3268               sprintf(watchSkipBuf[i], "%d", (traverse->data >> 8) & 0xFF);
4339         {
4340            /* do watch skip field */
4341            sprintf(watchSkipBuf[i], "%d", (traverse->data >> 8) & 0xFF);
32694342
3270               menuItemInfo[total].subcheat = i;
3271               menuItemInfo[total].fieldType = kType_WatchSkip;
3272               menuItem[total] = "Watch Skip";
3273               menuSubItem[total++] = watchSkipBuf[i];
3274            }
4343            menuItemInfo[total].sub_cheat = i;
4344            menuItemInfo[total].field_type = kType_WatchSkip;
4345            menuItem[total] = "Watch Skip";
4346            menuSubItem[total++] = watchSkipBuf[i];
4347         }
32754348
3276            {
3277               /* ----- do watch per line field ----- */
3278               sprintf(watchPerLineBuf[i], "%d", (traverse->data >> 16) & 0xFF);
4349         {
4350            /* do watch per line field */
4351            sprintf(watchPerLineBuf[i], "%d", (traverse->data >> 16) & 0xFF);
32794352
3280               menuItemInfo[total].subcheat = i;
3281               menuItemInfo[total].fieldType = kType_WatchPerLine;
3282               menuItem[total] = "Watch Per Line";
3283               menuSubItem[total++] = watchPerLineBuf[i];
3284            }
4353            menuItemInfo[total].sub_cheat = i;
4354            menuItemInfo[total].field_type = kType_WatchPerLine;
4355            menuItem[total] = "Watch Per Line";
4356            menuSubItem[total++] = watchPerLineBuf[i];
4357         }
32854358
3286            {
3287               /* ----- do watch add value field ----- */
3288               {
3289                  INT8   temp = (traverse->data >> 24) & 0xFF;
4359         {
4360            /* do watch add value field */
4361            INT8 temp = (traverse->data >> 24) & 0xFF;
32904362
3291                  if(temp < 0)
3292                     sprintf(watchAddValueBuf[i], "-%.2X", -temp);
3293                  else
3294                     sprintf(watchAddValueBuf[i], "%.2X", temp);
3295               }
4363            if(temp < 0)
4364               sprintf(watchAddValueBuf[i], "-%.2X", -temp);
4365            else
4366               sprintf(watchAddValueBuf[i], "%.2X", temp);
32964367
3297               menuItemInfo[total].subcheat = i;
3298               menuItemInfo[total].fieldType = kType_WatchAddValue;
3299               menuItem[total] = "Watch Add Value";
3300               menuSubItem[total++] = watchAddValueBuf[i];
3301            }
4368            menuItemInfo[total].sub_cheat = i;
4369            menuItemInfo[total].field_type = kType_WatchAddValue;
4370            menuItem[total] = "Watch Add Value";
4371            menuSubItem[total++] = watchAddValueBuf[i];
4372         }
33024373
3303            {
3304               /* ----- do watch format field ----- */
3305               menuItemInfo[total].subcheat = i;
3306               menuItemInfo[total].fieldType = kType_WatchFormat;
3307               menuItem[total] = "Watch Format";
3308               menuSubItem[total++] = kWatchDisplayTypeStringList[(typeParameter >> 0) & 0x03];
3309            }
4374         {
4375            /* do watch format field */
4376            menuItemInfo[total].sub_cheat = i;
4377            menuItemInfo[total].field_type = kType_WatchFormat;
4378            menuItem[total] = "Watch Format";
4379            menuSubItem[total++] = kWatchDisplayTypeStringList[(typeParameter >> 0) & 0x03];
4380         }
33104381
3311            {
3312               /* ----- do watch label field ----- */
3313               menuItemInfo[total].subcheat = i;
3314               menuItemInfo[total].fieldType = kType_WatchLabel;
3315               menuItem[total] = "Watch Label";
3316               menuSubItem[total++] = ((typeParameter >> 2) & 0x01) ? "On" : "Off";
3317            }
4382         {
4383            /* do watch label field */
4384            menuItemInfo[total].sub_cheat = i;
4385            menuItemInfo[total].field_type = kType_WatchLabel;
4386            menuItem[total] = "Watch Label";
4387            menuSubItem[total++] = typeParameter >> 2 & 0x01 ? "On" : "Off";
33184388         }
3319         else
3320         {
3321            /* ----- do operation field ----- */
3322            menuItemInfo[total].subcheat = i;
3323            menuItemInfo[total].fieldType = kType_Operation;
3324            menuItem[total] = "Operation";
4389         break;
4390      }
33254391
3326            if((locationType != kLocation_IndirectIndexed) && (operation == kOperation_SetOrClearBits))
3327            {
3328               /* ----- ignore Set/Clear Bit item if not relative address ----- */
3329               operation = kOperation_WriteMask;
4392      {
4393         /* do operation field */
4394         menuItemInfo[total].sub_cheat = i;
4395         menuItemInfo[total].field_type = kType_Operation;
4396         menuItem[total] = "Operation";
33304397
3331               CLEAR_MASK_FIELD(traverse->type, OperationExtend);
3332               SET_FIELD(traverse->type, Operation, operation);
3333            }
4398         menuSubItem[total++] = kOperationNames[operation];
4399      }
33344400
3335            menuSubItem[total++] = kOperationNames[operation];
3336         }
4401      {
4402         /* do operation extend field */
4403         menuItemInfo[total].sub_cheat = i;
4404         menuItemInfo[total].field_type = kType_OperationExtend;
4405         menuItem[total] = "Operation Extend";
4406         menuSubItem[total++] = TEST_FIELD(traverse->type, OperationExtend) ? "On" : "Off";
4407      }
33374408
3338         if((operation == kOperation_WriteMask) && (locationType != kLocation_IndirectIndexed))
4409      if(locationType != kLocation_IndirectIndexed)
4410      {
4411         switch(operation)
33394412         {
3340            /* ----- do mask field ----- */
3341            int   numChars;
3342
3343            if(traverse->flags & kActionFlag_IgnoreMask)
4413            default:
33444414            {
3345               menuItemInfo[total].extraData = 0xFFFFFFFF;
3346               numChars = 8;
3347            }
3348            else
3349            {
3350               menuItemInfo[total].extraData = kCheatSizeMaskTable[EXTRACT_FIELD(traverse->type, BytesUsed)];
3351               numChars = kCheatSizeDigitsTable[EXTRACT_FIELD(traverse->type, BytesUsed)];
3352            }
4415               /* do mask field */
4416               int numChars;
33534417
3354            sprintf(extendDataBuf[i], "%.*X", numChars, traverse->extendData);
4418               if(traverse->flags & kActionFlag_IndexAddress)
4419               {
4420                  menuItemInfo[total].extra_data = 0xFFFFFFFF;
4421                  numChars = 8;
4422               }
4423               else
4424               {
4425                  menuItemInfo[total].extra_data = kCheatSizeMaskTable[EXTRACT_FIELD(traverse->type, BytesUsed)];
4426                  numChars = kCheatSizeDigitsTable[EXTRACT_FIELD(traverse->type, BytesUsed)];
4427               }
33554428
3356            menuItemInfo[total].subcheat = i;
3357            menuItemInfo[total].fieldType = kType_WriteMask;
3358            menuItem[total] = "Mask";
3359            menuSubItem[total++] = extendDataBuf[i];
3360         }
4429               sprintf(extendDataBuf[i], "%.*X", numChars, traverse->extendData & kCheatSizeMaskTable[EXTRACT_FIELD(traverse->type, BytesUsed)]);
33614430
3362         if(operation == kOperation_AddSubtract)
3363         {
3364            {
3365               /* ----- do add/subtract field ----- */
3366               menuItemInfo[total].subcheat = i;
3367               menuItemInfo[total].fieldType = kType_AddSubtract;
3368               menuItem[total] = "Add/Subtract";
3369               menuSubItem[total++] = kAddSubtractNames[operationParameter];
4431               menuItemInfo[total].sub_cheat = i;
4432               menuItemInfo[total].field_type = kType_WriteMask;
4433               menuItem[total] = "Mask";
4434               menuSubItem[total++] = extendDataBuf[i];
33704435            }
4436            break;
33714437
3372            if(locationType != kLocation_IndirectIndexed)
4438            case kOperation_AddSubtract:
33734439            {
4440               {
4441                  /* do add/subtract field */
4442                  menuItemInfo[total].sub_cheat = i;
4443                  menuItemInfo[total].field_type = kType_AddSubtract;
4444                  menuItem[total] = "Add/Subtract";
4445                  menuSubItem[total++] = kAddSubtractNames[operationParameter];
4446               }
4447
33744448               if(operationParameter)
33754449               {
3376                  /* ----- do subtract minimum field ----- */
4450                  /* do subtract minimum field */
33774451                  sprintf(extendDataBuf[i], "%.8X", traverse->extendData);
33784452
3379                  menuItemInfo[total].subcheat = i;
3380                  menuItemInfo[total].fieldType = kType_SubtractMinimum;
4453                  menuItemInfo[total].sub_cheat = i;
4454                  menuItemInfo[total].field_type = kType_SubtractMinimum;
33814455                  menuItem[total] = "Minimum Boundary";
33824456                  menuSubItem[total++] = extendDataBuf[i];
33834457               }
33844458               else
33854459               {
3386                  /* ----- do add maximum field ----- */
4460                  /* do add maximum field */
33874461                  sprintf(extendDataBuf[i], "%.8X", traverse->extendData);
33884462
3389                  menuItemInfo[total].subcheat = i;
3390                  menuItemInfo[total].fieldType = kType_AddMaximum;
4463                  menuItemInfo[total].sub_cheat = i;
4464                  menuItemInfo[total].field_type = kType_AddMaximum;
33914465                  menuItem[total] = "Maximum Boundary";
33924466                  menuSubItem[total++] = extendDataBuf[i];
33934467               }
33944468            }
3395         }
4469            break;
33964470
3397         if((operation == kOperation_ForceRange) && (locationType != kLocation_IndirectIndexed))
3398         {
3399            /* ----- do range minimum field ----- */
3400            if(!EXTRACT_FIELD(traverse->type, BytesUsed))
3401               sprintf(extendDataBuf[i], "%.2X", (traverse->extendData >> 8) & 0xFF);
3402            else
3403               sprintf(extendDataBuf[i], "%.4X", (traverse->extendData >> 16) & 0xFFFF);
3404
3405            menuItemInfo[total].subcheat = i;
3406            menuItemInfo[total].fieldType = kType_RangeMinimum;
3407            menuItem[total] = "Range Minimum";
3408            menuSubItem[total++] = extendDataBuf[i];
3409
3410            /* ----- do range maximum field ----- */
3411            if(!EXTRACT_FIELD(traverse->type, BytesUsed))
4471            case kOperation_ForceRange:
34124472            {
3413               sprintf(extendDataBuf[i] + 3, "%.2X", (traverse->extendData >> 0) & 0xFF);
3414               menuSubItem[total] = extendDataBuf[i] + 3;
3415            }
3416            else
3417            {
3418               sprintf(extendDataBuf[i] + 7, "%.4X", (traverse->extendData >> 0) & 0xFFFF);
3419               menuSubItem[total] = extendDataBuf[i] + 7;
3420            }
3421
3422            menuItemInfo[total].subcheat = i;
3423            menuItemInfo[total].fieldType = kType_RangeMaximum;
3424            menuItem[total++] = "Range Maximum";
3425         }
3426
3427         if(operation == kOperation_SetOrClearBits)
3428         {
3429            /* ----- do set/clear field ----- */
3430            menuItemInfo[total].subcheat = i;
3431            menuItemInfo[total].fieldType = kType_SetClear;
3432            menuItem[total] = "Set/Clear";
3433            menuSubItem[total++] = kSetClearNames[operationParameter];
3434         }
3435
3436         if(operation == kOperation_WriteMatch)
3437         {
3438            /* ----- do match value field ----- */
3439            menuItemInfo[total].subcheat = i;
3440            menuItemInfo[total].fieldType = kType_WriteMatch;
3441            menuItem[total] = "Match to Write";
3442
3443            {
3444               int   numChars;
3445
3446               if(traverse->flags & kActionFlag_IgnoreMask)
34474473               {
3448                  menuItemInfo[total].extraData = 0xFFFFFFFF;
3449                  numChars = 8;
3450               }
3451               else
3452               {
3453                  menuItemInfo[total].extraData = kCheatSizeMaskTable[EXTRACT_FIELD(traverse->type, BytesUsed)];
3454                  numChars = kCheatSizeDigitsTable[EXTRACT_FIELD(traverse->type, BytesUsed)];
3455               }
4474                  /* do range minimum field */
4475                  if(!EXTRACT_FIELD(traverse->type, BytesUsed))
4476                     sprintf(extendDataBuf[i], "%.2X", (traverse->extendData >> 8) & 0xFF);
4477                  else
4478                     sprintf(extendDataBuf[i], "%.4X", (traverse->extendData >> 16) & 0xFFFF);
34564479
3457               sprintf(extendDataBuf[i], "%.*X", numChars, traverse->extendData);
3458            }
3459
3460            menuSubItem[total++] = extendDataBuf[i];
3461         }
3462
3463         if((operation != kOperation_None) || (type == kType_Watch))
3464         {
3465            UINT32   userSelect =      TEST_FIELD(entry->actionList[0].type, UserSelectEnable);
3466            UINT32   bytesUsed =         EXTRACT_FIELD(traverse->type, BytesUsed);
3467
3468            if(type != kType_Watch)
3469            {
3470               {
3471                  /* ----- do data field ----- */
3472
3473                  sprintf(dataBuf[i], "%.*X (%d)", (int)kCheatSizeDigitsTable[bytesUsed], traverse->originalDataField, traverse->originalDataField);
3474
3475                  menuItemInfo[total].subcheat = i;
3476                  menuItemInfo[total].fieldType = kType_Data;
3477                  menuItemInfo[total].extraData = kCheatSizeMaskTable[bytesUsed];
3478                  menuItem[total] = "Data";
3479                  menuSubItem[total++] = dataBuf[i];
4480                  menuItemInfo[total].sub_cheat = i;
4481                  menuItemInfo[total].field_type = kType_RangeMinimum;
4482                  menuItem[total] = "Range Minimum";
4483                  menuSubItem[total++] = extendDataBuf[i];
34804484               }
34814485
3482               if(!i)
34834486               {
3484                  /* ----- do user select field ----- */
3485                  menuItemInfo[total].subcheat = i;
3486                  menuItemInfo[total].fieldType = kType_UserSelect;
3487                  menuItem[total] = "User Select";
3488                  menuSubItem[total++] = userSelect ? "On" : "Off";
3489               }
3490
3491               if(!i && userSelect)
3492               {
4487                  /* do range maximum field */
4488                  if(!EXTRACT_FIELD(traverse->type, BytesUsed))
34934489                  {
3494                     /* ----- do user select minimum displayed value field ----- */
3495                     menuItemInfo[total].subcheat = i;
3496                     menuItemInfo[total].fieldType = kType_UserSelectMinimumDisp;
3497                     menuItem[total] = "Minimum Displayed Value";
3498                     menuSubItem[total++] = kNumbersTable[EXTRACT_FIELD(traverse->type, UserSelectMinimumDisplay)];
4490                     sprintf(extendDataBuf[i] + 3, "%.2X", (traverse->extendData >> 0) & 0xFF);
4491                     menuSubItem[total] = extendDataBuf[i] + 3;
34994492                  }
3500
4493                  else
35014494                  {
3502                     /* ----- do user select minimum value field ----- */
3503                     menuItemInfo[total].subcheat = i;
3504                     menuItemInfo[total].fieldType = kType_UserSelectMinimum;
3505                     menuItem[total] = "Minimum Value";
3506                     menuSubItem[total++] = kNumbersTable[EXTRACT_FIELD(traverse->type, UserSelectMinimum)];
4495                     sprintf(extendDataBuf[i] + 7, "%.4X", (traverse->extendData >> 0) & 0xFFFF);
4496                     menuSubItem[total] = extendDataBuf[i] + 7;
35074497                  }
3508               }
35094498
3510               if(userSelect)
3511               {
3512                  /* ----- do user select BCD field ----- */
3513                  menuItemInfo[total].subcheat = i;
3514                  menuItemInfo[total].fieldType = kType_UserSelectBCD;
3515                  menuItem[total] = "BCD";
3516                  menuSubItem[total++] = TEST_FIELD(traverse->type, UserSelectBCD) ? "On" : "Off";
4499                  menuItemInfo[total].sub_cheat = i;
4500                  menuItemInfo[total].field_type = kType_RangeMaximum;
4501                  menuItem[total++] = "Range Maximum";
35174502               }
3518
3519               if(userSelect || isSelect)
3520               {
3521                  /* ----- do prefill field ----- */
3522                  menuItemInfo[total].subcheat = i;
3523                  menuItemInfo[total].fieldType = kType_Prefill;
3524                  menuItem[total] = "Prefill";
3525                  menuSubItem[total++] = kPrefillNames[EXTRACT_FIELD(traverse->type, Prefill)];
3526               }
3527
3528               if(i && userSelect)
3529               {
3530                  /* ----- do copy previous value field ----- */
3531                  menuItemInfo[total].subcheat = i;
3532                  menuItemInfo[total].fieldType = kType_CopyPrevious;
3533                  menuItem[total] = "Copy Previous Value";
3534                  menuSubItem[total++] = TEST_FIELD(traverse->type, LinkCopyPreviousValue) ? "On" : "Off";
3535               }
35364503            }
4504            break;
35374505
4506            case kOperation_SetOrClearBits:
35384507            {
3539               /* ----- do byte length field ----- */
3540               menuItemInfo[total].subcheat = i;
3541               menuItemInfo[total].fieldType = kType_ByteLength;
3542               menuItem[total] = "Byte Length";
3543               menuSubItem[total++] = kSizeNames[bytesUsed];
4508               /* do set/clear field */
4509               menuItemInfo[total].sub_cheat = i;
4510               menuItemInfo[total].field_type = kType_SetClear;
4511               menuItem[total] = "Set/Clear";
4512               menuSubItem[total++] = kSetClearNames[operationParameter];
35444513            }
4514            break;
4515         }
4516      }
35454517
3546            if(bytesUsed > 0)
3547            {
3548               /* ----- do endianness field ----- */
3549               menuItemInfo[total].subcheat = i;
3550               menuItemInfo[total].fieldType = kType_Endianness;
3551               menuItem[total] = "Endianness";
3552               menuSubItem[total++] = kEndiannessNames[EXTRACT_FIELD(traverse->type, Endianness)];
3553            }
4518      {
4519         /* do data field */
4520         sprintf(dataBuf[i], "%.*X (%d)",
4521               (int)kCheatSizeDigitsTable[EXTRACT_FIELD(traverse->type, BytesUsed)],
4522               traverse->originalDataField,
4523               traverse->originalDataField);
35544524
3555            {
3556               /* ----- do location type field ----- */
3557               menuItemInfo[total].subcheat = i;
3558               menuItemInfo[total].fieldType = kType_LocationType;
3559               menuItem[total] = "Location";
4525         menuItemInfo[total].sub_cheat = i;
4526         menuItemInfo[total].field_type = kType_Data;
4527         menuItemInfo[total].extra_data = kCheatSizeMaskTable[EXTRACT_FIELD(traverse->type, BytesUsed)];
4528         menuItem[total] = "Data";
4529         menuSubItem[total++] = dataBuf[i];
4530      }
35604531
3561               if(locationType == kLocation_Custom)
3562                  menuSubItem[total++] = kCustomLocationNames[locationParameter];
3563               else
3564                  menuSubItem[total++] = kLocationNames[locationType];
3565            }
4532      {
4533         /* do user select field */
4534         menuItemInfo[total].sub_cheat = i;
4535         menuItemInfo[total].field_type = kType_UserSelect;
4536         menuItem[total] = "User Select";
4537         menuSubItem[total++] = EXTRACT_FIELD(traverse->type, UserSelectEnable) ? "On" : "Off";
4538      }
35664539
3567            if(   (locationType == kLocation_Standard) || (locationType == kLocation_HandlerMemory) ||
3568               (locationType == kLocation_ProgramSpace))
3569            {
3570               /* ----- do cpu field ----- */
3571               menuItemInfo[total].subcheat = i;
3572               menuItemInfo[total].fieldType = kType_CPU;
3573               menuItem[total] = "CPU";
3574               menuSubItem[total++] = kNumbersTable[locationParameter];
3575            }
4540      {
4541         /* do user select minimum displayed value field */
4542         menuItemInfo[total].sub_cheat = i;
4543         menuItemInfo[total].field_type = kType_UserSelectMinimumDisp;
4544         menuItem[total] = "Minimum Displayed Value";
4545         menuSubItem[total++] = kNumbersTable[EXTRACT_FIELD(traverse->type, UserSelectMinimumDisplay)];
4546      }
35764547
3577            if(locationType == kLocation_MemoryRegion)
3578            {
3579               /* ----- do region field ----- */
3580               menuItemInfo[total].subcheat = i;
3581               menuItemInfo[total].fieldType = kType_Region;
3582               menuItem[total] = "Region";
3583               menuSubItem[total++] = kRegionNames[locationParameter];
3584            }
4548      {
4549         /* do user select minimum value field */
4550         menuItemInfo[total].sub_cheat = i;
4551         menuItemInfo[total].field_type = kType_UserSelectMinimum;
4552         menuItem[total] = "Minimum Value";
4553         menuSubItem[total++] = kNumbersTable[EXTRACT_FIELD(traverse->type, UserSelectMinimum)];
4554      }
35854555
3586            if(locationType == kLocation_IndirectIndexed)
3587            {
3588               {
3589                  /* ----- do packed CPU field ----- */
3590                  menuItemInfo[total].subcheat = i;
3591                  menuItemInfo[total].fieldType = kType_PackedCPU;
3592                  menuItem[total] = "CPU";
3593                  menuSubItem[total++] = kNumbersTable[(locationParameter >> 2) & 7];
3594               }
4556      {
4557         /* do user select BCD field */
4558         menuItemInfo[total].sub_cheat = i;
4559         menuItemInfo[total].field_type = kType_UserSelectBCD;
4560         menuItem[total] = "BCD";
4561         menuSubItem[total++] = TEST_FIELD(traverse->type, UserSelectBCD) ? "On" : "Off";
4562      }
35954563
3596               {
3597                  /* ----- do packed size field ----- */
3598                  menuItemInfo[total].subcheat = i;
3599                  menuItemInfo[total].fieldType = kType_PackedSize;
3600                  menuItem[total] = "Address Size";
3601                  menuSubItem[total++] = kNumbersTable[(locationParameter & 3) + 1];
3602               }
4564      {
4565         /* do copy previous value field */
4566         menuItemInfo[total].sub_cheat = i;
4567         menuItemInfo[total].field_type = kType_CopyPrevious;
4568         menuItem[total] = "Copy Previous Value";
4569         menuSubItem[total++] = TEST_FIELD(traverse->type, LinkCopyPreviousValue) ? "On" : "Off";
4570      }
36034571
3604               {
3605                  /* ----- do address index field ----- */
4572      {
4573         /* do prefill field */
4574         menuItemInfo[total].sub_cheat = i;
4575         menuItemInfo[total].field_type = kType_Prefill;
4576         menuItem[total] = "Prefill";
4577         menuSubItem[total++] = kPrefillNames[EXTRACT_FIELD(traverse->type, Prefill)];
4578      }
36064579
3607                  /* ---- swap if negative ----- */
3608                  if(traverse->extendData & 0x80000000)
3609                  {
3610                     int   temp = traverse->extendData;
4580      {
4581         /* do byte length field */
4582         menuItemInfo[total].sub_cheat = i;
4583         menuItemInfo[total].field_type = kType_ByteLength;
4584         menuItem[total] = "Byte Length";
4585         menuSubItem[total++] = kByteSizeStringList[EXTRACT_FIELD(traverse->type, BytesUsed)];
4586      }
36114587
3612                     temp = -temp;
4588      {
4589         /* do endianness field */
4590         menuItemInfo[total].sub_cheat = i;
4591         menuItemInfo[total].field_type = kType_Endianness;
4592         menuItem[total] = "Endianness";
4593         menuSubItem[total++] = kEndiannessNames[EXTRACT_FIELD(traverse->type, Endianness)];
4594      }
36134595
3614                     sprintf(extendDataBuf[i], "-%.8X", temp);
3615                  }
3616                  else
3617                     sprintf(extendDataBuf[i], "%.8X", traverse->extendData);
4596      {
4597         /* do location type field */
4598         menuItemInfo[total].sub_cheat = i;
4599         menuItemInfo[total].field_type = kType_LocationType;
4600         menuItem[total] = "Location";
36184601
3619                  menuItemInfo[total].subcheat = i;
3620                  menuItemInfo[total].fieldType = kType_AddressIndex;
3621                  menuItem[total] = "Address Index";
3622                  menuSubItem[total++] = extendDataBuf[i];
3623               }
3624            }
4602         if(locationType == kLocation_Custom)
4603            /* "Comment", "EEPROM", "Select" */
4604            menuSubItem[total++] = kCustomLocationNames[locationParameter];
4605         else
4606            /* "Normal", "Region", "Mapped Memory", "Relative Address" */
4607            menuSubItem[total++] = kLocationNames[locationType];
4608      }
36254609
4610      if(locationType != kLocation_IndirectIndexed)
4611      {
4612         if(locationType != kLocation_MemoryRegion)
4613         {
4614            /* do cpu field */
4615            menuItemInfo[total].sub_cheat = i;
4616            menuItemInfo[total].field_type = kType_CPU;
4617            menuItem[total] = "CPU";
4618            menuSubItem[total++] = kNumbersTable[locationParameter];
4619         }
4620         else
4621         {
4622            /* do region field */
4623            menuItemInfo[total].sub_cheat = i;
4624            menuItemInfo[total].field_type = kType_Region;
4625            menuItem[total] = "Region";
4626            menuSubItem[total++] = kRegionNames[locationParameter];
4627         }
4628      }
4629      else
4630      {
4631         {
4632            /* do packed CPU field */
4633            menuItemInfo[total].sub_cheat = i;
4634            menuItemInfo[total].field_type = kType_PackedCPU;
4635            menuItem[total] = "CPU";
4636            menuSubItem[total++] = kNumbersTable[EXTRACT_FIELD(traverse->type, LocationParameterCPU)];
4637         }
4638
4639         {
4640            /* do packed size field */
4641            menuItemInfo[total].sub_cheat = i;
4642            menuItemInfo[total].field_type = kType_PackedSize;
4643            menuItem[total] = "Address Size";
4644            menuSubItem[total++] = kNumbersTable[(locationParameter & 3) + 1];
4645         }
4646
4647         {
4648            /* do address index field */
4649            if(traverse->extendData & 0x80000000)
36264650            {
3627               /* ----- do address field ----- */
3628               int   charsToPrint = 8;
4651               /* swap if negative */
4652               int temp = traverse->extendData;
36294653
3630               switch(EXTRACT_FIELD(traverse->type, LocationType))
3631               {
3632                  case kLocation_Standard:
3633                  case kLocation_HandlerMemory:
3634                  case kLocation_ProgramSpace:
3635                  {
3636                     CPUInfo   * cpuInfo = &cpuInfoList[EXTRACT_FIELD(traverse->type, LocationParameter)];
4654               temp = -temp;
36374655
3638                     charsToPrint = cpuInfo->addressCharsNeeded;
3639                     menuItemInfo[total].extraData = cpuInfo->addressMask;
3640                  }
3641                  break;
4656               sprintf(extendDataBuf[i], "-%.8X", temp);
4657            }
4658            else
4659               sprintf(extendDataBuf[i], "%.8X", traverse->extendData);
36424660
3643                  case kLocation_IndirectIndexed:
3644                  {
3645                     CPUInfo   * cpuInfo = &cpuInfoList[(EXTRACT_FIELD(traverse->type, LocationParameter) >> 2) & 7];
4661            menuItemInfo[total].sub_cheat = i;
4662            menuItemInfo[total].field_type = kType_AddressIndex;
4663            menuItem[total] = "Address Index";
4664            menuSubItem[total++] = extendDataBuf[i];
4665         }
4666      }
36464667
3647                     charsToPrint = cpuInfo->addressCharsNeeded;
3648                     menuItemInfo[total].extraData = cpuInfo->addressMask;
3649                  }
3650                  break;
4668      {
4669         /* do address field */
4670         cpu_region_info *info = get_cpu_info(0);
36514671
3652                  default:
3653                     menuItemInfo[total].extraData = 0xFFFFFFFF;
3654               }
4672         switch(EXTRACT_FIELD(traverse->type, LocationType))
4673         {
4674            case kLocation_Standard:
4675            case kLocation_HandlerMemory:
4676            case kLocation_MemoryRegion:
4677            case kLocation_IndirectIndexed:
4678               menuItemInfo[total].extra_data = info->addressMask;
4679               break;
36554680
3656               sprintf(addressBuf[i], "%.*X", charsToPrint, traverse->address);
4681            default:
4682               menuItemInfo[total].extra_data = 0xFFFFFFFF;
4683         }
36574684
3658               menuItemInfo[total].subcheat = i;
3659               menuItemInfo[total].fieldType = kType_Address;
3660               menuItem[total] = "Address";
3661               menuSubItem[total++] = addressBuf[i];
3662            }
3663         }
4685         sprintf(addressBuf[i], "%.*X", get_address_length(EXTRACT_FIELD(traverse->type, LocationParameter)), traverse->address);
4686
4687         menuItemInfo[total].sub_cheat = i;
4688         menuItemInfo[total].field_type = kType_Address;
4689         menuItem[total] = "Address";
4690         menuSubItem[total++] = addressBuf[i];
36644691      }
36654692
3666      if(i < (entry->actionListLength - 1))
4693      if(i < entry->actionListLength - 1)
36674694      {
3668         menuItemInfo[total].subcheat = i;
3669         menuItemInfo[total].fieldType = kType_Divider;
3670         menuItem[total] = "==========";
4695         /* do divider */
4696         menuItemInfo[total].sub_cheat = i;
4697         menuItemInfo[total].field_type = kType_Divider;
4698         menuItem[total] = MENU_SEPARATOR_ITEM;
36714699         menuSubItem[total++] = NULL;
36724700      }
36734701   }
36744702
3675   menuItemInfo[total].subcheat =   0;            // return
3676   menuItemInfo[total].fieldType =   kType_Return;
3677   menuItem[total] =            "Return to Prior Menu";
3678   menuSubItem[total++] =         NULL;
4703   /* ##### RETURN ##### */
4704   menuItemInfo[total].sub_cheat = 0;
4705   menuItemInfo[total].field_type = kType_Return;
4706   menuItem[total] = "Return to Prior Menu";
4707   menuSubItem[total++] = NULL;
36794708
3680   menuItemInfo[total].subcheat =   0;            // terminate arrey
3681   menuItemInfo[total].fieldType =   kType_Return;
3682   menuItem[total] =            NULL;
3683   menuSubItem[total] =         NULL;
4709   /* ##### TERMINATE ARREY ##### */
4710   menuItemInfo[total].sub_cheat = 0;
4711   menuItemInfo[total].field_type = kType_Return;
4712   menuItem[total] = NULL;
4713   menuSubItem[total] = NULL;
36844714
3685   /* ----- adjuste cursor position ----- */
4715   /* adjust cursor position */
36864716   if(sel < 0)
36874717      sel = 0;
36884718   if(sel >= total)
36894719      sel = total - 1;
36904720
36914721   info = &menuItemInfo[sel];
3692   action = &entry->actionList[info->subcheat];
4722   action = &entry->actionList[info->sub_cheat];
36934723
3694   /* ----- higlighted sub-item if edit mode ----- */
4724   /* higlighted sub-item if edit mode */
36954725   if(editActive)
36964726      flagBuf[sel] = 1;
36974727
3698   /* ---- draw it ----- */
4728   /* draw it */
36994729   old_style_menu(menuItem, menuSubItem, flagBuf, sel, 0);
37004730
37014731   /********** KEY HANDLING **********/
3702   if(AltKeyPressed())
3703      increment <<= 4;
3704   if(ControlKeyPressed())
3705      increment <<= 8;
3706   if(ShiftKeyPressed())
3707      increment <<= 16;
3708
3709   if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
4732   if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
37104733   {
37114734      editActive = 0;
37124735      dirty = 1;
37134736
37144737      switch(info->fieldType)
37154738      {
3716            case kType_Name:
3717               currentNameTemplate--;
3718
3719               if(currentNameTemplate < 0)
3720               {
3721                  currentNameTemplate = 0;
3722
3723                  while(kCheatNameTemplates[currentNameTemplate + 1][0])
3724                  {
3725                     currentNameTemplate++;
3726                  }
3727               }
3728
3729               entry->name = realloc(entry->name, strlen(kCheatNameTemplates[currentNameTemplate]) + 1);
3730               strcpy(entry->name, kCheatNameTemplates[currentNameTemplate]);
3731               break;
3732/*
3733            case kType_ActivationKey1:
4739/*          case kType_ActivationKey1:
37344740            case kType_ActivationKey2:
37354741                if(info->fieldType == kType_ActivationKey1)
37364742                {
37374743                    entry->activationKey1--;
37384744
3739                    if(entry->activationKey1 < 0)
4745                if(entry->activationKey1 < 0)
37404746                        entry->activationKey1 = __code_max - 1;
37414747                    if(entry->activationKey1 >= __code_max)
37424748                        entry->activationKey1 = 0;
r2762r2763
37564762                }
37574763                break;
37584764*/
4765         case kType_Link:
4766            TOGGLE_MASK_FIELD(action->type, LinkEnable);
4767            break;
4768
37594769         case kType_LinkExtension:
37604770            TOGGLE_MASK_FIELD(action->type, LinkExtension);
37614771            break;
37624772
37634773         case kType_Type:
37644774         {
3765            UINT8   handled = 0;
4775            UINT8 handled = 0;
37664776
3767            CLEAR_MASK_FIELD(action->type, OperationExtend);
3768
37694777            if(EXTRACT_FIELD(action->type, LocationType) == kLocation_Custom)
37704778            {
3771               UINT32   locationParameter = EXTRACT_FIELD(action->type, LocationParameter);
4779               UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameter);
37724780
37734781               if(locationParameter == kCustomLocation_Comment)
37744782               {
4783                  /* "Comment" -> "Watch" */
37754784                  SET_FIELD(action->type, LocationParameter, 0);
37764785                  SET_FIELD(action->type, LocationType, kLocation_Standard);
37774786                  SET_FIELD(action->type, Type, kType_Watch);
37784787                  SET_FIELD(action->type, Operation, kOperation_None);
3779                  SET_MASK_FIELD(action->type, OperationExtend);
37804788
37814789                  handled = 1;
37824790               }
37834791               else if(locationParameter == kCustomLocation_Select)
37844792               {
4793                  /* "Select" -> "Comment" */
37854794                  SET_FIELD(action->type, LocationParameter, kCustomLocation_Comment);
37864795                  SET_FIELD(action->type, LocationType, kLocation_Custom);
37874796                  SET_FIELD(action->type, Type, 0);
r2762r2763
37924801
37934802            if(!handled)
37944803            {
3795               UINT32   type = EXTRACT_FIELD(action->type, Type);
4804               UINT32 type = EXTRACT_FIELD(action->type, Type);
37964805
37974806               if(type == kType_NormalOrDelay)
37984807               {
4808                  /* "Normal/Delay" -> "Select" */
4809                  SET_FIELD(action->type, LocationType, kLocation_Custom);
37994810                  SET_FIELD(action->type, LocationParameter, kCustomLocation_Select);
3800                  SET_FIELD(action->type, LocationType, kLocation_Custom);
38014811                  SET_FIELD(action->type, Type, 0);
38024812               }
38034813               else
3804               {
38054814                  SET_FIELD(action->type, Type, type - 1);
3806               }
38074815            }
38084816         }
38094817         break;
r2762r2763
38174825            break;
38184826
38194827         case kType_Delay:
3820         case kType_IgnoreDecrementBy:
38214828         {
3822            UINT32   delay = (EXTRACT_FIELD(action->type, TypeParameter) - 1) & 7;
4829            UINT32 delay = (EXTRACT_FIELD(action->type, TypeParameter) - 1) & 7;
38234830
38244831            SET_FIELD(action->type, TypeParameter, delay);
38254832         }
r2762r2763
38474854
38484855         case kType_WatchFormat:
38494856         {
3850            UINT32   typeParameter = EXTRACT_FIELD(action->type, TypeParameter);
4857            UINT32 typeParameter = EXTRACT_FIELD(action->type, TypeParameter);
38514858
38524859            typeParameter = (typeParameter & 0xFFFFFFFC) | ((typeParameter - 0x00000001) & 0x0000003);
38534860            SET_FIELD(action->type, TypeParameter, typeParameter);
r2762r2763
38594866            break;
38604867
38614868         case kType_Operation:
3862         {
3863            UINT32   operation = ((EXTRACT_FIELD(action->type, Operation) | EXTRACT_FIELD(action->type, OperationExtend) << 2) - 1) & 7;
3864
3865            if(operation == kOperation_None)
3866               operation = kOperation_WriteMatch;
3867
3868            if(   (operation == kOperation_SetOrClearBits) &&
3869               !(EXTRACT_FIELD(action->type, LocationType) == kLocation_IndirectIndexed))
3870                  operation = (operation - 1) & 7;
3871
3872            if(operation >> 2)
3873               SET_MASK_FIELD(action->type, OperationExtend);
4869            if(EXTRACT_FIELD(action->type, Operation) == kOperation_WriteMask)
4870            {
4871               if(EXTRACT_FIELD(action->type, LocationType) == kLocation_IndirectIndexed)
4872                  SET_FIELD(action->type, Operation, kOperation_SetOrClearBits);
4873               else
4874                  SET_FIELD(action->type, Operation, kOperation_ForceRange);
4875            }
38744876            else
3875               CLEAR_MASK_FIELD(action->type, OperationExtend);
4877               SET_FIELD(action->type, Operation, EXTRACT_FIELD(action->type, Operation) - 1);
4878            break;
38764879
3877            SET_FIELD(action->type, Operation, operation);
3878         }
3879         break;
4880         case kType_OperationExtend:
4881            TOGGLE_MASK_FIELD(action->type, OperationExtend);
4882            break;
38804883
38814884         case kType_WriteMask:
3882         case kType_WriteMatch:
3883            action->extendData -= increment;
4885            action->extendData -= 1;
38844886            action->extendData &= info->extraData;
38854887            break;
38864888
r2762r2763
38984900               action->extendData = (action->extendData & 0xFFFF0000) | ((action->extendData - 0x00000001) & 0x0000FFFF);
38994901            break;
39004902
3901         case kType_AddressIndex:
39024903         case kType_SubtractMinimum:
39034904         case kType_AddMaximum:
3904            action->extendData -= increment;
4905         case kType_AddressIndex:
4906            action->extendData -= 1;
39054907            break;
39064908
39074909         case kType_AddSubtract:
r2762r2763
39104912            break;
39114913
39124914         case kType_Data:
3913            action->originalDataField -= increment;
4915            action->originalDataField -= 1;
39144916            action->originalDataField &= info->extraData;
39154917            action->data = action->originalDataField;
39164918            break;
r2762r2763
39314933            TOGGLE_MASK_FIELD(action->type, UserSelectBCD);
39324934            break;
39334935
4936         case kType_CopyPrevious:
4937            TOGGLE_MASK_FIELD(action->type, LinkCopyPreviousValue);
4938            break;
4939
39344940         case kType_Prefill:
39354941         {
3936            UINT32   prefill = (EXTRACT_FIELD(action->type, Prefill) - 1) & 3;
4942            UINT32 prefill = (EXTRACT_FIELD(action->type, Prefill) - 1) & 3;
39374943
39384944            SET_FIELD(action->type, Prefill, prefill);
39394945         }
3940            break;
4946         break;
39414947
3942         case kType_CopyPrevious:
3943            TOGGLE_MASK_FIELD(action->type, LinkCopyPreviousValue);
3944            break;
3945
39464948         case kType_ByteLength:
39474949         {
3948            UINT32   length = (EXTRACT_FIELD(action->type, BytesUsed) - 1) & 3;
4950            UINT32 length = (EXTRACT_FIELD(action->type, BytesUsed) - 1) & 3;
39494951
39504952            SET_FIELD(action->type, BytesUsed, length);
39514953         }
r2762r2763
39574959
39584960         case kType_LocationType:
39594961         {
3960            UINT32   locationType = EXTRACT_FIELD(action->type, LocationType);
3961            UINT32   locationParameter = EXTRACT_FIELD(action->type, LocationParameter);
4962            UINT32 locationType = EXTRACT_FIELD(action->type, LocationType);
39624963
3963            if(locationType == kLocation_Standard)
4964            switch(locationType)
39644965            {
3965               SET_FIELD(action->type, LocationType, kLocation_ProgramSpace);
3966               SET_FIELD(action->type, LocationParameter, (locationParameter << 2) & 0x1C);
3967            }
3968            else if(locationType == kLocation_Custom)
3969            {
3970               SET_FIELD(action->type, LocationType, kLocation_HandlerMemory);
3971               SET_FIELD(action->type, LocationParameter, 0);
3972            }
3973            else if(locationType == kLocation_IndirectIndexed)
3974            {
3975               SET_FIELD(action->type, LocationType, kLocation_Custom);
3976               SET_FIELD(action->type, LocationParameter, kCustomLocation_EEPROM);
3977            }
3978            else
3979            {
3980               locationType--;
4966               case kLocation_Standard:
4967                  /* "Normal" -> "Relative Address" */
4968                  SET_FIELD(action->type, LocationType, kLocation_IndirectIndexed);
4969                  SET_FIELD(action->type, LocationParameter, 0);
4970                  break;
39814971
3982               SET_FIELD(action->type, LocationType, locationType);
4972               case kLocation_Custom:
4973                  /* "EEPROM" -> "Mapped Memory" */
4974                  SET_FIELD(action->type, LocationType, kLocation_HandlerMemory);
4975                  SET_FIELD(action->type, LocationParameter, 0);
4976                  break;
4977
4978               case kLocation_IndirectIndexed:
4979                  /* "Relative Address" -> "EEPROM" */
4980                  SET_FIELD(action->type, LocationType, kLocation_Custom);
4981                  SET_FIELD(action->type, LocationParameter, kCustomLocation_EEPROM);
4982                  break;
4983
4984               default:
4985                  locationType--;
4986                  SET_FIELD(action->type, LocationType, locationType);
39834987            }
39844988         }
39854989         break;
r2762r2763
39874991         case kType_CPU:
39884992         case kType_Region:
39894993         {
3990            UINT32   locationParameter = EXTRACT_FIELD(action->type, LocationParameter);
4994            UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameter);
39914995
39924996            locationParameter = (locationParameter - 1) & 31;
39934997
r2762r2763
39975001
39985002         case kType_PackedCPU:
39995003         {
4000            UINT32   locationParameter = EXTRACT_FIELD(action->type, LocationParameter);
5004            UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameterCPU);
40015005
4002            locationParameter = ((locationParameter - 0x04) & 0x1C) | (locationParameter & 0x03);
5006            locationParameter = (locationParameter - 1) & 7;
40035007
4004            SET_FIELD(action->type, LocationParameter, locationParameter);
5008            SET_FIELD(action->type, LocationParameterCPU, locationParameter);
40055009         }
40065010         break;
40075011
40085012         case kType_PackedSize:
40095013         {
4010            UINT32   locationParameter = EXTRACT_FIELD(action->type, LocationParameter);
5014            UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameterOption);
40115015
4012            locationParameter = ((locationParameter - 0x01) & 0x03) | (locationParameter & 0x1C);
5016            locationParameter = (locationParameter - 1) & 3;
40135017
4014            SET_FIELD(action->type, LocationParameter, locationParameter);
5018            SET_FIELD(action->type, LocationParameterOption, locationParameter);
40155019         }
40165020         break;
40175021
40185022         case kType_Address:
4019            action->address -= increment;
5023            action->address -= 1;
40205024            action->address &= info->extraData;
40215025            break;
40225026
r2762r2763
40255029            break;
40265030      }
40275031   }
4028
4029   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
5032   else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
40305033   {
40315034      editActive = 0;
40325035      dirty = 1;
40335036
40345037      switch(info->fieldType)
40355038      {
4036            case kType_Name:
4037               currentNameTemplate++;
4038
4039               if((currentNameTemplate < 0) || !kCheatNameTemplates[currentNameTemplate][0])
4040               {
4041                  currentNameTemplate = 0;
4042               }
4043
4044               entry->name = realloc(entry->name, strlen(kCheatNameTemplates[currentNameTemplate]) + 1);
4045               strcpy(entry->name, kCheatNameTemplates[currentNameTemplate]);
4046               break;
4047/*
4048            case kType_ActivationKey1:
5039/*          case kType_ActivationKey1:
40495040            case kType_ActivationKey2:
40505041                if(info->fieldType == kType_ActivationKey1)
40515042                {
r2762r2763
40715062                }
40725063                break;
40735064*/
5065         case kType_Link:
5066            TOGGLE_MASK_FIELD(action->type, LinkEnable);
5067            break;
5068
40745069         case kType_LinkExtension:
40755070            TOGGLE_MASK_FIELD(action->type, LinkExtension);
40765071            break;
40775072
40785073         case kType_Type:
40795074         {
4080            UINT8   handled = 0;
5075            UINT8 handled = 0;
40815076
4082            CLEAR_MASK_FIELD(action->type, OperationExtend);
4083
40845077            if(EXTRACT_FIELD(action->type, LocationType) == kLocation_Custom)
40855078            {
4086               UINT32   locationParameter = EXTRACT_FIELD(action->type, LocationParameter);
5079               UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameter);
40875080
40885081               if(locationParameter == kCustomLocation_Comment)
40895082               {
5083                  /* "Comment" -> "Select" */
40905084                  SET_FIELD(action->type, LocationParameter, kCustomLocation_Select);
40915085                  SET_FIELD(action->type, LocationType, kLocation_Custom);
40925086                  SET_FIELD(action->type, Type, 0);
40935087
40945088                  handled = 1;
40955089               }
4096               else if(locationParameter == kCustomLocation_Select)
4097               {
4098                  SET_FIELD(action->type, LocationParameter, 0);
4099                  SET_FIELD(action->type, LocationType, kLocation_Standard);
4100                  SET_FIELD(action->type, Type, 0);
5090            }
5091            else if((EXTRACT_FIELD(action->type, LocationType) == kLocation_Custom) &&
5092                  (EXTRACT_FIELD(action->type, LocationParameter) == kCustomLocation_Select))
5093            {
5094               /* "Select" -> "Normal/Delay" */
5095               SET_FIELD(action->type, LocationParameter, 0);
5096               SET_FIELD(action->type, LocationType, kLocation_Standard);
5097               SET_FIELD(action->type, Type, 0);
41015098
4102                  handled = 1;
4103               }
5099               handled = 1;
41045100            }
41055101
41065102            if(!handled)
41075103            {
4108               UINT32   type = EXTRACT_FIELD(action->type, Type);
5104               UINT32 type = EXTRACT_FIELD(action->type, Type);
41095105
41105106               if(type == kType_Watch)
41115107               {
5108                  /* "Watch" -> "Comment" */
41125109                  SET_FIELD(action->type, LocationParameter, kCustomLocation_Comment);
41135110                  SET_FIELD(action->type, LocationType, kLocation_Custom);
41145111                  SET_FIELD(action->type, Type, 0);
41155112               }
41165113               else
4117               {
41185114                  SET_FIELD(action->type, Type, type + 1);
4119
4120                  if((type + 1) == kType_Watch)
4121                  {
4122                     SET_FIELD(action->type, Operation, kOperation_None);
4123                     SET_MASK_FIELD(action->type, OperationExtend);
4124                  }
4125               }
41265115            }
41275116         }
41285117         break;
r2762r2763
41365125            break;
41375126
41385127         case kType_Delay:
4139         case kType_IgnoreDecrementBy:
41405128         {
4141            UINT32   delay = (EXTRACT_FIELD(action->type, TypeParameter) + 1) & 7;
5129            UINT32 delay = (EXTRACT_FIELD(action->type, TypeParameter) + 1) & 7;
41425130
41435131            SET_FIELD(action->type, TypeParameter, delay);
41445132         }
r2762r2763
41665154
41675155         case kType_WatchFormat:
41685156         {
4169            UINT32   typeParameter = EXTRACT_FIELD(action->type, TypeParameter);
5157            UINT32 typeParameter = EXTRACT_FIELD(action->type, TypeParameter);
41705158
41715159            typeParameter = (typeParameter & 0xFFFFFFFC) | ((typeParameter + 0x00000001) & 0x0000003);
41725160            SET_FIELD(action->type, TypeParameter, typeParameter);
r2762r2763
41795167
41805168         case kType_Operation:
41815169         {
4182            UINT32   operation = ((EXTRACT_FIELD(action->type, Operation) | EXTRACT_FIELD(action->type, OperationExtend) << 2) + 1) & 7;
5170            CLEAR_MASK_FIELD(action->type, OperationExtend);
41835171
4184            if(operation > kOperation_WriteMatch)
4185               operation = kOperation_WriteMask;
4186
4187            if(   (operation == kOperation_SetOrClearBits) &&
4188               !(EXTRACT_FIELD(action->type, LocationType) == kLocation_IndirectIndexed))
4189                  operation = (operation + 1) & 7;
4190
4191            if(operation >> 2)
4192               SET_MASK_FIELD(action->type, OperationExtend);
5172            if(EXTRACT_FIELD(action->type, LocationType) == kLocation_IndirectIndexed)
5173            {
5174               if(EXTRACT_FIELD(action->type, Type) >= kOperation_SetOrClearBits)
5175                  SET_FIELD(action->type, Operation, 0);
5176               else
5177                  SET_FIELD(action->type, Operation, EXTRACT_FIELD(action->type, Operation) + 1);
5178            }
5179            else if(EXTRACT_FIELD(action->type, Operation) >= kOperation_ForceRange)
5180               SET_FIELD(action->type, Operation, 0);
41935181            else
4194               CLEAR_MASK_FIELD(action->type, OperationExtend);
4195
4196            SET_FIELD(action->type, Operation, operation);
5182               SET_FIELD(action->type, Operation, EXTRACT_FIELD(action->type, Operation) + 1);
41975183         }
41985184         break;
41995185
5186         case kType_OperationExtend:
5187            TOGGLE_MASK_FIELD(action->type, OperationExtend);
5188            break;
5189
42005190         case kType_WriteMask:
4201         case kType_WriteMatch:
4202            action->extendData += increment;
5191            action->extendData += 1;
42035192            action->extendData &= info->extraData;
42045193            break;
42055194
r2762r2763
42205209         case kType_AddressIndex:
42215210         case kType_SubtractMinimum:
42225211         case kType_AddMaximum:
4223            action->extendData += increment;
5212            action->extendData += 1;
42245213            break;
42255214
42265215         case kType_AddSubtract:
r2762r2763
42295218            break;
42305219
42315220         case kType_Data:
4232            action->originalDataField += increment;
5221            action->originalDataField += 1;
42335222            action->originalDataField &= info->extraData;
42345223            action->data = action->originalDataField;
42355224            break;
r2762r2763
42505239            TOGGLE_MASK_FIELD(action->type, UserSelectBCD);
42515240            break;
42525241
5242         case kType_CopyPrevious:
5243            TOGGLE_MASK_FIELD(action->type, LinkCopyPreviousValue);
5244            break;
5245
42535246         case kType_Prefill:
42545247         {
4255            UINT32   prefill = (EXTRACT_FIELD(action->type, Prefill) + 1) & 3;
5248            UINT32 prefill = (EXTRACT_FIELD(action->type, Prefill) + 1) & 3;
42565249
42575250            SET_FIELD(action->type, Prefill, prefill);
42585251         }
42595252            break;
42605253
4261         case kType_CopyPrevious:
4262            TOGGLE_MASK_FIELD(action->type, LinkCopyPreviousValue);
4263            break;
4264
42655254         case kType_ByteLength:
42665255         {
4267            UINT32   length = (EXTRACT_FIELD(action->type, BytesUsed) + 1) & 3;
5256            UINT32 length = (EXTRACT_FIELD(action->type, BytesUsed) + 1) & 3;
42685257
42695258            SET_FIELD(action->type, BytesUsed, length);
42705259         }
r2762r2763
42765265
42775266         case kType_LocationType:
42785267         {
4279            UINT32   locationType = EXTRACT_FIELD(action->type, LocationType);
4280            UINT32   locationParameter = EXTRACT_FIELD(action->type, LocationParameter);
5268            UINT32 locationType = EXTRACT_FIELD(action->type, LocationType);
42815269
4282            if(locationType == kLocation_ProgramSpace)
5270            switch(locationType)
42835271            {
4284               SET_FIELD(action->type, LocationType, kLocation_Standard);
4285               SET_FIELD(action->type, LocationParameter, (locationParameter >> 2) & 7);
4286            }
4287            else if(locationType == kLocation_Custom)
4288            {
4289               SET_FIELD(action->type, LocationType, kLocation_IndirectIndexed);
4290               SET_FIELD(action->type, LocationParameter, 0);
4291            }
4292            else if(locationType == kLocation_HandlerMemory)
4293            {
4294               SET_FIELD(action->type, LocationType, kLocation_Custom);
4295               SET_FIELD(action->type, LocationParameter, kCustomLocation_EEPROM);
4296            }
4297            else
4298            {
4299               locationType++;
5272               case kLocation_HandlerMemory:
5273                  /* "Mapped Memory" -> "EEPROM" */
5274                  SET_FIELD(action->type, LocationType, kLocation_Custom);
5275                  SET_FIELD(action->type, LocationParameter, kCustomLocation_EEPROM);
5276                  break;
43005277
4301               SET_FIELD(action->type, LocationType, locationType);
5278               case kLocation_Custom:
5279                  /* "EEPROM" -> "Relative Address" */
5280                  SET_FIELD(action->type, LocationType, kLocation_IndirectIndexed);
5281                  SET_FIELD(action->type, LocationParameter, 0);
5282                  break;
5283
5284               case kLocation_IndirectIndexed:
5285                  /* "Relative Address" -> "Normal" */
5286                  SET_FIELD(action->type, LocationType, kLocation_Standard);
5287                  SET_FIELD(action->type, LocationParameter, 0);
5288                  break;
5289
5290               default:
5291                  locationType++;
5292                  SET_FIELD(action->type, LocationType, locationType);
43025293            }
43035294         }
43045295         break;
r2762r2763
43065297         case kType_CPU:
43075298         case kType_Region:
43085299         {
4309            UINT32   locationParameter = EXTRACT_FIELD(action->type, LocationParameter);
5300            UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameter);
43105301
43115302            locationParameter = (locationParameter + 1) & 31;
43125303
r2762r2763
43165307
43175308         case kType_PackedCPU:
43185309         {
4319            UINT32   locationParameter = EXTRACT_FIELD(action->type, LocationParameter);
5310            UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameterCPU);
43205311
4321            locationParameter = ((locationParameter + 0x04) & 0x1C) | (locationParameter & 0x03);
5312            locationParameter = (locationParameter + 1) & 7;
43225313
4323            SET_FIELD(action->type, LocationParameter, locationParameter);
5314            SET_FIELD(action->type, LocationParameterCPU, locationParameter);
43245315         }
43255316         break;
43265317
43275318         case kType_PackedSize:
43285319         {
4329            UINT32   locationParameter = EXTRACT_FIELD(action->type, LocationParameter);
5320            UINT32 locationParameter = EXTRACT_FIELD(action->type, LocationParameterOption);
43305321
4331            locationParameter = ((locationParameter + 0x01) & 0x03) | (locationParameter & 0x1C);
5322            locationParameter = (locationParameter + 1) & 3;
43325323
4333            SET_FIELD(action->type, LocationParameter, locationParameter);
5324            SET_FIELD(action->type, LocationParameterOption, locationParameter);
43345325         }
43355326         break;
43365327
43375328         case kType_Address:
4338            action->address += increment;
5329            action->address += 1;
43395330            action->address &= info->extraData;
43405331            break;
43415332
r2762r2763
43445335            break;
43455336      }
43465337   }
4347
4348   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
5338   else if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
43495339   {
4350      sel++;
5340      if(--sel < 0)
5341         sel = total - 1;
43515342
4352      if(sel >= total)
4353         sel = 0;
4354
43555343      editActive = 0;
43565344   }
4357
4358   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
5345   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
43595346   {
4360      sel--;
5347      if(++sel >= total)
5348         sel = 0;
43615349
4362      if(sel < 0)
4363         sel = total - 1;
4364
43655350      editActive = 0;
43665351   }
4367
4368   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
5352   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
43695353   {
43705354      sel -= fullMenuPageHeight;
43715355
r2762r2763
43745358
43755359      editActive = 0;
43765360   }
4377
4378   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
5361   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
43795362   {
43805363      sel += fullMenuPageHeight;
43815364
r2762r2763
43845367
43855368      editActive = 0;
43865369   }
4387
4388   if(input_ui_pressed(machine, IPT_UI_SELECT))
5370   else if(input_ui_pressed(machine, IPT_UI_SELECT))
43895371   {
43905372      if(editActive)
4391      {
43925373         editActive = 0;
4393      }
43945374      else
43955375      {
43965376         switch(info->fieldType)
r2762r2763
44095389            case kType_SubtractMinimum:
44105390            case kType_RangeMinimum:
44115391            case kType_RangeMaximum:
4412            case kType_WriteMatch:
44135392            case kType_Data:
44145393            case kType_Address:
44155394               osd_readkey_unicode(1);
r2762r2763
44235402         }
44245403      }
44255404   }
5405   else if(input_ui_pressed(machine, IPT_UI_CANCEL))
5406   {
5407      if(editActive)
5408         editActive = 0;
5409      else
5410         sel = -1;
5411   }
44265412
44275413   /********** EDIT MODE **********/
44285414   if(editActive)
44295415   {
4430      /* ----- do edit text ----- */
5416      /* do edit text */
44315417      dirty = 1;
44325418
44335419      switch(info->fieldType)
r2762r2763
44645450            }
44655451            else
44665452            {
4467               int   code = input_code_poll_switches(FALSE);
5453               int code = input_code_poll_switches(FALSE);
44685454
44695455               if(code == KEYCODE_ESC)
44705456               {
r2762r2763
45055491
45065492         case kType_WatchSize:
45075493         {
4508            UINT32   temp = (action->originalDataField >> 0) & 0xFF;
5494            UINT32 temp = (action->originalDataField >> 0) & 0xFF;
45095495
45105496            temp++;
4511            temp = DoEditHexField(machine, temp) & 0xFF;
5497            temp = do_edit_hex_field(machine, temp) & 0xFF;
45125498            temp--;
45135499
45145500            action->originalDataField = (action->originalDataField & 0xFFFFFF00) | ((temp << 0) & 0x000000FF);
r2762r2763
45185504
45195505         case kType_WatchSkip:
45205506         {
4521            UINT32   temp = (action->originalDataField >> 8) & 0xFF;
5507            UINT32 temp = (action->originalDataField >> 8) & 0xFF;
45225508
4523            temp = DoEditHexField(machine, temp) & 0xFF;
5509            temp = do_edit_hex_field(machine, temp) & 0xFF;
45245510
45255511            action->originalDataField = (action->originalDataField & 0xFFFF00FF) | ((temp << 8) & 0x0000FF00);
45265512            action->data = action->originalDataField;
r2762r2763
45295515
45305516         case kType_WatchPerLine:
45315517         {
4532            UINT32   temp = (action->originalDataField >> 16) & 0xFF;
5518            UINT32 temp = (action->originalDataField >> 16) & 0xFF;
45335519
4534            temp = DoEditHexField(machine, temp) & 0xFF;
5520            temp = do_edit_hex_field(machine, temp) & 0xFF;
45355521
45365522            action->originalDataField = (action->originalDataField & 0xFF00FFFF) | ((temp << 16) & 0x00FF0000);
45375523            action->data = action->originalDataField;
r2762r2763
45405526
45415527         case kType_WatchAddValue:
45425528         {
4543            UINT32   temp = (action->originalDataField >> 24) & 0xFF;
5529            UINT32 temp = (action->originalDataField >> 24) & 0xFF;
45445530
45455531            temp = DoEditHexFieldSigned(temp, 0xFFFFFF80) & 0xFF;
45465532
r2762r2763
45505536         break;
45515537
45525538         case kType_WriteMask:
4553            action->extendData = DoEditHexField(machine, action->extendData);
5539            action->extendData = do_edit_hex_field(machine, action->extendData);
45545540            action->extendData &= info->extraData;
45555541            break;
45565542
45575543         case kType_AddMaximum:
45585544         case kType_SubtractMinimum:
4559         case kType_WriteMatch:
4560            action->extendData = DoEditHexField(machine, action->extendData);
5545            action->extendData = do_edit_hex_field(machine, action->extendData);
45615546            break;
45625547
45635548         case kType_RangeMinimum:
45645549         {
4565            UINT32   temp;
5550            UINT32 temp;
45665551
45675552            if(!TEST_FIELD(action->type, BytesUsed))
45685553            {
45695554               temp = (action->extendData >> 8) & 0xFF;
4570               temp = DoEditHexField(machine, temp) & 0xFF;
5555               temp = do_edit_hex_field(machine, temp) & 0xFF;
45715556
45725557               action->extendData = (action->extendData & 0xFF) | ((temp << 8) & 0xFF00);
45735558            }
45745559            else
45755560            {
45765561               temp = (action->extendData >> 16) & 0xFFFF;
4577               temp = DoEditHexField(machine, temp) & 0xFFFF;
5562               temp = do_edit_hex_field(machine, temp) & 0xFFFF;
45785563
45795564               action->extendData = (action->extendData & 0x0000FFFF) | ((temp << 16) & 0xFFFF0000);
45805565            }
r2762r2763
45835568
45845569         case kType_RangeMaximum:
45855570         {
4586            UINT32   temp;
5571            UINT32 temp;
45875572
45885573            if(!TEST_FIELD(action->type, BytesUsed))
45895574            {
45905575               temp = action->extendData & 0xFF;
4591               temp = DoEditHexField(machine, temp) & 0xFF;
5576               temp = do_edit_hex_field(machine, temp) & 0xFF;
45925577
45935578               action->extendData = (action->extendData & 0xFF00) | (temp & 0x00FF);
45945579            }
45955580            else
45965581            {
45975582               temp = action->extendData & 0xFFFF;
4598               temp = DoEditHexField(machine, temp) & 0xFFFF;
5583               temp = do_edit_hex_field(machine, temp) & 0xFFFF;
45995584
46005585               action->extendData = (action->extendData & 0xFFFF0000) | (temp & 0x0000FFFF);
46015586            }
r2762r2763
46035588         break;
46045589
46055590         case kType_Data:
4606            action->originalDataField = DoEditHexField(machine, action->originalDataField);
5591            action->originalDataField = do_edit_hex_field(machine, action->originalDataField);
46075592            action->originalDataField &= info->extraData;
46085593            action->data = action->originalDataField;
46095594            break;
46105595
46115596         case kType_Address:
4612            action->address = DoEditHexField(machine, action->address);
5597            action->address = do_edit_hex_field(machine, action->address);
46135598            action->address &= info->extraData;
46145599            break;
46155600      }
4616
4617      if(input_ui_pressed(machine, IPT_UI_CANCEL))
4618         editActive = 0;
46195601   }
46205602   else
46215603   {
46225604      if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))
46235605      {
4624         if(ControlKeyPressed())
4625            if((entry->flags & kCheatFlag_HasActivationKey1) || (entry->flags & kCheatFlag_HasActivationKey2))
4626            {
4627               SaveCheat(machine, entry, index, 1);   // save activation key
4628
4629               ui_popup_time(1, "activation key saved");
4630            }
4631            else
4632               ui_popup_time(1, "no activation key");
4633         else
4634            SaveCheat(machine, entry, 0, 0);         // save current entry
5606         SaveCheatCode(machine, entry);
46355607      }
4636
4637      if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE))
5608      else if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE))
5609      {
46385610         WatchCheatEntry(entry, 0);
5611      }
5612      else if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT))
5613      {
5614         AddActionBefore(entry, info->sub_cheat);
46395615
4640      if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT))
4641         AddActionBefore(entry, info->subcheat);
5616         entry->actionList[info->sub_cheat].extendData = ~0;
46425617
4643      if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
4644      {
4645         if(!info->subcheat)
5618         for(i = 0; i < entry->actionListLength; i++)
46465619         {
4647            /* ----- if selected entry is master, delete current entry then return to previous menu ----- */
4648            DeleteCheatAt(index);
5620            CheatAction * action = &entry->actionList[i];
46495621
4650            return 0;
5622            if(i)
5623               SET_MASK_FIELD(action->type, LinkEnable);
5624            else
5625               CLEAR_MASK_FIELD(action->type, LinkEnable);
46515626         }
5627      }
5628      else if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
5629      {
5630         if(!info->sub_cheat)
5631         {
5632            /* don't delete MASTER Action due to crash */
5633            messageTimer = DEFAULT_MESSAGE_TIME;
5634            messageType = kCheatMessage_FailedToDelete;
5635         }
46525636         else
4653            DeleteActionAt(entry, info->subcheat);
5637            DeleteActionAt(entry, info->sub_cheat);
46545638      }
46555639   }
46565640
4657   if(input_ui_pressed(machine, IPT_UI_CANCEL))
5641   if(dirty)
46585642   {
4659      sel = -1;
4660      editActive = 0;
5643      UpdateCheatInfo(entry, 0);
5644
5645      entry->flags |= kCheatFlag_Dirty;
46615646   }
46625647
46635648   if(sel == -1)
46645649   {
5650      /* NOTE : building label index table should be done when exit the edit menu */
5651      if(entry->flags & kCheatFlag_Select)
5652         BuildLabelIndexTable(entry);
5653
5654      CheckCodeFormat(entry);
5655
46655656      editActive = 0;
46665657      dirty = 1;
46675658   }
46685659
4669   if(dirty)
4670   {
4671      UpdateCheatInfo(entry, 0);
5660   /* free astrings used by displaying the name of activation key */
5661   astring_free(tempString1);
5662   astring_free(tempString2);
5663#endif
5664   return menu->sel;
5665}
46725666
4673      entry->flags |= kCheatFlag_Dirty;
4674   }
5667/*--------------------------------------------------------------
5668  view_cheat_menu - management for code viewer for new format
5669--------------------------------------------------------------*/
46755670
4676   astring_free(temp_string_1);
4677   astring_free(temp_string_2);
5671static int view_cheat_menu(running_machine *machine, cheat_menu_stack *menu)
5672{
5673   static const char *const kAddressSpaceNames[] = {
5674      "Program", "Data Space", "I/O Space", "Opcode RAM", "Mapped Memory", "Direct Memory", "EEPROM" };
46785675
4679   return sel + 1;
4680}
5676   static const char *const kCodeTypeNames[] = {
5677      "Write", "PDWWrite", "RWrite", "IWrite", "CWrite", "VWrite", "VRWrite", "Move", "Branch", "Loop",
5678      "Unused 1", "Unused 2", "Unused 3", "Unused 4",
5679      "Popup", "Watch" };
46815680
4682/*-----------------------------------------------------------
4683  DoSearchMenuMinimum - management for minimum search menu
4684-----------------------------------------------------------*/
5681   static const char *const kCustomCodeTypeNames[] = {
5682      "No Action", "Comment", "Separator", "Label Select", "Layer",
5683      "Unused 1", "Unused2", "Unused 3",
5684      /* NOTE : the following command codes should be removed when database is loaded */
5685      "Activation Key 1", "Activation Key 2", "Pre-enable", "Overclock", "Refresh Rate" };
46855686
4686static int DoSearchMenuMinimum(running_machine *machine, int selection)
4687{
4688   /* main */
4689   enum
5687   static const char *const kConditionNames[] = {
5688      "EQ", "NE", "LS", "LSEQ", "GR", "GREQ", "BSET", "BCLR",
5689      "Unused 1", "Unused 2", "Unused 3", "Unused 4",
5690      "PVAL", "KEY", "KEYR", "TRUE" };
5691
5692   static const char *const kDataNames[] = {
5693      "Data", "1st Data", "Data", "Data", "Data", "Max Data", "Max Data", "Add Value", "Comparison", "Count",
5694      "-----", "-----", "-----", "-----",
5695      "Comparison", "-----" };
5696
5697   static const char *const kPopupOptionNames[] = {
5698      "Label", "Value", "Label + Value", "Value + Label" };
5699
5700   enum{
5701      kViewMenu_Header = 1,                  // format : total index / current index
5702      kViewMenu_CodeLayer,                  // internal value of code and layer index
5703      kViewMenu_Name,                        // master code = entry->name, linked code = action->optionalName
5704         kViewMenu_Comment,
5705         kViewMenu_ActivationKey1,
5706         kViewMenu_ActivationKey2,
5707      // if(!CustomCode)
5708         kViewMenu_CodeType,                     // CodeType - CodeParameter / Return
5709         kViewMenu_CPURegion,                  // add Address Space if CPU region
5710         kViewMenu_Address,
5711         kViewMenu_Size,                        // address size / index size
5712         kViewMenu_Data,
5713         kViewMenu_Extend,
5714         // if(ValueSelect)
5715            kViewMenu_ValueSelectOptions,
5716         // if(Popup)
5717            kViewMenu_PopupOptions,
5718         // if(CopyLink)
5719            kViewMenu_CopyLinkOptions,
5720         kViewMenu_Options,                     // One-shot, Delay, Prefill, RestoreValue
5721      // if(CustomCode)
5722         //if(LayerIndex)
5723            kViewMenu_LayerDisplayLevel,
5724            kViewMenu_LayerSetLevel,
5725            kViewMenu_LayerSetLength,
5726      kViewMenu_Return,
5727      kViewMenu_Max };
5728
5729   int            total = 0;
5730   int            menu_index[kViewMenu_Max] = { 0 };
5731   static int      page_index = 0;
5732   UINT8         address_length = 0;
5733   UINT8         address_size = 0;
5734   const char      ** menu_item;
5735   const char      ** menu_sub_item;
5736   char         * flag_buf;
5737   char         * header;
5738   char         * buf_code;
5739   char         * buf_type;
5740   char         * buf_cpu;
5741   char         * buf_address;
5742   char         * buf_size;
5743   char         * buf_data;
5744   char         * buf_extend;
5745   char         * buf_options;
5746   char         * buf_code_type_options;
5747   CheatEntry      * entry = &cheatList[menu->pre_sel];
5748   CheatAction      * action = NULL;
5749   astring         * activation_key_string1 = NULL;
5750   astring         * activation_key_string2 = NULL;
5751
5752   /* first setting : forced set page as 0 when first open */
5753   if(menu->first_time)
46905754   {
4691      kMenu_CPU = 0,
4692      kMenu_SearchItem,
5755      page_index = 0;
5756      menu->first_time = 0;
5757   }
46935758
4694      kMenu_Divider,
5759   action         = &entry->actionList[page_index];
5760   address_length   = get_address_length(action->region);
5761   address_size   = EXTRACT_FIELD(action->type, AddressSize);
46955762
4696      kMenu_Memory,
4697      kMenu_ViewResult,
4698      kMenu_RestoreSearch,
5763   /* required items = (total items + return + terminator) & (strings buf * 10) */
5764   request_strings(kViewMenu_Max + 2, 0x0A, 32, 0);
5765   menu_item            = menu_strings.main_list;
5766   menu_sub_item         = menu_strings.sub_list;
5767   flag_buf            = menu_strings.flag_list;
5768   header               = menu_strings.main_strings[0];
5769   buf_code            = menu_strings.main_strings[1];
5770   buf_type            = menu_strings.main_strings[2];
5771   buf_cpu               = menu_strings.main_strings[3];
5772   buf_address            = menu_strings.main_strings[4];
5773   buf_size            = menu_strings.main_strings[5];
5774   buf_data            = menu_strings.main_strings[6];
5775   buf_extend            = menu_strings.main_strings[7];
5776   buf_options            = menu_strings.main_strings[8];
5777   buf_code_type_options   = menu_strings.main_strings[9];
46995778
4700      kMenu_Return,
4701   };
5779   memset(flag_buf, 0, kViewMenu_Max + 2);
47025780
4703   /* search item */
4704   enum
5781   /********** MENU CONSTRUCTION **********/
5782   /* ##### HEADER ##### */
5783   sprintf(header, "[%2.2d/%2.2d]", page_index + 1, entry->actionListLength);
5784   ADD_MENU_3_ITEMS("Page", header, kViewMenu_Header);
5785
5786   /* ##### CODE / LAYER INDEX ##### */
5787   sprintf(buf_code, "%8.8X / %2.2X", action->type, entry->layerIndex);
5788   ADD_MENU_3_ITEMS("Code / Layer", buf_code, kViewMenu_CodeLayer);
5789
5790   /* ##### NAME ##### */
5791   if(entry->name)
47055792   {
4706      kItem_Value,
4707      kItem_Timer,
4708      kItem_Equal,
4709      kItem_NotEqual,
4710      kItem_Less,
4711      kItem_Greater,
5793      if(page_index)
5794         ADD_MENU_3_ITEMS("Name", action->optionalName, kViewMenu_Name);
5795      else
5796         ADD_MENU_3_ITEMS("Name", entry->name, kViewMenu_Name);
5797   }
5798   else
5799      ADD_MENU_3_ITEMS("Name", "< none >", kViewMenu_Name);
47125800
4713      kItem_Max = kItem_Greater,
4714   };
5801   /* ##### COMMENT ##### */
5802   if(page_index == 0 && entry->comment)
5803      ADD_MENU_3_ITEMS("Comment", entry->comment, kViewMenu_Comment);
47155804
4716   const char      * menuItem[kMenu_Return + 2] = { 0 };
4717   const char      * menuSubItem[kMenu_Return + 2] = { 0 };
5805   /* ##### ACTIVATION KEY ##### */
5806   if(entry->flags & kCheatFlag_Select)
5807   {
5808      if(entry->flags & kCheatFlag_HasActivationKey1)
5809      {
5810         activation_key_string1 = astring_alloc();
5811         ADD_MENU_3_ITEMS("Activation Key", astring_c(input_code_name(activation_key_string1, entry->activationKey1)), kViewMenu_ActivationKey1);
5812      }
5813   }
5814   else
5815   {
5816      if(entry->flags & kCheatFlag_HasActivationKey1)
5817      {
5818         activation_key_string1 = astring_alloc();
5819         ADD_MENU_3_ITEMS("Activation Key - Prev", astring_c(input_code_name(activation_key_string1, entry->activationKey1)), kViewMenu_ActivationKey1);
5820      }
47185821
4719   char         valueBuffer[60];
4720   char         valueSignedBuffer[60];
4721   char         cpuBuffer[20];
4722   char         flagBuf[kMenu_Return + 2] = { 0 };
5822      if(entry->flags & kCheatFlag_HasActivationKey2)
5823      {
5824         activation_key_string2 = astring_alloc();
5825         ADD_MENU_3_ITEMS("Activation Key - Next", astring_c(input_code_name(activation_key_string2, entry->activationKey2)), kViewMenu_ActivationKey2);
5826      }
5827   }
47235828
4724   SearchInfo      * search = GetCurrentSearch();
5829   /* ##### CODE TYPE ##### */
5830   if(action->flags & kActionFlag_Custom)
5831   {
5832      ADD_MENU_3_ITEMS("Custom Type", kCustomCodeTypeNames[EXTRACT_FIELD(action->type, CodeType)], kViewMenu_CodeType);
5833   }
5834   else
5835   {
5836      char * type_strings = buf_type;
47255837
4726   INT32         sel = selection - 1;
4727   INT32         total =       0;
4728   UINT8         doSearch =    0;
5838      type_strings += sprintf(type_strings, "%s", kCodeTypeNames[EXTRACT_FIELD(action->type, CodeType)]);
47295839
4730   static INT8      searchItem = 0;
4731   static INT8      submenuChoice = 0;
4732   static UINT8   doneSaveMemory = 0;
4733   static UINT8   firstEntry = 0;
4734   static UINT8   editActive = 0;
4735   static UINT8   posnKeep = kMenu_SearchItem;
4736   static UINT32   increment = 1;
5840      if(action->flags & kActionFlag_CheckCondition)
5841         type_strings += sprintf(type_strings, "-%s", kConditionNames[EXTRACT_FIELD(action->type, CodeParameter)]);
47375842
4738   /********** SUB MENU **********/
4739   if(submenuChoice)
5843      if(TEST_FIELD(action->type, Return))
5844         type_strings += sprintf(type_strings, "/Ret");
5845
5846      ADD_MENU_3_ITEMS("Type", buf_type, kViewMenu_CodeType);
5847   }
5848
5849   if((action->flags & kActionFlag_Custom) == 0)
47405850   {
4741      switch(sel)
5851      /* ##### CPU/REGION ##### */
5852      if(TEST_FIELD(action->region, RegionFlag))
47425853      {
4743         case kMenu_CPU:
4744            submenuChoice = SelectSearchRegions(machine, submenuChoice, GetCurrentSearch());
5854         ADD_MENU_3_ITEMS("Region", kRegionNames[EXTRACT_FIELD(action->region, RegionIndex)], kViewMenu_CPURegion);
5855      }
5856      else
5857      {
5858         sprintf(buf_cpu, "%s (%s)", kRegionNames[EXTRACT_FIELD(action->region, CPUIndex) + 1], kAddressSpaceNames[EXTRACT_FIELD(action->region, AddressSpace)]);
5859         ADD_MENU_3_ITEMS("CPU", buf_cpu, kViewMenu_CPURegion);
5860      }
5861
5862      /* ##### ADDRESS ##### */
5863      switch(EXTRACT_FIELD(action->type, AddressRead))
5864      {
5865         case kReadFrom_Address:
5866            sprintf(buf_address, "%*.*X", address_length, address_length, action->originalAddress);
47455867            break;
47465868
4747         case kMenu_ViewResult:
4748            submenuChoice = ViewSearchResults(machine, submenuChoice, firstEntry);
5869         case kReadFrom_Index:
5870            sprintf(buf_address, "(V%s)", kNumbersTable[action->originalAddress]);
47495871            break;
5872
5873         case kReadFrom_Variable:
5874            sprintf(buf_address, "V%s", kNumbersTable[action->originalAddress]);
47505875      }
47515876
4752      firstEntry = 0;
5877      ADD_MENU_3_ITEMS("Address", buf_address, kViewMenu_Address);
47535878
4754      posnKeep = sel;
5879      /* ##### SIZE ##### */
5880      if(action->flags & kActionFlag_PDWWrite)
5881      {
5882         sprintf(buf_size, "%s / %s", kByteSizeStringList[address_size], kByteSizeStringList[EXTRACT_FIELD(action->type, IndexSize)]);
5883         ADD_MENU_3_ITEMS("Size 1st / 2nd", buf_size, kViewMenu_Size);
5884      }
5885      else if(action->flags & kActionFlag_IndexAddress)
5886      {
5887         if(action->extendData != ~0)
5888         {
5889            sprintf(buf_size, "%s / %s", kByteSizeStringList[address_size], kByteSizeStringList[EXTRACT_FIELD(action->type, IndexSize)]);
5890         }
5891         else
5892            sprintf(buf_size, "%s / < None >", kByteSizeStringList[address_size]);
47555893
4756      /* ----- meaningless ? because no longer return with sel = -1 (pressed UI_CONFIG in submenu) ----- */
4757//      if(submenuChoice == -1)
4758//          submenuChoice = 0;
5894         ADD_MENU_3_ITEMS("Size Adr / Idx", buf_size, kViewMenu_Size);
5895      }
5896      else
5897      {
5898         sprintf(buf_size, "%s", kByteSizeStringList[address_size]);
5899         ADD_MENU_3_ITEMS("Size", buf_size, kViewMenu_Size);
5900      }
47595901
4760      return sel + 1;
5902      /* ##### DATA ##### */
5903      if(EXTRACT_FIELD(action->type, CodeType) != kCodeType_Watch)
5904      {
5905         if(TEST_FIELD(action->type, DataRead))
5906         {
5907            sprintf(buf_data, "V%s", kNumbersTable[action->originalDataField]);
5908         }
5909         else
5910         {
5911            sprintf(buf_data, "%*.*X", kCheatSizeDigitsTable[address_size], kCheatSizeDigitsTable[address_size], action->originalDataField);
5912         }
5913
5914         if(EXTRACT_FIELD(action->type, Link) != kLink_CopyLink)
5915            ADD_MENU_3_ITEMS(kDataNames[EXTRACT_FIELD(action->type, CodeType)], buf_data, kViewMenu_Data);
5916         else
5917            ADD_MENU_3_ITEMS("Add Value", buf_data, kViewMenu_Data);
5918      }
5919
5920      /* ##### EXTEND DATA ##### */
5921      if(action->flags & kActionFlag_IndexAddress)
5922      {
5923         if(action->extendData != ~0)
5924            sprintf(buf_extend, "%*.8X", address_length, action->extendData);
5925         else
5926            sprintf(buf_extend, "< none >");
5927
5928         ADD_MENU_3_ITEMS("Index", buf_extend, kViewMenu_Extend);
5929      }
5930      else if(action->flags & kActionFlag_PDWWrite)
5931      {
5932         sprintf(buf_extend, "%*.*X",
5933            kCheatSizeDigitsTable[EXTRACT_FIELD(action->type, IndexSize)],
5934            kCheatSizeDigitsTable[EXTRACT_FIELD(action->type, IndexSize)],
5935            action->extendData);
5936         ADD_MENU_3_ITEMS("2nd Data", buf_extend, kViewMenu_Extend);
5937      }
5938      else if(action->flags & kActionFlag_Repeat)
5939      {
5940         sprintf(buf_extend, "%4.4X / %4.4X",
5941                  EXTRACT_FIELD(action->extendData, LSB16),
5942                  EXTRACT_FIELD(action->extendData, MSB16));
5943         ADD_MENU_3_ITEMS("Count / Skip", buf_extend, kViewMenu_Extend);
5944      }
5945      else
5946      {
5947         switch(EXTRACT_FIELD(action->type, CodeType))
5948         {
5949            case kCodeType_Write:
5950            case kCodeType_IWrite:
5951            case kCodeType_VWrite:
5952               sprintf(buf_extend, "%*.*X", address_size, address_size, action->extendData);
5953               ADD_MENU_3_ITEMS("Mask", buf_extend, kViewMenu_Extend);
5954               break;
5955
5956            case kCodeType_CWrite:
5957               sprintf(buf_extend, "%*.*X", address_size, address_size, action->extendData);
5958               ADD_MENU_3_ITEMS("Comparison", buf_extend, kViewMenu_Extend);
5959               break;
5960
5961            case kCodeType_Branch:
5962               sprintf(buf_extend, "%2.2d", action->extendData + 1);
5963               ADD_MENU_3_ITEMS("Jump Index", buf_extend, kViewMenu_Extend);
5964               break;
5965
5966            default:
5967               ADD_MENU_3_ITEMS("UNKNOWN", "?????", kViewMenu_Extend);
5968         }
5969      }
5970
5971      /* ##### OPTIONS ##### */
5972      sprintf(buf_options, "%s %s %s %s",
5973               TEST_FIELD(action->type, OneShot) ? "O" : "-",
5974               TEST_FIELD(action->type, DelayEnable) ? "D" : "-",
5975               TEST_FIELD(action->type, PrefillEnable) ? "P" : "-",
5976               TEST_FIELD(action->type, RestoreValue) ? "R" : "-");
5977      ADD_MENU_3_ITEMS("Options", buf_options, kViewMenu_Options);
5978
5979      /* ##### CODE TYPE OPTIONS ##### */
5980      if(   EXTRACT_FIELD(action->type, CodeType) == kCodeType_VWrite ||
5981         EXTRACT_FIELD(action->type, CodeType) == kCodeType_VRWrite)
5982      {
5983         sprintf(buf_code_type_options, "%s %s %s %s",
5984                  TEST_FIELD(action->type, ValueSelectMinimumDisplay) ? "D" : "-",
5985                  TEST_FIELD(action->type, ValueSelectMinimum) ? "M" : "-",
5986                  TEST_FIELD(action->type, ValueSelectBCD) ? "B" : "-",
5987                  TEST_FIELD(action->type, ValueSelectNegative) ? "N" : "-");
5988         ADD_MENU_3_ITEMS("Value Select Options", buf_code_type_options, kViewMenu_ValueSelectOptions);
5989      }
5990      else if(EXTRACT_FIELD(action->type, CodeType) == kCodeType_Popup)
5991      {
5992         ADD_MENU_3_ITEMS("Popup Options", kPopupOptionNames[EXTRACT_FIELD(action->type, PopupParameter)], kViewMenu_PopupOptions);
5993      }
5994      else if(EXTRACT_FIELD(action->type, Link) == kLink_CopyLink)
5995      {
5996         sprintf(buf_code_type_options, "%s %s",
5997                  TEST_FIELD(action->type, LinkValueSelectBCD) ? "B" : "-",
5998                  TEST_FIELD(action->type, LinkValueSelectNegative) ? "N" : "-");
5999         ADD_MENU_3_ITEMS("Copy Link Options", buf_code_type_options, kViewMenu_CopyLinkOptions);
6000      }
47616001   }
6002   else
6003   {
6004      if(EXTRACT_FIELD(action->type, CodeType) == kCustomCode_Layer)
6005      {
6006         /* ##### LAYER ##### */
6007         sprintf(buf_address, "%2.2X", action->originalAddress);
6008         ADD_MENU_3_ITEMS("Display Level", buf_address, kViewMenu_LayerDisplayLevel);
47626009
4763   sel = posnKeep;
6010         sprintf(buf_data, "%2.2X", action->originalDataField);
6011         ADD_MENU_3_ITEMS("Set Level", buf_data, kViewMenu_LayerSetLevel);
47646012
4765   /* ----- unselectable comparison search item if no save ----- */
4766   if(!doneSaveMemory)
4767      searchItem = kItem_Value;
6013         sprintf(buf_extend, "%2.2X", action->extendData);
6014         ADD_MENU_3_ITEMS("Set Length", buf_extend, kViewMenu_LayerSetLength);
6015      }
6016   }
47686017
6018   /* ##### RETURN ##### */
6019   ADD_MENU_3_ITEMS("Return to Prior Menu", NULL, kViewMenu_Return);
6020
6021   /* ##### TERMINATE ARRAY ##### */
6022   TERMINATE_MENU_2_ITEMS;
6023
6024   /* adjust current cursor position */
6025   ADJUST_CURSOR(menu->sel, total)
6026
6027   /* draw it */
6028   old_style_menu(menu_item, menu_sub_item, flag_buf, menu->sel, 0);
6029
6030   /********** KEY HANDLING **********/
6031   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
6032   {
6033      CURSOR_TO_PREVIOUS(menu->sel, total)
6034   }
6035   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
6036   {
6037      CURSOR_TO_NEXT(menu->sel, total)
6038   }
6039   else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
6040   {
6041      if(--page_index < 0)
6042         page_index = entry->actionListLength - 1;
6043   }
6044   else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
6045   {
6046      if(++page_index > entry->actionListLength - 1)
6047         page_index = 0;
6048   }
6049   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
6050   {
6051      CURSOR_PAGE_UP(menu->sel)
6052   }
6053   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
6054   {
6055      CURSOR_PAGE_DOWN(menu->sel, total)
6056   }
6057   else if(input_ui_pressed(machine, IPT_UI_SELECT) || input_ui_pressed(machine, IPT_UI_CANCEL))
6058   {
6059      menu->sel = -1;
6060   }
6061   else if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))
6062   {
6063      SaveCheatCode(machine, entry);
6064   }
6065
6066   if(activation_key_string1)
6067      astring_free(activation_key_string1);
6068   if(activation_key_string2)
6069      astring_free(activation_key_string2);
6070
6071   return menu->sel + 1;
6072}
6073
6074/*---------------------------------------------------------
6075  analyse_cheat_menu - management for code analizer menu
6076---------------------------------------------------------*/
6077
6078static int analyse_cheat_menu(running_machine *machine, cheat_menu_stack *menu)
6079{
6080   static const char *const kAnalyseItemName[] = {
6081      "Invalid Location Type",
6082      "Invalid Operation",
6083      "Invalid Code Type",
6084      "Invalid Condition",
6085      "Invalid Code Option",
6086      "Relative Address conflicts other operations",
6087      "Maximum range is smaller than minimum",
6088      "Missing Restore Previous Value flag",
6089      "Missing label link code",
6090      "Both Value and Label Select are defined",
6091      "Copy Link is defined though no value-select code",
6092      "Invalid Data Field",
6093      "Invalid Extend Data Field",
6094      "Don't set Variable in this type",
6095      "Value Select can't select any value",
6096      "RWrite doesn't have counter",
6097      "Invalid Address Read",
6098      "Invalid Variable in address field",
6099      "Invalid Variable in extend data field",
6100      "CPU/Region is out of range",
6101      "Invalid CPU/Region number",
6102      "Invalid Address Space",
6103      "An address is out of range",
6104      "Invalid Custom Code" };
6105
6106   int            i, j;
6107   int            total         = 0;
6108   UINT8         isEdit         = 0;
6109   const char      ** menuItem;
6110   CheatEntry      * entry         = &cheatList[menu->pre_sel];
6111
6112   /* first setting : NONE */
6113   if(menu->first_time)
6114      menu->first_time = 0;
6115
6116   /* required items = ((items + header + 2 separators) * total_actions) + edit + return + terminator) */
6117   request_strings(((kErrorFlag_Max + 3) * entry->actionListLength) + 3, 0, 0, 0);
6118   menuItem = menu_strings.main_list;
6119
47696120   /********** MENU CONSTRUCTION **********/
4770   sprintf(cpuBuffer, "%d", search->targetIdx);      // CPU
6121   for(i = 0; i < entry->actionListLength; i++)
6122   {
6123      CheatAction * action = &entry->actionList[i];
6124
6125      UINT32 flags = AnalyseCodeFormat(entry, action);
6126
6127      menuItem[total++] = action->optionalName ? action->optionalName : "(Null)";
6128      menuItem[total++] = MENU_SEPARATOR_ITEM;
6129
6130      if(flags)
6131      {
6132         for(j = 0; j < kErrorFlag_Max; j++)
6133         {
6134            if((flags >> j) & 1)
6135               menuItem[total++] = kAnalyseItemName[j];
6136         }
6137      }
6138      else
6139         menuItem[total++] = "No Problem";
6140
6141      menuItem[total++] = MENU_SEPARATOR_ITEM;
6142   }
6143
6144   menuItem[total++] = "Edit This Entry";
6145   menuItem[total++] = "Return to Prior Menu";
6146   menuItem[total] = NULL;
6147
6148   /* adjust cursor position */
6149   ADJUST_CURSOR(menu->sel, total)
6150
6151   old_style_menu(menuItem, NULL, NULL, menu->sel, 0);
6152
6153   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
6154   {
6155      CURSOR_TO_PREVIOUS(menu->sel, total)
6156   }
6157   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
6158   {
6159      CURSOR_TO_NEXT(menu->sel, total)
6160   }
6161   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
6162   {
6163      CURSOR_PAGE_UP(menu->sel)
6164   }
6165   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
6166   {
6167      CURSOR_PAGE_DOWN(menu->sel, total)
6168   }
6169   else if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT))
6170   {
6171      isEdit = 1;
6172   }
6173   else if(input_ui_pressed(machine, IPT_UI_SELECT))
6174   {
6175      if(menu->sel == total - 2)
6176         isEdit = 1;
6177      else
6178         menu->sel = -1;
6179   }
6180   else if(input_ui_pressed(machine, IPT_UI_CANCEL))
6181   {
6182      menu->sel = -1;
6183   }
6184
6185   if(isEdit)
6186   {
6187      if(entry->flags & kCheatFlag_OldFormat)
6188         cheat_menu_stack_push(edit_cheat_menu, menu->return_handler, menu->pre_sel);
6189      else
6190         cheat_menu_stack_push(view_cheat_menu, menu->return_handler, menu->pre_sel);
6191   }
6192
6193   return menu->sel + 1;
6194}
6195
6196/*-----------------------------------------------------------
6197  search_minimum_menu - management for minimum search menu
6198                        limited size, operand, comparison
6199-----------------------------------------------------------*/
6200
6201static int search_minimum_menu(running_machine *machine, cheat_menu_stack *menu)
6202{
6203   enum{
6204      kMenu_CPU = 0,
6205      kMenu_Memory,
6206      kMenu_Divider1,
6207      kMenu_Value,
6208      kMenu_Timer,
6209      kMenu_Greater,
6210      kMenu_Less,
6211      kMenu_Equal,
6212      kMenu_NotEqual,
6213      kMenu_Divider2,
6214      kMenu_Result,
6215      kMenu_RestoreSearch,
6216      kMenu_Return,
6217      kMenu_Max };
6218
6219   INT8         i;
6220   UINT8         total         = 0;
6221   UINT8         doSearch      = 0;
6222   static UINT8   doneSaveMemory   = 0;
6223   const char      * menuItem[kMenu_Max + 1]      = { 0 };
6224   const char      * menuSubItem[kMenu_Max + 1]   = { 0 };
6225   char         flagBuf[kMenu_Max + 1]         = { 0 };
6226   char         cpuBuf[4];
6227   char         valueBuf[32];      // "FFFFFFF[F] (4294967295)"    23 chars
6228   char         timerBuf[32];      // "-FFFFFFF[F] (4294967295)"   24 chars
6229   char         numResultsBuf[16];
6230   char         * stringsBuf;
6231   search_info      *search = get_current_search();
6232
6233   /* first setting : NONE */
6234   if(menu->first_time)
6235      menu->first_time = 0;
6236
6237   /* NOTE : in this mode, search bytes is always fixed with 1 byte right now */
6238   search->old_options.value &= kSearchByteMaskTable[search->bytes];
6239   search->old_options.delta &= kSearchByteMaskTable[search->bytes];
6240
6241   /********** MENU CONSTRUCTION **********/
6242   /* ##### CPU ##### */
47716243   menuItem[total] = "CPU";
4772   menuSubItem[total++] = cpuBuffer;
6244   sprintf(cpuBuf, "%d", search->target_idx);
6245   menuSubItem[total++] = cpuBuf;
47736246
4774   if(search->sign && (search->oldOptions.value & kSearchByteSignBitTable[search->bytes]))
6247   /* ##### MEMORY ##### */
6248   if(doneSaveMemory)
6249      menuItem[total] = "Initialize Memory";
6250   else
6251      menuItem[total] = "Save Memory";
6252   menuSubItem[total++] = NULL;
6253
6254   /* ##### DIVIDER ##### */
6255   menuItem[total] = MENU_SEPARATOR_ITEM;
6256   menuSubItem[total++] = NULL;
6257
6258   /* ##### VALUE ##### */
6259   menuItem[total] = "Value";
6260
6261   if(editActive && menu->sel == kMenu_Value)
47756262   {
4776      UINT32   tempValue;
6263      stringsBuf = valueBuf;
47776264
4778      tempValue = ~search->oldOptions.value + 1;
4779      tempValue &= kSearchByteUnsignedMaskTable[search->bytes];
6265      for(i = 1; i >= 0; i--)
6266      {
6267         if(i == editCursor)
6268            stringsBuf += sprintf(stringsBuf, "[%X]", (search->old_options.value & kIncrementMaskTable[i]) / kIncrementValueTable[i]);
6269         else
6270            stringsBuf += sprintf(stringsBuf, "%X", (search->old_options.value & kIncrementMaskTable[i]) / kIncrementValueTable[i]);
6271      }
47806272
4781      sprintf(valueBuffer, "-%.*X (-%d)", kSearchByteDigitsTable[search->bytes], tempValue, tempValue);
6273      stringsBuf += sprintf(stringsBuf, " (%d)", search->old_options.value);
47826274   }
47836275   else
4784      sprintf(valueBuffer, "%.*X (%d)", kSearchByteDigitsTable[search->bytes],
4785            search->oldOptions.value & kSearchByteMaskTable[search->bytes],
4786            search->oldOptions.value & kSearchByteMaskTable[search->bytes]);
6276      sprintf(valueBuf, "%.*X (%d)",
6277         kSearchByteDigitsTable[search->bytes], search->old_options.value, search->old_options.value);
47876278
4788   switch(searchItem)
6279   menuSubItem[total++] = valueBuf;
6280
6281   /* ##### TIMER ##### */
6282   menuItem[total] = "Timer";
6283
6284   if(!(search->old_options.delta & kSearchByteSignBitTable[search->bytes]))
47896285   {
4790      case kItem_Value:                              // value
4791         menuItem[total] = "Value";
4792         menuSubItem[total++] = valueBuffer;
4793         break;
6286      /* PLUS */
6287      if(editActive && menu->sel == kMenu_Timer)
6288      {
6289         stringsBuf = timerBuf;
47946290
4795      case kItem_Timer:
4796         menuItem[total] = "Timer (+ or -)";               // timer
4797
4798         /* ----- if memory has been saved, set sub-item for timer ----- */
4799         if(doneSaveMemory)
6291         for(i = 2; i >= 0; i--)
48006292         {
4801            if(search->oldOptions.delta & kSearchByteSignBitTable[search->bytes])
6293            if(i == editCursor)
48026294            {
4803               UINT32   tempValue;
6295               if(i == 2)
6296                  stringsBuf += sprintf(stringsBuf, "[+]");
6297               else
6298                  stringsBuf += sprintf(stringsBuf, "[%X]", (search->old_options.delta & kIncrementMaskTable[i]) / kIncrementValueTable[i]);
6299            }
6300            else
6301            {
6302               if(i == 2)
6303                  stringsBuf += sprintf(stringsBuf, "+");
6304               else
6305                  stringsBuf += sprintf(stringsBuf, "%X", (search->old_options.delta & kIncrementMaskTable[i]) / kIncrementValueTable[i]);
6306            }
6307         }
48046308
4805               tempValue = ~search->oldOptions.delta + 1;
4806               tempValue &= kSearchByteUnsignedMaskTable[search->bytes];
6309         stringsBuf += sprintf(stringsBuf, " (+%d)", search->old_options.delta);
6310      }
6311      else
6312         sprintf(timerBuf, "+%.2X (+%d)", search->old_options.delta, search->old_options.delta);
6313   }
6314   else
6315   {
6316      UINT32 deltaDisp = (~search->old_options.delta + 1) & 0x7F;
48076317
4808               sprintf(valueSignedBuffer, "-%.*X (-%d)", kSearchByteDigitsTable[search->bytes], tempValue, tempValue);
6318      /* MINUS */
6319      if(editActive && menu->sel == kMenu_Timer)
6320      {
6321         stringsBuf = timerBuf;
6322
6323         for(i = 2; i >= 0; i--)
6324         {
6325            if(i == editCursor)
6326            {
6327               if(i == 2)
6328                  stringsBuf += sprintf(stringsBuf, "[-]");
6329               else
6330                  stringsBuf += sprintf(stringsBuf, "[%X]", (deltaDisp & kIncrementMaskTable[i]) / kIncrementValueTable[i]);
48096331            }
48106332            else
4811               sprintf(valueSignedBuffer, "%.*X (%d)", kSearchByteDigitsTable[search->bytes],
4812                     search->oldOptions.delta & kSearchByteMaskTable[search->bytes],
4813                      search->oldOptions.delta & kSearchByteMaskTable[search->bytes]);
4814
4815            menuSubItem[total++] = valueSignedBuffer;
6333            {
6334               if(i == 2)
6335                  stringsBuf += sprintf(stringsBuf, "-");
6336               else
6337                  stringsBuf += sprintf(stringsBuf, "%X", (deltaDisp & kIncrementMaskTable[i]) / kIncrementValueTable[i]);
6338            }
48166339         }
4817         break;
48186340
4819      case kItem_Equal:
4820         menuItem[total] = "Comparison";                  // equal
4821         menuSubItem[total++] = "Equal";
4822         break;
6341#ifdef MAME_DEBUG
6342         stringsBuf += sprintf(stringsBuf, " = %.2X (-%d)", search->old_options.delta, deltaDisp);
6343#else
6344         stringsBuf += sprintf(stringsBuf, " (-%d)", deltaDisp);
6345#endif
6346      }
6347      else
48236348
4824      case kItem_NotEqual:
4825         menuItem[total] = "Comparison";                  // not equal
4826         menuSubItem[total++] = "Not Equal";
4827         break;
6349#ifdef MAME_DEBUG
6350      sprintf(timerBuf, "-%.2X = %.2X (-%d)", deltaDisp, search->old_options.delta, deltaDisp);
6351#else
6352      sprintf(timerBuf, "-%.2X (-%d)", deltaDisp, deltaDisp);
6353#endif
6354   }
6355   menuSubItem[total++] = timerBuf;
48286356
4829      case kItem_Less:
4830         menuItem[total] = "Comparison";                  // less
4831         menuSubItem[total++] = "Less";
4832         break;
6357   /* ##### GREATER ##### */
6358   menuItem[total] = "Greater";
6359   menuSubItem[total++] = "A > B";
48336360
4834      case kItem_Greater:
4835         menuItem[total] = "Comparison";                  // greater
4836         menuSubItem[total++] = "Greater";
4837         break;
4838   }
6361   /* ##### LESS ##### */
6362   menuItem[total] = "Less";
6363   menuSubItem[total++] = "A < B";
48396364
4840   menuItem[total] = "--------------------";         // divider
6365   /* ##### EQUAL ##### */
6366   menuItem[total] = "Equal";
6367   menuSubItem[total++] = "A = B";
6368
6369   /* ##### NOT EQUAL ##### */
6370   menuItem[total] = "Not Equal";
6371   menuSubItem[total++] = "A != B";
6372
6373   /* ##### DIVIDER ##### */
6374   menuItem[total] = MENU_SEPARATOR_ITEM;
48416375   menuSubItem[total++] = NULL;
48426376
4843   if(doneSaveMemory)                           // memory
4844      menuItem[total] = "Initialize Memory";
6377   /* ##### RESULT ##### */
6378   menuItem[total] = "Results";
6379   if(search->num_results)
6380   {
6381      sprintf(numResultsBuf, "%d", search->num_results);
6382   }
48456383   else
4846      menuItem[total] = "Save Memory";
4847   menuSubItem[total++] = NULL;
6384   {
6385      if(!doneSaveMemory)
6386         sprintf(numResultsBuf, "No Memory Save");
6387      else
6388         sprintf(numResultsBuf, "No Result");
6389   }
6390   menuSubItem[total++] = numResultsBuf;
48486391
4849   menuItem[total] = "View Last Results";      // view result
6392   /* ##### RESULT RESTORE ##### */
6393   menuItem[total] = "Restore Previous Results";
48506394   menuSubItem[total++] = NULL;
48516395
4852   menuItem[total] = "Restore Previous Results";   // restore result
6396   /* ##### RETURN ##### */
6397   menuItem[total] = "Return to Prior Menu";
48536398   menuSubItem[total++] = NULL;
48546399
4855   menuItem[total] = "Return to Prior Menu";   // return
4856   menuSubItem[total++] = NULL;
4857
4858   menuItem[total] = NULL;                        // terminate array
6400   /* ##### TERMINATE ARRAY ##### */
6401   menuItem[total] = NULL;
48596402   menuSubItem[total] = NULL;
48606403
4861   /* ----- adjust current cursor position ----- */
4862   if((sel < 0) || (sel >= total))
4863      sel = kMenu_SearchItem;
6404   /* adjust current cursor position */
6405   if(menu->sel < 0 || menu->sel >= total)
6406      menu->sel = kMenu_Memory;
6407   if(!doneSaveMemory)
6408   {
6409      if(menu->sel >= kMenu_Timer && menu->sel <= kMenu_NotEqual)
6410         menu->sel = kMenu_Memory;
6411   }
48646412
4865   /* ----- higlighted sub-item if edit mode ----- */
48666413   if(editActive)
4867      flagBuf[sel] = 1;
6414      flagBuf[menu->sel] = 1;
48686415
4869   /* ----- draw it ----- */
4870   old_style_menu(menuItem, menuSubItem, flagBuf, sel, 0);
6416   /* draw it */
6417   old_style_menu(menuItem, menuSubItem, flagBuf, menu->sel, 0);
48716418
48726419   /********** KEY HANDLING **********/
4873   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
6420   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
48746421   {
48756422      if(editActive)
48766423      {
4877         increment <<= 4;
4878
4879         switch(searchItem)
6424         switch(menu->sel)
48806425         {
4881            case kItem_Value:
4882               search->oldOptions.value += increment;
4883               search->oldOptions.value &= kSearchByteMaskTable[search->bytes];
6426            case kMenu_Value:
6427               search->old_options.value = DoIncrementHexField(search->old_options.value, editCursor);
48846428               break;
48856429
4886            case kItem_Timer:
4887               search->oldOptions.delta += increment;
4888               search->oldOptions.delta &= kSearchByteMaskTable[search->bytes];
6430            case kMenu_Timer:
6431               switch(editCursor)
6432               {
6433                  default:
6434                     search->old_options.delta = DoIncrementHexFieldSigned(search->old_options.delta, editCursor, search->bytes);
6435                     break;
6436
6437                  case 2:
6438                     if(!search->old_options.delta || search->old_options.delta == 0x80)
6439                        search->old_options.delta ^= 0x80;
6440                     else
6441                        search->old_options.delta = ~search->old_options.delta + 1;
6442                     break;
6443               }
48896444               break;
48906445         }
4891
4892         increment >>= 4;
48936446      }
48946447      else
48956448      {
4896         sel--;
6449         CURSOR_TO_PREVIOUS(menu->sel, total)
48976450
4898         /* ----- if divider, skip it ----- */
4899         if(sel == kMenu_Divider)
4900            sel--;
4901
4902         if(sel < 0)
4903            sel = total - 1;
6451         if(menu->sel == kMenu_Divider1 || menu->sel == kMenu_Divider2)
6452         {
6453            if(--menu->sel == kMenu_NotEqual && !doneSaveMemory)
6454               menu->sel = kMenu_Value;
6455         }
49046456      }
49056457   }
4906
4907   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
6458   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
49086459   {
49096460      if(editActive)
49106461      {
4911         increment <<= 4;
4912
4913         switch(searchItem)
6462         switch(menu->sel)
49146463         {
4915            case kItem_Value:
4916               search->oldOptions.value -= increment;
4917               search->oldOptions.value &= kSearchByteMaskTable[search->bytes];
6464            case kMenu_Value:
6465               search->old_options.value = DoDecrementHexField(search->old_options.value, editCursor);
49186466               break;
49196467
4920            case kItem_Timer:
4921               search->oldOptions.delta -= increment;
4922               search->oldOptions.delta &= kSearchByteMaskTable[search->bytes];
6468            case kMenu_Timer:
6469               switch(editCursor)
6470               {
6471                  default:
6472                     search->old_options.delta = DoDecrementHexFieldSigned(search->old_options.delta, editCursor, search->bytes);
6473                     break;
6474
6475                  case 2:
6476                     if(!search->old_options.delta || search->old_options.delta == 0x80)
6477                        search->old_options.delta ^= 0x80;
6478                     else
6479                        search->old_options.delta = ~search->old_options.delta + 1;
6480                     break;
6481               }
49236482               break;
49246483         }
4925
4926         increment >>= 4;
49276484      }
49286485      else
49296486      {
4930         sel++;
6487         CURSOR_TO_NEXT(menu->sel, total)
49316488
4932         /* ----- if divider, skip it ----- */
4933         if(sel == kMenu_Divider)
4934            sel++;
4935
4936         if(sel >= total)
4937            sel = 0;
6489         if(menu->sel == kMenu_Divider1 || menu->sel == kMenu_Divider2)
6490            menu->sel++;
6491         if(!doneSaveMemory && menu->sel == kMenu_Timer)
6492            menu->sel = kMenu_Result;
49386493      }
49396494   }
4940
4941   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
6495   else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
49426496   {
4943      sel -= fullMenuPageHeight;
4944
4945      if(sel < 0)
4946         sel = 0;
4947   }
4948
4949   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
4950   {
4951      sel += fullMenuPageHeight;
4952
4953      if(sel >= total)
4954         sel = total - 1;
4955   }
4956
4957   if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
4958   {
49596497      if(editActive)
49606498      {
4961         switch(searchItem)
6499         switch(menu->sel)
49626500         {
4963            case kItem_Value:
4964               search->oldOptions.value -= increment;
4965               search->oldOptions.value &= kSearchByteMaskTable[search->bytes];
6501            case kMenu_Value:
6502               editCursor ^= 1;
49666503               break;
49676504
4968            case kItem_Timer:
4969               search->oldOptions.delta -= increment;
4970               search->oldOptions.delta &= kSearchByteMaskTable[search->bytes];
6505            case kMenu_Timer:
6506               if(++editCursor > 2)
6507                  editCursor = 0;
49716508               break;
49726509         }
49736510      }
49746511      else
49756512      {
4976         switch(sel)
6513         switch(menu->sel)
49776514         {
49786515            case kMenu_CPU:
4979               if(search->targetIdx > 0)
6516               if(search->target_idx > 0)
49806517               {
4981                  search->targetIdx--;
6518                  search->target_idx--;
49826519
4983                  BuildSearchRegions(machine, search);
4984                  AllocateSearchRegions(search);
6520                  build_search_regions(machine, search);
6521                  allocate_search_regions(search);
49856522
49866523                  doneSaveMemory = 0;
49876524               }
49886525               break;
49896526
4990            case kMenu_SearchItem:
4991               if(doneSaveMemory)
4992                  searchItem--;
6527            case kMenu_Value:
6528               search->old_options.value = (search->old_options.value - 1) & 0xFF;
6529               break;
49936530
4994               if(searchItem < 0)
4995                  searchItem = kItem_Max;
6531            case kMenu_Timer:
6532               search->old_options.delta = (search->old_options.delta - 1) & 0xFF;
49966533               break;
6534
6535            default:
6536               menu->sel = kMenu_Memory;
49976537         }
49986538      }
49996539   }
5000
5001   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
6540   else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
50026541   {
50036542      if(editActive)
50046543      {
5005         switch(searchItem)
6544         switch(menu->sel)
50066545         {
5007            case kItem_Value:
5008               search->oldOptions.value += increment;
5009               search->oldOptions.value &= kSearchByteMaskTable[search->bytes];
6546            case kMenu_Value:
6547               editCursor ^= 1;
50106548               break;
50116549
5012            case kItem_Timer:
5013               search->oldOptions.delta += increment;
5014               search->oldOptions.delta &= kSearchByteMaskTable[search->bytes];
6550            case kMenu_Timer:
6551               if(--editCursor < 0)
6552                  editCursor = 2;
50156553               break;
50166554         }
50176555      }
50186556      else
50196557      {
5020         switch(sel)
6558         switch(menu->sel)
50216559         {
50226560            case kMenu_CPU:
5023               if(search->targetIdx < cpu_gettotalcpu() - 1)
6561               if(search->target_idx < cpu_gettotalcpu() - 1)
50246562               {
5025                  search->targetIdx++;
6563                  search->target_idx++;
50266564
5027                  BuildSearchRegions(machine, search);
5028                  AllocateSearchRegions(search);
6565                  build_search_regions(machine, search);
6566                  allocate_search_regions(search);
50296567
50306568                  doneSaveMemory = 0;
50316569               }
50326570               break;
50336571
5034            case kMenu_SearchItem:
5035               if(doneSaveMemory)
5036                  searchItem++;
6572            case kMenu_Value:
6573               search->old_options.value = (search->old_options.value + 1) & 0xFF;
6574               break;
50376575
5038               if(searchItem > kItem_Max)
5039                  searchItem = kItem_Value;
6576            case kMenu_Timer:
6577               search->old_options.delta = (search->old_options.delta + 1) & 0xFF;
6578               break;
50406579
5041               break;
6580            default:
6581               menu->sel = kMenu_Result;
50426582         }
50436583      }
50446584   }
5045
5046   if(input_ui_pressed(machine, IPT_UI_SELECT))
6585   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
50476586   {
6587      CURSOR_PAGE_UP(menu->sel)
6588   }
6589   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
6590   {
6591      CURSOR_PAGE_DOWN(menu->sel, total)
6592   }
6593   else if(input_ui_pressed(machine, IPT_UI_SELECT))
6594   {
50486595      if(editActive)
50496596      {
5050         switch(searchItem)
6597         switch(menu->sel)
50516598         {
5052            case kItem_Value:
6599            case kMenu_Value:
50536600               search->bytes =         kSearchSize_8Bit;
50546601               search->lhs =         kSearchOperand_Current;
50556602               search->rhs =         kSearchOperand_Value;
50566603               search->comparison =   kSearchComparison_EqualTo;
5057               search->value =         search->oldOptions.value;
5058
6604               search->value =         search->old_options.value;
50596605               doSearch = 1;
50606606               break;
50616607
5062            case kItem_Timer:
6608            case kMenu_Timer:
50636609               search->bytes =         kSearchSize_8Bit;
50646610               search->lhs =         kSearchOperand_Current;
50656611               search->rhs =         kSearchOperand_Previous;
50666612               search->comparison =   kSearchComparison_IncreasedBy;
5067               search->value =         search->oldOptions.delta;
5068
6613               search->value =         search->old_options.delta;
50696614               doSearch = 1;
50706615               break;
50716616         }
5072
5073         /* ----- finish edit mode then do search ----- */
50746617         editActive = 0;
50756618      }
50766619      else
50776620      {
5078         switch(sel)
6621         switch(menu->sel)
50796622         {
50806623            case kMenu_CPU:
5081               submenuChoice = 1;         // go to region selection menu
6624               cheat_menu_stack_push(select_search_region_menu, menu->handler, menu->sel);
50826625               break;
50836626
5084            case kMenu_SearchItem:
5085            {
6627            case kMenu_Memory:
6628               doneSaveMemory = 0;
6629               doSearch = 1;
6630               break;
50866631
5087               switch(searchItem)
5088               {
5089                  case kItem_Value:
5090                  case kItem_Timer:
5091                     editActive = 1;
5092                     break;
6632            case kMenu_Value:
6633               search->bytes =         kSearchSize_8Bit;
6634               search->lhs =         kSearchOperand_Current;
6635               search->rhs =         kSearchOperand_Value;
6636               search->comparison =   kSearchComparison_EqualTo;
6637               search->value =         search->old_options.value;
6638               doSearch = 1;
6639               break;
50936640
5094                  case kItem_Equal:
5095                     search->bytes =         kSearchSize_8Bit;
5096                     search->lhs =         kSearchOperand_Current;
5097                     search->rhs =         kSearchOperand_Previous;
5098                     search->comparison =   kSearchComparison_EqualTo;
6641            case kMenu_Timer:
6642               search->bytes =         kSearchSize_8Bit;
6643               search->lhs =         kSearchOperand_Current;
6644               search->rhs =         kSearchOperand_Previous;
6645               search->comparison =   kSearchComparison_IncreasedBy;
6646               search->value =         search->old_options.delta;
6647               doSearch = 1;
6648               break;
50996649
5100                     doSearch = 1;
5101                     break;
6650            case kMenu_Equal:
6651               search->bytes =         kSearchSize_8Bit;
6652               search->lhs =         kSearchOperand_Current;
6653               search->rhs =         kSearchOperand_Previous;
6654               search->comparison =   kSearchComparison_EqualTo;
6655               doSearch = 1;
6656               break;
51026657
5103                  case kItem_NotEqual:
5104                     search->bytes =         kSearchSize_8Bit;
5105                     search->lhs =         kSearchOperand_Current;
5106                     search->rhs =         kSearchOperand_Previous;
5107                     search->comparison =   kSearchComparison_NotEqual;
6658            case kMenu_NotEqual:
6659               search->bytes =         kSearchSize_8Bit;
6660               search->lhs =         kSearchOperand_Current;
6661               search->rhs =         kSearchOperand_Previous;
6662               search->comparison =   kSearchComparison_NotEqual;
6663               doSearch = 1;
6664               break;
51086665
5109                     doSearch = 1;
5110                     break;
6666            case kMenu_Less:
6667               search->bytes =         kSearchSize_8Bit;
6668               search->lhs =         kSearchOperand_Current;
6669               search->rhs =         kSearchOperand_Previous;
6670               search->comparison =   kSearchComparison_LessThan;
6671               doSearch = 1;
6672               break;
51116673
5112                  case kItem_Less:
5113                     search->bytes =         kSearchSize_8Bit;
5114                     search->lhs =         kSearchOperand_Current;
5115                     search->rhs =         kSearchOperand_Previous;
5116                     search->comparison =   kSearchComparison_LessThan;
5117
5118                     doSearch = 1;
5119                     break;
5120
5121                  case kItem_Greater:
5122                     search->bytes =         kSearchSize_8Bit;
5123                     search->lhs =         kSearchOperand_Current;
5124                     search->rhs =         kSearchOperand_Previous;
5125                     search->comparison =   kSearchComparison_GreaterThan;
5126
5127                     doSearch = 1;
5128                     break;
5129               }
5130            }
5131            break;
5132
5133            case kMenu_Memory:            // save memory to search newly
5134               doneSaveMemory = 0;
5135
6674            case kMenu_Greater:
6675               search->bytes =         kSearchSize_8Bit;
6676               search->lhs =         kSearchOperand_Current;
6677               search->rhs =         kSearchOperand_Previous;
6678               search->comparison =   kSearchComparison_GreaterThan;
51366679               doSearch = 1;
51376680               break;
51386681
5139            case kMenu_ViewResult:
5140               if(search->regionListLength)
6682            case kMenu_Result:
6683               if(search->region_list_length)
6684                  cheat_menu_stack_push(view_search_result_menu, menu->handler, menu->sel);
6685               else
51416686               {
5142                  /* ----- go to result viewer ----- */
5143                  firstEntry = 1;
5144                  submenuChoice = 1;
6687                  /* if no search region (eg, sms.c in HazeMD), don't open result viewer to avoid the crash */
6688                  messageTimer =   DEFAULT_MESSAGE_TIME;
6689                  messageType =   kCheatMessage_NoSearchRegion;
51456690               }
5146               else
5147                  /* ----- if no search region (eg, sms.c in HazeMD), don't open result viewer to avoid the crash ----- */
5148                  ui_popup_time(1, "no search regions");
51496691               break;
51506692
51516693            case kMenu_RestoreSearch:
5152               RestoreSearchBackup(search);
6694               restore_search_backup(search);
51536695               break;
51546696
51556697            case kMenu_Return:
5156               posnKeep = kMenu_SearchItem;
5157               sel = -1;
6698               menu->sel = -1;
51586699               break;
51596700         }
51606701      }
51616702   }
5162
5163   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate))
5164      /* ----- quick menu switch : search -> watchpoint list ----- */
5165      sel = -5;
5166
5167   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate))
5168      /* ----- quick menu switch : search -> add/edit ----- */
5169      sel = -3;
5170
5171   /* ----- edit mode ON/OFF ----- */
5172   if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT))
6703   else if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT))
51736704   {
51746705      if(editActive)
51756706         editActive = 0;
51766707      else
51776708      {
5178         if((searchItem == kItem_Value) || (kItem_Timer))
6709         if(menu->sel == kMenu_Value || menu->sel == kMenu_Timer)
6710         {
51796711            editActive = 1;
6712            editCursor = 0;
6713         }
51806714      }
51816715   }
5182
5183   /* ----- memory save ----- */
5184   if(input_ui_pressed(machine, IPT_UI_CLEAR))
6716   else if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT))
51856717   {
5186      doneSaveMemory = 0;
5187
5188      doSearch = 1;
6718      restore_search_backup(search);
51896719   }
5190
5191   if(input_ui_pressed(machine, IPT_UI_CANCEL))
6720   else if(input_ui_pressed(machine, IPT_UI_CANCEL))
51926721   {
51936722      if(editActive)
51946723         editActive = 0;
51956724      else
5196      {
5197         posnKeep = kMenu_Memory;
5198         sel = -1;
5199      }
6725         menu->sel = -1;
52006726   }
52016727
52026728   /********** SEARCH **********/
52036729   if(doSearch)
52046730   {
52056731      if(!doneSaveMemory)
5206         /* ----- initialize search ----- */
5207         InitializeNewSearch(search);
6732         init_new_search(search);
52086733
5209      if(((sel == kMenu_SearchItem) && (searchItem == kItem_Value)) || doneSaveMemory)
6734      if(doneSaveMemory || menu->sel == kMenu_Value)
52106735      {
5211         /* ----- do search ----- */
5212         BackupSearch(search);
5213
5214         DoSearch(search);
6736         backup_search(search);
6737         do_search(search);
52156738      }
52166739
5217      UpdateSearch(search);
6740      update_search(search);
52186741
5219      /* ----- display message ----- */
5220      if(((sel == kMenu_SearchItem) && (searchItem == kItem_Value)) || doneSaveMemory)
5221         popmessage("%d results found", search->numResults);
6742      if(doneSaveMemory || menu->sel == kMenu_Value)
6743         messageType = kCheatMessage_CheatFound;
52226744      else
5223         popmessage("saved all memory regions");
6745         messageType = kCheatMessage_InitializeMemory;
52246746
6747      messageTimer = DEFAULT_MESSAGE_TIME;
6748
52256749      doneSaveMemory = 1;
52266750
5227      if(search->numResults == 1)
6751      if(search->num_results == 1)
52286752      {
52296753         AddCheatFromFirstResult(search);
52306754
5231         popmessage("1 result found, added to list");
6755         messageType = kCheatMessage_1CheatFound;
52326756      }
52336757   }
52346758
52356759   /********** EDIT **********/
5236   if((sel == kMenu_SearchItem) && editActive)
6760   if(editActive)
52376761   {
5238      if(searchItem == kItem_Value)
6762      switch(menu->sel)
52396763      {
5240         search->oldOptions.value = DoEditHexField(machine, search->oldOptions.value);
6764         case kMenu_Value:
6765            search->old_options.value = do_edit_hex_field(machine, search->old_options.value);
6766            search->old_options.value &= 0xFF;
6767            break;
52416768
5242         search->oldOptions.value &= kSearchByteMaskTable[search->bytes];
6769         case kMenu_Timer:
6770            search->old_options.delta = do_edit_hex_field(machine, search->old_options.delta);
6771            search->old_options.delta &= 0xFF;
6772            break;
52436773      }
5244      else
5245      {
5246         if(searchItem == kItem_Timer)
5247         {
5248            search->oldOptions.delta = DoEditHexField(machine, search->oldOptions.delta);
5249
5250            search->oldOptions.delta &= kSearchByteMaskTable[search->bytes];
5251         }
5252      }
52536774   }
52546775
5255   if(sel >= 0)
5256      posnKeep = sel;
5257
5258   return sel + 1;
6776   return menu->sel + 1;
52596777}
52606778
5261/*-----------------------------------------------------------
5262  DoSearchMenuClassic - management for classic search menu
5263-----------------------------------------------------------*/
6779/*-------------------------------------------------------------
6780  search_standard_menu - management for standard search menu
6781                         fixed bit and operand
6782-------------------------------------------------------------*/
52646783
5265static int DoSearchMenuClassic(running_machine *machine, int selection)
6784static int search_standard_menu(running_machine *machine, cheat_menu_stack *menu)
52666785{
5267   static const char *const energyStrings[] =
5268   {
6786   static const char *const kComparisonNameTable[] = {
6787      "Equal",
6788      "Not Equal",
52696789      "Less",
6790      "Less or Equal",
52706791      "Greater",
5271      "Less or Equal",
5272      "Greater or Equal",
5273   };
6792      "Greater or Equal" };
52746793
5275   static const char *const equalOrNotStrings[] =
5276   {
5277      "Equal",
5278      "Not Equal",
5279   };
6794   static const char *const kIncrementNameTable[] = {
6795      "Increment",
6796      "Decrement" };
52806797
5281   static const char *const operandStrings[] =
5282   {
5283      "Previous Data",
5284      "First Data",
5285   };
5286
5287   /* conversion table */
5288   static const int kEnergyComparisonConversionTable[] =
5289   {
6798   static const int kComparisonConversionTable[] = {
6799      kSearchComparison_EqualTo,
6800      kSearchComparison_NotEqual,
52906801      kSearchComparison_LessThan,
6802      kSearchComparison_LessThanOrEqualTo,
52916803      kSearchComparison_GreaterThan,
5292      kSearchComparison_LessThanOrEqualTo,
5293      kSearchComparison_GreaterThanOrEqualTo
5294   };
6804      kSearchComparison_GreaterThanOrEqualTo };
52956805
5296   static const int kEqualOrNotConversionTable[] =
5297   {
5298      kSearchComparison_EqualTo,
5299      kSearchComparison_NotEqual
5300   };
5301
5302   static const int kOperandConversionTable[] =
5303   {
5304      kSearchOperand_Previous,
5305      kSearchOperand_First
5306   };
5307
5308   enum
5309   {
5310      kMenu_DoMemorySave = 0,
5311
5312      kMenu_Divider,
5313
6806   enum{
6807      kMenu_Comparison,
6808      kMenu_Value,
6809      kMenu_NearTo,
6810      kMenu_Increment,
6811      kMenu_Bit,
6812      kMenu_Separator,
53146813      kMenu_CPU,
5315      kMenu_ValueEqual,
5316      kMenu_ValueNearTo,
5317      kMenu_Time,
5318      kMenu_Energy,
5319      kMenu_Status,
5320      kMenu_Operand,
5321
5322      kMenu_Divider2,
5323
6814      kMenu_Memory,
53246815      kMenu_ViewResult,
5325      kMenu_RestoreSearch,
5326
6816      kMenu_RestoreResult,
53276817      kMenu_Return,
5328   };
53296818
5330   enum
5331   {
5332      kEnergy_Less = 0,
5333      kEnergy_Greater,
5334      kEnergy_LessOrEqual,
5335      kEnergy_GreaterOrEqual,
5336   };
6819      kMenu_Max };
53376820
5338   const char      * menuItem[kMenu_Return + 2] = { 0 };
5339   const char      * menuSubItem[kMenu_Return + 2] = { 0 };
6821   enum{
6822      kComparison_Equal = 0,
6823      kComparison_NotEqual,
6824      kComparison_Less,
6825      kComparison_LessOrEqual,
6826      kComparison_Greater,
6827      kComparison_GreaterOrEqual,
6828      kComparison_Max = kComparison_GreaterOrEqual };
53406829
5341   char         valueBuffer[60];
5342   char         valueSignedBuffer[60];
5343   char         cpuBuffer[20];
6830   INT8         total         = 0;
6831   INT8         doSearch      = 0;
6832   static INT8      doneSaveMemory   = 0;
6833   const char      * menuItem[kMenu_Max + 1]      = { 0 };
6834   const char      * menuSubItem[kMenu_Max + 1]   = { 0 };
6835   char         valueBuf[32];
6836   char         incrementBuf[16];
6837   search_info      *search = get_current_search();
53446838
5345   SearchInfo      * search = GetCurrentSearch();
6839   /* first setting : adjust search items */
6840   if(menu->first_time)
6841   {
6842      search->lhs = kSearchOperand_Current;
53466843
5347   INT32         sel = selection - 1;
5348   INT32         total = 0;
5349   UINT32         increment = 1;
5350   UINT8         doSearch = 0;
6844      if(!search->old_options.delta)
6845         search->old_options.delta = 1;
53516846
5352   static INT8      submenuChoice = 0;
5353   static UINT8   doneSaveMemory = 0;
5354   static UINT8   firstEntry = 0;
5355   static int      lastPos = 0;
6847      menu->first_time = 0;
6848   }
53566849
5357   sel = lastPos;
6850   /********** MENU CONSTRUCTION **********/
6851   /* ##### COMPARISON ##### */
6852   menuItem[total] = "Comparison";
6853   if(menu->sel == kMenu_Comparison || menu->sel == kMenu_Value)
6854      menuSubItem[total++] = kComparisonNameTable[search->old_options.comparison];
6855   else
6856      menuSubItem[total++] = " ";
53586857
5359   /********** SUB MENU **********/
5360   if(submenuChoice)
6858   /* ##### VALUE ##### */
6859   menuItem[total] = "Value";
6860   if(menu->sel == kMenu_Value)
53616861   {
5362      switch(sel)
6862      if(editActive)
53636863      {
5364         case kMenu_CPU:
5365            submenuChoice = SelectSearchRegions(machine, submenuChoice, GetCurrentSearch());
5366            break;
6864         INT8   i;
6865         char   * stringsBuf = valueBuf;
53676866
5368         case kMenu_ViewResult:
5369            submenuChoice = ViewSearchResults(machine, submenuChoice, firstEntry);
5370            break;
6867         for(i = 1; i >= 0; i--)
6868         {
6869            if(i == editCursor)
6870               stringsBuf += sprintf(stringsBuf, "[%X]", (search->old_options.value & kIncrementMaskTable[i]) / kIncrementValueTable[i]);
6871            else
6872               stringsBuf += sprintf(stringsBuf, "%X", (search->old_options.value & kIncrementMaskTable[i]) / kIncrementValueTable[i]);
6873         }
6874         stringsBuf += sprintf(stringsBuf, " (%d)", search->old_options.value);
53716875      }
6876      else
6877         sprintf(valueBuf,   "%2.2X (%2.2d)", search->old_options.value, search->old_options.value);
53726878
5373      firstEntry = 0;
6879      menuSubItem[total++] = valueBuf;
6880   }
6881   else
6882      menuSubItem[total++] = " ";
53746883
5375      /* ----- meaningless ? because no longer return with sel = -1 (pressed UI_CONFIG in submenu) ----- */
5376//      if(submenuChoice == -1)
5377//          submenuChoice = 0;
6884   /* ##### VALUE - NEAR TO ##### */
6885   menuItem[total] = "Near To";
6886   if(menu->sel == kMenu_NearTo)
6887   {
6888      if(editActive)
6889      {
6890         INT8   i;
6891         char   * stringsBuf = valueBuf;
53786892
5379      return sel + 1;
6893         for(i = 1; i >=0; i--)
6894         {
6895            if(i == editCursor)
6896               stringsBuf += sprintf(stringsBuf, "[%X]", (search->old_options.value & kIncrementMaskTable[i]) / kIncrementValueTable[i]);
6897            else
6898               stringsBuf += sprintf(stringsBuf, "%X", (search->old_options.value & kIncrementMaskTable[i]) / kIncrementValueTable[i]);
6899         }
6900         stringsBuf += sprintf(stringsBuf,   " or %2.2X (%2.2d or %2.2d)",
6901                                    (search->old_options.value - 1) & kSearchByteMaskTable[search->bytes],
6902                                    search->old_options.value,
6903                                    search->old_options.value - 1);
6904      }
6905      else
6906         sprintf(valueBuf,   "%2.2X or %2.2X (%2.2d or %2.2d)",
6907                        search->old_options.value, (search->old_options.value - 1) & kSearchByteMaskTable[search->bytes],
6908                        search->old_options.value, search->old_options.value - 1);
6909      menuSubItem[total++] = valueBuf;
53806910   }
5381
5382   /********** MENU CONSTRUCTION **********/
5383   if(!doneSaveMemory)
5384      menuItem[total] = "Save Memory";
53856911   else
5386      menuItem[total] = "Initialize Memory";
6912      menuSubItem[total++] = " ";
53876913
5388   menuSubItem[total++] = NULL;
5389
5390   menuItem[total] = "--------------------";
5391   menuSubItem[total++] = NULL;
5392
5393   sprintf(cpuBuffer, "%d", search->targetIdx);
5394   menuItem[total] = "CPU";
5395   menuSubItem[total++] = cpuBuffer;
5396
5397   if(search->sign && (search->oldOptions.value & kSearchByteSignBitTable[search->bytes]))
6914   /* ##### INCREMENT/DECREMENT ##### */
6915   menuItem[total] = kIncrementNameTable[search->old_options.sign];
6916   if(menu->sel == kMenu_Increment)
53986917   {
5399      UINT32   tempValue;
6918      if(editActive)
6919      {
6920         INT8   i;
6921         char   * stringsBuf = incrementBuf;
54006922
5401      tempValue = ~search->oldOptions.value + 1;
5402      tempValue &= kSearchByteUnsignedMaskTable[search->bytes];
5403
5404      sprintf(valueBuffer, "-%.*X (-%d)", kSearchByteDigitsTable[search->bytes], tempValue, tempValue);
6923         for(i = 2; i >=0; i--)
6924         {
6925            if(i == editCursor)
6926            {
6927               if(i == 2)
6928                  stringsBuf += sprintf(stringsBuf, "[%s]", search->old_options.sign ? "-" : "+");
6929               else
6930                  stringsBuf += sprintf(stringsBuf, "[%X]", (search->old_options.delta & kIncrementMaskTable[i]) / kIncrementValueTable[i]);
6931            }
6932            else
6933            {
6934               if(i == 2)
6935                  stringsBuf += sprintf(stringsBuf, "%s", search->old_options.sign ? "-" : "+");
6936               else
6937                  stringsBuf += sprintf(stringsBuf, "%X", (search->old_options.delta & kIncrementMaskTable[i]) / kIncrementValueTable[i]);
6938            }
6939         }
6940         stringsBuf += sprintf(stringsBuf, " (%s%2.2d)", search->old_options.sign ? "-" : "+", search->old_options.delta);
6941      }
6942      else
6943      {
6944         sprintf(incrementBuf,   "%s%2.2X (%s%2.2d)",
6945                           search->old_options.sign ? "-" : "+",
6946                           search->old_options.delta,
6947                           search->old_options.sign ? "-" : "+",
6948                           search->old_options.delta);
6949      }
6950      menuSubItem[total++] = incrementBuf;
54056951   }
54066952   else
5407      sprintf(valueBuffer, "%.*X (%d)", kSearchByteDigitsTable[search->bytes], search->oldOptions.value & kSearchByteMaskTable[search->bytes], search->oldOptions.value & kSearchByteMaskTable[search->bytes]);
5408
5409   menuItem[total] = "Value (Equal)";
5410
5411   if(sel >= kMenu_ValueNearTo)
54126953      menuSubItem[total++] = " ";
5413   else
5414      menuSubItem[total++] = valueBuffer;
54156954
5416   menuItem[total] = "Value (NearTo)";
5417
5418   if(sel >= kMenu_ValueNearTo)
5419      menuSubItem[total++] = valueBuffer;
6955   /* ##### BIT ##### */
6956   menuItem[total] = "Bit";
6957   if(menu->sel == kMenu_Bit)
6958      menuSubItem[total++] = kComparisonNameTable[search->old_options.comparison];
54206959   else
54216960      menuSubItem[total++] = " ";
54226961
5423   menuItem[total] = "Timer (+ or -)";
5424   menuSubItem[total++] = " ";
6962   /* ##### SEPARATOR ##### */
6963   menuItem[total] = MENU_SEPARATOR_ITEM;
6964   menuSubItem[total++] = NULL;
54256965
5426   menuItem[total] = "Energy (Less or Greater)";
5427   menuSubItem[total++] = " ";
6966   /* ##### CPU ##### */
6967   menuItem[total] = "CPU";
6968   menuSubItem[total++] = kNumbersTable[search->target_idx];
54286969
5429   menuItem[total] = "Status (Same or Different)";
5430   menuSubItem[total++] = " ";
5431
5432   menuItem[total] = "Comparison Option";
5433   menuSubItem[total++] = " ";
5434
5435   menuItem[total] = "--------------------";
6970   /* ##### MEMORY ##### */
6971   if(doneSaveMemory)
6972      menuItem[total] = "Initialize Memory";
6973   else
6974      menuItem[total] = "Save Memory";
54366975   menuSubItem[total++] = NULL;
54376976
5438   menuItem[total] = "View Last Results";      // view result
6977   /* ##### RESULT VIEWER ##### */
6978   menuItem[total] = "View Last Results";
54396979   menuSubItem[total++] = NULL;
54406980
5441   menuItem[total] = "Restore Previous Results";   // restore result
6981   /* ##### RESULT RESTORE ##### */
6982   menuItem[total] = "Restore Previous Results";
54426983   menuSubItem[total++] = NULL;
54436984
5444   menuItem[total] = "Return to Prior Menu";   // return
6985   /* ##### RETURN ##### */
6986   menuItem[total] = "Return to Prior Menu";
54456987   menuSubItem[total++] = NULL;
54466988
5447   menuItem[total] = NULL;                        // terminate array
6989   /* ##### TERMINATE ARRAY ##### */
6990   menuItem[total] = NULL;
54486991   menuSubItem[total] = NULL;
54496992
5450   /* ----- if memory has been saved, set sub-menu items ----- */
5451   if(doneSaveMemory)
6993   /* adjust current cursor position */
6994   ADJUST_CURSOR(menu->sel, total)
6995
6996   /* draw it */
6997   old_style_menu(menuItem, menuSubItem, 0, menu->sel, 0);
6998
6999   /********** KEY HANDLING **********/
7000   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
54527001   {
5453      if(search->oldOptions.delta & kSearchByteSignBitTable[search->bytes])
7002      if(editActive)
54547003      {
5455         UINT32   tempValue;
7004         switch(menu->sel)
7005         {
7006            case kMenu_Value:
7007            case kMenu_NearTo:
7008               search->old_options.value = DoIncrementHexField(search->old_options.value, editCursor);
7009               break;
54567010
5457         tempValue = ~search->oldOptions.delta + 1;
5458         tempValue &= kSearchByteUnsignedMaskTable[search->bytes];
5459
5460         sprintf(valueSignedBuffer, "-%.*X (-%d)", kSearchByteDigitsTable[search->bytes], tempValue, tempValue);
7011            case kMenu_Increment:
7012               if(editCursor == 2)
7013                  search->old_options.sign ^= 1;
7014               else
7015                  search->old_options.delta = DoIncrementHexField(search->old_options.delta, editCursor);
7016               break;
7017         }
54617018      }
54627019      else
5463         sprintf(valueSignedBuffer, "%.*X (%d)", kSearchByteDigitsTable[search->bytes], search->oldOptions.delta & kSearchByteMaskTable[search->bytes], search->oldOptions.delta & kSearchByteMaskTable[search->bytes]);
7020      {
7021         CURSOR_TO_PREVIOUS(menu->sel, total)
54647022
5465      menuSubItem[kMenu_Time] = valueSignedBuffer;
5466      menuSubItem[kMenu_Energy] = energyStrings[search->oldOptions.energy];
5467      menuSubItem[kMenu_Status] = equalOrNotStrings[search->oldOptions.status];
5468      menuSubItem[kMenu_Operand] = operandStrings[search->oldOptions.operand];
7023         if(menu->sel == kMenu_Separator) menu->sel--;
7024      }
54697025   }
5470
5471   /* ----- adjust current cursor position ----- */
5472   if(sel < 0)
5473      sel = 0;
5474   if(sel >= total)
5475      sel = total - 1;
5476
5477   /* ----- draw it ----- */
5478   old_style_menu(menuItem, menuSubItem, 0, sel, 0);
5479
5480   /********** KEY HANDLING **********/
5481   if(AltKeyPressed())
5482      increment <<= 4;
5483
5484   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
7026   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
54857027   {
5486      sel++;
7028      if(editActive)
7029      {
7030         switch(menu->sel)
7031         {
7032            case kMenu_Value:
7033            case kMenu_NearTo:
7034               search->old_options.value = DoDecrementHexField(search->old_options.value, editCursor);
7035               break;
54877036
5488      /* ----- if divider, skip it ----- */
5489      if((sel == kMenu_Divider) || (sel == kMenu_Divider2))
5490         sel++;
7037            case kMenu_Increment:
7038               if(editCursor == 2)
7039                  search->old_options.sign ^= 1;
7040               else
7041                  search->old_options.delta = DoDecrementHexField(search->old_options.delta, editCursor);
7042               break;
7043         }
7044      }
7045      else
7046      {
7047         CURSOR_TO_NEXT(menu->sel, total)
54917048
5492      if(sel >= total)
5493         sel = 0;
7049         if(menu->sel == kMenu_Separator) menu->sel++;
7050      }
54947051   }
5495
5496   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
7052   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
54977053   {
5498      sel--;
5499
5500      /* ----- if divider, skip it ----- */
5501      if((sel == kMenu_Divider) || (sel == kMenu_Divider2))
5502         sel--;
5503
5504      if(sel < 0)
5505         sel = total - 1;
7054      if(!editActive)
7055         CURSOR_PAGE_UP(menu->sel)
55067056   }
5507
5508   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
7057   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
55097058   {
5510      sel -= fullMenuPageHeight;
5511
5512      if(sel < 0)
5513         sel = 0;
7059      if(!editActive)
7060         CURSOR_PAGE_DOWN(menu->sel, total)
55147061   }
5515
5516   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
7062   else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
55177063   {
5518      sel += fullMenuPageHeight;
7064      if(editActive)
7065      {
7066         switch(menu->sel)
7067         {
7068            case kMenu_Value:
7069            case kMenu_NearTo:
7070               if(++editCursor > 1) editCursor = 0;
7071               break;
55197072
5520      if(sel >= total)
5521         sel = total - 1;
5522   }
5523
5524   if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
5525   {
5526      switch(sel)
7073            case kMenu_Increment:
7074               if(++editCursor > 2) editCursor = 0;
7075               break;
7076         }
7077      }
7078      else
55277079      {
5528         case kMenu_CPU:
5529            if(search->targetIdx > 0)
5530            {
5531               search->targetIdx--;
7080         switch(menu->sel)
7081         {
7082            case kMenu_Comparison:
7083            case kMenu_Bit:
7084               if(--search->old_options.comparison < kComparison_Equal)
7085                  search->old_options.comparison = kComparison_Max;
7086               break;
55327087
5533               BuildSearchRegions(machine, search);
5534               AllocateSearchRegions(search);
7088            case kMenu_Value:
7089            case kMenu_NearTo:
7090               search->old_options.value = (search->old_options.value - 1) & kCheatSizeMaskTable[search->bytes];
7091               break;
55357092
5536               doneSaveMemory = 0;
5537            }
5538            break;
5539
5540         case kMenu_ValueEqual:
5541         case kMenu_ValueNearTo:
5542            search->oldOptions.value -= increment;
5543
5544            search->oldOptions.value &= kSearchByteMaskTable[search->bytes];
5545            break;
5546
5547         case kMenu_Time:
5548            if(doneSaveMemory)
5549            {
5550               search->oldOptions.delta -= increment;
5551
5552               search->oldOptions.delta &= kSearchByteMaskTable[search->bytes];
5553            }
5554            break;
5555
5556         case kMenu_Energy:
5557            if(doneSaveMemory)
5558            {
5559               if(search->oldOptions.energy < kEnergy_GreaterOrEqual)
5560                  search->oldOptions.energy++;
5561               else
5562                  search->oldOptions.energy = kEnergy_Less;
5563            }
5564            break;
5565
5566         case kMenu_Status:
5567            if(doneSaveMemory)
5568               search->oldOptions.status ^= 1;
5569            break;
5570
5571         case kMenu_Operand:
5572            if(doneSaveMemory)
5573               search->oldOptions.operand ^= 1;
5574            break;
7093            case kMenu_Increment:
7094               if(search->old_options.sign)
7095               {
7096                  if(++search->old_options.delta > kSearchByteUnsignedMaskTable[search->bytes])
7097                     search->old_options.delta = kSearchByteUnsignedMaskTable[search->bytes];
7098               }
7099               else if(--search->old_options.delta <= 0)
7100               {
7101                  search->old_options.delta = 1;
7102                  search->old_options.sign ^= 0x01;
7103               }
7104               break;
7105         }
55757106      }
55767107   }
5577
5578   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
7108   else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
55797109   {
5580      switch(sel)
7110      if(editActive)
55817111      {
5582         case kMenu_CPU:
5583            if(search->targetIdx < cpu_gettotalcpu() - 1)
5584            {
5585               search->targetIdx++;
7112         switch(menu->sel)
7113         {
7114            case kMenu_Value:
7115            case kMenu_NearTo:
7116               if(--editCursor < 0) editCursor = 1;
7117               break;
55867118
5587               BuildSearchRegions(machine, search);
5588               AllocateSearchRegions(search);
7119            case kMenu_Increment:
7120               if(--editCursor < 0) editCursor = 2;
7121               break;
7122         }
7123      }
7124      else
7125      {
7126         switch(menu->sel)
7127         {
7128            case kMenu_Comparison:
7129            case kMenu_Bit:
7130               if(++search->old_options.comparison > kComparison_GreaterOrEqual)
7131                  search->old_options.comparison = 0;
7132               break;
55897133
5590               doneSaveMemory = 0;
5591            }
5592            break;
7134            case kMenu_Value:
7135            case kMenu_NearTo:
7136               search->old_options.value = (search->old_options.value + 1) & kCheatSizeMaskTable[search->bytes];
7137               break;
55937138
5594         case kMenu_ValueEqual:
5595         case kMenu_ValueNearTo:
5596            search->oldOptions.value += increment;
5597
5598            search->oldOptions.value &= kSearchByteMaskTable[search->bytes];
5599            break;
5600
5601         case kMenu_Time:
5602            if(doneSaveMemory)
5603            {
5604               search->oldOptions.delta += increment;
5605
5606               search->oldOptions.delta &= kSearchByteMaskTable[search->bytes];
5607            }
5608            break;
5609
5610         case kMenu_Energy:
5611            if(doneSaveMemory)
5612            {
5613               if(search->oldOptions.energy > kEnergy_Less)
5614                  search->oldOptions.energy--;
5615               else
5616                  search->oldOptions.energy = kEnergy_GreaterOrEqual;
5617            }
5618            break;
5619
5620         case kMenu_Status:
5621            if(doneSaveMemory)
5622               search->oldOptions.status ^= 1;
5623            break;
5624
5625         case kMenu_Operand:
5626            if(doneSaveMemory)
5627               search->oldOptions.operand ^= 1;
5628            break;
7139            case kMenu_Increment:
7140               if(search->old_options.sign)
7141               {
7142                  if(--search->old_options.delta <= 0)
7143                  {
7144                     search->old_options.delta = 1;
7145                     search->old_options.sign ^= 0x01;
7146                  }
7147               }
7148               else if(++search->old_options.delta > kSearchByteUnsignedMaskTable[search->bytes])
7149               {
7150                  search->old_options.delta = kSearchByteUnsignedMaskTable[search->bytes];
7151               }
7152               break;
7153         }
56297154      }
56307155   }
5631
5632   if(input_ui_pressed(machine, IPT_UI_SELECT))
7156   else if(input_ui_pressed(machine, IPT_UI_SELECT))
56337157   {
5634      switch(sel)
7158      if(editActive)
7159         editActive = 0;
7160      else
56357161      {
5636         case kMenu_DoMemorySave:      // save memory to search newly
5637            doneSaveMemory = 0;
7162         switch(menu->sel)
7163         {
7164            case kMenu_Comparison:
7165               search->bytes      = kSearchSize_8Bit;
7166               search->rhs         = kSearchOperand_First;
7167               search->comparison   = kComparisonConversionTable[search->old_options.comparison];
7168               doSearch         = 1;
7169               break;
56387170
5639            doSearch = 1;
5640            break;
7171            case kMenu_Value:
7172               search->bytes      = kSearchSize_8Bit;
7173               search->rhs         = kSearchOperand_Value;
7174               search->comparison   = kComparisonConversionTable[search->old_options.comparison];
7175               search->value      = search->old_options.value;
7176               doSearch         = 1;
7177               break;
56417178
5642         case kMenu_CPU:
5643            submenuChoice = 1;         // go to region selection menu
5644            break;
7179            case kMenu_NearTo:
7180               search->bytes      = kSearchSize_8Bit;
7181               search->rhs         = kSearchOperand_Value;
7182               search->comparison   = kSearchComparison_NearTo;
7183               search->value      = search->old_options.value;
7184               doSearch         = 1;
7185               break;
56457186
5646         case kMenu_ValueEqual:
5647         case kMenu_ValueNearTo:
5648            search->bytes =         kSearchSize_8Bit;
5649            search->lhs =         kSearchOperand_Current;
5650            search->rhs =         kSearchOperand_Value;
7187            case kMenu_Increment:
7188               if(search->old_options.delta)
7189               {
7190                  search->bytes      = kSearchSize_8Bit;
7191                  search->rhs         = kSearchOperand_First;
7192                  search->comparison   = kSearchComparison_IncreasedBy;
56517193
5652            if(sel == kMenu_ValueEqual)
5653               search->comparison = kSearchComparison_EqualTo;      // search requested value
5654            else
5655               search->comparison = kSearchComparison_NearTo;      // search requested and requested -1 value
7194                  if(search->old_options.sign)
7195                     search->value   = ~search->old_options.delta + 1;
7196                  else
7197                     search->value   = search->old_options.delta;
56567198
5657            search->value =         search->oldOptions.value;
7199                  doSearch         = 1;
7200               }
7201               break;
56587202
5659            doSearch = 1;
5660            break;
7203            case kMenu_Bit:
7204               search->bytes      = kSearchSize_1Bit;
7205               search->rhs         = kSearchOperand_First;
7206               search->comparison   = kComparisonConversionTable[search->old_options.comparison];
7207               doSearch         = 1;
7208               break;
56617209
5662         case kMenu_Time:
5663            search->bytes =         kSearchSize_8Bit;
5664            search->lhs =         kSearchOperand_Current;
5665            search->rhs =         kOperandConversionTable[search->oldOptions.operand];
5666            search->comparison =   kSearchComparison_IncreasedBy;
5667            search->value =         search->oldOptions.delta;
7210            case kMenu_Memory:
7211               doneSaveMemory   = 0;
7212               doSearch      = 1;
7213               break;
56687214
5669            doSearch = 1;
5670            break;
7215            case kMenu_CPU:
7216               cheat_menu_stack_pop();
7217               break;
56717218
5672         case kMenu_Energy:
5673            search->bytes =         kSearchSize_8Bit;
5674            search->lhs =         kSearchOperand_Current;
5675            search->rhs =         kOperandConversionTable[search->oldOptions.operand];
5676            search->comparison =   kEnergyComparisonConversionTable[search->oldOptions.energy];
7219            case kMenu_ViewResult:
7220               if(search->region_list_length)
7221                  cheat_menu_stack_push(view_search_result_menu, menu->handler, menu->sel);
7222               break;
56777223
5678            doSearch = 1;
5679            break;
7224            case kMenu_RestoreResult:
7225               restore_search_backup(search);
7226               break;
56807227
5681         case kMenu_Status:
5682            search->bytes =         kSearchSize_8Bit;
5683            search->lhs =         kSearchOperand_Current;
5684            search->rhs =         kOperandConversionTable[search->oldOptions.operand];
5685            search->comparison =   kEqualOrNotConversionTable[search->oldOptions.status];
5686
5687            doSearch = 1;
5688            break;
5689
5690         case kMenu_ViewResult:
5691            if(search->regionListLength)
5692            {
5693               /* ----- go to result viewer ----- */
5694               firstEntry = 1;
5695               submenuChoice = 1;
5696            }
5697            else
5698               /* ----- if no search region (eg, sms.c in HazeMD), don't open result viewer to avoid the crash ----- */
5699               ui_popup_time(1, "no search regions");
5700            break;
5701
5702         case kMenu_RestoreSearch:
5703            /* ----- restore previous results ----- */
5704            RestoreSearchBackup(search);
5705            break;
5706
5707         case kMenu_Return:
5708            sel = -1;
5709            lastPos = 0;
5710            break;
5711
5712         default:
5713            break;
7228            case kMenu_Return:
7229               menu->sel = -1;
7230               break;
7231         }
57147232      }
57157233   }
5716
5717   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate))
5718      /* ----- quick menu switch : search -> watchpoint list ----- */
5719      sel = -5;
5720
5721   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate))
5722      /* ----- quick menu switch : search -> add/edit ----- */
5723      sel = -3;
5724
5725
5726   if(input_ui_pressed(machine, IPT_UI_CANCEL))
7234   else if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT))
57277235   {
5728      /* ----- if cursor is now on the return item, adjust cursor keeper ----- */
5729      if(sel == kMenu_Return)
5730         lastPos = 0;
5731
5732      sel = -1;
7236      if(menu->sel == kMenu_Value || menu->sel == kMenu_NearTo || menu->sel == kMenu_Increment)
7237      {
7238         editActive ^= 1;
7239         editCursor = 0;
7240      }
57337241   }
7242   else if(input_ui_pressed(machine, IPT_UI_CANCEL))
7243   {
7244      if(editActive)   editActive = 0;
7245      else         menu->sel = -1;
7246   }
57347247
7248   /***** SEARCH *****/
57357249   if(doSearch)
57367250   {
57377251      if(!doneSaveMemory)
5738         /* ----- initialize search ----- */
5739         InitializeNewSearch(search);
7252         init_new_search(search);
57407253
5741      if( (sel == kMenu_ValueEqual) || (sel == kMenu_ValueNearTo) || doneSaveMemory)
7254      if(search->rhs == kSearchOperand_Value || doneSaveMemory)
57427255      {
5743         /* ----- do search ----- */
5744         BackupSearch(search);
5745
5746         DoSearch(search);
7256         backup_search(search);
7257         do_search(search);
57477258      }
57487259
5749      UpdateSearch(search);
5750
5751      if( (sel == kMenu_ValueEqual) || (sel == kMenu_ValueNearTo) || doneSaveMemory)
5752         popmessage("%d results found", search->numResults);
5753      else
5754         popmessage("saved all memory regions");
5755
7260      update_search(search);
57567261      doneSaveMemory = 1;
57577262
5758      if(search->numResults == 1)
5759      {
7263      if(search->num_results == 1)
57607264         AddCheatFromFirstResult(search);
5761
5762         popmessage("1 result found, added to list");
5763      }
57647265   }
57657266
5766   /* ----- edit a value if direct key input ----- */
5767   if((sel == kMenu_ValueEqual) || (sel == kMenu_ValueNearTo))
7267   /********** EDIT **********/
7268   switch(menu->sel)
57687269   {
5769      search->oldOptions.value = DoEditHexField(machine, search->oldOptions.value);
7270      case kMenu_Value:
7271         search->old_options.value = do_edit_hex_field(machine, search->old_options.value);
7272         search->old_options.value &= 0xFF;
7273         break;
57707274
5771      search->oldOptions.value &= kSearchByteMaskTable[search->bytes];
7275      case kMenu_Increment:
7276         search->old_options.delta = do_edit_hex_field(machine, search->old_options.delta);
7277         search->old_options.delta &= 0x7F;
7278         break;
57727279   }
5773   else
5774   {
5775      if(sel == kMenu_Time)
5776      {
5777         search->oldOptions.delta = DoEditHexField(machine, search->oldOptions.delta);
57787280
5779         search->oldOptions.delta &= kSearchByteMaskTable[search->bytes];
5780      }
5781   }
5782
5783   /* ----- keep current cursor position ----- */
5784   if(sel >= 0)
5785      lastPos = sel;
5786
5787   return sel + 1;
7281   return menu->sel + 1;
57887282}
57897283
5790/*-----------------------------------------------------
5791  DoSearchMenu - management for advanced search menu
5792-----------------------------------------------------*/
7284/*-------------------------------------------------------------
7285  search_advanced_menu - management for advanced search menu
7286-------------------------------------------------------------*/
57937287
5794static int DoSearchMenu(running_machine *machine, int selection)
7288static int search_advanced_menu(running_machine *machine, cheat_menu_stack *menu)
57957289{
7290#if 0
57967291   /* menu stirngs */
57977292   static const char *const kOperandNameTable[] =
57987293   {
r2762r2763
58607355   char         cpuBuffer[20];
58617356   char         flagBuf[kMenu_Max + 2] = { 0 };
58627357
5863   SearchInfo      * search = GetCurrentSearch();
7358   search_info      *search = get_current_search();
58647359
58657360   INT32         sel = selection - 1;
58667361   INT32         total = 0;
58677362   UINT32         increment = 1;
58687363
5869   static INT8   submenuChoice = 0;
7364   static int      submenuChoice = 0;
58707365   static UINT8   doneMemorySave = 0;
58717366   static UINT8   editActive = 0;
58727367   static UINT8   firstEntry = 0;
r2762r2763
58807375      switch(sel)
58817376      {
58827377         case kMenu_CPU:
5883            submenuChoice = SelectSearchRegions(machine, submenuChoice, GetCurrentSearch());
7378            submenuChoice = SelectSearchRegions(machine, submenuChoice, get_current_search());
58847379            break;
58857380
58867381         case kMenu_ViewResult:
5887            submenuChoice = ViewSearchResults(machine, submenuChoice, firstEntry);
7382            submenuChoice = ViewSearchResults(submenuChoice, firstEntry);
58887383            break;
58897384      }
58907385
58917386      firstEntry = 0;
58927387
5893      /* ----- meaningless ? because no longer return with sel = -1 (pressed UI_CONFIG in submenu) ----- */
7388      /* meaningless ? because no longer return with sel = -1 (pressed UI_CONFIG in submenu) */
58947389//      if(submenuChoice == -1)
58957390//          submenuChoice = 0;
58967391
r2762r2763
59857480   menu_item[total] = NULL;                        // terminate array
59867481   menu_subitem[total] = NULL;
59877482
5988   /* ----- adjust current cursor position ----- */
7483   /* adjust current cursor position */
59897484   if(sel < 0)
59907485      sel = 0;
59917486   if(sel >= total)
59927487      sel = total - 1;
59937488
5994   /* ----- higlighted sub-item if edit mode ----- */
7489   /* higlighted sub-item if edit mode */
59957490   if(editActive)
59967491      flagBuf[sel] = 1;
59977492
5998   /* ----- draw it ----- */
7493   /* draw it */
59997494   old_style_menu(menu_item, menu_subitem, flagBuf, sel, 0);
60007495
60017496   /********** KEY HANDLING **********/
r2762r2763
60067501   if(ShiftKeyPressed())
60077502      increment <<= 16;
60087503
6009   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
7504   if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
60107505   {
60117506      sel++;
60127507
6013      /* ----- if divider, skip it ----- */
7508      /* if divider, skip it */
60147509      if((sel == kMenu_Divider) || (sel == kMenu_Divider2) || (sel == kMenu_Divider3))
60157510         sel++;
60167511
r2762r2763
60187513         sel = 0;
60197514   }
60207515
6021   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
7516   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
60227517   {
60237518      sel--;
60247519
6025      /* ----- if divider, skip it ----- */
7520      /* if divider, skip it */
60267521      if((sel == kMenu_Divider) || (sel == kMenu_Divider2) || (sel == kMenu_Divider3))
60277522         sel--;
60287523
r2762r2763
60307525         sel = total - 1;
60317526   }
60327527
6033   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
7528   if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
60347529   {
60357530      sel -= fullMenuPageHeight;
60367531
r2762r2763
60387533         sel = 0;
60397534   }
60407535
6041   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
7536   if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
60427537   {
60437538      sel += fullMenuPageHeight;
60447539
r2762r2763
60467541         sel = total - 1;
60477542   }
60487543
6049   if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
7544   if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
60507545   {
60517546      switch(sel)
60527547      {
r2762r2763
61067601      }
61077602   }
61087603
6109   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
7604   if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
61107605   {
61117606      switch(sel)
61127607      {
r2762r2763
61857680
61867681            case kMenu_DoSearch:
61877682               if(!doneMemorySave)
6188                  /* ----- initialize search ----- */
6189                  InitializeNewSearch(search);
7683                  /* initialize search */
7684                  init_new_search(search);
61907685
61917686               if((!kSearchOperandNeedsInit[search->lhs] && !kSearchOperandNeedsInit[search->rhs]) || doneMemorySave)
61927687               {
6193                  BackupSearch(search);
7688                  backup_search(search);
61947689
61957690                  DoSearch(search);
61967691               }
61977692
6198               UpdateSearch(search);
7693               update_search(search);
61997694
62007695               if((!kSearchOperandNeedsInit[search->lhs] && !kSearchOperandNeedsInit[search->rhs]) || doneMemorySave)
6201                  popmessage("%d results found", search->numResults);
7696                  popmessage("%d results found", search->num_results);
62027697               else
62037698                  popmessage("saved all memory regions");
62047699
62057700               doneMemorySave = 1;
62067701
6207               if(search->numResults == 1)
7702               if(search->num_results == 1)
62087703               {
62097704                  AddCheatFromFirstResult(search);
62107705
r2762r2763
62137708               break;
62147709
62157710            case kMenu_SaveMemory:
6216               InitializeNewSearch(search);
7711               init_new_search(search);
62177712
6218               UpdateSearch(search);
7713               update_search(search);
62197714
62207715               popmessage("saved all memory regions");
62217716
r2762r2763
62257720            case kMenu_ViewResult:
62267721               if(search->regionListLength)
62277722               {
6228                  /* ----- go to result viewer ----- */
7723                  /* go to result viewer */
62297724                  firstEntry = 1;
62307725                  submenuChoice = 1;
62317726               }
62327727               else
6233                  /* ----- if no search region (eg, sms.c in HazeMD), don't open result viewer to avoid the crash ----- */
7728                  /* if no search region (eg, sms.c in HazeMD), don't open result viewer to avoid the crash */
62347729                  ui_popup_time(1, "no search regions");
62357730               break;
62367731
62377732            case kMenu_RestoreSearch:
6238               /* ----- restore previous results ----- */
6239               RestoreSearchBackup(search);
7733               /* restore previous results */
7734               restore_search_backup(search);
62407735               break;
62417736
62427737            case kMenu_Return:
r2762r2763
62507745      }
62517746   }
62527747
6253   /* ----- edit selected field ----- */
7748   /* edit selected field */
62547749   if(editActive)
62557750   {
62567751      switch(sel)
62577752      {
62587753         case kMenu_Value:
6259            search->value = DoEditHexField(machine, search->value);
7754            search->value = do_edit_hex_field(machine, search->value);
62607755
62617756            search->value &= kSearchByteMaskTable[search->bytes];
62627757            break;
r2762r2763
62707765   if(input_ui_pressed(machine, IPT_UI_CANCEL))
62717766      sel = -1;
62727767
6273   /* ----- keep current cursor position ----- */
7768   /* keep current cursor position */
62747769   if(!(sel == -1))
62757770      lastSel = sel;
6276
6277   return sel + 1;
7771#endif
7772   return menu->sel;
62787773}
62797774
6280/*---------------------------------------------------------------------
6281  SelectSearchRegions - management for search regions selection menu
6282---------------------------------------------------------------------*/
7775/*---------------------------------------------------------------------------
7776  select_search_region_menu - management for search regions selection menu
7777---------------------------------------------------------------------------*/
62837778
6284static int SelectSearchRegions(running_machine *machine, int selection, SearchInfo * search)
7779static int select_search_region_menu(running_machine *machine, cheat_menu_stack *menu)
62857780{
6286   static const char *const kSearchSpeedList[] =
7781   static const char *const ksearch_speedList[] =
62877782   {
62887783      "Fast",
62897784      "Medium",
62907785      "Slow",
62917786      "Very Slow",
6292      "All Memory"
7787      "All Memory",
7788      "User Defined"
62937789   };
62947790
6295   INT32         sel;
7791   int            total      = 0;
7792   UINT8         doRebuild   = 0;
62967793   const char      ** menuItem;
62977794   const char      ** menuSubItem;
6298   INT32         i;
6299   INT32         total = 0;
6300   SearchRegion   * region;
7795   search_info      *search = get_current_search();
7796   search_region   *region;
63017797
6302   if(!search)
6303      return 0;
7798   /* first setting : NONE */
7799   if(menu->first_time)
7800      menu->first_time = 0;
63047801
6305   sel = selection - 1;
7802   /* required items = speed + total regions + return + terminator */
7803   request_strings(search->region_list_length + 3, 0, 0, 0);
7804   menuItem   = menu_strings.main_list;
7805   menuSubItem   = menu_strings.sub_list;
63067806
6307   RequestStrings(search->regionListLength + 3, 0, 0, 0);
6308
63097807   /********** MENU CONSTRUCTION **********/
6310   menuItem =      menuStrings.mainList;
6311   menuSubItem =   menuStrings.subList;
7808   /* ##### SEARCH SPEED ##### */
7809   menuItem[total] = "Search Speed";
7810   menuSubItem[total++] = ksearch_speedList[search->search_speed];
63127811
6313   for(i = 0; i < search->regionListLength; i++)
7812   /* ##### REGIONS ##### */
7813   if(search->region_list_length)
63147814   {
6315      SearchRegion   * traverse = &search->regionList[i];
7815      int i;
63167816
6317      menuItem[total] = traverse->name;
6318      menuSubItem[total++] = (traverse->flags & kRegionFlag_Enabled) ? "On" : "Off";
7817      for(i = 0; i < search->region_list_length; i++)
7818      {
7819         search_region *region = &search->region_list[i];
7820
7821         menuItem[total] = region->name;
7822         menuSubItem[total++] = region->flags & kRegionFlag_Enabled ? "On" : "Off";
7823      }
63197824   }
7825   else
7826   {
7827      /* in case of no SearchRegion */
7828      menuItem[total] = "No Search Region";
7829      menuSubItem[total++] = NULL;
7830   }
63207831
6321   menuItem[total] = "Search Speed";
6322   menuSubItem[total++] = kSearchSpeedList[search->searchSpeed];
6323
6324   menuItem[total] = "Return to Prior Menu";      // return item
7832   /* ##### RETURN ##### */
7833   menuItem[total] = "Return to Prior Menu";
63257834   menuSubItem[total++] = NULL;
63267835
6327   menuItem[total] = NULL;         // terminate array
7836   /* ##### TERMINATE ARRAY ##### */
7837   menuItem[total] = NULL;
63287838   menuSubItem[total] = NULL;
63297839
6330   /* ----- adjust current cursor positon ----- */
6331   if(sel < 0)
6332      sel = 0;
6333   if(sel > (total - 1))
6334      sel = total - 1;
7840   /* adjust current cursor position */
7841   ADJUST_CURSOR(menu->sel, total)
63357842
6336   if(sel < search->regionListLength)
6337      region = &search->regionList[sel];
7843   /* draw it */
7844   old_style_menu(menuItem, menuSubItem, NULL, menu->sel, 0);
7845
7846   if(search->region_list_length && menu->sel && menu->sel < total -1)
7847      region = &search->region_list[menu->sel - 1];
63387848   else
63397849      region = NULL;
63407850
6341   /* ----- draw it ----- */
6342   old_style_menu(menuItem, menuSubItem, NULL, sel, 0);
6343
63447851   /********** KEY HANDLING **********/
6345   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
7852   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
63467853   {
6347      sel++;
6348
6349      if(sel >= total)
6350         sel = 0;
7854      CURSOR_TO_PREVIOUS(menu->sel, total)
63517855   }
6352
6353   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
7856   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
63547857   {
6355      sel--;
6356
6357      if(sel < 0)
6358         sel = total - 1;
7858      CURSOR_TO_NEXT(menu->sel, total)
63597859   }
6360
6361   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
7860   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
63627861   {
6363      sel -= fullMenuPageHeight;
6364
6365      if(sel < 0)
6366         sel = 0;
7862      CURSOR_PAGE_UP(menu->sel)
63677863   }
6368
6369   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
7864   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
63707865   {
6371      sel += fullMenuPageHeight;
6372
6373      if(sel >= total)
6374         sel = total - 1;
7866      CURSOR_PAGE_DOWN(menu->sel, total)
63757867   }
6376
6377   if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
7868   else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
63787869   {
6379      if(sel < search->regionListLength)
7870      if(region)
63807871      {
6381         search->regionList[sel].flags ^= kRegionFlag_Enabled;
6382
6383         AllocateSearchRegions(search);
7872         /* toggle ON/OFF */
7873         region->flags ^= kRegionFlag_Enabled;
63847874      }
6385
6386      if(sel == search->regionListLength)   // set search speed
7875      else if(!menu->sel)
63877876      {
6388         if(search->searchSpeed > kSearchSpeed_Fast)
6389            search->searchSpeed--;
6390         else
6391            search->searchSpeed = kSearchSpeed_Max;
7877         if(--search->search_speed < 0)
7878            /* "Fast" -> "User Defined" */
7879            search->search_speed = ksearch_speed_Max - 1;
63927880
6393         BuildSearchRegions(machine, search);
6394         AllocateSearchRegions(search);
7881         doRebuild = 1;
63957882      }
63967883   }
6397
6398   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
7884   else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
63997885   {
6400      if(sel < search->regionListLength)
7886      if(region)
64017887      {
6402         search->regionList[sel].flags ^= kRegionFlag_Enabled;
6403
6404         AllocateSearchRegions(search);
7888         /* toggle ON/OFF */
7889         region->flags ^= kRegionFlag_Enabled;
64057890      }
6406
6407      if(sel == search->regionListLength)   // set search speed
7891      else if(!menu->sel)
64087892      {
6409         if(search->searchSpeed < kSearchSpeed_Max)
6410            search->searchSpeed++;
6411         else
6412            search->searchSpeed = kSearchSpeed_Fast;
7893         if(++search->search_speed >= ksearch_speed_Max)
7894            /* "User Defined" -> "Fast" */
7895            search->search_speed = ksearch_speed_Fast;
64137896
6414         BuildSearchRegions(machine, search);
6415         AllocateSearchRegions(search);
7897         doRebuild = 1;
64167898      }
64177899   }
6418
6419   if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
7900   else if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
64207901   {
6421      if(ShiftKeyPressed())         // shift + delete = invalid region
7902      if(ShiftKeyPressed() && region && search)
64227903      {
6423         if(region && search)
6424         {
6425            InvalidateEntireRegion(search, region);
6426
6427            ui_popup_time(1, "region invalidated - %d results remain", search->numResults);
6428         }
7904         /* SHIFT + CHEAT DELETE = invalidate selected region */
7905         invalidate_entire_region(search, region);
7906//          ui_popup_time(1, "region invalidated - %d results remain", search->num_results);
64297907      }
64307908   }
7909   else if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT))
7910   {
7911      if(search->search_speed == ksearch_speed_UserDefined)
7912      /* reload user region */
7913         doRebuild = 1;
7914   }
7915   else if(input_ui_pressed(machine, IPT_UI_SELECT))
7916   {
7917      if(region)
7918         region->flags ^= kRegionFlag_Enabled;
7919      else if(!menu->sel)
7920         doRebuild = 1;
7921      else
7922         menu->sel = -1;
7923   }
7924   else if(input_ui_pressed(machine, IPT_UI_CANCEL))
7925      menu->sel = -1;
64317926
6432   if(input_ui_pressed(machine, IPT_UI_SELECT))
7927   /********** REBUILD SEARCH REGION **********/
7928   if(doRebuild)
64337929   {
6434      if(sel >= total - 1)
6435         sel = -1;
7930      if(search->search_speed != ksearch_speed_UserDefined)
7931         /* rebuild SearchRegion from memory map */
7932         build_search_regions(machine, search);
7933      else
7934         /* rebuild SearchRegion from user-defined map */
7935         LoadCheatDatabase(machine, kLoadFlag_UserRegion);
7936
7937      /* reallocate SearchRegions */
7938      allocate_search_regions(search);
64367939   }
64377940
6438   if(input_ui_pressed(machine, IPT_UI_CANCEL))
6439      sel = -1;
6440
6441   return sel + 1;
7941   return menu->sel + 1;
64427942}
64437943
6444/*--------------------------------------------------------
6445  ViewSearchResults - management for search result menu
6446--------------------------------------------------------*/
7944/*--------------------------------------------------------------
7945  view_search_result_menu - management for search result menu
7946--------------------------------------------------------------*/
64477947
6448static int ViewSearchResults(running_machine *machine, int selection, int firstTime)
7948static int view_search_result_menu(running_machine *machine, cheat_menu_stack *menu)
64497949{
6450   enum
6451   {
7950   enum{
64527951      kMenu_Header = 0,
64537952      kMenu_FirstResult,
64547953
6455      kMaxResultsPerPage = 100
6456   };
7954      kMaxResultsPerPage = 100 };
64577955
7956   int            i;
7957   int            total            = 0;
7958   int            numPages;
7959   int            resultsPerPage;
7960   int            numToSkip;
7961   UINT8         hadResults         = 0;
7962   UINT8         pageSwitch         = 0;
7963   UINT8         resultsFound      = 0;
7964   UINT8         selectedAddressGood   = 0;
7965   UINT32         selectedAddress      = 0;
7966   UINT32         selectedOffset      = 0;
7967   UINT32         traverse;
64587968   const char      ** menu_item;
64597969   char         ** buf;
64607970   char         * header;
7971   search_info      *search = get_current_search();
7972   search_region   *region;
64617973
6462   SearchInfo      * search = GetCurrentSearch();
6463   SearchRegion   * region;
6464
6465   INT32         sel;
6466   INT32         total = 0;
6467   INT32         numPages;
6468   INT32         resultsPerPage;
6469   INT32         i;
6470   UINT32         traverse;
6471   UINT8         hadResults = 0;
6472   INT32         numToSkip;
6473   UINT32         resultsFound = 0;
6474   UINT32         selectedAddress = 0;
6475   UINT32         selectedOffset = 0;
6476   UINT8         selectedAddressGood = 0;
6477   int            goToNextPage = 0;
6478   int            goToPrevPage = 0;
6479
6480   RequestStrings(kMaxResultsPerPage + 3, kMaxResultsPerPage + 3, 80, 0);
6481
6482   menu_item = menuStrings.mainList;
6483   buf = &menuStrings.mainStrings[1];
6484   header = menuStrings.mainStrings[0];
6485
6486   sel = selection - 1;
6487
6488   /********** FIRST SETTING **********/
6489   if(firstTime)
7974   /* first setting : initialize region index and page number */
7975   if(menu->first_time)
64907976   {
6491      search->currentRegionIdx = 0;
6492      search->currentResultsPage = 0;
7977      search->current_region_idx = 0;
7978      search->current_results_page = 0;
64937979
6494      /* ----- set current REGION for first display ----- */
6495      for(traverse = 0; traverse < search->regionListLength; traverse++)
7980      /* set current REGION for first display */
7981      for(traverse = 0; traverse < search->region_list_length; traverse++)
64967982      {
6497         region = &search->regionList[traverse];
7983         region = &search->region_list[traverse];
64987984
6499         if(region->numResults)
7985         if(region->num_results)
65007986         {
6501            search->currentRegionIdx = traverse;
7987            search->current_region_idx = traverse;
65027988            break;
65037989         }
65047990      }
7991
7992      menu->first_time = 0;
65057993   }
65067994
6507   /* ----- adjust current REGION ----- */
6508   if(search->currentRegionIdx >= search->regionListLength)
6509      search->currentRegionIdx = search->regionListLength - 1;
6510   if(search->currentRegionIdx < 0)
6511      search->currentRegionIdx = 0;
7995   /* required items = (header + defined max items + return + terminator) & (strings buf * (header + defined max items) [max chars = 32]) */
7996   request_strings(kMaxResultsPerPage + 3, kMaxResultsPerPage, 32, 0);
7997   menu_item   = menu_strings.main_list;
7998   header      = menu_strings.main_strings[0];
7999   buf         = &menu_strings.main_strings[1];
65128000
6513   region = &search->regionList[search->currentRegionIdx];
8001   /* adjust current REGION */
8002   if(search->current_region_idx >= search->region_list_length)
8003      search->current_region_idx = search->region_list_length - 1;
8004   if(search->current_region_idx < 0)
8005      search->current_region_idx = 0;
65148006
6515   /* ----- set and adjust maximum displayable result in the PAGE ----- */
8007   region = &search->region_list[search->current_region_idx];
8008
8009   /* set the number of items per PAGE */
65168010   resultsPerPage = fullMenuPageHeight - 3;
65178011
8012   /* adjust total items per PAGE */
65188013   if(resultsPerPage <= 0)
65198014      resultsPerPage = 1;
65208015   else if(resultsPerPage > kMaxResultsPerPage)
65218016      resultsPerPage = kMaxResultsPerPage;
65228017
6523   /* ----- get the number of total page ----- */
8018   /* get the number of total PAGEs */
65248019   if(region->flags & kRegionFlag_Enabled)
6525      numPages = (region->numResults / kSearchByteStep[search->bytes] + resultsPerPage - 1) / resultsPerPage;
8020      numPages = (region->num_results / kSearchByteStep[search->bytes] + resultsPerPage - 1) / resultsPerPage;
65268021   else
65278022      numPages = 0;
65288023
6529   /* ----- adjust current PAGE ----- */
6530   if(search->currentResultsPage >= numPages)
6531      search->currentResultsPage = numPages - 1;
6532   if(search->currentResultsPage < 0)
6533      search->currentResultsPage = 0;
8024   if(numPages > fullMenuPageHeight)
8025      numPages = fullMenuPageHeight;
65348026
6535   /* ----- set the number of undisplay result ----- */
6536   numToSkip = resultsPerPage * search->currentResultsPage;
8027   /* adjust current PAGE */
8028   if(search->current_results_page >= numPages)
8029      search->current_results_page = numPages - 1;
8030   if(search->current_results_page < 0)
8031      search->current_results_page = 0;
65378032
8033   /* set the number of skipping results to undisplay */
8034   numToSkip = resultsPerPage * search->current_results_page;
8035
65388036   /********** MENU CONSTRUCTION **********/
6539   /* ----- construct header item ----- */
6540   sprintf(header, "%s %d/%d", region->name, search->currentResultsPage + 1, numPages);
8037   /* ##### HEADER ##### */
8038   sprintf(header, "%s %d/%d", region->name, search->current_results_page + 1, numPages);
65418039
65428040   menu_item[total++] = header;
65438041
65448042   traverse = 0;
65458043
65468044   if((region->length < kSearchByteIncrementTable[search->bytes]) || !(region->flags & kRegionFlag_Enabled))
8045   {
65478046      ; // no results...
8047   }
65488048   else
65498049   {
6550      /* ----- construct result item ----- */
6551      for(i = 0; (i < resultsPerPage) && (traverse < region->length) && (resultsFound < region->numResults);)
8050      /* ##### RESULT ##### */
8051      for(i = 0; i < resultsPerPage && traverse < region->length && resultsFound < region->num_results;)
65528052      {
6553         while(!IsRegionOffsetValid(search, region, traverse) && (traverse < region->length))
8053         while(is_region_offset_valid(search, region, traverse) == 0 && traverse < region->length)
65548054            traverse += kSearchByteStep[search->bytes];
65558055
65568056         if(traverse < region->length)
r2762r2763
65598059               numToSkip--;
65608060            else
65618061            {
6562               if(total == sel)
8062               if(total == menu->sel)
65638063               {
6564                  selectedAddress =      region->address + traverse;
6565                  selectedOffset =      traverse;
6566                  selectedAddressGood =   1;
8064                  selectedAddress      = region->address + traverse;
8065                  selectedOffset      = traverse;
8066                  selectedAddressGood   = 1;
65678067               }
65688068
65698069               sprintf(   buf[total],
65708070                        "%.8X (%.*X %.*X %.*X)",
65718071                        region->address + traverse,
65728072                        kSearchByteDigitsTable[search->bytes],
6573                        ReadSearchOperand(kSearchOperand_First, search, region, region->address + traverse),
8073                        read_search_operand(kSearchOperand_First, search, region, region->address + traverse),
65748074                        kSearchByteDigitsTable[search->bytes],
6575                        ReadSearchOperand(kSearchOperand_Previous, search, region, region->address + traverse),
8075                        read_search_operand(kSearchOperand_Previous, search, region, region->address + traverse),
65768076                        kSearchByteDigitsTable[search->bytes],
6577                        ReadSearchOperand(kSearchOperand_Current, search, region, region->address + traverse));
8077                        read_search_operand(kSearchOperand_Current, search, region, region->address + traverse));
65788078
65798079               menu_item[total] = buf[total];
65808080               total++;
r2762r2763
65898089      }
65908090   }
65918091
6592   /* ----- set special message if empty REGION ----- */
8092   /* set special message if empty REGION */
65938093   if(!hadResults)
65948094   {
6595      if(search->numResults)
8095      if(search->num_results)
65968096         menu_item[total++] = "no results for this region";
65978097      else
65988098         menu_item[total++] = "no results found";
65998099   }
66008100
6601   menu_item[total++] = "Return to Prior Menu";      // return
8101   /* ##### RETURN ##### */
8102   menu_item[total++] = "Return to Prior Menu";
66028103
6603   menu_item[total] = NULL;                           // terminate array
8104   /* ##### TERMINATE ARRAY ##### */
8105   menu_item[total] = NULL;
66048106
6605   /* ----- adjust current cursor position ----- */
6606   if(sel <= kMenu_Header)
6607      sel = kMenu_FirstResult;
6608   if(sel > (total - 1) || !hadResults)
6609      sel = total - 1;
8107   /* adjust current cursor position */
8108   if(menu->sel <= kMenu_Header)
8109      menu->sel = kMenu_FirstResult;
8110   if(menu->sel > total - 1 || !hadResults)
8111      menu->sel = total - 1;
66108112
6611   /* ----- draw it ----- */
6612   old_style_menu(menu_item, NULL, NULL, sel, 0);
8113   /* draw it */
8114   old_style_menu(menu_item, NULL, NULL, menu->sel, 0);
66138115
66148116   /********** KEY HANDLING **********/
6615   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
8117   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
66168118   {
6617      sel++;
6618
6619      if(sel >= total)
6620         sel = kMenu_FirstResult;
8119      if(--menu->sel < 1)
8120         menu->sel = total - 1;
66218121   }
6622
6623   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
8122   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
66248123   {
6625      sel--;
6626
6627      if(sel < 1)
6628         sel = total - 1;
8124      if(++menu->sel >= total)
8125         menu->sel = kMenu_FirstResult;
66298126   }
6630
6631   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
8127   else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
66328128   {
66338129      if(ShiftKeyPressed())
6634         search->currentResultsPage = numPages - 1;            // shift + right = go to last PAGE
6635      else
66368130      {
6637         if(ControlKeyPressed())
6638         {
6639            search->currentRegionIdx++;                     // ctrl + right = go to next REGION
8131         /* shift + right = go to last PAGE */
8132         search->current_results_page = numPages - 1;
8133      }
8134      else if(ControlKeyPressed())
8135      {
8136         /* ctrl + right = go to next REGION */
8137         search->current_region_idx++;
66408138
6641            if(search->currentRegionIdx >= search->regionListLength)
6642               search->currentRegionIdx = 0;
6643         }
6644         else
6645            goToNextPage = 1;                           // right = go to next PAGE
8139         if(search->current_region_idx >= search->region_list_length)
8140            search->current_region_idx = 0;
66468141      }
8142      else
8143      {
8144         /* otherwise, go to next PAGE */
8145         pageSwitch = 1;
8146      }
66478147
6648      sel = kMenu_FirstResult;
8148      menu->sel = kMenu_FirstResult;
66498149   }
6650
6651   if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
8150   else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
66528151   {
66538152      if(ShiftKeyPressed())
6654         search->currentResultsPage = 0;                     // shift + left = go to first PAGE
6655      else
66568153      {
6657         if(ControlKeyPressed())
6658         {
6659            search->currentRegionIdx--;                     // ctrl + left = go to previous REGION
8154         /* shift + left = go to first PAGE */
8155         search->current_results_page = 0;
8156      }
8157      else if(ControlKeyPressed())
8158      {
8159         /* ctrl + left = go to previous REGION */
8160         search->current_region_idx--;
66608161
6661            if(search->currentRegionIdx < 0)
6662               search->currentRegionIdx = search->regionListLength - 1;
6663         }
6664         else
6665            goToPrevPage = 1;                           // left = go to previous PAGE
8162         if(search->current_region_idx < 0)
8163            search->current_region_idx = search->region_list_length - 1;
66668164      }
8165      else
8166      {
8167         /* otherwise, go to previous PAGE */
8168         pageSwitch = 2;
8169      }
66678170
6668      sel = kMenu_FirstResult;
8171      menu->sel = kMenu_FirstResult;
66698172   }
6670
6671   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kHorizontalFastKeyRepeatRate))
8173   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kHorizontalFastKeyRepeatRate))
66728174   {
6673      sel -=fullMenuPageHeight;
8175      menu->sel -=fullMenuPageHeight;
66748176
6675      if(sel <= kMenu_Header)
6676         sel = kMenu_FirstResult;
8177      if(menu->sel <= kMenu_Header)
8178         menu->sel = kMenu_FirstResult;
66778179   }
6678
6679   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kHorizontalFastKeyRepeatRate))
8180   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kHorizontalFastKeyRepeatRate))
66808181   {
6681      sel +=fullMenuPageHeight;
8182      menu->sel +=fullMenuPageHeight;
66828183
6683      if(sel >= total)
6684         sel = total - 1;
8184      if(menu->sel >= total)
8185         menu->sel = total - 1;
66858186   }
6686
6687   if(input_code_pressed_once(KEYCODE_END))
6688      search->currentResultsPage = numPages - 1;            // go to last PAGE
6689
6690   if(input_code_pressed_once(KEYCODE_HOME))
6691      search->currentResultsPage = 0;                     // go to first PAGE
6692
6693   if(UIPressedRepeatThrottle(machine, IPT_UI_PREV_GROUP, kVerticalKeyRepeatRate))
8187   else if(input_code_pressed_once(KEYCODE_HOME))
66948188   {
6695      search->currentRegionIdx--;                        // go to previous REGION
8189      /* go to first PAGE */
8190      search->current_results_page = 0;
8191   }
8192   else if(input_code_pressed_once(KEYCODE_END))
8193   {
8194      /* go to last PAGE */
8195      search->current_results_page = numPages - 1;
8196   }
8197   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PREV_GROUP, kVerticalKeyRepeatRate))
8198   {
8199      /* go to previous REGION */
8200      search->current_region_idx--;
66968201
6697      if(search->currentRegionIdx < 0)
6698         search->currentRegionIdx = search->regionListLength - 1;
8202      if(search->current_region_idx < 0)
8203         search->current_region_idx = search->region_list_length - 1;
66998204
6700      sel = kMenu_FirstResult;
8205      menu->sel = kMenu_FirstResult;
67018206   }
6702
6703   if(UIPressedRepeatThrottle(machine, IPT_UI_NEXT_GROUP, kVerticalKeyRepeatRate))
8207   else if(ui_pressed_repeat_throttle(machine, IPT_UI_NEXT_GROUP, kVerticalKeyRepeatRate))
67048208   {
6705      search->currentRegionIdx++;                        // go to next REGION
8209      /* go to next REGION */
8210      search->current_region_idx++;
67068211
6707      if(search->currentRegionIdx >= search->regionListLength)
6708         search->currentRegionIdx = 0;
8212      if(search->current_region_idx >= search->region_list_length)
8213         search->current_region_idx = 0;
67098214
6710      sel = kMenu_FirstResult;
8215      menu->sel = kMenu_FirstResult;
67118216   }
6712
6713   if(goToNextPage)
8217   else if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT))
67148218   {
6715      search->currentResultsPage++;
6716
6717      /* ----- if current PAGE is the last, go to first PAGE in next REGION ----- */
6718      if(search->currentResultsPage >= numPages)
8219      if(selectedAddressGood)
8220         AddCheatFromResult(search, region, selectedAddress);
8221   }
8222   else if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
8223   {
8224      if(ShiftKeyPressed())
67198225      {
6720         search->currentResultsPage = 0;
6721         search->currentRegionIdx++;
8226         if(region && search)
8227            /* shift + delete = invalidate all results in current REGION */
8228            invalidate_entire_region(search, region);
8229      }
8230      else if(selectedAddressGood)
8231      {
8232         /* otherwise, delete selected result */
8233         invalidate_region_offset(search, region, selectedOffset);
8234         search->num_results--;
8235         region->num_results--;
67228236
6723         /* ----- if current REGION is the last, go to first REGION ----- */
6724         if(search->currentRegionIdx >= search->regionListLength)
6725            search->currentRegionIdx = 0;
6726
6727         /* ----- if next REGION is empty, search next "non-empty" REGION.
6728                     but incomplete because last REGION is displayed even if empty ----- */
6729         for(traverse = search->currentRegionIdx; traverse < search->regionListLength; traverse++)
6730         {
6731            search->currentRegionIdx = traverse;
6732
6733            if(search->regionList[traverse].numResults)
6734               break;
6735         }
8237         messageType = kCheatMessage_SucceededToDelete;
8238         messageTimer = DEFAULT_MESSAGE_TIME;
67368239      }
6737
6738      sel = kMenu_FirstResult;
67398240   }
8241   else if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE))
8242   {
8243      if(selectedAddressGood)
8244         AddWatchFromResult(search, region, selectedAddress);
8245   }
8246   else if(input_ui_pressed(machine, IPT_UI_SELECT) || input_ui_pressed(machine, IPT_UI_CANCEL))
8247      menu->sel = -1;
67408248
6741   if(goToPrevPage)
8249   switch(pageSwitch)
67428250   {
6743      search->currentResultsPage--;
8251      case 1:      // go to next PAGE
8252         search->current_results_page++;
67448253
6745      /* ----- if current PAGE is first, go to previous REGION ----- */
6746      if(search->currentResultsPage < 0)
6747      {
6748         search->currentResultsPage = 0;
6749         search->currentRegionIdx--;
8254         /* if current PAGE is the last, go to first PAGE in next REGION */
8255         if(search->current_results_page >= numPages)
8256         {
8257            search->current_results_page = 0;
8258            search->current_region_idx++;
67508259
6751         /* ----- if current REGION is first, go to last REGION ----- */
6752         if(search->currentRegionIdx < 0)
6753            search->currentRegionIdx = search->regionListLength - 1;
8260            /* if current REGION is the last, go to first REGION */
8261            if(search->current_region_idx >= search->region_list_length)
8262               search->current_region_idx = 0;
67548263
6755         /* ----- if previous REGION is empty, search previous "non-empty" REGION.
6756                     but incomplete because first REGION is displayed even if empty ----- */
6757         for(i = search->currentRegionIdx; i >= 0; i--)
6758         {
6759            search->currentRegionIdx = i;
8264            /* if next REGION is empty, search next "non-empty" REGION.
8265                     but incomplete because last REGION is displayed even if empty */
8266            for(traverse = search->current_region_idx; traverse < search->region_list_length; traverse++)
8267            {
8268               search->current_region_idx = traverse;
67608269
6761            if(search->regionList[i].numResults)
6762               break;
8270               if(search->region_list[traverse].num_results)
8271                  break;
8272            }
67638273         }
67648274
6765         /* ----- go to last PAGE in previous REGION ----- */
6766         {
6767            /* ----- get the number of total page for previous REGION ----- */
6768            SearchRegion   * newRegion = &search->regionList[search->currentRegionIdx];
6769            UINT32         nextNumPages = (newRegion->numResults / kSearchByteStep[search->bytes] + resultsPerPage - 1) / resultsPerPage;
8275         menu->sel = kMenu_FirstResult;
8276         break;
67708277
6771            if(nextNumPages <= 0)
6772               nextNumPages = 1;
8278      case 2:      // go to previous PAGE
8279         search->current_results_page--;
67738280
6774            search->currentResultsPage = nextNumPages - 1;
6775         }
6776      }
8281         /* if current PAGE is first, go to previous REGION */
8282         if(search->current_results_page < 0)
8283         {
8284            search->current_results_page = 0;
8285            search->current_region_idx--;
67778286
6778      sel = kMenu_FirstResult;
6779   }
8287            /* if current REGION is first, go to last REGION */
8288            if(search->current_region_idx < 0)
8289               search->current_region_idx = search->region_list_length - 1;
67808290
6781   if(selectedAddressGood)
6782   {
6783      if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE))
6784         AddWatchFromResult(search, region, selectedAddress);      // watch selected result
8291            /* if previous REGION is empty, search previous "non-empty" REGION.
8292                     but incomplete because first REGION is displayed even if empty */
8293            for(i = search->current_region_idx; i >= 0; i--)
8294            {
8295               search->current_region_idx = i;
67858296
6786      if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT))
6787         AddCheatFromResult(search, region, selectedAddress);      // add selected result as new code to cheat list
8297               if(search->region_list[i].num_results)
8298                  break;
8299            }
67888300
6789      if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
6790      {
6791         InvalidateRegionOffset(search, region, selectedOffset);      // delete selected result
6792         search->numResults--;
6793         region->numResults--;
6794      }
6795   }
8301            /* go to last PAGE in previous REGION */
8302            {
8303               /* get the number of total PAGEs for previous REGION */
8304               search_region   *new_region      = &search->region_list[search->current_region_idx];
8305               UINT32         nextNumPages   = (new_region->num_results / kSearchByteStep[search->bytes] + resultsPerPage - 1) / resultsPerPage;
67968306
6797   if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
6798   {
6799      if(ShiftKeyPressed())
6800      {
6801         if(region && search)
6802         {
6803            InvalidateEntireRegion(search, region);               // invalidate all results in current REGION
8307               if(nextNumPages <= 0)
8308                  nextNumPages = 1;
68048309
6805            ui_popup_time(1, "region invalidated - %d results remain", search->numResults);
8310               search->current_results_page = nextNumPages - 1;
8311            }
68068312         }
6807      }
8313
8314         menu->sel = kMenu_FirstResult;
8315         break;
68088316   }
68098317
6810   if((input_ui_pressed(machine, IPT_UI_SELECT) && (sel == total - 1)) || input_ui_pressed(machine, IPT_UI_CANCEL))
6811      sel = -1;
6812
6813   return sel + 1;
8318   return menu->sel + 1;
68148319}
68158320
6816/*----------------------------------------------------
6817  ChooseWatch - management for watchpoint list menu
6818----------------------------------------------------*/
8321/*----------------------------------------------------------
8322  choose_watch_menu - management for watchpoint list menu
8323----------------------------------------------------------*/
68198324
6820static int ChooseWatch(running_machine *machine, int selection)
8325static int choose_watch_menu(running_machine *machine, cheat_menu_stack *menu)
68218326{
8327   int            i;
8328   UINT8         total         = 0;
68228329   const char      ** menuItem;
68238330   char         ** buf;
6824
8331   char         * stringsBuf;   // "USER20 FFFFFFFF (99:32 Bit)"    27 chars
68258332   WatchInfo      * watch;
68268333
6827   static INT32   submenuChoice = 0;
6828   static INT32   submenuWatch = 0;
6829   INT32         sel;
6830   INT32         total = 0;
6831   int            i;
8334   /* first setting : NONE */
8335   if(menu->first_time)
8336      menu->first_time = 0;
68328337
6833   RequestStrings(watchListLength + 2, watchListLength, 30, 0);
8338   /* required items = (total watchpoints + return + terminator) & (strings buf * total watchpoints [max chars = 32]) */
8339   request_strings(watchListLength + 2, watchListLength, 32, 0);
8340   menuItem   = menu_strings.main_list;
8341   buf         = menu_strings.main_strings;
68348342
6835   menuItem = menuStrings.mainList;
6836   buf = menuStrings.mainStrings;
8343   /********** MENU CONSTRUCTION **********/
8344   for(i = 0; i < watchListLength; i++)
8345   {
8346      WatchInfo   * traverse   = &watchList[i];
8347      cpu_region_info *info = get_cpu_or_region_info(traverse->cpu);
68378348
6838   sel = selection - 1;
8349      /* FORMAT : "CPU/Region : Address (Length : Bytes)" */
8350      if(!editActive || menu->sel != i)
8351      {
8352         sprintf(buf[i], "%s:%.*X (%d:%s)",
8353            get_region_name(traverse->cpu),
8354            info->address_chars_needed,
8355            traverse->address,
8356            traverse->numElements,
8357            kByteSizeStringList[traverse->elementBytes]);
8358      }
8359      else
8360      {
8361         /* insert edit cursor in quick edit mode */
8362         switch(editCursor)
8363         {
8364            default:
8365            {
8366               INT8 j;
68398367
6840   /********** SUB MENU **********/
6841   if(submenuChoice)
6842   {
6843      submenuChoice = EditWatch(machine, &watchList[submenuWatch], submenuChoice);
8368               stringsBuf = buf[i];
68448369
6845      /* ----- meaningless ? because no longer return with sel = -1 (pressed UI_CONFIG in submenu) ----- */
6846//      if(submenuChoice == -1)
6847//      {
6848//          submenuChoice = 0;
6849//          sel = -2;
6850//      }
8370               stringsBuf += sprintf(stringsBuf, "%s ", get_region_name(traverse->cpu));
68518371
6852      return sel + 1;
6853   }
8372               for(j = info->address_chars_needed + 1; j > 1; j--)
8373               {
8374                  INT8 digits = j - 2;
68548375
6855   /********** MENU CONSTRUCTION **********/
6856   for(i = 0; i < watchListLength; i++)
6857   {
6858      WatchInfo   * traverse = &watchList[i];
8376                  if(j == editCursor)
8377                     stringsBuf += sprintf(stringsBuf, "[%X]", (traverse->address & kIncrementMaskTable[digits]) / kIncrementValueTable[digits]);
8378                  else
8379                     stringsBuf += sprintf(stringsBuf, "%X", (traverse->address & kIncrementMaskTable[digits]) / kIncrementValueTable[digits]);
8380               }
68598381
6860      sprintf(buf[i], "%d:%.*X (%d)", traverse->cpu, cpuInfoList[traverse->cpu].addressCharsNeeded, traverse->address, traverse->numElements);
8382               stringsBuf += sprintf(stringsBuf, " (%d:%s)", traverse->numElements, kByteSizeStringList[traverse->elementBytes]);
8383            }
8384            break;
68618385
8386            case 1:
8387               sprintf(buf[i], "%s:%.*X ([%d]:%s)",
8388                  get_region_name(traverse->cpu),
8389                  info->address_chars_needed,
8390                  traverse->address,
8391                  traverse->numElements,
8392                  kByteSizeStringList[traverse->elementBytes]);
8393               break;
8394
8395            case 0:
8396               sprintf(buf[i], "%s:%.*X (%d:[%s])",
8397                  get_region_name(traverse->cpu),
8398                  info->address_chars_needed,
8399                  traverse->address,
8400                  traverse->numElements,
8401                  kByteSizeStringList[traverse->elementBytes]);
8402               break;
8403         }
8404      }
8405
68628406      menuItem[total] = buf[i];
68638407      total++;
68648408   }
68658409
6866   menuItem[total++] = "Return to Prior Menu";      // return
8410   /* ##### RETURN ##### */
8411   menuItem[total++] = "Return to Prior Menu";
68678412
6868   menuItem[total] = NULL;                           // terminate array
8413   /* ##### TERMINATE ARRAY ##### */
8414   menuItem[total] = NULL;
68698415
6870   /* ----- adjust current cursor position ----- */
6871   if(sel < 0)
6872      sel = 0;
6873   if(sel >= total)
6874      sel = total - 1;
8416   /* adjust current cursor position */
8417   ADJUST_CURSOR(menu->sel, total)
68758418
6876   /* ----- draw it ----- */
6877   old_style_menu(menuItem, NULL, NULL, sel, 0);
8419   /* draw it */
8420   old_style_menu(menuItem, NULL, NULL, menu->sel, 0);
68788421
6879   if(sel < watchListLength)
6880      watch = &watchList[sel];
8422   if(menu->sel < watchListLength)
8423      watch = &watchList[menu->sel];
68818424   else
68828425      watch = NULL;
68838426
68848427   /********** KEY HANDLING **********/
6885   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
8428   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
68868429   {
6887      sel++;
8430      if(!editActive)
8431      {
8432         CURSOR_TO_PREVIOUS(menu->sel, total)
8433      }
8434      else
8435      {
8436         switch(editCursor)
8437         {
8438            default:
8439               watch->address = DoIncrementHexField(watch->address, editCursor - 2);
8440               break;
68888441
6889      if(sel >= total)
6890         sel = 0;
8442            case 1:
8443               if(watch->numElements < 99)
8444                  watch->numElements++;
8445               break;
8446
8447            case 0:
8448               watch->elementBytes = (watch->elementBytes + 1) & 0x03;
8449               break;
8450         }
8451      }
68918452   }
6892
6893   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
8453   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
68948454   {
6895      sel--;
8455      if(!editActive)
8456      {
8457         CURSOR_TO_NEXT(menu->sel, total)
8458      }
8459      else
8460      {
8461         switch(editCursor)
8462         {
8463            default:
8464               watch->address = DoDecrementHexField(watch->address, editCursor - 2);
8465               break;
68968466
6897      if(sel < 0)
6898         sel = total - 1;
8467            case 1:
8468               if(watch->numElements > 0)
8469                  watch->numElements--;
8470               break;
8471
8472            case 0:
8473               watch->elementBytes = (watch->elementBytes - 1) & 0x03;
8474               break;
8475         }
8476      }
68998477   }
6900
6901   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
8478   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
69028479   {
6903      sel -= fullMenuPageHeight;
6904
6905      if(sel < 0)
6906         sel = 0;
8480      if(!editActive)
8481         CURSOR_PAGE_UP(menu->sel)
69078482   }
6908
6909   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
8483   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
69108484   {
6911      sel += fullMenuPageHeight;
8485      if(!editActive)
8486         CURSOR_PAGE_DOWN(menu->sel, total)
8487   }
8488   else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kVerticalKeyRepeatRate))
8489   {
8490      if(editActive)
8491      {
8492         cpu_region_info *info = get_cpu_or_region_info(watch->cpu);
69128493
6913      if(sel >= total)
6914         sel = total - 1;
8494         if(++editCursor > info->address_chars_needed + 1)
8495            editCursor = 0;
8496      }
69158497   }
6916
6917   if(ShiftKeyPressed())
8498   else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kVerticalKeyRepeatRate))
69188499   {
6919      if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT))            // shift + add = add new watchpoint
6920         AddWatchBefore(sel);
8500      if(editActive)
8501      {
8502         cpu_region_info *info = get_cpu_or_region_info(watch->cpu);
69218503
6922      if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))         // shift + delete = delete selected watchpoint
6923         DeleteWatchAt(sel);
8504         if(--editCursor < 0)
8505            editCursor = info->address_chars_needed + 1;
8506      }
69248507   }
6925   else
8508   else if(input_ui_pressed(machine, IPT_UI_SELECT))
69268509   {
6927      if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))            // save = save selected watchpoint as watchpoint code
8510      if(editActive)
8511         editActive = 0;
8512      else
69288513      {
69298514         if(watch)
8515            cheat_menu_stack_push(command_watch_menu, menu->handler, menu->sel);
8516         else
8517            menu->sel = -1;
8518      }
8519   }
8520   else if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT))
8521   {
8522      if(!editActive && watch)
8523      {
8524         if(ShiftKeyPressed())
8525            AddCheatFromWatch(watch);
8526         else if(ControlKeyPressed())
69308527         {
6931            CheatEntry   entry;
8528            CheatEntry * entry = GetNewCheat();
69328529
6933            memset(&entry, 0, sizeof(CheatEntry));
8530            DisposeCheat(entry);
8531            SetupCheatFromWatchAsWatch(entry, watch);
69348532
6935            SetupCheatFromWatchAsWatch(&entry, watch);
6936            SaveCheat(machine, &entry, 0, 0);
6937            DisposeCheat(&entry);
6938         }
6939      }
6940
6941      if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT))
6942      {
6943         if(watch)
6944         {
6945            if(ControlKeyPressed())                     // ctrl + add = add selected watchpoing as watchpoint code to cheat list
8533            /* when fails to add, delete this entry because it causes the crash */
8534            if(messageType == kCheatMessage_FailedToAdd)
69468535            {
6947               CheatEntry   * entry = GetNewCheat();
6948
6949               DisposeCheat(entry);
6950               SetupCheatFromWatchAsWatch(entry, watch);
8536               DeleteCheatAt(cheatListLength - 1);
8537               messageType      = kCheatMessage_FailedToAdd;
8538               messageTimer   = DEFAULT_MESSAGE_TIME;
69518539            }
6952            else
6953               AddCheatFromWatch(watch);               // add = add selected watchpoint as cheat code to cheat list
69548540         }
8541         else
8542            AddWatchBefore(menu->sel);
69558543      }
6956
6957      if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
8544   }
8545   else if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
8546   {
8547      if(!editActive && watch)
69588548      {
6959         if(ControlKeyPressed())
8549         if(ShiftKeyPressed())
69608550         {
6961            for(i = 0; i < watchListLength; i++)      // ctrl + delete = disable all watchpoints
8551            DeleteWatchAt(menu->sel);
8552         }
8553         else if(ControlKeyPressed())
8554         {
8555            for(i = 0; i < watchListLength; i++)
69628556               watchList[i].numElements = 0;
69638557         }
69648558         else
69658559         {
6966            if(watch)                           // delete = disable selected watchpoint
8560            if(watch)
69678561               watch->numElements = 0;
69688562         }
69698563      }
8564      else if(editActive)
8565      {
8566         switch(editCursor)
8567         {
8568            default:
8569               watch->address = 0;
8570               break;
8571
8572            case 1:
8573               watch->numElements = 0;
8574               break;
8575
8576            case 0:
8577               watch->elementBytes = 0;
8578         }
8579      }
69708580   }
6971
6972   if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT))               // edit = edit selected watchpoint
8581   else if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))
69738582   {
6974      if(sel < (total - 1))
8583      if(!editActive && watch)
69758584      {
6976         submenuWatch = sel;
6977         submenuChoice = 1;
8585         CheatEntry entry;
8586
8587         memset(&entry, 0, sizeof(CheatEntry));
8588
8589         SetupCheatFromWatchAsWatch(&entry, watch);
8590         SaveCheatCode(machine, &entry);
8591         DisposeCheat(&entry);
69788592      }
69798593   }
6980
6981   if(input_ui_pressed(machine, IPT_UI_SELECT))
8594   else if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT))
69828595   {
6983      if(sel == (total - 1))                  // return previous menu
8596      if(watch)
69848597      {
6985         submenuChoice = 0;
6986         sel = -1;
8598         editCursor = 2;
8599         editActive ^= 1;
69878600      }
6988      else
8601   }
8602   else if(input_ui_pressed(machine, IPT_UI_CLEAR))
8603   {
8604      if(!editActive)
69898605      {
6990         if(sel < (total - 1))               // edit selected watchpoint (same as edit key)
8606         if(ShiftKeyPressed())
69918607         {
6992            submenuWatch = sel;
6993            submenuChoice = 1;
8608            if(watch)
8609               ResetWatch(watch);
69948610         }
8611         else
8612         {
8613            for(i = 0; i < watchListLength; i++)
8614               ResetWatch(&watchList[i]);
8615         }
69958616      }
8617      else
8618      {
8619         watch->address = 0;
8620         watch->numElements = 0;
8621         watch->elementBytes = 0;
8622      }
69968623   }
8624   else if(input_ui_pressed(machine, IPT_UI_CANCEL))
8625   {
8626      if(editActive)
8627         editActive = 0;
8628      else
8629         menu->sel = -1;
8630   }
69978631
6998   if(input_ui_pressed(machine, IPT_UI_CLEAR))
8632   return menu->sel + 1;
8633}
8634
8635/*--------------------------------------------------------------
8636  command_watch_menu - management for wathcpoint command menu
8637--------------------------------------------------------------*/
8638
8639static int command_watch_menu(running_machine *machine, cheat_menu_stack *menu)
8640{
8641   enum{
8642      kMenu_EditWatch = 0,
8643      kMenu_DisableWatch,
8644      kMenu_DisableAllWatch,
8645      kMenu_ResetWatch,
8646      kMenu_ResetAllWatch,
8647      kMenu_AddAsCheatCode,
8648      kMenu_AddAsWatchCode,
8649      kMenu_SaveAsCheatCode,
8650      kMenu_SaveAsWatchCode,
8651      kMenu_AddWatch,
8652      kMenu_DeleteWatch,
8653      kMenu_Return,
8654      kMenu_Max };
8655
8656   int            i;
8657   UINT8         total   = 0;
8658   ui_menu_item   menuItem[kMenu_Max + 1];
8659   WatchInfo      * entry   = &watchList[menu->pre_sel];
8660
8661   /* first setting : NONE */
8662   if(menu->first_time)
8663      menu->first_time = 0;
8664
8665   memset(menuItem, 0, sizeof(menuItem));
8666
8667   /********** MENU CONSTRUCION **********/
8668   menuItem[total++].text = "Edit Watchpoint";
8669   menuItem[total++].text = "Disable Watchpoint";
8670   menuItem[total++].text = "Disable All Watchpoints";
8671   menuItem[total++].text = "Reset Watchpoint";
8672   menuItem[total++].text = "Reset All Watchpoints";
8673   menuItem[total++].text = "Add as Cheat Code";
8674   menuItem[total++].text = "Add as Watch Code";
8675   menuItem[total++].text = "Save as Cheat Code";
8676   menuItem[total++].text = "Save as Watch Code";
8677   menuItem[total++].text = "Add New Watchpoint";
8678   menuItem[total++].text = "Delete Watchpoint";
8679   menuItem[total++].text = "Return to Prior Menu";
8680   menuItem[total].text = NULL;
8681
8682   /* adjust current cursor position */
8683   ADJUST_CURSOR(menu->sel, total)
8684
8685   /* print it */
8686   ui_menu_draw(menuItem, total, menu->sel, NULL);
8687
8688   /********** KEY HANDLING **********/
8689   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
69998690   {
7000      /* ----- reset all watchpoints ----- */
7001      for(i = 0; i < watchListLength; i++)
8691      CURSOR_TO_PREVIOUS(menu->sel, total)
8692   }
8693   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
8694   {
8695      CURSOR_TO_NEXT(menu->sel, total)
8696   }
8697   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
8698   {
8699      CURSOR_PAGE_UP(menu->sel)
8700   }
8701   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
8702   {
8703      CURSOR_PAGE_DOWN(menu->sel, total)
8704   }
8705   else if(input_ui_pressed(machine, IPT_UI_SELECT))
8706   {
8707      switch(menu->sel)
70028708      {
7003         if(watch)
8709         case kMenu_EditWatch:
8710            cheat_menu_stack_push(edit_watch_menu, menu->return_handler, menu->pre_sel);
8711            break;
8712
8713         case kMenu_DisableWatch:
8714            entry->numElements = 0;
8715            break;
8716
8717         case kMenu_DisableAllWatch:
8718            for(i = 0; i < watchListLength; i++)
8719               watchList[i].numElements = 0;
8720            break;
8721
8722         case kMenu_ResetWatch:
8723            ResetWatch(entry);
8724            break;
8725
8726         case kMenu_ResetAllWatch:
8727            for(i = 0; i < watchListLength; i++)
8728               ResetWatch(&watchList[i]);
8729            break;
8730
8731         case kMenu_AddAsCheatCode:
8732            AddCheatFromWatch(entry);
8733            break;
8734
8735         case kMenu_AddAsWatchCode:
70048736         {
7005            watchList[i].address = 0;
7006            watchList[i].cpu = 0;
7007            watchList[i].numElements = 0;
7008            watchList[i].elementBytes = kWatchSizeConversionTable[0];
7009            watchList[i].labelType = kWatchLabel_None;
7010            watchList[i].displayType = kWatchDisplayType_Hex;
7011            watchList[i].skip = 0;
7012            watchList[i].elementsPerLine = 0;
7013            watchList[i].addValue = 0;
8737            CheatEntry * newEntry = GetNewCheat();
70148738
7015            watchList[i].linkedCheat = NULL;
8739            DisposeCheat(newEntry);
8740            SetupCheatFromWatchAsWatch(newEntry, entry);
70168741
7017            watchList[i].label[0] = 0;
8742            /* when fails to add, delete this entry because it causes the crash */
8743            if(messageType == kCheatMessage_FailedToAdd)
8744            {
8745               DeleteCheatAt(cheatListLength - 1);
8746               messageType      = kCheatMessage_FailedToAdd;
8747               messageTimer   = DEFAULT_MESSAGE_TIME;
8748            }
70188749         }
7019      }
7020   }
8750         break;
70218751
7022   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate))
7023      /* ----- quick menu switch : watchpoint list -> enable/disable ----- */
7024      sel = -2;
8752         case kMenu_SaveAsCheatCode:
8753            // underconstruction...
8754            break;
70258755
7026   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate))
7027      /* ----- quick menu switch : watchpoint list -> search ----- */
7028      sel = -4;
8756         case kMenu_SaveAsWatchCode:
8757         {
8758            CheatEntry tempEntry;
70298759
7030   if(input_ui_pressed(machine, IPT_UI_CANCEL))
7031      sel = -1;
8760            memset(&tempEntry, 0, sizeof(CheatEntry));
70328761
7033   return sel + 1;
8762            SetupCheatFromWatchAsWatch(&tempEntry, entry);
8763            SaveCheatCode(machine, &tempEntry);
8764            DisposeCheat(&tempEntry);
8765         }
8766         break;
8767
8768         case kMenu_Return:
8769            menu->sel = -1;
8770      }
8771   }
8772   else if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT))
8773   {
8774      ReloadCheatDatabase(machine);
8775   }
8776   else if(input_ui_pressed(machine, IPT_UI_CANCEL) || input_ui_pressed(machine, IPT_UI_LEFT) || input_ui_pressed(machine, IPT_UI_RIGHT))
8777   {
8778      menu->sel = -1;
8779   }
8780
8781   return menu->sel + 1;
70348782}
70358783
7036/*--------------------------------------------------
7037  EditWatch - management for watchpoint edit menu
7038--------------------------------------------------*/
8784/*--------------------------------------------------------
8785  edit_watch_menu - management for watchpoint edit menu
8786--------------------------------------------------------*/
70398787
7040static int EditWatch(running_machine *machine, WatchInfo * entry, int selection)
8788static int edit_watch_menu(running_machine *machine, cheat_menu_stack *menu)
70418789{
7042   enum
7043   {
8790   enum{
70448791      kMenu_Address = 0,
70458792      kMenu_CPU,
70468793      kMenu_NumElements,
r2762r2763
70578804      kMenu_DataShift,
70588805      kMenu_XOR,
70598806
7060      kMenu_Return
7061   };
8807      kMenu_Return,
8808      kMenu_Max };
70628809
7063   static const char *const kWatchSizeStringList[] =
7064   {
7065      "8 Bit",
7066      "16 Bit",
7067      "24 Bit",
7068      "32 Bit"
7069   };
7070
8810   UINT8         total      = 0;
8811   UINT32         increment   = 1;
70718812   const char      ** menuItem;
70728813   const char      ** menuSubItem;
70738814   char         ** buf;
70748815   char         * flagBuf;
8816   WatchInfo      * entry      = &watchList[menu->pre_sel];
8817   cpu_region_info *info = get_cpu_or_region_info(entry->cpu);
70758818
7076   INT32         sel;
7077   INT32         total = 0;
7078   UINT32         increment = 1;
7079   static UINT8   editActive = 0;
8819   /* first setting : NONE */
8820   if(menu->first_time)
8821      menu->first_time = 0;
70808822
7081   /* ----- if no watch entry, direct return ----- */
7082   if(!entry)
7083      return 0;
8823   request_strings(kMenu_Max + 1, kMenu_Return, 0, 20);
8824   menuItem      = menu_strings.main_list;
8825   menuSubItem      = menu_strings.sub_list;
8826   buf            = menu_strings.sub_strings;
8827   flagBuf         = menu_strings.flag_list;
70848828
7085   RequestStrings(kMenu_Return + 2, kMenu_Return, 0, 20);
8829   memset(flagBuf, 0, kMenu_Max + 1);
70868830
7087   menuItem = menuStrings.mainList;
7088   menuSubItem = menuStrings.subList;
7089   buf = menuStrings.subStrings;
7090   flagBuf = menuStrings.flagList;
7091
7092   memset(flagBuf, 0, kMenu_Return + 2);
7093
7094   sel = selection - 1;
7095
70968831   /********** MENU CONSTRUCTION **********/
7097   sprintf(buf[total], "%.*X", cpuInfoList[entry->cpu].addressCharsNeeded, entry->address >> entry->addressShift);
8832   /* ##### ADDRESS ##### */
8833   sprintf(buf[total], "%.*X", info->address_chars_needed, entry->address >> entry->addressShift);
70988834   menuItem[total] = "Address";
70998835   menuSubItem[total] = buf[total];
71008836   total++;
71018837
7102   sprintf(buf[total], "%d", entry->cpu);
7103   menuItem[total] = "CPU";
8838   /* ##### CPU/REGION ##### */
8839   sprintf(buf[total], "%s", get_region_name(entry->cpu));
8840   menuItem[total] = TEST_FIELD(entry->cpu, RegionFlag) ? "Region" : "CPU";
71048841   menuSubItem[total] = buf[total];
71058842   total++;
71068843
8844   /* ##### LENGTH ##### */
71078845   sprintf(buf[total], "%d", entry->numElements);
71088846   menuItem[total] = "Length";
71098847   menuSubItem[total] = buf[total];
71108848   total++;
71118849
8850   /* ##### ELEMENT SIZE ##### */
71128851   menuItem[total] = "Element Size";
7113   menuSubItem[total++] = kWatchSizeStringList[entry->elementBytes];
8852   menuSubItem[total++] = kByteSizeStringList[entry->elementBytes];
71148853
8854   /* ##### LABEL TYPE ##### */
71158855   menuItem[total] = "Label Type";
71168856   menuSubItem[total++] = kWatchLabelStringList[entry->labelType];
71178857
8858   /* ##### TEXT LABEL ##### */
71188859   menuItem[total] = "Text Label";
71198860   if(entry->label[0])
71208861      menuSubItem[total++] = entry->label;
71218862   else
71228863      menuSubItem[total++] = "(none)";
71238864
8865   /* ##### DISPLAY TYPE ##### */
71248866   menuItem[total] = "Display Type";
71258867   menuSubItem[total++] = kWatchDisplayTypeStringList[entry->displayType];
71268868
8869   /* ##### X POSITION ##### */
71278870   sprintf(buf[total], "%f", entry->x);
71288871   menuItem[total] = "X";
71298872   menuSubItem[total] = buf[total];
71308873   total++;
71318874
8875   /* ##### Y POSITION ##### */
71328876   sprintf(buf[total], "%f", entry->y);
71338877   menuItem[total] = "Y";
71348878   menuSubItem[total] = buf[total];
71358879   total++;
71368880
8881   /* ##### SKIP BYTES ##### */
71378882   sprintf(buf[total], "%d", entry->skip);
71388883   menuItem[total] = "Skip Bytes";
71398884   menuSubItem[total] = buf[total];
71408885   total++;
71418886
8887   /* ##### ELEMENTS PER LINE ##### */
71428888   sprintf(buf[total], "%d", entry->elementsPerLine);
71438889   menuItem[total] = "Elements Per Line";
71448890   menuSubItem[total] = buf[total];
71458891   total++;
71468892
8893   /* ##### ADD VALUE ##### */
8894   menuItem[total] = "Add Value";
71478895   if(entry->addValue < 0)
71488896      sprintf(buf[total], "-%.2X", -entry->addValue);
71498897   else
71508898      sprintf(buf[total], "%.2X", entry->addValue);
7151
7152   menuItem[total] = "Add Value";
71538899   menuSubItem[total] = buf[total];
71548900   total++;
71558901
8902   /* ##### ADDRESS SHIFT ##### */
71568903   sprintf(buf[total], "%d", entry->addressShift);
71578904   menuItem[total] = "Address Shift";
71588905   menuSubItem[total] = buf[total];
71598906   total++;
71608907
8908   /* ##### DATA SHIFT ##### */
71618909   sprintf(buf[total], "%d", entry->dataShift);
71628910   menuItem[total] = "Data Shift";
71638911   menuSubItem[total] = buf[total];
71648912   total++;
71658913
8914   /* ##### XOR ##### */
71668915   sprintf(buf[total], "%.*X", kSearchByteDigitsTable[kWatchSizeConversionTable[entry->elementBytes]], entry->xor);
71678916   menuItem[total] = "XOR";
71688917   menuSubItem[total] = buf[total];
71698918   total++;
71708919
7171   menuItem[total] = "Return to Prior Menu";      // return
8920   /* ##### RETURN ##### */
8921   menuItem[total] = "Return to Prior Menu";
71728922   menuSubItem[total++] = NULL;
71738923
7174   menuItem[total] = NULL;                           // terminate array
8924   /* ##### TERMINATE ARRAY ##### */
8925   menuItem[total] = NULL;
71758926   menuSubItem[total] = NULL;
71768927
7177   /* ----- adjust current cursor position ----- */
7178   if(sel < 0)
7179      sel = 0;
7180   if(sel >= total)
7181      sel = total - 1;
8928   /* adjust current cursor position */
8929   ADJUST_CURSOR(menu->sel, total)
71828930
7183   /* ----- higlighted sub-item if edit mode ----- */
8931   /* higlighted sub-item if edit mode */
71848932   if(editActive)
7185      flagBuf[sel] = 1;
8933      flagBuf[menu->sel] = 1;
71868934
7187   /* ----- draw it ----- */
7188   old_style_menu(menuItem, menuSubItem, flagBuf, sel, 0);
8935   /* draw it */
8936   old_style_menu(menuItem, menuSubItem, flagBuf, menu->sel, 0);
71898937
71908938   /********** KEY HANDLING **********/
7191   if(AltKeyPressed())
7192      increment <<= 4;
7193   if(ControlKeyPressed())
7194      increment <<= 8;
7195   if(ShiftKeyPressed())
7196      increment <<= 16;
7197
7198   if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
8939   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
71998940   {
7200      editActive = 0;
7201
7202      switch(sel)
8941      CURSOR_TO_PREVIOUS(menu->sel, total)
8942   }
8943   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
8944   {
8945      CURSOR_TO_NEXT(menu->sel, total)
8946   }
8947   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
8948   {
8949      CURSOR_PAGE_UP(menu->sel)
8950   }
8951   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
8952   {
8953      CURSOR_PAGE_DOWN(menu->sel, total)
8954   }
8955   else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
8956   {
8957      if(editActive)
72038958      {
7204         case kMenu_Address:
7205            entry->address = DoShift(entry->address, entry->addressShift);
7206            entry->address -= increment;
7207            entry->address = DoShift(entry->address, -entry->addressShift);
8959         // underconstruction...
8960      }
8961      else
8962      {
8963         switch(menu->sel)
8964         {
8965            case kMenu_Address:
8966               entry->address = DoShift(entry->address, entry->addressShift);
8967               entry->address -= increment;
8968               entry->address = DoShift(entry->address, -entry->addressShift);
72088969
7209            if(entry->locationType != kLocation_MemoryRegion)
7210               entry->address &= cpuInfoList[entry->cpu].addressMask;
8970               if(!TEST_FIELD(entry->cpu, RegionFlag))
8971                  entry->address &= info->address_mask;
8972               break;
72118973
7212            break;
8974            case kMenu_CPU:
8975               entry->cpu--;
72138976
7214         case kMenu_CPU:
7215            entry->cpu--;
8977               if(entry->cpu >= cpu_gettotalcpu())
8978                  entry->cpu = cpu_gettotalcpu() - 1;
72168979
7217            if(entry->cpu >= cpu_gettotalcpu())
7218               entry->cpu = cpu_gettotalcpu() - 1;
8980               entry->address &= info->address_mask;
8981               break;
72198982
7220            entry->address &= cpuInfoList[entry->cpu].addressMask;
7221            break;
8983            case kMenu_NumElements:
8984               if(entry->numElements > 0)
8985                  entry->numElements--;
8986               else
8987                  entry->numElements = 0;
8988               break;
72228989
7223         case kMenu_NumElements:
7224            if(entry->numElements > 0)
7225               entry->numElements--;
7226            else
7227               entry->numElements = 0;
7228            break;
8990            case kMenu_ElementSize:
8991               if(entry->elementBytes > 0)
8992                  entry->elementBytes--;
8993               else
8994                  entry->elementBytes = 0;
72298995
7230         case kMenu_ElementSize:
7231            if(entry->elementBytes > 0)
7232               entry->elementBytes--;
7233            else
7234               entry->elementBytes = 0;
8996               entry->xor &= kSearchByteMaskTable[kWatchSizeConversionTable[entry->elementBytes]];
8997               break;
72358998
7236            entry->xor &= kSearchByteMaskTable[kWatchSizeConversionTable[entry->elementBytes]];
7237            break;
8999            case kMenu_LabelType:
9000               if(entry->labelType > 0)
9001                  entry->labelType--;
9002               else
9003                  entry->labelType = 0;
9004               break;
72389005
7239         case kMenu_LabelType:
7240            if(entry->labelType > 0)
7241               entry->labelType--;
7242            else
7243               entry->labelType = 0;
7244            break;
9006            case kMenu_TextLabel:
9007               break;
72459008
7246         case kMenu_TextLabel:
7247            break;
9009            case kMenu_DisplayType:
9010               if(entry->displayType > 0)
9011                  entry->displayType--;
9012               else
9013                  entry->displayType = 0;
9014               break;
72489015
7249         case kMenu_DisplayType:
7250            if(entry->displayType > 0)
7251               entry->displayType--;
7252            else
7253               entry->displayType = 0;
7254            break;
9016            case kMenu_XPosition:
9017               entry->x -= 0.01f;
9018               break;
72559019
7256         case kMenu_XPosition:
7257            entry->x -= 0.01f;
7258            break;
9020            case kMenu_YPosition:
9021               entry->y -= 0.01f;
9022               break;
72599023
7260         case kMenu_YPosition:
7261            entry->y -= 0.01f;
7262            break;
9024            case kMenu_Skip:
9025               if(entry->skip > 0)
9026                  entry->skip--;
9027               break;
72639028
7264         case kMenu_Skip:
7265            if(entry->skip > 0)
7266               entry->skip--;
7267            break;
9029            case kMenu_ElementsPerLine:
9030               if(entry->elementsPerLine > 0)
9031                  entry->elementsPerLine--;
9032               break;
72689033
7269         case kMenu_ElementsPerLine:
7270            if(entry->elementsPerLine > 0)
7271               entry->elementsPerLine--;
7272            break;
9034            case kMenu_AddValue:
9035               entry->addValue = (entry->addValue - 1) & 0xFF;
9036               break;
72739037
7274         case kMenu_AddValue:
7275            entry->addValue = (entry->addValue - 1) & 0xFF;
7276            break;
9038            case kMenu_AddressShift:
9039               if(entry->addressShift > -31)
9040                  entry->addressShift--;
9041               else
9042                  entry->addressShift = 31;
9043               break;
72779044
7278         case kMenu_AddressShift:
7279            if(entry->addressShift > -31)
7280               entry->addressShift--;
7281            else
7282               entry->addressShift = 31;
7283            break;
9045            case kMenu_DataShift:
9046               if(entry->dataShift > -31)
9047                  entry->dataShift--;
9048               else
9049                  entry->dataShift = 31;
9050               break;
72849051
7285         case kMenu_DataShift:
7286            if(entry->dataShift > -31)
7287               entry->dataShift--;
7288            else
7289               entry->dataShift = 31;
7290            break;
7291
7292         case kMenu_XOR:
7293            entry->xor -= increment;
7294            entry->xor &= kSearchByteMaskTable[kWatchSizeConversionTable[entry->elementBytes]];
7295            break;
9052            case kMenu_XOR:
9053               entry->xor -= increment;
9054               entry->xor &= kSearchByteMaskTable[kWatchSizeConversionTable[entry->elementBytes]];
9055         }
72969056      }
72979057   }
7298
7299   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
9058   else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
73009059   {
7301      editActive = 0;
7302
7303      switch(sel)
9060      if(editActive)
73049061      {
7305         case kMenu_Address:
7306            entry->address = DoShift(entry->address, entry->addressShift);
7307            entry->address += increment;
7308            entry->address = DoShift(entry->address, -entry->addressShift);
7309            entry->address &= cpuInfoList[entry->cpu].addressMask;
7310            break;
9062         // underconstruction...
9063      }
9064      else
9065      {
9066         switch(menu->sel)
9067         {
9068            case kMenu_Address:
9069               entry->address = DoShift(entry->address, entry->addressShift);
9070               entry->address += increment;
9071               entry->address = DoShift(entry->address, -entry->addressShift);
73119072
7312         case kMenu_CPU:
7313            entry->cpu++;
9073               if(!TEST_FIELD(entry->cpu, RegionFlag))
9074                  entry->address &= info->address_mask;
9075               break;
73149076
7315            if(entry->cpu >= cpu_gettotalcpu())
7316               entry->cpu = 0;
9077            case kMenu_CPU:
9078               entry->cpu++;
73179079
7318            entry->address &= cpuInfoList[entry->cpu].addressMask;
7319            break;
9080               if(entry->cpu >= cpu_gettotalcpu())
9081                  entry->cpu = 0;
73209082
7321         case kMenu_NumElements:
7322            entry->numElements++;
7323            break;
9083               entry->address &= info->address_mask;
9084               break;
73249085
7325         case kMenu_ElementSize:
7326            if(entry->elementBytes < kSearchSize_32Bit)
7327               entry->elementBytes++;
7328            else
7329               entry->elementBytes = kSearchSize_32Bit;
9086            case kMenu_NumElements:
9087               entry->numElements++;
9088               break;
73309089
7331            entry->xor &= kSearchByteMaskTable[kWatchSizeConversionTable[entry->elementBytes]];
7332            break;
9090            case kMenu_ElementSize:
9091               if(entry->elementBytes < kSearchSize_32Bit)
9092                  entry->elementBytes++;
9093               else
9094                  entry->elementBytes = kSearchSize_32Bit;
73339095
7334         case kMenu_LabelType:
7335            if(entry->labelType < kWatchLabel_MaxPlusOne - 1)
7336               entry->labelType++;
7337            else
7338               entry->labelType = kWatchLabel_MaxPlusOne - 1;
7339            break;
9096               entry->xor &= kSearchByteMaskTable[kWatchSizeConversionTable[entry->elementBytes]];
9097               break;
73409098
7341         case kMenu_TextLabel:
7342            break;
9099            case kMenu_LabelType:
9100               if(entry->labelType < kWatchLabel_MaxPlusOne - 1)
9101                  entry->labelType++;
9102               else
9103                  entry->labelType = kWatchLabel_MaxPlusOne - 1;
9104               break;
73439105
7344         case kMenu_DisplayType:
7345            if(entry->displayType < kWatchDisplayType_MaxPlusOne - 1)
7346               entry->displayType++;
7347            else
7348               entry->displayType = kWatchDisplayType_MaxPlusOne - 1;
7349            break;
9106            case kMenu_TextLabel:
9107               break;
73509108
7351         case kMenu_XPosition:
7352            entry->x += 0.01f;
7353            break;
9109            case kMenu_DisplayType:
9110               if(entry->displayType < kWatchDisplayType_MaxPlusOne - 1)
9111                  entry->displayType++;
9112               else
9113                  entry->displayType = kWatchDisplayType_MaxPlusOne - 1;
9114               break;
73549115
7355         case kMenu_YPosition:
7356            entry->y += 0.01f;
7357            break;
9116            case kMenu_XPosition:
9117               entry->x += 0.01f;
9118               break;
73589119
7359         case kMenu_Skip:
7360            entry->skip++;
7361            break;
9120            case kMenu_YPosition:
9121               entry->y += 0.01f;
9122               break;
73629123
7363         case kMenu_ElementsPerLine:
7364            entry->elementsPerLine++;
7365            break;
9124            case kMenu_Skip:
9125               entry->skip++;
9126               break;
73669127
7367         case kMenu_AddValue:
7368            entry->addValue = (entry->addValue + 1) & 0xFF;
7369            break;
9128            case kMenu_ElementsPerLine:
9129               entry->elementsPerLine++;
9130               break;
73709131
7371         case kMenu_AddressShift:
7372            if(entry->addressShift < 31)
7373               entry->addressShift++;
7374            else
7375               entry->addressShift = -31;
7376            break;
9132            case kMenu_AddValue:
9133               entry->addValue = (entry->addValue + 1) & 0xFF;
9134               break;
73779135
7378         case kMenu_DataShift:
7379            if(entry->dataShift < 31)
7380               entry->dataShift++;
7381            else
7382               entry->dataShift = -31;
7383            break;
9136            case kMenu_AddressShift:
9137               if(entry->addressShift < 31)
9138                  entry->addressShift++;
9139               else
9140                  entry->addressShift = -31;
9141               break;
73849142
7385         case kMenu_XOR:
7386            entry->xor += increment;
7387            entry->xor &= kSearchByteMaskTable[kWatchSizeConversionTable[entry->elementBytes]];
7388            break;
9143            case kMenu_DataShift:
9144               if(entry->dataShift < 31)
9145                  entry->dataShift++;
9146               else
9147                  entry->dataShift = -31;
9148               break;
9149
9150            case kMenu_XOR:
9151               entry->xor += increment;
9152               entry->xor &= kSearchByteMaskTable[kWatchSizeConversionTable[entry->elementBytes]];
9153         }
73899154      }
73909155   }
7391
7392   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
9156   else if(input_ui_pressed(machine, IPT_UI_SELECT))
73939157   {
7394      sel++;
7395
7396      if(sel >= total)
7397         sel = 0;
7398
7399      editActive = 0;
7400   }
7401
7402   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
7403   {
7404      sel--;
7405
7406      if(sel < 0)
7407         sel = total - 1;
7408
7409      editActive = 0;
7410   }
7411
7412   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
7413   {
7414      sel -= fullMenuPageHeight;
7415
7416      if(sel < 0)
7417         sel = 0;
7418
7419      editActive = 0;
7420   }
7421
7422   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
7423   {
7424      sel += fullMenuPageHeight;
7425
7426      if(sel >= total)
7427         sel = total - 1;
7428
7429      editActive = 0;
7430   }
7431
7432   if(input_ui_pressed(machine, IPT_UI_SELECT))
7433   {
74349158      if(editActive)
74359159         editActive = 0;
74369160      else
74379161      {
7438         switch(sel)
9162         switch(menu->sel)
74399163         {
7440            case kMenu_Return:
7441               sel = -1;
7442               break;
7443
74449164            case kMenu_Address:
74459165            case kMenu_CPU:
74469166            case kMenu_NumElements:
r2762r2763
74539173            case kMenu_XOR:
74549174               osd_readkey_unicode(1);
74559175               editActive = 1;
9176               break;
9177
9178            case kMenu_Return:
9179               menu->sel = -1;
74569180         }
74579181      }
74589182   }
9183   else if(input_ui_pressed(machine, IPT_UI_CLEAR))
9184   {
9185      ResetWatch(entry);
9186   }
9187   else if(input_ui_pressed(machine, IPT_UI_CANCEL))
9188   {
9189      if(editActive)
9190         editActive = 0;
9191      else
9192         menu->sel = -1;
9193   }
74599194
74609195   if(editActive)
74619196   {
7462      switch(sel)
9197      switch(menu->sel)
74639198      {
74649199         case kMenu_Address:
74659200            entry->address = DoShift(entry->address, entry->addressShift);
7466            entry->address = DoEditHexField(machine, entry->address);
9201            entry->address = do_edit_hex_field(machine, entry->address);
74679202            entry->address = DoShift(entry->address, -entry->addressShift);
7468            entry->address &= cpuInfoList[entry->cpu].addressMask;
9203            entry->address &= info->address_mask;
74699204            break;
74709205
74719206         case kMenu_CPU:
74729207            entry->cpu = DoEditDecField(entry->cpu, 0, cpu_gettotalcpu() - 1);
7473            entry->address &= cpuInfoList[entry->cpu].addressMask;
9208            entry->address &= info->address_mask;
74749209            break;
74759210
74769211         case kMenu_NumElements:
r2762r2763
75029237            break;
75039238
75049239         case kMenu_XOR:
7505            entry->xor = DoEditHexField(machine, entry->xor);
9240            entry->xor = do_edit_hex_field(machine, entry->xor);
75069241            entry->xor &= kSearchByteMaskTable[kWatchSizeConversionTable[entry->elementBytes]];
75079242            break;
75089243      }
7509
7510      if(input_ui_pressed(machine, IPT_UI_CANCEL))
7511         editActive = 0;
75129244   }
75139245   else
75149246   {
r2762r2763
75209252
75219253      if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))
75229254      {
7523         CheatEntry   tempEntry;
9255         CheatEntry tempEntry;
75249256
75259257         memset(&tempEntry, 0, sizeof(CheatEntry));
75269258
75279259         SetupCheatFromWatchAsWatch(&tempEntry, entry);
7528         SaveCheat(machine, &tempEntry, 0, 0);
9260         SaveCheatCode(machine, &tempEntry);
75299261         DisposeCheat(&tempEntry);
75309262      }
75319263   }
75329264
7533   if(input_ui_pressed(machine, IPT_UI_CANCEL))
7534      sel = -1;
7535
7536   return sel + 1;
9265   return menu->sel + 1;
75379266}
75389267
7539/*----------------------------------------------
7540  SelectOptions - management for options menu
7541----------------------------------------------*/
9268/*---------------------------------------------------
9269  select_option_menu - management for options menu
9270---------------------------------------------------*/
75429271
7543static int SelectOptions(running_machine *machine, int selection)
9272static int select_option_menu(running_machine *machine, cheat_menu_stack *menu)
75449273{
7545   enum
7546   {
9274   enum{
75479275      kMenu_SelectSearch = 0,
9276      kMenu_LoadCheatOptions,
9277      kMenu_SaveCheatOptions,
9278      kMenu_ResetCheatOptions,
9279      kMenu_Separator,
75489280      kMenu_SearchDialogStyle,
75499281      kMenu_ShowSearchLabels,
75509282      kMenu_AutoSaveCheats,
75519283      kMenu_ShowActivationKeyMessage,
75529284      kMenu_LoadOldFormat,
7553      kMenu_Debug,
9285#ifdef MESS
9286      kMenu_SharedCode,
9287#endif
75549288      kMenu_Return,
75559289
7556      kMenu_Max
7557   };
9290      kMenu_Max };
75589291
7559   INT32         sel;
7560   static INT32   submenuChoice = 0;
7561   const char      * menuItem[kMenu_Max + 1];
7562   const char      * menuSubItem[kMenu_Max + 1];
7563   int            total = 0;
9292   UINT8         total      = 0;
9293   const char      * menu_item[kMenu_Max + 1];
9294   const char      * menu_sub_item[kMenu_Max + 1];
75649295
7565   sel = selection - 1;
9296   /* first setting : NONE */
9297   if(menu->first_time)
9298      menu->first_time = 0;
75669299
7567   /********** SUB MENU **********/
7568   if(submenuChoice)
7569   {
7570      switch(sel)
7571      {
7572         case kMenu_SelectSearch:
7573            submenuChoice = SelectSearch(machine, submenuChoice);
7574            break;
9300   /********** MENU CONSTRUCTION **********/
9301   /* ##### SEARCH REGION ##### */
9302   ADD_MENU_2_ITEMS("Select Search", NULL);
75759303
7576         default:
7577            submenuChoice = 0;
7578            sel = -1;
7579            break;
7580      }
9304   /* ##### LOAD CHEAT OPTIONS ##### */
9305   ADD_MENU_2_ITEMS("Load Cheat Options", NULL);
75819306
7582      if(submenuChoice == -1)
7583         submenuChoice = 0;
9307   /* ##### SAVE CHEAT OPTIONS ##### */
9308   ADD_MENU_2_ITEMS("Save Cheat Options", NULL);
75849309
7585      return sel + 1;
7586   }
9310   /* ##### RESET CHEAT OPTIONS ##### */
9311   ADD_MENU_2_ITEMS("Reset Cheat Options", NULL);
75879312
7588   /********** MENU CONSTRUCTION **********/
7589   menuItem[total] =      "Select Search";
7590   menuSubItem[total++] =   NULL;
9313   /* ##### SEPARATOR ##### */
9314   ADD_MENU_2_ITEMS(MENU_SEPARATOR_ITEM, NULL);
75919315
7592   menuItem[total] =      "Search Dialog Style";
9316   /* ##### SEARCH MENU ##### */
9317   menu_item[total] = "Search Dialog Style";
75939318   switch(EXTRACT_FIELD(cheatOptions, SearchBox))
75949319   {
75959320      case kSearchBox_Minimum:
7596         menuSubItem[total++] = "Minimum";
9321         menu_sub_item[total++] = "Minimum";
75979322         break;
75989323
7599      case kSearchBox_Classic:
7600         menuSubItem[total++] = "Classic";
9324      case kSearchBox_Standard:
9325         menu_sub_item[total++] = "Standard";
76019326         break;
76029327
76039328      case kSearchBox_Advanced:
7604         menuSubItem[total++] = "Advanced";
9329         menu_sub_item[total++] = "Advanced";
76059330         break;
9331
9332      default:
9333         menu_sub_item[total++] = "<< No Search Box >>";
9334         break;
76069335   }
76079336
7608   menuItem[total] =      "Show Search Labels";
7609   menuSubItem[total++] =   TEST_FIELD(cheatOptions, DontPrintNewLabels) ? "Off" : "On";
9337   /* ##### SEARCH LABEL ##### */
9338   ADD_MENU_2_ITEMS("Show Search Labels", TEST_FIELD(cheatOptions, DontPrintNewLabels) ? "Off" : "On");
76109339
7611   menuItem[total] =      "Auto Save Cheats";
7612   menuSubItem[total++] =   TEST_FIELD(cheatOptions, AutoSaveEnabled) ? "On" : "Off";
9340   /* ##### AUTO SAVE ##### */
9341   ADD_MENU_2_ITEMS("Auto Save Cheats", TEST_FIELD(cheatOptions, AutoSaveEnabled) ? "On" : "Off");
76139342
7614   menuItem[total] =      "Show Activation Key Message";
7615   menuSubItem[total++] =   TEST_FIELD(cheatOptions, ActivationKeyMessage) ? "On" : "Off";
9343   /* ##### ACTIVATION KEY MESSAGE ##### */
9344   ADD_MENU_2_ITEMS("Show Activation Key Message", TEST_FIELD(cheatOptions, ActivationKeyMessage) ? "On" : "Off");
76169345
7617   menuItem[total] =      "Load Old Format Code";
7618   menuSubItem[total++] =   TEST_FIELD(cheatOptions, LoadOldFormat) ? "On" : "Off";
9346   /* ##### OLD FORMAT LOADING ##### */
9347   ADD_MENU_2_ITEMS("Load Old Format Code", TEST_FIELD(cheatOptions, LoadOldFormat) ? "On" : "Off");
76199348
7620   menuItem[total] =      "Debug";
7621   menuSubItem[total++] =   TEST_FIELD(cheatOptions, Debug) ? "On" : "Off";
9349#ifdef MESS
9350   /* ##### SHARED CODE ##### */
9351   ADD_MENU_2_ITEMS("Shared Code", TEST_FIELD(cheatOptions, SharedCode) ? "On" : "Off");
9352#endif
76229353
7623   menuItem[total] =      "Return to Prior Menu";      // return
7624   menuSubItem[total++] =   NULL;
9354   /* ##### RETURN ##### */
9355   ADD_MENU_2_ITEMS("Return to Prior Menu", NULL);
76259356
7626   menuItem[total] =      NULL;                        // terminate array
7627   menuSubItem[total] =   NULL;
9357   /* ##### TERMINATE ALLAY ##### */
9358   TERMINATE_MENU_2_ITEMS;
76289359
7629   /* ----- draw it ----- */
7630   old_style_menu(menuItem, menuSubItem, NULL, sel, 0);
9360   /* draw it */
9361   old_style_menu(menu_item, menu_sub_item, NULL, menu->sel, 0);
76319362
76329363   /********** KEY HANDLING **********/
7633   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
9364   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
76349365   {
7635      switch(sel)
9366      CURSOR_TO_PREVIOUS(menu->sel, total)
9367
9368      if(menu->sel == kMenu_Separator)
9369         menu->sel--;
9370   }
9371   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
9372   {
9373      CURSOR_TO_NEXT(menu->sel, total)
9374
9375      if(menu->sel == kMenu_Separator)
9376         menu->sel++;
9377   }
9378   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
9379   {
9380      CURSOR_PAGE_UP(menu->sel)
9381   }
9382   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
9383   {
9384      CURSOR_PAGE_DOWN(menu->sel, total)
9385   }
9386   else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
9387   {
9388      switch(menu->sel)
76369389      {
76379390         case kMenu_SearchDialogStyle:
7638            {
7639               UINT8   length = (EXTRACT_FIELD(cheatOptions, SearchBox) + 1) & 3;
9391         {
9392            UINT8 length = (EXTRACT_FIELD(cheatOptions, SearchBox) - 1) & 3;
76409393
7641               if(length > kSearchBox_Advanced)
7642                  length = kSearchBox_Minimum;
9394            if(length > kSearchBox_Advanced)
9395               length = kSearchBox_Advanced;
76439396
7644               SET_FIELD(cheatOptions, SearchBox, length);
7645            }
7646            break;
9397            SET_FIELD(cheatOptions, SearchBox, length);
9398         }
9399         break;
76479400
76489401         case kMenu_ShowSearchLabels:
76499402            TOGGLE_MASK_FIELD(cheatOptions, DontPrintNewLabels);
r2762r2763
76609413         case kMenu_LoadOldFormat:
76619414            TOGGLE_MASK_FIELD(cheatOptions, LoadOldFormat);
76629415            break;
7663
7664         case kMenu_Debug:
7665            TOGGLE_MASK_FIELD(cheatOptions, Debug);
7666            break;
9416#ifdef MESS
9417         case kMenu_SharedCode:
9418            TOGGLE_MASK_FIELD(cheatOptions, SharedCode);
9419#endif
76679420      }
76689421   }
7669
7670    if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
9422   else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
76719423   {
7672      switch(sel)
9424      switch(menu->sel)
76739425      {
76749426         case kMenu_SearchDialogStyle:
7675            {
7676               UINT8   length = (EXTRACT_FIELD(cheatOptions, SearchBox) - 1) & 3;
9427         {
9428            UINT8 length = (EXTRACT_FIELD(cheatOptions, SearchBox) + 1) & 3;
76779429
7678               if(length > kSearchBox_Advanced)
7679                  length = kSearchBox_Advanced;
9430            if(length > kSearchBox_Advanced)
9431               length = kSearchBox_Minimum;
76809432
7681               SET_FIELD(cheatOptions, SearchBox, length);
7682            }
7683            break;
9433            SET_FIELD(cheatOptions, SearchBox, length);
9434         }
9435         break;
76849436
76859437         case kMenu_ShowSearchLabels:
76869438            TOGGLE_MASK_FIELD(cheatOptions, DontPrintNewLabels);
r2762r2763
76969448
76979449         case kMenu_LoadOldFormat:
76989450            TOGGLE_MASK_FIELD(cheatOptions, LoadOldFormat);
7699            break;
77009451
7701         case kMenu_Debug:
7702            TOGGLE_MASK_FIELD(cheatOptions, Debug);
7703            break;
9452#ifdef MESS
9453         case kMenu_SharedCode:
9454            TOGGLE_MASK_FIELD(cheatOptions, SharedCode);
9455#endif
77049456      }
77059457   }
7706
7707   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
9458   else if(input_ui_pressed(machine, IPT_UI_SELECT))
77089459   {
7709      if(sel < (kMenu_Max - 1))
7710         sel++;
7711      else
7712         sel = 0;
7713   }
9460      switch(menu->sel)
9461      {
9462         case kMenu_SelectSearch:
9463            cheat_menu_stack_push(select_search_menu, menu->handler, menu->sel);
9464            break;
77149465
7715   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
7716   {
7717      if(sel > 0)
7718         sel--;
7719      else
7720         sel = kMenu_Max - 1;
7721   }
9466         case kMenu_LoadCheatOptions:
9467            LoadCheatDatabase(machine, kLoadFlag_CheatOption);
9468            break;
77229469
7723   if(input_ui_pressed(machine, IPT_UI_SELECT))
7724   {
7725      switch(sel)
7726      {
7727         case kMenu_Return:
7728            submenuChoice = 0;
7729            sel = -1;
9470         case kMenu_SaveCheatOptions:
9471            SaveCheatOptions();
77309472            break;
77319473
7732         case kMenu_SelectSearch:
7733            submenuChoice = 1;
9474         case kMenu_ResetCheatOptions:
9475            cheatOptions = DEFAULT_CHEAT_OPTIONS;
77349476            break;
9477
9478         case kMenu_Return:
9479            menu->sel = -1;
77359480      }
77369481   }
7737
7738   if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))
9482   else if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))
77399483   {
7740      SaveCheat(machine, NULL, 0, 2);
7741
7742      ui_popup_time(1, "command code saved");
9484      SaveCheatOptions();
77439485   }
9486   else if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT))
9487   {
9488      LoadCheatDatabase(machine, kLoadFlag_CheatOption);
9489   }
9490   else if(input_ui_pressed(machine, IPT_UI_CANCEL))
9491   {
9492      menu->sel = -1;
9493   }
77449494
7745   if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT))
7746      ReloadCheatDatabase(machine);
7747
7748   if(input_ui_pressed(machine, IPT_UI_CANCEL))
7749      sel = -1;
7750
7751   return sel + 1;
9495   return menu->sel + 1;
77529496}
77539497
7754/*------------------------------------------------------
7755  SelectSearch - management for search selection menu
7756------------------------------------------------------*/
9498/*------------------------------------------------------------
9499  select_search_menu - management for search selection menu
9500------------------------------------------------------------*/
77579501
7758static int SelectSearch(running_machine *machine, int selection)
9502static int select_search_menu(running_machine *machine, cheat_menu_stack *menu)
77599503{
9504#if 0
77609505   INT32         sel;
77619506   const char      ** menuItem;
77629507   char         ** buf;
r2762r2763
77659510
77669511   sel = selection - 1;
77679512
7768   RequestStrings(searchListLength + 2, searchListLength, 300, 0);
9513   request_strings(search_list_length + 2, search_list_length, 300, 0);
77699514
7770   menuItem =   menuStrings.mainList;
7771   buf =      menuStrings.mainStrings;
9515   menuItem =   menu_strings.main_list;
9516   buf =      menu_strings.main_strings;
77729517
77739518   /********** MENU CONSTRUCTION **********/
7774   for(i = 0; i < searchListLength; i++)
9519   for(i = 0; i < search_list_length; i++)
77759520   {
7776      SearchInfo   * info = &searchList[i];
9521      search_info *info = &search_list[i];
77779522
7778      if(i == currentSearchIdx)
9523      if(i == current_search_idx)
77799524      {
77809525         if(info->name)
77819526            sprintf(buf[total], "[#%d: %s]", i, info->name);
r2762r2763
77989543
77999544   menuItem[total] = NULL;                           // terminate array
78009545
7801   /* ----- adjust current cursor position ----- */
9546   /* adjust current cursor position */
78029547   if(sel < 0)
78039548      sel = 0;
78049549   if(sel > (total - 1))
78059550      sel = total - 1;
78069551
7807   /* ----- draw it ----- */
9552   /* draw it */
78089553   old_style_menu(menuItem, NULL, NULL, sel, 0);
78099554
78109555   /********** KEY HANDLING **********/
7811   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
9556   if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
78129557   {
78139558      sel++;
78149559
r2762r2763
78169561         sel = 0;
78179562   }
78189563
7819   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
9564   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
78209565   {
78219566      sel--;
78229567
r2762r2763
78249569         sel = total - 1;
78259570   }
78269571
7827   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
9572   if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
78289573   {
78299574      sel -= fullMenuPageHeight;
78309575
r2762r2763
78329577         sel = 0;
78339578   }
78349579
7835   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
9580   if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
78369581   {
78379582      sel += fullMenuPageHeight;
78389583
r2762r2763
78509595
78519596   if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
78529597   {
7853      if(searchListLength > 1)
9598      if(search_list_length > 1)
78549599         DeleteSearchAt(sel);
78559600   }
78569601
78579602   if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT))
78589603   {
78599604      if(sel < total - 1)
7860         currentSearchIdx = sel;
9605         current_search_idx = sel;
78619606   }
78629607
78639608   if(input_ui_pressed(machine, IPT_UI_SELECT))
r2762r2763
78659610      if(sel >= total - 1)
78669611         sel = -1;
78679612      else
7868         currentSearchIdx = sel;
9613         current_search_idx = sel;
78699614   }
78709615
78719616   if(input_ui_pressed(machine, IPT_UI_CANCEL))
78729617      sel = -1;
9618#endif
9619   return menu->sel;
9620}
78739621
7874   return sel + 1;
9622#ifdef MAME_DEBUG
9623/*-----------------------------------------------------------------------
9624  check_activation_key_code_menu - key code checker for activation key
9625-----------------------------------------------------------------------*/
9626
9627static int check_activation_key_code_menu(running_machine *machine, cheat_menu_stack *menu)
9628{
9629   int            code      = input_code_poll_switches(FALSE);
9630   static int      index      = INPUT_CODE_INVALID;
9631   char         stringsBuf[64];
9632   char         * buf      = stringsBuf;
9633   astring         * keyIndex   = astring_alloc();
9634
9635   if(code != INPUT_CODE_INVALID)
9636   {
9637      /* NOTE : if first, no action to prevent from wrong display */
9638      if(menu->first_time)
9639         menu->first_time = 0;
9640      else
9641         index = code;
9642   }
9643
9644   /********** MENU CONSTRUCTION **********/
9645   /* ##### HEADER ##### */
9646   buf += sprintf(buf, "\tPress a key\n");
9647
9648   /* ##### KEY NAME / INDEX ##### */
9649   if(index != INPUT_CODE_INVALID && input_code_pressed(index))
9650      buf += sprintf(buf, "\t%s\n\t%X\n", astring_c(input_code_name(keyIndex, index)), index);
9651   else
9652      buf += sprintf(buf, "\n\n");
9653
9654   /* ##### RETURN ##### */
9655   buf += sprintf(buf, "\t Return = Shift + Cancel ");
9656
9657   /* print it */
9658   ui_draw_message_window(stringsBuf);
9659
9660   /* NOTE : shift + cancel is only key to return because normal cancel prevents from diplaying this key */
9661   if(ShiftKeyPressed() && input_ui_pressed(machine, IPT_UI_CANCEL))
9662   {
9663      index = INPUT_CODE_INVALID;
9664      menu->sel = -1;
9665   }
9666
9667   astring_free(keyIndex);
9668
9669   return menu->sel + 1;
78759670}
78769671
9672/*------------------------------------------------------------------------------------------------
9673  view_cpu_region_info_list_menu - view internal CPU or Region info list called from debug menu
9674------------------------------------------------------------------------------------------------*/
9675
9676static int view_cpu_region_info_list_menu(running_machine *machine, cheat_menu_stack *menu)
9677{
9678   enum{
9679      kMenu_Header = 0,
9680      kMenu_Type,
9681      kMenu_DataBits,
9682      kMenu_AddressBites,
9683      kMenu_AddressMask,
9684      kMenu_Endianness,
9685      kMenu_AddressShift,
9686      kMenu_Return,
9687      kMenu_Max };
9688
9689   UINT8      total   = 0;
9690   static INT8   index;
9691   const char   ** menuItem;
9692   const char   ** menuSubItem;
9693   char      * headerBuf;
9694   char      * regionNameBuf;
9695   char      * dataBitsBuf;
9696   char      * addressBitsBuf;
9697   char      * addressMaskBuf;
9698   char      * addressShiftBuf;
9699   cpu_region_info *info;
9700
9701   /* required items = total items + (strings buf * 6 [max chars : 32]) */
9702   request_strings(kMenu_Max, kMenu_Max - 2, 32, 0);
9703   menuItem       = menu_strings.main_list;
9704   menuSubItem      = menu_strings.sub_list;
9705   headerBuf      = menu_strings.main_strings[0];
9706   regionNameBuf   = menu_strings.main_strings[1];
9707   dataBitsBuf      = menu_strings.main_strings[2];
9708   addressBitsBuf   = menu_strings.main_strings[3];
9709   addressMaskBuf   = menu_strings.main_strings[4];
9710   addressShiftBuf   = menu_strings.main_strings[5];
9711
9712   /* first setting : set index as 1st */
9713   if(menu->first_time)
9714   {
9715      index = REGION_CPU1 - REGION_INVALID;
9716      menu->first_time = 0;
9717   }
9718
9719   info = get_region_info(index + REGION_INVALID);
9720
9721   /********** MENU CONSTRUCTION **********/
9722   /* ##### HEADER ##### */
9723   menuItem[total] = "Index";
9724   sprintf(headerBuf, "%2.2d", index);
9725   menuSubItem[total++] = headerBuf;
9726
9727   /* ##### CPU/REGION TYPE ##### */
9728   menuItem[total] = "Region";
9729
9730   if(index < REGION_CPU8 - REGION_INVALID)
9731      sprintf(regionNameBuf, "%s (%s)", kRegionNames[index], cputype_name(info->type));
9732   else
9733      sprintf(regionNameBuf, "%s (non-cpu)", kRegionNames[info->type - REGION_CPU1 + 1]);
9734   menuSubItem[total++] = regionNameBuf;
9735
9736   /* ##### DATA BITS ##### */
9737   menuItem[total] = "Data Bits";
9738   sprintf(dataBitsBuf, "%d", info->data_bits);
9739   menuSubItem[total++] = dataBitsBuf;
9740
9741   /* ##### ADDRESS BITS ##### */
9742   menuItem[total] = "Address Bits";
9743   sprintf(addressBitsBuf, "%d", info->address_bits);
9744   menuSubItem[total++] = addressBitsBuf;
9745
9746   /* ##### ADDRESS MASK/LENGTH ##### */
9747   menuItem[total] = "Address Mask";
9748   sprintf(addressMaskBuf, "%X (%d)", info->address_mask, info->address_chars_needed);
9749   menuSubItem[total++] = addressMaskBuf;
9750
9751   /* ##### ENDIANNESS ##### */
9752   menuItem[total] = "Endianness";
9753   menuSubItem[total++] = info->endianness ? "Big" : "Little";
9754
9755   /* ##### ADDRESS SHIFT ##### */
9756   menuItem[total] = "AddressShift";
9757   sprintf(addressShiftBuf, "%d", info->address_shift);
9758   menuSubItem[total++] = addressShiftBuf;
9759
9760   /* ##### RETURN ##### */
9761   menuItem[total] = "Return to Prior Menu";
9762   menuSubItem[total++] = NULL;
9763
9764   /* ##### TERMINATE ARRAY ##### */
9765   menuItem[total] = NULL;
9766   menuSubItem[total] = NULL;
9767
9768   /* draw it */
9769   old_style_menu(menuItem, menuSubItem, NULL, menu->sel, 0);
9770
9771   /* adjust current cursor position */
9772   ADJUST_CURSOR(menu->sel, total)
9773
9774   /********** KEY HANDLING **********/
9775   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
9776   {
9777      CURSOR_TO_PREVIOUS(menu->sel, total)
9778   }
9779   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
9780   {
9781      CURSOR_TO_NEXT(menu->sel, total)
9782   }
9783   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
9784   {
9785      CURSOR_PAGE_UP(menu->sel)
9786   }
9787   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
9788   {
9789      CURSOR_PAGE_DOWN(menu->sel, total)
9790   }
9791   else if(ui_pressed_repeat_throttle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
9792   {
9793      int i = index + 1;
9794
9795      /* search next valid info list */
9796      while(1)
9797      {
9798         if(i >= REGION_LIST_LENGTH - 1)
9799         {
9800            i = 0;
9801            continue;
9802         }
9803
9804         if(region_info_list[i].type)
9805         {
9806            index = i;
9807            break;
9808         }
9809         else
9810            i++;
9811      }
9812   }
9813   else if(ui_pressed_repeat_throttle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
9814   {
9815      int i = index - 1;
9816
9817      /* search previous valid info list */
9818      while(1)
9819      {
9820         if(i < 0)
9821         {
9822            i = REGION_LIST_LENGTH - 1;
9823            continue;
9824         }
9825
9826         if(region_info_list[i].type)
9827         {
9828            index = i;
9829            break;
9830         }
9831         else
9832            i--;
9833      }
9834   }
9835   else if(input_ui_pressed(machine, IPT_UI_SELECT))
9836   {
9837      if(menu->sel == kMenu_Return)
9838         menu->sel = -1;
9839   }
9840   else if(input_ui_pressed(machine, IPT_UI_CANCEL))
9841   {
9842      menu->sel = -1;
9843   }
9844
9845   return menu->sel + 1;
9846}
9847
9848/*-----------------------------------------------------
9849  debug_cheat_menu - view internal cheat engine data
9850-----------------------------------------------------*/
9851
9852static int debug_cheat_menu(running_machine *machine, cheat_menu_stack *menu)
9853{
9854   enum{
9855      kMenu_DriverName = 0,
9856      kMenu_GameName,
9857#ifdef MESS
9858      kMenu_CRC,
9859#endif
9860      kMenu_FullMenuPageHeight,
9861      kMenu_CheatListLength,
9862      kMenu_Separator,
9863      kMenu_CPURegionInfo,
9864      kMenu_KeyCodeChecker,
9865      kMenu_Return,
9866      kMenu_Max };
9867
9868   UINT8      total      = 0;
9869   const char   ** menuItem;
9870   const char   ** menuSubItem;
9871   char      * driverNameBuf;
9872#ifdef MESS
9873   char      * crcBuf;
9874#endif
9875   char      * heightBuf;
9876   char      * numCodeBuf;
9877
9878   /* first setting : NONE */
9879   if(menu->first_time)
9880      menu->first_time = 0;
9881
9882   /* required items = (total items + return + terminator) & (strings buf * 3 [MAME]/4 [MESS]) */
9883   request_strings(kMenu_Max + 2, kMenu_Max, 64, 0);
9884   menuItem = menu_strings.main_list;
9885   menuSubItem = menu_strings.sub_list;
9886   driverNameBuf = menu_strings.main_strings[0];
9887   heightBuf = menu_strings.main_strings[1];
9888   numCodeBuf = menu_strings.main_strings[2];
9889#ifdef MESS
9890   crcBuf = menu_strings.main_strings[3];
9891#endif
9892
9893   /********** MENU CONSTRUCTION **********/
9894   /* ##### DRIVER NAME ##### */
9895   menuItem[total] = "Driver";
9896   {
9897      astring * driverName = astring_alloc();
9898
9899      sprintf(driverNameBuf, "%s", astring_c(core_filename_extract_base(driverName, machine->gamedrv->source_file, TRUE)));
9900      menuSubItem[total++] = driverNameBuf;
9901      astring_free(driverName);
9902   }
9903
9904   /* ##### GAME / MACHINE NAME ##### */
9905#ifdef MESS
9906   menuItem[total]         = "Machine";
9907#else
9908   menuItem[total]       = "Game";
9909#endif
9910   menuSubItem[total++]   = machine->gamedrv->name;
9911
9912#ifdef MESS
9913   /* ##### CRC (MESS ONLY) ##### */
9914   menuItem[total] = "CRC";
9915   sprintf(crcBuf, "%X", thisGameCRC);
9916   menuSubItem[total++] = crcBuf;
9917#endif
9918
9919   /* ##### FULL PAGE MENU HEIGHT ##### */
9920   menuItem[total] = "Default Menu Height";
9921   sprintf(heightBuf, "%d", fullMenuPageHeight);
9922   menuSubItem[total++] = heightBuf;
9923
9924   /* ##### CHEAT LIST LENGTH ##### */
9925   menuItem[total] = "Total Code Entries";
9926   sprintf(numCodeBuf, "%d", cheatListLength);
9927   menuSubItem[total++] = numCodeBuf;
9928
9929   /* ##### SEPARATOR ##### */
9930   menuItem[total] = MENU_SEPARATOR_ITEM;
9931   menuSubItem[total++] = NULL;
9932
9933   /* ##### CPU/REGION INFO ##### */
9934   menuItem[total] = "View CPU/Region Info";
9935   menuSubItem[total++] = NULL;
9936
9937   /* ##### ACTIVATION KEY CODE CHEAKCER ##### */
9938   menuItem[total] = "Check Activation Key Code";
9939   menuSubItem[total++] = NULL;
9940
9941   /* ##### RETURN ##### */
9942   menuItem[total] = "Return to Prior Menu";
9943   menuSubItem[total++] = NULL;
9944
9945   /* ##### TERMINATE ARRAY ##### */
9946   menuItem[total] = NULL;
9947   menuSubItem[total] = NULL;
9948
9949   /* adjust cursor position */
9950   ADJUST_CURSOR(menu->sel, total)
9951
9952   /* draw it */
9953   old_style_menu(menuItem, menuSubItem, NULL, menu->sel, 0);
9954
9955   /********** KEY HANDLING **********/
9956   if(ui_pressed_repeat_throttle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
9957   {
9958      CURSOR_TO_PREVIOUS(menu->sel, total)
9959
9960      if(menu->sel == kMenu_Separator)
9961         menu->sel--;
9962   }
9963   else if(ui_pressed_repeat_throttle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
9964   {
9965      CURSOR_TO_NEXT(menu->sel, total)
9966
9967      if(menu->sel == kMenu_Separator)
9968         menu->sel++;
9969   }
9970   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
9971   {
9972      CURSOR_PAGE_UP(menu->sel)
9973   }
9974   else if(ui_pressed_repeat_throttle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
9975   {
9976      CURSOR_PAGE_DOWN(menu->sel, total)
9977   }
9978   else if(input_ui_pressed(machine, IPT_UI_SELECT))
9979   {
9980      switch(menu->sel)
9981      {
9982         case kMenu_CPURegionInfo:
9983            cheat_menu_stack_push(view_cpu_region_info_list_menu, menu->handler, menu->sel);
9984            break;
9985
9986         case kMenu_KeyCodeChecker:
9987            cheat_menu_stack_push(check_activation_key_code_menu, menu->handler, menu->sel);
9988            break;
9989
9990         case kMenu_Return:
9991            menu->sel = -1;
9992            break;
9993      }
9994   }
9995   else if(input_ui_pressed(machine, IPT_UI_CANCEL))
9996      menu->sel = -1;
9997
9998   return menu->sel + 1;
9999}
10000#endif
787710001/*------------------
787810002  cheate_periodic
787910003------------------*/
788010004
788110005static TIMER_CALLBACK( cheat_periodic )
788210006{
7883   int   i;
10007   int i;
788410008
788510009   if(input_ui_pressed(machine, IPT_UI_TOGGLE_CHEAT))
788610010   {
788710011      if(ShiftKeyPressed())
788810012      {
7889         /* ------ toggle watchpoint display if shift + toggle cheat ----- */
10013         /* ##### WATCHPOINT ##### */
789010014         watchesDisabled ^= 1;
789110015
789210016         ui_popup_time(1, "Watchpoints %s", watchesDisabled ? "Off" : "On");
789310017      }
789410018      else
789510019      {
7896         /* ------ toggle cheat ----- */
10020         /* ##### CHEAT ##### */
789710021         cheatsDisabled ^= 1;
789810022
789910023         ui_popup_time(1, "Cheats %s", cheatsDisabled ? "Off" : "On");
r2762r2763
791110035
791210036   for(i = 0; i < cheatListLength; i++)
791310037      cheat_periodicEntry(machine, &cheatList[i]);
10038
10039   if(EXTRACT_FIELD(cheatOptions, SearchBox) == kSearchBox_Minimum)
10040      SET_FIELD(cheatOptions, SearchBox, kSearchBox_Standard);
791410041}
791510042
791610043/*--------------
r2762r2763
794610073{
794710074   switch(size)
794810075   {
10076      case kSearchSize_8Bit:
10077      case kSearchSize_1Bit:
10078      default:
10079         buf[0] = (data >> 0) & 0xFF;
10080         buf[1] = 0;
10081
10082         return 1;
10083
794910084      case kSearchSize_16Bit:
795010085         buf[0] = (data >> 8) & 0xFF;
795110086         buf[1] = (data >> 0) & 0xFF;
r2762r2763
796910104         buf[4] = 0;
797010105
797110106         return 4;
7972
7973      case kSearchSize_8Bit:
7974      case kSearchSize_1Bit:
7975      default:
7976         buf[0] = (data >> 0) & 0xFF;
7977         buf[1] = 0;
7978
7979         return 1;
7980
798110107   }
7982
798310108}
798410109
798510110/*---------------------------------------------
r2762r2763
798810113
798910114void cheat_display_watches(void)
799010115{
7991   int      i;
10116   int i;
799210117
799310118   if(watchesDisabled)
799410119      return;
799510120
799610121   for(i = 0; i < watchListLength; i++)
799710122   {
10123      WatchInfo * info = &watchList[i];
10124
799810125      int         j;
7999      WatchInfo   * info = &watchList[i];
8000      char      buf[1024];
8001      UINT32      address = info->address;
8002      int         xOffset = 0, yOffset = 0;
800310126      int         numChars;
8004      int         lineElements = 0;
10127      int         xOffset         = 0;
10128      int         yOffset         = 0;
10129      int         lineElements   = 0;
10130      UINT32      address         = info->address;
800510131
8006      /* ----- if the length of the watchpoint is not 0, display it ----- */
10132      char      buf[1024];
10133
800710134      if(info->numElements)
800810135      {
8009         /* ----- label display ----- */
10136         /* ##### LABEL ##### */
801010137         switch(info->labelType)
801110138         {
801210139            case kWatchLabel_Address:
r2762r2763
802410151               break;
802510152         }
802610153
8027         /* ----- value display ----- */
10154         /* ##### VALUE ##### */
802810155         for(j = 0; j < info->numElements; j++)
802910156         {
8030            UINT32   data = 0;
10157            UINT32 data = 0;
803110158
8032            switch(info->locationType)
10159            if(!TEST_FIELD(info->cpu, RegionFlag))
803310160            {
8034               case kLocation_Standard:
8035                  data =   (DoCPURead(info->cpu, address, kSearchByteIncrementTable[info->elementBytes], CPUNeedsSwap(info->cpu)) + info->addValue) &
8036                        kSearchByteMaskTable[info->elementBytes];
8037                  break;
10161               UINT8 cpu = EXTRACT_FIELD(info->cpu, CPUIndex);
803810162
8039               case kLocation_MemoryRegion:
10163               switch(EXTRACT_FIELD(info->cpu, AddressSpace))
804010164               {
8041                  int      region = REGION_CPU1 + info->cpu;
8042                  UINT8   * buf = memory_region(region);
10165                  case kAddressSpace_Program:
10166                     data = (DoCPURead(cpu, address, kSearchByteIncrementTable[info->elementBytes], cpu_needs_swap(cpu)) + info->addValue) & kSearchByteMaskTable[info->elementBytes];
10167                     break;
804310168
8044                  data =   DoMemoryRead(buf, address, kSearchByteIncrementTable[info->elementBytes], RegionNeedsSwap(region) + info->addValue, GetRegionCPUInfo(region)) &
8045                        kSearchByteMaskTable[info->elementBytes];
8046               }
8047               break;
10169                  case kAddressSpace_DataSpace:
10170                  case kAddressSpace_IOSpace:
10171                  case kAddressSpace_OpcodeRAM:
10172                  {
10173                     UINT8 * buf = (UINT8 *) GetMemoryRegionBasePointer(cpu, EXTRACT_FIELD(info->cpu, AddressSpace), address);
804810174
8049               case kLocation_IndirectIndexed:
8050                  return; // under construction...
10175                     if(buf)
10176                        data =   DoMemoryRead(buf, address, kSearchByteIncrementTable[info->elementBytes], cpu_needs_swap(cpu) + info->addValue, get_cpu_info(cpu)) &
10177                              kSearchByteMaskTable[info->elementBytes];
10178                  }
10179                  break;
805110180
8052               case kLocation_ProgramSpace:
8053               {
8054                  UINT8   * buf;
8055
8056                  memory_set_opbase(address);
8057
8058                  buf = memory_get_op_ptr(info->cpu, address, 0);
8059
8060                  buf -= address;
8061
8062                  if(buf)
8063                     data =   DoMemoryRead(buf, address, kSearchByteIncrementTable[info->elementBytes], CPUNeedsSwap(info->cpu) + info->addValue, GetCPUInfo(info->cpu)) &
8064                           kSearchByteMaskTable[info->elementBytes];
10181                  default:
10182                     return;
806510183               }
8066               break;
10184            }
10185            else
10186            {
10187               UINT8 * buf = memory_region(info->cpu);
806710188
8068               default:
8069                  logerror("invalid location type : %x\n", info->locationType);
8070                  return;
8071
10189               if(buf)
10190                  data =   DoMemoryRead(buf, address, kSearchByteIncrementTable[info->elementBytes],
10191                        region_needs_swap(info->cpu) + info->addValue,
10192                        get_region_info(info->cpu)) & kSearchByteMaskTable[info->elementBytes];
807210193            }
807310194
807410195            data = DoShift(data, info->dataShift);
r2762r2763
807710198            if(   (lineElements >= info->elementsPerLine) && info->elementsPerLine)
807810199            {
807910200               lineElements = 0;
8080
808110201               xOffset = 0;
808210202               yOffset++;
808310203            }
r2762r2763
820510325
820610326static void AddCheatBefore(UINT32 idx)
820710327{
8208   /* ----- memory reallocation ----- */
820910328   ResizeCheatList(cheatListLength + 1);
821010329
821110330   if(idx < (cheatListLength - 1))
r2762r2763
821410333   if(idx >= cheatListLength)
821510334      idx = cheatListLength - 1;
821610335
8217   /* ----- insert new entry ----- */
821810336   memset(&cheatList[idx], 0, sizeof(CheatEntry));
821910337
822010338   cheatList[idx].flags |= kCheatFlag_Dirty;
822110339
822210340   ResizeCheatActionList(&cheatList[idx], 1);
10341
10342   cheatList[idx].actionList[0].extendData = ~0;
10343   cheatList[idx].actionList[0].lastValue = NULL;
10344
10345   messageType = kCheatMessage_SucceededToAdd;
10346   messageTimer = DEFAULT_MESSAGE_TIME;
822310347}
822410348
822510349/*----------------
r2762r2763
822910353static void DeleteCheatAt(UINT32 idx)
823010354{
823110355   if(idx >= cheatListLength)
10356   {
10357      messageType = kCheatMessage_FailedToDelete;
10358      messageTimer = DEFAULT_MESSAGE_TIME;
823210359      return;
10360   }
823310361
823410362   DisposeCheat(&cheatList[idx]);
823510363
r2762r2763
823910367   }
824010368
824110369   ResizeCheatListNoDispose(cheatListLength - 1);
10370
10371   messageType = kCheatMessage_SucceededToDelete;
10372   messageTimer = DEFAULT_MESSAGE_TIME;
824210373}
824310374
824410375/*------------------------------------------------
r2762r2763
825310384
825410385      free(entry->name);
825510386      free(entry->comment);
10387      free(entry->labelIndex);
825610388
825710389      for(i = 0; i < entry->actionListLength; i++)
825810390      {
r2762r2763
826710399   }
826810400}
826910401
8270/*------------------------------------
8271  GetNewCheat - get new cheat entry
8272------------------------------------*/
10402/*-----------------------------------------------------
10403  GetNewCheat - insert new cheat entry and return it
10404-----------------------------------------------------*/
827310405
827410406static CheatEntry *   GetNewCheat(void)
827510407{
8276   /* ----- insert new cheat entry ----- */
827710408   AddCheatBefore(cheatListLength);
827810409
8279   /* ----- return inserted entry ----- */
828010410   return &cheatList[cheatListLength - 1];
828110411}
828210412
r2762r2763
831910449/*---------------------------------
832010450  ResizeCheatActionListNoDispose
832110451---------------------------------*/
8322
10452#if 0
832310453static void ResizeCheatActionListNoDispose(CheatEntry * entry, UINT32 newLength)
832410454{
832510455   if(newLength != entry->actionListLength)
r2762r2763
834410474   }
834510475}
834610476
8347/*------------------
8348  AddActionBefore
8349------------------*/
10477/*----------------------------------------------------------------
10478  AddActionBefore - Insert empty Action
10479                    This function is only called in EditCheat()
10480----------------------------------------------------------------*/
835010481
835110482static void AddActionBefore(CheatEntry * entry, UINT32 idx)
835210483{
r2762r2763
835910490      idx = entry->actionListLength - 1;
836010491
836110492   memset(&entry->actionList[idx], 0, sizeof(CheatAction));
10493
10494   cheatList[idx].actionList[0].extendData = ~0;
10495   cheatList[idx].actionList[0].lastValue = NULL;
836210496}
836310497
836410498/*-----------------
r2762r2763
836810502static void DeleteActionAt(CheatEntry * entry, UINT32 idx)
836910503{
837010504   if(idx >= entry->actionListLength)
10505   {
10506      messageType = kCheatMessage_FailedToDelete;
10507      messageTimer = DEFAULT_MESSAGE_TIME;
837110508      return;
10509   }
837210510
837310511   DisposeAction(&entry->actionList[idx]);
837410512
r2762r2763
837610514      memmove(&entry->actionList[idx], &entry->actionList[idx + 1], sizeof(CheatAction) * (entry->actionListLength - 1 - idx));
837710515
837810516   ResizeCheatActionListNoDispose(entry, entry->actionListLength - 1);
10517
10518   messageTimer = DEFAULT_MESSAGE_TIME;
10519   messageType = kCheatMessage_SucceededToDelete;
837910520}
8380
10521#endif
838110522/*----------------
838210523  DisposeAction
838310524----------------*/
r2762r2763
838810529   {
838910530      free(action->optionalName);
839010531
10532      if(action->lastValue)
10533         free(action->lastValue);
10534
839110535      memset(action, 0, sizeof(CheatAction));
839210536   }
839310537}
839410538
8395/*----------------------------------------------------
8396  InitWatch - initialize y-position for watchpoints
8397----------------------------------------------------*/
10539/*------------------------------------------------
10540  InitWatch - initialize a value for watchpoint
10541------------------------------------------------*/
839810542
839910543static void InitWatch(WatchInfo * info, UINT32 idx)
840010544{
10545   /* NOTE : 1st watchpoint should be always Y = 0 */
840110546   if(idx > 0)
8402      /* ----- set 2nd or later y-position ----- */
840310547      info->y = watchList[idx - 1].y + ui_get_line_height();
840410548   else
8405      /* ----- set 1st y-position (always Y=0) ----- */
840610549      info->y = 0;
840710550}
840810551
r2762r2763
853610679   WatchInfo   * info;
853710680   WatchInfo   * theWatch = NULL;
853810681
8539   /* ----- search unused watchpoint ----- */
10682   /* search unused watchpoint */
854010683   for(i = 0; i < watchListLength; i++)
854110684   {
854210685      info = &watchList[i];
r2762r2763
854810691      }
854910692   }
855010693
8551   /* ----- if unused watchpoint is not found, insert new watchpoint as unused ----- */
10694   /* if unused watchpoint is not found, insert new watchpoint */
855210695   if(!theWatch)
855310696   {
855410697      AddWatchBefore(watchListLength);
r2762r2763
855610699      theWatch = &watchList[watchListLength - 1];
855710700   }
855810701
8559   /* ----- return unused watchpoint ----- */
856010702   return theWatch;
856110703}
856210704
r2762r2763
856810710{
856910711   if(watch)
857010712   {
8571      CheatEntry   * entry = GetNewCheat();
8572      CheatAction   * action = &entry->actionList[0];
10713      int         tempStringLength;
857310714      char      tempString[1024];
8574      int         tempStringLength;
8575      UINT32      data = DoCPURead(watch->cpu, watch->address, kSearchByteIncrementTable[watch->elementBytes], 0);
10715      CheatEntry   * entry            = GetNewCheat();
10716      CheatAction   * action         = &entry->actionList[0];
857610717
8577      tempStringLength = sprintf(tempString, "%.8X (%d) = %.*X", watch->address, watch->cpu, kSearchByteDigitsTable[watch->elementBytes], data);
10718      /* set parameters */
10719      action->region      = watch->cpu;
10720      SET_FIELD(action->type, CPURegion, action->region);
10721      SET_FIELD(action->type, AddressSize, watch->elementBytes);
10722      action->address      = action->originalAddress   = watch->address;
10723      action->extendData   = ~0;
10724      action->lastValue   = NULL;
857810725
8579      entry->name = realloc(entry->name, tempStringLength + 1);
8580      memcpy(entry->name, tempString, tempStringLength + 1);
10726      action->data       = ReadData(action);
858110727
8582      SET_FIELD(action->type, LocationParameter, watch->cpu);
8583      SET_FIELD(action->type, BytesUsed, kSearchByteIncrementTable[watch->elementBytes] - 1);
8584      action->address = watch->address;
8585      action->data = data;
8586      action->extendData = 0xFFFFFFFF;
8587      action->originalDataField = data;
10728      /* set name */
10729      tempStringLength = sprintf(tempString, "%.8X (%d) = %.*X", watch->address, watch->cpu, kSearchByteDigitsTable[watch->elementBytes], action->data);
10730      entry->name = create_string_copy(tempString);
858810731
858910732      UpdateCheatInfo(entry, 0);
10733
10734      messageType      = kCheatMessage_SucceededToAdd;
10735      messageTimer   = DEFAULT_MESSAGE_TIME;
859010736   }
10737   else
10738   {
10739      messageType      = kCheatMessage_FailedToAdd;
10740      messageTimer   = DEFAULT_MESSAGE_TIME;
10741   }
859110742}
859210743
8593/*-------------------------------------------------------------------------------------
10744/*--------------------------------------------------------------------------------------
859410745  SetupCheatFromWatchAsWatch - add new watch code from watchpoint list to cheat list
8595-------------------------------------------------------------------------------------*/
10746                               If watchpoint is not displayed (length = 0), don't add
10747--------------------------------------------------------------------------------------*/
859610748
859710749static void SetupCheatFromWatchAsWatch(CheatEntry * entry, WatchInfo * watch)
859810750{
859910751   if(watch && entry && watch->numElements)
860010752   {
8601      CheatAction   * action;
8602      char      tempString[1024];
8603      size_t      tempStringLength;
10753      char         tempString[256];
10754      CheatAction      * action;
860410755
860510756      DisposeCheat(entry);
860610757      ResizeCheatActionList(entry, 1);
860710758
860810759      action = &entry->actionList[0];
860910760
8610      tempStringLength = sprintf(tempString, "Watch %.8X (%d)", watch->address, watch->cpu);
10761      sprintf(tempString, "Watch %.8X (%d)", watch->address, watch->cpu);
861110762
8612      entry->name = realloc(entry->name, tempStringLength + 1);
8613      memcpy(entry->name, tempString, tempStringLength + 1);
10763      /* set name */
10764      entry->name      = create_string_copy(tempString);
10765      entry->comment   = create_string_copy(watch->label);
861410766
8615      action->type = 0;
8616      SET_FIELD(action->type, LocationParameter, watch->cpu);
8617      SET_FIELD(action->type, Type, kType_Watch);
8618      SET_FIELD(action->type, BytesUsed, kSearchByteIncrementTable[watch->elementBytes] - 1);
8619      SET_FIELD(action->type, TypeParameter, watch->displayType | ((watch->labelType == kWatchLabel_String) ? 0x04 : 0));
10767      /* set parameters */
10768      SET_FIELD(action->type, CodeType, kCodeType_Watch);
10769      SET_FIELD(action->type, AddressSize, kSearchByteIncrementTable[watch->elementBytes] - 1);
862010770
8621      action->address = watch->address;
8622      action->data  =   ((watch->numElements - 1) & 0xFF) |
8623                  ((watch->skip & 0xFF) << 8) |
8624                  ((watch->elementsPerLine & 0xFF) << 16) |
8625                  ((watch->addValue & 0xFF) << 24);
8626      action->originalDataField = action->data;
8627      action->extendData = 0xFFFFFFFF;
10771      action->region            =   watch->cpu;
10772      action->address            =   watch->address;
10773      action->originalAddress      =   action->address;
10774      action->originalDataField   =   action->data;
10775      action->extendData         =   0xFFFFFFFF;
862810776
8629      tempStringLength = strlen(watch->label);
8630      entry->comment = realloc(entry->comment, tempStringLength + 1);
8631      memcpy(entry->comment, watch->label, tempStringLength + 1);
10777      SET_FIELD(action->data, WatchNumElements, watch->numElements - 1);
10778      SET_FIELD(action->data, WatchSkip, watch->skip);
10779      SET_FIELD(action->data, WatchElementsPerLine, watch->elementsPerLine);
10780      SET_FIELD(action->data, WatchAddValue, watch->addValue);
863210781
10782      /* set comment */
10783
863310784      UpdateCheatInfo(entry, 0);
10785
10786      messageType      = kCheatMessage_SucceededToAdd;
10787      messageTimer   = DEFAULT_MESSAGE_TIME;
863410788   }
10789   else
10790   {
10791      messageType      = kCheatMessage_FailedToAdd;
10792      messageTimer   = DEFAULT_MESSAGE_TIME;
10793   }
863510794}
863610795
8637/*-------------------
8638  ResizeSearchList
8639-------------------*/
10796/*-----------------------------------------------------------
10797  ResetWatch - clear data in WatchInfo except x/y position
10798-----------------------------------------------------------*/
864010799
8641static void ResizeSearchList(UINT32 newLength)
10800static void ResetWatch(WatchInfo * watch)
864210801{
8643   if(newLength != searchListLength)
10802   if(watch)
864410803   {
8645      if(newLength < searchListLength)
10804      watch->address         = 0;
10805      watch->cpu            = 0;
10806      watch->numElements      = 0;
10807      watch->elementBytes      = kWatchSizeConversionTable[0];
10808      watch->labelType      = kWatchLabel_None;
10809      watch->displayType      = kWatchDisplayType_Hex;
10810      watch->skip            = 0;
10811      watch->elementsPerLine   = 0;
10812      watch->addValue         = 0;
10813      watch->addressShift      = 0;
10814      watch->dataShift      = 0;
10815      watch->xor            = 0;
10816      watch->linkedCheat      = NULL;
10817      watch->label[0]         = 0;
10818   }
10819}
10820
10821/*------------------------------------------------------------------
10822  resize_search_list - reallocate search list if different length
10823------------------------------------------------------------------*/
10824
10825static void resize_search_list(UINT32 new_length)
10826{
10827   if(new_length != search_list_length)
10828   {
10829      /* if delete, dispose deleted or later search lists */
10830      if(new_length < search_list_length)
864610831      {
8647         int   i;
10832         int i;
864810833
8649         for(i = newLength; i < searchListLength; i++)
8650            DisposeSearch(i);
10834         for(i = new_length; i < search_list_length; i++)
10835            dispose_search(&search_list[i]);
865110836      }
865210837
8653      searchList = realloc(searchList, newLength * sizeof(SearchInfo));
8654      if(!searchList && (newLength != 0))
10838      /* reallocate search list */
10839      search_list = realloc(search_list, new_length * sizeof(search_info));
10840
10841      if(search_list == NULL && new_length != 0)
865510842      {
10843         /* memory allocation error */
865610844         logerror("ResizeSearchList: out of memory resizing search list\n");
865710845         ui_popup_time(2, "out of memory while adding search");
865810846
8659         searchListLength = 0;
10847         search_list_length = 0;
866010848
866110849         return;
866210850      }
866310851
8664      if(newLength > searchListLength)
10852      /* if insert, initialize new search list */
10853      if(new_length > search_list_length)
866510854      {
8666         int   i;
10855         int i;
866710856
8668         memset(&searchList[searchListLength], 0, (newLength - searchListLength) * sizeof(SearchInfo));
10857         memset(&search_list[search_list_length], 0, (new_length - search_list_length) * sizeof(search_info));
866910858
8670         for(i = searchListLength; i < newLength; i++)
8671         {
8672            InitSearch(&searchList[i]);
8673         }
10859         for(i = search_list_length; i < new_length; i++)
10860            init_search(&search_list[i]);
867410861      }
867510862
8676      searchListLength = newLength;
10863      search_list_length = new_length;
867710864   }
867810865}
867910866
8680/*----------------------------
8681  ResizeSearchListNoDispose
8682----------------------------*/
8683
10867/*--------------------------------
10868  resize_search_list_no_dispose
10869--------------------------------*/
10870#if 0
868410871static void ResizeSearchListNoDispose(UINT32 newLength)
868510872{
8686   if(newLength != searchListLength)
10873   if(newLength != search_list_length)
868710874   {
8688      searchList = realloc(searchList, newLength * sizeof(SearchInfo));
10875      searchList = realloc(searchList, newLength * sizeof(search_info));
10876
868910877      if(!searchList && (newLength != 0))
869010878      {
869110879         logerror("ResizeSearchList: out of memory resizing search list\n");
869210880         ui_popup_time(2, "out of memory while adding search");
869310881
8694         searchListLength = 0;
10882         search_list_length = 0;
869510883
869610884         return;
869710885      }
869810886
8699      if(newLength > searchListLength)
8700      {
8701         memset(&searchList[searchListLength], 0, (newLength - searchListLength) * sizeof(SearchInfo));
8702      }
10887      if(newLength > search_list_length)
10888         memset(&searchList[search_list_length], 0, (newLength - search_list_length) * sizeof(search_info));
870310889
8704      searchListLength = newLength;
10890      search_list_length = newLength;
870510891   }
870610892}
870710893
8708/*------------------
8709  AddSearchBefore
8710------------------*/
10894/*--------------------
10895  add_search_before
10896--------------------*/
871110897
871210898static void AddSearchBefore(UINT32 idx)
871310899{
8714   ResizeSearchListNoDispose(searchListLength + 1);
10900   ResizeSearchListNoDispose(search_list_length + 1);
871510901
8716   if(idx < (searchListLength - 1))
8717      memmove(&searchList[idx + 1], &searchList[idx], sizeof(SearchInfo) * (searchListLength - 1 - idx));
10902   if(idx < (search_list_length - 1))
10903      memmove(&search_list[idx + 1], &search_list[idx], sizeof(search_info) * (search_list_length - 1 - idx));
871810904
8719   if(idx >= searchListLength)
8720      idx = searchListLength - 1;
10905   if(idx >= search_list_length)
10906      idx = search_list_length - 1;
872110907
8722   memset(&searchList[idx], 0, sizeof(SearchInfo));
8723   InitSearch(&searchList[idx]);
10908   memset(&search_list[idx], 0, sizeof(search_info));
10909
10910   init_search(&search_list[idx]);
872410911}
872510912
8726/*-----------------
8727  DeleteSearchAt
8728-----------------*/
10913/*-------------------
10914  delete_search_at
10915-------------------*/
872910916
873010917static void DeleteSearchAt(UINT32 idx)
873110918{
8732   if(idx >= searchListLength)
10919   if(idx >= search_list_length)
873310920      return;
873410921
873510922   DisposeSearch(idx);
873610923
8737   if(idx < (searchListLength - 1))
8738   {
8739      memmove(&searchList[idx], &searchList[idx + 1], sizeof(SearchInfo) * (searchListLength - 1 - idx));
8740   }
10924   if(idx < (search_list_length - 1))
10925      memmove(&search_list[idx], &search_list[idx + 1], sizeof(search_info) * (search_list_length - 1 - idx));
874110926
8742   ResizeSearchListNoDispose(searchListLength - 1);
10927   ResizeSearchListNoDispose(search_list_length - 1);
874310928}
10929#endif
10930/*---------------------------------------
10931  init_search - initialize search info
10932---------------------------------------*/
874410933
8745/*--------------------------------------
8746  InitSearch - initialize search info
8747--------------------------------------*/
8748
8749static void InitSearch(SearchInfo * info)
10934static void init_search(search_info *info)
875010935{
875110936   if(info)
8752   {
8753      info->searchSpeed = kSearchSpeed_Medium;
8754   }
10937      info->search_speed = ksearch_speed_Medium;
875510938}
875610939
8757/*-----------------------
8758  DisposeSearchRegions
8759-----------------------*/
10940/*---------------------------------------------------------------------------
10941  dispose_search_reigons - free all search regions in selected search info
10942---------------------------------------------------------------------------*/
876010943
8761static void DisposeSearchRegions(SearchInfo * info)
10944static void dispose_search_reigons(search_info *info)
876210945{
8763   if(info->regionList)
10946   if(info->region_list)
876410947   {
8765      int   i;
10948      int i;
876610949
8767      for(i = 0; i < info->regionListLength; i++)
10950      for(i = 0; i < info->region_list_length; i++)
876810951      {
8769         SearchRegion   * region = &info->regionList[i];
10952         search_region *region = &info->region_list[i];
877010953
877110954         free(region->first);
877210955         free(region->last);
877310956         free(region->status);
8774         free(region->backupLast);
8775         free(region->backupStatus);
10957         free(region->backup_last);
10958         free(region->backup_status);
877610959      }
877710960
8778      free(info->regionList);
10961      free(info->region_list);
877910962
8780      info->regionList = NULL;
10963      info->region_list = NULL;
878110964   }
878210965
8783   info->regionListLength = 0;
10966   info->region_list_length = 0;
878410967}
878510968
8786/*------------------
8787  DisposeSearch
8788  ----------------*/
10969/*-------------------------------------------------------------------------
10970  dispose_search - free selected search info and all search region in it
10971-------------------------------------------------------------------------*/
878910972
8790static void DisposeSearch(UINT32 idx)
10973static void dispose_search(search_info *info)
879110974{
8792   SearchInfo   * info;
10975   dispose_search_reigons(info);
879310976
8794   if(idx >= searchListLength)
8795      return;
10977   free(info->name);
879610978
8797   info = &searchList[idx];
8798
8799   DisposeSearchRegions(info);
8800
8801   free(info->name);
880210979   info->name = NULL;
880310980}
880410981
8805/*----------------------------------------
8806  GetCurrentSearch - return search info
8807----------------------------------------*/
10982/*--------------------------------------------------
10983  get_current_search - return working search info
10984--------------------------------------------------*/
880810985
8809static SearchInfo *   GetCurrentSearch(void)
10986static search_info *get_current_search(void)
881010987{
8811   if(currentSearchIdx >= searchListLength)
8812      currentSearchIdx = searchListLength - 1;
8813   if(currentSearchIdx < 0)
8814      currentSearchIdx = 0;
10988   if(current_search_idx >= search_list_length)
10989      current_search_idx = search_list_length - 1;
881510990
8816   return &searchList[currentSearchIdx];
10991   if(current_search_idx < 0)
10992      current_search_idx = 0;
10993
10994   return &search_list[current_search_idx];
881710995}
881810996
8819/*-------------------------------------------------------
8820  FillBufferFromRegion - set a data into search region
8821-------------------------------------------------------*/
10997/*----------------------------------------------------------------------------------------------
10998  fill_buffer_from_region - fill selected search region with a value read from search address
10999----------------------------------------------------------------------------------------------*/
882211000
8823static void FillBufferFromRegion(SearchRegion * region, UINT8 * buf)
11001static void fill_buffer_from_region(search_region *region, UINT8 * buf)
882411002{
8825   UINT32   offset;
11003   UINT32 offset;
882611004
8827   /* ### optimize if needed ### */
11005   /* ##### optimize if needed ##### */
882811006   for(offset = 0; offset < region->length; offset++)
8829      buf[offset] = ReadRegionData(region, offset, 1, 0);
11007      buf[offset] = read_region_data(region, offset, 1, 0);
883011008}
883111009
8832/*-------------------------------------------------------
8833  ReadRegionData - read a data from region when search
8834-------------------------------------------------------*/
11010/*---------------------------------------------------------------------------
11011  read_region_data - read a data from memory or search region in searching
11012---------------------------------------------------------------------------*/
883511013
8836static UINT32 ReadRegionData(SearchRegion * region, UINT32 offset, UINT8 size, UINT8 swap)
11014static UINT32 read_region_data(search_region *region, UINT32 offset, UINT8 size, UINT8 swap)
883711015{
8838   UINT32   address = region->address + offset;
11016   UINT32 address = region->address + offset;
883911017
8840   switch(region->targetType)
11018   switch(region->target_type)
884111019   {
884211020      case kRegionType_CPU:
8843         return DoCPURead(region->targetIdx, address, size, CPUNeedsSwap(region->targetIdx) ^ swap);
11021         return DoCPURead(region->target_idx, address, size, cpu_needs_swap(region->target_idx) ^ swap);
884411022
884511023      case kRegionType_Memory:
8846         if(region->cachedPointer)
8847            return DoMemoryRead(region->cachedPointer, address, size, swap, &rawCPUInfo);
8848         else
8849            return 0;
11024         {
11025            UINT8 * buf = (UINT8 *)region->cached_pointer;
11026
11027            if(buf)
11028/*                  return DoMemoryRead(region->cached_pointer, address, size, swap, &raw_cpu_info); */
11029               return DoMemoryRead(buf, address, size, cpu_needs_swap(region->target_idx) ^ swap, get_cpu_info(region->target_idx));
11030            else
11031               return 0;
11032         }
885011033   }
885111034
885211035   return 0;
885311036}
8854/*-----------------------------------------------
8855  BackupSearch - back up current search region
8856-----------------------------------------------*/
11037/*------------------------------------------------
11038  backup_search - back up current search region
11039------------------------------------------------*/
885711040
8858static void BackupSearch(SearchInfo * info)
11041static void backup_search(search_info *info)
885911042{
8860   int   i;
11043   int i;
886111044
8862   for(i = 0; i < info->regionListLength; i++)
8863      BackupRegion(&info->regionList[i]);
11045   for(i = 0; i < info->region_list_length; i++)
11046      backup_region(&info->region_list[i]);
886411047
8865   info->oldNumResults = info->numResults;
8866   info->backupValid = 1;
11048   info->old_num_results = info->num_results;
11049   info->backup_valid = 1;
886711050}
886811051
8869/*-------------------------------------------------------
8870  RestoreSearchBackup - restore previous search region
8871-------------------------------------------------------*/
11052/*---------------------------------------------------------
11053  restore_search_backup - restore previous search region
11054---------------------------------------------------------*/
887211055
8873static void RestoreSearchBackup(SearchInfo * info)
11056static void restore_search_backup(search_info *info)
887411057{
887511058   int i;
887611059
8877   if(info && info->backupValid)
11060   if(info && info->backup_valid)
887811061   {
8879      for(i = 0; i < info->regionListLength; i++)
8880         RestoreRegionBackup(&info->regionList[i]);
11062      for(i = 0; i < info->region_list_length; i++)
11063         restore_region_backup(&info->region_list[i]);
888111064
8882      info->numResults = info->oldNumResults;
8883      info->backupValid = 0;
11065      info->num_results   = info->old_num_results;
11066      info->backup_valid   = 0;
888411067
8885      ui_popup_time(1, "values restored");
11068#if 1
11069      messageTimer = DEFAULT_MESSAGE_TIME;
11070      messageType = kCheatMessage_RestoreValue;
11071#else
11072      ui_popup_time(1, "values restored");   /* not displayed when ui is opend */
11073#endif
888611074   }
888711075   else
8888      ui_popup_time(1, "there are no old values");
11076   {
11077#if 1
11078      messageTimer = DEFAULT_MESSAGE_TIME;
11079      messageType = kCheatMessage_NoOldValue;
11080#else
11081      ui_popup_time(1, "there are no old values");   /* not displayed when ui is opend */
11082#endif
11083   }
888911084}
889011085
8891/*------------------------------------------------
8892  BackupRegion - back up current search results
8893------------------------------------------------*/
11086/*-------------------------------------------------
11087  backup_region - back up current search results
11088-------------------------------------------------*/
889411089
8895static void BackupRegion(SearchRegion * region)
11090static void backup_region(search_region *region)
889611091{
889711092   if(region->flags & kRegionFlag_Enabled)
889811093   {
8899      memcpy(region->backupLast,      region->last,   region->length);
8900      memcpy(region->backupStatus,   region->status,   region->length);
8901      region->oldNumResults =         region->numResults;
11094      memcpy(region->backup_last,      region->last,   region->length);
11095      memcpy(region->backup_status,   region->status,   region->length);
11096
11097      region->old_num_results = region->num_results;
890211098   }
890311099}
890411100
8905/*--------------------------------------------------------
8906  RestoreSearchBackup - restore previous search results
8907--------------------------------------------------------*/
11101/*----------------------------------------------------------
11102  restore_region_backup - restore previous search results
11103----------------------------------------------------------*/
890811104
8909static void RestoreRegionBackup(SearchRegion * region)
11105static void restore_region_backup(search_region *region)
891011106{
891111107   if(region->flags & kRegionFlag_Enabled)
891211108   {
8913      memcpy(region->last,   region->backupLast,      region->length);
8914      memcpy(region->status,   region->backupStatus,   region->length);
8915      region->numResults =   region->oldNumResults;
11109      memcpy(region->last,   region->backup_last,   region->length);
11110      memcpy(region->status,   region->backup_status,   region->length);
11111
11112      region->num_results = region->old_num_results;
891611113   }
891711114}
891811115
8919/*-----------------------------------------------------------
8920  DefaultEnableRegion - get default regions you can search
8921-----------------------------------------------------------*/
11116/*--------------------------------------------------------
11117  default_enable_region - get default regions to search
11118--------------------------------------------------------*/
892211119
8923static UINT8 DefaultEnableRegion(running_machine *machine, SearchRegion * region, SearchInfo * info)
11120static UINT8 default_enable_region(running_machine *machine, search_region *region, search_info *info)
892411121{
8925   write8_machine_func   handler = region->writeHandler->write.mhandler8;
8926   FPTR            handlerAddress = (FPTR)handler;
11122   write8_machine_func   handler         = region->write_handler->write.mhandler8;
11123   FPTR            handlerAddress   = (FPTR)handler;
892711124
8928   switch(info->searchSpeed)
11125   switch(info->search_speed)
892911126   {
8930      case kSearchSpeed_Fast:
8931
11127      case ksearch_speed_Fast:
893211128#if HAS_SH2
8933         if(machine->config->cpu[0].type == CPU_SH2)
8934         {
8935            if(   (info->targetType == kRegionType_CPU) && (info->targetIdx == 0) && (region->address == 0x06000000))
11129         if(   machine->config->cpu[0].type == CPU_SH2 &&
11130            (info->target_type == kRegionType_CPU && info->target_idx == 0 && region->address == 0x06000000))
893611131               return 1;
8937
11132         else
893811133            return 0;
8939         }
894011134#endif
8941
8942         if(   (handler == SMH_RAM) && (!region->writeHandler->baseptr))
11135         if(handler == SMH_RAM && region->write_handler->baseptr != NULL)
894311136            return 1;
894411137
8945#ifndef MESS
8946
8947         {
8948            /* ----- for neogeo, search bank one ----- */
8949            if(   (!strcmp(machine->gamedrv->parent, "neogeo")) && (info->targetType == kRegionType_CPU) &&
8950               (info->targetIdx == 0) && (handler == SMH_BANK1))
8951               return 1;
8952         }
8953
8954#endif
8955
8956#if HAS_TMS34010
8957
8958         /* ----- for exterminator, search bank one ----- */
8959         if(   (machine->config->cpu[1].type == CPU_TMS34010) && (info->targetType == kRegionType_CPU) &&
8960            (info->targetIdx == 1) && (handler == SMH_BANK1))
11138      case ksearch_speed_Medium:
11139         if(handlerAddress >= (FPTR)SMH_BANK1 && handlerAddress <= (FPTR)SMH_BANK24)
896111140            return 1;
896211141
8963         /* ----- for smashtv, search bank two ----- */
8964         if(   (machine->config->cpu[0].type == CPU_TMS34010) && (info->targetType == kRegionType_CPU) &&
8965            (info->targetIdx == 0) && (handler == SMH_BANK2))
8966            return 1;
8967
8968#endif
8969         return 0;
8970
8971      case kSearchSpeed_Medium:
8972         if(   (handlerAddress >= ((FPTR)SMH_BANK1)) && (handlerAddress <= ((FPTR)SMH_BANK24)))
8973            return 1;
8974
897511142         if(handler == SMH_RAM)
897611143            return 1;
897711144
897811145         return 0;
897911146
8980      case kSearchSpeed_Slow:
8981         if(   (handler == SMH_NOP) || (handler == SMH_ROM))
11147      case ksearch_speed_Slow:
11148         if(handler == SMH_NOP || handler == SMH_ROM)
898211149            return 0;
898311150
8984         if(   (handlerAddress > STATIC_COUNT) && (!region->writeHandler->baseptr))
11151         if(handlerAddress > STATIC_COUNT && region->write_handler->baseptr == NULL)
898511152            return 0;
898611153
898711154         return 1;
898811155
8989      case kSearchSpeed_VerySlow:
8990         if(   (handler == SMH_NOP) || (handler == SMH_ROM))
11156      case ksearch_speed_VerySlow:
11157         if(handler == SMH_NOP || handler == SMH_ROM)
899111158            return 0;
899211159
899311160         return 1;
r2762r2763
899611163   return 0;
899711164}
899811165
8999/*-----------------------------
9000  SetSearchRegionDefaultName
9001-----------------------------*/
11166/*---------------------------------------------------------------------
11167  set_search_region_default_name - set name of region to region list
11168---------------------------------------------------------------------*/
900211169
9003static void SetSearchRegionDefaultName(SearchRegion * region)
11170static void set_search_region_default_name(search_region *region)
900411171{
9005   switch(region->targetType)
11172   switch(region->target_type)
900611173   {
900711174      case kRegionType_CPU:
900811175      {
9009         char   desc[16];
11176         char desc[16];
901011177
9011         if(region->writeHandler)
11178         if(region->write_handler)
901211179         {
9013            genf *            handler = region->writeHandler->write.generic;
9014            FPTR            handlerAddress = (FPTR)handler;
11180            genf   *handler      = region->write_handler->write.generic;
11181            FPTR   handler_address   = (FPTR)handler;
901511182
9016            if(   (handlerAddress >= ((FPTR)SMH_BANK1)) && (handlerAddress <= ((FPTR)SMH_BANK24)))
9017               sprintf(desc, "BANK%.2d", (int)(handlerAddress - (FPTR)SMH_BANK1) + 1);
11183            if(handler_address >= (FPTR)SMH_BANK1 && handler_address <= (FPTR)SMH_BANK24)
11184            {
11185               sprintf(desc, "BANK%.2d", (int)(handler_address - (FPTR)SMH_BANK1) + 1);
11186            }
901811187            else
901911188            {
9020               switch(handlerAddress)
11189               switch(handler_address)
902111190               {
902211191                  case (FPTR)SMH_NOP:      strcpy(desc, "NOP   ");   break;
902311192                  case (FPTR)SMH_RAM:      strcpy(desc, "RAM   ");   break;
902411193                  case (FPTR)SMH_ROM:      strcpy(desc, "ROM   ");   break;
9025                  default:               strcpy(desc, "CUSTOM");   break;
11194                  default:            strcpy(desc, "CUSTOM");   break;
902611195               }
902711196            }
902811197         }
902911198         else
9030            sprintf(desc, "CPU%.2d ", region->targetIdx);
11199            sprintf(desc, "CPU%.2d ", region->target_idx);
903111200
903211201         sprintf(region->name,   "%.*X-%.*X %s",
9033                           cpuInfoList[region->targetIdx].addressCharsNeeded,
9034                           region->address,
9035                           cpuInfoList[region->targetIdx].addressCharsNeeded,
9036                           region->address + region->length - 1,
11202                           cpu_info_list[region->target_idx].address_chars_needed, region->address,
11203                           cpu_info_list[region->target_idx].address_chars_needed, region->address + region->length - 1,
903711204                           desc);
903811205      }
903911206      break;
904011207
9041      case kRegionType_Memory:
11208      case kRegionType_Memory:   /* unused? */
904211209         sprintf(region->name, "%.8X-%.8X MEMORY", region->address, region->address + region->length - 1);
904311210         break;
904411211
904511212      default:
904611213         sprintf(region->name, "UNKNOWN");
9047         break;
904811214   }
904911215}
905011216
9051/*-----------------------------------------------------------------------------------
9052  AllocateSearchRegions - free memory for search region then realloc if searchable
9053-----------------------------------------------------------------------------------*/
11217/*-------------------------------------------------------------------------------------
11218  allocate_search_regions - free memory for search region then realloc if searchable
11219-------------------------------------------------------------------------------------*/
905411220
9055static void AllocateSearchRegions(SearchInfo * info)
11221static void allocate_search_regions(search_info *info)
905611222{
9057   int   i;
11223   int i;
905811224
9059   info->backupValid = 0;
9060   info->numResults = 0;
11225   info->backup_valid   = 0;
11226   info->num_results   = 0;
906111227
9062   for(i = 0; i < info->regionListLength; i++)
11228   for(i = 0; i < info->region_list_length; i++)
906311229   {
9064      SearchRegion   * region;
11230      search_region *region;
906511231
9066      region = &info->regionList[i];
11232      region            = &info->region_list[i];
11233      region->num_results   = 0;
906711234
9068      region->numResults = 0;
9069
907011235      free(region->first);
907111236      free(region->last);
907211237      free(region->status);
9073      free(region->backupLast);
9074      free(region->backupStatus);
11238      free(region->backup_last);
11239      free(region->backup_status);
907511240
907611241      if(region->flags & kRegionFlag_Enabled)
907711242      {
9078         region->first =         malloc(region->length);
9079         region->last =         malloc(region->length);
9080         region->status =      malloc(region->length);
9081         region->backupLast =   malloc(region->length);
9082         region->backupStatus =   malloc(region->length);
11243         region->first         = malloc(region->length);
11244         region->last         = malloc(region->length);
11245         region->status         = malloc(region->length);
11246         region->backup_last      = malloc(region->length);
11247         region->backup_status   = malloc(region->length);
908311248
9084         if(!region->first || !region->last || !region->status || !region->backupLast || !region->backupStatus)
9085         {
9086            free(region->first);
9087            free(region->last);
9088            free(region->status);
9089            free(region->backupLast);
9090            free(region->backupStatus);
9091
9092            region->first =         NULL;
9093            region->last =         NULL;
9094            region->status =      NULL;
9095            region->backupLast =   NULL;
9096            region->backupStatus =   NULL;
9097
9098            region->flags &= ~kRegionFlag_Enabled;
9099         }
11249         if(region->first == NULL || region->last == NULL || region->status == NULL || region->backup_last == NULL || region->backup_status == NULL)
11250            fatalerror(   "cheat: [search region] memory allocation error\n"
11251                     "   ----- %s -----\n"
11252                     "   first         = %p\n"
11253                     "   last         = %p\n"
11254                     "   status         = %p\n"
11255                     "   backup_last      = %p\n"
11256                     "   backup_status   = %p\n",
11257                     region->name,
11258                     region->first, region->last, region->status, region->backup_last, region->backup_status);
910011259      }
910111260      else
910211261      {
9103         region->first =         NULL;
9104         region->last =         NULL;
9105         region->status =      NULL;
9106         region->backupLast =   NULL;
9107         region->backupStatus =   NULL;
11262         region->first         = NULL;
11263         region->last         = NULL;
11264         region->status         = NULL;
11265         region->backup_last      = NULL;
11266         region->backup_status   = NULL;
910811267      }
910911268   }
911011269}
911111270
9112/*---------------------
9113  BuildSearchRegions
9114---------------------*/
11271/*--------------------------------------------------------------
11272  build_search_regions - build serach regions from memory map
11273--------------------------------------------------------------*/
911511274
9116static void BuildSearchRegions(running_machine *machine, SearchInfo * info)
11275static void build_search_regions(running_machine *machine, search_info *info)
911711276{
911811277   info->comparison = kSearchComparison_EqualTo;
911911278
9120   DisposeSearchRegions(info);
11279   /* 1st, free all search regions in current search_info */
11280   dispose_search_reigons(info);
912111281
9122   switch(info->targetType)
11282   /* 2nd, set parameters from memory map */
11283   switch(info->target_type)
912311284   {
912411285      case kRegionType_CPU:
912511286      {
9126         if(info->searchSpeed == kSearchSpeed_AllMemory)
11287         if(info->search_speed == ksearch_speed_AllMemory)
912711288         {
9128            UINT32         length = cpuInfoList[info->targetIdx].addressMask + 1;
9129            SearchRegion   * region;
11289            UINT32         length = cpu_info_list[info->target_idx].address_mask + 1;
11290            search_region   *region;
913011291
9131            info->regionList = calloc(sizeof(SearchRegion), 1);
9132            info->regionListLength = 1;
9133            region = info->regionList;
11292            info->region_list         = calloc(sizeof(search_region), 1);
11293            info->region_list_length   = 1;
913411294
9135            region->address = 0;
9136            region->length = length;
11295            region               = info->region_list;
11296            region->address         = 0;
11297            region->length         = length;
11298            region->target_idx      = info->target_idx;
11299            region->target_type      = info->target_type;
11300            region->write_handler   = NULL;
11301            region->first         = NULL;
11302            region->last         = NULL;
11303            region->status         = NULL;
11304            region->backup_last      = NULL;
11305            region->backup_status   = NULL;
11306            region->flags         = kRegionFlag_Enabled;
913711307
9138            region->targetIdx = info->targetIdx;
9139            region->targetType = info->targetType;
9140            region->writeHandler = NULL;
9141
9142            region->first = NULL;
9143            region->last = NULL;
9144            region->status = NULL;
9145
9146            region->backupLast = NULL;
9147            region->backupStatus = NULL;
9148
9149            region->flags = kRegionFlag_Enabled;
9150
9151            SetSearchRegionDefaultName(region);
11308            set_search_region_default_name(region);
915211309         }
915311310         else
915411311         {
9155            if(info->targetIdx < cpu_gettotalcpu())
11312            if(VALID_CPU(info->target_idx))
915611313            {
9157               const address_map         * map = NULL;
9158               const address_map_entry         * entry;
9159               SearchRegion                  * traverse;
9160               int                           count = 0;
11314               int                     count = 0;
11315               const address_map         *map = NULL;
11316               const address_map_entry      *entry;
11317               search_region            *traverse;
916111318
9162               map = memory_get_address_map(info->targetIdx, ADDRESS_SPACE_PROGRAM);
9163               for (entry = map->entrylist; entry != NULL; entry = entry->next)
9164                  if (entry->write.generic)
11319               map = memory_get_address_map(info->target_idx, ADDRESS_SPACE_PROGRAM);
11320
11321               for(entry = map->entrylist; entry != NULL; entry = entry->next)
11322                  if(entry->write.generic)
916511323                     count++;
916611324
9167               info->regionList = calloc(sizeof(SearchRegion), count);
9168               info->regionListLength = count;
9169               traverse = info->regionList;
11325               info->region_list         = calloc(sizeof(search_region), count);
11326               info->region_list_length   = count;
11327               traverse               = info->region_list;
917011328
9171               for (entry = map->entrylist; entry != NULL; entry = entry->next)
11329               for(entry = map->entrylist; entry != NULL; entry = entry->next)
917211330               {
917311331                  if (entry->write.generic)
917411332                  {
9175                     UINT32   length = (entry->addrend - entry->addrstart) + 1;
11333                     UINT32 length = (entry->addrend - entry->addrstart) + 1;
917611334
9177                     traverse->address = entry->addrstart;
9178                     traverse->length = length;
11335                     traverse->address      = entry->addrstart;
11336                     traverse->length      = length;
11337                     traverse->target_idx   = info->target_idx;
11338                     traverse->target_type   = info->target_type;
11339                     traverse->write_handler   = entry;
11340                     traverse->first         = NULL;
11341                     traverse->last         = NULL;
11342                     traverse->status      = NULL;
11343                     traverse->backup_last   = NULL;
11344                     traverse->backup_status   = NULL;
11345                     traverse->flags         = default_enable_region(machine, traverse, info) ? kRegionFlag_Enabled : 0;
917911346
9180                     traverse->targetIdx = info->targetIdx;
9181                     traverse->targetType = info->targetType;
9182                     traverse->writeHandler = entry;
11347                     set_search_region_default_name(traverse);
918311348
9184                     traverse->first = NULL;
9185                     traverse->last = NULL;
9186                     traverse->status = NULL;
9187
9188                     traverse->backupLast = NULL;
9189                     traverse->backupStatus = NULL;
9190
9191                     traverse->flags = DefaultEnableRegion(machine, traverse, info) ? kRegionFlag_Enabled : 0;
9192
9193                     SetSearchRegionDefaultName(traverse);
9194
919511349                     traverse++;
919611350                  }
919711351               }
r2762r2763
920011354      }
920111355      break;
920211356
9203      case kRegionType_Memory:
11357      case kRegionType_Memory:   /* unused? */
920411358         break;
920511359   }
920611360}
r2762r2763
928311437      {   94,      0x00000B00,   kCustomField_None },
928411438      {   95,      0x00000D00,   kCustomField_SubtractOne },
928511439      {   100,   0x20800000,   kCustomField_None },
9286      {   101,   0x20000001,   kCustomField_None },
11440      {   101,   0x20800001,   kCustomField_None },
928711441      {   102,   0x20800000,   kCustomField_None },
9288      {   103,   0x20000001,   kCustomField_None },
11442      {   103,   0x20800001,   kCustomField_None },
928911443      {   110,   0x40800000,   kCustomField_None },
9290      {   111,   0x40000001,   kCustomField_None },
11444      {   111,   0x40800001,   kCustomField_None },
929111445      {   112,   0x40800000,   kCustomField_None },
9292      {   113,   0x40000001,   kCustomField_None },
11446      {   113,   0x40800001,   kCustomField_None },
929311447      {   120,   0x63000001,   kCustomField_None },
929411448      {   121,   0x63000001,   kCustomField_DontApplyCPUField | kCustomField_SetBit },
929511449      {   122,   0x63000001,   kCustomField_DontApplyCPUField | kCustomField_ClearBit },
r2762r2763
929811452      {   -1,      0x00000000,   kCustomField_End }
929911453   };
930011454
9301   const struct ConversionTable   * traverse = kConversionTable;
9302   UINT32               newCode;
9303   UINT8               linkCheat = 0;
11455   const struct ConversionTable * traverse = kConversionTable;
930411456
9305   /* ----- convert link cheats ----- */
11457   UINT8   linkCheat = 0;
11458   UINT32   newCode;
11459
11460   /* convert link cheats */
930611461   if((code >= 500) && (code <= 699))
930711462   {
930811463      linkCheat = 1;
930911464      code -= 500;
931011465   }
931111466
9312   /* ----- look up code ----- */
11467   /* look up code */
931311468   while(traverse->oldCode >= 0)
931411469   {
931511470      if(code == traverse->oldCode)
r2762r2763
931911474
932011475   logerror("ConvertOldCode: %d not found\n", code);
932111476
9322   /* ----- not found ----- */
11477   /* not found */
932311478   *extendData = 0;
932411479   return 0;
932511480
9326   /* ----- found ----- */
11481   /* found */
932711482   foundCode:
932811483
932911484   newCode = traverse->newCode;
933011485
9331   /* ----- add in the CPU field ----- */
11486   /* add in the CPU field */
933211487   if(!(traverse->customField & kCustomField_DontApplyCPUField))
933311488      newCode = (newCode & ~0x1F000000) | ((cpu << 24) & 0x1F000000);
933411489
9335   /* ----- hack-ish, subtract one from data field for x5 user select ----- */
11490   /* hack-ish, subtract one from data field for x5 user select */
933611491   if(traverse->customField & kCustomField_SubtractOne)
933711492      (*data)--;   // yaay for C operator precedence
933811493
9339   /* ----- set up the extend data ----- */
11494   /* set up the extend data */
934011495   if(traverse->customField & kCustomField_BitMask)
934111496      *extendData = *data;
934211497   else
r2762r2763
935111506   return newCode;
935211507}
935311508
9354/*--------------------------------------------------------------------------------
9355  HandleLocalCommandCheat - get special code which is not added into cheat list
9356--------------------------------------------------------------------------------*/
11509/*-------------------
11510  ConvertToNewCode
11511-------------------*/
935711512
9358static void HandleLocalCommandCheat(running_machine *machine, UINT32 type, UINT32 address, UINT32 data, UINT32 extendData, char * name, char * description)
11513static int ConvertToNewCode(CheatAction * action)
935911514{
9360   switch(EXTRACT_FIELD(type, LocationType))
11515   int newType = 0;
11516
11517   if(EXTRACT_FIELD(action->type, LocationType) == kLocation_IndirectIndexed)
11518      SET_FIELD(newType, CPURegion, EXTRACT_FIELD(action->type, LocationParameterCPU));
11519   else if(EXTRACT_FIELD(action->type, LocationType) != kLocation_Custom)
11520      SET_FIELD(newType, CPURegion, EXTRACT_FIELD(action->type, LocationParameter));
11521
11522   if(TEST_FIELD(action->type, UserSelectEnable))
11523      SET_FIELD(newType, CodeType, kCodeType_VWrite);
11524   else if(EXTRACT_FIELD(action->type, LocationType) == kLocation_IndirectIndexed)
11525   {   SET_FIELD(newType, CodeType, kCodeType_IWrite);
11526      SET_FIELD(newType, IndexSize, EXTRACT_FIELD(action->type, LocationParameterOption)); }
11527   else
11528   {   SET_FIELD(newType, CodeType, kCodeType_PDWWrite);
11529      SET_FIELD(newType, IndexSize, kSearchSize_32Bit); }
11530
11531   SET_FIELD(newType, AddressSize, EXTRACT_FIELD(action->type, BytesUsed));
11532
11533   if(TEST_FIELD(action->type, LinkEnable))
11534      SET_FIELD(newType, Link, kLink_Link);
11535
11536   if(TEST_FIELD(action->type, RestorePreviousValue))
11537      SET_MASK_FIELD(newType, RestoreValue);
11538
11539   if(EXTRACT_FIELD(action->type, Prefill))
11540      SET_MASK_FIELD(newType, PrefillEnable);
11541
11542   if(!EXTRACT_FIELD(action->type, Type) && EXTRACT_FIELD(action->type, TypeParameter))
11543      SET_MASK_FIELD(newType, DelayEnable);
11544
11545   if(TEST_FIELD(action->type, OneShot))
11546      SET_MASK_FIELD(newType, OneShot);
11547
11548   return newType;
11549}
11550
11551/*--------------------------
11552  HandleLocalCommandCheat
11553--------------------------*/
11554
11555static void HandleLocalCommandCheat(running_machine *machine, int cpu, int type, int address, int data, UINT8 format)
11556{
11557   int command = 0;
11558
11559   if(format != 1)
936111560   {
9362      case kLocation_Custom:
9363         switch(EXTRACT_FIELD(type, LocationParameter))
9364         {
9365            /* ----- activation key ----- */
9366            case kCustomLocation_AssignActivationKey:
9367            {
9368               if(address < cheatListLength)
9369               {
9370                  CheatEntry   * entry = &cheatList[address];
11561      switch(EXTRACT_FIELD(type, LocationParameter))
11562      {
11563         case kCustomLocation_AssignActivationKey:
11564            command = kCustomCode_ActivationKey1;
937111565
9372                  if(!TEST_FIELD(type, OneShot))
9373                  {
9374                     /* ----- 1st activation key ----- */
9375                     entry->activationKey1 = data;
9376                     entry->flags |= kCheatFlag_HasActivationKey1;
9377                  }
9378                  else
9379                  {
9380                     /* ----- 2nd activation key ----- */
9381                     entry->activationKey2 = data;
9382                     entry->flags |= kCheatFlag_HasActivationKey2;
9383                  }
9384               }
9385            }
11566            if(TEST_FIELD(type, OneShot))
11567               command = kCustomCode_ActivationKey2;
938611568            break;
938711569
9388            /* ----- pre-enable ----- */
9389            case kCustomLocation_Enable:
9390            {
9391               if(address < cheatListLength)
9392               {
9393                  CheatEntry   * entry = &cheatList[address];
11570         case kCustomLocation_Enable:
11571            command = kCustomCode_PreEnable;
11572            break;
939411573
9395                  ActivateCheat(entry);
9396               }
9397            }
11574         case kCustomLocation_Overclock:
11575            command = kCustomCode_OverClock;
939811576            break;
939911577
9400            /* ----- over-clock ----- */
9401            case kCustomLocation_Overclock:
9402            {
9403               if(address < cpu_gettotalcpu())
9404               {
9405                  double   overclock = data;
11578         case kCustomLocation_RefreshRate:
11579            command = kCustomCode_RefreshRate;
11580            break;
940611581
9407                  overclock /= 65536.0;
11582         default:
11583            return;
11584      }
11585   }
11586   else
11587      command = EXTRACT_FIELD(type, CodeType);
940811588
9409                  cpunum_set_clockscale(machine, address, overclock);
9410               }
9411            }
9412            break;
11589   switch(command)
11590   {
11591      case kCustomCode_ActivationKey1:
11592      case kCustomCode_ActivationKey2:
11593         if(address < cheatListLength)
11594         {
11595            CheatEntry * entry = &cheatList[address];
941311596
9414            /* ----- refresh rate ----- */
9415            case kCustomLocation_RefreshRate:
11597            if(command == kCustomCode_ActivationKey1)
941611598            {
9417               int width  = video_screen_get_width(machine->primary_screen);
9418               int height = video_screen_get_height(machine->primary_screen);
9419               const rectangle *visarea = video_screen_get_visible_area(machine->primary_screen);
9420               double refresh = data / 65536.0;
9421
9422               video_screen_configure(machine->primary_screen, width, height, visarea, HZ_TO_ATTOSECONDS(refresh));
11599               entry->activationKey2 = data;
11600               entry->flags |= kCheatFlag_HasActivationKey2;
942311601            }
9424            break;
11602            else
11603            {
11604               entry->activationKey1 = data;
11605               entry->flags |= kCheatFlag_HasActivationKey1;
11606            }
942511607         }
942611608         break;
11609
11610      case kCustomCode_PreEnable:
11611         if(address < cheatListLength)
11612         {
11613            CheatEntry * entry = &cheatList[address];
11614
11615            ActivateCheat(entry);
11616
11617            if(data && (data < entry->actionListLength))
11618               entry->selection = data;
11619         }
11620         break;
11621
11622      case kCustomCode_OverClock:
11623         if(VALID_CPU(cpu))
11624         {
11625            double   overclock = data / 65536.0;
11626
11627            cpunum_set_clockscale(machine, address, overclock);
11628         }
11629         break;
11630
11631      case kCustomCode_RefreshRate:
11632         {
11633            int width      = video_screen_get_width(machine->primary_screen);
11634            int height      = video_screen_get_height(machine->primary_screen);
11635
11636            const rectangle   *visarea   = video_screen_get_visible_area(machine->primary_screen);
11637            double         refresh      = data / 65536.0;
11638
11639            video_screen_configure(machine->primary_screen, width, height, visarea, HZ_TO_ATTOSECONDS(refresh));
11640         }
11641         break;
942711642   }
942811643}
942911644
11645/*----------------------------------------------------
11646  LoadCheatOption - load cheat option from database
11647----------------------------------------------------*/
11648
11649static void LoadCheatOption(char * fileName)
11650{
11651   static char      buf[2048];
11652   mame_file *      theFile;
11653   file_error      filerr;
11654   cheat_format *   format = &cheat_format_table[0];
11655
11656   /* open the database */
11657   filerr = mame_fopen(SEARCHPATH_CHEAT, fileName, OPEN_FLAG_READ, &theFile);
11658
11659   if(filerr != FILERR_NONE)
11660   {
11661      messageType      = kCheatMessage_FailedToLoadDatabase;
11662      messageTimer   = DEFAULT_MESSAGE_TIME;
11663      return;
11664   }
11665
11666   while(mame_fgets(buf, 2048, theFile))
11667   {
11668      char preCommand[9];
11669
11670      if(sscanf(buf, format->format_string, preCommand) == format->arguments_matched)
11671      {
11672         if(strlen(preCommand) == format->length_matched)
11673         {
11674            sscanf(preCommand, "%X", &cheatOptions);
11675            messageType      = kCheatMessage_ReloadCheatOption;
11676            messageTimer   = DEFAULT_MESSAGE_TIME;
11677         }
11678      }
11679   }
11680
11681   mame_fclose(theFile);
11682}
11683
943011684/*------------------------------------------------
9431  LoadCheatFile - load cheat code from database
11685  LoadCheatCode - load cheat code from database
943211686------------------------------------------------*/
943311687
9434static void LoadCheatFile(running_machine *machine, char * fileName)
11688static void LoadCheatCode(running_machine *machine, char * fileName)
943511689{
11690   enum{
11691      kFormatLevel_New = 1,
11692      kFormatLevel_Standard,
11693      kFormatLevel_Old };
11694
11695   char      buf[2048];
943611696   mame_file   * theFile;
9437   file_error filerr;
9438   char      formatString[256];
9439   char      oldFormatString[256];
9440   char      buf[2048];
9441   int         recordNames = 0;
11697   file_error   filerr;
944211698
9443   /* ----- open the database ----- */
11699   /* open the database */
944411700   filerr = mame_fopen(SEARCHPATH_CHEAT, fileName, OPEN_FLAG_READ, &theFile);
944511701
944611702   if(filerr != FILERR_NONE)
r2762r2763
944811704
944911705   foundCheatDatabase = 1;
945011706
9451   /* ----- make the format strings ----- */
9452#ifdef MESS
9453   sprintf(formatString, ":%s:%s", machine->gamedrv->name, "%x:%x:%x:%x:%x:%[^:\n\r]:%[^:\n\r]");
9454   sprintf(oldFormatString, "%s:%s", machine->gamedrv->name, "%x:%d:%x:%x:%d:%[^:\n\r]:%[^:\n\r]");
9455#else
9456   sprintf(formatString, ":%s:%s", machine->gamedrv->name, "%x:%x:%x:%x:%[^:\n\r]:%[^:\n\r]");
9457   sprintf(oldFormatString, "%s:%s", machine->gamedrv->name, "%d:%x:%x:%d:%[^:\n\r]:%[^:\n\r]");
9458#endif
9459
9460   /* ----- get a line from database ----- */
11707   /* get a line from database */
946111708   while(mame_fgets(buf, 2048, theFile))
946211709   {
9463      int         type;
9464      int         address;
9465      int         data;
9466      int         extendData;
9467      char      name[256];
9468      char      description[256];
11710      int         i;
946911711#ifdef MESS
947011712      int         crc;
947111713#endif
9472
9473      int         argumentsMatched;
9474      UINT32      command;
9475
11714      int         type = 0;
11715      int         address = 0;
11716      int         data = 0;
11717      int         extendData = 0;
11718      int         argumentsMatched = 0;
11719      int         formatLevel = 0;
11720      int         oldCPU = 0;
11721      int         oldCode = 0;
11722      char      name[16] = { 0 };
11723      char      preData[16] = { 0 };
11724      char      preExtendData[16] = { 0 };
11725      char      description[256] = { 0 };
11726      char      comment[256] = { 0 };
947611727      CheatEntry   * entry;
947711728      CheatAction   * action;
947811729
9479      /* ----- get command line ----- */
9480      argumentsMatched = sscanf(buf, ":_command:%8X", &command);
9481
9482      if(argumentsMatched == 1)
11730      /* scan and check format */
11731      for(i = 1; i < 4; i++)
948311732      {
9484         /* ----- set cheatOptions from command line ----- */
9485         cheatOptions = command;
11733         cheat_format * format = &cheat_format_table[i];
948611734
9487         continue;
9488      }
9489
9490      /* ----- get cheat code ----- */
9491      name[0] = 0;
9492      description[0] = 0;
9493
11735         /* scan a parameter */
11736         switch(i)
11737         {
11738            case kFormatLevel_New:
11739            case kFormatLevel_Standard:
949411740#ifdef MESS
9495      argumentsMatched = sscanf(buf, formatString, &crc, &type, &address, &data, &extendData, name, description);
11741               argumentsMatched = sscanf(buf, format->format_string, name, &crc, &type, &address, preData, preExtendData, description, comment);
949611742#else
9497      argumentsMatched = sscanf(buf, formatString, &type, &address, &data, &extendData, name, description);
11743               argumentsMatched = sscanf(buf, format->format_string, name, &type, &address, preData, preExtendData, description, comment);
949811744#endif
11745               break;
949911746
11747            case kFormatLevel_Old:
950011748#ifdef MESS
9501      if(argumentsMatched < 5)
11749               argumentsMatched = sscanf(buf, format->format_string, &crc, name, &oldCPU, &address, &data, &oldCode, description, comment);
950211750#else
9503      if(argumentsMatched < 4)
11751               argumentsMatched = sscanf(buf, format->format_string, name, &oldCPU, &address, &data, &oldCode, description, comment);
950411752#endif
9505      {
9506         int   oldCPU;
9507         int   oldCode;
11753         }
950811754
11755         /* NOTE : description and comment are not always needed */
11756         if(argumentsMatched < format->arguments_matched)
11757            continue;
11758
950911759#ifdef MESS
9510         argumentsMatched = sscanf(buf, oldFormatString, &crc, &oldCPU, &address, &data, &oldCode, name, description);
11760         /* check name */
11761         if(TEST_FIELD(cheatOptions, SharedCode) && strcmp(machine->gamedrv->parent, "0"))
11762         {
11763            if(strcmp(name, machine->gamedrv->parent))
11764               break;
11765         }
11766         else
11767#endif
11768         if(strcmp(name, machine->gamedrv->name))
11769            break;
11770#ifdef MESS
11771         /* check crc */
11772         if(MatchesCRCTable(crc) == 0)
11773            break;
11774#endif
11775         if(i != kFormatLevel_Old)
11776         {
11777            UINT8 hasError = 0;
951111778
9512         if(argumentsMatched < 5)
9513#else
9514         argumentsMatched = sscanf(buf, oldFormatString, &oldCPU, &address, &data, &oldCode, name, description);
11779            /* check the length of data and extendData */
11780            if(strlen(preData) != format->length_matched)
11781            {
11782               logerror("cheat - LoadCheatFile : %s has invalid extend data field length\n", description);
11783               messageType = kCheatMessage_WrongCode;
11784               hasError++;
11785            }
951511786
9516         if(argumentsMatched < 4)
9517#endif
9518            /* ----- if it is not a cheat code, continue ----- */
9519            continue;
11787            if(strlen(preExtendData) != format->length_matched)
11788            {
11789               logerror("cheat - LoadCheatFile : %s has invalid data field length\n", description);
11790               messageType = kCheatMessage_WrongCode;
11791               hasError++;
11792            }
11793
11794            if(hasError)
11795               continue;
11796            else
11797            {
11798               sscanf(preData, "%X", &data);
11799               sscanf(preExtendData, "%X", &extendData);
11800            }
11801         }
952011802         else
11803            type = ConvertOldCode(oldCode, oldCPU, &data, &extendData);
11804
11805         /* matched! */
11806         formatLevel = i;
11807         break;
11808      }
11809
11810      /* attemp to get next line if unmatched */
11811      if(formatLevel == 0)
11812         continue;
11813
11814      //logerror("cheat: processing %s\n", buf);
11815
11816      /* handle command code */
11817      if(formatLevel == kFormatLevel_New)
11818      {
11819         if(EXTRACT_FIELD(type, CPURegion) == CUSTOM_CODE && EXTRACT_FIELD(type, CodeType) >= kCustomCode_ActivationKey1)
952111820         {
9522#ifdef MESS
9523            if(!MatchesCRCTable(crc))
9524               continue;
9525#endif
9526            /* ----- convert the old code to the new format ----- */
9527            if(TEST_FIELD(cheatOptions, LoadOldFormat))
9528               type = ConvertOldCode(oldCode, oldCPU, &data, &extendData);
9529//                  continue;
11821            // logerror("cheat: cheat line removed\n", buf);
11822            HandleLocalCommandCheat(machine, EXTRACT_FIELD(type, CPUIndex), type, address, data, formatLevel);
11823            continue;
953011824         }
953111825      }
953211826      else
953311827      {
9534#ifdef MESS
9535         if(!MatchesCRCTable(crc))
9536            continue;
9537#endif
11828         if(   EXTRACT_FIELD(type, LocationType) == kLocation_Custom &&
11829            EXTRACT_FIELD(type, LocationParameter) <= kCustomLocation_AssignActivationKey)
11830            {
11831               HandleLocalCommandCheat(machine, EXTRACT_FIELD(type, LocationParameter), type, address, data, formatLevel);
11832               continue;
11833            }
953811834      }
953911835
9540      //logerror("cheat: processing %s\n", buf);
9541
9542      if(TEST_FIELD(type, RemoveFromList))
11836      /***** ENTRY *****/
11837      if(EXTRACT_FIELD(type, Link) == kLink_Master)
954311838      {
9544         //logerror("cheat: cheat line removed\n", buf);
11839         /* 1st (master) code in an entry */
11840         ResizeCheatList(cheatListLength + 1);
954511841
9546         HandleLocalCommandCheat(machine, type, address, data, extendData, name, description);
11842         if(cheatListLength == 0)
11843         {
11844            logerror("cheat - LoadCheatFile: cheat list resize failed; bailing\n");
11845            goto bail;
11846         }
11847
11848         entry = &cheatList[cheatListLength - 1];
11849
11850         entry->name = create_string_copy(description);
11851
11852         if(argumentsMatched == cheat_format_table[formatLevel].comment_matched)
11853            entry->comment = create_string_copy(comment);
954711854      }
954811855      else
954911856      {
9550         if(TEST_FIELD(type, LinkEnable))
11857         /* 2nd or later (link) code in an entry */
11858         if(cheatListLength == 0)
955111859         {
9552            /* ----- if 1st code is the link code, it is invalid ----- */
9553            if(cheatListLength == 0)
9554            {
9555               logerror("LoadCheatFile: first cheat found was link cheat; bailing\n");
11860            logerror("cheat - LoadCheatFile: first cheat found was link cheat; bailing\n");
11861            goto bail;
11862         }
955611863
9557               goto bail;
9558            }
11864         entry = &cheatList[cheatListLength - 1];
11865      }
955911866
9560            //logerror("cheat: doing link cheat\n");
11867      /***** ACTION *****/
11868      ResizeCheatActionList(&cheatList[cheatListLength - 1], entry->actionListLength + 1);
956111869
9562            entry = &cheatList[cheatListLength - 1];
9563         }
9564         else
9565         {
9566            /* ----- go to the next cheat entry ----- */
9567            ResizeCheatList(cheatListLength + 1);
11870      if(entry->actionListLength == 0)
11871      {
11872         logerror("cheat - LoadCheatFile: action list resize failed; bailing\n");
11873         goto bail;
11874      }
956811875
9569            //logerror("cheat: doing normal cheat\n");
11876      action = &entry->actionList[entry->actionListLength - 1];
957011877
9571            if(cheatListLength == 0)
9572            {
9573               logerror("LoadCheatFile: cheat list resize failed; bailing\n");
11878      action->flags = 0;
11879      action->type = type;
11880      action->address = action->originalAddress = address;
11881      action->data = action->originalDataField = data;
11882      action->extendData = extendData;
11883      action->optionalName = create_string_copy(description);
11884      action->lastValue = NULL;
957411885
9575               goto bail;
9576            }
11886      if(formatLevel != kFormatLevel_New)
11887         action->flags |= kActionFlag_OldFormat;
11888   }
957711889
9578            entry = &cheatList[cheatListLength - 1];
11890   bail:
957911891
9580            /* ----- copy the code name ----- */
9581            entry->name = CreateStringCopy(name);
11892   /* close the database */
11893   mame_fclose(theFile);
11894}
958211895
9583            /* ----- copy the description if we got it ----- */
9584            if(argumentsMatched == 6)
9585               entry->comment = CreateStringCopy(description);
11896/*--------------------------------------------------------------------------------
11897  LoadUserDefinedSearchRegion - load user region code and rebuild search region
11898--------------------------------------------------------------------------------*/
958611899
9587            recordNames = 0;
11900static void LoadUserDefinedSearchRegion(running_machine *machine, char * fileName)
11901{
11902   int      count = 0;
11903   char   buf[2048];
958811904
9589            /* ----- try to copy the label if label-selection ------ */
9590            if(   (EXTRACT_FIELD(type, LocationType) == kLocation_Custom) &&
9591               (EXTRACT_FIELD(type, LocationParameter) == kCustomLocation_Select))
9592                  recordNames = 1;
9593         }
11905   search_info    *info = get_current_search();
11906   mame_file *      theFile;
11907   file_error      filerr;
11908   cheat_format *   format = &cheat_format_table[4];
959411909
9595         ResizeCheatActionList(&cheatList[cheatListLength - 1], entry->actionListLength + 1);
11910   /* 1st, free all search regions in current search_info */
11911   dispose_search_reigons(info);
959611912
9597         if(entry->actionListLength == 0)
11913   /* 2nd, attempt to open the memorymap file */
11914   filerr = mame_fopen(SEARCHPATH_CHEAT, fileName, OPEN_FLAG_READ, &theFile);
11915
11916   if(filerr != FILERR_NONE)
11917   {
11918      info->region_list_length   = 0;
11919      messageType            = kCheatMessage_FailedToLoadDatabase;
11920      messageTimer         = DEFAULT_MESSAGE_TIME;
11921      return;
11922   }
11923
11924   /* 3rd, scan parameters from the file */
11925   while(mame_fgets(buf, 2048, theFile))
11926   {
11927#ifdef MESS
11928      int      crc;
11929#endif
11930      int      cpu;
11931      int      space;
11932      int      start;
11933      int      end;
11934      int      status;
11935      char   name[9];
11936      char   description[64];
11937
11938      cpu_region_info *cpu_info;
11939      search_region   *region;
11940
11941      description[0] = 0;
11942
11943#ifdef MESS
11944      if(sscanf(buf, format->format_string, name, &crc, &cpu, &space, &start, &end, &status, description) < format->arguments_matched)
11945#else
11946      if(sscanf(buf, format->format_string, name, &cpu, &space, &start, &end, &status, description) < format->arguments_matched)
11947#endif
11948         continue;
11949      else
11950      {
11951#ifdef MESS
11952         if(!MatchesCRCTable(crc))
11953            continue;
11954#endif
11955         if(cpu != info->target_idx)
11956            continue;
11957      }
11958
11959      cpu_info = get_cpu_info(cpu);
11960
11961      /* check parameters */
11962      {
11963         switch(space)
959811964         {
9599            logerror("LoadCheatFile: action list resize failed; bailing\n");
11965            case kAddressSpace_Program:         // standard program space
11966            case kAddressSpace_DirectMemory:   // direct memory access for standard program space
11967               /* check length */
11968               if(start >= end)
11969               {
11970                  logerror("cheat - LoadUserDefinedSearchRegion : invalid length (start : %X >= end : %X) \n", start, end);
11971                  continue;
11972               }
960011973
9601            goto bail;
11974               /* check bound */
11975               if(end > cpu_info->address_mask)
11976               {
11977                  logerror("cheat - LoadUserDefinedSearchRegion : end address (%X) is out of range\n", end);
11978                  continue;
11979               }
11980               break;
11981
11982            case kAddressSpace_DataSpace:   // data space
11983            case kAddressSpace_IOSpace:      // I/O space
11984               // underconstruction...
11985               break;
11986
11987            default:
11988               logerror("cheat - LoadUserDefinedSearchRegion : %X is invalid space\n", space);
11989               continue;
960211990         }
960311991
9604         action = &entry->actionList[entry->actionListLength - 1];
11992         /* check status */
11993         if(status > 1)
11994         {
11995            logerror("cheat - LoadUserDefinedSearchRegion : %X is invalid status\n", status);
11996            continue;
11997         }
11998      }
960511999
9606         action->type = type;
9607         action->address = address;
9608         action->data = data;
9609         action->originalDataField = data;
9610         action->extendData = extendData;
12000      /* allocate memory for new search region */
12001      info->region_list = realloc(info->region_list, (count + 1) * sizeof(search_region));
961112002
9612         /* ----- copy the label if label-selection ------ */
9613         if(recordNames)
9614            action->optionalName = CreateStringCopy(name);
12003      if(!info->region_list)
12004      {
12005         /* memory allocation error */
12006         logerror("cheat - LoadUserDefinedSearchRegion: out of memory resizing search region\n");
12007         ui_popup_time(2, "out of memory while buiding user search region");
12008         info->region_list_length = 0;
12009         mame_fclose(theFile);
12010         return;
961512011      }
12012
12013      region = &info->region_list[count];
12014
12015      /* 4th, set region parameters from scaned data */
12016      region->address      = start;
12017      region->length      = end - start + 1;
12018      region->target_idx   = cpu;
12019
12020      if(!space)
12021      {
12022         region->target_type      = kRegionType_CPU;
12023         region->cached_pointer   = NULL;
12024      }
12025      else
12026      {
12027         region->target_type      = kRegionType_Memory;
12028         region->cached_pointer = GetMemoryRegionBasePointer(cpu, kAddressSpace_DirectMemory, start);
12029
12030         //logerror("pointer for %s : %p\n", description, region->cachedPointer);
12031      }
12032
12033      region->write_handler   = NULL;
12034      region->first         = NULL;
12035      region->last         = NULL;
12036      region->status         = NULL;
12037      region->backup_last      = NULL;
12038      region->backup_status   = NULL;
12039      region->flags         = status;
12040
12041      sprintf(region->name,   "%.*X-%.*X %s",
12042                        cpu_info->address_chars_needed, region->address,
12043                        cpu_info->address_chars_needed, region->address + region->length - 1,
12044                        description);
12045
12046      count++;
961612047   }
961712048
9618   bail:
12049   info->region_list_length = count;
961912050
9620   /* ----- close the database ----- */
12051   if(info->region_list_length)
12052   {
12053      messageType      = kCheatMessage_ReloadUserRegion;
12054      messageTimer   = DEFAULT_MESSAGE_TIME;
12055   }
12056
962112057   mame_fclose(theFile);
962212058}
962312059
r2762r2763
962512061  LoadCheatDatabase - get the database name then load it
962612062---------------------------------------------------------*/
962712063
9628static void LoadCheatDatabase(running_machine *machine)
12064static void LoadCheatDatabase(running_machine *machine, UINT8 flags)
962912065{
9630   char      buf[4096];
12066   UINT8      first = 1;
12067
12068   char      buf[256];
12069   char      data;
963112070   const char   * inTraverse;
963212071   char      * outTraverse;
963312072   char      * mainTraverse;
9634   int         first = 1;
9635   char      data;
963612073
963712074   cheatfile = options_get_string(mame_options(), OPTION_CHEAT_FILE);
963812075
9639   /* ----- set default database name as "cheat.dat" ----- */
9640   if (cheatfile[0] == 0)
12076   if (!cheatfile[0])
964112077      cheatfile = "cheat.dat";
964212078
9643   inTraverse = cheatfile;
9644   outTraverse = buf;
9645   mainTraverse = mainDatabaseName;
12079   inTraverse      = cheatfile;
12080   outTraverse      = buf;
12081   mainTraverse   = mainDatabaseName;
964612082
964712083   buf[0] = 0;
964812084
9649   /* ----- get database name ----- */
965012085   do
965112086   {
965212087      data = *inTraverse;
965312088
9654      /* ----- check separator or line end ----- */
9655      if((data == ';') || (data == 0))
12089      /* check separator or end */
12090      if(data == ';' || !data)
965612091      {
965712092         *outTraverse++ = 0;
965812093
r2762r2763
966112096
966212097         if(buf[0])
966312098         {
9664            /* ----- load database based on the name we gotten ----- */
9665            LoadCheatFile(machine, buf);
12099            /* load database based on the name we gotten */
12100            if(flags & kLoadFlag_CheatOption)
12101               LoadCheatOption(buf);
12102            if(flags & kLoadFlag_CheatCode)
12103               LoadCheatCode(machine, buf);
12104            if(flags & kLoadFlag_UserRegion)
12105               LoadUserDefinedSearchRegion(machine, buf);
966612106
9667            outTraverse =buf;
9668            buf[0] = 0;
9669            first = 0;
12107            outTraverse   = buf;
12108            buf[0]      = 0;
12109            first      = 0;
12110            break;
967012111         }
967112112      }
967212113      else
r2762r2763
968412125   UpdateAllCheatInfo();
968512126}
968612127
9687/*-----------------------------------------------------------------------------------------
9688  DisposeCheatDatabase - deactivate all cheats when reload database or exit cheat system
9689-----------------------------------------------------------------------------------------*/
12128/*---------------------------------------------------------------------------------------
12129  DisposeCheatDatabase - deactivate all cheats when reload a code or exit cheat system
12130---------------------------------------------------------------------------------------*/
969012131
969112132static void DisposeCheatDatabase(void)
969212133{
9693   int   i;
12134   int i;
969412135
9695   /* ----- first, turn all cheats "OFF" ----- */
12136   /* first, turn all cheats "OFF" */
969612137   for(i = 0; i < cheatListLength; i++)
969712138      TempDeactivateCheat(&cheatList[i]);
969812139
9699   /* ----- next, free memory for all cheat entries ----- */
12140   /* next, free memory for all cheat entries */
970012141   if(cheatList)
970112142   {
970212143      for(i = 0; i < cheatListLength; i++)
r2762r2763
971612157static void ReloadCheatDatabase(running_machine *machine)
971712158{
971812159   DisposeCheatDatabase();
9719   LoadCheatDatabase(machine);
12160   LoadCheatDatabase(machine, kLoadFlag_CheatCode);
972012161
9721   ui_popup_time(1, "Cheat Database reloaded");
12162   if(foundCheatDatabase)
12163      messageType   = kCheatMessage_ReloadCheatCode;
12164   else
12165      messageType   = kCheatMessage_FailedToLoadDatabase;
12166
12167   messageTimer   = DEFAULT_MESSAGE_TIME;
972212168}
972312169
9724/*---------------------------------------------------------------
9725  SaveCheat - save a code (normal code, activation key, option)
9726---------------------------------------------------------------*/
12170/*------------------------------------------------------
12171  SaveCheatCode - save a cheat code into the database
12172------------------------------------------------------*/
972712173
9728static void SaveCheat(running_machine *machine, CheatEntry * entry, int selection, int saveCode)
12174static void SaveCheatCode(running_machine *machine, CheatEntry * entry)
972912175{
9730   enum{
9731         normalCode = 0,
9732         activationKey,
9733         command,
9734      };
9735
9736   mame_file * theFile;
9737   file_error filerr;
9738   UINT32   i;
12176#ifdef MESS
12177   INT8   i;
12178   INT8   error = 0;
973912179   char   buf[4096];
974012180
9741   /* ----- check selected entry ----- */
9742   if((saveCode == normalCode) || (saveCode == activationKey))
12181   mame_file *   theFile;
12182   file_error   filerr;
12183
12184   if(!entry || !entry->actionList || ((entry->flags & kCheatFlag_Select) && entry->actionListLength == 1))
12185      error = 1;
12186
12187   /* open the database */
12188   if(!error)
974312189   {
9744      if(!entry || !entry->actionList)
9745         return;
12190      filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE, &theFile);
974612191
9747      if((saveCode == activationKey) && (entry->flags & kCheatFlag_Select) && !entry->actionListLength)
9748         return;
12192      if(!theFile)
12193         error = 1;
12194      else if(filerr != FILERR_NONE)
12195      {
12196         filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &theFile);
12197
12198         if(filerr != FILERR_NONE)
12199            error = 1;
12200      }
974912201   }
975012202
9751   /* ----- open the database ----- */
9752   filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE, &theFile);
12203   if(error)
12204   {
12205      messageType = kCheatMessage_FailedToSave;
12206      messageTimer = DEFAULT_MESSAGE_TIME;
12207      return;
12208   }
975312209
9754   /* ----- if fails to create, no save ----- */
9755   if(!theFile)
9756      return;
9757   if (filerr != FILERR_NONE)
12210   mame_fseek(theFile, 0, SEEK_END);
12211
12212   /* write the code to the database */
12213   for(i = 0; i < entry->actionListLength; i++)
975812214   {
9759      filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &theFile);
12215      UINT8      addressLength   = 8;
12216      char      * name;
12217      char      * bufTraverse   = buf;
976012218
9761      /* ----- if fails to create, no save ----- */
9762      if(filerr != FILERR_NONE)
12219      CheatAction   * action      = &entry->actionList[i];
12220
12221      /* get name */
12222      if(!i)
12223         name = entry->name;
12224      else
12225         name = action->optionalName;
12226
12227      /* get address length of CPU/Region */
12228      addressLength = get_address_length(EXTRACT_FIELD(action->type, CPURegion));
12229
12230      /* print format */
12231#ifdef MESS
12232      bufTraverse +=   sprintf(bufTraverse, ">%s:%.8X:%.8X:%.*X:%.8X:%.8X",
12233                  machine->gamedrv->name,
12234                  thisGameCRC,
12235                  action->type,
12236                  addressLength,
12237                  action->originalAddress,
12238                  action->originalDataField,
12239                  action->extendData);
12240#else
12241      bufTraverse +=   sprintf(bufTraverse, ">%s:%.8X:%.*X:%.8X:%.8X",
12242                  machine->gamedrv->name,
12243                  action->type,
12244                  addressLength,
12245                  action->originalAddress,
12246                  action->originalDataField,
12247                  action->extendData);
12248#endif
12249      /* set name */
12250      if(name)
12251      {
12252         bufTraverse += sprintf(bufTraverse, ":%s", name);
12253
12254         if(!i && entry->comment)
12255            bufTraverse += sprintf(bufTraverse, ":%s", entry->comment);
12256      }
12257      else
12258      {
12259         bufTraverse += sprintf(bufTraverse, ":(none)");
12260
12261         if(!i && entry->comment)
12262            bufTraverse += sprintf(bufTraverse, ":%s", entry->comment);
12263      }
12264
12265      /* set comment */
12266      if(!i && entry->comment)
12267         bufTraverse += sprintf(bufTraverse, ":%s", entry->comment);
12268
12269      bufTraverse += sprintf(bufTraverse, "\n");
12270
12271      mame_fwrite(theFile, buf, (UINT32)strlen(buf));
12272   }
12273
12274   /* close the database */
12275   mame_fclose(theFile);
12276
12277   /* clear dirty flag as "this entry is already saved" */
12278   entry->flags &= ~kCheatFlag_Dirty;
12279
12280   messageType = kCheatMessage_SucceededToSave;
12281   messageTimer = DEFAULT_MESSAGE_TIME;
12282#endif
12283   SaveDescription(machine);
12284}
12285
12286/*-----------------------------------------------------------------
12287  SaveActivationKey - save activation key code into the database
12288-----------------------------------------------------------------*/
12289
12290static void SaveActivationKey(running_machine *machine, CheatEntry * entry, int entryIndex)
12291{
12292   INT8   i;
12293   INT8   error = 0;
12294   char   buf[4096];
12295
12296   mame_file *   theFile = NULL;
12297   file_error   filerr;
12298
12299   if(!(entry->flags & kCheatFlag_HasActivationKey1) && !(entry->flags & kCheatFlag_HasActivationKey2))
12300      error = 1;
12301
12302   if(!error && (!entry || !entry->actionList || ((entry->flags & kCheatFlag_Select) && entry->actionListLength == 1)))
12303      error = 2;
12304
12305   /* open the database */
12306   if(!error)
12307   {
12308      filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE, &theFile);
12309
12310      if(!theFile)
12311         error = 2;
12312      else if(filerr != FILERR_NONE)
12313      {
12314         filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &theFile);
12315
12316         if(filerr != FILERR_NONE)
12317            error = 2;
12318      }
12319   }
12320
12321   switch(error)
12322   {
12323      case 1:
12324         messageType = kCheatMessage_NoActivationKey;
12325         messageTimer = DEFAULT_MESSAGE_TIME;
976312326         return;
12327
12328      case 2:
12329         messageType = kCheatMessage_FailedToSave;
12330         messageTimer = DEFAULT_MESSAGE_TIME;
12331         return;
976412332   }
976512333
976612334   mame_fseek(theFile, 0, SEEK_END);
976712335
9768   switch(saveCode)
12336   /* write the code to the database */
12337   for(i = 0; i < 2; i++)
976912338   {
9770      case normalCode:
9771         for(i = 0; i < entry->actionListLength; i++)
9772         {
9773            CheatAction   * action = &entry->actionList[i];
9774            char      * name = entry->name;
9775            UINT32      type = action->type;
9776            char      * bufTraverse = buf;
9777            int         addressLength = 8;
12339      int      addressLength   = 8;
12340      int      activationKey   = !i ? entry->activationKey1 : entry->activationKey2;
12341      int      type         = 0;
12342      char   * bufTraverse   = buf;
977812343
9779            /* ----- set link enable and label if label-selection ----- */
9780            if(i)
9781            {
9782               SET_MASK_FIELD(type, LinkEnable);
12344      CheatAction   * action = &entry->actionList[0];
12345      astring      * name = input_code_name(astring_alloc(), activationKey);
978312346
9784               if(entry->flags & kCheatFlag_Select)
9785                  name = action->optionalName;
9786            }
12347      /* set the flag in type field */
12348      SET_FIELD(type, CPURegion, CUSTOM_CODE);
978712349
9788            /* ----- get address length for current CPU ----- */
9789            switch(EXTRACT_FIELD(type, LocationType))
9790            {
9791               case kLocation_Standard:
9792               case kLocation_HandlerMemory:
9793               case kLocation_ProgramSpace:
9794                  addressLength = cpuInfoList[EXTRACT_FIELD(type, LocationParameter)].addressCharsNeeded;
9795                  break;
12350      if(activationKey)
12351         SET_FIELD(type, CodeType, kCustomCode_ActivationKey1);
12352      else
12353         SET_FIELD(type, CodeType, kCustomCode_ActivationKey2);
979612354
9797               case kLocation_IndirectIndexed:
9798                  addressLength = cpuInfoList[(EXTRACT_FIELD(type, LocationParameter) >> 2) & 0x7].addressCharsNeeded;
9799                  break;
12355      /* get address length of CPU/Region */
12356      addressLength = get_address_length(EXTRACT_FIELD(action->type, CPURegion));
980012357
9801               case kLocation_MemoryRegion:
9802                  {
9803                     int   idx = EXTRACT_FIELD(type, LocationParameter) + REGION_CPU1 - REGION_INVALID;
12358      /* if not find 1st activation key at saving 1st key, try to save 2nd key */
12359      if(!i && !(entry->flags & kCheatFlag_HasActivationKey1))
12360      {
12361         astring_free(name);
12362         continue;
12363      }
980412364
9805                     if(idx < kRegionListLength)
9806                        addressLength = regionInfoList[idx].addressCharsNeeded;
9807                  }
9808                  break;
9809            }
12365      /* if not find 2nd key after 1st key saved, finish */
12366      if(i && !(entry->flags & kCheatFlag_HasActivationKey2))
12367      {
12368         astring_free(name);
12369         break;
12370      }
12371
981012372#ifdef MESS
9811            bufTraverse += sprintf(bufTraverse, ":%s:%.8X:%.8X:%.*X:%.8X:%.8X", machine->gamedrv->name, thisGameCRC, type, addressLength, action->address, action->originalDataField, action->extendData);
12373      bufTraverse +=   sprintf(bufTraverse,
12374                  ">%s:%.8X:%.8X:%.*X:%.8X:00000000",
12375                  machine->gamedrv->name,
12376                  thisGameCRC,
12377                  type,
12378                  addressLength,
12379                  entryIndex,
12380                  activationKey);
981212381#else
9813            bufTraverse += sprintf(bufTraverse, ":%s:%.8X:%.*X:%.8X:%.8X", machine->gamedrv->name, type, addressLength, action->address, action->originalDataField, action->extendData);
12382      bufTraverse +=   sprintf(bufTraverse, ">%s:%.8X:%.*X:%.8X:00000000",
12383                  machine->gamedrv->name,
12384                  type,
12385                  addressLength,
12386                  entryIndex,
12387                  activationKey);
981412388#endif
9815            /* ----- set description and comment ----- */
9816            if(name)
9817            {
9818               bufTraverse += sprintf(bufTraverse, ":%s", name);
12389      /* set description */
12390      if(!i)
12391      {
12392         if(!(entry->flags & kCheatFlag_Select))
12393            bufTraverse += sprintf(bufTraverse, ":Pre-selection Key ");
12394         else
12395            bufTraverse += sprintf(bufTraverse, ":1st Activation Key ");
12396      }
12397      else
12398      {
12399         if(!(entry->flags & kCheatFlag_Select))
12400            bufTraverse += sprintf(bufTraverse, ":Next-selection Key ");
12401         else
12402            bufTraverse += sprintf(bufTraverse, ":2nd Activation Key ");
12403      }
981912404
9820               if(!i && (entry->comment))
9821                  bufTraverse += sprintf(bufTraverse, ":%s", entry->comment);
9822            }
9823            else
9824            {
9825               if(!i && (entry->comment))
9826                  bufTraverse += sprintf(bufTraverse, ":(none):%s", entry->comment);
9827            }
12405      /* set code name and button index */
12406      if(entry->name)
12407         bufTraverse += sprintf(bufTraverse, "for %s (%s)\n", entry->name, astring_c(name));
12408      else
12409         bufTraverse += sprintf(bufTraverse, "(%s)\n", astring_c(name));
982812410
9829            bufTraverse += sprintf(bufTraverse, "\n");
12411      /* write the activation key code */
12412      mame_fwrite(theFile, buf, (UINT32)strlen(buf));
983012413
9831            /* ----- write the normal cheat code ----- */
9832            mame_fwrite(theFile, buf, (UINT32)strlen(buf));
9833         }
9834         break;
12414      astring_free(name);
12415   }
983512416
9836      case activationKey:
9837         for(i = 0; i < 2; i++)
9838         {
9839            char      * bufTraverse = buf;
9840            int         addressLength;
12417   /* close the database */
12418   mame_fclose(theFile);
984112419
9842            /* ----- if not find 1st activation key at saving 1st key, try to save 2nd key ----- */
9843            if(!i && !(entry->flags & kCheatFlag_HasActivationKey1))
9844               continue;
12420   messageType = kCheatMessage_ActivationKeySaved;
12421   messageTimer = DEFAULT_MESSAGE_TIME;
12422}
984512423
9846            /* ----- if not find 2nd key after 1st key saved, finish ------ */
9847            if(i && !(entry->flags & kCheatFlag_HasActivationKey2))
9848               break;
12424/*-----------------------------------------------------------
12425  SavePreEnable - save a pre-enable code into the database
12426-----------------------------------------------------------*/
984912427
9850            /* ----- get address length for current CPU ----- */
9851            if(!(entry->flags & kCheatFlag_Select))
9852               addressLength = cpuInfoList[EXTRACT_FIELD(entry->actionList[0].type, LocationParameter)].addressCharsNeeded;
9853            else
9854               addressLength = cpuInfoList[EXTRACT_FIELD(entry->actionList[1].type, LocationParameter)].addressCharsNeeded;
12428static void SavePreEnable(running_machine *machine, CheatEntry * entry, int entryIndex)
12429{
12430   int      type         = 0;
12431   INT8   error         = 0;
12432   INT8   addressLength   = 8;
12433   char   buf[4096];
12434   char   * bufTraverse   = buf;
12435
12436   CheatAction      * action = &entry->actionList[0];
12437   mame_file *      theFile = NULL;
12438   file_error      filerr;
12439
12440   if(!entry || !entry->actionList || ((entry->flags & kCheatFlag_Select) && entry->actionListLength == 1))
12441      error = 1;
12442
12443   /* open the database */
12444   if(!error)
12445   {
12446      filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE, &theFile);
12447
12448      if(!theFile)
12449         error = 1;
12450      else if(filerr != FILERR_NONE)
12451      {
12452         filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &theFile);
12453
12454         if(filerr != FILERR_NONE)
12455            error = 1;
12456      }
12457   }
12458
12459   if(error)
12460   {
12461      messageType = kCheatMessage_FailedToSave;
12462      messageTimer = DEFAULT_MESSAGE_TIME;
12463      return;
12464   }
12465   else
12466   {
12467      SET_FIELD(type, CPURegion, CUSTOM_CODE);
12468      SET_FIELD(type, CodeType, kCustomCode_PreEnable);
12469   }
12470
12471   mame_fseek(theFile, 0, SEEK_END);
12472
12473   /* get address length of CPU/Region */
12474   addressLength = get_address_length(EXTRACT_FIELD(action->type, CPURegion));
12475
985512476#ifdef MESS
9856            if(!i)
9857               bufTraverse += sprintf(bufTraverse, ":%s:%.8X:63004000:%.*X:%.8X:00000000", machine->gamedrv->name, thisGameCRC, addressLength, selection, entry->activationKey1);
9858            else
9859               bufTraverse += sprintf(bufTraverse, ":%s:%.8X:63004001:%.*X:%.8X:00000000", machine->gamedrv->name, thisGameCRC, addressLength, selection, entry->activationKey2);
12477   bufTraverse +=   sprintf(bufTraverse, ">%s:%.8X:%8.8X:%.*X:%.8X:00000000",
12478               machine->gamedrv->name,
12479               thisGameCRC,
12480               type,
12481               addressLength,
12482               entryIndex,
12483               entry->selection);
986012484#else
9861            if(!i)
9862               bufTraverse += sprintf(bufTraverse, ":%s:63004000:%.*X:%.8X:00000000", machine->gamedrv->name, addressLength, selection, entry->activationKey1);
9863            else
9864               bufTraverse += sprintf(bufTraverse, ":%s:63004001:%.*X:%.8X:00000000", machine->gamedrv->name, addressLength, selection, entry->activationKey2);
12485   bufTraverse +=   sprintf(bufTraverse, ">%s:%8.8X:%.*X:%.8X:00000000",
12486               machine->gamedrv->name,
12487               type,
12488               addressLength,
12489               entryIndex,
12490               entry->selection);
986512491#endif
9866            /* ----- set description and button index ----- */
9867            if(!i)
9868            {
9869               /* ----- 1st key ----- */
9870               astring *name = input_code_name(astring_alloc(), entry->activationKey1);
9871               if (entry->name)
9872                  bufTraverse += sprintf(bufTraverse, ":1st Activation Key for %s (%s)\n", entry->name, astring_c(name));
9873               else
9874                  bufTraverse += sprintf(bufTraverse, ":1st Activation Key (%s)\n", astring_c(name));
9875               astring_free(name);
9876            }
9877            else
9878            {
9879               /* ----- 2nd key ----- */
9880               astring *name = input_code_name(astring_alloc(), entry->activationKey2);
9881               if (entry->name)
9882                  bufTraverse += sprintf(bufTraverse, ":2nd Activation Key for %s (%s)\n", entry->name, astring_c(name));
9883               else
9884                  bufTraverse += sprintf(bufTraverse, ":2nd Activation Key (%s)\n", astring_c(name));
9885               astring_free(name);
9886            }
988712492
9888            /* ----- write the activation key code ----- */
9889            mame_fwrite(theFile, buf, (UINT32)strlen(buf));
9890         }
9891         break;
12493   /* set name */
12494   bufTraverse += sprintf(bufTraverse, ":Pre-enable");
989212495
9893      case command:
9894         sprintf(buf, ":_command:%.8X\n", cheatOptions);
12496   if(entry->name)
12497      bufTraverse += sprintf(bufTraverse, " for %s", entry->name);
989512498
9896         /* ----- write the command code ----- */
9897         mame_fwrite(theFile, buf, (UINT32)strlen(buf));
9898         break;
12499   /* set label name */
12500   if(entry->selection)
12501      bufTraverse += sprintf(bufTraverse, " Label - %s", entry->actionList[entry->labelIndex[entry->selection]].optionalName);
989912502
9900      default:
9901         break;
12503   bufTraverse += sprintf(bufTraverse, "\n");
12504
12505   /* write the pre-enable code */
12506   mame_fwrite(theFile, buf, (UINT32)strlen(buf));
12507
12508   /* close the database */
12509   mame_fclose(theFile);
12510
12511   messageType = kCheatMessage_PreEnableSaved;
12512   messageTimer = DEFAULT_MESSAGE_TIME;
12513}
12514
12515/*--------------------------------------------------------------
12516  SaveCheatOptions - save cheat option code into the database
12517--------------------------------------------------------------*/
12518
12519static void SaveCheatOptions(void)
12520{
12521   UINT8      error = 0;
12522   char      buf[32];
12523
12524   mame_file *      theFile;
12525   file_error      filerr;
12526
12527   /* open the database */
12528   filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE, &theFile);
12529
12530   if(!theFile)
12531      error = 1;
12532   else if(filerr != FILERR_NONE)
12533   {
12534      filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &theFile);
12535
12536      if(filerr != FILERR_NONE)
12537         error = 1;
990212538   }
990312539
9904   /* ----- close the database ----- */
12540   if(error)
12541   {
12542      messageType = kCheatMessage_FailedToSave;
12543      messageTimer = DEFAULT_MESSAGE_TIME;
12544      return;
12545   }
12546
12547   mame_fseek(theFile, 0, SEEK_END);
12548
12549   sprintf(buf, ":_command:%.8X\n", cheatOptions);
12550
12551   /* write the command code */
12552   mame_fwrite(theFile, buf, (UINT32)strlen(buf));
12553
12554   /* close the database */
990512555   mame_fclose(theFile);
990612556
9907   /* ----- clear dirty flag ----- */
9908   if((saveCode == normalCode) || (saveCode == activationKey))
9909      entry->flags &= ~kCheatFlag_Dirty;
12557   messageType = kCheatMessage_SucceededToSave;
12558   messageTimer = DEFAULT_MESSAGE_TIME;
991012559}
991112560
12561/*------------------
12562  SaveDescription
12563------------------*/
12564
12565static void SaveDescription(running_machine *machine)
12566{
12567   UINT8   error = 0;
12568   char   buf[256];
12569
12570   mame_file *      theFile;
12571   file_error      filerr;
12572
12573   filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE, &theFile);
12574
12575   if(!theFile)
12576      error = 1;
12577   else if(filerr != FILERR_NONE)
12578   {
12579      filerr = mame_fopen(SEARCHPATH_CHEAT, mainDatabaseName, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &theFile);
12580
12581      if(filerr != FILERR_NONE)
12582         error = 1;
12583   }
12584
12585   if(error)
12586   {
12587      messageType = kCheatMessage_FailedToSave;
12588      messageTimer = DEFAULT_MESSAGE_TIME;
12589      return;
12590   }
12591
12592   mame_fseek(theFile, 0, SEEK_END);
12593   sprintf(buf, "> [ %s ]\n", machine->gamedrv->description);
12594
12595   /* write the command code */
12596   mame_fwrite(theFile, buf, (UINT32)strlen(buf));
12597
12598   /* close the database */
12599   mame_fclose(theFile);
12600
12601   messageType = kCheatMessage_SucceededToSave;
12602   messageTimer = DEFAULT_MESSAGE_TIME;
12603}
12604
991212605/*--------------------------------------------------------------------------
991312606  DoAutoSaveCheat - save normal code automatically when exit cheat system
991412607--------------------------------------------------------------------------*/
991512608
991612609static void DoAutoSaveCheats(running_machine *machine)
991712610{
9918   int   i;
12611   int i;
991912612
992012613   for(i = 0; i < cheatListLength; i++)
992112614   {
9922      CheatEntry   * entry = &cheatList[i];
12615      CheatEntry * entry = &cheatList[i];
992312616
12617      /* if the entry is not edited/added newly or has not been already saved, save it */
992412618      if(entry->flags & kCheatFlag_Dirty)
9925         SaveCheat(machine, entry, 0, 0);
12619         SaveCheatCode(machine, entry);
992612620   }
992712621}
992812622
r2762r2763
993012624  AddCheatFromResult - add a code from result viewer to cheat list
993112625-------------------------------------------------------------------*/
993212626
9933static void AddCheatFromResult(SearchInfo * search, SearchRegion * region, UINT32 address)
12627static void AddCheatFromResult(search_info *search, search_region *region, UINT32 address)
993412628{
9935   if(region->targetType == kRegionType_CPU)
12629   if((region->target_type == kRegionType_CPU) || (region->target_type == kRegionType_Memory))
993612630   {
993712631      CheatEntry   * entry = GetNewCheat();
993812632      CheatAction   * action = &entry->actionList[0];
993912633      char      tempString[1024];
994012634      int         tempStringLength;
9941      UINT32      data = ReadSearchOperand(kSearchOperand_First, search, region, address);
12635      UINT32      data = read_search_operand(kSearchOperand_First, search, region, address);
994212636
9943      tempStringLength = sprintf(tempString, "%.8X (%d) = %.*X", address, region->targetIdx, kSearchByteDigitsTable[search->bytes], data);
12637      tempStringLength = sprintf(tempString, "%.8X (%d) = %.*X", address, region->target_idx, kSearchByteDigitsTable[search->bytes], data);
994412638
994512639      entry->name = realloc(entry->name, tempStringLength + 1);
994612640      memcpy(entry->name, tempString, tempStringLength + 1);
994712641
9948      SET_FIELD(action->type, LocationParameter, region->targetIdx);
9949      SET_FIELD(action->type, BytesUsed, kSearchByteIncrementTable[search->bytes] - 1);
12642      SET_FIELD(action->type, CPURegion, region->target_idx);
12643      SET_FIELD(action->type, AddressSize, kSearchByteIncrementTable[search->bytes] - 1);
995012644      action->address = address;
9951      action->data = data;
12645      action->data = action->originalDataField = data;
995212646      action->extendData = 0xFFFFFFFF;
9953      action->originalDataField = data;
12647      action->lastValue = NULL;
995412648
995512649      UpdateCheatInfo(entry, 0);
995612650   }
r2762r2763
996012654  AddCheatFromFirstResult - add a code from search box to cheat list if found result is one
996112655--------------------------------------------------------------------------------------------*/
996212656
9963static void AddCheatFromFirstResult(SearchInfo * search)
12657static void AddCheatFromFirstResult(search_info *search)
996412658{
996512659   int   i;
996612660
9967   for(i = 0; i < search->regionListLength; i++)
12661   for(i = 0; i < search->region_list_length; i++)
996812662   {
9969      SearchRegion   * region = &search->regionList[i];
12663      search_region *region = &search->region_list[i];
997012664
9971      if(region->numResults)
12665      if(region->num_results)
997212666      {
997312667         UINT32   traverse;
997412668
r2762r2763
997612670         {
997712671            UINT32   address = region->address + traverse;
997812672
9979            if(IsRegionOffsetValid(search, region, traverse))
12673            if(is_region_offset_valid(search, region, traverse))
998012674            {
998112675               AddCheatFromResult(search, region, address);
9982
998312676               return;
998412677            }
998512678         }
r2762r2763
999112684  AddWatchFromResult - add a watch code from result viewer to cheat list
999212685-------------------------------------------------------------------------*/
999312686
9994static void AddWatchFromResult(SearchInfo * search, SearchRegion * region, UINT32 address)
12687static void AddWatchFromResult(search_info *search, search_region *region, UINT32 address)
999512688{
9996   if(region->targetType == kRegionType_CPU)
12689   if(region->target_type == kRegionType_CPU || region->target_type == kRegionType_Memory)
999712690   {
9998      WatchInfo   * info = GetUnusedWatch();
12691      WatchInfo * info = GetUnusedWatch();
999912692
10000      info->address =         address;
10001      info->cpu =            region->targetIdx;
10002      info->numElements =      1;
10003      info->elementBytes =   kWatchSizeConversionTable[search->bytes];
10004      info->labelType =      kWatchLabel_None;
10005      info->displayType =      kWatchDisplayType_Hex;
10006      info->skip =         0;
10007      info->elementsPerLine =   0;
10008      info->addValue =      0;
12693      info->address         = address;
12694      info->cpu            = region->target_idx;
12695      info->numElements      = 1;
12696      info->elementBytes      = kWatchSizeConversionTable[search->bytes];
12697      info->labelType         = kWatchLabel_None;
12698      info->displayType      = kWatchDisplayType_Hex;
12699      info->skip            = 0;
12700      info->elementsPerLine   = 0;
12701      info->addValue         = 0;
12702      info->linkedCheat      = NULL;
12703      info->label[0]         = 0;
1000912704
10010      info->linkedCheat =      NULL;
10011
10012      info->label[0] =      0;
12705      messageType      = kCheatMessage_SucceededToAdd;
12706      messageTimer   = DEFAULT_MESSAGE_TIME;
1001312707   }
12708   else
12709   {
12710      messageType      = kCheatMessage_FailedToAdd;
12711      messageTimer   = DEFAULT_MESSAGE_TIME;
12712   }
1001412713}
1001512714
10016/*--------------------
10017  SearchSignExtend
10018--------------------*/
12715/*---------------------
12716  search_sign_extend
12717---------------------*/
1001912718
10020static UINT32 SearchSignExtend(SearchInfo * search, UINT32 value)
12719static UINT32 search_sign_extend(search_info *search, UINT32 value)
1002112720{
1002212721   if(search->sign)
10023   {
1002412722      if(value & kSearchByteSignBitTable[search->bytes])
1002512723         value |= ~kSearchByteUnsignedMaskTable[search->bytes];
10026   }
1002712724
1002812725   return value;
1002912726}
1003012727
10031/*-------------------------------------------------------------------
10032  ReadSearchOperand - read a data from search region and return it
10033-------------------------------------------------------------------*/
12728/*---------------------------------------------------------------------
12729  read_search_operand - read a data from search region and return it
12730---------------------------------------------------------------------*/
1003412731
10035static UINT32 ReadSearchOperand(UINT8 type, SearchInfo * search, SearchRegion * region, UINT32 address)
12732static UINT32 read_search_operand(UINT8 type, search_info *search, search_region *region, UINT32 address)
1003612733{
10037   UINT32   value = 0;
12734   UINT32 value = 0;
1003812735
1003912736   switch(type)
1004012737   {
1004112738      case kSearchOperand_Current:
10042         value = ReadRegionData(region, address - region->address, kSearchByteIncrementTable[search->bytes], search->swap);
12739         value = read_region_data(region, address - region->address, kSearchByteIncrementTable[search->bytes], search->swap);
1004312740         break;
1004412741
1004512742      case kSearchOperand_Previous:
r2762r2763
1005212749
1005312750      case kSearchOperand_Value:
1005412751         value = search->value;
10055         break;
1005612752   }
1005712753
10058   value = SearchSignExtend(search, value);
12754   value = search_sign_extend(search, value);
1005912755
1006012756   return value;
1006112757}
1006212758
10063/*------------------------------------------------------------------------------------------
10064  ReadSearchOperandBit - read a bit data from search region and return it when bit search
10065------------------------------------------------------------------------------------------*/
12759/*---------------------------------------------------------------------------------------------
12760  read_search_operand_bit - read a bit data from search region and return it when bit search
12761---------------------------------------------------------------------------------------------*/
1006612762
10067static UINT32 ReadSearchOperandBit(UINT8 type, SearchInfo * search, SearchRegion * region, UINT32 address)
12763static UINT32 read_search_operand_bit(UINT8 type, search_info *search, search_region *region, UINT32 address)
1006812764{
10069   UINT32   value = 0;
12765   UINT32 value = 0;
1007012766
1007112767   switch(type)
1007212768   {
1007312769      case kSearchOperand_Current:
10074         value = ReadRegionData(region, address - region->address, kSearchByteIncrementTable[search->bytes], search->swap);
12770         value = read_region_data(region, address - region->address, kSearchByteIncrementTable[search->bytes], search->swap);
1007512771         break;
1007612772
1007712773      case kSearchOperand_Previous:
r2762r2763
1008712783            value = 0xFFFFFFFF;
1008812784         else
1008912785            value = 0x00000000;
10090         break;
1009112786   }
1009212787
10093   value = SearchSignExtend(search, value);
12788   value = search_sign_extend(search, value);
1009412789
1009512790   return value;
1009612791}
1009712792
10098/*----------------------------------------------------------
10099  DoSearchComparison - compare data and return it matched
10100----------------------------------------------------------*/
12793/*------------------------------------------------------------
12794  do_search_comparison - compare data and return it matched
12795------------------------------------------------------------*/
1010112796
10102static UINT8 DoSearchComparison(SearchInfo * search, UINT32 lhs, UINT32 rhs)
12797static UINT8 do_search_comparison(search_info *search, UINT32 lhs, UINT32 rhs)
1010312798{
10104   INT32   svalue;
12799   INT32 svalue;
1010512800
1010612801   if(search->sign)
1010712802   {
10108      /* ----- signed ----- */
12803      /* signed */
1010912804      INT32   slhs = lhs;
1011012805      INT32   srhs = rhs;
1011112806
r2762r2763
1013112826
1013212827         case kSearchComparison_IncreasedBy:
1013312828            svalue = search->value;
12829
1013412830            if(search->value & kSearchByteSignBitTable[search->bytes])
1013512831               svalue |= ~kSearchByteUnsignedMaskTable[search->bytes];
1013612832
r2762r2763
1014212838   }
1014312839   else
1014412840   {
10145      /* ----- unsigned ----- */
12841      /* unsigned */
1014612842      switch(search->comparison)
1014712843      {
1014812844         case kSearchComparison_LessThan:
r2762r2763
1016512861
1016612862         case kSearchComparison_IncreasedBy:
1016712863            svalue = search->value;
12864
1016812865            if(search->value & kSearchByteSignBitTable[search->bytes])
1016912866               svalue |= ~kSearchByteUnsignedMaskTable[search->bytes];
1017012867
r2762r2763
1017812875   return 0;
1017912876}
1018012877
10181/*-----------------------------------------------------------------
10182  DoSearchComparisonBit - compare bit data and return it matched
10183-----------------------------------------------------------------*/
12878/*--------------------------------------------------------------------
12879  do_search_comparison_bit - compare bit data and return it matched
12880--------------------------------------------------------------------*/
1018412881
10185static UINT32 DoSearchComparisonBit(SearchInfo * search, UINT32 lhs, UINT32 rhs)
12882static UINT32 do_search_comparison_bit(search_info *search, UINT32 lhs, UINT32 rhs)
1018612883{
1018712884   switch(search->comparison)
1018812885   {
r2762r2763
1020212899   return 0;
1020312900}
1020412901
10205/*----------------------
10206  IsRegionOffsetValid
10207----------------------*/
12902/*----------------------------------------------
12903  is_region_offset_valid - ????? unused ?????
12904----------------------------------------------*/
1020812905
10209/*
10210static UINT8 IsRegionOffsetValid(SearchInfo * search, SearchRegion * region, UINT32 offset)
12906#if 0
12907static UINT8 is_region_offset_valid(search_info *search, search_region *region, UINT32 offset)
1021112908{
1021212909    switch(kSearchByteIncrementTable[search->bytes])
1021312910    {
r2762r2763
1022612923
1022712924    return 0;
1022812925}
10229*/
12926#endif
1023012927
10231/*----------------------------------------------------------
10232  IsRegionOffsetValidBit - check selected offset is valid
10233----------------------------------------------------------*/
12928/*-----------------------------------------------------
12929  is_region_offset_valid_bit - check selected offset
12930-----------------------------------------------------*/
1023412931
10235static UINT8 IsRegionOffsetValidBit(SearchInfo * search, SearchRegion * region, UINT32 offset)
12932static UINT8 is_region_offset_valid_bit(search_info *search, search_region *region, UINT32 offset)
1023612933{
1023712934   switch(kSearchByteStep[search->bytes])
1023812935   {
r2762r2763
1025612953   return 0;
1025712954}
1025812955
10259/*----------------------------------------------------------------
10260  InvalidateRegionOffset - remove unmatched offset after search
10261----------------------------------------------------------------*/
12956/*------------------------------------------------------------------
12957  invalidate_region_offset - remove unmatched offset after search
12958------------------------------------------------------------------*/
1026212959
10263static void InvalidateRegionOffset(SearchInfo * search, SearchRegion * region, UINT32 offset)
12960static void invalidate_region_offset(search_info *search, search_region *region, UINT32 offset)
1026412961{
1026512962   switch(kSearchByteStep[search->bytes])
1026612963   {
r2762r2763
1028312980   }
1028412981}
1028512982
10286/*-----------------------------------------------------------------------
10287  InvalidateRegionOffsetBit - remove unmatched offset after bit search
10288-----------------------------------------------------------------------*/
12983/*--------------------------------------------------------------------------
12984  invalidate_region_offset_bit - remove unmatched offset after bit search
12985--------------------------------------------------------------------------*/
1028912986
10290static void InvalidateRegionOffsetBit(SearchInfo * search, SearchRegion * region, UINT32 offset, UINT32 invalidate)
12987static void invalidate_region_offset_bit(search_info *search, search_region *region, UINT32 offset, UINT32 invalidate)
1029112988{
1029212989   switch(kSearchByteStep[search->bytes])
1029312990   {
r2762r2763
1031013007   }
1031113008}
1031213009
10313/*--------------------------------------------------------------
10314  InvalidateEntireRegions - invalidate selected search region
10315--------------------------------------------------------------*/
13010/*----------------------------------------------------------------
13011  invalidate_entire_regions - invalidate selected search region
13012----------------------------------------------------------------*/
1031613013
10317static void InvalidateEntireRegion(SearchInfo * search, SearchRegion * region)
13014static void invalidate_entire_region(search_info *search, search_region *region)
1031813015{
1031913016   memset(region->status, 0, region->length);
1032013017
10321   search->numResults -= region->numResults;
10322   region->numResults = 0;
13018   search->num_results -=   region->num_results;
13019   region->num_results =   0;
1032313020}
1032413021
10325/*-------------------------------------------------------------------
10326  InitializeNewSearch - initialize search region to start a search
10327-------------------------------------------------------------------*/
13022/*---------------------------------------------------------------
13023  init_new_search - initialize search region to start a search
13024---------------------------------------------------------------*/
1032813025
10329static void InitializeNewSearch(SearchInfo * search)
13026static void init_new_search(search_info *search)
1033013027{
10331   int   i;
13028   int i;
1033213029
10333   search->numResults = 0;
13030   search->num_results = 0;
1033413031
10335   for(i = 0; i < search->regionListLength; i++)
13032   for(i = 0; i < search->region_list_length; i++)
1033613033   {
10337      SearchRegion   * region = &search->regionList[i];
13034      search_region *region = &search->region_list[i];
1033813035
1033913036      if(region->flags & kRegionFlag_Enabled)
1034013037      {
10341         region->numResults = 0;
13038         region->num_results = 0;
1034213039
1034313040         memset(region->status, 0xFF, region->length);
1034413041
10345         FillBufferFromRegion(region, region->first);
13042         fill_buffer_from_region(region, region->first);
1034613043
1034713044         memcpy(region->last, region->first, region->length);
1034813045      }
1034913046   }
1035013047}
1035113048
10352/*---------------------------------------------------------------------------
10353  UpdateSearch - updata a data in search region after initialize or search
10354---------------------------------------------------------------------------*/
13049/*----------------------------------------------------------------------------
13050  update_search - update a data in search region after initialize or search
13051----------------------------------------------------------------------------*/
1035513052
10356static void UpdateSearch(SearchInfo * search)
13053static void update_search(search_info *search)
1035713054{
10358   int   i;
13055   int i;
1035913056
10360   for(i = 0; i < search->regionListLength; i++)
13057   for(i = 0; i < search->region_list_length; i++)
1036113058   {
10362      SearchRegion   * region = &search->regionList[i];
13059      search_region *region = &search->region_list[i];
1036313060
1036413061      if(region->flags & kRegionFlag_Enabled)
10365         FillBufferFromRegion(region, region->last);
13062         fill_buffer_from_region(region, region->last);
1036613063   }
1036713064}
1036813065
10369/*-------------------------------------
10370  DoSearch - management for a search
10371-------------------------------------*/
13066/*---------------------------------------
13067  do_search - cheat engine search core
13068---------------------------------------*/
1037213069
10373static void DoSearch(SearchInfo * search)
13070static void do_search(search_info *search)
1037413071{
10375   int   i, j;
13072   int i, j;
1037613073
10377   search->numResults = 0;
13074   search->num_results = 0;
1037813075
1037913076   if(search->bytes == kSearchSize_1Bit)
1038013077   {
10381      /* ----- bit search ----- */
10382      for(i = 0; i < search->regionListLength; i++)
13078      /* bit search */
13079      for(i = 0; i < search->region_list_length; i++)
1038313080      {
10384         SearchRegion   * region = &search->regionList[i];
10385         UINT32         lastAddress = region->length - kSearchByteIncrementTable[search->bytes] + 1;
10386         UINT32         increment = kSearchByteStep[search->bytes];
13081         search_region   *region      = &search->region_list[i];
13082         UINT32         lastAddress   = region->length - kSearchByteIncrementTable[search->bytes] + 1;
13083         UINT32         increment   = kSearchByteStep[search->bytes];
1038713084
10388         region->numResults = 0;
13085         region->num_results = 0;
1038913086
10390         if((region->length < kSearchByteIncrementTable[search->bytes]) || !region->flags & kRegionFlag_Enabled)
13087         if(region->length < kSearchByteIncrementTable[search->bytes] || (region->flags & kRegionFlag_Enabled) == 0)
1039113088            continue;
1039213089
1039313090         for(j = 0; j < lastAddress; j += increment)
r2762r2763
1039713094
1039813095            address = region->address + j;
1039913096
10400            if(IsRegionOffsetValidBit(search, region, j))
13097            if(is_region_offset_valid_bit(search, region, j))
1040113098            {
1040213099               UINT32   validBits;
1040313100
10404               lhs = ReadSearchOperandBit(search->lhs, search, region, address);
10405               rhs = ReadSearchOperandBit(search->rhs, search, region, address);
13101               lhs = read_search_operand_bit(search->lhs, search, region, address);
13102               rhs = read_search_operand_bit(search->rhs, search, region, address);
1040613103
10407               /* ----- do search ----- */
10408               validBits = DoSearchComparisonBit(search, lhs, rhs);
13104               /* do bit search */
13105               validBits = do_search_comparison_bit(search, lhs, rhs);
1040913106
10410               InvalidateRegionOffsetBit(search, region, j, ~validBits);
13107               invalidate_region_offset_bit(search, region, j, ~validBits);
1041113108
10412               if(IsRegionOffsetValidBit(search, region, j))
13109               if(is_region_offset_valid_bit(search, region, j))
1041313110               {
10414                  search->numResults++;
10415                  region->numResults++;
13111                  search->num_results++;
13112                  region->num_results++;
1041613113               }
1041713114            }
1041813115         }
r2762r2763
1042013117   }
1042113118   else
1042213119   {
10423      /* ----- normal search ----- */
10424      for(i = 0; i < search->regionListLength; i++)
13120      /* normal search */
13121      for(i = 0; i < search->region_list_length; i++)
1042513122      {
10426         SearchRegion   * region = &search->regionList[i];
10427         UINT32         lastAddress = region->length - kSearchByteIncrementTable[search->bytes] + 1;
10428         UINT32         increment = kSearchByteStep[search->bytes];
13123         search_region   *region      = &search->region_list[i];
13124         UINT32         lastAddress   = region->length - kSearchByteIncrementTable[search->bytes] + 1;
13125         UINT32         increment   = kSearchByteStep[search->bytes];
1042913126
10430         region->numResults = 0;
13127         region->num_results = 0;
1043113128
10432         if((region->length < kSearchByteIncrementTable[search->bytes]) || !region->flags & kRegionFlag_Enabled)
13129         if(region->length < kSearchByteIncrementTable[search->bytes] || (region->flags & kRegionFlag_Enabled) == 0)
1043313130            continue;
1043413131
1043513132         for(j = 0; j < lastAddress; j += increment)
r2762r2763
1043913136
1044013137            address = region->address + j;
1044113138
10442            if(IsRegionOffsetValid(search, region, j))
13139            if(is_region_offset_valid(search, region, j))
1044313140            {
10444               lhs = ReadSearchOperand(search->lhs, search, region, address);
10445               rhs = ReadSearchOperand(search->rhs, search, region, address);
13141               lhs = read_search_operand(search->lhs, search, region, address);
13142               rhs = read_search_operand(search->rhs, search, region, address);
1044613143
10447               /* ----- do search ----- */
10448               if(!DoSearchComparison(search, lhs, rhs))
10449                  /* ----- unmatched ----- */
10450                  InvalidateRegionOffset(search, region, j);
13144               /* do value search */
13145               if(do_search_comparison(search, lhs, rhs) == 0)
13146               {
13147                  /* unmatched */
13148                  invalidate_region_offset(search, region, j);
13149               }
1045113150               else
1045213151               {
10453                  /* ----- matched ----- */
10454                  search->numResults++;
10455                  region->numResults++;
13152                  /* matched */
13153                  search->num_results++;
13154                  region->num_results++;
1045613155               }
1045713156            }
1045813157         }
r2762r2763
1046013159   }
1046113160}
1046213161
10463/*----------------------
10464  LookupHandlerMemory
10465----------------------*/
13162/*-----------------------------------------------------------
13163  LookupHandlerMemory - search specified write handler
13164-----------------------------------------------------------*/
1046613165
1046713166static UINT8 ** LookupHandlerMemory(UINT8 cpu, UINT32 address, UINT32 * outRelativeAddress)
1046813167{
10469   const address_map   * map = memory_get_address_map(cpu, ADDRESS_SPACE_PROGRAM);
10470   const address_map_entry *entry;
13168   const address_map         * map = memory_get_address_map(cpu, ADDRESS_SPACE_PROGRAM);
13169   const address_map_entry      *entry;
1047113170
10472   for (entry = map->entrylist; entry != NULL; entry = entry->next)
10473      if (entry->write.generic != NULL && (address >= entry->addrstart) && (address <= entry->addrend))
13171   for(entry = map->entrylist; entry != NULL; entry = entry->next)
13172   {
13173      if(entry->write.generic != NULL && address >= entry->addrstart && address <= entry->addrend)
1047413174      {
1047513175         if(outRelativeAddress)
13176         {
1047613177            *outRelativeAddress = address - entry->addrstart;
10477
10478         return (UINT8 **)entry->baseptr;
13178            return (UINT8 **)entry->baseptr;
13179         }
1047913180      }
13181   }
1048013182
1048113183   return NULL;
1048213184}
1048313185
10484/*------------------------------------------
10485  DoCPURead - read a data from RAM region
10486------------------------------------------*/
13186/*-------------------------------------------------------------------------------------------------------------
13187  GetMemoryRegionBasePointer - return base pointer to the base of RAM associated with given CPU and address
13188-------------------------------------------------------------------------------------------------------------*/
1048713189
13190static UINT8 ** GetMemoryRegionBasePointer(UINT8 cpu, UINT8 space, UINT32 address)
13191{
13192   UINT8   * buf = NULL;
13193
13194   switch(space)
13195   {
13196      case kAddressSpace_DataSpace:
13197         buf = memory_get_read_ptr(cpu, ADDRESS_SPACE_DATA, address);
13198         break;
13199
13200      case kAddressSpace_IOSpace:
13201         buf = memory_get_read_ptr(cpu, ADDRESS_SPACE_IO, address);
13202         break;
13203
13204      case kAddressSpace_OpcodeRAM:
13205         buf = memory_get_op_ptr(cpu, address, 0);
13206         break;
13207
13208      case kAddressSpace_DirectMemory:
13209         buf = memory_get_read_ptr(cpu, ADDRESS_SPACE_PROGRAM, address);
13210         break;
13211
13212      default:
13213         logerror("invalid address space (%x)\n", space);
13214   }
13215
13216   if(buf)      buf -= address;
13217
13218   //logerror("pointer (return) : %p\n", buf);
13219
13220   return (UINT8 **)buf;
13221}
13222
13223/*--------------------------------------------------------------------------------------------------------------
13224  DoCPURead - read a data from standard CPU region
13225              NOTE : if a driver has cpu_spinutil(), reading a data via cpunum_read_byte may conflict with it
13226--------------------------------------------------------------------------------------------------------------*/
13227
1048813228static UINT32 DoCPURead(UINT8 cpu, UINT32 address, UINT8 bytes, UINT8 swap)
1048913229{
13230   cpu_region_info *info = get_cpu_info(cpu);
13231
13232   address = DoShift(address, info->address_shift);
13233
1049013234   switch(bytes)
1049113235   {
1049213236      case 1:
r2762r2763
1052113265   return 0;
1052213266}
1052313267
10524/*-----------------------------------------------------
10525  DoMemoryRead - read a data from ROM or User region
10526-----------------------------------------------------*/
13268/*--------------------------------------------------
13269  DoMemoryRead - read a data from memory directly
13270--------------------------------------------------*/
1052713271
10528static UINT32 DoMemoryRead(UINT8 * buf, UINT32 address, UINT8 bytes, UINT8 swap, CPUInfo * info)
13272static UINT32 DoMemoryRead(UINT8 * buf, UINT32 address, UINT8 bytes, UINT8 swap, cpu_region_info *info)
1052913273{
10530   UINT32   data = 0;
13274   int i;
13275   int data = 0;
1053113276
13277   if(info)
13278      address = DoShift(address, info->address_shift);
13279
1053213280   if(!info)
1053313281   {
1053413282      switch(bytes)
r2762r2763
1055313301            break;
1055413302
1055513303         default:
10556            info = &rawCPUInfo;
13304            info = &raw_cpu_info;
1055713305            goto generic;
1055813306      }
1055913307
r2762r2763
1056113309   }
1056213310
1056313311generic:
13312   for(i = 0; i < bytes; i++)
13313      data |= swap ?   buf[SwapAddress(address + i, bytes, info)] << (i * 8) :
13314                  buf[SwapAddress(address + i, bytes, info)] << ((bytes - i - 1) * 8);
1056413315
10565   if(swap)
10566   {
10567      UINT32   i;
10568
10569      for(i = 0; i < bytes; i++)
10570         data |= buf[SwapAddress(address + i, bytes, info)] << (i * 8);
10571   }
10572   else
10573   {
10574      UINT32   i;
10575
10576      for(i = 0; i < bytes; i++)
10577         data |= buf[SwapAddress(address + i, bytes, info)] << ((bytes - i - 1) * 8);
10578   }
10579
1058013316   return data;
1058113317}
1058213318
10583/*--------------------------------------------
10584  DoCPUWrite - write a data into RAM region
10585--------------------------------------------*/
13319/*-----------------------------------------------------
13320  DoCPUWrite - write a data into standard CPU region
13321-----------------------------------------------------*/
1058613322
1058713323static void DoCPUWrite(UINT32 data, UINT8 cpu, UINT32 address, UINT8 bytes, UINT8 swap)
1058813324{
13325   cpu_region_info *info = get_cpu_info(cpu);
13326
13327   address = DoShift(address, info->address_shift);
13328
1058913329   switch(bytes)
1059013330   {
1059113331      case 1:
r2762r2763
1064313383   }
1064413384}
1064513385
10646/*-------------------------------------------------------
10647  DoMemoryWrite - write a data into ROM or User region
10648-------------------------------------------------------*/
13386/*----------------------------------------------------
13387  DoMemoryWrite - write a data into memory directly
13388----------------------------------------------------*/
1064913389
10650static void DoMemoryWrite(UINT32 data, UINT8 * buf, UINT32 address, UINT8 bytes, UINT8 swap, CPUInfo * info)
13390static void DoMemoryWrite(UINT32 data, UINT8 * buf, UINT32 address, UINT8 bytes, UINT8 swap, cpu_region_info *info)
1065113391{
13392   UINT32 i;
13393
13394   if(info)
13395      address = DoShift(address, info->address_shift);
13396
1065213397   if(!info)
1065313398   {
1065413399      switch(bytes)
r2762r2763
1067313418            break;
1067413419
1067513420         default:
10676            info = &rawCPUInfo;
13421            info = &raw_cpu_info;
1067713422            goto generic;
1067813423      }
1067913424
r2762r2763
1068113426   }
1068213427
1068313428generic:
10684
10685   if(swap)
13429   for(i = 0; i < bytes; i++)
1068613430   {
10687      UINT32   i;
10688
10689      for(i = 0; i < bytes; i++)
10690         buf[SwapAddress(address + i, bytes, info)] = data >> (i * 8);
13431      if(swap)   buf[SwapAddress(address + i, bytes, info)] = data >> (i * 8);
13432      else      buf[SwapAddress(address + i, bytes, info)] = data >> ((bytes - i - 1) * 8);
1069113433   }
10692   else
10693   {
10694      UINT32   i;
10695
10696      for(i = 0; i < bytes; i++)
10697         buf[SwapAddress(address + i, bytes, info)] = data >> ((bytes - i - 1) * 8);
10698   }
1069913434}
1070013435
10701/*--------------------------------
10702  CPUNeedsSwap - endian checker
10703--------------------------------*/
13436/*-----------
13437  ReadData
13438-----------*/
1070413439
10705static UINT8 CPUNeedsSwap(UINT8 cpu)
13440static UINT32 ReadData(CheatAction * action)
1070613441{
10707   return cpuInfoList[cpu].endianness ^ 1;
10708}
13442   UINT8   addressRead      = EXTRACT_FIELD(action->type, AddressRead);
13443   UINT8   bytes         = EXTRACT_FIELD(action->type, AddressSize) + 1;
1070913444
10710/*-----------------------------------
10711  RegionNeedsSwap - endian checker
10712-----------------------------------*/
10713
10714static UINT8 RegionNeedsSwap(UINT8 region)
10715{
10716   CPUInfo   * temp = GetRegionCPUInfo(region);
10717
10718   if(temp)
10719      return temp->endianness ^ 1;
10720
10721   return 0;
10722}
10723
10724/*----------------------------------------------------
10725  GetCPUInfo - return CPU info for standard region
10726----------------------------------------------------*/
10727
10728static CPUInfo * GetCPUInfo(UINT8 cpu)
10729{
10730      return &cpuInfoList[cpu];
10731}
10732
10733/*-------------------------------------------------
10734  GetRegionCPUInfo - return CPU info for regions
10735-------------------------------------------------*/
10736
10737static CPUInfo * GetRegionCPUInfo(UINT8 region)
10738{
10739   if((region >= REGION_INVALID) && (region < REGION_MAX))
10740      return &regionInfoList[region - REGION_INVALID];
10741
10742   return NULL;
10743}
10744
10745/*--------------
10746  SwapAddress
10747--------------*/
10748
10749static UINT32 SwapAddress(UINT32 address, UINT8 dataSize, CPUInfo * info)
10750{
10751   switch(info->dataBits)
13445   if(addressRead != kReadFrom_Variable)
1075213446   {
10753      case 16:
10754         if(info->endianness == CPU_IS_BE)
10755            return BYTE_XOR_BE(address);
10756         else
10757            return BYTE_XOR_LE(address);
13447      /* read a data from memory */
13448      int address = ~0;
1075813449
10759      case 32:
10760         if(info->endianness == CPU_IS_BE)
10761            return BYTE4_XOR_BE(address);
10762         else
10763            return BYTE4_XOR_LE(address);
10764   }
13450      if(addressRead == kReadFrom_Address)      address = action->address;
13451      else if(addressRead == kReadFrom_Index)      address = cheatVariable[action->address];
1076513452
10766   return address;
10767}
10768
10769/*------------------------------------
10770  ReadData - read a data per region
10771------------------------------------*/
10772
10773static UINT32 ReadData(CheatAction * action)
10774{
10775   UINT8   parameter = EXTRACT_FIELD(action->type, LocationParameter);
10776   UINT8   bytes = EXTRACT_FIELD(action->type, BytesUsed) + 1;
10777   UINT8   swapBytes = EXTRACT_FIELD(action->type, Endianness);
10778
10779   switch(EXTRACT_FIELD(action->type, LocationType))
10780   {
10781      case kLocation_Standard:
10782         return DoCPURead(parameter, action->address, bytes, CPUNeedsSwap(parameter) ^ swapBytes);
10783         break;
10784
10785      case kLocation_MemoryRegion:
13453      if(!TEST_FIELD(action->region, RegionFlag))
1078613454      {
10787         int      region = REGION_CPU1 + parameter;
10788         UINT8   * buf = memory_region(region);
13455         /* read a data from CPU */
13456         UINT8 cpu = EXTRACT_FIELD(action->region, CPUIndex);
1078913457
10790         if(buf)
13458         switch(EXTRACT_FIELD(action->region, AddressSpace))
1079113459         {
10792            if(TEST_FIELD(cheatOptions, Debug))
10793            {
10794               if(ControlKeyPressed())
10795                  ui_popup_time(1, "MR : %x : %p", region, buf);
10796            }
13460            case kAddressSpace_Program:
13461               if(action->flags & kActionFlag_IndexAddress)
13462               {
13463                  int indexAddress;
1079713464
10798            if(IsAddressInRange(action, memory_region_length(region)))
10799               return DoMemoryRead(buf, action->address, bytes, RegionNeedsSwap(region) ^ swapBytes, GetRegionCPUInfo(region));
10800         }
10801      }
10802      break;
13465                  cpu_region_info *info = get_cpu_info(cpu);
1080313466
10804      case kLocation_HandlerMemory:
10805      {
10806         UINT32   relativeAddress;
10807         UINT8   ** buf;
13467                  indexAddress = DoCPURead(cpu, address, EXTRACT_FIELD(action->type, IndexSize) + 1, cpu_needs_swap(cpu));
1080813468
10809         if(!action->cachedPointer)
10810            action->cachedPointer = LookupHandlerMemory(parameter, action->address, &action->cachedOffset);
13469                  if(info && info->address_shift)
13470                     indexAddress = DoShift(indexAddress, info->address_shift);
1081113471
10812         buf = action->cachedPointer;
10813         relativeAddress = action->cachedOffset;
13472                  if(indexAddress)
13473                  {
13474                     indexAddress += action->extendData;
13475                     return DoCPURead(cpu, indexAddress, bytes, cpu_needs_swap(cpu));
13476                  }
13477               }
13478               else if(action->flags & kActionFlag_PDWWrite)
13479               {
13480                  if(action->flags & kActionFlag_IsFirst)
13481                  {
13482                     address += bytes;
13483                     bytes = EXTRACT_FIELD(action->type, IndexSize) + 1;
13484                     action->flags &= ~kActionFlag_IsFirst;
13485                  }
13486                  else
13487                     action->flags |= kActionFlag_IsFirst;
1081413488
10815         if(buf && *buf)
10816            return DoMemoryRead(*buf, relativeAddress, bytes, CPUNeedsSwap(parameter) ^ swapBytes, GetCPUInfo(parameter));
10817      }
10818      break;
13489                  return DoCPURead(cpu, address, bytes, cpu_needs_swap(cpu));
13490               }
13491               else
13492               {
13493                  return DoCPURead(cpu, address, bytes, cpu_needs_swap(cpu));
13494               }
13495               break;
1081913496
10820      case kLocation_IndirectIndexed:
10821      {
10822         UINT32   address;
10823         INT32   offset = action->extendData;
10824         UINT8   cpu = (parameter >> 2) & 0x7;
10825         UINT8   addressBytes = (parameter & 0x3) + 1;
10826         CPUInfo   * info = GetCPUInfo(cpu);
13497            case kAddressSpace_DataSpace:
13498            case kAddressSpace_IOSpace:
13499            case kAddressSpace_OpcodeRAM:
13500            case kAddressSpace_DirectMemory:
13501               {
13502                  UINT8 * buf;
1082713503
10828         address = DoCPURead(cpu, action->address, addressBytes, CPUNeedsSwap(cpu) ^ swapBytes);
13504                  action->cachedPointer = GetMemoryRegionBasePointer(cpu, EXTRACT_FIELD(action->type, AddressSpace), address);
13505                  buf = (UINT8 *) action->cachedPointer;
1082913506
10830         if(info)
10831            address = DoShift(address, info->addressShift);
13507                  if(buf)
13508                  {
13509                     if(action->flags && kActionFlag_PDWWrite)
13510                     {
13511                        if(action->flags & kActionFlag_IsFirst)
13512                        {
13513                           address += bytes;
13514                           bytes = EXTRACT_FIELD(action->type, IndexSize) + 1;
13515                           action->flags &= ~kActionFlag_IsFirst;
13516                        }
13517                        else
13518                           action->flags |= kActionFlag_IsFirst;
13519                     }
1083213520
10833         if(address)
10834         {
10835            address += offset;
13521                     return DoMemoryRead(buf, address, bytes, cpu_needs_swap(cpu), get_cpu_info(cpu));
13522                  }
13523               }
13524               break;
1083613525
10837            return DoCPURead(cpu, address, bytes, CPUNeedsSwap(cpu) ^ swapBytes);
10838         }
10839      }
10840      break;
13526            case kAddressSpace_MappedMemory:
13527               {
13528                  int         relativeAddress;
13529                  UINT8 **   buf;
1084113530
10842      case kLocation_ProgramSpace:
10843      {
10844         UINT8   * buf;
13531                  action->cachedPointer = LookupHandlerMemory(cpu, address, &action->cachedOffset);
13532                  buf = action->cachedPointer;
13533                  relativeAddress = action->cachedOffset;
1084513534
10846         memory_set_opbase(action->address);
13535                  if(buf && *buf)
13536                  {
13537                     if(action->flags & kActionFlag_PDWWrite)
13538                     {
13539                        if(action->flags & kActionFlag_IsFirst)
13540                        {
13541                           relativeAddress += bytes;
13542                           bytes = EXTRACT_FIELD(action->type, IndexSize) + 1;
13543                           action->flags &= ~kActionFlag_IsFirst;
13544                        }
13545                        else
13546                           action->flags |= kActionFlag_IsFirst;
13547                     }
1084713548
10848         buf = memory_get_op_ptr(parameter, action->address, 0);
13549                     return DoMemoryRead(*buf, relativeAddress, bytes, cpu_needs_swap(cpu), get_cpu_info(cpu));
13550                  }
13551               }
13552               break;
1084913553
10850         buf -= action->address;
13554            case kAddressSpace_EEPROM:
13555               {
13556                  int      length;
13557                  UINT8 *   buf;
1085113558
10852         if(buf)
10853         {
10854            if(TEST_FIELD(cheatOptions, Debug))
10855            {
10856               if(ControlKeyPressed())
10857                  ui_popup_time(1,"PG : %x : %p", parameter, buf);
10858            }
13559                  buf = eeprom_get_data_pointer(&length);
1085913560
10860            return DoMemoryRead(buf, action->address, bytes, CPUNeedsSwap(parameter) ^ swapBytes, GetCPUInfo(parameter));
13561                  if(IsAddressInRange(action, length))
13562                  {
13563                     if(action->flags & kActionFlag_PDWWrite)
13564                     {
13565                        if(action->flags & kActionFlag_IsFirst)
13566                        {
13567                           address += bytes;
13568                           bytes = EXTRACT_FIELD(action->type, IndexSize) + 1;
13569                           action->flags &= ~kActionFlag_IsFirst;
13570                        }
13571                        else
13572                           action->flags |= kActionFlag_IsFirst;
13573                     }
13574
13575                     return DoMemoryRead(buf, address, bytes, 0, &raw_cpu_info);
13576                  }
13577               }
13578               break;
1086113579         }
1086213580      }
10863      break;
13581      else
13582      {
13583         /* read a data from region */
13584         UINT8 * buf = memory_region(action->region);
1086413585
10865      case kLocation_Custom:
10866      {
10867         switch(parameter)
13586         if(buf && IsAddressInRange(action, memory_region_length(action->region)))
1086813587         {
10869            case kCustomLocation_Comment:
10870               break;
10871
10872            case kCustomLocation_EEPROM:
13588            if(action->flags & kActionFlag_PDWWrite)
1087313589            {
10874               int      length;
10875               UINT8   * buf;
13590               if(action->flags & kActionFlag_IsFirst)
13591               {
13592                  address += bytes;
13593                  bytes = EXTRACT_FIELD(action->type, IndexSize) + 1;
13594                  action->flags &= ~kActionFlag_IsFirst;
13595               }
13596               else
13597                  action->flags |= kActionFlag_IsFirst;
1087613598
10877               buf = EEPROM_get_data_pointer(&length);
10878
10879               if(IsAddressInRange(action, length))
10880                  return DoMemoryRead(buf, action->address, bytes, swapBytes, &rawCPUInfo);
13599               return DoMemoryRead(buf, address, bytes, region_needs_swap(action->region), get_region_info(action->region));
1088113600            }
10882            break;
13601            else
13602               return DoMemoryRead(buf, address, bytes, region_needs_swap(action->region), get_region_info(action->region));
1088313603         }
1088413604      }
10885      break;
10886
10887      default:
10888         break;
1088913605   }
13606   else
13607      /* read a data from variable */
13608      return (cheatVariable[action->address] & kCheatSizeMaskTable[EXTRACT_FIELD(action->type, AddressSize)]);
1089013609
1089113610   return 0;
1089213611}
1089313612
10894/*--------------------------------------
10895  WriteData - write a data per region
10896--------------------------------------*/
13613/*-------------------------------------
13614  WriteData - write a data to memory
13615-------------------------------------*/
1089713616
1089813617static void WriteData(CheatAction * action, UINT32 data)
1089913618{
10900   UINT8   parameter = EXTRACT_FIELD(action->type, LocationParameter);
10901   UINT8   bytes = EXTRACT_FIELD(action->type, BytesUsed) + 1;
10902   UINT8   swapBytes = EXTRACT_FIELD(action->type, Endianness);
13619   UINT8   addressRead =   EXTRACT_FIELD(action->type, AddressRead);
13620   UINT8   bytes =         EXTRACT_FIELD(action->type, AddressSize) + 1;
1090313621
10904   switch(EXTRACT_FIELD(action->type, LocationType))
13622   if(EXTRACT_FIELD(action->type, AddressRead) != kReadFrom_Variable)
1090513623   {
10906      case kLocation_Standard:
10907         DoCPUWrite(data, parameter, action->address, bytes, CPUNeedsSwap(parameter) ^ swapBytes);
13624      /* write a data to memory */
13625      int address = ~0;
1090813626
10909         break;
13627      if(addressRead == kReadFrom_Address)      address = action->address;
13628      else if(addressRead == kReadFrom_Index)      address = cheatVariable[action->address];
1091013629
10911      case kLocation_MemoryRegion:
13630      if(!TEST_FIELD(action->region, RegionFlag))
1091213631      {
10913         int      region = REGION_CPU1 + parameter;
10914         UINT8   * buf = memory_region(region);
13632         UINT8 cpu = EXTRACT_FIELD(action->region, CPUIndex);
1091513633
10916         if(buf)
13634         switch(EXTRACT_FIELD(action->region, AddressSpace))
1091713635         {
10918            if(IsAddressInRange(action, memory_region_length(region)))
10919               DoMemoryWrite(data, buf, action->address, bytes, RegionNeedsSwap(region) ^ swapBytes, GetRegionCPUInfo(region));
10920         }
10921      }
10922      break;
13636            case kAddressSpace_Program:
13637               if(action->flags & kActionFlag_IndexAddress)
13638               {
13639                  int indexAddress;
1092313640
10924      case kLocation_HandlerMemory:
10925      {
10926         UINT32   relativeAddress;
10927         UINT8   ** buf;
13641                  cpu_region_info *info = get_cpu_info(cpu);
1092813642
10929         if(!action->cachedPointer)
10930         {
10931            action->cachedPointer = LookupHandlerMemory(parameter, action->address, &action->cachedOffset);
10932         }
13643                  indexAddress = DoCPURead(cpu, address, EXTRACT_FIELD(action->type, IndexSize) + 1, cpu_needs_swap(cpu));
1093313644
10934         buf = action->cachedPointer;
10935         relativeAddress = action->cachedOffset;
13645                  if(info && info->address_shift)
13646                     indexAddress = DoShift(indexAddress, info->address_shift);
1093613647
10937         if(buf && *buf)
10938            DoMemoryWrite(data, *buf, relativeAddress, bytes, CPUNeedsSwap(parameter) ^ swapBytes, GetCPUInfo(parameter));
10939      }
10940      break;
13648                  if(indexAddress)
13649                  {
13650                     indexAddress += action->extendData;
13651                     DoCPUWrite(data, cpu, indexAddress, bytes, cpu_needs_swap(cpu));
13652                  }
13653               }
13654               else if(action->flags & kActionFlag_PDWWrite)
13655               {
13656                  if(action->flags & kActionFlag_IsFirst)
13657                  {
13658                     address += bytes;
13659                     bytes = EXTRACT_FIELD(action->type, IndexSize) + 1;
13660                     action->flags &= ~kActionFlag_IsFirst;
13661                  }
13662                  else
13663                     action->flags |= kActionFlag_IsFirst;
1094113664
10942      case kLocation_IndirectIndexed:
10943      {
10944         UINT32   address;
10945         INT32   offset = action->extendData;
10946         UINT8   cpu = (parameter >> 2) & 0x7;
10947         UINT8   addressBytes = (parameter & 0x3) + 1;
10948         CPUInfo   * info = GetCPUInfo(cpu);
13665                  DoCPUWrite(data, cpu, address, bytes, cpu_needs_swap(cpu));
13666               }
13667               else
13668               {
13669                  DoCPUWrite(data, cpu, address, bytes, cpu_needs_swap(cpu));
13670               }
13671               break;
1094913672
10950         address = DoCPURead(cpu, action->address, addressBytes, CPUNeedsSwap(cpu) ^ swapBytes);
13673            case kAddressSpace_DataSpace:
13674            case kAddressSpace_IOSpace:
13675            case kAddressSpace_OpcodeRAM:
13676            case kAddressSpace_DirectMemory:
13677               {
13678                  UINT8 * buf;
1095113679
10952         if(info)
10953            address = DoShift(address, info->addressShift);
13680                  action->cachedPointer = GetMemoryRegionBasePointer(cpu, EXTRACT_FIELD(action->type, AddressSpace), address);
13681                  buf = (UINT8 *) action->cachedPointer;
1095413682
10955         if(address)
10956         {
10957            address += offset;
13683                  if(buf)
13684                  {
13685                     if(action->flags & kActionFlag_PDWWrite)
13686                     {
13687                        if(action->flags & kActionFlag_IsFirst)
13688                        {
13689                           address += bytes;
13690                           bytes = EXTRACT_FIELD(action->type, IndexSize) + 1;
13691                           action->flags &= ~kActionFlag_IsFirst;
13692                        }
13693                        else
13694                           action->flags |= kActionFlag_IsFirst;
13695                     }
1095813696
10959            DoCPUWrite(data, cpu, address, bytes, CPUNeedsSwap(cpu) ^ swapBytes);
10960         }
10961      }
10962      break;
13697                     DoMemoryWrite(data, buf, address, bytes, cpu_needs_swap(cpu), get_cpu_info(cpu));
13698                  }
13699               }
13700               break;
1096313701
10964      case kLocation_ProgramSpace:
10965      {
10966         UINT8   * buf;
13702            case kAddressSpace_MappedMemory:
13703               {
13704                  int         relativeAddress;
13705                  UINT8 **   buf;
1096713706
10968         memory_set_opbase(action->address);
13707                  action->cachedPointer = LookupHandlerMemory(cpu, address, &action->cachedOffset);
13708                  buf = action->cachedPointer;
13709                  relativeAddress = action->cachedOffset;
1096913710
10970         buf = memory_get_op_ptr(parameter, action->address, 0);
13711                  if(buf && *buf)
13712                  {
13713                     if(action->flags & kActionFlag_PDWWrite)
13714                     {
13715                        if(action->flags & kActionFlag_IsFirst)
13716                        {
13717                           relativeAddress += bytes;
13718                           bytes = EXTRACT_FIELD(action->type, IndexSize) + 1;
13719                           action->flags &= ~kActionFlag_IsFirst;
13720                        }
13721                        else
13722                           action->flags |= kActionFlag_IsFirst;
13723                     }
1097113724
10972         buf -= action->address;
13725                     DoMemoryWrite(data, *buf, relativeAddress, bytes, cpu_needs_swap(cpu), get_cpu_info(cpu));
13726                     return;
13727                  }
13728               }
13729               break;
1097313730
10974         if(buf)
10975            DoMemoryWrite(data, buf, action->address, bytes, CPUNeedsSwap(parameter) ^ swapBytes, GetCPUInfo(parameter));
13731            case kAddressSpace_EEPROM:
13732               {
13733                  int      length;
13734                  UINT8 *   buf;
13735
13736                  buf = eeprom_get_data_pointer(&length);
13737
13738                  if(IsAddressInRange(action, length))
13739                  {
13740                     if(action->flags & kActionFlag_PDWWrite)
13741                     {
13742                        if(action->flags & kActionFlag_IsFirst)
13743                        {
13744                           address += bytes;
13745                           bytes = EXTRACT_FIELD(action->type, IndexSize) + 1;
13746                           action->flags &= ~kActionFlag_IsFirst;
13747                        }
13748                        else
13749                           action->flags |= kActionFlag_IsFirst;
13750                     }
13751
13752                     DoMemoryWrite(data, buf, address, bytes, 0, &raw_cpu_info);
13753                     return;
13754                  }
13755               }
13756               break;
13757         }
1097613758      }
10977      break;
13759      else
13760      {
13761         /* write a data into region */
13762         UINT8 * buf = memory_region(action->region);
1097813763
10979      case kLocation_Custom:
10980      {
10981         switch(parameter)
13764         if(buf && IsAddressInRange(action, memory_region_length(action->region)))
1098213765         {
10983            case kCustomLocation_Comment:
10984               break;
10985
10986            case kCustomLocation_EEPROM:
13766            if(action->flags & kActionFlag_PDWWrite)
1098713767            {
10988               int      length;
10989               UINT8   * buf;
13768               if(action->flags & kActionFlag_IsFirst)
13769               {
13770                  address += bytes;
13771                  bytes = EXTRACT_FIELD(action->type, IndexSize) + 1;
13772                  action->flags &= ~kActionFlag_IsFirst;
13773               }
13774               else
13775                  action->flags |= kActionFlag_IsFirst;
13776            }
1099013777
10991               buf = EEPROM_get_data_pointer(&length);
10992
10993               if(IsAddressInRange(action, length))
10994                  DoMemoryWrite(data, buf, action->address, bytes, swapBytes, &rawCPUInfo);
10995            }
10996            break;
13778            DoMemoryWrite(data, buf, address, bytes, region_needs_swap(action->region), get_region_info(action->region));
13779            return;
1099713780         }
1099813781      }
10999      break;
11000
11001      default:
11002         break;
1100313782   }
13783   else
13784      cheatVariable[action->address] = data & kCheatSizeMaskTable[EXTRACT_FIELD(action->type, AddressSize)];
1100413785}
1100513786
11006/*-----------------------------------------------------
11007  WatchCheatEntry - set watchpoint from action entry
11008-----------------------------------------------------*/
13787/*------------------------------------------------------------------------------------
13788  WatchCheatEntry - set watchpoint when watch value key is pressed in several menus
13789------------------------------------------------------------------------------------*/
1100913790
1101013791static void WatchCheatEntry(CheatEntry * entry, UINT8 associate)
1101113792{
11012   UINT32      i, j;
13793   int         i, j;
1101313794   CheatEntry   * associateEntry = NULL;
1101413795
13796   /* NOTE : calling with associate = 1 doesn't exist right now */
1101513797   if(associate)
1101613798      associateEntry = entry;
1101713799
1101813800   if(!entry)
13801   {
13802      messageType = kCheatMessage_FailedToAdd;
13803      messageTimer = DEFAULT_MESSAGE_TIME;
1101913804      return;
13805   }
1102013806
1102113807   for(i = 0; i < entry->actionListLength; i++)
1102213808   {
11023      if(!i)
11024         /* ----- first action entry ----- */
11025         AddActionWatch(&entry->actionList[i], associateEntry);
11026      else
13809      CheatAction * action = &entry->actionList[i];
13810
13811      if(!(action->flags & kActionFlag_NoAction) && !EXTRACT_FIELD(action->type, AddressRead))
1102713812      {
11028         /* ----- 2nd or later action entry ----- */
11029         UINT8   sameAddress = 0;
13813         /* NOTE : unsupported the watchpoint for indirect index right now */
13814         if((action->flags & kActionFlag_IndexAddress) && action->extendData != ~0)
13815            continue;
1103013816
11031         for(j = 0; j < i; j++)
13817         if(!i)
1103213818         {
11033            /* ----- if we find the same address action entry, skip it ----- */
11034            if(entry->actionList[j].address == entry->actionList[i].address)
11035               sameAddress = 1;
13819            /* first CheatAction */
13820            AddActionWatch(&entry->actionList[i], associateEntry);
1103613821         }
13822         else
13823         {
13824            /* 2nd or later CheatAction */
13825            UINT8 differentAddress = 1;
1103713826
11038         if(!sameAddress)
11039            AddActionWatch(&entry->actionList[i], associateEntry);
13827            for(j = 0; j < i; j++)
13828            {
13829               /* if we find the same address CheatAction, skip it */
13830               if(entry->actionList[j].address == entry->actionList[i].address)
13831                  differentAddress = 0;
13832            }
13833
13834            if(differentAddress)
13835               AddActionWatch(&entry->actionList[i], associateEntry);
13836         }
1104013837      }
1104113838   }
13839
13840   messageType = kCheatMessage_SucceededToAdd;
13841   messageTimer = DEFAULT_MESSAGE_TIME;
1104213842}
1104313843
11044/*--------------------------------------------------
11045  AddActionWatch - add watchpoint into watch list
11046--------------------------------------------------*/
13844/*-----------------------------------------------------------------------
13845  AddActionWatch - set watchpoint parameters into WatchInfo.
13846                   called from WatchCheatEntry() when watch value key
13847                   or ActivateCheat() via watchpoint code.
13848-----------------------------------------------------------------------*/
1104713849
1104813850static void AddActionWatch(CheatAction * action, CheatEntry * entry)
1104913851{
11050   if(   (EXTRACT_FIELD(action->type, LocationType) == kLocation_Standard) ||
11051      (EXTRACT_FIELD(action->type, LocationType) == kLocation_MemoryRegion) ||
11052      (EXTRACT_FIELD(action->type, LocationType) == kLocation_IndirectIndexed) ||
11053      (EXTRACT_FIELD(action->type, LocationType) == kLocation_ProgramSpace))
11054
13852   switch(EXTRACT_FIELD(action->type, CodeType))
1105513853   {
11056      WatchInfo   * info = GetUnusedWatch();
13854      case kCodeType_Write:
13855      case kCodeType_PDWWrite:
13856      case kCodeType_RWrite:
13857      case kCodeType_IWrite:
13858      case kCodeType_CWrite:
13859      case kCodeType_VWrite:
13860      case kCodeType_VRWrite:
13861      case kCodeType_Branch:
13862      case kCodeType_Move:
13863      case kCodeType_Loop:
13864      case kCodeType_Popup:
13865         {
13866            WatchInfo   * info = GetUnusedWatch();
1105713867
11058      info->address =         action->address;
11059      info->cpu =            EXTRACT_FIELD(action->type, LocationParameter);
11060      info->displayType =      kWatchDisplayType_Hex;
11061      info->elementBytes =   kByteConversionTable[EXTRACT_FIELD(action->type, BytesUsed)];
11062      info->label[0] =      0;
11063      info->labelType =      kWatchLabel_None;
11064      info->linkedCheat =      entry;
11065      info->numElements =      1;
11066      info->skip =         0;
13868            info->address      = action->address;
13869            info->cpu         = action->region;
13870            info->displayType   = kWatchDisplayType_Hex;
13871            info->elementBytes   = kSearchSize_8Bit;
13872            info->label[0]      = 0;
13873            info->labelType      = kWatchLabel_None;
13874            info->numElements   = EXTRACT_FIELD(action->type, AddressSize) + 1;
13875            info->linkedCheat   = entry;
13876            info->skip         = 0;
1106713877
11068      info->locationType =   EXTRACT_FIELD(action->type, LocationType);
13878            if(action->flags & kActionFlag_PDWWrite)
13879            {
13880               info->numElements += (EXTRACT_FIELD(action->type, IndexSize) + 1);
13881            }
13882            else if(action->flags & kActionFlag_Repeat)
13883            {
13884               info->numElements   = EXTRACT_FIELD(action->extendData, LSB16);
13885               info->skip         = EXTRACT_FIELD(action->extendData, MSB16) - 1;
13886            }
13887         }
13888         break;
1106913889
11070      if(EXTRACT_FIELD(action->type, Type) == kType_Watch)
11071      {
11072         /* ----- set watchpoint from watch code ----- */
11073         UINT32   typeParameter = EXTRACT_FIELD(action->type, TypeParameter);
13890      case kCodeType_Watch:
13891         {
13892            WatchInfo * info = GetUnusedWatch();
1107413893
11075         info->numElements = (action->data & 0xFF) + 1;
13894            info->address         = action->address;
13895            info->cpu            = EXTRACT_FIELD(action->type, CPURegion);
13896            info->displayType      = EXTRACT_FIELD(action->type, WatchDisplayFormat);
13897            info->elementBytes      = kByteConversionTable[EXTRACT_FIELD(action->type, AddressSize)];
13898            info->label[0]         = 0;
13899            info->linkedCheat      = entry;
13900            info->numElements      = EXTRACT_FIELD(action->data, WatchNumElements) + 1;
13901            info->skip            = EXTRACT_FIELD(action->data, WatchSkip);
13902            info->elementsPerLine   = EXTRACT_FIELD(action->data, WatchElementsPerLine);
13903            info->addValue         = EXTRACT_FIELD(action->data, WatchAddValue);
1107613904
11077         info->skip = (action->data >> 8) & 0xFF;
11078         info->elementsPerLine = (action->data >> 16) & 0xFF;
11079         info->addValue = (action->data >> 24) & 0xFF;
13905            if(info->addValue & 0x80)
13906               info->addValue |= ~0xFF;
1108013907
11081         if(info->addValue & 0x80)
11082            info->addValue |= ~0xFF;
13908            if(action->extendData != ~0)
13909            {
13910               /* ### fix me... ### */
13911               info->x = (float)(EXTRACT_FIELD(action->extendData, LSB16)) / 100;
13912               info->y = (float)(EXTRACT_FIELD(action->extendData, MSB16)) / 100;
13913            }
1108313914
11084         if(action->extendData != 0xFFFFFFFF)
11085         {
11086            /* ### fix me... ### */
11087            info->x = (float)((action->extendData >> 16) & 0xFFFF)/100;
11088            info->y = (float)((action->extendData >>  0) & 0xFFFF)/100;
13915            if(TEST_FIELD(action->type, WatchShowLabel) && entry->comment && strlen(entry->comment) < 256)
13916            {
13917               info->labelType = kWatchLabel_String;
13918               strcpy(info->label, entry->comment);
13919            }
13920            else
13921               info->labelType = kWatchLabel_None;
1108913922         }
11090
11091         /* ----- if label is needed, copy the description from comment field ----- */
11092         if((typeParameter & 0x04) && (entry->comment) && (strlen(entry->comment) < 256))
11093         {
11094            info->labelType = kWatchLabel_String;
11095            strcpy(info->label, entry->comment);
11096         }
11097
11098         info->displayType = typeParameter & 0x03;
11099      }
13923         break;
1110013924   }
1110113925}
1110213926
11103/*-----------------------------------------------------------------
11104  RemoveAssociatedWatches - remove watchpoint when CODE is "OFF"
11105-----------------------------------------------------------------*/
13927/*------------------------------------------------------------------------------
13928  RemoveAssociatedWatches - delete watchpoints when watchpoint code is "OFF".
13929                            called from DeactivateCheat().
13930------------------------------------------------------------------------------*/
1110613931
1110713932static void RemoveAssociatedWatches(CheatEntry * entry)
1110813933{
11109   int   i;
13934   int i;
1111013935
1111113936   for(i = watchListLength - 1; i >= 0; i--)
1111213937   {
11113      WatchInfo   * info = &watchList[i];
13938      WatchInfo * info = &watchList[i];
1111413939
1111513940      if(info->linkedCheat == entry)
1111613941         DeleteWatchAt(i);
1111713942   }
1111813943}
1111913944
11120/*----------------------------------------------------------------------
11121  ResetAction - back up data and set action flags when turn CODE "ON"
11122----------------------------------------------------------------------*/
13945/*--------------------------------------------------
13946  ResetAction - back up data and set action flags
13947--------------------------------------------------*/
1112313948
1112413949static void ResetAction(CheatAction * action)
1112513950{
11126   action->frameTimer = 0;
13951   if(action->flags & kActionFlag_NoAction)
13952      return;
1112713953
11128   /* ----- backup value ----- */
13954   /* back up a value */
1112913955   if(!(action->flags & kActionFlag_LastValueGood))
11130      action->lastValue = ReadData(action);
13956   {
13957      switch(EXTRACT_FIELD(action->type, CodeType))
13958      {
13959         default:
13960            action->lastValue = malloc_or_die(sizeof(action->lastValue));
13961            action->lastValue[0] = ReadData(action);
13962            break;
1113113963
13964         case kCodeType_PDWWrite:
13965            action->lastValue = malloc_or_die(sizeof(action->lastValue) * 2);
13966            action->lastValue[0] = ReadData(action);
13967            action->lastValue[1] = ReadData(action);
13968            break;
13969
13970         case kCodeType_RWrite:
13971         case kCodeType_VRWrite:
13972            {
13973               int i;
13974
13975               for(i = 0; i < EXTRACT_FIELD(action->extendData, LSB16); i++)
13976               {
13977                  action->lastValue = realloc(action->lastValue, sizeof(action->lastValue) * EXTRACT_FIELD(action->extendData, LSB16));
13978                  action->lastValue[i] = ReadData(action);
13979                  action->address +=   EXTRACT_FIELD(action->extendData, MSB16) ?
13980                                 EXTRACT_FIELD(action->extendData, MSB16) :
13981                                 kSearchByteIncrementTable[EXTRACT_FIELD(action->type, AddressSize)];
13982               }
13983               action->address = action->originalAddress;
13984            }
13985            break;
13986      }
13987   }
13988
13989   action->frameTimer = 0;
1113213990   action->flags &= ~kActionFlag_StateMask;
1113313991   action->flags |= kActionFlag_LastValueGood;
13992
13993   if(action->flags & kActionFlag_CheckCondition)
13994   {
13995      if(EXTRACT_FIELD(action->type, CodeParameter) == kCondition_PreviousValue)
13996      {
13997         if(EXTRACT_FIELD(action->type, CodeType) == kCodeType_CWrite)
13998            action->extendData = ReadData(action);
13999         else
14000            action->data = ReadData(action);
14001      }
14002   }
1113414003}
1113514004
1113614005/*-------------------------------------------------------------------------------------
r2762r2763
1114314012
1114414013   for(i = 0; i < entry->actionListLength; i++)
1114514014   {
11146      CheatAction   * action = &entry->actionList[i];
14015      CheatAction * action = &entry->actionList[i];
1114714016
1114814017      ResetAction(action);
1114914018
11150      /* ----- if watchpoint code, add watchpoint ----- */
11151      if(EXTRACT_FIELD(action->type, Type) == kType_Watch)
14019      /* if watchpoint code, add watchpoint */
14020      if(EXTRACT_FIELD(action->type, CodeType) == kCodeType_Watch)
1115214021         AddActionWatch(action, entry);
1115314022   }
1115414023
14024   /* set activate flag */
1115514025   entry->flags |= kCheatFlag_Active;
1115614026}
1115714027
r2762r2763
1116114031
1116214032static void DeactivateCheat(CheatEntry * entry)
1116314033{
11164   int   i;
14034   int i;
1116514035
1116614036   for(i = 0; i < entry->actionListLength; i++)
1116714037   {
11168      CheatAction   * action = &entry->actionList[i];
14038      CheatAction * action = &entry->actionList[i];
1116914039
11170      /* ----- restore previous value and clear backup flag if needed ----- */
11171      if(EXTRACT_FIELD(action->type, RestorePreviousValue) && (action->flags & kActionFlag_LastValueGood))
14040      /* restore previous value and clear backup flag if needed */
14041      if(TEST_FIELD(action->type, RestoreValue) && (action->flags & kActionFlag_LastValueGood))
1117214042      {
11173         WriteData(action, action->lastValue);
14043         switch(EXTRACT_FIELD(action->type, CodeType))
14044         {
14045            default:
14046               WriteData(action, (UINT32)action->lastValue[0]);
14047               break;
1117414048
14049            case kCodeType_PDWWrite:
14050               WriteData(action, (UINT32)action->lastValue[0]);
14051               WriteData(action, (UINT32)action->lastValue[1]);
14052               break;
14053
14054            case kCodeType_RWrite:
14055            case kCodeType_VRWrite:
14056               {
14057                  int j;
14058
14059                  for(j = 0; j < EXTRACT_FIELD(action->extendData, LSB16); j++)
14060                  {
14061                     WriteData(action, (UINT32)action->lastValue[j]);
14062                     action->address +=   EXTRACT_FIELD(action->extendData, MSB16) ?
14063                                    EXTRACT_FIELD(action->extendData, MSB16) :
14064                                    kSearchByteIncrementTable[EXTRACT_FIELD(action->type, AddressSize)];
14065                  }
14066                  action->address = action->originalAddress;
14067               }
14068               break;
14069         }
1117514070         action->flags &= ~kActionFlag_LastValueGood;
1117614071      }
14072      free(action->lastValue);
14073      action->lastValue = NULL;
1117714074   }
1117814075
11179   /* ----- remove watchpoint ----- */
14076   /* remove watchpoint */
1118014077   RemoveAssociatedWatches(entry);
1118114078
14079   /* clear active flag */
1118214080   entry->flags &= ~kCheatFlag_StateMask;
1118314081}
1118414082
r2762r2763
1119014088{
1119114089   if(entry->flags & kCheatFlag_Active)
1119214090   {
11193      int   i;
14091      int i;
1119414092
1119514093      for(i = 0; i < entry->actionListLength; i++)
1119614094      {
11197         CheatAction   * action = &entry->actionList[i];
14095         CheatAction * action = &entry->actionList[i];
1119814096
11199         /* ----- restore previous value if needed ----- */
11200         if(EXTRACT_FIELD(action->type, RestorePreviousValue) && (action->flags & kActionFlag_LastValueGood))
11201            WriteData(action, action->lastValue);
14097         action->frameTimer = 0;
14098         action->flags &= ~kActionFlag_OperationDone;
14099
14100         /* restore previous value if needed */
14101         switch(EXTRACT_FIELD(action->type, CodeType))
14102         {
14103            default:
14104               WriteData(action, (UINT32)action->lastValue[0]);
14105               break;
14106
14107            case kCodeType_PDWWrite:
14108               WriteData(action, (UINT32)action->lastValue[0]);
14109               WriteData(action, (UINT32)action->lastValue[1]);
14110               break;
14111
14112            case kCodeType_RWrite:
14113            case kCodeType_VRWrite:
14114               {
14115                  int j;
14116
14117                  for(j = 0; j < EXTRACT_FIELD(action->extendData, LSB16); j++)
14118                  {
14119                     WriteData(action, (UINT32)action->lastValue[j]);
14120                     action->address +=   EXTRACT_FIELD(action->extendData, MSB16) ?
14121                                    EXTRACT_FIELD(action->extendData, MSB16) :
14122                                    kSearchByteIncrementTable[EXTRACT_FIELD(action->type, AddressSize)];
14123                  }
14124                  action->address = action->originalAddress;
14125               }
14126               break;
14127         }
1120214128      }
1120314129   }
1120414130}
1120514131
14132
1120614133/*------------------------------------------------------------
1120714134  cheat_periodicOperation - management for cheat operations
1120814135------------------------------------------------------------*/
1120914136
1121014137static void cheat_periodicOperation(CheatAction * action)
1121114138{
11212   UINT8   operation = EXTRACT_FIELD(action->type, Operation) | (EXTRACT_FIELD(action->type, OperationExtend) << 2);
14139   int data = TEST_FIELD(action->type, DataRead) ? cheatVariable[action->data] : action->data;
1121314140
11214   switch(operation)
14141   if(action->flags & kActionFlag_PDWWrite)
1121514142   {
11216      case kOperation_WriteMask:
14143      action->flags &= ~kActionFlag_IsFirst;
14144      WriteData(action, data);
14145      WriteData(action, action->extendData);
14146   }
14147   else if(action->flags & kActionFlag_Repeat)
14148   {
14149      int i;
14150
14151      for(i = 0; i < EXTRACT_FIELD(action->extendData, LSB16); i++)
1121714152      {
11218         UINT32   temp;
14153         WriteData(action, data);
14154         action->address +=   EXTRACT_FIELD(action->extendData, MSB16) ?
14155                        EXTRACT_FIELD(action->extendData, MSB16) :
14156                        kSearchByteIncrementTable[EXTRACT_FIELD(action->type, AddressSize)];
14157      }
14158      action->address = action->originalAddress;
14159   }
14160   else
14161   {
14162      switch(EXTRACT_FIELD(action->type, CodeType))
14163      {
14164         case kCodeType_Write:
14165            WriteData(action, (data & action->extendData) | (ReadData(action) & ~action->extendData));
14166            break;
1121914167
11220         if(action->flags & kActionFlag_IgnoreMask)
11221            WriteData(action, action->data);
11222         else
11223         {
11224            temp = ReadData(action);
14168         case kCodeType_IWrite:
14169            switch(EXTRACT_FIELD(action->type, CodeParameter))
14170            {
14171               case kIWrite_Write:
14172                  WriteData(action, data);
14173                  break;
1122514174
11226            temp = (action->data & action->extendData) | (temp & ~action->extendData);
14175               case kIWrite_BitSet:
14176                  WriteData(action, ReadData(action) | data);
14177                  break;
1122714178
11228            WriteData(action, temp);
11229         }
11230      }
11231      break;
14179               case kIWrite_BitClear:
14180                  WriteData(action, ReadData(action) & ~data);
14181                  break;
1123214182
11233      case kOperation_AddSubtract:
11234      {
11235         //INT32 temp, bound;
14183               case kIWrite_LimitedMask:
14184                  WriteData(action, (EXTRACT_FIELD(data, MSB16) & EXTRACT_FIELD(data, LSB16)) | (ReadData(action) & ~EXTRACT_FIELD(data, LSB16)));
14185                  break;
14186            }
14187            break;
1123614188
11237         /* ----- if extend data field is invalid, direct return ----- */
11238         //if(action->flags & kActionFlag_IgnoreMask)
11239            return;
14189         case kCodeType_CWrite:
14190         case kCodeType_VWrite:
14191            WriteData(action, data);
14192            break;
1124014193
11241         /* FIXME: AddSubstract looks seriously broken
11242             *        and being worked on. */
11243#if 0
11244         temp = ReadData(action);
14194         case kCodeType_Move:
14195            cheatVariable[EXTRACT_FIELD(action->type, CodeParameter)] = ReadData(action) + data;
14196            break;
1124514197
11246         /* ----- OperationParameter field stores add/subtract ----- */
11247         if(TEST_FIELD(action->type, OperationParameter))
11248         {
11249            /* ----- subtract ----- */
11250            bound = action->extendData + action->data;
14198         case kCodeType_Popup:
14199            switch(EXTRACT_FIELD(action->type, PopupParameter))
14200            {
14201               case kPopup_Label:
14202                  ui_popup_time(1, "%s", action->optionalName);
14203                  break;
1125114204
11252            if(temp > bound)
11253               temp -= action->data;
11254         }
11255         else
11256         {
11257            /* ----- add ----- */
11258            bound = action->extendData - action->data;
14205               case kPopup_Value:
14206                  ui_popup_time(1, "%*.*X",
14207                              kCheatSizeDigitsTable[EXTRACT_FIELD(action->type, AddressRead)],
14208                              kCheatSizeDigitsTable[EXTRACT_FIELD(action->type, AddressRead)],
14209                              ReadData(action));
14210                  break;
1125914211
11260            if(temp < bound)
11261               temp += action->data;
11262         }
14212               case kPopup_LabelValue:
14213                  ui_popup_time(1, "%s %*.*X",
14214                              action->optionalName,
14215                              kCheatSizeDigitsTable[EXTRACT_FIELD(action->type, AddressRead)],
14216                              kCheatSizeDigitsTable[EXTRACT_FIELD(action->type, AddressRead)],
14217                              ReadData(action));
14218                  break;
1126314219
11264         WriteData(action, temp);
14220               case kPopup_ValueLabel:
14221                  ui_popup_time(1, "%*.*X %s",
14222                              kCheatSizeDigitsTable[EXTRACT_FIELD(action->type, AddressRead)],
14223                              kCheatSizeDigitsTable[EXTRACT_FIELD(action->type, AddressRead)],
14224                              ReadData(action),
14225                              action->optionalName);
14226                  break;
14227            }
14228            break;
14229#ifdef MAME_DEBUG
14230         default:
14231            ui_popup_time(1, "Invalid CodeType : %X", EXTRACT_FIELD(action->type, CodeType));
1126514232#endif
1126614233      }
11267      break;
14234   }
14235}
1126814236
11269      case kOperation_ForceRange:
11270      {
11271         UINT32   temp;
14237/*------------------------------------------------------------
14238  cheat_periodicCondition - management for cheat conditions
14239                            used by CWrite, Branch, Popup
14240------------------------------------------------------------*/
1127214241
11273         /* ----- if extend data field is invalid, direct return ----- */
11274         if(action->flags & kActionFlag_IgnoreMask)
11275            return;
14242static UINT8 cheat_periodicCondition(CheatAction * action)
14243{
14244   int   data   = ReadData(action);
14245   int   value   = EXTRACT_FIELD(action->type, CodeType) == kCodeType_CWrite ? action->extendData : action->data;
1127614246
11277         temp = ReadData(action);
14247   switch(EXTRACT_FIELD(action->type, CodeParameter))
14248   {
14249      case kCondition_Equal:
14250         return (data == value);
1127814251
11279         if(!TEST_FIELD(action->type, BytesUsed))
11280         {
11281            /* ----- 8 bit ----- */
11282            if(   (temp < ((action->extendData >> 8) & 0xFF)) || (temp > ((action->extendData >> 0) & 0xFF)))
11283            {
11284               temp = action->data;
14252      case kCondition_NotEqual:
14253         return (data != value);
1128514254
11286               WriteData(action, temp);
11287            }
11288         }
11289         else
11290         {
11291            /* ----- 16 bit (or 24, 32 bit) ----- */
11292            if(   (temp < ((action->extendData >> 16) & 0xFFFF)) || (temp > ((action->extendData >> 0) & 0xFFFF)))
11293            {
11294               temp = action->data;
14255      case kCondition_Less:
14256         return (data < value);
1129514257
11296               WriteData(action, temp);
11297            }
11298         }
11299      }
11300      break;
14258      case kCondition_LessOrEqual:
14259         return (data <= value);
1130114260
11302      case kOperation_SetOrClearBits:
11303      {
11304         UINT32   temp;
14261      case kCondition_Greater:
14262         return (data > value);
1130514263
11306         temp = ReadData(action);
14264      case kCondition_GreaterOrEqual:
14265         return (data >= value);
1130714266
11308         if(TEST_FIELD(action->type, OperationParameter))
11309            /* ----- clear bit ----- */
11310            temp &= ~action->data;
11311         else
11312            /* ----- set bit ----- */
11313            temp |= action->data;
14267      case kCondition_BitSet:
14268         return (data & value);
1131414269
11315         WriteData(action, temp);
11316      }
11317      break;
14270      case kCondition_BitClear:
14271         return (!(data & value));
1131814272
11319      case kOperation_WriteMatch:
11320      {
11321         UINT32   temp;
11322
11323         /* ----- if extend data field is invalid, direct return ----- */
11324         if(action->flags & kActionFlag_IgnoreMask)
11325            return;
11326
11327         temp = ReadData(action);
11328
11329         /* ----- if current value matches appointed value, write ----- */
11330         if(temp == action->extendData)
14273      case kCondition_PreviousValue:
14274         if(data != value)
1133114275         {
11332            temp = action->data;
14276            if(EXTRACT_FIELD(action->type, CodeType) == kCodeType_CWrite)
14277               action->extendData = data;
14278            else
14279               action->data = data;
1133314280
11334            WriteData(action, temp);
14281            return 1;
1133514282         }
11336      }
11337      break;
11338
11339      case kOperation_None:
1134014283         break;
1134114284
11342      default:
11343         break;
14285      case kCondition_KeyPressedOnce:
14286         return (input_code_pressed_once(value));
14287
14288      case kCondition_KeyPressedRepeat:
14289         return (input_code_pressed(value));
14290
14291      case kCondition_True:
14292         return 1;
1134414293   }
14294
14295   return 0;
1134514296}
1134614297
1134714298/*------------------------------------------------------
1134814299  cheat_periodicAction - management for cheat actions
1134914300------------------------------------------------------*/
1135014301
11351static void cheat_periodicAction(running_machine *machine, CheatAction * action)
14302static int cheat_periodicAction(running_machine *machine, CheatAction * action, int selection)
1135214303{
11353   UINT8   parameter = EXTRACT_FIELD(action->type, TypeParameter);
14304   UINT8 executeOperation = 0;
1135414305
11355   /* ----- if operation is done in case of one shot, no action ----- */
11356   if(action->flags & kActionFlag_OperationDone)
11357      return;
14306   if(driverSpecifiedFlag)
14307      return (TEST_FIELD(action->type, Return) ? CHEAT_RETURN_VALUE : selection + 1);
1135814308
11359   if(TEST_FIELD(action->type, Prefill) && (!(action->flags & kActionFlag_PrefillDone)))
14309   if(TEST_FIELD(action->type, PrefillEnable) && !(action->flags & kActionFlag_PrefillDone))
1136014310   {
11361      /* ----- pre-fill ----- */
11362      UINT32   prefillValue = kPrefillValueTable[EXTRACT_FIELD(action->type, Prefill)];
14311      UINT8 prefillValue = kPrefillValueTable[EXTRACT_FIELD(action->type, PrefillEnable)];
1136314312
1136414313      if(!(action->flags & kActionFlag_PrefillWritten))
1136514314      {
11366         /* ----- set pre-fill value ---- */
14315         /* set prefill */
1136714316         WriteData(action, prefillValue);
11368
1136914317         action->flags |= kActionFlag_PrefillWritten;
14318         return (TEST_FIELD(action->type, Return) ? CHEAT_RETURN_VALUE : selection + 1);
1137014319
11371         return;
1137214320      }
1137314321      else
1137414322      {
11375         /* ----- if value is changed, try to write new value ----- */
14323         /* do re-write */
1137614324         if(ReadData(action) == prefillValue)
11377            return;
14325            return (TEST_FIELD(action->type, Return) ? CHEAT_RETURN_VALUE : selection + 1);
1137814326
1137914327         action->flags |= kActionFlag_PrefillDone;
1138014328      }
1138114329   }
1138214330
11383   switch(EXTRACT_FIELD(action->type, Type))
14331   if(EXTRACT_FIELD(action->type, DelayEnable))
1138414332   {
11385      case kType_NormalOrDelay:
14333      if(TEST_FIELD(action->type, OneShot) && TEST_FIELD(action->type, RestoreValue))
1138614334      {
11387         if(TEST_FIELD(action->type, OneShot) && TEST_FIELD(action->type, RestorePreviousValue) && parameter)
14335         /* Keep */
14336         executeOperation = 1;
14337
14338         if(action->frameTimer++ >= EXTRACT_FIELD(action->type, DelayEnable) * ATTOSECONDS_TO_HZ(video_screen_get_frame_period(machine->primary_screen).attoseconds))
14339            action->flags |= kActionFlag_OperationDone;
14340      }
14341      else
14342      {
14343         if(action->frameTimer++ >= EXTRACT_FIELD(action->type, DelayEnable) * ATTOSECONDS_TO_HZ(video_screen_get_frame_period(machine->primary_screen).attoseconds))
1138814344         {
11389            /* ----- keep if one shot + restore prevous value + delay !=0 ----- */
14345            /* Delay */
14346            executeOperation = 1;
14347            action->frameTimer = 0;
14348
14349            if(TEST_FIELD(action->type, OneShot))
14350               action->flags |= kActionFlag_OperationDone;
14351         }
14352      }
14353   }
14354   else
14355   {
14356      if(action->frameTimer++)
14357      {
14358         if(action->frameTimer >= EXTRACT_FIELD(action->type, DelayEnable) * ATTOSECONDS_TO_HZ(video_screen_get_frame_period(machine->primary_screen).attoseconds))
14359            action->frameTimer = 0;
14360
14361         return (TEST_FIELD(action->type, Return) ? CHEAT_RETURN_VALUE : selection + 1);
14362      }
14363      else
14364      {
14365         executeOperation = 1;
14366
14367         action->flags |= kActionFlag_OperationDone;
14368      }
14369   }
14370
14371   if(executeOperation)
14372   {
14373      /* do cheat operation */
14374      switch(EXTRACT_FIELD(action->type, CodeType))
14375      {
14376         case kCodeType_Write:
14377         case kCodeType_PDWWrite:
14378         case kCodeType_RWrite:
14379         case kCodeType_IWrite:
14380         case kCodeType_VWrite:
14381         case kCodeType_VRWrite:
14382         case kCodeType_Move:
1139014383            cheat_periodicOperation(action);
14384            break;
1139114385
11392            if(action->frameTimer >= (parameter * ATTOSECONDS_TO_HZ(video_screen_get_frame_period(machine->primary_screen).attoseconds)))
14386         case kCodeType_CWrite:
14387         case kCodeType_Popup:
14388            if(cheat_periodicCondition(action))
14389               cheat_periodicOperation(action);
14390            break;
14391
14392         case kCodeType_Branch:
14393            if(cheat_periodicCondition(action))
14394               return action->extendData;
14395            break;
14396
14397         case kCodeType_Loop:
1139314398            {
11394               action->frameTimer = 0;
14399               int counter = ReadData(action);
1139514400
11396               action->flags |= kActionFlag_OperationDone;
14401               if(counter)
14402               {
14403                  WriteData(action, counter - 1);
14404
14405                  return (TEST_FIELD(action->type, DataRead) ? cheatVariable[action->data] : action->data);
14406               }
1139714407            }
11398            else
11399               action->frameTimer++;
14408            break;
14409      }
14410   }
14411
14412   return (TEST_FIELD(action->type, Return) ? CHEAT_RETURN_VALUE : selection + 1);
14413}
14414
14415/*-----------------------------------------------------
14416  cheat_periodicEntry - management for cheat entries
14417-----------------------------------------------------*/
14418
14419static void cheat_periodicEntry(running_machine *machine, CheatEntry * entry)
14420{
14421   int      i         = 0;
14422   UINT8   pressedKey   = 0;
14423   UINT8   isSelect   = 0;
14424
14425   /* ***** 1st, handle activation key ***** */
14426
14427   if(!ui_is_menu_active())
14428   {
14429      /* NOTE : activation key should be not checked in activating UI menu because it conflicts activation key checker */
14430      if((entry->flags & kCheatFlag_HasActivationKey1) && input_code_pressed_once(entry->activationKey1))
14431         pressedKey = 1;
14432      else if((entry->flags & kCheatFlag_HasActivationKey2) && input_code_pressed_once(entry->activationKey2))
14433         pressedKey = 2;
14434   }
14435
14436   if(entry->flags & kCheatFlag_Select)
14437   {
14438      if(pressedKey)
14439      {
14440         if(pressedKey == 1)
14441         {
14442            if(--entry->selection < 0)
14443               entry->selection = entry->labelIndexLength - 1;
1140014444         }
1140114445         else
1140214446         {
11403            /* ----- otherwise, delay ----- */
11404            if(action->frameTimer >= (parameter * ATTOSECONDS_TO_HZ(video_screen_get_frame_period(machine->primary_screen).attoseconds)))
11405            {
11406               action->frameTimer = 0;
14447            if(++entry->selection >= entry->labelIndexLength)
14448               entry->selection = 0;
14449         }
1140714450
11408               cheat_periodicOperation(action);
14451         /* NOTE : in handling activatio key, forced to activate a cheat even if one shot */
14452         if(!(entry->flags & kCheatFlag_OneShot) && !(entry->labelIndex[entry->selection]))
14453            DeactivateCheat(entry);
14454         else
14455            ActivateCheat(entry);
1140914456
11410               if(TEST_FIELD(action->type, OneShot))
11411                  action->flags |= kActionFlag_OperationDone;
11412            }
14457         if(TEST_FIELD(cheatOptions, ActivationKeyMessage))
14458         {
14459            if(!entry->selection)
14460               ui_popup_time(1,"%s disabled", entry->name);
1141314461            else
11414               action->frameTimer++;
14462               ui_popup_time(1,"%s : %s selected", entry->name, entry->actionList[entry->labelIndex[entry->selection]].optionalName);
1141514463         }
1141614464      }
11417      break;
11418
11419      case kType_WaitForModification:
14465   }
14466   else
14467   {
14468      /* NOTE : if value-selection has activatinon key, no handling -----*/
14469      if(!(entry->flags & kCheatFlag_UserSelect) && pressedKey)
1142014470      {
11421         if(action->flags & kActionFlag_WasModified)
14471         if(entry->flags & kCheatFlag_OneShot)
1142214472         {
11423            if(action->frameTimer <= 0)
11424            {
11425               cheat_periodicOperation(action);
14473            ActivateCheat(entry);
1142614474
11427               action->flags &= ~kActionFlag_WasModified;
14475            if(TEST_FIELD(cheatOptions, ActivationKeyMessage))
14476               ui_popup_time(1,"set %s", entry->name);
14477         }
14478         else if(entry->flags & kCheatFlag_Active)
14479         {
14480            DeactivateCheat(entry);
1142814481
11429               if(TEST_FIELD(action->type, OneShot))
11430                  action->flags |= kActionFlag_OperationDone;
11431            }
11432            else
11433               action->frameTimer--;
11434
11435            action->lastValue = ReadData(action);
14482            if(TEST_FIELD(cheatOptions, ActivationKeyMessage))
14483               ui_popup_time(1,"%s disabled", entry->name);
1143614484         }
1143714485         else
1143814486         {
11439            UINT32   currentValue = ReadData(action);
14487            ActivateCheat(entry);
1144014488
11441            if(currentValue != action->lastValue)
11442            {
11443               action->frameTimer = parameter * ATTOSECONDS_TO_HZ(video_screen_get_frame_period(machine->primary_screen).attoseconds);
14489            if(TEST_FIELD(cheatOptions, ActivationKeyMessage))
14490               ui_popup_time(1,"%s enabled", entry->name);
14491         }
14492      }
14493   }
1144414494
11445               action->flags |= kActionFlag_WasModified;
11446            }
14495   /* ***** 2nd, do cheat actions ***** */
1144714496
11448            action->lastValue = currentValue;
14497   /* if "OFF", no action */
14498   if(!(entry->flags & kCheatFlag_Active))
14499      return;
14500
14501   while(1)
14502   {
14503      if(entry->actionList[i].flags & kActionFlag_Custom)
14504      {
14505         if(EXTRACT_FIELD(entry->actionList[i].type, CodeType) == kCustomCode_LabelSelect)
14506         {
14507            i = entry->labelIndex[entry->selection];
14508            isSelect = 1;
14509            continue;
1144914510         }
14511         else
14512            i++;
1145014513      }
11451      break;
14514      else if((entry->actionList[i].flags & kActionFlag_OperationDone) || (entry->actionList[i].flags & kActionFlag_NoAction))
14515      {
14516         i++;
14517      }
14518      else if(entry->actionList[i].flags & kActionFlag_OldFormat)
14519      {
14520         int   tempType   = entry->actionList[i].type;
14521         int   j         = i;
1145214522
11453      case kType_IgnoreIfDecrementing:
14523         entry->actionList[i].type = ConvertToNewCode(&entry->actionList[i]);
14524         i = cheat_periodicAction(machine, &entry->actionList[i], i);
14525         entry->actionList[j].type = tempType;
14526      }
14527      else
14528         i = cheat_periodicAction(machine, &entry->actionList[i], i);
14529
14530      if(i >= entry->actionListLength)
14531         break;
14532
14533      if(isSelect && EXTRACT_FIELD(entry->actionList[i].type, Link) != kLink_SubLink)
14534         break;
14535   }
14536
14537   /* ***** 3rd, deactive a cheat if one shot ***** */
14538
14539   if(entry->flags & kCheatFlag_OneShot)
14540   {
14541      UINT8 done = 1;
14542
14543      i = 0;
14544      isSelect = 0;
14545
14546      while(1)
1145414547      {
11455         UINT32   currentValue = ReadData(action);
11456
11457         /* ### is "NotEqual" correct ? "LessOrEqual" seems to be good... ### */
11458         if(currentValue != (action->lastValue - parameter))
14548         if(entry->actionList[i].flags & kActionFlag_Custom)
1145914549         {
11460            cheat_periodicOperation(action);
11461
11462            if(TEST_FIELD(action->type, OneShot))
11463               action->flags |= kActionFlag_OperationDone;
14550            if(EXTRACT_FIELD(entry->actionList[i].type, CodeType) == kCustomCode_LabelSelect)
14551            {
14552               i = entry->labelIndex[entry->selection];
14553               isSelect = 1;
14554               continue;
14555            }
1146414556         }
14557         else if(entry->actionList[i].flags & kActionFlag_NoAction)
14558         {
14559            i++;
14560         }
14561         else if(!(entry->actionList[i].flags & kActionFlag_OperationDone))
14562         {
14563            done = 0;
14564            i++;
14565         }
14566         else
14567            i++;
1146514568
11466         action->lastValue = currentValue;
14569         if(i >= entry->actionListLength)
14570            break;
14571
14572         if(isSelect && EXTRACT_FIELD(entry->actionList[i].type, Link) != kLink_SubLink)
14573            break;
1146714574      }
11468      break;
1146914575
11470      default:
11471         break;
14576      if(done)
14577         DeactivateCheat(entry);
1147214578   }
1147314579}
1147414580
11475/*-----------------------------------------------------
11476  cheat_periodicEntry - management for cheat entries
11477-----------------------------------------------------*/
14581/*------------------------------------------------------------------
14582  UpdateAllCheatInfo - update all cheat info when database loaded
14583------------------------------------------------------------------*/
1147814584
11479static void cheat_periodicEntry(running_machine *machine, CheatEntry * entry)
14585static void UpdateAllCheatInfo(void)
1148014586{
11481   int   i;
14587   int i;
1148214588
11483   /* ----- special handling for label-selection ----- */
11484   if(entry->flags & kCheatFlag_Select)
14589   /* update flags for all CheatEntry */
14590   for(i = 0; i < cheatListLength; i++)
1148514591   {
11486      /* ----- special handling for activation key ----- */
11487      if((entry->flags & kCheatFlag_HasActivationKey1) || (entry->flags & kCheatFlag_HasActivationKey2))
14592      UpdateCheatInfo(&cheatList[i], 1);
14593
14594      if(cheatList[i].flags & kCheatFlag_Select)
14595         BuildLabelIndexTable(&cheatList[i]);
14596   }
14597
14598   SetLayerIndex();
14599}
14600
14601/*---------------------------------------------------------------------------------------------
14602  UpdateCheatInfo - check several fields on CheatEntry and CheatAction then set flags
14603                    "isLoadTime" parameter is set when called UpdateAllCheatInfo() right now
14604---------------------------------------------------------------------------------------------*/
14605
14606static void UpdateCheatInfo(CheatEntry * entry, UINT8 isLoadTime)
14607{
14608   int      i;
14609   int      flags = 0;
14610   UINT8   isOneShot = 1;
14611   UINT8   isNull = 1;
14612   UINT8   isSeparator = 1;
14613   UINT8   isNewFormat = 1;
14614
14615   flags = entry->flags & kCheatFlag_PersistentMask;
14616
14617   for(i = 0; i < entry->actionListLength; i++)
14618   {
14619      CheatAction * action = &entry->actionList[i];
14620
14621      int actionFlags = action->flags & kActionFlag_PersistentMask;
14622
14623      action->region = EXTRACT_FIELD(action->type, CPURegion);
14624
14625      if(actionFlags & kActionFlag_OldFormat)
1148814626      {
11489         if(input_code_pressed(entry->activationKey1) || input_code_pressed(entry->activationKey2))
14627         if(   (EXTRACT_FIELD(action->type, LocationType) == kLocation_Custom) &&
14628            (EXTRACT_FIELD(action->type, LocationParameter) == kCustomLocation_Select))
14629               flags |= kCheatFlag_Select;
14630
14631         if(EXTRACT_FIELD(action->type, LocationType) != kLocation_Custom)
14632            isNull = 0;
14633
14634         if(!TEST_FIELD(action->type, OneShot))
14635            isOneShot = 0;
14636
14637         if(TEST_FIELD(action->type, UserSelectEnable))
14638            flags |= kCheatFlag_UserSelect;
14639
14640         if(   (EXTRACT_FIELD(action->type, LocationType) == kLocation_Custom) &&
14641            (EXTRACT_FIELD(action->type, LocationParameter) == kCustomLocation_Select))
14642               actionFlags |= kActionFlag_NoAction;
14643
14644         if(   (EXTRACT_FIELD(action->type, LocationType) == kLocation_IndirectIndexed) ||
14645            ((EXTRACT_FIELD(action->type, LocationType) != kLocation_Custom) &&
14646            ((EXTRACT_FIELD(action->type, Operation) | EXTRACT_FIELD(action->type, OperationExtend) << 2) == 1)))
14647               actionFlags |= kActionFlag_IndexAddress;
14648
14649         if(i && entry->actionList[i-1].type == entry->actionList[i].type)
1149014650         {
11491            if(!(entry->flags & kCheatFlag_ActivationKeyPressed))
14651            if(   entry->actionList[i].address >= entry->actionList[i-1].address &&
14652               entry->actionList[i].address <= entry->actionList[i-1].address + 3)
14653                  actionFlags |= kActionFlag_NoAction;
14654         }
14655
14656         isNewFormat = 0;
14657      }
14658      else
14659      {
14660         if(action->region != CUSTOM_CODE)
14661         {
14662            switch(EXTRACT_FIELD(action->type, CodeType))
1149214663            {
11493               /* ----- move current position until find OFF or no link extension code ----- */
11494               do{
11495                  /* ----- 1st activation key pressed ----- */
11496                  if(input_code_pressed(entry->activationKey1))
11497                  {
11498                     entry->selection++;
14664               case kCodeType_PDWWrite:
14665                  actionFlags |= kActionFlag_PDWWrite;
14666                  break;
1149914667
11500                     if(entry->flags & kCheatFlag_OneShot)
11501                     {
11502                        if(entry->selection >= entry->actionListLength)
11503                        {
11504                           entry->selection = 1;
14668               case kCodeType_RWrite:
14669                  actionFlags |= kActionFlag_Repeat;
14670                  break;
1150514671
11506                           if(entry->selection >= entry->actionListLength)
11507                              entry->selection = 0;
11508                        }
14672               case kCodeType_IWrite:
14673               case kCodeType_Move:
14674               case kCodeType_Loop:
14675                  if(action->extendData != ~0)
14676                     actionFlags |= kActionFlag_IndexAddress;
14677                  break;
1150914678
11510                        if(!TEST_FIELD(entry->actionList[entry->selection].type, LinkExtension))
11511                        {
11512                           ActivateCheat(entry);
14679               case kCodeType_CWrite:
14680               case kCodeType_Branch:
14681                  actionFlags |= kActionFlag_CheckCondition;
14682                  break;
1151314683
11514                           entry->flags |= kCheatFlag_DoOneShot;
11515                        }
11516                     }
11517                     else
11518                     {
11519                        if(entry->selection >= entry->actionListLength)
11520                        {
11521                           entry->selection = 0;
14684               case kCodeType_VWrite:
14685                  flags |= kCheatFlag_UserSelect;
1152214686
11523                           DeactivateCheat(entry);
11524                        }
11525                        else
11526                        {
11527                           if(!TEST_FIELD(entry->actionList[entry->selection].type, LinkExtension))
11528                              ActivateCheat(entry);
11529                        }
11530                     }
11531                  }
11532                  /* ----- 2nd activation key pressed ----- */
11533                  else
11534                  {
11535                     entry->selection--;
14687                  if(action->extendData != ~0)
14688                     actionFlags |= kActionFlag_IndexAddress;
14689                  break;
1153614690
11537                     if(entry->flags & kCheatFlag_OneShot)
11538                     {
11539                        if(entry->selection <= 0)
11540                           entry->selection = entry->actionListLength - 1;
14691               case kCodeType_VRWrite:
14692                  flags |= kCheatFlag_UserSelect;
14693                  actionFlags |= kActionFlag_Repeat;
14694                  break;
1154114695
11542                        if(!TEST_FIELD(entry->actionList[entry->selection].type, LinkExtension))
11543                        {
11544                           ActivateCheat(entry);
14696               case kCodeType_Popup:
14697                  actionFlags |= kActionFlag_CheckCondition;
1154514698
11546                           entry->flags |= kCheatFlag_DoOneShot;
11547                        }
11548                     }
11549                     else
11550                     {
11551                        if(!entry->selection)
11552                           DeactivateCheat(entry);
11553                        else
11554                        {
11555                           if(entry->selection < 0)
11556                              entry->selection = entry->actionListLength - 1;
14699                  if(action->extendData != ~0)
14700                     actionFlags |= kActionFlag_IndexAddress;
14701                  break;
1155714702
11558                           if(!TEST_FIELD(entry->actionList[entry->selection].type, LinkExtension))
11559                              ActivateCheat(entry);
11560                        }
11561                     }
11562                  }
11563               }while(entry->selection && TEST_FIELD(entry->actionList[entry->selection].type, LinkExtension));
14703               case kCodeType_Watch:
14704                  actionFlags |= kActionFlag_NoAction;
14705                  break;
14706            }
1156414707
11565               /* ----- display selected label name if needed ----- */
11566               if(TEST_FIELD(cheatOptions, ActivationKeyMessage))
11567               {
11568                  if(!entry->selection)
11569                     ui_popup_time(1,"%s disabled", entry->name);
11570                  else
11571                     ui_popup_time(1,"%s : %s selected", entry->name, entry->actionList[entry->selection].optionalName);
11572               }
14708            isNull = 0;
14709            isSeparator = 0;
14710         }
14711         else
14712         {
14713            /* is label-select? */
14714            if(EXTRACT_FIELD(action->type, CodeType) == kCustomCode_LabelSelect)
14715               flags |= kCheatFlag_Select;
1157314716
11574               entry->flags |= kCheatFlag_ActivationKeyPressed;      // set flag
11575            }
14717            /* is comment? */
14718            if(EXTRACT_FIELD(action->type, CodeType) != kCustomCode_Comment)
14719               isNull = 0;
14720
14721            /* is separator? */
14722            if(EXTRACT_FIELD(action->type, CodeType) != kCustomCode_Separator)
14723               isSeparator = 0;
14724
14725            /* is layer index? */
14726            if(EXTRACT_FIELD(action->type, CodeType) == kCustomCode_Layer)
14727               flags |= kCheatFlag_LayerIndex;
14728
14729            actionFlags |= kActionFlag_NoAction;
14730            actionFlags |= kActionFlag_Custom;
1157614731         }
11577         else
11578            entry->flags &= ~kCheatFlag_ActivationKeyPressed;         // clear flag
14732
14733         /* is one shot? */
14734         if(!TEST_FIELD(action->type, OneShot))
14735            isOneShot = 0;
1157914736      }
1158014737
11581      /* ----- if a subcheat is selected, handle it ----- */
11582      if(entry->selection)
14738      action->flags = actionFlags;
14739   }
14740
14741   /* one shot is set if "ALL" actions are not an one shot */
14742   if(isOneShot)
14743      flags |= kCheatFlag_OneShot;
14744
14745   if(isNull)
14746   {
14747      if(entry->actionListLength > 1)
14748         flags |= kCheatFlag_ExtendComment;
14749      else
14750         flags |= kCheatFlag_Null;
14751   }
14752
14753   if(isSeparator)
14754   {
14755      flags |= kCheatFlag_Null;
14756      flags |= kCheatFlag_Separator;
14757   }
14758
14759   if(isNewFormat == 0)
14760      flags |= kCheatFlag_OldFormat;
14761
14762   entry->flags = (flags & kCheatFlag_InfoMask) | (entry->flags & ~kCheatFlag_InfoMask);
14763
14764   /* clear dirty flag as "this entry has already exist in the database" when loaded from a database */
14765   if(isLoadTime)
14766      entry->flags &= ~kCheatFlag_Dirty;
14767
14768   CheckCodeFormat(entry);
14769}
14770
14771/*--------------------
14772  AnalyseCodeFormat
14773--------------------*/
14774
14775static UINT32 AnalyseCodeFormat(CheatEntry * entry, CheatAction * action)
14776{
14777   UINT32 errorFlag = 0;
14778
14779   /* check type field */
14780   if(action->flags & kActionFlag_OldFormat)
14781   {
14782      UINT8   type      = EXTRACT_FIELD(action->type, LocationType);
14783      UINT8   parameter   = EXTRACT_FIELD(action->type, LocationParameter);
14784      UINT8   operation   = EXTRACT_FIELD(action->type, Operation);
14785
14786      if(type >= kLocation_Unused5)
14787         errorFlag |= kErrorFlag_InvalidLocationType;
14788
14789      if(TEST_FIELD(action->type, OperationExtend))
14790         errorFlag |= kErrorFlag_InvalidOperation;
14791
14792      if(type == kLocation_IndirectIndexed)
1158314793      {
11584         i = entry->selection;
14794         if(operation != kOperation_WriteMask && operation != kOperation_SetOrClearBits)
14795            errorFlag |= kErrorFlag_ConflictedExtendField;
14796      }
1158514797
11586         do{
11587            if(!(entry->flags & kCheatFlag_OneShot) || (entry->flags & kCheatFlag_DoOneShot))
11588               cheat_periodicAction(machine, &entry->actionList[i]);
14798      if(operation == kOperation_ForceRange)
14799      {
14800         if(EXTRACT_FIELD(action->type, MSB16) <= EXTRACT_FIELD(action->type, LSB16))
14801            errorFlag |= kErrorFlag_InvalidRange;
14802      }
1158914803
11590            i++;
14804      if(type == kLocation_MemoryRegion)
14805      {
14806         if(!TEST_FIELD(action->type, RestorePreviousValue))
14807            errorFlag |= kErrorFlag_NoRestorePreviousValue;
14808      }
1159114809
11592            /* ----- if illegal index, finish ----- */
11593            if(i >= entry->actionListLength)
11594               break;
14810      if((entry->flags & kCheatFlag_UserSelect) && (entry->flags & kCheatFlag_Select))
14811         errorFlag |= kErrorFlag_ConflictedSelects;
1159514812
11596         /* ----- if next code has link extension, handle it too ----- */
11597         }while(TEST_FIELD(entry->actionList[i].type, LinkExtension));
14813      if(TEST_FIELD(action->type, UserSelectEnable))
14814      {
14815         if(!action->originalDataField)
14816            errorFlag |= kErrorFlag_NoSelectableValue;
1159814817      }
14818
14819      if(type == kLocation_Custom && parameter == kCustomLocation_Select)
14820      {
14821         if(entry->actionListLength == 1)
14822            errorFlag |= kErrorFlag_NoLabel;
14823
14824         if(action->originalDataField)
14825            errorFlag |= kErrorFlag_InvalidDataField;
14826
14827         if(action->extendData)
14828            errorFlag |= kErrorFlag_InvalidExtendDataField;
14829      }
14830
14831      if(operation == kOperation_WriteMask)
14832      {
14833         if(type == kLocation_Standard)
14834         {
14835            if(!action->extendData || action->extendData == 0xFF || action->extendData == 0xFFFF || action->extendData == 0xFFFFFF)
14836               errorFlag |= kErrorFlag_InvalidExtendDataField;
14837         }
14838         else if(type == kLocation_MemoryRegion)
14839         {
14840            if(action->extendData != ~0)
14841               errorFlag |= kErrorFlag_InvalidExtendDataField;
14842         }
14843      }
1159914844   }
1160014845   else
1160114846   {
11602      /* ----- NOTE : activatinon key for value-selection is disabled -----*/
11603      if(((entry->flags & kCheatFlag_HasActivationKey1) || (entry->flags & kCheatFlag_HasActivationKey2)) &&
11604         !(entry->flags & kCheatFlag_UserSelect))
14847      if((action->flags & kActionFlag_Custom) == 0)
1160514848      {
11606         /* ----- special handling for activation key ----- */
11607         if(input_code_pressed(entry->activationKey1) || input_code_pressed(entry->activationKey2))
14849         UINT8   codeType      = EXTRACT_FIELD(action->type, CodeType);
14850         UINT8   codeParameter   = EXTRACT_FIELD(action->type, CodeParameter);
14851
14852         if(codeType >= kCodeType_Unused1 && codeType <= kCodeType_Unused4)
14853            errorFlag |= kErrorFlag_InvalidCodeType;
14854
14855         if(action->flags & kActionFlag_CheckCondition)
1160814856         {
11609            if(!(entry->flags & kCheatFlag_ActivationKeyPressed))
11610            {
11611               if(entry->flags & kCheatFlag_OneShot)
11612               {
11613                  ActivateCheat(entry);
14857            if(codeParameter >= kCondition_Unused1 && codeParameter <= kCondition_Unused4)
14858               errorFlag |= kErrorFlag_InvalidCondition;
14859         }
1161414860
11615                  /* ----- display description for one shot if needed ----- */
11616                  if(TEST_FIELD(cheatOptions, ActivationKeyMessage))
11617                     ui_popup_time(1,"set %s", entry->name);
11618               }
11619               else
11620               {
11621                  if(entry->flags & kCheatFlag_Active)
11622                  {
11623                     DeactivateCheat(entry);
14861         if(codeType == kCodeType_PDWWrite)
14862         {
14863            if(EXTRACT_FIELD(action->type, AddressRead) == kReadFrom_Variable)
14864               errorFlag |= kErrorFlag_ForbittenVariable;
14865         }
1162414866
11625                     /* ----- display description for OFF if needed ----- */
11626                     if(TEST_FIELD(cheatOptions, ActivationKeyMessage))
11627                        ui_popup_time(1,"%s disabled", entry->name);
11628                  }
11629                  else
11630                  {
11631                     ActivateCheat(entry);
14867         if(EXTRACT_FIELD(action->type, Link) == kLink_CopyLink)
14868         {
14869            if(!entry->flags & kCheatFlag_UserSelect)
14870               errorFlag |= kErrorFlag_CopyLinkWithoutSelect;
14871         }
1163214872
11633                     /* ----- display description for ON if needed ----- */
11634                     if(TEST_FIELD(cheatOptions, ActivationKeyMessage))
11635                        ui_popup_time(1,"%s enabled", entry->name);
11636                  }
11637               }
14873         if(   TEST_FIELD(action->region, RegionFlag) ||
14874            EXTRACT_FIELD(action->type, AddressSpace) == kAddressSpace_OpcodeRAM)
14875         {
14876            if(!TEST_FIELD(action->type, RestoreValue))
14877               errorFlag |= kErrorFlag_NoRestorePreviousValue;
14878         }
1163814879
11639               entry->flags |= kCheatFlag_ActivationKeyPressed;
11640            }
14880         if(   EXTRACT_FIELD(action->type, CodeType) == kCodeType_VWrite ||
14881            EXTRACT_FIELD(action->type, CodeType) == kCodeType_VRWrite)
14882         {
14883            if(!action->originalDataField)
14884               errorFlag |= kErrorFlag_NoSelectableValue;
1164114885         }
11642         else
11643            entry->flags &= ~kCheatFlag_ActivationKeyPressed;
11644      }
1164514886
11646      if(!(entry->flags & kCheatFlag_Active))
11647         return;
14887         if(action->flags & kActionFlag_Repeat)
14888         {
14889            if(!EXTRACT_FIELD(action->extendData, LSB16))
14890               errorFlag |= kErrorFlag_NoRepeatCount;
14891         }
1164814892
11649      /* ----- update all actions ----- */
11650      for(i = 0; i < entry->actionListLength; i++)
11651         cheat_periodicAction(machine, &entry->actionList[i]);
14893         if(EXTRACT_FIELD(action->type, AddressRead))
14894         {
14895            if(EXTRACT_FIELD(action->type, AddressRead) > kReadFrom_Variable)
14896               errorFlag |= kErrorFlag_UndefinedAddressRead;
1165214897
11653      /* ----- if all actions are done, deactivate the cheat if oneshot entry ----- */
11654      {
11655         UINT8   done = 1;
14898            if(action->address >= VARIABLE_MAX_ARRAY)
14899               errorFlag |= kErrorFlag_AddressVariableOutRange;
14900         }
1165614901
11657         for(i = 0 ; (i < entry->actionListLength && done) ; i++)
11658            if(!(entry->actionList[i].flags & kActionFlag_OperationDone))
11659               done = 0;
14902         if(TEST_FIELD(action->type, DataRead))
14903         {
14904            if(action->data >= VARIABLE_MAX_ARRAY)
14905               errorFlag |= kErrorFlag_DataVariableOutRange;
14906         }
1166014907
11661         if(done)
11662            DeactivateCheat(entry);
14908         if(codeType == kCodeType_Write)
14909         {
14910            if(!action->extendData || action->extendData == 0xFF || action->extendData == 0xFFFF || action->extendData == 0xFFFFFF)
14911               errorFlag |= kErrorFlag_InvalidExtendDataField;
14912         }
14913
14914         if(!(action->flags & kActionFlag_Custom))
14915         {
14916            if(TEST_FIELD(action->region, RegionFlag))
14917            {
14918               UINT8 region = EXTRACT_FIELD(action->region, RegionIndex);
14919
14920               if(region >= REGION_MAX)            errorFlag |= kErrorFlag_OutOfCPURegion;
14921               else if(!region_info_list[region].type)   errorFlag |= kErrorFlag_InvalidCPURegion;
14922               else if(!IsAddressInRange(action, memory_region_length(action->region)))
14923                                             errorFlag |= kErrorFlag_RegionOutOfRange;
14924            }
14925            else
14926            {
14927               UINT8 cpu = EXTRACT_FIELD(action->region, CPUIndex);
14928
14929               if(!VALID_CPU(cpu))
14930                  errorFlag |= kErrorFlag_OutOfCPURegion;
14931               else if(cpu_info_list[cpu].type == 0)
14932                  errorFlag |= kErrorFlag_InvalidCPURegion;
14933
14934               if(EXTRACT_FIELD(action->type, AddressSpace) > kAddressSpace_EEPROM)
14935                  errorFlag |= kErrorFlag_InvalidAddressSpace;
14936            }
14937         }
1166314938      }
14939      else
14940      {
14941         if(EXTRACT_FIELD(action->type, CodeParameter) >= kCustomCode_Unused1)
14942            errorFlag |= kErrorFlag_InvalidCustomCode;
14943      }
1166414944   }
14945
14946   return errorFlag;
1166514947}
1166614948
11667/*------------------------------------------------------------------
11668  UpdateAllCheatInfo - update all cheat info when database loaded
11669------------------------------------------------------------------*/
14949/*----------------------------------------
14950  CheckCodeFormat - code format checker
14951----------------------------------------*/
1167014952
11671static void UpdateAllCheatInfo(void)
14953static void CheckCodeFormat(CheatEntry * entry)
1167214954{
11673   int   i;
14955   int      i;
14956   UINT8   isError = 0;
1167414957
11675   for(i = 0; i < cheatListLength; i++)
11676      UpdateCheatInfo(&cheatList[i], 1);
14958   for(i = 0; i < entry->actionListLength; i++)
14959   {
14960      CheatAction * action = &entry->actionList[i];
14961
14962      if(AnalyseCodeFormat(entry, action))
14963         isError = 1;
14964   }
14965
14966   if(isError)
14967   {
14968      entry->flags |= kCheatFlag_HasWrongCode;
14969      messageType = kCheatMessage_WrongCode;
14970      messageTimer = DEFAULT_MESSAGE_TIME;
14971   }
1167714972}
1167814973
11679/*--------------------------------------------------
11680  UpdateCheatInfo - update entry, action and flag
11681--------------------------------------------------*/
14974/*-------------------------------------------------------------------------------------------------
14975  BuildLabelIndexTable - create index table for label-selection and calculate index table length
14976-------------------------------------------------------------------------------------------------*/
1168214977
11683static void UpdateCheatInfo(CheatEntry * entry, UINT8 isLoadTime)
14978static void BuildLabelIndexTable(CheatEntry *entry)
1168414979{
11685   int      isOneShot =   1;
11686   int      isNull =   1;
11687   int      flags =      0;
11688   int      i;
14980   int i, j, length = 0;
1168914981
11690   flags = entry->flags & kCheatFlag_PersistentMask;
14982   entry->labelIndexLength = 0;
1169114983
11692   /* ---- is it label-selection ? ----- */
11693   if(   (EXTRACT_FIELD(entry->actionList[0].type, LocationType) == kLocation_Custom) &&
11694      (EXTRACT_FIELD(entry->actionList[0].type, LocationParameter) == kCustomLocation_Select))
11695         flags |= kCheatFlag_Select;
14984   for(i = 0, j = 0; i < entry->actionListLength; i++)
14985   {
14986      CheatAction * action = &entry->actionList[i];
1169614987
11697   for(i = 0; i < entry->actionListLength; i++)
14988      if((action->flags && kActionFlag_Custom) && EXTRACT_FIELD(action->type, CodeType) == kCustomCode_LabelSelect)
14989      {
14990         entry->labelIndex = malloc_or_die(sizeof(entry->labelIndex) * (++entry->labelIndexLength + 1));
14991         entry->labelIndex[j++] = i;
14992
14993         length = action->data ? action->data + i : entry->actionListLength;
14994      }
14995      else if(EXTRACT_FIELD(action->type, Link) == kLink_Link)
14996      {
14997         if(length)
14998         {
14999            entry->labelIndex = realloc(entry->labelIndex, sizeof(entry->labelIndex) * (++entry->labelIndexLength + 1));
15000            entry->labelIndex[j++] = i;
15001         }
15002      }
15003   }
15004
15005   if(entry->labelIndexLength <= 1)
1169815006   {
11699      CheatAction   * action = &entry->actionList[i];
15007      logerror("cheat - BuildLabelIndexTable : %s fails to build due to invalid or no link\n", entry->name);
15008      return;
15009   }
1170015010
11701      int         isActionNull =   0;
11702      UINT32      size;
11703      UINT32      operation;
11704      UINT32      actionFlags = action->flags & kActionFlag_PersistentMask;
15011   if(entry->flags & kCheatFlag_OneShot)
15012      entry->selection = 1;
1170515013
11706      size = EXTRACT_FIELD(action->type, BytesUsed);
15014   //logerror("Cheat - Finish building index table for %s (length = %x)\n", entry->name, entry->labelIndexLength);
15015   //for(i = 0; i < entry->labelIndexLength; i++)
15016   //  logerror("IndexTable[%x] = %x\n",i,entry->labelIndex[i]);
1170715017
11708      operation = EXTRACT_FIELD(action->type, Operation) | EXTRACT_FIELD(action->type, OperationExtend) << 2;
15018}
1170915019
11710      /* ---- is it comment ? ----- */
11711      if(   (EXTRACT_FIELD(action->type, LocationType) == kLocation_Custom) &&
11712         (EXTRACT_FIELD(action->type, LocationParameter) == kCustomLocation_Comment))
11713            isActionNull = 1;
11714      else
11715         isNull = 0;
15020/*----------------
15021  SetLayerIndex
15022----------------*/
1171615023
11717      /* ---- is it one shot ? ----- */
11718      if(!TEST_FIELD(action->type, OneShot))
11719         isOneShot = 0;
15024static void SetLayerIndex(void)
15025{
15026   int i, j;
1172015027
11721      /* ---- is it value-selection ? ----- */
11722      if(TEST_FIELD(action->type, UserSelectEnable))
11723         flags |= kCheatFlag_UserSelect;
15028   for(i = 0; i < cheatListLength; i++)
15029   {
15030      CheatEntry * entry = &cheatList[i];
1172415031
11725      /* ---- is it relative address ? ----- */
11726      if(EXTRACT_FIELD(action->type, LocationType) == kLocation_IndirectIndexed)
11727         actionFlags |= kActionFlag_IgnoreMask;
11728      else
15032      if(entry->flags & kCheatFlag_LayerIndex)
1172915033      {
11730         if(isLoadTime)
15034         int length = entry->actionList[0].extendData;
15035
15036         if(length < cheatListLength && (i + length) <= cheatListLength)
1173115037         {
11732            /* ----- check for mask == 0 and fix when database loaded ----- */
11733            if((operation == kOperation_WriteMask) && (action->extendData == 0))
11734               action->extendData = ~0;
15038            entry->layerIndex = entry->actionList[0].address;
15039
15040            for(j = i + 1; j <= i + length; j++)
15041            {
15042               CheatEntry * traverse = &cheatList[j];
15043
15044               if(!(traverse->flags & kCheatFlag_LayerIndex))
15045                  traverse->layerIndex = entry->actionList[0].data;
15046            }
1173515047         }
1173615048      }
15049   }
15050}
1173715051
11738      action->flags = actionFlags;
15052/*-----------------------------------------------------------------------------------------
15053  DisplayCheatMessage - display cheat message via ui_draw_text_box instead of popup menu
15054                        warning message is displayed with red back color
15055-----------------------------------------------------------------------------------------*/
15056
15057static void DisplayCheatMessage(void)
15058{
15059   static const char *const kCheatMessageTable[] = {
15060      "INVALID MESSAGE!",            // this message is unused
15061      "cheat option reloaded",
15062      "cheat code reloaded",
15063      "user defined search region reloaded",
15064      "failed to load database!",
15065      "cheats found",
15066      "1 result found, added to list",
15067      "succeeded to save",
15068      "failed to save!",
15069      "cheats saved",
15070      "activation key saved",
15071      "no activation key!",
15072      "pre-enable saved",
15073      "succeeded to add",
15074      "failed to add!",
15075      "succeeded to delete",
15076      "failed to delete!",
15077      "no search region!",
15078      "values restored",
15079      "there are no old values!",
15080      "saved all memory regions",
15081      "region invalidated remains results are",
15082      "debug mode only!",
15083      "found wrong code!" };
15084
15085   char buf[64];
15086
15087   if(!messageType)
15088      return;
15089
15090   switch(messageType)
15091   {
15092      /* simple message */
15093      default:
15094         sprintf(buf, "%s", kCheatMessageTable[messageType]);
15095         break;
15096
15097      /* message with data */
15098      case kCheatMessage_CheatFound:
15099      case kCheatMessage_InvalidatedRegion:
15100      {
15101         search_info *search = get_current_search();
15102
15103         sprintf(buf, "%d %s", search->num_results, kCheatMessageTable[messageType]);
15104      }
15105      break;
15106
15107      case kCheatMessage_AllCheatSaved:
15108         sprintf(buf, "%d %s", cheatListLength, kCheatMessageTable[messageType]);
15109         break;
1173915110   }
1174015111
11741   /* ---- set one shot flag ----- */
11742   if(isOneShot)
11743      flags |= kCheatFlag_OneShot;
15112   /* draw it */
15113   switch(messageType)
15114   {
15115      default:
15116         ui_draw_text_box(buf, JUSTIFY_CENTER, 0.5f, 0.9f, UI_FILLCOLOR);
15117         break;
1174415118
11745   /* ---- set null flag ----- */
11746   if(isNull)
11747      flags |= kCheatFlag_Null;
15119      case kCheatMessage_None:
15120      case kCheatMessage_FailedToLoadDatabase:
15121      case kCheatMessage_FailedToSave:
15122      case kCheatMessage_NoActivationKey:
15123      case kCheatMessage_FailedToAdd:
15124      case kCheatMessage_FailedToDelete:
15125      case kCheatMessage_NoSearchRegion:
15126      case kCheatMessage_NoOldValue:
15127      case kCheatMessage_Max:
15128      case kCheatMessage_DebugOnly:
15129      case kCheatMessage_WrongCode:
15130         /* warning message has red background color */
15131         ui_draw_text_box(buf, JUSTIFY_CENTER, 0.5f, 0.9f, UI_REDCOLOR);
15132         break;
15133   }
1174815134
11749   entry->flags = (flags & kCheatFlag_InfoMask) | (entry->flags & ~kCheatFlag_InfoMask);
15135   /* decrement message timer */
15136   if(--messageTimer == 0)
15137      messageType = 0;
15138}
1175015139
11751   if(isLoadTime)
11752      entry->flags &= ~kCheatFlag_Dirty;
15140/*---------------------
15141  get_address_length
15142---------------------*/
15143
15144static UINT8 get_address_length(UINT8 region)
15145{
15146   if(region != CUSTOM_CODE)
15147   {
15148      cpu_region_info *info = get_cpu_or_region_info(region);
15149
15150      if(info && info->type)
15151         return info->address_chars_needed;
15152   }
15153
15154   return 8;
1175315155}
1175415156
11755/*--------------------------------------------------------------------------------
11756  IsAddressInRange - check an address is in range (1 = in range, 0 = out range)
11757--------------------------------------------------------------------------------*/
15157/*------------------
15158  get_region_name
15159------------------*/
1175815160
11759static int IsAddressInRange(CheatAction * action, UINT32 length)
15161static char *get_region_name(UINT8 region)
1176015162{
11761   UINT8   bytes = EXTRACT_FIELD(action->type, BytesUsed) + 1;
15163   if(TEST_FIELD(region, RegionIndex))
15164   {
15165      if(region >= REGION_INVALID && region < REGION_MAX)
15166         return (char *)kRegionNames[EXTRACT_FIELD(region, RegionIndex)];
15167   }
15168   else
15169   {
15170      if(VALID_CPU(region))
15171         return (char *)kRegionNames[EXTRACT_FIELD(region, CPUIndex) + 1];
15172   }
1176215173
11763   return ((action->address + bytes) <= length);
15174   return (char *)kRegionNames[0];
1176415175}
1176515176
11766/*---------------------------------------------------------------
11767  BuildCPUInfoList - get CPU info when initialize cheat system
11768---------------------------------------------------------------*/
15177/*------------------------------------------------------------------------------------
15178  build_cpu_region_info_list - get CPU and region info when initialize cheat system
15179------------------------------------------------------------------------------------*/
1176915180
11770static void BuildCPUInfoList(running_machine *machine)
15181static void build_cpu_region_info_list(running_machine *machine)
1177115182{
11772   int   i;
15183   int i;
1177315184
11774   /* ----- do regions ----- */
15185   /* do regions */
1177515186   {
11776      const rom_entry    * traverse = rom_first_region(machine->gamedrv);
15187      const rom_entry *traverse = rom_first_region(machine->gamedrv);
1177715188
11778      memset(regionInfoList, 0, sizeof(CPUInfo) * kRegionListLength);
15189      memset(region_info_list, 0, sizeof(cpu_region_info) * REGION_LIST_LENGTH);
1177915190
1178015191      while(traverse)
1178115192      {
1178215193         if(ROMENTRY_ISREGION(traverse))
1178315194         {
11784            UINT8   regionType = ROMREGION_GETTYPE(traverse);
15195            UINT8 region_type = ROMREGION_GETTYPE(traverse);
1178515196
11786            /* ----- non-cpu region ? ----- */
11787            if((regionType >= REGION_GFX1) && (regionType <= REGION_USER8))
15197            /* non-cpu region */
15198            if(region_type >= REGION_GFX1 && region_type <= REGION_PLDS)
1178815199            {
11789               CPUInfo   * info = &regionInfoList[regionType - REGION_INVALID];
11790               UINT32   length = memory_region_length(regionType);
11791               int      bitState = 0;
15200               UINT8   bit_state      = 0;
15201               UINT32   length         = memory_region_length(region_type);
15202               cpu_region_info *info   = &region_info_list[region_type - REGION_INVALID];
1179215203
11793               info->type = regionType;
11794               info->dataBits = ROMREGION_GETWIDTH(traverse);
15204               info->type                  = region_type;
15205               info->data_bits               = ROMREGION_GETWIDTH(traverse);
15206               info->address_bits            = 0;
15207               info->address_mask            = length;
15208               info->address_chars_needed      = info->address_bits >> 2;
15209               info->endianness            = ROMREGION_ISBIGENDIAN(traverse);
1179515210
11796               info->addressBits = 0;
11797               info->addressMask = length;
15211               if(info->address_bits & 3)
15212                  info->address_chars_needed++;
1179815213
11799               /* ----- build address mask ----- */
15214               /* build address mask */
1180015215               for(i = 0; i < 32; i++)
1180115216               {
11802                  UINT32   mask = 1 << (31 - i);
15217                  UINT32 mask = 1 << (31 - i);
1180315218
11804                  if(bitState)
11805                     info->addressMask |= mask;
15219                  if(bit_state)
15220                     info->address_mask |= mask;
1180615221                  else
1180715222                  {
11808                     if(info->addressMask & mask)
15223                     if(info->address_mask & mask)
1180915224                     {
11810                        info->addressBits = 32 - i;
11811                        bitState = 1;
15225                        info->address_bits = 32 - i;
15226                        bit_state = 1;
1181215227                     }
1181315228                  }
1181415229               }
11815
11816               info->addressCharsNeeded = info->addressBits >> 2;
11817
11818               if(info->addressBits & 3)
11819                  info->addressCharsNeeded++;
11820
11821               info->endianness = ROMREGION_ISBIGENDIAN(traverse);
1182215230            }
1182315231         }
1182415232
r2762r2763
1182615234      }
1182715235   }
1182815236
11829   /* ----- do CPUs ----- */
15237   /* do CPUs */
1183015238   {
11831      memset(cpuInfoList, 0, sizeof(CPUInfo) * MAX_CPU);
15239      memset(cpu_info_list, 0, sizeof(cpu_region_info) * MAX_CPU);
1183215240
1183315241      for(i = 0; i < cpu_gettotalcpu(); i++)
1183415242      {
11835         CPUInfo   * info = &cpuInfoList[i];
11836         CPUInfo   * regionInfo = &regionInfoList[REGION_CPU1 + i - REGION_INVALID];
15243         cpu_region_info   *cpu_info      = &cpu_info_list[i];
15244         cpu_region_info   *region_info   = &region_info_list[REGION_CPU1 + i - REGION_INVALID];
15245         cpu_type      type         = machine->config->cpu[i].type;
1183715246
11838         cpu_type type = machine->config->cpu[i].type;
15247         cpu_info->type                  = type;
15248         cpu_info->data_bits               = cputype_databus_width(type, ADDRESS_SPACE_PROGRAM);
15249         cpu_info->address_bits            = cputype_addrbus_width(type, ADDRESS_SPACE_PROGRAM);
15250         cpu_info->address_mask            = 0xFFFFFFFF >> (32 - cpu_info->address_bits);
15251         cpu_info->address_chars_needed      = cpu_info->address_bits >> 2;
15252         cpu_info->endianness            = (cputype_endianness(type) == CPU_IS_BE);
15253         cpu_info->address_shift            = cputype_addrbus_shift(type, ADDRESS_SPACE_PROGRAM);
1183915254
11840         info->type = type;
11841         info->dataBits = cputype_databus_width(type, ADDRESS_SPACE_PROGRAM);
11842         info->addressBits = cputype_addrbus_width(type, ADDRESS_SPACE_PROGRAM);
11843         info->addressMask = 0xFFFFFFFF >> (32 - cputype_addrbus_width(type, ADDRESS_SPACE_PROGRAM));
15255         if(cpu_info->address_bits & 0x3)
15256            cpu_info->address_chars_needed++;
1184415257
11845         info->addressCharsNeeded = info->addressBits >> 2;
11846         if(info->addressBits & 0x3)
11847            info->addressCharsNeeded++;
11848
11849         info->endianness = (cputype_endianness(type) == CPU_IS_BE);
11850
11851         switch(type)
11852         {
11853#if HAS_TMS34010
11854            case CPU_TMS34010:
11855               info->addressShift = 3;
11856               break;
11857#endif
11858#if HAS_TMS34020
11859            case CPU_TMS34020:
11860               info->addressShift = 3;
11861               break;
11862#endif
11863            default:
11864               info->addressShift = 0;
11865               break;
11866         }
11867
11868         /* ----- copy to region list ----- */
11869         memcpy(regionInfo, info, sizeof(CPUInfo));
15258         /* copy CPU info to region info */
15259         memcpy(region_info, cpu_info, sizeof(cpu_region_info));
1187015260      }
1187115261   }
1187215262}
11873
src/emu/validity.c
r2762r2763
11901190   const input_field_config *field;
11911191   const game_driver *driver = drivers[drivnum];
11921192   int empty_string_found = FALSE;
1193   char errorbuf[1024];
11931194   quark_entry *entry;
11941195   int error = FALSE;
11951196   UINT32 crc;
r2762r2763
12081209   quark_add(inputs_table, drivnum, crc);
12091210
12101211   /* allocate the input ports */
1211   portlist = input_port_config_alloc(driver->ipt);
1212   portlist = input_port_config_alloc(driver->ipt, errorbuf, sizeof(errorbuf));
1213   if (errorbuf[0] != 0)
1214      mame_printf_error("%s: %s has input port errors:\n%s\n", driver->source_file, driver->name, errorbuf);
12121215
12131216   /* check for duplicate tags */
12141217   for (port = portlist; port != NULL; port = port->next)
src/emu/drivers/empty.c
r2762r2763
4949
5050/*************************************
5151 *
52 *  Input ports
53 *
54 *************************************/
55
56static INPUT_PORTS_START( empty )
57INPUT_PORTS_END
58
59
60
61/*************************************
62 *
6352 *  ROM definitions
6453 *
6554 *************************************/
r2762r2763
7665 *
7766 *************************************/
7867
79GAME( 2007, empty, 0, empty, empty, 0, ROT0, "MAME", "No Driver Loaded", 0 )
68GAME( 2007, empty, 0, empty, 0, 0, ROT0, "MAME", "No Driver Loaded", 0 )
src/emu/drivers/xtal.h
r2762r2763
5858   XTAL_4_9152MHz      = 4915200,
5959   XTAL_5MHz          = 5000000,      /* Mutant Night */
6060   XTAL_5_7143MHz      = 5714300,      /* Cidelsa Destroyer */
61   XTAL_6MHz          = 6000000,
61   XTAL_6MHz          = 6000000,      /* American Poker II */
6262   XTAL_6_144MHz      = 6144000,      /* Used on Alpha Denshi early 80's games sound board */
6363   XTAL_7MHz          = 7000000,      /* Jaleco Mega System PCBs */
6464   XTAL_7_15909MHz      = 7159090,      /* Blood Bros */
src/lib/util/astring.c
r2762r2763
291291
292292
293293/*-------------------------------------------------
294    astring_del - delete a substring of
295    ourself, keeping everything else
296-------------------------------------------------*/
297
298astring *astring_del(astring *str, int start, int count)
299{
300   int strlength = strlen(str->text);
301
302   /* ignore attempts to do this on the dummy */
303   if (str == &dummy_astring)
304      return str;
305
306   /* normalize parameters */
307   normalize_substr(&start, &count, strlength);
308
309   /* move the data and NULL-terminate */
310   if (count > 0)
311      memmove(str->text + start, str->text + start + count, strlength - (start + count));
312   str->text[strlength - count] = 0;
313   return str;
314}
315
316
317/*-------------------------------------------------
294318    astring_printf - printf text into an astring
295319-------------------------------------------------*/
296320
r2762r2763
498522}
499523
500524
525/*-------------------------------------------------
526    astring_replace - search in an astring for
527    another astring, replacing all instances with
528    a third and returning the number of matches
529-------------------------------------------------*/
501530
531int astring_replace(astring *str, int start, const astring *search, const astring *replace)
532{
533   return astring_replacec(str, start, search->text, replace->text);
534}
535
536
537/*-------------------------------------------------
538    astring_replacec - search in an astring for a
539    C string, replacing all instances with another
540    C string and returning the number of matches
541-------------------------------------------------*/
542
543int astring_replacec(astring *str, int start, const char *search, const char *replace)
544{
545   int searchlen = strlen(search);
546   int replacelen = strlen(replace);
547   int matches = 0;
548   int curindex;
549
550   for (curindex = astring_findc(str, start, search); curindex != -1; curindex = astring_findc(str, curindex + replacelen, search))
551   {
552      matches++;
553      astring_del(str, curindex, searchlen);
554      astring_insc(str, curindex, replace);
555   }
556   return matches;
557}
558
559
560
502561/***************************************************************************
503562    ASTRING UTILITIES
504563***************************************************************************/
src/lib/util/astring.h
r2762r2763
6969/* extract a substring of ourself, removing everything else */
7070astring *astring_substr(astring *str, int start, int count);
7171
72/* delete a substring from ourself, keeping everything else */
73astring *astring_del(astring *str, int start, int count);
74
7275/* formatted printf to an astring */
7376int astring_printf(astring *dst, const char *format, ...) ATTR_PRINTF(2,3);
7477
r2762r2763
118121/* search in an astring for a C string, returning offset or -1 if not found */
119122int astring_findc(const astring *str, int start, const char *search);
120123
124/* search in an astring for another astring, replacing all instances with a third and returning the number of matches */
125int astring_replace(astring *str, int start, const astring *search, const astring *replace);
121126
127/* search in an astring for a C string, replacing all instances with another C string and returning the number of matches */
128int astring_replacec(astring *str, int start, const char *search, const char *replace);
122129
130
131
123132/* ----- astring utilties ----- */
124133
125134/* delete all instances of 'ch' */
src/mess/drivers/n64.c
r2762r2763
6262INPUT_PORTS_END
6363
6464/* ?? */
65static const struct mips3_config config =
65static const mips3_config config =
6666{
6767   16384,            /* code cache size */
6868   8192,            /* data cache size */
src/mess/drivers/ip22.c
r2762r2763
15461546   }
15471547}
15481548
1549static const struct mips3_config config =
1549static const mips3_config config =
15501550{
15511551   32768,   /* code cache size */
15521552   32768   /* data cache size */
src/mess/drivers/ip20.c
r2762r2763
5252   return 0;
5353}
5454
55static const struct EEPROM_interface eeprom_interface_93C56 =
55static const eeprom_interface eeprom_interface_93C56 =
5656{
5757   7,               // address bits 7
5858   16,               // data bits    16
r2762r2763
6767{
6868   if (read_or_write)
6969   {
70      EEPROM_save(file);
70      eeprom_save(file);
7171   }
7272   else
7373   {
74      EEPROM_init(&eeprom_interface_93C56);
74      eeprom_init(&eeprom_interface_93C56);
7575      if (file)
7676      {
77         EEPROM_load(file);
77         eeprom_load(file);
7878      }
7979      else
8080      {
8181         int length;
8282         UINT8 *dat;
8383
84         dat = EEPROM_get_data_pointer(&length);
84         dat = eeprom_get_data_pointer(&length);
8585         memset(dat, 0, length);
8686      }
8787   }
r2762r2763
156156      break;
157157   case 0x01bc:
158158//      verboselog( 2, "HPC CPU Serial EEPROM Read\n" );
159      return ( ( EEPROM_read_bit() << 4 ) );
159      return ( ( eeprom_read_bit() << 4 ) );
160160      break;
161161   case 0x01c4:
162162      verboselog( 2, "HPC Local IO Register 0 Mask Read: %08x (%08x)\n", nHPC_LocalIOReg0Mask, mem_mask );
r2762r2763
361361      {
362362         verboselog( 2, "    CPU board LED on\n" );
363363      }
364      EEPROM_write_bit( (data & 0x00000008) ? 1 : 0 );
365      EEPROM_set_cs_line( (data & 0x00000002) ? ASSERT_LINE : CLEAR_LINE );
366      EEPROM_set_clock_line( (data & 0x00000004) ? CLEAR_LINE : ASSERT_LINE );
364      eeprom_write_bit( (data & 0x00000008) ? 1 : 0 );
365      eeprom_set_cs_line( (data & 0x00000002) ? ASSERT_LINE : CLEAR_LINE );
366      eeprom_set_clock_line( (data & 0x00000004) ? CLEAR_LINE : ASSERT_LINE );
367367      break;
368368   case 0x01c4:
369369      verboselog( 2, "HPC Local IO Register 0 Mask Write: %08x (%08x)\n", data, mem_mask );
r2762r2763
604604   }
605605}
606606
607static const struct mips3_config config =
607static const mips3_config config =
608608{
609609   32768,   /* code cache size */
610610   32768   /* data cache size */
docs/messnew.txt
r2762r2763
117117
118118Source Changes:
119119----------------
120- The core is based on MAME 0.125u2.  This incorporates all features of the
120- The core is based on MAME 0.125u3.  This incorporates all features of the
121121  update to this core.  [MAME team]
122122
123123- Fixed performance problems with -triplebuffer.  (bug #1539) [Justin Kerk]

Previous 15994 Revisions Next


© 1998-2018 The MESS Team