Previous 15994 Revisions Next

r2725 Saturday 24th May, 2008 at 15:17:10 UTC by Nathan Woods
Updated to MAME 0.125u2 core; almost certainly broken some natural keyboard
functionality and some Win32 frontend code; will rectify these soon

Also reverted Robbbert's imgtool change; it looks breaking to me
[docs]messnew.txt
[src/emu]cheat.c config.c config.h crsshair.c emuopts.c info.c inptport.c inptport.h inpttype.h* inputseq.h mame.c mame.h mamecore.h memory.c memory.h render.c sound.c ui.c uigfx.c uimenu.c uimenu.h validity.c
[src/emu/cpu]cpu.mak drcbec.c drcbeut.c drcbeut.h drcbex64.c drcbex86.c drcfe.c drcfe.h drcuml.c drcuml.h drcumld.c drcumlsh.h x86emit.h
[src/emu/cpu/mips]mips3.c mips3com.c mips3com.h mips3drc.c mips3fe.c mips3fe.h r3000.c
[src/emu/cpu/powerpc]ppcdrco.c*
[src/emu/cpu/saturn]satops.c sattable.c saturn.c saturn.h saturnds.c
[src/emu/debug]debugcpu.c
[src/emu/machine]53c810.c 53c810.h 6522via.c 6522via.h 6526cia.c 6526cia.h 6532riot.c 6532riot.h 6821pia.c 6821pia.h 6840ptm.c 6840ptm.h 68681.c 68681.h am53cf96.c am53cf96.h generic.c pc16552d.c pc16552d.h smc91c9x.c smc91c9x.h tmp68301.c tmp68301.h wd33c93.c wd33c93.h z80ctc.c z80ctc.h z80pio.c z80pio.h z80sio.c z80sio.h
[src/emu/sound]2151intf.h 2203intf.c 2203intf.h 2608intf.c 2608intf.h 2610intf.c 2610intf.h 2612intf.c 2612intf.h 262intf.c 262intf.h 3812intf.c 3812intf.h 5220intf.h aica.c aica.h disc_inp.c es5503.c es5503.h es5506.c es5506.h ics2115.c ics2115.h k054539.c k054539.h msm5205.c msm5205.h pokey.c pokey.h psx.c psx.h scsp.c scsp.h tms5110.c tms5110r.c tms5220.c tms5220.h ym2151.c ym2151.h ymf271.c ymf271.h ymf278b.c ymf278b.h ymz280b.c ymz280b.h
[src/emu/video]tms9928a.c tms9928a.h v9938.c v9938.h vooddefs.h voodoo.c voodoo.h
[src/mame]mame.mak mamedriv.c
[src/mame/audio]cage.c cage.h cchasm.c cinemat.c cyberbal.c dcs.c exidy.c harddriv.c irem.c jaguar.c jedi.c m72.c m72.h mcr.c seibu.c seibu.h senjyo.c t5182.c taito_en.c williams.c
[src/mame/drivers]2mindril.c 8080bw.c ace.c acefruit.c actfancr.c aerofgt.c airbustr.c alg.c alpha68k.c amspdwy.c angelkds.c appoooh.c aquarium.c argus.c artmagic.c ashnojoe.c astinvad.c astrocde.c astrof.c asuka.c atarigt.c backfire.c battlane.c battlera.c bbusters.c beathead.c berzerk.c bfcobra.c bfm_sc2.c bigfghtr.c bishi.c bishjan.c blktiger.c blmbycar.c blockout.c bmcbowl.c bnstars.c boogwing.c brkthru.c btime.c bublbobl.c bwing.c cabal.c capbowl.c carrera.c cave.c cbuster.c ccastles.c cchasm.c cclimber.c centiped.c cheekyms.c chinagat.c chinsan.c chqflag.c cinemat.c cischeat.c cliffhgr.c cloud9.c cninja.c compgolf.c cps1.c crbaloon.c crgolf.c crospang.c crshrace.c darius.c darkseal.c dassault.c dblewing.c dbz.c dcheese.c ddealer.c ddragon.c ddragon3.c ddrible.c dec0.c dec8.c deco156.c deco32.c deco_mlc.c deniam.c dgpix.c dietgo.c discoboy.c dlair.c dmndrby.c docastle.c dooyong.c dorachan.c drmicro.c dynax.c enigma2.c eolith.c ertictac.c exerion.c exidy.c exidy440.c exprraid.c exzisus.c f1gp.c fantland.c fcombat.c fcrash.c filetto.c firebeat.c firetrap.c firetrk.c fitfight.c flstory.c fortecar.c fromanc2.c fromance.c funkyjet.c fuukifg2.c fuukifg3.c gaiden.c galaxian.c galdrvr.c galivan.c galpanic.c galspnbl.c gameplan.c gauntlet.c genesis.c gijoe.c gladiatr.c goal92.c gotcha.c gottlieb.c gstriker.c gticlub.c gtipoker.c guab.c gumbo.c gunpey.c hcastle.c hnayayoi.c hng64.c hornet.c hshavoc.c hyperspt.c hyprduel.c igs_blit.c intrscti.c inufuku.c itech32.c itech8.c jchan.c jpmimpct.c jrpacman.c kaneko16.c karnov.c kchamp.c kingpin.c konamigq.c konamigv.c ksys573.c ladybug.c laserbat.c lasso.c lastduel.c lastfght.c lemmings.c lethal.c lethalj.c lkage.c lockon.c looping.c lordgun.c lsasquad.c lwings.c m10.c m107.c m62.c m92.c macrossp.c madalien.c madmotor.c mappy.c mastboy.c matmania.c maxaflex.c mcatadv.c mcr3.c mcr68.c meadows.c megadriv.c megasys1.c meritm.c metlclsh.c metro.c mgolf.c midas.c midzeus.c mirage.c missb2.c missile.c mitchell.c mlanding.c model2.c model3.c mpu4.c mpu4drvr.c mugsmash.c mw8080bw.c mystston.c namcona1.c namconb1.c namcos1.c namcos12.c naomi.c nbmj9195.c nemesis.c neodrvr.c neogeo.c ninjakd2.c ninjaw.c niyanpai.c nmg5.c nmk16.c nwk-tr.c nycaptor.c nyny.c ojankohs.c oneshot.c onetwo.c opwolf.c othldrby.c othunder.c pacman.c pcktgal.c pengo.c pgm.c phoenix.c pipedrm.c pipeline.c pkscram.c pntnpuzl.c polyplay.c powerins.c prehisle.c psikyo.c psikyo4.c psikyosh.c psychic5.c pushman.c qdrmfgp.c r2dtank.c rabbit.c rainbow.c rastan.c rbmk.c realbrk.c renegade.c rohga.c rollrace.c rpunch.c sandscrp.c sangho.c scramble.c seattle.c segag80r.c segag80v.c segahang.c segas16b.c segas24.c segas32.c segaxbd.c segaybd.c seibuspi.c seta.c seta2.c sf.c sg1000a.c shadfrce.c shangha3.c shanghai.c shootout.c sidearms.c sidepckt.c simpsons.c slapfght.c slapshot.c smstrv.c snk.c snk68.c snookr10.c snowbros.c spbactn.c spcforce.c spdodgeb.c spiders.c splash.c spy.c srmp2.c ssfindo.c sshangha.c ssv.c stactics.c stadhero.c steaser.c stepstag.c stfight.c strnskil.c stv.c suna16.c suna8.c supbtime.c superqix.c suprgolf.c suprnova.c suprridr.c suprslam.c surpratk.c system16.c system18.c tail2nos.c taito_b.c taito_f2.c taito_h.c taito_l.c taito_x.c taito_z.c taitoair.c taitojc.c taitosj.c taotaido.c tatsumi.c tbowl.c tecmo.c tecmo16.c tecmosys.c tehkanwc.c tempest.c tetrisp2.c tetriunk.c thedeep.c tigeroad.c tmaster.c tmnt.c tnzs.c toaplan1.c toaplan2.c toki.c topshoot.c topspeed.c toratora.c trackfld.c triplhnt.c trvquest.c tsamurai.c ttchamp.c tubep.c tumbleb.c tumblep.c twincobr.c ultratnk.c ultrsprt.c undrfire.c vaportra.c vball.c vegas.c vicdual.c videopin.c volfied.c vsnes.c wardner.c warriorb.c wc90.c wc90b.c welltris.c wgp.c wheelfir.c wrally.c wwfsstar.c wwfwfest.c xain.c yunsun16.c yunsung8.c zac2650.c zaccaria.c zaxxon.c zn.c zr107.c
[src/mame/includes]atari.h dynax.h genesis.h namcona1.h psx.h
[src/mame/layout]shuttlei.lay*
[src/mame/machine]ajax.c amiga.c atari.c atarigen.c atarigen.h beezer.c daikaiju.c galaxold.c kaneko16.c konamigx.c konamiic.c konamiic.h mcr.c midwayic.c midwayic.h namcos1.c namcos2.c nmk004.c nmk004.h pckeybrd.c psx.c qix.c segaic16.c segaic16.h seicop.c starwars.c stfight.c twincobr.c williams.c
[src/mame/video]aerofgt.c atari.c dkong.c dynax.c exidy440.c f1gp.c galpani2.c gameplan.c groundfx.c gtia.c homedata.c jagobj.c jaguar.c macrossp.c midvunit.c midzeus.c n64.c namcona1.c pacland.c phoenix.c psx.c st0016.c stactics.c taitojc.c undrfire.c victory.c
[src/mess]configms.c filemngr.c inputx.c inputx.h mess.h mesvalid.c tapectrl.c uimess.c uimess.h
[src/mess/drivers]a2600.c adam.c apf.c at.c bbcbc.c cgenie.c coleco.c crvision.c dc.c einstein.c ex800.c geneve.c ip20.c ip22.c kim1.c mpf1.c pc.c pdp1.c psx.c saturn.c sg1000.c sord.c super80.c ti99_4p.c ti99_4x.c ti99_8.c tutor.c x68k.c
[src/mess/includes]apple2gs.h hp48.h msx.h pc8801.h svi318.h vectrex.h
[src/mess/machine]99_peb.c 99_peb.h aim65.c amigakbd.c apple2gs.c apple3.c atom.c ay3600.c bbc.c bebox.c c64.c cbmb.c coco.c comx35.c concept.c dgn_beta.c geneve.c hp48.c kc.c lisa.c mac.c mbee.c mc6846.c mc6846.h microtan.c msx.c mtx.c oric.c osborne1.c pc8801.c pc_joy.c pce.c pet.c svi318.c sym1.c thomson.c ti99_4x.c ti99_4x.h vc1541.c vc20.c vectrex.c
[src/mess/osd/windows]dialog.c dialog.h menu.c
[src/mess/osd/winui]msuiutil.c
[src/mess/tools/imgtool]imgtool.c
[src/mess/tools/messtest]testmess.c tststubs.c
[src/mess/video]pc_cga.c
[src/osd]osdepend.h
[src/osd/windows]debugwin.c drawd3d.c input.c video.c
[src/osd/winui]mui_util.c

src/mame/audio/cchasm.c
r2724r2725
66
77#include "driver.h"
88#include "streams.h"
9#include "deprecat.h"
109#include "cpu/z80/z80.h"
1110#include "machine/z80ctc.h"
1211#include "cchasm.h"
r2724r2725
132131static int channel_active[2];
133132static int output[2];
134133
135static void ctc_interrupt (int state)
134static void ctc_interrupt (running_machine *machine, int state)
136135{
137   cpunum_set_input_line(Machine, 1, 0, state);
136   cpunum_set_input_line(machine, 1, 0, state);
138137}
139138
140139static WRITE8_HANDLER( ctc_timer_1_w )
src/mame/audio/jaguar.c
r2724r2725
261261      jaguar_wave_rom[0x200 + i] = (int)(32767. * sin(2.0 * M_PI * (double)i / (double)0x80));
262262
263263      /* F1DA00 = traingle wave with noise */
264      jaguar_wave_rom[0x280 + i] = jaguar_wave_rom[0x000 + i] * (mame_rand(Machine) % 32768) / 32768;
264      jaguar_wave_rom[0x280 + i] = jaguar_wave_rom[0x000 + i] * (mame_rand(machine) % 32768) / 32768;
265265
266266      /* F1DC00 = spike */
267267      jaguar_wave_rom[0x300 + i] = (i == 0x40) ? 32767 : 0;
268268
269269      /* F1DE00 = white noise */
270      jaguar_wave_rom[0x380 + i] = mame_rand(Machine) % 32768;
270      jaguar_wave_rom[0x380 + i] = mame_rand(machine) % 32768;
271271   }
272272
273273#if ENABLE_SPEEDUP_HACKS
src/mame/audio/cinemat.c
r2724r2725
14901490};
14911491
14921492
1493static void ctc_interrupt(int state)
1493static void ctc_interrupt(running_machine *machine, int state)
14941494{
1495   cpunum_set_input_line(Machine, 1, 0, state);
1495   cpunum_set_input_line(machine, 1, 0, state);
14961496}
14971497
14981498
src/mame/audio/cyberbal.c
r2724r2725
55****************************************************************************/
66
77#include "driver.h"
8#include "deprecat.h"
98#include "machine/atarigen.h"
109#include "sound/dac.h"
1110#include "includes/cyberbal.h"
r2724r2725
8483   if (!io_68k_int)
8584   {
8685      io_68k_int = 1;
87      update_sound_68k_interrupts(Machine);
86      update_sound_68k_interrupts(machine);
8887   }
8988}
9089
r2724r2725
127126   if (io_68k_int)
128127   {
129128      io_68k_int = 0;
130      update_sound_68k_interrupts(Machine);
129      update_sound_68k_interrupts(machine);
131130   }
132131}
133132
r2724r2725
161160   if (fast_68k_int)
162161   {
163162      fast_68k_int = 0;
164      update_sound_68k_interrupts(Machine);
163      update_sound_68k_interrupts(machine);
165164   }
166165}
src/mame/audio/cage.c
r2724r2725
4040static UINT8 cpu_to_cage_ready;
4141static UINT8 cage_to_cpu_ready;
4242
43static void (*cage_irqhandler)(int);
43static void (*cage_irqhandler)(running_machine *, int);
4444
4545static attotime serial_period_per_word;
4646
r2724r2725
161161   memory_set_bankptr(10, memory_region(boot_region));
162162   memory_set_bankptr(11, memory_region(boot_region + 1));
163163
164   cage_cpu = mame_find_cpu_index(Machine, "cage");
164   cage_cpu = mame_find_cpu_index(machine, "cage");
165165   cage_cpu_clock_period = ATTOTIME_IN_HZ(cpunum_get_clock(cage_cpu));
166166   cage_cpu_h1_clock_period = attotime_mul(cage_cpu_clock_period, 2);
167167
r2724r2725
174174}
175175
176176
177void cage_set_irq_handler(void (*irqhandler)(int))
177void cage_set_irq_handler(void (*irqhandler)(running_machine *, int))
178178{
179179   cage_irqhandler = irqhandler;
180180}
r2724r2725
447447      if ((cage_control & 2) && cage_to_cpu_ready)
448448         reason |= CAGE_IRQ_REASON_DATA_READY;
449449
450      (*cage_irqhandler)(reason);
450      (*cage_irqhandler)(Machine, reason);
451451   }
452452
453453   /* set the IOF input lines */
src/mame/audio/cage.h
r2724r2725
1111MACHINE_DRIVER_EXTERN( cage_seattle );
1212
1313void cage_init(running_machine *machine, int boot_region, offs_t speedup);
14void cage_set_irq_handler(void (*irqhandler)(int));
14void cage_set_irq_handler(void (*irqhandler)(running_machine *, int));
1515void cage_reset_w(int state);
1616
1717UINT16 main_from_cage_r(void);
src/mame/audio/senjyo.c
r2724r2725
66
77
88/* z80 pio */
9static void pio_interrupt(int state)
9static void pio_interrupt(running_machine *machine, int state)
1010{
11   cpunum_set_input_line(Machine, 1, 0, state);
11   cpunum_set_input_line(machine, 1, 0, state);
1212}
1313
1414static const z80pio_interface pio_intf =
r2724r2725
1919};
2020
2121/* z80 ctc */
22static void ctc_interrupt (int state)
22static void ctc_interrupt (running_machine *machine, int state)
2323{
24   cpunum_set_input_line(Machine, 1, 0, state);
24   cpunum_set_input_line(machine, 1, 0, state);
2525}
2626
2727static z80ctc_interface ctc_intf =
src/mame/audio/mcr.c
r2724r2725
530530   if (~z_mask & 0x20)  csdeluxe_status = (csdeluxe_status & ~2) | ((data >> 4) & 2);
531531}
532532
533static void csdeluxe_irq(int state)
533static void csdeluxe_irq(running_machine *machine, int state)
534534{
535535   int combined_state = pia_get_irq_a(0) | pia_get_irq_b(0);
536536
537     cpunum_set_input_line(Machine, csdeluxe_sound_cpu, 4, combined_state ? ASSERT_LINE : CLEAR_LINE);
537     cpunum_set_input_line(machine, csdeluxe_sound_cpu, 4, combined_state ? ASSERT_LINE : CLEAR_LINE);
538538}
539539
540540static TIMER_CALLBACK( csdeluxe_delayed_data_w )
r2724r2725
653653   if (~z_mask & 0x20)  soundsgood_status = (soundsgood_status & ~2) | ((data >> 4) & 2);
654654}
655655
656static void soundsgood_irq(int state)
656static void soundsgood_irq(running_machine *machine, int state)
657657{
658658   int combined_state = pia_get_irq_a(1) | pia_get_irq_b(1);
659659
660     cpunum_set_input_line(Machine, soundsgood_sound_cpu, 4, combined_state ? ASSERT_LINE : CLEAR_LINE);
660     cpunum_set_input_line(machine, soundsgood_sound_cpu, 4, combined_state ? ASSERT_LINE : CLEAR_LINE);
661661}
662662
663663static TIMER_CALLBACK( soundsgood_delayed_data_w )
r2724r2725
747747   turbocs_status = (data >> 4) & 3;
748748}
749749
750static void turbocs_irq(int state)
750static void turbocs_irq(running_machine *machine, int state)
751751{
752752   int combined_state = pia_get_irq_a(0) | pia_get_irq_b(0);
753753
754   cpunum_set_input_line(Machine, turbocs_sound_cpu, M6809_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
754   cpunum_set_input_line(machine, turbocs_sound_cpu, M6809_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
755755}
756756
757757static TIMER_CALLBACK( turbocs_delayed_data_w )
r2724r2725
880880   squawkntalk_tms_strobes = data;
881881}
882882
883static void squawkntalk_irq(int state)
883static void squawkntalk_irq(running_machine *machine, int state)
884884{
885885   int combined_state = pia_get_irq_a(0) | pia_get_irq_b(0) | pia_get_irq_a(1) | pia_get_irq_b(1);
886886
887   cpunum_set_input_line(Machine, squawkntalk_sound_cpu, M6808_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
887   cpunum_set_input_line(machine, squawkntalk_sound_cpu, M6808_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
888888}
889889
890890static TIMER_CALLBACK( squawkntalk_delayed_data_w )
src/mame/audio/t5182.c
r2724r2725
190190   timer_call_after_resynch(NULL, CPU_CLEAR,setirq_callback);
191191}
192192
193static void t5182_ym2151_irq_handler(int irq)
193static void t5182_ym2151_irq_handler(running_machine *machine, int irq)
194194{
195195   if (irq)
196196      timer_call_after_resynch(NULL, YM2151_ASSERT,setirq_callback);
src/mame/audio/irem.c
r2724r2725
55***************************************************************************/
66
77#include "driver.h"
8#include "deprecat.h"
98#include "irem.h"
109#include "cpu/m6800/m6800.h"
1110#include "sound/ay8910.h"
r2724r2725
174173 *
175174 *************************************/
176175
177static void adpcm_int(int data)
176static void adpcm_int(running_machine *machine, int data)
178177{
179   cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, PULSE_LINE);
178   cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, PULSE_LINE);
180179
181180   /* the first MSM5205 clocks the second */
182181   if (sndti_exists(SOUND_MSM5205, 1))
src/mame/audio/taito_en.c
r2724r2725
178178*/
179179//  offset<<=1;
180180
181//if (offset<7 && es5510_dsp_ram[0]!=0xff) return mame_rand(Machine)%0xffff;
181//if (offset<7 && es5510_dsp_ram[0]!=0xff) return mame_rand(machine)%0xffff;
182182
183183   if (offset==0x12) return 0;
184184
src/mame/audio/harddriv.c
r2724r2725
55****************************************************************************/
66
77#include "driver.h"
8#include "deprecat.h"
98#include "cpu/tms32010/tms32010.h"
109#include "sound/dac.h"
1110#include "machine/atarigen.h"
r2724r2725
121120   cpunum_set_input_line(machine, hdcpu_sound, INPUT_LINE_RESET, ASSERT_LINE);
122121   cpunum_set_input_line(machine, hdcpu_sound, INPUT_LINE_RESET, CLEAR_LINE);
123122   mainflag = soundflag = 0;
124   update_68k_interrupts(Machine);
123   update_68k_interrupts(machine);
125124   logerror("%06X:Reset sound\n", activecpu_get_previouspc());
126125}
127126
r2724r2725
136135READ16_HANDLER( hdsnd68k_data_r )
137136{
138137   mainflag = 0;
139   update_68k_interrupts(Machine);
138   update_68k_interrupts(machine);
140139   logerror("%06X:sound read from main=%04X\n", activecpu_get_previouspc(), maindata);
141140   return maindata;
142141}
r2724r2725
240239WRITE16_HANDLER( hdsnd68k_irqclr_w )
241240{
242241   irq68k = 0;
243   update_68k_interrupts(Machine);
242   update_68k_interrupts(machine);
244243}
245244
246245
r2724r2725
358357{
359358   /* generate 68k IRQ */
360359   irq68k = 1;
361   update_68k_interrupts(Machine);
360   update_68k_interrupts(machine);
362361}
363362
364363
src/mame/audio/m72.c
r2724r2725
113113   state_save_register_global(sample_addr);
114114}
115115
116void m72_ym2151_irq_handler(int irq)
116void m72_ym2151_irq_handler(running_machine *machine, int irq)
117117{
118118   if (irq)
119119      timer_call_after_resynch(NULL, YM2151_ASSERT,setvector_callback);
src/mame/audio/seibu.c
r2724r2725
3434
3535#include "driver.h"
3636#include "streams.h"
37#include "deprecat.h"
3837#include "audio/seibu.h"
3938#include "sound/3812intf.h"
4039#include "sound/2151intf.h"
r2724r2725
336335   update_irq_lines(machine, RST18_CLEAR);
337336}
338337
339void seibu_ym3812_irqhandler(int linestate)
338void seibu_ym3812_irqhandler(running_machine *machine, int linestate)
340339{
341   update_irq_lines(Machine, linestate ? RST10_ASSERT : RST10_CLEAR);
340   update_irq_lines(machine, linestate ? RST10_ASSERT : RST10_CLEAR);
342341}
343342
344void seibu_ym2151_irqhandler(int linestate)
343void seibu_ym2151_irqhandler(running_machine *machine, int linestate)
345344{
346   update_irq_lines(Machine, linestate ? RST10_ASSERT : RST10_CLEAR);
345   update_irq_lines(machine, linestate ? RST10_ASSERT : RST10_CLEAR);
347346}
348347
349void seibu_ym2203_irqhandler(int linestate)
348void seibu_ym2203_irqhandler(running_machine *machine, int linestate)
350349{
351   update_irq_lines(Machine, linestate ? RST10_ASSERT : RST10_CLEAR);
350   update_irq_lines(machine, linestate ? RST10_ASSERT : RST10_CLEAR);
352351}
353352
354353/***************************************************************************/
src/mame/audio/m72.h
r2724r2725
55****************************************************************************/
66
77MACHINE_RESET( m72_sound );
8void m72_ym2151_irq_handler(int irq);
8void m72_ym2151_irq_handler(running_machine *machine, int irq);
99WRITE8_HANDLER( m72_sound_command_byte_w );
1010WRITE16_HANDLER( m72_sound_command_w );
1111WRITE8_HANDLER( m72_sound_irq_ack_w );
src/mame/audio/seibu.h
r2724r2725
4747WRITE8_HANDLER( seibu_rst18_ack_w );
4848WRITE8_HANDLER( seibu_bank_w );
4949WRITE8_HANDLER( seibu_coin_w );
50void seibu_ym3812_irqhandler(int linestate);
51void seibu_ym2151_irqhandler(int linestate);
52void seibu_ym2203_irqhandler(int linestate);
50void seibu_ym3812_irqhandler(running_machine *machine, int linestate);
51void seibu_ym2151_irqhandler(running_machine *machine, int linestate);
52void seibu_ym2203_irqhandler(running_machine *machine, int linestate);
5353READ8_HANDLER( seibu_soundlatch_r );
5454READ8_HANDLER( seibu_main_data_pending_r );
5555WRITE8_HANDLER( seibu_main_data_w );
src/mame/audio/williams.c
r2724r2725
6565
6666static void init_audio_state(running_machine *machine);
6767
68static void cvsd_ym2151_irq(int state);
69static void adpcm_ym2151_irq(int state);
70static void cvsd_irqa(int state);
71static void cvsd_irqb(int state);
68static void cvsd_ym2151_irq(running_machine *machine, int state);
69static void adpcm_ym2151_irq(running_machine *machine, int state);
70static void cvsd_irqa(running_machine *machine, int state);
71static void cvsd_irqb(running_machine *machine, int state);
7272
7373static WRITE8_HANDLER( cvsd_bank_select_w );
7474static READ8_HANDLER( cvsd_pia_r );
r2724r2725
404404    CVSD IRQ GENERATION CALLBACKS
405405****************************************************************************/
406406
407static void cvsd_ym2151_irq(int state)
407static void cvsd_ym2151_irq(running_machine *machine, int state)
408408{
409409   pia_set_input_ca1(williams_pianum, !state);
410410}
411411
412412
413static void cvsd_irqa(int state)
413static void cvsd_irqa(running_machine *machine, int state)
414414{
415   cpunum_set_input_line(Machine, sound_cpunum, M6809_FIRQ_LINE, state ? ASSERT_LINE : CLEAR_LINE);
415   cpunum_set_input_line(machine, sound_cpunum, M6809_FIRQ_LINE, state ? ASSERT_LINE : CLEAR_LINE);
416416}
417417
418418
419static void cvsd_irqb(int state)
419static void cvsd_irqb(running_machine *machine, int state)
420420{
421   cpunum_set_input_line(Machine, sound_cpunum, INPUT_LINE_NMI, state ? ASSERT_LINE : CLEAR_LINE);
421   cpunum_set_input_line(machine, sound_cpunum, INPUT_LINE_NMI, state ? ASSERT_LINE : CLEAR_LINE);
422422}
423423
424424
r2724r2725
427427    ADPCM IRQ GENERATION CALLBACKS
428428****************************************************************************/
429429
430static void adpcm_ym2151_irq(int state)
430static void adpcm_ym2151_irq(running_machine *machine, int state)
431431{
432   cpunum_set_input_line(Machine, sound_cpunum, M6809_FIRQ_LINE, state ? ASSERT_LINE : CLEAR_LINE);
432   cpunum_set_input_line(machine, sound_cpunum, M6809_FIRQ_LINE, state ? ASSERT_LINE : CLEAR_LINE);
433433}
434434
435435
src/mame/audio/dcs.c
r2724r2725
935935   memset(&dcs, 0, sizeof(dcs));
936936
937937   /* find the DCS CPU and the sound ROMs */
938   dcs.cpunum = mame_find_cpu_index(Machine, "dcs2");
938   dcs.cpunum = mame_find_cpu_index(machine, "dcs2");
939939   dcs.rev = 2;
940940   if ((INT8)dcs.cpunum == -1)
941941   {
942      dcs.cpunum = mame_find_cpu_index(Machine, "dsio");
942      dcs.cpunum = mame_find_cpu_index(machine, "dsio");
943943      dcs.rev = 3;
944944   }
945945   if ((INT8)dcs.cpunum == -1)
946946   {
947      dcs.cpunum = mame_find_cpu_index(Machine, "denver");
947      dcs.cpunum = mame_find_cpu_index(machine, "denver");
948948      dcs.rev = 4;
949949   }
950950   dcs.channels = 2;
r2724r2725
989989   dcs_register_state();
990990
991991   /* reset the system */
992   dcs_reset(Machine, NULL, 0);
992   dcs_reset(machine, NULL, 0);
993993}
994994
995995
src/mame/audio/jedi.c
r2724r2725
103103
104104CUSTOM_INPUT( jedi_audio_comm_stat_r )
105105{
106   jedi_state *state = machine->driver_data;
106   jedi_state *state = field->port->machine->driver_data;
107107   return *state->audio_comm_stat >> 6;
108108}
109109
src/mame/audio/exidy.c
r2724r2725
130130 *
131131 *************************************/
132132
133static void update_irq_state(/* unused */ int state)
133static void update_irq_state(running_machine *machine, /* unused */ int state)
134134{
135   cpunum_set_input_line(Machine, 1, M6502_IRQ_LINE, (pia_get_irq_b(1) | riot_irq_state) ? ASSERT_LINE : CLEAR_LINE);
135   cpunum_set_input_line(machine, 1, M6502_IRQ_LINE, (pia_get_irq_b(1) | riot_irq_state) ? ASSERT_LINE : CLEAR_LINE);
136136}
137137
138138
r2724r2725
415415      /* generate the IRQ */
416416      riot_irq_flag |= 0x80;
417417      riot_irq_state = riot_timer_irq_enable;
418      update_irq_state(0);
418      update_irq_state(machine, 0);
419419
420420      /* now start counting clock cycles down */
421421      riot_state = RIOT_POST_COUNT;
r2724r2725
493493      if (riot_state != RIOT_COUNT)
494494         riot_irq_flag &= ~0x80;
495495      riot_irq_state = 0;
496      update_irq_state(0);
496      update_irq_state(machine, 0);
497497
498498      /* set the enable from the offset */
499499      riot_timer_irq_enable = (offset & 0x08) ? 1 : 0;
r2724r2725
546546      int temp = riot_irq_flag;
547547      riot_irq_flag = 0;
548548      riot_irq_state = 0;
549      update_irq_state(0);
549      update_irq_state(machine, 0);
550550      return temp;
551551   }
552552
src/mame/machine/nmk004.c
r2724r2725
11#include "driver.h"
2#include "deprecat.h"
32#include "nmk004.h"
43#include "sound/2203intf.h"
54#include "sound/okim6295.h"
r2724r2725
997996
998997
999998
1000void NMK004_irq(int irq)
999void NMK004_irq(running_machine *machine, int irq)
10011000{
10021001   int status;
10031002
10041003   if (!irq) return;
10051004
1006   status = YM2203_status_port_0_r(Machine,0);
1005   status = YM2203_status_port_0_r(machine,0);
10071006
10081007   if (status & 1)   // timer A expired
10091008   {
1010      oki_update_state(Machine);
1011      get_command(Machine);
1012      update_music(Machine);
1009      oki_update_state(machine);
1010      get_command(machine);
1011      update_music(machine);
10131012
10141013      // restart timer
1015      YM2203_control_port_0_w(Machine, 0, 0x27);
1016      YM2203_write_port_0_w(Machine, 0, 0x15);
1014      YM2203_control_port_0_w(machine, 0, 0x27);
1015      YM2203_write_port_0_w(machine, 0, 0x15);
10171016   }
10181017}
10191018
src/mame/machine/nmk004.h
r2724r2725
11void NMK004_init(void);
2void NMK004_irq(int irq);
2void NMK004_irq(running_machine *machine, int irq);
33READ16_HANDLER( NMK004_r );
44WRITE16_HANDLER( NMK004_w );
src/mame/machine/atari.c
r2724r2725
4040
4141static void pokey_reset(running_machine *machine);
4242
43void atari_interrupt_cb(int mask)
43void atari_interrupt_cb(running_machine *machine, int mask)
4444{
4545
4646   if (VERBOSE_POKEY)
r2724r2725
6969         logerror("atari interrupt_cb TIMR1\n");
7070   }
7171
72   cpunum_set_input_line(Machine, 0, 0, HOLD_LINE);
72   cpunum_set_input_line(machine, 0, 0, HOLD_LINE);
7373}
7474
7575/**************************************************************
r2724r2725
135135   /* check if self-test ROM changed */
136136   if ( new_mmu & 0x80 )
137137   {
138      logerror("%s MMU SELFTEST RAM\n", Machine->gamedrv->name);
138      logerror("%s MMU SELFTEST RAM\n", machine->gamedrv->name);
139139      rbank2 = SMH_NOP;
140140      wbank2 = SMH_NOP;
141141   }
142142   else
143143   {
144      logerror("%s MMU SELFTEST ROM\n", Machine->gamedrv->name);
144      logerror("%s MMU SELFTEST ROM\n", machine->gamedrv->name);
145145      rbank2 = SMH_BANK2;
146146      wbank2 = SMH_UNMAP;
147147   }
r2724r2725
159159   /* check if memory C000-FFFF changed */
160160   if( new_mmu & 0x01 )
161161   {
162      logerror("%s MMU BIOS ROM\n", Machine->gamedrv->name);
162      logerror("%s MMU BIOS ROM\n", machine->gamedrv->name);
163163      rbank3 = SMH_BANK3;
164164      wbank3 = SMH_UNMAP;
165165      base3 = memory_region(REGION_CPU1)+0x14000;  /* 8K lo BIOS */
r2724r2725
169169   }
170170   else
171171   {
172      logerror("%s MMU BIOS RAM\n", Machine->gamedrv->name);
172      logerror("%s MMU BIOS RAM\n", machine->gamedrv->name);
173173      rbank3 = SMH_BANK3;
174174      wbank3 = SMH_BANK3;
175175      base3 = memory_region(REGION_CPU1)+0x0c000;  /* 8K RAM */
r2724r2725
185185   /* check if BASIC changed */
186186   if( new_mmu & 0x02 )
187187   {
188      logerror("%s MMU BASIC RAM\n", Machine->gamedrv->name);
188      logerror("%s MMU BASIC RAM\n", machine->gamedrv->name);
189189      rbank1 = SMH_BANK1;
190190      wbank1 = SMH_BANK1;
191191      base1 = memory_region(REGION_CPU1)+0x0a000;  /* 8K RAM */
192192   }
193193   else
194194   {
195      logerror("%s MMU BASIC ROM\n", Machine->gamedrv->name);
195      logerror("%s MMU BASIC ROM\n", machine->gamedrv->name);
196196      rbank1 = SMH_BANK1;
197197      wbank1 = SMH_UNMAP;
198198      base1 = memory_region(REGION_CPU1)+0x10000;  /* 8K BASIC */
r2724r2725
203203   /* check if self-test ROM changed */
204204   if( new_mmu & 0x80 )
205205   {
206      logerror("%s MMU SELFTEST RAM\n", Machine->gamedrv->name);
206      logerror("%s MMU SELFTEST RAM\n", machine->gamedrv->name);
207207      rbank2 = SMH_BANK2;
208208      wbank2 = SMH_BANK2;
209209      base2 = memory_region(REGION_CPU1)+0x05000;  /* 0x0800 bytes */
210210   }
211211   else
212212   {
213      logerror("%s MMU SELFTEST ROM\n", Machine->gamedrv->name);
213      logerror("%s MMU SELFTEST ROM\n", machine->gamedrv->name);
214214      rbank2 = SMH_BANK2;
215215      wbank2 = SMH_UNMAP;
216216      base2 = memory_region(REGION_CPU1)+0x15000;  /* 0x0800 bytes */
r2724r2725
742742
743743   /* GTIA */
744744   memset(&gtia_intf, 0, sizeof(gtia_intf));
745   if (port_tag_to_index("console") >= 0)
745   if (input_port_by_tag(machine->portconfig, "console") != NULL)
746746      gtia_intf.console_read = console_read;
747747   if (sndti_exists(SOUND_DAC, 0))
748748      gtia_intf.console_write = console_write;
749749   gtia_init(machine, &gtia_intf);
750750
751751   /* pokey */
752   add_reset_callback(Machine, pokey_reset);
752   add_reset_callback(machine, pokey_reset);
753753
754754   /* PIA */
755755   if (pia_intf)
756756   {
757757      pia_config(0, pia_intf);
758      add_reset_callback(Machine, _pia_reset);
758      add_reset_callback(machine, _pia_reset);
759759   }
760760
761761   /* ANTIC */
762   add_reset_callback(Machine, _antic_reset);
762   add_reset_callback(machine, _antic_reset);
763763
764764   /* cartridge */
765765   if (has_cart)
766      add_reset_callback(Machine, cart_reset);
766      add_reset_callback(machine, cart_reset);
767767
768768#ifdef MESS
769769   {
770770      offs_t ram_top;
771771      offs_t ram_size;
772772
773      if (!strcmp(Machine->gamedrv->name, "a400")
774         || !strcmp(Machine->gamedrv->name, "a400pal")
775         || !strcmp(Machine->gamedrv->name, "a800")
776         || !strcmp(Machine->gamedrv->name, "a800pal")
777         || !strcmp(Machine->gamedrv->name, "a800xl"))
773      if (!strcmp(machine->gamedrv->name, "a400")
774         || !strcmp(machine->gamedrv->name, "a400pal")
775         || !strcmp(machine->gamedrv->name, "a800")
776         || !strcmp(machine->gamedrv->name, "a800pal")
777         || !strcmp(machine->gamedrv->name, "a800xl"))
778778      {
779779         ram_size = 0xA000;
780780      }
src/mame/machine/twincobr.c
r2724r2725
44 ****************************************************************************/
55
66#include "driver.h"
7#include "deprecat.h"
87#include "cpu/m68000/m68000.h"
98#include "cpu/tms32010/tms32010.h"
109#include "twincobr.h"
r2724r2725
191190}
192191
193192
194static void twincobr_dsp(int enable)
193static void twincobr_dsp(running_machine *machine, int enable)
195194{
196195   twincobr_dsp_on = enable;
197196   if (enable) {
198197      LOG(("Turning DSP on and main CPU off\n"));
199      cpunum_set_input_line(Machine, 2, INPUT_LINE_HALT, CLEAR_LINE);
200      cpunum_set_input_line(Machine, 2, 0, ASSERT_LINE); /* TMS32010 INT */
201      cpunum_set_input_line(Machine, 0, INPUT_LINE_HALT, ASSERT_LINE);
198      cpunum_set_input_line(machine, 2, INPUT_LINE_HALT, CLEAR_LINE);
199      cpunum_set_input_line(machine, 2, 0, ASSERT_LINE); /* TMS32010 INT */
200      cpunum_set_input_line(machine, 0, INPUT_LINE_HALT, ASSERT_LINE);
202201   }
203202   else {
204203      LOG(("Turning DSP off\n"));
205      cpunum_set_input_line(Machine, 2, 0, CLEAR_LINE); /* TMS32010 INT */
206      cpunum_set_input_line(Machine, 2, INPUT_LINE_HALT, ASSERT_LINE);
204      cpunum_set_input_line(machine, 2, 0, CLEAR_LINE); /* TMS32010 INT */
205      cpunum_set_input_line(machine, 2, INPUT_LINE_HALT, ASSERT_LINE);
207206   }
208207}
209208
210209static STATE_POSTLOAD( twincobr_restore_dsp )
211210{
212   twincobr_dsp(twincobr_dsp_on);
211   twincobr_dsp(machine, twincobr_dsp_on);
213212}
214213
215214
216static void toaplan0_control_w(int offset, int data)
215static void toaplan0_control_w(running_machine *machine, int offset, int data)
217216{
218217   LOG(("CPU0:%08x  Writing %08x to %08x.\n",activecpu_get_pc(),data,toaplan_port_type[toaplan_main_cpu] - offset));
219218
r2724r2725
231230      case 0x0009: twincobr_bg_ram_bank = 0x1000; break;
232231      case 0x000a: twincobr_fg_rom_bank = 0x0000; break;
233232      case 0x000b: twincobr_fg_rom_bank = 0x1000; break;
234      case 0x000c: twincobr_dsp(1); break;    /* Enable the INT line to the DSP */
235      case 0x000d: twincobr_dsp(0); break;    /* Inhibit the INT line to the DSP */
233      case 0x000c: twincobr_dsp(machine, 1); break;    /* Enable the INT line to the DSP */
234      case 0x000d: twincobr_dsp(machine, 0); break;    /* Inhibit the INT line to the DSP */
236235      case 0x000e: twincobr_display(0); break; /* Turn display off */
237236      case 0x000f: twincobr_display(1); break; /* Turn display on */
238237   }
r2724r2725
242241{
243242   if (ACCESSING_BITS_0_7)
244243   {
245      toaplan0_control_w(offset, data & 0xff);
244      toaplan0_control_w(machine, offset, data & 0xff);
246245   }
247246}
248247
249248WRITE8_HANDLER( wardner_control_w )
250249{
251   toaplan0_control_w(offset, data);
250   toaplan0_control_w(machine, offset, data);
252251}
253252
254253
r2724r2725
266265}
267266
268267
269static void toaplan0_coin_dsp_w(int offset, int data)
268static void toaplan0_coin_dsp_w(running_machine *machine, int offset, int data)
270269{
271270   if (data > 1)
272271      LOG(("CPU0:%08x  Writing %08x to %08x.\n",activecpu_get_pc(),data,toaplan_port_type[toaplan_main_cpu] - offset));
r2724r2725
282281      /****** The following apply to Flying Shark/Wardner only ******/
283282      case 0x00:   /* This means assert the INT line to the DSP */
284283               LOG(("Turning DSP on and main CPU off\n"));
285               cpunum_set_input_line(Machine, 2, INPUT_LINE_HALT, CLEAR_LINE);
286               cpunum_set_input_line(Machine, 2, 0, ASSERT_LINE); /* TMS32010 INT */
287               cpunum_set_input_line(Machine, 0, INPUT_LINE_HALT, ASSERT_LINE);
284               cpunum_set_input_line(machine, 2, INPUT_LINE_HALT, CLEAR_LINE);
285               cpunum_set_input_line(machine, 2, 0, ASSERT_LINE); /* TMS32010 INT */
286               cpunum_set_input_line(machine, 0, INPUT_LINE_HALT, ASSERT_LINE);
288287               break;
289288      case 0x01:   /* This means inhibit the INT line to the DSP */
290289               LOG(("Turning DSP off\n"));
291               cpunum_set_input_line(Machine, 2, 0, CLEAR_LINE); /* TMS32010 INT */
292               cpunum_set_input_line(Machine, 2, INPUT_LINE_HALT, ASSERT_LINE);
290               cpunum_set_input_line(machine, 2, 0, CLEAR_LINE); /* TMS32010 INT */
291               cpunum_set_input_line(machine, 2, INPUT_LINE_HALT, ASSERT_LINE);
293292               break;
294293   }
295294}
r2724r2725
299298{
300299   if (ACCESSING_BITS_0_7)
301300   {
302      toaplan0_coin_dsp_w(offset, data & 0xff);
301      toaplan0_coin_dsp_w(machine, offset, data & 0xff);
303302   }
304303}
305304
306305WRITE8_HANDLER( twincobr_coin_w )
307306{
308   toaplan0_coin_dsp_w(offset, data);
307   toaplan0_coin_dsp_w(machine, offset, data);
309308}
310309
311310WRITE8_HANDLER( wardner_coin_dsp_w )
312311{
313   toaplan0_coin_dsp_w(offset, data);
312   toaplan0_coin_dsp_w(machine, offset, data);
314313}
315314
316315
src/mame/machine/midwayic.c
r2724r2725
7474   UINT8   shuffle_type;
7575   UINT8   shuffle_active;
7676   const UINT8 *   shuffle_map;
77   void    (*irq_callback)(int);
77   void    (*irq_callback)(running_machine *, int);
7878   UINT8   irq_state;
7979   UINT16   sound_irq_state;
8080   UINT8   auto_ack;
r2724r2725
570570static void ioasic_input_empty(int state);
571571static void ioasic_output_full(int state);
572572static void update_ioasic_irq(void);
573static void cage_irq_handler(int state);
573static void cage_irq_handler(running_machine *machine, int state);
574574
575575
576576static void ioasic_register_state(void)
r2724r2725
589589}
590590
591591
592void midway_ioasic_init(int shuffle, int upper, int yearoffs, void (*irq_callback)(int))
592void midway_ioasic_init(int shuffle, int upper, int yearoffs, void (*irq_callback)(running_machine *, int))
593593{
594594   static const UINT8 shuffle_maps[][16] =
595595   {
r2724r2725
685685   {
686686      ioasic.irq_state = new_state;
687687      if (ioasic.irq_callback)
688         (*ioasic.irq_callback)(ioasic.irq_state ? ASSERT_LINE : CLEAR_LINE);
688         (*ioasic.irq_callback)(Machine, ioasic.irq_state ? ASSERT_LINE : CLEAR_LINE);
689689   }
690690}
691691
692692
693static void cage_irq_handler(int reason)
693static void cage_irq_handler(running_machine *machine, int reason)
694694{
695695   logerror("CAGE irq handler: %d\n", reason);
696696   ioasic.sound_irq_state = 0;
src/mame/machine/midwayic.h
r2724r2725
2323
2424
2525/* I/O ASIC connected to 2nd generation PIC */
26void midway_ioasic_init(int shuffle, int upper, int yearoffs, void (*irq_callback)(int));
26void midway_ioasic_init(int shuffle, int upper, int yearoffs, void (*irq_callback)(running_machine *, int));
2727void midway_ioasic_set_auto_ack(int auto_ack);
2828void midway_ioasic_set_shuffle_state(int state);
2929void midway_ioasic_reset(void);
src/mame/machine/konamigx.c
r2724r2725
16801680      }
16811681      color &= K055555_COLORMASK;
16821682
1683      if (drawmode >= 4) palette_set_shadow_mode(Machine, order & 0x0f);
1683      if (drawmode >= 4) palette_set_shadow_mode(machine, order & 0x0f);
16841684
16851685      if (!(mixerflags & GXMIX_NOZBUF))
16861686      {
r2724r2725
19511951            else
19521952               if (dy < 0) i = 0x80;
19531953            else
1954               i = mame_rand(Machine) & 0xff; // vector direction indeterminate
1954               i = mame_rand(machine) & 0xff; // vector direction indeterminate
19551955
19561956            prot_data[0x10] = i;
19571957         break;
src/mame/machine/daikaiju.c
r2724r2725
9898
9999***************************************************************************/
100100#include "driver.h"
101#include "deprecat.h"
102101#include "cpu/z80/z80.h"
103102
104103#define ID_DAIKAIJU 0x5a
r2724r2725
341340{
342341   int res = input_port_read_indexed(machine, 3);
343342
344   res^=mame_rand(Machine)&3;
343   res^=mame_rand(machine)&3;
345344   res |=((lsasquad_sound_pending & 0x02)^2)<<3; //inverted flag
346345   lsasquad_sound_pending &= ~0x02;
347346   return res;
src/mame/machine/namcos1.c
r2724r2725
11#include "driver.h"
2#include "deprecat.h"
32#include "sound/ym2151.h"
43#include "sound/namco.h"
54
r2724r2725
531530   op = (offset & 0x70) >> 4;
532531
533532   if (op == key_reg)      return key_id;
534   if (op == key_rng)      return mame_rand(Machine);
533   if (op == key_rng)      return mame_rand(machine);
535534   if (op == key_swap4)   return (key[key_swap4_arg] << 4) | (key[key_swap4_arg] >> 4);
536535   if (op == key_bottom4)   return (offset << 4) | (key[key_swap4_arg] & 0x0f);
537536   if (op == key_top4)      return (offset << 4) | (key[key_swap4_arg] >> 4);
src/mame/machine/segaic16.c
r2724r2725
6161   UINT16   counter;
6262   UINT8   bit;
6363   void   (*sound_w)(UINT8);
64   void   (*timer_ack)(void);
64   void   (*timer_ack)(running_machine *);
6565};
6666
6767
r2724r2725
218218         /*   03 - maybe controls halt and reset lines together? */
219219         if ((oldval ^ chip->regs[offset]) & 3)
220220         {
221            cpunum_set_input_line(Machine, chip->cpunum, INPUT_LINE_RESET, (chip->regs[offset] & 3) == 3 ? ASSERT_LINE : CLEAR_LINE);
221            cpunum_set_input_line(machine, chip->cpunum, INPUT_LINE_RESET, (chip->regs[offset] & 3) == 3 ? ASSERT_LINE : CLEAR_LINE);
222222            if ((chip->regs[offset] & 3) == 3)
223223               fd1094_machine_init();
224224         }
r2724r2725
232232      case 0x04:
233233         /* controls IRQ lines to 68000, negative logic -- write $B to signal IRQ4 */
234234         if ((chip->regs[offset] & 7) != 7)
235            cpunum_set_input_line(Machine, chip->cpunum, (~chip->regs[offset] & 7), HOLD_LINE);
235            cpunum_set_input_line(machine, chip->cpunum, (~chip->regs[offset] & 7), HOLD_LINE);
236236         break;
237237
238238      case 0x05:
r2724r2725
585585 *
586586 *************************************/
587587
588void segaic16_compare_timer_init(int which, void (*sound_write_callback)(UINT8), void (*timer_ack_callback)(void))
588void segaic16_compare_timer_init(int which, void (*sound_write_callback)(UINT8), void (*timer_ack_callback)(running_machine *))
589589{
590590   compare_timer[which].sound_w = sound_write_callback;
591591   compare_timer[which].timer_ack = timer_ack_callback;
r2724r2725
644644static void timer_interrupt_ack(int which)
645645{
646646   if (compare_timer[which].timer_ack)
647      (*compare_timer[which].timer_ack)();
647      (*compare_timer[which].timer_ack)(Machine);
648648}
649649
650650
src/mame/machine/pckeybrd.c
r2724r2725
188188   int scan_code_set;
189189   int last_code;
190190
191   int ports[8];
191   const input_port_config *ports[8];
192192} at_keyboard;
193193
194194static at_keyboard keyboard;
r2724r2725
343343   for (i = 0; i < sizeof(keyboard.ports) / sizeof(keyboard.ports[0]); i++)
344344   {
345345      sprintf(buf, "pc_keyboard_%d", i);
346      keyboard.ports[i] = port_tag_to_index(buf);
346      keyboard.ports[i] = input_port_by_tag(Machine->portconfig, buf);
347347   }
348348
349349#ifdef MESS
r2724r2725
508508static UINT32 at_keyboard_readport(int port)
509509{
510510   UINT32 result = 0;
511   if (keyboard.ports[port] >= 0)
512      result = input_port_read_indexed(Machine, keyboard.ports[port]);
511   if (keyboard.ports[port] != NULL)
512      result = input_port_read_direct(keyboard.ports[port]);
513513   return result;
514514}
515515
src/mame/machine/segaic16.h
r2724r2725
4747WRITE16_HANDLER( segaic16_divide_2_w );
4848
4949/* compare/timer chip */
50void segaic16_compare_timer_init(int which, void (*sound_write_callback)(UINT8), void (*timer_ack_callback)(void));
50void segaic16_compare_timer_init(int which, void (*sound_write_callback)(UINT8), void (*timer_ack_callback)(running_machine *));
5151int segaic16_compare_timer_clock(int which);
5252READ16_HANDLER( segaic16_compare_timer_0_r );
5353READ16_HANDLER( segaic16_compare_timer_1_r );
src/mame/machine/stfight.c
r2724r2725
182182static int adpcm_data_offs;
183183static int adpcm_data_end;
184184
185void stfight_adpcm_int( int data )
185void stfight_adpcm_int( running_machine *machine, int data )
186186{
187187   static int toggle;
188188   UINT8 *SAMPLES = memory_region(REGION_SOUND1);
src/mame/machine/qix.c
r2724r2725
77***************************************************************************/
88
99#include "driver.h"
10#include "deprecat.h"
1110#include "machine/6821pia.h"
1211#include "cpu/m6800/m6800.h"
1312#include "cpu/m6805/m6805.h"
r2724r2725
3433static WRITE8_HANDLER( qix_coinctl_w );
3534static WRITE8_HANDLER( slither_coinctl_w );
3635
37static void qix_pia_sint(int state);
38static void qix_pia_dint(int state);
36static void qix_pia_sint(running_machine *machine, int state);
37static void qix_pia_dint(running_machine *machine, int state);
3938
4039static WRITE8_HANDLER( slither_76489_0_w );
4140static WRITE8_HANDLER( slither_76489_1_w );
r2724r2725
375374 *
376375 *************************************/
377376
378static void qix_pia_dint(int state)
377static void qix_pia_dint(running_machine *machine, int state)
379378{
380379   int combined_state = pia_get_irq_a(3) | pia_get_irq_b(3);
381380
382381   /* DINT is connected to the data CPU's IRQ line */
383   cpunum_set_input_line(Machine, 0, M6809_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
382   cpunum_set_input_line(machine, 0, M6809_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
384383}
385384
386385
387static void qix_pia_sint(int state)
386static void qix_pia_sint(running_machine *machine, int state)
388387{
389388   int combined_state = pia_get_irq_a(4) | pia_get_irq_b(4);
390389
391390   /* SINT is connected to the sound CPU's IRQ line */
392   cpunum_set_input_line(Machine, 2, M6802_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
391   cpunum_set_input_line(machine, 2, M6802_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
393392}
394393
395394
src/mame/machine/amiga.c
r2724r2725
175175
176176static void custom_reset(void);
177177static void autoconfig_reset(void);
178static void amiga_cia_0_irq(int state);
179static void amiga_cia_1_irq(int state);
178static void amiga_cia_0_irq(running_machine *machine, int state);
179static void amiga_cia_1_irq(running_machine *machine, int state);
180180static TIMER_CALLBACK( amiga_irq_proc );
181181static TIMER_CALLBACK( amiga_blitter_proc );
182182static TIMER_CALLBACK( scanline_callback );
r2724r2725
462462
463463CUSTOM_INPUT( amiga_joystick_convert )
464464{
465   UINT8 bits = input_port_read(machine, param);
465   UINT8 bits = input_port_read(field->port->machine, param);
466466   int up = (bits >> 0) & 1;
467467   int down = (bits >> 1) & 1;
468468   int left = (bits >> 2) & 1;
r2724r2725
11331133 *
11341134 *************************************/
11351135
1136static void amiga_cia_0_irq(int state)
1136static void amiga_cia_0_irq(running_machine *machine, int state)
11371137{
1138   amiga_custom_w(Machine, REG_INTREQ, (state ? 0x8000 : 0x0000) | INTENA_PORTS, 0xffff);
1138   amiga_custom_w(machine, REG_INTREQ, (state ? 0x8000 : 0x0000) | INTENA_PORTS, 0xffff);
11391139}
11401140
11411141
1142static void amiga_cia_1_irq(int state)
1142static void amiga_cia_1_irq(running_machine *machine, int state)
11431143{
1144   amiga_custom_w(Machine, REG_INTREQ, (state ? 0x8000 : 0x0000) | INTENA_EXTER, 0xffff);
1144   amiga_custom_w(machine, REG_INTREQ, (state ? 0x8000 : 0x0000) | INTENA_EXTER, 0xffff);
11451145}
11461146
11471147
src/mame/machine/atarigen.c
r2724r2725
668668    IRQ line.
669669---------------------------------------------------------------*/
670670
671void atarigen_ym2151_irq_gen(int irq)
671void atarigen_ym2151_irq_gen(running_machine *machine, int irq)
672672{
673673   ym2151_int = irq;
674   update_6502_irq(Machine);
674   update_6502_irq(machine);
675675}
676676
677677
src/mame/machine/atarigen.h
r2724r2725
151151READ8_HANDLER( atarigen_6502_irq_ack_r );
152152WRITE8_HANDLER( atarigen_6502_irq_ack_w );
153153
154void atarigen_ym2151_irq_gen(int irq);
154void atarigen_ym2151_irq_gen(running_machine *machine, int irq);
155155
156156WRITE16_HANDLER( atarigen_sound_w );
157157READ16_HANDLER( atarigen_sound_r );
src/mame/machine/namcos2.c
r2724r2725
355355   //  case 3: return 0x142;
356356      case 4: return 0x142;
357357   //  case 3: popmessage("blah %08x",activecpu_get_pc());
358      default: return mame_rand(Machine);
358      default: return mame_rand(machine);
359359      }
360360      break;
361361
r2724r2725
412412
413413
414414
415   return mame_rand(Machine)&0xffff;
415   return mame_rand(machine)&0xffff;
416416}
417417
418418WRITE16_HANDLER( namcos2_68k_key_w )
src/mame/machine/mcr.c
r2724r2725
7979 *
8080 *************************************/
8181
82static void subtract_from_counter(int counter, int count);
82static void subtract_from_counter(running_machine *machine, int counter, int count);
8383
8484static TIMER_CALLBACK( mcr68_493_callback );
8585static TIMER_CALLBACK( zwackery_493_callback );
r2724r2725
8787static WRITE8_HANDLER( zwackery_pia_2_w );
8888static WRITE8_HANDLER( zwackery_pia_3_w );
8989static WRITE8_HANDLER( zwackery_ca2_w );
90static void zwackery_pia_irq(int state);
90static void zwackery_pia_irq(running_machine *machine, int state);
9191
9292static void reload_count(int counter);
9393static TIMER_CALLBACK( counter_fired_callback );
r2724r2725
188188 *
189189 *************************************/
190190
191static void ctc_interrupt(int state)
191static void ctc_interrupt(running_machine *machine, int state)
192192{
193   cpunum_set_input_line(Machine, 0, 0, state);
193   cpunum_set_input_line(machine, 0, 0, state);
194194}
195195
196196
197static void ipu_ctc_interrupt(int state)
197static void ipu_ctc_interrupt(running_machine *machine, int state)
198198{
199   cpunum_set_input_line(Machine, 3, 0, state);
199   cpunum_set_input_line(machine, 3, 0, state);
200200}
201201
202202
r2724r2725
453453{
454454   /* update the 6840 VBLANK clock */
455455   if (!m6840_state[0].timer_active)
456      subtract_from_counter(0, 1);
456      subtract_from_counter(machine, 0, 1);
457457
458458   logerror("--- VBLANK ---\n");
459459
r2724r2725
471471 *
472472 *************************************/
473473
474static void update_mcr68_interrupts(void)
474static void update_mcr68_interrupts(running_machine *machine)
475475{
476476   int newstate = 0;
477477
r2724r2725
483483
484484   /* set the new state of the IRQ lines */
485485   if (newstate)
486      cpunum_set_input_line(Machine, 0, newstate, ASSERT_LINE);
486      cpunum_set_input_line(machine, 0, newstate, ASSERT_LINE);
487487   else
488      cpunum_set_input_line(Machine, 0, 7, CLEAR_LINE);
488      cpunum_set_input_line(machine, 0, 7, CLEAR_LINE);
489489}
490490
491491
492492static TIMER_CALLBACK( mcr68_493_off_callback )
493493{
494494   v493_irq_state = 0;
495   update_mcr68_interrupts();
495   update_mcr68_interrupts(machine);
496496}
497497
498498
499499static TIMER_CALLBACK( mcr68_493_callback )
500500{
501501   v493_irq_state = 1;
502   update_mcr68_interrupts();
502   update_mcr68_interrupts(machine);
503503   timer_set(video_screen_get_scan_period(machine->primary_screen), NULL, 0, mcr68_493_off_callback);
504504   logerror("--- (INT1) ---\n");
505505}
r2724r2725
605605}
606606
607607
608static void zwackery_pia_irq(int state)
608static void zwackery_pia_irq(running_machine *machine, int state)
609609{
610610   v493_irq_state = pia_get_irq_a(2) | pia_get_irq_b(2);
611   update_mcr68_interrupts();
611   update_mcr68_interrupts(machine);
612612}
613613
614614
r2724r2725
632632 *
633633 *************************************/
634634
635INLINE void update_interrupts(void)
635INLINE void update_interrupts(running_machine *machine)
636636{
637637   m6840_status &= ~0x80;
638638
r2724r2725
641641   if ((m6840_status & 0x04) && (m6840_state[2].control & 0x40)) m6840_status |= 0x80;
642642
643643   m6840_irq_state = m6840_status >> 7;
644   update_mcr68_interrupts();
644   update_mcr68_interrupts(machine);
645645}
646646
647647
648static void subtract_from_counter(int counter, int count)
648static void subtract_from_counter(running_machine *machine, int counter, int count)
649649{
650650   /* dual-byte mode */
651651   if (m6840_state[counter].control & 0x04)
r2724r2725
668668         {
669669            m6840_status |= 1 << counter;
670670            m6840_status_read_since_int &= ~(1 << counter);
671            update_interrupts();
671            update_interrupts(machine);
672672            msb = (m6840_state[counter].latch >> 8) + 1;
673673            LOG(("** Counter %d fired\n", counter));
674674         }
r2724r2725
695695         /* we've expired */
696696         m6840_status |= 1 << counter;
697697         m6840_status_read_since_int &= ~(1 << counter);
698         update_interrupts();
698         update_interrupts(machine);
699699         LOG(("** Counter %d fired\n", counter));
700700      }
701701
r2724r2725
714714   m6840_state[counter].timer_active = 0;
715715
716716   /* subtract it all from the counter; this will generate an interrupt */
717   subtract_from_counter(counter, count);
717   subtract_from_counter(machine, counter, count);
718718}
719719
720720
r2724r2725
827827         }
828828
829829         m6840_status = 0;
830         update_interrupts();
830         update_interrupts(machine);
831831      }
832832
833833      /* changing the clock source? (needed for Zwackery) */
r2724r2725
852852
853853      /* clear the interrupt */
854854      m6840_status &= ~(1 << counter);
855      update_interrupts();
855      update_interrupts(machine);
856856
857857      /* reload the count if in an appropriate mode */
858858      if (!(m6840_state[counter].control & 0x10))
r2724r2725
886886      /* clear the interrupt if the status has been read */
887887      if (m6840_status_read_since_int & (1 << counter))
888888         m6840_status &= ~(1 << counter);
889      update_interrupts();
889      update_interrupts(machine);
890890
891891      m6840_lsb_buffer = result & 0xff;
892892
src/mame/machine/konamiic.c
r2724r2725
88
99static emu_timer *K056800_sound_cpu_timer;
1010static int K056800_sound_cpu_irq1_enable;
11static void (*K056800_sound_irq_callback)(int);
11static void (*K056800_sound_irq_callback)(running_machine *, int);
1212
1313static UINT8 K056800_host_reg_r(int reg)
1414{
r2724r2725
2020   return value;
2121}
2222
23static void K056800_host_reg_w(int reg, UINT8 data)
23static void K056800_host_reg_w(running_machine *machine, int reg, UINT8 data)
2424{
2525   K056800_sound_reg[reg] = data;
2626
2727   if (reg == 7)
2828   {
29      K056800_sound_irq_callback(1);
29      K056800_sound_irq_callback(machine, 1);
3030   }
3131}
3232
r2724r2725
4949{
5050   if (K056800_sound_cpu_irq1_enable)
5151   {
52      K056800_sound_irq_callback(0);
52      K056800_sound_irq_callback(machine, 0);
5353   }
5454}
5555
56void K056800_init(void (* irq_callback)(int))
56void K056800_init(void (* irq_callback)(running_machine *, int))
5757{
5858   attotime timer_period;
5959   K056800_sound_irq_callback = irq_callback;
r2724r2725
9595{
9696   if (ACCESSING_BITS_24_31)
9797   {
98      K056800_host_reg_w((offset*4)+0, (data >> 24) & 0xff);
98      K056800_host_reg_w(machine, (offset*4)+0, (data >> 24) & 0xff);
9999   }
100100   if (ACCESSING_BITS_16_23)
101101   {
102      K056800_host_reg_w((offset*4)+1, (data >> 16) & 0xff);
102      K056800_host_reg_w(machine, (offset*4)+1, (data >> 16) & 0xff);
103103   }
104104   if (ACCESSING_BITS_8_15)
105105   {
106      K056800_host_reg_w((offset*4)+2, (data >> 8) & 0xff);
106      K056800_host_reg_w(machine, (offset*4)+2, (data >> 8) & 0xff);
107107   }
108108   if (ACCESSING_BITS_0_7)
109109   {
110      K056800_host_reg_w((offset*4)+3, (data >> 0) & 0xff);
110      K056800_host_reg_w(machine, (offset*4)+3, (data >> 0) & 0xff);
111111   }
112112}
113113
src/mame/machine/galaxold.c
r2724r2725
236236       that it's working, doesn't actually use return value, so we can just use
237237       rand() */
238238
239   return (input_port_read_indexed(machine, 1) & ~0x20) | (mame_rand(Machine) & 0x20);
239   return (input_port_read_indexed(machine, 1) & ~0x20) | (mame_rand(machine) & 0x20);
240240}
241241
242242WRITE8_HANDLER( kingball_speech_dip_w )
src/mame/machine/konamiic.h
r2724r2725
11#ifndef _KONAMIIC_H
22#define _KONAMIIC_H
33
4void K056800_init(void (* irq_callback)(int));
4void K056800_init(void (* irq_callback)(running_machine *, int));
55READ32_HANDLER(K056800_host_r);
66WRITE32_HANDLER(K056800_host_w);
77READ16_HANDLER(K056800_sound_r);
src/mame/machine/psx.c
r2724r2725
77***************************************************************************/
88
99#include "driver.h"
10#include "deprecat.h"
1110#include "cpu/mips/psx.h"
1211#include "includes/psx.h"
1312
r2724r2725
6766static UINT32 m_n_irqdata;
6867static UINT32 m_n_irqmask;
6968
70static void psx_irq_update( void )
69static void psx_irq_update( running_machine *machine )
7170{
7271   if( ( m_n_irqdata & m_n_irqmask ) != 0 )
7372   {
7473      verboselog( 2, "psx irq assert\n" );
75      cpunum_set_input_line(Machine, 0, MIPS_IRQ0, ASSERT_LINE );
74      cpunum_set_input_line(machine, 0, MIPS_IRQ0, ASSERT_LINE );
7675   }
7776   else
7877   {
7978      verboselog( 2, "psx irq clear\n" );
80      cpunum_set_input_line(Machine, 0, MIPS_IRQ0, CLEAR_LINE );
79      cpunum_set_input_line(machine, 0, MIPS_IRQ0, CLEAR_LINE );
8180   }
8281}
8382
r2724r2725
8887   case 0x00:
8988      verboselog( 2, "psx irq data ( %08x, %08x ) %08x -> %08x\n", data, mem_mask, m_n_irqdata, ( m_n_irqdata & ~mem_mask ) | ( m_n_irqdata & m_n_irqmask & data ) );
9089      m_n_irqdata = ( m_n_irqdata & ~mem_mask ) | ( m_n_irqdata & m_n_irqmask & data );
91      psx_irq_update();
90      psx_irq_update(machine);
9291      break;
9392   case 0x01:
9493      verboselog( 2, "psx irq mask ( %08x, %08x ) %08x -> %08x\n", data, mem_mask, m_n_irqmask, ( m_n_irqmask & ~mem_mask ) | data );
r2724r2725
9796      {
9897         verboselog( 0, "psx_irq_w( %08x, %08x, %08x ) unknown irq\n", offset, data, mem_mask );
9998      }
100      psx_irq_update();
99      psx_irq_update(machine);
101100      break;
102101   default:
103102      verboselog( 0, "psx_irq_w( %08x, %08x, %08x ) unknown register\n", offset, data, mem_mask );
r2724r2725
122121   return 0;
123122}
124123
125void psx_irq_set( UINT32 data )
124void psx_irq_set( running_machine *machine, UINT32 data )
126125{
127126   verboselog( 2, "psx_irq_set %08x\n", data );
128127   m_n_irqdata |= data;
129   psx_irq_update();
128   psx_irq_update(machine);
130129}
131130
132131/* DMA */
r2724r2725
167166   }
168167}
169168
170static void dma_interrupt_update( void )
169static void dma_interrupt_update( running_machine *machine )
171170{
172171   int n_int;
173172   int n_mask;
r2724r2725
179178   {
180179      verboselog( 2, "dma_interrupt_update( %02x, %02x ) interrupt triggered\n", n_int, n_mask );
181180      m_n_dicr |= 0x80000000;
182      psx_irq_set( 0x0008 );
181      psx_irq_set( machine, 0x0008 );
183182   }
184183   else if( ( m_n_dicr & 0x80000000 ) != 0 )
185184   {
r2724r2725
194193   m_n_dicr &= 0x00ffffff | ( m_n_dicr << 8 );
195194}
196195
197static void dma_finished(int n_channel)
196static void dma_finished(running_machine *machine, int n_channel)
198197{
199198   if( m_p_n_dmachannelcontrol[ n_channel ] == 0x01000401 && n_channel == 2 )
200199   {
r2724r2725
250249   m_p_n_dmachannelcontrol[ n_channel ] &= ~( ( 1L << 0x18 ) | ( 1L << 0x1c ) );
251250
252251   m_n_dicr |= 1 << ( 24 + n_channel );
253   dma_interrupt_update();
252   dma_interrupt_update(machine);
254253   dma_stop_timer( n_channel );
255254}
256255
257256static TIMER_CALLBACK( dma_finished_callback )
258257{
259   dma_finished(param);
258   dma_finished(machine, param);
260259}
261260
262261void psx_dma_install_read_handler( int n_channel, psx_dma_read_handler p_fn_dma_read )
r2724r2725
315314            {
316315               verboselog( 1, "dma %d read block %08x %08x\n", n_channel, n_address, n_size );
317316               m_p_fn_dma_read[ n_channel ]( n_address, n_size );
318               dma_finished( n_channel );
317               dma_finished( machine, n_channel );
319318            }
320319            else if( m_p_n_dmachannelcontrol[ n_channel ] == 0x01000200 &&
321320               m_p_fn_dma_read[ n_channel ] != NULL )
r2724r2725
328327               }
329328               else
330329               {
331                  dma_finished( n_channel );
330                  dma_finished( machine, n_channel );
332331               }
333332            }
334333            else if( m_p_n_dmachannelcontrol[ n_channel ] == 0x01000201 &&
r2724r2725
336335            {
337336               verboselog( 1, "dma %d write block %08x %08x\n", n_channel, n_address, n_size );
338337               m_p_fn_dma_write[ n_channel ]( n_address, n_size );
339               dma_finished( n_channel );
338               dma_finished( machine, n_channel );
340339            }
341340            else if( m_p_n_dmachannelcontrol[ n_channel ] == 0x11050100 &&
342341               m_p_fn_dma_write[ n_channel ] != NULL )
r2724r2725
344343               /* todo: check this is a write not a read... */
345344               verboselog( 1, "dma %d write block %08x %08x\n", n_channel, n_address, n_size );
346345               m_p_fn_dma_write[ n_channel ]( n_address, n_size );
347               dma_finished( n_channel );
346               dma_finished( machine, n_channel );
348347            }
349348            else if( m_p_n_dmachannelcontrol[ n_channel ] == 0x11150100 &&
350349               m_p_fn_dma_write[ n_channel ] != NULL )
r2724r2725
352351               /* todo: check this is a write not a read... */
353352               verboselog( 1, "dma %d write block %08x %08x\n", n_channel, n_address, n_size );
354353               m_p_fn_dma_write[ n_channel ]( n_address, n_size );
355               dma_finished( n_channel );
354               dma_finished( machine, n_channel );
356355            }
357356            else if( m_p_n_dmachannelcontrol[ n_channel ] == 0x01000401 &&
358357               n_channel == 2 &&
r2724r2725
361360               verboselog( 1, "dma %d write linked list %08x\n",
362361                  n_channel, m_p_n_dmabase[ n_channel ] );
363362
364               dma_finished( n_channel );
363               dma_finished( machine, n_channel );
365364            }
366365            else if( m_p_n_dmachannelcontrol[ n_channel ] == 0x11000002 &&
367366               n_channel == 6 )
r2724r2725
418417            }
419418*/
420419         verboselog( 1, "psx_dma_w( %04x, %08x, %08x ) dicr -> %08x\n", offset, data, mem_mask, m_n_dicr );
421         dma_interrupt_update();
420         dma_interrupt_update(machine);
422421         break;
423422      default:
424423         verboselog( 0, "psx_dma_w( %04x, %08x, %08x ) Unknown dma control register\n", offset, data, mem_mask );
r2724r2725
580579   if( ( m_p_n_root_mode[ n_counter ] & RC_IRQOVERFLOW ) != 0 ||
581580      ( m_p_n_root_mode[ n_counter ] & RC_IRQTARGET ) != 0 )
582581   {
583      psx_irq_set( 0x10 << n_counter );
582      psx_irq_set( machine, 0x10 << n_counter );
584583   }
585584}
586585
r2724r2725
688687#define SIO_CONTROL_DSR_IENA ( 1 << 12 )
689688#define SIO_CONTROL_DTR ( 1 << 13 )
690689
691static void sio_interrupt( int n_port )
690static void sio_interrupt( running_machine *machine, int n_port )
692691{
693692   verboselog( 1, "sio_interrupt( %d )\n", n_port );
694693   m_p_n_sio_status[ n_port ] |= SIO_STATUS_IRQ;
695694   if( n_port == 0 )
696695   {
697      psx_irq_set( 0x80 );
696      psx_irq_set( machine, 0x80 );
698697   }
699698   else
700699   {
701      psx_irq_set( 0x100 );
700      psx_irq_set( machine, 0x100 );
702701   }
703702}
704703
r2724r2725
784783      if( m_p_n_sio_tx_bits[ n_port ] == 0 &&
785784         ( m_p_n_sio_control[ n_port ] & SIO_CONTROL_TX_IENA ) != 0 )
786785      {
787         sio_interrupt( n_port );
786         sio_interrupt( machine, n_port );
788787      }
789788   }
790789
r2724r2725
806805         }
807806         if( ( m_p_n_sio_control[ n_port ] & SIO_CONTROL_RX_IENA ) != 0 )
808807         {
809            sio_interrupt( n_port );
808            sio_interrupt( machine, n_port );
810809         }
811810      }
812811   }
r2724r2725
814813   sio_timer_adjust( n_port );
815814}
816815
817void psx_sio_input( int n_port, int n_mask, int n_data )
816void psx_sio_input( running_machine *machine, int n_port, int n_mask, int n_data )
818817{
819818   verboselog( 1, "psx_sio_input( %d, %02x, %02x )\n", n_port, n_mask, n_data );
820819   m_p_n_sio_rx[ n_port ] = ( m_p_n_sio_rx[ n_port ] & ~n_mask ) | ( n_data & n_mask );
r2724r2725
825824      if( ( m_p_n_sio_rx_prev[ n_port ] & PSX_SIO_IN_DSR ) == 0 &&
826825         ( m_p_n_sio_control[ n_port ] & SIO_CONTROL_DSR_IENA ) != 0 )
827826      {
828         sio_interrupt( n_port );
827         sio_interrupt( machine, n_port );
829828      }
830829   }
831830   else
r2724r2725
15391538{
15401539   int n;
15411540
1542   psx_irq_update();
1541   psx_irq_update(machine);
15431542
15441543   for( n = 0; n < 7; n++ )
15451544   {
src/mame/machine/beezer.c
r2724r2725
11#include "driver.h"
2#include "deprecat.h"
32#include "cpu/m6809/m6809.h"
43#include "machine/6522via.h"
54
r2724r2725
1312static WRITE8_HANDLER( b_via_0_pb_w );
1413static READ8_HANDLER( b_via_0_ca2_r );
1514static WRITE8_HANDLER( b_via_0_ca2_w );
16static void b_via_0_irq (int level);
15static void b_via_0_irq (running_machine *machine, int level);
1716
1817static READ8_HANDLER( b_via_1_pa_r );
1918static READ8_HANDLER( b_via_1_pb_r );
2019static WRITE8_HANDLER( b_via_1_pa_w );
2120static WRITE8_HANDLER( b_via_1_pb_w );
22static void b_via_1_irq (int level);
21static void b_via_1_irq (running_machine *machine, int level);
2322
2423static const struct via6522_interface b_via_0_interface =
2524{
r2724r2725
4847{
4948}
5049
51static void b_via_0_irq (int level)
50static void b_via_0_irq (running_machine *machine, int level)
5251{
53   cpunum_set_input_line(Machine, 0, M6809_IRQ_LINE, level);
52   cpunum_set_input_line(machine, 0, M6809_IRQ_LINE, level);
5453}
5554
5655static READ8_HANDLER( b_via_0_pb_r )
r2724r2725
9089   pbus = data;
9190}
9291
93static void b_via_1_irq (int level)
92static void b_via_1_irq (running_machine *machine, int level)
9493{
95   cpunum_set_input_line(Machine, 1, M6809_IRQ_LINE, level);
94   cpunum_set_input_line(machine, 1, M6809_IRQ_LINE, level);
9695}
9796
9897static READ8_HANDLER( b_via_1_pa_r )
src/mame/machine/kaneko16.c
r2724r2725
1313***************************************************************************/
1414
1515#include "driver.h"
16#include "deprecat.h"
1716#include "includes/kaneko16.h"
1817
1918#include "kanekotb.h"   // TOYBOX MCU trojaning results
r2724r2725
8786         return (((UINT32)hit.mult_a * (UINT32)hit.mult_b) & 0xffff);
8887
8988      case 0x14/2:
90         return (mame_rand(Machine) & 0xffff);
89         return (mame_rand(machine) & 0xffff);
9190
9291      default:
9392         logerror("CPU #0 PC %06x: warning - read unmapped calc address %06x\n",activecpu_get_pc(),offset<<1);
r2724r2725
218217         return data;
219218
220219      case 0x14/2:
221         return (mame_rand(Machine) & 0xffff);
220         return (mame_rand(machine) & 0xffff);
222221
223222      case 0x20/2: return hit.x1p;
224223      case 0x22/2: return hit.x1s;
r2724r2725
597596      case 0x02:   // Read from NVRAM
598597      {
599598         mame_file *f;
600         if ((f = nvram_fopen(Machine, OPEN_FLAG_READ)) != 0)
599         if ((f = nvram_fopen(machine, OPEN_FLAG_READ)) != 0)
601600         {
602601            mame_fread(f,&kaneko16_mcu_ram[mcu_offset], 128);
603602            mame_fclose(f);
r2724r2725
609608      case 0x42:   // Write to NVRAM
610609      {
611610         mame_file *f;
612         if ((f = nvram_fopen(Machine, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS)) != 0)
611         if ((f = nvram_fopen(machine, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS)) != 0)
613612         {
614613            mame_fwrite(f,&kaneko16_mcu_ram[mcu_offset], 128);
615614            mame_fclose(f);
r2724r2725
712711      case 0x02:   // Read from NVRAM
713712      {
714713         mame_file *f;
715         if ((f = nvram_fopen(Machine, OPEN_FLAG_READ)) != 0)
714         if ((f = nvram_fopen(machine, OPEN_FLAG_READ)) != 0)
716715         {
717716            mame_fread(f,&kaneko16_mcu_ram[mcu_offset], 128);
718717            mame_fclose(f);
r2724r2725
724723      case 0x42:   // Write to NVRAM
725724      {
726725         mame_file *f;
727         if ((f = nvram_fopen(Machine, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS)) != 0)
726         if ((f = nvram_fopen(machine, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS)) != 0)
728727         {
729728            mame_fwrite(f,&kaneko16_mcu_ram[mcu_offset], 128);
730729            mame_fclose(f);
r2724r2725
736735      case 0x43:   // Initialize NVRAM - MCU writes Default Data Set directly to NVRAM
737736      {
738737         mame_file *f;
739         if ((f = nvram_fopen(Machine, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS)) != 0)
738         if ((f = nvram_fopen(machine, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS)) != 0)
740739         {
741740            mame_fwrite(f, bonkadv_mcu_43, sizeof(bonkadv_mcu_43));
742741            mame_fclose(f);
r2724r2725
834833      case 0x02:   // Read from NVRAM
835834      {
836835         mame_file *f;
837         if ((f = nvram_fopen(Machine, OPEN_FLAG_READ)) != 0)
836         if ((f = nvram_fopen(machine, OPEN_FLAG_READ)) != 0)
838837         {
839838            mame_fread(f,&kaneko16_mcu_ram[mcu_offset], 128);
840839            mame_fclose(f);
r2724r2725
845844      case 0x42:   // Write to NVRAM
846845      {
847846         mame_file *f;
848         if ((f = nvram_fopen(Machine, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS)) != 0)
847         if ((f = nvram_fopen(machine, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS)) != 0)
849848         {
850849            mame_fwrite(f,&kaneko16_mcu_ram[mcu_offset], 128);
851850            mame_fclose(f);
r2724r2725
861860
862861      case 0x04:   // TEST (2 versions)
863862      {
864         if (strcmp(Machine->gamedrv->name, "gtmr") == 0 ||
865            strcmp(Machine->gamedrv->name, "gtmra") == 0)
863         if (strcmp(machine->gamedrv->name, "gtmr") == 0 ||
864            strcmp(machine->gamedrv->name, "gtmra") == 0)
866865         {
867866            /* MCU writes the string "MM0525-TOYBOX199" to shared ram */
868867            kaneko16_mcu_ram[mcu_offset+0] = 0x4d4d;
src/mame/machine/williams.c
r2724r2725
55***************************************************************************/
66
77#include "driver.h"
8#include "deprecat.h"
98#include "audio/williams.h"
109#include "cpu/m6800/m6800.h"
1110#include "cpu/m6809/m6809.h"
r2724r2725
3231static UINT16 joust2_current_sound_data;
3332
3433/* older-Williams routines */
35static void williams_main_irq(int state);
36static void williams_main_firq(int state);
37static void williams_snd_irq(int state);
34static void williams_main_irq(running_machine *machine, int state);
35static void williams_main_firq(running_machine *machine, int state);
36static void williams_snd_irq(running_machine *machine, int state);
3837static WRITE8_HANDLER( williams_snd_cmd_w );
3938static WRITE8_HANDLER( playball_snd_cmd_w );
4039
r2724r2725
4847
4948/* newer-Williams routines */
5049static WRITE8_HANDLER( williams2_snd_cmd_w );
51static void mysticm_main_irq(int state);
52static void tshoot_main_irq(int state);
50static void mysticm_main_irq(running_machine *machine, int state);
51static void tshoot_main_irq(running_machine *machine, int state);
5352
5453/* Lotto Fun-specific code */
5554static READ8_HANDLER( lottofun_input_port_0_r );
r2724r2725
297296}
298297
299298
300static void williams_main_irq(int state)
299static void williams_main_irq(running_machine *machine, int state)
301300{
302301   int combined_state = pia_get_irq_a(1) | pia_get_irq_b(1);
303302
304303   /* IRQ to the main CPU */
305   cpunum_set_input_line(Machine, 0, M6809_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
304   cpunum_set_input_line(machine, 0, M6809_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
306305}
307306
308307
309static void williams_main_firq(int state)
308static void williams_main_firq(running_machine *machine, int state)
310309{
311310   /* FIRQ to the main CPU */
312   cpunum_set_input_line(Machine, 0, M6809_FIRQ_LINE, state ? ASSERT_LINE : CLEAR_LINE);
311   cpunum_set_input_line(machine, 0, M6809_FIRQ_LINE, state ? ASSERT_LINE : CLEAR_LINE);
313312}
314313
315314
316static void williams_snd_irq(int state)
315static void williams_snd_irq(running_machine *machine, int state)
317316{
318317   int combined_state = pia_get_irq_a(2) | pia_get_irq_b(2);
319318
320319   /* IRQ to the sound CPU */
321   cpunum_set_input_line(Machine, 1, M6800_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
320   cpunum_set_input_line(machine, 1, M6800_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
322321}
323322
324323
r2724r2725
329328 *
330329 *************************************/
331330
332static void mysticm_main_irq(int state)
331static void mysticm_main_irq(running_machine *machine, int state)
333332{
334333   int combined_state = pia_get_irq_b(0) | pia_get_irq_a(1) | pia_get_irq_b(1);
335334
336335   /* IRQ to the main CPU */
337   cpunum_set_input_line(Machine, 0, M6809_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
336   cpunum_set_input_line(machine, 0, M6809_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
338337}
339338
340339
341static void tshoot_main_irq(int state)
340static void tshoot_main_irq(running_machine *machine, int state)
342341{
343342   int combined_state = pia_get_irq_a(0) | pia_get_irq_b(0) | pia_get_irq_a(1) | pia_get_irq_b(1);
344343
345344   /* IRQ to the main CPU */
346   cpunum_set_input_line(Machine, 0, M6809_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
345   cpunum_set_input_line(machine, 0, M6809_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
347346}
348347
349348
src/mame/machine/starwars.c
r2724r2725
88***************************************************************************/
99
1010#include "driver.h"
11#include "deprecat.h"
1211#include "starwars.h"
1312#include "video/avgdvg.h"
1413
r2724r2725
414413     */
415414
416415   /* Use MAME's PRNG for now */
417   return mame_rand(Machine);
416   return mame_rand(machine);
418417}
419418
420419
src/mame/machine/seicop.c
r2724r2725
14941494            {
14951495               //UINT32 dst = cop_register[0];
14961496               //UINT32 dst = cop_register[1];
1497               //program_write_word(dst,  mame_rand(Machine)/*program_read_word(src)*/);
1498               //program_write_word(dst+2,mame_rand(Machine)/*program_read_word(src+2)*/);
1499               //program_write_word(dst+4,mame_rand(Machine)/*program_read_word(src+4)*/);
1500               //program_write_word(dst+6,mame_rand(Machine)/*program_read_word(src+6)*/);
1497               //program_write_word(dst,  mame_rand(machine)/*program_read_word(src)*/);
1498               //program_write_word(dst+2,mame_rand(machine)/*program_read_word(src+2)*/);
1499               //program_write_word(dst+4,mame_rand(machine)/*program_read_word(src+4)*/);
1500               //program_write_word(dst+6,mame_rand(machine)/*program_read_word(src+6)*/);
15011501               //logerror("%04x\n",cop_register[0]);
15021502               break;
15031503            }
src/mame/machine/ajax.c
r2724r2725
88***************************************************************************/
99
1010#include "driver.h"
11#include "deprecat.h"
1211#include "cpu/m6809/m6809.h"
1312#include "cpu/z80/z80.h"
1413#include "cpu/konami/konami.h"
r2724r2725
113112
114113   switch ((offset & 0x01c0) >> 6){
115114      case 0x00:   /* ??? */
116         data = mame_rand(Machine);
115         data = mame_rand(machine);
117116         break;
118117      case 0x04:   /* 2P inputs */
119118         data = input_port_read_indexed(machine, 5);
src/mame/mamedriv.c
r2724r2725
35053505   DRIVER( shinoblb )   /* (c) 1987 (but bootleg) */
35063506   DRIVER( shinobld )   /* (c) 1987 (but bootleg) */
35073507   DRIVER( tetrisbl )   /* (c) 1988 (but bootleg) */
3508   DRIVER( beautyb )   /* (c) 1991 AMT */
35083509   DRIVER( tturfbl )   /* (c) 1989 (Datsu bootleg) */
35093510   DRIVER( wb3bbl )   /* BOOTLEG */
35103511
r2724r2725
66706671   DRIVER( sarukani )   /* (c) 1997 Kaneko / Mediaworks (Japan) */
66716672   DRIVER( cyvern )   /* (c) 1998 Kaneko (Japan) */
66726673   DRIVER( galpans2 )   /* (c) 1999 Kaneko (Japan) */
6674   DRIVER( galpansu )   /* (c) 1999 Kaneko (Korea) */
66736675   DRIVER( panicstr )   /* (c) 1999 Kaneko (Japan) */
66746676   DRIVER( senknow )   /* (c) 1999 Kaneko / Kouyousha (Japan) */
66756677   DRIVER( gutsn )      /* (c) 2000 Kaneko / Kouyousha (Japan) */
r2724r2725
69906992   DRIVER( dharmak )   /* (c) 1994 */
69916993   DRIVER( lastfort )   /* (c) 1994 */
69926994   DRIVER( lastfero )   /* (c) 1994 */
6995   DRIVER( lastfork )   /* (c) 1994 */
69936996   DRIVER( lastforg )   /* (c) 1994 */
69946997   DRIVER( toride2g )   /* (c) 1994 */
69956998   DRIVER( torid2gg )   /* (c) 1994 */
r2724r2725
76807683   DRIVER( 9ballsh2 )   /* (c) 1993 E-Scape EnterMedia + "marketed by Bundra Games" */
76817684   DRIVER( 9ballsh3 )   /* (c) 1993 E-Scape EnterMedia + "marketed by Bundra Games" */
76827685   DRIVER( gumbo )      /* (c) 1994 Min Corp. */
7686   DRIVER( mspuzzlg )   /* (c) 1994 Min Corp. */
76837687   DRIVER( mspuzzle )   /* (c) 1994 Min Corp. */
76847688   DRIVER( mspuzzln )   /* (c) 1994 Min Corp. */
76857689   DRIVER( msbingo )   /* (C) 1994 Min Corp. */
src/mame/includes/atari.h
r2724r2725
5050
5151 READ8_HANDLER ( atari_serin_r );
5252WRITE8_HANDLER ( atari_serout_w );
53void atari_interrupt_cb(int mask);
53void atari_interrupt_cb(running_machine *machine, int mask);
5454
5555void a800_handle_keyboard(running_machine *machine);
5656void a5200_handle_keypads(running_machine *machine);
src/mame/includes/dynax.h
r2724r2725
88
99extern UINT8 dynax_blitter_irq,   dynax_blitter2_irq;
1010
11void sprtmtch_update_irq(void);
12void jantouki_update_irq(void);
13void mjelctrn_update_irq(void);
14void neruton_update_irq(void);
11void sprtmtch_update_irq(running_machine *machine);
12void jantouki_update_irq(running_machine *machine);
13void mjelctrn_update_irq(running_machine *machine);
14void neruton_update_irq(running_machine *machine);
1515
1616//----------- defined in video/dynax.c -----------
1717
src/mame/includes/namcona1.h
r2724r2725
2222
2323#define NA1_NVRAM_SIZE (0x800)
2424
25extern UINT16 *namcona1_rozvideoram;
2625extern UINT16 *namcona1_workram;
2726extern UINT16 *namcona1_vreg;
2827extern UINT16 *namcona1_scroll;
2928
30extern WRITE16_HANDLER( namcona1_rozvideoram_w );
31extern READ16_HANDLER( namcona1_rozvideoram_r );
32
3329extern WRITE16_HANDLER( namcona1_videoram_w );
3430extern READ16_HANDLER( namcona1_videoram_r );
3531
src/mame/includes/psx.h
r2724r2725
3030READ32_HANDLER( psx_com_delay_r );
3131WRITE32_HANDLER( psx_irq_w );
3232READ32_HANDLER( psx_irq_r );
33extern void psx_irq_set( UINT32 );
33extern void psx_irq_set( running_machine *, UINT32 );
3434extern void psx_dma_install_read_handler( int, psx_dma_read_handler );
3535extern void psx_dma_install_write_handler( int, psx_dma_read_handler );
3636WRITE32_HANDLER( psx_dma_w );
r2724r2725
4141READ32_HANDLER( psx_sio_r );
4242typedef void ( *psx_sio_handler )( int );
4343extern void psx_sio_install_handler( int, psx_sio_handler );
44extern void psx_sio_input( int, int, int );
44extern void psx_sio_input( running_machine *, int, int, int );
4545
4646#define PSX_SIO_OUT_DATA ( 1 )   /* COMMAND */
4747#define PSX_SIO_OUT_DTR ( 2 )   /* ATT */
src/mame/includes/genesis.h
r2724r2725
3434extern READ16_HANDLER ( genesis_io_r );
3535extern READ16_HANDLER ( genesis_68k_to_z80_r );
3636extern INTERRUPT_GEN( genesis_vblank_interrupt );
37extern void genesis_irq2_interrupt(int state);
37extern void genesis_irq2_interrupt(running_machine *machine, int state);
3838
3939/*----------- defined in video/genesis.c -----------*/
4040
src/mame/mame.mak
r2724r2725
16401640# layout dependencies
16411641#-------------------------------------------------
16421642
1643$(DRIVERS)/8080bw.o:   $(LAYOUT)/invrvnge.lh
1643$(DRIVERS)/8080bw.o:   $(LAYOUT)/invrvnge.lh \
1644                  $(LAYOUT)/shuttlei.lh
16441645
16451646$(DRIVERS)/acefruit.o:   $(LAYOUT)/sidewndr.lh
16461647
src/mame/video/aerofgt.c
r2724r2725
573573
574574      if (!code) continue;
575575
576      xpos = (aerofgt_spriteram3[i + 2] & 0x01ff) - 16;
576      xpos = (aerofgt_spriteram3[i + 2] & 0x01ff) - 13;
577577      ypos = 256 - (aerofgt_spriteram3[i + 1] & 0x00ff) - 26;
578578      flipy = 0;
579579      flipx = aerofgt_spriteram3[i + 3] & 0x8000;
src/mame/video/galpani2.c
r2724r2725
88***************************************************************************/
99
1010#include "driver.h"
11#include "deprecat.h"
1211#include "kaneko16.h"
1312
1413/*
r2724r2725
3736{ \
3837   switch (offset * 2) \
3938   { \
40      case 0x16:   return mame_rand(Machine) & 1; \
39      case 0x16:   return mame_rand(machine) & 1; \
4140      default: \
4241         logerror("CPU #0 PC %06X : Warning, bg8 #%d screen reg %04X read\n",activecpu_get_pc(),_n_,offset*2); \
4342   } \
src/mame/video/dynax.c
r2724r2725
7777
7878static int layer_layout;
7979
80static void (*update_irq_func)(void);   // some games trigger IRQ at blitter end, some don't
80static void (*update_irq_func)(running_machine *machine);   // some games trigger IRQ at blitter end, some don't
8181
8282// up to 8 layers, 2 images per layer (interleaved on screen)
8383static UINT8 *dynax_pixmap[8][2];
r2724r2725
503503
504504
505505
506static void dynax_blitter_start(int flags)
506static void dynax_blitter_start(running_machine *machine, int flags)
507507{
508508   int blit_newsrc;
509509
r2724r2725
528528   if (update_irq_func)
529529   {
530530      dynax_blitter_irq = 1;
531      update_irq_func();
531      update_irq_func(machine);
532532   }
533533}
534534
535static void jantouki_blitter_start(int flags)
535static void jantouki_blitter_start(running_machine *machine, int flags)
536536{
537537   int blit_newsrc;
538538
r2724r2725
557557   if (update_irq_func)
558558   {
559559      dynax_blitter_irq = 1;
560      update_irq_func();
560      update_irq_func(machine);
561561   }
562562}
563563
564static void jantouki_blitter2_start(int flags)
564static void jantouki_blitter2_start(running_machine *machine, int flags)
565565{
566566   int blit2_newsrc;
567567
r2724r2725
586586   if (update_irq_func)
587587   {
588588      dynax_blitter2_irq = 1;
589      update_irq_func();
589      update_irq_func(machine);
590590   }
591591}
592592
r2724r2725
650650{
651651   switch (offset)
652652   {
653      case 0: dynax_blitter_start(data); break;
653      case 0: dynax_blitter_start(machine,data); break;
654654      case 1:   blit_x      =   data; break;
655655      case 2: blit_y      =   data; break;
656656      case 3:   blit_src   =   (blit_src & 0xffff00) | (data << 0); break;
r2724r2725
665665{
666666   switch (offset)
667667   {
668      case 0: dynax_blitter_start(data); break;
668      case 0: dynax_blitter_start(machine,data); break;
669669      case 1:   blit_x      =   data; break;
670670      case 2: blit_y      =   data; break;
671671      case 3:   blit_src   =   (blit_src & 0xffff00) | (data << 0); break;
r2724r2725
680680{
681681   switch (offset)
682682   {
683      case 0: jantouki_blitter_start(data); break;
683      case 0: jantouki_blitter_start(machine,data); break;
684684      case 1:   blit_x      =   data; break;
685685      case 2: blit_y      =   data; break;
686686      case 3:   blit_src   =   (blit_src & 0xffff00) | (data << 0); break;
r2724r2725
694694{
695695   switch (offset)
696696   {
697      case 0: jantouki_blitter2_start(data); break;
697      case 0: jantouki_blitter2_start(machine,data); break;
698698      case 1:   blit2_x      =   data; break;
699699      case 2: blit2_y      =   data; break;
700700      case 3:   blit2_src   =   (blit2_src & 0xffff00) | (data << 0); break;
src/mame/video/undrfire.c
r2724r2725
435435   pointless - it's always hidden by other layers. Does it
436436   serve some blending pupose ? */
437437
438   TC0100SCN_tilemap_draw(screen->machine,bitmap,cliprect,0,pivlayer[0],0,0);
438   TC0100SCN_tilemap_draw(screen->machine,bitmap,cliprect,0,pivlayer[0],TILEMAP_DRAW_OPAQUE,0);
439439   TC0100SCN_tilemap_draw(screen->machine,bitmap,cliprect,0,pivlayer[1],0,0);
440440
441441#ifdef MAME_DEBUG
src/mame/video/midzeus.c
r2724r2725
55**************************************************************************/
66
77#include "driver.h"
8#include "deprecat.h"
98#include "eminline.h"
109#include "includes/midzeus.h"
1110#include "video/poly.h"
r2724r2725
8584static void exit_handler(running_machine *machine);
8685
8786static void zeus_pointer_w(UINT32 which, UINT32 data, int logit);
88static void zeus_register16_w(offs_t offset, UINT16 data, int logit);
89static void zeus_register32_w(offs_t offset, UINT32 data, int logit);
90static void zeus_register_update(offs_t offset);
91static int zeus_fifo_process(const UINT32 *data, int numwords);
92static void zeus_draw_model(UINT32 texdata, int logit);
87static void zeus_register16_w(running_machine *machine, offs_t offset, UINT16 data, int logit);
88static void zeus_register32_w(running_machine *machine, offs_t offset, UINT32 data, int logit);
89static void zeus_register_update(running_machine *machine, offs_t offset);
90static int zeus_fifo_process(running_machine *machine, const UINT32 *data, int numwords);
91static void zeus_draw_model(running_machine *machine, UINT32 texdata, int logit);
9392static void zeus_draw_quad(const UINT32 *databuffer, UINT32 texdata, int logit);
9493
9594static void render_poly_4bit(void *dest, INT32 scanline, const poly_extent *extent, const void *extradata, int threadid);
r2724r2725
444443
445444   /* 32-bit mode */
446445   if (zeusbase[0x80] & 0x00020000)
447      zeus_register32_w(offset, data, logit);
446      zeus_register32_w(machine, offset, data, logit);
448447
449448   /* 16-bit mode */
450449   else
451      zeus_register16_w(offset, data, logit);
450      zeus_register16_w(machine, offset, data, logit);
452451}
453452
454453
r2724r2725
522521 *
523522 *************************************/
524523
525static void zeus_register16_w(offs_t offset, UINT16 data, int logit)
524static void zeus_register16_w(running_machine *machine, offs_t offset, UINT16 data, int logit)
526525{
527526   /* writes to register $CC need to force a partial update */
528527   if ((offset & ~1) == 0xcc)
529      video_screen_update_partial(Machine->primary_screen, video_screen_get_vpos(Machine->primary_screen));
528      video_screen_update_partial(machine->primary_screen, video_screen_get_vpos(machine->primary_screen));
530529
531530   /* write to high part on odd addresses */
532531   if (offset & 1)
r2724r2725
542541
543542   /* handle the update */
544543   if ((offset & 1) == 0)
545      zeus_register_update(offset);
544      zeus_register_update(machine, offset);
546545}
547546
548547
549static void zeus_register32_w(offs_t offset, UINT32 data, int logit)
548static void zeus_register32_w(running_machine *machine, offs_t offset, UINT32 data, int logit)
550549{
551550   /* writes to register $CC need to force a partial update */
552551   if ((offset & ~1) == 0xcc)
553      video_screen_update_partial(Machine->primary_screen, video_screen_get_vpos(Machine->primary_screen));
552      video_screen_update_partial(machine->primary_screen, video_screen_get_vpos(machine->primary_screen));
554553
555554   /* always write to low word? */
556555   zeusbase[offset & ~1] = data;
r2724r2725
568567
569568   /* handle the update */
570569   if ((offset & 1) == 0)
571      zeus_register_update(offset);
570      zeus_register_update(machine, offset);
572571}
573572
574573
r2724r2725
579578 *
580579 *************************************/
581580
582static void zeus_register_update(offs_t offset)
581static void zeus_register_update(running_machine *machine, offs_t offset)
583582{
584583   /* handle the writes; only trigger on low accesses */
585584   switch (offset)
r2724r2725
656655                we simply assert immediately if this is enabled. invasn needs this for proper
657656                operations */
658657         if (zeusbase[0x80] & 0x02000000)
659            cpunum_set_input_line(Machine, 0, 2, ASSERT_LINE);
658            cpunum_set_input_line(machine, 0, 2, ASSERT_LINE);
660659         else
661            cpunum_set_input_line(Machine, 0, 2, CLEAR_LINE);
660            cpunum_set_input_line(machine, 0, 2, CLEAR_LINE);
662661         break;
663662
664663      case 0x84:
r2724r2725
717716      case 0xc6:
718717      case 0xc8:
719718      case 0xca:
720         video_screen_update_partial(Machine->primary_screen, video_screen_get_vpos(Machine->primary_screen));
719         video_screen_update_partial(machine->primary_screen, video_screen_get_vpos(machine->primary_screen));
721720         {
722721            int vtotal = zeusbase[0xca] >> 16;
723722            int htotal = zeusbase[0xc6] >> 16;
r2724r2725
729728            visarea.max_y = zeusbase[0xc8] & 0xffff;
730729            if (htotal > 0 && vtotal > 0 && visarea.min_x < visarea.max_x && visarea.max_y < vtotal)
731730            {
732               video_screen_configure(Machine->primary_screen, htotal, vtotal, &visarea, HZ_TO_ATTOSECONDS((double)MIDZEUS_VIDEO_CLOCK / 8.0 / (htotal * vtotal)));
731               video_screen_configure(machine->primary_screen, htotal, vtotal, &visarea, HZ_TO_ATTOSECONDS((double)MIDZEUS_VIDEO_CLOCK / 8.0 / (htotal * vtotal)));
733732               zeus_cliprect = visarea;
734733               zeus_cliprect.max_x -= zeus_cliprect.min_x;
735734               zeus_cliprect.min_x = 0;
r2724r2725
738737         break;
739738
740739      case 0xcc:
741         video_screen_update_partial(Machine->primary_screen, video_screen_get_vpos(Machine->primary_screen));
740         video_screen_update_partial(machine->primary_screen, video_screen_get_vpos(machine->primary_screen));
742741         log_fifo = input_code_pressed(KEYCODE_L);
743742         break;
744743
745744      case 0xe0:
746745         zeus_fifo[zeus_fifo_words++] = zeusbase[0xe0];
747         if (zeus_fifo_process(zeus_fifo, zeus_fifo_words))
746         if (zeus_fifo_process(machine, zeus_fifo, zeus_fifo_words))
748747            zeus_fifo_words = 0;
749748         break;
750749   }
r2724r2725
758757 *
759758 *************************************/
760759
761static int zeus_fifo_process(const UINT32 *data, int numwords)
760static int zeus_fifo_process(running_machine *machine, const UINT32 *data, int numwords)
762761{
763762   /* handle logging */
764763   switch (data[0] >> 24)
r2724r2725
778777      case 0x13:   /* invasn */
779778         if (log_fifo)
780779            log_fifo_command(data, numwords, "");
781         zeus_draw_model((zeusbase[0x06] << 16), log_fifo);
780         zeus_draw_model(machine, (zeusbase[0x06] << 16), log_fifo);
782781         break;
783782
784783      /* 0x17: write 16-bit value to low registers */
785784      case 0x17:
786785         if (log_fifo)
787786            log_fifo_command(data, numwords, " -- reg16");
788         zeus_register16_w((data[0] >> 16) & 0x7f, data[0], log_fifo);
787         zeus_register16_w(machine, (data[0] >> 16) & 0x7f, data[0], log_fifo);
789788         break;
790789
791790      /* 0x18: write 32-bit value to low registers */
r2724r2725
795794            return FALSE;
796795         if (log_fifo)
797796            log_fifo_command(data, numwords, " -- reg32");
798         zeus_register32_w((data[0] >> 16) & 0x7f, data[1], log_fifo);
797         zeus_register32_w(machine, (data[0] >> 16) & 0x7f, data[1], log_fifo);
799798         break;
800799
801800      /* 0x1A: sync pipeline(?) */
r2724r2725
939938         if (log_fifo)
940939            log_fifo_command(data, numwords, "");
941940         zeus_objdata = data[1];
942         zeus_draw_model(data[2], log_fifo);
941         zeus_draw_model(machine, data[2], log_fifo);
943942         break;
944943
945944      default:
r2724r2725
959958 *
960959 *************************************/
961960
962static void zeus_draw_model(UINT32 texdata, int logit)
961static void zeus_draw_model(running_machine *machine, UINT32 texdata, int logit)
963962{
964963   UINT32 databuffer[32];
965964   int databufcount = 0;
r2724r2725
10181017               case 0x17:   /* mk4 */
10191018                  if (logit)
10201019                     logerror("reg16");
1021                  zeus_register16_w((databuffer[0] >> 16) & 0x7f, databuffer[0], logit);
1020                  zeus_register16_w(machine, (databuffer[0] >> 16) & 0x7f, databuffer[0], logit);
10221021                  if (((databuffer[0] >> 16) & 0x7f) == 0x06)
10231022                     texdata = (texdata & 0xffff) | (zeusbase[0x06] << 16);
10241023                  break;
r2724r2725
10261025               case 0x19:   /* invasn */
10271026                  if (logit)
10281027                     logerror("reg32");
1029                  zeus_register32_w((databuffer[0] >> 16) & 0x7f, databuffer[1], logit);
1028                  zeus_register32_w(machine, (databuffer[0] >> 16) & 0x7f, databuffer[1], logit);
10301029                  if (((databuffer[0] >> 16) & 0x7f) == 0x06)
10311030                     texdata = (texdata & 0xffff) | (zeusbase[0x06] << 16);
10321031                  break;
src/mame/video/namcona1.c
r2724r2725
1616UINT16 *namcona1_scroll;
1717UINT16 *namcona1_workram;
1818UINT16 *namcona1_sparevram;
19UINT16 *namcona1_rozvideoram;
2019UINT16 *namcona1_pixmap;
2120
2221/* private variables */
r2724r2725
9291{
9392   /* each logical tile is constructed from 4*4 normal tiles */
9493   int tilemap_color = roz_palette;
95   int use_4bpp_gfx = namcona1_vreg[0xbc/2]&16;
94   int use_4bpp_gfx = namcona1_vreg[0xbc/2]&16; /* ? */
9695   int c = tile_index%0x40;
9796   int r = tile_index/0x40;
98   int data = namcona1_rozvideoram[(r/4)*0x40+c/4]+(c%4)+(r%4)*0x40;
99   int tile = data&0xfff;
97   int data = videoram16[0x8000/2+(r/4)*0x40+c/4]&0xfbf; /* mask out bit 0x40 - patch for Emeraldia Japan */
98   int tile = (data+(c%4)+(r%4)*0x40)&0xfff;
10099   int gfx = use_4bpp_gfx;
101100   if( use_4bpp_gfx )
102101   {
r2724r2725
129128   }
130129} /* roz_get_info */
131130
132WRITE16_HANDLER( namcona1_rozvideoram_w )
133{
134   COMBINE_DATA( &namcona1_rozvideoram[offset] );
135   roz_dirty = 1;
136}
137READ16_HANDLER( namcona1_rozvideoram_r )
138{
139   return namcona1_rozvideoram[offset];
140}
141
142131/*************************************************************************/
143132
144133WRITE16_HANDLER( namcona1_videoram_w )
145134{
146135   COMBINE_DATA( &videoram16[offset] );
147   tilemap_mark_tile_dirty( bg_tilemap[offset/0x1000], offset&0xfff );
136   if( offset<0x8000/2 )
137   {
138      tilemap_mark_tile_dirty( bg_tilemap[offset/0x1000], offset&0xfff );
139   }
140   else if( offset<0xa000/2 )
141   {
142      roz_dirty = 1;
143   }
148144} /* namcona1_videoram_w */
149145
150146READ16_HANDLER( namcona1_videoram_r )
r2724r2725
157153static void
158154UpdatePalette(running_machine *machine, int offset )
159155{
160   UINT16 color = paletteram16[offset]; /* -RRRRRGGGGGBBBBB */
161   palette_set_color_rgb( machine, offset, pal5bit(color >> 10), pal5bit(color >> 5), pal5bit(color >> 0));
156   UINT16 data = paletteram16[offset]; /* -RRRRRGG GGGBBBBB */
157   /**
158     * sprites can be configured to use an alternate interpretation of palette ram
159     * (used in-game in Emeraldia)
160     *
161     * RRRGGGBB RRRGGGBB
162     */
163   int r = (((data&0x00e0)>>5)+((data&0xe000)>>13)*2)*0xff/(0x7*3);
164   int g = (((data&0x001c)>>2)+((data&0x1c00)>>10)*2)*0xff/(0x7*3);
165   int b = (((data&0x0003)>>0)+((data&0x0300)>>8)*2)*0xff/(0x3*3);
166   palette_set_color_rgb( machine, offset+0x1000, r, g, b);
167
168   palette_set_color_rgb( machine, offset, pal5bit(data >> 10), pal5bit(data >> 5), pal5bit(data >> 0));
162169} /* namcona1_paletteram_w */
163170
164171READ16_HANDLER( namcona1_paletteram_r )
r2724r2725
170177{
171178   COMBINE_DATA( &paletteram16[offset] );
172179   if( namcona1_vreg[0x8e/2] )
173   {
174      /* graphics enabled; update palette immediately */
180   { /* graphics enabled; update palette immediately */
175181      UpdatePalette(machine, offset );
176182   }
177183   else
r2724r2725
293299         }
294300      }
295301
296      pSource = namcona1_rozvideoram;
297      for( i=0; i<0x800; i++ )
302      for( i=0; i<0x1000; i++ )
298303      {
299304         if( dirtychar[*pSource++ & 0xfff] )
300305         {
r2724r2725
303308         }
304309      }
305310
306      for( i = 0;i < 0x1000;i++ )
311      for( i = 0;i <0x1000; i++ )
307312      {
308313         if( dirtychar[i] )
309314         {
r2724r2725
333338   }
334339
335340   shaperam           = auto_malloc( 0x2000*4 );
336   cgram              = auto_malloc( 0x1000*0x20*2 );
341   cgram              = auto_malloc( 0x1000*0x40 );
337342   dirtychar           = auto_malloc( 0x1000 );
338   namcona1_rozvideoram = auto_malloc( 0x4000 );
339343
340344   gfx0 = allocgfx( &cg_layout_8bpp );
341345   gfx0->total_colors = machine->config->total_colors/256;
r2724r2725
476480                              dest[x] = palette_shadow_table[dest[x]];
477481                           }
478482                           else
479                           { // bad?
480                              dest[x] = pal_base+c;
483                           {
484                              dest[x] = pal_base + c + 0x1000;
481485                           }
482486                        }
483487                        else
r2724r2725
584588static void draw_pixel_line( UINT16 *pDest, UINT8 *pPri, UINT16 *pSource, const pen_t *paldata )
585589{
586590   int x;
587   UINT16 data;
588
589591   for( x=0; x<38*8; x+=2 )
590592   {
591      pPri[x / 2] = 0xff;
592      data = *pSource++;
593      pDest[x] = paldata[data>>8];
593      UINT16 data = *pSource++;
594      pPri[x+0] = 0xff;
595      pPri[x+1] = 0xff;
596      pDest[x+0] = paldata[data>>8];
594597      pDest[x+1] = paldata[data&0xff];
595598   } /* next x */
596599} /* draw_pixel_line */
r2724r2725
647650            draw_pixel_line(
648651               BITMAP_ADDR16(bitmap, line, 0),
649652               BITMAP_ADDR8(priority_bitmap, line, 0),
650               namcona1_rozvideoram + (ydata-0x4000) + 25,
653               videoram16 + ydata + 25,
651654               paldata );
652655         }
653656         else
654657         {
655            // used in emeraldia
656            if(which == NAMCONA1_NUM_TILEMAPS )// && namcona1_vreg[0x8a/2] == 0xfd /* maybe reg & 0x4 */)
658            if(which == NAMCONA1_NUM_TILEMAPS )
657659            {
658               int incxx = ((INT16)namcona1_vreg[0xc0/2])<<8; // or incyy ?
660               int incxx = ((INT16)namcona1_vreg[0xc0/2])<<8;
659661               int incxy = ((INT16)namcona1_vreg[0xc2/2])<<8;
660662               int incyx = ((INT16)namcona1_vreg[0xc4/2])<<8;
661               int incyy = ((INT16)namcona1_vreg[0xc6/2])<<8; // or incxx ?
663               int incyy = ((INT16)namcona1_vreg[0xc6/2])<<8;
662664               INT16 xoffset = namcona1_vreg[0xc8/2];
663665               INT16 yoffset = namcona1_vreg[0xca/2];
664               int dx = 46;
665               int dy = -8;
666
667               // now, apply adjustments to startx, starty to translate the
668               // ROZ plane.  Note that these are corrected by the inc parameters
669               // to account for scale/rotate state.
666               int dx = 46; /* horizontal adjust */
667               int dy = -8; /* vertical adjust */
670668               UINT32 startx = (xoffset<<12)+incxx*dx+incyx*dy;
671669               UINT32 starty = (yoffset<<12)+incxy*dx+incyy*dy;
672
673670               tilemap_draw_roz_primask(bitmap, &clip, roz_tilemap,
674                  startx, starty, incxx, incxy, incyx, incyy,
675                  0, 0, primask, 0);
671                  startx, starty, incxx, incxy, incyx, incyy, 0, 0, primask, 0);
676672            }
677673            else
678674            {
r2724r2725
737733      {
738734         for( which=4; which>=0; which-- )
739735         {
740            int pri = namcona1_vreg[0xa0/2+which]&0x7; /* likely wrong for roz plane */
736            int pri;
737            if( which==4 )
738            {
739               pri = namcona1_vreg[0xa0/2+5]&0x7;
740            }
741            else
742            {
743               pri = namcona1_vreg[0xa0/2+which]&0x7;
744            }
741745            if( pri == priority )
742746            {
743747               draw_background(screen->machine,bitmap,cliprect,which,priority);
r2724r2725
751755}
752756
753757/*
758roz bad in emeraldaj - blit param?
759
754760$efff20: sprite control: 0x3a,0x3e,0x3f
755761            bit 0x01 selects spriteram bank
756762
r2724r2725
758764$efff00:    src0 src1 src2 dst0 dst1 dst2 BANK [src
759765$efff10:    src] [dst dst] #BYT BLIT eINT 001f 0001
760766$efff20:    003f 003f IACK ---- ---- ---- ---- ----
761$efff80:    0050 0170 0020 0100 0000 POSI 0000 GFXE     POSI: scanline for POSIRQ
767...
768$efff80:    0050 0170 0020 0100 0170 POS? 0000 GFXE
762769$efff90:    0000 0001 0002 0003 FLIP ---- ---- ----
763$efffa0:    PRI  PRI  PRI  PRI  ---- PRI? --?? ----     priority (0..7)
764$efffb0:    CLR  CLR  CLR  CLR  0001 CLR? BPP  ----     color (0..f), bpp flag per layer
765$efffc0:    RZXX RZXY RZYX RZYY RZX0 RZY0 ???? ----     ROZ
770$efffa0:    PRI  PRI  PRI  PRI  ???? PRI  00c0 ----     priority (0..7)
771$efffb0:    CLR  CLR  CLR  CLR  0001 CLR  BPP  ----     color (0..f), bpp flag per layer
772$efffc0:    RZXX RZXY RZYX RZYY RZX0 RZY0 0044 ----     ROZ
773
774
775Emeralda:   0048 0177 0020 0100 0000 00f0 0000 0001     in-game
776            0050 0170 0020 0100 0000 00f0 0000 0001     self test
777
778NumanAth:   0050 0170 0020 0100 0170 00d8 0000 0001     in-game
779
780
766781*/
767
src/mame/video/dkong.c
r2724r2725
834834static void check_palette(running_machine *machine)
835835{
836836   dkong_state *state = machine->driver_data;
837   const input_port_config *port;
837838   int newset;
838   int num;
839839
840   num = port_tag_to_index("VIDHW");
841   if (num>=0)
840   port = input_port_by_tag(machine->portconfig, "VIDHW");
841   if (port != NULL)
842842   {
843      newset = input_port_read_indexed(machine, num);
843      newset = input_port_read_direct(port);
844844      if (newset != state->vidhw)
845845      {
846846         state->vidhw = newset;
src/mame/video/psx.c
r2724r2725
624624   int n_level2;
625625   int n_shade;
626626   int n_shaded;
627   int width = video_screen_get_width(Machine->primary_screen);
628   int height = video_screen_get_height(Machine->primary_screen);
627   int width = video_screen_get_width(machine->primary_screen);
628   int height = video_screen_get_height(machine->primary_screen);
629629
630630#if defined( MAME_DEBUG )
631631   DebugMeshInit();
r2724r2725
39023902#endif
39033903
39043904   m_n_gpustatus ^= ( 1L << 31 );
3905   psx_irq_set( 0x0001 );
3905   psx_irq_set( machine, 0x0001 );
39063906}
39073907
39083908void psx_gpu_reset( void )
src/mame/video/stactics.c
r2724r2725
114114
115115CUSTOM_INPUT( stactics_get_frame_count_d3 )
116116{
117   stactics_state *state = machine->driver_data;
117   stactics_state *state = field->port->machine->driver_data;
118118
119119   return (state->frame_count >> 3) & 0x01;
120120}
r2724r2725
172172
173173CUSTOM_INPUT( stactics_get_shot_standby )
174174{
175   stactics_state *state = machine->driver_data;
175   stactics_state *state = field->port->machine->driver_data;
176176
177177   return state->shot_standby;
178178}
r2724r2725
180180
181181CUSTOM_INPUT( stactics_get_not_shot_arrive )
182182{
183   stactics_state *state = machine->driver_data;
183   stactics_state *state = field->port->machine->driver_data;
184184
185185   return !state->shot_arrive;
186186}
src/mame/video/jagobj.c
r2724r2725
900900 *
901901 *************************************/
902902
903static void process_object_list(int vc, UINT16 *_scanline)
903static void process_object_list(running_machine *machine, int vc, UINT16 *_scanline)
904904{
905905   int done = 0, count = 0;
906906   UINT32 *objdata;
r2724r2725
960960               fprintf(stderr, "stop int=%d\n", interrupt);
961961#endif
962962               cpu_irq_state |= 4;
963               update_cpu_irq();
963               update_cpu_irq(machine);
964964            }
965965            break;
966966         }
src/mame/video/taitojc.c
r2724r2725
6262         if (taitojc_dirty_map[i])
6363         {
6464            taitojc_dirty_map[i] = 0;
65            decodechar(Machine->gfx[taitojc_gfx_index], i, (UINT8 *)taitojc_char_ram);
65            decodechar(machine->gfx[taitojc_gfx_index], i, (UINT8 *)taitojc_char_ram);
6666         }
6767      }
6868      tilemap_mark_all_tiles_dirty(taitojc_tilemap);
src/mame/video/gameplan.c
r2724r2725
214214}
215215
216216
217static void via_irq(int state)
217static void via_irq(running_machine *machine, int state)
218218{
219219   /* Kaos sits in a tight loop polling the VIA irq flags register, but that register is
220220       cleared by the irq handler. Therefore, I wait a bit before triggering the irq to
src/mame/video/st0016.c
r2724r2725
44************************************/
55
66#include "driver.h"
7#include "deprecat.h"
87#include "st0016.h"
98
109UINT8 *st0016_charram,*st0016_spriteram,*st0016_paletteram;
r2724r2725
144143   {
145144      case 0:
146145      case 1:
147         return mame_rand(Machine);
146         return mame_rand(machine);
148147   }
149148
150149   return st0016_vregs[offset];
src/mame/video/midvunit.c
r2724r2725
55**************************************************************************/
66
77#include "driver.h"
8#include "deprecat.h"
98#include "cpu/tms34010/tms34010.h"
109#include "cpu/adsp2100/adsp2100.h"
1110#include "audio/williams.h"
r2724r2725
399398   {
400399      if (LOG_DMA && input_code_pressed(KEYCODE_L))
401400         logerror("%06X:trigger\n", activecpu_get_pc());
402      process_dma_queue(Machine);
401      process_dma_queue(machine);
403402      dma_data_index = 0;
404403   }
405404   return 0;
src/mame/video/gtia.c
r2724r2725
99***************************************************************************/
1010
1111#include "driver.h"
12#include "deprecat.h"
1312#include "cpu/m6502/m6502.h"
1413#include "includes/atari.h"
1514#include "video/gtia.h"
r2724r2725
6968   memset(&gtia, 0, sizeof(gtia));
7069   gtia.intf = *intf;
7170
72   add_reset_callback(Machine, gtia_reset);
71   add_reset_callback(machine, gtia_reset);
7372
7473   /* state saves */
7574   gtia_state(machine);
src/mame/video/jaguar.c
r2724r2725
211211
212212/* from jagobj.c */
213213static void jagobj_init(void);
214static void process_object_list(int vc, UINT16 *_scanline);
214static void process_object_list(running_machine *machine, int vc, UINT16 *_scanline);
215215
216216/* from jagblit.c */
217217static void generic_blitter(UINT32 command, UINT32 a1flags, UINT32 a2flags);
r2724r2725
325325 *
326326 *************************************/
327327
328static void update_cpu_irq(void)
328static void update_cpu_irq(running_machine *machine)
329329{
330330   if (cpu_irq_state & gpu_regs[INT1] & 0x1f)
331      cpunum_set_input_line(Machine, 0, cojag_is_r3000 ? R3000_IRQ4 : MC68000_IRQ_6, ASSERT_LINE);
331      cpunum_set_input_line(machine, 0, cojag_is_r3000 ? R3000_IRQ4 : MC68000_IRQ_6, ASSERT_LINE);
332332   else
333      cpunum_set_input_line(Machine, 0, cojag_is_r3000 ? R3000_IRQ4 : MC68000_IRQ_6, CLEAR_LINE);
333      cpunum_set_input_line(machine, 0, cojag_is_r3000 ? R3000_IRQ4 : MC68000_IRQ_6, CLEAR_LINE);
334334}
335335
336336
337337void jaguar_gpu_cpu_int(void)
338338{
339339   cpu_irq_state |= 2;
340   update_cpu_irq();
340   update_cpu_irq(Machine);
341341}
342342
343343
344344void jaguar_dsp_cpu_int(void)
345345{
346346   cpu_irq_state |= 16;
347   update_cpu_irq();
347   update_cpu_irq(Machine);
348348}
349349
350350
r2724r2725
654654      {
655655         case INT1:
656656            cpu_irq_state &= ~(gpu_regs[INT1] >> 8);
657            update_cpu_irq();
657            update_cpu_irq(machine);
658658            break;
659659
660660         case VMODE:
r2724r2725
778778      }
779779
780780      /* process the object list for this counter value */
781      process_object_list(vc, scanline);
781      process_object_list(machine, vc, scanline);
782782
783783      /* copy the data to the target, clipping */
784784      for (x = 0; x < 360 && hdb <= maxx && hdb < hde; x++, hdb++)
r2724r2725
792792      if (vc == gpu_regs[VI])
793793      {
794794         cpu_irq_state |= 1;
795         update_cpu_irq();
795         update_cpu_irq(machine);
796796      }
797797
798798      /* point to the next counter value */
r2724r2725
804804
805805static STATE_POSTLOAD( cojag_postload )
806806{
807   update_cpu_irq();
807   update_cpu_irq(machine);
808808}
809809
810810VIDEO_START( cojag )
src/mame/video/victory.c
r2724r2725
101101 *
102102 *************************************/
103103
104static void victory_update_irq(void)
104static void victory_update_irq(running_machine *machine)
105105{
106106   if (vblank_irq || fgcoll || (bgcoll && (video_control & 0x20)))
107      cpunum_set_input_line(Machine, 0, 0, ASSERT_LINE);
107      cpunum_set_input_line(machine, 0, 0, ASSERT_LINE);
108108   else
109      cpunum_set_input_line(Machine, 0, 0, CLEAR_LINE);
109      cpunum_set_input_line(machine, 0, 0, CLEAR_LINE);
110110}
111111
112112
r2724r2725
114114{
115115   vblank_irq = 1;
116116
117   victory_update_irq();
117   victory_update_irq(machine);
118118}
119119
120120
r2724r2725
167167         if (fgcoll)
168168         {
169169            fgcoll = 0;
170            victory_update_irq();
170            victory_update_irq(machine);
171171         }
172172         if (LOG_COLLISION) logerror("%04X:5CLFIQ read = %02X\n", activecpu_get_previouspc(), result);
173173         return result;
r2724r2725
182182         if (bgcoll)
183183         {
184184            bgcoll = 0;
185            victory_update_irq();
185            victory_update_irq(machine);
186186         }
187187         if (LOG_COLLISION) logerror("%04X:5BACKY read = %02X\n", activecpu_get_previouspc(), result);
188188         return result;
r2724r2725
321321      case 0x0b:   /* CLRVIRQ */
322322         if (LOG_MICROCODE) logerror("%04X:CLRVIRQ write = %02X\n", activecpu_get_previouspc(), data);
323323         vblank_irq = 0;
324         victory_update_irq();
324         victory_update_irq(machine);
325325         break;
326326
327327      default:
r2724r2725
674674               rram[dstoffs + 0] ^= src >> shift;
675675               rram[dstoffs + 1] ^= src << nshift;
676676            }
677            if (fgcoll) victory_update_irq();
677            if (fgcoll) victory_update_irq(Machine);
678678         }
679679      }
680680   }
r2724r2725
874874         }
875875         acc &= 0xff;
876876      }
877      if (fgcoll) victory_update_irq();
877      if (fgcoll) victory_update_irq(Machine);
878878   }
879879
880880   micro.xp = x;
r2724r2725
10041004         rram[addr + 0] ^= micro.r >> shift;
10051005         rram[addr + 1] ^= micro.r << nshift;
10061006      }
1007      if (fgcoll) victory_update_irq();
1007      if (fgcoll) victory_update_irq(Machine);
10081008   }
10091009
10101010   count_states(4);
r2724r2725
10871087   bgcollx = param & 0xff;
10881088   bgcolly = param >> 8;
10891089   bgcoll = 1;
1090   victory_update_irq();
1090   victory_update_irq(machine);
10911091}
10921092
10931093
src/mame/video/pacland.c
r2724r2725
2525***************************************************************************/
2626
2727#include "driver.h"
28#include "deprecat.h"
2928
3029
3130UINT8 *pacland_videoram,*pacland_videoram2,*pacland_spriteram;
r2724r2725
273272   if (palette_bank != ((data & 0x18) >> 3))
274273   {
275274      palette_bank = (data & 0x18) >> 3;
276      switch_palette(Machine);
275      switch_palette(machine);
277276   }
278277}
279278
src/mame/video/f1gp.c
r2724r2725
11#include "driver.h"
2#include "deprecat.h"
32#include "video/konamiic.h"
43#include "f1gp.h"
54
r2724r2725
292291      if((spriteram16[attr_start + 1] & 0x00f0) && (spriteram16[attr_start + 1] & 0x00f0) != 0xc0)
293292      {
294293         printf("attr %X\n",spriteram16[attr_start + 1] & 0x00f0);
295         code = mame_rand(Machine);
294         code = mame_rand(machine);
296295      }
297296
298297/*
src/mame/video/exidy440.c
r2724r2725
55***************************************************************************/
66
77#include "driver.h"
8#include "deprecat.h"
98#include "exidy440.h"
109
1110
r2724r2725
154153{
155154   /* clear the FIRQ on a read here */
156155   exidy440_firq_beam = 0;
157   exidy440_update_firq(Machine);
156   exidy440_update_firq(machine);
158157
159158   /* according to the schems, this value is only latched on an FIRQ
160159     * caused by collision or beam */
r2724r2725
208207   palettebank_vis = data & 1;
209208
210209   /* update the FIRQ in case we enabled something */
211   exidy440_update_firq(Machine);
210   exidy440_update_firq(machine);
212211
213212   /* if we're swapping palettes, change all the colors */
214213   if (oldvis != palettebank_vis)
r2724r2725
231230{
232231   /* clear the VBLANK FIRQ on a write here */
233232   exidy440_firq_vblank = 0;
234   exidy440_update_firq(Machine);
233   exidy440_update_firq(machine);
235234}
236235
237236
src/mame/video/phoenix.c
r2724r2725
293293CUSTOM_INPUT( player_input_r )
294294{
295295   if (cocktail_mode)
296      return (input_port_read(machine, "CTRL") & 0xf0) >> 4;
296      return (input_port_read(field->port->machine, "CTRL") & 0xf0) >> 4;
297297   else
298      return (input_port_read(machine, "CTRL") & 0x0f) >> 0;
298      return (input_port_read(field->port->machine, "CTRL") & 0x0f) >> 0;
299299}
300300
301301CUSTOM_INPUT( pleiads_protection_r )
src/mame/video/atari.c
r2724r2725
15231523      handle_keyboard(machine);
15241524
15251525      /* do nothing new for the rest of the frame */
1526      antic.modelines = video_screen_get_height(Machine->primary_screen) - VBL_START;
1526      antic.modelines = video_screen_get_height(machine->primary_screen) - VBL_START;
15271527      antic_renderer = antic_mode_0_xx;
15281528
15291529      /* if the CPU want's to be interrupted at vertical blank... */
r2724r2725
15321532         LOG(("           cause VBL NMI\n"));
15331533         /* set the VBL NMI status bit */
15341534         antic.r.nmist |= VBL_NMI;
1535         cpunum_set_input_line(Machine, 0, INPUT_LINE_NMI, PULSE_LINE);
1535         cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, PULSE_LINE);
15361536      }
15371537    }
15381538
src/mame/video/n64.c
r2724r2725
335335                  int r = ((pix >> 11) & 0x1f) << 3;
336336                  int g = ((pix >> 6) & 0x1f) << 3;
337337                  int b = ((pix >> 1) & 0x1f) << 3;
338                  d[i^1] = (r << 16) | (g << 8) | b;
338                  d[BYTE_XOR_BE(i)] = (r << 16) | (g << 8) | b;
339339               }
340340            }
341341         }
src/mame/video/homedata.c
r2724r2725
11#include "driver.h"
2#include "deprecat.h"
32#include "cpu/m6809/m6809.h"
43#include "homedata.h"
54
r2724r2725
133132   } /* for(;;) */
134133
135134finish:
136   cpunum_set_input_line(Machine, 0,M6809_FIRQ_LINE,HOLD_LINE);
135   cpunum_set_input_line(machine, 0,M6809_FIRQ_LINE,HOLD_LINE);
137136}
138137
139138static void reikaids_handleblit( running_machine *machine, int rom_base )
r2724r2725
233232   }
234233
235234finish:
236   cpunum_set_input_line(Machine, 0,M6809_FIRQ_LINE,HOLD_LINE);
235   cpunum_set_input_line(machine, 0,M6809_FIRQ_LINE,HOLD_LINE);
237236}
238237
239238static void pteacher_handleblit( running_machine *machine, int rom_base )
r2724r2725
321320   } /* for(;;) */
322321
323322finish:
324   cpunum_set_input_line(Machine, 0,M6809_FIRQ_LINE,HOLD_LINE);
323   cpunum_set_input_line(machine, 0,M6809_FIRQ_LINE,HOLD_LINE);
325324}
326325
327326
src/mame/video/macrossp.c
r2724r2725
22  see DRIVER file for notes */
33
44#include "driver.h"
5#include "deprecat.h"
65
76
87UINT32 *macrossp_scra_videoram, *macrossp_scra_videoregs;
r2724r2725
4443         break;
4544
4645      default:
47         color = mame_rand(Machine) & 7;
46         color = mame_rand(machine) & 7;
4847         break;
4948   }
5049
r2724r2725
7978         break;
8079
8180      default:
82         color = mame_rand(Machine) & 7;
81         color = mame_rand(machine) & 7;
8382         break;
8483   }
8584
r2724r2725
114113         break;
115114
116115      default:
117         color = mame_rand(Machine) & 7;
116         color = mame_rand(machine) & 7;
118117         break;
119118   }
120119
r2724r2725
232231               break;
233232
234233            default:
235               col = mame_rand(Machine);
234               col = mame_rand(machine);
236235               break;
237236         }
238237
src/mame/video/groundfx.c
r2724r2725
242242   fillbitmap(priority_bitmap,0,cliprect);
243243   fillbitmap(bitmap,0,cliprect);   /* wrong color? */
244244
245   TC0100SCN_tilemap_draw(screen->machine,bitmap,cliprect,0,pivlayer[0],0,0);
245   TC0100SCN_tilemap_draw(screen->machine,bitmap,cliprect,0,pivlayer[0],TILEMAP_DRAW_OPAQUE,0);
246246   TC0100SCN_tilemap_draw(screen->machine,bitmap,cliprect,0,pivlayer[1],0,0);
247247
248248   /*  BIG HACK!
src/mame/layout/shuttlei.lay
r0r2725
1<mamelayout version="2">
2   <element name="overlay">
3      <rect>
4         <bounds left="0" top="0" right="168" bottom="161.5" />
5         <color red="0.125" green="1" blue="0.125" />
6      </rect>
7      <rect>
8         <bounds left="0" top="161.5" right="168" bottom="175.5" />
9         <color red="1" green="0.5" blue="0.0625" />
10      </rect>
11      <rect>
12         <bounds left="0" top="175.5" right="168" bottom="224" />
13         <color red="1" green="0.125" blue="0.125" />
14      </rect>
15   </element>
16   <view name="Color_Overlay">
17      <screen index="0">
18         <bounds x="0" y="0" width="168" height="224" />
19      </screen>
20      <overlay element="overlay">
21         <bounds x="0" y="0" width="168" height="224" />
22      </overlay>
23      <bezel element="overlay">
24         <bounds x="0" y="0" width="168" height="224" />
25         <color alpha="0.1" />
26      </bezel>
27   </view>
28</mamelayout>
src/mame/drivers/bfcobra.c
r2724r2725
848848         val = 0x1;
849849
850850         /* TODO */
851         update_irqs(Machine);
851         update_irqs(machine);
852852         break;
853853      }
854854      case 0x1C:
src/mame/drivers/intrscti.c
r2724r2725
1212*/
1313
1414#include "driver.h"
15#include "deprecat.h"
1615
1716static READ8_HANDLER( unk_r )
1817{
19   return mame_rand(Machine);
18   return mame_rand(machine);
2019}
2120
2221static UINT8 *intrscti_ram;
src/mame/drivers/nycaptor.c
r2724r2725
456456
457457static READ8_HANDLER(cyclshtg_mcu_status_r1)
458458{
459  return mame_rand(Machine);
459  return mame_rand(machine);
460460}
461461
462462static WRITE8_HANDLER( cyclshtg_generic_control_w )
r2724r2725
534534
535535static READ8_HANDLER(unk_r)
536536{
537  return mame_rand(Machine);
537  return mame_rand(machine);
538538}
539539
540540static ADDRESS_MAP_START( bronx_readmem, ADDRESS_SPACE_PROGRAM, 8 )
src/mame/drivers/mitchell.c
r2724r2725
14131413
14141414
14151415
1416static void spangbl_adpcm_int(int data)
1416static void spangbl_adpcm_int(running_machine *machine, int data)
14171417{
14181418   MSM5205_data_w(0, sample_buffer & 0x0F);
14191419   sample_buffer >>= 4;
14201420   sample_select ^= 1;
14211421   if(sample_select == 0)
1422      cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, PULSE_LINE);
1422      cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, PULSE_LINE);
14231423}
14241424
14251425
src/mame/drivers/rainbow.c
r2724r2725
237237***************************************************************************/
238238
239239#include "driver.h"
240#include "deprecat.h"
241240#include "taitoipt.h"
242241#include "video/taitoic.h"
243242#include "audio/taitosnd.h"
r2724r2725
597596
598597/* handler called by the YM2151 emulator when the internal timers cause an IRQ */
599598
600static void irqhandler(int irq)
599static void irqhandler(running_machine *machine, int irq)
601600{
602   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
601   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
603602}
604603
605604static const struct YM2151interface ym2151_interface =
src/mame/drivers/galspnbl.c
r2724r2725
1919***************************************************************************/
2020
2121#include "driver.h"
22#include "deprecat.h"
2322#include "cpu/z80/z80.h"
2423#include "sound/okim6295.h"
2524#include "sound/3812intf.h"
r2724r2725
264263
265264
266265
267static void irqhandler(int linestate)
266static void irqhandler(running_machine *machine, int linestate)
268267{
269   cpunum_set_input_line(Machine, 1,0,linestate);
268   cpunum_set_input_line(machine, 1,0,linestate);
270269}
271270
272271static const struct YM3812interface ym3812_interface =
src/mame/drivers/blktiger.c
r2724r2725
1414***************************************************************************/
1515
1616#include "driver.h"
17#include "deprecat.h"
1817#include "cpu/z80/z80.h"
1918#include "sound/2203intf.h"
2019
r2724r2725
229228
230229
231230/* handler called by the 2203 emulator when the internal timers cause an IRQ */
232static void irqhandler(int irq)
231static void irqhandler(running_machine *machine, int irq)
233232{
234   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
233   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
235234}
236235
237236static const struct YM2203interface ym2203_interface =
src/mame/drivers/mgolf.c
r2724r2725
55***************************************************************************/
66
77#include "driver.h"
8#include "deprecat.h"
98
109static UINT8* mgolf_video_ram;
1110
r2724r2725
8281         time_released = timer_get_time();
8382
8483         if (!mask)
85            cpunum_set_input_line(Machine, 0, INPUT_LINE_NMI, PULSE_LINE);
84            cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, PULSE_LINE);
8685      }
8786      else
8887         time_pushed = timer_get_time();
src/mame/drivers/deco_mlc.c
r2724r2725
9696***************************************************************************/
9797
9898#include "driver.h"
99#include "deprecat.h"
10099#include "machine/eeprom.h"
101100#include "sound/ymz280b.h"
102101#include "decoprot.h"
r2724r2725
126125//  if (offset==0)
127126//      return input_port_read_indexed(machine, 0); //0xffffffff;
128127//   logerror("%08x:  Test2_r %d\n",activecpu_get_pc(),offset);
129   return mame_rand(Machine); //0xffffffff;
128   return mame_rand(machine); //0xffffffff;
130129}
131130
132131static READ32_HANDLER(test3_r)
r2724r2725
136135
137136*/
138137//if (offset==0)
139//  return mame_rand(Machine)|(mame_rand(Machine)<<16);
138//  return mame_rand(machine)|(mame_rand(machine)<<16);
140139//  logerror("%08x:  Test3_r %d\n",activecpu_get_pc(),offset);
141140   return 0xffffffff;
142141}
src/mame/drivers/tempest.c
r2724r2725
278278***************************************************************************/
279279
280280#include "driver.h"
281#include "deprecat.h"
282281#include "machine/mathbox.h"
283282#include "video/avgdvg.h"
284283#include "video/vector.h"
r2724r2725
305304static WRITE8_HANDLER( wdclr_w )
306305{
307306   cpunum_set_input_line(machine, 0, 0, CLEAR_LINE);
308   watchdog_reset(Machine);
307   watchdog_reset(machine);
309308}
310309
311310/*************************************
r2724r2725
320319
321320   if (tempest_player_select)
322321   {
323      ret = input_port_read(machine, TEMPEST_KNOB_P2_TAG);
322      ret = input_port_read(field->port->machine, TEMPEST_KNOB_P2_TAG);
324323   }
325324   else
326325   {
327      ret = input_port_read(machine, TEMPEST_KNOB_P1_TAG);
326      ret = input_port_read(field->port->machine, TEMPEST_KNOB_P1_TAG);
328327   }
329328
330329   return ret;
r2724r2725
336335
337336   if (tempest_player_select)
338337   {
339      ret = input_port_read(machine, TEMPEST_BUTTONS_P2_TAG);
338      ret = input_port_read(field->port->machine, TEMPEST_BUTTONS_P2_TAG);
340339   }
341340   else
342341   {
343      ret = input_port_read(machine, TEMPEST_BUTTONS_P1_TAG);
342      ret = input_port_read(field->port->machine, TEMPEST_BUTTONS_P1_TAG);
344343   }
345344
346345   return ret;
src/mame/drivers/madmotor.c
r2724r2725
1313***************************************************************************/
1414
1515#include "driver.h"
16#include "deprecat.h"
1716#include "cpu/h6280/h6280.h"
1817#include "sound/2203intf.h"
1918#include "sound/2151intf.h"
r2724r2725
272271
273272/******************************************************************************/
274273
275static void sound_irq(int state)
274static void sound_irq(running_machine *machine, int state)
276275{
277   cpunum_set_input_line(Machine, 1,1,state); /* IRQ 2 */
276   cpunum_set_input_line(machine, 1,1,state); /* IRQ 2 */
278277}
279278
280279static const struct YM2151interface ym2151_interface =
src/mame/drivers/bublbobl.c
r2724r2725
716716#define VBLANK      1 / VSYNC * (40 / 264)
717717
718718// handler called by the 2203 emulator when the internal timers cause an IRQ
719static void irqhandler(int irq)
719static void irqhandler(running_machine *machine, int irq)
720720{
721   cpunum_set_input_line(Machine, 2, 0, irq ? ASSERT_LINE : CLEAR_LINE);
721   cpunum_set_input_line(machine, 2, 0, irq ? ASSERT_LINE : CLEAR_LINE);
722722}
723723
724724static const struct YM2203interface ym2203_interface =
src/mame/drivers/chinsan.c
r2724r2725
4040*/
4141
4242#include "driver.h"
43#include "deprecat.h"
4443#include "machine/mc8123.h"
4544#include "sound/2203intf.h"
4645
r2724r2725
153152   }
154153
155154   printf("chinsan_input_port_0_r unk_r %02x\n", chinsan_port_select);
156   return mame_rand(Machine);
155   return mame_rand(machine);
157156}
158157
159158static READ8_HANDLER( chinsan_input_port_1_r )
r2724r2725
182181   }
183182
184183   printf("chinsan_input_port_1_r unk_r %02x\n", chinsan_port_select);
185   return mame_rand(Machine);
184   return mame_rand(machine);
186185}
187186
188187
src/mame/drivers/aerofgt.c
r2724r2725
5959***************************************************************************/
6060
6161#include "driver.h"
62#include "deprecat.h"
6362#include "cpu/z80/z80.h"
6463#include "sound/2610intf.h"
6564#include "sound/3812intf.h"
r2724r2725
11931192   16,16,
11941193   RGN_FRAC(1,4),
11951194   4,
1196   { RGN_FRAC(0,4), RGN_FRAC(1,4), RGN_FRAC(2,4), RGN_FRAC(3,4) },
1195   { RGN_FRAC(3,4), RGN_FRAC(2,4), RGN_FRAC(1,4), RGN_FRAC(0,4) },
11971196   { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 },
11981197   { 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16,
11991198         8*16, 9*16, 10*16, 11*16, 12*16, 13*16, 14*16, 15*16 },
r2724r2725
13001299   GFXDECODE_ENTRY( REGION_GFX2, 0, wbbc97_spritelayout, 1024, 64 )   /* colors 1024-2047 in 4 banks */
13011300GFXDECODE_END
13021301
1303static void irqhandler(int irq)
1302static void irqhandler(running_machine *machine, int irq)
13041303{
1305   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
1304   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
13061305}
13071306
13081307static const struct YM2610interface ym2610_interface =
r2724r2725
19091908   ROM_LOAD( "5.ic74",   0x40000, 0x20000, CRC(d7fcd97c) SHA1(eb7c8ac111f5916350aae0ee3edc019207fef654) )
19101909   ROM_LOAD( "6.ic73",   0x60000, 0x20000, CRC(e6b9107f) SHA1(aaab2f2dfb85ee764091253c9a4ab89bc51d7518) )
19111910
1912   ROM_REGION( 0x100000, REGION_GFX2, ROMREGION_DISPOSE )
1911   ROM_REGION( 0x100000, REGION_GFX2, ROMREGION_DISPOSE | ROMREGION_INVERT )
19131912   ROM_LOAD( "11.ic118",   0x00000, 0x40000, CRC(6e65b4b2) SHA1(5296e8095ec60f79a5cd3f9db829c7d491670282) )
19141913   ROM_LOAD( "12.ic119",   0x40000, 0x40000, CRC(60e0d3e0) SHA1(93efc58b03610e7f18ff076ac985428a446454f9) )
19151914   ROM_LOAD( "13.ic120",   0x80000, 0x40000, CRC(89213a8c) SHA1(8524d5c14669d9b03f1fe050c4318d4111bc8ef7) )
r2724r2725
24482447GAME( 1991, pspikesk, pspikes,  pspikes,  pspikes,  0, ROT0,   "Video System Co.", "Power Spikes (Korea)", GAME_NO_COCKTAIL )
24492448GAME( 1991, svolly91, pspikes,  pspikes,  pspikes,  0, ROT0,   "Video System Co.", "Super Volley '91 (Japan)", GAME_NO_COCKTAIL )
24502449GAME( 1991, pspikesb, pspikes,  pspikesb, pspikesb, 0, ROT0,   "bootleg",          "Power Spikes (bootleg)", GAME_NO_COCKTAIL )
2451GAME( 1991, spikes91, pspikes,  spikes91, pspikes,  0, ROT0,   "bootleg",          "1991 Spikes (Italian bootleg)", GAME_NOT_WORKING | GAME_NO_SOUND | GAME_NO_COCKTAIL )
2450GAME( 1991, spikes91, pspikes,  spikes91, pspikes,  0, ROT0,   "bootleg",          "1991 Spikes (Italian bootleg)", GAME_NO_SOUND | GAME_NO_COCKTAIL )
24522451GAME( 1991, pspikesc, pspikes,  pspikesc, pspikesc, 0, ROT0,   "bootleg",          "Power Spikes (China)", GAME_NO_COCKTAIL | GAME_IMPERFECT_SOUND )
24532452GAME( 1991, karatblz, 0,        karatblz, karatblz, 0, ROT0,   "Video System Co.", "Karate Blazers (World?)", GAME_NO_COCKTAIL )
24542453GAME( 1991, karatblu, karatblz, karatblz, karatblz, 0, ROT0,   "Video System Co.", "Karate Blazers (US)", GAME_NO_COCKTAIL )
src/mame/drivers/docastle.c
r2724r2725
159159
160160static int adpcm_pos, adpcm_idle;
161161
162static void idsoccer_adpcm_int(int chip)
162static void idsoccer_adpcm_int(running_machine *machine, int chip)
163163{
164164   static int adpcm_data = -1;
165165
src/mame/drivers/ultrsprt.c
r2724r2725
55*/
66
77#include "driver.h"
8#include "deprecat.h"
98#include "cpu/powerpc/ppc.h"
109#include "sound/k054539.h"
1110#include "machine/eeprom.h"
r2724r2725
260259   MDRV_SOUND_ROUTE(1, "right", 1.0)
261260MACHINE_DRIVER_END
262261
263static void sound_irq_callback(int irq)
262static void sound_irq_callback(running_machine *machine, int irq)
264263{
265264   if (irq == 0)
266      /*cpunum_set_input_line(Machine, 1, INPUT_LINE_IRQ5, PULSE_LINE)*/;
265      /*cpunum_set_input_line(machine, 1, INPUT_LINE_IRQ5, PULSE_LINE)*/;
267266   else
268      cpunum_set_input_line(Machine, 1, INPUT_LINE_IRQ6, PULSE_LINE);
267      cpunum_set_input_line(machine, 1, INPUT_LINE_IRQ6, PULSE_LINE);
269268}
270269
271270static DRIVER_INIT( ultrsprt )
src/mame/drivers/mystston.c
r2724r2725
5858static INPUT_CHANGED( coin_inserted )
5959{
6060   /* coin insertion causes an NMI */
61   cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, newval ? CLEAR_LINE : ASSERT_LINE);
61   cpunum_set_input_line(field->port->machine, 0, INPUT_LINE_NMI, newval ? CLEAR_LINE : ASSERT_LINE);
6262}
6363
6464
src/mame/drivers/snowbros.c
r2724r2725
15151515GFXDECODE_END
15161516
15171517/* handler called by the 3812/2151 emulator when the internal timers cause an IRQ */
1518static void irqhandler(int irq)
1518static void irqhandler(running_machine *machine, int irq)
15191519{
1520   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
1520   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
15211521}
15221522
15231523/* SnowBros Sound */
src/mame/drivers/segaxbd.c
r2724r2725
9595 *
9696 *************************************/
9797
98static void update_main_irqs(void)
98static void update_main_irqs(running_machine *machine)
9999{
100100   int irq = 0;
101101
r2724r2725
111111   /* assert the lines that are live, or clear everything if nothing is live */
112112   if (irq != 0)
113113   {
114      cpunum_set_input_line(Machine, 0, irq, ASSERT_LINE);
114      cpunum_set_input_line(machine, 0, irq, ASSERT_LINE);
115115      cpu_boost_interleave(attotime_zero, ATTOTIME_IN_USEC(100));
116116   }
117117   else
118      cpunum_set_input_line(Machine, 0, 7, CLEAR_LINE);
118      cpunum_set_input_line(machine, 0, 7, CLEAR_LINE);
119119}
120120
121121
r2724r2725
148148
149149   /* update IRQs on the main CPU */
150150   if (update)
151      update_main_irqs();
151      update_main_irqs(machine);
152152
153153   /* come back in 2 scanlines */
154154   timer_set(video_screen_get_time_until_pos(machine->primary_screen, next_scanline, 0), NULL, next_scanline, scanline_callback);
155155}
156156
157157
158static void timer_ack_callback(void)
158static void timer_ack_callback(running_machine *machine)
159159{
160160   /* clear the timer IRQ */
161161   timer_irq_state = 0;
162   update_main_irqs();
162   update_main_irqs(machine);
163163}
164164
165165
r2724r2725
183183}
184184
185185
186static void sound_cpu_irq(int state)
186static void sound_cpu_irq(running_machine *machine, int state)
187187{
188   cpunum_set_input_line(Machine, 2, 0, state);
188   cpunum_set_input_line(machine, 2, 0, state);
189189}
190190
191191
src/mame/drivers/nbmj9195.c
r2724r2725
2020******************************************************************************/
2121
2222#include "driver.h"
23#include "deprecat.h"
2423#include "machine/z80ctc.h"
2524#include "sound/3812intf.h"
2625#include "sound/dac.h"
r2724r2725
487486static WRITE8_HANDLER( tmpz84c011_1_dir_pe_w )   { pio_dir[9] = data; }
488487
489488
490static void ctc0_interrupt(int state)
489static void ctc0_interrupt(running_machine *machine, int state)
491490{
492   cpunum_set_input_line(Machine, 0, 0, state);
491   cpunum_set_input_line(machine, 0, 0, state);
493492}
494493
495static void ctc1_interrupt(int state)
494static void ctc1_interrupt(running_machine *machine, int state)
496495{
497   cpunum_set_input_line(Machine, 1, 0, state);
496   cpunum_set_input_line(machine, 1, 0, state);
498497}
499498
500499/* CTC of main cpu, ch0 trigger is vblank */
src/mame/drivers/hcastle.c
r2724r2725
77***************************************************************************/
88
99#include "driver.h"
10#include "deprecat.h"
1110#include "cpu/konami/konami.h"
1211#include "cpu/z80/z80.h"
1312#include "sound/3812intf.h"
r2724r2725
242241
243242/*****************************************************************************/
244243
245static void irqhandler(int linestate)
244static void irqhandler(running_machine *machine, int linestate)
246245{
247//  cpunum_set_input_line(Machine, 1,0,linestate);
246//  cpunum_set_input_line(machine, 1,0,linestate);
248247}
249248
250249static void volume_callback(int v)
src/mame/drivers/cliffhgr.c
r2724r2725
7575
7676#include "driver.h"
7777#include "render.h"
78#include "deprecat.h"
7978#include "machine/laserdsc.h"
8079#include "video/tms9928a.h"
8180#include "sound/discrete.h"
r2724r2725
228227{
229228   /* clock the laserdisc and video chip every 60Hz */
230229   laserdisc_vsync(discinfo);
231   TMS9928A_interrupt();
230   TMS9928A_interrupt(machine);
232231}
233232
234233static TIMER_CALLBACK( cliff_irq_callback )
r2724r2725
255254   timer_adjust_oneshot(irq_timer, video_screen_get_time_until_pos(machine->primary_screen, param, 0), param);
256255}
257256
258static void vdp_interrupt (int state)
257static void vdp_interrupt (running_machine *machine, int state)
259258{
260   cpunum_set_input_line(Machine, 0, INPUT_LINE_NMI, state ? ASSERT_LINE : CLEAR_LINE );
259   cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, state ? ASSERT_LINE : CLEAR_LINE );
261260}
262261
263262
src/mame/drivers/artmagic.c
r2724r2725
144144   if (activecpu_get_pc() == 0x18c2)
145145   {
146146      hack_irq = 1;
147      update_irq_state(Machine);
147      update_irq_state(machine);
148148      hack_irq = 0;
149      update_irq_state(Machine);
149      update_irq_state(machine);
150150   }
151151   return input_port_read_indexed(machine, 0);
152152}
r2724r2725
401401      prot_bit_index = 0;
402402
403403      /* update the protection state */
404      (*protection_handler)(Machine);
404      (*protection_handler)(machine);
405405   }
406406}
407407
src/mame/drivers/twincobr.c
r2724r2725
188188
189189
190190#include "driver.h"
191#include "deprecat.h"
192191#include "cpu/m68000/m68000.h"
193192#include "cpu/tms32010/tms32010.h"
194193#include "twincobr.h"
r2724r2725
634633
635634
636635/* handler called by the 3812 emulator when the internal timers cause an IRQ */
637static void irqhandler(int linestate)
636static void irqhandler(running_machine *machine, int linestate)
638637{
639   cpunum_set_input_line(Machine, 1,0,linestate);
638   cpunum_set_input_line(machine, 1,0,linestate);
640639}
641640
642641static const struct YM3812interface ym3812_interface =
src/mame/drivers/dblewing.c
r2724r2725
271271
272272   mame_printf_debug("dblewing prot r %08x, %04x, %04x\n",activecpu_get_pc(), offset*2, mem_mask);
273273
274   return 0;//mame_rand(Machine);
274   return 0;//mame_rand(machine);
275275}
276276
277277static WRITE16_HANDLER( dblewing_prot_w )
r2724r2725
526526
527527INPUT_PORTS_END
528528
529static void sound_irq(int irq)
529static void sound_irq(running_machine *machine, int irq)
530530{
531//  cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
531//  cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
532532//  mame_printf_debug("sound irq\n");
533533}
534534
src/mame/drivers/hornet.c
r2724r2725
486486
487487static int voodoo_version = 0;
488488
489static void voodoo_vblank_0(int param)
489static void voodoo_vblank_0(running_machine *machine, int param)
490490{
491   cpunum_set_input_line(Machine, 0, INPUT_LINE_IRQ0, ASSERT_LINE);
491   cpunum_set_input_line(machine, 0, INPUT_LINE_IRQ0, ASSERT_LINE);
492492}
493493
494static void voodoo_vblank_1(int param)
494static void voodoo_vblank_1(running_machine *machine, int param)
495495{
496   cpunum_set_input_line(Machine, 0, INPUT_LINE_IRQ1, ASSERT_LINE);
496   cpunum_set_input_line(machine, 0, INPUT_LINE_IRQ1, ASSERT_LINE);
497497}
498498
499499static void hornet_exit(running_machine *machine)
r2724r2725
11661166   jamma_jvs_cmd_exec();
11671167}
11681168
1169static void sound_irq_callback(int irq)
1169static void sound_irq_callback(running_machine *machine, int irq)
11701170{
11711171   if (irq == 0)
1172      cpunum_set_input_line(Machine, 1, INPUT_LINE_IRQ1, PULSE_LINE);
1172      cpunum_set_input_line(machine, 1, INPUT_LINE_IRQ1, PULSE_LINE);
11731173   else
1174      cpunum_set_input_line(Machine, 1, INPUT_LINE_IRQ2, PULSE_LINE);
1174      cpunum_set_input_line(machine, 1, INPUT_LINE_IRQ2, PULSE_LINE);
11751175}
11761176
11771177static UINT8 backup_ram[0x2000];
src/mame/drivers/pipedrm.c
r2724r2725
104104
105105
106106#include "driver.h"
107#include "deprecat.h"
108107#include "cpu/z80/z80.h"
109108#include "fromance.h"
110109#include "sound/2608intf.h"
r2724r2725
525524 *
526525 *************************************/
527526
528static void irqhandler(int irq)
527static void irqhandler(running_machine *machine, int irq)
529528{
530   cpunum_set_input_line(Machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
529   cpunum_set_input_line(machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
531530}
532531
533532
534533static const struct YM2608interface ym2608_interface =
535534{
536535   {
537      AY8910_LEGACY_OUTPUT,
536      AY8910_LEGACY_OUTPUT | AY8910_SINGLE_OUTPUT,
538537      AY8910_DEFAULT_LOADS,
539538      NULL, NULL, NULL, NULL
540539   },
src/mame/drivers/ccastles.c
r2724r2725
187187
188188static CUSTOM_INPUT( get_vblank )
189189{
190   int scanline = video_screen_get_vpos(machine->primary_screen);
190   int scanline = video_screen_get_vpos(field->port->machine->primary_screen);
191191   return syncprom[scanline & 0xff] & 1;
192192}
193193
src/mame/drivers/ddragon3.c
r2724r2725
475475
476476/* Sound Interfaces */
477477
478static void dd3_ymirq_handler(int irq)
478static void dd3_ymirq_handler(running_machine *machine, int irq)
479479{
480   cpunum_set_input_line(Machine, 1, 0 , irq ? ASSERT_LINE : CLEAR_LINE );
480   cpunum_set_input_line(machine, 1, 0 , irq ? ASSERT_LINE : CLEAR_LINE );
481481}
482482
483483static const struct YM2151interface ym2151_interface =
src/mame/drivers/discoboy.c
r2724r2725
253253      printf( "unk rb2_r\n");
254254   }
255255
256   return mame_rand(Machine);
256   return mame_rand(machine);
257257}
258258
259259static WRITE8_HANDLER( rambank2_w )
r2724r2725
336336//  adpcm_data = data;
337337//}
338338
339static void splash_msm5205_int(int data)
339static void splash_msm5205_int(running_machine *machine, int data)
340340{
341341   MSM5205_data_w(0,adpcm_data >> 4);
342342//  adpcm_data = (adpcm_data << 4) & 0xf0;
src/mame/drivers/seibuspi.c
r2724r2725
669669*/
670670
671671#include "driver.h"
672#include "deprecat.h"
673672#include "machine/ds2404.h"
674673#include "machine/eeprom.h"
675674#include "machine/intelfsh.h"
r2724r2725
11051104   }
11061105}
11071106
1108static void irqhandler(int state)
1107static void irqhandler(running_machine *machine, int state)
11091108{
11101109   if (state)
1111      cpunum_set_input_line_and_vector(Machine, 1, 0, ASSERT_LINE, 0xd7);   // IRQ is RST10
1110      cpunum_set_input_line_and_vector(machine, 1, 0, ASSERT_LINE, 0xd7);   // IRQ is RST10
11121111   else
1113      cpunum_set_input_line(Machine, 1, 0, CLEAR_LINE);
1112      cpunum_set_input_line(machine, 1, 0, CLEAR_LINE);
11141113}
11151114
11161115static const struct YMF271interface ymf271_interface =
src/mame/drivers/drmicro.c
r2724r2725
4545
4646static int pcm_adr;
4747
48static void pcm_w(int irq)
48static void pcm_w(running_machine *machine, int irq)
4949{
5050   UINT8 *PCM = memory_region(REGION_SOUND1);
5151
r2724r2725
6868static WRITE8_HANDLER( pcm_set_w )
6969{
7070   pcm_adr = ((data & 0x3f) << 9);
71   pcm_w(0);
71   pcm_w(machine, 0);
7272}
7373
7474/****************************************************************************/
src/mame/drivers/tetriunk.c
r2724r2725
99*/
1010
1111#include "driver.h"
12#include "deprecat.h"
1312
1413static int crtindex;
1514static int crtdata[256];
r2724r2725
2120
2221static READ8_HANDLER( tetriunk_random_r )
2322{
24   return mame_rand(Machine);
23   return mame_rand(machine);
2524}
2625
2726static WRITE8_HANDLER(crt_index_w)
src/mame/drivers/powerins.c
r2724r2725
2525***************************************************************************/
2626
2727#include "driver.h"
28#include "deprecat.h"
2928#include "machine/nmk112.h"
3029#include "sound/okim6295.h"
3130#include "sound/2203intf.h"
r2724r2725
333332}
334333
335334
336static void irqhandler(int irq)
335static void irqhandler(running_machine *machine, int irq)
337336{
338   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
337   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
339338}
340339
341340static const struct YM2203interface ym2203_interface =
src/mame/drivers/niyanpai.c
r2724r2725
3333******************************************************************************/
3434
3535#include "driver.h"
36#include "deprecat.h"
3736#include "machine/m68kfmly.h"
3837#include "machine/z80ctc.h"
3938#include "nb1413m3.h"
r2724r2725
185184static WRITE8_HANDLER( tmpz84c011_0_dir_pe_w )   { pio_dir[4] = data; }
186185
187186
188static void ctc0_interrupt(int state)
187static void ctc0_interrupt(running_machine *machine, int state)
189188{
190   cpunum_set_input_line(Machine, 1, 0, state);
189   cpunum_set_input_line(machine, 1, 0, state);
191190}
192191
193192static z80ctc_interface ctc_intf =
src/mame/drivers/bfm_sc2.c
r2724r2725
137137***************************************************************************/
138138
139139#include "driver.h"
140#include "deprecat.h"
141140#include "cpu/m6809/m6809.h"
142141
143142#include "video/bfm_adr2.h"
r2724r2725
512511      watchdog_cnt++;
513512      if ( watchdog_cnt > 2 )   // this is a hack, i don't know what the watchdog timeout is, 3 IRQ's works fine
514513      {  // reset board
515         mame_schedule_soft_reset(Machine);      // reset entire machine. CPU 0 should be enough, but that doesn't seem to work !!
514         mame_schedule_soft_reset(machine);      // reset entire machine. CPU 0 should be enough, but that doesn't seem to work !!
516515         on_scorpion2_reset();
517516         return;
518517      }
src/mame/drivers/suprnova.c
r2724r2725
12331233      ROM_LOAD( "gs230000.u1",  0x000000, 0x400000, CRC(0348e8e1) SHA1(8a21c7e5cea0bc08a2595213d689c58c0251fdb5) )
12341234ROM_END
12351235
1236/*
1237
1238Gals Panic SU (Kaneko 1999)
1239Korean hacked version. Runs on Super Kaneko Nova System mainboard
1240and original Super Kaneko Nova System ROM board labelled "ROM-BOARD"
1241EPROMs at U8, U10 and mainboard U10 are new to this version.
1242The ROM board is wired to accept 16MBit SOP44 maskROMs.
1243The actual ROMs used are 32M. There are some wire mods to enable the
1244higher capacity ROMs, basically wiring pin 44 of the SOP44's to
1245some logic to enable it.
1246All of the SOP44 ROMs are from Gals Panic 2, but because Gals Panic 2
1247uses a different ROM board the Gals Panic SU ROMs are at different
1248locations.
1249For Gals Panic SU, the 32M ROMs can be taken from the existing
1250Gals Panic 2 set.
1251
1252*/
1253
1254ROM_START( galpansu )
1255   ROM_REGION( 0x080000, REGION_CPU1, 0 ) /* SH-2 Code */
1256   ROM_LOAD       ( "bios.u10",   0x000000, 0x080000, CRC(161fb79e) SHA1(dfb5517de3a14a94344e0f58bbe90b69c5cb5b57) ) /* Korea BIOS */
1257
1258   ROM_REGION32_BE( 0x200000, REGION_USER1, 0 ) /* SH-2 Code mapped at 0x04000000 */
1259    ROM_LOAD16_BYTE( "su.u10",    0x000000, 0x100000, CRC(5ae66218) SHA1(c3f32603e1da945efb984ff99e1a30202e535773) )
1260    ROM_LOAD16_BYTE( "su.u8",     0x000001, 0x100000, CRC(10977a03) SHA1(2ab95398d6b88d8819f368ee6104d7f8b485778d) )
1261
1262   /* the rest of the roms match Gals Panic S2, but are in different locations */
1263   ROM_REGION( 0x1000000, REGION_GFX1, 0 )
1264    ROM_LOAD( "24", 0x000000, 0x400000, CRC(294b2f14) SHA1(90cbd0acdaa2d89d208c28aae33ab57c03624089) )
1265    ROM_LOAD( "20", 0x400000, 0x400000, CRC(f75c5a9a) SHA1(3919643cee6c88185a1aa3c58c5bc80599bf734e) )
1266    ROM_LOAD( "17",  0x800000, 0x400000, CRC(25b4f56b) SHA1(f9a33d5ed54a04ecece3035e75508d191bbe74b1) )
1267    ROM_LOAD( "32", 0xc00000, 0x400000, CRC(db6d4424) SHA1(0a88dafd0ee2490ff2ef39ce8eb1931c41bdda42) )
1268
1269   ROM_REGION( 0x800000, REGION_GFX2, ROMREGION_DISPOSE )
1270    ROM_LOAD( "16", 0x000000, 0x400000, CRC(5caae1c0) SHA1(8f77e4cf018d7290b2d804cbff9fccf0bf4d2404) )
1271    ROM_LOAD( "13",  0x400000, 0x400000, CRC(8d51f197) SHA1(19d2afab823ea179918e7bcbf4df2283e77570f0) )
1272
1273   ROM_REGION( 0x800000, REGION_GFX3, ROMREGION_ERASE00 ) /* Tiles Plane B */
1274   /* First 0x040000 bytes (0x03ff Tiles) are RAM Based Tiles */
1275   /* 0x040000 - 0x3fffff empty? */
1276    ROM_LOAD( "7",  0x400000, 0x400000, CRC(58800a18) SHA1(5e6d55ecd12275662d6f59559e137b759f23fff6) )
1277
1278   ROM_REGION( 0x400000, REGION_SOUND1, 0 ) /* Samples */
1279      ROM_LOAD( "4",  0x000000, 0x400000, CRC(0348e8e1) SHA1(8a21c7e5cea0bc08a2595213d689c58c0251fdb5) )
1280ROM_END
1281
1282
12361283ROM_START( gutsn )
12371284   ROM_REGION( 0x080000, REGION_CPU1, 0 ) /* SH-2 Code */
12381285   ROM_LOAD       ( "sknsj1.u10",   0x000000, 0x080000, CRC(7e2b836c) SHA1(92c5a7a2472496028bff0e5980d41dd294f42144) ) /* Japan BIOS */
r2724r2725
16041651GAME( 1997, galpanis, skns,    skns, galpanis, galpanis, ROT0,  "Kaneko", "Gals Panic S - Extra Edition (Japan)", GAME_IMPERFECT_GRAPHICS )
16051652GAME( 1998, cyvern,   skns,    skns, cyvern,   cyvern,   ROT90, "Kaneko", "Cyvern (Japan)", GAME_IMPERFECT_GRAPHICS )
16061653GAME( 1999, galpans2, skns,    skns, galpanis, galpans2, ROT0,  "Kaneko", "Gals Panic S2 (Japan)", GAME_IMPERFECT_GRAPHICS )
1654GAME( 1999, galpansu, galpans2,skns, galpanis, galpans2, ROT0,  "Kaneko", "Gals Panic SU (Korea)", GAME_IMPERFECT_GRAPHICS ) // official or hack?
16071655GAME( 1999, panicstr, skns,    skns, galpanis, panicstr, ROT0,  "Kaneko", "Panic Street (Japan)", GAME_IMPERFECT_GRAPHICS )
16081656GAME( 1999, senknow , skns,    skns, skns,     senknow,  ROT0,  "Kaneko / Kouyousha", "Sen-Know (Japan)", GAME_IMPERFECT_GRAPHICS )
16091657GAME( 2000, gutsn,    skns,    skns, skns,     gutsn,    ROT0,  "Kaneko / Kouyousha", "Guts'n (Japan)", GAME_IMPERFECT_GRAPHICS ) // quite fragile, started working of it's own accord in 0.69 :)
src/mame/drivers/seta2.c
r2724r2725
686686
687687static READ16_HANDLER( pzlbowl_coins_r )
688688{
689   return input_port_read_indexed(machine, 4) | (mame_rand(Machine) & 0x80 );
689   return input_port_read_indexed(machine, 4) | (mame_rand(machine) & 0x80 );
690690}
691691
692692static WRITE16_HANDLER( pzlbowl_coin_counter_w )
r2724r2725
17851785   {
17861786      case 0:
17871787         /* VBlank is connected to INT0 (external interrupts pin 0) */
1788         tmp68301_external_interrupt_0();
1788         tmp68301_external_interrupt_0(machine);
17891789         break;
17901790   }
17911791}
r2724r2725
17951795   switch ( cpu_getiloops() )
17961796   {
17971797      case 0:
1798         tmp68301_external_interrupt_0();   // vblank
1798         tmp68301_external_interrupt_0(machine);   // vblank
17991799         break;
18001800      case 1:
1801         tmp68301_external_interrupt_2();   // to do: hook up x1-10 interrupts
1801         tmp68301_external_interrupt_2(machine);   // to do: hook up x1-10 interrupts
18021802         break;
18031803   }
18041804}
src/mame/drivers/dynax.c
r2724r2725
9999static UINT8 dynax_vblank_irq;
100100
101101/* It runs in IM 0, thus needs an opcode on the data bus */
102void sprtmtch_update_irq(void)
102void sprtmtch_update_irq(running_machine *machine)
103103{
104104   int irq   =   ((dynax_sound_irq)   ? 0x08 : 0) |
105105            ((dynax_vblank_irq)  ? 0x10 : 0) |
106106            ((dynax_blitter_irq) ? 0x20 : 0) ;
107   cpunum_set_input_line_and_vector(Machine, 0, 0, irq ? ASSERT_LINE : CLEAR_LINE, 0xc7 | irq); /* rst $xx */
107   cpunum_set_input_line_and_vector(machine, 0, 0, irq ? ASSERT_LINE : CLEAR_LINE, 0xc7 | irq); /* rst $xx */
108108}
109109
110110static WRITE8_HANDLER( dynax_vblank_ack_w )
111111{
112112   dynax_vblank_irq = 0;
113   sprtmtch_update_irq();
113   sprtmtch_update_irq(machine);
114114}
115115
116116static WRITE8_HANDLER( dynax_blitter_ack_w )
117117{
118118   dynax_blitter_irq = 0;
119   sprtmtch_update_irq();
119   sprtmtch_update_irq(machine);
120120}
121121
122122static INTERRUPT_GEN( sprtmtch_vblank_interrupt )
123123{
124124   dynax_vblank_irq = 1;
125   sprtmtch_update_irq();
125   sprtmtch_update_irq(machine);
126126}
127127
128static void sprtmtch_sound_callback(int state)
128static void sprtmtch_sound_callback(running_machine *machine, int state)
129129{
130130   dynax_sound_irq = state;
131   sprtmtch_update_irq();
131   sprtmtch_update_irq(machine);
132132}
133133
134134
r2724r2725
139139UINT8 dynax_blitter2_irq;
140140
141141/* It runs in IM 0, thus needs an opcode on the data bus */
142void jantouki_update_irq(void)
142void jantouki_update_irq(running_machine *machine)
143143{
144144   int irq   =   ((dynax_blitter_irq)   ? 0x08 : 0) |
145145            ((dynax_blitter2_irq)   ? 0x10 : 0) |
146146            ((dynax_vblank_irq)      ? 0x20 : 0) ;
147   cpunum_set_input_line_and_vector(Machine, 0, 0, irq ? ASSERT_LINE : CLEAR_LINE, 0xc7 | irq); /* rst $xx */
147   cpunum_set_input_line_and_vector(machine, 0, 0, irq ? ASSERT_LINE : CLEAR_LINE, 0xc7 | irq); /* rst $xx */
148148}
149149
150150static WRITE8_HANDLER( jantouki_vblank_ack_w )
151151{
152152   dynax_vblank_irq = 0;
153   jantouki_update_irq();
153   jantouki_update_irq(machine);
154154}
155155
156156static WRITE8_HANDLER( jantouki_blitter_ack_w )
157157{
158158   dynax_blitter_irq = data;
159   jantouki_update_irq();
159   jantouki_update_irq(machine);
160160}
161161
162162static WRITE8_HANDLER( jantouki_blitter2_ack_w )
163163{
164164   dynax_blitter2_irq = data;
165   jantouki_update_irq();
165   jantouki_update_irq(machine);
166166}
167167
168168static INTERRUPT_GEN( jantouki_vblank_interrupt )
169169{
170170   dynax_vblank_irq = 1;
171   jantouki_update_irq();
171   jantouki_update_irq(machine);
172172}
173173
174174
r2724r2725
179179static UINT8 dynax_soundlatch_irq;
180180static UINT8 dynax_sound_vblank_irq;
181181
182static void jantouki_sound_update_irq(void)
182static void jantouki_sound_update_irq(running_machine *machine)
183183{
184184   int irq   =   ((dynax_sound_irq)         ? 0x08 : 0) |
185185            ((dynax_soundlatch_irq)      ? 0x10 : 0) |
186186            ((dynax_sound_vblank_irq)   ? 0x20 : 0) ;
187   cpunum_set_input_line_and_vector(Machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE, 0xc7 | irq); /* rst $xx */
187   cpunum_set_input_line_and_vector(machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE, 0xc7 | irq); /* rst $xx */
188188}
189189
190190static INTERRUPT_GEN( jantouki_sound_vblank_interrupt )
191191{
192192   dynax_sound_vblank_irq = 1;
193   jantouki_sound_update_irq();
193   jantouki_sound_update_irq(machine);
194194}
195195
196196static WRITE8_HANDLER( jantouki_sound_vblank_ack_w )
197197{
198198   dynax_sound_vblank_irq = 0;
199   jantouki_sound_update_irq();
199   jantouki_sound_update_irq(machine);
200200}
201201
202static void jantouki_sound_callback(int state)
202static void jantouki_sound_callback(running_machine *machine, int state)
203203{
204204   dynax_sound_irq = state;
205   jantouki_sound_update_irq();
205   jantouki_sound_update_irq(machine);
206206}
207207
208208
r2724r2725
396396static int msm5205next;
397397static int resetkludge;
398398
399static void adpcm_int(int data)
399static void adpcm_int(running_machine *machine, int data)
400400{
401401   static int toggle;
402402
r2724r2725
407407   if (toggle)
408408   {
409409      if (resetkludge)   // don't know what's wrong, but NMIs when the 5205 is reset make the game crash
410      cpunum_set_input_line(Machine, 0, INPUT_LINE_NMI, PULSE_LINE);
410      cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, PULSE_LINE);
411411   }
412412}
413static void adpcm_int_cpu1(int data)
413static void adpcm_int_cpu1(running_machine *machine, int data)
414414{
415415   static int toggle;
416416
r2724r2725
421421   if (toggle)
422422   {
423423      if (resetkludge)   // don't know what's wrong, but NMIs when the 5205 is reset make the game crash
424      cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, PULSE_LINE);   // cpu1
424      cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, PULSE_LINE);   // cpu1
425425   }
426426}
427427
r2724r2725
863863   dynax_soundlatch_full = 1;
864864   dynax_soundlatch_irq = 1;
865865   latch = data;
866   jantouki_sound_update_irq();
866   jantouki_sound_update_irq(machine);
867867}
868868
869869static READ8_HANDLER( jantouki_blitter_busy_r )
r2724r2725
919919{
920920   dynax_soundlatch_ack = data;
921921   dynax_soundlatch_irq = 0;
922   jantouki_sound_update_irq();
922   jantouki_sound_update_irq(machine);
923923}
924924
925925static READ8_HANDLER( jantouki_soundlatch_r )
r2724r2725
38293829      dynax_sound_irq = 1;
38303830   }
38313831
3832   sprtmtch_update_irq();
3832   sprtmtch_update_irq(machine);
38333833}
38343834
38353835static MACHINE_DRIVER_START( yarunara )
r2724r2725
39703970/*  It runs in IM 2, thus needs a vector on the data bus:
39713971    0xfa and 0xfc are very similar, they should be triggered by the blitter
39723972    0xf8 is vblank  */
3973void mjelctrn_update_irq(void)
3973void mjelctrn_update_irq(running_machine *machine)
39743974{
39753975   dynax_blitter_irq = 1;
3976   cpunum_set_input_line_and_vector(Machine, 0, 0, HOLD_LINE, 0xfa);
3976   cpunum_set_input_line_and_vector(machine, 0, 0, HOLD_LINE, 0xfa);
39773977}
39783978
39793979static INTERRUPT_GEN( mjelctrn_vblank_interrupt )
r2724r2725
40044004    0x42 and 0x44 are very similar, they should be triggered by the blitter
40054005    0x40 is vblank
40064006    0x46 is a periodic irq? */
4007void neruton_update_irq(void)
4007void neruton_update_irq(running_machine *machine)
40084008{
40094009   dynax_blitter_irq = 1;
4010   cpunum_set_input_line_and_vector(Machine, 0, 0, HOLD_LINE, 0x42);
4010   cpunum_set_input_line_and_vector(machine, 0, 0, HOLD_LINE, 0x42);
40114011}
40124012
40134013static INTERRUPT_GEN( neruton_vblank_interrupt )
src/mame/drivers/shootout.c
r2724r2725
3838*/
3939
4040#include "driver.h"
41#include "deprecat.h"
4241#include "cpu/m6502/m6502.h"
4342#include "sound/2203intf.h"
4443
r2724r2725
263262   GFXDECODE_ENTRY( REGION_GFX3, 0, tile_layout,   0,      16 ) /* tiles */
264263GFXDECODE_END
265264
266static void shootout_snd_irq(int linestate)
265static void shootout_snd_irq(running_machine *machine, int linestate)
267266{
268   cpunum_set_input_line(Machine, 1,0,linestate);
267   cpunum_set_input_line(machine, 1,0,linestate);
269268}
270269
271static void shootout_snd2_irq(int linestate)
270static void shootout_snd2_irq(running_machine *machine, int linestate)
272271{
273   cpunum_set_input_line(Machine, 0,0,linestate);
272   cpunum_set_input_line(machine, 0,0,linestate);
274273}
275274
276275static const struct YM2203interface ym2203_interface =
src/mame/drivers/zn.c
r2724r2725
199199   {
200200      if( m_b_lastclock )
201201      {
202         psx_sio_input( 0, PSX_SIO_IN_DATA, ( znsec_step( 0, ( n_data & PSX_SIO_OUT_DATA ) / PSX_SIO_OUT_DATA ) & 1 ) * PSX_SIO_IN_DATA );
202         psx_sio_input( Machine, 0, PSX_SIO_IN_DATA, ( znsec_step( 0, ( n_data & PSX_SIO_OUT_DATA ) / PSX_SIO_OUT_DATA ) & 1 ) * PSX_SIO_IN_DATA );
203203      }
204204      m_b_lastclock = 0;
205205   }
r2724r2725
215215   {
216216      if( m_b_lastclock )
217217      {
218         psx_sio_input( 0, PSX_SIO_IN_DATA, ( znsec_step( 1, ( n_data & PSX_SIO_OUT_DATA ) / PSX_SIO_OUT_DATA ) & 1 ) * PSX_SIO_IN_DATA );
218         psx_sio_input( Machine, 0, PSX_SIO_IN_DATA, ( znsec_step( 1, ( n_data & PSX_SIO_OUT_DATA ) / PSX_SIO_OUT_DATA ) & 1 ) * PSX_SIO_IN_DATA );
219219      }
220220      m_b_lastclock = 0;
221221   }
r2724r2725
237237   }
238238
239239   verboselog( 2, "read pad %04x %04x %02x\n", m_n_znsecsel, m_b_znsecport, n_data );
240   psx_sio_input( 0, PSX_SIO_IN_DATA | PSX_SIO_IN_DSR, PSX_SIO_IN_DATA | PSX_SIO_IN_DSR );
240   psx_sio_input( Machine, 0, PSX_SIO_IN_DATA | PSX_SIO_IN_DSR, PSX_SIO_IN_DATA | PSX_SIO_IN_DSR );
241241}
242242
243243static void sio_dip_handler( int n_data )
r2724r2725
247247      if( m_b_lastclock )
248248      {
249249         verboselog( 2, "read dip %02x -> %02x\n", n_data, ( ( input_port_read_indexed(Machine,  7 ) >> m_n_dip_bit ) & 1 ) * PSX_SIO_IN_DATA );
250         psx_sio_input( 0, PSX_SIO_IN_DATA, ( ( input_port_read_indexed(Machine,  7 ) >> m_n_dip_bit ) & 1 ) * PSX_SIO_IN_DATA );
250         psx_sio_input( Machine, 0, PSX_SIO_IN_DATA, ( ( input_port_read_indexed(Machine,  7 ) >> m_n_dip_bit ) & 1 ) * PSX_SIO_IN_DATA );
251251         m_n_dip_bit++;
252252         m_n_dip_bit &= 7;
253253      }
r2724r2725
391391   n_game = 0;
392392   while( zn_config_table[ n_game ].s_name != NULL )
393393   {
394      if( strcmp( Machine->gamedrv->name, zn_config_table[ n_game ].s_name ) == 0 )
394      if( strcmp( machine->gamedrv->name, zn_config_table[ n_game ].s_name ) == 0 )
395395      {
396396         znsec_init( 0, zn_config_table[ n_game ].p_n_mainsec );
397397         znsec_init( 1, zn_config_table[ n_game ].p_n_gamesec );
r2724r2725
12691269ADDRESS_MAP_END
12701270
12711271/* handler called by the YM2610 emulator when the internal timers cause an IRQ */
1272static void irq_handler(int irq)
1272static void irq_handler(running_machine *machine, int irq)
12731273{
1274   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
1274   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
12751275}
12761276
12771277static const struct YM2610interface ym2610_interface =
r2724r2725
16531653      *2                  - Unpopulated DIP28 socket
16541654*/
16551655
1656static void atpsx_interrupt(const device_config *config, int state)
1656static void atpsx_interrupt(const device_config *device, int state)
16571657{
16581658   if (state)
16591659   {
1660       psx_irq_set(0x400);
1660       psx_irq_set(device->machine, 0x400);
16611661   }
16621662}
16631663
r2724r2725
21172117{
21182118   if (state)
21192119   {
2120       psx_irq_set(0x400);
2120       psx_irq_set(device->machine, 0x400);
21212121   }
21222122}
21232123
r2724r2725
21812181static WRITE32_HANDLER( nbajamex_80_w )
21822182{
21832183   verboselog( 0, "nbajamex_80_w( %08x, %08x, %08x )\n", offset, data, mem_mask );
2184   psx_irq_set(0x400);
2184   psx_irq_set(machine, 0x400);
21852185}
21862186
21872187static READ32_HANDLER( nbajamex_08_r )
src/mame/drivers/volfied.c
r2724r2725
4040********************************************************************/
4141
4242#include "driver.h"
43#include "deprecat.h"
4443#include "taitoipt.h"
4544#include "video/taitoic.h"
4645#include "audio/taitosnd.h"
r2724r2725
215214
216215/* handler called by the YM2203 emulator when the internal timers cause an IRQ */
217216
218static void irqhandler(int irq)
217static void irqhandler(running_machine *machine, int irq)
219218{
220   cpunum_set_input_line(Machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
219   cpunum_set_input_line(machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
221220}
222221
223222static const struct YM2203interface ym2203_interface =
src/mame/drivers/megadriv.c
r2724r2725
5353
5454#define MEGADRIV_VDP_VRAM(address) megadrive_vdp_vram[(address)&0x7fff]
5555
56#ifdef MESS
57extern void setup_megadriv_custom_mappers(running_machine *);
58#endif
59
6056/* the same on all systems? */
6157#define MASTER_CLOCK      53693100
6258/* timing details */
r2724r2725
13051301      case 0x06:
13061302      //  if ((!ACCESSING_BITS_8_15) || (!ACCESSING_BITS_0_7)) mame_printf_debug("8-bit VDP read control port access, offset %04x mem_mask %04x\n",offset,mem_mask);
13071303         retvalue = megadriv_vdp_ctrl_port_r();
1308      //  retvalue = mame_rand(Machine);
1304      //  retvalue = mame_rand(machine);
13091305      //  mame_printf_debug("%06x: Read Control Port at scanline %d hpos %d (return %04x)\n",activecpu_get_pc(),genesis_scanline_counter, get_hposition(),retvalue);
13101306         break;
13111307
r2724r2725
13151311      case 0x0e:
13161312      //  if ((!ACCESSING_BITS_8_15) || (!ACCESSING_BITS_0_7)) mame_printf_debug("8-bit VDP read HV counter port access, offset %04x mem_mask %04x\n",offset,mem_mask);
13171313         retvalue = megadriv_read_hv_counters();
1318      //  retvalue = mame_rand(Machine);
1314      //  retvalue = mame_rand(machine);
13191315      //  mame_printf_debug("%06x: Read HV counters at scanline %d hpos %d (return %04x)\n",activecpu_get_pc(),genesis_scanline_counter, get_hposition(),retvalue);
13201316         break;
13211317
r2724r2725
19711967          D0 : Bit 0 of version number
19721968      */
19731969
1974   //return (mame_rand(Machine)&0x0f0f)|0xf0f0;//0x0000;
1970   //return (mame_rand(machine)&0x0f0f)|0xf0f0;//0x0000;
19751971   switch (offset)
19761972   {
19771973      case 0:
r2724r2725
21822178   else
21832179   {
21842180      logerror("%06x: 68000 attempting to access Z80 (read) address space without bus\n", activecpu_get_pc());
2185      return mame_rand(Machine);
2181      return mame_rand(machine);
21862182   }
21872183}
21882184
r2724r2725
22242220       the value is never zero.  Time Killers is the most fussy, and doesn't like the
22252221       read_next_instruction function from system16, so I just return a random value
22262222       in the unused bits */
2227   UINT16 nextvalue = mame_rand(Machine);//read_next_instruction()&0xff00;
2223   UINT16 nextvalue = mame_rand(machine);//read_next_instruction()&0xff00;
22282224
22292225
22302226   /* Check if the 68k has the z80 bus */
r2724r2725
24352431static READ8_HANDLER( megadriv_z80_vdp_read )
24362432{
24372433   mame_printf_debug("megadriv_z80_vdp_read %02x\n",offset);
2438   return mame_rand(Machine);
2434   return mame_rand(machine);
24392435}
24402436
24412437static READ8_HANDLER( megadriv_z80_unmapped_read )
r2724r2725
24762472
24772473static READ16_HANDLER( _32x_reg_r )
24782474{
2479   return mame_rand(Machine);
2475   return mame_rand(machine);
24802476}
24812477
24822478static UINT16 _32x_68k_comms[0x8];
r2724r2725
43204316
43214317            case 0xa000: // shadow set, highlight set - not possible
43224318            case 0xe000: // shadow set, highlight set, normal set, not possible
4323               lineptr[x] = megadrive_vdp_palette_lookup_highlight[mame_rand(Machine)&0x3f];
4319               lineptr[x] = megadrive_vdp_palette_lookup_highlight[mame_rand(machine)&0x3f];
43244320               break;
43254321
43264322
r2724r2725
48204816
48214817   memset(megadrive_ram,0x00,0x10000);
48224818
4823#ifdef MESS
4824   setup_megadriv_custom_mappers(machine);
4825#endif
48264819
48274820}
48284821
r2724r2725
50125005         {
50135006            int x;
50145007            for (x=0;x<megadriv_backupram_length/2;x++)
5015               megadriv_backupram[x]=0xffff;//mame_rand(Machine); // dino dini's needs 0xff or game rules are broken
5008               megadriv_backupram[x]=0xffff;//mame_rand(machine); // dino dini's needs 0xff or game rules are broken
50165009         }
50175010      }
50185011   }
src/mame/drivers/itech32.c
r2724r2725
631631 *
632632 *************************************/
633633
634static void via_irq(int state)
634static void via_irq(running_machine *machine, int state)
635635{
636636   if (state)
637      cpunum_set_input_line(Machine, 1, M6809_FIRQ_LINE, ASSERT_LINE);
637      cpunum_set_input_line(machine, 1, M6809_FIRQ_LINE, ASSERT_LINE);
638638   else
639      cpunum_set_input_line(Machine, 1, M6809_FIRQ_LINE, CLEAR_LINE);
639      cpunum_set_input_line(machine, 1, M6809_FIRQ_LINE, CLEAR_LINE);
640640}
641641
642642
r2724r2725
781781   else
782782   {
783783      for (i = 0x80; i < main_ram_size; i++)
784         ((UINT8 *)main_ram)[i] = mame_rand(Machine);
784         ((UINT8 *)main_ram)[i] = mame_rand(machine);
785785
786786      /* due to accessing uninitialized RAM, we need this hack */
787787      if (is_drivedge)
r2724r2725
801801   else
802802   {
803803      for (i = 0; i < nvram_size; i++)
804         ((UINT8 *)nvram)[i] = mame_rand(Machine);
804         ((UINT8 *)nvram)[i] = mame_rand(machine);
805805   }
806806}
807807
src/mame/drivers/fitfight.c
r2724r2725
8282*/
8383
8484#include "driver.h"
85#include "deprecat.h"
8685#include "cpu/upd7810/upd7810.h"
8786#include "sound/okim6295.h"
8887
r2724r2725
234233static READ8_HANDLER(snd_porta_r)
235234{
236235   //mame_printf_debug("PA R @%x\n",activecpu_get_pc());
237   return mame_rand(Machine);
236   return mame_rand(machine);
238237}
239238
240239static READ8_HANDLER(snd_portb_r)
241240{
242241   //mame_printf_debug("PB R @%x\n",activecpu_get_pc());
243   return mame_rand(Machine);
242   return mame_rand(machine);
244243}
245244
246245static READ8_HANDLER(snd_portc_r)
247246{
248247   //mame_printf_debug("PC R @%x\n",activecpu_get_pc());
249   return mame_rand(Machine);
248   return mame_rand(machine);
250249}
251250
252251static WRITE8_HANDLER(snd_porta_w)
src/mame/drivers/filetto.c
r2724r2725
381381
382382static READ8_HANDLER( kludge_r )
383383{
384   return mame_rand(Machine);
384   return mame_rand(machine);
385385}
386386
387387static PIT8253_OUTPUT_CHANGED( pc_timer0_w )
src/mame/drivers/ashnojoe.c
r2724r2725
7777*************************************************************************/
7878
7979#include "driver.h"
80#include "deprecat.h"
8180#include "sound/2203intf.h"
8281#include "sound/msm5205.h"
8382
r2724r2725
146145   /* FIXME: earlier attemts to remove ?
147146    return 1;
148147    return 0;
149    return mame_rand(Machine);
148    return mame_rand(machine);
150149    */
151150}
152151
r2724r2725
290289   GFXDECODE_ENTRY( REGION_GFX5, 0, tiles16x16_layout, 0, 0x100 )
291290GFXDECODE_END
292291
293static void irqhandler(int irq)
292static void irqhandler(running_machine *machine, int irq)
294293{
295   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
294   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
296295}
297296
298297static WRITE8_HANDLER(writeA)
r2724r2725
307306   memory_set_bankptr(4, memory_region(REGION_SOUND1) + ((data & 0xf) * 0x8000));
308307}
309308
310static void ashnojoe_adpcm_int (int data)
309static void ashnojoe_adpcm_int (running_machine *machine, int data)
311310{
312   cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, PULSE_LINE);
311   cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, PULSE_LINE);
313312}
314313
315314static const struct MSM5205interface msm5205_interface =
src/mame/drivers/undrfire.c
r2724r2725
600600   PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y ) PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(20) PORT_KEYDELTA(25) PORT_PLAYER(2)
601601
602602   PORT_START_TAG("FAKE")
603   PORT_BIT(    0x01, 0x00, IPT_DIPSWITCH_NAME ) PORT_NAME("Show gun target") PORT_CODE(KEYCODE_F1) PORT_TOGGLE
603   PORT_DIPNAME( 0x01, 0x00, "Show gun target" ) PORT_CODE(KEYCODE_F1) PORT_TOGGLE
604604   PORT_DIPSETTING(    0x00, DEF_STR( No ) )
605605   PORT_DIPSETTING(    0x01, DEF_STR( Yes ) )
606606INPUT_PORTS_END
r2724r2725
10241024GAME( 1993, undrfire, 0,        undrfire, undrfire, undrfire, ROT0, "Taito Corporation Japan", "Under Fire (World)", 0 )
10251025GAME( 1993, undrfiru, undrfire, undrfire, undrfire, undrfire, ROT0, "Taito America Corporation", "Under Fire (US)", 0 )
10261026GAME( 1993, undrfirj, undrfire, undrfire, undrfire, undrfire, ROT0, "Taito Corporation", "Under Fire (Japan)", 0 )
1027GAME( 1994, cbombers, 0,        cbombers, cbombers, cbombers, ROT0, "Taito Corporation", "Chase Bombers", 0 )
1027GAME( 1994, cbombers, 0,        cbombers, cbombers, cbombers, ROT0, "Taito Corporation", "Chase Bombers", GAME_IMPERFECT_GRAPHICS )
src/mame/drivers/deco32.c
r2724r2725
381381static READ32_HANDLER( lockload_gun_mirror_r )
382382{
383383//logerror("%08x:Read gun %d\n",activecpu_get_pc(),offset);
384//return ((mame_rand(Machine)%0xffff)<<16) | mame_rand(Machine)%0xffff;
384//return ((mame_rand(machine)%0xffff)<<16) | mame_rand(machine)%0xffff;
385385   if (offset) /* Mirror of player 1 and player 2 fire buttons */
386      return input_port_read_indexed(machine, 5) | ((mame_rand(Machine)%0xff)<<16);
387   return input_port_read_indexed(machine, 4) | input_port_read_indexed(machine, 6) | (input_port_read_indexed(machine, 6)<<16) | (input_port_read_indexed(machine, 6)<<24); //((mame_rand(Machine)%0xff)<<16);
386      return input_port_read_indexed(machine, 5) | ((mame_rand(machine)%0xff)<<16);
387   return input_port_read_indexed(machine, 4) | input_port_read_indexed(machine, 6) | (input_port_read_indexed(machine, 6)<<16) | (input_port_read_indexed(machine, 6)<<24); //((mame_rand(machine)%0xff)<<16);
388388}
389389
390390static READ32_HANDLER( dragngun_prot_r )
r2724r2725
17771777
17781778/**********************************************************************************/
17791779
1780static void sound_irq(int state)
1780static void sound_irq(running_machine *machine, int state)
17811781{
1782   cpunum_set_input_line(Machine, 1,1,state); /* IRQ 2 */
1782   cpunum_set_input_line(machine, 1,1,state); /* IRQ 2 */
17831783}
17841784
1785static void sound_irq_nslasher(int state)
1785static void sound_irq_nslasher(running_machine *machine, int state)
17861786{
17871787   /* bit 0 of nslasher_sound_irq specifies IRQ from sound chip */
17881788   if (state)
17891789      nslasher_sound_irq |= 0x01;
17901790   else
17911791      nslasher_sound_irq &= ~0x01;
1792   cpunum_set_input_line(Machine, 1, 0, (nslasher_sound_irq != 0) ? ASSERT_LINE : CLEAR_LINE);
1792   cpunum_set_input_line(machine, 1, 0, (nslasher_sound_irq != 0) ? ASSERT_LINE : CLEAR_LINE);
17931793}
17941794
17951795static WRITE8_HANDLER( sound_bankswitch_w )
src/mame/drivers/midzeus.c
r2724r2725
2525**************************************************************************/
2626
2727#include "driver.h"
28#include "deprecat.h"
2928#include "cpu/tms34010/tms34010.h"
3029#include "cpu/adsp2100/adsp2100.h"
3130#include "includes/midzeus.h"
r2724r2725
451450   static const UINT8 translate49[7] = { 0x8, 0xc, 0xe, 0xf, 0x3, 0x1, 0x0 };
452451   const char *namex = param;
453452   const char *namey = namex + strlen(namex) + 1;
454   return (translate49[input_port_read(machine, namey) >> 4] << 4) | translate49[input_port_read(machine, namex) >> 4];
453   return (translate49[input_port_read(field->port->machine, namey) >> 4] << 4) | translate49[input_port_read(field->port->machine, namex) >> 4];
455454}
456455
457456
r2724r2725
464463
465464static CUSTOM_INPUT( keypad_r )
466465{
467   UINT32 bits = input_port_read(machine, param);
466   UINT32 bits = input_port_read(field->port->machine, param);
468467   UINT8 select = keypad_select;
469468   while ((select & 1) != 0)
470469   {
r2724r2725
540539   /* bits 0-1 enable IRQs (?) */
541540   /* bits 2-3 reset IRQ states */
542541   gun_irq_state &= ~((gun_control >> 2) & 3);
543   update_gun_irq(Machine);
542   update_gun_irq(machine);
544543
545544   for (player = 0; player < 2; player++)
546545   {
src/mame/drivers/argus.c
r2724r2725
171171}
172172
173173/* Handler called by the YM2203 emulator when the internal timers cause an IRQ */
174static void irqhandler(int irq)
174static void irqhandler(running_machine *machine, int irq)
175175{
176   cpunum_set_input_line(Machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
176   cpunum_set_input_line(machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
177177}
178178
179179static const struct YM2203interface ym2203_interface =
r2724r2725
554554   PORT_DIPUNUSED_DIPLOC( 0x40, 0x40, "SW1:2" )         /* Listed as "Unused" */
555555   PORT_DIPUNUSED_DIPLOC( 0x80, 0x80, "SW1:1" )         /* Listed as "Unused" */
556556
557   PORT_START_TAG("DSW2")
557   PORT_MODIFY("DSW2")
558558   PORT_DIPNAME( 0x01, 0x01, DEF_STR( Flip_Screen ) )      PORT_DIPLOCATION("SW2:8")
559559   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
560560   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
src/mame/drivers/lkage.c
r2724r2725
2727***************************************************************************/
2828
2929#include "driver.h"
30#include "deprecat.h"
3130#include "cpu/z80/z80.h"
3231#include "cpu/m6805/m6805.h"
3332#include "sound/2203intf.h"
r2724r2725
309308   GFXDECODE_ENTRY( REGION_GFX1, 0x0000, sprite_layout,  0, 16 )
310309GFXDECODE_END
311310
312static void irqhandler(int irq)
311static void irqhandler(running_machine *machine, int irq)
313312{
314   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
313   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
315314}
316315
317316static const struct YM2203interface ym2203_interface =
src/mame/drivers/gaiden.c
r2724r2725
125125
126126
127127#include "driver.h"
128#include "deprecat.h"
129128#include "cpu/m68000/m68000.h"
130129#include "cpu/z80/z80.h"
131130#include "sound/2203intf.h"
r2724r2725
957956GFXDECODE_END
958957
959958/* handler called by the 2203 emulator when the internal timers cause an IRQ */
960static void irqhandler(int irq)
959static void irqhandler(running_machine *machine, int irq)
961960{
962   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
961   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
963962}
964963
965964static const struct YM2203interface ym2203_interface =
src/mame/drivers/zaxxon.c
r2724r2725
358358{
359359   /* pressing the service switch sends an NMI */
360360   if (newval)
361      cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, PULSE_LINE);
361      cpunum_set_input_line(field->port->machine, 0, INPUT_LINE_NMI, PULSE_LINE);
362362}
363363
364364
r2724r2725
421421   int num = (FPTR)param;
422422   int delta, res;
423423
424   delta = input_port_read(machine, dialname[num]);
424   delta = input_port_read(field->port->machine, dialname[num]);
425425
426426   if (delta < 0x80)
427427   {
r2724r2725
14691469   nprinces_decode();
14701470
14711471   /* additional input ports are wired */
1472   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xc004, 0xc004, 0, 0x18f3, port_tag_to_handler8("SW04"));
1473   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xc008, 0xc008, 0, 0x18f3, port_tag_to_handler8("SW08"));
1474   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xc00c, 0xc00c, 0, 0x18f3, port_tag_to_handler8("SW0C"));
1472   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xc004, 0xc004, 0, 0x18f3, input_port_read_handler8(machine->portconfig, "SW04"));
1473   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xc008, 0xc008, 0, 0x18f3, input_port_read_handler8(machine->portconfig, "SW08"));
1474   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xc00c, 0xc00c, 0, 0x18f3, input_port_read_handler8(machine->portconfig, "SW0C"));
14751475
14761476   /* unknown behavior expected here */
14771477   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0xc80a, 0xc80a, 0, 0, razmataz_counter_r);
src/mame/drivers/trackfld.c
r2724r2725
5353*/
5454static UINT8 *nvram;
5555static size_t nvram_size;
56static int we_flipped_the_switch;
5756
5857static NVRAM_HANDLER( trackfld )
5958{
6059   if (read_or_write)
61   {
6260      mame_fwrite(file,nvram,nvram_size);
63
64      if (we_flipped_the_switch)
65      {
66         input_port_entry *in;
67
68
69         /* find the dip switch which resets the high score table, and set it */
70         /* back to off. */
71         in = machine->input_ports;
72
73         while (in->type != IPT_END)
74         {
75            if (in->name != NULL && in->name != IP_NAME_DEFAULT &&
76                  strcmp(in->name,"World Records") == 0)
77            {
78               if (in->default_value == 0)
79                  in->default_value = in->mask;
80               break;
81            }
82
83            in++;
84         }
85
86         we_flipped_the_switch = 0;
87      }
88   }
89   else
90   {
91      if (file)
92      {
93         mame_fread(file,nvram,nvram_size);
94         we_flipped_the_switch = 0;
95      }
96      else
97      {
98         input_port_entry *in;
99
100
101         /* find the dip switch which resets the high score table, and set it on */
102         in = machine->input_ports;
103
104         while (in->type != IPT_END)
105         {
106            if (in->name != NULL && in->name != IP_NAME_DEFAULT &&
107                  strcmp(in->name,"World Records") == 0)
108            {
109               if (in->default_value == in->mask)
110               {
111                  in->default_value = 0;
112                  we_flipped_the_switch = 1;
113               }
114               break;
115            }
116
117            in++;
118         }
119      }
120   }
61   else if (file)
62      mame_fread(file,nvram,nvram_size);
12163}
12264
12365static NVRAM_HANDLER( mastkin )
src/mame/drivers/astrof.c
r2724r2725
109109static INPUT_CHANGED( coin_inserted )
110110{
111111   /* coin insertion causes an NMI */
112   cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, newval ? ASSERT_LINE : CLEAR_LINE);
112   cpunum_set_input_line(field->port->machine, 0, INPUT_LINE_NMI, newval ? ASSERT_LINE : CLEAR_LINE);
113113   coin_counter_w(0, newval);
114114}
115115
r2724r2725
117117static INPUT_CHANGED( service_coin_inserted )
118118{
119119   /* service coin insertion causes an NMI */
120   cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, newval ? ASSERT_LINE : CLEAR_LINE);
120   cpunum_set_input_line(field->port->machine, 0, INPUT_LINE_NMI, newval ? ASSERT_LINE : CLEAR_LINE);
121121}
122122
123123
124124static CUSTOM_INPUT( astrof_p1_controls_r )
125125{
126   return input_port_read(machine, "P1");
126   return input_port_read(field->port->machine, "P1");
127127}
128128
129129
r2724r2725
134134   /* on an upright cabinets, a single set of controls
135135       is connected to both sets of pins on the edge
136136       connector */
137   if (input_port_read(machine, "CAB"))
138      ret = input_port_read(machine, "P2");
137   if (input_port_read(field->port->machine, "CAB"))
138      ret = input_port_read(field->port->machine, "P2");
139139   else
140      ret = input_port_read(machine, "P1");
140      ret = input_port_read(field->port->machine, "P1");
141141
142142   return ret;
143143}
src/mame/drivers/karnov.c
r2724r2725
668668   cpunum_set_input_line(machine, 0,7,HOLD_LINE);   /* VBL */
669669}
670670
671static void sound_irq(int linestate)
671static void sound_irq(running_machine *machine, int linestate)
672672{
673   cpunum_set_input_line(Machine, 1,0,linestate); /* IRQ */
673   cpunum_set_input_line(machine, 1,0,linestate); /* IRQ */
674674}
675675
676676static const struct YM3526interface ym3526_interface =
src/mame/drivers/lwings.c
r2724r2725
385385   AM_RANGE(0x01, 0x01) AM_WRITE(msm5205_w)
386386ADDRESS_MAP_END
387387
388static INPUT_PORTS_START( sectionz )
389   PORT_START      /* IN0 */
388/*************************************
389 *
390 *  Generic port definitions
391 *
392 *************************************/
393
394static INPUT_PORTS_START( lwings_generic )
395   PORT_START_TAG("SERVICE")
390396   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START1 )
391397   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START2 )
392398   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
r2724r2725
396402   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN1 )
397403   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN2 )
398404
399   PORT_START      /* IN1 */
405   PORT_START_TAG("P1")
400406   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
401407   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
402408   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY
r2724r2725
406412   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
407413   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
408414
409   PORT_START      /* IN2 */
415   PORT_START_TAG("P2")
416   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2)
417   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2)
418   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2)
419   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2)
420   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
421   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
422   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
423   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
424INPUT_PORTS_END
425
426/*************************************
427 *
428 *  Game-specific port definitions
429 *
430 *************************************/
431
432static INPUT_PORTS_START( sectionz )
433   PORT_INCLUDE( lwings_generic )
434
435   PORT_MODIFY("P2")
410436   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_COCKTAIL
411437   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_COCKTAIL
412438   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_COCKTAIL
413439   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_COCKTAIL
414440   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
415441   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_COCKTAIL
416   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
417   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
418442
419   PORT_START      /* DSW0 */
420   PORT_SERVICE( 0x01, IP_ACTIVE_LOW )
421   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Flip_Screen ) )
443   PORT_START_TAG("DSWA")
444   PORT_SERVICE_DIPLOC( 0x01, IP_ACTIVE_LOW, "SWA:8" )
445   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("SWA:7")
422446   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
423447   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
424   PORT_DIPNAME( 0x0c, 0x0c, DEF_STR( Lives ) )
448   PORT_DIPNAME( 0x0c, 0x0c, DEF_STR( Lives ) ) PORT_DIPLOCATION("SWA:6,5")
425449   PORT_DIPSETTING(    0x04, "2" )
426450   PORT_DIPSETTING(    0x0c, "3" )
427451   PORT_DIPSETTING(    0x08, "4" )
428452   PORT_DIPSETTING(    0x00, "5" )
429   PORT_DIPNAME( 0x30, 0x30, DEF_STR( Coin_A ) )
453   PORT_DIPNAME( 0x30, 0x30, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("SWA:4,3")
430454   PORT_DIPSETTING(    0x00, DEF_STR( 4C_1C ) )
431455   PORT_DIPSETTING(    0x20, DEF_STR( 3C_1C ) )
432456   PORT_DIPSETTING(    0x10, DEF_STR( 2C_1C ) )
433457   PORT_DIPSETTING(    0x30, DEF_STR( 1C_1C ) )
434   PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Coin_B ) )
458   PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("SWA:2,1")
435459   PORT_DIPSETTING(    0x00, DEF_STR( 2C_1C ) )
436460   PORT_DIPSETTING(    0xc0, DEF_STR( 1C_1C ) )
437461   PORT_DIPSETTING(    0x40, DEF_STR( 1C_2C ) )
438462   PORT_DIPSETTING(    0x80, DEF_STR( 1C_3C ) )
439463
440   PORT_START      /* DSW1 */
441   PORT_DIPNAME( 0x01, 0x01, DEF_STR( Allow_Continue ) )
464   PORT_START_TAG("DSWB")
465   PORT_DIPNAME( 0x01, 0x01, DEF_STR( Allow_Continue ) ) PORT_DIPLOCATION("SWB:8")
442466   PORT_DIPSETTING(    0x00, DEF_STR( No ) )
443467   PORT_DIPSETTING(    0x01, DEF_STR( Yes ) )
444   PORT_DIPNAME( 0x06, 0x06, DEF_STR( Difficulty ) )
468   PORT_DIPNAME( 0x06, 0x06, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SWB:7,6")
445469   PORT_DIPSETTING(    0x02, DEF_STR( Easy ) )
446470   PORT_DIPSETTING(    0x06, DEF_STR( Normal ) )
447   PORT_DIPSETTING(    0x04, "Difficult" )
448   PORT_DIPSETTING(    0x00, "Very Difficult" )
449   PORT_DIPNAME( 0x38, 0x38, DEF_STR( Bonus_Life ) )
471   PORT_DIPSETTING(    0x04, DEF_STR( Hard ) )
472   PORT_DIPSETTING(    0x00, DEF_STR( Very_Hard ) )
473   PORT_DIPNAME( 0x38, 0x38, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("SWB:5,4,3")
450474   PORT_DIPSETTING(    0x38, "20000 50000" )
451475   PORT_DIPSETTING(    0x18, "20000 60000" )
452476   PORT_DIPSETTING(    0x28, "20000 70000" )
r2724r2725
455479   PORT_DIPSETTING(    0x10, "30000 80000" )
456480   PORT_DIPSETTING(    0x20, "40000 100000" )
457481   PORT_DIPSETTING(    0x00, DEF_STR( None ) )
458   PORT_DIPNAME( 0xc0, 0x00, DEF_STR( Cabinet ) )
482   PORT_DIPNAME( 0xc0, 0x00, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("SWB:2,1")
459483   PORT_DIPSETTING(    0x00, "Upright One Player" )
460484   PORT_DIPSETTING(    0x40, "Upright Two Players" )
461485/*      PORT_DIPSETTING(    0x80, "???" )       probably unused */
r2724r2725
463487INPUT_PORTS_END
464488
465489static INPUT_PORTS_START( lwings )
466   PORT_START      /* IN0 */
467   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START1 )
468   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START2 )
469   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
470   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
471   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
472   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
473   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN1 )
474   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN2 )
490   PORT_INCLUDE( lwings_generic )
475491
476   PORT_START      /* IN1 */
477   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
478   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
479   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY
480   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY
481   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
482   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 )
483   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
484   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
485
486   PORT_START      /* IN2 */
487   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2)
488   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2)
489   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2)
490   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2)
491   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
492   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
493   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
494   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
495
496   PORT_START      /* DSW0 */
497   PORT_DIPNAME( 0x01, 0x01, DEF_STR( Unused ) )
498   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
499   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
500   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Flip_Screen ) )
492   PORT_START_TAG("DSWA")
493   PORT_DIPUNUSED_DIPLOC( 0x0001, 0x0001, "SWA:8" )
494   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("SWA:7")
501495   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
502496   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
503   PORT_DIPNAME( 0x0c, 0x0c, DEF_STR( Lives ) )
497   PORT_DIPNAME( 0x0c, 0x0c, DEF_STR( Lives ) ) PORT_DIPLOCATION("SWA:6,5")
504498   PORT_DIPSETTING(    0x0c, "3" )
505499   PORT_DIPSETTING(    0x04, "4" )
506500   PORT_DIPSETTING(    0x08, "5" )
507501   PORT_DIPSETTING(    0x00, "6" )
508   PORT_DIPNAME( 0x30, 0x30, DEF_STR( Coin_B ) )
502   PORT_DIPNAME( 0x30, 0x30, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("SWA:4,3")
509503   PORT_DIPSETTING(    0x00, DEF_STR( 4C_1C ) )
510504   PORT_DIPSETTING(    0x20, DEF_STR( 3C_1C ) )
511505   PORT_DIPSETTING(    0x10, DEF_STR( 2C_1C ) )
512506   PORT_DIPSETTING(    0x30, DEF_STR( 1C_1C ) )
513   PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Coin_A ) )
507   PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("SWA:2,1")
514508   PORT_DIPSETTING(    0xc0, DEF_STR( 1C_1C ) )
515509   PORT_DIPSETTING(    0x00, DEF_STR( 2C_4C ) )
516510   PORT_DIPSETTING(    0x40, DEF_STR( 1C_2C ) )
517511   PORT_DIPSETTING(    0x80, DEF_STR( 1C_3C ) )
518512
519   PORT_START      /* DSW1 */
520   PORT_DIPNAME( 0x01, 0x01, DEF_STR( Unused ) )
521   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
522   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
523   PORT_DIPNAME( 0x06, 0x06, DEF_STR( Difficulty ) )
513   PORT_START_TAG("DSWB")
514   PORT_DIPUNUSED_DIPLOC( 0x0001, 0x0001, "SWB:8" )
515   PORT_DIPNAME( 0x06, 0x06, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SWB:7,6")
524516   PORT_DIPSETTING(    0x02, DEF_STR( Easy ) )
525517   PORT_DIPSETTING(    0x06, DEF_STR( Medium ) )
526518   PORT_DIPSETTING(    0x04, DEF_STR( Hard ) )
527519   PORT_DIPSETTING(    0x00, DEF_STR( Hardest ) )
528   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Demo_Sounds ) )
520   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("SWB:5")
529521   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
530522   PORT_DIPSETTING(    0x08, DEF_STR( On ) )
531   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Allow_Continue ) )
523   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Allow_Continue ) ) PORT_DIPLOCATION("SWB:4")
532524   PORT_DIPSETTING(    0x00, DEF_STR( No ) )
533525   PORT_DIPSETTING(    0x10, DEF_STR( Yes ) )
534   PORT_DIPNAME( 0xe0, 0xe0, DEF_STR( Bonus_Life ) )
526   PORT_DIPNAME( 0xe0, 0xe0, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("SWB:3,2,1")
535527   PORT_DIPSETTING(    0xe0, "20000 and every 50000" )
536528   PORT_DIPSETTING(    0x60, "20000 and every 60000" )
537529   PORT_DIPSETTING(    0xa0, "20000 and every 70000" )
r2724r2725
542534   PORT_DIPSETTING(    0x00, DEF_STR( None ) )
543535INPUT_PORTS_END
544536
545static INPUT_PORTS_START( trojan )
546   PORT_START      /* IN0 */
547   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START1 )
548   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START2 )
549   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
550   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
551   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
552   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
553   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN1 )
554   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN2 )
537static INPUT_PORTS_START( lwingsb )
538   PORT_INCLUDE( lwings )
555539
556   PORT_START      /* IN1 */
557   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
558   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
559   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY
560   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY
561   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
562   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 )
563   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
564   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
565
566   PORT_START      /* IN2 */
567   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_COCKTAIL
568   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_COCKTAIL
569   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_COCKTAIL
570   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_COCKTAIL
571   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
572   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_COCKTAIL
573   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
574   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
575
576   PORT_START      /* DSW0 */
577   PORT_DIPNAME( 0x03, 0x00, DEF_STR( Cabinet ) )
578   PORT_DIPSETTING(    0x00, "Upright 1 Player" )
579   PORT_DIPSETTING(    0x02, "Upright 2 Players" )
580   PORT_DIPSETTING(    0x03, DEF_STR( Cocktail ) )
581/* 0x01 same as 0x02 or 0x03 */
582   PORT_DIPNAME( 0x1c, 0x1c, DEF_STR( Bonus_Life ) )
583   PORT_DIPSETTING(    0x10, "20000 60000" )
584   PORT_DIPSETTING(    0x0c, "20000 70000" )
585   PORT_DIPSETTING(    0x08, "20000 80000" )
586   PORT_DIPSETTING(    0x1c, "30000 60000" )
587   PORT_DIPSETTING(    0x18, "30000 70000" )
588   PORT_DIPSETTING(    0x14, "30000 80000" )
589   PORT_DIPSETTING(    0x04, "40000 80000" )
590   PORT_DIPSETTING(    0x00, DEF_STR( None ) )
591   PORT_DIPNAME( 0xe0, 0xe0, "Starting Level" )
592   PORT_DIPSETTING(    0xe0, "1" )
593   PORT_DIPSETTING(    0xc0, "2" )
594   PORT_DIPSETTING(    0xa0, "3" )
595   PORT_DIPSETTING(    0x80, "4" )
596   PORT_DIPSETTING(    0x60, "5" )
597   PORT_DIPSETTING(    0x40, "6" )
598/* 0x00 and 0x20 start at level 6 */
599
600   PORT_START      /* DSW1 */
601   PORT_DIPNAME( 0x03, 0x03, DEF_STR( Coin_A ) )
602   PORT_DIPSETTING(    0x00, DEF_STR( 2C_1C ) )
603   PORT_DIPSETTING(    0x03, DEF_STR( 1C_1C ) )
604   PORT_DIPSETTING(    0x02, DEF_STR( 1C_2C ) )
605   PORT_DIPSETTING(    0x01, DEF_STR( 1C_3C ) )
606   PORT_DIPNAME( 0x0c, 0x0c, DEF_STR( Coin_B ) )
607   PORT_DIPSETTING(    0x00, DEF_STR( 4C_1C ) )
608   PORT_DIPSETTING(    0x04, DEF_STR( 3C_1C ) )
609   PORT_DIPSETTING(    0x08, DEF_STR( 2C_1C ) )
610   PORT_DIPSETTING(    0x0c, DEF_STR( 1C_1C ) )
611   PORT_DIPNAME( 0x30, 0x30, DEF_STR( Lives ) )
612   PORT_DIPSETTING(    0x20, "2" )
613   PORT_DIPSETTING(    0x30, "3" )
614   PORT_DIPSETTING(    0x10, "4" )
540   PORT_MODIFY("DSWA")
541   PORT_DIPNAME( 0x0c, 0x0c, DEF_STR( Lives ) ) PORT_DIPLOCATION("SWA:6,5")
542   PORT_DIPSETTING(    0x0c, "2" )
543   PORT_DIPSETTING(    0x04, "3" )
544   PORT_DIPSETTING(    0x08, "4" )
615545   PORT_DIPSETTING(    0x00, "5" )
616   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Flip_Screen ) )
617   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
618   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
619   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Allow_Continue ) )
620   PORT_DIPSETTING(    0x00, DEF_STR( No ) )
621   PORT_DIPSETTING(    0x80, DEF_STR( Yes ) )
622546INPUT_PORTS_END
623547
624548/* Trojan with level selection - starting level dip switches not used */
625549static INPUT_PORTS_START( trojanls )
626   PORT_START      /* IN0 */
627   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START1 )
628   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START2 )
629   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
630   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
631   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
632   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
633   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN1 )
634   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN2 )
550   PORT_INCLUDE( lwings_generic )
635551
636   PORT_START      /* IN1 */
637   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
638   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
639   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY
640   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY
641   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
642   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 )
643   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
644   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
645
646   PORT_START      /* IN2 */
552   PORT_MODIFY("P2")
647553   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_COCKTAIL
648554   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_COCKTAIL
649555   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_COCKTAIL
650556   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_COCKTAIL
651557   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
652558   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_COCKTAIL
653   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
654   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
655559
656   PORT_START      /* DSW0 */
657   PORT_DIPNAME( 0x03, 0x00, DEF_STR( Cabinet ) )
560   PORT_START_TAG("DSWB")
561   PORT_DIPNAME( 0x03, 0x00, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("SWB:8,7")
658562   PORT_DIPSETTING(    0x00, "Upright 1 Player" )
659563   PORT_DIPSETTING(    0x02, "Upright 2 Players" )
660564   PORT_DIPSETTING(    0x03, DEF_STR( Cocktail ) )
661565/* 0x01 same as 0x02 or 0x03 */
662   PORT_DIPNAME( 0x1c, 0x1c, DEF_STR( Bonus_Life ) )
566   PORT_DIPNAME( 0x1c, 0x1c, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("SWB:6,5,4")
663567   PORT_DIPSETTING(    0x10, "20000 60000" )
664568   PORT_DIPSETTING(    0x0c, "20000 70000" )
665569   PORT_DIPSETTING(    0x08, "20000 80000" )
r2724r2725
668572   PORT_DIPSETTING(    0x14, "30000 80000" )
669573   PORT_DIPSETTING(    0x04, "40000 80000" )
670574   PORT_DIPSETTING(    0x00, DEF_STR( None ) )
671   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
672   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
673   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
674   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
675   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
676   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
677   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
678   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
679   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
575   PORT_DIPUNUSED_DIPLOC( 0x20, 0x20, "SWB:3" )
576   PORT_DIPUNUSED_DIPLOC( 0x40, 0x40, "SWB:2" )
577   PORT_DIPUNUSED_DIPLOC( 0x40, 0x40, "SWB:1" )
680578
681   PORT_START      /* DSW1 */
682   PORT_DIPNAME( 0x03, 0x03, DEF_STR( Coin_A ) )
579   PORT_START_TAG("DSWA")
580   PORT_DIPNAME( 0x03, 0x03, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("SWA:8,7")
683581   PORT_DIPSETTING(    0x00, DEF_STR( 2C_1C ) )
684582   PORT_DIPSETTING(    0x03, DEF_STR( 1C_1C ) )
685583   PORT_DIPSETTING(    0x02, DEF_STR( 1C_2C ) )
686584   PORT_DIPSETTING(    0x01, DEF_STR( 1C_3C ) )
687   PORT_DIPNAME( 0x0c, 0x0c, DEF_STR( Coin_B ) )
585   PORT_DIPNAME( 0x0c, 0x0c, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("SWA:6,5")
688586   PORT_DIPSETTING(    0x00, DEF_STR( 4C_1C ) )
689587   PORT_DIPSETTING(    0x04, DEF_STR( 3C_1C ) )
690588   PORT_DIPSETTING(    0x08, DEF_STR( 2C_1C ) )
691589   PORT_DIPSETTING(    0x0c, DEF_STR( 1C_1C ) )
692   PORT_DIPNAME( 0x30, 0x30, DEF_STR( Lives ) )
590   PORT_DIPNAME( 0x30, 0x30, DEF_STR( Lives ) ) PORT_DIPLOCATION("SWA:4,3")
693591   PORT_DIPSETTING(    0x20, "2" )
694592   PORT_DIPSETTING(    0x30, "3" )
695593   PORT_DIPSETTING(    0x10, "4" )
696594   PORT_DIPSETTING(    0x00, "5" )
697   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Flip_Screen ) )
595   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("SWA:2")
698596   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
699597   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
700   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Allow_Continue ) )
598   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Allow_Continue ) ) PORT_DIPLOCATION("SWA:1")
701599   PORT_DIPSETTING(    0x00, DEF_STR( No ) )
702600   PORT_DIPSETTING(    0x80, DEF_STR( Yes ) )
703601INPUT_PORTS_END
704602
705static INPUT_PORTS_START( avengers )
706   PORT_START      /* IN0 */
707   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START1 )
708   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START2 )
709   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
710   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
711   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
712   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
713   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN1 )
714   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN2 )
603static INPUT_PORTS_START( trojan )
604   PORT_INCLUDE( trojanls )
715605
716   PORT_START      /* IN1 */
717   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
718   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
719   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY
720   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY
721   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
722   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 )
723   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
724   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
606   PORT_MODIFY("DSWB")
607   PORT_DIPNAME( 0xe0, 0xe0, "Starting Level" ) PORT_DIPLOCATION("SWB:3,2,1")
608   PORT_DIPSETTING(    0xe0, "1" )
609   PORT_DIPSETTING(    0xc0, "2" )
610   PORT_DIPSETTING(    0xa0, "3" )
611   PORT_DIPSETTING(    0x80, "4" )
612   PORT_DIPSETTING(    0x60, "5" )
613   PORT_DIPSETTING(    0x40, "6" )
614/* 0x00 and 0x20 start at level 6 */
615INPUT_PORTS_END
725616
726   PORT_START      /* IN2 */
727   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2)
728   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2)
729   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2)
730   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2)
731   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
732   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
733   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
734   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )    /* probably unused */
617static INPUT_PORTS_START( avengers )
618   PORT_INCLUDE( lwings_generic )
735619
736   PORT_START      /* DSWB */
737   PORT_DIPNAME( 0x01, 0x01, DEF_STR( Allow_Continue ) )
620   PORT_START_TAG("DSWB")
621   PORT_DIPNAME( 0x01, 0x01, DEF_STR( Allow_Continue ) ) PORT_DIPLOCATION("SWB:8")
738622   PORT_DIPSETTING(    0x00, DEF_STR( No ) )
739623   PORT_DIPSETTING(    0x01, DEF_STR( Yes ) )
740   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Demo_Sounds ) )
624   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("SWB:7")
741625   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
742626   PORT_DIPSETTING(    0x02, DEF_STR( On ) )
743   PORT_DIPNAME( 0x0c, 0x0c, DEF_STR( Difficulty ) )
627   PORT_DIPNAME( 0x0c, 0x0c, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SWB:6,5")
744628   PORT_DIPSETTING(    0x04, DEF_STR( Easy ) )
745629   PORT_DIPSETTING(    0x0c, DEF_STR( Normal ) )
746630   PORT_DIPSETTING(    0x08, DEF_STR( Hard ) )
747631   PORT_DIPSETTING(    0x00, DEF_STR( Very_Hard ) )
748   PORT_DIPNAME( 0x30, 0x30, "Bonus" )
632   PORT_DIPNAME( 0x30, 0x30, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("SWB:4,3")
749633   PORT_DIPSETTING(    0x30, "20k 60k" )
750634   PORT_DIPSETTING(    0x10, "20k 70k" )
751635   PORT_DIPSETTING(    0x20, "20k 80k" )
752636   PORT_DIPSETTING(    0x00, "30k 80k" )
753   PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Lives ) )
637   PORT_DIPNAME( 0xc0, 0xc0, DEF_STR( Lives ) ) PORT_DIPLOCATION("SWB:2,1")
754638   PORT_DIPSETTING(    0xc0, "3" )
755639   PORT_DIPSETTING(    0x40, "4" )
756640   PORT_DIPSETTING(    0x80, "5" )
757641   PORT_DIPSETTING(    0x00, "6" )
758642
759   PORT_START      /* DSWA */
760   PORT_SERVICE( 0x01, IP_ACTIVE_LOW )
761   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Flip_Screen ) )
643   PORT_START_TAG("DSWA")
644   PORT_SERVICE_DIPLOC( 0x01, IP_ACTIVE_LOW, "SWA:8")
645   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("SWA:7")
762646   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
763647   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
764   PORT_DIPNAME( 0x1c, 0x1c, DEF_STR( Coin_B ) )
648   PORT_DIPNAME( 0x1c, 0x1c, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("SWA:6,5,4")
765649   PORT_DIPSETTING(    0x00, DEF_STR( 4C_1C ) )
766650   PORT_DIPSETTING(    0x10, DEF_STR( 3C_1C ) )
767651   PORT_DIPSETTING(    0x08, DEF_STR( 2C_1C ) )
r2724r2725
770654   PORT_DIPSETTING(    0x14, DEF_STR( 1C_3C ) )
771655   PORT_DIPSETTING(    0x04, DEF_STR( 1C_4C ) )
772656   PORT_DIPSETTING(    0x18, DEF_STR( 1C_6C ) )
773   PORT_DIPNAME( 0xe0, 0xe0, DEF_STR( Coin_A ) )
657   PORT_DIPNAME( 0xe0, 0xe0, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("SWA:3,2,1")
774658   PORT_DIPSETTING(    0x00, DEF_STR( 4C_1C ) )
775659   PORT_DIPSETTING(    0x80, DEF_STR( 3C_1C ) )
776660   PORT_DIPSETTING(    0x40, DEF_STR( 2C_1C ) )
r2724r2725
781665   PORT_DIPSETTING(    0xc0, DEF_STR( 1C_6C ) )
782666INPUT_PORTS_END
783667
668/*************************************
669 *
670 *  Graphics definitions
671 *
672 *************************************/
673
784674static const gfx_layout charlayout =
785675{
786676   8,8,
r2724r2725
845735   GFXDECODE_ENTRY( REGION_GFX4, 0, bg2_tilelayout,   0,  8 ) /* colors   0-127 */
846736GFXDECODE_END
847737
738/*************************************
739 *
740 *  Sound definitions
741 *
742 *************************************/
743
848744static const struct MSM5205interface msm5205_interface =
849745{
850746   0,            /* interrupt function */
851747   MSM5205_SEX_4B   /* slave mode */
852748};
853749
750/*************************************
751 *
752 *  Machine driver
753 *
754 *************************************/
755
854756static MACHINE_DRIVER_START( lwings )
855757
856758   /* basic machine hardware */
857   MDRV_CPU_ADD(Z80, 6000000)        /* 4 MHz (?) */
759   MDRV_CPU_ADD_TAG("main", Z80, 6000000)        /* 4 MHz (?) */
858760   MDRV_CPU_PROGRAM_MAP(readmem,writemem)
859761   MDRV_CPU_VBLANK_INT("main", lwings_interrupt)
860762
861   MDRV_CPU_ADD(Z80, 4000000)
763   MDRV_CPU_ADD_TAG("sound", Z80, 4000000)
862764   /* audio CPU */
863765   MDRV_CPU_PROGRAM_MAP(sound_readmem,sound_writemem)
864766   MDRV_CPU_VBLANK_INT_HACK(irq0_line_hold,4)
r2724r2725
883785   /* sound hardware */
884786   MDRV_SPEAKER_STANDARD_MONO("mono")
885787
886   MDRV_SOUND_ADD(YM2203, 1500000)
788   MDRV_SOUND_ADD_TAG("2203a", YM2203, 1500000)
887789   MDRV_SOUND_ROUTE(0, "mono", 0.20)
888790   MDRV_SOUND_ROUTE(1, "mono", 0.20)
889791   MDRV_SOUND_ROUTE(2, "mono", 0.20)
890792   MDRV_SOUND_ROUTE(3, "mono", 0.10)
891793
892   MDRV_SOUND_ADD(YM2203, 1500000)
794   MDRV_SOUND_ADD_TAG("2203b", YM2203, 1500000)
893795   MDRV_SOUND_ROUTE(0, "mono", 0.20)
894796   MDRV_SOUND_ROUTE(1, "mono", 0.20)
895797   MDRV_SOUND_ROUTE(2, "mono", 0.20)
896798   MDRV_SOUND_ROUTE(3, "mono", 0.10)
897799MACHINE_DRIVER_END
898800
899
900801static MACHINE_DRIVER_START( trojan )
802   MDRV_IMPORT_FROM( lwings )
901803
902   /* basic machine hardware */
903   MDRV_CPU_ADD(Z80, 6000000)        /* 4 MHz (?) */
804   MDRV_CPU_MODIFY("main")
904805   MDRV_CPU_PROGRAM_MAP(readmem,trojan_writemem)
905   MDRV_CPU_VBLANK_INT("main", lwings_interrupt)
906806
907   MDRV_CPU_ADD(Z80, 4000000)
908   /* audio CPU */
909   MDRV_CPU_PROGRAM_MAP(sound_readmem,sound_writemem)
910   MDRV_CPU_VBLANK_INT_HACK(irq0_line_hold,4)
911
912   MDRV_CPU_ADD(Z80, 4000000) // 3.579545 Mhz (?)
807   MDRV_CPU_ADD_TAG("adpcm", Z80, 4000000) // 3.579545 Mhz (?)
913808   /* audio CPU */   /* ? */
914809   MDRV_CPU_PROGRAM_MAP(adpcm_readmem,adpcm_writemem)
915810   MDRV_CPU_IO_MAP(adpcm_readport,adpcm_writeport)
916811   MDRV_CPU_PERIODIC_INT(irq0_line_hold, 4000)
917812
918813   /* video hardware */
919   MDRV_VIDEO_ATTRIBUTES(VIDEO_BUFFERS_SPRITERAM)
920
921   MDRV_SCREEN_ADD("main", RASTER)
922   MDRV_SCREEN_REFRESH_RATE(60)
923   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
924   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
925   MDRV_SCREEN_SIZE(32*8, 32*8)
926   MDRV_SCREEN_VISIBLE_AREA(0*8, 32*8-1, 1*8, 31*8-1)
927
928814   MDRV_GFXDECODE(trojan)
929   MDRV_PALETTE_LENGTH(1024)
930815
931816   MDRV_VIDEO_START(trojan)
932   MDRV_VIDEO_EOF(lwings)
933817   MDRV_VIDEO_UPDATE(trojan)
934818
935819   /* sound hardware */
936   MDRV_SPEAKER_STANDARD_MONO("mono")
937
938   MDRV_SOUND_ADD(YM2203, 1500000)
939   MDRV_SOUND_ROUTE(0, "mono", 0.20)
940   MDRV_SOUND_ROUTE(1, "mono", 0.20)
941   MDRV_SOUND_ROUTE(2, "mono", 0.20)
942   MDRV_SOUND_ROUTE(3, "mono", 0.10)
943
944   MDRV_SOUND_ADD(YM2203, 1500000)
945   MDRV_SOUND_ROUTE(0, "mono", 0.20)
946   MDRV_SOUND_ROUTE(1, "mono", 0.20)
947   MDRV_SOUND_ROUTE(2, "mono", 0.20)
948   MDRV_SOUND_ROUTE(3, "mono", 0.10)
949
950   MDRV_SOUND_ADD(MSM5205, 384000)
820   MDRV_SOUND_ADD_TAG("5205", MSM5205, 384000)
951821   MDRV_SOUND_CONFIG(msm5205_interface)
952822   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
953823MACHINE_DRIVER_END
954824
955
956825static MACHINE_DRIVER_START( avengers )
826   MDRV_IMPORT_FROM( trojan )
957827
958   /* basic machine hardware */
959   MDRV_CPU_ADD(Z80, 6000000) //AT: (avengers37b16gre)
828   MDRV_CPU_MODIFY("main") //AT: (avengers37b16gre)
960829   MDRV_CPU_PROGRAM_MAP(avengers_readmem,avengers_writemem)
961830   MDRV_CPU_VBLANK_INT("main", nmi_line_pulse) // RST 38h triggered by software
962831
963   MDRV_CPU_ADD(Z80, 4000000)
964   /* audio CPU */
965   MDRV_CPU_PROGRAM_MAP(sound_readmem,sound_writemem)
966   MDRV_CPU_VBLANK_INT_HACK(irq0_line_hold,4)
967
968   MDRV_CPU_ADD(Z80, 4000000) // 3.579545 Mhz (?)
969   /* audio CPU */   /* ? */
970   MDRV_CPU_PROGRAM_MAP(adpcm_readmem,adpcm_writemem)
832   MDRV_CPU_MODIFY("adpcm")
971833   MDRV_CPU_IO_MAP(avengers_adpcm_readport,adpcm_writeport)
972   MDRV_CPU_PERIODIC_INT(irq0_line_hold, 4000)
973834
974835   /* video hardware */
975   MDRV_VIDEO_ATTRIBUTES(VIDEO_BUFFERS_SPRITERAM)
976
977   MDRV_SCREEN_ADD("main", RASTER)
978   MDRV_SCREEN_REFRESH_RATE(60)
979   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0))
980   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
981   MDRV_SCREEN_SIZE(32*8, 32*8)
982   MDRV_SCREEN_VISIBLE_AREA(0*8, 32*8-1, 1*8, 31*8-1)
983
984   MDRV_GFXDECODE(trojan)
985   MDRV_PALETTE_LENGTH(1024)
986
987836   MDRV_VIDEO_START(avengers)
988   MDRV_VIDEO_EOF(lwings)
989   MDRV_VIDEO_UPDATE(trojan)
990
991   /* sound hardware */
992   MDRV_SPEAKER_STANDARD_MONO("mono")
993
994   MDRV_SOUND_ADD(YM2203, 1500000)
995   MDRV_SOUND_ROUTE(0, "mono", 0.20)
996   MDRV_SOUND_ROUTE(1, "mono", 0.20)
997   MDRV_SOUND_ROUTE(2, "mono", 0.20)
998   MDRV_SOUND_ROUTE(3, "mono", 0.10)
999
1000   MDRV_SOUND_ADD(YM2203, 1500000)
1001   MDRV_SOUND_ROUTE(0, "mono", 0.20)
1002   MDRV_SOUND_ROUTE(1, "mono", 0.20)
1003   MDRV_SOUND_ROUTE(2, "mono", 0.20)
1004   MDRV_SOUND_ROUTE(3, "mono", 0.10)
1005
1006   MDRV_SOUND_ADD(MSM5205, 384000)
1007   MDRV_SOUND_CONFIG(msm5205_interface)
1008   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
1009837MACHINE_DRIVER_END
1010838
1011/***************************************************************************
839/*************************************
840 *
841 *  ROM definition(s)
842 *
843 *************************************/
1012844
1013  Game driver(s)
1014
1015***************************************************************************/
1016
1017845ROM_START( lwings )
1018846   ROM_REGION( 0x20000, REGION_CPU1, 0 )     /* 64k for code + 3*16k for the banked ROMs images */
1019847   ROM_LOAD( "6c_lw01.bin",  0x00000, 0x8000, CRC(b55a7f60) SHA1(e28cc540892a9ad050693900356744f8f5d05237) )
r2724r2725
14881316   ROM_LOAD( "tbb_1bpr.1e",  0x0100,  0x0100, CRC(5052fa9d) SHA1(8cd240f4795a7ae76499573c09069dba37182be2) )   /* priority (not used) */
14891317ROM_END
14901318
1319/*************************************
1320 *
1321 *  Game driver(s)
1322 *
1323 *************************************/
1324
14911325GAME( 1985, sectionz, 0,        lwings,   sectionz, 0, ROT0,  "Capcom", "Section Z (set 1)", 0 )
14921326GAME( 1985, sctionza, sectionz, lwings,   sectionz, 0, ROT0,  "Capcom", "Section Z (set 2)", 0 )
14931327GAME( 1986, lwings,   0,        lwings,   lwings,   0, ROT90, "Capcom", "Legendary Wings (US set 1)", 0 )
14941328GAME( 1986, lwings2,  lwings,   lwings,   lwings,   0, ROT90, "Capcom", "Legendary Wings (US set 2)", 0 )
14951329GAME( 1986, lwingsjp, lwings,   lwings,   lwings,   0, ROT90, "Capcom", "Ares no Tsubasa (Japan)", 0 )
1496GAME( 1986, lwingsb,  lwings,   lwings,   lwings,   0, ROT90, "bootleg", "Legendary Wings (bootleg)", 0 )
1330GAME( 1986, lwingsb,  lwings,   lwings,   lwingsb,  0, ROT90, "bootleg", "Legendary Wings (bootleg)", 0 )
14971331GAME( 1986, trojan,   0,        trojan,   trojanls, 0, ROT0,  "Capcom", "Trojan (US)", 0 )
14981332GAME( 1986, trojanr,  trojan,   trojan,   trojan,   0, ROT0,  "Capcom (Romstar license)", "Trojan (Romstar)", 0 )
14991333GAME( 1986, trojanj,  trojan,   trojan,   trojan,   0, ROT0,  "Capcom", "Tatakai no Banka (Japan)", 0 )
src/mame/drivers/maxaflex.c
r2724r2725
226226static INPUT_CHANGED( coin_inserted )
227227{
228228   if (!newval)
229      cpunum_set_input_line(machine, 1, M6805_IRQ_LINE, HOLD_LINE );
229      cpunum_set_input_line(field->port->machine, 1, M6805_IRQ_LINE, HOLD_LINE );
230230}
231231
232232int atari_input_disabled(void)
src/mame/drivers/vegas.c
r2724r2725
273273**************************************************************************/
274274
275275#include "driver.h"
276#include "deprecat.h"
277276#include "cpu/adsp2100/adsp2100.h"
278277#include "cpu/mips/mips3.h"
279278#include "audio/dcs.h"
r2724r2725
502501 *
503502 *************************************/
504503
505static void vblank_assert(int state);
504static void vblank_assert(running_machine *machine, int state);
506505static TIMER_CALLBACK( nile_timer_callback );
507506static void ide_interrupt(const device_config *device, int state);
508507static void remap_dynamic_addresses(running_machine *machine);
r2724r2725
600599   /* reset subsystems */
601600   devtag_reset(machine, IDE_CONTROLLER, "ide");
602601   voodoo_reset(0);
603   smc91c94_reset();
602   smc91c94_reset(machine);
604603
605604   /* initialize IRQ states */
606605   ide_irq_state = 0;
r2724r2725
892891 *
893892 *************************************/
894893
895static void update_nile_irqs(void)
894static void update_nile_irqs(running_machine *machine)
896895{
897896   UINT32 intctll = nile_regs[NREG_INTCTRL+0];
898897   UINT32 intctlh = nile_regs[NREG_INTCTRL+1];
r2724r2725
944943      if (irq[i])
945944      {
946945         if (LOG_NILE_IRQS) logerror(" 1");
947         cpunum_set_input_line(Machine, 0, MIPS3_IRQ0 + i, ASSERT_LINE);
946         cpunum_set_input_line(machine, 0, MIPS3_IRQ0 + i, ASSERT_LINE);
948947      }
949948      else
950949      {
951950         if (LOG_NILE_IRQS) logerror(" 0");
952         cpunum_set_input_line(Machine, 0, MIPS3_IRQ0 + i, CLEAR_LINE);
951         cpunum_set_input_line(machine, 0, MIPS3_IRQ0 + i, CLEAR_LINE);
953952      }
954953   }
955954   if (LOG_NILE_IRQS) logerror("\n");
r2724r2725
977976   if (which == 3)
978977      nile_irq_state |= 1 << 5;
979978
980   update_nile_irqs();
979   update_nile_irqs(machine);
981980}
982981
983982
r2724r2725
11191118      case NREG_INTCTRL+1:   /* Interrupt control */
11201119         if (LOG_NILE) logerror("%08X:NILE WRITE: interrupt control(%03X) = %08X & %08X\n", activecpu_get_pc(), offset*4, data, mem_mask);
11211120         logit = 0;
1122         update_nile_irqs();
1121         update_nile_irqs(machine);
11231122         break;
11241123
11251124      case NREG_INTSTAT0+0:   /* Interrupt status 0 */
11261125      case NREG_INTSTAT0+1:   /* Interrupt status 0 */
11271126         if (LOG_NILE) logerror("%08X:NILE WRITE: interrupt status 0(%03X) = %08X & %08X\n", activecpu_get_pc(), offset*4, data, mem_mask);
11281127         logit = 0;
1129         update_nile_irqs();
1128         update_nile_irqs(machine);
11301129         break;
11311130
11321131      case NREG_INTSTAT1+0:   /* Interrupt status 1 */
11331132      case NREG_INTSTAT1+1:   /* Interrupt status 1 */
11341133         if (LOG_NILE) logerror("%08X:NILE WRITE: interrupt status 1/enable(%03X) = %08X & %08X\n", activecpu_get_pc(), offset*4, data, mem_mask);
11351134         logit = 0;
1136         update_nile_irqs();
1135         update_nile_irqs(machine);
11371136         break;
11381137
11391138      case NREG_INTCLR+0:      /* Interrupt clear */
r2724r2725
11411140         if (LOG_NILE) logerror("%08X:NILE WRITE: interrupt clear(%03X) = %08X & %08X\n", activecpu_get_pc(), offset*4, data, mem_mask);
11421141         logit = 0;
11431142         nile_irq_state &= ~(nile_regs[offset] & ~0xf00);
1144         update_nile_irqs();
1143         update_nile_irqs(machine);
11451144         break;
11461145
11471146      case NREG_INTPPES+0:   /* PCI Interrupt control */
r2724r2725
12161215         logit = 0;
12171216         break;
12181217      case NREG_UARTIER:      /* serial interrupt enable */
1219         update_nile_irqs();
1218         update_nile_irqs(machine);
12201219         break;
12211220
12221221      case NREG_VID:
r2724r2725
12731272      nile_irq_state |= 0x800;
12741273   else
12751274      nile_irq_state &= ~0x800;
1276   update_nile_irqs();
1275   update_nile_irqs(device->machine);
12771276}
12781277
12791278
r2724r2725
12841283 *
12851284 *************************************/
12861285
1287static void update_sio_irqs(void)
1286static void update_sio_irqs(running_machine *machine)
12881287{
12891288   if (sio_irq_state & sio_irq_enable)
12901289      nile_irq_state |= 0x400;
12911290   else
12921291      nile_irq_state &= ~0x400;
1293   update_nile_irqs();
1292   update_nile_irqs(machine);
12941293}
12951294
12961295
1297static void vblank_assert(int state)
1296static void vblank_assert(running_machine *machine, int state)
12981297{
12991298   if (!vblank_state && state)
13001299   {
13011300      sio_irq_state |= 0x20;
1302      update_sio_irqs();
1301      update_sio_irqs(machine);
13031302   }
13041303   vblank_state = state;
13051304
r2724r2725
13111310}
13121311
13131312
1314static void ioasic_irq(int state)
1313static void ioasic_irq(running_machine *machine, int state)
13151314{
13161315   if (state)
13171316      sio_irq_state |= 0x04;
13181317   else
13191318      sio_irq_state &= ~0x04;
1320   update_sio_irqs();
1319   update_sio_irqs(machine);
13211320}
13221321
13231322
1324static void ethernet_interrupt(int state)
1323static void ethernet_interrupt(running_machine *machine, int state)
13251324{
13261325   if (state)
13271326      sio_irq_state |= 0x10;
13281327   else
13291328      sio_irq_state &= ~0x10;
1330   update_sio_irqs();
1329   update_sio_irqs(machine);
13311330}
13321331
13331332
r2724r2725
13541353      if (!(data & 0x08))
13551354      {
13561355         sio_irq_state &= ~0x20;
1357         update_sio_irqs();
1356         update_sio_irqs(machine);
13581357      }
13591358   }
13601359}
r2724r2725
13711370   if (ACCESSING_BITS_0_7)
13721371   {
13731372      sio_irq_enable = data;
1374      update_sio_irqs();
1373      update_sio_irqs(machine);
13751374   }
13761375}
13771376
src/mame/drivers/tecmo.c
r2724r2725
4646
4747***************************************************************************/
4848#include "driver.h"
49#include "deprecat.h"
5049#include "cpu/z80/z80.h"
5150#include "sound/3812intf.h"
5251#include "sound/msm5205.h"
r2724r2725
9897{
9998   MSM5205_set_volume(0,(data & 0x0f) * 100 / 15);
10099}
101static void tecmo_adpcm_int(int num)
100static void tecmo_adpcm_int(running_machine *machine, int num)
102101{
103102   static int adpcm_data = -1;
104103
r2724r2725
545544
546545
547546
548static void irqhandler(int linestate)
547static void irqhandler(running_machine *machine, int linestate)
549548{
550   cpunum_set_input_line(Machine, 1,0,linestate);
549   cpunum_set_input_line(machine, 1,0,linestate);
551550}
552551
553552static const struct YM3526interface ym3812_interface =
src/mame/drivers/galpanic.c
r2724r2725
237237
238238static READ16_HANDLER( kludge )
239239{
240   return mame_rand(Machine) & 0x0700;
240   return mame_rand(machine) & 0x0700;
241241}
242242
243243/* a kludge! */
r2724r2725
246246   UINT16 retvalue;
247247
248248//  retvalue = OKIM6295_status_0_msb_r(offset,mem_mask); // doesn't work, causes lockups when girls change..
249   retvalue = mame_rand(Machine);
249   retvalue = mame_rand(machine);
250250
251251   return retvalue;
252252}
r2724r2725
345345/*
346346READ16_HANDLER( zipzap_random_read )
347347{
348    return mame_rand(Machine);
348    return mame_rand(machine);
349349}
350350*/
351351static ADDRESS_MAP_START( zipzap_readmem, ADDRESS_SPACE_PROGRAM, 16 )
src/mame/drivers/segaybd.c
r2724r2725
1010***************************************************************************/
1111
1212#include "driver.h"
13#include "deprecat.h"
1413#include "system16.h"
1514#include "cpu/m68000/m68000.h"
1615#include "machine/segaic16.h"
r2724r2725
6564 *
6665 *************************************/
6766
68static void update_main_irqs(void)
67static void update_main_irqs(running_machine *machine)
6968{
7069   int irq = 0;
7170
r2724r2725
7877   /* assert the lines that are live, or clear everything if nothing is live */
7978   if (irq != 0)
8079   {
81      cpunum_set_input_line(Machine, 0, irq, ASSERT_LINE);
82      cpunum_set_input_line(Machine, 1, irq, ASSERT_LINE);
83      cpunum_set_input_line(Machine, 2, irq, ASSERT_LINE);
80      cpunum_set_input_line(machine, 0, irq, ASSERT_LINE);
81      cpunum_set_input_line(machine, 1, irq, ASSERT_LINE);
82      cpunum_set_input_line(machine, 2, irq, ASSERT_LINE);
8483      cpu_boost_interleave(attotime_zero, ATTOTIME_IN_USEC(50));
8584   }
8685   else
8786   {
88      cpunum_set_input_line(Machine, 0, 7, CLEAR_LINE);
89      cpunum_set_input_line(Machine, 1, 7, CLEAR_LINE);
90      cpunum_set_input_line(Machine, 2, 7, CLEAR_LINE);
87      cpunum_set_input_line(machine, 0, 7, CLEAR_LINE);
88      cpunum_set_input_line(machine, 1, 7, CLEAR_LINE);
89      cpunum_set_input_line(machine, 2, 7, CLEAR_LINE);
9190   }
9291}
9392
r2724r2725
161160   }
162161
163162   /* update IRQs on the main CPU */
164   update_main_irqs();
163   update_main_irqs(machine);
165164
166165   /* come back at the next appropriate scanline */
167166   timer_adjust_oneshot(interrupt_timer, video_screen_get_time_until_pos(machine->primary_screen, scanline, 0), scanline);
r2724r2725
202201 *
203202 *************************************/
204203
205static void sound_cpu_irq(int state)
204static void sound_cpu_irq(running_machine *machine, int state)
206205{
207   cpunum_set_input_line(Machine, 3, 0, state);
206   cpunum_set_input_line(machine, 3, 0, state);
208207}
209208
210209
src/mame/drivers/cclimber.c
r2724r2725
466466   PORT_DIPNAME( 0x04, 0x00, DEF_STR( Unknown ) )      // Look code at 0x03c4 : 0x8076 is never tested !
467467   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
468468   PORT_DIPSETTING(    0x04, DEF_STR( On ) )
469   PORT_BIT(    0x08, 0x00, IPT_DIPSWITCH_NAME ) PORT_NAME("Rack Test (Cheat)") PORT_CODE(KEYCODE_F1)
469   PORT_DIPNAME( 0x08, 0x00, "Rack Test (Cheat)" ) PORT_CODE(KEYCODE_F1)
470470   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
471471   PORT_DIPSETTING(    0x08, DEF_STR( On ) )
472472   PORT_DIPNAME( 0x30, 0x00, DEF_STR( Coin_A ) )
r2724r2725
497497   PORT_DIPNAME( 0x04, 0x00, DEF_STR( Bonus_Life ) )
498498   PORT_DIPSETTING(    0x00, "30000" )
499499   PORT_DIPSETTING(    0x04, "50000" )
500   PORT_BIT(    0x08, 0x00, IPT_DIPSWITCH_NAME ) PORT_NAME("Rack Test (Cheat)") PORT_CODE(KEYCODE_F1)
500   PORT_DIPNAME( 0x08, 0x00, "Rack Test (Cheat)" ) PORT_CODE(KEYCODE_F1)
501501   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
502502   PORT_DIPSETTING(    0x08, DEF_STR( On ) )
503503   PORT_DIPNAME( 0x30, 0x00, DEF_STR( Coin_A ) )
src/mame/drivers/enigma2.c
r2724r2725
375375
376376static CUSTOM_INPUT( p1_controls_r )
377377{
378   return input_port_read(machine, "P1CONTROLS");
378   return input_port_read(field->port->machine, "P1CONTROLS");
379379}
380380
381381
382382static CUSTOM_INPUT( p2_controls_r )
383383{
384384   if (engima2_flip_screen)
385      return input_port_read(machine, "P2CONTROLS");
385      return input_port_read(field->port->machine, "P2CONTROLS");
386386   else
387      return input_port_read(machine, "P1CONTROLS");
387      return input_port_read(field->port->machine, "P1CONTROLS");
388388}
389389
390390
src/mame/drivers/gticlub.c
r2724r2725
7777   palette_set_color_rgb(machine, offset, pal5bit(data >> 10), pal5bit(data >> 5), pal5bit(data >> 0));
7878}
7979
80static void voodoo_vblank_0(int param)
80static void voodoo_vblank_0(running_machine *machine, int param)
8181{
82   cpunum_set_input_line(Machine, 0, INPUT_LINE_IRQ0, ASSERT_LINE);
82   cpunum_set_input_line(machine, 0, INPUT_LINE_IRQ0, ASSERT_LINE);
8383}
8484
85static void voodoo_vblank_1(int param)
85static void voodoo_vblank_1(running_machine *machine, int param)
8686{
87   cpunum_set_input_line(Machine, 0, INPUT_LINE_IRQ1, ASSERT_LINE);
87   cpunum_set_input_line(machine, 0, INPUT_LINE_IRQ1, ASSERT_LINE);
8888}
8989
9090static VIDEO_START( hangplt )
r2724r2725
10001000        ROM_LOAD32_WORD( "685a14.12w",   0x000000, 0x400000, CRC(87437739) SHA1(0d45637af40938a54d5efd29c125b0fafd55f9a4) )
10011001ROM_END
10021002
1003static void sound_irq_callback(int irq)
1003static void sound_irq_callback(running_machine *machine, int irq)
10041004{
10051005   if (irq == 0)
1006      cpunum_set_input_line(Machine, 1, INPUT_LINE_IRQ1, PULSE_LINE);
1006      cpunum_set_input_line(machine, 1, INPUT_LINE_IRQ1, PULSE_LINE);
10071007   else
1008      cpunum_set_input_line(Machine, 1, INPUT_LINE_IRQ2, PULSE_LINE);
1008      cpunum_set_input_line(machine, 1, INPUT_LINE_IRQ2, PULSE_LINE);
10091009}
10101010
10111011static DRIVER_INIT(gticlub)
src/mame/drivers/namcona1.c
r2724r2725
828828   {
829829      namcona1_gfxram_w( machine, (dest-0xf40000)/2, data, 0xffff );
830830   }
831   else if( dest>=0xff0000 && dest<0xff8000 )
831   else if( dest>=0xff0000 && dest<0xffc000 )
832832   {
833833      namcona1_videoram_w( machine, (dest-0xff0000)/2, data, 0xffff );
834834   }
835   else if( dest>=0xff8000 && dest<0xffc000 )
836   {
837      namcona1_rozvideoram_w( machine, (dest-0xff8000)/2, data, 0xffff );
838   }
839835   else if( dest>=0xfff000 && dest<0x1000000 )
840836   {
841837      spriteram16[(dest-0xfff000)/2] = data;
r2724r2725
10491045   AM_RANGE(0xefff00, 0xefffff) AM_READWRITE(namcona1_vreg_r, namcona1_vreg_w) AM_BASE(&namcona1_vreg)
10501046   AM_RANGE(0xf00000, 0xf01fff) AM_READWRITE(namcona1_paletteram_r, namcona1_paletteram_w) AM_BASE(&paletteram16)
10511047   AM_RANGE(0xf40000, 0xf7ffff) AM_READWRITE(namcona1_gfxram_r, namcona1_gfxram_w)
1052   AM_RANGE(0xff0000, 0xff7fff) AM_READWRITE(namcona1_videoram_r,    namcona1_videoram_w) AM_BASE(&videoram16)
1053   AM_RANGE(0xff8000, 0xffbfff) AM_READWRITE(namcona1_rozvideoram_r, namcona1_rozvideoram_w) AM_BASE(&namcona1_rozvideoram)
1048   AM_RANGE(0xff0000, 0xffbfff) AM_READWRITE(namcona1_videoram_r,    namcona1_videoram_w) AM_BASE(&videoram16)
10541049   AM_RANGE(0xffd000, 0xffdfff) AM_RAM /* unknown */
10551050   AM_RANGE(0xffe000, 0xffefff) AM_RAM   AM_BASE(&namcona1_scroll)      /* scroll registers */
10561051   AM_RANGE(0xfff000, 0xffffff) AM_RAM   AM_BASE(&spriteram16)         /* spriteram */
r2724r2725
13091304   MDRV_SCREEN_SIZE(38*8, 32*8)
13101305   MDRV_SCREEN_VISIBLE_AREA(8, 38*8-1-8, 4*8, 32*8-1)
13111306
1312   MDRV_PALETTE_LENGTH(0x1000)
1307   MDRV_PALETTE_LENGTH(0x2000)
13131308
13141309   MDRV_VIDEO_START(namcona1)
13151310   MDRV_VIDEO_UPDATE(namcona1)
r2724r2725
13451340   AM_RANGE(0xefff00, 0xefffff) AM_READ(namcona1_vreg_r)
13461341   AM_RANGE(0xf00000, 0xf01fff) AM_READ(namcona1_paletteram_r)
13471342   AM_RANGE(0xf40000, 0xf7ffff) AM_READ(namcona1_gfxram_r)
1348   AM_RANGE(0xff0000, 0xff7fff) AM_READ(namcona1_videoram_r)
1349   AM_RANGE(0xff8000, 0xffbfff) AM_READ(namcona1_rozvideoram_r )
1343   AM_RANGE(0xff0000, 0xffbfff) AM_READ(namcona1_videoram_r)
13501344   AM_RANGE(0xffd000, 0xffdfff) AM_READ(SMH_RAM) /* unknown */
13511345   AM_RANGE(0xffe000, 0xffefff) AM_READ(SMH_RAM) /* scroll registers */
13521346   AM_RANGE(0xfff000, 0xffffff) AM_READ(SMH_RAM) /* spriteram */
r2724r2725
13661360   AM_RANGE(0xefff00, 0xefffff) AM_WRITE(namcona1_vreg_w) AM_BASE(&namcona1_vreg)
13671361   AM_RANGE(0xf00000, 0xf01fff) AM_WRITE(namcona1_paletteram_w) AM_BASE(&paletteram16)
13681362   AM_RANGE(0xf40000, 0xf7ffff) AM_WRITE(namcona1_gfxram_w)
1369   AM_RANGE(0xff0000, 0xff7fff) AM_WRITE(namcona1_videoram_w) AM_BASE(&videoram16)
1370   AM_RANGE(0xff8000, 0xffbfff) AM_WRITE(namcona1_rozvideoram_w) AM_BASE(&namcona1_rozvideoram)
1363   AM_RANGE(0xff0000, 0xffbfff) AM_WRITE(namcona1_videoram_w) AM_BASE(&videoram16)
13711364   AM_RANGE(0xffd000, 0xffdfff) AM_WRITE(SMH_RAM) /* unknown */
13721365   AM_RANGE(0xffe000, 0xffefff) AM_WRITE(SMH_RAM) AM_BASE(&namcona1_scroll)
13731366   AM_RANGE(0xfff000, 0xffffff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16)
r2724r2725
13981391   MDRV_SCREEN_SIZE(38*8, 32*8)
13991392   MDRV_SCREEN_VISIBLE_AREA(8, 38*8-1-8, 4*8, 32*8-1)
14001393
1401   MDRV_PALETTE_LENGTH(0x1000)
1394   MDRV_PALETTE_LENGTH(0x2000)
14021395
14031396   MDRV_VIDEO_START(namcona1)
14041397   MDRV_VIDEO_UPDATE(namcona1)
src/mame/drivers/acefruit.c
r2724r2725
146146   switch (bit_mask)
147147   {
148148      case 0x01:
149         return ((input_port_read(machine, "PAYOUT") & bit_mask) >> 0);
149         return ((input_port_read(field->port->machine, "PAYOUT") & bit_mask) >> 0);
150150      case 0x02:
151         return ((input_port_read(machine, "PAYOUT") & bit_mask) >> 1);
151         return ((input_port_read(field->port->machine, "PAYOUT") & bit_mask) >> 1);
152152      default:
153153         logerror("sidewndr_payout_r : invalid %02X bit_mask\n",bit_mask);
154154         return 0;
r2724r2725
162162   switch (bit_mask)
163163   {
164164      case 0x01:
165         return ((input_port_read(machine, "COINAGE") & bit_mask) >> 0);
165         return ((input_port_read(field->port->machine, "COINAGE") & bit_mask) >> 0);
166166      case 0x02:
167         return ((input_port_read(machine, "COINAGE") & bit_mask) >> 1);
167         return ((input_port_read(field->port->machine, "COINAGE") & bit_mask) >> 1);
168168      case 0x04:
169         return ((input_port_read(machine, "COINAGE") & bit_mask) >> 2);
169         return ((input_port_read(field->port->machine, "COINAGE") & bit_mask) >> 2);
170170      case 0x08:
171         return ((input_port_read(machine, "COINAGE") & bit_mask) >> 3);
171         return ((input_port_read(field->port->machine, "COINAGE") & bit_mask) >> 3);
172172      default:
173173         logerror("starspnr_coinage_r : invalid %02X bit_mask\n",bit_mask);
174174         return 0;
r2724r2725
182182   switch (bit_mask)
183183   {
184184      case 0x01:
185         return ((input_port_read(machine, "PAYOUT") & bit_mask) >> 0);
185         return ((input_port_read(field->port->machine, "PAYOUT") & bit_mask) >> 0);
186186      case 0x02:
187         return ((input_port_read(machine, "PAYOUT") & bit_mask) >> 1);
187         return ((input_port_read(field->port->machine, "PAYOUT") & bit_mask) >> 1);
188188      case 0x04:
189         return ((input_port_read(machine, "PAYOUT") & bit_mask) >> 2);
189         return ((input_port_read(field->port->machine, "PAYOUT") & bit_mask) >> 2);
190190      default:
191191         logerror("starspnr_payout_r : invalid %02X bit_mask\n",bit_mask);
192192         return 0;
src/mame/drivers/appoooh.c
r2724r2725
5656static UINT8 *adpcmptr = 0;
5757static int appoooh_adpcm_data;
5858
59static void appoooh_adpcm_int(int num)
59static void appoooh_adpcm_int(running_machine *machine, int num)
6060{
6161   if( adpcmptr )
6262   {
src/mame/drivers/metlclsh.c
r2724r2725
287287
288288***************************************************************************/
289289
290static void metlclsh_irqhandler(int linestate)
290static void metlclsh_irqhandler(running_machine *machine, int linestate)
291291{
292   cpunum_set_input_line(Machine, 0,M6809_IRQ_LINE,linestate);
292   cpunum_set_input_line(machine, 0,M6809_IRQ_LINE,linestate);
293293}
294294
295295static const struct YM3526interface ym3526_interface =
src/mame/drivers/chinagat.c
r2724r2725
6969
7070
7171#include "driver.h"
72#include "deprecat.h"
7372#include "cpu/m6809/m6809.h"
7473#include "cpu/z80/z80.h"
7574#include "cpu/i8039/i8039.h"
r2724r2725
257256   }
258257   return 0;
259258}
260static void saiyugb1_m5205_irq_w(int num)
259static void saiyugb1_m5205_irq_w(running_machine *machine, int num)
261260{
262261   adpcm_sound_irq = 1;
263262}
r2724r2725
457456   GFXDECODE_ENTRY( REGION_GFX3, 0, tilelayout, 256, 8 )   /* 16x16 background tiles */
458457GFXDECODE_END
459458
460static void chinagat_irq_handler(int irq) {
461   cpunum_set_input_line(Machine, 2, 0, irq ? ASSERT_LINE : CLEAR_LINE );
459static void chinagat_irq_handler(running_machine *machine, int irq)
460{
461   cpunum_set_input_line(machine, 2, 0, irq ? ASSERT_LINE : CLEAR_LINE );
462462}
463463
464464static const struct YM2151interface ym2151_interface =
src/mame/drivers/kaneko16.c
r2724r2725
243243
244244static READ16_HANDLER( kaneko16_rnd_r )
245245{
246   return mame_rand(Machine) & 0xffff;
246   return mame_rand(machine) & 0xffff;
247247}
248248
249249static WRITE16_HANDLER( kaneko16_coin_lockout_w )
src/mame/drivers/dbz.c
r2724r2725
138138   cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, PULSE_LINE);
139139}
140140
141static void dbz_sound_irq(int irq)
141static void dbz_sound_irq(running_machine *machine, int irq)
142142{
143143   if (irq)
144      cpunum_set_input_line(Machine, 1, 0, ASSERT_LINE);
144      cpunum_set_input_line(machine, 1, 0, ASSERT_LINE);
145145   else
146      cpunum_set_input_line(Machine, 1, 0, CLEAR_LINE);
146      cpunum_set_input_line(machine, 1, 0, CLEAR_LINE);
147147}
148148
149149static ADDRESS_MAP_START( dbz_readmem, ADDRESS_SPACE_PROGRAM, 16 )
src/mame/drivers/wc90.c
r2724r2725
5252*/
5353
5454#include "driver.h"
55#include "deprecat.h"
5655#include "cpu/z80/z80.h"
5756#include "sound/2608intf.h"
5857
r2724r2725
302301
303302
304303/* handler called by the 2608 emulator when the internal timers cause an IRQ */
305static void irqhandler(int irq)
304static void irqhandler(running_machine *machine, int irq)
306305{
307   cpunum_set_input_line(Machine, 2,0,irq ? ASSERT_LINE : CLEAR_LINE);
306   cpunum_set_input_line(machine, 2,0,irq ? ASSERT_LINE : CLEAR_LINE);
308307}
309308
310309static const struct YM2608interface ym2608_interface =
311310{
312311   {
313      AY8910_LEGACY_OUTPUT,
312      AY8910_LEGACY_OUTPUT | AY8910_SINGLE_OUTPUT,
314313      AY8910_DEFAULT_LOADS,
315314      NULL, NULL, NULL, NULL
316315   },
src/mame/drivers/gauntlet.c
r2724r2725
378378
379379static INPUT_PORTS_START( gauntlet )
380380   PORT_START_TAG("IN0")   /* 803000 */
381   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_START1 )
382381   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
383382   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1)
384383   PORT_BIT( 0x000c, IP_ACTIVE_LOW, IPT_UNUSED )
r2724r2725
389388   PORT_BIT( 0xff00, IP_ACTIVE_LOW, IPT_UNUSED )
390389
391390   PORT_START_TAG("IN1")   /* 803002 */
392   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_START2 )
393391   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
394392   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
395393   PORT_BIT( 0x000c, IP_ACTIVE_LOW, IPT_UNUSED )
r2724r2725
400398   PORT_BIT( 0xff00, IP_ACTIVE_LOW, IPT_UNUSED )
401399
402400   PORT_START_TAG("IN2")   /* 803004 */
403   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_START3 )
404401   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(3)
405402   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(3)
406403   PORT_BIT( 0x000c, IP_ACTIVE_LOW, IPT_UNUSED )
r2724r2725
411408   PORT_BIT( 0xff00, IP_ACTIVE_LOW, IPT_UNUSED )
412409
413410   PORT_START_TAG("IN3")   /* 803006 */
414   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_START4 )
415411   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(4)
416412   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(4)
417413   PORT_BIT( 0x000c, IP_ACTIVE_LOW, IPT_UNUSED )
src/mame/drivers/mpu4.c
r2724r2725
440440
441441
442442/* 6809 IRQ handler */
443static void cpu0_irq(int state)
443static void cpu0_irq(running_machine *machine, int state)
444444{
445445   /* The PIA and PTM IRQ lines are all connected to a common PCB track, leading directly to the 6809 IRQ line. */
446446   int combined_state = pia_get_irq_a(0) | pia_get_irq_b(0) |
r2724r2725
453453
454454   if (!serial_card_connected)
455455   {
456      cpunum_set_input_line(Machine, 0, M6809_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
456      cpunum_set_input_line(machine, 0, M6809_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
457457      LOG(("6809 int%d \n", combined_state));
458458   }
459459   else
460460   {
461      cpunum_set_input_line(Machine, 0, M6809_FIRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
461      cpunum_set_input_line(machine, 0, M6809_FIRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
462462      LOG(("6809 fint%d \n", combined_state));
463463   }
464464}
src/mame/drivers/darkseal.c
r2724r2725
1111***************************************************************************/
1212
1313#include "driver.h"
14#include "deprecat.h"
1514#include "cpu/h6280/h6280.h"
1615#include "sound/2203intf.h"
1716#include "sound/2151intf.h"
r2724r2725
274273
275274/******************************************************************************/
276275
277static void sound_irq(int state)
276static void sound_irq(running_machine *machine, int state)
278277{
279   cpunum_set_input_line(Machine, 1,1,state); /* IRQ 2 */
278   cpunum_set_input_line(machine, 1,1,state); /* IRQ 2 */
280279}
281280
282281static const struct YM2151interface ym2151_interface =
src/mame/drivers/spbactn.c
r2724r2725
126126*******************************************************************************/
127127
128128#include "driver.h"
129#include "deprecat.h"
130129#include "sound/okim6295.h"
131130#include "sound/3812intf.h"
132131
r2724r2725
342341   GFXDECODE_ENTRY( REGION_GFX3, 0, spritelayout,   0x0000, 16 + 384 )
343342GFXDECODE_END
344343
345static void irqhandler(int linestate)
344static void irqhandler(running_machine *machine, int linestate)
346345{
347   cpunum_set_input_line(Machine, 1,0,linestate);
346   cpunum_set_input_line(machine, 1,0,linestate);
348347}
349348
350349static const struct YM3812interface ym3812_interface =
src/mame/drivers/system16.c
r2724r2725
160160*/
161161
162162#include "driver.h"
163#include "deprecat.h"
164163#include "cpu/z80/z80.h"
165164#include "cpu/i8039/i8039.h"
166165#include "system16.h"
r2724r2725
269268   sample_buffer = data;
270269}
271270
272static void tturfbl_msm5205_callback(int data)
271static void tturfbl_msm5205_callback(running_machine *machine, int data)
273272{
274273   MSM5205_data_w(0, (sample_buffer >> 4) & 0x0F);
275274   sample_buffer <<= 4;
276275   sample_select ^= 1;
277276   if(sample_select == 0)
278      cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, PULSE_LINE);
277      cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, PULSE_LINE);
279278}
280279
281280static const struct MSM5205interface tturfbl_msm5205_interface =
r2724r2725
18341833   AM_RANGE(0xffc000, 0xffffff) AM_WRITE(SYS16_MWA16_WORKINGRAM) AM_BASE(&sys16_workingram)
18351834ADDRESS_MAP_END
18361835
1836
1837
1838static READ16_HANDLER(beautyb_unk1_r)
1839{
1840
1841   return mame_rand(machine);;
1842}
1843
1844
1845static READ16_HANDLER(beautyb_unk2_r)
1846{
1847   return mame_rand(machine);
1848}
1849
1850static ADDRESS_MAP_START( beautyb_map, ADDRESS_SPACE_PROGRAM, 16 )
1851   AM_RANGE(0x000000, 0x00ffff) AM_READWRITE(SMH_ROM, SMH_NOP)
1852   //AM_RANGE(0x010000, 0x03ffff) AM_WRITE(SMH_NOP)
1853
1854   AM_RANGE(0x0280D6, 0x0280D7) AM_READ(beautyb_unk2_r)
1855   AM_RANGE(0x0280D8, 0x0280D9) AM_READ(beautyb_unk2_r)
1856
1857   AM_RANGE(0x400000, 0x40ffff) AM_RAM AM_READWRITE(SYS16_MRA16_TILERAM, SYS16_MWA16_TILERAM) AM_BASE(&sys16_tileram)
1858   AM_RANGE(0x410000, 0x410fff) AM_RAM AM_READWRITE(SYS16_MRA16_TEXTRAM, SYS16_MWA16_TEXTRAM) AM_BASE(&sys16_textram)
1859   AM_RANGE(0x418000, 0x41803f) AM_RAM AM_READWRITE(SYS16_MRA16_EXTRAM2, SYS16_MWA16_EXTRAM2) AM_BASE(&sys16_extraram2)
1860   AM_RANGE(0x440000, 0x440fff) AM_RAM AM_READWRITE(SYS16_MRA16_SPRITERAM, SYS16_MWA16_SPRITERAM) AM_BASE(&sys16_spriteram)
1861   AM_RANGE(0x840000, 0x840fff) AM_RAM AM_READWRITE(SYS16_MRA16_PALETTERAM, SYS16_MWA16_PALETTERAM) AM_BASE(&paletteram16)
1862
1863   AM_RANGE(0xC41000, 0xC41001) AM_READ(beautyb_unk1_r )
1864   AM_RANGE(0xC41002, 0xC41003) AM_READ(beautyb_unk1_r )
1865
1866   AM_RANGE(0xc40000, 0xc40001) AM_WRITE(SMH_NOP)
1867   AM_RANGE(0xc80000, 0xc80001) AM_WRITE(SMH_NOP)
1868
1869   AM_RANGE(0xffc000, 0xffffff) AM_RAM AM_WRITE(SYS16_MWA16_WORKINGRAM) AM_BASE(&sys16_workingram)
1870ADDRESS_MAP_END
1871
18371872/***************************************************************************/
18381873
18391874
r2724r2725
19051940   MDRV_MACHINE_RESET(tetrisbl)
19061941MACHINE_DRIVER_END
19071942
1943static MACHINE_DRIVER_START( beautyb )
1944
1945   /* basic machine hardware */
1946   MDRV_IMPORT_FROM(system16)
1947   MDRV_CPU_MODIFY("main")
1948   MDRV_CPU_PROGRAM_MAP(beautyb_map, 0)
1949
1950   MDRV_MACHINE_RESET(tetrisbl)
1951MACHINE_DRIVER_END
1952
1953
19081954/***************************************************************************/
19091955
19101956static READ16_HANDLER( tt_io_player1_r )
r2724r2725
28012847GAME( 1988, tetrisbl, tetris,   tetrisbl, tetris,   tetrisbl, ROT0,   "bootleg", "Tetris (bootleg)", 0 )
28022848GAME( 1989, tturfbl,  tturf,    tturfbl,  tturf,    tturfbl,  ROT0,   "bootleg", "Tough Turf (bootleg)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND | GAME_NOT_WORKING )
28032849GAME( 1988, wb3bbl,   wb3,      wb3bbl,   wb3b,     wb3bbl,   ROT0,   "bootleg", "Wonder Boy III - Monster Lair (bootleg)", 0 )
2850
2851DRIVER_INIT( beautyb )
2852{
2853   UINT16*rom = (UINT16*)memory_region( REGION_CPU1 );
2854   int x;
2855
2856   for (x=0;x<0x8000;x++)
2857   {
2858      rom[x] = rom[x] ^ 0x2400;
2859
2860      if (x&8) rom[x] = BITSWAP16(rom[x],15,14,10,12,  11,13,9,8,
2861                                7,6,5,4,   3,2,1,0 );
2862
2863   }
2864
2865   MACHINE_RESET_CALL(sys16_onetime);
2866
2867}
2868
2869/* Program Roms contain
2870
2871Designed and Programmed by A.M.T. Research & Development Department 03/30/1991.
2872Copying or Revising for Commercial Use Is Not Permitted.
2873
2874*/
2875
2876ROM_START( beautyb )
2877   ROM_REGION( 0x010000, REGION_CPU1, ROMREGION_ERASEFF ) /* 68000 code */
2878   ROM_LOAD16_BYTE( "b13.u3", 0x00000, 0x8000, CRC(90c4489b) SHA1(240275ad6dfd02feab636ceb620264d339e79b6a) )
2879   ROM_LOAD16_BYTE( "b23.u2", 0x00001, 0x8000, CRC(79b8f9ed) SHA1(5926852ea00b60d91684dbea4687b67894a397a1) )
2880
2881   ROM_REGION( 0x30000, REGION_GFX1, ROMREGION_DISPOSE ) /* tiles */
2882   ROM_LOAD( "b43.bin", 0x00000, 0x10000, CRC(67fe3f0c) SHA1(c9479512dd7a80895740c7fbd2133ab4d4c679d6) )
2883   ROM_LOAD( "b53.bin", 0x10000, 0x10000, CRC(aca8e330) SHA1(912e636e3c1e238682ea29620e8e2c6089c77209) )
2884   ROM_LOAD( "b63.bin", 0x20000, 0x10000, CRC(f2af2fd5) SHA1(0a95ebb5eae7cdc6535533d73d06419c23d01ac3) )
2885
2886   ROM_REGION( 0x020000, REGION_GFX2, ROMREGION_ERASEFF ) /* sprites */
2887   /* no sprites on this */
2888
2889   ROM_REGION( 0x40000, REGION_CPU2, 0 ) /* sound CPU */
2890   ROM_LOAD( "1.bin", 0x0000, 0x8000, CRC(bd9ba01b) SHA1(fafa7dc36cc057a50ae4cdf7a35f3594292336f4) )
2891
2892   ROM_REGION( 0x0020, REGION_PROMS, 0 )
2893   ROM_LOAD( "82s123.2",  0x0000, 0x0020, CRC(58bcf8bd) SHA1(e4d3d179b08c0f3424a6bec0f15058fb1b56f8d8) )
2894
2895   ROM_REGION( 0x0144, REGION_USER1, 0 )
2896   ROM_LOAD( "pal16r4acn.1",  0x0000, 0x0104, CRC(826be9e7) SHA1(893fc49c38aa8e7d6e98f6320157ba627a5d1748) )
2897   ROM_LOAD( "pal16r4acn.2",  0x0000, 0x0104, CRC(b3084ffe) SHA1(086ad2f89bdd8524ae358fd49b0803f9bb4aff33) )
2898   ROM_LOAD( "pal16r4acn.3",  0x0000, 0x0104, CRC(741cd872) SHA1(d53bdcadcd25d44b6423e0740e88209f85c709bd) )
2899   ROM_LOAD( "pal20l8acn",    0x0000, 0x0144, CRC(36e30d71) SHA1(e38f0257f9beedccc9421eec78701a86465d16ad) )
2900   ROM_LOAD( "pal16l8ajc.u4", 0x0000, 0x0104, NO_DUMP)
2901ROM_END
2902
2903
2904GAME( 1991, beautyb,    0,        beautyb,    tetris,    beautyb, ROT0,  "AMT", "Beauty Block", GAME_NO_SOUND|GAME_NOT_WORKING )
2905
src/mame/drivers/deniam.c
r2724r2725
3232***************************************************************************/
3333
3434#include "driver.h"
35#include "deprecat.h"
3635#include "cpu/z80/z80.h"
3736#include "sound/okim6295.h"
3837#include "sound/3812intf.h"
r2724r2725
305304GFXDECODE_END
306305
307306
308static void irqhandler(int linestate)
307static void irqhandler(running_machine *machine, int linestate)
309308{
310309   /* system 16c doesn't have the sound CPU */
311   if (Machine->config->cpu[1].type != CPU_DUMMY)
312      cpunum_set_input_line(Machine, 1,0,linestate);
310   if (machine->config->cpu[1].type != CPU_DUMMY)
311      cpunum_set_input_line(machine, 1,0,linestate);
313312}
314313
315314static const struct YM3812interface ym3812_interface =
src/mame/drivers/nyny.c
r2724r2725
112112 *
113113 *************************************/
114114
115static void main_cpu_irq(int state)
115static void main_cpu_irq(running_machine *machine, int state)
116116{
117117   int combined_state = pia_get_irq_a(1) | pia_get_irq_b(1) | pia_get_irq_b(2);
118118
119   cpunum_set_input_line(Machine, 0, M6809_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
119   cpunum_set_input_line(machine, 0, M6809_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
120120}
121121
122122
123static void main_cpu_firq(int state)
123static void main_cpu_firq(running_machine *machine, int state)
124124{
125   cpunum_set_input_line(Machine, 0, M6809_FIRQ_LINE, state ? ASSERT_LINE : CLEAR_LINE);
125   cpunum_set_input_line(machine, 0, M6809_FIRQ_LINE, state ? ASSERT_LINE : CLEAR_LINE);
126126}
127127
128128
src/mame/drivers/mcr3.c
r2724r2725
718718   PORT_DIPSETTING(    0x40, DEF_STR( 1C_4C ) )
719719   PORT_DIPSETTING(    0x30, DEF_STR( 1C_5C ) )
720720   PORT_DIPSETTING(    0x20, DEF_STR( 1C_6C ) )
721   PORT_BIT( 0x80,    0x80, IPT_DIPSWITCH_NAME ) PORT_NAME("Rack Advance (Cheat)") PORT_CODE(KEYCODE_F1)
721   PORT_DIPNAME( 0x80, 0x80, "Rack Advance (Cheat)" ) PORT_CODE(KEYCODE_F1)
722722   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
723723   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
724724
r2724r2725
779779   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Demo_Sounds ) )
780780   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
781781   PORT_DIPSETTING(    0x40, DEF_STR( On ) )
782   PORT_BIT( 0x80,    0x80, IPT_DIPSWITCH_NAME ) PORT_NAME("Rack Advance (Cheat)") PORT_CODE(KEYCODE_F1)
782   PORT_DIPNAME( 0x80, 0x80, "Rack Advance (Cheat)" ) PORT_CODE(KEYCODE_F1)
783783   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
784784   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
785785
src/mame/drivers/pipeline.c
r2724r2725
4848*/
4949
5050#include "driver.h"
51#include "deprecat.h"
5251#include "machine/z80ctc.h"
5352#include "sound/2203intf.h"
5453#include "machine/8255ppi.h"
r2724r2725
286285   GFXDECODE_ENTRY( REGION_GFX2, 0, layout_8x8x3, 0x100, 32 ) // 3bpp tiles
287286GFXDECODE_END
288287
289static void ctc0_interrupt(int state)
288static void ctc0_interrupt(running_machine *machine, int state)
290289{
291   cpunum_set_input_line(Machine, 1, 0, state);
290   cpunum_set_input_line(machine, 1, 0, state);
292291}
293292
294293static z80ctc_interface ctc_intf =
src/mame/drivers/pengo.c
r2724r2725
190190   PORT_DIPSETTING(    0x10, "3" )
191191   PORT_DIPSETTING(    0x08, "4" )
192192   PORT_DIPSETTING(    0x00, "5" )
193   PORT_BIT(    0x20, 0x20, IPT_DIPSWITCH_NAME ) PORT_NAME("Rack Test (Cheat)") PORT_CODE(KEYCODE_F1)
193   PORT_DIPNAME( 0x20, 0x20, "Rack Test (Cheat)" ) PORT_CODE(KEYCODE_F1)
194194   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
195195   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
196196   PORT_DIPNAME( 0xc0, 0x80, DEF_STR( Difficulty ) )
r2724r2725
274274   PORT_DIPSETTING(    0x10, "15000" )
275275   PORT_DIPSETTING(    0x20, "20000" )
276276   PORT_DIPSETTING(    0x30, "30000" )
277   PORT_BIT( 0x40, 0x40, IPT_DIPSWITCH_NAME ) PORT_NAME("Rack Test (Cheat)") PORT_CODE(KEYCODE_F1)
277   PORT_DIPNAME( 0x40, 0x40, "Rack Test (Cheat)" ) PORT_CODE(KEYCODE_F1)
278278   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
279279   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
280280   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Cabinet ) )
src/mame/drivers/stadhero.c
r2724r2725
77***************************************************************************/
88
99#include "driver.h"
10#include "deprecat.h"
1110#include "cpu/m6502/m6502.h"
1211#include "sound/2203intf.h"
1312#include "sound/3812intf.h"
r2724r2725
231230
232231/******************************************************************************/
233232
234static void irqhandler(int linestate)
233static void irqhandler(running_machine *machine, int linestate)
235234{
236   cpunum_set_input_line(Machine, 1,0,linestate);
235   cpunum_set_input_line(machine, 1,0,linestate);
237236}
238237
239238static const struct YM3812interface ym3812_interface =
src/mame/drivers/prehisle.c
r2724r2725
99***************************************************************************/
1010
1111#include "driver.h"
12#include "deprecat.h"
1312#include "sound/upd7759.h"
1413#include "sound/3812intf.h"
1514
r2724r2725
215214
216215/******************************************************************************/
217216
218static void irqhandler(int irq)
217static void irqhandler(running_machine *machine, int irq)
219218{
220   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
219   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
221220}
222221
223222static const struct YM3812interface ym3812_interface =
src/mame/drivers/simpsons.c
r2724r2725
99***************************************************************************/
1010
1111#include "driver.h"
12#include "deprecat.h"
1312#include "cpu/konami/konami.h" /* for the callback and the firq irq definition */
1413#include "cpu/z80/z80.h"
1514#include "video/konamiic.h"
r2724r2725
6968#if 0
7069static int nmi_enabled;
7170
72static void sound_nmi_callback( int param )
71static void sound_nmi_callback( running_machine *machine, int param )
7372{
74   cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, ( nmi_enabled ) ? CLEAR_LINE : ASSERT_LINE );
73   cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, ( nmi_enabled ) ? CLEAR_LINE : ASSERT_LINE );
7574
7675   nmi_enabled = 0;
7776}
src/mame/drivers/wwfsstar.c
r2724r2725
328328 Straight from Ddragon 3
329329*******************************************************************************/
330330
331static void wwfsstar_ymirq_handler(int irq)
331static void wwfsstar_ymirq_handler(running_machine *machine, int irq)
332332{
333   cpunum_set_input_line(Machine, 1, 0 , irq ? ASSERT_LINE : CLEAR_LINE );
333   cpunum_set_input_line(machine, 1, 0 , irq ? ASSERT_LINE : CLEAR_LINE );
334334}
335335
336336static const struct YM2151interface ym2151_interface =
src/mame/drivers/actfancr.c
r2724r2725
2323*******************************************************************************/
2424
2525#include "driver.h"
26#include "deprecat.h"
2726#include "cpu/m6502/m6502.h"
2827#include "cpu/h6280/h6280.h"
2928#include "sound/2203intf.h"
r2724r2725
335334
336335/******************************************************************************/
337336
338static void sound_irq(int linestate)
337static void sound_irq(running_machine *machine, int linestate)
339338{
340   cpunum_set_input_line(Machine, 1,0,linestate); /* IRQ */
339   cpunum_set_input_line(machine, 1,0,linestate); /* IRQ */
341340}
342341
343342static const struct YM3812interface ym3812_interface =
src/mame/drivers/taito_b.c
r2724r2725
13801380   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
13811381   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
13821382
1383   PORT_START_TAG("IN0")
1383   PORT_START_TAG("IN1")
13841384   TAITO_B_PLAYERS_INPUT( 2 )
13851385   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
13861386   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
r2724r2725
25662566
25672567
25682568/* handler called by the YM2610 emulator when the internal timers cause an IRQ */
2569static void irqhandler(int irq)
2569static void irqhandler(running_machine *machine, int irq)
25702570{
2571   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
2571   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
25722572}
25732573
25742574static const struct YM2610interface ym2610_interface_rsaga2 =
src/mame/drivers/mw8080bw.c
r2724r2725
318318
319319static CUSTOM_INPUT( seawolf_erase_input_r )
320320{
321   return input_port_read(machine, SEAWOLF_ERASE_SW_PORT_TAG) &
322         input_port_read(machine, SEAWOLF_ERASE_DIP_PORT_TAG);
321   return input_port_read(field->port->machine, SEAWOLF_ERASE_SW_PORT_TAG) &
322         input_port_read(field->port->machine, SEAWOLF_ERASE_DIP_PORT_TAG);
323323}
324324
325325
r2724r2725
549549
550550static CUSTOM_INPUT( tornbase_hit_left_input_r )
551551{
552   return input_port_read(machine, TORNBASE_L_HIT_PORT_TAG);
552   return input_port_read(field->port->machine, TORNBASE_L_HIT_PORT_TAG);
553553}
554554
555555
r2724r2725
557557{
558558   UINT32 ret;
559559
560   switch (tornbase_get_cabinet_type(machine))
560   switch (tornbase_get_cabinet_type(field->port->machine))
561561   {
562562   case TORNBASE_CAB_TYPE_UPRIGHT_OLD:
563      ret = input_port_read(machine, TORNBASE_L_HIT_PORT_TAG);
563      ret = input_port_read(field->port->machine, TORNBASE_L_HIT_PORT_TAG);
564564      break;
565565
566566   case TORNBASE_CAB_TYPE_UPRIGHT_NEW:
567567   case TORNBASE_CAB_TYPE_COCKTAIL:
568568   default:
569      ret = input_port_read(machine, TORNBASE_R_HIT_PORT_TAG);
569      ret = input_port_read(field->port->machine, TORNBASE_R_HIT_PORT_TAG);
570570      break;
571571   }
572572
r2724r2725
578578{
579579   UINT32 ret;
580580
581   switch (tornbase_get_cabinet_type(machine))
581   switch (tornbase_get_cabinet_type(field->port->machine))
582582   {
583583   case TORNBASE_CAB_TYPE_UPRIGHT_OLD:
584584   case TORNBASE_CAB_TYPE_UPRIGHT_NEW:
585      ret = input_port_read(machine, TORNBASE_L_PITCH_PORT_TAG);
585      ret = input_port_read(field->port->machine, TORNBASE_L_PITCH_PORT_TAG);
586586      break;
587587
588588   case TORNBASE_CAB_TYPE_COCKTAIL:
589589   default:
590      ret = input_port_read(machine, TORNBASE_R_PITCH_PORT_TAG);
590      ret = input_port_read(field->port->machine, TORNBASE_R_PITCH_PORT_TAG);
591591      break;
592592   }
593593
r2724r2725
597597
598598static CUSTOM_INPUT( tornbase_pitch_right_input_r )
599599{
600   return input_port_read(machine, TORNBASE_L_PITCH_PORT_TAG);
600   return input_port_read(field->port->machine, TORNBASE_L_PITCH_PORT_TAG);
601601}
602602
603603
604604static CUSTOM_INPUT( tornbase_score_input_r )
605605{
606   return input_port_read(machine, TORNBASE_SCORE_SW_PORT_TAG) &
607         input_port_read(machine, TORNBASE_SCORE_DIP_PORT_TAG);
606   return input_port_read(field->port->machine, TORNBASE_SCORE_SW_PORT_TAG) &
607         input_port_read(field->port->machine, TORNBASE_SCORE_DIP_PORT_TAG);
608608}
609609
610610
r2724r2725
11811181   UINT32 ret;
11821182
11831183   if (desertgu_controller_select)
1184      ret = input_port_read(machine, DESERTGU_GUN_X_PORT_TAG);
1184      ret = input_port_read(field->port->machine, DESERTGU_GUN_X_PORT_TAG);
11851185   else
1186      ret = input_port_read(machine, DESERTGU_GUN_Y_PORT_TAG);
1186      ret = input_port_read(field->port->machine, DESERTGU_GUN_Y_PORT_TAG);
11871187
11881188   return ret;
11891189}
r2724r2725
11941194   UINT32 ret;
11951195
11961196   if (desertgu_controller_select)
1197      ret = input_port_read(machine, DESERTGU_DIP_SW_0_1_SET_2_TAG);
1197      ret = input_port_read(field->port->machine, DESERTGU_DIP_SW_0_1_SET_2_TAG);
11981198   else
1199      ret = input_port_read(machine, DESERTGU_DIP_SW_0_1_SET_1_TAG);
1199      ret = input_port_read(field->port->machine, DESERTGU_DIP_SW_0_1_SET_1_TAG);
12001200
12011201   return ret;
12021202}
r2724r2725
13071307{
13081308   UINT32 ret;
13091309
1310   if (input_port_read(machine, DPLAY_CAB_TYPE_PORT_TAG) == DPLAY_CAB_TYPE_UPRIGHT)
1311      ret = input_port_read(machine, DPLAY_L_PITCH_PORT_TAG);
1310   if (input_port_read(field->port->machine, DPLAY_CAB_TYPE_PORT_TAG) == DPLAY_CAB_TYPE_UPRIGHT)
1311      ret = input_port_read(field->port->machine, DPLAY_L_PITCH_PORT_TAG);
13121312   else
1313      ret = input_port_read(machine, DPLAY_R_PITCH_PORT_TAG);
1313      ret = input_port_read(field->port->machine, DPLAY_R_PITCH_PORT_TAG);
13141314
13151315   return ret;
13161316}
r2724r2725
13181318
13191319static CUSTOM_INPUT( dplay_pitch_right_input_r )
13201320{
1321   return input_port_read(machine, DPLAY_L_PITCH_PORT_TAG);
1321   return input_port_read(field->port->machine, DPLAY_L_PITCH_PORT_TAG);
13221322}
13231323
13241324
r2724r2725
16971697
16981698   if (clowns_controller_select)
16991699   {
1700      ret = input_port_read(machine, CLOWNS_CONTROLLER_P2_TAG);
1700      ret = input_port_read(field->port->machine, CLOWNS_CONTROLLER_P2_TAG);
17011701   }
17021702   else
17031703   {
1704      ret = input_port_read(machine, CLOWNS_CONTROLLER_P1_TAG);
1704      ret = input_port_read(field->port->machine, CLOWNS_CONTROLLER_P1_TAG);
17051705   }
17061706
17071707   return ret;
r2724r2725
24462446
24472447static CUSTOM_INPUT( invaders_coin_input_r )
24482448{
2449   UINT32 ret = input_port_read(machine, INVADERS_COIN_INPUT_PORT_TAG);
2449   UINT32 ret = input_port_read(field->port->machine, INVADERS_COIN_INPUT_PORT_TAG);
24502450
24512451   coin_counter_w(0, !ret);
24522452
r2724r2725
24612461   /* upright PCB : switches visible
24622462       cocktail PCB: HI */
24632463
2464   if (invaders_is_cabinet_cocktail(machine))
2464   if (invaders_is_cabinet_cocktail(field->port->machine))
24652465      ret = 0x03;
24662466   else
2467      ret = input_port_read(machine, INVADERS_SW6_SW7_PORT_TAG);
2467      ret = input_port_read(field->port->machine, INVADERS_SW6_SW7_PORT_TAG);
24682468
24692469   return ret;
24702470}
r2724r2725
24772477   /* upright PCB : switch visible
24782478       cocktail PCB: HI */
24792479
2480   if (invaders_is_cabinet_cocktail(machine))
2480   if (invaders_is_cabinet_cocktail(field->port->machine))
24812481      ret = 0x01;
24822482   else
2483      ret = input_port_read(machine, INVADERS_SW5_PORT_TAG);
2483      ret = input_port_read(field->port->machine, INVADERS_SW5_PORT_TAG);
24842484
24852485   return ret;
24862486}
r2724r2725
24932493   /* upright PCB : P1 controls
24942494       cocktail PCB: HI */
24952495
2496   if (invaders_is_cabinet_cocktail(machine))
2496   if (invaders_is_cabinet_cocktail(field->port->machine))
24972497      ret = 0x07;
24982498   else
2499      ret = input_port_read(machine, INVADERS_P1_CONTROL_PORT_TAG);
2499      ret = input_port_read(field->port->machine, INVADERS_P1_CONTROL_PORT_TAG);
25002500
25012501   return ret;
25022502}
r2724r2725
25092509   /* upright PCB : P1 controls
25102510       cocktail PCB: P2 controls */
25112511
2512   if (invaders_is_cabinet_cocktail(machine))
2513      ret = input_port_read(machine, INVADERS_P2_CONTROL_PORT_TAG);
2512   if (invaders_is_cabinet_cocktail(field->port->machine))
2513      ret = input_port_read(field->port->machine, INVADERS_P2_CONTROL_PORT_TAG);
25142514   else
2515      ret = input_port_read(machine, INVADERS_P1_CONTROL_PORT_TAG);
2515      ret = input_port_read(field->port->machine, INVADERS_P1_CONTROL_PORT_TAG);
25162516
25172517   return ret;
25182518}
r2724r2725
26462646
26472647static CUSTOM_INPUT( blueshrk_coin_input_r )
26482648{
2649   UINT32 ret = input_port_read(machine, BLUESHRK_COIN_INPUT_PORT_TAG);
2649   UINT32 ret = input_port_read(field->port->machine, BLUESHRK_COIN_INPUT_PORT_TAG);
26502650
26512651   coin_counter_w(0, !ret);
26522652
src/mame/drivers/suna8.c
r2724r2725
15181518
15191519***************************************************************************/
15201520
1521static void soundirq(int state)
1521static void soundirq(running_machine *machine, int state)
15221522{
1523   cpunum_set_input_line(Machine, 1, 0, state);
1523   cpunum_set_input_line(machine, 1, 0, state);
15241524}
15251525
15261526/* In games with only 2 CPUs, port A&B of the AY8910 are used
src/mame/drivers/vaportra.c
r2724r2725
99***************************************************************************/
1010
1111#include "driver.h"
12#include "deprecat.h"
1312#include "cpu/h6280/h6280.h"
1413#include "sound/2203intf.h"
1514#include "sound/2151intf.h"
r2724r2725
231230
232231/******************************************************************************/
233232
234static void sound_irq(int state)
233static void sound_irq(running_machine *machine, int state)
235234{
236   cpunum_set_input_line(Machine, 1,1,state); /* IRQ 2 */
235   cpunum_set_input_line(machine, 1,1,state); /* IRQ 2 */
237236}
238237
239238static const struct YM2151interface ym2151_interface =
src/mame/drivers/btime.c
r2724r2725
386386static INPUT_CHANGED( coin_inserted_irq_hi )
387387{
388388   if (newval)
389      cpunum_set_input_line(machine, 0, 0, HOLD_LINE);
389      cpunum_set_input_line(field->port->machine, 0, 0, HOLD_LINE);
390390}
391391
392392static INPUT_CHANGED( coin_inserted_irq_lo )
393393{
394394   if (!newval)
395      cpunum_set_input_line(machine, 0, 0, HOLD_LINE);
395      cpunum_set_input_line(field->port->machine, 0, 0, HOLD_LINE);
396396}
397397
398398static INPUT_CHANGED( coin_inserted_nmi_lo )
399399{
400   cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, newval ? CLEAR_LINE : ASSERT_LINE);
400   cpunum_set_input_line(field->port->machine, 0, INPUT_LINE_NMI, newval ? CLEAR_LINE : ASSERT_LINE);
401401}
402402
403403
src/mame/drivers/qdrmfgp.c
r2724r2725
593593 *
594594 *************************************/
595595
596static void sound_irq(void)
596static void sound_irq(running_machine *machine)
597597{
598598   if (control & 0x0001)
599      cpunum_set_input_line(Machine, 0, 1, HOLD_LINE);
599      cpunum_set_input_line(machine, 0, 1, HOLD_LINE);
600600}
601601
602602static const struct K054539interface k054539_interface =
src/mame/drivers/cps1.c
r2724r2725
153153***************************************************************************/
154154
155155#include "driver.h"
156#include "deprecat.h"
157156#include "machine/eeprom.h"
158157#include "sound/2151intf.h"
159158#include "sound/okim6295.h"
r2724r2725
35033502
35043503
35053504
3506static void cps1_irq_handler_mus(int irq)
3505static void cps1_irq_handler_mus(running_machine *machine, int irq)
35073506{
3508   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
3507   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
35093508}
35103509
35113510static const struct YM2151interface ym2151_interface =
src/mame/drivers/yunsun16.c
r2724r2725
8686***************************************************************************/
8787
8888#include "driver.h"
89#include "deprecat.h"
9089#include "sound/okim6295.h"
9190#include "sound/3812intf.h"
9291
r2724r2725
571570                                Magic Bubble
572571***************************************************************************/
573572
574static void soundirq(int state)
573static void soundirq(running_machine *machine, int state)
575574{
576   cpunum_set_input_line(Machine, 1, 0, state);
575   cpunum_set_input_line(machine, 1, 0, state);
577576}
578577
579578static const struct YM3812interface magicbub_ym3812_intf =
src/mame/drivers/stactics.c
r2724r2725
5454
5555static CUSTOM_INPUT( get_motor_not_ready )
5656{
57   stactics_state *state = machine->driver_data;
57   stactics_state *state = field->port->machine->driver_data;
5858
5959   /* if the motor is self-centering, but not centered yet */
6060    return ((*state->motor_on & 0x01) == 0) &&
r2724r2725
129129static CUSTOM_INPUT( get_rng )
130130{
131131   /* this is a 555 timer, but cannot read one of the resistor values */
132   return mame_rand(machine) & 0x07;
132   return mame_rand(field->port->machine) & 0x07;
133133}
134134
135135
src/mame/drivers/lethalj.c
r2724r2725
6464
6565static CUSTOM_INPUT( ticket_status )
6666{
67   return ticket_dispenser_0_r(machine, 0) >> 7;
67   return ticket_dispenser_0_r(field->port->machine, 0) >> 7;
6868}
6969
7070
7171static CUSTOM_INPUT( cclownz_paddle )
7272{
73   int value = input_port_read(machine, "PADDLE");
73   int value = input_port_read(field->port->machine, "PADDLE");
7474   return ((value << 4) & 0xf00) | (value & 0x00f);
7575}
7676
src/mame/drivers/itech8.c
r2724r2725
453453
454454
455455#include "driver.h"
456#include "deprecat.h"
457456#include "cpu/m6809/m6809.h"
458457#include "machine/6821pia.h"
459458#include "machine/6522via.h"
r2724r2725
519518 *
520519 *************************************/
521520
522static void via_irq(int state);
521static void via_irq(running_machine *machine, int state);
523522
524523static const struct via6522_interface via_interface =
525524{
r2724r2725
596595}
597596
598597
599static void generate_sound_irq(int state)
598static void generate_sound_irq(running_machine *machine, int state)
600599{
601   cpunum_set_input_line(Machine, 1, M6809_FIRQ_LINE, state ? ASSERT_LINE : CLEAR_LINE);
600   cpunum_set_input_line(machine, 1, M6809_FIRQ_LINE, state ? ASSERT_LINE : CLEAR_LINE);
602601}
603602
604603
r2724r2725
815814 *
816815 *************************************/
817816
818static void via_irq(int state)
817static void via_irq(running_machine *machine, int state)
819818{
820819   if (state)
821      cpunum_set_input_line(Machine, 1, M6809_FIRQ_LINE, ASSERT_LINE);
820      cpunum_set_input_line(machine, 1, M6809_FIRQ_LINE, ASSERT_LINE);
822821   else
823      cpunum_set_input_line(Machine, 1, M6809_FIRQ_LINE, CLEAR_LINE);
822      cpunum_set_input_line(machine, 1, M6809_FIRQ_LINE, CLEAR_LINE);
824823}
825824
826825
r2724r2725
869868      mame_fread(file, main_ram, main_ram_size);
870869   else
871870      for (i = 0; i < main_ram_size; i++)
872         main_ram[i] = mame_rand(Machine);
871         main_ram[i] = mame_rand(machine);
873872}
874873
875874
src/mame/drivers/galaxian.c
r2724r2725
841841
842842   /* select the bank and graphics bank based on it */
843843   memory_set_bank(1, gmgalax_selected_game);
844   galaxian_gfxbank_w(machine, 0, gmgalax_selected_game);
844   galaxian_gfxbank_w(field->port->machine, 0, gmgalax_selected_game);
845845
846846   /* reset the starts */
847   galaxian_stars_enable_w(machine, 0, 0);
847   galaxian_stars_enable_w(field->port->machine, 0, 0);
848848
849849   /* reset the CPU */
850   cpunum_set_input_line(machine, 0, INPUT_LINE_RESET, PULSE_LINE);
850   cpunum_set_input_line(field->port->machine, 0, INPUT_LINE_RESET, PULSE_LINE);
851851}
852852
853853
r2724r2725
856856   const char *portname = param;
857857   if (gmgalax_selected_game != 0)
858858      portname += strlen(portname) + 1;
859   return input_port_read(machine, portname);
859   return input_port_read(field->port->machine, portname);
860860}
861861
862862
r2724r2725
912912
913913static CUSTOM_INPUT( azurian_port_r )
914914{
915   return (input_port_read(machine, "FAKE") >> (FPTR)param) & 1;
915   return (input_port_read(field->port->machine, "FAKE") >> (FPTR)param) & 1;
916916}
917917
918918
r2724r2725
926926static CUSTOM_INPUT( kingball_muxbit_r )
927927{
928928   /* multiplex the service mode switch with a speech DIP switch */
929   return (input_port_read(machine, "FAKE") >> kingball_speech_dip) & 1;
929   return (input_port_read(field->port->machine, "FAKE") >> kingball_speech_dip) & 1;
930930}
931931
932932
r2724r2725
935935   /* bit 5 is the NOISE line from the sound circuit.  The code just verifies
936936       that it's working, doesn't actually use return value, so we can just use
937937       rand() */
938   return mame_rand(machine) & 1;
938   return mame_rand(field->port->machine) & 1;
939939}
940940
941941
r2724r2725
23232323   memory_configure_bank(1, 0, 2, memory_region(REGION_CPU1) + 0x10000, 0x4000);
23242324
23252325   /* callback when the game select is toggled */
2326   gmgalax_game_changed(machine, NULL, 0, 0);
2326   gmgalax_game_changed(machine->portconfig->fieldlist, NULL, 0, 0);
23272327   state_save_register_global(gmgalax_selected_game);
23282328}
23292329
src/mame/drivers/othldrby.c
r2724r2725
1515***************************************************************************/
1616
1717#include "driver.h"
18#include "deprecat.h"
1918#include "sound/okim6295.h"
2019
2120
r2724r2725
3938
4039static READ16_HANDLER( pap )
4140{
42   return mame_rand(Machine);
41   return mame_rand(machine);
4342}
4443
4544
src/mame/drivers/bbusters.c
r2724r2725
666666
667667/******************************************************************************/
668668
669static void sound_irq( int irq )
669static void sound_irq( running_machine *machine, int irq )
670670{
671   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
671   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
672672}
673673
674674static const struct YM2608interface ym2608_interface =
675675{
676676   {
677      AY8910_LEGACY_OUTPUT,
677      AY8910_LEGACY_OUTPUT | AY8910_SINGLE_OUTPUT,
678678      AY8910_DEFAULT_LOADS,
679679      NULL, NULL, NULL, NULL
680680   },
src/mame/drivers/gstriker.c
r2724r2725
3333******************************************************************************/
3434
3535#include "driver.h"
36#include "deprecat.h"
3736#include "gstriker.h"
3837#include "sound/2610intf.h"
3938
r2724r2725
271270
272271/*** MORE SOUND RELATED ******************************************************/
273272
274static void gs_ym2610_irq(int irq)
273static void gs_ym2610_irq(running_machine *machine, int irq)
275274{
276275   if (irq)
277      cpunum_set_input_line(Machine, 1, 0, ASSERT_LINE);
276      cpunum_set_input_line(machine, 1, 0, ASSERT_LINE);
278277   else
279      cpunum_set_input_line(Machine, 1, 0, CLEAR_LINE);
278      cpunum_set_input_line(machine, 1, 0, CLEAR_LINE);
280279}
281280
282281static const struct YM2610interface ym2610_interface =
src/mame/drivers/snk.c
r2724r2725
247247}
248248
249249// NMI handshakes between CPUs are determined to be much simpler
250READ8_HANDLER ( snk_cpuA_nmi_trigger_r ) { cpunum_set_input_line(Machine, 0, INPUT_LINE_NMI, ASSERT_LINE); return 0; }
251WRITE8_HANDLER( snk_cpuA_nmi_ack_w ) { cpunum_set_input_line(Machine, 0, INPUT_LINE_NMI, CLEAR_LINE); }
250READ8_HANDLER ( snk_cpuA_nmi_trigger_r ) { cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, ASSERT_LINE); return 0; }
251WRITE8_HANDLER( snk_cpuA_nmi_ack_w ) { cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, CLEAR_LINE); }
252252
253READ8_HANDLER ( snk_cpuB_nmi_trigger_r ) { cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, ASSERT_LINE); return 0; }
254WRITE8_HANDLER( snk_cpuB_nmi_ack_w ) { cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, CLEAR_LINE); }
253READ8_HANDLER ( snk_cpuB_nmi_trigger_r ) { cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, ASSERT_LINE); return 0; }
254WRITE8_HANDLER( snk_cpuB_nmi_ack_w ) { cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, CLEAR_LINE); }
255255
256256/*********************************************************************/
257257
r2724r2725
357357   return snk_sound_register;// | 0x2; /* hack; lets chopper1 play music */
358358}
359359
360static void snk_sound_callback0_w( int state ){ /* ? */
360static void snk_sound_callback0_w( running_machine *machine, int state ){ /* ? */
361361   if( state ) snk_sound_register |= 0x01;
362362}
363363
364static void snk_sound_callback1_w( int state ){ /* ? */
364static void snk_sound_callback1_w( running_machine *machine, int state ){ /* ? */
365365   if( state ) snk_sound_register |= 0x02;
366366}
367367
src/mame/drivers/hyprduel.c
r2724r2725
9393      COMBINE_DATA(&hypr_sub_sharedram2_2[offset-0x4000/2]);
9494}
9595
96static void update_irq_state(void)
96static void update_irq_state(running_machine *machine)
9797{
9898   int irq = requested_int & ~*hypr_irq_enable;
9999
100   cpunum_set_input_line(Machine, 0, 3, (irq & int_num) ? ASSERT_LINE : CLEAR_LINE);
100   cpunum_set_input_line(machine, 0, 3, (irq & int_num) ? ASSERT_LINE : CLEAR_LINE);
101101}
102102
103103static READ16_HANDLER( hyprduel_irq_cause_r )
r2724r2725
114114      else
115115         requested_int &= ~(data & *hypr_irq_enable);
116116
117      update_irq_state();
117      update_irq_state(machine);
118118   }
119119}
120120
r2724r2725
204204      rastersplit = line + 1;
205205   }
206206
207   update_irq_state();
207   update_irq_state(machine);
208208}
209209
210210static MACHINE_RESET( hyprduel )
r2724r2725
291291static TIMER_CALLBACK( hyprduel_blit_done )
292292{
293293   requested_int |= 1 << blitter_bit;
294   update_irq_state();
294   update_irq_state(machine);
295295}
296296
297297INLINE int blt_read(const UINT8 *ROM, const int offs)
r2724r2725
691691                            Sound Communication
692692***************************************************************************/
693693
694static void sound_irq(int state)
694static void sound_irq(running_machine *machine, int state)
695695{
696   cpunum_set_input_line(Machine, 1, 1, HOLD_LINE);
696   cpunum_set_input_line(machine, 1, 1, HOLD_LINE);
697697}
698698
699699static const struct YM2151interface ym2151_interface =
src/mame/drivers/namconb1.c
r2724r2725
525525
526526   do
527527   { /* pick a random number, but don't pick the same twice in a row */
528      count = mame_rand(Machine);
528      count = mame_rand(machine);
529529   } while( count==old_count );
530530
531531   switch( namcos2_gametype )
r2724r2725
675675static
676676READ32_HANDLER( randgen_r )
677677{
678   return mame_rand(Machine);
678   return mame_rand(machine);
679679} /* randgen_r */
680680
681681static
src/mame/drivers/flstory.c
r2724r2725
373373   PORT_DIPNAME( 0x20, 0x20, "Leave Off")      // Check code at 0x7859
374374   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )      // (must be OFF or the game will
375375   PORT_DIPSETTING(    0x00, DEF_STR( On ) )         // hang after the game is over !)
376   PORT_BIT(    0x40, 0x40, IPT_DIPSWITCH_NAME ) PORT_NAME("Invulnerability (Cheat)")
376   PORT_DIPNAME( 0x40, 0x40, "Invulnerability (Cheat)" )
377377   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
378378   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
379379   PORT_DIPNAME( 0x80, 0x80, "Coin Slots" )
src/mame/drivers/fcrash.c
r2724r2725
3333*/
3434
3535#include "driver.h"
36#include "deprecat.h"
3736#include "cpu/m68000/m68kmame.h"
3837#include "cps1.h"
3938#include "sound/2203intf.h"
r2724r2725
6463   memory_set_bankptr(1,&RAM[0x10000 + bankaddr]);
6564}
6665
67static void m5205_int1(int data)
66static void m5205_int1(running_machine *machine, int data)
6867{
6968   MSM5205_data_w(0, sample_buffer1 & 0x0F);
7069   sample_buffer1 >>= 4;
7170   sample_select1 ^= 1;
7271   if (sample_select1 == 0)
73      cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, PULSE_LINE);
72      cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, PULSE_LINE);
7473}
7574
76static void m5205_int2(int data)
75static void m5205_int2(running_machine *machine, int data)
7776{
7877   MSM5205_data_w(1, sample_buffer2 & 0x0F);
7978   sample_buffer2 >>= 4;
src/mame/drivers/suprslam.c
r2724r2725
8181******************************************************************************/
8282
8383#include "driver.h"
84#include "deprecat.h"
8584#include "video/konamiic.h"
8685#include "sound/2610intf.h"
8786
r2724r2725
312311
313312/*** MORE SOUND **************************************************************/
314313
315static void irqhandler(int irq)
314static void irqhandler(running_machine *machine, int irq)
316315{
317   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
316   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
318317}
319318
320319static const struct YM2610interface ym2610_interface =
src/mame/drivers/strnskil.c
r2724r2725
5151      case 0x6066:   res = 0xa5;   break;
5252      case 0x60dc:   res = 0x20;   break;   /* bits 0-3 unknown */
5353      case 0x615d:   res = 0x30;   break;   /* bits 0-3 unknown */
54      case 0x61b9:   res = 0x60|(mame_rand(Machine)&0x0f);   break;   /* bits 0-3 unknown */
54      case 0x61b9:   res = 0x60|(mame_rand(machine)&0x0f);   break;   /* bits 0-3 unknown */
5555      case 0x6219:   res = 0x77;   break;
5656      case 0x626c:   res = 0xb4;   break;
5757      default:      res = 0xff; break;
r2724r2725
7070      case 0x6094:   res = 0xa5;   break;
7171      case 0x6118:   res = 0x20;   break;   /* bits 0-3 unknown */
7272      case 0x6199:   res = 0x30;   break;   /* bits 0-3 unknown */
73      case 0x61f5:   res = 0x60|(mame_rand(Machine)&0x0f);   break;   /* bits 0-3 unknown */
73      case 0x61f5:   res = 0x60|(mame_rand(machine)&0x0f);   break;   /* bits 0-3 unknown */
7474      case 0x6255:   res = 0x77;   break;
7575      case 0x62a8:   res = 0xb4;   break;
7676      default:      res = 0xff; break;
src/mame/drivers/dgpix.c
r2724r2725
2626    You could even multiply the PC by the stack pointer if you wanted."
2727
2828
29
3029 driver by Pierpaolo Prazzoli & Tomasz Slanina
3130
3231 - Pierpaolo Prazzoli 2006.05.06
src/mame/drivers/sangho.c
r2724r2725
212212   sangho_common_machine_reset();
213213}
214214
215static void msx_vdp_interrupt(int i)
215static void msx_vdp_interrupt(running_machine *machine, int i)
216216{
217   cpunum_set_input_line (Machine, 0, 0, (i ? HOLD_LINE : CLEAR_LINE));
217   cpunum_set_input_line (machine, 0, 0, (i ? HOLD_LINE : CLEAR_LINE));
218218}
219219
220220static INTERRUPT_GEN( sangho_interrupt )
src/mame/drivers/model2.c
r2724r2725
16871687
16881688static int scsp_last_line = 0;
16891689
1690static void scsp_irq(int irq)
1690static void scsp_irq(running_machine *machine, int irq)
16911691{
16921692   if (irq > 0)
16931693   {
16941694      scsp_last_line = irq;
1695      cpunum_set_input_line(Machine, 1, irq, PULSE_LINE);
1695      cpunum_set_input_line(machine, 1, irq, PULSE_LINE);
16961696   }
16971697}
16981698
src/mame/drivers/bmcbowl.c
r2724r2725
175175
176176static READ16_HANDLER( bmc_random_read )
177177{
178   return mame_rand(Machine);
178   return mame_rand(machine);
179179}
180180
181181static READ16_HANDLER( bmc_protection_r )
r2724r2725
192192         break;
193193   }
194194   logerror("Protection read @ %X\n",activecpu_get_previouspc());
195   return mame_rand(Machine);
195   return mame_rand(machine);
196196}
197197
198198static WRITE16_HANDLER( bmc_RAMDAC_offset_w )
r2724r2725
245245}
246246
247247
248static void via_irq(int state)
248static void via_irq(running_machine *machine, int state)
249249{
250250   //used
251251}
src/mame/drivers/sshangha.c
r2724r2725
5252***************************************************************************/
5353
5454#include "driver.h"
55#include "deprecat.h"
5655#include "sound/2203intf.h"
5756#include "sound/okim6295.h"
5857
r2724r2725
327326
328327/******************************************************************************/
329328
330static void irqhandler(int state)
329static void irqhandler(running_machine *machine, int state)
331330{
332   cpunum_set_input_line(Machine, 1,0,state);
331   cpunum_set_input_line(machine, 1,0,state);
333332}
334333
335334static const struct YM2203interface ym2203_interface =
src/mame/drivers/compgolf.c
r2724r2725
1111****************************************************************************************/
1212
1313#include "driver.h"
14#include "deprecat.h"
1514#include "sound/2203intf.h"
1615
1716extern UINT8 *compgolf_bg_ram;
r2724r2725
194193
195194/***************************************************************************/
196195
197static void sound_irq(int linestate)
196static void sound_irq(running_machine *machine, int linestate)
198197{
199   cpunum_set_input_line(Machine, 0,0,linestate);
198   cpunum_set_input_line(machine, 0,0,linestate);
200199}
201200
202201static const struct YM2203interface ym2203_interface =
src/mame/drivers/lordgun.c
r2724r2725
2626***************************************************************************/
2727
2828#include "driver.h"
29#include "deprecat.h"
3029#include "machine/8255ppi.h"
3130#include "machine/eeprom.h"
3231#include "sound/3812intf.h"
r2724r2725
427426   }
428427};
429428
430static void soundirq(int state)
429static void soundirq(running_machine *machine, int state)
431430{
432   cpunum_set_input_line(Machine, 1, 0, state);
431   cpunum_set_input_line(machine, 1, 0, state);
433432}
434433
435434static const struct YM3812interface lordgun_ym3812_interface =
src/mame/drivers/lemmings.c
r2724r2725
1616***************************************************************************/
1717
1818#include "driver.h"
19#include "deprecat.h"
2019#include "lemmings.h"
2120#include "sound/2151intf.h"
2221#include "sound/okim6295.h"
r2724r2725
260259
261260/******************************************************************************/
262261
263static void sound_irq(int state)
262static void sound_irq(running_machine *machine, int state)
264263{
265   cpunum_set_input_line(Machine, 1,0,state);
264   cpunum_set_input_line(machine, 1,0,state);
266265}
267266
268267static const struct YM2151interface ym2151_interface =
src/mame/drivers/pushman.c
r2724r2725
2222***************************************************************************/
2323
2424#include "driver.h"
25#include "deprecat.h"
2625#include "cpu/z80/z80.h"
2726#include "cpu/m6805/m6805.h"
2827#include "sound/2203intf.h"
r2724r2725
419418
420419/******************************************************************************/
421420
422static void irqhandler(int irq)
421static void irqhandler(running_machine *machine, int irq)
423422{
424    cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
423   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
425424}
426425
427426static const struct YM2203interface ym2203_interface =
src/mame/drivers/hyperspt.c
r2724r2725
6363*/
6464static UINT8 *nvram;
6565static size_t nvram_size;
66static int we_flipped_the_switch;
6766
6867static NVRAM_HANDLER( hyperspt )
6968{
7069   if (read_or_write)
71   {
7270      mame_fwrite(file,nvram,nvram_size);
73
74      if (we_flipped_the_switch)
75      {
76         input_port_entry *in;
77
78
79         /* find the dip switch which resets the high score table, and set it */
80         /* back to off. */
81         in = machine->input_ports;
82
83         while (in->type != IPT_END)
84         {
85            if (in->name != NULL && in->name != IP_NAME_DEFAULT &&
86                  strcmp(in->name,"World Records") == 0)
87            {
88               if (in->default_value == 0)
89                  in->default_value = in->mask;
90               break;
91            }
92
93            in++;
94         }
95
96         we_flipped_the_switch = 0;
97      }
98   }
99   else
100   {
101      if (file)
102      {
103         mame_fread(file,nvram,nvram_size);
104         we_flipped_the_switch = 0;
105      }
106      else
107      {
108         input_port_entry *in;
109
110
111         /* find the dip switch which resets the high score table, and set it on */
112         in = machine->input_ports;
113
114         while (in->type != IPT_END)
115         {
116            if (in->name != NULL && in->name != IP_NAME_DEFAULT &&
117                  strcmp(in->name,"World Records") == 0)
118            {
119               if (in->default_value == in->mask)
120               {
121                  in->default_value = 0;
122                  we_flipped_the_switch = 1;
123               }
124               break;
125            }
126
127            in++;
128         }
129      }
130   }
71   else if (file)
72      mame_fread(file,nvram,nvram_size);
13173}
13274
13375
src/mame/drivers/toaplan1.c
r2724r2725
6262***************************************************************************/
6363
6464#include "driver.h"
65#include "deprecat.h"
6665#include "cpu/tms32010/tms32010.h"
6766#include "toaplan1.h"
6867#include "sound/3812intf.h"
r2724r2725
11041103   PORT_INCLUDE( vimana )
11051104
11061105   PORT_MODIFY("DSWA")      /* DSW A */
1106   PORT_DIPNAME( 0x08, 0x00, DEF_STR( Unused ) )
11071107   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
11081108   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
11091109   PORT_DIPNAME( 0x10, 0x00, DEF_STR( Unused ) )
r2724r2725
12081208GFXDECODE_END
12091209
12101210
1211static void irqhandler(int linestate)
1211static void irqhandler(running_machine *machine, int linestate)
12121212{
1213   cpunum_set_input_line(Machine, 1,0,linestate);
1213   cpunum_set_input_line(machine, 1,0,linestate);
12141214}
12151215
12161216static const struct YM3812interface ym3812_interface =
src/mame/drivers/segag80r.c
r2724r2725
160160{
161161   /* pressing the service switch sends an NMI */
162162   if (newval)
163      cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, PULSE_LINE);
163      cpunum_set_input_line(field->port->machine, 0, INPUT_LINE_NMI, PULSE_LINE);
164164}
165165
166166
src/mame/drivers/hnayayoi.c
r2724r2725
595595
596596
597597
598static void irqhandler(int irq)
598static void irqhandler(running_machine *machine, int irq)
599599{
600600popmessage("irq");
601//  cpunum_set_input_line(Machine, 2,0,irq ? ASSERT_LINE : CLEAR_LINE);
601//  cpunum_set_input_line(machine, 2,0,irq ? ASSERT_LINE : CLEAR_LINE);
602602}
603603
604604
src/mame/drivers/shanghai.c
r2724r2725
2020***************************************************************************/
2121
2222#include "driver.h"
23#include "deprecat.h"
2423#include "audio/seibu.h"
2524
2625/* the on-chip FIFO is 16 bytes long, but we use a larger one to simplify */
r2724r2725
788787
789788static READ16_HANDLER(shanghai_rand_r)
790789{
791   return mame_rand(Machine);
790   return mame_rand(machine);
792791}
793792
794793static READ16_HANDLER( kothello_HD63484_status_r )
src/mame/drivers/tmnt.c
r2724r2725
372372   /* 0xffffff, and returning 0 causes the game to mess up - locking up in a */
373373   /* loop where the ball is continuously bouncing from the basket. Returning */
374374   /* a random number seems to prevent that. */
375   return mame_rand(Machine);
375   return mame_rand(machine);
376376}
377377
378378
r2724r2725
22852285INPUT_PORTS_END
22862286
22872287
2288static void cuebrick_irq_handler(int state)
2288static void cuebrick_irq_handler(running_machine *machine, int state)
22892289{
22902290   cuebrick_snd_irqlatch = state;
22912291}
r2724r2725
26272627MACHINE_DRIVER_END
26282628
26292629
2630static void sound_nmi(void)
2630static void sound_nmi(running_machine *machine)
26312631{
2632   cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, PULSE_LINE);
2632   cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, PULSE_LINE);
26332633}
26342634
26352635static const struct K054539interface k054539_interface =
src/mame/drivers/jpmimpct.c
r2724r2725
154154 *
155155 *************************************/
156156
157static void update_irqs(void)
157static void update_irqs(running_machine *machine)
158158{
159159   int newstate = 0;
160160
r2724r2725
164164      newstate = 5;
165165
166166   if (newstate)
167      cpunum_set_input_line(Machine, 0, newstate, ASSERT_LINE);
167      cpunum_set_input_line(machine, 0, newstate, ASSERT_LINE);
168168   else
169      cpunum_set_input_line(Machine, 0, 7, CLEAR_LINE);
169      cpunum_set_input_line(machine, 0, 7, CLEAR_LINE);
170170}
171171
172172
r2724r2725
250250   duart_1.ISR |= 0x08;
251251
252252   duart_1_irq = 1;
253   update_irqs();
253   update_irqs(machine);
254254}
255255
256256static READ16_HANDLER( duart_1_r )
r2724r2725
307307      case 0xf:
308308      {
309309         duart_1_irq = 0;
310         update_irqs();
310         update_irqs(machine);
311311         duart_1.ISR |= ~0x8;
312312         break;
313313      }
r2724r2725
815815static void jpmimpct_tms_irq(int state)
816816{
817817   tms_irq = state;
818   update_irqs();
818   update_irqs(Machine);
819819}
820820
821821static const tms34010_config tms_config =
src/mame/drivers/namcos12.c
r2724r2725
13821382
13831383static READ8_HANDLER( s12_mcu_gun_h_r )
13841384{
1385   int index = port_tag_to_index("IN3");
1386   if( index != -1 )
1385   const input_port_config *port = input_port_by_tag(machine->portconfig, "IN3");
1386   if( port != NULL )
13871387   {
1388      int rv = input_port_read_indexed(machine, index ) << 6;
1388      int rv = input_port_read_direct( port ) << 6;
13891389
13901390      if( ( offset & 1 ) != 0 )
13911391      {
r2724r2725
14011401
14021402static READ8_HANDLER( s12_mcu_gun_v_r )
14031403{
1404   int index = port_tag_to_index("IN4");
1405   if( index != -1 )
1404   const input_port_config *port = input_port_by_tag(machine->portconfig, "IN4");
1405   if( port != NULL )
14061406   {
1407      int rv = input_port_read_indexed(machine, index ) << 6;
1407      int rv = input_port_read_direct( port ) << 6;
14081408
14091409      if( ( offset & 1 ) != 0 )
14101410      {
src/mame/drivers/scramble.c
r2724r2725
928928   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_4WAY
929929   PORT_SERVICE( 0x20, IP_ACTIVE_HIGH )
930930   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY
931   PORT_BIT(    0x80, 0x00, IPT_DIPSWITCH_NAME ) PORT_NAME("Rack Test (Cheat)") PORT_CODE(KEYCODE_F1)
931   PORT_DIPNAME( 0x80, 0x00, "Rack Test (Cheat)" ) PORT_CODE(KEYCODE_F1)
932932   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
933933   PORT_DIPSETTING(    0x80, DEF_STR( On ) )
934934INPUT_PORTS_END
src/mame/drivers/system18.c
r2724r2725
6262*/
6363
6464#include "driver.h"
65#include "deprecat.h"
6665#include "cpu/z80/z80.h"
6766#include "system16.h"
6867#include "cpu/m68000/m68000.h"
r2724r2725
175174   sample_buffer = data;
176175}
177176
178static void shdancbl_msm5205_callback(int data)
177static void shdancbl_msm5205_callback(running_machine *machine, int data)
179178{
180179   MSM5205_data_w(0, sample_buffer & 0x0F);
181180   sample_buffer >>= 4;
182181   sample_select ^= 1;
183182   if(sample_select == 0)
184      cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, PULSE_LINE);
183      cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, PULSE_LINE);
185184}
186185
187186static const struct MSM5205interface shdancbl_msm5205_interface =
src/mame/drivers/taitojc.c
r2724r2725
350350*/
351351
352352#include "driver.h"
353#include "deprecat.h"
354353#include "taito_f3.h"
355354#include "cpu/mc68hc11/mc68hc11.h"
356355#include "sound/es5506.h"
r2724r2725
455454      {
456455         if (ACCESSING_BITS_24_31)
457456         {
458            //r |= (mame_rand(Machine) & 0xff) << 24;
457            //r |= (mame_rand(machine) & 0xff) << 24;
459458         }
460459         return r;
461460      }
src/mame/drivers/missb2.c
r2724r2725
343343/* Sound Interfaces */
344344
345345// Handler called by the 3526 emulator when the internal timers cause an IRQ
346static void irqhandler(int irq)
346static void irqhandler(running_machine *machine, int irq)
347347{
348348   logerror("YM3526 firing an IRQ\n");
349//  cpunum_set_input_line(Machine, 2,0,irq ? ASSERT_LINE : CLEAR_LINE);
349//  cpunum_set_input_line(machine, 2,0,irq ? ASSERT_LINE : CLEAR_LINE);
350350}
351351
352352static const struct YM3526interface ym3526_interface =
src/mame/drivers/ddealer.c
r2724r2725
103103
104104
105105#include "driver.h"
106#include "deprecat.h"
107106
108107static UINT16 *shared_ram;
109108
r2724r2725
230229   if (resp[respcount]<0)
231230   {
232231       respcount = 0;
233       ddealer_protection(Machine);
232       ddealer_protection(machine);
234233
235234   }
236235   return res;
src/mame/drivers/berzerk.c
r2724r2725
665665   PORT_DIPSETTING(    0x00, DEF_STR( Cocktail ) )
666666
667667   PORT_START      /* IN3 */
668   PORT_BIT(    0x01, 0x00, IPT_DIPSWITCH_NAME ) PORT_NAME("Input Test Mode") PORT_CODE(KEYCODE_F2) PORT_TOGGLE PORT_DIPLOCATION("F3:1")
668   PORT_DIPNAME( 0x01, 0x00, "Input Test Mode" ) PORT_CODE(KEYCODE_F2) PORT_TOGGLE PORT_DIPLOCATION("F3:1")
669669   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
670670   PORT_DIPSETTING(    0x01, DEF_STR( On ) )
671   PORT_BIT(    0x02, 0x00, IPT_DIPSWITCH_NAME ) PORT_NAME("Crosshair Pattern") PORT_CODE(KEYCODE_F4) PORT_TOGGLE PORT_DIPLOCATION("F3:2")
671   PORT_DIPNAME( 0x02, 0x00, "Crosshair Pattern" ) PORT_CODE(KEYCODE_F4) PORT_TOGGLE PORT_DIPLOCATION("F3:2")
672672   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
673673   PORT_DIPSETTING(    0x02, DEF_STR( On ) )
674674   PORT_BIT( 0x3c, IP_ACTIVE_LOW,  IPT_UNUSED )
r2724r2725
679679   PORT_DIPSETTING(    0xc0, DEF_STR( Spanish ) )
680680
681681   PORT_START      /* IN4 */
682   PORT_BIT(    0x03, 0x00, IPT_DIPSWITCH_NAME ) PORT_NAME("Color Test") PORT_CODE(KEYCODE_F5) PORT_TOGGLE PORT_DIPLOCATION("F2:1,2")
682   PORT_DIPNAME( 0x03, 0x00, "Color Test" ) PORT_CODE(KEYCODE_F5) PORT_TOGGLE PORT_DIPLOCATION("F2:1,2")
683683   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
684684   PORT_DIPSETTING(    0x03, DEF_STR( On ) )
685685   PORT_BIT( 0x3c, IP_ACTIVE_LOW,  IPT_UNUSED )
r2724r2725
768768
769769   PORT_START      /* IN4 */
770770   PORT_BIT( 0x03, IP_ACTIVE_HIGH, IPT_UNUSED )  /* Bit 0 does some more hardware tests */
771   PORT_BIT(    0x04, 0x00, IPT_DIPSWITCH_NAME ) PORT_NAME("Input Test Mode") PORT_CODE(KEYCODE_F2) PORT_TOGGLE
771   PORT_DIPNAME( 0x04, 0x00, "Input Test Mode" ) PORT_CODE(KEYCODE_F2) PORT_TOGGLE
772772   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
773773   PORT_DIPSETTING(    0x04, DEF_STR( On ) )
774   PORT_BIT(    0x08, 0x00, IPT_DIPSWITCH_NAME ) PORT_NAME("Crosshair Pattern") PORT_CODE(KEYCODE_F4) PORT_TOGGLE
774   PORT_DIPNAME( 0x08, 0x00, "Crosshair Pattern" ) PORT_CODE(KEYCODE_F4) PORT_TOGGLE
775775   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
776776   PORT_DIPSETTING(    0x08, DEF_STR( On ) )
777777   PORT_BIT( 0xf0, IP_ACTIVE_LOW, IPT_UNUSED )
src/mame/drivers/tehkanwc.c
r2724r2725
212212   MSM5205_reset_w(0,data ? 0 : 1);
213213}
214214
215static void tehkanwc_adpcm_int (int data)
215static void tehkanwc_adpcm_int(running_machine *machine, int data)
216216{
217217   static int toggle;
218218
src/mame/drivers/suprridr.c
r2724r2725
228228
229229   /* screen flip multiplexes controls */
230230   if (suprridr_is_screen_flipped())
231      ret = input_port_read(machine, SUPRRIDR_P2_CONTROL_PORT_TAG);
231      ret = input_port_read(field->port->machine, SUPRRIDR_P2_CONTROL_PORT_TAG);
232232   else
233      ret = input_port_read(machine, SUPRRIDR_P1_CONTROL_PORT_TAG);
233      ret = input_port_read(field->port->machine, SUPRRIDR_P1_CONTROL_PORT_TAG);
234234
235235   return ret;
236236}
src/mame/drivers/spy.c
r2724r2725
1818***************************************************************************/
1919
2020#include "driver.h"
21#include "deprecat.h"
2221#include "cpu/m6809/m6809.h"
2322#include "video/konamiic.h"
2423#include "sound/3812intf.h"
r2724r2725
311310   {
312311      /* we should handle collision here */
313312//AT
314/*
315int i;
313      if (0)
314      {
315         int i;
316316
317logerror("collision test:\n");
318for (i = 0;i < 0xfe;i++)
319{
320    logerror("%02x ",pmcram[i]);
321    if (i == 0x0f || (i > 0x10 && (i - 0x10) % 14 == 13))
322        logerror("\n");
323}
324*/
317         logerror("collision test:\n");
318         for (i = 0;i < 0xfe;i++)
319         {
320            logerror("%02x ",pmcram[i]);
321            if (i == 0x0f || (i > 0x10 && (i - 0x10) % 14 == 13))
322            logerror("\n");
323         }
324      }
325325      spy_collision();
326326//ZT
327      cpunum_set_input_line(Machine, 0,M6809_FIRQ_LINE,HOLD_LINE);
327      cpunum_set_input_line(machine, 0,M6809_FIRQ_LINE,HOLD_LINE);
328328   }
329329
330330   old = data;
r2724r2725
521521};
522522
523523
524static void irqhandler(int linestate)
524static void irqhandler(running_machine *machine, int linestate)
525525{
526   cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, linestate);
526   cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, linestate);
527527}
528528
529529static const struct YM3812interface ym3812_interface =
src/mame/drivers/psikyo.c
r2724r2725
6161*****/
6262
6363#include "driver.h"
64#include "deprecat.h"
6564#include "sound/2610intf.h"
6665#include "sound/ymf278b.h"
6766
r2724r2725
369368
370369***************************************************************************/
371370
372static void sound_irq( int irq )
371static void sound_irq( running_machine *machine, int irq )
373372{
374   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
373   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
375374}
376375
377376static READ8_HANDLER( psikyo_soundlatch_r )
r2724r2725
16621661***************************************************************************/
16631662
16641663
1665static void irqhandler(int linestate)
1664static void irqhandler(running_machine *machine, int linestate)
16661665{
16671666   if (linestate)
1668      cpunum_set_input_line(Machine, 1, 0, ASSERT_LINE);
1667      cpunum_set_input_line(machine, 1, 0, ASSERT_LINE);
16691668   else
1670      cpunum_set_input_line(Machine, 1, 0, CLEAR_LINE);
1669      cpunum_set_input_line(machine, 1, 0, CLEAR_LINE);
16711670}
16721671
16731672static const struct YMF278B_interface ymf278b_interface =
src/mame/drivers/model3.c
r2724r2725
755755{
756756   int reg = offset*8;
757757   if (ACCESSING_BITS_56_63) {
758      lsi53c810_reg_w(reg+0, data >> 56);
758      lsi53c810_reg_w(machine, reg+0, data >> 56);
759759   }
760760   if (ACCESSING_BITS_48_55) {
761      lsi53c810_reg_w(reg+1, data >> 48);
761      lsi53c810_reg_w(machine, reg+1, data >> 48);
762762   }
763763   if (ACCESSING_BITS_40_47) {
764      lsi53c810_reg_w(reg+2, data >> 40);
764      lsi53c810_reg_w(machine, reg+2, data >> 40);
765765   }
766766   if (ACCESSING_BITS_32_39) {
767      lsi53c810_reg_w(reg+3, data >> 32);
767      lsi53c810_reg_w(machine, reg+3, data >> 32);
768768   }
769769   if (ACCESSING_BITS_24_31) {
770      lsi53c810_reg_w(reg+4, data >> 24);
770      lsi53c810_reg_w(machine, reg+4, data >> 24);
771771   }
772772   if (ACCESSING_BITS_16_23) {
773      lsi53c810_reg_w(reg+5, data >> 16);
773      lsi53c810_reg_w(machine, reg+5, data >> 16);
774774   }
775775   if (ACCESSING_BITS_8_15) {
776      lsi53c810_reg_w(reg+6, data >> 8);
776      lsi53c810_reg_w(machine, reg+6, data >> 8);
777777   }
778778   if (ACCESSING_BITS_0_7) {
779      lsi53c810_reg_w(reg+7, data >> 0);
779      lsi53c810_reg_w(machine, reg+7, data >> 0);
780780   }
781781}
782782
r2724r2725
787787   return BYTE_REVERSE32(result);
788788}
789789
790static void scsi_irq_callback(void)
790static void scsi_irq_callback(running_machine *machine)
791791{
792792   model3_irq_state |= model3_irq_enable & ~0x60;   /* FIXME: enable only SCSI interrupt */
793   cpunum_set_input_line(Machine, 0, INPUT_LINE_IRQ1, ASSERT_LINE);
793   cpunum_set_input_line(machine, 0, INPUT_LINE_IRQ1, ASSERT_LINE);
794794}
795795
796796/*****************************************************************************/
r2724r2725
846846               real3d_dma_callback(dma_source, dma_dest, length, 1);
847847            }
848848            dma_irq |= 0x01;
849            scsi_irq_callback();
849            scsi_irq_callback(machine);
850850            return;
851851         }
852852         else if(ACCESSING_BITS_16_23)
r2724r2725
40104010
40114011static int scsp_last_line = 0;
40124012
4013static void scsp_irq(int irq)
4013static void scsp_irq(running_machine *machine, int irq)
40144014{
40154015    if (irq > 0)
40164016   {
40174017      scsp_last_line = irq;
4018      cpunum_set_input_line(Machine, 1, irq, PULSE_LINE);
4018      cpunum_set_input_line(machine, 1, irq, PULSE_LINE);
40194019   }
40204020}
40214021
src/mame/drivers/pgm.c
r2724r2725
456456   soundlatch3_w(machine, 0, data);
457457}
458458
459static void sound_irq(int level)
459static void sound_irq(running_machine *machine, int level)
460460{
461   cpunum_set_input_line(Machine, 1, 0, level);
461   cpunum_set_input_line(machine, 1, 0, level);
462462}
463463
464464static const struct ics2115_interface pgm_ics2115_interface = {
src/mame/drivers/gameplan.c
r2724r2725
6464****************************************************************************/
6565
6666#include "driver.h"
67#include "deprecat.h"
6867#include "machine/6532riot.h"
6968#include "machine/6522via.h"
7069#include "sound/ay8910.h"
r2724r2725
167166 *
168167 *************************************/
169168
170static void r6532_irq(int state)
169static void r6532_irq(running_machine *machine, int state)
171170{
172   cpunum_set_input_line(Machine, 1, 0, state);
171   cpunum_set_input_line(machine, 1, 0, state);
173172}
174173
175174
src/mame/drivers/capbowl.c
r2724r2725
8888***************************************************************************/
8989
9090#include "driver.h"
91#include "deprecat.h"
9291#include "machine/ticket.h"
9392#include "cpu/m6809/m6809.h"
9493#include "capbowl.h"
r2724r2725
205204 *
206205 *************************************/
207206
208static void firqhandler(int irq)
207static void firqhandler(running_machine *machine, int irq)
209208{
210   cpunum_set_input_line(Machine, 1, 1, irq ? ASSERT_LINE : CLEAR_LINE);
209   cpunum_set_input_line(machine, 1, 1, irq ? ASSERT_LINE : CLEAR_LINE);
211210}
212211
213212
src/mame/drivers/darius.c
r2724r2725
515515ADDRESS_MAP_END
516516
517517
518static void darius_adpcm_int (int data)
518static void darius_adpcm_int (running_machine *machine, int data)
519519{
520520   if (nmi_enable)
521      cpunum_set_input_line(Machine, 3, INPUT_LINE_NMI, PULSE_LINE);
521      cpunum_set_input_line(machine, 3, INPUT_LINE_NMI, PULSE_LINE);
522522}
523523
524524static const struct MSM5205interface msm5205_interface =
r2724r2725
801801**************************************************************/
802802
803803/* handler called by the YM2203 emulator when the internal timers cause an IRQ */
804static void irqhandler(int irq)   /* assumes Z80 sandwiched between 68Ks */
804static void irqhandler(running_machine *machine, int irq)   /* assumes Z80 sandwiched between 68Ks */
805805{
806   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
806   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
807807}
808808
809809static const struct YM2203interface ym2203_interface_1 =
src/mame/drivers/beathead.c
r2724r2725
9898
9999
100100#include "driver.h"
101#include "deprecat.h"
102101#include "cpu/asap/asap.h"
103102#include "machine/atarigen.h"
104103#include "audio/atarijsa.h"
r2724r2725
226225      irq_state[0] = irq_state[1] = irq_state[2] = 0;
227226
228227   /* update the current state */
229   update_interrupts(Machine);
228   update_interrupts(machine);
230229}
231230
232231
src/mame/drivers/cchasm.c
r2724r2725
1313***************************************************************************/
1414
1515#include "driver.h"
16#include "deprecat.h"
1716#include "video/vector.h"
1817#include "machine/6840ptm.h"
1918#include "machine/z80ctc.h"
r2724r2725
5857   AM_RANGE(0x00, 0x03) AM_READWRITE(z80ctc_0_r,z80ctc_0_w)
5958ADDRESS_MAP_END
6059
61static void cchasm_6840_irq(int state)
60static void cchasm_6840_irq(running_machine *machine, int state)
6261{
63   cpunum_set_input_line(Machine, 0, 4, state?ASSERT_LINE:CLEAR_LINE);
62   cpunum_set_input_line(machine, 0, 4, state?ASSERT_LINE:CLEAR_LINE);
6463}
6564static const ptm6840_interface cchasm_6840_intf =
6665{
src/mame/drivers/smstrv.c
r2724r2725
8686*/
8787
8888#include "driver.h"
89#include "deprecat.h"
9089#include "sound/ay8910.h"
9190#include "machine/8255ppi.h"
9291
r2724r2725
9897   int pc = activecpu_get_pc();
9998   if(pc != 0x81cb)
10099      printf("r1 @ %X\n",activecpu_get_pc());
101   return mame_rand(Machine);
100   return mame_rand(machine);
102101}
103102static READ8_HANDLER( r2 )
104103{
105104   int pc = activecpu_get_pc();
106105   if(pc != 0x81cb)
107106      printf("r2 @ %X\n",activecpu_get_pc());
108   return mame_rand(Machine);
107   return mame_rand(machine);
109108}
110109static READ8_HANDLER( r3 )
111110{
112111   int pc = activecpu_get_pc();
113112   if(pc != 0x81cb && pc != 0x90fa && pc != 0x911b && pc != 0x90d3 && pc != 0x90c4)
114113      printf("r3 @ %X\n",activecpu_get_pc());
115   return mame_rand(Machine) & ~1; //with 1 jumps back (infinite loop): a status ready for something?
114   return mame_rand(machine) & ~1; //with 1 jumps back (infinite loop): a status ready for something?
116115}
117116static READ8_HANDLER( r4 )
118117{
119118   int pc = activecpu_get_pc();
120119   if(pc != 0x81cb)
121120      printf("r4 @ %X\n",activecpu_get_pc());
122   return mame_rand(Machine);
121   return mame_rand(machine);
123122}
124123static READ8_HANDLER( r5 )
125124{
126125   int pc = activecpu_get_pc();
127126   if(pc != 0x81cb)
128127      printf("r5 @ %X\n",activecpu_get_pc());
129   return mame_rand(Machine);
128   return mame_rand(machine);
130129}
131130static READ8_HANDLER( r6 )
132131{
r2724r2725
134133   if(pc != 0x81cb)
135134      printf("r6 @ %X\n",activecpu_get_pc());
136135
137   return mame_rand(Machine);
136   return mame_rand(machine);
138137}
139138
140139static WRITE8_HANDLER( w1 )
src/mame/drivers/funkyjet.c
r2724r2725
8888***************************************************************************/
8989
9090#include "driver.h"
91#include "deprecat.h"
9291#include "cpu/h6280/h6280.h"
9392#include "sound/2151intf.h"
9493#include "sound/okim6295.h"
r2724r2725
353352
354353/******************************************************************************/
355354
356static void sound_irq(int state)
355static void sound_irq(running_machine *machine, int state)
357356{
358   cpunum_set_input_line(Machine, 1,1,state); /* IRQ 2 */
357   cpunum_set_input_line(machine, 1,1,state); /* IRQ 2 */
359358}
360359
361360static const struct YM2151interface ym2151_interface =
src/mame/drivers/suprgolf.c
r2724r2725
1515***************************************************************************/
1616
1717#include "driver.h"
18#include "deprecat.h"
1918#include "sound/2203intf.h"
2019
2120static tilemap *suprgolf_tilemap;
r2724r2725
9291
9392static READ8_HANDLER( suprgolf_random )
9493{
95   return mame_rand(Machine);
94   return mame_rand(machine);
9695}
9796
9897static ADDRESS_MAP_START( io_map, ADDRESS_SPACE_IO, 8 )
r2724r2725
257256   mame_printf_debug("ymwA\n");
258257}
259258
260static void irqhandler(int irq)
259static void irqhandler(running_machine *machine, int irq)
261260{
262//  cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
261//  cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
263262}
264263
265264static const struct YM2203interface ym2203_interface =
src/mame/drivers/konamigq.c
r2724r2725
320320{
321321}
322322
323static void scsi_irq(void)
323static void scsi_irq(running_machine *machine)
324324{
325   psx_irq_set(0x400);
325   psx_irq_set(machine, 0x400);
326326}
327327
328328static const SCSIConfigTable dev_table =
src/mame/drivers/spiders.c
r2724r2725
230230 *
231231 *************************************/
232232
233static void main_cpu_irq(int state)
233static void main_cpu_irq(running_machine *machine, int state)
234234{
235235   int combined_state = pia_get_irq_a(1) | pia_get_irq_b(1) |
236236                                  pia_get_irq_b(2) |
237237                   pia_get_irq_a(3) | pia_get_irq_b(3);
238238
239   cpunum_set_input_line(Machine, 0, M6809_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
239   cpunum_set_input_line(machine, 0, M6809_IRQ_LINE, combined_state ? ASSERT_LINE : CLEAR_LINE);
240240}
241241
242242
243static void main_cpu_firq(int state)
243static void main_cpu_firq(running_machine *machine, int state)
244244{
245   cpunum_set_input_line(Machine, 0, M6809_FIRQ_LINE, state ? ASSERT_LINE : CLEAR_LINE);
245   cpunum_set_input_line(machine, 0, M6809_FIRQ_LINE, state ? ASSERT_LINE : CLEAR_LINE);
246246}
247247
248248
249static void audio_cpu_irq(int state)
249static void audio_cpu_irq(running_machine *machine, int state)
250250{
251   cpunum_set_input_line(Machine, 1, M6802_IRQ_LINE, state ? ASSERT_LINE : CLEAR_LINE);
251   cpunum_set_input_line(machine, 1, M6802_IRQ_LINE, state ? ASSERT_LINE : CLEAR_LINE);
252252}
253253
254254
src/mame/drivers/mcatadv.c
r2724r2725
136136******************************************************************************/
137137
138138#include "driver.h"
139#include "deprecat.h"
140139#include "sound/2610intf.h"
141140
142141VIDEO_UPDATE( mcatadv );
r2724r2725
478477
479478
480479/* Stolen from Psikyo.c */
481static void sound_irq( int irq )
480static void sound_irq( running_machine *machine, int irq )
482481{
483   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
482   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
484483}
485484static const struct YM2610interface mcatadv_ym2610_interface =
486485{
src/mame/drivers/cinemat.c
r2724r2725
151151
152152static UINT8 joystick_read(void)
153153{
154   if (port_tag_to_index("ANALOGX") != -1)
155   {
156      int xval = (INT16)(cpunum_get_reg(0, CCPU_X) << 4) >> 4;
157      return (input_port_read(Machine, mux_select ? "ANALOGX" : "ANALOGY") - xval) < 0x800;
158   }
159   return 0;
154   int xval = (INT16)(cpunum_get_reg(0, CCPU_X) << 4) >> 4;
155   return (input_port_read_safe(Machine, mux_select ? "ANALOGX" : "ANALOGY", 0) - xval) < 0x800;
160156}
161157
162158
src/mame/drivers/toaplan2.c
r2724r2725
13681368}
13691369
13701370
1371static void bbakraid_irqhandler (int state)
1371static void bbakraid_irqhandler(running_machine *machine, int state)
13721372{
13731373   /* Not used ???  Connected to a test pin (TP082) */
13741374   logerror("YMZ280 is generating an interrupt. State=%08x\n",state);
r2724r2725
34053405   GFXDECODE_ENTRY( REGION_GFX2, 0, fixeighblayout , 0, 128 )
34063406GFXDECODE_END
34073407
3408static void irqhandler(int linestate)
3408static void irqhandler(running_machine *machine, int linestate)
34093409{
3410   cpunum_set_input_line(Machine, 1,0,linestate);
3410   cpunum_set_input_line(machine, 1,0,linestate);
34113411}
34123412
34133413static const struct YM3812interface ym3812_interface =
r2724r2725
39023902   #endif
39033903}
39043904
3905void batsugun_ym2151_irqhandler(int linestate)
3905void batsugun_ym2151_irqhandler(running_machine *machine, int linestate)
39063906{
39073907   logerror("batsugun_ym2151_irqhandler %02x\n",linestate);
3908//  update_irq_lines(Machine, linestate ? assert : clear);
3908//  update_irq_lines(machine, linestate ? assert : clear);
39093909}
39103910
39113911const struct YM2151interface batsugun_ym2151_interface =
src/mame/drivers/jchan.c
r2724r2725
250250               mcu_ram[mcu_offset + 6] = 0x3939; mcu_ram[mcu_offset + 7] = 0x3420;
251251               break;
252252            case 0x3e:
253               if ( strcmp(Machine->gamedrv->name, "jchan") == 0 ) /* $f72 ($f6a-$fc6) */
253               if ( strcmp(machine->gamedrv->name, "jchan") == 0 ) /* $f72 ($f6a-$fc6) */
254254               {
255255                  /* MCU writes the string "1995/05/24 The kung-Fu Master Jackie Chan   " to shared ram */
256256                  mcu_ram[mcu_offset +  0] = 0x3139; mcu_ram[mcu_offset +  1] = 0x3935;
r2724r2725
265265                  mcu_ram[mcu_offset + 18] = 0x2043; mcu_ram[mcu_offset + 19] = 0x6861;
266266                  mcu_ram[mcu_offset + 20] = 0x6E20; mcu_ram[mcu_offset + 21] = 0x2020;
267267               }
268               else if ( strcmp(Machine->gamedrv->name, "jchan2") == 0 )
268               else if ( strcmp(machine->gamedrv->name, "jchan2") == 0 )
269269               {
270270                  /* MCU writes the string "1995/10/24 Fists Of Fire" to shared ram */
271271                  mcu_ram[mcu_offset +  0] = 0x3139; mcu_ram[mcu_offset +  1] = 0x3935;
r2724r2725
341341         mcu_ram[mcu_offset + 63] = 0x0062;
342342#endif
343343         mame_file *f;
344         if ((f = nvram_fopen(Machine, OPEN_FLAG_READ)) != 0)
344         if ((f = nvram_fopen(machine, OPEN_FLAG_READ)) != 0)
345345         {
346346            mame_fread(f,&mcu_ram[mcu_offset], 128);
347347            mame_fclose(f);
r2724r2725
353353      case 0x42: /* save game settings to 93C46 EEPROM ($50d4) */
354354      {
355355         mame_file *f;
356         if ((f = nvram_fopen(Machine, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS)) != 0)
356         if ((f = nvram_fopen(machine, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS)) != 0)
357357         {
358358            mame_fwrite(f,&mcu_ram[mcu_offset], 128);
359359            mame_fclose(f);
src/mame/drivers/mlanding.c
r2724r2725
8989
9090static int adpcm_pos;
9191
92static void ml_msm5205_vck(int chip)
92static void ml_msm5205_vck(running_machine *machine, int chip)
9393{
9494   static int adpcm_data = -1;
9595
r2724r2725
336336
337337INPUT_PORTS_END
338338
339static void irq_handler(int irq)
339static void irq_handler(running_machine *machine, int irq)
340340{
341   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
341   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
342342}
343343
344344static GFXDECODE_START( mlanding )
src/mame/drivers/crbaloon.c
r2724r2725
7575
7676   /* enable coin & start input? Wild guess!!! */
7777   if (pc3092_data[1] & 0x02)
78      ret = input_port_read(machine, "PC3092");
78      ret = input_port_read(field->port->machine, "PC3092");
7979   else
8080      ret = 0x00;
8181
src/mame/drivers/dmndrby.c
r2724r2725
3636*/
3737
3838#include "driver.h"
39#include "deprecat.h"
4039
4140static UINT8* dderby_vid;
4241
4342static READ8_HANDLER( dderby_random_reader )
4443{
45   return mame_rand(Machine);
44   return mame_rand(machine);
4645}
4746
4847static ADDRESS_MAP_START( memmap, ADDRESS_SPACE_PROGRAM, 8 )
src/mame/drivers/seattle.c
r2724r2725
465465 *
466466 *************************************/
467467
468static void vblank_assert(int state);
469static void update_vblank_irq(void);
468static void vblank_assert(running_machine *machine, int state);
469static void update_vblank_irq(running_machine *machine);
470470static void galileo_reset(void);
471471static TIMER_CALLBACK( galileo_timer_callback );
472472static void galileo_perform_dma(running_machine *machine, int which);
473static void voodoo_stall(int stall);
473static void voodoo_stall(running_machine *machine, int stall);
474474static void widget_reset(void);
475static void update_widget_irq(void);
475static void update_widget_irq(running_machine *machine);
476476
477477
478478
r2724r2725
571571   if (board_config == SEATTLE_WIDGET_CONFIG)
572572      widget_reset();
573573   if (board_config == FLAGSTAFF_CONFIG)
574      smc91c94_reset();
574      smc91c94_reset(machine);
575575}
576576
577577
r2724r2725
595595 *
596596 *************************************/
597597
598static void ethernet_interrupt(int state)
598static void ethernet_interrupt(running_machine *machine, int state)
599599{
600600   ethernet_irq_state = state;
601601   if (board_config == FLAGSTAFF_CONFIG)
602602   {
603603      UINT8 assert = ethernet_irq_state && (*interrupt_enable & (1 << ETHERNET_IRQ_SHIFT));
604604      if (ethernet_irq_num != 0)
605         cpunum_set_input_line(Machine, 0, ethernet_irq_num, assert ? ASSERT_LINE : CLEAR_LINE);
605         cpunum_set_input_line(machine, 0, ethernet_irq_num, assert ? ASSERT_LINE : CLEAR_LINE);
606606   }
607607   else if (board_config == SEATTLE_WIDGET_CONFIG)
608      update_widget_irq();
608      update_widget_irq(machine);
609609}
610610
611611
r2724r2725
622622 *
623623 *************************************/
624624
625static void ioasic_irq(int state)
625static void ioasic_irq(running_machine *machine, int state)
626626{
627   cpunum_set_input_line(Machine, 0, IOASIC_IRQ_NUM, state);
627   cpunum_set_input_line(machine, 0, IOASIC_IRQ_NUM, state);
628628}
629629
630630
r2724r2725
690690   }
691691
692692   /* update the states */
693   update_vblank_irq();
694   ethernet_interrupt(ethernet_irq_state);
693   update_vblank_irq(machine);
694   ethernet_interrupt(machine, ethernet_irq_state);
695695}
696696
697697
r2724r2725
702702   if (old != *interrupt_enable)
703703   {
704704      if (vblank_latch)
705         update_vblank_irq();
705         update_vblank_irq(machine);
706706      if (ethernet_irq_state)
707         ethernet_interrupt(ethernet_irq_state);
707         ethernet_interrupt(machine, ethernet_irq_state);
708708   }
709709}
710710
r2724r2725
716716 *
717717 *************************************/
718718
719static void update_vblank_irq(void)
719static void update_vblank_irq(running_machine *machine)
720720{
721721   int state = CLEAR_LINE;
722722
r2724r2725
727727   /* if the VBLANK has been latched, and the interrupt is enabled, assert */
728728   if (vblank_latch && (*interrupt_enable & (1 << VBLANK_IRQ_SHIFT)))
729729      state = ASSERT_LINE;
730   cpunum_set_input_line(Machine, 0, vblank_irq_num, state);
730   cpunum_set_input_line(machine, 0, vblank_irq_num, state);
731731}
732732
733733
r2724r2725
735735{
736736   /* clear the latch and update the IRQ */
737737   vblank_latch = 0;
738   update_vblank_irq();
738   update_vblank_irq(machine);
739739}
740740
741741
742static void vblank_assert(int state)
742static void vblank_assert(running_machine *machine, int state)
743743{
744744   /* cache the raw state */
745745   vblank_state = state;
r2724r2725
748748   if ((state && !(*interrupt_enable & 0x100)) || (!state && (*interrupt_enable & 0x100)))
749749   {
750750      vblank_latch = 1;
751      update_vblank_irq();
751      update_vblank_irq(machine);
752752   }
753753}
754754
r2724r2725
881881 *
882882 *************************************/
883883
884static void update_galileo_irqs(void)
884static void update_galileo_irqs(running_machine *machine)
885885{
886886   int state = CLEAR_LINE;
887887
888888   /* if any unmasked interrupts are live, we generate */
889889   if (galileo.reg[GREG_INT_STATE] & galileo.reg[GREG_INT_MASK])
890890      state = ASSERT_LINE;
891   cpunum_set_input_line(Machine, 0, GALILEO_IRQ_NUM, state);
891   cpunum_set_input_line(machine, 0, GALILEO_IRQ_NUM, state);
892892
893893   if (LOG_GALILEO)
894894      logerror("Galileo IRQ %s\n", (state == ASSERT_LINE) ? "asserted" : "cleared");
r2724r2725
916916
917917   /* trigger the interrupt */
918918   galileo.reg[GREG_INT_STATE] |= 1 << (GINT_T0EXP_SHIFT + which);
919   update_galileo_irqs();
919   update_galileo_irqs(machine);
920920}
921921
922922
r2724r2725
942942      if (galileo.reg[GREG_DMA0_CONTROL + which] & 0x400)
943943      {
944944         galileo.reg[GREG_INT_STATE] |= 1 << (GINT_DMA0COMP_SHIFT + which);
945         update_galileo_irqs();
945         update_galileo_irqs(Machine);
946946      }
947947      galileo.reg[GREG_DMA0_CONTROL + which] &= ~0x5000;
948948      return 0;
r2724r2725
10511051      if (!(galileo.reg[GREG_DMA0_CONTROL + which] & 0x400))
10521052      {
10531053         galileo.reg[GREG_INT_STATE] |= 1 << (GINT_DMA0COMP_SHIFT + which);
1054         update_galileo_irqs();
1054         update_galileo_irqs(machine);
10551055      }
10561056   } while (galileo_dma_fetch_next(which));
10571057
r2724r2725
12421242         if (LOG_GALILEO)
12431243            logerror("%08X:Galileo write to IRQ clear = %08X & %08X\n", offset*4, data, mem_mask);
12441244         galileo.reg[offset] = oldata & data;
1245         update_galileo_irqs();
1245         update_galileo_irqs(machine);
12461246         break;
12471247
12481248      case GREG_CONFIG_DATA:
r2724r2725
13201320}
13211321
13221322
1323static void voodoo_stall(int stall)
1323static void voodoo_stall(running_machine *machine, int stall)
13241324{
13251325   /* set the new state */
13261326   voodoo_stalled = stall;
r2724r2725
13561356
13571357            /* resume execution */
13581358            cpuintrf_push_context(0);
1359            galileo_perform_dma(Machine, which);
1359            galileo_perform_dma(machine, which);
13601360            cpuintrf_pop_context();
13611361            break;
13621362         }
r2724r2725
13661366      {
13671367         /* if the CPU had a pending write, do it now */
13681368         if (cpu_stalled_on_voodoo)
1369            voodoo_0_w(Machine, cpu_stalled_offset, cpu_stalled_data, cpu_stalled_mem_mask);
1369            voodoo_0_w(machine, cpu_stalled_offset, cpu_stalled_data, cpu_stalled_mem_mask);
13701370         cpu_stalled_on_voodoo = FALSE;
13711371
13721372         /* resume CPU execution */
13731373         if (LOG_DMA) logerror("Resuming CPU on voodoo\n");
1374         cpu_trigger(Machine, 45678);
1374         cpu_trigger(machine, 45678);
13751375      }
13761376   }
13771377}
r2724r2725
14941494   UINT8 saved_irq = widget.irq_num;
14951495   memset(&widget, 0, sizeof(widget));
14961496   widget.irq_num = saved_irq;
1497   smc91c94_reset();
1497   smc91c94_reset(Machine);
14981498}
14991499
15001500
1501static void update_widget_irq(void)
1501static void update_widget_irq(running_machine *machine)
15021502{
15031503   UINT8 state = ethernet_irq_state << WINT_ETHERNET_SHIFT;
15041504   UINT8 mask = widget.irq_mask;
r2724r2725
15061506
15071507   /* update the IRQ state */
15081508   if (widget.irq_num != 0)
1509      cpunum_set_input_line(Machine, 0, widget.irq_num, assert ? ASSERT_LINE : CLEAR_LINE);
1509      cpunum_set_input_line(machine, 0, widget.irq_num, assert ? ASSERT_LINE : CLEAR_LINE);
15101510}
15111511
15121512
r2724r2725
15531553
15541554      case WREG_INTERRUPT:
15551555         widget.irq_mask = data;
1556         update_widget_irq();
1556         update_widget_irq(machine);
15571557         break;
15581558
15591559      case WREG_ANALOG:
src/mame/drivers/tetrisp2.c
r2724r2725
3434***************************************************************************/
3535
3636#include "driver.h"
37#include "deprecat.h"
3837#include "sound/okim6295.h"
3938#include "sound/ymz280b.h"
4039#include "rocknms.lh"
r2724r2725
265264static READ16_HANDLER( tetrisp2_ip_1_word_r )
266265{
267266   return   ( input_port_read(machine, "IN1") &  0xfcff ) |
268         (           mame_rand(Machine) & ~0xfcff ) |
269         (      1 << (8 + (mame_rand(Machine)&1)) );
267         (           mame_rand(machine) & ~0xfcff ) |
268         (      1 << (8 + (mame_rand(machine)&1)) );
270269}
271270
272271
src/mame/drivers/lastduel.c
r2724r2725
232232/******************************************************************************/
233233
234234/* handler called by the 2203 emulator when the internal timers cause an IRQ */
235static void irqhandler(int irq)
235static void irqhandler(running_machine *machine, int irq)
236236{
237   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
237   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
238238}
239239
240240static const struct YM2203interface ym2203_interface =
src/mame/drivers/alpha68k.c
r2724r2725
19651965   }
19661966};
19671967
1968static void YM3812_irq(int param)
1968static void YM3812_irq(running_machine *machine, int param)
19691969{
1970   cpunum_set_input_line(Machine, 1, 0, (param) ? HOLD_LINE : CLEAR_LINE);
1970   cpunum_set_input_line(machine, 1, 0, (param) ? HOLD_LINE : CLEAR_LINE);
19711971}
19721972
19731973static const struct YM3812interface ym3812_interface =
src/mame/drivers/tmaster.c
r2724r2725
2525Touch Master 2000
2626Touch Master 6000
2727Touch Master 7000 *
28Touch Master 8000 *(?)
28Touch Master 8000 *
2929
3030* There is a reported "Minnesota" version with modifications due to legal issues
3131  Touch Master (current set) is a Euro version, all other sets are "DOMESTIC" (AKA "Standard").
r2724r2725
134134
135135***************************************************************************/
136136
137static void duart_irq_handler(UINT8 vector)
137static void duart_irq_handler(running_machine *machine, int vector)
138138{
139   cpunum_set_input_line_and_vector(Machine, 0, 4, HOLD_LINE, vector);
139   cpunum_set_input_line_and_vector(machine, 0, 4, HOLD_LINE, vector);
140140};
141141
142142static void duart_tx(int channel, UINT8 data)
r2724r2725
151151static void microtouch_tx(UINT8 data)
152152{
153153   //logerror( "microtouch->duart: %02x %c\n", data, (char)data);
154   duart_68681_rx_data(0, data);
154   duart_68681_rx_data(Machine, 0, data);
155155}
156156
157157
r2724r2725
640640   PORT_INCLUDE(microtouch)
641641
642642   PORT_START_TAG("COIN") // IN3
643   PORT_BIT( 0x0001, IP_ACTIVE_LOW,  IPT_UNKNOWN  )   // m. coin 1 (coin optics?)
644   PORT_BIT( 0x0002, IP_ACTIVE_LOW,  IPT_UNKNOWN  )   // m. coin 2 (coin optics?)
645   PORT_BIT( 0x0004, IP_ACTIVE_LOW,  IPT_UNKNOWN  )   // dbv input (coin optics?)
643   PORT_BIT( 0x0001, IP_ACTIVE_LOW,  IPT_COIN5    )   // "M. Coin 1 Input"
644   PORT_BIT( 0x0002, IP_ACTIVE_LOW,  IPT_COIN6    )   // "M. Coin 2 Input"
645   PORT_BIT( 0x0004, IP_ACTIVE_LOW,  IPT_BILL1    ) PORT_IMPULSE(2)   // "DBV Input"
646646   PORT_BIT( 0x0008, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
647   PORT_BIT( 0x0010, IP_ACTIVE_LOW,  IPT_COIN1    )   // (service coin?)
647   PORT_BIT( 0x0010, IP_ACTIVE_LOW,  IPT_UNKNOWN  )   // service coin?
648648   PORT_SERVICE_NO_TOGGLE( 0x0020, IP_ACTIVE_LOW  )
649   PORT_BIT( 0x0040, IP_ACTIVE_LOW,  IPT_SERVICE1 )   // calibrate
649   PORT_BIT( 0x0040, IP_ACTIVE_LOW,  IPT_SERVICE1 )   // "Calibrate"
650650   PORT_BIT( 0x0080, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
651651   PORT_BIT( 0x0100, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
652652   PORT_BIT( 0x0200, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
653653   PORT_BIT( 0x0400, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
654654   PORT_BIT( 0x0800, IP_ACTIVE_HIGH, IPT_SPECIAL  )
655   PORT_BIT( 0x1000, IP_ACTIVE_LOW,  IPT_COIN1    ) PORT_IMPULSE(2)   // e. coin 1
656   PORT_BIT( 0x2000, IP_ACTIVE_LOW,  IPT_UNKNOWN  )         // e. coin 2
657   PORT_BIT( 0x4000, IP_ACTIVE_LOW,  IPT_UNKNOWN  )         // e. coin 3
658   PORT_BIT( 0x8000, IP_ACTIVE_LOW,  IPT_UNKNOWN  )         // e. coin 4
655   PORT_BIT( 0x1000, IP_ACTIVE_LOW,  IPT_COIN1  )   // "E. Coin 1" (ECA?) tmaster defaults to e. coin,
656   PORT_BIT( 0x2000, IP_ACTIVE_LOW,  IPT_COIN2  )   // "E. Coin 2" (ECA?) rather than m. coin
657   PORT_BIT( 0x4000, IP_ACTIVE_LOW,  IPT_COIN3  )   // "E. Coin 3" (ECA?) so they're coin1-coin4
658   PORT_BIT( 0x8000, IP_ACTIVE_LOW,  IPT_COIN4  )   // "E. Coin 4" (ECA?)
659659INPUT_PORTS_END
660660
661661static INPUT_PORTS_START( tmaster )
662662   PORT_INCLUDE(microtouch)
663663
664664   PORT_START_TAG("COIN") // IN3
665   PORT_BIT( 0x0001, IP_ACTIVE_LOW,  IPT_COIN1    ) PORT_IMPULSE(2)   // m. coin 1 (coin optics?)
666   PORT_BIT( 0x0002, IP_ACTIVE_LOW,  IPT_UNKNOWN  )         // m. coin 2 (coin optics?)
667   PORT_BIT( 0x0004, IP_ACTIVE_LOW,  IPT_UNKNOWN  )         // dbv input (coin optics?)
665   PORT_BIT( 0x0001, IP_ACTIVE_LOW,  IPT_COIN1      )    // "M. Coin 1 Input"
666   PORT_BIT( 0x0002, IP_ACTIVE_LOW,  IPT_COIN2      )    // "M. Coin 2 Input"
667   PORT_BIT( 0x0004, IP_ACTIVE_LOW,  IPT_BILL1      ) PORT_IMPULSE(2)   // "DBV Input"
668668   PORT_BIT( 0x0008, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
669   PORT_BIT( 0x0010, IP_ACTIVE_LOW,  IPT_COIN1    )   // (service coin?)
669   PORT_BIT( 0x0010, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
670670   PORT_SERVICE_NO_TOGGLE( 0x0020, IP_ACTIVE_LOW  )
671   PORT_BIT( 0x0040, IP_ACTIVE_LOW,  IPT_SERVICE1 )   // calibrate
671   PORT_BIT( 0x0040, IP_ACTIVE_LOW,  IPT_SERVICE1 )   // "Calibrate"
672672   PORT_BIT( 0x0080, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
673673   PORT_BIT( 0x0100, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
674674   PORT_BIT( 0x0200, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
675675   PORT_BIT( 0x0400, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
676676   PORT_BIT( 0x0800, IP_ACTIVE_HIGH, IPT_SPECIAL  )
677   PORT_BIT( 0x1000, IP_ACTIVE_LOW,  IPT_UNKNOWN  )   // e. coin 1
678   PORT_BIT( 0x2000, IP_ACTIVE_LOW,  IPT_UNKNOWN  )   // e. coin 2
679   PORT_BIT( 0x4000, IP_ACTIVE_LOW,  IPT_UNKNOWN  )   // e. coin 3
680   PORT_BIT( 0x8000, IP_ACTIVE_LOW,  IPT_UNKNOWN  )   // e. coin 4
677   PORT_BIT( 0x1000, IP_ACTIVE_LOW,  IPT_COIN3  )   // "E. Coin 1" (ECA mech) The rest of the tm games
678   PORT_BIT( 0x2000, IP_ACTIVE_LOW,  IPT_COIN4  )   // "E. Coin 2" (ECA mech) Default to m. coin
679   PORT_BIT( 0x4000, IP_ACTIVE_LOW,  IPT_COIN5  )   // "E. Coin 3" (ECA mech) So these are coin3-coin6
680   PORT_BIT( 0x8000, IP_ACTIVE_LOW,  IPT_COIN6  )   // "E. Coin 4" (ECA mech)
681681INPUT_PORTS_END
682682
683683static INPUT_PORTS_START( galgames )
src/mame/drivers/cischeat.c
r2724r2725
505505
506506READ16_HANDLER( scudhamm_motor_status_r )
507507{
508//  return 1 << (mame_rand(Machine)&1);         // Motor Status
508//  return 1 << (mame_rand(machine)&1);         // Motor Status
509509   return scudhamm_motor_command;   // Motor Status
510510}
511511
src/mame/drivers/vicdual.c
r2724r2725
9595      coin_counter_w(0, 1);
9696      coin_counter_w(0, 0);
9797
98      cpunum_set_input_line(machine, 0, INPUT_LINE_RESET, PULSE_LINE);
98      cpunum_set_input_line(field->port->machine, 0, INPUT_LINE_RESET, PULSE_LINE);
9999
100100      /* simulate the coin switch being closed for a while */
101      timer_set(double_to_attotime(4 * attotime_to_double(video_screen_get_frame_period(machine->primary_screen))), NULL, 0, clear_coin_status);
101      timer_set(double_to_attotime(4 * attotime_to_double(video_screen_get_frame_period(field->port->machine->primary_screen))), NULL, 0, clear_coin_status);
102102   }
103103}
104104
r2724r2725
142142
143143static CUSTOM_INPUT( vicdual_get_64v )
144144{
145   return (get_vcounter(machine) >> 6) & 0x01;
145   return (get_vcounter(field->port->machine) >> 6) & 0x01;
146146}
147147
148148
149149static CUSTOM_INPUT( vicdual_get_vblank_comp )
150150{
151   return (get_vcounter(machine) < VICDUAL_VBSTART);
151   return (get_vcounter(field->port->machine) < VICDUAL_VBSTART);
152152}
153153
154154
155155static CUSTOM_INPUT( vicdual_get_composite_blank_comp )
156156{
157   return (vicdual_get_vblank_comp(machine, 0) && !video_screen_get_hblank(machine->primary_screen));
157   return (vicdual_get_vblank_comp(field, 0) && !video_screen_get_hblank(field->port->machine->primary_screen));
158158}
159159
160160
r2724r2725
20232023   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Lives ) )
20242024   PORT_DIPSETTING(    0x04, "3" )
20252025   PORT_DIPSETTING(    0x00, "4" )
2026   PORT_BIT(    0x08, 0x08, IPT_DIPSWITCH_NAME ) PORT_NAME("Infinite Lives")
2026   PORT_DIPNAME( 0x08, 0x08, "Infinite Lives" )
20272027   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
20282028   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
20292029   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY
src/mame/drivers/centiped.c
r2724r2725
417417***************************************************************************/
418418
419419#include "driver.h"
420#include "deprecat.h"
421420#include "cpu/s2650/s2650.h"
422421#include "machine/atari_vg.h"
423422#include "centiped.h"
r2724r2725
621620
622621static READ8_HANDLER( caterplr_rand_r )
623622{
624   return mame_rand(Machine) % 0xff;
623   return mame_rand(machine) % 0xff;
625624}
626625
627626
src/mame/drivers/wgp.c
r2724r2725
914914**************************************************************/
915915
916916/* handler called by the YM2610 emulator when the internal timers cause an IRQ */
917static void irqhandler(int irq)   // assumes Z80 sandwiched between 68Ks
917static void irqhandler(running_machine *machine, int irq)   // assumes Z80 sandwiched between 68Ks
918918{
919   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
919   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
920920}
921921
922922static const struct YM2610interface ym2610_interface =
src/mame/drivers/welltris.c
r2724r2725
313313#define WELLTRIS_4P_HACK 0
314314
315315#include "driver.h"
316#include "deprecat.h"
317316#include "sound/2610intf.h"
318317
319318UINT16 *welltris_spriteram;
r2724r2725
688687
689688
690689
691static void irqhandler(int irq)
690static void irqhandler(running_machine *machine, int irq)
692691{
693   cpunum_set_input_line(Machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
692   cpunum_set_input_line(machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
694693}
695694
696695static const struct YM2610interface ym2610_interface =
src/mame/drivers/gumbo.c
r2724r2725
355355   ROM_LOAD( "u210.bin", 0x00000, 0x40000, CRC(16fbe06b) SHA1(4e40e62341dc886fcabdb07f64217dc086f43c67) )
356356
357357   ROM_REGION( 0x100000, REGION_GFX1, 0 )
358   ROM_LOAD( "u421.bin", 0x00000, 0x80000, CRC(42445132) SHA1(f29d09d040644c8ef12a1cfdfc0d066e8ed9b82d) )
358   ROM_LOAD( "u421.bin", 0x00000, 0x80000, CRC(42445132) SHA1(f29d09d040644c8ef12a1cfdfc0d066e8ed9b82d) ) /* Nude & semi-nude girls, both real pictures & hand drawn */
359359   ROM_LOAD( "u420.bin", 0x80000, 0x80000, CRC(de1f0e2f) SHA1(3f46d19af48392794838a4b54f8c45b809c67d49) )
360360
361361   ROM_REGION( 0x40000, REGION_GFX2, 0 ) /* BG Tiles */
r2724r2725
363363   ROM_LOAD( "u511.bin", 0x20000, 0x20000, CRC(1411451b) SHA1(941d5f311f727e3a8d41ecbbe35b687d48cc2cef) )
364364ROM_END
365365
366ROM_START( mspuzzlg ) /* This version is a clone of Gumbo... NOT the other Miss Puzzle sets */
367   ROM_REGION( 0x80000, REGION_CPU1, 0 ) /* 68000 Code */
368   ROM_LOAD16_BYTE( "u1", 0x00001, 0x20000, CRC(95218ff1) SHA1(9617d979d026872dbe68eaae21c3ab1f5f9f4bfd) ) /* Korean bootleg / clone / hack??? */
369   ROM_LOAD16_BYTE( "u2", 0x00000, 0x20000, CRC(7ea7d96c) SHA1(17b9afb3214a07b1af5913f1926c7aeac27ea0e8) )
370
371   ROM_REGION( 0x040000, REGION_SOUND1, 0 ) /* Samples */
372   ROM_LOAD( "u210.bin", 0x00000, 0x40000, CRC(16fbe06b) SHA1(4e40e62341dc886fcabdb07f64217dc086f43c67) )
373
374   ROM_REGION( 0x200000, REGION_GFX1, 0 )
375   ROM_LOAD( "u421", 0x100000, 0x80000, CRC(afa06a93) SHA1(5c77b7aafd07d19a1eedf22858a00766a3e37389) ) /* Non-nude graphics, hand drawn girls & animals */
376   ROM_LOAD( "u420", 0x000000, 0x80000, CRC(2b387153) SHA1(c36f93d4f3a7ea8af58babeb33250d726067a35d) )
377
378   ROM_REGION( 0x40000, REGION_GFX2, 0 ) /* BG Tiles */
379   ROM_LOAD( "u512.bin", 0x00000, 0x20000, CRC(97741798) SHA1(3603e14511817da19f6819d5612728d333695e99) )
380   ROM_LOAD( "u511.bin", 0x20000, 0x20000, CRC(1411451b) SHA1(941d5f311f727e3a8d41ecbbe35b687d48cc2cef) )
381ROM_END
382
366383ROM_START( msbingo )
367384   ROM_REGION( 0x80000, REGION_CPU1, 0 ) /* 68000 Code */
368385   ROM_LOAD16_BYTE( "u1.bin", 0x00001, 0x20000, CRC(6eeb6d89) SHA1(d3e8870a2e95a1ee1c0ce80995c902a97b25a85c) )
r2724r2725
456473ROM_END
457474
458475GAME( 1994, gumbo,    0,        gumbo,    gumbo,    0, ROT0,  "Min Corp.", "Gumbo", 0 )
476GAME( 1994, mspuzzlg, gumbo,    gumbo,    gumbo,    0, ROT0,  "Min Corp.", "Miss Puzzle (Clone of Gumbo)", 0 )
459477GAME( 1994, msbingo,  0,        mspuzzle, msbingo,  0, ROT0,  "Min Corp.", "Miss Bingo", 0 )
460478GAME( 1994, mspuzzle, 0,        mspuzzle, mspuzzle, 0, ROT90, "Min Corp.", "Miss Puzzle", 0 )
461479GAME( 1994, mspuzzln, mspuzzle, mspuzzle, mspuzzle, 0, ROT90, "Min Corp.", "Miss Puzzle (Nudes)", GAME_NOT_WORKING )
src/mame/drivers/dec0.c
r2724r2725
3939***************************************************************************/
4040
4141#include "driver.h"
42#include "deprecat.h"
4342#include "cpu/m6502/m6502.h"
4443#include "cpu/h6280/h6280.h"
4544#include "dec0.h"
r2724r2725
903902
904903/******************************************************************************/
905904
906static void sound_irq(int linestate)
905static void sound_irq(running_machine *machine, int linestate)
907906{
908   cpunum_set_input_line(Machine, 1,0,linestate); /* IRQ */
907   cpunum_set_input_line(machine, 1,0,linestate); /* IRQ */
909908}
910909
911static void sound_irq2(int linestate)
910static void sound_irq2(running_machine *machine, int linestate)
912911{
913   cpunum_set_input_line(Machine, 1,1,linestate); /* IRQ2 */
912   cpunum_set_input_line(machine, 1,1,linestate); /* IRQ2 */
914913}
915914
916915static const struct YM3812interface ym3812_interface =
src/mame/drivers/ssv.c
r2724r2725
199199static UINT16 *ssv_mainram;
200200
201201/* Update the IRQ state based on all possible causes */
202static void update_irq_state(void)
202static void update_irq_state(running_machine *machine)
203203{
204   cpunum_set_input_line(Machine, 0, 0, (requested_int & irq_enable)? ASSERT_LINE : CLEAR_LINE);
204   cpunum_set_input_line(machine, 0, 0, (requested_int & irq_enable)? ASSERT_LINE : CLEAR_LINE);
205205}
206206
207207static IRQ_CALLBACK(ssv_irq_callback)
r2724r2725
223223   int level = ((offset * 2) & 0x70) >> 4;
224224   requested_int &= ~(1 << level);
225225
226   update_irq_state();
226   update_irq_state(machine);
227227}
228228
229229/*
r2724r2725
258258      if(interrupt_ultrax)
259259      {
260260         requested_int |= 1 << 1;   // needed by ultrax to coin up, breaks cairblad
261         update_irq_state();
261         update_irq_state(machine);
262262      }
263263   }
264264   else
265265   {
266266      requested_int |= 1 << 3;   // vblank
267      update_irq_state();
267      update_irq_state(machine);
268268   }
269269}
270270
r2724r2725
273273   if (cpu_getiloops())
274274   {
275275      requested_int |= 1 << 6;   // reads lightgun (4 times for 4 axis)
276      update_irq_state();
276      update_irq_state(machine);
277277   }
278278   else
279279   {
280280      requested_int |= 1 << 3;   // vblank
281      update_irq_state();
281      update_irq_state(machine);
282282   }
283283}
284284
r2724r2725
461461
462462static READ16_HANDLER( drifto94_rand_r )
463463{
464   return mame_rand(Machine) & 0xffff;
464   return mame_rand(machine) & 0xffff;
465465}
466466
467467static ADDRESS_MAP_START( drifto94_readmem, ADDRESS_SPACE_PROGRAM, 16 )
src/mame/drivers/taitoair.c
r2724r2725
216216****************************************************************************/
217217
218218#include "driver.h"
219#include "deprecat.h"
220219#include "taitoipt.h"
221220#include "audio/taitosnd.h"
222221#include "video/taitoic.h"
r2724r2725
439438   TAITO_COINAGE_WORLD_LOC(SWA)
440439
441440   /* 0xa00202 -> 0x0c0d7e (-$7283,A5) */
442   PORT_START_TAG("DSWA")
441   PORT_START_TAG("DSWB")
443442   TAITO_DIFFICULTY_LOC(SWA)
444443   PORT_DIPUNUSED_DIPLOC( 0x04, IP_ACTIVE_LOW, "SWB:3" )
445444   PORT_DIPUNUSED_DIPLOC( 0x08, IP_ACTIVE_LOW, "SWB:4" )
r2724r2725
575574************************************************************/
576575
577576/* Handler called by the YM2610 emulator when the internal timers cause an IRQ */
578static void irqhandler(int irq)
577static void irqhandler(running_machine *machine, int irq)
579578{
580   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
579   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
581580}
582581
583582static const struct YM2610interface airsys_ym2610_interface =
src/mame/drivers/mpu4drvr.c
r2724r2725
269269*/
270270
271271
272static void update_mpu68_interrupts(void)
272static void update_mpu68_interrupts(running_machine *machine)
273273{
274274   int newstate = 0;
275275
r2724r2725
284284   if (newstate)
285285   {
286286      LOGSTUFF(("68k IRQ, %x\n", newstate));
287      cpunum_set_input_line(Machine, 1, newstate, ASSERT_LINE);
287      cpunum_set_input_line(machine, 1, newstate, ASSERT_LINE);
288288   }
289289   else
290290   {
291291      LOGSTUFF(("68k IRQ Clear, %x\n", newstate));
292      cpunum_set_input_line(Machine, 1, 7, CLEAR_LINE);
292      cpunum_set_input_line(machine, 1, 7, CLEAR_LINE);
293293   }
294294}
295295
r2724r2725
307307{
308308   m6809_acia_cts = state;
309309   m6850_irq_state = state;
310   update_mpu68_interrupts();
310   update_mpu68_interrupts(Machine);
311311}
312312
313313
r2724r2725
337337};
338338
339339
340static void cpu1_ptm_irq(int state)
340static void cpu1_ptm_irq(running_machine *machine, int state)
341341{
342342   m6840_irq_state = state;
343   update_mpu68_interrupts();
343   update_mpu68_interrupts(machine);
344344}
345345
346346
r2724r2725
794794      {
795795         scn2674_irq_state = 1;
796796      }
797      update_mpu68_interrupts();
797      update_mpu68_interrupts(Machine);
798798   }
799799   if ((data&0xe0)==0x80)
800800   {
r2724r2725
820820            scn2674_irq_state = 1;
821821         }
822822      }
823      update_mpu68_interrupts();
823      update_mpu68_interrupts(Machine);
824824
825825   }
826826
r2724r2725
845845            scn2674_irq_state = 1;
846846         }
847847      }
848      update_mpu68_interrupts();
848      update_mpu68_interrupts(Machine);
849849   }
850850
851851   /* Delayed Commands */
r2724r2725
13531353         {
13541354            LOGSTUFF(("vblank irq\n"));
13551355            scn2674_irq_state = 1;
1356            update_mpu68_interrupts();
1356            update_mpu68_interrupts(machine);
13571357
13581358            scn2674_irq_register |= 0x10;
13591359         }
src/mame/drivers/aquarium.c
r2724r2725
5050
5151
5252#include "driver.h"
53#include "deprecat.h"
5453#include "sound/2151intf.h"
5554#include "sound/okim6295.h"
5655
r2724r2725
335334   GFXDECODE_ENTRY( REGION_GFX4, 0, char5bpplayout,   0x400, 32 )
336335GFXDECODE_END
337336
338static void irq_handler(int irq)
337static void irq_handler(running_machine *machine, int irq)
339338{
340   cpunum_set_input_line(Machine, 1, 0 , irq ? ASSERT_LINE : CLEAR_LINE );
339   cpunum_set_input_line(machine, 1, 0 , irq ? ASSERT_LINE : CLEAR_LINE );
341340}
342341
343342static const struct YM2151interface ym2151_interface =
src/mame/drivers/metro.c
r2724r2725
151151
152152
153153/* Update the IRQ state based on all possible causes */
154static void update_irq_state(void)
154static void update_irq_state(running_machine *machine)
155155{
156156   /*  Get the pending IRQs (only the enabled ones, e.g. where
157157        irq_enable is *0*)  */
158   UINT16 irq = metro_irq_cause_r(Machine,0,0xffff) & ~*metro_irq_enable;
158   UINT16 irq = metro_irq_cause_r(machine,0,0xffff) & ~*metro_irq_enable;
159159
160160   if (irq_line == -1)   /* mouja, gakusai, gakusai2, dokyusei, dokyusp */
161161   {
r2724r2725
167167      {
168168         if (irq & (1 << i))
169169         {
170            cpunum_set_input_line(Machine, 0, metro_irq_levels[i]&7, ASSERT_LINE);
170            cpunum_set_input_line(machine, 0, metro_irq_levels[i]&7, ASSERT_LINE);
171171            return;
172172         }
173173         i++;
174174      }
175      cpunum_set_input_line(Machine, 0, 0, ASSERT_LINE);
175      cpunum_set_input_line(machine, 0, 0, ASSERT_LINE);
176176   }
177177   else
178178   {
r2724r2725
181181            source by peeking a register (metro_irq_cause_r) */
182182
183183      int state =   (irq ? ASSERT_LINE : CLEAR_LINE);
184      cpunum_set_input_line(Machine, 0, irq_line, state);
184      cpunum_set_input_line(machine, 0, irq_line, state);
185185   }
186186}
187187
r2724r2725
218218      if (data & 0x80)   requested_int[7] = 0;
219219   }
220220
221   update_irq_state();
221   update_irq_state(machine);
222222}
223223
224224
r2724r2725
228228   {
229229      case 0:
230230         requested_int[0] = 1;
231         update_irq_state();
231         update_irq_state(machine);
232232         break;
233233
234234      default:
235235         requested_int[4] = 1;
236         update_irq_state();
236         update_irq_state(machine);
237237         break;
238238   }
239239}
r2724r2725
243243{
244244   requested_int[0] = 1;   // set scroll regs if a flag is set
245245   requested_int[4] = 1;   // clear that flag
246   update_irq_state();
246   update_irq_state(machine);
247247}
248248
249249
r2724r2725
262262         requested_int[5] = 1;   // write the scroll registers
263263         /* the duration is a guess */
264264         timer_set(ATTOTIME_IN_USEC(2500), NULL, 0, vblank_end_callback);
265         update_irq_state();
265         update_irq_state(machine);
266266         break;
267267
268268      default:
269269         requested_int[4] = 1;
270         update_irq_state();
270         update_irq_state(machine);
271271         break;
272272   }
273273}
r2724r2725
277277static TIMER_CALLBACK( mouja_irq_callback )
278278{
279279   requested_int[0] = 1;
280   update_irq_state();
280   update_irq_state(machine);
281281}
282282
283283static WRITE16_HANDLER( mouja_irq_timer_ctrl_w )
r2724r2725
289289static INTERRUPT_GEN( mouja_interrupt )
290290{
291291   requested_int[1] = 1;
292   update_irq_state();
292   update_irq_state(machine);
293293}
294294
295295
r2724r2725
299299   {
300300      case 0:
301301         requested_int[1] = 1;
302         update_irq_state();
302         update_irq_state(machine);
303303         break;
304304   }
305305}
r2724r2725
310310   {
311311      case 0:
312312         requested_int[1] = 1;
313         update_irq_state();
313         update_irq_state(machine);
314314         break;
315315      case 1:   // needed?
316316         requested_int[5] = 1;
317         update_irq_state();
317         update_irq_state(machine);
318318         break;
319319   }
320320}
321321
322static void ymf278b_interrupt(int active)
322static void ymf278b_interrupt(running_machine *machine, int active)
323323{
324   cpunum_set_input_line(Machine, 0, 2, active);
324   cpunum_set_input_line(machine, 0, 2, active);
325325}
326326
327327/***************************************************************************
r2724r2725
514514   portb = data;
515515}
516516
517static void metro_sound_irq_handler(int state)
517static void metro_sound_irq_handler(running_machine *machine, int state)
518518{
519   cpunum_set_input_line(Machine, 1, UPD7810_INTF2, state ? ASSERT_LINE : CLEAR_LINE);
519   cpunum_set_input_line(machine, 1, UPD7810_INTF2, state ? ASSERT_LINE : CLEAR_LINE);
520520}
521521
522522static const struct YM2151interface ym2151_interface =
r2724r2725
679679static TIMER_CALLBACK( metro_blit_done )
680680{
681681   requested_int[blitter_bit] = 1;
682   update_irq_state();
682   update_irq_state(machine);
683683}
684684
685685INLINE int blt_read(const UINT8 *ROM, const int offs)
r2724r2725
19391939   memory_set_bankptr(1, &RAM[bankaddress]);
19401940}
19411941
1942static void blzntrnd_irqhandler(int irq)
1942static void blzntrnd_irqhandler(running_machine *machine, int irq)
19431943{
1944   cpunum_set_input_line(Machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
1944   cpunum_set_input_line(machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
19451945}
19461946
19471947static const struct YM2610interface blzntrnd_ym2610_interface =
r2724r2725
46534653   {
46544654      case 0:
46554655         requested_int[1] = 1;
4656         update_irq_state();
4656         update_irq_state(machine);
46574657         break;
46584658
46594659      case 1:
46604660         requested_int[3] = 1;
4661         update_irq_state();
4661         update_irq_state(machine);
46624662         break;
46634663
46644664      case 2:
46654665         requested_int[5] = 1;
4666         update_irq_state();
4666         update_irq_state(machine);
46674667         break;
46684668
46694669      case 3:
46704670         requested_int[2] = 1;
4671         update_irq_state();
4671         update_irq_state(machine);
46724672         break;
46734673
46744674      default:
r2724r2725
54585458   ROM_LOAD( "tr_jb11", 0x000000, 0x020000, CRC(83786a09) SHA1(910cf0ccf4493f2a80062149f6364dbb6a1c2a5d) )
54595459ROM_END
54605460
5461ROM_START( lastfork )
5462   ROM_REGION( 0x040000, REGION_CPU1, 0 )      /* 68000 Code */
5463   ROM_LOAD16_BYTE( "7f-9",  0x000000, 0x020000, CRC(d2894c1f) SHA1(4f4ab6d8ce69999cd7c4a9ddabec8d1e8fefc6fc) )
5464   ROM_LOAD16_BYTE( "8f-10", 0x000001, 0x020000, CRC(9696ea39) SHA1(27af0c6399cd7be40aa8a1c1b58e0db8408aff11) )
5465
5466   ROM_REGION( 0x02c000, REGION_CPU2, 0 )      /* NEC78C10 Code */
5467   ROM_LOAD( "tr_jb12", 0x000000, 0x004000, CRC(8a8f5fef) SHA1(530b4966ec058cd80a2fc5f9e961239ce59d0b89) )   // (c)1992 Imagetek (11xxxxxxxxxxxxxxx = 0xFF)
5468   ROM_CONTINUE(        0x010000, 0x01c000 )
5469
5470   ROM_REGION( 0x200000, REGION_GFX1, 0 )   /* Gfx + Data (Addressable by CPU & Blitter) */
5471   ROMX_LOAD( "7i-2",  0x000000, 0x040000, CRC(d1fe8d7b) SHA1(88b1973ebb47b91a49f6b4f722c9cc33e5330694) , ROM_SKIP(7))
5472   ROMX_LOAD( "10i-4", 0x000001, 0x040000, CRC(058126d4) SHA1(985177556c8545e6a65a41083246b31509de7130) , ROM_SKIP(7))
5473   ROMX_LOAD( "13i-6", 0x000002, 0x040000, CRC(39a9dea2) SHA1(9f8067cff15be93771d42b3776ee7ca1b7c61798) , ROM_SKIP(7))
5474   ROMX_LOAD( "16i-8", 0x000003, 0x040000, CRC(4c050baa) SHA1(3e0b2029d7c0b6cd32b22f147663cd22975ce8c3) , ROM_SKIP(7))
5475   ROMX_LOAD( "5i-1",  0x000004, 0x040000, CRC(0d503f05) SHA1(0b1ce22630bb2326930f0f3b5710c6c191730c45) , ROM_SKIP(7))
5476   ROMX_LOAD( "8i-3",  0x000005, 0x040000, CRC(b6d4f753) SHA1(2864ad5fe4186e4e15bb7d5dafa6a9b8c803d7d0) , ROM_SKIP(7))
5477   ROMX_LOAD( "12i-5", 0x000006, 0x040000, CRC(ce69c805) SHA1(88debdbd8e73da54c1c25a1a60f27a05dac3f104) , ROM_SKIP(7))
5478   ROMX_LOAD( "14i-7", 0x000007, 0x040000, CRC(0cb38317) SHA1(6e18096f6616aa0d9c4f3a2394561ed3f636731e) , ROM_SKIP(7))
5479
5480   ROM_REGION( 0x020000, REGION_SOUND1, 0 )   /* Samples */
5481   ROM_LOAD( "tr_jb11", 0x000000, 0x020000, CRC(83786a09) SHA1(910cf0ccf4493f2a80062149f6364dbb6a1c2a5d) )
5482ROM_END
5483
54615484/* German version on PCB VG460-(A) */
54625485
54635486ROM_START( lastforg )
r2724r2725
54665489   ROM_LOAD16_BYTE( "trma03.bin",    0x000001, 0x020000, CRC(b00fb126) SHA1(7dd4b7a2d1c5401fde2275ef76fac1ccc586a0bd) )
54675490
54685491   ROM_REGION( 0x02c000, REGION_CPU2, 0 )      /* NEC78C10 Code */
5469   ROM_LOAD( "trma01.bin",    0x000000, 0x004000,  CRC(8a8f5fef) SHA1(530b4966ec058cd80a2fc5f9e961239ce59d0b89) )   // 11xxxxxxxxxxxxxxx = 0xFF
5470   ROM_CONTINUE(         0x010000, 0x01c000 )
5492   ROM_LOAD( "trma01.bin",  0x000000, 0x004000,  CRC(8a8f5fef) SHA1(530b4966ec058cd80a2fc5f9e961239ce59d0b89) ) /* Same as parent set, but different label */
5493   ROM_CONTINUE(            0x010000, 0x01c000 )
54715494
54725495   ROM_REGION( 0x200000, REGION_GFX1, 0 )   /* Gfx + Data (Addressable by CPU & Blitter) */
54735496   ROMX_LOAD( "trma04.bin", 0x000000, 0x080000, CRC(5feafc6f) SHA1(eb50905eb0d25eb342e08d591907f79b5eadff43) , ROM_GROUPWORD | ROM_SKIP(6))
r2724r2725
54765499   ROMX_LOAD( "trma06.bin", 0x000006, 0x080000, CRC(d366c04e) SHA1(e0a67688043cb45916860d32ff1076d9257e6ad9) , ROM_GROUPWORD | ROM_SKIP(6))
54775500
54785501   ROM_REGION( 0x020000, REGION_SOUND1, 0 )   /* Samples */
5479   ROM_LOAD( "trma08.bin",   0x000000, 0x020000, CRC(83786a09) SHA1(910cf0ccf4493f2a80062149f6364dbb6a1c2a5d) )
5502   ROM_LOAD( "trma08.bin",   0x000000, 0x020000, CRC(83786a09) SHA1(910cf0ccf4493f2a80062149f6364dbb6a1c2a5d) ) /* Same as parent set, but different label */
54805503ROM_END
54815504
54825505/***************************************************************************
r2724r2725
61406163GAME( 1994, dharmak,  dharma,   dharma,   dharma,   dharmak,  ROT0,   "Metro",                                  "Dharma Doujou (Korea)",             0 )
61416164GAME( 1994, lastfort, 0,        lastfort, lastfort, metro,    ROT0,   "Metro",                                  "Last Fortress - Toride",            0 )
61426165GAME( 1994, lastfero, lastfort, lastfort, lastfero, metro,    ROT0,   "Metro",                                  "Last Fortress - Toride (Erotic)",   0 )
6166GAME( 1994, lastfork, lastfort, lastfort, lastfero, metro,    ROT0,   "Metro",                                  "Last Fortress - Toride (Korea)",    0 )
61436167GAME( 1994, lastforg, lastfort, lastforg, ladykill, metro,    ROT0,   "Metro",                                  "Last Fortress - Toride (German)",   0 )
61446168GAME( 1994, toride2g, 0,        toride2g, toride2g, metro,    ROT0,   "Metro",                                  "Toride II Adauchi Gaiden",          GAME_IMPERFECT_GRAPHICS )
61456169GAME( 1994, torid2gg, toride2g, toride2g, toride2g, metro,    ROT0,   "Metro",                                  "Toride II Adauchi Gaiden (German)", GAME_IMPERFECT_GRAPHICS )
src/mame/drivers/angelkds.c
r2724r2725
127127
128128
129129#include "driver.h"
130#include "deprecat.h"
131130#include "cpu/z80/z80.h"
132131#include "machine/segacrpt.h"
133132#include "sound/2203intf.h"
r2724r2725
533532}
534533
535534
536static void irqhandler(int irq)
535static void irqhandler(running_machine *machine, int irq)
537536{
538   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
537   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
539538}
540539
541540static const struct YM2203interface ym2203_interface =
src/mame/drivers/jrpacman.c
r2724r2725
160160   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_4WAY
161161   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY
162162   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY
163   PORT_BIT( 0x10, 0x10, IPT_DIPSWITCH_NAME ) PORT_NAME("Rack Test (Cheat)") PORT_CODE(KEYCODE_F1)
163   PORT_DIPNAME( 0x10, 0x10, "Rack Test (Cheat)" ) PORT_CODE(KEYCODE_F1)
164164   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
165165   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
166166   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_COIN1 )
src/mame/drivers/hshavoc.c
r2724r2725
3535
3636
3737#include "driver.h"
38#include "deprecat.h"
3938#include "genesis.h"
4039
4140#define MASTER_CLOCK      53693100
r2724r2725
201200
202201static READ16_HANDLER( vdp_fake_r )
203202{
204   return mame_rand(Machine);
203   return mame_rand(machine);
205204}
206205
207206static DRIVER_INIT(genesis)
src/mame/drivers/kingpin.c
r2724r2725
2020*/
2121
2222#include "driver.h"
23#include "deprecat.h"
2423#include "video/tms9928a.h"
2524#include "sound/ay8910.h"
2625
r2724r2725
128127
129128static INTERRUPT_GEN( kingpin_video_interrupt )
130129{
131   TMS9928A_interrupt();
130   TMS9928A_interrupt(machine);
132131}
133132
134static void vdp_interrupt (int state)
133static void vdp_interrupt (running_machine *machine, int state)
135134{
136   cpunum_set_input_line(Machine, 0,0, HOLD_LINE);
135   cpunum_set_input_line(machine, 0,0, HOLD_LINE);
137136}
138137
139138static const TMS9928a_interface tms9928a_interface =
src/mame/drivers/opwolf.c
r2724r2725
9494***************************************************************************/
9595
9696#include "driver.h"
97#include "deprecat.h"
9897#include "taitoipt.h"
9998#include "video/taitoic.h"
10099#include "audio/taitosnd.h"
r2724r2725
311310   MSM5205_reset_w(1, 1);
312311}
313312
314static void opwolf_msm5205_vck(int chip)
313static void opwolf_msm5205_vck(running_machine *machine, int chip)
315314{
316315   static int adpcm_data[2] = { -1, -1 };
317316
r2724r2725
537536
538537/* handler called by the YM2151 emulator when the internal timers cause an IRQ */
539538
540static void irq_handler(int irq)
539static void irq_handler(running_machine *machine, int irq)
541540{
542   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
541   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
543542}
544543
545544
src/mame/drivers/surpratk.c
r2724r2725
99***************************************************************************/
1010
1111#include "driver.h"
12#include "deprecat.h"
1312#include "cpu/konami/konami.h" /* for the callback and the firq irq definition */
1413#include "video/konamiic.h"
1514#include "sound/2151intf.h"
r2724r2725
222221
223222
224223
225static void irqhandler(int linestate)
224static void irqhandler(running_machine *machine, int linestate)
226225{
227   cpunum_set_input_line(Machine, 0,KONAMI_FIRQ_LINE,linestate);
226   cpunum_set_input_line(machine, 0,KONAMI_FIRQ_LINE,linestate);
228227}
229228
230229static const struct YM2151interface ym2151_interface =
src/mame/drivers/suna16.c
r2724r2725
10181018                            Best Of Best
10191019***************************************************************************/
10201020
1021static void bestbest_ym3526_irqhandler(int state)
1021static void bestbest_ym3526_irqhandler(running_machine *machine, int state)
10221022{
1023   cpunum_set_input_line(Machine, 1, INPUT_LINE_IRQ0, state);
1023   cpunum_set_input_line(machine, 1, INPUT_LINE_IRQ0, state);
10241024}
10251025
10261026static const struct YM3526interface bestbest_ym3526_interface =
src/mame/drivers/zaccaria.c
r2724r2725
3434***************************************************************************/
3535
3636#include "driver.h"
37#include "deprecat.h"
3837#include "machine/6821pia.h"
3938#include "machine/8255ppi.h"
4039#include "sound/ay8910.h"
r2724r2725
10099}
101100
102101
103static void zaccaria_irq0a(int state) { cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, state ? ASSERT_LINE : CLEAR_LINE); }
104static void zaccaria_irq0b(int state) { cpunum_set_input_line(Machine, 1,0,state ? ASSERT_LINE : CLEAR_LINE); }
102static void zaccaria_irq0a(running_machine *machine, int state) { cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, state ? ASSERT_LINE : CLEAR_LINE); }
103static void zaccaria_irq0b(running_machine *machine, int state) { cpunum_set_input_line(machine, 1,0,state ? ASSERT_LINE : CLEAR_LINE); }
105104
106105static int active_8910,port0a,acs;
107106
r2724r2725
208207
209208}
210209
211static void tms5220_irq_handler(int state)
210static void tms5220_irq_handler(running_machine *machine, int state)
212211{
213   pia_1_cb1_w(Machine,0,state ? 0 : 1);
212   pia_1_cb1_w(machine,0,state ? 0 : 1);
214213}
215214
216215
src/mame/drivers/shadfrce.c
r2724r2725
532532
533533/* Machine Driver Bits */
534534
535static void irq_handler(int irq)
535static void irq_handler(running_machine *machine, int irq)
536536{
537   cpunum_set_input_line(Machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE );
537   cpunum_set_input_line(machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE );
538538}
539539
540540static const struct YM2151interface ym2151_interface =
src/mame/drivers/firebeat.c
r2724r2725
12621262   }
12631263}
12641264
1265static void comm_uart_irq_callback(int channel, int value)
1265static void comm_uart_irq_callback(running_machine *machine, int channel, int value)
12661266{
12671267   // TODO
1268   //cpunum_set_input_line(Machine, 0, INPUT_LINE_IRQ2, ASSERT_LINE);
1268   //cpunum_set_input_line(machine, 0, INPUT_LINE_IRQ2, ASSERT_LINE);
12691269}
12701270
12711271/*****************************************************************************/
r2724r2725
14131413   }
14141414}
14151415
1416static void midi_uart_irq_callback(int channel, int value)
1416static void midi_uart_irq_callback(running_machine *machine, int channel, int value)
14171417{
14181418   if (channel == 0)
14191419   {
14201420      if ((extend_board_irq_enable & 0x02) == 0)
14211421      {
14221422         extend_board_irq_active |= 0x02;
1423         cpunum_set_input_line(Machine, 0, INPUT_LINE_IRQ1, ASSERT_LINE);
1423         cpunum_set_input_line(machine, 0, INPUT_LINE_IRQ1, ASSERT_LINE);
14241424      }
14251425   }
14261426   else
r2724r2725
14281428      if ((extend_board_irq_enable & 0x01) == 0)
14291429      {
14301430         extend_board_irq_active |= 0x01;
1431         cpunum_set_input_line(Machine, 0, INPUT_LINE_IRQ1, ASSERT_LINE);
1431         cpunum_set_input_line(machine, 0, INPUT_LINE_IRQ1, ASSERT_LINE);
14321432      }
14331433   }
14341434}
r2724r2725
14831483            if ((keyboard_state[keyboard] & (1 << i)) != 0 && (kbstate & (1 << i)) == 0)
14841484            {
14851485               // key was on, now off -> send Note Off message
1486               pc16552d_rx_data(1, uart_channel, 0x80);
1487               pc16552d_rx_data(1, uart_channel, kbnote);
1488               pc16552d_rx_data(1, uart_channel, 0x7f);
1486               pc16552d_rx_data(machine, 1, uart_channel, 0x80);
1487               pc16552d_rx_data(machine, 1, uart_channel, kbnote);
1488               pc16552d_rx_data(machine, 1, uart_channel, 0x7f);
14891489            }
14901490            else if ((keyboard_state[keyboard] & (1 << i)) == 0 && (kbstate & (1 << i)) != 0)
14911491            {
14921492               // key was off, now on -> send Note On message
1493               pc16552d_rx_data(1, uart_channel, 0x90);
1494               pc16552d_rx_data(1, uart_channel, kbnote);
1495               pc16552d_rx_data(1, uart_channel, 0x7f);
1493               pc16552d_rx_data(machine, 1, uart_channel, 0x90);
1494               pc16552d_rx_data(machine, 1, uart_channel, kbnote);
1495               pc16552d_rx_data(machine, 1, uart_channel, 0x7f);
14961496            }
14971497         }
14981498      }
14991499      else
15001500      {
15011501         // no messages, send Active Sense message instead
1502         pc16552d_rx_data(1, uart_channel, 0xfe);
1502         pc16552d_rx_data(machine, 1, uart_channel, 0xfe);
15031503      }
15041504
15051505      keyboard_state[keyboard] = kbstate;
r2724r2725
17901790{
17911791}
17921792
1793static void sound_irq_callback(int state)
1793static void sound_irq_callback(running_machine *machine, int state)
17941794{
17951795}
17961796
src/mame/drivers/eolith.c
r2724r2725
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 )
src/mame/drivers/inufuku.c
r2724r2725
6868******************************************************************************/
6969
7070#include "driver.h"
71#include "deprecat.h"
7271#include "cpu/m68000/m68000.h"
7372#include "cpu/z80/z80.h"
7473#include "machine/eeprom.h"
r2724r2725
377376
378377******************************************************************************/
379378
380static void irqhandler(int irq)
379static void irqhandler(running_machine *machine, int irq)
381380{
382   cpunum_set_input_line(Machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
381   cpunum_set_input_line(machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
383382}
384383
385384static const struct YM2610interface ym2610_interface =
src/mame/drivers/ninjakd2.c
r2724r2725
121121******************************************************************************/
122122
123123#include "driver.h"
124#include "deprecat.h"
125124#include "sound/2203intf.h"
126125#include "sound/samples.h"
127126#include "machine/mc8123.h"
r2724r2725
897896 *
898897 *************************************/
899898
900static void irqhandler(int irq)
899static void irqhandler(running_machine *machine, int irq)
901900{
902   cpunum_set_input_line(Machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
901   cpunum_set_input_line(machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
903902}
904903
905904static const struct YM2203interface ym2203_interface =
src/mame/drivers/yunsung8.c
r2724r2725
3030***************************************************************************/
3131
3232#include "driver.h"
33#include "deprecat.h"
3433#include "cpu/z80/z80.h"
3534#include "sound/3812intf.h"
3635#include "sound/msm5205.h"
r2724r2725
485484***************************************************************************/
486485
487486
488static void yunsung8_adpcm_int(int irq)
487static void yunsung8_adpcm_int(running_machine *machine, int irq)
489488{
490489   static int toggle=0;
491490
r2724r2725
494493
495494   toggle ^= 1;
496495   if (toggle)
497      cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, PULSE_LINE);
496      cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, PULSE_LINE);
498497}
499498
500499static const struct MSM5205interface yunsung8_msm5205_interface =
src/mame/drivers/wheelfir.c
r2724r2725
5959
6060
6161
62   return input_port_read_indexed(machine, 0)^toggle_bit;// mame_rand(Machine);
62   return input_port_read_indexed(machine, 0)^toggle_bit;// mame_rand(machine);
6363}
6464
6565static READ16_HANDLER( wheelfir_rand2 )
6666{
67   return input_port_read_indexed(machine, 1);// mame_rand(Machine);
67   return input_port_read_indexed(machine, 1);// mame_rand(machine);
6868}
6969
7070
7171static READ16_HANDLER( wheelfir_rand4 )
7272{
73   return mame_rand(Machine);
73   return mame_rand(machine);
7474}
7575
7676static UINT16 *wheelfir_myram;
src/mame/drivers/steaser.c
r2724r2725
3535
3636
3737#include "driver.h"
38#include "deprecat.h"
3938
4039static VIDEO_START(steaser)
4140{
r2724r2725
4847
4948static READ16_HANDLER( steaser_bd0000_r )
5049{
51   return mame_rand(Machine);
50   return mame_rand(machine);
5251}
5352
5453static ADDRESS_MAP_START( steaser_map, ADDRESS_SPACE_PROGRAM, 16 )
src/mame/drivers/cbuster.c
r2724r2725
1414***************************************************************************/
1515
1616#include "driver.h"
17#include "deprecat.h"
1817#include "cpu/h6280/h6280.h"
1918#include "sound/2203intf.h"
2019#include "sound/2151intf.h"
r2724r2725
331330
332331/******************************************************************************/
333332
334static void sound_irq(int state)
333static void sound_irq(running_machine *machine, int state)
335334{
336   cpunum_set_input_line(Machine, 1,1,state); /* IRQ 2 */
335   cpunum_set_input_line(machine, 1,1,state); /* IRQ 2 */
337336}
338337
339338static const struct YM2151interface ym2151_interface =
src/mame/drivers/onetwo.c
r2724r2725
260260   return 0;
261261}
262262
263static void irqhandler(int linestate)
263static void irqhandler(running_machine *machine, int linestate)
264264{
265   cpunum_set_input_line(Machine, 1,0,linestate);
265   cpunum_set_input_line(machine, 1,0,linestate);
266266}
267267
268268static const struct YM3812interface ym3812_interface =
src/mame/drivers/ojankohs.c
r2724r2725
3232******************************************************************************/
3333
3434#include "driver.h"
35#include "deprecat.h"
3635#include "cpu/z80/z80.h"
3736#include "sound/ay8910.h"
3837#include "sound/msm5205.h"
r2724r2725
106105   ojankohs_vclk_left = 2;
107106}
108107
109static void ojankohs_adpcm_int(int irq)
108static void ojankohs_adpcm_int(running_machine *machine, int irq)
110109{
111110   /* skip if we're reset */
112111   if (!ojankohs_adpcm_reset)
r2724r2725
121120
122121   /* generate an NMI if we're out of data */
123122   if (!ojankohs_vclk_left)
124      cpunum_set_input_line(Machine, 0, INPUT_LINE_NMI, PULSE_LINE);
123      cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, PULSE_LINE);
125124}
126125
127126static WRITE8_HANDLER( ojankoc_ctrl_w )
src/mame/drivers/wc90b.c
r2724r2725
8383*/
8484
8585#include "driver.h"
86#include "deprecat.h"
8786#include "cpu/z80/z80.h"
8887#include "sound/2203intf.h"
8988#include "sound/msm5205.h"
r2724r2725
348347
349348
350349/* handler called by the 2203 emulator when the internal timers cause an IRQ */
351static void irqhandler(int irq)
350static void irqhandler(running_machine *machine, int irq)
352351{
353   cpunum_set_input_line(Machine, 2, INPUT_LINE_NMI, irq ? ASSERT_LINE : CLEAR_LINE);
352   cpunum_set_input_line(machine, 2, INPUT_LINE_NMI, irq ? ASSERT_LINE : CLEAR_LINE);
354353}
355354
356355static const struct YM2203interface ym2203_interface =
r2724r2725
363362   irqhandler
364363};
365364
366static void adpcm_int(int data)
365static void adpcm_int(running_machine *machine, int data)
367366{
368367   static int toggle = 0;
369368
r2724r2725
372371
373372   toggle ^= 1;
374373   if(toggle)
375      cpunum_set_input_line(Machine, 2, INPUT_LINE_NMI, PULSE_LINE);
374      cpunum_set_input_line(machine, 2, INPUT_LINE_NMI, PULSE_LINE);
376375
377376}
378377
src/mame/drivers/spdodgeb.c
r2724r2725
7676   }
7777}
7878
79static void spd_adpcm_int(int chip)
79static void spd_adpcm_int(running_machine *machine, int chip)
8080{
8181   static int adpcm_data[2] = { -1, -1 };
8282
r2724r2725
412412GFXDECODE_END
413413
414414
415static void irq_handler(int irq)
415static void irq_handler(running_machine *machine, int irq)
416416{
417   cpunum_set_input_line(Machine, 1,M6809_FIRQ_LINE,irq ? ASSERT_LINE : CLEAR_LINE);
417   cpunum_set_input_line(machine,1,M6809_FIRQ_LINE,irq ? ASSERT_LINE : CLEAR_LINE);
418418}
419419
420420static const struct YM3812interface ym3812_interface =
src/mame/drivers/seta.c
r2724r2725
14221422   0x1000,      /* address */
14231423};
14241424
1425static void utoukond_ym3438_interrupt(int linestate)
1425static void utoukond_ym3438_interrupt(running_machine *machine, int linestate)
14261426{
1427   cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, linestate);
1427   cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, linestate);
14281428}
14291429
14301430static const struct YM3438interface utoukond_ym3438_intf =
src/mame/drivers/laserbat.c
r2724r2725
1717*/
1818
1919#include "driver.h"
20#include "deprecat.h"
2120#include "cpu/s2650/s2650.h"
2221#include "machine/6821pia.h"
2322#include "video/s2636.h"
r2724r2725
594593
595594/* Cat'N Mouse sound ***********************************/
596595
597static void zaccaria_irq0a(int state) { cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, state ? ASSERT_LINE : CLEAR_LINE); }
598static void zaccaria_irq0b(int state) { cpunum_set_input_line(Machine, 1,0,state ? ASSERT_LINE : CLEAR_LINE); }
596static void zaccaria_irq0a(running_machine *machine, int state) { cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, state ? ASSERT_LINE : CLEAR_LINE); }
597static void zaccaria_irq0b(running_machine *machine, int state) { cpunum_set_input_line(machine, 1,0,state ? ASSERT_LINE : CLEAR_LINE); }
599598
600599static int active_8910,port0a;
601600
src/mame/drivers/trvquest.c
r2724r2725
152152   cpunum_set_input_line(machine, 0, 0, param);
153153}
154154
155static void via_irq(int state)
155static void via_irq(running_machine *machine, int state)
156156{
157157   // from gameplan.c
158158
src/mame/drivers/tnzs.c
r2724r2725
246246
247247
248248#include "driver.h"
249#include "deprecat.h"
250249#include "cpu/i8x41/i8x41.h"
251250#include "sound/2203intf.h"
252251#include "sound/dac.h"
r2724r2725
560559   b = (paldata >> 8) & 0x000f;
561560   // the other bits seem to be used, and the colours are wrong..
562561
563   palette_set_color_rgb(Machine,offset,r<<4, g<<4, b<<4);
562   palette_set_color_rgb(machine,offset,r<<4, g<<4, b<<4);
564563}
565564
566565static ADDRESS_MAP_START( jpopnics_main_map, ADDRESS_SPACE_PROGRAM, 8 )
r2724r2725
14281427
14291428
14301429/* handler called by the 2203 emulator when the internal timers cause an IRQ */
1431static void irqhandler(int irq)
1430static void irqhandler(running_machine *machine, int irq)
14321431{
1433   cpunum_set_input_line(Machine, 2, INPUT_LINE_NMI, irq ? ASSERT_LINE : CLEAR_LINE);
1432   cpunum_set_input_line(machine, 2, INPUT_LINE_NMI, irq ? ASSERT_LINE : CLEAR_LINE);
14341433}
14351434
14361435static const struct YM2203interface kageki_ym2203_interface =
src/mame/drivers/rohga.c
r2724r2725
108108***************************************************************************/
109109
110110#include "driver.h"
111#include "deprecat.h"
112111#include "cpu/h6280/h6280.h"
113112#include "decocrpt.h"
114113#include "decoprot.h"
r2724r2725
793792
794793/**********************************************************************************/
795794
796static void sound_irq(int state)
795static void sound_irq(running_machine *machine, int state)
797796{
798   cpunum_set_input_line(Machine, 1,1,state); /* IRQ 2 */
797   cpunum_set_input_line(machine, 1,1,state); /* IRQ 2 */
799798}
800799
801800static WRITE8_HANDLER( sound_bankswitch_w )
src/mame/drivers/vball.c
r2724r2725
387387   GFXDECODE_ENTRY( REGION_GFX2, 0, spritelayout, 128, 8 )   /* 16x16 sprites */
388388GFXDECODE_END
389389
390static void vball_irq_handler(int irq)
390static void vball_irq_handler(running_machine *machine, int irq)
391391{
392   cpunum_set_input_line(Machine, 1, 0 , irq ? ASSERT_LINE : CLEAR_LINE );
392   cpunum_set_input_line(machine, 1, 0 , irq ? ASSERT_LINE : CLEAR_LINE );
393393}
394394
395395static const struct YM2151interface ym2151_interface =
src/mame/drivers/naomi.c
r2724r2725
510510#include "cpu/arm7/arm7core.h"
511511#include "sound/aica.h"
512512#include "dc.h"
513#include "deprecat.h"
514513
515514#define CPU_CLOCK (200000000)
516515                                 /* MD2 MD1 MD0 MD6 MD4 MD3 MD5 MD7 MD8 */
r2724r2725
715714   return -1;
716715}
717716
718static void aica_irq(int irq)
717static void aica_irq(running_machine *machine, int irq)
719718{
720   cpunum_set_input_line(Machine, 1, ARM7_FIRQ_LINE, irq ? ASSERT_LINE : CLEAR_LINE);
719   cpunum_set_input_line(machine, 1, ARM7_FIRQ_LINE, irq ? ASSERT_LINE : CLEAR_LINE);
721720}
722721
723722static ADDRESS_MAP_START( dc_audio_map, ADDRESS_SPACE_PROGRAM, 32 )
src/mame/drivers/nemesis.c
r2724r2725
21142114   REGION_SOUND1   /* prom memory region */
21152115};
21162116
2117static void sound_irq(int state)
2117static void sound_irq(running_machine *machine, int state)
21182118{
21192119/* Interrupts _are_ generated, I wonder where they go.. */
2120/*cpunum_set_input_line(Machine, 1,0,HOLD_LINE);*/
2120/*cpunum_set_input_line(machine, 1,0,HOLD_LINE);*/
21212121}
21222122
21232123static const struct YM2151interface ym2151_interface =
src/mame/drivers/cheekyms.c
r2724r2725
2626{
2727   /* this starts a 556 one-shot timer (and triggers a sound effect) */
2828   if (newval)
29      cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, PULSE_LINE);
29      cpunum_set_input_line(field->port->machine, 0, INPUT_LINE_NMI, PULSE_LINE);
3030}
3131
3232
src/mame/drivers/stv.c
r2724r2725
26462646
26472647static int scsp_last_line = 0;
26482648
2649static void scsp_irq(int irq)
2649static void scsp_irq(running_machine *machine, int irq)
26502650{
26512651   // don't bother the 68k if it's off
26522652   if (!en_68k)
r2724r2725
26572657   if (irq > 0)
26582658   {
26592659      scsp_last_line = irq;
2660      cpunum_set_input_line(Machine, 2, irq, ASSERT_LINE);
2660      cpunum_set_input_line(machine, 2, irq, ASSERT_LINE);
26612661   }
26622662   else if (irq < 0)
26632663   {
2664      cpunum_set_input_line(Machine, 2, -irq, CLEAR_LINE);
2664      cpunum_set_input_line(machine, 2, -irq, CLEAR_LINE);
26652665   }
26662666   else
26672667   {
2668      cpunum_set_input_line(Machine, 2, scsp_last_line, CLEAR_LINE);
2668      cpunum_set_input_line(machine, 2, scsp_last_line, CLEAR_LINE);
26692669   }
26702670}
26712671
src/mame/drivers/warriorb.c
r2724r2725
144144***************************************************************************/
145145
146146#include "driver.h"
147#include "deprecat.h"
148147#include "taitoipt.h"
149148#include "rendlay.h"
150149#include "cpu/m68000/m68000.h"
r2724r2725
401400**************************************************************/
402401
403402/* handler called by the YM2610 emulator when the internal timers cause an IRQ */
404static void irqhandler(int irq)
403static void irqhandler(running_machine *machine, int irq)
405404{
406   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
405   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
407406}
408407
409408static const struct YM2610interface ym2610_interface =
src/mame/drivers/igs_blit.c
r2724r2725
24562456
24572457
24582458
2459static void sound_irq(int state)
2459static void sound_irq(running_machine *machine, int state)
24602460{
2461//  cpunum_set_input_line(Machine, 0, 3, state);
2461//  cpunum_set_input_line(machine, 0, 3, state);
24622462}
24632463
24642464static const struct ics2115_interface pgm_ics2115_interface = {
src/mame/drivers/goal92.c
r2724r2725
88***************************************************************************/
99
1010#include "driver.h"
11#include "deprecat.h"
1211#include "sound/2203intf.h"
1312#include "sound/okim6295.h"
1413#include "sound/msm5205.h"
r2724r2725
233232INPUT_PORTS_END
234233
235234/* handler called by the 2203 emulator when the internal timers cause an IRQ */
236static void irqhandler(int irq)
235static void irqhandler(running_machine *machine, int irq)
237236{
238   cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, irq ? ASSERT_LINE : CLEAR_LINE);
237   cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, irq ? ASSERT_LINE : CLEAR_LINE);
239238}
240239
241240static const struct YM2203interface ym2203_interface =
r2724r2725
248247   irqhandler
249248};
250249
251static void goal92_adpcm_int(int data)
250static void goal92_adpcm_int(running_machine *machine, int data)
252251{
253252   static int toggle = 0;
254253
r2724r2725
257256
258257   toggle ^= 1;
259258   if(toggle)
260      cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, PULSE_LINE);
259      cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, PULSE_LINE);
261260}
262261
263262static const struct MSM5205interface msm5205_interface =
src/mame/drivers/bishi.c
r2724r2725
321321{
322322}
323323
324static void sound_irq_gen(int state)
324static void sound_irq_gen(running_machine *machine, int state)
325325{
326326   if (state)
327      cpunum_set_input_line(Machine, 0, MC68000_IRQ_1, ASSERT_LINE);
327      cpunum_set_input_line(machine, 0, MC68000_IRQ_1, ASSERT_LINE);
328328   else
329      cpunum_set_input_line(Machine, 0, MC68000_IRQ_1, CLEAR_LINE);
329      cpunum_set_input_line(machine, 0, MC68000_IRQ_1, CLEAR_LINE);
330330}
331331
332332static const struct YMZ280Binterface ymz280b_intf =
src/mame/drivers/alg.c
r2724r2725
244244   int x = 0, y = 0;
245245
246246   /* get the position based on the input select */
247   get_lightgun_pos(machine->primary_screen, input_select, &x, &y);
247   get_lightgun_pos(field->port->machine->primary_screen, input_select, &x, &y);
248248   return (y << 8) | (x >> 2);
249249}
250250
r2724r2725
252252static CUSTOM_INPUT( lightgun_trigger_r )
253253{
254254   /* read the trigger control based on the input select */
255   return (input_port_read(machine, "TRIGGERS") >> input_select) & 1;
255   return (input_port_read(field->port->machine, "TRIGGERS") >> input_select) & 1;
256256}
257257
258258
259259static CUSTOM_INPUT( lightgun_holster_r )
260260{
261261   /* read the holster control based on the input select */
262   return (input_port_read(machine, "TRIGGERS") >> (2 + input_select)) & 1;
262   return (input_port_read(field->port->machine, "TRIGGERS") >> (2 + input_select)) & 1;
263263}
264264
265265
src/mame/drivers/fromanc2.c
r2724r2725
2222******************************************************************************/
2323
2424#include "driver.h"
25#include "deprecat.h"
2625#include "cpu/m68000/m68000.h"
2726#include "cpu/z80/z80.h"
2827#include "machine/eeprom.h"
r2724r2725
683682//
684683// ----------------------------------------------------------------------------
685684
686static void irqhandler(int irq)
685static void irqhandler(running_machine *machine, int irq)
687686{
688   cpunum_set_input_line(Machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
687   cpunum_set_input_line(machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
689688}
690689
691690static const struct YM2610interface ym2610_interface =
src/mame/drivers/bnstars.c
r2724r2725
12991299   return i;
13001300}
13011301
1302static void irq_init(void)
1302static void irq_init(running_machine *machine)
13031303{
13041304   irqreq = 0;
1305   cpunum_set_input_line(Machine, 0, 0, CLEAR_LINE);
1305   cpunum_set_input_line(machine, 0, 0, CLEAR_LINE);
13061306   cpunum_set_irq_callback(0, irq_callback);
13071307}
13081308
1309static void irq_raise(int level)
1309static void irq_raise(running_machine *machine, int level)
13101310{
13111311   irqreq |= (1<<level);
1312   cpunum_set_input_line(Machine, 0, 0, ASSERT_LINE);
1312   cpunum_set_input_line(machine, 0, 0, ASSERT_LINE);
13131313}
13141314
13151315
13161316static INTERRUPT_GEN(ms32_interrupt)
13171317{
1318   if( cpu_getiloops() == 0 ) irq_raise(10);
1319   if( cpu_getiloops() == 1 ) irq_raise(9);
1318   if( cpu_getiloops() == 0 ) irq_raise(machine, 10);
1319   if( cpu_getiloops() == 1 ) irq_raise(machine, 9);
13201320   /* hayaosi1 needs at least 12 IRQ 0 per frame to work (see code at FFE02289)
13211321       kirarast needs it too, at least 8 per frame, but waits for a variable amount
13221322       47pi2 needs ?? per frame (otherwise it hangs when you lose)
r2724r2725
13251325       desertwr
13261326       p47aces
13271327       */
1328   if( cpu_getiloops() >= 3 && cpu_getiloops() <= 32 ) irq_raise(0);
1328   if( cpu_getiloops() >= 3 && cpu_getiloops() <= 32 ) irq_raise(machine, 0);
13291329}
13301330
13311331static MACHINE_RESET( ms32 )
13321332{
1333   irq_init();
1333   irq_init(machine);
13341334}
13351335
13361336
src/mame/drivers/realbrk.c
r2724r2725
673673   {
674674      case 0:
675675         /* VBlank is connected to INT1 (external interrupts pin 1) */
676         tmp68301_external_interrupt_1();
676         tmp68301_external_interrupt_1(machine);
677677         break;
678678   }
679679}
src/mame/drivers/segag80v.c
r2724r2725
182182{
183183   /* pressing the service switch sends an NMI */
184184   if (newval)
185      cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, PULSE_LINE);
185      cpunum_set_input_line(field->port->machine, 0, INPUT_LINE_NMI, PULSE_LINE);
186186}
187187
188188
r2724r2725
313313
314314static CUSTOM_INPUT( elim4_joint_coin_r )
315315{
316   return (input_port_read(machine, "COINS") & 0xf) != 0xf;
316   return (input_port_read(field->port->machine, "COINS") & 0xf) != 0xf;
317317}
318318
319319
src/mame/drivers/ace.c
r2724r2725
3838****************************************************************************/
3939
4040#include "driver.h"
41#include "deprecat.h"
4241
4342
4443static UINT8 *ace_scoreram;
r2724r2725
139138
140139static READ8_HANDLER( unk_r )
141140{
142   return mame_rand(Machine)&0xff;
141   return mame_rand(machine)&0xff;
143142}
144143
145144
src/mame/drivers/battlera.c
r2724r2725
103103
104104static int msm5205next;
105105
106static void battlera_adpcm_int(int data)
106static void battlera_adpcm_int(running_machine *machine, int data)
107107{
108108   static int toggle;
109109
r2724r2725
112112
113113   toggle = 1 - toggle;
114114   if (toggle)
115      cpunum_set_input_line(Machine, 1, 1, HOLD_LINE);
115      cpunum_set_input_line(machine, 1, 1, HOLD_LINE);
116116}
117117
118118static WRITE8_HANDLER( battlera_adpcm_data_w )
src/mame/drivers/xain.c
r2724r2725
432432
433433
434434/* handler called by the 2203 emulator when the internal timers cause an IRQ */
435static void irqhandler(int irq)
435static void irqhandler(running_machine *machine, int irq)
436436{
437   cpunum_set_input_line(Machine, 2,M6809_FIRQ_LINE,irq ? ASSERT_LINE : CLEAR_LINE);
437   cpunum_set_input_line(machine, 2,M6809_FIRQ_LINE,irq ? ASSERT_LINE : CLEAR_LINE);
438438}
439439
440440static const struct YM2203interface ym2203_interface =
src/mame/drivers/galdrvr.c
r2724r2725
755755   PORT_BIT( 0xf0, IP_ACTIVE_HIGH, IPT_UNUSED )
756756
757757   PORT_START_TAG("GAMESEL")      /* fake - game select */
758   PORT_BIT( 0x01, 0x00, IPT_DIPSWITCH_NAME ) PORT_NAME("Game Select") PORT_CODE(KEYCODE_F1) PORT_TOGGLE PORT_CHANGED(gmgalax_game_changed, NULL)
758   PORT_DIPNAME( 0x01, 0x00, "Game Select") PORT_CODE(KEYCODE_F1) PORT_TOGGLE PORT_CHANGED(gmgalax_game_changed, NULL)
759759   PORT_DIPSETTING( 0x00, "Ghost Muncher" )
760760   PORT_DIPSETTING( 0x01, "Galaxian" )
761761INPUT_PORTS_END
src/mame/drivers/namcos1.c
r2724r2725
339339***********************************************************************/
340340
341341#include "driver.h"
342#include "deprecat.h"
343342#include "cpu/m6809/m6809.h"
344343#include "cpu/m6800/m6800.h"
345344#include "sound/2151intf.h"
r2724r2725
970969
971970
972971
973static void namcos1_sound_interrupt( int irq )
972static void namcos1_sound_interrupt( running_machine *machine, int irq )
974973{
975   cpunum_set_input_line(Machine, 2, M6809_FIRQ_LINE, irq ? ASSERT_LINE : CLEAR_LINE);
974   cpunum_set_input_line(machine, 2, M6809_FIRQ_LINE, irq ? ASSERT_LINE : CLEAR_LINE);
976975}
977976
978977static const struct YM2151interface ym2151_interface =
src/mame/drivers/m62.c
r2724r2725
853853   PORT_DIPNAME( 0x40, 0x40, "Invulnerability (Cheat)")
854854   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
855855   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
856   PORT_BIT(    0x80, 0x80, IPT_DIPSWITCH_NAME ) PORT_NAME("Service Mode (must set 2P game to No)") PORT_TOGGLE PORT_CODE(KEYCODE_F2)
856   PORT_DIPNAME( 0x80, 0x80, "Service Mode (must set 2P game to No)" ) PORT_TOGGLE PORT_CODE(KEYCODE_F2)
857857   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
858858   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
859859INPUT_PORTS_END
src/mame/drivers/astrocde.c
r2724r2725
110110****************************************************************************/
111111
112112#include "driver.h"
113#include "deprecat.h"
114113#include "cpu/z80/z80daisy.h"
115114#include "includes/astrocde.h"
116115#include "machine/z80ctc.h"
r2724r2725
258257static CUSTOM_INPUT( ebases_trackball_r )
259258{
260259   static const char *const names[] = { "TRACKX2", "TRACKY2", "TRACKX1", "TRACKY1" };
261   return input_port_read(machine, names[input_select]);
260   return input_port_read(field->port->machine, names[input_select]);
262261}
263262
264263
r2724r2725
474473static CUSTOM_INPUT( demndragn_joystick_r )
475474{
476475   static const char *const names[] = { "MOVEX", "MOVEY" };
477   return input_port_read(machine, names[input_select]);
476   return input_port_read(field->port->machine, names[input_select]);
478477}
479478
480479
r2724r2725
491490 *
492491 *************************************/
493492
494static void ctc_interrupt(int state)
493static void ctc_interrupt(running_machine *machine, int state)
495494{
496   cpunum_set_input_line(Machine, 1, 0, state);
495   cpunum_set_input_line(machine, 1, 0, state);
497496}
498497
499498
r2724r2725
14201419
14211420   MDRV_SOUND_ADD(SAMPLES, 0)
14221421   MDRV_SOUND_CONFIG(gorf_samples_interface)
1423   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "upper", 0.25)
1422   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "upper", 0.85)
14241423MACHINE_DRIVER_END
14251424
14261425
r2724r2725
17401739{
17411740   astrocade_video_config = 0x00;
17421741   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_IO, 0x14, 0x14, 0x1fff, 0xff00, demndrgn_io_r);
1743   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_IO, 0x1c, 0x1c, 0x0000, 0xff00, port_tag_to_handler8("FIREX"));
1744   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_IO, 0x1d, 0x1d, 0x0000, 0xff00, port_tag_to_handler8("FIREY"));
1742   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_IO, 0x1c, 0x1c, 0x0000, 0xff00, input_port_read_handler8(machine->portconfig, "FIREX"));
1743   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_IO, 0x1d, 0x1d, 0x0000, 0xff00, input_port_read_handler8(machine->portconfig, "FIREY"));
17451744   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_IO, 0x97, 0x97, 0x0000, 0xff00, demndrgn_sound_w);
17461745
17471746   /* reset banking */
r2724r2725
17531752static DRIVER_INIT( tenpindx )
17541753{
17551754   astrocade_video_config = 0x00;
1756   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_IO, 0x60, 0x60, 0x0000, 0xff00, port_tag_to_handler8("P60"));
1757   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_IO, 0x61, 0x61, 0x0000, 0xff00, port_tag_to_handler8("P61"));
1758   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_IO, 0x62, 0x62, 0x0000, 0xff00, port_tag_to_handler8("P62"));
1759   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_IO, 0x63, 0x63, 0x0000, 0xff00, port_tag_to_handler8("P63"));
1760   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_IO, 0x64, 0x64, 0x0000, 0xff00, port_tag_to_handler8("P64"));
1755   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_IO, 0x60, 0x60, 0x0000, 0xff00, input_port_read_handler8(machine->portconfig, "P60"));
1756   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_IO, 0x61, 0x61, 0x0000, 0xff00, input_port_read_handler8(machine->portconfig, "P61"));
1757   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_IO, 0x62, 0x62, 0x0000, 0xff00, input_port_read_handler8(machine->portconfig, "P62"));
1758   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_IO, 0x63, 0x63, 0x0000, 0xff00, input_port_read_handler8(machine->portconfig, "P63"));
1759   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_IO, 0x64, 0x64, 0x0000, 0xff00, input_port_read_handler8(machine->portconfig, "P64"));
17611760   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_IO, 0x65, 0x66, 0x0000, 0xff00, tenpindx_lamp_w);
17621761   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_IO, 0x67, 0x67, 0x0000, 0xff00, tenpindx_counter_w);
17631762   memory_install_write8_handler(machine, 0, ADDRESS_SPACE_IO, 0x68, 0x68, 0x0000, 0xff00, tenpindx_lights_w);
src/mame/drivers/deco156.c
r2724r2725
404404
405405/**********************************************************************************/
406406
407static void sound_irq_gen(int state)
407static void sound_irq_gen(running_machine *machine, int state)
408408{
409409   logerror("sound irq\n");
410410}
src/mame/drivers/toki.c
r2724r2725
3535***************************************************************************/
3636
3737#include "driver.h"
38#include "deprecat.h"
3938#include "cpu/z80/z80.h"
4039#include "audio/seibu.h"
4140#include "sound/3812intf.h"
r2724r2725
7372
7473static int msm5205next;
7574
76static void toki_adpcm_int (int data)
75static void toki_adpcm_int (running_machine *machine, int data)
7776{
7877   static int toggle=0;
7978
r2724r2725
8281
8382   toggle ^= 1;
8483   if (toggle)
85      cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, PULSE_LINE);
84      cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, PULSE_LINE);
8685}
8786
8887static WRITE8_HANDLER( toki_adpcm_control_w )
src/mame/drivers/renegade.c
r2724r2725
765765
766766
767767/* handler called by the 3526 emulator when the internal timers cause an IRQ */
768static void irqhandler(int linestate)
768static void irqhandler(running_machine *machine, int linestate)
769769{
770   cpunum_set_input_line(Machine, 1, M6809_FIRQ_LINE, linestate);
770   cpunum_set_input_line(machine, 1, M6809_FIRQ_LINE, linestate);
771771}
772772
773773static const struct YM3526interface ym3526_interface =
src/mame/drivers/sg1000a.c
r2724r2725
112112******************************************************/
113113
114114#include "driver.h"
115#include "deprecat.h"
116115#include "sound/sn76496.h"
117116#include "video/tms9928a.h"
118117#include "machine/segacrpt.h"
r2724r2725
244243
245244static INTERRUPT_GEN( sg100a_interrupt )
246245{
247   TMS9928A_interrupt();
246   TMS9928A_interrupt(machine);
248247}
249248
250static void vdp_interrupt (int state)
249static void vdp_interrupt (running_machine *machine, int state)
251250{
252   cpunum_set_input_line(Machine, 0,0, HOLD_LINE);
251   cpunum_set_input_line(machine, 0,0, HOLD_LINE);
253252}
254253
255254static const TMS9928a_interface tms9928a_interface =
src/mame/drivers/lasso.c
r2724r2725
3838static INPUT_CHANGED( coin_inserted )
3939{
4040   /* coin insertion causes an NMI */
41   cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, newval ? CLEAR_LINE : ASSERT_LINE);
41   cpunum_set_input_line(field->port->machine, 0, INPUT_LINE_NMI, newval ? CLEAR_LINE : ASSERT_LINE);
4242}
4343
4444
src/mame/drivers/psychic5.c
r2724r2725
535535
536536
537537
538static void irqhandler(int irq)
538static void irqhandler(running_machine *machine, int irq)
539539{
540   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
540   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
541541}
542542
543543static const struct YM2203interface ym2203_interface =
src/mame/drivers/taito_h.c
r2724r2725
128128
129129
130130#include "driver.h"
131#include "deprecat.h"
132131#include "taitoipt.h"
133132#include "audio/taitosnd.h"
134133#include "video/taitoic.h"
r2724r2725
159158***************************************************************************/
160159
161160/* Handler called by the YM2610 emulator when the internal timers cause an IRQ */
162static void irqhandler(int irq)
161static void irqhandler(running_machine *machine, int irq)
163162{
164   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
163   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
165164}
166165
167166static const struct YM2610interface syvalion_ym2610_interface =
src/mame/drivers/8080bw.c
r2724r2725
8989#include "machine/mb14241.h"
9090
9191#include "invrvnge.lh"
92#include "shuttlei.lh"
9293
9394/*******************************************************/
9495/*                                                     */
r2724r2725
14121413      case 0x5ffc:   return 0;
14131414   }
14141415   logerror("unknown port 0 read @ %x\n",activecpu_get_pc());
1415   return mame_rand(Machine);
1416   return mame_rand(machine);
14161417}
14171418
14181419static ADDRESS_MAP_START( indianbt_io_map, ADDRESS_SPACE_IO, 8 )
r2724r2725
23802381GAME( 1979, spaceph,  ozmawars, invaders, spaceph,  0, ROT270, "Zilec Games", "Space Phantoms", 0 )
23812382GAME( 1979, yosakdon, 0,        yosakdon, yosakdon, 0, ROT270, "Wing", "Yosaku To Donbei (set 1)", GAME_IMPERFECT_SOUND ) /* bootleg? */
23822383GAME( 1979, yosakdoa, yosakdon, yosakdon, yosakdon, 0, ROT270, "Wing", "Yosaku To Donbei (set 2)", GAME_IMPERFECT_SOUND ) /* bootleg? */
2383GAME( 197?, shuttlei, 0,        shuttlei, shuttlei, 0, ROT270, "Omori", "Shuttle Invader", GAME_NO_COCKTAIL )
2384GAMEL(197?, shuttlei, 0,        shuttlei, shuttlei, 0, ROT270, "Omori", "Shuttle Invader", GAME_NO_COCKTAIL, layout_shuttlei )
src/mame/drivers/othunder.c
r2724r2725
231231***************************************************************************/
232232
233233#include "driver.h"
234#include "deprecat.h"
235234#include "taitoipt.h"
236235#include "cpu/m68000/m68000.h"
237236#include "machine/eeprom.h"
r2724r2725
257256   last_irq_level = 0;
258257}
259258
260static void update_irq(void)
259static void update_irq(running_machine *machine)
261260{
262261   int curr_level;
263262
r2724r2725
270269
271270   if (curr_level != last_irq_level)
272271   {
273      cpunum_set_input_line(Machine, 0,curr_level,curr_level ? ASSERT_LINE : CLEAR_LINE);
272      cpunum_set_input_line(machine, 0,curr_level,curr_level ? ASSERT_LINE : CLEAR_LINE);
274273      last_irq_level = curr_level;
275274   }
276275}
r2724r2725
288287         break;
289288   }
290289
291   update_irq();
290   update_irq(machine);
292291}
293292
294293static INTERRUPT_GEN( vblank_interrupt )
295294{
296295   vblank_irq = 1;
297   update_irq();
296   update_irq(machine);
298297}
299298
300299static TIMER_CALLBACK( ad_interrupt )
301300{
302301   ad_irq = 1;
303   update_irq();
302   update_irq(machine);
304303}
305304
306305
r2724r2725
685684**************************************************************/
686685
687686/* handler called by the YM2610 emulator when the internal timers cause an IRQ */
688static void irqhandler(int irq)
687static void irqhandler(running_machine *machine, int irq)
689688{
690   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
689   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
691690}
692691
693692static const struct YM2610interface ym2610_interface =
src/mame/drivers/tail2nos.c
r2724r2725
1010***************************************************************************/
1111
1212#include "driver.h"
13#include "deprecat.h"
1413#include "video/konamiic.h"
1514#include "cpu/z80/z80.h"
1615#include "sound/2608intf.h"
r2724r2725
217216
218217
219218
220static void irqhandler(int irq)
219static void irqhandler(running_machine *machine, int irq)
221220{
222   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
221   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
223222}
224223
225224static const struct YM2608interface ym2608_interface =
226225{
227226   {
228      AY8910_LEGACY_OUTPUT,
227      AY8910_LEGACY_OUTPUT | AY8910_SINGLE_OUTPUT,
229228      AY8910_DEFAULT_LOADS,
230229      NULL,
231230      NULL,
src/mame/drivers/meritm.c
r2724r2725
216216
217217static void meritm_microtouch_tx_callback(UINT8 data)
218218{
219   pc16552d_rx_data(0, 0, data);
219   pc16552d_rx_data(Machine, 0, 0, data);
220220};
221221
222222/*************************************
r2724r2725
271271   v9938_interrupt(1);
272272}
273273
274static void meritm_vdp0_interrupt(int i)
274static void meritm_vdp0_interrupt(running_machine *machine, int i)
275275{
276276   if ( meritm_interrupt_vdp0_state != i )
277277   {
r2724r2725
286286   }
287287}
288288
289static void meritm_vdp1_interrupt(int i)
289static void meritm_vdp1_interrupt(running_machine *machine, int i)
290290{
291291   if ( meritm_interrupt_vdp1_state != i )
292292   {
r2724r2725
730730 *
731731 *************************************/
732732
733static void meritm_audio_pio_interrupt(int state)
733static void meritm_audio_pio_interrupt(running_machine *machine, int state)
734734{
735735   //logerror( "PIO(0) interrupt line: %d, V = %d, H = %d\n", state, video_screen_get_vpos(0), video_screen_get_hpos(0) );
736   cpunum_set_input_line(Machine, 0, 0, state);
736   cpunum_set_input_line(machine, 0, 0, state);
737737}
738738
739static void meritm_io_pio_interrupt(int state)
739static void meritm_io_pio_interrupt(running_machine *machine, int state)
740740{
741741   //logerror( "PIO(1) interrupt line: %d, V = %d, H = %d\n", state, video_screen_get_vpos(0), video_screen_get_hpos(0) );
742   cpunum_set_input_line(Machine, 0, 0, state);
742   cpunum_set_input_line(machine, 0, 0, state);
743743}
744744
745745
src/mame/drivers/slapshot.c
r2724r2725
132132***************************************************************************/
133133
134134#include "driver.h"
135#include "deprecat.h"
136135#include "cpu/m68000/m68000.h"
137136#include "video/taitoic.h"
138137#include "audio/taitosnd.h"
r2724r2725
533532**************************************************************/
534533
535534/* handler called by the YM2610 emulator when the internal timers cause an IRQ */
536static void irqhandler(int irq)
535static void irqhandler(running_machine *machine, int irq)
537536{
538   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
537   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
539538}
540539
541540static const struct YM2610interface ym2610_interface =
src/mame/drivers/ertictac.c
r2724r2725
2727
2828**********************************************************************/
2929#include "driver.h"
30#include "deprecat.h"
3130#include "cpu/arm/arm.h"
3231
3332static UINT32 *ertictac_mainram;
r2724r2725
8079
8180static READ32_HANDLER(IRQRQB_r)
8281{
83   return mame_rand(Machine)&IRQMSKB; /* hack  0x20 - controls,  0x02 - ?sound? */
82   return mame_rand(machine)&IRQMSKB; /* hack  0x20 - controls,  0x02 - ?sound? */
8483}
8584
8685static READ32_HANDLER(IRQMSKB_r)
src/mame/drivers/vsnes.c
r2724r2725
10221022   PORT_DIPNAME( 0x40, 0x00, DEF_STR( Unknown ) )
10231023   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )
10241024   PORT_DIPSETTING(   0x40, DEF_STR( On ) )
1025   PORT_BIT(     0x80, 0x00, IPT_DIPSWITCH_NAME ) PORT_NAME("Service Mode (Left Side)") PORT_TOGGLE PORT_CODE(KEYCODE_F2)
1025   PORT_DIPNAME( 0x80, 0x00, "Service Mode (Left Side)" ) PORT_TOGGLE PORT_CODE(KEYCODE_F2)
10261026   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )
10271027   PORT_DIPSETTING(   0x80, DEF_STR( On ) )
10281028
r2724r2725
10491049   PORT_DIPNAME( 0x40, 0x00, DEF_STR( Unknown ) )
10501050   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )
10511051   PORT_DIPSETTING(   0x40, DEF_STR( On ) )
1052   PORT_BIT(     0x80, 0x00, IPT_DIPSWITCH_NAME ) PORT_NAME("Service Mode (Right Side)") PORT_TOGGLE PORT_CODE(KEYCODE_F1)
1052   PORT_DIPNAME( 0x80, 0x00, "Service Mode (Right Side)" ) PORT_TOGGLE PORT_CODE(KEYCODE_F1)
10531053   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )
10541054   PORT_DIPSETTING(   0x80, DEF_STR( On ) )
10551055INPUT_PORTS_END
src/mame/drivers/cninja.c
r2724r2725
4141***************************************************************************/
4242
4343#include "driver.h"
44#include "deprecat.h"
4544#include "cninja.h"
4645#include "cpu/h6280/h6280.h"
4746#include "deco16ic.h"
r2724r2725
751750   cninja_irq_mask=0;
752751}
753752
754static void sound_irq(int state)
753static void sound_irq(running_machine *machine, int state)
755754{
756   cpunum_set_input_line(Machine, 1,1,state); /* IRQ 2 */
755   cpunum_set_input_line(machine, 1,1,state); /* IRQ 2 */
757756}
758757
759static void sound_irq2(int state)
758static void sound_irq2(running_machine *machine, int state)
760759{
761   cpunum_set_input_line(Machine, 1,0,state);
760   cpunum_set_input_line(machine, 1,0,state);
762761}
763762
764763static WRITE8_HANDLER( sound_bankswitch_w )
src/mame/drivers/psikyo4.c
r2724r2725
127127----------------------------------------------------------------*/
128128
129129#include "driver.h"
130#include "deprecat.h"
131130
132131#include "cpu/sh2/sh2.h"
133132#include "machine/eeprom.h"
r2724r2725
474473   AM_RANGE(0x06000000, 0x060fffff) AM_WRITE(SMH_RAM) AM_BASE(&ps4_ram)   // work RAM
475474ADDRESS_MAP_END
476475
477static void irqhandler(int linestate)
476static void irqhandler(running_machine *machine, int linestate)
478477{
479478   if (linestate)
480      cpunum_set_input_line(Machine, 0, 12, ASSERT_LINE);
479      cpunum_set_input_line(machine, 0, 12, ASSERT_LINE);
481480   else
482      cpunum_set_input_line(Machine, 0, 12, CLEAR_LINE);
481      cpunum_set_input_line(machine, 0, 12, CLEAR_LINE);
483482}
484483
485484static const struct YMF278B_interface ymf278b_interface =
src/mame/drivers/wardner.c
r2724r2725
124124
125125
126126#include "driver.h"
127#include "deprecat.h"
128127#include "cpu/tms32010/tms32010.h"
129128#include "twincobr.h"
130129#include "sound/3812intf.h"
r2724r2725
443442
444443
445444/* handler called by the 3812 emulator when the internal timers cause an IRQ */
446static void irqhandler(int linestate)
445static void irqhandler(running_machine *machine, int linestate)
447446{
448   cpunum_set_input_line(Machine, 1,0,linestate);
447   cpunum_set_input_line(machine, 1,0,linestate);
449448}
450449
451450static const struct YM3812interface ym3812_interface =
src/mame/drivers/rollrace.c
r2724r2725
151151   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
152152   PORT_DIPSETTING(    0x40, DEF_STR( On ) )
153153/*  PORT_DIPNAME( 0x80, 0x00, "Free Run" ) */
154   PORT_BIT(    0x80, 0x00, IPT_DIPSWITCH_NAME ) PORT_NAME("Invulnerability (Cheat)")
154   PORT_DIPNAME( 0x80, 0x00, "Invulnerability (Cheat)" )
155155   PORT_DIPSETTING(    0x00, DEF_STR( Off ) ) /* test mode, you are invulnerable */
156156   PORT_DIPSETTING(    0x80, DEF_STR( On ) )   /* to 'static' objects */
157157
src/mame/drivers/mirage.c
r2724r2725
3131*/
3232
3333#include "driver.h"
34#include "deprecat.h"
3534#include "decocrpt.h"
3635#include "decoprot.h"
3736#include "deco16ic.h"
r2724r2725
138137
139138static READ16_HANDLER( random_readers )
140139{
141   return mame_rand(Machine);
140   return mame_rand(machine);
142141}
143142
144143static READ16_HANDLER( mirage_input_r )
src/mame/drivers/missile.c
r2724r2725
239239******************************************************************************************/
240240
241241#include "driver.h"
242#include "deprecat.h"
243242#include "sound/pokey.h"
244243
245244
r2724r2725
328327
329328static CUSTOM_INPUT( get_vblank )
330329{
331   int v = scanline_to_v(video_screen_get_vpos(machine->primary_screen));
330   int v = scanline_to_v(video_screen_get_vpos(field->port->machine->primary_screen));
332331   return v < 24;
333332}
334333
r2724r2725
610609
611610   /* watchdog */
612611   else if (offset >= 0x4c00 && offset < 0x4d00)
613      watchdog_reset(Machine);
612      watchdog_reset(machine);
614613
615614   /* interrupt ack */
616615   else if (offset >= 0x4d00 && offset < 0x4e00)
src/mame/drivers/ddrible.c
r2724r2725
77***************************************************************************/
88
99#include "driver.h"
10#include "deprecat.h"
1110#include "cpu/m6809/m6809.h"
1211#include "sound/2203intf.h"
1312#include "sound/vlm5030.h"
r2724r2725
9190
9291static READ8_HANDLER( ddrible_vlm5030_busy_r )
9392{
94   return mame_rand(Machine); /* patch */
93   return mame_rand(machine); /* patch */
9594   /* FIXME: remove ? */
9695#if 0
9796   if (VLM5030_BSY()) return 1;
src/mame/drivers/sidearms.c
r2724r2725
3636***************************************************************************/
3737
3838#include "driver.h"
39#include "deprecat.h"
4039#include "sound/2203intf.h"
4140#include "sound/2151intf.h"
4241
r2724r2725
698697GFXDECODE_END
699698
700699/* handler called by the 2203 emulator when the internal timers cause an IRQ */
701static void irqhandler(int irq)
700static void irqhandler(running_machine *machine, int irq)
702701{
703   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
702   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
704703}
705704
706705static const struct YM2203interface ym2203_interface =
src/mame/drivers/taito_x.c
r2724r2725
311311***************************************************************************/
312312
313313#include "driver.h"
314#include "deprecat.h"
315314#include "taitoipt.h"
316315#include "audio/taitosnd.h"
317316#include "seta.h"
r2724r2725
971970/**************************************************************************/
972971
973972/* handler called by the YM2610 emulator when the internal timers cause an IRQ */
974static void irqhandler(int irq)
973static void irqhandler(running_machine *machine, int irq)
975974{
976   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
975   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
977976}
978977
979978static const struct YM2610interface ym2610_interface =
src/mame/drivers/tumblep.c
r2724r2725
4040***************************************************************************/
4141
4242#include "driver.h"
43#include "deprecat.h"
4443#include "cpu/h6280/h6280.h"
4544#include "decocrpt.h"
4645#include "sound/2151intf.h"
r2724r2725
289288
290289/***************************************************************************/
291290
292static void sound_irq(int state)
291static void sound_irq(running_machine *machine, int state)
293292{
294   cpunum_set_input_line(Machine, 1,1,state); /* IRQ 2 */
293   cpunum_set_input_line(machine, 1,1,state); /* IRQ 2 */
295294}
296295
297296static const struct YM2151interface ym2151_interface =
src/mame/drivers/dietgo.c
r2724r2725
55*/
66
77#include "driver.h"
8#include "deprecat.h"
98#include "cpu/h6280/h6280.h"
109#include "sound/2151intf.h"
1110#include "sound/okim6295.h"
r2724r2725
186185   GFXDECODE_ENTRY( REGION_GFX2, 0, spritelayout,      512, 16 )   /* Sprites (16x16) */
187186GFXDECODE_END
188187
189static void sound_irq(int state)
188static void sound_irq(running_machine *machine, int state)
190189{
191   cpunum_set_input_line(Machine, 1,1,state); /* IRQ 2 */
190   cpunum_set_input_line(machine, 1,1,state); /* IRQ 2 */
192191}
193192
194193static const struct YM2151interface ym2151_interface =
src/mame/drivers/taitosj.c
r2724r2725
336336      port_tag = "GEARP2";
337337
338338   /* gear MUST be 1, 2 or 3 */
339   if (input_port_read(machine, port_tag) & 0x01) kikstart_gears[player] = 0x02;
340   if (input_port_read(machine, port_tag) & 0x02) kikstart_gears[player] = 0x03;
341   if (input_port_read(machine, port_tag) & 0x04) kikstart_gears[player] = 0x01;
339   if (input_port_read(field->port->machine, port_tag) & 0x01) kikstart_gears[player] = 0x02;
340   if (input_port_read(field->port->machine, port_tag) & 0x02) kikstart_gears[player] = 0x03;
341   if (input_port_read(field->port->machine, port_tag) & 0x04) kikstart_gears[player] = 0x01;
342342
343343   return kikstart_gears[player];
344344}
src/mame/drivers/galivan.c
r2724r2725
2828***************************************************************************/
2929
3030#include "driver.h"
31#include "deprecat.h"
3231#include "sound/dac.h"
3332#include "sound/3812intf.h"
3433
r2724r2725
10231022
10241023static READ8_HANDLER( youmab_8a_r )
10251024{
1026   return mame_rand(Machine);
1025   return mame_rand(machine);
10271026}
10281027
10291028static WRITE8_HANDLER( youmab_81_w )
src/mame/drivers/blockout.c
r2724r2725
186186INPUT_PORTS_END
187187
188188/* handler called by the 2151 emulator when the internal timers cause an IRQ */
189static void blockout_irq_handler(int irq)
189static void blockout_irq_handler(running_machine *machine, int irq)
190190{
191   cpunum_set_input_line_and_vector(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE,0xff);
191   cpunum_set_input_line_and_vector(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE,0xff);
192192}
193193
194194static const struct YM2151interface ym2151_interface =
src/mame/drivers/tsamurai.c
r2724r2725
563563TS_IN2
564564TS_DSW1
565565
566   PORT_START_TAG("DSW1")
566   PORT_START_TAG("DSW2")
567567   PORT_DIPNAME( 0x01, 0x00, DEF_STR( Unknown ) )
568568   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
569569   PORT_DIPSETTING(    0x01, DEF_STR( On ) )
src/mame/drivers/splash.c
r2724r2725
143143   adpcm_data = data;
144144}
145145
146static void splash_msm5205_int(int data)
146static void splash_msm5205_int(running_machine *machine, int data)
147147{
148148   MSM5205_data_w(0,adpcm_data >> 4);
149149   adpcm_data = (adpcm_data << 4) & 0xf0;
r2724r2725
467467   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.80)
468468MACHINE_DRIVER_END
469469
470static void ym_irq(int state)
470static void ym_irq(running_machine *machine, int state)
471471{
472472   logerror("2203 IRQ: %d\n", state);
473473}
src/mame/drivers/f1gp.c
r2724r2725
2020***************************************************************************/
2121
2222#include "driver.h"
23#include "deprecat.h"
2423#include "video/konamiic.h"
2524#include "f1gp.h"
2625#include "sound/2610intf.h"
r2724r2725
549548
550549
551550
552static void irqhandler(int irq)
551static void irqhandler(running_machine *machine, int irq)
553552{
554   cpunum_set_input_line(Machine, 2,0,irq ? ASSERT_LINE : CLEAR_LINE);
553   cpunum_set_input_line(machine, 2,0,irq ? ASSERT_LINE : CLEAR_LINE);
555554}
556555
557556static const struct YM2610interface ym2610_interface =
src/mame/drivers/tecmosys.c
r2724r2725
171171*/
172172
173173#include "driver.h"
174#include "deprecat.h"
175174#include "machine/eeprom.h"
176175#include "cpu/m68000/m68k.h"
177176#include "sound/okim6295.h"
r2724r2725
585584*/
586585
587586
588static void sound_irq(int irq)
587static void sound_irq(running_machine *machine, int irq)
589588{
590589   /* IRQ */
591   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
590   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
592591}
593592
594593static const struct YMF262interface ymf262_interface =
src/mame/drivers/polyplay.c
r2724r2725
7979***************************************************************************/
8080
8181#include "driver.h"
82#include "deprecat.h"
8382#include "cpu/z80/z80.h"
8483#include "sound/samples.h"
8584
r2724r2725
253252
254253static READ8_HANDLER( polyplay_random_read )
255254{
256   return mame_rand(Machine) & 0xff;
255   return mame_rand(machine) & 0xff;
257256}
258257
259258/* graphic structures */
src/mame/drivers/exzisus.c
r2724r2725
2828****************************************************************************/
2929
3030#include "driver.h"
31#include "deprecat.h"
3231#include "taitoipt.h"
3332#include "audio/taitosnd.h"
3433#include "sound/2151intf.h"
r2724r2725
311310
312311
313312
314static void irqhandler(int irq)
313static void irqhandler(running_machine *machine, int irq)
315314{
316   cpunum_set_input_line(Machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
315   cpunum_set_input_line(machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
317316}
318317
319318static const struct YM2151interface ym2151_interface =
src/mame/drivers/exidy440.c
r2724r2725
264264{
265265   /* if we got a coin, set the IRQ on the main CPU */
266266   if (newval == 0)
267      cpunum_set_input_line(machine, 0, 0, ASSERT_LINE);
267      cpunum_set_input_line(field->port->machine, 0, 0, ASSERT_LINE);
268268}
269269
270270
r2724r2725
290290static CUSTOM_INPUT( hitnmiss_button1_r )
291291{
292292   /* button 1 shows up in two bits */
293   UINT32 button1 = input_port_read(machine, "HITNMISS_BUTTON1");
293   UINT32 button1 = input_port_read(field->port->machine, "HITNMISS_BUTTON1");
294294   return (button1 << 1) | button1;
295295}
296296
src/mame/drivers/topshoot.c
r2724r2725
134134*/
135135
136136#include "driver.h"
137#include "deprecat.h"
138137#include "genesis.h"
139138
140139
r2724r2725
297296
298297static READ16_HANDLER( vdp_fake_r )
299298{
300   return mame_rand(Machine);
299   return mame_rand(machine);
301300}
302301
303302static DRIVER_INIT(topshoot)
src/mame/drivers/dassault.c
r2724r2725
119119***************************************************************************/
120120
121121#include "driver.h"
122#include "deprecat.h"
123122#include "cpu/h6280/h6280.h"
124123#include "deco16ic.h"
125124#include "sound/2203intf.h"
r2724r2725
532531
533532/**********************************************************************************/
534533
535static void sound_irq(int state)
534static void sound_irq(running_machine *machine, int state)
536535{
537   cpunum_set_input_line(Machine, 2,1,state);
536   cpunum_set_input_line(machine, 2,1,state);
538537}
539538
540539static WRITE8_HANDLER( sound_bankswitch_w )
src/mame/drivers/gtipoker.c
r2724r2725
22/* Nothing else is known about this set / game */
33
44#include "driver.h"
5#include "deprecat.h"
65
76static VIDEO_START(gtipoker)
87{
r2724r2725
1615
1716static READ8_HANDLER( gtipoker_unk_r )
1817{
19   return mame_rand(Machine);
18   return mame_rand(machine);
2019}
2120
2221static ADDRESS_MAP_START( gtipoker_memmap, ADDRESS_SPACE_PROGRAM, 8 )
src/mame/drivers/tatsumi.c
r2724r2725
138138***************************************************************************/
139139
140140#include "driver.h"
141#include "deprecat.h"
142141#include "tatsumi.h"
143142#include "sound/2151intf.h"
144143#include "sound/okim6295.h"
r2724r2725
806805
807806/******************************************************************************/
808807
809static void sound_irq(int state)
808static void sound_irq(running_machine *machine, int state)
810809{
811   cpunum_set_input_line(Machine, 2, INPUT_LINE_IRQ0, state);
810   cpunum_set_input_line(machine, 2, INPUT_LINE_IRQ0, state);
812811}
813812
814813static const struct YM2151interface ym2151_interface =
src/mame/drivers/supbtime.c
r2724r2725
2121***************************************************************************/
2222
2323#include "driver.h"
24#include "deprecat.h"
2524#include "cpu/h6280/h6280.h"
2625#include "sound/2151intf.h"
2726#include "sound/okim6295.h"
r2724r2725
361360
362361/******************************************************************************/
363362
364static void sound_irq(int state)
363static void sound_irq(running_machine *machine, int state)
365364{
366   cpunum_set_input_line(Machine, 1,1,state); /* IRQ 2 */
365   cpunum_set_input_line(machine, 1,1,state); /* IRQ 2 */
367366}
368367
369368static const struct YM2151interface ym2151_interface =
src/mame/drivers/blmbycar.c
r2724r2725
2424***************************************************************************/
2525
2626#include "driver.h"
27#include "deprecat.h"
2827#include "sound/okim6295.h"
2928
3029/* Variables defined in video: */
r2724r2725
9493static READ16_HANDLER( blmbycar_pot_wheel_r )
9594{
9695   return   ((pot_wheel & 0x80) ? 0x04 : 0) |
97         (mame_rand(Machine) & 0x08);
96         (mame_rand(machine) & 0x08);
9897}
9998
10099
src/mame/drivers/toratora.c
r2724r2725
1818***************************************************************************/
1919
2020#include "driver.h"
21#include "deprecat.h"
2221#include "machine/6821pia.h"
2322#include "sound/sn76477.h"
2423
r2724r2725
117116 *
118117 *************************************/
119118
120static void main_cpu_irq(int state)
119static void main_cpu_irq(running_machine *machine, int state)
121120{
122121   int combined_state = pia_get_irq_a(0) | pia_get_irq_b(0);
123122
124123logerror("GEN IRQ: %x\n", combined_state);
125   cpunum_set_input_line(Machine, 0, 0, combined_state ? ASSERT_LINE : CLEAR_LINE);
124   cpunum_set_input_line(machine, 0, 0, combined_state ? ASSERT_LINE : CLEAR_LINE);
126125}
127126
128127
src/mame/drivers/meadows.c
r2724r2725
207207
208208static INPUT_CHANGED( coin_inserted )
209209{
210   cpunum_set_input_line_and_vector(machine, 0, 0, (newval ? ASSERT_LINE : CLEAR_LINE), 0x82);
210   cpunum_set_input_line_and_vector(field->port->machine, 0, 0, (newval ? ASSERT_LINE : CLEAR_LINE), 0x82);
211211}
212212
213213
src/mame/drivers/srmp2.c
r2724r2725
235235}
236236
237237
238static void srmp2_adpcm_int(int num)
238static void srmp2_adpcm_int(running_machine *machine, int num)
239239{
240240   UINT8 *ROM = memory_region(REGION_SOUND1);
241241
src/mame/drivers/r2dtank.c
r2724r2725
7272 *
7373 *************************************/
7474
75static void main_cpu_irq(int state)
75static void main_cpu_irq(running_machine *machine, int state)
7676{
7777   int combined_state = pia_get_irq_a(0) | pia_get_irq_b(0) |
7878                   pia_get_irq_a(1) | pia_get_irq_b(1);
7979
80   cpunum_set_input_line(Machine, 0, M6809_IRQ_LINE,  combined_state ? ASSERT_LINE : CLEAR_LINE);
80   cpunum_set_input_line(machine, 0, M6809_IRQ_LINE,  combined_state ? ASSERT_LINE : CLEAR_LINE);
8181}
8282
8383
src/mame/drivers/snk68.c
r2724r2725
3434***************************************************************************/
3535
3636#include "driver.h"
37#include "deprecat.h"
3837#include "cpu/z80/z80.h"
3938#include "sound/3812intf.h"
4039#include "sound/upd7759.h"
r2724r2725
678677
679678/******************************************************************************/
680679
681static void irqhandler(int irq)
680static void irqhandler(running_machine *machine, int irq)
682681{
683   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
682   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
684683}
685684
686685static const struct YM3812interface ym3812_interface =
src/mame/drivers/madalien.c
r2724r2725
2222static INPUT_CHANGED( coin_inserted )
2323{
2424   /* coin insertion causes an NMI */
25   cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, newval ? CLEAR_LINE : ASSERT_LINE);
25   cpunum_set_input_line(field->port->machine, 0, INPUT_LINE_NMI, newval ? CLEAR_LINE : ASSERT_LINE);
2626}
2727
2828
src/mame/drivers/konamigv.c
r2724r2725
287287   }
288288}
289289
290static void scsi_irq(void)
290static void scsi_irq(running_machine *machine)
291291{
292   psx_irq_set(0x400);
292   psx_irq_set(machine, 0x400);
293293}
294294
295295static const SCSIConfigTable dev_table =
src/mame/drivers/firetrap.c
r2724r2725
220220
221221static int msm5205next;
222222
223static void firetrap_adpcm_int (int data)
223static void firetrap_adpcm_int (running_machine *machine, int data)
224224{
225225   static int toggle=0;
226226
r2724r2725
229229
230230   toggle ^= 1;
231231   if (firetrap_irq_enable && toggle)
232      cpunum_set_input_line (Machine, 1, M6502_IRQ_LINE, HOLD_LINE);
232      cpunum_set_input_line (machine, 1, M6502_IRQ_LINE, HOLD_LINE);
233233}
234234
235235static WRITE8_HANDLER( firetrap_adpcm_data_w )
src/mame/drivers/crgolf.c
r2724r2725
169169 *
170170 *************************************/
171171
172static void vck_callback(int data)
172static void vck_callback(running_machine *machine, int data)
173173{
174174   /* only play back if we have data remaining */
175175   if (sample_count != 0xff)
src/mame/drivers/mastboy.c
r2724r2725
434434*/
435435
436436#include "driver.h"
437#include "deprecat.h"
438437#include "sound/saa1099.h"
439438#include "sound/msm5205.h"
440439
r2724r2725
634633   mastboy_m5205_next = data;
635634}
636635
637static void mastboy_adpcm_int(int data)
636static void mastboy_adpcm_int(running_machine *machine, int data)
638637{
639638   MSM5205_data_w (0,mastboy_m5205_next);
640639   mastboy_m5205_next>>=4;
641640
642641   mastboy_m5205_part ^= 1;
643642   if(!mastboy_m5205_part)
644         cpunum_set_input_line(Machine, 0, INPUT_LINE_NMI, PULSE_LINE);
643      cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, PULSE_LINE);
645644}
646645
647646
src/mame/drivers/thedeep.c
r2724r2725
321321
322322***************************************************************************/
323323
324static void irqhandler(int irq)
324static void irqhandler(running_machine *machine, int irq)
325325{
326   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
326   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
327327}
328328
329329static const struct YM2203interface thedeep_ym2203_intf =
src/mame/drivers/oneshot.c
r2724r2725
3030*/
3131
3232#include "driver.h"
33#include "deprecat.h"
3433#include "sound/okim6295.h"
3534#include "sound/3812intf.h"
3635
r2724r2725
357356   GFXDECODE_ENTRY( REGION_GFX1, 0, oneshot8x8_layout,     0x00, 4  ) /* sprites */
358357GFXDECODE_END
359358
360static void irq_handler(int irq)
359static void irq_handler(running_machine *machine, int irq)
361360{
362   cpunum_set_input_line(Machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
361   cpunum_set_input_line(machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
363362}
364363
365364static const struct YM3812interface ym3812_interface =
src/mame/drivers/topspeed.c
r2724r2725
377377   switch (offset)
378378   {
379379      case 0x0:
380         return (mame_rand(Machine) &0xff);   /* motor status ?? */
380         return (mame_rand(machine) &0xff);   /* motor status ?? */
381381
382382      case 0x101:
383383         return 0x55;   /* motor cpu status ? */
r2724r2725
416416
417417static int adpcm_pos;
418418
419static void topspeed_msm5205_vck(int chip)
419static void topspeed_msm5205_vck(running_machine *machine, int chip)
420420{
421421   static int adpcm_data = -1;
422422
r2724r2725
657657
658658/* handler called by the YM2151 emulator when the internal timers cause an IRQ */
659659
660static void irq_handler(int irq)   /* assumes Z80 sandwiched between 68Ks */
660static void irq_handler(running_machine *machine, int irq)   /* assumes Z80 sandwiched between 68Ks */
661661{
662   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
662   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
663663}
664664
665665static const struct YM2151interface ym2151_interface =
src/mame/drivers/zr107.c
r2724r2725
659659
660660/*****************************************************************************/
661661
662static void sound_irq_callback(int irq)
662static void sound_irq_callback(running_machine *machine, int irq)
663663{
664664   if (irq == 0)
665      cpunum_set_input_line(Machine, 1, INPUT_LINE_IRQ1, PULSE_LINE);
665      cpunum_set_input_line(machine, 1, INPUT_LINE_IRQ1, PULSE_LINE);
666666   else
667      cpunum_set_input_line(Machine, 1, INPUT_LINE_IRQ2, PULSE_LINE);
667      cpunum_set_input_line(machine, 1, INPUT_LINE_IRQ2, PULSE_LINE);
668668}
669669
670670static DRIVER_INIT(zr107)
src/mame/drivers/amspdwy.c
r2724r2725
1414***************************************************************************/
1515
1616#include "driver.h"
17#include "deprecat.h"
1817#include "sound/2151intf.h"
1918
2019/* Variables & functions defined in video: */
r2724r2725
240239***************************************************************************/
241240
242241
243static void irq_handler(int irq)
242static void irq_handler(running_machine *machine, int irq)
244243{
245   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
244   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
246245}
247246
248247static const struct YM2151interface amspdwy_ym2151_interface =
src/mame/drivers/fantland.c
r2724r2725
4444***************************************************************************************/
4545
4646#include "driver.h"
47#include "deprecat.h"
4847#include "sound/2151intf.h"
4948#include "sound/3812intf.h"
5049#include "sound/dac.h"
r2724r2725
335334   }
336335}
337336
338static void borntofi_adpcm_int(int voice)
337static void borntofi_adpcm_int(running_machine *machine, int voice)
339338{
340339   UINT8 *rom;
341340   size_t   len;
r2724r2725
696695static CUSTOM_INPUT( wheelrun_wheel_r )
697696{
698697   int player = (FPTR)param;
699   int delta = input_port_read_indexed(machine, 4 + player);
698   int delta = input_port_read_indexed(field->port->machine, 4 + player);
700699   delta = (delta & 0x7f) - (delta & 0x80) + 4;
701700
702701   if      (delta > 7)   delta = 7;
r2724r2725
849848MACHINE_DRIVER_END
850849
851850
852static void galaxygn_sound_irq(int line)
851static void galaxygn_sound_irq(running_machine *machine, int line)
853852{
854   cpunum_set_input_line_and_vector(Machine, 1, 0, line ? ASSERT_LINE : CLEAR_LINE, 0x80/4);
853   cpunum_set_input_line_and_vector(machine, 1, 0, line ? ASSERT_LINE : CLEAR_LINE, 0x80/4);
855854}
856855
857856static const struct YM2151interface galaxygn_ym2151_interface =
r2724r2725
949948
950949
951950
952static void wheelrun_ym3526_irqhandler(int state)
951static void wheelrun_ym3526_irqhandler(running_machine *machine, int state)
953952{
954   cpunum_set_input_line(Machine, 1, INPUT_LINE_IRQ0, state);
953   cpunum_set_input_line(machine, 1, INPUT_LINE_IRQ0, state);
955954}
956955
957956static const struct YM3526interface wheelrun_ym3526_interface =
src/mame/drivers/ksys573.c
r2724r2725
518518      atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO | ATAPI_INTREASON_COMMAND;
519519   }
520520
521   psx_irq_set(0x400);
521   psx_irq_set(machine, 0x400);
522522
523523   verboselog( 2, "atapi_xfer_end: %d %d\n", atapi_xferlen, atapi_xfermod );
524524}
r2724r2725
568568         atapi_regs[ATAPI_REG_COUNTLOW] = atapi_xferlen & 0xff;
569569         atapi_regs[ATAPI_REG_COUNTHIGH] = (atapi_xferlen>>8)&0xff;
570570
571         psx_irq_set(0x400);
571         psx_irq_set(machine, 0x400);
572572      }
573573
574574      if( atapi_data_ptr < atapi_data_len )
r2724r2725
585585            {
586586               atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
587587               atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO;
588               psx_irq_set(0x400);
588               psx_irq_set(machine, 0x400);
589589            }
590590         }
591591      }
r2724r2725
667667            SCSIWriteData( inserted_cdrom, atapi_data, atapi_cdata_wait );
668668
669669            // assert IRQ
670            psx_irq_set(0x400);
670            psx_irq_set(machine, 0x400);
671671
672672            // not sure here, but clear DRQ at least?
673673            atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
r2724r2725
740740            }
741741
742742            // assert IRQ
743            psx_irq_set(0x400);
743            psx_irq_set(machine, 0x400);
744744         }
745745         else
746746         {
r2724r2725
857857               atapi_regs[ATAPI_REG_COUNTLOW] = 0;
858858               atapi_regs[ATAPI_REG_COUNTHIGH] = 2;
859859
860               psx_irq_set(0x400);
860               psx_irq_set(machine, 0x400);
861861               break;
862862
863863            case 0xef:   // SET FEATURES
r2724r2725
866866               atapi_data_ptr = 0;
867867               atapi_data_len = 0;
868868
869               psx_irq_set(0x400);
869               psx_irq_set(machine, 0x400);
870870               break;
871871
872872            default:
r2724r2725
12211221   if( ( m_p_n_root_mode[ n_counter ] & RC_IRQOVERFLOW ) != 0 ||
12221222      ( m_p_n_root_mode[ n_counter ] & RC_IRQTARGET ) != 0 )
12231223   {
1224      psx_irq_set( 0x10 << n_counter );
1224      psx_irq_set( machine, 0x10 << n_counter );
12251225   }
12261226}
12271227
r2724r2725
15241524   if( chiptype[ 0 ] != 0 )
15251525   {
15261526      /* security cart */
1527      psx_sio_input( 1, PSX_SIO_IN_DSR, PSX_SIO_IN_DSR );
1527      psx_sio_input( machine, 1, PSX_SIO_IN_DSR, PSX_SIO_IN_DSR );
15281528   }
15291529
15301530   flash_bank = -1;
r2724r2725
18801880
18811881static CUSTOM_INPUT( gn845pwbb_read )
18821882{
1883   return input_port_read(machine,  "STAGE" ) & stage_mask;
1883   return input_port_read(field->port->machine,  "STAGE" ) & stage_mask;
18841884}
18851885
18861886static void gn845pwbb_output_callback( int offset, int data )
src/mame/drivers/midas.c
r2724r2725
426426INPUT_PORTS_END
427427
428428
429static void livequiz_irqhandler (int state)
429static void livequiz_irqhandler(running_machine *machine, int state)
430430{
431431   logerror("YMZ280 is generating an interrupt. State=%08x\n",state);
432432}
src/mame/drivers/mcr68.c
r2724r2725
561561   PORT_DIPSETTING(      0x0040, "45 sec" )
562562   PORT_DIPSETTING(      0x0060, "60 sec" )
563563   PORT_DIPSETTING(      0x0020, "90 sec" )
564   PORT_BIT( 0x0080,    0x0080, IPT_DIPSWITCH_NAME ) PORT_NAME("Rack Advance (Cheat)") PORT_CODE(KEYCODE_F1)
564   PORT_DIPNAME( 0x0080, 0x0080, "Rack Advance (Cheat)" ) PORT_CODE(KEYCODE_F1)
565565   PORT_DIPSETTING(      0x0080, DEF_STR( Off ) )
566566   PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
567567   PORT_BIT( 0xff00, IP_ACTIVE_LOW, IPT_UNUSED )
r2724r2725
626626   PORT_DIPNAME( 0x0040, 0x0040, DEF_STR( Demo_Sounds ) )
627627   PORT_DIPSETTING(      0x0000, DEF_STR( Off ) )
628628   PORT_DIPSETTING(      0x0040, DEF_STR( On ) )
629   PORT_BIT( 0x0080,    0x0080, IPT_DIPSWITCH_NAME ) PORT_NAME("Rack Advance (Cheat)") PORT_CODE(KEYCODE_F1)
629   PORT_DIPNAME( 0x0080, 0x0080, "Rack Advance (Cheat)" ) PORT_CODE(KEYCODE_F1)
630630   PORT_DIPSETTING(      0x0080, DEF_STR( Off ) )
631631   PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
632632   PORT_BIT( 0xff00, IP_ACTIVE_LOW, IPT_UNUSED )
src/mame/drivers/spcforce.c
r2724r2725
3232***************************************************************************/
3333
3434#include "driver.h"
35#include "deprecat.h"
3635#include "cpu/i8085/i8085.h"
3736#include "cpu/i8039/i8039.h"
3837#include "sound/sn76496.h"
r2724r2725
6968static READ8_HANDLER( spcforce_t0_r )
7069{
7170   /* SN76496 status according to Al - not supported by MAME?? */
72   return mame_rand(Machine) & 1;
71   return mame_rand(machine) & 1;
7372}
7473
7574
src/mame/drivers/nmg5.c
r2724r2725
220220*/
221221
222222#include "driver.h"
223#include "deprecat.h"
224223#include "sound/okim6295.h"
225224#include "sound/3812intf.h"
226225
r2724r2725
957956GFXDECODE_END
958957
959958
960static void soundirq(int state)
959static void soundirq(running_machine *machine, int state)
961960{
962   cpunum_set_input_line(Machine, 1, 0, state);
961   cpunum_set_input_line(machine, 1, 0, state);
963962}
964963
965964static const struct YM3812interface ym3812_intf =
src/mame/drivers/lethal.c
r2724r2725
165165***************************************************************************/
166166
167167#include "driver.h"
168#include "deprecat.h"
169168#include "video/konamiic.h"
170169#include "cpu/m6809/m6809.h"
171170#include "cpu/hd6309/hd6309.h"
r2724r2725
270269   return 0xf;
271270}
272271
273static void sound_nmi(void)
272static void sound_nmi(running_machine *machine)
274273{
275   cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, PULSE_LINE);
274   cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, PULSE_LINE);
276275}
277276
278277static WRITE8_HANDLER( le_bankswitch_w )
src/mame/drivers/videopin.c
r2724r2725
1111*************************************************************************/
1212
1313#include "driver.h"
14#include "deprecat.h"
1514#include "videopin.h"
1615#include "videopin.lh"
1716#include "sound/discrete.h"
r2724r2725
3736         time_released = timer_get_time();
3837
3938         if (!mask)
40            cpunum_set_input_line(Machine, 0, INPUT_LINE_NMI, ASSERT_LINE);
39            cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, ASSERT_LINE);
4140      }
4241      else
4342         time_pushed = timer_get_time();
src/mame/drivers/exprraid.c
r2724r2725
6161***************************************************************************/
6262
6363#include "driver.h"
64#include "deprecat.h"
6564#include "cpu/m6809/m6809.h"
6665#include "sound/2203intf.h"
6766#include "sound/3812intf.h"
r2724r2725
274273
275274
276275/* handler called by the 3812 emulator when the internal timers cause an IRQ */
277static void irqhandler(int linestate)
276static void irqhandler(running_machine *machine, int linestate)
278277{
279   cpunum_set_input_line_and_vector(Machine, 1,0,linestate,0xff);
278   cpunum_set_input_line_and_vector(machine, 1,0,linestate,0xff);
280279}
281280
282281static const struct YM3526interface ym3526_interface =
src/mame/drivers/tecmo16.c
r2724r2725
2424******************************************************************************/
2525
2626#include "driver.h"
27#include "deprecat.h"
2827#include "cpu/m68000/m68000.h"
2928#include "cpu/z80/z80.h"
3029#include "sound/2151intf.h"
r2724r2725
426425
427426/******************************************************************************/
428427
429static void irqhandler(int irq)
428static void irqhandler(running_machine *machine, int irq)
430429{
431   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
430   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
432431}
433432
434433static const struct YM2151interface ym2151_interface =
src/mame/drivers/2mindril.c
r2724r2725
5151*/
5252
5353#include "driver.h"
54#include "deprecat.h"
5554#include "sound/2610intf.h"
5655
5756static UINT16 *unkram;
r2724r2725
180179   cpunum_set_input_line(machine, 0, 4, HOLD_LINE);
181180}
182181
183static void irqhandler(int irq)
182static void irqhandler(running_machine *machine, int irq)
184183{
185   cpunum_set_input_line(Machine, 0,5,irq ? ASSERT_LINE : CLEAR_LINE);
184   cpunum_set_input_line(machine, 0,5,irq ? ASSERT_LINE : CLEAR_LINE);
186185}
187186
188187static const struct YM2610interface ym2610_interface =
src/mame/drivers/tumbleb.c
r2724r2725
262262***************************************************************************/
263263
264264#include "driver.h"
265#include "deprecat.h"
266265#include "cpu/h6280/h6280.h"
267266#include "decocrpt.h"
268267#include "sound/2151intf.h"
r2724r2725
719718
720719static READ16_HANDLER( semibase_unknown_r )
721720{
722   return mame_rand(Machine);
721   return mame_rand(machine);
723722}
724723static ADDRESS_MAP_START( htchctch_readmem, ADDRESS_SPACE_PROGRAM, 16 )
725724   AM_RANGE(0x000000, 0x0fffff) AM_READ(SMH_ROM)
r2724r2725
21542153
21552154
21562155
2157static void semicom_irqhandler(int irq)
2156static void semicom_irqhandler(running_machine *machine, int irq)
21582157{
2159   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
2158   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
21602159}
21612160
21622161
src/mame/drivers/kchamp.c
r2724r2725
6262
6363***************************************************************************/
6464#include "driver.h"
65#include "deprecat.h"
6665#include "cpu/z80/z80.h"
6766#include "sound/ay8910.h"
6867#include "sound/dac.h"
r2724r2725
403402      cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, PULSE_LINE);
404403}
405404
406static void msmint( int data ) {
405static void msmint( running_machine *machine, int data ) {
407406
408407   static int counter = 0;
409408
r2724r2725
416415
417416   if ( !( counter ^= 1 ) ) {
418417      if ( sound_nmi_enable ) {
419         cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, PULSE_LINE );
418         cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, PULSE_LINE );
420419      }
421420   }
422421}
src/mame/drivers/ultratnk.c
r2724r2725
2828
2929static CUSTOM_INPUT( get_joystick )
3030{
31   UINT8 joy = input_port_read(machine, param) & 3;
31   UINT8 joy = input_port_read(field->port->machine, param) & 3;
3232
3333   if (joy == 1)
3434   {
src/mame/drivers/taito_z.c
r2724r2725
27672767**************************************************************/
27682768
27692769/* handler called by the YM2610 emulator when the internal timers cause an IRQ */
2770static void irqhandler(int irq)   // assumes Z80 sandwiched between 68Ks
2770static void irqhandler(running_machine *machine, int irq)   // assumes Z80 sandwiched between 68Ks
27712771{
2772   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
2772   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
27732773}
27742774
27752775/* handler called by the YM2610 emulator when the internal timers cause an IRQ */
2776static void irqhandlerb(int irq)
2776static void irqhandlerb(running_machine *machine, int irq)
27772777{
27782778   // DG: this is probably specific to Z80 and wrong?
2779//  cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
2779//  cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
27802780}
27812781
27822782static const struct YM2610interface ym2610_interface =
src/mame/drivers/phoenix.c
r2724r2725
10221022static DRIVER_INIT( condor )
10231023{
10241024   /* additional inputs for coinage */
1025   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x5000, 0x5000, 0, 0, port_tag_to_handler8("DSW1") );
1025   memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x5000, 0x5000, 0, 0, input_port_read_handler8(machine->portconfig, "DSW1") );
10261026}
10271027
10281028static DRIVER_INIT( survival )
src/mame/drivers/lastfght.c
r2724r2725
306306{
307307   // high byte:
308308   // mask 0x1c: from sound?
309   return (mame_rand(Machine) & 0x1c00) | input_port_read_indexed(machine, 0);
309   return (mame_rand(machine) & 0x1c00) | input_port_read_indexed(machine, 0);
310310}
311311
312312static READ16_HANDLER( lastfght_c00004_r )
src/mame/drivers/superqix.c
r2724r2725
485485{
486486//  logerror("%04x: ay_port_a_r\n",activecpu_get_pc());
487487    /* bits 76------  MCU status bits */
488   return (mame_rand(Machine)&0xc0)|input_port_read_indexed(machine, 3);
488   return (mame_rand(machine)&0xc0)|input_port_read_indexed(machine, 3);
489489}
490490
491491
src/mame/drivers/lockon.c
r2724r2725
1010***************************************************************************/
1111
1212#include "driver.h"
13#include "deprecat.h"
1413#include "sound/2203intf.h"
1514#include "sound/flt_vol.h"
1615#include "lockon.h"
r2724r2725
441440   flt_volume_set_volume(5, rgain);
442441}
443442
444static void ym2203_irq(int irq)
443static void ym2203_irq(running_machine *machine, int irq)
445444{
446   cpunum_set_input_line(Machine, SOUND_CPU, 0, irq ? ASSERT_LINE : CLEAR_LINE );
445   cpunum_set_input_line(machine, SOUND_CPU, 0, irq ? ASSERT_LINE : CLEAR_LINE );
447446}
448447
449448static WRITE8_HANDLER( ym2203_out_b )
src/mame/drivers/mappy.c
r2724r2725
12601260   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Demo_Sounds ) )
12611261   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
12621262   PORT_DIPSETTING(    0x20, DEF_STR( On ) )
1263   PORT_BIT(    0x40, 0x40, IPT_DIPSWITCH_NAME ) PORT_NAME("Rack Test (Cheat)") PORT_CODE(KEYCODE_F1)
1263   PORT_DIPNAME( 0x40, 0x40, "Rack Test (Cheat)" ) PORT_CODE(KEYCODE_F1)
12641264   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
12651265   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
12661266   PORT_DIPNAME( 0x80, 0x80, "Freeze" )
src/mame/drivers/rastan.c
r2724r2725
159159***************************************************************************/
160160
161161#include "driver.h"
162#include "deprecat.h"
163162#include "taitoipt.h"
164163#include "video/taitoic.h"
165164#include "audio/taitosnd.h"
r2724r2725
187186
188187static int adpcm_pos;
189188
190static void rastan_msm5205_vck(int chip)
189static void rastan_msm5205_vck(running_machine *machine, int chip)
191190{
192191   static int adpcm_data = -1;
193192
r2724r2725
359358
360359
361360/* handler called by the YM2151 emulator when the internal timers cause an IRQ */
362static void irqhandler(int irq)
361static void irqhandler(running_machine *machine, int irq)
363362{
364   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
363   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
365364}
366365
367366static const struct YM2151interface ym2151_interface =
src/mame/drivers/pntnpuzl.c
r2724r2725
121121*/
122122
123123#include "driver.h"
124#include "deprecat.h"
125124#include "machine/eeprom.h"
126125
127126
r2724r2725
275274#ifdef UNUSED_FUNCTION
276275READ16_HANDLER ( pntnpuzl_random_r )
277276{
278   return mame_rand(Machine);
277   return mame_rand(machine);
279278}
280279#endif
281280
src/mame/drivers/gijoe.c
r2724r2725
3737***************************************************************************/
3838
3939#include "driver.h"
40#include "deprecat.h"
4140#include "video/konamiic.h"
4241#include "cpu/z80/z80.h"
4342#include "machine/eeprom.h"
r2724r2725
199198   return soundlatch2_r(machine,0);
200199}
201200
202static void sound_nmi(void)
201static void sound_nmi(running_machine *machine)
203202{
204   cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, PULSE_LINE);
203   cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, PULSE_LINE);
205204}
206205
207206static MACHINE_START( gijoe )
src/mame/drivers/tigeroad.c
r2724r2725
2020***************************************************************************/
2121
2222#include "driver.h"
23#include "deprecat.h"
2423#include "cpu/z80/z80.h"
2524#include "sound/2203intf.h"
2625#include "sound/msm5205.h"
r2724r2725
527526
528527
529528/* handler called by the 2203 emulator when the internal timers cause an IRQ */
530static void irqhandler(int irq)
529static void irqhandler(running_machine *machine, int irq)
531530{
532   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
531   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
533532}
534533
535534static const struct YM2203interface ym2203_interface =
src/mame/drivers/looping.c
r2724r2725
5252*/
5353
5454#include "driver.h"
55#include "deprecat.h"
5655#include "sound/ay8910.h"
5756#include "sound/dac.h"
5857#include "sound/5220intf.h"
r2724r2725
330329}
331330
332331
333static void looping_spcint(int state)
332static void looping_spcint(running_machine *machine, int state)
334333{
335   cpunum_set_input_line_and_vector(Machine, 1, 0, state, 6);
334   cpunum_set_input_line_and_vector(machine, 1, 0, state, 6);
336335}
337336
338337
src/mame/drivers/segas32.c
r2724r2725
292292***************************************************************************/
293293
294294#include "driver.h"
295#include "deprecat.h"
296295#include "rendlay.h"
297296#include "segas32.h"
298297#include "machine/eeprom.h"
r2724r2725
375374 *
376375 *************************************/
377376
378static void signal_v60_irq(int data);
377static void signal_v60_irq(running_machine *machine, int data);
379378static TIMER_CALLBACK( signal_v60_irq_callback );
380static void signal_sound_irq(int which);
379static void signal_sound_irq(running_machine *machine, int which);
381380
382381
383382
r2724r2725
408407 *
409408 *************************************/
410409
411static void update_irq_state(void)
410static void update_irq_state(running_machine *machine)
412411{
413412   UINT8 effirq = v60_irq_control[7] & ~v60_irq_control[6] & 0x1f;
414413   int vector;
r2724r2725
418417   for (vector = 0; vector < 5; vector++)
419418      if (effirq & (1 << vector))
420419      {
421         cpunum_set_input_line_and_vector(Machine, 0, 0, ASSERT_LINE, vector);
420         cpunum_set_input_line_and_vector(machine, 0, 0, ASSERT_LINE, vector);
422421         break;
423422      }
424423
425424   /* if we didn't find any, clear the interrupt line */
426425   if (vector == 5)
427      cpunum_set_input_line(Machine, 0, 0, CLEAR_LINE);
426      cpunum_set_input_line(machine, 0, 0, CLEAR_LINE);
428427}
429428
430429
431static void signal_v60_irq(int which)
430static void signal_v60_irq(running_machine *machine, int which)
432431{
433432   int i;
434433
r2724r2725
436435   for (i = 0; i < 5; i++)
437436      if (v60_irq_control[i] == which)
438437         v60_irq_control[7] |= 1 << i;
439   update_irq_state();
438   update_irq_state(machine);
440439}
441440
442441
443442static TIMER_CALLBACK( signal_v60_irq_callback )
444443{
445   signal_v60_irq(param);
444   signal_v60_irq(machine, param);
446445}
447446
448447
449static void int_control_w(int offset, UINT8 data)
448static void int_control_w(running_machine *machine, int offset, UINT8 data)
450449{
451450   int duration;
452451
r2724r2725
467466
468467      case 6:         /* mask */
469468         v60_irq_control[offset] = data;
470         update_irq_state();
469         update_irq_state(machine);
471470         break;
472471
473472      case 7:         /* acknowledge */
474473         v60_irq_control[offset] &= data;
475         update_irq_state();
474         update_irq_state(machine);
476475         break;
477476
478477      case 8:
r2724r2725
501500      case 13:
502501      case 14:
503502      case 15:      /* signal IRQ to sound CPU */
504         signal_sound_irq(SOUND_IRQ_V60);
503         signal_sound_irq(machine, SOUND_IRQ_V60);
505504         break;
506505   }
507506}
r2724r2725
528527static WRITE16_HANDLER( interrupt_control_16_w )
529528{
530529   if (ACCESSING_BITS_0_7)
531      int_control_w(offset*2+0, data);
530      int_control_w(machine, offset*2+0, data);
532531   if (ACCESSING_BITS_8_15)
533      int_control_w(offset*2+1, data >> 8);
532      int_control_w(machine, offset*2+1, data >> 8);
534533}
535534
536535
r2724r2725
551550static WRITE32_HANDLER( interrupt_control_32_w )
552551{
553552   if (ACCESSING_BITS_0_7)
554      int_control_w(offset*4+0, data);
553      int_control_w(machine, offset*4+0, data);
555554   if (ACCESSING_BITS_8_15)
556      int_control_w(offset*4+1, data >> 8);
555      int_control_w(machine, offset*4+1, data >> 8);
557556   if (ACCESSING_BITS_16_23)
558      int_control_w(offset*4+2, data >> 16);
557      int_control_w(machine, offset*4+2, data >> 16);
559558   if (ACCESSING_BITS_24_31)
560      int_control_w(offset*4+3, data >> 24);
559      int_control_w(machine, offset*4+3, data >> 24);
561560}
562561
563562
564563static TIMER_CALLBACK( end_of_vblank_int )
565564{
566   signal_v60_irq(MAIN_IRQ_VBSTOP);
565   signal_v60_irq(machine, MAIN_IRQ_VBSTOP);
567566   system32_set_vblank(0);
568567}
569568
570569
571570static INTERRUPT_GEN( start_of_vblank_int )
572571{
573   signal_v60_irq(MAIN_IRQ_VBSTART);
572   signal_v60_irq(machine, MAIN_IRQ_VBSTART);
574573   system32_set_vblank(1);
575574   timer_set(video_screen_get_time_until_pos(machine->primary_screen, 0, 0), NULL, 0, end_of_vblank_int);
576575   if (system32_prot_vblank)
r2724r2725
637636}
638637
639638
640static void common_io_chip_w(int which, offs_t offset, UINT16 data, UINT16 mem_mask)
639static void common_io_chip_w(running_machine *machine, int which, offs_t offset, UINT16 data, UINT16 mem_mask)
641640{
642641   UINT8 old;
643642
r2724r2725
692691      case 0x1c/2:
693692         system32_displayenable[which] = (data & 0x02);
694693         if (which == 0)
695            cpunum_set_input_line(Machine, 1, INPUT_LINE_RESET, (data & 0x04) ? CLEAR_LINE : ASSERT_LINE);
694            cpunum_set_input_line(machine, 1, INPUT_LINE_RESET, (data & 0x04) ? CLEAR_LINE : ASSERT_LINE);
696695         break;
697696   }
698697}
r2724r2725
706705
707706static WRITE16_HANDLER( io_chip_w )
708707{
709   common_io_chip_w(0, offset, data, mem_mask);
708   common_io_chip_w(machine, 0, offset, data, mem_mask);
710709}
711710
712711
r2724r2725
720719static WRITE32_HANDLER( io_chip_0_w )
721720{
722721   if (ACCESSING_BITS_0_15)
723      common_io_chip_w(0, offset*2+0, data, mem_mask);
722      common_io_chip_w(machine, 0, offset*2+0, data, mem_mask);
724723   if (ACCESSING_BITS_16_31)
725      common_io_chip_w(0, offset*2+1, data >> 16, mem_mask >> 16);
724      common_io_chip_w(machine, 0, offset*2+1, data >> 16, mem_mask >> 16);
726725}
727726
728727
r2724r2725
736735static WRITE32_HANDLER( io_chip_1_w )
737736{
738737   if (ACCESSING_BITS_0_15)
739      common_io_chip_w(1, offset*2+0, data, mem_mask);
738      common_io_chip_w(machine, 1, offset*2+0, data, mem_mask);
740739   if (ACCESSING_BITS_16_31)
741      common_io_chip_w(1, offset*2+1, data >> 16, mem_mask >> 16);
740      common_io_chip_w(machine, 1, offset*2+1, data >> 16, mem_mask >> 16);
742741}
743742
744743
r2724r2725
964963
965964static READ16_HANDLER( random_number_16_r )
966965{
967   return mame_rand(Machine);
966   return mame_rand(machine);
968967}
969968
970969static WRITE32_HANDLER( random_number_32_w )
r2724r2725
974973
975974static READ32_HANDLER( random_number_32_r )
976975{
977   return mame_rand(Machine) ^ (mame_rand(Machine) << 16);
976   return mame_rand(machine) ^ (mame_rand(machine) << 16);
978977}
979978
980979
r2724r2725
10271026 *
10281027 *************************************/
10291028
1030static void update_sound_irq_state(void)
1029static void update_sound_irq_state(running_machine *machine)
10311030{
10321031   UINT8 effirq = sound_irq_input & ~sound_irq_control[3] & 0x07;
10331032   int vector;
r2724r2725
10371036   for (vector = 0; vector < 3; vector++)
10381037      if (effirq & (1 << vector))
10391038      {
1040         cpunum_set_input_line_and_vector(Machine, 1, 0, ASSERT_LINE, 2 * vector);
1039         cpunum_set_input_line_and_vector(machine, 1, 0, ASSERT_LINE, 2 * vector);
10411040         break;
10421041      }
10431042
10441043   /* if we didn't find any, clear the interrupt line */
10451044   if (vector == 3)
1046      cpunum_set_input_line(Machine, 1, 0, CLEAR_LINE);
1045      cpunum_set_input_line(machine, 1, 0, CLEAR_LINE);
10471046}
10481047
10491048
1050static void signal_sound_irq(int which)
1049static void signal_sound_irq(running_machine *machine, int which)
10511050{
10521051   int i;
10531052
r2724r2725
10551054   for (i = 0; i < 3; i++)
10561055      if (sound_irq_control[i] == which)
10571056         sound_irq_input |= 1 << i;
1058   update_sound_irq_state();
1057   update_sound_irq_state(machine);
10591058}
10601059
10611060
1062static void clear_sound_irq(int which)
1061static void clear_sound_irq(running_machine *machine, int which)
10631062{
10641063   int i;
10651064   for (i = 0; i < 3; i++)
10661065      if (sound_irq_control[i] == which)
10671066         sound_irq_input &= ~(1 << i);
1068   update_sound_irq_state();
1067   update_sound_irq_state(machine);
10691068}
10701069
10711070
r2724r2725
10751074   if (offset & 1)
10761075   {
10771076      sound_irq_input &= data;
1078      update_sound_irq_state();
1077      update_sound_irq_state(machine);
10791078   }
10801079
10811080   /* high offsets signal an IRQ to the v60 */
10821081   if (offset & 4)
1083      signal_v60_irq(MAIN_IRQ_SOUND);
1082      signal_v60_irq(machine, MAIN_IRQ_SOUND);
10841083}
10851084
10861085
10871086static WRITE8_HANDLER( sound_int_control_hi_w )
10881087{
10891088   sound_irq_control[offset] = data;
1090   update_sound_irq_state();
1089   update_sound_irq_state(machine);
10911090}
10921091
10931092
1094static void ym3438_irq_handler(int state)
1093static void ym3438_irq_handler(running_machine *machine, int state)
10951094{
10961095   if (state)
1097      signal_sound_irq(SOUND_IRQ_YM3438);
1096      signal_sound_irq(machine, SOUND_IRQ_YM3438);
10981097   else
1099      clear_sound_irq(SOUND_IRQ_YM3438);
1098      clear_sound_irq(machine, SOUND_IRQ_YM3438);
11001099}
11011100
11021101
src/mame/drivers/slapfght.c
r2724r2725
462462   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
463463   PORT_SERVICE( 0x40, IP_ACTIVE_LOW )
464464   /* Actually, the following DIPSW doesnt seem to do anything */
465   PORT_BIT(    0x20, 0x20, IPT_DIPSWITCH_NAME ) PORT_NAME("Screen Test") PORT_CODE(KEYCODE_F1) PORT_TOGGLE
465   PORT_DIPNAME( 0x20, 0x20, "Screen Test" ) PORT_CODE(KEYCODE_F1) PORT_TOGGLE
466466   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
467467   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
468468   PORT_DIPNAME( 0x10, 0x00, DEF_STR( Cabinet ) )
r2724r2725
575575   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Demo_Sounds ) )
576576   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
577577   PORT_DIPSETTING(    0x10, DEF_STR( On ) )
578   PORT_BIT(    0x20, 0x20, IPT_DIPSWITCH_NAME ) PORT_NAME("Screen Test") PORT_CODE(KEYCODE_F1) PORT_TOGGLE
578   PORT_DIPNAME( 0x20, 0x20, "Screen Test" ) PORT_CODE(KEYCODE_F1) PORT_TOGGLE
579579   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
580580   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
581581   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Flip_Screen ) )
src/mame/drivers/astinvad.c
r2724r2725
212212static INPUT_CHANGED( spaceint_coin_inserted )
213213{
214214   /* coin insertion causes an NMI */
215   cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, newval ? ASSERT_LINE : CLEAR_LINE);
215   cpunum_set_input_line(field->port->machine, 0, INPUT_LINE_NMI, newval ? ASSERT_LINE : CLEAR_LINE);
216216}
217217
218218
src/mame/drivers/psikyosh.c
r2724r2725
270270*/
271271
272272#include "driver.h"
273#include "deprecat.h"
274273
275274#include "cpu/sh2/sh2.h"
276275#include "machine/eeprom.h"
r2724r2725
580579   AM_RANGE(0x06000000, 0x060fffff) AM_WRITE(SMH_RAM) AM_BASE(&psh_ram)
581580ADDRESS_MAP_END
582581
583static void irqhandler(int linestate)
582static void irqhandler(running_machine *machine, int linestate)
584583{
585584   if (linestate)
586      cpunum_set_input_line(Machine, 0, 12, ASSERT_LINE);
585      cpunum_set_input_line(machine, 0, 12, ASSERT_LINE);
587586   else
588      cpunum_set_input_line(Machine, 0, 12, CLEAR_LINE);
587      cpunum_set_input_line(machine, 0, 12, CLEAR_LINE);
589588}
590589
591590static const struct YMF278B_interface ymf278b_interface =
src/mame/drivers/boogwing.c
r2724r2725
7575*/
7676
7777#include "driver.h"
78#include "deprecat.h"
7978#include "cpu/m68000/m68000.h"
8079#include "cpu/h6280/h6280.h"
8180#include "decocrpt.h"
r2724r2725
283282
284283/**********************************************************************************/
285284
286static void sound_irq(int state)
285static void sound_irq(running_machine *machine, int state)
287286{
288   cpunum_set_input_line(Machine, 1,1,state); /* IRQ 2 */
287   cpunum_set_input_line(machine, 1,1,state); /* IRQ 2 */
289288}
290289
291290static WRITE8_HANDLER( sound_bankswitch_w )
src/mame/drivers/bishjan.c
r2724r2725
205205static READ16_HANDLER( bishjan_unk_r )
206206{
207207   return
208      (mame_rand(Machine) & 0x9800)   |   // bit 7 eeprom?
208      (mame_rand(machine) & 0x9800)   |   // bit 7 eeprom?
209209      (((bishjan_sel==0x12) ? 0x40:0x00) << 8) |
210210//      (mame_rand() & 0xff);
211211//      (((video_screen_get_frame_number(machine->primary_screen)%60)==0)?0x18:0x00);
src/mame/drivers/neodrvr.c
r2724r2725
72027202   memory_install_readwrite16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x200000, 0x201fff, 0, 0, SMH_BANK8, SMH_BANK8);
72037203   memory_set_bankptr(NEOGEO_BANK_EXTRA_RAM, extra_ram);
72047204
7205//  memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x280000, 0x280001, 0, 0, port_tag_to_handler16("IN5") );
7206//  memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x2c0000, 0x2c0001, 0, 0, port_tag_to_handler16("IN6") );
7205//  memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x280000, 0x280001, 0, 0, input_port_read_handler16(machine->portconfig, "IN5") );
7206//  memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x2c0000, 0x2c0001, 0, 0, input_port_read_handler16(machine->portconfig, "IN6") );
72077207
72087208   DRIVER_INIT_CALL(neogeo);
72097209}
r2724r2725
72197219   memory_install_readwrite16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x200000, 0x201fff, 0, 0, SMH_BANK8, SMH_BANK8);
72207220   memory_set_bankptr(NEOGEO_BANK_EXTRA_RAM, extra_ram);
72217221
7222   memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x280000, 0x280001, 0, 0, port_tag_to_handler16("IN5") );
7223    memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x2c0000, 0x2c0001, 0, 0, port_tag_to_handler16("IN6") );
7222   memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x280000, 0x280001, 0, 0, input_port_read_handler16(machine->portconfig, "IN5") );
7223    memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x2c0000, 0x2c0001, 0, 0, input_port_read_handler16(machine->portconfig, "IN6") );
72247224
72257225   DRIVER_INIT_CALL(neogeo);
72267226}
r2724r2725
72297229static DRIVER_INIT( kog )
72307230{
72317231   /* overlay cartridge ROM */
7232   memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x0ffffe, 0x0fffff, 0, 0, port_tag_to_handler16("JUMPER") );
7232   memory_install_read16_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x0ffffe, 0x0fffff, 0, 0, input_port_read_handler16(machine->portconfig, "JUMPER") );
72337233
72347234   kog_px_decrypt();
72357235   neogeo_bootleg_sx_decrypt(1);
src/mame/drivers/fromance.c
r2724r2725
4040******************************************************************************/
4141
4242#include "driver.h"
43#include "deprecat.h"
4443#include "cpu/z80/z80.h"
4544#include "fromance.h"
4645#include "sound/ay8910.h"
r2724r2725
165164}
166165
167166
168static void fromance_adpcm_int(int irq)
167static void fromance_adpcm_int(running_machine *machine, int irq)
169168{
170169   /* skip if we're reset */
171170   if (!fromance_adpcm_reset)
r2724r2725
181180
182181   /* generate an NMI if we're out of data */
183182   if (!fromance_vclk_left)
184      cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, PULSE_LINE);
183      cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, PULSE_LINE);
185184}
186185
187186
src/mame/drivers/dlair.c
r2724r2725
3434
3535#include "driver.h"
3636#include "render.h"
37#include "deprecat.h"
3837#include "cpu/z80/z80daisy.h"
3938#include "machine/laserdsc.h"
4039#include "machine/z80ctc.h"
r2724r2725
8988 *
9089 *************************************/
9190
92static void dleuro_interrupt(int state)
91static void dleuro_interrupt(running_machine *machine, int state)
9392{
94   cpunum_set_input_line(Machine, 0, 0, state);
93   cpunum_set_input_line(machine, 0, 0, state);
9594}
9695
9796
src/mame/drivers/ssfindo.c
r2724r2725
121121*/
122122
123123#include "driver.h"
124#include "deprecat.h"
125124#include "cpu/arm7/arm7core.h"
126125
127126enum
r2724r2725
315314   switch(offset)
316315   {
317316      case MSECR:
318         return mame_rand(Machine);
317         return mame_rand(machine);
319318      break;
320319
321320      case IOLINES: //TODO: eeprom  24c01
r2724r2725
326325      if(flashType==1)
327326         return 0;
328327      else
329         return mame_rand(Machine);
328         return mame_rand(machine);
330329
331330      case IRQSTA:
332331         return (PS7500_IO[offset]&(~2))|0x80;
r2724r2725
354353      //default:
355354         //mame_printf_debug("ior %i @%x\n",offset,activecpu_get_pc());
356355   }
357   return mame_rand(Machine);//PS7500_IO[offset];
356   return mame_rand(machine);//PS7500_IO[offset];
358357}
359358
360359static WRITE32_HANDLER(PS7500_IO_w)
r2724r2725
476475
477476static READ32_HANDLER(ff4_r)
478477{
479   return mame_rand(Machine)&0x20;
478   return mame_rand(machine)&0x20;
480479}
481480
482481static READ32_HANDLER(SIMPLEIO_r)
483482{
484   return mame_rand(Machine)&1;
483   return mame_rand(machine)&1;
485484}
486485
487486static READ32_HANDLER(randomized_r)
488487{
489   return mame_rand(Machine);
488   return mame_rand(machine);
490489}
491490
492491static ADDRESS_MAP_START( ssfindo_map, ADDRESS_SPACE_PROGRAM, 32 )
src/mame/drivers/firetrk.c
r2724r2725
3434
3535static INPUT_CHANGED( service_mode_switch_changed )
3636{
37   set_service_mode(machine, newval);
37   set_service_mode(field->port->machine, newval);
3838}
3939
4040
4141static INPUT_CHANGED( firetrk_horn_changed )
4242{
43   discrete_sound_w(machine, FIRETRUCK_HORN_EN, newval);
43   discrete_sound_w(field->port->machine, FIRETRUCK_HORN_EN, newval);
4444}
4545
4646
src/mame/drivers/segas24.c
r2724r2725
978978   }
979979}
980980
981static void irq_ym(int irq)
981static void irq_ym(running_machine *machine, int irq)
982982{
983983   irq_yms = irq;
984   cpunum_set_input_line(Machine, 0, IRQ_YM2151+1, irq_yms && (irq_allow0 & (1 << IRQ_YM2151)) ? ASSERT_LINE : CLEAR_LINE);
985   cpunum_set_input_line(Machine, 1, IRQ_YM2151+1, irq_yms && (irq_allow1 & (1 << IRQ_YM2151)) ? ASSERT_LINE : CLEAR_LINE);
984   cpunum_set_input_line(machine, 0, IRQ_YM2151+1, irq_yms && (irq_allow0 & (1 << IRQ_YM2151)) ? ASSERT_LINE : CLEAR_LINE);
985   cpunum_set_input_line(machine, 1, IRQ_YM2151+1, irq_yms && (irq_allow1 & (1 << IRQ_YM2151)) ? ASSERT_LINE : CLEAR_LINE);
986986}
987987
988988
src/mame/drivers/neogeo.c
r2724r2725
295295 *
296296 *************************************/
297297
298static void audio_cpu_irq(int assert)
298static void audio_cpu_irq(running_machine *machine, int assert)
299299{
300   cpunum_set_input_line(Machine, 1, 0, assert ? ASSERT_LINE : CLEAR_LINE);
300   cpunum_set_input_line(machine, 1, 0, assert ? ASSERT_LINE : CLEAR_LINE);
301301}
302302
303303
304static void audio_cpu_assert_nmi(void)
304static void audio_cpu_assert_nmi(running_machine *machine)
305305{
306   cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, ASSERT_LINE);
306   cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, ASSERT_LINE);
307307}
308308
309309
r2724r2725
332332
333333   sprintf(tag, "IN%s-%d", (const char *)param, controller_select & 0x01);
334334
335   return input_port_read(machine, tag);
335   return input_port_read(field->port->machine, tag);
336336}
337337
338338
r2724r2725
351351   {
352352   default:
353353   case 0x00: ret = 0x0000; break; /* nothing? */
354   case 0x09: ret = input_port_read(machine, "MAHJONG1"); break;
355   case 0x12: ret = input_port_read(machine, "MAHJONG2"); break;
356   case 0x1b: ret = input_port_read(machine, "MAHJONG3"); break; /* player 1 normal inputs? */
357   case 0x24: ret = input_port_read(machine, "MAHJONG4"); break;
354   case 0x09: ret = input_port_read(field->port->machine, "MAHJONG1"); break;
355   case 0x12: ret = input_port_read(field->port->machine, "MAHJONG2"); break;
356   case 0x1b: ret = input_port_read(field->port->machine, "MAHJONG3"); break; /* player 1 normal inputs? */
357   case 0x24: ret = input_port_read(field->port->machine, "MAHJONG4"); break;
358358   }
359359
360360   return ret;
r2724r2725
444444
445445static CUSTOM_INPUT( get_calendar_status )
446446{
447   return (pd4990a_databit_r(machine, 0) << 1) | pd4990a_testbit_r(machine, 0);
447   return (pd4990a_databit_r(field->port->machine, 0) << 1) | pd4990a_testbit_r(field->port->machine, 0);
448448}
449449
450450
r2724r2725
566566   {
567567      soundlatch_w(machine, 0, data >> 8);
568568
569      audio_cpu_assert_nmi();
569      audio_cpu_assert_nmi(machine);
570570
571571      /* boost the interleave to let the audio CPU read the command */
572572      cpu_boost_interleave(attotime_zero, ATTOTIME_IN_USEC(50));
src/mame/drivers/snookr10.c
r2724r2725
2121
2222    CPU:    1x 65SC02 at 2MHz.
2323
24    Sound:  1x AD-65 or U6295 (OKI6295 compatible)
24    Sound:  1x AD-65 or U6295 (OKI6295 compatible) at 1MHz, pin7 HIGH.
2525            1x LM358N
2626            1x TDA2003
2727
r2724r2725
4848***************************************************************************************
4949
5050
51    All the supported games have been coded using some Funworld games as point to start,
51    All supported games have been coded using some italian C.M.C games as point to start,
5252    changing hardware accesses, program logics, graphics, plus protection and some I/O
5353    through the 2x high density PLDs.
5454
r2724r2725
8686
8787    To clear credits (and stats), just re-initialize the NVRAM.
8888
89    Only for the new hardware revision (snookr10 & apple10), pressing STOP 1 (key 'Z') in the
89    Only for the new hardware revision (snookr10 & apple10), pressing STOP 1 (key 'Z') into the
9090    stats mode, make the hidden Input Test mode to appear. Press RESET (F3) to exit the mode.
9191
9292
r2724r2725
199199    To properly decrypt the thing 'on the fly' as the hardware does, I applied a bitswap into TILE_GET_INFO.
200200    This method rearrange the tile number for each tile called to be drawn.
201201
202    The final algorhithm:
202    The final algorithm:
203203                                                                   digit #3
204204                                                                   +-------+ swapped digits 1 & 2
205205                                                                   |       |  +-------+------+
r2724r2725
231231    0xE0-0xEF  |  0x70-0x7F
232232    0xF0-0xFF  |  0xF0-0xFF
233233
234    And each one of these segments are internally scrambled too.
234235
235    So, the algorhythm to properly decrypt the color codes is very different here:
236    So, the algorithm to properly decrypt the color codes is very different here:
236237
237238                                          1st nibble
238239                                      inverted bitorder
r2724r2725
248249***********************************************************************************
249250
250251
251    Memory Maps
252    -----------
252    * MEMORY MAPS *
253    ---------------
253254
254255    (Old hardware)
255256
r2724r2725
261262    $4003 - $4003   Input Port 3   ;R  , DIP switches.
262263    $5000 - $5000   Output Port A  ;W  , lamps.
263264    $5001 - $5001   Output Port B  ;W  , lamps.
264    $6000 - $6FFF   VideoRAM
265    $7000 - $7FFF   ColorRAM
265    $6000 - $6FFF   Video RAM
266    $7000 - $7FFF   Color RAM
266267    $8000 - $FFFF   ROM Space
267268
268269
r2724r2725
274275    $3001 - $3001   Input Port 1   ;R
275276    $3002 - $3002   Input Port 2   ;R
276277    $3003 - $3003   Input Port 3   ;R  , DIP switches.
277    $3004 - $3004   ???            ;R  , the code is constantly polling bit 7.
278    $3004 - $3004   (unknown)      ;R  , the code is constantly polling bit 7.
278279    $5000 - $5000   Output Port A  ;W  , lamps.
279280    $5001 - $5001   Output Port B  ;W  , lamps.
280    $6000 - $6FFF   VideoRAM
281    $7000 - $7FFF   ColorRAM
281    $6000 - $6FFF   Video RAM
282    $7000 - $7FFF   Color RAM
282283    $8000 - $FFFF   ROM Space
283284
284285
r2724r2725
288289    *** Driver Updates ***
289290
290291
292    [2008/05/22]
293    - Confirmed the CPU clock after some PCB measurements.
294    - Changed the SND clock to 1MHz to match the PCB measurement.
295    - Corrected the internal OKI6295 frequency turning the pin 7 state to HIGH.
296    - Inputs: Eliminated all pulse limitations.
297      Affected buttons have a rattled sound in the real thing too.
298    - Updated technical notes.
299
291300    [2008/04/28]
292301    - Created a new machine driver for tenballs due to different memory map.
293302    - Worked all the input ports from the scratch.
r2724r2725
318327    *** TO DO ***
319328
320329    - Figure out the unknown reads to offset $3004, bit 7.
321    - Get CPU and sound clocks properly measured.
322    - Get the OKI6295 pin 7 measured to know the real status.
323330    - Hook lamps.
331    - Turn the color system to resnet calculation.
324332
325333
326334***********************************************************************************/
r2724r2725
440448static INPUT_PORTS_START( snookr10 )
441449   PORT_START_TAG("IN0")
442450   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SERVICE )   PORT_NAME("Remote x100") PORT_CODE(KEYCODE_Q)
443   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON1 )   PORT_IMPULSE(2) PORT_NAME("Stop 1") PORT_CODE(KEYCODE_Z)   /* Input Test in stats mode */
444   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON6 )   PORT_IMPULSE(2) PORT_NAME("Cancella (Cancel) / Play / Bet") PORT_CODE(KEYCODE_N)
451   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON1 )   PORT_NAME("Stop 1") PORT_CODE(KEYCODE_Z)   /* Input Test in stats mode */
452   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON6 )   PORT_NAME("Cancella (Cancel) / Play / Bet") PORT_CODE(KEYCODE_N)
445453   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 )      PORT_NAME("Start (Deal) / Raddoppio (Double-Up)")
446   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON5 )   PORT_IMPULSE(2) PORT_NAME("Stop 5 / Risk (Half Gamble) / Super Game") PORT_CODE(KEYCODE_B)
454   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON5 )   PORT_NAME("Stop 5 / Risk (Half Gamble) / Super Game") PORT_CODE(KEYCODE_B)
447455   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_SERVICE1 )   PORT_NAME("Estatistica (Stats)")
448456   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_SERVICE2 )   PORT_NAME("Management")
449   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON4 )   PORT_IMPULSE(2) PORT_NAME("Stop 4 / Alta (High)") PORT_CODE(KEYCODE_V)
457   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON4 )   PORT_NAME("Stop 4 / Alta (High)") PORT_CODE(KEYCODE_V)
450458
451459   PORT_START_TAG("IN1")
452   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON2 )   PORT_IMPULSE(2) PORT_NAME("Stop 2 / Bassa (Low)") PORT_CODE(KEYCODE_X)
453   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON3 )   PORT_IMPULSE(2) PORT_NAME("Stop 3") PORT_CODE(KEYCODE_C)
460   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON2 )   PORT_NAME("Stop 2 / Bassa (Low)") PORT_CODE(KEYCODE_X)
461   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON3 )   PORT_NAME("Stop 3") PORT_CODE(KEYCODE_C)
454462   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_SERVICE )   PORT_NAME("Ticket") PORT_CODE(KEYCODE_T)
455463   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_SERVICE )   PORT_NAME("Hopper") PORT_CODE(KEYCODE_H)
456464   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
r2724r2725
495503static INPUT_PORTS_START( apple10 )
496504   PORT_START_TAG("IN0")
497505   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SERVICE )   PORT_NAME("Remote x100") PORT_CODE(KEYCODE_Q)
498   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON1 )   PORT_IMPULSE(2) PORT_NAME("Stop 1") PORT_CODE(KEYCODE_Z)   /* Input Test in stats mode */
499   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON6 )   PORT_IMPULSE(2) PORT_NAME("Cancella (Cancel) / Play / Bet") PORT_CODE(KEYCODE_N)
506   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON1 )   PORT_NAME("Stop 1") PORT_CODE(KEYCODE_Z)   /* Input Test in stats mode */
507   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON6 )   PORT_NAME("Cancella (Cancel) / Play / Bet") PORT_CODE(KEYCODE_N)
500508   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 )      PORT_NAME("Start (Deal) / Raddoppio (Double-Up)")
501   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON5 )   PORT_IMPULSE(2) PORT_NAME("Stop 5 / Risk (Half Gamble) / Super Game") PORT_CODE(KEYCODE_B)
509   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON5 )   PORT_NAME("Stop 5 / Risk (Half Gamble) / Super Game") PORT_CODE(KEYCODE_B)
502510   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_SERVICE1 )   PORT_NAME("Estatistica (Stats)")
503511   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_SERVICE2 )   PORT_NAME("Management")
504   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON4 )   PORT_IMPULSE(2) PORT_NAME("Stop 4 / Alta (High)") PORT_CODE(KEYCODE_V)
512   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON4 )   PORT_NAME("Stop 4 / Alta (High)") PORT_CODE(KEYCODE_V)
505513
506514   PORT_START_TAG("IN1")
507   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON2 )   PORT_IMPULSE(2) PORT_NAME("Stop 2 / Bassa (Low)") PORT_CODE(KEYCODE_X)
508   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON3 )   PORT_IMPULSE(2) PORT_NAME("Stop 3") PORT_CODE(KEYCODE_C)
515   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON2 )   PORT_NAME("Stop 2 / Bassa (Low)") PORT_CODE(KEYCODE_X)
516   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON3 )   PORT_NAME("Stop 3") PORT_CODE(KEYCODE_C)
509517   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_SERVICE )   PORT_NAME("Ticket") PORT_CODE(KEYCODE_T)
510518   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_SERVICE )   PORT_NAME("Hopper") PORT_CODE(KEYCODE_H)
511519   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
r2724r2725
550558static INPUT_PORTS_START( tenballs )
551559   PORT_START_TAG("IN0")
552560   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SERVICE )   PORT_NAME("Remote x100") PORT_CODE(KEYCODE_Q)
553   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON1 )   PORT_IMPULSE(2) PORT_NAME("Stop 1") PORT_CODE(KEYCODE_Z)   /* no Input Test in stats mode */
554   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON6 )   PORT_IMPULSE(2) PORT_NAME("Cancella (Cancel) / Play / Bet") PORT_CODE(KEYCODE_N)
561   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON1 )   PORT_NAME("Stop 1") PORT_CODE(KEYCODE_Z)   /* no Input Test in stats mode */
562   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON6 )   PORT_NAME("Cancella (Cancel) / Play / Bet") PORT_CODE(KEYCODE_N)
555563   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 )      PORT_NAME("Start (Deal) / Raddoppio (Double-Up)")
556   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON5 )   PORT_IMPULSE(2) PORT_NAME("Stop 5 / Risk (Half Gamble) / Super Game") PORT_CODE(KEYCODE_B)
564   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON5 )   PORT_NAME("Stop 5 / Risk (Half Gamble) / Super Game") PORT_CODE(KEYCODE_B)
557565   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_SERVICE1 )   PORT_NAME("Estatistica (Stats)")
558566   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_SERVICE2 )   PORT_NAME("Management")
559   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON4 )   PORT_IMPULSE(2) PORT_NAME("Stop 4 / Alta (High)") PORT_CODE(KEYCODE_V)
567   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON4 )   PORT_NAME("Stop 4 / Alta (High)") PORT_CODE(KEYCODE_V)
560568
561569   PORT_START_TAG("IN1")
562   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON2 )   PORT_IMPULSE(2) PORT_NAME("Stop 2 / Bassa (Low)") PORT_CODE(KEYCODE_X)
563   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON3 )   PORT_IMPULSE(2) PORT_NAME("Stop 3") PORT_CODE(KEYCODE_C)
570   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON2 )   PORT_NAME("Stop 2 / Bassa (Low)") PORT_CODE(KEYCODE_X)
571   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON3 )   PORT_NAME("Stop 3") PORT_CODE(KEYCODE_C)
564572   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_SERVICE )   PORT_NAME("Ticket") PORT_CODE(KEYCODE_T)
565573   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_SERVICE )   PORT_NAME("Hopper") PORT_CODE(KEYCODE_H)
566574   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
r2724r2725
644652static MACHINE_DRIVER_START( snookr10 )
645653
646654    /* basic machine hardware */
647   MDRV_CPU_ADD_TAG("main", M65SC02, MASTER_CLOCK/8)   /* 2MHz */
655   MDRV_CPU_ADD_TAG("main", M65SC02, MASTER_CLOCK/8)   /* 2 MHz (1.999 MHz measured) */
648656   MDRV_CPU_PROGRAM_MAP(snookr10_map, 0)
649657   MDRV_CPU_VBLANK_INT("main", nmi_line_pulse)
650658
r2724r2725
668676
669677   /* sound hardware */
670678   MDRV_SPEAKER_STANDARD_MONO("mono")
671   MDRV_SOUND_ADD(OKIM6295, MASTER_CLOCK/12)   /* guess */
672   MDRV_SOUND_CONFIG(okim6295_interface_region_1_pin7low)   /* pin7 not checked */
679   MDRV_SOUND_ADD(OKIM6295, MASTER_CLOCK/16)   /* 1 MHz (995.5 kHz measured) */
680   MDRV_SOUND_CONFIG(okim6295_interface_region_1_pin7high)   /* pin7 checked on PCB */
673681   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.8)
674682
675683MACHINE_DRIVER_END
src/mame/drivers/segahang.c
r2724r2725
343343 *
344344 *************************************/
345345
346static void sound_irq(int irq)
346static void sound_irq(running_machine *machine, int irq)
347347{
348   cpunum_set_input_line(Machine, 2, 0, irq ? ASSERT_LINE : CLEAR_LINE);
348   cpunum_set_input_line(machine, 2, 0, irq ? ASSERT_LINE : CLEAR_LINE);
349349}
350350
351351
src/mame/drivers/carrera.c
r2724r2725
4242#define MASTER_CLOCK 22118400
4343
4444#include "driver.h"
45#include "deprecat.h"
4645#include "sound/ay8910.h"
4746#include "video/mc6845.h"
4847
r2724r2725
266265
267266static READ8_HANDLER( unknown_r )
268267{
269   return mame_rand(Machine);
268   return mame_rand(machine);
270269}
271270
272271/* these are set as input, but I have no idea which input port it uses is for the AY */
src/mame/drivers/dorachan.c
r2724r2725
119119{
120120   /* to avoid resetting (when player 2 starts) bit 0 need to be
121121       inverted when screen is flipped */
122   return ((video_screen_get_vpos(machine->primary_screen) >> 7) & 0x01) ^ dorachan_flip_screen;
122   return ((video_screen_get_vpos(field->port->machine->primary_screen) >> 7) & 0x01) ^ dorachan_flip_screen;
123123}
124124
125125
src/mame/drivers/ladybug.c
r2724r2725
138138static INPUT_CHANGED( coin1_inserted )
139139{
140140   /* left coin insertion causes an NMI */
141   cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, newval ? ASSERT_LINE : CLEAR_LINE);
141   cpunum_set_input_line(field->port->machine, 0, INPUT_LINE_NMI, newval ? ASSERT_LINE : CLEAR_LINE);
142142}
143143
144144static INPUT_CHANGED( coin2_inserted )
145145{
146146   /* right coin insertion causes an IRQ */
147147   if (newval)
148      cpunum_set_input_line(machine, 0, 0, HOLD_LINE);
148      cpunum_set_input_line(field->port->machine, 0, 0, HOLD_LINE);
149149}
150150
151151
r2724r2725
154154
155155static CUSTOM_INPUT( ladybug_p1_control_r )
156156{
157   return input_port_read(machine, LADYBUG_P1_CONTROL_PORT_TAG);
157   return input_port_read(field->port->machine, LADYBUG_P1_CONTROL_PORT_TAG);
158158}
159159
160160static CUSTOM_INPUT( ladybug_p2_control_r )
r2724r2725
162162   UINT32 ret;
163163
164164   /* upright cabinet only uses a single set of controls */
165   if (input_port_read(machine, "DSW0") & 0x20)
166      ret = input_port_read(machine, LADYBUG_P2_CONTROL_PORT_TAG);
165   if (input_port_read(field->port->machine, "DSW0") & 0x20)
166      ret = input_port_read(field->port->machine, LADYBUG_P2_CONTROL_PORT_TAG);
167167   else
168      ret = input_port_read(machine, LADYBUG_P1_CONTROL_PORT_TAG);
168      ret = input_port_read(field->port->machine, LADYBUG_P1_CONTROL_PORT_TAG);
169169
170170   return ret;
171171}
r2724r2725
202202   PORT_DIPNAME( 0x04, 0x04, "High Score Names" )
203203   PORT_DIPSETTING(    0x00, "3 Letters" )
204204   PORT_DIPSETTING(    0x04, "10 Letters" )
205   PORT_BIT(    0x08, 0x08, IPT_DIPSWITCH_NAME ) PORT_NAME("Rack Test (Cheat)") PORT_CODE(KEYCODE_F1)
205   PORT_DIPNAME( 0x08, 0x08, "Rack Test (Cheat)" ) PORT_CODE(KEYCODE_F1)
206206   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
207207   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
208208   PORT_DIPNAME( 0x10, 0x10, "Freeze" )
r2724r2725
474474   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Bonus_Life ) )
475475   PORT_DIPSETTING(    0x04, "20000" )
476476   PORT_DIPSETTING(    0x00, "30000" )
477   PORT_BIT(    0x08, 0x08, IPT_DIPSWITCH_NAME ) PORT_NAME("Rack Test (Cheat)") PORT_CODE(KEYCODE_F1)
477   PORT_DIPNAME( 0x08, 0x08, "Rack Test (Cheat)" ) PORT_CODE(KEYCODE_F1)
478478   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
479479   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
480480   PORT_DIPNAME( 0x10, 0x10, "Freeze" )
src/mame/drivers/ttchamp.c
r2724r2725
4242*/
4343
4444#include "driver.h"
45#include "deprecat.h"
4645
4746static UINT16 *peno_vram;
4847
r2724r2725
110109
111110static READ16_HANDLER( peno_rand )
112111{
113    return 0xffff;// mame_rand(Machine);
112    return 0xffff;// mame_rand(machine);
114113}
115114
116115#ifdef UNUSED_FUNCTION
117116static READ16_HANDLER( peno_rand2 )
118117{
119    return mame_rand(Machine);
118    return mame_rand(machine);
120119}
121120#endif
122121
src/mame/drivers/gotcha.c
r2724r2725
5858***************************************************************************/
5959
6060#include "driver.h"
61#include "deprecat.h"
6261#include "sound/2151intf.h"
6362#include "sound/okim6295.h"
6463
r2724r2725
260259
261260
262261
263static void irqhandler(int linestate)
262static void irqhandler(running_machine *machine, int linestate)
264263{
265   cpunum_set_input_line(Machine, 1,0,linestate);
264   cpunum_set_input_line(machine, 1,0,linestate);
266265}
267266
268267static const struct YM2151interface ym2151_interface =
src/mame/drivers/taito_f2.c
r2724r2725
289289***************************************************************************/
290290
291291#include "driver.h"
292#include "deprecat.h"
293292#include "cpu/m68000/m68000.h"
294293#include "video/taitoic.h"
295294#include "audio/taitosnd.h"
r2724r2725
38193818
38203819
38213820/* handler called by the YM2610 emulator when the internal timers cause an IRQ */
3822static void irq_handler(int irq)
3821static void irq_handler(running_machine *machine, int irq)
38233822{
3824   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
3823   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
38253824}
38263825
38273826static const struct YM2610interface ym2610_interface =
src/mame/drivers/stfight.c
r2724r2725
245245WRITE8_HANDLER( stfight_coin_w );
246246WRITE8_HANDLER( stfight_e800_w );
247247READ8_HANDLER( stfight_fm_r );
248void stfight_adpcm_int( int data );
248void stfight_adpcm_int( running_machine *machine, int data );
249249WRITE8_HANDLER( stfight_adpcm_control_w );
250250
251251// video
src/mame/drivers/gottlieb.c
r2724r2725
18171817   ROM_LOAD( "mqb-rom0.bin",  0xe000, 0x2000, CRC(12a90cb2) SHA1(a33203aea79fe43d1233a16e3fdddaceac6e4a20) )
18181818
18191819   ROM_REGION( 0x10000, REGION_CPU2, 0 )
1820   ROM_LOAD( "mqb-snd1.bin",  0x7000, 0x800, CRC(e704b450) SHA1(d509f54658e9f0264b9ab865a6f36e5423a28904) )
1821   ROM_LOAD( "mqb-snd2.bin",  0x7800, 0x800, CRC(c6a98bf8) SHA1(cc5b5bb5966f5d79226f1f665a3f9fc934f4ef7f) )
1820   ROM_LOAD( "mqb-snd1.bin",  0x7000, 0x800, CRC(495ffcd2) SHA1(b2c16fffbd6af1c17fdb1a99844819e6ee0550ee) )
1821   ROM_LOAD( "mqb-snd2.bin",  0x7800, 0x800, CRC(9bbaa945) SHA1(13791b69cd6f426ad77a7d0537b10012feb0bc87) )
18221822
18231823   ROM_REGION( 0x2000, REGION_GFX1, ROMREGION_DISPOSE )
18241824   ROM_LOAD( "qb-bg0.bin",   0x0000, 0x1000, CRC(7a9ba824) SHA1(12aa6df499eb6996ee35f56acac403ff6290f844) ) /* chars */
r2724r2725
19701970   ROM_LOAD( "qq-rom0.bin",  0xe000, 0x2000, CRC(8ddbe438) SHA1(31112d711af5d4039491e99a0be0c088b3272482) )
19711971
19721972   ROM_REGION( 0x10000, REGION_CPU2, 0 )
1973   ROM_LOAD( "qq-snd1.bin",  0x7000, 0x800, BAD_DUMP CRC(15787c07) SHA1(8b7d03fbf2ebaa71b3a7e2f636a0d1bb9b796e43) )
1974   ROM_LOAD( "qq-snd2.bin",  0x7800, 0x800, BAD_DUMP CRC(58437508) SHA1(09d8053e7e99679b602dcda230d64db7fe6cb7f5) )
1973   ROM_LOAD( "qq-snd1.bin",  0x7000, 0x800, CRC(e704b450) SHA1(d509f54658e9f0264b9ab865a6f36e5423a28904) )
1974   ROM_LOAD( "qq-snd2.bin",  0x7800, 0x800, CRC(c6a98bf8) SHA1(cc5b5bb5966f5d79226f1f665a3f9fc934f4ef7f) )
19751975
19761976   ROM_REGION( 0x2000, REGION_GFX1, ROMREGION_DISPOSE )
19771977   ROM_LOAD( "qq-bg0.bin",   0x0000, 0x1000, CRC(050badde) SHA1(d049367e262cc6080e01d32227e86310166e00bb) )   /* chars */
r2724r2725
22602260GAME( 1983, krull,    0,        krull,    krull,    0,        ROT270, "Gottlieb", "Krull", 0 )
22612261GAME( 1983, kngtmare, 0,        gottlieb, kngtmare, 0,        ROT0,   "Gottlieb", "Knightmare (prototype)", GAME_NO_SOUND )
22622262GAME( 1983, sqbert,   0,        qbert,    qbert,    0,        ROT270, "Mylstar", "Faster, Harder, More Challenging Q*bert (prototype)", 0 )
2263GAME( 1983, qbertqub, 0,        qbert,    qbertqub, 0,        ROT270, "Mylstar", "Q*bert's Qubes", GAME_IMPERFECT_SOUND )
2263GAME( 1983, qbertqub, 0,        qbert,    qbertqub, 0,        ROT270, "Mylstar", "Q*bert's Qubes", 0 )
22642264GAME( 1983, mach3,    0,        gottlieb2,mach3,    laserdsc, ROT0,   "Mylstar", "M.A.C.H. 3", GAME_NOT_WORKING )
22652265GAME( 1983, screwloo, 0,        gottlieb2,screwloo, gottlieb, ROT0,   "Mylstar", "Screw Loose (prototype)", 0 )
22662266GAME( 1984, cobram3,  0,        gottlieb2,mach3,    laserdsc, ROT0,   "Data East","Cobra Command", GAME_NOT_WORKING )
src/mame/drivers/sandscrp.c
r2724r2725
7171*/
7272
7373#include "driver.h"
74#include "deprecat.h"
7574#include "machine/eeprom.h"
7675#include "includes/kaneko16.h"
7776#include "sound/2203intf.h"
r2724r2725
101100
102101
103102/* Update the IRQ state based on all possible causes */
104static void update_irq_state(void)
103static void update_irq_state(running_machine *machine)
105104{
106105   if (vblank_irq || sprite_irq || unknown_irq)
107      cpunum_set_input_line(Machine, 0, 1, ASSERT_LINE);
106      cpunum_set_input_line(machine, 0, 1, ASSERT_LINE);
108107   else
109      cpunum_set_input_line(Machine, 0, 1, CLEAR_LINE);
108      cpunum_set_input_line(machine, 0, 1, CLEAR_LINE);
110109}
111110
112111
r2724r2725
115114static INTERRUPT_GEN( sandscrp_interrupt )
116115{
117116   vblank_irq = 1;
118   update_irq_state();
117   update_irq_state(machine);
119118}
120119
121120
122121static VIDEO_EOF( sandscrp )
123122{
124123   sprite_irq = 1;
125   update_irq_state();
124   update_irq_state(machine);
126125   pandora_eof(machine);
127126}
128127
r2724r2725
148147      if (data & 0x20)   vblank_irq  = 0;
149148   }
150149
151   update_irq_state();
150   update_irq_state(machine);
152151}
153152
154153
r2724r2725
415414
416415/* YM3014B + YM2203C */
417416
418static void irq_handler(int irq)
417static void irq_handler(running_machine *machine, int irq)
419418{
420   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
419   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
421420}
422421
423422static const struct YM2203interface ym2203_intf_sandscrp =
src/mame/drivers/ddragon.c
r2724r2725
6565***************************************************************************/
6666
6767#include "driver.h"
68#include "deprecat.h"
6968#include "cpu/m6800/m6800.h"
7069#include "cpu/m6805/m6805.h"
7170#include "cpu/m6809/m6809.h"
r2724r2725
348347}
349348
350349
351static void irq_handler(int irq)
350static void irq_handler(running_machine *machine, int irq)
352351{
353   cpunum_set_input_line(Machine, snd_cpu, ym_irq , irq ? ASSERT_LINE : CLEAR_LINE );
352   cpunum_set_input_line(machine, snd_cpu, ym_irq , irq ? ASSERT_LINE : CLEAR_LINE );
354353}
355354
356355
r2724r2725
458457}
459458
460459
461static void dd_adpcm_int(int chip)
460static void dd_adpcm_int(running_machine *machine, int chip)
462461{
463462   static int adpcm_data[2] = { -1, -1 };
464463
src/mame/drivers/tubep.c
r2724r2725
9999
100100
101101#include "driver.h"
102#include "deprecat.h"
103102#include "cpu/z80/z80.h"
104103#include "cpu/m6805/m6805.h"
105104#include "sound/ay8910.h"
r2724r2725
565564}
566565
567566
568static void rjammer_adpcm_vck (int data)
567static void rjammer_adpcm_vck (running_machine *machine, int data)
569568{
570569   ls74 = (ls74+1) & 1;
571570
572571   if (ls74==1)
573572   {
574573      MSM5205_data_w(0, (ls377>>0) & 15 );
575      cpunum_set_input_line(Machine, 2, 0, ASSERT_LINE );
574      cpunum_set_input_line(machine, 2, 0, ASSERT_LINE );
576575   }
577576   else
578577   {
src/mame/drivers/exidy.c
r2724r2725
145145static CUSTOM_INPUT( teetert_input_direction_r )
146146{
147147   int result = 0;
148   UINT8 dial = input_port_read(machine, "DIAL");
148   UINT8 dial = input_port_read(field->port->machine, "DIAL");
149149
150150   if (dial != last_dial)
151151   {
r2724r2725
164164
165165static CUSTOM_INPUT( teetert_input_movement_r )
166166{
167   UINT8 dial = input_port_read(machine, "DIAL");
167   UINT8 dial = input_port_read(field->port->machine, "DIAL");
168168
169169   return (dial != last_dial) ? 1 : 0;
170170}
r2724r2725
500500   PORT_START_TAG("IN2")
501501   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("Yellow Button")
502502   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("Red Button")
503   PORT_BIT( 0x04, 0x04, IPT_DIPSWITCH_NAME ) PORT_NAME( DEF_STR( Free_Play ))
503   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Free_Play ) )
504504   PORT_DIPSETTING( 0x04, DEF_STR( Off ) )
505505   PORT_DIPSETTING( 0x00, DEF_STR( On ) )
506506   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("Blue Button")
src/mame/drivers/mugsmash.c
r2724r2725
4040*/
4141
4242#include "driver.h"
43#include "deprecat.h"
4443#include "sound/2151intf.h"
4544#include "sound/okim6295.h"
4645
r2724r2725
417416   GFXDECODE_ENTRY( REGION_GFX2, 0, mugsmash2_layout,  0x100, 256  ) /* bg tiles */
418417GFXDECODE_END
419418
420static void irq_handler(int irq)
419static void irq_handler(running_machine *machine, int irq)
421420{
422   cpunum_set_input_line(Machine, 1, 0 , irq ? ASSERT_LINE : CLEAR_LINE );
421   cpunum_set_input_line(machine, 1, 0 , irq ? ASSERT_LINE : CLEAR_LINE );
423422}
424423
425424static const struct YM2151interface ym2151_interface =
src/mame/drivers/pcktgal.c
r2724r2725
1313***************************************************************************/
1414
1515#include "driver.h"
16#include "deprecat.h"
1716#include "cpu/m6502/m6502.h"
1817#include "sound/2203intf.h"
1918#include "sound/3812intf.h"
r2724r2725
5251
5352static int msm5205next;
5453
55static void pcktgal_adpcm_int(int data)
54static void pcktgal_adpcm_int(running_machine *machine, int data)
5655{
5756   static int toggle;
5857
r2724r2725
6160
6261   toggle = 1 - toggle;
6362   if (toggle)
64      cpunum_set_input_line(Machine, 1,M6502_IRQ_LINE,HOLD_LINE);
63      cpunum_set_input_line(machine, 1,M6502_IRQ_LINE,HOLD_LINE);
6564}
6665
6766static WRITE8_HANDLER( pcktgal_adpcm_data_w )
src/mame/drivers/hng64.c
r2724r2725
565565
566566static READ32_HANDLER( hng64_random_read )
567567{
568   return mame_rand(Machine)&0xffffffff;
568   return mame_rand(machine)&0xffffffff;
569569}
570570
571571
r2724r2725
620620   a = ((paletteram32[offset] & 0xff000000) >>24);
621621
622622   // a sure ain't alpha.
623   // alpha_set_level(mame_rand(Machine)) ;
623   // alpha_set_level(mame_rand(machine)) ;
624624   // mame_printf_debug("Alpha : %d %d %d %d\n", a, b, g, r) ;
625625
626626   //if (a != 0)
r2724r2725
638638
639639   if(offset==0x85b) return 0x00000010;
640640
641   return mame_rand(Machine)&0xffffffff;
641   return mame_rand(machine)&0xffffffff;
642642}
643643
644644
r2724r2725
740740      case 0x600: return no_machine_error_code;
741741   }
742742
743   return mame_rand(Machine)&0xffffffff;
743   return mame_rand(machine)&0xffffffff;
744744   //return hng64_dualport[offset];
745745}
746746
src/mame/drivers/macrossp.c
r2724r2725
3838******************************************************************************/
3939
4040#include "driver.h"
41#include "deprecat.h"
4241#include "sound/es5506.h"
4342
4443/*** README INFO **************************************************************
r2724r2725
511510
512511/*** MACHINE DRIVER **********************************************************/
513512
514static void irqhandler(int irq)
513static void irqhandler(running_machine *machine, int irq)
515514{
516515   logerror("ES5506 irq %d\n",irq);
517516
518517   /* IRQ lines 1 & 4 on the sound 68000 are definitely triggered by the ES5506,
519518    but I haven't noticed the ES5506 ever assert the line - maybe only used when developing the game? */
520//  cpunum_set_input_line(Machine, 1,1,irq ? ASSERT_LINE : CLEAR_LINE);
519//  cpunum_set_input_line(machine, 1,1,irq ? ASSERT_LINE : CLEAR_LINE);
521520}
522521
523522static const struct ES5506interface es5506_interface =
src/mame/drivers/gladiatr.c
r2724r2725
182182***************************************************************************/
183183
184184#include "driver.h"
185#include "deprecat.h"
186185#include "machine/tait8741.h"
187186#include "cpu/z80/z80.h"
188187#include "sound/2203intf.h"
r2724r2725
288287   /* bit 0   : ??                    */
289288}
290289/* YM2203 IRQ */
291static void gladiator_ym_irq(int irq)
290static void gladiator_ym_irq(running_machine *machine, int irq)
292291{
293292   /* NMI IRQ is not used by gladiator sound program */
294   cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, irq ? ASSERT_LINE : CLEAR_LINE);
293   cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, irq ? ASSERT_LINE : CLEAR_LINE);
295294}
296295
297296/*Sound Functions*/
r2724r2725
362361
363362static WRITE8_HANDLER(qx3_w){ }
364363
365static READ8_HANDLER(qx2_r){ return mame_rand(Machine); }
364static READ8_HANDLER(qx2_r){ return mame_rand(machine); }
366365
367static READ8_HANDLER(qx3_r){ return mame_rand(Machine)&0xf; }
366static READ8_HANDLER(qx3_r){ return mame_rand(machine)&0xf; }
368367
369368static READ8_HANDLER(qx0_r)
370369{
r2724r2725
651650
652651static READ8_HANDLER(f1_r)
653652{
654   return mame_rand(Machine);
653   return mame_rand(machine);
655654}
656655
657656static const struct YM2203interface ppking_ym2203_interface =
src/mame/drivers/stepstag.c
r2724r2725
88 */
99
1010#include "driver.h"
11#include "deprecat.h"
1211
1312static READ16_HANDLER( unknown_read_0xc00000 )
1413{
15   return mame_rand(Machine);
14   return mame_rand(machine);
1615}
1716
1817static READ16_HANDLER( unknown_read_0xd00000 )
1918{
20   return mame_rand(Machine);
19   return mame_rand(machine);
2120}
2221
2322static READ16_HANDLER( unknown_read_0xffff00 )
2423{
25   return mame_rand(Machine);
24   return mame_rand(machine);
2625}
2726
2827static ADDRESS_MAP_START( stepstag_readmem, ADDRESS_SPACE_PROGRAM, 16 )
r2724r2725
7170
7271static READ16_HANDLER( unknown_sub_read_0xbe0004 )
7372{
74   return mame_rand(Machine);
73   return mame_rand(machine);
7574}
7675
7776
src/mame/drivers/taito_l.c
r2724r2725
577577
578578static int adpcm_pos;
579579
580static void champwr_msm5205_vck(int chip)
580static void champwr_msm5205_vck(running_machine *machine, int chip)
581581{
582582   static int adpcm_data = -1;
583583
r2724r2725
22462246
22472247
22482248
2249static void irqhandler(int irq)
2249static void irqhandler(running_machine *machine, int irq)
22502250{
2251   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
2251   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
22522252}
22532253
22542254static WRITE8_HANDLER( portA_w )
src/mame/drivers/cabal.c
r2724r2725
4141******************************************************************/
4242
4343#include "driver.h"
44#include "deprecat.h"
4544#include "cpu/z80/z80.h"
4645#include "audio/seibu.h"
4746#include "sound/2151intf.h"
r2724r2725
513512GFXDECODE_END
514513
515514
516static void irqhandler(int irq)
515static void irqhandler(running_machine *machine, int irq)
517516{
518   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
517   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
519518}
520519
521520static const struct YM2151interface cabalbl_ym2151_interface =
src/mame/drivers/m92.c
r2724r2725
932932
933933/***************************************************************************/
934934
935static void sound_irq(int state)
935static void sound_irq(running_machine *machine, int state)
936936{
937937   if (state)
938938      timer_call_after_resynch(NULL, YM2151_ASSERT, setvector_callback);
src/mame/drivers/fcombat.c
r2724r2725
6161static INPUT_CHANGED( coin_inserted )
6262{
6363   /* coin insertion causes an NMI */
64   cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, newval ? CLEAR_LINE : ASSERT_LINE);
64   cpunum_set_input_line(field->port->machine, 0, INPUT_LINE_NMI, newval ? CLEAR_LINE : ASSERT_LINE);
6565}
6666
6767
src/mame/drivers/segas16b.c
r2724r2725
10541054   disable_screen_blanking = 0;
10551055
10561056   /* see if we have a sound CPU and a UPD7759 chip */
1057   has_sound_cpu = (mame_find_cpu_index(Machine, "sound") != -1);
1057   has_sound_cpu = (mame_find_cpu_index(machine, "sound") != -1);
10581058}
10591059
10601060
src/mame/drivers/wwfwfest.c
r2724r2725
364364 Straight from Ddragon 3 with some adjusted volumes
365365*******************************************************************************/
366366
367static void dd3_ymirq_handler(int irq)
367static void dd3_ymirq_handler(running_machine *machine, int irq)
368368{
369   cpunum_set_input_line(Machine, 1, 0 , irq ? ASSERT_LINE : CLEAR_LINE );
369   cpunum_set_input_line(machine, 1, 0 , irq ? ASSERT_LINE : CLEAR_LINE );
370370}
371371
372372static const struct YM2151interface ym2151_interface =
src/mame/drivers/fuukifg2.c
r2724r2725
3333***************************************************************************/
3434
3535#include "driver.h"
36#include "deprecat.h"
3736#include "sound/2203intf.h"
3837#include "sound/3812intf.h"
3938#include "sound/okim6295.h"
r2724r2725
500499
501500***************************************************************************/
502501
503static void soundirq(int state)
502static void soundirq(running_machine *machine, int state)
504503{
505   cpunum_set_input_line(Machine, 1, 0, state);
504   cpunum_set_input_line(machine, 1, 0, state);
506505}
507506
508507static const struct YM3812interface fuuki16_ym3812_intf =
src/mame/drivers/nwk-tr.c
r2724r2725
521521
522522
523523
524static void voodoo_vblank_0(int param)
524static void voodoo_vblank_0(running_machine *machine, int param)
525525{
526   cpunum_set_input_line(Machine, 0, INPUT_LINE_IRQ0, ASSERT_LINE);
526   cpunum_set_input_line(machine, 0, INPUT_LINE_IRQ0, ASSERT_LINE);
527527}
528528
529529static VIDEO_START( nwktr )
r2724r2725
962962   //jamma_jvs_cmd_exec();
963963}
964964
965static void sound_irq_callback(int irq)
965static void sound_irq_callback(running_machine *machine, int irq)
966966{
967967   if (irq == 0)
968      cpunum_set_input_line(Machine, 1, INPUT_LINE_IRQ1, PULSE_LINE);
968      cpunum_set_input_line(machine, 1, INPUT_LINE_IRQ1, PULSE_LINE);
969969   else
970      cpunum_set_input_line(Machine, 1, INPUT_LINE_IRQ2, PULSE_LINE);
970      cpunum_set_input_line(machine, 1, INPUT_LINE_IRQ2, PULSE_LINE);
971971}
972972
973973static DRIVER_INIT( nwktr )
src/mame/drivers/zac2650.c
r2724r2725
217217   PORT_DIPSETTING(    0x80, DEF_STR( On ) )
218218
219219   PORT_START_TAG("1E86")
220   PORT_BIT(    0x01, 0x01, IPT_DIPSWITCH_NAME ) PORT_NAME("Collision Detection (Cheat)")
220   PORT_DIPNAME( 0x01, 0x01, "Collision Detection (Cheat)" )
221221   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
222222   PORT_DIPSETTING(    0x01, DEF_STR( On ) )
223223
src/mame/drivers/shangha3.c
r2724r2725
2020***************************************************************************/
2121
2222#include "driver.h"
23#include "deprecat.h"
2423#include "cpu/z80/z80.h"
2524#include "sound/ay8910.h"
2625#include "sound/okim6295.h"
r2724r2725
487486   NULL
488487};
489488
490static void irqhandler(int linestate)
489static void irqhandler(running_machine *machine, int linestate)
491490{
492   cpunum_set_input_line(Machine, 1, INPUT_LINE_NMI, linestate);
491   cpunum_set_input_line(machine, 1, INPUT_LINE_NMI, linestate);
493492}
494493
495494static const struct YM3438interface ym3438_interface =
src/mame/drivers/pkscram.c
r2724r2725
1212*/
1313
1414#include "driver.h"
15#include "deprecat.h"
1615#include "sound/2203intf.h"
1716
1817static int interrupt_scanline=192;
r2724r2725
258257   GFXDECODE_ENTRY( REGION_GFX1, 0, tiles8x8_layout, 0, 0x80 )
259258GFXDECODE_END
260259
261static void irqhandler(int irq)
260static void irqhandler(running_machine *machine, int irq)
262261{
263262   if(out & 0x10)
264      cpunum_set_input_line(Machine, 0,2,irq ? ASSERT_LINE : CLEAR_LINE);
263      cpunum_set_input_line(machine, 0,2,irq ? ASSERT_LINE : CLEAR_LINE);
265264}
266265
267266static const struct YM2203interface ym2203_interface =
src/mame/drivers/taotaido.c
r2724r2725
6464
6565
6666#include "driver.h"
67#include "deprecat.h"
6867#include "sound/2610intf.h"
6968
7069#define TAOTAIDO_SHOW_ALL_INPUTS   0
r2724r2725
319318   GFXDECODE_ENTRY( REGION_GFX2, 0, taotaido_layout,  0x300, 256  ) /* bg tiles */
320319GFXDECODE_END
321320
322static void irqhandler(int irq)
321static void irqhandler(running_machine *machine, int irq)
323322{
324   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
323   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
325324}
326325
327326static const struct YM2610interface ym2610_interface =
src/mame/drivers/fortecar.c
r2724r2725
1919
2020
2121#include "driver.h"
22#include "deprecat.h"
2322
2423static UINT8 *fortecar_ram;
2524
r2724r2725
3433#ifdef UNUSED_FUNCTION
3534READ8_HANDLER( fortecar_read62 )
3635{
37   return mame_rand(Machine);
36   return mame_rand(machine);
3837}
3938#endif
4039
src/mame/drivers/gunpey.c
r2724r2725
4646*/
4747
4848#include "driver.h"
49#include "deprecat.h"
5049
5150static UINT16 *unkram;
5251static UINT16 *mainram;
r2724r2725
7372   // 40,41,44 = ?
7473   // 4a = flags?
7574      if(offset==0xc9/2 )//|| offset==0x40 || offset==0x41 || offset==0x44)
76         return mame_rand(Machine);
75         return mame_rand(machine);
7776   return unkram[offset];
7877}
7978
src/mame/drivers/guab.c
r2724r2725
5959 *
6060 *************************************/
6161
62static void ptm_irq(int state)
62static void ptm_irq(running_machine *machine, int state)
6363{
64   cpunum_set_input_line(Machine, 0, INT_6840PTM, state);
64   cpunum_set_input_line(machine, 0, INT_6840PTM, state);
6565}
6666
6767static const ptm6840_interface ptm_intf =
src/mame/drivers/m107.c
r2724r2725
455455
456456/***************************************************************************/
457457
458static void sound_irq(int state)
458static void sound_irq(running_machine *machine, int state)
459459{
460460   if (state)
461461      timer_call_after_resynch(NULL, YM2151_ASSERT,setvector_callback);
src/mame/drivers/ninjaw.c
r2724r2725
569569**************************************************************/
570570
571571/* handler called by the YM2610 emulator when the internal timers cause an IRQ */
572static void irqhandler(int irq)
572static void irqhandler(running_machine *machine, int irq)
573573{
574   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
574   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
575575}
576576
577577static const struct YM2610interface ym2610_interface =
src/mame/drivers/matmania.c
r2724r2725
391391
392392
393393/* handler called by the 3526 emulator when the internal timers cause an IRQ */
394static void irqhandler(int linestate)
394static void irqhandler(running_machine *machine, int linestate)
395395{
396   cpunum_set_input_line(Machine, 1,1,linestate);
396   cpunum_set_input_line(machine, 1,1,linestate);
397397}
398398
399399static const struct YM3526interface ym3526_interface =
src/mame/drivers/megasys1.c
r2724r2725
456456*/
457457
458458/* YM2151 IRQ */
459static void megasys1_sound_irq(int irq)
459static void megasys1_sound_irq(running_machine *machine, int irq)
460460{
461461   if (irq)
462      cpunum_set_input_line(Machine, 1, 4, HOLD_LINE);
462      cpunum_set_input_line(machine, 1, 4, HOLD_LINE);
463463}
464464
465465static READ16_HANDLER( oki_status_0_r )
r2724r2725
787787***************************************************************************/
788788
789789
790static void irq_handler(int irq)
790static void irq_handler(running_machine *machine, int irq)
791791{
792   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
792   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
793793}
794794
795795
src/mame/drivers/crshrace.c
r2724r2725
124124***************************************************************************/
125125
126126#include "driver.h"
127#include "deprecat.h"
128127#include "video/konamiic.h"
129128#include "sound/2610intf.h"
130129#include "crshrace.h"
r2724r2725
606605
607606
608607
609static void irqhandler(int irq)
608static void irqhandler(running_machine *machine, int irq)
610609{
611   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
610   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
612611}
613612
614613static const struct YM2610interface ym2610_interface =
src/mame/drivers/airbustr.c
r2724r2725
266266      /* Reading eff4, F0 times must yield at most 80-1 consecutive
267267           equal values */
268268      case 0xff4:
269         return mame_rand(Machine);
269         return mame_rand(machine);
270270
271271      default:
272272         return devram[offset];
src/mame/drivers/pacman.c
r2724r2725
402402   /* and that the speedup button is pressed */
403403   else
404404   {
405      int portnum = port_tag_to_index("FAKE");
406      if (portnum != -1)
407      {
408         UINT8 value = input_port_read_indexed(machine, portnum);
409         if ((value & 7) == 5 || (value & 6) == 2)
410            irq0_line_hold(machine, cpunum);
411      }
405      UINT8 value = input_port_read_safe(machine, "FAKE", 0);
406      if ((value & 7) == 5 || (value & 6) == 2)
407         irq0_line_hold(machine, cpunum);
412408   }
413409}
414410
r2724r2725
534530{
535531   /* The return value determines what the mystery item is.  Each bit corresponds
536532       to a question mark */
537   return mame_rand(Machine) & 0x0f;
533   return mame_rand(machine) & 0x0f;
538534}
539535
540536
r2724r2725
12851281   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_4WAY
12861282   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY
12871283   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY
1288   PORT_BIT(    0x10, 0x10, IPT_DIPSWITCH_NAME ) PORT_NAME("Rack Test (Cheat)") PORT_CODE(KEYCODE_F1)
1284   PORT_DIPNAME( 0x10, 0x10, "Rack Test (Cheat)" ) PORT_CODE(KEYCODE_F1)
12891285   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
12901286   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
12911287   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_COIN1 )
r2724r2725
13461342   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_4WAY
13471343   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY
13481344   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY
1349   PORT_BIT(    0x10, 0x10, IPT_DIPSWITCH_NAME ) PORT_NAME("Rack Test (Cheat)") PORT_CODE(KEYCODE_F1)
1345   PORT_DIPNAME( 0x10, 0x10, "Rack Test (Cheat)" ) PORT_CODE(KEYCODE_F1)
13501346   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
13511347   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
13521348   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_COIN1 )
r2724r2725
13971393   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_4WAY
13981394   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY
13991395   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY
1400   PORT_BIT(    0x10, 0x10, IPT_DIPSWITCH_NAME ) PORT_NAME("Rack Test (Cheat)") PORT_CODE(KEYCODE_F1)
1396   PORT_DIPNAME( 0x10, 0x10, "Rack Test (Cheat)" ) PORT_CODE(KEYCODE_F1)
14011397   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
14021398   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
14031399   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_COIN1 )
r2724r2725
20652061   PORT_DIPNAME( 0x01, 0x00, DEF_STR( Unknown ) )
20662062   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
20672063   PORT_DIPSETTING(    0x01, DEF_STR( On ) )
2068   PORT_BIT(    0x02, 0x00, IPT_DIPSWITCH_NAME ) PORT_NAME("Invulnerability (Cheat)") PORT_CODE(KEYCODE_F1)
2064   PORT_DIPNAME( 0x02, 0x00, "Invulnerability (Cheat)" ) PORT_CODE(KEYCODE_F1)
20692065   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
20702066   PORT_DIPSETTING(    0x02, DEF_STR( On ) )
20712067   PORT_DIPNAME( 0x04, 0x00, DEF_STR( Unknown ) )
r2724r2725
21392135   PORT_DIPNAME( 0x01, 0x00, DEF_STR( Unknown ) )
21402136   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
21412137   PORT_DIPSETTING(    0x01, DEF_STR( On ) )
2142   PORT_BIT(    0x02, 0x00, IPT_DIPSWITCH_NAME ) PORT_NAME("Invulnerability (Cheat)") PORT_CODE(KEYCODE_F1)
2138   PORT_DIPNAME( 0x02, 0x00, "Invulnerability (Cheat)" ) PORT_CODE(KEYCODE_F1)
21432139   PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
21442140   PORT_DIPSETTING(    0x02, DEF_STR( On ) )
21452141   PORT_DIPNAME( 0x04, 0x00, DEF_STR( Unknown ) )
r2724r2725
22262222   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_4WAY
22272223   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY
22282224   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY
2229   PORT_BIT(0x10, 0x10, IPT_DIPSWITCH_NAME ) PORT_NAME("Rack Test (Cheat)") PORT_CODE(KEYCODE_F1)
2230   PORT_DIPSETTING(0x10, DEF_STR( Off ) )
2231   PORT_DIPSETTING(0x00, DEF_STR( On ) )
2225   PORT_DIPNAME( 0x10, 0x10, "Rack Test (Cheat)" ) PORT_CODE(KEYCODE_F1)
2226   PORT_DIPSETTING( 0x10, DEF_STR( Off ) )
2227   PORT_DIPSETTING( 0x00, DEF_STR( On ) )
22322228   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_COIN1 )
22332229   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON1 )
22342230   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN2 )
r2724r2725
25532549   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_4WAY
25542550   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY
25552551   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY
2556   PORT_BIT(    0x10, 0x10, IPT_DIPSWITCH_NAME ) PORT_NAME("Rack Test (Cheat)") PORT_CODE(KEYCODE_F1)
2552   PORT_DIPNAME( 0x10, 0x10, "Rack Test (Cheat)" ) PORT_CODE(KEYCODE_F1)
25572553   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
25582554   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
25592555   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_COIN1 )
r2724r2725
26062602   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_4WAY
26072603   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY
26082604   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY
2609   PORT_BIT(    0x10, 0x10, IPT_DIPSWITCH_NAME ) PORT_NAME("Rack Test (Cheat)") PORT_CODE(KEYCODE_F1)
2605   PORT_DIPNAME( 0x10, 0x10, "Rack Test (Cheat)" ) PORT_CODE(KEYCODE_F1)
26102606   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
26112607   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
26122608   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_COIN1 )
src/mame/drivers/dcheese.c
r2724r2725
5959 *
6060 *************************************/
6161
62static void update_irq_state(void)
62static void update_irq_state(running_machine *machine)
6363{
6464   int i;
6565
r2724r2725
6767   for (i = 4; i >= 0; i--)
6868      if (irq_state[i])
6969      {
70         cpunum_set_input_line(Machine, 0, i, ASSERT_LINE);
70         cpunum_set_input_line(machine, 0, i, ASSERT_LINE);
7171         return;
7272      }
7373
7474   /* otherwise, clear them all */
75   cpunum_set_input_line(Machine, 0, 7, CLEAR_LINE);
75   cpunum_set_input_line(machine, 0, 7, CLEAR_LINE);
7676}
7777
7878
r2724r2725
8080{
8181   /* auto-ack the IRQ */
8282   irq_state[irqline] = 0;
83   update_irq_state();
83   update_irq_state(machine);
8484
8585   /* vector is 0x40 + index */
8686   return 0x40 + irqline;
r2724r2725
9090void dcheese_signal_irq(int which)
9191{
9292   irq_state[which] = 1;
93   update_irq_state();
93   update_irq_state(Machine);
9494}
9595
9696
src/mame/drivers/chqflag.c
r2724r2725
318318
319319
320320
321static void chqflag_ym2151_irq_w(int data)
321static void chqflag_ym2151_irq_w(running_machine *machine, int data)
322322{
323   cpunum_set_input_line(Machine, 1,INPUT_LINE_NMI,PULSE_LINE);
323   cpunum_set_input_line(machine, 1,INPUT_LINE_NMI,PULSE_LINE);
324324}
325325
326326
src/mame/drivers/bwing.c
r2724r2725
9898
9999static WRITE8_HANDLER( bwp12_sharedram1_w ) { bwp1_sharedram1[offset] = bwp2_sharedram1[offset] = data; }
100100static WRITE8_HANDLER( bwp3_u8F_w ) { bwp3_u8F_d = data; } // prepares custom chip for various operations
101static WRITE8_HANDLER( bwp3_nmiack_w ) { cpunum_set_input_line(Machine, 2, INPUT_LINE_NMI, CLEAR_LINE); }
101static WRITE8_HANDLER( bwp3_nmiack_w ) { cpunum_set_input_line(machine, 2, INPUT_LINE_NMI, CLEAR_LINE); }
102102static WRITE8_HANDLER( bwp3_nmimask_w ) { bwp3_nmimask = data & 0x80; }
103103
104104
src/mame/drivers/sf.c
r2724r2725
1010***************************************************************************/
1111
1212#include "driver.h"
13#include "deprecat.h"
1413#include "cpu/z80/z80.h"
1514#include "cpu/m68000/m68000.h"
1615#include "sound/2151intf.h"
r2724r2725
799798
800799
801800
802static void irq_handler(int irq)
801static void irq_handler(running_machine *machine, int irq)
803802{
804   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
803   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
805804}
806805
807806static const struct YM2151interface ym2151_interface =
src/mame/drivers/lsasquad.c
r2724r2725
147147***************************************************************************/
148148
149149#include "driver.h"
150#include "deprecat.h"
151150#include "cpu/m6805/m6805.h"
152151#include "sound/ay8910.h"
153152#include "sound/2203intf.h"
r2724r2725
565564
566565
567566
568static void irqhandler(int irq)
567static void irqhandler(running_machine *machine, int irq)
569568{
570   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
569   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
571570}
572571
573572static WRITE8_HANDLER( unk )
src/mame/drivers/cave.c
r2724r2725
6969***************************************************************************/
7070
7171#include "driver.h"
72#include "deprecat.h"
7372#include "machine/eeprom.h"
7473#include "machine/nmk112.h"
7574#include "cpu/z80/z80.h"
r2724r2725
129128}
130129
131130/* Called by the YMZ280B to set the IRQ state */
132static void sound_irq_gen(int state)
131static void sound_irq_gen(running_machine *machine, int state)
133132{
134133   sound_irq = (state != 0);
135   update_irq_state(Machine);
134   update_irq_state(machine);
136135}
137136
138137
r2724r2725
162161   if (offset == 4/2)   vblank_irq = 0;
163162   if (offset == 6/2)   unknown_irq = 0;
164163
165   update_irq_state(Machine);
164   update_irq_state(machine);
166165
167166/*
168167    sailormn and agallet wait for bit 2 of $b80001 to go 1 -> 0.
r2724r2725
19931992   sound_irq_gen
19941993};
19951994
1996static void irqhandler(int irq)
1995static void irqhandler(running_machine *machine, int irq)
19971996{
1998   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
1997   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
19991998}
20001999
20012000static const struct YM2151interface ym2151_interface =
src/mame/drivers/dooyong.c
r2724r2725
898898   GFXDECODE_ENTRY( REGION_GFX2, 0, popbingo_tilelayout, 256,  1 )
899899GFXDECODE_END
900900
901static void irqhandler(int irq)
901static void irqhandler(running_machine *machine, int irq)
902902{
903   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
903   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
904904}
905905
906906static READ8_HANDLER( unk_r )
src/mame/drivers/brkthru.c
r2724r2725
4646***************************************************************************/
4747
4848#include "driver.h"
49#include "deprecat.h"
5049#include "cpu/m6809/m6809.h"
5150#include "sound/2203intf.h"
5251#include "sound/3812intf.h"
r2724r2725
9291static INPUT_CHANGED( coin_inserted )
9392{
9493   /* coin insertion causes an IRQ */
95   cpunum_set_input_line(machine, 0, 0, newval ? CLEAR_LINE : ASSERT_LINE);
94   cpunum_set_input_line(field->port->machine, 0, 0, newval ? CLEAR_LINE : ASSERT_LINE);
9695}
9796
9897
r2724r2725
374373GFXDECODE_END
375374
376375/* handler called by the 3812 emulator when the internal timers cause an IRQ */
377static void irqhandler(int linestate)
376static void irqhandler(running_machine *machine, int linestate)
378377{
379   cpunum_set_input_line(Machine, 1,M6809_IRQ_LINE,linestate);
378   cpunum_set_input_line(machine, 1,M6809_IRQ_LINE,linestate);
380379}
381380
382381static const struct YM3526interface ym3526_interface =
src/mame/drivers/fuukifg3.c
r2724r2725
158158
159159
160160#include "driver.h"
161#include "deprecat.h"
162161#include "sound/262intf.h"
163162#include "sound/ymf278b.h"
164163
r2724r2725
586585}
587586
588587
589static void irqhandler(int irq)
588static void irqhandler(running_machine *machine, int irq)
590589{
591   cpunum_set_input_line(Machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
590   cpunum_set_input_line(machine, 1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
592591}
593592
594593static const struct YMF278B_interface ymf278b_interface =
src/mame/drivers/dec8.c
r2724r2725
3838***************************************************************************/
3939
4040#include "driver.h"
41#include "deprecat.h"
4241#include "cpu/m6809/m6809.h"
4342#include "cpu/m6502/m6502.h"
4443#include "sound/2203intf.h"
r2724r2725
436435   cpunum_set_input_line(machine, 2,INPUT_LINE_NMI,PULSE_LINE);
437436}
438437
439static void csilver_adpcm_int(int data)
438static void csilver_adpcm_int(running_machine *machine, int data)
440439{
441440   static int toggle =0;
442441
443442   toggle ^= 1;
444443   if (toggle)
445      cpunum_set_input_line(Machine, 2,M6502_IRQ_LINE,HOLD_LINE);
444      cpunum_set_input_line(machine, 2,M6502_IRQ_LINE,HOLD_LINE);
446445
447446   MSM5205_data_w (0,msm5205next>>4);
448447   msm5205next<<=4;
r2724r2725
20102009/******************************************************************************/
20112010
20122011/* handler called by the 3812 emulator when the internal timers cause an IRQ */
2013static void irqhandler(int linestate)
2012static void irqhandler(running_machine *machine, int linestate)
20142013{
2015   cpunum_set_input_line(Machine, 1,0,linestate); /* M6502_IRQ_LINE */
2014   cpunum_set_input_line(machine, 1,0,linestate); /* M6502_IRQ_LINE */
20162015}
20172016
2018static void oscar_irqhandler(int linestate)
2017static void oscar_irqhandler(running_machine *machine, int linestate)
20192018{
2020   cpunum_set_input_line(Machine, 2,0,linestate); /* M6502_IRQ_LINE */
2019   cpunum_set_input_line(machine, 2,0,linestate); /* M6502_IRQ_LINE */
20212020}
20222021
20232022static const struct YM3526interface ym3526_interface =
src/mame/drivers/tbowl.c
r2724r2725
1313***/
1414
1515#include "driver.h"
16#include "deprecat.h"
1716#include "cpu/z80/z80.h"
1817#include "sound/3812intf.h"
1918#include "sound/msm5205.h"
r2724r2725
197196   MSM5205_set_volume(offset & 1, (data & 0x7f) * 100 / 0x7f);
198197}
199198
200static void tbowl_adpcm_int(int num)
199static void tbowl_adpcm_int(running_machine *machine, int num)
201200{
202201   static int adpcm_data[2] = { -1, -1 };
203202
r2724r2725
556555
557556*/
558557
559static void irqhandler(int linestate)
558static void irqhandler(running_machine *machine, int linestate)
560559{
561   cpunum_set_input_line(Machine, 2,0,linestate);
560   cpunum_set_input_line(machine, 2,0,linestate);
562561}
563562
564563static const struct YM3526interface ym3812_interface =
src/mame/drivers/battlane.c
r2724r2725
1010***************************************************************************/
1111
1212#include "driver.h"
13#include "deprecat.h"
1413#include "cpu/m6809/m6809.h"
1514#include "sound/3812intf.h"
1615
r2724r2725
242241GFXDECODE_END
243242
244243
245static void irqhandler(int irq)
244static void irqhandler(running_machine *machine, int irq)
246245{
247   cpunum_set_input_line(Machine, 0, M6809_FIRQ_LINE, irq ? ASSERT_LINE : CLEAR_LINE);
246   cpunum_set_input_line(machine, 0, M6809_FIRQ_LINE, irq ? ASSERT_LINE : CLEAR_LINE);
248247}
249248
250249static const struct YM3526interface ym3526_interface =
src/mame/drivers/atarigt.c
r2724r2725
1919
2020
2121#include "driver.h"
22#include "deprecat.h"
2322#include "machine/atarigen.h"
2423#include "video/atarirle.h"
2524#include "cpu/m68000/m68000.h"
r2724r2725
4544static void (*protection_w)(offs_t offset, UINT16 data);
4645static void (*protection_r)(offs_t offset, UINT16 *data);
4746
48static void cage_irq_callback(int reason);
47static void cage_irq_callback(running_machine *machine, int reason);
4948
5049
5150
r2724r2725
8887 *
8988 *************************************/
9089
91static void cage_irq_callback(int reason)
90static void cage_irq_callback(running_machine *machine, int reason)
9291{
9392   if (reason)
94      atarigen_sound_int_gen(Machine, 0);
93      atarigen_sound_int_gen(machine, 0);
9594   else
96      atarigen_sound_int_ack_w(Machine,0,0,0xffff);
95      atarigen_sound_int_ack_w(machine,0,0,0xffff);
9796}
9897
9998
src/mame/drivers/rbmk.c
r2724r2725
5656*/
5757
5858#include "driver.h"
59#include "deprecat.h"
6059#include "sound/okim6295.h"
6160#include "machine/eeprom.h"
6261
r2724r2725
6766
6867static READ16_HANDLER( gms_read )
6968{
70   return mame_rand(Machine);
69   return mame_rand(machine);
7170}
7271
7372
src/mame/drivers/bigfghtr.c
r2724r2725
312312            if(read_latch)
313313            {
314314               read_latch=0;
315               return mame_rand(Machine);
315               return mame_rand(machine);
316316            }
317317         break;
318318
src/mame/drivers/genesis.c
r2724r2725
1212*/
1313
1414#include "driver.h"
15#include "deprecat.h"
1615#include "genesis.h"
1716
1817#define MASTER_CLOCK      53693100
r2724r2725
140139
141140
142141/* interrupt callback to generate the YM3438 interrupt */
143void genesis_irq2_interrupt(int state)
142void genesis_irq2_interrupt(running_machine *machine, int state)
144143{
145144   irq2_int = state;
146   update_interrupts(Machine);
145   update_interrupts(machine);
147146}
148147
149148
src/mame/drivers/cloud9.c
r2724r2725
154154
155155static CUSTOM_INPUT( get_vblank )
156156{
157   int scanline = video_screen_get_vpos(machine->primary_screen);
157   int scanline = video_screen_get_vpos(field->port->machine->primary_screen);
158158   return (~syncprom[scanline & 0xff] >> 1) & 1;
159159}
160160
src/mame/drivers/rpunch.c
r2724r2725
105105
106106
107107#include "driver.h"
108#include "deprecat.h"
109108#include "cpu/m6809/m6809.h"
110109#include "sound/2151intf.h"
111110#include "sound/upd7759.h"
r2724r2725
143142 *
144143 *************************************/
145144
146static void ym2151_irq_gen(int state)
145static void ym2151_irq_gen(running_machine *machine, int state)
147146{
148147   ym2151_irq = state;
149   cpunum_set_input_line(Machine, 1, 0, (ym2151_irq | sound_busy) ? ASSERT_LINE : CLEAR_LINE);
148   cpunum_set_input_line(machine, 1, 0, (ym2151_irq | sound_busy) ? ASSERT_LINE : CLEAR_LINE);
150149}
151150
152151
src/mame/drivers/rabbit.c
r2724r2725
498498
499499static READ32_HANDLER( randomrabbits )
500500{
501   return mame_rand(Machine);
501   return mame_rand(machine);
502502}
503503
504504static ADDRESS_MAP_START( rabbit_readmem, ADDRESS_SPACE_PROGRAM, 32 )
src/mame/drivers/asuka.c
r2724r2725
213213***************************************************************************/
214214
215215#include "driver.h"
216#include "deprecat.h"
217216#include "taitoipt.h"
218217#include "video/taitoic.h"
219218#include "audio/taitosnd.h"
r2724r2725
268267
269268static int adpcm_pos;
270269
271static void asuka_msm5205_vck(int chip)
270static void asuka_msm5205_vck(running_machine *machine, int chip)
272271{
273272   static int adpcm_data = -1;
274273
r2724r2725
754753                SOUND
755754**************************************************************/
756755
757static void irq_handler(int irq)
756static void irq_handler(running_machine *machine, int irq)
758757{
759   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
758   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
760759}
761760
762761static const struct YM2610interface ym2610_interface =
src/mame/drivers/triplhnt.c
r2724r2725
197197   PORT_START /* 0C48 */
198198// default to service enabled to make users calibrate gun
199199//  PORT_SERVICE( 0x40, IP_ACTIVE_LOW )
200   PORT_BIT(    0x40, 0x00, IPT_DIPSWITCH_NAME ) PORT_NAME( DEF_STR( Service_Mode )) PORT_TOGGLE PORT_CODE(KEYCODE_F2)
200   PORT_DIPNAME( 0x40, 0x00, DEF_STR( Service_Mode )) PORT_TOGGLE PORT_CODE(KEYCODE_F2)
201201   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
202202   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
203203   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 )
src/mame/drivers/backfire.c
r2724r2725
1414extern void decrypt156(void);
1515
1616#include "driver.h"
17#include "deprecat.h"
1817#include "decocrpt.h"
1918#include "deco32.h"
2019#include "machine/eeprom.h"
r2724r2725
230229static READ32_HANDLER(backfire_eeprom_r)
231230{
232231   /* some kind of screen indicator?  checked by backfira set before it will boot */
233   int backfire_screen = mame_rand(Machine)&1;
232   int backfire_screen = mame_rand(machine)&1;
234233   return ((EEPROM_read_bit()<<24) | input_port_read_indexed(machine, 0) | (input_port_read_indexed(machine, 3)<<16)) ^  (backfire_screen << 26) ;
235234}
236235
r2724r2725
311310
312311READ32_HANDLER( backfire_wheel1_r )
313312{
314   return mame_rand(Machine);
313   return mame_rand(machine);
315314}
316315
317316READ32_HANDLER( backfire_wheel2_r )
318317{
319   return mame_rand(Machine);
318   return mame_rand(machine);
320319}
321320#endif
322321
r2724r2725
465464GFXDECODE_END
466465
467466
468static void sound_irq_gen(int state)
467static void sound_irq_gen(running_machine *machine, int state)
469468{
470469   logerror("sound irq\n");
471470}
src/mame/drivers/sidepckt.c
r2724r2725
1414***************************************************************************/
1515
1616#include "driver.h"
17#include "deprecat.h"
1817#include "cpu/m6809/m6809.h"
1918#include "cpu/m6502/m6502.h"
2019#include "sound/2203intf.h"
r2724r2725
278277
279278
280279/* handler called by the 3526 emulator when the internal timers cause an IRQ */
281static void irqhandler(int linestate)
280static void irqhandler(running_machine *machine, int linestate)
282281{
283   cpunum_set_input_line(Machine, 1,0,linestate);
282   cpunum_set_input_line(machine, 1,0,linestate);
284283}
285284
286285static const struct YM3526interface ym3526_interface =
src/mame/drivers/exerion.c
r2724r2725
3838static INPUT_CHANGED( coin_inserted )
3939{
4040   /* coin insertion causes an NMI */
41   cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, newval ? CLEAR_LINE : ASSERT_LINE);
41   cpunum_set_input_line(field->port->machine, 0, INPUT_LINE_NMI, newval ? CLEAR_LINE : ASSERT_LINE);
4242}
4343
4444
src/mame/drivers/wrally.c
r2724r2725
8080* 2xMS6264A-20NC (8KB SRAM) @ C8 & C9 (palette RAM (xxxxBBBBRRRRGGGG))
8181* 2x74HCT273 (octal D-Type flip-flop with clear) @ B8 & B9 (connected to RGB output)
8282
83Controls related: (added by Mirko Mattioli)
84=================
85When optical wheel is selected (via dipswitch), then gear shift (low/high) is enabled.
86On the real PCB the optical wheel encoder is connected to 74LS169 ICs (@A16 and @A17)
87via a flip-flop IC mounted in the steering wheel assembly. As a result, the output
88of the flip-flop generates a signal that contains the information about the steering
89direction; this signal is routed to pin #1 (U/D) at ICs A16 and A17 (high when turn
90left and low when turn right). The second signal of the optical encoder goes directly
91to pin #2 (CLK) at ICs A16 and A17 and it is a clock for the 74LS169 ICs; this clock
92frequency is proportional to the movements of the steering wheel: fast movements
93produces a high clock frequency, slow movements a low freq.
94
8395***************************************************************************/
8496
8597#include "driver.h"
r2724r2725
91103extern UINT16 *wrally_vregs;
92104extern UINT16 *wrally_videoram;
93105extern UINT16 *wrally_spriteram;
106static UINT16 *wrally_shareram;
94107
95108VIDEO_START( wrally );
96109VIDEO_UPDATE( wrally );
r2724r2725
123136   AM_RANGE(0x70004a, 0x70004b) AM_WRITE(SMH_NOP)                                    /* Sound muting */
124137   AM_RANGE(0x70005a, 0x70005b) AM_WRITE(wrally_flipscreen_w)                           /* Flip screen */
125138   AM_RANGE(0x70006a, 0x70007b) AM_WRITE(SMH_NOP)                                    /* ??? */
126   AM_RANGE(0xfec000, 0xfeffff) AM_RAM AM_SHARE(1)                                    /* Work RAM (shared with DS5002FP) */
139   AM_RANGE(0xfec000, 0xfeffff) AM_RAM AM_BASE(&wrally_shareram)                              /* Work RAM (shared with DS5002FP) */
127140ADDRESS_MAP_END
128141
142static READ8_HANDLER( dallas_share_r )
143{
144   UINT8 *shareram = (UINT8 *)wrally_shareram;
145
146   return shareram[BYTE_XOR_LE(offset)];
147}
148
149static WRITE8_HANDLER( dallas_share_w )
150{
151   UINT8 *shareram = (UINT8 *)wrally_shareram;
152
153   shareram[BYTE_XOR_LE(offset)] = data;
154}
155
129156static ADDRESS_MAP_START( dallas_rom, ADDRESS_SPACE_PROGRAM, 8 )
130157   AM_RANGE(0x0000, 0x7fff) AM_ROM                           /* Code in NVRAM */
131158ADDRESS_MAP_END
132159
133160static ADDRESS_MAP_START( dallas_ram, ADDRESS_SPACE_DATA, 8 )
134   AM_RANGE(0x0000, 0xffff) AM_RAM AM_SHARE(1)   AM_MASK(0x3fff)      /* Shared RAM with the main CPU */
161   AM_RANGE(0x0000, 0xffff) AM_READWRITE(dallas_share_r, dallas_share_w)   AM_MASK(0x3fff)      /* Shared RAM with the main CPU */
135162ADDRESS_MAP_END
136163
137164/* DS5002FP configuration */
r2724r2725
193220   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(1)
194221   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(1)
195222   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(1)
196   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
223   PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_NAME("Gear Shift") PORT_TOGGLE PORT_REVERSE
197224   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1)
198225   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_COIN1 )
199226   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_COIN2 )
r2724r2725
206233   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_START1 )
207234   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_START2 )
208235
209PORT_START   /* Wheel control? */
210   PORT_BIT( 0xffff, IP_ACTIVE_LOW, IPT_UNKNOWN ) /* not implemented */
236PORT_START   /* Wheel control */
237   PORT_BIT( 0xff00, 0x0000, IPT_DIAL ) PORT_SENSITIVITY(70) PORT_KEYDELTA(10) PORT_CODE_DEC(KEYCODE_RIGHT) PORT_CODE_INC(KEYCODE_LEFT) PORT_REVERSE
238   PORT_BIT( 0x00ff, IP_ACTIVE_LOW, IPT_UNKNOWN )
211239
212240PORT_START   /* INPUTS, TEST & SERVICE */
213241   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_SERVICE1 )
src/mame/drivers/crospang.c
r2724r2725
2727*/
2828
2929#include "driver.h"
30#include "deprecat.h"
3130#include "sound/okim6295.h"
3231#include "sound/3812intf.h"
3332
r2724r2725
391390GFXDECODE_END
392391
393392
394static void irqhandler(int linestate)
393static void irqhandler(running_machine *machine, int linestate)
395394{
396   cpunum_set_input_line(Machine, 1,0,linestate);
395   cpunum_set_input_line(machine, 1,0,linestate);
397396}
398397
399398static const struct YM3812interface ym3812_interface =
src/mame/drivers/nmk16.c
r2724r2725
36843684   NMK004_irq
36853685};
36863686
3687static void ym2203_irqhandler(int irq)
3687static void ym2203_irqhandler(running_machine *machine, int irq)
36883688{
3689   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
3689   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
36903690}
36913691
36923692static const struct YM2203interface ym2203_interface =
r2724r2725
50245024
50255025***************************************************************************/
50265026
5027static void irq_handler(int irq)
5027static void irq_handler(running_machine *machine, int irq)
50285028{
5029   cpunum_set_input_line(Machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
5029   cpunum_set_input_line(machine, 1,0,irq ? ASSERT_LINE : CLEAR_LINE);
50305030}
50315031
50325032static const struct YM2151interface afega_ym2151_intf =
src/mame/drivers/m10.c
r2724r2725
429429static INPUT_CHANGED( coin_inserted )
430430{
431431   /* coin insertion causes an NMI */
432   cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, newval ? ASSERT_LINE : CLEAR_LINE);
432   cpunum_set_input_line(field->port->machine, 0, INPUT_LINE_NMI, newval ? ASSERT_LINE : CLEAR_LINE);
433433}
434434
435435
src/osd/osdepend.h
r2724r2725
4040
4141#include "mamecore.h"
4242#include "osdcore.h"
43#include "inptport.h"
4344#include "timer.h"
4445
4546
r2724r2725
145146  This function is called on startup, before reading the configuration from disk.
146147  Scan the list, and change the keys/joysticks you want.
147148*/
148void osd_customize_inputport_list(input_port_default_entry *defaults);
149void osd_customize_input_type_list(input_type_desc *typelist);
149150
150151
151152
src/osd/windows/input.c
r2724r2725
699699
700700
701701//============================================================
702//  osd_customize_inputport_list
702//  osd_customize_mapping_list
703703//============================================================
704704
705void osd_customize_inputport_list(input_port_default_entry *defaults)
705void osd_customize_input_type_list(input_type_desc *typelist)
706706{
707   input_port_default_entry *idef = defaults;
707   input_type_desc *typedesc;
708708
709   // loop over all the defaults
710   for (idef = defaults; idef->type != IPT_END; idef++)
711      switch (idef->type)
709   // loop over the defaults
710   for (typedesc = typelist; typedesc != NULL; typedesc = typedesc->next)
711      switch (typedesc->type)
712712      {
713713         // disable the config menu if the ALT key is down
714714         // (allows ALT-TAB to switch between windows apps)
715715         case IPT_UI_CONFIGURE:
716            input_seq_set_5(&idef->defaultseq, KEYCODE_TAB, SEQCODE_NOT, KEYCODE_LALT, SEQCODE_NOT, KEYCODE_RALT);
716            input_seq_set_5(&typedesc->seq[SEQ_TYPE_STANDARD], KEYCODE_TAB, SEQCODE_NOT, KEYCODE_LALT, SEQCODE_NOT, KEYCODE_RALT);
717717            break;
718718
719719         // alt-enter for fullscreen
720720         case IPT_OSD_1:
721            idef->token = "TOGGLE_FULLSCREEN";
722            idef->name = "Toggle Fullscreen";
723            input_seq_set_2(&idef->defaultseq, KEYCODE_LALT, KEYCODE_ENTER);
721            typedesc->token = "TOGGLE_FULLSCREEN";
722            typedesc->name = "Toggle Fullscreen";
723            input_seq_set_2(&typedesc->seq[SEQ_TYPE_STANDARD], KEYCODE_LALT, KEYCODE_ENTER);
724724            break;
725725
726726#ifdef MESS
727727         case IPT_OSD_2:
728728            if (mess_use_new_ui())
729729            {
730               idef->token = "TOGGLE_MENUBAR";
731               idef->name = "Toggle Menubar";
732               input_seq_set_1 (&idef->defaultseq, KEYCODE_SCRLOCK);
730               typedesc->token = "TOGGLE_MENUBAR";
731               typedesc->name = "Toggle Menubar";
732               input_seq_set_1 (&typedesc->seq[SEQ_TYPE_STANDARD], KEYCODE_SCRLOCK);
733733            }
734734            break;
735735
736736         case IPT_UI_THROTTLE:
737            input_seq_set_0(&idef->defaultseq);
737            input_seq_set_0(&typedesc->seq[SEQ_TYPE_STANDARD]);
738738            break;
739739#endif /* MESS */
740740      }
src/osd/windows/debugwin.c
r2724r2725
427427   {
428428      // see if the interrupt key is pressed and break if it is
429429      temporarily_fake_that_we_are_not_visible = TRUE;
430      if (input_ui_pressed(IPT_UI_DEBUG_BREAK))
430      if (input_ui_pressed(Machine, IPT_UI_DEBUG_BREAK))
431431      {
432432         debugwin_info *info;
433433         HWND focuswnd = GetFocus();
r2724r2725
28912891   int ignoreme;
28922892
28932893   /* ignore any keys that are received while the debug key is down */
2894   ignoreme = input_ui_pressed(IPT_UI_DEBUG_BREAK);
2894   ignoreme = input_ui_pressed(Machine, IPT_UI_DEBUG_BREAK);
28952895   if (ignoreme)
28962896      return 1;
28972897
src/osd/windows/video.c
r2724r2725
7171static BOOL CALLBACK monitor_enum_callback(HMONITOR handle, HDC dc, LPRECT rect, LPARAM data);
7272static win_monitor_info *pick_monitor(int index);
7373
74static void check_osd_inputs(void);
74static void check_osd_inputs(running_machine *machine);
7575
7676static void extract_video_config(running_machine *machine);
7777static void load_effect_overlay(running_machine *machine, const char *filename);
r2724r2725
211211   // poll the joystick values here
212212   winwindow_process_events(machine, TRUE);
213213   wininput_poll(machine);
214   check_osd_inputs();
214   check_osd_inputs(machine);
215215}
216216
217217
r2724r2725
352352//  check_osd_inputs
353353//============================================================
354354
355static void check_osd_inputs(void)
355static void check_osd_inputs(running_machine *machine)
356356{
357357   // check for toggling fullscreen mode
358   if (input_ui_pressed(IPT_OSD_1))
358   if (input_ui_pressed(machine, IPT_OSD_1))
359359      winwindow_toggle_full_screen();
360360
361361#ifdef MESS
362362   // check for toggling menu bar
363   if (input_ui_pressed(IPT_OSD_2))
363   if (input_ui_pressed(machine, IPT_OSD_2))
364364      win_toggle_menubar();
365365#endif
366366}
src/osd/windows/drawd3d.c
r2724r2725
765765
766766   // set the max texture size
767767   render_target_set_max_texture_size(window->target, d3d->texture_max_width, d3d->texture_max_height);
768   mame_printf_verbose("Direct3D: Max texture size = %dx%d\n", (int)d3d->texture_max_width, (int)d3d->texture_max_height);
768769
769770   // set the gamma if we need to
770771   if (window->fullscreen)
src/osd/winui/mui_util.c
r2724r2725
356356         struct DriversInfo *gameinfo = &drivers_info[ndriver];
357357         const rom_entry *region, *rom;
358358         machine_config *config;
359         const input_port_entry *input_ports;
360359         int num_speakers;
361360
362361         /* Allocate machine config */
r2724r2725
431430         gameinfo->usesLightGun = FALSE;
432431         if (gamedrv->ipt != NULL)
433432         {
434            begin_resource_tracking();
435            input_ports = input_port_allocate(gamedrv->ipt, NULL);
436            while (1)
437            {
438               UINT32 type;
439               type = input_ports->type;
440               if (type == IPT_END)
441                  break;
442               if (type == IPT_DIAL || type == IPT_PADDLE ||
443                  type == IPT_TRACKBALL_X || type == IPT_TRACKBALL_Y ||
444                  type == IPT_AD_STICK_X || type == IPT_AD_STICK_Y)
445                  gameinfo->usesTrackball = TRUE;
446               if (type == IPT_LIGHTGUN_X || type == IPT_LIGHTGUN_Y)
447                  gameinfo->usesLightGun = TRUE;
448               input_ports++;
449            }
450            end_resource_tracking();
451433         }
452434      }
453435   }
src/emu/config.c
r2724r2725
8686 *
8787 *************************************/
8888
89void config_register(const char *nodename, config_callback_func load, config_callback_func save)
89void config_register(running_machine *machine, const char *nodename, config_callback_func load, config_callback_func save)
9090{
9191   config_type *newtype;
9292   config_type **ptype;
r2724r2725
122122
123123   /* loop over all registrants and call their init function */
124124   for (type = typelist; type; type = type->next)
125      (*type->load)(CONFIG_TYPE_INIT, NULL);
125      (*type->load)(machine, CONFIG_TYPE_INIT, NULL);
126126
127127   /* now load the controller file */
128128   if (controller[0] != 0)
r2724r2725
162162
163163   /* loop over all registrants and call their final function */
164164   for (type = typelist; type; type = type->next)
165      (*type->load)(CONFIG_TYPE_FINAL, NULL);
165      (*type->load)(machine, CONFIG_TYPE_FINAL, NULL);
166166
167167   /* if we didn't find a saved config, return 0 so the main core knows that it */
168168   /* is the first time the game is run and it should diplay the disclaimer. */
r2724r2725
179179
180180   /* loop over all registrants and call their init function */
181181   for (type = typelist; type; type = type->next)
182      (*type->save)(CONFIG_TYPE_INIT, NULL);
182      (*type->save)(machine, CONFIG_TYPE_INIT, NULL);
183183
184184   /* save the defaults file */
185185   filerr = mame_fopen(SEARCHPATH_CONFIG, "default.cfg", OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
r2724r2725
202202
203203   /* loop over all registrants and call their final function */
204204   for (type = typelist; type; type = type->next)
205      (*type->save)(CONFIG_TYPE_FINAL, NULL);
205      (*type->save)(machine, CONFIG_TYPE_FINAL, NULL);
206206}
207207
208208
r2724r2725
288288
289289      /* loop over all registrants and call their load function */
290290      for (type = typelist; type; type = type->next)
291         (*type->load)(which_type, xml_get_sibling(systemnode->child, type->name));
291         (*type->load)(machine, which_type, xml_get_sibling(systemnode->child, type->name));
292292      count++;
293293   }
294294
r2724r2725
343343      xml_data_node *curnode = xml_add_child(systemnode, type->name, NULL);
344344      if (!curnode)
345345         goto error;
346      (*type->save)(which_type, curnode);
346      (*type->save)(machine, which_type, curnode);
347347
348348      /* if nothing was added, just nuke the node */
349349      if (!curnode->value && !curnode->child)
src/emu/debug/debugcpu.c
r2724r2725
828828      if (execution_state != EXECUTION_STATE_STOPPED && ++key_check_counter > 10000)
829829      {
830830         key_check_counter = 0;
831         if (input_ui_pressed(IPT_UI_DEBUG_BREAK))
831         if (input_ui_pressed(Machine, IPT_UI_DEBUG_BREAK))
832832         {
833833            execution_state = EXECUTION_STATE_STOPPED;
834834            debug_console_printf("User-initiated break\n");
src/emu/cpu/cpu.mak
r2724r2725
11371137DBGOBJS += $(CPUOBJ)/powerpc/ppc_dasm.o
11381138
11391139ifdef X86_PPC_DRC
1140CPUOBJS += $(CPUOBJ)/powerpc/ppcdrc.o $(DRCOBJ)
1140CPUOBJS += $(CPUOBJ)/powerpc/ppcdrco.o $(DRCOBJ)
11411141else
11421142CPUOBJS += $(CPUOBJ)/powerpc/ppc.o
11431143endif
r2724r2725
11511151                     $(CPUSRC)/powerpc/ppc602.c \
11521152                     $(CPUSRC)/powerpc/ppc603.c
11531153
1154$(CPUOBJ)/powerpc/ppcdrc.o:   $(CPUSRC)/powerpc/ppcdrc.c \
1154$(CPUOBJ)/powerpc/ppcdrco.o:$(CPUSRC)/powerpc/ppcdrco.c \
11551155                     $(CPUSRC)/powerpc/ppc.h \
11561156                     $(CPUSRC)/powerpc/drc_ops.c \
11571157                     $(CPUSRC)/powerpc/drc_ops.h \
r2724r2725
13281328$(CPUOBJ)/saturn/saturn.o:   $(CPUSRC)/saturn/saturn.c \
13291329                     $(CPUSRC)/saturn/sattable.c \
13301330                     $(CPUSRC)/saturn/satops.c \
1331                     $(CPUSRC)/saturn/saturn.h \
1332                     $(CPUSRC)/saturn/sat.h
1331                     $(CPUSRC)/saturn/saturn.h
13331332
13341333
13351334
src/emu/cpu/drcfe.c
r2724r2725
217217         /* allocate a new description and describe this instruction */
218218         drcfe->desc_array[curpc - minpc] = curdesc = describe_one(drcfe, curpc);
219219
220         /* first instruction in a sequence is always a branch target */
221         if (curpc == curstack->targetpc)
222            curdesc->flags |= OPFLAG_IS_BRANCH_TARGET;
223
220224         /* stop if we hit a page fault */
221225         if (curdesc->flags & OPFLAG_COMPILER_PAGE_FAULT)
222226            break;
r2724r2725
225229         if (curpc == startpc && drcfe->pageshift != 0)
226230            curdesc->flags |= OPFLAG_VALIDATE_TLB | OPFLAG_CAN_CAUSE_EXCEPTION;
227231
228         /* first instruction in a sequence is always a branch target */
229         if (curpc == curstack->targetpc)
230            curdesc->flags |= OPFLAG_IS_BRANCH_TARGET;
231
232232         /* if we are a branch within the block range, add the branch target to our stack */
233233         if ((curdesc->flags & OPFLAG_IS_BRANCH) && curdesc->targetpc >= minpc && curdesc->targetpc < maxpc && pcstackptr < &pcstack[MAX_STACK_DEPTH])
234234         {
r2724r2725
278278   {
279279      /* uh-oh: a page fault; leave the description empty and just if this is the first instruction, leave it empty and */
280280      /* mark as needing to validate; otherwise, just end the sequence here */
281      desc->flags |= OPFLAG_VALIDATE_TLB | OPFLAG_CAN_CAUSE_EXCEPTION | OPFLAG_COMPILER_PAGE_FAULT | OPFLAG_VIRTUAL_NOOP;
281      desc->flags |= OPFLAG_VALIDATE_TLB | OPFLAG_CAN_CAUSE_EXCEPTION | OPFLAG_COMPILER_PAGE_FAULT | OPFLAG_VIRTUAL_NOOP | OPFLAG_END_SEQUENCE;
282282      return desc;
283283   }
284284
r2724r2725
289289   if (desc->opptr.v == NULL)
290290   {
291291      /* address is unmapped; report it as such */
292      desc->flags |= OPFLAG_VALIDATE_TLB | OPFLAG_CAN_CAUSE_EXCEPTION | OPFLAG_COMPILER_UNMAPPED | OPFLAG_VIRTUAL_NOOP;
292      desc->flags |= OPFLAG_VALIDATE_TLB | OPFLAG_CAN_CAUSE_EXCEPTION | OPFLAG_COMPILER_UNMAPPED | OPFLAG_VIRTUAL_NOOP | OPFLAG_END_SEQUENCE;
293293      return desc;
294294   }
295295
r2724r2725
373373         }
374374
375375         /* start a new sequence if we aren't already in the middle of one */
376         if (seqstart == -1)
376         if (seqstart == -1 && skipsleft == 0)
377         {
378            /* tag all start-of-sequence instructions as needing TLB verification */
379            curdesc->flags |= OPFLAG_VALIDATE_TLB | OPFLAG_CAN_CAUSE_EXCEPTION;
377380            seqstart = descnum;
381         }
378382
379383         /* if we are the last instruction, indicate end-of-sequence and redispatch */
380384         if (nextdesc == NULL)
r2724r2725
418422            /* loop until all the registers have been accounted for */
419423            gprread = gprwrite = 0;
420424            fprread = fprwrite = 0;
421            for (backdesc = descnum; backdesc != seqstart - 1; backdesc--)
422               if (drcfe->desc_array[backdesc] != NULL)
423                  accumulate_live_info_backwards(drcfe->desc_array[backdesc], &gprread, &gprwrite, &fprread, &fprwrite);
425            if (seqstart != -1)
426               for (backdesc = descnum; backdesc != seqstart - 1; backdesc--)
427                  if (drcfe->desc_array[backdesc] != NULL)
428                     accumulate_live_info_backwards(drcfe->desc_array[backdesc], &gprread, &gprwrite, &fprread, &fprwrite);
424429
425430            /* reset the register states */
426431            seqstart = -1;
src/emu/cpu/drcuml.c
r2724r2725
1919    * Extend registers to 16? Depends on if PPC can use them
2020
2121    * New instructions?
22        - EXTRACT dst,src,shift,mask
23            dst = (src >> shift) & mask
24
25        - INSERT dst,src,shift,mask
26            dst = (dst & ~mask) | ((src << shift) & mask)
27
2822        - VALID opcode_desc,handle,param
2923            checksum/compare code referenced by opcode_desc; if not
3024            matching, generate exception with handle,param
r2724r2725
3226        - RECALL handle
3327            change code at caller to call handle in the future
3428
35    * Add interface for getting hints from the backend:
36        - number of direct-mapped integer registers
37        - number of direct-mapped floating point registers
38
3929***************************************************************************/
4030
4131#include "drcuml.h"
4232#include "drcumlsh.h"
4333#include "drcumld.h"
34#include "deprecat.h"
4435#include "mame.h"
45#include "deprecat.h"
4636#include <stdarg.h>
4737#include <setjmp.h>
4838
4939
5040/***************************************************************************
41    DEBUGGING
42***************************************************************************/
43
44#define VALIDATE_BACKEND      (0)
45
46
47
48/***************************************************************************
5149    CONSTANTS
5250***************************************************************************/
5351
5452/* opcode validation condition/flag valid bitmasks */
5553#define OV_CONDFLAG_NONE      0x00
5654#define OV_CONDFLAG_COND      0x80
55#define OV_CONDFLAG_SZ         (DRCUML_FLAG_S | DRCUML_FLAG_Z)
56#define OV_CONDFLAG_SZC         (DRCUML_FLAG_S | DRCUML_FLAG_Z | DRCUML_FLAG_C)
57#define OV_CONDFLAG_SZVC      (DRCUML_FLAG_S | DRCUML_FLAG_Z | DRCUML_FLAG_V | DRCUML_FLAG_C)
58#define OV_CONDFLAG_UZC         (DRCUML_FLAG_U | DRCUML_FLAG_Z | DRCUML_FLAG_C)
5759#define OV_CONDFLAG_FLAGS      0x1f
5860
59/* opcode validation parameter valid bitmasks */
61/* bitmasks of valid parameter types and flags */
6062#define OV_PARAM_ALLOWED_NONE   (1 << DRCUML_PTYPE_NONE)
6163#define OV_PARAM_ALLOWED_IMM   (1 << DRCUML_PTYPE_IMMEDIATE)
6264#define OV_PARAM_ALLOWED_IREG   (1 << DRCUML_PTYPE_INT_REGISTER)
6365#define OV_PARAM_ALLOWED_FREG   (1 << DRCUML_PTYPE_FLOAT_REGISTER)
6466#define OV_PARAM_ALLOWED_MVAR   (1 << DRCUML_PTYPE_MAPVAR)
6567#define OV_PARAM_ALLOWED_MEM   (1 << DRCUML_PTYPE_MEMORY)
66#define OV_PARAM_ALLOWED_NCMEM   (OV_PARAM_ALLOWED_MEM | 0x80)
68#define OV_PARAM_FLAG_ANYMEM   0x100
69#define OV_PARAM_FLAG_FIXED4   0x200
70#define OV_PARAM_FLAG_FIXED8   0x400
71
72/* opcode validation parameter valid bitmasks */
73#define OV_PARAM_ALLOWED_ANYMEM   (OV_PARAM_ALLOWED_MEM | OV_PARAM_FLAG_ANYMEM)
6774#define OV_PARAM_ALLOWED_IMV   (OV_PARAM_ALLOWED_IMM | OV_PARAM_ALLOWED_MVAR)
75#define OV_PARAM_ALLOWED_IMV4   (OV_PARAM_ALLOWED_IMM | OV_PARAM_ALLOWED_MVAR | OV_PARAM_FLAG_FIXED4)
76#define OV_PARAM_ALLOWED_IMV8   (OV_PARAM_ALLOWED_IMM | OV_PARAM_ALLOWED_MVAR | OV_PARAM_FLAG_FIXED8)
6877#define OV_PARAM_ALLOWED_IRM   (OV_PARAM_ALLOWED_IREG | OV_PARAM_ALLOWED_MEM)
78#define OV_PARAM_ALLOWED_IRM4   (OV_PARAM_ALLOWED_IREG | OV_PARAM_ALLOWED_MEM | OV_PARAM_FLAG_FIXED4)
79#define OV_PARAM_ALLOWED_IRM8   (OV_PARAM_ALLOWED_IREG | OV_PARAM_ALLOWED_MEM | OV_PARAM_FLAG_FIXED8)
6980#define OV_PARAM_ALLOWED_FRM   (OV_PARAM_ALLOWED_FREG | OV_PARAM_ALLOWED_MEM)
81#define OV_PARAM_ALLOWED_FRM4   (OV_PARAM_ALLOWED_FREG | OV_PARAM_ALLOWED_MEM | OV_PARAM_FLAG_FIXED4)
82#define OV_PARAM_ALLOWED_FRM8   (OV_PARAM_ALLOWED_FREG | OV_PARAM_ALLOWED_MEM | OV_PARAM_FLAG_FIXED8)
7083#define OV_PARAM_ALLOWED_IANY   (OV_PARAM_ALLOWED_IRM | OV_PARAM_ALLOWED_IMV)
84#define OV_PARAM_ALLOWED_IANY4   (OV_PARAM_ALLOWED_IRM | OV_PARAM_ALLOWED_IMV | OV_PARAM_FLAG_FIXED4)
85#define OV_PARAM_ALLOWED_IANY8   (OV_PARAM_ALLOWED_IRM | OV_PARAM_ALLOWED_IMV | OV_PARAM_FLAG_FIXED8)
7186#define OV_PARAM_ALLOWED_FANY   (OV_PARAM_ALLOWED_FRM)
87#define OV_PARAM_ALLOWED_FANY4   (OV_PARAM_ALLOWED_FRM | OV_PARAM_FLAG_FIXED4)
88#define OV_PARAM_ALLOWED_FANY8   (OV_PARAM_ALLOWED_FRM | OV_PARAM_FLAG_FIXED8)
7289
7390
7491
r2724r2725
121138   drcuml_opcode         opcode;            /* the opcode itself */
122139   UINT8               sizes;            /* allowed sizes */
123140   UINT8               condflags;         /* allowed conditions/flags */
124   UINT8               p0types;         /* allowed types for parameter 0 */
125   UINT8               p1types;         /* allowed types for parameter 1 */
126   UINT8               p2types;         /* allowed types for parameter 2 */
127   UINT8               p3types;         /* allowed types for parameter 3 */
141   UINT16               ptypes[4];         /* allowed types for parameters */
128142};
129143
130144
145/* structure describing back-end validation test */
146typedef struct _bevalidate_test bevalidate_test;
147struct _bevalidate_test
148{
149   drcuml_opcode      opcode;
150   UINT8            size;
151   UINT8            destmask;
152   UINT8            iflags;
153   UINT8            flags;
154   UINT64            param[4];
155};
131156
157
158
132159/***************************************************************************
133160    TABLES
134161***************************************************************************/
135162
136163/* macro to simplify the table */
137#define OPVALID_ENTRY_0(op,sizes,condflag)            { DRCUML_OP_##op, sizes, OV_CONDFLAG_##condflag, OV_PARAM_ALLOWED_NONE, OV_PARAM_ALLOWED_NONE, OV_PARAM_ALLOWED_NONE, OV_PARAM_ALLOWED_NONE },
138#define OPVALID_ENTRY_1(op,sizes,condflag,p0)         { DRCUML_OP_##op, sizes, OV_CONDFLAG_##condflag, OV_PARAM_ALLOWED_##p0, OV_PARAM_ALLOWED_NONE, OV_PARAM_ALLOWED_NONE, OV_PARAM_ALLOWED_NONE },
139#define OPVALID_ENTRY_2(op,sizes,condflag,p0,p1)      { DRCUML_OP_##op, sizes, OV_CONDFLAG_##condflag, OV_PARAM_ALLOWED_##p0, OV_PARAM_ALLOWED_##p1, OV_PARAM_ALLOWED_NONE, OV_PARAM_ALLOWED_NONE },
140#define OPVALID_ENTRY_3(op,sizes,condflag,p0,p1,p2)      { DRCUML_OP_##op, sizes, OV_CONDFLAG_##condflag, OV_PARAM_ALLOWED_##p0, OV_PARAM_ALLOWED_##p1, OV_PARAM_ALLOWED_##p2, OV_PARAM_ALLOWED_NONE },
141#define OPVALID_ENTRY_4(op,sizes,condflag,p0,p1,p2,p3)   { DRCUML_OP_##op, sizes, OV_CONDFLAG_##condflag, OV_PARAM_ALLOWED_##p0, OV_PARAM_ALLOWED_##p1, OV_PARAM_ALLOWED_##p2, OV_PARAM_ALLOWED_##p3 },
164#define OPVALID_ENTRY_0(op,sizes,condflag)            { DRCUML_OP_##op, sizes, OV_CONDFLAG_##condflag, { OV_PARAM_ALLOWED_NONE, OV_PARAM_ALLOWED_NONE, OV_PARAM_ALLOWED_NONE, OV_PARAM_ALLOWED_NONE } },
165#define OPVALID_ENTRY_1(op,sizes,condflag,p0)         { DRCUML_OP_##op, sizes, OV_CONDFLAG_##condflag, { OV_PARAM_ALLOWED_##p0, OV_PARAM_ALLOWED_NONE, OV_PARAM_ALLOWED_NONE, OV_PARAM_ALLOWED_NONE } },
166#define OPVALID_ENTRY_2(op,sizes,condflag,p0,p1)      { DRCUML_OP_##op, sizes, OV_CONDFLAG_##condflag, { OV_PARAM_ALLOWED_##p0, OV_PARAM_ALLOWED_##p1, OV_PARAM_ALLOWED_NONE, OV_PARAM_ALLOWED_NONE } },
167#define OPVALID_ENTRY_3(op,sizes,condflag,p0,p1,p2)      { DRCUML_OP_##op, sizes, OV_CONDFLAG_##condflag, { OV_PARAM_ALLOWED_##p0, OV_PARAM_ALLOWED_##p1, OV_PARAM_ALLOWED_##p2, OV_PARAM_ALLOWED_NONE } },
168#define OPVALID_ENTRY_4(op,sizes,condflag,p0,p1,p2,p3)   { DRCUML_OP_##op, sizes, OV_CONDFLAG_##condflag, { OV_PARAM_ALLOWED_##p0, OV_PARAM_ALLOWED_##p1, OV_PARAM_ALLOWED_##p2, OV_PARAM_ALLOWED_##p3 } },
142169
143170/* opcode validation table */
144171static const drcuml_opcode_valid opcode_valid_list[] =
r2724r2725
147174   OPVALID_ENTRY_1(HANDLE,  4,   NONE,  MEM)
148175   OPVALID_ENTRY_2(HASH,    4,   NONE,  IMV,  IMV)
149176   OPVALID_ENTRY_1(LABEL,   4,   NONE,  IMV)
150   OPVALID_ENTRY_1(COMMENT, 4,   NONE,  NCMEM)
177   OPVALID_ENTRY_1(COMMENT, 4,   NONE,  ANYMEM)
151178   OPVALID_ENTRY_2(MAPVAR,  4,   NONE,  MVAR, IMV)
152179
153180   /* Control Flow Operations */
r2724r2725
159186   OPVALID_ENTRY_2(EXH,     4,   COND,  MEM,  IANY)
160187   OPVALID_ENTRY_1(CALLH,   4,   COND,  MEM)
161188   OPVALID_ENTRY_0(RET,     4,   COND)
162   OPVALID_ENTRY_2(CALLC,   4,   COND,  NCMEM,NCMEM)
189   OPVALID_ENTRY_2(CALLC,   4,   COND,  ANYMEM,ANYMEM)
163190   OPVALID_ENTRY_2(RECOVER, 4,   NONE,  IRM,  MVAR)
164191
165192   /* Internal Register Operations */
166193   OPVALID_ENTRY_1(SETFMOD, 4,   NONE,  IANY)
167194   OPVALID_ENTRY_1(GETFMOD, 4,   NONE,  IRM)
168195   OPVALID_ENTRY_1(GETEXP,  4,   NONE,  IRM)
196   OPVALID_ENTRY_1(SAVE,    4,   NONE,  ANYMEM)
197   OPVALID_ENTRY_1(RESTORE, 4,   NONE,  ANYMEM)
169198
170199   /* Integer Operations */
171   OPVALID_ENTRY_3(LOAD1U,  4|8, NONE,  IRM,  NCMEM,IANY)
172   OPVALID_ENTRY_3(LOAD1S,  4|8, NONE,  IRM,  NCMEM,IANY)
173   OPVALID_ENTRY_3(LOAD2U,  4|8, NONE,  IRM,  NCMEM,IANY)
174   OPVALID_ENTRY_3(LOAD2S,  4|8, NONE,  IRM,  NCMEM,IANY)
175   OPVALID_ENTRY_3(LOAD4U,  4|8, NONE,  IRM,  NCMEM,IANY)
176   OPVALID_ENTRY_3(LOAD4S,    8, NONE,  IRM,  NCMEM,IANY)
177   OPVALID_ENTRY_3(LOAD8U,    8, NONE,  IRM,  NCMEM,IANY)
178   OPVALID_ENTRY_3(STORE1,  4|8, NONE,  NCMEM,IANY, IANY)
179   OPVALID_ENTRY_3(STORE2,  4|8, NONE,  NCMEM,IANY, IANY)
180   OPVALID_ENTRY_3(STORE4,  4|8, NONE,  NCMEM,IANY, IANY)
181   OPVALID_ENTRY_3(STORE8,    8, NONE,  NCMEM,IANY, IANY)
182   OPVALID_ENTRY_3(READ1U,  4|8, NONE,  IRM,  IMV,  IANY)
183   OPVALID_ENTRY_3(READ1S,  4|8, NONE,  IRM,  IMV,  IANY)
184   OPVALID_ENTRY_3(READ2U,  4|8, NONE,  IRM,  IMV,  IANY)
185   OPVALID_ENTRY_3(READ2S,  4|8, NONE,  IRM,  IMV,  IANY)
186   OPVALID_ENTRY_4(READ2M,  4|8, NONE,  IRM,  IMV,  IANY, IANY)
187   OPVALID_ENTRY_3(READ4U,  4|8, NONE,  IRM,  IMV,  IANY)
188   OPVALID_ENTRY_3(READ4S,    8, NONE,  IRM,  IMV,  IANY)
189   OPVALID_ENTRY_4(READ4M,  4|8, NONE,  IRM,  IMV,  IANY, IANY)
190   OPVALID_ENTRY_3(READ8U,    8, NONE,  IRM,  IMV,  IANY)
191   OPVALID_ENTRY_4(READ8M,    8, NONE,  IRM,  IMV,  IANY, IANY)
192   OPVALID_ENTRY_3(WRITE1,  4|8, NONE,  IMV,  IANY, IANY)
193   OPVALID_ENTRY_3(WRITE2,  4|8, NONE,  IMV,  IANY, IANY)
194   OPVALID_ENTRY_4(WRIT2M,  4|8, NONE,  IMV,  IANY, IANY, IANY)
195   OPVALID_ENTRY_3(WRITE4,  4|8, NONE,  IMV,  IANY, IANY)
196   OPVALID_ENTRY_4(WRIT4M,  4|8, NONE,  IMV,  IANY, IANY, IANY)
197   OPVALID_ENTRY_3(WRITE8,    8, NONE,  IMV,  IANY, IANY)
198   OPVALID_ENTRY_4(WRIT8M,    8, NONE,  IMV,  IANY, IANY, IANY)
199   OPVALID_ENTRY_3(FLAGS,   4|8, NONE,  IRM,  IMV,  MEM)
200   OPVALID_ENTRY_2(MOV,     4|8, COND,  IRM,  IANY)
201   OPVALID_ENTRY_2(ZEXT1,   4|8, NONE,  IRM,  IANY)
202   OPVALID_ENTRY_2(ZEXT2,   4|8, NONE,  IRM,  IANY)
203   OPVALID_ENTRY_2(ZEXT4,     8, NONE,  IRM,  IANY)
204   OPVALID_ENTRY_2(SEXT1,   4|8, NONE,  IRM,  IANY)
205   OPVALID_ENTRY_2(SEXT2,   4|8, NONE,  IRM,  IANY)
206   OPVALID_ENTRY_2(SEXT4,     8, NONE,  IRM,  IANY)
207   OPVALID_ENTRY_3(ADD,     4|8, FLAGS, IRM,  IANY, IANY)
208   OPVALID_ENTRY_3(ADDC,    4|8, FLAGS, IRM,  IANY, IANY)
209   OPVALID_ENTRY_3(SUB,     4|8, FLAGS, IRM,  IANY, IANY)
210   OPVALID_ENTRY_3(SUBB,    4|8, FLAGS, IRM,  IANY, IANY)
211   OPVALID_ENTRY_2(CMP,     4|8, FLAGS, IANY, IANY)
212   OPVALID_ENTRY_4(MULU,    4|8, FLAGS, IRM,  IRM,  IANY, IANY)
213   OPVALID_ENTRY_4(MULS,    4|8, FLAGS, IRM,  IRM,  IANY, IANY)
214   OPVALID_ENTRY_4(DIVU,    4|8, FLAGS, IRM,  IRM,  IANY, IANY)
215   OPVALID_ENTRY_4(DIVS,    4|8, FLAGS, IRM,  IRM,  IANY, IANY)
216   OPVALID_ENTRY_3(AND,     4|8, FLAGS, IRM,  IANY, IANY)
217   OPVALID_ENTRY_2(TEST,    4|8, FLAGS, IANY, IANY)
218   OPVALID_ENTRY_3(OR,      4|8, FLAGS, IRM,  IANY, IANY)
219   OPVALID_ENTRY_3(XOR,     4|8, FLAGS, IRM,  IANY, IANY)
220   OPVALID_ENTRY_3(SHL,     4|8, FLAGS, IRM,  IANY, IANY)
221   OPVALID_ENTRY_3(SHR,     4|8, FLAGS, IRM,  IANY, IANY)
222   OPVALID_ENTRY_3(SAR,     4|8, FLAGS, IRM,  IANY, IANY)
223   OPVALID_ENTRY_3(ROL,     4|8, FLAGS, IRM,  IANY, IANY)
224   OPVALID_ENTRY_3(ROLC,    4|8, FLAGS, IRM,  IANY, IANY)
225   OPVALID_ENTRY_3(ROR,     4|8, FLAGS, IRM,  IANY, IANY)
226   OPVALID_ENTRY_3(RORC,    4|8, FLAGS, IRM,  IANY, IANY)
200   OPVALID_ENTRY_3(LOAD1U,  4|8, NONE,  IRM,   ANYMEM,IANY4)
201   OPVALID_ENTRY_3(LOAD1S,  4|8, NONE,  IRM,   ANYMEM,IANY4)
202   OPVALID_ENTRY_3(LOAD2U,  4|8, NONE,  IRM,   ANYMEM,IANY4)
203   OPVALID_ENTRY_3(LOAD2S,  4|8, NONE,  IRM,   ANYMEM,IANY4)
204   OPVALID_ENTRY_3(LOAD4U,  4|8, NONE,  IRM,   ANYMEM,IANY4)
205   OPVALID_ENTRY_3(LOAD4S,    8, NONE,  IRM,   ANYMEM,IANY4)
206   OPVALID_ENTRY_3(LOAD8U,    8, NONE,  IRM,   ANYMEM,IANY4)
207   OPVALID_ENTRY_3(STORE1,  4|8, NONE,  ANYMEM,IANY4, IANY)
208   OPVALID_ENTRY_3(STORE2,  4|8, NONE,  ANYMEM,IANY4, IANY)
209   OPVALID_ENTRY_3(STORE4,  4|8, NONE,  ANYMEM,IANY4, IANY)
210   OPVALID_ENTRY_3(STORE8,    8, NONE,  ANYMEM,IANY4, IANY)
211   OPVALID_ENTRY_3(READ1U,  4|8, NONE,  IRM,   IMV4,  IANY4)
212   OPVALID_ENTRY_3(READ1S,  4|8, NONE,  IRM,   IMV4,  IANY4)
213   OPVALID_ENTRY_3(READ2U,  4|8, NONE,  IRM,   IMV4,  IANY4)
214   OPVALID_ENTRY_3(READ2S,  4|8, NONE,  IRM,   IMV4,  IANY4)
215   OPVALID_ENTRY_4(READ2M,  4|8, NONE,  IRM,   IMV4,  IANY4, IANY)
216   OPVALID_ENTRY_3(READ4U,  4|8, NONE,  IRM,   IMV4,  IANY4)
217   OPVALID_ENTRY_3(READ4S,    8, NONE,  IRM,   IMV4,  IANY4)
218   OPVALID_ENTRY_4(READ4M,  4|8, NONE,  IRM,   IMV4,  IANY4, IANY)
219   OPVALID_ENTRY_3(READ8U,    8, NONE,  IRM,   IMV4,  IANY4)
220   OPVALID_ENTRY_4(READ8M,    8, NONE,  IRM,   IMV4,  IANY4, IANY)
221   OPVALID_ENTRY_3(WRITE1,  4|8, NONE,  IMV4,  IANY4, IANY)
222   OPVALID_ENTRY_3(WRITE2,  4|8, NONE,  IMV4,  IANY4, IANY)
223   OPVALID_ENTRY_4(WRIT2M,  4|8, NONE,  IMV4,  IANY4, IANY,  IANY)
224   OPVALID_ENTRY_3(WRITE4,  4|8, NONE,  IMV4,  IANY4, IANY)
225   OPVALID_ENTRY_4(WRIT4M,  4|8, NONE,  IMV4,  IANY4, IANY,  IANY)
226   OPVALID_ENTRY_3(WRITE8,    8, NONE,  IMV4,  IANY4, IANY)
227   OPVALID_ENTRY_4(WRIT8M,    8, NONE,  IMV4,  IANY4, IANY,  IANY)
228   OPVALID_ENTRY_3(FLAGS,   4|8, NONE,  IRM,   IMV,   MEM)
229   OPVALID_ENTRY_2(MOV,     4|8, COND,  IRM,   IANY)
230   OPVALID_ENTRY_2(ZEXT1,   4|8, NONE,  IRM,   IANY4)
231   OPVALID_ENTRY_2(ZEXT2,   4|8, NONE,  IRM,   IANY4)
232   OPVALID_ENTRY_2(ZEXT4,     8, NONE,  IRM,   IANY4)
233   OPVALID_ENTRY_2(SEXT1,   4|8, NONE,  IRM,   IANY4)
234   OPVALID_ENTRY_2(SEXT2,   4|8, NONE,  IRM,   IANY4)
235   OPVALID_ENTRY_2(SEXT4,     8, NONE,  IRM,   IANY4)
236   OPVALID_ENTRY_4(XTRACT,  4|8, NONE,  IRM,   IANY,  IANY,  IANY)
237   OPVALID_ENTRY_4(INSERT,  4|8, NONE,  IRM,   IANY,  IANY,  IANY)
238   OPVALID_ENTRY_3(ADD,     4|8, SZVC,  IRM,   IANY,  IANY)
239   OPVALID_ENTRY_3(ADDC,    4|8, SZVC,  IRM,   IANY,  IANY)
240   OPVALID_ENTRY_3(SUB,     4|8, SZVC,  IRM,   IANY,  IANY)
241   OPVALID_ENTRY_3(SUBB,    4|8, SZVC,  IRM,   IANY,  IANY)
242   OPVALID_ENTRY_2(CMP,     4|8, SZVC,  IANY,  IANY)
243   OPVALID_ENTRY_4(MULU,    4|8, SZ,    IRM,   IRM,   IANY,  IANY)
244   OPVALID_ENTRY_4(MULS,    4|8, SZ,    IRM,   IRM,   IANY,  IANY)
245   OPVALID_ENTRY_4(DIVU,    4|8, SZ,    IRM,   IRM,   IANY,  IANY)
246   OPVALID_ENTRY_4(DIVS,    4|8, SZ,    IRM,   IRM,   IANY,  IANY)
247   OPVALID_ENTRY_3(AND,     4|8, SZ,    IRM,   IANY,  IANY)
248   OPVALID_ENTRY_2(TEST,    4|8, SZ,    IANY,  IANY)
249   OPVALID_ENTRY_3(OR,      4|8, SZ,    IRM,   IANY,  IANY)
250   OPVALID_ENTRY_3(XOR,     4|8, SZ,    IRM,   IANY,  IANY)
251   OPVALID_ENTRY_2(LZCNT,   4|8, NONE,  IRM,   IANY)
252   OPVALID_ENTRY_3(SHL,     4|8, SZC,   IRM,   IANY,  IANY)
253   OPVALID_ENTRY_3(SHR,     4|8, SZC,   IRM,   IANY,  IANY)
254   OPVALID_ENTRY_3(SAR,     4|8, SZC,   IRM,   IANY,  IANY)
255   OPVALID_ENTRY_3(ROL,     4|8, SZC,   IRM,   IANY,  IANY)
256   OPVALID_ENTRY_3(ROLC,    4|8, SZC,   IRM,   IANY,  IANY)
257   OPVALID_ENTRY_3(ROR,     4|8, SZC,   IRM,   IANY,  IANY)
258   OPVALID_ENTRY_3(RORC,    4|8, SZC,   IRM,   IANY,  IANY)
227259
228260   /* Floating Point Operations */
229   OPVALID_ENTRY_3(FLOAD,   4|8, NONE,  FRM,  NCMEM,IANY)
230   OPVALID_ENTRY_3(FSTORE,  4|8, NONE,  NCMEM,IANY, FANY)
231   OPVALID_ENTRY_3(FREAD,   4|8, NONE,  FRM,  IMV,  IANY)
232   OPVALID_ENTRY_3(FWRITE,  4|8, NONE,  IMV,  IANY, FANY)
233   OPVALID_ENTRY_2(FMOV,    4|8, COND,  FRM,  FANY)
234   OPVALID_ENTRY_2(FTOI4,   4|8, NONE,  IRM,  FANY)
235   OPVALID_ENTRY_2(FTOI4T,  4|8, NONE,  IRM,  FANY)
236   OPVALID_ENTRY_2(FTOI4R,  4|8, NONE,  IRM,  FANY)
237   OPVALID_ENTRY_2(FTOI4F,  4|8, NONE,  IRM,  FANY)
238   OPVALID_ENTRY_2(FTOI4C,  4|8, NONE,  IRM,  FANY)
239   OPVALID_ENTRY_2(FTOI8,   4|8, NONE,  IRM,  FANY)
240   OPVALID_ENTRY_2(FTOI8T,  4|8, NONE,  IRM,  FANY)
241   OPVALID_ENTRY_2(FTOI8R,  4|8, NONE,  IRM,  FANY)
242   OPVALID_ENTRY_2(FTOI8F,  4|8, NONE,  IRM,  FANY)
243   OPVALID_ENTRY_2(FTOI8C,  4|8, NONE,  IRM,  FANY)
244   OPVALID_ENTRY_2(FFRFS,     8, NONE,  FRM,  FANY)
245   OPVALID_ENTRY_2(FFRFD,   4  , NONE,  FRM,  FANY)
246   OPVALID_ENTRY_2(FFRI4,   4|8, NONE,  FRM,  IANY)
247   OPVALID_ENTRY_2(FFRI8,   4|8, NONE,  FRM,  IANY)
248   OPVALID_ENTRY_3(FADD,    4|8, FLAGS, FRM,  FANY, FANY)
249   OPVALID_ENTRY_3(FSUB,    4|8, FLAGS, FRM,  FANY, FANY)
250   OPVALID_ENTRY_2(FCMP,    4|8, FLAGS, FANY, FANY)
251   OPVALID_ENTRY_3(FMUL,    4|8, FLAGS, FRM,  FANY, FANY)
252   OPVALID_ENTRY_3(FDIV,    4|8, FLAGS, FRM,  FANY, FANY)
253   OPVALID_ENTRY_2(FNEG,    4|8, FLAGS, FRM,  FANY)
254   OPVALID_ENTRY_2(FABS,    4|8, FLAGS, FRM,  FANY)
255   OPVALID_ENTRY_2(FSQRT,   4|8, FLAGS, FRM,  FANY)
256   OPVALID_ENTRY_2(FRECIP,  4|8, NONE,  FRM,  FANY)
257   OPVALID_ENTRY_2(FRSQRT,  4|8, NONE,  FRM,  FANY)
261   OPVALID_ENTRY_3(FLOAD,   4|8, NONE,  FRM,   ANYMEM,IANY4)
262   OPVALID_ENTRY_3(FSTORE,  4|8, NONE,  ANYMEM,IANY4, FANY)
263   OPVALID_ENTRY_3(FREAD,   4|8, NONE,  FRM,   IMV4,  IANY4)
264   OPVALID_ENTRY_3(FWRITE,  4|8, NONE,  IMV4,  IANY4, FANY)
265   OPVALID_ENTRY_2(FMOV,    4|8, COND,  FRM,   FANY)
266   OPVALID_ENTRY_2(FTOI4,   4|8, NONE,  IRM4,  FANY)
267   OPVALID_ENTRY_2(FTOI4T,  4|8, NONE,  IRM4,  FANY)
268   OPVALID_ENTRY_2(FTOI4R,  4|8, NONE,  IRM4,  FANY)
269   OPVALID_ENTRY_2(FTOI4F,  4|8, NONE,  IRM4,  FANY)
270   OPVALID_ENTRY_2(FTOI4C,  4|8, NONE,  IRM4,  FANY)
271   OPVALID_ENTRY_2(FTOI8,   4|8, NONE,  IRM8,  FANY)
272   OPVALID_ENTRY_2(FTOI8T,  4|8, NONE,  IRM8,  FANY)
273   OPVALID_ENTRY_2(FTOI8R,  4|8, NONE,  IRM8,  FANY)
274   OPVALID_ENTRY_2(FTOI8F,  4|8, NONE,  IRM8,  FANY)
275   OPVALID_ENTRY_2(FTOI8C,  4|8, NONE,  IRM8,  FANY)
276   OPVALID_ENTRY_2(FFRFS,     8, NONE,  FRM,   FANY4)
277   OPVALID_ENTRY_2(FFRFD,   4  , NONE,  FRM,   FANY8)
278   OPVALID_ENTRY_2(FFRI4,   4|8, NONE,  FRM,   IANY4)
279   OPVALID_ENTRY_2(FFRI8,   4|8, NONE,  FRM,   IANY8)
280   OPVALID_ENTRY_3(FADD,    4|8, NONE,  FRM,   FANY,  FANY)
281   OPVALID_ENTRY_3(FSUB,    4|8, NONE,  FRM,   FANY,  FANY)
282   OPVALID_ENTRY_2(FCMP,    4|8, UZC,   FANY,  FANY)
283   OPVALID_ENTRY_3(FMUL,    4|8, NONE,  FRM,   FANY,  FANY)
284   OPVALID_ENTRY_3(FDIV,    4|8, NONE,  FRM,   FANY,  FANY)
285   OPVALID_ENTRY_2(FNEG,    4|8, NONE,  FRM,   FANY)
286   OPVALID_ENTRY_2(FABS,    4|8, NONE,  FRM,   FANY)
287   OPVALID_ENTRY_2(FSQRT,   4|8, NONE,  FRM,   FANY)
288   OPVALID_ENTRY_2(FRECIP,  4|8, NONE,  FRM,   FANY)
289   OPVALID_ENTRY_2(FRSQRT,  4|8, NONE,  FRM,   FANY)
258290};
259291
260292
r2724r2725
282314    FUNCTION PROTOTYPES
283315***************************************************************************/
284316
285#ifdef MAME_DEBUG
286317static void validate_instruction(drcuml_block *block, const drcuml_instruction *inst);
287#else
288#define validate_instruction(block, inst) do { } while (0)
289#endif
318static void validate_backend(drcuml_state *drcuml);
319static void bevalidate_iterate_over_params(drcuml_state *drcuml, drcuml_codehandle **handles, const bevalidate_test *test, drcuml_parameter *paramlist, int pnum);
320static void bevalidate_iterate_over_flags(drcuml_state *drcuml, drcuml_codehandle **handles, const bevalidate_test *test, drcuml_parameter *paramlist);
321static void bevalidate_execute(drcuml_state *drcuml, drcuml_codehandle **handles, const bevalidate_test *test, const drcuml_parameter *paramlist, UINT8 flagmask);
322static void bevalidate_initialize_random_state(drcuml_block *block, drcuml_machine_state *state);
323static int bevalidate_populate_state(drcuml_block *block, drcuml_machine_state *state, const bevalidate_test *test, const drcuml_parameter *paramlist, drcuml_parameter *params, UINT64 *parammem);
324static int bevalidate_verify_state(drcuml_state *drcuml, const drcuml_machine_state *istate, drcuml_machine_state *state, const bevalidate_test *test, const drcuml_parameter *params, const drcuml_instruction *testinst, drccodeptr codestart, drccodeptr codeend, UINT8 flagmask);
290325
291326
292327
293328/***************************************************************************
329    INLINE FUNCTIONS
330***************************************************************************/
331
332/*-------------------------------------------------
333    size_for_param - given a set of parameter
334    flags and the instruction size, return the
335    size of the parameter
336-------------------------------------------------*/
337
338INLINE int size_for_param(int instsize, UINT16 flags)
339{
340   if (flags & OV_PARAM_FLAG_FIXED4)
341      return 4;
342   else if (flags & OV_PARAM_FLAG_FIXED8)
343      return 8;
344   else
345      return instsize;
346}
347
348
349/*-------------------------------------------------
350    mask_for_param - given a set of parameter
351    flags and the instruction size, return a
352    mask of valid bits for that parameter
353-------------------------------------------------*/
354
355INLINE UINT64 mask_for_param(int instsize, UINT16 flags)
356{
357   switch (size_for_param(instsize, flags))
358   {
359      case 4:      return U64(0x00000000ffffffff);
360      case 8:      return U64(0xffffffffffffffff);
361   }
362   return 0;
363}
364
365
366
367/***************************************************************************
294368    INITIALIZATION/TEARDOWN
295369***************************************************************************/
296370
r2724r2725
335409
336410
337411/*-------------------------------------------------
412    drcuml_get_backend_info - return information
413    about the back-end
414-------------------------------------------------*/
415
416void drcuml_get_backend_info(drcuml_state *drcuml, drcbe_info *info)
417{
418   (*drcuml->beintf->be_get_info)(drcuml->bestate, info);
419}
420
421
422/*-------------------------------------------------
338423    drcuml_reset - reset the state completely,
339424    flushing the cache and all information
340425-------------------------------------------------*/
r2724r2725
357442
358443   /* call the backend to reset */
359444   (*drcuml->beintf->be_reset)(drcuml->bestate);
445
446   /* do a one-time validation if requested */
447   if (VALIDATE_BACKEND)
448   {
449      static int validated = FALSE;
450      if (!validated)
451      {
452         validated = TRUE;
453         validate_backend(drcuml);
454      }
455   }
360456}
361457
362458
r2724r2725
817913    instruction created meets all requirements
818914-------------------------------------------------*/
819915
820#ifdef MAME_DEBUG
821916static void validate_instruction(drcuml_block *block, const drcuml_instruction *inst)
822917{
823918   const drcuml_opcode_valid *opvalid = &opcode_valid_table[inst->opcode];
r2724r2725
829924   if (inst->numparams > 0)
830925   {
831926      assert(inst->param[0].type > DRCUML_PTYPE_NONE && inst->param[0].type < DRCUML_PTYPE_MAX);
832      assert(((opvalid->p0types >> inst->param[0].type) & 1) != 0);
833      if (inst->param[0].type == DRCUML_PTYPE_MEMORY && !(opvalid->p0types & 0x80))
927      assert(((opvalid->ptypes[0] >> inst->param[0].type) & 1) != 0);
928      if (inst->param[0].type == DRCUML_PTYPE_MEMORY && !(opvalid->ptypes[0] & OV_PARAM_FLAG_ANYMEM))
834929         assert_in_near_cache(block->drcuml->cache, (void *)(FPTR)inst->param[0].value);
835930   }
836931   if (inst->numparams > 1)
837932   {
838933      assert(inst->param[1].type > DRCUML_PTYPE_NONE && inst->param[1].type < DRCUML_PTYPE_MAX);
839      assert(((opvalid->p1types >> inst->param[1].type) & 1) != 0);
840      if (inst->param[1].type == DRCUML_PTYPE_MEMORY && !(opvalid->p1types & 0x80))
934      assert(((opvalid->ptypes[1] >> inst->param[1].type) & 1) != 0);
935      if (inst->param[1].type == DRCUML_PTYPE_MEMORY && !(opvalid->ptypes[1] & OV_PARAM_FLAG_ANYMEM))
841936         assert_in_near_cache(block->drcuml->cache, (void *)(FPTR)inst->param[1].value);
842937   }
843938   if (inst->numparams > 2)
844939   {
845940      assert(inst->param[2].type > DRCUML_PTYPE_NONE && inst->param[2].type < DRCUML_PTYPE_MAX);
846      assert(((opvalid->p2types >> inst->param[2].type) & 1) != 0);
847      if (inst->param[2].type == DRCUML_PTYPE_MEMORY && !(opvalid->p2types & 0x80))
941      assert(((opvalid->ptypes[2] >> inst->param[2].type) & 1) != 0);
942      if (inst->param[2].type == DRCUML_PTYPE_MEMORY && !(opvalid->ptypes[2] & OV_PARAM_FLAG_ANYMEM))
848943         assert_in_near_cache(block->drcuml->cache, (void *)(FPTR)inst->param[2].value);
849944   }
850945   if (inst->numparams > 3)
851946   {
852947      assert(inst->param[3].type > DRCUML_PTYPE_NONE && inst->param[3].type < DRCUML_PTYPE_MAX);
853      assert(((opvalid->p3types >> inst->param[3].type) & 1) != 0);
854      if (inst->param[3].type == DRCUML_PTYPE_MEMORY && !(opvalid->p3types & 0x80))
948      assert(((opvalid->ptypes[3] >> inst->param[3].type) & 1) != 0);
949      if (inst->param[3].type == DRCUML_PTYPE_MEMORY && !(opvalid->ptypes[3] & OV_PARAM_FLAG_ANYMEM))
855950         assert_in_near_cache(block->drcuml->cache, (void *)(FPTR)inst->param[3].value);
856951   }
857952}
858#endif
953
954
955
956/***************************************************************************
957    BACK-END VALIDATION
958***************************************************************************/
959
960#define TEST_ENTRY_DSS(op, size, p1, p2, p3, flags) { DRCUML_OP_##op, size, 0x01, 0, flags, { U64(p1), U64(p2), U64(p3) } },
961#define TEST_ENTRY_DSSI(op, size, p1, p2, p3, iflags, flags) { DRCUML_OP_##op, size, 0x01, iflags, flags, { U64(p1), U64(p2), U64(p3) } },
962
963static const bevalidate_test bevalidate_test_list[] =
964{
965   TEST_ENTRY_DSS(ADD, 4, 0x7fffffff, 0x12345678, 0x6dcba987, 0)
966   TEST_ENTRY_DSS(ADD, 4, 0x80000000, 0x12345678, 0x6dcba988, FLAGS_V | FLAGS_S)
967   TEST_ENTRY_DSS(ADD, 4, 0xffffffff, 0x92345678, 0x6dcba987, FLAGS_S)
968   TEST_ENTRY_DSS(ADD, 4, 0x00000000, 0x92345678, 0x6dcba988, FLAGS_C | FLAGS_Z)
969
970   TEST_ENTRY_DSS(ADD, 8, 0x7fffffffffffffff, 0x0123456789abcdef, 0x7edcba9876543210, 0)
971   TEST_ENTRY_DSS(ADD, 8, 0x8000000000000000, 0x0123456789abcdef, 0x7edcba9876543211, FLAGS_V | FLAGS_S)
972   TEST_ENTRY_DSS(ADD, 8, 0xffffffffffffffff, 0x8123456789abcdef, 0x7edcba9876543210, FLAGS_S)
973   TEST_ENTRY_DSS(ADD, 8, 0x0000000000000000, 0x8123456789abcdef, 0x7edcba9876543211, FLAGS_C | FLAGS_Z)
974
975   TEST_ENTRY_DSSI(ADDC, 4, 0x7fffffff, 0x12345678, 0x6dcba987, 0,       0)
976   TEST_ENTRY_DSSI(ADDC, 4, 0x7fffffff, 0x12345678, 0x6dcba986, FLAGS_C, 0)
977   TEST_ENTRY_DSSI(ADDC, 4, 0x80000000, 0x12345678, 0x6dcba988, 0,       FLAGS_V | FLAGS_S)
978   TEST_ENTRY_DSSI(ADDC, 4, 0x80000000, 0x12345678, 0x6dcba987, FLAGS_C, FLAGS_V | FLAGS_S)
979   TEST_ENTRY_DSSI(ADDC, 4, 0xffffffff, 0x92345678, 0x6dcba987, 0,       FLAGS_S)
980   TEST_ENTRY_DSSI(ADDC, 4, 0xffffffff, 0x92345678, 0x6dcba986, FLAGS_C, FLAGS_S)
981   TEST_ENTRY_DSSI(ADDC, 4, 0x00000000, 0x92345678, 0x6dcba988, 0,       FLAGS_C | FLAGS_Z)
982   TEST_ENTRY_DSSI(ADDC, 4, 0x00000000, 0x92345678, 0x6dcba987, FLAGS_C, FLAGS_C | FLAGS_Z)
983   TEST_ENTRY_DSSI(ADDC, 4, 0x12345678, 0x12345678, 0xffffffff, FLAGS_C, FLAGS_C)
984
985   TEST_ENTRY_DSSI(ADDC, 8, 0x7fffffffffffffff, 0x0123456789abcdef, 0x7edcba9876543210, 0,       0)
986   TEST_ENTRY_DSSI(ADDC, 8, 0x7fffffffffffffff, 0x0123456789abcdef, 0x7edcba987654320f, FLAGS_C, 0)
987   TEST_ENTRY_DSSI(ADDC, 8, 0x8000000000000000, 0x0123456789abcdef, 0x7edcba9876543211, 0,       FLAGS_V | FLAGS_S)
988   TEST_ENTRY_DSSI(ADDC, 8, 0x8000000000000000, 0x0123456789abcdef, 0x7edcba9876543210, FLAGS_C, FLAGS_V | FLAGS_S)
989   TEST_ENTRY_DSSI(ADDC, 8, 0xffffffffffffffff, 0x8123456789abcdef, 0x7edcba9876543210, 0,       FLAGS_S)
990   TEST_ENTRY_DSSI(ADDC, 8, 0xffffffffffffffff, 0x8123456789abcdef, 0x7edcba987654320f, FLAGS_C, FLAGS_S)
991   TEST_ENTRY_DSSI(ADDC, 8, 0x0000000000000000, 0x8123456789abcdef, 0x7edcba9876543211, 0,       FLAGS_C | FLAGS_Z)
992   TEST_ENTRY_DSSI(ADDC, 8, 0x0000000000000000, 0x8123456789abcdef, 0x7edcba9876543210, FLAGS_C, FLAGS_C | FLAGS_Z)
993   TEST_ENTRY_DSSI(ADDC, 8, 0x123456789abcdef0, 0x123456789abcdef0, 0xffffffffffffffff, FLAGS_C, FLAGS_C)
994};
995
996
997/*-------------------------------------------------
998    validate_backend - execute a number of
999    generic tests on the backend code generator
1000-------------------------------------------------*/
1001
1002static void validate_backend(drcuml_state *drcuml)
1003{
1004   drcuml_codehandle *handles[3];
1005   int tnum;
1006
1007   /* allocate handles for the code */
1008   handles[0] = drcuml_handle_alloc(drcuml, "test_entry");
1009   handles[1] = drcuml_handle_alloc(drcuml, "code_start");
1010   handles[2] = drcuml_handle_alloc(drcuml, "code_end");
1011
1012   /* iterate over test entries */
1013   printf("Backend validation....\n");
1014   for (tnum = 0; tnum < ARRAY_LENGTH(bevalidate_test_list); tnum++)
1015   {
1016      const bevalidate_test *test = &bevalidate_test_list[tnum];
1017      drcuml_parameter param[ARRAY_LENGTH(test->param)];
1018
1019      /* reset parameter list and iterate */
1020      memset(param, 0, sizeof(param));
1021      printf("Executing test %d/%d", tnum + 1, (int)ARRAY_LENGTH(bevalidate_test_list));
1022      bevalidate_iterate_over_params(drcuml, handles, test, param, 0);
1023      printf("\n");
1024   }
1025   fatalerror("All tests passed!");
1026}
1027
1028
1029/*-------------------------------------------------
1030    bevalidate_iterate_over_params - iterate over
1031    all supported types and values of a parameter
1032    and recursively hand off to the next parameter,
1033    or else move on to iterate over the flags
1034-------------------------------------------------*/
1035
1036static void bevalidate_iterate_over_params(drcuml_state *drcuml, drcuml_codehandle **handles, const bevalidate_test *test, drcuml_parameter *paramlist, int pnum)
1037{
1038   const drcuml_opcode_valid *opvalid = &opcode_valid_table[test->opcode];
1039
1040   /* if no parameters, execute now */
1041   if (pnum >= ARRAY_LENGTH(opvalid->ptypes) || opvalid->ptypes[pnum] == OV_PARAM_ALLOWED_NONE)
1042   {
1043      bevalidate_iterate_over_flags(drcuml, handles, test, paramlist);
1044      return;
1045   }
1046
1047   /* iterate over valid parameter types */
1048   for (paramlist[pnum].type = DRCUML_PTYPE_IMMEDIATE; paramlist[pnum].type < DRCUML_PTYPE_MAX; paramlist[pnum].type++)
1049      if (opvalid->ptypes[pnum] & (1 << paramlist[pnum].type))
1050      {
1051         int pindex, pcount;
1052
1053         /* mapvars can only do 32-bit tests */
1054         if (paramlist[pnum].type == DRCUML_PTYPE_MAPVAR && size_for_param(test->size, opvalid->ptypes[pnum]) == 8)
1055            continue;
1056
1057         /* for some parameter types, we wish to iterate over all possibilities */
1058         switch (paramlist[pnum].type)
1059         {
1060            case DRCUML_PTYPE_INT_REGISTER:      pcount = DRCUML_REG_I_END - DRCUML_REG_I0;      break;
1061            case DRCUML_PTYPE_FLOAT_REGISTER:   pcount = DRCUML_REG_F_END - DRCUML_REG_F0;      break;
1062            case DRCUML_PTYPE_MAPVAR:         pcount = DRCUML_MAPVAR_END - DRCUML_MAPVAR_M0;   break;
1063            default:                     pcount = 1;                              break;
1064         }
1065
1066         /* iterate over possibilities */
1067         for (pindex = 0; pindex < pcount; pindex++)
1068         {
1069            int skip = FALSE;
1070            int pscannum;
1071
1072            /* for param 0, print a dot */
1073            if (pnum == 0)
1074               printf(".");
1075
1076            /* can't duplicate multiple source parameters unless they are immediates */
1077            if (paramlist[pnum].type != DRCUML_PTYPE_IMMEDIATE && ((test->destmask >> pnum) & 1) == 0)
1078
1079               /* loop over all parameters we've done before; if the parameter is a source and matches us, skip this case */
1080               for (pscannum = 0; pscannum < pnum; pscannum++)
1081                  if (((test->destmask >> pscannum) & 1) == 0 && paramlist[pnum].type == paramlist[pscannum].type && pindex == paramlist[pscannum].value)
1082                     skip = TRUE;
1083
1084            /* iterate over the next parameter in line */
1085            if (!skip)
1086            {
1087               paramlist[pnum].value = pindex;
1088               bevalidate_iterate_over_params(drcuml, handles, test, paramlist, pnum + 1);
1089            }
1090         }
1091      }
1092}
1093
1094
1095/*-------------------------------------------------
1096    bevalidate_iterate_over_flags - iterate over
1097    all supported flag masks
1098-------------------------------------------------*/
1099
1100static void bevalidate_iterate_over_flags(drcuml_state *drcuml, drcuml_codehandle **handles, const bevalidate_test *test, drcuml_parameter *paramlist)
1101{
1102   const drcuml_opcode_valid *opvalid = &opcode_valid_table[test->opcode];
1103   UINT8 flagmask = opvalid->condflags & 0x1f;
1104   UINT8 curmask;
1105
1106   /* iterate over all possible flag combinations */
1107   for (curmask = 0; curmask <= flagmask; curmask++)
1108      if ((curmask & flagmask) == curmask)
1109         bevalidate_execute(drcuml, handles, test, paramlist, curmask);
1110}
1111
1112
1113/*-------------------------------------------------
1114    bevalidate_execute - execute a single instance
1115    of a test, generating code and verifying the
1116    results
1117-------------------------------------------------*/
1118
1119static void bevalidate_execute(drcuml_state *drcuml, drcuml_codehandle **handles, const bevalidate_test *test, const drcuml_parameter *paramlist, UINT8 flagmask)
1120{
1121   drcuml_parameter params[ARRAY_LENGTH(test->param)];
1122   drcuml_machine_state istate, fstate;
1123   drcuml_instruction testinst;
1124   drcuml_block *block;
1125   UINT64 *parammem;
1126   int numparams;
1127
1128   /* allocate memory for parameters */
1129   parammem = drccache_memory_alloc_near(drcuml->cache, sizeof(UINT64) * ARRAY_LENGTH(test->param));
1130
1131   /* flush the cache */
1132   drcuml_reset(drcuml);
1133
1134   /* start a new block */
1135   block = drcuml_block_begin(drcuml, 30, NULL);
1136   UML_HANDLE(block, handles[0]);
1137
1138   /* set up a random initial state */
1139   bevalidate_initialize_random_state(block, &istate);
1140
1141   /* then populate the state with the parameters */
1142   numparams = bevalidate_populate_state(block, &istate, test, paramlist, params, parammem);
1143
1144   /* generate the code */
1145   UML_RESTORE(block, &istate);
1146   UML_HANDLE(block, handles[1]);
1147   switch (numparams)
1148   {
1149      case 0:
1150         drcuml_block_append_0(block, test->opcode, test->size, flagmask);
1151         break;
1152
1153      case 1:
1154         drcuml_block_append_1(block, test->opcode, test->size, flagmask, params[0].type, params[0].value);
1155         break;
1156
1157      case 2:
1158         drcuml_block_append_2(block, test->opcode, test->size, flagmask, params[0].type, params[0].value, params[1].type, params[1].value);
1159         break;
1160
1161      case 3:
1162         drcuml_block_append_3(block, test->opcode, test->size, flagmask, params[0].type, params[0].value, params[1].type, params[1].value, params[2].type, params[2].value);
1163         break;
1164
1165      case 4:
1166         drcuml_block_append_4(block, test->opcode, test->size, flagmask, params[0].type, params[0].value, params[1].type, params[1].value, params[2].type, params[2].value, params[3].type, params[3].value);
1167         break;
1168   }
1169   testinst = block->inst[block->nextinst - 1];
1170   UML_HANDLE(block, handles[2]);
1171   UML_SAVE(block, &fstate);
1172   UML_EXIT(block, IMM(0));
1173
1174   /* end the block */
1175   drcuml_block_end(block);
1176
1177   /* execute */
1178   drcuml_execute(drcuml, handles[0]);
1179
1180   /* verify the results */
1181   bevalidate_verify_state(drcuml, &istate, &fstate, test, params, &testinst, handles[1]->code, handles[2]->code, flagmask);
1182
1183   /* free memory */
1184   drccache_memory_free(drcuml->cache, parammem, sizeof(UINT64) * ARRAY_LENGTH(test->param));
1185}
1186
1187
1188/*-------------------------------------------------
1189    bevalidate_initialize_random_state -
1190    initialize the machine state to randomness
1191-------------------------------------------------*/
1192
1193static void bevalidate_initialize_random_state(drcuml_block *block, drcuml_machine_state *state)
1194{
1195   int regnum;
1196
1197   /* initialize core state to random values */
1198   state->fmod = mame_rand(Machine) & 0x03;
1199   state->flags = mame_rand(Machine) & 0x1f;
1200   state->exp = mame_rand(Machine);
1201
1202   /* initialize integer registers to random values */
1203   for (regnum = 0; regnum < ARRAY_LENGTH(state->r); regnum++)
1204   {
1205      state->r[regnum].w.h = mame_rand(Machine);
1206      state->r[regnum].w.l = mame_rand(Machine);
1207   }
1208
1209   /* initialize float registers to random values */
1210   for (regnum = 0; regnum < ARRAY_LENGTH(state->f); regnum++)
1211   {
1212      *(UINT32 *)&state->f[regnum].s.h = mame_rand(Machine);
1213      *(UINT32 *)&state->f[regnum].s.l = mame_rand(Machine);
1214   }
1215
1216   /* initialize map variables to random values */
1217   for (regnum = 0; regnum < DRCUML_MAPVAR_END - DRCUML_MAPVAR_M0; regnum++)
1218      UML_MAPVAR(block, MVAR(regnum), mame_rand(Machine));
1219}
1220
1221
1222/*-------------------------------------------------
1223    bevalidate_populate_state - populate the
1224    machine state with the proper values prior
1225    to executing a test
1226-------------------------------------------------*/
1227
1228static int bevalidate_populate_state(drcuml_block *block, drcuml_machine_state *state, const bevalidate_test *test, const drcuml_parameter *paramlist, drcuml_parameter *params, UINT64 *parammem)
1229{
1230   const drcuml_opcode_valid *opvalid = &opcode_valid_table[test->opcode];
1231   int numparams = ARRAY_LENGTH(test->param);
1232   int pnum;
1233
1234   /* copy flags as-is */
1235   state->flags = test->iflags;
1236
1237   /* iterate over parameters */
1238   for (pnum = 0; pnum < ARRAY_LENGTH(test->param); pnum++)
1239   {
1240      int psize = size_for_param(test->size, opvalid->ptypes[pnum]);
1241      drcuml_parameter *curparam = &params[pnum];
1242
1243      /* start with a copy of the parameter from the list */
1244      *curparam = paramlist[pnum];
1245
1246      /* switch off the type */
1247      switch (curparam->type)
1248      {
1249         /* immediate parameters: take the value from the test entry */
1250         case DRCUML_PTYPE_IMMEDIATE:
1251            curparam->value = test->param[pnum];
1252            break;
1253
1254         /* register parameters: set the register value in the state and set the parameter value to the register index */
1255         case DRCUML_PTYPE_INT_REGISTER:
1256            state->r[curparam->value].d = test->param[pnum];
1257            curparam->value += DRCUML_REG_I0;
1258            break;
1259
1260         /* register parameters: set the register value in the state and set the parameter value to the register index */
1261         case DRCUML_PTYPE_FLOAT_REGISTER:
1262            state->f[curparam->value].d = test->param[pnum];
1263            curparam->value += DRCUML_REG_F0;
1264            break;
1265
1266         /* memory parameters: set the memory value in the parameter space and set the parameter value to point to it */
1267         case DRCUML_PTYPE_MEMORY:
1268            curparam->value = (FPTR)&parammem[pnum];
1269            if (psize == 4)
1270               *(UINT32 *)(FPTR)curparam->value = test->param[pnum];
1271            else
1272               *(UINT64 *)(FPTR)curparam->value = test->param[pnum];
1273            break;
1274
1275         /* map variables: issue a MAPVAR instruction to set the value and set the parameter value to the mapvar index */
1276         case DRCUML_PTYPE_MAPVAR:
1277            UML_MAPVAR(block, MVAR(curparam->value), test->param[pnum]);
1278            curparam->value += DRCUML_MAPVAR_M0;
1279            break;
1280
1281         /* use anything else to count the number of parameters */
1282         default:
1283            numparams = MIN(numparams, pnum);
1284            break;
1285      }
1286   }
1287
1288   /* return the total number of parameters */
1289   return numparams;
1290}
1291
1292
1293/*-------------------------------------------------
1294    bevalidate_verify_state - verify the final
1295    state after executing a test, and report any
1296    discrepancies
1297-------------------------------------------------*/
1298
1299static int bevalidate_verify_state(drcuml_state *drcuml, const drcuml_machine_state *istate, drcuml_machine_state *state, const bevalidate_test *test, const drcuml_parameter *params, const drcuml_instruction *testinst, drccodeptr codestart, drccodeptr codeend, UINT8 flagmask)
1300{
1301   const drcuml_opcode_valid *opvalid = &opcode_valid_table[test->opcode];
1302   UINT8 ireg[DRCUML_REG_I_END - DRCUML_REG_I0] = { 0 };
1303   UINT8 freg[DRCUML_REG_F_END - DRCUML_REG_F0] = { 0 };
1304   char errorbuf[1024];
1305   char *errend = errorbuf;
1306   int pnum, regnum;
1307
1308   *errend = 0;
1309
1310   /* check flags */
1311   if ((state->flags & flagmask) != (test->flags & flagmask))
1312   {
1313      errend += sprintf(errend, "  Flags ... result:%c%c%c%c%c  expected:%c%c%c%c%c\n",
1314         (flagmask & DRCUML_FLAG_U) ? ((state->flags & DRCUML_FLAG_U) ? 'U' : '.') : '-',
1315         (flagmask & DRCUML_FLAG_S) ? ((state->flags & DRCUML_FLAG_S) ? 'S' : '.') : '-',
1316         (flagmask & DRCUML_FLAG_Z) ? ((state->flags & DRCUML_FLAG_Z) ? 'Z' : '.') : '-',
1317         (flagmask & DRCUML_FLAG_V) ? ((state->flags & DRCUML_FLAG_V) ? 'V' : '.') : '-',
1318         (flagmask & DRCUML_FLAG_C) ? ((state->flags & DRCUML_FLAG_C) ? 'C' : '.') : '-',
1319         (flagmask & DRCUML_FLAG_U) ? ((test->flags & DRCUML_FLAG_U) ? 'U' : '.') : '-',
1320         (flagmask & DRCUML_FLAG_S) ? ((test->flags & DRCUML_FLAG_S) ? 'S' : '.') : '-',
1321         (flagmask & DRCUML_FLAG_Z) ? ((test->flags & DRCUML_FLAG_Z) ? 'Z' : '.') : '-',
1322         (flagmask & DRCUML_FLAG_V) ? ((test->flags & DRCUML_FLAG_V) ? 'V' : '.') : '-',
1323         (flagmask & DRCUML_FLAG_C) ? ((test->flags & DRCUML_FLAG_C) ? 'C' : '.') : '-');
1324   }
1325
1326   /* check destination parameters */
1327   for (pnum = 0; pnum < ARRAY_LENGTH(test->param); pnum++)
1328      if (test->destmask & (1 << pnum))
1329      {
1330         UINT64 mask = mask_for_param(test->size, opvalid->ptypes[pnum]);
1331         int psize = size_for_param(test->size, opvalid->ptypes[pnum]);
1332         UINT64 result = 0;
1333
1334         /* fetch the result from the parameters */
1335         switch (params[pnum].type)
1336         {
1337            /* integer registers fetch from the state */
1338            case DRCUML_PTYPE_INT_REGISTER:
1339               ireg[params[pnum].value - DRCUML_REG_I0] = 1;
1340               result = state->r[params[pnum].value - DRCUML_REG_I0].d;
1341               break;
1342
1343            /* float registers fetch from the state */
1344            case DRCUML_PTYPE_FLOAT_REGISTER:
1345               freg[params[pnum].value - DRCUML_REG_I0] = 1;
1346               result = state->f[params[pnum].value - DRCUML_REG_F0].d;
1347               break;
1348
1349            /* memory registers fetch from the memory address */
1350            case DRCUML_PTYPE_MEMORY:
1351               if (psize == 4)
1352                  result = *(UINT32 *)(FPTR)params[pnum].value;
1353               else
1354                  result = *(UINT64 *)(FPTR)params[pnum].value;
1355               break;
1356
1357            default:
1358               break;
1359         }
1360
1361         /* check against the mask */
1362         if ((result & mask) != (test->param[pnum] & mask))
1363         {
1364            if ((UINT32)mask == mask)
1365               errend += sprintf(errend, "  Parameter %d ... result:%08X  expected:%08X\n", pnum,
1366                              (UINT32)(result & mask), (UINT32)(test->param[pnum] & mask));
1367            else
1368               errend += sprintf(errend, "  Parameter %d ... result:%08X%08X  expected:%08X%08X\n", pnum,
1369                              (UINT32)((result & mask) >> 32), (UINT32)(result & mask),
1370                              (UINT32)((test->param[pnum] & mask) >> 32), (UINT32)(test->param[pnum] & mask));
1371         }
1372      }
1373
1374   /* check source integer parameters for unexpected alterations */
1375   for (regnum = 0; regnum < ARRAY_LENGTH(state->r); regnum++)
1376      if (ireg[regnum] == 0 && istate->r[regnum].d != state->r[regnum].d)
1377         errend += sprintf(errend, "  Register i%d ... result:%08X%08X  originally:%08X%08X\n", regnum,
1378                        (UINT32)(state->r[regnum].d >> 32), (UINT32)state->r[regnum].d,
1379                        (UINT32)(istate->r[regnum].d >> 32), (UINT32)istate->r[regnum].d);
1380
1381   /* check source float parameters for unexpected alterations */
1382   for (regnum = 0; regnum < ARRAY_LENGTH(state->f); regnum++)
1383      if (freg[regnum] == 0 && *(UINT64 *)&istate->f[regnum].d != *(UINT64 *)&state->f[regnum].d)
1384         errend += sprintf(errend, "  Register f%d ... result:%08X%08X  originally:%08X%08X\n", regnum,
1385                        (UINT32)(*(UINT64 *)&state->f[regnum].d >> 32), (UINT32)*(UINT64 *)&state->f[regnum].d,
1386                        (UINT32)(*(UINT64 *)&istate->f[regnum].d >> 32), (UINT32)*(UINT64 *)&istate->f[regnum].d);
1387
1388   /* output the error if we have one */
1389   if (errend != errorbuf)
1390   {
1391      char disasm[100];
1392
1393      /* disassemble the test instruction */
1394      drcuml_disasm(testinst, disasm);
1395
1396      /* output a description of what went wrong */
1397      printf("\n");
1398      printf("----------------------------------------------\n");
1399      printf("Backend validation error:\n");
1400      printf("   %s\n", disasm);
1401      printf("\n");
1402      printf("Errors:\n");
1403      printf("%s\n", errorbuf);
1404      fatalerror("Error during validation");
1405   }
1406   return errend != errorbuf;
1407}
src/emu/cpu/drcfe.h
r2724r2725
7676/* execution semantics */
7777#define OPFLAG_READS_MEMORY            0x00080000      /* instruction reads memory */
7878#define OPFLAG_WRITES_MEMORY         0x00100000      /* instruction writes memory */
79#define OPFLAG_VARIABLE_SHIFT         0x00200000      /* instruction performs a variable count shift */
80#define OPFLAG_MULTIPLY_DIVIDE         0x00400000      /* instruction performs a multiply/divide */
8179
8280
8381
src/emu/cpu/drcuml.h
r2724r2725
176176   DRCUML_OP_SETFMOD,      /* SETFMOD src                    */
177177   DRCUML_OP_GETFMOD,      /* GETFMOD dst                    */
178178   DRCUML_OP_GETEXP,      /* GETEXP  dst,index              */
179   DRCUML_OP_SAVE,         /* SAVE    mem                    */
180   DRCUML_OP_RESTORE,      /* RESTORE mem                    */
179181
180182   /* Integer Operations */
181183   DRCUML_OP_LOAD1U,      /* LOAD1U  dst,base,index         */
r2724r2725
214216   DRCUML_OP_SEXT1,      /* SEXT1   dst,src                */
215217   DRCUML_OP_SEXT2,      /* SEXT2   dst,src                */
216218   DRCUML_OP_SEXT4,      /* SEXT4   dst,src                */
219   DRCUML_OP_XTRACT,      /* XTRACT  dst,src,shift,mask     */
220   DRCUML_OP_INSERT,      /* INSERT  dst,src,shift,mask     */
217221   DRCUML_OP_ADD,         /* ADD     dst,src1,src2[,f]      */
218222   DRCUML_OP_ADDC,         /* ADDC    dst,src1,src2[,f]      */
219223   DRCUML_OP_SUB,         /* SUB     dst,src1,src2[,f]      */
r2724r2725
227231   DRCUML_OP_TEST,         /* TEST    src1,src2[,f]          */
228232   DRCUML_OP_OR,         /* OR      dst,src1,src2[,f]      */
229233   DRCUML_OP_XOR,         /* XOR     dst,src1,src2[,f]      */
234   DRCUML_OP_LZCNT,      /* LZCNT   dst,src                */
230235   DRCUML_OP_SHL,         /* SHL     dst,src,count[,f]      */
231236   DRCUML_OP_SHR,         /* SHR     dst,src,count[,f]      */
232237   DRCUML_OP_SAR,         /* SAR     dst,src,count[,f]      */
r2724r2725
317322};
318323
319324
325/* an integer register, with low/high parts */
326typedef union _drcuml_ireg drcuml_ireg;
327union _drcuml_ireg
328{
329#ifdef LSB_FIRST
330   struct { UINT32   l,h; } w;         /* 32-bit low, high parts of the register */
331#else
332   struct { UINT32 h,l; } w;         /* 32-bit low, high parts of the register */
333#endif
334   UINT64         d;               /* 64-bit full register */
335};
336
337
338/* a floating-point register, with low/high parts */
339typedef union _drcuml_freg drcuml_freg;
340union _drcuml_freg
341{
342#ifdef LSB_FIRST
343   struct { float l,h; } s;         /* 32-bit low, high parts of the register */
344#else
345   struct { float h,l;   } s;         /* 32-bit low, high parts of the register */
346#endif
347   double         d;               /* 64-bit full register */
348};
349
350
351/* the collected machine state of a system */
352typedef struct _drcuml_machine_state drcuml_machine_state;
353struct _drcuml_machine_state
354{
355   drcuml_ireg      r[DRCUML_REG_I_END - DRCUML_REG_I0];   /* integer registers */
356   drcuml_freg      f[DRCUML_REG_F_END - DRCUML_REG_F0];   /* floating-point registers */
357   UINT32         exp;                           /* exception parameter register */
358   UINT8         fmod;                           /* fmod (floating-point mode) register */
359   UINT8         flags;                           /* flags state */
360};
361
362
363/* hints and information about the back-end */
364typedef struct _drcbe_info drcbe_info;
365struct _drcbe_info
366{
367   UINT8         direct_iregs;                     /* number of direct-mapped integer registers */
368   UINT8         direct_fregs;                     /* number of direct-mapped floating point registers */
369};
370
371
320372/* typedefs for back-end callback functions */
321373typedef drcbe_state *(*drcbe_alloc_func)(drcuml_state *drcuml, drccache *cache, UINT32 flags, int modes, int addrbits, int ignorebits);
322374typedef void (*drcbe_free_func)(drcbe_state *state);
r2724r2725
324376typedef int   (*drcbe_execute_func)(drcbe_state *state, drcuml_codehandle *entry);
325377typedef void (*drcbe_generate_func)(drcbe_state *state, drcuml_block *block, const drcuml_instruction *instlist, UINT32 numinst);
326378typedef int (*drcbe_hash_exists)(drcbe_state *state, UINT32 mode, UINT32 pc);
379typedef void (*drcbe_get_info)(drcbe_state *state, drcbe_info *info);
327380
328381
329382/* interface structure for a back-end */
r2724r2725
336389   drcbe_execute_func   be_execute;
337390   drcbe_generate_func   be_generate;
338391   drcbe_hash_exists   be_hash_exists;
392   drcbe_get_info      be_get_info;
339393};
340394
341395
r2724r2725
349403/* allocate state for the code generator and initialize the back-end */
350404drcuml_state *drcuml_alloc(drccache *cache, UINT32 flags, int modes, int addrbits, int ignorebits);
351405
406/* return information about the back-end */
407void drcuml_get_backend_info(drcuml_state *drcuml, drcbe_info *info);
408
352409/* reset the state completely, flushing the cache and all information */
353410void drcuml_reset(drcuml_state *drcuml);
354411
src/emu/cpu/drcbex64.c
r2724r2725
168168#include "drcbeut.h"
169169#include "debugger.h"
170170#include "x86emit.h"
171#include "eminline.h"
171172#undef REG_SP
172173#include "x86log.h"
173174#include <math.h>
175#include <stddef.h>
174176
175177
176178
r2724r2725
265267   x86code *            drcmap_get_value;      /* map lookup helper */
266268   data_accessors         accessors[ADDRESS_SPACES];/* memory accessors */
267269
270   UINT8               sse41;               /* do we have SSE4.1 support? */
268271   UINT32               ssemode;            /* saved SSE mode */
269272   UINT32               ssemodesave;         /* temporary location for saving */
270273   UINT32               ssecontrol[4];         /* copy of the sse_control array */
r2724r2725
276279
277280   UINT8 *               rbpvalue;            /* value of RBP */
278281   UINT8               flagsmap[0x1000];      /* flags map */
282   UINT64               flagsunmap[0x20];      /* flags unmapper */
279283
280284   x86log_context *      log;               /* logging */
281285};
r2724r2725
293297static int drcbex64_execute(drcbe_state *drcbe, drcuml_codehandle *entry);
294298static void drcbex64_generate(drcbe_state *drcbe, drcuml_block *block, const drcuml_instruction *instlist, UINT32 numinst);
295299static int drcbex64_hash_exists(drcbe_state *drcbe, UINT32 mode, UINT32 pc);
300static void drcbex64_get_info(drcbe_state *state, drcbe_info *info);
296301
297302/* private helper functions */
298303static void fixup_label(void *parameter, drccodeptr labelcodeptr);
r2724r2725
311316   drcbex64_reset,
312317   drcbex64_execute,
313318   drcbex64_generate,
314   drcbex64_hash_exists
319   drcbex64_hash_exists,
320   drcbex64_get_info
315321};
316322
317323/* opcode table */
r2724r2725
356362   COND_GE,   /* DRCUML_COND_GE,          requires SV */
357363};
358364
365/* rounding mode mapping table */
366static const UINT8 fprnd_map[4] =
367{
368   FPRND_CHOP,      /* DRCUML_FMOD_TRUNC,       truncate */
369   FPRND_NEAR,      /* DRCUML_FMOD_ROUND,       round */
370   FPRND_UP,      /* DRCUML_FMOD_CEIL,        round up */
371   FPRND_DOWN      /* DRCUML_FMOD_FLOOR        round down */
372};
359373
360374
375
361376/***************************************************************************
362377    TABLES
363378***************************************************************************/
r2724r2725
381396static x86code *op_setfmod(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
382397static x86code *op_getfmod(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
383398static x86code *op_getexp(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
399static x86code *op_save(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
400static x86code *op_restore(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
384401
385402static x86code *op_load1u(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
386403static x86code *op_load1s(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
r2724r2725
418435static x86code *op_sext1(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
419436static x86code *op_sext2(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
420437static x86code *op_sext4(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
438static x86code *op_xtract(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
439static x86code *op_insert(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
421440static x86code *op_add(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
422441static x86code *op_addc(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
423442static x86code *op_sub(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
r2724r2725
431450static x86code *op_test(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
432451static x86code *op_or(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
433452static x86code *op_xor(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
453static x86code *op_lzcnt(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
434454static x86code *op_shl(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
435455static x86code *op_shr(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
436456static x86code *op_sar(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
r2724r2725
493513   { DRCUML_OP_SETFMOD, op_setfmod },   /* SETFMOD src                    */
494514   { DRCUML_OP_GETFMOD, op_getfmod },   /* GETFMOD dst                    */
495515   { DRCUML_OP_GETEXP,  op_getexp },   /* GETEXP  dst,index              */
516   { DRCUML_OP_SAVE,    op_save },      /* SAVE    dst,index              */
517   { DRCUML_OP_RESTORE, op_restore },   /* RESTORE dst,index              */
496518
497519   /* Integer Operations */
498520   { DRCUML_OP_LOAD1U,  op_load1u },   /* LOAD1U  dst,base,index         */
r2724r2725
531553   { DRCUML_OP_SEXT1,   op_sext1 },   /* SEXT1   dst,src                */
532554   { DRCUML_OP_SEXT2,   op_sext2 },   /* SEXT2   dst,src                */
533555   { DRCUML_OP_SEXT4,   op_sext4 },   /* SEXT4   dst,src                */
556   { DRCUML_OP_XTRACT,  op_xtract },   /* XTRACT  dst,src1,src2,src3     */
557   { DRCUML_OP_INSERT,  op_insert },   /* INSERT  dst,src1,src2,src3     */
534558   { DRCUML_OP_ADD,     op_add },      /* ADD     dst,src1,src2[,f]      */
535559   { DRCUML_OP_ADDC,    op_addc },      /* ADDC    dst,src1,src2[,f]      */
536560   { DRCUML_OP_SUB,     op_sub },      /* SUB     dst,src1,src2[,f]      */
r2724r2725
544568   { DRCUML_OP_TEST,    op_test },      /* TEST    src1,src2[,f]          */
545569   { DRCUML_OP_OR,      op_or },      /* OR      dst,src1,src2[,f]      */
546570   { DRCUML_OP_XOR,     op_xor },      /* XOR     dst,src1,src2[,f]      */
571   { DRCUML_OP_LZCNT,   op_lzcnt },   /* LZCNT   dst,src[,f]            */
547572   { DRCUML_OP_SHL,     op_shl },      /* SHL     dst,src,count[,f]      */
548573   { DRCUML_OP_SHR,     op_shr },      /* SHR     dst,src,count[,f]      */
549574   { DRCUML_OP_SAR,     op_sar },      /* SAR     dst,src,count[,f]      */
r2724r2725
605630
606631
607632/*-------------------------------------------------
633    param_select_register2 - select a register
634    to use, avoiding conflicts with the optional
635    checkparam
636-------------------------------------------------*/
637
638INLINE int param_select_register2(int defreg, const drcuml_parameter *param, const drcuml_parameter *checkparam1, const drcuml_parameter *checkparam2)
639{
640   if (param->type == DRCUML_PTYPE_INT_REGISTER && (param->type != checkparam1->type || param->value != checkparam1->value) && (param->type != checkparam2->type || param->value != checkparam2->value))
641      return param->value;
642   return defreg;
643}
644
645
646/*-------------------------------------------------
608647    offset_from_rbp - return the verified offset
609648    from rbp
610649-------------------------------------------------*/
r2724r2725
765804      if (entry & 0x800) flags |= DRCUML_FLAG_V;
766805      drcbe->flagsmap[entry] = flags;
767806   }
807   for (entry = 0; entry < ARRAY_LENGTH(drcbe->flagsunmap); entry++)
808   {
809      UINT64 flags = 0;
810      if (entry & DRCUML_FLAG_C) flags |= 0x001;
811      if (entry & DRCUML_FLAG_U) flags |= 0x004;
812      if (entry & DRCUML_FLAG_Z) flags |= 0x040;
813      if (entry & DRCUML_FLAG_S) flags |= 0x080;
814      if (entry & DRCUML_FLAG_V) flags |= 0x800;
815      drcbe->flagsunmap[entry] = flags;
816   }
768817
769818   /* create the log */
770819   if (flags & DRCUML_OPTION_LOG_NATIVE)
r2724r2725
792841
793842static void drcbex64_reset(drcbe_state *drcbe)
794843{
844   UINT32 (*cpuid_ecx_stub)(void);
795845   x86code **dst;
796846   int spacenum;
797847
r2724r2725
809859   if (dst == NULL)
810860      fatalerror("Out of cache space after a reset!");
811861
862   /* generate a simple CPUID stub */
863   cpuid_ecx_stub = (UINT32 (*)(void))*dst;
864   emit_push_r64(dst, REG_RBX);                                          // push  rbx
865   emit_mov_r32_imm(dst, REG_EAX, 1);                                       // mov   eax,1
866   emit_cpuid(dst);                                                   // cpuid
867   emit_mov_r32_r32(dst, REG_EAX, REG_ECX);                                 // mov   eax,ecx
868   emit_pop_r64(dst, REG_RBX);                                             // pop   rbx
869   emit_ret(dst);                                                      // ret
870
871   /* call it to determine if we have SSE4.1 support */
872   drcbe->sse41 = (((*cpuid_ecx_stub)() & 0x80000) != 0);
873
812874   /* generate an entry point */
813875   drcbe->entry = (x86_entry_point_func)*dst;
814876   emit_push_r64(dst, REG_RBX);                                          // push  rbx
r2724r2725
862924
863925
864926/*-------------------------------------------------
927    drcbex64_execute - execute a block of code
928    referenced by the given handle
929-------------------------------------------------*/
930
931static int drcbex64_execute(drcbe_state *drcbe, drcuml_codehandle *entry)
932{
933   /* call our entry point which will jump to the destination */
934   return (*drcbe->entry)(drcbe->rbpvalue, (x86code *)drcuml_handle_codeptr(entry));
935}
936
937
938/*-------------------------------------------------
865939    drcbex64_generate - generate code
866940-------------------------------------------------*/
867941
r2724r2725
9451019
9461020
9471021/*-------------------------------------------------
948    drcbec_execute - execute a block of code
949    registered at the given mode/pc
1022    drcbex64_get_info - return information about
1023    the back-end implementation
9501024-------------------------------------------------*/
9511025
952static int drcbex64_execute(drcbe_state *drcbe, drcuml_codehandle *entry)
1026static void drcbex64_get_info(drcbe_state *state, drcbe_info *info)
9531027{
954   /* call our entry point which will jump to the destination */
955   return (*drcbe->entry)(drcbe->rbpvalue, (x86code *)drcuml_handle_codeptr(entry));
1028   for (info->direct_iregs = 0; info->direct_iregs < DRCUML_REG_I_END - DRCUML_REG_I0; info->direct_iregs++)
1029      if (int_register_map[info->direct_iregs] == 0)
1030         break;
1031   for (info->direct_fregs = 0; info->direct_fregs < DRCUML_REG_F_END - DRCUML_REG_F0; info->direct_fregs++)
1032      if (float_register_map[info->direct_fregs] == 0)
1033         break;
9561034}
9571035
9581036
r2724r2725
14611539{
14621540   if (param->type == DRCUML_PTYPE_IMMEDIATE)
14631541   {
1464      if (inst->condflags != 0 && (UINT32)param->value == 0xffffffff)
1542      if (inst->condflags == 0 && (UINT32)param->value == 0xffffffff)
14651543         /* skip */;
14661544      else if (inst->condflags != 0 && (UINT32)param->value == 0)
14671545         emit_xor_r32_r32(dst, reg, reg);                                 // xor   reg,reg
r2724r2725
14841562{
14851563   if (param->type == DRCUML_PTYPE_IMMEDIATE)
14861564   {
1487      if (inst->condflags != 0 && (UINT32)param->value == 0xffffffff)
1565      if (inst->condflags == 0 && (UINT32)param->value == 0xffffffff)
14881566         /* skip */;
14891567      else if (inst->condflags != 0 && (UINT32)param->value == 0)
14901568         emit_mov_m32_imm(dst, MEMPARAMS, 0);                              // mov   [dest],0
r2724r2725
15441622{
15451623   if (param->type == DRCUML_PTYPE_IMMEDIATE)
15461624   {
1547      if (inst->condflags != 0 && (UINT32)param->value == 0)
1625      if (inst->condflags == 0 && (UINT32)param->value == 0)
15481626         /* skip */;
15491627      else if (inst->condflags != 0 && (UINT32)param->value == 0xffffffff)
15501628         emit_mov_r32_imm(dst, reg, -1);                                    // mov  reg,-1
r2724r2725
15671645{
15681646   if (param->type == DRCUML_PTYPE_IMMEDIATE)
15691647   {
1570      if (inst->condflags != 0 && (UINT32)param->value == 0)
1648      if (inst->condflags == 0 && (UINT32)param->value == 0)
15711649         /* skip */;
15721650      else if (inst->condflags != 0 && (UINT32)param->value == 0xffffffff)
15731651         emit_mov_m32_imm(dst, MEMPARAMS, -1);                              // mov   [dest],-1
r2724r2725
15921670{
15931671   if (param->type == DRCUML_PTYPE_IMMEDIATE)
15941672   {
1595      if (inst->condflags != 0 && (UINT32)param->value == 0)
1673      if (inst->condflags == 0 && (UINT32)param->value == 0)
15961674         /* skip */;
15971675      else if (inst->condflags != 0 && (UINT32)param->value == 0xffffffff)
15981676         emit_not_r32(dst, reg);                                          // not   reg
r2724r2725
16151693{
16161694   if (param->type == DRCUML_PTYPE_IMMEDIATE)
16171695   {
1618      if (inst->condflags != 0 && (UINT32)param->value == 0)
1696      if (inst->condflags == 0 && (UINT32)param->value == 0)
16191697         /* skip */;
16201698      else if (inst->condflags != 0 && (UINT32)param->value == 0xffffffff)
16211699         emit_not_m32(dst, MEMPARAMS);                                    // not   [dest]
r2724r2725
16401718{
16411719   if (param->type == DRCUML_PTYPE_IMMEDIATE)
16421720   {
1643      if (inst->condflags != 0 && (UINT32)param->value == 0)
1721      if (inst->condflags == 0 && (UINT32)param->value == 0)
16441722         /* skip */;
16451723      else
16461724         emit_shl_r32_imm(dst, reg, param->value);                           // shl   reg,param
r2724r2725
16621740{
16631741   if (param->type == DRCUML_PTYPE_IMMEDIATE)
16641742   {
1665      if (inst->condflags != 0 && (UINT32)param->value == 0)
1743      if (inst->condflags == 0 && (UINT32)param->value == 0)
16661744         /* skip */;
16671745      else
16681746         emit_shl_m32_imm(dst, MEMPARAMS, param->value);                        // shl   [dest],param
r2724r2725
16841762{
16851763   if (param->type == DRCUML_PTYPE_IMMEDIATE)
16861764   {
1687      if (inst->condflags != 0 && (UINT32)param->value == 0)
1765      if (inst->condflags == 0 && (UINT32)param->value == 0)
16881766         /* skip */;
16891767      else
16901768         emit_shr_r32_imm(dst, reg, param->value);                           // shr   reg,param
r2724r2725
17061784{
17071785   if (param->type == DRCUML_PTYPE_IMMEDIATE)
17081786   {
1709      if (inst->condflags != 0 && (UINT32)param->value == 0)
1787      if (inst->condflags == 0 && (UINT32)param->value == 0)
17101788         /* skip */;
17111789      else
17121790         emit_shr_m32_imm(dst, MEMPARAMS, param->value);                        // shr   [dest],param
r2724r2725
17281806{
17291807   if (param->type == DRCUML_PTYPE_IMMEDIATE)
17301808   {
1731      if (inst->condflags != 0 && (UINT32)param->value == 0)
1809      if (inst->condflags == 0 && (UINT32)param->value == 0)
17321810         /* skip */;
17331811      else
17341812         emit_sar_r32_imm(dst, reg, param->value);                           // sar   reg,param
r2724r2725
17501828{
17511829   if (param->type == DRCUML_PTYPE_IMMEDIATE)
17521830   {
1753      if (inst->condflags != 0 && (UINT32)param->value == 0)
1831      if (inst->condflags == 0 && (UINT32)param->value == 0)
17541832         /* skip */;
17551833      else
17561834         emit_sar_m32_imm(dst, MEMPARAMS, param->value);                        // sar   [dest],param
r2724r2725
17721850{
17731851   if (param->type == DRCUML_PTYPE_IMMEDIATE)
17741852   {
1775      if (inst->condflags != 0 && (UINT32)param->value == 0)
1853      if (inst->condflags == 0 && (UINT32)param->value == 0)
17761854         /* skip */;
17771855      else
17781856         emit_rol_r32_imm(dst, reg, param->value);                           // rol   reg,param
r2724r2725
17941872{
17951873   if (param->type == DRCUML_PTYPE_IMMEDIATE)
17961874   {
1797      if (inst->condflags != 0 && (UINT32)param->value == 0)
1875      if (inst->condflags == 0 && (UINT32)param->value == 0)
17981876         /* skip */;
17991877      else
18001878         emit_rol_m32_imm(dst, MEMPARAMS, param->value);                        // rol   [dest],param
r2724r2725
18161894{
18171895   if (param->type == DRCUML_PTYPE_IMMEDIATE)
18181896   {
1819      if (inst->condflags != 0 && (UINT32)param->value == 0)
1897      if (inst->condflags == 0 && (UINT32)param->value == 0)
18201898         /* skip */;
18211899      else
18221900         emit_ror_r32_imm(dst, reg, param->value);                           // ror   reg,param
r2724r2725
18381916{
18391917   if (param->type == DRCUML_PTYPE_IMMEDIATE)
18401918   {
1841      if (inst->condflags != 0 && (UINT32)param->value == 0)
1919      if (inst->condflags == 0 && (UINT32)param->value == 0)
18421920         /* skip */;
18431921      else
18441922         emit_ror_m32_imm(dst, MEMPARAMS, param->value);                        // ror   [dest],param
r2724r2725
18601938{
18611939   if (param->type == DRCUML_PTYPE_IMMEDIATE)
18621940   {
1863      if (inst->condflags != 0 && (UINT32)param->value == 0)
1941      if (inst->condflags == 0 && (UINT32)param->value == 0)
18641942         /* skip */;
18651943      else
18661944         emit_rcl_r32_imm(dst, reg, param->value);                           // rcl   reg,param
r2724r2725
18821960{
18831961   if (param->type == DRCUML_PTYPE_IMMEDIATE)
18841962   {
1885      if (inst->condflags != 0 && (UINT32)param->value == 0)
1963      if (inst->condflags == 0 && (UINT32)param->value == 0)
18861964         /* skip */;
18871965      else
18881966         emit_rcl_m32_imm(dst, MEMPARAMS, param->value);                        // rcl   [dest],param
r2724r2725
19041982{
19051983   if (param->type == DRCUML_PTYPE_IMMEDIATE)
19061984   {
1907      if (inst->condflags != 0 && (UINT32)param->value == 0)
1985      if (inst->condflags == 0 && (UINT32)param->value == 0)
19081986         /* skip */;
19091987      else
19101988         emit_rcr_r32_imm(dst, reg, param->value);                           // rcr   reg,param
r2724r2725
19262004{
19272005   if (param->type == DRCUML_PTYPE_IMMEDIATE)
19282006   {
1929      if (inst->condflags != 0 && (UINT32)param->value == 0)
2007      if (inst->condflags == 0 && (UINT32)param->value == 0)
19302008         /* skip */;
19312009      else
19322010         emit_rcr_m32_imm(dst, MEMPARAMS, param->value);                        // rcr   [dest],param
r2724r2725
24482526{
24492527   if (param->type == DRCUML_PTYPE_IMMEDIATE)
24502528   {
2451      if (inst->condflags != 0 && (UINT32)param->value == 0)
2529      if (inst->condflags == 0 && (UINT32)param->value == 0)
24522530         /* skip */;
24532531      else
24542532         emit_shl_r64_imm(dst, reg, param->value);                           // shl   reg,param
r2724r2725
24702548{
24712549   if (param->type == DRCUML_PTYPE_IMMEDIATE)
24722550   {
2473      if (inst->condflags != 0 && (UINT64)param->value == 0)
2551      if (inst->condflags == 0 && (UINT64)param->value == 0)
24742552         /* skip */;
24752553      else
24762554         emit_shl_m64_imm(dst, MEMPARAMS, param->value);                        // shl   [dest],param
r2724r2725
24922570{
24932571   if (param->type == DRCUML_PTYPE_IMMEDIATE)
24942572   {
2495      if (inst->condflags != 0 && (UINT32)param->value == 0)
2573      if (inst->condflags == 0 && (UINT32)param->value == 0)
24962574         /* skip */;
24972575      else
24982576         emit_shr_r64_imm(dst, reg, param->value);                           // shr   reg,param
r2724r2725
25142592{
25152593   if (param->type == DRCUML_PTYPE_IMMEDIATE)
25162594   {
2517      if (inst->condflags != 0 && (UINT64)param->value == 0)
2595      if (inst->condflags == 0 && (UINT64)param->value == 0)
25182596         /* skip */;
25192597      else
25202598         emit_shr_m64_imm(dst, MEMPARAMS, param->value);                        // shr   [dest],param
r2724r2725
25362614{
25372615   if (param->type == DRCUML_PTYPE_IMMEDIATE)
25382616   {
2539      if (inst->condflags != 0 && (UINT32)param->value == 0)
2617      if (inst->condflags == 0 && (UINT32)param->value == 0)
25402618         /* skip */;
25412619      else
25422620         emit_sar_r64_imm(dst, reg, param->value);                           // sar   reg,param
r2724r2725
25582636{
25592637   if (param->type == DRCUML_PTYPE_IMMEDIATE)
25602638   {
2561      if (inst->condflags != 0 && (UINT64)param->value == 0)
2639      if (inst->condflags == 0 && (UINT64)param->value == 0)
25622640         /* skip */;
25632641      else
25642642         emit_sar_m64_imm(dst, MEMPARAMS, param->value);                        // sar   [dest],param
r2724r2725
25802658{
25812659   if (param->type == DRCUML_PTYPE_IMMEDIATE)
25822660   {
2583      if (inst->condflags != 0 && (UINT32)param->value == 0)
2661      if (inst->condflags == 0 && (UINT32)param->value == 0)
25842662         /* skip */;
25852663      else
25862664         emit_rol_r64_imm(dst, reg, param->value);                           // rol   reg,param
r2724r2725
26022680{
26032681   if (param->type == DRCUML_PTYPE_IMMEDIATE)
26042682   {
2605      if (inst->condflags != 0 && (UINT64)param->value == 0)
2683      if (inst->condflags == 0 && (UINT64)param->value == 0)
26062684         /* skip */;
26072685      else
26082686         emit_rol_m64_imm(dst, MEMPARAMS, param->value);                        // rol   [dest],param
r2724r2725
26242702{
26252703   if (param->type == DRCUML_PTYPE_IMMEDIATE)
26262704   {
2627      if (inst->condflags != 0 && (UINT32)param->value == 0)
2705      if (inst->condflags == 0 && (UINT32)param->value == 0)
26282706         /* skip */;
26292707      else
26302708         emit_ror_r64_imm(dst, reg, param->value);                           // ror   reg,param
r2724r2725
26462724{
26472725   if (param->type == DRCUML_PTYPE_IMMEDIATE)
26482726   {
2649      if (inst->condflags != 0 && (UINT64)param->value == 0)
2727      if (inst->condflags == 0 && (UINT64)param->value == 0)
26502728         /* skip */;
26512729      else
26522730         emit_ror_m64_imm(dst, MEMPARAMS, param->value);                        // ror   [dest],param
r2724r2725
26682746{
26692747   if (param->type == DRCUML_PTYPE_IMMEDIATE)
26702748   {
2671      if (inst->condflags != 0 && (UINT32)param->value == 0)
2749      if (inst->condflags == 0 && (UINT32)param->value == 0)
26722750         /* skip */;
26732751      else
26742752         emit_rcl_r64_imm(dst, reg, param->value);                           // rcl   reg,param
r2724r2725
26902768{
26912769   if (param->type == DRCUML_PTYPE_IMMEDIATE)
26922770   {
2693      if (inst->condflags != 0 && (UINT64)param->value == 0)
2771      if (inst->condflags == 0 && (UINT64)param->value == 0)
26942772         /* skip */;
26952773      else
26962774         emit_rcl_m64_imm(dst, MEMPARAMS, param->value);                        // rcl   [dest],param
r2724r2725
27122790{
27132791   if (param->type == DRCUML_PTYPE_IMMEDIATE)
27142792   {
2715      if (inst->condflags != 0 && (UINT32)param->value == 0)
2793      if (inst->condflags == 0 && (UINT32)param->value == 0)
27162794         /* skip */;
27172795      else
27182796         emit_rcr_r64_imm(dst, reg, param->value);                           // rcr   reg,param
r2724r2725
27342812{
27352813   if (param->type == DRCUML_PTYPE_IMMEDIATE)
27362814   {
2737      if (inst->condflags != 0 && (UINT64)param->value == 0)
2815      if (inst->condflags == 0 && (UINT64)param->value == 0)
27382816         /* skip */;
27392817      else
27402818         emit_rcr_m64_imm(dst, MEMPARAMS, param->value);                        // rcr   [dest],param
r2724r2725
29693047   drcuml_handle_set_codeptr((drcuml_codehandle *)(FPTR)inst->param[0].value, dst);
29703048
29713049   /* by default, the handle points to prolog code that moves the stack pointer */
2972   emit_sub_r64_imm(&dst, REG_RSP, 40);                                    // sub   rsp,40
3050   emit_lea_r64_m64(&dst, REG_RSP, MBD(REG_RSP, -40));                           // lea   rsp,[rsp-40]
29733051   return dst;
29743052}
29753053
r2724r2725
31723250   }
31733251
31743252   /* in all cases, if there is no code, we return here to generate the exception */
3175   emit_mov_m32_p32(drcbe, &dst, MABS(drcbe, &drcbe->state.exp.l), &pcp);            // mov   [exp],param
3253   emit_mov_m32_p32(drcbe, &dst, MABS(drcbe, &drcbe->state.exp), &pcp);            // mov   [exp],param
31763254   emit_sub_r64_imm(&dst, REG_RSP, 8);                                       // sub   rsp,8
31773255   emit_call_m64(&dst, MABS(drcbe, exp.value));                              // call  [exp]
31783256
r2724r2725
32313309   /* perform the exception processing inline if unconditional */
32323310   if (inst->condflags == DRCUML_COND_ALWAYS)
32333311   {
3234      emit_mov_m32_p32(drcbe, &dst, MABS(drcbe, &drcbe->state.exp.l), &exp);         // mov   [exp],exp
3312      emit_mov_m32_p32(drcbe, &dst, MABS(drcbe, &drcbe->state.exp), &exp);         // mov   [exp],exp
32353313      if (*targetptr != NULL)
32363314         emit_call(&dst, *targetptr);                                    // call  *targetptr
32373315      else
r2724r2725
33033381      emit_jcc_short_link(&dst, X86_NOT_CONDITION(inst->condflags), &skip);         // jcc   skip
33043382
33053383   /* return */
3306   emit_add_r64_imm(&dst, REG_RSP, 40);                                    // add   rsp,40
3384   emit_lea_r64_m64(&dst, REG_RSP, MBD(REG_RSP, 40));                           // lea   rsp,[rsp+40]
33073385   emit_ret(&dst);                                                      // ret
33083386
33093387   /* resolve the conditional link */
r2724r2725
34593537
34603538   /* fetch the exception parameter and store to the destination */
34613539   if (dstp.type == DRCUML_PTYPE_INT_REGISTER)
3462      emit_mov_r32_m32(&dst, dstp.value, MABS(drcbe, &drcbe->state.exp.l));               // mov   reg,[exp]
3540      emit_mov_r32_m32(&dst, dstp.value, MABS(drcbe, &drcbe->state.exp));               // mov   reg,[exp]
34633541   else
34643542   {
3465      emit_mov_r32_m32(&dst, REG_EAX, MABS(drcbe, &drcbe->state.exp.l));                  // mov   eax,[exp]
3543      emit_mov_r32_m32(&dst, REG_EAX, MABS(drcbe, &drcbe->state.exp));                  // mov   eax,[exp]
34663544      emit_mov_m32_r32(&dst, MABS(drcbe, dstp.value), REG_EAX);                        // mov   [dstp],eax
34673545   }
34683546
r2724r2725
34703548}
34713549
34723550
3551/*-------------------------------------------------
3552    op_save - process a SAVE opcode
3553-------------------------------------------------*/
34733554
3555static x86code *op_save(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
3556{
3557   drcuml_parameter dstp;
3558   int regnum;
3559
3560   /* validate instruction */
3561   assert(inst->size == 4);
3562   assert(inst->condflags == DRCUML_COND_ALWAYS);
3563
3564   /* normalize parameters */
3565   param_normalize_1(drcbe, inst, &dstp, PTYPE_M);
3566
3567   /* copy live state to the destination */
3568   emit_mov_r64_imm(&dst, REG_RCX, dstp.value);                              // mov    rcx,dstp
3569
3570   /* copy flags */
3571   emit_pushf(&dst);                                                   // pushf
3572   emit_pop_r64(&dst, REG_RAX);                                          // pop    rax
3573   emit_and_r32_imm(&dst, REG_EAX, 0x8c5);                                    // and    eax,0x8c5
3574   emit_mov_r8_m8(&dst, REG_AL, MBISD(REG_RBP, REG_RAX, 1, offset_from_rbp(drcbe, (FPTR)&drcbe->flagsmap[0])));
3575                                                                  // mov    al,[flags_map]
3576   emit_mov_m8_r8(&dst, MBD(REG_RCX, offsetof(drcuml_machine_state, flags)), REG_AL);   // mov    state->flags,al
3577
3578   /* copy fmod and exp */
3579   emit_mov_r8_m8(&dst, REG_AL, MABS(drcbe, &drcbe->state.fmod));                  // mov    al,[fmod]
3580   emit_mov_m8_r8(&dst, MBD(REG_RCX, offsetof(drcuml_machine_state, fmod)), REG_AL);   // mov    state->fmod,al
3581   emit_mov_r32_m32(&dst, REG_EAX, MABS(drcbe, &drcbe->state.exp));               // mov    eax,[exp]
3582   emit_mov_m32_r32(&dst, MBD(REG_RCX, offsetof(drcuml_machine_state, exp)), REG_EAX);   // mov    state->exp,eax
3583
3584   /* copy integer registers */
3585   for (regnum = 0; regnum < ARRAY_LENGTH(drcbe->state.r); regnum++)
3586   {
3587      if (int_register_map[regnum] != 0)
3588         emit_mov_m64_r64(&dst, MBD(REG_RCX, offsetof(drcuml_machine_state, r[regnum].d)), int_register_map[regnum]);
3589      else
3590      {
3591         emit_mov_r64_m64(&dst, REG_RAX, MABS(drcbe, &drcbe->state.r[regnum].d));
3592         emit_mov_m64_r64(&dst, MBD(REG_RCX, offsetof(drcuml_machine_state, r[regnum].d)), REG_RAX);
3593      }
3594   }
3595
3596   /* copy FP registers */
3597   for (regnum = 0; regnum < ARRAY_LENGTH(drcbe->state.f); regnum++)
3598   {
3599      if (float_register_map[regnum] != 0)
3600         emit_movsd_m64_r128(&dst, MBD(REG_RCX, offsetof(drcuml_machine_state, f[regnum].d)), float_register_map[regnum]);
3601      else
3602      {
3603         emit_mov_r64_m64(&dst, REG_RAX, MABS(drcbe, &drcbe->state.f[regnum].d));
3604         emit_mov_m64_r64(&dst, MBD(REG_RCX, offsetof(drcuml_machine_state, f[regnum].d)), REG_RAX);
3605      }
3606   }
3607
3608   return dst;
3609}
3610
3611
3612/*-------------------------------------------------
3613    op_restore - process a RESTORE opcode
3614-------------------------------------------------*/
3615
3616static x86code *op_restore(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
3617{
3618   drcuml_parameter dstp;
3619   int regnum;
3620
3621   /* validate instruction */
3622   assert(inst->size == 4);
3623   assert(inst->condflags == DRCUML_COND_ALWAYS);
3624
3625   /* normalize parameters */
3626   param_normalize_1(drcbe, inst, &dstp, PTYPE_M);
3627
3628   /* copy live state from the destination */
3629   emit_mov_r64_imm(&dst, REG_ECX, dstp.value);                              // mov    rcx,dstp
3630
3631   /* copy integer registers */
3632   for (regnum = 0; regnum < ARRAY_LENGTH(drcbe->state.r); regnum++)
3633   {
3634      if (int_register_map[regnum] != 0)
3635         emit_mov_r64_m64(&dst, int_register_map[regnum], MBD(REG_RCX, offsetof(drcuml_machine_state, r[regnum].d)));
3636      else
3637      {
3638         emit_mov_r64_m64(&dst, REG_RAX, MBD(REG_RCX, offsetof(drcuml_machine_state, r[regnum].d)));
3639         emit_mov_m64_r64(&dst, MABS(drcbe, &drcbe->state.r[regnum].d), REG_RAX);
3640      }
3641   }
3642
3643   /* copy FP registers */
3644   for (regnum = 0; regnum < ARRAY_LENGTH(drcbe->state.f); regnum++)
3645   {
3646      if (float_register_map[regnum] != 0)
3647         emit_movsd_r128_m64(&dst, float_register_map[regnum], MBD(REG_RCX, offsetof(drcuml_machine_state, f[regnum].d)));
3648      else
3649      {
3650         emit_mov_r64_m64(&dst, REG_RAX, MBD(REG_RCX, offsetof(drcuml_machine_state, f[regnum].d)));
3651         emit_mov_m64_r64(&dst, MABS(drcbe, &drcbe->state.f[regnum].d), REG_RAX);
3652      }
3653   }
3654
3655   /* copy fmod and exp */
3656   emit_movzx_r32_m8(&dst, REG_EAX, MBD(REG_RCX, offsetof(drcuml_machine_state, fmod)));// movzx eax,state->fmod
3657   emit_and_r32_imm(&dst, REG_EAX, 3);                                       // and   eax,3
3658   emit_mov_m8_r8(&dst, MABS(drcbe, &drcbe->state.fmod), REG_AL);                  // mov   [fmod],al
3659   emit_ldmxcsr_m32(&dst, MBISD(REG_RBP, REG_RAX, 4, offset_from_rbp(drcbe, (FPTR)&drcbe->ssecontrol[0])));
3660   emit_mov_r32_m32(&dst, REG_EAX, MBD(REG_RCX, offsetof(drcuml_machine_state, exp)));   // mov    eax,state->exp
3661   emit_mov_m32_r32(&dst, MABS(drcbe, &drcbe->state.exp), REG_EAX);               // mov    [exp],eax
3662
3663   /* copy flags */
3664   emit_movzx_r32_m8(&dst, REG_EAX, MBD(REG_RCX, offsetof(drcuml_machine_state, flags)));// movzx eax,state->flags
3665   emit_push_m64(&dst, MBISD(REG_RBP, REG_RAX, 8, offset_from_rbp(drcbe, (FPTR)&drcbe->flagsunmap[0])));
3666                                                                  // push   flags_unmap[eax*8]
3667   emit_popf(&dst);                                                   // popf
3668
3669   return dst;
3670}
3671
3672
3673
34743674/***************************************************************************
34753675    INTEGER OPERATIONS
34763676***************************************************************************/
r2724r2725
49915191
49925192
49935193/*-------------------------------------------------
5194    op_xtract - process an XTRACT opcode
5195-------------------------------------------------*/
5196
5197static x86code *op_xtract(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
5198{
5199   drcuml_parameter dstp, srcp, shiftp, maskp;
5200   int dstreg;
5201
5202   /* validate instruction */
5203   assert(inst->size == 4 || inst->size == 8);
5204   assert(inst->condflags == DRCUML_COND_ALWAYS);
5205
5206   /* normalize parameters */
5207   param_normalize_4(drcbe, inst, &dstp, PTYPE_MR, &srcp, PTYPE_MRI, &shiftp, PTYPE_MRI, &maskp, PTYPE_MRI);
5208
5209   /* degenerate cases -- convert to a move or simple shift */
5210   if (srcp.type == DRCUML_PTYPE_IMMEDIATE && shiftp.type == DRCUML_PTYPE_IMMEDIATE && maskp.type == DRCUML_PTYPE_IMMEDIATE)
5211   {
5212      if (inst->size == 4)
5213         return convert_to_mov_imm(drcbe, dst, inst, &dstp, ((srcp.value << shiftp.value) | (srcp.value >> (32 - shiftp.value))) & maskp.value);
5214      else if (inst->size == 8)
5215         return convert_to_mov_imm(drcbe, dst, inst, &dstp, ((srcp.value << shiftp.value) | (srcp.value >> (64 - shiftp.value))) & maskp.value);
5216   }
5217   if (shiftp.type == DRCUML_PTYPE_IMMEDIATE && maskp.type == DRCUML_PTYPE_IMMEDIATE)
5218   {
5219      if ((inst->size == 4 && maskp.value == (UINT32)(0xffffffffUL << shiftp.value)) || (inst->size == 8 && maskp.value == U64(0xffffffffffffffff) << shiftp.value))
5220      {
5221         drcuml_instruction temp = *inst;
5222         temp.numparams = 3;
5223         return op_shl(drcbe, dst, &temp);
5224      }
5225      if ((inst->size == 4 && maskp.value == (UINT32)(0xffffffffUL >> (32 - shiftp.value))) || (inst->size == 8 && maskp.value == U64(0xffffffffffffffff) >> (64 - shiftp.value)))
5226      {
5227         drcuml_instruction temp = *inst;
5228         temp.numparams = 3;
5229         temp.param[2].value = inst->size * 8 - temp.param[2].value;
5230         return op_shr(drcbe, dst, &temp);
5231      }
5232   }
5233
5234   /* pick a target register for the general case */
5235   dstreg = param_select_register2(REG_EAX, &dstp, &shiftp, &maskp);
5236
5237   /* 32-bit form */
5238   if (inst->size == 4)
5239   {
5240      emit_mov_r32_p32(drcbe, &dst, dstreg, &srcp);                           // mov   dstreg,srcp
5241      emit_rol_r32_p32(drcbe, &dst, dstreg, &shiftp, inst);                     // rol   dstreg,shiftp
5242      emit_and_r32_p32(drcbe, &dst, dstreg, &maskp, inst);                     // and   dstreg,maskp
5243      emit_mov_p32_r32(drcbe, &dst, &dstp, dstreg);                           // mov   dstp,dstreg
5244   }
5245
5246   /* 64-bit form */
5247   else if (inst->size == 8)
5248   {
5249      emit_mov_r64_p64(drcbe, &dst, dstreg, &srcp);                           // mov   dstreg,srcp
5250      emit_rol_r64_p64(drcbe, &dst, dstreg, &shiftp, inst);                     // rol   dstreg,shiftp
5251      emit_and_r64_p64(drcbe, &dst, dstreg, &maskp, inst);                     // and   dstreg,maskp
5252      emit_mov_p64_r64(drcbe, &dst, &dstp, dstreg);                           // mov   dstp,dstreg
5253   }
5254   return dst;
5255}
5256
5257
5258/*-------------------------------------------------
5259    op_insert - process an INSERT opcode
5260-------------------------------------------------*/
5261
5262static x86code *op_insert(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
5263{
5264   drcuml_parameter dstp, srcp, shiftp, maskp;
5265   int dstreg;
5266
5267   /* validate instruction */
5268   assert(inst->size == 4 || inst->size == 8);
5269   assert(inst->condflags == DRCUML_COND_ALWAYS);
5270
5271   /* normalize parameters */
5272   param_normalize_4(drcbe, inst, &dstp, PTYPE_MR, &srcp, PTYPE_MRI, &shiftp, PTYPE_MRI, &maskp, PTYPE_MRI);
5273
5274   /* pick a target register for the general case */
5275   dstreg = param_select_register2(REG_ECX, &dstp, &shiftp, &maskp);
5276
5277   /* 32-bit form */
5278   if (inst->size == 4)
5279   {
5280      emit_mov_r32_p32(drcbe, &dst, REG_EAX, &srcp);                           // mov   eax,srcp
5281      emit_rol_r32_p32(drcbe, &dst, REG_EAX, &shiftp, inst);                     // rol   eax,shiftp
5282      emit_mov_r32_p32(drcbe, &dst, dstreg, &dstp);                           // mov   dstreg,dstp
5283      if (maskp.type == DRCUML_PTYPE_IMMEDIATE)
5284      {
5285         emit_and_r32_imm(&dst, REG_EAX, maskp.value);                        // and   eax,maskp
5286         emit_and_r32_imm(&dst, dstreg, ~maskp.value);                        // and   dstreg,~maskp
5287      }
5288      else
5289      {
5290         emit_mov_r32_p32(drcbe, &dst, REG_EDX, &maskp);                        // mov   edx,maskp
5291         emit_and_r32_r32(&dst, REG_EAX, REG_EDX);                           // and   eax,edx
5292         emit_not_r32(&dst, REG_EDX);                                    // not   edx
5293         emit_and_r32_r32(&dst, dstreg, REG_EDX);                           // and   dstreg,edx
5294      }
5295      emit_or_r32_r32(&dst, dstreg, REG_EAX);                                 // or    dstreg,eax
5296      emit_mov_p32_r32(drcbe, &dst, &dstp, dstreg);                           // mov   dstp,dstreg
5297   }
5298
5299   /* 64-bit form */
5300   else if (inst->size == 8)
5301   {
5302      emit_mov_r64_p64(drcbe, &dst, REG_RAX, &srcp);                           // mov   rax,srcp
5303      emit_mov_r64_p64(drcbe, &dst, REG_RDX, &maskp);                           // mov   rdx,maskp
5304      emit_rol_r64_p64(drcbe, &dst, REG_RAX, &shiftp, inst);                     // rol   rax,shiftp
5305      emit_mov_r64_p64(drcbe, &dst, dstreg, &dstp);                           // mov   dstreg,dstp
5306      emit_and_r64_r64(&dst, REG_RAX, REG_RDX);                              // and   eax,rdx
5307      emit_not_r64(&dst, REG_RDX);                                       // not   rdx
5308      emit_and_r64_r64(&dst, dstreg, REG_RDX);                              // and   dstreg,rdx
5309      emit_or_r64_r64(&dst, dstreg, REG_RAX);                                 // or    dstreg,rax
5310      emit_mov_p64_r64(drcbe, &dst, &dstp, dstreg);                           // mov   dstp,dstreg
5311   }
5312   return dst;
5313}
5314
5315
5316/*-------------------------------------------------
49945317    op_add - process a ADD opcode
49955318-------------------------------------------------*/
49965319
r2724r2725
50205343   {
50215344      /* dstp == src1p in memory */
50225345      if (dstp.type == DRCUML_PTYPE_MEMORY && src1p.type == DRCUML_PTYPE_MEMORY && src1p.value == dstp.value)
5023         emit_add_m32_p32(drcbe, &dst, MABS(drcbe, dstp.value), &src2p, inst);            // add   [dstp],src2p
5346         emit_add_m32_p32(drcbe, &dst, MABS(drcbe, dstp.value), &src2p, inst);      // add   [dstp],src2p
50245347
50255348      /* reg = reg + imm */
50265349      else if (dstp.type == DRCUML_PTYPE_INT_REGISTER && src1p.type == DRCUML_PTYPE_INT_REGISTER && src2p.type == DRCUML_PTYPE_IMMEDIATE && inst->condflags == 0)
r2724r2725
59026225
59036226
59046227/*-------------------------------------------------
6228    op_lzcnt - process a LZCNT opcode
6229-------------------------------------------------*/
6230
6231static x86code *op_lzcnt(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
6232{
6233   drcuml_parameter dstp, srcp;
6234   int dstreg;
6235
6236   /* validate instruction */
6237   assert(inst->size == 4 || inst->size == 8);
6238   assert(inst->condflags == 0);
6239
6240   /* normalize parameters */
6241   param_normalize_2(drcbe, inst, &dstp, PTYPE_MR, &srcp, PTYPE_MRI);
6242
6243   /* degenerate cases -- convert to a move */
6244   if (srcp.type == DRCUML_PTYPE_IMMEDIATE && inst->condflags == 0)
6245      return convert_to_mov_imm(drcbe, dst, inst, &dstp, count_leading_zeros(srcp.value));
6246
6247   /* pick a target register for the general case */
6248   dstreg = param_select_register(REG_EAX, &dstp, &srcp);
6249
6250   /* 32-bit form */
6251   if (inst->size == 4)
6252   {
6253      emit_mov_r32_p32(drcbe, &dst, dstreg, &srcp);                           // mov   dstreg,src1p
6254      emit_mov_r32_imm(&dst, REG_ECX, 32);                                 // mov   ecx,32
6255      emit_bsr_r32_r32(&dst, dstreg, dstreg);                                 // bsr   dstreg,dstreg
6256      emit_cmovcc_r32_r32(&dst, COND_Z, dstreg, REG_ECX);                        // cmovz dstreg,ecx
6257      emit_mov_p32_r32(drcbe, &dst, &dstp, dstreg);                           // mov   dstp,dstreg
6258   }
6259
6260   /* 64-bit form */
6261   else if (inst->size == 8)
6262   {
6263      emit_mov_r64_p64(drcbe, &dst, dstreg, &srcp);                           // mov   dstreg,src1p
6264      emit_mov_r64_imm(&dst, REG_RCX, 64);                                 // mov   rcx,64
6265      emit_bsr_r64_r64(&dst, dstreg, dstreg);                                 // bsr   dstreg,dstreg
6266      emit_cmovcc_r64_r64(&dst, COND_Z, dstreg, REG_RCX);                        // cmovz dstreg,rcx
6267      emit_mov_p64_r64(drcbe, &dst, &dstp, dstreg);                           // mov   dstp,dstreg
6268   }
6269   return dst;
6270}
6271
6272
6273/*-------------------------------------------------
59056274    op_shl - process a SHL opcode
59066275-------------------------------------------------*/
59076276
r2724r2725
66547023
66557024
66567025/*-------------------------------------------------
6657    op_ftoi4r - process a FTOI4R opcode
7026    op_ftoi4x - process a FTOI4R/F/C opcode
66587027-------------------------------------------------*/
66597028
6660static x86code *op_ftoi4r(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
7029static x86code *op_ftoi4x(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst, int mode)
66617030{
66627031   drcuml_parameter dstp, srcp;
66637032   int dstreg;
r2724r2725
66727041   /* pick a target register for the general case */
66737042   dstreg = param_select_register(REG_EAX, &dstp, NULL);
66747043
6675   /* save and set the control word */
6676   emit_stmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssemodesave));                     // stmxcsr [ssemodesave]
6677   emit_ldmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssecontrol[DRCUML_FMOD_ROUND]));         // ldmxcsr fpcontrol[DRCUML_FMOD_ROUND]
7044   /* non-SSE4.1 case */
7045   if (!drcbe->sse41 || inst->size == 8)
7046   {
7047      /* save and set the control word */
7048      emit_stmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssemodesave));                  // stmxcsr [ssemodesave]
7049      emit_ldmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssecontrol[mode]));               // ldmxcsr fpcontrol[mode]
66787050
6679   /* 32-bit form */
6680   if (inst->size == 4)
6681   {
6682      if (srcp.type == DRCUML_PTYPE_MEMORY)
6683         emit_cvtss2si_r32_m32(&dst, dstreg, MABS(drcbe, srcp.value));            // cvtss2si dstreg,[srcp]
6684      else if (srcp.type == DRCUML_PTYPE_FLOAT_REGISTER)
6685         emit_cvtss2si_r32_r128(&dst, dstreg, srcp.value);                     // cvtss2si dstreg,srcp
7051      /* 32-bit form */
7052      if (inst->size == 4)
7053      {
7054         if (srcp.type == DRCUML_PTYPE_MEMORY)
7055            emit_cvtss2si_r32_m32(&dst, dstreg, MABS(drcbe, srcp.value));         // cvtss2si dstreg,[srcp]
7056         else if (srcp.type == DRCUML_PTYPE_FLOAT_REGISTER)
7057            emit_cvtss2si_r32_r128(&dst, dstreg, srcp.value);                  // cvtss2si dstreg,srcp
7058      }
7059
7060      /* 64-bit form */
7061      else if (inst->size == 8)
7062      {
7063         if (srcp.type == DRCUML_PTYPE_MEMORY)
7064            emit_cvtsd2si_r32_m64(&dst, dstreg, MABS(drcbe, srcp.value));         // cvtsd2si dstreg,[srcp]
7065         else if (srcp.type == DRCUML_PTYPE_FLOAT_REGISTER)
7066            emit_cvtsd2si_r32_r128(&dst, dstreg, srcp.value);                  // cvtsd2si dstreg,srcp
7067      }
7068
7069      /* restore control word and proceed */
7070      emit_mov_p32_r32(drcbe, &dst, &dstp, dstreg);                           // mov   dstp,dstreg
7071      emit_ldmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssemodesave));                  // ldmxcsr [ssemodesave]
66867072   }
66877073
6688   /* 64-bit form */
6689   else if (inst->size == 8)
7074   /* SSE4.1 case */
7075   else
66907076   {
7077      /* 32-bit form */
66917078      if (srcp.type == DRCUML_PTYPE_MEMORY)
6692         emit_cvtsd2si_r32_m64(&dst, dstreg, MABS(drcbe, srcp.value));            // cvtsd2si dstreg,[srcp]
7079         emit_roundss_r128_m32_imm(&dst, REG_XMM0, MABS(drcbe, srcp.value), fprnd_map[mode]);
7080                                                                  // roundss  xmm0,[srcp],mode
66937081      else if (srcp.type == DRCUML_PTYPE_FLOAT_REGISTER)
6694         emit_cvtsd2si_r32_r128(&dst, dstreg, srcp.value);                     // cvtsd2si dstreg,srcp
7082         emit_roundss_r128_r128_imm(&dst, REG_XMM0, srcp.value, fprnd_map[mode]);   // roundss  xmm0,srcp,mode
7083
7084      /* store to the destination */
7085      if (dstp.type == DRCUML_PTYPE_MEMORY)
7086         emit_movd_m32_r128(&dst, MABS(drcbe, dstp.value), REG_XMM0);            // movd     [dstp],xmm0
7087      else if (dstp.type == DRCUML_PTYPE_INT_REGISTER)
7088         emit_movd_r32_r128(&dst, dstp.value, REG_XMM0);                        // movd     dstp,xmm0
66957089   }
7090   return dst;
66967091
6697   /* restore control word and proceed */
6698   emit_mov_p32_r32(drcbe, &dst, &dstp, dstreg);                              // mov   dstp,dstreg
6699   emit_ldmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssemodesave));                     // ldmxcsr [ssemodesave]
6700   return dst;
67017092}
67027093
7094static x86code *op_ftoi4r(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
7095{
7096   return op_ftoi4x(drcbe, dst, inst, DRCUML_FMOD_ROUND);
7097}
67037098
6704/*-------------------------------------------------
6705    op_ftoi4f - process a FTOI4F opcode
6706-------------------------------------------------*/
6707
67087099static x86code *op_ftoi4f(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
67097100{
6710   drcuml_parameter dstp, srcp;
6711   int dstreg;
6712
6713   /* validate instruction */
6714   assert(inst->size == 4 || inst->size == 8);
6715   assert(inst->condflags == DRCUML_COND_ALWAYS);
6716
6717   /* normalize parameters */
6718   param_normalize_2(drcbe, inst, &dstp, PTYPE_MR, &srcp, PTYPE_MF);
6719
6720   /* pick a target register for the general case */
6721   dstreg = param_select_register(REG_EAX, &dstp, NULL);
6722
6723   /* save and set the control word */
6724   emit_stmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssemodesave));                     // stmxcsr [ssemodesave]
6725   emit_ldmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssecontrol[DRCUML_FMOD_FLOOR]));         // ldmxcsr fpcontrol[DRCUML_FMOD_FLOOR]
6726
6727   /* 32-bit form */
6728   if (inst->size == 4)
6729   {
6730      if (srcp.type == DRCUML_PTYPE_MEMORY)
6731         emit_cvtss2si_r32_m32(&dst, dstreg, MABS(drcbe, srcp.value));            // cvtss2si dstreg,[srcp]
6732      else if (srcp.type == DRCUML_PTYPE_FLOAT_REGISTER)
6733         emit_cvtss2si_r32_r128(&dst, dstreg, srcp.value);                     // cvtss2si dstreg,srcp
6734   }
6735
6736   /* 64-bit form */
6737   else if (inst->size == 8)
6738   {
6739      if (srcp.type == DRCUML_PTYPE_MEMORY)
6740         emit_cvtsd2si_r32_m64(&dst, dstreg, MABS(drcbe, srcp.value));            // cvtsd2si dstreg,[srcp]
6741      else if (srcp.type == DRCUML_PTYPE_FLOAT_REGISTER)
6742         emit_cvtsd2si_r32_r128(&dst, dstreg, srcp.value);                     // cvtsd2si dstreg,srcp
6743   }
6744
6745   /* restore control word and proceed */
6746   emit_mov_p32_r32(drcbe, &dst, &dstp, dstreg);                              // mov   dstp,dstreg
6747   emit_ldmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssemodesave));                     // ldmxcsr [ssemodesave]
6748   return dst;
7101   return op_ftoi4x(drcbe, dst, inst, DRCUML_FMOD_FLOOR);
67497102}
67507103
6751
6752/*-------------------------------------------------
6753    op_ftoi4c - process a FTOI4C opcode
6754-------------------------------------------------*/
6755
67567104static x86code *op_ftoi4c(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
67577105{
6758   drcuml_parameter dstp, srcp;
6759   int dstreg;
6760
6761   /* validate instruction */
6762   assert(inst->size == 4 || inst->size == 8);
6763   assert(inst->condflags == DRCUML_COND_ALWAYS);
6764
6765   /* normalize parameters */
6766   param_normalize_2(drcbe, inst, &dstp, PTYPE_MR, &srcp, PTYPE_MF);
6767
6768   /* pick a target register for the general case */
6769   dstreg = param_select_register(REG_EAX, &dstp, NULL);
6770
6771   /* save and set the control word */
6772   emit_stmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssemodesave));                     // stmxcsr [ssemodesave]
6773   emit_ldmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssecontrol[DRCUML_FMOD_CEIL]));         // ldmxcsr fpcontrol[DRCUML_FMOD_CEIL]
6774
6775   /* 32-bit form */
6776   if (inst->size == 4)
6777   {
6778      if (srcp.type == DRCUML_PTYPE_MEMORY)
6779         emit_cvtss2si_r32_m32(&dst, dstreg, MABS(drcbe, srcp.value));            // cvtss2si dstreg,[srcp]
6780      else if (srcp.type == DRCUML_PTYPE_FLOAT_REGISTER)
6781         emit_cvtss2si_r32_r128(&dst, dstreg, srcp.value);                     // cvtss2si dstreg,srcp
6782   }
6783
6784   /* 64-bit form */
6785   else if (inst->size == 8)
6786   {
6787      if (srcp.type == DRCUML_PTYPE_MEMORY)
6788         emit_cvtsd2si_r32_m64(&dst, dstreg, MABS(drcbe, srcp.value));            // cvtsd2si dstreg,[srcp]
6789      else if (srcp.type == DRCUML_PTYPE_FLOAT_REGISTER)
6790         emit_cvtsd2si_r32_r128(&dst, dstreg, srcp.value);                     // cvtsd2si dstreg,srcp
6791   }
6792
6793   /* restore control word and proceed */
6794   emit_mov_p32_r32(drcbe, &dst, &dstp, dstreg);                              // mov   dstp,dstreg
6795   emit_ldmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssemodesave));                     // ldmxcsr [ssemodesave]
6796   return dst;
7106   return op_ftoi4x(drcbe, dst, inst, DRCUML_FMOD_CEIL);
67977107}
67987108
67997109
r2724r2725
68847194
68857195
68867196/*-------------------------------------------------
6887    op_ftoi8r - process a FTOI8R opcode
7197    op_ftoi8x - process a FTOI8R/F/C opcode
68887198-------------------------------------------------*/
68897199
6890static x86code *op_ftoi8r(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
7200static x86code *op_ftoi8x(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst, int mode)
68917201{
68927202   drcuml_parameter dstp, srcp;
68937203   int dstreg;
r2724r2725
69027212   /* pick a target register for the general case */
69037213   dstreg = param_select_register(REG_EAX, &dstp, NULL);
69047214
6905   /* save and set the control word */
6906   emit_stmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssemodesave));                     // stmxcsr [ssemodesave]
6907   emit_ldmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssecontrol[DRCUML_FMOD_ROUND]));         // ldmxcsr fpcontrol[DRCUML_FMOD_ROUND]
7215   /* non-SSE4.1 case */
7216   if (!drcbe->sse41 || inst->size == 4)
7217   {
7218      /* save and set the control word */
7219      emit_stmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssemodesave));                  // stmxcsr [ssemodesave]
7220      emit_ldmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssecontrol[mode]));               // ldmxcsr fpcontrol[mode]
69087221
6909   /* 32-bit form */
6910   if (inst->size == 4)
6911   {
6912      if (srcp.type == DRCUML_PTYPE_MEMORY)
6913         emit_cvtss2si_r64_m32(&dst, dstreg, MABS(drcbe, srcp.value));            // cvtss2si dstreg,[srcp]
6914      else if (srcp.type == DRCUML_PTYPE_FLOAT_REGISTER)
6915         emit_cvtss2si_r64_r128(&dst, dstreg, srcp.value);                     // cvtss2si dstreg,srcp
7222      /* 32-bit form */
7223      if (inst->size == 4)
7224      {
7225         if (srcp.type == DRCUML_PTYPE_MEMORY)
7226            emit_cvtss2si_r64_m32(&dst, dstreg, MABS(drcbe, srcp.value));         // cvtss2si dstreg,[srcp]
7227         else if (srcp.type == DRCUML_PTYPE_FLOAT_REGISTER)
7228            emit_cvtss2si_r64_r128(&dst, dstreg, srcp.value);                  // cvtss2si dstreg,srcp
7229      }
7230
7231      /* 64-bit form */
7232      else if (inst->size == 8)
7233      {
7234         if (srcp.type == DRCUML_PTYPE_MEMORY)
7235            emit_cvtsd2si_r64_m64(&dst, dstreg, MABS(drcbe, srcp.value));         // cvtsd2si dstreg,[srcp]
7236         else if (srcp.type == DRCUML_PTYPE_FLOAT_REGISTER)
7237            emit_cvtsd2si_r64_r128(&dst, dstreg, srcp.value);                  // cvtsd2si dstreg,srcp
7238      }
7239
7240      /* restore control word and proceed */
7241      emit_mov_p64_r64(drcbe, &dst, &dstp, dstreg);                           // mov   dstp,dstreg
7242      emit_ldmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssemodesave));                  // ldmxcsr [ssemodesave]
69167243   }
69177244
6918   /* 64-bit form */
6919   else if (inst->size == 8)
7245   /* SSE4.1 case */
7246   else
69207247   {
7248      /* 64-bit form */
69217249      if (srcp.type == DRCUML_PTYPE_MEMORY)
6922         emit_cvtsd2si_r64_m64(&dst, dstreg, MABS(drcbe, srcp.value));            // cvtsd2si dstreg,[srcp]
7250         emit_roundsd_r128_m64_imm(&dst, REG_XMM0, MABS(drcbe, srcp.value), fprnd_map[mode]);
7251                                                                  // roundsd  xmm0,[srcp],mode
69237252      else if (srcp.type == DRCUML_PTYPE_FLOAT_REGISTER)
6924         emit_cvtsd2si_r64_r128(&dst, dstreg, srcp.value);                     // cvtsd2si dstreg,srcp
7253         emit_roundsd_r128_r128_imm(&dst, REG_XMM0, srcp.value, fprnd_map[mode]);   // roundsd  xmm0,srcp,mode
7254
7255      /* store to the destination */
7256      if (dstp.type == DRCUML_PTYPE_MEMORY)
7257         emit_movq_m64_r128(&dst, MABS(drcbe, dstp.value), REG_XMM0);            // movq     [dstp],xmm0
7258      else if (dstp.type == DRCUML_PTYPE_INT_REGISTER)
7259         emit_movq_r64_r128(&dst, dstp.value, REG_XMM0);                        // movq     dstp,xmm0
69257260   }
7261   return dst;
69267262
6927   /* restore control word and proceed */
6928   emit_mov_p64_r64(drcbe, &dst, &dstp, dstreg);                              // mov   dstp,dstreg
6929   emit_ldmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssemodesave));                     // ldmxcsr [ssemodesave]
6930   return dst;
69317263}
69327264
7265static x86code *op_ftoi8r(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
7266{
7267   return op_ftoi8x(drcbe, dst, inst, DRCUML_FMOD_ROUND);
7268}
69337269
6934/*-------------------------------------------------
6935    op_ftoi8f - process a FTOI8F opcode
6936-------------------------------------------------*/
6937
69387270static x86code *op_ftoi8f(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
69397271{
6940   drcuml_parameter dstp, srcp;
6941   int dstreg;
6942
6943   /* validate instruction */
6944   assert(inst->size == 4 || inst->size == 8);
6945   assert(inst->condflags == DRCUML_COND_ALWAYS);
6946
6947   /* normalize parameters */
6948   param_normalize_2(drcbe, inst, &dstp, PTYPE_MR, &srcp, PTYPE_MF);
6949
6950   /* pick a target register for the general case */
6951   dstreg = param_select_register(REG_EAX, &dstp, NULL);
6952
6953   /* save and set the control word */
6954   emit_stmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssemodesave));                     // stmxcsr [ssemodesave]
6955   emit_ldmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssecontrol[DRCUML_FMOD_FLOOR]));         // ldmxcsr fpcontrol[DRCUML_FMOD_FLOOR]
6956
6957   /* 32-bit form */
6958   if (inst->size == 4)
6959   {
6960      if (srcp.type == DRCUML_PTYPE_MEMORY)
6961         emit_cvtss2si_r64_m32(&dst, dstreg, MABS(drcbe, srcp.value));            // cvtss2si dstreg,[srcp]
6962      else if (srcp.type == DRCUML_PTYPE_FLOAT_REGISTER)
6963         emit_cvtss2si_r64_r128(&dst, dstreg, srcp.value);                     // cvtss2si dstreg,srcp
6964   }
6965
6966   /* 64-bit form */
6967   else if (inst->size == 8)
6968   {
6969      if (srcp.type == DRCUML_PTYPE_MEMORY)
6970         emit_cvtsd2si_r64_m64(&dst, dstreg, MABS(drcbe, srcp.value));            // cvtsd2si dstreg,[srcp]
6971      else if (srcp.type == DRCUML_PTYPE_FLOAT_REGISTER)
6972         emit_cvtsd2si_r64_r128(&dst, dstreg, srcp.value);                     // cvtsd2si dstreg,srcp
6973   }
6974
6975   /* restore control word and proceed */
6976   emit_mov_p64_r64(drcbe, &dst, &dstp, dstreg);                              // mov   dstp,dstreg
6977   emit_ldmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssemodesave));                     // ldmxcsr [ssemodesave]
6978   return dst;
7272   return op_ftoi8x(drcbe, dst, inst, DRCUML_FMOD_FLOOR);
69797273}
69807274
6981
6982/*-------------------------------------------------
6983    op_ftoi8c - process a FTOI8C opcode
6984-------------------------------------------------*/
6985
69867275static x86code *op_ftoi8c(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
69877276{
6988   drcuml_parameter dstp, srcp;
6989   int dstreg;
6990
6991   /* validate instruction */
6992   assert(inst->size == 4 || inst->size == 8);
6993   assert(inst->condflags == DRCUML_COND_ALWAYS);
6994
6995   /* normalize parameters */
6996   param_normalize_2(drcbe, inst, &dstp, PTYPE_MR, &srcp, PTYPE_MF);
6997
6998   /* pick a target register for the general case */
6999   dstreg = param_select_register(REG_EAX, &dstp, NULL);
7000
7001   /* save and set the control word */
7002   emit_stmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssemodesave));                     // stmxcsr [ssemodesave]
7003   emit_ldmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssecontrol[DRCUML_FMOD_CEIL]));         // ldmxcsr fpcontrol[DRCUML_FMOD_CEIL]
7004
7005   /* 32-bit form */
7006   if (inst->size == 4)
7007   {
7008      if (srcp.type == DRCUML_PTYPE_MEMORY)
7009         emit_cvtss2si_r64_m32(&dst, dstreg, MABS(drcbe, srcp.value));            // cvtss2si dstreg,[srcp]
7010      else if (srcp.type == DRCUML_PTYPE_FLOAT_REGISTER)
7011         emit_cvtss2si_r64_r128(&dst, dstreg, srcp.value);                     // cvtss2si dstreg,srcp
7012   }
7013
7014   /* 64-bit form */
7015   else if (inst->size == 8)
7016   {
7017      if (srcp.type == DRCUML_PTYPE_MEMORY)
7018         emit_cvtsd2si_r64_m64(&dst, dstreg, MABS(drcbe, srcp.value));            // cvtsd2si dstreg,[srcp]
7019      else if (srcp.type == DRCUML_PTYPE_FLOAT_REGISTER)
7020         emit_cvtsd2si_r64_r128(&dst, dstreg, srcp.value);                     // cvtsd2si dstreg,srcp
7021   }
7022
7023   /* restore control word and proceed */
7024   emit_mov_p64_r64(drcbe, &dst, &dstp, dstreg);                              // mov   dstp,dstreg
7025   emit_ldmxcsr_m32(&dst, MABS(drcbe, &drcbe->ssemodesave));                     // ldmxcsr [ssemodesave]
7026   return dst;
7277   return op_ftoi8x(drcbe, dst, inst, DRCUML_FMOD_CEIL);
70277278}
70287279
70297280
src/emu/cpu/drcbec.c
r2724r2725
154154   float *            pfloat;
155155   double *         pdouble;
156156   void            (*cfunc)(void *);
157   drcuml_machine_state *state;
157158   const drcuml_codehandle *handle;
158159   const drcbec_instruction *inst;
159160   const drcbec_instruction **pinst;
r2724r2725
172173static int drcbec_execute(drcbe_state *state, drcuml_codehandle *entry);
173174static void drcbec_generate(drcbe_state *drcbe, drcuml_block *block, const drcuml_instruction *instlist, UINT32 numinst);
174175static int drcbec_hash_exists(drcbe_state *state, UINT32 mode, UINT32 pc);
176static void drcbec_get_info(drcbe_state *state, drcbe_info *info);
175177
176178/* private helper functions */
177static void output_parameter(drcbe_state *drcbe, drcbec_instruction **dstptr, void **immedptr, int size, int immedsize, const drcuml_parameter *param);
179static void output_parameter(drcbe_state *drcbe, drcbec_instruction **dstptr, void **immedptr, int size, const drcuml_parameter *param);
178180static void fixup_label(void *parameter, drccodeptr labelcodeptr);
179181static int dmulu(UINT64 *dstlo, UINT64 *dsthi, UINT64 src1, UINT64 src2, int flags);
180182static int dmuls(UINT64 *dstlo, UINT64 *dsthi, INT64 src1, INT64 src2, int flags);
r2724r2725
236238   drcbec_reset,
237239   drcbec_execute,
238240   drcbec_generate,
239   drcbec_hash_exists
241   drcbec_hash_exists,
242   drcbec_get_info
240243};
241244
242245
r2724r2725
331334   for (inum = 0; inum < numinst; inum++)
332335   {
333336      const drcuml_instruction *inst = &instlist[inum];
337      UINT8 psize[ARRAY_LENGTH(instlist->param)];
334338      drcuml_instruction modified_inst;
335      int immedsize, immedbytes, immedwords, pnum;
339      int immedbytes, immedwords, pnum;
336340      void *immed;
337341
338342      /* handle most instructions generally, but a few special cases */
r2724r2725
391395               inst = &modified_inst;
392396            }
393397
394            /* determine the maximum size of an immediate; mostly this is just the instruction size */
395            immedsize = inst->size;
398            /* determine the operand size for each operand; mostly this is just the instruction size */
399            for (pnum = 0; pnum < inst->numparams; pnum++)
400               psize[pnum] = inst->size;
401            if ((inst->opcode >= DRCUML_OP_LOAD1U && inst->opcode <= DRCUML_OP_LOAD8U) || inst->opcode == DRCUML_OP_FLOAD)
402               psize[2] = 4;
403            if ((inst->opcode >= DRCUML_OP_STORE1 && inst->opcode <= DRCUML_OP_STORE8) || inst->opcode == DRCUML_OP_FSTORE)
404               psize[1] = 4;
405            if ((inst->opcode >= DRCUML_OP_READ1U && inst->opcode <= DRCUML_OP_READ8M) || inst->opcode == DRCUML_OP_FREAD)
406               psize[1] = psize[2] = 4;
407            if ((inst->opcode >= DRCUML_OP_WRITE1 && inst->opcode <= DRCUML_OP_WRIT8M) || inst->opcode == DRCUML_OP_FWRITE)
408               psize[0] = psize[1] = 4;
409            if (inst->opcode >= DRCUML_OP_FTOI4 && inst->opcode <= DRCUML_OP_FTOI4C)
410               psize[0] = 4;
411            if (inst->opcode >= DRCUML_OP_FTOI8 && inst->opcode <= DRCUML_OP_FTOI8C)
412               psize[0] = 8;
413            if ((inst->opcode >= DRCUML_OP_ZEXT1 && inst->opcode <= DRCUML_OP_SEXT4) || inst->opcode == DRCUML_OP_FFRFS || inst->opcode == DRCUML_OP_FFRI4)
414               psize[1] = 4;
396415            if (inst->opcode == DRCUML_OP_FFRFD || inst->opcode == DRCUML_OP_FFRI8)
397               immedsize = 8;
416               psize[1] = 8;
398417
399418            /* count how many bytes of immediates we need */
400419            immedbytes = 0;
401420            for (pnum = 0; pnum < inst->numparams; pnum++)
402421               if (inst->param[pnum].type == DRCUML_PTYPE_MAPVAR ||
403422                  (inst->param[pnum].type == DRCUML_PTYPE_IMMEDIATE && inst->param[pnum].value != 0))
404                  immedbytes += immedsize;
423                  immedbytes += psize[pnum];
405424
406425            /* compute how many instruction words we need for that */
407426            immedwords = (immedbytes + sizeof(drcbec_instruction) - 1) / sizeof(drcbec_instruction);
r2724r2725
414433
415434            /* output each of the parameters */
416435            for (pnum = 0; pnum < inst->numparams; pnum++)
417               output_parameter(drcbe, &dst, &immed, inst->size, immedsize, &inst->param[pnum]);
436               output_parameter(drcbe, &dst, &immed, psize[pnum], &inst->param[pnum]);
418437
419438            /* point past the end of the immediates */
420439            dst += immedwords;
r2724r2725
444463}
445464
446465
466/*-------------------------------------------------
467    drcbec_get_info - return information about
468    the back-end implementation
469-------------------------------------------------*/
447470
471static void drcbec_get_info(drcbe_state *state, drcbe_info *info)
472{
473   info->direct_iregs = 0;
474   info->direct_fregs = 0;
475}
476
477
478
448479/***************************************************************************
449480    BACK-END EXECUTION
450481***************************************************************************/
r2724r2725
497528            if (newinst == NULL)
498529            {
499530               assert(sp < ARRAY_LENGTH(callstack));
500               drcbe->state.exp.l = PARAM1;
531               drcbe->state.exp = PARAM1;
501532               newinst = (const drcbec_instruction *)drcuml_handle_codeptr(inst[2].handle);
502533               callstack[sp++] = inst;
503534            }
r2724r2725
558589            assert(sp < ARRAY_LENGTH(callstack));
559590            newinst = (const drcbec_instruction *)drcuml_handle_codeptr(inst[0].handle);
560591            assert_in_cache(drcbe->cache, newinst);
561            drcbe->state.exp.l = PARAM1;
592            drcbe->state.exp = PARAM1;
562593            callstack[sp++] = inst;
563594            inst = newinst;
564595            continue;
r2724r2725
589620            break;
590621
591622         case MAKE_OPCODE_SHORT(DRCUML_OP_GETEXP, 4, 0):      /* GETEXP  dst                    */
592            PARAM0 = drcbe->state.exp.l;
623            PARAM0 = drcbe->state.exp;
593624            break;
594625
626         case MAKE_OPCODE_SHORT(DRCUML_OP_SAVE, 4, 0):      /* SAVE    dst                    */
627            *inst[0].state = drcbe->state;
628            inst[0].state->flags = flags;
629            break;
595630
631         case MAKE_OPCODE_SHORT(DRCUML_OP_RESTORE, 4, 0):   /* RESTORE dst                    */
632            drcbe->state = *inst[0].state;
633            flags = inst[0].state->flags;
634            break;
635
636
596637         /* ----------------------- 32-Bit Integer Operations ----------------------- */
597638
598639         case MAKE_OPCODE_SHORT(DRCUML_OP_LOAD1U, 4, 0):      /* LOAD1U  dst,base,index         */
r2724r2725
704745            PARAM0 = (INT16)PARAM1;
705746            break;
706747
748         case MAKE_OPCODE_SHORT(DRCUML_OP_XTRACT, 4, 0):      /* XTRACT  dst,src,count,mask[,f] */
749            shift = PARAM2 & 31;
750            PARAM0 = ((PARAM1 << shift) | (PARAM1 >> (32 - shift))) & PARAM3;
751            break;
752
753         case MAKE_OPCODE_SHORT(DRCUML_OP_INSERT, 4, 0):      /* INSERT  dst,src,count,mask[,f] */
754            shift = PARAM2 & 31;
755            PARAM0 = (PARAM0 & ~PARAM3) | (((PARAM1 << shift) | (PARAM1 >> (32 - shift))) & PARAM3);
756            break;
757
707758         case MAKE_OPCODE_SHORT(DRCUML_OP_ADD, 4, 0):      /* ADD     dst,src1,src2[,f]      */
708759            PARAM0 = PARAM1 + PARAM2;
709760            break;
r2724r2725
720771
721772         case MAKE_OPCODE_SHORT(DRCUML_OP_ADDC, 4, 1):
722773            temp32 = PARAM1 + PARAM2 + (flags & DRCUML_FLAG_C);
723            flags = FLAGS32_NZCV_ADD(temp32, PARAM1, PARAM2);
774            if (PARAM2 + 1 != 0)
775               flags = FLAGS32_NZCV_ADD(temp32, PARAM1, PARAM2 + (flags & DRCUML_FLAG_C));
776            else
777               flags = FLAGS32_NZCV_ADD(temp32, PARAM1 + (flags & DRCUML_FLAG_C), PARAM2);
724778            PARAM0 = temp32;
725779            break;
726780
r2724r2725
740794
741795         case MAKE_OPCODE_SHORT(DRCUML_OP_SUBB, 4, 1):
742796            temp32 = PARAM1 - PARAM2 - (flags & DRCUML_FLAG_C);
743            flags = FLAGS32_NZCV_SUB(temp32, PARAM1, PARAM2);
797            if (PARAM2 + 1 != 0)
798               flags = FLAGS32_NZCV_SUB(temp32, PARAM1, PARAM2 + (flags & DRCUML_FLAG_C));
799            else
800               flags = FLAGS32_NZCV_SUB(temp32, PARAM1 - (flags & DRCUML_FLAG_C), PARAM2);
744801            PARAM0 = temp32;
745802            break;
746803
r2724r2725
848905            PARAM0 = temp32;
849906            break;
850907
908         case MAKE_OPCODE_SHORT(DRCUML_OP_LZCNT, 4, 0):      /* LZCNT   dst,src[,f]            */
909            PARAM0 = count_leading_zeros(PARAM1);
910            break;
911
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            break;
917
851918         case MAKE_OPCODE_SHORT(DRCUML_OP_SHL, 4, 0):      /* SHL     dst,src,count[,f]      */
852919            PARAM0 = PARAM1 << (PARAM2 & 31);
853920            break;
r2724r2725
10811148            break;
10821149
10831150         case MAKE_OPCODE_SHORT(DRCUML_OP_ZEXT1, 8, 0):      /* DZEXT1  dst,src                */
1084            DPARAM0 = (UINT8)DPARAM1;
1151            DPARAM0 = (UINT8)PARAM1;
10851152            break;
10861153
10871154         case MAKE_OPCODE_SHORT(DRCUML_OP_ZEXT2, 8, 0):      /* DZEXT2  dst,src                */
1088            DPARAM0 = (UINT16)DPARAM1;
1155            DPARAM0 = (UINT16)PARAM1;
10891156            break;
10901157
10911158         case MAKE_OPCODE_SHORT(DRCUML_OP_ZEXT4, 8, 0):      /* DZEXT4  dst,src                */
1092            DPARAM0 = (UINT32)DPARAM1;
1159            DPARAM0 = (UINT32)PARAM1;
10931160            break;
10941161
10951162         case MAKE_OPCODE_SHORT(DRCUML_OP_SEXT1, 8, 0):      /* DSEXT1  dst,src                */
1096            DPARAM0 = (INT8)DPARAM1;
1163            DPARAM0 = (INT8)PARAM1;
10971164            break;
10981165
10991166         case MAKE_OPCODE_SHORT(DRCUML_OP_SEXT2, 8, 0):      /* DSEXT2  dst,src                */
1100            DPARAM0 = (INT16)DPARAM1;
1167            DPARAM0 = (INT16)PARAM1;
11011168            break;
11021169
11031170         case MAKE_OPCODE_SHORT(DRCUML_OP_SEXT4, 8, 0):      /* DSEXT4  dst,src                */
1104            DPARAM0 = (INT32)DPARAM1;
1171            DPARAM0 = (INT32)PARAM1;
11051172            break;
11061173
1174         case MAKE_OPCODE_SHORT(DRCUML_OP_XTRACT, 8, 0):      /* DXTRACT dst,src,count,mask[,f] */
1175            shift = DPARAM2 & 63;
1176            DPARAM0 = ((DPARAM1 << shift) | (DPARAM1 >> (64 - shift))) & DPARAM3;
1177            break;
1178
1179         case MAKE_OPCODE_SHORT(DRCUML_OP_INSERT, 8, 0):      /* DINSERT dst,src,count,mask[,f] */
1180            shift = DPARAM2 & 63;
1181            DPARAM0 = (DPARAM0 & ~DPARAM3) | (((DPARAM1 << shift) | (DPARAM1 >> (64 - shift))) & DPARAM3);
1182            break;
1183
11071184         case MAKE_OPCODE_SHORT(DRCUML_OP_ADD, 8, 0):      /* DADD    dst,src1,src2[,f]      */
11081185            DPARAM0 = DPARAM1 + DPARAM2;
11091186            break;
r2724r2725
11201197
11211198         case MAKE_OPCODE_SHORT(DRCUML_OP_ADDC, 8, 1):
11221199            temp64 = DPARAM1 + DPARAM2 + (flags & DRCUML_FLAG_C);
1123            flags = FLAGS64_NZCV_ADD(temp64, DPARAM1, DPARAM2);
1200            if (DPARAM2 + 1 != 0)
1201               flags = FLAGS64_NZCV_ADD(temp64, DPARAM1, DPARAM2 + (flags & DRCUML_FLAG_C));
1202            else
1203               flags = FLAGS64_NZCV_ADD(temp64, DPARAM1 + (flags & DRCUML_FLAG_C), DPARAM2);
11241204            DPARAM0 = temp64;
11251205            break;
11261206
r2724r2725
11401220
11411221         case MAKE_OPCODE_SHORT(DRCUML_OP_SUBB, 8, 1):
11421222            temp64 = DPARAM1 - DPARAM2 - (flags & DRCUML_FLAG_C);
1143            flags = FLAGS64_NZCV_SUB(temp64, DPARAM1, DPARAM2);
1223            if (DPARAM2 + 1 != 0)
1224               flags = FLAGS64_NZCV_SUB(temp64, DPARAM1, DPARAM2 + (flags & DRCUML_FLAG_C));
1225            else
1226               flags = FLAGS64_NZCV_SUB(temp64, DPARAM1 - (flags & DRCUML_FLAG_C), DPARAM2);
11441227            DPARAM0 = temp64;
11451228            break;
11461229
r2724r2725
12381321            DPARAM0 = temp64;
12391322            break;
12401323
1324         case MAKE_OPCODE_SHORT(DRCUML_OP_LZCNT, 8, 0):      /* DLZCNT  dst,src[,f]            */
1325            if ((UINT32)(DPARAM1 >> 32) != 0)
1326               DPARAM0 = count_leading_zeros(DPARAM1 >> 32);
1327            else
1328               DPARAM0 = 32 + count_leading_zeros(DPARAM1);
1329            break;
1330
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            break;
1339
12411340         case MAKE_OPCODE_SHORT(DRCUML_OP_SHL, 8, 0):      /* DSHL    dst,src,count[,f]      */
12421341            DPARAM0 = DPARAM1 << (DPARAM2 & 63);
12431342            break;
r2724r2725
14891588            break;
14901589
14911590         case MAKE_OPCODE_SHORT(DRCUML_OP_FREAD, 8, 0):      /* FDREAD  dst,space,src1         */
1492            PARAM0 = (UINT64)(*active_address_space[PARAM1].accessors->read_qword)(PARAM2);
1591            DPARAM0 = (UINT64)(*active_address_space[PARAM1].accessors->read_qword)(PARAM2);
14931592            break;
14941593
14951594         case MAKE_OPCODE_SHORT(DRCUML_OP_FWRITE, 8, 0):      /* FDWRITE space,dst,src1         */
1496            (*active_address_space[PARAM0].accessors->write_qword)(PARAM1, PARAM2);
1595            (*active_address_space[PARAM0].accessors->write_qword)(PARAM1, DPARAM2);
14971596            break;
14981597
14991598         case MAKE_OPCODE_SHORT(DRCUML_OP_FMOV, 8, 1):      /* FDMOV   dst,src[,c]            */
r2724r2725
16341733    output_parameter - output a parameter
16351734-------------------------------------------------*/
16361735
1637static void output_parameter(drcbe_state *drcbe, drcbec_instruction **dstptr, void **immedptr, int size, int immedsize, const drcuml_parameter *param)
1736static void output_parameter(drcbe_state *drcbe, drcbec_instruction **dstptr, void **immedptr, int size, const drcuml_parameter *param)
16381737{
16391738   drcbec_instruction *dst = *dstptr;
16401739   void *immed = *immedptr;
r2724r2725
16551754         else
16561755         {
16571756            (dst++)->v = immed;
1658            if (immedsize == 4)
1757            if (size == 4)
16591758               *(UINT32 *)immed = (UINT32)param->value;
16601759            else
16611760               *(UINT64 *)immed = (UINT64)param->value;
1662            immed = (UINT8 *)immed + immedsize;
1761            immed = (UINT8 *)immed + size;
16631762         }
16641763         break;
16651764
16661765      /* int registers point to the appropriate part of the integer register state */
16671766      case DRCUML_PTYPE_INT_REGISTER:
16681767         if (size == 4)
1669            (dst++)->puint32 = &drcbe->state.r[param->value - DRCUML_REG_I0].l;
1768            (dst++)->puint32 = &drcbe->state.r[param->value - DRCUML_REG_I0].w.l;
16701769         else
16711770            (dst++)->puint64 = &drcbe->state.r[param->value - DRCUML_REG_I0].d;
16721771         break;
r2724r2725
16741773      /* float registers point to the appropriate part of the floating point register state */
16751774      case DRCUML_PTYPE_FLOAT_REGISTER:
16761775         if (size == 4)
1677            (dst++)->pfloat = &drcbe->state.f[param->value - DRCUML_REG_F0].l;
1776            (dst++)->pfloat = &drcbe->state.f[param->value - DRCUML_REG_F0].s.l;
16781777         else
16791778            (dst++)->pdouble = &drcbe->state.f[param->value - DRCUML_REG_F0].d;
16801779         break;
src/emu/cpu/powerpc/ppcdrco.c
r0r2725
1/*
2    PowerPC 4xx/6xx Dynamic Recompiler for x86
3
4    Written by Ville Linde
5*/
6
7#include "debugger.h"
8#include "ppc.h"
9#include "cpu/x86drc.h"
10
11
12#define PPC_DRC
13#define LOG_CODE         (0)
14
15#define CACHE_SIZE         (16 * 1024 * 1024)
16#define MAX_INSTRUCTIONS   512
17
18
19#if (HAS_PPC603)
20static void ppcdrc603_init(int index, int clock, const void *_config, int (*irqcallback)(int));
21static void ppcdrc603_exit(void);
22#endif
23#if (HAS_PPC601 || HAS_PPC603 || HAS_MPC8240 || HAS_PPC604)
24static void ppcdrc603_reset(void);
25static int ppcdrc603_execute(int cycles);
26static void ppcdrc603_set_irq_line(int irqline, int state);
27#endif
28#if (HAS_PPC602)
29static void ppcdrc602_init(int index, int clock, const void *_config, int (*irqcallback)(int));
30static void ppcdrc602_exit(void);
31static void ppcdrc602_reset(void);
32static int ppcdrc602_execute(int cycles);
33static void ppcdrc602_set_irq_line(int irqline, int state);
34#endif
35#if (HAS_PPC403)
36static UINT8 ppc403_spu_r(UINT32 a);
37static void ppc403_spu_w(UINT32 a, UINT8 d);
38static void ppcdrc403_init(int index, int clock, const void *_config, int (*irqcallback)(int));
39static void ppcdrc403_exit(void);
40static void ppcdrc403_reset(void);
41static int ppcdrc403_execute(int cycles);
42static void ppcdrc403_set_irq_line(int irqline, int state);
43#endif
44
45static void ppcdrc_init(void);
46static void ppcdrc_reset(drc_core *drc);
47static void ppcdrc_recompile(drc_core *drc);
48static void ppcdrc_entrygen(drc_core *drc);
49
50#define RD            ((op >> 21) & 0x1F)
51#define RT            ((op >> 21) & 0x1f)
52#define RS            ((op >> 21) & 0x1f)
53#define RA            ((op >> 16) & 0x1f)
54#define RB            ((op >> 11) & 0x1f)
55#define RC            ((op >> 6) & 0x1f)
56
57#define MB            ((op >> 6) & 0x1f)
58#define ME            ((op >> 1) & 0x1f)
59#define SH            ((op >> 11) & 0x1f)
60#define BO            ((op >> 21) & 0x1f)
61#define BI            ((op >> 16) & 0x1f)
62#define CRFD         ((op >> 23) & 0x7)
63#define CRFA         ((op >> 18) & 0x7)
64#define FXM            ((op >> 12) & 0xff)
65#define SPR            (((op >> 16) & 0x1f) | ((op >> 6) & 0x3e0))
66
67#define SIMM16         (INT32)(INT16)(op & 0xffff)
68#define UIMM16         (UINT32)(op & 0xffff)
69
70#define RCBIT         (op & 0x1)
71#define OEBIT         (op & 0x400)
72#define AABIT         (op & 0x2)
73#define LKBIT         (op & 0x1)
74
75#define REG(x)         (ppc.r[x])
76#define LR            (ppc.lr)
77#define CTR            (ppc.ctr)
78#define XER            (ppc.xer)
79#define CR(x)         (ppc.cr[x])
80#define MSR            (ppc.msr)
81#define SRR0         (ppc.srr0)
82#define SRR1         (ppc.srr1)
83#define SRR2         (ppc.srr2)
84#define SRR3         (ppc.srr3)
85#define EVPR         (ppc.evpr)
86#define EXIER         (ppc.exier)
87#define EXISR         (ppc.exisr)
88#define DEC            (ppc.dec)
89
90
91// Stuff added for the 6xx
92#define FPR(x)         (ppc.fpr[x])
93#define FM            ((op >> 17) & 0xFF)
94#define SPRF         (((op >> 6) & 0x3E0) | ((op >> 16) & 0x1F))
95
96
97#define CHECK_SUPERVISOR()         \
98   if((ppc.msr & 0x4000) != 0){   \
99   }
100
101#define CHECK_FPU_AVAILABLE()      \
102   if((ppc.msr & 0x2000) == 0){   \
103   }
104
105#if (HAS_PPC601||HAS_PPC602||HAS_PPC603||HAS_PPC604||HAS_MPC8240)
106static UINT32      ppc_field_xlat[256];
107#endif
108
109
110
111#define FPSCR_FX      0x80000000
112#define FPSCR_FEX      0x40000000
113#define FPSCR_VX      0x20000000
114#define FPSCR_OX      0x10000000
115#define FPSCR_UX      0x08000000
116#define FPSCR_ZX      0x04000000
117#define FPSCR_XX      0x02000000
118
119
120
121#define BITMASK_0(n)   (UINT32)(((UINT64)1 << n) - 1)
122#define CRBIT(x)      ((ppc.cr[x / 4] & (1 << (3 - (x % 4)))) ? 1 : 0)
123#define _BIT(n)         (1 << (n))
124#define GET_ROTATE_MASK(mb,me)      (ppc_rotate_mask[mb][me])
125#define ADD_CA(r,a,b)      ((UINT32)r < (UINT32)a)
126#define SUB_CA(r,a,b)      (!((UINT32)a < (UINT32)b))
127#define ADD_OV(r,a,b)      ((~((a) ^ (b)) & ((a) ^ (r))) & 0x80000000)
128#define SUB_OV(r,a,b)      (( ((a) ^ (b)) & ((a) ^ (r))) & 0x80000000)
129
130#define XER_SO         0x80000000
131#define XER_OV         0x40000000
132#define XER_CA         0x20000000
133
134#define MSR_AP         0x00800000   /* Access privilege state (PPC602) */
135#define MSR_SA         0x00400000   /* Supervisor access mode (PPC602) */
136#define MSR_POW         0x00040000   /* Power Management Enable */
137#define MSR_WE         0x00040000
138#define MSR_CE         0x00020000
139#define MSR_ILE         0x00010000   /* Interrupt Little Endian Mode */
140#define MSR_EE         0x00008000   /* External Interrupt Enable */
141#define MSR_PR         0x00004000   /* Problem State */
142#define MSR_FP         0x00002000   /* Floating Point Available */
143#define MSR_ME         0x00001000   /* Machine Check Enable */
144#define MSR_FE0         0x00000800
145#define MSR_SE         0x00000400   /* Single Step Trace Enable */
146#define MSR_BE         0x00000200   /* Branch Trace Enable */
147#define MSR_DE         0x00000200
148#define MSR_FE1         0x00000100
149#define MSR_IP         0x00000040   /* Interrupt Prefix */
150#define MSR_IR         0x00000020   /* Instruction Relocate */
151#define MSR_DR         0x00000010   /* Data Relocate */
152#define MSR_PE         0x00000008
153#define MSR_PX         0x00000004
154#define MSR_RI         0x00000002   /* Recoverable Interrupt Enable */
155#define MSR_LE         0x00000001
156
157#define TSR_ENW         0x80000000
158#define TSR_WIS         0x40000000
159
160#define BYTE_REVERSE16(x)   ((((x) >> 8) & 0xff) | (((x) << 8) & 0xff00))
161#define BYTE_REVERSE32(x)   ((((x) >> 24) & 0xff) | (((x) >> 8) & 0xff00) | (((x) << 8) & 0xff0000) | (((x) << 24) & 0xff000000))
162
163typedef struct {
164   UINT32 cr;
165   UINT32 da;
166   UINT32 sa;
167   UINT32 ct;
168   UINT32 cc;
169} DMA_REGS;
170
171typedef struct {
172   UINT8 spls;
173   UINT8 sphs;
174   UINT16 brd;
175   UINT8 spctl;
176   UINT8 sprc;
177   UINT8 sptc;
178   UINT8 sprb;
179   UINT8 sptb;
180   emu_timer *rx_timer;
181   emu_timer *tx_timer;
182} SPU_REGS;
183
184typedef union {
185   UINT64   id;
186   double   fd;
187} FPR;
188
189typedef union {
190   UINT32 i;
191   float f;
192} FPR32;
193
194typedef struct {
195   UINT32 u;
196   UINT32 l;
197} BATENT;
198
199
200typedef struct {
201   UINT32 r[32];
202   UINT32 pc;
203   UINT32 npc;
204
205   UINT32 lr;
206   UINT32 ctr;
207   UINT32 xer;
208   UINT32 msr;
209   UINT8 cr[8];
210   UINT32 pvr;
211   UINT32 srr0;
212   UINT32 srr1;
213   UINT32 srr2;
214   UINT32 srr3;
215   UINT32 hid0;
216   UINT32 hid1;
217   UINT32 hid2;
218   UINT32 sdr1;
219   UINT32 sprg[4];
220
221   UINT32 dsisr;
222   UINT32 dar;
223   UINT32 ear;
224   UINT32 dmiss;
225   UINT32 dcmp;
226   UINT32 hash1;
227   UINT32 hash2;
228   UINT32 imiss;
229   UINT32 icmp;
230   UINT32 rpa;
231
232   BATENT ibat[4];
233   BATENT dbat[4];
234
235   UINT32 evpr;
236   UINT32 exier;
237   UINT32 exisr;
238   UINT32 bear;
239   UINT32 besr;
240   UINT32 iocr;
241   UINT32 br[8];
242   UINT32 iabr;
243   UINT32 esr;
244   UINT32 iccr;
245   UINT32 dccr;
246   UINT32 pit;
247   UINT32 tsr;
248   UINT32 tcr;
249   UINT32 dbsr;
250   UINT32 sgr;
251   UINT32 pid;
252   UINT32 pbl1, pbl2, pbu1, pbu2;
253   UINT32 fit_bit;
254   UINT32 fit_int_enable;
255   UINT32 wdt_bit;
256   UINT32 wdt_int_enable;
257   UINT32 dac1, dac2;
258   UINT32 iac1, iac2;
259
260   SPU_REGS spu;
261   DMA_REGS dma[4];
262   UINT32 dmasr;
263
264   int reserved;
265   UINT32 reserved_address;
266
267   int exception_pending;
268
269   UINT64 tb;         /* 56-bit timebase register */
270
271   int (*irq_callback)(int irqline);
272   drc_core *drc;
273   UINT32 drcoptions;
274
275   x86code *      invoke_exception_handler;
276   x86code *      generate_interrupt_exception;
277   x86code *      generate_syscall_exception;
278   x86code *      generate_decrementer_exception;
279   x86code *      generate_trap_exception;
280   x86code *      generate_dsi_exception;
281   x86code *      generate_isi_exception;
282   x86code *      generate_fit_exception;
283
284   // PowerPC 60x specific registers */
285   UINT32 dec, dec_frac;
286   UINT32 fpscr;
287
288   FPR   fpr[32];
289   UINT32 sr[16];
290
291   int is603;
292   int is602;
293
294   /* PowerPC 602 specific registers */
295   UINT32 lt;
296   UINT32 sp;
297   UINT32 ibr;
298   UINT32 esasrr;
299   UINT32 sebr;
300   UINT32 ser;
301
302   /* PowerPC function pointers for memory accesses/exceptions */
303   UINT8 (*read8)(offs_t address);
304   UINT16 (*read16)(offs_t address);
305   UINT32 (*read32)(offs_t address);
306   UINT64 (*read64)(offs_t address);
307   void (*write8)(offs_t address, UINT8 data);
308   void (*write16)(offs_t address, UINT16 data);
309   void (*write32)(offs_t address, UINT32 data);
310   void (*write64)(offs_t address, UINT64 data);
311   UINT16 (*read16_unaligned)(offs_t address);
312   UINT32 (*read32_unaligned)(offs_t address);
313   UINT64 (*read64_unaligned)(offs_t address);
314   void (*write16_unaligned)(offs_t address, UINT16 data);
315   void (*write32_unaligned)(offs_t address, UINT32 data);
316   void (*write64_unaligned)(offs_t address, UINT64 data);
317
318   /* saved ESP when entering entry point */
319   UINT32 host_esp;
320
321   UINT32 (* optable19[1024])(drc_core *, UINT32);
322   UINT32 (* optable31[1024])(drc_core *, UINT32);
323   UINT32 (* optable59[1024])(drc_core *, UINT32);
324   UINT32 (* optable63[1024])(drc_core *, UINT32);
325   UINT32 (* optable[64])(drc_core *, UINT32);
326} PPC_REGS;
327
328
329
330typedef struct {
331   int code;
332   int subcode;
333   UINT32 (* handler)(drc_core *, UINT32);
334} PPC_OPCODE;
335
336
337/* code logging info */
338typedef struct _code_log_entry code_log_entry;
339struct _code_log_entry
340{
341   UINT32      pc;
342   UINT32      op;
343   void *      base;
344};
345
346
347
348static int ppc_icount;
349static int ppc_tb_base_icount;
350static int ppc_dec_base_icount;
351static int ppc_dec_trigger_cycle;
352static int bus_freq_multiplier = 1;
353static int ppc_fit_trigger_cycle;
354static PPC_REGS ppc;
355static UINT32 ppc_rotate_mask[32][32];
356
357#define ROPCODE(pc)         cpu_readop32(pc)
358#define ROPCODE64(pc)      cpu_readop64(DWORD_XOR_BE(pc))
359
360INLINE void SET_CR0(INT32 rd)
361{
362   if( rd < 0 ) {
363      CR(0) = 0x8;
364   } else if( rd > 0 ) {
365      CR(0) = 0x4;
366   } else {
367      CR(0) = 0x2;
368   }
369
370   if( XER & XER_SO )
371      CR(0) |= 0x1;
372}
373
374INLINE void SET_CR1(void)
375{
376   CR(1) = (ppc.fpscr >> 28) & 0xf;
377}
378
379INLINE void SET_ADD_OV(UINT32 rd, UINT32 ra, UINT32 rb)
380{
381   if( ADD_OV(rd, ra, rb) )
382      XER |= XER_SO | XER_OV;
383   else
384      XER &= ~XER_OV;
385}
386
387INLINE void SET_SUB_OV(UINT32 rd, UINT32 ra, UINT32 rb)
388{
389   if( SUB_OV(rd, ra, rb) )
390      XER |= XER_SO | XER_OV;
391   else
392      XER &= ~XER_OV;
393}
394
395INLINE void SET_ADD_CA(UINT32 rd, UINT32 ra, UINT32 rb)
396{
397   if( ADD_CA(rd, ra, rb) )
398      XER |= XER_CA;
399   else
400      XER &= ~XER_CA;
401}
402
403INLINE void SET_SUB_CA(UINT32 rd, UINT32 ra, UINT32 rb)
404{
405   if( SUB_CA(rd, ra, rb) )
406      XER |= XER_CA;
407   else
408      XER &= ~XER_CA;
409}
410
411INLINE UINT32 check_condition_code(UINT32 bo, UINT32 bi)
412{
413   UINT32 ctr_ok;
414   UINT32 condition_ok;
415   UINT32 bo0 = (bo & 0x10) ? 1 : 0;
416   UINT32 bo1 = (bo & 0x08) ? 1 : 0;
417   UINT32 bo2 = (bo & 0x04) ? 1 : 0;
418   UINT32 bo3 = (bo & 0x02) ? 1 : 0;
419
420   if( bo2 == 0 )
421      --CTR;
422
423   ctr_ok = bo2 | ((CTR != 0) ^ bo3);
424   condition_ok = bo0 | (CRBIT(bi) ^ (~bo1 & 0x1));
425
426   return ctr_ok && condition_ok;
427}
428
429INLINE UINT64 ppc_read_timebase(void)
430{
431   int cycles = ppc_tb_base_icount - ppc_icount;
432
433   if (ppc.is603 || ppc.is602)
434   {
435      // timebase is incremented once every four core clock cycles, so adjust the cycles accordingly
436      return ppc.tb + (cycles / 4);
437   }
438   else
439   {
440      // timebase is incremented once every core cycle on PPC403
441      return ppc.tb + cycles;
442   }
443}
444
445INLINE void ppc_write_timebase_l(UINT32 tbl)
446{
447   ppc_tb_base_icount = ppc_icount;
448
449   ppc.tb &= ~0xffffffff;
450   ppc.tb |= tbl;
451}
452
453INLINE void ppc_write_timebase_h(UINT32 tbh)
454{
455   ppc_tb_base_icount = ppc_icount;
456
457   ppc.tb &= 0xffffffff;
458   ppc.tb |= (UINT64)(tbh) << 32;
459}
460
461INLINE UINT32 read_decrementer(void)
462{
463   int cycles = ppc_dec_base_icount - ppc_icount;
464
465   // decrementer is decremented once every four bus clock cycles, so adjust the cycles accordingly
466   return DEC - (cycles / (bus_freq_multiplier * 2));
467}
468
469INLINE void write_decrementer(UINT32 value)
470{
471   ppc_dec_base_icount = ppc_icount + (ppc_dec_base_icount - ppc_icount) % (bus_freq_multiplier * 2);
472
473   DEC = value;
474
475   // check if decrementer exception occurs during execution
476   if ((UINT32)(DEC - ppc_icount) > (UINT32)(DEC))
477   {
478      ppc_dec_trigger_cycle = ppc_icount - DEC;
479   }
480   else
481   {
482      ppc_dec_trigger_cycle = 0x7fffffff;
483   }
484}
485
486/*********************************************************************/
487
488INLINE void ppc_exception(int exception_type)
489{
490   void *exception_code = NULL;
491   void (*invoke_exception_handler)(void *handler);
492
493   switch(exception_type)
494   {
495      case EXCEPTION_DECREMENTER:
496         exception_code = ppc.generate_decrementer_exception;
497         break;
498      case EXCEPTION_DSI:
499         exception_code = ppc.generate_dsi_exception;
500         break;
501      case EXCEPTION_ISI:
502         exception_code = ppc.generate_isi_exception;
503         break;
504      default:
505         fatalerror("Unknown exception %d", exception_type);
506         break;
507   }
508
509   memcpy(&invoke_exception_handler, &ppc.invoke_exception_handler, sizeof(invoke_exception_handler));
510   invoke_exception_handler(exception_code);
511}
512
513/*********************************************************************/
514
515INLINE void ppc_set_spr(int spr, UINT32 value)
516{
517   switch (spr)
518   {
519      case SPR_LR:      LR = value; return;
520      case SPR_CTR:      CTR = value; return;
521      case SPR_XER:      XER = value; return;
522      case SPR_SRR0:      ppc.srr0 = value; return;
523      case SPR_SRR1:      ppc.srr1 = value; return;
524      case SPR_SPRG0:      ppc.sprg[0] = value; return;
525      case SPR_SPRG1:      ppc.sprg[1] = value; return;
526      case SPR_SPRG2:      ppc.sprg[2] = value; return;
527      case SPR_SPRG3:      ppc.sprg[3] = value; return;
528      case SPR_PVR:      return;
529   }
530
531#if (HAS_PPC603 || HAS_PPC602 || HAS_PPC601 || HAS_PPC604)
532   if(ppc.is603 || ppc.is602) {
533      switch(spr)
534      {
535         case SPR603E_DEC:
536            if((value & 0x80000000) && !(DEC & 0x80000000))
537            {
538               /* trigger interrupt */
539               if( MSR & MSR_EE )
540                  ppc_exception(EXCEPTION_DECREMENTER);
541            }
542            write_decrementer(value);
543            return;
544
545         case SPR603E_TBL_W:
546         case SPR603E_TBL_R: // special 603e case
547            ppc_write_timebase_l(value);
548            return;
549
550         case SPR603E_TBU_R:
551         case SPR603E_TBU_W: // special 603e case
552            ppc_write_timebase_h(value);
553            return;
554
555         case SPR603E_HID0:
556            ppc.hid0 = value;
557            return;
558
559         case SPR603E_HID1:
560            ppc.hid1 = value;
561            return;
562
563         case SPR603E_HID2:
564            ppc.hid1 = value;
565            return;
566
567         case SPR603E_DSISR:         ppc.dsisr = value; return;
568         case SPR603E_DAR:         ppc.dar = value; return;
569         case SPR603E_EAR:         ppc.ear = value; return;
570         case SPR603E_DMISS:         ppc.dmiss = value; return;
571         case SPR603E_DCMP:         ppc.dcmp = value; return;
572         case SPR603E_HASH1:         ppc.hash1 = value; return;
573         case SPR603E_HASH2:         ppc.hash2 = value; return;
574         case SPR603E_IMISS:         ppc.imiss = value; return;
575         case SPR603E_ICMP:         ppc.icmp = value; return;
576         case SPR603E_RPA:         ppc.rpa = value; return;
577
578         case SPR603E_IBAT0L:      ppc.ibat[0].l = value; return;
579         case SPR603E_IBAT0U:      ppc.ibat[0].u = value; return;
580         case SPR603E_IBAT1L:      ppc.ibat[1].l = value; return;
581         case SPR603E_IBAT1U:      ppc.ibat[1].u = value; return;
582         case SPR603E_IBAT2L:      ppc.ibat[2].l = value; return;
583         case SPR603E_IBAT2U:      ppc.ibat[2].u = value; return;
584         case SPR603E_IBAT3L:      ppc.ibat[3].l = value; return;
585         case SPR603E_IBAT3U:      ppc.ibat[3].u = value; return;
586         case SPR603E_DBAT0L:      ppc.dbat[0].l = value; return;
587         case SPR603E_DBAT0U:      ppc.dbat[0].u = value; return;
588         case SPR603E_DBAT1L:      ppc.dbat[1].l = value; return;
589         case SPR603E_DBAT1U:      ppc.dbat[1].u = value; return;
590         case SPR603E_DBAT2L:      ppc.dbat[2].l = value; return;
591         case SPR603E_DBAT2U:      ppc.dbat[2].u = value; return;
592         case SPR603E_DBAT3L:      ppc.dbat[3].l = value; return;
593         case SPR603E_DBAT3U:      ppc.dbat[3].u = value; return;
594
595         case SPR603E_SDR1:
596            ppc.sdr1 = value;
597            return;
598
599         case SPR603E_IABR:         ppc.iabr = value; return;
600      }
601   }
602#endif
603
604#if (HAS_PPC602)
605   if (ppc.is602) {
606      switch(spr)
607      {
608         case SPR602_LT:         ppc.lt = value; return;
609         case SPR602_IBR:      ppc.ibr = value; return;
610         case SPR602_SP:         ppc.sp = value; return;
611         case SPR602_SEBR:      ppc.sebr = value; return;
612         case SPR602_SER:      ppc.ser = value; return;
613         case SPR602_TCR:      ppc.tcr = value; return;
614      }
615   }
616#endif
617
618#if (HAS_PPC403)
619   if (!ppc.is603 && !ppc.is602) {
620      switch(spr)
621      {
622         case SPR403_TBHI:      ppc_write_timebase_h(value); return;
623         case SPR403_TBLO:      ppc_write_timebase_l(value); return;
624
625         case SPR403_TSR:
626            ppc.tsr &= ~value; // 1 clears, 0 does nothing
627            return;
628
629         case SPR403_TCR:
630            switch((value >> 24) & 0x3)
631            {
632               case 0: ppc.fit_bit = 1 << 8; break;
633               case 1: ppc.fit_bit = 1 << 12; break;
634               case 2: ppc.fit_bit = 1 << 16; break;
635               case 3: ppc.fit_bit = 1 << 20; break;
636            }
637            switch((value >> 30) & 0x3)
638            {
639               case 0: ppc.wdt_bit = 1 << 16; break;
640               case 1: ppc.wdt_bit = 1 << 20; break;
641               case 2: ppc.wdt_bit = 1 << 24; break;
642               case 3: ppc.wdt_bit = 1 << 28; break;
643            }
644            ppc.fit_int_enable = (value >> 23) & 0x1;
645            ppc.wdt_int_enable = (value >> 27) & 0x1;
646            ppc.tcr = value;
647
648            if (!ppc.fit_int_enable)
649            {
650               ppc.exception_pending &= ~0x4;
651            }
652            return;
653
654         case SPR403_ESR:      ppc.esr = value; return;
655         case SPR403_ICCR:      ppc.iccr = value; return;
656         case SPR403_DCCR:      ppc.dccr = value; return;
657         case SPR403_EVPR:      EVPR = value & 0xffff0000; return;
658         case SPR403_PIT:      ppc.pit = value; return;
659         case SPR403_SGR:      ppc.sgr = value; return;
660         case SPR403_DBSR:      ppc.dbsr = value; return;
661         case SPR403_DCWR:      return;
662         case SPR403_PID:      ppc.pid = value; return;
663         case SPR403_PBL1:      ppc.pbl1 = value; return;
664         case SPR403_PBU1:      ppc.pbu1 = value; return;
665         case SPR403_PBL2:      ppc.pbl2 = value; return;
666         case SPR403_PBU2:      ppc.pbu2 = value; return;
667         case SPR403_SRR2:      ppc.srr2 = value; return;
668         case SPR403_SRR3:      ppc.srr3 = value; return;
669         case SPR403_DAC1:      ppc.dac1 = value; return;
670         case SPR403_DAC2:      ppc.dac2 = value; return;
671         case SPR403_IAC1:      ppc.iac1 = value; return;
672         case SPR403_IAC2:      ppc.iac2 = value; return;
673      }
674   }
675#endif
676
677   fatalerror("ppc: set_spr: unknown spr %d (%03X) !", spr, spr);
678}
679
680INLINE UINT32 ppc_get_spr(int spr)
681{
682   switch(spr)
683   {
684      case SPR_LR:      return LR;
685      case SPR_CTR:      return CTR;
686      case SPR_XER:      return XER;
687      case SPR_SRR0:      return ppc.srr0;
688      case SPR_SRR1:      return ppc.srr1;
689      case SPR_SPRG0:      return ppc.sprg[0];
690      case SPR_SPRG1:      return ppc.sprg[1];
691      case SPR_SPRG2:      return ppc.sprg[2];
692      case SPR_SPRG3:      return ppc.sprg[3];
693      case SPR_PVR:      return ppc.pvr;
694   }
695
696#if (HAS_PPC403)
697   if (!ppc.is603 && !ppc.is602)
698   {
699      switch (spr)
700      {
701         case SPR403_TBLU:
702         case SPR403_TBLO:      return (UINT32)(ppc_read_timebase());
703         case SPR403_TBHU:
704         case SPR403_TBHI:      return (UINT32)(ppc_read_timebase() >> 32);
705
706         case SPR403_EVPR:      return EVPR;
707         case SPR403_ESR:      return ppc.esr;
708         case SPR403_TCR:      return ppc.tcr;
709         case SPR403_ICCR:      return ppc.iccr;
710         case SPR403_DCCR:      return ppc.dccr;
711         case SPR403_PIT:      return ppc.pit;
712         case SPR403_DBSR:      return ppc.dbsr;
713         case SPR403_SGR:      return ppc.sgr;
714         case SPR403_TSR:      return ppc.tsr;
715         case SPR403_PBL1:      return ppc.pbl1;
716         case SPR403_PBU1:      return ppc.pbu1;
717         case SPR403_PBL2:      return ppc.pbl2;
718         case SPR403_PBU2:      return ppc.pbu2;
719         case SPR403_SRR2:      return ppc.srr2;
720         case SPR403_SRR3:      return ppc.srr3;
721         case SPR403_DAC1:      return ppc.dac1;
722         case SPR403_DAC2:      return ppc.dac2;
723         case SPR403_IAC1:      return ppc.iac1;
724         case SPR403_IAC2:      return ppc.iac2;
725      }
726   }
727#endif
728
729#if (HAS_PPC602)
730   if (ppc.is602) {
731      switch(spr)
732      {
733         case SPR602_LT:         return ppc.lt;
734         case SPR602_IBR:      return ppc.ibr;
735         case SPR602_ESASRR:      return ppc.esasrr;
736         case SPR602_SEBR:      return ppc.sebr;
737         case SPR602_SER:      return ppc.ser;
738         case SPR602_SP:         return ppc.sp;
739         case SPR602_TCR:      return ppc.tcr;
740      }
741   }
742#endif
743
744#if (HAS_PPC603 || HAS_PPC602 || HAS_PPC601 || HAS_PPC604)
745   if (ppc.is603 || ppc.is602)
746   {
747      switch (spr)
748      {
749         case SPR603E_TBL_R:
750            fatalerror("ppc: get_spr: TBL_R ");
751            break;
752
753         case SPR603E_TBU_R:
754            fatalerror("ppc: get_spr: TBU_R ");
755            break;
756
757         case SPR603E_TBL_W:      return (UINT32)(ppc_read_timebase());
758         case SPR603E_TBU_W:      return (UINT32)(ppc_read_timebase() >> 32);
759         case SPR603E_HID0:      return ppc.hid0;
760         case SPR603E_HID1:      return ppc.hid1;
761         case SPR603E_HID2:      return ppc.hid2;
762         case SPR603E_DEC:      return read_decrementer();
763         case SPR603E_SDR1:      return ppc.sdr1;
764         case SPR603E_DSISR:      return ppc.dsisr;
765         case SPR603E_DAR:      return ppc.dar;
766         case SPR603E_EAR:      return ppc.ear;
767         case SPR603E_IBAT0L:   return ppc.ibat[0].l;
768         case SPR603E_IBAT0U:   return ppc.ibat[0].u;
769         case SPR603E_IBAT1L:   return ppc.ibat[1].l;
770         case SPR603E_IBAT1U:   return ppc.ibat[1].u;
771         case SPR603E_IBAT2L:   return ppc.ibat[2].l;
772         case SPR603E_IBAT2U:   return ppc.ibat[2].u;
773         case SPR603E_IBAT3L:   return ppc.ibat[3].l;
774         case SPR603E_IBAT3U:   return ppc.ibat[3].u;
775         case SPR603E_DBAT0L:   return ppc.dbat[0].l;
776         case SPR603E_DBAT0U:   return ppc.dbat[0].u;
777         case SPR603E_DBAT1L:   return ppc.dbat[1].l;
778         case SPR603E_DBAT1U:   return ppc.dbat[1].u;
779         case SPR603E_DBAT2L:   return ppc.dbat[2].l;
780         case SPR603E_DBAT2U:   return ppc.dbat[2].u;
781         case SPR603E_DBAT3L:   return ppc.dbat[3].l;
782         case SPR603E_DBAT3U:   return ppc.dbat[3].u;
783      }
784   }
785#endif
786
787   fatalerror("ppc: get_spr: unknown spr %d (%03X) !", spr, spr);
788   return 0;
789}
790
791static UINT8 ppc_read8_translated(offs_t address);
792static UINT16 ppc_read16_translated(offs_t address);
793static UINT32 ppc_read32_translated(offs_t address);
794static UINT64 ppc_read64_translated(offs_t address);
795static void ppc_write8_translated(offs_t address, UINT8 data);
796static void ppc_write16_translated(offs_t address, UINT16 data);
797static void ppc_write32_translated(offs_t address, UINT32 data);
798static void ppc_write64_translated(offs_t address, UINT64 data);
799
800INLINE void ppc_set_msr(UINT32 value)
801{
802   if( value & (MSR_ILE | MSR_LE) )
803      fatalerror("ppc: set_msr: little_endian mode not supported !");
804
805   MSR = value;
806
807   if (ppc.is603 || ppc.is602)
808   {
809      if (!(MSR & MSR_DR))
810      {
811         ppc.read8 = program_read_byte_64be;
812         ppc.read16 = program_read_word_64be;
813         ppc.read32 = program_read_dword_64be;
814         ppc.read64 = program_read_qword_64be;
815         ppc.write8 = program_write_byte_64be;
816         ppc.write16 = program_write_word_64be;
817         ppc.write32 = program_write_dword_64be;
818         ppc.write64 = program_write_qword_64be;
819      }
820      else
821      {
822         ppc.read8 = ppc_read8_translated;
823         ppc.read16 = ppc_read16_translated;
824         ppc.read32 = ppc_read32_translated;
825         ppc.read64 = ppc_read64_translated;
826         ppc.write8 = ppc_write8_translated;
827         ppc.write16 = ppc_write16_translated;
828         ppc.write32 = ppc_write32_translated;
829         ppc.write64 = ppc_write64_translated;
830      }
831   }
832}
833
834INLINE UINT32 ppc_get_msr(void)
835{
836   return MSR;
837}
838
839INLINE void ppc_set_cr(UINT32 value)
840{
841   CR(0) = (value >> 28) & 0xf;
842   CR(1) = (value >> 24) & 0xf;
843   CR(2) = (value >> 20) & 0xf;
844   CR(3) = (value >> 16) & 0xf;
845   CR(4) = (value >> 12) & 0xf;
846   CR(5) = (value >> 8) & 0xf;
847   CR(6) = (value >> 4) & 0xf;
848   CR(7) = (value >> 0) & 0xf;
849}
850
851INLINE UINT32 ppc_get_cr(void)
852{
853   return CR(0) << 28 | CR(1) << 24 | CR(2) << 20 | CR(3) << 16 | CR(4) << 12 | CR(5) << 8 | CR(6) << 4 | CR(7);
854}
855
856#ifdef UNUSED_FUNCTION
857static void log_code(drc_core *drc)
858{
859#if LOG_CODE
860   FILE *temp;
861   temp = fopen("code.bin", "wb");
862   fwrite(drc->cache_base, 1, drc->cache_top - drc->cache_base, temp);
863   fclose(temp);
864#endif
865}
866#endif
867
868/***********************************************************************/
869
870#include "ppc_mem.c"
871
872#if (HAS_PPC403)
873#include "ppc403.c"
874#endif
875
876#if (HAS_PPC602)
877#include "ppc602.c"
878#endif
879
880/***************************************************************************
881    CODE LOGGING
882***************************************************************************/
883
884#if LOG_CODE
885
886static code_log_entry code_log_buffer[MAX_INSTRUCTIONS*2];
887static int code_log_index;
888static FILE *logfile;
889
890
891/*-------------------------------------------------
892    open_logfile - open the log file if it is
893    not already opened
894-------------------------------------------------*/
895
896INLINE int open_logfile(void)
897{
898   if (logfile == NULL)
899      logfile = fopen("ppcdrc.asm", "w");
900   return (logfile != NULL);
901}
902
903
904/*-------------------------------------------------
905    code_log_reset - reset the logging index
906-------------------------------------------------*/
907
908INLINE void code_log_reset(void)
909{
910   code_log_index = 0;
911}
912
913
914/*-------------------------------------------------
915    code_log_add_entry - add an entry to the log
916-------------------------------------------------*/
917
918INLINE void code_log_add_entry(UINT32 pc, UINT32 op, void *base)
919{
920   code_log_buffer[code_log_index].pc = pc;
921   code_log_buffer[code_log_index].op = op;
922   code_log_buffer[code_log_index].base = base;
923   code_log_index++;
924}
925
926
927/*-------------------------------------------------
928    code_log - actually log some code
929-------------------------------------------------*/
930
931static void code_log(const char *label, x86code *start, x86code *stop)
932{
933   extern int i386_dasm_one(char *buffer, UINT32 eip, UINT8 *oprom, int mode);
934   offs_t ppc_dasm_one(char *buffer, UINT32 pc, UINT32 op);
935   UINT8 *cur = start;
936
937   /* open the file, creating it if necessary */
938   if (!open_logfile())
939      return;
940   fprintf(logfile, "\n%s\n", label);
941
942   /* loop from the start until the cache top */
943   while (cur < stop)
944   {
945      char buffer[100];
946      int bytes;
947      int op;
948
949      /* skip filler opcodes */
950      if (*cur == 0xcc)
951      {
952         cur++;
953         continue;
954      }
955
956      /* disassemble this instruction */
957#ifdef PTR64
958      bytes = i386_dasm_one(buffer, (UINT32)(FPTR)cur, cur, 64) & DASMFLAG_LENGTHMASK;
959#else
960      bytes = i386_dasm_one(buffer, (UINT32)cur, cur, 32) & DASMFLAG_LENGTHMASK;
961#endif
962
963      /* look for a match in the registered opcodes */
964      for (op = 0; op < code_log_index; op++)
965         if (code_log_buffer[op].base == (void *)cur)
966            break;
967
968      /* if no match, just output the current instruction */
969      if (op == code_log_index)
970         fprintf(logfile, "%p: %s\n", cur, buffer);
971
972      /* otherwise, output with the original instruction to the right */
973      else
974      {
975         char buffer2[100];
976         ppc_dasm_one(buffer2, code_log_buffer[op].pc, code_log_buffer[op].op);
977         fprintf(logfile, "%p: %-50s %08X: %s\n", cur, buffer, code_log_buffer[op].pc, buffer2);
978      }
979
980      /* advance past this instruction */
981      cur += bytes;
982   }
983
984   /* flush the file */
985   fflush(logfile);
986}
987
988#else
989
990#define code_log_reset()
991#define code_log_add_entry(a,b,c)
992#define code_log(a,b,c)
993
994#endif
995
996
997/********************************************************************/
998
999#include "ppc_ops.c"
1000#include "drc_ops.c"
1001#include "drc_ops.h"
1002
1003/* Initialization and shutdown */
1004
1005static void ppc_init(void)
1006{
1007   int i,j;
1008
1009   for( i=0; i < 64; i++ ) {
1010      ppc.optable[i] = recompile_invalid;
1011   }
1012   for( i=0; i < 1024; i++ ) {
1013      ppc.optable19[i] = recompile_invalid;
1014      ppc.optable31[i] = recompile_invalid;
1015      ppc.optable59[i] = recompile_invalid;
1016      ppc.optable63[i] = recompile_invalid;
1017   }
1018
1019   /* Fill the opcode tables */
1020   for( i=0; i < (sizeof(ppcdrc_opcode_common) / sizeof(PPC_OPCODE)); i++ ) {
1021
1022      switch(ppcdrc_opcode_common[i].code)
1023      {
1024         case 19:
1025            ppc.optable19[ppcdrc_opcode_common[i].subcode] = ppcdrc_opcode_common[i].handler;
1026            break;
1027
1028         case 31:
1029            ppc.optable31[ppcdrc_opcode_common[i].subcode] = ppcdrc_opcode_common[i].handler;
1030            break;
1031
1032         case 59:
1033         case 63:
1034            break;
1035
1036         default:
1037            ppc.optable[ppcdrc_opcode_common[i].code] = ppcdrc_opcode_common[i].handler;
1038      }
1039
1040   }
1041
1042   /* Calculate rotate mask table */
1043   for( i=0; i < 32; i++ ) {
1044      for( j=0; j < 32; j++ ) {
1045         UINT32 mask;
1046         int mb = i;
1047         int me = j;
1048         mask = ((UINT32)0xFFFFFFFF >> mb) ^ ((me >= 31) ? 0 : ((UINT32)0xFFFFFFFF >> (me + 1)));
1049         if( mb > me )
1050            mask = ~mask;
1051
1052         ppc_rotate_mask[i][j] = mask;
1053      }
1054   }
1055}
1056
1057#if (HAS_PPC403)
1058static void ppcdrc403_init(int index, int clock, const void *_config, int (*irqcallback)(int))
1059{
1060   const ppc_config *config = _config;
1061
1062   ppc_init();
1063   ppcdrc_init();
1064
1065   /* PPC403 specific opcodes */
1066   ppc.optable31[454] = recompile_dccci;
1067   ppc.optable31[486] = recompile_dcread;
1068   ppc.optable31[262] = recompile_icbt;
1069   ppc.optable31[966] = recompile_iccci;
1070   ppc.optable31[998] = recompile_icread;
1071   ppc.optable31[323] = recompile_mfdcr;
1072   ppc.optable31[451] = recompile_mtdcr;
1073   ppc.optable31[131] = recompile_wrtee;
1074   ppc.optable31[163] = recompile_wrteei;
1075   ppc.optable19[51] = recompile_rfci;
1076
1077   ppc.spu.rx_timer = timer_alloc(ppc403_spu_rx_callback, NULL);
1078   ppc.spu.tx_timer = timer_alloc(ppc403_spu_tx_callback, NULL);
1079
1080   ppc.is603 = 0;
1081   ppc.is602 = 0;
1082
1083   ppc.read8 = ppc403_read8;
1084   ppc.read16 = ppc403_read16;
1085   ppc.read32 = ppc403_read32;
1086   ppc.write8 = ppc403_write8;
1087   ppc.write16 = ppc403_write16;
1088   ppc.write32 = ppc403_write32;
1089   ppc.read16_unaligned = ppc403_read16_unaligned;
1090   ppc.read32_unaligned = ppc403_read32_unaligned;
1091   ppc.write16_unaligned = ppc403_write16_unaligned;
1092   ppc.write32_unaligned = ppc403_write32_unaligned;
1093
1094   ppc.irq_callback = irqcallback;
1095
1096   ppc.pvr = config->pvr;
1097}
1098
1099static void ppcdrc403_exit(void)
1100{
1101#if LOG_CODE
1102   //if (symfile) fclose(symfile);
1103#endif
1104   ppcdrc_exit();
1105}
1106
1107static void ppcdrc403_reset(void)
1108{
1109   ppc.pc = ppc.npc = 0xfffffffc;
1110
1111   ppc_set_msr(0);
1112   change_pc(ppc.pc);
1113
1114   /* reset the DRC */
1115   drc_cache_reset(ppc.drc);
1116}
1117
1118static int ppcdrc403_execute(int cycles)
1119{
1120   /* count cycles and interrupt cycles */
1121   ppc_icount = cycles;
1122   ppc_tb_base_icount = cycles;
1123
1124   ppc_fit_trigger_cycle = 0x7fffffff;
1125
1126   if (ppc.fit_int_enable)
1127   {
1128      UINT32 tb = (UINT32)ppc.tb;
1129      UINT32 fit_cycles = 0;
1130
1131      if (ppc.tb & ppc.fit_bit)
1132      {
1133         fit_cycles += ppc.fit_bit;
1134         tb += fit_cycles;
1135      }
1136
1137      fit_cycles += ppc.fit_bit - (tb & (ppc.fit_bit-1));
1138
1139      ppc_fit_trigger_cycle = ppc_icount - fit_cycles;
1140   }
1141
1142   drc_execute(ppc.drc);
1143
1144   // update timebase
1145   ppc.tb += (ppc_tb_base_icount - ppc_icount);
1146
1147   return cycles - ppc_icount;
1148}
1149
1150static void ppcdrc403_set_irq_line(int irqline, int state)
1151{
1152   if (irqline >= INPUT_LINE_IRQ0 && irqline <= INPUT_LINE_IRQ4)
1153   {
1154      UINT32 mask = (1 << (4 - irqline));
1155      if( state == ASSERT_LINE) {
1156         if (EXIER & mask)
1157         {
1158            ppc.exisr |= mask;
1159            ppc.exception_pending |= 0x1;
1160
1161            if (ppc.irq_callback)
1162            {
1163               ppc.irq_callback(irqline);
1164            }
1165         }
1166      }
1167      // clear line is used to clear the interrupt when the interrupts are level-sensitive
1168      else if (state == CLEAR_LINE)
1169      {
1170         ppc.exisr &= ~mask;
1171      }
1172   }
1173   else if (irqline == PPC403_SPU_RX)
1174   {
1175      UINT32 mask = 0x08000000;
1176      if (state) {
1177         if( EXIER & mask ) {
1178            ppc.exisr |= mask;
1179            ppc.exception_pending |= 0x1;
1180         }
1181      }
1182   }
1183   else if (irqline == PPC403_SPU_TX)
1184   {
1185      UINT32 mask = 0x04000000;
1186      if (state) {
1187         if( EXIER & mask ) {
1188            ppc.exisr |= mask;
1189            ppc.exception_pending |= 0x1;
1190         }
1191      }
1192   }
1193   else
1194   {
1195      fatalerror("PPC: Unknown IRQ line %d", irqline);
1196   }
1197}
1198#endif
1199
1200#if (HAS_PPC603)
1201static void ppcdrc603_init(int index, int clock, const void *_config, int (*irqcallback)(int))
1202{
1203   int pll_config = 0;
1204   float multiplier;
1205   const ppc_config *config = _config;
1206   int i;
1207
1208   ppc_init();
1209   ppcdrc_init();
1210
1211   ppc.optable[48] = recompile_lfs;
1212   ppc.optable[49] = recompile_lfsu;
1213   ppc.optable[50] = recompile_lfd;
1214   ppc.optable[51] = recompile_lfdu;
1215   ppc.optable[52] = recompile_stfs;
1216   ppc.optable[53] = recompile_stfsu;
1217   ppc.optable[54] = recompile_stfd;
1218   ppc.optable[55] = recompile_stfdu;
1219   ppc.optable31[631] = recompile_lfdux;
1220   ppc.optable31[599] = recompile_lfdx;
1221   ppc.optable31[567] = recompile_lfsux;
1222   ppc.optable31[535] = recompile_lfsx;
1223   ppc.optable31[595] = recompile_mfsr;
1224   ppc.optable31[659] = recompile_mfsrin;
1225   ppc.optable31[371] = recompile_mftb;
1226   ppc.optable31[210] = recompile_mtsr;
1227   ppc.optable31[242] = recompile_mtsrin;
1228   ppc.optable31[758] = recompile_dcba;
1229   ppc.optable31[759] = recompile_stfdux;
1230   ppc.optable31[727] = recompile_stfdx;
1231   ppc.optable31[983] = recompile_stfiwx;
1232   ppc.optable31[695] = recompile_stfsux;
1233   ppc.optable31[663] = recompile_stfsx;
1234   ppc.optable31[370] = recompile_tlbia;
1235   ppc.optable31[306] = recompile_tlbie;
1236   ppc.optable31[566] = recompile_tlbsync;
1237   ppc.optable31[310] = recompile_eciwx;
1238   ppc.optable31[438] = recompile_ecowx;
1239
1240   ppc.optable63[264] = recompile_fabsx;
1241   ppc.optable63[21] = recompile_faddx;
1242   ppc.optable63[32] = recompile_fcmpo;
1243   ppc.optable63[0] = recompile_fcmpu;
1244   ppc.optable63[14] = recompile_fctiwx;
1245   ppc.optable63[15] = recompile_fctiwzx;
1246   ppc.optable63[18] = recompile_fdivx;
1247   ppc.optable63[72] = recompile_fmrx;
1248   ppc.optable63[136] = recompile_fnabsx;
1249   ppc.optable63[40] = recompile_fnegx;
1250   ppc.optable63[12] = recompile_frspx;
1251   ppc.optable63[26] = recompile_frsqrtex;
1252   ppc.optable63[22] = recompile_fsqrtx;
1253   ppc.optable63[20] = recompile_fsubx;
1254   ppc.optable63[583] = recompile_mffsx;
1255   ppc.optable63[70] = recompile_mtfsb0x;
1256   ppc.optable63[38] = recompile_mtfsb1x;
1257   ppc.optable63[711] = recompile_mtfsfx;
1258   ppc.optable63[134] = recompile_mtfsfix;
1259   ppc.optable63[64] = recompile_mcrfs;
1260
1261   ppc.optable59[21] = recompile_faddsx;
1262   ppc.optable59[18] = recompile_fdivsx;
1263   ppc.optable59[24] = recompile_fresx;
1264   ppc.optable59[22] = recompile_fsqrtsx;
1265   ppc.optable59[20] = recompile_fsubsx;
1266
1267   for(i = 0; i < 32; i++)
1268   {
1269      ppc.optable63[i * 32 | 29] = recompile_fmaddx;
1270      ppc.optable63[i * 32 | 28] = recompile_fmsubx;
1271      ppc.optable63[i * 32 | 25] = recompile_fmulx;
1272      ppc.optable63[i * 32 | 31] = recompile_fnmaddx;
1273      ppc.optable63[i * 32 | 30] = recompile_fnmsubx;
1274      ppc.optable63[i * 32 | 23] = recompile_fselx;
1275
1276      ppc.optable59[i * 32 | 29] = recompile_fmaddsx;
1277      ppc.optable59[i * 32 | 28] = recompile_fmsubsx;
1278      ppc.optable59[i * 32 | 25] = recompile_fmulsx;
1279      ppc.optable59[i * 32 | 31] = recompile_fnmaddsx;
1280      ppc.optable59[i * 32 | 30] = recompile_fnmsubsx;
1281   }
1282
1283#if (HAS_PPC602 || HAS_MPC8240)
1284   ppc.optable31[978] = recompile_tlbld;
1285#endif /* (HAS_PPC602 || HAS_MPC8240) */
1286
1287   for(i = 0; i < 256; i++)
1288   {
1289      ppc_field_xlat[i] =
1290         ((i & 0x80) ? 0xF0000000 : 0) |
1291         ((i & 0x40) ? 0x0F000000 : 0) |
1292         ((i & 0x20) ? 0x00F00000 : 0) |
1293         ((i & 0x10) ? 0x000F0000 : 0) |
1294         ((i & 0x08) ? 0x0000F000 : 0) |
1295         ((i & 0x04) ? 0x00000F00 : 0) |
1296         ((i & 0x02) ? 0x000000F0 : 0) |
1297         ((i & 0x01) ? 0x0000000F : 0);
1298   }
1299
1300   ppc.is603 = 1;
1301
1302   ppc.read8 = program_read_byte_64be;
1303   ppc.read16 = program_read_word_64be;
1304   ppc.read32 = program_read_dword_64be;
1305   ppc.read64 = program_read_qword_64be;
1306   ppc.write8 = program_write_byte_64be;
1307   ppc.write16 = program_write_word_64be;
1308   ppc.write32 = program_write_dword_64be;
1309   ppc.write64 = program_write_qword_64be;
1310   ppc.read16_unaligned = ppc_read16_unaligned;
1311   ppc.read32_unaligned = ppc_read32_unaligned;
1312   ppc.read64_unaligned = ppc_read64_unaligned;
1313   ppc.write16_unaligned = ppc_write16_unaligned;
1314   ppc.write32_unaligned = ppc_write32_unaligned;
1315   ppc.write64_unaligned = ppc_write64_unaligned;
1316
1317   ppc.irq_callback = irqcallback;
1318
1319   ppc.pvr = config->pvr;
1320
1321   multiplier = (float)((config->bus_frequency_multiplier >> 4) & 0xf) +
1322             (float)(config->bus_frequency_multiplier & 0xf) / 10.0f;
1323   bus_freq_multiplier = (int)(multiplier * 2);
1324
1325   switch(config->pvr)
1326   {
1327      case PPC_MODEL_603E:   pll_config = mpc603e_pll_config[bus_freq_multiplier-1][config->bus_frequency]; break;
1328      case PPC_MODEL_603EV:   pll_config = mpc603ev_pll_config[bus_freq_multiplier-1][config->bus_frequency]; break;
1329      case PPC_MODEL_603R:   pll_config = mpc603r_pll_config[bus_freq_multiplier-1][config->bus_frequency]; break;
1330      default: break;
1331   }
1332
1333   if (pll_config == -1)
1334   {
1335      fatalerror("PPC: Invalid bus/multiplier combination (bus frequency = %d, multiplier = %1.1f)", config->bus_frequency, multiplier);
1336   }
1337
1338   ppc.hid1 = pll_config << 28;
1339}
1340
1341static void ppcdrc603_exit(void)
1342{
1343#if LOG_CODE
1344   //if (symfile) fclose(symfile);
1345#endif
1346   ppcdrc_exit();
1347}
1348#endif
1349
1350#if (HAS_PPC601 || HAS_PPC603 || HAS_MPC8240 || HAS_PPC604)
1351static void ppcdrc603_reset(void)
1352{
1353   ppc.pc = ppc.npc = 0xfff00100;
1354
1355   ppc_set_msr(0x40);
1356   change_pc(ppc.pc);
1357
1358   /* reset the DRC */
1359   drc_cache_reset(ppc.drc);
1360}
1361
1362static int ppcdrc603_execute(int cycles)
1363{
1364   /* count cycles and interrupt cycles */
1365   ppc_icount = cycles;
1366   ppc_tb_base_icount = cycles;
1367   ppc_dec_base_icount = cycles + ppc.dec_frac;
1368
1369   // check if decrementer exception occurs during execution
1370   if ((UINT32)(DEC - ppc_icount) > (UINT32)(DEC))
1371   {
1372      ppc_dec_trigger_cycle = ppc_icount - DEC;
1373   }
1374   else
1375   {
1376      ppc_dec_trigger_cycle = 0x7fffffff;
1377   }
1378
1379   drc_execute(ppc.drc);
1380
1381   // update timebase
1382   // timebase is incremented once every four core clock cycles, so adjust the cycles accordingly
1383   ppc.tb += ((ppc_tb_base_icount - ppc_icount) / 4);
1384
1385   // update decrementer
1386   ppc.dec_frac = ((ppc_dec_base_icount - ppc_icount) % (bus_freq_multiplier * 2));
1387   DEC -= ((ppc_dec_base_icount - ppc_icount) / (bus_freq_multiplier * 2));
1388
1389   return cycles - ppc_icount;
1390}
1391
1392static void ppcdrc603_set_irq_line(int irqline, int state)
1393{
1394   if( state ) {
1395      ppc.exception_pending |= 0x1;
1396      if (ppc.irq_callback)
1397      {
1398         ppc.irq_callback(irqline);
1399      }
1400   }
1401}
1402#endif
1403
1404#if (HAS_PPC602)
1405static void ppcdrc602_init(int index, int clock, const void *_config, int (*irqcallback)(int))
1406{
1407   float multiplier;
1408   const ppc_config *config = _config;
1409   int i;
1410
1411   ppc_init();
1412   ppcdrc_init();
1413
1414   ppc.optable[48] = recompile_lfs;
1415   ppc.optable[49] = recompile_lfsu;
1416   ppc.optable[50] = recompile_lfd;
1417   ppc.optable[51] = recompile_lfdu;
1418   ppc.optable[52] = recompile_stfs;
1419   ppc.optable[53] = recompile_stfsu;
1420   ppc.optable[54] = recompile_stfd;
1421   ppc.optable[55] = recompile_stfdu;
1422   ppc.optable31[631] = recompile_lfdux;
1423   ppc.optable31[599] = recompile_lfdx;
1424   ppc.optable31[567] = recompile_lfsux;
1425   ppc.optable31[535] = recompile_lfsx;
1426   ppc.optable31[595] = recompile_mfsr;
1427   ppc.optable31[659] = recompile_mfsrin;
1428   ppc.optable31[371] = recompile_mftb;
1429   ppc.optable31[210] = recompile_mtsr;
1430   ppc.optable31[242] = recompile_mtsrin;
1431   ppc.optable31[758] = recompile_dcba;
1432   ppc.optable31[759] = recompile_stfdux;
1433   ppc.optable31[727] = recompile_stfdx;
1434   ppc.optable31[983] = recompile_stfiwx;
1435   ppc.optable31[695] = recompile_stfsux;
1436   ppc.optable31[663] = recompile_stfsx;
1437   ppc.optable31[370] = recompile_tlbia;
1438   ppc.optable31[306] = recompile_tlbie;
1439   ppc.optable31[566] = recompile_tlbsync;
1440   ppc.optable31[310] = recompile_eciwx;
1441   ppc.optable31[438] = recompile_ecowx;
1442
1443   ppc.optable63[264] = recompile_fabsx;
1444   ppc.optable63[21] = recompile_faddx;
1445   ppc.optable63[32] = recompile_fcmpo;
1446   ppc.optable63[0] = recompile_fcmpu;
1447   ppc.optable63[14] = recompile_fctiwx;
1448   ppc.optable63[15] = recompile_fctiwzx;
1449   ppc.optable63[18] = recompile_fdivx;
1450   ppc.optable63[72] = recompile_fmrx;
1451   ppc.optable63[136] = recompile_fnabsx;
1452   ppc.optable63[40] = recompile_fnegx;
1453   ppc.optable63[12] = recompile_frspx;
1454   ppc.optable63[26] = recompile_frsqrtex;
1455   ppc.optable63[22] = recompile_fsqrtx;
1456   ppc.optable63[20] = recompile_fsubx;
1457   ppc.optable63[583] = recompile_mffsx;
1458   ppc.optable63[70] = recompile_mtfsb0x;
1459   ppc.optable63[38] = recompile_mtfsb1x;
1460   ppc.optable63[711] = recompile_mtfsfx;
1461   ppc.optable63[134] = recompile_mtfsfix;
1462   ppc.optable63[64] = recompile_mcrfs;
1463
1464   ppc.optable59[21] = recompile_faddsx;
1465   ppc.optable59[18] = recompile_fdivsx;
1466   ppc.optable59[24] = recompile_fresx;
1467   ppc.optable59[22] = recompile_fsqrtsx;
1468   ppc.optable59[20] = recompile_fsubsx;
1469
1470   for(i = 0; i < 32; i++)
1471   {
1472      ppc.optable63[i * 32 | 29] = recompile_fmaddx;
1473      ppc.optable63[i * 32 | 28] = recompile_fmsubx;
1474      ppc.optable63[i * 32 | 25] = recompile_fmulx;
1475      ppc.optable63[i * 32 | 31] = recompile_fnmaddx;
1476      ppc.optable63[i * 32 | 30] = recompile_fnmsubx;
1477      ppc.optable63[i * 32 | 23] = recompile_fselx;
1478
1479      ppc.optable59[i * 32 | 29] = recompile_fmaddsx;
1480      ppc.optable59[i * 32 | 28] = recompile_fmsubsx;
1481      ppc.optable59[i * 32 | 25] = recompile_fmulsx;
1482      ppc.optable59[i * 32 | 31] = recompile_fnmaddsx;
1483      ppc.optable59[i * 32 | 30] = recompile_fnmsubsx;
1484   }
1485
1486   for(i = 0; i < 256; i++)
1487   {
1488      ppc_field_xlat[i] =
1489         ((i & 0x80) ? 0xF0000000 : 0) |
1490         ((i & 0x40) ? 0x0F000000 : 0) |
1491         ((i & 0x20) ? 0x00F00000 : 0) |
1492         ((i & 0x10) ? 0x000F0000 : 0) |
1493         ((i & 0x08) ? 0x0000F000 : 0) |
1494         ((i & 0x04) ? 0x00000F00 : 0) |
1495         ((i & 0x02) ? 0x000000F0 : 0) |
1496         ((i & 0x01) ? 0x0000000F : 0);
1497   }
1498
1499   // PPC602 specific opcodes
1500   ppc.optable31[596] = recompile_esa;
1501   ppc.optable31[628] = recompile_dsa;
1502   ppc.optable31[1010] = recompile_tlbli;
1503   ppc.optable31[978] = recompile_tlbld;
1504
1505   ppc.is603 = 0;
1506   ppc.is602 = 1;
1507
1508   ppc.read8 = program_read_byte_64be;
1509   ppc.read16 = program_read_word_64be;
1510   ppc.read32 = program_read_dword_64be;
1511   ppc.read64 = program_read_qword_64be;
1512   ppc.write8 = program_write_byte_64be;
1513   ppc.write16 = program_write_word_64be;
1514   ppc.write32 = program_write_dword_64be;
1515   ppc.write64 = program_write_qword_64be;
1516   ppc.read16_unaligned = ppc_read16_unaligned;
1517   ppc.read32_unaligned = ppc_read32_unaligned;
1518   ppc.read64_unaligned = ppc_read64_unaligned;
1519   ppc.write16_unaligned = ppc_write16_unaligned;
1520   ppc.write32_unaligned = ppc_write32_unaligned;
1521   ppc.write64_unaligned = ppc_write64_unaligned;
1522
1523   ppc.irq_callback = irqcallback;
1524
1525   ppc.pvr = config->pvr;
1526
1527   multiplier = (float)((config->bus_frequency_multiplier >> 4) & 0xf) +
1528             (float)(config->bus_frequency_multiplier & 0xf) / 10.0f;
1529   bus_freq_multiplier = (int)(multiplier * 2);
1530}
1531
1532static void ppcdrc602_exit(void)
1533{
1534#if LOG_CODE
1535   //if (symfile) fclose(symfile);
1536#endif
1537   ppcdrc_exit();
1538}
1539
1540static void ppcdrc602_reset(void)
1541{
1542   ppc.pc = ppc.npc = 0xfff00100;
1543
1544   ppc_set_msr(0x40);
1545   change_pc(ppc.pc);
1546
1547   ppc.hid0 = 1;
1548
1549   /* reset the DRC */
1550   drc_cache_reset(ppc.drc);
1551}
1552
1553static int ppcdrc602_execute(int cycles)
1554{
1555   /* count cycles and interrupt cycles */
1556   ppc_icount = cycles;
1557   ppc_tb_base_icount = cycles;
1558   ppc_dec_base_icount = cycles;
1559
1560   // check if decrementer exception occurs during execution
1561   if ((UINT32)(DEC - ppc_icount) > (UINT32)(DEC))
1562   {
1563      ppc_dec_trigger_cycle = ppc_icount - DEC;
1564   }
1565   else
1566   {
1567      ppc_dec_trigger_cycle = 0x7fffffff;
1568   }
1569
1570   drc_execute(ppc.drc);
1571
1572   // update timebase
1573   // timebase is incremented once every four core clock cycles, so adjust the cycles accordingly
1574   ppc.tb += ((ppc_tb_base_icount - ppc_icount) / 4);
1575
1576   // update decrementer
1577   DEC -= ((ppc_dec_base_icount - ppc_icount) / (bus_freq_multiplier * 2));
1578
1579   return cycles - ppc_icount;
1580}
1581
1582static void ppcdrc602_set_irq_line(int irqline, int state)
1583{
1584   if( state ) {
1585      ppc.exception_pending |= 0x1;
1586      if (ppc.irq_callback)
1587      {
1588         ppc.irq_callback(irqline);
1589      }
1590   }
1591}
1592#endif
1593
1594#if (HAS_MPC8240)
1595static void mpc8240drc_init(int index, int clock, const void *_config, int (*irqcallback)(int))
1596{
1597   float multiplier;
1598   const ppc_config *config = _config;
1599   int i;
1600
1601   ppc_init();
1602   ppcdrc_init();
1603
1604   ppc.optable[48] = recompile_lfs;
1605   ppc.optable[49] = recompile_lfsu;
1606   ppc.optable[50] = recompile_lfd;
1607   ppc.optable[51] = recompile_lfdu;
1608   ppc.optable[52] = recompile_stfs;
1609   ppc.optable[53] = recompile_stfsu;
1610   ppc.optable[54] = recompile_stfd;
1611   ppc.optable[55] = recompile_stfdu;
1612   ppc.optable31[631] = recompile_lfdux;
1613   ppc.optable31[599] = recompile_lfdx;
1614   ppc.optable31[567] = recompile_lfsux;
1615   ppc.optable31[535] = recompile_lfsx;
1616   ppc.optable31[595] = recompile_mfsr;
1617   ppc.optable31[659] = recompile_mfsrin;
1618   ppc.optable31[371] = recompile_mftb;
1619   ppc.optable31[210] = recompile_mtsr;
1620   ppc.optable31[242] = recompile_mtsrin;
1621   ppc.optable31[758] = recompile_dcba;
1622   ppc.optable31[759] = recompile_stfdux;
1623   ppc.optable31[727] = recompile_stfdx;
1624   ppc.optable31[983] = recompile_stfiwx;
1625   ppc.optable31[695] = recompile_stfsux;
1626   ppc.optable31[663] = recompile_stfsx;
1627   ppc.optable31[370] = recompile_tlbia;
1628   ppc.optable31[306] = recompile_tlbie;
1629   ppc.optable31[566] = recompile_tlbsync;
1630   ppc.optable31[310] = recompile_eciwx;
1631   ppc.optable31[438] = recompile_ecowx;
1632
1633   ppc.optable63[264] = recompile_fabsx;
1634   ppc.optable63[21] = recompile_faddx;
1635   ppc.optable63[32] = recompile_fcmpo;
1636   ppc.optable63[0] = recompile_fcmpu;
1637   ppc.optable63[14] = recompile_fctiwx;
1638   ppc.optable63[15] = recompile_fctiwzx;
1639   ppc.optable63[18] = recompile_fdivx;
1640   ppc.optable63[72] = recompile_fmrx;
1641   ppc.optable63[136] = recompile_fnabsx;
1642   ppc.optable63[40] = recompile_fnegx;
1643   ppc.optable63[12] = recompile_frspx;
1644   ppc.optable63[26] = recompile_frsqrtex;
1645   ppc.optable63[22] = recompile_fsqrtx;
1646   ppc.optable63[20] = recompile_fsubx;
1647   ppc.optable63[583] = recompile_mffsx;
1648   ppc.optable63[70] = recompile_mtfsb0x;
1649   ppc.optable63[38] = recompile_mtfsb1x;
1650   ppc.optable63[711] = recompile_mtfsfx;
1651   ppc.optable63[134] = recompile_mtfsfix;
1652   ppc.optable63[64] = recompile_mcrfs;
1653
1654   ppc.optable59[21] = recompile_faddsx;
1655   ppc.optable59[18] = recompile_fdivsx;
1656   ppc.optable59[24] = recompile_fresx;
1657   ppc.optable59[22] = recompile_fsqrtsx;
1658   ppc.optable59[20] = recompile_fsubsx;
1659
1660   for(i = 0; i < 32; i++)
1661   {
1662      ppc.optable63[i * 32 | 29] = recompile_fmaddx;
1663      ppc.optable63[i * 32 | 28] = recompile_fmsubx;
1664      ppc.optable63[i * 32 | 25] = recompile_fmulx;
1665      ppc.optable63[i * 32 | 31] = recompile_fnmaddx;
1666      ppc.optable63[i * 32 | 30] = recompile_fnmsubx;
1667      ppc.optable63[i * 32 | 23] = recompile_fselx;
1668
1669      ppc.optable59[i * 32 | 29] = recompile_fmaddsx;
1670      ppc.optable59[i * 32 | 28] = recompile_fmsubsx;
1671      ppc.optable59[i * 32 | 25] = recompile_fmulsx;
1672      ppc.optable59[i * 32 | 31] = recompile_fnmaddsx;
1673      ppc.optable59[i * 32 | 30] = recompile_fnmsubsx;
1674   }
1675
1676   for(i = 0; i < 256; i++)
1677   {
1678      ppc_field_xlat[i] =
1679         ((i & 0x80) ? 0xF0000000 : 0) |
1680         ((i & 0x40) ? 0x0F000000 : 0) |
1681         ((i & 0x20) ? 0x00F00000 : 0) |
1682         ((i & 0x10) ? 0x000F0000 : 0) |
1683         ((i & 0x08) ? 0x0000F000 : 0) |
1684         ((i & 0x04) ? 0x00000F00 : 0) |
1685         ((i & 0x02) ? 0x000000F0 : 0) |
1686         ((i & 0x01) ? 0x0000000F : 0);
1687   }
1688
1689   // MPC8240 specific opcodes
1690   ppc.optable31[978] = recompile_tlbld;
1691   ppc.optable31[1010] = recompile_tlbli;
1692
1693   ppc.is603 = 1;
1694
1695   ppc.read8 = program_read_byte_64be;
1696   ppc.read16 = program_read_word_64be;
1697   ppc.read32 = program_read_dword_64be;
1698   ppc.read64 = program_read_qword_64be;
1699   ppc.write8 = program_write_byte_64be;
1700   ppc.write16 = program_write_word_64be;
1701   ppc.write32 = program_write_dword_64be;
1702   ppc.write64 = program_write_qword_64be;
1703   ppc.read16_unaligned = ppc_read16_unaligned;
1704   ppc.read32_unaligned = ppc_read32_unaligned;
1705   ppc.read64_unaligned = ppc_read64_unaligned;
1706   ppc.write16_unaligned = ppc_write16_unaligned;
1707   ppc.write32_unaligned = ppc_write32_unaligned;
1708   ppc.write64_unaligned = ppc_write64_unaligned;
1709
1710   ppc.irq_callback = irqcallback;
1711
1712   ppc.pvr = config->pvr;
1713
1714   multiplier = (float)((config->bus_frequency_multiplier >> 4) & 0xf) +
1715             (float)(config->bus_frequency_multiplier & 0xf) / 10.0f;
1716   bus_freq_multiplier = (int)(multiplier * 2);
1717}
1718
1719static void mpc8240drc_exit(void)
1720{
1721   ppcdrc_exit();
1722}
1723#endif
1724
1725
1726#if (HAS_PPC601)
1727static void ppc601drc_init(int index, int clock, const void *_config, int (*irqcallback)(int))
1728{
1729   int pll_config = 0;
1730   float multiplier;
1731   const ppc_config *config = _config;
1732   int i;
1733
1734   ppc_init();
1735   ppcdrc_init();
1736
1737   ppc.optable[48] = recompile_lfs;
1738   ppc.optable[49] = recompile_lfsu;
1739   ppc.optable[50] = recompile_lfd;
1740   ppc.optable[51] = recompile_lfdu;
1741   ppc.optable[52] = recompile_stfs;
1742   ppc.optable[53] = recompile_stfsu;
1743   ppc.optable[54] = recompile_stfd;
1744   ppc.optable[55] = recompile_stfdu;
1745   ppc.optable31[631] = recompile_lfdux;
1746   ppc.optable31[599] = recompile_lfdx;
1747   ppc.optable31[567] = recompile_lfsux;
1748   ppc.optable31[535] = recompile_lfsx;
1749   ppc.optable31[595] = recompile_mfsr;
1750   ppc.optable31[659] = recompile_mfsrin;
1751   ppc.optable31[371] = recompile_mftb;
1752   ppc.optable31[210] = recompile_mtsr;
1753   ppc.optable31[242] = recompile_mtsrin;
1754   ppc.optable31[758] = recompile_dcba;
1755   ppc.optable31[759] = recompile_stfdux;
1756   ppc.optable31[727] = recompile_stfdx;
1757   ppc.optable31[983] = recompile_stfiwx;
1758   ppc.optable31[695] = recompile_stfsux;
1759   ppc.optable31[663] = recompile_stfsx;
1760   ppc.optable31[370] = recompile_tlbia;
1761   ppc.optable31[306] = recompile_tlbie;
1762   ppc.optable31[566] = recompile_tlbsync;
1763   ppc.optable31[310] = recompile_eciwx;
1764   ppc.optable31[438] = recompile_ecowx;
1765
1766   ppc.optable63[264] = recompile_fabsx;
1767   ppc.optable63[21] = recompile_faddx;
1768   ppc.optable63[32] = recompile_fcmpo;
1769   ppc.optable63[0] = recompile_fcmpu;
1770   ppc.optable63[14] = recompile_fctiwx;
1771   ppc.optable63[15] = recompile_fctiwzx;
1772   ppc.optable63[18] = recompile_fdivx;
1773   ppc.optable63[72] = recompile_fmrx;
1774   ppc.optable63[136] = recompile_fnabsx;
1775   ppc.optable63[40] = recompile_fnegx;
1776   ppc.optable63[12] = recompile_frspx;
1777   ppc.optable63[26] = recompile_frsqrtex;
1778   ppc.optable63[22] = recompile_fsqrtx;
1779   ppc.optable63[20] = recompile_fsubx;
1780   ppc.optable63[583] = recompile_mffsx;
1781   ppc.optable63[70] = recompile_mtfsb0x;
1782   ppc.optable63[38] = recompile_mtfsb1x;
1783   ppc.optable63[711] = recompile_mtfsfx;
1784   ppc.optable63[134] = recompile_mtfsfix;
1785   ppc.optable63[64] = recompile_mcrfs;
1786
1787   ppc.optable59[21] = recompile_faddsx;
1788   ppc.optable59[18] = recompile_fdivsx;
1789   ppc.optable59[24] = recompile_fresx;
1790   ppc.optable59[22] = recompile_fsqrtsx;
1791   ppc.optable59[20] = recompile_fsubsx;
1792
1793   for(i = 0; i < 32; i++)
1794   {
1795      ppc.optable63[i * 32 | 29] = recompile_fmaddx;
1796      ppc.optable63[i * 32 | 28] = recompile_fmsubx;
1797      ppc.optable63[i * 32 | 25] = recompile_fmulx;
1798      ppc.optable63[i * 32 | 31] = recompile_fnmaddx;
1799      ppc.optable63[i * 32 | 30] = recompile_fnmsubx;
1800      ppc.optable63[i * 32 | 23] = recompile_fselx;
1801
1802      ppc.optable59[i * 32 | 29] = recompile_fmaddsx;
1803      ppc.optable59[i * 32 | 28] = recompile_fmsubsx;
1804      ppc.optable59[i * 32 | 25] = recompile_fmulsx;
1805      ppc.optable59[i * 32 | 31] = recompile_fnmaddsx;
1806      ppc.optable59[i * 32 | 30] = recompile_fnmsubsx;
1807   }
1808
1809   for(i = 0; i < 256; i++)
1810   {
1811      ppc_field_xlat[i] =
1812         ((i & 0x80) ? 0xF0000000 : 0) |
1813         ((i & 0x40) ? 0x0F000000 : 0) |
1814         ((i & 0x20) ? 0x00F00000 : 0) |
1815         ((i & 0x10) ? 0x000F0000 : 0) |
1816         ((i & 0x08) ? 0x0000F000 : 0) |
1817         ((i & 0x04) ? 0x00000F00 : 0) |
1818         ((i & 0x02) ? 0x000000F0 : 0) |
1819         ((i & 0x01) ? 0x0000000F : 0);
1820   }
1821
1822   ppc.is603 = 1;
1823
1824   ppc.read8 = program_read_byte_64be;
1825   ppc.read16 = program_read_word_64be;
1826   ppc.read32 = program_read_dword_64be;
1827   ppc.read64 = program_read_qword_64be;
1828   ppc.write8 = program_write_byte_64be;
1829   ppc.write16 = program_write_word_64be;
1830   ppc.write32 = program_write_dword_64be;
1831   ppc.write64 = program_write_qword_64be;
1832   ppc.read16_unaligned = ppc_read16_unaligned;
1833   ppc.read32_unaligned = ppc_read32_unaligned;
1834   ppc.read64_unaligned = ppc_read64_unaligned;
1835   ppc.write16_unaligned = ppc_write16_unaligned;
1836   ppc.write32_unaligned = ppc_write32_unaligned;
1837   ppc.write64_unaligned = ppc_write64_unaligned;
1838
1839   ppc.irq_callback = irqcallback;
1840
1841   ppc.pvr = config->pvr;
1842
1843   multiplier = (float)((config->bus_frequency_multiplier >> 4) & 0xf) +
1844             (float)(config->bus_frequency_multiplier & 0xf) / 10.0f;
1845   bus_freq_multiplier = (int)(multiplier * 2);
1846
1847   switch(config->pvr)
1848   {
1849      case PPC_MODEL_603E:   pll_config = mpc603e_pll_config[bus_freq_multiplier-1][config->bus_frequency]; break;
1850      case PPC_MODEL_603EV:   pll_config = mpc603ev_pll_config[bus_freq_multiplier-1][config->bus_frequency]; break;
1851      case PPC_MODEL_603R:   pll_config = mpc603r_pll_config[bus_freq_multiplier-1][config->bus_frequency]; break;
1852      default: break;
1853   }
1854
1855   if (pll_config == -1)
1856   {
1857      fatalerror("PPC: Invalid bus/multiplier combination (bus frequency = %d, multiplier = %1.1f)", config->bus_frequency, multiplier);
1858   }
1859
1860   ppc.hid1 = pll_config << 28;
1861}
1862
1863static void ppc601drc_exit(void)
1864{
1865#if LOG_CODE
1866   //if (symfile) fclose(symfile);
1867#endif
1868   ppcdrc_exit();
1869}
1870#endif
1871
1872
1873#if (HAS_PPC604)
1874static void ppc604drc_init(int index, int clock, const void *_config, int (*irqcallback)(int))
1875{
1876   float multiplier;
1877   const ppc_config *config = _config;
1878   int i;
1879
1880   ppc_init();
1881   ppcdrc_init();
1882
1883   ppc.optable[48] = recompile_lfs;
1884   ppc.optable[49] = recompile_lfsu;
1885   ppc.optable[50] = recompile_lfd;
1886   ppc.optable[51] = recompile_lfdu;
1887   ppc.optable[52] = recompile_stfs;
1888   ppc.optable[53] = recompile_stfsu;
1889   ppc.optable[54] = recompile_stfd;
1890   ppc.optable[55] = recompile_stfdu;
1891   ppc.optable31[631] = recompile_lfdux;
1892   ppc.optable31[599] = recompile_lfdx;
1893   ppc.optable31[567] = recompile_lfsux;
1894   ppc.optable31[535] = recompile_lfsx;
1895   ppc.optable31[595] = recompile_mfsr;
1896   ppc.optable31[659] = recompile_mfsrin;
1897   ppc.optable31[371] = recompile_mftb;
1898   ppc.optable31[210] = recompile_mtsr;
1899   ppc.optable31[242] = recompile_mtsrin;
1900   ppc.optable31[758] = recompile_dcba;
1901   ppc.optable31[759] = recompile_stfdux;
1902   ppc.optable31[727] = recompile_stfdx;
1903   ppc.optable31[983] = recompile_stfiwx;
1904   ppc.optable31[695] = recompile_stfsux;
1905   ppc.optable31[663] = recompile_stfsx;
1906   ppc.optable31[370] = recompile_tlbia;
1907   ppc.optable31[306] = recompile_tlbie;
1908   ppc.optable31[566] = recompile_tlbsync;
1909   ppc.optable31[310] = recompile_eciwx;
1910   ppc.optable31[438] = recompile_ecowx;
1911
1912   ppc.optable63[264] = recompile_fabsx;
1913   ppc.optable63[21] = recompile_faddx;
1914   ppc.optable63[32] = recompile_fcmpo;
1915   ppc.optable63[0] = recompile_fcmpu;
1916   ppc.optable63[14] = recompile_fctiwx;
1917   ppc.optable63[15] = recompile_fctiwzx;
1918   ppc.optable63[18] = recompile_fdivx;
1919   ppc.optable63[72] = recompile_fmrx;
1920   ppc.optable63[136] = recompile_fnabsx;
1921   ppc.optable63[40] = recompile_fnegx;
1922   ppc.optable63[12] = recompile_frspx;
1923   ppc.optable63[26] = recompile_frsqrtex;
1924   ppc.optable63[22] = recompile_fsqrtx;
1925   ppc.optable63[20] = recompile_fsubx;
1926   ppc.optable63[583] = recompile_mffsx;
1927   ppc.optable63[70] = recompile_mtfsb0x;
1928   ppc.optable63[38] = recompile_mtfsb1x;
1929   ppc.optable63[711] = recompile_mtfsfx;
1930   ppc.optable63[134] = recompile_mtfsfix;
1931   ppc.optable63[64] = recompile_mcrfs;
1932
1933   ppc.optable59[21] = recompile_faddsx;
1934   ppc.optable59[18] = recompile_fdivsx;
1935   ppc.optable59[24] = recompile_fresx;
1936   ppc.optable59[22] = recompile_fsqrtsx;
1937   ppc.optable59[20] = recompile_fsubsx;
1938
1939   for(i = 0; i < 32; i++)
1940   {
1941      ppc.optable63[i * 32 | 29] = recompile_fmaddx;
1942      ppc.optable63[i * 32 | 28] = recompile_fmsubx;
1943      ppc.optable63[i * 32 | 25] = recompile_fmulx;
1944      ppc.optable63[i * 32 | 31] = recompile_fnmaddx;
1945      ppc.optable63[i * 32 | 30] = recompile_fnmsubx;
1946      ppc.optable63[i * 32 | 23] = recompile_fselx;
1947
1948      ppc.optable59[i * 32 | 29] = recompile_fmaddsx;
1949      ppc.optable59[i * 32 | 28] = recompile_fmsubsx;
1950      ppc.optable59[i * 32 | 25] = recompile_fmulsx;
1951      ppc.optable59[i * 32 | 31] = recompile_fnmaddsx;
1952      ppc.optable59[i * 32 | 30] = recompile_fnmsubsx;
1953   }
1954
1955   ppc.optable31[978] = recompile_tlbld;
1956
1957   for(i = 0; i < 256; i++)
1958   {
1959      ppc_field_xlat[i] =
1960         ((i & 0x80) ? 0xF0000000 : 0) |
1961         ((i & 0x40) ? 0x0F000000 : 0) |
1962         ((i & 0x20) ? 0x00F00000 : 0) |
1963         ((i & 0x10) ? 0x000F0000 : 0) |
1964         ((i & 0x08) ? 0x0000F000 : 0) |
1965         ((i & 0x04) ? 0x00000F00 : 0) |
1966         ((i & 0x02) ? 0x000000F0 : 0) |
1967         ((i & 0x01) ? 0x0000000F : 0);
1968   }
1969
1970   ppc.is603 = 1;
1971
1972   ppc.read8 = program_read_byte_64be;
1973   ppc.read16 = program_read_word_64be;
1974   ppc.read32 = program_read_dword_64be;
1975   ppc.read64 = program_read_qword_64be;
1976   ppc.write8 = program_write_byte_64be;
1977   ppc.write16 = program_write_word_64be;
1978   ppc.write32 = program_write_dword_64be;
1979   ppc.write64 = program_write_qword_64be;
1980   ppc.read16_unaligned = ppc_read16_unaligned;
1981   ppc.read32_unaligned = ppc_read32_unaligned;
1982   ppc.read64_unaligned = ppc_read64_unaligned;
1983   ppc.write16_unaligned = ppc_write16_unaligned;
1984   ppc.write32_unaligned = ppc_write32_unaligned;
1985   ppc.write64_unaligned = ppc_write64_unaligned;
1986
1987   ppc.irq_callback = irqcallback;
1988
1989   ppc.pvr = config->pvr;
1990
1991   multiplier = (float)((config->bus_frequency_multiplier >> 4) & 0xf) +
1992             (float)(config->bus_frequency_multiplier & 0xf) / 10.0f;
1993   bus_freq_multiplier = (int)(multiplier * 2);
1994}
1995
1996static void ppc604drc_exit(void)
1997{
1998#if LOG_CODE
1999   //if (symfile) fclose(symfile);
2000#endif
2001   ppcdrc_exit();
2002}
2003#endif
2004
2005
2006static void ppc_get_context(void *dst)
2007{
2008   /* copy the context */
2009   if (dst)
2010      *(PPC_REGS *)dst = ppc;
2011}
2012
2013
2014static void ppc_set_context(void *src)
2015{
2016   /* copy the context */
2017   if (src)
2018      ppc = *(PPC_REGS *)src;
2019
2020   change_pc(ppc.pc);
2021}
2022
2023
2024/**************************************************************************
2025 * Generic set_info
2026 **************************************************************************/
2027
2028static void ppc_set_info(UINT32 state, cpuinfo *info)
2029{
2030   switch (state)
2031   {
2032      case CPUINFO_INT_PC:
2033      case CPUINFO_INT_REGISTER + PPC_PC:            ppc.pc = info->i;                  break;
2034      case CPUINFO_INT_REGISTER + PPC_MSR:         ppc_set_msr(info->i);                break;
2035      case CPUINFO_INT_REGISTER + PPC_CR:            ppc_set_cr(info->i);                break;
2036      case CPUINFO_INT_REGISTER + PPC_LR:            LR = info->i;                     break;
2037      case CPUINFO_INT_REGISTER + PPC_CTR:         CTR = info->i;                     break;
2038      case CPUINFO_INT_REGISTER + PPC_XER:         XER = info->i;                      break;
2039      case CPUINFO_INT_REGISTER + PPC_SRR0:         SRR0 = info->i;                     break;
2040      case CPUINFO_INT_REGISTER + PPC_SRR1:         SRR1 = info->i;                     break;
2041
2042      case CPUINFO_INT_REGISTER + PPC_R0:            ppc.r[0] = info->i;                  break;
2043      case CPUINFO_INT_REGISTER + PPC_R1:            ppc.r[1] = info->i;                  break;
2044      case CPUINFO_INT_REGISTER + PPC_R2:            ppc.r[2] = info->i;                  break;
2045      case CPUINFO_INT_REGISTER + PPC_R3:            ppc.r[3] = info->i;                  break;
2046      case CPUINFO_INT_REGISTER + PPC_R4:            ppc.r[4] = info->i;                  break;
2047      case CPUINFO_INT_REGISTER + PPC_R5:            ppc.r[5] = info->i;                  break;
2048      case CPUINFO_INT_REGISTER + PPC_R6:            ppc.r[6] = info->i;                  break;
2049      case CPUINFO_INT_REGISTER + PPC_R7:            ppc.r[7] = info->i;                  break;
2050      case CPUINFO_INT_REGISTER + PPC_R8:            ppc.r[8] = info->i;                  break;
2051      case CPUINFO_INT_REGISTER + PPC_R9:            ppc.r[9] = info->i;                  break;
2052      case CPUINFO_INT_REGISTER + PPC_R10:         ppc.r[10] = info->i;               break;
2053      case CPUINFO_INT_REGISTER + PPC_R11:         ppc.r[11] = info->i;               break;
2054      case CPUINFO_INT_REGISTER + PPC_R12:         ppc.r[12] = info->i;               break;
2055      case CPUINFO_INT_REGISTER + PPC_R13:         ppc.r[13] = info->i;               break;
2056      case CPUINFO_INT_REGISTER + PPC_R14:         ppc.r[14] = info->i;               break;
2057      case CPUINFO_INT_REGISTER + PPC_R15:         ppc.r[15] = info->i;               break;
2058      case CPUINFO_INT_REGISTER + PPC_R16:         ppc.r[16] = info->i;               break;
2059      case CPUINFO_INT_REGISTER + PPC_R17:         ppc.r[17] = info->i;               break;
2060      case CPUINFO_INT_REGISTER + PPC_R18:         ppc.r[18] = info->i;               break;
2061      case CPUINFO_INT_REGISTER + PPC_R19:         ppc.r[19] = info->i;               break;
2062      case CPUINFO_INT_REGISTER + PPC_R20:         ppc.r[20] = info->i;               break;
2063      case CPUINFO_INT_REGISTER + PPC_R21:         ppc.r[21] = info->i;               break;
2064      case CPUINFO_INT_REGISTER + PPC_R22:         ppc.r[22] = info->i;               break;
2065      case CPUINFO_INT_REGISTER + PPC_R23:         ppc.r[23] = info->i;               break;
2066      case CPUINFO_INT_REGISTER + PPC_R24:         ppc.r[24] = info->i;               break;
2067      case CPUINFO_INT_REGISTER + PPC_R25:         ppc.r[25] = info->i;               break;
2068      case CPUINFO_INT_REGISTER + PPC_R26:         ppc.r[26] = info->i;               break;
2069      case CPUINFO_INT_REGISTER + PPC_R27:         ppc.r[27] = info->i;               break;
2070      case CPUINFO_INT_REGISTER + PPC_R28:         ppc.r[28] = info->i;               break;
2071      case CPUINFO_INT_REGISTER + PPC_R29:         ppc.r[29] = info->i;               break;
2072      case CPUINFO_INT_REGISTER + PPC_R30:         ppc.r[30] = info->i;               break;
2073      case CPUINFO_INT_REGISTER + PPC_R31:         ppc.r[31] = info->i;               break;
2074
2075      case CPUINFO_INT_PPC_DRC_OPTIONS:            ppc.drcoptions = info->i;            break;
2076   }
2077}
2078
2079static void ppc_get_info(UINT32 state, cpuinfo *info)
2080{
2081   switch(state)
2082   {
2083      /* --- the following bits of info are returned as 64-bit signed integers --- */
2084      case CPUINFO_INT_CONTEXT_SIZE:               info->i = sizeof(ppc);               break;
2085      case CPUINFO_INT_INPUT_LINES:               info->i = 1;                     break;
2086      case CPUINFO_INT_DEFAULT_IRQ_VECTOR:         info->i = 0;                     break;
2087      case CPUINFO_INT_ENDIANNESS:               info->i = CPU_IS_BE;               break;
2088      case CPUINFO_INT_CLOCK_MULTIPLIER:            info->i = 1;                     break;
2089      case CPUINFO_INT_CLOCK_DIVIDER:               info->i = 1;                     break;
2090      case CPUINFO_INT_MIN_INSTRUCTION_BYTES:         info->i = 4;                     break;
2091      case CPUINFO_INT_MAX_INSTRUCTION_BYTES:         info->i = 4;                     break;
2092      case CPUINFO_INT_MIN_CYCLES:               info->i = 1;                     break;
2093      case CPUINFO_INT_MAX_CYCLES:               info->i = 40;                     break;
2094
2095      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_PROGRAM:   info->i = 32;               break;
2096      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_PROGRAM: info->i = 32;               break;
2097      case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_PROGRAM: info->i = 0;               break;
2098      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_DATA:   info->i = 0;               break;
2099      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_DATA:    info->i = 0;               break;
2100      case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_DATA:    info->i = 0;               break;
2101      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_IO:      info->i = 0;               break;
2102      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_IO:       info->i = 0;               break;
2103      case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_IO:       info->i = 0;               break;
2104
2105      case CPUINFO_INT_INPUT_STATE:               info->i = CLEAR_LINE;               break;
2106
2107      case CPUINFO_INT_PREVIOUSPC:               /* not implemented */               break;
2108
2109      case CPUINFO_INT_PC:   /* intentional fallthrough */
2110      case CPUINFO_INT_REGISTER + PPC_PC:            info->i = ppc.pc;                  break;
2111      case CPUINFO_INT_REGISTER + PPC_MSR:         info->i = ppc_get_msr();            break;
2112      case CPUINFO_INT_REGISTER + PPC_CR:            info->i = ppc_get_cr();               break;
2113      case CPUINFO_INT_REGISTER + PPC_LR:            info->i = LR;                     break;
2114      case CPUINFO_INT_REGISTER + PPC_CTR:         info->i = CTR;                     break;
2115      case CPUINFO_INT_REGISTER + PPC_XER:         info->i = XER;                     break;
2116      case CPUINFO_INT_REGISTER + PPC_SRR0:         info->i = SRR0;                     break;
2117      case CPUINFO_INT_REGISTER + PPC_SRR1:         info->i = SRR1;                     break;
2118
2119      case CPUINFO_INT_REGISTER + PPC_R0:            info->i = ppc.r[0];                  break;
2120      case CPUINFO_INT_REGISTER + PPC_R1:            info->i = ppc.r[1];                  break;
2121      case CPUINFO_INT_REGISTER + PPC_R2:            info->i = ppc.r[2];                  break;
2122      case CPUINFO_INT_REGISTER + PPC_R3:            info->i = ppc.r[3];                  break;
2123      case CPUINFO_INT_REGISTER + PPC_R4:            info->i = ppc.r[4];                  break;
2124      case CPUINFO_INT_REGISTER + PPC_R5:            info->i = ppc.r[5];                  break;
2125      case CPUINFO_INT_REGISTER + PPC_R6:            info->i = ppc.r[6];                  break;
2126      case CPUINFO_INT_REGISTER + PPC_R7:            info->i = ppc.r[7];                  break;
2127      case CPUINFO_INT_REGISTER + PPC_R8:            info->i = ppc.r[8];                  break;
2128      case CPUINFO_INT_REGISTER + PPC_R9:            info->i = ppc.r[9];                  break;
2129      case CPUINFO_INT_REGISTER + PPC_R10:         info->i = ppc.r[10];               break;
2130      case CPUINFO_INT_REGISTER + PPC_R11:         info->i = ppc.r[11];               break;
2131      case CPUINFO_INT_REGISTER + PPC_R12:         info->i = ppc.r[12];               break;
2132      case CPUINFO_INT_REGISTER + PPC_R13:         info->i = ppc.r[13];               break;
2133      case CPUINFO_INT_REGISTER + PPC_R14:         info->i = ppc.r[14];               break;
2134      case CPUINFO_INT_REGISTER + PPC_R15:         info->i = ppc.r[15];               break;
2135      case CPUINFO_INT_REGISTER + PPC_R16:         info->i = ppc.r[16];               break;
2136      case CPUINFO_INT_REGISTER + PPC_R17:         info->i = ppc.r[17];               break;
2137      case CPUINFO_INT_REGISTER + PPC_R18:         info->i = ppc.r[18];               break;
2138      case CPUINFO_INT_REGISTER + PPC_R19:         info->i = ppc.r[19];               break;
2139      case CPUINFO_INT_REGISTER + PPC_R20:         info->i = ppc.r[20];               break;
2140      case CPUINFO_INT_REGISTER + PPC_R21:         info->i = ppc.r[21];               break;
2141      case CPUINFO_INT_REGISTER + PPC_R22:         info->i = ppc.r[22];               break;
2142      case CPUINFO_INT_REGISTER + PPC_R23:         info->i = ppc.r[23];               break;
2143      case CPUINFO_INT_REGISTER + PPC_R24:         info->i = ppc.r[24];               break;
2144      case CPUINFO_INT_REGISTER + PPC_R25:         info->i = ppc.r[25];               break;
2145      case CPUINFO_INT_REGISTER + PPC_R26:         info->i = ppc.r[26];               break;
2146      case CPUINFO_INT_REGISTER + PPC_R27:         info->i = ppc.r[27];               break;
2147      case CPUINFO_INT_REGISTER + PPC_R28:         info->i = ppc.r[28];               break;
2148      case CPUINFO_INT_REGISTER + PPC_R29:         info->i = ppc.r[29];               break;
2149      case CPUINFO_INT_REGISTER + PPC_R30:         info->i = ppc.r[30];               break;
2150      case CPUINFO_INT_REGISTER + PPC_R31:         info->i = ppc.r[31];               break;
2151
2152      /* --- the following bits of info are returned as pointers to data or functions --- */
2153      case CPUINFO_PTR_GET_CONTEXT:               info->getcontext = ppc_get_context;      break;
2154      case CPUINFO_PTR_SET_CONTEXT:               info->setcontext = ppc_set_context;      break;
2155      case CPUINFO_PTR_BURN:                     info->burn = NULL;                  break;
2156#ifdef ENABLE_DEBUGGER
2157      case CPUINFO_PTR_DISASSEMBLE:               info->disassemble = ppc_dasm;         break;
2158#endif /* ENABLE_DEBUGGER */
2159      case CPUINFO_PTR_INSTRUCTION_COUNTER:         info->icount = &ppc_icount;            break;
2160
2161      /* --- the following bits of info are returned as NULL-terminated strings --- */
2162      case CPUINFO_STR_NAME:                     strcpy(info->s, "PPC403");            break;
2163      case CPUINFO_STR_CORE_FAMILY:               strcpy(info->s, "PowerPC");            break;
2164      case CPUINFO_STR_CORE_VERSION:               strcpy(info->s, "1.0");               break;
2165      case CPUINFO_STR_CORE_FILE:                  strcpy(info->s, __FILE__);            break;
2166      case CPUINFO_STR_CORE_CREDITS:               strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team");   break;
2167
2168      case CPUINFO_STR_FLAGS:                     strcpy(info->s, " ");               break;
2169
2170      case CPUINFO_STR_REGISTER + PPC_PC:            sprintf(info->s, "PC: %08X", ppc.pc);   break;
2171      case CPUINFO_STR_REGISTER + PPC_MSR:         sprintf(info->s, "MSR: %08X", ppc_get_msr()); break;
2172      case CPUINFO_STR_REGISTER + PPC_CR:            sprintf(info->s, "CR: %08X", ppc_get_cr()); break;
2173      case CPUINFO_STR_REGISTER + PPC_LR:            sprintf(info->s, "LR: %08X", LR);      break;
2174      case CPUINFO_STR_REGISTER + PPC_CTR:         sprintf(info->s, "CTR: %08X", CTR);      break;
2175      case CPUINFO_STR_REGISTER + PPC_XER:         sprintf(info->s, "XER: %08X", XER);      break;
2176      case CPUINFO_STR_REGISTER + PPC_SRR0:         sprintf(info->s, "SRR0: %08X", SRR0);   break;
2177      case CPUINFO_STR_REGISTER + PPC_SRR1:         sprintf(info->s, "SRR1: %08X", SRR1);   break;
2178
2179      case CPUINFO_STR_REGISTER + PPC_R0:            sprintf(info->s, "R0: %08X", ppc.r[0]); break;
2180      case CPUINFO_STR_REGISTER + PPC_R1:            sprintf(info->s, "R1: %08X", ppc.r[1]); break;
2181      case CPUINFO_STR_REGISTER + PPC_R2:            sprintf(info->s, "R2: %08X", ppc.r[2]); break;
2182      case CPUINFO_STR_REGISTER + PPC_R3:            sprintf(info->s, "R3: %08X", ppc.r[3]); break;
2183      case CPUINFO_STR_REGISTER + PPC_R4:            sprintf(info->s, "R4: %08X", ppc.r[4]); break;
2184      case CPUINFO_STR_REGISTER + PPC_R5:            sprintf(info->s, "R5: %08X", ppc.r[5]); break;
2185      case CPUINFO_STR_REGISTER + PPC_R6:            sprintf(info->s, "R6: %08X", ppc.r[6]); break;
2186      case CPUINFO_STR_REGISTER + PPC_R7:            sprintf(info->s, "R7: %08X", ppc.r[7]); break;
2187      case CPUINFO_STR_REGISTER + PPC_R8:            sprintf(info->s, "R8: %08X", ppc.r[8]); break;
2188      case CPUINFO_STR_REGISTER + PPC_R9:            sprintf(info->s, "R9: %08X", ppc.r[9]); break;
2189      case CPUINFO_STR_REGISTER + PPC_R10:         sprintf(info->s, "R10: %08X", ppc.r[10]); break;
2190      case CPUINFO_STR_REGISTER + PPC_R11:         sprintf(info->s, "R11: %08X", ppc.r[11]); break;
2191      case CPUINFO_STR_REGISTER + PPC_R12:         sprintf(info->s, "R12: %08X", ppc.r[12]); break;
2192      case CPUINFO_STR_REGISTER + PPC_R13:         sprintf(info->s, "R13: %08X", ppc.r[13]); break;
2193      case CPUINFO_STR_REGISTER + PPC_R14:         sprintf(info->s, "R14: %08X", ppc.r[14]); break;
2194      case CPUINFO_STR_REGISTER + PPC_R15:         sprintf(info->s, "R15: %08X", ppc.r[15]); break;
2195      case CPUINFO_STR_REGISTER + PPC_R16:         sprintf(info->s, "R16: %08X", ppc.r[16]); break;
2196      case CPUINFO_STR_REGISTER + PPC_R17:         sprintf(info->s, "R17: %08X", ppc.r[17]); break;
2197      case CPUINFO_STR_REGISTER + PPC_R18:         sprintf(info->s, "R18: %08X", ppc.r[18]); break;
2198      case CPUINFO_STR_REGISTER + PPC_R19:         sprintf(info->s, "R19: %08X", ppc.r[19]); break;
2199      case CPUINFO_STR_REGISTER + PPC_R20:         sprintf(info->s, "R20: %08X", ppc.r[20]); break;
2200      case CPUINFO_STR_REGISTER + PPC_R21:         sprintf(info->s, "R21: %08X", ppc.r[21]); break;
2201      case CPUINFO_STR_REGISTER + PPC_R22:         sprintf(info->s, "R22: %08X", ppc.r[22]); break;
2202      case CPUINFO_STR_REGISTER + PPC_R23:         sprintf(info->s, "R23: %08X", ppc.r[23]); break;
2203      case CPUINFO_STR_REGISTER + PPC_R24:         sprintf(info->s, "R24: %08X", ppc.r[24]); break;
2204      case CPUINFO_STR_REGISTER + PPC_R25:         sprintf(info->s, "R25: %08X", ppc.r[25]); break;
2205      case CPUINFO_STR_REGISTER + PPC_R26:         sprintf(info->s, "R26: %08X", ppc.r[26]); break;
2206      case CPUINFO_STR_REGISTER + PPC_R27:         sprintf(info->s, "R27: %08X", ppc.r[27]); break;
2207      case CPUINFO_STR_REGISTER + PPC_R28:         sprintf(info->s, "R28: %08X", ppc.r[28]); break;
2208      case CPUINFO_STR_REGISTER + PPC_R29:         sprintf(info->s, "R29: %08X", ppc.r[29]); break;
2209      case CPUINFO_STR_REGISTER + PPC_R30:         sprintf(info->s, "R30: %08X", ppc.r[30]); break;
2210      case CPUINFO_STR_REGISTER + PPC_R31:         sprintf(info->s, "R31: %08X", ppc.r[31]); break;
2211   }
2212}
2213
2214
2215
2216/* PowerPC 403 */
2217#if (HAS_PPC403)
2218static void ppc403_set_info(UINT32 state, cpuinfo *info)
2219{
2220   if (state >= CPUINFO_INT_INPUT_STATE && state <= CPUINFO_INT_INPUT_STATE + 5)
2221   {
2222      ppcdrc403_set_irq_line(state-CPUINFO_INT_INPUT_STATE, info->i);
2223      return;
2224   }
2225   switch(state)
2226   {
2227      default:   ppc_set_info(state, info);      break;
2228   }
2229}
2230
2231void ppc403_get_info(UINT32 state, cpuinfo *info)
2232{
2233   switch(state)
2234   {
2235      /* --- the following bits of info are returned as 64-bit signed integers --- */
2236      case CPUINFO_INT_INPUT_LINES:               info->i = 7;                     break;
2237      case CPUINFO_INT_ENDIANNESS:               info->i = CPU_IS_BE;               break;
2238
2239      /* --- the following bits of info are returned as pointers to data or functions --- */
2240      case CPUINFO_PTR_SET_INFO:                  info->setinfo = ppc403_set_info;      break;
2241      case CPUINFO_PTR_INIT:                     info->init = ppcdrc403_init;         break;
2242      case CPUINFO_PTR_RESET:                     info->reset = ppcdrc403_reset;         break;
2243      case CPUINFO_PTR_EXIT:                     info->exit = ppcdrc403_exit;         break;
2244      case CPUINFO_PTR_EXECUTE:                  info->execute = ppcdrc403_execute;      break;
2245
2246      /* --- the following bits of info are returned as NULL-terminated strings --- */
2247      case CPUINFO_STR_NAME:                     strcpy(info->s, "PPC403");            break;
2248
2249      default:                              ppc_get_info(state, info);            break;
2250   }
2251}
2252#endif
2253
2254/* PowerPC 603 */
2255#if (HAS_PPC603)
2256static void ppc603_set_info(UINT32 state, cpuinfo *info)
2257{
2258   if (state >= CPUINFO_INT_INPUT_STATE && state <= CPUINFO_INT_INPUT_STATE + 5)
2259   {
2260      ppcdrc603_set_irq_line(state-CPUINFO_INT_INPUT_STATE, info->i);
2261      return;
2262   }
2263   switch(state)
2264   {
2265      case CPUINFO_INT_REGISTER + PPC_DEC:         write_decrementer(info->i);            break;
2266      default:                              ppc_set_info(state, info);            break;
2267   }
2268}
2269
2270void ppc603_get_info(UINT32 state, cpuinfo *info)
2271{
2272   switch(state)
2273   {
2274      /* --- the following bits of info are returned as 64-bit signed integers --- */
2275      case CPUINFO_INT_INPUT_LINES:               info->i = 5;                     break;
2276      case CPUINFO_INT_ENDIANNESS:               info->i = CPU_IS_BE;               break;
2277      case CPUINFO_INT_REGISTER + PPC_DEC:         info->i = read_decrementer();         break;
2278
2279      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_PROGRAM:   info->i = 64;               break;
2280      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_PROGRAM: info->i = 32;               break;
2281      case CPUINFO_INT_LOGADDR_WIDTH + ADDRESS_SPACE_PROGRAM: info->i = 32;               break;
2282      case CPUINFO_INT_PAGE_SHIFT + ADDRESS_SPACE_PROGRAM:    info->i = 17;               break;
2283
2284      /* --- the following bits of info are returned as pointers to data or functions --- */
2285      case CPUINFO_PTR_SET_INFO:                  info->setinfo = ppc603_set_info;      break;
2286      case CPUINFO_PTR_INIT:                     info->init = ppcdrc603_init;         break;
2287      case CPUINFO_PTR_RESET:                     info->reset = ppcdrc603_reset;         break;
2288      case CPUINFO_PTR_EXIT:                     info->exit = ppcdrc603_exit;         break;
2289      case CPUINFO_PTR_EXECUTE:                  info->execute = ppcdrc603_execute;      break;
2290      case CPUINFO_PTR_READ:                     info->read = ppc_read;               break;
2291      case CPUINFO_PTR_WRITE:                     info->write = ppc_write;            break;
2292      case CPUINFO_PTR_READOP:                  info->readop = ppc_readop;            break;
2293      case CPUINFO_PTR_TRANSLATE:                  info->translate = ppc_translate_address_cb;   break;
2294
2295      /* --- the following bits of info are returned as NULL-terminated strings --- */
2296      case CPUINFO_STR_NAME:                     strcpy(info->s, "PPC603");            break;
2297      case CPUINFO_STR_REGISTER + PPC_DEC:         sprintf(info->s, "DEC: %08X", read_decrementer()); break;
2298
2299      default:                              ppc_get_info(state, info);            break;
2300   }
2301}
2302#endif
2303
2304/* PowerPC 602 */
2305#if (HAS_PPC602)
2306static void ppc602_set_info(UINT32 state, cpuinfo *info)
2307{
2308   if (state >= CPUINFO_INT_INPUT_STATE && state <= CPUINFO_INT_INPUT_STATE + 5)
2309   {
2310      ppcdrc602_set_irq_line(state-CPUINFO_INT_INPUT_STATE, info->i);
2311      return;
2312   }
2313   switch(state)
2314   {
2315      default:   ppc_set_info(state, info);      break;
2316   }
2317}
2318
2319void ppc602_get_info(UINT32 state, cpuinfo *info)
2320{
2321   switch(state)
2322   {
2323      /* --- the following bits of info are returned as 64-bit signed integers --- */
2324      case CPUINFO_INT_INPUT_LINES:               info->i = 5;                     break;
2325      case CPUINFO_INT_ENDIANNESS:               info->i = CPU_IS_BE;               break;
2326
2327      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_PROGRAM:   info->i = 64;               break;
2328      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_PROGRAM: info->i = 32;               break;
2329      case CPUINFO_INT_LOGADDR_WIDTH + ADDRESS_SPACE_PROGRAM: info->i = 32;               break;
2330      case CPUINFO_INT_PAGE_SHIFT + ADDRESS_SPACE_PROGRAM:    info->i = 17;               break;
2331
2332      /* --- the following bits of info are returned as pointers to data or functions --- */
2333      case CPUINFO_PTR_SET_INFO:                  info->setinfo = ppc602_set_info;      break;
2334      case CPUINFO_PTR_INIT:                     info->init = ppcdrc602_init;         break;
2335      case CPUINFO_PTR_RESET:                     info->reset = ppcdrc602_reset;         break;
2336      case CPUINFO_PTR_EXIT:                     info->exit = ppcdrc602_exit;         break;
2337      case CPUINFO_PTR_EXECUTE:                  info->execute = ppcdrc602_execute;      break;
2338      case CPUINFO_PTR_READ:                     info->read = ppc_read;               break;
2339      case CPUINFO_PTR_WRITE:                     info->write = ppc_write;            break;
2340      case CPUINFO_PTR_READOP:                  info->readop = ppc_readop;            break;
2341      case CPUINFO_PTR_TRANSLATE:                  info->translate = ppc_translate_address_cb;   break;
2342
2343      /* --- the following bits of info are returned as NULL-terminated strings --- */
2344      case CPUINFO_STR_NAME:                     strcpy(info->s, "PPC602");            break;
2345
2346      default:                              ppc_get_info(state, info);            break;
2347   }
2348}
2349#endif
2350
2351/* Motorola MPC8240 */
2352
2353#if (HAS_MPC8240)
2354static void mpc8240_set_info(UINT32 state, cpuinfo *info)
2355{
2356   if (state >= CPUINFO_INT_INPUT_STATE && state <= CPUINFO_INT_INPUT_STATE + 5)
2357   {
2358      ppcdrc603_set_irq_line(state-CPUINFO_INT_INPUT_STATE, info->i);
2359      return;
2360   }
2361   switch(state)
2362   {
2363      default:                              ppc_set_info(state, info);            break;
2364   }
2365}
2366
2367void mpc8240_get_info(UINT32 state, cpuinfo *info)
2368{
2369   switch(state)
2370   {
2371      /* --- the following bits of info are returned as 64-bit signed integers --- */
2372      case CPUINFO_INT_INPUT_LINES:               info->i = 5;                     break;
2373      case CPUINFO_INT_ENDIANNESS:               info->i = CPU_IS_BE;               break;
2374
2375      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_PROGRAM:   info->i = 64;               break;
2376      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_PROGRAM: info->i = 32;               break;
2377
2378      /* --- the following bits of info are returned as pointers to data or functions --- */
2379      case CPUINFO_PTR_SET_INFO:                  info->setinfo = mpc8240_set_info;      break;
2380      case CPUINFO_PTR_INIT:                     info->init = mpc8240drc_init;         break;
2381      case CPUINFO_PTR_RESET:                     info->reset = ppcdrc603_reset;         break;
2382      case CPUINFO_PTR_EXIT:                     info->exit = mpc8240drc_exit;         break;
2383      case CPUINFO_PTR_EXECUTE:                  info->execute = ppcdrc603_execute;      break;
2384      case CPUINFO_PTR_READ:                     info->read = ppc_read;               break;
2385      case CPUINFO_PTR_WRITE:                     info->write = ppc_write;            break;
2386      case CPUINFO_PTR_READOP:                  info->readop = ppc_readop;            break;
2387
2388      /* --- the following bits of info are returned as NULL-terminated strings --- */
2389      case CPUINFO_STR_NAME:                     strcpy(info->s, "MPC8240");            break;
2390
2391      default:                              ppc_get_info(state, info);            break;
2392   }
2393}
2394#endif
2395
2396
2397/* PPC601 */
2398
2399#if (HAS_PPC601)
2400static void ppc601_set_info(UINT32 state, cpuinfo *info)
2401{
2402   if (state >= CPUINFO_INT_INPUT_STATE && state <= CPUINFO_INT_INPUT_STATE + 5)
2403   {
2404      ppcdrc603_set_irq_line(state-CPUINFO_INT_INPUT_STATE, info->i);
2405      return;
2406   }
2407   switch(state)
2408   {
2409      default:                              ppc_set_info(state, info);            break;
2410   }
2411}
2412
2413void ppc601_get_info(UINT32 state, cpuinfo *info)
2414{
2415   switch(state)
2416   {
2417      /* --- the following bits of info are returned as 64-bit signed integers --- */
2418      case CPUINFO_INT_INPUT_LINES:               info->i = 5;                     break;
2419      case CPUINFO_INT_ENDIANNESS:               info->i = CPU_IS_BE;               break;
2420
2421      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_PROGRAM:   info->i = 64;               break;
2422      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_PROGRAM: info->i = 32;               break;
2423
2424      /* --- the following bits of info are returned as pointers to data or functions --- */
2425      case CPUINFO_PTR_SET_INFO:                  info->setinfo = ppc601_set_info;      break;
2426      case CPUINFO_PTR_INIT:                     info->init = ppc601drc_init;         break;
2427      case CPUINFO_PTR_RESET:                     info->reset = ppcdrc603_reset;         break;
2428      case CPUINFO_PTR_EXIT:                     info->exit = ppc601drc_exit;         break;
2429      case CPUINFO_PTR_EXECUTE:                  info->execute = ppcdrc603_execute;      break;
2430      case CPUINFO_PTR_READ:                     info->read = ppc_read;               break;
2431      case CPUINFO_PTR_WRITE:                     info->write = ppc_write;            break;
2432      case CPUINFO_PTR_READOP:                  info->readop = ppc_readop;            break;
2433
2434      /* --- the following bits of info are returned as NULL-terminated strings --- */
2435      case CPUINFO_STR_NAME:                     strcpy(info->s, "PPC601");            break;
2436
2437      default:                              ppc_get_info(state, info);            break;
2438   }
2439}
2440#endif
2441
2442/* PPC604 */
2443
2444#if (HAS_PPC604)
2445static void ppc604_set_info(UINT32 state, cpuinfo *info)
2446{
2447   if (state >= CPUINFO_INT_INPUT_STATE && state <= CPUINFO_INT_INPUT_STATE + 5)
2448   {
2449      ppcdrc603_set_irq_line(state-CPUINFO_INT_INPUT_STATE, info->i);
2450      return;
2451   }
2452   switch(state)
2453   {
2454      default:                              ppc_set_info(state, info);            break;
2455   }
2456}
2457
2458void ppc604_get_info(UINT32 state, cpuinfo *info)
2459{
2460   switch(state)
2461   {
2462      /* --- the following bits of info are returned as 64-bit signed integers --- */
2463      case CPUINFO_INT_INPUT_LINES:               info->i = 5;                     break;
2464      case CPUINFO_INT_ENDIANNESS:               info->i = CPU_IS_BE;               break;
2465
2466      case CPUINFO_INT_DATABUS_WIDTH + ADDRESS_SPACE_PROGRAM:   info->i = 64;               break;
2467      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_PROGRAM: info->i = 32;               break;
2468
2469      /* --- the following bits of info are returned as pointers to data or functions --- */
2470      case CPUINFO_PTR_SET_INFO:                  info->setinfo = ppc604_set_info;      break;
2471      case CPUINFO_PTR_INIT:                     info->init = ppc604drc_init;         break;
2472      case CPUINFO_PTR_RESET:                     info->reset = ppcdrc603_reset;         break;
2473      case CPUINFO_PTR_EXIT:                     info->exit = ppc604drc_exit;         break;
2474      case CPUINFO_PTR_EXECUTE:                  info->execute = ppcdrc603_execute;      break;
2475      case CPUINFO_PTR_READ:                     info->read = ppc_read;               break;
2476      case CPUINFO_PTR_WRITE:                     info->write = ppc_write;            break;
2477      case CPUINFO_PTR_READOP:                  info->readop = ppc_readop;            break;
2478
2479      /* --- the following bits of info are returned as NULL-terminated strings --- */
2480      case CPUINFO_STR_NAME:                     strcpy(info->s, "PPC604");            break;
2481
2482      default:                              ppc_get_info(state, info);            break;
2483   }
2484}
2485#endif
src/emu/cpu/drcumlsh.h
r2724r2725
8686#define FREG(x)            DRCUML_PTYPE_FLOAT_REGISTER, (DRCUML_REG_F0 + (x))
8787#define MVAR(x)            DRCUML_PTYPE_MAPVAR, (DRCUML_MAPVAR_M0 + (x))
8888#define MEM(x)            DRCUML_PTYPE_MEMORY, (FPTR)(x)
89#define PARAM(t,v)         (t), (v)
8990
9091
9192
r2724r2725
128129
129130
130131/* ----- Internal Register Operations ----- */
131#define UML_SETMODE(block, mode)                     do { drcuml_block_append_1(block, DRCUML_OP_SETMODE, 4, IF_ALWAYS,  mode); } while (0)
132#define UML_GETMODE(block, dst)                        do { drcuml_block_append_1(block, DRCUML_OP_GETMODE, 4, IF_ALWAYS,  dst); } while (0)
133132#define UML_SETFMOD(block, mode)                     do { drcuml_block_append_1(block, DRCUML_OP_SETFMOD, 4, IF_ALWAYS,  mode); } while (0)
134133#define UML_GETFMOD(block, dst)                        do { drcuml_block_append_1(block, DRCUML_OP_GETFMOD, 4, IF_ALWAYS,  dst); } while (0)
135#define UML_SUBICNT(block, delta, param)               do { drcuml_block_append_2(block, DRCUML_OP_SUBICNT, 4, IF_ALWAYS,  delta, param); } while (0)
136134#define UML_GETEXP(block, dst)                        do { drcuml_block_append_1(block, DRCUML_OP_GETEXP,  4, IF_ALWAYS,  dst); } while (0)
135#define UML_SAVE(block, dst)                        do { drcuml_block_append_1(block, DRCUML_OP_SAVE,    4, IF_ALWAYS,  MEM(dst)); } while (0)
136#define UML_RESTORE(block, src)                        do { drcuml_block_append_1(block, DRCUML_OP_RESTORE, 4, IF_ALWAYS,  MEM(src)); } while (0)
137137
138138
139139/* ----- 32-Bit Integer Operations ----- */
r2724r2725
170170#define UML_SEXT1(block, dst, src1)                     do { drcuml_block_append_2(block, DRCUML_OP_SEXT1,   4, IF_ALWAYS,  dst, src1); } while (0)
171171#define UML_SEXT2(block, dst, src1)                     do { drcuml_block_append_2(block, DRCUML_OP_SEXT2,   4, IF_ALWAYS,  dst, src1); } while (0)
172172
173#define UML_XTRACT(block, dst, src, shift, mask)         do { drcuml_block_append_4(block, DRCUML_OP_XTRACT,  4, IF_ALWAYS,  dst, src, shift, mask); } while (0)
174#define UML_INSERT(block, dst, src, shift, mask)         do { drcuml_block_append_4(block, DRCUML_OP_INSERT,  4, IF_ALWAYS,  dst, src, shift, mask); } while (0)
175
173176#define UML_NEG(block, dst, src1)                     do { drcuml_block_append_2(block, DRCUML_OP_NEG,     4, FLAGS_NONE, dst, src1); } while (0)
174177#define UML_NEGf(block, dst, src1, flags)               do { drcuml_block_append_2(block, DRCUML_OP_NEG,     4, flags,      dst, src1); } while (0)
175178
r2724r2725
274277#define UML_DSEXT2(block, dst, src1)                  do { drcuml_block_append_2(block, DRCUML_OP_SEXT2,   8, IF_ALWAYS,  dst, src1); } while (0)
275278#define UML_DSEXT4(block, dst, src1)                  do { drcuml_block_append_2(block, DRCUML_OP_SEXT4,   8, IF_ALWAYS,  dst, src1); } while (0)
276279
280#define UML_DXTRACT(block, dst, src, shift, mask)         do { drcuml_block_append_4(block, DRCUML_OP_XTRACT,  8, IF_ALWAYS,  dst, src, shift, mask); } while (0)
281#define UML_DINSERT(block, dst, src, shift, mask)         do { drcuml_block_append_4(block, DRCUML_OP_INSERT,  8, IF_ALWAYS,  dst, src, shift, mask); } while (0)
282
277283#define UML_DNEG(block, dst, src1)                     do { drcuml_block_append_2(block, DRCUML_OP_NEG,     8, FLAGS_NONE, dst, src1); } while (0)
278284#define UML_DNEGf(block, dst, src1, flags)               do { drcuml_block_append_2(block, DRCUML_OP_NEG,     8, flags,      dst, src1); } while (0)
279285
src/emu/cpu/mips/mips3com.h
r2724r2725
4444};
4545typedef enum _mips3_flavor mips3_flavor;
4646
47/* TLB bits */
48#define TLB_GLOBAL            0x01
49#define TLB_VALID            0x02
50#define TLB_DIRTY            0x04
51#define TLB_PRESENT            0x08
52
4753/* COP0 registers */
48#define COP0_Index         0
49#define COP0_Random         1
50#define COP0_EntryLo      2
51#define COP0_EntryLo0      2
52#define COP0_EntryLo1      3
53#define COP0_Context      4
54#define COP0_PageMask      5
55#define COP0_Wired         6
56#define COP0_BadVAddr      8
57#define COP0_Count         9
58#define COP0_EntryHi      10
59#define COP0_Compare      11
60#define COP0_Status         12
61#define COP0_Cause         13
62#define COP0_EPC         14
63#define COP0_PRId         15
64#define COP0_Config         16
65#define COP0_XContext      20
54#define COP0_Index            0
55#define COP0_Random            1
56#define COP0_EntryLo         2
57#define COP0_EntryLo0         2
58#define COP0_EntryLo1         3
59#define COP0_Context         4
60#define COP0_PageMask         5
61#define COP0_Wired            6
62#define COP0_BadVAddr         8
63#define COP0_Count            9
64#define COP0_EntryHi         10
65#define COP0_Compare         11
66#define COP0_Status            12
67#define COP0_Cause            13
68#define COP0_EPC            14
69#define COP0_PRId            15
70#define COP0_Config            16
71#define COP0_LLAddr            17
72#define COP0_XContext         20
73#define COP0_ECC            26
74#define COP0_CacheErr         27
75#define COP0_TagLo            28
76#define COP0_TagHi            29
77#define COP0_ErrorPC         30
6678
6779/* Status register bits */
68#define SR_IE            0x00000001
69#define SR_EXL            0x00000002
70#define SR_ERL            0x00000004
71#define SR_KSU_MASK         0x00000018
72#define SR_KSU_KERNEL      0x00000000
73#define SR_KSU_SUPERVISOR   0x00000008
74#define SR_KSU_USER         0x00000010
75#define SR_IMSW0         0x00000100
76#define SR_IMSW1         0x00000200
77#define SR_IMEX0         0x00000400
78#define SR_IMEX1         0x00000800
79#define SR_IMEX2         0x00001000
80#define SR_IMEX3         0x00002000
81#define SR_IMEX4         0x00004000
82#define SR_IMEX5         0x00008000
83#define SR_DE            0x00010000
84#define SR_CE            0x00020000
85#define SR_CH            0x00040000
86#define SR_SR            0x00100000
87#define SR_TS            0x00200000
88#define SR_BEV            0x00400000
89#define SR_RE            0x02000000
90#define SR_FR            0x04000000
91#define SR_RP            0x08000000
92#define SR_COP0            0x10000000
93#define SR_COP1            0x20000000
94#define SR_COP2            0x40000000
95#define SR_COP3            0x80000000
80#define SR_IE               0x00000001
81#define SR_EXL               0x00000002
82#define SR_ERL               0x00000004
83#define SR_KSU_MASK            0x00000018
84#define SR_KSU_KERNEL         0x00000000
85#define SR_KSU_SUPERVISOR      0x00000008
86#define SR_KSU_USER            0x00000010
87#define SR_IMSW0            0x00000100
88#define SR_IMSW1            0x00000200
89#define SR_IMEX0            0x00000400
90#define SR_IMEX1            0x00000800
91#define SR_IMEX2            0x00001000
92#define SR_IMEX3            0x00002000
93#define SR_IMEX4            0x00004000
94#define SR_IMEX5            0x00008000
95#define SR_DE               0x00010000
96#define SR_CE               0x00020000
97#define SR_CH               0x00040000
98#define SR_SR               0x00100000
99#define SR_TS               0x00200000
100#define SR_BEV               0x00400000
101#define SR_RE               0x02000000
102#define SR_FR               0x04000000
103#define SR_RP               0x08000000
104#define SR_COP0               0x10000000
105#define SR_COP1               0x20000000
106#define SR_COP2               0x40000000
107#define SR_COP3               0x80000000
96108
97109/* exception types */
98#define EXCEPTION_INTERRUPT   0
99#define EXCEPTION_TLBMOD   1
100#define EXCEPTION_TLBLOAD   2
101#define EXCEPTION_TLBSTORE   3
102#define EXCEPTION_ADDRLOAD   4
103#define EXCEPTION_ADDRSTORE   5
104#define EXCEPTION_BUSINST   6
105#define EXCEPTION_BUSDATA   7
106#define EXCEPTION_SYSCALL   8
107#define EXCEPTION_BREAK      9
108#define EXCEPTION_INVALIDOP   10
109#define EXCEPTION_BADCOP   11
110#define EXCEPTION_OVERFLOW   12
111#define EXCEPTION_TRAP      13
112#define EXCEPTION_COUNT      16
110#define EXCEPTION_INTERRUPT      0
111#define EXCEPTION_TLBMOD      1
112#define EXCEPTION_TLBLOAD      2
113#define EXCEPTION_TLBSTORE      3
114#define EXCEPTION_ADDRLOAD      4
115#define EXCEPTION_ADDRSTORE      5
116#define EXCEPTION_BUSINST      6
117#define EXCEPTION_BUSDATA      7
118#define EXCEPTION_SYSCALL      8
119#define EXCEPTION_BREAK         9
120#define EXCEPTION_INVALIDOP      10
121#define EXCEPTION_BADCOP      11
122#define EXCEPTION_OVERFLOW      12
123#define EXCEPTION_TRAP         13
124#define EXCEPTION_TLBLOAD_FILL   16
125#define EXCEPTION_TLBSTORE_FILL   17
126#define EXCEPTION_COUNT         18
113127
114128
115129
src/emu/cpu/mips/r3000.c
r2724r2725
77***************************************************************************/
88
99#include "debugger.h"
10#include "deprecat.h"
1110#include "r3000.h"
1211
1312
src/emu/cpu/mips/mips3fe.c
r2724r2725
516516               return TRUE;
517517
518518            case 0x18:   /* ERET */
519               desc->flags |= OPFLAG_IS_UNCONDITIONAL_BRANCH | OPFLAG_END_SEQUENCE;
519               desc->flags |= OPFLAG_CAN_CHANGE_MODES | OPFLAG_IS_UNCONDITIONAL_BRANCH | OPFLAG_END_SEQUENCE;
520520               return TRUE;
521521         }
522522         return FALSE;
src/emu/cpu/mips/mips3fe.h
r2724r2725
3030
3131
3232/***************************************************************************
33    CONSTANTS
34***************************************************************************/
35
36/* this defines a branch targetpc that is dynamic at runtime */
37#define BRANCH_TARGET_DYNAMIC         (~0)
38
39
40/* opcode branch flags */
41#define OPFLAG_IS_UNCONDITIONAL_BRANCH   0x00000001      /* instruction is unconditional branch */
42
43
44/***************************************************************************
4533    FUNCTION PROTOTYPES
4634***************************************************************************/
4735
src/emu/cpu/mips/mips3drc.c
r2724r2725
1414
1515    * Add DRC option to flush PC before calling memory handlers
1616
17    * Map MIPS registers to i5-i7 (or more)
18        - should rely on backend hints to know how many to assign
19        - add instrumentation to figure out which ones are most used
20        - on entry, load registers; on exit, flush them
21        - also flush before calling debugger
22
2317    * Constant tracking? (hasn't bought us much in the past)
2418
2519    * Customized mapped/unmapped memory handlers
r2724r2725
5347#define LOG_UML                     (0)
5448#define LOG_NATIVE                  (0)
5549
50#define DISABLE_FAST_REGISTERS         (0)
5651#define SINGLE_INSTRUCTION_MODE         (0)
52
5753#define PRINTF_EXCEPTIONS            (0)
54#define PRINTF_MMU                  (0)
5855
5956#define PROBE_ADDRESS               ~0
6057
r2724r2725
6865#define MAPVAR_PC                  MVAR(0)
6966#define MAPVAR_CYCLES               MVAR(1)
7067
68/* modes */
69#define MODE_KERNEL                  0
70#define MODE_SUPER                  1
71#define MODE_USER                  2
72
7173/* size of the execution code cache */
7274#define CACHE_SIZE                  (32 * 1024 * 1024)
7375
r2724r2725
8082/* exit codes */
8183#define EXECUTE_OUT_OF_CYCLES         0
8284#define EXECUTE_MISSING_CODE         1
85#define EXECUTE_UNMAPPED_CODE         2
86#define EXECUTE_RESET_CACHE            3
8387
8488
8589
r2724r2725
9397#define LOPTR(x)            ((UINT32 *)(x) + 1)
9498#endif
9599
96#define R32(reg)            ((reg == 0) ? DRCUML_PTYPE_IMMEDIATE : DRCUML_PTYPE_MEMORY), ((reg) == 0) ? 0 : (FPTR)LOPTR(&mips3.core->r[reg])
100#define R32(reg)            mips3.regmaplo[reg].type, mips3.regmaplo[reg].value
97101#define LO32               R32(REG_LO)
98102#define HI32               R32(REG_HI)
99103#define CPR032(reg)            MEM(LOPTR(&mips3.core->cpr[0][reg]))
100104#define CCR032(reg)            MEM(LOPTR(&mips3.core->ccr[0][reg]))
101#define FPR32(reg)            MEM((mips3.cstate->mode == 0) ? &((float *)&mips3.core->cpr[1][0])[reg] : (float *)&mips3.core->cpr[1][reg])
105#define FPR32(reg)            MEM(((mips3.cstate->mode & 1) == 0) ? &((float *)&mips3.core->cpr[1][0])[reg] : (float *)&mips3.core->cpr[1][reg])
102106#define CCR132(reg)            MEM(LOPTR(&mips3.core->ccr[1][reg]))
103107#define CPR232(reg)            MEM(LOPTR(&mips3.core->cpr[2][reg]))
104108#define CCR232(reg)            MEM(LOPTR(&mips3.core->ccr[2][reg]))
105109
106#define R64(reg)            ((reg == 0) ? DRCUML_PTYPE_IMMEDIATE : DRCUML_PTYPE_MEMORY), ((reg) == 0) ? 0 : (FPTR)&mips3.core->r[reg]
110#define R64(reg)            mips3.regmap[reg].type, mips3.regmap[reg].value
107111#define LO64               R64(REG_LO)
108112#define HI64               R64(REG_HI)
109113#define CPR064(reg)            MEM(&mips3.core->cpr[0][reg])
110114#define CCR064(reg)            MEM(&mips3.core->ccr[0][reg])
111#define FPR64(reg)            MEM((mips3.cstate->mode == 0) ? (double *)&mips3.core->cpr[1][(reg)/2] : (double *)&mips3.core->cpr[1][reg])
115#define FPR64(reg)            MEM(((mips3.cstate->mode & 1) == 0) ? (double *)&mips3.core->cpr[1][(reg)/2] : (double *)&mips3.core->cpr[1][reg])
112116#define CCR164(reg)            MEM(&mips3.core->ccr[1][reg])
113117#define CPR264(reg)            MEM(&mips3.core->cpr[2][reg])
114118#define CCR264(reg)            MEM(&mips3.core->ccr[2][reg])
r2724r2725
160164   /* parameters for subroutines */
161165   UINT64            numcycles;               /* return value from gettotalcycles */
162166   UINT32            mode;                  /* current global mode */
167   UINT32            arg0;                  /* print_debug argument 1 */
168   UINT32            arg1;                  /* print_debug argument 2 */
163169
164170   /* tables */
165171   UINT8            fpmode[4];               /* FPU mode table */
r2724r2725
190196   /* internal stuff */
191197   UINT8            cache_dirty;            /* true if we need to flush the cache */
192198
199   /* register mappings */
200   drcuml_parameter   regmap[34];               /* parameter to register mappings for all 32 integer registers */
201   drcuml_parameter   regmaplo[34];            /* parameter to register mappings for all 32 integer registers */
202
193203   /* subroutines */
194204   drcuml_codehandle *   entry;                  /* entry point */
195205   drcuml_codehandle *   nocode;                  /* nocode exception handler */
196206   drcuml_codehandle *   out_of_cycles;            /* out of cycles exception handler */
197   drcuml_codehandle *   tlb_mismatch;            /* tlb mismatch at current PC */
198   drcuml_codehandle *   read8;                  /* read byte */
199   drcuml_codehandle *   write8;                  /* write byte */
200   drcuml_codehandle *   read16;                  /* read half */
201   drcuml_codehandle *   write16;               /* write half */
202   drcuml_codehandle *   read32;                  /* read word */
203   drcuml_codehandle *   read32mask;               /* read word masked */
204   drcuml_codehandle *   write32;               /* write word */
205   drcuml_codehandle *   write32mask;            /* write word masked */
206   drcuml_codehandle *   read64;                  /* read double */
207   drcuml_codehandle *   read64mask;               /* read double masked */
208   drcuml_codehandle *   write64;               /* write double */
209   drcuml_codehandle *   write64mask;            /* write double masked */
207   drcuml_codehandle *   tlb_mismatch;            /* tlb mismatch handler */
208   drcuml_codehandle *   read8[3];               /* read byte */
209   drcuml_codehandle *   write8[3];               /* write byte */
210   drcuml_codehandle *   read16[3];               /* read half */
211   drcuml_codehandle *   write16[3];               /* write half */
212   drcuml_codehandle *   read32[3];               /* read word */
213   drcuml_codehandle *   read32mask[3];            /* read word masked */
214   drcuml_codehandle *   write32[3];               /* write word */
215   drcuml_codehandle *   write32mask[3];            /* write word masked */
216   drcuml_codehandle *   read64[3];               /* read double */
217   drcuml_codehandle *   read64mask[3];            /* read double masked */
218   drcuml_codehandle *   write64[3];               /* write double */
219   drcuml_codehandle *   write64mask[3];            /* write double masked */
210220   drcuml_codehandle *   exception[EXCEPTION_COUNT];   /* array of exception handlers */
211221   drcuml_codehandle *   exception_norecover[EXCEPTION_COUNT];   /* array of no-recover exception handlers */
212222
r2724r2725
235245static void static_generate_entry_point(drcuml_state *drcuml);
236246static void static_generate_nocode_handler(drcuml_state *drcuml);
237247static void static_generate_out_of_cycles(drcuml_state *drcuml);
248static void static_generate_tlb_mismatch(drcuml_state *drcuml);
238249static void static_generate_exception(drcuml_state *drcuml, UINT8 exception, int recover, const char *name);
239static void static_generate_memory_accessor(drcuml_state *drcuml, int size, int iswrite, int ismasked, const char *name, drcuml_codehandle **handleptr);
250static void static_generate_memory_accessor(drcuml_state *drcuml, int mode, int size, int iswrite, int ismasked, const char *name, drcuml_codehandle **handleptr);
240251
241static void generate_update_cycles(drcuml_block *block, compiler_state *compiler, UINT32 nextpc, UINT32 *mempc, int allow_exception);
252static void generate_update_mode(drcuml_block *block);
253static void generate_update_cycles(drcuml_block *block, compiler_state *compiler, drcuml_ptype ptype, UINT64 pvalue, int allow_exception);
242254static void generate_checksum_block(drcuml_block *block, compiler_state *compiler, const opcode_desc *seqhead, const opcode_desc *seqlast);
243255static void generate_sequence_instruction(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc);
244256static void generate_delay_slot_and_branch(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc, UINT8 linkreg);
r2724r2725
640652}
641653
642654
655/*-------------------------------------------------
656    load_fast_iregs - load any fast integer
657    registers
658-------------------------------------------------*/
643659
660INLINE void load_fast_iregs(drcuml_block *block)
661{
662   int regnum;
663
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]));
667}
668
669
670/*-------------------------------------------------
671    save_fast_iregs - save any fast integer
672    registers
673-------------------------------------------------*/
674
675INLINE void save_fast_iregs(drcuml_block *block)
676{
677   int regnum;
678
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));
682}
683
684
685
644686/***************************************************************************
645687    CORE CALLBACKS
646688***************************************************************************/
r2724r2725
658700      COMPILE_MAX_SEQUENCE,      /* maximum instructions to include in a sequence */
659701      mips3fe_describe         /* callback to describe a single instruction */
660702   };
703   drcbe_info beinfo;
661704   UINT32 flags = 0;
662705   size_t extrasize;
663706   void *extramem;
707   int regnum;
664708
665709   /* determine how much memory beyond the core size we need */
666710    extrasize = mips3com_init(NULL, flavor, bigendian, index, clock, config, irqcallback, NULL);
r2724r2725
698742      flags |= DRCUML_OPTION_LOG_UML;
699743   if (LOG_NATIVE)
700744      flags |= DRCUML_OPTION_LOG_NATIVE;
701   mips3.drcuml = drcuml_alloc(mips3.cache, flags, 2, 32, 2);
745   mips3.drcuml = drcuml_alloc(mips3.cache, flags, 8, 32, 2);
702746   if (mips3.drcuml == NULL)
703747      fatalerror("Error initializing the UML");
704748
r2724r2725
707751      feconfig.max_sequence = 1;
708752   mips3.drcfe = drcfe_init(&feconfig, mips3.core);
709753
754   /* compute the register parameters */
755   for (regnum = 0; regnum < 34; regnum++)
756   {
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]);
761   }
762
763   /* if we have registers to spare, assign r2, r3, r4 to leftovers */
764   if (!DISABLE_FAST_REGISTERS)
765   {
766      drcuml_get_backend_info(mips3.drcuml, &beinfo);
767      if (beinfo.direct_iregs > 4)
768      {
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;
771      }
772      if (beinfo.direct_iregs > 5)
773      {
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;
776      }
777      if (beinfo.direct_iregs > 6)
778      {
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;
781      }
782   }
783
710784   /* mark the cache dirty so it is updated on next execute */
711785   mips3.cache_dirty = TRUE;
712786}
r2724r2725
720794{
721795   /* reset the common code and mark the cache dirty */
722796   mips3com_reset(mips3.core);
797   mips3.cstate->mode = (MODE_KERNEL << 1) | 0;
723798   mips3.cache_dirty = TRUE;
724799}
725800
r2724r2725
749824      /* if we need to recompile, do it */
750825      if (execute_result == EXECUTE_MISSING_CODE)
751826         code_compile_block(drcuml, mips3.cstate->mode, mips3.core->pc);
827      else if (execute_result == EXECUTE_UNMAPPED_CODE)
828         fatalerror("Attempted to execute unmapped code at PC=%08X\n", mips3.core->pc);
829      else if (execute_result == EXECUTE_RESET_CACHE)
830         code_flush_cache(drcuml);
752831
753832   } while (execute_result != EXECUTE_OUT_OF_CYCLES);
754833
r2724r2725
830909
831910static void code_flush_cache(drcuml_state *drcuml)
832911{
912   int mode;
913
833914   /* empty the transient cache contents */
834915   drcuml_reset(drcuml);
835916
r2724r2725
837918   static_generate_entry_point(drcuml);
838919   static_generate_nocode_handler(drcuml);
839920   static_generate_out_of_cycles(drcuml);
921   static_generate_tlb_mismatch(drcuml);
840922
841923   /* append exception handlers for various types */
842   static_generate_exception(drcuml, EXCEPTION_INTERRUPT, TRUE,  "exception_interrupt");
843   static_generate_exception(drcuml, EXCEPTION_INTERRUPT, FALSE, "exception_interrupt_norecover");
844   static_generate_exception(drcuml, EXCEPTION_TLBMOD,    TRUE,  "exception_tlbmod");
845   static_generate_exception(drcuml, EXCEPTION_TLBLOAD,   TRUE,  "exception_tlbload");
846   static_generate_exception(drcuml, EXCEPTION_TLBSTORE,  TRUE,  "exception_tlbstore");
847   static_generate_exception(drcuml, EXCEPTION_SYSCALL,   TRUE,  "exception_syscall");
848   static_generate_exception(drcuml, EXCEPTION_BREAK,     TRUE,  "exception_break");
849   static_generate_exception(drcuml, EXCEPTION_INVALIDOP, TRUE,  "exception_invalidop");
850   static_generate_exception(drcuml, EXCEPTION_BADCOP,    TRUE,  "exception_badcop");
851   static_generate_exception(drcuml, EXCEPTION_OVERFLOW,  TRUE,  "exception_overflow");
852   static_generate_exception(drcuml, EXCEPTION_TRAP,      TRUE,  "exception_trap");
924   static_generate_exception(drcuml, EXCEPTION_INTERRUPT,     TRUE,  "exception_interrupt");
925   static_generate_exception(drcuml, EXCEPTION_INTERRUPT,     FALSE, "exception_interrupt_norecover");
926   static_generate_exception(drcuml, EXCEPTION_TLBMOD,        TRUE,  "exception_tlbmod");
927   static_generate_exception(drcuml, EXCEPTION_TLBLOAD,       TRUE,  "exception_tlbload");
928   static_generate_exception(drcuml, EXCEPTION_TLBSTORE,      TRUE,  "exception_tlbstore");
929   static_generate_exception(drcuml, EXCEPTION_TLBLOAD_FILL,  TRUE,  "exception_tlbload_fill");
930   static_generate_exception(drcuml, EXCEPTION_TLBSTORE_FILL, TRUE,  "exception_tlbstore_fill");
931   static_generate_exception(drcuml, EXCEPTION_ADDRLOAD,      TRUE,  "exception_addrload");
932   static_generate_exception(drcuml, EXCEPTION_ADDRSTORE,     TRUE,  "exception_addrstore");
933   static_generate_exception(drcuml, EXCEPTION_SYSCALL,       TRUE,  "exception_syscall");
934   static_generate_exception(drcuml, EXCEPTION_BREAK,         TRUE,  "exception_break");
935   static_generate_exception(drcuml, EXCEPTION_INVALIDOP,     TRUE,  "exception_invalidop");
936   static_generate_exception(drcuml, EXCEPTION_BADCOP,        TRUE,  "exception_badcop");
937   static_generate_exception(drcuml, EXCEPTION_OVERFLOW,      TRUE,  "exception_overflow");
938   static_generate_exception(drcuml, EXCEPTION_TRAP,          TRUE,  "exception_trap");
853939
854940   /* add subroutines for memory accesses */
855   static_generate_memory_accessor(drcuml, 1, FALSE, FALSE, "read8",       &mips3.read8);
856   static_generate_memory_accessor(drcuml, 1, TRUE,  FALSE, "write8",      &mips3.write8);
857   static_generate_memory_accessor(drcuml, 2, FALSE, FALSE, "read16",      &mips3.read16);
858   static_generate_memory_accessor(drcuml, 2, TRUE,  FALSE, "write16",     &mips3.write16);
859   static_generate_memory_accessor(drcuml, 4, FALSE, FALSE, "read32",      &mips3.read32);
860   static_generate_memory_accessor(drcuml, 4, FALSE, TRUE,  "read32mask",  &mips3.read32mask);
861   static_generate_memory_accessor(drcuml, 4, TRUE,  FALSE, "write32",     &mips3.write32);
862   static_generate_memory_accessor(drcuml, 4, TRUE,  TRUE,  "write32mask", &mips3.write32mask);
863   static_generate_memory_accessor(drcuml, 8, FALSE, FALSE, "read64",      &mips3.read64);
864   static_generate_memory_accessor(drcuml, 8, FALSE, TRUE,  "read64mask",  &mips3.read64mask);
865   static_generate_memory_accessor(drcuml, 8, TRUE,  FALSE, "write64",     &mips3.write64);
866   static_generate_memory_accessor(drcuml, 8, TRUE,  TRUE,  "write64mask", &mips3.write64mask);
941   for (mode = 0; mode < 3; mode++)
942   {
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]);
955   }
867956}
868957
869958
r2724r2725
883972
884973   /* get a description of this sequence */
885974   desclist = drcfe_describe_code(mips3.drcfe, pc);
886   if (LOG_UML)
975   if (LOG_UML || LOG_NATIVE)
887976      log_opcode_desc(drcuml, desclist, 0);
888977
889978   /* if we get an error back, flush the cache and try again */
r2724r2725
9511040         nextpc = seqlast->pc + (seqlast->skipslots + 1) * 4;
9521041
9531042      /* count off cycles and go there */
954      generate_update_cycles(block, &compiler, nextpc, NULL, TRUE);            // <subtract cycles>
1043      generate_update_cycles(block, &compiler, IMM(nextpc), TRUE);            // <subtract cycles>
9551044
9561045      /* if the last instruction can change modes, use a variable mode; otherwise, assume the same mode */
9571046      if (seqlast->flags & OPFLAG_CAN_CHANGE_MODES)
r2724r2725
9711060***************************************************************************/
9721061
9731062/*-------------------------------------------------
1063    cfunc_get_cycles - compute the total number
1064    of cycles executed so far
1065-------------------------------------------------*/
1066
1067static void cfunc_get_cycles(void *param)
1068{
1069   UINT64 *dest = param;
1070   *dest = activecpu_gettotalcycles();
1071}
1072
1073
1074/*-------------------------------------------------
9741075    cfunc_printf_exception - log any exceptions that
9751076    aren't interrupts
9761077-------------------------------------------------*/
r2724r2725
9831084
9841085
9851086/*-------------------------------------------------
986    cfunc_get_cycles - compute the total number
987    of cycles executed so far
1087    cfunc_printf_debug - generic printf for
1088    debugging
9881089-------------------------------------------------*/
9891090
990static void cfunc_get_cycles(void *param)
1091static void cfunc_printf_debug(void *param)
9911092{
992   UINT64 *dest = param;
993   *dest = activecpu_gettotalcycles();
1093   const char *format = param;
1094   printf(format, mips3.cstate->arg0, mips3.cstate->arg1);
9941095}
9951096
9961097
r2724r2725
10491150}
10501151
10511152
1153/*-------------------------------------------------
1154    cfunc_unimplemented - handler for
1155    unimplemented opcdes
1156-------------------------------------------------*/
10521157
1158static void cfunc_unimplemented(void *param)
1159{
1160   UINT32 opcode = (FPTR)param;
1161   fatalerror("PC=%08X: Unimplemented op %08X (%02X,%02X)", mips3.core->pc, opcode, opcode >> 26, opcode & 0x3f);
1162}
1163
1164
1165
10531166/***************************************************************************
10541167    STATIC CODEGEN
10551168***************************************************************************/
r2724r2725
10801193   UML_HANDLE(block, mips3.entry);                                       // handle  entry
10811194
10821195   /* reset the FPU mode */
1083   UML_AND(block, IREG(0), CCR164(31), IMM(3));                           // and     i0,ccr1[31],3
1196   UML_AND(block, IREG(0), CCR132(31), IMM(3));                           // and     i0,ccr1[31],3
10841197   UML_LOAD1U(block, IREG(0), &mips3.cstate->fpmode[0], IREG(0));               // load1u  i0,fpmode,i0
10851198   UML_SETFMOD(block, IREG(0));                                       // setfmod i0
10861199
1200   /* load fast integer registers */
1201   load_fast_iregs(block);
1202
10871203   /* check for interrupts */
10881204   UML_AND(block, IREG(0), CPR032(COP0_Cause), CPR032(COP0_Status));            // and     i0,[Cause],[Status]
10891205   UML_ANDf(block, IREG(0), IREG(0), IMM(0xfc00), FLAGS_Z);                  // and     i0,i0,0xfc00,Z
r2724r2725
11261242   UML_HANDLE(block, mips3.nocode);                                    // handle  nocode
11271243   UML_GETEXP(block, IREG(0));                                          // getexp  i0
11281244   UML_MOV(block, MEM(&mips3.core->pc), IREG(0));                           // mov     [pc],i0
1245   save_fast_iregs(block);
11291246   UML_EXIT(block, IMM(EXECUTE_MISSING_CODE));                              // exit    EXECUTE_MISSING_CODE
11301247
11311248   drcuml_block_end(block);
r2724r2725
11541271   UML_HANDLE(block, mips3.out_of_cycles);                                 // handle  out_of_cycles
11551272   UML_GETEXP(block, IREG(0));                                          // getexp  i0
11561273   UML_MOV(block, MEM(&mips3.core->pc), IREG(0));                           // mov     <pc>,i0
1274   save_fast_iregs(block);
11571275   UML_EXIT(block, IMM(EXECUTE_OUT_OF_CYCLES));                           // exit    EXECUTE_OUT_OF_CYCLES
11581276
11591277   drcuml_block_end(block);
r2724r2725
11611279
11621280
11631281/*-------------------------------------------------
1282    static_generate_tlb_mismatch - generate a
1283    TLB mismatch handler
1284-------------------------------------------------*/
1285
1286static void static_generate_tlb_mismatch(drcuml_state *drcuml)
1287{
1288   drcuml_block *block;
1289   jmp_buf errorbuf;
1290
1291   /* if we get an error back, we're screwed */
1292   if (setjmp(errorbuf) != 0)
1293      fatalerror("Unrecoverable error in static_generate_tlb_mismatch");
1294
1295   /* forward references */
1296   alloc_handle(drcuml, &mips3.exception[EXCEPTION_TLBLOAD], "exception_tlbload");
1297   alloc_handle(drcuml, &mips3.exception[EXCEPTION_TLBLOAD_FILL], "exception_tlbload_fill");
1298
1299   /* begin generating */
1300   block = drcuml_block_begin(drcuml, 20, &errorbuf);
1301
1302   /* 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
1305   UML_RECOVER(block, IREG(0), MAPVAR_PC);                                 // recover i0,PC
1306   UML_MOV(block, MEM(&mips3.core->pc), IREG(0));                           // mov     <pc>,i0
1307   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
1309   if (PRINTF_MMU)
1310   {
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
1313      UML_CALLC(block, cfunc_printf_debug, "TLB mismatch @ %08X (ent=%08X)\n");   // callc   printf_debug
1314   }
1315   UML_TEST(block, IREG(1), IMM(TLB_VALID));                              // test    i1,TLB_VALID
1316   UML_JMPc(block, IF_NZ, 1);                                          // jmp     1,nz
1317   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
1320   UML_LABEL(block, 1);                                          // 1:
1321   save_fast_iregs(block);
1322   UML_EXIT(block, IMM(EXECUTE_MISSING_CODE));                              // exit    EXECUTE_MISSING_CODE
1323
1324   drcuml_block_end(block);
1325}
1326
1327
1328/*-------------------------------------------------
11641329    static_generate_exception - generate a static
11651330    exception handler
11661331-------------------------------------------------*/
11671332
11681333static void static_generate_exception(drcuml_state *drcuml, UINT8 exception, int recover, const char *name)
11691334{
1170   UINT32 offset = (exception >= EXCEPTION_TLBMOD && exception <= EXCEPTION_TLBSTORE) ? 0x00 : 0x180;
1335   drcuml_codehandle **exception_handle = recover ? &mips3.exception[exception] : &mips3.exception_norecover[exception];
1336   UINT32 offset = 0x180;
11711337   drcuml_codelabel next = 1;
11721338   drcuml_block *block;
11731339   jmp_buf errorbuf;
r2724r2725
11761342   if (setjmp(errorbuf) != 0)
11771343      fatalerror("Unrecoverable error in static_generate_exception");
11781344
1345   /* translate our fake fill exceptions into real exceptions */
1346   if (exception == EXCEPTION_TLBLOAD_FILL || exception == EXCEPTION_TLBSTORE_FILL)
1347   {
1348      offset = 0x000;
1349      exception = (exception - EXCEPTION_TLBLOAD_FILL) + EXCEPTION_TLBLOAD;
1350   }
1351
11791352   /* begin generating */
11801353   block = drcuml_block_begin(drcuml, 1024, &errorbuf);
11811354
11821355   /* add a global entry for this */
1183   if (recover)
1356   alloc_handle(drcuml, exception_handle, name);
1357   UML_HANDLE(block, *exception_handle);                                 // handle  name
1358
1359   /* exception parameter is expected to be the fault address in this case */
1360   if (exception == EXCEPTION_TLBLOAD || exception == EXCEPTION_TLBSTORE || exception == EXCEPTION_ADDRLOAD || exception == EXCEPTION_ADDRSTORE)
11841361   {
1185      alloc_handle(drcuml, &mips3.exception[exception], name);
1186      UML_HANDLE(block, mips3.exception[exception]);                        // handle  name
1362      /* set BadVAddr to the fault address */
1363      UML_GETEXP(block, IREG(0));                                       // getexp  i0
1364      UML_TEST(block, CPR032(COP0_Status), IMM(SR_EXL));                     // test    [Status],SR_EXL
1365      UML_MOVc(block, IF_Z, CPR032(COP0_BadVAddr), IREG(0));                  // mov     [BadVAddr],i0,Z
11871366   }
1188   else
1189   {
1190      alloc_handle(drcuml, &mips3.exception_norecover[exception], name);
1191      UML_HANDLE(block, mips3.exception_norecover[exception]);               // handle  name
1192   }
11931367
1194   /* exception parameter is expected to be the fault address in this case */
11951368   if (exception == EXCEPTION_TLBLOAD || exception == EXCEPTION_TLBSTORE)
11961369   {
1197      /* set BadVAddr to the fault address */
1198      UML_GETEXP(block, CPR032(COP0_BadVAddr));                           // mov     [BadVAddr],exp
1199
1200      /* set the upper bits of EntryHi to the fault page */
1201      UML_AND(block, IREG(0), IREG(0), IMM(0xffffe000));                     // and     i0,i0,0xffffe000
1202      UML_AND(block, IREG(1), CPR032(COP0_EntryHi), IMM(0x000000ff));            // and     i1,[EntryHi],0x000000ff
1203      UML_OR(block, CPR032(COP0_EntryHi), IREG(0), IREG(1));                  // or      [EntryHi],i0,i1
1204
1205      /* set the lower bits of Context to the fault page */
1206      UML_SHR(block, IREG(0), IREG(0), IMM(9));                           // shr     i0,i0,9
1207      UML_AND(block, IREG(1), CPR032(COP0_Context), IMM(0xff800000));            // and     i1,[Context],0xff800000
1208      UML_OR(block, CPR032(COP0_Context), IREG(0), IREG(1));                  // or      [Context],i0,i1
1370      /* set the upper bits of EntryHi and the lower bits of Context to the fault page */
1371      UML_INSERT(block, CPR032(COP0_EntryHi), IREG(0), IMM(0), IMM(0xffffe000));   // insert  [EntryHi],i0,0,0xffffe000
1372      UML_INSERT(block, CPR032(COP0_Context), IREG(0), IMM(32-9), IMM(0x7fffff));   // insert  [Context],i0,32-9,0x7fffff
12091373   }
12101374
12111375   /* set the EPC and Cause registers */
r2724r2725
12211385   UML_OR(block, IREG(2), IREG(2), IMM(0x80000000));                        // or      i2,i2,0x80000000
12221386   UML_SUB(block, IREG(0), IREG(0), IMM(1));                              // sub     i0,i0,1
12231387   UML_LABEL(block, next);                                          // <next>:
1224   UML_MOV(block, CPR032(COP0_EPC), IREG(0));                              // mov     [EPC],i0
1388   UML_TEST(block, CPR032(COP0_Status), IMM(SR_EXL));                        // test    [Status],SR_EXL
1389   UML_MOVc(block, IF_Z, CPR032(COP0_EPC), IREG(0));                        // mov     [EPC],i0,Z
12251390   UML_OR(block, CPR032(COP0_Cause), IREG(2), IMM(exception << 2));            // or      [Cause],i2,exception << 2
12261391
12271392   /* set EXL in the SR */
1228   UML_OR(block, CPR032(COP0_Status), CPR032(COP0_Status), IMM(SR_EXL));         // or      [Status],[Status],SR_EXL
1393   UML_OR(block, IREG(0), CPR032(COP0_Status), IMM(SR_EXL));                  // or      i0,[Status],SR_EXL
1394   UML_MOV(block, CPR032(COP0_Status), IREG(0));                           // mov     [Status],i0
1395   generate_update_mode(block);
12291396
12301397   /* optionally print exceptions */
1231   if (PRINTF_EXCEPTIONS && exception != EXCEPTION_INTERRUPT && exception != EXCEPTION_SYSCALL)
1398   if ((PRINTF_EXCEPTIONS && exception != EXCEPTION_INTERRUPT && exception != EXCEPTION_SYSCALL) ||
1399      (PRINTF_MMU && (exception == EXCEPTION_TLBLOAD || exception == EXCEPTION_TLBSTORE)))
12321400      UML_CALLC(block, cfunc_printf_exception, NULL);                        // callc   cfunc_printf_exception,NULL
12331401
12341402   /* choose our target PC */
12351403   UML_MOV(block, IREG(0), IMM(0xbfc00200 + offset));                        // mov     i0,0xbfc00200 + offset
1236   UML_TEST(block, CPR032(COP0_Status), IMM(SR_BEV));                        // test    [Status],SR_BEV
1404   UML_TEST(block, IREG(1), IMM(SR_BEV));                                 // test    i1,SR_BEV
12371405   UML_MOVc(block, IF_Z, IREG(0), IMM(0x80000000 + offset));                  // mov     i0,0x80000000 + offset,z
12381406
12391407   /* adjust cycles */
r2724r2725
12501418    static_generate_memory_accessor
12511419------------------------------------------------------------------*/
12521420
1253static void static_generate_memory_accessor(drcuml_state *drcuml, int size, int iswrite, int ismasked, const char *name, drcuml_codehandle **handleptr)
1421static void static_generate_memory_accessor(drcuml_state *drcuml, int mode, int size, int iswrite, int ismasked, const char *name, drcuml_codehandle **handleptr)
12541422{
12551423   /* on entry, address is in I0; data for writes is in I1; mask for accesses is in I2 */
12561424   /* on exit, read result is in I0 */
12571425   /* routine trashes I0-I3 */
1258   drcuml_codehandle *exception_target = mips3.exception[iswrite ? EXCEPTION_TLBSTORE : EXCEPTION_TLBLOAD];
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];
12591429   drcuml_block *block;
12601430   jmp_buf errorbuf;
1261   int label = 0;
1431   int tlbmiss = 0;
1432   int label = 1;
12621433   int ramnum;
12631434
12641435   /* if we get an error back, we're screwed */
r2724r2725
12721443   alloc_handle(drcuml, handleptr, name);
12731444   UML_HANDLE(block, *handleptr);                                       // handle  *handleptr
12741445
1446   /* user mode? generate address exception if top bit is set */
1447   if (mode == MODE_USER)
1448   {
1449      UML_TEST(block, IREG(0), IMM(0x80000000));                           // test    i0,0x80000000
1450      UML_EXHc(block, IF_NZ, exception_addrerr, IREG(0));                     // exh     addrerr,i0,nz
1451   }
1452
1453   /* supervisor mode? generate address exception if not in user space or in $C0000000-DFFFFFFF */
1454   if (mode == MODE_SUPER)
1455   {
1456      int addrok;
1457      UML_TEST(block, IREG(0), IMM(0x80000000));                           // test    i0,0x80000000
1458      UML_JMPc(block, IF_Z, addrok = label++);                           // jz      addrok
1459      UML_SHR(block, IREG(3), IREG(0), IMM(29));                           // shr     i3,i0,29
1460      UML_CMP(block, IREG(3), IMM(6));                                 // cmp     i3,6
1461      UML_EXHc(block, IF_NE, exception_addrerr, IREG(0));                     // exh     addrerr,i0,ne
1462      UML_LABEL(block, addrok);                                    // addrok:
1463   }
1464
12751465   /* general case: assume paging and perform a translation */
12761466   UML_SHR(block, IREG(3), IREG(0), IMM(12));                              // shr     i3,i0,12
12771467   UML_LOAD4(block, IREG(3), mips3.core->tlb_table, IREG(3));                  // load4   i3,[tlb_table],i3
1278   UML_TEST(block, IREG(3), IMM(iswrite ? 1 : 2));                           // test    i3,iswrite ? 1 : 2
1279   UML_EXHc(block, IF_NZ, exception_target, IREG(0));                        // exnz    exception_target,i0
1280   UML_AND(block, IREG(0), IREG(0), IMM(0xfff));                           // and     i0,i0,0xfff
1281   UML_AND(block, IREG(3), IREG(3), IMM(~0xfff));                           // and     i3,i3,~0xfff
1282   UML_OR(block, IREG(0), IREG(0), IREG(3));                              // or      i0,i0,i3
1468   UML_TEST(block, IREG(3), IMM(iswrite ? TLB_DIRTY : TLB_VALID));               // test    i3,iswrite ? TLB_DIRTY : TLB_VALID
1469   UML_JMPc(block, IF_Z, tlbmiss = label++);                              // jmp     tlbmiss,z
1470   UML_INSERT(block, IREG(0), IREG(3), IMM(0), IMM(0xfffff000));               // insert  i0,i3,0,0xfffff000
12831471
12841472   for (ramnum = 0; ramnum < MIPS3_MAX_FASTRAM; ramnum++)
12851473      if (!Machine->debug_mode && mips3.fastram[ramnum].base != NULL && (!iswrite || !mips3.fastram[ramnum].readonly))
r2724r2725
13471535               if (ismasked)
13481536               {
13491537                  UML_LOAD4(block, IREG(3), fastbase, IREG(0));            // load4   i3,fastbase,i0
1350                  UML_AND(block, IREG(1), IREG(1), IREG(2));               // and     i1,i1,i2
1351                  UML_XOR(block, IREG(2), IREG(2), IMM(0xffffffff));         // xor     i2,i2,0xfffffffff
1352                  UML_AND(block, IREG(3), IREG(3), IREG(2));               // and     i3,i3,i2
1353                  UML_OR(block, IREG(1), IREG(1), IREG(3));               // or      i1,i1,i3
1538                  UML_INSERT(block, IREG(3), IREG(1), IMM(0), IREG(2));      // insert  i3,i1,0,i2
1539                  UML_STORE4(block, fastbase, IREG(0), IREG(3));            // store4  fastbase,i0,i3
13541540               }
1355               UML_STORE4(block, fastbase, IREG(0), IREG(1));               // store4  fastbase,i0,i1
1541               else
1542                  UML_STORE4(block, fastbase, IREG(0), IREG(1));            // store4  fastbase,i0,i1
13561543            }
13571544            else if (size == 8)
13581545            {
r2724r2725
13641551                  UML_DROR(block, IREG(2), IREG(2), IMM(32 * (mips3.core->bigendian ? BYTE_XOR_BE(0) : BYTE_XOR_LE(0))));
13651552                                                               // dror    i2,i2,32*bytexor
13661553                  UML_DLOAD8(block, IREG(3), fastbase, IREG(0));            // dload8  i3,fastbase,i0
1367                  UML_DAND(block, IREG(1), IREG(1), IREG(2));               // dand    i1,i1,i2
1368                  UML_DXOR(block, IREG(2), IREG(2), IMM(U64(0xffffffffffffffff)));
1369                                                               // dxor    i2,i2,0xfffffffffffffffff
1370                  UML_DAND(block, IREG(3), IREG(3), IREG(2));               // dand    i3,i3,i2
1371                  UML_DOR(block, IREG(1), IREG(1), IREG(3));               // dor     i1,i1,i3
1554                  UML_DINSERT(block, IREG(3), IREG(1), IMM(0), IREG(2));      // dinsert i3,i1,0,i2
1555                  UML_DSTORE8(block, fastbase, IREG(0), IREG(3));            // dstore8 fastbase,i0,i3
13721556               }
1373               UML_DSTORE8(block, fastbase, IREG(0), IREG(1));               // dstore8 fastbase,i0,i1
1557               else
1558                  UML_DSTORE8(block, fastbase, IREG(0), IREG(1));            // dstore8 fastbase,i0,i1
13741559            }
13751560            UML_RET(block);                                          // ret
13761561         }
r2724r2725
14301615   }
14311616   UML_RET(block);                                                   // ret
14321617
1618   if (tlbmiss != 0)
1619   {
1620      UML_LABEL(block, tlbmiss);                                    // tlbmiss:
1621      if (iswrite)
1622      {
1623         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
1625      }
1626      UML_TEST(block, IREG(3), IMM(TLB_PRESENT));                           // test    i3,TLB_PRESENT
1627      UML_EXHc(block, IF_NZ, exception_tlb, IREG(0));                        // exh     tlb,i0,nz
1628      UML_EXH(block, exception_tlbfill, IREG(0));                           // exh     tlbfill,i0
1629   }
1630
14331631   drcuml_block_end(block);
14341632}
14351633
r2724r2725
14401638***************************************************************************/
14411639
14421640/*-------------------------------------------------
1641    generate_update_mode - update the mode based
1642    on a new SR (in i0); trashes i2
1643-------------------------------------------------*/
1644
1645static void generate_update_mode(drcuml_block *block)
1646{
1647   UML_XTRACT(block, IREG(2), IREG(0), IMM(32-2), IMM(0x06));                  // xtract  i2,i0,32-2,0x06
1648   UML_TEST(block, IREG(0), IMM(SR_EXL | SR_ERL));                           // test    i0,SR_EXL | SR_ERL
1649   UML_MOVc(block, IF_NZ, IREG(2), IMM(0));                              // mov     i2,0,nz
1650   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
1652}
1653
1654
1655/*-------------------------------------------------
14431656    generate_update_cycles - generate code to
14441657    subtract cycles from the icount and generate
14451658    an exception if out
14461659-------------------------------------------------*/
14471660
1448static void generate_update_cycles(drcuml_block *block, compiler_state *compiler, UINT32 nextpc, UINT32 *mempc, int allow_exception)
1661static void generate_update_cycles(drcuml_block *block, compiler_state *compiler, drcuml_ptype ptype, UINT64 pvalue, int allow_exception)
14491662{
14501663   /* check software interrupts if pending */
14511664   if (compiler->checksoftints)
r2724r2725
14561669      UML_AND(block, IREG(0), CPR032(COP0_Cause), CPR032(COP0_Status));         // and     i0,[Cause],[Status]
14571670      UML_ANDf(block, IREG(0), IREG(0), IMM(0x0300), FLAGS_Z);               // and     i0,i0,0x0300,Z
14581671      UML_JMPc(block, IF_Z, skip = compiler->labelnum++);                     // jmp     skip,Z
1459      if (mempc == NULL)
1460         UML_MOV(block, IREG(0), IMM(nextpc));                           // mov     i0,nextpc
1461      else
1462         UML_MOV(block, IREG(0), MEM(mempc));                           // mov     i0,[mempc]
1672      UML_MOV(block, IREG(0), PARAM(ptype, pvalue));                        // mov     i0,nextpc
14631673      UML_MOV(block, IREG(1), IMM(compiler->cycles));                        // mov     i1,cycles
14641674      UML_CALLH(block, mips3.exception_norecover[EXCEPTION_INTERRUPT]);         // callh   interrupt_norecover
14651675      UML_LABEL(block, skip);                                       // skip:
r2724r2725
14781688      UML_JMPc(block, IF_Z, skip);                                    // jmp     skip,Z
14791689      UML_TEST(block, CPR032(COP0_Status), IMM(SR_EXL | SR_ERL));               // test    [Status],SR_EXL | SR_ERL
14801690      UML_JMPc(block, IF_NZ, skip);                                    // jmp     skip,NZ
1481      if (mempc == NULL)
1482         UML_MOV(block, IREG(0), IMM(nextpc));                           // mov     i0,nextpc
1483      else
1484         UML_MOV(block, IREG(0), MEM(mempc));                           // mov     i0,[mempc]
1691      UML_MOV(block, IREG(0), PARAM(ptype, pvalue));                        // mov     i0,nextpc
14851692      UML_MOV(block, IREG(1), IMM(compiler->cycles));                        // mov     i1,cycles
14861693      UML_CALLH(block, mips3.exception_norecover[EXCEPTION_INTERRUPT]);         // callh   interrupt_norecover
14871694      UML_LABEL(block, skip);                                       // skip:
r2724r2725
14941701                                                               // sub     icount,icount,cycles,S
14951702      UML_MAPVAR(block, MAPVAR_CYCLES, 0);                              // mapvar  cycles,0
14961703      if (allow_exception)
1497      {
1498         if (mempc == NULL)
1499            UML_EXHc(block, IF_S, mips3.out_of_cycles, IMM(nextpc));         // exh     out_of_cycles,nextpc
1500         else
1501            UML_EXHc(block, IF_S, mips3.out_of_cycles, MEM(mempc));            // exh     out_of_cycles,<mempc>
1502      }
1704         UML_EXHc(block, IF_S, mips3.out_of_cycles, PARAM(ptype, pvalue));      // exh     out_of_cycles,nextpc
15031705   }
15041706   compiler->cycles = 0;
15051707}
r2724r2725
15191721   /* loose verify or single instruction: just compare and fail */
15201722   if (!(mips3.drcoptions & MIPS3DRC_STRICT_VERIFY) || seqhead->next == NULL)
15211723   {
1522      UML_LOAD4(block, IREG(0), seqhead->opptr.l, IMM(0));                  // load4   i0,*opptr
1523      UML_CMP(block, IREG(0), IMM(*seqhead->opptr.l));                     // cmp     i0,*opptr
1524      UML_EXHc(block, IF_NE, mips3.nocode, IMM(epc(seqhead)));               // exne    nocode,seqhead->pc
1724      if (!(seqhead->flags & OPFLAG_VIRTUAL_NOOP))
1725      {
1726         UML_LOAD4(block, IREG(0), seqhead->opptr.l, IMM(0));               // load4   i0,*opptr
1727         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
1729      }
15251730   }
15261731
15271732   /* full verification; sum up everything */
15281733   else
15291734   {
1735#if 0
1736      for (curdesc = seqhead->next; curdesc != seqlast->next; curdesc = curdesc->next)
1737         if (!(curdesc->flags & OPFLAG_VIRTUAL_NOOP))
1738         {
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
1742         }
1743#else
15301744      UINT32 sum = 0;
15311745      UML_LOAD4(block, IREG(0), seqhead->opptr.l, IMM(0));                  // load4   i0,*opptr
15321746      sum += *seqhead->opptr.l;
15331747      for (curdesc = seqhead->next; curdesc != seqlast->next; curdesc = curdesc->next)
1534      {
1535         UML_LOAD4(block, IREG(1), curdesc->opptr.l, IMM(0));               // load4   i1,*opptr
1536         UML_ADD(block, IREG(0), IREG(0), IREG(1));                        // add     i0,i0,i1
1537         sum += *curdesc->opptr.l;
1538      }
1748         if (!(curdesc->flags & OPFLAG_VIRTUAL_NOOP))
1749         {
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
1752            sum += *curdesc->opptr.l;
1753         }
15391754      UML_CMP(block, IREG(0), IMM(sum));                                 // cmp     i0,sum
15401755      UML_EXHc(block, IF_NE, mips3.nocode, IMM(epc(seqhead)));               // exne    nocode,seqhead->pc
1756#endif
15411757   }
15421758}
15431759
r2724r2725
15531769   int hotnum;
15541770
15551771   /* add an entry for the log */
1556   if (LOG_UML)
1772   if (LOG_UML && !(desc->flags & OPFLAG_VIRTUAL_NOOP))
15571773      log_add_disasm_comment(block, desc->pc, *desc->opptr.l);
15581774
15591775   /* set the PC map variable */
r2724r2725
15651781
15661782   /* is this a hotspot? */
15671783   for (hotnum = 0; hotnum < MIPS3_MAX_HOTSPOTS; hotnum++)
1568      if (desc->pc == mips3.hotspot[hotnum].pc && *desc->opptr.l == mips3.hotspot[hotnum].opcode)
1784      if (mips3.hotspot[hotnum].pc != 0 && desc->pc == mips3.hotspot[hotnum].pc && *desc->opptr.l == mips3.hotspot[hotnum].opcode)
15691785      {
15701786         compiler->cycles += mips3.hotspot[hotnum].cycles;
15711787         break;
r2724r2725
15821798   if (Machine->debug_mode)
15831799   {
15841800      UML_MOV(block, MEM(&mips3.core->pc), IMM(desc->pc));                  // mov     [pc],desc->pc
1801      save_fast_iregs(block);
15851802      UML_DEBUG(block, IMM(desc->pc));                                 // debug   desc->pc
15861803   }
15871804
1588   /* validate our TLB entry at this PC; if we fail, we need to recompile */
1805   /* if we hit an unmapped address, fatal error */
1806   if (desc->flags & OPFLAG_COMPILER_UNMAPPED)
1807   {
1808      UML_MOV(block, MEM(&mips3.core->pc), IMM(desc->pc));                  // mov     [pc],desc->pc
1809      save_fast_iregs(block);
1810      UML_EXIT(block, IMM(EXECUTE_UNMAPPED_CODE));                        // exit    EXECUTE_UNMAPPED_CODE
1811   }
1812
1813   /* if we hit a compiler page fault, it's just like a TLB mismatch */
1814   if (desc->flags & OPFLAG_COMPILER_PAGE_FAULT)
1815   {
1816      if (PRINTF_MMU)
1817      {
1818         UML_MOV(block, MEM(&mips3.cstate->arg0), IMM(desc->pc));            // mov     [arg0],desc->pc
1819         UML_CALLC(block, cfunc_printf_debug, "Compiler page fault @ %08X\n");   // callc   printf_debug
1820      }
1821      UML_EXH(block, mips3.tlb_mismatch, IMM(0));                           // exh     tlb_mismatch,0
1822   }
1823
1824   /* validate our TLB entry at this PC; if we fail, we need to handle it */
15891825   if ((desc->flags & OPFLAG_VALIDATE_TLB) && (desc->pc < 0x80000000 || desc->pc >= 0xc0000000))
15901826   {
1591      UML_CMP(block, MEM(&mips3.core->tlb_table[desc->pc >> 12]),
1592                     IMM(mips3.core->tlb_table[desc->pc >> 12]));               // cmp     [tlbentry],*tlbentry
1593      UML_EXHc(block, IF_NE, mips3.tlb_mismatch, IMM(0));                     // exh     tlb_mismatch,0,NE
1827      /* if we currently have a valid TLB read entry, we just verify */
1828      if (mips3.core->tlb_table[desc->pc >> 12] & TLB_VALID)
1829      {
1830         if (PRINTF_MMU)
1831         {
1832            UML_MOV(block, MEM(&mips3.cstate->arg0), IMM(desc->pc));         // mov     [arg0],desc->pc
1833            UML_CALLC(block, cfunc_printf_debug, "Checking TLB at @ %08X\n");   // callc   printf_debug
1834         }
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
1838      }
1839
1840      /* otherwise, we generate an unconditional exception */
1841      else
1842      {
1843         if (PRINTF_MMU)
1844         {
1845            UML_MOV(block, MEM(&mips3.cstate->arg0), IMM(desc->pc));         // mov     [arg0],desc->pc
1846            UML_CALLC(block, cfunc_printf_debug, "No valid TLB @ %08X\n");      // callc   printf_debug
1847         }
1848         UML_EXH(block, mips3.tlb_mismatch, IMM(0));                        // exh     tlb_mismatch,0
1849      }
15941850   }
15951851
15961852   /* if this is an invalid opcode, generate the exception now */
15971853   if (desc->flags & OPFLAG_INVALID_OPCODE)
15981854      UML_EXH(block, mips3.exception[EXCEPTION_INVALIDOP], IMM(0));            // exh     invalidop,0
15991855
1600   /* otherwise, it's a regular instruction */
1601   else
1856   /* otherwise, unless this is a virtual no-op, it's a regular instruction */
1857   else if (!(desc->flags & OPFLAG_VIRTUAL_NOOP))
16021858   {
16031859      /* compile the instruction */
16041860      if (!generate_opcode(block, compiler, desc))
1605         fatalerror("Unimplemented op %08X (%02X,%02X)", *desc->opptr.l, *desc->opptr.l >> 26, *desc->opptr.l & 0x3f);
1861      {
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
1864      }
16061865   }
16071866}
16081867
r2724r2725
16271886   /* update the cycles and jump through the hash table to the target */
16281887   if (desc->targetpc != BRANCH_TARGET_DYNAMIC)
16291888   {
1630      generate_update_cycles(block, &compiler_temp, desc->targetpc, NULL, TRUE);   // <subtract cycles>
1889      generate_update_cycles(block, &compiler_temp, IMM(desc->targetpc), TRUE);   // <subtract cycles>
16311890      if (desc->flags & OPFLAG_INTRABLOCK_BRANCH)
16321891         UML_JMP(block, desc->targetpc | 0x80000000);                     // jmp     desc->targetpc | 0x80000000
16331892      else
r2724r2725
16361895   }
16371896   else
16381897   {
1639      generate_update_cycles(block, &compiler_temp, 0, LOPTR(&mips3.core->r[RSREG]), TRUE);
1898      generate_update_cycles(block, &compiler_temp, R32(RSREG), TRUE);
16401899                                                               // <subtract cycles>
16411900      UML_HASHJMP(block, IMM(mips3.cstate->mode), R32(RSREG), mips3.nocode);      // hashjmp <mode>,<rsreg>,nocode
16421901   }
r2724r2725
18032062
18042063      case 0x20:   /* LB - MIPS I */
18052064         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
1806         UML_CALLH(block, mips3.read8);                                 // callh   read8
2065         UML_CALLH(block, mips3.read8[mips3.cstate->mode >> 1]);               // callh   read8
18072066         if (RTREG != 0)
18082067            UML_DSEXT1(block, R64(RTREG), IREG(0));                        // dsext1  <rtreg>,i0
18092068         if (!in_delay_slot)
1810            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2069            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
18112070         return TRUE;
18122071
18132072      case 0x21:   /* LH - MIPS I */
18142073         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
1815         UML_CALLH(block, mips3.read16);                                 // callh   read16
2074         UML_CALLH(block, mips3.read16[mips3.cstate->mode >> 1]);            // callh   read16
18162075         if (RTREG != 0)
18172076            UML_DSEXT2(block, R64(RTREG), IREG(0));                        // dsext2  <rtreg>,i0
18182077         if (!in_delay_slot)
1819            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2078            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
18202079         return TRUE;
18212080
18222081      case 0x23:   /* LW - MIPS I */
18232082         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
1824         UML_CALLH(block, mips3.read32);                                 // callh   read32
2083         UML_CALLH(block, mips3.read32[mips3.cstate->mode >> 1]);            // callh   read32
18252084         if (RTREG != 0)
18262085            UML_DSEXT4(block, R64(RTREG), IREG(0));                        // dsext4  <rtreg>,i0
18272086         if (!in_delay_slot)
1828            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2087            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
18292088         return TRUE;
18302089
18312090      case 0x24:   /* LBU - MIPS I */
18322091         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
1833         UML_CALLH(block, mips3.read8);                                 // callh   read8
2092         UML_CALLH(block, mips3.read8[mips3.cstate->mode >> 1]);               // callh   read8
18342093         if (RTREG != 0)
18352094            UML_DZEXT1(block, R64(RTREG), IREG(0));                        // dzext1  <rtreg>,i0
18362095         if (!in_delay_slot)
1837            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2096            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
18382097         return TRUE;
18392098
18402099      case 0x25:   /* LHU - MIPS I */
18412100         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
1842         UML_CALLH(block, mips3.read16);                                 // callh   read16
2101         UML_CALLH(block, mips3.read16[mips3.cstate->mode >> 1]);            // callh   read16
18432102         if (RTREG != 0)
18442103            UML_DZEXT2(block, R64(RTREG), IREG(0));                        // dzext2  <rtreg>,i0
18452104         if (!in_delay_slot)
1846            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2105            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
18472106         return TRUE;
18482107
18492108      case 0x27:   /* LWU - MIPS III */
18502109         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
1851         UML_CALLH(block, mips3.read32);                                 // callh   read32
2110         UML_CALLH(block, mips3.read32[mips3.cstate->mode >> 1]);            // callh   read32
18522111         if (RTREG != 0)
18532112            UML_DZEXT4(block, R64(RTREG), IREG(0));                        // dzext4  <rtreg>,i0
18542113         if (!in_delay_slot)
1855            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2114            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
18562115         return TRUE;
18572116
18582117      case 0x37:   /* LD - MIPS III */
18592118         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
1860         UML_CALLH(block, mips3.read64);                                 // callh   read64
2119         UML_CALLH(block, mips3.read64[mips3.cstate->mode >> 1]);            // callh   read64
18612120         if (RTREG != 0)
18622121            UML_DMOV(block, R64(RTREG), IREG(0));                        // dmov    <rtreg>,i0
18632122         if (!in_delay_slot)
1864            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2123            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
18652124         return TRUE;
18662125
18672126      case 0x22:   /* LWL - MIPS I */
18682127         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
1869         UML_SHL(block, IREG(4), IREG(0), IMM(3));                        // shl     i4,i0,3
2128         UML_SHL(block, IREG(1), IREG(0), IMM(3));                        // shl     i1,i0,3
18702129         if (!mips3.core->bigendian)
1871            UML_XOR(block, IREG(4), IREG(4), IMM(0x18));                  // xor     i4,i4,0x18
1872         UML_SHR(block, IREG(2), IMM(~0), IREG(4));                        // shr     i2,~0,i4
1873         UML_CALLH(block, mips3.read32mask);                              // callh   read32mask
2130            UML_XOR(block, IREG(1), IREG(1), IMM(0x18));                  // xor     i1,i1,0x18
2131         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
18742133         if (RTREG != 0)
18752134         {
1876            UML_SHL(block, IREG(2), IMM(~0), IREG(4));                     // shl     i2,~0,i4
1877            UML_XOR(block, IREG(2), IREG(2), IMM(~0));                     // xor     i2,i2,~0
1878            UML_SHL(block, IREG(0), IREG(0), IREG(4));                     // shl     i0,i0,i4
1879            UML_AND(block, IREG(2), IREG(2), R32(RTREG));                  // and     i2,i2,<rtreg>
1880            UML_OR(block, IREG(0), IREG(0), IREG(2));                     // or      i0,i0,i2
1881            UML_DSEXT4(block, R64(RTREG), IREG(0));                        // dsext4  <rtreg>,i0
2135            UML_SHL(block, IREG(2), IMM(~0), IREG(1));                     // shl     i2,~0,i1
2136            UML_MOV(block, IREG(3), R32(RTREG));                        // mov     i3,<rtreg>
2137            UML_INSERT(block, IREG(3), IREG(0), IREG(1), IREG(2));            // insert  i3,i0,i1,i2
2138            UML_DSEXT4(block, R64(RTREG), IREG(3));                        // dsext4  <rtreg>,i3
18822139         }
18832140         if (!in_delay_slot)
1884            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2141            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
18852142         return TRUE;
18862143
18872144      case 0x26:   /* LWR - MIPS I */
18882145         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
1889         UML_SHL(block, IREG(4), IREG(0), IMM(3));                        // shl     i4,i0,3
2146         UML_SHL(block, IREG(1), IREG(0), IMM(3));                        // shl     i1,i0,3
18902147         if (mips3.core->bigendian)
1891            UML_XOR(block, IREG(4), IREG(4), IMM(0x18));                  // xor     i4,i4,0x18
1892         UML_SHL(block, IREG(2), IMM(~0), IREG(4));                        // shl     i2,~0,i4
1893         UML_CALLH(block, mips3.read32mask);                              // callh   read32mask
2148            UML_XOR(block, IREG(1), IREG(1), IMM(0x18));                  // xor     i1,i1,0x18
2149         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
18942151         if (RTREG != 0)
18952152         {
1896            UML_SHR(block, IREG(2), IMM(~0), IREG(4));                     // shr     i2,~0,i4
1897            UML_XOR(block, IREG(2), IREG(2), IMM(~0));                     // xor     i2,i2,~0
1898            UML_SHR(block, IREG(0), IREG(0), IREG(4));                     // shr     i0,i0,i4
1899            UML_AND(block, IREG(2), IREG(2), R32(RTREG));                  // and     i2,i2,<rtreg>
1900            UML_OR(block, IREG(0), IREG(0), IREG(2));                     // or      i0,i0,i2
1901            UML_DSEXT4(block, R64(RTREG), IREG(0));                        // dsext4  <rtreg>,i0
2153            UML_SHR(block, IREG(2), IMM(~0), IREG(1));                     // shr     i2,~0,i1
2154            UML_SUB(block, IREG(1), IMM(32), IREG(1));                     // sub     i1,32,i1
2155            UML_MOV(block, IREG(3), R32(RTREG));                        // mov     i3,<rtreg>
2156            UML_INSERT(block, IREG(3), IREG(0), IREG(1), IREG(2));            // insert  i3,i0,i1,i2
2157            UML_DSEXT4(block, R64(RTREG), IREG(3));                        // dsext4  <rtreg>,i3
19022158         }
19032159         if (!in_delay_slot)
1904            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2160            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
19052161         return TRUE;
19062162
19072163      case 0x1a:   /* LDL - MIPS III */
19082164         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
1909         UML_SHL(block, IREG(4), IREG(0), IMM(3));                        // shl     i4,i0,3
2165         UML_SHL(block, IREG(1), IREG(0), IMM(3));                        // shl     i1,i0,3
19102166         if (!mips3.core->bigendian)
1911            UML_XOR(block, IREG(4), IREG(4), IMM(0x38));                  // xor     i4,i4,0x38
1912         UML_DSHR(block, IREG(2), IMM((UINT64)~0), IREG(4));                  // dshr    i2,~0,i4
1913         UML_CALLH(block, mips3.read64mask);                              // callh   read64mask
2167            UML_XOR(block, IREG(1), IREG(1), IMM(0x38));                  // xor     i1,i1,0x38
2168         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
19142170         if (RTREG != 0)
19152171         {
1916            UML_DSHL(block, IREG(2), IMM((UINT64)~0), IREG(4));               // dshl    i2,~0,i4
1917            UML_DXOR(block, IREG(2), IREG(2), IMM((UINT64)~0));               // dxor    i2,i2,~0
1918            UML_DSHL(block, IREG(0), IREG(0), IREG(4));                     // dshl    i0,i0,i4
1919            UML_DAND(block, IREG(2), IREG(2), R64(RTREG));                  // dand    i2,i2,<rtreg>
1920            UML_DOR(block, R64(RTREG), IREG(0), IREG(2));                  // dor     <rtreg>,i0,i2
2172            UML_DSHL(block, IREG(2), IMM((UINT64)~0), IREG(1));               // dshl    i2,~0,i1
2173            UML_DINSERT(block, R64(RTREG), IREG(0), IREG(1), IREG(2));         // dinsert <rtreg>,i0,i1,i2
19212174         }
19222175         if (!in_delay_slot)
1923            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2176            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
19242177         return TRUE;
19252178
19262179      case 0x1b:   /* LDR - MIPS III */
19272180         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
1928         UML_SHL(block, IREG(4), IREG(0), IMM(3));                        // shl     i4,i0,3
2181         UML_SHL(block, IREG(1), IREG(0), IMM(3));                        // shl     i1,i0,3
19292182         if (mips3.core->bigendian)
1930            UML_XOR(block, IREG(4), IREG(4), IMM(0x38));                  // xor     i4,i4,0x38
1931         UML_DSHL(block, IREG(2), IMM((UINT64)~0), IREG(4));                  // dshl    i2,~0,i4
1932         UML_CALLH(block, mips3.read64mask);                              // callh   read64mask
2183            UML_XOR(block, IREG(1), IREG(1), IMM(0x38));                  // xor     i1,i1,0x38
2184         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
19332186         if (RTREG != 0)
19342187         {
1935            UML_DSHR(block, IREG(2), IMM((UINT64)~0), IREG(4));               // dshr    i2,~0,i4
1936            UML_DXOR(block, IREG(2), IREG(2), IMM((UINT64)~0));               // dxor    i2,i2,~0
1937            UML_DSHR(block, IREG(0), IREG(0), IREG(4));                     // dshr    i0,i0,i4
1938            UML_DAND(block, IREG(2), IREG(2), R64(RTREG));                  // dand    i2,i2,<rtreg>
1939            UML_DOR(block, R64(RTREG), IREG(0), IREG(2));                  // dor     <rtreg>,i0,i2
2188            UML_DSHR(block, IREG(2), IMM((UINT64)~0), IREG(1));               // dshr    i2,~0,i1
2189            UML_SUB(block, IREG(1), IMM(64), IREG(1));                     // sub     i1,64,i1
2190            UML_DINSERT(block, R64(RTREG), IREG(0), IREG(1), IREG(2));         // dinsert <rtreg>,i0,i1,i2
19402191         }
19412192         if (!in_delay_slot)
1942            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2193            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
19432194         return TRUE;
19442195
19452196      case 0x31:   /* LWC1 - MIPS I */
19462197         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
1947         UML_CALLH(block, mips3.read32);                                 // callh   read32
2198         UML_CALLH(block, mips3.read32[mips3.cstate->mode >> 1]);            // callh   read32
19482199         UML_MOV(block, FPR32(RTREG), IREG(0));                           // mov     <cpr1_rt>,i0
19492200         if (!in_delay_slot)
1950            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2201            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
19512202         return TRUE;
19522203
19532204      case 0x35:   /* LDC1 - MIPS III */
19542205         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
1955         UML_CALLH(block, mips3.read64);                                 // callh   read64
2206         UML_CALLH(block, mips3.read64[mips3.cstate->mode >> 1]);            // callh   read64
19562207         UML_DMOV(block, FPR64(RTREG), IREG(0));                           // dmov    <cpr1_rt>,i0
19572208         if (!in_delay_slot)
1958            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2209            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
19592210         return TRUE;
19602211
19612212      case 0x32:   /* LWC2 - MIPS I */
19622213         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
1963         UML_CALLH(block, mips3.read32);                                 // callh   read32
2214         UML_CALLH(block, mips3.read32[mips3.cstate->mode >> 1]);            // callh   read32
19642215         UML_DZEXT4(block, CPR264(RTREG), IREG(0));                        // dzext4  <cpr2_rt>,i0
19652216         if (!in_delay_slot)
1966            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2217            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
19672218         return TRUE;
19682219
19692220      case 0x36:   /* LDC2 - MIPS II */
19702221         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
1971         UML_CALLH(block, mips3.read64);                                 // callh   read64
2222         UML_CALLH(block, mips3.read64[mips3.cstate->mode >> 1]);            // callh   read64
19722223         UML_DMOV(block, CPR264(RTREG), IREG(0));                        // dmov    <cpr2_rt>,i0
19732224         if (!in_delay_slot)
1974            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2225            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
19752226         return TRUE;
19762227
19772228
r2724r2725
19802231      case 0x28:   /* SB - MIPS I */
19812232         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
19822233         UML_MOV(block, IREG(1), R32(RTREG));                           // mov     i1,<rtreg>
1983         UML_CALLH(block, mips3.write8);                                 // callh   write8
2234         UML_CALLH(block, mips3.write8[mips3.cstate->mode >> 1]);            // callh   write8
19842235         if (!in_delay_slot)
1985            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2236            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
19862237         return TRUE;
19872238
19882239      case 0x29:   /* SH - MIPS I */
19892240         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
19902241         UML_MOV(block, IREG(1), R32(RTREG));                           // mov     i1,<rtreg>
1991         UML_CALLH(block, mips3.write16);                              // callh   write16
2242         UML_CALLH(block, mips3.write16[mips3.cstate->mode >> 1]);            // callh   write16
19922243         if (!in_delay_slot)
1993            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2244            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
19942245         return TRUE;
19952246
19962247      case 0x2b:   /* SW - MIPS I */
19972248         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
19982249         UML_MOV(block, IREG(1), R32(RTREG));                           // mov     i1,<rtreg>
1999         UML_CALLH(block, mips3.write32);                              // callh   write32
2250         UML_CALLH(block, mips3.write32[mips3.cstate->mode >> 1]);            // callh   write32
20002251         if (!in_delay_slot)
2001            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2252            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
20022253         return TRUE;
20032254
20042255      case 0x3f:   /* SD - MIPS III */
20052256         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
20062257         UML_DMOV(block, IREG(1), R64(RTREG));                           // dmov    i1,<rtreg>
2007         UML_CALLH(block, mips3.write64);                              // callh   write64
2258         UML_CALLH(block, mips3.write64[mips3.cstate->mode >> 1]);            // callh   write64
20082259         if (!in_delay_slot)
2009            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2260            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
20102261         return TRUE;
20112262
20122263      case 0x2a:   /* SWL - MIPS I */
20132264         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
2014         UML_SHL(block, IREG(4), IREG(0), IMM(3));                        // shl     i4,i0,3
2265         UML_SHL(block, IREG(3), IREG(0), IMM(3));                        // shl     i3,i0,3
20152266         UML_MOV(block, IREG(1), R32(RTREG));                           // mov     i1,<rtreg>
20162267         if (!mips3.core->bigendian)
2017            UML_XOR(block, IREG(4), IREG(4), IMM(0x18));                  // xor     i4,i4,0x18
2018         UML_SHR(block, IREG(2), IMM(~0), IREG(4));                        // shr     i2,~0,i4
2019         UML_SHR(block, IREG(1), IREG(1), IREG(4));                        // shr     i1,i1,i4
2020         UML_CALLH(block, mips3.write32mask);                           // callh   write32mask
2268            UML_XOR(block, IREG(3), IREG(3), IMM(0x18));                  // xor     i3,i3,0x18
2269         UML_SHR(block, IREG(2), IMM(~0), IREG(3));                        // shr     i2,~0,i3
2270         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
20212272         if (!in_delay_slot)
2022            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2273            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
20232274         return TRUE;
20242275
20252276      case 0x2e:   /* SWR - MIPS I */
20262277         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
2027         UML_SHL(block, IREG(4), IREG(0), IMM(3));                        // shl     i4,i0,3
2278         UML_SHL(block, IREG(3), IREG(0), IMM(3));                        // shl     i3,i0,3
20282279         UML_MOV(block, IREG(1), R32(RTREG));                           // mov     i1,<rtreg>
20292280         if (mips3.core->bigendian)
2030            UML_XOR(block, IREG(4), IREG(4), IMM(0x18));                  // xor     i4,i4,0x18
2031         UML_SHL(block, IREG(2), IMM(~0), IREG(4));                        // shl     i2,~0,i4
2032         UML_SHL(block, IREG(1), IREG(1), IREG(4));                        // shl     i1,i1,i4
2033         UML_CALLH(block, mips3.write32mask);                           // callh   write32mask
2281            UML_XOR(block, IREG(3), IREG(3), IMM(0x18));                  // xor     i3,i3,0x18
2282         UML_SHL(block, IREG(2), IMM(~0), IREG(3));                        // shl     i2,~0,i3
2283         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
20342285         if (!in_delay_slot)
2035            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2286            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
20362287         return TRUE;
20372288
20382289      case 0x2c:   /* SDL - MIPS III */
20392290         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
2040         UML_SHL(block, IREG(4), IREG(0), IMM(3));                        // shl     i4,i0,3
2291         UML_SHL(block, IREG(3), IREG(0), IMM(3));                        // shl     i3,i0,3
20412292         UML_DMOV(block, IREG(1), R64(RTREG));                           // dmov    i1,<rtreg>
20422293         if (!mips3.core->bigendian)
2043            UML_XOR(block, IREG(4), IREG(4), IMM(0x38));                  // xor     i4,i4,0x38
2044         UML_DSHR(block, IREG(2), IMM((UINT64)~0), IREG(4));                  // dshr    i2,~0,i4
2045         UML_DSHR(block, IREG(1), IREG(1), IREG(4));                        // dshr    i1,i1,i4
2046         UML_CALLH(block, mips3.write64mask);                           // callh   write64mask
2294            UML_XOR(block, IREG(3), IREG(3), IMM(0x38));                  // xor     i3,i3,0x38
2295         UML_DSHR(block, IREG(2), IMM((UINT64)~0), IREG(3));                  // dshr    i2,~0,i3
2296         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
20472298         if (!in_delay_slot)
2048            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2299            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
20492300         return TRUE;
20502301
20512302      case 0x2d:   /* SDR - MIPS III */
20522303         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
2053         UML_SHL(block, IREG(4), IREG(0), IMM(3));                        // shl     i4,i0,3
2304         UML_SHL(block, IREG(3), IREG(0), IMM(3));                        // shl     i3,i0,3
20542305         UML_DMOV(block, IREG(1), R64(RTREG));                           // dmov    i1,<rtreg>
20552306         if (mips3.core->bigendian)
2056            UML_XOR(block, IREG(4), IREG(4), IMM(0x38));                  // xor     i4,i4,0x38
2057         UML_DSHL(block, IREG(2), IMM((UINT64)~0), IREG(4));                  // dshl    i2,~0,i4
2058         UML_DSHL(block, IREG(1), IREG(1), IREG(4));                        // dshl    i1,i1,i4
2059         UML_CALLH(block, mips3.write64mask);                           // callh   write64mask
2307            UML_XOR(block, IREG(3), IREG(3), IMM(0x38));                  // xor     i3,i3,0x38
2308         UML_DSHL(block, IREG(2), IMM((UINT64)~0), IREG(3));                  // dshl    i2,~0,i3
2309         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
20602311         if (!in_delay_slot)
2061            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2312            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
20622313         return TRUE;
20632314
20642315      case 0x39:   /* SWC1 - MIPS I */
20652316         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
20662317         UML_MOV(block, IREG(1), FPR32(RTREG));                           // mov     i1,<cpr1_rt>
2067         UML_CALLH(block, mips3.write32);                              // callh   write32
2318         UML_CALLH(block, mips3.write32[mips3.cstate->mode >> 1]);            // callh   write32
20682319         if (!in_delay_slot)
2069            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2320            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
20702321         return TRUE;
20712322
20722323      case 0x3d:   /* SDC1 - MIPS III */
20732324         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
20742325         UML_DMOV(block, IREG(1), FPR64(RTREG));                           // dmov    i1,<cpr1_rt>
2075         UML_CALLH(block, mips3.write64);                              // callh   write64
2326         UML_CALLH(block, mips3.write64[mips3.cstate->mode >> 1]);            // callh   write64
20762327         if (!in_delay_slot)
2077            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2328            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
20782329         return TRUE;
20792330
20802331      case 0x3a:   /* SWC2 - MIPS I */
20812332         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
20822333         UML_MOV(block, IREG(1), CPR232(RTREG));                           // mov     i1,<cpr2_rt>
2083         UML_CALLH(block, mips3.write32);                              // callh   write32
2334         UML_CALLH(block, mips3.write32[mips3.cstate->mode >> 1]);            // callh   write32
20842335         if (!in_delay_slot)
2085            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2336            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
20862337         return TRUE;
20872338
20882339      case 0x3e:   /* SDC2 - MIPS II */
20892340         UML_ADD(block, IREG(0), R32(RSREG), IMM(SIMMVAL));                  // add     i0,<rsreg>,SIMMVAL
20902341         UML_DMOV(block, IREG(1), CPR264(RTREG));                        // dmov    i1,<cpr2_rt>
2091         UML_CALLH(block, mips3.write64);                              // callh   write64
2342         UML_CALLH(block, mips3.write64[mips3.cstate->mode >> 1]);            // callh   write64
20922343         if (!in_delay_slot)
2093            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
2344            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
20942345         return TRUE;
20952346
20962347
r2724r2725
26042855
26052856static int generate_idt(drcuml_block *block, compiler_state *compiler, const opcode_desc *desc)
26062857{
2607   fatalerror("Unimplemented IDT instructions");
2608#if 0
26092858   UINT32 op = *desc->opptr.l;
26102859   UINT8 opswitch = op & 0x1f;
26112860
2861   /* only enabled on IDT processors */
2862   if (mips3.core->flavor != MIPS3_TYPE_R4650)
2863      return FALSE;
2864
26122865   switch (opswitch)
26132866   {
26142867      case 0: /* MAD */
26152868         if (RSREG != 0 && RTREG != 0)
26162869         {
2617            emit_mov_r32_m32(REG_EAX, REGADDR(RSREG));                     // mov  eax,[rsreg]
2618            emit_mov_r32_m32(REG_EDX, REGADDR(RTREG));                     // mov  edx,[rtreg]
2619            emit_imul_r32(DRCTOP, REG_EDX);                              // imul edx
2620            emit_add_r32_m32(DRCTOP, LOADDR);                           // add  eax,[lo]
2621            emit_adc_r32_m32(DRCTOP, HIADDR);                           // adc  edx,[hi]
2622            emit_mov_r32_r32(DRCTOP, REG_EBX, REG_EDX);                     // mov  ebx,edx
2623            emit_cdq(DRCTOP);                                       // cdq
2624            emit_mov_m64_r64(DRCTOP, LOADDR, REG_EAX);                     // mov  [lo],edx:eax
2625            emit_mov_r32_r32(DRCTOP, REG_EAX, REG_EBX);                     // mov  eax,ebx
2626            emit_cdq(DRCTOP);                                       // cdq
2627            emit_mov_m64_r64(DRCTOP, HIADDR, REG_EAX);                     // mov  [hi],edx:eax
2870            UML_MULS(block, IREG(0), IREG(1), R32(RSREG), R32(RTREG));         // muls   i0,i1,rsreg,rtreg
2871            UML_ADDf(block, FLAGS_C, IREG(0), IREG(0), LO32);               // add    i0,i0,lo
2872            UML_ADDC(block, IREG(1), IREG(1), HI32);                     // addc   i1,i1,hi
2873            UML_DSEXT4(block, LO64, IREG(0));                           // dsext4 lo,i0
2874            UML_DSEXT4(block, HI64, IREG(1));                           // dsext4 hi,i0
26282875         }
2629         return compile_SUCCESSFUL_CP(3,4);
2876         return TRUE;
26302877
26312878      case 1: /* MADU */
26322879         if (RSREG != 0 && RTREG != 0)
26332880         {
2634            emit_mov_r32_m32(REG_EAX, REGADDR(RSREG));                     // mov  eax,[rsreg]
2635            emit_mov_r32_m32(REG_EDX, REGADDR(RTREG));                     // mov  edx,[rtreg]
2636            emit_mul_r32(DRCTOP, REG_EDX);                              // mul  edx
2637            emit_add_r32_m32(DRCTOP, LOADDR);                           // add  eax,[lo]
2638            emit_adc_r32_m32(DRCTOP, HIADDR);                           // adc  edx,[hi]
2639            emit_mov_r32_r32(DRCTOP, REG_EBX, REG_EDX);                     // mov  ebx,edx
2640            emit_cdq(DRCTOP);                                       // cdq
2641            emit_mov_m64_r64(DRCTOP, LOADDR, REG_EDX, REG_EAX);               // mov  [lo],edx:eax
2642            emit_mov_r32_r32(DRCTOP, REG_EAX, REG_EBX);                     // mov  eax,ebx
2643            emit_cdq(DRCTOP);                                       // cdq
2644            emit_mov_m64_r64(DRCTOP, HIADDR, REG_EDX, REG_EAX);               // mov  [hi],edx:eax
2881            UML_MULU(block, IREG(0), IREG(1), R32(RSREG), R32(RTREG));         // mulu   i0,i1,rsreg,rtreg
2882            UML_ADDf(block, FLAGS_C, IREG(0), IREG(0), LO32);               // add    i0,i0,lo
2883            UML_ADDC(block, IREG(1), IREG(1), HI32);                     // addc   i1,i1,hi
2884            UML_DSEXT4(block, LO64, IREG(0));                           // dsext4 lo,i0
2885            UML_DSEXT4(block, HI64, IREG(1));                           // dsext4 hi,i0
26452886         }
2646         return compile_SUCCESSFUL_CP(3,4);
2887         return TRUE;
26472888
26482889      case 2: /* MUL */
26492890         if (RDREG != 0)
26502891         {
2651            if (RSREG != 0 && RTREG != 0)
2652            {
2653               emit_mov_r32_m32(REG_EAX, REGADDR(RSREG));                  // mov  eax,[rsreg]
2654               emit_imul_r32_m32(REG_EAX, REGADDR(RTREG));                  // imul eax,[rtreg]
2655               emit_cdq(DRCTOP);                                    // cdq
2656               emit_mov_m64_r64(REG_ESI, REGADDR(RDREG), REG_EDX, REG_EAX);   // mov  [rd],edx:eax
2657            }
2658            else
2659               emit_zero_m64(REG_ESI, REGADDR(RDREG));
2892            UML_MULS(block, IREG(0), IREG(0), R32(RSREG), R32(RTREG));         // muls   i0,i0,rsreg,rtreg
2893            UML_DSEXT4(block, R64(RDREG), IREG(0));                        // dsext4 rdreg,i0
26602894         }
2661         return compile_SUCCESSFUL_CP(3,4);
2895         return TRUE;
26622896   }
2663#endif
26642897   return FALSE;
26652898}
26662899
r2724r2725
26782911   switch (reg)
26792912   {
26802913      case COP0_Cause:
2681         UML_AND(block, IREG(0), IREG(0), IMM(~0xfc00));                     // and     i0,i0,~0xfc00
2682         UML_AND(block, IREG(1), CPR032(COP0_Cause), IMM(0xfc00));            // and     i1,[Cause],0xfc00
2683         UML_OR(block, CPR032(COP0_Cause), IREG(0), IREG(1));               // or      [Cause],i0,i1
2914         UML_INSERT(block, CPR032(COP0_Cause), IREG(0), IMM(0), IMM(~0xfc00));   // insert  [Cause],i0,0,~0xfc00
26842915         compiler->checksoftints = TRUE;
26852916         if (!in_delay_slot)
2686            generate_update_cycles(block, compiler, desc->pc + 4, NULL, TRUE);
2917            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
26872918         return TRUE;
26882919
26892920      case COP0_Status:
2690         generate_update_cycles(block, compiler, desc->pc, NULL, !in_delay_slot);// <subtract cycles>
2921         generate_update_cycles(block, compiler, IMM(desc->pc), !in_delay_slot);   // <subtract cycles>
26912922         UML_MOV(block, IREG(1), CPR032(COP0_Status));                     // mov     i1,[Status]
26922923         UML_MOV(block, CPR032(COP0_Status), IREG(0));                     // mov     [Status],i0
2693         UML_SHR(block, IREG(2), IREG(1), IMM(26));                        // shr     i2,i1,26
2694         UML_AND(block, MEM(&mips3.cstate->mode), IREG(2), IMM(1));            // and     [mode],i2,1
2924         generate_update_mode(block);
26952925         UML_XOR(block, IREG(0), IREG(0), IREG(1));                        // xor     i0,i0,i1
26962926         UML_TEST(block, IREG(0), IMM(0x8000));                           // test    i0,0x8000
26972927         UML_CALLCc(block, IF_NZ, mips3com_update_cycle_counting, mips3.core);   // callc   mips3com_update_cycle_counting,mips.core,NZ
26982928         compiler->checkints = TRUE;
26992929         if (!in_delay_slot)
2700            generate_update_cycles(block, compiler, desc->pc + 4, NULL, TRUE);
2930            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
27012931         return TRUE;
27022932
27032933      case COP0_Count:
2704         generate_update_cycles(block, compiler, desc->pc, NULL, !in_delay_slot);// <subtract cycles>
2934         generate_update_cycles(block, compiler, IMM(desc->pc), !in_delay_slot);   // <subtract cycles>
27052935         UML_MOV(block, CPR032(COP0_Count), IREG(0));                     // mov     [Count],i0
27062936         UML_CALLC(block, cfunc_get_cycles, &mips3.cstate->numcycles);         // callc   cfunc_get_cycles,&mips3.numcycles
27072937         UML_DZEXT4(block, IREG(0), IREG(0));                           // dzext4  i0,i0
r2724r2725
27122942         return TRUE;
27132943
27142944      case COP0_Compare:
2715         generate_update_cycles(block, compiler, desc->pc, NULL, !in_delay_slot);// <subtract cycles>
2945         generate_update_cycles(block, compiler, IMM(desc->pc), !in_delay_slot);   // <subtract cycles>
27162946         UML_MOV(block, CPR032(COP0_Compare), IREG(0));                     // mov     [Compare],i0
2717         UML_AND(block, CPR032(COP0_Cause), CPR032(COP0_Cause), IMM(~0x8000));   // and    [Cause],[Cause],~0x8000
2947         UML_AND(block, CPR032(COP0_Cause), CPR032(COP0_Cause), IMM(~0x8000));   // and    [Cause],[Cause],~0x8000
27182948         UML_CALLC(block, mips3com_update_cycle_counting, mips3.core);         // callc   mips3com_update_cycle_counting,mips.core
27192949         return TRUE;
27202950
r2724r2725
27222952         return TRUE;
27232953
27242954      case COP0_Config:
2725         UML_AND(block, IREG(0), IREG(0), IMM(0x0007));                     // and     i0,i0,0x0007
2726         UML_AND(block, IREG(1), CPR032(COP0_Config), IMM(~0x0007));            // and     i1,[Config],~0x0007
2727         UML_OR(block, CPR032(COP0_Config), IREG(0), IREG(1));               // or      [Config],i0,i1
2955         UML_INSERT(block, CPR032(COP0_Config), IREG(0), IMM(0), IMM(0x0007));   // insert  [Config],i0,0,0x0007
27282956         return TRUE;
27292957
27302958      case COP0_EntryHi:
r2724r2725
27562984   switch (reg)
27572985   {
27582986      case COP0_Count:
2759         generate_update_cycles(block, compiler, desc->pc, NULL, FALSE);         // <subtract cycles>
2987         generate_update_cycles(block, compiler, IMM(desc->pc), FALSE);         // <subtract cycles>
27602988         UML_CALLC(block, cfunc_get_cycles, &mips3.cstate->numcycles);         // callc   cfunc_get_cycles,&mips3.numcycles
27612989         UML_DSUB(block, IREG(0), MEM(&mips3.cstate->numcycles), MEM(&mips3.core->count_zero_time));
27622990                                                               // dsub    i0,[numcycles],[count_zero_time]
r2724r2725
27652993         return TRUE;
27662994
27672995      case COP0_Random:
2768         generate_update_cycles(block, compiler, desc->pc, NULL, FALSE);         // <subtract cycles>
2996         generate_update_cycles(block, compiler, IMM(desc->pc), FALSE);         // <subtract cycles>
27692997         UML_CALLC(block, cfunc_get_cycles, &mips3.cstate->numcycles);         // callc   cfunc_get_cycles,&mips3.numcycles
27702998         UML_DSUB(block, IREG(0), MEM(&mips3.cstate->numcycles), MEM(&mips3.core->count_zero_time));
27712999                                                               // dsub    i0,[numcycles],[count_zero_time]
r2724r2725
27973025{
27983026   UINT32 op = *desc->opptr.l;
27993027   UINT8 opswitch = RSREG;
3028   drcuml_codelabel okay;
3029   int skip;
28003030
28013031   /* generate an exception if COP0 is disabled or we are not in kernel mode */
2802   if (mips3.drcoptions & MIPS3DRC_STRICT_COP0)
2803   {
2804      drcuml_codelabel okay;
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:
28053037
2806      UML_TEST(block, CPR032(COP0_Status), IMM(SR_KSU_MASK));                  // test    [Status],SR_KSU_MASK
2807      UML_JMPc(block, IF_Z, okay = compiler->labelnum++);                     // jmp     okay,Z
2808      UML_TEST(block, CPR032(COP0_Status), IMM(SR_COP0));                     // test    [Status],SR_COP0
2809      UML_EXHc(block, IF_Z, mips3.exception[EXCEPTION_BADCOP], IMM(0));         // exh     cop,0,Z
2810      UML_LABEL(block, okay);                                       // okay:
2811   }
2812
28133038   switch (opswitch)
28143039   {
28153040      case 0x00:   /* MFCz */
r2724r2725
28303055
28313056      case 0x02:   /* CFCz */
28323057         if (RTREG != 0)
2833            UML_DSEXT4(block, R32(RTREG), CCR032(RDREG));                  // dsext4  <rtreg>,ccr0[rdreg]
3058            UML_DSEXT4(block, R64(RTREG), CCR032(RDREG));                  // dsext4  <rtreg>,ccr0[rdreg]
28343059         return TRUE;
28353060
28363061      case 0x04:   /* MTCz */
r2724r2725
28823107               return TRUE;
28833108
28843109            case 0x18:   /* ERET */
2885               UML_AND(block, CPR032(COP0_Status), CPR032(COP0_Status), IMM(~SR_EXL));
2886                                                               // and     [Status],[Status],~SR_EXL
3110               UML_MOV(block, IREG(0), CPR032(COP0_Status));               // mov     i0,[Status]
3111               UML_TEST(block, IREG(0), IMM(SR_ERL));                     // test    i0,SR_ERL
3112               UML_JMPc(block, IF_NZ, skip = compiler->labelnum++);         // jmp     skip,nz
3113               UML_AND(block, IREG(0), IREG(0), IMM(~SR_EXL));               // and     i0,i0,~SR_EXL
3114               UML_MOV(block, CPR032(COP0_Status), IREG(0));               // mov     [Status],i0
3115               generate_update_mode(block);
28873116               compiler->checkints = TRUE;
2888               generate_update_cycles(block, compiler, 0, LOPTR(&mips3.core->cpr[0][COP0_EPC]), TRUE);
3117               generate_update_cycles(block, compiler, CPR032(COP0_EPC), TRUE);// <subtract cycles>
3118               UML_HASHJMP(block, MEM(&mips3.cstate->mode), CPR032(COP0_EPC), mips3.nocode);
3119                                                               // hashjmp <mode>,[EPC],nocode
3120               UML_LABEL(block, skip);                              // skip:
3121               UML_AND(block, IREG(0), IREG(0), IMM(~SR_ERL));               // and     i0,i0,~SR_ERL
3122               UML_MOV(block, CPR032(COP0_Status), IREG(0));               // mov     [Status],i0
3123               generate_update_mode(block);
3124               compiler->checkints = TRUE;
3125               generate_update_cycles(block, compiler, CPR032(COP0_ErrorPC), TRUE);
28893126                                                               // <subtract cycles>
2890               UML_HASHJMP(block, IMM(mips3.cstate->mode), CPR032(COP0_EPC), mips3.nocode);
3127               UML_HASHJMP(block, MEM(&mips3.cstate->mode), CPR032(COP0_ErrorPC), mips3.nocode);
28913128                                                               // hashjmp <mode>,[EPC],nocode
28923129               return TRUE;
28933130
r2724r2725
32823519   {
32833520      case 0x00:      /* LWXC1 - MIPS IV */
32843521         UML_ADD(block, IREG(0), R32(RSREG), R32(RTREG));                  // add     i0,<rsreg>,<rtreg>
3285         UML_CALLH(block, mips3.read32);                                 // callh   read32
3522         UML_CALLH(block, mips3.read32[mips3.cstate->mode >> 1]);            // callh   read32
32863523         UML_MOV(block, FPR32(RDREG), IREG(0));                           // mov     <cpr1_rd>,i0
32873524         if (!in_delay_slot)
3288            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
3525            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
32893526         return TRUE;
32903527
32913528      case 0x01:      /* LDXC1 - MIPS IV */
32923529         UML_ADD(block, IREG(0), R32(RSREG), R32(RTREG));                  // add     i0,<rsreg>,<rtreg>
3293         UML_CALLH(block, mips3.read64);                                 // callh   read64
3530         UML_CALLH(block, mips3.read64[mips3.cstate->mode >> 1]);            // callh   read64
32943531         UML_DMOV(block, FPR64(RDREG), IREG(0));                           // dmov    <cpr1_rd>,i0
32953532         if (!in_delay_slot)
3296            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
3533            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
32973534         return TRUE;
32983535
32993536      case 0x08:      /* SWXC1 - MIPS IV */
33003537         UML_ADD(block, IREG(0), R32(RSREG), R32(RTREG));                  // add     i0,<rsreg>,<rtreg>
33013538         UML_MOV(block, IREG(1), FPR32(RTREG));                           // mov     i1,<cpr1_rt>
3302         UML_CALLH(block, mips3.write32);                              // callh   write32
3539         UML_CALLH(block, mips3.write32[mips3.cstate->mode >> 1]);            // callh   write32
33033540         if (!in_delay_slot)
3304            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
3541            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
33053542         return TRUE;
33063543
33073544      case 0x09:      /* SDXC1 - MIPS IV */
33083545         UML_ADD(block, IREG(0), R32(RSREG), R32(RTREG));                  // add     i0,<rsreg>,<rtreg>
33093546         UML_DMOV(block, IREG(1), FPR64(RTREG));                           // dmov    i1,<cpr1_rt>
3310         UML_CALLH(block, mips3.write64);                              // callh   write64
3547         UML_CALLH(block, mips3.write64[mips3.cstate->mode >> 1]);            // callh   write64
33113548         if (!in_delay_slot)
3312            generate_update_cycles(block, compiler, desc->pc + 4, 0, TRUE);
3549            generate_update_cycles(block, compiler, IMM(desc->pc + 4), TRUE);
33133550         return TRUE;
33143551
33153552      case 0x0f:      /* PREFX */
r2724r2725
34893726      char buffer[100];
34903727
34913728      /* disassemle the current instruction and output it to the log */
3492#if LOG_UML
3493      dasmmips3(buffer, desclist->pc, *desclist->opptr.l);
3729#if (LOG_UML || LOG_NATIVE)
3730      if (desclist->flags & OPFLAG_VIRTUAL_NOOP)
3731         strcpy(buffer, "<virtual nop>");
3732      else
3733         dasmmips3(buffer, desclist->pc, *desclist->opptr.l);
34943734#else
34953735      strcpy(buffer, "???");
34963736#endif
r2724r2725
39044144    DISASSEMBLERS
39054145***************************************************************************/
39064146
3907#if !defined(MAME_DEBUG) && (LOG_UML)
4147#if !defined(MAME_DEBUG) && (LOG_UML || LOG_NATIVE)
39084148#include "mips3dsm.c"
39094149#endif
39104150
src/emu/cpu/mips/mips3com.c
r2724r2725
8282
8383size_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)
8484{
85   int tlbindex;
86
8587   /* if no memory, return the amount needed */
8688   if (memory == NULL)
8789      return config->icache + config->dcache + (sizeof(mips->tlb_table[0]) * (1 << (MIPS3_MAX_PADDR_SHIFT - MIPS3_MIN_PAGE_SHIFT)));
8890
89   /* initialize the state */
91   /* initialize based on the config */
9092   memset(mips, 0, sizeof(*mips));
91
92   /* initialize based on the config */
9393   mips->flavor = flavor;
9494   mips->bigendian = bigendian;
9595   mips->cpu_clock = clock;
r2724r2725
109109   mips->dcache = (void *)((UINT8 *)memory + config->icache);
110110   mips->tlb_table = (void *)((UINT8 *)memory + config->dcache);
111111
112   /* initialize the TLB state */
113   for (tlbindex = 0; tlbindex < ARRAY_LENGTH(mips->tlb); tlbindex++)
114   {
115      mips3_tlb_entry *tlbent = &mips->tlb[tlbindex];
116      tlbent->page_mask = 0;
117      tlbent->entry_hi = 0xffffffff;
118      tlbent->entry_lo[0] = 0xfffffff8;
119      tlbent->entry_lo[1] = 0xfffffff8;
120   }
121
112122   /* allocate a timer for the compare interrupt */
113123   mips->compare_int_timer = timer_alloc(compare_int_callback, NULL);
114124
r2724r2725
128138   /* initialize the state */
129139   mips->pc = 0xbfc00000;
130140   mips->cpr[0][COP0_Status] = SR_BEV | SR_ERL;
141   mips->cpr[0][COP0_Wired] = 0;
131142   mips->cpr[0][COP0_Compare] = 0xffffffff;
132143   mips->cpr[0][COP0_Count] = 0;
133144   mips->cpr[0][COP0_Config] = compute_config_register(mips);
r2724r2725
202213   {
203214      mips3_tlb_entry *tlbent = &mips->tlb[index];
204215
205      /* only process if global or if the ASID matches */
206      if ((tlbent->entry_hi & 0x1000) || valid_asid == (tlbent->entry_hi & 0xff))
216      /* only process if the ASID matches or if global */
217      if (valid_asid == (tlbent->entry_hi & 0xff) || ((tlbent->entry_lo[0] & tlbent->entry_lo[1]) & TLB_GLOBAL))
207218      {
208219         UINT32 count = (tlbent->page_mask >> 13) & 0x00fff;
209220         UINT32 vpn = ((tlbent->entry_hi >> 13) & 0x07ffffff) << 1;
r2724r2725
216227            for (which = 0; which < 2; which++)
217228            {
218229               UINT64 lo = tlbent->entry_lo[which];
230               UINT32 pfn = (lo >> 6) & 0x00ffffff;
231               UINT32 wp = (lo & 7) | TLB_PRESENT;
219232
220               /* only map if the TLB entry is valid */
221               if (lo & 2)
222               {
223                  UINT32 pfn = (lo >> 6) & 0x00ffffff;
224                  UINT32 wp = (~lo >> 2) & 1;
233               /* ensure that if the valid bit is clear, the dirty bit is as well */
234               /* this way we can always test dirty for writes, and valid for reads */
235               if (!(wp & TLB_VALID))
236                  wp &= ~TLB_DIRTY;
225237
226                  for (i = 0; i <= count; i++, vpn++, pfn++)
227                     if (vpn < 0x80000 || vpn >= 0xc0000)
228                        mips->tlb_table[vpn] = (pfn << MIPS3_MIN_PAGE_SHIFT) | wp;
229               }
230
231               /* otherwise, advance by the number of pages we would have mapped */
232               else
233                  vpn += count + 1;
238               for (i = 0; i <= count; i++, vpn++, pfn++)
239                  if (vpn < 0x80000 || vpn >= 0xc0000)
240                     mips->tlb_table[vpn] = (pfn << MIPS3_MIN_PAGE_SHIFT) | wp;
234241            }
235242      }
236243   }
r2724r2725
261268         for (which = 0; which < 2; which++)
262269            for (i = 0; i <= count; i++, vpn++)
263270               if (vpn < 0x80000 || vpn >= 0xc0000)
264                  mips->tlb_table[vpn] = 0xffffffff;
271                  mips->tlb_table[vpn] = 0;
265272   }
266273}
267274
r2724r2725
277284
278285   /* map in the hard-coded spaces */
279286   for (addr = 0x80000000; addr < 0xc0000000; addr += MIPS3_MIN_PAGE_SIZE)
280      mips->tlb_table[addr >> MIPS3_MIN_PAGE_SHIFT] = addr & 0x1ffff000;
287      mips->tlb_table[addr >> MIPS3_MIN_PAGE_SHIFT] = (addr & 0x1ffff000) | TLB_PRESENT | TLB_DIRTY | TLB_VALID | TLB_GLOBAL;
281288
282289   /* reset everything else to unmapped */
283   memset(&mips->tlb_table[0x00000000 >> MIPS3_MIN_PAGE_SHIFT], 0xff, sizeof(mips->tlb_table[0]) * (0x80000000 >> MIPS3_MIN_PAGE_SHIFT));
284   memset(&mips->tlb_table[0xc0000000 >> MIPS3_MIN_PAGE_SHIFT], 0xff, sizeof(mips->tlb_table[0]) * (0x40000000 >> MIPS3_MIN_PAGE_SHIFT));
290   memset(&mips->tlb_table[0x00000000 >> MIPS3_MIN_PAGE_SHIFT], 0, sizeof(mips->tlb_table[0]) * (0x80000000 >> MIPS3_MIN_PAGE_SHIFT));
291   memset(&mips->tlb_table[0xc0000000 >> MIPS3_MIN_PAGE_SHIFT], 0, sizeof(mips->tlb_table[0]) * (0x40000000 >> MIPS3_MIN_PAGE_SHIFT));
285292
286293   /* remap all the entries in the TLB */
287294   mips3com_map_tlb_entries(mips);
r2724r2725
299306   if (space == ADDRESS_SPACE_PROGRAM)
300307   {
301308      UINT32 result = mips->tlb_table[*address >> MIPS3_MIN_PAGE_SHIFT];
302      if (result == 0xffffffff)
309      if (!(result & TLB_PRESENT) || !(result & TLB_VALID))
303310         return FALSE;
304311      *address = (result & ~MIPS3_MIN_PAGE_MASK) | (*address & MIPS3_MIN_PAGE_MASK);
305312   }
r2724r2725
378385      if ((tlbent->entry_hi & mask) == (mips->cpr[0][COP0_EntryHi] & mask))
379386
380387         /* and if we are either global or matching the current ASID, then stop */
381         if ((tlbent->entry_hi & 0x1000) || (tlbent->entry_hi & 0xff) == (mips->cpr[0][COP0_EntryHi] & 0xff))
388         if ((tlbent->entry_hi & 0xff) == (mips->cpr[0][COP0_EntryHi] & 0xff) || ((tlbent->entry_lo[0] & tlbent->entry_lo[1]) & TLB_GLOBAL))
382389            break;
383390   }
384391
r2724r2725
386393   vpn = ((mips->cpr[0][COP0_EntryHi] >> 13) & 0x07ffffff) << 1;
387394   if (index != ARRAY_LENGTH(mips->tlb))
388395   {
389      /* we can't assert this because the TLB entry may not be valid */
390      /* assert(mips->tlb_table[vpn & 0xfffff] != 0xffffffff); */
396      assert(mips->tlb_table[vpn & 0xfffff] & TLB_PRESENT);
391397      mips->cpr[0][COP0_Index] = index;
392398   }
393399   else
394400   {
395      assert(mips->tlb_table[vpn & 0xfffff] == 0xffffffff);
401      assert(!(mips->tlb_table[vpn & 0xfffff] & TLB_PRESENT));
396402      mips->cpr[0][COP0_Index] = 0x80000000;
397403   }
398404}
r2724r2725
920926
921927   mame_printf_debug("index=%08X  pagesize=%08X  vaddr=%08X%08X  paddr=%08X%08X  asid=%02X  r=%X  c=%X  dvg=%c%c%c\n",
922928         index, pagesize, (UINT32)(vaddr >> 32), (UINT32)vaddr, (UINT32)(paddr >> 32), (UINT32)paddr,
923         asid, r, c, (lo & 4) ? 'd' : '.', (lo & 2) ? 'v' : '.', (hi & 0x1000) ? 'g' : '.');
929         asid, r, c, (lo & 4) ? 'd' : '.', (lo & 2) ? 'v' : '.', (lo & 1) ? 'g' : '.');
924930#endif
925931}
src/emu/cpu/mips/mips3.c
r2724r2725
1010***************************************************************************/
1111
1212#include "debugger.h"
13#include "deprecat.h"
1413#include "mips3com.h"
1514
1615
src/emu/cpu/drcbeut.c
r2724r2725
1414
1515
1616/***************************************************************************
17    DEBUGGING
18***************************************************************************/
19
20#define LOG_RECOVER         (0)
21
22
23/***************************************************************************
1724    TYPE DEFINITIONS
1825***************************************************************************/
1926
r2724r2725
308315   /* reset the tailptr and count */
309316   drcmap->tailptr = &drcmap->head;
310317   drcmap->numvalues = 0;
318
319   /* reset the variable values */
320   memset(drcmap->mapvalue, 0, sizeof(drcmap->mapvalue));
311321}
312322
313323
r2724r2725
317327
318328void drcmap_block_end(drcmap_state *drcmap, drcuml_block *block)
319329{
320   UINT32 curvalue[DRCUML_MAPVAR_END - DRCUML_MAPVAR_M0];
321   UINT8 changed[DRCUML_MAPVAR_END - DRCUML_MAPVAR_M0];
330   UINT32 curvalue[DRCUML_MAPVAR_END - DRCUML_MAPVAR_M0] = { 0 };
331   UINT8 changed[DRCUML_MAPVAR_END - DRCUML_MAPVAR_M0] = { 0 };
322332   drcmap_entry *entry;
323333   drccodeptr lastptr;
324334   drccodeptr *top;
r2724r2725
343353   *dest = (drccodeptr)dest - lastptr;
344354   dest++;
345355
346   /* reset the current values */
347   memset(curvalue, 0, sizeof(curvalue));
348   memset(changed, 0, sizeof(changed));
349
350356   /* now iterate over entries and store them */
351357   for (entry = drcmap->head; entry != NULL; entry = entry->next)
352358   {
r2724r2725
503509      /* low 4 bits contain the total number of words of data */
504510      data += controlword & 0x0f;
505511   }
512   if (LOG_RECOVER)
513      printf("recover %d @ %p = %08X\n", mapvar, codebase, result);
506514   return result;
507515}
508516
src/emu/cpu/drcumld.c
r2724r2725
8989   { DRCUML_OP_SETFMOD,   "setfmod",   { output_param } },
9090   { DRCUML_OP_GETFMOD,   "getfmod",   { output_param } },
9191   { DRCUML_OP_GETEXP,      "getexp",   { output_param } },
92   { DRCUML_OP_SAVE,      "save",      { output_param } },
93   { DRCUML_OP_RESTORE,   "restore",   { output_param } },
9294
9395   /* Integer Operations */
9496   { DRCUML_OP_LOAD1U,      "!load1u",   { output_param, output_param, output_param } },
r2724r2725
127129   { DRCUML_OP_SEXT1,      "!sext1",   { output_param, output_param } },
128130   { DRCUML_OP_SEXT2,      "!sext2",   { output_param, output_param } },
129131   { DRCUML_OP_SEXT4,      "!sext4",   { output_param, output_param } },
132   { DRCUML_OP_XTRACT,      "!xtract",   { output_param, output_param, output_param, output_param } },
133   { DRCUML_OP_INSERT,      "!insert",   { output_param, output_param, output_param, output_param } },
130134   { DRCUML_OP_ADD,      "!add",      { output_param, output_param, output_param, output_flags } },
131135   { DRCUML_OP_ADDC,      "!addc",   { output_param, output_param, output_param, output_flags } },
132136   { DRCUML_OP_SUB,      "!sub",      { output_param, output_param, output_param, output_flags } },
r2724r2725
140144   { DRCUML_OP_TEST,      "!test",   { output_param, output_param, output_flags_cmptest } },
141145   { DRCUML_OP_OR,         "!or",      { output_param, output_param, output_param, output_flags } },
142146   { DRCUML_OP_XOR,      "!xor",      { output_param, output_param, output_param, output_flags } },
147   { DRCUML_OP_LZCNT,      "!lzcnt",   { output_param, output_param } },
143148   { DRCUML_OP_SHL,      "!shl",      { output_param, output_param, output_param, output_flags } },
144149   { DRCUML_OP_SHR,      "!shr",      { output_param, output_param, output_param, output_flags } },
145150   { DRCUML_OP_SAR,      "!sar",      { output_param, output_param, output_param, output_flags } },
src/emu/cpu/drcbeut.h
r2724r2725
5757};
5858
5959
60/* an integer register, with low/high parts */
61typedef union _drcuml_ireg drcuml_ireg;
62union _drcuml_ireg
63{
64#ifdef LSB_FIRST
65   UINT32         l,h;            /* 32-bit low, high parts of the register */
66#else
67   UINT32         h,l;            /* 32-bit low, high parts of the register */
68#endif
69   UINT64         d;               /* 64-bit full register */
70};
7160
72
73/* an floating-point register, with low/high parts */
74typedef union _drcuml_freg drcuml_freg;
75union _drcuml_freg
76{
77#ifdef LSB_FIRST
78   float         l,unused;         /* 32-bit low, high parts of the register */
79#else
80   float         unused,l;         /* 32-bit low, high parts of the register */
81#endif
82   double         d;               /* 64-bit full register */
83};
84
85
86/* the collected machine state of a system */
87typedef struct _drcuml_machine_state drcuml_machine_state;
88struct _drcuml_machine_state
89{
90   drcuml_ireg      r[DRCUML_REG_I_END - DRCUML_REG_I0];   /* integer registers */
91   drcuml_freg      f[DRCUML_REG_F_END - DRCUML_REG_F0];   /* floating-point registers */
92   drcuml_ireg      exp;                           /* exception parameter register */
93   UINT8         fmod;                           /* fmod (floating-point mode) register */
94};
95
96
97
9861/***************************************************************************
9962    FUNCTION PROTOTYPES
10063***************************************************************************/
src/emu/cpu/x86emit.h
r2724r2725
518518#define OP_INVD               0x0f08
519519#define OP_WBINVD            0x0f09
520520#define OP_UD2               0x0f0b
521#define OP_NOP0d_Ev            0x0f0d
521522
522523#define OP_MOVUPS_Vps_Wps      0x0f10
523524#define OP_MOVSS_Vss_Wss      0xf30f10
r2724r2725
545546#define OP_MOVHPS_Mq_Vq         0x0f17
546547#define OP_MOVHPD_Mq_Vq         0x660f17
547548#define OP_PREFETCH_G16         0x0f18
549#define OP_NOP1f_Ev            0x0f1f
548550
549551#define OP_MOV_Rd_Cd         0x0f20
550552#define OP_MOV_Rd_Dd         0x0f21
r2724r2725
579581#define OP_RDPMC            0x0f33
580582#define OP_SYSENTER            0x0f34
581583#define OP_SYSEXIT            0x0f35
584#define OP_GETSEC            0x0f37
582585
583586#define OP_CMOV_O_Gv_Ev         0x0f40
584587#define OP_CMOV_NO_Gv_Ev      0x0f41
r2724r2725
703706#define OP_PCMPEQD_Pq_Qq      0x0f76
704707#define OP_PCMPEQD_Vdq_Wdq      0x660f76
705708#define OP_EMMS               0x0f77
709#define OP_VMREAD_Ed_Gd         0x0f78
710#define OP_VMWRITE_Gd_Ed      0x0f79
706711#define OP_HADDPD_Vpd_Wpd      0x660f7c
707712#define OP_HADDPS_Vps_Wps      0xf20f7c
708713#define OP_HSUBPD_Vpd_Wpd      0x660f7d
r2724r2725
799804#define OP_LGS_Mp            0x0fb5
800805#define OP_MOVZX_Gv_Eb         (0x0fb6 | OPFLAG_8BITRM)
801806#define OP_MOVZX_Gv_Ew         0x0fb7
807#define OP_JMPE               0x0fb8
808#define OP_POPCNT_Gv_Ev         0xf30fb8
802809#define OP_G10_INVALID         0x0fb9
803810#define OP_G8_Ev_Ib            0x0fba
804811#define OP_BTC_Ev_Gv         0x0fbb
r2724r2725
929936#define OP_PADDD_Vdq_Wdq      0x660ffe
930937
931938
939/* triple byte opcodes (0f 38) */
940#define OP_PSHUFB_Pq_Qq         0x0f3800
941#define OP_PSHUFB_Vdq_Wdq      0x660f3800
942#define OP_PHADDW_Pq_Qq         0x0f3801
943#define OP_PHADDW_Vdq_Wdq      0x660f3801
944#define OP_PHADDD_Pq_Qq         0x0f3802
945#define OP_PHADDD_Vdq_Wdq      0x660f3802
946#define OP_PHADDSW_Pq_Qq      0x0f3803
947#define OP_PHADDSW_Vdq_Wdq      0x660f3803
948#define OP_PMADDUBSW_Pq_Qq      0x0f3804
949#define OP_PMADDUBSW_Vdq_Wdq   0x660f3804
950#define OP_PHSUBW_Pq_Qq         0x0f3805
951#define OP_PHSUBW_Vdq_Wdq      0x660f3805
952#define OP_PHSUBD_Pq_Qq         0x0f3806
953#define OP_PHSUBD_Vdq_Wdq      0x660f3806
954#define OP_PHSUBSW_Pq_Qq      0x0f3807
955#define OP_PHSUBSW_Vdq_Wdq      0x660f3807
956#define OP_PSIGNB_Pq_Qq         0x0f3808
957#define OP_PSIGNB_Vdq_Wdq      0x660f3808
958#define OP_PSIGNW_Pq_Qq         0x0f3809
959#define OP_PSIGNW_Vdq_Wdq      0x660f3809
960#define OP_PSIGND_Pq_Qq         0x0f380a
961#define OP_PSIGND_Vdq_Wdq      0x660f380a
962#define OP_PMULHRSW_Pq_Qq      0x0f380b
963#define OP_PMULHRSW_Vdq_Wdq      0x660f380b
964
965#define OP_PBLENDVB_Vdq_Wdq      0x660f3810
966#define OP_PBLENDVPS_Vdq_Wdq   0x660f3814
967#define OP_PBLENDVPD_Vdq_Wdq   0x660f3815
968#define OP_PTEST_Vdq_Wdq      0x660f3817
969#define OP_PABSB_Pq_Qq         0x0f381c
970#define OP_PABSB_Vdq_Wdq      0x660f381c
971#define OP_PABSW_Pq_Qq         0x0f381d
972#define OP_PABSW_Vdq_Wdq      0x660f381d
973#define OP_PABSD_Pq_Qq         0x0f381e
974#define OP_PABSD_Vdq_Wdq      0x660f381e
975
976#define OP_PMOVSXBW_Vdq_Udq      0x660f3820
977#define OP_PMOVSXBD_Vdq_Udq      0x660f3821
978#define OP_PMOVSXBQ_Vdq_Udq      0x660f3822
979#define OP_PMOVSXWD_Vdq_Udq      0x660f3823
980#define OP_PMOVSXWQ_Vdq_Udq      0x660f3824
981#define OP_PMOVSXDQ_Vdq_Udq      0x660f3825
982#define OP_PMULDQ_Vdq_Udq      0x660f3828
983#define OP_PCMPEQQ_Vdq_Udq      0x660f3829
984#define OP_MOVNTDQA_Vdq_Udq      0x660f382a
985#define OP_PACKUSDW_Vdq_Udq      0x660f382b
986
987#define OP_PMOVZXBW_Vdq_Udq      0x660f3830
988#define OP_PMOVZXBD_Vdq_Udq      0x660f3831
989#define OP_PMOVZXBQ_Vdq_Udq      0x660f3832
990#define OP_PMOVZXWD_Vdq_Udq      0x660f3833
991#define OP_PMOVZXWQ_Vdq_Udq      0x660f3834
992#define OP_PMOVZXDQ_Vdq_Udq      0x660f3835
993#define OP_PMINSB_Vdq_Udq      0x660f3838
994#define OP_PMINSD_Vdq_Udq      0x660f3839
995#define OP_PMINUW_Vdq_Udq      0x660f383a
996#define OP_PMINUD_Vdq_Udq      0x660f383b
997#define OP_PMAXSB_Vdq_Udq      0x660f383c
998#define OP_PMAXSD_Vdq_Udq      0x660f383d
999#define OP_PMAXUW_Vdq_Udq      0x660f383e
1000#define OP_PMAXUD_Vdq_Udq      0x660f383f
1001
1002#define OP_MULLD_Vdq_Wdq      0x660f3840
1003#define OP_PHMINPOSUW_Vdq_Wdq   0x660f3841
1004
1005#define OP_NVEPT_Gd_Mdq         0x660f3880
1006#define OP_NVVPID_Gd_Mdq      0x660f3881
1007
1008#define OP_MOVBE_Gv_Mv         0x0f38f0
1009#define OP_CRC32_Gd_Eb         0xf20f38f0
1010#define OP_MOVBE_Mv_Gv         0x0f38f1
1011#define OP_CRC32_Gd_Ev         0xf20f38f1
1012
1013
1014/* triple byte opcodes (0f 3a) */
1015#define OP_ROUNDPS_Vdq_Wdq_Ib   0x660f3a08
1016#define OP_ROUNDPD_Vdq_Wdq_Ib   0x660f3a09
1017#define OP_ROUNDSS_Vss_Wss_Ib   0x660f3a0a
1018#define OP_ROUNDSD_Vsd_Wsd_Ib   0x660f3a0b
1019#define OP_BLENDPS_Vdq_Wdq_Ib   0x660f3a0c
1020#define OP_BLENDPD_Vdq_Wdq_Ib   0x660f3a0d
1021#define OP_PBLENDW_Vdq_Wdq_Ib   0x660f3a0e
1022#define OP_PALIGNR_Pq_Qq_Ib      0x0f3a0f
1023#define OP_PALIGNR_Vdq_Wdq_Ib   0x660f3a0f
1024
1025#define OP_EXTRB_Rd_Vdq_Ib      0x660f3a14
1026#define OP_EXTRW_Rd_Vdq_Ib      0x660f3a15
1027#define OP_EXTRD_Rd_Vdq_Ib      0x660f3a16
1028#define OP_EXTRACTPS_Ed_Vdq_Ib   0x660f3a17
1029
1030#define OP_PINSRB_Vdq_Rd_Ib      0x660f3a20
1031#define OP_INSERTPS_Vdq_Udq_Ib   0x660f3a21
1032#define OP_PINSRD_Vdq_Ed_Ib      0x660f3a22
1033
1034#define OP_DPPS_Vdq_Wdq_Ib      0x660f3a40
1035#define OP_DPPD_Vdq_Wdq_Ib      0x660f3a41
1036#define OP_MPSADBW_Vdq_Wdq_Ib   0x660f3a42
1037
1038#define OP_PCMPESTRM_Vdq_Wdq_Ib   0x660f3a60
1039#define OP_PCMPESTRI_Vdq_Wdq_Ib   0x660f3a61
1040#define OP_PCMPISTRM_Vdq_Wdq_Ib   0x660f3a62
1041#define OP_PCMPISTRI_Vdq_Wdq_Ib   0x660f3a63
1042
1043
9321044/* floating point opcodes */
9331045#define OP_FADD_ST0_STn         0xd8c0
9341046#define OP_FMUL_ST0_STn         0xd8c8
r2724r2725
14591571INLINE void emit_cmc(x86code **emitptr)    { emit_op_simple(emitptr, OP_CMC, OP_32BIT); }
14601572INLINE void emit_pushf(x86code **emitptr)  { emit_op_simple(emitptr, OP_PUSHF_Fv, OP_32BIT); }
14611573INLINE void emit_popf(x86code **emitptr)   { emit_op_simple(emitptr, OP_POPF_Fv, OP_32BIT); }
1574INLINE void emit_cpuid(x86code **emitptr)  { emit_op_simple(emitptr, OP_CPUID, OP_32BIT); }
14621575
14631576#ifndef PTR64
14641577INLINE void emit_pushad(x86code **emitptr) { emit_op_simple(emitptr, OP_PUSHA, OP_32BIT); }
r2724r2725
28542967INLINE void emit_cvttss2si_r64_m32(x86code **emitptr, UINT8 dreg, DECLARE_MEMPARAMS)   { emit_op_modrm_mem(emitptr, OP_CVTTSS2SI_Gd_Wss, OP_64BIT, dreg, MEMPARAMS); }
28552968#endif
28562969
2970INLINE void emit_roundss_r128_r128_imm(x86code **emitptr, UINT8 dreg, UINT8 sreg, UINT8 imm)      { emit_op_modrm_reg(emitptr, OP_ROUNDSS_Vss_Wss_Ib, OP_32BIT, dreg, sreg); emit_byte(emitptr, imm); }
2971INLINE void emit_roundss_r128_m32_imm(x86code **emitptr, UINT8 dreg, DECLARE_MEMPARAMS, UINT8 imm)   { emit_op_modrm_mem(emitptr, OP_ROUNDSS_Vss_Wss_Ib, OP_32BIT, dreg, MEMPARAMS); emit_byte(emitptr, imm); }
28572972
28582973
2974
28592975/***************************************************************************
28602976    SSE PACKED SINGLE EMITTERS
28612977***************************************************************************/
r2724r2725
29093025INLINE void emit_cvttps2dq_r128_r128(x86code **emitptr, UINT8 dreg, UINT8 sreg)         { emit_op_modrm_reg(emitptr, OP_CVTTPS2DQ_Vdq_Wps, OP_32BIT, dreg, sreg); }
29103026INLINE void emit_cvttps2dq_r128_m128(x86code **emitptr, UINT8 dreg, DECLARE_MEMPARAMS)    { emit_op_modrm_mem(emitptr, OP_CVTTPS2DQ_Vdq_Wps, OP_32BIT, dreg, MEMPARAMS); }
29113027
3028INLINE void emit_roundps_r128_r128_imm(x86code **emitptr, UINT8 dreg, UINT8 sreg, UINT8 imm)      { emit_op_modrm_reg(emitptr, OP_ROUNDPS_Vdq_Wdq_Ib, OP_32BIT, dreg, sreg); emit_byte(emitptr, imm); }
3029INLINE void emit_roundps_r128_m128_imm(x86code **emitptr, UINT8 dreg, DECLARE_MEMPARAMS, UINT8 imm)   { emit_op_modrm_mem(emitptr, OP_ROUNDPS_Vdq_Wdq_Ib, OP_32BIT, dreg, MEMPARAMS); emit_byte(emitptr, imm); }
29123030
29133031
3032
29143033/***************************************************************************
29153034    SSE SCALAR DOUBLE EMITTERS
29163035***************************************************************************/
r2724r2725
29673086INLINE void emit_cvttsd2si_r64_m64(x86code **emitptr, UINT8 dreg, DECLARE_MEMPARAMS)   { emit_op_modrm_mem(emitptr, OP_CVTTSD2SI_Gd_Wsd, OP_64BIT, dreg, MEMPARAMS); }
29683087#endif
29693088
3089INLINE void emit_roundsd_r128_r128_imm(x86code **emitptr, UINT8 dreg, UINT8 sreg, UINT8 imm)      { emit_op_modrm_reg(emitptr, OP_ROUNDSD_Vsd_Wsd_Ib, OP_32BIT, dreg, sreg); emit_byte(emitptr, imm); }
3090INLINE void emit_roundsd_r128_m64_imm(x86code **emitptr, UINT8 dreg, DECLARE_MEMPARAMS, UINT8 imm)   { emit_op_modrm_mem(emitptr, OP_ROUNDSD_Vsd_Wsd_Ib, OP_32BIT, dreg, MEMPARAMS); emit_byte(emitptr, imm); }
29703091
29713092
3093
29723094/***************************************************************************
29733095    SSE PACKED DOUBLE EMITTERS
29743096***************************************************************************/
r2724r2725
30163138INLINE void emit_cvttpd2dq_r128_r128(x86code **emitptr, UINT8 dreg, UINT8 sreg)         { emit_op_modrm_reg(emitptr, OP_CVTTPD2DQ_Vdq_Wpd, OP_32BIT, dreg, sreg); }
30173139INLINE void emit_cvttpd2dq_r128_m128(x86code **emitptr, UINT8 dreg, DECLARE_MEMPARAMS)    { emit_op_modrm_mem(emitptr, OP_CVTTPD2DQ_Vdq_Wpd, OP_32BIT, dreg, MEMPARAMS); }
30183140
3141INLINE void emit_roundpd_r128_r128_imm(x86code **emitptr, UINT8 dreg, UINT8 sreg, UINT8 imm)      { emit_op_modrm_reg(emitptr, OP_ROUNDPD_Vdq_Wdq_Ib, OP_32BIT, dreg, sreg); emit_byte(emitptr, imm); }
3142INLINE void emit_roundpd_r128_m128_imm(x86code **emitptr, UINT8 dreg, DECLARE_MEMPARAMS, UINT8 imm) { emit_op_modrm_mem(emitptr, OP_ROUNDPD_Vdq_Wdq_Ib, OP_32BIT, dreg, MEMPARAMS); emit_byte(emitptr, imm); }
3143
30193144#endif
src/emu/cpu/drcbex86.c
r2724r2725
7878#include "drcbeut.h"
7979#include "debugger.h"
8080#include "x86emit.h"
81#include "eminline.h"
8182#undef REG_SP
8283#include "x86log.h"
8384#include <math.h>
85#include <stddef.h>
8486
8587
8688
r2724r2725
155157   UINT32 *            reghi[REG_MAX];         /* pointer to high part of data for each register */
156158   double               fptemp;               /* temporary storage for floating point */
157159
160   UINT8               sse3;               /* do we have SSE3 support? */
158161   UINT16               fpumode;            /* saved FPU mode */
159162   UINT16               fmodesave;            /* temporary location for saving */
160163
r2724r2725
179182static int drcbex86_execute(drcbe_state *drcbe, drcuml_codehandle *entry);
180183static void drcbex86_generate(drcbe_state *drcbe, drcuml_block *block, const drcuml_instruction *instlist, UINT32 numinst);
181184static int drcbex86_hash_exists(drcbe_state *drcbe, UINT32 mode, UINT32 pc);
185static void drcbex86_get_info(drcbe_state *state, drcbe_info *info);
182186
183187/* private helper functions */
184188static void fixup_label(void *parameter, drccodeptr labelcodeptr);
r2724r2725
203207   drcbex86_reset,
204208   drcbex86_execute,
205209   drcbex86_generate,
206   drcbex86_hash_exists
210   drcbex86_hash_exists,
211   drcbex86_get_info
207212};
208213
209214/* opcode table */
r2724r2725
220225
221226/* flags mapping tables */
222227static UINT8 flags_map[0x1000];
228static UINT32 flags_unmap[0x20];
223229
224230/* condition mapping table */
225231static UINT8 condition_map[DRCUML_COND_MAX - DRCUML_COND_Z] =
r2724r2725
276282static x86code *op_setfmod(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
277283static x86code *op_getfmod(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
278284static x86code *op_getexp(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
285static x86code *op_save(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
286static x86code *op_restore(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
279287
280288static x86code *op_load1u(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
281289static x86code *op_load1s(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
r2724r2725
313321static x86code *op_sext1(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
314322static x86code *op_sext2(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
315323static x86code *op_sext4(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
324static x86code *op_xtract(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
325static x86code *op_insert(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
316326static x86code *op_add(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
317327static x86code *op_addc(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
318328static x86code *op_sub(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
r2724r2725
326336static x86code *op_test(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
327337static x86code *op_or(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
328338static x86code *op_xor(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
339static x86code *op_lzcnt(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
329340static x86code *op_shl(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
330341static x86code *op_shr(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
331342static x86code *op_sar(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst);
r2724r2725
388399   { DRCUML_OP_SETFMOD, op_setfmod },   /* SETFMOD src                    */
389400   { DRCUML_OP_GETFMOD, op_getfmod },   /* GETFMOD dst                    */
390401   { DRCUML_OP_GETEXP,  op_getexp },   /* GETEXP  dst,index              */
402   { DRCUML_OP_SAVE,    op_save },      /* SAVE    dst,index              */
403   { DRCUML_OP_RESTORE, op_restore },   /* RESTORE dst,index              */
391404
392405   /* Integer Operations */
393406   { DRCUML_OP_LOAD1U,  op_load1u },   /* LOAD1U  dst,base,index         */
r2724r2725
426439   { DRCUML_OP_SEXT1,   op_sext1 },   /* SEXT1   dst,src                */
427440   { DRCUML_OP_SEXT2,   op_sext2 },   /* SEXT2   dst,src                */
428441   { DRCUML_OP_SEXT4,   op_sext4 },   /* SEXT4   dst,src                */
442   { DRCUML_OP_XTRACT,  op_xtract },   /* XTRACT  dst,src1,src2,src3     */
443   { DRCUML_OP_INSERT,  op_insert },   /* INSERT  dst,src1,src2,src3     */
429444   { DRCUML_OP_ADD,     op_add },      /* ADD     dst,src1,src2[,f]      */
430445   { DRCUML_OP_ADDC,    op_addc },      /* ADDC    dst,src1,src2[,f]      */
431446   { DRCUML_OP_SUB,     op_sub },      /* SUB     dst,src1,src2[,f]      */
r2724r2725
439454   { DRCUML_OP_TEST,    op_test },      /* TEST    src1,src2[,f]          */
440455   { DRCUML_OP_OR,      op_or },      /* OR      dst,src1,src2[,f]      */
441456   { DRCUML_OP_XOR,     op_xor },      /* XOR     dst,src1,src2[,f]      */
457   { DRCUML_OP_LZCNT,   op_lzcnt },   /* LZCNT   dst,src                */
442458   { DRCUML_OP_SHL,     op_shl },      /* SHL     dst,src,count[,f]      */
443459   { DRCUML_OP_SHR,     op_shr },      /* SHR     dst,src,count[,f]      */
444460   { DRCUML_OP_SAR,     op_sar },      /* SAR     dst,src,count[,f]      */
r2724r2725
500516
501517
502518/*-------------------------------------------------
519    param_select_register2 - select a register
520    to use, avoiding conflicts with the optional
521    checkparam
522-------------------------------------------------*/
523
524INLINE int param_select_register2(int defreg, const drcuml_parameter *param, const drcuml_parameter *checkparam1, const drcuml_parameter *checkparam2)
525{
526   if (param->type == DRCUML_PTYPE_INT_REGISTER && (param->type != checkparam1->type || param->value != checkparam1->value) && (param->type != checkparam2->type || param->value != checkparam2->value))
527      return param->value;
528   return defreg;
529}
530
531
532/*-------------------------------------------------
503533    emit_combine_z_flags - combine the Z flag from
504534    two 32-bit operations
505535-------------------------------------------------*/
r2724r2725
589619      if (entry & 0x800) flags |= DRCUML_FLAG_V;
590620      flags_map[entry] = flags;
591621   }
622   for (entry = 0; entry < ARRAY_LENGTH(flags_unmap); entry++)
623   {
624      UINT32 flags = 0;
625      if (entry & DRCUML_FLAG_C) flags |= 0x001;
626      if (entry & DRCUML_FLAG_U) flags |= 0x004;
627      if (entry & DRCUML_FLAG_Z) flags |= 0x040;
628      if (entry & DRCUML_FLAG_S) flags |= 0x080;
629      if (entry & DRCUML_FLAG_V) flags |= 0x800;
630      flags_unmap[entry] = flags;
631   }
592632
593633   /* compute hi pointers for each register */
594634   for (regnum = 0; regnum < ARRAY_LENGTH(int_register_map); regnum++)
595635      if (int_register_map[regnum] != 0)
596636      {
597         drcbe->reglo[int_register_map[regnum]] = &drcbe->state.r[regnum].l;
598         drcbe->reghi[int_register_map[regnum]] = &drcbe->state.r[regnum].h;
637         drcbe->reglo[int_register_map[regnum]] = &drcbe->state.r[regnum].w.l;
638         drcbe->reghi[int_register_map[regnum]] = &drcbe->state.r[regnum].w.h;
599639      }
600640
601641   /* create the log */
r2724r2725
624664
625665static void drcbex86_reset(drcbe_state *drcbe)
626666{
667   UINT32 (*cpuid_ecx_stub)(void);
627668   x86code **dst;
628669
629670   /* output a note to the log */
r2724r2725
635676   if (dst == NULL)
636677      fatalerror("Out of cache space after a reset!");
637678
679   /* generate a simple CPUID stub */
680   cpuid_ecx_stub = (UINT32 (*)(void))*dst;
681   emit_push_r32(dst, REG_EBX);                                          // push  ebx
682   emit_mov_r32_imm(dst, REG_EAX, 1);                                       // mov   eax,1
683   emit_cpuid(dst);                                                   // cpuid
684   emit_mov_r32_r32(dst, REG_EAX, REG_ECX);                                 // mov   eax,ecx
685   emit_pop_r32(dst, REG_EBX);                                             // pop   ebx
686   emit_ret(dst);                                                      // ret
687
688   /* call it to determine if we have SSE3 support */
689   drcbe->sse3 = (((*cpuid_ecx_stub)() & 1) != 0);
690
638691   /* generate an entry point */
639692   drcbe->entry = (x86_entry_point_func)*dst;
640693   emit_mov_r32_m32(dst, REG_EAX, MBD(REG_ESP, 4));                           // mov   eax,[esp+4]
r2724r2725
678731
679732
680733/*-------------------------------------------------
734    drcbex86_execute - execute a block of code
735    referenced by the given handle
736-------------------------------------------------*/
737
738static int drcbex86_execute(drcbe_state *drcbe, drcuml_codehandle *entry)
739{
740   /* call our entry point which will jump to the destination */
741   return (*drcbe->entry)((x86code *)drcuml_handle_codeptr(entry));
742}
743
744
745/*-------------------------------------------------
681746    drcbex86_generate - generate code
682747-------------------------------------------------*/
683748
r2724r2725
761826
762827
763828/*-------------------------------------------------
764    drcbec_execute - execute a block of code
765    registered at the given mode/pc
829    drcbex86_get_info - return information about
830    the back-end implementation
766831-------------------------------------------------*/
767832
768static int drcbex86_execute(drcbe_state *drcbe, drcuml_codehandle *entry)
833static void drcbex86_get_info(drcbe_state *state, drcbe_info *info)
769834{
770   /* call our entry point which will jump to the destination */
771   return (*drcbe->entry)((x86code *)drcuml_handle_codeptr(entry));
835   for (info->direct_iregs = 0; info->direct_iregs < DRCUML_REG_I_END - DRCUML_REG_I0; info->direct_iregs++)
836      if (int_register_map[info->direct_iregs] == 0)
837         break;
838   info->direct_fregs = 0;
772839}
773840
774841
r2724r2725
13221389{
13231390   if (param->type == DRCUML_PTYPE_IMMEDIATE)
13241391   {
1325      if (inst->condflags != 0 && (UINT32)param->value == 0xffffffff)
1392      if (inst->condflags == 0 && (UINT32)param->value == 0xffffffff)
13261393         /* skip */;
13271394      else if (inst->condflags != 0 && (UINT32)param->value == 0)
13281395         emit_xor_r32_r32(dst, reg, reg);                                 // xor   reg,reg
r2724r2725
13451412{
13461413   if (param->type == DRCUML_PTYPE_IMMEDIATE)
13471414   {
1348      if (inst->condflags != 0 && (UINT32)param->value == 0xffffffff)
1415      if (inst->condflags == 0 && (UINT32)param->value == 0xffffffff)
13491416         /* skip */;
13501417      else if (inst->condflags != 0 && (UINT32)param->value == 0)
13511418         emit_mov_m32_imm(dst, MEMPARAMS, 0);                              // mov   [dest],0
r2724r2725
14051472{
14061473   if (param->type == DRCUML_PTYPE_IMMEDIATE)
14071474   {
1408      if (inst->condflags != 0 && (UINT32)param->value == 0)
1475      if (inst->condflags == 0 && (UINT32)param->value == 0)
14091476         /* skip */;
14101477      else if (inst->condflags != 0 && (UINT32)param->value == 0xffffffff)
14111478         emit_mov_r32_imm(dst, reg, -1);                                    // mov  reg,-1
r2724r2725
14281495{
14291496   if (param->type == DRCUML_PTYPE_IMMEDIATE)
14301497   {
1431      if (inst->condflags != 0 && (UINT32)param->value == 0)
1498      if (inst->condflags == 0 && (UINT32)param->value == 0)
14321499         /* skip */;
14331500      else if (inst->condflags != 0 && (UINT32)param->value == 0xffffffff)
14341501         emit_mov_m32_imm(dst, MEMPARAMS, -1);                              // mov   [dest],-1
r2724r2725
14531520{
14541521   if (param->type == DRCUML_PTYPE_IMMEDIATE)
14551522   {
1456      if (inst->condflags != 0 && (UINT32)param->value == 0)
1523      if (inst->condflags == 0 && (UINT32)param->value == 0)
14571524         /* skip */;
14581525      else if (inst->condflags != 0 && (UINT32)param->value == 0xffffffff)
14591526         emit_not_r32(dst, reg);                                          // not   reg
r2724r2725
14761543{
14771544   if (param->type == DRCUML_PTYPE_IMMEDIATE)
14781545   {
1479      if (inst->condflags != 0 && (UINT32)param->value == 0)
1546      if (inst->condflags == 0 && (UINT32)param->value == 0)
14801547         /* skip */;
14811548      else if (inst->condflags != 0 && (UINT32)param->value == 0xffffffff)
14821549         emit_not_m32(dst, MEMPARAMS);                                    // not   [dest]
r2724r2725
15011568{
15021569   if (param->type == DRCUML_PTYPE_IMMEDIATE)
15031570   {
1504      if (inst->condflags != 0 && (UINT32)param->value == 0)
1571      if (inst->condflags == 0 && (UINT32)param->value == 0)
15051572         /* skip */;
15061573      else
15071574         emit_shl_r32_imm(dst, reg, param->value);                           // shl   reg,param
r2724r2725
15231590{
15241591   if (param->type == DRCUML_PTYPE_IMMEDIATE)
15251592   {
1526      if (inst->condflags != 0 && (UINT32)param->value == 0)
1593      if (inst->condflags == 0 && (UINT32)param->value == 0)
15271594         /* skip */;
15281595      else
15291596         emit_shl_m32_imm(dst, MEMPARAMS, param->value);                        // shl   [dest],param
r2724r2725
15451612{
15461613   if (param->type == DRCUML_PTYPE_IMMEDIATE)
15471614   {
1548      if (inst->condflags != 0 && (UINT32)param->value == 0)
1615      if (inst->condflags == 0 && (UINT32)param->value == 0)
15491616         /* skip */;
15501617      else
15511618         emit_shr_r32_imm(dst, reg, param->value);                           // shr   reg,param
r2724r2725
15671634{
15681635   if (param->type == DRCUML_PTYPE_IMMEDIATE)
15691636   {
1570      if (inst->condflags != 0 && (UINT32)param->value == 0)
1637      if (inst->condflags == 0 && (UINT32)param->value == 0)
15711638         /* skip */;
15721639      else
15731640         emit_shr_m32_imm(dst, MEMPARAMS, param->value);                        // shr   [dest],param
r2724r2725
15891656{
15901657   if (param->type == DRCUML_PTYPE_IMMEDIATE)
15911658   {
1592      if (inst->condflags != 0 && (UINT32)param->value == 0)
1659      if (inst->condflags == 0 && (UINT32)param->value == 0)
15931660         /* skip */;
15941661      else
15951662         emit_sar_r32_imm(dst, reg, param->value);                           // sar   reg,param
r2724r2725
16111678{
16121679   if (param->type == DRCUML_PTYPE_IMMEDIATE)
16131680   {
1614      if (inst->condflags != 0 && (UINT32)param->value == 0)
1681      if (inst->condflags == 0 && (UINT32)param->value == 0)
16151682         /* skip */;
16161683      else
16171684         emit_sar_m32_imm(dst, MEMPARAMS, param->value);                        // sar   [dest],param
r2724r2725
16331700{
16341701   if (param->type == DRCUML_PTYPE_IMMEDIATE)
16351702   {
1636      if (inst->condflags != 0 && (UINT32)param->value == 0)
1703      if (inst->condflags == 0 && (UINT32)param->value == 0)
16371704         /* skip */;
16381705      else
16391706         emit_rol_r32_imm(dst, reg, param->value);                           // rol   reg,param
r2724r2725
16551722{
16561723   if (param->type == DRCUML_PTYPE_IMMEDIATE)
16571724   {
1658      if (inst->condflags != 0 && (UINT32)param->value == 0)
1725      if (inst->condflags == 0 && (UINT32)param->value == 0)
16591726         /* skip */;
16601727      else
16611728         emit_rol_m32_imm(dst, MEMPARAMS, param->value);                        // rol   [dest],param
r2724r2725
16771744{
16781745   if (param->type == DRCUML_PTYPE_IMMEDIATE)
16791746   {
1680      if (inst->condflags != 0 && (UINT32)param->value == 0)
1747      if (inst->condflags == 0 && (UINT32)param->value == 0)
16811748         /* skip */;
16821749      else
16831750         emit_ror_r32_imm(dst, reg, param->value);                           // ror   reg,param
r2724r2725
16991766{
17001767   if (param->type == DRCUML_PTYPE_IMMEDIATE)
17011768   {
1702      if (inst->condflags != 0 && (UINT32)param->value == 0)
1769      if (inst->condflags == 0 && (UINT32)param->value == 0)
17031770         /* skip */;
17041771      else
17051772         emit_ror_m32_imm(dst, MEMPARAMS, param->value);                        // ror   [dest],param
r2724r2725
17211788{
17221789   if (param->type == DRCUML_PTYPE_IMMEDIATE)
17231790   {
1724      if (inst->condflags != 0 && (UINT32)param->value == 0)
1791      if (inst->condflags == 0 && (UINT32)param->value == 0)
17251792         /* skip */;
17261793      else
17271794         emit_rcl_r32_imm(dst, reg, param->value);                           // rcl   reg,param
r2724r2725
17431810{
17441811   if (param->type == DRCUML_PTYPE_IMMEDIATE)
17451812   {
1746      if (inst->condflags != 0 && (UINT32)param->value == 0)
1813      if (inst->condflags == 0 && (UINT32)param->value == 0)
17471814         /* skip */;
17481815      else
17491816         emit_rcl_m32_imm(dst, MEMPARAMS, param->value);                        // rcl   [dest],param
r2724r2725
17651832{
17661833   if (param->type == DRCUML_PTYPE_IMMEDIATE)
17671834   {
1768      if (inst->condflags != 0 && (UINT32)param->value == 0)
1835      if (inst->condflags == 0 && (UINT32)param->value == 0)
17691836         /* skip */;
17701837      else
17711838         emit_rcr_r32_imm(dst, reg, param->value);                           // rcr   reg,param
r2724r2725
17871854{
17881855   if (param->type == DRCUML_PTYPE_IMMEDIATE)
17891856   {
1790      if (inst->condflags != 0 && (UINT32)param->value == 0)
1857      if (inst->condflags == 0 && (UINT32)param->value == 0)
17911858         /* skip */;
17921859      else
17931860         emit_rcr_m32_imm(dst, MEMPARAMS, param->value);                        // rcr   [dest],param
r2724r2725
24192486   if (param->type == DRCUML_PTYPE_IMMEDIATE)
24202487   {
24212488      int count = param->value & 63;
2422      if (inst->condflags != 0 && count == 0)
2489      if (inst->condflags == 0 && count == 0)
24232490         /* skip */;
24242491      else
24252492      {
r2724r2725
24902557   if (param->type == DRCUML_PTYPE_IMMEDIATE)
24912558   {
24922559      int count = param->value & 63;
2493      if (inst->condflags != 0 && count == 0)
2560      if (inst->condflags == 0 && count == 0)
24942561         /* skip */;
24952562      else
24962563      {
r2724r2725
25612628   if (param->type == DRCUML_PTYPE_IMMEDIATE)
25622629   {
25632630      int count = param->value & 63;
2564      if (inst->condflags != 0 && count == 0)
2631      if (inst->condflags == 0 && count == 0)
25652632         /* skip */;
25662633      else
25672634      {
r2724r2725
26322699   if (param->type == DRCUML_PTYPE_IMMEDIATE)
26332700   {
26342701      int count = param->value & 63;
2635      if (inst->condflags != 0 && count == 0)
2702      if (inst->condflags == 0 && count == 0)
26362703         /* skip */;
26372704      else
26382705      {
r2724r2725
26882755      emit_shld_r32_r32_cl(dst, reglo, reghi);                              // shld  reglo,reghi,cl
26892756      if (saveflags) emit_pushf(dst);                                       // pushf
26902757      emit_shld_r32_r32_cl(dst, reghi, REG_EBX);                              // shld  reghi,ebx,cl
2691      emit_mov_r32_m32(dst, MBD(REG_ESP, saveflags ? -4 : -8), REG_EBX);            // mov   ebx,[esp-8]
2758      emit_mov_r32_m32(dst, REG_EBX, MBD(REG_ESP, saveflags ? -4 : -8));            // mov   ebx,[esp-8]
26922759   }
26932760   if (saveflags)
26942761      emit_combine_z_flags(dst);
r2724r2725
27062773   if (param->type == DRCUML_PTYPE_IMMEDIATE)
27072774   {
27082775      int count = param->value & 63;
2709      if (inst->condflags != 0 && count == 0)
2776      if (inst->condflags == 0 && count == 0)
27102777         /* skip */;
27112778      else
27122779      {
r2724r2725
27622829      emit_shrd_r32_r32_cl(dst, reglo, reghi);                              // shrd  reglo,reghi,cl
27632830      if (saveflags) emit_pushf(dst);                                       // pushf
27642831      emit_shrd_r32_r32_cl(dst, reghi, REG_EBX);                              // shrd  reghi,ebx,cl
2765      emit_mov_r32_m32(dst, MBD(REG_ESP, saveflags ? -4 : -8), REG_EBX);            // mov   ebx,[esp-8]
2832      emit_mov_r32_m32(dst, REG_EBX, MBD(REG_ESP, saveflags ? -4 : -8));            // mov   ebx,[esp-8]
27662833   }
27672834   if (saveflags)
27682835      emit_combine_z_flags(dst);
r2724r2725
31413208
31423209   /* validate instruction */
31433210   assert(inst->size == 4);
3144   assert(inst->condflags == DRCUML_COND_ALWAYS || (inst->condflags >= COND_Z && inst->condflags < DRCUML_COND_MAX));
3211   assert(inst->condflags == DRCUML_COND_ALWAYS || (inst->condflags >= DRCUML_COND_Z && inst->condflags < DRCUML_COND_MAX));
31453212
31463213   /* normalize parameters */
31473214   param_normalize_1(drcbe, inst, &retp, PTYPE_MRI);
r2724r2725
32343301   }
32353302
32363303   /* in all cases, if there is no code, we return here to generate the exception */
3237   emit_mov_m32_p32(drcbe, &dst, MABS(&drcbe->state.exp.l), &pcp);                  // mov   [exp],param
3304   emit_mov_m32_p32(drcbe, &dst, MABS(&drcbe->state.exp), &pcp);                  // mov   [exp],param
32383305   emit_sub_r32_imm(&dst, REG_ESP, 4);                                       // sub   esp,4
32393306   emit_call_m32(&dst, MABS(exp.value));                                    // call  [exp]
32403307
r2724r2725
32533320
32543321   /* validate instruction */
32553322   assert(inst->size == 4);
3256   assert(inst->condflags == DRCUML_COND_ALWAYS || (inst->condflags >= COND_Z && inst->condflags < DRCUML_COND_MAX));
3323   assert(inst->condflags == DRCUML_COND_ALWAYS || (inst->condflags >= DRCUML_COND_Z && inst->condflags < DRCUML_COND_MAX));
32573324
32583325   /* normalize parameters */
32593326   param_normalize_1(drcbe, inst, &labelp, PTYPE_I);
r2724r2725
32803347
32813348   /* validate instruction */
32823349   assert(inst->size == 4);
3283   assert(inst->condflags == DRCUML_COND_ALWAYS || (inst->condflags >= COND_Z && inst->condflags < DRCUML_COND_MAX));
3350   assert(inst->condflags == DRCUML_COND_ALWAYS || (inst->condflags >= DRCUML_COND_Z && inst->condflags < DRCUML_COND_MAX));
32843351
32853352   /* normalize parameters */
32863353   param_normalize_2(drcbe, inst, &handp, PTYPE_M, &exp, PTYPE_MRI);
r2724r2725
32913358   /* perform the exception processing inline if unconditional */
32923359   if (inst->condflags == DRCUML_COND_ALWAYS)
32933360   {
3294      emit_mov_m32_p32(drcbe, &dst, MABS(&drcbe->state.exp.l), &exp);               // mov   [exp],exp
3361      emit_mov_m32_p32(drcbe, &dst, MABS(&drcbe->state.exp), &exp);               // mov   [exp],exp
32953362      if (*targetptr != NULL)
32963363         emit_call(&dst, *targetptr);                                    // call  *targetptr
32973364      else
r2724r2725
33203387
33213388   /* validate instruction */
33223389   assert(inst->size == 4);
3323   assert(inst->condflags == DRCUML_COND_ALWAYS || (inst->condflags >= COND_Z && inst->condflags < DRCUML_COND_MAX));
3390   assert(inst->condflags == DRCUML_COND_ALWAYS || (inst->condflags >= DRCUML_COND_Z && inst->condflags < DRCUML_COND_MAX));
33243391
33253392   /* normalize parameters */
33263393   param_normalize_1(drcbe, inst, &handp, PTYPE_M);
r2724r2725
33553422
33563423   /* validate instruction */
33573424   assert(inst->size == 4);
3358   assert(inst->condflags == DRCUML_COND_ALWAYS || (inst->condflags >= COND_Z && inst->condflags < DRCUML_COND_MAX));
3425   assert(inst->condflags == DRCUML_COND_ALWAYS || (inst->condflags >= DRCUML_COND_Z && inst->condflags < DRCUML_COND_MAX));
33593426   assert(inst->numparams == 0);
33603427
33613428   /* skip if conditional */
r2724r2725
33833450
33843451   /* validate instruction */
33853452   assert(inst->size == 4);
3386   assert(inst->condflags == DRCUML_COND_ALWAYS || (inst->condflags >= COND_Z && inst->condflags < DRCUML_COND_MAX));
3453   assert(inst->condflags == DRCUML_COND_ALWAYS || (inst->condflags >= DRCUML_COND_Z && inst->condflags < DRCUML_COND_MAX));
33873454
33883455   /* normalize parameters */
33893456   param_normalize_2(drcbe, inst, &funcp, PTYPE_M, &paramp, PTYPE_M);
r2724r2725
35203587
35213588   /* fetch the exception parameter and store to the destination */
35223589   if (dstp.type == DRCUML_PTYPE_INT_REGISTER)
3523      emit_mov_r32_m32(&dst, dstp.value, MABS(&drcbe->state.exp.l));               // mov   reg,[exp]
3590      emit_mov_r32_m32(&dst, dstp.value, MABS(&drcbe->state.exp));               // mov   reg,[exp]
35243591   else
35253592   {
3526      emit_mov_r32_m32(&dst, REG_EAX, MABS(&drcbe->state.exp.l));                  // mov   eax,[exp]
3593      emit_mov_r32_m32(&dst, REG_EAX, MABS(&drcbe->state.exp));                  // mov   eax,[exp]
35273594      emit_mov_m32_r32(&dst, MABS(dstp.value), REG_EAX);                        // mov   [dstp],eax
35283595   }
35293596
r2724r2725
35313598}
35323599
35333600
3601/*-------------------------------------------------
3602    op_save - process a SAVE opcode
3603-------------------------------------------------*/
35343604
3605static x86code *op_save(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
3606{
3607   drcuml_parameter dstp;
3608   int regnum;
3609
3610   /* validate instruction */
3611   assert(inst->size == 4);
3612   assert(inst->condflags == DRCUML_COND_ALWAYS);
3613
3614   /* normalize parameters */
3615   param_normalize_1(drcbe, inst, &dstp, PTYPE_M);
3616
3617   /* copy live state to the destination */
3618   emit_mov_r32_imm(&dst, REG_ECX, dstp.value);                              // mov    ecx,dstp
3619
3620   /* copy flags */
3621   emit_pushf(&dst);                                                   // pushf
3622   emit_pop_r32(&dst, REG_EAX);                                          // pop    eax
3623   emit_and_r32_imm(&dst, REG_EAX, 0x8c5);                                    // and    eax,0x8c5
3624   emit_mov_r8_m8(&dst, REG_AL, MBD(REG_EAX, flags_map));                        // mov    al,[flags_map]
3625   emit_mov_m8_r8(&dst, MBD(REG_ECX, offsetof(drcuml_machine_state, flags)), REG_AL);   // mov    state->flags,al
3626
3627   /* copy fmod and exp */
3628   emit_mov_r8_m8(&dst, REG_AL, MABS(&drcbe->state.fmod));                        // mov    al,[fmod]
3629   emit_mov_m8_r8(&dst, MBD(REG_ECX, offsetof(drcuml_machine_state, fmod)), REG_AL);   // mov    state->fmod,al
3630   emit_mov_r32_m32(&dst, REG_EAX, MABS(&drcbe->state.exp));                     // mov    eax,[exp]
3631   emit_mov_m32_r32(&dst, MBD(REG_ECX, offsetof(drcuml_machine_state, exp)), REG_EAX);   // mov    state->exp,eax
3632
3633   /* copy integer registers */
3634   for (regnum = 0; regnum < ARRAY_LENGTH(drcbe->state.r); regnum++)
3635   {
3636      if (int_register_map[regnum] != 0)
3637         emit_mov_m32_r32(&dst, MBD(REG_ECX, offsetof(drcuml_machine_state, r[regnum].w.l)), int_register_map[regnum]);
3638      else
3639      {
3640         emit_mov_r32_m32(&dst, REG_EAX, MABS(&drcbe->state.r[regnum].w.l));
3641         emit_mov_m32_r32(&dst, MBD(REG_ECX, offsetof(drcuml_machine_state, r[regnum].w.l)), REG_EAX);
3642      }
3643      emit_mov_r32_m32(&dst, REG_EAX, MABS(&drcbe->state.r[regnum].w.h));
3644      emit_mov_m32_r32(&dst, MBD(REG_ECX, offsetof(drcuml_machine_state, r[regnum].w.h)), REG_EAX);
3645   }
3646
3647   /* copy FP registers */
3648   for (regnum = 0; regnum < ARRAY_LENGTH(drcbe->state.f); regnum++)
3649   {
3650      emit_mov_r32_m32(&dst, REG_EAX, MABS(&drcbe->state.f[regnum].s.l));
3651      emit_mov_m32_r32(&dst, MBD(REG_ECX, offsetof(drcuml_machine_state, f[regnum].s.l)), REG_EAX);
3652      emit_mov_r32_m32(&dst, REG_EAX, MABS(&drcbe->state.f[regnum].s.h));
3653      emit_mov_m32_r32(&dst, MBD(REG_ECX, offsetof(drcuml_machine_state, f[regnum].s.h)), REG_EAX);
3654   }
3655
3656   return dst;
3657}
3658
3659
3660/*-------------------------------------------------
3661    op_restore - process a RESTORE opcode
3662-------------------------------------------------*/
3663
3664static x86code *op_restore(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
3665{
3666   drcuml_parameter dstp;
3667   int regnum;
3668
3669   /* validate instruction */
3670   assert(inst->size == 4);
3671   assert(inst->condflags == DRCUML_COND_ALWAYS);
3672
3673   /* normalize parameters */
3674   param_normalize_1(drcbe, inst, &dstp, PTYPE_M);
3675
3676   /* copy live state from the destination */
3677   emit_mov_r32_imm(&dst, REG_ECX, dstp.value);                              // mov    ecx,dstp
3678
3679   /* copy integer registers */
3680   for (regnum = 0; regnum < ARRAY_LENGTH(drcbe->state.r); regnum++)
3681   {
3682      if (int_register_map[regnum] != 0)
3683         emit_mov_r32_m32(&dst, int_register_map[regnum], MBD(REG_ECX, offsetof(drcuml_machine_state, r[regnum].w.l)));
3684      else
3685      {
3686         emit_mov_r32_m32(&dst, REG_EAX, MBD(REG_ECX, offsetof(drcuml_machine_state, r[regnum].w.l)));
3687         emit_mov_m32_r32(&dst, MABS(&drcbe->state.r[regnum].w.l), REG_EAX);
3688      }
3689      emit_mov_r32_m32(&dst, REG_EAX, MBD(REG_ECX, offsetof(drcuml_machine_state, r[regnum].w.h)));
3690      emit_mov_m32_r32(&dst, MABS(&drcbe->state.r[regnum].w.h), REG_EAX);
3691   }
3692
3693   /* copy FP registers */
3694   for (regnum = 0; regnum < ARRAY_LENGTH(drcbe->state.f); regnum++)
3695   {
3696      emit_mov_r32_m32(&dst, REG_EAX, MBD(REG_ECX, offsetof(drcuml_machine_state, f[regnum].s.l)));
3697      emit_mov_m32_r32(&dst, MABS(&drcbe->state.f[regnum].s.l), REG_EAX);
3698      emit_mov_r32_m32(&dst, REG_EAX, MBD(REG_ECX, offsetof(drcuml_machine_state, f[regnum].s.h)));
3699      emit_mov_m32_r32(&dst, MABS(&drcbe->state.f[regnum].s.h), REG_EAX);
3700   }
3701
3702   /* copy fmod and exp */
3703   emit_movzx_r32_m8(&dst, REG_EAX, MBD(REG_ECX, offsetof(drcuml_machine_state, fmod)));// movzx eax,state->fmod
3704   emit_and_r32_imm(&dst, REG_EAX, 3);                                       // and    eax,3
3705   emit_mov_m8_r8(&dst, MABS(&drcbe->state.fmod), REG_AL);                        // mov    [fmod],al
3706   emit_fldcw_m16(&dst, MISD(REG_EAX, 2, &fp_control[0]));                        // fldcw  fp_control[eax]
3707   emit_mov_r32_m32(&dst, REG_EAX, MBD(REG_ECX, offsetof(drcuml_machine_state, exp)));   // mov    eax,state->exp
3708   emit_mov_m32_r32(&dst, MABS(&drcbe->state.exp), REG_EAX);                     // mov    [exp],eax
3709
3710   /* copy flags */
3711   emit_movzx_r32_m8(&dst, REG_EAX, MBD(REG_ECX, offsetof(drcuml_machine_state, flags)));// movzx eax,state->flags
3712   emit_push_m32(&dst, MISD(REG_EAX, 4, flags_unmap));                           // push   flags_unmap[eax*4]
3713   emit_popf(&dst);                                                   // popf
3714
3715   return dst;
3716}
3717
3718
3719
35353720/***************************************************************************
35363721    INTEGER OPERATIONS
35373722***************************************************************************/
r2724r2725
47064891
47074892   /* validate instruction */
47084893   assert(inst->size == 4 || inst->size == 8);
4709   assert(inst->condflags == DRCUML_COND_ALWAYS || (inst->condflags >= COND_Z && inst->condflags < DRCUML_COND_MAX));
4894   assert(inst->condflags == DRCUML_COND_ALWAYS || (inst->condflags >= DRCUML_COND_Z && inst->condflags < DRCUML_COND_MAX));
47104895
47114896   /* normalize parameters, but only if we got here directly */
47124897   /* other opcodes call through here with pre-normalized parameters */
r2724r2725
50855270
50865271
50875272/*-------------------------------------------------
5273    op_xtract - process an XTRACT opcode
5274-------------------------------------------------*/
5275
5276static x86code *op_xtract(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
5277{
5278   drcuml_parameter dstp, srcp, shiftp, maskp;
5279   int dstreg;
5280
5281   /* validate instruction */
5282   assert(inst->size == 4 || inst->size == 8);
5283   assert(inst->condflags == DRCUML_COND_ALWAYS);
5284
5285   /* normalize parameters */
5286   param_normalize_4(drcbe, inst, &dstp, PTYPE_MR, &srcp, PTYPE_MRI, &shiftp, PTYPE_MRI, &maskp, PTYPE_MRI);
5287
5288   /* degenerate cases -- convert to a move or simple shift */
5289   if (srcp.type == DRCUML_PTYPE_IMMEDIATE && shiftp.type == DRCUML_PTYPE_IMMEDIATE && maskp.type == DRCUML_PTYPE_IMMEDIATE)
5290   {
5291      if (inst->size == 4)
5292         return convert_to_mov_imm(drcbe, dst, inst, &dstp, ((srcp.value << shiftp.value) | (srcp.value >> (32 - shiftp.value))) & maskp.value);
5293      else if (inst->size == 8)
5294         return convert_to_mov_imm(drcbe, dst, inst, &dstp, ((srcp.value << shiftp.value) | (srcp.value >> (64 - shiftp.value))) & maskp.value);
5295   }
5296   if (shiftp.type == DRCUML_PTYPE_IMMEDIATE && maskp.type == DRCUML_PTYPE_IMMEDIATE)
5297   {
5298      if ((inst->size == 4 && maskp.value == (UINT32)(0xffffffffUL << shiftp.value)) || (inst->size == 8 && maskp.value == U64(0xffffffffffffffff) << shiftp.value))
5299      {
5300         drcuml_instruction temp = *inst;
5301         temp.numparams = 3;
5302         return op_shl(drcbe, dst, &temp);
5303      }
5304      if ((inst->size == 4 && maskp.value == (UINT32)(0xffffffffUL >> (32 - shiftp.value))) || (inst->size == 8 && maskp.value == U64(0xffffffffffffffff) >> (64 - shiftp.value)))
5305      {
5306         drcuml_instruction temp = *inst;
5307         temp.numparams = 3;
5308         temp.param[2].value = inst->size * 8 - temp.param[2].value;
5309         return op_shr(drcbe, dst, &temp);
5310      }
5311   }
5312
5313   /* pick a target register for the general case */
5314   dstreg = param_select_register2(REG_EAX, &dstp, &shiftp, &maskp);
5315
5316   /* 32-bit form */
5317   if (inst->size == 4)
5318   {
5319      emit_mov_r32_p32(drcbe, &dst, dstreg, &srcp);                           // mov   dstreg,srcp
5320      emit_rol_r32_p32(drcbe, &dst, dstreg, &shiftp, inst);                     // rol   dstreg,shiftp
5321      emit_and_r32_p32(drcbe, &dst, dstreg, &maskp, inst);                     // and   dstreg,maskp
5322      emit_mov_p32_r32(drcbe, &dst, &dstp, dstreg);                           // mov   dstp,dstreg
5323   }
5324
5325   /* 64-bit form */
5326   else if (inst->size == 8)
5327   {
5328      emit_mov_r64_p64(drcbe, &dst, dstreg, REG_EDX, &srcp);                     // mov   edx:dstreg,srcp
5329      emit_rol_r64_p64(drcbe, &dst, dstreg, REG_EDX, &shiftp, inst);               // rol   edx:dstreg,shiftp
5330      emit_and_r64_p64(drcbe, &dst, dstreg, REG_EDX, &maskp, inst);               // and   edx:dstreg,maskp
5331      emit_mov_p64_r64(drcbe, &dst, &dstp, dstreg, REG_EDX);                     // mov   dstp,edx:dstreg
5332   }
5333   return dst;
5334}
5335
5336
5337/*-------------------------------------------------
5338    op_insert - process an INSERT opcode
5339-------------------------------------------------*/
5340
5341static x86code *op_insert(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
5342{
5343   drcuml_parameter dstp, srcp, shiftp, maskp;
5344   int dstreg;
5345
5346   /* validate instruction */
5347   assert(inst->size == 4 || inst->size == 8);
5348   assert(inst->condflags == DRCUML_COND_ALWAYS);
5349
5350   /* normalize parameters */
5351   param_normalize_4(drcbe, inst, &dstp, PTYPE_MR, &srcp, PTYPE_MRI, &shiftp, PTYPE_MRI, &maskp, PTYPE_MRI);
5352
5353   /* pick a target register for the general case */
5354   dstreg = param_select_register2(REG_ECX, &dstp, &shiftp, &maskp);
5355
5356   /* 32-bit form */
5357   if (inst->size == 4)
5358   {
5359      emit_mov_r32_p32(drcbe, &dst, REG_EAX, &srcp);                           // mov   eax,srcp
5360      emit_rol_r32_p32(drcbe, &dst, REG_EAX, &shiftp, inst);                     // rol   eax,shiftp
5361      emit_mov_r32_p32(drcbe, &dst, dstreg, &dstp);                           // mov   dstreg,dstp
5362      if (maskp.type == DRCUML_PTYPE_IMMEDIATE)
5363      {
5364         emit_and_r32_imm(&dst, REG_EAX, maskp.value);                        // and   eax,maskp
5365         emit_and_r32_imm(&dst, dstreg, ~maskp.value);                        // and   dstreg,~maskp
5366      }
5367      else
5368      {
5369         emit_mov_r32_p32(drcbe, &dst, REG_EDX, &maskp);                        // mov   edx,maskp
5370         emit_and_r32_r32(&dst, REG_EAX, REG_EDX);                           // and   eax,edx
5371         emit_not_r32(&dst, REG_EDX);                                    // not   edx
5372         emit_and_r32_r32(&dst, dstreg, REG_EDX);                           // and   dstreg,edx
5373      }
5374      emit_or_r32_r32(&dst, dstreg, REG_EAX);                                 // or    dstreg,eax
5375      emit_mov_p32_r32(drcbe, &dst, &dstp, dstreg);                           // mov   dstp,dstreg
5376   }
5377
5378   /* 64-bit form */
5379   else if (inst->size == 8)
5380   {
5381      emit_mov_r64_p64(drcbe, &dst, REG_EAX, REG_EDX, &srcp);                     // mov   edx:eax,srcp
5382      emit_rol_r64_p64(drcbe, &dst, REG_EAX, REG_EDX, &shiftp, inst);               // rol   edx:eax,shiftp
5383      if (maskp.type == DRCUML_PTYPE_IMMEDIATE)
5384      {
5385         emit_and_r32_imm(&dst, REG_EAX, maskp.value);                        // and   eax,maskp
5386         emit_and_r32_imm(&dst, REG_EDX, maskp.value >> 32);                     // and   edx,maskp >> 32
5387         if (dstp.type == DRCUML_PTYPE_INT_REGISTER)
5388         {
5389            emit_and_r32_imm(&dst, dstp.value, ~maskp.value);                  // and   dstp.lo,~maskp
5390            emit_and_m32_imm(&dst, MABS(drcbe->reghi[dstp.value]), ~maskp.value >> 32);// and   dstp.hi,~maskp >> 32
5391            emit_or_r32_r32(&dst, dstp.value, REG_EAX);                        // or    dstp.lo,eax
5392            emit_or_m32_r32(&dst, MABS(drcbe->reghi[dstp.value]), REG_EDX);         // or    dstp.hi,edx
5393         }
5394         else
5395         {
5396            emit_and_m32_imm(&dst, MABS(dstp.value), ~maskp.value);               // and   dstp.lo,~maskp
5397            emit_and_m32_imm(&dst, MABS(dstp.value + 4), ~maskp.value >> 32);      // and   dstp.hi,~maskp >> 32
5398            emit_or_m32_r32(&dst, MABS(dstp.value), REG_EAX);                  // or    dstp.lo,eax
5399            emit_or_m32_r32(&dst, MABS(dstp.value + 4), REG_EDX);               // or    dstp.hi,edx
5400         }
5401      }
5402      else
5403      {
5404         emit_mov_m32_r32(&dst, MBD(REG_ESP, -8), REG_EBX);                     // mov   [esp-8],ebx
5405         emit_mov_r64_p64(drcbe, &dst, REG_EBX, REG_ECX, &maskp);               // mov   ecx:ebx,maskp
5406         emit_and_r32_r32(&dst, REG_EAX, REG_EBX);                           // and   eax,ebx
5407         emit_and_r32_r32(&dst, REG_EDX, REG_ECX);                           // and   edx,ecx
5408         emit_not_r32(&dst, REG_EBX);                                    // not   ebx
5409         emit_not_r32(&dst, REG_ECX);                                    // not   ecx
5410         if (dstp.type == DRCUML_PTYPE_INT_REGISTER)
5411         {
5412            emit_and_r32_r32(&dst, dstp.value, REG_EBX);                     // and   dstp.lo,ebx
5413            emit_and_m32_r32(&dst, MABS(drcbe->reghi[dstp.value]), REG_ECX);      // and   dstp.hi,ecx
5414            emit_or_r32_r32(&dst, dstp.value, REG_EAX);                        // or    dstp.lo,eax
5415            emit_or_m32_r32(&dst, MABS(drcbe->reghi[dstp.value]), REG_EDX);         // or    dstp.hi,edx
5416         }
5417         else
5418         {
5419            emit_and_m32_r32(&dst, MABS(dstp.value), REG_EBX);                  // and   dstp.lo,ebx
5420            emit_and_m32_r32(&dst, MABS(dstp.value + 4), REG_ECX);               // and   dstp.hi,ecx
5421            emit_or_m32_r32(&dst, MABS(dstp.value), REG_EAX);                  // or    dstp.lo,eax
5422            emit_or_m32_r32(&dst, MABS(dstp.value + 4), REG_EDX);               // or    dstp.hi,edx
5423         }
5424         emit_mov_r32_m32(&dst, REG_EBX, MBD(REG_ESP, -8));                     // mov   ebx,[esp-8]
5425      }
5426   }
5427   return dst;
5428}
5429
5430
5431/*-------------------------------------------------
50885432    op_add - process a ADD opcode
50895433-------------------------------------------------*/
50905434
r2724r2725
60386382
60396383
60406384/*-------------------------------------------------
6385    op_lzcnt - process a LZCNT opcode
6386-------------------------------------------------*/
6387
6388static x86code *op_lzcnt(drcbe_state *drcbe, x86code *dst, const drcuml_instruction *inst)
6389{
6390   drcuml_parameter dstp, srcp;
6391   int dstreg;
6392
6393   /* validate instruction */
6394   assert(inst->size == 4 || inst->size == 8);
6395   assert(inst->condflags == 0);
6396
6397   /* normalize parameters */
6398   param_normalize_2(drcbe, inst, &dstp, PTYPE_MR, &srcp, PTYPE_MRI);
6399
6400   /* degenerate cases -- convert to a move */
6401   if (srcp.type == DRCUML_PTYPE_IMMEDIATE && inst->condflags == 0)
6402      return convert_to_mov_imm(drcbe, dst, inst, &dstp, count_leading_zeros(srcp.value));
6403
6404   /* pick a target register for the general case */
6405   dstreg = param_select_register(REG_EAX, &dstp, &srcp);
6406
6407   /* 32-bit form */
6408   if (inst->size == 4)
6409   {
6410      emit_mov_r32_p32(drcbe, &dst, dstreg, &srcp);                           // mov   dstreg,src1p
6411      emit_mov_r32_imm(&dst, REG_ECX, 32);                                 // mov   ecx,32
6412      emit_bsr_r32_r32(&dst, dstreg, dstreg);                                 // bsr   dstreg,dstreg
6413      emit_cmovcc_r32_r32(&dst, COND_Z, dstreg, REG_ECX);                        // cmovz dstreg,ecx
6414      emit_mov_p32_r32(drcbe, &dst, &dstp, dstreg);                           // mov   dstp,dstreg
6415   }
6416
6417   /* 64-bit form */
6418   else if (inst->size == 8)
6419   {
6420      emit_link skip;
6421
6422      emit_mov_r64_p64(drcbe, &dst, REG_EDX, dstreg, &srcp);                     // mov   dstreg:edx,srcp
6423      emit_bsr_r32_r32(&dst, dstreg, dstreg);                                 // bsr   dstreg,dstreg
6424      emit_jcc_short_link(&dst, COND_NZ, &skip);                              // jnz   skip
6425      emit_mov_r32_imm(&dst, REG_ECX, 32);                                 // mov   ecx,32
6426      emit_bsr_r32_r32(&dst, dstreg, REG_EDX);                              // bsr   dstreg,edx
6427      emit_cmovcc_r32_r32(&dst, COND_Z, dstreg, REG_ECX);                        // cmovz dstreg,ecx
6428      emit_add_r32_imm(&dst, REG_ECX, 32);                                 // add   ecx,32
6429      resolve_link(&dst, &skip);                                       // skip:
6430      emit_xor_r32_r32(&dst, REG_EDX, REG_EDX);                        // xor   edx,edx
6431      emit_mov_p64_r64(drcbe, &dst, &dstp, dstreg, REG_EDX);                     // mov   dstp,edx:dstreg
6432   }
6433   return dst;
6434}
6435
6436
6437/*-------------------------------------------------
60416438    op_shl - process a SHL opcode
60426439-------------------------------------------------*/
60436440
r2724r2725
65766973
65776974   /* validate instruction */
65786975   assert(inst->size == 4 || inst->size == 8);
6579   assert(inst->condflags == DRCUML_COND_ALWAYS || (inst->condflags >= COND_Z && inst->condflags < DRCUML_COND_MAX));
6976   assert(inst->condflags == DRCUML_COND_ALWAYS || (inst->condflags >= DRCUML_COND_Z && inst->condflags < DRCUML_COND_MAX));
65806977
65816978   /* normalize parameters */
65826979   param_normalize_2(drcbe, inst, &dstp, PTYPE_MF, &srcp, PTYPE_MF);
r2724r2725
66397036   /* normalize parameters */
66407037   param_normalize_2(drcbe, inst, &dstp, PTYPE_MR, &srcp, PTYPE_MF);
66417038
6642   /* general case */
6643   emit_fld_p(&dst, inst->size, &srcp);                                    // fld   srcp
6644   if (dstp.type == DRCUML_PTYPE_MEMORY)
6645      emit_fisttp_m32(&dst, MABS(dstp.value));                              // fisttp [dstp]
6646   else if (dstp.type == DRCUML_PTYPE_INT_REGISTER)
7039   /* non-SSE3 case */
7040   if (!drcbe->sse3)
66477041   {
6648      emit_fisttp_m32(&dst, MABS(drcbe->reglo[dstp.value]));                     // fisttp reglo[dstp]
6649      emit_mov_r32_m32(&dst, dstp.value, MABS(drcbe->reglo[dstp.value]));            // mov   dstp,reglo[dstp]
7042      /* save and set the control word */
7043      emit_fstcw_m16(&dst, MABS(&drcbe->fmodesave));                           // fstcw [fmodesave]
7044      emit_fldcw_m16(&dst, MABS(&fp_control[DRCUML_FMOD_TRUNC]));                  // fldcw fpcontrol[DRCUML_FMOD_TRUNC]
7045
7046      /* general case */
7047      emit_fld_p(&dst, inst->size, &srcp);                                 // fld   srcp
7048      if (dstp.type == DRCUML_PTYPE_MEMORY)
7049         emit_fistp_m32(&dst, MABS(dstp.value));                              // fistp [dstp]
7050      else if (dstp.type == DRCUML_PTYPE_INT_REGISTER)
7051      {
7052         emit_fistp_m32(&dst, MABS(drcbe->reglo[dstp.value]));                  // fistp reglo[dstp]
7053         emit_mov_r32_m32(&dst, dstp.value, MABS(drcbe->reglo[dstp.value]));         // mov   dstp,reglo[dstp]
7054      }
7055
7056      /* restore control word and proceed */
7057      emit_fldcw_m16(&dst, MABS(&drcbe->fmodesave));                           // fldcw [fmodesave]
66507058   }
7059
7060   /* SSE3 case */
7061   else
7062   {
7063      /* general case */
7064      emit_fld_p(&dst, inst->size, &srcp);                                 // fld   srcp
7065      if (dstp.type == DRCUML_PTYPE_MEMORY)
7066         emit_fisttp_m32(&dst, MABS(dstp.value));                           // fisttp [dstp]
7067      else if (dstp.type == DRCUML_PTYPE_INT_REGISTER)
7068      {
7069         emit_fisttp_m32(&dst, MABS(drcbe->reglo[dstp.value]));                  // fisttp reglo[dstp]
7070         emit_mov_r32_m32(&dst, dstp.value, MABS(drcbe->reglo[dstp.value]));         // mov   dstp,reglo[dstp]
7071      }
7072   }
66517073   return dst;
66527074}
66537075
r2724r2725
68007222   /* normalize parameters */
68017223   param_normalize_2(drcbe, inst, &dstp, PTYPE_MR, &srcp, PTYPE_MF);
68027224
6803   /* general case */
6804   emit_fld_p(&dst, inst->size, &srcp);                                    // fld   srcp
6805   if (dstp.type == DRCUML_PTYPE_MEMORY)
6806      emit_fisttp_m64(&dst, MABS(dstp.value));                              // fisttp [dstp]
6807   else if (dstp.type == DRCUML_PTYPE_INT_REGISTER)
7225   /* non-SSE3 case */
7226   if (!drcbe->sse3)
68087227   {
6809      emit_fisttp_m64(&dst, MABS(drcbe->reglo[dstp.value]));                     // fisttp reglo[dstp]
6810      emit_mov_r32_m32(&dst, dstp.value, MABS(drcbe->reglo[dstp.value]));            // mov   dstp,reglo[dstp]
7228      /* save and set the control word */
7229      emit_fstcw_m16(&dst, MABS(&drcbe->fmodesave));                           // fstcw [fmodesave]
7230      emit_fldcw_m16(&dst, MABS(&fp_control[DRCUML_FMOD_TRUNC]));                  // fldcw fpcontrol[DRCUML_FMOD_TRUNC]
7231
7232      /* general case */
7233      emit_fld_p(&dst, inst->size, &srcp);                                 // fld   srcp
7234      if (dstp.type == DRCUML_PTYPE_MEMORY)
7235         emit_fistp_m64(&dst, MABS(dstp.value));                              // fistp [dstp]
7236      else if (dstp.type == DRCUML_PTYPE_INT_REGISTER)
7237      {
7238         emit_fistp_m64(&dst, MABS(drcbe->reglo[dstp.value]));                  // fistp reglo[dstp]
7239         emit_mov_r32_m32(&dst, dstp.value, MABS(drcbe->reglo[dstp.value]));         // mov   dstp,reglo[dstp]
7240      }
7241
7242      /* restore control word and proceed */
7243      emit_fldcw_m16(&dst, MABS(&drcbe->fmodesave));                           // fldcw [fmodesave]
68117244   }
7245
7246   /* SSE3 case */
7247   else
7248   {
7249      /* general case */
7250      emit_fld_p(&dst, inst->size, &srcp);                                 // fld   srcp
7251      if (dstp.type == DRCUML_PTYPE_MEMORY)
7252         emit_fisttp_m64(&dst, MABS(dstp.value));                           // fisttp [dstp]
7253      else if (dstp.type == DRCUML_PTYPE_INT_REGISTER)
7254      {
7255         emit_fisttp_m64(&dst, MABS(drcbe->reglo[dstp.value]));                  // fisttp reglo[dstp]
7256         emit_mov_r32_m32(&dst, dstp.value, MABS(drcbe->reglo[dstp.value]));         // mov   dstp,reglo[dstp]
7257      }
7258   }
68127259   return dst;
68137260}
68147261
r2724r2725
70917538
70927539   /* validate instruction */
70937540   assert(inst->size == 4 || inst->size == 8);
7094   assert((inst->condflags & ~(DRCUML_FLAG_C | DRCUML_FLAG_V | DRCUML_FLAG_Z | DRCUML_FLAG_S)) == 0);
7541   assert((inst->condflags & ~(DRCUML_FLAG_C | DRCUML_FLAG_Z | DRCUML_FLAG_U)) == 0);
70957542
70967543   /* normalize parameters */
70977544   param_normalize_2(drcbe, inst, &src1p, PTYPE_MF, &src2p, PTYPE_MF);
src/emu/cpu/saturn/sattable.c
r2724r2725
11static const int adr_a_begin[]={
22-1, -1, BEGIN_XS, BEGIN_X, BEGIN_S, BEGIN_M, BEGIN_B, BEGIN_W,
3-1, -1, -1, -1,  -1, -1, -1, -1,
34};
45
56static const int adr_a_count[]={
67-1, -1, COUNT_XS, COUNT_X, COUNT_S, COUNT_M, COUNT_B, COUNT_W,
8-1, -1, -1, -1,  -1, -1, -1, -1,
79};
810
911static const int adr_b_begin[]={
r2724r2725
2628-1, -1, -1, -1, -1, -1, -1, COUNT_A
2729};
2830
29static const int reg_left[]={A,B,C,D,B,C,A,C};
30static const int reg_right[]={B,C,A,C,A,B,C,D};
31static const int add_left[]={ A,B,C,D, 0,0,0,0, B,C,A,C };
32static const int add_right[]={ B,C,A,C, 0,0,0,0, A,B,C,D };
33static const int sub_left[]={A,B,C,D, 0,0,0,0, B,C,A,C, A,B,C,D};
34static const int sub_right[]={B,C,A,C, 0,0,0,0, A,B,C,D, A,B,C,D };
31static const int reg_left[] ={A,B,C,D, B,C,A,C, I,I,I,I, I,I,I,I};
32static const int reg_right[]={B,C,A,C, A,B,C,D, I,I,I,I, I,I,I,I};
33static const int add_left[] ={A,B,C,D, I,I,I,I, B,C,A,C, I,I,I,I};
34static const int add_right[]={B,C,A,C, I,I,I,I, A,B,C,D, I,I,I,I};
35static const int sub_left[] ={A,B,C,D, I,I,I,I, B,C,A,C, A,B,C,D};
36static const int sub_right[]={B,C,A,C, I,I,I,I, A,B,C,D, B,C,A,C};
3537
38void saturn_invalid3( int op1, int op2, int op3 )
39{
40   logerror( "SATURN#%d invalid opcode %x%x%x at %05x\n",
41        cpu_getactivecpu(), op1, op2, op3, saturn.pc-3 );
42}
43
44void saturn_invalid4( int op1, int op2, int op3, int op4 )
45{
46   logerror( "SATURN#%d invalid opcode %x%x%x%x at %05x\n",
47        cpu_getactivecpu(), op1, op2, op3, op4, saturn.pc-4 );
48}
49
50void saturn_invalid5( int op1, int op2, int op3, int op4, int op5 )
51{
52   logerror( "SATURN#%d invalid opcode %x%x%x%x%x at %05x\n",
53        cpu_getactivecpu(), op1, op2, op3, op4, op5, saturn.pc-5 );
54}
55
56void saturn_invalid6( int op1, int op2, int op3, int op4, int op5, int op6 )
57{
58   logerror( "SATURN#%d invalid opcode %x%x%x%x%x%x at %05x\n",
59        cpu_getactivecpu(), op1, op2, op3, op4, op5, op6, saturn.pc-6 );
60}
61
62
3663INLINE void saturn_instruction_0e(void)
3764{
3865   int reg, adr;
r2724r2725
6895         break; //A=A!B xs
6996      }
7097      break;
98   default:
99      saturn_invalid3( 0, 0xe, adr );
100      break;
71101   }
72102}
73103
r2724r2725
84114      case 8: case 9: case 0xa: case 0xb: case 0xc:
85115         saturn_copy(R0+(reg&7), BEGIN_W, COUNT_W, C);
86116         break; // r0=c w
117      default:
118         saturn_invalid3( 1, adr, reg );
119         break;
87120      }
88121      break;
89122   case 1:
r2724r2725
94127      case 8: case 9: case 0xa: case 0xb: case 0xc:
95128         saturn_copy(C, BEGIN_W, COUNT_W, R0+(reg&7));
96129         break; // c=r0 w
130      default:
131         saturn_invalid3( 1, adr, reg );
132         break;
97133      }
98134      break;
99135   case 2:
r2724r2725
104140      case 8: case 9: case 0xa: case 0xb: case 0xc:
105141         saturn_exchange(C, BEGIN_W, COUNT_W, R0+(reg&7));
106142         break; // cr0ex w
143      default:
144         saturn_invalid3( 2, adr, reg );
145         break;
107146      }
108147      break;
109148   case 3:
r2724r2725
159198         case 2: case 3: case 4: case 5: case 6: case 7:
160199            saturn_store_nibbles(oper&4?C:A,adr_a_begin[adr],adr_a_count[adr],oper&1);
161200            break;
201         default:
202            saturn_invalid4( 1, 5, oper, adr );
203            break;
162204         }
163205         break;
164206      case 2: case 3: case 6: case 7:
r2724r2725
172214         case 2: case 3: case 4: case 5: case 6: case 7:
173215            saturn_load_nibbles(oper&4?C:A,adr_a_begin[adr],adr_a_count[adr],oper&1);
174216            break;
217         default:
218            saturn_invalid4( 1, 5, oper, adr );
219            break;
175220         }
176221         break;
177222      case 8: saturn_store_nibbles(A, 0, READ_OP()+1, 0); break;
r2724r2725
184229      case 0xf: saturn_load_nibbles(C, 0, READ_OP()+1, 1); break;
185230      }
186231      break;
232   case 6: saturn_add_adr(0);break;
233   case 7: saturn_add_adr(1);break;
234   case 8: saturn_sub_adr(0);break;
187235   case 9: saturn_load_adr(0,2);break;
188236   case 0xa: saturn_load_adr(0,4);break;
189237   case 0xb: saturn_load_adr(0,5);break;
238   case 0xc: saturn_sub_adr(1);break;
190239   case 0xd: saturn_load_adr(1,2);break;
191240   case 0xe: saturn_load_adr(1,4);break;
192241   case 0xf: saturn_load_adr(1,5);break;
193   case 6: saturn_add_adr(0);break;
194   case 7: saturn_add_adr(1);break;
195   case 8: saturn_sub_adr(0);break;
196   case 0xc: saturn_sub_adr(1);break;
197242   }
198243}
199244
200245static void saturn_instruction_80(void)
201246{
247   int op;
202248   switch(READ_OP()) {
203249   case 0: saturn_out_cs();break;
204250   case 1: saturn_out_c();break;
r2724r2725
212258      switch(READ_OP()) {
213259      case 0: saturn_interrupt_on();break;
214260      case 1:
215         switch(READ_OP()) {
261         switch(op=READ_OP()) {
216262         case 0: saturn_reset_interrupt();break;
263         default: saturn_invalid5( 8, 0, 8, 1, op ); break;
217264         }
218265         break;
219266      case 2: saturn_load_reg(A);break; //la
220      case 3: saturn_bus_command_c();break;
267      case 3: saturn_bus_command_b();break;
221268      case 4: saturn_clear_bit(A);break; // abit=0
222269      case 5: saturn_set_bit(A);break; // abit=1
223270      case 6: saturn_jump_bit_clear(A);break;
r2724r2725
244291
245292static void saturn_instruction_81a(void)
246293{
247   int reg, adr;
294   int reg, adr,op;
248295   switch(adr=READ_OP()) {
249296   case 0:
250      switch(READ_OP()) {
297      switch(op=READ_OP()) {
251298      case 0:
252299         switch(reg=READ_OP()) {
253300         case 0: case 1: case 2: case 3: case 4:
r2724r2725
256303         case 8: case 9: case 0xa: case 0xb: case 0xc:
257304            saturn_copy(R0+(reg&7),saturn.p,1,C);
258305            break; //r0=c p
306         default:
307            saturn_invalid6( 8, 1, 0xa, adr, op, reg);
308            break;
259309         }
260310         break;
261311      case 1:
r2724r2725
266316         case 8: case 9: case 0xa: case 0xb: case 0xc:
267317            saturn_copy(C,saturn.p,1,R0+(reg&7));
268318            break; //c=r0 p
319         default:
320            saturn_invalid6( 8, 1, 0xa, adr, op, reg);
321            break;
269322         }
270323         break;
271324      case 2:
r2724r2725
276329         case 8: case 9: case 0xa: case 0xb: case 0xc:
277330            saturn_exchange(C, saturn.p,1,R0+(reg&7));
278331            break; // cr0ex p
332         default:
333            saturn_invalid6( 8, 1, 0xa, adr, op, reg);
334            break;
279335         }
280336         break;
337      default:
338         saturn_invalid5( 8, 1, 0xa, adr, op );
339         break;
281340      }
282341      break;
283342   case 1:
284      switch(READ_OP()) {
343      switch(op=READ_OP()) {
285344      case 0:
286345         switch(reg=READ_OP()) {
287346         case 0: case 1: case 2: case 3: case 4:
r2724r2725
290349         case 8: case 9: case 0xa: case 0xb: case 0xc:
291350            saturn_copy(R0+(reg&7),0,saturn.p+1,C);
292351            break; //r0=c wp
352         default:
353            saturn_invalid6( 8, 1, 0xa, adr, op, reg);
354            break;
293355         }
294356         break;
295357      case 1:
r2724r2725
300362         case 8: case 9: case 0xa: case 0xb: case 0xc:
301363            saturn_copy(C,0,saturn.p+1,R0+(reg&7));
302364            break; //c=r0 wp
365         default:
366            saturn_invalid6( 8, 1, 0xa, adr, op, reg);
367            break;
303368         }
304369         break;
305370      case 2:
r2724r2725
310375         case 8: case 9: case 0xa: case 0xb: case 0xc:
311376            saturn_exchange(C, 0, saturn.p+1, R0+(reg&7));
312377            break; // cr0ex wp
378         default:
379            saturn_invalid6( 8, 1, 0xa, adr, op, reg);
380            break;
313381         }
314382         break;
383      default:
384         saturn_invalid5( 8, 1, 0xa, adr, op );
385         break;
315386      }
316387      break;
317388   case 2: case 3: case 4: case 5: case 6: case 7: case 0xf:
318      switch(READ_OP()) {
389      switch(op=READ_OP()) {
319390      case 0:
320391         switch(reg=READ_OP()) {
321392         case 0: case 1: case 2: case 3: case 4:
r2724r2725
324395         case 8: case 9: case 0xa: case 0xb: case 0xc:
325396            saturn_copy(R0+(reg&7),adr_af_begin[adr], adr_af_count[adr],C);
326397            break; //r0=c xs
398         default:
399            saturn_invalid6( 8, 1, 0xa, adr, op, reg);
400            break;
327401         }
328402         break;
329403      case 1:
r2724r2725
334408         case 8: case 9: case 0xa: case 0xb: case 0xc:
335409            saturn_copy(C,adr_af_begin[adr],adr_af_count[adr],R0+(reg&7));
336410            break; //c=r0 xs
411         default:
412            saturn_invalid6( 8, 1, 0xa, adr, op, reg);
413            break;
337414         }
338415         break;
339416      case 2:
r2724r2725
344421         case 8: case 9: case 0xa: case 0xb: case 0xc:
345422            saturn_exchange(C, adr_af_begin[adr], adr_af_count[adr], R0+(reg&7));
346423            break; // cr0ex xs
424         default:
425            saturn_invalid6( 8, 1, 0xa, adr, op, reg);
426            break;
347427         }
348428         break;
429      default:
430         saturn_invalid5( 8, 1, 0xa, adr, op );
431         break;
349432      }
350433      break;
434   default:
435      saturn_invalid4( 8, 1, 0xa, adr );
436      break;
351437   }
352438}
353439
r2724r2725
368454            saturn_add_const(A+reg, saturn.p, 1, READ_OP()+1);
369455            break;
370456         case 8: case 9: case 0xa: case 0xb:
371            saturn_sub_const(A+reg, saturn.p, 1, READ_OP()+1);
457            saturn_sub_const(A+(reg&3), saturn.p, 1, READ_OP()+1);
372458            break;
459         default:
460            saturn_invalid5( 8, 1, 8, adr, reg );
461            break;
373462         }
374463         break;
375464      case 1:
376465         switch (reg=READ_OP()) {
377466         case 0: case 1: case 2: case 3:
378            saturn_add_const(A+reg, 1, saturn.p+1, READ_OP()+1);
467            saturn_add_const(A+reg, 0, saturn.p+1, READ_OP()+1);
379468            break;
380469         case 8: case 9: case 0xa: case 0xb:
381            saturn_sub_const(A+reg, 1, saturn.p+1, READ_OP()+1);
470            saturn_sub_const(A+(reg&3), 0, saturn.p+1, READ_OP()+1);
382471            break;
472         default:
473            saturn_invalid5( 8, 1, 8, adr, reg );
474            break;
383475         }
384476         break;
385477      case 2: case 3: case 4: case 5: case 6: case 7: case 0xf:
r2724r2725
388480            saturn_add_const(A+reg, adr_af_begin[adr], adr_af_count[adr], READ_OP()+1);
389481            break;
390482         case 8: case 9: case 0xa: case 0xb:
391            saturn_sub_const(A+reg, adr_af_begin[adr], adr_af_count[adr], READ_OP()+1);
483            saturn_sub_const(A+(reg&3), adr_af_begin[adr], adr_af_count[adr], READ_OP()+1);
392484            break;
485         default:
486            saturn_invalid5( 8, 1, 8, adr, reg );
487            break;
393488         }
394489         break;
490      default:
491         saturn_invalid4( 8, 1, 8, adr );
492         break;
395493      }
396494      break;
397495   case 9:
r2724r2725
401499         case 0: case 1: case 2: case 3:
402500            saturn_shift_right(A+reg,saturn.p,1);
403501            break; // asrb p
502         default:
503            saturn_invalid5( 8, 1, 9, adr, reg );
504            break;
404505         }
405506         break;
406507      case 1:
r2724r2725
408509         case 0: case 1: case 2: case 3:
409510            saturn_shift_right(A+reg, 0,saturn.p+1);
410511            break; // asrb wp
512         default:
513            saturn_invalid5( 8, 1, 9, adr, reg );
514            break;
411515         }
412516         break;
413      case 2: /*case 3:*/ case 4: case 5: case 6:/* case 7:*/case 0xf:
517      case 2: case 3: case 4: case 5: case 6: case 7: case 0xf:
414518         switch(reg=READ_OP()){
415519         case 0: case 1: case 2: case 3:
416520            saturn_shift_right(A+reg, adr_af_begin[adr], adr_af_count[adr]);
417521            break; // asrb xs
522         default:
523            saturn_invalid5( 8, 1, 9, adr, reg );
524            break;
418525         }
419526         break;
527      default:
528         saturn_invalid4( 8, 1, 9, adr );
529         break;
420530      }
421531      break;
422532   case 0xa:
423533      saturn_instruction_81a();
424534      break;
425535   case 0xb:
426      switch(READ_OP()) {
536      switch(adr=READ_OP()) {
427537      case 2: saturn_load_pc(A);break;
428538      case 3: saturn_load_pc(C);break;
429539      case 4: saturn_store_pc(A);break;
430540      case 5: saturn_store_pc(C);break;
431541      case 6: saturn_exchange_pc(A);break;
432542      case 7: saturn_exchange_pc(C);break;
543      default: saturn_invalid4( 8, 1, reg, adr ); break;
433544      }
434545      break;
435546   case 0xc: case 0xd: case 0xe: case 0xf:
r2724r2725
440551
441552static void saturn_instruction_8(void)
442553{
443   int oper;
554   int oper, adr;
444555
445556   switch(READ_OP()) {
446557   case 0:
r2724r2725
489600         break;
490601      }
491602      break;
492   case 0xc: saturn_jump((READ_OP_DIS16()+saturn.pc-4)&0xfffff,1);break;
493   case 0xd: saturn_jump(READ_OP_ARG20(),1);break;
494   case 0xe: saturn_call((READ_OP_DIS16()+saturn.pc)&0xfffff);break;
495   case 0xf: saturn_call(READ_OP_ARG20());break;
603   case 0xc:
604      adr=READ_OP_DIS16();
605      saturn_jump((adr+saturn.pc-4)&0xfffff,1);
606      break;
607   case 0xd:
608      adr=READ_OP_ARG20();
609      saturn_jump(adr,1);
610      break;
611   case 0xe:
612      adr=READ_OP_DIS16();
613      saturn_call((adr+saturn.pc)&0xfffff);
614      break;
615   case 0xf:
616      adr=READ_OP_ARG20();
617      saturn_call(adr);
618      break;
496619   }
497620}
498621
r2724r2725
533656         break;
534657      }
535658      break;
536   case 2: case 3: case 4: case 5:
537   case 6: case 7:
659   case 2: case 3: case 4: case 5: case 6: case 7:
538660      switch(oper=READ_OP()) {
539661      case 0: case 1: case 2: case 3:
540662         saturn_equals(reg_left[oper&3] ,adr_a_begin[adr], adr_a_count[adr], reg_right[oper&3]);
r2724r2725
612734      case 8: case 9: case 0xa: case 0xb:
613735         saturn_add(add_left[reg], saturn.p, 1, add_right[reg]);
614736         break;
615         break;
616737      case 4: case 5: case 6: case 7:
617         saturn_shift_left(A+(reg&3), saturn.p, 1);
738         saturn_add(A+(reg&3), saturn.p, 1, A+(reg&3));
618739         break;
619740      case 0xc: case 0xd: case 0xe: case 0xf:
620741         saturn_decrement(A+(reg&3), saturn.p, 1);
r2724r2725
625746      switch (reg=READ_OP()) {
626747      case 0: case 1: case 2: case 3:
627748      case 8: case 9: case 0xa: case 0xb:
628         saturn_add(add_left[reg], 1, saturn.p+1, add_right[reg]);
749         saturn_add(add_left[reg], 0, saturn.p+1, add_right[reg]);
629750         break;
630751      case 4: case 5: case 6: case 7:
631         saturn_shift_left(A+(reg&3), 1, saturn.p+1);
752         saturn_add(A+(reg&3), 0, saturn.p+1, A+(reg&3));
632753         break;
633754      case 0xc: case 0xd: case 0xe: case 0xf:
634         saturn_decrement(A+(reg&3), 1, saturn.p+1);
755         saturn_decrement(A+(reg&3), 0, saturn.p+1);
635756         break;
636757      }
637758      break;
r2724r2725
642763         saturn_add(add_left[reg], adr_a_begin[adr], adr_a_count[adr], add_right[reg]);
643764         break;
644765      case 4: case 5: case 6: case 7:
645         saturn_shift_left(A+(reg&3), adr_a_begin[adr], adr_a_count[adr]);
766         saturn_add(A+(reg&3), adr_a_begin[adr], adr_a_count[adr], A+(reg&3));
646767         break;
647768      case 0xc: case 0xd: case 0xe: case 0xf:
648769         saturn_decrement(A+(reg&3), adr_a_begin[adr], adr_a_count[adr]);
r2724r2725
656777         break; // a=0 p
657778      case 4: case 5: case 6: case 7:
658779      case 8: case 9: case 0xa: case 0xb:
659         saturn_copy(reg_right[reg&7], saturn.p,1,reg_left[reg&7]); //!correct
780         saturn_copy(reg_right[reg&7], saturn.p,1,reg_left[reg&7]);
660781         break; // a=b p
661782      case 0xc: case 0xd: case 0xe: case 0xf:
662783         saturn_exchange(reg_left[reg&3], saturn.p,1,reg_right[reg&3]);
r2724r2725
670791         break; // a=0 wp
671792      case 4: case 5: case 6: case 7:
672793      case 8: case 9: case 0xa: case 0xb:
673         saturn_copy(reg_right[reg&7], 0, saturn.p+1, reg_left[reg&7]); //!correct
794         saturn_copy(reg_right[reg&7], 0, saturn.p+1, reg_left[reg&7]);
674795         break; // a=b wp
675796      case 0xc: case 0xd: case 0xe: case 0xf:
676797         saturn_exchange(reg_left[reg&3], 0, saturn.p+1, reg_right[reg&3]);
r2724r2725
684805         break; // a=0 xs
685806      case 4: case 5: case 6: case 7:
686807      case 8: case 9: case 0xa: case 0xb:
687         saturn_copy(reg_right[reg&7], adr_b_begin[adr], adr_b_count[adr],
688                  reg_left[reg&7]); //correct
808         saturn_copy(reg_right[reg&7], adr_b_begin[adr], adr_b_count[adr], reg_left[reg&7]);
689809         break; // a=b xs
690810      case 0xc: case 0xd: case 0xe: case 0xf:
691         saturn_exchange(reg_left[reg&3], adr_b_begin[adr], adr_b_count[adr],
692                     reg_right[reg&3]);
811         saturn_exchange(reg_left[reg&3], adr_b_begin[adr], adr_b_count[adr], reg_right[reg&3]);
693812         break; // abex xs
694813      }
695814      break;
r2724r2725
705824      switch(reg=READ_OP()) {
706825      case 0: case 1: case 2: case 3:
707826      case 8: case 9: case 0xa: case 0xb:
708         saturn_sub(sub_left[reg], saturn.p, 1, S64_READ_P(sub_right[reg]));
827         saturn_sub(sub_left[reg], saturn.p, 1, sub_right[reg]);
709828         break;
710829      case 4: case 5: case 6: case 7:
711830         saturn_increment(A+(reg&3), saturn.p, 1); break; // a=a+1 p
712831      case 0xc: case 0xd: case 0xe: case 0xf:
713         saturn_sub2(sub_left[reg], saturn.p, 1, S64_READ_P(sub_right[reg]));
832         saturn_sub2(sub_left[reg], saturn.p, 1, sub_right[reg]);
714833         break;
715834      }
716835      break;
r2724r2725
718837      switch(reg=READ_OP()) {
719838      case 0: case 1: case 2: case 3:
720839      case 8: case 9: case 0xa: case 0xb:
721         saturn_sub(sub_left[reg], 1, saturn.p+1, sub_right[reg]);
840         saturn_sub(sub_left[reg], 0, saturn.p+1, sub_right[reg]);
722841         break;
723842      case 4: case 5: case 6: case 7:
724         saturn_increment(A+(reg&3), 1, saturn.p+1); break; // a=a+1 wp
843         saturn_increment(A+(reg&3), 0, saturn.p+1); break; // a=a+1 wp
725844      case 0xc: case 0xd: case 0xe: case 0xf:
726         saturn_sub2(sub_left[reg], 1, saturn.p+1, sub_right[reg]);
845         saturn_sub2(sub_left[reg], 0, saturn.p+1, sub_right[reg]);
727846         break;
728847      }
729848      break;
r2724r2725
731850      switch(reg=READ_OP()) {
732851      case 0: case 1: case 2: case 3:
733852      case 8: case 9: case 0xa: case 0xb:
734         saturn_sub(sub_left[reg], adr_a_begin[adr], adr_a_count[adr],
735                  sub_right[reg]);
853         saturn_sub(sub_left[reg], adr_a_begin[adr], adr_a_count[adr], sub_right[reg]);
736854         break;
737855      case 4: case 5: case 6: case 7:
738856         saturn_increment(A+(reg&3), adr_a_begin[adr], adr_a_count[adr]);
r2724r2725
750868      case 4: case 5: case 6: case 7:
751869         saturn_shift_nibble_right(A+(reg&3), saturn.p, 1); break; // asr p
752870      case 8: case 9: case 0xa: case 0xb:
753         saturn_invert(A+(reg&3), saturn.p, 1); break; // A=-A p
871         saturn_negate(A+(reg&3), saturn.p, 1); break; // A=-A p
754872      case 0xc: case 0xd: case 0xe: case 0xf:
755         saturn_negate(A+(reg&3), saturn.p, 1); break; // A=-A-1 p
873         saturn_invert(A+(reg&3), saturn.p, 1); break; // A=-A-1 p
756874      }
757875      break;
758876   case 9:
r2724r2725
762880      case 4: case 5: case 6: case 7:
763881         saturn_shift_nibble_right(A+(reg&3),0,saturn.p+1); break; // asr wp
764882      case 8: case 9: case 0xa: case 0xb:
765         saturn_invert(A+(reg&3),0,saturn.p+1); break; // A=-A wp
883         saturn_negate(A+(reg&3),0,saturn.p+1); break; // A=-A wp
766884      case 0xc: case 0xd: case 0xe: case 0xf:
767         saturn_negate(A+(reg&3),0,saturn.p+1); break; // A=-A-1 wp
885         saturn_invert(A+(reg&3),0,saturn.p+1); break; // A=-A-1 wp
768886      }
769887      break;
770888   case 0xa: case 0xb: case 0xc: case 0xd: case 0xe: case 0xf:
r2724r2725
776894         saturn_shift_nibble_right(A+(reg&3), adr_b_begin[adr], adr_b_count[adr]);
777895         break;
778896      case 8: case 9: case 0xa: case 0xb:
779         saturn_invert(A+(reg&3), adr_b_begin[adr], adr_b_count[adr]);
897         saturn_negate(A+(reg&3), adr_b_begin[adr], adr_b_count[adr]);
780898         break;
781899      case 0xc: case 0xd: case 0xe: case 0xf:
782         saturn_negate(A+(reg&3), adr_b_begin[adr], adr_b_count[adr]);
900         saturn_invert(A+(reg&3), adr_b_begin[adr], adr_b_count[adr]);
783901         break;
784902      }
785903      break;
r2724r2725
806924      case 9: saturn_st_to_c();break;
807925      case 0xa: saturn_c_to_st();break;
808926      case 0xb: saturn_exchange_c_st();break;
809      case 0xc:
810         saturn_inc_p();
811         break;
812      case 0xd:
813         saturn_dec_p();
814         break;
927      case 0xc: saturn_inc_p();break;
928      case 0xd: saturn_dec_p();break;
929      case 0xe: saturn_instruction_0e();break;
815930      case 0xf: saturn_return_interrupt();break;
816      case 0xe:
817         saturn_instruction_0e();
818         break;
819931      }
820932      break;
821933   case 1:
r2724r2725
824936   case 2:
825937      saturn_load_p();
826938      break;
827   case 3: saturn_load_reg(C);break; // lc
939   case 3:
940      saturn_load_reg(C);
941      break; // lc
828942   case 4:
829943      adr=READ_OP_DIS8();
830944      if (adr==0) {
831945         saturn_return(saturn.carry);
832      } else {
946      }
947      else {
833948         saturn_jump((saturn.pc+adr-2)&0xfffff, saturn.carry);
834949      }
835950      break;
r2724r2725
837952      adr=READ_OP_DIS8();
838953      if (adr==0) {
839954         saturn_return(!saturn.carry);
840      } else {
955      }
956      else {
841957         saturn_jump((saturn.pc+adr-2)&0xfffff,!saturn.carry);
842958      }
843959      break;
r2724r2725
866982         saturn_add(add_left[reg], BEGIN_A, COUNT_A, add_right[reg]);
867983         break;
868984      case 4: case 5: case 6: case 7:
869         saturn_shift_left(A+(reg&3), BEGIN_A, COUNT_A);
985         saturn_add(A+(reg&3), BEGIN_A, COUNT_A, A+(reg&3));
870986         break;
871987      case 0xc: case 0xd: case 0xe: case 0xf:
872988         saturn_decrement(A+(reg&3), BEGIN_A, COUNT_A);
r2724r2725
880996         break; // a=0 a
881997      case 4: case 5: case 6: case 7:
882998      case 8: case 9: case 0xa: case 0xb:
883         saturn_copy(reg_right[reg&7], BEGIN_A, COUNT_A, reg_left[reg&7]); //correct
999         saturn_copy(reg_right[reg&7], BEGIN_A, COUNT_A, reg_left[reg&7]);
8841000         break; // a=b a
8851001      case 0xc: case 0xd: case 0xe: case 0xf:
8861002         saturn_exchange(reg_left[reg&3], BEGIN_A, COUNT_A, reg_right[reg&3]);
r2724r2725
8911007      switch(reg=READ_OP()) {
8921008      case 0: case 1: case 2: case 3:
8931009      case 8: case 9: case 0xa: case 0xb:
894         saturn_sub(sub_left[reg], BEGIN_A, COUNT_A, S64_READ_A(sub_right[reg]));
1010         saturn_sub(sub_left[reg], BEGIN_A, COUNT_A, sub_right[reg]);
8951011         break;
8961012      case 4: case 5: case 6: case 7:
8971013         saturn_increment(A+(reg&3), BEGIN_A, COUNT_A);
8981014         break; // a=a+1 a
8991015      case 0xc: case 0xd: case 0xe: case 0xf:
900         saturn_sub2(sub_left[reg], BEGIN_A, COUNT_A, S64_READ_A(sub_right[reg]));
1016         saturn_sub2(sub_left[reg], BEGIN_A, COUNT_A, sub_right[reg]);
9011017         break;
9021018      }
9031019      break;
r2724r2725
9101026         saturn_shift_nibble_right(A+(reg&3),BEGIN_A, COUNT_A);
9111027         break; // asr a
9121028      case 8: case 9: case 0xa: case 0xb:
913         saturn_invert(A+(reg&3),BEGIN_A, COUNT_A);
1029         saturn_negate(A+(reg&3),BEGIN_A, COUNT_A);
9141030         break; // A=-A a
9151031      case 0xc: case 0xd: case 0xe: case 0xf:
916         saturn_negate(A+(reg&3),BEGIN_A, COUNT_A);
1032         saturn_invert(A+(reg&3),BEGIN_A, COUNT_A);
9171033         break; // A=-A-1 a
9181034      }
9191035      break;
src/emu/cpu/saturn/saturn.h
r2724r2725
66 *
77 *   Copyright Peter Trauner, all rights reserved.
88 *
9 *   Modified by Antoine Mine'
10 *
911 *   - This source code is released as freeware for non-commercial purposes.
1012 *   - You are free to use and redistribute this code in modified or
1113 *     unmodified form, provided you list me in the credits.
r2724r2725
4951
5052typedef struct
5153{
52   void (*out)(int);
53   int (*in)(void);
54   void (*reset)(void);
55   void (*config)(int v);
56   void (*unconfig)(int v);
57   int (*id)(void);
58   void (*crc)(int addr, int data);
54   void (*out)(running_machine*,int);
55   int (*in)(running_machine*);
56   void (*reset)(running_machine*);
57   void (*config)(running_machine*,int v);
58   void (*unconfig)(running_machine*,int v);
59   int (*id)(running_machine*);
60   void (*crc)(running_machine*,int addr, int data);
61   void (*rsi)(running_machine*);
5962} SATURN_CONFIG;
6063
64enum {
65   SATURN_A=1, SATURN_B, SATURN_C, SATURN_D,
66   SATURN_R0, SATURN_R1, SATURN_R2, SATURN_R3, SATURN_R4,
67   SATURN_RSTK0, SATURN_RSTK1, SATURN_RSTK2, SATURN_RSTK3,
68   SATURN_RSTK4, SATURN_RSTK5, SATURN_RSTK6, SATURN_RSTK7,
69   SATURN_PC, SATURN_D0, SATURN_D1,
70
71   SATURN_P,
72   SATURN_OUT,
73   SATURN_CARRY,
74   SATURN_ST,
75   SATURN_HST,
76
77   SATURN_IRQ_STATE,
78   SATURN_SLEEPING,
79};
80
81#define SATURN_IRQ_LINE 0
82#define SATURN_NMI_LINE 1
83#define SATURN_WAKEUP_LINE 2
84
6185#ifdef ENABLE_DEBUGGER
6286unsigned saturn_dasm(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram);
6387#endif /* ENABLE_DEBUGGER */
src/emu/cpu/saturn/saturnds.c
r2724r2725
11/*****************************************************************************
22 *
3 *   saturn.c
3 *   saturnds.c
44 *   portable saturn emulator interface
55 *   (hp calculators)
66 *
77 *   Copyright Peter Trauner, all rights reserved.
88 *
9 *   Modified by Antoine Mine'
10 *
911 *   - This source code is released as freeware for non-commercial purposes.
1012 *   - You are free to use and redistribute this code in modified or
1113 *     unmodified form, provided you list me in the credits.
r2724r2725
2426#include "debugger.h"
2527
2628#include "saturn.h"
27#include "sat.h"
2829
30#define SATURN_HP_MNEMONICS
31
2932#if defined SATURN_HP_MNEMONICS
3033// class/hp mnemonics
3134static int set=0;
r2724r2725
5154{ P, WP, XS, X, S, M, B, W, 0, 0, 0, 0, 0, 0, 0, A };
5255
5356static const char *const adr_a[]=
54{ P, WP, XS, X, S, M, B, W };
57  { P, WP, XS, X, S, M, B, W };
5558
5659static const char number_2_hex[]=
5760{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
r2724r2725
8083   CcopyP, PcopyC, sreq, CswapP,
8184
8285   inton, AloadImm, buscb,
83   clearAbit, setAbit, Abitclear, Abitset,
84   clearCbit, setCbit, Cbitclear, Cbitset,
86   clearAbit, setAbit,
87   branchAbitclear, returnAbitclear,
88   branchAbitset, returnAbitset,
89   clearCbit, setCbit,
90   branchCbitclear, returnCbitclear,
91   branchCbitset, returnCbitset,
8592   PCloadA, buscd, PCloadC, intoff, rsi,
8693
8794   jumpA, jumpC, PCcopyA, PCcopyC, AcopyPC, CcopyPC,
r2724r2725
132139   branchDnotgreaterC, returnDnotgreaterC,
133140
134141   SetHexMode, SetDecMode,
135   PopC, PushC,
142   PushC, PopC,
136143
137144   D0loadImm2, D0loadImm4, D0loadImm5,
138145   D1loadImm2, D1loadImm4, D1loadImm5,
r2724r2725
232239   { { "Abit=0  %x",         "CLRB     %x,A" } },
233240   { { "Abit=1  %x",         "SETB     %x,A" } },
234241   { { "?Abit=0 %x,%05x",      "BRBC     %x,A,%05x" } },
242   { { "?Abit=0 %x,rtn",      "RETBC    %x,A" } },
235243   { { "?Abit=1 %x,%05x",      "BRBS     %x,A,%05x" } },
244   { { "?Abit=1 %x,rtn",      "RETBS    %x,A" } },
236245   { { "Cbit=0  %x",         "CLRB     %x,C" } },
237246   { { "Cbit=1  %x",         "SETB     %x,C" } },
238247   { { "?Cbit=0 %x,%05x",      "BRBC     %x,C,%05x" } },
248   { { "?Cbit=0 %x,rtn",      "RETBC    %x,C" } },
239249   { { "?Cbit=1 %x,%05x",      "BRBS     %x,C,%05x" } },
250   { { "?Cbit=1 %x,rtn",      "RETBS    %x,C" } },
240251   { { "PC=(A)",               "JUMP.A   @A" } },
241252   { { "!buscd",            "!BUSCD" } },
242253   { { "PC=(C)",            "JUMP.A   @C" } },
r2724r2725
252263
253264   { { "HST=0   %x",         "CLRHST   %x" } },
254265   { { "?HST=0  %x,%05x",      "BRBCHST  %x,%05x" } },
255   { { "?HST=0  %x",         "RETBCHST %x" } },
266   { { "?HST=0  %x,rtn",         "RETBCHST %x" } },
256267   { { "ST=0    %x",         "CLRB     %x,ST" } },
257268   { { "ST=1    %x",         "SETB     %x,ST" } },
258269   { { "?ST=0   %x,%05x",      "BRBC     ST,%x,%05x" } },
259   { { "?ST=0   %x",         "RETBC    ST,%x" } },
270   { { "?ST=0   %x,rtn",         "RETBC    ST,%x" } },
260271   { { "?ST=1   %x,%05x",      "BRBS     ST,%x,%05x" } },
261   { { "?ST=1   %x",         "RETBS    ST,%x" } },
272   { { "?ST=1   %x,rtn",         "RETBS    ST,%x" } },
262273   { { "?P#     %x,%05x",      "BRNE     P,%x,%05x" } },
263   { { "?P#     %x",         "RETNE    P,%x" } },
274   { { "?P#     %x,rtn",         "RETNE    P,%x" } },
264275   { { "?P=     %x,%05x",      "BREQ     P,%x,%05x" } },
265   { { "?P=     %x",         "RETEQ    P,%x" } },
276   { { "?P=     %x,rtn",         "RETEQ    P,%x" } },
266277
267   { { "?A=B    %x,%05x",      "BREQ.%-2s  A,B,%05x" } },
268   { { "?A=B    %x",         "RETEQ.%-2s A,B" } },
269   { { "?B=C    %x,%05x",      "BREQ.%-2s  B,C,%05x" } },
270   { { "?B=C    %x",         "RETEQ.%-2s B,C" } },
271   { { "?A=C    %x,%05x",      "BREQ.%-2s  A,C,%05x" } },
272   { { "?A=C    %x",         "RETEQ.%-2s A,C" } },
273   { { "?C=D    %x,%05x",      "BREQ.%-2s  C,D,%05x" } },
274   { { "?C=D    %x",         "RETEQ.%-2s C,D" } },
275   { { "?A#B    %x,%05x",      "BRNE.%-2s  A,B,%05x" } },
276   { { "?A#B    %x",         "RETNE.%-2s A,B" } },
277   { { "?B#C    %x,%05x",      "BRNE.%-2s  B,C,%05x" } },
278   { { "?B#C    %x",         "RETNE.%-2s B,C" } },
279   { { "?A#C    %x,%05x",      "BRNE.%-2s  A,C,%05x" } },
280   { { "?A#C    %x",         "RETNE.%-2s A,C" } },
281   { { "?C#D    %x,%05x",      "BRNE.%-2s  C,D,%05x" } },
282   { { "?C#D    %x",         "RETNE.%-2s C,D" } },
283   { { "?A=0    %x,%05x",      "BRZ.%-2s   A,%05x" } },
284   { { "?A=0    %x",         "RETZ.%-2s  A" } },
285   { { "?B=0    %x,%05x",      "BRZ.%-2s   B,%05x" } },
286   { { "?B=0    %x",         "RETZ.%-2s  B" } },
287   { { "?C=0    %x,%05x",      "BRZ.%-2s   C,%05x" } },
288   { { "?C=0    %x",         "RETZ.%-2s  C" } },
289   { { "?D=0    %x,%05x",      "BRZ.%-2s   D,%05x" } },
290   { { "?D=0    %x",         "RETZ.%-2s  D" } },
291   { { "?A#0    %x,%05x",      "BRNZ.%-2s  A,%05x" } },
292   { { "?A#0    %x",         "RETNZ.%-2s A" } },
293   { { "?B#0    %x,%05x",      "BRNZ.%-2s  B,%05x" } },
294   { { "?B#0    %x",         "RETNZ.%-2s B" } },
295   { { "?C#0    %x,%05x",      "BRNZ.%-2s  C,%05x" } },
296   { { "?C#0    %x",         "RETNZ.%-2s C" } },
297   { { "?D#0    %x,%05x",      "BRNZ.%-2s  D,%05x" } },
298   { { "?D#0    %x",         "RETNZ.%-2s D" } },
278   { { "?A=B    %s,%05x",      "BREQ.%-2s  A,B,%05x" } },
279   { { "?A=B    %s,rtn",         "RETEQ.%-2s A,B" } },
280   { { "?B=C    %s,%05x",      "BREQ.%-2s  B,C,%05x" } },
281   { { "?B=C    %s,rtn",         "RETEQ.%-2s B,C" } },
282   { { "?A=C    %s,%05x",      "BREQ.%-2s  A,C,%05x" } },
283   { { "?A=C    %s,rtn",         "RETEQ.%-2s A,C" } },
284   { { "?C=D    %s,%05x",      "BREQ.%-2s  C,D,%05x" } },
285   { { "?C=D    %s,rtn",         "RETEQ.%-2s C,D" } },
286   { { "?A#B    %s,%05x",      "BRNE.%-2s  A,B,%05x" } },
287   { { "?A#B    %s,rtn",         "RETNE.%-2s A,B" } },
288   { { "?B#C    %s,%05x",      "BRNE.%-2s  B,C,%05x" } },
289   { { "?B#C    %s,rtn",         "RETNE.%-2s B,C" } },
290   { { "?A#C    %s,%05x",      "BRNE.%-2s  A,C,%05x" } },
291   { { "?A#C    %s,rtn",         "RETNE.%-2s A,C" } },
292   { { "?C#D    %s,%05x",      "BRNE.%-2s  C,D,%05x" } },
293   { { "?C#D    %s,rtn",         "RETNE.%-2s C,D" } },
294   { { "?A=0    %s,%05x",      "BRZ.%-2s   A,%05x" } },
295   { { "?A=0    %s,rtn",         "RETZ.%-2s  A" } },
296   { { "?B=0    %s,%05x",      "BRZ.%-2s   B,%05x" } },
297   { { "?B=0    %s,rtn",         "RETZ.%-2s  B" } },
298   { { "?C=0    %s,%05x",      "BRZ.%-2s   C,%05x" } },
299   { { "?C=0    %s,rtn",         "RETZ.%-2s  C" } },
300   { { "?D=0    %s,%05x",      "BRZ.%-2s   D,%05x" } },
301   { { "?D=0    %s,rtn",         "RETZ.%-2s  D" } },
302   { { "?A#0    %s,%05x",      "BRNZ.%-2s  A,%05x" } },
303   { { "?A#0    %s,rtn",         "RETNZ.%-2s A" } },
304   { { "?B#0    %s,%05x",      "BRNZ.%-2s  B,%05x" } },
305   { { "?B#0    %s,rtn",         "RETNZ.%-2s B" } },
306   { { "?C#0    %s,%05x",      "BRNZ.%-2s  C,%05x" } },
307   { { "?C#0    %s,rtn",         "RETNZ.%-2s C" } },
308   { { "?D#0    %s,%05x",      "BRNZ.%-2s  D,%05x" } },
309   { { "?D#0    %s,rtn",         "RETNZ.%-2s D" } },
299310
300   { { "?A>B    %x,%05x",      "BRGT.%-2s  A,B,%05x" } },
301   { { "?A>B    %x",         "RETGT.%-2s A,B" } },
302   { { "?B>C    %x,%05x",      "BRGT.%-2s  B,C,%05x" } },
303   { { "?B>C    %x",         "RETGT.%-2s B,C" } },
304   { { "?C>A    %x,%05x",      "BRGT.%-2s  C,A,%05x" } },
305   { { "?C>A    %x",         "RETGT.%-2s C,A" } },
306   { { "?D>C    %x,%05x",      "BRGT.%-2s  D,C,%05x" } },
307   { { "?D>C    %x",         "RETGT.%-2s D,C" } },
308   { { "?A<B    %x,%05x",      "BRLT.%-2s  A,B,%05x" } },
309   { { "?A<B    %x",         "RETLT.%-2s A,B" } },
310   { { "?B<C    %x,%05x",      "BRLT.%-2s  B,C,%05x" } },
311   { { "?B<C    %x",         "RETLT.%-2s B,C" } },
312   { { "?C<A    %x,%05x",      "BRLT.%-2s  C,A,%05x" } },
313   { { "?C<A    %x",         "RETLT.%-2s C,A" } },
314   { { "?D<C    %x,%05x",      "BRLT.%-2s  D,C,%05x" } },
315   { { "?D<C    %x",         "RETLT.%-2s D,C" } },
316   { { "?A>=B   %x,%05x",      "BRGE.%-2s  A,B,%05x" } },
317   { { "?A>=B   %x",         "RETGE.%-2s A,B" } },
318   { { "?B>=C   %x,%05x",      "BRGE.%-2s  B,C,%05x" } },
319   { { "?B>=C   %x",         "RETGE.%-2s B,C" } },
320   { { "?C>=A   %x,%05x",      "BRGE.%-2s  C,A,%05x" } },
321   { { "?C>=A   %x",         "RETGE.%-2s C,A" } },
322   { { "?D>=C   %x,%05x",      "BRGE.%-2s  D,C,%05x" } },
323   { { "?D>=C   %x",         "RETGE.%-2s D,C" } },
324   { { "?A<=B   %x,%05x",      "BRLE.%-2s  A,B,%05x" } },
325   { { "?A<=B   %x",         "RETLE.%-2s A,B" } },
326   { { "?B<=C   %x,%05x",      "BRLE.%-2s  B,C,%05x" } },
327   { { "?B<=C   %x",         "RETLE.%-2s B,C" } },
328   { { "?C<=A   %x,%05x",      "BRLE.%-2s  C,A,%05x" } },
329   { { "?C<=A   %x",         "RETLE.%-2s C,A" } },
330   { { "?D<=C   %x,%05x",      "BRLE.%-2s  D,C,%05x" } },
331   { { "?D<=C   %x",         "RETLE.%-2s D,C" } },
311   { { "?A>B    %s,%05x",      "BRGT.%-2s  A,B,%05x" } },
312   { { "?A>B    %s,rtn",         "RETGT.%-2s A,B" } },
313   { { "?B>C    %s,%05x",      "BRGT.%-2s  B,C,%05x" } },
314   { { "?B>C    %s,rtn",         "RETGT.%-2s B,C" } },
315   { { "?C>A    %s,%05x",      "BRGT.%-2s  C,A,%05x" } },
316   { { "?C>A    %s,rtn",         "RETGT.%-2s C,A" } },
317   { { "?D>C    %s,%05x",      "BRGT.%-2s  D,C,%05x" } },
318   { { "?D>C    %s,rtn",         "RETGT.%-2s D,C" } },
319   { { "?A<B    %s,%05x",      "BRLT.%-2s  A,B,%05x" } },
320   { { "?A<B    %s,rtn",         "RETLT.%-2s A,B" } },
321   { { "?B<C    %s,%05x",      "BRLT.%-2s  B,C,%05x" } },
322   { { "?B<C    %s,rtn",         "RETLT.%-2s B,C" } },
323   { { "?C<A    %s,%05x",      "BRLT.%-2s  C,A,%05x" } },
324   { { "?C<A    %s,rtn",         "RETLT.%-2s C,A" } },
325   { { "?D<C    %s,%05x",      "BRLT.%-2s  D,C,%05x" } },
326   { { "?D<C    %s,rtn",         "RETLT.%-2s D,C" } },
327   { { "?A>=B   %s,%05x",      "BRGE.%-2s  A,B,%05x" } },
328   { { "?A>=B   %s,rtn",         "RETGE.%-2s A,B" } },
329   { { "?B>=C   %s,%05x",      "BRGE.%-2s  B,C,%05x" } },
330   { { "?B>=C   %s,rtn",         "RETGE.%-2s B,C" } },
331   { { "?C>=A   %s,%05x",      "BRGE.%-2s  C,A,%05x" } },
332   { { "?C>=A   %s,rtn",         "RETGE.%-2s C,A" } },
333   { { "?D>=C   %s,%05x",      "BRGE.%-2s  D,C,%05x" } },
334   { { "?D>=C   %s,rtn",         "RETGE.%-2s D,C" } },
335   { { "?A<=B   %s,%05x",      "BRLE.%-2s  A,B,%05x" } },
336   { { "?A<=B   %s,rtn",         "RETLE.%-2s A,B" } },
337   { { "?B<=C   %s,%05x",      "BRLE.%-2s  B,C,%05x" } },
338   { { "?B<=C   %s,rtn",         "RETLE.%-2s B,C" } },
339   { { "?C<=A   %s,%05x",      "BRLE.%-2s  C,A,%05x" } },
340   { { "?C<=A   %s,rtn",         "RETLE.%-2s C,A" } },
341   { { "?D<=C   %s,%05x",      "BRLE.%-2s  D,C,%05x" } },
342   { { "?D<=C   %s,rtn",         "RETLE.%-2s D,C" } },
332343
333344   { { "sethex",            "SETHEX" } },
334345   { { "setdec",            "SETDEC" } },
r2724r2725
456467   { { "A=A!C   %s",         "OR.%-2s    C,A" } },
457468   { { "C=C!D   %s",         "OR.%-2s    D,C" } },
458469
459   { { "Asrb    %x",         "SRB.%-2s   A" } },
460   { { "Bsrb    %x",         "SRB.%-2s   B" } },
461   { { "Csrb    %x",         "SRB.%-2s   C" } },
462   { { "Dsrb    %x",         "SRB.%-2s   D" } },
470   { { "Asrb    %s",         "SRB.%-2s   A" } },
471   { { "Bsrb    %s",         "SRB.%-2s   B" } },
472   { { "Csrb    %s",         "SRB.%-2s   C" } },
473   { { "Dsrb    %s",         "SRB.%-2s   D" } },
463474
464475   { { "Aslc    %s",         "RLN.%-2s   A" } },
465476   { { "Bslc    %s",         "RLN.%-2s   B" } },
466477   { { "Cslc    %s",         "RLN.%-2s   C" } },
467478   { { "Dslc    %s",         "RLN.%-2s   D" } },
468   { { "Aslc    %s",         "RRN.%-2s   A" } },
469   { { "Bslc    %s",         "RRN.%-2s   B" } },
470   { { "Cslc    %s",         "RRN.%-2s   C" } },
471   { { "Dslc    %s",         "RRN.%-2s   D" } },
479   { { "Asrc    %s",         "RRN.%-2s   A" } },
480   { { "Bsrc    %s",         "RRN.%-2s   B" } },
481   { { "Csrc    %s",         "RRN.%-2s   C" } },
482   { { "Dsrc    %s",         "RRN.%-2s   D" } },
472483
473484   { { "A=A+B   %s",         "ADD.%-2s   B,A" } },
474485   { { "B=B+C   %s",         "ADD.%-2s   C,B" } },
r2724r2725
566577      xBranchReturn, // address field specified in previous opcode entry
567578      Imm, ImmCount, ImmCload, Imm2, Imm4, Imm5,
568579      Dis3, Dis3Call, Dis4, Dis4Call, Abs,
569      FieldP, FieldWP, FieldXS, FieldX, FieldS, FieldM, FieldB, FieldW, FieldA
580      FieldP, FieldWP, FieldXS, FieldX, FieldS, FieldM, FieldB, FieldW, FieldA,
581      AdrImmCount
570582   } adr;
571583   MNEMONICS mnemonic;
572584} OPCODE;
r2724r2725
613625      { Complete,      AdrNone,      ReturnClearCarry },
614626      { Complete,      AdrNone,      SetHexMode },
615627      { Complete,      AdrNone,      SetDecMode },
628      { Complete,      AdrNone,      PushC },
616629      { Complete,      AdrNone,      PopC },
617      { Complete,      AdrNone,      PushC },
618630      { Complete,      AdrNone,      clearST },
619631      { Complete,      AdrNone,      CcopyST },
620632      { Complete,      AdrNone,      STcopyC },
r2724r2725
817829      { Complete,      AdrNone,      buscb },
818830      { Complete,      Imm,         clearAbit },
819831      { Complete,      Imm,         setAbit },
820      { Complete,      ImmBranch,      Abitclear },
821      { Complete,      ImmBranch,      Abitset },
832      { Complete,      TestBranchRet,      branchAbitclear },
833      { Complete,      TestBranchRet,      branchAbitset },
822834      { Complete,      Imm,         clearCbit },
823835      { Complete,      Imm,         setCbit },
824      { Complete,      ImmBranch,      Cbitclear },
825      { Complete,      ImmBranch,      Cbitset },
836      { Complete,      TestBranchRet,      branchCbitclear },
837      { Complete,      TestBranchRet,      branchCbitset },
826838      { Complete,      AdrNone,      PCloadA },
827839      { Complete,      AdrNone,      buscd },
828840      { Complete,      AdrNone,      PCloadC },
r2724r2725
833845   }, { //81
834846      { Complete,      FieldW,         AshiftleftCarry },
835847      { Complete,      FieldW,         BshiftleftCarry },
848      { Complete,      FieldW,         CshiftleftCarry },
836849      { Complete,      FieldW,         DshiftleftCarry },
837      { Complete,      FieldW,         DshiftleftCarry },
838850      { Complete,      FieldW,         AshiftrightCarry },
839      { Complete,      FieldW,         AshiftrightCarry },
840      { Complete,      FieldW,         AshiftrightCarry },
841      { Complete,      FieldW,         AshiftrightCarry },
851      { Complete,      FieldW,         BshiftrightCarry },
852      { Complete,      FieldW,         CshiftrightCarry },
853      { Complete,      FieldW,         DshiftrightCarry },
842854      { Opcode818 },
843855      { Opcode819 },
844856      { Opcode81A },
r2724r2725
865877      { Illegal },
866878      { Opcode818a,   AdrAF },
867879   }, { //818a
868      { Complete,      AdrNone,      AaddImm },
869      { Complete,      AdrNone,      BaddImm },
870      { Complete,      AdrNone,      CaddImm },
871      { Complete,      AdrNone,      DaddImm },
872      { Complete,      AdrNone,      AsubImm },
873      { Complete,      AdrNone,      BsubImm },
874      { Complete,      AdrNone,      CsubImm },
875      { Complete,      AdrNone,      DsubImm }
876      //! rest illegal
880      { Complete,      AdrImmCount,      AaddImm },
881      { Complete,      AdrImmCount,      BaddImm },
882      { Complete,      AdrImmCount,           CaddImm },
883      { Complete,      AdrImmCount,      DaddImm },
884      { Illegal },
885      { Illegal },
886      { Illegal },
887      { Illegal },
888      { Complete,      AdrImmCount,      AsubImm },
889      { Complete,      AdrImmCount,      BsubImm },
890      { Complete,      AdrImmCount,      CsubImm },
891      { Complete,      AdrImmCount,      DsubImm },
892      { Illegal },
893      { Illegal },
894      { Illegal },
895      { Illegal },
877896   }, { //819
878897      { Opcode819a,   AdrAF },
879898      { Opcode819a,   AdrAF },
r2724r2725
12691288
12701289   while (cont)
12711290   {
1272      op = oprom[pos++];
1291      op = oprom[pos++] & 0xf;
12731292      level+=op;
12741293      switch (level->sel) {
12751294      case Illegal:
r2724r2725
13111330         case ImmCount:
13121331            sprintf(dst, mnemonics[level->mnemonic].name[set], oprom[pos++]+1);
13131332            break;
1333         case AdrImmCount:
1334            sprintf(dst, mnemonics[level->mnemonic].name[set], field_2_string(adr), oprom[pos++]+1);
1335            break;
13141336         case AdrCount: // mnemonics have string %s for address field
13151337            snprintf(number,sizeof(number),"%x",oprom[pos++]+1);
13161338            sprintf(dst, mnemonics[level->mnemonic].name[set], number);
r2724r2725
13361358            sprintf(dst, mnemonics[level->mnemonic].name[set], v);
13371359            break;
13381360         case ImmCload:
1339            c=i=oprom[pos++];
1361            c=i=oprom[pos++] & 0xf;
13401362            number[i+1]=0;
1341            for (;i>=0; i--) number[i]=number_2_hex[oprom[pos++]];
1363            for (;i>=0; i--) number[i]=number_2_hex[oprom[pos++] & 0xf];
13421364            sprintf(dst, mnemonics[level->mnemonic].name[set], c+1, number);
13431365            break;
13441366         case Dis3:
13451367            SATURN_PEEKOP_DIS12(v);
1346            c=(pc+pos-3+v)%0xfffff;
1368            c=(pc+pos-3+v)&0xfffff;
13471369            sprintf(dst, mnemonics[level->mnemonic].name[set], c );
13481370            break;
13491371         case Dis3Call:
13501372            SATURN_PEEKOP_DIS12(v);
1351            c=(pc+pos-3+v)%0xfffff;
1373            c=(pc+pos+v)&0xfffff;
13521374            sprintf(dst, mnemonics[level->mnemonic].name[set], c );
13531375            break;
13541376         case Dis4:
13551377            SATURN_PEEKOP_DIS16(v);
1356            c=(pc+pos-4+v)%0xfffff;
1378            c=(pc+pos-4+v)&0xfffff;
13571379            sprintf(dst, mnemonics[level->mnemonic].name[set], c );
13581380            break;
13591381         case Dis4Call:
13601382            SATURN_PEEKOP_DIS16(v);
1361            c=(pc+pos-4+v)%0xfffff;
1383            c=(pc+pos+v)&0xfffff;
13621384            sprintf(dst, mnemonics[level->mnemonic].name[set], c );
13631385            break;
13641386         case Abs:
r2724r2725
14361458            sprintf(dst, mnemonics[level->mnemonic].name[set], W );
14371459            break;
14381460         case AdrA:
1439            sprintf(dst, mnemonics[level->mnemonic].name[set], adr_a[oprom[pos++]] );
1461            sprintf(dst, mnemonics[level->mnemonic].name[set], adr_a[oprom[pos++] & 0x7] );
14401462            break;
14411463         case AdrAF:
1442            sprintf(dst, mnemonics[level->mnemonic].name[set], adr_af[oprom[pos++]] );
1464            sprintf(dst, mnemonics[level->mnemonic].name[set], adr_af[oprom[pos++] & 0xf] );
14431465            break;
14441466         case AdrB:
1445            sprintf(dst, mnemonics[level->mnemonic].name[set], adr_b[oprom[pos++]&0x7] );
1467            sprintf(dst, mnemonics[level->mnemonic].name[set], adr_b[oprom[pos++] & 0x7] );
14461468            break;
14471469         }
14481470         break;
src/emu/cpu/saturn/satops.c
r2724r2725
11#define IRQ_ADDRESS   0xf
22
3#define saturn_assert(x) \
4   do { if (!(x)) logerror("SATURN%d assertion failed: %s at %s:%i, pc=%05x\n", cpu_getactivecpu(), #x, __FILE__, __LINE__, saturn.pc); } while (0)
5
36INLINE int READ_OP(void)
47{
8   UINT8 data;
59   saturn_ICount-=3;
6   return cpu_readop(saturn.pc++);
10        data=cpu_readop(saturn.pc);
11   saturn_assert(data<0x10);
12   saturn.pc=(saturn.pc+1)&0xfffff;
13   return data;
714}
815
916INLINE int READ_OP_ARG(void)
1017{
18   UINT8 data;
1119   saturn_ICount-=3;
12   return cpu_readop_arg(saturn.pc++);
20        data=cpu_readop_arg(saturn.pc);
21   saturn_assert(data<0x10);
22   saturn.pc=(saturn.pc+1)&0xfffff;
23   return data;
1324}
1425
1526INLINE int READ_OP_ARG8(void)
1627{
17   return READ_OP_ARG()|(READ_OP_ARG()<<4);
28   int n0=READ_OP_ARG();
29   int n1=READ_OP_ARG();
30   return n0|(n1<<4);
1831}
1932
2033INLINE INT8 READ_OP_DIS8(void)
2134{
22   return READ_OP_ARG()|(READ_OP_ARG()<<4);
35   return (INT8)READ_OP_ARG8();
2336}
2437
2538INLINE int READ_OP_ARG12(void)
2639{
27   return READ_OP_ARG()|(READ_OP_ARG()<<4)|(READ_OP_ARG()<<8);
40   int n0=READ_OP_ARG();
41   int n1=READ_OP_ARG();
42   int n2=READ_OP_ARG();
43   return n0|(n1<<4)|(n2<<8);
2844}
2945
3046INLINE int READ_OP_DIS12(void)
3147{
32   int temp=READ_OP_ARG()|(READ_OP_ARG()<<4)|(READ_OP_ARG()<<8);
33   if (temp&0x800) return -0x1000+temp;
34   else return temp;
48   int temp=READ_OP_ARG12();
49   if (temp&0x800) temp-=0x1000;
50   return temp;
3551}
3652
3753INLINE int READ_OP_ARG16(void)
3854{
39   return READ_OP_ARG()|(READ_OP_ARG()<<4)|(READ_OP_ARG()<<8)|(READ_OP_ARG()<<12);
55   int n0=READ_OP_ARG();
56   int n1=READ_OP_ARG();
57   int n2=READ_OP_ARG();
58   int n3=READ_OP_ARG();
59   return n0|(n1<<4)|(n2<<8)|(n3<<12);
4060}
4161
4262INLINE INT16 READ_OP_DIS16(void)
4363{
44   return READ_OP_ARG()|(READ_OP_ARG()<<4)|(READ_OP_ARG()<<8)|(READ_OP_ARG()<<12);
64   return (INT16)READ_OP_ARG16();
4565}
4666
4767INLINE int READ_OP_ARG20(void)
4868{
49   return READ_OP_ARG()|(READ_OP_ARG()<<4)|(READ_OP_ARG()<<8)
50      |(READ_OP_ARG()<<12)|(READ_OP_ARG()<<16);
69   int n0=READ_OP_ARG();
70   int n1=READ_OP_ARG();
71   int n2=READ_OP_ARG();
72   int n3=READ_OP_ARG();
73   int n4=READ_OP_ARG();
74   return n0|(n1<<4)|(n2<<8)|(n3<<12)|(n4<<16);
5175}
5276
5377INLINE int READ_NIBBLE(SaturnAdr adr)
5478{
55   int data;
79   UINT8 data;
5680   saturn_ICount-=3;
57   data = program_read_byte(adr);
58   if (saturn.config&&saturn.config->crc) saturn.config->crc(adr, data);
81   data=program_read_byte(adr&0xfffff);
82   saturn_assert(data<0x10);
83   if (saturn.config&&saturn.config->crc) saturn.config->crc(Machine, adr&0xfffff, data);
5984   return data;
6085}
6186
r2724r2725
7196
7297INLINE int READ_16(SaturnAdr adr)
7398{
74   return READ_NIBBLE(adr)|(READ_NIBBLE(adr+1)<<4)
75      |(READ_NIBBLE(adr+2)<<8)|(READ_NIBBLE(adr+3)<<12);
99   return READ_NIBBLE(adr)|(READ_NIBBLE(adr+1)<<4)|(READ_NIBBLE(adr+2)<<8)|(READ_NIBBLE(adr+3)<<12);
76100}
77101
78102INLINE int READ_20(SaturnAdr adr)
79103{
80   return READ_NIBBLE(adr)|(READ_NIBBLE(adr+1)<<4)
81      |(READ_NIBBLE(adr+2)<<8)|(READ_NIBBLE(adr+3)<<12)|(READ_NIBBLE(adr+4)<<16);
104   return READ_NIBBLE(adr)|(READ_NIBBLE(adr+1)<<4)|(READ_NIBBLE(adr+2)<<8)|(READ_NIBBLE(adr+3)<<12)|(READ_NIBBLE(adr+4)<<16);
82105}
83106
84107INLINE void WRITE_NIBBLE(SaturnAdr adr, SaturnNib nib)
85108{
86   saturn_ICount -= 3;
87   program_write_byte(adr, nib);
109   saturn_ICount-=3;
110   saturn_assert(nib<0x10);
111   program_write_byte(adr&0xfffff,nib);
88112}
89113
90#ifdef LSB_FIRST
91#define S64_BYTE(r, x) saturn.reg[r].b[x]
92#define S64_WORD(r, x) saturn.reg[r].w[x]
93#define S64_DOUBLE(r, x) saturn.reg[r].d[x]
94#else
95#define S64_BYTE(r, x) saturn.reg[r].b[7-x]
96#define S64_WORD(r, x) saturn.reg[r].w[3-x]
97#define S64_DOUBLE(r, x) saturn.reg[r].d[1-x]
98#endif
99
100#define S64_QUAD(r) saturn.reg[r].q
101
102114#define BEGIN_B 0
103115#define COUNT_B 2
104116#define BEGIN_X 0
r2724r2725
114126#define BEGIN_W 0
115127#define COUNT_W 16
116128
117#define S64_READ_NIBBLE(r, x) (((x)&1) ? (S64_BYTE(r, ((x)>>1))>>4) : (S64_BYTE(r, ((x)>>1))&0xf) )
118#define S64_WRITE_NIBBLE(r, x, v) \
119      (S64_BYTE(r, ((x)>>1)) = ((x)&1) \
120       ?(S64_BYTE(r, ((x)>>1))&0xf)|((v)<<4) \
121       :(S64_BYTE(r, ((x)>>1))&0xf0)|(v) )
122129
123#define S64_READ_B(r) S64_BYTE(r,0)
124#define S64_WRITE_B(r,v) (S64_BYTE(r,0)=v)
130INLINE int S64_READ_X(int r)
131{
132   return saturn.reg[r][0]|(saturn.reg[r][1]<<4)|(saturn.reg[r][2]<<8);
133}
125134
126#define S64_READ_XS(r) S64_READ_NIBBLE(r,2)
127#define S64_WRITE_XS(r,v) S64_WRITE_NIBBLE(r,2,v)
135INLINE int S64_READ_WORD(int r)
136{
137   return saturn.reg[r][0]|(saturn.reg[r][1]<<4)|(saturn.reg[r][2]<<8)|(saturn.reg[r][3]<<12);
138}
128139
129#define S64_READ_S(r) S64_READ_NIBBLE(r,15)
130#define S64_WRITE_S(r,v) S64_WRITE_NIBBLE(r,15,v)
140INLINE int S64_READ_A(int r)
141{
142   return saturn.reg[r][0]|(saturn.reg[r][1]<<4)|(saturn.reg[r][2]<<8)|(saturn.reg[r][3]<<12)|(saturn.reg[r][4]<<16);
143}
131144
132#define S64_READ_P(r) S64_READ_NIBBLE(r,saturn.p)
133#define S64_WRITE_P(r,v) S64_WRITE_NIBBLE(r,saturn.p,v)
145INLINE void S64_WRITE_X(int r, int v)
146{
147   saturn.reg[r][0]=v&0xf;
148   saturn.reg[r][1]=(v>>4)&0xf;
149   saturn.reg[r][2]=(v>>8)&0xf;
150}
134151
135#define S64_READ_X(r) (S64_WORD(r,0)&0xfff)
136#define S64_WRITE_X(r,v) (S64_WORD(r,0)=(S64_WORD(r,0)&~0xfff)|(v))
152INLINE void S64_WRITE_WORD(int r, int v)
153{
154   saturn.reg[r][0]=v&0xf;
155   saturn.reg[r][1]=(v>>4)&0xf;
156   saturn.reg[r][2]=(v>>8)&0xf;
157   saturn.reg[r][3]=(v>>12)&0xf;
158}
137159
138// for address reg operations
139#define S64_READ_WORD(r,nr) S64_WORD(r,nr)
140#define S64_WRITE_WORD(r,nr,v) (S64_WORD(r,nr)=v)
160INLINE void S64_WRITE_A(int r, int v)
161{
162   saturn.reg[r][0]=v&0xf;
163   saturn.reg[r][1]=(v>>4)&0xf;
164   saturn.reg[r][2]=(v>>8)&0xf;
165   saturn.reg[r][3]=(v>>12)&0xf;
166   saturn.reg[r][4]=(v>>16)&0xf;
167}
141168
142#define S64_READ_A(r) (S64_DOUBLE(r,0)&0xfffff)
143#define S64_WRITE_A(r,v) (S64_DOUBLE(r,0)=(S64_DOUBLE(r,0)&~0xfffff)|(v))
144169
145#define S64_READ_M(r) ((S64_QUAD(r)>>12)&0xffffffffffffULL)
146#define S64_WRITE_M(r,v) (S64_QUAD(r)=(S64_QUAD(r)&~0xffffffffffff000ULL)|((v)<<12))
147170
148#define S64_READ_W(r) S64_QUAD(r)
149#define S64_WRITE_W(r,v) (S64_QUAD(r)=(v))
150171
172
151173INLINE SaturnAdr saturn_pop(void)
152174{
153175   SaturnAdr temp=saturn.rstk[0];
154176   memmove(saturn.rstk, saturn.rstk+1, sizeof(saturn.rstk)-sizeof(saturn.rstk[0]));
155177   saturn.rstk[7]=0;
156   saturn.stackpointer--;
157178   return temp;
158179}
159180
r2724r2725
161182{
162183   memmove(saturn.rstk+1, saturn.rstk, sizeof(saturn.rstk)-sizeof(saturn.rstk[0]));
163184   saturn.rstk[0]=adr;
164   saturn.stackpointer++;
165185}
166186
167187INLINE void saturn_interrupt_on(void)
168188{
169
189   LOG(( "SATURN#%d at %05x: INTON\n", cpu_getactivecpu(), saturn.pc-4 ));
190   saturn.irq_enable=1;
191   if (saturn.irq_state)
192   {
193      LOG(( "SATURN#%d set_irq_line(ASSERT)\n", cpu_getactivecpu()));
194      saturn.pending_irq=1;
195   }
170196}
171197
172198INLINE void saturn_interrupt_off(void)
173199{
174
200   LOG(( "SATURN#%d at %05x: INTOFF\n", cpu_getactivecpu(), saturn.pc-4 ));
201   saturn.irq_enable=0;
175202}
176203
177204INLINE void saturn_reset_interrupt(void)
178205{
179
206   LOG(( "SATURN#%d at %05x: RSI\n", cpu_getactivecpu(), saturn.pc-5 ));
207   if (saturn.config&&saturn.config->rsi) saturn.config->rsi(Machine);
180208}
181209
182210INLINE void saturn_mem_reset(void)
183211{
184   if (saturn.config->reset) saturn.config->reset();
212   if (saturn.config&&saturn.config->reset) saturn.config->reset(Machine);
185213}
186214
187215INLINE void saturn_mem_config(void)
188216{
189   if (saturn.config->config) saturn.config->config(S64_READ_A(C));
217   if (saturn.config&&saturn.config->config) saturn.config->config(Machine, S64_READ_A(C));
190218}
191219
192220INLINE void saturn_mem_unconfig(void)
193221{
194   if (saturn.config->unconfig) saturn.config->unconfig(S64_READ_A(C));
222   if (saturn.config&&saturn.config->unconfig) saturn.config->unconfig(Machine, S64_READ_A(C));
195223}
196224
197INLINE int saturn_mem_id(void)
225int monitor_id;
226
227INLINE void saturn_mem_id(void)
198228{
199   if (saturn.config->id) return saturn.config->id();
200   return 0;
229   int id=0;
230   if (saturn.config&&saturn.config->id) id=saturn.config->id(Machine);
231   S64_WRITE_A(C,id);
232   monitor_id = id;
201233}
202234
203235INLINE void saturn_shutdown(void)
204236{
237   saturn.sleeping=1;
238   saturn.irq_enable=1;
239   LOG(( "SATURN#%d at %05x: SHUTDN\n", cpu_getactivecpu(), saturn.pc-3 ));
205240}
206241
207242INLINE void saturn_bus_command_b(void)
208243{
244   logerror( "SATURN#%d at %05x: BUSCB opcode not handled\n", cpu_getactivecpu(), saturn.pc-4 );
209245}
210246
211247INLINE void saturn_bus_command_c(void)
212248{
249   logerror( "SATURN#%d at %05x: BUSCC opcode not handled\n", cpu_getactivecpu(), saturn.pc-3 );
213250}
214251
215252INLINE void saturn_bus_command_d(void)
216253{
254   logerror( "SATURN#%d at %05x: BUSCD opcode not handled\n", cpu_getactivecpu(), saturn.pc-4 );
217255}
218256
219257INLINE void saturn_serial_request(void)
220258{
259   logerror( "SATURN#%d at %05x: SREQ? opcode not handled\n", cpu_getactivecpu(), saturn.pc-3 );
221260}
222261
223262INLINE void saturn_out_c(void)
224263{
225   if (saturn.config&&saturn.config->out) saturn.config->out(S64_READ_X(C));
264   saturn.out=S64_READ_X(C);
265   if (saturn.config&&saturn.config->out) saturn.config->out(Machine, saturn.out);
226266}
227267
228268INLINE void saturn_out_cs(void)
229269{
230   if (saturn.config&&saturn.config->out)
231      saturn.config->out(S64_READ_NIBBLE(C,0)|(saturn.out&0xff0));
270   saturn.out=(saturn.out&0xff0)|saturn.reg[C][0];
271   if (saturn.config&&saturn.config->out) saturn.config->out(Machine, saturn.out);
232272}
233273
274int monitor_in;
275
234276INLINE void saturn_in(int reg)
235277{
236   if (saturn.config&&saturn.config->in) S64_WORD(reg,0)=saturn.config->in();
278   int in = 0;
279   saturn_assert(reg>=0 && reg<9);
280   if (!(saturn.pc&1))
281      logerror( "SATURN#%d at %05x: reg=IN opcode at odd addresse\n",
282           cpu_getactivecpu(), saturn.pc-3 );
283   if (saturn.config&&saturn.config->in) in = saturn.config->in(Machine);
284   S64_WRITE_WORD(reg,in);
285   monitor_in = in;
237286}
238287
239288INLINE void saturn_sethex(void) { saturn.decimal=0; }
r2724r2725
242291/* st related */
243292INLINE void saturn_clear_st(void)
244293{
245   saturn.st=0;
294   saturn.st&=0xf000;
246295}
247296
248297INLINE void saturn_st_to_c(void)
249298{
250   S64_WRITE_X(C, saturn.st&0xfff);
299   S64_WRITE_X(C,saturn.st);
251300}
252301
253302INLINE void saturn_c_to_st(void)
254303{
255   saturn.st=(saturn.st&~0xfff)|S64_READ_X(C);
304   saturn.st=(saturn.st&0xf000)|(S64_READ_X(C));
256305}
257306
258307INLINE void saturn_exchange_c_st(void)
259308{
260   int t=saturn.st&0xfff;
261   saturn.st=(saturn.st&~0xfff)|S64_READ_X(C);
262   S64_WRITE_X(C, t);
309   int t=saturn.st;
310   saturn.st=(t&0xf000)|(S64_READ_X(C));
311   S64_WRITE_X(C,t);
263312}
264313
265INLINE void saturn_st_clear_bit(void)
314INLINE void saturn_jump_after_test(void)
266315{
267   switch(READ_OP_ARG()) {
268   case 0: saturn.st&=~1;break;
269   case 1: saturn.st&=~2;break;
270   case 2: saturn.st&=~4;break;
271   case 3: saturn.st&=~8;break;
272   case 4: saturn.st&=~0x10;break;
273   case 5: saturn.st&=~0x20;break;
274   case 6: saturn.st&=~0x40;break;
275   case 7: saturn.st&=~0x80;break;
276   case 8: saturn.st&=~0x100;break;
277   case 9: saturn.st&=~0x200;break;
278   case 0xa: saturn.st&=~0x400;break;
279   case 0xb: saturn.st&=~0x800;break;
280   case 0xc: saturn.st&=~0x1000;break;
281   case 0xd: saturn.st&=~0x2000;break;
282   case 0xe: saturn.st&=~0x4000;break;
283   case 0xf: saturn.st&=~0x8000;break;
316   int adr=READ_OP_DIS8();
317   if (saturn.carry) {
318      if (adr==0) {
319         saturn.pc=saturn_pop();
320      } else {
321         saturn.pc=(saturn.pc+adr-2)&0xfffff;
322      }
323      change_pc(saturn.pc);
284324   }
285325}
326INLINE void saturn_st_clear_bit(void)
327{
328   saturn.st &= ~(1<<(READ_OP_ARG()));
329}
286330
287331INLINE void saturn_st_set_bit(void)
288332{
289   switch(READ_OP_ARG()) {
290   case 0: saturn.st|=1;break;
291   case 1: saturn.st|=2;break;
292   case 2: saturn.st|=4;break;
293   case 3: saturn.st|=8;break;
294   case 4: saturn.st|=0x10;break;
295   case 5: saturn.st|=0x20;break;
296   case 6: saturn.st|=0x40;break;
297   case 7: saturn.st|=0x80;break;
298   case 8: saturn.st|=0x100;break;
299   case 9: saturn.st|=0x200;break;
300   case 0xa: saturn.st|=0x400;break;
301   case 0xb: saturn.st|=0x800;break;
302   case 0xc: saturn.st|=0x1000;break;
303   case 0xd: saturn.st|=0x2000;break;
304   case 0xe: saturn.st|=0x4000;break;
305   case 0xf: saturn.st|=0x8000;break;
306   }
333   saturn.st |= (1<<(READ_OP_ARG()));
307334}
308335
309336INLINE void saturn_st_jump_bit_clear(void)
310337{
311   int adr;
312   switch(READ_OP_ARG()) {
313   case 0: saturn.carry=!saturn.st&1;break;
314   case 1: saturn.carry=!saturn.st&2;break;
315   case 2: saturn.carry=!saturn.st&4;break;
316   case 3: saturn.carry=!saturn.st&8;break;
317   case 4: saturn.carry=!saturn.st&0x10;break;
318   case 5: saturn.carry=!saturn.st&0x20;break;
319   case 6: saturn.carry=!saturn.st&0x40;break;
320   case 7: saturn.carry=!saturn.st&0x80;break;
321   case 8: saturn.carry=!saturn.st&0x100;break;
322   case 9: saturn.carry=!saturn.st&0x200;break;
323   case 0xa: saturn.carry=!saturn.st&0x400;break;
324   case 0xb: saturn.carry=!saturn.st&0x800;break;
325   case 0xc: saturn.carry=!saturn.st&0x1000;break;
326   case 0xd: saturn.carry=!saturn.st&0x2000;break;
327   case 0xe: saturn.carry=!saturn.st&0x4000;break;
328   case 0xf: saturn.carry=!saturn.st&0x8000;break;
329   }
330   adr=READ_OP_DIS8();
331   if (saturn.carry) {
332      if (adr==0) {
333         saturn.pc=saturn_pop();
334      } else {
335         saturn.pc=(saturn.pc+adr-2)&0xfffff;
336      }
337      change_pc(saturn.pc);
338   }
338   saturn.carry=!((saturn.st>>(READ_OP_ARG()))&1);
339   saturn_jump_after_test();
339340}
340341
341342INLINE void saturn_st_jump_bit_set(void)
342343{
343   int adr;
344   switch(READ_OP_ARG()) {
345   case 0: saturn.carry=saturn.st&1;break;
346   case 1: saturn.carry=saturn.st&2;break;
347   case 2: saturn.carry=saturn.st&4;break;
348   case 3: saturn.carry=saturn.st&8;break;
349   case 4: saturn.carry=saturn.st&0x10;break;
350   case 5: saturn.carry=saturn.st&0x20;break;
351   case 6: saturn.carry=saturn.st&0x40;break;
352   case 7: saturn.carry=saturn.st&0x80;break;
353   case 8: saturn.carry=saturn.st&0x100;break;
354   case 9: saturn.carry=saturn.st&0x200;break;
355   case 0xa: saturn.carry=saturn.st&0x400;break;
356   case 0xb: saturn.carry=saturn.st&0x800;break;
357   case 0xc: saturn.carry=saturn.st&0x1000;break;
358   case 0xd: saturn.carry=saturn.st&0x2000;break;
359   case 0xe: saturn.carry=saturn.st&0x4000;break;
360   case 0xf: saturn.carry=saturn.st&0x8000;break;
361   }
362   adr=READ_OP_DIS8();
363   if (saturn.carry) {
364      if (adr==0) {
365         saturn.pc=saturn_pop();
366      } else {
367         saturn.pc=(saturn.pc+adr-2)&0xfffff;
368      }
369      change_pc(saturn.pc);
370   }
344   saturn.carry=(saturn.st>>(READ_OP_ARG()))&1;
345   saturn_jump_after_test();
371346}
372347
373348INLINE void saturn_hst_clear_bits(void)
374349{
375   saturn.hst&=~READ_OP_ARG();
350   saturn.hst&=~(READ_OP_ARG());
376351}
377352
378353INLINE void saturn_hst_bits_cleared(void)
379354{
380   saturn.carry=!(saturn.hst&READ_OP_ARG());
355   saturn.carry=!(saturn.hst&(READ_OP_ARG()));
356   saturn_jump_after_test();
381357}
382358
383359/* p related */
r2724r2725
385361{
386362   int nr=READ_OP_ARG();
387363   int t=saturn.p;
388   saturn.p=S64_READ_NIBBLE(C,nr);
389   S64_WRITE_NIBBLE(C,nr,t);
364   saturn.p=saturn.reg[C][nr];
365   saturn.reg[C][nr]=t;
390366}
391367
392368INLINE void saturn_p_to_c(void)
393369{
394370   int nr=READ_OP_ARG();
395   S64_WRITE_NIBBLE(C,nr,saturn.p);
371   saturn.reg[C][nr]=saturn.p;
396372}
397373
398374INLINE void saturn_c_to_p(void)
399375{
400376   int nr=READ_OP_ARG();
401   saturn.p=S64_READ_NIBBLE(C,nr);
377   saturn.p=saturn.reg[C][nr];
402378}
403379
404380INLINE void saturn_dec_p(void)
405381{
406382   saturn.carry=saturn.p==0;
407   saturn.p=saturn.p-1;
383   saturn.p=(saturn.p-1)&0xf;
408384}
409385
410386INLINE void saturn_inc_p(void)
411387{
412   saturn.p=saturn.p+1;
388   saturn.p=(saturn.p+1)&0xf;
413389   saturn.carry=saturn.p==0;
414390}
415391
r2724r2725
420396
421397INLINE void saturn_p_equals(void)
422398{
423   int nr=READ_OP_ARG();
424   int adr;
425   saturn.carry=saturn.p==nr;
426   adr=READ_OP_DIS8();
427   if (saturn.carry) {
428      if (adr==0) {
429         saturn.pc=saturn_pop();
430      } else {
431         saturn.pc=(saturn.pc+adr-2)&0xfffff;
432      }
433      change_pc(saturn.pc);
434   }
399   saturn.carry=saturn.p==(READ_OP_ARG());
400   saturn_jump_after_test();
435401}
436402
437403INLINE void saturn_p_not_equals(void)
438404{
439   int nr=READ_OP_ARG();
440   int adr;
441   saturn.carry=saturn.p!=nr;
442   adr=READ_OP_DIS8();
443   if (saturn.carry) {
444      if (adr==0) {
445         saturn.pc=saturn_pop();
446      } else {
447         saturn.pc=(saturn.pc+adr-2)&0xfffff;
448      }
449      change_pc(saturn.pc);
450   }
405   saturn.carry=saturn.p!=(READ_OP_ARG());
406   saturn_jump_after_test();
451407}
452408
453409INLINE void saturn_ca_p_1(void)
454410{
455   int a=S64_READ_A(C)+1+saturn.p;
411   int a=(S64_READ_A(C))+1+saturn.p;
456412   saturn.carry=a>=0x100000;
457413   S64_WRITE_A(C,a&0xfffff);
458414}
r2724r2725
461417{
462418   int count=READ_OP_ARG();
463419   int pos=saturn.p;
420   saturn_assert(reg>=0 && reg<9);
464421   for (; count>=0; count--, pos=(pos+1)&0xf ) {
465      S64_WRITE_NIBBLE( reg, pos, READ_OP_ARG());
422      saturn.reg[reg][pos]=READ_OP_ARG();
466423   }
467424}
468425
469426INLINE void saturn_jump(int adr, int jump)
470427{
428   saturn_assert(adr>=0 && adr<0x100000);
471429   if (jump) {
472430      saturn.pc=adr;
473431      saturn_ICount-=10;
r2724r2725
477435
478436INLINE void saturn_call(int adr)
479437{
438   saturn_assert(adr>=0 && adr<0x100000);
480439   saturn_push(saturn.pc);
481440   saturn.pc=adr;
482441//  saturn_ICount-=10;
r2724r2725
510469
511470INLINE void saturn_return_interrupt(void)
512471{
472   LOG(( "SATURN#%d at %05x: RTI\n", cpu_getactivecpu(), saturn.pc-2 ));
473   saturn.in_irq=0; /* set to 1 when an IRQ is taken */
513474   saturn.pc=saturn_pop();
514475//  saturn_ICount-=10;
515476   change_pc(saturn.pc);
r2724r2725
535496
536497INLINE void saturn_indirect_jump(int reg)
537498{
499   saturn_assert(reg>=0 && reg<9);
538500   saturn.pc=READ_20(S64_READ_A(reg));
539501   change_pc(saturn.pc);
540502}
541503
542504INLINE void saturn_equals_zero(int reg, int begin, int count)
543505{
544   int i, t,adr;
506   int i, t;
507   saturn_assert(reg>=0 && reg<9);
508   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
509   saturn.carry=1;
545510   for (i=0; i<count; i++) {
546      t=S64_READ_NIBBLE(reg, (begin+i)&0xf );
547      if (t!=0) break;
511      t=saturn.reg[reg][begin+i];
512      if (t!=0) { saturn.carry=0; break; }
548513      saturn_ICount-=2;
549514   }
550   saturn.carry=i==count;
551   adr=READ_OP_DIS8();
552   if (saturn.carry) {
553      if (adr==0) {
554         saturn.pc=saturn_pop();
555      } else {
556         saturn.pc=(saturn.pc+adr-2)&0xfffff;
557      }
558      change_pc(saturn.pc);
559   }
515   saturn_jump_after_test();
560516}
561517
562518INLINE void saturn_equals(int reg, int begin, int count, int right)
563519{
564   int i, t,t2,adr;
520   int i, t,t2;
521   saturn_assert(reg>=0 && reg<9);
522   saturn_assert(right>=0 && right<9);
523   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
524   saturn.carry=1;
565525   for (i=0; i<count; i++) {
566      t=S64_READ_NIBBLE(reg, (begin+i)&0xf );
567      t2=S64_READ_NIBBLE(right, (begin+i)&0xf );
568      if (t!=t2) break;
526      t=saturn.reg[reg][begin+i];
527      t2=saturn.reg[right][begin+i];
528      if (t!=t2) { saturn.carry=0; break; }
569529      saturn_ICount-=2;
570530   }
571   saturn.carry=i==count;
572   adr=READ_OP_DIS8();
573   if (saturn.carry) {
574      if (adr==0) {
575         saturn.pc=saturn_pop();
576      } else {
577         saturn.pc=(saturn.pc+adr-2)&0xfffff;
578      }
579      change_pc(saturn.pc);
580   }
531   saturn_jump_after_test();
581532}
582533
583534INLINE void saturn_not_equals_zero(int reg, int begin, int count)
584535{
585   int i, t,adr;
536   int i, t;
537   saturn_assert(reg>=0 && reg<9);
538   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
539   saturn.carry=0;
586540   for (i=0; i<count; i++) {
587      t=S64_READ_NIBBLE(reg, (begin+i)&0xf );
588      if (t==0) break;
541      t=saturn.reg[reg][begin+i];
542      if (t!=0) { saturn.carry=1; break; }
589543      saturn_ICount-=2;
590544   }
591   saturn.carry=i==count;
592   adr=READ_OP_DIS8();
593   if (saturn.carry) {
594      if (adr==0) {
595         saturn.pc=saturn_pop();
596      } else {
597         saturn.pc=(saturn.pc+adr-2)&0xfffff;
598      }
599      change_pc(saturn.pc);
600   }
545   saturn_jump_after_test();
601546}
602547
603548INLINE void saturn_not_equals(int reg, int begin, int count, int right)
604549{
605   int i, t,t2,adr;
550   int i, t,t2;
551   saturn_assert(reg>=0 && reg<9);
552   saturn_assert(right>=0 && right<9);
553   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
554   saturn.carry=0;
606555   for (i=0; i<count; i++) {
607      t=S64_READ_NIBBLE(reg, (begin+i)&0xf );
608      t2=S64_READ_NIBBLE(right, (begin+i)&0xf );
609      if (t==t2) break;
556      t=saturn.reg[reg][begin+i];
557      t2=saturn.reg[right][begin+i];
558      if (t!=t2) { saturn.carry=1; break; }
610559      saturn_ICount-=2;
611560   }
612   saturn.carry=i==count;
613   adr=READ_OP_DIS8();
614   if (saturn.carry) {
615      if (adr==0) {
616         saturn.pc=saturn_pop();
617      } else {
618         saturn.pc=(saturn.pc+adr-2)&0xfffff;
619      }
620      change_pc(saturn.pc);
621   }
561   saturn_jump_after_test();
622562}
623563
624564INLINE void saturn_greater(int reg, int begin, int count, int right)
625565{
626   int i, t,t2,adr;
627   for (i=count; i>=0; i--) {
628      t=S64_READ_NIBBLE(reg, (begin+i)&0xf );
629      t2=S64_READ_NIBBLE(right, (begin+i)&0xf );
630      if (t<=t2) break;
566   int i, t,t2;
567   saturn_assert(reg>=0 && reg<9);
568   saturn_assert(right>=0 && right<9);
569   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
570   saturn.carry=0;
571   for (i=count-1; i>=0; i--) {
572      t=saturn.reg[reg][begin+i];
573      t2=saturn.reg[right][begin+i];
574      if (t>t2) { saturn.carry=1; break; }
575      if (t<t2) break;
631576      saturn_ICount-=2;
632577   }
633   saturn.carry=i<0;
634   adr=READ_OP_DIS8();
635   if (saturn.carry) {
636      if (adr==0) {
637         saturn.pc=saturn_pop();
638      } else {
639         saturn.pc=(saturn.pc+adr-2)&0xfffff;
640      }
641      change_pc(saturn.pc);
642   }
578   saturn_jump_after_test();
643579}
644580
645581INLINE void saturn_greater_equals(int reg, int begin, int count, int right)
646582{
647   int i, t,t2,adr;
648   for (i=count; i>=0; i--) {
649      t=S64_READ_NIBBLE(reg, (begin+i)&0xf );
650      t2=S64_READ_NIBBLE(right, (begin+i)&0xf );
651      if (t<t2) break;
583   int i, t,t2;
584   saturn_assert(reg>=0 && reg<9);
585   saturn_assert(right>=0 && right<9);
586   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
587   saturn.carry=1;
588   for (i=count-1; i>=0; i--) {
589      t=saturn.reg[reg][begin+i];
590      t2=saturn.reg[right][begin+i];
591      if (t<t2) { saturn.carry=0; break; }
592      if (t>t2) break;
652593      saturn_ICount-=2;
653594   }
654   saturn.carry=i<0;
655   adr=READ_OP_DIS8();
656   if (saturn.carry) {
657      if (adr==0) {
658         saturn.pc=saturn_pop();
659      } else {
660         saturn.pc=(saturn.pc+adr-2)&0xfffff;
661      }
662      change_pc(saturn.pc);
663   }
595   saturn_jump_after_test();
664596}
665597
666598INLINE void saturn_smaller_equals(int reg, int begin, int count, int right)
667599{
668   int i, t,t2,adr;
669   for (i=count; i>=0; i--) {
670      t=S64_READ_NIBBLE(reg, (begin+i)&0xf );
671      t2=S64_READ_NIBBLE(right, (begin+i)&0xf );
672      if (t>t2) break;
600   int i, t,t2;
601   saturn_assert(reg>=0 && reg<9);
602   saturn_assert(right>=0 && right<9);
603   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
604   saturn.carry=1;
605   for (i=count-1; i>=0; i--) {
606      t=saturn.reg[reg][begin+i];
607      t2=saturn.reg[right][begin+i];
608      if (t>t2) { saturn.carry=0; break; }
609      if (t<t2) break;
673610      saturn_ICount-=2;
674611   }
675   saturn.carry=i<0;
676   adr=READ_OP_DIS8();
677   if (saturn.carry) {
678      if (adr==0) {
679         saturn.pc=saturn_pop();
680      } else {
681         saturn.pc=(saturn.pc+adr-2)&0xfffff;
682      }
683      change_pc(saturn.pc);
684   }
612   saturn_jump_after_test();
685613}
686614
687615INLINE void saturn_smaller(int reg, int begin, int count, int right)
688616{
689   int i, t,t2,adr;
690   for (i=count; i>=0; i--) {
691      t=S64_READ_NIBBLE(reg, (begin+i)&0xf );
692      t2=S64_READ_NIBBLE(right, (begin+i)&0xf );
693      if (t>=t2) break;
617   int i, t,t2;
618   saturn_assert(reg>=0 && reg<9);
619   saturn_assert(right>=0 && right<9);
620   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
621   saturn.carry=0;
622   for (i=count-1; i>=0; i--) {
623      t=saturn.reg[reg][begin+i];
624      t2=saturn.reg[right][begin+i];
625      if (t<t2) { saturn.carry=1; break; }
626      if (t>t2) break;
694627      saturn_ICount-=2;
695628   }
696   saturn.carry=i<0;
697   adr=READ_OP_DIS8();
698   if (saturn.carry) {
699      if (adr==0) {
700         saturn.pc=saturn_pop();
701      } else {
702         saturn.pc=(saturn.pc+adr-2)&0xfffff;
703      }
704      change_pc(saturn.pc);
705   }
629   saturn_jump_after_test();
706630}
707631
708632INLINE void saturn_jump_bit_clear(int reg)
709633{
710   int adr;
711   switch(READ_OP_ARG()) {
712   case 0: saturn.carry=!(S64_BYTE( reg, 0)&1);break;
713   case 1: saturn.carry=!(S64_BYTE( reg, 0)&2);break;
714   case 2: saturn.carry=!(S64_BYTE( reg, 0)&4);break;
715   case 3: saturn.carry=!(S64_BYTE( reg, 0)&8);break;
716   case 4: saturn.carry=!(S64_BYTE( reg, 0)&0x10);break;
717   case 5: saturn.carry=!(S64_BYTE( reg, 0)&0x20);break;
718   case 6: saturn.carry=!(S64_BYTE( reg, 0)&0x40);break;
719   case 7: saturn.carry=!(S64_BYTE( reg, 0)&0x80);break;
720   case 8: saturn.carry=!(S64_BYTE( reg, 1)&1);break;
721   case 9: saturn.carry=!(S64_BYTE( reg, 1)&2);break;
722   case 0xa: saturn.carry=!(S64_BYTE( reg, 1)&4);break;
723   case 0xb: saturn.carry=!(S64_BYTE( reg, 1)&8);break;
724   case 0xc: saturn.carry=!(S64_BYTE( reg, 1)&0x10);break;
725   case 0xd: saturn.carry=!(S64_BYTE( reg, 1)&0x20);break;
726   case 0xe: saturn.carry=!(S64_BYTE( reg, 1)&0x40);break;
727   case 0xf: saturn.carry=!(S64_BYTE( reg, 1)&0x80);break;
728   }
729   adr=READ_OP_DIS8();
730   if (saturn.carry) {
731      if (adr==0) {
732         saturn.pc=saturn_pop();
733      } else {
734         saturn.pc=(saturn.pc+adr-2)&0xfffff;
735      }
736      change_pc(saturn.pc);
737   }
634   int op=READ_OP_ARG();
635   saturn_assert(reg>=0 && reg<9);
636   saturn.carry=!((saturn.reg[reg][op>>2]>>(op&3))&1);
637   saturn_jump_after_test();
738638}
739639
740640INLINE void saturn_jump_bit_set(int reg)
741641{
742   int adr;
743   switch(READ_OP_ARG()) {
744   case 0: saturn.carry=S64_BYTE( reg, 0)&1;break;
745   case 1: saturn.carry=S64_BYTE( reg, 0)&2;break;
746   case 2: saturn.carry=S64_BYTE( reg, 0)&4;break;
747   case 3: saturn.carry=S64_BYTE( reg, 0)&8;break;
748   case 4: saturn.carry=S64_BYTE( reg, 0)&0x10;break;
749   case 5: saturn.carry=S64_BYTE( reg, 0)&0x20;break;
750   case 6: saturn.carry=S64_BYTE( reg, 0)&0x40;break;
751   case 7: saturn.carry=S64_BYTE( reg, 0)&0x80;break;
752   case 8: saturn.carry=S64_BYTE( reg, 1)&1;break;
753   case 9: saturn.carry=S64_BYTE( reg, 1)&2;break;
754   case 0xa: saturn.carry=S64_BYTE( reg, 1)&4;break;
755   case 0xb: saturn.carry=S64_BYTE( reg, 1)&8;break;
756   case 0xc: saturn.carry=S64_BYTE( reg, 1)&0x10;break;
757   case 0xd: saturn.carry=S64_BYTE( reg, 1)&0x20;break;
758   case 0xe: saturn.carry=S64_BYTE( reg, 1)&0x40;break;
759   case 0xf: saturn.carry=S64_BYTE( reg, 1)&0x80;break;
760   }
761   adr=READ_OP_DIS8();
762   if (saturn.carry) {
763      if (adr==0) {
764         saturn.pc=saturn_pop();
765      } else {
766         saturn.pc=(saturn.pc+adr-2)&0xfffff;
767      }
768      change_pc(saturn.pc);
769   }
642   int op=READ_OP_ARG();
643   saturn_assert(reg>=0 && reg<9);
644   saturn.carry=(saturn.reg[reg][op>>2]>>(op&3))&1;
645   saturn_jump_after_test();
770646}
771647
772648INLINE void saturn_load_pc(int reg)
773649{
650   saturn_assert(reg>=0 && reg<9);
774651   saturn.pc=S64_READ_A(reg);
775652   change_pc(saturn.pc);
776653}
777654
778655INLINE void saturn_store_pc(int reg)
779656{
657   saturn_assert(reg>=0 && reg<9);
780658   S64_WRITE_A(reg,saturn.pc);
781659}
782660
783661INLINE void saturn_exchange_pc(int reg)
784662{
785663   int temp=saturn.pc;
664   saturn_assert(reg>=0 && reg<9);
786665   saturn.pc=S64_READ_A(reg);
787666   change_pc(saturn.pc);
788667   S64_WRITE_A(reg, temp);
r2724r2725
793672*************************************************************************************/
794673INLINE void saturn_load_adr(int reg, int nibbles)
795674{
675   saturn_assert(reg>=0 && reg<2);
676   saturn_assert(nibbles==2 || nibbles==4 || nibbles==5);
796677   switch (nibbles) {
797678   case 5:
798679      saturn.d[reg]=READ_OP_ARG20();
r2724r2725
809690INLINE void saturn_add_adr(int reg)
810691{
811692   int t=saturn.d[reg]+READ_OP_ARG()+1;
693   saturn_assert(reg>=0 && reg<2);
812694   saturn.d[reg]=t&0xfffff;
813695   saturn.carry=t>=0x100000;
814696}
r2724r2725
816698INLINE void saturn_sub_adr(int reg)
817699{
818700   int t=saturn.d[reg]-READ_OP_ARG()-1;
701   saturn_assert(reg>=0 && reg<2);
819702   saturn.d[reg]=t&0xfffff;
820703   saturn.carry=t<0;
821704}
822705
823706INLINE void saturn_adr_to_reg(int adr, int reg)
824707{
708   saturn_assert(reg>=0 && reg<9);
709   saturn_assert(adr>=0 && adr<2);
825710   S64_WRITE_A(reg,saturn.d[adr]);
826711}
827712
828713INLINE void saturn_reg_to_adr(int reg, int adr)
829714{
715   saturn_assert(reg>=0 && reg<9);
716   saturn_assert(adr>=0 && adr<2);
830717   saturn.d[adr]=S64_READ_A(reg);
831718}
832719
833720INLINE void saturn_adr_to_reg_word(int adr, int reg)
834721{
835   S64_WRITE_WORD(reg,0,saturn.d[adr]&0xffff);
722   saturn_assert(reg>=0 && reg<9);
723   saturn_assert(adr>=0 && adr<2);
724   S64_WRITE_WORD(reg,saturn.d[adr]&0xffff);
836725}
837726
838727INLINE void saturn_reg_to_adr_word(int reg, int adr)
839728{
840   saturn.d[adr]=(saturn.d[adr]&0xf0000)|S64_READ_WORD(reg,0);
729   saturn_assert(reg>=0 && reg<9);
730   saturn_assert(adr>=0 && adr<2);
731   saturn.d[adr]=(saturn.d[adr]&0xf0000)|S64_READ_WORD(reg);
841732}
842733
843734INLINE void saturn_exchange_adr_reg(int adr, int reg)
844735{
845736   int temp=saturn.d[adr];
737   saturn_assert(reg>=0 && reg<9);
738   saturn_assert(adr>=0 && adr<2);
846739   saturn.d[adr]=S64_READ_A(reg);
847740   S64_WRITE_A(reg,temp);
848741}
r2724r2725
850743INLINE void saturn_exchange_adr_reg_word(int adr, int reg)
851744{
852745   int temp=saturn.d[adr]&0xffff;
853   saturn.d[adr]=(saturn.d[adr]&0xf0000)|S64_READ_WORD(reg,0);
854   S64_WRITE_WORD(reg,0,temp);
746   saturn_assert(reg>=0 && reg<9);
747   saturn_assert(adr>=0 && adr<2);
748   saturn.d[adr]=(saturn.d[adr]&0xf0000)|S64_READ_WORD(reg);
749   S64_WRITE_WORD(reg,temp);
855750}
856751
857752INLINE void saturn_load_nibbles(int reg, int begin, int count, int adr)
858753{
859754   int i;
755   saturn_assert(reg>=0 && reg<9);
756   saturn_assert(adr>=0 && adr<2);
757   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
860758   for (i=0; i<count; i++) {
861      S64_WRITE_NIBBLE(reg,(begin+i)&0xf,READ_NIBBLE(saturn.d[adr]+i) );
759      saturn.reg[reg][begin+i]=READ_NIBBLE(saturn.d[adr]+i);
862760      saturn_ICount-=2;
863761   }
864762}
r2724r2725
866764INLINE void saturn_store_nibbles(int reg, int begin, int count, int adr)
867765{
868766   int i;
767   saturn_assert(reg>=0 && reg<9);
768   saturn_assert(adr>=0 && adr<2);
769   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
869770   for (i=0; i<count; i++) {
870      WRITE_NIBBLE(saturn.d[adr]+i,S64_READ_NIBBLE(reg,(begin+i)&0xf) );
771      WRITE_NIBBLE((saturn.d[adr]+i)&0xfffff,saturn.reg[reg][begin+i]);
871772      saturn_ICount-=2;
872773   }
873774}
874775
875776INLINE void saturn_clear_bit(int reg)
876777{
877   switch(READ_OP_ARG()) {
878   case 0: S64_BYTE( reg, 0)&=~1;break;
879   case 1: S64_BYTE( reg, 0)&=~2;break;
880   case 2: S64_BYTE( reg, 0)&=~4;break;
881   case 3: S64_BYTE( reg, 0)&=~8;break;
882   case 4: S64_BYTE( reg, 0)&=~0x10;break;
883   case 5: S64_BYTE( reg, 0)&=~0x20;break;
884   case 6: S64_BYTE( reg, 0)&=~0x40;break;
885   case 7: S64_BYTE( reg, 0)&=~0x80;break;
886   case 8: S64_BYTE( reg, 1)&=~1;break;
887   case 9: S64_BYTE( reg, 1)&=~2;break;
888   case 0xa: S64_BYTE( reg, 1)&=~4;break;
889   case 0xb: S64_BYTE( reg, 1)&=~8;break;
890   case 0xc: S64_BYTE( reg, 1)&=~0x10;break;
891   case 0xd: S64_BYTE( reg, 1)&=~0x20;break;
892   case 0xe: S64_BYTE( reg, 1)&=~0x40;break;
893   case 0xf: S64_BYTE( reg, 1)&=~0x80;break;
894   }
778   int arg=READ_OP_ARG();
779   saturn_assert(reg>=0 && reg<9);
780   saturn.reg[reg][arg>>2]&=~(1<<(arg&3));
895781}
896782
897783INLINE void saturn_set_bit(int reg)
898784{
899   switch(READ_OP_ARG()) {
900   case 0: S64_BYTE( reg, 0)|=1;break;
901   case 1: S64_BYTE( reg, 0)|=2;break;
902   case 2: S64_BYTE( reg, 0)|=4;break;
903   case 3: S64_BYTE( reg, 0)|=8;break;
904   case 4: S64_BYTE( reg, 0)|=0x10;break;
905   case 5: S64_BYTE( reg, 0)|=0x20;break;
906   case 6: S64_BYTE( reg, 0)|=0x40;break;
907   case 7: S64_BYTE( reg, 0)|=0x80;break;
908   case 8: S64_BYTE( reg, 1)|=1;break;
909   case 9: S64_BYTE( reg, 1)|=2;break;
910   case 0xa: S64_BYTE( reg, 1)|=4;break;
911   case 0xb: S64_BYTE( reg, 1)|=8;break;
912   case 0xc: S64_BYTE( reg, 1)|=0x10;break;
913   case 0xd: S64_BYTE( reg, 1)|=0x20;break;
914   case 0xe: S64_BYTE( reg, 1)|=0x40;break;
915   case 0xf: S64_BYTE( reg, 1)|=0x80;break;
916   }
785   int arg=READ_OP_ARG();
786   saturn_assert(reg>=0 && reg<9);
787   saturn.reg[reg][arg>>2]|=1<<(arg&3);
917788}
918789
919790/****************************************************************************
r2724r2725
922793INLINE void saturn_clear(int reg, int begin, int count)
923794{
924795   int i;
796   saturn_assert(reg>=0 && reg<9);
797   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
925798   for (i=0; i<count; i++) {
926      S64_WRITE_NIBBLE(reg, (begin+i)&0xf, 0);
799      saturn.reg[reg][begin+i]=0;
927800      saturn_ICount-=2;
928801   }
929802}
r2724r2725
935808{
936809   int i;
937810   SaturnNib temp;
811   saturn_assert(left>=0 && left<9);
812   saturn_assert(right>=0 && right<9);
813   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
938814   for (i=0; i<count; i++) {
939      temp=S64_READ_NIBBLE(left,(begin+i)&0xf);
940      S64_WRITE_NIBBLE(left, (begin+i)&0xf, S64_READ_NIBBLE(right,(begin+i)&0xf));
941      S64_WRITE_NIBBLE(right, (begin+i)&0xf, temp);
815      temp=saturn.reg[left][begin+i];
816      saturn.reg[left][begin+i]=saturn.reg[right][begin+i];
817      saturn.reg[right][begin+i]=temp;
942818      saturn_ICount-=2;
943819   }
944820}
r2724r2725
949825INLINE void saturn_copy(int dest, int begin, int count, int src)
950826{
951827   int i;
828   saturn_assert(dest>=0 && dest<9);
829   saturn_assert(src>=0 && src<9);
830   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
952831   for (i=0; i<count; i++) {
953      S64_WRITE_NIBBLE(dest, (begin+i)&0xf, S64_READ_NIBBLE(src, (begin+i)&0xf));
832      saturn.reg[dest][begin+i]=saturn.reg[src][begin+i];
954833      saturn_ICount-=2;
955834   }
956835}
r2724r2725
960839 ****************************************************************************/
961840INLINE void saturn_add(int reg, int begin, int count, int right)
962841{
963   int i, t=0;
842   int i, t;
843   int base=saturn.decimal?10:16;
844   saturn_assert(reg>=0 && reg<9);
845   saturn_assert(right>=0 && right<9);
846   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
847   saturn.carry=0;
964848   for (i=0; i<count; i++) {
965      if (t>0x10) {
966         t=S64_READ_NIBBLE(reg, (begin+i)&0xf)+1;
967      } else {
968         t=S64_READ_NIBBLE(reg, (begin+i)&0xf);
849      t=saturn.reg[reg][begin+i];
850      t+=saturn.reg[right][begin+i];
851      t+=saturn.carry;
852      if (t>=base) {
853         saturn.carry=1;
854         t-=base;
969855      }
970      t+=S64_READ_NIBBLE(right, (begin+i)&0xf );
971      S64_WRITE_NIBBLE(reg, (begin+i)&0xf , t&0x0f);
856      else saturn.carry=0;
857      saturn_assert(t>=0); saturn_assert(t<base);
858      saturn.reg[reg][begin+i]=t&0xf;
972859      saturn_ICount-=2;
973860   }
974   saturn.carry=t==0x10;
975861}
976862
977863INLINE void saturn_add_const(int reg, int begin, int count, SaturnNib right)
978864{
979   int i, t=0;
865   int i, t;
866   int base=saturn.decimal?10:16;
867   saturn_assert(reg>=0 && reg<9);
868   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
869   saturn_assert(count>1 || !saturn.decimal); /* SATURN bug */
980870   for (i=0; i<count; i++) {
981      t=S64_READ_NIBBLE(reg, (begin+i)&0xf);
982      t+=right;
983      right=(right>>4)+1;
984      S64_WRITE_NIBBLE(reg, (begin+i)&0xf, t&0x0f);
871      t=saturn.reg[reg][begin+i];
872      t+=(right&0xf);
873      right>>=4;
874      if (t>=base) {
875         right++;
876         t-=base;
877      }
878      saturn_assert(t>=0); saturn_assert(t<base);
879      saturn.reg[reg][begin+i]=t&0xf;
985880      saturn_ICount-=2;
986      if (t<0x10) break;
881      if (!right) break;
987882   }
988   saturn.carry=t>=0x10;
883   saturn.carry=right>0;
989884}
990885
991886/****************************************************************************
r2724r2725
993888 ****************************************************************************/
994889INLINE void saturn_sub(int reg, int begin, int count, int right)
995890{
996   int i, t=0;
891   int i, t;
892   int base=saturn.decimal?10:16;
893   saturn_assert(reg>=0 && reg<9);
894   saturn_assert(right>=0 && right<9);
895   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
896   saturn.carry=0;
997897   for (i=0; i<count; i++) {
998      if (t>0x10) {
999         t=S64_READ_NIBBLE(reg, (begin+i)&0xf)-1;
1000      } else {
1001         t=S64_READ_NIBBLE(reg, (begin+i)&0xf );
898      t=saturn.reg[reg][begin+i];
899      t-=saturn.reg[right][begin+i];
900      t-=saturn.carry;
901      if (t<0) {
902         saturn.carry=1;
903         t+=base;
1002904      }
1003      t-=S64_READ_NIBBLE(right, (begin+i)&0xf );
1004      S64_WRITE_NIBBLE(reg, (begin+i)&0xf, t&0x0f);
905      else saturn.carry=0;
906      saturn_assert(t>=0); saturn_assert(t<base);
907      saturn.reg[reg][begin+i]=t&0xf;
1005908      saturn_ICount-=2;
1006909   }
1007   saturn.carry=t<0;
1008910}
1009911
1010912INLINE void saturn_sub_const(int reg, int begin, int count, int right)
1011913{
1012   int i, t=0;
914   int i, t;
915   int base=saturn.decimal?10:16;
916   saturn_assert(reg>=0 && reg<9);
917   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
918   saturn_assert(count>1 || !saturn.decimal); /* SATURN bug */
1013919   for (i=0; i<count; i++) {
1014      t=S64_READ_NIBBLE(reg, (begin+i)&0xf );
1015      t-=right;
1016      right=(right>>4)+1;
1017      S64_WRITE_NIBBLE(reg, (begin+i)&0xf, t&0x0f);
920      t=saturn.reg[reg][begin+i];
921      t-=(right&0xf);
922      right>>=4;
923      if (t<0) {
924         right++;
925         t+=base;
926      }
927      saturn_assert(t>=0); saturn_assert(t<base);
928      saturn.reg[reg][begin+i]=t&0xf;
1018929      saturn_ICount-=2;
1019      if (t>=0) break;
930      if (!right) break;
1020931   }
1021   saturn.carry=t<0;
932   saturn.carry=right>0;
1022933}
1023934
1024935/****************************************************************************
r2724r2725
1026937 ****************************************************************************/
1027938INLINE void saturn_sub2(int reg, int begin, int count, int right)
1028939{
1029   int i, t=0;
940   int i, t;
941   int base=saturn.decimal?10:16;
942   saturn_assert(reg>=0 && reg<9);
943   saturn_assert(right>=0 && right<9);
944   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
945   saturn.carry=0;
1030946   for (i=0; i<count; i++) {
1031      t=S64_READ_NIBBLE(reg, (begin+i)&0xf );
1032      t=S64_READ_NIBBLE(right, i)-t;
1033      S64_WRITE_NIBBLE(reg, (begin+i)&0xf, t&0x0f);
947      t=saturn.reg[right][begin+i];
948      t-=saturn.reg[reg][begin+i];
949      t-=saturn.carry;
950      if (t<0) {
951         saturn.carry=1;
952         t+=base;
953      }
954      else saturn.carry=0;
955      saturn_assert(t>=0); saturn_assert(t<base);
956      saturn.reg[reg][begin+i]=t&0xf;
1034957      saturn_ICount-=2;
1035      if (t>=0) break;
1036958   }
1037   saturn.carry=t<0;
1038959}
1039960
1040961/****************************************************************************
r2724r2725
1043964INLINE void saturn_increment(int reg, int begin, int count)
1044965{
1045966   int i, t=0;
967   int base=saturn.decimal?10:16;
968   saturn_assert(reg>=0 && reg<9);
969   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
1046970   for (i=0; i<count; i++) {
1047      t=S64_READ_NIBBLE(reg, (begin+i)&0xf );
1048      t++;
1049      S64_WRITE_NIBBLE(reg, (begin+i)&0xf, t&0x0f);
1050971      saturn_ICount-=2;
1051      if (t!=0x10) break;
972      t=saturn.reg[reg][begin+i];
973      t++;
974      if (t>=base) saturn.reg[reg][begin+i]=t-base;
975      else { saturn.reg[reg][begin+i]=t; break; }
1052976   }
977   saturn.carry=t>=base;
1053978}
1054979
1055980/****************************************************************************
r2724r2725
1058983INLINE void saturn_decrement(int reg, int begin, int count)
1059984{
1060985   int i, t=0;
986   int base=saturn.decimal?10:16;
987   saturn_assert(reg>=0 && reg<9);
988   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
1061989   for (i=0; i<count; i++) {
1062      t=S64_READ_NIBBLE(reg, (begin+i)&0xf );
1063      t=(t-1)&0xf;
1064      S64_WRITE_NIBBLE(reg, (begin+i)&0xf, t);
1065990      saturn_ICount-=2;
1066      if (t!=0) break;
991      t=saturn.reg[reg][begin+i];
992      t--;
993      if (t<0) saturn.reg[reg][begin+i]=t+base;
994      else { saturn.reg[reg][begin+i]=t; break; }
1067995   }
1068   saturn.carry=t==0;
996   saturn.carry=t<0;
1069997}
1070998
1071999/****************************************************************************
r2724r2725
10741002INLINE void saturn_invert(int reg, int begin, int count)
10751003{
10761004   int i;
1077   SaturnNib n;
1078   saturn.carry=1;
1005   int max=saturn.decimal?9:15;
1006   saturn_assert(reg>=0 && reg<9);
1007   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
1008   saturn.carry=0;
10791009   for (i=0; i<count; i++) {
1080      S64_WRITE_NIBBLE(reg, (begin+i)&0xf, (n=S64_READ_NIBBLE(reg,(begin+i)&0xf)) ^ 0xf);
1081      saturn.carry=saturn.carry && (n==0);
1010      saturn.reg[reg][begin+i]=(max-saturn.reg[reg][begin+i])&0xf;
10821011      saturn_ICount-=2;
10831012   }
10841013}
r2724r2725
10861015/****************************************************************************
10871016 negate (2 complement)  opers
10881017 ****************************************************************************/
1089INLINE void   saturn_negate(int reg, int begin, int count)
1018INLINE void saturn_negate(int reg, int begin, int count)
10901019{
1091   int i;
1092   SaturnNib n;
1093   saturn.carry=1;
1020   int i, n, c;
1021   int max=saturn.decimal?9:15;
1022   saturn_assert(reg>=0 && reg<9);
1023   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
1024   c=1;
1025   saturn.carry=0;
10941026   for (i=0; i<count; i++) {
1095      n=S64_READ_NIBBLE(reg, (begin+i)&0xf );
1096      saturn.carry=saturn.carry && (n==0);
1097      n=((n ^ 0xf)+1)&0xf;
1098      S64_WRITE_NIBBLE(reg, (begin+i)&0xf, n);
1027      n=saturn.reg[reg][begin+i];
1028      if (n) saturn.carry=1;
1029      n=max+c-n;
1030      if (n>max) n-=max+1;
1031      else c=0;
1032      saturn_assert(n>=0); saturn_assert(n<=max);
1033      saturn.reg[reg][begin+i]=n&0xf;
10991034      saturn_ICount-=2;
11001035   }
11011036}
r2724r2725
11061041INLINE void saturn_or(int dest, int begin, int count, int src)
11071042{
11081043   int i;
1044   saturn_assert(dest>=0 && dest<9);
1045   saturn_assert(src>=0 && src<9);
1046   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
11091047   for (i=0; i<count; i++) {
1110      S64_WRITE_NIBBLE(dest, (begin+i)&0xf,
1111                   S64_READ_NIBBLE(dest,(begin+i)&0xf)|S64_READ_NIBBLE(src,(begin+i)&0xf));
1048      saturn.reg[dest][begin+i]|=saturn.reg[src][begin+i];
11121049      saturn_ICount-=2;
11131050   }
11141051}
r2724r2725
11191056INLINE void saturn_and(int dest, int begin, int count, int src)
11201057{
11211058   int i;
1059   saturn_assert(dest>=0 && dest<9);
1060   saturn_assert(src>=0 && src<9);
1061   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
11221062   for (i=0; i<count; i++) {
1123      S64_WRITE_NIBBLE(dest, (begin+i)&0xf,
1124                   S64_READ_NIBBLE(dest,(begin+i)&0xf)&S64_READ_NIBBLE(src,(begin+i)&0xf));
1063      saturn.reg[dest][begin+i]&=saturn.reg[src][begin+i];
11251064      saturn_ICount-=2;
11261065   }
11271066}
r2724r2725
11321071INLINE void saturn_shift_nibble_left(int reg, int begin, int count)
11331072{
11341073   int i;
1135   for (i=count; i>1; i--) {
1136      S64_WRITE_NIBBLE(reg, (begin+i)&0xf, S64_READ_NIBBLE(reg,(begin+i-1)&0xf) );
1074   saturn_assert(reg>=0 && reg<9);
1075   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
1076   if (saturn.reg[reg][begin+count-1]) saturn.hst|=SB;
1077   for (i=count-1; i>=1; i--) {
1078      saturn.reg[reg][begin+i]=saturn.reg[reg][begin+i-1];
11371079      saturn_ICount-=2;
11381080   }
1139   S64_WRITE_NIBBLE(reg, begin, 0);
1081   saturn.reg[reg][begin]=0;
11401082   saturn_ICount-=2;
11411083}
11421084
r2724r2725
11461088INLINE void saturn_shift_nibble_right(int reg, int begin, int count)
11471089{
11481090   int i;
1091   saturn_assert(reg>=0 && reg<9);
1092   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
1093   if (saturn.reg[reg][begin]) saturn.hst|=SB;
11491094   for (i=1; i<count; i++) {
1150      S64_WRITE_NIBBLE(reg, (begin+i-1)&0xf, S64_READ_NIBBLE(reg,(begin+i)&0xf) );
1095      saturn.reg[reg][begin+i-1]=saturn.reg[reg][begin+i];
11511096      saturn_ICount-=2;
11521097   }
1153   S64_WRITE_NIBBLE(reg, (begin+i-1)&0xf, 0);
1098   saturn.reg[reg][begin+count-1]=0;
11541099   saturn_ICount-=2;
11551100}
11561101
1102
11571103/****************************************************************************
1158 rotate nibble left opers
1104 rotate nibbles left opers
11591105 ****************************************************************************/
11601106INLINE void saturn_rotate_nibble_left_w(int reg)
11611107{
1162   SaturnNib a=S64_READ_NIBBLE(reg, 15);
1163   S64_WRITE_W(reg, S64_READ_W(reg)<<4);
1164   S64_WRITE_NIBBLE(reg,0,a);
1165   saturn_ICount-=32;
1108   int i, x=saturn.reg[reg][15];
1109   saturn_assert(reg>=0 && reg<9);
1110   for (i=15; i>=1; i--) {
1111      saturn.reg[reg][i]=saturn.reg[reg][i-1];
1112      saturn_ICount-=2;
1113   }
1114   saturn.reg[reg][0]=x;
1115   saturn_ICount-=2;
11661116}
11671117
1118/****************************************************************************
1119 rotate nibbles right opers
1120 ****************************************************************************/
11681121INLINE void saturn_rotate_nibble_right_w(int reg)
11691122{
1170   SaturnNib a=S64_READ_NIBBLE(reg,0);
1171   if (a) saturn.hst|=SB;
1172   S64_WRITE_W(reg, S64_READ_W(reg)>>4);
1173   S64_WRITE_NIBBLE(reg,15,a);
1174   saturn_ICount-=32;
1123   int i, x=saturn.reg[reg][0];
1124   saturn_assert(reg>=0 && reg<9);
1125   for (i=1; i<16; i++) {
1126      saturn.reg[reg][i-1]=saturn.reg[reg][i];
1127      saturn_ICount-=2;
1128   }
1129   saturn.reg[reg][15]=x;
1130   if (x) saturn.hst|=SB;
1131   saturn_ICount-=2;
11751132}
11761133
1134
11771135/****************************************************************************
11781136 shift right opers
11791137 ****************************************************************************/
11801138INLINE void saturn_shift_right(int reg, int begin, int count)
11811139{
11821140   int i, t, c=0;
1183   for (i=count; i>=count; i--) {
1184      t=S64_READ_NIBBLE(reg, (begin+i)&0xf );
1185      if (c) t|=0x10;
1141   saturn_assert(reg>=0 && reg<9);
1142   saturn_assert(begin>=0 && count>=0 && begin+count<=16);
1143   for (i=count-1; i>=0; i--) {
1144      t=saturn.reg[reg][begin+i];
1145      t|=(c<<4);
11861146      c=t&1;
1187      S64_WRITE_NIBBLE(reg, (begin+i-1)&0xf, t>>1);
1147      saturn.reg[reg][begin+i]=t>>1;
11881148      saturn_ICount-=2;
11891149   }
11901150   if (c) saturn.hst|=SB;
11911151   saturn_ICount-=2;
11921152}
1193
1194
1195/****************************************************************************
1196 shift left opers, sets carry!
1197 ****************************************************************************/
1198INLINE void saturn_shift_left(int reg, int begin, int count)
1199{
1200   SaturnNib t;
1201   int i;
1202   saturn.carry=0;
1203   for (i=0; i<count; i++) {
1204      t=S64_READ_NIBBLE(reg,(begin+i)&0xf);
1205      S64_WRITE_NIBBLE(reg, (begin+i)&0xf, ((t<<1)&0xf)|saturn.carry);
1206      saturn.carry=t&8?1:0;
1207      saturn_ICount-=2;
1208   }
1209}
src/emu/cpu/saturn/saturn.c
r2724r2725
66 *
77 *   Copyright Peter Trauner, all rights reserved.
88 *
9 *   Modified by Antoine Mine'
10 *
911 *   - This source code is released as freeware for non-commercial purposes.
1012 *   - You are free to use and redistribute this code in modified or
1113 *     unmodified form, provided you list me in the credits.
r2724r2725
2224#include "debugger.h"
2325
2426#include "saturn.h"
25#include "sat.h"
27#include "deprecat.h" /* for Machine */
2628
2729#define R0 0
2830#define R1 1
r2724r2725
3335#define B 6
3436#define C 7
3537#define D 8
38#define I 9 // invalid
3639
37typedef int SaturnAdr; // 20 bit
38typedef UINT8 SaturnNib; // 4 bit
39typedef short SaturnX; // 12 bit
40typedef INT64 SaturnM; // 48 bit
40typedef UINT32 SaturnAdr;   // 20 bit, packed
41typedef UINT8  SaturnNib;   // 4 bit
4142
42typedef union {
43   UINT8 b[8];
44   UINT16 w[4];
45   UINT32 d[2];
46   UINT64 q;
47} Saturn64;
43// 64 bit, unpacked (one nibble per byte)
44typedef SaturnNib Saturn64[16];
4845
4946#define VERBOSE 0
5047
r2724r2725
5249
5350
5451/****************************************************************************
55 * The 6502 registers.
52 * The SATURN registers.
5653 ****************************************************************************/
5754typedef struct
5855{
5956   SATURN_CONFIG *config;
60   Saturn64 reg[9]; //r0,r1,r2,r3,r4,a,b,c,d;
6157
58   Saturn64 reg[9]; //r0,r1,r2,r3,r4,a,b,c,d
59
6260   SaturnAdr d[2], pc, oldpc, rstk[8]; // 20 bit addresses
6361
64   int stackpointer; // this is only for debugger stepover support!
65
6662   SaturnNib p; // 4 bit pointer
6763
68   UINT16 in;
69   int out; // 12
70   int carry, decimal;
64        UINT16 out; // 12 bit (packed)
65   UINT8  carry, decimal;
7166   UINT16 st; // status 16 bit
72#define XM 1
73#define SR 2
74#define SB 4
75#define MP 8
76   int hst; // hardware status 4 bit
77      /*  XM external Modules missing
78            SR Service Request
79            SB Sticky bit
80            MP Module Pulled */
8167
82   int irq_state;
68   SaturnNib hst; // hardware status 4 bit
69#define XM 1 // external Modules missing
70#define SB 2 // Sticky bit
71#define SR 4 // Service Request
72#define MP 8 // Module Pulled
8373
84   UINT8   pending_irq;   /* nonzero if an IRQ is pending */
85   UINT8   after_cli;      /* pending IRQ and last insn cleared I */
8674   UINT8   nmi_state;
75   UINT8   irq_state;
76   UINT8   irq_enable;     /* INTON / INTOFF */
77   UINT8   in_irq;         /* already servicing IRQ */
78   UINT8   pending_irq;   /* IRQ is pending */
79   UINT8   sleeping;       /* low-consumption state */
8780   int    (*irq_callback)(int irqline);   /* IRQ callback */
8881}   Saturn_Regs;
8982
r2724r2725
9487/***************************************************************
9588 * include the opcode macros, functions and tables
9689 ***************************************************************/
90
9791#include "satops.c"
9892#include "sattable.c"
9993
r2724r2725
106100static void saturn_init(int index, int clock, const void *config, int (*irqcallback)(int))
107101{
108102   saturn.config = (SATURN_CONFIG *) config;
103   saturn.irq_callback = irqcallback;
104
105   state_save_register_item_array("saturn",index,saturn.reg[R0]);
106   state_save_register_item_array("saturn",index,saturn.reg[R1]);
107   state_save_register_item_array("saturn",index,saturn.reg[R2]);
108   state_save_register_item_array("saturn",index,saturn.reg[R3]);
109   state_save_register_item_array("saturn",index,saturn.reg[R4]);
110   state_save_register_item_array("saturn",index,saturn.reg[A]);
111   state_save_register_item_array("saturn",index,saturn.reg[B]);
112   state_save_register_item_array("saturn",index,saturn.reg[C]);
113   state_save_register_item_array("saturn",index,saturn.reg[D]);
114   state_save_register_item_array("saturn",index,saturn.d);
115   state_save_register_item("saturn",index,saturn.pc);
116   state_save_register_item("saturn",index,saturn.oldpc);
117   state_save_register_item_array("saturn",index,saturn.rstk);
118   state_save_register_item("saturn",index,saturn.out);
119   state_save_register_item("saturn",index,saturn.carry);
120   state_save_register_item("saturn",index,saturn.st);
121   state_save_register_item("saturn",index,saturn.hst);
122   state_save_register_item("saturn",index,saturn.nmi_state);
123   state_save_register_item("saturn",index,saturn.irq_state);
124   state_save_register_item("saturn",index,saturn.irq_enable);
125   state_save_register_item("saturn",index,saturn.in_irq);
126   state_save_register_item("saturn",index,saturn.pending_irq);
127   state_save_register_item("saturn",index,saturn.sleeping);
109128}
110129
111130static void saturn_reset(void)
112131{
113   saturn.stackpointer=0;
114132   saturn.pc=0;
133   saturn.sleeping = 0;
134   saturn.irq_enable = 0;
135   saturn.in_irq = 0;
115136   change_pc(saturn.pc);
116137}
117138
r2724r2725
134155
135156INLINE void saturn_take_irq(void)
136157{
137   {
138      saturn_ICount -= 7;
158   saturn.in_irq = 1;       /* reset by software, using RTI */
159   saturn.pending_irq = 0;
160   saturn_ICount -= 7;
161   saturn_push(saturn.pc);
162   saturn.pc=IRQ_ADDRESS;
139163
140      saturn_push(saturn.pc);
141      saturn.pc=IRQ_ADDRESS;
164   LOG(("Saturn#%d takes IRQ ($%04x)\n", cpu_getactivecpu(), saturn.pc));
142165
143      LOG(("Saturn#%d takes IRQ ($%04x)\n", cpu_getactivecpu(), saturn.pc));
144      /* call back the cpuintrf to let it clear the line */
145      if (saturn.irq_callback) (*saturn.irq_callback)(0);
146      change_pc(saturn.pc);
147   }
148   saturn.pending_irq = 0;
166   if (saturn.irq_callback) (*saturn.irq_callback)(SATURN_IRQ_LINE);
167   change_pc(saturn.pc);
149168}
150169
151170static int saturn_execute(int cycles)
r2724r2725
160179
161180      CALL_DEBUGGER(saturn.pc);
162181
163      /* if an irq is pending, take it now */
164      if( saturn.pending_irq )
165         saturn_take_irq();
166
167      saturn_instruction();
168
169      /* check if the I flag was just reset (interrupts enabled) */
170      if( saturn.after_cli )
182      if ( saturn.sleeping )
171183      {
172         LOG(("M6502#%d after_cli was >0", cpu_getactivecpu()));
173         saturn.after_cli = 0;
174         if (saturn.irq_state != CLEAR_LINE)
175         {
176            LOG((": irq line is asserted: set pending IRQ\n"));
177            saturn.pending_irq = 1;
178         }
179         else
180         {
181            LOG((": irq line is clear\n"));
182         }
184         /* advance time when sleeping */
185         saturn_ICount -= 100;
183186      }
184187      else
185      if( saturn.pending_irq )
186         saturn_take_irq();
188      {
189         /* takes irq */
190         if ( saturn.pending_irq && (!saturn.in_irq) )
191            saturn_take_irq();
187192
193         /* execute one instruction */
194         saturn_instruction();
195      }
196
188197   } while (saturn_ICount > 0);
189198
190199   return cycles - saturn_ICount;
191200}
192201
193#ifdef UNUSED_FUNCTION
194void saturn_set_nmi_line(int state)
202
203static void saturn_set_nmi_line(int state)
195204{
196   if (saturn.nmi_state == state) return;
205   if ( state == saturn.nmi_state ) return;
197206   saturn.nmi_state = state;
198   if( state != CLEAR_LINE )
207   if ( state != CLEAR_LINE )
199208   {
200      LOG(( "M6502#%d set_nmi_line(ASSERT)\n", cpu_getactivecpu()));
201      saturn_ICount -= 7;
202      saturn_push(saturn.pc);
203      saturn.pc=IRQ_ADDRESS;
204
205      LOG(("M6502#%d takes NMI ($%04x)\n", cpu_getactivecpu(), PC));
206      change_pc(saturn.pc);
209      LOG(( "SATURN#%d set_nmi_line(ASSERT)\n", cpu_getactivecpu()));
210      saturn.pending_irq = 1;
207211   }
208212}
209213
210void saturn_set_irq_line(int irqline, int state)
214static void saturn_set_irq_line(int state)
211215{
216   if ( state == saturn.irq_state ) return;
212217   saturn.irq_state = state;
213   if( state != CLEAR_LINE )
218   if ( state != CLEAR_LINE && saturn.irq_enable )
214219   {
215      LOG(( "M6502#%d set_irq_line(ASSERT)\n", cpu_getactivecpu()));
220      LOG(( "SATURN#%d set_irq_line(ASSERT)\n", cpu_getactivecpu()));
216221      saturn.pending_irq = 1;
217222   }
218223}
219224
220void saturn_set_irq_callback(int (*callback)(int))
225static void saturn_set_wakeup_line(int state)
221226{
222   saturn.irq_callback = callback;
227   if (saturn.sleeping && state==1)
228   {
229      LOG(( "SATURN#%d set_wakeup_line(ASSERT)\n", cpu_getactivecpu()));
230      if (saturn.irq_callback) (*saturn.irq_callback)(SATURN_WAKEUP_LINE);
231      saturn.sleeping = 0;
232   }
223233}
224#endif
225234
226#if 0
227static void saturn_state_save(void *file)
228{
229   int cpu = cpu_getactivecpu();
230   state_save_UINT16(file,"m6502",cpu,"PC",&m6502.pc.w.l,2);
231   state_save_UINT16(file,"m6502",cpu,"SP",&m6502.sp.w.l,2);
232   state_save_UINT8(file,"m6502",cpu,"P",&m6502.p,1);
233   state_save_UINT8(file,"m6502",cpu,"A",&m6502.a,1);
234   state_save_UINT8(file,"m6502",cpu,"X",&m6502.x,1);
235   state_save_UINT8(file,"m6502",cpu,"Y",&m6502.y,1);
236   state_save_UINT8(file,"m6502",cpu,"PENDING",&m6502.pending_irq,1);
237   state_save_UINT8(file,"m6502",cpu,"AFTER_CLI",&m6502.after_cli,1);
238   state_save_UINT8(file,"m6502",cpu,"NMI_STATE",&m6502.nmi_state,1);
239   state_save_UINT8(file,"m6502",cpu,"IRQ_STATE",&m6502.irq_state,1);
240   state_save_UINT8(file,"m6502",cpu,"SO_STATE",&m6502.so_state,1);
241}
242235
243static void saturn_state_load(void *file)
244{
245   int cpu = cpu_getactivecpu();
246   state_load_UINT16(file,"m6502",cpu,"PC",&m6502.pc.w.l,2);
247   state_load_UINT16(file,"m6502",cpu,"SP",&m6502.sp.w.l,2);
248   state_load_UINT8(file,"m6502",cpu,"P",&m6502.p,1);
249   state_load_UINT8(file,"m6502",cpu,"A",&m6502.a,1);
250   state_load_UINT8(file,"m6502",cpu,"X",&m6502.x,1);
251   state_load_UINT8(file,"m6502",cpu,"Y",&m6502.y,1);
252   state_load_UINT8(file,"m6502",cpu,"PENDING",&m6502.pending_irq,1);
253   state_load_UINT8(file,"m6502",cpu,"AFTER_CLI",&m6502.after_cli,1);
254   state_load_UINT8(file,"m6502",cpu,"NMI_STATE",&m6502.nmi_state,1);
255   state_load_UINT8(file,"m6502",cpu,"IRQ_STATE",&m6502.irq_state,1);
256   state_load_UINT8(file,"m6502",cpu,"SO_STATE",&m6502.so_state,1);
257}
258#endif
259236
260237/**************************************************************************
261238 * Generic set_info
262239 **************************************************************************/
263240
241static void IntReg64(Saturn64 r, INT64 d)
242{
243   int i;
244   for (i=0; i<16; i++)
245      r[i] = (d >> (4*i)) & 0xf;
246}
247
248
264249static void saturn_set_info(UINT32 state, cpuinfo *info)
265250{
266251   switch (state)
267252   {
268253      /* --- the following bits of info are set as 64-bit signed integers --- */
269      case CPUINFO_INT_INPUT_STATE + SATURN_NMI_STATE:   saturn.nmi_state = info->i;   break;
270      case CPUINFO_INT_INPUT_STATE + SATURN_IRQ_STATE:   saturn.irq_state = info->i;   break;
254           case CPUINFO_INT_INPUT_STATE + SATURN_NMI_LINE:           saturn_set_nmi_line(info->i);   break;
255            case CPUINFO_INT_INPUT_STATE + SATURN_IRQ_LINE:           saturn_set_irq_line(info->i);   break;
256            case CPUINFO_INT_INPUT_STATE + SATURN_WAKEUP_LINE:   saturn_set_wakeup_line(info->i);   break;
271257
272258      case CPUINFO_INT_PC:
273259      case CPUINFO_INT_REGISTER + SATURN_PC:         saturn.pc = info->i; change_pc(saturn.pc);            break;
274      case CPUINFO_INT_SP:                     saturn.stackpointer = info->i;                     break;
275260      case CPUINFO_INT_REGISTER + SATURN_D0:         saturn.d[0] = info->i;                     break;
276261      case CPUINFO_INT_REGISTER + SATURN_D1:         saturn.d[1] = info->i;                     break;
277#if 0
278      case CPUINFO_INT_REGISTER + SATURN_A:         saturn.reg[A] = info->i;                     break;
279      case CPUINFO_INT_REGISTER + SATURN_B:         saturn.reg[B] = info->i;                     break;
280      case CPUINFO_INT_REGISTER + SATURN_C:         saturn.reg[C] = info->i;                     break;
281      case CPUINFO_INT_REGISTER + SATURN_D:         saturn.reg[D] = info->i;                     break;
282      case CPUINFO_INT_REGISTER + SATURN_R0:         saturn.reg[R0] = info->i;                     break;
283      case CPUINFO_INT_REGISTER + SATURN_R1:         saturn.reg[R1] = info->i;                     break;
284      case CPUINFO_INT_REGISTER + SATURN_R2:         saturn.reg[R2] = info->i;                     break;
285      case CPUINFO_INT_REGISTER + SATURN_R3:         saturn.reg[R3] = info->i;                     break;
286      case CPUINFO_INT_REGISTER + SATURN_R4:         saturn.reg[R4] = info->i;                     break;
287#endif
262             case CPUINFO_INT_REGISTER + SATURN_A:         IntReg64(saturn.reg[A], info->i);                     break;
263             case CPUINFO_INT_REGISTER + SATURN_B:         IntReg64(saturn.reg[B], info->i);                     break;
264             case CPUINFO_INT_REGISTER + SATURN_C:         IntReg64(saturn.reg[C], info->i);                     break;
265             case CPUINFO_INT_REGISTER + SATURN_D:         IntReg64(saturn.reg[D], info->i);                     break;
266             case CPUINFO_INT_REGISTER + SATURN_R0:         IntReg64(saturn.reg[R0], info->i);                     break;
267             case CPUINFO_INT_REGISTER + SATURN_R1:         IntReg64(saturn.reg[R1], info->i);                     break;
268             case CPUINFO_INT_REGISTER + SATURN_R2:         IntReg64(saturn.reg[R2], info->i);                     break;
269             case CPUINFO_INT_REGISTER + SATURN_R3:         IntReg64(saturn.reg[R3], info->i);                     break;
270             case CPUINFO_INT_REGISTER + SATURN_R4:         IntReg64(saturn.reg[R4], info->i);                     break;
288271      case CPUINFO_INT_REGISTER + SATURN_P:         saturn.p = info->i;                     break;
289      case CPUINFO_INT_REGISTER + SATURN_IN:         saturn.in = info->i;                     break;
290272      case CPUINFO_INT_REGISTER + SATURN_OUT:         saturn.out = info->i;                     break;
291273      case CPUINFO_INT_REGISTER + SATURN_CARRY:      saturn.carry = info->i;                     break;
292274      case CPUINFO_INT_REGISTER + SATURN_ST:         saturn.st = info->i;                     break;
r2724r2725
299281      case CPUINFO_INT_REGISTER + SATURN_RSTK5:      saturn.rstk[5] = info->i;                     break;
300282      case CPUINFO_INT_REGISTER + SATURN_RSTK6:      saturn.rstk[6] = info->i;                     break;
301283      case CPUINFO_INT_REGISTER + SATURN_RSTK7:      saturn.rstk[7] = info->i;                     break;
284                case CPUINFO_INT_REGISTER + SATURN_SLEEPING:      saturn.sleeping = info->i;
302285   }
303286}
304287
r2724r2725
306289 * Generic get_info
307290 **************************************************************************/
308291
292#define Reg64Data(s) s[15],s[14],s[13],s[12],s[11],s[10],s[9],s[8],s[7],s[6],s[5],s[4],s[3],s[2],s[1],s[0]
293#define Reg64Format "%x %x%x%x%x%x%x%x %x%x%x %x%x%x%x%x"
294
295static INT64 Reg64Int(Saturn64 r)
296{
297   INT64 x = 0;
298   int i;
299   for (i=0; i<16; i++)
300      x |= (INT64) r[i] << (4*i);
301   return x;
302}
303
309304void saturn_get_info(UINT32 state, cpuinfo *info)
310305{
311306   switch (state)
r2724r2725
332327      case CPUINFO_INT_ADDRBUS_WIDTH + ADDRESS_SPACE_IO:       info->i = 0;               break;
333328      case CPUINFO_INT_ADDRBUS_SHIFT + ADDRESS_SPACE_IO:       info->i = 0;               break;
334329
335      case CPUINFO_INT_INPUT_STATE + SATURN_NMI_STATE:   info->i = saturn.nmi_state;            break;
336      case CPUINFO_INT_INPUT_STATE + SATURN_IRQ_STATE:   info->i = saturn.irq_state;            break;
330      case CPUINFO_INT_INPUT_STATE + SATURN_NMI_LINE:           info->i = saturn.nmi_state;            break;
331      case CPUINFO_INT_INPUT_STATE + SATURN_IRQ_LINE:           info->i = saturn.irq_state;            break;
337332
338333      case CPUINFO_INT_PREVIOUSPC:               info->i = saturn.oldpc;               break;
339334
340335      case CPUINFO_INT_PC:
341336      case CPUINFO_INT_REGISTER + SATURN_PC:         info->i = saturn.pc;               break;
342      case CPUINFO_INT_SP:                     info->i = saturn.stackpointer;         break;
343337      case CPUINFO_INT_REGISTER + SATURN_D0:         info->i = saturn.d[0];               break;
344338      case CPUINFO_INT_REGISTER + SATURN_D1:         info->i = saturn.d[1];               break;
345#if 0
346      case CPUINFO_INT_REGISTER + SATURN_A:         info->i = saturn.reg[A];            break;
347      case CPUINFO_INT_REGISTER + SATURN_B:         info->i = saturn.reg[B];            break;
348      case CPUINFO_INT_REGISTER + SATURN_C:         info->i = saturn.reg[C];            break;
349      case CPUINFO_INT_REGISTER + SATURN_D:         info->i = saturn.reg[D];            break;
350      case CPUINFO_INT_REGISTER + SATURN_R0:         info->i = saturn.reg[R0];            break;
351      case CPUINFO_INT_REGISTER + SATURN_R1:         info->i = saturn.reg[R1];            break;
352      case CPUINFO_INT_REGISTER + SATURN_R2:         info->i = saturn.reg[R2];            break;
353      case CPUINFO_INT_REGISTER + SATURN_R3:         info->i = saturn.reg[R3];            break;
354      case CPUINFO_INT_REGISTER + SATURN_R4:         info->i = saturn.reg[R4];            break;
355#endif
339
340                case CPUINFO_INT_REGISTER + SATURN_A:         info->i = Reg64Int(saturn.reg[A]);            break;
341                case CPUINFO_INT_REGISTER + SATURN_B:         info->i = Reg64Int(saturn.reg[B]);            break;
342                case CPUINFO_INT_REGISTER + SATURN_C:         info->i = Reg64Int(saturn.reg[C]);            break;
343                case CPUINFO_INT_REGISTER + SATURN_D:         info->i = Reg64Int(saturn.reg[D]);            break;
344                case CPUINFO_INT_REGISTER + SATURN_R0:         info->i = Reg64Int(saturn.reg[R0]);            break;
345           case CPUINFO_INT_REGISTER + SATURN_R1:         info->i = Reg64Int(saturn.reg[R1]);            break;
346                  case CPUINFO_INT_REGISTER + SATURN_R2:         info->i = Reg64Int(saturn.reg[R2]);            break;
347           case CPUINFO_INT_REGISTER + SATURN_R3:         info->i = Reg64Int(saturn.reg[R3]);            break;
348           case CPUINFO_INT_REGISTER + SATURN_R4:         info->i = Reg64Int(saturn.reg[R4]);            break;
349
356350      case CPUINFO_INT_REGISTER + SATURN_P:         info->i = saturn.p;                  break;
357      case CPUINFO_INT_REGISTER + SATURN_IN:         info->i = saturn.in;               break;
358351      case CPUINFO_INT_REGISTER + SATURN_OUT:         info->i = saturn.out;               break;
359352      case CPUINFO_INT_REGISTER + SATURN_CARRY:      info->i = saturn.carry;               break;
360353      case CPUINFO_INT_REGISTER + SATURN_ST:         info->i = saturn.st;               break;
r2724r2725
367360      case CPUINFO_INT_REGISTER + SATURN_RSTK5:      info->i = saturn.rstk[5];            break;
368361      case CPUINFO_INT_REGISTER + SATURN_RSTK6:      info->i = saturn.rstk[6];            break;
369362      case CPUINFO_INT_REGISTER + SATURN_RSTK7:      info->i = saturn.rstk[7];            break;
363           case CPUINFO_INT_REGISTER + SATURN_SLEEPING:      info->i = saturn.sleeping;
370364
371365      /* --- the following bits of info are returned as pointers to data or functions --- */
372366      case CPUINFO_PTR_SET_INFO:                  info->setinfo = saturn_set_info;         break;
r2724r2725
391385      case CPUINFO_STR_REGISTER + SATURN_PC:      sprintf(info->s = cpuintrf_temp_str(), "PC:   %.5x", saturn.pc);break;
392386      case CPUINFO_STR_REGISTER + SATURN_D0:      sprintf(info->s = cpuintrf_temp_str(), "D0:   %.5x", saturn.d[0]);break;
393387      case CPUINFO_STR_REGISTER + SATURN_D1:      sprintf(info->s = cpuintrf_temp_str(), "D1:   %.5x", saturn.d[1]);break;
394      case CPUINFO_STR_REGISTER + SATURN_A:      sprintf(info->s = cpuintrf_temp_str(), "A: %.8x %.8x", saturn.reg[A].d[1], saturn.reg[A].d[0]);break;
395      case CPUINFO_STR_REGISTER + SATURN_B:      sprintf(info->s = cpuintrf_temp_str(), "B: %.8x %.8x", saturn.reg[B].d[1], saturn.reg[B].d[0]);break;
396      case CPUINFO_STR_REGISTER + SATURN_C:      sprintf(info->s = cpuintrf_temp_str(), "C: %.8x %.8x", saturn.reg[C].d[1], saturn.reg[C].d[0]);break;
397      case CPUINFO_STR_REGISTER + SATURN_D:      sprintf(info->s = cpuintrf_temp_str(), "D: %.8x %.8x", saturn.reg[D].d[1], saturn.reg[D].d[0]);break;
398      case CPUINFO_STR_REGISTER + SATURN_R0:      sprintf(info->s = cpuintrf_temp_str(), "R0:%.8x %.8x", saturn.reg[R0].d[1], saturn.reg[R0].d[0]);break;
399      case CPUINFO_STR_REGISTER + SATURN_R1:      sprintf(info->s = cpuintrf_temp_str(), "R1:%.8x %.8x", saturn.reg[R1].d[1], saturn.reg[R1].d[0]);break;
400      case CPUINFO_STR_REGISTER + SATURN_R2:      sprintf(info->s = cpuintrf_temp_str(), "R2:%.8x %.8x", saturn.reg[R2].d[1], saturn.reg[R2].d[0]);break;
401      case CPUINFO_STR_REGISTER + SATURN_R3:      sprintf(info->s = cpuintrf_temp_str(), "R3:%.8x %.8x", saturn.reg[R3].d[1], saturn.reg[R3].d[0]);break;
402      case CPUINFO_STR_REGISTER + SATURN_R4:      sprintf(info->s = cpuintrf_temp_str(), "R4:%.8x %.8x", saturn.reg[R4].d[1], saturn.reg[R4].d[0]);break;
388                  case CPUINFO_STR_REGISTER + SATURN_A:      sprintf(info->s = cpuintrf_temp_str(), "A: " Reg64Format, Reg64Data(saturn.reg[A]));break;
389                  case CPUINFO_STR_REGISTER + SATURN_B:      sprintf(info->s = cpuintrf_temp_str(), "B: " Reg64Format, Reg64Data(saturn.reg[B]));break;
390                  case CPUINFO_STR_REGISTER + SATURN_C:      sprintf(info->s = cpuintrf_temp_str(), "C: " Reg64Format, Reg64Data(saturn.reg[C]));break;
391                  case CPUINFO_STR_REGISTER + SATURN_D:      sprintf(info->s = cpuintrf_temp_str(), "D: " Reg64Format, Reg64Data(saturn.reg[D]));break;
392                  case CPUINFO_STR_REGISTER + SATURN_R0:      sprintf(info->s = cpuintrf_temp_str(), "R0: " Reg64Format, Reg64Data(saturn.reg[R0]));break;
393                  case CPUINFO_STR_REGISTER + SATURN_R1:      sprintf(info->s = cpuintrf_temp_str(), "R1: " Reg64Format, Reg64Data(saturn.reg[R1]));break;
394                  case CPUINFO_STR_REGISTER + SATURN_R2:      sprintf(info->s = cpuintrf_temp_str(), "R2: " Reg64Format, Reg64Data(saturn.reg[R2]));break;
395                  case CPUINFO_STR_REGISTER + SATURN_R3:      sprintf(info->s = cpuintrf_temp_str(), "R3: " Reg64Format, Reg64Data(saturn.reg[R3]));break;
396                  case CPUINFO_STR_REGISTER + SATURN_R4:      sprintf(info->s = cpuintrf_temp_str(), "R4: " Reg64Format, Reg64Data(saturn.reg[R4]));break;
403397      case CPUINFO_STR_REGISTER + SATURN_P:      sprintf(info->s = cpuintrf_temp_str(), "P:%x", saturn.p);break;
404      case CPUINFO_STR_REGISTER + SATURN_IN:      sprintf(info->s = cpuintrf_temp_str(), "IN:%.4x", saturn.in);break;
405398      case CPUINFO_STR_REGISTER + SATURN_OUT:      sprintf(info->s = cpuintrf_temp_str(), "OUT:%.3x", saturn.out);break;
406399      case CPUINFO_STR_REGISTER + SATURN_CARRY:   sprintf(info->s = cpuintrf_temp_str(), "Carry: %d", saturn.carry);break;
407400      case CPUINFO_STR_REGISTER + SATURN_ST:      sprintf(info->s = cpuintrf_temp_str(), "ST:%.4x", saturn.st);break;
r2724r2725
414407      case CPUINFO_STR_REGISTER + SATURN_RSTK5:   sprintf(info->s = cpuintrf_temp_str(), "RSTK5:%.5x", saturn.rstk[5]);break;
415408      case CPUINFO_STR_REGISTER + SATURN_RSTK6:   sprintf(info->s = cpuintrf_temp_str(), "RSTK6:%.5x", saturn.rstk[6]);break;
416409      case CPUINFO_STR_REGISTER + SATURN_RSTK7:   sprintf(info->s = cpuintrf_temp_str(), "RSTK7:%.5x", saturn.rstk[7]);break;
417      case CPUINFO_STR_REGISTER + SATURN_IRQ_STATE:   sprintf(info->s = cpuintrf_temp_str(), "IRQ:%.4x", saturn.pending_irq);break;
418      case CPUINFO_STR_FLAGS:                  sprintf(info->s = cpuintrf_temp_str(), "%c%c", saturn.decimal?'D':'.', saturn.carry ? 'C':'.'); break;
410            case CPUINFO_STR_REGISTER + SATURN_IRQ_STATE:   sprintf(info->s = cpuintrf_temp_str(), "IRQ:%c%c%c%i", saturn.in_irq?'S':'.', saturn.irq_enable?'e':'.', saturn.pending_irq?'p':'.', saturn.irq_state); break;
411            case CPUINFO_STR_FLAGS:            sprintf(info->s = cpuintrf_temp_str(), "%c%c", saturn.decimal?'D':'.', saturn.carry ? 'C':'.'); break;
412            case CPUINFO_STR_REGISTER + SATURN_SLEEPING:   sprintf(info->s = cpuintrf_temp_str(), "sleep:%c", saturn.sleeping?'S':'.'); break;
419413   }
420414}
src/emu/config.h
r2724r2725
4343 *
4444 *************************************/
4545
46typedef void (*config_callback_func)(int config_type, xml_data_node *parentnode);
46typedef void (*config_callback_func)(running_machine *machine, int config_type, xml_data_node *parentnode);
4747
4848
4949
r2724r2725
5454 *************************************/
5555
5656void config_init(running_machine *machine);
57void config_register(const char *nodename, config_callback_func load, config_callback_func save);
57void config_register(running_machine *machine, const char *nodename, config_callback_func load, config_callback_func save);
5858int config_load_settings(running_machine *machine);
5959void config_save_settings(running_machine *machine);
6060
src/emu/uigfx.c
r2724r2725
7878static void ui_gfx_exit(running_machine *machine);
7979
8080/* palette handling */
81static void palette_handle_keys(ui_gfx_state *state);
82static void palette_handler(ui_gfx_state *state);
81static void palette_handle_keys(running_machine *machine, ui_gfx_state *state);
82static void palette_handler(running_machine *machine, ui_gfx_state *state);
8383
8484/* graphics set handling */
85static void gfxset_handle_keys(ui_gfx_state *state, int xcells, int ycells);
85static void gfxset_handle_keys(running_machine *machine, ui_gfx_state *state, int xcells, int ycells);
8686static void gfxset_draw_item(const gfx_element *gfx, int index, bitmap_t *bitmap, int dstx, int dsty, int color, int rotate);
8787static void gfxset_update_bitmap(ui_gfx_state *state, int xcells, int ycells, gfx_element *gfx);
88static void gfxset_handler(ui_gfx_state *state);
88static void gfxset_handler(running_machine *machine, ui_gfx_state *state);
8989
9090/* tilemap handling */
91static void tilemap_handle_keys(ui_gfx_state *state, int viswidth, int visheight);
91static void tilemap_handle_keys(running_machine *machine, ui_gfx_state *state, int viswidth, int visheight);
9292static void tilemap_update_bitmap(ui_gfx_state *state, int width, int height);
93static void tilemap_handler(ui_gfx_state *state);
93static void tilemap_handler(running_machine *machine, ui_gfx_state *state);
9494
9595
9696
r2724r2725
170170         /* if we have a palette, display it */
171171         if (machine->config->total_colors > 0)
172172         {
173            palette_handler(state);
173            palette_handler(machine, state);
174174            break;
175175         }
176176
r2724r2725
181181         /* if we have graphics sets, display them */
182182         if (machine->gfx[0] != NULL)
183183         {
184            gfxset_handler(state);
184            gfxset_handler(machine, state);
185185            break;
186186         }
187187
r2724r2725
192192         /* if we have tilemaps, display them */
193193         if (tilemap_count() > 0)
194194         {
195            tilemap_handler(state);
195            tilemap_handler(machine, state);
196196            break;
197197         }
198198
r2724r2725
201201   }
202202
203203   /* handle keys */
204   if (input_ui_pressed(IPT_UI_SELECT))
204   if (input_ui_pressed(machine, IPT_UI_SELECT))
205205   {
206206      state->mode = (state->mode + 1) % 3;
207207      state->bitmap_dirty = TRUE;
208208   }
209209
210   if (input_ui_pressed(IPT_UI_PAUSE))
210   if (input_ui_pressed(machine, IPT_UI_PAUSE))
211211      mame_pause(machine, !mame_is_paused(machine));
212212
213   if (input_ui_pressed(IPT_UI_CANCEL) || input_ui_pressed(IPT_UI_SHOW_GFX))
213   if (input_ui_pressed(machine, IPT_UI_CANCEL) || input_ui_pressed(machine, IPT_UI_SHOW_GFX))
214214      goto cancel;
215215
216216   return uistate;
r2724r2725
233233    viewer
234234-------------------------------------------------*/
235235
236static void palette_handler(ui_gfx_state *state)
236static void palette_handler(running_machine *machine, ui_gfx_state *state)
237237{
238238   int total = state->palette.which ? colortable_palette_get_size(Machine->colortable) : Machine->config->total_colors;
239239   const char *title = state->palette.which ? "COLORTABLE" : "PALETTE";
r2724r2725
344344      }
345345
346346   /* handle keys */
347   palette_handle_keys(state);
347   palette_handle_keys(machine, state);
348348}
349349
350350
r2724r2725
353353    palette viewer
354354-------------------------------------------------*/
355355
356static void palette_handle_keys(ui_gfx_state *state)
356static void palette_handle_keys(running_machine *machine, ui_gfx_state *state)
357357{
358358   int rowcount, screencount;
359359   int total;
360360
361361   /* handle zoom (minus,plus) */
362   if (input_ui_pressed(IPT_UI_ZOOM_OUT))
362   if (input_ui_pressed(machine, IPT_UI_ZOOM_OUT))
363363      state->palette.count /= 2;
364   if (input_ui_pressed(IPT_UI_ZOOM_IN))
364   if (input_ui_pressed(machine, IPT_UI_ZOOM_IN))
365365      state->palette.count *= 2;
366366
367367   /* clamp within range */
r2724r2725
371371      state->palette.count = 64;
372372
373373   /* handle colormap selection (open bracket,close bracket) */
374   if (input_ui_pressed(IPT_UI_PREV_GROUP))
374   if (input_ui_pressed(machine, IPT_UI_PREV_GROUP))
375375      state->palette.which--;
376   if (input_ui_pressed(IPT_UI_NEXT_GROUP))
376   if (input_ui_pressed(machine, IPT_UI_NEXT_GROUP))
377377      state->palette.which++;
378378
379379   /* clamp within range */
r2724r2725
390390   screencount = rowcount * rowcount;
391391
392392   /* handle keyboard navigation */
393   if (input_ui_pressed_repeat(IPT_UI_UP, 4))
393   if (input_ui_pressed_repeat(machine, IPT_UI_UP, 4))
394394      state->palette.offset -= rowcount;
395   if (input_ui_pressed_repeat(IPT_UI_DOWN, 4))
395   if (input_ui_pressed_repeat(machine, IPT_UI_DOWN, 4))
396396      state->palette.offset += rowcount;
397   if (input_ui_pressed_repeat(IPT_UI_PAGE_UP, 6))
397   if (input_ui_pressed_repeat(machine, IPT_UI_PAGE_UP, 6))
398398      state->palette.offset -= screencount;
399   if (input_ui_pressed_repeat(IPT_UI_PAGE_DOWN, 6))
399   if (input_ui_pressed_repeat(machine, IPT_UI_PAGE_DOWN, 6))
400400      state->palette.offset += screencount;
401   if (input_ui_pressed_repeat(IPT_UI_HOME, 4))
401   if (input_ui_pressed_repeat(machine, IPT_UI_HOME, 4))
402402      state->palette.offset = 0;
403   if (input_ui_pressed_repeat(IPT_UI_END, 4))
403   if (input_ui_pressed_repeat(machine, IPT_UI_END, 4))
404404      state->palette.offset = total;
405405
406406   /* clamp within range */
r2724r2725
421421    viewer
422422-------------------------------------------------*/
423423
424static void gfxset_handler(ui_gfx_state *state)
424static void gfxset_handler(running_machine *machine, ui_gfx_state *state)
425425{
426426   render_font *ui_font = ui_get_font();
427427   int set = state->gfxset.set;
r2724r2725
578578                  ARGB_WHITE, state->texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
579579
580580   /* handle keyboard navigation before drawing */
581   gfxset_handle_keys(state, xcells, ycells);
581   gfxset_handle_keys(machine, state, xcells, ycells);
582582}
583583
584584
585585/*-------------------------------------------------
586    gfxset_handler - handle keys for the graphics
587    viewer
586    gfxset_handle_keys - handle keys for the
587    graphics viewer
588588-------------------------------------------------*/
589589
590static void gfxset_handle_keys(ui_gfx_state *state, int xcells, int ycells)
590static void gfxset_handle_keys(running_machine *machine, ui_gfx_state *state, int xcells, int ycells)
591591{
592592   ui_gfx_state oldstate = *state;
593593   gfx_element *gfx;
594594   int temp, set;
595595
596596   /* handle gfxset selection (open bracket,close bracket) */
597   if (input_ui_pressed(IPT_UI_PREV_GROUP))
597   if (input_ui_pressed(machine, IPT_UI_PREV_GROUP))
598598   {
599599      for (temp = state->gfxset.set - 1; temp >= 0; temp--)
600600         if (Machine->gfx[temp] != NULL)
r2724r2725
602602      if (temp >= 0)
603603         state->gfxset.set = temp;
604604   }
605   if (input_ui_pressed(IPT_UI_NEXT_GROUP))
605   if (input_ui_pressed(machine, IPT_UI_NEXT_GROUP))
606606   {
607607      for (temp = state->gfxset.set + 1; temp < MAX_GFX_ELEMENTS; temp++)
608608         if (Machine->gfx[temp] != NULL)
r2724r2725
616616   gfx = Machine->gfx[set];
617617
618618   /* handle cells per line (minus,plus) */
619   if (input_ui_pressed(IPT_UI_ZOOM_OUT))
619   if (input_ui_pressed(machine, IPT_UI_ZOOM_OUT))
620620      state->gfxset.count[set] = xcells - 1;
621   if (input_ui_pressed(IPT_UI_ZOOM_IN))
621   if (input_ui_pressed(machine, IPT_UI_ZOOM_IN))
622622      state->gfxset.count[set] = xcells + 1;
623623
624624   /* clamp within range */
r2724r2725
628628      state->gfxset.count[set] = 32;
629629
630630   /* handle rotation (R) */
631   if (input_ui_pressed(IPT_UI_ROTATE))
631   if (input_ui_pressed(machine, IPT_UI_ROTATE))
632632      state->gfxset.rotate[set] = orientation_add(ROT90, state->gfxset.rotate[set]);
633633
634634   /* handle navigation within the cells (up,down,pgup,pgdown) */
635   if (input_ui_pressed_repeat(IPT_UI_UP, 4))
635   if (input_ui_pressed_repeat(machine, IPT_UI_UP, 4))
636636      state->gfxset.offset[set] -= xcells;
637   if (input_ui_pressed_repeat(IPT_UI_DOWN, 4))
637   if (input_ui_pressed_repeat(machine, IPT_UI_DOWN, 4))
638638      state->gfxset.offset[set] += xcells;
639   if (input_ui_pressed_repeat(IPT_UI_PAGE_UP, 6))
639   if (input_ui_pressed_repeat(machine, IPT_UI_PAGE_UP, 6))
640640      state->gfxset.offset[set] -= xcells * ycells;
641   if (input_ui_pressed_repeat(IPT_UI_PAGE_DOWN, 6))
641   if (input_ui_pressed_repeat(machine, IPT_UI_PAGE_DOWN, 6))
642642      state->gfxset.offset[set] += xcells * ycells;
643   if (input_ui_pressed_repeat(IPT_UI_HOME, 4))
643   if (input_ui_pressed_repeat(machine, IPT_UI_HOME, 4))
644644      state->gfxset.offset[set] = 0;
645   if (input_ui_pressed_repeat(IPT_UI_END, 4))
645   if (input_ui_pressed_repeat(machine, IPT_UI_END, 4))
646646      state->gfxset.offset[set] = gfx->total_elements;
647647
648648   /* clamp within range */
r2724r2725
652652      state->gfxset.offset[set] = 0;
653653
654654   /* handle color selection (left,right) */
655   if (input_ui_pressed_repeat(IPT_UI_LEFT, 4))
655   if (input_ui_pressed_repeat(machine, IPT_UI_LEFT, 4))
656656      state->gfxset.color[set] -= 1;
657   if (input_ui_pressed_repeat(IPT_UI_RIGHT, 4))
657   if (input_ui_pressed_repeat(machine, IPT_UI_RIGHT, 4))
658658      state->gfxset.color[set] += 1;
659659
660660   /* clamp within range */
r2724r2725
838838    viewer
839839-------------------------------------------------*/
840840
841static void tilemap_handler(ui_gfx_state *state)
841static void tilemap_handler(running_machine *machine, ui_gfx_state *state)
842842{
843843   render_font *ui_font = ui_get_font();
844844   float chwidth, chheight;
r2724r2725
939939                  PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXORIENT(state->tilemap.rotate));
940940
941941   /* handle keyboard input */
942   tilemap_handle_keys(state, mapboxwidth, mapboxheight);
942   tilemap_handle_keys(machine, state, mapboxwidth, mapboxheight);
943943}
944944
945945
r2724r2725
948948    tilemap view
949949-------------------------------------------------*/
950950
951static void tilemap_handle_keys(ui_gfx_state *state, int viswidth, int visheight)
951static void tilemap_handle_keys(running_machine *machine, ui_gfx_state *state, int viswidth, int visheight)
952952{
953953   ui_gfx_state oldstate = *state;
954954   UINT32 mapwidth, mapheight;
955955   int step;
956956
957957   /* handle tilemap selection (open bracket,close bracket) */
958   if (input_ui_pressed(IPT_UI_PREV_GROUP))
958   if (input_ui_pressed(machine, IPT_UI_PREV_GROUP))
959959      state->tilemap.which--;
960   if (input_ui_pressed(IPT_UI_NEXT_GROUP))
960   if (input_ui_pressed(machine, IPT_UI_NEXT_GROUP))
961961      state->tilemap.which++;
962962
963963   /* clamp within range */
r2724r2725
970970   tilemap_size_by_index(state->tilemap.which, &mapwidth, &mapheight);
971971
972972   /* handle zoom (minus,plus) */
973   if (input_ui_pressed(IPT_UI_ZOOM_OUT))
973   if (input_ui_pressed(machine, IPT_UI_ZOOM_OUT))
974974      state->tilemap.zoom--;
975   if (input_ui_pressed(IPT_UI_ZOOM_IN))
975   if (input_ui_pressed(machine, IPT_UI_ZOOM_IN))
976976      state->tilemap.zoom++;
977977
978978   /* clamp within range */
r2724r2725
989989   }
990990
991991   /* handle rotation (R) */
992   if (input_ui_pressed(IPT_UI_ROTATE))
992   if (input_ui_pressed(machine, IPT_UI_ROTATE))
993993      state->tilemap.rotate = orientation_add(ROT90, state->tilemap.rotate);
994994
995995   /* handle navigation (up,down,left,right) */
996996   step = 8;
997997   if (input_code_pressed(KEYCODE_LSHIFT)) step = 1;
998998   if (input_code_pressed(KEYCODE_LCONTROL)) step = 64;
999   if (input_ui_pressed_repeat(IPT_UI_UP, 4))
999   if (input_ui_pressed_repeat(machine, IPT_UI_UP, 4))
10001000      state->tilemap.yoffs -= step;
1001   if (input_ui_pressed_repeat(IPT_UI_DOWN, 4))
1001   if (input_ui_pressed_repeat(machine, IPT_UI_DOWN, 4))
10021002      state->tilemap.yoffs += step;
1003   if (input_ui_pressed_repeat(IPT_UI_LEFT, 6))
1003   if (input_ui_pressed_repeat(machine, IPT_UI_LEFT, 6))
10041004      state->tilemap.xoffs -= step;
1005   if (input_ui_pressed_repeat(IPT_UI_RIGHT, 6))
1005   if (input_ui_pressed_repeat(machine, IPT_UI_RIGHT, 6))
10061006      state->tilemap.xoffs += step;
10071007
10081008   /* clamp within range */
src/emu/video/tms9928a.c
r2724r2725
108108static void draw_mode23 (running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect);
109109static void draw_modebogus (running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect);
110110static void draw_sprites (running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect);
111static void change_register (int reg, UINT8 data);
111static void change_register (running_machine *machine, int reg, UINT8 data);
112112
113113static void (*const ModeHandlers[])(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect) = {
114114        draw_mode0, draw_mode1, draw_mode2,  draw_mode12,
r2724r2725
138138    INT32 Addr;
139139    int colour,pattern,nametbl,spriteattribute,spritepattern;
140140    int colourmask,patternmask;
141    void (*INTCallback)(int);
141    void (*INTCallback)(running_machine *, int);
142142    /* memory */
143143    UINT8 *vMem, *dBackMem;
144144    bitmap_t *tmpbmp;
r2724r2725
235235}
236236
237237
238void TMS9928A_post_load (void) {
238void TMS9928A_post_load (running_machine *machine) {
239239   int i;
240240
241241   /* all registers need to be re-written, so tables are recalculated */
242242   for (i=0;i<8;i++)
243      change_register (i, tms.Regs[i]);
243      change_register (machine, i, tms.Regs[i]);
244244
245245   /* make sure the interrupt request is set properly */
246   if (tms.INTCallback) tms.INTCallback (tms.INT);
246   if (tms.INTCallback) tms.INTCallback (machine, tms.INT);
247247}
248248
249249
r2724r2725
273273    tms.StatusReg = 0x1f;
274274    if (tms.INT) {
275275        tms.INT = 0;
276        if (tms.INTCallback) tms.INTCallback (tms.INT);
276        if (tms.INTCallback) tms.INTCallback (machine, tms.INT);
277277    }
278278    tms.latch = 0;
279279    return b;
r2724r2725
287287            /* register write */
288288         reg = data & 7;
289289         /*if (tms.FirstByte != tms.Regs[reg])*/ /* Removed to fix ColecoVision MESS Driver*/
290               change_register (reg, tms.FirstByte);
290               change_register (machine, reg, tms.FirstByte);
291291        } else {
292292            /* set read/write address */
293293            tms.Addr = ((UINT16)data << 8 | tms.FirstByte) & (tms.vramsize - 1);
r2724r2725
303303    }
304304}
305305
306static void change_register (int reg, UINT8 val) {
306static void change_register (running_machine *machine, int reg, UINT8 val) {
307307    static const UINT8 Mask[8] =
308308        { 0x03, 0xfb, 0x0f, 0xff, 0x07, 0x7f, 0x07, 0xff };
309309    static const char *const modes[] = {
r2724r2725
337337        b = (val & 0x20) && (tms.StatusReg & 0x80) ;
338338        if (b != tms.INT) {
339339            tms.INT = b;
340            if (tms.INTCallback) tms.INTCallback (tms.INT);
340            if (tms.INTCallback) tms.INTCallback (machine, tms.INT);
341341        }
342342        logerror("TMS9928A: %s\n", modes[TMS_MODE]);
343343        break;
r2724r2725
423423   return 0;
424424}
425425
426int TMS9928A_interrupt () {
426int TMS9928A_interrupt(running_machine *machine) {
427427    int b;
428428
429429    /* when skipping frames, calculate sprite collision */
r2724r2725
437437    b = (tms.Regs[1] & 0x20) != 0;
438438    if (b != tms.INT) {
439439        tms.INT = b;
440        if (tms.INTCallback) tms.INTCallback (tms.INT);
440        if (tms.INTCallback) tms.INTCallback (machine, tms.INT);
441441    }
442442
443443    return b;
src/emu/video/v9938.c
r2724r2725
4040   int vram_size;
4141    /* interrupt */
4242    UINT8 INT;
43    void (*INTCallback)(int);
43    void (*INTCallback)(running_machine *, int);
4444   int scanline;
4545    /* blinking */
4646    int blink, blink_count;
r2724r2725
483483
484484***************************************************************************/
485485
486void v9938_init (running_machine *machine, int which, const device_config *screen, bitmap_t *bitmap, int model, int vram_size, void (*callback)(int) )
486void v9938_init (running_machine *machine, int which, const device_config *screen, bitmap_t *bitmap, int model, int vram_size, void (*callback)(running_machine *, int) )
487487{
488488   vdp = &vdps[which];
489489
r2724r2725
610610    ** called; because of this Mr. Ghost, Xevious and SD Snatcher don't
611611    ** run. As a patch it's called every scanline
612612    */
613   vdp->INTCallback (n);
613   vdp->INTCallback (Machine, n);
614614   }
615615
616616void v9938_set_sprite_limit (int which, int i)
src/emu/video/tms9928a.h
r2724r2725
2727   tms9928a_model model;      /* model: tms9929(a) runs at 50Hz instead of 60Hz */
2828   int vram;               /* VRAM size in bytes (4k, 8k or 16k) */
2929   int borderx, bordery;      /* number of border pixels to show in each direction */
30   void (*int_callback)(int);   /* callback which is called whenever the state
30   void (*int_callback)(running_machine *, int);   /* callback which is called whenever the state
3131                                ** of the INT output of the TMS9918A changes (may be NULL)*/
3232} TMS9928a_interface;
3333
r2724r2725
6464** This next function must be called 50 (tms9929a) or 60 (tms99x8a) times per second,
6565** to generate the necessary interrupts
6666*/
67int TMS9928A_interrupt (void);
67int TMS9928A_interrupt (running_machine *machine);
6868
6969/*
7070** The parameter is a function pointer. This function is called whenever
r2724r2725
8080/*
8181** After loading a state, call this function
8282*/
83void TMS9928A_post_load (void);
83void TMS9928A_post_load (running_machine *machine);
8484
8585/*
8686** MachineDriver video declarations for the TMS9928A chip
src/emu/video/voodoo.c
r2724r2725
199199static void check_stalled_cpu(running_machine *machine, voodoo_state *v, attotime current_time);
200200static void flush_fifos(voodoo_state *v, attotime current_time);
201201static TIMER_CALLBACK( stall_cpu_callback );
202static void stall_cpu(voodoo_state *v, int state, attotime current_time);
202static void stall_cpu(running_machine *machine, voodoo_state *v, int state, attotime current_time);
203203static TIMER_CALLBACK( vblank_callback );
204204static INT32 register_w(voodoo_state *v, offs_t offset, UINT32 data);
205205static INT32 lfb_w(voodoo_state *v, offs_t offset, UINT32 data, UINT32 mem_mask, int forcefront);
206206static INT32 texture_w(voodoo_state *v, offs_t offset, UINT32 data);
207static void voodoo_w(voodoo_state *v, offs_t offset, UINT32 data, UINT32 mem_mask);
207static void voodoo_w(running_machine *machine, voodoo_state *v, offs_t offset, UINT32 data, UINT32 mem_mask);
208208static UINT32 voodoo_r(voodoo_state *v, offs_t offset);
209209static void banshee_w(voodoo_state *v, offs_t offset, UINT32 data, UINT32 mem_mask);
210210static UINT32 banshee_r(voodoo_state *v, offs_t offset, UINT32 mem_mask);
r2724r2725
626626}
627627
628628
629void voodoo_set_vblank_callback(int which, void (*vblank)(int))
629void voodoo_set_vblank_callback(int which, void (*vblank)(running_machine *, int))
630630{
631631   voodoo[which]->fbi.vblank_client = vblank;
632632}
633633
634634
635void voodoo_set_stall_callback(int which, void (*stall)(int))
635void voodoo_set_stall_callback(int which, void (*stall)(running_machine *, int))
636636{
637637   voodoo[which]->pci.stall_callback = stall;
638638}
r2724r2725
647647
648648WRITE32_HANDLER( voodoo_0_w )
649649{
650   voodoo_w(voodoo[0], offset, data, mem_mask);
650   voodoo_w(machine, voodoo[0], offset, data, mem_mask);
651651}
652652
653653
654654WRITE32_HANDLER( voodoo_1_w )
655655{
656   voodoo_w(voodoo[1], offset, data, mem_mask);
656   voodoo_w(machine, voodoo[1], offset, data, mem_mask);
657657}
658658
659659
r2724r2725
11091109   /* set internal state and call the client */
11101110   v->fbi.vblank = FALSE;
11111111   if (v->fbi.vblank_client)
1112      (*v->fbi.vblank_client)(FALSE);
1112      (*v->fbi.vblank_client)(machine, FALSE);
11131113
11141114   /* go to the end of the next frame */
11151115   adjust_vblank_timer(v);
r2724r2725
11491149   /* set internal state and call the client */
11501150   v->fbi.vblank = TRUE;
11511151   if (v->fbi.vblank_client)
1152      (*v->fbi.vblank_client)(TRUE);
1152      (*v->fbi.vblank_client)(machine, TRUE);
11531153}
11541154
11551155
r2724r2725
21942194
21952195      /* either call the callback, or trigger the trigger */
21962196      if (v->pci.stall_callback)
2197         (*v->pci.stall_callback)(FALSE);
2197         (*v->pci.stall_callback)(machine, FALSE);
21982198      else
21992199         cpu_trigger(machine, v->trigger);
22002200   }
r2724r2725
22072207}
22082208
22092209
2210static void stall_cpu(voodoo_state *v, int state, attotime current_time)
2210static void stall_cpu(running_machine *machine, voodoo_state *v, int state, attotime current_time)
22112211{
22122212   /* sanity check */
22132213   if (!v->pci.op_pending) fatalerror("FIFOs not empty, no op pending!");
r2724r2725
22182218
22192219   /* either call the callback, or spin the CPU */
22202220   if (v->pci.stall_callback)
2221      (*v->pci.stall_callback)(TRUE);
2221      (*v->pci.stall_callback)(machine, TRUE);
22222222   else
22232223      cpu_spinuntil_trigger(v->trigger);
22242224
r2724r2725
35833583 *
35843584 *************************************/
35853585
3586static void voodoo_w(voodoo_state *v, offs_t offset, UINT32 data, UINT32 mem_mask)
3586static void voodoo_w(running_machine *machine, voodoo_state *v, offs_t offset, UINT32 data, UINT32 mem_mask)
35873587{
35883588   int stall = FALSE;
35893589
r2724r2725
37283728         fifo_items(&v->fbi.fifo) >= 2 * 32 * FBIINIT0_MEMORY_FIFO_HWM(v->reg[fbiInit0].u))
37293729      {
37303730         if (LOG_FIFO) logerror("VOODOO.%d.FIFO:voodoo_w hit memory FIFO HWM -- stalling\n", v->index);
3731         stall_cpu(v, STALLED_UNTIL_FIFO_LWM, timer_get_time());
3731         stall_cpu(machine, v, STALLED_UNTIL_FIFO_LWM, timer_get_time());
37323732      }
37333733   }
37343734
r2724r2725
37373737      fifo_space(&v->pci.fifo) <= 2 * FBIINIT0_PCI_FIFO_LWM(v->reg[fbiInit0].u))
37383738   {
37393739      if (LOG_FIFO) logerror("VOODOO.%d.FIFO:voodoo_w hit PCI FIFO free LWM -- stalling\n", v->index);
3740      stall_cpu(v, STALLED_UNTIL_FIFO_LWM, timer_get_time());
3740      stall_cpu(machine, v, STALLED_UNTIL_FIFO_LWM, timer_get_time());
37413741   }
37423742
37433743   /* if we weren't ready, and this is a non-FIFO access, stall until the FIFOs are clear */
37443744   if (stall)
37453745   {
37463746      if (LOG_FIFO_VERBOSE) logerror("VOODOO.%d.FIFO:voodoo_w wrote non-FIFO register -- stalling until clear\n", v->index);
3747      stall_cpu(v, STALLED_UNTIL_FIFO_EMPTY, timer_get_time());
3747      stall_cpu(machine, v, STALLED_UNTIL_FIFO_EMPTY, timer_get_time());
37483748   }
37493749
37503750   profiler_mark(PROFILER_END);
src/emu/video/v9938.h
r2724r2725
1414#define RENDER_LOW   (1)
1515#define RENDER_AUTO   (2)
1616
17void v9938_init (running_machine *machine, int which, const device_config *screen, bitmap_t *bitmap, int model, int vram_size, void (*callback)(int) );
17void v9938_init (running_machine *machine, int which, const device_config *screen, bitmap_t *bitmap, int model, int vram_size, void (*callback)(running_machine *, int) );
1818void v9938_reset (int which);
1919int v9938_interrupt (int which);
2020void v9938_set_sprite_limit (int which, int);
src/emu/video/voodoo.h
r2724r2725
2525int voodoo_get_type(int which);
2626int voodoo_is_stalled(int which);
2727void voodoo_set_init_enable(int which, UINT32 newval);
28void voodoo_set_vblank_callback(int which, void (*vblank)(int));
29void voodoo_set_stall_callback(int which, void (*stall)(int));
28void voodoo_set_vblank_callback(int which, void (*vblank)(running_machine *, int));
29void voodoo_set_stall_callback(int which, void (*stall)(running_machine *, int));
3030
3131READ32_HANDLER( voodoo_0_r );
3232WRITE32_HANDLER( voodoo_0_w );
src/emu/video/vooddefs.h
r2724r2725
14321432   fifo_state   fifo;               /* PCI FIFO */
14331433   UINT32      init_enable;         /* initEnable value */
14341434   UINT8      stall_state;         /* state of the system if we're stalled */
1435   void      (*stall_callback)(int); /* callback for stalling/unstalling */
1435   void      (*stall_callback)(running_machine *, int); /* callback for stalling/unstalling */
14361436   UINT8      op_pending;            /* true if an operation is pending */
14371437   attotime   op_end_time;         /* time when the pending operation ends */
14381438   emu_timer *continue_timer;         /* timer to use to continue processing */
r2724r2725
15551555   UINT8      vblank_swap_pending;   /* a swap is pending, waiting for a vblank */
15561556   UINT8      vblank_swap;         /* swap when we hit this count */
15571557   UINT8      vblank_dont_swap;      /* don't actually swap when we hit this point */
1558   void      (*vblank_client)(int);   /* client callback */
1558   void      (*vblank_client)(running_machine *, int);   /* client callback */
15591559
15601560   /* triangle setup info */
15611561   UINT8      cheating_allowed;      /* allow cheating? */
src/emu/info.c
r2724r2725
3636    settings for a game
3737-------------------------------------------------*/
3838
39static void print_game_switches(FILE *out, const game_driver *game, const input_port_entry *input)
39static void print_game_switches(FILE *out, const game_driver *game, const input_port_config *portlist)
4040{
41   /* iterate over input entries until we run out */
42   while (input->type != IPT_END)
43   {
44      /* once we hit a name entry, start outputting */
45      if (input->type == IPT_DIPSWITCH_NAME)
46      {
47         int def = input->default_value;
41   const input_port_config *port;
42   const input_field_config *field;
4843
49         /* output the switch name information */
50         fprintf(out, "\t\t<dipswitch name=\"%s\">\n", xml_normalize_string(input->name));
51
52         /* loop over settings */
53         for (input++; input->type == IPT_DIPSWITCH_SETTING; input++)
44   /* iterate looking for DIP switches */
45   for (port = portlist; port != NULL; port = port->next)
46      for (field = port->fieldlist; field != NULL; field = field->next)
47         if (field->type == IPT_DIPSWITCH)
5448         {
55            fprintf(out, "\t\t\t<dipvalue name=\"%s\"", xml_normalize_string(input->name));
56            if (def == input->default_value)
57               fprintf(out, " default=\"yes\"");
58            fprintf(out, "/>\n");
59         }
49            const input_setting_config *setting;
6050
61         /* terminate the switch entry */
62         fprintf(out, "\t\t</dipswitch>\n");
63      }
64      else
65         ++input;
66   }
51            /* output the switch name information */
52            fprintf(out, "\t\t<dipswitch name=\"%s\">\n", xml_normalize_string(input_field_name(field)));
53
54            /* loop over settings */
55            for (setting = field->settinglist; setting != NULL; setting = setting->next)
56            {
57               fprintf(out, "\t\t\t<dipvalue name=\"%s\"", xml_normalize_string(setting->name));
58               if (setting->value == field->defvalue)
59                  fprintf(out, " default=\"yes\"");
60               fprintf(out, "/>\n");
61            }
62
63            /* terminate the switch entry */
64            fprintf(out, "\t\t</dipswitch>\n");
65         }
6766}
6867
6968
r2724r2725
7271    input
7372-------------------------------------------------*/
7473
75static void print_game_input(FILE *out, const game_driver *game, const input_port_entry *input)
74static void print_game_input(FILE *out, const game_driver *game, const input_port_config *portlist)
7675{
7776   /* fix me -- this needs to be cleaned up to match the core style */
7877
r2724r2725
9796      int            keydelta;      /* default analog keydelta */
9897      int            reverse;      /* default analog reverse setting */
9998   } control[ENDCONTROLTYPES];
99   const input_port_config *port;
100   const input_field_config *field;
100101
101102   for (i=0;i<ENDCONTROLTYPES;i++)
102103   {
r2724r2725
110111      control[i].reverse = 0;
111112   }
112113
113   while (input->type != IPT_END)
114   {
115      if (nplayer < input->player+1)
116         nplayer = input->player+1;
117
118      switch (input->type)
114   for (port = portlist; port != NULL; port = port->next)
115      for (field = port->fieldlist; field != NULL; field = field->next)
119116      {
120         case IPT_JOYSTICK_LEFT:
121         case IPT_JOYSTICK_RIGHT:
117         if (nplayer < field->player+1)
118            nplayer = field->player+1;
122119
123            /* if control not defined, start it off as horizontal 2-way */
124            if (control[cjoy].Xway == NULL)
125               control[cjoy].Xway = "joy2way";
126            else if (strcmp(control[cjoy].Xway,"joy2way") == 0)
127               ;
128            /* if already defined as vertical, make it 4 or 8 way */
129            else if (strcmp(control[cjoy].Xway,"vjoy2way") == 0)
130            {
131               if (input->way == 4)
132                  control[cjoy].Xway = "joy4way";
133               else
134                  control[cjoy].Xway = "joy8way";
135            }
136            controlsyes = 1;
137            break;
120         switch (field->type)
121         {
122            case IPT_JOYSTICK_LEFT:
123            case IPT_JOYSTICK_RIGHT:
138124
139         case IPT_JOYSTICK_UP:
140         case IPT_JOYSTICK_DOWN:
125               /* if control not defined, start it off as horizontal 2-way */
126               if (control[cjoy].Xway == NULL)
127                  control[cjoy].Xway = "joy2way";
128               else if (strcmp(control[cjoy].Xway,"joy2way") == 0)
129                  ;
130               /* if already defined as vertical, make it 4 or 8 way */
131               else if (strcmp(control[cjoy].Xway,"vjoy2way") == 0)
132               {
133                  if (field->way == 4)
134                     control[cjoy].Xway = "joy4way";
135                  else
136                     control[cjoy].Xway = "joy8way";
137               }
138               controlsyes = 1;
139               break;
141140
142            /* if control not defined, start it off as vertical 2-way */
143            if (control[cjoy].Xway == NULL)
144               control[cjoy].Xway = "vjoy2way";
145            else if (strcmp(control[cjoy].Xway,"vjoy2way") == 0)
146               ;
147            /* if already defined as horiz, make it 4 or 8way */
148            else if (strcmp(control[cjoy].Xway,"joy2way") == 0)
149            {
150               if (input->way == 4)
151                  control[cjoy].Xway = "joy4way";
152               else
153                  control[cjoy].Xway = "joy8way";
154            }
155            controlsyes = 1;
156            break;
141            case IPT_JOYSTICK_UP:
142            case IPT_JOYSTICK_DOWN:
157143
158         case IPT_JOYSTICKRIGHT_UP:
159         case IPT_JOYSTICKRIGHT_DOWN:
160         case IPT_JOYSTICKLEFT_UP:
161         case IPT_JOYSTICKLEFT_DOWN:
144               /* if control not defined, start it off as vertical 2-way */
145               if (control[cjoy].Xway == NULL)
146                  control[cjoy].Xway = "vjoy2way";
147               else if (strcmp(control[cjoy].Xway,"vjoy2way") == 0)
148                  ;
149               /* if already defined as horiz, make it 4 or 8way */
150               else if (strcmp(control[cjoy].Xway,"joy2way") == 0)
151               {
152                  if (field->way == 4)
153                     control[cjoy].Xway = "joy4way";
154                  else
155                     control[cjoy].Xway = "joy8way";
156               }
157               controlsyes = 1;
158               break;
162159
163            /* if control not defined, start it off as vertical 2way */
164            if (control[cdoublejoy].Xway == NULL)
165               control[cdoublejoy].Xway = "vdoublejoy2way";
166            else if (strcmp(control[cdoublejoy].Xway,"vdoublejoy2way") == 0)
167               ;
168            /* if already defined as horiz, make it 4 or 8 way */
169            else if (strcmp(control[cdoublejoy].Xway,"doublejoy2way") == 0)
170            {
171               if (input->way == 4)
172                  control[cdoublejoy].Xway = "doublejoy4way";
173               else
174                  control[cdoublejoy].Xway = "doublejoy8way";
175            }
176            controlsyes = 1;
177            break;
160            case IPT_JOYSTICKRIGHT_UP:
161            case IPT_JOYSTICKRIGHT_DOWN:
162            case IPT_JOYSTICKLEFT_UP:
163            case IPT_JOYSTICKLEFT_DOWN:
178164
179         case IPT_JOYSTICKRIGHT_LEFT:
180         case IPT_JOYSTICKRIGHT_RIGHT:
181         case IPT_JOYSTICKLEFT_LEFT:
182         case IPT_JOYSTICKLEFT_RIGHT:
165               /* if control not defined, start it off as vertical 2way */
166               if (control[cdoublejoy].Xway == NULL)
167                  control[cdoublejoy].Xway = "vdoublejoy2way";
168               else if (strcmp(control[cdoublejoy].Xway,"vdoublejoy2way") == 0)
169                  ;
170               /* if already defined as horiz, make it 4 or 8 way */
171               else if (strcmp(control[cdoublejoy].Xway,"doublejoy2way") == 0)
172               {
173                  if (field->way == 4)
174                     control[cdoublejoy].Xway = "doublejoy4way";
175                  else
176                     control[cdoublejoy].Xway = "doublejoy8way";
177               }
178               controlsyes = 1;
179               break;
183180
184            /* if control not defined, start it off as horiz 2-way */
185            if (control[cdoublejoy].Xway == NULL)
186               control[cdoublejoy].Xway = "doublejoy2way";
187            else if (strcmp(control[cdoublejoy].Xway,"doublejoy2way") == 0)
188               ;
189            /* if already defined as vertical, make it 4 or 8 way */
190            else if (strcmp(control[cdoublejoy].Xway,"vdoublejoy2way") == 0)
191            {
192               if (input->way == 4)
193                  control[cdoublejoy].Xway = "doublejoy4way";
194               else
195                  control[cdoublejoy].Xway = "doublejoy8way";
196            }
197            controlsyes = 1;
198            break;
181            case IPT_JOYSTICKRIGHT_LEFT:
182            case IPT_JOYSTICKRIGHT_RIGHT:
183            case IPT_JOYSTICKLEFT_LEFT:
184            case IPT_JOYSTICKLEFT_RIGHT:
199185
200         /* mark as an analog input, and get analog stats after switch */
201         case IPT_PADDLE:
202            analogcontrol = cpaddle;
203            break;
204         case IPT_DIAL:
205            analogcontrol = cdial;
206            break;
207         case IPT_TRACKBALL_X:
208         case IPT_TRACKBALL_Y:
209            analogcontrol = ctrackball;
210            break;
211         case IPT_AD_STICK_X:
212         case IPT_AD_STICK_Y:
213            analogcontrol = cAD_stick;
214            break;
215         case IPT_LIGHTGUN_X:
216         case IPT_LIGHTGUN_Y:
217            analogcontrol = clightgun;
218            break;
219         case IPT_PEDAL:
220         case IPT_PEDAL2:
221         case IPT_PEDAL3:
222            analogcontrol = cpedal;
223            break;
186               /* if control not defined, start it off as horiz 2-way */
187               if (control[cdoublejoy].Xway == NULL)
188                  control[cdoublejoy].Xway = "doublejoy2way";
189               else if (strcmp(control[cdoublejoy].Xway,"doublejoy2way") == 0)
190                  ;
191               /* if already defined as vertical, make it 4 or 8 way */
192               else if (strcmp(control[cdoublejoy].Xway,"vdoublejoy2way") == 0)
193               {
194                  if (field->way == 4)
195                     control[cdoublejoy].Xway = "doublejoy4way";
196                  else
197                     control[cdoublejoy].Xway = "doublejoy8way";
198               }
199               controlsyes = 1;
200               break;
224201
225         case IPT_BUTTON1:
226            if (nbutton<1) nbutton = 1;
227            break;
228         case IPT_BUTTON2:
229            if (nbutton<2) nbutton = 2;
230            break;
231         case IPT_BUTTON3:
232            if (nbutton<3) nbutton = 3;
233            break;
234         case IPT_BUTTON4:
235            if (nbutton<4) nbutton = 4;
236            break;
237         case IPT_BUTTON5:
238            if (nbutton<5) nbutton = 5;
239            break;
240         case IPT_BUTTON6:
241            if (nbutton<6) nbutton = 6;
242            break;
243         case IPT_BUTTON7:
244            if (nbutton<7) nbutton = 7;
245            break;
246         case IPT_BUTTON8:
247            if (nbutton<8) nbutton = 8;
248            break;
249         case IPT_BUTTON9:
250            if (nbutton<9) nbutton = 9;
251            break;
252         case IPT_BUTTON10:
253            if (nbutton<10) nbutton = 10;
254            break;
202            /* mark as an analog input, and get analog stats after switch */
203            case IPT_PADDLE:
204               analogcontrol = cpaddle;
205               break;
206            case IPT_DIAL:
207               analogcontrol = cdial;
208               break;
209            case IPT_TRACKBALL_X:
210            case IPT_TRACKBALL_Y:
211               analogcontrol = ctrackball;
212               break;
213            case IPT_AD_STICK_X:
214            case IPT_AD_STICK_Y:
215               analogcontrol = cAD_stick;
216               break;
217            case IPT_LIGHTGUN_X:
218            case IPT_LIGHTGUN_Y:
219               analogcontrol = clightgun;
220               break;
221            case IPT_PEDAL:
222            case IPT_PEDAL2:
223            case IPT_PEDAL3:
224               analogcontrol = cpedal;
225               break;
255226
256         case IPT_COIN1:
257            if (ncoin < 1) ncoin = 1;
258            break;
259         case IPT_COIN2:
260            if (ncoin < 2) ncoin = 2;
261            break;
262         case IPT_COIN3:
263            if (ncoin < 3) ncoin = 3;
264            break;
265         case IPT_COIN4:
266            if (ncoin < 4) ncoin = 4;
267            break;
268         case IPT_COIN5:
269            if (ncoin < 5) ncoin = 5;
270            break;
271         case IPT_COIN6:
272            if (ncoin < 6) ncoin = 6;
273            break;
274         case IPT_COIN7:
275            if (ncoin < 7) ncoin = 7;
276            break;
277         case IPT_COIN8:
278            if (ncoin < 8) ncoin = 8;
279            break;
280         case IPT_SERVICE :
281            service = "yes";
282            break;
283         case IPT_TILT :
284            tilt = "yes";
285            break;
286      }
227            case IPT_BUTTON1:
228            case IPT_BUTTON2:
229            case IPT_BUTTON3:
230            case IPT_BUTTON4:
231            case IPT_BUTTON5:
232            case IPT_BUTTON6:
233            case IPT_BUTTON7:
234            case IPT_BUTTON8:
235            case IPT_BUTTON9:
236            case IPT_BUTTON10:
237            case IPT_BUTTON11:
238            case IPT_BUTTON12:
239            case IPT_BUTTON13:
240            case IPT_BUTTON14:
241            case IPT_BUTTON15:
242            case IPT_BUTTON16:
243               nbutton = MAX(nbutton, field->type - IPT_BUTTON1 + 1);
244               break;
287245
288      /* get the analog stats */
289      if (analogcontrol)
290      {
291         controlsyes = 1;
292         control[analogcontrol].analog = 1;
246            case IPT_COIN1:
247            case IPT_COIN2:
248            case IPT_COIN3:
249            case IPT_COIN4:
250            case IPT_COIN5:
251            case IPT_COIN6:
252            case IPT_COIN7:
253            case IPT_COIN8:
254               ncoin = MAX(ncoin, field->type - IPT_COIN1 + 1);
293255
294         if (input->analog.min)
295            control[analogcontrol].min = input->analog.min;
296         if (input->analog.max)
297            control[analogcontrol].max = input->analog.max;
298         if (input->analog.sensitivity)
299            control[analogcontrol].sensitivity = input->analog.sensitivity;
300         if (input->analog.delta)
301            control[analogcontrol].keydelta = input->analog.delta;
302         if (input->analog.reverse)
303            control[analogcontrol].reverse = 1;
256            case IPT_SERVICE :
257               service = "yes";
258               break;
304259
305         analogcontrol = 0;
306      }
260            case IPT_TILT :
261               tilt = "yes";
262               break;
263         }
307264
308      ++input;
309   }
265         /* get the analog stats */
266         if (analogcontrol)
267         {
268            controlsyes = 1;
269            control[analogcontrol].analog = 1;
310270
271            if (field->min)
272               control[analogcontrol].min = field->min;
273            if (field->max)
274               control[analogcontrol].max = field->max;
275            if (field->sensitivity)
276               control[analogcontrol].sensitivity = field->sensitivity;
277            if (field->delta)
278               control[analogcontrol].keydelta = field->delta;
279            if (field->flags & ANALOG_FLAG_REVERSE)
280               control[analogcontrol].reverse = 1;
281
282            analogcontrol = 0;
283         }
284      }
285
311286   fprintf(out, "\t\t<input");
312287   fprintf(out, " players=\"%d\"", nplayer);
313288   if (nbutton != 0)
r2724r2725
856831
857832static void print_game_info(FILE *out, const game_driver *game)
858833{
859   const input_port_entry *input;
834   const input_port_config *portconfig;
860835   const game_driver *clone_of;
861836   machine_config *config;
862837   const char *start;
r2724r2725
866841      return;
867842
868843   /* start tracking resources and allocate the machine and input configs */
869   begin_resource_tracking();
870844   config = machine_config_alloc(game->machine_config);
871845#ifdef MESS
872846   /* temporary hook until MESS device transition is complete */
873847   mess_devices_setup(config, game);
874848#endif /* MESS */
875   input = input_port_allocate(game->ipt, NULL);
849   portconfig = input_port_config_alloc(game->ipt);
876850
877851   /* print the header and the game name */
878852   fprintf(out, "\t<" XML_TOP);
r2724r2725
922896   print_game_chips(out, game, config);
923897   print_game_display(out, game, config);
924898   print_game_sound(out, game, config);
925   print_game_input(out, game, input);
926   print_game_switches(out, game, input);
899   print_game_input(out, game, portconfig);
900   print_game_switches(out, game, portconfig);
927901   print_game_driver(out, game, config);
928902#ifdef MESS
929903   print_game_device(out, game, config);
r2724r2725
933907   /* close the topmost tag */
934908   fprintf(out, "\t</" XML_TOP ">\n");
935909
936   /* release resources */
937   end_resource_tracking();
910   input_port_config_free(portconfig);
938911   machine_config_free(config);
939912}
940913
src/emu/emuopts.c
r2724r2725
119119   { NULL,                          NULL,        OPTION_HEADER,     "CORE INPUT OPTIONS" },
120120   { "ctrlr",                       NULL,        0,                 "preconfigure for specified controller" },
121121   { "mouse",                       "0",         OPTION_BOOLEAN,    "enable mouse input" },
122   { "joystick;joy",                "0",         OPTION_BOOLEAN,    "enable joystick input" },
122   { "joystick;joy",                "1",         OPTION_BOOLEAN,    "enable joystick input" },
123123   { "lightgun;gun",                "0",         OPTION_BOOLEAN,    "enable lightgun input" },
124124   { "multikeyboard;multikey",      "0",         OPTION_BOOLEAN,    "enable separate input from each keyboard device (if present)" },
125125   { "multimouse",                  "0",         OPTION_BOOLEAN,    "enable separate input from each mouse device (if present)" },
src/emu/uimenu.c
r2724r2725
3939#define VISIBLE_GAMES_IN_LIST   15
4040
4141#define MAX_PHYSICAL_DIPS      10
42#define MAX_INPUT_PORTS         32
43#define MAX_BITS_PER_PORT      32
4244
4345/* DIP switch rendering parameters */
4446#define DIP_SWITCH_HEIGHT      0.05f
r2724r2725
8486typedef struct _input_item_data input_item_data;
8587struct _input_item_data
8688{
87   input_seq *      seq;            /* pointer to the sequence we are operating on */
88   const input_seq *defseq;         /* pointer to the sequence we are operating on */
89   const input_type_desc *typedesc;      /* reference to type description for global inputs */
90   const input_field_config *field;      /* reference to field for game inputs */
91   int            seqtype;            /* sequence type */
92   input_seq      seq;               /* copy of the live sequence */
93   const input_seq *defseq;            /* pointer to the default sequence */
8994   const char *   name;
9095   const char *   seqname;
91   UINT16          sortorder;         /* sorting information */
92   UINT8          type;            /* type of port */
93   UINT8          invert;            /* type of port */
96   UINT16          sortorder;            /* sorting information */
97   UINT8          type;               /* type of port */
98   UINT8          invert;               /* type of port */
9499};
95100
96101
r2724r2725
152157static void ui_menu_exit(running_machine *machine);
153158
154159/* menu handlers */
155static UINT32 menu_main(UINT32 state);
156static UINT32 menu_input_groups(UINT32 state);
157static UINT32 menu_input(UINT32 state);
158static UINT32 menu_switches(UINT32 state);
159static UINT32 menu_analog(UINT32 state);
160static UINT32 menu_main(running_machine *machine, UINT32 state);
161static UINT32 menu_input_groups(running_machine *machine, UINT32 state);
162static UINT32 menu_input(running_machine *machine, UINT32 state);
163static UINT32 menu_switches(running_machine *machine, UINT32 state);
164static UINT32 menu_analog(running_machine *machine, UINT32 state);
160165#ifndef MESS
161static UINT32 menu_bookkeeping(UINT32 state);
166static UINT32 menu_bookkeeping(running_machine *machine, UINT32 state);
162167#endif
163static UINT32 menu_game_info(UINT32 state);
164static UINT32 menu_cheat(UINT32 state);
165static UINT32 menu_memory_card(UINT32 state);
166static UINT32 menu_video(UINT32 state);
167static UINT32 menu_quit_game(UINT32 state);
168static UINT32 menu_select_game(UINT32 state);
168static UINT32 menu_game_info(running_machine *machine, UINT32 state);
169static UINT32 menu_cheat(running_machine *machine, UINT32 state);
170static UINT32 menu_memory_card(running_machine *machine, UINT32 state);
171static UINT32 menu_video(running_machine *machine, UINT32 state);
172static UINT32 menu_quit_game(running_machine *machine, UINT32 state);
173static UINT32 menu_select_game(running_machine *machine, UINT32 state);
169174#ifdef MESS
170static UINT32 menu_file_manager(UINT32 state);
175static UINT32 menu_file_manager(running_machine *machine, UINT32 state);
171176#if HAS_WAVE
172static UINT32 menu_tape_control(UINT32 state);
177static UINT32 menu_tape_control(running_machine *machine, UINT32 state);
173178#endif /* HAS_WAVE */
174179#endif /* MESS */
175180
176181/* menu helpers */
177182static void menu_render_triangle(bitmap_t *dest, const bitmap_t *source, const rectangle *sbounds, void *param);
178183
179static int input_menu_get_items(input_item_data *itemlist, int group);
180static int input_menu_get_game_items(input_item_data *itemlist);
184static int input_menu_get_items(running_machine *machine, input_item_data *itemlist, int group);
185static int input_menu_get_game_items(running_machine *machine, input_item_data *itemlist);
181186static void input_menu_toggle_none_default(input_seq *selected_seq, input_seq *original_seq, const input_seq *selected_defseq);
182187static int input_menu_compare_items(const void *i1, const void *i2);
183static void switches_menu_add_item(ui_menu_item *item, const input_port_entry *in, int switch_entry, void *ref);
184static void switches_menu_select_previous(input_port_entry *in, int switch_entry);
185static void switches_menu_select_next(input_port_entry *in, int switch_entry);
186//static int switches_menu_compare_items(const void *i1, const void *i2);
187static void analog_menu_add_item(ui_menu_item *item, const input_port_entry *in, const char *append_string, int which_item);
188static 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);
191static void analog_menu_add_item(ui_menu_item *item, const input_field_config *field, const char *append_string, int which_item);
188192
189193/* DIP switch helpers */
190static void dip_switch_build_model(input_port_entry *entry, int item_is_selected);
194static void dip_switch_build_model(const input_field_config *field, int item_is_selected);
191195static void dip_switch_draw_one(float dip_menu_x1, float dip_menu_y1, float dip_menu_x2, float dip_menu_y2, int model_index);
192196static void dip_switch_render(const menu_extra *extra, float x1, float y1, float x2, float y2);
193197
r2724r2725
531535    bottom
532536-------------------------------------------------*/
533537
534void ui_menu_draw_text_box(const char *text)
538static void ui_menu_draw_text_box(const char *text)
535539{
536540   const char *priortext = "Return to Prior Menu";
537541   float line_height = ui_get_line_height();
r2724r2725
591595    keys for a menu
592596-------------------------------------------------*/
593597
594int ui_menu_generic_keys(UINT32 *selected, int num_items, int visible_items)
598int ui_menu_generic_keys(running_machine *machine, UINT32 *selected, int num_items, int visible_items)
595599{
596600   /* hitting cancel or selecting the last item returns to the previous menu */
597   if (input_ui_pressed(IPT_UI_CANCEL) || (*selected == num_items - 1 && input_ui_pressed(IPT_UI_SELECT)))
601   if (input_ui_pressed(machine, IPT_UI_CANCEL) || (*selected == num_items - 1 && input_ui_pressed(machine, IPT_UI_SELECT)))
598602   {
599603      *selected = ui_menu_stack_pop();
600604      return 1;
601605   }
602606
603607   /* up backs up by one item */
604   if (input_ui_pressed_repeat(IPT_UI_UP, 6))
608   if (input_ui_pressed_repeat(machine, IPT_UI_UP, 6))
605609      *selected = (*selected + num_items - 1) % num_items;
606610
607611   /* down advances by one item */
608   if (input_ui_pressed_repeat(IPT_UI_DOWN, 6))
612   if (input_ui_pressed_repeat(machine, IPT_UI_DOWN, 6))
609613      *selected = (*selected + 1) % num_items;
610614
611615   /* page up backs up by visible_items */
612   if (input_ui_pressed_repeat(IPT_UI_PAGE_UP, 6))
616   if (input_ui_pressed_repeat(machine, IPT_UI_PAGE_UP, 6))
613617   {
614618      if (*selected >= visible_items - 1)
615619         *selected -= visible_items - 1;
r2724r2725
618622   }
619623
620624   /* page down advances by visible_items */
621   if (input_ui_pressed_repeat(IPT_UI_PAGE_DOWN, 6))
625   if (input_ui_pressed_repeat(machine, IPT_UI_PAGE_DOWN, 6))
622626   {
623627      *selected += visible_items - 1;
624628      if (*selected >= num_items)
r2724r2725
626630   }
627631
628632   /* home goes to the start */
629   if (input_ui_pressed(IPT_UI_HOME))
633   if (input_ui_pressed(machine, IPT_UI_HOME))
630634      *selected = 0;
631635
632636   /* end goes to the last */
633   if (input_ui_pressed(IPT_UI_END))
637   if (input_ui_pressed(machine, IPT_UI_END))
634638      *selected = num_items - 1;
635639
636640   /* pause enables/disables pause */
637   if (input_ui_pressed(IPT_UI_PAUSE))
641   if (input_ui_pressed(machine, IPT_UI_PAUSE))
638642      mame_pause(Machine, !mame_is_paused(Machine));
639643
640644   return 0;
r2724r2725
694698      ui_menu_stack_push(menu_main, 0);
695699
696700   /* update the menu state */
697   newstate = (*menu_stack[menu_stack_index].handler)(menu_stack[menu_stack_index].state);
701   newstate = (*menu_stack[menu_stack_index].handler)(machine, menu_stack[menu_stack_index].state);
698702   menu_stack[menu_stack_index].state = newstate;
699703
700704   /* if the menus are to be hidden, return a cancel here */
701   if ((input_ui_pressed(IPT_UI_CONFIGURE) && !ui_menu_is_force_game_select()) || menu_stack[menu_stack_index].handler == NULL)
705   if ((input_ui_pressed(machine, IPT_UI_CONFIGURE) && !ui_menu_is_force_game_select()) || menu_stack[menu_stack_index].handler == NULL)
702706      return UI_HANDLER_CANCEL;
703707
704708   return 0;
r2724r2725
752756    menu_main - main UI menu
753757-------------------------------------------------*/
754758
755static UINT32 menu_main(UINT32 state)
759static UINT32 menu_main(running_machine *machine, UINT32 state)
756760{
757761#define ADD_MENU(name, _handler, _param) \
758762do { \
r2724r2725
762766   menu_items++; \
763767} while (0)
764768
769   const input_port_config *port;
770   const input_field_config *field;
765771   menu_state handler_list[20];
766772   ui_menu_item item_list[20];
767773   int has_categories = FALSE;
768774   int has_configs = FALSE;
769775   int has_analog = FALSE;
770776   int has_dips = FALSE;
771   input_port_entry *in;
772777   int menu_items = 0;
773778   int visible_items;
774779
775780   /* scan the input port array to see what options we need to enable */
776   for (in = Machine->input_ports; in->type != IPT_END; in++)
777      if (input_port_active(in))
781   for (port = machine->portconfig; port != NULL; port = port->next)
782      for (field = port->fieldlist; field != NULL; field = field->next)
778783      {
779         if (in->type == IPT_DIPSWITCH_NAME)
784         if (field->type == IPT_DIPSWITCH)
780785            has_dips = TRUE;
781         if (port_type_is_analog(in->type))
782            has_analog = TRUE;
783         if (in->type == IPT_CONFIG_NAME)
786         if (field->type == IPT_CONFIG)
784787            has_configs = TRUE;
785         if (in->category > 0)
788         if (field->category > 0)
786789            has_categories = TRUE;
790         if (input_type_is_analog(field->type))
791            has_analog = TRUE;
787792      }
788793
789794   /* reset the menu */
r2724r2725
795800
796801   /* add optional input-related menus */
797802   if (has_dips)
798      ADD_MENU("Dip Switches", menu_switches, (IPT_DIPSWITCH_NAME << 16) | (IPT_DIPSWITCH_SETTING << 24));
803      ADD_MENU("Dip Switches", menu_switches, IPT_DIPSWITCH << 16);
799804   if (has_configs)
800      ADD_MENU("Driver Configuration", menu_switches, (IPT_CONFIG_NAME << 16) | (IPT_CONFIG_SETTING << 24));
805      ADD_MENU("Driver Configuration", menu_switches, IPT_CONFIG << 16);
801806#ifdef MESS
802807   if (has_categories)
803      ADD_MENU("Categories", menu_switches, (IPT_CATEGORY_NAME << 16) | (IPT_CATEGORY_SETTING << 24));
808      ADD_MENU("Categories", menu_switches, IPT_CATEGORY << 16);
804809#endif
805810   if (has_analog)
806811      ADD_MENU("Analog Controls", menu_analog, 0);
r2724r2725
822827
823828#if HAS_WAVE
824829     /* add tape control menu */
825   if (device_find_from_machine(Machine, IO_CASSETTE))
830   if (device_find_from_machine(machine, IO_CASSETTE))
826831      ADD_MENU("Tape Control", menu_tape_control, 1);
827832#endif /* HAS_WAVE */
828833#endif /* MESS */
r2724r2725
835840      ADD_MENU("Cheat", menu_cheat, 1);
836841
837842   /* add memory card menu */
838   if (Machine->config->memcard_handler != NULL)
843   if (machine->config->memcard_handler != NULL)
839844      ADD_MENU("Memory Card", menu_memory_card, 0);
840845
841846   /* add reset and exit menus */
r2724r2725
846851   visible_items = ui_menu_draw(item_list, menu_items, state, NULL);
847852
848853   /* handle the keys */
849   if (ui_menu_generic_keys(&state, menu_items, visible_items))
854   if (ui_menu_generic_keys(machine, &state, menu_items, visible_items))
850855      return state;
851   if (input_ui_pressed(IPT_UI_SELECT))
856   if (input_ui_pressed(machine, IPT_UI_SELECT))
852857      return ui_menu_stack_push(handler_list[state].handler, handler_list[state].state);
853858
854859   return state;
r2724r2725
862867    groups
863868-------------------------------------------------*/
864869
865static UINT32 menu_input_groups(UINT32 state)
870static UINT32 menu_input_groups(running_machine *machine, UINT32 state)
866871{
867872   ui_menu_item item_list[IPG_TOTAL_GROUPS + 2];
868873   int menu_items = 0;
r2724r2725
885890   visible_items = ui_menu_draw(item_list, menu_items, state, NULL);
886891
887892   /* handle the keys */
888   if (ui_menu_generic_keys(&state, menu_items, visible_items))
893   if (ui_menu_generic_keys(machine, &state, menu_items, visible_items))
889894      return state;
890   if (input_ui_pressed(IPT_UI_SELECT))
895   if (input_ui_pressed(machine, IPT_UI_SELECT))
891896      return ui_menu_stack_push(menu_input, state << 16);
892897
893898   return state;
r2724r2725
898903    menu_input - display a menu for inputs
899904-------------------------------------------------*/
900905
901static UINT32 menu_input(UINT32 state)
906static UINT32 menu_input(running_machine *machine, UINT32 state)
902907{
903908   ui_menu_item item_list[MAX_INPUT_PORTS * MAX_BITS_PER_PORT / 2];
904909   input_item_data item_data[MAX_INPUT_PORTS * MAX_BITS_PER_PORT / 2];
r2724r2725
907912   int record_next = (state >> 14) & 1;
908913   int polling = (state >> 15) & 1;
909914   int group = state >> 16;
915   int changed = FALSE;
910916   int visible_items;
911917   int menu_items;
912918   int item;
913919
914920   /* get the list of items */
915921   menu_string_pool_offset = 0;
916   menu_items = input_menu_get_items(item_data, group);
917922
923   /* an out of range group is special; it just means the game-specific inputs */
924   if (group > IPG_TOTAL_GROUPS)
925      menu_items = input_menu_get_game_items(machine, item_data);
926   else
927      menu_items = input_menu_get_items(machine, item_data, group);
928
918929   /* build the menu */
919930   memset(item_list, 0, sizeof(item_list));
920931   for (item = 0; item < menu_items; item++)
r2724r2725
954965      input_seq newseq;
955966
956967      /* if UI_CANCEL is pressed, abort */
957      if (input_ui_pressed(IPT_UI_CANCEL))
968      if (input_ui_pressed(machine, IPT_UI_CANCEL))
958969      {
959970         record_next = polling = FALSE;
960         input_menu_toggle_none_default(selected_item_data->seq, &starting_seq, selected_item_data->defseq);
971         input_menu_toggle_none_default(&selected_item_data->seq, &starting_seq, selected_item_data->defseq);
972         changed = TRUE;
961973      }
962974
963975      /* poll again; if finished, update the sequence */
r2724r2725
965977      {
966978         record_next = TRUE;
967979         polling = FALSE;
968         *selected_item_data->seq = newseq;
980         selected_item_data->seq = newseq;
981         changed = TRUE;
969982      }
970983   }
971984
r2724r2725
975988      int prevsel = selected;
976989
977990      /* handle generic menu keys */
978      if (ui_menu_generic_keys(&selected, menu_items, visible_items))
991      if (ui_menu_generic_keys(machine, &selected, menu_items, visible_items))
979992         return selected;
980993
981994      /* if an item was selected, start polling on it */
982      if (input_ui_pressed(IPT_UI_SELECT))
995      if (input_ui_pressed(machine, IPT_UI_SELECT))
983996      {
984         input_seq_poll_start((selected_item_data->type == INPUT_TYPE_ANALOG) ? ITEM_CLASS_ABSOLUTE : ITEM_CLASS_SWITCH, record_next ? selected_item_data->seq : NULL);
985         starting_seq = *selected_item_data->seq;
997         input_seq_poll_start((selected_item_data->type == INPUT_TYPE_ANALOG) ? ITEM_CLASS_ABSOLUTE : ITEM_CLASS_SWITCH, record_next ? &selected_item_data->seq : NULL);
998         starting_seq = selected_item_data->seq;
986999         polling = TRUE;
9871000      }
9881001
9891002      /* if the clear key was pressed, reset the selected item */
990      if (input_ui_pressed(IPT_UI_CLEAR))
1003      if (input_ui_pressed(machine, IPT_UI_CLEAR))
9911004      {
992         input_menu_toggle_none_default(selected_item_data->seq, selected_item_data->seq, selected_item_data->defseq);
1005         input_menu_toggle_none_default(&selected_item_data->seq, &selected_item_data->seq, selected_item_data->defseq);
9931006         record_next = FALSE;
1007         changed = TRUE;
9941008      }
9951009
9961010      /* if the selection changed, update and reset the "record first" flag */
r2724r2725
9981012         record_next = FALSE;
9991013   }
10001014
1015   /* if the sequence changed, update it */
1016   if (changed)
1017   {
1018      if (group > IPG_TOTAL_GROUPS)
1019      {
1020         input_field_user_settings settings;
1021
1022         input_field_get_user_settings(selected_item_data->field, &settings);
1023         settings.seq[selected_item_data->seqtype] = selected_item_data->seq;
1024         input_field_set_user_settings(selected_item_data->field, &settings);
1025      }
1026      else
1027      {
1028         const input_type_desc *typedesc = selected_item_data->typedesc;
1029         input_type_set_seq(machine, typedesc->type, typedesc->player, selected_item_data->seqtype, &selected_item_data->seq);
1030      }
1031   }
1032
10011033   return selected | (record_next << 14) | (polling << 15) | (group << 16);
10021034}
10031035
r2724r2725
10071039    switches
10081040-------------------------------------------------*/
10091041
1010static UINT32 menu_switches(UINT32 state)
1042static UINT32 menu_switches(running_machine *machine, UINT32 state)
10111043{
10121044   ui_menu_item item_list[MAX_INPUT_PORTS * MAX_BITS_PER_PORT / 2];
1013   int switch_entry = (state >> 24) & 0xff;
10141045   int switch_name = (state >> 16) & 0xff;
10151046   UINT32 selected = state & 0xffff;
1016   input_port_entry *selected_in = NULL;
1017   input_port_entry *in;
1047   const input_port_config *port;
1048   const input_field_config *field;
1049   const input_field_config *selected_field = NULL;
10181050   int menu_items = 0;
10191051   int changed = FALSE;
10201052   int visible_items;
r2724r2725
10261058   memset(dip_switch_model, 0, sizeof(dip_switch_model));
10271059
10281060   /* loop over input ports and set up the current values */
1029   for (in = Machine->input_ports; in->type != IPT_END; in++)
1030      if (in->type == switch_name && input_port_active(in) && input_port_condition(in))
1031      {
1032         switches_menu_add_item(&item_list[menu_items], in, switch_entry, in);
1033         if (in->type == IPT_DIPSWITCH_NAME)
1034            dip_switch_build_model(in, menu_items == selected);
1035         menu_items++;
1036      }
1061   for (port = machine->portconfig; port != NULL; port = port->next)
1062      for (field = port->fieldlist; field != NULL; field = field->next)
1063         if (field->type == switch_name && input_condition_true(machine, &field->condition))
1064         {
1065            switches_menu_add_item(&item_list[menu_items], field);
1066            if (field->type == IPT_DIPSWITCH)
1067               dip_switch_build_model(field, menu_items == selected);
1068            menu_items++;
1069         }
10371070
10381071   /* sort the list */
1039//  qsort(item_list, menu_items, sizeof(item_list[0]), switches_menu_compare_items);
1040   selected_in = item_list[selected].ref;
1072   selected_field = item_list[selected].ref;
10411073
10421074   /* add an item to return */
10431075   item_list[menu_items++].text = "Return to Prior Menu";
r2724r2725
10521084   visible_items = ui_menu_draw(item_list, menu_items, selected, (dip_switch_model[0].dip_name) ? &extra : NULL);
10531085
10541086   /* handle generic menu keys */
1055   if (ui_menu_generic_keys(&selected, menu_items, visible_items))
1087   if (ui_menu_generic_keys(machine, &selected, menu_items, visible_items))
10561088      return selected;
10571089
10581090   /* handle left/right arrows */
1059   if (input_ui_pressed(IPT_UI_LEFT) && (item_list[selected].flags & MENU_FLAG_LEFT_ARROW))
1091   if (input_ui_pressed(machine, IPT_UI_LEFT) && (item_list[selected].flags & MENU_FLAG_LEFT_ARROW))
10601092   {
1061      switches_menu_select_previous(selected_in, switch_entry);
1093      switches_menu_select_previous(selected_field);
10621094      changed = TRUE;
10631095   }
1064   if (input_ui_pressed(IPT_UI_RIGHT) && (item_list[selected].flags & MENU_FLAG_RIGHT_ARROW))
1096   if (input_ui_pressed(machine, IPT_UI_RIGHT) && (item_list[selected].flags & MENU_FLAG_RIGHT_ARROW))
10651097   {
1066      switches_menu_select_next(selected_in, switch_entry);
1098      switches_menu_select_next(selected_field);
10671099      changed = TRUE;
10681100   }
10691101
r2724r2725
10711103   /* due to conditional DIPs changing things */
10721104   if (changed)
10731105   {
1074      int newsel = 0;
1075      input_port_update_defaults();
1076      for (in = Machine->input_ports; in->type != IPT_END; in++)
1077         if (in->type == switch_name && input_port_active(in) && input_port_condition(in))
1078         {
1079            if (selected_in == in)
1106      int newselected = 0;
1107      for (port = machine->portconfig; port != NULL; port = port->next)
1108         for (field = port->fieldlist; field != NULL; field = field->next)
1109            if (field->type == switch_name && input_condition_true(machine, &field->condition))
10801110            {
1081               selected = newsel;
1082               break;
1111               if (field == selected_field)
1112               {
1113                  selected = newselected;
1114                  break;
1115               }
1116               newselected++;
10831117            }
1084            newsel++;
1085         }
10861118   }
10871119
1088   return selected | (switch_name << 16) | (switch_entry << 24);
1120   return selected | (switch_name << 16);
10891121}
10901122
10911123
r2724r2725
10941126    control settings
10951127-------------------------------------------------*/
10961128
1097static UINT32 menu_analog(UINT32 state)
1129static UINT32 menu_analog(running_machine *machine, UINT32 state)
10981130{
10991131   ui_menu_item item_list[MAX_INPUT_PORTS * 4 * ANALOG_ITEM_COUNT];
1100   input_port_entry *selected_in = NULL;
1101   input_port_entry *in;
1132   const input_port_config *port;
1133   const input_field_config *field;
1134   const input_field_config *selected_field = NULL;
11021135   int menu_items = 0;
11031136   int selected_item = 0;
11041137   int visible_items;
r2724r2725
11101143   menu_string_pool_offset = 0;
11111144
11121145   /* loop over input ports and add the items */
1113   for (in = Machine->input_ports; in->type != IPT_END; in++)
1114      if (port_type_is_analog(in->type))
1115      {
1116         use_autocenter = 0;
1117         switch (in->type)
1146   for (port = Machine->portconfig; port != NULL; port = port->next)
1147      for (field = port->fieldlist; field != NULL; field = field->next)
1148         if (input_type_is_analog(field->type))
11181149         {
1119            /* Autocenter Speed is only used for these devices */
1120            case IPT_POSITIONAL:
1121            case IPT_POSITIONAL_V:
1122               if (in->analog.wraps) break;
1150            use_autocenter = FALSE;
1151            switch (field->type)
1152            {
1153               /* Autocenter Speed is only used for these devices */
1154               case IPT_POSITIONAL:
1155               case IPT_POSITIONAL_V:
1156                  if (field->flags & ANALOG_FLAG_WRAPS)
1157                     break;
11231158
1124            case IPT_PEDAL:
1125            case IPT_PEDAL2:
1126            case IPT_PEDAL3:
1127            case IPT_PADDLE:
1128            case IPT_PADDLE_V:
1129            case IPT_AD_STICK_X:
1130            case IPT_AD_STICK_Y:
1131            case IPT_AD_STICK_Z:
1132               use_autocenter = 1;
1133               break;
1134         }
1159               case IPT_PEDAL:
1160               case IPT_PEDAL2:
1161               case IPT_PEDAL3:
1162               case IPT_PADDLE:
1163               case IPT_PADDLE_V:
1164               case IPT_AD_STICK_X:
1165               case IPT_AD_STICK_Y:
1166               case IPT_AD_STICK_Z:
1167                  use_autocenter = TRUE;
1168                  break;
1169            }
11351170
1136         /* track the selected item */
1137         if (state >= menu_items && state < menu_items + 3 + use_autocenter)
1138         {
1139            selected_in = in;
1140            selected_item = state - menu_items;
1141            // shift menu for missing Autocenter
1142            if (selected_item && !use_autocenter) selected_item++;
1171            /* track the selected item */
1172            if (state >= menu_items && state < menu_items + 3 + use_autocenter)
1173            {
1174               selected_field = field;
1175               selected_item = state - menu_items;
1176               // shift menu for missing Autocenter
1177               if (selected_item && !use_autocenter)
1178                  selected_item++;
1179            }
1180
1181            /* add the needed items for each analog input */
1182            analog_menu_add_item(&item_list[menu_items++], field, "Digital Speed", ANALOG_ITEM_KEYSPEED);
1183            if (use_autocenter)
1184               analog_menu_add_item(&item_list[menu_items++], field, "Autocenter Speed", ANALOG_ITEM_CENTERSPEED);
1185            analog_menu_add_item(&item_list[menu_items++], field, "Reverse", ANALOG_ITEM_REVERSE);
1186            analog_menu_add_item(&item_list[menu_items++], field, "Sensitivity", ANALOG_ITEM_SENSITIVITY);
11431187         }
11441188
1145         /* add the needed items for each analog input */
1146         analog_menu_add_item(&item_list[menu_items++], in, "Digital Speed", ANALOG_ITEM_KEYSPEED);
1147         if (use_autocenter)
1148            analog_menu_add_item(&item_list[menu_items++], in, "Autocenter Speed", ANALOG_ITEM_CENTERSPEED);
1149         analog_menu_add_item(&item_list[menu_items++], in, "Reverse", ANALOG_ITEM_REVERSE);
1150         analog_menu_add_item(&item_list[menu_items++], in, "Sensitivity", ANALOG_ITEM_SENSITIVITY);
1151      }
1152
11531189   /* add an item to return */
11541190   item_list[menu_items++].text = "Return to Prior Menu";
11551191
r2724r2725
11571193   visible_items = ui_menu_draw(item_list, menu_items, state, NULL);
11581194
11591195   /* handle generic menu keys */
1160   if (ui_menu_generic_keys(&state, menu_items, visible_items))
1196   if (ui_menu_generic_keys(machine, &state, menu_items, visible_items))
11611197      return state;
11621198
11631199   /* handle left/right arrows */
1164   if (input_ui_pressed_repeat(IPT_UI_LEFT,6) && (item_list[state].flags & MENU_FLAG_LEFT_ARROW))
1200   if (input_ui_pressed_repeat(machine, IPT_UI_LEFT,6) && (item_list[state].flags & MENU_FLAG_LEFT_ARROW))
11651201      delta = -1;
1166   if (input_ui_pressed_repeat(IPT_UI_RIGHT,6) && (item_list[state].flags & MENU_FLAG_RIGHT_ARROW))
1202   if (input_ui_pressed_repeat(machine, IPT_UI_RIGHT,6) && (item_list[state].flags & MENU_FLAG_RIGHT_ARROW))
11671203      delta = 1;
11681204   if (input_code_pressed(KEYCODE_LSHIFT))
11691205      delta *= 10;
11701206
11711207   /* adjust the appropriate value */
1172   if (delta != 0 && selected_in)
1208   if (delta != 0 && selected_field != NULL)
1209   {
1210      input_field_user_settings settings;
1211
1212      input_field_get_user_settings(selected_field, &settings);
11731213      switch (selected_item)
11741214      {
1175         case ANALOG_ITEM_KEYSPEED:      selected_in->analog.delta += delta;         break;
1176         case ANALOG_ITEM_CENTERSPEED:   selected_in->analog.centerdelta += delta;   break;
1177         case ANALOG_ITEM_REVERSE:      selected_in->analog.reverse += delta;      break;
1178         case ANALOG_ITEM_SENSITIVITY:   selected_in->analog.sensitivity += delta;   break;
1215         case ANALOG_ITEM_KEYSPEED:      settings.delta += delta;      break;
1216         case ANALOG_ITEM_CENTERSPEED:   settings.centerdelta += delta;   break;
1217         case ANALOG_ITEM_REVERSE:      settings.reverse += delta;      break;
1218         case ANALOG_ITEM_SENSITIVITY:   settings.sensitivity += delta;   break;
11791219      }
1220      input_field_set_user_settings(selected_field, &settings);
1221   }
11801222
11811223   return state;
11821224}
r2724r2725
11881230-------------------------------------------------*/
11891231
11901232#ifndef MESS
1191static UINT32 menu_bookkeeping(UINT32 state)
1233static UINT32 menu_bookkeeping(running_machine *machine, UINT32 state)
11921234{
11931235   char buf[2048];
11941236   char *bufptr = buf;
r2724r2725
12301272   ui_menu_draw_text_box(buf);
12311273
12321274   /* handle the keys */
1233   ui_menu_generic_keys(&selected, 1, 0);
1275   ui_menu_generic_keys(machine, &selected, 1, 0);
12341276   return selected;
12351277}
12361278#endif
r2724r2725
12411283    game information
12421284-------------------------------------------------*/
12431285
1244static UINT32 menu_game_info(UINT32 state)
1286static UINT32 menu_game_info(running_machine *machine, UINT32 state)
12451287{
12461288   char buf[2048];
12471289   char *bufptr = buf;
12481290   UINT32 selected = 0;
12491291
12501292   /* add the game info */
1251   bufptr += sprintf_game_info(Machine, bufptr);
1293   bufptr += sprintf_game_info(machine, bufptr);
12521294
12531295   /* draw the text */
12541296   ui_menu_draw_text_box(buf);
12551297
12561298   /* handle the keys */
1257   ui_menu_generic_keys(&selected, 1, 0);
1299   ui_menu_generic_keys(machine, &selected, 1, 0);
12581300   return selected;
12591301}
12601302
r2724r2725
12631305    menu_cheat - display a menu for cheat options
12641306-------------------------------------------------*/
12651307
1266static UINT32 menu_cheat(UINT32 state)
1308static UINT32 menu_cheat(running_machine *machine, UINT32 state)
12671309{
1268   int result = cheat_menu(Machine, state);
1310   int result = cheat_menu(machine, state);
12691311   if (result == 0)
12701312      return ui_menu_stack_pop();
12711313   return result;
r2724r2725
12771319    card options
12781320-------------------------------------------------*/
12791321
1280static UINT32 menu_memory_card(UINT32 state)
1322static UINT32 menu_memory_card(running_machine *machine, UINT32 state)
12811323{
12821324   ui_menu_item item_list[5];
12831325   int menu_items = 0;
r2724r2725
13121354   visible_items = ui_menu_draw(item_list, menu_items, selected, NULL);
13131355
13141356   /* handle the keys */
1315   if (ui_menu_generic_keys(&selected, menu_items, visible_items))
1357   if (ui_menu_generic_keys(machine, &selected, menu_items, visible_items))
13161358      return selected;
1317   if (selected == 0 && input_ui_pressed(IPT_UI_LEFT) && cardnum > 0)
1359   if (selected == 0 && input_ui_pressed(machine, IPT_UI_LEFT) && cardnum > 0)
13181360      cardnum--;
1319   if (selected == 0 && input_ui_pressed(IPT_UI_RIGHT) && cardnum < 1000)
1361   if (selected == 0 && input_ui_pressed(machine, IPT_UI_RIGHT) && cardnum < 1000)
13201362      cardnum++;
13211363
13221364   /* handle actions */
1323   if (input_ui_pressed(IPT_UI_SELECT))
1365   if (input_ui_pressed(machine, IPT_UI_SELECT))
13241366   {
13251367      /* handle load */
13261368      if (selected == insertindex)
r2724r2725
13381380      /* handle eject */
13391381      else if (selected == ejectindex)
13401382      {
1341         memcard_eject(Machine);
1383         memcard_eject(machine);
13421384         popmessage("Memory card ejected");
13431385      }
13441386
r2724r2725
13601402    menu_video - display a menu for video options
13611403-------------------------------------------------*/
13621404
1363static UINT32 menu_video(UINT32 state)
1405static UINT32 menu_video(running_machine *machine, UINT32 state)
13641406{
13651407   ui_menu_item item_list[100];
13661408   render_target *targetlist[16];
r2724r2725
13911433
13921434      /* if we only ended up with one, auto-select it */
13931435      if (menu_items == 1)
1394         return menu_video(0 << 16 | render_target_get_view(render_target_get_indexed(0)));
1436         return menu_video(machine, 0 << 16 | render_target_get_view(render_target_get_indexed(0)));
13951437
13961438      /* add an item for moving the UI */
13971439      item_list[menu_items++].text = "Move User Interface";
r2724r2725
14031445      visible_items = ui_menu_draw(item_list, menu_items, selected, NULL);
14041446
14051447      /* handle the keys */
1406      if (ui_menu_generic_keys(&selected, menu_items, visible_items))
1448      if (ui_menu_generic_keys(machine, &selected, menu_items, visible_items))
14071449         return selected;
14081450
14091451      /* handle actions */
1410      if (input_ui_pressed(IPT_UI_SELECT))
1452      if (input_ui_pressed(machine, IPT_UI_SELECT))
14111453      {
14121454         if (selected == menu_items - 2)
14131455         {
r2724r2725
14781520      visible_items = ui_menu_draw(item_list, menu_items, selected, NULL);
14791521
14801522      /* handle the keys */
1481      if (ui_menu_generic_keys(&selected, menu_items, visible_items))
1523      if (ui_menu_generic_keys(machine, &selected, menu_items, visible_items))
14821524         return selected;
14831525
14841526      /* handle actions */
1485      if (input_ui_pressed(IPT_UI_SELECT))
1527      if (input_ui_pressed(machine, IPT_UI_SELECT))
14861528      {
14871529         /* rotate */
14881530         if (selected == menu_items - 6)
r2724r2725
15351577    quitting the game
15361578-------------------------------------------------*/
15371579
1538static UINT32 menu_quit_game(UINT32 state)
1580static UINT32 menu_quit_game(running_machine *machine, UINT32 state)
15391581{
15401582   /* request a reset */
1541   mame_schedule_exit(Machine);
1583   mame_schedule_exit(machine);
15421584
15431585   /* reset the menu stack */
15441586   ui_menu_stack_reset();
r2724r2725
15511593    menu
15521594-------------------------------------------------*/
15531595
1554static UINT32 menu_select_game(UINT32 state)
1596static UINT32 menu_select_game(running_machine *machine, UINT32 state)
15551597{
15561598   ui_menu_item item_list[VISIBLE_GAMES_IN_LIST + 2];
15571599   int error = (state >> 17) & 1;
r2724r2725
16491691         recompute |= select_game_handle_key(curkey, curkey - KEYCODE_0_PAD + '0');
16501692
16511693      /* escape pressed with non-empty text clears the text */
1652      if (input_ui_pressed(IPT_UI_CANCEL))
1694      if (input_ui_pressed(machine, IPT_UI_CANCEL))
16531695      {
16541696         if (select_game_buffer[0] == 0)
16551697            return ui_menu_stack_pop();
r2724r2725
16651707         selected = 0;
16661708
16671709      /* ignore pause keys by swallowing them */
1668      input_ui_pressed(IPT_UI_PAUSE);
1710      input_ui_pressed(machine, IPT_UI_PAUSE);
16691711
16701712      /* handle the generic keys */
1671      if (!recompute && ui_menu_generic_keys(&selected, menu_items, visible_items))
1713      if (!recompute && ui_menu_generic_keys(machine, &selected, menu_items, visible_items))
16721714         return selected;
16731715
16741716      /* handle actions */
1675      if (input_ui_pressed(IPT_UI_SELECT))
1717      if (input_ui_pressed(machine, IPT_UI_SELECT))
16761718      {
16771719         /* control config */
16781720         if (ui_menu_is_force_game_select() && selected == menu_items - 2)
r2724r2725
16941736            /* if everything looks good, schedule the new driver */
16951737            if (audit_result == CORRECT || audit_result == BEST_AVAILABLE)
16961738            {
1697               mame_schedule_new_driver(Machine, select_game_list[selected]);
1739               mame_schedule_new_driver(machine, select_game_list[selected]);
16981740               ui_menu_stack_reset();
16991741               return 0;
17001742            }
r2724r2725
17181760-------------------------------------------------*/
17191761
17201762#ifdef MESS
1721static UINT32 menu_file_manager(UINT32 state)
1763static UINT32 menu_file_manager(running_machine *machine, UINT32 state)
17221764{
1723   int result = filemanager(state);
1765   int result = filemanager(machine, state);
17241766   if (result == 0)
17251767   return ui_menu_stack_pop();
17261768   return result;
r2724r2725
17341776
17351777#ifdef MESS
17361778#if HAS_WAVE
1737static UINT32 menu_tape_control(UINT32 state)
1779static UINT32 menu_tape_control(running_machine *machine, UINT32 state)
17381780{
1739   int result = tapecontrol(state);
1781   int result = tapecontrol(machine, state);
17401782   if (result == 0)
17411783   return ui_menu_stack_pop();
17421784   return result;
r2724r2725
18101852    for a given group of inputs
18111853-------------------------------------------------*/
18121854
1813static int input_menu_get_items(input_item_data *itemlist, int group)
1855static int input_menu_get_items(running_machine *machine, input_item_data *itemlist, int group)
18141856{
18151857   input_item_data *item = itemlist;
1816   const input_port_default_entry *indef;
1817   input_port_default_entry *in;
1858   const input_type_desc *typedesc;
18181859   astring *seqstring;
18191860
1820   /* an out of range group is special; it just means the game-specific inputs */
1821   if (group > IPG_TOTAL_GROUPS)
1822      return input_menu_get_game_items(itemlist);
1823
18241861   /* iterate over the input ports and add menu items */
18251862   seqstring = astring_alloc();
1826   for (in = get_input_port_list(), indef = get_input_port_list_defaults(); in->type != IPT_END; in++, indef++)
1863   for (typedesc = input_type_list(machine); typedesc != NULL; typedesc = typedesc->next)
18271864
18281865      /* add if we match the group and we have a valid name */
1829      if (in->group == group && in->name && in->name[0] != 0)
1866      if (typedesc->group == group && typedesc->name != NULL && typedesc->name[0] != 0)
18301867      {
18311868         /* build an entry for the standard sequence */
1832         item->seq = &in->defaultseq;
1833         item->defseq = &indef->defaultseq;
1869         item->typedesc = typedesc;
1870         item->seqtype = SEQ_TYPE_STANDARD;
1871         item->seq = *input_type_seq(machine, typedesc->type, typedesc->player, item->seqtype);
1872         item->defseq = &typedesc->seq[item->seqtype];
18341873         item->sortorder = item - itemlist;
1835         item->type = port_type_is_analog(in->type) ? INPUT_TYPE_ANALOG : INPUT_TYPE_DIGITAL;
1836         item->name = menu_string_pool_add(input_format[item->type], in->name);
1837         item->seqname = menu_string_pool_add("%s", astring_c(input_seq_name(seqstring, item->seq)));
1838         item->invert = input_seq_cmp(item->seq, item->defseq);
1874         item->type = input_type_is_analog(typedesc->type) ? INPUT_TYPE_ANALOG : INPUT_TYPE_DIGITAL;
1875         item->name = menu_string_pool_add(input_format[item->type], typedesc->name);
1876         item->seqname = menu_string_pool_add("%s", astring_c(input_seq_name(seqstring, &item->seq)));
1877         item->invert = input_seq_cmp(&item->seq, item->defseq);
18391878         item++;
18401879
18411880         /* if we're analog, add more entries */
18421881         if (item[-1].type == INPUT_TYPE_ANALOG)
18431882         {
18441883            /* build an entry for the decrement sequence */
1845            item->seq = &in->defaultdecseq;
1846            item->defseq = &indef->defaultdecseq;
1884            item->typedesc = typedesc;
1885            item->seqtype = SEQ_TYPE_DECREMENT;
1886            item->seq = *input_type_seq(machine, typedesc->type, typedesc->player, item->seqtype);
1887            item->defseq = &typedesc->seq[item->seqtype];
18471888            item->sortorder = item - itemlist;
18481889            item->type = INPUT_TYPE_ANALOG_DEC;
1849            item->name = menu_string_pool_add(input_format[item->type], in->name);
1850            item->seqname = menu_string_pool_add("%s", astring_c(input_seq_name(seqstring, item->seq)));
1851            item->invert = input_seq_cmp(item->seq, item->defseq);
1890            item->name = menu_string_pool_add(input_format[item->type], typedesc->name);
1891            item->seqname = menu_string_pool_add("%s", astring_c(input_seq_name(seqstring, &item->seq)));
1892            item->invert = input_seq_cmp(&item->seq, item->defseq);
18521893            item++;
18531894
18541895            /* build an entry for the increment sequence */
1855            item->seq = &in->defaultincseq;
1856            item->defseq = &indef->defaultincseq;
1896            item->typedesc = typedesc;
1897            item->seqtype = SEQ_TYPE_INCREMENT;
1898            item->seq = *input_type_seq(machine, typedesc->type, typedesc->player, item->seqtype);
1899            item->defseq = &typedesc->seq[item->seqtype];
18571900            item->sortorder = item - itemlist;
18581901            item->type = INPUT_TYPE_ANALOG_INC;
1859            item->name = menu_string_pool_add(input_format[item->type], in->name);
1860            item->seqname = menu_string_pool_add("%s", astring_c(input_seq_name(seqstring, item->seq)));
1861            item->invert = input_seq_cmp(item->seq, item->defseq);
1902            item->name = menu_string_pool_add(input_format[item->type], typedesc->name);
1903            item->seqname = menu_string_pool_add("%s", astring_c(input_seq_name(seqstring, &item->seq)));
1904            item->invert = input_seq_cmp(&item->seq, item->defseq);
18621905            item++;
18631906         }
18641907      }
r2724r2725
18701913
18711914
18721915/*-------------------------------------------------
1916    get_field_default_seq - return a pointer
1917    to the default sequence for the given field
1918-------------------------------------------------*/
1919
1920static const input_seq *get_field_default_seq(const input_field_config *field, int seqtype)
1921{
1922   if (input_seq_get_1(&field->seq[seqtype]) == SEQCODE_DEFAULT)
1923      return input_type_seq(field->port->machine, field->type, field->player, seqtype);
1924   else
1925      return &field->seq[seqtype];
1926}
1927
1928
1929/*-------------------------------------------------
18731930    input_menu_get_game_items - build a list of
18741931    items for the game-specific inputs
18751932-------------------------------------------------*/
18761933
1877static int input_menu_get_game_items(input_item_data *itemlist)
1934static int input_menu_get_game_items(running_machine *machine, input_item_data *itemlist)
18781935{
1879   static const input_seq default_seq = SEQ_DEF_1(SEQCODE_DEFAULT);
18801936   astring *seqstring = astring_alloc();
18811937   input_item_data *item = itemlist;
1882   input_port_entry *in;
1938   const input_port_config *port;
1939   const input_field_config *field;
18831940
18841941   /* iterate over the input ports and add menu items */
1885   for (in = Machine->input_ports; in->type != IPT_END; in++)
1886   {
1887      const char *name = input_port_name(in);
1942   for (port = machine->portconfig; port != NULL; port = port->next)
1943      for (field = port->fieldlist; field != NULL; field = field->next)
1944      {
1945         const char *name = input_field_name(field);
18881946
1889      /* add if we match the group and we have a valid name */
1890      if ((name != NULL) && (input_port_condition(in)) &&
1947         /* add if we match the group and we have a valid name */
1948         if (name != NULL && input_condition_true(machine, &field->condition) &&
18911949#ifdef MESS
1892         (in->category == 0 || input_category_active(Machine, in->category)) &&
1950            (field->category == 0 || input_category_active(machine, field->category)) &&
18931951#endif /* MESS */
1894         ((in->type == IPT_OTHER && in->name != IP_NAME_DEFAULT) || port_type_to_group(in->type, in->player) != IPG_INVALID))
1895      {
1896         UINT16 sortorder;
1897         const input_seq *curseq, *defseq;
1952            ((field->type == IPT_OTHER && field->name != NULL) || input_type_group(machine, field->type, field->player) != IPG_INVALID))
1953         {
1954            UINT16 sortorder;
18981955
1899         /* determine the sorting order */
1900         if (in->type >= IPT_START1 && in->type <= __ipt_analog_end)
1901            sortorder = (in->type << 2) | (in->player << 12);
1902         else
1903            sortorder = in->type | 0xf000;
1956            /* determine the sorting order */
1957            if (field->type >= IPT_START1 && field->type <= __ipt_analog_end)
1958               sortorder = (field->type << 2) | (field->player << 12);
1959            else
1960               sortorder = field->type | 0xf000;
19041961
1905         /* fetch data for the standard sequence */
1906         curseq = input_port_seq(in, SEQ_TYPE_STANDARD);
1907         defseq = input_port_default_seq(in->type, in->player, SEQ_TYPE_STANDARD);
1908
1909         /* build an entry for the standard sequence */
1910         item->seq = &in->seq;
1911         item->defseq = &default_seq;
1912         item->sortorder = sortorder;
1913         item->type = port_type_is_analog(in->type) ? INPUT_TYPE_ANALOG : INPUT_TYPE_DIGITAL;
1914         item->name = menu_string_pool_add(input_format[item->type], name);
1915         item->seqname = menu_string_pool_add("%s", astring_c(input_seq_name(seqstring, curseq)));
1916         item->invert = input_seq_cmp(curseq, defseq);
1917         item++;
1918
1919         /* if we're analog, add more entries */
1920         if (item[-1].type == INPUT_TYPE_ANALOG)
1921         {
1922            /* fetch data for the decrement sequence */
1923            curseq = input_port_seq(in, SEQ_TYPE_DECREMENT);
1924            defseq = input_port_default_seq(in->type, in->player, SEQ_TYPE_DECREMENT);
1925
1926            /* build an entry for the decrement sequence */
1927            item->seq = &in->analog.decseq;
1928            item->defseq = &default_seq;
1962            /* build an entry for the standard sequence */
1963            item->field = field;
1964            item->seqtype = SEQ_TYPE_STANDARD;
1965            item->seq = *input_field_seq(field, item->seqtype);
1966            item->defseq = get_field_default_seq(field, item->seqtype);
19291967            item->sortorder = sortorder;
1930            item->type = INPUT_TYPE_ANALOG_DEC;
1968            item->type = input_type_is_analog(field->type) ? INPUT_TYPE_ANALOG : INPUT_TYPE_DIGITAL;
19311969            item->name = menu_string_pool_add(input_format[item->type], name);
1932            item->seqname = menu_string_pool_add("%s", astring_c(input_seq_name(seqstring, curseq)));
1933            item->invert = input_seq_cmp(curseq, defseq);
1970            item->seqname = menu_string_pool_add("%s", astring_c(input_seq_name(seqstring, &item->seq)));
1971            item->invert = input_seq_cmp(&item->seq, item->defseq);
19341972            item++;
19351973
1936            /* fetch data for the increment sequence */
1937            curseq = input_port_seq(in, SEQ_TYPE_INCREMENT);
1938            defseq = input_port_default_seq(in->type, in->player, SEQ_TYPE_INCREMENT);
1974            /* if we're analog, add more entries */
1975            if (item[-1].type == INPUT_TYPE_ANALOG)
1976            {
1977               /* build an entry for the decrement sequence */
1978               item->field = field;
1979               item->seqtype = SEQ_TYPE_DECREMENT;
1980               item->seq = *input_field_seq(field, item->seqtype);
1981               item->defseq = get_field_default_seq(field, item->seqtype);
1982               item->sortorder = sortorder;
1983               item->type = INPUT_TYPE_ANALOG_DEC;
1984               item->name = menu_string_pool_add(input_format[item->type], name);
1985               item->seqname = menu_string_pool_add("%s", astring_c(input_seq_name(seqstring, &item->seq)));
1986               item->invert = input_seq_cmp(&item->seq, item->defseq);
1987               item++;
19391988
1940            /* build an entry for the increment sequence */
1941            item->seq = &in->analog.incseq;
1942            item->defseq = &default_seq;
1943            item->sortorder = sortorder;
1944            item->type = INPUT_TYPE_ANALOG_INC;
1945            item->name = menu_string_pool_add(input_format[item->type], name);
1946            item->seqname = menu_string_pool_add("%s", astring_c(input_seq_name(seqstring, curseq)));
1947            item->invert = input_seq_cmp(curseq, defseq);
1948            item++;
1989               /* build an entry for the increment sequence */
1990               item->field = field;
1991               item->seqtype = SEQ_TYPE_INCREMENT;
1992               item->seq = *input_field_seq(field, item->seqtype);
1993               item->defseq = get_field_default_seq(field, item->seqtype);
1994               item->sortorder = sortorder;
1995               item->type = INPUT_TYPE_ANALOG_INC;
1996               item->name = menu_string_pool_add(input_format[item->type], name);
1997               item->seqname = menu_string_pool_add("%s", astring_c(input_seq_name(seqstring, &item->seq)));
1998               item->invert = input_seq_cmp(&item->seq, item->defseq);
1999               item++;
2000            }
19492001         }
19502002      }
1951   }
19522003
19532004   /* return the number of items */
19542005   astring_free(seqstring);
r2724r2725
20012052    switches menu list
20022053-------------------------------------------------*/
20032054
2004static void switches_menu_add_item(ui_menu_item *item, const input_port_entry *in, int switch_entry, void *ref)
2055static void switches_menu_add_item(ui_menu_item *item, const input_field_config *field)
20052056{
2006   const input_port_entry *tin;
2057   const input_setting_config *setting;
2058   input_field_user_settings settings;
20072059
20082060   /* set the text to the name and the subitem text to invalid */
2009   item->text = input_port_name(in);
2061   input_field_get_user_settings(field, &settings);
2062   item->text = input_field_name(field);
20102063   item->subtext = NULL;
20112064
20122065   /* scan for the current selection in the list */
2013   for (tin = in + 1; tin->type == switch_entry; tin++)
2014      if (input_port_condition(tin))
2066   for (setting = field->settinglist; setting != NULL; setting = setting->next)
2067      if (input_condition_true(field->port->machine, &setting->condition))
20152068      {
20162069         /* if this is a match, set the subtext */
2017         if (in->default_value == tin->default_value)
2018            item->subtext = input_port_name(tin);
2070         if (setting->value == settings.value)
2071            item->subtext = setting->name;
20192072
20202073         /* else if we haven't seen a match yet, show a left arrow */
2021         else if (!item->subtext)
2074         else if (item->subtext == NULL)
20222075            item->flags |= MENU_FLAG_LEFT_ARROW;
20232076
20242077         /* else if we have seen a match, show a right arrow */
r2724r2725
20272080      }
20282081
20292082   /* if no matches, we're invalid */
2030   if (!item->subtext)
2083   if (item->subtext == NULL)
20312084      item->subtext = "INVALID";
20322085
20332086   /* stash our reference */
2034   item->ref = ref;
2087   item->ref = (void *)field;
20352088}
20362089
20372090
r2724r2725
20402093    previous item in the switches list
20412094-------------------------------------------------*/
20422095
2043static void switches_menu_select_previous(input_port_entry *in, int switch_entry)
2096static void switches_menu_select_previous(const input_field_config *field)
20442097{
2045   int last_value = in->default_value;
2046   const input_port_entry *tin;
2098   const input_setting_config *setting, *prevsetting;
2099   input_field_user_settings settings;
2100   int found_match = FALSE;
20472101
2048   /* scan for the current selection in the list */
2049   for (tin = in + 1; tin->type == switch_entry; tin++)
2050      if (input_port_condition(tin))
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)
20512110      {
2052         /* if this is a match, we're done */
2053         if (in->default_value == tin->default_value)
2054         {
2055            in->default_value = last_value;
2056            return;
2057         }
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   }
20582118
2059         /* otherwise, keep track of last one found */
2060         else
2061            last_value = tin->default_value;
2062      }
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);
20632131}
20642132
20652133
r2724r2725
20682136    next item in the switches list
20692137-------------------------------------------------*/
20702138
2071static void switches_menu_select_next(input_port_entry *in, int switch_entry)
2139static void switches_menu_select_next(const input_field_config *field)
20722140{
2073   const input_port_entry *tin;
2074   int foundit = FALSE;
2141   const input_setting_config *setting, *nextsetting;
2142   input_field_user_settings settings;
20752143
2076   /* scan for the current selection in the list */
2077   for (tin = in + 1; tin->type == switch_entry; tin++)
2078      if (input_port_condition(tin))
2079      {
2080         /* if we found the current selection, we pick the next one */
2081         if (foundit)
2082         {
2083            in->default_value = tin->default_value;
2084            return;
2085         }
2144   /* get the current configured settings */
2145   input_field_get_user_settings(field, &settings);
20862146
2087         /* if this is a match, note it */
2088         if (in->default_value == tin->default_value)
2089            foundit = TRUE;
2090      }
2091}
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;
20922152
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;
20932158
2094/*-------------------------------------------------
2095    switches_menu_compare_items - compare two
2096    switches items for quicksort purposes
2097-------------------------------------------------*/
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;
20982164
2099/*
2100static int switches_menu_compare_items(const void *i1, const void *i2)
2101{
2102    const ui_menu_item *item1 = i1;
2103    const ui_menu_item *item2 = i2;
2104    const input_port_entry *data1 = item1->ref;
2105    const input_port_entry *data2 = item2->ref;
2106    return strcmp(input_port_name(data1), input_port_name(data2));
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);
21072169}
2108*/
21092170
21102171
21112172/*-------------------------------------------------
r2724r2725
21132174    analog controls menu
21142175-------------------------------------------------*/
21152176
2116static void analog_menu_add_item(ui_menu_item *item, const input_port_entry *in, const char *append_string, int which_item)
2177static void analog_menu_add_item(ui_menu_item *item, const input_field_config *field, const char *append_string, int which_item)
21172178{
2179   input_field_user_settings settings;
21182180   int value, minval, maxval;
21192181
2182   input_field_get_user_settings(field, &settings);
2183
21202184   /* set the item text using the formatting string provided */
2121   item->text = menu_string_pool_add("%s %s", input_port_name(in), append_string);
2185   item->text = menu_string_pool_add("%s %s", input_field_name(field), append_string);
21222186
21232187   /* set the subitem text */
21242188   switch (which_item)
21252189   {
21262190      default:
21272191      case ANALOG_ITEM_KEYSPEED:
2128         value = in->analog.delta;
2192         value = settings.delta;
21292193         minval = 0;
21302194         maxval = 255;
21312195         item->subtext = menu_string_pool_add("%d", value);
21322196         break;
21332197
21342198      case ANALOG_ITEM_CENTERSPEED:
2135         value = in->analog.centerdelta;
2199         value = settings.centerdelta;
21362200         minval = 0;
21372201         maxval = 255;
21382202         item->subtext = menu_string_pool_add("%d", value);
21392203         break;
21402204
21412205      case ANALOG_ITEM_REVERSE:
2142         value = in->analog.reverse;
2206         value = settings.reverse;
21432207         minval = 0;
21442208         maxval = 1;
21452209         item->subtext = value ? "On" : "Off";
21462210         break;
21472211
21482212      case ANALOG_ITEM_SENSITIVITY:
2149         value = in->analog.sensitivity;
2213         value = settings.sensitivity;
21502214         minval = 1;
21512215         maxval = 255;
21522216         item->subtext = menu_string_pool_add("%d%%", value);
r2724r2725
21662230    for DIP switches
21672231-------------------------------------------------*/
21682232
2169static void dip_switch_build_model(input_port_entry *entry, int item_is_selected)
2233static void dip_switch_build_model(const input_field_config *field, int item_is_selected)
21702234{
2171   int dip_declaration_index = 0;
2172   int value_mask_temp = entry->mask;
2235   input_port_value value_mask_temp = field->mask;
2236   const input_field_diplocation *diploc;
2237   input_port_value toggle_switch_mask;
2238   input_field_user_settings settings;
21732239   int value_mask_bit = 0;
2174   int toggle_switch_mask;
2175   int model_index = 0;
2240   int model_index;
21762241   int toggle_num;
21772242
2178   if (entry->diploc[dip_declaration_index].swname == NULL)
2243   diploc = field->diploclist;
2244   if (diploc == NULL || diploc->swname == NULL)
21792245      return;
21802246
2247   input_field_get_user_settings(field, &settings);
2248
21812249   /* get the entry in the model to work with */
2182   do
2250   for (model_index = 0; model_index < MAX_PHYSICAL_DIPS; model_index++)
21832251   {
21842252      /* use this entry if it's not used */
21852253      if (dip_switch_model[model_index].dip_name == NULL)
21862254      {
2187         dip_switch_model[model_index].dip_name = entry->diploc[dip_declaration_index].swname;
2255         dip_switch_model[model_index].dip_name = diploc->swname;
21882256         break;
21892257      }
21902258
21912259      /* reuse this entry if the switch name matches */
2192      if (!strcmp(entry->diploc[dip_declaration_index].swname, dip_switch_model[model_index].dip_name))
2260      if (!strcmp(diploc->swname, dip_switch_model[model_index].dip_name))
21932261         break;
21942262
21952263      // todo: add a check here to see if we go over the max dips and throw an error.
2196   } while (++model_index < MAX_PHYSICAL_DIPS);
2264   }
21972265
21982266   /* Create a mask depicting the number of toggles on the physical switch */
2199   while (entry->diploc[dip_declaration_index].swname)
2267   for ( ; diploc != NULL; diploc = diploc->next)
22002268   {
22012269      /* get the Nth DIP toggle number */
2202      toggle_num = entry->diploc[dip_declaration_index].swnum;
2270      toggle_num = diploc->swnum;
22032271
22042272      /* get the Nth mask bit -
22052273         * should probably put a check here to avoid bad driver definitions
r2724r2725
22182286      dip_switch_model[model_index].total_dip_mask |= toggle_switch_mask;
22192287
22202288      /* if it's inverted, mark it as such */
2221      if (entry->diploc[dip_declaration_index].invert)
2289      if (diploc->invert)
22222290         dip_switch_model[model_index].dip_invert_mask |= toggle_switch_mask;
22232291
22242292      /* if isolated bit is on, set the toggle on */
2225      if ((1 << value_mask_bit) & entry->default_value)
2293      if ((1 << value_mask_bit) & settings.value)
22262294         dip_switch_model[model_index].total_dip_settings |= toggle_switch_mask;
22272295
22282296      /* indicate if the toggle is selected */
22292297      if (item_is_selected)
22302298         dip_switch_model[model_index].selected_dip_feature_mask |= toggle_switch_mask;
2231
2232      ++dip_declaration_index;
22332299   }
22342300}
22352301
src/emu/uimenu.h
r2724r2725
3232    TYPE DEFINITIONS
3333***************************************************************************/
3434
35typedef UINT32 (*ui_menu_handler_func)(UINT32 state);
35typedef UINT32 (*ui_menu_handler_func)(running_machine *machine, UINT32 state);
3636
3737typedef struct _ui_menu_item ui_menu_item;
3838struct _ui_menu_item
r2724r2725
6565/* draw a menu, returning the number of visible items */
6666int ui_menu_draw(const ui_menu_item *items, int numitems, int selected, const menu_extra *extra);
6767
68/* draw a text box */
69void ui_menu_draw_text_box(const char *text);
70
7168/* master handler */
7269UINT32 ui_menu_ui_handler(running_machine *machine, UINT32 state);
7370
7471/* menu keyboard handling */
75int ui_menu_generic_keys(UINT32 *selected, int num_items, int visible_items);
72int ui_menu_generic_keys(running_machine *machine, UINT32 *selected, int num_items, int visible_items);
7673
7774/* menu stack management */
7875void ui_menu_stack_reset(void);
src/emu/memory.c
r2724r2725
706706   /* loop over tokens until we hit the end */
707707   while (entrytype != ADDRMAP_TOKEN_END)
708708   {
709      const char *tag;
710
711709      /* unpack the token from the first entry */
712710      TOKEN_GET_UINT32_UNPACK1(tokens, entrytype, 8);
713711      switch (entrytype)
r2724r2725
785783            break;
786784
787785         case ADDRMAP_TOKEN_READ_PORT:
788            tag = TOKEN_GET_STRING(tokens);
789            switch (map->databits)
790            {
791               case 8:      entry->read.mhandler8  = port_tag_to_handler8(tag);      break;
792               case 16:   entry->read.mhandler16 = port_tag_to_handler16(tag);   break;
793               case 32:   entry->read.mhandler32 = port_tag_to_handler32(tag);   break;
794               case 64:   entry->read.mhandler64 = port_tag_to_handler64(tag);   break;
795            }
796            if (entry->read.generic == NULL)
797               fatalerror("Non-existent port referenced: '%s'\n", tag);
786            entry->read_porttag = TOKEN_GET_STRING(tokens);
798787            break;
799788
800789         case ADDRMAP_TOKEN_REGION:
r2724r2725
15561545               while (last_entry != space->map->entrylist)
15571546               {
15581547                  const address_map_entry *entry;
1548                  read_handler rhandler;
1549                  write_handler whandler;
15591550
15601551                  /* find the entry before the last one we processed */
15611552                  for (entry = space->map->entrylist; entry->next != last_entry; entry = entry->next) ;
15621553                  last_entry = entry;
1554                  rhandler = entry->read;
1555                  whandler = entry->write;
15631556
1564                  if (entry->read.generic != NULL)
1557                  /* if we have a read port tag, look it up */
1558                  if (entry->read_porttag != NULL)
15651559                  {
1560                     switch (space->dbits)
1561                     {
1562                        case 8:      rhandler.mhandler8  = input_port_read_handler8(machine->portconfig, entry->read_porttag);   break;
1563                        case 16:   rhandler.mhandler16 = input_port_read_handler16(machine->portconfig, entry->read_porttag);   break;
1564                        case 32:   rhandler.mhandler32 = input_port_read_handler32(machine->portconfig, entry->read_porttag);   break;
1565                        case 64:   rhandler.mhandler64 = input_port_read_handler64(machine->portconfig, entry->read_porttag);   break;
1566                     }
1567                     if (rhandler.generic == NULL)
1568                        fatalerror("Non-existent port referenced: '%s'\n", entry->read_porttag);
1569                  }
1570
1571                  /* install the read handler if present */
1572                  if (rhandler.generic != NULL)
1573                  {
15661574                     int bits = (entry->read_bits == 0) ? space->dbits : entry->read_bits;
15671575                     void *object = machine;
15681576                     if (entry->read_devtype != NULL)
r2724r2725
15711579                        if (object == NULL)
15721580                           fatalerror("Unidentified object in memory map: type=%s tag=%s\n", devtype_name(entry->read_devtype), entry->read_devtag);
15731581                     }
1574                     space_map_range_private(space, ROW_READ, bits, entry->read_mask, entry->addrstart, entry->addrend, entry->addrmask, entry->addrmirror, entry->read.generic, object, entry->read_name);
1582                     space_map_range_private(space, ROW_READ, bits, entry->read_mask, entry->addrstart, entry->addrend, entry->addrmask, entry->addrmirror, rhandler.generic, object, entry->read_name);
15751583                  }
1576                  if (entry->write.generic != NULL)
1584
1585                  /* install the write handler if present */
1586                  if (whandler.generic != NULL)
15771587                  {
15781588                     int bits = (entry->write_bits == 0) ? space->dbits : entry->write_bits;
15791589                     void *object = machine;
r2724r2725
15831593                        if (object == NULL)
15841594                           fatalerror("Unidentified object in memory map: type=%s tag=%s\n", devtype_name(entry->write_devtype), entry->write_devtag);
15851595                     }
1586                     space_map_range_private(space, ROW_WRITE, bits, entry->write_mask, entry->addrstart, entry->addrend, entry->addrmask, entry->addrmirror, entry->write.generic, object, entry->write_name);
1596                     space_map_range_private(space, ROW_WRITE, bits, entry->write_mask, entry->addrstart, entry->addrend, entry->addrmask, entry->addrmirror, whandler.generic, object, entry->write_name);
15871597                  }
15881598               }
15891599            }
r2724r2725
24432453               if (entry->baseptr != NULL)
24442454                  *entry->baseptr = entry->memory;
24452455               if (entry->baseptroffs_plus1 != 0)
2446                  *(void **)((UINT8 *)Machine->driver_data + entry->baseptroffs_plus1 - 1) = entry->memory;
2456                  *(void **)((UINT8 *)machine->driver_data + entry->baseptroffs_plus1 - 1) = entry->memory;
24472457               if (entry->sizeptr != NULL)
24482458                  *entry->sizeptr = entry->byteend - entry->bytestart + 1;
24492459               if (entry->sizeptroffs_plus1 != 0)
2450                  *(size_t *)((UINT8 *)Machine->driver_data + entry->sizeptroffs_plus1 - 1) = entry->byteend - entry->bytestart + 1;
2460                  *(size_t *)((UINT8 *)machine->driver_data + entry->sizeptroffs_plus1 - 1) = entry->byteend - entry->bytestart + 1;
24512461            }
24522462         }
24532463
src/emu/memory.h
r2724r2725
212212   const char *         read_name;         /* read handler callback name */
213213   device_type            read_devtype;      /* read device type for device references */
214214   const char *         read_devtag;      /* read tag for the relevant device */
215   const char *         read_porttag;      /* tag for input port reading */
215216   write_handler          write;            /* write handler callback */
216217   UINT8               write_bits;         /* bits for the write handler callback (0=default, 1=8, 2=16, 3=32) */
217218   UINT8               write_mask;         /* mask bits indicating which subunits to process */
src/emu/mame.c
r2724r2725
14671467   machine->sample_rate = options_get_int(mame_options(), OPTION_SAMPLERATE);
14681468
14691469   /* input-related information */
1470   machine->input_ports = NULL;
1471   machine->record_file = NULL;
1472   machine->playback_file = NULL;
1470   machine->portconfig = NULL;
14731471
14741472   /* debugger-related information */
14751473#ifdef ENABLE_DEBUGGER
r2724r2725
15981596#endif
15991597
16001598   /* call the driver's _START callbacks */
1601   if (machine->config->machine_start != NULL) (*machine->config->machine_start)(machine);
1602   if (machine->config->sound_start != NULL) (*machine->config->sound_start)(machine);
1603   if (machine->config->video_start != NULL) (*machine->config->video_start)(machine);
1599   if (machine->config->machine_start != NULL)
1600      (*machine->config->machine_start)(machine);
1601   if (machine->config->sound_start != NULL)
1602      (*machine->config->sound_start)(machine);
1603   if (machine->config->video_start != NULL)
1604      (*machine->config->video_start)(machine);
16041605
16051606   /* free memory regions allocated with REGIONFLAG_DISPOSE (typically gfx roms) */
16061607   for (num = 0; num < MAX_MEMORY_REGIONS; num++)
r2724r2725
18951896}
18961897
18971898
1898
18991899/*-------------------------------------------------
19001900    fill_systime - fills out a mame_system_time
19011901    structure
r2724r2725
19091909}
19101910
19111911
1912
19131912/*-------------------------------------------------
19141913    mame_get_base_datetime - retrieve the time of
19151914    the host system; useful for RTC implementations
r2724r2725
19221921}
19231922
19241923
1925
19261924/*-------------------------------------------------
19271925    mame_get_current_datetime - retrieve the current
19281926    time (offsetted by the baes); useful for RTC
src/emu/inptport.c
r2724r2725
130130    TYPE DEFINITIONS
131131***************************************************************************/
132132
133typedef struct _analog_port_info analog_port_info;
134struct _analog_port_info
133/* live analog field information */
134typedef struct _analog_field_state analog_field_state;
135struct _analog_field_state
135136{
136   analog_port_info *   next;            /* linked list */
137   input_port_entry *   portentry;         /* pointer to the input port entry referenced */
138   INT32            accum;            /* accumulated value (including relative adjustments) */
139   INT32            previous;         /* previous adjusted value */
140   INT32            previousanalog;      /* previous analog value */
141   INT32            minimum;         /* minimum adjusted value */
142   INT32            maximum;         /* maximum adjusted value */
143   INT32            center;            /* center adjusted value for autocentering */
144   INT32            reverse_val;      /* value where we subtract from to reverse directions */
145   INT64            scalepos;         /* scale factor to apply to positive adjusted values */
146   INT64            scaleneg;         /* scale factor to apply to negative adjusted values */
147   INT64            keyscalepos;      /* scale factor to apply to the key delta field when pos */
148   INT64            keyscaleneg;      /* scale factor to apply to the key delta field when neg */
149   INT64            positionalscale;   /* scale factor to divide a joystick into positions */
150   UINT8            shift;            /* left shift to apply to the final result */
151   UINT8            bits;            /* how many bits of resolution are expected? */
152   UINT8            absolute;         /* is this an absolute or relative input? */
153   UINT8            wraps;            /* does the control wrap around? */
154   UINT8            one_of_x;         /* is this a 1 of X positional input? */
155   UINT8            autocenter;         /* autocenter this input? */
156   UINT8            single_scale;      /* scale joystick differently if default is between min/max */
157   UINT8            interpolate;      /* should we do linear interpolation for mid-frame reads? */
158   UINT8            lastdigital;      /* was the last modification caused by a digital form? */
137   analog_field_state *      next;            /* link to the next analog state for this port */
138   const input_field_config *   field;            /* pointer to the input field referenced */
139
140   /* adjusted values (right-justified and tweaked) */
141   UINT8                  shift;            /* shift to align final value in the port */
142   INT32                  adjdefvalue;      /* adjusted default value from the config */
143   INT32                  adjmin;            /* adjusted minimum value from the config */
144   INT32                  adjmax;            /* adjusted maximum value from the config */
145
146   /* live values of configurable parameters */
147   INT32                  sensitivity;      /* current live sensitivity (100=normal) */
148   UINT8                  reverse;         /* current live reverse flag */
149   INT32                  delta;            /* current live delta to apply each frame a digital inc/dec key is pressed */
150   INT32                  centerdelta;      /* current live delta to apply each frame no digital inputs are pressed */
151
152   /* live analog value tracking */
153   INT32                  accum;            /* accumulated value (including relative adjustments) */
154   INT32                  previous;         /* previous adjusted value */
155   INT32                  previousanalog;      /* previous analog value */
156
157   /* parameters for modifying live values */
158   INT32                  minimum;         /* minimum adjusted value */
159   INT32                  maximum;         /* maximum adjusted value */
160   INT32                  center;            /* center adjusted value for autocentering */
161   INT32                  reverse_val;      /* value where we subtract from to reverse directions */
162
163   /* scaling factors */
164   INT64                  scalepos;         /* scale factor to apply to positive adjusted values */
165   INT64                  scaleneg;         /* scale factor to apply to negative adjusted values */
166   INT64                  keyscalepos;      /* scale factor to apply to the key delta field when pos */
167   INT64                  keyscaleneg;      /* scale factor to apply to the key delta field when neg */
168   INT64                  positionalscale;   /* scale factor to divide a joystick into positions */
169
170   /* misc flags */
171   UINT8                  absolute;         /* is this an absolute or relative input? */
172   UINT8                  wraps;            /* does the control wrap around? */
173   UINT8                  autocenter;         /* autocenter this input? */
174   UINT8                  single_scale;      /* scale joystick differently if default is between min/max */
175   UINT8                  interpolate;      /* should we do linear interpolation for mid-frame reads? */
176   UINT8                  lastdigital;      /* was the last modification caused by a digital form? */
159177};
160178
161179
162typedef struct _custom_port_info custom_port_info;
163struct _custom_port_info
180/* shared digital joystick state */
181typedef struct _digital_joystick_state digital_joystick_state;
182struct _digital_joystick_state
164183{
165   custom_port_info *   next;            /* linked list */
166   input_port_entry *   portentry;         /* pointer to the input port entry referenced */
167   UINT8            shift;            /* left shift to apply to the final result */
184   const input_field_config *   field[4];         /* input field for up, down, left, right respectively */
185   UINT8                  inuse;            /* is this joystick used? */
186   UINT8                  current;         /* current value */
187   UINT8                  current4way;      /* current 4-way value */
188   UINT8                  previous;         /* previous value */
168189};
169190
170191
171typedef struct _changed_port_info changed_port_info;
172struct _changed_port_info
192/* live custom/changed field information */
193typedef struct _callback_field_info callback_field_info;
194struct _callback_field_info
173195{
174   changed_port_info *   next;            /* linked list */
175   input_port_entry *   portentry;         /* pointer to the input port entry referenced */
176   UINT8            shift;            /* right shift to apply before calling callback */
196   callback_field_info *      next;            /* linked list of info for this port */
197   const input_field_config *   field;            /* pointer to the input field referenced */
198   UINT8                  shift;            /* shift to apply to the final result */
177199};
178200
179201
180typedef struct _input_bit_info input_bit_info;
181struct _input_bit_info
202/* internal live state of an input field */
203struct _input_field_state
182204{
183   input_port_entry *   portentry;         /* port entry for this input */
184   UINT8            impulse;         /* counter for impulse controls */
185   UINT8            last;            /* were we pressed last time? */
205   analog_field_state *      analog;            /* pointer to live analog data if this is an analog field */
206   digital_joystick_state *   joystick;         /* pointer to digital joystick information */
207   input_seq               seq[SEQ_TYPE_TOTAL];/* currently configured input sequences */
208   input_port_value         value;            /* current value of this port */
209   UINT8                  impulse;         /* counter for impulse controls */
210   UINT8                  last;            /* were we pressed last time? */
211   UINT8                  toggle;            /* current toggle state */
212   UINT8                  joydir;            /* digital joystick direction index */
186213};
187214
188215
189typedef struct _input_port_info input_port_info;
190struct _input_port_info
216/* internal live state of an input port */
217struct _input_port_state
191218{
192   const char *      tag;            /* tag for this port */
193   UINT32            defvalue;         /* default value of all the bits */
194   UINT32            digital;         /* value from digital inputs */
195   UINT32            vblank;            /* value of all IPT_VBLANK bits */
196   input_bit_info       bit[MAX_BITS_PER_PORT]; /* info about each bit in the port */
197   analog_port_info *   analoginfo;         /* pointer to linked list of analog port info */
198   custom_port_info *   custominfo;         /* pointer to linked list of custom port info */
199   changed_port_info *   changedinfo;      /* pointer to linked list of changed port info */
219   analog_field_state *      analoglist;         /* pointer to list of analog port info */
220   callback_field_info *      customlist;         /* pointer to list of custom port info */
221   callback_field_info *      changedlist;      /* pointer to list of changed port info */
222   input_port_value         defvalue;         /* combined default value across the port */
223   input_port_value         digital;         /* current value from all digital inputs */
224   input_port_value         vblank;            /* value of all IPT_VBLANK bits */
225   input_port_value         lastvalue;         /* last value of the port, to detect changes */
200226};
201227
202228
203typedef struct _digital_joystick_info digital_joystick_info;
204struct _digital_joystick_info
229/* internal live state of an input type */
230typedef struct _input_type_state input_type_state;
231struct _input_type_state
205232{
206   input_port_entry *   portentry[4];      /* port entry for up,down,left,right respectively */
207   UINT8            inuse;            /* is this joystick used? */
208   UINT8            current;         /* current value */
209   UINT8            current4way;      /* current 4-way value */
210   UINT8            previous;         /* previous value */
233   input_type_state *         next;            /* pointer to the next live state in the list */
234   input_type_desc            typedesc;         /* copy of the original description, modified by the OSD */
235   input_seq               seq[SEQ_TYPE_TOTAL];/* currently configured sequences */
211236};
212237
213238
214struct _input_port_init_params
239/* private input port state */
240struct _input_port_private
215241{
216   input_port_entry *   ports;            /* base of the port array */
217   int               max_ports;         /* maximum number of ports we can support */
218   int               current_port;      /* current port index */
242   /* types */
243   input_type_state *         typestatelist;      /* list of live type states */
244   input_type_state *         type_to_typestate[__ipt_max][MAX_PLAYERS]; /* map from type/player to type state */
245
246   /* specific special global input states */
247   digital_joystick_state       joystick_info[MAX_PLAYERS][DIGITAL_JOYSTICKS_PER_PLAYER]; /* joystick states */
248   osd_ticks_t               ui_memory[__ipt_max];/* keypress timing for UI */
249
250   /* frame time tracking */
251   attotime               last_frame_time;   /* time of the last frame callback */
252   attoseconds_t            last_delta_nsec;   /* nanoseconds that passed since the previous callback */
253
254   /* playback/record information */
255   mame_file *               record_file;      /* recording file (NULL if not recording) */
256   mame_file *               playback_file;      /* playback file (NULL if not recording) */
257   UINT64                  playback_accumulated_speed;/* accumulated speed during playback */
258   UINT32                  playback_accumulated_frames;/* accumulated frames during playback */
219259};
220260
221261
r2724r2725
224264    MACROS
225265***************************************************************************/
226266
227#define IS_ANALOG(in)            ((in)->type >= __ipt_analog_start && (in)->type <= __ipt_analog_end)
228#define IS_DIGITAL_JOYSTICK(in)      ((in)->type >= __ipt_digital_joystick_start && (in)->type <= __ipt_digital_joystick_end)
229#define JOYSTICK_INFO_FOR_PORT(in)   (&joystick_info[(in)->player][((in)->type - __ipt_digital_joystick_start) / 4])
230#define JOYSTICK_DIR_FOR_PORT(in)   (((in)->type - __ipt_digital_joystick_start) % 4)
231
232267#define APPLY_SENSITIVITY(x,s)      (((INT64)(x) * (s)) / 100)
233268#define APPLY_INVERSE_SENSITIVITY(x,s) (((INT64)(x) * 100) / (s))
234269
r2724r2725
242277    GLOBAL VARIABLES
243278***************************************************************************/
244279
245/* current value of all the ports */
246static input_port_info port_info[MAX_INPUT_PORTS];
247
248/* additiona tracking information for special types of controls */
249static digital_joystick_info joystick_info[MAX_PLAYERS][DIGITAL_JOYSTICKS_PER_PLAYER];
250
251/* memory for UI keys */
252static UINT8 ui_memory[__ipt_max];
253
254280/* XML attributes for the different types */
255281static const char *const seqtypestrings[] = { "standard", "decrement", "increment" };
256282
257/* original input_ports without modifications */
258static input_port_entry *input_ports_default;
259283
260/* for scaling analog ports */
261static attotime last_update;
262static attoseconds_t last_delta;
263284
264/* playback information */
265static UINT64 playback_accumulated_speed;
266static UINT32 playback_accumulated_frames;
267
268
269
270285/***************************************************************************
271286    PORT HANDLER TABLES
272287***************************************************************************/
r2724r2725
434449
435450
436451/***************************************************************************
437    DEFAULT INPUT PORTS
452    BUILT-IN CORE MAPPINGS
438453***************************************************************************/
439454
440#define INPUT_PORT_DIGITAL_DEF(player_,group_,type_,name_,seq_) \
441   { IPT_##type_, group_, (player_ == 0) ? player_ : (player_) - 1, (player_ == 0) ? #type_ : ("P" #player_ "_" #type_), name_, seq_, SEQ_DEF_0, SEQ_DEF_0 },
455#include "inpttype.h"
442456
443#define INPUT_PORT_ANALOG_DEF(player_,group_,type_,name_,seq_,decseq_,incseq_) \
444   { IPT_##type_, group_, (player_ == 0) ? player_ : (player_) - 1, (player_ == 0) ? #type_ : ("P" #player_ "_" #type_), name_, seq_, incseq_, decseq_ },
445457
446#define INDEXED(a,b)   INPUT_CODE_SET_DEVINDEX(a,b)
447458
448static const input_port_default_entry default_ports_builtin[] =
459/***************************************************************************
460    FUNCTION PROTOTYPES
461***************************************************************************/
462
463/* core system management */
464static void input_port_exit(running_machine *machine);
465
466/* port reading */
467static INT32 apply_analog_settings(INT32 current, analog_field_state *analog);
468
469/* initialization helpers */
470static void init_port_types(running_machine *machine);
471static void init_port_state(running_machine *machine);
472static void init_autoselect_devices(const input_port_config *portlist, int type1, int type2, int type3, const char *option, const char *ananame);
473static callback_field_info *init_field_callback_info(const input_field_config *field);
474static analog_field_state *init_field_analog_state(const input_field_config *field);
475
476/* once-per-frame updates */
477static void frame_update_callback(running_machine *machine);
478static void frame_update(running_machine *machine);
479static void frame_update_digital_joysticks(running_machine *machine);
480static void frame_update_analog_field(analog_field_state *analog);
481static int frame_get_digital_field_state(const input_field_config *field);
482
483/* port configuration helpers */
484static input_port_config *port_config_detokenize(input_port_config *listhead, const input_port_token *ipt);
485static input_port_config *port_config_alloc(const input_port_config **listhead);
486static void port_config_free(const input_port_config **portptr);
487static input_port_config *port_config_find(const input_port_config *listhead, const char *tag);
488static input_field_config *field_config_alloc(input_port_config *port, int type, input_port_value defvalue, input_port_value maskbits);
489static void field_config_free(input_field_config **fieldptr);
490static input_setting_config *setting_config_alloc(input_field_config *field, input_port_value value, const char *name);
491static void setting_config_free(input_setting_config **settingptr);
492static const input_field_diplocation *diplocation_list_alloc(const input_field_config *field, const char *location);
493static void diplocation_free(input_field_diplocation **diplocptr);
494
495/* tokenization helpers */
496static int token_to_input_field_type(running_machine *machine, const char *string, int *player);
497static const char *input_field_type_to_token(running_machine *machine, int type, int player);
498static int token_to_seq_type(const char *string);
499
500/* settings load */
501static void load_config_callback(running_machine *machine, int config_type, xml_data_node *parentnode);
502static void load_remap_table(running_machine *machine, xml_data_node *parentnode);
503static int load_default_config(running_machine *machine, xml_data_node *portnode, int type, int player, const input_seq *newseq);
504static int load_game_config(running_machine *machine, xml_data_node *portnode, int type, int player, const input_seq *newseq);
505
506/* settings save */
507static void save_config_callback(running_machine *machine, int config_type, xml_data_node *parentnode);
508static void save_sequence(xml_data_node *parentnode, int type, int porttype, const input_seq *seq);
509static int save_this_input_field_type(int type);
510static void save_default_inputs(running_machine *machine, xml_data_node *parentnode);
511static void save_game_inputs(running_machine *machine, xml_data_node *parentnode);
512
513/* input playback */
514static time_t playback_init(running_machine *machine);
515static void playback_end(running_machine *machine, const char *message);
516static void playback_frame(running_machine *machine, attotime curtime);
517static void playback_port(const input_port_config *port);
518
519/* input recording */
520static void record_init(running_machine *machine);
521static void record_end(running_machine *machine, const char *message);
522static void record_frame(running_machine *machine, attotime curtime);
523static void record_port(const input_port_config *port);
524
525
526
527/***************************************************************************
528    INLINE FUNCTIONS
529***************************************************************************/
530
531/*-------------------------------------------------
532    apply_analog_min_max - clamp the given input
533    value to the appropriate min/max for the
534    analog control
535-------------------------------------------------*/
536
537INLINE INT32 apply_analog_min_max(const analog_field_state *analog, INT32 value)
449538{
450   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   JOYSTICK_UP,      "P1 Up",            SEQ_DEF_3(KEYCODE_UP, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)) )
451   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   JOYSTICK_DOWN,      "P1 Down",            SEQ_DEF_3(KEYCODE_DOWN, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
452   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   JOYSTICK_LEFT,      "P1 Left",             SEQ_DEF_3(KEYCODE_LEFT, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)) )
453   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   JOYSTICK_RIGHT,     "P1 Right",            SEQ_DEF_3(KEYCODE_RIGHT, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
454   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   JOYSTICKRIGHT_UP,   "P1 Right/Up",         SEQ_DEF_3(KEYCODE_I, SEQCODE_OR, INDEXED(JOYCODE_BUTTON2, 0)) )
455   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   JOYSTICKRIGHT_DOWN, "P1 Right/Down",      SEQ_DEF_3(KEYCODE_K, SEQCODE_OR, INDEXED(JOYCODE_BUTTON3, 0)) )
456   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   JOYSTICKRIGHT_LEFT, "P1 Right/Left",      SEQ_DEF_3(KEYCODE_J, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 0)) )
457   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   JOYSTICKRIGHT_RIGHT,"P1 Right/Right",      SEQ_DEF_3(KEYCODE_L, SEQCODE_OR, INDEXED(JOYCODE_BUTTON4, 0)) )
458   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   JOYSTICKLEFT_UP,    "P1 Left/Up",          SEQ_DEF_3(KEYCODE_E, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)) )
459   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   JOYSTICKLEFT_DOWN,  "P1 Left/Down",         SEQ_DEF_3(KEYCODE_D, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
460   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   JOYSTICKLEFT_LEFT,  "P1 Left/Left",       SEQ_DEF_3(KEYCODE_S, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)) )
461   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   JOYSTICKLEFT_RIGHT, "P1 Left/Right",      SEQ_DEF_3(KEYCODE_F, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
462   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   BUTTON1,         "P1 Button 1",         SEQ_DEF_7(KEYCODE_LCONTROL, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 0), SEQCODE_OR, INDEXED(MOUSECODE_BUTTON1, 0), SEQCODE_OR, INDEXED(GUNCODE_BUTTON1, 0)) )
463   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   BUTTON2,         "P1 Button 2",         SEQ_DEF_7(KEYCODE_LALT, SEQCODE_OR, INDEXED(JOYCODE_BUTTON2, 0), SEQCODE_OR, INDEXED(MOUSECODE_BUTTON3, 0), SEQCODE_OR, INDEXED(GUNCODE_BUTTON2, 0)) )
464   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   BUTTON3,         "P1 Button 3",         SEQ_DEF_5(KEYCODE_SPACE, SEQCODE_OR, INDEXED(JOYCODE_BUTTON3, 0), SEQCODE_OR, INDEXED(MOUSECODE_BUTTON2, 0)) )
465   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   BUTTON4,         "P1 Button 4",         SEQ_DEF_3(KEYCODE_LSHIFT, SEQCODE_OR, INDEXED(JOYCODE_BUTTON4, 0)) )
466   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   BUTTON5,         "P1 Button 5",         SEQ_DEF_3(KEYCODE_Z, SEQCODE_OR, INDEXED(JOYCODE_BUTTON5, 0)) )
467   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   BUTTON6,         "P1 Button 6",         SEQ_DEF_3(KEYCODE_X, SEQCODE_OR, INDEXED(JOYCODE_BUTTON6, 0)) )
468   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   BUTTON7,         "P1 Button 7",         SEQ_DEF_3(KEYCODE_C, SEQCODE_OR, INDEXED(JOYCODE_BUTTON7, 0)) )
469   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   BUTTON8,         "P1 Button 8",         SEQ_DEF_3(KEYCODE_V, SEQCODE_OR, INDEXED(JOYCODE_BUTTON8, 0)) )
470   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   BUTTON9,         "P1 Button 9",         SEQ_DEF_3(KEYCODE_B, SEQCODE_OR, INDEXED(JOYCODE_BUTTON9, 0)) )
471   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   BUTTON10,         "P1 Button 10",         SEQ_DEF_3(KEYCODE_N, SEQCODE_OR, INDEXED(JOYCODE_BUTTON10, 0)) )
472   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   BUTTON11,         "P1 Button 11",         SEQ_DEF_3(KEYCODE_M, SEQCODE_OR, INDEXED(JOYCODE_BUTTON11, 0)) )
473   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   BUTTON12,         "P1 Button 12",         SEQ_DEF_3(KEYCODE_COMMA, SEQCODE_OR, INDEXED(JOYCODE_BUTTON12, 0)) )
474   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   BUTTON13,         "P1 Button 13",         SEQ_DEF_3(KEYCODE_STOP, SEQCODE_OR, INDEXED(JOYCODE_BUTTON13, 0)) )
475   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   BUTTON14,         "P1 Button 14",         SEQ_DEF_3(KEYCODE_SLASH, SEQCODE_OR, INDEXED(JOYCODE_BUTTON14, 0)) )
476   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   BUTTON15,         "P1 Button 15",         SEQ_DEF_3(KEYCODE_RSHIFT, SEQCODE_OR, INDEXED(JOYCODE_BUTTON15, 0)) )
477   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   BUTTON16,         "P1 Button 16",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON16, 0)) )
478   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1, START,            "P1 Start",            SEQ_DEF_3(KEYCODE_1, SEQCODE_OR, INDEXED(JOYCODE_START, 0)) )
479   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1, SELECT,            "P1 Select",         SEQ_DEF_3(KEYCODE_5, SEQCODE_OR, INDEXED(JOYCODE_SELECT, 0)) )
480   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_A,          "P1 Mahjong A",         SEQ_DEF_1(KEYCODE_A) )
481   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_B,          "P1 Mahjong B",         SEQ_DEF_1(KEYCODE_B) )
482   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_C,          "P1 Mahjong C",         SEQ_DEF_1(KEYCODE_C) )
483   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_D,          "P1 Mahjong D",         SEQ_DEF_1(KEYCODE_D) )
484   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_E,          "P1 Mahjong E",         SEQ_DEF_1(KEYCODE_E) )
485   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_F,          "P1 Mahjong F",         SEQ_DEF_1(KEYCODE_F) )
486   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_G,          "P1 Mahjong G",         SEQ_DEF_1(KEYCODE_G) )
487   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_H,          "P1 Mahjong H",         SEQ_DEF_1(KEYCODE_H) )
488   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_I,          "P1 Mahjong I",         SEQ_DEF_1(KEYCODE_I) )
489   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_J,          "P1 Mahjong J",         SEQ_DEF_1(KEYCODE_J) )
490   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_K,          "P1 Mahjong K",         SEQ_DEF_1(KEYCODE_K) )
491   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_L,          "P1 Mahjong L",         SEQ_DEF_1(KEYCODE_L) )
492   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_M,          "P1 Mahjong M",         SEQ_DEF_1(KEYCODE_M) )
493   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_N,          "P1 Mahjong N",         SEQ_DEF_1(KEYCODE_N) )
494   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_O,          "P1 Mahjong O",         SEQ_DEF_1(KEYCODE_O) )
495   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_P,          "P1 Mahjong P",         SEQ_DEF_1(KEYCODE_COLON) )
496   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_Q,          "P1 Mahjong Q",         SEQ_DEF_1(KEYCODE_Q) )
497   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_KAN,        "P1 Mahjong Kan",      SEQ_DEF_1(KEYCODE_LCONTROL) )
498   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_PON,        "P1 Mahjong Pon",      SEQ_DEF_1(KEYCODE_LALT) )
499   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_CHI,        "P1 Mahjong Chi",      SEQ_DEF_1(KEYCODE_SPACE) )
500   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_REACH,      "P1 Mahjong Reach",      SEQ_DEF_1(KEYCODE_LSHIFT) )
501   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_RON,        "P1 Mahjong Ron",      SEQ_DEF_1(KEYCODE_Z) )
502   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_BET,        "P1 Mahjong Bet",      SEQ_DEF_1(KEYCODE_2) )
503   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_LAST_CHANCE,"P1 Mahjong Last Chance",SEQ_DEF_1(KEYCODE_RALT) )
504   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_SCORE,      "P1 Mahjong Score",      SEQ_DEF_1(KEYCODE_RCONTROL) )
505   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_DOUBLE_UP,  "P1 Mahjong Double Up",   SEQ_DEF_1(KEYCODE_RSHIFT) )
506   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_FLIP_FLOP,  "P1 Mahjong Flip Flop",   SEQ_DEF_1(KEYCODE_Y) )
507   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_BIG,        "P1 Mahjong Big",       SEQ_DEF_1(KEYCODE_ENTER) )
508   INPUT_PORT_DIGITAL_DEF( 1, IPG_PLAYER1,   MAHJONG_SMALL,      "P1 Mahjong Small",     SEQ_DEF_1(KEYCODE_BACKSPACE) )
539   /* take the analog minimum and maximum values and apply the inverse of the */
540   /* sensitivity so that we can clamp against them before applying sensitivity */
541   INT32 adjmin = APPLY_INVERSE_SENSITIVITY(analog->minimum, analog->sensitivity);
542   INT32 adjmax = APPLY_INVERSE_SENSITIVITY(analog->maximum, analog->sensitivity);
509543
510   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   JOYSTICK_UP,      "P2 Up",            SEQ_DEF_3(KEYCODE_R, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 1)) )
511   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   JOYSTICK_DOWN,      "P2 Down",             SEQ_DEF_3(KEYCODE_F, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 1)) )
512   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   JOYSTICK_LEFT,      "P2 Left",             SEQ_DEF_3(KEYCODE_D, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 1)) )
513   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   JOYSTICK_RIGHT,     "P2 Right",            SEQ_DEF_3(KEYCODE_G, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 1)) )
514   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   JOYSTICKRIGHT_UP,   "P2 Right/Up",         SEQ_DEF_0 )
515   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   JOYSTICKRIGHT_DOWN, "P2 Right/Down",      SEQ_DEF_0 )
516   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   JOYSTICKRIGHT_LEFT, "P2 Right/Left",      SEQ_DEF_0 )
517   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   JOYSTICKRIGHT_RIGHT,"P2 Right/Right",      SEQ_DEF_0 )
518   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   JOYSTICKLEFT_UP,    "P2 Left/Up",          SEQ_DEF_0 )
519   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   JOYSTICKLEFT_DOWN,  "P2 Left/Down",         SEQ_DEF_0 )
520   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   JOYSTICKLEFT_LEFT,  "P2 Left/Left",         SEQ_DEF_0 )
521   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   JOYSTICKLEFT_RIGHT, "P2 Left/Right",      SEQ_DEF_0 )
522   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   BUTTON1,         "P2 Button 1",         SEQ_DEF_7(KEYCODE_A, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 1), SEQCODE_OR, INDEXED(MOUSECODE_BUTTON1, 1), SEQCODE_OR, INDEXED(GUNCODE_BUTTON1, 1)) )
523   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   BUTTON2,         "P2 Button 2",         SEQ_DEF_7(KEYCODE_S, SEQCODE_OR, INDEXED(JOYCODE_BUTTON2, 1), SEQCODE_OR, INDEXED(MOUSECODE_BUTTON3, 1), SEQCODE_OR, INDEXED(GUNCODE_BUTTON2, 1)) )
524   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   BUTTON3,         "P2 Button 3",         SEQ_DEF_5(KEYCODE_Q, SEQCODE_OR, INDEXED(JOYCODE_BUTTON3, 1), SEQCODE_OR, INDEXED(MOUSECODE_BUTTON2, 1)) )
525   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   BUTTON4,         "P2 Button 4",         SEQ_DEF_3(KEYCODE_W, SEQCODE_OR, INDEXED(JOYCODE_BUTTON4, 1)) )
526   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   BUTTON5,         "P2 Button 5",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON5, 1)) )
527   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   BUTTON6,         "P2 Button 6",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON6, 1)) )
528   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   BUTTON7,         "P2 Button 7",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON7, 1)) )
529   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   BUTTON8,         "P2 Button 8",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON8, 1)) )
530   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   BUTTON9,         "P2 Button 9",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON9, 1)) )
531   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   BUTTON10,         "P2 Button 10",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON10, 1)) )
532   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   BUTTON11,         "P2 Button 11",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON11, 1)) )
533   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   BUTTON12,         "P2 Button 12",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON12, 1)) )
534   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   BUTTON13,         "P2 Button 13",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON13, 1)) )
535   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   BUTTON14,         "P2 Button 14",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON14, 1)) )
536   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   BUTTON15,         "P2 Button 15",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON15, 1)) )
537   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   BUTTON16,         "P2 Button 16",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON16, 1)) )
538   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2, START,            "P2 Start",            SEQ_DEF_3(KEYCODE_2, SEQCODE_OR, INDEXED(JOYCODE_START, 1)) )
539   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2, SELECT,            "P2 Select",         SEQ_DEF_3(KEYCODE_6, SEQCODE_OR, INDEXED(JOYCODE_SELECT, 1)) )
540   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_A,          "P2 Mahjong A",         SEQ_DEF_0 )
541   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_B,          "P2 Mahjong B",         SEQ_DEF_0 )
542   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_C,          "P2 Mahjong C",         SEQ_DEF_0 )
543   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_D,          "P2 Mahjong D",         SEQ_DEF_0 )
544   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_E,          "P2 Mahjong E",         SEQ_DEF_0 )
545   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_F,          "P2 Mahjong F",         SEQ_DEF_0 )
546   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_G,          "P2 Mahjong G",         SEQ_DEF_0 )
547   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_H,          "P2 Mahjong H",         SEQ_DEF_0 )
548   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_I,          "P2 Mahjong I",         SEQ_DEF_0 )
549   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_J,          "P2 Mahjong J",         SEQ_DEF_0 )
550   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_K,          "P2 Mahjong K",         SEQ_DEF_0 )
551   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_L,          "P2 Mahjong L",         SEQ_DEF_0 )
552   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_M,          "P2 Mahjong M",         SEQ_DEF_0 )
553   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_N,          "P2 Mahjong N",         SEQ_DEF_0 )
554   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_O,          "P2 Mahjong O",         SEQ_DEF_0 )
555   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_P,          "P2 Mahjong P",         SEQ_DEF_0 )
556   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_Q,          "P2 Mahjong Q",         SEQ_DEF_0 )
557   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_KAN,        "P2 Mahjong Kan",      SEQ_DEF_0 )
558   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_PON,        "P2 Mahjong Pon",      SEQ_DEF_0 )
559   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_CHI,        "P2 Mahjong Chi",      SEQ_DEF_0 )
560   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_REACH,      "P2 Mahjong Reach",      SEQ_DEF_0 )
561   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_RON,        "P2 Mahjong Ron",      SEQ_DEF_0 )
562   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_BET,        "P2 Mahjong Bet",      SEQ_DEF_0 )
563   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_LAST_CHANCE,"P2 Mahjong Last Chance",SEQ_DEF_0 )
564   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_SCORE,      "P2 Mahjong Score",      SEQ_DEF_0 )
565   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_DOUBLE_UP,  "P2 Mahjong Double Up",   SEQ_DEF_0 )
566   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_FLIP_FLOP,  "P2 Mahjong Flip Flop",   SEQ_DEF_0 )
567   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_BIG,        "P2 Mahjong Big",       SEQ_DEF_0 )
568   INPUT_PORT_DIGITAL_DEF( 2, IPG_PLAYER2,   MAHJONG_SMALL,      "P2 Mahjong Small",     SEQ_DEF_0 )
544   /* for absolute devices, clamp to the bounds absolutely */
545   if (!analog->wraps)
546   {
547      if (value > adjmax)
548         value = adjmax;
549      else if (value < adjmin)
550         value = adjmin;
551   }
569552
570   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   JOYSTICK_UP,      "P3 Up",            SEQ_DEF_3(KEYCODE_I, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 2)) )
571   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   JOYSTICK_DOWN,      "P3 Down",             SEQ_DEF_3(KEYCODE_K, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 2)) )
572   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   JOYSTICK_LEFT,      "P3 Left",             SEQ_DEF_3(KEYCODE_J, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 2)) )
573   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   JOYSTICK_RIGHT,     "P3 Right",            SEQ_DEF_3(KEYCODE_L, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 2)) )
574   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   JOYSTICKRIGHT_UP,   "P3 Right/Up",         SEQ_DEF_0 )
575   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   JOYSTICKRIGHT_DOWN, "P3 Right/Down",      SEQ_DEF_0 )
576   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   JOYSTICKRIGHT_LEFT, "P3 Right/Left",      SEQ_DEF_0 )
577   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   JOYSTICKRIGHT_RIGHT,"P3 Right/Right",      SEQ_DEF_0 )
578   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   JOYSTICKLEFT_UP,    "P3 Left/Up",          SEQ_DEF_0 )
579   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   JOYSTICKLEFT_DOWN,  "P3 Left/Down",         SEQ_DEF_0 )
580   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   JOYSTICKLEFT_LEFT,  "P3 Left/Left",         SEQ_DEF_0 )
581   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   JOYSTICKLEFT_RIGHT, "P3 Left/Right",      SEQ_DEF_0 )
582   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   BUTTON1,         "P3 Button 1",         SEQ_DEF_5(KEYCODE_RCONTROL, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 2), SEQCODE_OR, INDEXED(GUNCODE_BUTTON1, 2)) )
583   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   BUTTON2,         "P3 Button 2",         SEQ_DEF_5(KEYCODE_RSHIFT, SEQCODE_OR, INDEXED(JOYCODE_BUTTON2, 2), SEQCODE_OR, INDEXED(GUNCODE_BUTTON2, 2)) )
584   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   BUTTON3,         "P3 Button 3",         SEQ_DEF_3(KEYCODE_ENTER, SEQCODE_OR, INDEXED(JOYCODE_BUTTON3, 2)) )
585   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   BUTTON4,         "P3 Button 4",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON4, 2)) )
586   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   BUTTON5,         "P3 Button 5",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON5, 2)) )
587   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   BUTTON6,         "P3 Button 6",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON6, 2)) )
588   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   BUTTON7,         "P3 Button 7",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON7, 2)) )
589   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   BUTTON8,         "P3 Button 8",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON8, 2)) )
590   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   BUTTON9,         "P3 Button 9",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON9, 2)) )
591   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   BUTTON10,         "P3 Button 10",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON10, 2)) )
592   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   BUTTON11,         "P3 Button 11",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON11, 2)) )
593   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   BUTTON12,         "P3 Button 12",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON12, 2)) )
594   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   BUTTON13,         "P3 Button 13",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON13, 2)) )
595   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   BUTTON14,         "P3 Button 14",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON14, 2)) )
596   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   BUTTON15,         "P3 Button 15",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON15, 2)) )
597   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3,   BUTTON16,         "P3 Button 16",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON16, 2)) )
598   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3, START,            "P3 Start",            SEQ_DEF_3(KEYCODE_3, SEQCODE_OR, INDEXED(JOYCODE_START, 2)) )
599   INPUT_PORT_DIGITAL_DEF( 3, IPG_PLAYER3, SELECT,            "P3 Select",         SEQ_DEF_3(KEYCODE_7, SEQCODE_OR, INDEXED(JOYCODE_SELECT, 2)) )
553   /* for relative devices, wrap around when we go past the edge */
554   else
555   {
556      INT32 adj1 = APPLY_INVERSE_SENSITIVITY(512, analog->sensitivity);
557      INT32 adjdif = adjmax - adjmin + adj1;
600558
601   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   JOYSTICK_UP,      "P4 Up",            SEQ_DEF_3(KEYCODE_8_PAD, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 3)) )
602   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   JOYSTICK_DOWN,      "P4 Down",             SEQ_DEF_3(KEYCODE_2_PAD, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 3)) )
603   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   JOYSTICK_LEFT,      "P4 Left",             SEQ_DEF_3(KEYCODE_4_PAD, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 3)) )
604   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   JOYSTICK_RIGHT,     "P4 Right",            SEQ_DEF_3(KEYCODE_6_PAD, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 3)) )
605   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   JOYSTICKRIGHT_UP,   "P4 Right/Up",         SEQ_DEF_0 )
606   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   JOYSTICKRIGHT_DOWN, "P4 Right/Down",      SEQ_DEF_0 )
607   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   JOYSTICKRIGHT_LEFT, "P4 Right/Left",      SEQ_DEF_0 )
608   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   JOYSTICKRIGHT_RIGHT,"P4 Right/Right",      SEQ_DEF_0 )
609   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   JOYSTICKLEFT_UP,    "P4 Left/Up",          SEQ_DEF_0 )
610   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   JOYSTICKLEFT_DOWN,  "P4 Left/Down",         SEQ_DEF_0 )
611   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   JOYSTICKLEFT_LEFT,  "P4 Left/Left",         SEQ_DEF_0 )
612   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   JOYSTICKLEFT_RIGHT, "P4 Left/Right",      SEQ_DEF_0 )
613   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   BUTTON1,         "P4 Button 1",         SEQ_DEF_3(KEYCODE_0_PAD, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 3)) )
614   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   BUTTON2,         "P4 Button 2",         SEQ_DEF_3(KEYCODE_DEL_PAD, SEQCODE_OR, INDEXED(JOYCODE_BUTTON2, 3)) )
615   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   BUTTON3,         "P4 Button 3",         SEQ_DEF_3(KEYCODE_ENTER_PAD, SEQCODE_OR, INDEXED(JOYCODE_BUTTON3, 3)) )
616   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   BUTTON4,         "P4 Button 4",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON4, 3)) )
617   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   BUTTON5,         "P4 Button 5",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON5, 3)) )
618   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   BUTTON6,         "P4 Button 6",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON6, 3)) )
619   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   BUTTON7,         "P4 Button 7",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON7, 3)) )
620   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   BUTTON8,         "P4 Button 8",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON8, 3)) )
621   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   BUTTON9,         "P4 Button 9",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON9, 3)) )
622   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   BUTTON10,         "P4 Button 10",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON10, 3)) )
623   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   BUTTON11,         "P4 Button 11",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON11, 3)) )
624   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   BUTTON12,         "P4 Button 12",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON12, 3)) )
625   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   BUTTON13,         "P4 Button 13",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON13, 3)) )
626   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   BUTTON14,         "P4 Button 14",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON14, 3)) )
627   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   BUTTON15,         "P4 Button 15",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON15, 3)) )
628   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4,   BUTTON16,         "P4 Button 16",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON16, 3)) )
629   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4, START,            "P4 Start",            SEQ_DEF_3(KEYCODE_4, SEQCODE_OR, INDEXED(JOYCODE_START, 3)) )
630   INPUT_PORT_DIGITAL_DEF( 4, IPG_PLAYER4, SELECT,            "P4 Select",         SEQ_DEF_3(KEYCODE_8, SEQCODE_OR, INDEXED(JOYCODE_SELECT, 3)) )
559      if (analog->reverse)
560      {
561         while (value <= adjmin - adj1)
562            value += adjdif;
563         while (value > adjmax)
564            value -= adjdif;
565      }
566      else
567      {
568         while (value >= adjmax + adj1)
569            value -= adjdif;
570         while (value < adjmin)
571            value += adjdif;
572      }
573   }
631574
632   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   JOYSTICK_UP,      "P5 Up",            SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 4)) )
633   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   JOYSTICK_DOWN,      "P5 Down",             SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 4)) )
634   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   JOYSTICK_LEFT,      "P5 Left",             SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 4)) )
635   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   JOYSTICK_RIGHT,     "P5 Right",            SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 4)) )
636   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   JOYSTICKRIGHT_UP,   "P5 Right/Up",         SEQ_DEF_0 )
637   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   JOYSTICKRIGHT_DOWN, "P5 Right/Down",      SEQ_DEF_0 )
638   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   JOYSTICKRIGHT_LEFT, "P5 Right/Left",      SEQ_DEF_0 )
639   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   JOYSTICKRIGHT_RIGHT,"P5 Right/Right",      SEQ_DEF_0 )
640   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   JOYSTICKLEFT_UP,    "P5 Left/Up",          SEQ_DEF_0 )
641   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   JOYSTICKLEFT_DOWN,  "P5 Left/Down",         SEQ_DEF_0 )
642   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   JOYSTICKLEFT_LEFT,  "P5 Left/Left",         SEQ_DEF_0 )
643   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   JOYSTICKLEFT_RIGHT, "P5 Left/Right",      SEQ_DEF_0 )
644   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   BUTTON1,         "P5 Button 1",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON1, 4)) )
645   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   BUTTON2,         "P5 Button 2",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON2, 4)) )
646   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   BUTTON3,         "P5 Button 3",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON3, 4)) )
647   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   BUTTON4,         "P5 Button 4",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON4, 4)) )
648   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   BUTTON5,         "P5 Button 5",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON5, 4)) )
649   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   BUTTON6,         "P5 Button 6",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON6, 4)) )
650   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   BUTTON7,         "P5 Button 7",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON7, 4)) )
651   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   BUTTON8,         "P5 Button 8",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON8, 4)) )
652   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   BUTTON9,         "P5 Button 9",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON9, 4)) )
653   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   BUTTON10,         "P5 Button 10",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON10, 4)) )
654   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   BUTTON11,         "P5 Button 11",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON11, 4)) )
655   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   BUTTON12,         "P5 Button 12",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON12, 4)) )
656   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   BUTTON13,         "P5 Button 13",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON13, 4)) )
657   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   BUTTON14,         "P5 Button 14",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON14, 4)) )
658   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   BUTTON15,         "P5 Button 15",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON15, 4)) )
659   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5,   BUTTON16,         "P5 Button 16",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON16, 4)) )
660   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5, START,            "P5 Start",            SEQ_DEF_0 )
661   INPUT_PORT_DIGITAL_DEF( 5, IPG_PLAYER5, SELECT,            "P5 Select",         SEQ_DEF_0 )
575   return value;
576}
662577
663   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   JOYSTICK_UP,      "P6 Up",            SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 5)) )
664   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   JOYSTICK_DOWN,      "P6 Down",             SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 5)) )
665   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   JOYSTICK_LEFT,      "P6 Left",             SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 5)) )
666   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   JOYSTICK_RIGHT,     "P6 Right",            SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 5)) )
667   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   JOYSTICKRIGHT_UP,   "P6 Right/Up",         SEQ_DEF_0 )
668   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   JOYSTICKRIGHT_DOWN, "P6 Right/Down",      SEQ_DEF_0 )
669   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   JOYSTICKRIGHT_LEFT, "P6 Right/Left",      SEQ_DEF_0 )
670   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   JOYSTICKRIGHT_RIGHT,"P6 Right/Right",      SEQ_DEF_0 )
671   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   JOYSTICKLEFT_UP,    "P6 Left/Up",          SEQ_DEF_0 )
672   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   JOYSTICKLEFT_DOWN,  "P6 Left/Down",         SEQ_DEF_0 )
673   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   JOYSTICKLEFT_LEFT,  "P6 Left/Left",         SEQ_DEF_0 )
674   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   JOYSTICKLEFT_RIGHT, "P6 Left/Right",      SEQ_DEF_0 )
675   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   BUTTON1,         "P6 Button 1",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON1, 5)) )
676   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   BUTTON2,         "P6 Button 2",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON2, 5)) )
677   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   BUTTON3,         "P6 Button 3",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON3, 5)) )
678   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   BUTTON4,         "P6 Button 4",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON4, 5)) )
679   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   BUTTON5,         "P6 Button 5",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON5, 5)) )
680   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   BUTTON6,         "P6 Button 6",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON6, 5)) )
681   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   BUTTON7,         "P6 Button 7",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON7, 5)) )
682   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   BUTTON8,         "P6 Button 8",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON8, 5)) )
683   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   BUTTON9,         "P6 Button 9",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON9, 5)) )
684   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   BUTTON10,         "P6 Button 10",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON10, 5)) )
685   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   BUTTON11,         "P6 Button 11",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON11, 5)) )
686   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   BUTTON12,         "P6 Button 12",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON12, 5)) )
687   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   BUTTON13,         "P6 Button 13",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON13, 5)) )
688   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   BUTTON14,         "P6 Button 14",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON14, 5)) )
689   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   BUTTON15,         "P6 Button 15",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON15, 5)) )
690   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6,   BUTTON16,         "P6 Button 16",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON16, 5)) )
691   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6, START,            "P6 Start",            SEQ_DEF_0 )
692   INPUT_PORT_DIGITAL_DEF( 6, IPG_PLAYER6, SELECT,            "P6 Select",         SEQ_DEF_0 )
693578
694   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   JOYSTICK_UP,      "P7 Up",            SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 6)) )
695   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   JOYSTICK_DOWN,      "P7 Down",             SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 6)) )
696   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   JOYSTICK_LEFT,      "P7 Left",             SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 6)) )
697   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   JOYSTICK_RIGHT,     "P7 Right",            SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 6)) )
698   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   JOYSTICKRIGHT_UP,   "P7 Right/Up",         SEQ_DEF_0 )
699   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   JOYSTICKRIGHT_DOWN, "P7 Right/Down",      SEQ_DEF_0 )
700   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   JOYSTICKRIGHT_LEFT, "P7 Right/Left",      SEQ_DEF_0 )
701   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   JOYSTICKRIGHT_RIGHT,"P7 Right/Right",      SEQ_DEF_0 )
702   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   JOYSTICKLEFT_UP,    "P7 Left/Up",          SEQ_DEF_0 )
703   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   JOYSTICKLEFT_DOWN,  "P7 Left/Down",         SEQ_DEF_0 )
704   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   JOYSTICKLEFT_LEFT,  "P7 Left/Left",         SEQ_DEF_0 )
705   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   JOYSTICKLEFT_RIGHT, "P7 Left/Right",      SEQ_DEF_0 )
706   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   BUTTON1,         "P7 Button 1",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON1, 6)) )
707   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   BUTTON2,         "P7 Button 2",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON2, 6)) )
708   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   BUTTON3,         "P7 Button 3",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON3, 6)) )
709   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   BUTTON4,         "P7 Button 4",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON4, 6)) )
710   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   BUTTON5,         "P7 Button 5",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON5, 6)) )
711   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   BUTTON6,         "P7 Button 6",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON6, 6)) )
712   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   BUTTON7,         "P7 Button 7",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON7, 6)) )
713   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   BUTTON8,         "P7 Button 8",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON8, 6)) )
714   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   BUTTON9,         "P7 Button 9",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON9, 6)) )
715   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   BUTTON10,         "P7 Button 10",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON10, 6)) )
716   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   BUTTON11,         "P7 Button 11",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON11, 6)) )
717   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   BUTTON12,         "P7 Button 12",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON12, 6)) )
718   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   BUTTON13,         "P7 Button 13",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON13, 6)) )
719   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   BUTTON14,         "P7 Button 14",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON14, 6)) )
720   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   BUTTON15,         "P7 Button 15",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON15, 6)) )
721   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7,   BUTTON16,         "P7 Button 16",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON16, 6)) )
722   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7, START,            "P7 Start",            SEQ_DEF_0 )
723   INPUT_PORT_DIGITAL_DEF( 7, IPG_PLAYER7, SELECT,            "P7 Select",         SEQ_DEF_0 )
579/*-------------------------------------------------
580    get_port_index - return an index for the
581    given port tag
582-------------------------------------------------*/
724583
725   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   JOYSTICK_UP,      "P8 Up",            SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 7)) )
726   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   JOYSTICK_DOWN,      "P8 Down",            SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 7)) )
727   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   JOYSTICK_LEFT,      "P8 Left",            SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 7)) )
728   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   JOYSTICK_RIGHT,     "P8 Right",            SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 7)) )
729   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   JOYSTICKRIGHT_UP,   "P8 Right/Up",         SEQ_DEF_0 )
730   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   JOYSTICKRIGHT_DOWN, "P8 Right/Down",      SEQ_DEF_0 )
731   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   JOYSTICKRIGHT_LEFT, "P8 Right/Left",      SEQ_DEF_0 )
732   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   JOYSTICKRIGHT_RIGHT,"P8 Right/Right",      SEQ_DEF_0 )
733   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   JOYSTICKLEFT_UP,    "P8 Left/Up",         SEQ_DEF_0 )
734   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   JOYSTICKLEFT_DOWN,  "P8 Left/Down",         SEQ_DEF_0 )
735   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   JOYSTICKLEFT_LEFT,  "P8 Left/Left",         SEQ_DEF_0 )
736   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   JOYSTICKLEFT_RIGHT, "P8 Left/Right",      SEQ_DEF_0 )
737   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   BUTTON1,         "P8 Button 1",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON1, 7)) )
738   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   BUTTON2,         "P8 Button 2",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON2, 7)) )
739   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   BUTTON3,         "P8 Button 3",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON3, 7)) )
740   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   BUTTON4,         "P8 Button 4",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON4, 7)) )
741   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   BUTTON5,         "P8 Button 5",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON5, 7)) )
742   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   BUTTON6,         "P8 Button 6",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON6, 7)) )
743   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   BUTTON7,         "P8 Button 7",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON7, 7)) )
744   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   BUTTON8,         "P8 Button 8",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON8, 7)) )
745   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   BUTTON9,         "P8 Button 9",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON9, 7)) )
746   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   BUTTON10,         "P8 Button 10",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON10, 7)) )
747   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   BUTTON11,         "P8 Button 11",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON11, 7)) )
748   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   BUTTON12,         "P8 Button 12",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON12, 7)) )
749   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   BUTTON13,         "P8 Button 13",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON13, 7)) )
750   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   BUTTON14,         "P8 Button 14",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON14, 7)) )
751   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   BUTTON15,         "P8 Button 15",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON15, 7)) )
752   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8,   BUTTON16,         "P8 Button 16",         SEQ_DEF_1(INDEXED(JOYCODE_BUTTON16, 7)) )
753   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8, START,            "P8 Start",            SEQ_DEF_0 )
754   INPUT_PORT_DIGITAL_DEF( 8, IPG_PLAYER8, SELECT,            "P8 Select",         SEQ_DEF_0 )
584INLINE int get_port_index(const input_port_config *portlist, const char *tag)
585{
586   const input_port_config *port;
587   int index = 0;
755588
756   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   START1,            "1 Player Start",      SEQ_DEF_3(KEYCODE_1, SEQCODE_OR, INDEXED(JOYCODE_START, 0)) )
757   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   START2,            "2 Players Start",      SEQ_DEF_3(KEYCODE_2, SEQCODE_OR, INDEXED(JOYCODE_START, 1)) )
758   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   START3,            "3 Players Start",      SEQ_DEF_3(KEYCODE_3, SEQCODE_OR, INDEXED(JOYCODE_START, 2)) )
759   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   START4,            "4 Players Start",      SEQ_DEF_3(KEYCODE_4, SEQCODE_OR, INDEXED(JOYCODE_START, 3)) )
760   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   START5,            "5 Players Start",      SEQ_DEF_0 )
761   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   START6,            "6 Players Start",      SEQ_DEF_0 )
762   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   START7,            "7 Players Start",      SEQ_DEF_0 )
763   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   START8,            "8 Players Start",      SEQ_DEF_0 )
589   for (port = portlist; port != NULL; port = port->next)
590   {
591      if (port->tag != NULL && strcmp(tag, port->tag) == 0)
592         return index;
593      index++;
594   }
595   return -1;
596}
764597
765   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   COIN1,            "Coin 1",            SEQ_DEF_3(KEYCODE_5, SEQCODE_OR, INDEXED(JOYCODE_SELECT, 0)) )
766   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   COIN2,            "Coin 2",            SEQ_DEF_3(KEYCODE_6, SEQCODE_OR, INDEXED(JOYCODE_SELECT, 1)) )
767   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   COIN3,            "Coin 3",            SEQ_DEF_3(KEYCODE_7, SEQCODE_OR, INDEXED(JOYCODE_SELECT, 2)) )
768   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   COIN4,            "Coin 4",            SEQ_DEF_3(KEYCODE_8, SEQCODE_OR, INDEXED(JOYCODE_SELECT, 3)) )
769   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   COIN5,            "Coin 5",            SEQ_DEF_0 )
770   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   COIN6,            "Coin 6",            SEQ_DEF_0 )
771   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   COIN7,            "Coin 7",            SEQ_DEF_0 )
772   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   COIN8,            "Coin 8",            SEQ_DEF_0 )
773   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   BILL1,            "Bill 1",            SEQ_DEF_1(KEYCODE_BACKSPACE) )
774598
775   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   SERVICE1,         "Service 1",          SEQ_DEF_1(KEYCODE_9) )
776   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   SERVICE2,         "Service 2",          SEQ_DEF_1(KEYCODE_0) )
777   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   SERVICE3,         "Service 3",           SEQ_DEF_1(KEYCODE_MINUS) )
778   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   SERVICE4,         "Service 4",           SEQ_DEF_1(KEYCODE_EQUALS) )
779599
780   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   SERVICE,         "Service",              SEQ_DEF_1(KEYCODE_F2) )
781   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   TILT,             "Tilt",                  SEQ_DEF_1(KEYCODE_T) )
782   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   INTERLOCK,         "Door Interlock",        SEQ_DEF_0 )
783   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   VOLUME_DOWN,      "Volume Down",           SEQ_DEF_1(KEYCODE_MINUS) )
784   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   VOLUME_UP,         "Volume Up",           SEQ_DEF_1(KEYCODE_EQUALS) )
600/***************************************************************************
601    CORE SYSTEM MANAGEMENT
602***************************************************************************/
785603
786   INPUT_PORT_ANALOG_DEF ( 1, IPG_PLAYER1,   PEDAL,            "P1 Pedal 1",           SEQ_DEF_1(INDEXED(JOYCODE_Y_NEG_ABSOLUTE, 0)), SEQ_DEF_0, SEQ_DEF_3(KEYCODE_LCONTROL, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 0)) )
787   INPUT_PORT_ANALOG_DEF ( 2, IPG_PLAYER2,   PEDAL,            "P2 Pedal 1",          SEQ_DEF_1(INDEXED(JOYCODE_Y_NEG_ABSOLUTE, 1)), SEQ_DEF_0, SEQ_DEF_3(KEYCODE_A, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 1)) )
788   INPUT_PORT_ANALOG_DEF ( 3, IPG_PLAYER3,   PEDAL,            "P3 Pedal 1",         SEQ_DEF_1(INDEXED(JOYCODE_Y_NEG_ABSOLUTE, 2)), SEQ_DEF_0, SEQ_DEF_3(KEYCODE_RCONTROL, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 2)) )
789   INPUT_PORT_ANALOG_DEF ( 4, IPG_PLAYER4,   PEDAL,            "P4 Pedal 1",         SEQ_DEF_1(INDEXED(JOYCODE_Y_NEG_ABSOLUTE, 3)), SEQ_DEF_0, SEQ_DEF_3(KEYCODE_0_PAD, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 3)) )
790   INPUT_PORT_ANALOG_DEF ( 5, IPG_PLAYER5,   PEDAL,            "P5 Pedal 1",         SEQ_DEF_1(INDEXED(JOYCODE_Y_NEG_ABSOLUTE, 4)), SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON1, 4)) )
791   INPUT_PORT_ANALOG_DEF ( 6, IPG_PLAYER6,   PEDAL,            "P6 Pedal 1",         SEQ_DEF_1(INDEXED(JOYCODE_Y_NEG_ABSOLUTE, 5)), SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON1, 5)) )
792   INPUT_PORT_ANALOG_DEF ( 7, IPG_PLAYER7,   PEDAL,            "P7 Pedal 1",         SEQ_DEF_1(INDEXED(JOYCODE_Y_NEG_ABSOLUTE, 6)), SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON1, 6)) )
793   INPUT_PORT_ANALOG_DEF ( 8, IPG_PLAYER8,   PEDAL,            "P8 Pedal 1",         SEQ_DEF_1(INDEXED(JOYCODE_Y_NEG_ABSOLUTE, 7)), SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON1, 7)) )
604/*-------------------------------------------------
605    input_port_init - initialize the input port
606    system
607-------------------------------------------------*/
794608
795   INPUT_PORT_ANALOG_DEF ( 1, IPG_PLAYER1,   PEDAL2,            "P1 Pedal 2",         SEQ_DEF_1(INDEXED(JOYCODE_Y_POS_ABSOLUTE, 0)), SEQ_DEF_0, SEQ_DEF_3(KEYCODE_LALT, SEQCODE_OR, INDEXED(JOYCODE_BUTTON2, 0)) )
796   INPUT_PORT_ANALOG_DEF ( 2, IPG_PLAYER2,   PEDAL2,            "P2 Pedal 2",         SEQ_DEF_1(INDEXED(JOYCODE_Y_POS_ABSOLUTE, 1)), SEQ_DEF_0, SEQ_DEF_3(KEYCODE_S, SEQCODE_OR, INDEXED(JOYCODE_BUTTON2, 1)) )
797   INPUT_PORT_ANALOG_DEF ( 3, IPG_PLAYER3,   PEDAL2,            "P3 Pedal 2",         SEQ_DEF_1(INDEXED(JOYCODE_Y_POS_ABSOLUTE, 2)), SEQ_DEF_0, SEQ_DEF_3(KEYCODE_RSHIFT, SEQCODE_OR, INDEXED(JOYCODE_BUTTON2, 2)) )
798   INPUT_PORT_ANALOG_DEF ( 4, IPG_PLAYER4,   PEDAL2,            "P4 Pedal 2",         SEQ_DEF_1(INDEXED(JOYCODE_Y_POS_ABSOLUTE, 3)), SEQ_DEF_0, SEQ_DEF_3(KEYCODE_DEL_PAD, SEQCODE_OR, INDEXED(JOYCODE_BUTTON2, 3)) )
799   INPUT_PORT_ANALOG_DEF ( 5, IPG_PLAYER5,   PEDAL2,            "P5 Pedal 2",         SEQ_DEF_1(INDEXED(JOYCODE_Y_POS_ABSOLUTE, 4)), SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON2, 4)) )
800   INPUT_PORT_ANALOG_DEF ( 6, IPG_PLAYER6,   PEDAL2,            "P6 Pedal 2",         SEQ_DEF_1(INDEXED(JOYCODE_Y_POS_ABSOLUTE, 5)), SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON2, 5)) )
801   INPUT_PORT_ANALOG_DEF ( 7, IPG_PLAYER7,   PEDAL2,            "P7 Pedal 2",         SEQ_DEF_1(INDEXED(JOYCODE_Y_POS_ABSOLUTE, 6)), SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON2, 6)) )
802   INPUT_PORT_ANALOG_DEF ( 8, IPG_PLAYER8,   PEDAL2,            "P8 Pedal 2",         SEQ_DEF_1(INDEXED(JOYCODE_Y_POS_ABSOLUTE, 7)), SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON2, 7)) )
609time_t input_port_init(running_machine *machine, const input_port_token *tokens)
610{
611   input_port_private *portdata;
612   time_t basetime;
803613
804   INPUT_PORT_ANALOG_DEF ( 1, IPG_PLAYER1,   PEDAL3,            "P1 Pedal 3",         SEQ_DEF_0, SEQ_DEF_0, SEQ_DEF_3(KEYCODE_SPACE, SEQCODE_OR, INDEXED(JOYCODE_BUTTON3, 0)) )
805   INPUT_PORT_ANALOG_DEF ( 2, IPG_PLAYER2,   PEDAL3,            "P2 Pedal 3",         SEQ_DEF_0, SEQ_DEF_0, SEQ_DEF_3(KEYCODE_Q, SEQCODE_OR, INDEXED(JOYCODE_BUTTON3, 1)) )
806   INPUT_PORT_ANALOG_DEF ( 3, IPG_PLAYER3,   PEDAL3,            "P3 Pedal 3",         SEQ_DEF_0, SEQ_DEF_0, SEQ_DEF_3(KEYCODE_ENTER, SEQCODE_OR, INDEXED(JOYCODE_BUTTON3, 2)) )
807   INPUT_PORT_ANALOG_DEF ( 4, IPG_PLAYER4,   PEDAL3,            "P4 Pedal 3",         SEQ_DEF_0, SEQ_DEF_0, SEQ_DEF_3(KEYCODE_ENTER_PAD, SEQCODE_OR, INDEXED(JOYCODE_BUTTON3, 3)) )
808   INPUT_PORT_ANALOG_DEF ( 5, IPG_PLAYER5,   PEDAL3,            "P5 Pedal 3",         SEQ_DEF_0, SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON3, 4)) )
809   INPUT_PORT_ANALOG_DEF ( 6, IPG_PLAYER6,   PEDAL3,            "P6 Pedal 3",         SEQ_DEF_0, SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON3, 5)) )
810   INPUT_PORT_ANALOG_DEF ( 7, IPG_PLAYER7,   PEDAL3,            "P7 Pedal 3",         SEQ_DEF_0, SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON3, 6)) )
811   INPUT_PORT_ANALOG_DEF ( 8, IPG_PLAYER8,   PEDAL3,            "P8 Pedal 3",         SEQ_DEF_0, SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON3, 7)) )
614   /* allocate memory for our data structure */
615   machine->input_port_data = auto_malloc(sizeof(*machine->input_port_data));
616   memset(machine->input_port_data, 0, sizeof(*machine->input_port_data));
617   portdata = machine->input_port_data;
812618
813   INPUT_PORT_ANALOG_DEF ( 1, IPG_PLAYER1,   PADDLE,            "Paddle",             SEQ_DEF_3(INDEXED(MOUSECODE_X, 0), SEQCODE_OR, INDEXED(JOYCODE_X, 0)), SEQ_DEF_3(KEYCODE_LEFT, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)), SEQ_DEF_3(KEYCODE_RIGHT, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
814   INPUT_PORT_ANALOG_DEF ( 2, IPG_PLAYER2,   PADDLE,            "Paddle 2",            SEQ_DEF_3(INDEXED(MOUSECODE_X, 1), SEQCODE_OR, INDEXED(JOYCODE_X, 1)), SEQ_DEF_3(KEYCODE_D, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 1)), SEQ_DEF_3(KEYCODE_G, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 1)) )
815   INPUT_PORT_ANALOG_DEF ( 3, IPG_PLAYER3,   PADDLE,            "Paddle 3",            SEQ_DEF_3(INDEXED(MOUSECODE_X, 2), SEQCODE_OR, INDEXED(JOYCODE_X, 2)), SEQ_DEF_3(KEYCODE_J, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 2)), SEQ_DEF_3(KEYCODE_L, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 2)) )
816   INPUT_PORT_ANALOG_DEF ( 4, IPG_PLAYER4,   PADDLE,            "Paddle 4",            SEQ_DEF_3(INDEXED(MOUSECODE_X, 3), SEQCODE_OR, INDEXED(JOYCODE_X, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 3)) )
817   INPUT_PORT_ANALOG_DEF ( 5, IPG_PLAYER5,   PADDLE,            "Paddle 5",            SEQ_DEF_3(INDEXED(MOUSECODE_X, 4), SEQCODE_OR, INDEXED(JOYCODE_X, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 4)) )
818   INPUT_PORT_ANALOG_DEF ( 6, IPG_PLAYER6,   PADDLE,            "Paddle 6",            SEQ_DEF_3(INDEXED(MOUSECODE_X, 5), SEQCODE_OR, INDEXED(JOYCODE_X, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 5)) )
819   INPUT_PORT_ANALOG_DEF ( 7, IPG_PLAYER7,   PADDLE,            "Paddle 7",            SEQ_DEF_3(INDEXED(MOUSECODE_X, 6), SEQCODE_OR, INDEXED(JOYCODE_X, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 6)) )
820   INPUT_PORT_ANALOG_DEF ( 8, IPG_PLAYER8,   PADDLE,            "Paddle 8",            SEQ_DEF_3(INDEXED(MOUSECODE_X, 7), SEQCODE_OR, INDEXED(JOYCODE_X, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 7)) )
619   /* add an exit callback and a frame callback */
620   add_exit_callback(machine, input_port_exit);
621   add_frame_callback(machine, frame_update_callback);
821622
822   INPUT_PORT_ANALOG_DEF ( 1, IPG_PLAYER1,   PADDLE_V,         "Paddle V",            SEQ_DEF_3(INDEXED(MOUSECODE_Y, 0), SEQCODE_OR, INDEXED(JOYCODE_Y, 0)), SEQ_DEF_3(KEYCODE_UP, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)), SEQ_DEF_3(KEYCODE_DOWN, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
823   INPUT_PORT_ANALOG_DEF ( 2, IPG_PLAYER2,   PADDLE_V,         "Paddle V 2",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 1), SEQCODE_OR, INDEXED(JOYCODE_Y, 1)), SEQ_DEF_3(KEYCODE_R, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 1)), SEQ_DEF_3(KEYCODE_F, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 1)) )
824   INPUT_PORT_ANALOG_DEF ( 3, IPG_PLAYER3,   PADDLE_V,         "Paddle V 3",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 2), SEQCODE_OR, INDEXED(JOYCODE_Y, 2)), SEQ_DEF_3(KEYCODE_I, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 2)), SEQ_DEF_3(KEYCODE_K, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 2)) )
825   INPUT_PORT_ANALOG_DEF ( 4, IPG_PLAYER4,   PADDLE_V,         "Paddle V 4",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 3), SEQCODE_OR, INDEXED(JOYCODE_Y, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 3)) )
826   INPUT_PORT_ANALOG_DEF ( 5, IPG_PLAYER5,   PADDLE_V,         "Paddle V 5",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 4), SEQCODE_OR, INDEXED(JOYCODE_Y, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 4)) )
827   INPUT_PORT_ANALOG_DEF ( 6, IPG_PLAYER6,   PADDLE_V,         "Paddle V 6",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 5), SEQCODE_OR, INDEXED(JOYCODE_Y, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 5)) )
828   INPUT_PORT_ANALOG_DEF ( 7, IPG_PLAYER7,   PADDLE_V,         "Paddle V 7",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 6), SEQCODE_OR, INDEXED(JOYCODE_Y, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 6)) )
829   INPUT_PORT_ANALOG_DEF ( 8, IPG_PLAYER8,   PADDLE_V,         "Paddle V 8",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 7), SEQCODE_OR, INDEXED(JOYCODE_Y, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 7)) )
623   /* initialize the default port info from the OSD */
624   init_port_types(machine);
830625
831   INPUT_PORT_ANALOG_DEF ( 1, IPG_PLAYER1,   POSITIONAL,         "Positional",         SEQ_DEF_3(INDEXED(MOUSECODE_X, 0), SEQCODE_OR, INDEXED(JOYCODE_X, 0)), SEQ_DEF_3(KEYCODE_LEFT, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)), SEQ_DEF_3(KEYCODE_RIGHT, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
832   INPUT_PORT_ANALOG_DEF ( 2, IPG_PLAYER2,   POSITIONAL,         "Positional 2",         SEQ_DEF_3(INDEXED(MOUSECODE_X, 1), SEQCODE_OR, INDEXED(JOYCODE_X, 1)), SEQ_DEF_3(KEYCODE_D, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 1)), SEQ_DEF_3(KEYCODE_G, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 1)) )
833   INPUT_PORT_ANALOG_DEF ( 3, IPG_PLAYER3,   POSITIONAL,         "Positional 3",       SEQ_DEF_3(INDEXED(MOUSECODE_X, 2), SEQCODE_OR, INDEXED(JOYCODE_X, 2)), SEQ_DEF_3(KEYCODE_J, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 2)), SEQ_DEF_3(KEYCODE_L, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 2)) )
834   INPUT_PORT_ANALOG_DEF ( 4, IPG_PLAYER4,   POSITIONAL,         "Positional 4",       SEQ_DEF_3(INDEXED(MOUSECODE_X, 3), SEQCODE_OR, INDEXED(JOYCODE_X, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 3)) )
835   INPUT_PORT_ANALOG_DEF ( 5, IPG_PLAYER5,   POSITIONAL,         "Positional 5",       SEQ_DEF_3(INDEXED(MOUSECODE_X, 4), SEQCODE_OR, INDEXED(JOYCODE_X, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 4)) )
836   INPUT_PORT_ANALOG_DEF ( 6, IPG_PLAYER6,   POSITIONAL,         "Positional 6",       SEQ_DEF_3(INDEXED(MOUSECODE_X, 5), SEQCODE_OR, INDEXED(JOYCODE_X, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 5)) )
837   INPUT_PORT_ANALOG_DEF ( 7, IPG_PLAYER7,   POSITIONAL,         "Positional 7",       SEQ_DEF_3(INDEXED(MOUSECODE_X, 6), SEQCODE_OR, INDEXED(JOYCODE_X, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 6)) )
838   INPUT_PORT_ANALOG_DEF ( 8, IPG_PLAYER8,   POSITIONAL,         "Positional 8",       SEQ_DEF_3(INDEXED(MOUSECODE_X, 7), SEQCODE_OR, INDEXED(JOYCODE_X, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 7)) )
626   /* if we have a token list, proceed */
627   if (tokens != NULL)
628   {
629      machine->portconfig = input_port_config_alloc(tokens);
630      init_port_state(machine);
631   }
839632
840   INPUT_PORT_ANALOG_DEF ( 1, IPG_PLAYER1,   POSITIONAL_V,      "Positional V",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 0), SEQCODE_OR, INDEXED(JOYCODE_Y, 0)), SEQ_DEF_3(KEYCODE_UP, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)), SEQ_DEF_3(KEYCODE_DOWN, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
841   INPUT_PORT_ANALOG_DEF ( 2, IPG_PLAYER2,   POSITIONAL_V,      "Positional V 2",      SEQ_DEF_3(INDEXED(MOUSECODE_Y, 1), SEQCODE_OR, INDEXED(JOYCODE_Y, 1)), SEQ_DEF_3(KEYCODE_R, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 1)), SEQ_DEF_3(KEYCODE_F, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 1)) )
842   INPUT_PORT_ANALOG_DEF ( 3, IPG_PLAYER3,   POSITIONAL_V,      "Positional V 3",       SEQ_DEF_3(INDEXED(MOUSECODE_Y, 2), SEQCODE_OR, INDEXED(JOYCODE_Y, 2)), SEQ_DEF_3(KEYCODE_I, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 2)), SEQ_DEF_3(KEYCODE_K, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 2)) )
843   INPUT_PORT_ANALOG_DEF ( 4, IPG_PLAYER4,   POSITIONAL_V,      "Positional V 4",       SEQ_DEF_3(INDEXED(MOUSECODE_Y, 3), SEQCODE_OR, INDEXED(JOYCODE_Y, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 3)) )
844   INPUT_PORT_ANALOG_DEF ( 5, IPG_PLAYER5,   POSITIONAL_V,      "Positional V 5",       SEQ_DEF_3(INDEXED(MOUSECODE_Y, 4), SEQCODE_OR, INDEXED(JOYCODE_Y, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 4)) )
845   INPUT_PORT_ANALOG_DEF ( 6, IPG_PLAYER6,   POSITIONAL_V,      "Positional V 6",       SEQ_DEF_3(INDEXED(MOUSECODE_Y, 5), SEQCODE_OR, INDEXED(JOYCODE_Y, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 5)) )
846   INPUT_PORT_ANALOG_DEF ( 7, IPG_PLAYER7,   POSITIONAL_V,      "Positional V 7",       SEQ_DEF_3(INDEXED(MOUSECODE_Y, 6), SEQCODE_OR, INDEXED(JOYCODE_Y, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 6)) )
847   INPUT_PORT_ANALOG_DEF ( 8, IPG_PLAYER8,   POSITIONAL_V,      "Positional V 8",       SEQ_DEF_3(INDEXED(MOUSECODE_Y, 7), SEQCODE_OR, INDEXED(JOYCODE_Y, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 7)) )
633   /* register callbacks for when we load configurations */
634   config_register(machine, "input", load_config_callback, save_config_callback);
848635
849   INPUT_PORT_ANALOG_DEF ( 1, IPG_PLAYER1,   DIAL,            "Dial",               SEQ_DEF_3(INDEXED(MOUSECODE_X, 0), SEQCODE_OR, INDEXED(JOYCODE_X, 0)), SEQ_DEF_3(KEYCODE_LEFT, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)), SEQ_DEF_3(KEYCODE_RIGHT, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
850   INPUT_PORT_ANALOG_DEF ( 2, IPG_PLAYER2,   DIAL,            "Dial 2",            SEQ_DEF_3(INDEXED(MOUSECODE_X, 1), SEQCODE_OR, INDEXED(JOYCODE_X, 1)), SEQ_DEF_3(KEYCODE_D, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 1)), SEQ_DEF_3(KEYCODE_G, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 1)) )
851   INPUT_PORT_ANALOG_DEF ( 3, IPG_PLAYER3,   DIAL,            "Dial 3",            SEQ_DEF_3(INDEXED(MOUSECODE_X, 2), SEQCODE_OR, INDEXED(JOYCODE_X, 2)), SEQ_DEF_3(KEYCODE_J, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 2)), SEQ_DEF_3(KEYCODE_L, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 2)) )
852   INPUT_PORT_ANALOG_DEF ( 4, IPG_PLAYER4,   DIAL,            "Dial 4",            SEQ_DEF_3(INDEXED(MOUSECODE_X, 3), SEQCODE_OR, INDEXED(JOYCODE_X, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 3)) )
853   INPUT_PORT_ANALOG_DEF ( 5, IPG_PLAYER5,   DIAL,            "Dial 5",            SEQ_DEF_3(INDEXED(MOUSECODE_X, 4), SEQCODE_OR, INDEXED(JOYCODE_X, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 4)) )
854   INPUT_PORT_ANALOG_DEF ( 6, IPG_PLAYER6,   DIAL,            "Dial 6",            SEQ_DEF_3(INDEXED(MOUSECODE_X, 5), SEQCODE_OR, INDEXED(JOYCODE_X, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 5)) )
855   INPUT_PORT_ANALOG_DEF ( 7, IPG_PLAYER7,   DIAL,            "Dial 7",            SEQ_DEF_3(INDEXED(MOUSECODE_X, 6), SEQCODE_OR, INDEXED(JOYCODE_X, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 6)) )
856   INPUT_PORT_ANALOG_DEF ( 8, IPG_PLAYER8,   DIAL,            "Dial 8",            SEQ_DEF_3(INDEXED(MOUSECODE_X, 7), SEQCODE_OR, INDEXED(JOYCODE_X, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 7)) )
636   /* open playback and record files if specified */
637   basetime = playback_init(machine);
638   record_init(machine);
857639
858   INPUT_PORT_ANALOG_DEF ( 1, IPG_PLAYER1,   DIAL_V,            "Dial V",            SEQ_DEF_3(INDEXED(MOUSECODE_Y, 0), SEQCODE_OR, INDEXED(JOYCODE_Y, 0)), SEQ_DEF_3(KEYCODE_UP, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)), SEQ_DEF_3(KEYCODE_DOWN, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
859   INPUT_PORT_ANALOG_DEF ( 2, IPG_PLAYER2,   DIAL_V,            "Dial V 2",            SEQ_DEF_3(INDEXED(MOUSECODE_Y, 1), SEQCODE_OR, INDEXED(JOYCODE_Y, 1)), SEQ_DEF_3(KEYCODE_R, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 1)), SEQ_DEF_3(KEYCODE_F, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 1)) )
860   INPUT_PORT_ANALOG_DEF ( 3, IPG_PLAYER3,   DIAL_V,            "Dial V 3",            SEQ_DEF_3(INDEXED(MOUSECODE_Y, 2), SEQCODE_OR, INDEXED(JOYCODE_Y, 2)), SEQ_DEF_3(KEYCODE_I, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 2)), SEQ_DEF_3(KEYCODE_K, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 2)) )
861   INPUT_PORT_ANALOG_DEF ( 4, IPG_PLAYER4,   DIAL_V,            "Dial V 4",            SEQ_DEF_3(INDEXED(MOUSECODE_Y, 3), SEQCODE_OR, INDEXED(JOYCODE_Y, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 3)) )
862   INPUT_PORT_ANALOG_DEF ( 5, IPG_PLAYER5,   DIAL_V,            "Dial V 5",            SEQ_DEF_3(INDEXED(MOUSECODE_Y, 4), SEQCODE_OR, INDEXED(JOYCODE_Y, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 4)) )
863   INPUT_PORT_ANALOG_DEF ( 6, IPG_PLAYER6,   DIAL_V,            "Dial V 6",            SEQ_DEF_3(INDEXED(MOUSECODE_Y, 5), SEQCODE_OR, INDEXED(JOYCODE_Y, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 5)) )
864   INPUT_PORT_ANALOG_DEF ( 7, IPG_PLAYER7,   DIAL_V,            "Dial V 7",            SEQ_DEF_3(INDEXED(MOUSECODE_Y, 6), SEQCODE_OR, INDEXED(JOYCODE_Y, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 6)) )
865   INPUT_PORT_ANALOG_DEF ( 8, IPG_PLAYER8,   DIAL_V,            "Dial V 8",            SEQ_DEF_3(INDEXED(MOUSECODE_Y, 7), SEQCODE_OR, INDEXED(JOYCODE_Y, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 7)) )
640   return basetime;
641}
866642
867   INPUT_PORT_ANALOG_DEF ( 1, IPG_PLAYER1,   TRACKBALL_X,      "Track X",            SEQ_DEF_3(INDEXED(MOUSECODE_X, 0), SEQCODE_OR, INDEXED(JOYCODE_X, 0)), SEQ_DEF_3(KEYCODE_LEFT, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)), SEQ_DEF_3(KEYCODE_RIGHT, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
868   INPUT_PORT_ANALOG_DEF ( 2, IPG_PLAYER2,   TRACKBALL_X,      "Track X 2",         SEQ_DEF_3(INDEXED(MOUSECODE_X, 1), SEQCODE_OR, INDEXED(JOYCODE_X, 1)), SEQ_DEF_3(KEYCODE_D, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 1)), SEQ_DEF_3(KEYCODE_G, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 1)) )
869   INPUT_PORT_ANALOG_DEF ( 3, IPG_PLAYER3,   TRACKBALL_X,      "Track X 3",         SEQ_DEF_3(INDEXED(MOUSECODE_X, 2), SEQCODE_OR, INDEXED(JOYCODE_X, 2)), SEQ_DEF_3(KEYCODE_J, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 2)), SEQ_DEF_3(KEYCODE_L, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 2)) )
870   INPUT_PORT_ANALOG_DEF ( 4, IPG_PLAYER4,   TRACKBALL_X,      "Track X 4",         SEQ_DEF_3(INDEXED(MOUSECODE_X, 3), SEQCODE_OR, INDEXED(JOYCODE_X, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 3)) )
871   INPUT_PORT_ANALOG_DEF ( 5, IPG_PLAYER5,   TRACKBALL_X,      "Track X 5",         SEQ_DEF_3(INDEXED(MOUSECODE_X, 4), SEQCODE_OR, INDEXED(JOYCODE_X, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 4)) )
872   INPUT_PORT_ANALOG_DEF ( 6, IPG_PLAYER6,   TRACKBALL_X,      "Track X 6",         SEQ_DEF_3(INDEXED(MOUSECODE_X, 5), SEQCODE_OR, INDEXED(JOYCODE_X, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 5)) )
873   INPUT_PORT_ANALOG_DEF ( 7, IPG_PLAYER7,   TRACKBALL_X,      "Track X 7",         SEQ_DEF_3(INDEXED(MOUSECODE_X, 6), SEQCODE_OR, INDEXED(JOYCODE_X, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 6)) )
874   INPUT_PORT_ANALOG_DEF ( 8, IPG_PLAYER8,   TRACKBALL_X,      "Track X 8",         SEQ_DEF_3(INDEXED(MOUSECODE_X, 7), SEQCODE_OR, INDEXED(JOYCODE_X, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 7)) )
875643
876   INPUT_PORT_ANALOG_DEF ( 1, IPG_PLAYER1,   TRACKBALL_Y,      "Track Y",            SEQ_DEF_3(INDEXED(MOUSECODE_Y, 0), SEQCODE_OR, INDEXED(JOYCODE_Y, 0)), SEQ_DEF_3(KEYCODE_UP, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)), SEQ_DEF_3(KEYCODE_DOWN, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
877   INPUT_PORT_ANALOG_DEF ( 2, IPG_PLAYER2,   TRACKBALL_Y,      "Track Y 2",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 1), SEQCODE_OR, INDEXED(JOYCODE_Y, 1)), SEQ_DEF_3(KEYCODE_R, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 1)), SEQ_DEF_3(KEYCODE_F, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 1)) )
878   INPUT_PORT_ANALOG_DEF ( 3, IPG_PLAYER3,   TRACKBALL_Y,      "Track Y 3",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 2), SEQCODE_OR, INDEXED(JOYCODE_Y, 2)), SEQ_DEF_3(KEYCODE_I, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 2)), SEQ_DEF_3(KEYCODE_K, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 2)) )
879   INPUT_PORT_ANALOG_DEF ( 4, IPG_PLAYER4,   TRACKBALL_Y,      "Track Y 4",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 3), SEQCODE_OR, INDEXED(JOYCODE_Y, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 3)) )
880   INPUT_PORT_ANALOG_DEF ( 5, IPG_PLAYER5,   TRACKBALL_Y,      "Track Y 5",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 4), SEQCODE_OR, INDEXED(JOYCODE_Y, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 4)) )
881   INPUT_PORT_ANALOG_DEF ( 6, IPG_PLAYER6,   TRACKBALL_Y,      "Track Y 6",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 5), SEQCODE_OR, INDEXED(JOYCODE_Y, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 5)) )
882   INPUT_PORT_ANALOG_DEF ( 7, IPG_PLAYER7,   TRACKBALL_Y,      "Track Y 7",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 6), SEQCODE_OR, INDEXED(JOYCODE_Y, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 6)) )
883   INPUT_PORT_ANALOG_DEF ( 8, IPG_PLAYER8,   TRACKBALL_Y,      "Track Y 8",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 7), SEQCODE_OR, INDEXED(JOYCODE_Y, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 7)) )
644/*-------------------------------------------------
645    input_port_exit - exit callback to ensure
646    we clean up and close our files
647-------------------------------------------------*/
884648
885   INPUT_PORT_ANALOG_DEF ( 1, IPG_PLAYER1,   AD_STICK_X,         "AD Stick X",         SEQ_DEF_3(INDEXED(JOYCODE_X, 0), SEQCODE_OR, INDEXED(MOUSECODE_X, 0)), SEQ_DEF_3(KEYCODE_LEFT, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)), SEQ_DEF_3(KEYCODE_RIGHT, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
886   INPUT_PORT_ANALOG_DEF ( 2, IPG_PLAYER2,   AD_STICK_X,         "AD Stick X 2",         SEQ_DEF_3(INDEXED(JOYCODE_X, 1), SEQCODE_OR, INDEXED(MOUSECODE_X, 1)), SEQ_DEF_3(KEYCODE_D, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 1)), SEQ_DEF_3(KEYCODE_G, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 1)) )
887   INPUT_PORT_ANALOG_DEF ( 3, IPG_PLAYER3,   AD_STICK_X,         "AD Stick X 3",         SEQ_DEF_3(INDEXED(JOYCODE_X, 2), SEQCODE_OR, INDEXED(MOUSECODE_X, 2)), SEQ_DEF_3(KEYCODE_J, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 2)), SEQ_DEF_3(KEYCODE_L, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 2)) )
888   INPUT_PORT_ANALOG_DEF ( 4, IPG_PLAYER4,   AD_STICK_X,         "AD Stick X 4",         SEQ_DEF_3(INDEXED(JOYCODE_X, 3), SEQCODE_OR, INDEXED(MOUSECODE_X, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 3)) )
889   INPUT_PORT_ANALOG_DEF ( 5, IPG_PLAYER5,   AD_STICK_X,         "AD Stick X 5",         SEQ_DEF_3(INDEXED(JOYCODE_X, 4), SEQCODE_OR, INDEXED(MOUSECODE_X, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 4)) )
890   INPUT_PORT_ANALOG_DEF ( 6, IPG_PLAYER6,   AD_STICK_X,         "AD Stick X 6",         SEQ_DEF_3(INDEXED(JOYCODE_X, 5), SEQCODE_OR, INDEXED(MOUSECODE_X, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 5)) )
891   INPUT_PORT_ANALOG_DEF ( 7, IPG_PLAYER7,   AD_STICK_X,         "AD Stick X 7",         SEQ_DEF_3(INDEXED(JOYCODE_X, 6), SEQCODE_OR, INDEXED(MOUSECODE_X, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 6)) )
892   INPUT_PORT_ANALOG_DEF ( 8, IPG_PLAYER8,   AD_STICK_X,         "AD Stick X 8",         SEQ_DEF_3(INDEXED(JOYCODE_X, 7), SEQCODE_OR, INDEXED(MOUSECODE_X, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 7)) )
649static void input_port_exit(running_machine *machine)
650{
651   /* close any playback or recording files */
652   playback_end(machine, NULL);
653   record_end(machine, NULL);
893654
894   INPUT_PORT_ANALOG_DEF ( 1, IPG_PLAYER1,   AD_STICK_Y,         "AD Stick Y",         SEQ_DEF_3(INDEXED(JOYCODE_Y, 0), SEQCODE_OR, INDEXED(MOUSECODE_Y, 0)), SEQ_DEF_3(KEYCODE_UP, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)), SEQ_DEF_3(KEYCODE_DOWN, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
895   INPUT_PORT_ANALOG_DEF ( 2, IPG_PLAYER2,   AD_STICK_Y,         "AD Stick Y 2",         SEQ_DEF_3(INDEXED(JOYCODE_Y, 1), SEQCODE_OR, INDEXED(MOUSECODE_Y, 1)), SEQ_DEF_3(KEYCODE_R, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 1)), SEQ_DEF_3(KEYCODE_F, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 1)) )
896   INPUT_PORT_ANALOG_DEF ( 3, IPG_PLAYER3,   AD_STICK_Y,         "AD Stick Y 3",         SEQ_DEF_3(INDEXED(JOYCODE_Y, 2), SEQCODE_OR, INDEXED(MOUSECODE_Y, 2)), SEQ_DEF_3(KEYCODE_I, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 2)), SEQ_DEF_3(KEYCODE_K, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 2)) )
897   INPUT_PORT_ANALOG_DEF ( 4, IPG_PLAYER4,   AD_STICK_Y,         "AD Stick Y 4",         SEQ_DEF_3(INDEXED(JOYCODE_Y, 3), SEQCODE_OR, INDEXED(MOUSECODE_Y, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 3)) )
898   INPUT_PORT_ANALOG_DEF ( 5, IPG_PLAYER5,   AD_STICK_Y,         "AD Stick Y 5",         SEQ_DEF_3(INDEXED(JOYCODE_Y, 4), SEQCODE_OR, INDEXED(MOUSECODE_Y, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 4)) )
899   INPUT_PORT_ANALOG_DEF ( 6, IPG_PLAYER6,   AD_STICK_Y,         "AD Stick Y 6",         SEQ_DEF_3(INDEXED(JOYCODE_Y, 5), SEQCODE_OR, INDEXED(MOUSECODE_Y, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 5)) )
900   INPUT_PORT_ANALOG_DEF ( 7, IPG_PLAYER7,   AD_STICK_Y,         "AD Stick Y 7",         SEQ_DEF_3(INDEXED(JOYCODE_Y, 6), SEQCODE_OR, INDEXED(MOUSECODE_Y, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 6)) )
901   INPUT_PORT_ANALOG_DEF ( 8, IPG_PLAYER8,   AD_STICK_Y,         "AD Stick Y 8",         SEQ_DEF_3(INDEXED(JOYCODE_Y, 7), SEQCODE_OR, INDEXED(MOUSECODE_Y, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 7)) )
655   /* free our allocated config */
656   if (machine->portconfig != NULL)
657      input_port_config_free(machine->portconfig);
658}
902659
903   INPUT_PORT_ANALOG_DEF ( 1, IPG_PLAYER1,   AD_STICK_Z,         "AD Stick Z",         SEQ_DEF_1(INDEXED(JOYCODE_Z, 0)), SEQ_DEF_0, SEQ_DEF_0 )
904   INPUT_PORT_ANALOG_DEF ( 2, IPG_PLAYER2,   AD_STICK_Z,         "AD Stick Z 2",         SEQ_DEF_1(INDEXED(JOYCODE_Z, 1)), SEQ_DEF_0, SEQ_DEF_0 )
905   INPUT_PORT_ANALOG_DEF ( 3, IPG_PLAYER3,   AD_STICK_Z,         "AD Stick Z 3",         SEQ_DEF_1(INDEXED(JOYCODE_Z, 2)), SEQ_DEF_0, SEQ_DEF_0 )
906   INPUT_PORT_ANALOG_DEF ( 4, IPG_PLAYER4,   AD_STICK_Z,         "AD Stick Z 4",         SEQ_DEF_1(INDEXED(JOYCODE_Z, 3)), SEQ_DEF_0, SEQ_DEF_0 )
907   INPUT_PORT_ANALOG_DEF ( 5, IPG_PLAYER5,   AD_STICK_Z,         "AD Stick Z 5",         SEQ_DEF_1(INDEXED(JOYCODE_Z, 4)), SEQ_DEF_0, SEQ_DEF_0 )
908   INPUT_PORT_ANALOG_DEF ( 6, IPG_PLAYER6,   AD_STICK_Z,         "AD Stick Z 6",         SEQ_DEF_1(INDEXED(JOYCODE_Z, 5)), SEQ_DEF_0, SEQ_DEF_0 )
909   INPUT_PORT_ANALOG_DEF ( 7, IPG_PLAYER7,   AD_STICK_Z,         "AD Stick Z 7",         SEQ_DEF_1(INDEXED(JOYCODE_Z, 6)), SEQ_DEF_0, SEQ_DEF_0 )
910   INPUT_PORT_ANALOG_DEF ( 8, IPG_PLAYER8,   AD_STICK_Z,         "AD Stick Z 8",         SEQ_DEF_1(INDEXED(JOYCODE_Z, 7)), SEQ_DEF_0, SEQ_DEF_0 )
911660
912   INPUT_PORT_ANALOG_DEF ( 1, IPG_PLAYER1,   LIGHTGUN_X,         "Lightgun X",         SEQ_DEF_5(INDEXED(GUNCODE_X, 0), SEQCODE_OR, INDEXED(MOUSECODE_X, 0), SEQCODE_OR, INDEXED(JOYCODE_X, 0)), SEQ_DEF_3(KEYCODE_LEFT, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)), SEQ_DEF_3(KEYCODE_RIGHT, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
913   INPUT_PORT_ANALOG_DEF ( 2, IPG_PLAYER2,   LIGHTGUN_X,         "Lightgun X 2",         SEQ_DEF_5(INDEXED(GUNCODE_X, 1), SEQCODE_OR, INDEXED(MOUSECODE_X, 1), SEQCODE_OR, INDEXED(JOYCODE_X, 1)), SEQ_DEF_3(KEYCODE_D, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 1)), SEQ_DEF_3(KEYCODE_G, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 1)) )
914   INPUT_PORT_ANALOG_DEF ( 3, IPG_PLAYER3,   LIGHTGUN_X,         "Lightgun X 3",         SEQ_DEF_5(INDEXED(GUNCODE_X, 2), SEQCODE_OR, INDEXED(MOUSECODE_X, 2), SEQCODE_OR, INDEXED(JOYCODE_X, 2)), SEQ_DEF_3(KEYCODE_J, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 2)), SEQ_DEF_3(KEYCODE_L, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 2)) )
915   INPUT_PORT_ANALOG_DEF ( 4, IPG_PLAYER4,   LIGHTGUN_X,         "Lightgun X 4",         SEQ_DEF_5(INDEXED(GUNCODE_X, 3), SEQCODE_OR, INDEXED(MOUSECODE_X, 3), SEQCODE_OR, INDEXED(JOYCODE_X, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 3)) )
916   INPUT_PORT_ANALOG_DEF ( 5, IPG_PLAYER5,   LIGHTGUN_X,         "Lightgun X 5",         SEQ_DEF_5(INDEXED(GUNCODE_X, 4), SEQCODE_OR, INDEXED(MOUSECODE_X, 4), SEQCODE_OR, INDEXED(JOYCODE_X, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 4)) )
917   INPUT_PORT_ANALOG_DEF ( 6, IPG_PLAYER6,   LIGHTGUN_X,         "Lightgun X 6",         SEQ_DEF_5(INDEXED(GUNCODE_X, 5), SEQCODE_OR, INDEXED(MOUSECODE_X, 5), SEQCODE_OR, INDEXED(JOYCODE_X, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 5)) )
918   INPUT_PORT_ANALOG_DEF ( 7, IPG_PLAYER7,   LIGHTGUN_X,         "Lightgun X 7",         SEQ_DEF_5(INDEXED(GUNCODE_X, 6), SEQCODE_OR, INDEXED(MOUSECODE_X, 6), SEQCODE_OR, INDEXED(JOYCODE_X, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 6)) )
919   INPUT_PORT_ANALOG_DEF ( 8, IPG_PLAYER8,   LIGHTGUN_X,         "Lightgun X 8",         SEQ_DEF_5(INDEXED(GUNCODE_X, 7), SEQCODE_OR, INDEXED(MOUSECODE_X, 7), SEQCODE_OR, INDEXED(JOYCODE_X, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 7)) )
920661
921   INPUT_PORT_ANALOG_DEF ( 1, IPG_PLAYER1,   LIGHTGUN_Y,         "Lightgun Y",         SEQ_DEF_5(INDEXED(GUNCODE_Y, 0), SEQCODE_OR, INDEXED(MOUSECODE_Y, 0), SEQCODE_OR, INDEXED(JOYCODE_Y, 0)), SEQ_DEF_3(KEYCODE_UP, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)), SEQ_DEF_3(KEYCODE_DOWN, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
922   INPUT_PORT_ANALOG_DEF ( 2, IPG_PLAYER2,   LIGHTGUN_Y,         "Lightgun Y 2",         SEQ_DEF_5(INDEXED(GUNCODE_Y, 1), SEQCODE_OR, INDEXED(MOUSECODE_Y, 1), SEQCODE_OR, INDEXED(JOYCODE_Y, 1)), SEQ_DEF_3(KEYCODE_R, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 1)), SEQ_DEF_3(KEYCODE_F, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 1)) )
923   INPUT_PORT_ANALOG_DEF ( 3, IPG_PLAYER3,   LIGHTGUN_Y,         "Lightgun Y 3",         SEQ_DEF_5(INDEXED(GUNCODE_Y, 2), SEQCODE_OR, INDEXED(MOUSECODE_Y, 2), SEQCODE_OR, INDEXED(JOYCODE_Y, 2)), SEQ_DEF_3(KEYCODE_I, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 2)), SEQ_DEF_3(KEYCODE_K, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 2)) )
924   INPUT_PORT_ANALOG_DEF ( 4, IPG_PLAYER4,   LIGHTGUN_Y,         "Lightgun Y 4",         SEQ_DEF_5(INDEXED(GUNCODE_Y, 3), SEQCODE_OR, INDEXED(MOUSECODE_Y, 3), SEQCODE_OR, INDEXED(JOYCODE_Y, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 3)) )
925   INPUT_PORT_ANALOG_DEF ( 5, IPG_PLAYER5,   LIGHTGUN_Y,         "Lightgun Y 5",         SEQ_DEF_5(INDEXED(GUNCODE_Y, 4), SEQCODE_OR, INDEXED(MOUSECODE_Y, 4), SEQCODE_OR, INDEXED(JOYCODE_Y, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 4)) )
926   INPUT_PORT_ANALOG_DEF ( 6, IPG_PLAYER6,   LIGHTGUN_Y,         "Lightgun Y 6",         SEQ_DEF_5(INDEXED(GUNCODE_Y, 5), SEQCODE_OR, INDEXED(MOUSECODE_Y, 5), SEQCODE_OR, INDEXED(JOYCODE_Y, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 5)) )
927   INPUT_PORT_ANALOG_DEF ( 7, IPG_PLAYER7,   LIGHTGUN_Y,         "Lightgun Y 7",         SEQ_DEF_5(INDEXED(GUNCODE_Y, 6), SEQCODE_OR, INDEXED(MOUSECODE_Y, 6), SEQCODE_OR, INDEXED(JOYCODE_Y, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 6)) )
928   INPUT_PORT_ANALOG_DEF ( 8, IPG_PLAYER8,   LIGHTGUN_Y,         "Lightgun Y 8",         SEQ_DEF_5(INDEXED(GUNCODE_Y, 7), SEQCODE_OR, INDEXED(MOUSECODE_Y, 7), SEQCODE_OR, INDEXED(JOYCODE_Y, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 7)) )
662/***************************************************************************
663    PORT CONFIGURATIONS
664***************************************************************************/
929665
930   INPUT_PORT_ANALOG_DEF ( 1, IPG_PLAYER1,   MOUSE_X,         "Mouse X",            SEQ_DEF_1(INDEXED(MOUSECODE_X, 0)), SEQ_DEF_3(KEYCODE_LEFT, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)), SEQ_DEF_3(KEYCODE_RIGHT, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
931   INPUT_PORT_ANALOG_DEF ( 2, IPG_PLAYER2,   MOUSE_X,         "Mouse X 2",         SEQ_DEF_1(INDEXED(MOUSECODE_X, 1)), SEQ_DEF_3(KEYCODE_D, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 1)), SEQ_DEF_3(KEYCODE_G, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 1)) )
932   INPUT_PORT_ANALOG_DEF ( 3, IPG_PLAYER3,   MOUSE_X,         "Mouse X 3",         SEQ_DEF_1(INDEXED(MOUSECODE_X, 2)), SEQ_DEF_3(KEYCODE_J, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 2)), SEQ_DEF_3(KEYCODE_L, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 2)) )
933   INPUT_PORT_ANALOG_DEF ( 4, IPG_PLAYER4,   MOUSE_X,         "Mouse X 4",         SEQ_DEF_1(INDEXED(MOUSECODE_X, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 3)) )
934   INPUT_PORT_ANALOG_DEF ( 5, IPG_PLAYER5,   MOUSE_X,         "Mouse X 5",         SEQ_DEF_1(INDEXED(MOUSECODE_X, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 4)) )
935   INPUT_PORT_ANALOG_DEF ( 6, IPG_PLAYER6,   MOUSE_X,         "Mouse X 6",         SEQ_DEF_1(INDEXED(MOUSECODE_X, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 5)) )
936   INPUT_PORT_ANALOG_DEF ( 7, IPG_PLAYER7,   MOUSE_X,         "Mouse X 7",         SEQ_DEF_1(INDEXED(MOUSECODE_X, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 6)) )
937   INPUT_PORT_ANALOG_DEF ( 8, IPG_PLAYER8,   MOUSE_X,         "Mouse X 8",         SEQ_DEF_1(INDEXED(MOUSECODE_X, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 7)) )
666/*-------------------------------------------------
667    input_port_config_alloc - allocate a list of
668    input ports from the given token list
669-------------------------------------------------*/
938670
939   INPUT_PORT_ANALOG_DEF ( 1, IPG_PLAYER1,   MOUSE_Y,         "Mouse Y",            SEQ_DEF_1(INDEXED(MOUSECODE_Y, 0)), SEQ_DEF_3(KEYCODE_UP, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)), SEQ_DEF_3(KEYCODE_DOWN, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
940   INPUT_PORT_ANALOG_DEF ( 2, IPG_PLAYER2,   MOUSE_Y,         "Mouse Y 2",         SEQ_DEF_1(INDEXED(MOUSECODE_Y, 1)), SEQ_DEF_3(KEYCODE_R, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 1)), SEQ_DEF_3(KEYCODE_F, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 1)) )
941   INPUT_PORT_ANALOG_DEF ( 3, IPG_PLAYER3,   MOUSE_Y,         "Mouse Y 3",         SEQ_DEF_1(INDEXED(MOUSECODE_Y, 2)), SEQ_DEF_3(KEYCODE_I, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 2)), SEQ_DEF_3(KEYCODE_K, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 2)) )
942   INPUT_PORT_ANALOG_DEF ( 4, IPG_PLAYER4,   MOUSE_Y,         "Mouse Y 4",         SEQ_DEF_1(INDEXED(MOUSECODE_Y, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 3)) )
943   INPUT_PORT_ANALOG_DEF ( 5, IPG_PLAYER5,   MOUSE_Y,         "Mouse Y 5",         SEQ_DEF_1(INDEXED(MOUSECODE_Y, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 4)) )
944   INPUT_PORT_ANALOG_DEF ( 6, IPG_PLAYER6,   MOUSE_Y,         "Mouse Y 6",         SEQ_DEF_1(INDEXED(MOUSECODE_Y, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 5)) )
945   INPUT_PORT_ANALOG_DEF ( 7, IPG_PLAYER7,   MOUSE_Y,         "Mouse Y 7",         SEQ_DEF_1(INDEXED(MOUSECODE_Y, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 6)) )
946   INPUT_PORT_ANALOG_DEF ( 8, IPG_PLAYER8,   MOUSE_Y,         "Mouse Y 8",         SEQ_DEF_1(INDEXED(MOUSECODE_Y, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 7)) )
671const input_port_config *input_port_config_alloc(const input_port_token *tokens)
672{
673   return port_config_detokenize(NULL, tokens);
674}
947675
948   INPUT_PORT_DIGITAL_DEF( 0, IPG_OTHER,   KEYBOARD,          "Keyboard",               SEQ_DEF_0 )
949676
950   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_ON_SCREEN_DISPLAY,"On Screen Display",   SEQ_DEF_1(KEYCODE_TILDE) )
951   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_DEBUG_BREAK,      "Break in Debugger",   SEQ_DEF_1(KEYCODE_TILDE) )
952   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_CONFIGURE,        "Config Menu",         SEQ_DEF_1(KEYCODE_TAB) )
953   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_PAUSE,            "Pause",            SEQ_DEF_1(KEYCODE_P) )
954   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_RESET_MACHINE,    "Reset Game",         SEQ_DEF_2(KEYCODE_F3, KEYCODE_LSHIFT) )
955   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_SOFT_RESET,       "Soft Reset",         SEQ_DEF_3(KEYCODE_F3, SEQCODE_NOT, KEYCODE_LSHIFT) )
956   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_SHOW_GFX,         "Show Gfx",         SEQ_DEF_1(KEYCODE_F4) )
957   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_FRAMESKIP_DEC,    "Frameskip Dec",      SEQ_DEF_1(KEYCODE_F8) )
958   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_FRAMESKIP_INC,    "Frameskip Inc",      SEQ_DEF_1(KEYCODE_F9) )
959   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_THROTTLE,         "Throttle",         SEQ_DEF_1(KEYCODE_F10) )
960   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_FAST_FORWARD,     "Fast Forward",      SEQ_DEF_1(KEYCODE_INSERT) )
961   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_SHOW_FPS,         "Show FPS",         SEQ_DEF_5(KEYCODE_F11, SEQCODE_NOT, KEYCODE_LCONTROL, SEQCODE_NOT, KEYCODE_LSHIFT) )
962   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_SNAPSHOT,         "Save Snapshot",      SEQ_DEF_3(KEYCODE_F12, SEQCODE_NOT, KEYCODE_LSHIFT) )
963   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_RECORD_MOVIE,     "Record Movie",      SEQ_DEF_2(KEYCODE_F12, KEYCODE_LSHIFT) )
964   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_TOGGLE_CHEAT,     "Toggle Cheat",      SEQ_DEF_1(KEYCODE_F6) )
965   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_UP,               "UI Up",            SEQ_DEF_3(KEYCODE_UP, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)) )
966   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_DOWN,             "UI Down",            SEQ_DEF_3(KEYCODE_DOWN, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
967   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_LEFT,             "UI Left",            SEQ_DEF_3(KEYCODE_LEFT, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)) )
968   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_RIGHT,            "UI Right",         SEQ_DEF_3(KEYCODE_RIGHT, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
969   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_HOME,             "UI Home",            SEQ_DEF_1(KEYCODE_HOME) )
970   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_END,              "UI End",            SEQ_DEF_1(KEYCODE_END) )
971   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_PAGE_UP,          "UI Page Up",         SEQ_DEF_1(KEYCODE_PGUP) )
972   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_PAGE_DOWN,        "UI Page Down",      SEQ_DEF_1(KEYCODE_PGDN) )
973   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_SELECT,           "UI Select",         SEQ_DEF_3(KEYCODE_ENTER, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 0)) )
974   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_CANCEL,           "UI Cancel",         SEQ_DEF_1(KEYCODE_ESC) )
975   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_CLEAR,            "UI Clear",         SEQ_DEF_1(KEYCODE_DEL) )
976   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_ZOOM_IN,          "UI Zoom In",         SEQ_DEF_1(KEYCODE_EQUALS) )
977   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_ZOOM_OUT,         "UI Zoom Out",         SEQ_DEF_1(KEYCODE_MINUS) )
978   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_PREV_GROUP,       "UI Previous Group",   SEQ_DEF_1(KEYCODE_OPENBRACE) )
979   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_NEXT_GROUP,       "UI Next Group",      SEQ_DEF_1(KEYCODE_CLOSEBRACE) )
980   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_ROTATE,           "UI Rotate",         SEQ_DEF_1(KEYCODE_R) )
981   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_SHOW_PROFILER,    "Show Profiler",      SEQ_DEF_2(KEYCODE_F11, KEYCODE_LSHIFT) )
982#ifdef MESS
983   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_TOGGLE_UI,        "UI Toggle",         SEQ_DEF_3(KEYCODE_SCRLOCK, SEQCODE_NOT, KEYCODE_LSHIFT) )
984   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_PASTE,          "UI Paste Text",      SEQ_DEF_2(KEYCODE_SCRLOCK, KEYCODE_LSHIFT) )
985#endif /* MESS */
986   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_TOGGLE_DEBUG,     "Toggle Debugger",      SEQ_DEF_1(KEYCODE_F5) )
987   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_SAVE_STATE,       "Save State",         SEQ_DEF_2(KEYCODE_F7, KEYCODE_LSHIFT) )
988   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_LOAD_STATE,       "Load State",         SEQ_DEF_3(KEYCODE_F7, SEQCODE_NOT, KEYCODE_LSHIFT) )
989   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_ADD_CHEAT,        "Add Cheat",         SEQ_DEF_1(KEYCODE_A) )
990   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_DELETE_CHEAT,     "Delete Cheat",      SEQ_DEF_1(KEYCODE_D) )
991   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_SAVE_CHEAT,       "Save Cheat",         SEQ_DEF_1(KEYCODE_S) )
992   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_WATCH_VALUE,      "Watch Value",         SEQ_DEF_1(KEYCODE_W) )
993   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_EDIT_CHEAT,       "Edit Cheat",         SEQ_DEF_1(KEYCODE_E) )
994   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_RELOAD_CHEAT,     "Reload Database",      SEQ_DEF_1(KEYCODE_L) )
995   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      UI_TOGGLE_CROSSHAIR, "Toggle Crosshair",   SEQ_DEF_1(KEYCODE_F1) )
677/*-------------------------------------------------
678    input_port_config_alloc - free memory
679    allocated from input_port_alloc
680-------------------------------------------------*/
996681
997   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      OSD_1,            NULL,               SEQ_DEF_0 )
998   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      OSD_2,            NULL,               SEQ_DEF_0 )
999   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      OSD_3,            NULL,               SEQ_DEF_0 )
1000   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      OSD_4,            NULL,               SEQ_DEF_0 )
1001   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      OSD_5,            NULL,               SEQ_DEF_0 )
1002   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      OSD_6,            NULL,               SEQ_DEF_0 )
1003   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      OSD_7,            NULL,               SEQ_DEF_0 )
1004   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      OSD_8,            NULL,               SEQ_DEF_0 )
1005   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      OSD_9,            NULL,               SEQ_DEF_0 )
1006   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      OSD_10,            NULL,               SEQ_DEF_0 )
1007   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      OSD_11,            NULL,               SEQ_DEF_0 )
1008   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      OSD_12,            NULL,               SEQ_DEF_0 )
1009   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      OSD_13,            NULL,               SEQ_DEF_0 )
1010   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      OSD_14,            NULL,               SEQ_DEF_0 )
1011   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      OSD_15,            NULL,               SEQ_DEF_0 )
1012   INPUT_PORT_DIGITAL_DEF( 0, IPG_UI,      OSD_16,            NULL,               SEQ_DEF_0 )
1013   INPUT_PORT_DIGITAL_DEF( 0, IPG_INVALID, UNKNOWN,         NULL,               SEQ_DEF_0 )
1014   INPUT_PORT_DIGITAL_DEF( 0, IPG_INVALID, SPECIAL,         NULL,               SEQ_DEF_0 )
1015   INPUT_PORT_DIGITAL_DEF( 0, IPG_INVALID, OTHER,            NULL,               SEQ_DEF_0 )
1016   INPUT_PORT_DIGITAL_DEF( 0, IPG_INVALID, DIPSWITCH_NAME,      NULL,               SEQ_DEF_0 )
1017   INPUT_PORT_DIGITAL_DEF( 0, IPG_INVALID, CONFIG_NAME,      NULL,               SEQ_DEF_0 )
1018   INPUT_PORT_DIGITAL_DEF( 0, IPG_INVALID, END,            NULL,               SEQ_DEF_0 )
1019};
682void input_port_config_free(const input_port_config *portlist)
683{
684   /* iterate over all ports and free them */
685   while (portlist != NULL)
686      port_config_free(&portlist);
687}
1020688
1021689
1022static input_port_default_entry default_ports[ARRAY_LENGTH(default_ports_builtin)];
1023static input_port_default_entry default_ports_backup[ARRAY_LENGTH(default_ports_builtin)];
1024static const int input_port_count = ARRAY_LENGTH(default_ports_builtin);
1025static int default_ports_lookup[__ipt_max][MAX_PLAYERS];
690/*-------------------------------------------------
691    input_port_by_tag - return a pointer to the
692    port_config associated with the given port
693    tag
694-------------------------------------------------*/
1026695
696const input_port_config *input_port_by_tag(const input_port_config *portlist, const char *tag)
697{
698   const input_port_config *port;
1027699
700   /* loop over ports until we hit the index or run out */
701   for (port = portlist; port != NULL; port = port->next)
702      if (port->tag != NULL && strcmp(port->tag, tag) == 0)
703         return port;
1028704
705   return NULL;
706}
707
708
709/*-------------------------------------------------
710    input_port_by_index - return a pointer to the
711    port_config associated with the given port
712    index
713-------------------------------------------------*/
714
715const input_port_config *input_port_by_index(const input_port_config *portlist, int index)
716{
717   const input_port_config *port;
718
719   /* loop over ports until we hit the index or run out */
720   for (port = portlist; port != NULL; port = port->next)
721      if (index-- == 0)
722         return port;
723
724   return NULL;
725}
726
727
728
1029729/***************************************************************************
1030    FUNCTION PROTOTYPES
730    ACCESSORS FOR INPUT FIELDS
1031731***************************************************************************/
1032732
1033static void input_port_exit(running_machine *machine);
1034static void input_port_frame(running_machine *machine);
1035static void input_port_frame_update(running_machine *machine);
1036static void input_port_load(int config_type, xml_data_node *parentnode);
1037static void input_port_save(int config_type, xml_data_node *parentnode);
1038static void update_digital_joysticks(running_machine *machine);
1039static void update_analog_port(int port);
1040static void autoselect_device(const input_port_entry *ipt, int type1, int type2, int type3, const char *option, const char *ananame);
733/*-------------------------------------------------
734    input_field_name - return the field name for
735    a given input field
736-------------------------------------------------*/
1041737
1042/* playback and record */
1043static time_t playback_init(running_machine *machine);
1044static void record_init(running_machine *machine);
1045static void playback_end(running_machine *machine, const char *message);
1046static void record_end(running_machine *machine, const char *message);
1047static void playback_frame(running_machine *machine, attotime curtime);
1048static void record_frame(running_machine *machine, attotime curtime);
1049static void playback_port(running_machine *machine, input_port_info *portinfo);
1050static void record_port(running_machine *machine, input_port_info *portinfo);
738const char *input_field_name(const input_field_config *field)
739{
740   /* if we have a non-default name, use that */
741   if (field->name != NULL)
742      return field->name;
1051743
744   /* otherwise, return the name associated with the type */
745   return input_type_name(field->port->machine, field->type, field->player);
746}
1052747
1053748
749/*-------------------------------------------------
750    input_field_seq - return the input sequence
751    for the given input field
752-------------------------------------------------*/
753
754const input_seq *input_field_seq(const input_field_config *field, input_seq_type seqtype)
755{
756   static const input_seq ip_none = SEQ_DEF_0;
757   const input_seq *portseq = &ip_none;
758
759   /* if the field is disabled, return no key */
760   if (field->flags & FIELD_FLAG_UNUSED)
761      return portseq;
762
763   /* select either the live or config state depending on whether we have live state */
764   portseq = (field->state == NULL) ? &field->seq[seqtype] : &field->state->seq[seqtype];
765
766   /* if the portseq is the special default code, return the expanded default value */
767   if (input_seq_get_1(portseq) == SEQCODE_DEFAULT)
768      return input_type_seq(field->port->machine, field->type, field->player, seqtype);
769
770   /* otherwise, return the sequence as-is */
771   return portseq;
772}
773
774
775/*-------------------------------------------------
776    input_field_get_user_settings - return the current
777    settings for the given input field
778-------------------------------------------------*/
779
780void input_field_get_user_settings(const input_field_config *field, input_field_user_settings *settings)
781{
782   int seqtype;
783
784   /* zap the entire structure */
785   memset(settings, 0, sizeof(*settings));
786
787   /* copy the basics */
788   for (seqtype = 0; seqtype < ARRAY_LENGTH(settings->seq); seqtype++)
789      settings->seq[seqtype] = field->state->seq[seqtype];
790
791   /* if there's a list of settings or we're an adjuster, copy the current value */
792   if (field->settinglist != NULL || field->type == IPT_ADJUSTER)
793      settings->value = field->state->value;
794
795   /* if there's analog data, extract the analog settings */
796   if (field->state->analog != NULL)
797   {
798      settings->sensitivity = field->state->analog->sensitivity;
799      settings->delta = field->state->analog->delta;
800      settings->centerdelta = field->state->analog->centerdelta;
801      settings->reverse = field->state->analog->reverse;
802   }
803}
804
805
806/*-------------------------------------------------
807    input_field_set_user_settings - modify the current
808    settings for the given input field
809-------------------------------------------------*/
810
811void input_field_set_user_settings(const input_field_config *field, const input_field_user_settings *settings)
812{
813   static const input_seq default_seq = SEQ_DEF_1(SEQCODE_DEFAULT);
814   int seqtype;
815
816   /* copy the basics */
817   for (seqtype = 0; seqtype < ARRAY_LENGTH(settings->seq); seqtype++)
818   {
819      const input_seq *defseq = input_type_seq(field->port->machine, field->type, field->player, seqtype);
820      if (input_seq_cmp(defseq, &settings->seq[seqtype]) == 0)
821         field->state->seq[seqtype] = default_seq;
822      else
823         field->state->seq[seqtype] = settings->seq[seqtype];
824   }
825
826   /* if there's a list of settings or we're an adjuster, copy the current value */
827   if (field->settinglist != NULL || field->type == IPT_ADJUSTER)
828      field->state->value = settings->value;
829
830   /* if there's analog data, extract the analog settings */
831   if (field->state->analog != NULL)
832   {
833      field->state->analog->sensitivity = settings->sensitivity;
834      field->state->analog->delta = settings->delta;
835      field->state->analog->centerdelta = settings->centerdelta;
836      field->state->analog->reverse = settings->reverse;
837   }
838}
839
840
841
1054842/***************************************************************************
1055    CORE IMPLEMENTATION
843    ACCESSORS FOR INPUT TYPES
1056844***************************************************************************/
1057845
1058/*************************************
1059 *
1060 *  Input port initialize
1061 *
1062 *************************************/
846/*-------------------------------------------------
847    input_type_is_analog - return TRUE if
848    the given type represents an analog control
849-------------------------------------------------*/
1063850
1064time_t input_port_init(running_machine *machine, const input_port_token *ipt)
851int input_type_is_analog(int type)
1065852{
1066   int ipnum, player;
1067   time_t basetime;
853   return (type >= __ipt_analog_start && type <= __ipt_analog_end);
854}
1068855
1069   /* add an exit callback */
1070   add_exit_callback(machine, input_port_exit);
1071   add_frame_callback(machine, input_port_frame);
1072856
1073   /* reset the pointers */
1074   memset(&joystick_info, 0, sizeof(joystick_info));
857/*-------------------------------------------------
858    input_type_name - return the name
859    for the given type/player
860-------------------------------------------------*/
1075861
1076   /* start with the raw defaults and ask the OSD to customize them in the backup array */
1077   memcpy(default_ports_backup, default_ports_builtin, sizeof(default_ports_backup));
1078   osd_customize_inputport_list(default_ports_backup);
862const char *input_type_name(running_machine *machine, int type, int player)
863{
864   /* if we have a machine, use the live state and quick lookup */
865   if (machine != NULL)
866   {
867      input_port_private *portdata = machine->input_port_data;
868      input_type_state *typestate = portdata->type_to_typestate[type][player];
869      if (typestate != NULL)
870         return typestate->typedesc.name;
871   }
1079872
1080   /* propogate these changes forward to the final input list */
1081   memcpy(default_ports, default_ports_backup, sizeof(default_ports));
873   /* if no machine, fall back to brute force searching */
874   else
875   {
876      int typenum;
877      for (typenum = 0; typenum < ARRAY_LENGTH(core_types); typenum++)
878         if (core_types[typenum].type == type && core_types[typenum].player == player)
879            return core_types[typenum].name;
880   }
1082881
1083   /* make a lookup table mapping type/player to the default port list entry */
1084   for (ipnum = 0; ipnum < __ipt_max; ipnum++)
1085      for (player = 0; player < MAX_PLAYERS; player++)
1086         default_ports_lookup[ipnum][player] = -1;
1087   for (ipnum = 0; default_ports[ipnum].type != IPT_END; ipnum++)
1088      default_ports_lookup[default_ports[ipnum].type][default_ports[ipnum].player] = ipnum;
882   /* if we find nothing, return an invalid group */
883   return "???";
884}
1089885
1090   /* reset the port info */
1091   memset(port_info, 0, sizeof(port_info));
1092886
1093   /* if we have inputs, process them now */
1094   if (ipt != NULL)
887/*-------------------------------------------------
888    input_type_group - return the group
889    for the given type/player
890-------------------------------------------------*/
891
892int input_type_group(running_machine *machine, int type, int player)
893{
894   /* if we have a machine, use the live state and quick lookup */
895   if (machine != NULL)
1095896   {
1096      const char *joystick_map_default = options_get_string(mame_options(), OPTION_JOYSTICK_MAP);
1097      input_port_entry *portentry;
1098      int portnum;
897      input_port_private *portdata = machine->input_port_data;
898      input_type_state *typestate = portdata->type_to_typestate[type][player];
899      if (typestate != NULL)
900         return typestate->typedesc.group;
901   }
1099902
1100      /* allocate input ports */
1101      machine->input_ports = input_port_allocate(ipt, NULL);
903   /* if no machine, fall back to brute force searching */
904   else
905   {
906      int typenum;
907      for (typenum = 0; typenum < ARRAY_LENGTH(core_types); typenum++)
908         if (core_types[typenum].type == type && core_types[typenum].player == player)
909            return core_types[typenum].group;
910   }
1102911
1103      /* allocate default input ports */
1104      input_ports_default = input_port_allocate(ipt, NULL);
912   /* if we find nothing, return an invalid group */
913   return IPG_INVALID;
914}
1105915
1106      /* handle autoselection of devices */
1107      autoselect_device(machine->input_ports, IPT_PADDLE,      IPT_PADDLE_V,     0,              OPTION_PADDLE_DEVICE,     "paddle");
1108      autoselect_device(machine->input_ports, IPT_AD_STICK_X,  IPT_AD_STICK_Y,   IPT_AD_STICK_Z, OPTION_ADSTICK_DEVICE,    "analog joystick");
1109      autoselect_device(machine->input_ports, IPT_LIGHTGUN_X,  IPT_LIGHTGUN_Y,   0,              OPTION_LIGHTGUN_DEVICE,   "lightgun");
1110      autoselect_device(machine->input_ports, IPT_PEDAL,       IPT_PEDAL2,       IPT_PEDAL3,     OPTION_PEDAL_DEVICE,      "pedal");
1111      autoselect_device(machine->input_ports, IPT_DIAL,        IPT_DIAL_V,       0,              OPTION_DIAL_DEVICE,       "dial");
1112      autoselect_device(machine->input_ports, IPT_TRACKBALL_X, IPT_TRACKBALL_Y,  0,              OPTION_TRACKBALL_DEVICE,  "trackball");
1113      autoselect_device(machine->input_ports, IPT_POSITIONAL,  IPT_POSITIONAL_V, 0,              OPTION_POSITIONAL_DEVICE, "positional");
1114      autoselect_device(machine->input_ports, IPT_MOUSE_X,     IPT_MOUSE_Y,      0,              OPTION_MOUSE_DEVICE,      "mouse");
1115916
1116      /* look for 4-way joysticks and change the default map if we find any */
1117      if (joystick_map_default[0] == 0 || strcmp(joystick_map_default, "auto") == 0)
1118         for (portentry = machine->input_ports; portentry->type != IPT_END; portentry++)
1119            if (IS_DIGITAL_JOYSTICK(portentry) && portentry->way == 4)
1120            {
1121               input_device_set_joystick_map(-1, portentry->rotated ? joystick_map_4way_diagonal : joystick_map_4way_sticky);
1122               break;
1123            }
917/*-------------------------------------------------
918    input_type_seq - return the input
919    sequence for the given type/player
920-------------------------------------------------*/
1124921
1125      /* identify all the tagged ports up front so the memory system can access them */
1126      portnum = 0;
1127      for (portentry = machine->input_ports; portentry->type != IPT_END; portentry++)
1128         if (portentry->type == IPT_PORT)
1129            port_info[portnum++].tag = portentry->start.tag;
922const input_seq *input_type_seq(running_machine *machine, int type, int player, input_seq_type seqtype)
923{
924   static const input_seq ip_none = SEQ_DEF_0;
1130925
1131      /* look up all the tags referenced in conditions */
1132      for (portentry = machine->input_ports; portentry->type != IPT_END; portentry++)
1133         if (portentry->condition.tag)
1134         {
1135            int tag = port_tag_to_index(portentry->condition.tag);
1136            if (tag == -1)
1137               fatalerror("Conditional port references invalid tag '%s'", portentry->condition.tag);
1138            portentry->condition.portnum = tag;
1139         }
926   /* if we have a machine, use the live state and quick lookup */
927   if (machine != NULL)
928   {
929      input_port_private *portdata = machine->input_port_data;
930      input_type_state *typestate = portdata->type_to_typestate[type][player];
931      if (typestate != NULL)
932         return &typestate->seq[seqtype];
1140933   }
1141934
1142   /* register callbacks for when we load configurations */
1143   config_register("input", input_port_load, input_port_save);
935   /* if no machine, fall back to brute force searching */
936   else
937   {
938      int typenum;
939      for (typenum = 0; typenum < ARRAY_LENGTH(core_types); typenum++)
940         if (core_types[typenum].type == type && core_types[typenum].player == player)
941            return &core_types[typenum].seq[seqtype];
942   }
1144943
1145   /* open playback and record files if specified */
1146   basetime = playback_init(machine);
1147   record_init(machine);
944   /* if we find nothing, return an empty sequence */
945   return &ip_none;
946}
1148947
1149   return basetime;
948
949/*-------------------------------------------------
950    input_type_set_seq - change the input
951    sequence for the given type/player
952-------------------------------------------------*/
953
954void input_type_set_seq(running_machine *machine, int type, int player, input_seq_type seqtype, const input_seq *newseq)
955{
956   input_port_private *portdata = machine->input_port_data;
957   input_type_state *typestate = portdata->type_to_typestate[type][player];
958   if (typestate != NULL)
959      typestate->seq[seqtype] = *newseq;
1150960}
1151961
1152962
963/*-------------------------------------------------
964    input_type_pressed - return TRUE if
965    the sequence for the given input type/player
966    is pressed
967-------------------------------------------------*/
1153968
1154/*************************************
1155 *
1156 *  Input port exit
1157 *
1158 *************************************/
969int input_type_pressed(running_machine *machine, int type, int player)
970{
971   return input_seq_pressed(input_type_seq(machine, type, player, SEQ_TYPE_STANDARD));
972}
1159973
1160void input_port_exit(running_machine *machine)
974
975/*-------------------------------------------------
976    input_type_list - return the list of types
977-------------------------------------------------*/
978
979const input_type_desc *input_type_list(running_machine *machine)
1161980{
1162   /* close any playback or recording files */
1163   playback_end(machine, NULL);
1164   record_end(machine, NULL);
981   input_port_private *portdata = machine->input_port_data;
982   return &portdata->typestatelist->typedesc;
1165983}
1166984
1167985
1168986
1169/*************************************
1170 *
1171 *  Input port initialization
1172 *
1173 *************************************/
987/***************************************************************************
988    USER INTERFACE SEQUENCE READING
989***************************************************************************/
1174990
1175static void input_port_postload(void)
991/*-------------------------------------------------
992    input_ui_pressed - return TRUE if a key down
993    for the given user interface sequence is
994    detected
995-------------------------------------------------*/
996
997int input_ui_pressed(running_machine *machine, int code)
1176998{
1177   input_port_entry *portentry;
1178   int portnum, bitnum;
1179   UINT32 mask;
999   return input_ui_pressed_repeat(machine, code, 0);
1000}
11801001
1181   /* loop over the ports and identify all the analog inputs */
1182   portnum = -1;
1183   bitnum = 0;
1184   for (portentry = Machine->input_ports; portentry->type != IPT_END; portentry++)
1002
1003/*-------------------------------------------------
1004    input_ui_pressed_r - return TRUE if a key down
1005    for the given user interface sequence is
1006    detected, or if autorepeat at the given speed
1007    is triggered
1008-------------------------------------------------*/
1009
1010int input_ui_pressed_repeat(running_machine *machine, int code, int speed)
1011{
1012   input_port_private *portdata = machine->input_port_data;
1013   int pressed;
1014
1015profiler_mark(PROFILER_INPUT);
1016
1017   /* get the status of this key (assumed to be only in the defaults) */
1018   assert(code >= IPT_UI_CONFIGURE && code <= IPT_OSD_16);
1019   pressed = input_seq_pressed(input_type_seq(machine, code, 0, SEQ_TYPE_STANDARD));
1020
1021   /* if down, handle it specially */
1022   if (pressed)
11851023   {
1186      /* if this is IPT_PORT, increment the port number */
1187      if (portentry->type == IPT_PORT)
1024      osd_ticks_t tps = osd_ticks_per_second();
1025
1026      /* if this is the first press, set a 3x delay and leave pressed = 1 */
1027      if (portdata->ui_memory[code] == 0)
1028         portdata->ui_memory[code] = osd_ticks() + 3 * speed * tps / 60;
1029
1030      /* if this is an autorepeat case, set a 1x delay and leave pressed = 1 */
1031      else if (speed > 0 && (osd_ticks() + tps - portdata->ui_memory[code]) >= tps)
1032         portdata->ui_memory[code] += 1 * speed * tps / 60;
1033
1034      /* otherwise, reset pressed = 0 */
1035      else
1036         pressed = 0;
1037   }
1038
1039   /* if we're not pressed, reset the memory field */
1040   else
1041      portdata->ui_memory[code] = 0;
1042
1043profiler_mark(PROFILER_END);
1044
1045   return pressed;
1046}
1047
1048
1049
1050/***************************************************************************
1051    PORT READING
1052***************************************************************************/
1053
1054/*-------------------------------------------------
1055    input_port_read_direct - return the value of
1056    an input port
1057-------------------------------------------------*/
1058
1059input_port_value input_port_read_direct(const input_port_config *port)
1060{
1061   input_port_private *portdata = port->machine->input_port_data;
1062   analog_field_state *analog;
1063   callback_field_info *custom;
1064   input_port_value result;
1065
1066   /* start with the digital */
1067   result = port->state->digital;
1068
1069   /* update custom values */
1070   for (custom = port->state->customlist; custom != NULL; custom = custom->next)
1071      if (input_condition_true(port->machine, &custom->field->condition))
11881072      {
1189         portnum++;
1190         bitnum = 0;
1073         /* replace the bits with bits from the custom routine */
1074         input_port_value newbits = (*custom->field->custom)(custom->field, custom->field->custom_param);
1075         result = (result & ~custom->field->mask) | ((newbits << custom->shift) & custom->field->mask);
11911076      }
11921077
1193      /* if this is not a DIP setting or config setting, add it to the list */
1194      else if (portentry->type != IPT_DIPSWITCH_SETTING && portentry->type != IPT_CONFIG_SETTING)
1195      {
1196         /* fatal error if we didn't hit an IPT_PORT */
1197         if (portnum < 0)
1198            fatalerror("Error in InputPort definition: expecting PORT_START");
11991078
1200         /* fatal error if too many bits */
1201         if (bitnum >= MAX_BITS_PER_PORT)
1202            fatalerror("Error in InputPort definition: too many bits for a port (%d max)", MAX_BITS_PER_PORT);
1079   /* update VBLANK bits */
1080   if (port->state->vblank != 0)
1081   {
1082      if (video_screen_get_vblank(port->machine->primary_screen))
1083         result |= port->state->vblank;
1084      else
1085         result &= ~port->state->vblank;
1086   }
12031087
1204         /* fill in the bit info */
1205         port_info[portnum].bit[bitnum].portentry = portentry;
1206         port_info[portnum].bit[bitnum].impulse = 0;
1207         port_info[portnum].bit[bitnum++].last = 0;
1088   /* apply active high/low state to digital, custom, and VBLANK inputs */
1089   result ^= port->state->defvalue;
12081090
1209         /* if this is a custom input, add it to the list */
1210         if (portentry->custom != NULL)
1091   /* merge in analog portions */
1092   for (analog = port->state->analoglist; analog != NULL; analog = analog->next)
1093      if (input_condition_true(port->machine, &analog->field->condition))
1094      {
1095         /* start with the raw value */
1096         INT32 value = analog->accum;
1097
1098         /* interpolate if appropriate and if time has passed since the last update */
1099         if (analog->interpolate && !(analog->field->flags & ANALOG_FLAG_RESET) && portdata->last_delta_nsec != 0)
12111100         {
1212            custom_port_info *info;
1101            attoseconds_t nsec_since_last = attotime_to_attoseconds(attotime_sub(timer_get_time(), portdata->last_frame_time)) / ATTOSECONDS_PER_NANOSECOND;
1102            value = analog->previous + ((INT64)(analog->accum - analog->previous) * nsec_since_last / portdata->last_delta_nsec);
1103         }
12131104
1214            /* allocate memory */
1215            info = auto_malloc(sizeof(*info));
1216            memset(info, 0, sizeof(*info));
1105         /* apply standard analog settings */
1106         value = apply_analog_settings(value, analog);
12171107
1218            /* fill in the data */
1219            info->portentry = portentry;
1220            for (mask = portentry->mask; !(mask & 1); mask >>= 1)
1221               info->shift++;
1108         /* remap the value if needed */
1109         if (analog->field->remap_table != NULL)
1110            value = analog->field->remap_table[value];
12221111
1223            /* hook in the list */
1224            info->next = port_info[portnum].custominfo;
1225            port_info[portnum].custominfo = info;
1226         }
1112         /* invert bits if needed */
1113         if (analog->field->flags & ANALOG_FLAG_INVERT)
1114            value = ~value;
12271115
1228         /* if this is a changed input, add it to the list */
1229         else if (portentry->changed != NULL)
1230         {
1231            changed_port_info *info;
1116         /* insert into the port */
1117         result = (result & ~analog->field->mask) | ((value << analog->shift) & analog->field->mask);
1118      }
12321119
1233            /* allocate memory */
1234            info = auto_malloc(sizeof(*info));
1235            memset(info, 0, sizeof(*info));
1120   return result;
1121}
12361122
1237            /* fill in the data */
1238            info->portentry = portentry;
1239            for (mask = portentry->mask; !(mask & 1); mask >>= 1)
1240               info->shift++;
12411123
1242            /* hook in the list */
1243            info->next = port_info[portnum].changedinfo;
1244            port_info[portnum].changedinfo = info;
1245         }
1124/*-------------------------------------------------
1125    input_port_read - return the value of
1126    an input port specified by tag
1127-------------------------------------------------*/
12461128
1247         /* if this is an analog port, create an info struct for it */
1248         else if (IS_ANALOG(portentry))
1249         {
1250            analog_port_info *info;
1129input_port_value input_port_read(running_machine *machine, const char *tag)
1130{
1131   const input_port_config *port = input_port_by_tag(machine->portconfig, tag);
1132   if (port == NULL)
1133      fatalerror("Unable to locate input port '%s'", tag);
1134   return input_port_read_direct(port);
1135}
12511136
1252            /* allocate memory */
1253            info = auto_malloc(sizeof(*info));
1254            memset(info, 0, sizeof(*info));
12551137
1256            /* fill in the data */
1257            info->portentry = portentry;
1258            for (mask = portentry->mask; !(mask & 1); mask >>= 1)
1259               info->shift++;
1260            for ( ; mask & 1; mask >>= 1)
1261               info->bits++;
1138/*-------------------------------------------------
1139    input_port_read_indexed - return the value of
1140    an input port specified by tag, or a default
1141    value if the port does not exist
1142-------------------------------------------------*/
12621143
1263            /* based on the port type determine if we need absolute or relative coordinates */
1264            info->minimum = INPUT_ABSOLUTE_MIN;
1265            info->maximum = INPUT_ABSOLUTE_MAX;
1266            info->interpolate = 1;
1144input_port_value input_port_read_safe(running_machine *machine, const char *tag, UINT32 defvalue)
1145{
1146   const input_port_config *port = input_port_by_tag(machine->portconfig, tag);
1147   return (port == NULL) ? defvalue : input_port_read_direct(port);
1148}
12671149
1268            /* adjust default, min, and max so they fall in the bitmask range */
1269            portentry->default_value = (portentry->default_value & portentry->mask) >> info->shift;
1270            if (portentry->type != IPT_POSITIONAL && portentry->type != IPT_POSITIONAL_V)
1271            {
1272               portentry->analog.min = (portentry->analog.min & portentry->mask) >> info->shift;
1273               portentry->analog.max = (portentry->analog.max & portentry->mask) >> info->shift;
1274            }
12751150
1276            switch (portentry->type)
1277            {
1278               /* pedals start at and autocenter to the min range*/
1279               case IPT_PEDAL:
1280               case IPT_PEDAL2:
1281               case IPT_PEDAL3:
1282                  info->center = INPUT_ABSOLUTE_MIN;
1283                  /* force pedals to start at their scaled minimum */
1284                  info->accum = APPLY_INVERSE_SENSITIVITY(info->center, portentry->analog.sensitivity);
1285                  /* fall through to complete setup */
1151/*-------------------------------------------------
1152    input_port_read_indexed - return the value of
1153    an input port specified by index
1154-------------------------------------------------*/
12861155
1287               /* pedals, paddles and analog joysticks are absolute and autocenter */
1288               case IPT_AD_STICK_X:
1289               case IPT_AD_STICK_Y:
1290               case IPT_AD_STICK_Z:
1291               case IPT_PADDLE:
1292               case IPT_PADDLE_V:
1293                  info->absolute = 1;
1294                  info->autocenter = 1;
1295                  break;
1156input_port_value input_port_read_indexed(running_machine *machine, int portnum)
1157{
1158   const input_port_config *port = input_port_by_index(machine->portconfig, portnum);
1159   return (port == NULL) ? 0 : input_port_read_direct(port);
1160}
12961161
1297               /* lightguns are absolute as well, but don't autocenter and don't interpolate their values */
1298               case IPT_LIGHTGUN_X:
1299               case IPT_LIGHTGUN_Y:
1300                  info->absolute = 1;
1301                  info->interpolate = 0;
1302                  break;
13031162
1304               /* dials, mice and trackballs are relative devices */
1305               /* these have fixed "min" and "max" values based on how many bits are in the port */
1306               /* in addition, we set the wrap around min/max values to 512 * the min/max values */
1307               /* this takes into account the mapping that one mouse unit ~= 512 analog units */
1308               case IPT_DIAL:
1309               case IPT_DIAL_V:
1310               case IPT_MOUSE_X:
1311               case IPT_MOUSE_Y:
1312               case IPT_TRACKBALL_X:
1313               case IPT_TRACKBALL_Y:
1314                  info->absolute = 0;
1315                  info->wraps = 1;
1316                  break;
1163/*-------------------------------------------------
1164    input_port_read_crosshair - return the
1165    extracted crosshair values for the given
1166    player
1167-------------------------------------------------*/
13171168
1318               /* positional devices are abolute, but can also wrap like relative devices */
1319               /* set each position to be 512 units */
1320               case IPT_POSITIONAL:
1321               case IPT_POSITIONAL_V:
1322                  info->positionalscale = COMPUTE_SCALE(portentry->analog.max, INPUT_ABSOLUTE_MAX - INPUT_ABSOLUTE_MIN);
1323                  /* force to only use PORT_POSITIONS data */
1324                  portentry->analog.min = 0;
1325                  portentry->analog.max--;
1326                  info->autocenter = !portentry->analog.wraps;
1327                  info->wraps = portentry->analog.wraps;
1328                  break;
1169int input_port_get_crosshair_position(running_machine *machine, int player, float *x, float *y)
1170{
1171   const input_port_config *port;
1172   const input_field_config *field;
1173   int gotx = FALSE, goty = FALSE;
13291174
1330               default:
1331                  fatalerror("Unknown analog port type -- don't know if it is absolute or not");
1332                  break;
1333            }
1334
1335            if (info->absolute)
1175   /* read all the lightgun values */
1176   for (port = machine->portconfig; port != NULL; port = port->next)
1177      for (field = port->fieldlist; field != NULL; field = field->next)
1178         if (field->player == player && field->crossaxis != CROSSHAIR_AXIS_NONE)
1179            if (input_condition_true(machine, &field->condition))
13361180            {
1337               /* if we are receiving data from the OSD input as absolute,
1338                     * and the emulated port type is absolute,
1339                     * and the default port value is between min/max,
1340                     * we need to scale differently for the +/- directions.
1341                     * All other absolute types use a 1:1 scale */
1342               info->single_scale = (portentry->default_value == portentry->analog.min) || (portentry->default_value == portentry->analog.max);
1181               analog_field_state *analog = field->state->analog;
1182               INT32 rawvalue = apply_analog_settings(analog->accum, analog) & (analog->field->mask >> analog->shift);
1183               float value = (float)(rawvalue - field->state->analog->adjmin) / (float)(field->state->analog->adjmax - field->state->analog->adjmin);
13431184
1344               if (!info->single_scale)
1185               /* apply the scale and offset */
1186               if (field->crossscale < 0)
1187                  value = -(1.0 - value) * field->crossscale;
1188               else
1189                  value *= field->crossscale;
1190               value += field->crossoffset;
1191
1192               /* handle X axis */
1193               if (field->crossaxis == CROSSHAIR_AXIS_X)
13451194               {
1346                  /* axis moves in both directions from the default value */
1347
1348                  /* unsigned */
1349                  info->scalepos = COMPUTE_SCALE(portentry->analog.max - portentry->default_value, INPUT_ABSOLUTE_MAX - 0);
1350                  info->scaleneg = COMPUTE_SCALE(portentry->default_value - portentry->analog.min, 0 - INPUT_ABSOLUTE_MIN);
1351
1352                  if (portentry->analog.min > portentry->analog.max)
1195                  *x = value;
1196                  gotx = TRUE;
1197                  if (field->crossaltaxis != 0)
13531198                  {
1354                     /* signed */
1355                     info->scaleneg *= -1;
1199                     *y = field->crossaltaxis;
1200                     goty = TRUE;
13561201                  }
1202               }
13571203
1358                  /* reverse from center */
1359                  info->reverse_val = 0;
1360               }
1204               /* handle Y axis */
13611205               else
13621206               {
1363                  /* single axis that increases from default */
1364                  info->scalepos = COMPUTE_SCALE(portentry->analog.max - portentry->analog.min, INPUT_ABSOLUTE_MAX - INPUT_ABSOLUTE_MIN);
1207                  *y = value;
1208                  goty = TRUE;
1209                  if (field->crossaltaxis != 0)
1210                  {
1211                     *x = field->crossaltaxis;
1212                     gotx = TRUE;
1213                  }
1214               }
13651215
1366                  /* move from default */
1367                  if (portentry->default_value == portentry->analog.max)
1368                     info->scalepos *= -1;
1369
1370                  /* make the scaling the same for easier coding when we need to scale */
1371                  info->scaleneg = info->scalepos;
1372
1373                  /* reverse from max */
1374                  info->reverse_val = info->maximum;
1375               }
1216               /* if we got both, stop */
1217               if (gotx && goty)
1218                  break;
13761219            }
13771220
1378            /* relative and positional controls all map directly with a 512x scale factor */
1379            else
1380            {
1381               /* The relative code is set up to allow specifing PORT_MINMAX and default values. */
1382               /* The validity checks are purposely set up to not allow you to use anything other */
1383               /* a default of 0 and PORT_MINMAX(0,mask).  This is in case the need arises to use */
1384               /* this feature in the future.  Keeping the code in does not hurt anything. */
1385               if (portentry->analog.min > portentry->analog.max)
1386                  /* adjust for signed */
1387                  portentry->analog.min *= -1;
1221   return (gotx && goty);
1222}
13881223
1389               info->minimum = (portentry->analog.min - portentry->default_value) * 512;
1390               info->maximum = (portentry->analog.max - portentry->default_value) * 512;
13911224
1392               /* make the scaling the same for easier coding when we need to scale */
1393               info->scaleneg = info->scalepos = COMPUTE_SCALE(1, 512);
1225/*-------------------------------------------------
1226    input_port_update_defaults - force an update
1227    to the input port values based on current
1228    conditions
1229-------------------------------------------------*/
13941230
1395               if (portentry->analog.reset)
1396                  /* delta values reverse from center */
1397                  info->reverse_val = 0;
1398               else
1399               {
1400                  /* positional controls reverse from their max range */
1401                  info->reverse_val = info->maximum + info->minimum;
1231void input_port_update_defaults(running_machine *machine)
1232{
1233   int loopnum;
14021234
1403                  /* relative controls reverse from 1 past their max range */
1404                  if (info->positionalscale == 0)
1405                     info->reverse_val += 512;
1406               }
1407            }
1235   /* two passes to catch conditionals properly */
1236   for (loopnum = 0; loopnum < 2; loopnum++)
1237   {
1238      const input_port_config *port;
14081239
1409            /* compute scale for keypresses */
1410            info->keyscalepos = RECIP_SCALE(info->scalepos);
1411            info->keyscaleneg = RECIP_SCALE(info->scaleneg);
1240      /* loop over all input ports */
1241      for (port = machine->portconfig; port != NULL; port = port->next)
1242      {
1243         const input_field_config *field;
14121244
1413            /* hook in the list */
1414            info->next = port_info[portnum].analoginfo;
1415            port_info[portnum].analoginfo = info;
1416         }
1245         /* only clear on the first pass */
1246         if (loopnum == 0)
1247            port->state->defvalue = 0;
14171248
1418         /* if this is a digital joystick port, update info on it */
1419         else if (IS_DIGITAL_JOYSTICK(portentry))
1420         {
1421            digital_joystick_info *info = JOYSTICK_INFO_FOR_PORT(portentry);
1422            info->portentry[JOYSTICK_DIR_FOR_PORT(portentry)] = portentry;
1423            info->inuse = 1;
1424         }
1249         /* first compute the default value for the entire port */
1250         for (field = port->fieldlist; field != NULL; field = field->next)
1251            if (input_condition_true(machine, &field->condition))
1252               port->state->defvalue = (port->state->defvalue & ~field->mask) | (field->state->value & field->mask);
14251253      }
14261254   }
1255}
14271256
1428   /* run an initial update */
1429   input_port_frame_update(Machine);
1257
1258/*-------------------------------------------------
1259    apply_analog_settings - return the value of
1260    an input port
1261-------------------------------------------------*/
1262
1263static INT32 apply_analog_settings(INT32 value, analog_field_state *analog)
1264{
1265   /* apply the min/max and then the sensitivity */
1266   value = apply_analog_min_max(analog, value);
1267   value = APPLY_SENSITIVITY(value, analog->sensitivity);
1268
1269   /* apply reversal if needed */
1270   if (analog->reverse)
1271      value = analog->reverse_val - value;
1272   else if (analog->single_scale)
1273      /* it's a pedal or the default value is equal to min/max */
1274      /* so we need to adjust the center to the minimum */
1275      value -= INPUT_ABSOLUTE_MIN;
1276
1277   /* map differently for positive and negative values */
1278   if (value >= 0)
1279      value = APPLY_SCALE(value, analog->scalepos);
1280   else
1281      value = APPLY_SCALE(value, analog->scaleneg);
1282   value += analog->adjdefvalue;
1283
1284   return value;
14301285}
14311286
14321287
14331288
1434/*************************************
1435 *
1436 *  Identifies which port types are
1437 *  saved/loaded
1438 *
1439 *************************************/
1289/***************************************************************************
1290    MISC HELPER FUNCTIONS
1291***************************************************************************/
14401292
1441static int save_this_port_type(int type)
1293/*-------------------------------------------------
1294    input_condition_true - return the TRUE
1295    if the given condition attached is true
1296-------------------------------------------------*/
1297
1298int input_condition_true(running_machine *machine, const input_condition *condition)
14421299{
1443   switch (type)
1300   input_port_value condvalue;
1301
1302   /* always condition is always true */
1303   if (condition->condition == PORTCOND_ALWAYS)
1304      return TRUE;
1305
1306   /* otherwise, read the referenced port */
1307   condvalue = input_port_read(machine, condition->tag);
1308
1309   /* based on the condition encoded, determine truth */
1310   switch (condition->condition)
14441311   {
1445      case IPT_UNUSED:
1446      case IPT_END:
1447      case IPT_PORT:
1448      case IPT_DIPSWITCH_SETTING:
1449      case IPT_CONFIG_SETTING:
1450      case IPT_CATEGORY_SETTING:
1451      case IPT_VBLANK:
1452      case IPT_UNKNOWN:
1453         return 0;
1312      case PORTCOND_EQUALS:
1313         return ((condvalue & condition->mask) == condition->value);
1314
1315      case PORTCOND_NOTEQUALS:
1316         return ((condvalue & condition->mask) != condition->value);
14541317   }
1455   return 1;
1318   return TRUE;
14561319}
14571320
14581321
1322/*-------------------------------------------------
1323    input_port_string_from_token - convert an
1324    input_port_token to a default string
1325-------------------------------------------------*/
14591326
1460/*************************************
1461 *
1462 *  Input port configuration read
1463 *
1464 *************************************/
1327const char *input_port_string_from_token(const input_port_token token)
1328{
1329   int index;
14651330
1466#ifdef UNUSED_FUNCTION
1467INLINE input_code get_default_code(int config_type, int type)
1331   /* 0 is an invalid index */
1332   if (token.i == 0)
1333      return NULL;
1334
1335   /* if the index is greater than the count, assume it to be a pointer */
1336   if (token.i >= INPUT_STRING_COUNT)
1337      return token.stringptr;
1338
1339   /* otherwise, scan the list for a matching string and return it */
1340   for (index = 0; index < ARRAY_LENGTH(input_port_default_strings); index++)
1341      if (input_port_default_strings[index].id == token.i)
1342         return input_port_default_strings[index].string;
1343   return "(Unknown Default)";
1344}
1345
1346
1347
1348/*-------------------------------------------------
1349    input_port_read_handler* - return a memory
1350    handler corresponding to a given input port
1351    tag
1352-------------------------------------------------*/
1353
1354read8_machine_func input_port_read_handler8(const input_port_config *portlist, const char *tag)
14681355{
1469   switch (type)
1470   {
1471      case IPT_DIPSWITCH_NAME:
1472      case IPT_CATEGORY_NAME:
1473         return SEQCODE_END;
1356   int portnum = get_port_index(portlist, tag);
1357   return (portnum == -1) ? SMH_NOP : port_handler8[portnum];
1358}
14741359
1475      default:
1476         if (config_type != CONFIG_TYPE_GAME)
1477            return SEQCODE_END;
1478         else
1479            return SEQCODE_DEFAULT;
1480   }
1481   return SEQCODE_END;
1360
1361read16_machine_func input_port_read_handler16(const input_port_config *portlist, const char *tag)
1362{
1363   int portnum = get_port_index(portlist, tag);
1364   return (portnum == -1) ? SMH_NOP : port_handler16[portnum];
14821365}
1483#endif
14841366
14851367
1486INLINE int string_to_seq_index(const char *string)
1368read32_machine_func input_port_read_handler32(const input_port_config *portlist, const char *tag)
14871369{
1488   int seqindex;
1370   int portnum = get_port_index(portlist, tag);
1371   return (portnum == -1) ? SMH_NOP : port_handler32[portnum];
1372}
14891373
1490   for (seqindex = 0; seqindex < ARRAY_LENGTH(seqtypestrings); seqindex++)
1491      if (!mame_stricmp(string, seqtypestrings[seqindex]))
1492         return seqindex;
14931374
1494   return -1;
1375read64_machine_func input_port_read_handler64(const input_port_config *portlist, const char *tag)
1376{
1377   return SMH_NOP;
14951378}
14961379
14971380
1498static void apply_remaps(int count, const input_code *oldtable, const input_code *newtable)
1381
1382/***************************************************************************
1383    INITIALIZATION HELPERS
1384***************************************************************************/
1385
1386/*-------------------------------------------------
1387    init_port_types - initialize the default
1388    type list
1389-------------------------------------------------*/
1390
1391static void init_port_types(running_machine *machine)
14991392{
1500   int remapnum;
1393   input_port_private *portdata = machine->input_port_data;
1394   input_type_state **stateptr;
1395   input_type_state *curtype;
1396   input_type_desc *lasttype = NULL;
1397   int seqtype, typenum;
15011398
1502   /* loop over the remapping table, operating only if something was specified */
1503   for (remapnum = 0; remapnum < count; remapnum++)
1399   /* convert the array into a list of type states that can be modified */
1400   portdata->typestatelist = NULL;
1401   stateptr = &portdata->typestatelist;
1402   for (typenum = 0; typenum < ARRAY_LENGTH(core_types); typenum++)
15041403   {
1505      input_code oldcode = oldtable[remapnum];
1506      input_code newcode = newtable[remapnum];
1507      int portnum;
1404      /* allocate memory for the state and link it to the end of the list */
1405      *stateptr = auto_malloc(sizeof(**stateptr));
1406      memset(*stateptr, 0, sizeof(**stateptr));
15081407
1509      /* loop over all default ports, remapping the requested keys */
1510      for (portnum = 0; default_ports[portnum].type != IPT_END; portnum++)
1511      {
1512         input_port_default_entry *defport = &default_ports[portnum];
1513         int seqnum;
1408      /* copy the type description and link the previous description to it */
1409      (*stateptr)->typedesc = core_types[typenum];
1410      if (lasttype != NULL)
1411         lasttype->next = &(*stateptr)->typedesc;
1412      lasttype = &(*stateptr)->typedesc;
15141413
1515         /* remap anything in the default sequences */
1516         for (seqnum = 0; seqnum < ARRAY_LENGTH(defport->defaultseq.code); seqnum++)
1517            if (defport->defaultseq.code[seqnum] == oldcode)
1518               defport->defaultseq.code[seqnum] = newcode;
1519         for (seqnum = 0; seqnum < ARRAY_LENGTH(defport->defaultdecseq.code); seqnum++)
1520            if (defport->defaultdecseq.code[seqnum] == oldcode)
1521               defport->defaultdecseq.code[seqnum] = newcode;
1522         for (seqnum = 0; seqnum < ARRAY_LENGTH(defport->defaultincseq.code); seqnum++)
1523            if (defport->defaultincseq.code[seqnum] == oldcode)
1524               defport->defaultincseq.code[seqnum] = newcode;
1525      }
1414      /* advance */
1415      stateptr = &(*stateptr)->next;
15261416   }
1417
1418   /* ask the OSD to customize the list */
1419   osd_customize_input_type_list(&portdata->typestatelist->typedesc);
1420
1421   /* now iterate over the OSD-modified types */
1422   for (curtype = portdata->typestatelist; curtype != NULL; curtype = curtype->next)
1423   {
1424      /* first copy all the OSD-updated sequences into our current state */
1425      for (seqtype = 0; seqtype < ARRAY_LENGTH(curtype->seq); seqtype++)
1426         curtype->seq[seqtype] = curtype->typedesc.seq[seqtype];
1427
1428      /* also make a lookup table mapping type/player to the appropriate type list entry */
1429      portdata->type_to_typestate[curtype->typedesc.type][curtype->typedesc.player] = curtype;
1430   }
15271431}
15281432
15291433
1434/*-------------------------------------------------
1435    init_port_state - initialize the live port
1436    states based on the tokens
1437-------------------------------------------------*/
15301438
1531static int apply_config_to_default(xml_data_node *portnode, int type, int player, input_seq *newseq)
1439static void init_port_state(running_machine *machine)
15321440{
1533   int portnum;
1441   const char *joystick_map_default = options_get_string(mame_options(), OPTION_JOYSTICK_MAP);
1442   input_port_private *portdata = machine->input_port_data;
1443   const input_field_config *field;
1444   const input_port_config *port;
15341445
1535   /* find a matching port in the list */
1536   for (portnum = 0; portnum < ARRAY_LENGTH(default_ports_backup); portnum++)
1446   /* allocate live structures to mirror the configuration */
1447   for (port = machine->portconfig; port != NULL; port = port->next)
15371448   {
1538      input_port_default_entry *updateport = &default_ports[portnum];
1539      if (updateport->type == type && updateport->player == player)
1449      analog_field_state **analogstatetail;
1450      callback_field_info **custominfotail;
1451      callback_field_info **changedinfotail;
1452      input_port_state *portstate;
1453
1454      /* allocate a new input_port_info structure */
1455      portstate = auto_malloc(sizeof(*portstate));
1456      memset(portstate, 0, sizeof(*portstate));
1457      ((input_port_config *)port)->state = portstate;
1458      ((input_port_config *)port)->machine = machine;
1459
1460      /* start with tail pointers to all the data */
1461      analogstatetail = &portstate->analoglist;
1462      custominfotail = &portstate->customlist;
1463      changedinfotail = &portstate->changedlist;
1464
1465      /* iterate over fields */
1466      for (field = port->fieldlist; field != NULL; field = field->next)
15401467      {
1541         /* copy the sequence(s) that were specified */
1542         if (input_seq_get_1(&newseq[0]) != INPUT_CODE_INVALID)
1543            updateport->defaultseq = newseq[0];
1544         if (input_seq_get_1(&newseq[1]) != INPUT_CODE_INVALID)
1545            updateport->defaultdecseq = newseq[1];
1546         if (input_seq_get_1(&newseq[2]) != INPUT_CODE_INVALID)
1547            updateport->defaultincseq = newseq[2];
1548         return 1;
1468         input_field_state *fieldstate;
1469         int seqtype;
1470
1471         /* allocate a new input_field_info structure */
1472         fieldstate = auto_malloc(sizeof(*fieldstate));
1473         memset(fieldstate, 0, sizeof(*fieldstate));
1474         ((input_field_config *)field)->state = fieldstate;
1475
1476         /* fill in the basic values */
1477         for (seqtype = 0; seqtype < ARRAY_LENGTH(fieldstate->seq); seqtype++)
1478            fieldstate->seq[seqtype] = field->seq[seqtype];
1479         fieldstate->value = field->defvalue;
1480
1481         /* if this is an analog field, allocate memory for the analog data */
1482         if (field->type >= __ipt_analog_start && field->type <= __ipt_analog_end)
1483         {
1484            *analogstatetail = fieldstate->analog = init_field_analog_state(field);
1485            analogstatetail = &(*analogstatetail)->next;
1486         }
1487
1488         /* if this is a digital joystick field, make a note of it */
1489         if (field->type >= __ipt_digital_joystick_start && field->type <= __ipt_digital_joystick_end)
1490         {
1491            fieldstate->joystick = &portdata->joystick_info[field->player][(field->type - __ipt_digital_joystick_start) / 4];
1492            fieldstate->joydir = (field->type - __ipt_digital_joystick_start) % 4;
1493            fieldstate->joystick->field[fieldstate->joydir] = field;
1494            fieldstate->joystick->inuse = TRUE;
1495         }
1496
1497         /* if this entry has custom callback, allocate memory for the tracking structure */
1498         if (field->custom != NULL)
1499         {
1500            *custominfotail = init_field_callback_info(field);
1501            custominfotail = &(*custominfotail)->next;
1502         }
1503
1504         /* if this entry has changed callback, allocate memory for the tracking structure */
1505         if (field->changed != NULL)
1506         {
1507            *changedinfotail = init_field_callback_info(field);
1508            changedinfotail = &(*changedinfotail)->next;
1509         }
15491510      }
15501511   }
1551   return 0;
1512
1513   /* handle autoselection of devices */
1514   init_autoselect_devices(machine->portconfig, IPT_PADDLE,      IPT_PADDLE_V,     0,              OPTION_PADDLE_DEVICE,     "paddle");
1515   init_autoselect_devices(machine->portconfig, IPT_AD_STICK_X,  IPT_AD_STICK_Y,   IPT_AD_STICK_Z, OPTION_ADSTICK_DEVICE,    "analog joystick");
1516   init_autoselect_devices(machine->portconfig, IPT_LIGHTGUN_X,  IPT_LIGHTGUN_Y,   0,              OPTION_LIGHTGUN_DEVICE,   "lightgun");
1517   init_autoselect_devices(machine->portconfig, IPT_PEDAL,       IPT_PEDAL2,       IPT_PEDAL3,     OPTION_PEDAL_DEVICE,      "pedal");
1518   init_autoselect_devices(machine->portconfig, IPT_DIAL,        IPT_DIAL_V,       0,              OPTION_DIAL_DEVICE,       "dial");
1519   init_autoselect_devices(machine->portconfig, IPT_TRACKBALL_X, IPT_TRACKBALL_Y,  0,              OPTION_TRACKBALL_DEVICE,  "trackball");
1520   init_autoselect_devices(machine->portconfig, IPT_POSITIONAL,  IPT_POSITIONAL_V, 0,              OPTION_POSITIONAL_DEVICE, "positional");
1521   init_autoselect_devices(machine->portconfig, IPT_MOUSE_X,     IPT_MOUSE_Y,      0,              OPTION_MOUSE_DEVICE,      "mouse");
1522
1523   /* look for 4-way joysticks and change the default map if we find any */
1524   if (joystick_map_default[0] == 0 || strcmp(joystick_map_default, "auto") == 0)
1525      for (port = machine->portconfig; port != NULL; port = port->next)
1526         for (field = port->fieldlist; field != NULL; field = field->next)
1527            if (field->state->joystick != NULL && field->way == 4)
1528            {
1529               input_device_set_joystick_map(-1, (field->flags & FIELD_FLAG_ROTATED) ? joystick_map_4way_diagonal : joystick_map_4way_sticky);
1530               break;
1531            }
15521532}
15531533
15541534
1555static int apply_config_to_current(xml_data_node *portnode, int type, int player, input_seq *newseq)
1535/*-------------------------------------------------
1536    init_autoselect_devices - autoselect a single
1537    device based on the input port list passed
1538    in and the corresponding option
1539-------------------------------------------------*/
1540
1541static void init_autoselect_devices(const input_port_config *portlist, int type1, int type2, int type3, const char *option, const char *ananame)
15561542{
1557   input_port_entry *updateport;
1558   int mask, defvalue, index;
1543   const char *stemp = options_get_string(mame_options(), option);
1544   input_device_class autoenable = DEVICE_CLASS_KEYBOARD;
1545   const char *autostring = "keyboard";
1546   const input_field_config *field;
1547   const input_port_config *port;
15591548
1560   /* read the mask, index, and defvalue attributes */
1561   index = xml_get_attribute_int(portnode, "index", 0);
1562   mask = xml_get_attribute_int(portnode, "mask", 0);
1563   defvalue = xml_get_attribute_int(portnode, "defvalue", 0);
1549   /* if nothing specified, ignore the option */
1550   if (stemp[0] == 0)
1551      return;
15641552
1565   /* find the indexed port; we scan the array to make sure we don't read past the end */
1566   for (updateport = input_ports_default; updateport->type != IPT_END; updateport++)
1567      if (index-- == 0)
1568         break;
1569
1570   /* verify that it matches */
1571   if (updateport->type == type && updateport->player == player &&
1572      updateport->mask == mask && (updateport->default_value & mask) == (defvalue & mask))
1553   /* extract valid strings */
1554   if (strcmp(stemp, "mouse") == 0)
15731555   {
1574      const char *revstring;
1556      autoenable = DEVICE_CLASS_MOUSE;
1557      autostring = "mouse";
1558   }
1559   else if (strcmp(stemp, "joystick") == 0)
1560   {
1561      autoenable = DEVICE_CLASS_JOYSTICK;
1562      autostring = "joystick";
1563   }
1564   else if (strcmp(stemp, "lightgun") == 0)
1565   {
1566      autoenable = DEVICE_CLASS_LIGHTGUN;
1567      autostring = "lightgun";
1568   }
1569   else if (strcmp(stemp, "none") == 0)
1570   {
1571      /* nothing specified */
1572      return;
1573   }
1574   else if (strcmp(stemp, "keyboard") != 0)
1575      mame_printf_error("Invalid %s value %s; reverting to keyboard\n", option, stemp);
15751576
1576      /* point to the real port */
1577      updateport = Machine->input_ports + (updateport - input_ports_default);
1577   /* only scan the list if we haven't already enabled this class of control */
1578   if (!input_device_class_enabled(autoenable))
1579      for (port = portlist; port != NULL; port = port->next)
1580         for (field = port->fieldlist; field != NULL; field = field->next)
15781581
1579      /* fill in the data from the attributes */
1580      if (!port_type_is_analog(updateport->type))
1581         updateport->default_value = xml_get_attribute_int(portnode, "value", updateport->default_value);
1582      updateport->analog.delta = xml_get_attribute_int(portnode, "keydelta", updateport->analog.delta);
1583      updateport->analog.centerdelta = xml_get_attribute_int(portnode, "centerdelta", updateport->analog.centerdelta);
1584      updateport->analog.sensitivity = xml_get_attribute_int(portnode, "sensitivity", updateport->analog.sensitivity);
1585      revstring = xml_get_attribute_string(portnode, "reverse", NULL);
1586      if (revstring)
1587         updateport->analog.reverse = (strcmp(revstring, "yes") == 0);
1582            /* if this port type is in use, apply the autoselect criteria */
1583            if ((type1 != 0 && field->type == type1) ||
1584               (type2 != 0 && field->type == type2) ||
1585               (type3 != 0 && field->type == type3))
1586            {
1587               mame_printf_verbose("Input: Autoenabling %s due to presence of a %s\n", autostring, ananame);
1588               input_device_class_enable(autoenable, TRUE);
1589               break;
1590            }
1591}
15881592
1589      /* copy the sequence(s) that were specified */
1590      if (input_seq_get_1(&newseq[0]) != INPUT_CODE_INVALID)
1591         updateport->seq = newseq[0];
1592      if (input_seq_get_1(&newseq[1]) != INPUT_CODE_INVALID)
1593         updateport->analog.decseq = newseq[1];
1594      if (input_seq_get_1(&newseq[2]) != INPUT_CODE_INVALID)
1595         updateport->analog.incseq = newseq[2];
1596      return 1;
1597   }
1598   return 0;
1593
1594/*-------------------------------------------------
1595    init_field_callback_info - allocate and populate
1596    information about a changed or custom
1597    callback
1598-------------------------------------------------*/
1599
1600static callback_field_info *init_field_callback_info(const input_field_config *field)
1601{
1602   callback_field_info *info;
1603   input_port_value mask;
1604
1605   /* allocate memory */
1606   info = auto_malloc(sizeof(*info));
1607   memset(info, 0, sizeof(*info));
1608
1609   /* fill in the data */
1610   info->field = field;
1611   for (mask = field->mask; !(mask & 1); mask >>= 1)
1612      info->shift++;
1613
1614   return info;
15991615}
16001616
16011617
1602static void input_port_load(int config_type, xml_data_node *parentnode)
1618/*-------------------------------------------------
1619    init_field_analog_state - allocate and populate
1620    information about an analog port
1621-------------------------------------------------*/
1622
1623static analog_field_state *init_field_analog_state(const input_field_config *field)
16031624{
1604   xml_data_node *portnode;
1605   int seqnum;
1625   analog_field_state *state;
1626   input_port_value mask;
16061627
1607   /* in the completion phase, we finish the initialization with the final ports */
1608   if (config_type == CONFIG_TYPE_FINAL)
1609      input_port_postload();
1628   /* allocate memory */
1629   state = auto_malloc(sizeof(*state));
1630   memset(state, 0, sizeof(*state));
16101631
1611   /* early exit if no data to parse */
1612   if (!parentnode)
1613      return;
1632   /* compute the shift amount and number of bits */
1633   for (mask = field->mask; !(mask & 1); mask >>= 1)
1634      state->shift++;
16141635
1615   /* iterate over all the remap nodes for controller configs only */
1616   if (config_type == CONFIG_TYPE_CONTROLLER)
1636   /* initialize core data */
1637   state->field = field;
1638   state->adjdefvalue = (field->defvalue & field->mask) >> state->shift;
1639   state->adjmin = (field->min & field->mask) >> state->shift;
1640   state->adjmax = (field->max & field->mask) >> state->shift;
1641   state->sensitivity = field->sensitivity;
1642   state->reverse = ((field->flags & ANALOG_FLAG_REVERSE) != 0);
1643   state->delta = field->delta;
1644   state->centerdelta = field->centerdelta;
1645   state->minimum = INPUT_ABSOLUTE_MIN;
1646   state->maximum = INPUT_ABSOLUTE_MAX;
1647
1648   /* set basic parameters based on the configured type */
1649   switch (field->type)
16171650   {
1618      input_code *oldtable, *newtable;
1619      xml_data_node *remapnode;
1620      int count;
1651      /* pedals start at and autocenter to the min range */
1652      case IPT_PEDAL:
1653      case IPT_PEDAL2:
1654      case IPT_PEDAL3:
1655         state->center = INPUT_ABSOLUTE_MIN;
1656         state->accum = APPLY_INVERSE_SENSITIVITY(state->center, state->sensitivity);
1657         state->absolute = TRUE;
1658         state->autocenter = TRUE;
1659         state->interpolate = TRUE;
1660         break;
16211661
1622      /* count items first so we can allocate */
1623      count = 0;
1624      for (remapnode = xml_get_sibling(parentnode->child, "remap"); remapnode; remapnode = xml_get_sibling(remapnode->next, "remap"))
1625         count++;
1662      /* paddles and analog joysticks are absolute and autocenter */
1663      case IPT_AD_STICK_X:
1664      case IPT_AD_STICK_Y:
1665      case IPT_AD_STICK_Z:
1666      case IPT_PADDLE:
1667      case IPT_PADDLE_V:
1668         state->absolute = TRUE;
1669         state->autocenter = TRUE;
1670         state->interpolate = TRUE;
1671         break;
16261672
1627      /* if we have some, deal with them */
1628      if (count > 0)
1673      /* lightguns are absolute as well, but don't autocenter and don't interpolate their values */
1674      case IPT_LIGHTGUN_X:
1675      case IPT_LIGHTGUN_Y:
1676         state->absolute = TRUE;
1677         state->autocenter = FALSE;
1678         state->interpolate = FALSE;
1679         break;
1680
1681      /* dials, mice and trackballs are relative devices */
1682      /* these have fixed "min" and "max" values based on how many bits are in the port */
1683      /* in addition, we set the wrap around min/max values to 512 * the min/max values */
1684      /* this takes into account the mapping that one mouse unit ~= 512 analog units */
1685      case IPT_DIAL:
1686      case IPT_DIAL_V:
1687      case IPT_MOUSE_X:
1688      case IPT_MOUSE_Y:
1689      case IPT_TRACKBALL_X:
1690      case IPT_TRACKBALL_Y:
1691         state->absolute = FALSE;
1692         state->wraps = TRUE;
1693         state->interpolate = TRUE;
1694         break;
1695
1696      /* positional devices are abolute, but can also wrap like relative devices */
1697      /* set each position to be 512 units */
1698      case IPT_POSITIONAL:
1699      case IPT_POSITIONAL_V:
1700         state->positionalscale = COMPUTE_SCALE(state->adjmax, INPUT_ABSOLUTE_MAX - INPUT_ABSOLUTE_MIN);
1701         state->adjmin = 0;
1702         state->adjmax--;
1703         state->wraps = ((field->flags & ANALOG_FLAG_WRAPS) != 0);
1704         state->autocenter = !state->wraps;
1705         break;
1706
1707      default:
1708         fatalerror("Unknown analog port type -- don't know if it is absolute or not");
1709         break;
1710   }
1711
1712   /* further processing for absolute controls */
1713   if (state->absolute)
1714   {
1715      /* if the default value is pegged at the min or max, use a single scale value for the whole axis */
1716      state->single_scale = (state->adjdefvalue == state->adjmin) || (state->adjdefvalue == state->adjmax);
1717
1718      /* if not "single scale", compute separate scales for each side of the default */
1719      if (!state->single_scale)
16291720      {
1630         /* allocate tables */
1631         oldtable = malloc_or_die(count * sizeof(*oldtable));
1632         newtable = malloc_or_die(count * sizeof(*newtable));
1721         /* unsigned */
1722         state->scalepos = COMPUTE_SCALE(state->adjmax - state->adjdefvalue, INPUT_ABSOLUTE_MAX - 0);
1723         state->scaleneg = COMPUTE_SCALE(state->adjdefvalue - state->adjmin, 0 - INPUT_ABSOLUTE_MIN);
16331724
1634         /* build up the remap table */
1635         count = 0;
1636         for (remapnode = xml_get_sibling(parentnode->child, "remap"); remapnode; remapnode = xml_get_sibling(remapnode->next, "remap"))
1637         {
1638            input_code origcode = input_code_from_token(xml_get_attribute_string(remapnode, "origcode", ""));
1639            input_code newcode = input_code_from_token(xml_get_attribute_string(remapnode, "newcode", ""));
1640            if (origcode != INPUT_CODE_INVALID && newcode != INPUT_CODE_INVALID)
1641            {
1642               oldtable[count] = origcode;
1643               newtable[count] = newcode;
1644               count++;
1645            }
1646         }
1725         if (state->adjmin > state->adjmax)
1726            state->scaleneg = -state->scaleneg;
16471727
1648         /* apply it then free the tables */
1649         apply_remaps(count, oldtable, newtable);
1650         free(oldtable);
1651         free(newtable);
1728         /* reverse point is at center */
1729         state->reverse_val = 0;
16521730      }
1731      else
1732      {
1733         /* single axis that increases from default */
1734         state->scalepos = COMPUTE_SCALE(state->adjmax - state->adjmin, INPUT_ABSOLUTE_MAX - INPUT_ABSOLUTE_MIN);
1735
1736         /* move from default */
1737         if (state->adjdefvalue == state->adjmax)
1738            state->scalepos = -state->scalepos;
1739
1740         /* make the scaling the same for easier coding when we need to scale */
1741         state->scaleneg = state->scalepos;
1742
1743         /* reverse point is at max */
1744         state->reverse_val = state->maximum;
1745      }
16531746   }
16541747
1655   /* iterate over all the port nodes */
1656   for (portnode = xml_get_sibling(parentnode->child, "port"); portnode; portnode = xml_get_sibling(portnode->next, "port"))
1748   /* relative and positional controls all map directly with a 512x scale factor */
1749   else
16571750   {
1658      input_seq newseq[3], tempseq;
1659      xml_data_node *seqnode;
1660      int type, player;
1751      /* The relative code is set up to allow specifing PORT_MINMAX and default values. */
1752      /* The validity checks are purposely set up to not allow you to use anything other */
1753      /* a default of 0 and PORT_MINMAX(0,mask).  This is in case the need arises to use */
1754      /* this feature in the future.  Keeping the code in does not hurt anything. */
1755      if (state->adjmin > state->adjmax)
1756         /* adjust for signed */
1757         state->adjmin = -state->adjmin;
16611758
1662      /* get the basic port info from the attributes */
1663      type = token_to_port_type(xml_get_attribute_string(portnode, "type", ""), &player);
1759      state->minimum = (state->adjmin - state->adjdefvalue) * 512;
1760      state->maximum = (state->adjmax - state->adjdefvalue) * 512;
16641761
1665      /* initialize sequences to invalid defaults */
1666      for (seqnum = 0; seqnum < 3; seqnum++)
1667         input_seq_set_1(&newseq[seqnum], INPUT_CODE_INVALID);
1762      /* make the scaling the same for easier coding when we need to scale */
1763      state->scaleneg = state->scalepos = COMPUTE_SCALE(1, 512);
16681764
1669      /* loop over new sequences */
1670      for (seqnode = xml_get_sibling(portnode->child, "newseq"); seqnode; seqnode = xml_get_sibling(seqnode->next, "newseq"))
1765      if (field->flags & ANALOG_FLAG_RESET)
1766         /* delta values reverse from center */
1767         state->reverse_val = 0;
1768      else
16711769      {
1672         /* with a valid type, parse out the new sequence */
1673         seqnum = string_to_seq_index(xml_get_attribute_string(seqnode, "type", ""));
1674         if (seqnum != -1)
1675            if (seqnode->value != NULL)
1676            {
1677               if (strcmp(seqnode->value, "NONE") == 0)
1678                  input_seq_set_0(&newseq[seqnum]);
1679               else if (input_seq_from_tokens(seqnode->value, &tempseq) != 0)
1680                  newseq[seqnum] = tempseq;
1681            }
1770         /* positional controls reverse from their max range */
1771         state->reverse_val = state->maximum + state->minimum;
1772
1773         /* relative controls reverse from 1 past their max range */
1774         if (state->positionalscale == 0)
1775            state->reverse_val += 512;
16821776      }
1683
1684      /* if we're loading default ports, apply to the default_ports */
1685      if (config_type != CONFIG_TYPE_GAME)
1686         apply_config_to_default(portnode, type, player, newseq);
1687      else
1688         apply_config_to_current(portnode, type, player, newseq);
16891777   }
16901778
1691   /* after applying the controller config, push that back into the backup, since that is */
1692   /* what we will diff against */
1693   if (config_type == CONFIG_TYPE_CONTROLLER)
1694      memcpy(default_ports_backup, default_ports, sizeof(default_ports_backup));
1779   /* compute scale for keypresses */
1780   state->keyscalepos = RECIP_SCALE(state->scalepos);
1781   state->keyscaleneg = RECIP_SCALE(state->scaleneg);
1782
1783   return state;
16951784}
16961785
16971786
16981787
1699/*************************************
1700 *
1701 *  Input port configuration write
1702 *
1703 *************************************/
1788/***************************************************************************
1789    ONCE-PER-FRAME UPDATES
1790***************************************************************************/
17041791
1705static void add_sequence(xml_data_node *parentnode, int type, int porttype, const input_seq *seq)
1792/*-------------------------------------------------
1793    frame_update_callback - system-wide callback to
1794    update the input ports once per frame, but
1795    only if we are not paused
1796-------------------------------------------------*/
1797
1798static void frame_update_callback(running_machine *machine)
17061799{
1707   astring *seqstring = astring_alloc();
1708   xml_data_node *seqnode;
1800   /* if we're paused, don't do anything */
1801   if (mame_is_paused(machine))
1802      return;
17091803
1710   /* get the string for the sequence */
1711   if (input_seq_get_1(seq) == SEQCODE_END)
1712      astring_cpyc(seqstring, "NONE");
1713   else
1714      input_seq_to_tokens(seqstring, seq);
1715
1716   /* add the new node */
1717   seqnode = xml_add_child(parentnode, "newseq", astring_c(seqstring));
1718   if (seqnode)
1719      xml_set_attribute(seqnode, "type", seqtypestrings[type]);
1720   astring_free(seqstring);
1804   /* otherwise, use the common code */
1805   frame_update(machine);
17211806}
17221807
17231808
1724static void save_default_inputs(xml_data_node *parentnode)
1809/*-------------------------------------------------
1810    frame_update - core logic for per-frame input
1811    port updating
1812-------------------------------------------------*/
1813
1814static void frame_update(running_machine *machine)
17251815{
1726   int portnum;
1816   input_port_private *portdata = machine->input_port_data;
1817   int ui_visible = ui_is_menu_active() || ui_is_slider_active();
1818   attotime curtime = timer_get_time();
1819   const input_port_config *port;
17271820
1728   /* iterate over ports */
1729   for (portnum = 0; portnum < ARRAY_LENGTH(default_ports_backup); portnum++)
1821profiler_mark(PROFILER_INPUT);
1822
1823   /* record/playback information about the current frame */
1824   playback_frame(machine, curtime);
1825   record_frame(machine, curtime);
1826
1827   /* track the duration of the previous frame */
1828   portdata->last_delta_nsec = attotime_to_attoseconds(attotime_sub(curtime, portdata->last_frame_time)) / ATTOSECONDS_PER_NANOSECOND;
1829   portdata->last_frame_time = curtime;
1830
1831   /* update the digital joysticks */
1832   frame_update_digital_joysticks(machine);
1833
1834   /* compute default values for all the ports */
1835   input_port_update_defaults(machine);
1836
1837   /* loop over all input ports */
1838   for (port = machine->portconfig; port != NULL; port = port->next)
17301839   {
1731      input_port_default_entry *defport = &default_ports_backup[portnum];
1732      input_port_default_entry *curport = &default_ports[portnum];
1840      const input_field_config *field;
1841      callback_field_info *changed;
1842      input_port_value newvalue;
17331843
1734      /* only save if something has changed and this port is a type we save */
1735      if (save_this_port_type(defport->type) &&
1736         (input_seq_cmp(&defport->defaultseq, &curport->defaultseq) != 0 ||
1737          input_seq_cmp(&defport->defaultdecseq, &curport->defaultdecseq) != 0 ||
1738          input_seq_cmp(&defport->defaultincseq, &curport->defaultincseq) != 0))
1844      /* start with 0 values for the digital and VBLANK bits */
1845      port->state->digital = 0;
1846      port->state->vblank = 0;
1847
1848      /* now loop back and modify based on the inputs */
1849      for (field = port->fieldlist; field != NULL; field = field->next)
1850         if (input_condition_true(port->machine, &field->condition))
1851         {
1852            /* accumulate VBLANK bits */
1853            if (field->type == IPT_VBLANK)
1854               port->state->vblank ^= field->mask;
1855
1856            /* handle analog inputs */
1857            else if (field->state->analog != NULL)
1858               frame_update_analog_field(field->state->analog);
1859
1860            /* handle non-analog types, but only when the UI isn't visible */
1861            else if (!ui_visible && frame_get_digital_field_state(field))
1862               port->state->digital |= field->mask;
1863         }
1864
1865#ifdef MESS
1866      /* hook for MESS's natural keyboard support */
1867      mess_input_port_update_hook(machine, port);
1868#endif /* MESS */
1869
1870      /* call changed handlers */
1871      newvalue = input_port_read_direct(port);
1872      for (changed = port->state->changedlist; changed; changed = changed->next)
1873         if (input_condition_true(port->machine, &changed->field->condition))
1874         {
1875            input_port_value oldbits = (port->state->lastvalue & changed->field->mask) >> changed->shift;
1876            input_port_value newbits = (newvalue & changed->field->mask) >> changed->shift;
1877
1878            /* if the bits have  changed, call the handler */
1879            if (oldbits != newbits)
1880               (*changed->field->changed)(changed->field, changed->field->changed_param, oldbits, newbits);
1881         }
1882
1883      /* remember the last value */
1884      port->state->lastvalue = newvalue;
1885   }
1886
1887   /* handle playback/record */
1888   for (port = machine->portconfig; port != NULL; port = port->next)
1889   {
1890      playback_port(port);
1891      record_port(port);
1892   }
1893
1894profiler_mark(PROFILER_END);
1895}
1896
1897
1898/*-------------------------------------------------
1899    frame_update_digital_joysticks - update the
1900    state of digital joysticks prior to
1901    accumulating the results in a port
1902-------------------------------------------------*/
1903
1904static void frame_update_digital_joysticks(running_machine *machine)
1905{
1906   input_port_private *portdata = machine->input_port_data;
1907   int player, joyindex;
1908
1909   /* loop over all the joysticks */
1910   for (player = 0; player < MAX_PLAYERS; player++)
1911      for (joyindex = 0; joyindex < DIGITAL_JOYSTICKS_PER_PLAYER; joyindex++)
17391912      {
1740         /* add a new port node */
1741         xml_data_node *portnode = xml_add_child(parentnode, "port", NULL);
1742         if (portnode)
1913         digital_joystick_state *joystick = &portdata->joystick_info[player][joyindex];
1914         if (joystick->inuse)
17431915         {
1744            /* add the port information and attributes */
1745            xml_set_attribute(portnode, "type", port_type_to_token(defport->type, defport->player));
1916            joystick->previous = joystick->current;
1917            joystick->current = 0;
17461918
1747            /* add only the sequences that have changed from the defaults */
1748            if (input_seq_cmp(&defport->defaultseq, &curport->defaultseq) != 0)
1749               add_sequence(portnode, 0, defport->type, &curport->defaultseq);
1750            if (input_seq_cmp(&defport->defaultdecseq, &curport->defaultdecseq) != 0)
1751               add_sequence(portnode, 1, defport->type, &curport->defaultdecseq);
1752            if (input_seq_cmp(&defport->defaultincseq, &curport->defaultincseq) != 0)
1753               add_sequence(portnode, 2, defport->type, &curport->defaultincseq);
1919            /* read all the associated ports */
1920            if (joystick->field[JOYDIR_UP] != NULL && input_seq_pressed(input_field_seq(joystick->field[JOYDIR_UP], SEQ_TYPE_STANDARD)))
1921               joystick->current |= JOYDIR_UP_BIT;
1922            if (joystick->field[JOYDIR_DOWN] != NULL && input_seq_pressed(input_field_seq(joystick->field[JOYDIR_DOWN], SEQ_TYPE_STANDARD)))
1923               joystick->current |= JOYDIR_DOWN_BIT;
1924            if (joystick->field[JOYDIR_LEFT] != NULL && input_seq_pressed(input_field_seq(joystick->field[JOYDIR_LEFT], SEQ_TYPE_STANDARD)))
1925               joystick->current |= JOYDIR_LEFT_BIT;
1926            if (joystick->field[JOYDIR_RIGHT] != NULL && input_seq_pressed(input_field_seq(joystick->field[JOYDIR_RIGHT], SEQ_TYPE_STANDARD)))
1927               joystick->current |= JOYDIR_RIGHT_BIT;
1928
1929            /* lock out opposing directions (left + right or up + down) */
1930            if ((joystick->current & (JOYDIR_UP_BIT | JOYDIR_DOWN_BIT)) == (JOYDIR_UP_BIT | JOYDIR_DOWN_BIT))
1931               joystick->current &= ~(JOYDIR_UP_BIT | JOYDIR_DOWN_BIT);
1932            if ((joystick->current & (JOYDIR_LEFT_BIT | JOYDIR_RIGHT_BIT)) == (JOYDIR_LEFT_BIT | JOYDIR_RIGHT_BIT))
1933               joystick->current &= ~(JOYDIR_LEFT_BIT | JOYDIR_RIGHT_BIT);
1934
1935            /* only update 4-way case if joystick has moved */
1936            if (joystick->current != joystick->previous)
1937            {
1938               joystick->current4way = joystick->current;
1939
1940               /*
1941                        If joystick is pointing at a diagonal, acknowledge that the player moved
1942                        the joystick by favoring a direction change.  This minimizes frustration
1943                        when using a keyboard for input, and maximizes responsiveness.
1944
1945                        For example, if you are holding "left" then switch to "up" (where both left
1946                        and up are briefly pressed at the same time), we'll transition immediately
1947                        to "up."
1948
1949                        Zero any switches that didn't change from the previous to current state.
1950                     */
1951               if ((joystick->current4way & (JOYDIR_UP_BIT | JOYDIR_DOWN_BIT)) &&
1952                  (joystick->current4way & (JOYDIR_LEFT_BIT | JOYDIR_RIGHT_BIT)))
1953               {
1954                  joystick->current4way ^= joystick->current4way & joystick->previous;
1955               }
1956
1957               /*
1958                        If we are still pointing at a diagonal, we are in an indeterminant state.
1959
1960                        This could happen if the player moved the joystick from the idle position directly
1961                        to a diagonal, or from one diagonal directly to an extreme diagonal.
1962
1963                        The chances of this happening with a keyboard are slim, but we still need to
1964                        constrain this case.
1965
1966                        For now, just resolve randomly.
1967                     */
1968               if ((joystick->current4way & (JOYDIR_UP_BIT | JOYDIR_DOWN_BIT)) &&
1969                  (joystick->current4way & (JOYDIR_LEFT_BIT | JOYDIR_RIGHT_BIT)))
1970               {
1971                  if (mame_rand(machine) & 1)
1972                     joystick->current4way &= ~(JOYDIR_LEFT_BIT | JOYDIR_RIGHT_BIT);
1973                  else
1974                     joystick->current4way &= ~(JOYDIR_UP_BIT | JOYDIR_DOWN_BIT);
1975               }
1976            }
17541977         }
17551978      }
1756   }
17571979}
17581980
17591981
1760static void save_game_inputs(xml_data_node *parentnode)
1982/*-------------------------------------------------
1983    frame_update_analog_field - update the
1984    internals of a single analog field
1985-------------------------------------------------*/
1986
1987static void frame_update_analog_field(analog_field_state *analog)
17611988{
1762   int portnum;
1989   input_item_class itemclass;
1990   int keypressed = FALSE;
1991   INT64 keyscale;
1992   INT32 rawvalue;
1993   INT32 delta = 0;
17631994
1764   /* iterate over ports */
1765   for (portnum = 0; input_ports_default[portnum].type != IPT_END; portnum++)
1995   /* clamp the previous value to the min/max range and remember it */
1996   analog->previous = analog->accum = apply_analog_min_max(analog, analog->accum);
1997
1998   /* get the new raw analog value and its type */
1999   rawvalue = input_seq_axis_value(input_field_seq(analog->field, SEQ_TYPE_STANDARD), &itemclass);
2000
2001   /* if we got an absolute input, it overrides everything else */
2002   if (itemclass == ITEM_CLASS_ABSOLUTE)
17662003   {
1767      input_port_entry *defport = &input_ports_default[portnum];
1768      input_port_entry *curport = &Machine->input_ports[portnum];
2004      if (analog->previousanalog != rawvalue)
2005      {
2006         /* only update if analog value changed */
2007         analog->previousanalog = rawvalue;
17692008
1770      /* only save if something has changed and this port is a type we save */
1771      if (save_this_port_type(defport->type) &&
1772         ((!port_type_is_analog(defport->type) && (defport->default_value & defport->mask) != (curport->default_value & defport->mask)) ||
1773          defport->analog.delta != curport->analog.delta ||
1774          defport->analog.centerdelta != curport->analog.centerdelta ||
1775          defport->analog.sensitivity != curport->analog.sensitivity ||
1776          defport->analog.reverse != curport->analog.reverse ||
1777          input_seq_cmp(&defport->seq, &curport->seq) != 0 ||
1778          input_seq_cmp(&defport->analog.decseq, &curport->analog.decseq) != 0 ||
1779          input_seq_cmp(&defport->analog.incseq, &curport->analog.incseq) != 0))
1780      {
1781         /* add a new port node */
1782         xml_data_node *portnode = xml_add_child(parentnode, "port", NULL);
1783         if (portnode)
2009         /* apply the inverse of the sensitivity to the raw value so that */
2010         /* it will still cover the full min->max range requested after */
2011         /* we apply the sensitivity adjustment */
2012         if (analog->absolute || (analog->field->flags & ANALOG_FLAG_RESET))
17842013         {
1785            /* add the port information and attributes */
1786            xml_set_attribute(portnode, "type", port_type_to_token(defport->type, defport->player));
1787            xml_set_attribute_int(portnode, "mask", defport->mask);
1788            xml_set_attribute_int(portnode, "index", portnum);
1789            xml_set_attribute_int(portnode, "defvalue", defport->default_value & defport->mask);
2014            /* if port is absolute, then just return the absolute data supplied */
2015            analog->accum = APPLY_INVERSE_SENSITIVITY(rawvalue, analog->sensitivity);
2016         }
2017         else if (analog->positionalscale != 0)
2018         {
2019            /* if port is positional, we will take the full analog control and divide it */
2020            /* into positions, that way as the control is moved full scale, */
2021            /* it moves through all the positions */
2022            rawvalue = APPLY_SCALE(rawvalue - INPUT_ABSOLUTE_MIN, analog->positionalscale) * 512 + analog->minimum;
17902023
1791            /* if the value has changed, add it as well */
1792            if (!port_type_is_analog(defport->type) && defport->default_value != curport->default_value)
1793               xml_set_attribute_int(portnode, "value", curport->default_value & defport->mask);
2024            /* clamp the high value so it does not roll over */
2025            rawvalue = MIN(rawvalue, analog->maximum);
2026            analog->accum = APPLY_INVERSE_SENSITIVITY(rawvalue, analog->sensitivity);
2027         }
2028         else
2029            /* if port is relative, we use the value to simulate the speed of relative movement */
2030            /* sensitivity adjustment is allowed for this mode */
2031            analog->accum += rawvalue;
17942032
1795            /* add analog-specific attributes if they have changed */
1796            if (port_type_is_analog(defport->type))
2033         analog->lastdigital = 0;
2034         /* do not bother with other control types if the analog data is changing */
2035         return;
2036      }
2037      else
2038      {
2039         /* we still have to update fake relative from joystick control */
2040         if (!analog->absolute && analog->positionalscale == 0)
2041            analog->accum += rawvalue;
2042      }
2043   }
2044
2045   /* if we got it from a relative device, use that as the starting delta */
2046   /* also note that the last input was not a digital one */
2047   if (itemclass == ITEM_CLASS_RELATIVE && rawvalue != 0)
2048   {
2049      delta = rawvalue;
2050      analog->lastdigital = 0;
2051   }
2052
2053   keyscale = (analog->accum >= 0) ? analog->keyscalepos : analog->keyscaleneg;
2054
2055   /* if the decrement code sequence is pressed, add the key delta to */
2056   /* the accumulated delta; also note that the last input was a digital one */
2057   if (input_seq_pressed(input_field_seq(analog->field, SEQ_TYPE_DECREMENT)))
2058   {
2059      keypressed = TRUE;
2060      if (analog->field->delta != 0)
2061         delta -= APPLY_SCALE(analog->field->delta, keyscale);
2062      else if (analog->lastdigital != 1)
2063         /* decrement only once when first pressed */
2064         delta -= APPLY_SCALE(1, keyscale);
2065      analog->lastdigital = 1;
2066   }
2067
2068   /* same for the increment code sequence */
2069   if (input_seq_pressed(input_field_seq(analog->field, SEQ_TYPE_INCREMENT)))
2070   {
2071      keypressed = TRUE;
2072      if (analog->field->delta)
2073         delta += APPLY_SCALE(analog->field->delta, keyscale);
2074      else if (analog->lastdigital != 2)
2075         /* increment only once when first pressed */
2076         delta += APPLY_SCALE(1, keyscale);
2077      analog->lastdigital = 2;
2078   }
2079
2080   /* if resetting is requested, clear the accumulated position to 0 before */
2081   /* applying the deltas so that we only return this frame's delta */
2082   /* note that centering only works for relative controls */
2083   /* no need to check if absolute here because it is checked by the validity tests */
2084   if (analog->field->flags & ANALOG_FLAG_RESET)
2085      analog->accum = 0;
2086
2087   /* apply the delta to the accumulated value */
2088   analog->accum += delta;
2089
2090   /* if our last movement was due to a digital input, and if this control */
2091   /* type autocenters, and if neither the increment nor the decrement seq */
2092   /* was pressed, apply autocentering */
2093   if (analog->autocenter)
2094   {
2095      INT32 center = APPLY_INVERSE_SENSITIVITY(analog->center, analog->sensitivity);
2096      if (analog->lastdigital != 0 && !keypressed)
2097      {
2098         /* autocenter from positive values */
2099         if (analog->accum >= center)
2100         {
2101            analog->accum -= APPLY_SCALE(analog->field->centerdelta, analog->keyscalepos);
2102            if (analog->accum < center)
17972103            {
1798               if (defport->analog.delta != curport->analog.delta)
1799                  xml_set_attribute_int(portnode, "keydelta", curport->analog.delta);
1800               if (defport->analog.centerdelta != curport->analog.centerdelta)
1801                  xml_set_attribute_int(portnode, "centerdelta", curport->analog.centerdelta);
1802               if (defport->analog.sensitivity != curport->analog.sensitivity)
1803                  xml_set_attribute_int(portnode, "sensitivity", curport->analog.sensitivity);
1804               if (defport->analog.reverse != curport->analog.reverse)
1805                  xml_set_attribute(portnode, "reverse", curport->analog.reverse ? "yes" : "no");
2104               analog->accum = center;
2105               analog->lastdigital = 0;
18062106            }
2107         }
18072108
1808            /* add only the sequences that have changed from the defaults */
1809            if (input_seq_cmp(&defport->seq, &curport->seq) != 0)
1810               add_sequence(portnode, 0, defport->type, &curport->seq);
1811            if (input_seq_cmp(&defport->analog.decseq, &curport->analog.decseq) != 0)
1812               add_sequence(portnode, 1, defport->type, &curport->analog.decseq);
1813            if (input_seq_cmp(&defport->analog.incseq, &curport->analog.incseq) != 0)
1814               add_sequence(portnode, 2, defport->type, &curport->analog.incseq);
2109         /* autocenter from negative values */
2110         else
2111         {
2112            analog->accum += APPLY_SCALE(analog->field->centerdelta, analog->keyscaleneg);
2113            if (analog->accum > center)
2114            {
2115               analog->accum = center;
2116               analog->lastdigital = 0;
2117            }
18152118         }
18162119      }
18172120   }
2121   else if (!keypressed)
2122      analog->lastdigital = 0;
18182123}
18192124
18202125
1821static void input_port_save(int config_type, xml_data_node *parentnode)
2126/*-------------------------------------------------
2127    frame_get_digital_field_state - get the state
2128    of a digital field
2129-------------------------------------------------*/
2130
2131static int frame_get_digital_field_state(const input_field_config *field)
18222132{
1823   if (parentnode)
2133   int curstate = input_seq_pressed(input_field_seq(field, SEQ_TYPE_STANDARD));
2134   int changed = FALSE;
2135
2136   /* if the state changed, look for switch down/switch up */
2137   if (curstate != field->state->last)
18242138   {
1825      /* default ports save differently */
1826      if (config_type == CONFIG_TYPE_DEFAULT)
1827         save_default_inputs(parentnode);
1828      else
1829         save_game_inputs(parentnode);
2139      field->state->last = curstate;
2140      changed = TRUE;
18302141   }
1831}
18322142
2143#ifdef MESS
2144   /* (MESS-specific) check for disabled keyboard */
2145   if (field->type == IPT_KEYBOARD && osd_keyboard_disabled())
2146      return FALSE;
2147#endif /* MESS */
18332148
2149   /* skip locked-out coin inputs */
2150   if (field->type >= IPT_COIN1 && field->type <= IPT_COIN8 && coinlockedout[field->type - IPT_COIN1])
2151   {
2152      ui_popup_time(3, "Coinlock disabled %s.", input_field_name(field));
2153      return FALSE;
2154   }
18342155
1835/*************************************
1836 *
1837 *  Token to default string
1838 *
1839 *************************************/
2156   /* skip locked-out service inputs */
2157   if (field->type >= IPT_SERVICE1 && field->type <= IPT_SERVICE4 && servicecoinlockedout[field->type - IPT_SERVICE1])
2158   {
2159      ui_popup_time(3, "Coinlock disabled %s.", input_field_name(field));
2160      return FALSE;
2161   }
18402162
1841const char *input_port_string_from_token(const input_port_token token)
1842{
1843   int index;
2163   /* if this is a switch-down event, handle impulse and toggle */
2164   if (changed && curstate)
2165   {
2166      /* impluse controls: reset the impulse counter */
2167      if (field->impulse != 0 && field->state->impulse == 0)
2168         field->state->impulse = field->impulse;
18442169
1845   if (token.i == 0)
1846      return NULL;
1847   if (token.i >= INPUT_STRING_COUNT)
1848      return token.stringptr;
1849   for (index = 0; index < ARRAY_LENGTH(input_port_default_strings); index++)
1850      if (input_port_default_strings[index].id == token.i)
1851         return input_port_default_strings[index].string;
1852   return "(Unknown Default)";
2170      /* toggle controls: flip the toggle state */
2171      if (field->flags & FIELD_FLAG_TOGGLE)
2172         field->state->toggle = !field->state->toggle;
2173   }
2174
2175   /* update the current state with the impulse state */
2176   if (field->impulse != 0 && field->state->impulse != 0)
2177   {
2178      field->state->impulse--;
2179      curstate = TRUE;
2180   }
2181
2182   /* update the current state with the toggle state */
2183   if (field->flags & FIELD_FLAG_TOGGLE)
2184      curstate = field->state->toggle;
2185
2186   /* additional logic to restrict digital joysticks */
2187   if (curstate && field->state->joystick != NULL && field->way != 16)
2188   {
2189      UINT8 mask = (field->way == 4) ? field->state->joystick->current4way : field->state->joystick->current;
2190      if (!(mask & (1 << field->state->joydir)))
2191         curstate = FALSE;
2192   }
2193
2194   return curstate;
18532195}
18542196
18552197
18562198
1857/*************************************
1858 *
1859 *  Input port detokenizer
1860 *
1861 *************************************/
2199/***************************************************************************
2200    PORT CONFIGURATION HELPERS
2201***************************************************************************/
18622202
1863static void input_port_detokenize(input_port_init_params *param, const input_port_token *ipt)
2203/*-------------------------------------------------
2204    port_config_detokenize - recursively
2205    detokenize a series of input port tokens
2206-------------------------------------------------*/
2207
2208static input_port_config *port_config_detokenize(input_port_config *listhead, const input_port_token *ipt)
18642209{
18652210   UINT32 entrytype = INPUT_TOKEN_INVALID;
1866   input_port_entry *portentry = NULL;
1867   const char *modify_tag = NULL;
1868   int seq_index[3] = {0};
2211   input_setting_config *cursetting = NULL;
2212   input_field_config *curfield = NULL;
2213   input_port_config *curport = NULL;
18692214
18702215   /* loop over tokens until we hit the end */
18712216   while (entrytype != INPUT_TOKEN_END)
18722217   {
18732218      UINT32 mask, defval, type, val;
18742219      input_port_token temptoken;
1875      int hasdiploc, strindex;
1876#ifdef MESS
1877      UINT16 category;
1878#endif /* MESS */
2220      input_condition condition;
2221      int hasdiploc;
2222      int index;
18792223
18802224      /* unpack the token from the first entry */
18812225      TOKEN_GET_UINT32_UNPACK1(ipt, entrytype, 8);
r2724r2725
18872231
18882232         /* including */
18892233         case INPUT_TOKEN_INCLUDE:
1890            input_port_detokenize(param, TOKEN_GET_PTR(ipt, tokenptr));
2234            listhead = port_config_detokenize(listhead, TOKEN_GET_PTR(ipt, tokenptr));
18912235            break;
18922236
18932237         /* start of a new input port */
18942238         case INPUT_TOKEN_START:
18952239         case INPUT_TOKEN_START_TAG:
1896            modify_tag = NULL;
1897            portentry = input_port_initialize(param, IPT_PORT, NULL, 0, 0);
2240            curport = port_config_alloc((const input_port_config **)&listhead);
18982241            if (entrytype == INPUT_TOKEN_START_TAG)
1899               portentry->start.tag = TOKEN_GET_STRING(ipt);
2242               curport->tag = TOKEN_GET_STRING(ipt);
2243            curfield = NULL;
2244            cursetting = NULL;
19002245            break;
19012246
19022247         /* modify an existing port */
19032248         case INPUT_TOKEN_MODIFY:
1904            modify_tag = TOKEN_GET_STRING(ipt);
2249            curport = port_config_find(listhead, TOKEN_GET_STRING(ipt));
19052250            break;
19062251
1907         /* input bit definition */
1908         case INPUT_TOKEN_BIT:
2252         /* input field definition */
2253         case INPUT_TOKEN_FIELD:
2254            if (curport == NULL)
2255               fatalerror("INPUT_TOKEN_FIELD encountered with no active port");
2256
19092257            TOKEN_UNGET_UINT32(ipt);
19102258            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, type, 24);
19112259            TOKEN_GET_UINT64_UNPACK2(ipt, mask, 32, defval, 32);
1912            portentry = input_port_initialize(param, type, modify_tag, mask, defval);
1913            seq_index[0] = seq_index[1] = seq_index[2] = 0;
2260
2261            curfield = field_config_alloc(curport, type, defval, mask);
2262            cursetting = NULL;
19142263            break;
19152264
1916         case INPUT_TOKEN_SPECIAL_ONOFF:
2265         /* field or setting condition */
2266         case INPUT_TOKEN_CONDITION:
2267            if (curfield == NULL && cursetting == NULL)
2268               fatalerror("INPUT_TOKEN_CONDITION encountered with no active field or setting");
2269
19172270            TOKEN_UNGET_UINT32(ipt);
1918            TOKEN_GET_UINT32_UNPACK3(ipt, entrytype, 8, hasdiploc, 1, strindex, 23);
1919            TOKEN_GET_UINT64_UNPACK2(ipt, mask, 32, defval, 32);
2271            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, condition.condition, 24);
2272            TOKEN_GET_UINT64_UNPACK2(ipt, condition.mask, 32, condition.value, 32);
2273            condition.tag = TOKEN_GET_STRING(ipt);
19202274
1921            portentry = input_port_initialize(param, IPT_DIPSWITCH_NAME, modify_tag, mask, mask & defval);
1922            temptoken.i = strindex;
1923            portentry->name = input_port_string_from_token(temptoken);
1924            if (strindex == INPUT_STRING_Service_Mode)
1925            {
1926               portentry->toggle = TRUE;
1927               portentry->seq.code[0] = KEYCODE_F2;
1928            }
1929            if (hasdiploc)
1930               input_port_parse_diplocation(portentry, TOKEN_GET_STRING(ipt));
2275            if (cursetting != NULL)
2276               cursetting->condition = condition;
2277            else
2278               curfield->condition = condition;
2279            break;
19312280
1932            portentry = input_port_initialize(param, IPT_DIPSWITCH_SETTING, modify_tag, 0, mask & defval);
1933            temptoken.i = INPUT_STRING_Off;
1934            portentry->name = input_port_string_from_token(temptoken);
1935
1936            portentry = input_port_initialize(param, IPT_DIPSWITCH_SETTING, modify_tag, 0, mask & ~defval);
1937            temptoken.i = INPUT_STRING_On;
1938            portentry->name = input_port_string_from_token(temptoken);
2281         /* field player select */
2282         case INPUT_TOKEN_PLAYER1:
2283         case INPUT_TOKEN_PLAYER2:
2284         case INPUT_TOKEN_PLAYER3:
2285         case INPUT_TOKEN_PLAYER4:
2286         case INPUT_TOKEN_PLAYER5:
2287         case INPUT_TOKEN_PLAYER6:
2288         case INPUT_TOKEN_PLAYER7:
2289         case INPUT_TOKEN_PLAYER8:
2290            if (curfield == NULL)
2291               fatalerror("INPUT_TOKEN_PLAYERn encountered with no active field");
2292            curfield->player = entrytype - INPUT_TOKEN_PLAYER1;
19392293            break;
19402294
1941         /* append a code */
1942         case INPUT_TOKEN_CODE:
2295         /* field category */
2296         case INPUT_TOKEN_CATEGORY:
2297            if (curfield == NULL)
2298               fatalerror("INPUT_TOKEN_CATEGORY encountered with no active field");
19432299            TOKEN_UNGET_UINT32(ipt);
1944            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, val, 32);
1945            if (seq_index[0] > 0)
1946               portentry->seq.code[seq_index[0]++] = SEQCODE_OR;
1947            portentry->seq.code[seq_index[0]++] = val;
2300            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, curfield->category, 24);
19482301            break;
19492302
1950         case INPUT_TOKEN_CODE_DEC:
2303         /* field flags */
2304         case INPUT_TOKEN_UNUSED:
2305            if (curfield == NULL)
2306               fatalerror("INPUT_TOKEN_UNUSED encountered with no active field");
2307            curfield->flags |= FIELD_FLAG_UNUSED;
2308            break;
2309
2310         case INPUT_TOKEN_COCKTAIL:
2311            if (curfield == NULL)
2312               fatalerror("INPUT_TOKEN_COCKTAIL encountered with no active field");
2313            curfield->flags |= FIELD_FLAG_COCKTAIL;
2314            curfield->player = 1;
2315            break;
2316
2317         case INPUT_TOKEN_ROTATED:
2318            if (curfield == NULL)
2319               fatalerror("INPUT_TOKEN_ROTATED encountered with no active field");
2320            curfield->flags |= FIELD_FLAG_ROTATED;
2321            break;
2322
2323         case INPUT_TOKEN_TOGGLE:
2324            if (curfield == NULL)
2325               fatalerror("INPUT_TOKEN_TOGGLE encountered with no active field");
2326            curfield->flags |= FIELD_FLAG_TOGGLE;
2327            break;
2328
2329         /* field impulse */
2330         case INPUT_TOKEN_IMPULSE:
2331            if (curfield == NULL)
2332               fatalerror("INPUT_TOKEN_IMPULSE encountered with no active field");
19512333            TOKEN_UNGET_UINT32(ipt);
1952            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, val, 32);
1953            if (seq_index[1] > 0)
1954               portentry->analog.decseq.code[seq_index[1]++] = SEQCODE_OR;
1955            portentry->analog.decseq.code[seq_index[1]++] = val;
2334            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, curfield->impulse, 24);
19562335            break;
19572336
1958         case INPUT_TOKEN_CODE_INC:
2337         /* field name */
2338         case INPUT_TOKEN_NAME:
2339            if (curfield == NULL)
2340               fatalerror("INPUT_TOKEN_NAME encountered with no active field");
2341            curfield->name = input_port_string_from_token(*ipt++);
2342            break;
2343
2344         /* field code sequence */
2345         case INPUT_TOKEN_CODE:
2346            if (curfield == NULL)
2347               fatalerror("INPUT_TOKEN_CODE encountered with no active field");
2348
19592349            TOKEN_UNGET_UINT32(ipt);
19602350            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, val, 32);
1961            if (seq_index[2] > 0)
1962               portentry->analog.incseq.code[seq_index[2]++] = SEQCODE_OR;
1963            portentry->analog.incseq.code[seq_index[2]++] = val;
2351
2352            input_seq_append_or(&curfield->seq[SEQ_TYPE_STANDARD], val);
19642353            break;
19652354
2355         /* field custom callback */
2356         case INPUT_TOKEN_CUSTOM:
2357            if (curfield == NULL)
2358               fatalerror("INPUT_TOKEN_CUSTOM encountered with no active field");
2359            curfield->custom = TOKEN_GET_PTR(ipt, customptr);
2360            curfield->custom_param = (void *)TOKEN_GET_PTR(ipt, voidptr);
2361            break;
2362
2363         /* field changed callback */
2364         case INPUT_TOKEN_CHANGED:
2365            if (curfield == NULL)
2366               fatalerror("INPUT_TOKEN_CHANGED encountered with no active field");
2367            curfield->changed = TOKEN_GET_PTR(ipt, changedptr);
2368            curfield->changed_param = (void *)TOKEN_GET_PTR(ipt, voidptr);
2369            break;
2370
2371         /* DIP switch location */
2372         case INPUT_TOKEN_DIPLOCATION:
2373            if (curfield == NULL)
2374               fatalerror("INPUT_TOKEN_DIPLOCATION encountered with no active field");
2375            curfield->diploclist = diplocation_list_alloc(curfield, TOKEN_GET_STRING(ipt));
2376            break;
2377
19662378         /* joystick flags */
19672379         case INPUT_TOKEN_2WAY:
19682380         case INPUT_TOKEN_4WAY:
19692381         case INPUT_TOKEN_8WAY:
19702382         case INPUT_TOKEN_16WAY:
1971            portentry->way = 2 << (entrytype - INPUT_TOKEN_2WAY);
2383            if (curfield == NULL)
2384               fatalerror("INPUT_TOKEN_nWAY encountered with no active field");
2385            curfield->way = 2 << (entrytype - INPUT_TOKEN_2WAY);
19722386            break;
19732387
1974         case INPUT_TOKEN_ROTATED:
1975            portentry->rotated = TRUE;
1976            break;
2388         /* (MESS) natural keyboard support */
2389         case INPUT_TOKEN_CHAR:
2390            if (curfield == NULL)
2391               fatalerror("INPUT_TOKEN_CHAR encountered with no active field");
19772392
1978         /* general flags */
1979         case INPUT_TOKEN_NAME:
1980            portentry->name = input_port_string_from_token(*ipt++);
2393            TOKEN_UNGET_UINT32(ipt);
2394            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, val, 32);
2395
2396            for (index = 0; index < ARRAY_LENGTH(curfield->chars); index++)
2397               if (curfield->chars[index] == 0)
2398               {
2399                  curfield->chars[index] = (unicode_char)val;
2400                  break;
2401               }
19812402            break;
19822403
1983         case INPUT_TOKEN_PLAYER1:
1984         case INPUT_TOKEN_PLAYER2:
1985         case INPUT_TOKEN_PLAYER3:
1986         case INPUT_TOKEN_PLAYER4:
1987         case INPUT_TOKEN_PLAYER5:
1988         case INPUT_TOKEN_PLAYER6:
1989         case INPUT_TOKEN_PLAYER7:
1990         case INPUT_TOKEN_PLAYER8:
1991            portentry->player = entrytype - INPUT_TOKEN_PLAYER1;
2404         /* analog minimum/maximum */
2405         case INPUT_TOKEN_MINMAX:
2406            if (curfield == NULL)
2407               fatalerror("INPUT_TOKEN_MINMAX encountered with no active field");
2408            TOKEN_GET_UINT64_UNPACK2(ipt, curfield->min, 32, curfield->max, 32);
19922409            break;
19932410
1994         case INPUT_TOKEN_COCKTAIL:
1995            portentry->cocktail = TRUE;
1996            portentry->player = 1;
2411         /* analog sensitivity */
2412         case INPUT_TOKEN_SENSITIVITY:
2413            if (curfield == NULL)
2414               fatalerror("INPUT_TOKEN_SENSITIVITY encountered with no active field");
2415            TOKEN_UNGET_UINT32(ipt);
2416            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, curfield->sensitivity, 24);
19972417            break;
19982418
1999         case INPUT_TOKEN_TOGGLE:
2000            portentry->toggle = TRUE;
2419         /* analog keyboard delta */
2420         case INPUT_TOKEN_KEYDELTA:
2421            if (curfield == NULL)
2422               fatalerror("INPUT_TOKEN_KEYDELTA encountered with no active field");
2423            TOKEN_UNGET_UINT32(ipt);
2424            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, curfield->delta, -24);
2425            curfield->centerdelta = curfield->delta;
20012426            break;
20022427
2003         case INPUT_TOKEN_IMPULSE:
2428         /* analog autocenter delta */
2429         case INPUT_TOKEN_CENTERDELTA:
2430            if (curfield == NULL)
2431               fatalerror("INPUT_TOKEN_CENTERDELTA encountered with no active field");
20042432            TOKEN_UNGET_UINT32(ipt);
2005            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, portentry->impulse, 24);
2433            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, curfield->centerdelta, -24);
20062434            break;
20072435
2436         /* analog reverse flags */
20082437         case INPUT_TOKEN_REVERSE:
2009            portentry->analog.reverse = TRUE;
2438            if (curfield == NULL)
2439               fatalerror("INPUT_TOKEN_REVERSE encountered with no active field");
2440            curfield->flags |= ANALOG_FLAG_REVERSE;
20102441            break;
20112442
20122443         case INPUT_TOKEN_RESET:
2013            portentry->analog.reset = TRUE;
2444            if (curfield == NULL)
2445               fatalerror("INPUT_TOKEN_RESET encountered with no active field");
2446            curfield->flags |= ANALOG_FLAG_RESET;
20142447            break;
20152448
2016         case INPUT_TOKEN_UNUSED:
2017            portentry->unused = TRUE;
2449         case INPUT_TOKEN_WRAPS:
2450            if (curfield == NULL)
2451               fatalerror("INPUT_TOKEN_WRAPS encountered with no active field");
2452            curfield->flags |= ANALOG_FLAG_WRAPS;
20182453            break;
20192454
2020         /* analog settings */
2021         case INPUT_TOKEN_MINMAX:
2022            TOKEN_GET_UINT64_UNPACK2(ipt, portentry->analog.min, 32, portentry->analog.max, 32);
2455         case INPUT_TOKEN_INVERT:
2456            if (curfield == NULL)
2457               fatalerror("INPUT_TOKEN_INVERT encountered with no active field");
2458            curfield->flags |= ANALOG_FLAG_INVERT;
20232459            break;
20242460
2025         case INPUT_TOKEN_SENSITIVITY:
2461         /* analog crosshair parameters */
2462         case INPUT_TOKEN_CROSSHAIR:
2463            if (curfield == NULL)
2464               fatalerror("INPUT_TOKEN_CROSSHAIR encountered with no active field");
2465
20262466            TOKEN_UNGET_UINT32(ipt);
2027            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, portentry->analog.sensitivity, 24);
2467            TOKEN_GET_UINT32_UNPACK3(ipt, entrytype, 8, curfield->crossaxis, 4, curfield->crossaltaxis, -20);
2468            TOKEN_GET_UINT64_UNPACK2(ipt, curfield->crossscale, -32, curfield->crossoffset, -32);
2469
2470            curfield->crossaltaxis *= 1.0f / 65536.0f;
2471            curfield->crossscale *= 1.0f / 65536.0f;
2472            curfield->crossoffset *= 1.0f / 65536.0f;
20282473            break;
20292474
2030         case INPUT_TOKEN_KEYDELTA:
2475         /* analog decrement sequence */
2476         case INPUT_TOKEN_CODE_DEC:
2477            if (curfield == NULL)
2478               fatalerror("INPUT_TOKEN_CODE_DEC encountered with no active field");
2479            index = entrytype - INPUT_TOKEN_CODE;
2480
20312481            TOKEN_UNGET_UINT32(ipt);
2032            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, portentry->analog.delta, -24);
2033            portentry->analog.centerdelta = portentry->analog.delta;
2482            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, val, 32);
2483
2484            input_seq_append_or(&curfield->seq[SEQ_TYPE_DECREMENT], val);
20342485            break;
20352486
2036         case INPUT_TOKEN_CENTERDELTA:
2487         /* analog increment sequence */
2488         case INPUT_TOKEN_CODE_INC:
2489            if (curfield == NULL)
2490               fatalerror("INPUT_TOKEN_CODE_INC encountered with no active field");
2491            index = entrytype - INPUT_TOKEN_CODE;
2492
20372493            TOKEN_UNGET_UINT32(ipt);
2038            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, portentry->analog.centerdelta, -24);
2039            break;
2494            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, val, 32);
20402495
2041         case INPUT_TOKEN_CROSSHAIR:
2042            TOKEN_UNGET_UINT32(ipt);
2043            TOKEN_GET_UINT32_UNPACK3(ipt, entrytype, 8, portentry->analog.crossaxis, 4, portentry->analog.crossaltaxis, -20);
2044            TOKEN_GET_UINT64_UNPACK2(ipt, portentry->analog.crossscale, -32, portentry->analog.crossoffset, -32);
2045            portentry->analog.crossaltaxis *= 1.0f / 65536.0f;
2046            portentry->analog.crossscale *= 1.0f / 65536.0f;
2047            portentry->analog.crossoffset *= 1.0f / 65536.0f;
2496            input_seq_append_or(&curfield->seq[SEQ_TYPE_INCREMENT], val);
20482497            break;
20492498
2499         /* analog wraps flag */
2500
20502501         case INPUT_TOKEN_FULL_TURN_COUNT:
2502            if (curfield == NULL)
2503               fatalerror("INPUT_TOKEN_FULL_TURN_COUNT encountered with no active field");
20512504            TOKEN_UNGET_UINT32(ipt);
2052            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, portentry->analog.full_turn_count, 24);
2505            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, curfield->full_turn_count, 24);
20532506            break;
20542507
20552508         case INPUT_TOKEN_POSITIONS:
2509            if (curfield == NULL)
2510               fatalerror("INPUT_TOKEN_POSITIONS encountered with no active field");
20562511            TOKEN_UNGET_UINT32(ipt);
2057            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, portentry->analog.max, 24);
2512            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, curfield->max, 24);
20582513            break;
20592514
2060         case INPUT_TOKEN_WRAPS:
2061            portentry->analog.wraps = TRUE;
2062            break;
2063
20642515         case INPUT_TOKEN_REMAP_TABLE:
2065            portentry->analog.remap_table = TOKEN_GET_PTR(ipt, ui32ptr);
2516            if (curfield == NULL)
2517               fatalerror("INPUT_TOKEN_REMAP_TABLE encountered with no active field");
2518            curfield->remap_table = TOKEN_GET_PTR(ipt, ui32ptr);
20662519            break;
20672520
2068         case INPUT_TOKEN_INVERT:
2069            portentry->analog.invert = TRUE;
2070            break;
2521         /* DIP switch definition */
2522         case INPUT_TOKEN_DIPNAME:
2523            if (curport == NULL)
2524               fatalerror("INPUT_TOKEN_DIPNAME encountered with no active port");
20712525
2072         /* custom callbacks */
2073         case INPUT_TOKEN_CUSTOM:
2074            portentry->custom = TOKEN_GET_PTR(ipt, customptr);
2075            portentry->custom_param = (void *)TOKEN_GET_PTR(ipt, voidptr);
2076            break;
2526            TOKEN_GET_UINT64_UNPACK2(ipt, mask, 32, defval, 32);
20772527
2078         /* changed callbacks */
2079         case INPUT_TOKEN_CHANGED:
2080            portentry->changed = TOKEN_GET_PTR(ipt, changedptr);
2081            portentry->changed_param = (void *)TOKEN_GET_PTR(ipt, voidptr);
2082            break;
2528            curfield = field_config_alloc(curport, IPT_DIPSWITCH, defval, mask);
2529            cursetting = NULL;
20832530
2084         /* dip switch definition */
2085         case INPUT_TOKEN_DIPNAME:
2086            TOKEN_GET_UINT64_UNPACK2(ipt, mask, 32, defval, 32);
2087            portentry = input_port_initialize(param, IPT_DIPSWITCH_NAME, modify_tag, mask, defval);
2088            seq_index[0] = seq_index[1] = seq_index[2] = 0;
2089            portentry->name = input_port_string_from_token(*ipt++);
2531            curfield->name = input_port_string_from_token(*ipt++);
20902532            break;
20912533
2534         /* DIP switch setting */
20922535         case INPUT_TOKEN_DIPSETTING:
2536            if (curfield == NULL)
2537               fatalerror("INPUT_TOKEN_DIPSETTING encountered with no active field");
2538
20932539            TOKEN_UNGET_UINT32(ipt);
20942540            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, defval, 32);
2095            portentry = input_port_initialize(param, IPT_DIPSWITCH_SETTING, modify_tag, 0, defval);
2096            seq_index[0] = seq_index[1] = seq_index[2] = 0;
2097            portentry->name = input_port_string_from_token(*ipt++);
2098            break;
20992541
2100         /* physical location */
2101         case INPUT_TOKEN_DIPLOCATION:
2102            input_port_parse_diplocation(portentry, TOKEN_GET_STRING(ipt));
2542            cursetting = setting_config_alloc(curfield, defval & curfield->mask, input_port_string_from_token(*ipt++));
21032543            break;
21042544
2105         /* conditionals for dip switch settings */
2106         case INPUT_TOKEN_CONDITION:
2545         /* special DIP switch with on/off values */
2546         case INPUT_TOKEN_SPECIAL_ONOFF:
2547            if (curport == NULL)
2548               fatalerror("INPUT_TOKEN_SPECIAL_ONOFF encountered with no active port");
2549
21072550            TOKEN_UNGET_UINT32(ipt);
2108            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, portentry->condition.condition, 24);
2109            TOKEN_GET_UINT64_UNPACK2(ipt, portentry->condition.mask, 32, portentry->condition.value, 32);
2110            portentry->condition.tag = TOKEN_GET_STRING(ipt);
2111            break;
2551            TOKEN_GET_UINT32_UNPACK3(ipt, entrytype, 8, hasdiploc, 1, temptoken.i, 23);
2552            TOKEN_GET_UINT64_UNPACK2(ipt, mask, 32, defval, 32);
21122553
2113         /* analog adjuster definition */
2114         case INPUT_TOKEN_ADJUSTER:
2115            TOKEN_UNGET_UINT32(ipt);
2116            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, defval, 32);
2117            portentry = input_port_initialize(param, IPT_ADJUSTER, modify_tag, 0xff, defval | (defval << 8));
2118            seq_index[0] = seq_index[1] = seq_index[2] = 0;
2119            portentry->name = TOKEN_GET_STRING(ipt);
2554            curfield = field_config_alloc(curport, IPT_DIPSWITCH, defval, mask);
2555            cursetting = NULL;
2556
2557            curfield->name = input_port_string_from_token(temptoken);
2558            if (temptoken.i == INPUT_STRING_Service_Mode)
2559            {
2560               curfield->flags |= FIELD_FLAG_TOGGLE;
2561               curfield->seq[SEQ_TYPE_STANDARD].code[0] = KEYCODE_F2;
2562            }
2563            if (hasdiploc)
2564               curfield->diploclist = diplocation_list_alloc(curfield, TOKEN_GET_STRING(ipt));
2565
2566            temptoken.i = INPUT_STRING_Off;
2567            cursetting = setting_config_alloc(curfield, defval & mask, input_port_string_from_token(temptoken));
2568
2569            temptoken.i = INPUT_STRING_On;
2570            cursetting = setting_config_alloc(curfield, ~defval & mask, input_port_string_from_token(temptoken));
21202571            break;
21212572
21222573         /* configuration definition */
21232574         case INPUT_TOKEN_CONFNAME:
2575            if (curport == NULL)
2576               fatalerror("INPUT_TOKEN_CONFNAME encountered with no active port");
2577
21242578            TOKEN_GET_UINT64_UNPACK2(ipt, mask, 32, defval, 32);
2125            portentry = input_port_initialize(param, IPT_CONFIG_NAME, modify_tag, mask, defval);
2126            seq_index[0] = seq_index[1] = seq_index[2] = 0;
2127            portentry->name = input_port_string_from_token(*ipt++);
2579
2580            curfield = field_config_alloc(curport, IPT_CONFIG, defval, mask);
2581            cursetting = NULL;
2582
2583            curfield->name = input_port_string_from_token(*ipt++);
21282584            break;
21292585
2586         /* configuration setting */
21302587         case INPUT_TOKEN_CONFSETTING:
2588            if (curfield == NULL)
2589               fatalerror("INPUT_TOKEN_CONFSETTING encountered with no active field");
2590
21312591            TOKEN_UNGET_UINT32(ipt);
21322592            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, defval, 32);
2133            portentry = input_port_initialize(param, IPT_CONFIG_SETTING, modify_tag, 0, defval);
2134            seq_index[0] = seq_index[1] = seq_index[2] = 0;
2135            portentry->name = input_port_string_from_token(*ipt++);
2136            break;
21372593
2138#ifdef MESS
2139         case INPUT_TOKEN_CHAR:
2140            TOKEN_UNGET_UINT32(ipt);
2141            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, val, 32);
2142            {
2143               int ch;
2144               for (ch = 0; portentry->keyboard.chars[ch] != 0; ch++)
2145                  ;
2146               portentry->keyboard.chars[ch] = (unicode_char) val;
2147            }
2594            cursetting = setting_config_alloc(curfield, defval & curfield->mask, input_port_string_from_token(*ipt++));
21482595            break;
21492596
2150         /* category definition */
2151         case INPUT_TOKEN_CATEGORY:
2152            TOKEN_UNGET_UINT32(ipt);
2153            TOKEN_GET_UINT32_UNPACK2(ipt, entrytype, 8, portentry->category, 24);
2154            break;
2597         /* configuration definition */
2598         case INPUT_TOKEN_CATEGORY_NAME:
2599            if (curport == NULL)
2600               fatalerror("INPUT_TOKEN_CATEGORY_NAME encountered with no active port");
21552601
2156         case INPUT_TOKEN_CATEGORY_NAME:
21572602            TOKEN_GET_UINT64_UNPACK2(ipt, mask, 32, defval, 32);
2158            portentry = input_port_initialize(param, IPT_CATEGORY_NAME, modify_tag, mask, defval);
2159            seq_index[0] = seq_index[1] = seq_index[2] = 0;
2160            portentry->name = input_port_string_from_token(*ipt++);
2603
2604            curfield = field_config_alloc(curport, IPT_CATEGORY, defval, mask);
2605            cursetting = NULL;
2606
2607            curfield->name = input_port_string_from_token(*ipt++);
21612608            break;
21622609
2610         /* configuration setting */
21632611         case INPUT_TOKEN_CATEGORY_SETTING:
2612            if (curfield == NULL)
2613               fatalerror("INPUT_TOKEN_CATEGORY_SETTING encountered with no active field");
2614
21642615            TOKEN_UNGET_UINT32(ipt);
2165            TOKEN_GET_UINT64_UNPACK3(ipt, entrytype, 8, defval, 32, category, 16);
2166            portentry = input_port_initialize(param, IPT_CATEGORY_SETTING, modify_tag, 0, defval);
2167            seq_index[0] = seq_index[1] = seq_index[2] = 0;
2168            portentry->name = input_port_string_from_token(*ipt++);
2169            portentry->category = category;
2616            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, defval, 32);
2617
2618            cursetting = setting_config_alloc(curfield, defval & curfield->mask, input_port_string_from_token(*ipt++));
21702619            break;
2171#endif /* MESS */
21722620
2621         /* analog adjuster definition */
2622         case INPUT_TOKEN_ADJUSTER:
2623            if (curport == NULL)
2624               fatalerror("INPUT_TOKEN_ADJUSTER encountered with no active port");
2625
2626            TOKEN_UNGET_UINT32(ipt);
2627            TOKEN_GET_UINT64_UNPACK2(ipt, entrytype, 8, defval, 32);
2628
2629            curfield = field_config_alloc(curport, IPT_ADJUSTER, defval, 0xff);
2630            cursetting = NULL;
2631
2632            curfield->name = TOKEN_GET_STRING(ipt);
2633            break;
2634
21732635         default:
21742636            fatalerror("Invalid token %d in input ports\n", entrytype);
21752637            break;
21762638      }
21772639   }
2640
2641   return listhead;
21782642}
21792643
21802644
2645/*-------------------------------------------------
2646    port_config_alloc - allocate a new input
2647    port config and append to the end of the
2648    given list
2649-------------------------------------------------*/
21812650
2182/*************************************
2183 *
2184 *  Input port construction
2185 *
2186 *************************************/
2651static input_port_config *port_config_alloc(const input_port_config **listhead)
2652{
2653   const input_port_config * const *tailptr;
2654   input_port_config *config;
21872655
2188input_port_entry *input_port_initialize(input_port_init_params *iip, UINT32 type, const char *tag, UINT32 mask, UINT32 defval)
2656   /* allocate memory */
2657   config = malloc_or_die(sizeof(*config));
2658   memset(config, 0, sizeof(*config));
2659
2660   /* add it to the tail */
2661   for (tailptr = listhead; *tailptr != NULL; tailptr = &(*tailptr)->next) ;
2662   *(input_port_config **)tailptr = config;
2663
2664   return config;
2665}
2666
2667
2668/*-------------------------------------------------
2669    port_config_free - free an allocated input
2670    port configuration
2671-------------------------------------------------*/
2672
2673static void port_config_free(const input_port_config **portptr)
21892674{
2190   /* this function is used within an INPUT_PORT callback to set up a single port */
2191   input_port_entry *portentry;
2192   input_code code;
2675   input_port_config *port = (input_port_config *)*portptr;
21932676
2194   /* are we modifying an existing port? */
2195   if (tag != NULL)
2196   {
2197      int portnum, deleting;
2677   /* free any field configs first */
2678   while (port->fieldlist != NULL)
2679      field_config_free((input_field_config **)&port->fieldlist);
21982680
2199      /* find the matching port */
2200      for (portnum = 0; portnum < iip->current_port; portnum++)
2201         if (iip->ports[portnum].type == IPT_PORT && iip->ports[portnum].start.tag != NULL && !strcmp(iip->ports[portnum].start.tag, tag))
2202            break;
2203      if (portnum >= iip->current_port)
2204         fatalerror("Could not find port to modify: '%s'", tag);
2681   /* remove ourself from the list */
2682   *portptr = port->next;
22052683
2206      /* nuke any matching masks */
2207      for (portnum++, deleting = 0; portnum < iip->current_port && iip->ports[portnum].type != IPT_PORT; portnum++)
2684   /* free ourself */
2685   free(port);
2686}
2687
2688
2689/*-------------------------------------------------
2690    port_config_find - locate an existing port
2691    configuration by tag
2692-------------------------------------------------*/
2693
2694static input_port_config *port_config_find(const input_port_config *listhead, const char *tag)
2695{
2696   const input_port_config *scanport;
2697
2698   /* scan for a matching tag and return the matching port */
2699   for (scanport = listhead; scanport != NULL; scanport = scanport->next)
2700      if (scanport->tag != NULL && strcmp(scanport->tag, tag) == 0)
2701         return (input_port_config *)scanport;
2702
2703   /* failure is fatal */
2704   fatalerror("port_config_find failed to find a matching port '%s'", tag);
2705}
2706
2707
2708/*-------------------------------------------------
2709    field_config_alloc - allocate a new input
2710    port field config, replacing any intersecting
2711    fields already present and inserting at the
2712    correct sorted location
2713-------------------------------------------------*/
2714
2715static input_field_config *field_config_alloc(input_port_config *port, int type, input_port_value defvalue, input_port_value maskbits)
2716{
2717   const input_field_config * const *scanfieldptr;
2718   const input_field_config * const *scanfieldnextptr;
2719   input_field_config *config;
2720   input_port_value lowbit;
2721   int seqtype;
2722
2723   /* first modify/nuke any entries that intersect our maskbits */
2724   for (scanfieldptr = &port->fieldlist; *scanfieldptr != NULL; scanfieldptr = scanfieldnextptr)
2725   {
2726      scanfieldnextptr = &(*scanfieldptr)->next;
2727      if (((*scanfieldptr)->mask & maskbits) != 0)
22082728      {
2209         deleting = (iip->ports[portnum].mask & mask) || (deleting && iip->ports[portnum].mask == 0);
2210         if (deleting)
2729         /* reduce the mask of the field we found */
2730         config = (input_field_config *)*scanfieldptr;
2731         config->mask &= ~maskbits;
2732
2733         /* if the new entry fully overrides the previous one, we nuke */
2734         if (config->mask == 0)
22112735         {
2212            iip->current_port--;
2213            memmove(&iip->ports[portnum], &iip->ports[portnum + 1], (iip->current_port - portnum) * sizeof(iip->ports[0]));
2214            portnum--;
2736            field_config_free((input_field_config **)scanfieldptr);
2737            scanfieldnextptr = scanfieldptr;
22152738         }
22162739      }
2217
2218      /* allocate space for a new port at the end of this entry */
2219      if (iip->current_port >= iip->max_ports)
2220         fatalerror("Too many input ports");
2221      if (portnum < iip->current_port)
2222      {
2223         memmove(&iip->ports[portnum + 1], &iip->ports[portnum], (iip->current_port - portnum) * sizeof(iip->ports[0]));
2224         iip->current_port++;
2225         portentry = &iip->ports[portnum];
2226      }
2227      else
2228         portentry = &iip->ports[iip->current_port++];
22292740   }
22302741
2231   /* otherwise, just allocate a new one from the end */
2232   else
2233   {
2234      if (iip->current_port >= iip->max_ports)
2235         fatalerror("Too many input ports");
2236      portentry = &iip->ports[iip->current_port++];
2237   }
2742   /* make a mask of just the low bit */
2743   lowbit = (maskbits ^ (maskbits - 1)) & maskbits;
22382744
2239   /* set up defaults */
2240   memset(portentry, 0, sizeof(*portentry));
2241   portentry->name = IP_NAME_DEFAULT;
2242   portentry->type = type;
2243   portentry->mask = mask;
2244   portentry->default_value = defval;
2745   /* scan forward to find where to insert ourselves */
2746   for (scanfieldptr = (const input_field_config * const *)&port->fieldlist; *scanfieldptr != NULL; scanfieldptr = &(*scanfieldptr)->next)
2747      if ((*scanfieldptr)->mask > lowbit)
2748         break;
22452749
2246   /* default min to 0 and max to the mask value */
2247   /* they can be overwritten by PORT_MINMAX */
2248   if (port_type_is_analog(portentry->type) && !portentry->analog.min && !portentry->analog.max)
2249      portentry->analog.max = portentry->mask;
2750   /* allocate memory */
2751   config = malloc_or_die(sizeof(*config));
2752   memset(config, 0, sizeof(*config));
22502753
2251   /* sets up default port codes */
2252   switch (portentry->type)
2253   {
2254      case IPT_DIPSWITCH_NAME:
2255      case IPT_DIPSWITCH_SETTING:
2256      case IPT_CONFIG_NAME:
2257      case IPT_CONFIG_SETTING:
2258         code = SEQCODE_END;
2259         break;
2754   /* fill in the basic field values */
2755   config->port = port;
2756   config->type = type;
2757   config->mask = maskbits;
2758   config->defvalue = defvalue & maskbits;
2759   config->max = maskbits;
2760   for (seqtype = 0; seqtype < ARRAY_LENGTH(config->seq); seqtype++)
2761      input_seq_set_1(&config->seq[seqtype], SEQCODE_DEFAULT);
22602762
2261      default:
2262         code = SEQCODE_DEFAULT;
2263         break;
2264   }
2763   /* insert it into the list */
2764   config->next = *scanfieldptr;
2765   *(input_field_config **)scanfieldptr = config;
22652766
2266   /* set the default codes */
2267   input_seq_set_1(&portentry->seq, code);
2268   input_seq_set_1(&portentry->analog.incseq, code);
2269   input_seq_set_1(&portentry->analog.decseq, code);
2270   return portentry;
2767   return config;
22712768}
22722769
22732770
2274input_port_entry *input_port_allocate(const input_port_token *ipt, input_port_entry *memory)
2771/*-------------------------------------------------
2772    field_config_free - free an allocated input
2773    field configuration
2774-------------------------------------------------*/
2775
2776static void field_config_free(input_field_config **fieldptr)
22752777{
2276   input_port_init_params iip;
2778   input_field_config *field = *fieldptr;
22772779
2278   /* set up the port parameter structure */
2279   iip.max_ports = MAX_INPUT_PORTS * MAX_BITS_PER_PORT;
2280   iip.current_port = 0;
2780   /* free any settings and DIP locations first */
2781   while (field->settinglist != NULL)
2782      setting_config_free((input_setting_config **)&field->settinglist);
2783   while (field->diploclist != NULL)
2784      diplocation_free((input_field_diplocation **)&field->diploclist);
22812785
2282   /* allocate memory for the input ports */
2283   if (memory == NULL)
2284      iip.ports = (input_port_entry *)auto_malloc(iip.max_ports * sizeof(*iip.ports));
2285   else
2286      iip.ports = memory;
2287   memset(iip.ports, 0, iip.max_ports * sizeof(*iip.ports));
2786   /* remove ourself from the list */
2787   *fieldptr = (input_field_config *)field->next;
22882788
2289   /* construct the ports */
2290   input_port_detokenize(&iip, ipt);
2789   /* free ourself */
2790   free(field);
2791}
22912792
2292   /* append final IPT_END */
2293   input_port_initialize(&iip, IPT_END, NULL, 0, 0);
22942793
2295#ifdef MESS
2296   /* process MESS specific extensions to the port */
2297   inputx_handle_mess_extensions(iip.ports);
2298#endif
2794/*-------------------------------------------------
2795    setting_config_alloc - allocate a new input
2796    port setting and append it to the end of the
2797    list
2798-------------------------------------------------*/
22992799
2300   return iip.ports;
2800static input_setting_config *setting_config_alloc(input_field_config *field, input_port_value value, const char *name)
2801{
2802   const input_setting_config * const *tailptr;
2803   input_setting_config *config;
2804
2805   /* allocate memory */
2806   config = malloc_or_die(sizeof(*config));
2807   memset(config, 0, sizeof(*config));
2808
2809   /* fill in the basic setting values */
2810   config->field = field;
2811   config->value = value;
2812   config->name = name;
2813
2814   /* add it to the tail */
2815   for (tailptr = &field->settinglist; *tailptr != NULL; tailptr = &(*tailptr)->next) ;
2816   *(input_setting_config **)tailptr = config;
2817
2818   return config;
23012819}
23022820
23032821
2304void input_port_parse_diplocation(input_port_entry *in, const char *location)
2822/*-------------------------------------------------
2823    setting_config_free - free an allocated input
2824    setting configuration
2825-------------------------------------------------*/
2826
2827static void setting_config_free(input_setting_config **settingptr)
23052828{
2306   char *curname = NULL, tempbuf[100];
2307   const char *entry;
2308   int index, val, bits;
2309   UINT32 temp;
2829   input_setting_config *setting = (input_setting_config *)*settingptr;
23102830
2831   /* remove ourself from the list */
2832   *settingptr = (input_setting_config *)setting->next;
2833
2834   /* free ourself */
2835   free(setting);
2836}
2837
2838
2839/*-------------------------------------------------
2840    diplocation_expand - expand a string-based
2841    DIP location into a linked list of
2842    descriptions
2843-------------------------------------------------*/
2844
2845static const input_field_diplocation *diplocation_list_alloc(const input_field_config *field, const char *location)
2846{
2847   input_field_diplocation *head = NULL;
2848   input_field_diplocation **tailptr = &head;
2849   const char *curentry = location;
2850   char *lastname = NULL;
2851   char tempbuf[100];
2852   input_port_value temp;
2853   int entries = 0;
2854   int val, bits;
2855
23112856   /* if nothing present, bail */
2312   if (!location)
2313      return;
2314   memset(in->diploc, 0, sizeof(in->diploc));
2857   if (location == NULL)
2858      return NULL;
23152859
23162860   /* parse the string */
2317   for (index = 0, entry = location; *entry && index < ARRAY_LENGTH(in->diploc); index++)
2861   while (*curentry != 0)
23182862   {
23192863      const char *comma, *colon, *number;
23202864
2865      /* allocate a new entry */
2866      *tailptr = malloc_or_die(sizeof(**tailptr));
2867      memset(*tailptr, 0, sizeof(**tailptr));
2868      entries++;
2869
23212870      /* find the end of this entry */
2322      comma = strchr(entry, ',');
2871      comma = strchr(curentry, ',');
23232872      if (comma == NULL)
2324         comma = entry + strlen(entry);
2873         comma = curentry + strlen(curentry);
23252874
23262875      /* extract it to tempbuf */
2327      strncpy(tempbuf, entry, comma - entry);
2328      tempbuf[comma - entry] = 0;
2876      strncpy(tempbuf, curentry, comma - curentry);
2877      tempbuf[comma - curentry] = 0;
23292878
23302879      /* first extract the switch name if present */
23312880      number = tempbuf;
23322881      colon = strchr(tempbuf, ':');
2882
2883      /* allocate and copy the name if it is present */
23332884      if (colon != NULL)
23342885      {
2335         curname = auto_malloc(colon - tempbuf + 1);
2336         strncpy(curname, tempbuf, colon - tempbuf);
2337         curname[colon - tempbuf] = 0;
2886         (*tailptr)->swname = lastname = malloc_or_die(colon - tempbuf + 1);
2887         strncpy(lastname, tempbuf, colon - tempbuf);
2888         lastname[colon - tempbuf] = 0;
23382889         number = colon + 1;
23392890      }
23402891
2341      /* if we don't have a name by now, we're screwed */
2342      if (curname == NULL)
2343         fatalerror("Switch location '%s' missing switch name!", location);
2892      /* otherwise, just copy the last name */
2893      else
2894      {
2895         char *namecopy;
2896         if (lastname == NULL)
2897            fatalerror("Switch location '%s' missing switch name!", location);
2898         (*tailptr)->swname = namecopy = malloc_or_die(strlen(lastname) + 1);
2899         strcpy(namecopy, lastname);
2900      }
23442901
23452902      /* if the number is preceded by a '!' it's active high */
2903      (*tailptr)->invert = FALSE;
23462904      if (*number == '!')
23472905      {
2348         in->diploc[index].invert = 1;
2906         (*tailptr)->invert = TRUE;
23492907         number++;
23502908      }
2351      else
2352         in->diploc[index].invert = 0;
23532909
23542910      /* now scan the switch number */
23552911      if (sscanf(number, "%d", &val) != 1)
23562912         fatalerror("Switch location '%s' has invalid format!", location);
2913      (*tailptr)->swnum = val;
23572914
2358      /* fill the entry and bump the index */
2359      in->diploc[index].swname = curname;
2360      in->diploc[index].swnum = val;
2361
23622915      /* advance to the next item */
2363      entry = comma;
2364      if (*entry)
2365         entry++;
2916      curentry = comma;
2917      if (*curentry != 0)
2918         curentry++;
2919      tailptr = &(*tailptr)->next;
23662920   }
23672921
23682922   /* then verify the number of bits in the mask matches */
2369   for (bits = 0, temp = in->mask; temp && bits < 32; bits++)
2923   for (bits = 0, temp = field->mask; temp != 0 && bits < 32; bits++)
23702924      temp &= temp - 1;
2371   if (bits != index)
2372      fatalerror("Switch location '%s' does not describe enough bits for mask %X\n", location, in->mask);
2925   if (bits != entries)
2926      fatalerror("Switch location '%s' does not describe enough bits for mask %X\n", location, field->mask);
2927   return head;
23732928}
23742929
23752930
2931/*-------------------------------------------------
2932    diplocation_free - free an allocated dip
2933    location
2934-------------------------------------------------*/
23762935
2377/*************************************
2378 *
2379 *  List access
2380 *
2381 *************************************/
2382
2383input_port_default_entry *get_input_port_list(void)
2936static void diplocation_free(input_field_diplocation **diplocptr)
23842937{
2385   return default_ports;
2386}
2938   input_field_diplocation *diploc = (input_field_diplocation *)*diplocptr;
23872939
2940   /* free the name */
2941   if (diploc->swname != NULL)
2942      free((void *)diploc->swname);
23882943
2389const input_port_default_entry *get_input_port_list_defaults(void)
2390{
2391   return default_ports_backup;
2944   /* remove ourself from the list */
2945   *diplocptr = (input_field_diplocation *)diploc->next;
2946
2947   /* free ourself */
2948   free(diploc);
23922949}
23932950
23942951
23952952
2396/*************************************
2397 *
2398 *  Input port tokens
2399 *
2400 *************************************/
2953/***************************************************************************
2954    TOKENIZATION HELPERS
2955***************************************************************************/
24012956
2402const char *port_type_to_token(int type, int player)
2403{
2404   static char tempbuf[32];
2405   int defindex;
2957/*-------------------------------------------------
2958    token_to_input_field_type - convert a string
2959    token to an input field type and player
2960-------------------------------------------------*/
24062961
2407   /* look up the port and return the token */
2408   defindex = default_ports_lookup[type][player];
2409   if (defindex != -1)
2410      return default_ports[defindex].token;
2411
2412   /* if that fails, carry on */
2413   sprintf(tempbuf, "TYPE_OTHER(%d,%d)", type, player);
2414   return tempbuf;
2415}
2416
2417
2418int token_to_port_type(const char *string, int *player)
2962static int token_to_input_field_type(running_machine *machine, const char *string, int *player)
24192963{
2964   input_port_private *portdata = machine->input_port_data;
2965   const input_type_desc *typedesc;
24202966   int ipnum;
24212967
24222968   /* check for our failsafe case first */
r2724r2725
24242970      return ipnum;
24252971
24262972   /* find the token in the list */
2427   for (ipnum = 0; ipnum < input_port_count; ipnum++)
2428      if (default_ports[ipnum].token != NULL && !strcmp(default_ports[ipnum].token, string))
2973   for (typedesc = &portdata->typestatelist->typedesc; typedesc != NULL; typedesc = typedesc->next)
2974      if (typedesc->token != NULL && !strcmp(typedesc->token, string))
24292975      {
2430         *player = default_ports[ipnum].player;
2431         return default_ports[ipnum].type;
2976         *player = typedesc->player;
2977         return typedesc->type;
24322978      }
24332979
24342980   /* if we fail, return IPT_UNKNOWN */
r2724r2725
24372983}
24382984
24392985
2986/*-------------------------------------------------
2987    input_field_type_to_token - convert an input
2988    field type and player to a string token
2989-------------------------------------------------*/
24402990
2441/*************************************
2442 *
2443 *  Input port getters
2444 *
2445 *************************************/
2446
2447int input_port_active(const input_port_entry *portentry)
2991static const char *input_field_type_to_token(running_machine *machine, int type, int player)
24482992{
2449   return (input_port_name(portentry) != NULL && !portentry->unused);
2450}
2993   input_port_private *portdata = machine->input_port_data;
2994   input_type_state *typestate;
2995   static char tempbuf[32];
24512996
2997   /* look up the port and return the token */
2998   typestate = portdata->type_to_typestate[type][player];
2999   if (typestate != NULL)
3000      return typestate->typedesc.token;
24523001
2453int port_type_is_analog(int type)
2454{
2455   return (type >= __ipt_analog_start && type <= __ipt_analog_end);
3002   /* if that fails, carry on */
3003   sprintf(tempbuf, "TYPE_OTHER(%d,%d)", type, player);
3004   return tempbuf;
24563005}
24573006
24583007
2459int port_type_is_analog_absolute(int type)
2460{
2461   return (type >= __ipt_analog_absolute_start && type <= __ipt_analog_absolute_end);
2462}
3008/*-------------------------------------------------
3009    token_to_seq_type - convert a string to
3010    a sequence type
3011-------------------------------------------------*/
24633012
2464
2465int port_type_in_use(int type)
3013static int token_to_seq_type(const char *string)
24663014{
2467   input_port_entry *portentry;
2468   for (portentry = Machine->input_ports; portentry->type != IPT_END; portentry++)
2469      if (portentry->type == type)
2470         return 1;
2471   return 0;
2472}
3015   int seqindex;
24733016
3017   /* look up the string in the table of possible sequence types and return the index */
3018   for (seqindex = 0; seqindex < ARRAY_LENGTH(seqtypestrings); seqindex++)
3019      if (!mame_stricmp(string, seqtypestrings[seqindex]))
3020         return seqindex;
24743021
2475int port_type_to_group(int type, int player)
2476{
2477   int defindex = default_ports_lookup[type][player];
2478   if (defindex != -1)
2479      return default_ports[defindex].group;
2480   return IPG_INVALID;
2481}
2482
2483
2484int port_tag_to_index(const char *tag)
2485{
2486   int portnum;
2487
2488   /* find the matching tag */
2489   for (portnum = 0; portnum < MAX_INPUT_PORTS; portnum++)
2490      if (port_info[portnum].tag != NULL && !strcmp(port_info[portnum].tag, tag))
2491         return portnum;
24923022   return -1;
24933023}
24943024
24953025
2496read8_machine_func port_tag_to_handler8(const char *tag)
2497{
2498   int portnum = port_tag_to_index(tag);
2499   return (portnum == -1) ? SMH_NOP : port_handler8[portnum];
2500}
25013026
3027/***************************************************************************
3028    SETTINGS LOAD
3029***************************************************************************/
25023030
2503read16_machine_func port_tag_to_handler16(const char *tag)
2504{
2505   int portnum = port_tag_to_index(tag);
2506   return (portnum == -1) ? SMH_NOP : port_handler16[portnum];
2507}
3031/*-------------------------------------------------
3032    load_config_callback - callback to extract
3033    configuration data from the XML nodes
3034-------------------------------------------------*/
25083035
2509
2510read32_machine_func port_tag_to_handler32(const char *tag)
3036static void load_config_callback(running_machine *machine, int config_type, xml_data_node *parentnode)
25113037{
2512   int portnum = port_tag_to_index(tag);
2513   return (portnum == -1) ? SMH_NOP : port_handler32[portnum];
2514}
3038   input_port_private *portdata = machine->input_port_data;
3039   xml_data_node *portnode;
3040   int seqtype;
25153041
3042   /* in the completion phase, we finish the initialization with the final ports */
3043   if (config_type == CONFIG_TYPE_FINAL)
3044      frame_update(machine);
25163045
2517read64_machine_func port_tag_to_handler64(const char *tag)
2518{
2519   return SMH_NOP;
2520}
3046   /* early exit if no data to parse */
3047   if (parentnode == NULL)
3048      return;
25213049
3050   /* iterate over all the remap nodes for controller configs only */
3051   if (config_type == CONFIG_TYPE_CONTROLLER)
3052      load_remap_table(machine, parentnode);
25223053
2523const char *input_port_name(const input_port_entry *portentry)
2524{
2525   int defindex;
2526
2527   /* if we have a non-default name, use that */
2528   if (portentry->name != IP_NAME_DEFAULT)
2529      return portentry->name;
2530
2531   /* if the port exists, return the default name */
2532   defindex = default_ports_lookup[portentry->type][portentry->player];
2533   if (defindex != -1)
2534      return default_ports[defindex].name;
2535
2536   /* should never get here */
2537   return NULL;
2538}
2539
2540
2541const input_seq *input_port_seq(input_port_entry *portentry, input_seq_type seqtype)
2542{
2543   static const input_seq ip_none = SEQ_DEF_0;
2544   input_seq *portseq;
2545
2546   /* if port is disabled, return no key */
2547   if (portentry->unused)
2548      return &ip_none;
2549
2550   /* handle the various seq types */
2551   switch (seqtype)
3054   /* iterate over all the port nodes */
3055   for (portnode = xml_get_sibling(parentnode->child, "port"); portnode; portnode = xml_get_sibling(portnode->next, "port"))
25523056   {
2553      case SEQ_TYPE_STANDARD:
2554         portseq = &portentry->seq;
2555         break;
3057      input_seq newseq[SEQ_TYPE_TOTAL], tempseq;
3058      xml_data_node *seqnode;
3059      int type, player;
25563060
2557      case SEQ_TYPE_INCREMENT:
2558         if (!IS_ANALOG(portentry))
2559            return &ip_none;
2560         portseq = &portentry->analog.incseq;
2561         break;
3061      /* get the basic port info from the attributes */
3062      type = token_to_input_field_type(machine, xml_get_attribute_string(portnode, "type", ""), &player);
25623063
2563      case SEQ_TYPE_DECREMENT:
2564         if (!IS_ANALOG(portentry))
2565            return &ip_none;
2566         portseq = &portentry->analog.decseq;
2567         break;
3064      /* initialize sequences to invalid defaults */
3065      for (seqtype = 0; seqtype < ARRAY_LENGTH(newseq); seqtype++)
3066         input_seq_set_1(&newseq[seqtype], INPUT_CODE_INVALID);
25683067
2569      default:
2570         return &ip_none;
2571   }
2572
2573   /* does this override the default? if so, return it directly */
2574   if (input_seq_get_1(portseq) != SEQCODE_DEFAULT)
2575      return portseq;
2576
2577   /* otherwise find the default setting */
2578   return input_port_default_seq(portentry->type, portentry->player, seqtype);
2579}
2580
2581
2582const input_seq *input_port_default_seq(int type, int player, input_seq_type seqtype)
2583{
2584   static const input_seq ip_none = SEQ_DEF_0;
2585
2586   /* find the default setting */
2587   int defindex = default_ports_lookup[type][player];
2588   if (defindex != -1)
2589   {
2590      switch (seqtype)
3068      /* loop over new sequences */
3069      for (seqnode = xml_get_sibling(portnode->child, "newseq"); seqnode; seqnode = xml_get_sibling(seqnode->next, "newseq"))
25913070      {
2592         case SEQ_TYPE_STANDARD:
2593            return &default_ports[defindex].defaultseq;
2594         case SEQ_TYPE_INCREMENT:
2595            return &default_ports[defindex].defaultincseq;
2596         case SEQ_TYPE_DECREMENT:
2597            return &default_ports[defindex].defaultdecseq;
3071         /* with a valid type, parse out the new sequence */
3072         seqtype = token_to_seq_type(xml_get_attribute_string(seqnode, "type", ""));
3073         if (seqtype != -1 && seqnode->value != NULL)
3074         {
3075            if (strcmp(seqnode->value, "NONE") == 0)
3076               input_seq_set_0(&newseq[seqtype]);
3077            else if (input_seq_from_tokens(seqnode->value, &tempseq) != 0)
3078               newseq[seqtype] = tempseq;
3079         }
25983080      }
3081
3082      /* if we're loading default ports, apply to the defaults */
3083      if (config_type != CONFIG_TYPE_GAME)
3084         load_default_config(machine, portnode, type, player, newseq);
3085      else
3086         load_game_config(machine, portnode, type, player, newseq);
25993087   }
2600   return &ip_none;
2601}
26023088
3089   /* after applying the controller config, push that back into the backup, since that is */
3090   /* what we will diff against */
3091   if (config_type == CONFIG_TYPE_CONTROLLER)
3092   {
3093      input_type_state *typestate;
3094      int seqtype;
26033095
2604int input_port_condition(const input_port_entry *in)
2605{
2606   switch (in->condition.condition)
2607   {
2608      case PORTCOND_EQUALS:
2609         return ((input_port_read_indexed(Machine, in->condition.portnum) & in->condition.mask) == in->condition.value);
2610      case PORTCOND_NOTEQUALS:
2611         return ((input_port_read_indexed(Machine, in->condition.portnum) & in->condition.mask) != in->condition.value);
3096      for (typestate = portdata->typestatelist; typestate != NULL; typestate = typestate->next)
3097         for (seqtype = 0; seqtype < ARRAY_LENGTH(typestate->typedesc.seq); seqtype++)
3098            typestate->typedesc.seq[seqtype] = typestate->seq[seqtype];
26123099   }
2613   return 1;
26143100}
26153101
26163102
3103/*-------------------------------------------------
3104    load_remap_table - extract and apply the
3105    global remapping table
3106-------------------------------------------------*/
26173107
2618/*************************************
2619 *
2620 *  Key sequence handlers
2621 *
2622 *************************************/
2623
2624int input_port_type_pressed(int type, int player)
3108static void load_remap_table(running_machine *machine, xml_data_node *parentnode)
26253109{
2626   int defindex = default_ports_lookup[type][player];
2627   if (defindex != -1)
2628      return input_seq_pressed(&default_ports[defindex].defaultseq);
3110   input_port_private *portdata = machine->input_port_data;
3111   input_code *oldtable, *newtable;
3112   xml_data_node *remapnode;
3113   int count;
26293114
2630   return 0;
2631}
3115   /* count items first so we can allocate */
3116   count = 0;
3117   for (remapnode = xml_get_sibling(parentnode->child, "remap"); remapnode != NULL; remapnode = xml_get_sibling(remapnode->next, "remap"))
3118      count++;
26323119
2633
2634int input_ui_pressed(int code)
2635{
2636   int pressed;
2637
2638profiler_mark(PROFILER_INPUT);
2639
2640   /* get the status of this key (assumed to be only in the defaults) */
2641   pressed = input_seq_pressed(input_port_default_seq(code, 0, SEQ_TYPE_STANDARD));
2642
2643   /* if pressed, handle it specially */
2644   if (pressed)
3120   /* if we have some, deal with them */
3121   if (count > 0)
26453122   {
2646      /* if this is the first press, leave pressed = 1 */
2647      if (ui_memory[code] == 0)
2648         ui_memory[code] = 1;
3123      int remapnum;
26493124
2650      /* otherwise, reset pressed = 0 */
2651      else
2652         pressed = 0;
2653   }
3125      /* allocate tables */
3126      oldtable = malloc_or_die(count * sizeof(*oldtable));
3127      newtable = malloc_or_die(count * sizeof(*newtable));
26543128
2655   /* if we're not pressed, reset the memory field */
2656   else
2657      ui_memory[code] = 0;
2658
2659profiler_mark(PROFILER_END);
2660
2661   return pressed;
2662}
2663
2664
2665int input_ui_pressed_repeat(int code, int speed)
2666{
2667   static osd_ticks_t lastdown;
2668   static osd_ticks_t keydelay;
2669   int pressed;
2670
2671profiler_mark(PROFILER_INPUT);
2672
2673   /* get the status of this key (assumed to be only in the defaults) */
2674   pressed = input_seq_pressed(input_port_default_seq(code, 0, SEQ_TYPE_STANDARD));
2675
2676   /* if so, handle it specially */
2677   if (pressed)
2678   {
2679      /* if this is the first press, set a 3x delay and leave pressed = 1 */
2680      if (ui_memory[code] == 0)
3129      /* build up the remap table */
3130      count = 0;
3131      for (remapnode = xml_get_sibling(parentnode->child, "remap"); remapnode != NULL; remapnode = xml_get_sibling(remapnode->next, "remap"))
26813132      {
2682         ui_memory[code] = 1;
2683         lastdown = osd_ticks();
2684         keydelay = 3 * speed * osd_ticks_per_second() / 60;
3133         input_code origcode = input_code_from_token(xml_get_attribute_string(remapnode, "origcode", ""));
3134         input_code newcode = input_code_from_token(xml_get_attribute_string(remapnode, "newcode", ""));
3135         if (origcode != INPUT_CODE_INVALID && newcode != INPUT_CODE_INVALID)
3136         {
3137            oldtable[count] = origcode;
3138            newtable[count] = newcode;
3139            count++;
3140         }
26853141      }
26863142
2687      /* if this is an autorepeat case, set a 1x delay and leave pressed = 1 */
2688      else if (osd_ticks() - lastdown >= keydelay)
3143      /* loop over the remapping table, operating only if something was specified */
3144      for (remapnum = 0; remapnum < count; remapnum++)
26893145      {
2690         lastdown += keydelay;
2691         keydelay = 1 * speed * osd_ticks_per_second() / 60;
3146         input_code oldcode = oldtable[remapnum];
3147         input_code newcode = newtable[remapnum];
3148         input_type_state *typestate;
3149
3150         /* loop over all default ports, remapping the requested keys */
3151         for (typestate = portdata->typestatelist; typestate != NULL; typestate = typestate->next)
3152         {
3153            int seqtype, codenum;
3154
3155            /* remap anything in the default sequences */
3156            for (seqtype = 0; seqtype < ARRAY_LENGTH(typestate->seq); seqtype++)
3157               for (codenum = 0; codenum < ARRAY_LENGTH(typestate->seq[0].code); codenum++)
3158                  if (typestate->seq[seqtype].code[codenum] == oldcode)
3159                     typestate->seq[seqtype].code[codenum] = newcode;
3160         }
26923161      }
26933162
2694      /* otherwise, reset pressed = 0 */
2695      else
2696         pressed = 0;
3163      /* release the tables */
3164      free(oldtable);
3165      free(newtable);
26973166   }
2698
2699   /* if we're not pressed, reset the memory field */
2700   else
2701      ui_memory[code] = 0;
2702
2703profiler_mark(PROFILER_END);
2704
2705   return pressed;
27063167}
27073168
27083169
3170/*-------------------------------------------------
3171    load_default_config - apply configuration
3172    data to the default mappings
3173-------------------------------------------------*/
27093174
2710/*************************************
2711 *
2712 *  Update default ports
2713 *
2714 *************************************/
2715
2716void input_port_update_defaults(void)
3175static int load_default_config(running_machine *machine, xml_data_node *portnode, int type, int player, const input_seq *newseq)
27173176{
2718   int loopnum, portnum;
3177   input_port_private *portdata = machine->input_port_data;
3178   input_type_state *typestate;
3179   int seqtype;
27193180
2720   /* two passes to catch conditionals properly */
2721   for (loopnum = 0; loopnum < 2; loopnum++)
2722
2723      /* loop over all input ports */
2724      for (portnum = 0; portnum < MAX_INPUT_PORTS; portnum++)
3181   /* find a matching port in the list */
3182   for (typestate = portdata->typestatelist; typestate != NULL; typestate = typestate->next)
3183      if (typestate->typedesc.type == type && typestate->typedesc.player == player)
27253184      {
2726         input_port_info *portinfo = &port_info[portnum];
2727         input_bit_info *info;
2728         int bitnum;
3185         for (seqtype = 0; seqtype < ARRAY_LENGTH(typestate->seq); seqtype++)
3186            if (input_seq_get_1(&newseq[seqtype]) != INPUT_CODE_INVALID)
3187               typestate->seq[seqtype] = newseq[seqtype];
3188         return TRUE;
3189      }
27293190
2730         /* only clear on the first pass */
2731         if (loopnum == 0)
2732            portinfo->defvalue = 0;
2733
2734         /* first compute the default value for the entire port */
2735         for (bitnum = 0, info = &portinfo->bit[0]; bitnum < MAX_BITS_PER_PORT && info->portentry; bitnum++, info++)
2736            if (input_port_condition(info->portentry))
2737               portinfo->defvalue = (portinfo->defvalue & ~info->portentry->mask) | (info->portentry->default_value & info->portentry->mask);
2738      }
3191   return FALSE;
27393192}
27403193
27413194
3195/*-------------------------------------------------
3196    load_game_config - apply configuration
3197    data to the current set of input ports
3198-------------------------------------------------*/
27423199
2743/*************************************
2744 *
2745 *  VBLANK start routine
2746 *
2747 *************************************/
2748
2749static void input_port_frame(running_machine *machine)
3200static int load_game_config(running_machine *machine, xml_data_node *portnode, int type, int player, const input_seq *newseq)
27503201{
2751   /* if we're paused, don't do anything */
2752   if (mame_is_paused(machine))
2753      return;
3202   input_port_value mask, defvalue;
3203   const input_field_config *field;
3204   const input_port_config *port;
3205   const char *tag;
27543206
2755   /* otherwise, use the common code */
2756   input_port_frame_update(machine);
2757}
3207   /* read the mask, index, and defvalue attributes */
3208   tag = xml_get_attribute_string(portnode, "port", NULL);
3209   mask = xml_get_attribute_int(portnode, "mask", 0);
3210   defvalue = xml_get_attribute_int(portnode, "defvalue", 0);
27583211
3212   /* find the port we want; if no tag, search them all */
3213   for (port = machine->portconfig; port != NULL; port = port->next)
3214      if (tag == NULL || (port->tag != NULL && strcmp(port->tag, tag) == 0))
3215         for (field = port->fieldlist; field != NULL; field = field->next)
27593216
2760static void input_port_frame_update(running_machine *machine)
2761{
2762   int ui_visible = ui_is_menu_active() || ui_is_slider_active();
2763   attotime curtime = timer_get_time();
2764   int portnum, bitnum;
2765
2766profiler_mark(PROFILER_INPUT);
2767
2768   /* record/playback information about the current frame */
2769   playback_frame(machine, curtime);
2770   record_frame(machine, curtime);
2771
2772   /* track the duration of the previous frame */
2773   last_delta = attotime_to_attoseconds(attotime_sub(curtime, last_update)) / ATTOSECONDS_PER_SECOND_SQRT;
2774   last_update = curtime;
2775
2776   /* update all analog ports if the UI isn't visible */
2777   if (!ui_visible)
2778      for (portnum = 0; portnum < MAX_INPUT_PORTS; portnum++)
2779         update_analog_port(portnum);
2780
2781   /* update the digital joysticks first */
2782   update_digital_joysticks(machine);
2783
2784   /* compute default values for all the ports */
2785   input_port_update_defaults();
2786
2787   /* loop over all input ports */
2788   for (portnum = 0; portnum < MAX_INPUT_PORTS; portnum++)
2789   {
2790      input_port_info *portinfo = &port_info[portnum];
2791      input_bit_info *info;
2792      changed_port_info *changed;
2793
2794      /* compute the VBLANK mask */
2795      portinfo->vblank = 0;
2796      for (bitnum = 0, info = &portinfo->bit[0]; bitnum < MAX_BITS_PER_PORT && info->portentry; bitnum++, info++)
2797         if (input_port_condition(info->portentry) && info->portentry->type == IPT_VBLANK)
2798            portinfo->vblank ^= info->portentry->mask;
2799
2800      /* now loop back and modify based on the inputs */
2801      portinfo->digital = 0;
2802      for (bitnum = 0, info = &portinfo->bit[0]; bitnum < MAX_BITS_PER_PORT && info->portentry; bitnum++, info++)
2803         if (input_port_condition(info->portentry))
2804         {
2805            input_port_entry *portentry = info->portentry;
2806
2807            /* handle non-analog types, but only when the UI isn't visible */
2808            if (portentry->type != IPT_VBLANK && !IS_ANALOG(portentry) && !ui_visible)
3217            /* find the matching mask and defvalue */
3218            if (field->type == type && field->player == player &&
3219               field->mask == mask && (field->defvalue & mask) == (defvalue & mask))
28093220            {
2810               /* if the sequence for this port is currently pressed.... */
2811               if (input_seq_pressed(input_port_seq(portentry, SEQ_TYPE_STANDARD)))
2812               {
2813#ifdef MESS
2814                  /* (MESS-specific) check for disabled keyboard */
2815                  if (portentry->type == IPT_KEYBOARD && osd_keyboard_disabled())
2816                     continue;
2817#endif /* MESS */
2818                  /* skip locked-out coin inputs */
2819                  if (portentry->type >= IPT_COIN1 && portentry->type <= IPT_COIN8 && coinlockedout[portentry->type - IPT_COIN1])
2820                  {
2821                     ui_popup_time(3, "Coinlock disabled %s.", input_port_name(portentry));
2822                     continue;
2823                  }
2824                  if (portentry->type >= IPT_SERVICE1 && portentry->type <= IPT_SERVICE4 && servicecoinlockedout[portentry->type - IPT_SERVICE1])
2825                  {
2826                     ui_popup_time(3, "Coinlock disabled %s.", input_port_name(portentry));
2827                     continue;
2828                  }
2829                  /* if this is a downward press and we're an impulse control, reset the count */
2830                  if (portentry->impulse)
2831                  {
2832                     if (info->last == 0)
2833                        info->impulse = portentry->impulse;
2834                  }
3221               const char *revstring;
3222               int seqtype;
28353223
2836                  /* if this is a downward press and we're a toggle control, toggle the value */
2837                  else if (portentry->toggle)
2838                  {
2839                     if (info->last == 0)
2840                     {
2841                        portentry->default_value ^= portentry->mask;
2842                        portinfo->digital ^= portentry->mask;
2843                     }
2844                  }
3224               /* if a sequence was specified, copy it in */
3225               for (seqtype = 0; seqtype < ARRAY_LENGTH(field->state->seq); seqtype++)
3226                  if (input_seq_get_1(&newseq[seqtype]) != INPUT_CODE_INVALID)
3227                     field->state->seq[seqtype] = newseq[seqtype];
28453228
2846                  /* if this is a digital joystick type, apply either standard or 4-way rules */
2847                  else if (IS_DIGITAL_JOYSTICK(portentry))
2848                  {
2849                     digital_joystick_info *joyinfo = JOYSTICK_INFO_FOR_PORT(portentry);
2850                     UINT8 mask;
2851                     switch( portentry->way )
2852                     {
2853                        case 4:
2854                           mask = joyinfo->current4way;
2855                           break;
2856                        case 16:
2857                           mask = 0xff;
2858                           break;
2859                        default:
2860                           mask = joyinfo->current;
2861                           break;
2862                     }
2863                     if ((mask >> JOYSTICK_DIR_FOR_PORT(portentry)) & 1)
2864                        portinfo->digital ^= portentry->mask;
2865                  }
3229               /* for non-analog fields, fetch the value */
3230               if (field->state->analog == NULL)
3231                  field->state->value = xml_get_attribute_int(portnode, "value", field->defvalue);
28663232
2867                  /* otherwise, just set it raw */
2868                  else
2869                     portinfo->digital ^= portentry->mask;
2870
2871                  /* track the last value */
2872                  info->last = 1;
2873               }
3233               /* for analog fields, fetch configurable analog attributes */
28743234               else
2875                  info->last = 0;
3235               {
3236                  /* get base attributes */
3237                  field->state->analog->delta = xml_get_attribute_int(portnode, "keydelta", field->delta);
3238                  field->state->analog->centerdelta = xml_get_attribute_int(portnode, "centerdelta", field->centerdelta);
3239                  field->state->analog->sensitivity = xml_get_attribute_int(portnode, "sensitivity", field->sensitivity);
28763240
2877               /* handle the impulse countdown */
2878               if (portentry->impulse && info->impulse > 0)
2879               {
2880                  info->impulse--;
2881                  info->last = 1;
2882                  portinfo->digital ^= portentry->mask;
3241                  /* fetch yes/no for reverse setting */
3242                  revstring = xml_get_attribute_string(portnode, "reverse", NULL);
3243                  if (revstring != NULL)
3244                     field->state->analog->reverse = (strcmp(revstring, "yes") == 0);
28833245               }
3246               return TRUE;
28843247            }
28853248
2886            /* note that analog ports are handled instantaneously at port read time */
2887         }
3249   return FALSE;
3250}
28883251
2889#ifdef MESS
2890      /* hook for MESS's natural keyboard support */
2891      mess_input_port_update_hook(machine, portnum, &portinfo->digital);
2892#endif /* MESS */
28933252
2894      /* call changed handlers */
2895      for (changed = portinfo->changedinfo; changed; changed = changed->next)
2896         if (input_port_condition(changed->portentry))
2897         {
2898            input_port_entry *portentry = changed->portentry;
28993253
2900            UINT32 new_unmasked_value = input_port_read_indexed(machine, portnum);
2901            UINT32 newval = (new_unmasked_value       & portentry->mask) >> changed->shift;
2902            UINT32 oldval = (portentry->changed_last_value & portentry->mask) >> changed->shift;
3254/***************************************************************************
3255    SETTINGS SAVE
3256***************************************************************************/
29033257
2904            if (newval != oldval)
2905               (*portentry->changed)(machine, portentry->changed_param, oldval, newval);
3258/*-------------------------------------------------
3259    save_config_callback - config callback for
3260    saving input port configuration
3261-------------------------------------------------*/
29063262
2907            portentry->changed_last_value = new_unmasked_value;
2908         }
2909   }
3263static void save_config_callback(running_machine *machine, int config_type, xml_data_node *parentnode)
3264{
3265   /* if no parentnode, ignore */
3266   if (parentnode == NULL)
3267      return;
29103268
2911   /* handle playback/record */
2912   for (portnum = 0; portnum < MAX_INPUT_PORTS; portnum++)
2913   {
2914      playback_port(machine, &port_info[portnum]);
2915      record_port(machine, &port_info[portnum]);
2916   }
2917
2918profiler_mark(PROFILER_END);
3269   /* default ports save differently */
3270   if (config_type == CONFIG_TYPE_DEFAULT)
3271      save_default_inputs(machine, parentnode);
3272   else
3273      save_game_inputs(machine, parentnode);
29193274}
29203275
29213276
3277/*-------------------------------------------------
3278    save_sequence - add a node for an input
3279    sequence
3280-------------------------------------------------*/
29223281
2923/*************************************
2924 *
2925 *  Digital joystick updating
2926 *
2927 *************************************/
2928
2929static void update_digital_joysticks(running_machine *machine)
3282static void save_sequence(xml_data_node *parentnode, int type, int porttype, const input_seq *seq)
29303283{
2931   int player, joyindex;
3284   astring *seqstring = astring_alloc();
3285   xml_data_node *seqnode;
29323286
2933   /* loop over all the joysticks */
2934   for (player = 0; player < MAX_PLAYERS; player++)
2935      for (joyindex = 0; joyindex < DIGITAL_JOYSTICKS_PER_PLAYER; joyindex++)
2936      {
2937         digital_joystick_info *info = &joystick_info[player][joyindex];
2938         if (info->inuse)
2939         {
2940            info->previous = info->current;
2941            info->current = 0;
3287   /* get the string for the sequence */
3288   if (input_seq_get_1(seq) == SEQCODE_END)
3289      astring_cpyc(seqstring, "NONE");
3290   else
3291      input_seq_to_tokens(seqstring, seq);
29423292
2943            /* read all the associated ports */
2944            if (info->portentry[JOYDIR_UP] != NULL && input_seq_pressed(input_port_seq(info->portentry[JOYDIR_UP], SEQ_TYPE_STANDARD)))
2945               info->current |= JOYDIR_UP_BIT;
2946            if (info->portentry[JOYDIR_DOWN] != NULL && input_seq_pressed(input_port_seq(info->portentry[JOYDIR_DOWN], SEQ_TYPE_STANDARD)))
2947               info->current |= JOYDIR_DOWN_BIT;
2948            if (info->portentry[JOYDIR_LEFT] != NULL && input_seq_pressed(input_port_seq(info->portentry[JOYDIR_LEFT], SEQ_TYPE_STANDARD)))
2949               info->current |= JOYDIR_LEFT_BIT;
2950            if (info->portentry[JOYDIR_RIGHT] != NULL && input_seq_pressed(input_port_seq(info->portentry[JOYDIR_RIGHT], SEQ_TYPE_STANDARD)))
2951               info->current |= JOYDIR_RIGHT_BIT;
2952
2953            /* lock out opposing directions (left + right or up + down) */
2954            if ((info->current & (JOYDIR_UP_BIT | JOYDIR_DOWN_BIT)) == (JOYDIR_UP_BIT | JOYDIR_DOWN_BIT))
2955               info->current &= ~(JOYDIR_UP_BIT | JOYDIR_DOWN_BIT);
2956            if ((info->current & (JOYDIR_LEFT_BIT | JOYDIR_RIGHT_BIT)) == (JOYDIR_LEFT_BIT | JOYDIR_RIGHT_BIT))
2957               info->current &= ~(JOYDIR_LEFT_BIT | JOYDIR_RIGHT_BIT);
2958
2959            /* only update 4-way case if joystick has moved */
2960            if (info->current != info->previous)
2961            {
2962               info->current4way = info->current;
2963
2964               /*
2965                        If joystick is pointing at a diagonal, acknowledge that the player moved
2966                        the joystick by favoring a direction change.  This minimizes frustration
2967                        when using a keyboard for input, and maximizes responsiveness.
2968
2969                        For example, if you are holding "left" then switch to "up" (where both left
2970                        and up are briefly pressed at the same time), we'll transition immediately
2971                        to "up."
2972
2973                        Zero any switches that didn't change from the previous to current state.
2974                     */
2975               if ((info->current4way & (JOYDIR_UP_BIT | JOYDIR_DOWN_BIT)) &&
2976                  (info->current4way & (JOYDIR_LEFT_BIT | JOYDIR_RIGHT_BIT)))
2977               {
2978                  info->current4way ^= info->current4way & info->previous;
2979               }
2980
2981               /*
2982                        If we are still pointing at a diagonal, we are in an indeterminant state.
2983
2984                        This could happen if the player moved the joystick from the idle position directly
2985                        to a diagonal, or from one diagonal directly to an extreme diagonal.
2986
2987                        The chances of this happening with a keyboard are slim, but we still need to
2988                        constrain this case.
2989
2990                        For now, just resolve randomly.
2991                     */
2992               if ((info->current4way & (JOYDIR_UP_BIT | JOYDIR_DOWN_BIT)) &&
2993                  (info->current4way & (JOYDIR_LEFT_BIT | JOYDIR_RIGHT_BIT)))
2994               {
2995                  if (mame_rand(machine) & 1)
2996                     info->current4way &= ~(JOYDIR_LEFT_BIT | JOYDIR_RIGHT_BIT);
2997                  else
2998                     info->current4way &= ~(JOYDIR_UP_BIT | JOYDIR_DOWN_BIT);
2999               }
3000            }
3001         }
3002      }
3293   /* add the new node */
3294   seqnode = xml_add_child(parentnode, "newseq", astring_c(seqstring));
3295   if (seqnode != NULL)
3296      xml_set_attribute(seqnode, "type", seqtypestrings[type]);
3297   astring_free(seqstring);
30033298}
30043299
30053300
3301/*-------------------------------------------------
3302    save_this_input_field_type - determine if the given
3303    port type is worth saving
3304-------------------------------------------------*/
30063305
3007/*************************************
3008 *
3009 *  Analog minimum/maximum clamping
3010 *
3011 *************************************/
3012
3013INLINE INT32 apply_analog_min_max(const analog_port_info *info, INT32 value)
3306static int save_this_input_field_type(int type)
30143307{
3015   const input_port_entry *portentry = info->portentry;
3016   INT32 adjmax, adjmin, adj1, adjdif;
3017
3018   /* take the analog minimum and maximum values and apply the inverse of the */
3019   /* sensitivity so that we can clamp against them before applying sensitivity */
3020   adjmin = APPLY_INVERSE_SENSITIVITY(info->minimum, portentry->analog.sensitivity);
3021   adjmax = APPLY_INVERSE_SENSITIVITY(info->maximum, portentry->analog.sensitivity);
3022   adj1   = APPLY_INVERSE_SENSITIVITY(512, portentry->analog.sensitivity);
3023
3024   /* for absolute devices, clamp to the bounds absolutely */
3025   if (!info->wraps)
3308   switch (type)
30263309   {
3027      if (value > adjmax)
3028         value = adjmax;
3029      else if (value < adjmin)
3030         value = adjmin;
3310      case IPT_UNUSED:
3311      case IPT_END:
3312      case IPT_PORT:
3313      case IPT_VBLANK:
3314      case IPT_UNKNOWN:
3315         return FALSE;
30313316   }
3032
3033   /* for relative devices, wrap around when we go past the edge */
3034   else
3035   {
3036      adjdif = adjmax - adjmin + adj1;
3037      if (portentry->analog.reverse)
3038      {
3039         while (value <= adjmin - adj1)
3040            value += adjdif;
3041         while (value > adjmax)
3042            value -= adjdif;
3043      }
3044      else
3045      {
3046         while (value >= adjmax + adj1)
3047            value -= adjdif;
3048         while (value < adjmin)
3049            value += adjdif;
3050      }
3051   }
3052
3053   return value;
3317   return TRUE;
30543318}
30553319
30563320
3321/*-------------------------------------------------
3322    save_default_inputs - add nodes for any default
3323    mappings that have changed
3324-------------------------------------------------*/
30573325
3058/*************************************
3059 *
3060 *  Analog port updating
3061 *
3062 *************************************/
3063
3064static void update_analog_port(int portnum)
3326static void save_default_inputs(running_machine *machine, xml_data_node *parentnode)
30653327{
3066   analog_port_info *info;
3328   input_port_private *portdata = machine->input_port_data;
3329   input_type_state *typestate;
30673330
3068   /* loop over all analog ports in this port number */
3069   for (info = port_info[portnum].analoginfo; info != NULL; info = info->next)
3331   /* iterate over ports */
3332   for (typestate = portdata->typestatelist; typestate != NULL; typestate = typestate->next)
30703333   {
3071      input_port_entry *portentry = info->portentry;
3072      INT32 rawvalue;
3073      INT32 delta = 0;
3074      INT64 keyscale;
3075      int keypressed = FALSE;
3076      input_item_class itemclass;
3334      /* only save if this port is a type we save */
3335      if (save_this_input_field_type(typestate->typedesc.type))
3336      {
3337         int seqtype;
30773338
3078      /* clamp the previous value to the min/max range and remember it */
3079      info->previous = info->accum = apply_analog_min_max(info, info->accum);
3339         /* see if any of the sequences have changed */
3340         for (seqtype = 0; seqtype < ARRAY_LENGTH(typestate->seq); seqtype++)
3341            if (input_seq_cmp(&typestate->seq[seqtype], &typestate->typedesc.seq[seqtype]) != 0)
3342               break;
30803343
3081      /* get the new raw analog value and its type */
3082      rawvalue = input_seq_axis_value(input_port_seq(portentry, SEQ_TYPE_STANDARD), &itemclass);
3083
3084      /* if we got an absolute input, it overrides everything else */
3085      if (itemclass == ITEM_CLASS_ABSOLUTE)
3086      {
3087         if (info->previousanalog != rawvalue)
3344         /* if so, we need to add a node */
3345         if (seqtype < ARRAY_LENGTH(typestate->seq))
30883346         {
3089            /* only update if analog value changed */
3090            info->previousanalog = rawvalue;
3091
3092            /* apply the inverse of the sensitivity to the raw value so that */
3093            /* it will still cover the full min->max range requested after */
3094            /* we apply the sensitivity adjustment */
3095            if (info->absolute || portentry->analog.reset)
3347            /* add a new port node */
3348            xml_data_node *portnode = xml_add_child(parentnode, "port", NULL);
3349            if (portnode != NULL)
30963350            {
3097               /* if port is absolute, then just return the absolute data supplied */
3098               info->accum = APPLY_INVERSE_SENSITIVITY(rawvalue, portentry->analog.sensitivity);
3099            }
3100            else if (info->positionalscale != 0)
3101            {
3102               /* if port is positional, we will take the full analog control and divide it */
3103               /* into positions, that way as the control is moved full scale, */
3104               /* it moves through all the positions */
3105               rawvalue = APPLY_SCALE(rawvalue - INPUT_ABSOLUTE_MIN, info->positionalscale) * 512 + info->minimum;
3351               /* add the port information and attributes */
3352               xml_set_attribute(portnode, "type", input_field_type_to_token(machine, typestate->typedesc.type, typestate->typedesc.player));
31063353
3107               /* clamp the high value so it does not roll over */
3108               rawvalue = MIN(rawvalue, info->maximum);
3109               info->accum = APPLY_INVERSE_SENSITIVITY(rawvalue, portentry->analog.sensitivity);
3354               /* add only the sequences that have changed from the defaults */
3355               for (seqtype = 0; seqtype < ARRAY_LENGTH(typestate->seq); seqtype++)
3356                  if (input_seq_cmp(&typestate->seq[seqtype], &typestate->typedesc.seq[seqtype]) != 0)
3357                     save_sequence(portnode, seqtype, typestate->typedesc.type, &typestate->seq[seqtype]);
31103358            }
3111            else
3112               /* if port is relative, we use the value to simulate the speed of relative movement */
3113               /* sensitivity adjustment is allowed for this mode */
3114               info->accum += rawvalue;
3115
3116            info->lastdigital = FALSE;
3117            /* do not bother with other control types if the analog data is changing */
3118            continue;
31193359         }
3120         else
3121         {
3122            /* we still have to update fake relative from joystick control */
3123            if (!info->absolute && info->positionalscale == 0)
3124               info->accum += rawvalue;
3125         }
31263360      }
3361   }
3362}
31273363
3128      /* if we got it from a relative device, use that as the starting delta */
3129      /* also note that the last input was not a digital one */
3130      if (itemclass == ITEM_CLASS_RELATIVE && rawvalue != 0)
3131      {
3132         delta = rawvalue;
3133         info->lastdigital = 0;
3134      }
31353364
3136      keyscale = (info->accum >= 0) ? info->keyscalepos : info->keyscaleneg;
3365/*-------------------------------------------------
3366    save_game_inputs - add nodes for any game
3367    mappings that have changed
3368-------------------------------------------------*/
31373369
3138      /* if the decrement code sequence is pressed, add the key delta to */
3139      /* the accumulated delta; also note that the last input was a digital one */
3140      if (input_seq_pressed(input_port_seq(info->portentry, SEQ_TYPE_DECREMENT)))
3141      {
3142         keypressed = TRUE;
3143         if (portentry->analog.delta)
3144            delta -= APPLY_SCALE(portentry->analog.delta, keyscale);
3145         else if (info->lastdigital != 1)
3146            /* decrement only once when first pressed */
3147            delta -= APPLY_SCALE(1, keyscale);
3148         info->lastdigital = 1;
3149      }
3370static void save_game_inputs(running_machine *machine, xml_data_node *parentnode)
3371{
3372   const input_field_config *field;
3373   const input_port_config *port;
31503374
3151      /* same for the increment code sequence */
3152      if (input_seq_pressed(input_port_seq(info->portentry, SEQ_TYPE_INCREMENT)))
3153      {
3154         keypressed = TRUE;
3155         if (portentry->analog.delta)
3156            delta += APPLY_SCALE(portentry->analog.delta, keyscale);
3157         else if (info->lastdigital != 2)
3158            /* increment only once when first pressed */
3159            delta += APPLY_SCALE(1, keyscale);
3160         info->lastdigital = 2;
3161      }
3375   /* iterate over ports */
3376   for (port = machine->portconfig; port != NULL; port = port->next)
3377      for (field = port->fieldlist; field != NULL; field = field->next)
3378         if (save_this_input_field_type(field->type))
3379         {
3380            int changed = FALSE;
3381            int seqtype;
31623382
3163      /* if resetting is requested, clear the accumulated position to 0 before */
3164      /* applying the deltas so that we only return this frame's delta */
3165      /* note that centering only works for relative controls */
3166      /* no need to check if absolute here because it is checked by the validity tests */
3167      if (portentry->analog.reset)
3168         info->accum = 0;
3383            /* determine if we changed */
3384            for (seqtype = 0; seqtype < ARRAY_LENGTH(field->state->seq); seqtype++)
3385               changed |= (input_seq_cmp(&field->state->seq[seqtype], &field->seq[seqtype]) != 0);
31693386
3170      /* apply the delta to the accumulated value */
3171      info->accum += delta;
3387            /* non-analog changes */
3388            if (field->state->analog == NULL)
3389               changed |= ((field->state->value & field->mask) != (field->defvalue & field->mask));
31723390
3173      /* if our last movement was due to a digital input, and if this control */
3174      /* type autocenters, and if neither the increment nor the decrement seq */
3175      /* was pressed, apply autocentering */
3176      if (info->autocenter)
3177      {
3178         INT32 center = APPLY_INVERSE_SENSITIVITY(info->center, portentry->analog.sensitivity);
3179         if (info->lastdigital && !keypressed)
3180         {
3181            /* autocenter from positive values */
3182            if (info->accum >= center)
3391            /* analog changes */
3392            else
31833393            {
3184               info->accum -= APPLY_SCALE(portentry->analog.centerdelta, info->keyscalepos);
3185               if (info->accum < center)
3186               {
3187                  info->accum = center;
3188                  info->lastdigital = 0;
3189               }
3394               changed |= (field->state->analog->delta != field->delta);
3395               changed |= (field->state->analog->centerdelta != field->centerdelta);
3396               changed |= (field->state->analog->sensitivity != field->sensitivity);
3397               changed |= (field->state->analog->reverse != ((field->flags & ANALOG_FLAG_REVERSE) != 0));
31903398            }
31913399
3192            /* autocenter from negative values */
3193            else
3400            /* if we did change, add a new node */
3401            if (changed)
31943402            {
3195               info->accum += APPLY_SCALE(portentry->analog.centerdelta, info->keyscaleneg);
3196               if (info->accum > center)
3403               /* add a new port node */
3404               xml_data_node *portnode = xml_add_child(parentnode, "port", NULL);
3405               if (portnode != NULL)
31973406               {
3198                  info->accum = center;
3199                  info->lastdigital = 0;
3407                  /* add the identifying information and attributes */
3408                  xml_set_attribute(portnode, "tag", port->tag);
3409                  xml_set_attribute(portnode, "type", input_field_type_to_token(machine, field->type, field->player));
3410                  xml_set_attribute_int(portnode, "mask", field->mask);
3411                  xml_set_attribute_int(portnode, "defvalue", field->defvalue & field->mask);
3412
3413                  /* add sequences if changed */
3414                  for (seqtype = 0; seqtype < ARRAY_LENGTH(field->state->seq); seqtype++)
3415                     if (input_seq_cmp(&field->state->seq[seqtype], &field->seq[seqtype]) != 0)
3416                        save_sequence(portnode, seqtype, field->type, &field->state->seq[seqtype]);
3417
3418                  /* write out non-analog changes */
3419                  if (field->state->analog == NULL)
3420                  {
3421                     if ((field->state->value & field->mask) != (field->defvalue & field->mask))
3422                        xml_set_attribute_int(portnode, "value", field->state->value & field->mask);
3423                  }
3424
3425                  /* write out analog changes */
3426                  else
3427                  {
3428                     if (field->state->analog->delta != field->delta)
3429                        xml_set_attribute_int(portnode, "keydelta", field->state->analog->delta);
3430                     if (field->state->analog->centerdelta != field->centerdelta)
3431                        xml_set_attribute_int(portnode, "centerdelta", field->state->analog->centerdelta);
3432                     if (field->state->analog->sensitivity != field->sensitivity)
3433                        xml_set_attribute_int(portnode, "sensitivity", field->state->analog->sensitivity);
3434                     if (field->state->analog->reverse != ((field->flags & ANALOG_FLAG_REVERSE) != 0))
3435                        xml_set_attribute(portnode, "reverse", field->state->analog->reverse ? "yes" : "no");
3436                  }
32003437               }
32013438            }
32023439         }
3203      }
3204      else if (!keypressed)
3205         info->lastdigital = 0;
3206   }
32073440}
32083441
32093442
32103443
3211/*************************************
3212 *
3213 *  Apply analogue port settings
3214 *
3215 *************************************/
3444/***************************************************************************
3445    INPUT PLAYBACK
3446***************************************************************************/
32163447
3217INT32 apply_analogue_settings(INT32 current, analog_port_info *info)
3448/*-------------------------------------------------
3449    playback_read_uint8 - read an 8-bit value
3450    from the playback file
3451-------------------------------------------------*/
3452
3453static UINT8 playback_read_uint8(running_machine *machine)
32183454{
3219   INT32 value;
3220   input_port_entry *portentry = info->portentry;
3455   input_port_private *portdata = machine->input_port_data;
3456   UINT8 result;
32213457
3222   /* apply the min/max and then the sensitivity */
3223   current = apply_analog_min_max(info, current);
3224   current = APPLY_SENSITIVITY(current, portentry->analog.sensitivity);
3458   /* protect against NULL handles if previous reads fail */
3459   if (portdata->playback_file == NULL)
3460      return 0;
32253461
3226   /* apply reversal if needed */
3227   if (portentry->analog.reverse)
3228      current = info->reverse_val - current;
3229   else if (info->single_scale)
3230      /* it's a pedal or the default value is equal to min/max */
3231      /* so we need to adjust the center to the minimum */
3232      current -= INPUT_ABSOLUTE_MIN;
3462   /* read the value; if we fail, end playback */
3463   if (mame_fread(portdata->playback_file, &result, sizeof(result)) != sizeof(result))
3464   {
3465      playback_end(machine, "End of file");
3466      return 0;
3467   }
32333468
3234   /* map differently for positive and negative values */
3235   if (current >= 0)
3236      value = APPLY_SCALE(current, info->scalepos);
3237   else
3238      value = APPLY_SCALE(current, info->scaleneg);
3239   value += portentry->default_value;
3240
3241   return value;
3469   /* return the appropriate value */
3470   return result;
32423471}
32433472
32443473
3474/*-------------------------------------------------
3475    playback_read_uint32 - read a 32-bit value
3476    from the playback file
3477-------------------------------------------------*/
32453478
3246/*************************************
3247 *
3248 *  Analog port interpolation
3249 *
3250 *************************************/
3251
3252static UINT32 merge_interpolated_analog_data(int portnum, UINT32 digital)
3479static UINT32 playback_read_uint32(running_machine *machine)
32533480{
3254   analog_port_info *info;
3255   UINT32 result = digital;
3481   input_port_private *portdata = machine->input_port_data;
3482   UINT32 result;
32563483
3257profiler_mark(PROFILER_INPUT);
3484   /* protect against NULL handles if previous reads fail */
3485   if (portdata->playback_file == NULL)
3486      return 0;
32583487
3259   /* loop over all analog ports in this port number */
3260   for (info = port_info[portnum].analoginfo; info != NULL; info = info->next)
3488   /* read the value; if we fail, end playback */
3489   if (mame_fread(portdata->playback_file, &result, sizeof(result)) != sizeof(result))
32613490   {
3262      input_port_entry *portentry = info->portentry;
3491      playback_end(machine, "End of file");
3492      return 0;
3493   }
32633494
3264      if (input_port_condition(portentry))
3265      {
3266         INT32 current;
3267         INT32 value;
3495   /* return the appropriate value */
3496   return LITTLE_ENDIANIZE_INT32(result);
3497}
32683498
3269         /* interpolate or not */
3270         if (info->interpolate && !portentry->analog.reset && last_delta != 0)
3271         {
3272            attoseconds_t time_since_last = attotime_to_attoseconds(attotime_sub(timer_get_time(), last_update)) / ATTOSECONDS_PER_SECOND_SQRT;
3273            current = info->previous + ((INT64)(info->accum - info->previous) * time_since_last / last_delta);
3274         }
3275         else
3276            current = info->accum;
32773499
3278         value = apply_analogue_settings(current, info);
3500/*-------------------------------------------------
3501    playback_read_uint64 - read a 64-bit value
3502    from the playback file
3503-------------------------------------------------*/
32793504
3280         /* remap the value if needed */
3281         if (portentry->analog.remap_table)
3282            value = info->portentry->analog.remap_table[value];
3505static UINT64 playback_read_uint64(running_machine *machine)
3506{
3507   input_port_private *portdata = machine->input_port_data;
3508   UINT64 result;
32833509
3284         /* invert bits if needed */
3285         if (portentry->analog.invert)
3286            value = ~value;
3510   /* protect against NULL handles if previous reads fail */
3511   if (portdata->playback_file == NULL)
3512      return 0;
32873513
3288         /* insert into the port */
3289         result = (result & ~portentry->mask) | ((value << info->shift) & portentry->mask);
3290      }
3514   /* read the value; if we fail, end playback */
3515   if (mame_fread(portdata->playback_file, &result, sizeof(result)) != sizeof(result))
3516   {
3517      playback_end(machine, "End of file");
3518      return 0;
32913519   }
32923520
3293profiler_mark(PROFILER_END);
3294   return result;
3521   /* return the appropriate value */
3522   return LITTLE_ENDIANIZE_INT64(result);
32953523}
32963524
32973525
3526/*-------------------------------------------------
3527    playback_init - initialize INP playback
3528-------------------------------------------------*/
32983529
3299/*************************************
3300 *
3301 *  Input port reading
3302 *
3303 *************************************/
3304
3305UINT32 input_port_read_indexed(running_machine *machine, int portnum)
3530static time_t playback_init(running_machine *machine)
33063531{
3307   input_port_info *portinfo = &port_info[portnum];
3308   custom_port_info *custom;
3309   UINT32 result;
3532   const char *filename = options_get_string(mame_options(), OPTION_PLAYBACK);
3533   input_port_private *portdata = machine->input_port_data;
3534   UINT8 header[INP_HEADER_SIZE];
3535   file_error filerr;
3536   time_t basetime;
33103537
3311   /* start with the digital */
3312   result = portinfo->defvalue ^ portinfo->digital;
3538   /* if no file, nothing to do */
3539   if (filename[0] == 0)
3540      return 0;
33133541
3314   /* merge in analog portions */
3315   result = merge_interpolated_analog_data(portnum, result);
3542   /* open the playback file */
3543   filerr = mame_fopen(SEARCHPATH_INPUTLOG, filename, OPEN_FLAG_READ, &portdata->playback_file);
3544   assert_always(filerr == FILERR_NONE, "Failed to open file for playback");
33163545
3317   /* update custom values */
3318   for (custom = portinfo->custominfo; custom; custom = custom->next)
3319      if (input_port_condition(custom->portentry))
3320      {
3321         /* replace the bits with bits from the custom routine */
3322         input_port_entry *portentry = custom->portentry;
3323         result &= ~portentry->mask;
3324         result |= ((*portentry->custom)(machine, portentry->custom_param) << custom->shift) & portentry->mask;
3325      }
3546   /* read the header and verify that it is a modern version; if not, print an error */
3547   if (mame_fread(portdata->playback_file, header, sizeof(header)) != sizeof(header))
3548      fatalerror("Input file is corrupt or invalid (missing header)");
3549   if (memcmp(header, "MAMEINP\0", 8) != 0)
3550      fatalerror("Input file invalid or in an older, unsupported format");
3551   if (header[0x10] != INP_HEADER_MAJVERSION)
3552      fatalerror("Input file format version mismatch");
33263553
3327   /* handle VBLANK bits */
3328   if (portinfo->vblank)
3329   {
3330      /* reset the VBLANK bits to their default value, regardless of inputs */
3331      result = (result & ~portinfo->vblank) | (portinfo->defvalue & portinfo->vblank);
3554   /* output info to console */
3555   mame_printf_info("Input file: %s\n", filename);
3556   mame_printf_info("INP version %d.%d\n", header[0x10], header[0x11]);
3557   basetime = header[0x08] | (header[0x09] << 8) | (header[0x0a] << 16) | (header[0x0b] << 24) |
3558            ((UINT64)header[0x0c] << 32) | ((UINT64)header[0x0d] << 40) | ((UINT64)header[0x0e] << 48) | ((UINT64)header[0x0f] << 56);
3559   mame_printf_info("Created %s", ctime(&basetime));
3560   mame_printf_info("Recorded using %s\n", header + 0x20);
33323561
3333      /* toggle VBLANK if we're in a VBLANK state */
3334      if (video_screen_get_vblank(machine->primary_screen))
3335         result ^= portinfo->vblank;
3336   }
3337   return result;
3562   /* verify the header against the current game */
3563   if (memcmp(machine->gamedrv->name, header + 0x14, strlen(machine->gamedrv->name) + 1) != 0)
3564      fatalerror("Input file is for " GAMENOUN " '%s', not for current " GAMENOUN " '%s'\n", header + 0x14, machine->gamedrv->name);
3565
3566   return basetime;
33383567}
33393568
33403569
3341UINT32 input_port_read(running_machine *machine, const char *tag)
3570/*-------------------------------------------------
3571    playback_end - end INP playback
3572-------------------------------------------------*/
3573
3574static void playback_end(running_machine *machine, const char *message)
33423575{
3343   int portnum = port_tag_to_index(tag);
3344   if (portnum != -1)
3345      return input_port_read_indexed(machine, portnum);
3576   input_port_private *portdata = machine->input_port_data;
33463577
3347   /* otherwise fail horribly */
3348   fatalerror("Unable to locate input port '%s'", tag);
3349   return -1;
3350}
3578   /* only applies if we have a live file */
3579   if (portdata->playback_file != NULL)
3580   {
3581      /* close the file */
3582      mame_fclose(portdata->playback_file);
3583      portdata->playback_file = NULL;
33513584
3585      /* pop a message */
3586      if (message != NULL)
3587         popmessage("Playback Ended\nReason: %s", message);
33523588
3353UINT32 input_port_read_safe(running_machine *machine, const char *tag, UINT32 defvalue)
3354{
3355   int portnum = port_tag_to_index(tag);
3356   if (portnum != -1)
3357      return input_port_read_indexed(machine, portnum);
3358   return defvalue;
3589      /* display speed stats */
3590      portdata->playback_accumulated_speed /= portdata->playback_accumulated_frames;
3591      mame_printf_info("Total playback frames: %d\n", (UINT32)portdata->playback_accumulated_frames);
3592      mame_printf_info("Average recorded speed: %d%%\n", (UINT32)((portdata->playback_accumulated_speed * 200 + 1) >> 21));
3593   }
33593594}
33603595
33613596
3597/*-------------------------------------------------
3598    playback_frame - start of frame callback for
3599    playback
3600-------------------------------------------------*/
33623601
3363/*************************************
3364 *
3365 *  Return position of crosshair axis
3366 *
3367 *************************************/
3368
3369UINT32 get_crosshair_pos(int port_num, UINT8 player, UINT8 axis)
3602static void playback_frame(running_machine *machine, attotime curtime)
33703603{
3371   input_port_info *portinfo = &port_info[port_num];
3372   analog_port_info *info;
3373   input_port_entry *portentry;
3374   UINT32 result = 0;
3604   input_port_private *portdata = machine->input_port_data;
33753605
3376   for (info = portinfo->analoginfo; info; info = info->next)
3606   /* if playing back, fetch the information and verify */
3607   if (portdata->playback_file != NULL)
33773608   {
3378      portentry = info->portentry;
3379      if (portentry->player == player && portentry->analog.crossaxis == axis && input_port_condition(portentry))
3380      {
3381         result = apply_analogue_settings(info->accum, info) & (portentry->mask >> info->shift);
3382         break;
3383      }
3609      attotime readtime;
3610
3611      /* first the absolute time */
3612      readtime.seconds = playback_read_uint32(machine);
3613      readtime.attoseconds = playback_read_uint64(machine);
3614      if (attotime_compare(readtime, curtime) != 0)
3615         playback_end(machine, "Out of sync");
3616
3617      /* then the speed */
3618      portdata->playback_accumulated_speed += playback_read_uint32(machine);
3619      portdata->playback_accumulated_frames++;
33843620   }
3385
3386   return result;
33873621}
33883622
33893623
33903624/*-------------------------------------------------
3391    autoselect_device - autoselect a single
3392    device based on the input port list passed
3393    in and the corresponding option
3625    playback_port - per-port callback for playback
33943626-------------------------------------------------*/
33953627
3396static void autoselect_device(const input_port_entry *ipt, int type1, int type2, int type3, const char *option, const char *ananame)
3628static void playback_port(const input_port_config *port)
33973629{
3398   const char *stemp = options_get_string(mame_options(), option);
3399   input_device_class autoenable = DEVICE_CLASS_KEYBOARD;
3400   const char *autostring = "keyboard";
3630   input_port_private *portdata = port->machine->input_port_data;
34013631
3402   /* if nothing specified, ignore the option */
3403   if (stemp[0] == 0)
3404      return;
3405
3406   /* extract valid strings */
3407   if (strcmp(stemp, "mouse") == 0)
3632   /* if playing back, fetch information about this port */
3633   if (portdata->playback_file != NULL)
34083634   {
3409      autoenable = DEVICE_CLASS_MOUSE;
3410      autostring = "mouse";
3411   }
3412   else if (strcmp(stemp, "joystick") == 0)
3413   {
3414      autoenable = DEVICE_CLASS_JOYSTICK;
3415      autostring = "joystick";
3416   }
3417   else if (strcmp(stemp, "lightgun") == 0)
3418   {
3419      autoenable = DEVICE_CLASS_LIGHTGUN;
3420      autostring = "lightgun";
3421   }
3422   else if (strcmp(stemp, "none") == 0)
3423   {
3424      /* nothing specified */
3425      return;
3426   }
3427   else if (strcmp(stemp, "keyboard") != 0)
3428      mame_printf_error("Invalid %s value %s; reverting to keyboard\n", option, stemp);
3635      analog_field_state *analog;
34293636
3430   /* only scan the list if we haven't already enabled this class of control */
3431   if (!input_device_class_enabled(autoenable))
3432      for ( ; ipt->type != IPT_END; ipt++)
3637      /* read the digital value */
3638      port->state->digital = playback_read_uint32(port->machine);
34333639
3434         /* if this port type is in use, apply the autoselect criteria */
3435         if ((type1 != 0 && ipt->type == type1) ||
3436            (type2 != 0 && ipt->type == type2) ||
3437            (type3 != 0 && ipt->type == type3))
3438         {
3439            mame_printf_verbose("Input: Autoenabling %s due to presence of a %s\n", autostring, ananame);
3440            input_device_class_enable(autoenable, TRUE);
3441            break;
3442         }
3640      /* loop over analog ports and save their data */
3641      for (analog = port->state->analoglist; analog != NULL; analog = analog->next)
3642      {
3643         /* read current and previous values */
3644         analog->accum = playback_read_uint32(port->machine);
3645         analog->previous = playback_read_uint32(port->machine);
3646
3647         /* read configuration information */
3648         analog->sensitivity = playback_read_uint32(port->machine);
3649         analog->reverse = playback_read_uint8(port->machine);
3650      }
3651   }
34433652}
34443653
34453654
34463655
34473656/***************************************************************************
3448    PLAYBACK AND RECORD
3657    INPUT RECORDING
34493658***************************************************************************/
34503659
34513660/*-------------------------------------------------
3452    playback_read_uint8 - read an 8-bit value
3453    from the playback file
3454-------------------------------------------------*/
3455
3456static UINT8 playback_read_uint8(running_machine *machine)
3457{
3458   UINT8 result;
3459
3460   /* protect against NULL handles if previous reads fail */
3461   if (machine->playback_file == NULL)
3462      return 0;
3463
3464   /* read the value; if we fail, end playback */
3465   if (mame_fread(machine->playback_file, &result, sizeof(result)) != sizeof(result))
3466   {
3467      playback_end(machine, "End of file");
3468      return 0;
3469   }
3470
3471   /* return the appropriate value */
3472   return result;
3473}
3474
3475
3476/*-------------------------------------------------
34773661    record_write_uint8 - write an 8-bit value
34783662    to the record file
34793663-------------------------------------------------*/
34803664
34813665static void record_write_uint8(running_machine *machine, UINT8 data)
34823666{
3667   input_port_private *portdata = machine->input_port_data;
34833668   UINT8 result = data;
34843669
34853670   /* protect against NULL handles if previous reads fail */
3486   if (machine->record_file == NULL)
3671   if (portdata->record_file == NULL)
34873672      return;
34883673
34893674   /* read the value; if we fail, end playback */
3490   if (mame_fwrite(machine->record_file, &result, sizeof(result)) != sizeof(result))
3675   if (mame_fwrite(portdata->record_file, &result, sizeof(result)) != sizeof(result))
34913676      record_end(machine, "Out of space");
34923677}
34933678
34943679
34953680/*-------------------------------------------------
3496    playback_read_uint32 - read a 32-bit value
3497    from the playback file
3498-------------------------------------------------*/
3499
3500static UINT32 playback_read_uint32(running_machine *machine)
3501{
3502   UINT32 result;
3503
3504   /* protect against NULL handles if previous reads fail */
3505   if (machine->playback_file == NULL)
3506      return 0;
3507
3508   /* read the value; if we fail, end playback */
3509   if (mame_fread(machine->playback_file, &result, sizeof(result)) != sizeof(result))
3510   {
3511      playback_end(machine, "End of file");
3512      return 0;
3513   }
3514
3515   /* return the appropriate value */
3516   return LITTLE_ENDIANIZE_INT32(result);
3517}
3518
3519
3520/*-------------------------------------------------
35213681    record_write_uint32 - write a 32-bit value
35223682    to the record file
35233683-------------------------------------------------*/
35243684
35253685static void record_write_uint32(running_machine *machine, UINT32 data)
35263686{
3687   input_port_private *portdata = machine->input_port_data;
35273688   UINT32 result = LITTLE_ENDIANIZE_INT32(data);
35283689
35293690   /* protect against NULL handles if previous reads fail */
3530   if (machine->record_file == NULL)
3691   if (portdata->record_file == NULL)
35313692      return;
35323693
35333694   /* read the value; if we fail, end playback */
3534   if (mame_fwrite(machine->record_file, &result, sizeof(result)) != sizeof(result))
3695   if (mame_fwrite(portdata->record_file, &result, sizeof(result)) != sizeof(result))
35353696      record_end(machine, "Out of space");
35363697}
35373698
35383699
35393700/*-------------------------------------------------
3540    playback_read_uint64 - read a 64-bit value
3541    from the playback file
3542-------------------------------------------------*/
3543
3544static UINT64 playback_read_uint64(running_machine *machine)
3545{
3546   UINT64 result;
3547
3548   /* protect against NULL handles if previous reads fail */
3549   if (machine->playback_file == NULL)
3550      return 0;
3551
3552   /* read the value; if we fail, end playback */
3553   if (mame_fread(machine->playback_file, &result, sizeof(result)) != sizeof(result))
3554   {
3555      playback_end(machine, "End of file");
3556      return 0;
3557   }
3558
3559   /* return the appropriate value */
3560   return LITTLE_ENDIANIZE_INT64(result);
3561}
3562
3563
3564/*-------------------------------------------------
35653701    record_write_uint64 - write a 64-bit value
35663702    to the record file
35673703-------------------------------------------------*/
35683704
35693705static void record_write_uint64(running_machine *machine, UINT64 data)
35703706{
3707   input_port_private *portdata = machine->input_port_data;
35713708   UINT64 result = LITTLE_ENDIANIZE_INT64(data);
35723709
35733710   /* protect against NULL handles if previous reads fail */
3574   if (machine->record_file == NULL)
3711   if (portdata->record_file == NULL)
35753712      return;
35763713
35773714   /* read the value; if we fail, end playback */
3578   if (mame_fwrite(machine->record_file, &result, sizeof(result)) != sizeof(result))
3715   if (mame_fwrite(portdata->record_file, &result, sizeof(result)) != sizeof(result))
35793716      record_end(machine, "Out of space");
35803717}
35813718
35823719
35833720/*-------------------------------------------------
3584    playback_init - initialize INP playback
3585-------------------------------------------------*/
3586
3587static time_t playback_init(running_machine *machine)
3588{
3589   const char *filename = options_get_string(mame_options(), OPTION_PLAYBACK);
3590   UINT8 header[INP_HEADER_SIZE];
3591   file_error filerr;
3592   time_t basetime;
3593
3594   /* if no file, nothing to do */
3595   if (filename[0] == 0)
3596      return 0;
3597
3598   /* open the playback file */
3599   filerr = mame_fopen(SEARCHPATH_INPUTLOG, filename, OPEN_FLAG_READ, &machine->playback_file);
3600   assert_always(filerr == FILERR_NONE, "Failed to open file for playback");
3601
3602   /* read the header and verify that it is a modern version; if not, print an error */
3603   if (mame_fread(machine->playback_file, header, sizeof(header)) != sizeof(header))
3604      fatalerror("Input file is corrupt or invalid (missing header)");
3605   if (memcmp(header, "MAMEINP\0", 8) != 0)
3606      fatalerror("Input file invalid or in an older, unsupported format");
3607   if (header[0x10] != INP_HEADER_MAJVERSION)
3608      fatalerror("Input file format version mismatch");
3609
3610   /* output info to console */
3611   mame_printf_info("Input file: %s\n", filename);
3612   mame_printf_info("INP version %d.%d\n", header[0x10], header[0x11]);
3613   basetime = header[0x08] | (header[0x09] << 8) | (header[0x0a] << 16) | (header[0x0b] << 24) |
3614            ((UINT64)header[0x0c] << 32) | ((UINT64)header[0x0d] << 40) | ((UINT64)header[0x0e] << 48) | ((UINT64)header[0x0f] << 56);
3615   mame_printf_info("Created %s", ctime(&basetime));
3616   mame_printf_info("Recorded using %s\n", header + 0x20);
3617
3618   /* verify the header against the current game */
3619   if (memcmp(machine->gamedrv->name, header + 0x14, strlen(machine->gamedrv->name) + 1) != 0)
3620      fatalerror("Input file is for " GAMENOUN " '%s', not for current " GAMENOUN " '%s'\n", header + 0x14, machine->gamedrv->name);
3621
3622   return basetime;
3623}
3624
3625
3626/*-------------------------------------------------
36273721    record_init - initialize INP recording
36283722-------------------------------------------------*/
36293723
36303724static void record_init(running_machine *machine)
36313725{
36323726   const char *filename = options_get_string(mame_options(), OPTION_RECORD);
3727   input_port_private *portdata = machine->input_port_data;
36333728   UINT8 header[INP_HEADER_SIZE];
36343729   mame_system_time systime;
36353730   file_error filerr;
r2724r2725
36393734      return;
36403735
36413736   /* open the record file  */
3642   filerr = mame_fopen(SEARCHPATH_INPUTLOG, filename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &machine->record_file);
3737   filerr = mame_fopen(SEARCHPATH_INPUTLOG, filename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &portdata->record_file);
36433738   assert_always(filerr == FILERR_NONE, "Failed to open file for recording");
36443739
36453740   /* get the base time */
r2724r2725
36623757   sprintf((char *)header + 0x20, APPNAME " %s", build_version);
36633758
36643759   /* write it */
3665   mame_fwrite(machine->record_file, header, sizeof(header));
3760   mame_fwrite(portdata->record_file, header, sizeof(header));
36663761}
36673762
36683763
36693764/*-------------------------------------------------
3670    playback_end - end INP playback
3671-------------------------------------------------*/
3672
3673static void playback_end(running_machine *machine, const char *message)
3674{
3675   /* only applies if we have a live file */
3676   if (machine->playback_file != NULL)
3677   {
3678      /* close the file */
3679      mame_fclose(machine->playback_file);
3680      machine->playback_file = NULL;
3681
3682      /* pop a message */
3683      if (message != NULL)
3684         popmessage("Playback Ended\nReason: %s", message);
3685
3686      /* display speed stats */
3687      playback_accumulated_speed /= playback_accumulated_frames;
3688      mame_printf_info("Total playback frames: %d\n", (UINT32)playback_accumulated_frames);
3689      mame_printf_info("Average recorded speed: %d%%\n", (UINT32)((playback_accumulated_speed * 200 + 1) >> 21));
3690   }
3691}
3692
3693
3694/*-------------------------------------------------
36953765    record_end - end INP recording
36963766-------------------------------------------------*/
36973767
36983768static void record_end(running_machine *machine, const char *message)
36993769{
3770   input_port_private *portdata = machine->input_port_data;
3771
37003772   /* only applies if we have a live file */
3701   if (machine->record_file != NULL)
3773   if (portdata->record_file != NULL)
37023774   {
37033775      /* close the file */
3704      mame_fclose(machine->record_file);
3705      machine->record_file = NULL;
3776      mame_fclose(portdata->record_file);
3777      portdata->record_file = NULL;
37063778
37073779      /* pop a message */
37083780      if (message != NULL)
r2724r2725
37123784
37133785
37143786/*-------------------------------------------------
3715    playback_frame - start of frame callback for
3716    playback
3717-------------------------------------------------*/
3718
3719static void playback_frame(running_machine *machine, attotime curtime)
3720{
3721   /* if playing back, fetch the information and verify */
3722   if (machine->playback_file != NULL)
3723   {
3724      attotime readtime;
3725
3726      /* first the absolute time */
3727      readtime.seconds = playback_read_uint32(machine);
3728      readtime.attoseconds = playback_read_uint64(machine);
3729      if (attotime_compare(readtime, curtime) != 0)
3730         playback_end(machine, "Out of sync");
3731
3732      /* then the speed */
3733      playback_accumulated_speed += playback_read_uint32(machine);
3734      playback_accumulated_frames++;
3735   }
3736}
3737
3738
3739/*-------------------------------------------------
37403787    record_frame - start of frame callback for
37413788    recording
37423789-------------------------------------------------*/
37433790
37443791static void record_frame(running_machine *machine, attotime curtime)
37453792{
3793   input_port_private *portdata = machine->input_port_data;
3794
37463795   /* if recording, record information about the current frame */
3747   if (machine->record_file != NULL)
3796   if (portdata->record_file != NULL)
37483797   {
37493798      /* first the absolute time */
37503799      record_write_uint32(machine, curtime.seconds);
r2724r2725
37573806
37583807
37593808/*-------------------------------------------------
3760    playback_port - per-port callback for playback
3809    record_port - per-port callback for record
37613810-------------------------------------------------*/
37623811
3763static void playback_port(running_machine *machine, input_port_info *portinfo)
3812static void record_port(const input_port_config *port)
37643813{
3765   /* if playing back, fetch information about this port */
3766   if (machine->playback_file != NULL)
3767   {
3768      analog_port_info *analog;
3814   input_port_private *portdata = port->machine->input_port_data;
37693815
3770      /* read the digital value */
3771      portinfo->digital = playback_read_uint32(machine);
3772
3773      /* loop over analog ports and save their data */
3774      for (analog = portinfo->analoginfo; analog != NULL; analog = analog->next)
3775      {
3776         /* read current and previous values */
3777         analog->accum = playback_read_uint32(machine);
3778         analog->previous = playback_read_uint32(machine);
3779
3780         /* read configuration information */
3781         analog->portentry->analog.sensitivity = playback_read_uint32(machine);
3782         analog->portentry->analog.reverse = playback_read_uint8(machine);
3783      }
3784   }
3785}
3786
3787
3788/*-------------------------------------------------
3789    record_port - per-port callback for record
3790-------------------------------------------------*/
3791
3792static void record_port(running_machine *machine, input_port_info *portinfo)
3793{
37943816   /* if recording, store information about this port */
3795   if (machine->record_file != NULL)
3817   if (portdata->record_file != NULL)
37963818   {
3797      analog_port_info *analog;
3819      analog_field_state *analog;
37983820
37993821      /* store the digital value */
3800      record_write_uint32(machine, portinfo->digital);
3822      record_write_uint32(port->machine, port->state->digital);
38013823
38023824      /* loop over analog ports and save their data */
3803      for (analog = portinfo->analoginfo; analog != NULL; analog = analog->next)
3825      for (analog = port->state->analoglist; analog != NULL; analog = analog->next)
38043826      {
38053827         /* store current and previous values */
3806         record_write_uint32(machine, analog->accum);
3807         record_write_uint32(machine, analog->previous);
3828         record_write_uint32(port->machine, analog->accum);
3829         record_write_uint32(port->machine, analog->previous);
38083830
38093831         /* store configuration information */
3810         record_write_uint32(machine, analog->portentry->analog.sensitivity);
3811         record_write_uint8(machine, analog->portentry->analog.reverse);
3832         record_write_uint32(port->machine, analog->sensitivity);
3833         record_write_uint8(port->machine, analog->reverse);
38123834      }
38133835   }
38143836}
src/emu/inpttype.h
r0r2725
1/***************************************************************************
2
3    inpttype.h
4
5    Array of core-defined input types and default mappings.
6
7    Copyright Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
10***************************************************************************/
11
12
13/***************************************************************************
14    BUILT-IN CORE MAPPINGS
15***************************************************************************/
16
17#define INPUT_PORT_DIGITAL_TYPE(_player,_group,_type,_name,_seq) \
18   { NULL, IPT_##_type, IPG_##_group, (_player == 0) ? _player : (_player) - 1, (_player == 0) ? #_type : ("P" #_player "_" #_type), _name, { _seq, SEQ_DEF_0, SEQ_DEF_0 } },
19
20#define INPUT_PORT_ANALOG_TYPE(_player,_group,_type,_name,_seq,_decseq,_incseq) \
21   { NULL, IPT_##_type, IPG_##_group, (_player == 0) ? _player : (_player) - 1, (_player == 0) ? #_type : ("P" #_player "_" #_type), _name, { _seq, _incseq, _decseq } },
22
23#define INDEXED(a,b)   INPUT_CODE_SET_DEVINDEX(a,b)
24
25static const input_type_desc core_types[] =
26{
27   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, JOYSTICK_UP,         "P1 Up",                  SEQ_DEF_3(KEYCODE_UP, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)) )
28   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, JOYSTICK_DOWN,       "P1 Down",                SEQ_DEF_3(KEYCODE_DOWN, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
29   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, JOYSTICK_LEFT,       "P1 Left",                SEQ_DEF_3(KEYCODE_LEFT, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)) )
30   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, JOYSTICK_RIGHT,      "P1 Right",               SEQ_DEF_3(KEYCODE_RIGHT, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
31   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, JOYSTICKRIGHT_UP,    "P1 Right/Up",            SEQ_DEF_3(KEYCODE_I, SEQCODE_OR, INDEXED(JOYCODE_BUTTON2, 0)) )
32   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, JOYSTICKRIGHT_DOWN,  "P1 Right/Down",          SEQ_DEF_3(KEYCODE_K, SEQCODE_OR, INDEXED(JOYCODE_BUTTON3, 0)) )
33   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, JOYSTICKRIGHT_LEFT,  "P1 Right/Left",          SEQ_DEF_3(KEYCODE_J, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 0)) )
34   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, JOYSTICKRIGHT_RIGHT, "P1 Right/Right",         SEQ_DEF_3(KEYCODE_L, SEQCODE_OR, INDEXED(JOYCODE_BUTTON4, 0)) )
35   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, JOYSTICKLEFT_UP,     "P1 Left/Up",             SEQ_DEF_3(KEYCODE_E, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)) )
36   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, JOYSTICKLEFT_DOWN,   "P1 Left/Down",           SEQ_DEF_3(KEYCODE_D, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
37   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, JOYSTICKLEFT_LEFT,   "P1 Left/Left",           SEQ_DEF_3(KEYCODE_S, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)) )
38   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, JOYSTICKLEFT_RIGHT,  "P1 Left/Right",          SEQ_DEF_3(KEYCODE_F, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
39   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, BUTTON1,             "P1 Button 1",            SEQ_DEF_7(KEYCODE_LCONTROL, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 0), SEQCODE_OR, INDEXED(MOUSECODE_BUTTON1, 0), SEQCODE_OR, INDEXED(GUNCODE_BUTTON1, 0)) )
40   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, BUTTON2,             "P1 Button 2",            SEQ_DEF_7(KEYCODE_LALT, SEQCODE_OR, INDEXED(JOYCODE_BUTTON2, 0), SEQCODE_OR, INDEXED(MOUSECODE_BUTTON3, 0), SEQCODE_OR, INDEXED(GUNCODE_BUTTON2, 0)) )
41   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, BUTTON3,             "P1 Button 3",            SEQ_DEF_5(KEYCODE_SPACE, SEQCODE_OR, INDEXED(JOYCODE_BUTTON3, 0), SEQCODE_OR, INDEXED(MOUSECODE_BUTTON2, 0)) )
42   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, BUTTON4,             "P1 Button 4",            SEQ_DEF_3(KEYCODE_LSHIFT, SEQCODE_OR, INDEXED(JOYCODE_BUTTON4, 0)) )
43   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, BUTTON5,             "P1 Button 5",            SEQ_DEF_3(KEYCODE_Z, SEQCODE_OR, INDEXED(JOYCODE_BUTTON5, 0)) )
44   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, BUTTON6,             "P1 Button 6",            SEQ_DEF_3(KEYCODE_X, SEQCODE_OR, INDEXED(JOYCODE_BUTTON6, 0)) )
45   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, BUTTON7,             "P1 Button 7",            SEQ_DEF_3(KEYCODE_C, SEQCODE_OR, INDEXED(JOYCODE_BUTTON7, 0)) )
46   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, BUTTON8,             "P1 Button 8",            SEQ_DEF_3(KEYCODE_V, SEQCODE_OR, INDEXED(JOYCODE_BUTTON8, 0)) )
47   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, BUTTON9,             "P1 Button 9",            SEQ_DEF_3(KEYCODE_B, SEQCODE_OR, INDEXED(JOYCODE_BUTTON9, 0)) )
48   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, BUTTON10,            "P1 Button 10",           SEQ_DEF_3(KEYCODE_N, SEQCODE_OR, INDEXED(JOYCODE_BUTTON10, 0)) )
49   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, BUTTON11,            "P1 Button 11",           SEQ_DEF_3(KEYCODE_M, SEQCODE_OR, INDEXED(JOYCODE_BUTTON11, 0)) )
50   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, BUTTON12,            "P1 Button 12",           SEQ_DEF_3(KEYCODE_COMMA, SEQCODE_OR, INDEXED(JOYCODE_BUTTON12, 0)) )
51   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, BUTTON13,            "P1 Button 13",           SEQ_DEF_3(KEYCODE_STOP, SEQCODE_OR, INDEXED(JOYCODE_BUTTON13, 0)) )
52   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, BUTTON14,            "P1 Button 14",           SEQ_DEF_3(KEYCODE_SLASH, SEQCODE_OR, INDEXED(JOYCODE_BUTTON14, 0)) )
53   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, BUTTON15,            "P1 Button 15",           SEQ_DEF_3(KEYCODE_RSHIFT, SEQCODE_OR, INDEXED(JOYCODE_BUTTON15, 0)) )
54   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, BUTTON16,            "P1 Button 16",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON16, 0)) )
55   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, START,               "P1 Start",               SEQ_DEF_3(KEYCODE_1, SEQCODE_OR, INDEXED(JOYCODE_START, 0)) )
56   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, SELECT,              "P1 Select",              SEQ_DEF_3(KEYCODE_5, SEQCODE_OR, INDEXED(JOYCODE_SELECT, 0)) )
57   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_A,           "P1 Mahjong A",           SEQ_DEF_1(KEYCODE_A) )
58   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_B,           "P1 Mahjong B",           SEQ_DEF_1(KEYCODE_B) )
59   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_C,           "P1 Mahjong C",           SEQ_DEF_1(KEYCODE_C) )
60   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_D,           "P1 Mahjong D",           SEQ_DEF_1(KEYCODE_D) )
61   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_E,           "P1 Mahjong E",           SEQ_DEF_1(KEYCODE_E) )
62   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_F,           "P1 Mahjong F",           SEQ_DEF_1(KEYCODE_F) )
63   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_G,           "P1 Mahjong G",           SEQ_DEF_1(KEYCODE_G) )
64   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_H,           "P1 Mahjong H",           SEQ_DEF_1(KEYCODE_H) )
65   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_I,           "P1 Mahjong I",           SEQ_DEF_1(KEYCODE_I) )
66   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_J,           "P1 Mahjong J",           SEQ_DEF_1(KEYCODE_J) )
67   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_K,           "P1 Mahjong K",           SEQ_DEF_1(KEYCODE_K) )
68   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_L,           "P1 Mahjong L",           SEQ_DEF_1(KEYCODE_L) )
69   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_M,           "P1 Mahjong M",           SEQ_DEF_1(KEYCODE_M) )
70   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_N,           "P1 Mahjong N",           SEQ_DEF_1(KEYCODE_N) )
71   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_O,           "P1 Mahjong O",           SEQ_DEF_1(KEYCODE_O) )
72   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_P,           "P1 Mahjong P",           SEQ_DEF_1(KEYCODE_COLON) )
73   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_Q,           "P1 Mahjong Q",           SEQ_DEF_1(KEYCODE_Q) )
74   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_KAN,         "P1 Mahjong Kan",         SEQ_DEF_1(KEYCODE_LCONTROL) )
75   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_PON,         "P1 Mahjong Pon",         SEQ_DEF_1(KEYCODE_LALT) )
76   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_CHI,         "P1 Mahjong Chi",         SEQ_DEF_1(KEYCODE_SPACE) )
77   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_REACH,       "P1 Mahjong Reach",       SEQ_DEF_1(KEYCODE_LSHIFT) )
78   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_RON,         "P1 Mahjong Ron",         SEQ_DEF_1(KEYCODE_Z) )
79   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_BET,         "P1 Mahjong Bet",         SEQ_DEF_1(KEYCODE_2) )
80   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_LAST_CHANCE, "P1 Mahjong Last Chance", SEQ_DEF_1(KEYCODE_RALT) )
81   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_SCORE,       "P1 Mahjong Score",       SEQ_DEF_1(KEYCODE_RCONTROL) )
82   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_DOUBLE_UP,   "P1 Mahjong Double Up",   SEQ_DEF_1(KEYCODE_RSHIFT) )
83   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_FLIP_FLOP,   "P1 Mahjong Flip Flop",   SEQ_DEF_1(KEYCODE_Y) )
84   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_BIG,         "P1 Mahjong Big",         SEQ_DEF_1(KEYCODE_ENTER) )
85   INPUT_PORT_DIGITAL_TYPE( 1, PLAYER1, MAHJONG_SMALL,       "P1 Mahjong Small",       SEQ_DEF_1(KEYCODE_BACKSPACE) )
86
87   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, JOYSTICK_UP,         "P2 Up",                  SEQ_DEF_3(KEYCODE_R, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 1)) )
88   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, JOYSTICK_DOWN,       "P2 Down",                SEQ_DEF_3(KEYCODE_F, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 1)) )
89   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, JOYSTICK_LEFT,       "P2 Left",                SEQ_DEF_3(KEYCODE_D, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 1)) )
90   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, JOYSTICK_RIGHT,      "P2 Right",               SEQ_DEF_3(KEYCODE_G, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 1)) )
91   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, JOYSTICKRIGHT_UP,    "P2 Right/Up",            SEQ_DEF_0 )
92   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, JOYSTICKRIGHT_DOWN,  "P2 Right/Down",          SEQ_DEF_0 )
93   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, JOYSTICKRIGHT_LEFT,  "P2 Right/Left",          SEQ_DEF_0 )
94   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, JOYSTICKRIGHT_RIGHT, "P2 Right/Right",         SEQ_DEF_0 )
95   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, JOYSTICKLEFT_UP,     "P2 Left/Up",             SEQ_DEF_0 )
96   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, JOYSTICKLEFT_DOWN,   "P2 Left/Down",           SEQ_DEF_0 )
97   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, JOYSTICKLEFT_LEFT,   "P2 Left/Left",           SEQ_DEF_0 )
98   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, JOYSTICKLEFT_RIGHT,  "P2 Left/Right",          SEQ_DEF_0 )
99   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, BUTTON1,             "P2 Button 1",            SEQ_DEF_7(KEYCODE_A, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 1), SEQCODE_OR, INDEXED(MOUSECODE_BUTTON1, 1), SEQCODE_OR, INDEXED(GUNCODE_BUTTON1, 1)) )
100   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, BUTTON2,             "P2 Button 2",            SEQ_DEF_7(KEYCODE_S, SEQCODE_OR, INDEXED(JOYCODE_BUTTON2, 1), SEQCODE_OR, INDEXED(MOUSECODE_BUTTON3, 1), SEQCODE_OR, INDEXED(GUNCODE_BUTTON2, 1)) )
101   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, BUTTON3,             "P2 Button 3",            SEQ_DEF_5(KEYCODE_Q, SEQCODE_OR, INDEXED(JOYCODE_BUTTON3, 1), SEQCODE_OR, INDEXED(MOUSECODE_BUTTON2, 1)) )
102   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, BUTTON4,             "P2 Button 4",            SEQ_DEF_3(KEYCODE_W, SEQCODE_OR, INDEXED(JOYCODE_BUTTON4, 1)) )
103   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, BUTTON5,             "P2 Button 5",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON5, 1)) )
104   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, BUTTON6,             "P2 Button 6",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON6, 1)) )
105   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, BUTTON7,             "P2 Button 7",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON7, 1)) )
106   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, BUTTON8,             "P2 Button 8",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON8, 1)) )
107   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, BUTTON9,             "P2 Button 9",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON9, 1)) )
108   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, BUTTON10,            "P2 Button 10",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON10, 1)) )
109   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, BUTTON11,            "P2 Button 11",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON11, 1)) )
110   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, BUTTON12,            "P2 Button 12",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON12, 1)) )
111   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, BUTTON13,            "P2 Button 13",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON13, 1)) )
112   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, BUTTON14,            "P2 Button 14",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON14, 1)) )
113   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, BUTTON15,            "P2 Button 15",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON15, 1)) )
114   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, BUTTON16,            "P2 Button 16",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON16, 1)) )
115   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, START,               "P2 Start",               SEQ_DEF_3(KEYCODE_2, SEQCODE_OR, INDEXED(JOYCODE_START, 1)) )
116   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, SELECT,              "P2 Select",              SEQ_DEF_3(KEYCODE_6, SEQCODE_OR, INDEXED(JOYCODE_SELECT, 1)) )
117   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_A,           "P2 Mahjong A",           SEQ_DEF_0 )
118   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_B,           "P2 Mahjong B",           SEQ_DEF_0 )
119   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_C,           "P2 Mahjong C",           SEQ_DEF_0 )
120   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_D,           "P2 Mahjong D",           SEQ_DEF_0 )
121   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_E,           "P2 Mahjong E",           SEQ_DEF_0 )
122   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_F,           "P2 Mahjong F",           SEQ_DEF_0 )
123   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_G,           "P2 Mahjong G",           SEQ_DEF_0 )
124   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_H,           "P2 Mahjong H",           SEQ_DEF_0 )
125   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_I,           "P2 Mahjong I",           SEQ_DEF_0 )
126   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_J,           "P2 Mahjong J",           SEQ_DEF_0 )
127   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_K,           "P2 Mahjong K",           SEQ_DEF_0 )
128   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_L,           "P2 Mahjong L",           SEQ_DEF_0 )
129   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_M,           "P2 Mahjong M",           SEQ_DEF_0 )
130   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_N,           "P2 Mahjong N",           SEQ_DEF_0 )
131   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_O,           "P2 Mahjong O",           SEQ_DEF_0 )
132   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_P,           "P2 Mahjong P",           SEQ_DEF_0 )
133   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_Q,           "P2 Mahjong Q",           SEQ_DEF_0 )
134   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_KAN,         "P2 Mahjong Kan",         SEQ_DEF_0 )
135   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_PON,         "P2 Mahjong Pon",         SEQ_DEF_0 )
136   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_CHI,         "P2 Mahjong Chi",         SEQ_DEF_0 )
137   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_REACH,       "P2 Mahjong Reach",       SEQ_DEF_0 )
138   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_RON,         "P2 Mahjong Ron",         SEQ_DEF_0 )
139   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_BET,         "P2 Mahjong Bet",         SEQ_DEF_0 )
140   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_LAST_CHANCE, "P2 Mahjong Last Chance", SEQ_DEF_0 )
141   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_SCORE,       "P2 Mahjong Score",       SEQ_DEF_0 )
142   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_DOUBLE_UP,   "P2 Mahjong Double Up",   SEQ_DEF_0 )
143   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_FLIP_FLOP,   "P2 Mahjong Flip Flop",   SEQ_DEF_0 )
144   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_BIG,         "P2 Mahjong Big",         SEQ_DEF_0 )
145   INPUT_PORT_DIGITAL_TYPE( 2, PLAYER2, MAHJONG_SMALL,       "P2 Mahjong Small",       SEQ_DEF_0 )
146
147   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, JOYSTICK_UP,         "P3 Up",                  SEQ_DEF_3(KEYCODE_I, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 2)) )
148   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, JOYSTICK_DOWN,       "P3 Down",                SEQ_DEF_3(KEYCODE_K, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 2)) )
149   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, JOYSTICK_LEFT,       "P3 Left",                SEQ_DEF_3(KEYCODE_J, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 2)) )
150   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, JOYSTICK_RIGHT,      "P3 Right",               SEQ_DEF_3(KEYCODE_L, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 2)) )
151   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, JOYSTICKRIGHT_UP,    "P3 Right/Up",            SEQ_DEF_0 )
152   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, JOYSTICKRIGHT_DOWN,  "P3 Right/Down",          SEQ_DEF_0 )
153   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, JOYSTICKRIGHT_LEFT,  "P3 Right/Left",          SEQ_DEF_0 )
154   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, JOYSTICKRIGHT_RIGHT, "P3 Right/Right",         SEQ_DEF_0 )
155   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, JOYSTICKLEFT_UP,     "P3 Left/Up",             SEQ_DEF_0 )
156   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, JOYSTICKLEFT_DOWN,   "P3 Left/Down",           SEQ_DEF_0 )
157   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, JOYSTICKLEFT_LEFT,   "P3 Left/Left",           SEQ_DEF_0 )
158   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, JOYSTICKLEFT_RIGHT,  "P3 Left/Right",          SEQ_DEF_0 )
159   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, BUTTON1,             "P3 Button 1",            SEQ_DEF_5(KEYCODE_RCONTROL, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 2), SEQCODE_OR, INDEXED(GUNCODE_BUTTON1, 2)) )
160   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, BUTTON2,             "P3 Button 2",            SEQ_DEF_5(KEYCODE_RSHIFT, SEQCODE_OR, INDEXED(JOYCODE_BUTTON2, 2), SEQCODE_OR, INDEXED(GUNCODE_BUTTON2, 2)) )
161   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, BUTTON3,             "P3 Button 3",            SEQ_DEF_3(KEYCODE_ENTER, SEQCODE_OR, INDEXED(JOYCODE_BUTTON3, 2)) )
162   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, BUTTON4,             "P3 Button 4",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON4, 2)) )
163   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, BUTTON5,             "P3 Button 5",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON5, 2)) )
164   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, BUTTON6,             "P3 Button 6",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON6, 2)) )
165   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, BUTTON7,             "P3 Button 7",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON7, 2)) )
166   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, BUTTON8,             "P3 Button 8",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON8, 2)) )
167   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, BUTTON9,             "P3 Button 9",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON9, 2)) )
168   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, BUTTON10,            "P3 Button 10",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON10, 2)) )
169   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, BUTTON11,            "P3 Button 11",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON11, 2)) )
170   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, BUTTON12,            "P3 Button 12",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON12, 2)) )
171   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, BUTTON13,            "P3 Button 13",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON13, 2)) )
172   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, BUTTON14,            "P3 Button 14",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON14, 2)) )
173   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, BUTTON15,            "P3 Button 15",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON15, 2)) )
174   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, BUTTON16,            "P3 Button 16",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON16, 2)) )
175   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, START,               "P3 Start",               SEQ_DEF_3(KEYCODE_3, SEQCODE_OR, INDEXED(JOYCODE_START, 2)) )
176   INPUT_PORT_DIGITAL_TYPE( 3, PLAYER3, SELECT,              "P3 Select",              SEQ_DEF_3(KEYCODE_7, SEQCODE_OR, INDEXED(JOYCODE_SELECT, 2)) )
177
178   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, JOYSTICK_UP,         "P4 Up",                  SEQ_DEF_3(KEYCODE_8_PAD, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 3)) )
179   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, JOYSTICK_DOWN,       "P4 Down",                SEQ_DEF_3(KEYCODE_2_PAD, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 3)) )
180   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, JOYSTICK_LEFT,       "P4 Left",                SEQ_DEF_3(KEYCODE_4_PAD, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 3)) )
181   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, JOYSTICK_RIGHT,      "P4 Right",               SEQ_DEF_3(KEYCODE_6_PAD, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 3)) )
182   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, JOYSTICKRIGHT_UP,    "P4 Right/Up",            SEQ_DEF_0 )
183   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, JOYSTICKRIGHT_DOWN,  "P4 Right/Down",          SEQ_DEF_0 )
184   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, JOYSTICKRIGHT_LEFT,  "P4 Right/Left",          SEQ_DEF_0 )
185   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, JOYSTICKRIGHT_RIGHT, "P4 Right/Right",         SEQ_DEF_0 )
186   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, JOYSTICKLEFT_UP,     "P4 Left/Up",             SEQ_DEF_0 )
187   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, JOYSTICKLEFT_DOWN,   "P4 Left/Down",           SEQ_DEF_0 )
188   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, JOYSTICKLEFT_LEFT,   "P4 Left/Left",           SEQ_DEF_0 )
189   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, JOYSTICKLEFT_RIGHT,  "P4 Left/Right",          SEQ_DEF_0 )
190   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, BUTTON1,             "P4 Button 1",            SEQ_DEF_3(KEYCODE_0_PAD, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 3)) )
191   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, BUTTON2,             "P4 Button 2",            SEQ_DEF_3(KEYCODE_DEL_PAD, SEQCODE_OR, INDEXED(JOYCODE_BUTTON2, 3)) )
192   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, BUTTON3,             "P4 Button 3",            SEQ_DEF_3(KEYCODE_ENTER_PAD, SEQCODE_OR, INDEXED(JOYCODE_BUTTON3, 3)) )
193   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, BUTTON4,             "P4 Button 4",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON4, 3)) )
194   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, BUTTON5,             "P4 Button 5",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON5, 3)) )
195   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, BUTTON6,             "P4 Button 6",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON6, 3)) )
196   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, BUTTON7,             "P4 Button 7",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON7, 3)) )
197   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, BUTTON8,             "P4 Button 8",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON8, 3)) )
198   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, BUTTON9,             "P4 Button 9",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON9, 3)) )
199   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, BUTTON10,            "P4 Button 10",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON10, 3)) )
200   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, BUTTON11,            "P4 Button 11",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON11, 3)) )
201   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, BUTTON12,            "P4 Button 12",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON12, 3)) )
202   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, BUTTON13,            "P4 Button 13",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON13, 3)) )
203   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, BUTTON14,            "P4 Button 14",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON14, 3)) )
204   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, BUTTON15,            "P4 Button 15",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON15, 3)) )
205   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, BUTTON16,            "P4 Button 16",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON16, 3)) )
206   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, START,               "P4 Start",               SEQ_DEF_3(KEYCODE_4, SEQCODE_OR, INDEXED(JOYCODE_START, 3)) )
207   INPUT_PORT_DIGITAL_TYPE( 4, PLAYER4, SELECT,              "P4 Select",              SEQ_DEF_3(KEYCODE_8, SEQCODE_OR, INDEXED(JOYCODE_SELECT, 3)) )
208
209   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, JOYSTICK_UP,         "P5 Up",                  SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 4)) )
210   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, JOYSTICK_DOWN,       "P5 Down",                SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 4)) )
211   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, JOYSTICK_LEFT,       "P5 Left",                SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 4)) )
212   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, JOYSTICK_RIGHT,      "P5 Right",               SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 4)) )
213   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, JOYSTICKRIGHT_UP,    "P5 Right/Up",            SEQ_DEF_0 )
214   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, JOYSTICKRIGHT_DOWN,  "P5 Right/Down",          SEQ_DEF_0 )
215   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, JOYSTICKRIGHT_LEFT,  "P5 Right/Left",          SEQ_DEF_0 )
216   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, JOYSTICKRIGHT_RIGHT, "P5 Right/Right",         SEQ_DEF_0 )
217   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, JOYSTICKLEFT_UP,     "P5 Left/Up",             SEQ_DEF_0 )
218   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, JOYSTICKLEFT_DOWN,   "P5 Left/Down",           SEQ_DEF_0 )
219   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, JOYSTICKLEFT_LEFT,   "P5 Left/Left",           SEQ_DEF_0 )
220   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, JOYSTICKLEFT_RIGHT,  "P5 Left/Right",          SEQ_DEF_0 )
221   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, BUTTON1,             "P5 Button 1",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON1, 4)) )
222   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, BUTTON2,             "P5 Button 2",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON2, 4)) )
223   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, BUTTON3,             "P5 Button 3",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON3, 4)) )
224   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, BUTTON4,             "P5 Button 4",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON4, 4)) )
225   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, BUTTON5,             "P5 Button 5",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON5, 4)) )
226   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, BUTTON6,             "P5 Button 6",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON6, 4)) )
227   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, BUTTON7,             "P5 Button 7",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON7, 4)) )
228   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, BUTTON8,             "P5 Button 8",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON8, 4)) )
229   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, BUTTON9,             "P5 Button 9",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON9, 4)) )
230   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, BUTTON10,            "P5 Button 10",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON10, 4)) )
231   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, BUTTON11,            "P5 Button 11",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON11, 4)) )
232   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, BUTTON12,            "P5 Button 12",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON12, 4)) )
233   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, BUTTON13,            "P5 Button 13",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON13, 4)) )
234   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, BUTTON14,            "P5 Button 14",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON14, 4)) )
235   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, BUTTON15,            "P5 Button 15",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON15, 4)) )
236   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, BUTTON16,            "P5 Button 16",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON16, 4)) )
237   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, START,               "P5 Start",               SEQ_DEF_0 )
238   INPUT_PORT_DIGITAL_TYPE( 5, PLAYER5, SELECT,              "P5 Select",              SEQ_DEF_0 )
239
240   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, JOYSTICK_UP,         "P6 Up",                  SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 5)) )
241   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, JOYSTICK_DOWN,       "P6 Down",                SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 5)) )
242   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, JOYSTICK_LEFT,       "P6 Left",                SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 5)) )
243   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, JOYSTICK_RIGHT,      "P6 Right",               SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 5)) )
244   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, JOYSTICKRIGHT_UP,    "P6 Right/Up",            SEQ_DEF_0 )
245   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, JOYSTICKRIGHT_DOWN,  "P6 Right/Down",          SEQ_DEF_0 )
246   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, JOYSTICKRIGHT_LEFT,  "P6 Right/Left",          SEQ_DEF_0 )
247   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, JOYSTICKRIGHT_RIGHT, "P6 Right/Right",         SEQ_DEF_0 )
248   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, JOYSTICKLEFT_UP,     "P6 Left/Up",             SEQ_DEF_0 )
249   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, JOYSTICKLEFT_DOWN,   "P6 Left/Down",           SEQ_DEF_0 )
250   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, JOYSTICKLEFT_LEFT,   "P6 Left/Left",           SEQ_DEF_0 )
251   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, JOYSTICKLEFT_RIGHT,  "P6 Left/Right",          SEQ_DEF_0 )
252   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, BUTTON1,             "P6 Button 1",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON1, 5)) )
253   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, BUTTON2,             "P6 Button 2",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON2, 5)) )
254   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, BUTTON3,             "P6 Button 3",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON3, 5)) )
255   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, BUTTON4,             "P6 Button 4",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON4, 5)) )
256   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, BUTTON5,             "P6 Button 5",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON5, 5)) )
257   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, BUTTON6,             "P6 Button 6",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON6, 5)) )
258   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, BUTTON7,             "P6 Button 7",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON7, 5)) )
259   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, BUTTON8,             "P6 Button 8",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON8, 5)) )
260   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, BUTTON9,             "P6 Button 9",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON9, 5)) )
261   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, BUTTON10,            "P6 Button 10",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON10, 5)) )
262   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, BUTTON11,            "P6 Button 11",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON11, 5)) )
263   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, BUTTON12,            "P6 Button 12",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON12, 5)) )
264   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, BUTTON13,            "P6 Button 13",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON13, 5)) )
265   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, BUTTON14,            "P6 Button 14",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON14, 5)) )
266   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, BUTTON15,            "P6 Button 15",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON15, 5)) )
267   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, BUTTON16,            "P6 Button 16",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON16, 5)) )
268   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, START,               "P6 Start",               SEQ_DEF_0 )
269   INPUT_PORT_DIGITAL_TYPE( 6, PLAYER6, SELECT,              "P6 Select",              SEQ_DEF_0 )
270
271   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, JOYSTICK_UP,         "P7 Up",                  SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 6)) )
272   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, JOYSTICK_DOWN,       "P7 Down",                SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 6)) )
273   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, JOYSTICK_LEFT,       "P7 Left",                SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 6)) )
274   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, JOYSTICK_RIGHT,      "P7 Right",               SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 6)) )
275   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, JOYSTICKRIGHT_UP,    "P7 Right/Up",            SEQ_DEF_0 )
276   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, JOYSTICKRIGHT_DOWN,  "P7 Right/Down",          SEQ_DEF_0 )
277   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, JOYSTICKRIGHT_LEFT,  "P7 Right/Left",          SEQ_DEF_0 )
278   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, JOYSTICKRIGHT_RIGHT, "P7 Right/Right",         SEQ_DEF_0 )
279   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, JOYSTICKLEFT_UP,     "P7 Left/Up",             SEQ_DEF_0 )
280   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, JOYSTICKLEFT_DOWN,   "P7 Left/Down",           SEQ_DEF_0 )
281   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, JOYSTICKLEFT_LEFT,   "P7 Left/Left",           SEQ_DEF_0 )
282   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, JOYSTICKLEFT_RIGHT,  "P7 Left/Right",          SEQ_DEF_0 )
283   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, BUTTON1,             "P7 Button 1",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON1, 6)) )
284   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, BUTTON2,             "P7 Button 2",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON2, 6)) )
285   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, BUTTON3,             "P7 Button 3",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON3, 6)) )
286   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, BUTTON4,             "P7 Button 4",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON4, 6)) )
287   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, BUTTON5,             "P7 Button 5",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON5, 6)) )
288   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, BUTTON6,             "P7 Button 6",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON6, 6)) )
289   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, BUTTON7,             "P7 Button 7",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON7, 6)) )
290   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, BUTTON8,             "P7 Button 8",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON8, 6)) )
291   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, BUTTON9,             "P7 Button 9",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON9, 6)) )
292   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, BUTTON10,            "P7 Button 10",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON10, 6)) )
293   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, BUTTON11,            "P7 Button 11",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON11, 6)) )
294   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, BUTTON12,            "P7 Button 12",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON12, 6)) )
295   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, BUTTON13,            "P7 Button 13",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON13, 6)) )
296   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, BUTTON14,            "P7 Button 14",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON14, 6)) )
297   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, BUTTON15,            "P7 Button 15",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON15, 6)) )
298   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, BUTTON16,            "P7 Button 16",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON16, 6)) )
299   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, START,               "P7 Start",               SEQ_DEF_0 )
300   INPUT_PORT_DIGITAL_TYPE( 7, PLAYER7, SELECT,              "P7 Select",              SEQ_DEF_0 )
301
302   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, JOYSTICK_UP,         "P8 Up",                  SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 7)) )
303   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, JOYSTICK_DOWN,       "P8 Down",                SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 7)) )
304   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, JOYSTICK_LEFT,       "P8 Left",                SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 7)) )
305   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, JOYSTICK_RIGHT,      "P8 Right",               SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 7)) )
306   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, JOYSTICKRIGHT_UP,    "P8 Right/Up",            SEQ_DEF_0 )
307   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, JOYSTICKRIGHT_DOWN,  "P8 Right/Down",          SEQ_DEF_0 )
308   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, JOYSTICKRIGHT_LEFT,  "P8 Right/Left",          SEQ_DEF_0 )
309   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, JOYSTICKRIGHT_RIGHT, "P8 Right/Right",         SEQ_DEF_0 )
310   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, JOYSTICKLEFT_UP,     "P8 Left/Up",             SEQ_DEF_0 )
311   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, JOYSTICKLEFT_DOWN,   "P8 Left/Down",           SEQ_DEF_0 )
312   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, JOYSTICKLEFT_LEFT,   "P8 Left/Left",           SEQ_DEF_0 )
313   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, JOYSTICKLEFT_RIGHT,  "P8 Left/Right",          SEQ_DEF_0 )
314   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, BUTTON1,             "P8 Button 1",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON1, 7)) )
315   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, BUTTON2,             "P8 Button 2",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON2, 7)) )
316   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, BUTTON3,             "P8 Button 3",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON3, 7)) )
317   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, BUTTON4,             "P8 Button 4",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON4, 7)) )
318   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, BUTTON5,             "P8 Button 5",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON5, 7)) )
319   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, BUTTON6,             "P8 Button 6",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON6, 7)) )
320   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, BUTTON7,             "P8 Button 7",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON7, 7)) )
321   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, BUTTON8,             "P8 Button 8",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON8, 7)) )
322   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, BUTTON9,             "P8 Button 9",            SEQ_DEF_1(INDEXED(JOYCODE_BUTTON9, 7)) )
323   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, BUTTON10,            "P8 Button 10",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON10, 7)) )
324   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, BUTTON11,            "P8 Button 11",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON11, 7)) )
325   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, BUTTON12,            "P8 Button 12",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON12, 7)) )
326   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, BUTTON13,            "P8 Button 13",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON13, 7)) )
327   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, BUTTON14,            "P8 Button 14",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON14, 7)) )
328   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, BUTTON15,            "P8 Button 15",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON15, 7)) )
329   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, BUTTON16,            "P8 Button 16",           SEQ_DEF_1(INDEXED(JOYCODE_BUTTON16, 7)) )
330   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, START,               "P8 Start",               SEQ_DEF_0 )
331   INPUT_PORT_DIGITAL_TYPE( 8, PLAYER8, SELECT,              "P8 Select",              SEQ_DEF_0 )
332
333   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   START1,              "1 Player Start",         SEQ_DEF_3(KEYCODE_1, SEQCODE_OR, INDEXED(JOYCODE_START, 0)) )
334   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   START2,              "2 Players Start",        SEQ_DEF_3(KEYCODE_2, SEQCODE_OR, INDEXED(JOYCODE_START, 1)) )
335   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   START3,              "3 Players Start",        SEQ_DEF_3(KEYCODE_3, SEQCODE_OR, INDEXED(JOYCODE_START, 2)) )
336   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   START4,              "4 Players Start",        SEQ_DEF_3(KEYCODE_4, SEQCODE_OR, INDEXED(JOYCODE_START, 3)) )
337   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   START5,              "5 Players Start",        SEQ_DEF_0 )
338   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   START6,              "6 Players Start",        SEQ_DEF_0 )
339   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   START7,              "7 Players Start",        SEQ_DEF_0 )
340   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   START8,              "8 Players Start",        SEQ_DEF_0 )
341
342   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   COIN1,               "Coin 1",                 SEQ_DEF_3(KEYCODE_5, SEQCODE_OR, INDEXED(JOYCODE_SELECT, 0)) )
343   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   COIN2,               "Coin 2",                 SEQ_DEF_3(KEYCODE_6, SEQCODE_OR, INDEXED(JOYCODE_SELECT, 1)) )
344   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   COIN3,               "Coin 3",                 SEQ_DEF_3(KEYCODE_7, SEQCODE_OR, INDEXED(JOYCODE_SELECT, 2)) )
345   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   COIN4,               "Coin 4",                 SEQ_DEF_3(KEYCODE_8, SEQCODE_OR, INDEXED(JOYCODE_SELECT, 3)) )
346   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   COIN5,               "Coin 5",                 SEQ_DEF_0 )
347   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   COIN6,               "Coin 6",                 SEQ_DEF_0 )
348   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   COIN7,               "Coin 7",                 SEQ_DEF_0 )
349   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   COIN8,               "Coin 8",                 SEQ_DEF_0 )
350   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   BILL1,               "Bill 1",                 SEQ_DEF_1(KEYCODE_BACKSPACE) )
351
352   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   SERVICE1,            "Service 1",              SEQ_DEF_1(KEYCODE_9) )
353   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   SERVICE2,            "Service 2",              SEQ_DEF_1(KEYCODE_0) )
354   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   SERVICE3,            "Service 3",              SEQ_DEF_1(KEYCODE_MINUS) )
355   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   SERVICE4,            "Service 4",              SEQ_DEF_1(KEYCODE_EQUALS) )
356
357   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   SERVICE,             "Service",                SEQ_DEF_1(KEYCODE_F2) )
358   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   TILT,                "Tilt",                   SEQ_DEF_1(KEYCODE_T) )
359   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   INTERLOCK,           "Door Interlock",         SEQ_DEF_0 )
360   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   VOLUME_DOWN,         "Volume Down",            SEQ_DEF_1(KEYCODE_MINUS) )
361   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   VOLUME_UP,           "Volume Up",              SEQ_DEF_1(KEYCODE_EQUALS) )
362
363   INPUT_PORT_ANALOG_TYPE(  1, PLAYER1, PEDAL,               "P1 Pedal 1",             SEQ_DEF_1(INDEXED(JOYCODE_Y_NEG_ABSOLUTE, 0)), SEQ_DEF_0, SEQ_DEF_3(KEYCODE_LCONTROL, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 0)) )
364   INPUT_PORT_ANALOG_TYPE(  2, PLAYER2, PEDAL,               "P2 Pedal 1",             SEQ_DEF_1(INDEXED(JOYCODE_Y_NEG_ABSOLUTE, 1)), SEQ_DEF_0, SEQ_DEF_3(KEYCODE_A, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 1)) )
365   INPUT_PORT_ANALOG_TYPE(  3, PLAYER3, PEDAL,               "P3 Pedal 1",             SEQ_DEF_1(INDEXED(JOYCODE_Y_NEG_ABSOLUTE, 2)), SEQ_DEF_0, SEQ_DEF_3(KEYCODE_RCONTROL, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 2)) )
366   INPUT_PORT_ANALOG_TYPE(  4, PLAYER4, PEDAL,               "P4 Pedal 1",             SEQ_DEF_1(INDEXED(JOYCODE_Y_NEG_ABSOLUTE, 3)), SEQ_DEF_0, SEQ_DEF_3(KEYCODE_0_PAD, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 3)) )
367   INPUT_PORT_ANALOG_TYPE(  5, PLAYER5, PEDAL,               "P5 Pedal 1",             SEQ_DEF_1(INDEXED(JOYCODE_Y_NEG_ABSOLUTE, 4)), SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON1, 4)) )
368   INPUT_PORT_ANALOG_TYPE(  6, PLAYER6, PEDAL,               "P6 Pedal 1",             SEQ_DEF_1(INDEXED(JOYCODE_Y_NEG_ABSOLUTE, 5)), SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON1, 5)) )
369   INPUT_PORT_ANALOG_TYPE(  7, PLAYER7, PEDAL,               "P7 Pedal 1",             SEQ_DEF_1(INDEXED(JOYCODE_Y_NEG_ABSOLUTE, 6)), SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON1, 6)) )
370   INPUT_PORT_ANALOG_TYPE(  8, PLAYER8, PEDAL,               "P8 Pedal 1",             SEQ_DEF_1(INDEXED(JOYCODE_Y_NEG_ABSOLUTE, 7)), SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON1, 7)) )
371
372   INPUT_PORT_ANALOG_TYPE(  1, PLAYER1, PEDAL2,              "P1 Pedal 2",             SEQ_DEF_1(INDEXED(JOYCODE_Y_POS_ABSOLUTE, 0)), SEQ_DEF_0, SEQ_DEF_3(KEYCODE_LALT, SEQCODE_OR, INDEXED(JOYCODE_BUTTON2, 0)) )
373   INPUT_PORT_ANALOG_TYPE(  2, PLAYER2, PEDAL2,              "P2 Pedal 2",             SEQ_DEF_1(INDEXED(JOYCODE_Y_POS_ABSOLUTE, 1)), SEQ_DEF_0, SEQ_DEF_3(KEYCODE_S, SEQCODE_OR, INDEXED(JOYCODE_BUTTON2, 1)) )
374   INPUT_PORT_ANALOG_TYPE(  3, PLAYER3, PEDAL2,              "P3 Pedal 2",             SEQ_DEF_1(INDEXED(JOYCODE_Y_POS_ABSOLUTE, 2)), SEQ_DEF_0, SEQ_DEF_3(KEYCODE_RSHIFT, SEQCODE_OR, INDEXED(JOYCODE_BUTTON2, 2)) )
375   INPUT_PORT_ANALOG_TYPE(  4, PLAYER4, PEDAL2,              "P4 Pedal 2",             SEQ_DEF_1(INDEXED(JOYCODE_Y_POS_ABSOLUTE, 3)), SEQ_DEF_0, SEQ_DEF_3(KEYCODE_DEL_PAD, SEQCODE_OR, INDEXED(JOYCODE_BUTTON2, 3)) )
376   INPUT_PORT_ANALOG_TYPE(  5, PLAYER5, PEDAL2,              "P5 Pedal 2",             SEQ_DEF_1(INDEXED(JOYCODE_Y_POS_ABSOLUTE, 4)), SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON2, 4)) )
377   INPUT_PORT_ANALOG_TYPE(  6, PLAYER6, PEDAL2,              "P6 Pedal 2",             SEQ_DEF_1(INDEXED(JOYCODE_Y_POS_ABSOLUTE, 5)), SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON2, 5)) )
378   INPUT_PORT_ANALOG_TYPE(  7, PLAYER7, PEDAL2,              "P7 Pedal 2",             SEQ_DEF_1(INDEXED(JOYCODE_Y_POS_ABSOLUTE, 6)), SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON2, 6)) )
379   INPUT_PORT_ANALOG_TYPE(  8, PLAYER8, PEDAL2,              "P8 Pedal 2",             SEQ_DEF_1(INDEXED(JOYCODE_Y_POS_ABSOLUTE, 7)), SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON2, 7)) )
380
381   INPUT_PORT_ANALOG_TYPE(  1, PLAYER1, PEDAL3,              "P1 Pedal 3",             SEQ_DEF_0, SEQ_DEF_0, SEQ_DEF_3(KEYCODE_SPACE, SEQCODE_OR, INDEXED(JOYCODE_BUTTON3, 0)) )
382   INPUT_PORT_ANALOG_TYPE(  2, PLAYER2, PEDAL3,              "P2 Pedal 3",             SEQ_DEF_0, SEQ_DEF_0, SEQ_DEF_3(KEYCODE_Q, SEQCODE_OR, INDEXED(JOYCODE_BUTTON3, 1)) )
383   INPUT_PORT_ANALOG_TYPE(  3, PLAYER3, PEDAL3,              "P3 Pedal 3",             SEQ_DEF_0, SEQ_DEF_0, SEQ_DEF_3(KEYCODE_ENTER, SEQCODE_OR, INDEXED(JOYCODE_BUTTON3, 2)) )
384   INPUT_PORT_ANALOG_TYPE(  4, PLAYER4, PEDAL3,              "P4 Pedal 3",             SEQ_DEF_0, SEQ_DEF_0, SEQ_DEF_3(KEYCODE_ENTER_PAD, SEQCODE_OR, INDEXED(JOYCODE_BUTTON3, 3)) )
385   INPUT_PORT_ANALOG_TYPE(  5, PLAYER5, PEDAL3,              "P5 Pedal 3",             SEQ_DEF_0, SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON3, 4)) )
386   INPUT_PORT_ANALOG_TYPE(  6, PLAYER6, PEDAL3,              "P6 Pedal 3",             SEQ_DEF_0, SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON3, 5)) )
387   INPUT_PORT_ANALOG_TYPE(  7, PLAYER7, PEDAL3,              "P7 Pedal 3",             SEQ_DEF_0, SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON3, 6)) )
388   INPUT_PORT_ANALOG_TYPE(  8, PLAYER8, PEDAL3,              "P8 Pedal 3",             SEQ_DEF_0, SEQ_DEF_0, SEQ_DEF_1(INDEXED(JOYCODE_BUTTON3, 7)) )
389
390   INPUT_PORT_ANALOG_TYPE(  1, PLAYER1, PADDLE,              "Paddle",                 SEQ_DEF_3(INDEXED(MOUSECODE_X, 0), SEQCODE_OR, INDEXED(JOYCODE_X, 0)), SEQ_DEF_3(KEYCODE_LEFT, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)), SEQ_DEF_3(KEYCODE_RIGHT, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
391   INPUT_PORT_ANALOG_TYPE(  2, PLAYER2, PADDLE,              "Paddle 2",               SEQ_DEF_3(INDEXED(MOUSECODE_X, 1), SEQCODE_OR, INDEXED(JOYCODE_X, 1)), SEQ_DEF_3(KEYCODE_D, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 1)), SEQ_DEF_3(KEYCODE_G, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 1)) )
392   INPUT_PORT_ANALOG_TYPE(  3, PLAYER3, PADDLE,              "Paddle 3",               SEQ_DEF_3(INDEXED(MOUSECODE_X, 2), SEQCODE_OR, INDEXED(JOYCODE_X, 2)), SEQ_DEF_3(KEYCODE_J, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 2)), SEQ_DEF_3(KEYCODE_L, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 2)) )
393   INPUT_PORT_ANALOG_TYPE(  4, PLAYER4, PADDLE,              "Paddle 4",               SEQ_DEF_3(INDEXED(MOUSECODE_X, 3), SEQCODE_OR, INDEXED(JOYCODE_X, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 3)) )
394   INPUT_PORT_ANALOG_TYPE(  5, PLAYER5, PADDLE,              "Paddle 5",               SEQ_DEF_3(INDEXED(MOUSECODE_X, 4), SEQCODE_OR, INDEXED(JOYCODE_X, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 4)) )
395   INPUT_PORT_ANALOG_TYPE(  6, PLAYER6, PADDLE,              "Paddle 6",               SEQ_DEF_3(INDEXED(MOUSECODE_X, 5), SEQCODE_OR, INDEXED(JOYCODE_X, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 5)) )
396   INPUT_PORT_ANALOG_TYPE(  7, PLAYER7, PADDLE,              "Paddle 7",               SEQ_DEF_3(INDEXED(MOUSECODE_X, 6), SEQCODE_OR, INDEXED(JOYCODE_X, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 6)) )
397   INPUT_PORT_ANALOG_TYPE(  8, PLAYER8, PADDLE,              "Paddle 8",               SEQ_DEF_3(INDEXED(MOUSECODE_X, 7), SEQCODE_OR, INDEXED(JOYCODE_X, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 7)) )
398
399   INPUT_PORT_ANALOG_TYPE(  1, PLAYER1, PADDLE_V,            "Paddle V",               SEQ_DEF_3(INDEXED(MOUSECODE_Y, 0), SEQCODE_OR, INDEXED(JOYCODE_Y, 0)), SEQ_DEF_3(KEYCODE_UP, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)), SEQ_DEF_3(KEYCODE_DOWN, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
400   INPUT_PORT_ANALOG_TYPE(  2, PLAYER2, PADDLE_V,            "Paddle V 2",             SEQ_DEF_3(INDEXED(MOUSECODE_Y, 1), SEQCODE_OR, INDEXED(JOYCODE_Y, 1)), SEQ_DEF_3(KEYCODE_R, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 1)), SEQ_DEF_3(KEYCODE_F, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 1)) )
401   INPUT_PORT_ANALOG_TYPE(  3, PLAYER3, PADDLE_V,            "Paddle V 3",             SEQ_DEF_3(INDEXED(MOUSECODE_Y, 2), SEQCODE_OR, INDEXED(JOYCODE_Y, 2)), SEQ_DEF_3(KEYCODE_I, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 2)), SEQ_DEF_3(KEYCODE_K, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 2)) )
402   INPUT_PORT_ANALOG_TYPE(  4, PLAYER4, PADDLE_V,            "Paddle V 4",             SEQ_DEF_3(INDEXED(MOUSECODE_Y, 3), SEQCODE_OR, INDEXED(JOYCODE_Y, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 3)) )
403   INPUT_PORT_ANALOG_TYPE(  5, PLAYER5, PADDLE_V,            "Paddle V 5",             SEQ_DEF_3(INDEXED(MOUSECODE_Y, 4), SEQCODE_OR, INDEXED(JOYCODE_Y, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 4)) )
404   INPUT_PORT_ANALOG_TYPE(  6, PLAYER6, PADDLE_V,            "Paddle V 6",             SEQ_DEF_3(INDEXED(MOUSECODE_Y, 5), SEQCODE_OR, INDEXED(JOYCODE_Y, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 5)) )
405   INPUT_PORT_ANALOG_TYPE(  7, PLAYER7, PADDLE_V,            "Paddle V 7",             SEQ_DEF_3(INDEXED(MOUSECODE_Y, 6), SEQCODE_OR, INDEXED(JOYCODE_Y, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 6)) )
406   INPUT_PORT_ANALOG_TYPE(  8, PLAYER8, PADDLE_V,            "Paddle V 8",             SEQ_DEF_3(INDEXED(MOUSECODE_Y, 7), SEQCODE_OR, INDEXED(JOYCODE_Y, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 7)) )
407
408   INPUT_PORT_ANALOG_TYPE(  1, PLAYER1, POSITIONAL,          "Positional",             SEQ_DEF_3(INDEXED(MOUSECODE_X, 0), SEQCODE_OR, INDEXED(JOYCODE_X, 0)), SEQ_DEF_3(KEYCODE_LEFT, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)), SEQ_DEF_3(KEYCODE_RIGHT, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
409   INPUT_PORT_ANALOG_TYPE(  2, PLAYER2, POSITIONAL,          "Positional 2",           SEQ_DEF_3(INDEXED(MOUSECODE_X, 1), SEQCODE_OR, INDEXED(JOYCODE_X, 1)), SEQ_DEF_3(KEYCODE_D, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 1)), SEQ_DEF_3(KEYCODE_G, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 1)) )
410   INPUT_PORT_ANALOG_TYPE(  3, PLAYER3, POSITIONAL,          "Positional 3",           SEQ_DEF_3(INDEXED(MOUSECODE_X, 2), SEQCODE_OR, INDEXED(JOYCODE_X, 2)), SEQ_DEF_3(KEYCODE_J, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 2)), SEQ_DEF_3(KEYCODE_L, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 2)) )
411   INPUT_PORT_ANALOG_TYPE(  4, PLAYER4, POSITIONAL,          "Positional 4",           SEQ_DEF_3(INDEXED(MOUSECODE_X, 3), SEQCODE_OR, INDEXED(JOYCODE_X, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 3)) )
412   INPUT_PORT_ANALOG_TYPE(  5, PLAYER5, POSITIONAL,          "Positional 5",           SEQ_DEF_3(INDEXED(MOUSECODE_X, 4), SEQCODE_OR, INDEXED(JOYCODE_X, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 4)) )
413   INPUT_PORT_ANALOG_TYPE(  6, PLAYER6, POSITIONAL,          "Positional 6",           SEQ_DEF_3(INDEXED(MOUSECODE_X, 5), SEQCODE_OR, INDEXED(JOYCODE_X, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 5)) )
414   INPUT_PORT_ANALOG_TYPE(  7, PLAYER7, POSITIONAL,          "Positional 7",           SEQ_DEF_3(INDEXED(MOUSECODE_X, 6), SEQCODE_OR, INDEXED(JOYCODE_X, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 6)) )
415   INPUT_PORT_ANALOG_TYPE(  8, PLAYER8, POSITIONAL,          "Positional 8",           SEQ_DEF_3(INDEXED(MOUSECODE_X, 7), SEQCODE_OR, INDEXED(JOYCODE_X, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 7)) )
416
417   INPUT_PORT_ANALOG_TYPE(  1, PLAYER1, POSITIONAL_V,        "Positional V",           SEQ_DEF_3(INDEXED(MOUSECODE_Y, 0), SEQCODE_OR, INDEXED(JOYCODE_Y, 0)), SEQ_DEF_3(KEYCODE_UP, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)), SEQ_DEF_3(KEYCODE_DOWN, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
418   INPUT_PORT_ANALOG_TYPE(  2, PLAYER2, POSITIONAL_V,        "Positional V 2",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 1), SEQCODE_OR, INDEXED(JOYCODE_Y, 1)), SEQ_DEF_3(KEYCODE_R, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 1)), SEQ_DEF_3(KEYCODE_F, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 1)) )
419   INPUT_PORT_ANALOG_TYPE(  3, PLAYER3, POSITIONAL_V,        "Positional V 3",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 2), SEQCODE_OR, INDEXED(JOYCODE_Y, 2)), SEQ_DEF_3(KEYCODE_I, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 2)), SEQ_DEF_3(KEYCODE_K, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 2)) )
420   INPUT_PORT_ANALOG_TYPE(  4, PLAYER4, POSITIONAL_V,        "Positional V 4",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 3), SEQCODE_OR, INDEXED(JOYCODE_Y, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 3)) )
421   INPUT_PORT_ANALOG_TYPE(  5, PLAYER5, POSITIONAL_V,        "Positional V 5",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 4), SEQCODE_OR, INDEXED(JOYCODE_Y, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 4)) )
422   INPUT_PORT_ANALOG_TYPE(  6, PLAYER6, POSITIONAL_V,        "Positional V 6",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 5), SEQCODE_OR, INDEXED(JOYCODE_Y, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 5)) )
423   INPUT_PORT_ANALOG_TYPE(  7, PLAYER7, POSITIONAL_V,        "Positional V 7",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 6), SEQCODE_OR, INDEXED(JOYCODE_Y, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 6)) )
424   INPUT_PORT_ANALOG_TYPE(  8, PLAYER8, POSITIONAL_V,        "Positional V 8",         SEQ_DEF_3(INDEXED(MOUSECODE_Y, 7), SEQCODE_OR, INDEXED(JOYCODE_Y, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 7)) )
425
426   INPUT_PORT_ANALOG_TYPE(  1, PLAYER1, DIAL,                "Dial",                   SEQ_DEF_3(INDEXED(MOUSECODE_X, 0), SEQCODE_OR, INDEXED(JOYCODE_X, 0)), SEQ_DEF_3(KEYCODE_LEFT, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)), SEQ_DEF_3(KEYCODE_RIGHT, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
427   INPUT_PORT_ANALOG_TYPE(  2, PLAYER2, DIAL,                "Dial 2",                 SEQ_DEF_3(INDEXED(MOUSECODE_X, 1), SEQCODE_OR, INDEXED(JOYCODE_X, 1)), SEQ_DEF_3(KEYCODE_D, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 1)), SEQ_DEF_3(KEYCODE_G, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 1)) )
428   INPUT_PORT_ANALOG_TYPE(  3, PLAYER3, DIAL,                "Dial 3",                 SEQ_DEF_3(INDEXED(MOUSECODE_X, 2), SEQCODE_OR, INDEXED(JOYCODE_X, 2)), SEQ_DEF_3(KEYCODE_J, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 2)), SEQ_DEF_3(KEYCODE_L, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 2)) )
429   INPUT_PORT_ANALOG_TYPE(  4, PLAYER4, DIAL,                "Dial 4",                 SEQ_DEF_3(INDEXED(MOUSECODE_X, 3), SEQCODE_OR, INDEXED(JOYCODE_X, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 3)) )
430   INPUT_PORT_ANALOG_TYPE(  5, PLAYER5, DIAL,                "Dial 5",                 SEQ_DEF_3(INDEXED(MOUSECODE_X, 4), SEQCODE_OR, INDEXED(JOYCODE_X, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 4)) )
431   INPUT_PORT_ANALOG_TYPE(  6, PLAYER6, DIAL,                "Dial 6",                 SEQ_DEF_3(INDEXED(MOUSECODE_X, 5), SEQCODE_OR, INDEXED(JOYCODE_X, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 5)) )
432   INPUT_PORT_ANALOG_TYPE(  7, PLAYER7, DIAL,                "Dial 7",                 SEQ_DEF_3(INDEXED(MOUSECODE_X, 6), SEQCODE_OR, INDEXED(JOYCODE_X, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 6)) )
433   INPUT_PORT_ANALOG_TYPE(  8, PLAYER8, DIAL,                "Dial 8",                 SEQ_DEF_3(INDEXED(MOUSECODE_X, 7), SEQCODE_OR, INDEXED(JOYCODE_X, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 7)) )
434
435   INPUT_PORT_ANALOG_TYPE(  1, PLAYER1, DIAL_V,              "Dial V",                 SEQ_DEF_3(INDEXED(MOUSECODE_Y, 0), SEQCODE_OR, INDEXED(JOYCODE_Y, 0)), SEQ_DEF_3(KEYCODE_UP, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)), SEQ_DEF_3(KEYCODE_DOWN, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
436   INPUT_PORT_ANALOG_TYPE(  2, PLAYER2, DIAL_V,              "Dial V 2",               SEQ_DEF_3(INDEXED(MOUSECODE_Y, 1), SEQCODE_OR, INDEXED(JOYCODE_Y, 1)), SEQ_DEF_3(KEYCODE_R, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 1)), SEQ_DEF_3(KEYCODE_F, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 1)) )
437   INPUT_PORT_ANALOG_TYPE(  3, PLAYER3, DIAL_V,              "Dial V 3",               SEQ_DEF_3(INDEXED(MOUSECODE_Y, 2), SEQCODE_OR, INDEXED(JOYCODE_Y, 2)), SEQ_DEF_3(KEYCODE_I, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 2)), SEQ_DEF_3(KEYCODE_K, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 2)) )
438   INPUT_PORT_ANALOG_TYPE(  4, PLAYER4, DIAL_V,              "Dial V 4",               SEQ_DEF_3(INDEXED(MOUSECODE_Y, 3), SEQCODE_OR, INDEXED(JOYCODE_Y, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 3)) )
439   INPUT_PORT_ANALOG_TYPE(  5, PLAYER5, DIAL_V,              "Dial V 5",               SEQ_DEF_3(INDEXED(MOUSECODE_Y, 4), SEQCODE_OR, INDEXED(JOYCODE_Y, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 4)) )
440   INPUT_PORT_ANALOG_TYPE(  6, PLAYER6, DIAL_V,              "Dial V 6",               SEQ_DEF_3(INDEXED(MOUSECODE_Y, 5), SEQCODE_OR, INDEXED(JOYCODE_Y, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 5)) )
441   INPUT_PORT_ANALOG_TYPE(  7, PLAYER7, DIAL_V,              "Dial V 7",               SEQ_DEF_3(INDEXED(MOUSECODE_Y, 6), SEQCODE_OR, INDEXED(JOYCODE_Y, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 6)) )
442   INPUT_PORT_ANALOG_TYPE(  8, PLAYER8, DIAL_V,              "Dial V 8",               SEQ_DEF_3(INDEXED(MOUSECODE_Y, 7), SEQCODE_OR, INDEXED(JOYCODE_Y, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 7)) )
443
444   INPUT_PORT_ANALOG_TYPE(  1, PLAYER1, TRACKBALL_X,         "Track X",                SEQ_DEF_3(INDEXED(MOUSECODE_X, 0), SEQCODE_OR, INDEXED(JOYCODE_X, 0)), SEQ_DEF_3(KEYCODE_LEFT, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)), SEQ_DEF_3(KEYCODE_RIGHT, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
445   INPUT_PORT_ANALOG_TYPE(  2, PLAYER2, TRACKBALL_X,         "Track X 2",              SEQ_DEF_3(INDEXED(MOUSECODE_X, 1), SEQCODE_OR, INDEXED(JOYCODE_X, 1)), SEQ_DEF_3(KEYCODE_D, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 1)), SEQ_DEF_3(KEYCODE_G, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 1)) )
446   INPUT_PORT_ANALOG_TYPE(  3, PLAYER3, TRACKBALL_X,         "Track X 3",              SEQ_DEF_3(INDEXED(MOUSECODE_X, 2), SEQCODE_OR, INDEXED(JOYCODE_X, 2)), SEQ_DEF_3(KEYCODE_J, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 2)), SEQ_DEF_3(KEYCODE_L, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 2)) )
447   INPUT_PORT_ANALOG_TYPE(  4, PLAYER4, TRACKBALL_X,         "Track X 4",              SEQ_DEF_3(INDEXED(MOUSECODE_X, 3), SEQCODE_OR, INDEXED(JOYCODE_X, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 3)) )
448   INPUT_PORT_ANALOG_TYPE(  5, PLAYER5, TRACKBALL_X,         "Track X 5",              SEQ_DEF_3(INDEXED(MOUSECODE_X, 4), SEQCODE_OR, INDEXED(JOYCODE_X, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 4)) )
449   INPUT_PORT_ANALOG_TYPE(  6, PLAYER6, TRACKBALL_X,         "Track X 6",              SEQ_DEF_3(INDEXED(MOUSECODE_X, 5), SEQCODE_OR, INDEXED(JOYCODE_X, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 5)) )
450   INPUT_PORT_ANALOG_TYPE(  7, PLAYER7, TRACKBALL_X,         "Track X 7",              SEQ_DEF_3(INDEXED(MOUSECODE_X, 6), SEQCODE_OR, INDEXED(JOYCODE_X, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 6)) )
451   INPUT_PORT_ANALOG_TYPE(  8, PLAYER8, TRACKBALL_X,         "Track X 8",              SEQ_DEF_3(INDEXED(MOUSECODE_X, 7), SEQCODE_OR, INDEXED(JOYCODE_X, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 7)) )
452
453   INPUT_PORT_ANALOG_TYPE(  1, PLAYER1, TRACKBALL_Y,         "Track Y",                SEQ_DEF_3(INDEXED(MOUSECODE_Y, 0), SEQCODE_OR, INDEXED(JOYCODE_Y, 0)), SEQ_DEF_3(KEYCODE_UP, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)), SEQ_DEF_3(KEYCODE_DOWN, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
454   INPUT_PORT_ANALOG_TYPE(  2, PLAYER2, TRACKBALL_Y,         "Track Y 2",              SEQ_DEF_3(INDEXED(MOUSECODE_Y, 1), SEQCODE_OR, INDEXED(JOYCODE_Y, 1)), SEQ_DEF_3(KEYCODE_R, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 1)), SEQ_DEF_3(KEYCODE_F, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 1)) )
455   INPUT_PORT_ANALOG_TYPE(  3, PLAYER3, TRACKBALL_Y,         "Track Y 3",              SEQ_DEF_3(INDEXED(MOUSECODE_Y, 2), SEQCODE_OR, INDEXED(JOYCODE_Y, 2)), SEQ_DEF_3(KEYCODE_I, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 2)), SEQ_DEF_3(KEYCODE_K, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 2)) )
456   INPUT_PORT_ANALOG_TYPE(  4, PLAYER4, TRACKBALL_Y,         "Track Y 4",              SEQ_DEF_3(INDEXED(MOUSECODE_Y, 3), SEQCODE_OR, INDEXED(JOYCODE_Y, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 3)) )
457   INPUT_PORT_ANALOG_TYPE(  5, PLAYER5, TRACKBALL_Y,         "Track Y 5",              SEQ_DEF_3(INDEXED(MOUSECODE_Y, 4), SEQCODE_OR, INDEXED(JOYCODE_Y, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 4)) )
458   INPUT_PORT_ANALOG_TYPE(  6, PLAYER6, TRACKBALL_Y,         "Track Y 6",              SEQ_DEF_3(INDEXED(MOUSECODE_Y, 5), SEQCODE_OR, INDEXED(JOYCODE_Y, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 5)) )
459   INPUT_PORT_ANALOG_TYPE(  7, PLAYER7, TRACKBALL_Y,         "Track Y 7",              SEQ_DEF_3(INDEXED(MOUSECODE_Y, 6), SEQCODE_OR, INDEXED(JOYCODE_Y, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 6)) )
460   INPUT_PORT_ANALOG_TYPE(  8, PLAYER8, TRACKBALL_Y,         "Track Y 8",              SEQ_DEF_3(INDEXED(MOUSECODE_Y, 7), SEQCODE_OR, INDEXED(JOYCODE_Y, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 7)) )
461
462   INPUT_PORT_ANALOG_TYPE(  1, PLAYER1, AD_STICK_X,          "AD Stick X",             SEQ_DEF_3(INDEXED(JOYCODE_X, 0), SEQCODE_OR, INDEXED(MOUSECODE_X, 0)), SEQ_DEF_3(KEYCODE_LEFT, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)), SEQ_DEF_3(KEYCODE_RIGHT, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
463   INPUT_PORT_ANALOG_TYPE(  2, PLAYER2, AD_STICK_X,          "AD Stick X 2",           SEQ_DEF_3(INDEXED(JOYCODE_X, 1), SEQCODE_OR, INDEXED(MOUSECODE_X, 1)), SEQ_DEF_3(KEYCODE_D, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 1)), SEQ_DEF_3(KEYCODE_G, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 1)) )
464   INPUT_PORT_ANALOG_TYPE(  3, PLAYER3, AD_STICK_X,          "AD Stick X 3",           SEQ_DEF_3(INDEXED(JOYCODE_X, 2), SEQCODE_OR, INDEXED(MOUSECODE_X, 2)), SEQ_DEF_3(KEYCODE_J, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 2)), SEQ_DEF_3(KEYCODE_L, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 2)) )
465   INPUT_PORT_ANALOG_TYPE(  4, PLAYER4, AD_STICK_X,          "AD Stick X 4",           SEQ_DEF_3(INDEXED(JOYCODE_X, 3), SEQCODE_OR, INDEXED(MOUSECODE_X, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 3)) )
466   INPUT_PORT_ANALOG_TYPE(  5, PLAYER5, AD_STICK_X,          "AD Stick X 5",           SEQ_DEF_3(INDEXED(JOYCODE_X, 4), SEQCODE_OR, INDEXED(MOUSECODE_X, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 4)) )
467   INPUT_PORT_ANALOG_TYPE(  6, PLAYER6, AD_STICK_X,          "AD Stick X 6",           SEQ_DEF_3(INDEXED(JOYCODE_X, 5), SEQCODE_OR, INDEXED(MOUSECODE_X, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 5)) )
468   INPUT_PORT_ANALOG_TYPE(  7, PLAYER7, AD_STICK_X,          "AD Stick X 7",           SEQ_DEF_3(INDEXED(JOYCODE_X, 6), SEQCODE_OR, INDEXED(MOUSECODE_X, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 6)) )
469   INPUT_PORT_ANALOG_TYPE(  8, PLAYER8, AD_STICK_X,          "AD Stick X 8",           SEQ_DEF_3(INDEXED(JOYCODE_X, 7), SEQCODE_OR, INDEXED(MOUSECODE_X, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 7)) )
470
471   INPUT_PORT_ANALOG_TYPE(  1, PLAYER1, AD_STICK_Y,          "AD Stick Y",             SEQ_DEF_3(INDEXED(JOYCODE_Y, 0), SEQCODE_OR, INDEXED(MOUSECODE_Y, 0)), SEQ_DEF_3(KEYCODE_UP, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)), SEQ_DEF_3(KEYCODE_DOWN, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
472   INPUT_PORT_ANALOG_TYPE(  2, PLAYER2, AD_STICK_Y,          "AD Stick Y 2",           SEQ_DEF_3(INDEXED(JOYCODE_Y, 1), SEQCODE_OR, INDEXED(MOUSECODE_Y, 1)), SEQ_DEF_3(KEYCODE_R, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 1)), SEQ_DEF_3(KEYCODE_F, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 1)) )
473   INPUT_PORT_ANALOG_TYPE(  3, PLAYER3, AD_STICK_Y,          "AD Stick Y 3",           SEQ_DEF_3(INDEXED(JOYCODE_Y, 2), SEQCODE_OR, INDEXED(MOUSECODE_Y, 2)), SEQ_DEF_3(KEYCODE_I, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 2)), SEQ_DEF_3(KEYCODE_K, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 2)) )
474   INPUT_PORT_ANALOG_TYPE(  4, PLAYER4, AD_STICK_Y,          "AD Stick Y 4",           SEQ_DEF_3(INDEXED(JOYCODE_Y, 3), SEQCODE_OR, INDEXED(MOUSECODE_Y, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 3)) )
475   INPUT_PORT_ANALOG_TYPE(  5, PLAYER5, AD_STICK_Y,          "AD Stick Y 5",           SEQ_DEF_3(INDEXED(JOYCODE_Y, 4), SEQCODE_OR, INDEXED(MOUSECODE_Y, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 4)) )
476   INPUT_PORT_ANALOG_TYPE(  6, PLAYER6, AD_STICK_Y,          "AD Stick Y 6",           SEQ_DEF_3(INDEXED(JOYCODE_Y, 5), SEQCODE_OR, INDEXED(MOUSECODE_Y, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 5)) )
477   INPUT_PORT_ANALOG_TYPE(  7, PLAYER7, AD_STICK_Y,          "AD Stick Y 7",           SEQ_DEF_3(INDEXED(JOYCODE_Y, 6), SEQCODE_OR, INDEXED(MOUSECODE_Y, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 6)) )
478   INPUT_PORT_ANALOG_TYPE(  8, PLAYER8, AD_STICK_Y,          "AD Stick Y 8",           SEQ_DEF_3(INDEXED(JOYCODE_Y, 7), SEQCODE_OR, INDEXED(MOUSECODE_Y, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 7)) )
479
480   INPUT_PORT_ANALOG_TYPE(  1, PLAYER1, AD_STICK_Z,          "AD Stick Z",             SEQ_DEF_1(INDEXED(JOYCODE_Z, 0)), SEQ_DEF_0, SEQ_DEF_0 )
481   INPUT_PORT_ANALOG_TYPE(  2, PLAYER2, AD_STICK_Z,          "AD Stick Z 2",           SEQ_DEF_1(INDEXED(JOYCODE_Z, 1)), SEQ_DEF_0, SEQ_DEF_0 )
482   INPUT_PORT_ANALOG_TYPE(  3, PLAYER3, AD_STICK_Z,          "AD Stick Z 3",           SEQ_DEF_1(INDEXED(JOYCODE_Z, 2)), SEQ_DEF_0, SEQ_DEF_0 )
483   INPUT_PORT_ANALOG_TYPE(  4, PLAYER4, AD_STICK_Z,          "AD Stick Z 4",           SEQ_DEF_1(INDEXED(JOYCODE_Z, 3)), SEQ_DEF_0, SEQ_DEF_0 )
484   INPUT_PORT_ANALOG_TYPE(  5, PLAYER5, AD_STICK_Z,          "AD Stick Z 5",           SEQ_DEF_1(INDEXED(JOYCODE_Z, 4)), SEQ_DEF_0, SEQ_DEF_0 )
485   INPUT_PORT_ANALOG_TYPE(  6, PLAYER6, AD_STICK_Z,          "AD Stick Z 6",           SEQ_DEF_1(INDEXED(JOYCODE_Z, 5)), SEQ_DEF_0, SEQ_DEF_0 )
486   INPUT_PORT_ANALOG_TYPE(  7, PLAYER7, AD_STICK_Z,          "AD Stick Z 7",           SEQ_DEF_1(INDEXED(JOYCODE_Z, 6)), SEQ_DEF_0, SEQ_DEF_0 )
487   INPUT_PORT_ANALOG_TYPE(  8, PLAYER8, AD_STICK_Z,          "AD Stick Z 8",           SEQ_DEF_1(INDEXED(JOYCODE_Z, 7)), SEQ_DEF_0, SEQ_DEF_0 )
488
489   INPUT_PORT_ANALOG_TYPE(  1, PLAYER1, LIGHTGUN_X,          "Lightgun X",             SEQ_DEF_5(INDEXED(GUNCODE_X, 0), SEQCODE_OR, INDEXED(MOUSECODE_X, 0), SEQCODE_OR, INDEXED(JOYCODE_X, 0)), SEQ_DEF_3(KEYCODE_LEFT, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)), SEQ_DEF_3(KEYCODE_RIGHT, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
490   INPUT_PORT_ANALOG_TYPE(  2, PLAYER2, LIGHTGUN_X,          "Lightgun X 2",           SEQ_DEF_5(INDEXED(GUNCODE_X, 1), SEQCODE_OR, INDEXED(MOUSECODE_X, 1), SEQCODE_OR, INDEXED(JOYCODE_X, 1)), SEQ_DEF_3(KEYCODE_D, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 1)), SEQ_DEF_3(KEYCODE_G, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 1)) )
491   INPUT_PORT_ANALOG_TYPE(  3, PLAYER3, LIGHTGUN_X,          "Lightgun X 3",           SEQ_DEF_5(INDEXED(GUNCODE_X, 2), SEQCODE_OR, INDEXED(MOUSECODE_X, 2), SEQCODE_OR, INDEXED(JOYCODE_X, 2)), SEQ_DEF_3(KEYCODE_J, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 2)), SEQ_DEF_3(KEYCODE_L, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 2)) )
492   INPUT_PORT_ANALOG_TYPE(  4, PLAYER4, LIGHTGUN_X,          "Lightgun X 4",           SEQ_DEF_5(INDEXED(GUNCODE_X, 3), SEQCODE_OR, INDEXED(MOUSECODE_X, 3), SEQCODE_OR, INDEXED(JOYCODE_X, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 3)) )
493   INPUT_PORT_ANALOG_TYPE(  5, PLAYER5, LIGHTGUN_X,          "Lightgun X 5",           SEQ_DEF_5(INDEXED(GUNCODE_X, 4), SEQCODE_OR, INDEXED(MOUSECODE_X, 4), SEQCODE_OR, INDEXED(JOYCODE_X, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 4)) )
494   INPUT_PORT_ANALOG_TYPE(  6, PLAYER6, LIGHTGUN_X,          "Lightgun X 6",           SEQ_DEF_5(INDEXED(GUNCODE_X, 5), SEQCODE_OR, INDEXED(MOUSECODE_X, 5), SEQCODE_OR, INDEXED(JOYCODE_X, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 5)) )
495   INPUT_PORT_ANALOG_TYPE(  7, PLAYER7, LIGHTGUN_X,          "Lightgun X 7",           SEQ_DEF_5(INDEXED(GUNCODE_X, 6), SEQCODE_OR, INDEXED(MOUSECODE_X, 6), SEQCODE_OR, INDEXED(JOYCODE_X, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 6)) )
496   INPUT_PORT_ANALOG_TYPE(  8, PLAYER8, LIGHTGUN_X,          "Lightgun X 8",           SEQ_DEF_5(INDEXED(GUNCODE_X, 7), SEQCODE_OR, INDEXED(MOUSECODE_X, 7), SEQCODE_OR, INDEXED(JOYCODE_X, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 7)) )
497
498   INPUT_PORT_ANALOG_TYPE(  1, PLAYER1, LIGHTGUN_Y,          "Lightgun Y",             SEQ_DEF_5(INDEXED(GUNCODE_Y, 0), SEQCODE_OR, INDEXED(MOUSECODE_Y, 0), SEQCODE_OR, INDEXED(JOYCODE_Y, 0)), SEQ_DEF_3(KEYCODE_UP, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)), SEQ_DEF_3(KEYCODE_DOWN, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
499   INPUT_PORT_ANALOG_TYPE(  2, PLAYER2, LIGHTGUN_Y,          "Lightgun Y 2",           SEQ_DEF_5(INDEXED(GUNCODE_Y, 1), SEQCODE_OR, INDEXED(MOUSECODE_Y, 1), SEQCODE_OR, INDEXED(JOYCODE_Y, 1)), SEQ_DEF_3(KEYCODE_R, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 1)), SEQ_DEF_3(KEYCODE_F, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 1)) )
500   INPUT_PORT_ANALOG_TYPE(  3, PLAYER3, LIGHTGUN_Y,          "Lightgun Y 3",           SEQ_DEF_5(INDEXED(GUNCODE_Y, 2), SEQCODE_OR, INDEXED(MOUSECODE_Y, 2), SEQCODE_OR, INDEXED(JOYCODE_Y, 2)), SEQ_DEF_3(KEYCODE_I, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 2)), SEQ_DEF_3(KEYCODE_K, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 2)) )
501   INPUT_PORT_ANALOG_TYPE(  4, PLAYER4, LIGHTGUN_Y,          "Lightgun Y 4",           SEQ_DEF_5(INDEXED(GUNCODE_Y, 3), SEQCODE_OR, INDEXED(MOUSECODE_Y, 3), SEQCODE_OR, INDEXED(JOYCODE_Y, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 3)) )
502   INPUT_PORT_ANALOG_TYPE(  5, PLAYER5, LIGHTGUN_Y,          "Lightgun Y 5",           SEQ_DEF_5(INDEXED(GUNCODE_Y, 4), SEQCODE_OR, INDEXED(MOUSECODE_Y, 4), SEQCODE_OR, INDEXED(JOYCODE_Y, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 4)) )
503   INPUT_PORT_ANALOG_TYPE(  6, PLAYER6, LIGHTGUN_Y,          "Lightgun Y 6",           SEQ_DEF_5(INDEXED(GUNCODE_Y, 5), SEQCODE_OR, INDEXED(MOUSECODE_Y, 5), SEQCODE_OR, INDEXED(JOYCODE_Y, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 5)) )
504   INPUT_PORT_ANALOG_TYPE(  7, PLAYER7, LIGHTGUN_Y,          "Lightgun Y 7",           SEQ_DEF_5(INDEXED(GUNCODE_Y, 6), SEQCODE_OR, INDEXED(MOUSECODE_Y, 6), SEQCODE_OR, INDEXED(JOYCODE_Y, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 6)) )
505   INPUT_PORT_ANALOG_TYPE(  8, PLAYER8, LIGHTGUN_Y,          "Lightgun Y 8",           SEQ_DEF_5(INDEXED(GUNCODE_Y, 7), SEQCODE_OR, INDEXED(MOUSECODE_Y, 7), SEQCODE_OR, INDEXED(JOYCODE_Y, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 7)) )
506
507   INPUT_PORT_ANALOG_TYPE(  1, PLAYER1, MOUSE_X,             "Mouse X",                SEQ_DEF_1(INDEXED(MOUSECODE_X, 0)), SEQ_DEF_3(KEYCODE_LEFT, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)), SEQ_DEF_3(KEYCODE_RIGHT, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
508   INPUT_PORT_ANALOG_TYPE(  2, PLAYER2, MOUSE_X,             "Mouse X 2",              SEQ_DEF_1(INDEXED(MOUSECODE_X, 1)), SEQ_DEF_3(KEYCODE_D, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 1)), SEQ_DEF_3(KEYCODE_G, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 1)) )
509   INPUT_PORT_ANALOG_TYPE(  3, PLAYER3, MOUSE_X,             "Mouse X 3",              SEQ_DEF_1(INDEXED(MOUSECODE_X, 2)), SEQ_DEF_3(KEYCODE_J, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 2)), SEQ_DEF_3(KEYCODE_L, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 2)) )
510   INPUT_PORT_ANALOG_TYPE(  4, PLAYER4, MOUSE_X,             "Mouse X 4",              SEQ_DEF_1(INDEXED(MOUSECODE_X, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 3)) )
511   INPUT_PORT_ANALOG_TYPE(  5, PLAYER5, MOUSE_X,             "Mouse X 5",              SEQ_DEF_1(INDEXED(MOUSECODE_X, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 4)) )
512   INPUT_PORT_ANALOG_TYPE(  6, PLAYER6, MOUSE_X,             "Mouse X 6",              SEQ_DEF_1(INDEXED(MOUSECODE_X, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 5)) )
513   INPUT_PORT_ANALOG_TYPE(  7, PLAYER7, MOUSE_X,             "Mouse X 7",              SEQ_DEF_1(INDEXED(MOUSECODE_X, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 6)) )
514   INPUT_PORT_ANALOG_TYPE(  8, PLAYER8, MOUSE_X,             "Mouse X 8",              SEQ_DEF_1(INDEXED(MOUSECODE_X, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_LEFT_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_X_RIGHT_SWITCH, 7)) )
515
516   INPUT_PORT_ANALOG_TYPE(  1, PLAYER1, MOUSE_Y,             "Mouse Y",                SEQ_DEF_1(INDEXED(MOUSECODE_Y, 0)), SEQ_DEF_3(KEYCODE_UP, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)), SEQ_DEF_3(KEYCODE_DOWN, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
517   INPUT_PORT_ANALOG_TYPE(  2, PLAYER2, MOUSE_Y,             "Mouse Y 2",              SEQ_DEF_1(INDEXED(MOUSECODE_Y, 1)), SEQ_DEF_3(KEYCODE_R, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 1)), SEQ_DEF_3(KEYCODE_F, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 1)) )
518   INPUT_PORT_ANALOG_TYPE(  3, PLAYER3, MOUSE_Y,             "Mouse Y 3",              SEQ_DEF_1(INDEXED(MOUSECODE_Y, 2)), SEQ_DEF_3(KEYCODE_I, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 2)), SEQ_DEF_3(KEYCODE_K, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 2)) )
519   INPUT_PORT_ANALOG_TYPE(  4, PLAYER4, MOUSE_Y,             "Mouse Y 4",              SEQ_DEF_1(INDEXED(MOUSECODE_Y, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 3)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 3)) )
520   INPUT_PORT_ANALOG_TYPE(  5, PLAYER5, MOUSE_Y,             "Mouse Y 5",              SEQ_DEF_1(INDEXED(MOUSECODE_Y, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 4)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 4)) )
521   INPUT_PORT_ANALOG_TYPE(  6, PLAYER6, MOUSE_Y,             "Mouse Y 6",              SEQ_DEF_1(INDEXED(MOUSECODE_Y, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 5)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 5)) )
522   INPUT_PORT_ANALOG_TYPE(  7, PLAYER7, MOUSE_Y,             "Mouse Y 7",              SEQ_DEF_1(INDEXED(MOUSECODE_Y, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 6)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 6)) )
523   INPUT_PORT_ANALOG_TYPE(  8, PLAYER8, MOUSE_Y,             "Mouse Y 8",              SEQ_DEF_1(INDEXED(MOUSECODE_Y, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_UP_SWITCH, 7)), SEQ_DEF_1(INDEXED(JOYCODE_Y_DOWN_SWITCH, 7)) )
524
525   INPUT_PORT_DIGITAL_TYPE( 0, OTHER,   KEYBOARD,            "Keyboard",               SEQ_DEF_0 )
526
527   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_ON_SCREEN_DISPLAY,"On Screen Display",      SEQ_DEF_1(KEYCODE_TILDE) )
528   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_DEBUG_BREAK,      "Break in Debugger",      SEQ_DEF_1(KEYCODE_TILDE) )
529   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_CONFIGURE,        "Config Menu",            SEQ_DEF_1(KEYCODE_TAB) )
530   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_PAUSE,            "Pause",                  SEQ_DEF_1(KEYCODE_P) )
531   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_RESET_MACHINE,    "Reset Game",             SEQ_DEF_2(KEYCODE_F3, KEYCODE_LSHIFT) )
532   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_SOFT_RESET,       "Soft Reset",             SEQ_DEF_3(KEYCODE_F3, SEQCODE_NOT, KEYCODE_LSHIFT) )
533   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_SHOW_GFX,         "Show Gfx",               SEQ_DEF_1(KEYCODE_F4) )
534   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_FRAMESKIP_DEC,    "Frameskip Dec",          SEQ_DEF_1(KEYCODE_F8) )
535   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_FRAMESKIP_INC,    "Frameskip Inc",          SEQ_DEF_1(KEYCODE_F9) )
536   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_THROTTLE,         "Throttle",               SEQ_DEF_1(KEYCODE_F10) )
537   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_FAST_FORWARD,     "Fast Forward",           SEQ_DEF_1(KEYCODE_INSERT) )
538   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_SHOW_FPS,         "Show FPS",               SEQ_DEF_5(KEYCODE_F11, SEQCODE_NOT, KEYCODE_LCONTROL, SEQCODE_NOT, KEYCODE_LSHIFT) )
539   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_SNAPSHOT,         "Save Snapshot",          SEQ_DEF_3(KEYCODE_F12, SEQCODE_NOT, KEYCODE_LSHIFT) )
540   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_RECORD_MOVIE,     "Record Movie",           SEQ_DEF_2(KEYCODE_F12, KEYCODE_LSHIFT) )
541   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_TOGGLE_CHEAT,     "Toggle Cheat",           SEQ_DEF_1(KEYCODE_F6) )
542   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_UP,               "UI Up",                  SEQ_DEF_3(KEYCODE_UP, SEQCODE_OR, INDEXED(JOYCODE_Y_UP_SWITCH, 0)) )
543   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_DOWN,             "UI Down",                SEQ_DEF_3(KEYCODE_DOWN, SEQCODE_OR, INDEXED(JOYCODE_Y_DOWN_SWITCH, 0)) )
544   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_LEFT,             "UI Left",                SEQ_DEF_3(KEYCODE_LEFT, SEQCODE_OR, INDEXED(JOYCODE_X_LEFT_SWITCH, 0)) )
545   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_RIGHT,            "UI Right",               SEQ_DEF_3(KEYCODE_RIGHT, SEQCODE_OR, INDEXED(JOYCODE_X_RIGHT_SWITCH, 0)) )
546   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_HOME,             "UI Home",                SEQ_DEF_1(KEYCODE_HOME) )
547   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_END,              "UI End",                 SEQ_DEF_1(KEYCODE_END) )
548   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_PAGE_UP,          "UI Page Up",             SEQ_DEF_1(KEYCODE_PGUP) )
549   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_PAGE_DOWN,        "UI Page Down",           SEQ_DEF_1(KEYCODE_PGDN) )
550   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_SELECT,           "UI Select",              SEQ_DEF_3(KEYCODE_ENTER, SEQCODE_OR, INDEXED(JOYCODE_BUTTON1, 0)) )
551   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_CANCEL,           "UI Cancel",              SEQ_DEF_1(KEYCODE_ESC) )
552   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_CLEAR,            "UI Clear",               SEQ_DEF_1(KEYCODE_DEL) )
553   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_ZOOM_IN,          "UI Zoom In",             SEQ_DEF_1(KEYCODE_EQUALS) )
554   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_ZOOM_OUT,         "UI Zoom Out",            SEQ_DEF_1(KEYCODE_MINUS) )
555   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_PREV_GROUP,       "UI Previous Group",      SEQ_DEF_1(KEYCODE_OPENBRACE) )
556   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_NEXT_GROUP,       "UI Next Group",          SEQ_DEF_1(KEYCODE_CLOSEBRACE) )
557   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_ROTATE,           "UI Rotate",              SEQ_DEF_1(KEYCODE_R) )
558   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_SHOW_PROFILER,    "Show Profiler",          SEQ_DEF_2(KEYCODE_F11, KEYCODE_LSHIFT) )
559#ifdef MESS
560   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_TOGGLE_UI,        "UI Toggle",              SEQ_DEF_3(KEYCODE_SCRLOCK, SEQCODE_NOT, KEYCODE_LSHIFT) )
561   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_PASTE,            "UI Paste Text",          SEQ_DEF_2(KEYCODE_SCRLOCK, KEYCODE_LSHIFT) )
562#endif /* MESS */
563   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_TOGGLE_DEBUG,     "Toggle Debugger",        SEQ_DEF_1(KEYCODE_F5) )
564   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_SAVE_STATE,       "Save State",             SEQ_DEF_2(KEYCODE_F7, KEYCODE_LSHIFT) )
565   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_LOAD_STATE,       "Load State",             SEQ_DEF_3(KEYCODE_F7, SEQCODE_NOT, KEYCODE_LSHIFT) )
566   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_ADD_CHEAT,        "Add Cheat",              SEQ_DEF_1(KEYCODE_A) )
567   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_DELETE_CHEAT,     "Delete Cheat",           SEQ_DEF_1(KEYCODE_D) )
568   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_SAVE_CHEAT,       "Save Cheat",             SEQ_DEF_1(KEYCODE_S) )
569   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_WATCH_VALUE,      "Watch Value",            SEQ_DEF_1(KEYCODE_W) )
570   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_EDIT_CHEAT,       "Edit Cheat",             SEQ_DEF_1(KEYCODE_E) )
571   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_RELOAD_CHEAT,     "Reload Database",        SEQ_DEF_1(KEYCODE_L) )
572   INPUT_PORT_DIGITAL_TYPE( 0, UI,      UI_TOGGLE_CROSSHAIR, "Toggle Crosshair",       SEQ_DEF_1(KEYCODE_F1) )
573
574   INPUT_PORT_DIGITAL_TYPE( 0, UI,      OSD_1,               NULL,                     SEQ_DEF_0 )
575   INPUT_PORT_DIGITAL_TYPE( 0, UI,      OSD_2,               NULL,                     SEQ_DEF_0 )
576   INPUT_PORT_DIGITAL_TYPE( 0, UI,      OSD_3,               NULL,                     SEQ_DEF_0 )
577   INPUT_PORT_DIGITAL_TYPE( 0, UI,      OSD_4,               NULL,                     SEQ_DEF_0 )
578   INPUT_PORT_DIGITAL_TYPE( 0, UI,      OSD_5,               NULL,                     SEQ_DEF_0 )
579   INPUT_PORT_DIGITAL_TYPE( 0, UI,      OSD_6,               NULL,                     SEQ_DEF_0 )
580   INPUT_PORT_DIGITAL_TYPE( 0, UI,      OSD_7,               NULL,                     SEQ_DEF_0 )
581   INPUT_PORT_DIGITAL_TYPE( 0, UI,      OSD_8,               NULL,                     SEQ_DEF_0 )
582   INPUT_PORT_DIGITAL_TYPE( 0, UI,      OSD_9,               NULL,                     SEQ_DEF_0 )
583   INPUT_PORT_DIGITAL_TYPE( 0, UI,      OSD_10,              NULL,                     SEQ_DEF_0 )
584   INPUT_PORT_DIGITAL_TYPE( 0, UI,      OSD_11,              NULL,                     SEQ_DEF_0 )
585   INPUT_PORT_DIGITAL_TYPE( 0, UI,      OSD_12,              NULL,                     SEQ_DEF_0 )
586   INPUT_PORT_DIGITAL_TYPE( 0, UI,      OSD_13,              NULL,                     SEQ_DEF_0 )
587   INPUT_PORT_DIGITAL_TYPE( 0, UI,      OSD_14,              NULL,                     SEQ_DEF_0 )
588   INPUT_PORT_DIGITAL_TYPE( 0, UI,      OSD_15,              NULL,                     SEQ_DEF_0 )
589   INPUT_PORT_DIGITAL_TYPE( 0, UI,      OSD_16,              NULL,                     SEQ_DEF_0 )
590   INPUT_PORT_DIGITAL_TYPE( 0, INVALID, UNKNOWN,             NULL,                     SEQ_DEF_0 )
591   INPUT_PORT_DIGITAL_TYPE( 0, INVALID, UNUSED,              NULL,                     SEQ_DEF_0 )
592   INPUT_PORT_DIGITAL_TYPE( 0, INVALID, SPECIAL,             NULL,                     SEQ_DEF_0 )
593   INPUT_PORT_DIGITAL_TYPE( 0, INVALID, OTHER,               NULL,                     SEQ_DEF_0 )
594   INPUT_PORT_DIGITAL_TYPE( 0, INVALID, ADJUSTER,            NULL,                     SEQ_DEF_0 )
595   INPUT_PORT_DIGITAL_TYPE( 0, INVALID, DIPSWITCH,           NULL,                     SEQ_DEF_0 )
596   INPUT_PORT_DIGITAL_TYPE( 0, INVALID, CONFIG,              NULL,                     SEQ_DEF_0 )
597   INPUT_PORT_DIGITAL_TYPE( 0, INVALID, CATEGORY,            NULL,                     SEQ_DEF_0 )
598};
src/emu/machine/6526cia.c
r2724r2725
7474{
7575   int            active;
7676   cia_type_t      type;
77   void         (*irq_func)(int state);
77   void         (*irq_func)(running_machine *machine, int state);
7878   int            clock;
7979
8080   cia_port      port[2];
r2724r2725
298298   {
299299      cia->irq = new_irq;
300300      if (cia->irq_func)
301         cia->irq_func(cia->irq);
301         cia->irq_func(Machine, cia->irq);
302302   }
303303}
304304
src/emu/machine/53c810.c
r2724r2725
11/* LSI Logic LSI53C810A PCI to SCSI I/O Processor */
22
33#include "driver.h"
4#include "deprecat.h"
45#include "53c810.h"
56
67#define DMA_MAX_ICOUNT   512      /* Maximum number of DMA Scripts opcodes to run */
r2724r2725
4142   int halted;
4243   int carry;
4344   UINT32 (* fetch)(UINT32 dsp);
44   void (* irq_callback)(void);
45   void (* irq_callback)(running_machine *machine);
4546   void (* dma_callback)(UINT32, UINT32, int, int);
4647} lsi810;
4748
r2724r2725
9495   lsi810.dstat |= 0x4;   /* SIR (SCRIPTS Interrupt Instruction Received) */
9596
9697   if(intf->irq_callback != NULL) {
97      intf->irq_callback();
98      intf->irq_callback(Machine);
9899   }
99100   lsi810.dma_icount = 0;
100101   lsi810.halted = 1;
r2724r2725
518519   return 0;
519520}
520521
521void lsi53c810_reg_w(int reg, UINT8 value)
522void lsi53c810_reg_w(running_machine *machine, int reg, UINT8 value)
522523{
523524   logerror("53c810: %02x to reg %d:0x%x (PC=%x)\n", value, reg, reg, activecpu_get_pc());
524525   switch(reg)
r2724r2725
614615            lsi810.istat |= 0x3;   /* DMA interrupt pending */
615616            lsi810.dstat |= 0x8;   /* SSI (Single Step Interrupt) */
616617            if(intf->irq_callback != NULL) {
617               intf->irq_callback();
618               intf->irq_callback(machine);
618619            }
619620         }
620621         else if(lsi810.dcntl & 0x04 && !lsi810.halted)   /* manual start DMA */
src/emu/machine/6526cia.h
r2724r2725
2020struct _cia6526_interface
2121{
2222   cia_type_t type;
23   void (*irq_func)(int state);
23   void (*irq_func)(running_machine *machine, int state);
2424   int clock;
2525   int tod_clock;
2626
src/emu/machine/53c810.h
r2724r2725
66struct LSI53C810interface
77{
88   const SCSIConfigTable *scsidevs;         /* SCSI devices */
9   void (*irq_callback)(void);         /* IRQ callback */
9   void (*irq_callback)(running_machine *machine); /* IRQ callback */
1010   void (*dma_callback)(UINT32, UINT32, int, int);   /* DMA callback */
1111   UINT32 (*fetch)(UINT32 dsp);
1212};
r2724r2725
2020extern void *lsi53c810_get_device(int id);
2121
2222UINT8 lsi53c810_reg_r(int reg);
23void lsi53c810_reg_w(int reg, UINT8 value);
23void lsi53c810_reg_w(running_machine *machine, int reg, UINT8 value);
2424
2525unsigned lsi53c810_dasm(char *buf, UINT32 pc);
2626
src/emu/machine/6821pia.c
r2724r2725
195195      pias[i].in_ca2 = TRUE;
196196
197197      /* clear the IRQs */
198      if (intf->irq_a_func) (*intf->irq_a_func)(FALSE);
199      if (intf->irq_b_func) (*intf->irq_b_func)(FALSE);
198      if (intf->irq_a_func) (*intf->irq_a_func)(Machine, FALSE);
199      if (intf->irq_b_func) (*intf->irq_b_func)(Machine, FALSE);
200200   }
201201}
202202
r2724r2725
219219   {
220220      p->irq_a_state = new_state;
221221
222      if (p->intf->irq_a_func) (p->intf->irq_a_func)(p->irq_a_state);
222      if (p->intf->irq_a_func) (p->intf->irq_a_func)(Machine, p->irq_a_state);
223223   }
224224
225225   /* then do IRQ B */
r2724r2725
229229   {
230230      p->irq_b_state = new_state;
231231
232      if (p->intf->irq_b_func) (p->intf->irq_b_func)(p->irq_b_state);
232      if (p->intf->irq_b_func) (p->intf->irq_b_func)(Machine, p->irq_b_state);
233233   }
234234}
235235
src/emu/machine/68681.c
r2724r2725
8585   // callbacks
8686   UINT8 (*input_port_read)(void);
8787   void  (*tx_callback)(int channel, UINT8 data);
88   void  (*irq_handler)(UINT8 vector);
88   void  (*irq_handler)(running_machine *machine, int vector);
8989
9090   DUART_68681_CHANNEL channel[2];
9191} DUART_68681;
9292
9393static DUART_68681 duart_68681;
9494
95static void duart_68681_update_interrupts( void )
95static void duart_68681_update_interrupts( running_machine *machine )
9696{
9797   if ( (duart_68681.ISR & duart_68681.IMR) != 0 )
9898   {
9999      if ( duart_68681.irq_handler )
100100      {
101         duart_68681.irq_handler( duart_68681.IVR );
101         duart_68681.irq_handler( machine, duart_68681.IVR );
102102      }
103103   }
104104};
r2724r2725
192192   }
193193};
194194
195static UINT8 duart_68681_read_rx_fifo( int ch )
195static UINT8 duart_68681_read_rx_fifo( running_machine *machine, int ch )
196196{
197197   UINT8 r;
198198
r2724r2725
234234         duart_68681.ISR &= ~INT_RXRDY_FFULLB;
235235      }
236236   }
237   duart_68681_update_interrupts();
237   duart_68681_update_interrupts(machine);
238238   return r;
239239};
240240
r2724r2725
253253   else
254254      duart_68681.ISR |= INT_TXRDYB;
255255
256   duart_68681_update_interrupts();
256   duart_68681_update_interrupts(machine);
257257   timer_adjust_oneshot(duart_68681.channel[ch].tx_timer, attotime_never, ch);
258258};
259259
260static void duart_68681_write_TX(int ch, UINT8 data)
260static void duart_68681_write_TX(running_machine *machine, int ch, UINT8 data)
261261{
262262   attotime period;
263263
r2724r2725
271271   else
272272      duart_68681.ISR &= ~INT_TXRDYB;
273273
274   duart_68681_update_interrupts();
274   duart_68681_update_interrupts(machine);
275275
276276   period = ATTOTIME_IN_HZ(duart_68681.channel[ch].baud_rate / 10 );
277277   timer_adjust_oneshot(duart_68681.channel[ch].tx_timer, period, ch);
r2724r2725
288288         r = duart_68681.channel[0].SR;
289289         break;
290290      case 0x03: /* Rx Holding Register A */
291         r = duart_68681_read_rx_fifo(0);
291         r = duart_68681_read_rx_fifo(machine, 0);
292292         break;
293293      case 0x04: /* IPCR */
294294         {
r2724r2725
301301            r = (((duart_68681.IP_last_state ^ IP) & 0x0f) << 4) | (IP & 0x0f);
302302            duart_68681.IP_last_state = IP;
303303            duart_68681.ISR &= ~INT_INPUT_PORT_CHANGE;
304            duart_68681_update_interrupts();
304            duart_68681_update_interrupts(machine);
305305         }
306306         break;
307307      case 0x09: /* SRB */
308308         r = duart_68681.channel[1].SR;
309309         break;
310310      case 0x0b: /* RHRB */
311         r = duart_68681_read_rx_fifo(1);
311         r = duart_68681_read_rx_fifo(machine, 1);
312312         break;
313313      default:
314314         logerror( "Reading unhandled 68681 reg %x\n", offset );
r2724r2725
332332         duart_68681_write_CR(0, data);
333333         break;
334334      case 0x03: /* THRA */
335         duart_68681_write_TX(0, data);
335         duart_68681_write_TX(machine, 0, data);
336336         break;
337337      case 0x04: /* ACR */
338338         duart_68681.ACR = data;
r2724r2725
356356         duart_68681_write_CR(1, data);
357357         break;
358358      case 0x0b: /* THRB */
359         duart_68681_write_TX(1, data);
359         duart_68681_write_TX(machine, 1, data);
360360         break;
361361      case 0x0c: /* IVR */
362362         duart_68681.IVR = data;
r2724r2725
376376   }
377377}
378378
379void duart_68681_rx_data( int ch, UINT8 data )
379void duart_68681_rx_data( running_machine *machine, int ch, UINT8 data )
380380{
381381   if ( duart_68681.channel[ch].rx_enabled )
382382   {
r2724r2725
405405            duart_68681.ISR |= (ch == 0) ? INT_RXRDY_FFULLA : INT_RXRDY_FFULLB;
406406         }
407407      }
408      duart_68681_update_interrupts();
408      duart_68681_update_interrupts(machine);
409409   }
410410};
411411
412void duart_68681_init(int frequency, void (*irq_handler)(UINT8 vector), void (*tx_callback)(int channel, UINT8 data))
412void duart_68681_init(int frequency, void (*irq_handler)(running_machine *machine, int vector), void (*tx_callback)(int channel, UINT8 data))
413413{
414414   memset(&duart_68681, 0, sizeof(duart_68681));
415415
src/emu/machine/6532riot.c
r2724r2725
5858   {
5959      r6532[which].timer_irq = 1;
6060      if (r6532[which].intf->irq_func)
61         (*r6532[which].intf->irq_func)(ASSERT_LINE);
61         (*r6532[which].intf->irq_func)(machine, ASSERT_LINE);
6262      else
6363         logerror("6532RIOT chip #%d: Interrupt is asserted but there is no callback function.  PC: %08X\n", which, safe_activecpu_get_pc());
6464   }
r2724r2725
7373      if (r6532[which].pa7_enable)
7474      {
7575         if (r6532[which].intf->irq_func)
76            (*r6532[which].intf->irq_func)(ASSERT_LINE);
76            (*r6532[which].intf->irq_func)(Machine, ASSERT_LINE);
7777         else
7878            logerror("6532RIOT chip #%d: Interrupt is asserted but there is no callback function.  PC: %08X\n", which, safe_activecpu_get_pc());
7979      }
r2724r2725
166166      if (timer_cycles_left != -1)
167167      {
168168         if (r6532[which].intf->irq_func && r6532[which].timer_irq)
169            (*r6532[which].intf->irq_func)(CLEAR_LINE);
169            (*r6532[which].intf->irq_func)(Machine, CLEAR_LINE);
170170         else
171171            logerror("6532RIOT chip #%d: Interrupt is cleared but there is no callback function.  PC: %08X\n", which, safe_activecpu_get_pc());
172172
r2724r2725
204204      if ( timer_cycles_left < -1 )
205205      {
206206         if ( r6532[which].intf->irq_func)
207            (*r6532[which].intf->irq_func)(CLEAR_LINE);
207            (*r6532[which].intf->irq_func)(Machine, CLEAR_LINE);
208208         else
209209            logerror("6532RIOT chip #%d: Interrupt is cleared but there is no callback function.  PC: %08X\n", which, safe_activecpu_get_pc());
210210
r2724r2725
219219      r6532[which].pa7_flag = 0;
220220
221221      if (r6532[which].intf->irq_func && timer_cycles_left != -1)
222         (*r6532[which].intf->irq_func)(CLEAR_LINE);
222         (*r6532[which].intf->irq_func)(Machine, CLEAR_LINE);
223223      else
224224         logerror("6532RIOT chip #%d: Interrupt is cleared but there is no callback function.  PC: %08X\n", which, safe_activecpu_get_pc());
225225   }
r2724r2725
300300   r6532[which].timer_irq = 0;
301301
302302   if (r6532[which].intf->irq_func)
303      (*r6532[which].intf->irq_func)(CLEAR_LINE);
303      (*r6532[which].intf->irq_func)(Machine, CLEAR_LINE);
304304   else
305305      logerror("6532RIOT chip #%d: Interrupt is cleared but there is no callback function.  PC: %08X\n", which, safe_activecpu_get_pc());
306306}
src/emu/machine/6522via.c
r2724r2725
185185    {
186186      v->ifr |= INT_ANY;
187187      if (v->intf->irq_func)
188         (*v->intf->irq_func)(ASSERT_LINE);
188         (*v->intf->irq_func)(Machine, ASSERT_LINE);
189189      else
190190         logerror("6522VIA chip %d: Interrupt is asserted but there is no callback function.  PC: %08X\n", which, safe_activecpu_get_pc());
191191    }
r2724r2725
206206   else
207207   {
208208      if (v->intf->irq_func)
209         (*v->intf->irq_func)(CLEAR_LINE);
209         (*v->intf->irq_func)(Machine, CLEAR_LINE);
210210//      else
211211//          logerror("6522VIA chip %d: Interrupt is cleared but there is no callback function.  PC: %08X\n", which, safe_activecpu_get_pc());
212212   }
r2724r2725
821821         {
822822            v->ifr &= ~INT_ANY;
823823            if (v->intf->irq_func)
824               (*v->intf->irq_func)(CLEAR_LINE);
824               (*v->intf->irq_func)(Machine, CLEAR_LINE);
825825//              else
826826//                  logerror("6522VIA chip %d: Interrupt is cleared but there is no callback function.  PC: %08X\n", which, safe_activecpu_get_pc());
827827         }
r2724r2725
832832         {
833833            v->ifr |= INT_ANY;
834834            if (v->intf->irq_func)
835               (*v->intf->irq_func)(ASSERT_LINE);
835               (*v->intf->irq_func)(Machine, ASSERT_LINE);
836836            else
837837               logerror("6522VIA chip %d: Interrupt is asserted but there is no callback function.  PC: %08X\n", which, safe_activecpu_get_pc());
838838         }
src/emu/machine/6821pia.h
r2724r2725
4040   write8_machine_func out_b_func;
4141   write8_machine_func out_ca2_func;
4242   write8_machine_func out_cb2_func;
43   void (*irq_a_func)(int state);
44   void (*irq_b_func)(int state);
43   void (*irq_a_func)(running_machine *machine, int state);
44   void (*irq_b_func)(running_machine *machine, int state);
4545};
4646
4747
src/emu/machine/wd33c93.c
r2724r2725
235235   }
236236}
237237
238static void wd33c93_complete_immediate( int status )
238static void wd33c93_complete_immediate( running_machine *machine, int status )
239239{
240240   /* reset our timer */
241241   timer_reset( scsi_data.cmd_timer, attotime_never );
r2724r2725
264264   /* if we have a callback, call it */
265265   if (intf && intf->irq_callback)
266266   {
267      intf->irq_callback(1);
267      intf->irq_callback(machine, 1);
268268   }
269269}
270270
271271static TIMER_CALLBACK(wd33c93_complete_cb)
272272{
273   wd33c93_complete_immediate( param );
273   wd33c93_complete_immediate( machine, param );
274274}
275275
276276static TIMER_CALLBACK(wd33c93_service_request)
277277{
278278   /* issue a message out request */
279   wd33c93_complete_immediate(CSR_SRV_REQ | scsi_data.busphase);
279   wd33c93_complete_immediate(machine, CSR_SRV_REQ | scsi_data.busphase);
280280}
281281
282282static TIMER_CALLBACK(wd33c93_deassert_cip)
r2724r2725
635635                  }
636636
637637                  /* complete the command */
638                  wd33c93_complete_immediate(CSR_XFER_DONE | scsi_data.busphase);
638                  wd33c93_complete_immediate(machine, CSR_XFER_DONE | scsi_data.busphase);
639639               }
640640            }
641641            else
r2724r2725
682682
683683            if (intf && intf->irq_callback)
684684            {
685               intf->irq_callback(0);
685               intf->irq_callback(machine, 0);
686686            }
687687
688688            LOG(( "WD33C93: PC=%08x - Status read (%02x)\n", safe_activecpu_get_pc(), scsi_data.regs[WD_SCSI_STATUS] ));
src/emu/machine/68681.h
r2724r2725
11#ifndef _68681_H
22#define _68681_H
33
4void duart_68681_init(int frequency, void (*irq_handler)(UINT8 vector), void (*tx_callback)(int channel, UINT8 data));
5void duart_68681_rx_data( int ch, UINT8 data );
4void duart_68681_init(int frequency, void (*irq_handler)(running_machine *machine, int vector), void (*tx_callback)(int channel, UINT8 data));
5void duart_68681_rx_data( running_machine *machine, int ch, UINT8 data );
66
77READ16_HANDLER(duart_68681_r);
88WRITE16_HANDLER(duart_68681_w);
src/emu/machine/6532riot.h
r2724r2725
1515   read8_machine_func in_b_func;
1616   write8_machine_func out_a_func;
1717   write8_machine_func out_b_func;
18   void (*irq_func)(int state);
18   void (*irq_func)(running_machine *machine, int state);
1919};
2020
2121void r6532_set_clock(int which, int clock);
src/emu/machine/6522via.h
r2724r2725
4848   write8_machine_func out_cb1_func;
4949   write8_machine_func out_ca2_func;
5050   write8_machine_func out_cb2_func;
51   void (*irq_func)(int state);
51   void (*irq_func)(running_machine *machine, int state);
5252};
5353
5454void via_set_clock(int which,int clck);
src/emu/machine/wd33c93.h
r2724r2725
1111struct WD33C93interface
1212{
1313   const SCSIConfigTable *scsidevs;      /* SCSI devices */
14   void (*irq_callback)(int state);   /* irq callback */
14   void (*irq_callback)(running_machine *machine, int state); /* irq callback */
1515};
1616
1717extern void wd33c93_init( const struct WD33C93interface *interface );
src/emu/machine/6840ptm.c
r2724r2725
261261         currptr->status_reg &= ~0x80;
262262
263263      if (currptr->intf->irq_func)
264         (currptr->intf->irq_func)(currptr->IRQ);
264         (currptr->intf->irq_func)(Machine, currptr->IRQ);
265265   }
266266}
267267
src/emu/machine/6840ptm.h
r2724r2725
2020
2121   write8_machine_func   out_func[3];   // function to call when output[idx] changes
2222
23   void (*irq_func)(int state);   // function called if IRQ line changes
23   void (*irq_func)(running_machine *machine, int state);   // function called if IRQ line changes
2424};
2525
2626void ptm6840_config( int which, const ptm6840_interface *intf);
src/emu/machine/am53cf96.c
r2724r2725
8787{
8888   scsi_regs[REG_IRQSTATE] = 8;   // indicate success
8989   scsi_regs[REG_STATUS] |= 0x80;   // indicate IRQ
90   intf->irq_callback();
90   intf->irq_callback(machine);
9191}
9292
9393WRITE32_HANDLER( am53cf96_w )
src/emu/machine/am53cf96.h
r2724r2725
1111struct AM53CF96interface
1212{
1313   const SCSIConfigTable *scsidevs;   /* SCSI devices */
14   void (*irq_callback)(void);   /* irq callback */
14   void (*irq_callback)(running_machine *machine);   /* irq callback */
1515};
1616
1717extern void am53cf96_init( const struct AM53CF96interface *interface );
src/emu/machine/pc16552d.c
r2724r2725
5454{
5555   PC16552D_CHANNEL ch[2];
5656   int frequency;
57   void (* irq_handler)(int channel, int value);
57   void (* irq_handler)(running_machine *machine, int channel, int value);
5858   void (* tx_callback)(int channel, int count, UINT8* data);
5959} PC16552D_REGS;
6060
r2724r2725
6767static const int rx_trigger_level[4] = { 1, 4, 8, 14 };
6868
6969
70static void check_interrupts(int chip, int channel)
70static void check_interrupts(running_machine *machine, int chip, int channel)
7171{
7272   PC16552D_CHANNEL *ch = &duart[chip].ch[channel];
7373
r2724r2725
8080      {
8181         if (duart[chip].irq_handler != NULL)
8282         {
83            duart[chip].irq_handler(channel, 0);
83            duart[chip].irq_handler(machine, channel, 0);
8484         }
8585      }
8686   }
8787}
8888
89static void duart_push_rx_fifo(int chip, int channel, UINT8 data)
89static void duart_push_rx_fifo(running_machine *machine, int chip, int channel, UINT8 data)
9090{
9191   PC16552D_CHANNEL *ch = &duart[chip].ch[channel];
9292
r2724r2725
107107   {
108108      ch->pending_interrupt |= IRQ_RX_DATA_AVAILABLE;      // INT ID: received data available
109109
110      check_interrupts(chip, channel);
110      check_interrupts(machine, chip, channel);
111111   }
112112}
113113
114static UINT8 duart_pop_rx_fifo(int chip, int channel)
114static UINT8 duart_pop_rx_fifo(running_machine *machine, int chip, int channel)
115115{
116116   UINT8 r;
117117   PC16552D_CHANNEL *ch = &duart[chip].ch[channel];
r2724r2725
133133   {
134134      ch->pending_interrupt &= ~IRQ_RX_DATA_AVAILABLE;
135135
136      check_interrupts(chip, channel);
136      check_interrupts(machine, chip, channel);
137137   }
138138
139139   return r;
r2724r2725
154154
155155   // set transmitter empty interrupt
156156   ch->pending_interrupt |= IRQ_TX_HOLDING_REG_EMPTY;
157   check_interrupts(chip, channel);
157   check_interrupts(machine, chip, channel);
158158
159159   timer_adjust_oneshot(duart[chip].ch[channel].tx_fifo_timer, attotime_never, (chip * 2) + channel);
160160}
r2724r2725
180180#endif
181181
182182
183static UINT8 duart_r(int chip, int reg)
183static UINT8 duart_r(running_machine *machine, int chip, int reg)
184184{
185185   int channel = (reg >> 3) & 1;
186186   PC16552D_CHANNEL *ch = &duart[chip].ch[channel];
r2724r2725
202202            // Receiver Buffer
203203            ch->pending_interrupt &= ~IRQ_RX_DATA_AVAILABLE;
204204
205            check_interrupts(chip, channel);
205            check_interrupts(machine, chip, channel);
206206
207            return duart_pop_rx_fifo(chip, channel);
207            return duart_pop_rx_fifo(machine, chip, channel);
208208         }
209209      }
210210      case 1:
r2724r2725
288288   return ch->reg[reg];
289289}
290290
291static void duart_w(int chip, int reg, UINT8 data)
291static void duart_w(running_machine *machine, int chip, int reg, UINT8 data)
292292{
293293   int channel = (reg >> 3) & 1;
294294   PC16552D_CHANNEL *ch = &duart[chip].ch[channel];
r2724r2725
314314            duart_push_tx_fifo(chip, channel, data);
315315
316316            ch->pending_interrupt &= ~IRQ_TX_HOLDING_REG_EMPTY;
317            check_interrupts(chip, channel);
317            check_interrupts(machine, chip, channel);
318318
319319            return;
320320         }
r2724r2725
335335            // Interrupt enable
336336            ch->reg[REG_INT_ENABLE] = data;
337337
338            check_interrupts(chip, channel);
338            check_interrupts(machine, chip, channel);
339339            return;
340340         }
341341      }
r2724r2725
371371                    // cause transmitter empty IRQ
372372                    ch->pending_interrupt |= IRQ_TX_HOLDING_REG_EMPTY;
373373
374                    check_interrupts(chip, channel);
374                    check_interrupts(machine, chip, channel);
375375                }
376376                */
377377         }
r2724r2725
384384
385385/*****************************************************************************/
386386
387void pc16552d_init(int chip, int frequency, void (* irq_handler)(int channel, int value), void (* tx_callback)(int channel, int count, UINT8* data))
387void pc16552d_init(int chip, int frequency, void (* irq_handler)(running_machine *machine, int channel, int value), void (* tx_callback)(int channel, int count, UINT8* data))
388388{
389389   memset(&duart[chip], 0, sizeof(PC16552D_REGS));
390390
r2724r2725
404404   timer_adjust_oneshot(duart[chip].ch[1].tx_fifo_timer, attotime_never, (chip * 2) + 1);
405405}
406406
407void pc16552d_rx_data(int chip, int channel, UINT8 data)
407void pc16552d_rx_data(running_machine *machine, int chip, int channel, UINT8 data)
408408{
409409   if (duart[chip].ch[channel].reg[REG_FIFO_CTRL] & 0x01)   // RCVR & XMIT FIFO enable
410410   {
411      duart_push_rx_fifo(chip, channel, data);
411      duart_push_rx_fifo(machine, chip, channel, data);
412412   }
413413}
414414
r2724r2725
417417
418418READ8_HANDLER(pc16552d_0_r)
419419{
420   return duart_r(0, offset);
420   return duart_r(machine, 0, offset);
421421}
422422
423423WRITE8_HANDLER(pc16552d_0_w)
424424{
425   duart_w(0, offset, data);
425   duart_w(machine, 0, offset, data);
426426}
427427
428428READ8_HANDLER(pc16552d_1_r)
429429{
430   return duart_r(1, offset);
430   return duart_r(machine, 1, offset);
431431}
432432
433433WRITE8_HANDLER(pc16552d_1_w)
434434{
435   duart_w(1, offset, data);
435   duart_w(machine, 1, offset, data);
436436}
src/emu/machine/generic.c
r2724r2725
4646    FUNCTION PROTOTYPES
4747***************************************************************************/
4848
49static void counters_load(int config_type, xml_data_node *parentnode);
50static void counters_save(int config_type, xml_data_node *parentnode);
49static void counters_load(running_machine *machine, int config_type, xml_data_node *parentnode);
50static void counters_save(running_machine *machine, int config_type, xml_data_node *parentnode);
5151static void interrupt_reset(running_machine *machine);
5252
5353
r2724r2725
9393   state_save_register_item_array("cpu", 0, interrupt_enable);
9494
9595   /* register for configuration */
96   config_register("counters", counters_load, counters_save);
96   config_register(machine, "counters", counters_load, counters_save);
9797
9898   /* for memory cards, request save state and an exit callback */
9999   if (machine->config->memcard_handler != NULL)
r2724r2725
114114    and tickets
115115-------------------------------------------------*/
116116
117static void counters_load(int config_type, xml_data_node *parentnode)
117static void counters_load(running_machine *machine, int config_type, xml_data_node *parentnode)
118118{
119119   xml_data_node *coinnode, *ticketnode;
120120
r2724r2725
153153    and tickets
154154-------------------------------------------------*/
155155
156static void counters_save(int config_type, xml_data_node *parentnode)
156static void counters_save(running_machine *machine, int config_type, xml_data_node *parentnode)
157157{
158158   int i;
159159
src/emu/machine/pc16552d.h
r2724r2725
11#ifndef PC16552D_H
22#define PC16552D_H
33
4void pc16552d_init(int chip, int frequency, void (* irq_handler)(int channel, int value), void (* tx_callback)(int channel, int count, UINT8* data));
5void pc16552d_rx_data(int chip, int channel, UINT8 data);
4void pc16552d_init(int chip, int frequency, void (* irq_handler)(running_machine *machine, int channel, int value), void (* tx_callback)(int channel, int count, UINT8* data));
5void pc16552d_rx_data(running_machine *machine, int chip, int channel, UINT8 data);
66
77READ8_HANDLER(pc16552d_0_r);
88WRITE8_HANDLER(pc16552d_0_w);
src/emu/machine/smc91c9x.c
r2724r2725
114114
115115struct smc91c94_data
116116{
117   void (*irq_handler)(int state);
117   void (*irq_handler)(running_machine *machine, int state);
118118
119119   /* raw register data and masks */
120120   UINT16         reg[64];
r2724r2725
154154 *
155155 *************************************/
156156
157static void update_ethernet_irq(void);
157static void update_ethernet_irq(running_machine *machine);
158158
159159
160160
r2724r2725
177177 *
178178 *************************************/
179179
180void smc91c94_reset(void)
180void smc91c94_reset(running_machine *machine)
181181{
182   void (*saved_handler)(int) = ethernet.irq_handler;
182   void (*saved_handler)(running_machine *machine, int) = ethernet.irq_handler;
183183   memset(&ethernet, 0, sizeof(ethernet));
184184   ethernet.irq_handler = saved_handler;
185185
r2724r2725
215215   ethernet.reg[EREG_REVISION]      = 0x3340;   ethernet.regmask[EREG_REVISION]      = 0x0000;
216216   ethernet.reg[EREG_ERCV]         = 0x331f;   ethernet.regmask[EREG_ERCV]         = 0x009f;
217217
218   update_ethernet_irq();
218   update_ethernet_irq(machine);
219219}
220220
221221
r2724r2725
226226 *
227227 *************************************/
228228
229static void update_ethernet_irq(void)
229static void update_ethernet_irq(running_machine *machine)
230230{
231231   UINT8 mask = ethernet.reg[EREG_INTERRUPT] >> 8;
232232   UINT8 state = ethernet.reg[EREG_INTERRUPT] & 0xff;
r2724r2725
234234   /* update the IRQ state */
235235   ethernet.irq_state = ((mask & state) != 0);
236236   if (ethernet.irq_handler)
237      (*ethernet.irq_handler)(ethernet.irq_state ? ASSERT_LINE : CLEAR_LINE);
237      (*ethernet.irq_handler)(machine, ethernet.irq_state ? ASSERT_LINE : CLEAR_LINE);
238238}
239239
240240
r2724r2725
260260 *
261261 *************************************/
262262
263static void finish_enqueue(int param)
263static void finish_enqueue(running_machine *machine, int param)
264264{
265265   int is_broadcast = (ethernet.tx[4] == 0xff && ethernet.tx[5] == 0xff && ethernet.tx[6] == 0xff &&
266266                  ethernet.tx[7] == 0xff && ethernet.tx[8] == 0xff && ethernet.tx[9] == 0xff);
r2724r2725
320320         ethernet.reg[EREG_INTERRUPT] |= EINT_RCV;
321321         ethernet.reg[EREG_FIFO_PORTS] &= ~0x8000;
322322      }
323   update_ethernet_irq();
323   update_ethernet_irq(machine);
324324}
325325
326326
r2724r2725
331331 *
332332 *************************************/
333333
334static void process_command(UINT16 data)
334static void process_command(running_machine *machine, UINT16 data)
335335{
336336   switch ((data >> 5) & 7)
337337   {
r2724r2725
346346         ethernet.reg[EREG_PNR_ARR] &= ~0xff00;
347347         ethernet.reg[EREG_PNR_ARR] |= ethernet.alloc_count++ << 8;
348348         ethernet.reg[EREG_INTERRUPT] |= 0x0008;
349         update_ethernet_irq();
349         update_ethernet_irq(machine);
350350         break;
351351
352352      case ECMD_RESET_MMU:
r2724r2725
373373         }
374374         else
375375            ethernet.reg[EREG_FIFO_PORTS] |= 0x8000;
376         update_ethernet_irq();
376         update_ethernet_irq(machine);
377377         ethernet.recd++;
378378         update_stats();
379379         break;
r2724r2725
386386      case ECMD_ENQUEUE_PACKET:
387387         if (LOG_ETHERNET)
388388            logerror("   ENQUEUE TX PACKET\n");
389         finish_enqueue(0);
389         finish_enqueue(machine, 0);
390390         break;
391391
392392      case ECMD_RESET_FIFOS:
r2724r2725
421421         if (ACCESSING_BITS_8_15)
422422         {
423423            ethernet.reg[EREG_INTERRUPT] &= ~0x0008;
424            update_ethernet_irq();
424            update_ethernet_irq(machine);
425425         }
426426         break;
427427
r2724r2725
490490      case EREG_RCR:      /* receive control register */
491491         if (LOG_ETHERNET)
492492         {
493            if (data & 0x8000) smc91c94_reset();
493            if (data & 0x8000) smc91c94_reset(machine);
494494            if (data & 0x8000) logerror("   SOFT RST\n");
495495            if (data & 0x4000) logerror("   FILT_CAR\n");
496496            if (data & 0x0200) logerror("   STRIP CRC\n");
r2724r2725
540540         break;
541541
542542      case EREG_MMU_COMMAND:   /* command register */
543         process_command(data);
543         process_command(machine, data);
544544         break;
545545
546546      case EREG_DATA_0:   /* data register */
r2724r2725
558558
559559      case EREG_INTERRUPT:
560560         ethernet.reg[EREG_INTERRUPT] &= ~(data & 0x56);
561         update_ethernet_irq();
561         update_ethernet_irq(machine);
562562         break;
563563   }
564564}
src/emu/machine/smc91c9x.h
r2724r2725
1111
1212struct smc91c9x_interface
1313{
14   void (*irq_handler)(int state);
14   void (*irq_handler)(running_machine *machine, int state);
1515};
1616
1717void smc91c94_init(const struct smc91c9x_interface *config);
18void smc91c94_reset(void);
18void smc91c94_reset(running_machine *machine);
1919READ16_HANDLER( smc91c94_r );
2020WRITE16_HANDLER( smc91c94_w );
2121
src/emu/machine/z80pio.c
r2724r2725
5656struct _z80pio
5757{
5858   UINT8 vector[2];                      /* interrupt vector               */
59   void (*intr)(int which);            /* interrupt callbacks            */
59   void (*intr)(running_machine *, int which);            /* interrupt callbacks            */
6060   void (*rdyr[2])(int data);          /* RDY active callback            */
6161   read8_machine_func  port_read[2];     /* port read callbacks            */
6262   write8_machine_func port_write[2];    /* port write callbacks           */
r2724r2725
103103
104104   /* if we have a callback, update it with the current state */
105105   if (pio->intr)
106      (*pio->intr)((z80pio_irq_state(which) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE);
106      (*pio->intr)(Machine, (z80pio_irq_state(which) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE);
107107}
108108
109109
src/emu/machine/z80sio.c
r2724r2725
180180   sio_channel   chan[2];         /* 2 channels */
181181   UINT8      int_state[8];      /* interrupt states */
182182
183   void (*irq_cb)(int state);
183   void (*irq_cb)(running_machine *machine, int state);
184184   write8_machine_func dtr_changed_cb;
185185   write8_machine_func rts_changed_cb;
186186   write8_machine_func break_changed_cb;
r2724r2725
265265{
266266   /* if we have a callback, update it with the current state */
267267   if (sio->irq_cb != NULL)
268      (*sio->irq_cb)((z80sio_irq_state(sio - sios) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE);
268      (*sio->irq_cb)(Machine, (z80sio_irq_state(sio - sios) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE);
269269}
270270
271271
src/emu/machine/z80pio.h
r2724r2725
2121
2222struct _z80pio_interface
2323{
24   void (*intr)(int which);    /* callback when change interrupt status */
24   void (*intr)(running_machine *machine, int which);    /* callback when change interrupt status */
2525   read8_machine_func portAread;    /* port A read callback */
2626   read8_machine_func portBread;    /* port B read callback */
2727   write8_machine_func portAwrite;  /* port A write callback */
src/emu/machine/z80sio.h
r2724r2725
2323struct _z80sio_interface
2424{
2525   int baseclock;
26   void (*irq_cb)(int state);
26   void (*irq_cb)(running_machine *machine, int state);
2727   write8_machine_func dtr_changed_cb;
2828   write8_machine_func rts_changed_cb;
2929   write8_machine_func break_changed_cb;
src/emu/machine/tmp68301.c
r2724r2725
99***************************************************************************/
1010
1111#include "driver.h"
12#include "deprecat.h"
1312#include "machine/tmp68301.h"
1413
1514UINT16 *tmp68301_regs;
r2724r2725
120119}
121120
122121/* Update the IRQ state based on all possible causes */
123static void update_irq_state(void)
122static void update_irq_state(running_machine *machine)
124123{
125124   int i;
126125
r2724r2725
146145
147146         tmp68301_IE[i] = 0;      // Interrupts are edge triggerred
148147
149         cpunum_set_input_line(Machine, 0,level,HOLD_LINE);
148         cpunum_set_input_line(machine, 0,level,HOLD_LINE);
150149      }
151150   }
152151}
r2724r2725
174173   }
175174}
176175
177void tmp68301_external_interrupt_0()   { tmp68301_IE[0] = 1;   update_irq_state(); }
178void tmp68301_external_interrupt_1()   { tmp68301_IE[1] = 1;   update_irq_state(); }
179void tmp68301_external_interrupt_2()   { tmp68301_IE[2] = 1;   update_irq_state(); }
176void tmp68301_external_interrupt_0(running_machine *machine)   { tmp68301_IE[0] = 1;   update_irq_state(machine); }
177void tmp68301_external_interrupt_1(running_machine *machine)   { tmp68301_IE[1] = 1;   update_irq_state(machine); }
178void tmp68301_external_interrupt_2(running_machine *machine)   { tmp68301_IE[2] = 1;   update_irq_state(machine); }
180179
src/emu/machine/tmp68301.h
r2724r2725
99WRITE16_HANDLER( tmp68301_regs_w );
1010
1111// Interrupts
12void tmp68301_external_interrupt_0(void);
13void tmp68301_external_interrupt_1(void);
14void tmp68301_external_interrupt_2(void);
12void tmp68301_external_interrupt_0(running_machine *machine);
13void tmp68301_external_interrupt_1(running_machine *machine);
14void tmp68301_external_interrupt_2(running_machine *machine);
1515
1616#endif
src/emu/machine/z80ctc.c
r2724r2725
8080   UINT32 clock;            /* system clock */
8181   attotime period16;         /* 16/system clock */
8282   attotime period256;      /* 256/system clock */
83   void (*intr)(int which);   /* interrupt callback */
83   void (*intr)(running_machine *machine, int which);   /* interrupt callback */
8484   write8_machine_func zc[4];      /* zero crossing callbacks */
8585   UINT8 notimer;            /* no timer masks */
8686   UINT16 mode[4];            /* current mode */
r2724r2725
111111
112112   /* if we have a callback, update it with the current state */
113113   if (ctc->intr)
114      (*ctc->intr)((z80ctc_irq_state(which) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE);
114      (*ctc->intr)(Machine, (z80ctc_irq_state(which) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE);
115115}
116116
117117
src/emu/machine/z80ctc.h
r2724r2725
2828{
2929   int baseclock;                           /* timer clock */
3030   int notimer;                         /* timer disablers */
31   void (*intr)(int which);             /* callback when change interrupt status */
31   void (*intr)(running_machine *machine, int which);             /* callback when change interrupt status */
3232   write8_machine_func zc0;   /* ZC/TO0 callback */
3333   write8_machine_func zc1;   /* ZC/TO1 callback */
3434   write8_machine_func zc2;   /* ZC/TO2 callback */
src/emu/mame.h
r2724r2725
1717#include "crsshair.h"
1818#include "restrack.h"
1919#include "options.h"
20#include "inptport.h"
2021#include <stdarg.h>
2122
2223#ifdef MESS
r2724r2725
166167typedef struct _palette_private palette_private;
167168typedef struct _streams_private streams_private;
168169typedef struct _devices_private devices_private;
170typedef struct _input_port_private input_port_private;
169171
170172
171173/* description of the currently-running machine */
172174/* typedef struct _running_machine running_machine; -- in mamecore.h */
173175struct _running_machine
174176{
177   /* configuration data */
178   const machine_config *   config;            /* points to the constructed machine_config */
179   const input_port_config *portconfig;      /* points to a list of input port configurations */
180
175181   /* game-related information */
176182   const game_driver *      gamedrv;         /* points to the definition of the game machine */
177   const machine_config *   config;            /* points to the constructed machine_config */
178183   const char *         basename;         /* basename used for game-related paths */
179184
180185   /* video-related information */
r2724r2725
190195   /* audio-related information */
191196   int                  sample_rate;      /* the digital audio sample rate */
192197
193   /* input-related information */
194   input_port_entry *      input_ports;      /* the input ports definition from the driver is copied here and modified */
195   mame_file *            record_file;      /* recording file (NULL if not recording) */
196   mame_file *            playback_file;      /* playback file (NULL if not recording) */
197
198198   /* debugger-related information */
199199   int                  debug_mode;         /* was debug mode enabled? */
200200
r2724r2725
203203   palette_private *      palette_data;      /* internal data from palette.c */
204204   streams_private *      streams_data;      /* internal data from streams.c */
205205   devices_private *      devices_data;      /* internal data from devices.c */
206   input_port_private *   input_port_data;   /* internal data from inptport.c */
206207#ifdef MESS
207208   images_private *      images_data;      /* internal data from image.c */
208209#endif /* MESS */
src/emu/inptport.h
r2724r2725
1919#include "memory.h"
2020#include "inputseq.h"
2121#include "tokenize.h"
22
23#ifdef MESS
2422#include "unicode.h"
25#endif
2623
2724
2825
r2724r2725
3027    CONSTANTS
3128***************************************************************************/
3229
33#define MAX_INPUT_PORTS      32
3430#define MAX_PLAYERS         8
35#define MAX_BITS_PER_PORT   32
3631
3732#define IP_ACTIVE_HIGH      0x00000000
3833#define IP_ACTIVE_LOW      0xffffffff
3934
40#define INPUT_PORT_PAIR_ENTRIES   (sizeof(FPTR) / sizeof(UINT32))
41#define INPUT_PORT_PAIR_TOKENS   (2 * sizeof(UINT32) / sizeof(FPTR))
4235
36/* flags for input_field_configs */
37#define FIELD_FLAG_UNUSED   0x01         /* set if this field is unused but relevant to other games on the same hw */
38#define FIELD_FLAG_COCKTAIL   0x02         /* set if this field is relevant only for cocktail cabinets */
39#define FIELD_FLAG_TOGGLE   0x04         /* set if this field should behave as a toggle */
40#define FIELD_FLAG_ROTATED   0x08         /* set if this field represents a rotated control */
41#define ANALOG_FLAG_REVERSE   0x10         /* analog only: reverse the sense of the axis */
42#define ANALOG_FLAG_RESET   0x20         /* analog only: always preload in->default for relative axes, returning only deltas */
43#define ANALOG_FLAG_WRAPS   0x40         /* analog only: positional count wraps around */
44#define ANALOG_FLAG_INVERT   0x80         /* analog only: bitwise invert bits */
4345
46
47/* INP file information */
4448#define INP_HEADER_SIZE         64
4549#define INP_HEADER_MAJVERSION   2
4650#define INP_HEADER_MINVERSION   0
4751
4852
49/* macro for a custom callback functions (PORT_CUSTOM) */
50#define CUSTOM_INPUT(name)   UINT32 name(running_machine *machine, void *param)
51
52/* macro for port changed callback functions (PORT_CHANGED) */
53#define INPUT_CHANGED(name)   void name(running_machine *machine, void *param, UINT32 oldval, UINT32 newval)
54
55
5653/* sequence types for input_port_seq() call */
5754enum _input_seq_type
5855{
5956   SEQ_TYPE_STANDARD = 0,
60   SEQ_TYPE_INCREMENT = 1,
61   SEQ_TYPE_DECREMENT = 2
57   SEQ_TYPE_INCREMENT,
58   SEQ_TYPE_DECREMENT,
59   SEQ_TYPE_TOTAL
6260};
6361typedef enum _input_seq_type input_seq_type;
6462
r2724r2725
108106   IPT_END,
109107   IPT_UNKNOWN,
110108   IPT_PORT,
111   IPT_DIPSWITCH_NAME,
112   IPT_DIPSWITCH_SETTING,
109   IPT_DIPSWITCH,
113110   IPT_VBLANK,
114   IPT_CONFIG_NAME,         /* MESS only */
115   IPT_CONFIG_SETTING,         /* MESS only */
116   IPT_CATEGORY_NAME,         /* MESS only */
117   IPT_CATEGORY_SETTING,      /* MESS only */
111   IPT_CONFIG,
112   IPT_CATEGORY,            /* MESS only */
118113
119114   /* start buttons */
120115   IPT_START1,
r2724r2725
249244   IPT_ADJUSTER,
250245
251246   /* the following are special codes for user interface handling - not to be used by drivers! */
247#define __ipt_ui_start IPT_UI_CONFIGURE
252248   IPT_UI_CONFIGURE,
253249   IPT_UI_ON_SCREEN_DISPLAY,
254250   IPT_UI_DEBUG_BREAK,
r2724r2725
311307   IPT_OSD_14,
312308   IPT_OSD_15,
313309   IPT_OSD_16,
310#define __ipt_ui_end IPT_OSD_16
314311
315312   /* other meaning not mapped to standard defaults */
316313   IPT_OTHER,
r2724r2725
331328   INPUT_TOKEN_START,
332329   INPUT_TOKEN_START_TAG,
333330   INPUT_TOKEN_MODIFY,
334   INPUT_TOKEN_BIT,
331   INPUT_TOKEN_FIELD,
335332   INPUT_TOKEN_SPECIAL_ONOFF,
336333   INPUT_TOKEN_CODE,
337334   INPUT_TOKEN_CODE_DEC,
r2724r2725
375372   INPUT_TOKEN_ADJUSTER,
376373   INPUT_TOKEN_CONFNAME,
377374   INPUT_TOKEN_CONFSETTING,
378#ifdef MESS
379375   INPUT_TOKEN_CHAR,
380376   INPUT_TOKEN_CATEGORY,
381377   INPUT_TOKEN_CATEGORY_NAME,
382   INPUT_TOKEN_CATEGORY_SETTING,
383#endif /* MESS */
378   INPUT_TOKEN_CATEGORY_SETTING
384379};
385380
386381
r2724r2725
505500    TYPE DEFINITIONS
506501***************************************************************************/
507502
508/* this is an opaque type */
509typedef struct _input_port_init_params input_port_init_params;
503/* input ports support up to 32 bits each */
504typedef UINT32 input_port_value;
510505
511506
512/* a custom input port callback function */
513typedef UINT32 (*input_port_custom_func)(running_machine *machine, void *param);
514typedef void (*input_port_changed_func)(running_machine *machine, void *param, UINT32 oldval, UINT32 newval);
507/* opaque types pointing to live state */
508typedef struct _input_port_state input_port_state;
509typedef struct _input_field_state input_field_state;
515510
516511
512/* forward declarations */
513typedef struct _input_port_config input_port_config;
514typedef struct _input_field_config input_field_config;
515
516
517/* custom input port callback function */
518typedef UINT32 (*input_field_custom_func)(const input_field_config *field, void *param);
519
520/* input port changed callback function */
521typedef void (*input_field_changed_func)(const input_field_config *field, void *param, UINT32 oldval, UINT32 newval);
522
523
517524/* this type is used to encode input port definitions */
518525typedef union _input_port_token input_port_token;
519526union _input_port_token
520527{
521528   TOKEN_COMMON_FIELDS
522   const input_port_token *tokenptr;
523   input_port_custom_func customptr;
524   input_port_changed_func changedptr;
529   const input_port_token *   tokenptr;
530   input_field_custom_func    customptr;
531   input_field_changed_func    changedptr;
525532};
526533
527534
528/* In mamecore.h: typedef struct _input_port_default_entry input_port_default_entry; */
529struct _input_port_default_entry
535/* encapsulates a condition on a port field or setting */
536typedef struct _input_condition input_condition;
537struct _input_condition
530538{
531   UINT32      type;         /* type of port; see enum above */
532   UINT8      group;         /* which group the port belongs to */
533   UINT8      player;         /* player number (0 is player 1) */
534   const char *token;         /* token used to store settings */
535   const char *name;         /* user-friendly name */
536   input_seq   defaultseq;      /* default input sequence */
537   input_seq   defaultincseq;   /* default input sequence to increment (analog ports only) */
538   input_seq   defaultdecseq;   /* default input sequence to decrement (analog ports only) */
539   const char *            tag;         /* tag of port whose condition is to be tested */
540   input_port_value         mask;         /* mask to apply to the port */
541   input_port_value         value;         /* value to compare against */
542   UINT8                  condition;      /* condition to use */
539543};
540544
541545
542/* In mamecore.h: typedef struct _input_port_entry input_port_entry; */
543struct _input_port_entry
546/* a single setting for a configuration or DIP switch */
547typedef struct _input_setting_config input_setting_config;
548struct _input_setting_config
544549{
545   UINT32      mask;         /* bits affected */
546   UINT32      default_value;   /* default value for the bits affected */
547                        /* you can also use one of the IP_ACTIVE defines above */
548   UINT32      type;         /* see enum above */
549   UINT8      unused;         /* The bit is not used by this game, but is used */
550                        /* by other games running on the same hardware. */
551                        /* This is different from IPT_UNUSED, which marks */
552                        /* bits not connected to anything. */
553   UINT8      cocktail;      /* the bit is used in cocktail mode only */
554   UINT8      player;         /* the player associated with this port; note that */
555                        /* player 1 is '0' */
556   UINT8      toggle;         /* When this is set, the key acts as a toggle - press */
557                        /* it once and it goes on, press it again and it goes off. */
558                        /* useful e.g. for some Test Mode dip switches. */
559   UINT8      impulse;      /* When this is set, when the key corresponding to */
560                        /* the input bit is pressed it will be reported as */
561                        /* pressed for a certain number of video frames and */
562                        /* then released, regardless of the real status of */
563                        /* the key. This is useful e.g. for some coin inputs. */
564                        /* The number of frames the signal should stay active */
565                        /* is specified in the "arg" field. */
566   UINT8      way;         /* Joystick modes of operation. 8WAY is the default, */
567                        /* it prevents left/right or up/down to be pressed at */
568                        /* the same time. 4WAY prevents diagonal directions. */
569                        /* 2WAY should be used for joysticks wich move only */
570                        /* on one axis (e.g. Battle Zone) */
571   UINT8      rotated;      /* Indicates the control is rotated 45 degrees. This */
572                        /* is used as a hint for joystick mapping. */
573   UINT16      category;      /* (MESS-specific) category */
574   const char *name;         /* user-friendly name to display */
575   input_seq   seq;         /* input sequence affecting the input bits */
576   input_port_custom_func custom;/* custom callback routine */
577   void *      custom_param;   /* parameter for custom callback routine */
578   input_port_changed_func changed;/* changed callback routine */
579   void *      changed_param;   /* parameter for changed callback routine */
580   UINT32      changed_last_value; /* the last value for changed detection purposes */
550   const input_setting_config *next;         /* pointer to next setting in sequence */
551   const input_field_config *   field;         /* pointer back to the field that owns us */
552   input_port_value         value;         /* value of the bits in this setting */
553   input_condition            condition;      /* condition under which this setting is valid */
554   const char *            name;         /* user-friendly name to display */
555};
581556
582   /* valid if type is between __ipt_analog_start and __ipt_analog_end */
583   struct
584   {
585      INT32   min;            /* minimum value for absolute axes */
586      INT32   max;            /* maximum value for absolute axes */
587      INT32   sensitivity;      /* sensitivity (100=normal) */
588      INT32   delta;            /* delta to apply each frame a digital inc/dec key is pressed */
589      INT32   centerdelta;      /* delta to apply each frame no digital inputs are pressed */
590      UINT8   reverse;         /* reverse the sense of the analog axis */
591      UINT8   reset;            /* always preload in->default for relative axes, returning only deltas */
592      UINT8   crossaxis;         /* crosshair axis */
593      float   crossscale;         /* crosshair scale */
594      float   crossoffset;      /* crosshair offset */
595      float   crossaltaxis;      /* crosshair alternate axis value */
596      input_seq incseq;         /* increment sequence */
597      input_seq decseq;         /* decrement sequence */
598      UINT8   wraps;            /* positional count wraps around */
599      UINT8   invert;            /* bitwise invert bits */
600      UINT16   full_turn_count;   /* number of optical counts for 1 full turn of the original control */
601      const UINT32 *remap_table;   /* pointer to an array that remaps the port value */
602   } analog;
603557
604   /* valid if type is IPT_PORT */
605   struct
606   {
607      const char *tag;      /* used to tag PORT_START declarations */
608   } start;
558/* a mapping from a bit to a physical DIP switch description */
559typedef struct _input_field_diplocation input_field_diplocation;
560struct _input_field_diplocation
561{
562   input_field_diplocation *   next;         /* pointer to the next bit */
563   const char *            swname;         /* name of the physical DIP switch */
564   UINT8                  swnum;         /* physical switch number */
565   UINT8                  invert;         /* is this an active-high DIP? */
566};
609567
610   /* valid for most types */
611   struct
612   {
613      const char *tag;      /* port tag to use for condition */
614      UINT8   portnum;      /* port number for condition */
615      UINT8   condition;      /* condition to use */
616      UINT32   mask;         /* mask to apply to the port */
617      UINT32   value;         /* value to compare against */
618   } condition;
619568
620   /* valid for IPT_DIPNAME */
621   struct
622   {
623      const char *swname;      /* name of the physical DIP switch */
624      UINT8   swnum;         /* physical switch number */
625      UINT8   invert;         /* is this an active-high DIP? */
626   } diploc[8];
569/* a single bitfield within an input port */
570struct _input_field_config
571{
572   /* generally-applicable data */
573   const input_field_config *   next;         /* pointer to next field in sequence */
574   const input_port_config *   port;         /* pointer back to the port that owns us */
575   input_port_value         mask;         /* mask of bits belonging to the field */
576   input_port_value         defvalue;      /* default value of these bits */
577   input_condition            condition;      /* condition under which this field is relevant */
578   UINT32                  type;         /* IPT_* type for this port */
579   UINT8                  player;         /* player number (0-based) */
580   UINT16                  category;      /* (MESS-specific) category */
581   UINT32                  flags;         /* combination of FIELD_FLAG_* and ANALOG_FLAG_* above */
582   UINT8                  impulse;      /* number of frames before reverting to defvalue */
583   const char *            name;         /* user-friendly name to display */
584   input_seq               seq[SEQ_TYPE_TOTAL];/* sequences of all types */
585   input_field_custom_func      custom;         /* custom callback routine */
586   void *                  custom_param;   /* parameter for custom callback routine */
587   input_field_changed_func    changed;      /* changed callback routine */
588   void *                  changed_param;   /* parameter for changed callback routine */
627589
628   /* valid if type is IPT_KEYBOARD */
629#ifdef MESS
630   struct
631   {
632      unicode_char chars[3];   /* (MESS-specific) unicode key data */
633   } keyboard;
634#endif /* MESS */
590   /* data relevant to analog control types */
591   INT32                  min;         /* minimum value for absolute axes */
592   INT32                  max;         /* maximum value for absolute axes */
593   INT32                  sensitivity;   /* sensitivity (100=normal) */
594   INT32                  delta;         /* delta to apply each frame a digital inc/dec key is pressed */
595   INT32                  centerdelta;   /* delta to apply each frame no digital inputs are pressed */
596   UINT8                  crossaxis;      /* crosshair axis */
597   float                  crossscale;      /* crosshair scale */
598   float                  crossoffset;   /* crosshair offset */
599   float                  crossaltaxis;   /* crosshair alternate axis value */
600   UINT16                  full_turn_count;/* number of optical counts for 1 full turn of the original control */
601   const input_port_value *   remap_table;   /* pointer to an array that remaps the port value */
602
603   /* data relevant to other specific types */
604   const input_setting_config *settinglist;   /* list of input_setting_configs */
605   const input_field_diplocation *diploclist;   /* list of locations for various bits */
606   UINT8                  way;         /* digital joystick 2/4/8-way descriptions */
607   unicode_char             chars[3];      /* (MESS-specific) unicode key data */
608
609   /* this field is only valid if the device is live */
610   input_field_state *         state;         /* live state of field (NULL if not live) */
635611};
636612
637613
614/* user-controllable settings for a field */
615typedef struct _input_field_user_settings input_field_user_settings;
616struct _input_field_user_settings
617{
618   input_port_value         value;         /* for DIP switches */
619   input_seq               seq[SEQ_TYPE_TOTAL];/* sequences of all types */
620   INT32                  sensitivity;   /* for analog controls */
621   INT32                  delta;         /* for analog controls */
622   INT32                  centerdelta;   /* for analog controls */
623   UINT8                  reverse;      /* for analog controls */
624};
625
626
627/* a single input port configuration */
628struct _input_port_config
629{
630   const input_port_config *   next;         /* pointer to next port */
631   const char *            tag;         /* pointer to this port's tag */
632   const input_field_config *   fieldlist;      /* list of input_field_configs */
633
634   /* these two fields are only valid if the port is live */
635   input_port_state *         state;         /* live state of port (NULL if not live) */
636   running_machine *         machine;      /* machine if port is live */
637};
638
639
640/* describes a fundamental input type, including default input sequences */
641typedef struct _input_type_desc input_type_desc;
642struct _input_type_desc
643{
644   input_type_desc *         next;         /* next description in the list */
645   UINT32                  type;         /* IPT_* for this entry */
646   UINT8                  group;         /* which group the port belongs to */
647   UINT8                  player;         /* player number (0 is player 1) */
648   const char *            token;         /* token used to store settings */
649   const char *            name;         /* user-friendly name */
650   input_seq               seq[SEQ_TYPE_TOTAL];/* default input sequence */
651};
652
653
654/* heaeder at the front of INP files */
638655typedef struct _inp_header inp_header;
639656struct _inp_header
640657{
641   char   header[8];         /* +00: 8 byte header - must be "MAMEINP\0" */
642   UINT64   basetime;         /* +08: base time of recording */
643   UINT8   majversion;         /* +10: major INP version */
644   UINT8   minversion;         /* +11: minor INP version */
645   UINT8   reserved[2];      /* +12: must be zero */
646   char   gamename[12];      /* +14: game name string, NULL-terminated */
647   char   version[32];      /* +20: system version string, NULL-terminated */
658   char                  header[8];      /* +00: 8 byte header - must be "MAMEINP\0" */
659   UINT64                  basetime;      /* +08: base time of recording */
660   UINT8                  majversion;      /* +10: major INP version */
661   UINT8                  minversion;      /* +11: minor INP version */
662   UINT8                  reserved[2];   /* +12: must be zero */
663   char                  gamename[12];   /* +14: game name string, NULL-terminated */
664   char                  version[32];   /* +20: system version string, NULL-terminated */
648665};
649666
650667
651668
652669/***************************************************************************
670    MACROS
671***************************************************************************/
672
673/* macro for a custom callback functions (PORT_CUSTOM) */
674#define CUSTOM_INPUT(name)   UINT32 name(const input_field_config *field, void *param)
675
676/* macro for port changed callback functions (PORT_CHANGED) */
677#define INPUT_CHANGED(name)   void name(const input_field_config *field, void *param, UINT32 oldval, UINT32 newval)
678
679/* macro for wrapping a default string */
680#define DEF_STR(str_num) ((const char *)INPUT_STRING_##str_num)
681
682
683
684/***************************************************************************
653685    MACROS FOR BUILDING INPUT PORTS
654686***************************************************************************/
655687
656#define IP_NAME_DEFAULT             NULL
657
658688/* start of table */
659689#define INPUT_PORTS_START(_name) \
660690   const input_port_token ipt_##_name[] = {
r2724r2725
688718
689719/* input bit definition */
690720#define PORT_BIT(_mask, _default, _type) \
691   TOKEN_UINT32_PACK2(INPUT_TOKEN_BIT, 8, _type, 24), \
721   TOKEN_UINT32_PACK2(INPUT_TOKEN_FIELD, 8, _type, 24), \
692722   TOKEN_UINT64_PACK2(_mask, 32, _default, 32),
693723
694724#define PORT_SPECIAL_ONOFF(_mask, _default, _strindex) \
r2724r2725
845875   TOKEN_UINT64_PACK2(INPUT_TOKEN_CONFSETTING, 8, _default, 32), \
846876   TOKEN_STRING(_name),
847877
848#ifdef MESS
849878/* keyboard chars */
850879#define PORT_CHAR(_ch) \
851880   TOKEN_UINT64_PACK2(INPUT_TOKEN_CHAR, 8, _ch, 32), \
r2724r2725
862891#define PORT_CATEGORY_ITEM(_default, _name, _category) \
863892   TOKEN_UINT64_PACK3(INPUT_TOKEN_CATEGORY_SETTING, 8, _default, 32, _category, 16), \
864893   TOKEN_STRING(_name),
865#endif /* MESS */
866894
867895
868896
r2724r2725
894922
895923
896924/***************************************************************************
897    GLOBAL VARIABLES
925    FUNCTION PROTOTYPES
898926***************************************************************************/
899927
900#define DEF_STR(str_num) ((const char *)INPUT_STRING_##str_num)
901928
929/* ----- core system management ----- */
902930
903/***************************************************************************
904    FUNCTION PROTOTYPES
905***************************************************************************/
931/* initialize the input ports, processing the given token list */
932time_t input_port_init(running_machine *machine, const input_port_token *tokens);
906933
907time_t input_port_init(running_machine *machine, const input_port_token *ipt);
908const char *input_port_string_from_token(const input_port_token token);
909934
910input_port_entry *input_port_initialize(input_port_init_params *params, UINT32 type, const char *tag, UINT32 mask, UINT32 defval);
911input_port_entry *input_port_allocate(const input_port_token *ipt, input_port_entry *memory);
912void input_port_parse_diplocation(input_port_entry *in, const char *location);
913935
914input_port_default_entry *get_input_port_list(void);
915const input_port_default_entry *get_input_port_list_defaults(void);
936/* ----- port configurations ----- */
916937
917int input_port_active(const input_port_entry *in);
918int port_type_is_analog(int type);
919int port_type_is_analog_absolute(int type);
920int port_type_in_use(int type);
921int port_type_to_group(int type, int player);
922int port_tag_to_index(const char *tag);
923read8_machine_func port_tag_to_handler8(const char *tag);
924read16_machine_func port_tag_to_handler16(const char *tag);
925read32_machine_func port_tag_to_handler32(const char *tag);
926read64_machine_func port_tag_to_handler64(const char *tag);
927const char *input_port_name(const input_port_entry *in);
928const input_seq *input_port_seq(input_port_entry *in, input_seq_type seqtype);
929const input_seq *input_port_default_seq(int type, int player, input_seq_type seqtype);
930int input_port_condition(const input_port_entry *in);
938/* allocate a list of input ports from the given token list */
939const input_port_config *input_port_config_alloc(const input_port_token *tokens);
931940
932const char *port_type_to_token(int type, int player);
933int token_to_port_type(const char *string, int *player);
941/* free memory allocated from input_port_alloc */
942void input_port_config_free(const input_port_config *portlist);
934943
935int input_port_type_pressed(int type, int player);
936int input_ui_pressed(int code);
937int input_ui_pressed_repeat(int code, int speed);
944/* return the config that matches the given tag */
945const input_port_config *input_port_by_tag(const input_port_config *portlist, const char *tag);
938946
939void input_port_update_defaults(void);
947/* return the config that matches the given tag */
948const input_port_config *input_port_by_index(const input_port_config *portlist, int index);
940949
941UINT32 get_crosshair_pos(int port_num, UINT8 player, UINT8 axis);
942950
943UINT32 input_port_read_indexed(running_machine *machine, int port);
944UINT32 input_port_read(running_machine *machine, const char *tag);
945UINT32 input_port_read_safe(running_machine *machine, const char *tag, UINT32 defvalue);
946951
952/* ----- accessors for input types ----- */
953
954/* return TRUE if the given type represents an analog control */
955int input_type_is_analog(int type);
956
957/* return the name for the given type/player */
958const char *input_type_name(running_machine *machine, int type, int player);
959
960/* return the group for the given type/player */
961int input_type_group(running_machine *machine, int type, int player);
962
963/* return the global input mapping sequence for the given type/player */
964const input_seq *input_type_seq(running_machine *machine, int type, int player, input_seq_type seqtype);
965
966/* change the global input sequence for the given type/player */
967void input_type_set_seq(running_machine *machine, int type, int player, input_seq_type seqtype, const input_seq *newseq);
968
969/* return TRUE if the sequence for the given input type/player is pressed */
970int input_type_pressed(running_machine *machine, int type, int player);
971
972/* return the list of default mappings */
973const input_type_desc *input_type_list(running_machine *machine);
974
975
976
977/* ----- accessors for input fields ----- */
978
979/* return the expanded string name of the field */
980const char *input_field_name(const input_field_config *field);
981
982/* return the input sequence for the given input field */
983const input_seq *input_field_seq(const input_field_config *field, input_seq_type seqtype);
984
985/* return the current settings for the given input field */
986void input_field_get_user_settings(const input_field_config *field, input_field_user_settings *settings);
987
988/* modify the current settings for the given input field */
989void input_field_set_user_settings(const input_field_config *field, const input_field_user_settings *settings);
990
991
992
993/* ----- user interface sequence reading ----- */
994
995/* return TRUE if a key down for the given user interface sequence is detected */
996int input_ui_pressed(running_machine *machine, int code);
997
998/* return TRUE if a key down for the given user interface sequence is detected, or if
999   autorepeat at the given speed is triggered */
1000int input_ui_pressed_repeat(running_machine *machine, int code, int speed);
1001
1002
1003
1004/* ----- port reading ----- */
1005
1006/* return the value of an input port */
1007input_port_value input_port_read_direct(const input_port_config *port);
1008
1009/* return the value of an input port specified by tag */
1010input_port_value input_port_read(running_machine *machine, const char *tag);
1011
1012/* return the value of an input port specified by tag, or a default value if the port does not exist */
1013input_port_value input_port_read_safe(running_machine *machine, const char *tag, input_port_value defvalue);
1014
1015/* return the value of an input port specified by index */
1016input_port_value input_port_read_indexed(running_machine *machine, int portnum);
1017
1018/* return the extracted crosshair values for the given player */
1019int input_port_get_crosshair_position(running_machine *machine, int player, float *x, float *y);
1020
1021/* force an update to the input port values based on current conditions */
1022void input_port_update_defaults(running_machine *machine);
1023
1024
1025
1026/* ----- misc helper functions ----- */
1027
1028/* return the TRUE if the given condition attached is true */
1029int input_condition_true(running_machine *machine, const input_condition *condition);
1030
1031/* convert an input_port_token to a default string */
1032const char *input_port_string_from_token(const input_port_token token);
1033
1034/* return a memory handler corresponding to a given input port tag */
1035read8_machine_func input_port_read_handler8(const input_port_config *portlist, const char *tag);
1036read16_machine_func input_port_read_handler16(const input_port_config *portlist, const char *tag);
1037read32_machine_func input_port_read_handler32(const input_port_config *portlist, const char *tag);
1038read64_machine_func input_port_read_handler64(const input_port_config *portlist, const char *tag);
1039
1040
9471041#endif   /* __INPTPORT_H__ */
src/emu/mamecore.h
r2724r2725
6666typedef struct _rom_load_data rom_load_data;
6767typedef struct _osd_create_params osd_create_params;
6868typedef struct _gfx_element gfx_element;
69typedef struct _input_port_entry input_port_entry;
70typedef struct _input_port_default_entry input_port_default_entry;
7169typedef struct _mame_file mame_file;
7270
7371
src/emu/sound/262intf.h
r2724r2725
44
55struct YMF262interface
66{
7   void (*handler)(int irq);
7   void (*handler)(running_machine *machine, int irq);
88};
99
1010
src/emu/sound/tms5110.c
r2724r2725
77     Additional tweaking by Aaron Giles
88     Various fixes by Lord Nightmare
99     Additional enhancements by Couriersud
10     Sub-interpolation-cycle parameter updating added by Lord Nightmare
1011
1112     Todo:
1213        - implement CS
r2724r2725
417418{
418419   struct tms5110 *tms = chip;
419420   int buf_count=0;
420   int i, interp_period;
421   int i, interp_period, bitout;
421422   INT16 Y11, cliptemp;
422423
423424   /* if we're not speaking, fill with nothingness */
r2724r2725
542543               tms->target_k[i] = tms->new_k[i];
543544         }
544545      }
545      else if (tms->interp_count == 0)
546      else
546547      {
547         /* interpolate (update) values based on step values */
548         /*logerror("\n");*/
549
550548         interp_period = tms->sample_count / 25;
551         tms->current_energy += (tms->target_energy - tms->current_energy) / tms->coeff->interp_coeff[interp_period];
552         tms->current_pitch += (tms->target_pitch - tms->current_pitch) / tms->coeff->interp_coeff[interp_period];
553
554         /*logerror("*** Energy = %d\n",current_energy);*/
555
556         for (i = 0; i < tms->coeff->num_k; i++)
549         switch(tms->interp_count)
557550         {
558            tms->current_k[i] += (tms->target_k[i] - tms->current_k[i]) / tms->coeff->interp_coeff[interp_period];
551            /*         PC=X  X cycle, rendering change (change for next cycle which chip is actually doing) */
552            case 0: /* PC=0, A cycle, nothing happens (calc energy) */
553            break;
554            case 1: /* PC=0, B cycle, nothing happens (update energy) */
555            break;
556            case 2: /* PC=1, A cycle, update energy (calc pitch) */
557            tms->current_energy += ((tms->target_energy - tms->current_energy) >> tms->coeff->interp_coeff[interp_period]);
558            break;
559            case 3: /* PC=1, B cycle, nothing happens (update pitch) */
560            break;
561            case 4: /* PC=2, A cycle, update pitch (calc K1) */
562            tms->current_pitch += ((tms->target_pitch - tms->current_pitch) >> tms->coeff->interp_coeff[interp_period]);
563            break;
564            case 5: /* PC=2, B cycle, nothing happens (update K1) */
565            break;
566            case 6: /* PC=3, A cycle, update K1 (calc K2) */
567            tms->current_k[0] += ((tms->target_k[0] - tms->current_k[0]) >> tms->coeff->interp_coeff[interp_period]);
568            break;
569            case 7: /* PC=3, B cycle, nothing happens (update K2) */
570            break;
571            case 8: /* PC=4, A cycle, update K2 (calc K3) */
572            tms->current_k[1] += ((tms->target_k[1] - tms->current_k[1]) >> tms->coeff->interp_coeff[interp_period]);
573            break;
574            case 9: /* PC=4, B cycle, nothing happens (update K3) */
575            break;
576            case 10: /* PC=5, A cycle, update K3 (calc K4) */
577            tms->current_k[2] += ((tms->target_k[2] - tms->current_k[2]) >> tms->coeff->interp_coeff[interp_period]);
578            break;
579            case 11: /* PC=5, B cycle, nothing happens (update K4) */
580            break;
581            case 12: /* PC=6, A cycle, update K4 (calc K5) */
582            tms->current_k[3] += ((tms->target_k[3] - tms->current_k[3]) >> tms->coeff->interp_coeff[interp_period]);
583            break;
584            case 13: /* PC=6, B cycle, nothing happens (update K5) */
585            break;
586            case 14: /* PC=7, A cycle, update K5 (calc K6) */
587            tms->current_k[4] += ((tms->target_k[4] - tms->current_k[4]) >> tms->coeff->interp_coeff[interp_period]);
588            break;
589            case 15: /* PC=7, B cycle, nothing happens (update K6) */
590            break;
591            case 16: /* PC=8, A cycle, update K6 (calc K7) */
592            tms->current_k[5] += ((tms->target_k[5] - tms->current_k[5]) >> tms->coeff->interp_coeff[interp_period]);
593            break;
594            case 17: /* PC=8, B cycle, nothing happens (update K7) */
595            break;
596            case 18: /* PC=9, A cycle, update K7 (calc K8) */
597            tms->current_k[6] += ((tms->target_k[6] - tms->current_k[6]) >> tms->coeff->interp_coeff[interp_period]);
598            break;
599            case 19: /* PC=9, B cycle, nothing happens (update K8) */
600            break;
601            case 20: /* PC=10, A cycle, update K8 (calc K9) */
602            tms->current_k[7] += ((tms->target_k[7] - tms->current_k[7]) >> tms->coeff->interp_coeff[interp_period]);
603            break;
604            case 21: /* PC=10, B cycle, nothing happens (update K9) */
605            break;
606            case 22: /* PC=11, A cycle, update K9 (calc K10) */
607            tms->current_k[8] += ((tms->target_k[8] - tms->current_k[8]) >> tms->coeff->interp_coeff[interp_period]);
608            break;
609            case 23: /* PC=11, B cycle, nothing happens (update K10) */
610            break;
611            case 24: /* PC=12, A cycle, update K10 (do nothing) */
612            tms->current_k[9] += ((tms->target_k[9] - tms->current_k[9]) >> tms->coeff->interp_coeff[interp_period]);
613            break;
559614         }
560615      }
561616
562617
618      /* calculate the output */
563619
564
565
566   /* calculate the output */
567
568620      if (tms->current_energy == 0)
569621      {
570622         /* generate silent samples here */
r2724r2725
572624      }
573625      else if (tms->old_pitch == 0)
574626      {
575         int bitout, randbit;
576
577627         /* generate unvoiced samples here */
578628         if (tms->RNG&1)
579            randbit = -64; /* according to the patent it is (either + or -) half of the maximum value in the chirp table */
629            current_val = -64; /* according to the patent it is (either + or -) half of the maximum value in the chirp table */
580630         else
581            randbit = 64;
631            current_val = 64;
582632
583         bitout = ((tms->RNG>>12)&1) ^
584                ((tms->RNG>>10)&1) ^
585                ((tms->RNG>> 9)&1) ^
586                ((tms->RNG>> 0)&1);
587         tms->RNG >>= 1;
588         tms->RNG |= (bitout<<12);
589
590         current_val = randbit;
591633      }
592634      else
593635      {
r2724r2725
608650         current_val = tms->coeff->chirptable[tms->pitch_count];
609651      }
610652
653      /* Update LFSR *20* times every sample, like patent shows */
654      for (i=0; i<20; i++)
655      {
656         bitout = ((tms->RNG>>12)&1) ^
657             ((tms->RNG>>10)&1) ^
658             ((tms->RNG>> 9)&1) ^
659             ((tms->RNG>> 0)&1);
660         tms->RNG >>= 1;
661         tms->RNG |= (bitout<<12);
662      }
611663
612664      /* Lattice filter here */
613665
src/emu/sound/2612intf.c
r2724r2725
3131static void IRQHandler(void *param,int irq)
3232{
3333   struct ym2612_info *info = param;
34   if(info->intf->handler) info->intf->handler(irq);
34   if(info->intf->handler) info->intf->handler(Machine, irq);
3535}
3636
3737/* Timer overflow callback from timer.c */
src/emu/sound/2612intf.h
r2724r2725
33
44struct YM2612interface
55{
6   void (*handler)(int irq);
6   void (*handler)(running_machine *machine, int irq);
77};
88
99
r2724r2725
3333
3434struct YM3438interface
3535{
36   void (*handler)(int irq);
36   void (*handler)(running_machine *machine, int irq);
3737};
3838
3939
src/emu/sound/k054539.c
r2724r2725
430430{
431431   struct k054539_info *info = ptr;
432432   if(info->regs[0x22f] & 0x20)
433      info->intf->irq ();
433      info->intf->irq(machine);
434434}
435435
436436static void K054539_init_chip(struct k054539_info *info, int clock, int sndindex)
src/emu/sound/disc_inp.c
r2724r2725
2222
2323struct dss_adjustment_context
2424{
25   INT32      port;
25   const input_port_config *port;
2626   INT32      lastpval;
2727   INT32      pmin;
2828   double      pscale;
r2724r2725
122122   if (DSS_ADJUSTMENT__ENABLE)
123123   {
124124      struct dss_adjustment_context *context = node->context;
125      INT32 rawportval = input_port_read_indexed(Machine, context->port);
125      INT32 rawportval = input_port_read_direct(context->port);
126126
127127      /* only recompute if the value changed from last time */
128128      if (rawportval != context->lastpval)
r2724r2725
150150
151151   if (node->custom)
152152   {
153      context->port = port_tag_to_index(node->custom);
154      if (context->port == -1)
153      context->port = input_port_by_tag(Machine->portconfig, node->custom);
154      if (context->port == NULL)
155155         fatalerror("DISCRETE_ADJUSTMENT_TAG - NODE_%d has invalid tag", node->node-NODE_00);
156156   }
157157   else
158      context->port = DSS_ADJUSTMENT__PORT;
158      context->port = input_port_by_index(Machine->portconfig, DSS_ADJUSTMENT__PORT);
159159
160160   context->lastpval = 0x7fffffff;
161161   context->pmin = DSS_ADJUSTMENT__PMIN;
src/emu/sound/k054539.h
r2724r2725
99struct K054539interface {
1010   int region;                  /* memory regions of sample ROM(s) */
1111   void (*apan)(double, double);   /* Callback for analog output mixing levels (0..1 for each channel) */
12   void (*irq)( void );
12   void (*irq)(running_machine *);
1313};
1414
1515
src/emu/sound/msm5205.c
r2724r2725
116116   int val;
117117   int new_signal;
118118   /* callback user handler and latch next data */
119   if(voice->intf->vclk_callback) (*voice->intf->vclk_callback)(voice->index);
119   if(voice->intf->vclk_callback) (*voice->intf->vclk_callback)(machine, voice->index);
120120
121121   /* reset check at last hieddge of VCLK */
122122   if(voice->reset)
src/emu/sound/msm5205.h
r2724r2725
1616
1717struct MSM5205interface
1818{
19   void (*vclk_callback)(int);   /* VCLK callback              */
19   void (*vclk_callback)(running_machine *, int);   /* VCLK callback              */
2020   int select;       /* prescaler / bit width selector        */
2121};
2222
src/emu/sound/3812intf.c
r2724r2725
3838static void IRQHandler_3812(void *param,int irq)
3939{
4040   struct ym3812_info *info = param;
41   if (info->intf->handler) (info->intf->handler)(irq ? ASSERT_LINE : CLEAR_LINE);
41   if (info->intf->handler) (info->intf->handler)(Machine, irq ? ASSERT_LINE : CLEAR_LINE);
4242}
4343static TIMER_CALLBACK( timer_callback_3812_0 )
4444{
r2724r2725
207207static void IRQHandler_3526(void *param,int irq)
208208{
209209   struct ym3526_info *info = param;
210   if (info->intf->handler) (info->intf->handler)(irq ? ASSERT_LINE : CLEAR_LINE);
210   if (info->intf->handler) (info->intf->handler)(Machine, irq ? ASSERT_LINE : CLEAR_LINE);
211211}
212212/* Timer overflow callback from timer.c */
213213static TIMER_CALLBACK( timer_callback_3526_0 )
r2724r2725
374374static void IRQHandler_8950(void *param,int irq)
375375{
376376   struct y8950_info *info = param;
377   if (info->intf->handler) (info->intf->handler)(irq ? ASSERT_LINE : CLEAR_LINE);
377   if (info->intf->handler) (info->intf->handler)(Machine, irq ? ASSERT_LINE : CLEAR_LINE);
378378}
379379static TIMER_CALLBACK( timer_callback_8950_0 )
380380{
src/emu/sound/3812intf.h
r2724r2725
44
55struct YM3812interface
66{
7   void (*handler)(int linestate);
7   void (*handler)(running_machine *machine, int linestate);
88};
99
1010#define YM3526interface YM3812interface
1111
1212struct Y8950interface
1313{
14   void (*handler)(int linestate);
14   void (*handler)(running_machine *machine, int linestate);
1515
1616   int rom_region; /* delta-T ADPCM ROM/RAM region */
1717
src/emu/sound/ymz280b.c
r2724r2725
8989   UINT8 irq_enable;            /* current IRQ enable */
9090   UINT8 keyon_enable;            /* key on enable */
9191   double master_clock;         /* master clock frequency */
92   void (*irq_callback)(int);      /* IRQ callback */
92   void (*irq_callback)(running_machine *, int);      /* IRQ callback */
9393   struct YMZ280BVoice   voice[8];   /* the 8 voices */
9494   UINT32 rom_readback_addr;      /* where the CPU can read the ROM */
9595   read8_machine_func ext_ram_read;      /* external RAM read handler */
r2724r2725
145145   {
146146      chip->irq_state = 1;
147147      if (chip->irq_callback)
148         (*chip->irq_callback)(1);
148         (*chip->irq_callback)(Machine, 1);
149149      else logerror("YMZ280B: IRQ generated, but no callback specified!");
150150   }
151151   else if (!irq_bits && chip->irq_state)
152152   {
153153      chip->irq_state = 0;
154154      if (chip->irq_callback)
155         (*chip->irq_callback)(0);
155         (*chip->irq_callback)(Machine, 0);
156156      else logerror("YMZ280B: IRQ generated, but no callback specified!");
157157   }
158158}
src/emu/sound/ymz280b.h
r2724r2725
1111struct YMZ280Binterface
1212{
1313   int region;                  /* memory region where the sample ROM lives */
14   void (*irq_callback)(int state);   /* irq callback */
14   void (*irq_callback)(running_machine *machine, int state);   /* irq callback */
1515   read8_machine_func ext_read;         /* external RAM read */
1616   write8_machine_func ext_write;      /* external RAM write */
1717};
src/emu/sound/tms5110r.c
r2724r2725
2626 *
2727 * Instead,  { 8, 8, 8, 4, 4, 4, 2, 1 }
2828 * will calculate those coefficients and this has been used below.
29 * LN:
30 * The real chip uses shifters and not true division to achieve those factors,
31 * so they have been replaced by the shifting coefficients:
32 * { 3, 3, 3, 2, 2, 2, 1, 0 }
2933 */
3034
3135static const struct tms5100_coeffs pat4209836_coeff =
r2724r2725
8589       1,  0,    0,  0,   0,  0,  0,  0,
8690       0,  0,    0 },
8791   /* interpolation coefficients */
88   { 8, 8, 8, 4, 4, 4, 2, 1 }
92   { 3, 3, 3, 2, 2, 2, 1, 0 }
8993};
9094
9195/*
r2724r2725
161165   0,0,0
162166    },
163167   /* interpolation coefficients */
164   { 8, 8, 8, 4, 4, 4, 2, 1 }
168   { 3, 3, 3, 2, 2, 2, 1, 0 }
165169};
166170
167171
r2724r2725
228232       1,  0,    0,  0,   0,  0,  0,  0,
229233       0,  0,    0 },
230234   /* interpolation coefficients */
231   { 8, 8, 8, 4, 4, 4, 2, 1 }
235   { 3, 3, 3, 2, 2, 2, 1, 0 }
232236};
233237
234238
src/emu/sound/aica.c
r2724r2725
175175   unsigned char *AICARAM;
176176   UINT32 AICARAM_LENGTH, RAM_MASK, RAM_MASK16;
177177   char Master;
178   void (*IntARMCB)(int irq);
178   void (*IntARMCB)(running_machine *machine, int irq);
179179   sound_stream * stream;
180180
181181   INT32 *buffertmpl, *buffertmpr;
r2724r2725
233233{
234234#if 0
235235   UINT32 reset = AICA->udata.data[0xa4/2];
236   running_machine *machine = Machine;
237
236238   if (reset & 0x40)
237      AICA->IntARMCB(-AICA->IrqTimA);
239      AICA->IntARMCB(machine, -AICA->IrqTimA);
238240   if (reset & 0x180)
239      AICA->IntARMCB(-AICA->IrqTimBC);
241      AICA->IntARMCB(machine, -AICA->IrqTimBC);
240242#endif
241243}
242244
r2724r2725
244246{
245247   UINT32 pend=AICA->udata.data[0xa0/2];
246248   UINT32 en=AICA->udata.data[0x9c/2];
249   running_machine *machine = Machine;
250
247251   if(AICA->MidiW!=AICA->MidiR)
248252   {
249253      AICA->IRQL = AICA->IrqMidi;
250      AICA->IntARMCB(1);
254      AICA->IntARMCB(machine, 1);
251255      return;
252256   }
253257   if(!pend)
r2724r2725
256260      if(en&0x40)
257261      {
258262         AICA->IRQL = AICA->IrqTimA;
259         AICA->IntARMCB(1);
263         AICA->IntARMCB(machine, 1);
260264         return;
261265      }
262266   if(pend&0x80)
263267      if(en&0x80)
264268      {
265269         AICA->IRQL = AICA->IrqTimBC;
266         AICA->IntARMCB(1);
270         AICA->IntARMCB(machine, 1);
267271         return;
268272      }
269273   if(pend&0x100)
270274      if(en&0x100)
271275      {
272276         AICA->IRQL = AICA->IrqTimBC;
273         AICA->IntARMCB(1);
277         AICA->IntARMCB(machine, 1);
274278         return;
275279      }
276280}
r2724r2725
856860            unsigned short v=AICA->udata.data[0x8/2];
857861            v&=0xff00;
858862            v|=AICA->MidiStack[AICA->MidiR];
859            AICA->IntARMCB(0);   // cancel the IRQ
863            AICA->IntARMCB(Machine, 0);   // cancel the IRQ
860864            if(AICA->MidiR!=AICA->MidiW)
861865            {
862866               ++AICA->MidiR;
r2724r2725
922926
923927         if (val)
924928         {
925            AICA->IntARMCB(0);
929            AICA->IntARMCB(Machine, 0);
926930         }
927931      }
928932   }
src/emu/sound/aica.h
r2724r2725
1212{
1313   int region;            /* region of 2M/8M RAM */
1414   int roffset;            /* offset in the region */
15   void (*irq_callback)(int state);   /* irq callback */
15   void (*irq_callback)(running_machine *machine, int state);   /* irq callback */
1616};
1717
1818void AICA_set_ram_base(int which, void *base, int size);
src/emu/sound/ymf271.c
r2724r2725
110110   const UINT8 *rom;
111111   read8_machine_func ext_mem_read;
112112   write8_machine_func ext_mem_write;
113   void (*irq_callback)(int);
113   void (*irq_callback)(running_machine *, int);
114114
115115   int index;
116116   UINT32 clock;
r2724r2725
13561356   if (chip->enable & 4)
13571357   {
13581358      chip->irqstate |= 1;
1359      if (chip->irq_callback) chip->irq_callback(1);
1359      if (chip->irq_callback) chip->irq_callback(machine, 1);
13601360   }
13611361}
13621362
r2724r2725
13691369   if (chip->enable & 8)
13701370   {
13711371      chip->irqstate |= 2;
1372      if (chip->irq_callback) chip->irq_callback(1);
1372      if (chip->irq_callback) chip->irq_callback(machine, 1);
13731373   }
13741374}
13751375
r2724r2725
13961396   int slotnum;
13971397   YMF271Group *group;
13981398   attotime period;
1399   running_machine *machine = Machine;
13991400
14001401   slotnum = fm_tab[chip->timerreg & 0xf];
14011402   group = &chip->groups[slotnum];
r2724r2725
14531454               chip->irqstate &= ~1;
14541455               chip->status &= ~1;
14551456
1456               if (chip->irq_callback) chip->irq_callback(0);
1457               if (chip->irq_callback) chip->irq_callback(machine, 0);
14571458
14581459               //period = (double)(256.0 - chip->timerAVal ) * ( 384.0 * 4.0 / (double)CLOCK);
14591460               period = attotime_mul(ATTOTIME_IN_HZ(chip->clock), 384 * (1024 - chip->timerAVal));
r2724r2725
14651466               chip->irqstate &= ~2;
14661467               chip->status &= ~2;
14671468
1468               if (chip->irq_callback) chip->irq_callback(0);
1469               if (chip->irq_callback) chip->irq_callback(machine, 0);
14691470
14701471               period = attotime_mul(ATTOTIME_IN_HZ(chip->clock), 384 * 16 * (256 - chip->timerBVal));
14711472
r2724r2725
17261727   state_save_register_item("ymf271", chip->index, chip->ext_read);
17271728}
17281729
1729static void ymf271_init(YMF271Chip *chip, UINT8 *rom, void (*cb)(int), read8_machine_func ext_read, write8_machine_func ext_write)
1730static void ymf271_init(YMF271Chip *chip, UINT8 *rom, void (*cb)(running_machine *,int), read8_machine_func ext_read, write8_machine_func ext_write)
17301731{
17311732   chip->timA = timer_alloc(ymf271_timer_a_tick, chip);
17321733   chip->timB = timer_alloc(ymf271_timer_b_tick, chip);
src/emu/sound/pokey.c
r2724r2725
185185   read8_machine_func allpot_r;
186186   read8_machine_func serin_r;
187187   write8_machine_func serout_w;
188   void (*interrupt_cb)(int mask);
188   void (*interrupt_cb)(running_machine *machine, int mask);
189189    UINT8 AUDF[4];          /* AUDFx (D200, D202, D204, D206) */
190190   UINT8 AUDC[4];         /* AUDCx (D201, D203, D205, D207) */
191191   UINT8 POTx[8];         /* POTx   (R/D200-D207) */
r2724r2725
698698      p->IRQST |= timers;
699699        /* call back an application supplied function to handle the interrupt */
700700      if( p->interrupt_cb )
701         (*p->interrupt_cb)(timers);
701         (*p->interrupt_cb)(machine, timers);
702702    }
703703}
704704
r2724r2725
761761      p->IRQST |= IRQ_SERIN;
762762      /* call back an application supplied function to handle the interrupt */
763763      if( p->interrupt_cb )
764         (*p->interrupt_cb)(IRQ_SERIN);
764         (*p->interrupt_cb)(machine, IRQ_SERIN);
765765   }
766766}
767767
r2724r2725
772772   {
773773      p->IRQST |= IRQ_SEROR;
774774      if( p->interrupt_cb )
775         (*p->interrupt_cb)(IRQ_SEROR);
775         (*p->interrupt_cb)(machine, IRQ_SEROR);
776776   }
777777}
778778
r2724r2725
783783   {
784784      p->IRQST |= IRQ_SEROC;
785785      if( p->interrupt_cb )
786         (*p->interrupt_cb)(IRQ_SEROC);
786         (*p->interrupt_cb)(machine, IRQ_SEROC);
787787   }
788788}
789789
r2724r2725
14361436      /* set break IRQ status and call back the interrupt handler */
14371437      p->IRQST |= IRQ_BREAK;
14381438      if( p->interrupt_cb )
1439         (*p->interrupt_cb)(IRQ_BREAK);
1439         (*p->interrupt_cb)(Machine, IRQ_BREAK);
14401440    }
14411441}
14421442
r2724r2725
14801480            p->SKSTAT |= SK_KBERR;
14811481         p->IRQST |= IRQ_KEYBD;
14821482         if( p->interrupt_cb )
1483            (*p->interrupt_cb)(IRQ_KEYBD);
1483            (*p->interrupt_cb)(Machine, IRQ_KEYBD);
14841484      }
14851485   }
14861486   else
src/emu/sound/ymf271.h
r2724r2725
66   int region;         /* memory region of sample ROMs */
77   read8_machine_func ext_read;      /* external memory read */
88   write8_machine_func ext_write;   /* external memory write */
9   void (*irq_callback)(int state);   /* irq callback */
9   void (*irq_callback)(running_machine *machine, int state);   /* irq callback */
1010};
1111
1212READ8_HANDLER( YMF271_0_r );
src/emu/sound/pokey.h
r2724r2725
7171   read8_machine_func allpot_r;
7272   read8_machine_func serin_r;
7373   write8_machine_func serout_w;
74   void (*interrupt_cb)(int mask);
74   void (*interrupt_cb)(running_machine *machine, int mask);
7575};
7676
7777
src/emu/sound/ym2151.c
r2724r2725
165165
166166   UINT32      noise_tab[32];         /* 17bit Noise Generator periods */
167167
168   void (*irqhandler)(int irq);      /* IRQ function handler */
168   void (*irqhandler)(running_machine *machine, int irq);      /* IRQ function handler */
169169   write8_machine_func porthandler;      /* port write function handler */
170170
171171   unsigned int clock;               /* chip clock in Hz (passed from 2151intf.c) */
r2724r2725
791791
792792   chip->irqlinestate |= 1;
793793
794   if (oldstate == 0 && chip->irqhandler) (*chip->irqhandler)(1);
794   if (oldstate == 0 && chip->irqhandler) (*chip->irqhandler)(machine, 1);
795795}
796796
797797static TIMER_CALLBACK( irqBon_callback )
r2724r2725
801801
802802   chip->irqlinestate |= 2;
803803
804   if (oldstate == 0 && chip->irqhandler) (*chip->irqhandler)(1);
804   if (oldstate == 0 && chip->irqhandler) (*chip->irqhandler)(machine, 1);
805805}
806806
807807static TIMER_CALLBACK( irqAoff_callback )
r2724r2725
811811
812812   chip->irqlinestate &= ~1;
813813
814   if (oldstate == 1 && chip->irqhandler) (*chip->irqhandler)(0);
814   if (oldstate == 1 && chip->irqhandler) (*chip->irqhandler)(machine, 0);
815815}
816816
817817static TIMER_CALLBACK( irqBoff_callback )
r2724r2725
821821
822822   chip->irqlinestate &= ~2;
823823
824   if (oldstate == 2 && chip->irqhandler) (*chip->irqhandler)(0);
824   if (oldstate == 2 && chip->irqhandler) (*chip->irqhandler)(machine, 0);
825825}
826826
827827static TIMER_CALLBACK( timer_callback_a )
r2724r2725
11121112#else
11131113            int oldstate = chip->status & 3;
11141114            chip->status &= ~1;
1115            if ((oldstate==1) && (chip->irqhandler)) (*chip->irqhandler)(0);
1115            if ((oldstate==1) && (chip->irqhandler)) (*chip->irqhandler)(machine, 0);
11161116#endif
11171117         }
11181118
r2724r2725
11241124#else
11251125            int oldstate = chip->status & 3;
11261126            chip->status &= ~2;
1127            if ((oldstate==2) && (chip->irqhandler)) (*chip->irqhandler)(0);
1127            if ((oldstate==2) && (chip->irqhandler)) (*chip->irqhandler)(machine, 0);
11281128#endif
11291129         }
11301130
r2724r2725
24032403         {
24042404            int oldstate = PSG->status & 3;
24052405            PSG->status |= 2;
2406            if ((!oldstate) && (PSG->irqhandler)) (*PSG->irqhandler)(1);
2406            if ((!oldstate) && (PSG->irqhandler)) (*PSG->irqhandler)(machine, 1);
24072407         }
24082408      }
24092409   }
r2724r2725
24812481            {
24822482               int oldstate = PSG->status & 3;
24832483               PSG->status |= 1;
2484               if ((!oldstate) && (PSG->irqhandler)) (*PSG->irqhandler)(1);
2484               if ((!oldstate) && (PSG->irqhandler)) (*PSG->irqhandler)(machine, 1);
24852485            }
24862486            if (PSG->irq_enable & 0x80)
24872487               PSG->csm_req = 2;   /* request KEY ON / KEY OFF sequence */
r2724r2725
24922492   }
24932493}
24942494
2495void YM2151SetIrqHandler(void *chip, void(*handler)(int irq))
2495void YM2151SetIrqHandler(void *chip, void(*handler)(running_machine *machine, int irq))
24962496{
24972497   YM2151 *PSG = chip;
24982498   PSG->irqhandler = handler;
src/emu/sound/ym2151.h
r2724r2725
7676int YM2151ReadStatus(void *chip);
7777
7878/* set interrupt handler on YM2151 chip number 'n'*/
79void YM2151SetIrqHandler(void *chip, void (*handler)(int irq));
79void YM2151SetIrqHandler(void *chip, void (*handler)(running_machine *machine, int irq));
8080
8181/* set port write handler on YM2151 chip number 'n'*/
8282void YM2151SetPortWriteHandler(void *chip, write8_machine_func handler);
src/emu/sound/scsp.c
r2724r2725
194194   unsigned char *SCSPRAM;
195195   UINT32 SCSPRAM_LENGTH;
196196   char Master;
197   void (*Int68kCB)(int irq);
197   void (*Int68kCB)(running_machine *machine, int irq);
198198   sound_stream * stream;
199199
200200   INT32 *buffertmpl,*buffertmpr;
r2724r2725
226226   struct _SCSPDSP DSP;
227227};
228228
229static void dma_scsp(struct _SCSP *SCSP);       /*SCSP DMA transfer function*/
229static void dma_scsp(running_machine *machine, struct _SCSP *SCSP);       /*SCSP DMA transfer function*/
230230#define   scsp_dgate      scsp_regs[0x16/2] & 0x4000
231231#define   scsp_ddir      scsp_regs[0x16/2] & 0x2000
232232#define scsp_dexe       scsp_regs[0x16/2] & 0x1000
r2724r2725
259259{
260260   UINT32 pend=SCSP->udata.data[0x20/2];
261261   UINT32 en=SCSP->udata.data[0x1e/2];
262   running_machine *machine = Machine;
263
262264   if(SCSP->MidiW!=SCSP->MidiR)
263265   {
264266      SCSP->udata.data[0x20/2] |= 8;
r2724r2725
269271   if(pend&0x40)
270272      if(en&0x40)
271273      {
272         SCSP->Int68kCB(SCSP->IrqTimA);
274         SCSP->Int68kCB(machine, SCSP->IrqTimA);
273275         return;
274276      }
275277   if(pend&0x80)
276278      if(en&0x80)
277279      {
278         SCSP->Int68kCB(SCSP->IrqTimBC);
280         SCSP->Int68kCB(machine, SCSP->IrqTimBC);
279281         return;
280282      }
281283   if(pend&0x100)
282284      if(en&0x100)
283285      {
284         SCSP->Int68kCB(SCSP->IrqTimBC);
286         SCSP->Int68kCB(machine, SCSP->IrqTimBC);
285287         return;
286288      }
287289   if(pend&8)
288290      if (en&8)
289291      {
290         SCSP->Int68kCB(SCSP->IrqMidi);
292         SCSP->Int68kCB(machine, SCSP->IrqMidi);
291293         SCSP->udata.data[0x20/2] &= ~8;
292294         return;
293295      }
294296
295   SCSP->Int68kCB(0);
297   SCSP->Int68kCB(machine, 0);
296298}
297299
298300static void ResetInterrupts(struct _SCSP *SCSP)
299301{
300302   UINT32 reset = SCSP->udata.data[0x22/2];
303   running_machine *machine = Machine;
301304
302305   if (reset & 0x40)
303306   {
304      SCSP->Int68kCB(-SCSP->IrqTimA);
307      SCSP->Int68kCB(machine, -SCSP->IrqTimA);
305308   }
306309   if (reset & 0x180)
307310   {
308      SCSP->Int68kCB(-SCSP->IrqTimBC);
311      SCSP->Int68kCB(machine, -SCSP->IrqTimBC);
309312   }
310313   if (reset & 0x8)
311314   {
312      SCSP->Int68kCB(-SCSP->IrqMidi);
315      SCSP->Int68kCB(machine, -SCSP->IrqMidi);
313316   }
314317
315318   CheckPendingIRQ(SCSP);
r2724r2725
833836            unsigned short v=SCSP->udata.data[0x5/2];
834837            v&=0xff00;
835838            v|=SCSP->MidiStack[SCSP->MidiR];
836            SCSP[0].Int68kCB(-SCSP->IrqMidi);   // cancel the IRQ
839            SCSP[0].Int68kCB(Machine, -SCSP->IrqMidi);   // cancel the IRQ
837840            if(SCSP->MidiR!=SCSP->MidiW)
838841            {
839842               ++SCSP->MidiR;
r2724r2725
11471150   }
11481151}
11491152
1150static void dma_scsp(struct _SCSP *SCSP)
1153static void dma_scsp(running_machine *machine, struct _SCSP *SCSP)
11511154{
11521155   static UINT16 tmp_dma[3], *scsp_regs;
11531156
r2724r2725
11951198
11961199   /*Job done,request a dma end irq*/
11971200   if(scsp_regs[0x1e/2] & 0x10)
1198   cpunum_set_input_line(Machine, 2,dma_transfer_end,HOLD_LINE);
1201   cpunum_set_input_line(machine, 2,dma_transfer_end,HOLD_LINE);
11991202}
12001203
12011204#ifdef UNUSED_FUNCTION
r2724r2725
13021305      SCSP->scsp_dtlg = scsp_regs[0x416/2] & 0x0ffe;
13031306      if(scsp_dexe)
13041307      {
1305         dma_scsp(SCSP);
1308         dma_scsp(machine, SCSP);
13061309         scsp_regs[0x416/2]^=0x1000;//disable starting bit
13071310      }
13081311      break;
src/emu/sound/2610intf.c
r2724r2725
6666static void IRQHandler(void *param,int irq)
6767{
6868   struct ym2610_info *info = param;
69   if(info->intf->handler) info->intf->handler(irq);
69   if(info->intf->handler) info->intf->handler(Machine, irq);
7070}
7171
7272/* Timer overflow callback from timer.c */
src/emu/sound/scsp.h
r2724r2725
1010{
1111   int region;             /* region of 512k RAM */
1212   int roffset;            /* offset in the region */
13   void (*irq_callback)(int state);   /* irq callback */
13   void (*irq_callback)(running_machine *machine, int state);   /* irq callback */
1414};
1515
1616void SCSP_set_ram_base(int which, void *base);
src/emu/sound/2610intf.h
r2724r2725
55
66struct YM2610interface
77{
8   void ( *handler )( int irq );   /* IRQ handler for the YM2610 */
8   void ( *handler )( running_machine *machine, int irq );   /* IRQ handler for the YM2610 */
99   int pcmromb;      /* Delta-T rom region */
1010   int pcmroma;      /* ADPCM   rom region */
1111};
src/emu/sound/ics2115.c
r2724r2725
77
88#include <math.h>
99#include "sndintrf.h"
10#include "deprecat.h"
1011#include "streams.h"
1112#include "cpuintrf.h"
1213#include "ics2115.h"
r2724r2725
9192   if(irq != chip->irq_on) {
9293      chip->irq_on = irq;
9394      if(chip->intf->irq_cb)
94         chip->intf->irq_cb(irq ? ASSERT_LINE : CLEAR_LINE);
95         chip->intf->irq_cb(Machine, irq ? ASSERT_LINE : CLEAR_LINE);
9596   }
9697}
9798
src/emu/sound/ics2115.h
r2724r2725
33
44struct ics2115_interface {
55   int region;
6   void (*irq_cb)(int);
6   void (*irq_cb)(running_machine *, int);
77};
88
99READ8_HANDLER( ics2115_r );
src/emu/sound/2608intf.c
r2724r2725
6666static void IRQHandler(void *param,int irq)
6767{
6868   struct ym2608_info *info = param;
69   if(info->intf->handler) info->intf->handler(irq);
69   if(info->intf->handler) info->intf->handler(Machine, irq);
7070}
7171
7272/* Timer overflow callback from timer.c */
src/emu/sound/2608intf.h
r2724r2725
77struct YM2608interface
88{
99   const struct AY8910interface ay8910_intf;
10   void ( *handler )( int irq );   /* IRQ handler for the YM2608 */
10   void ( *handler )( running_machine *machine, int irq );   /* IRQ handler for the YM2608 */
1111   int pcmrom;      /* Delta-T memory region ram/rom */
1212};
1313
src/emu/sound/es5506.c
r2724r2725
99#include <math.h>
1010
1111#include "sndintrf.h"
12#include "deprecat.h"
1213#include "streams.h"
1314#include "cpuintrf.h"
1415#include "es5506.h"
r2724r2725
104105   UINT32       write_latch;         /* currently accumulated data for write */
105106   UINT32       read_latch;            /* currently accumulated data for read */
106107   UINT32       master_clock;         /* master clock frequency */
107   void       (*irq_callback)(int);   /* IRQ callback */
108   void       (*irq_callback)(running_machine *, int);   /* IRQ callback */
108109   UINT16      (*port_read)(void);      /* input port read */
109110
110111   UINT8       current_page;         /* current register page */
r2724r2725
149150{
150151   /* ES5505/6 irq line has been set high - inform the host */
151152   if (chip->irq_callback)
152      (*chip->irq_callback)(1); /* IRQB set high */
153      (*chip->irq_callback)(Machine, 1); /* IRQB set high */
153154}
154155
155156static void update_internal_irq_state(struct ES5506Chip *chip)
r2724r2725
166167   chip->irqv=0x80;
167168
168169   if (chip->irq_callback)
169      (*chip->irq_callback)(0); /* IRQB set low */
170      (*chip->irq_callback)(Machine, 0); /* IRQB set low */
170171}
171172
172173/**********************************************************************************************
src/emu/sound/es5506.h
r2724r2725
1212{
1313   int region0;                  /* memory region where the sample ROM lives */
1414   int region1;                  /* memory region where the sample ROM lives */
15   void (*irq_callback)(int state);   /* irq callback */
15   void (*irq_callback)(running_machine *machine, int state);   /* irq callback */
1616   UINT16 (*read_port)(void);         /* input port read */
1717};
1818
r2724r2725
3333   int region1;                  /* memory region where the sample ROM lives */
3434   int region2;                  /* memory region where the sample ROM lives */
3535   int region3;                  /* memory region where the sample ROM lives */
36   void (*irq_callback)(int state);   /* irq callback */
36   void (*irq_callback)(running_machine *machine, int state);   /* irq callback */
3737   UINT16 (*read_port)(void);         /* input port read */
3838};
3939
src/emu/sound/ymf278b.c
r2724r2725
118118   int irq_line;
119119
120120   UINT8 port_A, port_B, port_C;
121   void (*irq_callback)(int);
121   void (*irq_callback)(running_machine *, int);
122122
123123   const UINT8 *rom;
124124   int clock;
r2724r2725
336336   }
337337}
338338
339static void ymf278b_irq_check(YMF278BChip *chip)
339static void ymf278b_irq_check(running_machine *machine, YMF278BChip *chip)
340340{
341341   int prev_line = chip->irq_line;
342342   chip->irq_line = chip->current_irq ? ASSERT_LINE : CLEAR_LINE;
343343   if(chip->irq_line != prev_line && chip->irq_callback)
344      chip->irq_callback(chip->irq_line);
344      chip->irq_callback(machine, chip->irq_line);
345345}
346346
347347static TIMER_CALLBACK( ymf278b_timer_a_tick )
r2724r2725
350350   if(!(chip->enable & 0x40))
351351   {
352352      chip->current_irq |= 0x40;
353      ymf278b_irq_check(chip);
353      ymf278b_irq_check(machine, chip);
354354   }
355355}
356356
r2724r2725
360360   if(!(chip->enable & 0x20))
361361   {
362362      chip->current_irq |= 0x20;
363      ymf278b_irq_check(chip);
363      ymf278b_irq_check(machine, chip);
364364   }
365365}
366366
r2724r2725
394394      timer_adjust_oneshot(chip->timer_b, attotime_never, 0);
395395}
396396
397static void ymf278b_A_w(YMF278BChip *chip, UINT8 reg, UINT8 data)
397static void ymf278b_A_w(running_machine *machine, YMF278BChip *chip, UINT8 reg, UINT8 data)
398398{
399399   switch(reg)
400400   {
r2724r2725
419419            if((old_enable ^ data) & 2)
420420               ymf278b_timer_b_reset(chip);
421421         }
422         ymf278b_irq_check(chip);
422         ymf278b_irq_check(machine, chip);
423423         break;
424424      default:
425425         logerror("YMF278B:  Port A write %02x, %02x\n", reg, data);
r2724r2725
624624   chip->port_A = data;
625625}
626626
627static void ymf278b_data_port_A_w(int num, UINT8 data)
627static void ymf278b_data_port_A_w(running_machine *machine, int num, UINT8 data)
628628{
629629   YMF278BChip *chip = sndti_token(SOUND_YMF278B, num);
630   ymf278b_A_w(chip, chip->port_A, data);
630   ymf278b_A_w(machine, chip, chip->port_A, data);
631631}
632632
633633static void ymf278b_control_port_B_w(int num, UINT8 data)
r2724r2725
654654   ymf278b_C_w(chip, chip->port_C, data);
655655}
656656
657static void ymf278b_init(YMF278BChip *chip, UINT8 *rom, void (*cb)(int), int clock)
657static void ymf278b_init(YMF278BChip *chip, UINT8 *rom, void (*cb)(running_machine *, int), int clock)
658658{
659659   chip->rom = rom;
660660   chip->irq_callback = cb;
r2724r2725
720720
721721WRITE8_HANDLER( YMF278B_data_port_0_A_w )
722722{
723   ymf278b_data_port_A_w(0, data);
723   ymf278b_data_port_A_w(machine, 0, data);
724724}
725725
726726WRITE8_HANDLER( YMF278B_control_port_0_B_w )
r2724r2725
761761
762762WRITE8_HANDLER( YMF278B_data_port_1_A_w )
763763{
764   ymf278b_data_port_A_w(1, data);
764   ymf278b_data_port_A_w(machine, 1, data);
765765}
766766
767767WRITE8_HANDLER( YMF278B_control_port_1_B_w )
src/emu/sound/ymf278b.h
r2724r2725
55
66struct YMF278B_interface {
77   int region;         /* memory region of sample ROMs */
8   void (*irq_callback)(int state);   /* irq callback */
8   void (*irq_callback)(running_machine *machine, int state);   /* irq callback */
99};
1010
1111READ8_HANDLER( YMF278B_status_port_0_r );
src/emu/sound/psx.c
r2724r2725
1010
1111#include <stdarg.h>
1212#include "sndintrf.h"
13#include "deprecat.h"
1314#include "streams.h"
1415#include "cpuintrf.h"
1516#include "psx.h"
r2724r2725
154155               ( chip->m_n_irqaddress * 4 ) >= chip->m_p_n_blockaddress[ n_channel ] &&
155156               ( chip->m_n_irqaddress * 4 ) <= chip->m_p_n_blockaddress[ n_channel ] + 7 )
156157            {
157               chip->intf->irq_set( 0x0200 );
158               chip->intf->irq_set( Machine, 0x0200 );
158159            }
159160
160161            n_shift =   ( chip->m_p_n_spuram[ chip->m_p_n_blockaddress[ n_channel ] ] >> 0 ) & 0x0f;
src/emu/sound/5220intf.h
r2724r2725
77
88struct TMS5220interface
99{
10   void (*irq)(int state);      /* IRQ callback function */
10   void (*irq)(running_machine *machine, int state);      /* IRQ callback function */
1111
1212   int (*read)(int count);         /* speech ROM read callback */
1313   void (*load_address)(int data);   /* speech ROM load address callback */
src/emu/sound/2151intf.h
r2724r2725
33
44struct YM2151interface
55{
6   void (*irqhandler)(int irq);
6   void (*irqhandler)(running_machine *machine, int irq);
77   write8_machine_func portwritehandler;
88};
99
src/emu/sound/psx.h
r2724r2725
1818struct PSXSPUinterface
1919{
2020   UINT32 **p_psxram;
21   void (*irq_set)(UINT32);
21   void (*irq_set)(running_machine *,UINT32);
2222   void (*spu_install_read_handler)(int,spu_handler);
2323   void (*spu_install_write_handler)(int,spu_handler);
2424};
src/emu/sound/2203intf.c
r2724r2725
5252static void IRQHandler(void *param,int irq)
5353{
5454   struct ym2203_info *info = param;
55   if(info->intf->handler) info->intf->handler(irq);
55   if(info->intf->handler) info->intf->handler(Machine, irq);
5656}
5757
5858/* Timer overflow callback from timer.c */
src/emu/sound/2203intf.h
r2724r2725
66struct YM2203interface
77{
88   const struct AY8910interface ay8910_intf;
9   void (*handler)(int irq);
9   void (*handler)(running_machine *machine, int irq);
1010};
1111
1212
src/emu/sound/tms5220.c
r2724r2725
1010     Chirp/excitation table fixes by Lord Nightmare
1111     Various fixes by Lord Nightmare
1212     Modularization by Lord Nightmare
13     Sub-interpolation-cycle parameter updating added by Lord Nightmare
1314
1415     Much information regarding these lpc encoding comes from US patent 4,209,844
1516     US patent 4,331,836 describes the complete 51xx chip
r2724r2725
1920***********************************************************************************************/
2021
2122#include "sndintrf.h"
23#include "deprecat.h"
2224#include "tms5220.h"
2325
2426
r2724r2725
6971   UINT8 buffer_empty;      /* FIFO is empty*/
7072   UINT8 irq_pin;         /* state of the IRQ pin (output) */
7173
72   void (*irq_func)(int state); /* called when the state of the IRQ pin changes */
74   void (*irq_func)(running_machine *machine, int state); /* called when the state of the IRQ pin changes */
7375
7476
7577   /* these contain data describing the current and previous voice frames */
r2724r2725
9395
9496   UINT16 previous_energy;         /* needed for lattice filter to match patent */
9597
96   UINT8 interp_count;      /* number of interp periods (0-7) */
97   UINT8 sample_count;      /* sample number within interp (0-24) */
98   UINT16 pitch_count;
98   UINT8 interp_count;      /* number of samples within each sub-interpolation period, ranges from 0-24 */
99   UINT8 sample_count;      /* number of samples within the ENTIRE interpolation period, ranges from 0-199 */
100   UINT16 pitch_count;      /* pitch counter; provides chirp rom address */
99101
100102   INT32 u[11];
101103   INT32 x[10];
r2724r2725
233235   /* initialize the chip state */
234236   /* Note that we do not actually clear IRQ on start-up : IRQ is even raised if tms->buffer_empty or tms->buffer_low are 0 */
235237   tms->tms5220_speaking = tms->speak_external = tms->talk_status = tms->first_frame = tms->last_frame = tms->irq_pin = 0;
236   if (tms->irq_func) tms->irq_func(0);
238   if (tms->irq_func) tms->irq_func(Machine, 0);
237239   tms->buffer_empty = tms->buffer_low = 1;
238240
239241   tms->RDB_flag = FALSE;
r2724r2725
266268
267269***********************************************************************************************/
268270
269void tms5220_set_irq(void *chip, void (*func)(int))
271void tms5220_set_irq(void *chip, void (*func)(running_machine *, int))
270272{
271273   struct tms5220 *tms = chip;
272274    tms->irq_func = func;
r2724r2725
595597                }
596598            }
597599        }
598        else if (tms->interp_count == 0)
600        else
599601        {
600            /* Update values based on step values */
601            /*mame_printf_debug("\n");*/
602
603602            interp_period = tms->sample_count / 25;
604            tms->current_energy += ((tms->target_energy - tms->current_energy) >> interp_coeff[interp_period]);
605            if (tms->old_pitch != 0)
606                tms->current_pitch += ((tms->target_pitch - tms->current_pitch) >> interp_coeff[interp_period]);
607
608            /*mame_printf_debug("*** Energy = %d\n",tms->current_energy);*/
609
610            for (i = 0; i < 10; i++)
611            {
612                tms->current_k[i] += ((tms->target_k[i] - tms->current_k[i]) >> interp_coeff[interp_period]);
613            }
603       switch(tms->interp_count)
604       {
605                /*         PC=X  X cycle, rendering change (change for next cycle which chip is actually doing) */
606      case 0: /* PC=0, A cycle, nothing happens (calc energy) */
607                  break;
608      case 1: /* PC=0, B cycle, nothing happens (update energy) */
609        break;
610      case 2: /* PC=1, A cycle, update energy (calc pitch) */
611        tms->current_energy += ((tms->target_energy - tms->current_energy) >> interp_coeff[interp_period]);
612                 break;
613                case 3: /* PC=1, B cycle, nothing happens (update pitch) */
614        break;
615                case 4: /* PC=2, A cycle, update pitch (calc K1) */
616                 if (tms->old_pitch != 0)
617                  tms->current_pitch += ((tms->target_pitch - tms->current_pitch) >> interp_coeff[interp_period]);
618        break;
619                case 5: /* PC=2, B cycle, nothing happens (update K1) */
620        break;
621      case 6: /* PC=3, A cycle, update K1 (calc K2) */
622        tms->current_k[0] += ((tms->target_k[0] - tms->current_k[0]) >> interp_coeff[interp_period]);
623                 break;
624                case 7: /* PC=3, B cycle, nothing happens (update K2) */
625        break;
626      case 8: /* PC=4, A cycle, update K2 (calc K3) */
627        tms->current_k[1] += ((tms->target_k[1] - tms->current_k[1]) >> interp_coeff[interp_period]);
628                 break;
629                case 9: /* PC=4, B cycle, nothing happens (update K3) */
630        break;
631      case 10: /* PC=5, A cycle, update K3 (calc K4) */
632        tms->current_k[2] += ((tms->target_k[2] - tms->current_k[2]) >> interp_coeff[interp_period]);
633                 break;
634                case 11: /* PC=5, B cycle, nothing happens (update K4) */
635        break;
636      case 12: /* PC=6, A cycle, update K4 (calc K5) */
637        tms->current_k[3] += ((tms->target_k[3] - tms->current_k[3]) >> interp_coeff[interp_period]);
638                 break;
639                case 13: /* PC=6, B cycle, nothing happens (update K5) */
640        break;
641      case 14: /* PC=7, A cycle, update K5 (calc K6) */
642        tms->current_k[4] += ((tms->target_k[4] - tms->current_k[4]) >> interp_coeff[interp_period]);
643                 break;
644                case 15: /* PC=7, B cycle, nothing happens (update K6) */
645        break;
646      case 16: /* PC=8, A cycle, update K6 (calc K7) */
647        tms->current_k[5] += ((tms->target_k[5] - tms->current_k[5]) >> interp_coeff[interp_period]);
648                 break;
649                case 17: /* PC=8, B cycle, nothing happens (update K7) */
650        break;
651      case 18: /* PC=9, A cycle, update K7 (calc K8) */
652        tms->current_k[6] += ((tms->target_k[6] - tms->current_k[6]) >> interp_coeff[interp_period]);
653                 break;
654                case 19: /* PC=9, B cycle, nothing happens (update K8) */
655        break;
656      case 20: /* PC=10, A cycle, update K8 (calc K9) */
657        tms->current_k[7] += ((tms->target_k[7] - tms->current_k[7]) >> interp_coeff[interp_period]);
658                 break;
659                case 21: /* PC=10, B cycle, nothing happens (update K9) */
660        break;
661      case 22: /* PC=11, A cycle, update K9 (calc K10) */
662        tms->current_k[8] += ((tms->target_k[8] - tms->current_k[8]) >> interp_coeff[interp_period]);
663                 break;
664                case 23: /* PC=11, B cycle, nothing happens (update K10) */
665        break;
666      case 24: /* PC=12, A cycle, update K10 (do nothing) */
667        tms->current_k[9] += ((tms->target_k[9] - tms->current_k[9]) >> interp_coeff[interp_period]);
668                 break;
669       }
614670        }
615671
616672        if (tms->old_energy == 0)
617673        {
618674            /* generate silent samples here */
619         tms->excitation_data = 0x00; /* I'm not sure if this is actually RIGHT, the current_energy may be forced to zero when we've just passed a zero energy frame. However, this does work too. May be removed later. */
675         tms->excitation_data = 0x00; /* This is NOT correct, the current_energy is forced to zero when we                         just passed a zero energy frame because thats what the tables hold for that value.
676                        However, this code does no harm. Will be removed later. */
620677        }
621678        else if (tms->old_pitch == 0)
622679        {
r2724r2725
642699              tms->excitation_data = chirptable[tms->pitch_count];
643700        }
644701
645        /* Update LFSR every clock, like patent shows */
646        bitout = ((tms->RNG >> 12) & 1) ^
647                 ((tms->RNG >> 10) & 1) ^
648                 ((tms->RNG >>  9) & 1) ^
649                 ((tms->RNG >>  0) & 1);
650        tms->RNG >>= 1;
651        tms->RNG |= bitout << 12;
702        /* Update LFSR *20* times every sample, like patent shows */
703   for (i=0; i<20; i++)
704   {
705            bitout = ((tms->RNG >> 12) & 1) ^
706                     ((tms->RNG >> 10) & 1) ^
707                     ((tms->RNG >>  9) & 1) ^
708                     ((tms->RNG >>  0) & 1);
709            tms->RNG >>= 1;
710            tms->RNG |= bitout << 12;
711   }
652712
653713      buffer[buf_count] = clip_and_wrap(lattice_filter(tms)); /* execute lattice filter and clipping/wrapping */
654714
r2724r2725
11121172static void set_interrupt_state(struct tms5220 *tms, int state)
11131173{
11141174    if (tms->irq_func && state != tms->irq_pin)
1115       tms->irq_func(state);
1175       tms->irq_func(Machine, state);
11161176    tms->irq_pin = state;
11171177}
src/emu/sound/tms5220.h
r2724r2725
55void tms5220_destroy(void *chip);
66
77void tms5220_reset_chip(void *chip);
8void tms5220_set_irq(void *chip, void (*func)(int));
8void tms5220_set_irq(void *chip, void (*func)(running_machine *, int));
99
1010void tms5220_data_write(void *chip, int data);
1111int tms5220_status_read(void *chip);
src/emu/sound/es5503.c
r2724r2725
3636#include <math.h>
3737#include "sndintrf.h"
3838#include "cpuintrf.h"
39#include "deprecat.h"
3940#include "es5503.h"
4041#include "streams.h"
4142#include "state.h"
r2724r2725
6768   int index;
6869   sound_stream * stream;
6970
70   void (*irq_callback)(int);   // IRQ callback
71   void (*irq_callback)(running_machine *machine, int);   // IRQ callback
7172
7273   read8_machine_func adc_read;      // callback for the 5503's built-in analog to digital converter
7374
r2724r2725
127128
128129      if (chip->irq_callback)
129130      {
130         chip->irq_callback(1);
131         chip->irq_callback(Machine, 1);
131132      }
132133   }
133134}
r2724r2725
347348
348349                  if (chip->irq_callback)
349350                  {
350                     chip->irq_callback(0);
351                     chip->irq_callback(machine, 0);
351352                  }
352353                  break;
353354               }
r2724r2725
360361               {
361362                  if (chip->irq_callback)
362363                  {
363                     chip->irq_callback(1);
364                     chip->irq_callback(machine, 1);
364365                  }
365366                  break;
366367               }
src/emu/sound/es5503.h
r2724r2725
33
44struct ES5503interface
55{
6   void (*irq_callback)(int state);
6   void (*irq_callback)(running_machine *machine, int state);
77   read8_machine_func adc_read;
88   UINT8 *wave_memory;
99};
src/emu/sound/262intf.c
r2724r2725
66
77***************************************************************************/
88#include "sndintrf.h"
9#include "deprecat.h"
910#include "streams.h"
1011#include "262intf.h"
1112#include "ymf262.h"
r2724r2725
2526static void IRQHandler_262(void *param,int irq)
2627{
2728   struct ymf262_info *info = param;
28   if (info->intf->handler) (info->intf->handler)(irq);
29   if (info->intf->handler) (info->intf->handler)(Machine, irq);
2930}
3031
3132static TIMER_CALLBACK( timer_callback_262_0 )
src/emu/inputseq.h
r2724r2725
174174   return 0;
175175}
176176
177
178/*-------------------------------------------------
179    input_seq_append_or - append a code to a
180    sequence; if the sequence is non-empty, insert
181    an OR before the new code
182-------------------------------------------------*/
183
184INLINE void input_seq_append_or(input_seq *seq, input_code code)
185{
186   int codenum;
187   if (seq->code[0] == SEQCODE_END || seq->code[0] == SEQCODE_DEFAULT)
188   {
189      seq->code[0] = code;
190      seq->code[1] = SEQCODE_END;
191   }
192   else
193   {
194      for (codenum = 0; codenum < ARRAY_LENGTH(seq->code) - 2; codenum++)
195         if (seq->code[codenum] == SEQCODE_END)
196         {
197            seq->code[codenum++] = SEQCODE_OR;
198            seq->code[codenum++] = code;
199            seq->code[codenum++] = SEQCODE_END;
200         }
201   }
202}
203
204
177205#endif   /* __INPUTSEQ_H__ */
src/emu/ui.c
r2724r2725
7272   INT32         defval;            /* default value */
7373   INT32         maxval;            /* maximum value */
7474   INT32         incval;            /* increment value */
75   INT32         (*update)(running_machine *machine, INT32 newval, char *buffer, int arg); /* callback */
76   int            arg;            /* argument */
75   INT32         (*update)(running_machine *machine, INT32 newval, char *buffer, void *arg); /* callback */
76   void *         arg;            /* argument */
7777};
7878
7979
r2724r2725
139139static void slider_init(running_machine *machine);
140140static void slider_display(const char *text, int minval, int maxval, int defval, int curval);
141141static void slider_draw_bar(float leftx, float topy, float width, float height, float percentage, float default_percentage);
142static INT32 slider_volume(running_machine *machine, INT32 newval, char *buffer, int arg);
143static INT32 slider_mixervol(running_machine *machine, INT32 newval, char *buffer, int arg);
144static INT32 slider_adjuster(running_machine *machine, INT32 newval, char *buffer, int arg);
145static INT32 slider_overclock(running_machine *machine, INT32 newval, char *buffer, int arg);
146static INT32 slider_refresh(running_machine *machine, INT32 newval, char *buffer, int arg);
147static INT32 slider_brightness(running_machine *machine, INT32 newval, char *buffer, int arg);
148static INT32 slider_contrast(running_machine *machine, INT32 newval, char *buffer, int arg);
149static INT32 slider_gamma(running_machine *machine, INT32 newval, char *buffer, int arg);
150static INT32 slider_xscale(running_machine *machine, INT32 newval, char *buffer, int arg);
151static INT32 slider_yscale(running_machine *machine, INT32 newval, char *buffer, int arg);
152static INT32 slider_xoffset(running_machine *machine, INT32 newval, char *buffer, int arg);
153static INT32 slider_yoffset(running_machine *machine, INT32 newval, char *buffer, int arg);
154static INT32 slider_flicker(running_machine *machine, INT32 newval, char *buffer, int arg);
155static INT32 slider_beam(running_machine *machine, INT32 newval, char *buffer, int arg);
142static INT32 slider_volume(running_machine *machine, INT32 newval, char *buffer, void *arg);
143static INT32 slider_mixervol(running_machine *machine, INT32 newval, char *buffer, void *arg);
144static INT32 slider_adjuster(running_machine *machine, INT32 newval, char *buffer, void *arg);
145static INT32 slider_overclock(running_machine *machine, INT32 newval, char *buffer, void *arg);
146static INT32 slider_refresh(running_machine *machine, INT32 newval, char *buffer, void *arg);
147static INT32 slider_brightness(running_machine *machine, INT32 newval, char *buffer, void *arg);
148static INT32 slider_contrast(running_machine *machine, INT32 newval, char *buffer, void *arg);
149static INT32 slider_gamma(running_machine *machine, INT32 newval, char *buffer, void *arg);
150static INT32 slider_xscale(running_machine *machine, INT32 newval, char *buffer, void *arg);
151static INT32 slider_yscale(running_machine *machine, INT32 newval, char *buffer, void *arg);
152static INT32 slider_xoffset(running_machine *machine, INT32 newval, char *buffer, void *arg);
153static INT32 slider_yoffset(running_machine *machine, INT32 newval, char *buffer, void *arg);
154static INT32 slider_flicker(running_machine *machine, INT32 newval, char *buffer, void *arg);
155static INT32 slider_beam(running_machine *machine, INT32 newval, char *buffer, void *arg);
156156static char *slider_get_screen_desc(const device_config *screen);
157157#ifdef MAME_DEBUG
158static INT32 slider_crossscale(running_machine *machine, INT32 newval, char *buffer, int arg);
159static INT32 slider_crossoffset(running_machine *machine, INT32 newval, char *buffer, int arg);
158static INT32 slider_crossscale(running_machine *machine, INT32 newval, char *buffer, void *arg);
159static INT32 slider_crossoffset(running_machine *machine, INT32 newval, char *buffer, void *arg);
160160#endif
161161
162162
r2724r2725
182182-------------------------------------------------*/
183183
184184INLINE void slider_config(slider_state *state, INT32 minval, INT32 defval, INT32 maxval, INT32 incval,
185                    INT32 (*update)(running_machine *, INT32, char *, int), int arg)
185                    INT32 (*update)(running_machine *, INT32, char *, void *), void *arg)
186186{
187187   state->minval = minval;
188188   state->defval = defval;
r2724r2725
11731173   ui_draw_text_box(messagebox_text, JUSTIFY_LEFT, 0.5f, 0.5f, messagebox_backcolor);
11741174
11751175   /* an 'O' or left joystick kicks us to the next state */
1176   if (state == 0 && (input_code_pressed_once(KEYCODE_O) || input_ui_pressed(IPT_UI_LEFT)))
1176   if (state == 0 && (input_code_pressed_once(KEYCODE_O) || input_ui_pressed(machine, IPT_UI_LEFT)))
11771177      state++;
11781178
11791179   /* a 'K' or right joystick exits the state */
1180   else if (state == 1 && (input_code_pressed_once(KEYCODE_K) || input_ui_pressed(IPT_UI_RIGHT)))
1180   else if (state == 1 && (input_code_pressed_once(KEYCODE_K) || input_ui_pressed(machine, IPT_UI_RIGHT)))
11811181      state = UI_HANDLER_CANCEL;
11821182
11831183   /* if the user cancels, exit out completely */
1184   else if (input_ui_pressed(IPT_UI_CANCEL))
1184   else if (input_ui_pressed(machine, IPT_UI_CANCEL))
11851185   {
11861186      mame_schedule_exit(machine);
11871187      state = UI_HANDLER_CANCEL;
r2724r2725
12031203   ui_draw_text_box(messagebox_text, JUSTIFY_LEFT, 0.5f, 0.5f, messagebox_backcolor);
12041204
12051205   /* if the user cancels, exit out completely */
1206   if (input_ui_pressed(IPT_UI_CANCEL))
1206   if (input_ui_pressed(machine, IPT_UI_CANCEL))
12071207   {
12081208      mame_schedule_exit(machine);
12091209      state = UI_HANDLER_CANCEL;
r2724r2725
12621262#endif /* MESS */
12631263
12641264   /* if the user pressed ESC, stop the emulation */
1265   if (input_ui_pressed(IPT_UI_CANCEL))
1265   if (input_ui_pressed(machine, IPT_UI_CANCEL))
12661266      mame_schedule_exit(machine);
12671267
12681268   /* turn on menus if requested */
1269   if (input_ui_pressed(IPT_UI_CONFIGURE))
1269   if (input_ui_pressed(machine, IPT_UI_CONFIGURE))
12701270      return ui_set_handler(ui_menu_ui_handler, 0);
12711271
12721272   /* if the on-screen display isn't up and the user has toggled it, turn it on */
1273   if (!machine->debug_mode && input_ui_pressed(IPT_UI_ON_SCREEN_DISPLAY))
1273   if (!machine->debug_mode && input_ui_pressed(machine, IPT_UI_ON_SCREEN_DISPLAY))
12741274      return ui_set_handler(handler_slider, 0);
12751275
12761276   /* handle a reset request */
1277   if (input_ui_pressed(IPT_UI_RESET_MACHINE))
1277   if (input_ui_pressed(machine, IPT_UI_RESET_MACHINE))
12781278      mame_schedule_hard_reset(machine);
1279   if (input_ui_pressed(IPT_UI_SOFT_RESET))
1279   if (input_ui_pressed(machine, IPT_UI_SOFT_RESET))
12801280      mame_schedule_soft_reset(machine);
12811281
12821282   /* handle a request to display graphics/palette */
1283   if (input_ui_pressed(IPT_UI_SHOW_GFX))
1283   if (input_ui_pressed(machine, IPT_UI_SHOW_GFX))
12841284   {
12851285      if (!is_paused)
12861286         mame_pause(machine, TRUE);
r2724r2725
12881288   }
12891289
12901290   /* handle a save state request */
1291   if (input_ui_pressed(IPT_UI_SAVE_STATE))
1291   if (input_ui_pressed(machine, IPT_UI_SAVE_STATE))
12921292   {
12931293      mame_pause(machine, TRUE);
12941294      return ui_set_handler(handler_load_save, LOADSAVE_SAVE);
12951295   }
12961296
12971297   /* handle a load state request */
1298   if (input_ui_pressed(IPT_UI_LOAD_STATE))
1298   if (input_ui_pressed(machine, IPT_UI_LOAD_STATE))
12991299   {
13001300      mame_pause(machine, TRUE);
13011301      return ui_set_handler(handler_load_save, LOADSAVE_LOAD);
13021302   }
13031303
13041304   /* handle a save snapshot request */
1305   if (input_ui_pressed(IPT_UI_SNAPSHOT))
1305   if (input_ui_pressed(machine, IPT_UI_SNAPSHOT))
13061306      video_save_active_screen_snapshots(machine);
13071307
13081308   /* toggle pause */
1309   if (input_ui_pressed(IPT_UI_PAUSE))
1309   if (input_ui_pressed(machine, IPT_UI_PAUSE))
13101310   {
13111311      /* with a shift key, it is single step */
13121312      if (is_paused && (input_code_pressed(KEYCODE_LSHIFT) || input_code_pressed(KEYCODE_RSHIFT)))
r2724r2725
13191319   }
13201320
13211321   /* toggle movie recording */
1322   if (input_ui_pressed(IPT_UI_RECORD_MOVIE))
1322   if (input_ui_pressed(machine, IPT_UI_RECORD_MOVIE))
13231323   {
13241324      if (!video_mng_is_movie_active(machine->primary_screen))
13251325      {
r2724r2725
13341334   }
13351335
13361336   /* toggle profiler display */
1337   if (input_ui_pressed(IPT_UI_SHOW_PROFILER))
1337   if (input_ui_pressed(machine, IPT_UI_SHOW_PROFILER))
13381338      ui_set_show_profiler(!ui_get_show_profiler());
13391339
13401340   /* toggle FPS display */
1341   if (input_ui_pressed(IPT_UI_SHOW_FPS))
1341   if (input_ui_pressed(machine, IPT_UI_SHOW_FPS))
13421342      ui_set_show_fps(!ui_get_show_fps());
13431343
13441344   /* toggle crosshair display */
1345   if (input_ui_pressed(IPT_UI_TOGGLE_CROSSHAIR))
1345   if (input_ui_pressed(machine, IPT_UI_TOGGLE_CROSSHAIR))
13461346      crosshair_toggle(machine);
13471347
13481348   /* increment frameskip? */
1349   if (input_ui_pressed(IPT_UI_FRAMESKIP_INC))
1349   if (input_ui_pressed(machine, IPT_UI_FRAMESKIP_INC))
13501350   {
13511351      /* get the current value and increment it */
13521352      int newframeskip = video_get_frameskip() + 1;
r2724r2725
13591359   }
13601360
13611361   /* decrement frameskip? */
1362   if (input_ui_pressed(IPT_UI_FRAMESKIP_DEC))
1362   if (input_ui_pressed(machine, IPT_UI_FRAMESKIP_DEC))
13631363   {
13641364      /* get the current value and decrement it */
13651365      int newframeskip = video_get_frameskip() - 1;
r2724r2725
13721372   }
13731373
13741374   /* toggle throttle? */
1375   if (input_ui_pressed(IPT_UI_THROTTLE))
1375   if (input_ui_pressed(machine, IPT_UI_THROTTLE))
13761376      video_set_throttle(!video_get_throttle());
13771377
13781378   /* check for fast forward */
1379   if (input_port_type_pressed(IPT_UI_FAST_FORWARD, 0))
1379   if (input_type_pressed(machine, IPT_UI_FAST_FORWARD, 0))
13801380   {
13811381      video_set_fastforward(TRUE);
13821382      ui_show_fps_temp(0.5);
r2724r2725
13861386
13871387#ifdef MESS
13881388   /* paste? */
1389   if (input_ui_pressed(IPT_UI_PASTE))
1389   if (input_ui_pressed(machine, IPT_UI_PASTE))
13901390      ui_paste(machine);
13911391#endif /* MESS */
13921392
r2724r2725
14061406   char textbuf[256];
14071407
14081408   /* left/right control the increment */
1409   if (input_ui_pressed_repeat(IPT_UI_LEFT,6))
1409   if (input_ui_pressed_repeat(machine, IPT_UI_LEFT,6))
14101410      increment = -cur->incval;
1411   if (input_ui_pressed_repeat(IPT_UI_RIGHT,6))
1411   if (input_ui_pressed_repeat(machine, IPT_UI_RIGHT,6))
14121412      increment = cur->incval;
14131413
14141414   /* alt goes to 1, shift goes 10x smaller, control goes 10x larger */
r2724r2725
14261426   newval = (*cur->update)(machine, 0, NULL, cur->arg) + increment;
14271427
14281428   /* select resets to the default value */
1429   if (input_ui_pressed(IPT_UI_SELECT))
1429   if (input_ui_pressed(machine, IPT_UI_SELECT))
14301430      newval = cur->defval;
14311431
14321432   /* clamp within bounds */
r2724r2725
14421442   slider_display(textbuf, cur->minval, cur->maxval, cur->defval, newval);
14431443
14441444   /* up/down select which slider to control */
1445   if (input_ui_pressed_repeat(IPT_UI_DOWN,6))
1445   if (input_ui_pressed_repeat(machine, IPT_UI_DOWN,6))
14461446      slider_current = (slider_current + 1) % slider_count;
1447   if (input_ui_pressed_repeat(IPT_UI_UP,6))
1447   if (input_ui_pressed_repeat(machine, IPT_UI_UP,6))
14481448      slider_current = (slider_current + slider_count - 1) % slider_count;
14491449
14501450   /* the slider toggle or ESC will cancel out of our display */
1451   if (input_ui_pressed(IPT_UI_ON_SCREEN_DISPLAY) || input_ui_pressed(IPT_UI_CANCEL))
1451   if (input_ui_pressed(machine, IPT_UI_ON_SCREEN_DISPLAY) || input_ui_pressed(machine, IPT_UI_CANCEL))
14521452      return UI_HANDLER_CANCEL;
14531453
14541454   /* the menu key will take us directly to the menu */
1455   if (input_ui_pressed(IPT_UI_CONFIGURE))
1455   if (input_ui_pressed(machine, IPT_UI_CONFIGURE))
14561456      return ui_set_handler(ui_menu_ui_handler, 0);
14571457
14581458   return 0;
r2724r2725
14811481      ui_draw_message_window("Select position to load from");
14821482
14831483   /* check for cancel key */
1484   if (input_ui_pressed(IPT_UI_CANCEL))
1484   if (input_ui_pressed(machine, IPT_UI_CANCEL))
14851485   {
14861486      /* display a popup indicating things were cancelled */
14871487      if (state == LOADSAVE_SAVE)
r2724r2725
15411541static void slider_init(running_machine *machine)
15421542{
15431543   int numscreens = video_screen_count(machine->config);
1544   const input_port_config *port;
1545   const input_field_config *field;
15441546   const device_config *device;
15451547   int numitems, item;
1546   input_port_entry *in;
15471548
15481549   slider_count = 0;
15491550
15501551   /* add overall volume */
1551   slider_config(&slider_list[slider_count++], -32, 0, 0, 1, slider_volume, 0);
1552   slider_config(&slider_list[slider_count++], -32, 0, 0, 1, slider_volume, NULL);
15521553
15531554   /* add per-channel volume */
15541555   numitems = sound_get_user_gain_count();
r2724r2725
15601561      if (defval > 1000)
15611562         maxval = 2 * defval;
15621563
1563      slider_config(&slider_list[slider_count++], 0, defval, maxval, 20, slider_mixervol, item);
1564      slider_config(&slider_list[slider_count++], 0, defval, maxval, 20, slider_mixervol, (void *)(FPTR)item);
15641565   }
15651566
15661567   /* add analog adjusters */
1567   for (in = machine->input_ports; in && in->type != IPT_END; in++)
1568      if ((in->type & 0xff) == IPT_ADJUSTER)
1569         slider_config(&slider_list[slider_count++], 0, in->default_value >> 8, 100, 1, slider_adjuster, in - machine->input_ports);
1568   for (port = machine->portconfig; port != NULL; port = port->next)
1569      for (field = port->fieldlist; field != NULL; field = field->next)
1570         if (field->type == IPT_ADJUSTER)
1571         {
1572            void *param = (void *)field;
1573            slider_config(&slider_list[slider_count++], 0, field->defvalue, 100, 1, slider_adjuster, param);
1574         }
15701575
15711576   if (options_get_bool(mame_options(), OPTION_CHEAT))
15721577   {
15731578      /* add CPU overclocking */
15741579      numitems = cpu_gettotalcpu();
15751580      for (item = 0; item < numitems; item++)
1576         slider_config(&slider_list[slider_count++], 10, 1000, 2000, 1, slider_overclock, item);
1581         slider_config(&slider_list[slider_count++], 10, 1000, 2000, 1, slider_overclock, (void *)(FPTR)item);
15771582
15781583      /* add refresh rate tweaker */
1579      slider_config(&slider_list[slider_count++], -10000, 0, 10000, 1000, slider_refresh, 0);
1584      slider_config(&slider_list[slider_count++], -10000, 0, 10000, 1000, slider_refresh, NULL);
15801585   }
15811586
15821587   for (item = 0; item < numscreens; item++)
15831588   {
1584      const screen_config *scrconfig = device_list_find_by_index(machine->config->devicelist, VIDEO_SCREEN, item)->inline_config;
1589      const device_config *screen = device_list_find_by_index(machine->config->devicelist, VIDEO_SCREEN, item);
1590      const screen_config *scrconfig = screen->inline_config;
15851591      int defxscale = floor(scrconfig->xscale * 1000.0f + 0.5f);
15861592      int defyscale = floor(scrconfig->yscale * 1000.0f + 0.5f);
15871593      int defxoffset = floor(scrconfig->xoffset * 1000.0f + 0.5f);
15881594      int defyoffset = floor(scrconfig->yoffset * 1000.0f + 0.5f);
1595      void *param = (void *)screen;
15891596
15901597      /* add standard brightness/contrast/gamma controls per-screen */
1591      slider_config(&slider_list[slider_count++], 100, 1000, 2000, 10, slider_brightness, item);
1592      slider_config(&slider_list[slider_count++], 100, 1000, 2000, 50, slider_contrast, item);
1593      slider_config(&slider_list[slider_count++], 100, 1000, 3000, 50, slider_gamma, item);
1598      slider_config(&slider_list[slider_count++], 100, 1000, 2000, 10, slider_brightness, param);
1599      slider_config(&slider_list[slider_count++], 100, 1000, 2000, 50, slider_contrast, param);
1600      slider_config(&slider_list[slider_count++], 100, 1000, 3000, 50, slider_gamma, param);
15941601
15951602      /* add scale and offset controls per-screen */
1596      slider_config(&slider_list[slider_count++], 500, (defxscale == 0) ? 1000 : defxscale, 1500, 2, slider_xscale, item);
1597      slider_config(&slider_list[slider_count++], -500, defxoffset, 500, 2, slider_xoffset, item);
1598      slider_config(&slider_list[slider_count++], 500, (defyscale == 0) ? 1000 : defyscale, 1500, 2, slider_yscale, item);
1599      slider_config(&slider_list[slider_count++], -500, defyoffset, 500, 2, slider_yoffset, item);
1603      slider_config(&slider_list[slider_count++], 500, (defxscale == 0) ? 1000 : defxscale, 1500, 2, slider_xscale, param);
1604      slider_config(&slider_list[slider_count++], -500, defxoffset, 500, 2, slider_xoffset, param);
1605      slider_config(&slider_list[slider_count++], 500, (defyscale == 0) ? 1000 : defyscale, 1500, 2, slider_yscale, param);
1606      slider_config(&slider_list[slider_count++], -500, defyoffset, 500, 2, slider_yoffset, param);
16001607   }
16011608
16021609   for (device = video_screen_first(machine->config); device != NULL; device = video_screen_next(device))
r2724r2725
16051612      if (scrconfig->type == SCREEN_TYPE_VECTOR)
16061613      {
16071614         /* add flicker control */
1608         slider_config(&slider_list[slider_count++], 0, 0, 1000, 10, slider_flicker, 0);
1609         slider_config(&slider_list[slider_count++], 10, 100, 1000, 10, slider_beam, 0);
1615         slider_config(&slider_list[slider_count++], 0, 0, 1000, 10, slider_flicker, NULL);
1616         slider_config(&slider_list[slider_count++], 10, 100, 1000, 10, slider_beam, NULL);
16101617         break;
16111618      }
16121619   }
16131620
16141621#ifdef MAME_DEBUG
16151622   /* add crosshair adjusters */
1616   for (in = machine->input_ports; in && in->type != IPT_END; in++)
1617      if (in->analog.crossaxis != CROSSHAIR_AXIS_NONE && in->player == 0)
1618      {
1619         slider_config(&slider_list[slider_count++], -3000, 1000, 3000, 100, slider_crossscale, in->analog.crossaxis);
1620         slider_config(&slider_list[slider_count++], -3000, 0, 3000, 100, slider_crossoffset, in->analog.crossaxis);
1621      }
1623   for (port = machine->portconfig; port != NULL; port = port->next)
1624      for (field = port->fieldlist; field != NULL; field = field->next)
1625         if (field->crossaxis != CROSSHAIR_AXIS_NONE && field->player == 0)
1626         {
1627            void *param = (void *)field;
1628            slider_config(&slider_list[slider_count++], -3000, 1000, 3000, 100, slider_crossscale, param);
1629            slider_config(&slider_list[slider_count++], -3000, 0, 3000, 100, slider_crossoffset, param);
1630         }
16221631#endif
16231632}
16241633
r2724r2725
16931702    slider_volume - global volume slider callback
16941703-------------------------------------------------*/
16951704
1696static INT32 slider_volume(running_machine *machine, INT32 newval, char *buffer, int arg)
1705static INT32 slider_volume(running_machine *machine, INT32 newval, char *buffer, void *arg)
16971706{
16981707   if (buffer != NULL)
16991708   {
r2724r2725
17091718    slider callback
17101719-------------------------------------------------*/
17111720
1712static INT32 slider_mixervol(running_machine *machine, INT32 newval, char *buffer, int arg)
1721static INT32 slider_mixervol(running_machine *machine, INT32 newval, char *buffer, void *arg)
17131722{
1723   int which = (FPTR)arg;
17141724   if (buffer != NULL)
17151725   {
1716      sound_set_user_gain(arg, (float)newval * 0.001f);
1717      sprintf(buffer, "%s Volume %4.2f", sound_get_user_gain_name(arg), sound_get_user_gain(arg));
1726      sound_set_user_gain(which, (float)newval * 0.001f);
1727      sprintf(buffer, "%s Volume %4.2f", sound_get_user_gain_name(which), sound_get_user_gain(which));
17181728   }
1719   return floor(sound_get_user_gain(arg) * 1000.0f + 0.5f);
1729   return floor(sound_get_user_gain(which) * 1000.0f + 0.5f);
17201730}
17211731
17221732
r2724r2725
17251735    callback
17261736-------------------------------------------------*/
17271737
1728static INT32 slider_adjuster(running_machine *machine, INT32 newval, char *buffer, int arg)
1738static INT32 slider_adjuster(running_machine *machine, INT32 newval, char *buffer, void *arg)
17291739{
1730   input_port_entry *in = &machine->input_ports[arg];
1740   const input_field_config *field = arg;
1741   input_field_user_settings settings;
1742
1743   input_field_get_user_settings(field, &settings);
17311744   if (buffer != NULL)
17321745   {
1733      in->default_value = (in->default_value & ~0xff) | (newval & 0xff);
1734      sprintf(buffer, "%s %d%%", in->name, in->default_value & 0xff);
1746      settings.value = newval;
1747      input_field_set_user_settings(field, &settings);
1748      sprintf(buffer, "%s %d%%", field->name, settings.value);
17351749   }
1736   return in->default_value & 0xff;
1750   return settings.value;
17371751}
17381752
17391753
r2724r2725
17421756    callback
17431757-------------------------------------------------*/
17441758
1745static INT32 slider_overclock(running_machine *machine, INT32 newval, char *buffer, int arg)
1759static INT32 slider_overclock(running_machine *machine, INT32 newval, char *buffer, void *arg)
17461760{
1761   int which = (FPTR)arg;
17471762   if (buffer != NULL)
17481763   {
1749      cpunum_set_clockscale(machine, arg, (float)newval * 0.001f);
1750      sprintf(buffer, "Overclock CPU %d %3.0f%%", arg, floor(cpunum_get_clockscale(arg) * 100.0f + 0.5f));
1764      cpunum_set_clockscale(machine, which, (float)newval * 0.001f);
1765      sprintf(buffer, "Overclock CPU %d %3.0f%%", which, floor(cpunum_get_clockscale(which) * 100.0f + 0.5f));
17511766   }
1752   return floor(cpunum_get_clockscale(arg) * 1000.0f + 0.5f);
1767   return floor(cpunum_get_clockscale(which) * 1000.0f + 0.5f);
17531768}
17541769
17551770
r2724r2725
17571772    slider_refresh - refresh rate slider callback
17581773-------------------------------------------------*/
17591774
1760static INT32 slider_refresh(running_machine *machine, INT32 newval, char *buffer, int arg)
1775static INT32 slider_refresh(running_machine *machine, INT32 newval, char *buffer, void *arg)
17611776{
1762   const screen_config *scrconfig = device_list_find_by_index(machine->config->devicelist, VIDEO_SCREEN, arg)->inline_config;
1777   const device_config *screen = arg;
1778   const screen_config *scrconfig = screen->inline_config;
17631779   double defrefresh = ATTOSECONDS_TO_HZ(scrconfig->refresh);
17641780   double refresh;
17651781
17661782   if (buffer != NULL)
17671783   {
1768      const device_config *screen = device_list_find_by_index(machine->config->devicelist, VIDEO_SCREEN, arg);
17691784      int width = video_screen_get_width(screen);
17701785      int height = video_screen_get_height(screen);
17711786      const rectangle *visarea = video_screen_get_visible_area(screen);
r2724r2725
17831798    callback
17841799-------------------------------------------------*/
17851800
1786static INT32 slider_brightness(running_machine *machine, INT32 newval, char *buffer, int arg)
1801static INT32 slider_brightness(running_machine *machine, INT32 newval, char *buffer, void *arg)
17871802{
1788   const device_config *screen = device_list_find_by_index(machine->config->devicelist, VIDEO_SCREEN, arg);
1803   const device_config *screen = arg;
17891804   render_container *container = render_container_get_screen(screen);
17901805   if (buffer != NULL)
17911806   {
r2724r2725
18011816    callback
18021817-------------------------------------------------*/
18031818
1804static INT32 slider_contrast(running_machine *machine, INT32 newval, char *buffer, int arg)
1819static INT32 slider_contrast(running_machine *machine, INT32 newval, char *buffer, void *arg)
18051820{
1806   const device_config *screen = device_list_find_by_index(machine->config->devicelist, VIDEO_SCREEN, arg);
1821   const device_config *screen = arg;
18071822   render_container *container = render_container_get_screen(screen);
18081823   if (buffer != NULL)
18091824   {
r2724r2725
18181833    slider_gamma - screen gamma slider callback
18191834-------------------------------------------------*/
18201835
1821static INT32 slider_gamma(running_machine *machine, INT32 newval, char *buffer, int arg)
1836static INT32 slider_gamma(running_machine *machine, INT32 newval, char *buffer, void *arg)
18221837{
1823   const device_config *screen = device_list_find_by_index(machine->config->devicelist, VIDEO_SCREEN, arg);
1838   const device_config *screen = arg;
18241839   render_container *container = render_container_get_screen(screen);
18251840   if (buffer != NULL)
18261841   {
r2724r2725
18361851    callback
18371852-------------------------------------------------*/
18381853
1839static INT32 slider_xscale(running_machine *machine, INT32 newval, char *buffer, int arg)
1854static INT32 slider_xscale(running_machine *machine, INT32 newval, char *buffer, void *arg)
18401855{
1841   const device_config *screen = device_list_find_by_index(machine->config->devicelist, VIDEO_SCREEN, arg);
1856   const device_config *screen = arg;
18421857   render_container *container = render_container_get_screen(screen);
18431858   if (buffer != NULL)
18441859   {
r2724r2725
18541869    callback
18551870-------------------------------------------------*/
18561871
1857static INT32 slider_yscale(running_machine *machine, INT32 newval, char *buffer, int arg)
1872static INT32 slider_yscale(running_machine *machine, INT32 newval, char *buffer, void *arg)
18581873{
1859   const device_config *screen = device_list_find_by_index(machine->config->devicelist, VIDEO_SCREEN, arg);
1874   const device_config *screen = arg;
18601875   render_container *container = render_container_get_screen(screen);
18611876   if (buffer != NULL)
18621877   {
r2724r2725
18721887    slider callback
18731888-------------------------------------------------*/
18741889
1875static INT32 slider_xoffset(running_machine *machine, INT32 newval, char *buffer, int arg)
1890static INT32 slider_xoffset(running_machine *machine, INT32 newval, char *buffer, void *arg)
18761891{
1877   const device_config *screen = device_list_find_by_index(machine->config->devicelist, VIDEO_SCREEN, arg);
1892   const device_config *screen = arg;
18781893   render_container *container = render_container_get_screen(screen);
18791894   if (buffer != NULL)
18801895   {
r2724r2725
18901905    slider callback
18911906-------------------------------------------------*/
18921907
1893static INT32 slider_yoffset(running_machine *machine, INT32 newval, char *buffer, int arg)
1908static INT32 slider_yoffset(running_machine *machine, INT32 newval, char *buffer, void *arg)
18941909{
1895   const device_config *screen = device_list_find_by_index(machine->config->devicelist, VIDEO_SCREEN, arg);
1910   const device_config *screen = arg;
18961911   render_container *container = render_container_get_screen(screen);
18971912   if (buffer != NULL)
18981913   {
r2724r2725
19081923    callback
19091924-------------------------------------------------*/
19101925
1911static INT32 slider_flicker(running_machine *machine, INT32 newval, char *buffer, int arg)
1926static INT32 slider_flicker(running_machine *machine, INT32 newval, char *buffer, void *arg)
19121927{
19131928   if (buffer != NULL)
19141929   {
r2724r2725
19241939    callback
19251940-------------------------------------------------*/
19261941
1927static INT32 slider_beam(running_machine *machine, INT32 newval, char *buffer, int arg)
1942static INT32 slider_beam(running_machine *machine, INT32 newval, char *buffer, void *arg)
19281943{
19291944   if (buffer != NULL)
19301945   {
r2724r2725
19601975-------------------------------------------------*/
19611976
19621977#ifdef MAME_DEBUG
1963static INT32 slider_crossscale(running_machine *machine, INT32 newval, char *buffer, int arg)
1978static INT32 slider_crossscale(running_machine *machine, INT32 newval, char *buffer, void *arg)
19641979{
1965   input_port_entry *in;
1980   input_field_config *field = arg;
19661981
19671982   if (buffer != NULL)
19681983   {
1969      for (in = machine->input_ports; in && in->type != IPT_END; in++)
1970         if (in->analog.crossaxis == arg)
1971         {
1972            in->analog.crossscale = (float)newval * 0.001f;
1973            break;
1974         }
1975      sprintf(buffer, "%s %s %1.3f", "Crosshair Scale", (in->analog.crossaxis == CROSSHAIR_AXIS_X) ? "X" : "Y", (float)newval * 0.001f);
1984      field->crossscale = (float)newval * 0.001f;
1985      sprintf(buffer, "%s %s %1.3f", "Crosshair Scale", (field->crossaxis == CROSSHAIR_AXIS_X) ? "X" : "Y", (float)newval * 0.001f);
19761986   }
1977   for (in = machine->input_ports; in && in->type != IPT_END; in++)
1978      if (in->analog.crossaxis == arg)
1979         return floor(in->analog.crossscale * 1000.0f + 0.5f);
1980   return 0;
1987   return floor(field->crossscale * 1000.0f + 0.5f);
19811988}
19821989#endif
19831990
r2724r2725
19881995-------------------------------------------------*/
19891996
19901997#ifdef MAME_DEBUG
1991static INT32 slider_crossoffset(running_machine *machine, INT32 newval, char *buffer, int arg)
1998static INT32 slider_crossoffset(running_machine *machine, INT32 newval, char *buffer, void *arg)
19921999{
1993   input_port_entry *in;
2000   input_field_config *field = arg;
19942001
19952002   if (buffer != NULL)
19962003   {
1997      for (in = machine->input_ports; in && in->type != IPT_END; in++)
1998         if (in->analog.crossaxis == arg)
1999         {
2000            in->analog.crossoffset = (float)newval * 0.001f;
2001            break;
2002         }
2003      sprintf(buffer, "%s %s %1.3f", "Crosshair Offset", (in->analog.crossaxis == CROSSHAIR_AXIS_X) ? "X" : "Y", (float)newval * 0.001f);
2004      field->crossoffset = (float)newval * 0.001f;
2005      sprintf(buffer, "%s %s %1.3f", "Crosshair Offset", (field->crossaxis == CROSSHAIR_AXIS_X) ? "X" : "Y", (float)newval * 0.001f);
20042006   }
2005   for (in = machine->input_ports; in && in->type != IPT_END; in++)
2006      if (in->analog.crossaxis == arg)
2007         return floor(in->analog.crossoffset * 1000.0f + 0.5f);
2008   return 0;
2007   return field->crossoffset;
20092008}
20102009#endif
src/emu/crsshair.c
r2724r2725
182182
183183void crosshair_init(running_machine *machine)
184184{
185   input_port_entry *ipt;
185   const input_port_config *port;
186   const input_field_config *field;
186187
187188   /* request a callback upon exiting */
188189   add_exit_callback(machine, crosshair_exit);
r2724r2725
191192   memset(&global, 0, sizeof(global));
192193
193194   /* determine who needs crosshairs */
194   for (ipt = machine->input_ports; ipt->type != IPT_END; ipt++)
195      if (ipt->analog.crossaxis != CROSSHAIR_AXIS_NONE)
196      {
197         int player = ipt->player;
195   for (port = machine->portconfig; port != NULL; port = port->next)
196      for (field = port->fieldlist; field != NULL; field = field->next)
197         if (field->crossaxis != CROSSHAIR_AXIS_NONE)
198         {
199            int player = field->player;
198200
199         assert(player < MAX_PLAYERS);
201            assert(player < MAX_PLAYERS);
200202
201         /* mark as used and visible */
202         global.used[player] = TRUE;
203         global.visible[player] = TRUE;
203            /* mark as used and visible */
204            global.used[player] = TRUE;
205            global.visible[player] = TRUE;
204206
205         /* for now, use the main screen */
206         global.screen[player] = machine->primary_screen;
207            /* for now, use the main screen */
208            global.screen[player] = machine->primary_screen;
207209
208         create_bitmap(player);
209      }
210            create_bitmap(player);
211         }
210212
211213   /* register the animation callback */
212214   if (machine->primary_screen != NULL)
r2724r2725
272274
273275static void animate(const device_config *device, int vblank_state)
274276{
275   input_port_entry *ipt;
276   int portnum = -1;
277   int player;
277278
278279   /* increment animation counter */
279280   global.animation_counter += 0x04;
r2724r2725
285286      global.fade = 0xa0 + (0x60 * (~global.animation_counter & 0x7f) / 0x80);
286287
287288   /* read all the lightgun values */
288   for (ipt = device->machine->input_ports; ipt->type != IPT_END; ipt++)
289   {
290      /* keep track of the port number */
291      if (ipt->type == IPT_PORT)
292         portnum++;
293
294      /* compute the values */
295      if (ipt->analog.crossaxis != CROSSHAIR_AXIS_NONE)
296      {
297         float value = (float)(get_crosshair_pos(portnum, ipt->player, ipt->analog.crossaxis) - ipt->analog.min) / (float)(ipt->analog.max - ipt->analog.min);
298         if (ipt->analog.crossscale < 0)
299            value = -(1.0 - value) * ipt->analog.crossscale;
300         else
301            value *= ipt->analog.crossscale;
302         value += ipt->analog.crossoffset;
303
304         /* switch off the axis */
305         switch (ipt->analog.crossaxis)
306         {
307            case CROSSHAIR_AXIS_X:
308               global.x[ipt->player] = value;
309               if (ipt->analog.crossaltaxis != 0)
310                  global.y[ipt->player] = ipt->analog.crossaltaxis;
311               break;
312
313            case CROSSHAIR_AXIS_Y:
314               global.y[ipt->player] = value;
315               if (ipt->analog.crossaltaxis != 0)
316                  global.x[ipt->player] = ipt->analog.crossaltaxis;
317               break;
318         }
319      }
320   }
289   for (player = 0; player < MAX_PLAYERS; player++)
290      if (global.used[player])
291         input_port_get_crosshair_position(device->machine, player, &global.x[player], &global.y[player]);
321292}
322293
323294
src/emu/sound.c
r2724r2725
114114static void sound_reset(running_machine *machine);
115115static void sound_exit(running_machine *machine);
116116static void sound_pause(running_machine *machine, int pause);
117static void sound_load(int config_type, xml_data_node *parentnode);
118static void sound_save(int config_type, xml_data_node *parentnode);
117static void sound_load(running_machine *machine, int config_type, xml_data_node *parentnode);
118static void sound_save(running_machine *machine, int config_type, xml_data_node *parentnode);
119119static TIMER_CALLBACK( sound_update );
120120static void start_sound_chips(void);
121121static void route_sound(void);
122122static void mixer_update(void *param, stream_sample_t **inputs, stream_sample_t **buffer, int length);
123static STATE_POSTLOAD( mixer_postload );
123124
124125
125126
r2724r2725
223224   sound_set_attenuation(options_get_int(mame_options(), OPTION_VOLUME));
224225
225226   /* register callbacks */
226   config_register("mixer", sound_load, sound_save);
227   config_register(machine, "mixer", sound_load, sound_save);
227228   add_pause_callback(machine, sound_pause);
228229   add_reset_callback(machine, sound_reset);
229230   add_exit_callback(machine, sound_exit);
r2724r2725
397398      if (info->inputs != 0)
398399      {
399400         info->mixer_stream = stream_create(info->inputs, 1, Machine->sample_rate, info, mixer_update);
401         state_save_register_postload(Machine, mixer_postload, info->mixer_stream);
400402         info->input = auto_malloc(info->inputs * sizeof(*info->input));
401403         info->inputs = 0;
402404      }
r2724r2725
577579    configuration file
578580-------------------------------------------------*/
579581
580static void sound_load(int config_type, xml_data_node *parentnode)
582static void sound_load(running_machine *machine, int config_type, xml_data_node *parentnode)
581583{
582584   xml_data_node *channelnode;
583585   int mixernum;
r2724r2725
610612    file
611613-------------------------------------------------*/
612614
613static void sound_save(int config_type, xml_data_node *parentnode)
615static void sound_save(running_machine *machine, int config_type, xml_data_node *parentnode)
614616{
615617   int mixernum;
616618
r2724r2725
791793}
792794
793795
796/*-------------------------------------------------
797    mixer_postload - postload function to reset
798    the mixer stream to the proper sample rate
799-------------------------------------------------*/
794800
801static STATE_POSTLOAD( mixer_postload )
802{
803   sound_stream *stream = param;
804   stream_set_sample_rate(stream, machine->sample_rate);
805}
806
807
808
795809/***************************************************************************
796810    SPEAKER OUTPUT DEVICE INTERFACE
797811***************************************************************************/
src/emu/render.c
r2724r2725
252252
253253/* core system */
254254static void render_exit(running_machine *machine);
255static void render_load(int config_type, xml_data_node *parentnode);
256static void render_save(int config_type, xml_data_node *parentnode);
255static void render_load(running_machine *machine, int config_type, xml_data_node *parentnode);
256static void render_save(running_machine *machine, int config_type, xml_data_node *parentnode);
257257
258258/* render targets */
259259static void release_render_list(render_primitive_list *list);
r2724r2725
537537   *current_container_ptr = NULL;
538538
539539   /* register callbacks */
540   config_register("video", render_load, render_save);
540   config_register(machine, "video", render_load, render_save);
541541}
542542
543543
r2724r2725
615615    configuration file
616616-------------------------------------------------*/
617617
618static void render_load(int config_type, xml_data_node *parentnode)
618static void render_load(running_machine *machine, int config_type, xml_data_node *parentnode)
619619{
620620   xml_data_node *targetnode;
621621   xml_data_node *screennode;
r2724r2725
733733    file
734734-------------------------------------------------*/
735735
736static void render_save(int config_type, xml_data_node *parentnode)
736static void render_save(running_machine *machine, int config_type, xml_data_node *parentnode)
737737{
738738   render_target *target;
739739   render_container *container;
src/emu/cheat.c
r2724r2725
751751static int      ControlKeyPressed(void);
752752static int      AltKeyPressed(void);
753753
754static int      UIPressedRepeatThrottle(int code, int baseSpeed);
754static int      UIPressedRepeatThrottle(running_machine *machine, int code, int baseSpeed);
755755
756756/********** DIRECT KEY INPUT **********/
757757static int      ReadHexInput(void);
758758
759759static char *   DoDynamicEditTextField(char * buf);
760760static void      DoStaticEditTextField(char * buf, int size);
761static UINT32   DoEditHexField(UINT32 data);
761static UINT32   DoEditHexField(running_machine *machine, UINT32 data);
762762static UINT32   DoEditHexFieldSigned(UINT32 data, UINT32 mask);
763763static INT32   DoEditDecField(INT32 data, INT32 min, INT32 max);
764764
r2724r2725
777777static char *   CreateStringCopy(char * buf);
778778
779779/********** ADDITIONAL MENU FOR CHEAT **********/
780static INT32   UserSelectValueMenu(int selection, CheatEntry * entry);
780static INT32   UserSelectValueMenu(running_machine *machine, int selection, CheatEntry * entry);
781781
782782/********** CHEAT MENU **********/
783783static int      EnableDisableCheatMenu(running_machine *machine, int selection, int firstTime);
r2724r2725
788788static int      DoSearchMenuClassic(running_machine *machine, int selection);   // classic mode
789789static int      DoSearchMenu(running_machine *machine, int selection);         // advanced mode
790790static int      SelectSearchRegions(running_machine *machine, int selection, SearchInfo * search);
791static int      ViewSearchResults(int selection, int firstTime);
791static int      ViewSearchResults(running_machine *machine, int selection, int firstTime);
792792
793793static int      ChooseWatch(running_machine *machine, int selection);
794794static int      EditWatch(running_machine *machine, WatchInfo * entry, int selection);
r2724r2725
11871187  UIPressedRepoeatThrottle - key repeat handling
11881188-------------------------------------------------*/
11891189
1190static int UIPressedRepeatThrottle(int code, int baseSpeed)
1190static int UIPressedRepeatThrottle(running_machine *machine, int code, int baseSpeed)
11911191{
11921192   static int   lastCode = -1;
11931193   static int   lastSpeed = -1;
r2724r2725
11961196
11971197   const int   kDelayRampTimer = 10;
11981198
1199   if(input_port_type_pressed(code, 0))
1199   if(input_type_pressed(machine, code, 0))
12001200   {
12011201      if(lastCode != code)         // different key pressed
12021202      {
r2724r2725
12271227         lastCode = -1;
12281228   }
12291229
1230   return input_ui_pressed_repeat(code, lastSpeed);
1230   return input_ui_pressed_repeat(machine, code, lastSpeed);
12311231}
12321232
12331233/*---------------------------------
r2724r2725
13501350  DoEditHexField - edit hex field with direct key input (unsigned)
13511351------------------------------------------------------------------*/
13521352
1353static UINT32 DoEditHexField(UINT32 data)
1353static UINT32 DoEditHexField(running_machine *machine, UINT32 data)
13541354{
13551355   INT8   key;
13561356
r2724r2725
13631363   }
13641364   else
13651365   {
1366      if(input_ui_pressed(IPT_UI_CLEAR))
1366      if(input_ui_pressed(machine, IPT_UI_CLEAR))
13671367      {
13681368         data = 0;
13691369
r2724r2725
17131713   ui_menu_draw(menu_item, total, sel, NULL);
17141714
17151715   /********** KEY HANDLING **********/
1716   if(UIPressedRepeatThrottle(IPT_UI_DOWN, kVerticalKeyRepeatRate))
1716   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
17171717   {
17181718      if(sel < (total - 1))
17191719         sel++;
r2724r2725
17211721         sel = 0;
17221722   }
17231723
1724   if(UIPressedRepeatThrottle(IPT_UI_UP, kVerticalKeyRepeatRate))
1724   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
17251725   {
17261726      if(sel > 0)
17271727         sel--;
r2724r2725
17291729         sel = total - 1;
17301730   }
17311731
1732   if(input_ui_pressed(IPT_UI_SELECT))
1732   if(input_ui_pressed(machine, IPT_UI_SELECT))
17331733   {
17341734      switch(sel)
17351735      {
r2724r2725
17501750      }
17511751   }
17521752
1753   if(input_ui_pressed(IPT_UI_RELOAD_CHEAT))
1753   if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT))
17541754      ReloadCheatDatabase(machine);
17551755
1756   if(input_ui_pressed(IPT_UI_CANCEL))
1756   if(input_ui_pressed(machine, IPT_UI_CANCEL))
17571757   {
17581758      if(sel == kMenu_Return)
17591759         lastPstn = 0;         // if cursor is now on the return item, adjust cursor keeper
r2724r2725
19731973  UserSelectValueMenu - management for value-selection menu
19741974------------------------------------------------------------*/
19751975
1976static INT32 UserSelectValueMenu(int selection, CheatEntry * entry)
1976static INT32 UserSelectValueMenu(running_machine *machine, int selection, CheatEntry * entry)
19771977{
19781978   char               buf[2048];
19791979   int                  sel;
r2724r2725
20402040   ui_draw_message_window(buf);
20412041
20422042   /********** KEY HANDLING **********/
2043   if(UIPressedRepeatThrottle(IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
2043   if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
20442044      delta = -1;
20452045
2046   if(UIPressedRepeatThrottle(IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
2046   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
20472047      delta = 1;
20482048
2049   if(input_ui_pressed(IPT_UI_SELECT))
2049   if(input_ui_pressed(machine, IPT_UI_SELECT))
20502050   {
20512051      /* ### redundant?? probably can be removed ### */
20522052      if(!firstTime)
r2724r2725
20932093      sel = -1;
20942094   }
20952095
2096   if(input_ui_pressed(IPT_UI_CANCEL))
2096   if(input_ui_pressed(machine, IPT_UI_CANCEL))
20972097   {
20982098      firstTime = 1;
20992099      sel = -1;
r2724r2725
21612161  CommentMenu - management comment for code menu
21622162-------------------------------------------------*/
21632163
2164static INT32 CommentMenu(int selection, CheatEntry * entry)
2164static INT32 CommentMenu(running_machine *machine, int selection, CheatEntry * entry)
21652165{
21662166   char   buf[2048];
21672167   int      sel;
r2724r2725
21842184   ui_draw_message_window(buf);
21852185
21862186   /********** KEY HANDLING **********/
2187   if(input_ui_pressed(IPT_UI_SELECT) || input_ui_pressed(IPT_UI_CANCEL))
2187   if(input_ui_pressed(machine, IPT_UI_SELECT) || input_ui_pressed(machine, IPT_UI_CANCEL))
21882188      sel = -1;
21892189
21902190   return sel + 1;
r2724r2725
22212221      switch(submenu_id)
22222222      {
22232223         case 1:
2224            submenu_choice = CommentMenu(submenu_choice, &cheatList[sel]);
2224            submenu_choice = CommentMenu(machine, submenu_choice, &cheatList[sel]);
22252225            break;
22262226
22272227         case 2:
2228            submenu_choice = UserSelectValueMenu(submenu_choice, &cheatList[sel]);
2228            submenu_choice = UserSelectValueMenu(machine, submenu_choice, &cheatList[sel]);
22292229            break;
22302230
22312231         case 3:
r2724r2725
23432343   old_style_menu(menu_item, menu_subitem, flagBuf, sel, 0);
23442344
23452345   /********** KEY HANDLING **********/
2346   if(UIPressedRepeatThrottle(IPT_UI_DOWN, kVerticalKeyRepeatRate))
2346   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
23472347   {
23482348      sel++;
23492349
r2724r2725
23582358      }
23592359   }
23602360
2361   if(UIPressedRepeatThrottle(IPT_UI_UP, kVerticalKeyRepeatRate))
2361   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
23622362   {
23632363      sel--;
23642364
r2724r2725
23802380      }
23812381   }
23822382
2383   if(UIPressedRepeatThrottle(IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
2383   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
23842384   {
23852385      sel -= fullMenuPageHeight;
23862386
r2724r2725
23882388         sel = 0;
23892389   }
23902390
2391   if(UIPressedRepeatThrottle(IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
2391   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
23922392   {
23932393      sel += fullMenuPageHeight;
23942394
r2724r2725
24012401   else
24022402      entry = NULL;
24032403
2404   if(UIPressedRepeatThrottle(IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
2404   if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
24052405   {
24062406      if((sel < (total - 1)) && entry)
24072407      {
r2724r2725
24602460      }
24612461   }
24622462
2463   if(UIPressedRepeatThrottle(IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
2463   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
24642464   {
24652465      if((sel < (total - 1)) && entry)
24662466      {
r2724r2725
25242524      }
25252525   }
25262526
2527   if(input_ui_pressed(IPT_UI_SELECT))
2527   if(input_ui_pressed(machine, IPT_UI_SELECT))
25282528   {
25292529      if(sel == (total - 1))
25302530      {
r2724r2725
25742574      }
25752575   }
25762576
2577   if(input_ui_pressed(IPT_UI_WATCH_VALUE))
2577   if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE))
25782578      WatchCheatEntry(entry, 0);
25792579
25802580   if(ShiftKeyPressed())
25812581   {
2582      if(input_ui_pressed(IPT_UI_SAVE_CHEAT))         // shift + save = save all codes
2582      if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))         // shift + save = save all codes
25832583      {
25842584         for(i = 0; i < cheatListLength; i++)
25852585            SaveCheat(machine, &cheatList[i], 0, 0);
r2724r2725
25872587         ui_popup_time(1, "%d cheats saved", cheatListLength);
25882588      }
25892589
2590      if(input_ui_pressed(IPT_UI_ADD_CHEAT))         // shift + add = add new emypty code
2590      if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT))         // shift + add = add new emypty code
25912591         AddCheatBefore(sel);
25922592
2593      if(input_ui_pressed(IPT_UI_DELETE_CHEAT))      // shift + delete = delete selected code
2593      if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))      // shift + delete = delete selected code
25942594         DeleteCheatAt(sel);
25952595   }
25962596   else
25972597   {
25982598      if(ControlKeyPressed())
25992599      {
2600         if(input_ui_pressed(IPT_UI_SAVE_CHEAT))      // ctrl + save = save activation key
2600         if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))      // ctrl + save = save activation key
26012601         {
26022602            if((entry->flags & kCheatFlag_HasActivationKey1) || (entry->flags & kCheatFlag_HasActivationKey2))
26032603            {
r2724r2725
26112611      }
26122612      else
26132613      {
2614         if(input_ui_pressed(IPT_UI_SAVE_CHEAT))
2614         if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))
26152615            SaveCheat(machine, entry, 0, 0);         // save current entry
26162616      }
26172617   }
26182618
2619   if(input_ui_pressed(IPT_UI_EDIT_CHEAT) && entry)      // edit selected code
2619   if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT) && entry)      // edit selected code
26202620   {
26212621      submenu_id = 3;
26222622      submenu_choice = 1;
26232623   }
26242624
2625   if(input_ui_pressed(IPT_UI_RELOAD_CHEAT))
2625   if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT))
26262626      ReloadCheatDatabase(machine);
26272627
2628   if(UIPressedRepeatThrottle(IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate))
2628   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate))
26292629      /* ----- quick menu switch : enable/disable -> add/edit ----- */
26302630      sel = -3;
26312631
2632   if(UIPressedRepeatThrottle(IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate))
2632   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate))
26332633      /* ----- quick menu switch : enable/disable -> watchpoint list ----- */
26342634      sel = -5;
26352635
2636   if(input_ui_pressed(IPT_UI_CANCEL))
2636   if(input_ui_pressed(machine, IPT_UI_CANCEL))
26372637      sel = -1;
26382638
26392639   return sel + 1;
r2724r2725
26992699   old_style_menu(menu_item, NULL, NULL, sel, 0);
27002700
27012701   /********** KEY HANDLING **********/
2702   if(UIPressedRepeatThrottle(IPT_UI_DOWN, kVerticalKeyRepeatRate))
2702   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
27032703   {
27042704      sel++;
27052705
r2724r2725
27072707         sel = 0;
27082708   }
27092709
2710   if(UIPressedRepeatThrottle(IPT_UI_UP, kVerticalKeyRepeatRate))
2710   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
27112711   {
27122712      sel--;
27132713
r2724r2725
27152715         sel = total - 1;
27162716   }
27172717
2718   if(UIPressedRepeatThrottle(IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
2718   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
27192719   {
27202720      sel -= fullMenuPageHeight;
27212721
r2724r2725
27232723         sel = 0;
27242724   }
27252725
2726   if(UIPressedRepeatThrottle(IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
2726   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
27272727   {
27282728      sel += fullMenuPageHeight;
27292729
r2724r2725
27362736   else
27372737      entry = NULL;
27382738
2739   if(input_ui_pressed(IPT_UI_SAVE_CHEAT))
2739   if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))
27402740   {
27412741      if(ShiftKeyPressed())
27422742      {
r2724r2725
27632763      }
27642764   }
27652765
2766   if(input_ui_pressed(IPT_UI_ADD_CHEAT))
2766   if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT))
27672767      AddCheatBefore(sel);         // insert empty code
27682768
2769   if(input_ui_pressed(IPT_UI_DELETE_CHEAT))
2769   if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
27702770      DeleteCheatAt(sel);         // delete selected code
27712771
2772   if(input_ui_pressed(IPT_UI_WATCH_VALUE))
2772   if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE))
27732773      WatchCheatEntry(entry, 0);            // watch selected code
27742774
2775   if(input_ui_pressed(IPT_UI_EDIT_CHEAT))      // edit selected code
2775   if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT))      // edit selected code
27762776   {
27772777      /* ----- if selected item is not return, go to edit menu ----- */
27782778      if(sel < (total - 1))
r2724r2725
27822782      }
27832783   }
27842784
2785   if(input_ui_pressed(IPT_UI_SELECT))
2785   if(input_ui_pressed(machine, IPT_UI_SELECT))
27862786   {
27872787      /* ----- if selected item is return, return previous menu ----- */
27882788      if(sel >= (total - 1))
r2724r2725
27982798      }
27992799   }
28002800
2801   if(input_ui_pressed(IPT_UI_RELOAD_CHEAT))
2801   if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT))
28022802      ReloadCheatDatabase(machine);
28032803
2804   if(UIPressedRepeatThrottle(IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate))
2804   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate))
28052805      /* ----- quick menu switch : add/edit -> search ----- */
28062806      sel = -4;
28072807
2808   if(UIPressedRepeatThrottle(IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate))
2808   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate))
28092809      /* ----- quick menu switch : add/edit -> enable/disable ----- */
28102810      sel = -2;
28112811
2812   if(input_ui_pressed(IPT_UI_CANCEL))
2812   if(input_ui_pressed(machine, IPT_UI_CANCEL))
28132813      sel = -1;
28142814
28152815   return sel + 1;
r2724r2725
37063706   if(ShiftKeyPressed())
37073707      increment <<= 16;
37083708
3709   if(UIPressedRepeatThrottle(IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
3709   if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
37103710   {
37113711      editActive = 0;
37123712      dirty = 1;
r2724r2725
40264026      }
40274027   }
40284028
4029   if(UIPressedRepeatThrottle(IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
4029   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
40304030   {
40314031      editActive = 0;
40324032      dirty = 1;
r2724r2725
43454345      }
43464346   }
43474347
4348   if(UIPressedRepeatThrottle(IPT_UI_DOWN, kVerticalKeyRepeatRate))
4348   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
43494349   {
43504350      sel++;
43514351
r2724r2725
43554355      editActive = 0;
43564356   }
43574357
4358   if(UIPressedRepeatThrottle(IPT_UI_UP, kVerticalKeyRepeatRate))
4358   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
43594359   {
43604360      sel--;
43614361
r2724r2725
43654365      editActive = 0;
43664366   }
43674367
4368   if(UIPressedRepeatThrottle(IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
4368   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
43694369   {
43704370      sel -= fullMenuPageHeight;
43714371
r2724r2725
43754375      editActive = 0;
43764376   }
43774377
4378   if(UIPressedRepeatThrottle(IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
4378   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
43794379   {
43804380      sel += fullMenuPageHeight;
43814381
r2724r2725
43854385      editActive = 0;
43864386   }
43874387
4388   if(input_ui_pressed(IPT_UI_SELECT))
4388   if(input_ui_pressed(machine, IPT_UI_SELECT))
43894389   {
43904390      if(editActive)
43914391      {
r2724r2725
44474447         case kType_ActivationKey1:
44484448         case kType_ActivationKey2:
44494449         {
4450            if(input_ui_pressed(IPT_UI_CANCEL))
4450            if(input_ui_pressed(machine, IPT_UI_CANCEL))
44514451            {
44524452               if(info->fieldType == kType_ActivationKey1)
44534453               {
r2724r2725
44834483               }
44844484               else
44854485               {
4486                  if((code != INPUT_CODE_INVALID) && !input_ui_pressed(IPT_UI_SELECT))
4486                  if((code != INPUT_CODE_INVALID) && !input_ui_pressed(machine, IPT_UI_SELECT))
44874487                  {
44884488                     if(info->fieldType == kType_ActivationKey1)
44894489                     {
r2724r2725
45084508            UINT32   temp = (action->originalDataField >> 0) & 0xFF;
45094509
45104510            temp++;
4511            temp = DoEditHexField(temp) & 0xFF;
4511            temp = DoEditHexField(machine, temp) & 0xFF;
45124512            temp--;
45134513
45144514            action->originalDataField = (action->originalDataField & 0xFFFFFF00) | ((temp << 0) & 0x000000FF);
r2724r2725
45204520         {
45214521            UINT32   temp = (action->originalDataField >> 8) & 0xFF;
45224522
4523            temp = DoEditHexField(temp) & 0xFF;
4523            temp = DoEditHexField(machine, temp) & 0xFF;
45244524
45254525            action->originalDataField = (action->originalDataField & 0xFFFF00FF) | ((temp << 8) & 0x0000FF00);
45264526            action->data = action->originalDataField;
r2724r2725
45314531         {
45324532            UINT32   temp = (action->originalDataField >> 16) & 0xFF;
45334533
4534            temp = DoEditHexField(temp) & 0xFF;
4534            temp = DoEditHexField(machine, temp) & 0xFF;
45354535
45364536            action->originalDataField = (action->originalDataField & 0xFF00FFFF) | ((temp << 16) & 0x00FF0000);
45374537            action->data = action->originalDataField;
r2724r2725
45504550         break;
45514551
45524552         case kType_WriteMask:
4553            action->extendData = DoEditHexField(action->extendData);
4553            action->extendData = DoEditHexField(machine, action->extendData);
45544554            action->extendData &= info->extraData;
45554555            break;
45564556
45574557         case kType_AddMaximum:
45584558         case kType_SubtractMinimum:
45594559         case kType_WriteMatch:
4560            action->extendData = DoEditHexField(action->extendData);
4560            action->extendData = DoEditHexField(machine, action->extendData);
45614561            break;
45624562
45634563         case kType_RangeMinimum:
r2724r2725
45674567            if(!TEST_FIELD(action->type, BytesUsed))
45684568            {
45694569               temp = (action->extendData >> 8) & 0xFF;
4570               temp = DoEditHexField(temp) & 0xFF;
4570               temp = DoEditHexField(machine, temp) & 0xFF;
45714571
45724572               action->extendData = (action->extendData & 0xFF) | ((temp << 8) & 0xFF00);
45734573            }
45744574            else
45754575            {
45764576               temp = (action->extendData >> 16) & 0xFFFF;
4577               temp = DoEditHexField(temp) & 0xFFFF;
4577               temp = DoEditHexField(machine, temp) & 0xFFFF;
45784578
45794579               action->extendData = (action->extendData & 0x0000FFFF) | ((temp << 16) & 0xFFFF0000);
45804580            }
r2724r2725
45884588            if(!TEST_FIELD(action->type, BytesUsed))
45894589            {
45904590               temp = action->extendData & 0xFF;
4591               temp = DoEditHexField(temp) & 0xFF;
4591               temp = DoEditHexField(machine, temp) & 0xFF;
45924592
45934593               action->extendData = (action->extendData & 0xFF00) | (temp & 0x00FF);
45944594            }
45954595            else
45964596            {
45974597               temp = action->extendData & 0xFFFF;
4598               temp = DoEditHexField(temp) & 0xFFFF;
4598               temp = DoEditHexField(machine, temp) & 0xFFFF;
45994599
46004600               action->extendData = (action->extendData & 0xFFFF0000) | (temp & 0x0000FFFF);
46014601            }
r2724r2725
46034603         break;
46044604
46054605         case kType_Data:
4606            action->originalDataField = DoEditHexField(action->originalDataField);
4606            action->originalDataField = DoEditHexField(machine, action->originalDataField);
46074607            action->originalDataField &= info->extraData;
46084608            action->data = action->originalDataField;
46094609            break;
46104610
46114611         case kType_Address:
4612            action->address = DoEditHexField(action->address);
4612            action->address = DoEditHexField(machine, action->address);
46134613            action->address &= info->extraData;
46144614            break;
46154615      }
46164616
4617      if(input_ui_pressed(IPT_UI_CANCEL))
4617      if(input_ui_pressed(machine, IPT_UI_CANCEL))
46184618         editActive = 0;
46194619   }
46204620   else
46214621   {
4622      if(input_ui_pressed(IPT_UI_SAVE_CHEAT))
4622      if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))
46234623      {
46244624         if(ControlKeyPressed())
46254625            if((entry->flags & kCheatFlag_HasActivationKey1) || (entry->flags & kCheatFlag_HasActivationKey2))
r2724r2725
46344634            SaveCheat(machine, entry, 0, 0);         // save current entry
46354635      }
46364636
4637      if(input_ui_pressed(IPT_UI_WATCH_VALUE))
4637      if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE))
46384638         WatchCheatEntry(entry, 0);
46394639
4640      if(input_ui_pressed(IPT_UI_ADD_CHEAT))
4640      if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT))
46414641         AddActionBefore(entry, info->subcheat);
46424642
4643      if(input_ui_pressed(IPT_UI_DELETE_CHEAT))
4643      if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
46444644      {
46454645         if(!info->subcheat)
46464646         {
r2724r2725
46544654      }
46554655   }
46564656
4657   if(input_ui_pressed(IPT_UI_CANCEL))
4657   if(input_ui_pressed(machine, IPT_UI_CANCEL))
46584658   {
46594659      sel = -1;
46604660      editActive = 0;
r2724r2725
47454745            break;
47464746
47474747         case kMenu_ViewResult:
4748            submenuChoice = ViewSearchResults(submenuChoice, firstEntry);
4748            submenuChoice = ViewSearchResults(machine, submenuChoice, firstEntry);
47494749            break;
47504750      }
47514751
r2724r2725
48704870   old_style_menu(menuItem, menuSubItem, flagBuf, sel, 0);
48714871
48724872   /********** KEY HANDLING **********/
4873   if(UIPressedRepeatThrottle(IPT_UI_UP, kVerticalKeyRepeatRate))
4873   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
48744874   {
48754875      if(editActive)
48764876      {
r2724r2725
49044904      }
49054905   }
49064906
4907   if(UIPressedRepeatThrottle(IPT_UI_DOWN, kVerticalKeyRepeatRate))
4907   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
49084908   {
49094909      if(editActive)
49104910      {
r2724r2725
49384938      }
49394939   }
49404940
4941   if(UIPressedRepeatThrottle(IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
4941   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
49424942   {
49434943      sel -= fullMenuPageHeight;
49444944
r2724r2725
49464946         sel = 0;
49474947   }
49484948
4949   if(UIPressedRepeatThrottle(IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
4949   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
49504950   {
49514951      sel += fullMenuPageHeight;
49524952
r2724r2725
49544954         sel = total - 1;
49554955   }
49564956
4957   if(UIPressedRepeatThrottle(IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
4957   if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
49584958   {
49594959      if(editActive)
49604960      {
r2724r2725
49984998      }
49994999   }
50005000
5001   if(UIPressedRepeatThrottle(IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
5001   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
50025002   {
50035003      if(editActive)
50045004      {
r2724r2725
50435043      }
50445044   }
50455045
5046   if(input_ui_pressed(IPT_UI_SELECT))
5046   if(input_ui_pressed(machine, IPT_UI_SELECT))
50475047   {
50485048      if(editActive)
50495049      {
r2724r2725
51605160      }
51615161   }
51625162
5163   if(UIPressedRepeatThrottle(IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate))
5163   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate))
51645164      /* ----- quick menu switch : search -> watchpoint list ----- */
51655165      sel = -5;
51665166
5167   if(UIPressedRepeatThrottle(IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate))
5167   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate))
51685168      /* ----- quick menu switch : search -> add/edit ----- */
51695169      sel = -3;
51705170
51715171   /* ----- edit mode ON/OFF ----- */
5172   if(input_ui_pressed(IPT_UI_EDIT_CHEAT))
5172   if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT))
51735173   {
51745174      if(editActive)
51755175         editActive = 0;
r2724r2725
51815181   }
51825182
51835183   /* ----- memory save ----- */
5184   if(input_ui_pressed(IPT_UI_CLEAR))
5184   if(input_ui_pressed(machine, IPT_UI_CLEAR))
51855185   {
51865186      doneSaveMemory = 0;
51875187
51885188      doSearch = 1;
51895189   }
51905190
5191   if(input_ui_pressed(IPT_UI_CANCEL))
5191   if(input_ui_pressed(machine, IPT_UI_CANCEL))
51925192   {
51935193      if(editActive)
51945194         editActive = 0;
r2724r2725
52375237   {
52385238      if(searchItem == kItem_Value)
52395239      {
5240         search->oldOptions.value = DoEditHexField(search->oldOptions.value);
5240         search->oldOptions.value = DoEditHexField(machine, search->oldOptions.value);
52415241
52425242         search->oldOptions.value &= kSearchByteMaskTable[search->bytes];
52435243      }
r2724r2725
52455245      {
52465246         if(searchItem == kItem_Timer)
52475247         {
5248            search->oldOptions.delta = DoEditHexField(search->oldOptions.delta);
5248            search->oldOptions.delta = DoEditHexField(machine, search->oldOptions.delta);
52495249
52505250            search->oldOptions.delta &= kSearchByteMaskTable[search->bytes];
52515251         }
r2724r2725
53665366            break;
53675367
53685368         case kMenu_ViewResult:
5369            submenuChoice = ViewSearchResults(submenuChoice, firstEntry);
5369            submenuChoice = ViewSearchResults(machine, submenuChoice, firstEntry);
53705370            break;
53715371      }
53725372
r2724r2725
54815481   if(AltKeyPressed())
54825482      increment <<= 4;
54835483
5484   if(UIPressedRepeatThrottle(IPT_UI_DOWN, kVerticalKeyRepeatRate))
5484   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
54855485   {
54865486      sel++;
54875487
r2724r2725
54935493         sel = 0;
54945494   }
54955495
5496   if(UIPressedRepeatThrottle(IPT_UI_UP, kVerticalKeyRepeatRate))
5496   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
54975497   {
54985498      sel--;
54995499
r2724r2725
55055505         sel = total - 1;
55065506   }
55075507
5508   if(UIPressedRepeatThrottle(IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
5508   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
55095509   {
55105510      sel -= fullMenuPageHeight;
55115511
r2724r2725
55135513         sel = 0;
55145514   }
55155515
5516   if(UIPressedRepeatThrottle(IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
5516   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
55175517   {
55185518      sel += fullMenuPageHeight;
55195519
r2724r2725
55215521         sel = total - 1;
55225522   }
55235523
5524   if(UIPressedRepeatThrottle(IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
5524   if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
55255525   {
55265526      switch(sel)
55275527      {
r2724r2725
55755575      }
55765576   }
55775577
5578   if(UIPressedRepeatThrottle(IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
5578   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
55795579   {
55805580      switch(sel)
55815581      {
r2724r2725
56295629      }
56305630   }
56315631
5632   if(input_ui_pressed(IPT_UI_SELECT))
5632   if(input_ui_pressed(machine, IPT_UI_SELECT))
56335633   {
56345634      switch(sel)
56355635      {
r2724r2725
57145714      }
57155715   }
57165716
5717   if(UIPressedRepeatThrottle(IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate))
5717   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate))
57185718      /* ----- quick menu switch : search -> watchpoint list ----- */
57195719      sel = -5;
57205720
5721   if(UIPressedRepeatThrottle(IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate))
5721   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate))
57225722      /* ----- quick menu switch : search -> add/edit ----- */
57235723      sel = -3;
57245724
57255725
5726   if(input_ui_pressed(IPT_UI_CANCEL))
5726   if(input_ui_pressed(machine, IPT_UI_CANCEL))
57275727   {
57285728      /* ----- if cursor is now on the return item, adjust cursor keeper ----- */
57295729      if(sel == kMenu_Return)
r2724r2725
57665766   /* ----- edit a value if direct key input ----- */
57675767   if((sel == kMenu_ValueEqual) || (sel == kMenu_ValueNearTo))
57685768   {
5769      search->oldOptions.value = DoEditHexField(search->oldOptions.value);
5769      search->oldOptions.value = DoEditHexField(machine, search->oldOptions.value);
57705770
57715771      search->oldOptions.value &= kSearchByteMaskTable[search->bytes];
57725772   }
r2724r2725
57745774   {
57755775      if(sel == kMenu_Time)
57765776      {
5777         search->oldOptions.delta = DoEditHexField(search->oldOptions.delta);
5777         search->oldOptions.delta = DoEditHexField(machine, search->oldOptions.delta);
57785778
57795779         search->oldOptions.delta &= kSearchByteMaskTable[search->bytes];
57805780      }
r2724r2725
58845884            break;
58855885
58865886         case kMenu_ViewResult:
5887            submenuChoice = ViewSearchResults(submenuChoice, firstEntry);
5887            submenuChoice = ViewSearchResults(machine, submenuChoice, firstEntry);
58885888            break;
58895889      }
58905890
r2724r2725
60066006   if(ShiftKeyPressed())
60076007      increment <<= 16;
60086008
6009   if(UIPressedRepeatThrottle(IPT_UI_DOWN, kVerticalKeyRepeatRate))
6009   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
60106010   {
60116011      sel++;
60126012
r2724r2725
60186018         sel = 0;
60196019   }
60206020
6021   if(UIPressedRepeatThrottle(IPT_UI_UP, kVerticalKeyRepeatRate))
6021   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
60226022   {
60236023      sel--;
60246024
r2724r2725
60306030         sel = total - 1;
60316031   }
60326032
6033   if(UIPressedRepeatThrottle(IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
6033   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
60346034   {
60356035      sel -= fullMenuPageHeight;
60366036
r2724r2725
60386038         sel = 0;
60396039   }
60406040
6041   if(UIPressedRepeatThrottle(IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
6041   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
60426042   {
60436043      sel += fullMenuPageHeight;
60446044
r2724r2725
60466046         sel = total - 1;
60476047   }
60486048
6049   if(UIPressedRepeatThrottle(IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
6049   if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
60506050   {
60516051      switch(sel)
60526052      {
r2724r2725
61066106      }
61076107   }
61086108
6109   if(UIPressedRepeatThrottle(IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
6109   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
61106110   {
61116111      switch(sel)
61126112      {
r2724r2725
61666166      }
61676167   }
61686168
6169   if(input_ui_pressed(IPT_UI_SELECT))
6169   if(input_ui_pressed(machine, IPT_UI_SELECT))
61706170   {
61716171      if(editActive)
61726172         editActive = 0;
r2724r2725
62566256      switch(sel)
62576257      {
62586258         case kMenu_Value:
6259            search->value = DoEditHexField(search->value);
6259            search->value = DoEditHexField(machine, search->value);
62606260
62616261            search->value &= kSearchByteMaskTable[search->bytes];
62626262            break;
r2724r2725
62676267      }
62686268   }
62696269
6270   if(input_ui_pressed(IPT_UI_CANCEL))
6270   if(input_ui_pressed(machine, IPT_UI_CANCEL))
62716271      sel = -1;
62726272
62736273   /* ----- keep current cursor position ----- */
r2724r2725
63426342   old_style_menu(menuItem, menuSubItem, NULL, sel, 0);
63436343
63446344   /********** KEY HANDLING **********/
6345   if(UIPressedRepeatThrottle(IPT_UI_DOWN, kVerticalKeyRepeatRate))
6345   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
63466346   {
63476347      sel++;
63486348
r2724r2725
63506350         sel = 0;
63516351   }
63526352
6353   if(UIPressedRepeatThrottle(IPT_UI_UP, kVerticalKeyRepeatRate))
6353   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
63546354   {
63556355      sel--;
63566356
r2724r2725
63586358         sel = total - 1;
63596359   }
63606360
6361   if(UIPressedRepeatThrottle(IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
6361   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
63626362   {
63636363      sel -= fullMenuPageHeight;
63646364
r2724r2725
63666366         sel = 0;
63676367   }
63686368
6369   if(UIPressedRepeatThrottle(IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
6369   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
63706370   {
63716371      sel += fullMenuPageHeight;
63726372
r2724r2725
63746374         sel = total - 1;
63756375   }
63766376
6377   if(UIPressedRepeatThrottle(IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
6377   if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
63786378   {
63796379      if(sel < search->regionListLength)
63806380      {
r2724r2725
63956395      }
63966396   }
63976397
6398   if(UIPressedRepeatThrottle(IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
6398   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
63996399   {
64006400      if(sel < search->regionListLength)
64016401      {
r2724r2725
64166416      }
64176417   }
64186418
6419   if(input_ui_pressed(IPT_UI_DELETE_CHEAT))
6419   if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
64206420   {
64216421      if(ShiftKeyPressed())         // shift + delete = invalid region
64226422      {
r2724r2725
64296429      }
64306430   }
64316431
6432   if(input_ui_pressed(IPT_UI_SELECT))
6432   if(input_ui_pressed(machine, IPT_UI_SELECT))
64336433   {
64346434      if(sel >= total - 1)
64356435         sel = -1;
64366436   }
64376437
6438   if(input_ui_pressed(IPT_UI_CANCEL))
6438   if(input_ui_pressed(machine, IPT_UI_CANCEL))
64396439      sel = -1;
64406440
64416441   return sel + 1;
r2724r2725
64456445  ViewSearchResults - management for search result menu
64466446--------------------------------------------------------*/
64476447
6448static int ViewSearchResults(int selection, int firstTime)
6448static int ViewSearchResults(running_machine *machine, int selection, int firstTime)
64496449{
64506450   enum
64516451   {
r2724r2725
66126612   old_style_menu(menu_item, NULL, NULL, sel, 0);
66136613
66146614   /********** KEY HANDLING **********/
6615   if(UIPressedRepeatThrottle(IPT_UI_DOWN, kVerticalKeyRepeatRate))
6615   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
66166616   {
66176617      sel++;
66186618
r2724r2725
66206620         sel = kMenu_FirstResult;
66216621   }
66226622
6623   if(UIPressedRepeatThrottle(IPT_UI_UP, kVerticalKeyRepeatRate))
6623   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
66246624   {
66256625      sel--;
66266626
r2724r2725
66286628         sel = total - 1;
66296629   }
66306630
6631   if(UIPressedRepeatThrottle(IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
6631   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalFastKeyRepeatRate))
66326632   {
66336633      if(ShiftKeyPressed())
66346634         search->currentResultsPage = numPages - 1;            // shift + right = go to last PAGE
r2724r2725
66486648      sel = kMenu_FirstResult;
66496649   }
66506650
6651   if(UIPressedRepeatThrottle(IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
6651   if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalFastKeyRepeatRate))
66526652   {
66536653      if(ShiftKeyPressed())
66546654         search->currentResultsPage = 0;                     // shift + left = go to first PAGE
r2724r2725
66686668      sel = kMenu_FirstResult;
66696669   }
66706670
6671   if(UIPressedRepeatThrottle(IPT_UI_PAGE_UP, kHorizontalFastKeyRepeatRate))
6671   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kHorizontalFastKeyRepeatRate))
66726672   {
66736673      sel -=fullMenuPageHeight;
66746674
r2724r2725
66766676         sel = kMenu_FirstResult;
66776677   }
66786678
6679   if(UIPressedRepeatThrottle(IPT_UI_PAGE_DOWN, kHorizontalFastKeyRepeatRate))
6679   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kHorizontalFastKeyRepeatRate))
66806680   {
66816681      sel +=fullMenuPageHeight;
66826682
r2724r2725
66906690   if(input_code_pressed_once(KEYCODE_HOME))
66916691      search->currentResultsPage = 0;                     // go to first PAGE
66926692
6693   if(UIPressedRepeatThrottle(IPT_UI_PREV_GROUP, kVerticalKeyRepeatRate))
6693   if(UIPressedRepeatThrottle(machine, IPT_UI_PREV_GROUP, kVerticalKeyRepeatRate))
66946694   {
66956695      search->currentRegionIdx--;                        // go to previous REGION
66966696
r2724r2725
67006700      sel = kMenu_FirstResult;
67016701   }
67026702
6703   if(UIPressedRepeatThrottle(IPT_UI_NEXT_GROUP, kVerticalKeyRepeatRate))
6703   if(UIPressedRepeatThrottle(machine, IPT_UI_NEXT_GROUP, kVerticalKeyRepeatRate))
67046704   {
67056705      search->currentRegionIdx++;                        // go to next REGION
67066706
r2724r2725
67806780
67816781   if(selectedAddressGood)
67826782   {
6783      if(input_ui_pressed(IPT_UI_WATCH_VALUE))
6783      if(input_ui_pressed(machine, IPT_UI_WATCH_VALUE))
67846784         AddWatchFromResult(search, region, selectedAddress);      // watch selected result
67856785
6786      if(input_ui_pressed(IPT_UI_ADD_CHEAT))
6786      if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT))
67876787         AddCheatFromResult(search, region, selectedAddress);      // add selected result as new code to cheat list
67886788
6789      if(input_ui_pressed(IPT_UI_DELETE_CHEAT))
6789      if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
67906790      {
67916791         InvalidateRegionOffset(search, region, selectedOffset);      // delete selected result
67926792         search->numResults--;
r2724r2725
67946794      }
67956795   }
67966796
6797   if(input_ui_pressed(IPT_UI_DELETE_CHEAT))
6797   if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
67986798   {
67996799      if(ShiftKeyPressed())
68006800      {
r2724r2725
68076807      }
68086808   }
68096809
6810   if((input_ui_pressed(IPT_UI_SELECT) && (sel == total - 1)) || input_ui_pressed(IPT_UI_CANCEL))
6810   if((input_ui_pressed(machine, IPT_UI_SELECT) && (sel == total - 1)) || input_ui_pressed(machine, IPT_UI_CANCEL))
68116811      sel = -1;
68126812
68136813   return sel + 1;
r2724r2725
68826882      watch = NULL;
68836883
68846884   /********** KEY HANDLING **********/
6885   if(UIPressedRepeatThrottle(IPT_UI_DOWN, kVerticalKeyRepeatRate))
6885   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
68866886   {
68876887      sel++;
68886888
r2724r2725
68906890         sel = 0;
68916891   }
68926892
6893   if(UIPressedRepeatThrottle(IPT_UI_UP, kVerticalKeyRepeatRate))
6893   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
68946894   {
68956895      sel--;
68966896
r2724r2725
68986898         sel = total - 1;
68996899   }
69006900
6901   if(UIPressedRepeatThrottle(IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
6901   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
69026902   {
69036903      sel -= fullMenuPageHeight;
69046904
r2724r2725
69066906         sel = 0;
69076907   }
69086908
6909   if(UIPressedRepeatThrottle(IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
6909   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
69106910   {
69116911      sel += fullMenuPageHeight;
69126912
r2724r2725
69166916
69176917   if(ShiftKeyPressed())
69186918   {
6919      if(input_ui_pressed(IPT_UI_ADD_CHEAT))            // shift + add = add new watchpoint
6919      if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT))            // shift + add = add new watchpoint
69206920         AddWatchBefore(sel);
69216921
6922      if(input_ui_pressed(IPT_UI_DELETE_CHEAT))         // shift + delete = delete selected watchpoint
6922      if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))         // shift + delete = delete selected watchpoint
69236923         DeleteWatchAt(sel);
69246924   }
69256925   else
69266926   {
6927      if(input_ui_pressed(IPT_UI_SAVE_CHEAT))            // save = save selected watchpoint as watchpoint code
6927      if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))            // save = save selected watchpoint as watchpoint code
69286928      {
69296929         if(watch)
69306930         {
r2724r2725
69386938         }
69396939      }
69406940
6941      if(input_ui_pressed(IPT_UI_ADD_CHEAT))
6941      if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT))
69426942      {
69436943         if(watch)
69446944         {
r2724r2725
69546954         }
69556955      }
69566956
6957      if(input_ui_pressed(IPT_UI_DELETE_CHEAT))
6957      if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
69586958      {
69596959         if(ControlKeyPressed())
69606960         {
r2724r2725
69696969      }
69706970   }
69716971
6972   if(input_ui_pressed(IPT_UI_EDIT_CHEAT))               // edit = edit selected watchpoint
6972   if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT))               // edit = edit selected watchpoint
69736973   {
69746974      if(sel < (total - 1))
69756975      {
r2724r2725
69786978      }
69796979   }
69806980
6981   if(input_ui_pressed(IPT_UI_SELECT))
6981   if(input_ui_pressed(machine, IPT_UI_SELECT))
69826982   {
69836983      if(sel == (total - 1))                  // return previous menu
69846984      {
r2724r2725
69956995      }
69966996   }
69976997
6998   if(input_ui_pressed(IPT_UI_CLEAR))
6998   if(input_ui_pressed(machine, IPT_UI_CLEAR))
69996999   {
70007000      /* ----- reset all watchpoints ----- */
70017001      for(i = 0; i < watchListLength; i++)
r2724r2725
70197019      }
70207020   }
70217021
7022   if(UIPressedRepeatThrottle(IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate))
7022   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_IN, kVerticalKeyRepeatRate))
70237023      /* ----- quick menu switch : watchpoint list -> enable/disable ----- */
70247024      sel = -2;
70257025
7026   if(UIPressedRepeatThrottle(IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate))
7026   if(UIPressedRepeatThrottle(machine, IPT_UI_ZOOM_OUT, kVerticalKeyRepeatRate))
70277027      /* ----- quick menu switch : watchpoint list -> search ----- */
70287028      sel = -4;
70297029
7030   if(input_ui_pressed(IPT_UI_CANCEL))
7030   if(input_ui_pressed(machine, IPT_UI_CANCEL))
70317031      sel = -1;
70327032
70337033   return sel + 1;
r2724r2725
71957195   if(ShiftKeyPressed())
71967196      increment <<= 16;
71977197
7198   if(UIPressedRepeatThrottle(IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
7198   if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
71997199   {
72007200      editActive = 0;
72017201
r2724r2725
72967296      }
72977297   }
72987298
7299   if(UIPressedRepeatThrottle(IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
7299   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
73007300   {
73017301      editActive = 0;
73027302
r2724r2725
73897389      }
73907390   }
73917391
7392   if(UIPressedRepeatThrottle(IPT_UI_DOWN, kVerticalKeyRepeatRate))
7392   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
73937393   {
73947394      sel++;
73957395
r2724r2725
73997399      editActive = 0;
74007400   }
74017401
7402   if(UIPressedRepeatThrottle(IPT_UI_UP, kVerticalKeyRepeatRate))
7402   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
74037403   {
74047404      sel--;
74057405
r2724r2725
74097409      editActive = 0;
74107410   }
74117411
7412   if(UIPressedRepeatThrottle(IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
7412   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
74137413   {
74147414      sel -= fullMenuPageHeight;
74157415
r2724r2725
74197419      editActive = 0;
74207420   }
74217421
7422   if(UIPressedRepeatThrottle(IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
7422   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
74237423   {
74247424      sel += fullMenuPageHeight;
74257425
r2724r2725
74297429      editActive = 0;
74307430   }
74317431
7432   if(input_ui_pressed(IPT_UI_SELECT))
7432   if(input_ui_pressed(machine, IPT_UI_SELECT))
74337433   {
74347434      if(editActive)
74357435         editActive = 0;
r2724r2725
74637463      {
74647464         case kMenu_Address:
74657465            entry->address = DoShift(entry->address, entry->addressShift);
7466            entry->address = DoEditHexField(entry->address);
7466            entry->address = DoEditHexField(machine, entry->address);
74677467            entry->address = DoShift(entry->address, -entry->addressShift);
74687468            entry->address &= cpuInfoList[entry->cpu].addressMask;
74697469            break;
r2724r2725
75027502            break;
75037503
75047504         case kMenu_XOR:
7505            entry->xor = DoEditHexField(entry->xor);
7505            entry->xor = DoEditHexField(machine, entry->xor);
75067506            entry->xor &= kSearchByteMaskTable[kWatchSizeConversionTable[entry->elementBytes]];
75077507            break;
75087508      }
75097509
7510      if(input_ui_pressed(IPT_UI_CANCEL))
7510      if(input_ui_pressed(machine, IPT_UI_CANCEL))
75117511         editActive = 0;
75127512   }
75137513   else
75147514   {
7515      if(input_ui_pressed(IPT_UI_ADD_CHEAT))
7515      if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT))
75167516         AddCheatFromWatch(entry);
75177517
7518      if(input_ui_pressed(IPT_UI_DELETE_CHEAT))
7518      if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
75197519         entry->numElements = 0;
75207520
7521      if(input_ui_pressed(IPT_UI_SAVE_CHEAT))
7521      if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))
75227522      {
75237523         CheatEntry   tempEntry;
75247524
r2724r2725
75307530      }
75317531   }
75327532
7533   if(input_ui_pressed(IPT_UI_CANCEL))
7533   if(input_ui_pressed(machine, IPT_UI_CANCEL))
75347534      sel = -1;
75357535
75367536   return sel + 1;
r2724r2725
76307630   old_style_menu(menuItem, menuSubItem, NULL, sel, 0);
76317631
76327632   /********** KEY HANDLING **********/
7633   if(UIPressedRepeatThrottle(IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
7633   if(UIPressedRepeatThrottle(machine, IPT_UI_RIGHT, kHorizontalSlowKeyRepeatRate))
76347634   {
76357635      switch(sel)
76367636      {
r2724r2725
76677667      }
76687668   }
76697669
7670    if(UIPressedRepeatThrottle(IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
7670    if(UIPressedRepeatThrottle(machine, IPT_UI_LEFT, kHorizontalSlowKeyRepeatRate))
76717671   {
76727672      switch(sel)
76737673      {
r2724r2725
77047704      }
77057705   }
77067706
7707   if(UIPressedRepeatThrottle(IPT_UI_DOWN, kVerticalKeyRepeatRate))
7707   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
77087708   {
77097709      if(sel < (kMenu_Max - 1))
77107710         sel++;
r2724r2725
77127712         sel = 0;
77137713   }
77147714
7715   if(UIPressedRepeatThrottle(IPT_UI_UP, kVerticalKeyRepeatRate))
7715   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
77167716   {
77177717      if(sel > 0)
77187718         sel--;
r2724r2725
77207720         sel = kMenu_Max - 1;
77217721   }
77227722
7723   if(input_ui_pressed(IPT_UI_SELECT))
7723   if(input_ui_pressed(machine, IPT_UI_SELECT))
77247724   {
77257725      switch(sel)
77267726      {
r2724r2725
77357735      }
77367736   }
77377737
7738   if(input_ui_pressed(IPT_UI_SAVE_CHEAT))
7738   if(input_ui_pressed(machine, IPT_UI_SAVE_CHEAT))
77397739   {
77407740      SaveCheat(machine, NULL, 0, 2);
77417741
77427742      ui_popup_time(1, "command code saved");
77437743   }
77447744
7745   if(input_ui_pressed(IPT_UI_RELOAD_CHEAT))
7745   if(input_ui_pressed(machine, IPT_UI_RELOAD_CHEAT))
77467746      ReloadCheatDatabase(machine);
77477747
7748   if(input_ui_pressed(IPT_UI_CANCEL))
7748   if(input_ui_pressed(machine, IPT_UI_CANCEL))
77497749      sel = -1;
77507750
77517751   return sel + 1;
r2724r2725
78087808   old_style_menu(menuItem, NULL, NULL, sel, 0);
78097809
78107810   /********** KEY HANDLING **********/
7811   if(UIPressedRepeatThrottle(IPT_UI_DOWN, kVerticalKeyRepeatRate))
7811   if(UIPressedRepeatThrottle(machine, IPT_UI_DOWN, kVerticalKeyRepeatRate))
78127812   {
78137813      sel++;
78147814
r2724r2725
78167816         sel = 0;
78177817   }
78187818
7819   if(UIPressedRepeatThrottle(IPT_UI_UP, kVerticalKeyRepeatRate))
7819   if(UIPressedRepeatThrottle(machine, IPT_UI_UP, kVerticalKeyRepeatRate))
78207820   {
78217821      sel--;
78227822
r2724r2725
78247824         sel = total - 1;
78257825   }
78267826
7827   if(UIPressedRepeatThrottle(IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
7827   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_UP, kVerticalKeyRepeatRate))
78287828   {
78297829      sel -= fullMenuPageHeight;
78307830
r2724r2725
78327832         sel = 0;
78337833   }
78347834
7835   if(UIPressedRepeatThrottle(IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
7835   if(UIPressedRepeatThrottle(machine, IPT_UI_PAGE_DOWN, kVerticalKeyRepeatRate))
78367836   {
78377837      sel += fullMenuPageHeight;
78387838
r2724r2725
78407840         sel = total - 1;
78417841   }
78427842
7843   if(input_ui_pressed(IPT_UI_ADD_CHEAT))
7843   if(input_ui_pressed(machine, IPT_UI_ADD_CHEAT))
78447844   {
78457845      AddSearchBefore(sel);
78467846
r2724r2725
78487848      AllocateSearchRegions(&searchList[sel]);
78497849   }
78507850
7851   if(input_ui_pressed(IPT_UI_DELETE_CHEAT))
7851   if(input_ui_pressed(machine, IPT_UI_DELETE_CHEAT))
78527852   {
78537853      if(searchListLength > 1)
78547854         DeleteSearchAt(sel);
78557855   }
78567856
7857   if(input_ui_pressed(IPT_UI_EDIT_CHEAT))
7857   if(input_ui_pressed(machine, IPT_UI_EDIT_CHEAT))
78587858   {
78597859      if(sel < total - 1)
78607860         currentSearchIdx = sel;
78617861   }
78627862
7863   if(input_ui_pressed(IPT_UI_SELECT))
7863   if(input_ui_pressed(machine, IPT_UI_SELECT))
78647864   {
78657865      if(sel >= total - 1)
78667866         sel = -1;
r2724r2725
78687868         currentSearchIdx = sel;
78697869   }
78707870
7871   if(input_ui_pressed(IPT_UI_CANCEL))
7871   if(input_ui_pressed(machine, IPT_UI_CANCEL))
78727872      sel = -1;
78737873
78747874   return sel + 1;
r2724r2725
78827882{
78837883   int   i;
78847884
7885   if(input_ui_pressed(IPT_UI_TOGGLE_CHEAT))
7885   if(input_ui_pressed(machine, IPT_UI_TOGGLE_CHEAT))
78867886   {
78877887      if(ShiftKeyPressed())
78887888      {
src/emu/validity.c
r2724r2725
947947
948948
949949/*-------------------------------------------------
950    display_valid_coin_order - display the
951    correct coin order
950    get_defstr_index - return the index of the
951    string assuming it is one of the default
952    strings
952953-------------------------------------------------*/
953954
954static void display_valid_coin_order(int drivnum, const input_port_entry *memory)
955static int get_defstr_index(const char *name, const game_driver *driver, int *error)
955956{
956   const game_driver *driver = drivers[drivnum];
957   const input_port_entry *inp;
958   int   coin_list[1024];
959   int coin_len = 0;
960   int i, j;
957   UINT32 crc = quark_string_crc(name);
961958   quark_entry *entry;
959   int strindex = 0;
962960
963   for (inp = memory; inp->type != IPT_END; inp++)
964   {
965      int      strindex = 0;
966      UINT32   crc;
967
968      if ( !inp->name || inp->name == IP_NAME_DEFAULT )
969         continue;
970
971      /* hash the string and look it up in the string table */
972      crc = quark_string_crc(inp->name);
973      for (entry = quark_table_get_first(defstr_table, crc); entry; entry = entry->next)
974         if (entry->crc == crc && !strcmp(inp->name, input_port_string_from_index(entry - defstr_table->entry)))
975         {
976            strindex = entry - defstr_table->entry;
977            break;
978         }
979
980      /* if its a coin entry, add it to our list, avoiding repetitions */
981      if ( strindex >= INPUT_STRING_9C_1C && strindex <= INPUT_STRING_1C_9C )
961   /* scan the quark table of input port strings */
962   for (entry = quark_table_get_first(defstr_table, crc); entry != NULL; entry = entry->next)
963      if (entry->crc == crc && strcmp(name, input_port_string_from_index(entry - defstr_table->entry)) == 0)
982964      {
983         j = 1;
984
985         for( i = 0; i < coin_len; i++ )
986         {
987            if ( coin_list[i] == strindex )
988            {
989               j = 0;
990               break;
991            }
992         }
993
994         if ( j )
995            coin_list[coin_len++] = strindex;
965         strindex = entry - defstr_table->entry;
966         break;
996967      }
968
969   /* check for strings that should be DEF_STR */
970   if (strindex != 0 && name != input_port_string_from_index(strindex) && error != NULL)
971   {
972      mame_printf_error("%s: %s must use DEF_STR( %s )\n", driver->source_file, driver->name, name);
973      *error = TRUE;
997974   }
998975
999   /* now display the proper coin entry list */
1000   mame_printf_error( "%s: %s proper coin sort order should be:\n", driver->source_file, driver->name );
1001   for (i = INPUT_STRING_9C_1C; i <= INPUT_STRING_1C_9C; i++)
1002      for (j = 0; j < coin_len; j++)
1003         /* if it's on our list, display it */
1004         if (coin_list[j] == i)
1005            mame_printf_error("%s\n", input_port_string_from_index(i));
976   return strindex;
1006977}
1007978
1008979
1009980/*-------------------------------------------------
1010    validate_inputs - validate input configuration
981    validate_analog_input_field - validate an
982    analog input field
1011983-------------------------------------------------*/
1012984
1013static int validate_inputs(int drivnum, const machine_config *config, input_port_entry **memory)
985static void validate_analog_input_field(const input_field_config *field, const game_driver *driver, int *error)
1014986{
1015   const char *demo_sounds = input_port_string_from_index(INPUT_STRING_Demo_Sounds);
1016   const char *flipscreen = input_port_string_from_index(INPUT_STRING_Flip_Screen);
1017   const input_port_entry *inp, *last_dipname_entry = NULL;
1018   const game_driver *driver = drivers[drivnum];
1019   const char *tag[MAX_INPUT_PORTS] = { 0 };
1020   int portnum = 0;
1021   int empty_string_found = FALSE;
1022   int last_strindex = 0;
1023   quark_entry *entry;
1024   int error = FALSE;
1025   int coin_error = FALSE;
1026   UINT32 crc;
987   INT32 analog_max = field->max;
988   INT32 analog_min = field->min;
989   int shift;
1027990
1028   /* skip if no ports */
1029   if (!driver->ipt)
1030      return FALSE;
991   if (field->type == IPT_POSITIONAL || field->type == IPT_POSITIONAL_V)
992   {
993      for (shift = 0; (shift <= 31) && (~field->mask & (1 << shift)); shift++) ;
994      /* convert the positional max value to be in the bitmask for testing */
995      analog_max = (analog_max - 1) << shift;
1031996
1032   /* skip if we already validated these ports */
1033   crc = (FPTR)driver->ipt;
1034   for (entry = quark_table_get_first(inputs_table, crc); entry; entry = entry->next)
1035      if (entry->crc == crc && driver->ipt == drivers[entry - inputs_table->entry]->ipt)
1036         return FALSE;
997      /* positional port size must fit in bits used */
998      if (((field->mask >> shift) + 1) < field->max)
999      {
1000         mame_printf_error("%s: %s has an analog port with a positional port size bigger then the mask size\n", driver->source_file, driver->name);
1001         *error = TRUE;
1002      }
1003   }
1004   else
1005   {
1006      /* only positional controls use PORT_WRAPS */
1007      if (field->flags & ANALOG_FLAG_WRAPS)
1008      {
1009         mame_printf_error("%s: %s only positional analog ports use PORT_WRAPS\n", driver->source_file, driver->name);
1010         *error = TRUE;
1011      }
1012   }
10371013
1038   /* otherwise, add ourself to the list */
1039   quark_add(inputs_table, drivnum, crc);
1014   /* analog ports must have a valid sensitivity */
1015   if (field->sensitivity == 0)
1016   {
1017      mame_printf_error("%s: %s has an analog port with zero sensitivity\n", driver->source_file, driver->name);
1018      *error = TRUE;
1019   }
10401020
1041   /* allocate the input ports */
1042   *memory = input_port_allocate(driver->ipt, *memory);
1021   /* check that the default falls in the bitmask range */
1022   if (field->defvalue & ~field->mask)
1023   {
1024      mame_printf_error("%s: %s has an analog port with a default value out of the bitmask range\n", driver->source_file, driver->name);
1025      *error = TRUE;
1026   }
10431027
1044   /* iterate over the results */
1045   for (inp = *memory; inp->type != IPT_END; inp++)
1028   /* tests for absolute devices */
1029   if (field->type >= __ipt_analog_absolute_start && field->type <= __ipt_analog_absolute_end)
10461030   {
1047      int strindex = 0;
1031      INT32 default_value = field->defvalue;
10481032
1049      /* check for duplicate tags */
1050      if (inp->type == IPT_PORT)
1033      /* adjust for signed values */
1034      if (analog_min > analog_max)
10511035      {
1052         if (inp->start.tag != NULL && portnum < ARRAY_LENGTH(tag))
1053         {
1054            int scanport;
1036         analog_min = -analog_min;
1037         if (default_value > analog_max)
1038            default_value = -default_value;
1039      }
10551040
1056            for (scanport = 0; scanport < portnum - 1; scanport++)
1057               if (strcmp(inp->start.tag, tag[scanport]) == 0)
1058               {
1059                  mame_printf_error("%s: %s has a duplicate input port tag \"%s\"\n", driver->source_file, driver->name, inp->start.tag);
1060                  error = TRUE;
1061               }
1062            tag[portnum++] = inp->start.tag;
1063         }
1064         continue;
1041      /* check that the default falls in the MINMAX range */
1042      if (default_value < analog_min || default_value > analog_max)
1043      {
1044         mame_printf_error("%s: %s has an analog port with a default value out PORT_MINMAX range\n", driver->source_file, driver->name);
1045         *error = TRUE;
10651046      }
10661047
1067      if (port_type_is_analog(inp->type))
1048      /* check that the MINMAX falls in the bitmask range */
1049      /* we use the unadjusted min for testing */
1050      if (field->min & ~field->mask || analog_max & ~field->mask)
10681051      {
1069         INT32 analog_max = inp->analog.max;
1070         INT32 analog_min = inp->analog.min;
1071         int shift;
1052         mame_printf_error("%s: %s has an analog port with a PORT_MINMAX value out of the bitmask range\n", driver->source_file, driver->name);
1053         *error = TRUE;
1054      }
10721055
1073         if (inp->type == IPT_POSITIONAL || inp->type == IPT_POSITIONAL_V)
1074         {
1075            for (shift = 0; (shift <= 31) && (~inp->mask & (1 << shift)); shift++);
1076            /* convert the positional max value to be in the bitmask for testing */
1077            analog_max = (analog_max - 1) << shift;
1056      /* absolute analog ports do not use PORT_RESET */
1057      if (field->flags & ANALOG_FLAG_RESET)
1058      {
1059         mame_printf_error("%s: %s - absolute analog ports do not use PORT_RESET\n", driver->source_file, driver->name);
1060         *error = TRUE;
1061      }
1062   }
10781063
1079            /* positional port size must fit in bits used */
1080            if (((inp->mask >> shift) + 1) < inp->analog.max)
1081            {
1082               mame_printf_error("%s: %s has an analog port with a positional port size bigger then the mask size\n", driver->source_file, driver->name);
1083               error = TRUE;
1084            }
1085         }
1086         else
1064   /* tests for relative devices */
1065   else
1066   {
1067      /* tests for non IPT_POSITIONAL relative devices */
1068      if (field->type != IPT_POSITIONAL && field->type != IPT_POSITIONAL_V)
1069      {
1070         /* relative devices do not use PORT_MINMAX */
1071         if (field->min != 0 || field->max != field->mask)
10871072         {
1088            /* only positional controls use PORT_WRAPS */
1089            if (inp->analog.wraps)
1090            {
1091               mame_printf_error("%s: %s only positional analog ports use PORT_WRAPS\n", driver->source_file, driver->name);
1092               error = TRUE;
1093            }
1073            mame_printf_error("%s: %s - relative ports do not use PORT_MINMAX\n", driver->source_file, driver->name);
1074            *error = TRUE;
10941075         }
10951076
1096
1097         /* analog ports must have a valid sensitivity */
1098         if (inp->analog.sensitivity == 0)
1077         /* relative devices do not use a default value */
1078         /* the counter is at 0 on power up */
1079         if (field->defvalue != 0)
10991080         {
1100            mame_printf_error("%s: %s has an analog port with zero sensitivity\n", driver->source_file, driver->name);
1101            error = TRUE;
1081            mame_printf_error("%s: %s - relative ports do not use a default value other then 0\n", driver->source_file, driver->name);
1082            *error = TRUE;
11021083         }
1084      }
1085   }
1086}
11031087
1104         /* check that the default falls in the bitmask range */
1105         if (inp->default_value & ~inp->mask)
1106         {
1107            mame_printf_error("%s: %s has an analog port with a default value out of the bitmask range\n", driver->source_file, driver->name);
1108            error = TRUE;
1109         }
11101088
1111         /* tests for absolute devices */
1112         if (port_type_is_analog_absolute(inp->type))
1113         {
1114            INT32 default_value = inp->default_value;
1089/*-------------------------------------------------
1090    validate_dip_settings - validate a DIP switch
1091    setting
1092-------------------------------------------------*/
11151093
1116            /* adjust for signed values */
1117            if (analog_min > analog_max)
1118            {
1119               analog_min = -analog_min;
1120               if (default_value > analog_max)
1121                  default_value = -default_value;
1122            }
1094static void validate_dip_settings(const input_field_config *field, const game_driver *driver, int *error)
1095{
1096   const char *demo_sounds = input_port_string_from_index(INPUT_STRING_Demo_Sounds);
1097   const char *flipscreen = input_port_string_from_index(INPUT_STRING_Flip_Screen);
1098   UINT8 coin_list[INPUT_STRING_1C_9C + 1 - INPUT_STRING_9C_1C] = { 0 };
1099   const input_setting_config *setting;
1100   int coin_error = FALSE;
11231101
1124            /* check that the default falls in the MINMAX range */
1125            if (default_value < analog_min || default_value > analog_max)
1126            {
1127               mame_printf_error("%s: %s has an analog port with a default value out PORT_MINMAX range\n", driver->source_file, driver->name);
1128               error = TRUE;
1129            }
1102   /* iterate through the settings */
1103   for (setting = field->settinglist; setting != NULL; setting = setting->next)
1104   {
1105      int strindex = get_defstr_index(setting->name, driver, error);
11301106
1131            /* check that the MINMAX falls in the bitmask range */
1132            /* we use the unadjusted min for testing */
1133            if (inp->analog.min & ~inp->mask || analog_max & ~inp->mask)
1134            {
1135               mame_printf_error("%s: %s has an analog port with a PORT_MINMAX value out of the bitmask range\n", driver->source_file, driver->name);
1136               error = TRUE;
1137            }
1107      /* note any coinage strings */
1108      if (strindex >= INPUT_STRING_9C_1C && strindex <= INPUT_STRING_1C_9C)
1109         coin_list[strindex - INPUT_STRING_9C_1C] = 1;
11381110
1139            /* absolute analog ports do not use PORT_RESET */
1140            if (inp->analog.reset)
1141            {
1142               mame_printf_error("%s: %s - absolute analog ports do not use PORT_RESET\n", driver->source_file, driver->name);
1143               error = TRUE;
1144            }
1145         }
1146         else
1147         /* tests for relative devices */
1148         {
1149            /* tests for non IPT_POSITIONAL relative devices */
1150            if (inp->type != IPT_POSITIONAL && inp->type != IPT_POSITIONAL_V)
1151            {
1152               /* relative devices do not use PORT_MINMAX */
1153               if (inp->analog.min || inp->analog.max != inp->mask)
1154               {
1155                 mame_printf_error("%s: %s - relative ports do not use PORT_MINMAX\n", driver->source_file, driver->name);
1156                 error = TRUE;
1157               }
1158
1159               /* relative devices do not use a default value */
1160               /* the counter is at 0 on power up */
1161               if (inp->default_value)
1162               {
1163                 mame_printf_error("%s: %s - relative ports do not use a default value other then 0\n", driver->source_file, driver->name);
1164                 error = TRUE;
1165               }
1166            }
1167         }
1168      }
1169
1170      /* clear the DIP switch tracking when we hit the first non-DIP entry */
1171      if (last_dipname_entry != NULL && inp->type != IPT_DIPSWITCH_SETTING)
1172         last_dipname_entry = NULL;
1173
1174      /* look for invalid (0) types which should be mapped to IPT_OTHER */
1175      if (inp->type == IPT_INVALID)
1111      /* make sure demo sounds default to on */
1112      if (field->name == demo_sounds && strindex == INPUT_STRING_On && field->defvalue != setting->value)
11761113      {
1177         mame_printf_error("%s: %s has an input port with an invalid type (0); use IPT_OTHER instead\n", driver->source_file, driver->name);
1178         error = TRUE;
1114         mame_printf_error("%s: %s Demo Sounds must default to On\n", driver->source_file, driver->name);
1115         *error = TRUE;
11791116      }
11801117
1181      /* if this entry doesn't have a name, we don't care about the rest of this stuff */
1182      if (inp->name == NULL || inp->name == IP_NAME_DEFAULT)
1118      /* check for bad demo sounds options */
1119      if (field->name == demo_sounds && (strindex == INPUT_STRING_Yes || strindex == INPUT_STRING_No))
11831120      {
1184         /* not allowed for dipswitches */
1185         if (inp->type == IPT_DIPSWITCH_NAME || inp->type == IPT_DIPSWITCH_SETTING)
1186         {
1187            mame_printf_error("%s: %s has a DIP switch name or setting with no name\n", driver->source_file, driver->name);
1188            error = TRUE;
1189         }
1190         last_strindex = 0;
1191         continue;
1121         mame_printf_error("%s: %s has wrong Demo Sounds option %s (must be Off/On)\n", driver->source_file, driver->name, setting->name);
1122         *error = TRUE;
11921123      }
11931124
1194      /* check for empty string */
1195      if (inp->name[0] == 0 && !empty_string_found)
1125      /* check for bad flip screen options */
1126      if (field->name == flipscreen && (strindex == INPUT_STRING_Yes || strindex == INPUT_STRING_No))
11961127      {
1197         mame_printf_error("%s: %s has an input with an empty string\n", driver->source_file, driver->name);
1198         error = TRUE;
1199         empty_string_found = TRUE;
1128         mame_printf_error("%s: %s has wrong Flip Screen option %s (must be Off/On)\n", driver->source_file, driver->name, setting->name);
1129         *error = TRUE;
12001130      }
12011131
1202      /* check for trailing spaces */
1203      if (inp->name[0] != 0 && inp->name[strlen(inp->name) - 1] == ' ')
1132      /* if we have a neighbor, compare ourselves to him */
1133      if (setting->next != NULL)
12041134      {
1205         mame_printf_error("%s: %s input '%s' has trailing spaces\n", driver->source_file, driver->name, inp->name);
1206         error = TRUE;
1207      }
1135         int next_strindex = get_defstr_index(setting->next->name, driver, error);
12081136
1209      /* check for invalid UTF-8 */
1210      if (!utf8_is_valid_string(inp->name))
1211      {
1212         mame_printf_error("%s: %s input '%s' has invalid characters\n", driver->source_file, driver->name, inp->name);
1213         error = TRUE;
1214      }
1215
1216      /* hash the string and look it up in the string table */
1217      crc = quark_string_crc(inp->name);
1218      for (entry = quark_table_get_first(defstr_table, crc); entry; entry = entry->next)
1219         if (entry->crc == crc && !strcmp(inp->name, input_port_string_from_index(entry - defstr_table->entry)))
1220         {
1221            strindex = entry - defstr_table->entry;
1222            break;
1223         }
1224
1225      /* check for strings that should be DEF_STR */
1226      if (strindex != 0 && inp->name != input_port_string_from_index(strindex))
1227      {
1228         mame_printf_error("%s: %s must use DEF_STR( %s )\n", driver->source_file, driver->name, inp->name);
1229         error = TRUE;
1230      }
1231
1232      /* track the last dipswitch we encountered */
1233      if (inp->type == IPT_DIPSWITCH_NAME)
1234         last_dipname_entry = inp;
1235
1236      /* check for dipswitch ordering against the last entry */
1237      if (inp[0].type == IPT_DIPSWITCH_SETTING && inp[-1].type == IPT_DIPSWITCH_SETTING && last_strindex != 0 && strindex != 0)
1238      {
12391137         /* check for inverted off/on dispswitch order */
1240         if (last_strindex == INPUT_STRING_On && strindex == INPUT_STRING_Off)
1138         if (strindex == INPUT_STRING_On && next_strindex == INPUT_STRING_Off)
12411139         {
12421140            mame_printf_error("%s: %s has inverted Off/On dipswitch order\n", driver->source_file, driver->name);
1243            error = TRUE;
1141            *error = TRUE;
12441142         }
12451143
12461144         /* check for inverted yes/no dispswitch order */
1247         else if (last_strindex == INPUT_STRING_Yes && strindex == INPUT_STRING_No)
1145         else if (strindex == INPUT_STRING_Yes && next_strindex == INPUT_STRING_No)
12481146         {
12491147            mame_printf_error("%s: %s has inverted No/Yes dipswitch order\n", driver->source_file, driver->name);
1250            error = TRUE;
1148            *error = TRUE;
12511149         }
12521150
12531151         /* check for inverted upright/cocktail dispswitch order */
1254         else if (last_strindex == INPUT_STRING_Cocktail && strindex == INPUT_STRING_Upright)
1152         else if (strindex == INPUT_STRING_Cocktail && next_strindex == INPUT_STRING_Upright)
12551153         {
12561154            mame_printf_error("%s: %s has inverted Upright/Cocktail dipswitch order\n", driver->source_file, driver->name);
1257            error = TRUE;
1155            *error = TRUE;
12581156         }
12591157
12601158         /* check for proper coin ordering */
1261         else if (last_strindex >= INPUT_STRING_9C_1C && last_strindex <= INPUT_STRING_1C_9C && strindex >= INPUT_STRING_9C_1C && strindex <= INPUT_STRING_1C_9C &&
1262                last_strindex >= strindex && !memcmp(&inp[-1].condition, &inp[0].condition, sizeof(inp[-1].condition)))
1159         else if (strindex >= INPUT_STRING_9C_1C && strindex <= INPUT_STRING_1C_9C && next_strindex >= INPUT_STRING_9C_1C && next_strindex <= INPUT_STRING_1C_9C &&
1160                strindex >= next_strindex && memcmp(&setting->condition, &setting->next->condition, sizeof(setting->condition)) == 0)
12631161         {
1264            mame_printf_error("%s: %s has unsorted coinage %s > %s\n", driver->source_file, driver->name, inp[-1].name, inp[0].name);
1265            error = TRUE;
1266            coin_error = TRUE;
1162            mame_printf_error("%s: %s has unsorted coinage %s > %s\n", driver->source_file, driver->name, setting->name, setting->next->name);
1163            coin_error = *error = TRUE;
12671164         }
12681165      }
1166   }
12691167
1270      /* check for invalid DIP switch entries */
1271      if (last_dipname_entry && inp->type == IPT_DIPSWITCH_SETTING)
1168   /* if we have a coin error, demonstrate the correct way */
1169   if (coin_error)
1170   {
1171      int entry;
1172
1173      mame_printf_error("%s: %s proper coin sort order should be:\n", driver->source_file, driver->name);
1174      for (entry = 0; entry < ARRAY_LENGTH(coin_list); entry++)
1175         if (coin_list[entry])
1176            mame_printf_error("%s\n", input_port_string_from_index(INPUT_STRING_9C_1C + entry));
1177   }
1178}
1179
1180
1181/*-------------------------------------------------
1182    validate_inputs - validate input configuration
1183-------------------------------------------------*/
1184
1185static int validate_inputs(int drivnum, const machine_config *config)
1186{
1187   const input_port_config *portlist;
1188   const input_port_config *scanport;
1189   const input_port_config *port;
1190   const input_field_config *field;
1191   const game_driver *driver = drivers[drivnum];
1192   int empty_string_found = FALSE;
1193   quark_entry *entry;
1194   int error = FALSE;
1195   UINT32 crc;
1196
1197   /* skip if no ports */
1198   if (driver->ipt == NULL)
1199      return FALSE;
1200
1201   /* skip if we already validated these ports */
1202   crc = (FPTR)driver->ipt;
1203   for (entry = quark_table_get_first(inputs_table, crc); entry != NULL; entry = entry->next)
1204      if (entry->crc == crc && driver->ipt == drivers[entry - inputs_table->entry]->ipt)
1205         return FALSE;
1206
1207   /* otherwise, add ourself to the list */
1208   quark_add(inputs_table, drivnum, crc);
1209
1210   /* allocate the input ports */
1211   portlist = input_port_config_alloc(driver->ipt);
1212
1213   /* check for duplicate tags */
1214   for (port = portlist; port != NULL; port = port->next)
1215      if (port->tag != NULL)
1216         for (scanport = port->next; scanport != NULL; scanport = scanport->next)
1217            if (scanport->tag != NULL && strcmp(port->tag, scanport->tag) == 0)
1218            {
1219               mame_printf_error("%s: %s has a duplicate input port tag \"%s\"\n", driver->source_file, driver->name, port->tag);
1220               error = TRUE;
1221            }
1222
1223   /* iterate over the results */
1224   for (port = portlist; port != NULL; port = port->next)
1225      for (field = port->fieldlist; field != NULL; field = field->next)
12721226      {
1273         /* make sure demo sounds default to on */
1274         if (last_dipname_entry->name == demo_sounds && strindex == INPUT_STRING_On &&
1275            last_dipname_entry->default_value != inp->default_value)
1227         int strindex = 0;
1228
1229         /* verify analog inputs */
1230         if (input_type_is_analog(field->type))
1231            validate_analog_input_field(field, driver, &error);
1232
1233         /* verify dip switches */
1234         if (field->type == IPT_DIPSWITCH)
12761235         {
1277            mame_printf_error("%s: %s Demo Sounds must default to On\n", driver->source_file, driver->name);
1278            error = TRUE;
1236            /* dip switch fields must have a name */
1237            if (field->name == NULL)
1238            {
1239               mame_printf_error("%s: %s has a DIP switch name or setting with no name\n", driver->source_file, driver->name);
1240               error = TRUE;
1241            }
1242
1243            /* verify the settings list */
1244            validate_dip_settings(field, driver, &error);
12791245         }
12801246
1281         /* check for bad flip screen options */
1282         if (last_dipname_entry->name == flipscreen && (strindex == INPUT_STRING_Yes || strindex == INPUT_STRING_No))
1247         /* look for invalid (0) types which should be mapped to IPT_OTHER */
1248         if (field->type == IPT_INVALID)
12831249         {
1284            mame_printf_error("%s: %s has wrong Flip Screen option %s (must be Off/On)\n", driver->source_file, driver->name, inp->name);
1250            mame_printf_error("%s: %s has an input port with an invalid type (0); use IPT_OTHER instead\n", driver->source_file, driver->name);
12851251            error = TRUE;
12861252         }
12871253
1288         /* check for bad demo sounds options */
1289         if (last_dipname_entry->name == demo_sounds && (strindex == INPUT_STRING_Yes || strindex == INPUT_STRING_No))
1254         /* verify names */
1255         if (field->name != NULL)
12901256         {
1291            mame_printf_error("%s: %s has wrong Demo Sounds option %s (must be Off/On)\n", driver->source_file, driver->name, inp->name);
1292            error = TRUE;
1257            /* check for empty string */
1258            if (field->name[0] == 0 && !empty_string_found)
1259            {
1260               mame_printf_error("%s: %s has an input with an empty string\n", driver->source_file, driver->name);
1261               empty_string_found = error = TRUE;
1262            }
1263
1264            /* check for trailing spaces */
1265            if (field->name[0] != 0 && field->name[strlen(field->name) - 1] == ' ')
1266            {
1267               mame_printf_error("%s: %s input '%s' has trailing spaces\n", driver->source_file, driver->name, field->name);
1268               error = TRUE;
1269            }
1270
1271            /* check for invalid UTF-8 */
1272            if (!utf8_is_valid_string(field->name))
1273            {
1274               mame_printf_error("%s: %s input '%s' has invalid characters\n", driver->source_file, driver->name, field->name);
1275               error = TRUE;
1276            }
1277
1278            /* look up the string and print an error if default strings are not used */
1279            strindex = get_defstr_index(field->name, driver, &error);
12931280         }
12941281      }
12951282
1296      /* remember the last string index */
1297      last_strindex = strindex;
1298   }
1283#ifdef MESS
1284   if (mess_validate_input_ports(drivnum, config, portlist))
1285      error = TRUE;
1286#endif /* MESS */
12991287
1300   if ( coin_error )
1301      display_valid_coin_order(drivnum, *memory);
1302
1288   /* free the config */
1289   input_port_config_free(portlist);
13031290   return error;
13041291}
13051292
r2724r2725
13931380   osd_ticks_t mess_checks = 0;
13941381#endif
13951382
1396   input_port_entry *inputports = NULL;
13971383   int drivnum;
13981384   int error = FALSE;
13991385   UINT16 lsbtest;
r2724r2725
14871473
14881474      /* validate input ports */
14891475      input_checks -= osd_profiling_ticks();
1490      error = validate_inputs(drivnum, config, &inputports) || error;
1476      error = validate_inputs(drivnum, config) || error;
14911477      input_checks += osd_profiling_ticks();
14921478
14931479      /* validate sounds and speakers */
src/mess/configms.c
r2724r2725
55****************************************************************************/
66
77#include "mame.h"
8#include "deprecat.h"
98#include "configms.h"
109#include "config.h"
1110#include "xmlfile.h"
r2724r2725
2019   configuration items
2120-------------------------------------------------*/
2221
23static void device_dirs_load(int config_type, xml_data_node *parentnode)
22static void device_dirs_load(running_machine *machine, int config_type, xml_data_node *parentnode)
2423{
2524   xml_data_node *node;
2625   const device_config *dev;
r2724r2725
3837
3938         if ((dev_instance != NULL) && (dev_instance[0] != '\0'))
4039         {
41            for (dev = image_device_first(Machine->config); (image == NULL) && (dev != NULL); dev = image_device_next(dev))
40            for (dev = image_device_first(machine->config); (image == NULL) && (dev != NULL); dev = image_device_next(dev))
4241            {
43               info = image_device_getinfo(Machine->config, dev);
42               info = image_device_getinfo(machine->config, dev);
4443               if (!strcmp(dev_instance, info.instance_name))
4544                  image = dev;
4645            }
r2724r2725
6362   directories to the configuration file
6463-------------------------------------------------*/
6564
66static void device_dirs_save(int config_type, xml_data_node *parentnode)
65static void device_dirs_save(running_machine *machine, int config_type, xml_data_node *parentnode)
6766{
6867   xml_data_node *node;
6968   image_device_info info;
r2724r2725
7372   /* only care about game-specific data */
7473   if (config_type == CONFIG_TYPE_GAME)
7574   {
76      for (image = image_device_first(Machine->config); image != NULL; image = image_device_next(image))
75      for (image = image_device_first(machine->config); image != NULL; image = image_device_next(image))
7776      {
78         info = image_device_getinfo(Machine->config, image);
77         info = image_device_getinfo(machine->config, image);
7978         dev_instance = info.instance_name;
8079
8180         node = xml_add_child(parentnode, "device", NULL);
r2724r2725
9796
9897void mess_config_init(running_machine *machine)
9998{
100   config_register("device_directories", device_dirs_load, device_dirs_save);
99   config_register(machine, "device_directories", device_dirs_load, device_dirs_save);
101100}
src/mess/uimess.c
r2724r2725
77*********************************************************************/
88
99#include "mame.h"
10#include "deprecat.h"
1110#include "mslegacy.h"
1211#include "uimenu.h"
1312#include "uimess.h"
r2724r2725
3130   /* traditional MESS interface */
3231   if (machine->gamedrv->flags & GAME_COMPUTER)
3332   {
34      if( input_ui_pressed(IPT_UI_TOGGLE_UI) )
33      if( input_ui_pressed(machine, IPT_UI_TOGGLE_UI) )
3534      {
3635         if( !ui_toggle_key )
3736         {
r2724r2725
161160
162161
163162
164UINT32 ui_menu_image_info(UINT32 state)
163UINT32 ui_menu_image_info(running_machine *machine, UINT32 state)
165164{
166165   char buf[2048];
167166   char *bufptr = buf;
168167   UINT32 selected = 0;
169168
170169   /* add the game info */
171   bufptr += ui_sprintf_image_info(Machine, bufptr);
170   bufptr += ui_sprintf_image_info(machine, bufptr);
172171
173172   /* make it look like a menu */
174173   bufptr += sprintf(bufptr, "\n\t%s %s %s", ui_getstring(UI_lefthilight), ui_getstring(UI_returntomain), ui_getstring(UI_righthilight));
r2724r2725
177176   ui_draw_message_window(buf);
178177
179178   /* handle the keys */
180   ui_menu_generic_keys(&selected, 1, 0);
179   ui_menu_generic_keys(machine, &selected, 1, 0);
181180   return selected;
182181}
183182
src/mess/uimess.h
r2724r2725
1818
1919/* image info screen */
2020int ui_sprintf_image_info(running_machine *machine, char *buf);
21UINT32 ui_menu_image_info(UINT32 state);
21UINT32 ui_menu_image_info(running_machine *machine, UINT32 state);
2222
2323/* file manager */
24int filemanager(int selected);
24int filemanager(running_machine *machine, int selected);
2525
2626/* tape control */
27int tapecontrol(int selected);
27int tapecontrol(running_machine *machine, int selected);
2828
2929/* paste */
3030void ui_paste(running_machine *machine);
src/mess/mess.h
r2724r2725
5555/***************************************************************************/
5656
5757#if HAS_WAVE
58int tapecontrol(int selected);
58int tapecontrol(running_machine *machine, int selected);
5959void tapecontrol_gettime(char *timepos, size_t timepos_size, const device_config *img, int *curpos, int *endpos);
6060#endif
6161
src/mess/tapectrl.c
r2724r2725
1212#include "uimenu.h"
1313#include "mslegacy.h"
1414#include "devices/cassette.h"
15#include "deprecat.h"
1615
1716
1817
r2724r2725
3837      *endpos = t1;
3938}
4039
41int tapecontrol(int selected)
40int tapecontrol(running_machine *machine, int selected)
4241{
43   running_machine *machine = Machine;
4442   static int id = 0;
4543   char timepos[32];
4644   ui_menu_item menu_item[40];
r2724r2725
6664      strcat(name, ui_getstring(UI_righthilight));
6765      ui_draw_message_window(name);
6866
69      if (input_ui_pressed(IPT_UI_SELECT) || input_ui_pressed(IPT_UI_CANCEL))
67      if (input_ui_pressed(machine, IPT_UI_SELECT) || input_ui_pressed(machine, IPT_UI_CANCEL))
7068         sel = -1;
71      if (input_ui_pressed(IPT_UI_CONFIGURE))
69      if (input_ui_pressed(machine, IPT_UI_CONFIGURE))
7270         sel = -2;
7371
7472      return sel + 1;
r2724r2725
139137
140138   ui_menu_draw(menu_item, total, sel, NULL);
141139
142   if (input_ui_pressed_repeat(IPT_UI_DOWN,8))
140   if (input_ui_pressed_repeat(machine, IPT_UI_DOWN,8))
143141   {
144142      if (sel < total - 1) sel++;
145143      else sel = 0;
146144   }
147145
148   if (input_ui_pressed_repeat(IPT_UI_UP,8))
146   if (input_ui_pressed_repeat(machine, IPT_UI_UP,8))
149147   {
150148      if (sel > 0) sel--;
151149      else sel = total - 1;
152150   }
153151
154152
155   if (input_ui_pressed(IPT_UI_LEFT))
153   if (input_ui_pressed(machine, IPT_UI_LEFT))
156154   {
157155      switch (sel)
158156      {
r2724r2725
163161      }
164162   }
165163
166   if (input_ui_pressed(IPT_UI_RIGHT))
164   if (input_ui_pressed(machine, IPT_UI_RIGHT))
167165   {
168166      switch (sel)
169167      {
r2724r2725
174172      }
175173   }
176174
177   if (input_ui_pressed(IPT_UI_SELECT))
175   if (input_ui_pressed(machine, IPT_UI_SELECT))
178176   {
179177      if (sel == total - 1)
180178         sel = -1;
r2724r2725
210208      }
211209   }
212210
213   if (input_ui_pressed(IPT_UI_CANCEL))
211   if (input_ui_pressed(machine, IPT_UI_CANCEL))
214212      sel = -1;
215213
216   if (input_ui_pressed(IPT_UI_CONFIGURE))
214   if (input_ui_pressed(machine, IPT_UI_CONFIGURE))
217215      sel = -2;
218216
219217   return sel + 1;
src/mess/tools/messtest/testmess.c
r2724r2725
487487
488488
489489
490static void find_switch(running_machine *machine, const char *switch_name, const char *switch_setting,
491   int switch_type, int switch_setting_type,
492   input_port_entry **in_switch, input_port_entry **in_switch_setting)
490static const input_setting_config *find_switch(running_machine *machine, const char *switch_name,
491   const char *switch_setting, int switch_type, int *found_field)
493492{
494   input_port_entry *in;
493   int found = FALSE;
494   const input_port_config *port;
495   const input_field_config *field = NULL;
496   const input_setting_config *setting = NULL;
495497
496   *in_switch = NULL;
497   *in_switch_setting = NULL;
498
499498   /* find switch with the name */
500   in = machine->input_ports;
501   while(in->type != IPT_END)
499   found = FALSE;
500   for (port = machine->portconfig; !found && (port != NULL); port = port->next)
502501   {
503      if (in->type == switch_type && input_port_active(in)
504         && input_port_name(in) && !mame_stricmp(input_port_name(in), switch_name))
505         break;
506      in++;
502      for (field = port->fieldlist; !found && (field != NULL); field = field->next)
503      {
504         if (field->type == switch_type && input_field_name(field) && !mame_stricmp(input_field_name(field), switch_name))
505            found = TRUE;
506      }
507507   }
508   if (in->type == IPT_END)
509      return;
510   *in_switch = in;
511508
512   /* find the setting */
513   in++;
514   while(in->type == switch_setting_type)
509   /* did we find the field? */
510   if (field != NULL)
515511   {
516      if (input_port_active(in) && input_port_name(in) && !mame_stricmp(input_port_name(in), switch_setting))
517         break;
518      in++;
512      /* we did find the field - now find the setting */
513      for (setting = field->settinglist; setting != NULL; setting = setting->next)
514      {
515         if (setting->name != NULL && !mame_stricmp(setting->name, switch_setting))
516            break;
517      }
519518   }
520   if (in->type != switch_setting_type)
521      return;
522   *in_switch_setting = in;
519
520   /* return whether the field was found at all, if we're asked that */
521   if (found_field != NULL)
522      *found_field = (field != NULL);
523
524   return setting;
523525}
524526
525527
r2724r2725
638640
639641static void command_switch(running_machine *machine)
640642{
641   input_port_entry *switch_name;
642   input_port_entry *switch_setting;
643   int found_field;
644   const input_setting_config *setting;
643645
644646   /* special hack until we support video targets natively */
645647   if (!strcmp(current_command->u.switch_args.name, "Video type"))
r2724r2725
662664      }
663665   }
664666
665   find_switch(machine, current_command->u.switch_args.name, current_command->u.switch_args.value,
666      IPT_DIPSWITCH_NAME, IPT_DIPSWITCH_SETTING, &switch_name, &switch_setting);
667   /* first try dip switches */
668   setting = find_switch(machine, current_command->u.switch_args.name,
669      current_command->u.switch_args.value, IPT_DIPSWITCH, &found_field);
667670
668   if (!switch_name || !switch_setting)
671   if (setting == NULL)
669672   {
670      find_switch(machine, current_command->u.switch_args.name, current_command->u.switch_args.value,
671         IPT_CONFIG_NAME, IPT_CONFIG_SETTING, &switch_name, &switch_setting);
673      /* failing that, try configs */
674      setting = find_switch(machine, current_command->u.switch_args.name,
675         current_command->u.switch_args.value, IPT_CONFIG, &found_field);
672676   }
673677
674   if (!switch_name)
678   if (setting == NULL)
675679   {
680      /* now failing that, really fail - lets report a good message */
681      if (found_field)
682      {
683         report_message(MSG_FAILURE, "Cannot find setting '%s' on switch '%s'",
684            current_command->u.switch_args.value, current_command->u.switch_args.name);
685      }
686      else
687      {
688         report_message(MSG_FAILURE, "Cannot find switch named '%s'", current_command->u.switch_args.name);
689      }
676690      state = STATE_ABORTED;
677      report_message(MSG_FAILURE, "Cannot find switch named '%s'", current_command->u.switch_args.name);
678691      return;
679692   }
680693
681   if (!switch_setting)
682   {
683      state = STATE_ABORTED;
684      report_message(MSG_FAILURE, "Cannot find setting '%s' on switch '%s'",
685         current_command->u.switch_args.value, current_command->u.switch_args.name);
686      return;
687   }
688
689   switch_name->default_value = switch_setting->default_value;
694   /* success! */
695   /* FIXME */
696   /* switch_name->default_value = setting->value; */
690697}
691698
692699
src/mess/tools/messtest/tststubs.c
r2724r2725
1414{
1515}
1616
17void osd_customize_inputport_list(input_port_default_entry *defaults)
17void osd_customize_input_type_list(input_type_desc *typelist)
1818{
1919}
2020
src/mess/tools/imgtool/imgtool.c
r2724r2725
25242524   {
25252525      /* append a path */
25262526      if ((strlen(path1) > 0) && (path1[strlen(path1) - 1] != path_separator))
2527         snprintf(buffer, buffer_len, "%s%c%s%c", path1, path_separator, path2, path_separator);
2527         snprintf(buffer, buffer_len, "%s%c%s", path1, path_separator, path2);
25282528      else
2529         snprintf(buffer, buffer_len, "%s%s%c", path1, path2, path_separator);
2529         snprintf(buffer, buffer_len, "%s%s", path1, path2);
25302530   }
25312531   return buffer;
25322532}
src/mess/includes/apple2gs.h
r2724r2725
3333
3434NVRAM_HANDLER( apple2gs );
3535
36void apple2gs_doc_irq(int state);
36void apple2gs_doc_irq(running_machine *machine, int state);
3737
3838
3939/*----------- defined in video/apple2gs.c -----------*/
src/mess/includes/hp48.h
r2724r2725
6969extern HP48_HARDWARE hp48_hardware;
7070
7171extern UINT8 *hp48_ram, *hp48_card1, *hp48_card2;
72void hp48_mem_reset(void);
73void hp48_mem_config(int v);
74void hp48_mem_unconfig(int v);
75int hp48_mem_id(void);
76void hp48_crc(int adr, int data);
77int hp48_in(void);
78void hp48_out(int v);
72void hp48_mem_reset(running_machine *machine);
73void hp48_mem_config(running_machine *machine, int v);
74void hp48_mem_unconfig(running_machine *machine, int v);
75int hp48_mem_id(running_machine *machine);
76void hp48_crc(running_machine *machine, int adr, int data);
77int hp48_in(running_machine *machine);
78void hp48_out(running_machine *machine, int v);
7979
8080DRIVER_INIT( hp48s );
8181DRIVER_INIT( hp48g );
src/mess/includes/msx.h
r2724r2725
6262DEVICE_IMAGE_LOAD( msx_cart );
6363DEVICE_IMAGE_UNLOAD( msx_cart );
6464
65void msx_vdp_interrupt (int);
65void msx_vdp_interrupt(running_machine *machine, int i);
6666
6767/* I/O functions */
6868WRITE8_HANDLER ( msx_printer_w );
src/mess/includes/vectrex.h
r2724r2725
2424void vectrex_configuration(running_machine *machine);
2525READ8_HANDLER (v_via_pa_r);
2626READ8_HANDLER(v_via_pb_r );
27void v_via_irq (int level);
27void v_via_irq (running_machine *machine, int level);
2828WRITE8_HANDLER ( vectrex_psg_port_w );
2929
3030DRIVER_INIT( vectrex );
src/mess/includes/pc8801.h
r2724r2725
1515
1616WRITE8_HANDLER(pc8801_write_interrupt_level);
1717WRITE8_HANDLER(pc8801_write_interrupt_mask);
18 READ8_HANDLER(pc88sr_inport_30);
19 READ8_HANDLER(pc88sr_inport_31);
20 READ8_HANDLER(pc88sr_inport_32);
18READ8_HANDLER(pc88sr_inport_30);
19READ8_HANDLER(pc88sr_inport_31);
20READ8_HANDLER(pc88sr_inport_32);
2121WRITE8_HANDLER(pc88sr_outport_30);
2222WRITE8_HANDLER(pc88sr_outport_31);
2323WRITE8_HANDLER(pc88sr_outport_32);
2424WRITE8_HANDLER(pc88sr_outport_40);
25 READ8_HANDLER(pc88sr_inport_40);
26 READ8_HANDLER(pc8801_inport_70);
25READ8_HANDLER(pc88sr_inport_40);
26READ8_HANDLER(pc8801_inport_70);
2727WRITE8_HANDLER(pc8801_outport_70);
2828WRITE8_HANDLER(pc8801_outport_78);
29 READ8_HANDLER(pc88sr_inport_71);
29READ8_HANDLER(pc88sr_inport_71);
3030WRITE8_HANDLER(pc88sr_outport_71);
3131
3232extern INTERRUPT_GEN( pc8801_interrupt );
r2724r2725
3636void pc8801_update_bank(void);
3737extern unsigned char *pc8801_mainRAM;
3838extern int pc88sr_is_highspeed;
39 READ8_HANDLER(pc8801fd_nec765_tc);
40void pc88sr_sound_interupt(int irq);
39READ8_HANDLER(pc8801fd_nec765_tc);
40void pc88sr_sound_interupt(running_machine *machine, int irq);
4141WRITE8_HANDLER(pc8801_write_kanji1);
42 READ8_HANDLER(pc8801_read_kanji1);
42READ8_HANDLER(pc8801_read_kanji1);
4343WRITE8_HANDLER(pc8801_write_kanji2);
44 READ8_HANDLER(pc8801_read_kanji2);
44READ8_HANDLER(pc8801_read_kanji2);
4545WRITE8_HANDLER(pc8801_calender);
46 READ8_HANDLER(pc8801_read_extmem);
46READ8_HANDLER(pc8801_read_extmem);
4747WRITE8_HANDLER(pc8801_write_extmem);
4848
4949
src/mess/includes/svi318.h
r2724r2725
2727DEVICE_IMAGE_UNLOAD( svi318_cart );
2828
2929INTERRUPT_GEN( svi318_interrupt );
30void svi318_vdp_interrupt(int i);
30void svi318_vdp_interrupt(running_machine *machine, int i);
3131
3232WRITE8_HANDLER( svi318_writemem1 );
3333WRITE8_HANDLER( svi318_writemem2 );
src/mess/video/pc_cga.c
r2724r2725
154154INPUT_PORTS_END
155155
156156/* Dipswitch for font selection */
157#define CGA_FONT        (input_port_read_indexed(machine, cga.config_input_port)&3)
157#define CGA_FONT        (input_port_read_direct(cga.config_input_port)&3)
158158
159159/* Dipswitch for monitor selection */
160#define CGA_MONITOR     (input_port_read_indexed(machine, cga.config_input_port)&0x1C)
160#define CGA_MONITOR     (input_port_read_direct(cga.config_input_port)&0x1C)
161161#define CGA_MONITOR_RGB         0x00    /* Colour RGB */
162162#define CGA_MONITOR_MONO        0x04    /* Greyscale RGB */
163163#define CGA_MONITOR_COMPOSITE   0x08    /* Colour composite */
r2724r2725
166166
167167
168168/* Dipswitch for chipset selection */
169#define CGA_CHIPSET     (input_port_read_indexed(machine, cga.config_input_port)&0xE0)
169#define CGA_CHIPSET     (input_port_read_direct(cga.config_input_port)&0xE0)
170170#define CGA_CHIPSET_IBM         0x00    /* Original IBM CGA */
171171#define CGA_CHIPSET_PC1512      0x20    /* PC1512 CGA subset */
172172#define CGA_CHIPSET_PC200       0x40    /* PC200 in CGA mode */
r2724r2725
242242
243243   UINT8   *chr_gen;
244244
245   int      config_input_port;
245   const input_port_config *config_input_port;
246246
247247   mc6845_update_row_func   update_row;
248248   UINT8   palette_lut_2bpp[4];
r2724r2725
454454   state_save_register_item("pccga", 0, cga.status);
455455   state_save_register_item("pccga", 0, cga.plantronics);
456456
457   cga.config_input_port = port_tag_to_index( "pcvideo_cga_config" );
457   cga.config_input_port = input_port_by_tag(Machine->portconfig, "pcvideo_cga_config" );
458458
459459   return 0;
460460}
r2724r2725
513513
514514static VIDEO_UPDATE( mc6845_cga )
515515{
516   running_machine *machine = screen->machine;
517516   device_config   *devconf = (device_config *) device_list_find_by_tag(screen->machine->config->devicelist, MC6845, CGA_MC6845_NAME);
518517   mc6845_update( devconf, bitmap, cliprect);
519518
r2724r2725
11651164 */
11661165static void pc_cga_plantronics_w(int data)
11671166{
1168   running_machine *machine = Machine;
1169
11701167   CGA_LOG(1,"CGA_plantronics_w",("$%02x\n", data));
11711168
11721169   if (CGA_CHIPSET != CGA_CHIPSET_ATI) return;
r2724r2725
16401637
16411638static VIDEO_UPDATE( mc6845_pc1512 )
16421639{
1643   running_machine *machine = screen->machine;
16441640   device_config   *devconf = (device_config *) device_list_find_by_tag(screen->machine->config->devicelist, MC6845, CGA_MC6845_NAME);
16451641   mc6845_update( devconf, bitmap, cliprect);
16461642
src/mess/inputx.c
r2724r2725
2727#define NUM_SIMUL_KEYS   (UCHAR_SHIFT_END - UCHAR_SHIFT_BEGIN + 1)
2828#define LOG_INPUTX      0
2929#define SPACE_COUNT      3
30#define INVALID_CHAR   '?'
31#define IP_NAME_DEFAULT   NULL
3032
3133
3234
r2724r2725
3436    TYPE DEFINITIONS
3537***************************************************************************/
3638
39typedef const input_port_config *input_port_config_c;
40typedef const input_field_config *input_field_config_c;
41
42
3743typedef struct _mess_input_code mess_input_code;
3844struct _mess_input_code
3945{
4046   unicode_char ch;
41   UINT32 port[NUM_SIMUL_KEYS];
42   const input_port_entry *ipt[NUM_SIMUL_KEYS];
47   input_port_config_c port[NUM_SIMUL_KEYS];
48   input_field_config_c ipt[NUM_SIMUL_KEYS];
4349};
4450
4551typedef struct _key_buffer key_buffer;
r2724r2725
361367
362368
363369
364#define INVALID_CHAR '?'
365370
366371/***************************************************************************
372    MISCELLANEOUS
373***************************************************************************/
367374
368   Char info lookup
375/*-------------------------------------------------
376    find_charinfo - looks up information about a
377   particular character
378-------------------------------------------------*/
369379
370***************************************************************************/
371
372380static const char_info *find_charinfo(unicode_char target_char)
373381{
374382   int low = 0;
r2724r2725
394402
395403
396404/***************************************************************************
397
398   Code assembling
399
405    CODE ASSEMBLING
400406***************************************************************************/
401407
402408/*-------------------------------------------------
r2724r2725
448454
449455
450456
451static unicode_char get_keyboard_code(const input_port_entry *ipt, int i)
457/*-------------------------------------------------
458    get_keyboard_code - accesses a particular
459   keyboard code
460-------------------------------------------------*/
461
462static unicode_char get_keyboard_code(const input_field_config *field, int i)
452463{
453   unicode_char ch = ipt->keyboard.chars[i];
464   unicode_char ch = field->chars[i];
454465
455466   /* special hack to allow for PORT_CODE('\xA3') */
456467   if ((ch >= 0xFFFFFF80) && (ch <= 0xFFFFFFFF))
r2724r2725
460471
461472
462473
463static int scan_keys(const input_port_entry *input_ports, mess_input_code *codes, UINT32 *ports, const input_port_entry **shift_ports, int keys, int shift)
474/*-------------------------------------------------
475    scan_keys - scans through input ports and
476   sets up natural keyboard input mapping
477-------------------------------------------------*/
478
479static int scan_keys(const input_port_config *portconfig, mess_input_code *codes, input_port_config_c *ports, input_field_config_c *shift_ports, int keys, int shift)
464480{
465481   int code_count = 0;
466   const input_port_entry *ipt;
467   const input_port_entry *ipt_key = NULL;
468   UINT32 port = (UINT32) -1;
482   const input_port_config *port;
483   const input_field_config *field;
469484   unicode_char code;
470485
471486   assert(keys < NUM_SIMUL_KEYS);
472487
473   ipt = input_ports;
474   while(ipt->type != IPT_END)
488   for (port = portconfig; port != NULL; port = port->next)
475489   {
476      switch(ipt->type)
490      for (field = port->fieldlist; field != NULL; field = field->next)
477491      {
478         case IPT_KEYBOARD:
479            ipt_key = ipt;
480
481            code = get_keyboard_code(ipt, shift);
492         if (field->type == IPT_KEYBOARD)
493         {
494            code = get_keyboard_code(field, shift);
482495            if (code != 0)
483496            {
484497               /* is this a shifter key? */
485498               if ((code >= UCHAR_SHIFT_BEGIN) && (code <= UCHAR_SHIFT_END))
486499               {
487                  ports[keys] = port;
488                  shift_ports[keys] = ipt_key;
489                  code_count += scan_keys(input_ports,
500                  shift_ports[keys] = field;
501                  code_count += scan_keys(portconfig,
490502                     codes ? &codes[code_count] : NULL,
491503                     ports,
492504                     shift_ports,
r2724r2725
503515                     memcpy((void *) codes[code_count].ipt, shift_ports, sizeof(shift_ports[0]) * keys);
504516                     codes[code_count].ch = code;
505517                     codes[code_count].port[keys] = port;
506                     codes[code_count].ipt[keys] = ipt_key;
518                     codes[code_count].ipt[keys] = field;
507519                  }
508520
509521                  /* increment the count */
510522                  code_count++;
511523
512524                  if (LOG_INPUTX)
513                     logerror("inputx: code=%i (%s) port=%i ipt->name='%s'\n", (int) code, code_point_string(code), port, ipt->name);
525                     logerror("inputx: code=%i (%s) port=%p field->name='%s'\n", (int) code, code_point_string(code), port, field->name);
514526               }
515527            }
516            break;
517
518         case IPT_PORT:
519            port++;
520            /* fall through */
521
522         default:
523            ipt_key = NULL;
524            break;
528         }
525529      }
526      ipt++;
527530   }
528531   return code_count;
529532}
r2724r2725
536539   chars
537540-------------------------------------------------*/
538541
539static mess_input_code *build_codes(const input_port_entry *input_ports)
542static mess_input_code *build_codes(const input_port_config *portconfig)
540543{
541544   mess_input_code *codes = NULL;
542   UINT32 ports[NUM_SIMUL_KEYS];
543   const input_port_entry *ipts[NUM_SIMUL_KEYS];
545   const input_port_config *ports[NUM_SIMUL_KEYS];
546   const input_field_config *ipts[NUM_SIMUL_KEYS];
544547   int code_count;
545548
546549   /* first count the number of codes */
547   code_count = scan_keys(input_ports, NULL, ports, ipts, 0, 0);
550   code_count = scan_keys(portconfig, NULL, ports, ipts, 0, 0);
548551   if (code_count > 0)
549552   {
550553      /* allocate the codes */
r2724r2725
552555      memset(codes, 0, sizeof(*codes) * (code_count + 1));
553556
554557      /* and populate them */
555      scan_keys(input_ports, codes, ports, ipts, 0, 0);
558      scan_keys(portconfig, codes, ports, ipts, 0, 0);
556559   }
557560   return codes;
558561}
r2724r2725
560563
561564
562565/***************************************************************************
566    VALIDITY CHECKS
567***************************************************************************/
563568
564   Validity checks
569/*-------------------------------------------------
570    mess_validate_input_ports - validates the
571   natural keyboard setup of a set of input ports
572-------------------------------------------------*/
565573
566***************************************************************************/
574int mess_validate_input_ports(int drivnum, const machine_config *config, const input_port_config *portlist)
575{
576   int error = FALSE;
567577
568int inputx_validitycheck(const game_driver *gamedrv, input_port_entry **memory)
578   if (drivers[drivnum]->flags & GAME_COMPUTER)
579   {
580      /* unused hook */
581   }
582
583   return error;
584}
585
586
587
588/*-------------------------------------------------
589    mess_validate_natural_keyboard_statics -
590   validates natural keyboard static data
591-------------------------------------------------*/
592
593int mess_validate_natural_keyboard_statics(void)
569594{
570   mess_input_code *codes;
571   const input_port_entry *input_ports;
572   const input_port_entry *ipt;
573   int port_count, i, j;
574   int error = 0;
595   int i;
596   int error = FALSE;
575597   unicode_char last_char = 0;
576598   const char_info *ci;
577599
578   if (gamedrv)
600   /* check to make sure that charinfo is in order */
601   for (i = 0; i < sizeof(charinfo) / sizeof(charinfo[0]); i++)
579602   {
580      if (gamedrv->flags & GAME_COMPUTER)
603      if (last_char >= charinfo[i].ch)
581604      {
582         /* allocate the input ports */
583         *memory = input_port_allocate(gamedrv->ipt, *memory);
584         input_ports = *memory;
585
586         codes = build_codes(input_ports);
587         if (codes)
588         {
589            /* count the total amount of ports */
590            port_count = 0;
591            for (ipt = input_ports; ipt->type != IPT_END; ipt++)
592            {
593               if (ipt->type == IPT_PORT)
594                  port_count++;
595            }
596
597            for (i = 0; codes[i].ch; i++)
598            {
599               for (j = 0; j < NUM_SIMUL_KEYS; j++)
600               {
601                  if (codes[i].port[j] >= port_count)
602                  {
603                     mame_printf_error("%s: invalid inputx translation for code %i port %i\n", gamedrv->name, i, j);
604                     error = 1;
605                  }
606               }
607            }
608         }
605         mame_printf_error("inputx: charinfo is out of order; 0x%08x should be higher than 0x%08x\n", charinfo[i].ch, last_char);
606         error = TRUE;
609607      }
608      last_char = charinfo[i].ch;
610609   }
611   else
610
611   /* check to make sure that I can look up everything on alternate_charmap */
612   for (i = 0; i < sizeof(charinfo) / sizeof(charinfo[0]); i++)
612613   {
613      /* check to make sure that charinfo is in order */
614      for (i = 0; i < sizeof(charinfo) / sizeof(charinfo[0]); i++)
614      ci = find_charinfo(charinfo[i].ch);
615      if (ci != &charinfo[i])
615616      {
616         if (last_char >= charinfo[i].ch)
617         {
618            mame_printf_error("inputx: charinfo is out of order; 0x%08x should be higher than 0x%08x\n", charinfo[i].ch, last_char);
619            error = 1;
620         }
621         last_char = charinfo[i].ch;
617         mame_printf_error("inputx: expected find_charinfo(0x%08x) to work properly\n", charinfo[i].ch);
618         error = TRUE;
622619      }
623
624      /* check to make sure that I can look up everything on alternate_charmap */
625      for (i = 0; i < sizeof(charinfo) / sizeof(charinfo[0]); i++)
626      {
627         ci = find_charinfo(charinfo[i].ch);
628         if (ci != &charinfo[i])
629         {
630            mame_printf_error("inputx: expected find_charinfo(0x%08x) to work properly\n", charinfo[i].ch);
631            error = 1;
632         }
633      }
634620   }
635621   return error;
636622}
r2724r2725
699685   /* posting keys directly only makes sense for a computer */
700686   if (machine->gamedrv->flags & GAME_COMPUTER)
701687   {
702      codes = build_codes(machine->input_ports);
688      codes = build_codes(machine->portconfig);
703689      setup_keybuffer(machine);
704690   }
705691}
r2724r2725
882868            if (LOG_INPUTX)
883869            {
884870               code = find_code(ch);
885               logerror("inputx_postn(): code=%i (%s) port=%i ipt->name='%s'\n", (int) ch, code_point_string(ch), code ? code->port[0] : -1, (code && code->ipt[0]) ? code->ipt[0]->name : "<null>");
871               logerror("inputx_postn(): code=%i (%s) port=%p field->name='%s'\n", (int) ch, code_point_string(ch), code ? code->port[0] : NULL, (code && code->ipt[0]) ? code->ipt[0]->name : "<null>");
886872            }
887873
888874            if (can_post_key_directly(ch))
r2724r2725
962948   called from core to allow for natural keyboard   
963949-------------------------------------------------*/
964950
965void mess_input_port_update_hook(running_machine *machine, int portnum, UINT32 *digital)
951void mess_input_port_update_hook(running_machine *machine, const input_port_config *port)
966952{
967953   const key_buffer *keybuf;
968954   const mess_input_code *code;
r2724r2725
986972         {
987973            for (i = 0; i < ARRAY_LENGTH(code->ipt) && (code->ipt[i] != NULL); i++)
988974            {
989               if (code->port[i] == portnum)
975               if (code->port[i] == port)
990976               {
991977                  value = code->ipt[i]->mask;
992                  *digital |= value;
978                  /* 24-May-2008 - FIXME */
979                  /* *digital |= value; */
993980               }
994981            }
995982         }
r2724r2725
999986
1000987
1001988
1002void inputx_handle_mess_extensions(input_port_entry *ipt)
989void inputx_handle_mess_extensions(input_field_config *ipt)
1003990{
1004991   char buf[256];
1005992   int i, pos;
r2724r2725
10141001         buf[0] = '\0';
10151002         pos = 0;
10161003
1017         for (i = 0; i < ARRAY_LENGTH(ipt->keyboard.chars) && ipt->keyboard.chars[i]; i++)
1004         for (i = 0; i < ARRAY_LENGTH(ipt->chars) && ipt->chars[i]; i++)
10181005         {
10191006            ch = get_keyboard_code(ipt, i);
10201007            pos += snprintf(&buf[pos], ARRAY_LENGTH(buf) - pos, "%-*s ", MAX(SPACE_COUNT - 1, 0), inputx_key_name(ch));
r2724r2725
13551342   This stuff is here more out of convienience than anything else
13561343***************************************************************************/
13571344
1358int input_classify_port(const input_port_entry *port)
1345int input_classify_port(const input_field_config *field)
13591346{
13601347   int result;
13611348
1362   if (port->unused)
1363      return INPUT_CLASS_INTERNAL;
1364   if (port->category && (port->type != IPT_CATEGORY_SETTING))
1349   if (field->category && (field->type != IPT_CATEGORY))
13651350      return INPUT_CLASS_CATEGORIZED;
13661351
1367   switch(port->type) {
1368   case IPT_JOYSTICK_UP:
1369   case IPT_JOYSTICK_DOWN:
1370   case IPT_JOYSTICK_LEFT:
1371   case IPT_JOYSTICK_RIGHT:
1372   case IPT_JOYSTICKLEFT_UP:
1373   case IPT_JOYSTICKLEFT_DOWN:
1374   case IPT_JOYSTICKLEFT_LEFT:
1375   case IPT_JOYSTICKLEFT_RIGHT:
1376   case IPT_JOYSTICKRIGHT_UP:
1377   case IPT_JOYSTICKRIGHT_DOWN:
1378   case IPT_JOYSTICKRIGHT_LEFT:
1379   case IPT_JOYSTICKRIGHT_RIGHT:
1380   case IPT_BUTTON1:
1381   case IPT_BUTTON2:
1382   case IPT_BUTTON3:
1383   case IPT_BUTTON4:
1384   case IPT_BUTTON5:
1385   case IPT_BUTTON6:
1386   case IPT_BUTTON7:
1387   case IPT_BUTTON8:
1388   case IPT_BUTTON9:
1389   case IPT_BUTTON10:
1390   case IPT_AD_STICK_X:
1391   case IPT_AD_STICK_Y:
1392   case IPT_AD_STICK_Z:
1393   case IPT_TRACKBALL_X:
1394   case IPT_TRACKBALL_Y:
1395   case IPT_LIGHTGUN_X:
1396   case IPT_LIGHTGUN_Y:
1397   case IPT_MOUSE_X:
1398   case IPT_MOUSE_Y:
1399   case IPT_START:
1400   case IPT_SELECT:
1401      result = INPUT_CLASS_CONTROLLER;
1402      break;
1352   switch(field->type)
1353   {
1354      case IPT_JOYSTICK_UP:
1355      case IPT_JOYSTICK_DOWN:
1356      case IPT_JOYSTICK_LEFT:
1357      case IPT_JOYSTICK_RIGHT:
1358      case IPT_JOYSTICKLEFT_UP:
1359      case IPT_JOYSTICKLEFT_DOWN:
1360      case IPT_JOYSTICKLEFT_LEFT:
1361      case IPT_JOYSTICKLEFT_RIGHT:
1362      case IPT_JOYSTICKRIGHT_UP:
1363      case IPT_JOYSTICKRIGHT_DOWN:
1364      case IPT_JOYSTICKRIGHT_LEFT:
1365      case IPT_JOYSTICKRIGHT_RIGHT:
1366      case IPT_BUTTON1:
1367      case IPT_BUTTON2:
1368      case IPT_BUTTON3:
1369      case IPT_BUTTON4:
1370      case IPT_BUTTON5:
1371      case IPT_BUTTON6:
1372      case IPT_BUTTON7:
1373      case IPT_BUTTON8:
1374      case IPT_BUTTON9:
1375      case IPT_BUTTON10:
1376      case IPT_AD_STICK_X:
1377      case IPT_AD_STICK_Y:
1378      case IPT_AD_STICK_Z:
1379      case IPT_TRACKBALL_X:
1380      case IPT_TRACKBALL_Y:
1381      case IPT_LIGHTGUN_X:
1382      case IPT_LIGHTGUN_Y:
1383      case IPT_MOUSE_X:
1384      case IPT_MOUSE_Y:
1385      case IPT_START:
1386      case IPT_SELECT:
1387         result = INPUT_CLASS_CONTROLLER;
1388         break;
14031389
1404   case IPT_KEYBOARD:
1405      result = INPUT_CLASS_KEYBOARD;
1406      break;
1390      case IPT_KEYBOARD:
1391         result = INPUT_CLASS_KEYBOARD;
1392         break;
14071393
1408   case IPT_CONFIG_NAME:
1409      result = INPUT_CLASS_CONFIG;
1410      break;
1394      case IPT_CONFIG:
1395         result = INPUT_CLASS_CONFIG;
1396         break;
14111397
1412   case IPT_DIPSWITCH_NAME:
1413      result = INPUT_CLASS_DIPSWITCH;
1414      break;
1398      case IPT_DIPSWITCH:
1399         result = INPUT_CLASS_DIPSWITCH;
1400         break;
14151401
1416   case 0:
1417      if (port->name && (port->name != (const char *) -1))
1418         result = INPUT_CLASS_MISC;
1419      else
1402      case 0:
1403         if (field->name && (field->name != (const char *) -1))
1404            result = INPUT_CLASS_MISC;
1405         else
1406            result = INPUT_CLASS_INTERNAL;
1407         break;
1408
1409      default:
14201410         result = INPUT_CLASS_INTERNAL;
1421      break;
1422
1423   default:
1424      result = INPUT_CLASS_INTERNAL;
1425      break;
1411         break;
14261412   }
14271413   return result;
14281414}
14291415
14301416
14311417
1432int input_player_number(const input_port_entry *port)
1418int input_player_number(const input_field_config *port)
14331419{
14341420   return port->player;
14351421}
14361422
14371423
14381424
1425/*-------------------------------------------------
1426    input_has_input_class - checks to see if a
1427   particular input class is present
1428-------------------------------------------------*/
1429
14391430int input_has_input_class(running_machine *machine, int inputclass)
14401431{
1441   input_port_entry *in;
1442   for (in = machine->input_ports; in->type != IPT_END; in++)
1432   const input_port_config *port;
1433   const input_field_config *field;
1434
1435   for (port = machine->portconfig; port != NULL; port = port->next)
14431436   {
1444      if (input_classify_port(in) == inputclass)
1445         return TRUE;
1437      for (field = port->fieldlist; field != NULL; field = field->next)
1438      {
1439         if (input_classify_port(field) == inputclass)
1440            return TRUE;
1441      }
14461442   }
14471443   return FALSE;
14481444}
14491445
14501446
14511447
1448/*-------------------------------------------------
1449    input_count_players - counts the number of
1450   active players
1451-------------------------------------------------*/
1452
14521453int input_count_players(running_machine *machine)
14531454{
1454   const input_port_entry *in;
1455   const input_port_config *port;
1456   const input_field_config *field;
14551457   int joystick_count;
14561458
14571459   joystick_count = 0;
1458   for (in = machine->input_ports; in->type != IPT_END; in++)
1460   for (port = machine->portconfig; port != NULL; port = port->next)
14591461   {
1460      if (input_classify_port(in) == INPUT_CLASS_CONTROLLER)
1462      for (field = port->fieldlist; field != NULL; field = field->next)
14611463      {
1462         if (joystick_count <= in->player + 1)
1463            joystick_count = in->player + 1;
1464         if (input_classify_port(field) == INPUT_CLASS_CONTROLLER)
1465         {
1466            if (joystick_count <= field->player + 1)
1467               joystick_count = field->player + 1;
1468         }
14641469      }
14651470   }
14661471   return joystick_count;
r2724r2725
14681473
14691474
14701475
1476/*-------------------------------------------------
1477    input_category_active - checks to see if a
1478   specific category is active
1479-------------------------------------------------*/
1480
14711481int input_category_active(running_machine *machine, int category)
14721482{
1473   const input_port_entry *in;
1474   const input_port_entry *in_base = NULL;
1483   int found;
1484   const input_port_config *port;
1485   const input_field_config *field = NULL;
1486   const input_setting_config *setting;
14751487
14761488   assert(category >= 1);
14771489
1478   for (in = machine->input_ports; in->type != IPT_END; in++)
1490   found = FALSE;
1491   for (port = machine->portconfig; !found && (port != NULL); port = port->next)
14791492   {
1480      switch(in->type) {
1481      case IPT_CATEGORY_NAME:
1482         in_base = in;
1483         break;
1493      for (field = port->fieldlist; !found && (field != NULL); field = field->next)
1494         found = (field->type == IPT_CATEGORY) && (field->category == category);
1495   }
14841496
1485      case IPT_CATEGORY_SETTING:
1486         if ((in->category == category) && (in_base->default_value == in->default_value))
1497   if (field != NULL)
1498   {
1499      for (setting = field->settinglist; setting != NULL; setting = setting->next)
1500      {
1501         if (setting->value == field->defvalue)
14871502            return TRUE;
1488         break;
14891503      }
14901504   }
14911505   return FALSE;
src/mess/inputx.h
r2724r2725
5151
5252/* these are called by the core; they should not be called from FEs */
5353void inputx_init(running_machine *machine);
54void mess_input_port_update_hook(running_machine *machine, int portnum, UINT32 *digital);
55void inputx_handle_mess_extensions(input_port_entry *ipt);
54void mess_input_port_update_hook(running_machine *machine, const input_port_config *port);
55/*void inputx_handle_mess_extensions(input_port_entry *ipt);*/
5656
5757/* called by drivers to setup natural keyboard support */
5858void inputx_setup_natural_keyboard(
r2724r2725
6060   int (*accept_char)(unicode_char ch),
6161   int (*charqueue_empty)(void));
6262
63/* run the validity checks */
64int inputx_validitycheck(const game_driver *gamedrv, input_port_entry **memory);
63/* validity checks */
64int mess_validate_input_ports(int drivnum, const machine_config *config, const input_port_config *portlist);
65int mess_validate_natural_keyboard_statics(void);
6566
6667/* these can be called from FEs */
6768int inputx_can_post(running_machine *machine);
r2724r2725
9091void inputx_postn_coded_rate(running_machine *machine, const char *text, size_t text_len, attotime rate);
9192
9293/* miscellaneous functions */
93int input_classify_port(const input_port_entry *in);
94int input_classify_port(const input_field_config *field);
9495int input_has_input_class(running_machine *machine, int inputclass);
95int input_player_number(const input_port_entry *in);
96int input_player_number(const input_field_config *field);
9697int input_count_players(running_machine *machine);
9798int input_category_active(running_machine *machine, int category);
9899
src/mess/filemngr.c
r2724r2725
77*********************************************************************/
88
99#include "driver.h"
10#include "deprecat.h"
1110#include "utils.h"
1211#include "image.h"
1312#include "ui.h"
r2724r2725
449448/* and mask to get bits */
450449#define SEL_BITS_MASK         (~SEL_MASK)
451450
452static int fileselect(int selected, const char *default_selection, const char *working_directory)
451static int fileselect(running_machine *machine, int selected, const char *default_selection, const char *working_directory)
453452{
454453   int sel, total, arrowize;
455454   int visible;
456   running_machine *machine = Machine;
457455
458456   sel = selected - 1;
459457
r2724r2725
536534      /* Maybe the following code up to IPT_UI_PAUSE can be replaced with a call to ui_menu_generic_keys() */
537535
538536      /* up backs up by one item */
539      if (input_ui_pressed_repeat(IPT_UI_UP, 6))
537      if (input_ui_pressed_repeat(machine, IPT_UI_UP, 6))
540538         sel = (sel + total - 1) % total;
541539
542540      /* down advances by one item */
543      if (input_ui_pressed_repeat(IPT_UI_DOWN, 6))
541      if (input_ui_pressed_repeat(machine, IPT_UI_DOWN, 6))
544542         sel = (sel +  1) % total;
545543
546544      /* page up backs up by visible_items */
547      if (input_ui_pressed_repeat(IPT_UI_PAGE_UP, 6))
545      if (input_ui_pressed_repeat(machine, IPT_UI_PAGE_UP, 6))
548546      {
549547         if (sel >= visible - 1)
550548            sel -= visible - 1;
r2724r2725
553551      }
554552
555553      /* page down advances by visible_items */
556      if (input_ui_pressed_repeat(IPT_UI_PAGE_DOWN, 6))
554      if (input_ui_pressed_repeat(machine, IPT_UI_PAGE_DOWN, 6))
557555      {
558556         sel += visible - 1;
559557         if (sel >= total)
r2724r2725
561559      }
562560
563561      /* home goes to the start */
564      if (input_ui_pressed(IPT_UI_HOME))
562      if (input_ui_pressed(machine, IPT_UI_HOME))
565563         sel = 0;
566564
567565      /* end goes to the last */
568      if (input_ui_pressed(IPT_UI_END))
566      if (input_ui_pressed(machine, IPT_UI_END))
569567         sel = total - 1;
570568
571569      /* pause enables/disables pause */
572      if (input_ui_pressed(IPT_UI_PAUSE))
570      if (input_ui_pressed(machine, IPT_UI_PAUSE))
573571         mame_pause(machine, !mame_is_paused(machine));
574572
575      if (input_ui_pressed(IPT_UI_SELECT))
573      if (input_ui_pressed(machine, IPT_UI_SELECT))
576574      {
577575         if (sel < SEL_MASK)
578576         {
r2724r2725
643641         }
644642      }
645643
646      if (input_ui_pressed(IPT_UI_CANCEL))
644      if (input_ui_pressed(machine, IPT_UI_CANCEL))
647645         sel = -1;
648646
649      if (input_ui_pressed(IPT_UI_CONFIGURE))
647      if (input_ui_pressed(machine, IPT_UI_CONFIGURE))
650648         sel = -2;
651649   }
652650   else
r2724r2725
665663   return sel + 1;
666664}
667665
668int filemanager(int selected)
666int filemanager(running_machine *machine, int selected)
669667{
670   running_machine *machine = Machine;
671668   static int previous_sel;
672669   const char *name;
673670   ui_menu_item menu_items[40];
r2724r2725
699696   if (sel & (2 << SEL_BITS))
700697   {
701698      image = devices[previous_sel & SEL_MASK];
702      sel = fileselect(selected & ~(2 << SEL_BITS), image_filename(image), image_working_directory(image));
699      sel = fileselect(machine, selected & ~(2 << SEL_BITS), image_filename(image), image_working_directory(image));
703700      if (sel != 0 && sel != -1 && sel!=-2)
704701         return sel | (2 << SEL_BITS);
705702
r2724r2725
757754
758755   visible = ui_menu_draw(menu_items, total, sel, NULL);
759756
760   if (input_ui_pressed(IPT_UI_SELECT))
757   if (input_ui_pressed(machine, IPT_UI_SELECT))
761758   {
762759      int os_sel;
763760
r2724r2725
807804         sel |= 1 << SEL_BITS;   /* we'll ask for a key */
808805      }
809806   }
810   else if (input_ui_pressed(IPT_UI_CANCEL))
807   else if (input_ui_pressed(machine, IPT_UI_CANCEL))
811808   {
812809      sel = -1;
813810   }
814811   else
815812   {
816      ui_menu_generic_keys(&sel, total, visible);
813      ui_menu_generic_keys(machine, &sel, total, visible);
817814   }
818815
819   if (input_ui_pressed(IPT_UI_CONFIGURE))
816   if (input_ui_pressed(machine, IPT_UI_CONFIGURE))
820817      sel = -2;
821818
822819   return sel + 1;
src/mess/mesvalid.c
r2724r2725
286286   int error = 0;
287287   iodevice_t devtype;
288288   const char *name;
289   input_port_entry *inputports = NULL;
290289
291290   /* make sure that all of the UI_* strings are set for all devices */
292291   for (devtype = 0; devtype < IO_COUNT; devtype++)
r2724r2725
310309
311310      /* check system config */
312311      ram_option_count(drivers[i]);
313
314      /* make sure that our input system likes this driver */
315      error = inputx_validitycheck(drivers[i], &inputports) || error;
316312   }
317313
318314   /* call other validity checks */
319   error = inputx_validitycheck(NULL, &inputports) || error;
315   error = mess_validate_natural_keyboard_statics() || error;
320316   error = device_valididtychecks() || error;
321317
322318   return error;
src/mess/osd/windows/dialog.c
r2724r2725
12641264//   input_port_mutable_seq
12651265//============================================================
12661266
1267static input_seq *input_port_mutable_seq(input_port_entry *port, int seqtype)
1267static input_seq *input_port_mutable_seq(input_field_config *field, int seqtype)
12681268{
12691269   input_seq *portseq;
12701270
1271   // if port is disabled, return no key
1272   if (port->unused)
1271   // if field is disabled, return no key
1272   if (field->flags & FIELD_FLAG_UNUSED)
12731273      return NULL;
12741274
12751275   // handle the various seq types
1276   switch (seqtype)
1277   {
1278      case SEQ_TYPE_STANDARD:
1279         portseq = &port->seq;
1280         break;
1276   portseq = &field->seq[seqtype];
12811277
1282      case SEQ_TYPE_INCREMENT:
1283         portseq = &port->analog.incseq;
1284         break;
1285
1286      case SEQ_TYPE_DECREMENT:
1287         portseq = &port->analog.decseq;
1288         break;
1289
1290      default:
1291         return NULL;
1292   }
1293
12941278   // does this override the default? if not, find the default setting
12951279   if (input_seq_get_1(portseq) == SEQCODE_DEFAULT)
12961280   {
12971281      const input_seq *default_portseq;
1298      default_portseq = input_port_default_seq(port->type, port->player, seqtype);
1282      default_portseq = input_type_seq(field->port->machine, field->type, field->player, seqtype);
12991283      *portseq = *default_portseq;
13001284   }
13011285   return portseq;
r2724r2725
13061290//============================================================
13071291
13081292static int dialog_add_single_seqselect(struct _dialog_box *di, short x, short y,
1309   short cx, short cy, input_port_entry *port, int is_analog, int seq)
1293   short cx, short cy, input_field_config *field, int is_analog, int seq)
13101294{
13111295   seqselect_info *stuff;
13121296   input_seq *code;
13131297
1314   code = input_port_mutable_seq(port, seq);
1298   code = input_port_mutable_seq(field, seq);
13151299
13161300   if (dialog_write_item(di, WS_CHILD | WS_VISIBLE | SS_ENDELLIPSIS | ES_CENTER | SS_SUNKEN,
13171301         x, y, cx, cy, NULL, DLGITEM_EDIT, NULL))
r2724r2725
13361320//   win_dialog_add_seqselect
13371321//============================================================
13381322
1339int win_dialog_add_portselect(dialog_box *dialog, input_port_entry *port, const RECT *r)
1323int win_dialog_add_portselect(dialog_box *dialog, input_field_config *field, const RECT *r)
13401324{
13411325   dialog_box *di = dialog;
13421326   short x;
r2724r2725
13531337   int is_analog[3];
13541338   int len;
13551339
1356   port_name = input_port_name(port);
1340   port_name = input_field_name(field);
13571341   assert(port_name);
13581342
1359   if (port_type_is_analog(port->type))
1343   if (field->type >= __ipt_analog_start && field->type <= __ipt_analog_end)
13601344   {
13611345      seq_types[seq_count] = SEQ_TYPE_STANDARD;
13621346      port_suffix[seq_count] = " Analog";
r2724r2725
14051389         x += dialog->layout->label_width + DIM_HORIZONTAL_SPACING;
14061390
14071391         if (dialog_add_single_seqselect(di, x, y, DIM_EDIT_WIDTH, DIM_NORMAL_ROW_HEIGHT,
1408               port, is_analog[seq], seq_types[seq]))
1392               field, is_analog[seq], seq_types[seq]))
14091393            return 1;
14101394         y += DIM_VERTICAL_SPACING + DIM_NORMAL_ROW_HEIGHT;
14111395         x += DIM_EDIT_WIDTH + DIM_HORIZONTAL_SPACING;
r2724r2725
14271411         height   /= pixels_to_ydlgunits;
14281412
14291413         if (dialog_add_single_seqselect(di, x, y, width, height,
1430               port, is_analog[seq], seq_types[seq]))
1414               field, is_analog[seq], seq_types[seq]))
14311415            return 1;
14321416      }
14331417   }
src/mess/osd/windows/menu.c
r2724r2725
126126static void customize_input(running_machine *machine, HWND wnd, const char *title, artwork_cust_type cust_type, int player, int inputclass, const char *section)
127127{
128128   dialog_box *dlg;
129   input_port_entry *in;
129   const input_port_config *port;
130   const input_field_config *field;
130131   png_info png;
131132   struct inputform_customization customizations[128];
132133   RECT *pr;
r2724r2725
134135
135136   struct
136137   {
137      input_port_entry *in;
138      input_field_config *field;
138139      const RECT *pr;
139140   } portslots[256];
140141
r2724r2725
157158      win_dialog_add_separator(dlg);
158159   }
159160
160   in = machine->input_ports;
161   while(in->type != IPT_END)
161   for (port = machine->portconfig; port != NULL; port = port->next)
162162   {
163      this_inputclass = input_classify_port(in);
164      if (input_port_name(in) && (this_inputclass == inputclass))
163      for (field = port->fieldlist; field != NULL; field = field->next)
165164      {
166         /* most of the time, the player parameter is the player number
167          * but in the case of INPUT_CLASS_CATEGORIZED, it is the
168          * category */
169         if (inputclass == INPUT_CLASS_CATEGORIZED)
170            this_player = in->category;
171         else
172                this_player = input_player_number(in);
165         this_inputclass = input_classify_port(field);
166         if (input_field_name(field) && (this_inputclass == inputclass))
167         {
168            /* most of the time, the player parameter is the player number
169             * but in the case of INPUT_CLASS_CATEGORIZED, it is the
170             * category */
171            if (inputclass == INPUT_CLASS_CATEGORIZED)
172               this_player = field->category;
173            else
174               this_player = input_player_number(field);
173175
174         if (this_player == player)
175         {
176            /* check to see if the custom artwork for this configure dialog
177             * says anything about this input */
178            pr = NULL;
179            for (i = 0; customizations[i].ipt != IPT_END; i++)
176            if (this_player == player)
180177            {
181               if (in->type == customizations[i].ipt)
178               /* check to see if the custom artwork for this configure dialog
179                * says anything about this input */
180               pr = NULL;
181               for (i = 0; customizations[i].ipt != IPT_END; i++)
182182               {
183                  pr = (RECT *) alloca(sizeof(*pr));
184                  pr->left = customizations[i].x;
185                  pr->top = customizations[i].y;
186                  pr->right = pr->left + customizations[i].width;
187                  pr->bottom = pr->top + customizations[i].height;
188                  break;
183                  if (field->type == customizations[i].ipt)
184                  {
185                     pr = (RECT *) alloca(sizeof(*pr));
186                     pr->left = customizations[i].x;
187                     pr->top = customizations[i].y;
188                     pr->right = pr->left + customizations[i].width;
189                     pr->bottom = pr->top + customizations[i].height;
190                     break;
191                  }
189192               }
190            }
191193
192            /* store this InputPort/RECT combo in our list.  we do not
193             * necessarily want to add it yet because we the INI might
194             * want to reorder the tab order */
195            if (customizations[i].ipt == IPT_END)
196               i = portslot_count++;
197            if (i < (sizeof(portslots) / sizeof(portslots[0])))
198            {
199               portslots[i].in = in;
200               portslots[i].pr = pr;
194               /* store this InputPort/RECT combo in our list.  we do not
195                * necessarily want to add it yet because we the INI might
196                * want to reorder the tab order */
197               if (customizations[i].ipt == IPT_END)
198                  i = portslot_count++;
199               if (i < (sizeof(portslots) / sizeof(portslots[0])))
200               {
201                  portslots[i].field = (input_field_config *) field;
202                  portslots[i].pr = pr;
203               }
201204            }
202205         }
203206      }
204      in++;
205207   }
206208
207209   /* finally add the portselects to the dialog */
r2724r2725
209211      portslot_count = sizeof(portslots) / sizeof(portslots[0]);
210212   for (i = 0; i < portslot_count; i++)
211213   {
212      if (portslots[i].in)
214      if (portslots[i].field)
213215      {
214         if (win_dialog_add_portselect(dlg, portslots[i].in, portslots[i].pr))
216         if (win_dialog_add_portselect(dlg, portslots[i].field, portslots[i].pr))
215217            goto done;
216218      }
217219   }
r2724r2725
281283
282284static void storeval_inputport(void *param, int val)
283285{
284   input_port_entry *in = (input_port_entry *) param;
285   in->default_value = (UINT16) val;
286   input_field_config *field = (input_field_config *) param;
287   field->defvalue = (UINT16) val;
286288}
287289
288290
r2724r2725
291293//   customize_switches
292294//============================================================
293295
294static void customize_switches(running_machine *machine, HWND wnd, int title_string_num, UINT32 ipt_name, UINT32 ipt_setting)
296static void customize_switches(running_machine *machine, HWND wnd, int title_string_num, UINT32 ipt_name)
295297{
296298   dialog_box *dlg;
297   input_port_entry *in;
299   const input_port_config *port;
300   const input_field_config *field;
301   const input_setting_config *setting;
298302   const char *switch_name = NULL;
299303   UINT32 type;
300304
r2724r2725
302306   if (!dlg)
303307      goto done;
304308
305   for (in = machine->input_ports; in->type != IPT_END; in++)
309   for (port = machine->portconfig; port != NULL; port = port->next)
306310   {
307      type = in->type;
311      for (field = port->fieldlist; field != NULL; field = field->next)
312      {
313         type = field->type;
308314
309      if (type == ipt_name)
310      {
311         if (input_port_active(in))
315         if (type == ipt_name)
312316         {
313            switch_name = input_port_name(in);
314            if (win_dialog_add_combobox(dlg, switch_name, in->default_value, storeval_inputport, in))
317            switch_name = input_field_name(field);
318            if (win_dialog_add_combobox(dlg, switch_name, field->defvalue, storeval_inputport, (input_field_config *) field))
315319               goto done;
320
321            for (setting = field->settinglist; setting != NULL; setting = setting->next)
322            {
323               if (win_dialog_add_combobox_item(dlg, setting->name, setting->value))
324                  goto done;
325            }
316326         }
317         else
318         {
319            switch_name = NULL;
320         }
321327      }
322      else if (type == ipt_setting)
323      {
324         if (switch_name)
325         {
326            if (win_dialog_add_combobox_item(dlg, input_port_name(in), in->default_value))
327               goto done;
328         }
329      }
330328   }
331329
332330   if (win_dialog_add_standard_buttons(dlg))
r2724r2725
347345
348346static void customize_dipswitches(running_machine *machine, HWND wnd)
349347{
350   customize_switches(machine, wnd, UI_dipswitches, IPT_DIPSWITCH_NAME, IPT_DIPSWITCH_SETTING);
348   customize_switches(machine, wnd, UI_dipswitches, IPT_DIPSWITCH);
351349}
352350
353351
r2724r2725
358356
359357static void customize_configuration(running_machine *machine, HWND wnd)
360358{
361   customize_switches(machine, wnd, UI_configuration, IPT_CONFIG_NAME, IPT_CONFIG_SETTING);
359   customize_switches(machine, wnd, UI_configuration, IPT_CONFIG);
362360}
363361
364362
r2724r2725
367365//   customize_analogcontrols
368366//============================================================
369367
368enum
369{
370   ANALOG_ITEM_KEYSPEED,
371   ANALOG_ITEM_CENTERSPEED,
372   ANALOG_ITEM_REVERSE,
373   ANALOG_ITEM_SENSITIVITY
374};
375
376
377
378static void store_analogitem(void *param, int val, int selected_item)
379{
380   const input_field_config *field = (const input_field_config *) param;
381   input_field_user_settings settings;
382
383   input_field_get_user_settings(field, &settings);
384
385   switch(selected_item)
386   {
387      case ANALOG_ITEM_KEYSPEED:      settings.delta = val;      break;
388      case ANALOG_ITEM_CENTERSPEED:   settings.centerdelta = val;   break;
389      case ANALOG_ITEM_REVERSE:      settings.reverse = val;      break;
390      case ANALOG_ITEM_SENSITIVITY:   settings.sensitivity = val;   break;
391   }
392   input_field_set_user_settings(field, &settings);
393}
394
395
396
370397static void store_delta(void *param, int val)
371398{
372   ((input_port_entry *) param)->analog.delta = val;
399   store_analogitem(param, val, ANALOG_ITEM_KEYSPEED);
373400}
374401
375402
376403
377404static void store_centerdelta(void *param, int val)
378405{
379   ((input_port_entry *) param)->analog.centerdelta = val;
406   store_analogitem(param, val, ANALOG_ITEM_CENTERSPEED);
380407}
381408
382409
383410
384411static void store_reverse(void *param, int val)
385412{
386   ((input_port_entry *) param)->analog.reverse = val;
413   store_analogitem(param, val, ANALOG_ITEM_REVERSE);
387414}
388415
389416
390417
391418static void store_sensitivity(void *param, int val)
392419{
393   ((input_port_entry *) param)->analog.sensitivity = val;
420   store_analogitem(param, val, ANALOG_ITEM_SENSITIVITY);
394421}
395422
396423
397424
425static int port_type_is_analog(int type)
426{
427   return (type >= __ipt_analog_start && type <= __ipt_analog_end);
428}
429
430
431
398432static void customize_analogcontrols(running_machine *machine, HWND wnd)
399433{
400434   dialog_box *dlg;
401   input_port_entry *in;
435   const input_port_config *port;
436   const input_field_config *field;
437   input_field_user_settings settings;
402438   const char *name;
403439   char buf[255];
404440   static const struct dialog_layout layout = { 120, 52 };
r2724r2725
407443   if (!dlg)
408444      goto done;
409445
410   in = machine->input_ports;
411
412   while (in->type != IPT_END)
446   for (port = machine->portconfig; port != NULL; port = port->next)
413447   {
414      if (port_type_is_analog(in->type))
448      for (field = port->fieldlist; field != NULL; field = field->next)
415449      {
416         name = input_port_name(in);
450         if (port_type_is_analog(field->type))
451         {
452            input_field_get_user_settings(field, &settings);
453            name = input_field_name(field);
417454
418         _snprintf(buf, sizeof(buf) / sizeof(buf[0]),
419            "%s %s", name, ui_getstring(UI_keyjoyspeed));
420         if (win_dialog_add_adjuster(dlg, buf, in->analog.delta, 1, 255, FALSE, store_delta, in))
421            goto done;
455            _snprintf(buf, sizeof(buf) / sizeof(buf[0]),
456               "%s %s", name, ui_getstring(UI_keyjoyspeed));
457            if (win_dialog_add_adjuster(dlg, buf, settings.delta, 1, 255, FALSE, store_delta, (input_field_config *) field))
458               goto done;
422459
423         _snprintf(buf, sizeof(buf) / sizeof(buf[0]),
424            "%s %s", name, ui_getstring(UI_centerspeed));
425         if (win_dialog_add_adjuster(dlg, buf, in->analog.centerdelta, 1, 255, FALSE, store_centerdelta, in))
426            goto done;
460            _snprintf(buf, sizeof(buf) / sizeof(buf[0]),
461               "%s %s", name, ui_getstring(UI_centerspeed));
462            if (win_dialog_add_adjuster(dlg, buf, settings.centerdelta, 1, 255, FALSE, store_centerdelta, (input_field_config *) field))
463               goto done;
427464
428         _snprintf(buf, sizeof(buf) / sizeof(buf[0]),
429            "%s %s", name, ui_getstring(UI_reverse));
430         if (win_dialog_add_combobox(dlg, buf, in->analog.reverse ? 1 : 0, store_reverse, in))
431            goto done;
432         if (win_dialog_add_combobox_item(dlg, ui_getstring(UI_off), 0))
433            goto done;
434         if (win_dialog_add_combobox_item(dlg, ui_getstring(UI_on), 1))
435            goto done;
465            _snprintf(buf, sizeof(buf) / sizeof(buf[0]),
466               "%s %s", name, ui_getstring(UI_reverse));
467            if (win_dialog_add_combobox(dlg, buf, settings.reverse ? 1 : 0, store_reverse, (input_field_config *) field))
468               goto done;
469            if (win_dialog_add_combobox_item(dlg, ui_getstring(UI_off), 0))
470               goto done;
471            if (win_dialog_add_combobox_item(dlg, ui_getstring(UI_on), 1))
472               goto done;
436473
437         _snprintf(buf, sizeof(buf) / sizeof(buf[0]),
438            "%s %s", name, ui_getstring(UI_sensitivity));
439         if (win_dialog_add_adjuster(dlg, buf, in->analog.sensitivity, 1, 255, TRUE, store_sensitivity, in))
440            goto done;
474            _snprintf(buf, sizeof(buf) / sizeof(buf[0]),
475               "%s %s", name, ui_getstring(UI_sensitivity));
476            if (win_dialog_add_adjuster(dlg, buf, settings.sensitivity, 1, 255, TRUE, store_sensitivity, (input_field_config *) field))
477               goto done;
478         }
441479      }
442      in++;
443480   }
444481
445482   if (win_dialog_add_standard_buttons(dlg))
r2724r2725
10881125   HMENU joystick_menu;
10891126   int i, j;
10901127   HMENU submenu = NULL;
1091   const input_port_entry *in;
1092   const input_port_entry *in_setting;
1128   const input_port_config *port;
1129   const input_field_config *field;
1130   const input_setting_config *setting;
10931131   char buf[256];
10941132   int child_count = 0;
10951133
1096   in = machine->input_ports;
10971134   use_input_categories = 0;
1098   while(in->type != IPT_END)
1135   for (port = machine->portconfig; port != NULL; port = port->next)
10991136   {
1100      if (in->type == IPT_CATEGORY_NAME)
1137      for (field = port->fieldlist; field != NULL; field = field->next)
11011138      {
1102         use_input_categories = 1;
1103         break;
1139         if (field->type == IPT_CATEGORY)
1140         {
1141            use_input_categories = 1;
1142            break;
1143         }
11041144      }
1105      in++;
11061145   }
11071146
11081147   joystick_menu = find_sub_menu(menu_bar, "&Options\0&Joysticks\0", TRUE);
r2724r2725
11121151   if (use_input_categories)
11131152   {
11141153      // using input categories
1115      for (i = 0; machine->input_ports[i].type != IPT_END; i++)
1154      i = 0;
1155      for (port = machine->portconfig; port != NULL; port = port->next)
11161156      {
1117         in = &machine->input_ports[i];
1118         if ((in->type) == IPT_CATEGORY_NAME)
1157         for (field = port->fieldlist; field != NULL; field = field->next)
11191158         {
1120            submenu = CreateMenu();
1121            if (!submenu)
1122               return;
1159            if (field->type == IPT_CATEGORY)
1160            {
1161               submenu = CreateMenu();
1162               if (!submenu)
1163                  return;
11231164
1124            // append all of the category settings
1125            for (j = i + 1; (machine->input_ports[j].type) == IPT_CATEGORY_SETTING; j++)
1126            {
1127               in_setting = &machine->input_ports[j];
1128               append_menu_utf8(submenu, MF_STRING, ID_INPUT_0 + j, in_setting->name);
1165               // append all of the category settings
1166               j = 0;
1167               for (setting = field->settinglist; setting != NULL; setting = setting->next)
1168               {
1169                  append_menu_utf8(submenu, MF_STRING, ID_INPUT_0 + j++, setting->name);
1170               }
1171
1172               // tack on the final items and the menu item
1173               AppendMenu(submenu, MF_SEPARATOR, 0, NULL);
1174               AppendMenu(submenu, MF_STRING, ID_INPUT_0 + i, TEXT("&Configure..."));
1175               append_menu_utf8(joystick_menu, MF_STRING | MF_POPUP, (UINT_PTR) submenu, field->name);
1176               child_count++;
11291177            }
1130
1131            // tack on the final items and the menu item
1132            AppendMenu(submenu, MF_SEPARATOR, 0, NULL);
1133            AppendMenu(submenu, MF_STRING, ID_INPUT_0 + i, TEXT("&Configure..."));
1134            append_menu_utf8(joystick_menu, MF_STRING | MF_POPUP, (UINT_PTR) submenu, in->name);
1135            child_count++;
1178            i++;
11361179         }
11371180      }
11381181   }
r2724r2725
12101253   UINT flags_for_writing;
12111254   const device_config *img;
12121255   int has_config, has_dipswitch, has_keyboard, has_analog, has_misc;
1213   const input_port_entry *in;
1214   UINT16 in_cat_value = 0;
1256   const input_port_config *port;
1257   const input_field_config *field;
1258   const input_setting_config *setting;
12151259   int frameskip;
12161260   int orientation;
12171261   int speed;
r2724r2725
12421286   has_misc      = input_has_input_class(machine, INPUT_CLASS_MISC);
12431287
12441288   has_analog = 0;
1245   for (in = machine->input_ports; in->type != IPT_END; in++)
1289   for (port = machine->portconfig; port != NULL; port = port->next)
12461290   {
1247      if (port_type_is_analog(in->type))
1291      for (field = port->fieldlist; field != NULL; field = field->next)
12481292      {
1249         has_analog = 1;
1250         break;
1293         if (port_type_is_analog(field->type))
1294         {
1295            has_analog = 1;
1296            break;
1297         }
12511298      }
12521299   }
12531300
r2724r2725
12941341   // if we are using categorized input, we need to properly checkmark the categories
12951342   if (use_input_categories)
12961343   {
1297      for (i = 0; machine->input_ports[i].type != IPT_END; i++)
1344      for (port = machine->portconfig; port != NULL; port = port->next)
12981345      {
1299         in = &machine->input_ports[i];
1300         switch(in->type) {
1301         case IPT_CATEGORY_NAME:
1302            in_cat_value = in->default_value;
1303            break;
1304
1305         case IPT_CATEGORY_SETTING:
1306            set_command_state(menu_bar, ID_INPUT_0 + i, (in->default_value == in_cat_value) ? MFS_CHECKED : MFS_ENABLED);
1307            break;
1346         for (field = port->fieldlist; field != NULL; field = field->next)
1347         {
1348            if (field->type == IPT_CATEGORY)
1349            {
1350               i = 0;
1351               for (setting = field->settinglist; setting != NULL; setting = setting->next)
1352                  set_command_state(menu_bar, ID_INPUT_0 + i++, (setting->value == field->defvalue) ? MFS_CHECKED : MFS_ENABLED);
1353            }
13081354         }
13091355      }
13101356   }
r2724r2725
16371683   int dev_command, i;
16381684   const device_config *img;
16391685   int port_count;
1640   UINT16 setting, category;
1641   input_port_entry *in;
1686   UINT16 category;
16421687   const char *section;
1688   const input_port_config *port;
1689   const input_field_config *field;
1690   const input_setting_config *setting;
16431691   LONG_PTR ptr = GetWindowLongPtr(wnd, GWLP_USERDATA);
16441692   win_window_info *window = (win_window_info *)ptr;
16451693
r2724r2725
18051853         // quickly come up with a port count, so we can upper bound commands
18061854         // near ID_INPUT_0
18071855         port_count = 0;
1808         while(machine->input_ports[port_count].type != IPT_END)
1809            port_count++;
1856         field = NULL;
1857         for (port = machine->portconfig; port != NULL; port = port->next)
1858         {
1859            for (field = port->fieldlist; field != NULL; field = field->next)
1860               port_count++;
1861         }
18101862
18111863         if ((command >= ID_FRAMESKIP_0) && (command < ID_FRAMESKIP_0 + frameskip_level_count()))
18121864         {
r2724r2725
18321884         else if ((command >= ID_INPUT_0) && (command < ID_INPUT_0 + port_count))
18331885         {
18341886            // customize categorized input
1835            in = &machine->input_ports[command - ID_INPUT_0];
1836            switch(in->type) {
1837            case IPT_CATEGORY_NAME:
1838               // customize the input type
1839               category = 0;
1840               section = NULL;
1841               for (i = 1; (in[i].type) == IPT_CATEGORY_SETTING; i++)
1842               {
1843                  if (in[i].default_value == in[0].default_value)
1887            i = command - ID_INPUT_0;
1888            for (port = machine->portconfig; (i > 0) && (port != NULL); port = port->next)
1889            {
1890               for (field = port->fieldlist; (i > 0) && (field != NULL); field = field->next)
1891                  ;
1892            }
1893
1894            switch(field->type)
1895            {
1896               case IPT_CATEGORY:
1897                  // customize the input type
1898                  category = 0;
1899                  section = NULL;
1900                  for (setting = field->settinglist; setting != NULL; setting = setting->next)
18441901                  {
1845                     category = in[i].category;
1846                     section = in[i].name;
1902                     if (field->defvalue == setting->value)
1903                     {
1904                        //category = in[i].category;
1905                        //section = in[i].name;
1906                     }
18471907                  }
1848               }
1849               customize_categorizedinput(machine, wnd, section, category);
1850               break;
1908                  customize_categorizedinput(machine, wnd, section, category);
1909                  break;
18511910
1852            case IPT_CATEGORY_SETTING:
1853               // change the input type for this category
1854               setting = in->default_value;
1855               while((in->type) != IPT_CATEGORY_NAME)
1856                  in--;
1857               in->default_value = setting;
1858               break;
1911//               case IPT_CATEGORY_SETTING:
1912//                  // change the input type for this category
1913//                  setting = in->default_value;
1914//                  while((in->type) != IPT_CATEGORY_NAME)
1915//                     in--;
1916//                  in->default_value = setting;
1917//                  break;
18591918
1860            default:
1861               // should never happen
1862               handled = 0;
1863               break;
1919               default:
1920                  // should never happen
1921                  handled = 0;
1922                  break;
18641923            }
18651924         }
18661925         else
src/mess/osd/windows/dialog.h
r2724r2725
5757   int min_value, int max_value,
5858   dialog_itemstoreval storeval, void *storeval_param);
5959
60int win_dialog_add_portselect(dialog_box *dialog, input_port_entry *port, const RECT *r);
60int win_dialog_add_portselect(dialog_box *dialog, input_field_config *field, const RECT *r);
6161
6262int win_dialog_add_standard_buttons(dialog_box *dialog);
6363int win_dialog_add_image(dialog_box *dialog, const png_info *png);
src/mess/osd/winui/msuiutil.c
r2724r2725
1414
1515BOOL DriverUsesMouse(int driver_index)
1616{
17   // NPW 23-May-2008 - Temporarily disabling
18   BOOL retval = FALSE;
19#if 0
1720   const input_port_entry *input_ports;
18   BOOL retval = FALSE;
1921
2022   if (drivers[driver_index]->ipt)
2123   {
r2724r2725
3436
3537      end_resource_tracking();
3638   }
37
39#endif
3840   return retval;
3941}
4042
src/mess/machine/dgn_beta.c
r2724r2725
105105static READ8_HANDLER(d_pia0_pb_r);
106106static WRITE8_HANDLER(d_pia0_pb_w);
107107static WRITE8_HANDLER(d_pia0_cb2_w);
108static void d_pia0_irq_a(int state);
109static void d_pia0_irq_b(int state);
108static void d_pia0_irq_a(running_machine *machine, int state);
109static void d_pia0_irq_b(running_machine *machine, int state);
110110static READ8_HANDLER(d_pia1_pa_r);
111111static WRITE8_HANDLER(d_pia1_pa_w);
112112static READ8_HANDLER(d_pia1_pb_r);
113113static WRITE8_HANDLER(d_pia1_pb_w);
114static void d_pia1_irq_a(int state);
115static void d_pia1_irq_b(int state);
114static void d_pia1_irq_a(running_machine *machine, int state);
115static void d_pia1_irq_b(running_machine *machine, int state);
116116static READ8_HANDLER(d_pia2_pa_r);
117117static WRITE8_HANDLER(d_pia2_pa_w);
118118static READ8_HANDLER(d_pia2_pb_r);
119119static WRITE8_HANDLER(d_pia2_pb_w);
120static void d_pia2_irq_a(int state);
121static void d_pia2_irq_b(int state);
120static void d_pia2_irq_a(running_machine *machine, int state);
121static void d_pia2_irq_b(running_machine *machine, int state);
122122
123123static void cpu0_recalc_irq(running_machine *machine, int state);
124124static void cpu0_recalc_firq(running_machine *machine, int state);
r2724r2725
647647}
648648
649649
650static void d_pia0_irq_a(int state)
650static void d_pia0_irq_a(running_machine *machine, int state)
651651{
652   cpu0_recalc_irq(Machine, state);
652   cpu0_recalc_irq(machine, state);
653653}
654654
655static void d_pia0_irq_b(int state)
655static void d_pia0_irq_b(running_machine *machine, int state)
656656{
657   cpu0_recalc_firq(Machine, state);
657   cpu0_recalc_firq(machine, state);
658658}
659659
660660/* PIA #1 at $FC24-$FC27 I63
r2724r2725
739739   }
740740}
741741
742static void d_pia1_irq_a(int state)
742static void d_pia1_irq_a(running_machine *machine, int state)
743743{
744   cpu0_recalc_irq(Machine, state);
744   cpu0_recalc_irq(machine, state);
745745}
746746
747static void d_pia1_irq_b(int state)
747static void d_pia1_irq_b(running_machine *machine, int state)
748748{
749   cpu0_recalc_irq(Machine, state);
749   cpu0_recalc_irq(machine, state);
750750}
751751
752752/* PIA #2 at FCC0-FCC3 I28
r2724r2725
842842   vid_set_gctrl(data);
843843}
844844
845static void d_pia2_irq_a(int state)
845static void d_pia2_irq_a(running_machine *machine, int state)
846846{
847847   logerror("PIA2 IRQ1 state=%02X\n",state);
848   cpu0_recalc_irq(Machine, state);
848   cpu0_recalc_irq(machine, state);
849849}
850850
851static void d_pia2_irq_b(int state)
851static void d_pia2_irq_b(running_machine *machine, int state)
852852{
853853   logerror("PIA2 IRQ2 state=%02X\n",state);
854   cpu0_recalc_irq(Machine, state);
854   cpu0_recalc_irq(machine, state);
855855}
856856
857857/************************************ Recalculate CPU inturrupts ****************************/
src/mess/machine/hp48.c
r2724r2725
173173
174174/* priority on the bus
175175   hdw, ram, ce2, ce1, nce3, rom */
176void hp48_mem_reset(void)
176void hp48_mem_reset(running_machine *machine)
177177{
178178   int i;
179179   hp48s.state=0;
r2724r2725
184184   hp48_config();
185185}
186186
187void hp48_mem_config(int v)
187void hp48_mem_config(running_machine *machine, int v)
188188{
189189   logerror("hp48_mem_config called\n");
190190   if (hp48s.mem[HDW].adr==-1) {
r2724r2725
228228   }
229229}
230230
231void hp48_mem_unconfig(int v)
231void hp48_mem_unconfig(running_machine *machine, int v)
232232{
233233   int i;
234234   for (i=0; i+1< sizeof(hp48s.mem)/sizeof(hp48s.mem[0]); i++) {
r2724r2725
250250#define CE2_ID_ADR 0xf8
251251#define NCE3_ID_SIZE 1
252252#define NCE3_ID_ADR 0xf2
253int hp48_mem_id(void)
253int hp48_mem_id(running_machine *machine)
254254{
255255   if (hp48s.mem[HDW].adr==-1) {
256256      return (hp48s.mem[HDW].adr&~0x3f)|HDW_ID_ADR;
r2724r2725
272272   {0}
273273};
274274
275void hp48_crc(int adr, int data)
275void hp48_crc(running_machine *machine, int adr, int data)
276276{
277277   if ((hp48s.mem[HDW].adr==-1)
278278      ||(adr<(hp48s.mem[HDW].adr&~0x3f))
r2724r2725
424424   }
425425}
426426
427void hp48_out(int v)
427void hp48_out(running_machine *machine, int v)
428428{
429429   out=v;
430430}
431431
432int hp48_in(void)
432int hp48_in(running_machine *machine)
433433{
434434   int data=0;
435435#if 1
r2724r2725
556556
557557MACHINE_RESET( hp48 )
558558{
559   hp48_mem_reset();
559   hp48_mem_reset(machine);
560560}
src/mess/machine/apple3.c
r2724r2725
485485static WRITE8_HANDLER(apple3_via_1_out_a) { apple3_via_out(machine, &via_1_a, data); }
486486static WRITE8_HANDLER(apple3_via_1_out_b) { apple3_via_out(machine, &via_1_b, data); }
487487
488static void apple2_via_1_irq_func(int state)
488static void apple2_via_1_irq_func(running_machine *machine, int state)
489489{
490490   if (!via_1_irq && state)
491      cpunum_set_input_line(Machine, 0, M6502_IRQ_LINE, PULSE_LINE);
491      cpunum_set_input_line(machine, 0, M6502_IRQ_LINE, PULSE_LINE);
492492   via_1_irq = state;
493493}
494494
src/mess/machine/cbmb.c
r2724r2725
188188   cbm_ieee_data_w(0, data);
189189}
190190
191static void cbmb_tpi6525_0_irq2_level( int level ) {
192   tpi6525_0_irq2_level( Machine, level );
191static void cbmb_tpi6525_0_irq2_level( running_machine *machine, int level )
192{
193   tpi6525_0_irq2_level( machine, level );
193194}
194195
195196static const cia6526_interface cbmb_cia =
src/mess/machine/mbee.c
r2724r2725
3030static UINT8 fdc_head = 0;
3131static UINT8 fdc_den = 0;
3232static UINT8 fdc_status = 0;
33static void pio_interrupt(int state);
33static void pio_interrupt(running_machine *machine, int state);
3434static void mbee_fdc_callback(running_machine *machine, wd17xx_state_t event, void *param);
3535
3636UINT8 *mbee_workram;
r2724r2725
4646   0            /* portB ready active callback (do not support yet)*/
4747};
4848
49static void pio_interrupt(int state)
49static void pio_interrupt(running_machine *machine, int state)
5050{
51   cpunum_set_input_line(Machine, 0, 0, state ? ASSERT_LINE : CLEAR_LINE);
51   cpunum_set_input_line(machine, 0, 0, state ? ASSERT_LINE : CLEAR_LINE);
5252}
5353
5454/*
src/mess/machine/coco.c
r2724r2725
130130static WRITE8_HANDLER ( d_pia0_cb2_w);
131131static WRITE8_HANDLER ( d_pia1_ca2_w);
132132static WRITE8_HANDLER ( d_pia0_ca2_w);
133static void d_pia0_irq_a(int state);
134static void d_pia0_irq_b(int state);
135static void d_pia1_firq_a(int state);
136static void d_pia1_firq_b(int state);
133static void d_pia0_irq_a(running_machine *machine, int state);
134static void d_pia0_irq_b(running_machine *machine, int state);
135static void d_pia1_firq_a(running_machine *machine, int state);
136static void d_pia1_firq_b(running_machine *machine, int state);
137137static void d_sam_set_pageonemode(int val);
138138static void d_sam_set_mpurate(int val);
139139static void d_sam_set_memorysize(int val);
r2724r2725
154154static UINT8 coco3_interupt_line;
155155static UINT8 gime_firq, gime_irq;
156156
157static void coco3_pia0_irq_a(int state);
158static void coco3_pia0_irq_b(int state);
159static void coco3_pia1_firq_a(int state);
160static void coco3_pia1_firq_b(int state);
157static void coco3_pia0_irq_a(running_machine *machine, int state);
158static void coco3_pia0_irq_b(running_machine *machine, int state);
159static void coco3_pia1_firq_a(running_machine *machine, int state);
160static void coco3_pia1_firq_b(running_machine *machine, int state);
161161static void coco3_sam_set_maptype(int val);
162162static const UINT8 *coco3_sam_get_rambase(void);
163163
r2724r2725
172172
173173/* Dragon Alpha specific */
174174static WRITE8_HANDLER ( dgnalpha_pia2_pa_w );
175static void d_pia2_firq_a(int state);
176static void d_pia2_firq_b(int state);
175static void d_pia2_firq_a(running_machine *machine, int state);
176static void d_pia2_firq_b(running_machine *machine, int state);
177177static int dgnalpha_just_reset;      /* Reset flag used to ignore first NMI after reset */
178178
179179/* Dragon Plus specific */
r2724r2725
813813      d_recalc_firq(machine);
814814}
815815
816static void d_pia0_irq_a(int state)
816static void d_pia0_irq_a(running_machine *machine, int state)
817817{
818   d_recalc_irq(Machine);
818   d_recalc_irq(machine);
819819}
820820
821static void d_pia0_irq_b(int state)
821static void d_pia0_irq_b(running_machine *machine, int state)
822822{
823   d_recalc_irq(Machine);
823   d_recalc_irq(machine);
824824}
825825
826static void d_pia1_firq_a(int state)
826static void d_pia1_firq_a(running_machine *machine, int state)
827827{
828   d_recalc_firq(Machine);
828   d_recalc_firq(machine);
829829}
830830
831static void d_pia1_firq_b(int state)
831static void d_pia1_firq_b(running_machine *machine, int state)
832832{
833   d_recalc_firq(Machine);
833   d_recalc_firq(machine);
834834}
835835
836836/* Dragon Alpha second PIA IRQ lines also cause FIRQ */
837static void d_pia2_firq_a(int state)
837static void d_pia2_firq_a(running_machine *machine, int state)
838838{
839   d_recalc_firq(Machine);
839   d_recalc_firq(machine);
840840}
841841
842static void d_pia2_firq_b(int state)
842static void d_pia2_firq_b(running_machine *machine, int state)
843843{
844   d_recalc_firq(Machine);
844   d_recalc_firq(machine);
845845}
846846
847static void coco3_pia0_irq_a(int state)
847static void coco3_pia0_irq_a(running_machine *machine, int state)
848848{
849   coco3_recalc_irq(Machine);
849   coco3_recalc_irq(machine);
850850}
851851
852static void coco3_pia0_irq_b(int state)
852static void coco3_pia0_irq_b(running_machine *machine, int state)
853853{
854   coco3_recalc_irq(Machine);
854   coco3_recalc_irq(machine);
855855}
856856
857static void coco3_pia1_firq_a(int state)
857static void coco3_pia1_firq_a(running_machine *machine, int state)
858858{
859   coco3_recalc_firq(Machine);
859   coco3_recalc_firq(machine);
860860}
861861
862static void coco3_pia1_firq_b(int state)
862static void coco3_pia1_firq_b(running_machine *machine, int state)
863863{
864   coco3_recalc_firq(Machine);
864   coco3_recalc_firq(machine);
865865}
866866
867867static void coco3_raise_interrupt(running_machine *machine, UINT8 mask, int state)
r2724r2725
14121412
14131413/* three functions that update the keyboard in varying ways */
14141414static WRITE8_HANDLER ( d_pia0_pb_w )               { (*update_keyboard)(machine); }
1415INPUT_CHANGED(coco_keyboard_changed)               { (*update_keyboard)(machine); }
1415INPUT_CHANGED(coco_keyboard_changed)               { (*update_keyboard)(field->port->machine); }
14161416static TIMER_CALLBACK(coco_update_keyboard_timerproc)   { (*update_keyboard)(machine); }
14171417
14181418static WRITE8_HANDLER ( d_pia0_pa_w )
r2724r2725
30813081
30823082INPUT_CHANGED( coco_joystick_mode_changed )
30833083{
3084   update_lightgun(machine);
3084   update_lightgun(field->port->machine);
30853085}
30863086
30873087static TIMER_CALLBACK( update_lightgun_timer_callback )
src/mess/machine/aim65.c
r2724r2725
3737******************************************************************************/
3838
3939
40static void aim65_via_irq_func(int state)
40static void aim65_via_irq_func(running_machine *machine, int state)
4141{
42   cpunum_set_input_line(Machine, 0, M6502_IRQ_LINE, state ? HOLD_LINE : CLEAR_LINE);
42   cpunum_set_input_line(machine, 0, M6502_IRQ_LINE, state ? HOLD_LINE : CLEAR_LINE);
4343}
4444
4545/* STEP/RUN
r2724r2725
155155}
156156
157157
158static void aim65_riot_irq(int state)
158static void aim65_riot_irq(running_machine *machine, int state)
159159{
160   cpunum_set_input_line(Machine, 0, M6502_IRQ_LINE, state ? HOLD_LINE : CLEAR_LINE);
160   cpunum_set_input_line(machine, 0, M6502_IRQ_LINE, state ? HOLD_LINE : CLEAR_LINE);
161161}
162162
163163
src/mess/machine/vc1541.c
r2724r2725
399399 * also ca1 (books says cb2)
400400 * irq to m6502 irq connected (or with second via irq)
401401 */
402static void vc1541_via0_irq (int level)
402static void vc1541_via0_irq (running_machine *machine, int level)
403403{
404404   vc1541->via0irq = level;
405405   DBG_LOG(2, "vc1541 via0 irq",("level %d %d\n",vc1541->via0irq,vc1541->via1irq));
406   cpunum_set_input_line (Machine, vc1541->cpunumber,
406   cpunum_set_input_line (machine, vc1541->cpunumber,
407407                 M6502_IRQ_LINE, vc1541->via1irq || vc1541->via0irq);
408408}
409409
410static READ8_HANDLER( vc1541_via0_read_portb )
410static READ8_HANDLER( vc1541_via0_read_portb )
411411{
412412   static int old=-1;
413413   int value = 0x7a;
r2724r2725
498498 *
499499 * irq to m6502 irq connected
500500 */
501static void vc1541_via1_irq (int level)
501static void vc1541_via1_irq (running_machine *machine, int level)
502502{
503503   vc1541->via1irq = level;
504504   DBG_LOG(2, "vc1541 via1 irq",("level %d %d\n",vc1541->via0irq,vc1541->via1irq));
505   cpunum_set_input_line (Machine, vc1541->cpunumber,
505   cpunum_set_input_line (machine, vc1541->cpunumber,
506506                 M6502_IRQ_LINE, vc1541->via1irq || vc1541->via0irq);
507507}
508508
509static READ8_HANDLER( vc1541_via1_read_porta )
509static READ8_HANDLER( vc1541_via1_read_porta )
510510{
511511   int data=vc1541->head.data[vc1541->d64.pos];
512512   DBG_LOG(2, "vc1541 drive",("port a read %.2x\n", data));
src/mess/machine/thomson.c
r2724r2725
114114
115115
116116
117static void thom_irq_0  ( int state )
117static void thom_irq_0  ( running_machine *machine, int state )
118118{
119   thom_set_irq  ( Machine, 0, state );
119   thom_set_irq  ( machine, 0, state );
120120}
121121
122static void thom_irq_1  ( int state )
122static void thom_irq_1  ( running_machine *machine, int state )
123123{
124   thom_set_irq  ( Machine, 1, state );
124   thom_set_irq  ( machine, 1, state );
125125}
126126
127static void thom_irq_3  ( int state )
127static void thom_irq_3  ( running_machine *machine, int state )
128128{
129   thom_set_irq  ( Machine, 3, state );
129   thom_set_irq  ( machine, 3, state );
130130}
131131
132static void thom_firq_1 ( int state )
132static void thom_firq_1 ( running_machine *machine, int state )
133133{
134   thom_set_firq ( Machine, 1, state );
134   thom_set_firq ( machine, 1, state );
135135}
136136
137static void thom_firq_2 ( int state )
137static void thom_firq_2 ( running_machine *machine, int state )
138138{
139   thom_set_firq ( Machine, 2, state );
139   thom_set_firq ( machine, 2, state );
140140}
141141
142142#ifdef CHARDEV
143static void thom_irq_4  ( int state )
143static void thom_irq_4  ( running_machine *machine, int state )
144144{
145   thom_set_irq  ( Machine, 4, state );
145   thom_set_irq  ( machine, 4, state );
146146}
147147#endif
148148
r2724r2725
23542354   if ( (to9_kbd_intr & 3) == 1 && (to9_kbd_status & ACIA_6850_TDRE) )
23552355      to9_kbd_status |= ACIA_6850_irq; /* ready to transmit interrupt */
23562356
2357   thom_irq_3( to9_kbd_status & ACIA_6850_irq );
2357   thom_irq_3( Machine, to9_kbd_status & ACIA_6850_irq );
23582358}
23592359
23602360
r2724r2725
35053505   case 1: /* ram register / lightpen register 2 */
35063506      if ( to7_lightpen )
35073507      {
3508         thom_firq_2( 0 );
3508         thom_firq_2( machine, 0 );
35093509         to8_lightpen_intr = 0;
35103510         res = count & 0xff;
35113511      }
r2724r2725
37633763   if ( ! to7_lightpen )
37643764      return;
37653765
3766   thom_firq_2( 1 );
3766   thom_firq_2( Machine, 1 );
37673767   to7_lightpen_step = step;
37683768   to8_lightpen_intr = 1;
37693769}
r2724r2725
43884388   case 1: /* ram register / lightpen register 2 */
43894389      if ( to7_lightpen )
43904390      {
4391         thom_firq_2( 0 );
4391         thom_firq_2( machine, 0 );
43924392         to8_lightpen_intr = 0;
43934393         res =  count & 0xff;
43944394      }
src/mess/machine/mc6846.c
r2724r2725
1919**********************************************************************/
2020
2121#include "driver.h"
22#include "deprecat.h"
2223#include "mc6846.h"
2324
2425#define VERBOSE 0
r2724r2725
9495
9596
9697
97INLINE void mc6846_update_irq( void )
98INLINE void mc6846_update_irq( running_machine *machine )
9899{
99100   static int old_cif;
100101   int cif = 0;
r2724r2725
114115   {
115116      mc6846.csr |= 0x80;
116117      if ( mc6846.iface->irq_func )
117         mc6846.iface->irq_func( 1 );
118         mc6846.iface->irq_func( machine, 1 );
118119   }
119120   else
120121   {
121122      mc6846.csr &= ~0x80;
122123      if ( mc6846.iface->irq_func )
123         mc6846.iface->irq_func( 0 );
124         mc6846.iface->irq_func( machine, 0 );
124125   }
125126}
126127
r2724r2725
179180
180181   mc6846.csr &= ~1;
181182   mc6846_update_cto(machine);
182   mc6846_update_irq();
183   mc6846_update_irq(machine);
183184}
184185
185186
r2724r2725
224225
225226   mc6846.csr |= 1;
226227   mc6846_update_cto(machine);
227   mc6846_update_irq();
228   mc6846_update_irq(machine);
228229}
229230
230231
r2724r2725
275276            mc6846.csr &= ~2;
276277         if ( mc6846.csr2_to_be_cleared )
277278            mc6846.csr &= ~4;
278         mc6846_update_irq();
279         mc6846_update_irq(machine);
279280         mc6846.csr1_to_be_cleared = 0;
280281         mc6846.csr2_to_be_cleared = 0;
281282      }
r2724r2725
290291      if ( mc6846.csr0_to_be_cleared )
291292      {
292293         mc6846.csr &= ~1;
293         mc6846_update_irq();
294         mc6846_update_irq(machine);
294295      }
295296      mc6846.csr0_to_be_cleared = 0;
296297      return mc6846_counter() >> 8;
r2724r2725
300301      if ( mc6846.csr0_to_be_cleared )
301302      {
302303         mc6846.csr &= ~1;
303         mc6846_update_irq();
304         mc6846_update_irq(machine);
304305      }
305306      mc6846.csr0_to_be_cleared = 0;
306307      return mc6846_counter() & 0xff;
r2724r2725
345346      mc6846.pdr = 0;
346347      mc6846.ddr = 0;
347348      mc6846.csr &= ~6;
348      mc6846_update_irq();
349      mc6846_update_irq(machine);
349350   }
350351   if ( data & 4 )
351352      logerror( "$%04x mc6846 CP1 latching not implemented\n", activecpu_get_previouspc() );
r2724r2725
391392         }
392393         mc6846.csr1_to_be_cleared = 0;
393394         mc6846.csr2_to_be_cleared = 0;
394         mc6846_update_irq();
395         mc6846_update_irq(machine);
395396      }
396397      break;
397398
r2724r2725
427428         if ( ! mc6846.timer_started )
428429            mc6846_timer_launch(machine);
429430      }
430      mc6846_update_irq();
431      mc6846_update_irq(machine);
431432   }
432433   break;
433434
r2724r2725
443444         /* timer initialization */
444445         mc6846.preset = mc6846.latch;
445446         mc6846.csr &= ~1;
446         mc6846_update_irq();
447         mc6846_update_irq(machine);
447448         mc6846.cto = 0;
448449         mc6846_update_cto(machine);
449450         /* launch only if started */
r2724r2725
473474   if (( data &&  (mc6846.pcr & 2)) || (!data && !(mc6846.pcr & 2)))
474475   {
475476      mc6846.csr |= 2;
476      mc6846_update_irq();
477      mc6846_update_irq(Machine);
477478   }
478479}
479480
r2724r2725
489490      if (( data &&  (mc6846.pcr & 0x10)) || (!data && !(mc6846.pcr & 0x10)))
490491      {
491492         mc6846.csr |= 4;
492         mc6846_update_irq();
493         mc6846_update_irq(Machine);
493494      }
494495   }
495496}
src/mess/machine/mc6846.h
r2724r2725
2727  write8_machine_func out_cto_func; /* 1-bit output */
2828
2929  /* timer interrupt */
30  void ( * irq_func ) ( int state );
30  void ( * irq_func ) ( running_machine *machine, int state );
3131
3232  /* CPU identifier (defines the clock rate) */
3333  int cpunum;
src/mess/machine/ay3600.c
r2724r2725
278278  Helper Functions
279279***************************************************************************/
280280
281INLINE int a2_has_keypad(void)
281INLINE int a2_has_keypad(running_machine *machine)
282282{
283   return port_tag_to_index("keypad_1") != -1;
283   return input_port_by_tag(machine->portconfig, "keypad_1") != NULL;
284284}
285285
286INLINE int a2_has_reset_dip(void)
286INLINE int a2_has_reset_dip(running_machine *machine)
287287{
288   return port_tag_to_index("reset_dip") != -1;
288   return input_port_by_tag(machine->portconfig, "reset_dip") != NULL;
289289}
290290
291INLINE int a2_has_repeat(void)
291INLINE int a2_has_repeat(running_machine *machine)
292292{
293   return port_tag_to_index("keyb_repeat") != -1;
293   return input_port_by_tag(machine->portconfig, "keyb_repeat") != NULL;
294294}
295295
296INLINE int a2_has_capslock(void)
296INLINE int a2_has_capslock(running_machine *machine)
297297{
298   return !a2_has_repeat(); /* BUG: Doesn't work with Ace */
298   return !a2_has_repeat(machine); /* BUG: Doesn't work with Ace */
299299}
300300
301301INLINE int a2_no_ctrl_reset(running_machine *machine)
302302{
303   return ((a2_has_repeat() && !a2_has_reset_dip()) ||
304         (a2_has_reset_dip() && !input_port_read(machine, "reset_dip")));
303   return ((a2_has_repeat(machine) && !a2_has_reset_dip(machine)) ||
304         (a2_has_reset_dip(machine) && !input_port_read(machine, "reset_dip")));
305305}
306306
307307
r2724r2725
361361   /* check for these special cases because they affect the emulated key codes */
362362
363363   /* only repeat keys on a 2/2+ if special REPT key is pressed */
364   if (a2_has_repeat())
364   if (a2_has_repeat(machine))
365365      time_until_repeat = input_port_read(machine, "keyb_repeat") & 0x01 ? 0 : ~0;
366366
367367   /* check caps lock and set LED here */
r2724r2725
440440   }
441441
442442   /* run through real keys and see what's being pressed */
443   num_ports = a2_has_keypad() ? 9 : 7;
443   num_ports = a2_has_keypad(machine) ? 9 : 7;
444444
445445   keymodreg &= ~A2_KEYMOD_KEYPAD;
446446
r2724r2725
449449      data = input_port_read_indexed(machine, AY3600_KEYS_BASEPORT + port);
450450      for (bit = 0; bit < 8; bit++)
451451      {
452         if (a2_has_capslock()) {
452         if (a2_has_capslock(machine)) {
453453            curkey = ay3600_key_remap_2e[caps_lock][port*8+bit][switchkey];
454454            curkey_unmodified = ay3600_key_remap_2e[caps_lock][port*8+bit][0];
455455         } else {
src/mess/machine/pet.c
r2724r2725
107107   cbm_ieee_eoi_w(0, data);
108108}
109109
110static void pet_irq (int level)
110static void pet_irq (running_machine *machine, int level)
111111{
112112   static int old_level = 0;
113113
r2724r2725
115115   {
116116      DBG_LOG (3, "mos6502", ("irq %s\n", level ? "start" : "end"));
117117      if (superpet)
118         cpunum_set_input_line(Machine, 1, M6809_IRQ_LINE, level);
119      cpunum_set_input_line(Machine, 0, M6502_IRQ_LINE, level);
118         cpunum_set_input_line(machine, 1, M6809_IRQ_LINE, level);
119      cpunum_set_input_line(machine, 0, M6502_IRQ_LINE, level);
120120      old_level = level;
121121   }
122122}
src/mess/machine/oric.c
r2724r2725
406406}
407407
408408
409static void   oric_via_irq_func(int state)
409static void   oric_via_irq_func(running_machine *machine, int state)
410410{
411411   oric_irqs &= ~(1<<0);
412412
r2724r2725
420420      oric_irqs |=(1<<0);
421421   }
422422
423   oric_refresh_ints(Machine);
423   oric_refresh_ints(machine);
424424}
425425
426426
r2724r2725
14371437}
14381438
14391439
1440static void   telestrat_via2_irq_func(int state)
1440static void   telestrat_via2_irq_func(running_machine *machine, int state)
14411441{
14421442    oric_irqs &=~(1<<2);
14431443
r2724r2725
14481448        oric_irqs |=(1<<2);
14491449   }
14501450
1451    oric_refresh_ints(Machine);
1451    oric_refresh_ints(machine);
14521452}
14531453static const struct via6522_interface telestrat_via2_interface=
14541454{
src/mess/machine/amigakbd.c
r2724r2725
9191      /* if the buffer was empty and we have new data, start a timer to send the keystrokes */
9292      if ( key_buf_was_empty && ( key_buf_pos != key_cur_pos ) )
9393      {
94         timer_adjust_oneshot(kbd_timer, attotime_div(video_screen_get_frame_period(machine->primary_screen),4), 0);
94         timer_adjust_oneshot(kbd_timer, attotime_div(video_screen_get_frame_period(field->port->machine->primary_screen),4), 0);
9595      }
9696   }
9797}
src/mess/machine/microtan.c
r2724r2725
215215    LOG(("microtan_via_0_out_cb2 %d\n", data));
216216}
217217
218static void via_0_irq(int state)
218static void via_0_irq(running_machine *machine, int state)
219219{
220220    LOG(("microtan_via_0_irq %d\n", state));
221221    via_0_irq_line = state;
222    microtan_set_irq_line(Machine);
222    microtan_set_irq_line(machine);
223223}
224224
225225/**************************************************************
r2724r2725
287287    LOG(("microtan_via_1_out_cb2 %d\n", data));
288288}
289289
290static void via_1_irq(int state)
290static void via_1_irq(running_machine *machine, int state)
291291{
292292    LOG(("microtan_via_1_irq %d\n", state));
293293    via_1_irq_line = state;
294    microtan_set_irq_line(Machine);
294    microtan_set_irq_line(machine);
295295}
296296
297297/**************************************************************
src/mess/machine/99_peb.c
r2724r2725
101101*/
102102
103103#include "driver.h"
104#include "deprecat.h"
104105#include "99_peb.h"
105106
106107/* TRUE if we are using the snug sgcpu 99/4p 16-bit extensions */
r2724r2725
162163static int tmp_buffer;
163164
164165/* inta/intb handlers */
165static void (*inta_callback)(int state);
166static void (*intb_callback)(int state);
166static void (*inta_callback)(running_machine *machine, int state);
167static void (*intb_callback)(running_machine *machine, int state);
167168
168169
169170/*
r2724r2725
187188   in_intb_callback: callback called when the state of INTB changes (may be
188189      NULL)
189190*/
190void ti99_peb_reset(int in_has_16bit_peb, void (*in_inta_callback)(int state), void (*in_intb_callback)(int state))
191void ti99_peb_reset(int in_has_16bit_peb, void (*in_inta_callback)(running_machine *machine, int state), void (*in_intb_callback)(running_machine *machine, int state))
191192{
192193   has_16bit_peb = in_has_16bit_peb;
193194   inta_callback = in_inta_callback;
r2724r2725
286287   {
287288      ila |= 1 << bit;
288289      if (inta_callback)
289         (*inta_callback)(1);
290         (*inta_callback)(Machine, 1);
290291   }
291292   else
292293   {
293294      ila &= ~(1 << bit);
294295      if ((! ila) && inta_callback)
295         (*inta_callback)(0);
296         (*inta_callback)(Machine, 0);
296297   }
297298}
298299
r2724r2725
311312   {
312313      ilb |= 1 << bit;
313314      if (intb_callback)
314         (*intb_callback)(1);
315         (*intb_callback)(Machine, 1);
315316   }
316317   else
317318   {
318319      ilb &= ~(1 << bit);
319320      if ((! ilb) && intb_callback)
320         (*intb_callback)(0);
321         (*intb_callback)(Machine, 0);
321322   }
322323}
323324
src/mess/machine/osborne1.c
r2724r2725
236236   }
237237}
238238
239static void ieee_pia_irq_a_func(int state) {
239static void ieee_pia_irq_a_func(running_machine *machine, int state) {
240240   osborne1.pia_0_irq_state = state;
241   osborne1_update_irq_state(Machine);
241   osborne1_update_irq_state(machine);
242242}
243243
244244static const pia6821_interface osborne1_ieee_pia_config = {
r2724r2725
277277   //logerror("Video pia port b write: %02X\n", data );
278278}
279279
280static void video_pia_irq_a_func(int state) {
280static void video_pia_irq_a_func(running_machine *machine, int state) {
281281   osborne1.pia_1_irq_state = state;
282   osborne1_update_irq_state(Machine);
282   osborne1_update_irq_state(machine);
283283}
284284
285285static const pia6821_interface osborne1_video_pia_config = {
src/mess/machine/99_peb.h
r2724r2725
5454};
5555
5656void ti99_peb_init(void);
57void ti99_peb_reset(int in_has_16bit_peb, void (*in_inta_callback)(int state), void (*in_intb_callback)(int state));
57void ti99_peb_reset(int in_has_16bit_peb, void (*in_inta_callback)(running_machine *machine, int state), void (*in_intb_callback)(running_machine *machine, int state));
5858
5959void ti99_peb_set_card_handlers(int cru_base, const ti99_peb_card_handlers_t *handler);
6060void ti99_peb_set_16bit_card_handlers(int cru_base, const ti99_peb_16bit_card_handlers_t *handler);
src/mess/machine/comx35.c
r2724r2725
586586 
587587INPUT_CHANGED( comx35_reset )
588588{
589   if (BIT(input_port_read(machine, "RESET"), 0) && BIT(input_port_read(machine, "D6"), 7))
589   if (BIT(input_port_read(field->port->machine, "RESET"), 0) && BIT(input_port_read(field->port->machine, "D6"), 7))
590590   {
591      running_machine *machine = field->port->machine;
591592      MACHINE_RESET_CALL(comx35);
592593   }
593594}
src/mess/machine/svi318.c
r2724r2725
563563
564564/* Init functions */
565565
566void svi318_vdp_interrupt(int i)
566void svi318_vdp_interrupt(running_machine *machine, int i)
567567{
568   cpunum_set_input_line(Machine, 0, 0, (i ? HOLD_LINE : CLEAR_LINE));
568   cpunum_set_input_line(machine, 0, 0, (i ? HOLD_LINE : CLEAR_LINE));
569569}
570570
571571DRIVER_INIT( svi318 )
r2724r2725
669669
670670   set = input_port_read(machine, "CONFIG");
671671   TMS9928A_set_spriteslimit (set & 0x20);
672   TMS9928A_interrupt();
672   TMS9928A_interrupt(machine);
673673}
674674
675675/* Memory */
src/mess/machine/apple2gs.c
r2724r2725
336336   }
337337}
338338
339void apple2gs_doc_irq(int state)
339void apple2gs_doc_irq(running_machine *machine, int state)
340340{
341341   if (state)
342342   {
343      apple2gs_add_irq(Machine, IRQ_DOC);
343      apple2gs_add_irq(machine, IRQ_DOC);
344344   }
345345   else
346346   {
347      apple2gs_remove_irq(Machine, IRQ_DOC);
347      apple2gs_remove_irq(machine, IRQ_DOC);
348348   }
349349}
350350
src/mess/machine/mac.c
r2724r2725
7575static WRITE8_HANDLER(mac_via_out_a);
7676static WRITE8_HANDLER(mac_via_out_b);
7777static WRITE8_HANDLER(mac_via_out_cb2);
78static void mac_via_irq(int state);
78static void mac_via_irq(running_machine *machine, int state);
7979static offs_t mac_dasm_override(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram);
8080
8181static const struct via6522_interface mac_via6522_intf =
r2724r2725
12531253      mac_adb_newaction((data & 0x30) >> 4);
12541254}
12551255
1256static void mac_via_irq(int state)
1256static void mac_via_irq(running_machine *machine, int state)
12571257{
12581258   /* interrupt the 68k (level 1) */
12591259   //cpunum_set_input_line(machine, 0, 1, state);
1260   set_via_interrupt(Machine, state);
1260   set_via_interrupt(machine, state);
12611261}
12621262
12631263READ16_HANDLER ( mac_via_r )
src/mess/machine/concept.c
r2724r2725
4747static  READ8_HANDLER(via_in_b);
4848static WRITE8_HANDLER(via_out_b);
4949static WRITE8_HANDLER(via_out_cb2);
50static void via_irq_func(int state);
50static void via_irq_func(running_machine *machine, int state);
5151
5252
5353static const struct via6522_interface concept_via6522_intf =
r2724r2725
274274/*
275275   VIA irq -> 68k level 5
276276*/
277static void via_irq_func(int state)
277static void via_irq_func(running_machine *machine, int state)
278278{
279   concept_set_interrupt(Machine, TIMINT_level, state);
279   concept_set_interrupt(machine, TIMINT_level, state);
280280}
281281
282282READ16_HANDLER(concept_io_r)
src/mess/machine/msx.c
r2724r2725
277277   }
278278}
279279
280void msx_vdp_interrupt(int i)
280void msx_vdp_interrupt(running_machine *machine, int i)
281281{
282   cpunum_set_input_line (Machine, 0, 0, (i ? HOLD_LINE : CLEAR_LINE));
282   cpunum_set_input_line (machine, 0, 0, (i ? HOLD_LINE : CLEAR_LINE));
283283}
284284
285285static void msx_ch_reset_core (void)
r2724r2725
421421   }
422422
423423   TMS9928A_set_spriteslimit (input_port_read(machine, "DSW") & 0x20);
424   TMS9928A_interrupt();
424   TMS9928A_interrupt(machine);
425425}
426426
427427/*
src/mess/machine/vectrex.c
r2724r2725
211211
212212*********************************************************************/
213213
214void v_via_irq (int level)
214void v_via_irq (running_machine *machine, int level)
215215{
216   cpunum_set_input_line(Machine, 0, M6809_IRQ_LINE, level);
216   cpunum_set_input_line(machine, 0, M6809_IRQ_LINE, level);
217217}
218218
219219READ8_HANDLER( v_via_pb_r )
src/mess/machine/pc_joy.c
r2724r2725
1919   UINT8 data = 0;
2020   int delta;
2121   attotime new_time = timer_get_time();
22   int joystick_port = port_tag_to_index("pc_joy");
22   const input_port_config *joystick_port = input_port_by_tag(machine->portconfig, "pc_joy");
2323
24   if (joystick_port >= 0)
24   if (joystick_port != NULL)
2525   {
26      data = input_port_read_indexed(machine, joystick_port + 0) ^ 0xf0;
26      data = input_port_read_direct(joystick_port) ^ 0xf0;
2727
2828      /* timer overflow? */
2929      if (attotime_compare(attotime_sub(new_time, JOY_time), ATTOTIME_IN_MSEC(10)) > 0)
r2724r2725
3333      else
3434      {
3535         delta = attotime_mul(attotime_sub(new_time, JOY_time), 256 * 1000).seconds;
36         if (input_port_read_indexed(machine, joystick_port + 1) < delta) data &= ~0x01;
37         if (input_port_read_indexed(machine, joystick_port + 2) < delta) data &= ~0x02;
38         if (input_port_read_indexed(machine, joystick_port + 3) < delta) data &= ~0x04;
39         if (input_port_read_indexed(machine, joystick_port + 4) < delta) data &= ~0x08;
36         if (input_port_read(machine, "pc_joy_1") < delta) data &= ~0x01;
37         if (input_port_read(machine, "pc_joy_2") < delta) data &= ~0x02;
38         if (input_port_read(machine, "pc_joy_3") < delta) data &= ~0x04;
39         if (input_port_read(machine, "pc_joy_4") < delta) data &= ~0x08;
4040      }
4141   }
4242   return data;
r2724r2725
7979   PORT_BIT( 0x0040, 0x0000, IPT_BUTTON1) PORT_NAME("Joystick 2 Button 1") PORT_CODE(JOYCODE_BUTTON1) PORT_PLAYER(2)
8080   PORT_BIT( 0x0080, 0x0000, IPT_BUTTON2) PORT_NAME("Joystick 2 Button 2") PORT_CODE(JOYCODE_BUTTON2) PORT_PLAYER(2)
8181
82   PORT_START
82   PORT_START_TAG("pc_joy_1")
8383   PORT_BIT(0xff,0x80,IPT_AD_STICK_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_MINMAX(1,0xff) PORT_CODE_DEC(KEYCODE_LEFT) PORT_CODE_INC(KEYCODE_RIGHT) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH) PORT_REVERSE
8484
85   PORT_START
85   PORT_START_TAG("pc_joy_2")
8686   PORT_BIT(0xff,0x80,IPT_AD_STICK_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_MINMAX(1,0xff) PORT_CODE_DEC(KEYCODE_UP) PORT_CODE_INC(KEYCODE_DOWN) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH) PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH) PORT_REVERSE
8787
88   PORT_START
88   PORT_START_TAG("pc_joy_3")
8989   PORT_BIT(0xff,0x80,IPT_AD_STICK_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_MINMAX(1,0xff) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH) PORT_PLAYER(2) PORT_REVERSE
9090
91   PORT_START
91   PORT_START_TAG("pc_joy_4")
9292   PORT_BIT(0xff,0x80,IPT_AD_STICK_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_MINMAX(1,0xff) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH) PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH) PORT_PLAYER(2) PORT_REVERSE
9393INPUT_PORTS_END
9494
src/mess/machine/lisa.c
r2724r2725
131131static WRITE8_HANDLER(COPS_via_out_b);
132132static WRITE8_HANDLER(COPS_via_out_ca2);
133133static WRITE8_HANDLER(COPS_via_out_cb2);
134static void COPS_via_irq_func(int val);
134static void COPS_via_irq_func(running_machine *machine, int val);
135135static  READ8_HANDLER(parallel_via_in_b);
136136
137137static int KBIR;   /* COPS VIA interrupt pending */
r2724r2725
842842   speaker_level_w(0, data);
843843}
844844
845static void COPS_via_irq_func(int val)
845static void COPS_via_irq_func(running_machine *machine, int val)
846846{
847847   if (KBIR != val)
848848   {
849849      KBIR = val;
850      lisa_field_interrupts(Machine);
850      lisa_field_interrupts(machine);
851851   }
852852}
853853
src/mess/machine/sym1.c
r2724r2725
171171******************************************************************************/
172172
173173
174static void sym1_irq(int level)
174static void sym1_irq(running_machine *machine, int level)
175175{
176   cpunum_set_input_line(Machine, 0, M6502_IRQ_LINE, level);
176   cpunum_set_input_line(machine, 0, M6502_IRQ_LINE, level);
177177}
178178
179179
src/mess/machine/geneve.c
r2724r2725
2424
2525
2626/* prototypes */
27static void inta_callback(int state);
28static void intb_callback(int state);
27static void inta_callback(running_machine *machine, int state);
28static void intb_callback(running_machine *machine, int state);
2929
3030static void read_key_if_possible(void);
3131static void poll_keyboard(void);
r2724r2725
254254   KeyReset = 1;
255255
256256   /* read config */
257   has_speech = (input_port_read_indexed(machine, input_port_config) >> config_speech_bit) & config_speech_mask;
258   fdc_kind = (input_port_read_indexed(machine, input_port_config) >> config_fdc_bit) & config_fdc_mask;
259   has_ide = (input_port_read_indexed(machine, input_port_config) >> config_ide_bit) & config_ide_mask;
260   has_rs232 = (input_port_read_indexed(machine, input_port_config) >> config_rs232_bit) & config_rs232_mask;
261   has_usb_sm = (input_port_read_indexed(machine, input_port_config) >> config_usbsm_bit) & config_usbsm_mask;
257   has_speech = (input_port_read_indexed(machine, INPUT_PORT_CONFIG) >> config_speech_bit) & config_speech_mask;
258   fdc_kind = (input_port_read_indexed(machine, INPUT_PORT_CONFIG) >> config_fdc_bit) & config_fdc_mask;
259   has_ide = (input_port_read_indexed(machine, INPUT_PORT_CONFIG) >> config_ide_bit) & config_ide_mask;
260   has_rs232 = (input_port_read_indexed(machine, INPUT_PORT_CONFIG) >> config_rs232_bit) & config_rs232_mask;
261   has_usb_sm = (input_port_read_indexed(machine, INPUT_PORT_CONFIG) >> config_usbsm_bit) & config_usbsm_mask;
262262
263263   /* set up optional expansion hardware */
264264   ti99_peb_reset(0, inta_callback, intb_callback);
r2724r2725
342342/*
343343   inta is connected to both tms9901 IRQ1 line and to tms9995 INT4/EC line.
344344*/
345static void inta_callback(int state)
345static void inta_callback(running_machine *machine, int state)
346346{
347347   tms9901_set_single_int(0, 1, state);
348   cpunum_set_input_line(Machine, 0, 1, state ? ASSERT_LINE : CLEAR_LINE);
348   cpunum_set_input_line(machine, 0, 1, state ? ASSERT_LINE : CLEAR_LINE);
349349}
350350
351351/*
352352   intb is connected to tms9901 IRQ12 line.
353353*/
354static void intb_callback(int state)
354static void intb_callback(running_machine *machine, int state)
355355{
356356   tms9901_set_single_int(0, 12, state);
357357}
src/mess/machine/pc8801.c
r2724r2725
842842  FM_IRQ_save=0;
843843}
844844
845void pc88sr_sound_interupt(int irq)
845void pc88sr_sound_interupt(running_machine *machine, int irq)
846846{
847  FM_IRQ_save=irq;
848  if(FM_IRQ_save && enable_FM_IRQ) pc8801_raise_interrupt(Machine, FM_IRQ_LEVEL);
847   FM_IRQ_save=irq;
848   if(FM_IRQ_save && enable_FM_IRQ) pc8801_raise_interrupt(machine, FM_IRQ_LEVEL);
849849}
850850
851851/*
src/mess/machine/atom.c
r2724r2725
4040/* I am not sure if this is correct, the atom appears to have a 2.4Khz timer used for reading tapes?? */
4141static int   timer_state = 0;
4242
43static void atom_via_irq_func(int state)
43static void atom_via_irq_func(running_machine *machine, int state)
4444{
4545   if (state)
4646   {
47      cpunum_set_input_line(Machine, 0, 0, HOLD_LINE);
47      cpunum_set_input_line(machine, 0, 0, HOLD_LINE);
4848   }
4949   else
5050   {
51      cpunum_set_input_line(Machine, 0, 0, CLEAR_LINE);
51      cpunum_set_input_line(machine, 0, 0, CLEAR_LINE);
5252   }
5353}
5454
src/mess/machine/vc20.c
r2724r2725
5757 pa2 till pa6, port b, cb1, cb2 userport
5858 irq connected to m6502 nmi
5959*/
60static void vc20_via0_irq (int level)
60static void vc20_via0_irq (running_machine *machine, int level)
6161{
62   cpunum_set_input_line(Machine, 0, INPUT_LINE_NMI, level);
62   cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, level);
6363}
6464
65static READ8_HANDLER( vc20_via0_read_ca1 )
65static READ8_HANDLER( vc20_via0_read_ca1 )
6666{
6767   return ! ( input_port_read(machine,  TAG_KEYBOARD_EXTRA ) & 0x02 );
6868}
6969
70static READ8_HANDLER( vc20_via0_read_ca2 )
70static READ8_HANDLER( vc20_via0_read_ca2 )
7171{
7272   DBG_LOG (1, "tape", ("motor read %d\n", via0_ca2));
7373   return via0_ca2;
r2724r2725
121121 * cb2 inverted serial data out
122122 * irq connected to m6502 irq
123123 */
124static void vc20_via1_irq (int level)
124static void vc20_via1_irq (running_machine *machine, int level)
125125{
126   cpunum_set_input_line(Machine, 0, M6502_IRQ_LINE, level);
126   cpunum_set_input_line(machine, 0, M6502_IRQ_LINE, level);
127127}
128128
129static READ8_HANDLER( vc20_via1_read_porta )
129static READ8_HANDLER( vc20_via1_read_porta )
130130{
131131   int value = 0xff;
132132
src/mess/machine/bebox.c
r2724r2725
908908{
909909   int reg = offset*8;
910910   if (!(mem_mask & U64(0xff00000000000000))) {
911      lsi53c810_reg_w(reg+0, data >> 56);
911      lsi53c810_reg_w(machine, reg+0, data >> 56);
912912   }
913913   if (!(mem_mask & U64(0x00ff000000000000))) {
914      lsi53c810_reg_w(reg+1, data >> 48);
914      lsi53c810_reg_w(machine, reg+1, data >> 48);
915915   }
916916   if (!(mem_mask & U64(0x0000ff0000000000))) {
917      lsi53c810_reg_w(reg+2, data >> 40);
917      lsi53c810_reg_w(machine, reg+2, data >> 40);
918918   }
919919   if (!(mem_mask & U64(0x000000ff00000000))) {
920      lsi53c810_reg_w(reg+3, data >> 32);
920      lsi53c810_reg_w(machine, reg+3, data >> 32);
921921   }
922922   if (!(mem_mask & U64(0x00000000ff000000))) {
923      lsi53c810_reg_w(reg+4, data >> 24);
923      lsi53c810_reg_w(machine, reg+4, data >> 24);
924924   }
925925   if (!(mem_mask & U64(0x0000000000ff0000))) {
926      lsi53c810_reg_w(reg+5, data >> 16);
926      lsi53c810_reg_w(machine, reg+5, data >> 16);
927927   }
928928   if (!(mem_mask & U64(0x000000000000ff00))) {
929      lsi53c810_reg_w(reg+6, data >> 8);
929      lsi53c810_reg_w(machine, reg+6, data >> 8);
930930   }
931931   if (!(mem_mask & U64(0x00000000000000ff))) {
932      lsi53c810_reg_w(reg+7, data >> 0);
932      lsi53c810_reg_w(machine, reg+7, data >> 0);
933933   }
934934}
935935
r2724r2725
947947}
948948
949949
950static void scsi53c810_irq_callback(void)
950static void scsi53c810_irq_callback(running_machine *machine)
951951{
952   bebox_set_irq_bit(Machine, 21, 1);
953   bebox_set_irq_bit(Machine, 21, 0);
952   bebox_set_irq_bit(machine, 21, 1);
953   bebox_set_irq_bit(machine, 21, 0);
954954}
955955
956956
src/mess/machine/mtx.c
r2724r2725
4949 *
5050 *************************************/
5151
52static void mtx_tms9929a_interrupt(int data)
52static void mtx_tms9929a_interrupt(running_machine *machine, int data)
5353{
54   running_machine *machine = Machine;
5554   z80ctc_0_trg0_w(machine, 0, data ? 0 : 1);
5655}
5756
r2724r2725
6564
6665INTERRUPT_GEN( mtx_interrupt )
6766{
68   TMS9928A_interrupt();
67   TMS9928A_interrupt(machine);
6968}
7069
7170
r2724r2725
210209 *
211210 *************************************/
212211
213static void mtx_ctc_interrupt(int state)
212static void mtx_ctc_interrupt(running_machine *machine, int state)
214213{
215214//  logerror("mtx_ctc_interrupt: %02x\n", state);
216   cpunum_set_input_line(Machine, 0, 0, state);
215   cpunum_set_input_line(machine, 0, 0, state);
217216}
218217
219218READ8_HANDLER( mtx_ctc_r )
src/mess/machine/c64.c
r2724r2725
322322   cia_issue_index(0);
323323}
324324
325static void c64_cia0_interrupt (int level)
325static void c64_cia0_interrupt (running_machine *machine, int level)
326326{
327   c64_irq (Machine, level || vicirq);
327   c64_irq (machine, level || vicirq);
328328}
329329
330330void c64_vic_interrupt (int level)
r2724r2725
386386   }
387387}
388388
389static void c64_cia1_interrupt (int level)
389static void c64_cia1_interrupt (running_machine *machine, int level)
390390{
391   c64_nmi(Machine);
391   c64_nmi(machine);
392392}
393393
394394const cia6526_interface c64_cia0 =
src/mess/machine/pce.c
r2724r2725
7575} pce_cd;
7676
7777/* MSM5205 ADPCM decoder definition */
78static void pce_cd_msm5205_int( int data );
78static void pce_cd_msm5205_int( running_machine *machine, int data );
7979const struct MSM5205interface pce_cd_msm5205_interface = {
8080   pce_cd_msm5205_int,   /* interrupt function */
8181   MSM5205_S48_4B      /* 1/48 prescaler, 4bit data */
r2724r2725
296296  the MSM5205. Currently we can only use static clocks for the
297297  MSM5205.
298298 */
299static void pce_cd_msm5205_int( int chip ) {
299static void pce_cd_msm5205_int( running_machine *machine, int chip ) {
300300   pce_cd.adpcm_clock_count = ( pce_cd.adpcm_clock_count + 1 ) % pce_cd.adpcm_clock_divider;
301301   if ( ! pce_cd.adpcm_clock_count ) {
302302      /* Supply new ADPCM data */
src/mess/machine/ti99_4x.c
r2724r2725
7676static READ16_HANDLER ( ti99_rspeech_r );
7777static WRITE16_HANDLER ( ti99_wspeech_w );
7878
79static void tms9901_set_int1(int state);
79static void tms9901_set_int1(running_machine *machine, int state);
8080static void tms9901_interrupt_callback(int intreq, int ic);
8181static int ti99_R9901_0(int offset);
8282static int ti99_R9901_1(int offset);
r2724r2725
792792   else if (ti99_model == model_99_4p)
793793      xRAM_kind = xRAM_kind_99_4p_1Mb;   /* hack */
794794   else
795      xRAM_kind = (input_port_read_indexed(machine, input_port_config) >> config_xRAM_bit) & config_xRAM_mask;
795      xRAM_kind = (input_port_read_indexed(machine, INPUT_PORT_CONFIG) >> config_xRAM_bit) & config_xRAM_mask;
796796   if (ti99_model == model_99_8)
797797      has_speech = TRUE;
798798   else
799      has_speech = (input_port_read_indexed(machine, input_port_config) >> config_speech_bit) & config_speech_mask;
800   fdc_kind = (input_port_read_indexed(machine, input_port_config) >> config_fdc_bit) & config_fdc_mask;
801   has_ide = (input_port_read_indexed(machine, input_port_config) >> config_ide_bit) & config_ide_mask;
802   has_rs232 = (input_port_read_indexed(machine, input_port_config) >> config_rs232_bit) & config_rs232_mask;
803   has_handset = (ti99_model == model_99_4) && ((input_port_read_indexed(machine, input_port_config) >> config_handsets_bit) & config_handsets_mask);
804   has_hsgpl = (ti99_model == model_99_4p) || ((input_port_read_indexed(machine, input_port_config) >> config_hsgpl_bit) & config_hsgpl_mask);
805   has_usb_sm = (input_port_read_indexed(machine, input_port_config) >> config_usbsm_bit) & config_usbsm_mask;
799      has_speech = (input_port_read_indexed(machine, INPUT_PORT_CONFIG) >> config_speech_bit) & config_speech_mask;
800   fdc_kind = (input_port_read_indexed(machine, INPUT_PORT_CONFIG) >> config_fdc_bit) & config_fdc_mask;
801   has_ide = (input_port_read_indexed(machine, INPUT_PORT_CONFIG) >> config_ide_bit) & config_ide_mask;
802   has_rs232 = (input_port_read_indexed(machine, INPUT_PORT_CONFIG) >> config_rs232_bit) & config_rs232_mask;
803   has_handset = (ti99_model == model_99_4) && ((input_port_read_indexed(machine, INPUT_PORT_CONFIG) >> config_handsets_bit) & config_handsets_mask);
804   has_hsgpl = (ti99_model == model_99_4p) || ((input_port_read_indexed(machine, INPUT_PORT_CONFIG) >> config_hsgpl_bit) & config_hsgpl_mask);
805   has_usb_sm = (input_port_read_indexed(machine, INPUT_PORT_CONFIG) >> config_usbsm_bit) & config_usbsm_mask;
806806
807807   /* set up optional expansion hardware */
808808   ti99_peb_reset(ti99_model == model_99_4p, tms9901_set_int1, NULL);
r2724r2725
944944*/
945945INTERRUPT_GEN( ti99_vblank_interrupt )
946946{
947   TMS9928A_interrupt();
947   TMS9928A_interrupt(machine);
948948   if (has_handset)
949949      ti99_handset_task();
950   has_mecmouse = (input_port_read_indexed(machine, input_port_config) >> config_mecmouse_bit) & config_mecmouse_mask;
950   has_mecmouse = (input_port_read_indexed(machine, INPUT_PORT_CONFIG) >> config_mecmouse_bit) & config_mecmouse_mask;
951951   if (has_mecmouse)
952952      mecmouse_poll();
953953}
r2724r2725
959959   if (++line_count == 262)
960960   {
961961      line_count = 0;
962      has_mecmouse = (input_port_read_indexed(machine, input_port_config) >> config_mecmouse_bit) & config_mecmouse_mask;
962      has_mecmouse = (input_port_read_indexed(machine, INPUT_PORT_CONFIG) >> config_mecmouse_bit) & config_mecmouse_mask;
963963      if (has_mecmouse)
964964         mecmouse_poll();
965965   }
r2724r2725
21812181/*
21822182   set the state of int1 (called by the peb core)
21832183*/
2184static void tms9901_set_int1(int state)
2184static void tms9901_set_int1(running_machine *machine, int state)
21852185{
21862186   tms9901_set_single_int(0, 1, state);
21872187}
r2724r2725
21892189/*
21902190   set the state of int2 (called by the tms9928 core)
21912191*/
2192void tms9901_set_int2(int state)
2192void tms9901_set_int2(running_machine *machine, int state)
21932193{
21942194   tms9901_set_single_int(0, 2, state);
21952195}
src/mess/machine/ti99_4x.h
r2724r2725
108108/* defines for input ports */
109109enum
110110{
111   input_port_config = 0,
111   INPUT_PORT_CONFIG = 0,
112112   input_port_mousex,                           /* optional mouse */
113113   input_port_mousey,                           /* optional mouse */
114114   input_port_mouse_buttons,                     /* optional mouse */
r2724r2725
194194READ16_HANDLER ( ti99_4p_rgpl_r );
195195WRITE16_HANDLER ( ti99_4p_wgpl_w );
196196
197extern void tms9901_set_int2(int state);
197extern void tms9901_set_int2(running_machine *machine, int state);
198198
199 READ8_HANDLER ( ti99_8_r );
199READ8_HANDLER ( ti99_8_r );
200200WRITE8_HANDLER ( ti99_8_w );
src/mess/machine/bbc.c
r2724r2725
11631163
11641164
11651165
1166static void bbc_via_system_irq(int level)
1166static void bbc_via_system_irq(running_machine *machine, int level)
11671167{
11681168//  logerror("SYSTEM via irq %d %d %d\n",via_system_irq,via_user_irq,level);
11691169  via_system_irq=level;
1170  bbc_setirq(Machine);
1170  bbc_setirq(machine);
11711171}
11721172
11731173
r2724r2725
12531253   via_1_ca1_w(machine, 0,data);
12541254}
12551255
1256static void bbc_via_user_irq(int level)
1256static void bbc_via_user_irq(running_machine *machine, int level)
12571257{
12581258  via_user_irq=level;
1259  bbc_setirq(Machine);
1259  bbc_setirq(machine);
12601260}
12611261
12621262
src/mess/machine/kc.c
r2724r2725
17251725}
17261726
17271727
1728static void kc85_pio_interrupt(int state)
1728static void kc85_pio_interrupt(running_machine *machine, int state)
17291729{
1730   cpunum_set_input_line(Machine, 0, 0, state);
1730   cpunum_set_input_line(machine, 0, 0, state);
17311731}
17321732
1733static void kc85_ctc_interrupt(int state)
1733static void kc85_ctc_interrupt(running_machine *machine, int state)
17341734{
1735   cpunum_set_input_line(Machine, 0, 1, state);
1735   cpunum_set_input_line(machine, 0, 1, state);
17361736}
17371737
17381738/* callback for ardy output from PIO */
src/mess/drivers/pdp1.c
r2724r2725
300300   PORT_BIT(0x8000, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Return") PORT_CODE(KEYCODE_ENTER)
301301
302302   PORT_START      /* 10: pseudo-input port with config */
303   PORT_BIT( 0x0003, 0x0002, IPT_DIPSWITCH_NAME) PORT_NAME("RAM size")
303   PORT_DIPNAME( 0x0003, 0x0002, "RAM size")
304304    PORT_DIPSETTING(   0x0000, "4kw" )
305305    PORT_DIPSETTING(   0x0001, "32kw")
306306    PORT_DIPSETTING(   0x0002, "64kw")
307   PORT_BIT( 0x0004, 0x0000, IPT_DIPSWITCH_NAME) PORT_NAME("Hardware multiply")
307   PORT_DIPNAME( 0x0004, 0x0000, "Hardware multiply")
308308    PORT_DIPSETTING(   0x0000, DEF_STR( Off ) )
309309    PORT_DIPSETTING(   0x0004, DEF_STR( On ) )
310   PORT_BIT( 0x0008, 0x0000, IPT_DIPSWITCH_NAME) PORT_NAME("Hardware divide")
310   PORT_DIPNAME( 0x0008, 0x0000, "Hardware divide")
311311    PORT_DIPSETTING(   0x0000, DEF_STR( Off ) )
312312    PORT_DIPSETTING(   0x0008, DEF_STR( On ) )
313   PORT_BIT( 0x0010, 0x0000, IPT_DIPSWITCH_NAME) PORT_NAME("Type 20 sequence break system")
313   PORT_DIPNAME( 0x0010, 0x0000, "Type 20 sequence break system")
314314    PORT_DIPSETTING(   0x0000, DEF_STR( Off ) )
315315    PORT_DIPSETTING(   0x0010, DEF_STR( On ) )
316316   PORT_DIPNAME( 0x0020, 0x0000, "Type 32 light pen") PORT_CODE(KEYCODE_ENTER_PAD)
src/mess/drivers/adam.c
r2724r2725
423423
424424static INTERRUPT_GEN( adam_interrupt )
425425{
426    TMS9928A_interrupt();
426    TMS9928A_interrupt(machine);
427427    exploreKeyboard();
428428}
429429
430static void adam_vdp_interrupt (int state)
430static void adam_vdp_interrupt (running_machine *machine, int state)
431431{
432432   static int last_state = 0;
433433
434434    /* only if it goes up */
435435   if (state && !last_state)
436436    {
437        cpunum_set_input_line(Machine, 0, INPUT_LINE_NMI, PULSE_LINE);
437        cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, PULSE_LINE);
438438    }
439439   last_state = state;
440440}
src/mess/drivers/sord.c
r2724r2725
298298/*********************************************************************************************/
299299
300300
301static void sord_m5_ctc_interrupt(int state)
301static void sord_m5_ctc_interrupt(running_machine *machine, int state)
302302{
303303   //logerror("interrupting ctc %02x\r\n ",state);
304   cpunum_set_input_line(Machine, 0, 0, state);
304   cpunum_set_input_line(machine, 0, 0, state);
305305}
306306
307307static z80ctc_interface   sord_m5_ctc_intf =
r2724r2725
451451   },
452452};
453453
454static void sordm5_video_interrupt_callback(int state)
454static void sordm5_video_interrupt_callback(running_machine *machine, int state)
455455{
456456   if (state)
457457   {
458      z80ctc_0_trg3_w(Machine, 0, 1);
459      z80ctc_0_trg3_w(Machine, 0, 0);
458      z80ctc_0_trg3_w(machine, 0, 1);
459      z80ctc_0_trg3_w(machine, 0, 0);
460460   }
461461}
462462
r2724r2725
622622
623623static INTERRUPT_GEN( sord_interrupt )
624624{
625   if (TMS9928A_interrupt())
625   if (TMS9928A_interrupt(machine))
626626      cpunum_set_input_line(machine, 0, 0, HOLD_LINE);
627627}
628628
src/mess/drivers/ti99_8.c
r2724r2725
198198
199199   /* 1 port for config */
200200   PORT_START   /* config */
201      PORT_BIT( config_fdc_mask << config_fdc_bit, /*fdc_kind_hfdc << config_fdc_bit*/0, IPT_DIPSWITCH_NAME) PORT_NAME("Floppy disk controller")
201      PORT_DIPNAME( config_fdc_mask << config_fdc_bit, /*fdc_kind_hfdc << config_fdc_bit*/0, "Floppy disk controller")
202202         PORT_DIPSETTING( fdc_kind_none << config_fdc_bit, DEF_STR( None ) )
203203         PORT_DIPSETTING( fdc_kind_TI << config_fdc_bit, "Texas Instruments SD" )
204204#if HAS_99CCFDC
r2724r2725
206206#endif
207207         PORT_DIPSETTING( fdc_kind_BwG << config_fdc_bit, "SNUG's BwG" )
208208         PORT_DIPSETTING( fdc_kind_hfdc << config_fdc_bit, "Myarc's HFDC" )
209      PORT_BIT( config_ide_mask << config_ide_bit, /*1 << config_ide_bit*/0, IPT_DIPSWITCH_NAME) PORT_NAME("Nouspickel's IDE card")
209      PORT_DIPNAME( config_ide_mask << config_ide_bit, /*1 << config_ide_bit*/0, "Nouspickel's IDE card")
210210         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
211211         PORT_DIPSETTING( 1 << config_ide_bit, DEF_STR( On ) )
212      PORT_BIT( config_rs232_mask << config_rs232_bit, /*1 << config_rs232_bit*/0, IPT_DIPSWITCH_NAME) PORT_NAME("TI RS232 card")
212      PORT_DIPNAME( config_rs232_mask << config_rs232_bit, /*1 << config_rs232_bit*/0, "TI RS232 card")
213213         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
214214         PORT_DIPSETTING( 1 << config_rs232_bit, DEF_STR( On ) )
215      PORT_BIT( config_hsgpl_mask << config_hsgpl_bit, 0/*1 << config_hsgpl_bit*/, IPT_DIPSWITCH_NAME) PORT_NAME("SNUG HSGPL card")
215      PORT_DIPNAME( config_hsgpl_mask << config_hsgpl_bit, 0/*1 << config_hsgpl_bit*/, "SNUG HSGPL card")
216216         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
217217         PORT_DIPSETTING( 1 << config_hsgpl_bit, DEF_STR( On ) )
218      PORT_BIT( config_mecmouse_mask << config_mecmouse_bit, 0, IPT_DIPSWITCH_NAME) PORT_NAME("Mechatronics Mouse")
218      PORT_DIPNAME( config_mecmouse_mask << config_mecmouse_bit, 0, "Mechatronics Mouse")
219219         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
220220         PORT_DIPSETTING( 1 << config_mecmouse_bit, DEF_STR( On ) )
221      PORT_BIT( config_usbsm_mask << config_usbsm_bit, 1 << config_usbsm_bit, IPT_DIPSWITCH_NAME) PORT_NAME("Nouspickel's USB-SM card")
221      PORT_DIPNAME( config_usbsm_mask << config_usbsm_bit, 1 << config_usbsm_bit, "Nouspickel's USB-SM card")
222222         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
223223         PORT_DIPSETTING( 1 << config_usbsm_bit, DEF_STR( On ) )
224224
src/mess/drivers/kim1.c
r2724r2725
108108   PORT_BIT (0x80, 0x00, IPT_UNUSED )
109109   PORT_BIT(0x40, 0x40, IPT_KEYBOARD) PORT_NAME("sw1: ST (F7)") PORT_CODE(KEYCODE_F7)
110110   PORT_BIT(0x20, 0x20, IPT_KEYBOARD) PORT_NAME("sw2: RS (F3)") PORT_CODE(KEYCODE_F3)
111   PORT_BIT(0x10, 0x10, IPT_DIPSWITCH_NAME) PORT_NAME("sw3: SS (NumLock)") PORT_CODE(KEYCODE_NUMLOCK) PORT_TOGGLE
111   PORT_DIPNAME(0x10, 0x10, "sw3: SS (NumLock)") PORT_CODE(KEYCODE_NUMLOCK) PORT_TOGGLE
112112   PORT_DIPSETTING( 0x00, "single step")
113113   PORT_DIPSETTING( 0x10, "run")
114114   PORT_BIT (0x08, 0x00, IPT_UNUSED )
src/mess/drivers/dc.c
r2724r2725
121121   AICA_set_ram_base(0, dc_sound_ram, 2*1024*1024);
122122}
123123
124static void aica_irq(int irq)
124static void aica_irq(running_machine *machine, int irq)
125125{
126   cpunum_set_input_line(Machine, 1, ARM7_FIRQ_LINE, irq ? ASSERT_LINE : CLEAR_LINE);
126   cpunum_set_input_line(machine, 1, ARM7_FIRQ_LINE, irq ? ASSERT_LINE : CLEAR_LINE);
127127}
128128
129129static const struct AICAinterface aica_interface =
src/mess/drivers/cgenie.c
r2724r2725
7272   PORT_DIPNAME(     0x20, 0x00, "Extension  E000-EFFF")
7373   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )
7474   PORT_DIPSETTING(   0x20, DEF_STR( On ) )
75   PORT_BIT(     0x10, 0x10, IPT_DIPSWITCH_NAME) PORT_NAME("Video Display accuracy") PORT_CODE(KEYCODE_F5) PORT_TOGGLE
75   PORT_DIPNAME(     0x10, 0x10, "Video Display accuracy") PORT_CODE(KEYCODE_F5) PORT_TOGGLE
7676   PORT_DIPSETTING(   0x10, "TV set" )
7777   PORT_DIPSETTING(   0x00, "RGB monitor" )
78   PORT_BIT(     0x08, 0x08, IPT_DIPSWITCH_NAME) PORT_NAME("Virtual tape support") PORT_CODE(KEYCODE_F6) PORT_TOGGLE
78   PORT_DIPNAME(     0x08, 0x08, "Virtual tape support") PORT_CODE(KEYCODE_F6) PORT_TOGGLE
7979   PORT_DIPSETTING(   0x00, DEF_STR( Off ) )
8080   PORT_DIPSETTING(   0x08, DEF_STR( On ) )
8181   PORT_BIT(0x07, 0x07, IPT_UNUSED)
src/mess/drivers/x68k.c
r2724r2725
14401440   }
14411441}
14421442
1443static void x68k_fm_irq(int irq)
1443static void x68k_fm_irq(running_machine *machine, int irq)
14441444{
14451445   if(irq == CLEAR_LINE)
14461446   {
src/mess/drivers/mpf1.c
r2724r2725
367367
368368/* Z80 PIO Interface */
369369
370static void mpf1_pio_interrupt( int state )
370static void mpf1_pio_interrupt( running_machine *machine, int state )
371371{
372372   logerror("pio irq state: %02x\n",state);
373373}
src/mess/drivers/super80.c
r2724r2725
341341
342342/**************************** PIO ******************************************************************************/
343343
344static void pio_interrupt(int state)
344static void pio_interrupt(running_machine *machine, int state)
345345{
346   cpunum_set_input_line( Machine, 0, 0, state ? ASSERT_LINE : CLEAR_LINE );
346   cpunum_set_input_line( machine, 0, 0, state ? ASSERT_LINE : CLEAR_LINE );
347347}
348348
349349static const z80pio_interface pio_intf =
src/mess/drivers/geneve.c
r2724r2725
252252static INPUT_PORTS_START(geneve)
253253
254254   PORT_START   /* config */
255      PORT_BIT( config_speech_mask << config_speech_bit, 1 << config_speech_bit, IPT_DIPSWITCH_NAME) PORT_NAME("Speech synthesis")
255      PORT_DIPNAME( config_speech_mask << config_speech_bit, 1 << config_speech_bit, "Speech synthesis")
256256         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
257257         PORT_DIPSETTING( 1 << config_speech_bit, DEF_STR( On ) )
258      PORT_BIT( config_fdc_mask << config_fdc_bit, fdc_kind_hfdc << config_fdc_bit, IPT_DIPSWITCH_NAME) PORT_NAME("Floppy disk controller")
258      PORT_DIPNAME( config_fdc_mask << config_fdc_bit, fdc_kind_hfdc << config_fdc_bit, "Floppy disk controller")
259259         PORT_DIPSETTING( fdc_kind_none << config_fdc_bit, DEF_STR( None ) )
260260         PORT_DIPSETTING( fdc_kind_TI << config_fdc_bit, "Texas Instruments SD" )
261261#if HAS_99CCFDC
r2724r2725
263263#endif
264264         PORT_DIPSETTING( fdc_kind_BwG << config_fdc_bit, "SNUG's BwG" )
265265         PORT_DIPSETTING( fdc_kind_hfdc << config_fdc_bit, "Myarc's HFDC" )
266      PORT_BIT( config_ide_mask << config_ide_bit, /*1 << config_ide_bit*/0, IPT_DIPSWITCH_NAME) PORT_NAME("Nouspickel's IDE card")
266      PORT_DIPNAME( config_ide_mask << config_ide_bit, /*1 << config_ide_bit*/0, "Nouspickel's IDE card")
267267         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
268268         PORT_DIPSETTING( 1 << config_ide_bit, DEF_STR( On ) )
269      PORT_BIT( config_rs232_mask << config_rs232_bit, 1 << config_rs232_bit, IPT_DIPSWITCH_NAME) PORT_NAME("TI RS232 card")
269      PORT_DIPNAME( config_rs232_mask << config_rs232_bit, 1 << config_rs232_bit, "TI RS232 card")
270270         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
271271         PORT_DIPSETTING( 1 << config_rs232_bit, DEF_STR( On ) )
272      PORT_BIT( config_usbsm_mask << config_usbsm_bit, 1 << config_usbsm_bit, IPT_DIPSWITCH_NAME) PORT_NAME("Nouspickel's USB-SM card")
272      PORT_DIPNAME( config_usbsm_mask << config_usbsm_bit, 1 << config_usbsm_bit, "Nouspickel's USB-SM card")
273273         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
274274         PORT_DIPSETTING( 1 << config_usbsm_bit, DEF_STR( On ) )
275275
src/mess/drivers/sg1000.c
r2724r2725
313313
314314static INTERRUPT_GEN( sg1000_int )
315315{
316    TMS9928A_interrupt();
316    TMS9928A_interrupt(machine);
317317}
318318
319static void sg1000_vdp_interrupt(int state)
319static void sg1000_vdp_interrupt(running_machine *machine, int state)
320320{
321   cpunum_set_input_line_and_vector(Machine, 0, INPUT_LINE_IRQ0, state, 0x38);
321   cpunum_set_input_line_and_vector(machine, 0, INPUT_LINE_IRQ0, state, 0x38);
322322}
323323
324324static const TMS9928a_interface tms9928a_interface =
src/mess/drivers/ip22.c
r2724r2725
12711271
12721272static UINT8 dma_buffer[4096];
12731273
1274static void scsi_irq(int state)
1274static void scsi_irq(running_machine *machine, int state)
12751275{
1276   running_machine *machine = Machine;
1277
12781276   if (state)
12791277   {
12801278      if (wd33c93_get_dma_count())
src/mess/drivers/a2600.c
r2724r2725
11381138static WRITE8_HANDLER( switch_B_w ) {
11391139}
11401140
1141static void irq_callback(int state) {
1141static void irq_callback(running_machine *machine, int state) {
11421142}
11431143
11441144static const struct riot6532_interface r6532_interface =
r2724r2725
14311431}
14321432
14331433static void set_category_value( running_machine *machine, const char* cat, const char *cat_selection ) {
1434   /* NPW 22-May-2008 - FIXME */
1435#if 0
14341436   input_port_entry   *cat_in = NULL;
14351437   input_port_entry   *in;
14361438
r2724r2725
14431445         return;
14441446      }
14451447   }
1448#endif
14461449}
14471450
14481451static void set_controller( running_machine *machine, const char *controller, unsigned int selection ) {
src/mess/drivers/at.c
r2724r2725
402402
403403#if defined(ADLIB)
404404/* irq line not connected to pc on adlib cards (and compatibles) */
405static void irqhandler(int linestate) {}
405static void irqhandler(running_machine *machine, int linestate) {}
406406
407407static const struct YM3812interface ym3812_interface =
408408{
src/mess/drivers/coleco.c
r2724r2725
177177
178178static INTERRUPT_GEN( coleco_interrupt )
179179{
180    TMS9928A_interrupt();
180    TMS9928A_interrupt(machine);
181181}
182182
183static void coleco_vdp_interrupt (int state)
183static void coleco_vdp_interrupt (running_machine *machine, int state)
184184{
185185   static int last_state = 0;
186186
187187    // only if it goes up
188   if (state && !last_state) cpunum_set_input_line(Machine, 0, INPUT_LINE_NMI, PULSE_LINE);
188   if (state && !last_state) cpunum_set_input_line(machine, 0, INPUT_LINE_NMI, PULSE_LINE);
189189   last_state = state;
190190}
191191
src/mess/drivers/ex800.c
r2724r2725
170170
171171   if (newval)
172172   {
173      cpunum_set_input_line(machine, 0, UPD7810_INTF1, state);
173      cpunum_set_input_line(field->port->machine, 0, UPD7810_INTF1, state);
174174      state = (state == ASSERT_LINE) ? CLEAR_LINE : ASSERT_LINE;
175175   }
176176}
src/mess/drivers/apf.c
r2724r2725
148148   cpunum_set_input_line(machine, 0, 0, apf_ints ? HOLD_LINE : CLEAR_LINE);
149149}
150150
151static void   apf_m1000_irq_a_func(int state)
151static void   apf_m1000_irq_a_func(running_machine *machine, int state)
152152{
153153   if (state)
154154   {
r2724r2725
159159      apf_ints&=~1;
160160   }
161161
162   apf_update_ints(Machine);
162   apf_update_ints(machine);
163163}
164164
165165
166static void   apf_m1000_irq_b_func(int state)
166static void   apf_m1000_irq_b_func(running_machine *machine, int state)
167167{
168168   //logerror("pia 0 irq b %d\n",state);
169169
r2724r2725
176176      apf_ints&=~2;
177177   }
178178
179   apf_update_ints(Machine);
179   apf_update_ints(machine);
180180
181181}
182182
r2724r2725
274274{
275275}
276276
277static void   apf_imagination_irq_a_func(int state)
277static void   apf_imagination_irq_a_func(running_machine *machine, int state)
278278{
279279   if (state)
280280   {
r2724r2725
285285      apf_ints&=~4;
286286   }
287287
288   apf_update_ints(Machine);
288   apf_update_ints(machine);
289289
290290}
291291
292static void   apf_imagination_irq_b_func(int state)
292static void   apf_imagination_irq_b_func(running_machine *machine, int state)
293293{
294294   if (state)
295295   {
r2724r2725
300300      apf_ints&=~8;
301301   }
302302
303   apf_update_ints(Machine);
303   apf_update_ints(machine);
304304
305305}
306306
src/mess/drivers/saturn.c
r2724r2725
22492249static const struct sh2_config sh2_conf_master = { 0 };
22502250static const struct sh2_config sh2_conf_slave  = { 1 };
22512251
2252static void scsp_irq(int irq)
2252static void scsp_irq(running_machine *machine, int irq)
22532253{
22542254   // don't bother the 68k if it's off
22552255   if (!en_68k)
r2724r2725
22602260   if (irq > 0)
22612261   {
22622262      scsp_last_line = irq;
2263      cpunum_set_input_line(Machine, 2, irq, ASSERT_LINE);
2263      cpunum_set_input_line(machine, 2, irq, ASSERT_LINE);
22642264   }
22652265   else if (irq < 0)
22662266   {
2267      cpunum_set_input_line(Machine, 2, -irq, CLEAR_LINE);
2267      cpunum_set_input_line(machine, 2, -irq, CLEAR_LINE);
22682268   }
22692269   else
22702270   {
2271      cpunum_set_input_line(Machine, 2, scsp_last_line, CLEAR_LINE);
2271      cpunum_set_input_line(machine, 2, scsp_last_line, CLEAR_LINE);
22722272   }
22732273}
22742274
src/mess/drivers/crvision.c
r2724r2725
197197
198198static INTERRUPT_GEN( crvision_int )
199199{
200    TMS9928A_interrupt();
200    TMS9928A_interrupt(machine);
201201}
202202
203static void crvision_vdp_interrupt(int state)
203static void crvision_vdp_interrupt(running_machine *machine, int state)
204204{
205   cpunum_set_input_line(Machine, 0, INPUT_LINE_IRQ0, state);
205   cpunum_set_input_line(machine, 0, INPUT_LINE_IRQ0, state);
206206}
207207
208208static const TMS9928a_interface tms9918_intf =
src/mess/drivers/einstein.c
r2724r2725
402402
403403
404404/* interrupt state callback for ctc */
405static void einstein_ctc_interrupt(int state)
405static void einstein_ctc_interrupt(running_machine *machine, int state)
406406{
407407   logerror("ctc irq state: %02x\n",state);
408   cpunum_set_input_line(Machine, 0, 1, state);
408   cpunum_set_input_line(machine, 0, 1, state);
409409}
410410
411static void einstein_pio_interrupt(int state)
411static void einstein_pio_interrupt(running_machine *machine, int state)
412412{
413413   logerror("pio irq state: %02x\n",state);
414   cpunum_set_input_line(Machine, 0, 3, state);
414   cpunum_set_input_line(machine, 0, 3, state);
415415}
416416
417417static WRITE8_HANDLER(einstein_serial_transmit_clock)
src/mess/drivers/psx.c
r2724r2725
180180   int n_port = param;
181181   if( m_pad[ n_port ].n_state != PAD_STATE_IDLE )
182182   {
183      psx_sio_input( 0, PSX_SIO_IN_DSR, m_pad[ n_port ].b_ack * PSX_SIO_IN_DSR );
183      psx_sio_input( machine, 0, PSX_SIO_IN_DSR, m_pad[ n_port ].b_ack * PSX_SIO_IN_DSR );
184184      if( !m_pad[ n_port ].b_ack )
185185      {
186186         m_pad[ n_port ].b_ack = 1;
r2724r2725
217217   case PAD_STATE_READ:
218218      if( m_pad[ n_port ].b_lastclock && !b_clock )
219219      {
220         psx_sio_input( 0, PSX_SIO_IN_DATA, ( m_pad[ n_port ].n_shiftout & 1 ) * PSX_SIO_IN_DATA );
220         psx_sio_input( machine, 0, PSX_SIO_IN_DATA, ( m_pad[ n_port ].n_shiftout & 1 ) * PSX_SIO_IN_DATA );
221221         m_pad[ n_port ].n_shiftout >>= 1;
222222      }
223223      if( !m_pad[ n_port ].b_lastclock && b_clock )
r2724r2725
634634      if (psx_cdcmd)
635635         psx_cdcmd();
636636
637      psx_irq_set(0x0004);
637      psx_irq_set(machine, 0x0004);
638638   }
639639   else if( mem_mask == 0xff00ffff )
640640   {
src/mess/drivers/tutor.c
r2724r2725
135135static INTERRUPT_GEN( tutor_vblank_interrupt )
136136{
137137   /* No vblank interrupt? */
138   TMS9928A_interrupt();
138   TMS9928A_interrupt(machine);
139139}
140140
141141static const device_config *printer_fp(void)
src/mess/drivers/ti99_4p.c
r2724r2725
9595
9696   /* 1 port for config */
9797   PORT_START   /* config */
98      PORT_BIT( config_speech_mask << config_speech_bit, 1 << config_speech_bit, IPT_DIPSWITCH_NAME) PORT_NAME("Speech synthesis")
98      PORT_DIPNAME( config_speech_mask << config_speech_bit, 1 << config_speech_bit, "Speech synthesis")
9999         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
100100         PORT_DIPSETTING( 1 << config_speech_bit, DEF_STR( On ) )
101      PORT_BIT( config_fdc_mask << config_fdc_bit, fdc_kind_hfdc << config_fdc_bit, IPT_DIPSWITCH_NAME) PORT_NAME("Floppy disk controller")
101      PORT_DIPNAME( config_fdc_mask << config_fdc_bit, fdc_kind_hfdc << config_fdc_bit, "Floppy disk controller")
102102         PORT_DIPSETTING( fdc_kind_none << config_fdc_bit, DEF_STR( None ) )
103103         PORT_DIPSETTING( fdc_kind_TI << config_fdc_bit, "Texas Instruments SD" )
104104#if HAS_99CCFDC
r2724r2725
106106#endif
107107         PORT_DIPSETTING( fdc_kind_BwG << config_fdc_bit, "SNUG's BwG" )
108108         PORT_DIPSETTING( fdc_kind_hfdc << config_fdc_bit, "Myarc's HFDC" )
109      /*PORT_BIT( config_ide_mask << config_ide_bit, 1 << config_ide_bit, IPT_DIPSWITCH_NAME) PORT_NAME("Nouspickel's IDE card")
109      /*PORT_DIPNAME( config_ide_mask << config_ide_bit, 1 << config_ide_bit, IPT_DIPSWITCH_NAME) PORT_NAME("Nouspickel's IDE card")
110110            PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
111111            PORT_DIPSETTING( 1 << config_ide_bit, DEF_STR( On ) )*/
112      PORT_BIT( config_rs232_mask << config_rs232_bit, /*1 << config_rs232_bit*/0, IPT_DIPSWITCH_NAME) PORT_NAME("TI RS232 card")
112      PORT_DIPNAME( config_rs232_mask << config_rs232_bit, /*1 << config_rs232_bit*/0, "TI RS232 card")
113113         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
114114         PORT_DIPSETTING( 1 << config_rs232_bit, DEF_STR( On ) )
115      PORT_BIT( config_mecmouse_mask << config_mecmouse_bit, 0, IPT_DIPSWITCH_NAME) PORT_NAME("Mechatronics Mouse")
115      PORT_DIPNAME( config_mecmouse_mask << config_mecmouse_bit, 0, "Mechatronics Mouse")
116116         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
117117         PORT_DIPSETTING( 1 << config_mecmouse_bit, DEF_STR( On ) )
118      PORT_BIT( config_usbsm_mask << config_usbsm_bit, 1 << config_usbsm_bit, IPT_DIPSWITCH_NAME) PORT_NAME("Nouspickel's USB-SM card")
118      PORT_DIPNAME( config_usbsm_mask << config_usbsm_bit, 1 << config_usbsm_bit, "Nouspickel's USB-SM card")
119119         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
120120         PORT_DIPSETTING( 1 << config_usbsm_bit, DEF_STR( On ) )
121121
src/mess/drivers/pc.c
r2724r2725
11561156
11571157#if defined(ADLIB)
11581158/* irq line not connected to pc on adlib cards (and compatibles) */
1159static void pc_irqhandler(int linestate) {}
1159static void pc_irqhandler(running_machine *machine, int linestate) {}
11601160
11611161static const struct YM3812interface ym3812_interface =
11621162{
src/mess/drivers/ti99_4x.c
r2724r2725
105105
106106   /* 1 port for config */
107107   PORT_START   /* config */
108      PORT_BIT( config_xRAM_mask << config_xRAM_bit, xRAM_kind_TI << config_xRAM_bit, IPT_DIPSWITCH_NAME) PORT_NAME("RAM extension")
108      PORT_DIPNAME( config_xRAM_mask << config_xRAM_bit, xRAM_kind_TI << config_xRAM_bit, "RAM extension")
109109         PORT_DIPSETTING( xRAM_kind_none << config_xRAM_bit,            DEF_STR( None ) )
110110         PORT_DIPSETTING( xRAM_kind_TI << config_xRAM_bit,            "Texas Instruments 32kb")
111111         PORT_DIPSETTING( xRAM_kind_super_AMS << config_xRAM_bit,      "Super AMS 1Mb")
r2724r2725
113113         PORT_DIPSETTING( xRAM_kind_foundation_512k << config_xRAM_bit,   "Foundation 512kb")
114114         PORT_DIPSETTING( xRAM_kind_myarc_128k << config_xRAM_bit,      "Myarc look-alike 128kb")
115115         PORT_DIPSETTING( xRAM_kind_myarc_512k << config_xRAM_bit,      "Myarc look-alike 512kb")
116      PORT_BIT( config_speech_mask << config_speech_bit, 1 << config_speech_bit, IPT_DIPSWITCH_NAME) PORT_NAME("Speech synthesis")
116      PORT_DIPNAME( config_speech_mask << config_speech_bit, 1 << config_speech_bit, "Speech synthesis")
117117         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
118118         PORT_DIPSETTING( 1 << config_speech_bit, DEF_STR( On ) )
119      PORT_BIT( config_fdc_mask << config_fdc_bit, fdc_kind_hfdc << config_fdc_bit, IPT_DIPSWITCH_NAME) PORT_NAME("Floppy disk controller")
119      PORT_DIPNAME( config_fdc_mask << config_fdc_bit, fdc_kind_hfdc << config_fdc_bit, "Floppy disk controller")
120120         PORT_DIPSETTING( fdc_kind_none << config_fdc_bit, DEF_STR( None ) )
121121         PORT_DIPSETTING( fdc_kind_TI << config_fdc_bit, "Texas Instruments SD" )
122122#if HAS_99CCFDC
r2724r2725
124124#endif
125125         PORT_DIPSETTING( fdc_kind_BwG << config_fdc_bit, "SNUG's BwG" )
126126         PORT_DIPSETTING( fdc_kind_hfdc << config_fdc_bit, "Myarc's HFDC" )
127      PORT_BIT( config_ide_mask << config_ide_bit, 1 << config_ide_bit, IPT_DIPSWITCH_NAME) PORT_NAME("Nouspickel's IDE card")
127      PORT_DIPNAME( config_ide_mask << config_ide_bit, 1 << config_ide_bit, "Nouspickel's IDE card")
128128         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
129129         PORT_DIPSETTING( 1 << config_ide_bit, DEF_STR( On ) )
130      PORT_BIT( config_rs232_mask << config_rs232_bit, 1 << config_rs232_bit, IPT_DIPSWITCH_NAME) PORT_NAME("TI RS232 card")
130      PORT_DIPNAME( config_rs232_mask << config_rs232_bit, 1 << config_rs232_bit, "TI RS232 card")
131131         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
132132         PORT_DIPSETTING( 1 << config_rs232_bit, DEF_STR( On ) )
133      PORT_BIT( config_hsgpl_mask << config_hsgpl_bit, 0/*1 << config_hsgpl_bit*/, IPT_DIPSWITCH_NAME) PORT_NAME("SNUG HSGPL card")
133      PORT_DIPNAME( config_hsgpl_mask << config_hsgpl_bit, 0/*1 << config_hsgpl_bit*/, "SNUG HSGPL card")
134134         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
135135         PORT_DIPSETTING( 1 << config_hsgpl_bit, DEF_STR( On ) )
136      PORT_BIT( config_mecmouse_mask << config_mecmouse_bit, 0, IPT_DIPSWITCH_NAME) PORT_NAME("Mechatronics Mouse")
136      PORT_DIPNAME( config_mecmouse_mask << config_mecmouse_bit, 0, "Mechatronics Mouse")
137137         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
138138         PORT_DIPSETTING( 1 << config_mecmouse_bit, DEF_STR( On ) )
139      PORT_BIT( config_usbsm_mask << config_usbsm_bit, 1 << config_usbsm_bit, IPT_DIPSWITCH_NAME) PORT_NAME("Nouspickel's USB-SM card")
139      PORT_DIPNAME( config_usbsm_mask << config_usbsm_bit, 1 << config_usbsm_bit, "Nouspickel's USB-SM card")
140140         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
141141         PORT_DIPSETTING( 1 << config_usbsm_bit, DEF_STR( On ) )
142142
r2724r2725
245245
246246   /* 1 port for config */
247247   PORT_START   /* config */
248      PORT_BIT( config_xRAM_mask << config_xRAM_bit, xRAM_kind_TI << config_xRAM_bit, IPT_DIPSWITCH_NAME) PORT_NAME("RAM extension")
248      PORT_DIPNAME( config_xRAM_mask << config_xRAM_bit, xRAM_kind_TI << config_xRAM_bit, "RAM extension")
249249         PORT_DIPSETTING( xRAM_kind_none << config_xRAM_bit,            DEF_STR( None ) )
250250         PORT_DIPSETTING( xRAM_kind_TI << config_xRAM_bit,            "Texas Instruments 32kb")
251251         PORT_DIPSETTING( xRAM_kind_super_AMS << config_xRAM_bit,      "Super AMS 1Mb")
r2724r2725
253253         PORT_DIPSETTING( xRAM_kind_foundation_512k << config_xRAM_bit,   "Foundation 512kb")
254254         PORT_DIPSETTING( xRAM_kind_myarc_128k << config_xRAM_bit,      "Myarc look-alike 128kb")
255255         PORT_DIPSETTING( xRAM_kind_myarc_512k << config_xRAM_bit,      "Myarc look-alike 512kb")
256      PORT_BIT( config_speech_mask << config_speech_bit, 1 << config_speech_bit, IPT_DIPSWITCH_NAME) PORT_NAME("Speech synthesis")
256      PORT_DIPNAME( config_speech_mask << config_speech_bit, 1 << config_speech_bit, "Speech synthesis")
257257         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
258258         PORT_DIPSETTING( 1 << config_speech_bit, DEF_STR( On ) )
259      PORT_BIT( config_fdc_mask << config_fdc_bit, fdc_kind_hfdc << config_fdc_bit, IPT_DIPSWITCH_NAME) PORT_NAME("Floppy disk controller")
259      PORT_DIPNAME( config_fdc_mask << config_fdc_bit, fdc_kind_hfdc << config_fdc_bit, "Floppy disk controller")
260260         PORT_DIPSETTING( fdc_kind_none << config_fdc_bit, DEF_STR( None ) )
261261         PORT_DIPSETTING( fdc_kind_TI << config_fdc_bit, "Texas Instruments SD" )
262262#if HAS_99CCFDC
r2724r2725
264264#endif
265265         PORT_DIPSETTING( fdc_kind_BwG << config_fdc_bit, "SNUG's BwG" )
266266         PORT_DIPSETTING( fdc_kind_hfdc << config_fdc_bit, "Myarc's HFDC" )
267      PORT_BIT( config_ide_mask << config_ide_bit, /*1 << config_ide_bit*/0, IPT_DIPSWITCH_NAME) PORT_NAME("Nouspickel's IDE card")
267      PORT_DIPNAME( config_ide_mask << config_ide_bit, /*1 << config_ide_bit*/0, "Nouspickel's IDE card")
268268         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
269269         PORT_DIPSETTING( 1 << config_ide_bit, DEF_STR( On ) )
270      PORT_BIT( config_rs232_mask << config_rs232_bit, 1 << config_rs232_bit, IPT_DIPSWITCH_NAME) PORT_NAME("TI RS232 card")
270      PORT_DIPNAME( config_rs232_mask << config_rs232_bit, 1 << config_rs232_bit, "TI RS232 card")
271271         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
272272         PORT_DIPSETTING( 1 << config_rs232_bit, DEF_STR( On ) )
273      PORT_BIT( config_handsets_mask << config_handsets_bit, /*1 << config_handsets_bit*/0, IPT_DIPSWITCH_NAME) PORT_NAME("I/R remote handset")
273      PORT_DIPNAME( config_handsets_mask << config_handsets_bit, /*1 << config_handsets_bit*/0, "I/R remote handset")
274274         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
275275         PORT_DIPSETTING( 1 << config_handsets_bit, DEF_STR( On ) )
276      PORT_BIT( config_hsgpl_mask << config_hsgpl_bit, 0/*1 << config_hsgpl_bit*/, IPT_DIPSWITCH_NAME) PORT_NAME("SNUG HSGPL card")
276      PORT_DIPNAME( config_hsgpl_mask << config_hsgpl_bit, 0/*1 << config_hsgpl_bit*/, "SNUG HSGPL card")
277277         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
278278         PORT_DIPSETTING( 1 << config_hsgpl_bit, DEF_STR( On ) )
279      PORT_BIT( config_mecmouse_mask << config_mecmouse_bit, 0, IPT_DIPSWITCH_NAME) PORT_NAME("Mechatronics Mouse")
279      PORT_DIPNAME( config_mecmouse_mask << config_mecmouse_bit, 0, "Mechatronics Mouse")
280280         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
281281         PORT_DIPSETTING( 1 << config_mecmouse_bit, DEF_STR( On ) )
282      PORT_BIT( config_usbsm_mask << config_usbsm_bit, 1 << config_usbsm_bit, IPT_DIPSWITCH_NAME) PORT_NAME("Nouspickel's USB-SM card")
282      PORT_DIPNAME( config_usbsm_mask << config_usbsm_bit, 1 << config_usbsm_bit, "Nouspickel's USB-SM card")
283283         PORT_DIPSETTING( 0x0000, DEF_STR( Off ) )
284284         PORT_DIPSETTING( 1 << config_usbsm_bit, DEF_STR( On ) )
285285
src/mess/drivers/ip20.c
r2724r2725
559559   nRTC_Temp = 0;
560560}
561561
562static void scsi_irq(int state)
562static void scsi_irq(running_machine *machine, int state)
563563{
564564}
565565
src/mess/drivers/bbcbc.c
r2724r2725
2828   AM_RANGE(0x81, 0x81) AM_READWRITE(TMS9928A_register_r, TMS9928A_register_w)
2929ADDRESS_MAP_END
3030
31static void tms_interrupt(int dummy)
31static void tms_interrupt(running_machine *machine, int dummy)
3232{
33   cpunum_set_input_line(Machine, 0, 0, HOLD_LINE);
33   cpunum_set_input_line(machine, 0, 0, HOLD_LINE);
3434}
3535
3636static INTERRUPT_GEN( bbcbc_interrupt )
3737{
38    TMS9928A_interrupt();
38    TMS9928A_interrupt(machine);
3939}
4040
4141static INPUT_PORTS_START( bbcbc )
docs/messnew.txt
r2724r2725
8181
8282Source Changes:
8383----------------
84- The core is based on MAME 0.125u1.  This incorporates all features of the
84- The core is based on MAME 0.125u2.  This incorporates all features of the
8585  update to this core.  [MAME team]
8686
8787- Fixed performance problems with -triplebuffer.  (bug #1539) [Justin Kerk]

Previous 15994 Revisions Next


© 1998-2018 The MESS Team