Previous 15994 Revisions Next

r10428 Monday 14th February, 2011 at 10:29:24 UTC by Miodrag Milanović
Sync with MAME (hash rewrite)
[src/emu]audit.c audit.h clifront.c devimage.c diimage.c diimage.h emu.h fileio.c fileio.h hash.c hash.h hashfile.c hashfile.h info.c romload.c romload.h softlist.c validity.c video.c
[src/emu/cpu/sh2]sh2.c sh2.h sh2comn.c sh2comn.h
[src/emu/imagedev]multcart.c
[src/emu/sound]okiadpcm.c* okiadpcm.h* okim9810.c okim9810.h sound.mak
[src/emu/video]tms9928a.c
[src/mame]mame.mak mamedriv.c
[src/mame/audio]cchasm.c cinemat.c cps3.c
[src/mame/drivers]86lions.c 88games.c aristmk4.c aristmk5.c asterix.c atarig1.c atarig42.c atarigt.c atarigx2.c battlera.c beezer.c bfcobra.c bfm_sc1.c bfm_sc2.c bfmsys85.c bingoc.c bmcbowl.c caswin.c cchasm.c cinemat.c coolridr.c cps3.c darkseal.c dec0.c deco32.c deco_ld.c deco_mlc.c deshoros.c destroyr.c djmain.c dlair.c fastfred.c firebeat.c gpworld.c gticlub.c hexion.c hornet.c koftball.c konamigv.c konamim2.c ksys573.c madalien.c micro3d.c mitchell.c model1.c model2.c model3.c mystwarr.c nwk-tr.c pcktgal.c powerins.c progolf.c qdrmfgp.c rmhaihai.c scobra.c segag80v.c segas32.c sigmab98.c srumbler.c sshangha.c stadhero.c suprloco.c system1.c taitogn.c tigeroad.c timetrv.c tp84.c tryout.c tumbleb.c twin16.c twinkle.c ultrsprt.c viper.c vulgus.c wecleman.c zn.c zr107.c
[src/mame/includes]88games.h atarig1.h atarig42.h atarigt.h atarigx2.h battlera.h beezer.h cchasm.h cinemat.h cps3.h darkseal.h dec0.h deco32.h deco_mlc.h djmain.h fastfred.h hexion.h madalien.h micro3d.h mitchell.h model1.h model2.h model3.h mystwarr.h pcktgal.h powerins.h qdrmfgp.h segag80v.h segas32.h srumbler.h sshangha.h stadhero.h suprloco.h system1.h tigeroad.h tp84.h tryout.h tumbleb.h twin16.h vulgus.h wecleman.h
[src/mame/machine]atarigen.h beezer.c dec0.c megadriv.c micro3d.c model1.c model3.c psx.c segas32.c
[src/mame/video]atarig1.c atarig42.c atarigt.c atarigx2.c atarirle.c atarirle.h battlera.c beezer.c bfm_dm01.c bfm_dm01.h cchasm.c cinemat.c darkseal.c dec0.c deco32.c deco_mlc.c djmain.c fastfred.c gticlub.c gticlub.h hexion.c konamigx.c konamiic.c konamiic.h m3raster.c madalien.c model1.c model2.c model2rd.c model3.c mystwarr.c pcktgal.c powerins.c qdrmfgp.c segag80v.c segas32.c srumbler.c sshangha.c stadhero.c suprloco.c system1.c tigeroad.c tp84.c tryout.c twin16.c vulgus.c wecleman.c
[src/mess/drivers]a7800.c nes.c pce.c
[src/mess/includes]a7800.h nes.h
[src/mess/machine]a7800.c lynx.c nes.c
[src/osd/winui]softwarepicker.c swconfig.c treeview.c

src/mame/audio/cchasm.c
r10427r10428
1111#include "sound/ay8910.h"
1212#include "sound/dac.h"
1313
14static int sound_flags;
15static int coin_flag;
16static device_t *ctc;
1714
1815WRITE8_HANDLER( cchasm_reset_coin_flag_w )
1916{
20   if (coin_flag)
17   cchasm_state *state = space->machine->driver_data<cchasm_state>();
18   if (state->coin_flag)
2119   {
22      coin_flag = 0;
23      z80ctc_trg0_w(ctc, coin_flag);
20      state->coin_flag = 0;
21      z80ctc_trg0_w(state->ctc, state->coin_flag);
2422   }
2523}
2624
2725INPUT_CHANGED( cchasm_set_coin_flag )
2826{
29   if (!newval && !coin_flag)
27   cchasm_state *state = field->port->machine->driver_data<cchasm_state>();
28   if (!newval && !state->coin_flag)
3029   {
31      coin_flag = 1;
32      z80ctc_trg0_w(ctc, coin_flag);
30      state->coin_flag = 1;
31      z80ctc_trg0_w(state->ctc, state->coin_flag);
3332   }
3433}
3534
3635READ8_HANDLER( cchasm_coin_sound_r )
3736{
37   cchasm_state *state = space->machine->driver_data<cchasm_state>();
3838   UINT8 coin = (input_port_read(space->machine, "IN3") >> 4) & 0x7;
39   return sound_flags | (coin_flag << 3) | coin;
39   return state->sound_flags | (state->coin_flag << 3) | coin;
4040}
4141
4242READ8_HANDLER( cchasm_soundlatch2_r )
4343{
44   sound_flags &= ~0x80;
45   z80ctc_trg2_w(ctc, 0);
44   cchasm_state *state = space->machine->driver_data<cchasm_state>();
45   state->sound_flags &= ~0x80;
46   z80ctc_trg2_w(state->ctc, 0);
4647   return soundlatch2_r(space, offset);
4748}
4849
4950WRITE8_HANDLER( cchasm_soundlatch4_w )
5051{
51   sound_flags |= 0x40;
52   cchasm_state *state = space->machine->driver_data<cchasm_state>();
53   state->sound_flags |= 0x40;
5254   soundlatch4_w(space, offset, data);
5355   cputag_set_input_line(space->machine, "maincpu", 1, HOLD_LINE);
5456}
5557
5658WRITE16_HANDLER( cchasm_io_w )
5759{
58    static int led;
60   cchasm_state *state = space->machine->driver_data<cchasm_state>();
61   //static int led;
5962
6063   if (ACCESSING_BITS_8_15)
6164   {
r10427r10428
6669         soundlatch_w (space, offset, data);
6770         break;
6871      case 1:
69         sound_flags |= 0x80;
72         state->sound_flags |= 0x80;
7073         soundlatch2_w (space, offset, data);
71         z80ctc_trg2_w(ctc, 1);
74         z80ctc_trg2_w(state->ctc, 1);
7275         cputag_set_input_line(space->machine, "audiocpu", INPUT_LINE_NMI, PULSE_LINE);
7376         break;
7477      case 2:
75         led = data;
78         //led = data;
7679         break;
7780      }
7881   }
r10427r10428
8083
8184READ16_HANDLER( cchasm_io_r )
8285{
86   cchasm_state *state = space->machine->driver_data<cchasm_state>();
8387   switch (offset & 0xf)
8488   {
8589   case 0x0:
8690      return soundlatch3_r (space, offset) << 8;
8791   case 0x1:
88      sound_flags &= ~0x40;
92      state->sound_flags &= ~0x40;
8993      return soundlatch4_r (space,offset) << 8;
9094   case 0x2:
91      return (sound_flags| (input_port_read(space->machine, "IN3") & 0x07) | 0x08) << 8;
95      return (state->sound_flags| (input_port_read(space->machine, "IN3") & 0x07) | 0x08) << 8;
9296   case 0x5:
9397      return input_port_read(space->machine, "IN2") << 8;
9498   case 0x8:
r10427r10428
98102   }
99103}
100104
101static int channel_active[2];
102static int output[2];
103105
104106static WRITE_LINE_DEVICE_HANDLER( ctc_timer_1_w )
105107{
108   cchasm_state *drvstate = device->machine->driver_data<cchasm_state>();
106109   if (state) /* rising edge */
107110   {
108      output[0] ^= 0x7f;
109      channel_active[0] = 1;
110      dac_data_w(device->machine->device("dac1"), output[0]);
111      drvstate->output[0] ^= 0x7f;
112      drvstate->channel_active[0] = 1;
113      dac_data_w(device->machine->device("dac1"), drvstate->output[0]);
111114   }
112115}
113116
114117static WRITE_LINE_DEVICE_HANDLER( ctc_timer_2_w )
115118{
119   cchasm_state *drvstate = device->machine->driver_data<cchasm_state>();
116120   if (state) /* rising edge */
117121   {
118      output[1] ^= 0x7f;
119      channel_active[1] = 1;
120      dac_data_w(device->machine->device("dac2"), output[0]);
122      drvstate->output[1] ^= 0x7f;
123      drvstate->channel_active[1] = 1;
124      dac_data_w(device->machine->device("dac2"), drvstate->output[0]);
121125   }
122126}
123127
r10427r10428
132136
133137SOUND_START( cchasm )
134138{
135   coin_flag = 0;
136    sound_flags = 0;
137    output[0] = 0; output[1] = 0;
139   cchasm_state *state = machine->driver_data<cchasm_state>();
140   state->coin_flag = 0;
141   state->sound_flags = 0;
142   state->output[0] = 0; state->output[1] = 0;
138143
139   ctc = machine->device("ctc");
144   state->ctc = machine->device("ctc");
140145}
src/mame/audio/cps3.c
r10427r10428
4040
4141   // the actual 'user5' region only exists on the nocd sets, on the others it's allocated in the initialization.
4242   // it's a shared gfx/sound region, so can't be allocated as part of the sound device.
43   state->base = (INT8*)cps3_user5region;
43   state->base = (INT8*)device->machine->driver_data<cps3_state>()->user5region;
4444
4545   /* Clear the buffers */
4646   memset(outputs[0], 0, samples*sizeof(*outputs[0]));
src/mame/audio/cinemat.c
r10427r10428
3838#define SOUNDVAL_RISING_EDGE(bit)      RISING_EDGE(bit, bits_changed, sound_val)
3939#define SOUNDVAL_FALLING_EDGE(bit)      FALLING_EDGE(bit, bits_changed, sound_val)
4040
41#define SHIFTREG_RISING_EDGE(bit)      RISING_EDGE(bit, (last_shift ^ current_shift), current_shift)
42#define SHIFTREG_FALLING_EDGE(bit)      FALLING_EDGE(bit, (last_shift ^ current_shift), current_shift)
41#define SHIFTREG_RISING_EDGE(bit)      RISING_EDGE(bit, (state->last_shift ^ state->current_shift), state->current_shift)
42#define SHIFTREG_FALLING_EDGE(bit)      FALLING_EDGE(bit, (state->last_shift ^ state->current_shift), state->current_shift)
4343
44#define SHIFTREG2_RISING_EDGE(bit)      RISING_EDGE(bit, (last_shift2 ^ current_shift), current_shift)
45#define SHIFTREG2_FALLING_EDGE(bit)      FALLING_EDGE(bit, (last_shift2 ^ current_shift), current_shift)
44#define SHIFTREG2_RISING_EDGE(bit)      RISING_EDGE(bit, (state->last_shift2 ^ state->current_shift), state->current_shift)
45#define SHIFTREG2_FALLING_EDGE(bit)      FALLING_EDGE(bit, (state->last_shift2 ^ state->current_shift), state->current_shift)
4646
4747
4848
r10427r10428
5353 *************************************/
5454
5555static void (*sound_handler)(running_machine *,UINT8 sound_val, UINT8 bits_changed);
56static UINT8 sound_control;
5756
5857/* general shift register variables */
59static UINT32 current_shift;
60static UINT32 last_shift;
61static UINT32 last_shift2;
62static UINT32 current_pitch;
63static UINT32 last_frame;
6458
6559/* Rockola sound variables */
66static UINT8 sound_fifo[16];
67static UINT8 sound_fifo_in;
68static UINT8 sound_fifo_out;
69static UINT8 last_portb_write;
7060
7161
7262
r10427r10428
7868
7969WRITE8_HANDLER( cinemat_sound_control_w )
8070{
81   UINT8 oldval = sound_control;
71   cinemat_state *state = space->machine->driver_data<cinemat_state>();
72   UINT8 oldval = state->sound_control;
8273
8374   /* form an 8-bit value with the new bit */
84   sound_control = (sound_control & ~(1 << offset)) | ((data & 1) << offset);
75   state->sound_control = (state->sound_control & ~(1 << offset)) | ((data & 1) << offset);
8576
8677   /* if something changed, call the sound subroutine */
87   if ((sound_control != oldval) && sound_handler)
88      (*sound_handler)(space->machine, sound_control, sound_control ^ oldval);
78   if ((state->sound_control != oldval) && sound_handler)
79      (*sound_handler)(space->machine, state->sound_control, state->sound_control ^ oldval);
8980}
9081
9182
r10427r10428
9889
9990static MACHINE_START( generic )
10091{
92   cinemat_state *state = machine->driver_data<cinemat_state>();
10193    /* register for save states */
102    state_save_register_global(machine, sound_control);
103    state_save_register_global(machine, current_shift);
104    state_save_register_global(machine, last_shift);
105    state_save_register_global(machine, last_shift2);
106    state_save_register_global(machine, current_pitch);
107    state_save_register_global(machine, last_frame);
108    state_save_register_global_array(machine, sound_fifo);
109    state_save_register_global(machine, sound_fifo_in);
110    state_save_register_global(machine, sound_fifo_out);
111    state_save_register_global(machine, last_portb_write);
94    state_save_register_global(machine, state->sound_control);
95    state_save_register_global(machine, state->current_shift);
96    state_save_register_global(machine, state->last_shift);
97    state_save_register_global(machine, state->last_shift2);
98    state_save_register_global(machine, state->current_pitch);
99    state_save_register_global(machine, state->last_frame);
100    state_save_register_global_array(machine, state->sound_fifo);
101    state_save_register_global(machine, state->sound_fifo_in);
102    state_save_register_global(machine, state->sound_fifo_out);
103    state_save_register_global(machine, state->last_portb_write);
112104}
113105
114106
115107static void generic_init(running_machine *machine, void (*callback)(running_machine *,UINT8, UINT8))
116108{
109   cinemat_state *state = machine->driver_data<cinemat_state>();
117110   /* call the standard init */
118111   MACHINE_RESET_CALL(cinemat);
119112
r10427r10428
121114   sound_handler = callback;
122115
123116   /* reset sound control */
124   sound_control = 0x9f;
117   state->sound_control = 0x9f;
125118
126119   /* reset shift register values */
127    current_shift = 0xffff;
128    last_shift = 0xffff;
129    last_shift2 = 0xffff;
120    state->current_shift = 0xffff;
121    state->last_shift = 0xffff;
122    state->last_shift2 = 0xffff;
130123
131124   /* reset frame counters */
132    last_frame = 0;
125    state->last_frame = 0;
133126
134127   /* reset Star Castle pitch */
135    current_pitch = 0x10000;
128    state->current_pitch = 0x10000;
136129}
137130
138131
r10427r10428
299292
300293static void speedfrk_sound_w(running_machine *machine, UINT8 sound_val, UINT8 bits_changed)
301294{
295   cinemat_state *state = machine->driver_data<cinemat_state>();
302296   device_t *samples = machine->device("samples");
303297
304298   /* on the falling edge of bit 0x08, clock the inverse of bit 0x04 into the top of the shiftreg */
305299   if (SOUNDVAL_FALLING_EDGE(0x08))
306300   {
307      current_shift = ((current_shift >> 1) & 0x7fff) | ((~sound_val << 13) & 1);
301      state->current_shift = ((state->current_shift >> 1) & 0x7fff) | ((~sound_val << 13) & 1);
308302      /* high 12 bits control the frequency - counts from value to $FFF, carry triggers */
309303      /* another counter */
310304
r10427r10428
513507
514508static void tailg_sound_w(running_machine *machine, UINT8 sound_val, UINT8 bits_changed)
515509{
510   cinemat_state *state = machine->driver_data<cinemat_state>();
516511   /* the falling edge of bit 0x10 clocks bit 0x08 into the mux selected by bits 0x07 */
517512   if (SOUNDVAL_FALLING_EDGE(0x10))
518513   {
519514      device_t *samples = machine->device("samples");
520515
521516      /* update the shift register (actually just a simple mux) */
522      current_shift = (current_shift & ~(1 << (sound_val & 7))) | (((sound_val >> 3) & 1) << (sound_val & 7));
517      state->current_shift = (state->current_shift & ~(1 << (sound_val & 7))) | (((sound_val >> 3) & 1) << (sound_val & 7));
523518
524519      /* explosion - falling edge */
525520      if (SHIFTREG_FALLING_EDGE(0x01))
r10427r10428
552547         sample_start(samples, 5, 5, 0);
553548
554549      /* LED */
555      set_led_status(machine, 0, current_shift & 0x40);
550      set_led_status(machine, 0, state->current_shift & 0x40);
556551
557552      /* remember the previous value */
558      last_shift = current_shift;
553      state->last_shift = state->current_shift;
559554   }
560555}
561556
r10427r10428
674669
675670static void armora_sound_w(running_machine *machine, UINT8 sound_val, UINT8 bits_changed)
676671{
672   cinemat_state *state = machine->driver_data<cinemat_state>();
677673   device_t *samples = machine->device("samples");
678674
679675   /* on the rising edge of bit 0x10, clock bit 0x80 into the shift register */
680676   if (SOUNDVAL_RISING_EDGE(0x10))
681      current_shift = ((current_shift >> 1) & 0x7f) | (sound_val & 0x80);
677      state->current_shift = ((state->current_shift >> 1) & 0x7f) | (sound_val & 0x80);
682678
683679   /* execute on the rising edge of bit 0x01 */
684680   if (SOUNDVAL_RISING_EDGE(0x01))
r10427r10428
702698         sample_start(samples, 3, 3, 0);
703699
704700      /* remember the previous value */
705      last_shift = current_shift;
701      state->last_shift = state->current_shift;
706702   }
707703
708704   /* tank sound - 0=on, 1=off */
r10427r10428
776772
777773static void ripoff_sound_w(running_machine *machine, UINT8 sound_val, UINT8 bits_changed)
778774{
775   cinemat_state *state = machine->driver_data<cinemat_state>();
779776   device_t *samples = machine->device("samples");
780777
781778   /* on the rising edge of bit 0x02, clock bit 0x01 into the shift register */
782779   if (SOUNDVAL_RISING_EDGE(0x02))
783      current_shift = ((current_shift >> 1) & 0x7f) | ((sound_val << 7) & 0x80);
780      state->current_shift = ((state->current_shift >> 1) & 0x7f) | ((sound_val << 7) & 0x80);
784781
785782   /* execute on the rising edge of bit 0x04 */
786783   if (SOUNDVAL_RISING_EDGE(0x04))
787784   {
788785      /* background - 0=on, 1=off, selected by bits 0x38 */
789      if ((((current_shift ^ last_shift) & 0x38) && !(current_shift & 0x04)) || SHIFTREG_FALLING_EDGE(0x04))
790         sample_start(samples, 5, 5 + ((current_shift >> 5) & 7), 1);
786      if ((((state->current_shift ^ state->last_shift) & 0x38) && !(state->current_shift & 0x04)) || SHIFTREG_FALLING_EDGE(0x04))
787         sample_start(samples, 5, 5 + ((state->current_shift >> 5) & 7), 1);
791788      if (SHIFTREG_RISING_EDGE(0x04))
792789         sample_stop(samples, 5);
793790
r10427r10428
802799         sample_stop(samples, 1);
803800
804801      /* remember the previous value */
805      last_shift = current_shift;
802      state->last_shift = state->current_shift;
806803   }
807804
808805   /* torpedo - falling edge */
r10427r10428
864861
865862static void starcas_sound_w(running_machine *machine, UINT8 sound_val, UINT8 bits_changed)
866863{
864   cinemat_state *state = machine->driver_data<cinemat_state>();
867865   device_t *samples = machine->device("samples");
868866   UINT32 target_pitch;
869867
870868   /* on the rising edge of bit 0x10, clock bit 0x80 into the shift register */
871869   if (SOUNDVAL_RISING_EDGE(0x10))
872      current_shift = ((current_shift >> 1) & 0x7f) | (sound_val & 0x80);
870      state->current_shift = ((state->current_shift >> 1) & 0x7f) | (sound_val & 0x80);
873871
874872   /* execute on the rising edge of bit 0x01 */
875873   if (SOUNDVAL_RISING_EDGE(0x01))
r10427r10428
901899         sample_stop(samples, 4);
902900
903901      /* latch the drone pitch */
904      target_pitch = (current_shift & 7) + ((current_shift & 2) << 2);
902      target_pitch = (state->current_shift & 7) + ((state->current_shift & 2) << 2);
905903        target_pitch = 0x5800 + (target_pitch << 12);
906904
907905        /* once per frame slide the pitch toward the target */
908        if (machine->primary_screen->frame_number() > last_frame)
906        if (machine->primary_screen->frame_number() > state->last_frame)
909907        {
910            if (current_pitch > target_pitch)
911                current_pitch -= 225;
912            if (current_pitch < target_pitch)
913                current_pitch += 150;
914            sample_set_freq(samples, 4, current_pitch);
915            last_frame = machine->primary_screen->frame_number();
908            if (state->current_pitch > target_pitch)
909                state->current_pitch -= 225;
910            if (state->current_pitch < target_pitch)
911                state->current_pitch += 150;
912            sample_set_freq(samples, 4, state->current_pitch);
913            state->last_frame = machine->primary_screen->frame_number();
916914        }
917915
918916      /* remember the previous value */
919      last_shift = current_shift;
917      state->last_shift = state->current_shift;
920918   }
921919
922920   /* loud explosion - falling edge */
r10427r10428
978976
979977static void solarq_sound_w(running_machine *machine, UINT8 sound_val, UINT8 bits_changed)
980978{
979   cinemat_state *state = machine->driver_data<cinemat_state>();
981980   device_t *samples = machine->device("samples");
982   static float target_volume, current_volume;
983981
984982   /* on the rising edge of bit 0x10, clock bit 0x80 into the shift register */
985983   if (SOUNDVAL_RISING_EDGE(0x10))
986      current_shift = ((current_shift >> 1) & 0x7fff) | ((sound_val << 8) & 0x8000);
984      state->current_shift = ((state->current_shift >> 1) & 0x7fff) | ((sound_val << 8) & 0x8000);
987985
988986   /* execute on the rising edge of bit 0x02 */
989987   if (SOUNDVAL_RISING_EDGE(0x02))
990988   {
991989      /* only the upper 8 bits matter */
992      current_shift >>= 8;
990      state->current_shift >>= 8;
993991
994992      /* loud explosion - falling edge */
995993      if (SHIFTREG_FALLING_EDGE(0x80))
r10427r10428
10021000      /* thrust - 0=on, 1=off */
10031001      if (SHIFTREG_FALLING_EDGE(0x20))
10041002      {
1005         target_volume = 1.0;
1003         state->target_volume = 1.0;
10061004         if (!sample_playing(samples, 2))
10071005            sample_start(samples, 2, 2, 1);
10081006      }
10091007      if (SHIFTREG_RISING_EDGE(0x20))
1010         target_volume = 0;
1008         state->target_volume = 0;
10111009
10121010      /* ramp the thrust volume */
1013        if (sample_playing(samples, 2) && machine->primary_screen->frame_number() > last_frame)
1011        if (sample_playing(samples, 2) && machine->primary_screen->frame_number() > state->last_frame)
10141012        {
1015            if (current_volume > target_volume)
1016                current_volume -= 0.078f;
1017            if (current_volume < target_volume)
1018                current_volume += 0.078f;
1019            if (current_volume > 0)
1020                sample_set_volume(samples, 2, current_volume);
1013            if (state->current_volume > state->target_volume)
1014                state->current_volume -= 0.078f;
1015            if (state->current_volume < state->target_volume)
1016                state->current_volume += 0.078f;
1017            if (state->current_volume > 0)
1018                sample_set_volume(samples, 2, state->current_volume);
10211019            else
10221020                sample_stop(samples, 2);
1023            last_frame = machine->primary_screen->frame_number();
1021            state->last_frame = machine->primary_screen->frame_number();
10241022        }
10251023
10261024      /* fire - falling edge */
r10427r10428
10421040         sample_start(samples, 6, 6, 0);
10431041
10441042      /* remember the previous value */
1045      last_shift = current_shift;
1043      state->last_shift = state->current_shift;
10461044   }
10471045
10481046   /* clock music data on the rising edge of bit 0x01 */
r10427r10428
10571055         sample_stop(samples, 7);
10581056
10591057      /* set the frequency */
1060      freq = 56818.181818 / (4096 - (current_shift & 0xfff));
1058      freq = 56818.181818 / (4096 - (state->current_shift & 0xfff));
10611059      sample_set_freq(samples, 7, 44100 * freq / 1050);
10621060
10631061      /* set the volume */
1064      vol = (~current_shift >> 12) & 7;
1062      vol = (~state->current_shift >> 12) & 7;
10651063      sample_set_volume(samples, 7, vol / 7.0);
10661064
10671065      /* remember the previous value */
1068      last_shift2 = current_shift;
1066      state->last_shift2 = state->current_shift;
10691067    }
10701068}
10711069
r10427r10428
11191117
11201118static void boxingb_sound_w(running_machine *machine, UINT8 sound_val, UINT8 bits_changed)
11211119{
1120   cinemat_state *state = machine->driver_data<cinemat_state>();
11221121   device_t *samples = machine->device("samples");
11231122
11241123   /* on the rising edge of bit 0x10, clock bit 0x80 into the shift register */
11251124   if (SOUNDVAL_RISING_EDGE(0x10))
1126      current_shift = ((current_shift >> 1) & 0x7fff) | ((sound_val << 8) & 0x8000);
1125      state->current_shift = ((state->current_shift >> 1) & 0x7fff) | ((sound_val << 8) & 0x8000);
11271126
11281127   /* execute on the rising edge of bit 0x02 */
11291128   if (SOUNDVAL_RISING_EDGE(0x02))
11301129   {
11311130      /* only the upper 8 bits matter */
1132      current_shift >>= 8;
1131      state->current_shift >>= 8;
11331132
11341133      /* soft explosion - falling edge */
11351134      if (SHIFTREG_FALLING_EDGE(0x80))
r10427r10428
11661165         sample_start(samples, 7, 7, 0);
11671166
11681167      /* remember the previous value */
1169      last_shift = current_shift;
1168      state->last_shift = state->current_shift;
11701169   }
11711170
11721171   /* clock music data on the rising edge of bit 0x01 */
r10427r10428
11811180         sample_stop(samples, 8);
11821181
11831182      /* set the frequency */
1184      freq = 56818.181818 / (4096 - (current_shift & 0xfff));
1183      freq = 56818.181818 / (4096 - (state->current_shift & 0xfff));
11851184      sample_set_freq(samples, 8, 44100 * freq / 1050);
11861185
11871186      /* set the volume */
1188      vol = (~current_shift >> 12) & 3;
1187      vol = (~state->current_shift >> 12) & 3;
11891188      sample_set_volume(samples, 8, vol / 3.0);
11901189
11911190        /* cannon - falling edge */
r10427r10428
11931192           sample_start(samples, 9, 9, 0);
11941193
11951194      /* remember the previous value */
1196      last_shift2 = current_shift;
1195      state->last_shift2 = state->current_shift;
11971196    }
11981197
11991198   /* bounce - rising edge */
r10427r10428
12511250
12521251static void wotw_sound_w(running_machine *machine, UINT8 sound_val, UINT8 bits_changed)
12531252{
1253   cinemat_state *state = machine->driver_data<cinemat_state>();
12541254   device_t *samples = machine->device("samples");
12551255   UINT32 target_pitch;
12561256
12571257   /* on the rising edge of bit 0x10, clock bit 0x80 into the shift register */
12581258   if (SOUNDVAL_RISING_EDGE(0x10))
1259      current_shift = ((current_shift >> 1) & 0x7f) | (sound_val & 0x80);
1259      state->current_shift = ((state->current_shift >> 1) & 0x7f) | (sound_val & 0x80);
12601260
12611261   /* execute on the rising edge of bit 0x01 */
12621262   if (SOUNDVAL_RISING_EDGE(0x01))
r10427r10428
12881288         sample_stop(samples, 4);
12891289
12901290      /* latch the drone pitch */
1291      target_pitch = (current_shift & 7) + ((current_shift & 2) << 2);
1291      target_pitch = (state->current_shift & 7) + ((state->current_shift & 2) << 2);
12921292        target_pitch = 0x10000 + (target_pitch << 12);
12931293
12941294        /* once per frame slide the pitch toward the target */
1295        if (machine->primary_screen->frame_number() > last_frame)
1295        if (machine->primary_screen->frame_number() > state->last_frame)
12961296        {
1297            if (current_pitch > target_pitch)
1298                current_pitch -= 300;
1299            if (current_pitch < target_pitch)
1300                current_pitch += 200;
1301            sample_set_freq(samples, 4, current_pitch);
1302            last_frame = machine->primary_screen->frame_number();
1297            if (state->current_pitch > target_pitch)
1298                state->current_pitch -= 300;
1299            if (state->current_pitch < target_pitch)
1300                state->current_pitch += 200;
1301            sample_set_freq(samples, 4, state->current_pitch);
1302            state->last_frame = machine->primary_screen->frame_number();
13031303        }
13041304
13051305      /* remember the previous value */
1306      last_shift = current_shift;
1306      state->last_shift = state->current_shift;
13071307   }
13081308
13091309   /* loud explosion - falling edge */
r10427r10428
13651365
13661366static void wotwc_sound_w(running_machine *machine, UINT8 sound_val, UINT8 bits_changed)
13671367{
1368   cinemat_state *state = machine->driver_data<cinemat_state>();
13681369   device_t *samples = machine->device("samples");
13691370   UINT32 target_pitch;
13701371
13711372   /* on the rising edge of bit 0x10, clock bit 0x80 into the shift register */
13721373   if (SOUNDVAL_RISING_EDGE(0x10))
1373      current_shift = ((current_shift >> 1) & 0x7f) | (sound_val & 0x80);
1374      state->current_shift = ((state->current_shift >> 1) & 0x7f) | (sound_val & 0x80);
13741375
13751376   /* execute on the rising edge of bit 0x01 */
13761377   if (SOUNDVAL_RISING_EDGE(0x01))
r10427r10428
14021403         sample_stop(samples, 4);
14031404
14041405      /* latch the drone pitch */
1405      target_pitch = (current_shift & 7) + ((current_shift & 2) << 2);
1406      target_pitch = (state->current_shift & 7) + ((state->current_shift & 2) << 2);
14061407        target_pitch = 0x10000 + (target_pitch << 12);
14071408
14081409        /* once per frame slide the pitch toward the target */
1409        if (machine->primary_screen->frame_number() > last_frame)
1410        if (machine->primary_screen->frame_number() > state->last_frame)
14101411        {
1411            if (current_pitch > target_pitch)
1412                current_pitch -= 300;
1413            if (current_pitch < target_pitch)
1414                current_pitch += 200;
1415            sample_set_freq(samples, 4, current_pitch);
1416            last_frame = machine->primary_screen->frame_number();
1412            if (state->current_pitch > target_pitch)
1413                state->current_pitch -= 300;
1414            if (state->current_pitch < target_pitch)
1415                state->current_pitch += 200;
1416            sample_set_freq(samples, 4, state->current_pitch);
1417            state->last_frame = machine->primary_screen->frame_number();
14171418        }
14181419
14191420      /* remember the previous value */
1420      last_shift = current_shift;
1421      state->last_shift = state->current_shift;
14211422   }
14221423
14231424   /* loud explosion - falling edge */
r10427r10428
14591460
14601461static TIMER_CALLBACK( synced_sound_w )
14611462{
1462   sound_fifo[sound_fifo_in] = param;
1463   sound_fifo_in = (sound_fifo_in + 1) % 16;
1463   cinemat_state *state = machine->driver_data<cinemat_state>();
1464   state->sound_fifo[state->sound_fifo_in] = param;
1465   state->sound_fifo_in = (state->sound_fifo_in + 1) % 16;
14641466}
14651467
14661468
r10427r10428
14771479
14781480static READ8_DEVICE_HANDLER( sound_porta_r )
14791481{
1482   cinemat_state *state = device->machine->driver_data<cinemat_state>();
14801483   /* bits 0-3 are the sound data; bit 4 is the data ready */
1481   return sound_fifo[sound_fifo_out] | ((sound_fifo_in != sound_fifo_out) << 4);
1484   return state->sound_fifo[state->sound_fifo_out] | ((state->sound_fifo_in != state->sound_fifo_out) << 4);
14821485}
14831486
14841487
14851488static READ8_DEVICE_HANDLER( sound_portb_r )
14861489{
1487   return last_portb_write;
1490   cinemat_state *state = device->machine->driver_data<cinemat_state>();
1491   return state->last_portb_write;
14881492}
14891493
14901494
14911495static WRITE8_DEVICE_HANDLER( sound_portb_w )
14921496{
1497   cinemat_state *state = device->machine->driver_data<cinemat_state>();
14931498   /* watch for a 0->1 edge on bit 0 ("shift out") to advance the data pointer */
1494   if ((data & 1) != (last_portb_write & 1) && (data & 1) != 0)
1495      sound_fifo_out = (sound_fifo_out + 1) % 16;
1499   if ((data & 1) != (state->last_portb_write & 1) && (data & 1) != 0)
1500      state->sound_fifo_out = (state->sound_fifo_out + 1) % 16;
14961501
14971502   /* watch for a 0->1 edge of bit 1 ("hard reset") to reset the FIFO */
1498   if ((data & 2) != (last_portb_write & 2) && (data & 2) != 0)
1499      sound_fifo_in = sound_fifo_out = 0;
1503   if ((data & 2) != (state->last_portb_write & 2) && (data & 2) != 0)
1504      state->sound_fifo_in = state->sound_fifo_out = 0;
15001505
15011506   /* bit 2 controls the global mute */
1502   if ((data & 4) != (last_portb_write & 4))
1507   if ((data & 4) != (state->last_portb_write & 4))
15031508      device->machine->sound().system_mute(data & 4);
15041509
15051510   /* remember the last value written */
1506   last_portb_write = data;
1511   state->last_portb_write = data;
15071512}
15081513
15091514
r10427r10428
15461551
15471552static MACHINE_RESET( demon_sound )
15481553{
1554   cinemat_state *state = machine->driver_data<cinemat_state>();
15491555   /* generic init */
15501556   generic_init(machine, demon_sound_w);
15511557
15521558   /* reset the FIFO */
1553   sound_fifo_in = sound_fifo_out = 0;
1554   last_portb_write = 0xff;
1559   state->sound_fifo_in = state->sound_fifo_out = 0;
1560   state->last_portb_write = 0xff;
15551561
15561562   /* turn off channel A on AY8910 #0 because it is used as a low-pass filter */
15571563   ay8910_set_volume(machine->device("ay1"), 0, 0);
src/mame/machine/micro3d.c
r10427r10428
8888
8989/*************************************
9090 *
91 *  68901
92 *
93 *************************************/
94
95enum
96{
97   TMRB = 0,
98   TXERR,
99   TBE,
100   RXERR,
101   RBF,
102   TMRA,
103   GPIP6,
104   GPIP7,
105   GPIP0,
106   GPIP1,
107   GPIP2,
108   GPIP3,
109   TMRD,
110   TMRC,
111   GPIP4,
112   GPIP5
113};
114
115
116static void micro3d_mc68901_int_gen(running_machine *machine, int source)
117{
118   micro3d_state *state = machine->driver_data<micro3d_state>();
119   UINT8 *ien = source & 8 ? &state->mc68901.ierb : &state->mc68901.iera;
120   UINT8 *ipend = source & 8 ? &state->mc68901.iprb : &state->mc68901.ipra;
121   UINT8 *imask = source & 8 ? &state->mc68901.imrb : &state->mc68901.imra;
122   int bit = source & 7;
123
124   if (*ien & (1 << bit))
125   {
126      *ipend |= (1 << bit);
127   }
128
129   if (*imask & (1 << bit))
130   {
131      cputag_set_input_line(machine, "maincpu", 4, HOLD_LINE);
132   }
133}
134
135static TIMER_CALLBACK( mfp_timer_a_cb )
136{
137   micro3d_mc68901_int_gen(machine, TMRA);
138}
139
140READ16_HANDLER( micro3d_mc68901_r )
141{
142   micro3d_state *state = space->machine->driver_data<micro3d_state>();
143   UINT16 val = 0;
144
145   switch (offset)
146   {
147      case 0:
148         val = 0xff;
149         break;
150      default:
151         val = state->mc68901.regs[offset] << 8;
152   }
153
154   return val;
155}
156
157WRITE16_HANDLER( micro3d_mc68901_w )
158{
159   micro3d_state *state = space->machine->driver_data<micro3d_state>();
160
161   data >>= 8;
162   state->mc68901.regs[offset] = data;
163
164   switch (offset)
165   {
166      case 0x0f:
167      {
168         int mode = state->mc68901.tacr & 0xf;
169
170         state->mc68901.tadr = data;
171
172         /* Timer stopped */
173         if (mode == 0)
174         {
175            state->mc68901.timer_a->enable(false);
176         }
177         else if (mode < 8)
178         {
179            int divisor = 1;
180            attotime period;
181
182            switch (mode)
183            {
184               case 1: divisor = 4; break;
185               case 2: divisor = 10; break;
186               case 3: divisor = 16; break;
187               case 4: divisor = 50; break;
188               case 5: divisor = 64; break;
189               case 6: divisor = 100; break;
190               case 7: divisor = 200; break;
191            }
192
193            period = attotime::from_hz(4000000 / divisor) * data;
194
195            state->mc68901.timer_a->adjust(period, 0, period);
196         }
197         else
198         {
199            fatalerror("MC68901: Unsupported Timer A mode! (%x)", state->mc68901.tadr);
200         }
201         break;
202      }
203      default:
204         state->mc68901.regs[offset] = data;
205   }
206}
207
208
209/*************************************
210 *
21191 *  SCN2651 (TMS34010)
21292 *
21393 *************************************/
r10427r10428
757637    non-zero on a reset, otherwise the 3D object data doesn't get uploaded! */
758638   space->write_dword(0x00470000, 0xa5a5a5a5);
759639
760   state->mc68901.timer_a = machine->scheduler().timer_alloc(FUNC(mfp_timer_a_cb));
761
762640   /* TODO? BOTSS crashes when starting the final stage because the 68000
763641    overwrites memory in use by the Am29000. Slowing down the 68000 slightly
764642    avoids this */
src/mame/machine/segas32.c
r10427r10428
5656
5757READ16_HANDLER( ga2_dpram_r )
5858{
59   return (ga2_dpram[offset])|(ga2_dpram[offset+1]<<8);
59   segas32_state *state = space->machine->driver_data<segas32_state>();
60   return (state->ga2_dpram[offset])|(state->ga2_dpram[offset+1]<<8);
6061}
6162
6263
r10427r10428
102103
103104WRITE16_HANDLER(sonic_level_load_protection)
104105{
106   segas32_state *state = space->machine->driver_data<segas32_state>();
105107   UINT16 level;
106108//Perform write
107   system32_workram[CLEARED_LEVELS / 2] = (data & mem_mask) | (system32_workram[CLEARED_LEVELS / 2] & ~mem_mask);
109   state->system32_workram[CLEARED_LEVELS / 2] = (data & mem_mask) | (state->system32_workram[CLEARED_LEVELS / 2] & ~mem_mask);
108110
109111//Refresh current level
110      if (system32_workram[CLEARED_LEVELS / 2] == 0)
112      if (state->system32_workram[CLEARED_LEVELS / 2] == 0)
111113      {
112114         level = 0x0007;
113115      }
114116      else
115117      {
116118         const UINT8 *ROM = space->machine->region("maincpu")->base();
117         level =  *((ROM + LEVEL_ORDER_ARRAY) + (system32_workram[CLEARED_LEVELS / 2] * 2) - 1);
118         level |= *((ROM + LEVEL_ORDER_ARRAY) + (system32_workram[CLEARED_LEVELS / 2] * 2) - 2) << 8;
119         level =  *((ROM + LEVEL_ORDER_ARRAY) + (state->system32_workram[CLEARED_LEVELS / 2] * 2) - 1);
120         level |= *((ROM + LEVEL_ORDER_ARRAY) + (state->system32_workram[CLEARED_LEVELS / 2] * 2) - 2) << 8;
119121      }
120      system32_workram[CURRENT_LEVEL / 2] = level;
122      state->system32_workram[CURRENT_LEVEL / 2] = level;
121123
122124//Reset level status
123      system32_workram[CURRENT_LEVEL_STATUS / 2] = 0x0000;
124      system32_workram[(CURRENT_LEVEL_STATUS + 2) / 2] = 0x0000;
125      state->system32_workram[CURRENT_LEVEL_STATUS / 2] = 0x0000;
126      state->system32_workram[(CURRENT_LEVEL_STATUS + 2) / 2] = 0x0000;
125127}
126128
127129
r10427r10428
136138// and can write things into work RAM.  we simulate that here for burning rival.
137139READ16_HANDLER(brival_protection_r)
138140{
141   segas32_state *state = space->machine->driver_data<segas32_state>();
139142   if (mem_mask == 0xffff)   // only trap on word-wide reads
140143   {
141144      switch (offset)
r10427r10428
147150      }
148151   }
149152
150   return system32_workram[0xba00/2 + offset];
153   return state->system32_workram[0xba00/2 + offset];
151154}
152155
153156WRITE16_HANDLER(brival_protection_w)
154157{
158   segas32_state *state = space->machine->driver_data<segas32_state>();
155159   static const int protAddress[6][2] =
156160   {
157161      { 0x109517, 0x00/2 },
r10427r10428
195199   memcpy(ret, &ROM[protAddress[curProtType][0]], 16);
196200   ret[16] = '\0';
197201
198   memcpy(&system32_protram[protAddress[curProtType][1]], ret, 16);
202   memcpy(&state->system32_protram[protAddress[curProtType][1]], ret, 16);
199203}
200204
201205
r10427r10428
303307 ******************************************************************************/
304308WRITE16_HANDLER( jleague_protection_w )
305309{
306   COMBINE_DATA( &system32_workram[0xf700/2 + offset ] );
310   segas32_state *state = space->machine->driver_data<segas32_state>();
311   COMBINE_DATA( &state->system32_workram[0xf700/2 + offset ] );
307312
308313   switch( offset )
309314   {
r10427r10428
343348    99.99% of the dsp code is unused because the V60 ROM is hardcoded as part of a twin set,
344349    maybe the standalone board was for dev only? nop the 3 bytes at 0x06023A for standalone. (centred intro text)
345350*/
346static UINT16 arescue_dsp_io[6] = {0,0,0,0,0,0};
347351
348352READ16_HANDLER( arescue_dsp_r )
349353{
354   segas32_state *state = space->machine->driver_data<segas32_state>();
350355   if( offset == 4/2 )
351356   {
352      switch( arescue_dsp_io[0] )
357      switch( state->arescue_dsp_io[0] )
353358      {
354359         case 0:
355360         case 1:
r10427r10428
357362            break;
358363
359364         case 3:
360            arescue_dsp_io[0] = 0x8000;
361            arescue_dsp_io[2/2] = 0x0001;
365            state->arescue_dsp_io[0] = 0x8000;
366            state->arescue_dsp_io[2/2] = 0x0001;
362367            break;
363368
364369         case 6:
365            arescue_dsp_io[0] = 4 * arescue_dsp_io[2/2];
370            state->arescue_dsp_io[0] = 4 * state->arescue_dsp_io[2/2];
366371            break;
367372
368373         default:
369            logerror("Unhandled DSP cmd %04x (%04x).\n", arescue_dsp_io[0], arescue_dsp_io[1] );
374            logerror("Unhandled DSP cmd %04x (%04x).\n", state->arescue_dsp_io[0], state->arescue_dsp_io[1] );
370375            break;
371376      }
372377   }
373378
374   return arescue_dsp_io[offset];
379   return state->arescue_dsp_io[offset];
375380}
376381
377382WRITE16_HANDLER( arescue_dsp_w )
378383{
379   COMBINE_DATA(&arescue_dsp_io[offset]);
384   segas32_state *state = space->machine->driver_data<segas32_state>();
385   COMBINE_DATA(&state->arescue_dsp_io[offset]);
380386}
381387
src/mame/machine/model3.c
r10427r10428
77#include "emu.h"
88#include "includes/model3.h"
99
10static int m3_step;
1110
1211/******************************************************************/
1312/* Real3D TAP Port                                                */
r10427r10428
2019 * 167 of the 3D-RAM manual.
2120 */
2221
23#define NEXT(new_state) fsm[state][new_state]
22#define NEXT(new_state) fsm[state->tap_state][new_state]
2423
25static INT32  state;  // current state
2624static const INT32 fsm[][2] = {
2725                            {  1,  0 },  // 0  Test-Logic/Reset
2826                            {  1,  2 },  // 1  Run-Test/Idle
r10427r10428
4240                            {  1,  2 }   // 15 Update-IR
4341};
4442
45/*
46 * TAP Registers
47 */
4843
49static UINT64   current_instruction;    // latched IR (not always equal to IR)
50static UINT64   ir;                     // instruction register (46 bits)
51
52static UINT8    id_data[32];            // ASIC ID code data buffer
53static INT32      id_size;                // size of ID data in bits
54//static INT32      ptr;                    // current bit ptr for data
55
56static int      tdo;                    // bit shifted out to TDO
57
5844/*
5945 * insert_bit():
6046 *
r10427r10428
7864 * Inserts a 32-bit ID code into the ID bit field.
7965 */
8066
81static void insert_id(UINT32 id, INT32 start_bit)
67static void insert_id(model3_state *state, UINT32 id, INT32 start_bit)
8268{
8369    INT32 i;
8470
8571    for (i = 31; i >= 0; i--)
86        insert_bit(id_data, start_bit++, (id >> i) & 1);
72        insert_bit(state->id_data, start_bit++, (id >> i) & 1);
8773}
8874
8975/*
r10427r10428
136122 *      TDO.
137123 */
138124
139int model3_tap_read(void)
125int model3_tap_read(running_machine *machine)
140126{
141    return tdo;
127   model3_state *state = machine->driver_data<model3_state>();
128    return state->tdo;
142129}
143130
144131/*
r10427r10428
154141 *      trst = Reset.
155142 */
156143
157void model3_tap_write(int tck, int tms, int tdi, int trst)
144void model3_tap_write(running_machine *machine, int tck, int tms, int tdi, int trst)
158145{
146   model3_state *state = machine->driver_data<model3_state>();
159147    if (!tck)
160148        return;
161149
162    state = NEXT(tms);
150    state->tap_state = NEXT(tms);
163151
164    switch (state)
152    switch (state->tap_state)
165153    {
166154    case 3:     // Capture-DR
167155
r10427r10428
187175         * data on TAP reset and when the instruction is issued.
188176         */
189177
190        if (m3_step == 0x10)
178        if (state->m3_step == 0x10)
191179        {
192            insert_id(0x116C7057, 1 + 0 * 32);
193            insert_id(0x216C3057, 1 + 1 * 32);
194            insert_id(0x116C4057, 1 + 2 * 32);
195            insert_id(0x216C5057, 1 + 3 * 32);
196            insert_id(0x116C6057, 1 + 4 * 32 + 1);
197            insert_id(0x116C6057, 1 + 5 * 32 + 1);
180            insert_id(state, 0x116C7057, 1 + 0 * 32);
181            insert_id(state, 0x216C3057, 1 + 1 * 32);
182            insert_id(state, 0x116C4057, 1 + 2 * 32);
183            insert_id(state, 0x216C5057, 1 + 3 * 32);
184            insert_id(state, 0x116C6057, 1 + 4 * 32 + 1);
185            insert_id(state, 0x116C6057, 1 + 5 * 32 + 1);
198186        }
199        else if (m3_step == 0x15)
187        else if (state->m3_step == 0x15)
200188        {
201            insert_id(0x316C7057, 1 + 0 * 32);
202            insert_id(0x316C3057, 1 + 1 * 32);
203            insert_id(0x216C4057, 1 + 2 * 32);      // Lost World may to use 0x016C4057
204            insert_id(0x316C5057, 1 + 3 * 32);
205            insert_id(0x216C6057, 1 + 4 * 32 + 1);
206            insert_id(0x216C6057, 1 + 5 * 32 + 1);
189            insert_id(state, 0x316C7057, 1 + 0 * 32);
190            insert_id(state, 0x316C3057, 1 + 1 * 32);
191            insert_id(state, 0x216C4057, 1 + 2 * 32);      // Lost World may to use 0x016C4057
192            insert_id(state, 0x316C5057, 1 + 3 * 32);
193            insert_id(state, 0x216C6057, 1 + 4 * 32 + 1);
194            insert_id(state, 0x216C6057, 1 + 5 * 32 + 1);
207195        }
208        else if (m3_step >= 0x20)
196        else if (state->m3_step >= 0x20)
209197        {
210            insert_id(0x416C7057, 1 + 0 * 32);
211            insert_id(0x416C3057, 1 + 1 * 32);
212            insert_id(0x316C4057, 1 + 2 * 32);
213            insert_id(0x416C5057, 1 + 3 * 32);
214            insert_id(0x316C6057, 1 + 4 * 32 + 1);
215            insert_id(0x316C6057, 1 + 5 * 32 + 1);
198            insert_id(state, 0x416C7057, 1 + 0 * 32);
199            insert_id(state, 0x416C3057, 1 + 1 * 32);
200            insert_id(state, 0x316C4057, 1 + 2 * 32);
201            insert_id(state, 0x416C5057, 1 + 3 * 32);
202            insert_id(state, 0x316C6057, 1 + 4 * 32 + 1);
203            insert_id(state, 0x316C6057, 1 + 5 * 32 + 1);
216204        }
217205
218206        break;
219207
220208    case 4:     // Shift-DR
221209
222        tdo = shift(id_data, id_size);
210        state->tdo = shift(state->id_data, state->id_size);
223211        break;
224212
225213    case 10:    // Capture-IR
r10427r10428
228216         * Load lower 2 bits with 01 as per IEEE 1149.1-1990
229217         */
230218
231        ir = 1;
219        state->ir = 1;
232220        break;
233221
234222    case 11:    // Shift-IR
r10427r10428
237225         * Shift IR towards output and load in new data from TDI
238226         */
239227
240        tdo = ir & 1;   // shift LSB to output
241        ir >>= 1;
242        ir |= ((UINT64) tdi << 45);
228        state->tdo = state->ir & 1;   // shift LSB to output
229        state->ir >>= 1;
230        state->ir |= ((UINT64) tdi << 45);
243231        break;
244232
245233    case 15:    // Update-IR
r10427r10428
249237         * TCK)
250238         */
251239
252        ir &= U64(0x3fffffffffff);
253        current_instruction = ir;
240        state->ir &= U64(0x3fffffffffff);
254241        break;
255242
256243    default:
r10427r10428
265252 * Resets the TAP (simulating a power up or SCAN_RST signal.)
266253 */
267254
268void model3_tap_reset(void)
255void model3_tap_reset(running_machine *machine)
269256{
270    id_size = 197;  // 197 bits
257   model3_state *state = machine->driver_data<model3_state>();
258    state->id_size = 197;  // 197 bits
271259
272    state = 0;  // test-logic/reset
260    state->tap_state = 0;  // test-logic/reset
273261}
274262
275263/*
r10427r10428
279267 *
280268 */
281269
282void model3_machine_init(int step)
270void model3_machine_init(running_machine *machine, int step)
283271{
284   m3_step = step;
272   model3_state *state = machine->driver_data<model3_state>();
273   state->m3_step = step;
285274}
286275
287276/*****************************************************************************/
src/mame/machine/megadriv.c
r10427r10428
93289328MACHINE_CONFIG_END
93299329
93309330
9331static int _32x_fifo_available_callback(UINT32 src, UINT32 dst, UINT32 data, int size)
9331static int _32x_fifo_available_callback(device_t *device, UINT32 src, UINT32 dst, UINT32 data, int size)
93329332{
93339333   if (src==0x4012)
93349334   {
src/mame/machine/atarigen.h
r10427r10428
4242
4343#include "machine/nvram.h"
4444#include "video/atarimo.h"
45#include "video/atarirle.h"
4645#include "machine/er2055.h"
4746
4847
src/mame/machine/psx.c
r10427r10428
514514            }
515515            else
516516            {
517               printf("dma %d unknown mode %08x\n", n_channel, dma->n_channelcontrol );
517               verboselog( p_psx, 1, "dma %d unknown mode %08x\n", n_channel, dma->n_channelcontrol );
518518            }
519519         }
520520         else if( dma->n_channelcontrol != 0 )
src/mame/machine/dec0.c
r10427r10428
1111#include "cpu/h6280/h6280.h"
1212#include "cpu/mcs51/mcs51.h"
1313
14static int GAME,i8751_return,i8751_command,slyspy_state;
1514
1615/******************************************************************************/
1716
1817READ16_HANDLER( dec0_controls_r )
1918{
19   dec0_state *state = space->machine->driver_data<dec0_state>();
2020   switch (offset<<1)
2121   {
2222      case 0: /* Player 1 & 2 joystick & buttons */
r10427r10428
2929         return input_port_read(space->machine, "DSW");
3030
3131      case 8: /* Intel 8751 mc, Bad Dudes & Heavy Barrel only */
32         //logerror("CPU #0 PC %06x: warning - read i8751 %06x - %04x\n", cpu_get_pc(space->cpu), 0x30c000+offset, i8751_return);
33         return i8751_return;
32         //logerror("CPU #0 PC %06x: warning - read i8751 %06x - %04x\n", cpu_get_pc(space->cpu), 0x30c000+offset, state->i8751_return);
33         return state->i8751_return;
3434   }
3535
3636   logerror("CPU #0 PC %06x: warning - read unmapped memory address %06x\n", cpu_get_pc(space->cpu), 0x30c000+offset);
r10427r10428
154154
155155WRITE16_HANDLER( slyspy_state_w )
156156{
157   slyspy_state=0;
157   dec0_state *state = space->machine->driver_data<dec0_state>();
158   state->slyspy_state=0;
158159}
159160
160161READ16_HANDLER( slyspy_state_r )
161162{
162   slyspy_state++;
163   slyspy_state=slyspy_state%4;
163   dec0_state *state = space->machine->driver_data<dec0_state>();
164   state->slyspy_state++;
165   state->slyspy_state=state->slyspy_state%4;
164166   return 0; /* Value doesn't mater */
165167}
166168
167169WRITE16_HANDLER( slyspy_240000_w )
168170{
169   switch (slyspy_state) {
171   dec0_state *state = space->machine->driver_data<dec0_state>();
172   switch (state->slyspy_state) {
170173      case 0x3:
171174         dec0_pf1_data_w(space,offset,data,mem_mask);
172175         return;
r10427r10428
178181         else if (offset<0x10) dec0_pf2_control_1_w(space,offset-0x8,data,mem_mask);
179182         return;
180183   }
181   logerror("Wrote to 240000 %02x at %04x %04x (Trap %02x)\n",offset,cpu_get_pc(space->cpu),data,slyspy_state);
184   logerror("Wrote to 240000 %02x at %04x %04x (Trap %02x)\n",offset,cpu_get_pc(space->cpu),data,state->slyspy_state);
182185}
183186
184187WRITE16_HANDLER( slyspy_242000_w )
185188{
186   switch (slyspy_state) {
189   dec0_state *state = space->machine->driver_data<dec0_state>();
190   switch (state->slyspy_state) {
187191      case 0x2: /* Trap A */
188192         dec0_pf1_data_w(space,offset,data,mem_mask);
189193         return;
190194      case 0x0: /* Trap C */
191         if (offset<0x40) COMBINE_DATA(&dec0_pf2_colscroll[offset]);
192         else if (offset<0x300) COMBINE_DATA(&dec0_pf2_rowscroll[offset-0x200]);
195         if (offset<0x40) COMBINE_DATA(&state->pf2_colscroll[offset]);
196         else if (offset<0x300) COMBINE_DATA(&state->pf2_rowscroll[offset-0x200]);
193197         return;
194198   }
195   logerror("Wrote to 242000 %02x at %04x %04x (Trap %02x)\n",offset,cpu_get_pc(space->cpu),data,slyspy_state);
199   logerror("Wrote to 242000 %02x at %04x %04x (Trap %02x)\n",offset,cpu_get_pc(space->cpu),data,state->slyspy_state);
196200}
197201
198202WRITE16_HANDLER( slyspy_246000_w )
199203{
200   switch (slyspy_state) {
204   dec0_state *state = space->machine->driver_data<dec0_state>();
205   switch (state->slyspy_state) {
201206      case 0x0:
202207         dec0_pf2_data_w(space,offset,data,mem_mask);
203208         return;
204209   }
205   logerror("Wrote to 246000 %02x at %04x %04x (Trap %02x)\n",offset,cpu_get_pc(space->cpu),data,slyspy_state);
210   logerror("Wrote to 246000 %02x at %04x %04x (Trap %02x)\n",offset,cpu_get_pc(space->cpu),data,state->slyspy_state);
206211}
207212
208213WRITE16_HANDLER( slyspy_248000_w )
209214{
210   switch (slyspy_state) {
215   dec0_state *state = space->machine->driver_data<dec0_state>();
216   switch (state->slyspy_state) {
211217      case 0x1:
212218         dec0_pf1_data_w(space,offset,data,mem_mask);
213219         return;
r10427r10428
219225         else if (offset<0x10) dec0_pf1_control_1_w(space,offset-0x8,data,mem_mask);
220226         return;
221227   }
222   logerror("Wrote to 248000 %02x at %04x %04x (Trap %02x)\n",offset,cpu_get_pc(space->cpu),data,slyspy_state);
228   logerror("Wrote to 248000 %02x at %04x %04x (Trap %02x)\n",offset,cpu_get_pc(space->cpu),data,state->slyspy_state);
223229}
224230
225231WRITE16_HANDLER( slyspy_24c000_w )
226232{
227   switch (slyspy_state) {
233   dec0_state *state = space->machine->driver_data<dec0_state>();
234   switch (state->slyspy_state) {
228235      case 0x1: /* Trap 9 */
229236         dec0_pf2_data_w(space,offset,data,mem_mask);
230237         return;
231238      case 0x0: /* Trap C */
232         if (offset<0x40) COMBINE_DATA(&dec0_pf1_colscroll[offset]);
233         else if (offset<0x300) COMBINE_DATA(&dec0_pf1_rowscroll[offset-0x200]);
239         if (offset<0x40) COMBINE_DATA(&state->pf1_colscroll[offset]);
240         else if (offset<0x300) COMBINE_DATA(&state->pf1_rowscroll[offset-0x200]);
234241         return;
235242   }
236   logerror("Wrote to 24c000 %02x at %04x %04x (Trap %02x)\n",offset,cpu_get_pc(space->cpu),data,slyspy_state);
243   logerror("Wrote to 24c000 %02x at %04x %04x (Trap %02x)\n",offset,cpu_get_pc(space->cpu),data,state->slyspy_state);
237244}
238245
239246WRITE16_HANDLER( slyspy_24e000_w )
240247{
241   switch (slyspy_state) {
248   dec0_state *state = space->machine->driver_data<dec0_state>();
249   switch (state->slyspy_state) {
242250      case 0x2:
243251      case 0x0:
244252         dec0_pf1_data_w(space,offset,data,mem_mask);
245253         return;
246254   }
247   logerror("Wrote to 24e000 %02x at %04x %04x (Trap %02x)\n",offset,cpu_get_pc(space->cpu),data,slyspy_state);
255   logerror("Wrote to 24e000 %02x at %04x %04x (Trap %02x)\n",offset,cpu_get_pc(space->cpu),data,state->slyspy_state);
248256}
249257
250258/******************************************************************************/
251259
252static int share[0xff];
253static int hippodrm_msb,hippodrm_lsb;
254260
255261READ8_HANDLER( hippodrm_prot_r )
256262{
263   dec0_state *state = space->machine->driver_data<dec0_state>();
257264//logerror("6280 PC %06x - Read %06x\n",cpu_getpc(),offset+0x1d0000);
258   if (hippodrm_lsb==0x45) return 0x4e;
259   if (hippodrm_lsb==0x92) return 0x15;
265   if (state->hippodrm_lsb==0x45) return 0x4e;
266   if (state->hippodrm_lsb==0x92) return 0x15;
260267   return 0;
261268}
262269
263270WRITE8_HANDLER( hippodrm_prot_w )
264271{
272   dec0_state *state = space->machine->driver_data<dec0_state>();
265273   switch (offset) {
266      case 4:   hippodrm_msb=data; break;
267      case 5:   hippodrm_lsb=data; break;
274      case 4:   state->hippodrm_msb=data; break;
275      case 5:   state->hippodrm_lsb=data; break;
268276   }
269277//logerror("6280 PC %06x - Wrote %06x to %04x\n",cpu_getpc(),data,offset+0x1d0000);
270278}
271279
272280READ8_HANDLER( hippodrm_shared_r )
273281{
274   return share[offset];
282   dec0_state *state = space->machine->driver_data<dec0_state>();
283   return state->share[offset];
275284}
276285
277286WRITE8_HANDLER( hippodrm_shared_w )
278287{
279   share[offset]=data;
288   dec0_state *state = space->machine->driver_data<dec0_state>();
289   state->share[offset]=data;
280290}
281291
282292static READ16_HANDLER( hippodrm_68000_share_r )
283293{
294   dec0_state *state = space->machine->driver_data<dec0_state>();
284295   if (offset==0) cpu_yield(space->cpu); /* A wee helper */
285   return share[offset]&0xff;
296   return state->share[offset]&0xff;
286297}
287298
288299static WRITE16_HANDLER( hippodrm_68000_share_w )
289300{
290   share[offset]=data&0xff;
301   dec0_state *state = space->machine->driver_data<dec0_state>();
302   state->share[offset]=data&0xff;
291303}
292304
293305/******************************************************************************/
r10427r10428
326338    values are not known to change after bootup.
327339*/
328340
329static UINT8 i8751_ports[4];
330341
331342READ8_HANDLER(dec0_mcu_port_r )
332343{
333   int latchEnable=i8751_ports[2]>>4;
344   dec0_state *state = space->machine->driver_data<dec0_state>();
345   int latchEnable=state->i8751_ports[2]>>4;
334346
335347   // P0 connected to 4 latches
336348   if (offset==0)
337349   {
338350      if ((latchEnable&1)==0)
339         return i8751_command>>8;
351         return state->i8751_command>>8;
340352      else if ((latchEnable&2)==0)
341         return i8751_command&0xff;
353         return state->i8751_command&0xff;
342354      else if ((latchEnable&4)==0)
343         return i8751_return>>8;
355         return state->i8751_return>>8;
344356      else if ((latchEnable&8)==0)
345         return i8751_return&0xff;
357         return state->i8751_return&0xff;
346358   }
347359
348360   return 0xff;
r10427r10428
350362
351363WRITE8_HANDLER(dec0_mcu_port_w )
352364{
353   i8751_ports[offset]=data;
365   dec0_state *state = space->machine->driver_data<dec0_state>();
366   state->i8751_ports[offset]=data;
354367
355368   if (offset==2)
356369   {
r10427r10428
359372      if ((data&0x8)==0)
360373         cputag_set_input_line(space->machine, "mcu", MCS51_INT1_LINE, CLEAR_LINE);
361374      if ((data&0x40)==0)
362         i8751_return=(i8751_return&0xff00)|(i8751_ports[0]);
375         state->i8751_return=(state->i8751_return&0xff00)|(state->i8751_ports[0]);
363376      if ((data&0x80)==0)
364         i8751_return=(i8751_return&0xff)|(i8751_ports[0]<<8);
377         state->i8751_return=(state->i8751_return&0xff)|(state->i8751_ports[0]<<8);
365378   }
366379}
367380
368381static void baddudes_i8751_write(running_machine *machine, int data)
369382{
370   i8751_return=0;
383   dec0_state *state = machine->driver_data<dec0_state>();
384   state->i8751_return=0;
371385
372386   switch (data&0xffff) {
373      case 0x714: i8751_return=0x700; break;
374      case 0x73b: i8751_return=0x701; break;
375      case 0x72c: i8751_return=0x702; break;
376      case 0x73f: i8751_return=0x703; break;
377      case 0x755: i8751_return=0x704; break;
378      case 0x722: i8751_return=0x705; break;
379      case 0x72b: i8751_return=0x706; break;
380      case 0x724: i8751_return=0x707; break;
381      case 0x728: i8751_return=0x708; break;
382      case 0x735: i8751_return=0x709; break;
383      case 0x71d: i8751_return=0x70a; break;
384      case 0x721: i8751_return=0x70b; break;
385      case 0x73e: i8751_return=0x70c; break;
386      case 0x761: i8751_return=0x70d; break;
387      case 0x753: i8751_return=0x70e; break;
388      case 0x75b: i8751_return=0x70f; break;
387      case 0x714: state->i8751_return=0x700; break;
388      case 0x73b: state->i8751_return=0x701; break;
389      case 0x72c: state->i8751_return=0x702; break;
390      case 0x73f: state->i8751_return=0x703; break;
391      case 0x755: state->i8751_return=0x704; break;
392      case 0x722: state->i8751_return=0x705; break;
393      case 0x72b: state->i8751_return=0x706; break;
394      case 0x724: state->i8751_return=0x707; break;
395      case 0x728: state->i8751_return=0x708; break;
396      case 0x735: state->i8751_return=0x709; break;
397      case 0x71d: state->i8751_return=0x70a; break;
398      case 0x721: state->i8751_return=0x70b; break;
399      case 0x73e: state->i8751_return=0x70c; break;
400      case 0x761: state->i8751_return=0x70d; break;
401      case 0x753: state->i8751_return=0x70e; break;
402      case 0x75b: state->i8751_return=0x70f; break;
389403   }
390404
391   if (!i8751_return) logerror("%s: warning - write unknown command %02x to 8571\n",machine->describe_context(),data);
405   if (!state->i8751_return) logerror("%s: warning - write unknown command %02x to 8571\n",machine->describe_context(),data);
392406   cputag_set_input_line(machine, "maincpu", 5, HOLD_LINE);
393407}
394408
395409static void birdtry_i8751_write(running_machine *machine, int data)
396410{
411   dec0_state *state = machine->driver_data<dec0_state>();
397412   static int   pwr,
398413            hgt;
399414
400   i8751_return=0;
415   state->i8751_return=0;
401416
402417   switch(data&0xffff) {
403418      /*"Sprite control"*/
404      case 0x22a:   i8751_return = 0x200;     break;
419      case 0x22a:   state->i8751_return = 0x200;     break;
405420
406421      /* Gives an O.B. otherwise (it must be > 0xb0 )*/
407      case 0x3c7:   i8751_return = 0x7ff;     break;
422      case 0x3c7:   state->i8751_return = 0x7ff;     break;
408423
409424      /*Enables shot checks*/
410      case 0x33c: i8751_return = 0x200;     break;
425      case 0x33c: state->i8751_return = 0x200;     break;
411426
412427      /*Used on the title screen only(???)*/
413      case 0x31e: i8751_return = 0x200;     break;
428      case 0x31e: state->i8751_return = 0x200;     break;
414429
415430/*  0x100-0x10d values are for club power meters(1W=0x100<<-->>PT=0x10d).    *
416431 *  Returned value to i8751 doesn't matter,but send the result to 0x481.     *
r10427r10428
429444      case 0x10b: pwr = 0x5c;          break; /*PW*/
430445      case 0x10c: pwr = 0x60;          break; /*SW*/
431446      case 0x10d: pwr = 0x80;          break; /*PT*/
432      case 0x481: i8751_return = pwr;     break; /*Power meter*/
447      case 0x481: state->i8751_return = pwr;     break; /*Power meter*/
433448
434449/*  0x200-0x20f values are for shot height(STRONG=0x200<<-->>WEAK=0x20f).    *
435450 *  Returned value to i8751 doesn't matter,but send the result to 0x534.     *
r10427r10428
450465      case 0x20d: hgt = 0x280;         break; /*|*/
451466      case 0x20e: hgt = 0x240;         break; /*|*/
452467      case 0x20f: hgt = 0x200;         break; /*L*/
453      case 0x534: i8751_return = hgt;    break; /*Shot height*/
468      case 0x534: state->i8751_return = hgt;    break; /*Shot height*/
454469
455470      /*At the ending screen(???)*/
456      //case 0x3b4: i8751_return = 0;       break;
471      //case 0x3b4: state->i8751_return = 0;       break;
457472
458473      /*These are activated after a shot (???)*/
459      case 0x6ca: i8751_return = 0xff;      break;
460      case 0x7ff: i8751_return = 0x200;     break;
474      case 0x6ca: state->i8751_return = 0xff;      break;
475      case 0x7ff: state->i8751_return = 0x200;     break;
461476      default: logerror("%s: warning - write unknown command %02x to 8571\n",machine->describe_context(),data);
462477   }
463478   cputag_set_input_line(machine, "maincpu", 5, HOLD_LINE);
r10427r10428
465480
466481void dec0_i8751_write(running_machine *machine, int data)
467482{
468   i8751_command=data;
483   dec0_state *state = machine->driver_data<dec0_state>();
484   state->i8751_command=data;
469485
470486   /* Writes to this address cause an IRQ to the i8751 microcontroller */
471   if (GAME == 1) cputag_set_input_line(machine, "mcu", MCS51_INT1_LINE, ASSERT_LINE);
472   if (GAME == 2) baddudes_i8751_write(machine, data);
473   if (GAME == 3) birdtry_i8751_write(machine, data);
487   if (state->GAME == 1) cputag_set_input_line(machine, "mcu", MCS51_INT1_LINE, ASSERT_LINE);
488   if (state->GAME == 2) baddudes_i8751_write(machine, data);
489   if (state->GAME == 3) birdtry_i8751_write(machine, data);
474490
475491   //logerror("%s: warning - write %02x to i8751\n",machine->describe_context(),data);
476492}
477493
478void dec0_i8751_reset(void)
494void dec0_i8751_reset(running_machine *machine)
479495{
480   i8751_return=i8751_command=0;
496   dec0_state *state = machine->driver_data<dec0_state>();
497   state->i8751_return=state->i8751_command=0;
481498}
482499
483500/******************************************************************************/
r10427r10428
491508
492509static READ16_HANDLER( robocop_68000_share_r )
493510{
511   dec0_state *state = space->machine->driver_data<dec0_state>();
494512//logerror("%08x: Share read %04x\n",cpu_get_pc(space->cpu),offset);
495513
496   return robocop_shared_ram[offset];
514   return state->robocop_shared_ram[offset];
497515}
498516
499517static WRITE16_HANDLER( robocop_68000_share_w )
500518{
519   dec0_state *state = space->machine->driver_data<dec0_state>();
501520//  logerror("%08x: Share write %04x %04x\n",cpu_get_pc(space->cpu),offset,data);
502521
503   robocop_shared_ram[offset]=data&0xff;
522   state->robocop_shared_ram[offset]=data&0xff;
504523
505524   if (offset == 0x7ff) /* A control address - not standard ram */
506525      cputag_set_input_line(space->machine, "sub", 0, HOLD_LINE);
r10427r10428
552571
553572DRIVER_INIT( baddudes )
554573{
555   GAME = 2;
574   dec0_state *state = machine->driver_data<dec0_state>();
575   state->GAME = 2;
556576}
557577
558578DRIVER_INIT( hbarrel )
559579{
560   GAME = 1;
580   dec0_state *state = machine->driver_data<dec0_state>();
581   state->GAME = 1;
561582}
562583
563584DRIVER_INIT( birdtry )
564585{
586   dec0_state *state = machine->driver_data<dec0_state>();
565587   UINT8 *src, tmp;
566588   int i, j, k;
567589
568   GAME=3;
590   state->GAME=3;
569591
570592   src = machine->region("gfx4")->base();
571593
src/mame/machine/beezer.c
r10427r10428
33#include "machine/6522via.h"
44#include "includes/beezer.h"
55
6extern const via6522_interface b_via_0_interface;
7extern const via6522_interface b_via_1_interface;
86
9static int pbus;
10static int banklatch;
11
127static READ8_DEVICE_HANDLER( b_via_0_pa_r );
138static READ8_DEVICE_HANDLER( b_via_0_pb_r );
149static WRITE8_DEVICE_HANDLER( b_via_0_pa_w );
r10427r10428
9388
9489static READ8_DEVICE_HANDLER( b_via_0_pa_r )
9590{
96   return (banklatch&0x38)<<2; // return X,Y,Z bits TODO: the Z bit connects somewhere else... where?
91   beezer_state *state = device->machine->driver_data<beezer_state>();
92   return (state->banklatch&0x38)<<2; // return X,Y,Z bits TODO: the Z bit connects somewhere else... where?
9793}
9894
9995static READ8_DEVICE_HANDLER( b_via_0_pb_r )
10096{
101   return pbus;
97   beezer_state *state = device->machine->driver_data<beezer_state>();
98   return state->pbus;
10299}
103100
104101static WRITE8_DEVICE_HANDLER( b_via_0_pa_w )
105102{
103   beezer_state *state = device->machine->driver_data<beezer_state>();
106104   if ((data & 0x08) == 0)
107105      cputag_set_input_line(device->machine, "audiocpu", INPUT_LINE_RESET, ASSERT_LINE);
108106   else
r10427r10428
113111      switch (data & 0x03)
114112      {
115113      case 0:
116         pbus = input_port_read(device->machine, "IN0");
114         state->pbus = input_port_read(device->machine, "IN0");
117115         break;
118116      case 1:
119         pbus = input_port_read(device->machine, "IN1") | (input_port_read(device->machine, "IN2") << 4);
117         state->pbus = input_port_read(device->machine, "IN1") | (input_port_read(device->machine, "IN2") << 4);
120118         break;
121119      case 2:
122         pbus = input_port_read(device->machine, "DSWB");
120         state->pbus = input_port_read(device->machine, "DSWB");
123121         break;
124122      case 3:
125         pbus = input_port_read(device->machine, "DSWA"); // Technically DSWA isn't populated on the board and is pulled to 0xFF with resistor pack, but there IS a DSWA port in the driver so we may as well use it.
123         state->pbus = input_port_read(device->machine, "DSWA"); // Technically DSWA isn't populated on the board and is pulled to 0xFF with resistor pack, but there IS a DSWA port in the driver so we may as well use it.
126124         break;
127125      }
128126   }
r10427r10428
130128
131129static WRITE8_DEVICE_HANDLER( b_via_0_pb_w )
132130{
133   pbus = data;
131   beezer_state *state = device->machine->driver_data<beezer_state>();
132   state->pbus = data;
134133}
135134
136135static READ8_DEVICE_HANDLER( b_via_1_pa_r )
137136{
138   return pbus;
137   beezer_state *state = device->machine->driver_data<beezer_state>();
138   return state->pbus;
139139}
140140
141141static READ8_DEVICE_HANDLER( b_via_1_pb_r )
r10427r10428
145145
146146static WRITE8_DEVICE_HANDLER( b_via_1_pa_w )
147147{
148   pbus = data;
148   beezer_state *state = device->machine->driver_data<beezer_state>();
149   state->pbus = data;
149150}
150151
151152static WRITE8_DEVICE_HANDLER( b_via_1_pb_w )
r10427r10428
157158
158159DRIVER_INIT( beezer )
159160{
160   pbus = 0;
161   banklatch = 0;
161   beezer_state *state = machine->driver_data<beezer_state>();
162   state->pbus = 0;
163   state->banklatch = 0;
162164}
163165
164166WRITE8_HANDLER( beezer_bankswitch_w )
165167{
166   banklatch = data&0x3f; // latched 'x,y,z' plus bank bits in ls174 @ 4H
168   beezer_state *state = space->machine->driver_data<beezer_state>();
169   state->banklatch = data&0x3f; // latched 'x,y,z' plus bank bits in ls174 @ 4H
167170   if ((data & 0x07) == 0)
168171   {
169172      via6522_device *via_0 = space->machine->device<via6522_device>("via6522_0");
src/mame/machine/model1.c
r10427r10428
99#include "includes/model1.h"
1010
1111#define TGP_FUNCTION(name) void name(running_machine *machine)
12typedef void (*tgp_func)(running_machine *machine);
1312
1413
15enum {FIFO_SIZE = 256};
16enum {MAT_STACK_SIZE = 32};
17
18int model1_dump;
19
20static offs_t pushpc;
21
22static int fifoin_rpos, fifoin_wpos;
23static UINT32 fifoin_data[FIFO_SIZE];
24static int model1_swa;
25
26static int fifoin_cbcount;
27static tgp_func fifoin_cb;
28
29static INT32 fifoout_rpos, fifoout_wpos;
30static UINT32 fifoout_data[FIFO_SIZE];
31
32static UINT32 list_length;
33
34static float cmat[12], mat_stack[MAT_STACK_SIZE][12], mat_vector[21][12];
35static INT32 mat_stack_pos;
36static float acc;
37
38static float tgp_vf_xmin, tgp_vf_xmax, tgp_vf_zmin, tgp_vf_zmax, tgp_vf_ygnd, tgp_vf_yflr, tgp_vf_yjmp;
39static float tgp_vr_circx, tgp_vr_circy, tgp_vr_circrad, tgp_vr_cbox[12];
40static int tgp_vr_select;
41static UINT16 ram_adr, ram_latch[2], ram_scanadr;
42static UINT32 *ram_data;
43static float tgp_vr_base[4];
44
4514static UINT32 fifoout_pop(address_space *space)
4615{
16   model1_state *state = space->machine->driver_data<model1_state>();
4717   UINT32 v;
48   if(fifoout_wpos == fifoout_rpos) {
18   if(state->fifoout_wpos == state->fifoout_rpos) {
4919      fatalerror("TGP FIFOOUT underflow (%x)", cpu_get_pc(space->cpu));
5020   }
51   v = fifoout_data[fifoout_rpos++];
52   if(fifoout_rpos == FIFO_SIZE)
53      fifoout_rpos = 0;
21   v = state->fifoout_data[state->fifoout_rpos++];
22   if(state->fifoout_rpos == FIFO_SIZE)
23      state->fifoout_rpos = 0;
5424   return v;
5525}
5626
57static int puuu = 0;
5827
59static void fifoout_push(UINT32 data)
28static void fifoout_push(model1_state *state, UINT32 data)
6029{
61   if(!puuu)
30   if(!state->puuu)
6231      logerror("TGP: Push %d\n", data);
6332   else
64      puuu = 0;
65   fifoout_data[fifoout_wpos++] = data;
66   if(fifoout_wpos == FIFO_SIZE)
67      fifoout_wpos = 0;
68   if(fifoout_wpos == fifoout_rpos)
33      state->puuu = 0;
34   state->fifoout_data[state->fifoout_wpos++] = data;
35   if(state->fifoout_wpos == FIFO_SIZE)
36      state->fifoout_wpos = 0;
37   if(state->fifoout_wpos == state->fifoout_rpos)
6938      logerror("TGP FIFOOUT overflow\n");
7039}
7140
72static void fifoout_push_f(float data)
41static void fifoout_push_f(model1_state *state, float data)
7342{
74   puuu = 1;
43   state->puuu = 1;
7544
7645   logerror("TGP: Push %f\n", data);
77   fifoout_push(f2u(data));
46   fifoout_push(state, f2u(data));
7847}
7948
80static UINT32 fifoin_pop(void)
49static UINT32 fifoin_pop(model1_state *state)
8150{
8251   UINT32 v;
83   if(fifoin_wpos == fifoin_rpos)
52   if(state->fifoin_wpos == state->fifoin_rpos)
8453      logerror("TGP FIFOIN underflow\n");
85   v = fifoin_data[fifoin_rpos++];
86   if(fifoin_rpos == FIFO_SIZE)
87      fifoin_rpos = 0;
54   v = state->fifoin_data[state->fifoin_rpos++];
55   if(state->fifoin_rpos == FIFO_SIZE)
56      state->fifoin_rpos = 0;
8857   return v;
8958}
9059
9160static void fifoin_push(address_space *space, UINT32 data)
9261{
62   model1_state *state = space->machine->driver_data<model1_state>();
9363   //  logerror("TGP FIFOIN write %08x (%x)\n", data, cpu_get_pc(space->cpu));
94   fifoin_data[fifoin_wpos++] = data;
95   if(fifoin_wpos == FIFO_SIZE)
96      fifoin_wpos = 0;
97   if(fifoin_wpos == fifoin_rpos)
64   state->fifoin_data[state->fifoin_wpos++] = data;
65   if(state->fifoin_wpos == FIFO_SIZE)
66      state->fifoin_wpos = 0;
67   if(state->fifoin_wpos == state->fifoin_rpos)
9868      logerror("TGP FIFOIN overflow\n");
99   fifoin_cbcount--;
100   if(!fifoin_cbcount)
101      fifoin_cb(space->machine);
69   state->fifoin_cbcount--;
70   if(!state->fifoin_cbcount)
71      state->fifoin_cb(space->machine);
10272}
10373
104static float fifoin_pop_f(void)
74static float fifoin_pop_f(model1_state *state)
10575{
106   return u2f(fifoin_pop());
76   return u2f(fifoin_pop(state));
10777}
10878
10979static TGP_FUNCTION( function_get_vf );
11080static TGP_FUNCTION( function_get_swa );
11181
112static void next_fn(void)
82static void next_fn(model1_state *state)
11383{
114   fifoin_cbcount = 1;
115   fifoin_cb = model1_swa ? function_get_swa : function_get_vf;
84   state->fifoin_cbcount = 1;
85   state->fifoin_cb = state->swa ? function_get_swa : function_get_vf;
11686}
11787
11888static float tcos(INT16 a)
r10427r10428
139109      return sin(a*(2*M_PI/65536.0));
140110}
141111
142static UINT16 ram_get_i(void)
112static UINT16 ram_get_i(model1_state *state)
143113{
144   return ram_data[ram_scanadr++];
114   return state->ram_data[state->ram_scanadr++];
145115}
146116
147static float ram_get_f(void)
117static float ram_get_f(model1_state *state)
148118{
149   return u2f(ram_data[ram_scanadr++]);
119   return u2f(state->ram_data[state->ram_scanadr++]);
150120}
151121
152122static TGP_FUNCTION( fadd )
153123{
154   float a = fifoin_pop_f();
155   float b = fifoin_pop_f();
124   model1_state *state = machine->driver_data<model1_state>();
125   float a = fifoin_pop_f(state);
126   float b = fifoin_pop_f(state);
156127   float r = a+b;
157   logerror("TGP fadd %f+%f=%f (%x)\n", a, b, r, pushpc);
158   fifoout_push_f(r);
159   next_fn();
128   logerror("TGP fadd %f+%f=%f (%x)\n", a, b, r, state->pushpc);
129   fifoout_push_f(state, r);
130   next_fn(state);
160131}
161132
162133static TGP_FUNCTION( fsub )
163134{
164   float a = fifoin_pop_f();
165   float b = fifoin_pop_f();
135   model1_state *state = machine->driver_data<model1_state>();
136   float a = fifoin_pop_f(state);
137   float b = fifoin_pop_f(state);
166138   float r = a-b;
167   model1_dump = 1;
168   logerror("TGP fsub %f-%f=%f (%x)\n", a, b, r, pushpc);
169   fifoout_push_f(r);
170   next_fn();
139   state->dump = 1;
140   logerror("TGP fsub %f-%f=%f (%x)\n", a, b, r, state->pushpc);
141   fifoout_push_f(state, r);
142   next_fn(state);
171143}
172144
173145static TGP_FUNCTION( fmul )
174146{
175   float a = fifoin_pop_f();
176   float b = fifoin_pop_f();
147   model1_state *state = machine->driver_data<model1_state>();
148   float a = fifoin_pop_f(state);
149   float b = fifoin_pop_f(state);
177150   float r = a*b;
178   logerror("TGP fmul %f*%f=%f (%x)\n", a, b, r, pushpc);
179   fifoout_push_f(r);
180   next_fn();
151   logerror("TGP fmul %f*%f=%f (%x)\n", a, b, r, state->pushpc);
152   fifoout_push_f(state, r);
153   next_fn(state);
181154}
182155
183156static TGP_FUNCTION( fdiv )
184157{
185   float a = fifoin_pop_f();
186   float b = fifoin_pop_f();
158   model1_state *state = machine->driver_data<model1_state>();
159   float a = fifoin_pop_f(state);
160   float b = fifoin_pop_f(state);
187161//  float r = !b ? 1e39 : a/b;
188162   float r = !b ? 0 : a * (1/b);
189   logerror("TGP fdiv %f/%f=%f (%x)\n", a, b, r, pushpc);
190   fifoout_push_f(r);
191   next_fn();
163   logerror("TGP fdiv %f/%f=%f (%x)\n", a, b, r, state->pushpc);
164   fifoout_push_f(state, r);
165   next_fn(state);
192166}
193167
194168static TGP_FUNCTION( matrix_push )
195169{
196   if(mat_stack_pos != MAT_STACK_SIZE) {
197      memcpy(mat_stack[mat_stack_pos], cmat, sizeof(cmat));
198      mat_stack_pos++;
170   model1_state *state = machine->driver_data<model1_state>();
171   if(state->mat_stack_pos != MAT_STACK_SIZE) {
172      memcpy(state->mat_stack[state->mat_stack_pos], state->cmat, sizeof(state->cmat));
173      state->mat_stack_pos++;
199174   }
200   logerror("TGP matrix_push (depth=%d, pc=%x)\n", mat_stack_pos, pushpc);
201   next_fn();
175   logerror("TGP matrix_push (depth=%d, pc=%x)\n", state->mat_stack_pos, state->pushpc);
176   next_fn(state);
202177}
203178
204179static TGP_FUNCTION( matrix_pop )
205180{
206   if(mat_stack_pos) {
207      mat_stack_pos--;
208      memcpy(cmat, mat_stack[mat_stack_pos], sizeof(cmat));
181   model1_state *state = machine->driver_data<model1_state>();
182   if(state->mat_stack_pos) {
183      state->mat_stack_pos--;
184      memcpy(state->cmat, state->mat_stack[state->mat_stack_pos], sizeof(state->cmat));
209185   }
210   logerror("TGP matrix_pop (depth=%d, pc=%x)\n", mat_stack_pos, pushpc);
211   next_fn();
186   logerror("TGP matrix_pop (depth=%d, pc=%x)\n", state->mat_stack_pos, state->pushpc);
187   next_fn(state);
212188}
213189
214190static TGP_FUNCTION( matrix_write )
215191{
192   model1_state *state = machine->driver_data<model1_state>();
216193   int i;
217194   for(i=0; i<12; i++)
218      cmat[i] = fifoin_pop_f();
195      state->cmat[i] = fifoin_pop_f(state);
219196   logerror("TGP matrix_write %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f) (%x)\n",
220          cmat[0], cmat[1], cmat[2], cmat[3], cmat[4], cmat[5], cmat[6], cmat[7], cmat[8], cmat[9], cmat[10], cmat[11],
221          pushpc);
222   next_fn();
197          state->cmat[0], state->cmat[1], state->cmat[2], state->cmat[3], state->cmat[4], state->cmat[5], state->cmat[6], state->cmat[7], state->cmat[8], state->cmat[9], state->cmat[10], state->cmat[11],
198          state->pushpc);
199   next_fn(state);
223200}
224201
225202static TGP_FUNCTION( clear_stack )
226203{
227   logerror("TGP clear_stack (%x)\n", pushpc);
228   mat_stack_pos = 0;
229   next_fn();
204   model1_state *state = machine->driver_data<model1_state>();
205   logerror("TGP clear_stack (%x)\n", state->pushpc);
206   state->mat_stack_pos = 0;
207   next_fn(state);
230208}
231209
232210static TGP_FUNCTION( matrix_mul )
233211{
212   model1_state *state = machine->driver_data<model1_state>();
234213   float m[12];
235   float a = fifoin_pop_f();
236   float b = fifoin_pop_f();
237   float c = fifoin_pop_f();
238   float d = fifoin_pop_f();
239   float e = fifoin_pop_f();
240   float f = fifoin_pop_f();
241   float g = fifoin_pop_f();
242   float h = fifoin_pop_f();
243   float i = fifoin_pop_f();
244   float j = fifoin_pop_f();
245   float k = fifoin_pop_f();
246   float l = fifoin_pop_f();
247   logerror("TGP matrix_mul %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, pushpc);
248   m[0]  = a*cmat[0] + b*cmat[3] + c*cmat[6];
249   m[1]  = a*cmat[1] + b*cmat[4] + c*cmat[7];
250   m[2]  = a*cmat[2] + b*cmat[5] + c*cmat[8];
251   m[3]  = d*cmat[0] + e*cmat[3] + f*cmat[6];
252   m[4]  = d*cmat[1] + e*cmat[4] + f*cmat[7];
253   m[5]  = d*cmat[2] + e*cmat[5] + f*cmat[8];
254   m[6]  = g*cmat[0] + h*cmat[3] + i*cmat[6];
255   m[7]  = g*cmat[1] + h*cmat[4] + i*cmat[7];
256   m[8]  = g*cmat[2] + h*cmat[5] + i*cmat[8];
257   m[9]  = j*cmat[0] + k*cmat[3] + l*cmat[6] + cmat[9];
258   m[10] = j*cmat[1] + k*cmat[4] + l*cmat[7] + cmat[10];
259   m[11] = j*cmat[2] + k*cmat[5] + l*cmat[8] + cmat[11];
214   float a = fifoin_pop_f(state);
215   float b = fifoin_pop_f(state);
216   float c = fifoin_pop_f(state);
217   float d = fifoin_pop_f(state);
218   float e = fifoin_pop_f(state);
219   float f = fifoin_pop_f(state);
220   float g = fifoin_pop_f(state);
221   float h = fifoin_pop_f(state);
222   float i = fifoin_pop_f(state);
223   float j = fifoin_pop_f(state);
224   float k = fifoin_pop_f(state);
225   float l = fifoin_pop_f(state);
226   logerror("TGP matrix_mul %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, state->pushpc);
227   m[0]  = a*state->cmat[0] + b*state->cmat[3] + c*state->cmat[6];
228   m[1]  = a*state->cmat[1] + b*state->cmat[4] + c*state->cmat[7];
229   m[2]  = a*state->cmat[2] + b*state->cmat[5] + c*state->cmat[8];
230   m[3]  = d*state->cmat[0] + e*state->cmat[3] + f*state->cmat[6];
231   m[4]  = d*state->cmat[1] + e*state->cmat[4] + f*state->cmat[7];
232   m[5]  = d*state->cmat[2] + e*state->cmat[5] + f*state->cmat[8];
233   m[6]  = g*state->cmat[0] + h*state->cmat[3] + i*state->cmat[6];
234   m[7]  = g*state->cmat[1] + h*state->cmat[4] + i*state->cmat[7];
235   m[8]  = g*state->cmat[2] + h*state->cmat[5] + i*state->cmat[8];
236   m[9]  = j*state->cmat[0] + k*state->cmat[3] + l*state->cmat[6] + state->cmat[9];
237   m[10] = j*state->cmat[1] + k*state->cmat[4] + l*state->cmat[7] + state->cmat[10];
238   m[11] = j*state->cmat[2] + k*state->cmat[5] + l*state->cmat[8] + state->cmat[11];
260239
261   memcpy(cmat, m, sizeof(m));
262   next_fn();
240   memcpy(state->cmat, m, sizeof(m));
241   next_fn(state);
263242}
264243
265244static TGP_FUNCTION( anglev )
266245{
267   float a = fifoin_pop_f();
268   float b = fifoin_pop_f();
269   logerror("TGP anglev %f, %f (%x)\n", a, b, pushpc);
246   model1_state *state = machine->driver_data<model1_state>();
247   float a = fifoin_pop_f(state);
248   float b = fifoin_pop_f(state);
249   logerror("TGP anglev %f, %f (%x)\n", a, b, state->pushpc);
270250   if(!b) {
271251      if(a>=0)
272         fifoout_push(0);
252         fifoout_push(state, 0);
273253      else
274         fifoout_push((UINT32)-32768);
254         fifoout_push(state, (UINT32)-32768);
275255   } else if(!a) {
276256      if(b>=0)
277         fifoout_push(16384);
257         fifoout_push(state, 16384);
278258      else
279         fifoout_push((UINT32)-16384);
259         fifoout_push(state, (UINT32)-16384);
280260   } else
281      fifoout_push((INT16)(atan2(b, a)*32768/M_PI));
282   next_fn();
261      fifoout_push(state, (INT16)(atan2(b, a)*32768/M_PI));
262   next_fn(state);
283263}
284264
285265static TGP_FUNCTION( f11 )
286266{
287   float a = fifoin_pop_f();
288   float b = fifoin_pop_f();
289   float c = fifoin_pop_f();
290   float d = fifoin_pop_f();
291   float e = fifoin_pop_f();
292   float f = fifoin_pop_f();
293   float g = fifoin_pop_f();
294   float h = fifoin_pop_f();
295   float i = fifoin_pop_f();
267   model1_state *state = machine->driver_data<model1_state>();
268   float a = fifoin_pop_f(state);
269   float b = fifoin_pop_f(state);
270   float c = fifoin_pop_f(state);
271   float d = fifoin_pop_f(state);
272   float e = fifoin_pop_f(state);
273   float f = fifoin_pop_f(state);
274   float g = fifoin_pop_f(state);
275   float h = fifoin_pop_f(state);
276   float i = fifoin_pop_f(state);
296277   (void)a;
297278   (void)b;
298279   (void)c;
r10427r10428
302283   (void)g;
303284   (void)h;
304285   (void)i;
305   logerror("TGP f11 %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, pushpc);
306   fifoout_push_f(0);
307   fifoout_push_f(0);
308   fifoout_push_f(0);
309   next_fn();
286   logerror("TGP f11 %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, state->pushpc);
287   fifoout_push_f(state, 0);
288   fifoout_push_f(state, 0);
289   fifoout_push_f(state, 0);
290   next_fn(state);
310291}
311292
312293static TGP_FUNCTION( normalize )
313294{
314   float a = fifoin_pop_f();
315   float b = fifoin_pop_f();
316   float c = fifoin_pop_f();
295   model1_state *state = machine->driver_data<model1_state>();
296   float a = fifoin_pop_f(state);
297   float b = fifoin_pop_f(state);
298   float c = fifoin_pop_f(state);
317299   float n = (a*a+b*b+c*c) / sqrt(a*a+b*b+c*c);
318   logerror("TGP normalize %f, %f, %f (%x)\n", a, b, c, pushpc);
319   fifoout_push_f(a/n);
320   fifoout_push_f(b/n);
321   fifoout_push_f(c/n);
322   next_fn();
300   logerror("TGP normalize %f, %f, %f (%x)\n", a, b, c, state->pushpc);
301   fifoout_push_f(state, a/n);
302   fifoout_push_f(state, b/n);
303   fifoout_push_f(state, c/n);
304   next_fn(state);
323305}
324306
325307static TGP_FUNCTION( acc_seti )
326308{
327   INT32 a = fifoin_pop();
328   model1_dump = 1;
329   logerror("TGP acc_seti %d (%x)\n", a, pushpc);
330   acc = a;
331   next_fn();
309   model1_state *state = machine->driver_data<model1_state>();
310   INT32 a = fifoin_pop(state);
311   state->dump = 1;
312   logerror("TGP acc_seti %d (%x)\n", a, state->pushpc);
313   state->acc = a;
314   next_fn(state);
332315}
333316
334317static TGP_FUNCTION( track_select )
335318{
336   INT32 a = fifoin_pop();
337   logerror("TGP track_select %d (%x)\n", a, pushpc);
338   tgp_vr_select = a;
339   next_fn();
319   model1_state *state = machine->driver_data<model1_state>();
320   INT32 a = fifoin_pop(state);
321   logerror("TGP track_select %d (%x)\n", a, state->pushpc);
322   state->tgp_vr_select = a;
323   next_fn(state);
340324}
341325
342326static TGP_FUNCTION( f14 )
343327{
344   tgp_vr_base[0] = fifoin_pop_f();
345   tgp_vr_base[1] = fifoin_pop_f();
346   tgp_vr_base[2] = fifoin_pop_f();
347   tgp_vr_base[3] = fifoin_pop_f();
328   model1_state *state = machine->driver_data<model1_state>();
329   state->tgp_vr_base[0] = fifoin_pop_f(state);
330   state->tgp_vr_base[1] = fifoin_pop_f(state);
331   state->tgp_vr_base[2] = fifoin_pop_f(state);
332   state->tgp_vr_base[3] = fifoin_pop_f(state);
348333
349   next_fn();
334   next_fn(state);
350335}
351336
352337static TGP_FUNCTION( f15_swa )
353338{
354   logerror("TGP f15_swa (%x)\n", pushpc);
339   model1_state *state = machine->driver_data<model1_state>();
340   logerror("TGP f15_swa (%x)\n", state->pushpc);
355341
356   next_fn();
342   next_fn(state);
357343}
358344
359345static TGP_FUNCTION( anglep )
360346{
361   float a = fifoin_pop_f();
362   float b = fifoin_pop_f();
363   float c = fifoin_pop_f();
364   float d = fifoin_pop_f();
365   logerror("TGP anglep %f, %f, %f, %f (%x)\n", a, b, c, d, pushpc);
347   model1_state *state = machine->driver_data<model1_state>();
348   float a = fifoin_pop_f(state);
349   float b = fifoin_pop_f(state);
350   float c = fifoin_pop_f(state);
351   float d = fifoin_pop_f(state);
352   logerror("TGP anglep %f, %f, %f, %f (%x)\n", a, b, c, d, state->pushpc);
366353   c = a - c;
367354   d = b - d;
368355   if(!d) {
369356      if(c>=0)
370         fifoout_push(0);
357         fifoout_push(state, 0);
371358      else
372         fifoout_push((UINT32)-32768);
359         fifoout_push(state, (UINT32)-32768);
373360   } else if(!c) {
374361      if(d>=0)
375         fifoout_push(16384);
362         fifoout_push(state, 16384);
376363      else
377         fifoout_push((UINT32)-16384);
364         fifoout_push(state, (UINT32)-16384);
378365   } else
379      fifoout_push((INT16)(atan2(d, c)*32768/M_PI));
380   next_fn();
366      fifoout_push(state, (INT16)(atan2(d, c)*32768/M_PI));
367   next_fn(state);
381368}
382369
383370static TGP_FUNCTION( matrix_ident )
384371{
385   logerror("TGP matrix_ident (%x)\n", pushpc);
386   memset(cmat, 0, sizeof(cmat));
387   cmat[0] = 1.0;
388   cmat[4] = 1.0;
389   cmat[8] = 1.0;
390   next_fn();
372   model1_state *state = machine->driver_data<model1_state>();
373   logerror("TGP matrix_ident (%x)\n", state->pushpc);
374   memset(state->cmat, 0, sizeof(state->cmat));
375   state->cmat[0] = 1.0;
376   state->cmat[4] = 1.0;
377   state->cmat[8] = 1.0;
378   next_fn(state);
391379}
392380
393381static TGP_FUNCTION( matrix_read )
394382{
383   model1_state *state = machine->driver_data<model1_state>();
395384   int i;
396385   logerror("TGP matrix_read (%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f) (%x)\n",
397          cmat[0], cmat[1], cmat[2], cmat[3], cmat[4], cmat[5], cmat[6], cmat[7], cmat[8], cmat[9], cmat[10], cmat[11], pushpc);
386          state->cmat[0], state->cmat[1], state->cmat[2], state->cmat[3], state->cmat[4], state->cmat[5], state->cmat[6], state->cmat[7], state->cmat[8], state->cmat[9], state->cmat[10], state->cmat[11], state->pushpc);
398387   for(i=0; i<12; i++)
399      fifoout_push_f(cmat[i]);
400   next_fn();
388      fifoout_push_f(state, state->cmat[i]);
389   next_fn(state);
401390}
402391
403392static TGP_FUNCTION( matrix_trans )
404393{
405   float a = fifoin_pop_f();
406   float b = fifoin_pop_f();
407   float c = fifoin_pop_f();
394   model1_state *state = machine->driver_data<model1_state>();
395   float a = fifoin_pop_f(state);
396   float b = fifoin_pop_f(state);
397   float c = fifoin_pop_f(state);
408398
409   cmat[ 9] += cmat[0]*a+cmat[3]*b+cmat[6]*c;
410   cmat[10] += cmat[1]*a+cmat[4]*b+cmat[7]*c;
411   cmat[11] += cmat[2]*a+cmat[5]*b+cmat[8]*c;
412   next_fn();
399   state->cmat[ 9] += state->cmat[0]*a+state->cmat[3]*b+state->cmat[6]*c;
400   state->cmat[10] += state->cmat[1]*a+state->cmat[4]*b+state->cmat[7]*c;
401   state->cmat[11] += state->cmat[2]*a+state->cmat[5]*b+state->cmat[8]*c;
402   next_fn(state);
413403}
414404
415405static TGP_FUNCTION( matrix_scale )
416406{
417   float a = fifoin_pop_f();
418   float b = fifoin_pop_f();
419   float c = fifoin_pop_f();
420   logerror("TGP matrix_scale %f, %f, %f (%x)\n", a, b, c, pushpc);
421   cmat[0] *= a;
422   cmat[1] *= a;
423   cmat[2] *= a;
424   cmat[3] *= b;
425   cmat[4] *= b;
426   cmat[5] *= b;
427   cmat[6] *= c;
428   cmat[7] *= c;
429   cmat[8] *= c;
430   next_fn();
407   model1_state *state = machine->driver_data<model1_state>();
408   float a = fifoin_pop_f(state);
409   float b = fifoin_pop_f(state);
410   float c = fifoin_pop_f(state);
411   logerror("TGP matrix_scale %f, %f, %f (%x)\n", a, b, c, state->pushpc);
412   state->cmat[0] *= a;
413   state->cmat[1] *= a;
414   state->cmat[2] *= a;
415   state->cmat[3] *= b;
416   state->cmat[4] *= b;
417   state->cmat[5] *= b;
418   state->cmat[6] *= c;
419   state->cmat[7] *= c;
420   state->cmat[8] *= c;
421   next_fn(state);
431422}
432423
433424static TGP_FUNCTION( matrix_rotx )
434425{
435   INT16 a = fifoin_pop();
426   model1_state *state = machine->driver_data<model1_state>();
427   INT16 a = fifoin_pop(state);
436428   float s = tsin(a);
437429   float c = tcos(a);
438430   float t1, t2;
439   logerror("TGP matrix_rotx %d (%x)\n", a, pushpc);
440   t1 = cmat[3];
441   t2 = cmat[6];
442   cmat[3] = c*t1-s*t2;
443   cmat[6] = s*t1+c*t2;
444   t1 = cmat[4];
445   t2 = cmat[7];
446   cmat[4] = c*t1-s*t2;
447   cmat[7] = s*t1+c*t2;
448   t1 = cmat[5];
449   t2 = cmat[8];
450   cmat[5] = c*t1-s*t2;
451   cmat[8] = s*t1+c*t2;
452   next_fn();
431   logerror("TGP matrix_rotx %d (%x)\n", a, state->pushpc);
432   t1 = state->cmat[3];
433   t2 = state->cmat[6];
434   state->cmat[3] = c*t1-s*t2;
435   state->cmat[6] = s*t1+c*t2;
436   t1 = state->cmat[4];
437   t2 = state->cmat[7];
438   state->cmat[4] = c*t1-s*t2;
439   state->cmat[7] = s*t1+c*t2;
440   t1 = state->cmat[5];
441   t2 = state->cmat[8];
442   state->cmat[5] = c*t1-s*t2;
443   state->cmat[8] = s*t1+c*t2;
444   next_fn(state);
453445}
454446
455447static TGP_FUNCTION( matrix_roty )
456448{
457   INT16 a = fifoin_pop();
449   model1_state *state = machine->driver_data<model1_state>();
450   INT16 a = fifoin_pop(state);
458451   float s = tsin(a);
459452   float c = tcos(a);
460453   float t1, t2;
461454
462   logerror("TGP matrix_roty %d (%x)\n", a, pushpc);
463   t1 = cmat[6];
464   t2 = cmat[0];
465   cmat[6] = c*t1-s*t2;
466   cmat[0] = s*t1+c*t2;
467   t1 = cmat[7];
468   t2 = cmat[1];
469   cmat[7] = c*t1-s*t2;
470   cmat[1] = s*t1+c*t2;
471   t1 = cmat[8];
472   t2 = cmat[2];
473   cmat[8] = c*t1-s*t2;
474   cmat[2] = s*t1+c*t2;
475   next_fn();
455   logerror("TGP matrix_roty %d (%x)\n", a, state->pushpc);
456   t1 = state->cmat[6];
457   t2 = state->cmat[0];
458   state->cmat[6] = c*t1-s*t2;
459   state->cmat[0] = s*t1+c*t2;
460   t1 = state->cmat[7];
461   t2 = state->cmat[1];
462   state->cmat[7] = c*t1-s*t2;
463   state->cmat[1] = s*t1+c*t2;
464   t1 = state->cmat[8];
465   t2 = state->cmat[2];
466   state->cmat[8] = c*t1-s*t2;
467   state->cmat[2] = s*t1+c*t2;
468   next_fn(state);
476469}
477470
478471static TGP_FUNCTION( matrix_rotz )
479472{
480   INT16 a = fifoin_pop();
473   model1_state *state = machine->driver_data<model1_state>();
474   INT16 a = fifoin_pop(state);
481475   float s = tsin(a);
482476   float c = tcos(a);
483477   float t1, t2;
484478
485   logerror("TGP matrix_rotz %d (%x)\n", a, pushpc);
486   t1 = cmat[0];
487   t2 = cmat[3];
488   cmat[0] = c*t1-s*t2;
489   cmat[3] = s*t1+c*t2;
490   t1 = cmat[1];
491   t2 = cmat[4];
492   cmat[1] = c*t1-s*t2;
493   cmat[4] = s*t1+c*t2;
494   t1 = cmat[2];
495   t2 = cmat[5];
496   cmat[2] = c*t1-s*t2;
497   cmat[5] = s*t1+c*t2;
498   next_fn();
479   logerror("TGP matrix_rotz %d (%x)\n", a, state->pushpc);
480   t1 = state->cmat[0];
481   t2 = state->cmat[3];
482   state->cmat[0] = c*t1-s*t2;
483   state->cmat[3] = s*t1+c*t2;
484   t1 = state->cmat[1];
485   t2 = state->cmat[4];
486   state->cmat[1] = c*t1-s*t2;
487   state->cmat[4] = s*t1+c*t2;
488   t1 = state->cmat[2];
489   t2 = state->cmat[5];
490   state->cmat[2] = c*t1-s*t2;
491   state->cmat[5] = s*t1+c*t2;
492   next_fn(state);
499493}
500494
501495static TGP_FUNCTION( track_read_quad )
502496{
497   model1_state *state = machine->driver_data<model1_state>();
503498   const UINT32 *tgp_data = (const UINT32 *)machine->region("user2")->base();
504   UINT32 a = fifoin_pop();
499   UINT32 a = fifoin_pop(state);
505500   int offd;
506501
507   logerror("TGP track_read_quad %d (%x)\n", a, pushpc);
502   logerror("TGP track_read_quad %d (%x)\n", a, state->pushpc);
508503
509   offd = tgp_data[0x20+tgp_vr_select] + 16*a;
510   fifoout_push(tgp_data[offd]);
511   fifoout_push(tgp_data[offd+1]);
512   fifoout_push(tgp_data[offd+2]);
513   fifoout_push(tgp_data[offd+3]);
514   fifoout_push(tgp_data[offd+4]);
515   fifoout_push(tgp_data[offd+5]);
516   fifoout_push(tgp_data[offd+6]);
517   fifoout_push(tgp_data[offd+7]);
518   fifoout_push(tgp_data[offd+8]);
519   fifoout_push(tgp_data[offd+9]);
520   fifoout_push(tgp_data[offd+10]);
521   fifoout_push(tgp_data[offd+11]);
522   next_fn();
504   offd = tgp_data[0x20+state->tgp_vr_select] + 16*a;
505   fifoout_push(state, tgp_data[offd]);
506   fifoout_push(state, tgp_data[offd+1]);
507   fifoout_push(state, tgp_data[offd+2]);
508   fifoout_push(state, tgp_data[offd+3]);
509   fifoout_push(state, tgp_data[offd+4]);
510   fifoout_push(state, tgp_data[offd+5]);
511   fifoout_push(state, tgp_data[offd+6]);
512   fifoout_push(state, tgp_data[offd+7]);
513   fifoout_push(state, tgp_data[offd+8]);
514   fifoout_push(state, tgp_data[offd+9]);
515   fifoout_push(state, tgp_data[offd+10]);
516   fifoout_push(state, tgp_data[offd+11]);
517   next_fn(state);
523518}
524519
525520static TGP_FUNCTION( f24_swa )
526521{
527   float a = fifoin_pop_f();
528   float b = fifoin_pop_f();
529   float c = fifoin_pop_f();
530   float d = fifoin_pop_f();
531   float e = fifoin_pop_f();
532   float f = fifoin_pop_f();
533   UINT32 g = fifoin_pop();
522   model1_state *state = machine->driver_data<model1_state>();
523   float a = fifoin_pop_f(state);
524   float b = fifoin_pop_f(state);
525   float c = fifoin_pop_f(state);
526   float d = fifoin_pop_f(state);
527   float e = fifoin_pop_f(state);
528   float f = fifoin_pop_f(state);
529   UINT32 g = fifoin_pop(state);
534530   (void)a;
535531   (void)b;
536532   (void)c;
r10427r10428
538534   (void)e;
539535   (void)f;
540536   (void)g;
541   logerror("TGP f24_swa %f, %f, %f, %f, %f, %f, %x (%x)\n", a, b, c, d, e, f, g, pushpc);
542   fifoout_push_f(0);
543   next_fn();
537   logerror("TGP f24_swa %f, %f, %f, %f, %f, %f, %x (%x)\n", a, b, c, d, e, f, g, state->pushpc);
538   fifoout_push_f(state, 0);
539   next_fn(state);
544540}
545541
546542static TGP_FUNCTION( transform_point )
547543{
548   float x = fifoin_pop_f();
549   float y = fifoin_pop_f();
550   float z = fifoin_pop_f();
551   logerror("TGP transform_point %f, %f, %f (%x)\n", x, y, z, pushpc);
544   model1_state *state = machine->driver_data<model1_state>();
545   float x = fifoin_pop_f(state);
546   float y = fifoin_pop_f(state);
547   float z = fifoin_pop_f(state);
548   logerror("TGP transform_point %f, %f, %f (%x)\n", x, y, z, state->pushpc);
552549
553   fifoout_push_f(cmat[0]*x+cmat[3]*y+cmat[6]*z+cmat[9]);
554   fifoout_push_f(cmat[1]*x+cmat[4]*y+cmat[7]*z+cmat[10]);
555   fifoout_push_f(cmat[2]*x+cmat[5]*y+cmat[8]*z+cmat[11]);
556   next_fn();
550   fifoout_push_f(state, state->cmat[0]*x+state->cmat[3]*y+state->cmat[6]*z+state->cmat[9]);
551   fifoout_push_f(state, state->cmat[1]*x+state->cmat[4]*y+state->cmat[7]*z+state->cmat[10]);
552   fifoout_push_f(state, state->cmat[2]*x+state->cmat[5]*y+state->cmat[8]*z+state->cmat[11]);
553   next_fn(state);
557554}
558555
559556static TGP_FUNCTION( fcos_m1 )
560557{
561    INT16 a = fifoin_pop();
562   logerror("TGP fcos %d (%x)\n", a, pushpc);
563   fifoout_push_f(tcos(a));
564   next_fn();
558   model1_state *state = machine->driver_data<model1_state>();
559   INT16 a = fifoin_pop(state);
560   logerror("TGP fcos %d (%x)\n", a, state->pushpc);
561   fifoout_push_f(state, tcos(a));
562   next_fn(state);
565563}
566564
567565static TGP_FUNCTION( fsin_m1 )
568566{
569    INT16 a = fifoin_pop();
570   logerror("TGP fsin %d (%x)\n", a, pushpc);
571   fifoout_push_f(tsin(a));
572   next_fn();
567   model1_state *state = machine->driver_data<model1_state>();
568   INT16 a = fifoin_pop(state);
569   logerror("TGP fsin %d (%x)\n", a, state->pushpc);
570   fifoout_push_f(state, tsin(a));
571   next_fn(state);
573572}
574573
575574static TGP_FUNCTION( fcosm_m1 )
576575{
577    INT16 a = fifoin_pop();
578   float b = fifoin_pop_f();
579   logerror("TGP fcosm %d, %f (%x)\n", a, b, pushpc);
580   fifoout_push_f(b*tcos(a));
581   next_fn();
576   model1_state *state = machine->driver_data<model1_state>();
577   INT16 a = fifoin_pop(state);
578   float b = fifoin_pop_f(state);
579   logerror("TGP fcosm %d, %f (%x)\n", a, b, state->pushpc);
580   fifoout_push_f(state, b*tcos(a));
581   next_fn(state);
582582}
583583
584584static TGP_FUNCTION( fsinm_m1 )
585585{
586    INT16 a = fifoin_pop();
587   float b = fifoin_pop_f();
588   model1_dump = 1;
589   logerror("TGP fsinm %d, %f (%x)\n", a, b, pushpc);
590   fifoout_push_f(b*tsin(a));
591   next_fn();
586   model1_state *state = machine->driver_data<model1_state>();
587   INT16 a = fifoin_pop(state);
588   float b = fifoin_pop_f(state);
589   state->dump = 1;
590   logerror("TGP fsinm %d, %f (%x)\n", a, b, state->pushpc);
591   fifoout_push_f(state, b*tsin(a));
592   next_fn(state);
592593}
593594
594595static TGP_FUNCTION( distance3 )
595596{
596   float a = fifoin_pop_f();
597   float b = fifoin_pop_f();
598   float c = fifoin_pop_f();
599   float d = fifoin_pop_f();
600   float e = fifoin_pop_f();
601   float f = fifoin_pop_f();
602   logerror("TGP distance3 (%f, %f, %f), (%f, %f, %f) (%x)\n", a, b, c, d, e, f, pushpc);
597   model1_state *state = machine->driver_data<model1_state>();
598   float a = fifoin_pop_f(state);
599   float b = fifoin_pop_f(state);
600   float c = fifoin_pop_f(state);
601   float d = fifoin_pop_f(state);
602   float e = fifoin_pop_f(state);
603   float f = fifoin_pop_f(state);
604   logerror("TGP distance3 (%f, %f, %f), (%f, %f, %f) (%x)\n", a, b, c, d, e, f, state->pushpc);
603605   a -= d;
604606   b -= e;
605607   c -= f;
606   fifoout_push_f((a*a+b*b+c*c)/sqrt(a*a+b*b+c*c));
607   next_fn();
608   fifoout_push_f(state, (a*a+b*b+c*c)/sqrt(a*a+b*b+c*c));
609   next_fn(state);
608610}
609611
610612static TGP_FUNCTION( ftoi )
611613{
612   float a = fifoin_pop_f();
613   logerror("TGP ftoi %f (%x)\n", a, pushpc);
614   fifoout_push((int)a);
615   next_fn();
614   model1_state *state = machine->driver_data<model1_state>();
615   float a = fifoin_pop_f(state);
616   logerror("TGP ftoi %f (%x)\n", a, state->pushpc);
617   fifoout_push(state, (int)a);
618   next_fn(state);
616619}
617620
618621static TGP_FUNCTION( itof )
619622{
620   INT32 a = fifoin_pop();
621   logerror("TGP itof %d (%x)\n", a, pushpc);
622   fifoout_push_f(a);
623   next_fn();
623   model1_state *state = machine->driver_data<model1_state>();
624   INT32 a = fifoin_pop(state);
625   logerror("TGP itof %d (%x)\n", a, state->pushpc);
626   fifoout_push_f(state, a);
627   next_fn(state);
624628}
625629
626630static TGP_FUNCTION( acc_set )
627631{
628   float a = fifoin_pop_f();
629   logerror("TGP acc_set %f (%x)\n", a, pushpc);
630   acc = a;
631   next_fn();
632   model1_state *state = machine->driver_data<model1_state>();
633   float a = fifoin_pop_f(state);
634   logerror("TGP acc_set %f (%x)\n", a, state->pushpc);
635   state->acc = a;
636   next_fn(state);
632637}
633638
634639static TGP_FUNCTION( acc_get )
635640{
636   logerror("TGP acc_get (%x)\n", pushpc);
637   fifoout_push_f(acc);
638   next_fn();
641   model1_state *state = machine->driver_data<model1_state>();
642   logerror("TGP acc_get (%x)\n", state->pushpc);
643   fifoout_push_f(state, state->acc);
644   next_fn(state);
639645}
640646
641647static TGP_FUNCTION( acc_add )
642648{
643   float a = fifoin_pop_f();
644   logerror("TGP acc_add %f (%x)\n", a, pushpc);
645   acc += a;
646   next_fn();
649   model1_state *state = machine->driver_data<model1_state>();
650   float a = fifoin_pop_f(state);
651   logerror("TGP acc_add %f (%x)\n", a, state->pushpc);
652   state->acc += a;
653   next_fn(state);
647654}
648655
649656static TGP_FUNCTION( acc_sub )
650657{
651   float a = fifoin_pop_f();
652   logerror("TGP acc_sub %f (%x)\n", a, pushpc);
653   acc -= a;
654   next_fn();
658   model1_state *state = machine->driver_data<model1_state>();
659   float a = fifoin_pop_f(state);
660   logerror("TGP acc_sub %f (%x)\n", a, state->pushpc);
661   state->acc -= a;
662   next_fn(state);
655663}
656664
657665static TGP_FUNCTION( acc_mul )
658666{
659   float a = fifoin_pop_f();
660   logerror("TGP acc_mul %f (%x)\n", a, pushpc);
661   acc *= a;
662   next_fn();
667   model1_state *state = machine->driver_data<model1_state>();
668   float a = fifoin_pop_f(state);
669   logerror("TGP acc_mul %f (%x)\n", a, state->pushpc);
670   state->acc *= a;
671   next_fn(state);
663672}
664673
665674static TGP_FUNCTION( acc_div )
666675{
667   float a = fifoin_pop_f();
668   logerror("TGP acc_div %f (%x)\n", a, pushpc);
669   acc /= a;
670   next_fn();
676   model1_state *state = machine->driver_data<model1_state>();
677   float a = fifoin_pop_f(state);
678   logerror("TGP acc_div %f (%x)\n", a, state->pushpc);
679   state->acc /= a;
680   next_fn(state);
671681}
672682
673683static TGP_FUNCTION( f42 )
674684{
675   float a = fifoin_pop_f();
676   float b = fifoin_pop_f();
677   float c = fifoin_pop_f();
685   model1_state *state = machine->driver_data<model1_state>();
686   float a = fifoin_pop_f(state);
687   float b = fifoin_pop_f(state);
688   float c = fifoin_pop_f(state);
678689   (void)a;
679690   (void)b;
680691   (void)c;
681   logerror("TGP f42 %f, %f, %f (%x)\n", a, b, c, pushpc);
692   logerror("TGP f42 %f, %f, %f (%x)\n", a, b, c, state->pushpc);
682693   //  fifoout_push_f((machine->rand() % 1000) - 500);
683   fifoout_push_f(0);
684   fifoout_push_f(0);
685   fifoout_push_f(0);
686   fifoout_push_f(0);
687   fifoout_push_f(0);
688   fifoout_push_f(0);
689   next_fn();
694   fifoout_push_f(state, 0);
695   fifoout_push_f(state, 0);
696   fifoout_push_f(state, 0);
697   fifoout_push_f(state, 0);
698   fifoout_push_f(state, 0);
699   fifoout_push_f(state, 0);
700   next_fn(state);
690701}
691702
692703
r10427r10428
694705
695706static TGP_FUNCTION( xyz2rqf )
696707{
697   float a = fifoin_pop_f();
698   float b = fifoin_pop_f();
699   float c = fifoin_pop_f();
708   model1_state *state = machine->driver_data<model1_state>();
709   float a = fifoin_pop_f(state);
710   float b = fifoin_pop_f(state);
711   float c = fifoin_pop_f(state);
700712   float norm;
701713   (void)a;
702714   (void)b;
703715   (void)c;
704   logerror("TGP xyz2rqf %f, %f, %f (%x)\n", a, b, c, pushpc);
705   fifoout_push_f((a*a+b*b+c*c)/sqrt(a*a+b*b+c*c));
716   logerror("TGP xyz2rqf %f, %f, %f (%x)\n", a, b, c, state->pushpc);
717   fifoout_push_f(state, (a*a+b*b+c*c)/sqrt(a*a+b*b+c*c));
706718   norm = sqrt(a*a+c*c);
707719   if(!c) {
708720      if(a>=0)
709         fifoout_push(0);
721         fifoout_push(state, 0);
710722      else
711         fifoout_push((UINT32)-32768);
723         fifoout_push(state, (UINT32)-32768);
712724   } else if(!a) {
713725      if(c>=0)
714         fifoout_push(16384);
726         fifoout_push(state, 16384);
715727      else
716         fifoout_push((UINT32)-16384);
728         fifoout_push(state, (UINT32)-16384);
717729   } else
718      fifoout_push((INT16)(atan2(c, a)*32768/M_PI));
730      fifoout_push(state, (INT16)(atan2(c, a)*32768/M_PI));
719731
720732   if(!b)
721      fifoout_push(0);
733      fifoout_push(state, 0);
722734   else if(!norm) {
723735      if(b>=0)
724         fifoout_push(16384);
736         fifoout_push(state, 16384);
725737      else
726         fifoout_push((UINT32)-16384);
738         fifoout_push(state, (UINT32)-16384);
727739   } else
728      fifoout_push((INT16)(atan2(b, norm)*32768/M_PI));
740      fifoout_push(state, (INT16)(atan2(b, norm)*32768/M_PI));
729741
730   next_fn();
742   next_fn(state);
731743}
732744
733745static TGP_FUNCTION( f43 )
734746{
735   float a = fifoin_pop_f();
736   float b = fifoin_pop_f();
737   float c = fifoin_pop_f();
738   float d = fifoin_pop_f();
739   float e = fifoin_pop_f();
740   float f = fifoin_pop_f();
747   model1_state *state = machine->driver_data<model1_state>();
748   float a = fifoin_pop_f(state);
749   float b = fifoin_pop_f(state);
750   float c = fifoin_pop_f(state);
751   float d = fifoin_pop_f(state);
752   float e = fifoin_pop_f(state);
753   float f = fifoin_pop_f(state);
741754   (void)a;
742755   (void)b;
743756   (void)c;
744757   (void)d;
745758   (void)e;
746759   (void)f;
747   logerror("TGP f43 %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, pushpc);
748   fifoout_push_f(0);
749   fifoout_push_f(0);
750   fifoout_push_f(0);
751   fifoout_push_f(0);
752   next_fn();
760   logerror("TGP f43 %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, state->pushpc);
761   fifoout_push_f(state, 0);
762   fifoout_push_f(state, 0);
763   fifoout_push_f(state, 0);
764   fifoout_push_f(state, 0);
765   next_fn(state);
753766}
754767
755768static TGP_FUNCTION( f43_swa )
756769{
757   float a = fifoin_pop_f();
758   int b = fifoin_pop();
759   int c = fifoin_pop();
770   model1_state *state = machine->driver_data<model1_state>();
771   float a = fifoin_pop_f(state);
772   int b = fifoin_pop(state);
773   int c = fifoin_pop(state);
760774   (void)a;
761775   (void)b;
762776   (void)c;
763   logerror("TGP f43_swa %f, %d, %d (%x)\n", a, b, c, pushpc);
764   fifoout_push_f(0);
765   fifoout_push_f(0);
766   fifoout_push_f(0);
767   next_fn();
777   logerror("TGP f43_swa %f, %d, %d (%x)\n", a, b, c, state->pushpc);
778   fifoout_push_f(state, 0);
779   fifoout_push_f(state, 0);
780   fifoout_push_f(state, 0);
781   next_fn(state);
768782}
769783
770784static TGP_FUNCTION( f44 )
771785{
772   float a = fifoin_pop_f();
786   model1_state *state = machine->driver_data<model1_state>();
787   float a = fifoin_pop_f(state);
773788   (void)a;
774   logerror("TGP f44 %f (%x)\n", a, pushpc);
775   fifoout_push_f(0);
776   fifoout_push_f(0);
777   fifoout_push_f(0);
778   next_fn();
789   logerror("TGP f44 %f (%x)\n", a, state->pushpc);
790   fifoout_push_f(state, 0);
791   fifoout_push_f(state, 0);
792   fifoout_push_f(state, 0);
793   next_fn(state);
779794}
780795
781796static TGP_FUNCTION( matrix_sdir )
782797{
783   float a = fifoin_pop_f();
784   float b = fifoin_pop_f();
785   float c = fifoin_pop_f();
798   model1_state *state = machine->driver_data<model1_state>();
799   float a = fifoin_pop_f(state);
800   float b = fifoin_pop_f(state);
801   float c = fifoin_pop_f(state);
786802   float norm = sqrt(a*a+b*b+c*c);
787803   float t[9], m[9];
788   logerror("TGP matrix_sdir %f, %f, %f (%x)\n", a, b, c, pushpc);
804   logerror("TGP matrix_sdir %f, %f, %f (%x)\n", a, b, c, state->pushpc);
789805
790806   memset(t, 0, sizeof(t));
791807
r10427r10428
813829      t[5] /= norm;
814830   }
815831
816   m[0]  = t[0]*cmat[0] + t[1]*cmat[3] + t[2]*cmat[6];
817   m[1]  = t[0]*cmat[1] + t[1]*cmat[4] + t[2]*cmat[7];
818   m[2]  = t[0]*cmat[2] + t[1]*cmat[5] + t[2]*cmat[8];
819   m[3]  = t[3]*cmat[0] + t[4]*cmat[3] + t[5]*cmat[6];
820   m[4]  = t[3]*cmat[1] + t[4]*cmat[4] + t[5]*cmat[7];
821   m[5]  = t[3]*cmat[2] + t[4]*cmat[5] + t[5]*cmat[8];
822   m[6]  = t[6]*cmat[0] + t[7]*cmat[3] + t[8]*cmat[6];
823   m[7]  = t[6]*cmat[1] + t[7]*cmat[4] + t[8]*cmat[7];
824   m[8]  = t[6]*cmat[2] + t[7]*cmat[5] + t[8]*cmat[8];
832   m[0]  = t[0]*state->cmat[0] + t[1]*state->cmat[3] + t[2]*state->cmat[6];
833   m[1]  = t[0]*state->cmat[1] + t[1]*state->cmat[4] + t[2]*state->cmat[7];
834   m[2]  = t[0]*state->cmat[2] + t[1]*state->cmat[5] + t[2]*state->cmat[8];
835   m[3]  = t[3]*state->cmat[0] + t[4]*state->cmat[3] + t[5]*state->cmat[6];
836   m[4]  = t[3]*state->cmat[1] + t[4]*state->cmat[4] + t[5]*state->cmat[7];
837   m[5]  = t[3]*state->cmat[2] + t[4]*state->cmat[5] + t[5]*state->cmat[8];
838   m[6]  = t[6]*state->cmat[0] + t[7]*state->cmat[3] + t[8]*state->cmat[6];
839   m[7]  = t[6]*state->cmat[1] + t[7]*state->cmat[4] + t[8]*state->cmat[7];
840   m[8]  = t[6]*state->cmat[2] + t[7]*state->cmat[5] + t[8]*state->cmat[8];
825841
826   memcpy(cmat, m, sizeof(m));
842   memcpy(state->cmat, m, sizeof(m));
827843
828   next_fn();
844   next_fn(state);
829845}
830846
831847static TGP_FUNCTION( f45 )
832848{
833   float a = fifoin_pop_f();
849   model1_state *state = machine->driver_data<model1_state>();
850   float a = fifoin_pop_f(state);
834851   (void)a;
835   logerror("TGP f45 %f (%x)\n", a, pushpc);
836   fifoout_push_f(0);
837   next_fn();
852   logerror("TGP f45 %f (%x)\n", a, state->pushpc);
853   fifoout_push_f(state, 0);
854   next_fn(state);
838855}
839856
840857static TGP_FUNCTION( vlength )
841858{
842   float a = fifoin_pop_f() - tgp_vr_base[0];
843   float b = fifoin_pop_f() - tgp_vr_base[1];
844   float c = fifoin_pop_f() - tgp_vr_base[2];
845   logerror("TGP vlength %f, %f, %f (%x)\n", a, b, c, pushpc);
859   model1_state *state = machine->driver_data<model1_state>();
860   float a = fifoin_pop_f(state) - state->tgp_vr_base[0];
861   float b = fifoin_pop_f(state) - state->tgp_vr_base[1];
862   float c = fifoin_pop_f(state) - state->tgp_vr_base[2];
863   logerror("TGP vlength %f, %f, %f (%x)\n", a, b, c, state->pushpc);
846864
847865   a = (a*a+b*b+c*c);
848866   b = 1/sqrt(a);
849867   c = a * b;
850   c -= tgp_vr_base[3];
851   fifoout_push_f(c);
852   next_fn();
868   c -= state->tgp_vr_base[3];
869   fifoout_push_f(state, c);
870   next_fn(state);
853871}
854872
855873static TGP_FUNCTION( f47 )
856874{
857   float a = fifoin_pop_f();
858   float b = fifoin_pop_f();
859   float c = fifoin_pop_f();
860   logerror("TGP f47 %f, %f, %f (%x)\n", a, b, c, pushpc);
861   fifoout_push_f(a+c);
862   fifoout_push_f(b+c);
863   next_fn();
875   model1_state *state = machine->driver_data<model1_state>();
876   float a = fifoin_pop_f(state);
877   float b = fifoin_pop_f(state);
878   float c = fifoin_pop_f(state);
879   logerror("TGP f47 %f, %f, %f (%x)\n", a, b, c, state->pushpc);
880   fifoout_push_f(state, a+c);
881   fifoout_push_f(state, b+c);
882   next_fn(state);
864883}
865884
866885static TGP_FUNCTION( track_read_info )
867886{
887   model1_state *state = machine->driver_data<model1_state>();
868888   const UINT32 *tgp_data = (const UINT32 *)machine->region("user2")->base();
869    UINT16 a = fifoin_pop();
889   UINT16 a = fifoin_pop(state);
870890   int offd;
871891
872   logerror("TGP track_read_info %d (%x)\n", a, pushpc);
892   logerror("TGP track_read_info %d (%x)\n", a, state->pushpc);
873893
874   offd = tgp_data[0x20+tgp_vr_select] + 16*a;
875   fifoout_push(tgp_data[offd+15]);
876   next_fn();
894   offd = tgp_data[0x20+state->tgp_vr_select] + 16*a;
895   fifoout_push(state, tgp_data[offd+15]);
896   next_fn(state);
877897}
878898
879899static TGP_FUNCTION( colbox_set )
880900{
881   float a = fifoin_pop_f();
882   float b = fifoin_pop_f();
883   float c = fifoin_pop_f();
884   float d = fifoin_pop_f();
885   float e = fifoin_pop_f();
886   float f = fifoin_pop_f();
887   float g = fifoin_pop_f();
888   float h = fifoin_pop_f();
889   float i = fifoin_pop_f();
890   float j = fifoin_pop_f();
891   float k = fifoin_pop_f();
892   float l = fifoin_pop_f();
893   logerror("TGP colbox_set %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, pushpc);
894   tgp_vr_cbox[ 0] = a;
895   tgp_vr_cbox[ 1] = b;
896   tgp_vr_cbox[ 2] = c;
897   tgp_vr_cbox[ 3] = d;
898   tgp_vr_cbox[ 4] = e;
899   tgp_vr_cbox[ 5] = f;
900   tgp_vr_cbox[ 6] = g;
901   tgp_vr_cbox[ 7] = h;
902   tgp_vr_cbox[ 8] = i;
903   tgp_vr_cbox[ 9] = j;
904   tgp_vr_cbox[10] = k;
905   tgp_vr_cbox[11] = l;
906   next_fn();
901   model1_state *state = machine->driver_data<model1_state>();
902   float a = fifoin_pop_f(state);
903   float b = fifoin_pop_f(state);
904   float c = fifoin_pop_f(state);
905   float d = fifoin_pop_f(state);
906   float e = fifoin_pop_f(state);
907   float f = fifoin_pop_f(state);
908   float g = fifoin_pop_f(state);
909   float h = fifoin_pop_f(state);
910   float i = fifoin_pop_f(state);
911   float j = fifoin_pop_f(state);
912   float k = fifoin_pop_f(state);
913   float l = fifoin_pop_f(state);
914   logerror("TGP colbox_set %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, state->pushpc);
915   state->tgp_vr_cbox[ 0] = a;
916   state->tgp_vr_cbox[ 1] = b;
917   state->tgp_vr_cbox[ 2] = c;
918   state->tgp_vr_cbox[ 3] = d;
919   state->tgp_vr_cbox[ 4] = e;
920   state->tgp_vr_cbox[ 5] = f;
921   state->tgp_vr_cbox[ 6] = g;
922   state->tgp_vr_cbox[ 7] = h;
923   state->tgp_vr_cbox[ 8] = i;
924   state->tgp_vr_cbox[ 9] = j;
925   state->tgp_vr_cbox[10] = k;
926   state->tgp_vr_cbox[11] = l;
927   next_fn(state);
907928}
908929
909930static TGP_FUNCTION( colbox_test )
910931{
911   float a = fifoin_pop_f();
912   float b = fifoin_pop_f();
913   float c = fifoin_pop_f();
932   model1_state *state = machine->driver_data<model1_state>();
933   float a = fifoin_pop_f(state);
934   float b = fifoin_pop_f(state);
935   float c = fifoin_pop_f(state);
914936   (void)a;
915937   (void)b;
916938   (void)c;
917   logerror("TGP colbox_test %f, %f, %f (%x)\n", a, b, c, pushpc);
939   logerror("TGP colbox_test %f, %f, %f (%x)\n", a, b, c, state->pushpc);
918940
919   // #### Wrong, need to check with the tgp_vr_cbox coordinates
941   // #### Wrong, need to check with the state->tgp_vr_cbox coordinates
920942   // Game only test sign, negative = collision
921   fifoout_push_f(-1);
922   next_fn();
943   fifoout_push_f(state, -1);
944   next_fn(state);
923945}
924946
925947static TGP_FUNCTION( f49_swa )
926948{
927   float a = fifoin_pop_f();
928   float b = fifoin_pop_f();
929   float c = fifoin_pop_f();
930   float d = fifoin_pop_f();
931   float e = fifoin_pop_f();
932   float f = fifoin_pop_f();
949   model1_state *state = machine->driver_data<model1_state>();
950   float a = fifoin_pop_f(state);
951   float b = fifoin_pop_f(state);
952   float c = fifoin_pop_f(state);
953   float d = fifoin_pop_f(state);
954   float e = fifoin_pop_f(state);
955   float f = fifoin_pop_f(state);
933956   (void)a;
934957   (void)b;
935958   (void)c;
936959   (void)d;
937960   (void)e;
938961   (void)f;
939   logerror("TGP f49_swa %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, pushpc);
940   next_fn();
962   logerror("TGP f49_swa %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, state->pushpc);
963   next_fn(state);
941964}
942965
943966static TGP_FUNCTION( f50_swa )
944967{
945    float a = fifoin_pop_f();
946   float b = fifoin_pop_f();
947   float c = fifoin_pop_f();
948   float d = fifoin_pop_f();
968   model1_state *state = machine->driver_data<model1_state>();
969   float a = fifoin_pop_f(state);
970   float b = fifoin_pop_f(state);
971   float c = fifoin_pop_f(state);
972   float d = fifoin_pop_f(state);
949973   (void)a;
950974   (void)b;
951975   (void)c;
952976   (void)d;
953   logerror("TGP f50_swa %f, %f, %f, %f (%x)\n", a, b, c, d, pushpc);
954   fifoout_push_f(d);
955   next_fn();
977   logerror("TGP f50_swa %f, %f, %f, %f (%x)\n", a, b, c, d, state->pushpc);
978   fifoout_push_f(state, d);
979   next_fn(state);
956980}
957981
958982static TGP_FUNCTION( f52 )
959983{
960   logerror("TGP f52 (%x)\n", pushpc);
961   next_fn();
984   model1_state *state = machine->driver_data<model1_state>();
985   logerror("TGP f52 (%x)\n", state->pushpc);
986   next_fn(state);
962987}
963988
964989static TGP_FUNCTION( matrix_rdir )
965990{
966   float a = fifoin_pop_f();
967   float b = fifoin_pop_f();
968   float c = fifoin_pop_f();
991   model1_state *state = machine->driver_data<model1_state>();
992   float a = fifoin_pop_f(state);
993   float b = fifoin_pop_f(state);
994   float c = fifoin_pop_f(state);
969995   float norm = sqrt(a*a+c*c);
970996   float t1, t2;
971997   (void)b;
972998
973   logerror("TGP matrix_rdir %f, %f, %f (%x)\n", a, b, c, pushpc);
999   logerror("TGP matrix_rdir %f, %f, %f (%x)\n", a, b, c, state->pushpc);
9741000
9751001   if(!norm) {
9761002      c = 1;
r10427r10428
9801006      a /= norm;
9811007   }
9821008
983   t1 = cmat[6];
984   t2 = cmat[0];
985   cmat[6] = c*t1-a*t2;
986   cmat[0] = a*t1+c*t2;
987   t1 = cmat[7];
988   t2 = cmat[1];
989   cmat[7] = c*t1-a*t2;
990   cmat[1] = a*t1+c*t2;
991   t1 = cmat[8];
992   t2 = cmat[2];
993   cmat[8] = c*t1-a*t2;
994   cmat[2] = a*t1+c*t2;
995   next_fn();
1009   t1 = state->cmat[6];
1010   t2 = state->cmat[0];
1011   state->cmat[6] = c*t1-a*t2;
1012   state->cmat[0] = a*t1+c*t2;
1013   t1 = state->cmat[7];
1014   t2 = state->cmat[1];
1015   state->cmat[7] = c*t1-a*t2;
1016   state->cmat[1] = a*t1+c*t2;
1017   t1 = state->cmat[8];
1018   t2 = state->cmat[2];
1019   state->cmat[8] = c*t1-a*t2;
1020   state->cmat[2] = a*t1+c*t2;
1021   next_fn(state);
9961022}
9971023
9981024// A+(B-A)*t1 + (C-A)*t2 = P
r10427r10428
10121038
10131039static TGP_FUNCTION( track_lookup )
10141040{
1041   model1_state *state = machine->driver_data<model1_state>();
10151042   const UINT32 *tgp_data = (const UINT32 *)machine->region("user2")->base();
1016   float a = fifoin_pop_f();
1017   UINT32 b = fifoin_pop();
1018   float c = fifoin_pop_f();
1019   float d = fifoin_pop_f();
1043   float a = fifoin_pop_f(state);
1044   UINT32 b = fifoin_pop(state);
1045   float c = fifoin_pop_f(state);
1046   float d = fifoin_pop_f(state);
10201047   int offi, offd, len;
10211048   float dist;
10221049   int i;
10231050   UINT32 behaviour, entry;
10241051   float height;
10251052
1026   logerror("TGP track_lookup %f, 0x%x, %f, %f (%x)\n", a, b, c, d, pushpc);
1053   logerror("TGP track_lookup %f, 0x%x, %f, %f (%x)\n", a, b, c, d, state->pushpc);
10271054
1028   offi = tgp_data[0x10+tgp_vr_select] + b;
1029   offd = tgp_data[0x20+tgp_vr_select];
1055   offi = tgp_data[0x10+state->tgp_vr_select] + b;
1056   offd = tgp_data[0x20+state->tgp_vr_select];
10301057
10311058   len = tgp_data[offi++];
10321059
r10427r10428
10611088      }
10621089   }
10631090
1064   ram_data[0x0000] = 0; // non zero = still computing
1065   ram_data[0x8001] = f2u(height);
1066   ram_data[0x8002] = entry;
1091   state->ram_data[0x0000] = 0; // non zero = still computing
1092   state->ram_data[0x8001] = f2u(height);
1093   state->ram_data[0x8002] = entry;
10671094
1068   next_fn();
1095   next_fn(state);
10691096}
10701097
10711098static TGP_FUNCTION( f56 )
10721099{
1073   float a = fifoin_pop_f();
1074   float b = fifoin_pop_f();
1075   float c = fifoin_pop_f();
1076   float d = fifoin_pop_f();
1077   float e = fifoin_pop_f();
1078   float f = fifoin_pop_f();
1079   UINT32 g = fifoin_pop();
1100   model1_state *state = machine->driver_data<model1_state>();
1101   float a = fifoin_pop_f(state);
1102   float b = fifoin_pop_f(state);
1103   float c = fifoin_pop_f(state);
1104   float d = fifoin_pop_f(state);
1105   float e = fifoin_pop_f(state);
1106   float f = fifoin_pop_f(state);
1107   UINT32 g = fifoin_pop(state);
10801108   (void)a;
10811109   (void)b;
10821110   (void)c;
r10427r10428
10851113   (void)f;
10861114   (void)g;
10871115
1088   logerror("TGP f56 %f, %f, %f, %f, %f, %f, %d (%x)\n", a, b, c, d, e, f, g, pushpc);
1089   fifoout_push(0);
1090   next_fn();
1116   logerror("TGP f56 %f, %f, %f, %f, %f, %f, %d (%x)\n", a, b, c, d, e, f, g, state->pushpc);
1117   fifoout_push(state, 0);
1118   next_fn(state);
10911119}
10921120
10931121static TGP_FUNCTION( f57 )
10941122{
1095   logerror("TGP f57 (%x)\n", pushpc);
1096   fifoout_push_f(0);
1097   fifoout_push_f(0);
1098   fifoout_push_f(0);
1099   next_fn();
1123   model1_state *state = machine->driver_data<model1_state>();
1124   logerror("TGP f57 (%x)\n", state->pushpc);
1125   fifoout_push_f(state, 0);
1126   fifoout_push_f(state, 0);
1127   fifoout_push_f(state, 0);
1128   next_fn(state);
11001129}
11011130
11021131static TGP_FUNCTION( matrix_readt )
11031132{
1104   logerror("TGP matrix_readt (%x)\n", pushpc);
1105   fifoout_push_f(cmat[9]);
1106   fifoout_push_f(cmat[10]);
1107   fifoout_push_f(cmat[11]);
1108   next_fn();
1133   model1_state *state = machine->driver_data<model1_state>();
1134   logerror("TGP matrix_readt (%x)\n", state->pushpc);
1135   fifoout_push_f(state, state->cmat[9]);
1136   fifoout_push_f(state, state->cmat[10]);
1137   fifoout_push_f(state, state->cmat[11]);
1138   next_fn(state);
11091139}
11101140
11111141static TGP_FUNCTION( acc_geti )
11121142{
1113   logerror("TGP acc_geti (%x)\n", pushpc);
1114   fifoout_push((int)acc);
1115   next_fn();
1143   model1_state *state = machine->driver_data<model1_state>();
1144   logerror("TGP acc_geti (%x)\n", state->pushpc);
1145   fifoout_push(state, (int)state->acc);
1146   next_fn(state);
11161147}
11171148
11181149static TGP_FUNCTION( f60 )
11191150{
1120   logerror("TGP f60 (%x)\n", pushpc);
1121   fifoout_push_f(0);
1122   fifoout_push_f(0);
1123   fifoout_push_f(0);
1124   next_fn();
1151   model1_state *state = machine->driver_data<model1_state>();
1152   logerror("TGP f60 (%x)\n", state->pushpc);
1153   fifoout_push_f(state, 0);
1154   fifoout_push_f(state, 0);
1155   fifoout_push_f(state, 0);
1156   next_fn(state);
11251157}
11261158
11271159static TGP_FUNCTION( col_setcirc )
11281160{
1129   float a = fifoin_pop_f();
1130   float b = fifoin_pop_f();
1131   float c = fifoin_pop_f();
1132   logerror("TGP col_setcirc %f, %f, %f (%x)\n", a, b, c, pushpc);
1133   tgp_vr_circx = a;
1134   tgp_vr_circy = b;
1135   tgp_vr_circrad = c;
1136   next_fn();
1161   model1_state *state = machine->driver_data<model1_state>();
1162   float a = fifoin_pop_f(state);
1163   float b = fifoin_pop_f(state);
1164   float c = fifoin_pop_f(state);
1165   logerror("TGP col_setcirc %f, %f, %f (%x)\n", a, b, c, state->pushpc);
1166   state->tgp_vr_circx = a;
1167   state->tgp_vr_circy = b;
1168   state->tgp_vr_circrad = c;
1169   next_fn(state);
11371170}
11381171
11391172static TGP_FUNCTION( col_testpt )
11401173{
1174   model1_state *state = machine->driver_data<model1_state>();
11411175   float x, y;
1142   float a = fifoin_pop_f();
1143   float b = fifoin_pop_f();
1144   logerror("TGP col_testpt %f, %f (%x)\n", a, b, pushpc);
1145   x = a - tgp_vr_circx;
1146   y = b - tgp_vr_circy;
1147   fifoout_push_f(((x*x+y*y)/sqrt(x*x+y*y)) - tgp_vr_circrad);
1148   next_fn();
1176   float a = fifoin_pop_f(state);
1177   float b = fifoin_pop_f(state);
1178   logerror("TGP col_testpt %f, %f (%x)\n", a, b, state->pushpc);
1179   x = a - state->tgp_vr_circx;
1180   y = b - state->tgp_vr_circy;
1181   fifoout_push_f(state, ((x*x+y*y)/sqrt(x*x+y*y)) - state->tgp_vr_circrad);
1182   next_fn(state);
11491183}
11501184
11511185static TGP_FUNCTION( push_and_ident )
11521186{
1153   if(mat_stack_pos != MAT_STACK_SIZE) {
1154      memcpy(mat_stack[mat_stack_pos], cmat, sizeof(cmat));
1155      mat_stack_pos++;
1187   model1_state *state = machine->driver_data<model1_state>();
1188   if(state->mat_stack_pos != MAT_STACK_SIZE) {
1189      memcpy(state->mat_stack[state->mat_stack_pos], state->cmat, sizeof(state->cmat));
1190      state->mat_stack_pos++;
11561191   }
1157   logerror("TGP push_and_ident (depth=%d, pc=%x)\n", mat_stack_pos, pushpc);
1158   memset(cmat, 0, sizeof(cmat));
1159   cmat[0] = 1.0;
1160   cmat[4] = 1.0;
1161   cmat[8] = 1.0;
1162   next_fn();
1192   logerror("TGP push_and_ident (depth=%d, pc=%x)\n", state->mat_stack_pos, state->pushpc);
1193   memset(state->cmat, 0, sizeof(state->cmat));
1194   state->cmat[0] = 1.0;
1195   state->cmat[4] = 1.0;
1196   state->cmat[8] = 1.0;
1197   next_fn(state);
11631198}
11641199
11651200static TGP_FUNCTION( catmull_rom )
11661201{
1167   float a = fifoin_pop_f();
1168   float b = fifoin_pop_f();
1169   float c = fifoin_pop_f();
1170   float d = fifoin_pop_f();
1171   float e = fifoin_pop_f();
1172   float f = fifoin_pop_f();
1173   float g = fifoin_pop_f();
1174   float h = fifoin_pop_f();
1175   float i = fifoin_pop_f();
1176   float j = fifoin_pop_f();
1177   float k = fifoin_pop_f();
1178   float l = fifoin_pop_f();
1179   float m = fifoin_pop_f();
1202   model1_state *state = machine->driver_data<model1_state>();
1203   float a = fifoin_pop_f(state);
1204   float b = fifoin_pop_f(state);
1205   float c = fifoin_pop_f(state);
1206   float d = fifoin_pop_f(state);
1207   float e = fifoin_pop_f(state);
1208   float f = fifoin_pop_f(state);
1209   float g = fifoin_pop_f(state);
1210   float h = fifoin_pop_f(state);
1211   float i = fifoin_pop_f(state);
1212   float j = fifoin_pop_f(state);
1213   float k = fifoin_pop_f(state);
1214   float l = fifoin_pop_f(state);
1215   float m = fifoin_pop_f(state);
11801216   float m2, m3;
11811217   float w1, w2, w3, w4;
11821218
1183   logerror("TGP catmull_rom %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, m, pushpc);
1219   logerror("TGP catmull_rom %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, m, state->pushpc);
11841220
11851221   m2 = m*m;
11861222   m3 = m*m*m;
r10427r10428
11901226   w3 = 0.5*(-3*m3+4*m2+m);
11911227   w4 = 0.5*(m3-m2);
11921228
1193   fifoout_push_f(a*w1+d*w2+g*w3+j*w4);
1194   fifoout_push_f(b*w1+e*w2+h*w3+k*w4);
1195   fifoout_push_f(c*w1+f*w2+i*w3+l*w4);
1196   next_fn();
1229   fifoout_push_f(state, a*w1+d*w2+g*w3+j*w4);
1230   fifoout_push_f(state, b*w1+e*w2+h*w3+k*w4);
1231   fifoout_push_f(state, c*w1+f*w2+i*w3+l*w4);
1232   next_fn(state);
11971233}
11981234
11991235static TGP_FUNCTION( distance )
12001236{
1201   float a = fifoin_pop_f();
1202   float b = fifoin_pop_f();
1203   float c = fifoin_pop_f();
1204   float d = fifoin_pop_f();
1205   logerror("TGP distance (%f, %f), (%f, %f) (%x)\n", a, b, c, d, pushpc);
1237   model1_state *state = machine->driver_data<model1_state>();
1238   float a = fifoin_pop_f(state);
1239   float b = fifoin_pop_f(state);
1240   float c = fifoin_pop_f(state);
1241   float d = fifoin_pop_f(state);
1242   logerror("TGP distance (%f, %f), (%f, %f) (%x)\n", a, b, c, d, state->pushpc);
12061243   c -= a;
12071244   d -= b;
1208   fifoout_push_f((c*c+d*d)/sqrt(c*c+d*d));
1209   next_fn();
1245   fifoout_push_f(state, (c*c+d*d)/sqrt(c*c+d*d));
1246   next_fn(state);
12101247}
12111248
12121249static TGP_FUNCTION( car_move )
12131250{
1214   INT16 a = fifoin_pop();
1215   float b = fifoin_pop_f();
1216   float c = fifoin_pop_f();
1217   float d = fifoin_pop_f();
1251   model1_state *state = machine->driver_data<model1_state>();
1252   INT16 a = fifoin_pop(state);
1253   float b = fifoin_pop_f(state);
1254   float c = fifoin_pop_f(state);
1255   float d = fifoin_pop_f(state);
12181256   float dx, dy;
1219   logerror("TGP car_move (%d, %f), (%f, %f) (%x)\n", a, b, c, d, pushpc);
1257   logerror("TGP car_move (%d, %f), (%f, %f) (%x)\n", a, b, c, d, state->pushpc);
12201258
12211259   dx = b*tsin(a);
12221260   dy = b*tcos(a);
12231261
1224   fifoout_push_f(dx);
1225   fifoout_push_f(dy);
1226   fifoout_push_f(c+dx);
1227   fifoout_push_f(d+dy);
1228   next_fn();
1262   fifoout_push_f(state, dx);
1263   fifoout_push_f(state, dy);
1264   fifoout_push_f(state, c+dx);
1265   fifoout_push_f(state, d+dy);
1266   next_fn(state);
12291267}
12301268
12311269static TGP_FUNCTION( cpa )
12321270{
1271   model1_state *state = machine->driver_data<model1_state>();
12331272   float dv_x, dv_y, dv_z, dv2, dw_x, dw_y, dw_z, dt;
12341273
1235   float a = fifoin_pop_f();
1236   float b = fifoin_pop_f();
1237   float c = fifoin_pop_f();
1238   float d = fifoin_pop_f();
1239   float e = fifoin_pop_f();
1240   float f = fifoin_pop_f();
1241   float g = fifoin_pop_f();
1242   float h = fifoin_pop_f();
1243   float i = fifoin_pop_f();
1244   float j = fifoin_pop_f();
1245   float k = fifoin_pop_f();
1246   float l = fifoin_pop_f();
1247   logerror("TGP cpa %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, pushpc);
1274   float a = fifoin_pop_f(state);
1275   float b = fifoin_pop_f(state);
1276   float c = fifoin_pop_f(state);
1277   float d = fifoin_pop_f(state);
1278   float e = fifoin_pop_f(state);
1279   float f = fifoin_pop_f(state);
1280   float g = fifoin_pop_f(state);
1281   float h = fifoin_pop_f(state);
1282   float i = fifoin_pop_f(state);
1283   float j = fifoin_pop_f(state);
1284   float k = fifoin_pop_f(state);
1285   float l = fifoin_pop_f(state);
1286   logerror("TGP cpa %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, state->pushpc);
12481287
12491288   dv_x = (b-a) - (d-c);
12501289   dv_y = (f-e) - (h-g);
r10427r10428
12681307   dv_z = (i-k)*(1-dt) + (j-l)*dt;
12691308   dv2 = dv_x*dv_x + dv_y*dv_y + dv_z*dv_z;
12701309
1271   fifoout_push_f(sqrt(dv2));
1272   next_fn();
1310   fifoout_push_f(state, sqrt(dv2));
1311   next_fn(state);
12731312}
12741313
12751314static TGP_FUNCTION( vmat_store )
12761315{
1277   UINT32 a = fifoin_pop();
1316   model1_state *state = machine->driver_data<model1_state>();
1317   UINT32 a = fifoin_pop(state);
12781318   if(a<21)
1279      memcpy(mat_vector[a], cmat, sizeof(cmat));
1319      memcpy(state->mat_vector[a], state->cmat, sizeof(state->cmat));
12801320   else
12811321      logerror("TGP ERROR bad vector index\n");
1282   logerror("TGP vmat_store %d (%x)\n", a, pushpc);
1283   next_fn();
1322   logerror("TGP vmat_store %d (%x)\n", a, state->pushpc);
1323   next_fn(state);
12841324}
12851325
12861326static TGP_FUNCTION( vmat_restore )
12871327{
1288   UINT32 a = fifoin_pop();
1328   model1_state *state = machine->driver_data<model1_state>();
1329   UINT32 a = fifoin_pop(state);
12891330   if(a<21)
1290      memcpy(cmat, mat_vector[a], sizeof(cmat));
1331      memcpy(state->cmat, state->mat_vector[a], sizeof(state->cmat));
12911332   else
12921333      logerror("TGP ERROR bad vector index\n");
1293   logerror("TGP vmat_restore %d (%x)\n", a, pushpc);
1294   next_fn();
1334   logerror("TGP vmat_restore %d (%x)\n", a, state->pushpc);
1335   next_fn(state);
12951336}
12961337
12971338static TGP_FUNCTION( vmat_mul )
12981339{
1299   UINT32 a = fifoin_pop();
1300   UINT32 b = fifoin_pop();
1340   model1_state *state = machine->driver_data<model1_state>();
1341   UINT32 a = fifoin_pop(state);
1342   UINT32 b = fifoin_pop(state);
13011343   if(a<21 && b<21) {
1302      mat_vector[b][0]  = mat_vector[a][ 0]*cmat[0] + mat_vector[a][ 1]*cmat[3] + mat_vector[a][ 2]*cmat[6];
1303      mat_vector[b][1]  = mat_vector[a][ 0]*cmat[1] + mat_vector[a][ 1]*cmat[4] + mat_vector[a][ 2]*cmat[7];
1304      mat_vector[b][2]  = mat_vector[a][ 0]*cmat[2] + mat_vector[a][ 1]*cmat[5] + mat_vector[a][ 2]*cmat[8];
1305      mat_vector[b][3]  = mat_vector[a][ 3]*cmat[0] + mat_vector[a][ 4]*cmat[3] + mat_vector[a][ 5]*cmat[6];
1306      mat_vector[b][4]  = mat_vector[a][ 3]*cmat[1] + mat_vector[a][ 4]*cmat[4] + mat_vector[a][ 5]*cmat[7];
1307      mat_vector[b][5]  = mat_vector[a][ 3]*cmat[2] + mat_vector[a][ 4]*cmat[5] + mat_vector[a][ 5]*cmat[8];
1308      mat_vector[b][6]  = mat_vector[a][ 6]*cmat[0] + mat_vector[a][ 7]*cmat[3] + mat_vector[a][ 8]*cmat[6];
1309      mat_vector[b][7]  = mat_vector[a][ 6]*cmat[1] + mat_vector[a][ 7]*cmat[4] + mat_vector[a][ 8]*cmat[7];
1310      mat_vector[b][8]  = mat_vector[a][ 6]*cmat[2] + mat_vector[a][ 7]*cmat[5] + mat_vector[a][ 8]*cmat[8];
1311      mat_vector[b][9]  = mat_vector[a][ 9]*cmat[0] + mat_vector[a][10]*cmat[3] + mat_vector[a][11]*cmat[6] + cmat[9];
1312      mat_vector[b][10] = mat_vector[a][ 9]*cmat[1] + mat_vector[a][10]*cmat[4] + mat_vector[a][11]*cmat[7] + cmat[10];
1313      mat_vector[b][11] = mat_vector[a][ 9]*cmat[2] + mat_vector[a][10]*cmat[5] + mat_vector[a][11]*cmat[8] + cmat[11];
1344      state->mat_vector[b][0]  = state->mat_vector[a][ 0]*state->cmat[0] + state->mat_vector[a][ 1]*state->cmat[3] + state->mat_vector[a][ 2]*state->cmat[6];
1345      state->mat_vector[b][1]  = state->mat_vector[a][ 0]*state->cmat[1] + state->mat_vector[a][ 1]*state->cmat[4] + state->mat_vector[a][ 2]*state->cmat[7];
1346      state->mat_vector[b][2]  = state->mat_vector[a][ 0]*state->cmat[2] + state->mat_vector[a][ 1]*state->cmat[5] + state->mat_vector[a][ 2]*state->cmat[8];
1347      state->mat_vector[b][3]  = state->mat_vector[a][ 3]*state->cmat[0] + state->mat_vector[a][ 4]*state->cmat[3] + state->mat_vector[a][ 5]*state->cmat[6];
1348      state->mat_vector[b][4]  = state->mat_vector[a][ 3]*state->cmat[1] + state->mat_vector[a][ 4]*state->cmat[4] + state->mat_vector[a][ 5]*state->cmat[7];
1349      state->mat_vector[b][5]  = state->mat_vector[a][ 3]*state->cmat[2] + state->mat_vector[a][ 4]*state->cmat[5] + state->mat_vector[a][ 5]*state->cmat[8];
1350      state->mat_vector[b][6]  = state->mat_vector[a][ 6]*state->cmat[0] + state->mat_vector[a][ 7]*state->cmat[3] + state->mat_vector[a][ 8]*state->cmat[6];
1351      state->mat_vector[b][7]  = state->mat_vector[a][ 6]*state->cmat[1] + state->mat_vector[a][ 7]*state->cmat[4] + state->mat_vector[a][ 8]*state->cmat[7];
1352      state->mat_vector[b][8]  = state->mat_vector[a][ 6]*state->cmat[2] + state->mat_vector[a][ 7]*state->cmat[5] + state->mat_vector[a][ 8]*state->cmat[8];
1353      state->mat_vector[b][9]  = state->mat_vector[a][ 9]*state->cmat[0] + state->mat_vector[a][10]*state->cmat[3] + state->mat_vector[a][11]*state->cmat[6] + state->cmat[9];
1354      state->mat_vector[b][10] = state->mat_vector[a][ 9]*state->cmat[1] + state->mat_vector[a][10]*state->cmat[4] + state->mat_vector[a][11]*state->cmat[7] + state->cmat[10];
1355      state->mat_vector[b][11] = state->mat_vector[a][ 9]*state->cmat[2] + state->mat_vector[a][10]*state->cmat[5] + state->mat_vector[a][11]*state->cmat[8] + state->cmat[11];
13141356   } else
13151357      logerror("TGP ERROR bad vector index\n");
1316   logerror("TGP vmat_mul %d, %d (%x)\n", a, b, pushpc);
1317   next_fn();
1358   logerror("TGP vmat_mul %d, %d (%x)\n", a, b, state->pushpc);
1359   next_fn(state);
13181360}
13191361
13201362static TGP_FUNCTION( vmat_read )
13211363{
1322   UINT32 a = fifoin_pop();
1323   logerror("TGP vmat_read %d (%x)\n", a, pushpc);
1364   model1_state *state = machine->driver_data<model1_state>();
1365   UINT32 a = fifoin_pop(state);
1366   logerror("TGP vmat_read %d (%x)\n", a, state->pushpc);
13241367   if(a<21) {
13251368      int i;
13261369      for(i=0; i<12; i++)
1327         fifoout_push_f(mat_vector[a][i]);
1370         fifoout_push_f(state, state->mat_vector[a][i]);
13281371   } else {
13291372      int i;
13301373      logerror("TGP ERROR bad vector index\n");
13311374      for(i=0; i<12; i++)
1332         fifoout_push_f(0);
1375         fifoout_push_f(state, 0);
13331376   }
1334   next_fn();
1377   next_fn(state);
13351378}
13361379
13371380static TGP_FUNCTION( matrix_rtrans )
13381381{
1339   logerror("TGP matrix_rtrans (%x)\n", pushpc);
1340   fifoout_push_f(cmat[ 9]);
1341   fifoout_push_f(cmat[10]);
1342   fifoout_push_f(cmat[11]);
1343   next_fn();
1382   model1_state *state = machine->driver_data<model1_state>();
1383   logerror("TGP matrix_rtrans (%x)\n", state->pushpc);
1384   fifoout_push_f(state, state->cmat[ 9]);
1385   fifoout_push_f(state, state->cmat[10]);
1386   fifoout_push_f(state, state->cmat[11]);
1387   next_fn(state);
13441388}
13451389
13461390static TGP_FUNCTION( matrix_unrot )
13471391{
1348   logerror("TGP matrix_unrot (%x)\n", pushpc);
1349   memset(cmat, 0, 9*sizeof(cmat[0]));
1350   cmat[0] = 1.0;
1351   cmat[4] = 1.0;
1352   cmat[8] = 1.0;
1353   next_fn();
1392   model1_state *state = machine->driver_data<model1_state>();
1393   logerror("TGP matrix_unrot (%x)\n", state->pushpc);
1394   memset(state->cmat, 0, 9*sizeof(state->cmat[0]));
1395   state->cmat[0] = 1.0;
1396   state->cmat[4] = 1.0;
1397   state->cmat[8] = 1.0;
1398   next_fn(state);
13541399}
13551400
13561401static TGP_FUNCTION( f80 )
13571402{
1358   logerror("TGP f80 (%x)\n", pushpc);
1359   //  cmat[9] = cmat[10] = cmat[11] = 0;
1360   next_fn();
1403   model1_state *state = machine->driver_data<model1_state>();
1404   logerror("TGP f80 (%x)\n", state->pushpc);
1405   //  state->cmat[9] = state->cmat[10] = state->cmat[11] = 0;
1406   next_fn(state);
13611407}
13621408
13631409static TGP_FUNCTION( vmat_save )
13641410{
1365   UINT32 a = fifoin_pop();
1411   model1_state *state = machine->driver_data<model1_state>();
1412   UINT32 a = fifoin_pop(state);
13661413   int i;
1367   logerror("TGP vmat_save 0x%x (%x)\n", a, pushpc);
1414   logerror("TGP vmat_save 0x%x (%x)\n", a, state->pushpc);
13681415   for(i=0; i<16; i++)
1369      memcpy(ram_data+a+0x10*i, mat_vector[i], sizeof(cmat));
1370   next_fn();
1416      memcpy(state->ram_data+a+0x10*i, state->mat_vector[i], sizeof(state->cmat));
1417   next_fn(state);
13711418}
13721419
13731420static TGP_FUNCTION( vmat_load )
13741421{
1375   UINT32 a = fifoin_pop();
1422   model1_state *state = machine->driver_data<model1_state>();
1423   UINT32 a = fifoin_pop(state);
13761424   int i;
1377   logerror("TGP vmat_load 0x%x (%x)\n", a, pushpc);
1425   logerror("TGP vmat_load 0x%x (%x)\n", a, state->pushpc);
13781426   for(i=0; i<16; i++)
1379      memcpy(mat_vector[i], ram_data+a+0x10*i, sizeof(cmat));
1380   next_fn();
1427      memcpy(state->mat_vector[i], state->ram_data+a+0x10*i, sizeof(state->cmat));
1428   next_fn(state);
13811429}
13821430
13831431static TGP_FUNCTION( ram_setadr )
13841432{
1385    ram_scanadr = fifoin_pop() - 0x8000;
1386   logerror("TGP f0 ram_setadr 0x%x (%x)\n", ram_scanadr+0x8000, pushpc);
1387   next_fn();
1433   model1_state *state = machine->driver_data<model1_state>();
1434   state->ram_scanadr = fifoin_pop(state) - 0x8000;
1435   logerror("TGP f0 ram_setadr 0x%x (%x)\n", state->ram_scanadr+0x8000, state->pushpc);
1436   next_fn(state);
13881437}
13891438
13901439static TGP_FUNCTION( groundbox_test )
13911440{
1441   model1_state *state = machine->driver_data<model1_state>();
13921442   int out_x, out_y, out_z;
13931443   float x, /*y,*/ z;
1394   float a = fifoin_pop_f();
1395   float b = fifoin_pop_f();
1396   float c = fifoin_pop_f();
1444   float a = fifoin_pop_f(state);
1445   float b = fifoin_pop_f(state);
1446   float c = fifoin_pop_f(state);
13971447
1398   logerror("TGP groundbox_test %f, %f, %f (%x)\n", a, b, c, pushpc);
1399   x = cmat[0]*a+cmat[3]*b+cmat[6]*c+cmat[9];
1400   //y = cmat[1]*a+cmat[4]*b+cmat[7]*c+cmat[10];
1401   z = cmat[2]*a+cmat[5]*b+cmat[8]*c+cmat[11];
1448   logerror("TGP groundbox_test %f, %f, %f (%x)\n", a, b, c, state->pushpc);
1449   x = state->cmat[0]*a+state->cmat[3]*b+state->cmat[6]*c+state->cmat[9];
1450   //y = state->cmat[1]*a+state->cmat[4]*b+state->cmat[7]*c+state->cmat[10];
1451   z = state->cmat[2]*a+state->cmat[5]*b+state->cmat[8]*c+state->cmat[11];
14021452
1403   out_x = x < tgp_vf_xmin || x > tgp_vf_xmax;
1404   out_z = z < tgp_vf_zmin || z > tgp_vf_zmax;
1453   out_x = x < state->tgp_vf_xmin || x > state->tgp_vf_xmax;
1454   out_z = z < state->tgp_vf_zmin || z > state->tgp_vf_zmax;
14051455   out_y = 1; // Wrong, but untestable it seems.
14061456
1407   fifoout_push(out_x);
1408   fifoout_push(out_y);
1409   fifoout_push(out_z);
1410   next_fn();
1457   fifoout_push(state, out_x);
1458   fifoout_push(state, out_y);
1459   fifoout_push(state, out_z);
1460   next_fn(state);
14111461}
14121462
14131463static TGP_FUNCTION( f89 )
14141464{
1415    UINT32 a = fifoin_pop();
1416   UINT32 b = fifoin_pop();
1417    UINT32 c = fifoin_pop();
1418   UINT32 d = fifoin_pop();
1465   model1_state *state = machine->driver_data<model1_state>();
1466   UINT32 a = fifoin_pop(state);
1467   UINT32 b = fifoin_pop(state);
1468   UINT32 c = fifoin_pop(state);
1469   UINT32 d = fifoin_pop(state);
14191470   (void)a;
14201471   (void)b;
14211472   (void)c;
1422   logerror("TGP list set base 0x%x, 0x%x, %d, length=%d (%x)\n", a, b, c, d, pushpc);
1423   list_length = d;
1424   next_fn();
1473   logerror("TGP list set base 0x%x, 0x%x, %d, length=%d (%x)\n", a, b, c, d, state->pushpc);
1474   state->list_length = d;
1475   next_fn(state);
14251476}
14261477
14271478static TGP_FUNCTION( f92 )
14281479{
1429   float a = fifoin_pop_f();
1430   float b = fifoin_pop_f();
1431   float c = fifoin_pop_f();
1432   float d = fifoin_pop_f();
1480   model1_state *state = machine->driver_data<model1_state>();
1481   float a = fifoin_pop_f(state);
1482   float b = fifoin_pop_f(state);
1483   float c = fifoin_pop_f(state);
1484   float d = fifoin_pop_f(state);
14331485   (void)a;
14341486   (void)b;
14351487   (void)c;
14361488   (void)d;
1437   logerror("TGP f92 %f, %f, %f, %f (%x)\n", a, b, c, d, pushpc);
1438   next_fn();
1489   logerror("TGP f92 %f, %f, %f, %f (%x)\n", a, b, c, d, state->pushpc);
1490   next_fn(state);
14391491}
14401492
14411493static TGP_FUNCTION( f93 )
14421494{
1443   float a = fifoin_pop_f();
1495   model1_state *state = machine->driver_data<model1_state>();
1496   float a = fifoin_pop_f(state);
14441497   (void)a;
1445   logerror("TGP f93 %f (%x)\n", a, pushpc);
1446   next_fn();
1498   logerror("TGP f93 %f (%x)\n", a, state->pushpc);
1499   next_fn(state);
14471500}
14481501
14491502static TGP_FUNCTION( f94 )
14501503{
1451   UINT32 a = fifoin_pop();
1504   model1_state *state = machine->driver_data<model1_state>();
1505   UINT32 a = fifoin_pop(state);
14521506   (void)a;
1453   logerror("TGP f94 %d (%x)\n", a, pushpc);
1454   next_fn();
1507   logerror("TGP f94 %d (%x)\n", a, state->pushpc);
1508   next_fn(state);
14551509}
14561510
14571511static TGP_FUNCTION( vmat_flatten )
14581512{
1513   model1_state *state = machine->driver_data<model1_state>();
14591514   int i;
14601515   float m[12];
1461   logerror("TGP vmat_flatten (%x)\n", pushpc);
1516   logerror("TGP vmat_flatten (%x)\n", state->pushpc);
14621517
14631518   for(i=0; i<16; i++) {
1464      memcpy(m, mat_vector[i], sizeof(cmat));
1519      memcpy(m, state->mat_vector[i], sizeof(state->cmat));
14651520      m[1] = m[4] = m[7] = m[10] = 0;
14661521
1467      mat_vector[i][0]  = m[ 0]*cmat[0] + m[ 1]*cmat[3] + m[ 2]*cmat[6];
1468      mat_vector[i][1]  = m[ 0]*cmat[1] + m[ 1]*cmat[4] + m[ 2]*cmat[7];
1469      mat_vector[i][2]  = m[ 0]*cmat[2] + m[ 1]*cmat[5] + m[ 2]*cmat[8];
1470      mat_vector[i][3]  = m[ 3]*cmat[0] + m[ 4]*cmat[3] + m[ 5]*cmat[6];
1471      mat_vector[i][4]  = m[ 3]*cmat[1] + m[ 4]*cmat[4] + m[ 5]*cmat[7];
1472      mat_vector[i][5]  = m[ 3]*cmat[2] + m[ 4]*cmat[5] + m[ 5]*cmat[8];
1473      mat_vector[i][6]  = m[ 6]*cmat[0] + m[ 7]*cmat[3] + m[ 8]*cmat[6];
1474      mat_vector[i][7]  = m[ 6]*cmat[1] + m[ 7]*cmat[4] + m[ 8]*cmat[7];
1475      mat_vector[i][8]  = m[ 6]*cmat[2] + m[ 7]*cmat[5] + m[ 8]*cmat[8];
1476      mat_vector[i][9]  = m[ 9]*cmat[0] + m[10]*cmat[3] + m[11]*cmat[6] + cmat[9];
1477      mat_vector[i][10] = m[ 9]*cmat[1] + m[10]*cmat[4] + m[11]*cmat[7] + cmat[10];
1478      mat_vector[i][11] = m[ 9]*cmat[2] + m[10]*cmat[5] + m[11]*cmat[8] + cmat[11];
1522      state->mat_vector[i][0]  = m[ 0]*state->cmat[0] + m[ 1]*state->cmat[3] + m[ 2]*state->cmat[6];
1523      state->mat_vector[i][1]  = m[ 0]*state->cmat[1] + m[ 1]*state->cmat[4] + m[ 2]*state->cmat[7];
1524      state->mat_vector[i][2]  = m[ 0]*state->cmat[2] + m[ 1]*state->cmat[5] + m[ 2]*state->cmat[8];
1525      state->mat_vector[i][3]  = m[ 3]*state->cmat[0] + m[ 4]*state->cmat[3] + m[ 5]*state->cmat[6];
1526      state->mat_vector[i][4]  = m[ 3]*state->cmat[1] + m[ 4]*state->cmat[4] + m[ 5]*state->cmat[7];
1527      state->mat_vector[i][5]  = m[ 3]*state->cmat[2] + m[ 4]*state->cmat[5] + m[ 5]*state->cmat[8];
1528      state->mat_vector[i][6]  = m[ 6]*state->cmat[0] + m[ 7]*state->cmat[3] + m[ 8]*state->cmat[6];
1529      state->mat_vector[i][7]  = m[ 6]*state->cmat[1] + m[ 7]*state->cmat[4] + m[ 8]*state->cmat[7];
1530      state->mat_vector[i][8]  = m[ 6]*state->cmat[2] + m[ 7]*state->cmat[5] + m[ 8]*state->cmat[8];
1531      state->mat_vector[i][9]  = m[ 9]*state->cmat[0] + m[10]*state->cmat[3] + m[11]*state->cmat[6] + state->cmat[9];
1532      state->mat_vector[i][10] = m[ 9]*state->cmat[1] + m[10]*state->cmat[4] + m[11]*state->cmat[7] + state->cmat[10];
1533      state->mat_vector[i][11] = m[ 9]*state->cmat[2] + m[10]*state->cmat[5] + m[11]*state->cmat[8] + state->cmat[11];
14791534   }
1480   next_fn();
1535   next_fn(state);
14811536}
14821537
14831538static TGP_FUNCTION( vmat_load1 )
14841539{
1485   UINT32 a = fifoin_pop();
1486   logerror("TGP vmat_load1 0x%x (%x)\n", a, pushpc);
1487   memcpy(cmat, ram_data+a, sizeof(cmat));
1488   next_fn();
1540   model1_state *state = machine->driver_data<model1_state>();
1541   UINT32 a = fifoin_pop(state);
1542   logerror("TGP vmat_load1 0x%x (%x)\n", a, state->pushpc);
1543   memcpy(state->cmat, state->ram_data+a, sizeof(state->cmat));
1544   next_fn(state);
14891545}
14901546
14911547static TGP_FUNCTION( ram_trans )
14921548{
1493   float a = ram_get_f();
1494   float b = ram_get_f();
1495   float c = ram_get_f();
1496   logerror("TGP ram_trans (%x)\n", pushpc);
1497   cmat[ 9] += cmat[0]*a+cmat[3]*b+cmat[6]*c;
1498   cmat[10] += cmat[1]*a+cmat[4]*b+cmat[7]*c;
1499   cmat[11] += cmat[2]*a+cmat[5]*b+cmat[8]*c;
1500   next_fn();
1549   model1_state *state = machine->driver_data<model1_state>();
1550   float a = ram_get_f(state);
1551   float b = ram_get_f(state);
1552   float c = ram_get_f(state);
1553   logerror("TGP ram_trans (%x)\n", state->pushpc);
1554   state->cmat[ 9] += state->cmat[0]*a+state->cmat[3]*b+state->cmat[6]*c;
1555   state->cmat[10] += state->cmat[1]*a+state->cmat[4]*b+state->cmat[7]*c;
1556   state->cmat[11] += state->cmat[2]*a+state->cmat[5]*b+state->cmat[8]*c;
1557   next_fn(state);
15011558}
15021559
15031560static TGP_FUNCTION( f98_load )
15041561{
1562   model1_state *state = machine->driver_data<model1_state>();
15051563   int i;
1506   for(i=0; i<list_length; i++) {
1507      float f = fifoin_pop_f();
1564   for(i=0; i<state->list_length; i++) {
1565      float f = fifoin_pop_f(state);
15081566      (void)f;
1509      logerror("TGP load list (%2d/%2d) %f (%x)\n", i, list_length, f, pushpc);
1567      logerror("TGP load list (%2d/%2d) %f (%x)\n", i, state->list_length, f, state->pushpc);
15101568   }
1511   next_fn();
1569   next_fn(state);
15121570}
15131571
15141572static TGP_FUNCTION( f98 )
15151573{
1516    UINT32 a = fifoin_pop();
1574   model1_state *state = machine->driver_data<model1_state>();
1575   UINT32 a = fifoin_pop(state);
15171576   (void)a;
1518   logerror("TGP load list start %d (%x)\n", a, pushpc);
1519   fifoin_cbcount = list_length;
1520   fifoin_cb = f98_load;
1577   logerror("TGP load list start %d (%x)\n", a, state->pushpc);
1578   state->fifoin_cbcount = state->list_length;
1579   state->fifoin_cb = f98_load;
15211580}
15221581
15231582static TGP_FUNCTION( f99 )
15241583{
1525   logerror("TGP f99 (%x)\n", pushpc);
1526   next_fn();
1584   model1_state *state = machine->driver_data<model1_state>();
1585   logerror("TGP f99 (%x)\n", state->pushpc);
1586   next_fn(state);
15271587}
15281588
15291589static TGP_FUNCTION( f100 )
15301590{
1591   model1_state *state = machine->driver_data<model1_state>();
15311592   int i;
1532   logerror("TGP f100 get list (%x)\n", pushpc);
1533   for(i=0; i<list_length; i++)
1534      fifoout_push_f((machine->rand() % 1000)/100.0);
1535   next_fn();
1593   logerror("TGP f100 get list (%x)\n", state->pushpc);
1594   for(i=0; i<state->list_length; i++)
1595      fifoout_push_f(state, (machine->rand() % 1000)/100.0);
1596   next_fn(state);
15361597}
15371598
15381599static TGP_FUNCTION( groundbox_set )
15391600{
1540   float a = fifoin_pop_f();
1541   float b = fifoin_pop_f();
1542   float c = fifoin_pop_f();
1543   float d = fifoin_pop_f();
1544   float e = fifoin_pop_f();
1545   float f = fifoin_pop_f();
1546   float g = fifoin_pop_f();
1547   logerror("TGP groundbox_set %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, pushpc);
1548   tgp_vf_xmin = e;
1549   tgp_vf_xmax = d;
1550   tgp_vf_zmin = g;
1551   tgp_vf_zmax = f;
1552   tgp_vf_ygnd = b;
1553   tgp_vf_yflr = a;
1554   tgp_vf_yjmp = c;
1601   model1_state *state = machine->driver_data<model1_state>();
1602   float a = fifoin_pop_f(state);
1603   float b = fifoin_pop_f(state);
1604   float c = fifoin_pop_f(state);
1605   float d = fifoin_pop_f(state);
1606   float e = fifoin_pop_f(state);
1607   float f = fifoin_pop_f(state);
1608   float g = fifoin_pop_f(state);
1609   logerror("TGP groundbox_set %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, state->pushpc);
1610   state->tgp_vf_xmin = e;
1611   state->tgp_vf_xmax = d;
1612   state->tgp_vf_zmin = g;
1613   state->tgp_vf_zmax = f;
1614   state->tgp_vf_ygnd = b;
1615   state->tgp_vf_yflr = a;
1616   state->tgp_vf_yjmp = c;
15551617
1556   next_fn();
1618   next_fn(state);
15571619}
15581620
15591621static TGP_FUNCTION( f102 )
15601622{
1561   static int ccount = 0;
1623   model1_state *state = machine->driver_data<model1_state>();
15621624   float px, py, pz;
1563   float a = fifoin_pop_f();
1564   float b = fifoin_pop_f();
1565   float c = fifoin_pop_f();
1566   float d = fifoin_pop_f();
1567   float e = fifoin_pop_f();
1568   UINT32 f = fifoin_pop();
1569   UINT32 g = fifoin_pop();
1570   UINT32 h = fifoin_pop();
1625   float a = fifoin_pop_f(state);
1626   float b = fifoin_pop_f(state);
1627   float c = fifoin_pop_f(state);
1628   float d = fifoin_pop_f(state);
1629   float e = fifoin_pop_f(state);
1630   UINT32 f = fifoin_pop(state);
1631   UINT32 g = fifoin_pop(state);
1632   UINT32 h = fifoin_pop(state);
15711633
1572   ccount++;
1634   state->ccount++;
15731635
1574   logerror("TGP f0 mve_calc %f, %f, %f, %f, %f, %d, %d, %d (%d) (%x)\n", a, b, c, d, e, f, g, h, ccount, pushpc);
1636   logerror("TGP f0 mve_calc %f, %f, %f, %f, %f, %d, %d, %d (%d) (%x)\n", a, b, c, d, e, f, g, h, state->ccount, state->pushpc);
15751637
1576   px = u2f(ram_data[ram_scanadr+0x16]);
1577   py = u2f(ram_data[ram_scanadr+0x17]);
1578   pz = u2f(ram_data[ram_scanadr+0x18]);
1638   px = u2f(state->ram_data[state->ram_scanadr+0x16]);
1639   py = u2f(state->ram_data[state->ram_scanadr+0x17]);
1640   pz = u2f(state->ram_data[state->ram_scanadr+0x18]);
15791641
1580   //  memset(cmat, 0, sizeof(cmat));
1581   //  cmat[0] = 1.0;
1582   //  cmat[4] = 1.0;
1583   //  cmat[8] = 1.0;
1642   //  memset(state->cmat, 0, sizeof(state->cmat));
1643   //  state->cmat[0] = 1.0;
1644   //  state->cmat[4] = 1.0;
1645   //  state->cmat[8] = 1.0;
15841646
15851647   px = c;
15861648   py = d;
15871649   pz = e;
15881650
15891651#if 1
1590   cmat[ 9] += cmat[0]*a+cmat[3]*b+cmat[6]*c;
1591   cmat[10] += cmat[1]*a+cmat[4]*b+cmat[7]*c;
1592   cmat[11] += cmat[2]*a+cmat[5]*b+cmat[8]*c;
1652   state->cmat[ 9] += state->cmat[0]*a+state->cmat[3]*b+state->cmat[6]*c;
1653   state->cmat[10] += state->cmat[1]*a+state->cmat[4]*b+state->cmat[7]*c;
1654   state->cmat[11] += state->cmat[2]*a+state->cmat[5]*b+state->cmat[8]*c;
15931655#else
1594   cmat[ 9] += px;
1595   cmat[10] += py;
1596   cmat[11] += pz;
1656   state->cmat[ 9] += px;
1657   state->cmat[10] += py;
1658   state->cmat[11] += pz;
15971659#endif
15981660
15991661   logerror("    f0 mve_calc %f, %f, %f\n", px, py, pz);
16001662
1601   fifoout_push_f(c);
1602   fifoout_push_f(d);
1603   fifoout_push_f(e);
1604   fifoout_push(f);
1605   fifoout_push(g);
1606   fifoout_push(h);
1663   fifoout_push_f(state, c);
1664   fifoout_push_f(state, d);
1665   fifoout_push_f(state, e);
1666   fifoout_push(state, f);
1667   fifoout_push(state, g);
1668   fifoout_push(state, h);
16071669
16081670
1609   next_fn();
1671   next_fn(state);
16101672}
16111673
16121674static TGP_FUNCTION( f103 )
16131675{
1614    ram_scanadr = fifoin_pop() - 0x8000;
1615   logerror("TGP f0 mve_setadr 0x%x (%x)\n", ram_scanadr, pushpc);
1616   ram_get_i();
1617   next_fn();
1676   model1_state *state = machine->driver_data<model1_state>();
1677   state->ram_scanadr = fifoin_pop(state) - 0x8000;
1678   logerror("TGP f0 mve_setadr 0x%x (%x)\n", state->ram_scanadr, state->pushpc);
1679   ram_get_i(state);
1680   next_fn(state);
16181681}
16191682
16201683struct function {
r10427r10428
18181881
18191882static TGP_FUNCTION( dump )
18201883{
1821   logerror("TGP FIFOIN write %08x (%x)\n", fifoin_pop(), pushpc);
1822   fifoin_cbcount = 1;
1823   fifoin_cb = dump;
1884   model1_state *state = machine->driver_data<model1_state>();
1885   logerror("TGP FIFOIN write %08x (%x)\n", fifoin_pop(state), state->pushpc);
1886   state->fifoin_cbcount = 1;
1887   state->fifoin_cb = dump;
18241888}
18251889
18261890static TGP_FUNCTION( function_get_vf )
18271891{
1828   UINT32 f = fifoin_pop() >> 23;
1892   model1_state *state = machine->driver_data<model1_state>();
1893   UINT32 f = fifoin_pop(state) >> 23;
18291894
1830   if(fifoout_rpos != fifoout_wpos) {
1831      int count = fifoout_wpos - fifoout_rpos;
1895   if(state->fifoout_rpos != state->fifoout_wpos) {
1896      int count = state->fifoout_wpos - state->fifoout_rpos;
18321897      if(count < 0)
18331898         count += FIFO_SIZE;
18341899      logerror("TGP function called with sizeout = %d\n", count);
18351900   }
18361901   if(ARRAY_LENGTH(ftab_vf) > f && NULL != ftab_vf[f].cb) {
1837      fifoin_cbcount = ftab_vf[f].count;
1838      fifoin_cb = ftab_vf[f].cb;
1839      //      logerror("TGP function %d request, %d parameters\n", f, fifoin_cbcount);
1840      if(!fifoin_cbcount)
1841         fifoin_cb(machine);
1902      state->fifoin_cbcount = ftab_vf[f].count;
1903      state->fifoin_cb = ftab_vf[f].cb;
1904      //      logerror("TGP function %d request, %d parameters\n", f, state->fifoin_cbcount);
1905      if(!state->fifoin_cbcount)
1906         state->fifoin_cb(machine);
18421907   } else {
1843      logerror("TGP function %d unimplemented (%x)\n", f, pushpc);
1844      fifoin_cbcount = 1;
1845      fifoin_cb = dump;
1908      logerror("TGP function %d unimplemented (%x)\n", f, state->pushpc);
1909      state->fifoin_cbcount = 1;
1910      state->fifoin_cb = dump;
18461911   }
18471912}
18481913
18491914static TGP_FUNCTION( function_get_swa )
18501915{
1851   UINT32 f = fifoin_pop();
1916   model1_state *state = machine->driver_data<model1_state>();
1917   UINT32 f = fifoin_pop(state);
18521918
1853   if(fifoout_rpos != fifoout_wpos) {
1854      int count = fifoout_wpos - fifoout_rpos;
1919   if(state->fifoout_rpos != state->fifoout_wpos) {
1920      int count = state->fifoout_wpos - state->fifoout_rpos;
18551921      if(count < 0)
18561922         count += FIFO_SIZE;
18571923      logerror("TGP function called with sizeout = %d\n", count);
18581924   }
18591925   if(ARRAY_LENGTH(ftab_swa) > f && NULL != ftab_swa[f].cb) {
1860      fifoin_cbcount = ftab_swa[f].count;
1861      fifoin_cb = ftab_swa[f].cb;
1862      //      logerror("TGP function %d request, %d parameters\n", f, fifoin_cbcount);
1863      if(!fifoin_cbcount)
1864         fifoin_cb(machine);
1926      state->fifoin_cbcount = ftab_swa[f].count;
1927      state->fifoin_cb = ftab_swa[f].cb;
1928      //      logerror("TGP function %d request, %d parameters\n", f, state->fifoin_cbcount);
1929      if(!state->fifoin_cbcount)
1930         state->fifoin_cb(machine);
18651931   } else {
1866      logerror("TGP function %d unimplemented (%x)\n", f, pushpc);
1867      fifoin_cbcount = 1;
1868      fifoin_cb = dump;
1932      logerror("TGP function %d unimplemented (%x)\n", f, state->pushpc);
1933      state->fifoin_cbcount = 1;
1934      state->fifoin_cb = dump;
18691935   }
18701936}
18711937
18721938READ16_HANDLER( model1_tgp_copro_r )
18731939{
1874   static UINT32 cur;
1940   model1_state *state = space->machine->driver_data<model1_state>();
18751941   if(!offset) {
1876      cur = fifoout_pop(space);
1877      return cur;
1942      state->copro_r = fifoout_pop(space);
1943      return state->copro_r;
18781944   } else
1879      return cur >> 16;
1945      return state->copro_r >> 16;
18801946}
18811947
18821948WRITE16_HANDLER( model1_tgp_copro_w )
18831949{
1884   static UINT32 cur;
1950   model1_state *state = space->machine->driver_data<model1_state>();
18851951   if(offset) {
1886      cur = (cur & 0x0000ffff) | (data << 16);
1887      pushpc = cpu_get_pc(space->cpu);
1888      fifoin_push(space, cur);
1952      state->copro_w = (state->copro_w & 0x0000ffff) | (data << 16);
1953      state->pushpc = cpu_get_pc(space->cpu);
1954      fifoin_push(space, state->copro_w);
18891955   } else
1890      cur = (cur & 0xffff0000) | data;
1956      state->copro_w = (state->copro_w & 0xffff0000) | data;
18911957}
18921958
18931959READ16_HANDLER( model1_tgp_copro_adr_r )
18941960{
1895   return ram_adr;
1961   model1_state *state = space->machine->driver_data<model1_state>();
1962   return state->ram_adr;
18961963}
18971964
18981965WRITE16_HANDLER( model1_tgp_copro_adr_w )
18991966{
1900   COMBINE_DATA(&ram_adr);
1967   model1_state *state = space->machine->driver_data<model1_state>();
1968   COMBINE_DATA(&state->ram_adr);
19011969}
19021970
19031971READ16_HANDLER( model1_tgp_copro_ram_r )
19041972{
1973   model1_state *state = space->machine->driver_data<model1_state>();
19051974   if(!offset) {
1906      logerror("TGP f0 ram read %04x, %08x (%f) (%x)\n", ram_adr, ram_data[ram_adr], u2f(ram_data[ram_adr]), cpu_get_pc(space->cpu));
1907      return ram_data[ram_adr];
1975      logerror("TGP f0 ram read %04x, %08x (%f) (%x)\n", state->ram_adr, state->ram_data[state->ram_adr], u2f(state->ram_data[state->ram_adr]), cpu_get_pc(space->cpu));
1976      return state->ram_data[state->ram_adr];
19081977   } else
1909      return ram_data[ram_adr++] >> 16;
1978      return state->ram_data[state->ram_adr++] >> 16;
19101979}
19111980
19121981WRITE16_HANDLER( model1_tgp_copro_ram_w )
19131982{
1914   COMBINE_DATA(ram_latch+offset);
1983   model1_state *state = space->machine->driver_data<model1_state>();
1984   COMBINE_DATA(state->ram_latch+offset);
19151985   if(offset) {
1916      UINT32 v = ram_latch[0]|(ram_latch[1]<<16);
1917      logerror("TGP f0 ram write %04x, %08x (%f) (%x)\n", ram_adr, v, u2f(v), cpu_get_pc(space->cpu));
1918      ram_data[ram_adr] = v;
1919      ram_adr++;
1986      UINT32 v = state->ram_latch[0]|(state->ram_latch[1]<<16);
1987      logerror("TGP f0 ram write %04x, %08x (%f) (%x)\n", state->ram_adr, v, u2f(v), cpu_get_pc(space->cpu));
1988      state->ram_data[state->ram_adr] = v;
1989      state->ram_adr++;
19201990   }
19211991}
19221992
19231993MACHINE_START( model1 )
19241994{
1925   ram_data = auto_alloc_array(machine, UINT32, 0x10000);
1995   model1_state *state = machine->driver_data<model1_state>();
1996   state->ram_data = auto_alloc_array(machine, UINT32, 0x10000);
19261997
1927   state_save_register_global_pointer(machine, ram_data, 0x10000);
1928   state_save_register_global(machine, ram_adr);
1929   state_save_register_global(machine, ram_scanadr);
1930   state_save_register_global_array(machine, ram_latch);
1931   state_save_register_global(machine, fifoout_rpos);
1932   state_save_register_global(machine, fifoout_wpos);
1933   state_save_register_global_array(machine, fifoout_data);
1934   state_save_register_global(machine, fifoin_rpos);
1935   state_save_register_global(machine, fifoin_wpos);
1936   state_save_register_global_array(machine, fifoin_data);
1937   state_save_register_global_array(machine, cmat);
1938   state_save_register_global_2d_array(machine, mat_stack);
1939   state_save_register_global_2d_array(machine, mat_vector);
1940   state_save_register_global(machine, mat_stack_pos);
1941   state_save_register_global(machine, acc);
1942   state_save_register_global(machine, list_length);
1998   state_save_register_global_pointer(machine, state->ram_data, 0x10000);
1999   state_save_register_global(machine, state->ram_adr);
2000   state_save_register_global(machine, state->ram_scanadr);
2001   state_save_register_global_array(machine, state->ram_latch);
2002   state_save_register_global(machine, state->fifoout_rpos);
2003   state_save_register_global(machine, state->fifoout_wpos);
2004   state_save_register_global_array(machine, state->fifoout_data);
2005   state_save_register_global(machine, state->fifoin_rpos);
2006   state_save_register_global(machine, state->fifoin_wpos);
2007   state_save_register_global_array(machine, state->fifoin_data);
2008   state_save_register_global_array(machine, state->cmat);
2009   state_save_register_global_2d_array(machine, state->mat_stack);
2010   state_save_register_global_2d_array(machine, state->mat_vector);
2011   state_save_register_global(machine, state->mat_stack_pos);
2012   state_save_register_global(machine, state->acc);
2013   state_save_register_global(machine, state->list_length);
19432014}
19442015
19452016void model1_tgp_reset(running_machine *machine, int swa)
19462017{
1947   ram_adr = 0;
1948   memset(ram_data, 0, 0x10000*4);
2018   model1_state *state = machine->driver_data<model1_state>();
2019   state->ram_adr = 0;
2020   memset(state->ram_data, 0, 0x10000*4);
19492021
1950   fifoout_rpos = 0;
1951   fifoout_wpos = 0;
1952   fifoin_rpos = 0;
1953   fifoin_wpos = 0;
2022   state->fifoout_rpos = 0;
2023   state->fifoout_wpos = 0;
2024   state->fifoin_rpos = 0;
2025   state->fifoin_wpos = 0;
19542026
1955   acc = 0;
1956   mat_stack_pos = 0;
1957   memset(cmat, 0, sizeof(cmat));
1958   cmat[0] = 1.0;
1959   cmat[4] = 1.0;
1960   cmat[8] = 1.0;
2027   state->acc = 0;
2028   state->mat_stack_pos = 0;
2029   memset(state->cmat, 0, sizeof(state->cmat));
2030   state->cmat[0] = 1.0;
2031   state->cmat[4] = 1.0;
2032   state->cmat[8] = 1.0;
19612033
1962   model1_dump = 0;
1963   model1_swa = swa;
1964   next_fn();
2034   state->dump = 0;
2035   state->swa = swa;
2036   next_fn(state);
19652037}
19662038
19672039/*********************************** Virtua Racing ***********************************/
19682040
1969static int copro_fifoout_rpos, copro_fifoout_wpos;
1970static UINT32 copro_fifoout_data[FIFO_SIZE];
1971static int copro_fifoout_num;
1972static int copro_fifoin_rpos, copro_fifoin_wpos;
1973static UINT32 copro_fifoin_data[FIFO_SIZE];
1974static int copro_fifoin_num;
19752041
19762042void model1_vr_tgp_reset( running_machine *machine )
19772043{
1978   ram_adr = 0;
1979   memset(ram_data, 0, 0x8000*4);
2044   model1_state *state = machine->driver_data<model1_state>();
2045   state->ram_adr = 0;
2046   memset(state->ram_data, 0, 0x8000*4);
19802047
1981   copro_fifoout_rpos = 0;
1982   copro_fifoout_wpos = 0;
1983   copro_fifoout_num = 0;
1984   copro_fifoin_rpos = 0;
1985   copro_fifoin_wpos = 0;
1986   copro_fifoin_num = 0;
2048   state->copro_fifoout_rpos = 0;
2049   state->copro_fifoout_wpos = 0;
2050   state->copro_fifoout_num = 0;
2051   state->copro_fifoin_rpos = 0;
2052   state->copro_fifoin_wpos = 0;
2053   state->copro_fifoin_num = 0;
19872054}
19882055
19892056/* FIFO */
19902057static int copro_fifoin_pop(device_t *device, UINT32 *result)
19912058{
2059   model1_state *state = device->machine->driver_data<model1_state>();
19922060   UINT32 r;
19932061
1994   if (copro_fifoin_num == 0)
2062   if (state->copro_fifoin_num == 0)
19952063   {
19962064      return 0;
19972065   }
19982066
1999   r = copro_fifoin_data[copro_fifoin_rpos++];
2067   r = state->copro_fifoin_data[state->copro_fifoin_rpos++];
20002068
2001   if (copro_fifoin_rpos == FIFO_SIZE)
2069   if (state->copro_fifoin_rpos == FIFO_SIZE)
20022070   {
2003      copro_fifoin_rpos = 0;
2071      state->copro_fifoin_rpos = 0;
20042072   }
20052073
2006   copro_fifoin_num--;
2074   state->copro_fifoin_num--;
20072075
20082076   *result = r;
20092077
r10427r10428
20122080
20132081static void copro_fifoin_push(address_space *space, UINT32 data)
20142082{
2015   if (copro_fifoin_num == FIFO_SIZE)
2083   model1_state *state = space->machine->driver_data<model1_state>();
2084   if (state->copro_fifoin_num == FIFO_SIZE)
20162085   {
20172086      fatalerror("Copro FIFOIN overflow (at %08X)", cpu_get_pc(space->cpu));
20182087      return;
20192088   }
20202089
2021   copro_fifoin_data[copro_fifoin_wpos++] = data;
2090   state->copro_fifoin_data[state->copro_fifoin_wpos++] = data;
20222091
2023   if (copro_fifoin_wpos == FIFO_SIZE)
2092   if (state->copro_fifoin_wpos == FIFO_SIZE)
20242093   {
2025      copro_fifoin_wpos = 0;
2094      state->copro_fifoin_wpos = 0;
20262095   }
20272096
2028   copro_fifoin_num++;
2097   state->copro_fifoin_num++;
20292098}
20302099
20312100static UINT32 copro_fifoout_pop(address_space *space)
20322101{
2102   model1_state *state = space->machine->driver_data<model1_state>();
20332103   UINT32 r;
20342104
2035   if (copro_fifoout_num == 0)
2105   if (state->copro_fifoout_num == 0)
20362106   {
20372107      // Reading from empty FIFO causes the v60 to enter wait state
20382108      v60_stall(space->machine->device("maincpu"));
r10427r10428
20422112      return 0;
20432113   }
20442114
2045   r = copro_fifoout_data[copro_fifoout_rpos++];
2115   r = state->copro_fifoout_data[state->copro_fifoout_rpos++];
20462116
2047   if (copro_fifoout_rpos == FIFO_SIZE)
2117   if (state->copro_fifoout_rpos == FIFO_SIZE)
20482118   {
2049      copro_fifoout_rpos = 0;
2119      state->copro_fifoout_rpos = 0;
20502120   }
20512121
2052   copro_fifoout_num--;
2122   state->copro_fifoout_num--;
20532123
20542124   return r;
20552125}
20562126
20572127static void copro_fifoout_push(device_t *device, UINT32 data)
20582128{
2059   if (copro_fifoout_num == FIFO_SIZE)
2129   model1_state *state = device->machine->driver_data<model1_state>();
2130   if (state->copro_fifoout_num == FIFO_SIZE)
20602131   {
20612132      fatalerror("Copro FIFOOUT overflow (at %08X)", cpu_get_pc(device));
20622133      return;
20632134   }
20642135
2065   copro_fifoout_data[copro_fifoout_wpos++] = data;
2136   state->copro_fifoout_data[state->copro_fifoout_wpos++] = data;
20662137
2067   if (copro_fifoout_wpos == FIFO_SIZE)
2138   if (state->copro_fifoout_wpos == FIFO_SIZE)
20682139   {
2069      copro_fifoout_wpos = 0;
2140      state->copro_fifoout_wpos = 0;
20702141   }
20712142
2072   copro_fifoout_num++;
2143   state->copro_fifoout_num++;
20732144}
20742145
20752146static READ32_HANDLER(copro_ram_r)
20762147{
2077   return ram_data[offset & 0x7fff];
2148   model1_state *state = space->machine->driver_data<model1_state>();
2149   return state->ram_data[offset & 0x7fff];
20782150}
20792151
20802152static WRITE32_HANDLER(copro_ram_w)
20812153{
2082   ram_data[offset&0x7fff] = data;
2154   model1_state *state = space->machine->driver_data<model1_state>();
2155   state->ram_data[offset&0x7fff] = data;
20832156}
20842157
20852158READ16_HANDLER( model1_tgp_vr_adr_r )
20862159{
2087   if ( ram_adr == 0 && copro_fifoin_num != 0 )
2160   model1_state *state = space->machine->driver_data<model1_state>();
2161   if ( state->ram_adr == 0 && state->copro_fifoin_num != 0 )
20882162   {
20892163      /* spin the main cpu and let the TGP catch up */
20902164      cpu_spinuntil_time(space->cpu, attotime::from_usec(100));
20912165   }
20922166
2093   return ram_adr;
2167   return state->ram_adr;
20942168}
20952169
20962170WRITE16_HANDLER( model1_tgp_vr_adr_w )
20972171{
2098   COMBINE_DATA(&ram_adr);
2172   model1_state *state = space->machine->driver_data<model1_state>();
2173   COMBINE_DATA(&state->ram_adr);
20992174}
21002175
21012176READ16_HANDLER( model1_vr_tgp_ram_r )
21022177{
2178   model1_state *state = space->machine->driver_data<model1_state>();
21032179   UINT16   r;
21042180
21052181   if (!offset)
21062182   {
2107      r = ram_data[ram_adr&0x7fff];
2183      r = state->ram_data[state->ram_adr&0x7fff];
21082184   }
21092185   else
21102186   {
2111      r = ram_data[ram_adr&0x7fff] >> 16;
2187      r = state->ram_data[state->ram_adr&0x7fff] >> 16;
21122188
2113      if ( ram_adr == 0 && r == 0xffff )
2189      if ( state->ram_adr == 0 && r == 0xffff )
21142190      {
21152191         /* if the TGP is busy, spin some more */
21162192         cpu_spinuntil_time(space->cpu, attotime::from_usec(100));
21172193      }
21182194
2119      if ( ram_adr & 0x8000 )
2120         ram_adr++;
2195      if ( state->ram_adr & 0x8000 )
2196         state->ram_adr++;
21212197   }
21222198
21232199   return r;
r10427r10428
21252201
21262202WRITE16_HANDLER( model1_vr_tgp_ram_w )
21272203{
2128   COMBINE_DATA(ram_latch+offset);
2204   model1_state *state = space->machine->driver_data<model1_state>();
2205   COMBINE_DATA(state->ram_latch+offset);
21292206
21302207   if (offset)
21312208   {
2132      UINT32 v = ram_latch[0]|(ram_latch[1]<<16);
2133      ram_data[ram_adr&0x7fff] = v;
2134      if ( ram_adr & 0x8000 )
2135         ram_adr++;
2209      UINT32 v = state->ram_latch[0]|(state->ram_latch[1]<<16);
2210      state->ram_data[state->ram_adr&0x7fff] = v;
2211      if ( state->ram_adr & 0x8000 )
2212         state->ram_adr++;
21362213   }
21372214}
21382215
21392216READ16_HANDLER( model1_vr_tgp_r )
21402217{
2141   static UINT32 cur;
2142
2218   model1_state *state = space->machine->driver_data<model1_state>();
21432219   if (!offset)
21442220   {
2145      cur = copro_fifoout_pop(space);
2146      return cur;
2221      state->vr_r = copro_fifoout_pop(space);
2222      return state->vr_r;
21472223   }
21482224   else
2149      return cur >> 16;
2225      return state->vr_r >> 16;
21502226}
21512227
21522228WRITE16_HANDLER( model1_vr_tgp_w )
21532229{
2154   static UINT32 cur;
2155
2230   model1_state *state = space->machine->driver_data<model1_state>();
21562231   if (offset)
21572232   {
2158      cur = (cur & 0x0000ffff) | (data << 16);
2159      copro_fifoin_push(space, cur);
2233      state->vr_w = (state->vr_w & 0x0000ffff) | (data << 16);
2234      copro_fifoin_push(space, state->vr_w);
21602235   }
21612236   else
2162      cur = (cur & 0xffff0000) | data;
2237      state->vr_w = (state->vr_w & 0xffff0000) | data;
21632238}
21642239
21652240/* TGP config */
src/mame/mamedriv.c
r10427r10428
85278527   DRIVER( jwildb52a )   /* (c) 199? Sigma */
85288528   DRIVER( jwildb52h )   /* (c) 199? Sigma */
85298529
8530   /* Sigma B98 */
8530   /* Sigma B98 / Sammy Medal Games */
85318531   DRIVER( gegege )   /* (c) 1997 Banpresto / Sigma */
8532   DRIVER( animalc )   /* 2000 Sammy */
8533   DRIVER( itazuram )   /* 2000 Sammy */
8534   DRIVER( pyenaget )   /* 2000 Sammy */
8535   DRIVER( haekaka )   /* 2002 Sammy */
8536   DRIVER( tdoboon )   /* 2002 Sammy */
8532   DRIVER( animalc )   /* (c) 2000 Sammy */
8533   DRIVER( itazuram )   /* (c) 2000 Sammy */
8534   DRIVER( pyenaget )   /* (c) 2000 Sammy */
8535   DRIVER( tdoboon )   /* (c) 2000 Sammy */
8536   DRIVER( haekaka )   /* (c) 2001 Sammy */
85378537
85388538   /* IGS games ( www.igs.com.tw ) */
85398539   DRIVER( goldstar )   /* (c) 198? IGS */
src/mame/includes/mitchell.h
r10427r10428
3939   /* devices */
4040   optional_device<cpu_device> audiocpu;
4141   optional_device<okim6295_device> oki;
42   UINT8 *nvram;
43   size_t nvram_size;
4244};
4345
4446
src/mame/includes/deco_mlc.h
r10427r10428
1class deco_mlc_state : public driver_device
2{
3public:
4   deco_mlc_state(running_machine &machine, const driver_device_config_base &config)
5      : driver_device(machine, config) { }
6
7   UINT32 *mlc_ram;
8   UINT32 *irq_ram;
9   timer_device *raster_irq_timer;
10   int mainCpuIsArm;
11   int mlc_raster_table[9][256];
12   UINT32 vbl_i;
13   int lastScanline[9];
14   UINT32 *mlc_vram;
15   UINT32 *mlc_clip_ram;
16   UINT32 colour_mask;
17   UINT32 *mlc_buffered_spriteram;
18};
19
20
121/*----------- defined in video/deco_mlc.c -----------*/
222
3extern UINT32 *mlc_vram, *mlc_clip_ram;
4
523VIDEO_START( mlc );
624VIDEO_UPDATE( mlc );
725VIDEO_EOF( mlc );
src/mame/includes/tryout.h
r10427r10428
55      : driver_device(machine, config) { }
66
77   UINT8 *videoram;
8   UINT8 *gfx_control;
9   tilemap_t *fg_tilemap;
10   tilemap_t *bg_tilemap;
11   UINT8 vram_bank;
12   UINT8 *vram;
13   UINT8 *vram_gfx;
814};
915
1016
1117/*----------- defined in video/tryout.c -----------*/
1218
13extern UINT8 *tryout_gfx_control;
14
1519READ8_HANDLER( tryout_vram_r );
1620WRITE8_HANDLER( tryout_videoram_w );
1721WRITE8_HANDLER( tryout_vram_w );
src/mame/includes/hexion.h
r10427r10428
1class hexion_state : public driver_device
2{
3public:
4   hexion_state(running_machine &machine, const driver_device_config_base &config)
5      : driver_device(machine, config) { }
6
7   UINT8 *vram[2];
8   UINT8 *unkram;
9   int bankctrl;
10   int rambank;
11   int pmcbank;
12   int gfxrom_select;
13   tilemap_t *bg_tilemap[2];
14};
15
16
117/*----------- defined in video/hexion.c -----------*/
218
319VIDEO_START( hexion );
src/mame/includes/system1.h
r10427r10428
55      : driver_device(machine, config) { }
66
77   UINT8 *videoram;
8   void (*videomode_custom)(running_machine *machine, UINT8 data, UINT8 prevdata);
9   UINT8 mute_xor;
10   UINT8 *ram;
11   UINT8 dakkochn_mux_data;
12   UINT8 videomode_prev;
13   UINT8 mcu_control;
14   UINT8 *nob_mcu_status;
15   UINT8 *nob_mcu_latch;
16   UINT8 nob_maincpu_latch;
17   int nobb_inport23_step;
18   UINT8 *mix_collide;
19   UINT8 mix_collide_summary;
20   UINT8 *sprite_collide;
21   UINT8 sprite_collide_summary;
22   bitmap_t *sprite_bitmap;
23   UINT8 video_mode;
24   UINT8 videoram_bank;
25   tilemap_t *tilemap_page[8];
26   UINT8 tilemap_pages;
827};
928
1029
src/mame/includes/powerins.h
r10427r10428
1class powerins_state : public driver_device
2{
3public:
4   powerins_state(running_machine &machine, const driver_device_config_base &config)
5      : driver_device(machine, config) { }
6
7   int oki_bank;
8   UINT16 *vram_0;
9   UINT16 *vctrl_0;
10   UINT16 *vram_1;
11   UINT16 *vctrl_1;
12   tilemap_t *tilemap_0;
13   tilemap_t *tilemap_1;
14   int tile_bank;
15};
16
17
118/*----------- defined in video/powerins.c -----------*/
219
3extern UINT16 *powerins_vram_0, *powerins_vctrl_0;
4extern UINT16 *powerins_vram_1, *powerins_vctrl_1;
5
620WRITE16_HANDLER( powerins_flipscreen_w );
721WRITE16_HANDLER( powerins_tilebank_w );
822
src/mame/includes/deco32.h
r10427r10428
1class deco32_state : public driver_device
2{
3public:
4   deco32_state(running_machine &machine, const driver_device_config_base &config)
5      : driver_device(machine, config) { }
6
7   UINT32 *ram;
8   int raster_enable;
9   timer_device *raster_irq_timer;
10   UINT8 nslasher_sound_irq;
11   int strobe;
12   int dragngun_lightgun_port;
13   int tattass_eprom_bit;
14   int lastClock;
15   char buffer[32];
16   int bufPtr;
17   int pendingCommand;
18   int readBitCount;
19   int byteAddr;
20   UINT8 bsmt_latch;
21   UINT8 bsmt_reset;
22   UINT32 *pf1_data;
23   UINT32 *pf2_data;
24   UINT32 *pf3_data;
25   UINT32 *pf4_data;
26   UINT32 *pf12_control;
27   UINT32 *pf34_control;
28   UINT32 *pf1_rowscroll;
29   UINT32 *pf2_rowscroll;
30   UINT32 *pf3_rowscroll;
31   UINT32 *pf4_rowscroll;
32   UINT32 *dragngun_sprite_layout_0_ram;
33   UINT32 *dragngun_sprite_layout_1_ram;
34   UINT32 *dragngun_sprite_lookup_0_ram;
35   UINT32 *dragngun_sprite_lookup_1_ram;
36   UINT32 *ace_ram;
37   UINT16 *raster_display_list;
38   int raster_display_position;
39   UINT8 *dirty_palette;
40   tilemap_t *pf1_tilemap;
41   tilemap_t *pf1a_tilemap;
42   tilemap_t *pf2_tilemap;
43   tilemap_t *pf3_tilemap;
44   tilemap_t *pf4_tilemap;
45   int pf1_bank;
46   int pf2_bank;
47   int pf3_bank;
48   int pf4_bank;
49   int pf1_flip;
50   int pf2_flip;
51   int pf3_flip;
52   int pf4_flip;
53   int pf2_colourbank;
54   int pf4_colourbank;
55   int pri;
56   bitmap_t *sprite0_mix_bitmap;
57   bitmap_t *sprite1_mix_bitmap;
58   bitmap_t *tilemap_alpha_bitmap;
59   UINT32 dragngun_sprite_ctrl;
60   int ace_ram_dirty;
61   int has_ace_ram;
62   bitmap_t *sprite_priority_bitmap;
63   int last_pf3_bank;
64};
65
66
167/*----------- defined in video/deco32.c -----------*/
268
369VIDEO_START( captaven );
r10427r10428
1480VIDEO_UPDATE( dragngun );
1581VIDEO_UPDATE( nslasher );
1682
17extern UINT32 *deco32_pf1_data,*deco32_pf2_data,*deco32_pf3_data,*deco32_pf4_data;
18extern UINT32 *deco32_pf12_control,*deco32_pf34_control;
19extern UINT32 *deco32_pf1_rowscroll,*deco32_pf2_rowscroll,*deco32_pf3_rowscroll,*deco32_pf4_rowscroll;
20extern UINT32 *dragngun_sprite_layout_0_ram, *dragngun_sprite_layout_1_ram;
21extern UINT32 *dragngun_sprite_lookup_0_ram, *dragngun_sprite_lookup_1_ram;
22extern UINT32 *deco32_ace_ram;
23extern UINT16 *deco32_raster_display_list;
24extern int deco32_raster_display_position;
2583
2684WRITE32_HANDLER( deco32_pf1_data_w );
2785WRITE32_HANDLER( deco32_pf2_data_w );
src/mame/includes/fastfred.h
r10427r10428
55
66***************************************************************************/
77
8/*----------- defined in video/fastfred.c -----------*/
8class fastfred_state : public driver_device
9{
10public:
11   fastfred_state(running_machine &machine, const driver_device_config_base &config)
12      : driver_device(machine, config) { }
913
10extern int fastfred_hardware_type;
14   UINT8 imago_sprites[0x800*3];
15   UINT16 imago_sprites_address;
16   UINT8 imago_sprites_bank;
17   int hardware_type;
18   UINT8 *videoram;
19   UINT8 *spriteram;
20   size_t spriteram_size;
21   UINT8 *attributesram;
22   UINT8 *background_color;
23   UINT8 *imago_fg_videoram;
24   UINT16 charbank;
25   UINT8 colorbank;
26   tilemap_t *bg_tilemap;
27   tilemap_t *fg_tilemap;
28   tilemap_t *web_tilemap;
29};
1130
12extern UINT8 *fastfred_videoram;
13extern UINT8 *fastfred_spriteram;
14extern size_t fastfred_spriteram_size;
15extern UINT8 *fastfred_attributesram;
16extern UINT8 *fastfred_background_color;
1731
32/*----------- defined in video/fastfred.c -----------*/
33
1834PALETTE_INIT( fastfred );
1935VIDEO_START( fastfred );
2036WRITE8_HANDLER( fastfred_videoram_w );
r10427r10428
2743WRITE8_HANDLER( fastfred_flip_screen_y_w );
2844VIDEO_UPDATE( fastfred );
2945
30extern UINT8 *imago_fg_videoram;
3146VIDEO_START( imago );
3247VIDEO_UPDATE( imago );
3348WRITE8_HANDLER( imago_fg_videoram_w );
src/mame/includes/88games.h
r10427r10428
1515   UINT8 *      banked_rom;
1616//  UINT8 *      paletteram_1000;   // this currently uses generic palette handling
1717//  UINT8 *      nvram; // this currently uses generic nvram handling
18   UINT8 *paletteram_1000;
1819
1920   /* video-related */
2021   int          k88games_priority;
src/mame/includes/beezer.h
r10427r10428
1#include "machine/6522via.h"
2
13class beezer_state : public driver_device
24{
35public:
r10427r10428
57      : driver_device(machine, config) { }
68
79   UINT8 *videoram;
10   int pbus;
11   int banklatch;
12   int scanline;
813};
914
1015
1116/*----------- defined in machine/beezer.c -----------*/
1217
13//extern const via6522_interface b_via_0_interface;
14//extern const via6522_interface b_via_1_interface;
18extern const via6522_interface b_via_0_interface;
19extern const via6522_interface b_via_1_interface;
1520
1621DRIVER_INIT( beezer );
1722WRITE8_HANDLER( beezer_bankswitch_w );
src/mame/includes/darkseal.h
r10427r10428
1class darkseal_state : public driver_device
2{
3public:
4   darkseal_state(running_machine &machine, const driver_device_config_base &config)
5      : driver_device(machine, config) { }
6
7   UINT16 *ram;
8   UINT16 *pf12_row;
9   UINT16 *pf34_row;
10   UINT16 *pf1_data;
11   UINT16 *pf2_data;
12   UINT16 *pf3_data;
13   UINT16 control_0[8];
14   UINT16 control_1[8];
15   tilemap_t *pf1_tilemap;
16   tilemap_t *pf2_tilemap;
17   tilemap_t *pf3_tilemap;
18   int flipscreen;
19};
20
21
122/*----------- defined in video/darkseal.c -----------*/
223
3extern UINT16 *darkseal_pf12_row, *darkseal_pf34_row;
4extern UINT16 *darkseal_pf1_data,*darkseal_pf2_data,*darkseal_pf3_data;
5
624VIDEO_START( darkseal );
725VIDEO_UPDATE( darkseal );
826
src/mame/includes/stadhero.h
r10427r10428
1class stadhero_state : public driver_device
2{
3public:
4   stadhero_state(running_machine &machine, const driver_device_config_base &config)
5      : driver_device(machine, config) { }
6
7   UINT16 *pf1_data;
8   UINT16 *pf2_control_0;
9   UINT16 *pf2_control_1;
10   UINT16 *pf2_data;
11   tilemap_t *pf1_tilemap;
12   tilemap_t *pf2_tilemap;
13   int flipscreen;
14};
15
16
117/*----------- defined in video/stadhero.c -----------*/
218
3extern UINT16 *stadhero_pf1_data;
4extern UINT16 *stadhero_pf2_control_0;
5extern UINT16 *stadhero_pf2_control_1;
6
719VIDEO_START( stadhero );
820VIDEO_UPDATE( stadhero );
921
src/mame/includes/model1.h
r10427r10428
1typedef void (*tgp_func)(running_machine *machine);
2
3enum {FIFO_SIZE = 256};
4enum {MAT_STACK_SIZE = 32};
5
6class model1_state : public driver_device
7{
8public:
9   model1_state(running_machine &machine, const driver_device_config_base &config)
10      : driver_device(machine, config) { }
11
12   struct view *view;
13   struct point *pointdb, *pointpt;
14   struct quad_m1 *quaddb, *quadpt;
15   struct quad_m1 **quadind;
16   int sound_irq;
17   int to_68k[8];
18   int fifo_wptr;
19   int fifo_rptr;
20   int last_irq;
21   UINT16 *mr;
22   UINT16 *mr2;
23   int dump;
24   UINT16 *display_list0;
25   UINT16 *display_list1;
26   UINT16 *color_xlat;
27   offs_t pushpc;
28   int fifoin_rpos;
29   int fifoin_wpos;
30   UINT32 fifoin_data[FIFO_SIZE];
31   int swa;
32   int fifoin_cbcount;
33   tgp_func fifoin_cb;
34   INT32 fifoout_rpos;
35   INT32 fifoout_wpos;
36   UINT32 fifoout_data[FIFO_SIZE];
37   UINT32 list_length;
38   float cmat[12];
39   float mat_stack[MAT_STACK_SIZE][12];
40   float mat_vector[21][12];
41   INT32 mat_stack_pos;
42   float acc;
43   float tgp_vf_xmin;
44   float tgp_vf_xmax;
45   float tgp_vf_zmin;
46   float tgp_vf_zmax;
47   float tgp_vf_ygnd;
48   float tgp_vf_yflr;
49   float tgp_vf_yjmp;
50   float tgp_vr_circx;
51   float tgp_vr_circy;
52   float tgp_vr_circrad;
53   float tgp_vr_cbox[12];
54   int tgp_vr_select;
55   UINT16 ram_adr;
56   UINT16 ram_latch[2];
57   UINT16 ram_scanadr;
58   UINT32 *ram_data;
59   float tgp_vr_base[4];
60   int puuu;
61   int ccount;
62   UINT32 copro_r;
63   UINT32 copro_w;
64   int copro_fifoout_rpos;
65   int copro_fifoout_wpos;
66   UINT32 copro_fifoout_data[FIFO_SIZE];
67   int copro_fifoout_num;
68   int copro_fifoin_rpos;
69   int copro_fifoin_wpos;
70   UINT32 copro_fifoin_data[FIFO_SIZE];
71   int copro_fifoin_num;
72   UINT32 vr_r;
73   UINT32 vr_w;
74   UINT16 listctl[2];
75   UINT16 *glist;
76   int render_done;
77   UINT16 *tgp_ram;
78   UINT16 *paletteram16;
79   UINT32 *poly_rom;
80   UINT32 *poly_ram;
81};
82
83
184/*----------- defined in machine/model1.c -----------*/
285
386extern const mb86233_cpu_core model1_vr_tgp_config;
4extern int model1_dump;
587
688READ16_HANDLER( model1_tgp_copro_r );
789WRITE16_HANDLER( model1_tgp_copro_w );
r10427r10428
27109
28110/*----------- defined in video/model1.c -----------*/
29111
30extern UINT16 *model1_display_list0, *model1_display_list1;
31extern UINT16 *model1_color_xlat;
32
33112VIDEO_START(model1);
34113VIDEO_UPDATE(model1);
35114VIDEO_EOF(model1);
src/mame/includes/qdrmfgp.h
r10427r10428
66        m_nvram(*this, "nvram") { }
77
88   required_shared_ptr<UINT8>   m_nvram;
9   UINT8 *sndram;
10   UINT16 *workram;
11   UINT16 control;
12   INT32 gp2_irq_control;
13   INT32 pal;
914};
1015
11/*----------- defined in drivers/qdrmfgp.c -----------*/
12
13int qdrmfgp_get_palette(void);
14
15
1616/*----------- defined in video/qdrmfgp.c -----------*/
1717
1818VIDEO_START( qdrmfgp );
src/mame/includes/model2.h
r10427r10428
1/*----------- defined in drivers/model2.c -----------*/
1#include "video/poly.h"
22
3extern UINT32 geo_read_start_address;
4extern UINT32 geo_write_start_address;
5extern UINT32 *model2_bufferram;
6extern UINT32 *model2_colorxlat;
7extern UINT32 *model2_textureram0;
8extern UINT32 *model2_textureram1;
9extern UINT32 *model2_lumaram;
10extern UINT32 *model2_paletteram32;
113
4typedef struct _raster_state raster_state;
5typedef struct _geo_state geo_state;
126
7
8class model2_state : public driver_device
9{
10public:
11   model2_state(running_machine &machine, const driver_device_config_base &config)
12      : driver_device(machine, config) { }
13
14   UINT32 *workram;
15   UINT32 intreq;
16   UINT32 intena;
17   UINT32 coproctl;
18   UINT32 coprocnt;
19   UINT32 geoctl;
20   UINT32 geocnt;
21   UINT16 *soundram;
22   UINT32 timervals[4];
23   UINT32 timerorig[4];
24   int timerrun[4];
25   timer_device *timers[4];
26   int ctrlmode;
27   int analog_channel;
28   UINT32 *tgp_program;
29   int dsp_type;
30   int copro_fifoin_rpos;
31   int copro_fifoin_wpos;
32   UINT32 *copro_fifoin_data;
33   int copro_fifoin_num;
34   int copro_fifoout_rpos;
35   int copro_fifoout_wpos;
36   UINT32 *copro_fifoout_data;
37   int copro_fifoout_num;
38   UINT16 cmd_data;
39   UINT8 driveio_comm_data;
40   int iop_write_num;
41   UINT32 iop_data;
42   int geo_iop_write_num;
43   UINT32 geo_iop_data;
44   int to_68k;
45   int protstate;
46   int protpos;
47   UINT8 protram[256];
48   int prot_a;
49   int maxxstate;
50   UINT32 netram[0x8000/4];
51   int zflagi;
52   int zflag;
53   int sysres;
54   int scsp_last_line;
55   int jnet_time_out;
56   UINT32 geo_read_start_address;
57   UINT32 geo_write_start_address;
58   UINT32 *bufferram;
59   UINT32 *colorxlat;
60   UINT32 *textureram0;
61   UINT32 *textureram1;
62   UINT32 *lumaram;
63   UINT32 *paletteram32;
64   poly_manager *poly;
65   raster_state *raster;
66   geo_state *geo;
67   bitmap_t *sys24_bitmap;
68};
69
70
1371/*----------- defined in video/model2.c -----------*/
1472
1573VIDEO_START(model2);
1674VIDEO_UPDATE(model2);
1775
18void model2_3d_set_zclip( UINT8 clip );
76void model2_3d_set_zclip( running_machine *machine, UINT8 clip );
src/mame/includes/sshangha.h
r10427r10428
1class sshangha_state : public driver_device
2{
3public:
4   sshangha_state(running_machine &machine, const driver_device_config_base &config)
5      : driver_device(machine, config) { }
6
7   UINT16 *prot_data;
8   UINT16 *sound_shared_ram;
9   UINT16 *pf1_data;
10   UINT16 *pf2_data;
11   UINT16 *pf1_rowscroll;
12   UINT16 *pf2_rowscroll;
13   UINT16 control_0[8];
14   tilemap_t *pf1_8x8_tilemap;
15   tilemap_t *pf1_16x16_tilemap;
16   tilemap_t *pf2_tilemap;
17   int pf1_bank;
18   int pf2_bank;
19   int video_control;
20   int last_pf1_bank;
21   int last_pf2_bank;
22};
23
24
125/*----------- defined in video/sshangha.c -----------*/
226
3extern UINT16 *sshangha_pf1_data;
4extern UINT16 *sshangha_pf2_data;
5extern UINT16 *sshangha_pf1_rowscroll, *sshangha_pf2_rowscroll;
6
727VIDEO_START( sshangha );
828VIDEO_UPDATE( sshangha );
929
src/mame/includes/model3.h
r10427r10428
1#include "video/poly.h"
2
3typedef float MATRIX[4][4];
4typedef float VECTOR[4];
5typedef float VECTOR3[3];
6
7typedef struct {
8   float x,y,z,d;
9} PLANE;
10
11typedef struct _cached_texture cached_texture;
12
13class model3_state : public driver_device
14{
15public:
16   model3_state(running_machine &machine, const driver_device_config_base &config)
17      : driver_device(machine, config) { }
18
19   UINT8 irq_enable;
20   UINT8 irq_state;
21   UINT8 scsi_irq_state;
22   UINT64 *work_ram;
23   int crom_bank;
24   int controls_bank;
25   UINT32 real3d_device_id;
26   UINT16 *soundram;
27   UINT32 mpc105_regs[0x40];
28   UINT32 mpc105_addr;
29   int pci_bus;
30   int pci_device;
31   int pci_function;
32   int pci_reg;
33   UINT32 mpc106_regs[0x40];
34   UINT32 mpc106_addr;
35   UINT32 dma_data;
36   UINT32 dma_status;
37   UINT32 dma_source;
38   UINT32 dma_dest;
39   UINT32 dma_endian;
40   UINT32 dma_irq;
41   UINT64 controls_2;
42   UINT64 controls_3;
43   UINT8 serial_fifo1;
44   UINT8 serial_fifo2;
45   int lightgun_reg_sel;
46   int adc_channel;
47   UINT64 real3d_status;
48   UINT64 *network_ram;
49   int prot_data_ptr;
50   int scsp_last_line;
51   int vblank;
52   UINT32 *vrom;
53   int step;
54   UINT64 *paletteram64;
55   int m3_step;
56   INT32 tap_state;
57   UINT64 ir;
58   UINT8 id_data[32];
59   INT32 id_size;
60   int tdo;
61   UINT8 layer_enable;
62   UINT32 layer_modulate_r;
63   UINT32 layer_modulate_g;
64   UINT32 layer_modulate_b;
65   UINT32 layer_modulate1;
66   UINT32 layer_modulate2;
67   UINT64 layer_scroll[2];
68   UINT64 *m3_char_ram;
69   UINT64 *m3_tile_ram;
70   UINT32 *texture_fifo;
71   int texture_fifo_pos;
72   UINT16 *texture_ram[2];
73   UINT32 *display_list_ram;
74   UINT32 *culling_ram;
75   UINT32 *polygon_ram;
76   UINT16 *pal_lookup;
77   int real3d_display_list;
78   bitmap_t *bitmap3d;
79   bitmap_t *zbuffer;
80   rectangle clip3d;
81   rectangle *screen_clip;
82   VECTOR3 parallel_light;
83   float parallel_light_intensity;
84   float ambient_light_intensity;
85   poly_manager *poly;
86   int list_depth;
87   int tick;
88   int debug_layer_disable;
89   UINT64 vid_reg0;
90   int matrix_stack_ptr;
91   MATRIX *matrix_stack;
92   MATRIX coordinate_system;
93   float viewport_focal_length;
94   int viewport_region_x;
95   int viewport_region_y;
96   int viewport_region_width;
97   int viewport_region_height;
98   PLANE clip_plane[5];
99   UINT32 matrix_base_address;
100   cached_texture *texcache[2][1024/32][2048/32];
101};
102
103
1104/*----------- defined in drivers/model3.c -----------*/
2105
3extern UINT32 *model3_vrom;
4extern int model3_step;
5
6106void model3_set_irq_line(running_machine *machine, UINT8 bit, int state);
7107
8108
9109/*----------- defined in machine/model3.c -----------*/
10110
11extern void model3_machine_init(int step);
12extern int model3_tap_read(void);
13extern void model3_tap_write(int tck, int tms, int tdi, int trst);
14extern void model3_tap_reset(void);
111extern void model3_machine_init(running_machine *machine, int step);
112extern int model3_tap_read(running_machine *machine);
113extern void model3_tap_write(running_machine *machine, int tck, int tms, int tdi, int trst);
114extern void model3_tap_reset(running_machine *machine);
15115extern READ32_HANDLER(rtc72421_r);
16116extern WRITE32_HANDLER(rtc72421_w);
17117
18118
19119/*----------- defined in video/model3.c -----------*/
20120
21extern UINT64 *paletteram64;
22
23121READ64_HANDLER(model3_char_r);
24122WRITE64_HANDLER(model3_char_w);
25123READ64_HANDLER(model3_tile_r);
src/mame/includes/cchasm.h
r10427r10428
66
77#include "machine/z80ctc.h"
88
9class cchasm_state : public driver_device
10{
11public:
12   cchasm_state(running_machine &machine, const driver_device_config_base &config)
13      : driver_device(machine, config) { }
14
15   int sound_flags;
16   int coin_flag;
17   device_t *ctc;
18   int channel_active[2];
19   int output[2];
20   UINT16 *ram;
21   int xcenter;
22   int ycenter;
23};
24
25
926/*----------- defined in machine/cchasm.c -----------*/
1027
1128WRITE16_HANDLER( cchasm_led_w );
r10427r10428
2845
2946/*----------- defined in video/cchasm.c -----------*/
3047
31extern UINT16 *cchasm_ram;
32
3348WRITE16_HANDLER( cchasm_refresh_control_w );
3449VIDEO_START( cchasm );
3550
src/mame/includes/cps3.h
r10427r10428
55****************************************************************************/
66
77#include "devlegcy.h"
8#include "machine/intelfsh.h"
89
9/*----------- defined in drivers/cps3.c -----------*/
10class cps3_state : public driver_device
11{
12public:
13   cps3_state(running_machine &machine, const driver_device_config_base &config)
14      : driver_device(machine, config) { }
1015
11extern UINT8* cps3_user5region;
16   fujitsu_29f016a_device *simm[7][8];
17   UINT32* decrypted_bios;
18   UINT32* decrypted_gamerom;
19   UINT32 cram_gfxflash_bank;
20   UINT32* nops;
21   UINT32* tilemap20_regs_base;
22   UINT32* tilemap30_regs_base;
23   UINT32* tilemap40_regs_base;
24   UINT32* tilemap50_regs_base;
25   UINT32* _0xc0000000_ram;
26   UINT32* _0xc0000000_ram_decrypted;
27   UINT32* char_ram;
28   UINT32* spriteram;
29   UINT32* eeprom;
30   UINT32* fullscreenzoom;
31   UINT32 ss_pal_base;
32   UINT32* colourram;
33   UINT32 unk_vidregs[0x20/4];
34   UINT32 ss_bank_base;
35   UINT32 screenwidth;
36   UINT32* mame_colours;
37   bitmap_t *renderbuffer_bitmap;
38   rectangle renderbuffer_clip;
39   UINT8* user4region;
40   UINT32 key1;
41   UINT32 key2;
42   int altEncryption;
43   UINT32* ss_ram;
44   UINT32 cram_bank;
45   UINT16 current_eeprom_read;
46   UINT32 paldma_source;
47   UINT32 paldma_realsource;
48   UINT32 paldma_dest;
49   UINT32 paldma_fade;
50   UINT32 paldma_other2;
51   UINT32 paldma_length;
52   UINT32 chardma_source;
53   UINT32 chardma_other;
54   UINT32 current_table_address;
55   int rle_length;
56   int last_normal_byte;
57   unsigned short lastb;
58   unsigned short lastb2;
59   UINT32* mainram;
60   UINT8* user5region;
61};
1262
1363
1464/*----------- defined in audio/cps3.c -----------*/
src/mame/includes/cinemat.h
r10427r10428
55*************************************************************************/
66
77
8class cinemat_state : public driver_device
9{
10public:
11   cinemat_state(running_machine &machine, const driver_device_config_base &config)
12      : driver_device(machine, config) { }
13
14   UINT8 sound_control;
15   UINT32 current_shift;
16   UINT32 last_shift;
17   UINT32 last_shift2;
18   UINT32 current_pitch;
19   UINT32 last_frame;
20   UINT8 sound_fifo[16];
21   UINT8 sound_fifo_in;
22   UINT8 sound_fifo_out;
23   UINT8 last_portb_write;
24   float target_volume;
25   float current_volume;
26   UINT16 *rambase;
27   UINT8 coin_detected;
28   UINT8 coin_last_reset;
29   UINT8 mux_select;
30   int gear;
31   int color_mode;
32   rgb_t vector_color;
33   INT16 lastx;
34   INT16 lasty;
35   UINT8 last_control;
36   int qb3_lastx;
37   int qb3_lasty;
38};
39
40
841/*----------- defined in drivers/cinemat.c -----------*/
942
1043MACHINE_RESET( cinemat );
src/mame/includes/wecleman.h
r10427r10428
1/*----------- defined in drivers/wecleman.c -----------*/
1class wecleman_state : public driver_device
2{
3public:
4   wecleman_state(running_machine &machine, const driver_device_config_base &config)
5      : driver_device(machine, config) { }
26
3extern int wecleman_selected_ip, wecleman_irqctrl;
7   UINT16 *blitter_regs;
8   int multiply_reg[2];
9   UINT16 *protection_ram;
10   int spr_color_offs;
11   int prot_state;
12   int selected_ip;
13   int irqctrl;
14   UINT16 *videostatus;
15   UINT16 *pageram;
16   UINT16 *txtram;
17   UINT16 *roadram;
18   size_t roadram_size;
19   int bgpage[4];
20   int fgpage[4];
21   const int *gfx_bank;
22   tilemap_t *bg_tilemap;
23   tilemap_t *fg_tilemap;
24   tilemap_t *txt_tilemap;
25   int *spr_idx_list;
26   int *spr_pri_list;
27   int *t32x32pm;
28   int gameid;
29   int spr_offsx;
30   int spr_offsy;
31   int spr_count;
32   UINT16 *rgb_half;
33   int cloud_blend;
34   int cloud_ds;
35   int cloud_visible;
36   pen_t black_pen;
37   struct sprite *sprite_list;
38   struct sprite **spr_ptr_list;
39};
440
541
642/*----------- defined in video/wecleman.c -----------*/
743
8extern UINT16 *wecleman_videostatus;
9extern UINT16 *wecleman_pageram, *wecleman_txtram, *wecleman_roadram;
10extern size_t wecleman_roadram_size;
11
1244WRITE16_HANDLER( hotchase_paletteram16_SBGRBBBBGGGGRRRR_word_w );
1345WRITE16_HANDLER( wecleman_paletteram16_SSSSBBBBGGGGRRRR_word_w );
1446WRITE16_HANDLER( wecleman_videostatus_w );
src/mame/includes/dec0.h
r10427r10428
1/*----------- defined in drivers/dec0.c -----------*/
1class dec0_state : public driver_device
2{
3public:
4   dec0_state(running_machine &machine, const driver_device_config_base &config)
5      : driver_device(machine, config) { }
26
3extern UINT16 *dec0_ram;
4extern UINT8 *robocop_shared_ram;
7   UINT8 automat_adpcm_byte;
8   int automat_msm5205_vclk_toggle;
9   UINT16 *ram;
10   UINT8 *robocop_shared_ram;
11   UINT16 *pf1_rowscroll;
12   UINT16 *pf2_rowscroll;
13   UINT16 *pf3_rowscroll;
14   UINT16 *pf1_colscroll;
15   UINT16 *pf2_colscroll;
16   UINT16 *pf3_colscroll;
17   UINT16 *pf1_data;
18   UINT16 *pf2_data;
19   UINT16 *pf3_data;
20   int GAME;
21   int i8751_return;
22   int i8751_command;
23   int slyspy_state;
24   int share[0xff];
25   int hippodrm_msb;
26   int hippodrm_lsb;
27   UINT8 i8751_ports[4];
28   tilemap_t *pf1_tilemap_0;
29   tilemap_t *pf1_tilemap_1;
30   tilemap_t *pf1_tilemap_2;
31   tilemap_t *pf2_tilemap_0;
32   tilemap_t *pf2_tilemap_1;
33   tilemap_t *pf2_tilemap_2;
34   tilemap_t *pf3_tilemap_0;
35   tilemap_t *pf3_tilemap_1;
36   tilemap_t *pf3_tilemap_2;
37   UINT16 pf1_control_0[4];
38   UINT16 pf1_control_1[4];
39   UINT16 pf2_control_0[4];
40   UINT16 pf2_control_1[4];
41   UINT16 pf3_control_0[4];
42   UINT16 pf3_control_1[4];
43   UINT16 *spriteram;
44   UINT16 pri;
45   int buffer[0x20];
46};
547
48
649/*----------- defined in video/dec0.c -----------*/
750
851/* Video emulation definitions */
r10427r10428
1659VIDEO_UPDATE( slyspy );
1760VIDEO_UPDATE( midres );
1861
19extern UINT16 *dec0_pf1_rowscroll,*dec0_pf2_rowscroll,*dec0_pf3_rowscroll;
20extern UINT16 *dec0_pf1_colscroll,*dec0_pf2_colscroll,*dec0_pf3_colscroll;
21extern UINT16 *dec0_pf1_data,*dec0_pf2_data,*dec0_pf3_data;
2262
2363WRITE16_HANDLER( dec0_pf1_control_0_w );
2464WRITE16_HANDLER( dec0_pf1_control_1_w );
r10427r10428
63103DRIVER_INIT( birdtry );
64104
65105extern void dec0_i8751_write(running_machine *machine, int data);
66extern void dec0_i8751_reset(void);
106extern void dec0_i8751_reset(running_machine *machine);
67107READ8_HANDLER( hippodrm_prot_r );
68108WRITE8_HANDLER( dec0_mcu_port_w );
69109READ8_HANDLER( dec0_mcu_port_r );
src/mame/includes/atarig42.h
r10427r10428
1313      : atarigen_state(machine, config) { }
1414
1515   UINT16         playfield_base;
16   UINT16         motion_object_base;
17   UINT16         motion_object_mask;
1816
1917   UINT16         current_control;
2018   UINT8         playfield_tile_bank;
r10427r10428
3028   int          sloop_offset;
3129   int          sloop_state;
3230   UINT16 *      sloop_base;
31
32   device_t *      rle;
3333};
3434
3535
3636/*----------- defined in video/atarig42.c -----------*/
3737
3838VIDEO_START( atarig42 );
39VIDEO_EOF( atarig42 );
3940VIDEO_UPDATE( atarig42 );
4041
4142WRITE16_HANDLER( atarig42_mo_control_w );
src/mame/includes/tp84.h
r10427r10428
1class tp84_state : public driver_device
2{
3public:
4   tp84_state(running_machine &machine, const driver_device_config_base &config)
5      : driver_device(machine, config) { }
6
7   cpu_device *audiocpu;
8   UINT8 *bg_videoram;
9   UINT8 *bg_colorram;
10   UINT8 *fg_videoram;
11   UINT8 *fg_colorram;
12   UINT8 *spriteram;
13   UINT8 *scroll_x;
14   UINT8 *scroll_y;
15   UINT8 *palette_bank;
16   UINT8 *flipscreen_x;
17   UINT8 *flipscreen_y;
18   tilemap_t *bg_tilemap;
19   tilemap_t *fg_tilemap;
20};
21
22
123/*----------- defined in video/tp84.c -----------*/
224
3extern UINT8 *tp84_bg_videoram;
4extern UINT8 *tp84_bg_colorram;
5extern UINT8 *tp84_fg_videoram;
6extern UINT8 *tp84_fg_colorram;
7extern UINT8 *tp84_spriteram;
8extern UINT8 *tp84_scroll_x;
9extern UINT8 *tp84_scroll_y;
10extern UINT8 *tp84_palette_bank;
11extern UINT8 *tp84_flipscreen_x;
12extern UINT8 *tp84_flipscreen_y;
13
1425WRITE8_HANDLER( tp84_spriteram_w );
1526READ8_HANDLER( tp84_scanline_r );
1627
src/mame/includes/segag80v.h
r10427r10428
55*************************************************************************/
66
77
8class segag80v_state : public driver_device
9{
10public:
11   segag80v_state(running_machine &machine, const driver_device_config_base &config)
12      : driver_device(machine, config) { }
13
14   UINT8 *mainram;
15   UINT8 has_usb;
16   UINT8 mult_data[2];
17   UINT16 mult_result;
18   UINT8 spinner_select;
19   UINT8 spinner_sign;
20   UINT8 spinner_count;
21   UINT8 *vectorram;
22   size_t vectorram_size;
23   int min_x;
24   int min_y;
25};
26
27
828/*----------- defined in audio/segag80v.c -----------*/
929
1030WRITE8_HANDLER( elim1_sh_w );
r10427r10428
1737
1838/*----------- defined in video/segag80v.c -----------*/
1939
20extern UINT8 *segag80v_vectorram;
21extern size_t segag80v_vectorram_size;
22
2340VIDEO_START( segag80v );
2441VIDEO_UPDATE( segag80v );
src/mame/includes/battlera.h
r10427r10428
1class battlera_state : public driver_device
2{
3public:
4   battlera_state(running_machine &machine, const driver_device_config_base &config)
5      : driver_device(machine, config) { }
6
7   int control_port_select;
8   int msm5205next;
9   int toggle;
10   int HuC6270_registers[20];
11   int VDC_register;
12   int vram_ptr;
13   UINT8 *HuC6270_vram;
14   UINT8 *vram_dirty;
15   bitmap_t *tile_bitmap;
16   bitmap_t *front_bitmap;
17   UINT32 tile_dirtyseq;
18   int current_scanline;
19   int inc_value;
20   int irq_enable;
21   int rcr_enable;
22   int sb_enable;
23   int bb_enable;
24   int bldwolf_vblank;
25   UINT8 blank_tile[32];
26};
27
28
129/*----------- defined in video/battlera.c -----------*/
230
331VIDEO_UPDATE( battlera );
src/mame/includes/madalien.h
r10427r10428
1212#define MADALIEN_MAIN_CLOCK      XTAL_10_595MHz
1313
1414
15/*----------- defined in video/madalien.c -----------*/
15class madalien_state : public driver_device
16{
17public:
18   madalien_state(running_machine &machine, const driver_device_config_base &config)
19      : driver_device(machine, config) { }
1620
17extern UINT8 *madalien_videoram;
18extern UINT8 *madalien_charram;
21   UINT8 *shift_hi;
22   UINT8 *shift_lo;
23   UINT8 *videoram;
24   UINT8 *charram;
25   UINT8 *video_flags;
26   UINT8 *video_control;
27   UINT8 *scroll;
28   UINT8 *edge1_pos;
29   UINT8 *edge2_pos;
30   UINT8 *headlight_pos;
31   tilemap_t *tilemap_fg;
32   tilemap_t *tilemap_edge1[4];
33   tilemap_t *tilemap_edge2[4];
34   bitmap_t *headlight_bitmap;
35};
1936
20extern UINT8 *madalien_video_flags;
21extern UINT8 *madalien_video_control;
22extern UINT8 *madalien_scroll;
23extern UINT8 *madalien_edge1_pos;
24extern UINT8 *madalien_edge2_pos;
25extern UINT8 *madalien_headlight_pos;
2637
38/*----------- defined in video/madalien.c -----------*/
39
2740MACHINE_CONFIG_EXTERN( madalien_video );
2841
2942WRITE8_HANDLER( madalien_videoram_w );
src/mame/includes/atarig1.h
r10427r10428
2727   UINT8         playfield_tile_bank;
2828   UINT16         playfield_xscroll;
2929   UINT16         playfield_yscroll;
30
31   device_t *      rle;
3032};
3133
3234
r10427r10428
3537WRITE16_HANDLER( atarig1_mo_control_w );
3638
3739VIDEO_START( atarig1 );
40VIDEO_EOF( atarig1 );
3841VIDEO_UPDATE( atarig1 );
3942
4043void atarig1_scanline_update(screen_device &screen, int scanline);
src/mame/includes/srumbler.h
r10427r10428
1class srumbler_state : public driver_device
2{
3public:
4   srumbler_state(running_machine &machine, const driver_device_config_base &config)
5      : driver_device(machine, config) { }
6
7   UINT8 *backgroundram;
8   UINT8 *foregroundram;
9   tilemap_t *bg_tilemap;
10   tilemap_t *fg_tilemap;
11   int scroll[4];
12};
13
14
115/*----------- defined in video/srumbler.c -----------*/
216
3extern UINT8 *srumbler_backgroundram,*srumbler_foregroundram;
4
517WRITE8_HANDLER( srumbler_background_w );
618WRITE8_HANDLER( srumbler_foreground_w );
719WRITE8_HANDLER( srumbler_scroll_w );
src/mame/includes/tumbleb.h
r10427r10428
3131   device_t *maincpu;
3232   device_t *audiocpu;
3333   device_t *oki;
34   UINT8 semicom_prot_offset;
35   UINT16 protbase;
3436};
3537
3638/*----------- defined in video/tumbleb.c -----------*/
src/mame/includes/micro3d.h
r10427r10428
1717public:
1818   micro3d_state(running_machine &machine, const driver_device_config_base &config)
1919      : driver_device(machine, config) { }
20
21   struct
22   {
23      union
24      {
25         struct
26         {
27            UINT8 gpdr;
28            UINT8 aer;
29            UINT8 ddr;
30            UINT8 iera;
31            UINT8 ierb;
32            UINT8 ipra;
33            UINT8 iprb;
34            UINT8 isra;
35            UINT8 isrb;
36            UINT8 imra;
37            UINT8 imrb;
38            UINT8 vr;
39            UINT8 tacr;
40            UINT8 tbcr;
41            UINT8 tcdcr;
42            UINT8 tadr;
43            UINT8 tbdr;
44            UINT8 tcdr;
45            UINT8 tddr;
46            UINT8 scr;
47            UINT8 ucr;
48            UINT8 rsr;
49            UINT8 tsr;
50            UINT8 udr;
51         };
52         UINT8 regs[24];
53      };
54
55      emu_timer *timer_a;
56   } mc68901;
57
20   
5821   UINT16            *shared_ram;
59   device_t      *duart68681;
22   device_t         *duart68681;
6023   UINT8            m68681_tx0;
6124
6225   /* Sound */
r10427r10428
11982
12083/*----------- defined in machine/micro3d.c -----------*/
12184
122READ16_HANDLER( micro3d_mc68901_r );
123WRITE16_HANDLER( micro3d_mc68901_w );
124
12585READ16_HANDLER( micro3d_ti_uart_r );
12686WRITE16_HANDLER( micro3d_ti_uart_w );
12787
src/mame/includes/tigeroad.h
r10427r10428
55      : driver_device(machine, config) { }
66
77   UINT16 *videoram;
8   UINT16 *ram16;
9   int bgcharbank;
10   tilemap_t *bg_tilemap;
11   tilemap_t *fg_tilemap;
812};
913
1014
src/mame/includes/segas32.h
r10427r10428
55***************************************************************************/
66
77
8/*----------- defined in drivers/segas32.c -----------*/
8typedef void (*sys32_output_callback)(int which, UINT16 data);
9struct layer_info
10{
11   bitmap_t *   bitmap;
12   UINT8 *               transparent;
13};
914
10extern UINT8 *ga2_dpram;
11extern UINT16 *system32_workram;
12extern UINT16 *system32_protram;
1315
16class segas32_state : public driver_device
17{
18public:
19   segas32_state(running_machine &machine, const driver_device_config_base &config)
20      : driver_device(machine, config) { }
1421
22   UINT8 *z80_shared_ram;
23   UINT8 v60_irq_control[0x10];
24   timer_device *v60_irq_timer[2];
25   UINT8 sound_irq_control[4];
26   UINT8 sound_irq_input;
27   UINT8 sound_dummy_value;
28   UINT16 sound_bank;
29   UINT8 misc_io_data[2][0x10];
30   read16_space_func custom_io_r[2];
31   write16_space_func custom_io_w[2];
32   UINT8 analog_bank;
33   UINT8 analog_value[4];
34   UINT8 sonic_last[6];
35   sys32_output_callback sw1_output;
36   sys32_output_callback sw2_output;
37   sys32_output_callback sw3_output;
38   UINT16* dual_pcb_comms;
39   UINT8 *ga2_dpram;
40   UINT16 *system32_workram;
41   UINT16 *system32_protram;
42   UINT16 *system32_videoram;
43   UINT16 *system32_spriteram;
44   UINT16 *system32_paletteram[2];
45   UINT16 system32_displayenable[2];
46   UINT16 system32_tilebank_external;
47   UINT16 arescue_dsp_io[6];
48   UINT8 is_multi32;
49   struct cache_entry *cache_head;
50   struct layer_info layer_data[11];
51   UINT16 mixer_control[2][0x40];
52   UINT16 *solid_0000;
53   UINT16 *solid_ffff;
54   UINT8 sprite_render_count;
55   UINT8 sprite_control_latched[8];
56   UINT8 sprite_control[8];
57   UINT32 *spriteram_32bit;
58};
59
60
1561/*----------- defined in machine/segas32.c -----------*/
1662
1763READ16_HANDLER( arabfgt_protection_r );
r10427r10428
4288
4389/*----------- defined in video/segas32.c -----------*/
4490
45extern UINT16 *system32_videoram;
46extern UINT16 *system32_spriteram;
47extern UINT16 *system32_paletteram[2];
48extern UINT16 system32_displayenable[2];
49extern UINT16 system32_tilebank_external;
50
5191VIDEO_START(system32);
5292VIDEO_START(multi32);
5393VIDEO_UPDATE(system32);
src/mame/includes/mystwarr.h
r10427r10428
1class mystwarr_state : public driver_device
2{
3public:
4   mystwarr_state(running_machine &machine, const driver_device_config_base &config)
5      : driver_device(machine, config) { }
6
7   UINT16 *gx_workram;
8   UINT8 mw_irq_control;
9   int cur_sound_region;
10   int layer_colorbase[6];
11   int oinprion;
12   int cbparam;
13   int sprite_colorbase;
14   int sub1_colorbase;
15   int last_psac_colorbase;
16   int gametype;
17   int roz_enable;
18   int roz_rombank;
19   tilemap_t *ult_936_tilemap;
20   UINT16 clip;
21};
22
23
124/*----------- defined in video/mystwarr.c -----------*/
225
326VIDEO_START( gaiapols );
src/mame/includes/djmain.h
r10427r10428
1class djmain_state : public driver_device
2{
3public:
4   djmain_state(running_machine &machine, const driver_device_config_base &config)
5      : driver_device(machine, config) { }
6
7   int sndram_bank;
8   UINT8 *sndram;
9   int turntable_select;
10   UINT8 turntable_last_pos[2];
11   UINT16 turntable_pos[2];
12   UINT8 pending_vb_int;
13   UINT16 v_ctrl;
14   UINT32 obj_regs[0xa0/4];
15   const UINT8 *ide_user_password;
16   const UINT8 *ide_master_password;
17   UINT32 *obj_ram;
18};
19
20
121/*----------- defined in video/djmain.c -----------*/
222
3extern UINT32 *djmain_obj_ram;
4
523VIDEO_UPDATE( djmain );
624VIDEO_START( djmain );
725
src/mame/includes/pcktgal.h
r10427r10428
55      : driver_device(machine, config) { }
66
77   UINT8 *videoram;
8   int msm5205next;
9   int toggle;
10   tilemap_t *bg_tilemap;
811};
912
1013
src/mame/includes/suprloco.h
r10427r10428
1class suprloco_state : public driver_device
2{
3public:
4   suprloco_state(running_machine &machine, const driver_device_config_base &config)
5      : driver_device(machine, config) { }
6
7   UINT8 *videoram;
8   UINT8 *scrollram;
9   tilemap_t *bg_tilemap;
10   int control;
11};
12
13
114/*----------- defined in video/suprloco.c -----------*/
215
3extern UINT8 *suprloco_videoram;
4extern UINT8 *suprloco_scrollram;
5
616PALETTE_INIT( suprloco );
717VIDEO_START( suprloco );
818VIDEO_UPDATE( suprloco );
src/mame/includes/atarigx2.h
r10427r10428
1313      : atarigen_state(machine, config) { }
1414
1515   UINT16         playfield_base;
16   UINT16         motion_object_base;
17   UINT16         motion_object_mask;
1816
1917   UINT32 *      mo_command;
2018   UINT32 *      protection_base;
r10427r10428
2725
2826   UINT16         last_write;
2927   UINT16         last_write_offset;
28
29   device_t *      rle;
3030};
3131
3232
3333/*----------- defined in video/atarigx2.c -----------*/
3434
3535VIDEO_START( atarigx2 );
36VIDEO_EOF( atarigx2 );
3637VIDEO_UPDATE( atarigx2 );
3738
3839WRITE16_HANDLER( atarigx2_mo_control_w );
src/mame/includes/vulgus.h
r10427r10428
1class vulgus_state : public driver_device
2{
3public:
4   vulgus_state(running_machine &machine, const driver_device_config_base &config)
5      : driver_device(machine, config) { }
6
7   UINT8 *fgvideoram;
8   UINT8 *bgvideoram;
9   UINT8 *scroll_low;
10   UINT8 *scroll_high;
11   int palette_bank;
12   tilemap_t *fg_tilemap;
13   tilemap_t *bg_tilemap;
14};
15
16
117/*----------- defined in video/vulgus.c -----------*/
218
3extern UINT8 *vulgus_fgvideoram;
4extern UINT8 *vulgus_bgvideoram;
5extern UINT8 *vulgus_scroll_low,*vulgus_scroll_high;
6
719WRITE8_HANDLER( vulgus_fgvideoram_w );
820WRITE8_HANDLER( vulgus_bgvideoram_w );
921WRITE8_HANDLER( vulgus_c804_w );
src/mame/includes/twin16.h
r10427r10428
55      : driver_device(machine, config) { }
66
77   UINT16 *videoram;
8   UINT16 CPUA_register;
9   UINT16 CPUB_register;
10   UINT16 sound_command;
11   int cuebrickj_nvram_bank;
12   UINT16 cuebrickj_nvram[0x400*0x20];
13   UINT16 custom_video;
14   UINT16 *gfx_rom;
15   UINT16 *text_ram;
16   UINT16 *sprite_gfx_ram;
17   UINT16 *tile_gfx_ram;
18   UINT16 sprite_buffer[0x800];
19   emu_timer *sprite_timer;
20   int sprite_busy;
21   int need_process_spriteram;
22   UINT16 gfx_bank;
23   UINT16 scrollx[3];
24   UINT16 scrolly[3];
25   UINT16 video_register;
26   tilemap_t *text_tilemap;
827};
928
1029
1130/*----------- defined in drivers/twin16.c -----------*/
1231
13extern UINT16 twin16_custom_video;
14extern UINT16 *twin16_gfx_rom;
15extern UINT16 *twin16_text_ram;
16extern UINT16 *twin16_sprite_gfx_ram;
17extern UINT16 *twin16_tile_gfx_ram;
18int twin16_spriteram_process_enable( void );
32int twin16_spriteram_process_enable( running_machine *machine );
1933
2034
2135/*----------- defined in video/twin16.c -----------*/
r10427r10428
3044VIDEO_UPDATE( twin16 );
3145VIDEO_EOF( twin16 );
3246
33void twin16_spriteram_process( running_machine* );
47void twin16_spriteram_process( running_machine *machine );
src/mame/includes/atarigt.h
r10427r10428
4444   UINT8         protmode;
4545   UINT16         protresult;
4646   UINT8         protdata[0x800];
47
48   device_t *      rle;
4749};
4850
4951
r10427r10428
5355UINT16 atarigt_colorram_r(atarigt_state *state, offs_t address);
5456
5557VIDEO_START( atarigt );
58VIDEO_EOF( atarigt );
5659VIDEO_UPDATE( atarigt );
5760
5861void atarigt_scanline_update(screen_device &screen, int scanline);
src/mame/mame.mak
r10427r10428
204204SOUNDS += GAELCO_GAE1
205205SOUNDS += C6280
206206SOUNDS += SP0250
207SOUNDS += PSXSPU
207SOUNDS += SPU
208208SOUNDS += CDDA
209209SOUNDS += ICS2115
210210SOUNDS += ST0016
r10427r10428
381381
382382$(MAMEOBJ)/aristocr.a: \
383383   $(DRIVERS)/86lions.o \
384   $(DRIVERS)/caswin.o \
385384   $(DRIVERS)/aristmk4.o \
386385   $(DRIVERS)/aristmk5.o \
386   $(DRIVERS)/caswin.o \
387387   $(MACHINE)/archimds.o \
388388   $(VIDEO)/archimds.o \
389389
r10427r10428
514514   $(DRIVERS)/cps2.o \
515515   $(DRIVERS)/cps3.o $(AUDIO)/cps3.o \
516516   $(DRIVERS)/egghunt.o \
517   $(DRIVERS)/exedexes.o $(VIDEO)/exedexes.o \
517518   $(DRIVERS)/fcrash.o \
518519   $(DRIVERS)/gng.o $(VIDEO)/gng.o \
519520   $(DRIVERS)/gunsmoke.o $(VIDEO)/gunsmoke.o \
520   $(DRIVERS)/exedexes.o $(VIDEO)/exedexes.o \
521521   $(DRIVERS)/higemaru.o $(VIDEO)/higemaru.o \
522522   $(DRIVERS)/lastduel.o $(VIDEO)/lastduel.o \
523523   $(DRIVERS)/lwings.o $(VIDEO)/lwings.o \
r10427r10428
526526   $(DRIVERS)/sidearms.o $(VIDEO)/sidearms.o \
527527   $(DRIVERS)/sonson.o $(VIDEO)/sonson.o \
528528   $(DRIVERS)/srumbler.o $(VIDEO)/srumbler.o \
529   $(DRIVERS)/tigeroad.o $(VIDEO)/tigeroad.o \
529530   $(DRIVERS)/vulgus.o $(VIDEO)/vulgus.o \
530   $(DRIVERS)/tigeroad.o $(VIDEO)/tigeroad.o \
531531   $(DRIVERS)/zn.o $(MACHINE)/znsec.o \
532532   $(DRIVERS)/taitogn.o \
533533   $(MACHINE)/cps2crpt.o \
r10427r10428
560560   $(DRIVERS)/boogwing.o $(VIDEO)/boogwing.o \
561561   $(DRIVERS)/brkthru.o $(VIDEO)/brkthru.o \
562562   $(DRIVERS)/btime.o $(MACHINE)/btime.o $(VIDEO)/btime.o \
563   $(DRIVERS)/chanbara.o \
564563   $(DRIVERS)/bwing.o $(VIDEO)/bwing.o \
565   $(DRIVERS)/deshoros.o \
566564   $(DRIVERS)/cbuster.o $(VIDEO)/cbuster.o \
565   $(DRIVERS)/chanbara.o \
567566   $(DRIVERS)/cninja.o $(VIDEO)/cninja.o \
568567   $(DRIVERS)/cntsteer.o \
569568   $(DRIVERS)/compgolf.o $(VIDEO)/compgolf.o \
r10427r10428
577576   $(DRIVERS)/deco156.o $(MACHINE)/deco156.o \
578577   $(DRIVERS)/deco32.o $(VIDEO)/deco32.o \
579578   $(DRIVERS)/decocass.o $(MACHINE)/decocass.o $(VIDEO)/decocass.o \
579   $(DRIVERS)/deshoros.o \
580580   $(DRIVERS)/dietgo.o $(VIDEO)/dietgo.o \
581581   $(DRIVERS)/exprraid.o $(VIDEO)/exprraid.o \
582582   $(DRIVERS)/firetrap.o $(VIDEO)/firetrap.o \
src/mame/video/deco_mlc.c
r10427r10428
1414//extern int mlc_raster_table[9][256];
1515//extern UINT32 mlc_clipper[32];
1616//static bitmap_t *temp_bitmap;
17static UINT32 colour_mask, *mlc_buffered_spriteram;
18UINT32 *mlc_vram, *mlc_clip_ram;
1917
2018/******************************************************************************/
2119
2220VIDEO_START( mlc )
2321{
22   deco_mlc_state *state = machine->driver_data<deco_mlc_state>();
2423   if (machine->gfx[0]->color_granularity==16)
25      colour_mask=0x7f;
24      state->colour_mask=0x7f;
2625   else if (machine->gfx[0]->color_granularity==32)
27      colour_mask=0x3f;
26      state->colour_mask=0x3f;
2827   else
29      colour_mask=0x1f;
28      state->colour_mask=0x1f;
3029
3130//  temp_bitmap = auto_bitmap_alloc( machine, 512, 512, BITMAP_FORMAT_RGB32 );
32   mlc_buffered_spriteram = auto_alloc_array(machine, UINT32, 0x3000/4);
31   state->mlc_buffered_spriteram = auto_alloc_array(machine, UINT32, 0x3000/4);
3332}
3433
3534#ifdef UNUSED_FUNCTION
3635static void blitRaster(running_machine *machine, bitmap_t *bitmap, int rasterMode)
3736{
37   deco_mlc_state *state = machine->driver_data<deco_mlc_state>();
3838   int x,y;
3939   for (y=0; y<256; y++) //todo
4040   {
4141      UINT32* src=BITMAP_ADDR32(temp_bitmap, y&0x1ff, 0);
4242      UINT32* dst=BITMAP_ADDR32(bitmap, y, 0);
43      UINT32 xptr=(mlc_raster_table[0][y]<<13);
43      UINT32 xptr=(state->mlc_raster_table[0][y]<<13);
4444
4545      if (input_code_pressed(machine, KEYCODE_X))
4646         xptr=0;
r10427r10428
5353         //if (input_code_pressed(machine, KEYCODE_X))
5454         //  xptr+=0x10000;
5555         //else if(rasterHackTest[0][y]<0)
56            xptr+=0x10000 - ((mlc_raster_table[2][y]&0x3ff)<<5);
56            xptr+=0x10000 - ((state->mlc_raster_table[2][y]&0x3ff)<<5);
5757         //else
58         //  xptr+=0x10000 + (mlc_raster_table[0][y]<<5);
58         //  xptr+=0x10000 + (state->mlc_raster_table[0][y]<<5);
5959      }
6060   }
6161}
r10427r10428
227227
228228static void draw_sprites(running_machine* machine, bitmap_t *bitmap,const rectangle *cliprect)
229229{
230   deco_mlc_state *state = machine->driver_data<deco_mlc_state>();
230231   UINT32 *index_ptr=0;
231232   int offs,fx=0,fy=0,x,y,color,colorOffset,sprite,indx,h,w,bx,by,fx1,fy1;
232233   int xoffs,yoffs;
r10427r10428
245246//  int rasterDirty=0;
246247   int clipper=0;
247248   rectangle user_clip;
248   UINT32* mlc_spriteram=mlc_buffered_spriteram; // spriteram32
249   UINT32* mlc_spriteram=state->mlc_buffered_spriteram; // spriteram32
249250
250251   for (offs = (0x3000/4)-8; offs>=0; offs-=8)
251252   {
r10427r10428
312313        however there are space for 8 clipping windows, where is the high bit? (Or is it ~0x400?) */
313314      clipper=((clipper&2)>>1)|((clipper&1)<<1); // Swap low two bits
314315
315      user_clip.min_y=mlc_clip_ram[(clipper*4)+0];
316      user_clip.max_y=mlc_clip_ram[(clipper*4)+1];
317      user_clip.min_x=mlc_clip_ram[(clipper*4)+2];
318      user_clip.max_x=mlc_clip_ram[(clipper*4)+3];
316      user_clip.min_y=state->mlc_clip_ram[(clipper*4)+0];
317      user_clip.max_y=state->mlc_clip_ram[(clipper*4)+1];
318      user_clip.min_x=state->mlc_clip_ram[(clipper*4)+2];
319      user_clip.max_x=state->mlc_clip_ram[(clipper*4)+3];
319320
320321      sect_rect(&user_clip, cliprect);
321322
322323      /* Any colours out of range (for the bpp value) trigger 'shadow' mode */
323      if (color & (colour_mask+1))
324      if (color & (state->colour_mask+1))
324325         alpha=0x80;
325326      else
326327         alpha=0xff;
327      color&=colour_mask;
328      color&=state->colour_mask;
328329
329330      /* If this bit is set, combine this block with the next one */
330331      if (mlc_spriteram[offs+1]&0x1000) {
r10427r10428
371372
372373      } else {
373374         indx&=0x1fff;
374         index_ptr=mlc_vram + indx*4;
375         index_ptr=state->mlc_vram + indx*4;
375376         h=(index_ptr[0]>>8)&0xf;
376377         w=(index_ptr[1]>>8)&0xf;
377378
r10427r10428
379380         if (!w) w=16;
380381
381382         if (use8bppMode) {
382            UINT32* index_ptr2=mlc_vram + ((indx2*4)&0x7fff);
383            UINT32* index_ptr2=state->mlc_vram + ((indx2*4)&0x7fff);
383384            sprite2=((index_ptr2[2]&0x3)<<16) | (index_ptr2[3]&0xffff);
384385         }
385386
r10427r10428
459460               }
460461               else
461462               {
462                  const UINT32* ptr=mlc_vram + ((sprite)&0x7fff);
463                  const UINT32* ptr=state->mlc_vram + ((sprite)&0x7fff);
463464                  tile=(*ptr)&0xffff;
464465
465466                  if (tileFormat)
r10427r10428
510511
511512VIDEO_EOF( mlc )
512513{
514   deco_mlc_state *state = machine->driver_data<deco_mlc_state>();
513515   /* Spriteram is definitely double buffered, as the vram lookup tables
514516    are often updated a frame after spriteram is setup to point to a new
515517    lookup table.  Without buffering incorrect one frame glitches are seen
516518    in several places, especially in Hoops.
517519    */
518   memcpy(mlc_buffered_spriteram, machine->generic.spriteram.u32, 0x3000);
520   memcpy(state->mlc_buffered_spriteram, machine->generic.spriteram.u32, 0x3000);
519521}
520522
521523VIDEO_UPDATE( mlc )
src/mame/video/tryout.c
r10427r10428
88#include "emu.h"
99#include "includes/tryout.h"
1010
11static tilemap_t *fg_tilemap, *bg_tilemap;
12static UINT8 vram_bank;
13static UINT8 *tryout_vram, *tryout_vram_gfx;
14UINT8 *tryout_gfx_control;
1511
1612PALETTE_INIT( tryout )
1713{
r10427r10428
5753
5854static TILE_GET_INFO( get_bg_tile_info )
5955{
60   SET_TILE_INFO(2, tryout_vram[tile_index] & 0x7f, 2, 0);
56   tryout_state *state = machine->driver_data<tryout_state>();
57   SET_TILE_INFO(2, state->vram[tile_index] & 0x7f, 2, 0);
6158}
6259
6360READ8_HANDLER( tryout_vram_r )
6461{
65   return tryout_vram[offset]; // debug only
62   tryout_state *state = space->machine->driver_data<tryout_state>();
63   return state->vram[offset]; // debug only
6664}
6765
6866WRITE8_HANDLER( tryout_videoram_w )
r10427r10428
7068   tryout_state *state = space->machine->driver_data<tryout_state>();
7169   UINT8 *videoram = state->videoram;
7270   videoram[offset] = data;
73   tilemap_mark_tile_dirty(fg_tilemap, offset & 0x3ff);
71   tilemap_mark_tile_dirty(state->fg_tilemap, offset & 0x3ff);
7472}
7573
7674WRITE8_HANDLER( tryout_vram_w )
7775{
76   tryout_state *state = space->machine->driver_data<tryout_state>();
7877   /*  There are eight banks of vram - in bank 0 the first 0x400 bytes
7978    is reserved for the tilemap.  In banks 2, 4 and 6 the game never
8079    writes to the first 0x400 bytes - I suspect it's either
r10427r10428
8887    gfx data and then set high from that point onwards.
8988
9089    */
91   const UINT8 bank=(vram_bank>>1)&0x7;
90   const UINT8 bank=(state->vram_bank>>1)&0x7;
9291
9392
9493   if ((bank==0 || bank==2 || bank==4 || bank==6) && (offset&0x7ff)<0x400) {
9594      int newoff=offset&0x3ff;
9695
97      tryout_vram[newoff]=data;
98      tilemap_mark_tile_dirty(bg_tilemap,newoff);
96      state->vram[newoff]=data;
97      tilemap_mark_tile_dirty(state->bg_tilemap,newoff);
9998      return;
10099   }
101100
r10427r10428
109108    */
110109
111110   offset=(offset&0x7ff) | (bank<<11);
112   tryout_vram[offset]=data;
111   state->vram[offset]=data;
113112
114113   switch (offset&0x1c00) {
115114   case 0x0400:
116      tryout_vram_gfx[(offset&0x3ff) + 0x0000 + ((offset&0x2000)>>1)]=(~data&0xf);
117      tryout_vram_gfx[(offset&0x3ff) + 0x2000 + ((offset&0x2000)>>1)]=(~data&0xf0)>>4;
115      state->vram_gfx[(offset&0x3ff) + 0x0000 + ((offset&0x2000)>>1)]=(~data&0xf);
116      state->vram_gfx[(offset&0x3ff) + 0x2000 + ((offset&0x2000)>>1)]=(~data&0xf0)>>4;
118117      break;
119118   case 0x0800:
120      tryout_vram_gfx[(offset&0x3ff) + 0x4000 + ((offset&0x2000)>>1)]=(~data&0xf);
121      tryout_vram_gfx[(offset&0x3ff) + 0x4400 + ((offset&0x2000)>>1)]=(~data&0xf0)>>4;
119      state->vram_gfx[(offset&0x3ff) + 0x4000 + ((offset&0x2000)>>1)]=(~data&0xf);
120      state->vram_gfx[(offset&0x3ff) + 0x4400 + ((offset&0x2000)>>1)]=(~data&0xf0)>>4;
122121      break;
123122   case 0x0c00:
124      tryout_vram_gfx[(offset&0x3ff) + 0x0400 + ((offset&0x2000)>>1)]=(~data&0xf);
125      tryout_vram_gfx[(offset&0x3ff) + 0x2400 + ((offset&0x2000)>>1)]=(~data&0xf0)>>4;
123      state->vram_gfx[(offset&0x3ff) + 0x0400 + ((offset&0x2000)>>1)]=(~data&0xf);
124      state->vram_gfx[(offset&0x3ff) + 0x2400 + ((offset&0x2000)>>1)]=(~data&0xf0)>>4;
126125      break;
127126   case 0x1400:
128      tryout_vram_gfx[(offset&0x3ff) + 0x0800 + ((offset&0x2000)>>1)]=(~data&0xf);
129      tryout_vram_gfx[(offset&0x3ff) + 0x2800 + ((offset&0x2000)>>1)]=(~data&0xf0)>>4;
127      state->vram_gfx[(offset&0x3ff) + 0x0800 + ((offset&0x2000)>>1)]=(~data&0xf);
128      state->vram_gfx[(offset&0x3ff) + 0x2800 + ((offset&0x2000)>>1)]=(~data&0xf0)>>4;
130129      break;
131130   case 0x1800:
132      tryout_vram_gfx[(offset&0x3ff) + 0x4800 + ((offset&0x2000)>>1)]=(~data&0xf);
133      tryout_vram_gfx[(offset&0x3ff) + 0x4c00 + ((offset&0x2000)>>1)]=(~data&0xf0)>>4;
131      state->vram_gfx[(offset&0x3ff) + 0x4800 + ((offset&0x2000)>>1)]=(~data&0xf);
132      state->vram_gfx[(offset&0x3ff) + 0x4c00 + ((offset&0x2000)>>1)]=(~data&0xf0)>>4;
134133      break;
135134   case 0x1c00:
136      tryout_vram_gfx[(offset&0x3ff) + 0x0c00 + ((offset&0x2000)>>1)]=(~data&0xf);
137      tryout_vram_gfx[(offset&0x3ff) + 0x2c00 + ((offset&0x2000)>>1)]=(~data&0xf0)>>4;
135      state->vram_gfx[(offset&0x3ff) + 0x0c00 + ((offset&0x2000)>>1)]=(~data&0xf);
136      state->vram_gfx[(offset&0x3ff) + 0x2c00 + ((offset&0x2000)>>1)]=(~data&0xf0)>>4;
138137      break;
139138   }
140139
r10427r10428
143142
144143WRITE8_HANDLER( tryout_vram_bankswitch_w )
145144{
146   vram_bank = data;
145   tryout_state *state = space->machine->driver_data<tryout_state>();
146   state->vram_bank = data;
147147}
148148
149149WRITE8_HANDLER( tryout_flipscreen_w )
r10427r10428
170170
171171VIDEO_START( tryout )
172172{
173   fg_tilemap = tilemap_create(machine, get_fg_tile_info,get_fg_memory_offset,8,8,32,32);
174   bg_tilemap = tilemap_create(machine, get_bg_tile_info,get_bg_memory_offset,16,16,64,16);
173   tryout_state *state = machine->driver_data<tryout_state>();
174   state->fg_tilemap = tilemap_create(machine, get_fg_tile_info,get_fg_memory_offset,8,8,32,32);
175   state->bg_tilemap = tilemap_create(machine, get_bg_tile_info,get_bg_memory_offset,16,16,64,16);
175176
176   tryout_vram=auto_alloc_array(machine, UINT8, 8 * 0x800);
177   tryout_vram_gfx=auto_alloc_array(machine, UINT8, 0x6000);
177   state->vram=auto_alloc_array(machine, UINT8, 8 * 0x800);
178   state->vram_gfx=auto_alloc_array(machine, UINT8, 0x6000);
178179
179   gfx_element_set_source(machine->gfx[2], tryout_vram_gfx);
180   gfx_element_set_source(machine->gfx[2], state->vram_gfx);
180181
181   tilemap_set_transparent_pen(fg_tilemap,0);
182   tilemap_set_transparent_pen(state->fg_tilemap,0);
182183}
183184
184185static void draw_sprites(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect)
r10427r10428
233234
234235VIDEO_UPDATE( tryout )
235236{
237   tryout_state *state = screen->machine->driver_data<tryout_state>();
236238   int scrollx = 0;
237239
238240   if (!flip_screen_get(screen->machine))
239      tilemap_set_scrollx(fg_tilemap, 0, 16); /* Assumed hard-wired */
241      tilemap_set_scrollx(state->fg_tilemap, 0, 16); /* Assumed hard-wired */
240242   else
241      tilemap_set_scrollx(fg_tilemap, 0, -8); /* Assumed hard-wired */
243      tilemap_set_scrollx(state->fg_tilemap, 0, -8); /* Assumed hard-wired */
242244
243   scrollx = tryout_gfx_control[1] + ((tryout_gfx_control[0]&1)<<8) + ((tryout_gfx_control[0]&4)<<7) - ((tryout_gfx_control[0] & 2) ? 0 : 0x100);
245   scrollx = state->gfx_control[1] + ((state->gfx_control[0]&1)<<8) + ((state->gfx_control[0]&4)<<7) - ((state->gfx_control[0] & 2) ? 0 : 0x100);
244246
245247   /* wrap-around */
246   if(tryout_gfx_control[1] == 0) { scrollx+=0x100; }
248   if(state->gfx_control[1] == 0) { scrollx+=0x100; }
247249
248   tilemap_set_scrollx(bg_tilemap, 0, scrollx+2); /* why +2? hard-wired? */
249   tilemap_set_scrolly(bg_tilemap, 0, -tryout_gfx_control[2]);
250   tilemap_set_scrollx(state->bg_tilemap, 0, scrollx+2); /* why +2? hard-wired? */
251   tilemap_set_scrolly(state->bg_tilemap, 0, -state->gfx_control[2]);
250252
251   if(!(tryout_gfx_control[0] & 0x8)) // screen disable
253   if(!(state->gfx_control[0] & 0x8)) // screen disable
252254   {
253255      /* TODO: Color might be different, needs a video from an original pcb. */
254256      bitmap_fill(bitmap, cliprect, screen->machine->pens[0x10]);
255257   }
256258   else
257259   {
258      tilemap_draw(bitmap,cliprect,bg_tilemap,0,0);
259      tilemap_draw(bitmap,cliprect,fg_tilemap,0,0);
260      tilemap_draw(bitmap,cliprect,state->bg_tilemap,0,0);
261      tilemap_draw(bitmap,cliprect,state->fg_tilemap,0,0);
260262      draw_sprites(screen->machine, bitmap,cliprect);
261263   }
262264
263//  popmessage("%02x %02x %02x %02x",tryout_gfx_control[0],tryout_gfx_control[1],tryout_gfx_control[2],scrollx);
265//  popmessage("%02x %02x %02x %02x",state->gfx_control[0],state->gfx_control[1],state->gfx_control[2],scrollx);
264266   return 0;
265267}
src/mame/video/hexion.c
r10427r10428
11#include "emu.h"
22#include "includes/hexion.h"
33
4static UINT8 *vram[2],*unkram;
5static int bankctrl,rambank,pmcbank,gfxrom_select;
6static tilemap_t *bg_tilemap[2];
74
85
96
r10427r10428
2522
2623static TILE_GET_INFO( get_tile_info0 )
2724{
28   get_tile_info(machine,tileinfo,tile_index,vram[0]);
25   hexion_state *state = machine->driver_data<hexion_state>();
26   get_tile_info(machine,tileinfo,tile_index,state->vram[0]);
2927}
3028
3129static TILE_GET_INFO( get_tile_info1 )
3230{
33   get_tile_info(machine,tileinfo,tile_index,vram[1]);
31   hexion_state *state = machine->driver_data<hexion_state>();
32   get_tile_info(machine,tileinfo,tile_index,state->vram[1]);
3433}
3534
3635
r10427r10428
4342
4443VIDEO_START( hexion )
4544{
46   bg_tilemap[0] = tilemap_create(machine, get_tile_info0,tilemap_scan_rows,8,8,64,32);
47   bg_tilemap[1] = tilemap_create(machine, get_tile_info1,tilemap_scan_rows,     8,8,64,32);
45   hexion_state *state = machine->driver_data<hexion_state>();
46   state->bg_tilemap[0] = tilemap_create(machine, get_tile_info0,tilemap_scan_rows,8,8,64,32);
47   state->bg_tilemap[1] = tilemap_create(machine, get_tile_info1,tilemap_scan_rows,     8,8,64,32);
4848
49   tilemap_set_transparent_pen(bg_tilemap[0],0);
50   tilemap_set_scrollx(bg_tilemap[1],0,-4);
51   tilemap_set_scrolly(bg_tilemap[1],0,4);
49   tilemap_set_transparent_pen(state->bg_tilemap[0],0);
50   tilemap_set_scrollx(state->bg_tilemap[1],0,-4);
51   tilemap_set_scrolly(state->bg_tilemap[1],0,4);
5252
53   vram[0] = machine->region("maincpu")->base() + 0x30000;
54   vram[1] = vram[0] + 0x2000;
55   unkram = vram[1] + 0x2000;
53   state->vram[0] = machine->region("maincpu")->base() + 0x30000;
54   state->vram[1] = state->vram[0] + 0x2000;
55   state->unkram = state->vram[1] + 0x2000;
5656}
5757
5858
r10427r10428
6565
6666WRITE8_HANDLER( hexion_bankswitch_w )
6767{
68   hexion_state *state = space->machine->driver_data<hexion_state>();
6869   UINT8 *rom = space->machine->region("maincpu")->base() + 0x10000;
6970
7071   /* bits 0-3 select ROM bank */
r10427r10428
7374   /* does bit 6 trigger the 052591? */
7475   if (data & 0x40)
7576   {
76      int bank = unkram[0]&1;
77      memset(vram[bank],unkram[1],0x2000);
78      tilemap_mark_all_tiles_dirty(bg_tilemap[bank]);
77      int bank = state->unkram[0]&1;
78      memset(state->vram[bank],state->unkram[1],0x2000);
79      tilemap_mark_all_tiles_dirty(state->bg_tilemap[bank]);
7980   }
8081   /* bit 7 = PMC-BK */
81   pmcbank = (data & 0x80) >> 7;
82   state->pmcbank = (data & 0x80) >> 7;
8283
8384   /* other bits unknown */
8485if (data & 0x30)
r10427r10428
8990
9091READ8_HANDLER( hexion_bankedram_r )
9192{
92   if (gfxrom_select && offset < 0x1000)
93   hexion_state *state = space->machine->driver_data<hexion_state>();
94   if (state->gfxrom_select && offset < 0x1000)
9395   {
94      return space->machine->region("gfx1")->base()[((gfxrom_select & 0x7f) << 12) + offset];
96      return space->machine->region("gfx1")->base()[((state->gfxrom_select & 0x7f) << 12) + offset];
9597   }
96   else if (bankctrl == 0)
98   else if (state->bankctrl == 0)
9799   {
98      return vram[rambank][offset];
100      return state->vram[state->rambank][offset];
99101   }
100   else if (bankctrl == 2 && offset < 0x800)
102   else if (state->bankctrl == 2 && offset < 0x800)
101103   {
102      return unkram[offset];
104      return state->unkram[offset];
103105   }
104106   else
105107   {
106//logerror("%04x: bankedram_r offset %04x, bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,bankctrl);
108//logerror("%04x: bankedram_r offset %04x, state->bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,state->bankctrl);
107109      return 0;
108110   }
109111}
110112
111113WRITE8_HANDLER( hexion_bankedram_w )
112114{
113   if (bankctrl == 3 && offset == 0 && (data & 0xfe) == 0)
115   hexion_state *state = space->machine->driver_data<hexion_state>();
116   if (state->bankctrl == 3 && offset == 0 && (data & 0xfe) == 0)
114117   {
115//logerror("%04x: bankedram_w offset %04x, data %02x, bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,data,bankctrl);
116      rambank = data & 1;
118//logerror("%04x: bankedram_w offset %04x, data %02x, state->bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,data,state->bankctrl);
119      state->rambank = data & 1;
117120   }
118   else if (bankctrl == 0)
121   else if (state->bankctrl == 0)
119122   {
120      if (pmcbank)
123      if (state->pmcbank)
121124      {
122//logerror("%04x: bankedram_w offset %04x, data %02x, bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,data,bankctrl);
123         vram[rambank][offset] = data;
124         tilemap_mark_tile_dirty(bg_tilemap[rambank],offset/4);
125//logerror("%04x: bankedram_w offset %04x, data %02x, state->bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,data,state->bankctrl);
126         state->vram[state->rambank][offset] = data;
127         tilemap_mark_tile_dirty(state->bg_tilemap[state->rambank],offset/4);
125128      }
126129      else
127130         logerror("%04x pmc internal ram %04x = %02x\n",cpu_get_pc(space->cpu),offset,data);
128131   }
129   else if (bankctrl == 2 && offset < 0x800)
132   else if (state->bankctrl == 2 && offset < 0x800)
130133   {
131      if (pmcbank)
134      if (state->pmcbank)
132135      {
133//logerror("%04x: unkram_w offset %04x, data %02x, bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,data,bankctrl);
134         unkram[offset] = data;
136//logerror("%04x: unkram_w offset %04x, data %02x, state->bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,data,state->bankctrl);
137         state->unkram[offset] = data;
135138      }
136139      else
137140         logerror("%04x pmc internal ram %04x = %02x\n",cpu_get_pc(space->cpu),offset,data);
138141   }
139142   else
140logerror("%04x: bankedram_w offset %04x, data %02x, bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,data,bankctrl);
143logerror("%04x: bankedram_w offset %04x, data %02x, state->bankctrl = %02x\n",cpu_get_pc(space->cpu),offset,data,state->bankctrl);
141144}
142145
143146WRITE8_HANDLER( hexion_bankctrl_w )
144147{
148   hexion_state *state = space->machine->driver_data<hexion_state>();
145149//logerror("%04x: bankctrl_w %02x\n",cpu_get_pc(space->cpu),data);
146   bankctrl = data;
150   state->bankctrl = data;
147151}
148152
149153WRITE8_HANDLER( hexion_gfxrom_select_w )
150154{
155   hexion_state *state = space->machine->driver_data<hexion_state>();
151156//logerror("%04x: gfxrom_select_w %02x\n",cpu_get_pc(space->cpu),data);
152   gfxrom_select = data;
157   state->gfxrom_select = data;
153158}
154159
155160
r10427r10428
162167
163168VIDEO_UPDATE( hexion )
164169{
165   tilemap_draw(bitmap,cliprect,bg_tilemap[1],0,0);
166   tilemap_draw(bitmap,cliprect,bg_tilemap[0],0,0);
170   hexion_state *state = screen->machine->driver_data<hexion_state>();
171   tilemap_draw(bitmap,cliprect,state->bg_tilemap[1],0,0);
172   tilemap_draw(bitmap,cliprect,state->bg_tilemap[0],0,0);
167173   return 0;
168174}
src/mame/video/system1.c
r10427r10428
8181#include "emu.h"
8282#include "includes/system1.h"
8383
84static UINT8 *mix_collide;
85static UINT8 mix_collide_summary;
86static UINT8 *sprite_collide;
87static UINT8 sprite_collide_summary;
8884
89static bitmap_t *sprite_bitmap;
90
91static UINT8 system1_video_mode;
92
93static UINT8 videoram_bank;
94
95static tilemap_t *tilemap_page[8];
96static UINT8 tilemap_pages;
97
98
99
10085/*************************************
10186 *
10287 *  Tile callback
r10427r10428
127112   int pagenum;
128113
129114   /* allocate memory for the collision arrays */
130   mix_collide = auto_alloc_array_clear(machine, UINT8, 64);
131   sprite_collide = auto_alloc_array_clear(machine, UINT8, 1024);
115   state->mix_collide = auto_alloc_array_clear(machine, UINT8, 64);
116   state->sprite_collide = auto_alloc_array_clear(machine, UINT8, 1024);
132117
133118   /* allocate memory for videoram */
134   tilemap_pages = pagecount;
119   state->tilemap_pages = pagecount;
135120   state->videoram = auto_alloc_array_clear(machine, UINT8, 0x800 * pagecount);
136121
137122   /* create the tilemap pages */
138123   for (pagenum = 0; pagenum < pagecount; pagenum++)
139124   {
140      tilemap_page[pagenum] = tilemap_create(machine, tile_get_info, tilemap_scan_rows, 8,8, 32,32);
141      tilemap_set_transparent_pen(tilemap_page[pagenum], 0);
142      tilemap_set_user_data(tilemap_page[pagenum], state->videoram + 0x800 * pagenum);
125      state->tilemap_page[pagenum] = tilemap_create(machine, tile_get_info, tilemap_scan_rows, 8,8, 32,32);
126      tilemap_set_transparent_pen(state->tilemap_page[pagenum], 0);
127      tilemap_set_user_data(state->tilemap_page[pagenum], state->videoram + 0x800 * pagenum);
143128   }
144129
145130   /* allocate a temporary bitmap for sprite rendering */
146   sprite_bitmap = auto_bitmap_alloc(machine, 256, 256, BITMAP_FORMAT_INDEXED16);
131   state->sprite_bitmap = auto_bitmap_alloc(machine, 256, 256, BITMAP_FORMAT_INDEXED16);
147132
148133   /* register for save stats */
149   state_save_register_global(machine, system1_video_mode);
150   state_save_register_global(machine, mix_collide_summary);
151   state_save_register_global(machine, sprite_collide_summary);
134   state_save_register_global(machine, state->video_mode);
135   state_save_register_global(machine, state->mix_collide_summary);
136   state_save_register_global(machine, state->sprite_collide_summary);
152137   state->save_pointer(NAME(state->videoram), 0x800 * pagecount);
153   state_save_register_global_pointer(machine, mix_collide, 64);
154   state_save_register_global_pointer(machine, sprite_collide, 1024);
138   state_save_register_global_pointer(machine, state->mix_collide, 64);
139   state_save_register_global_pointer(machine, state->sprite_collide, 1024);
155140}
156141
157142
r10427r10428
176161
177162WRITE8_HANDLER( system1_videomode_w )
178163{
164   system1_state *state = space->machine->driver_data<system1_state>();
179165if (data & 0x6e) logerror("videomode = %02x\n",data);
180166
181167   /* bit 4 is screen blank */
182   system1_video_mode = data;
168   state->video_mode = data;
183169
184170   /* bit 7 is flip screen */
185171   flip_screen_set(space->machine, data & 0x80);
r10427r10428
195181
196182READ8_HANDLER( system1_mixer_collision_r )
197183{
184   system1_state *state = space->machine->driver_data<system1_state>();
198185   space->machine->primary_screen->update_now();
199   return mix_collide[offset & 0x3f] | 0x7e | (mix_collide_summary << 7);
186   return state->mix_collide[offset & 0x3f] | 0x7e | (state->mix_collide_summary << 7);
200187}
201188
202189WRITE8_HANDLER( system1_mixer_collision_w )
203190{
191   system1_state *state = space->machine->driver_data<system1_state>();
204192   space->machine->primary_screen->update_now();
205   mix_collide[offset & 0x3f] = 0;
193   state->mix_collide[offset & 0x3f] = 0;
206194}
207195
208196WRITE8_HANDLER( system1_mixer_collision_reset_w )
209197{
198   system1_state *state = space->machine->driver_data<system1_state>();
210199   space->machine->primary_screen->update_now();
211   mix_collide_summary = 0;
200   state->mix_collide_summary = 0;
212201}
213202
214203
r10427r10428
221210
222211READ8_HANDLER( system1_sprite_collision_r )
223212{
213   system1_state *state = space->machine->driver_data<system1_state>();
224214   space->machine->primary_screen->update_now();
225   return sprite_collide[offset & 0x3ff] | 0x7e | (sprite_collide_summary << 7);
215   return state->sprite_collide[offset & 0x3ff] | 0x7e | (state->sprite_collide_summary << 7);
226216}
227217
228218WRITE8_HANDLER( system1_sprite_collision_w )
229219{
220   system1_state *state = space->machine->driver_data<system1_state>();
230221   space->machine->primary_screen->update_now();
231   sprite_collide[offset & 0x3ff] = 0;
222   state->sprite_collide[offset & 0x3ff] = 0;
232223}
233224
234225WRITE8_HANDLER( system1_sprite_collision_reset_w )
235226{
227   system1_state *state = space->machine->driver_data<system1_state>();
236228   space->machine->primary_screen->update_now();
237   sprite_collide_summary = 0;
229   state->sprite_collide_summary = 0;
238230}
239231
240232
r10427r10428
265257   system1_state *state = space->machine->driver_data<system1_state>();
266258   UINT8 *videoram = state->videoram;
267259   videoram_wait_states(space->machine->firstcpu);
268   offset |= 0x1000 * ((videoram_bank >> 1) % (tilemap_pages / 2));
260   offset |= 0x1000 * ((state->videoram_bank >> 1) % (state->tilemap_pages / 2));
269261   return videoram[offset];
270262}
271263
r10427r10428
274266   system1_state *state = space->machine->driver_data<system1_state>();
275267   UINT8 *videoram = state->videoram;
276268   videoram_wait_states(space->machine->firstcpu);
277   offset |= 0x1000 * ((videoram_bank >> 1) % (tilemap_pages / 2));
269   offset |= 0x1000 * ((state->videoram_bank >> 1) % (state->tilemap_pages / 2));
278270   videoram[offset] = data;
279271
280   tilemap_mark_tile_dirty(tilemap_page[offset / 0x800], (offset % 0x800) / 2);
272   tilemap_mark_tile_dirty(state->tilemap_page[offset / 0x800], (offset % 0x800) / 2);
281273
282274   /* force a partial update if the page is changing */
283   if (tilemap_pages > 2 && offset >= 0x740 && offset < 0x748 && offset % 2 == 0)
275   if (state->tilemap_pages > 2 && offset >= 0x740 && offset < 0x748 && offset % 2 == 0)
284276      space->machine->primary_screen->update_now();
285277}
286278
287279WRITE8_DEVICE_HANDLER( system1_videoram_bank_w )
288280{
289   videoram_bank = data;
281   system1_state *state = device->machine->driver_data<system1_state>();
282   state->videoram_bank = data;
290283}
291284
292285
r10427r10428
370363
371364static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int xoffset)
372365{
366   system1_state *state = machine->driver_data<system1_state>();
373367   UINT32 gfxbanks = machine->region("sprites")->bytes() / 0x8000;
374368   const UINT8 *gfxbase = machine->region("sprites")->base();
375369   UINT8 *spriteram = machine->generic.spriteram.u8;
r10427r10428
456450                  int prevpix = destbase[effx];
457451
458452                  if ((prevpix & 0x0f) != 0)
459                     sprite_collide[((prevpix >> 4) & 0x1f) + 32 * spritenum] = sprite_collide_summary = 1;
453                     state->sprite_collide[((prevpix >> 4) & 0x1f) + 32 * spritenum] = state->sprite_collide_summary = 1;
460454                  destbase[effx] = color1 | palettebase;
461455               }
462456            }
r10427r10428
474468                  int prevpix = destbase[effx];
475469
476470                  if ((prevpix & 0x0f) != 0)
477                     sprite_collide[((prevpix >> 4) & 0x1f) + 32 * spritenum] = sprite_collide_summary = 1;
471                     state->sprite_collide[((prevpix >> 4) & 0x1f) + 32 * spritenum] = state->sprite_collide_summary = 1;
478472                  destbase[effx] = color2 | palettebase;
479473               }
480474            }
r10427r10428
493487
494488static void video_update_common(device_t *screen, bitmap_t *bitmap, const rectangle *cliprect, bitmap_t *fgpixmap, bitmap_t **bgpixmaps, const int *bgrowscroll, int bgyscroll, int spritexoffs)
495489{
490   system1_state *state = screen->machine->driver_data<system1_state>();
496491   const UINT8 *lookup = screen->machine->region("proms")->base();
497492   int x, y;
498493
499494   /* first clear the sprite bitmap and draw sprites within this area */
500   bitmap_fill(sprite_bitmap, cliprect, 0);
501   draw_sprites(screen->machine, sprite_bitmap, cliprect, spritexoffs);
495   bitmap_fill(state->sprite_bitmap, cliprect, 0);
496   draw_sprites(screen->machine, state->sprite_bitmap, cliprect, spritexoffs);
502497
503498   /* iterate over rows */
504499   for (y = cliprect->min_y; y <= cliprect->max_y; y++)
505500   {
506501      UINT16 *fgbase = BITMAP_ADDR16(fgpixmap, y & 0xff, 0);
507      UINT16 *sprbase = BITMAP_ADDR16(sprite_bitmap, y & 0xff, 0);
502      UINT16 *sprbase = BITMAP_ADDR16(state->sprite_bitmap, y & 0xff, 0);
508503      UINT16 *dstbase = BITMAP_ADDR16(bitmap, y, 0);
509504      int bgy = (y + bgyscroll) & 0x1ff;
510505      int bgxscroll = bgrowscroll[y / 8];
r10427r10428
534529
535530         /* compute collisions based on two of the PROM bits */
536531         if (!(lookup_value & 4))
537            mix_collide[((lookup_value & 8) << 2) | ((sprpix >> 4) & 0x1f)] = mix_collide_summary = 1;
532            state->mix_collide[((lookup_value & 8) << 2) | ((sprpix >> 4) & 0x1f)] = state->mix_collide_summary = 1;
538533
539534         /* the lower 2 PROM bits select the palette and which pixels */
540535         lookup_value &= 3;
541         if (system1_video_mode & 0x10)
536         if (state->video_mode & 0x10)
542537            dstbase[x] = 0;
543538         else if (lookup_value == 0)
544539            dstbase[x] = 0x000 | (sprpix & 0x1ff);
r10427r10428
568563   int y;
569564
570565   /* all 4 background pages are the same, fixed to page 0 */
571   bgpixmaps[0] = bgpixmaps[1] = bgpixmaps[2] = bgpixmaps[3] = tilemap_get_pixmap(tilemap_page[0]);
566   bgpixmaps[0] = bgpixmaps[1] = bgpixmaps[2] = bgpixmaps[3] = tilemap_get_pixmap(state->tilemap_page[0]);
572567
573568   /* foreground is fixed to page 1 */
574   fgpixmap = tilemap_get_pixmap(tilemap_page[1]);
569   fgpixmap = tilemap_get_pixmap(state->tilemap_page[1]);
575570
576571   /* get fixed scroll offsets */
577572   xscroll = (videoram[0xffc] | (videoram[0xffd] << 8)) / 2 + 14;
r10427r10428
605600   int y;
606601
607602   /* 4 independent background pages */
608   bgpixmaps[0] = tilemap_get_pixmap(tilemap_page[videoram[0x740] & 7]);
609   bgpixmaps[1] = tilemap_get_pixmap(tilemap_page[videoram[0x742] & 7]);
610   bgpixmaps[2] = tilemap_get_pixmap(tilemap_page[videoram[0x744] & 7]);
611   bgpixmaps[3] = tilemap_get_pixmap(tilemap_page[videoram[0x746] & 7]);
603   bgpixmaps[0] = tilemap_get_pixmap(state->tilemap_page[videoram[0x740] & 7]);
604   bgpixmaps[1] = tilemap_get_pixmap(state->tilemap_page[videoram[0x742] & 7]);
605   bgpixmaps[2] = tilemap_get_pixmap(state->tilemap_page[videoram[0x744] & 7]);
606   bgpixmaps[3] = tilemap_get_pixmap(state->tilemap_page[videoram[0x746] & 7]);
612607
613608   /* foreground is fixed to page 0 */
614   fgpixmap = tilemap_get_pixmap(tilemap_page[0]);
609   fgpixmap = tilemap_get_pixmap(state->tilemap_page[0]);
615610
616611   /* get scroll offsets */
617612   if (!flip_screen_get(screen->machine))
r10427r10428
647642   int y;
648643
649644   /* 4 independent background pages */
650   bgpixmaps[0] = tilemap_get_pixmap(tilemap_page[videoram[0x740] & 7]);
651   bgpixmaps[1] = tilemap_get_pixmap(tilemap_page[videoram[0x742] & 7]);
652   bgpixmaps[2] = tilemap_get_pixmap(tilemap_page[videoram[0x744] & 7]);
653   bgpixmaps[3] = tilemap_get_pixmap(tilemap_page[videoram[0x746] & 7]);
645   bgpixmaps[0] = tilemap_get_pixmap(state->tilemap_page[videoram[0x740] & 7]);
646   bgpixmaps[1] = tilemap_get_pixmap(state->tilemap_page[videoram[0x742] & 7]);
647   bgpixmaps[2] = tilemap_get_pixmap(state->tilemap_page[videoram[0x744] & 7]);
648   bgpixmaps[3] = tilemap_get_pixmap(state->tilemap_page[videoram[0x746] & 7]);
654649
655650   /* foreground is fixed to page 0 */
656   fgpixmap = tilemap_get_pixmap(tilemap_page[0]);
651   fgpixmap = tilemap_get_pixmap(state->tilemap_page[0]);
657652
658653   /* get scroll offsets */
659654   if (!flip_screen_get(screen->machine))
src/mame/video/powerins.c
r10427r10428
4040#include "emu.h"
4141#include "includes/powerins.h"
4242
43/* Variables that driver has access to: */
44UINT16 *powerins_vram_0, *powerins_vctrl_0;
45UINT16 *powerins_vram_1, *powerins_vctrl_1;
46//UINT16 *powerins_vregs;
4743
48/* Variables only used here: */
49static tilemap_t *tilemap_0, *tilemap_1;
50static int tile_bank;
51
52
53
5444/***************************************************************************
5545
5646                        Hardware registers access
r10427r10428
6555
6656WRITE16_HANDLER( powerins_tilebank_w )
6757{
58   powerins_state *state = space->machine->driver_data<powerins_state>();
6859   if (ACCESSING_BITS_0_7)
6960   {
70      if (data != tile_bank)
61      if (data != state->tile_bank)
7162      {
72         tile_bank = data;      // Tiles Bank (VRAM 0)
73         tilemap_mark_all_tiles_dirty(tilemap_0);
63         state->tile_bank = data;      // Tiles Bank (VRAM 0)
64         tilemap_mark_all_tiles_dirty(state->tilemap_0);
7465      }
7566   }
7667}
r10427r10428
130121
131122static TILE_GET_INFO( get_tile_info_0 )
132123{
133   UINT16 code = powerins_vram_0[tile_index];
124   powerins_state *state = machine->driver_data<powerins_state>();
125   UINT16 code = state->vram_0[tile_index];
134126   SET_TILE_INFO(
135127         0,
136         (code & 0x07ff) + (tile_bank*0x800),
128         (code & 0x07ff) + (state->tile_bank*0x800),
137129         ((code & 0xf000) >> (16-4)) + ((code & 0x0800) >> (11-4)),
138130         0);
139131}
140132
141133WRITE16_HANDLER( powerins_vram_0_w )
142134{
143   COMBINE_DATA(&powerins_vram_0[offset]);
144   tilemap_mark_tile_dirty(tilemap_0, offset);
135   powerins_state *state = space->machine->driver_data<powerins_state>();
136   COMBINE_DATA(&state->vram_0[offset]);
137   tilemap_mark_tile_dirty(state->tilemap_0, offset);
145138}
146139
147140static TILEMAP_MAPPER( powerins_get_memory_offset_0 )
r10427r10428
170163
171164static TILE_GET_INFO( get_tile_info_1 )
172165{
173   UINT16 code = powerins_vram_1[tile_index];
166   powerins_state *state = machine->driver_data<powerins_state>();
167   UINT16 code = state->vram_1[tile_index];
174168   SET_TILE_INFO(
175169         1,
176170         code & 0x0fff,
r10427r10428
180174
181175WRITE16_HANDLER( powerins_vram_1_w )
182176{
183   COMBINE_DATA(&powerins_vram_1[offset]);
184   tilemap_mark_tile_dirty(tilemap_1, offset);
177   powerins_state *state = space->machine->driver_data<powerins_state>();
178   COMBINE_DATA(&state->vram_1[offset]);
179   tilemap_mark_tile_dirty(state->tilemap_1, offset);
185180}
186181
187182
r10427r10428
198193
199194VIDEO_START( powerins )
200195{
201   tilemap_0 = tilemap_create(   machine, get_tile_info_0,
196   powerins_state *state = machine->driver_data<powerins_state>();
197   state->tilemap_0 = tilemap_create(   machine, get_tile_info_0,
202198                        powerins_get_memory_offset_0,
203199
204200                        16,16,
205201                        DIM_NX_0, DIM_NY_0 );
206202
207   tilemap_1 = tilemap_create(   machine, get_tile_info_1,
203   state->tilemap_1 = tilemap_create(   machine, get_tile_info_1,
208204                        tilemap_scan_cols,
209205
210206                        8,8,
211207                        DIM_NX_1, DIM_NY_1 );
212208
213      tilemap_set_scroll_rows(tilemap_0,1);
214      tilemap_set_scroll_cols(tilemap_0,1);
209      tilemap_set_scroll_rows(state->tilemap_0,1);
210      tilemap_set_scroll_cols(state->tilemap_0,1);
215211
216      tilemap_set_scroll_rows(tilemap_1,1);
217      tilemap_set_scroll_cols(tilemap_1,1);
218      tilemap_set_transparent_pen(tilemap_1,15);
212      tilemap_set_scroll_rows(state->tilemap_1,1);
213      tilemap_set_scroll_cols(state->tilemap_1,1);
214      tilemap_set_transparent_pen(state->tilemap_1,15);
219215}
220216
221217
r10427r10428
345341
346342VIDEO_UPDATE( powerins )
347343{
344   powerins_state *state = screen->machine->driver_data<powerins_state>();
348345   int layers_ctrl = -1;
349346
350   int scrollx = (powerins_vctrl_0[2/2]&0xff) + (powerins_vctrl_0[0/2]&0xff)*256;
351   int scrolly = (powerins_vctrl_0[6/2]&0xff) + (powerins_vctrl_0[4/2]&0xff)*256;
347   int scrollx = (state->vctrl_0[2/2]&0xff) + (state->vctrl_0[0/2]&0xff)*256;
348   int scrolly = (state->vctrl_0[6/2]&0xff) + (state->vctrl_0[4/2]&0xff)*256;
352349
353   tilemap_set_scrollx( tilemap_0, 0, scrollx - 0x20);
354   tilemap_set_scrolly( tilemap_0, 0, scrolly );
350   tilemap_set_scrollx( state->tilemap_0, 0, scrollx - 0x20);
351   tilemap_set_scrolly( state->tilemap_0, 0, scrolly );
355352
356   tilemap_set_scrollx( tilemap_1, 0, -0x20);   // fixed offset
357   tilemap_set_scrolly( tilemap_1, 0,  0x00);
353   tilemap_set_scrollx( state->tilemap_1, 0, -0x20);   // fixed offset
354   tilemap_set_scrolly( state->tilemap_1, 0,  0x00);
358355
359356#ifdef MAME_DEBUG
360357if (input_code_pressed(screen->machine, KEYCODE_Z))
r10427r10428
369366}
370367#endif
371368
372   if (layers_ctrl&1)      tilemap_draw(bitmap,cliprect, tilemap_0, 0, 0);
369   if (layers_ctrl&1)      tilemap_draw(bitmap,cliprect, state->tilemap_0, 0, 0);
373370   else               bitmap_fill(bitmap,cliprect,0);
374371   if (layers_ctrl&8)      draw_sprites(screen->machine,bitmap,cliprect);
375   if (layers_ctrl&2)      tilemap_draw(bitmap,cliprect, tilemap_1, 0, 0);
372   if (layers_ctrl&2)      tilemap_draw(bitmap,cliprect, state->tilemap_1, 0, 0);
376373   return 0;
377374}
src/mame/video/deco32.c
r10427r10428
11#include "emu.h"
22#include "includes/deco32.h"
33
4UINT32 *deco32_pf1_data,*deco32_pf2_data,*deco32_pf3_data,*deco32_pf4_data;
5UINT32 *deco32_pf12_control,*deco32_pf34_control;
6UINT32 *deco32_pf1_rowscroll,*deco32_pf2_rowscroll,*deco32_pf3_rowscroll,*deco32_pf4_rowscroll;
7UINT32 *dragngun_sprite_layout_0_ram, *dragngun_sprite_layout_1_ram;
8UINT32 *dragngun_sprite_lookup_0_ram, *dragngun_sprite_lookup_1_ram;
9UINT32 *deco32_ace_ram;
104
11static UINT8 *dirty_palette;
12static tilemap_t *pf1_tilemap,*pf1a_tilemap,*pf2_tilemap,*pf3_tilemap,*pf4_tilemap;
13static int deco32_pf1_bank,deco32_pf2_bank,deco32_pf3_bank,deco32_pf4_bank;
14static int deco32_pf1_flip,deco32_pf2_flip,deco32_pf3_flip,deco32_pf4_flip;
15static int deco32_pf2_colourbank,deco32_pf4_colourbank,deco32_pri;
16
17static bitmap_t *sprite0_mix_bitmap, *sprite1_mix_bitmap, *tilemap_alpha_bitmap;
18
19static UINT32 dragngun_sprite_ctrl;
20static int deco32_ace_ram_dirty, has_ace_ram;
21
22int deco32_raster_display_position;
23UINT16 *deco32_raster_display_list;
24
255/******************************************************************************
266
277 This sprite_priority_bitmap handling is the same as in deco16ic.c
288
299******************************************************************************/
3010
31static bitmap_t *sprite_priority_bitmap;
3211
33static void deco16_clear_sprite_priority_bitmap(void)
12static void deco16_clear_sprite_priority_bitmap(deco32_state *state)
3413{
35   if (sprite_priority_bitmap)
36      bitmap_fill(sprite_priority_bitmap,NULL,0);
14   if (state->sprite_priority_bitmap)
15      bitmap_fill(state->sprite_priority_bitmap,NULL,0);
3716}
3817
3918/* A special pdrawgfx z-buffered sprite renderer that is needed to properly draw multiple sprite sources with alpha */
r10427r10428
4221      UINT32 code,UINT32 color,int flipx,int flipy,int sx,int sy,
4322      int transparent_color,UINT32 pri_mask,UINT32 sprite_mask,UINT8 write_pri,UINT8 alpha)
4423{
24   deco32_state *state = gfx->machine->driver_data<deco32_state>();
4525   int ox,oy,cx,cy;
4626   int x_index,y_index,x,y;
4727   bitmap_t *priority_bitmap = gfx->machine->priority_bitmap;
r10427r10428
6949      const UINT8 *source = code_base + (y_index * gfx->line_modulo);
7050      UINT32 *destb = BITMAP_ADDR32(dest, sy, 0);
7151      UINT8 *pri = BITMAP_ADDR8(priority_bitmap, sy, 0);
72      UINT8 *spri = BITMAP_ADDR8(sprite_priority_bitmap, sy, 0);
52      UINT8 *spri = BITMAP_ADDR8(state->sprite_priority_bitmap, sy, 0);
7353
7454      if (sy >= 0 && sy < 248)
7555      {
r10427r10428
10585
10686WRITE32_HANDLER( deco32_pf1_data_w )
10787{
108   COMBINE_DATA(&deco32_pf1_data[offset]);
109   tilemap_mark_tile_dirty(pf1_tilemap,offset);
110   if (pf1a_tilemap && offset<0x400)
111      tilemap_mark_tile_dirty(pf1a_tilemap,offset);
88   deco32_state *state = space->machine->driver_data<deco32_state>();
89   COMBINE_DATA(&state->pf1_data[offset]);
90   tilemap_mark_tile_dirty(state->pf1_tilemap,offset);
91   if (state->pf1a_tilemap && offset<0x400)
92      tilemap_mark_tile_dirty(state->pf1a_tilemap,offset);
11293}
11394
11495WRITE32_HANDLER( deco32_pf2_data_w )
11596{
116   COMBINE_DATA(&deco32_pf2_data[offset]);
117   tilemap_mark_tile_dirty(pf2_tilemap,offset);
97   deco32_state *state = space->machine->driver_data<deco32_state>();
98   COMBINE_DATA(&state->pf2_data[offset]);
99   tilemap_mark_tile_dirty(state->pf2_tilemap,offset);
118100}
119101
120102WRITE32_HANDLER( deco32_pf3_data_w )
121103{
122   COMBINE_DATA(&deco32_pf3_data[offset]);
123   tilemap_mark_tile_dirty(pf3_tilemap,offset);
104   deco32_state *state = space->machine->driver_data<deco32_state>();
105   COMBINE_DATA(&state->pf3_data[offset]);
106   tilemap_mark_tile_dirty(state->pf3_tilemap,offset);
124107}
125108
126109WRITE32_HANDLER( deco32_pf4_data_w )
127110{
128   COMBINE_DATA(&deco32_pf4_data[offset]);
129   tilemap_mark_tile_dirty(pf4_tilemap,offset);
111   deco32_state *state = space->machine->driver_data<deco32_state>();
112   COMBINE_DATA(&state->pf4_data[offset]);
113   tilemap_mark_tile_dirty(state->pf4_tilemap,offset);
130114}
131115
132116/******************************************************************************/
133117
134118WRITE32_HANDLER( deco32_pri_w )
135119{
136   deco32_pri=data;
120   deco32_state *state = space->machine->driver_data<deco32_state>();
121   state->pri=data;
137122}
138123
139124WRITE32_HANDLER( dragngun_sprite_control_w )
140125{
141   dragngun_sprite_ctrl=data;
126   deco32_state *state = space->machine->driver_data<deco32_state>();
127   state->dragngun_sprite_ctrl=data;
142128}
143129
144130WRITE32_HANDLER( dragngun_spriteram_dma_w )
r10427r10428
150136
151137WRITE32_HANDLER( deco32_ace_ram_w )
152138{
139   deco32_state *state = space->machine->driver_data<deco32_state>();
153140   /* Some notes pieced together from Tattoo Assassins info:
154141
155142        Bytes 0 to 0x58 - object alpha control?
r10427r10428
181168
182169        'fadetype' - 1100 for multiplicative fade, 1000 for additive
183170    */
184   if (offset>=(0x80/4) && (data!=deco32_ace_ram[offset]))
185      deco32_ace_ram_dirty=1;
171   if (offset>=(0x80/4) && (data!=state->ace_ram[offset]))
172      state->ace_ram_dirty=1;
186173
187   COMBINE_DATA(&deco32_ace_ram[offset]);
174   COMBINE_DATA(&state->ace_ram[offset]);
188175}
189176
190177static void updateAceRam(running_machine* machine)
191178{
179   deco32_state *state = machine->driver_data<deco32_state>();
192180   int r,g,b,i;
193   UINT8 fadeptr=deco32_ace_ram[0x20];
194   UINT8 fadeptg=deco32_ace_ram[0x21];
195   UINT8 fadeptb=deco32_ace_ram[0x22];
196   UINT8 fadepsr=deco32_ace_ram[0x23];
197   UINT8 fadepsg=deco32_ace_ram[0x24];
198   UINT8 fadepsb=deco32_ace_ram[0x25];
199//  UINT8 mode=deco32_ace_ram[0x26];
181   UINT8 fadeptr=state->ace_ram[0x20];
182   UINT8 fadeptg=state->ace_ram[0x21];
183   UINT8 fadeptb=state->ace_ram[0x22];
184   UINT8 fadepsr=state->ace_ram[0x23];
185   UINT8 fadepsg=state->ace_ram[0x24];
186   UINT8 fadepsb=state->ace_ram[0x25];
187//  UINT8 mode=state->ace_ram[0x26];
200188
201   deco32_ace_ram_dirty=0;
189   state->ace_ram_dirty=0;
202190
203191   for (i=0; i<2048; i++)
204192   {
r10427r10428
239227
240228WRITE32_HANDLER( deco32_buffered_palette_w )
241229{
230   deco32_state *state = space->machine->driver_data<deco32_state>();
242231   COMBINE_DATA(&space->machine->generic.paletteram.u32[offset]);
243   dirty_palette[offset]=1;
232   state->dirty_palette[offset]=1;
244233}
245234
246235WRITE32_HANDLER( deco32_palette_dma_w )
247236{
237   deco32_state *state = space->machine->driver_data<deco32_state>();
248238   const int m=space->machine->total_colors();
249239   int r,g,b,i;
250240
251241   for (i=0; i<m; i++) {
252      if (dirty_palette[i]) {
253         dirty_palette[i]=0;
242      if (state->dirty_palette[i]) {
243         state->dirty_palette[i]=0;
254244
255         if (has_ace_ram)
245         if (state->has_ace_ram)
256246         {
257            deco32_ace_ram_dirty=1;
247            state->ace_ram_dirty=1;
258248         }
259249         else
260250         {
r10427r10428
753743
754744static void dragngun_draw_sprites(running_machine* machine, bitmap_t *bitmap, const rectangle *cliprect, const UINT32 *spritedata)
755745{
746   deco32_state *state = machine->driver_data<deco32_state>();
756747   const UINT32 *layout_ram;
757748   const UINT32 *lookup_ram;
758749   int offs;
r10427r10428
803794    */
804795
805796   /* Sprite global disable bit */
806   if (dragngun_sprite_ctrl&0x40000000)
797   if (state->dragngun_sprite_ctrl&0x40000000)
807798      return;
808799
809800   for (offs = 0;offs < 0x800;offs += 8)
r10427r10428
818809         continue;
819810
820811      if (spritedata[offs+0]&0x400)
821         layout_ram = dragngun_sprite_layout_1_ram + ((spritedata[offs+0]&0x1ff)*4); //CHECK!
812         layout_ram = state->dragngun_sprite_layout_1_ram + ((spritedata[offs+0]&0x1ff)*4); //CHECK!
822813      else
823         layout_ram = dragngun_sprite_layout_0_ram + ((spritedata[offs+0]&0x1ff)*4); //1ff in drag gun code??
814         layout_ram = state->dragngun_sprite_layout_0_ram + ((spritedata[offs+0]&0x1ff)*4); //1ff in drag gun code??
824815      h = (layout_ram[1]>>0)&0xf;
825816      w = (layout_ram[1]>>4)&0xf;
826817      if (!h || !w)
r10427r10428
847838
848839//      if (spritedata[offs+0]&0x400)
849840      if (layout_ram[0]&0x2000)
850         lookup_ram = dragngun_sprite_lookup_1_ram + (layout_ram[0]&0x1fff);
841         lookup_ram = state->dragngun_sprite_lookup_1_ram + (layout_ram[0]&0x1fff);
851842      else
852         lookup_ram = dragngun_sprite_lookup_0_ram + (layout_ram[0]&0x1fff);
843         lookup_ram = state->dragngun_sprite_lookup_0_ram + (layout_ram[0]&0x1fff);
853844
854845      zoomx=scalex * 0x10000 / (w*16);
855846      zoomy=scaley * 0x10000 / (h*16);
r10427r10428
873864            /* High bits of the sprite reference into the sprite control bits for banking */
874865            switch (sprite&0x3000) {
875866            default:
876            case 0x0000: sprite=(sprite&0xfff) | ((dragngun_sprite_ctrl&0x000f)<<12); break;
877            case 0x1000: sprite=(sprite&0xfff) | ((dragngun_sprite_ctrl&0x00f0)<< 8); break;
878            case 0x2000: sprite=(sprite&0xfff) | ((dragngun_sprite_ctrl&0x0f00)<< 4); break;
879            case 0x3000: sprite=(sprite&0xfff) | ((dragngun_sprite_ctrl&0xf000)<< 0); break;
867            case 0x0000: sprite=(sprite&0xfff) | ((state->dragngun_sprite_ctrl&0x000f)<<12); break;
868            case 0x1000: sprite=(sprite&0xfff) | ((state->dragngun_sprite_ctrl&0x00f0)<< 8); break;
869            case 0x2000: sprite=(sprite&0xfff) | ((state->dragngun_sprite_ctrl&0x0f00)<< 4); break;
870            case 0x3000: sprite=(sprite&0xfff) | ((state->dragngun_sprite_ctrl&0xf000)<< 0); break;
880871            }
881872
882873            /* Because of the unusual interleaved rom layout, we have to mangle the bank bits
r10427r10428
936927
937928static TILE_GET_INFO( get_pf1_tile_info )
938929{
939   int tile=deco32_pf1_data[tile_index];
940   SET_TILE_INFO(0,(tile&0xfff)|deco32_pf1_bank,(tile>>12)&0xf,0);
930   deco32_state *state = machine->driver_data<deco32_state>();
931   int tile=state->pf1_data[tile_index];
932   SET_TILE_INFO(0,(tile&0xfff)|state->pf1_bank,(tile>>12)&0xf,0);
941933}
942934
943935static TILE_GET_INFO( get_pf1a_tile_info )
944936{
937   deco32_state *state = machine->driver_data<deco32_state>();
945938
946   int tile=deco32_pf1_data[tile_index];
947   SET_TILE_INFO(1,(tile&0xfff)|deco32_pf1_bank,(tile>>12)&0xf,0);
939   int tile=state->pf1_data[tile_index];
940   SET_TILE_INFO(1,(tile&0xfff)|state->pf1_bank,(tile>>12)&0xf,0);
948941}
949942
950943static TILE_GET_INFO( get_pf2_tile_info )
951944{
952   UINT32 tile=deco32_pf2_data[tile_index];
945   deco32_state *state = machine->driver_data<deco32_state>();
946   UINT32 tile=state->pf2_data[tile_index];
953947   UINT8   colour=(tile>>12)&0xf;
954948   UINT8 flags=0;
955949
956950   if (tile&0x8000) {
957      if ((deco32_pf12_control[6]>>8)&0x01) {
951      if ((state->pf12_control[6]>>8)&0x01) {
958952         flags|=TILE_FLIPX;
959953         colour&=0x7;
960954      }
961      if ((deco32_pf12_control[6]>>8)&0x02) {
955      if ((state->pf12_control[6]>>8)&0x02) {
962956         flags|=TILE_FLIPY;
963957         colour&=0x7;
964958      }
965959   }
966960
967   SET_TILE_INFO(1,(tile&0xfff)|deco32_pf2_bank,colour+deco32_pf2_colourbank,flags);
961   SET_TILE_INFO(1,(tile&0xfff)|state->pf2_bank,colour+state->pf2_colourbank,flags);
968962}
969963
970964static TILE_GET_INFO( get_pf3_tile_info )
971965{
972   UINT32 tile=deco32_pf3_data[tile_index];
966   deco32_state *state = machine->driver_data<deco32_state>();
967   UINT32 tile=state->pf3_data[tile_index];
973968   UINT8   colour=(tile>>12)&0xf;
974969   UINT8 flags=0;
975970
976971   if (tile&0x8000) {
977      if ((deco32_pf34_control[6]>>0)&0x01) {
972      if ((state->pf34_control[6]>>0)&0x01) {
978973         flags|=TILE_FLIPX;
979974         colour&=0x7;
980975      }
981      if ((deco32_pf34_control[6]>>0)&0x02) {
976      if ((state->pf34_control[6]>>0)&0x02) {
982977         flags|=TILE_FLIPY;
983978         colour&=0x7;
984979      }
985980   }
986981
987   SET_TILE_INFO(2,(tile&0xfff)|deco32_pf3_bank,colour,flags);
982   SET_TILE_INFO(2,(tile&0xfff)|state->pf3_bank,colour,flags);
988983}
989984
990985static TILE_GET_INFO( get_pf4_tile_info )
991986{
992   UINT32 tile=deco32_pf4_data[tile_index];
987   deco32_state *state = machine->driver_data<deco32_state>();
988   UINT32 tile=state->pf4_data[tile_index];
993989   UINT8   colour=(tile>>12)&0xf;
994990   UINT8 flags=0;
995991
996992   if (tile&0x8000) {
997      if ((deco32_pf34_control[6]>>8)&0x01) {
993      if ((state->pf34_control[6]>>8)&0x01) {
998994         flags|=TILE_FLIPX;
999995         colour&=0x7;
1000996      }
1001      if ((deco32_pf34_control[6]>>8)&0x02) {
997      if ((state->pf34_control[6]>>8)&0x02) {
1002998         flags|=TILE_FLIPY;
1003999         colour&=0x7;
10041000      }
10051001   }
10061002
1007   SET_TILE_INFO(2,(tile&0xfff)|deco32_pf4_bank,colour+deco32_pf4_colourbank,flags);
1003   SET_TILE_INFO(2,(tile&0xfff)|state->pf4_bank,colour+state->pf4_colourbank,flags);
10081004}
10091005
10101006/* Captain America tilemap chip 2 has different banking and colour from normal */
10111007static TILE_GET_INFO( get_ca_pf3_tile_info )
10121008{
1013   int tile=deco32_pf3_data[tile_index];
1014   SET_TILE_INFO(2,(tile&0x3fff)+deco32_pf3_bank,(tile >> 14)&3,0);
1009   deco32_state *state = machine->driver_data<deco32_state>();
1010   int tile=state->pf3_data[tile_index];
1011   SET_TILE_INFO(2,(tile&0x3fff)+state->pf3_bank,(tile >> 14)&3,0);
10151012}
10161013
10171014static TILE_GET_INFO( get_ll_pf3_tile_info )
10181015{
1019   UINT32 tile=deco32_pf3_data[tile_index];
1016   deco32_state *state = machine->driver_data<deco32_state>();
1017   UINT32 tile=state->pf3_data[tile_index];
10201018   UINT8 flags=0;
10211019
10221020   if (tile&0x8000) {
1023      if ((deco32_pf34_control[6]>>0)&0x01)
1021      if ((state->pf34_control[6]>>0)&0x01)
10241022         flags|=TILE_FLIPX;
1025      if ((deco32_pf34_control[6]>>0)&0x02)
1023      if ((state->pf34_control[6]>>0)&0x02)
10261024         flags|=TILE_FLIPY;
10271025   }
10281026
1029   SET_TILE_INFO(2,(tile&0x0fff)|deco32_pf3_bank,(tile >> 12)&3,flags);
1027   SET_TILE_INFO(2,(tile&0x0fff)|state->pf3_bank,(tile >> 12)&3,flags);
10301028}
10311029
10321030static TILE_GET_INFO( get_ll_pf4_tile_info )
10331031{
1034   UINT32 tile=deco32_pf4_data[tile_index];
1032   deco32_state *state = machine->driver_data<deco32_state>();
1033   UINT32 tile=state->pf4_data[tile_index];
10351034   UINT8 flags=0;
10361035
10371036   if (tile&0x8000) {
1038      if ((deco32_pf34_control[6]>>8)&0x01)
1037      if ((state->pf34_control[6]>>8)&0x01)
10391038         flags|=TILE_FLIPX;
1040      if ((deco32_pf34_control[6]>>8)&0x02)
1039      if ((state->pf34_control[6]>>8)&0x02)
10411040         flags|=TILE_FLIPY;
10421041   }
10431042
1044   SET_TILE_INFO(2,(tile&0x0fff)|deco32_pf4_bank,(tile >> 12)&3,flags);
1043   SET_TILE_INFO(2,(tile&0x0fff)|state->pf4_bank,(tile >> 12)&3,flags);
10451044}
10461045
10471046VIDEO_START( captaven )
10481047{
1049   pf1_tilemap = tilemap_create(machine, get_pf1_tile_info,    tilemap_scan_rows, 8, 8,64,32);
1050   pf1a_tilemap =tilemap_create(machine, get_pf1a_tile_info,   deco16_scan_rows,16,16,64,32);
1051   pf2_tilemap = tilemap_create(machine, get_pf2_tile_info,    deco16_scan_rows,16,16,64,32);
1052   pf3_tilemap = tilemap_create(machine, get_ca_pf3_tile_info, tilemap_scan_rows,16,16,32,32);
1048   deco32_state *state = machine->driver_data<deco32_state>();
1049   state->pf1_tilemap = tilemap_create(machine, get_pf1_tile_info,    tilemap_scan_rows, 8, 8,64,32);
1050   state->pf1a_tilemap =tilemap_create(machine, get_pf1a_tile_info,   deco16_scan_rows,16,16,64,32);
1051   state->pf2_tilemap = tilemap_create(machine, get_pf2_tile_info,    deco16_scan_rows,16,16,64,32);
1052   state->pf3_tilemap = tilemap_create(machine, get_ca_pf3_tile_info, tilemap_scan_rows,16,16,32,32);
10531053
1054   tilemap_set_transparent_pen(pf1_tilemap,0);
1055   tilemap_set_transparent_pen(pf1a_tilemap,0);
1056   tilemap_set_transparent_pen(pf2_tilemap,0);
1057   tilemap_set_transparent_pen(pf3_tilemap,0);
1054   tilemap_set_transparent_pen(state->pf1_tilemap,0);
1055   tilemap_set_transparent_pen(state->pf1a_tilemap,0);
1056   tilemap_set_transparent_pen(state->pf2_tilemap,0);
1057   tilemap_set_transparent_pen(state->pf3_tilemap,0);
10581058
1059   deco32_pf2_colourbank=16;
1060   deco32_pf4_colourbank=0;
1061   has_ace_ram=0;
1059   state->pf2_colourbank=16;
1060   state->pf4_colourbank=0;
1061   state->has_ace_ram=0;
10621062}
10631063
10641064VIDEO_START( fghthist )
10651065{
1066   pf1_tilemap = tilemap_create(machine, get_pf1_tile_info, tilemap_scan_rows, 8, 8,64,32);
1067   pf2_tilemap = tilemap_create(machine, get_pf2_tile_info, deco16_scan_rows, 16,16,64,32);
1068   pf3_tilemap = tilemap_create(machine, get_pf3_tile_info, deco16_scan_rows, 16,16,64,32);
1069   pf4_tilemap = tilemap_create(machine, get_pf4_tile_info, deco16_scan_rows, 16,16,64,32);
1070   pf1a_tilemap =0;
1071   dirty_palette = auto_alloc_array(machine, UINT8, 4096);
1066   deco32_state *state = machine->driver_data<deco32_state>();
1067   state->pf1_tilemap = tilemap_create(machine, get_pf1_tile_info, tilemap_scan_rows, 8, 8,64,32);
1068   state->pf2_tilemap = tilemap_create(machine, get_pf2_tile_info, deco16_scan_rows, 16,16,64,32);
1069   state->pf3_tilemap = tilemap_create(machine, get_pf3_tile_info, deco16_scan_rows, 16,16,64,32);
1070   state->pf4_tilemap = tilemap_create(machine, get_pf4_tile_info, deco16_scan_rows, 16,16,64,32);
1071   state->pf1a_tilemap =0;
1072   state->dirty_palette = auto_alloc_array(machine, UINT8, 4096);
10721073
10731074   /* Allow sprite bitmap */
10741075   int width = machine->primary_screen->width();
10751076   int height = machine->primary_screen->height();
1076   sprite_priority_bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16 );
1077   state->sprite_priority_bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16 );
10771078
1078   tilemap_set_transparent_pen(pf1_tilemap,0);
1079   tilemap_set_transparent_pen(pf2_tilemap,0);
1080   tilemap_set_transparent_pen(pf3_tilemap,0);
1079   tilemap_set_transparent_pen(state->pf1_tilemap,0);
1080   tilemap_set_transparent_pen(state->pf2_tilemap,0);
1081   tilemap_set_transparent_pen(state->pf3_tilemap,0);
10811082
1082   deco32_pf2_colourbank=deco32_pf4_colourbank=0;
1083   has_ace_ram=0;
1083   state->pf2_colourbank=state->pf4_colourbank=0;
1084   state->has_ace_ram=0;
10841085}
10851086
10861087VIDEO_START( dragngun )
10871088{
1088   pf1_tilemap = tilemap_create(machine, get_pf1_tile_info,    tilemap_scan_rows, 8, 8,64,32);
1089   pf2_tilemap = tilemap_create(machine, get_pf2_tile_info,    deco16_scan_rows,16,16,64,32);
1090   pf3_tilemap = tilemap_create(machine, get_ll_pf3_tile_info, deco16_scan_rows,16,16,64,32);
1091   pf4_tilemap = tilemap_create(machine, get_ll_pf4_tile_info, deco16_scan_rows,     16,16,64,32);
1092   pf1a_tilemap =tilemap_create(machine, get_pf1a_tile_info,   deco16_scan_rows,16,16,64,32);
1093   dirty_palette = auto_alloc_array(machine, UINT8, 4096);
1094   deco32_raster_display_list = auto_alloc_array(machine, UINT16, 10 * 256 / 2);
1089   deco32_state *state = machine->driver_data<deco32_state>();
1090   state->pf1_tilemap = tilemap_create(machine, get_pf1_tile_info,    tilemap_scan_rows, 8, 8,64,32);
1091   state->pf2_tilemap = tilemap_create(machine, get_pf2_tile_info,    deco16_scan_rows,16,16,64,32);
1092   state->pf3_tilemap = tilemap_create(machine, get_ll_pf3_tile_info, deco16_scan_rows,16,16,64,32);
1093   state->pf4_tilemap = tilemap_create(machine, get_ll_pf4_tile_info, deco16_scan_rows,     16,16,64,32);
1094   state->pf1a_tilemap =tilemap_create(machine, get_pf1a_tile_info,   deco16_scan_rows,16,16,64,32);
1095   state->dirty_palette = auto_alloc_array(machine, UINT8, 4096);
1096   state->raster_display_list = auto_alloc_array(machine, UINT16, 10 * 256 / 2);
10951097
1096   tilemap_set_transparent_pen(pf1_tilemap,0);
1097   tilemap_set_transparent_pen(pf2_tilemap,0);
1098   tilemap_set_transparent_pen(pf3_tilemap,0);
1099   tilemap_set_transparent_pen(pf1a_tilemap,0);
1100   memset(dirty_palette,0,4096);
1098   tilemap_set_transparent_pen(state->pf1_tilemap,0);
1099   tilemap_set_transparent_pen(state->pf2_tilemap,0);
1100   tilemap_set_transparent_pen(state->pf3_tilemap,0);
1101   tilemap_set_transparent_pen(state->pf1a_tilemap,0);
1102   memset(state->dirty_palette,0,4096);
11011103
1102   deco32_pf2_colourbank=deco32_pf4_colourbank=0;
1104   state->pf2_colourbank=state->pf4_colourbank=0;
11031105
1104   state_save_register_global(machine, dragngun_sprite_ctrl);
1105   has_ace_ram=0;
1106   state_save_register_global(machine, state->dragngun_sprite_ctrl);
1107   state->has_ace_ram=0;
11061108}
11071109
11081110VIDEO_START( lockload )
11091111{
1110   pf1_tilemap = tilemap_create(machine, get_pf1_tile_info,    tilemap_scan_rows, 8, 8,64,32);
1111   pf2_tilemap = tilemap_create(machine, get_pf2_tile_info,    deco16_scan_rows,16,16,64,32);
1112   pf3_tilemap = tilemap_create(machine, get_ll_pf3_tile_info, deco16_scan_rows,16,16,32,32);
1113   pf4_tilemap = tilemap_create(machine, get_ll_pf4_tile_info, deco16_scan_rows,     16,16,32,32);
1114   pf1a_tilemap =tilemap_create(machine, get_pf1a_tile_info,   deco16_scan_rows,16,16,64,32);
1115   dirty_palette = auto_alloc_array(machine, UINT8, 4096);
1116   deco32_raster_display_list = auto_alloc_array(machine, UINT16, 10 * 256 / 2);
1117   memset(deco32_raster_display_list, 0, 10 * 256);
1112   deco32_state *state = machine->driver_data<deco32_state>();
1113   state->pf1_tilemap = tilemap_create(machine, get_pf1_tile_info,    tilemap_scan_rows, 8, 8,64,32);
1114   state->pf2_tilemap = tilemap_create(machine, get_pf2_tile_info,    deco16_scan_rows,16,16,64,32);
1115   state->pf3_tilemap = tilemap_create(machine, get_ll_pf3_tile_info, deco16_scan_rows,16,16,32,32);
1116   state->pf4_tilemap = tilemap_create(machine, get_ll_pf4_tile_info, deco16_scan_rows,     16,16,32,32);
1117   state->pf1a_tilemap =tilemap_create(machine, get_pf1a_tile_info,   deco16_scan_rows,16,16,64,32);
1118   state->dirty_palette = auto_alloc_array(machine, UINT8, 4096);
1119   state->raster_display_list = auto_alloc_array(machine, UINT16, 10 * 256 / 2);
1120   memset(state->raster_display_list, 0, 10 * 256);
11181121
1119   tilemap_set_transparent_pen(pf1_tilemap,0);
1120   tilemap_set_transparent_pen(pf2_tilemap,0);
1121   tilemap_set_transparent_pen(pf3_tilemap,0);
1122   tilemap_set_transparent_pen(pf1a_tilemap,0);
1123   memset(dirty_palette,0,4096);
1122   tilemap_set_transparent_pen(state->pf1_tilemap,0);
1123   tilemap_set_transparent_pen(state->pf2_tilemap,0);
1124   tilemap_set_transparent_pen(state->pf3_tilemap,0);
1125   tilemap_set_transparent_pen(state->pf1a_tilemap,0);
1126   memset(state->dirty_palette,0,4096);
11241127
1125   deco32_pf2_colourbank=deco32_pf4_colourbank=0;
1128   state->pf2_colourbank=state->pf4_colourbank=0;
11261129
1127   state_save_register_global(machine, dragngun_sprite_ctrl);
1128   has_ace_ram=0;
1130   state_save_register_global(machine, state->dragngun_sprite_ctrl);
1131   state->has_ace_ram=0;
11291132}
11301133
11311134VIDEO_START( nslasher )
11321135{
1136   deco32_state *state = machine->driver_data<deco32_state>();
11331137   int width, height;
11341138
1135   pf1_tilemap = tilemap_create(machine, get_pf1_tile_info, tilemap_scan_rows, 8, 8,64,32);
1136   pf2_tilemap = tilemap_create(machine, get_pf2_tile_info, deco16_scan_rows,16,16,64,32);
1137   pf3_tilemap = tilemap_create(machine, get_pf3_tile_info, deco16_scan_rows,16,16,64,32);
1138   pf4_tilemap = tilemap_create(machine, get_pf4_tile_info, deco16_scan_rows,     16,16,64,32);
1139   pf1a_tilemap =0;
1140   dirty_palette = auto_alloc_array(machine, UINT8, 4096);
1139   state->pf1_tilemap = tilemap_create(machine, get_pf1_tile_info, tilemap_scan_rows, 8, 8,64,32);
1140   state->pf2_tilemap = tilemap_create(machine, get_pf2_tile_info, deco16_scan_rows,16,16,64,32);
1141   state->pf3_tilemap = tilemap_create(machine, get_pf3_tile_info, deco16_scan_rows,16,16,64,32);
1142   state->pf4_tilemap = tilemap_create(machine, get_pf4_tile_info, deco16_scan_rows,     16,16,64,32);
1143   state->pf1a_tilemap =0;
1144   state->dirty_palette = auto_alloc_array(machine, UINT8, 4096);
11411145
11421146   width = machine->primary_screen->width();
11431147   height = machine->primary_screen->height();
1144   sprite0_mix_bitmap=auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16 );
1145   sprite1_mix_bitmap=auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16 );
1146   tilemap_alpha_bitmap=auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16 );
1148   state->sprite0_mix_bitmap=auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16 );
1149   state->sprite1_mix_bitmap=auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16 );
1150   state->tilemap_alpha_bitmap=auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16 );
11471151
1148   tilemap_set_transparent_pen(pf1_tilemap,0);
1149   tilemap_set_transparent_pen(pf2_tilemap,0);
1150   tilemap_set_transparent_pen(pf3_tilemap,0);
1151   memset(dirty_palette,0,4096);
1152   tilemap_set_transparent_pen(state->pf1_tilemap,0);
1153   tilemap_set_transparent_pen(state->pf2_tilemap,0);
1154   tilemap_set_transparent_pen(state->pf3_tilemap,0);
1155   memset(state->dirty_palette,0,4096);
11521156
1153   deco32_pf2_colourbank=16;
1154   deco32_pf4_colourbank=16;
1155   state_save_register_global(machine, deco32_pri);
1156   has_ace_ram=1;
1157   state->pf2_colourbank=16;
1158   state->pf4_colourbank=16;
1159   state_save_register_global(machine, state->pri);
1160   state->has_ace_ram=1;
11571161}
11581162
11591163/******************************************************************************/
r10427r10428
11651169
11661170VIDEO_EOF( dragngun )
11671171{
1168   deco32_raster_display_position=0;
1172   deco32_state *state = machine->driver_data<deco32_state>();
1173   state->raster_display_position=0;
11691174}
11701175
11711176#if 0
11721177static void print_debug_info(bitmap_t *bitmap)
11731178{
1179   deco32_state *state = machine->driver_data<deco32_state>();
11741180   int j;
11751181   char buf[64*5];
11761182   char *bufptr = buf;
11771183
1178   bufptr += sprintf(bufptr,"%04X %04X %04X %04X\n",deco32_pf12_control[0]&0xffff,deco32_pf12_control[1]&0xffff,deco32_pf12_control[2]&0xffff,deco32_pf12_control[3]&0xffff);
1179   bufptr += sprintf(bufptr,"%04X %04X %04X %04X\n",deco32_pf12_control[4]&0xffff,deco32_pf12_control[5]&0xffff,deco32_pf12_control[6]&0xffff,deco32_pf12_control[7]&0xffff);
1184   bufptr += sprintf(bufptr,"%04X %04X %04X %04X\n",state->pf12_control[0]&0xffff,state->pf12_control[1]&0xffff,state->pf12_control[2]&0xffff,state->pf12_control[3]&0xffff);
1185   bufptr += sprintf(bufptr,"%04X %04X %04X %04X\n",state->pf12_control[4]&0xffff,state->pf12_control[5]&0xffff,state->pf12_control[6]&0xffff,state->pf12_control[7]&0xffff);
11801186
1181   bufptr += sprintf(bufptr,"%04X %04X %04X %04X\n",deco32_pf34_control[0]&0xffff,deco32_pf34_control[1]&0xffff,deco32_pf34_control[2]&0xffff,deco32_pf34_control[3]&0xffff);
1182   bufptr += sprintf(bufptr,"%04X %04X %04X %04X\n",deco32_pf34_control[4]&0xffff,deco32_pf34_control[5]&0xffff,deco32_pf34_control[6]&0xffff,deco32_pf34_control[7]&0xffff);
1183   bufptr += sprintf(bufptr,"%04X\n",deco32_pri);
1187   bufptr += sprintf(bufptr,"%04X %04X %04X %04X\n",state->pf34_control[0]&0xffff,state->pf34_control[1]&0xffff,state->pf34_control[2]&0xffff,state->pf34_control[3]&0xffff);
1188   bufptr += sprintf(bufptr,"%04X %04X %04X %04X\n",state->pf34_control[4]&0xffff,state->pf34_control[5]&0xffff,state->pf34_control[6]&0xffff,state->pf34_control[7]&0xffff);
1189   bufptr += sprintf(bufptr,"%04X\n",state->pri);
11841190
11851191   ui_draw_text(buf,60,40);
11861192}
r10427r10428
12321238
12331239static void combined_tilemap_draw(running_machine* machine, bitmap_t *bitmap, const rectangle *cliprect)
12341240{
1235   const bitmap_t *bitmap0 = tilemap_get_pixmap(pf3_tilemap);
1236   const bitmap_t *bitmap1 = tilemap_get_pixmap(pf4_tilemap);
1241   deco32_state *state = machine->driver_data<deco32_state>();
1242   const bitmap_t *bitmap0 = tilemap_get_pixmap(state->pf3_tilemap);
1243   const bitmap_t *bitmap1 = tilemap_get_pixmap(state->pf4_tilemap);
12371244   int x,y,p;
12381245
12391246   const UINT16 width_mask=0x3ff;
12401247   const UINT16 height_mask=0x1ff;
1241   const UINT16 y_src=deco32_pf34_control[2];
1242//  const UINT32 *rows=deco32_pf3_rowscroll;
1248   const UINT16 y_src=state->pf34_control[2];
1249//  const UINT32 *rows=state->pf3_rowscroll;
12431250
12441251   const UINT16 *bitmap0_y;
12451252   const UINT16 *bitmap1_y;
r10427r10428
12551262      bitmap2_y=BITMAP_ADDR32(bitmap, y, 0);
12561263
12571264      /* Todo:  Should add row enable, and col scroll, but never used as far as I can see */
1258      x_src=(deco32_pf34_control[1] + deco32_pf3_rowscroll[py])&width_mask;
1265      x_src=(state->pf34_control[1] + state->pf3_rowscroll[py])&width_mask;
12591266
12601267      for (x=0; x<320; x++) {
12611268
r10427r10428
12751282
12761283VIDEO_UPDATE( captaven )
12771284{
1285   deco32_state *state = screen->machine->driver_data<deco32_state>();
12781286   int pf1_enable,pf2_enable,pf3_enable;
1279   static int last_pf3_bank;
12801287
1281   flip_screen_set(screen->machine, deco32_pf12_control[0]&0x80);
1288   flip_screen_set(screen->machine, state->pf12_control[0]&0x80);
12821289   tilemap_set_flip_all(screen->machine,flip_screen_get(screen->machine) ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
12831290
1284   deco32_setup_scroll(pf1_tilemap, 256,(deco32_pf12_control[5]>>0)&0xff,(deco32_pf12_control[6]>>0)&0xff,deco32_pf12_control[2],deco32_pf12_control[1],deco32_pf1_rowscroll,deco32_pf1_rowscroll+0x200);
1285   deco32_setup_scroll(pf1a_tilemap,512,(deco32_pf12_control[5]>>0)&0xff,(deco32_pf12_control[6]>>0)&0xff,deco32_pf12_control[2],deco32_pf12_control[1],deco32_pf1_rowscroll,deco32_pf1_rowscroll+0x200);
1286   deco32_setup_scroll(pf2_tilemap, 512,(deco32_pf12_control[5]>>8)&0xff,(deco32_pf12_control[6]>>8)&0xff,deco32_pf12_control[4],deco32_pf12_control[3],deco32_pf2_rowscroll,deco32_pf2_rowscroll+0x200);
1287   deco32_setup_scroll(pf3_tilemap, 512,(deco32_pf34_control[5]>>0)&0xff,(deco32_pf34_control[6]>>0)&0xff,deco32_pf34_control[4],deco32_pf34_control[3],deco32_pf3_rowscroll,deco32_pf3_rowscroll+0x200);
1291   deco32_setup_scroll(state->pf1_tilemap, 256,(state->pf12_control[5]>>0)&0xff,(state->pf12_control[6]>>0)&0xff,state->pf12_control[2],state->pf12_control[1],state->pf1_rowscroll,state->pf1_rowscroll+0x200);
1292   deco32_setup_scroll(state->pf1a_tilemap,512,(state->pf12_control[5]>>0)&0xff,(state->pf12_control[6]>>0)&0xff,state->pf12_control[2],state->pf12_control[1],state->pf1_rowscroll,state->pf1_rowscroll+0x200);
1293   deco32_setup_scroll(state->pf2_tilemap, 512,(state->pf12_control[5]>>8)&0xff,(state->pf12_control[6]>>8)&0xff,state->pf12_control[4],state->pf12_control[3],state->pf2_rowscroll,state->pf2_rowscroll+0x200);
1294   deco32_setup_scroll(state->pf3_tilemap, 512,(state->pf34_control[5]>>0)&0xff,(state->pf34_control[6]>>0)&0xff,state->pf34_control[4],state->pf34_control[3],state->pf3_rowscroll,state->pf3_rowscroll+0x200);
12881295
12891296   /* PF1 & PF2 only have enough roms for 1 bank */
1290   deco32_pf1_bank=0;//(deco32_pf12_control[7]>> 4)&0xf;
1291   deco32_pf2_bank=0;//(deco32_pf12_control[7]>>12)&0xf;
1292   deco32_pf3_bank=(deco32_pf34_control[7]>> 4)&0xf;
1297   state->pf1_bank=0;//(state->pf12_control[7]>> 4)&0xf;
1298   state->pf2_bank=0;//(state->pf12_control[7]>>12)&0xf;
1299   state->pf3_bank=(state->pf34_control[7]>> 4)&0xf;
12931300
1294   if (deco32_pf34_control[7]&0x0020) deco32_pf3_bank=0x4000; else deco32_pf3_bank=0;
1295   if (deco32_pf3_bank!=last_pf3_bank) tilemap_mark_all_tiles_dirty(pf3_tilemap);
1296   last_pf3_bank=deco32_pf3_bank;
1301   if (state->pf34_control[7]&0x0020) state->pf3_bank=0x4000; else state->pf3_bank=0;
1302   if (state->pf3_bank!=state->last_pf3_bank) tilemap_mark_all_tiles_dirty(state->pf3_tilemap);
1303   state->last_pf3_bank=state->pf3_bank;
12971304
1298   pf1_enable=deco32_pf12_control[5]&0x0080;
1299   pf2_enable=deco32_pf12_control[5]&0x8000;
1300   pf3_enable=deco32_pf34_control[5]&0x0080;
1305   pf1_enable=state->pf12_control[5]&0x0080;
1306   pf2_enable=state->pf12_control[5]&0x8000;
1307   pf3_enable=state->pf34_control[5]&0x0080;
13011308
1302   tilemap_set_enable(pf1_tilemap,pf1_enable);
1303   tilemap_set_enable(pf1a_tilemap,pf1_enable);
1304   tilemap_set_enable(pf2_tilemap,pf2_enable);
1305   tilemap_set_enable(pf3_tilemap,pf3_enable);
1309   tilemap_set_enable(state->pf1_tilemap,pf1_enable);
1310   tilemap_set_enable(state->pf1a_tilemap,pf1_enable);
1311   tilemap_set_enable(state->pf2_tilemap,pf2_enable);
1312   tilemap_set_enable(state->pf3_tilemap,pf3_enable);
13061313
13071314   bitmap_fill(screen->machine->priority_bitmap,cliprect,0);
1308   if ((deco32_pri&1)==0) {
1315   if ((state->pri&1)==0) {
13091316      if (pf3_enable)
1310         tilemap_draw(bitmap,cliprect,pf3_tilemap,TILEMAP_DRAW_OPAQUE,1);
1317         tilemap_draw(bitmap,cliprect,state->pf3_tilemap,TILEMAP_DRAW_OPAQUE,1);
13111318      else
13121319         bitmap_fill(bitmap,cliprect,get_black_pen(screen->machine));
13131320
1314      tilemap_draw(bitmap,cliprect,pf2_tilemap,0,2);
1321      tilemap_draw(bitmap,cliprect,state->pf2_tilemap,0,2);
13151322   } else {
13161323      if (pf2_enable) {
1317         tilemap_draw(bitmap,cliprect,pf2_tilemap,0,1);
1324         tilemap_draw(bitmap,cliprect,state->pf2_tilemap,0,1);
13181325      }
13191326      else
13201327         bitmap_fill(bitmap,cliprect,get_black_pen(screen->machine));
13211328
1322      tilemap_draw(bitmap,cliprect,pf3_tilemap,0,2);
1329      tilemap_draw(bitmap,cliprect,state->pf3_tilemap,0,2);
13231330   }
13241331
13251332   /* PF1 can be in 8x8 mode or 16x16 mode */
1326   if (deco32_pf12_control[6]&0x80)
1327      tilemap_draw(bitmap,cliprect,pf1_tilemap,0,4);
1333   if (state->pf12_control[6]&0x80)
1334      tilemap_draw(bitmap,cliprect,state->pf1_tilemap,0,4);
13281335   else
1329      tilemap_draw(bitmap,cliprect,pf1a_tilemap,0,4);
1336      tilemap_draw(bitmap,cliprect,state->pf1a_tilemap,0,4);
13301337
13311338   captaven_draw_sprites(screen->machine,bitmap,cliprect,screen->machine->generic.buffered_spriteram.u32,3);
13321339
r10427r10428
13351342
13361343VIDEO_UPDATE( dragngun )
13371344{
1345   deco32_state *state = screen->machine->driver_data<deco32_state>();
13381346   /* Tilemap graphics banking */
1339   if ((((deco32_pf12_control[7]>> 4)&0x7)<<12)!=deco32_pf1_bank || deco32_pf1_flip!=((deco32_pf12_control[6]>>0)&0x3)) {
1340      tilemap_mark_all_tiles_dirty(pf1_tilemap);
1341      tilemap_mark_all_tiles_dirty(pf1a_tilemap);
1347   if ((((state->pf12_control[7]>> 4)&0x7)<<12)!=state->pf1_bank || state->pf1_flip!=((state->pf12_control[6]>>0)&0x3)) {
1348      tilemap_mark_all_tiles_dirty(state->pf1_tilemap);
1349      tilemap_mark_all_tiles_dirty(state->pf1a_tilemap);
13421350   }
1343   if ((((deco32_pf12_control[7]>>12)&0x7)<<12)!=deco32_pf2_bank || deco32_pf2_flip!=((deco32_pf12_control[6]>>8)&0x3))
1344      tilemap_mark_all_tiles_dirty(pf2_tilemap);
1345   if ((((deco32_pf34_control[7]>> 5)&0x7)<<12)!=deco32_pf3_bank || deco32_pf3_flip!=((deco32_pf34_control[6]>>0)&0x3))
1346      tilemap_mark_all_tiles_dirty(pf3_tilemap);
1347   if ((((deco32_pf34_control[7]>>13)&0x7)<<12)!=deco32_pf4_bank || deco32_pf4_flip!=((deco32_pf34_control[6]>>8)&0x3))
1348      tilemap_mark_all_tiles_dirty(pf4_tilemap);
1349   deco32_pf1_bank=((deco32_pf12_control[7]>> 5)&0x7)<<12;
1350   deco32_pf2_bank=((deco32_pf12_control[7]>>12)&0x7)<<12;
1351   deco32_pf3_bank=((deco32_pf34_control[7]>> 5)&0x7)<<12;
1352   deco32_pf4_bank=((deco32_pf34_control[7]>>13)&0x7)<<12;
1351   if ((((state->pf12_control[7]>>12)&0x7)<<12)!=state->pf2_bank || state->pf2_flip!=((state->pf12_control[6]>>8)&0x3))
1352      tilemap_mark_all_tiles_dirty(state->pf2_tilemap);
1353   if ((((state->pf34_control[7]>> 5)&0x7)<<12)!=state->pf3_bank || state->pf3_flip!=((state->pf34_control[6]>>0)&0x3))
1354      tilemap_mark_all_tiles_dirty(state->pf3_tilemap);
1355   if ((((state->pf34_control[7]>>13)&0x7)<<12)!=state->pf4_bank || state->pf4_flip!=((state->pf34_control[6]>>8)&0x3))
1356      tilemap_mark_all_tiles_dirty(state->pf4_tilemap);
1357   state->pf1_bank=((state->pf12_control[7]>> 5)&0x7)<<12;
1358   state->pf2_bank=((state->pf12_control[7]>>12)&0x7)<<12;
1359   state->pf3_bank=((state->pf34_control[7]>> 5)&0x7)<<12;
1360   state->pf4_bank=((state->pf34_control[7]>>13)&0x7)<<12;
13531361
1354   deco32_pf1_flip=(deco32_pf12_control[6]>>0)&0x3;
1355   deco32_pf2_flip=(deco32_pf12_control[6]>>8)&0x3;
1356   deco32_pf3_flip=(deco32_pf34_control[6]>>0)&0x3;
1357   deco32_pf4_flip=(deco32_pf34_control[6]>>8)&0x3;
1362   state->pf1_flip=(state->pf12_control[6]>>0)&0x3;
1363   state->pf2_flip=(state->pf12_control[6]>>8)&0x3;
1364   state->pf3_flip=(state->pf34_control[6]>>0)&0x3;
1365   state->pf4_flip=(state->pf34_control[6]>>8)&0x3;
13581366
1359   deco32_setup_scroll(pf1_tilemap, 256,(deco32_pf12_control[5]>>0)&0xff,(deco32_pf12_control[6]>>0)&0xff,deco32_pf12_control[2],deco32_pf12_control[1],deco32_pf1_rowscroll,deco32_pf1_rowscroll+0x200);
1360   deco32_setup_scroll(pf1a_tilemap,512,(deco32_pf12_control[5]>>0)&0xff,(deco32_pf12_control[6]>>0)&0xff,deco32_pf12_control[2],deco32_pf12_control[1],deco32_pf1_rowscroll,deco32_pf1_rowscroll+0x200);
1361   deco32_setup_scroll(pf2_tilemap, 512,(deco32_pf12_control[5]>>8)&0xff,(deco32_pf12_control[6]>>8)&0xff,deco32_pf12_control[4],deco32_pf12_control[3],deco32_pf2_rowscroll,deco32_pf2_rowscroll+0x200);
1362   deco32_setup_scroll(pf3_tilemap, 512,(deco32_pf34_control[5]>>0)&0xff,(deco32_pf34_control[6]>>0)&0xff,deco32_pf34_control[2],deco32_pf34_control[1],deco32_pf3_rowscroll,deco32_pf3_rowscroll+0x200);
1363   deco32_setup_scroll(pf4_tilemap, 512,(deco32_pf34_control[5]>>8)&0xff,(deco32_pf34_control[6]>>8)&0xff,deco32_pf34_control[4],deco32_pf34_control[3],deco32_pf4_rowscroll,deco32_pf4_rowscroll+0x200);
1367   deco32_setup_scroll(state->pf1_tilemap, 256,(state->pf12_control[5]>>0)&0xff,(state->pf12_control[6]>>0)&0xff,state->pf12_control[2],state->pf12_control[1],state->pf1_rowscroll,state->pf1_rowscroll+0x200);
1368   deco32_setup_scroll(state->pf1a_tilemap,512,(state->pf12_control[5]>>0)&0xff,(state->pf12_control[6]>>0)&0xff,state->pf12_control[2],state->pf12_control[1],state->pf1_rowscroll,state->pf1_rowscroll+0x200);
1369   deco32_setup_scroll(state->pf2_tilemap, 512,(state->pf12_control[5]>>8)&0xff,(state->pf12_control[6]>>8)&0xff,state->pf12_control[4],state->pf12_control[3],state->pf2_rowscroll,state->pf2_rowscroll+0x200);
1370   deco32_setup_scroll(state->pf3_tilemap, 512,(state->pf34_control[5]>>0)&0xff,(state->pf34_control[6]>>0)&0xff,state->pf34_control[2],state->pf34_control[1],state->pf3_rowscroll,state->pf3_rowscroll+0x200);
1371   deco32_setup_scroll(state->pf4_tilemap, 512,(state->pf34_control[5]>>8)&0xff,(state->pf34_control[6]>>8)&0xff,state->pf34_control[4],state->pf34_control[3],state->pf4_rowscroll,state->pf4_rowscroll+0x200);
13641372
1365   tilemap_set_enable(pf1_tilemap, deco32_pf12_control[5]&0x0080);
1366   tilemap_set_enable(pf1a_tilemap,deco32_pf12_control[5]&0x0080);
1367   tilemap_set_enable(pf2_tilemap, deco32_pf12_control[5]&0x8000);
1368   tilemap_set_enable(pf3_tilemap, deco32_pf34_control[5]&0x0080);
1369   tilemap_set_enable(pf4_tilemap, deco32_pf34_control[5]&0x8000);
1373   tilemap_set_enable(state->pf1_tilemap, state->pf12_control[5]&0x0080);
1374   tilemap_set_enable(state->pf1a_tilemap,state->pf12_control[5]&0x0080);
1375   tilemap_set_enable(state->pf2_tilemap, state->pf12_control[5]&0x8000);
1376   tilemap_set_enable(state->pf3_tilemap, state->pf34_control[5]&0x0080);
1377   tilemap_set_enable(state->pf4_tilemap, state->pf34_control[5]&0x8000);
13701378
1371   if ((deco32_pf34_control[5]&0x8000)==0)
1379   if ((state->pf34_control[5]&0x8000)==0)
13721380      bitmap_fill(bitmap,cliprect,get_black_pen(screen->machine));
13731381
1374   tilemap_draw(bitmap,cliprect,pf4_tilemap,0,0);
1375   tilemap_draw(bitmap,cliprect,pf3_tilemap,0,0);
1382   tilemap_draw(bitmap,cliprect,state->pf4_tilemap,0,0);
1383   tilemap_draw(bitmap,cliprect,state->pf3_tilemap,0,0);
13761384
13771385   /* Raster update */
1378   if (deco32_raster_display_position) {
1386   if (state->raster_display_position) {
13791387      int ptr=0,start,end=0;
13801388      rectangle clip;
1381      int overflow=deco32_raster_display_position;
1389      int overflow=state->raster_display_position;
13821390
13831391      clip.min_x = cliprect->min_x;
13841392      clip.max_x = cliprect->max_x;
13851393
13861394      /* Finish list up to end of visible display */
1387      deco32_raster_display_list[overflow++]=255;
1388      deco32_raster_display_list[overflow++]=deco32_pf12_control[1];
1389      deco32_raster_display_list[overflow++]=deco32_pf12_control[2];
1390      deco32_raster_display_list[overflow++]=deco32_pf12_control[3];
1391      deco32_raster_display_list[overflow++]=deco32_pf12_control[4];
1395      state->raster_display_list[overflow++]=255;
1396      state->raster_display_list[overflow++]=state->pf12_control[1];
1397      state->raster_display_list[overflow++]=state->pf12_control[2];
1398      state->raster_display_list[overflow++]=state->pf12_control[3];
1399      state->raster_display_list[overflow++]=state->pf12_control[4];
13921400
13931401      while (ptr<overflow) {
13941402         start=end;
1395         end=deco32_raster_display_list[ptr++];
1396         deco32_pf12_control[1]=deco32_raster_display_list[ptr++];
1397         deco32_pf12_control[2]=deco32_raster_display_list[ptr++];
1398         deco32_pf12_control[3]=deco32_raster_display_list[ptr++];
1399         deco32_pf12_control[4]=deco32_raster_display_list[ptr++];
1403         end=state->raster_display_list[ptr++];
1404         state->pf12_control[1]=state->raster_display_list[ptr++];
1405         state->pf12_control[2]=state->raster_display_list[ptr++];
1406         state->pf12_control[3]=state->raster_display_list[ptr++];
1407         state->pf12_control[4]=state->raster_display_list[ptr++];
14001408
14011409         clip.min_y = start;
14021410         clip.max_y = end;
14031411
1404         deco32_setup_scroll(pf2_tilemap, 512,(deco32_pf12_control[5]>>8)&0xff,(deco32_pf12_control[6]>>8)&0xff,deco32_pf12_control[4],deco32_pf12_control[3],deco32_pf2_rowscroll,deco32_pf2_rowscroll+0x200);
1405         tilemap_draw(bitmap,&clip,pf2_tilemap,0,0);
1412         deco32_setup_scroll(state->pf2_tilemap, 512,(state->pf12_control[5]>>8)&0xff,(state->pf12_control[6]>>8)&0xff,state->pf12_control[4],state->pf12_control[3],state->pf2_rowscroll,state->pf2_rowscroll+0x200);
1413         tilemap_draw(bitmap,&clip,state->pf2_tilemap,0,0);
14061414      }
14071415   } else {
1408      tilemap_draw(bitmap,cliprect,pf2_tilemap,0,0);
1416      tilemap_draw(bitmap,cliprect,state->pf2_tilemap,0,0);
14091417   }
14101418
14111419   dragngun_draw_sprites(screen->machine,bitmap,cliprect,screen->machine->generic.buffered_spriteram.u32);
14121420
14131421   /* PF1 can be in 8x8 mode or 16x16 mode */
1414   if (deco32_pf12_control[6]&0x80)
1415      tilemap_draw(bitmap,cliprect,pf1_tilemap,0,0);
1422   if (state->pf12_control[6]&0x80)
1423      tilemap_draw(bitmap,cliprect,state->pf1_tilemap,0,0);
14161424   else
1417      tilemap_draw(bitmap,cliprect,pf1a_tilemap,0,0);
1425      tilemap_draw(bitmap,cliprect,state->pf1a_tilemap,0,0);
14181426   return 0;
14191427}
14201428
14211429VIDEO_UPDATE( fghthist )
14221430{
1431   deco32_state *state = screen->machine->driver_data<deco32_state>();
14231432   /* Dirty tilemaps if any globals change */
1424   if (deco32_pf1_flip!=((deco32_pf12_control[6]>>0)&0x3))
1425      tilemap_mark_all_tiles_dirty(pf1_tilemap);
1426   if (deco32_pf2_flip!=((deco32_pf12_control[6]>>8)&0x3))
1427      tilemap_mark_all_tiles_dirty(pf2_tilemap);
1433   if (state->pf1_flip!=((state->pf12_control[6]>>0)&0x3))
1434      tilemap_mark_all_tiles_dirty(state->pf1_tilemap);
1435   if (state->pf2_flip!=((state->pf12_control[6]>>8)&0x3))
1436      tilemap_mark_all_tiles_dirty(state->pf2_tilemap);
14281437
1429   if ((((deco32_pf12_control[7]>>13)&0x7)<<12)!=deco32_pf2_bank || deco32_pf2_flip!=((deco32_pf12_control[6]>>8)&0x3))
1430      tilemap_mark_all_tiles_dirty(pf2_tilemap);
1431   if ((((deco32_pf34_control[7]>> 5)&0x7)<<12)!=deco32_pf3_bank || deco32_pf3_flip!=((deco32_pf34_control[6]>>0)&0x3))
1432      tilemap_mark_all_tiles_dirty(pf3_tilemap);
1433   if ((((deco32_pf34_control[7]>>13)&0x7)<<12)!=deco32_pf4_bank || deco32_pf4_flip!=((deco32_pf34_control[6]>>8)&0x3))
1434      tilemap_mark_all_tiles_dirty(pf4_tilemap);
1438   if ((((state->pf12_control[7]>>13)&0x7)<<12)!=state->pf2_bank || state->pf2_flip!=((state->pf12_control[6]>>8)&0x3))
1439      tilemap_mark_all_tiles_dirty(state->pf2_tilemap);
1440   if ((((state->pf34_control[7]>> 5)&0x7)<<12)!=state->pf3_bank || state->pf3_flip!=((state->pf34_control[6]>>0)&0x3))
1441      tilemap_mark_all_tiles_dirty(state->pf3_tilemap);
1442   if ((((state->pf34_control[7]>>13)&0x7)<<12)!=state->pf4_bank || state->pf4_flip!=((state->pf34_control[6]>>8)&0x3))
1443      tilemap_mark_all_tiles_dirty(state->pf4_tilemap);
14351444
1436   deco32_pf2_bank=((deco32_pf12_control[7]>>12)&0x3)<<12;
1437   deco32_pf3_bank=((deco32_pf34_control[7]>> 5)&0x3)<<12;  //WRONG WRONG WRONG  check masks
1438   deco32_pf4_bank=((deco32_pf34_control[7]>>12)&0x3)<<12;
1439   deco32_pf1_flip=(deco32_pf12_control[6]>>0)&0x3;
1440   deco32_pf2_flip=(deco32_pf12_control[6]>>8)&0x3;
1441   deco32_pf3_flip=(deco32_pf34_control[6]>>0)&0x3;
1442   deco32_pf4_flip=(deco32_pf34_control[6]>>8)&0x3;
1445   state->pf2_bank=((state->pf12_control[7]>>12)&0x3)<<12;
1446   state->pf3_bank=((state->pf34_control[7]>> 5)&0x3)<<12;  //WRONG WRONG WRONG  check masks
1447   state->pf4_bank=((state->pf34_control[7]>>12)&0x3)<<12;
1448   state->pf1_flip=(state->pf12_control[6]>>0)&0x3;
1449   state->pf2_flip=(state->pf12_control[6]>>8)&0x3;
1450   state->pf3_flip=(state->pf34_control[6]>>0)&0x3;
1451   state->pf4_flip=(state->pf34_control[6]>>8)&0x3;
14431452
14441453   /* Enable registers */
1445   tilemap_set_enable(pf1_tilemap, deco32_pf12_control[5]&0x0080);
1446   tilemap_set_enable(pf2_tilemap, deco32_pf12_control[5]&0x8000);
1447   tilemap_set_enable(pf3_tilemap, deco32_pf34_control[5]&0x0080);
1448   tilemap_set_enable(pf4_tilemap, deco32_pf34_control[5]&0x8000);
1454   tilemap_set_enable(state->pf1_tilemap, state->pf12_control[5]&0x0080);
1455   tilemap_set_enable(state->pf2_tilemap, state->pf12_control[5]&0x8000);
1456   tilemap_set_enable(state->pf3_tilemap, state->pf34_control[5]&0x0080);
1457   tilemap_set_enable(state->pf4_tilemap, state->pf34_control[5]&0x8000);
14491458
14501459   /* Setup scroll registers */
1451   deco32_setup_scroll(pf1_tilemap, 256,(deco32_pf12_control[5]>>0)&0xff,(deco32_pf12_control[6]>>0)&0xff,deco32_pf12_control[2],deco32_pf12_control[1],deco32_pf1_rowscroll,deco32_pf1_rowscroll+0x200);
1452   deco32_setup_scroll(pf2_tilemap, 512,(deco32_pf12_control[5]>>8)&0xff,(deco32_pf12_control[6]>>8)&0xff,deco32_pf12_control[4],deco32_pf12_control[3],deco32_pf2_rowscroll,deco32_pf2_rowscroll+0x200);
1453   deco32_setup_scroll(pf3_tilemap, 512,(deco32_pf34_control[5]>>0)&0xff,(deco32_pf34_control[6]>>0)&0xff,deco32_pf34_control[2],deco32_pf34_control[1],deco32_pf3_rowscroll,deco32_pf3_rowscroll+0x200);
1454   deco32_setup_scroll(pf4_tilemap, 512,(deco32_pf34_control[5]>>8)&0xff,(deco32_pf34_control[6]>>8)&0xff,deco32_pf34_control[4],deco32_pf34_control[3],deco32_pf4_rowscroll,deco32_pf4_rowscroll+0x200);
1460   deco32_setup_scroll(state->pf1_tilemap, 256,(state->pf12_control[5]>>0)&0xff,(state->pf12_control[6]>>0)&0xff,state->pf12_control[2],state->pf12_control[1],state->pf1_rowscroll,state->pf1_rowscroll+0x200);
1461   deco32_setup_scroll(state->pf2_tilemap, 512,(state->pf12_control[5]>>8)&0xff,(state->pf12_control[6]>>8)&0xff,state->pf12_control[4],state->pf12_control[3],state->pf2_rowscroll,state->pf2_rowscroll+0x200);
1462   deco32_setup_scroll(state->pf3_tilemap, 512,(state->pf34_control[5]>>0)&0xff,(state->pf34_control[6]>>0)&0xff,state->pf34_control[2],state->pf34_control[1],state->pf3_rowscroll,state->pf3_rowscroll+0x200);
1463   deco32_setup_scroll(state->pf4_tilemap, 512,(state->pf34_control[5]>>8)&0xff,(state->pf34_control[6]>>8)&0xff,state->pf34_control[4],state->pf34_control[3],state->pf4_rowscroll,state->pf4_rowscroll+0x200);
14551464
14561465   /* Draw screen */
1457   deco16_clear_sprite_priority_bitmap();
1466   deco16_clear_sprite_priority_bitmap(state);
14581467   bitmap_fill(screen->machine->priority_bitmap,cliprect,0);
14591468   bitmap_fill(bitmap,cliprect,screen->machine->pens[0x000]); // Palette index not confirmed
1460   tilemap_draw(bitmap,cliprect,pf4_tilemap,0,0);
1461   if(deco32_pri&1)
1469   tilemap_draw(bitmap,cliprect,state->pf4_tilemap,0,0);
1470   if(state->pri&1)
14621471   {
1463      tilemap_draw(bitmap,cliprect,pf2_tilemap,0,0);
1464      tilemap_draw(bitmap,cliprect,pf3_tilemap,0,2);
1472      tilemap_draw(bitmap,cliprect,state->pf2_tilemap,0,0);
1473      tilemap_draw(bitmap,cliprect,state->pf3_tilemap,0,2);
14651474   }
14661475   else
14671476   {
1468      tilemap_draw(bitmap,cliprect,pf3_tilemap,0,0);
1469      tilemap_draw(bitmap,cliprect,pf2_tilemap,0,2);
1477      tilemap_draw(bitmap,cliprect,state->pf3_tilemap,0,0);
1478      tilemap_draw(bitmap,cliprect,state->pf2_tilemap,0,2);
14701479   }
14711480   fghthist_draw_sprites(screen->machine, bitmap, cliprect, screen->machine->generic.buffered_spriteram.u32,3,0, 0xf);
1472   tilemap_draw(bitmap,cliprect,pf1_tilemap,0,0);
1481   tilemap_draw(bitmap,cliprect,state->pf1_tilemap,0,0);
14731482   return 0;
14741483}
14751484
r10427r10428
14831492*/
14841493static void mixDualAlphaSprites(bitmap_t *bitmap, const rectangle *cliprect, const gfx_element *gfx0, const gfx_element *gfx1, int mixAlphaTilemap)
14851494{
1495   deco32_state *state = gfx0->machine->driver_data<deco32_state>();
14861496   running_machine *machine = gfx0->machine;
14871497   const pen_t *pens = machine->pens;
14881498   const pen_t *pal0 = &pens[gfx0->color_base];
14891499   const pen_t *pal1 = &pens[gfx1->color_base];
1490   const pen_t *pal2 = &pens[machine->gfx[(deco32_pri&1) ? 1 : 2]->color_base];
1500   const pen_t *pal2 = &pens[machine->gfx[(state->pri&1) ? 1 : 2]->color_base];
14911501   int x,y;
14921502
14931503   /* Mix sprites into main bitmap, based on priority & alpha */
14941504   for (y=8; y<248; y++) {
14951505      UINT8* tilemapPri=BITMAP_ADDR8(machine->priority_bitmap, y, 0);
1496      UINT16* sprite0=BITMAP_ADDR16(sprite0_mix_bitmap, y, 0);
1497      UINT16* sprite1=BITMAP_ADDR16(sprite1_mix_bitmap, y, 0);
1506      UINT16* sprite0=BITMAP_ADDR16(state->sprite0_mix_bitmap, y, 0);
1507      UINT16* sprite1=BITMAP_ADDR16(state->sprite1_mix_bitmap, y, 0);
14981508      UINT32* destLine=BITMAP_ADDR32(bitmap, y, 0);
1499      UINT16* alphaTilemap=BITMAP_ADDR16(tilemap_alpha_bitmap, y, 0);
1509      UINT16* alphaTilemap=BITMAP_ADDR16(state->tilemap_alpha_bitmap, y, 0);
15001510
15011511      for (x=0; x<320; x++) {
15021512         UINT16 priColAlphaPal0=sprite0[x];
r10427r10428
15501560                    */
15511561
15521562               /* Alpha values are tied to ACE ram... */
1553               //int alpha=((deco32_ace_ram[0x0 + (((priColAlphaPal1&0xf0)>>4)/2)]) * 8)-1;
1563               //int alpha=((state->ace_ram[0x0 + (((priColAlphaPal1&0xf0)>>4)/2)]) * 8)-1;
15541564               //if (alpha<0)
15551565               //  alpha=0;
15561566
r10427r10428
15591569
15601570               if (pri1==0 && (((priColAlphaPal0&0xff)==0 || ((pri0&0x3)!=0 && (pri0&0x3)!=1 && (pri0&0x3)!=2))))
15611571               {
1562                  if ((deco32_pri&1)==0 || ((deco32_pri&1)==1 && tilemapPri[x]<4) || ((deco32_pri&1)==1 && mixAlphaTilemap))
1572                  if ((state->pri&1)==0 || ((state->pri&1)==1 && tilemapPri[x]<4) || ((state->pri&1)==1 && mixAlphaTilemap))
15631573                     destLine[x]=alpha_blend_r32(destLine[x], pal1[(priColAlphaPal1&0xff) + (gfx1->color_granularity * col1)], 0x80);
15641574               }
15651575               else if (pri1==1 && ((priColAlphaPal0&0xff)==0 || ((pri0&0x3)!=0 && (pri0&0x3)!=1 && (pri0&0x3)!=2)))
r10427r10428
15981608                  && ((priColAlphaPal1&0xff)==0 || (pri1&0x3)==2 || (pri1&0x3)==3 || alpha1))
15991609               {
16001610                  /* Alpha values are tied to ACE ram */
1601                  int alpha=((deco32_ace_ram[0x17 + (((p&0xf0)>>4)/2)]) * 8)-1;
1611                  int alpha=((state->ace_ram[0x17 + (((p&0xf0)>>4)/2)]) * 8)-1;
16021612                  if (alpha<0)
16031613                     alpha=0;
16041614
r10427r10428
16121622
16131623VIDEO_UPDATE( nslasher )
16141624{
1625   deco32_state *state = screen->machine->driver_data<deco32_state>();
16151626   int alphaTilemap=0;
16161627
16171628   /* Dirty tilemaps if any globals change */
1618   if (deco32_pf1_flip!=((deco32_pf12_control[6]>>0)&0x3))
1619      tilemap_mark_all_tiles_dirty(pf1_tilemap);
1620   if (deco32_pf2_flip!=((deco32_pf12_control[6]>>8)&0x3))
1621      tilemap_mark_all_tiles_dirty(pf2_tilemap);
1622   if ((((deco32_pf12_control[7]>>12)&0x7)<<12)!=deco32_pf2_bank || deco32_pf2_flip!=((deco32_pf12_control[6]>>8)&0x3))
1623      tilemap_mark_all_tiles_dirty(pf2_tilemap);
1624   if ((((deco32_pf34_control[7]>> 4)&0x3)<<12)!=deco32_pf3_bank || deco32_pf3_flip!=((deco32_pf34_control[6]>>0)&0x3))
1625      tilemap_mark_all_tiles_dirty(pf3_tilemap);
1626   if ((((deco32_pf34_control[7]>>12)&0x3)<<12)!=deco32_pf4_bank || deco32_pf4_flip!=((deco32_pf34_control[6]>>8)&0x3))
1627      tilemap_mark_all_tiles_dirty(pf4_tilemap);
1629   if (state->pf1_flip!=((state->pf12_control[6]>>0)&0x3))
1630      tilemap_mark_all_tiles_dirty(state->pf1_tilemap);
1631   if (state->pf2_flip!=((state->pf12_control[6]>>8)&0x3))
1632      tilemap_mark_all_tiles_dirty(state->pf2_tilemap);
1633   if ((((state->pf12_control[7]>>12)&0x7)<<12)!=state->pf2_bank || state->pf2_flip!=((state->pf12_control[6]>>8)&0x3))
1634      tilemap_mark_all_tiles_dirty(state->pf2_tilemap);
1635   if ((((state->pf34_control[7]>> 4)&0x3)<<12)!=state->pf3_bank || state->pf3_flip!=((state->pf34_control[6]>>0)&0x3))
1636      tilemap_mark_all_tiles_dirty(state->pf3_tilemap);
1637   if ((((state->pf34_control[7]>>12)&0x3)<<12)!=state->pf4_bank || state->pf4_flip!=((state->pf34_control[6]>>8)&0x3))
1638      tilemap_mark_all_tiles_dirty(state->pf4_tilemap);
16281639
1629   deco32_pf2_bank=((deco32_pf12_control[7]>>12)&0x3)<<12;
1630   deco32_pf3_bank=((deco32_pf34_control[7]>> 4)&0x3)<<12;
1631   deco32_pf4_bank=((deco32_pf34_control[7]>>12)&0x3)<<12;
1632   deco32_pf1_flip=(deco32_pf12_control[6]>>0)&0x3;
1633   deco32_pf2_flip=(deco32_pf12_control[6]>>8)&0x3;
1634   deco32_pf3_flip=(deco32_pf34_control[6]>>0)&0x3;
1635   deco32_pf4_flip=(deco32_pf34_control[6]>>8)&0x3;
1640   state->pf2_bank=((state->pf12_control[7]>>12)&0x3)<<12;
1641   state->pf3_bank=((state->pf34_control[7]>> 4)&0x3)<<12;
1642   state->pf4_bank=((state->pf34_control[7]>>12)&0x3)<<12;
1643   state->pf1_flip=(state->pf12_control[6]>>0)&0x3;
1644   state->pf2_flip=(state->pf12_control[6]>>8)&0x3;
1645   state->pf3_flip=(state->pf34_control[6]>>0)&0x3;
1646   state->pf4_flip=(state->pf34_control[6]>>8)&0x3;
16361647
16371648   /* Setup scroll registers */
1638   deco32_setup_scroll(pf1_tilemap, 256,(deco32_pf12_control[5]>>0)&0xff,(deco32_pf12_control[6]>>0)&0xff,deco32_pf12_control[2],deco32_pf12_control[1],deco32_pf1_rowscroll,deco32_pf1_rowscroll+0x200);
1639   deco32_setup_scroll(pf2_tilemap, 512,(deco32_pf12_control[5]>>8)&0xff,(deco32_pf12_control[6]>>8)&0xff,deco32_pf12_control[4],deco32_pf12_control[3],deco32_pf2_rowscroll,deco32_pf2_rowscroll+0x200);
1640   deco32_setup_scroll(pf3_tilemap, 512,(deco32_pf34_control[5]>>0)&0xff,(deco32_pf34_control[6]>>0)&0xff,deco32_pf34_control[2],deco32_pf34_control[1],deco32_pf3_rowscroll,deco32_pf3_rowscroll+0x200);
1641   deco32_setup_scroll(pf4_tilemap, 512,(deco32_pf34_control[5]>>8)&0xff,(deco32_pf34_control[6]>>8)&0xff,deco32_pf34_control[4],deco32_pf34_control[3],deco32_pf4_rowscroll,deco32_pf4_rowscroll+0x200);
1649   deco32_setup_scroll(state->pf1_tilemap, 256,(state->pf12_control[5]>>0)&0xff,(state->pf12_control[6]>>0)&0xff,state->pf12_control[2],state->pf12_control[1],state->pf1_rowscroll,state->pf1_rowscroll+0x200);
1650   deco32_setup_scroll(state->pf2_tilemap, 512,(state->pf12_control[5]>>8)&0xff,(state->pf12_control[6]>>8)&0xff,state->pf12_control[4],state->pf12_control[3],state->pf2_rowscroll,state->pf2_rowscroll+0x200);
1651   deco32_setup_scroll(state->pf3_tilemap, 512,(state->pf34_control[5]>>0)&0xff,(state->pf34_control[6]>>0)&0xff,state->pf34_control[2],state->pf34_control[1],state->pf3_rowscroll,state->pf3_rowscroll+0x200);
1652   deco32_setup_scroll(state->pf4_tilemap, 512,(state->pf34_control[5]>>8)&0xff,(state->pf34_control[6]>>8)&0xff,state->pf34_control[4],state->pf34_control[3],state->pf4_rowscroll,state->pf4_rowscroll+0x200);
16421653
16431654   /* Enable registers */
1644   tilemap_set_enable(pf1_tilemap, deco32_pf12_control[5]&0x0080);
1645   tilemap_set_enable(pf2_tilemap, deco32_pf12_control[5]&0x8000);
1646   tilemap_set_enable(pf3_tilemap, deco32_pf34_control[5]&0x0080);
1647   tilemap_set_enable(pf4_tilemap, deco32_pf34_control[5]&0x8000);
1655   tilemap_set_enable(state->pf1_tilemap, state->pf12_control[5]&0x0080);
1656   tilemap_set_enable(state->pf2_tilemap, state->pf12_control[5]&0x8000);
1657   tilemap_set_enable(state->pf3_tilemap, state->pf34_control[5]&0x0080);
1658   tilemap_set_enable(state->pf4_tilemap, state->pf34_control[5]&0x8000);
16481659
16491660   /* This is not a conclusive test for deciding if tilemap needs alpha blending */
1650   if (deco32_ace_ram[0x17]!=0x0 && deco32_pri)
1661   if (state->ace_ram[0x17]!=0x0 && state->pri)
16511662      alphaTilemap=1;
16521663
1653   if (deco32_ace_ram_dirty)
1664   if (state->ace_ram_dirty)
16541665      updateAceRam(screen->machine);
16551666
1656   bitmap_fill(sprite0_mix_bitmap,cliprect,0);
1657   bitmap_fill(sprite1_mix_bitmap,cliprect,0);
1667   bitmap_fill(state->sprite0_mix_bitmap,cliprect,0);
1668   bitmap_fill(state->sprite1_mix_bitmap,cliprect,0);
16581669   bitmap_fill(screen->machine->priority_bitmap,cliprect,0);
1659   if ((deco32_pf34_control[5]&0x8000)==0)
1670   if ((state->pf34_control[5]&0x8000)==0)
16601671      bitmap_fill(bitmap,cliprect,screen->machine->pens[0x200]);
16611672
16621673   /* Draw sprites to temporary bitmaps, saving alpha & priority info for later mixing */
1663   nslasher_draw_sprites(screen->machine,sprite0_mix_bitmap,cliprect,screen->machine->generic.buffered_spriteram.u32,3);
1664   nslasher_draw_sprites(screen->machine,sprite1_mix_bitmap,cliprect,screen->machine->generic.buffered_spriteram2.u32,4);
1674   nslasher_draw_sprites(screen->machine,state->sprite0_mix_bitmap,cliprect,screen->machine->generic.buffered_spriteram.u32,3);
1675   nslasher_draw_sprites(screen->machine,state->sprite1_mix_bitmap,cliprect,screen->machine->generic.buffered_spriteram2.u32,4);
16651676
16661677   /* Render alpha-blended tilemap to seperate buffer for proper mixing */
1667   bitmap_fill(tilemap_alpha_bitmap,cliprect,0);
1678   bitmap_fill(state->tilemap_alpha_bitmap,cliprect,0);
16681679
16691680   /* Draw playfields & sprites */
1670   if (deco32_pri&2)
1681   if (state->pri&2)
16711682   {
16721683      combined_tilemap_draw(screen->machine,bitmap,cliprect);
1673      tilemap_draw(bitmap,cliprect,pf2_tilemap,0,4);
1684      tilemap_draw(bitmap,cliprect,state->pf2_tilemap,0,4);
16741685   }
16751686   else
16761687   {
1677      tilemap_draw(bitmap,cliprect,pf4_tilemap,0,1);
1678      if (deco32_pri&1)
1688      tilemap_draw(bitmap,cliprect,state->pf4_tilemap,0,1);
1689      if (state->pri&1)
16791690      {
1680         tilemap_draw(bitmap,cliprect,pf2_tilemap,0,2);
1691         tilemap_draw(bitmap,cliprect,state->pf2_tilemap,0,2);
16811692         if (alphaTilemap)
1682            tilemap_draw(tilemap_alpha_bitmap,cliprect,pf3_tilemap,0,4);
1693            tilemap_draw(state->tilemap_alpha_bitmap,cliprect,state->pf3_tilemap,0,4);
16831694         else
1684            tilemap_draw(bitmap,cliprect,pf3_tilemap,0,4);
1695            tilemap_draw(bitmap,cliprect,state->pf3_tilemap,0,4);
16851696      }
16861697      else
16871698      {
1688         tilemap_draw(bitmap,cliprect,pf3_tilemap,0,2);
1699         tilemap_draw(bitmap,cliprect,state->pf3_tilemap,0,2);
16891700         if (alphaTilemap)
1690            tilemap_draw(tilemap_alpha_bitmap,cliprect,pf2_tilemap,0,4);
1701            tilemap_draw(state->tilemap_alpha_bitmap,cliprect,state->pf2_tilemap,0,4);
16911702         else
1692            tilemap_draw(bitmap,cliprect,pf2_tilemap,0,4);
1703            tilemap_draw(bitmap,cliprect,state->pf2_tilemap,0,4);
16931704      }
16941705   }
16951706
16961707   mixDualAlphaSprites(bitmap, cliprect, screen->machine->gfx[3], screen->machine->gfx[4], alphaTilemap);
16971708
1698   tilemap_draw(bitmap,cliprect,pf1_tilemap,0,0);
1709   tilemap_draw(bitmap,cliprect,state->pf1_tilemap,0,0);
16991710   return 0;
17001711}
src/mame/video/fastfred.c
r10427r10428
1111#include "includes/fastfred.h"
1212#include "includes/galaxold.h"
1313
14UINT8 *fastfred_videoram;
15UINT8 *fastfred_spriteram;
16size_t fastfred_spriteram_size;
17UINT8 *fastfred_attributesram;
18UINT8 *fastfred_background_color;
19UINT8 *imago_fg_videoram;
2014
2115
2216static const rectangle spritevisiblearea =
r10427r10428
3125        2*8, 30*8-1
3226};
3327
34static UINT16 charbank;
35static UINT8 colorbank;
36int fastfred_hardware_type;
37static tilemap_t *bg_tilemap, *fg_tilemap, *web_tilemap;
3828
3929/***************************************************************************
4030
r10427r10428
10595
10696static TILE_GET_INFO( get_tile_info )
10797{
98   fastfred_state *state = machine->driver_data<fastfred_state>();
10899   UINT8 x = tile_index & 0x1f;
109100
110   UINT16 code = charbank | fastfred_videoram[tile_index];
111   UINT8 color = colorbank | (fastfred_attributesram[2 * x + 1] & 0x07);
101   UINT16 code = state->charbank | state->videoram[tile_index];
102   UINT8 color = state->colorbank | (state->attributesram[2 * x + 1] & 0x07);
112103
113104   SET_TILE_INFO(0, code, color, 0);
114105}
r10427r10428
123114
124115VIDEO_START( fastfred )
125116{
126   bg_tilemap = tilemap_create(machine, get_tile_info,tilemap_scan_rows,8,8,32,32);
117   fastfred_state *state = machine->driver_data<fastfred_state>();
118   state->bg_tilemap = tilemap_create(machine, get_tile_info,tilemap_scan_rows,8,8,32,32);
127119
128   tilemap_set_transparent_pen(bg_tilemap, 0);
129   tilemap_set_scroll_cols(bg_tilemap, 32);
120   tilemap_set_transparent_pen(state->bg_tilemap, 0);
121   tilemap_set_scroll_cols(state->bg_tilemap, 32);
130122}
131123
132124
r10427r10428
138130
139131WRITE8_HANDLER( fastfred_videoram_w )
140132{
141   fastfred_videoram[offset] = data;
142   tilemap_mark_tile_dirty(bg_tilemap, offset);
133   fastfred_state *state = space->machine->driver_data<fastfred_state>();
134   state->videoram[offset] = data;
135   tilemap_mark_tile_dirty(state->bg_tilemap, offset);
143136}
144137
145138
146139WRITE8_HANDLER( fastfred_attributes_w )
147140{
148   if (fastfred_attributesram[offset] != data)
141   fastfred_state *state = space->machine->driver_data<fastfred_state>();
142   if (state->attributesram[offset] != data)
149143   {
150144      if (offset & 0x01)
151145      {
r10427r10428
153147         int i;
154148
155149         for (i = offset / 2; i < 0x0400; i += 32)
156            tilemap_mark_tile_dirty(bg_tilemap, i);
150            tilemap_mark_tile_dirty(state->bg_tilemap, i);
157151      }
158152      else
159153      {
160154         /* coloumn scroll */
161         tilemap_set_scrolly(bg_tilemap, offset / 2, data);
155         tilemap_set_scrolly(state->bg_tilemap, offset / 2, data);
162156      }
163157
164      fastfred_attributesram[offset] = data;
158      state->attributesram[offset] = data;
165159   }
166160}
167161
168162
169163WRITE8_HANDLER( fastfred_charbank1_w )
170164{
171   UINT16 new_data = (charbank & 0x0200) | ((data & 0x01) << 8);
165   fastfred_state *state = space->machine->driver_data<fastfred_state>();
166   UINT16 new_data = (state->charbank & 0x0200) | ((data & 0x01) << 8);
172167
173   if (new_data != charbank)
168   if (new_data != state->charbank)
174169   {
175      tilemap_mark_all_tiles_dirty(bg_tilemap);
170      tilemap_mark_all_tiles_dirty(state->bg_tilemap);
176171
177      charbank = new_data;
172      state->charbank = new_data;
178173   }
179174}
180175
181176WRITE8_HANDLER( fastfred_charbank2_w )
182177{
183   UINT16 new_data = (charbank & 0x0100) | ((data & 0x01) << 9);
178   fastfred_state *state = space->machine->driver_data<fastfred_state>();
179   UINT16 new_data = (state->charbank & 0x0100) | ((data & 0x01) << 9);
184180
185   if (new_data != charbank)
181   if (new_data != state->charbank)
186182   {
187      tilemap_mark_all_tiles_dirty(bg_tilemap);
183      tilemap_mark_all_tiles_dirty(state->bg_tilemap);
188184
189      charbank = new_data;
185      state->charbank = new_data;
190186   }
191187}
192188
193189
194190WRITE8_HANDLER( fastfred_colorbank1_w )
195191{
196   UINT8 new_data = (colorbank & 0x10) | ((data & 0x01) << 3);
192   fastfred_state *state = space->machine->driver_data<fastfred_state>();
193   UINT8 new_data = (state->colorbank & 0x10) | ((data & 0x01) << 3);
197194
198   if (new_data != colorbank)
195   if (new_data != state->colorbank)
199196   {
200      tilemap_mark_all_tiles_dirty(bg_tilemap);
197      tilemap_mark_all_tiles_dirty(state->bg_tilemap);
201198
202      colorbank = new_data;
199      state->colorbank = new_data;
203200   }
204201}
205202
206203WRITE8_HANDLER( fastfred_colorbank2_w )
207204{
208   UINT8 new_data = (colorbank & 0x08) | ((data & 0x01) << 4);
205   fastfred_state *state = space->machine->driver_data<fastfred_state>();
206   UINT8 new_data = (state->colorbank & 0x08) | ((data & 0x01) << 4);
209207
210   if (new_data != colorbank)
208   if (new_data != state->colorbank)
211209   {
212      tilemap_mark_all_tiles_dirty(bg_tilemap);
210      tilemap_mark_all_tiles_dirty(state->bg_tilemap);
213211
214      colorbank = new_data;
212      state->colorbank = new_data;
215213   }
216214}
217215
r10427r10428
219217
220218WRITE8_HANDLER( fastfred_flip_screen_x_w )
221219{
220   fastfred_state *state = space->machine->driver_data<fastfred_state>();
222221   if (flip_screen_x_get(space->machine) != (data & 0x01))
223222   {
224223      flip_screen_x_set(space->machine, data & 0x01);
225224
226      tilemap_set_flip(bg_tilemap, (flip_screen_x_get(space->machine) ? TILEMAP_FLIPX : 0) | (flip_screen_y_get(space->machine) ? TILEMAP_FLIPY : 0));
225      tilemap_set_flip(state->bg_tilemap, (flip_screen_x_get(space->machine) ? TILEMAP_FLIPX : 0) | (flip_screen_y_get(space->machine) ? TILEMAP_FLIPY : 0));
227226   }
228227}
229228
230229WRITE8_HANDLER( fastfred_flip_screen_y_w )
231230{
231   fastfred_state *state = space->machine->driver_data<fastfred_state>();
232232   if (flip_screen_y_get(space->machine) != (data & 0x01))
233233   {
234234      flip_screen_y_set(space->machine, data & 0x01);
235235
236      tilemap_set_flip(bg_tilemap, (flip_screen_x_get(space->machine) ? TILEMAP_FLIPX : 0) | (flip_screen_y_get(space->machine) ? TILEMAP_FLIPY : 0));
236      tilemap_set_flip(state->bg_tilemap, (flip_screen_x_get(space->machine) ? TILEMAP_FLIPX : 0) | (flip_screen_y_get(space->machine) ? TILEMAP_FLIPY : 0));
237237   }
238238}
239239
r10427r10428
247247
248248static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect)
249249{
250   fastfred_state *state = machine->driver_data<fastfred_state>();
250251   int offs;
251252
252   for (offs = fastfred_spriteram_size - 4; offs >= 0; offs -= 4)
253   for (offs = state->spriteram_size - 4; offs >= 0; offs -= 4)
253254   {
254255      UINT8 code,sx,sy;
255256      int flipx,flipy;
256257
257      sx = fastfred_spriteram[offs + 3];
258      sy = 240 - fastfred_spriteram[offs];
258      sx = state->spriteram[offs + 3];
259      sy = 240 - state->spriteram[offs];
259260
260      if (fastfred_hardware_type == 3)
261      if (state->hardware_type == 3)
261262      {
262263         // Imago
263         code  = (fastfred_spriteram[offs + 1]) & 0x3f;
264         code  = (state->spriteram[offs + 1]) & 0x3f;
264265         flipx = 0;
265266         flipy = 0;
266267      }
267      else if (fastfred_hardware_type == 2)
268      else if (state->hardware_type == 2)
268269      {
269270         // Boggy 84
270         code  =  fastfred_spriteram[offs + 1] & 0x7f;
271         code  =  state->spriteram[offs + 1] & 0x7f;
271272         flipx =  0;
272         flipy =  fastfred_spriteram[offs + 1] & 0x80;
273         flipy =  state->spriteram[offs + 1] & 0x80;
273274      }
274      else if (fastfred_hardware_type == 1)
275      else if (state->hardware_type == 1)
275276      {
276277         // Fly-Boy/Fast Freddie/Red Robin
277         code  =  fastfred_spriteram[offs + 1] & 0x7f;
278         code  =  state->spriteram[offs + 1] & 0x7f;
278279         flipx =  0;
279         flipy = ~fastfred_spriteram[offs + 1] & 0x80;
280         flipy = ~state->spriteram[offs + 1] & 0x80;
280281      }
281282      else
282283      {
283284         // Jump Coaster
284         code  = (fastfred_spriteram[offs + 1] & 0x3f) | 0x40;
285         flipx = ~fastfred_spriteram[offs + 1] & 0x40;
286         flipy =  fastfred_spriteram[offs + 1] & 0x80;
285         code  = (state->spriteram[offs + 1] & 0x3f) | 0x40;
286         flipx = ~state->spriteram[offs + 1] & 0x40;
287         flipy =  state->spriteram[offs + 1] & 0x80;
287288      }
288289
289290
r10427r10428
300301
301302      drawgfx_transpen(bitmap,flip_screen_x_get(machine) ? &spritevisibleareaflipx : &spritevisiblearea,machine->gfx[1],
302303            code,
303            colorbank | (fastfred_spriteram[offs + 2] & 0x07),
304            state->colorbank | (state->spriteram[offs + 2] & 0x07),
304305            flipx,flipy,
305306            sx,sy,0);
306307   }
r10427r10428
309310
310311VIDEO_UPDATE( fastfred )
311312{
312   bitmap_fill(bitmap, cliprect, *fastfred_background_color);
313   tilemap_draw(bitmap,cliprect,bg_tilemap,0,0);
313   fastfred_state *state = screen->machine->driver_data<fastfred_state>();
314   bitmap_fill(bitmap, cliprect, *state->background_color);
315   tilemap_draw(bitmap,cliprect,state->bg_tilemap,0,0);
314316   draw_sprites(screen->machine, bitmap, cliprect);
315317
316318   return 0;
r10427r10428
319321
320322static TILE_GET_INFO( imago_get_tile_info_bg )
321323{
324   fastfred_state *state = machine->driver_data<fastfred_state>();
322325   UINT8 x = tile_index & 0x1f;
323326
324   UINT16 code = charbank * 0x100 + fastfred_videoram[tile_index];
325   UINT8 color = colorbank | (fastfred_attributesram[2 * x + 1] & 0x07);
327   UINT16 code = state->charbank * 0x100 + state->videoram[tile_index];
328   UINT8 color = state->colorbank | (state->attributesram[2 * x + 1] & 0x07);
326329
327330   SET_TILE_INFO(0, code, color, 0);
328331}
329332
330333static TILE_GET_INFO( imago_get_tile_info_fg )
331334{
332   int code = imago_fg_videoram[tile_index];
335   fastfred_state *state = machine->driver_data<fastfred_state>();
336   int code = state->imago_fg_videoram[tile_index];
333337   SET_TILE_INFO(2, code, 2, 0);
334338}
335339
r10427r10428
340344
341345WRITE8_HANDLER( imago_fg_videoram_w )
342346{
343   imago_fg_videoram[offset] = data;
344   tilemap_mark_tile_dirty(fg_tilemap, offset);
347   fastfred_state *state = space->machine->driver_data<fastfred_state>();
348   state->imago_fg_videoram[offset] = data;
349   tilemap_mark_tile_dirty(state->fg_tilemap, offset);
345350}
346351
347352WRITE8_HANDLER( imago_charbank_w )
348353{
349   if( charbank != data )
354   fastfred_state *state = space->machine->driver_data<fastfred_state>();
355   if( state->charbank != data )
350356   {
351      charbank = data;
352      tilemap_mark_all_tiles_dirty(bg_tilemap);
357      state->charbank = data;
358      tilemap_mark_all_tiles_dirty(state->bg_tilemap);
353359   }
354360}
355361
356362VIDEO_START( imago )
357363{
358   web_tilemap = tilemap_create(machine, imago_get_tile_info_web,tilemap_scan_rows,     8,8,32,32);
359   bg_tilemap   = tilemap_create(machine, imago_get_tile_info_bg, tilemap_scan_rows,8,8,32,32);
360   fg_tilemap   = tilemap_create(machine, imago_get_tile_info_fg, tilemap_scan_rows,8,8,32,32);
364   fastfred_state *state = machine->driver_data<fastfred_state>();
365   state->web_tilemap = tilemap_create(machine, imago_get_tile_info_web,tilemap_scan_rows,     8,8,32,32);
366   state->bg_tilemap   = tilemap_create(machine, imago_get_tile_info_bg, tilemap_scan_rows,8,8,32,32);
367   state->fg_tilemap   = tilemap_create(machine, imago_get_tile_info_fg, tilemap_scan_rows,8,8,32,32);
361368
362   tilemap_set_transparent_pen(bg_tilemap, 0);
363   tilemap_set_transparent_pen(fg_tilemap, 0);
369   tilemap_set_transparent_pen(state->bg_tilemap, 0);
370   tilemap_set_transparent_pen(state->fg_tilemap, 0);
364371
365372   /* the game has a galaxian starfield */
366373   galaxold_init_stars(machine, 256);
r10427r10428
373380
374381VIDEO_UPDATE( imago )
375382{
376   tilemap_draw(bitmap,cliprect,web_tilemap,0,0);
383   fastfred_state *state = screen->machine->driver_data<fastfred_state>();
384   tilemap_draw(bitmap,cliprect,state->web_tilemap,0,0);
377385   galaxold_draw_stars(screen->machine, bitmap, cliprect);
378   tilemap_draw(bitmap,cliprect,bg_tilemap,0,0);
386   tilemap_draw(bitmap,cliprect,state->bg_tilemap,0,0);
379387   draw_sprites(screen->machine, bitmap, cliprect);
380   tilemap_draw(bitmap,cliprect,fg_tilemap,0,0);
388   tilemap_draw(bitmap,cliprect,state->fg_tilemap,0,0);
381389
382390   return 0;
383391}
src/mame/video/gticlub.c
r10427r10428
11#include "emu.h"
22#include "cpu/sharc/sharc.h"
33#include "machine/konppc.h"
4#include "video/voodoo.h"
45#include "video/poly.h"
56#include "video/konicdev.h"
67#include "video/gticlub.h"
r10427r10428
1718   int texture_mirror_y;
1819};
1920
20extern UINT8 gticlub_led_reg0;
21extern UINT8 gticlub_led_reg1;
21static UINT8 gticlub_led_reg[2];
2222
23void gticlub_led_setreg(int offset, UINT8 data)
24{
25   gticlub_led_reg[offset] = data;
26}
2327
28
2429/*****************************************************************************/
2530/* Konami K001006 Custom 3D Texel Renderer chip (KS10081) */
2631
r10427r10428
967972
968973VIDEO_START( gticlub )
969974{
975   gticlub_led_reg[0] = gticlub_led_reg[1] = 0x7f;
970976   tick = 0;
971977   debug_tex_page = 0;
972978   debug_tex_palette = 0;
r10427r10428
10351041    }
10361042#endif
10371043
1038   draw_7segment_led(bitmap, 3, 3, gticlub_led_reg0);
1039   draw_7segment_led(bitmap, 9, 3, gticlub_led_reg1);
1044   draw_7segment_led(bitmap, 3, 3, gticlub_led_reg[0]);
1045   draw_7segment_led(bitmap, 9, 3, gticlub_led_reg[1]);
10401046
10411047   //cputag_set_input_line(screen->machine, "dsp", SHARC_INPUT_FLAG1, ASSERT_LINE);
10421048   sharc_set_flag_input(screen->machine->device("dsp"), 1, ASSERT_LINE);
10431049   return 0;
10441050}
10451051
1052VIDEO_UPDATE( hangplt )
1053{
1054   bitmap_fill(bitmap, cliprect, screen->machine->pens[0]);
1055
1056   if (strcmp(screen->tag(), "lscreen") == 0)
1057   {
1058      device_t *k001604 = screen->machine->device("k001604_1");
1059      device_t *voodoo = screen->machine->device("voodoo0");
1060
1061   //  k001604_draw_back_layer(k001604, bitmap, cliprect);
1062
1063      voodoo_update(voodoo, bitmap, cliprect);
1064
1065      k001604_draw_front_layer(k001604, bitmap, cliprect);
1066   }
1067   else if (strcmp(screen->tag(), "rscreen") == 0)
1068   {
1069      device_t *k001604 = screen->machine->device("k001604_2");
1070      device_t *voodoo = screen->machine->device("voodoo1");
1071
1072   //  k001604_draw_back_layer(k001604, bitmap, cliprect);
1073
1074      voodoo_update(voodoo, bitmap, cliprect);
1075
1076      k001604_draw_front_layer(k001604, bitmap, cliprect);
1077   }
1078
1079   draw_7segment_led(bitmap, 3, 3, gticlub_led_reg[0]);
1080   draw_7segment_led(bitmap, 9, 3, gticlub_led_reg[1]);
1081
1082   return 0;
1083}
1084
src/mame/video/gticlub.h
r10427r10428
1void gticlub_led_setreg(int offset, UINT8 data);
2
13void K001005_draw(bitmap_t *bitmap, const rectangle *cliprect);
24void K001005_swap_buffers(running_machine *machine);
35void K001005_init(running_machine *machine);
r10427r10428
1416
1517VIDEO_START( gticlub );
1618VIDEO_UPDATE( gticlub );
19VIDEO_UPDATE( hangplt );
src/mame/video/beezer.c
r10427r10428
33#include "machine/6522via.h"
44#include "includes/beezer.h"
55
6static int scanline=0;
76
87INTERRUPT_GEN( beezer_interrupt )
98{
9   beezer_state *state = device->machine->driver_data<beezer_state>();
1010   via6522_device *via_0 = device->machine->device<via6522_device>("via6522_0");
1111
12   scanline = (scanline + 1) % 0x80;
13   via_0->write_ca2((scanline & 0x10) ? 1 : 0);
14   if ((scanline & 0x78) == 0x78)
12   state->scanline = (state->scanline + 1) % 0x80;
13   via_0->write_ca2((state->scanline & 0x10) ? 1 : 0);
14   if ((state->scanline & 0x78) == 0x78)
1515      cpu_set_input_line(device, M6809_FIRQ_LINE, ASSERT_LINE);
1616   else
1717      cpu_set_input_line(device, M6809_FIRQ_LINE, CLEAR_LINE);
r10427r10428
6868
6969READ8_HANDLER( beezer_line_r )
7070{
71   return (scanline & 0xfe) << 1;
71   beezer_state *state = space->machine->driver_data<beezer_state>();
72   return (state->scanline & 0xfe) << 1;
7273}
7374
src/mame/video/darkseal.c
r10427r10428
8888#include "emu.h"
8989#include "includes/darkseal.h"
9090
91UINT16 *darkseal_pf12_row,*darkseal_pf34_row;
92UINT16 *darkseal_pf1_data,*darkseal_pf2_data,*darkseal_pf3_data;
9391
94static UINT16 darkseal_control_0[8];
95static UINT16 darkseal_control_1[8];
9692
97static tilemap_t *pf1_tilemap,*pf2_tilemap,*pf3_tilemap;
98static int flipscreen;
9993
10094/***************************************************************************/
10195
r10427r10428
121115         0);
122116}
123117
124static TILE_GET_INFO( get_bg_tile_info2 ) { get_bg_tile_info(machine,tileinfo,tile_index,1,darkseal_pf2_data); }
125static TILE_GET_INFO( get_bg_tile_info3 ) { get_bg_tile_info(machine,tileinfo,tile_index,2,darkseal_pf3_data); }
118static TILE_GET_INFO( get_bg_tile_info2 )
119{
120   darkseal_state *state = machine->driver_data<darkseal_state>();
121   get_bg_tile_info(machine,tileinfo,tile_index,1,state->pf2_data);
122}
126123
124static TILE_GET_INFO( get_bg_tile_info3 )
125{
126   darkseal_state *state = machine->driver_data<darkseal_state>();
127   get_bg_tile_info(machine,tileinfo,tile_index,2,state->pf3_data);
128}
129
127130static TILE_GET_INFO( get_fg_tile_info )
128131{
129   int tile=darkseal_pf1_data[tile_index];
132   darkseal_state *state = machine->driver_data<darkseal_state>();
133   int tile=state->pf1_data[tile_index];
130134   int color=tile >> 12;
131135
132136   tile=tile&0xfff;
r10427r10428
166170
167171static void draw_sprites(running_machine* machine, bitmap_t *bitmap, const rectangle *cliprect)
168172{
173   darkseal_state *state = machine->driver_data<darkseal_state>();
169174   UINT16 *buffered_spriteram16 = machine->generic.buffered_spriteram.u16;
170175   int offs;
171176
r10427r10428
206211         inc = 1;
207212      }
208213
209      if (flipscreen)
214      if (state->flipscreen)
210215      {
211216         y=240-y;
212217         x=240-x;
r10427r10428
233238
234239WRITE16_HANDLER( darkseal_pf1_data_w )
235240{
236   COMBINE_DATA(&darkseal_pf1_data[offset]);
237   tilemap_mark_tile_dirty(pf1_tilemap,offset);
241   darkseal_state *state = space->machine->driver_data<darkseal_state>();
242   COMBINE_DATA(&state->pf1_data[offset]);
243   tilemap_mark_tile_dirty(state->pf1_tilemap,offset);
238244}
239245
240246WRITE16_HANDLER( darkseal_pf2_data_w )
241247{
242   COMBINE_DATA(&darkseal_pf2_data[offset]);
243   tilemap_mark_tile_dirty(pf2_tilemap,offset);
248   darkseal_state *state = space->machine->driver_data<darkseal_state>();
249   COMBINE_DATA(&state->pf2_data[offset]);
250   tilemap_mark_tile_dirty(state->pf2_tilemap,offset);
244251}
245252
246253WRITE16_HANDLER( darkseal_pf3_data_w )
247254{
248   COMBINE_DATA(&darkseal_pf3_data[offset]);
249   tilemap_mark_tile_dirty(pf3_tilemap,offset);
255   darkseal_state *state = space->machine->driver_data<darkseal_state>();
256   COMBINE_DATA(&state->pf3_data[offset]);
257   tilemap_mark_tile_dirty(state->pf3_tilemap,offset);
250258}
251259
252260WRITE16_HANDLER( darkseal_pf3b_data_w ) /* Mirror */
r10427r10428
256264
257265WRITE16_HANDLER( darkseal_control_0_w )
258266{
259   COMBINE_DATA(&darkseal_control_0[offset]);
267   darkseal_state *state = space->machine->driver_data<darkseal_state>();
268   COMBINE_DATA(&state->control_0[offset]);
260269}
261270
262271WRITE16_HANDLER( darkseal_control_1_w )
263272{
264   COMBINE_DATA(&darkseal_control_1[offset]);
273   darkseal_state *state = space->machine->driver_data<darkseal_state>();
274   COMBINE_DATA(&state->control_1[offset]);
265275}
266276
267277/******************************************************************************/
268278
269279VIDEO_START( darkseal )
270280{
271   pf1_tilemap = tilemap_create(machine, get_fg_tile_info, tilemap_scan_rows, 8, 8,64,64);
272   pf2_tilemap = tilemap_create(machine, get_bg_tile_info2,darkseal_scan,    16,16,64,64);
273   pf3_tilemap = tilemap_create(machine, get_bg_tile_info3,darkseal_scan,         16,16,64,64);
281   darkseal_state *state = machine->driver_data<darkseal_state>();
282   state->pf1_tilemap = tilemap_create(machine, get_fg_tile_info, tilemap_scan_rows, 8, 8,64,64);
283   state->pf2_tilemap = tilemap_create(machine, get_bg_tile_info2,darkseal_scan,    16,16,64,64);
284   state->pf3_tilemap = tilemap_create(machine, get_bg_tile_info3,darkseal_scan,         16,16,64,64);
274285
275   tilemap_set_transparent_pen(pf1_tilemap,0);
276   tilemap_set_transparent_pen(pf2_tilemap,0);
286   tilemap_set_transparent_pen(state->pf1_tilemap,0);
287   tilemap_set_transparent_pen(state->pf2_tilemap,0);
277288}
278289
279290/******************************************************************************/
280291
281292VIDEO_UPDATE( darkseal )
282293{
283   flipscreen=!(darkseal_control_0[0]&0x80);
284   tilemap_set_flip_all(screen->machine,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
294   darkseal_state *state = screen->machine->driver_data<darkseal_state>();
295   state->flipscreen=!(state->control_0[0]&0x80);
296   tilemap_set_flip_all(screen->machine,state->flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
285297
286298   /* Update scroll registers */
287   tilemap_set_scrollx( pf1_tilemap,0, darkseal_control_1[3] );
288   tilemap_set_scrolly( pf1_tilemap,0, darkseal_control_1[4] );
289   tilemap_set_scrollx( pf2_tilemap,0, darkseal_control_1[1]);
290   tilemap_set_scrolly( pf2_tilemap,0, darkseal_control_1[2] );
299   tilemap_set_scrollx( state->pf1_tilemap,0, state->control_1[3] );
300   tilemap_set_scrolly( state->pf1_tilemap,0, state->control_1[4] );
301   tilemap_set_scrollx( state->pf2_tilemap,0, state->control_1[1]);
302   tilemap_set_scrolly( state->pf2_tilemap,0, state->control_1[2] );
291303
292   if (darkseal_control_0[6]&0x4000) { /* Rowscroll enable */
293      int offs,scrollx=darkseal_control_0[3];
304   if (state->control_0[6]&0x4000) { /* Rowscroll enable */
305      int offs,scrollx=state->control_0[3];
294306
295      tilemap_set_scroll_rows(pf3_tilemap,512);
307      tilemap_set_scroll_rows(state->pf3_tilemap,512);
296308      for (offs = 0;offs < 512;offs++)
297         tilemap_set_scrollx( pf3_tilemap,offs, scrollx + darkseal_pf34_row[offs+0x40] );
309         tilemap_set_scrollx( state->pf3_tilemap,offs, scrollx + state->pf34_row[offs+0x40] );
298310   }
299311   else {
300      tilemap_set_scroll_rows(pf3_tilemap,1);
301      tilemap_set_scrollx( pf3_tilemap,0, darkseal_control_0[3] );
312      tilemap_set_scroll_rows(state->pf3_tilemap,1);
313      tilemap_set_scrollx( state->pf3_tilemap,0, state->control_0[3] );
302314   }
303   tilemap_set_scrolly( pf3_tilemap,0, darkseal_control_0[4] );
315   tilemap_set_scrolly( state->pf3_tilemap,0, state->control_0[4] );
304316
305   tilemap_draw(bitmap,cliprect,pf3_tilemap,0,0);
306   tilemap_draw(bitmap,cliprect,pf2_tilemap,0,0);
317   tilemap_draw(bitmap,cliprect,state->pf3_tilemap,0,0);
318   tilemap_draw(bitmap,cliprect,state->pf2_tilemap,0,0);
307319   draw_sprites(screen->machine,bitmap,cliprect);
308   tilemap_draw(bitmap,cliprect,pf1_tilemap,0,0);
320   tilemap_draw(bitmap,cliprect,state->pf1_tilemap,0,0);
309321   return 0;
310322}
311323
src/mame/video/stadhero.c
r10427r10428
1212#include "emu.h"
1313#include "includes/stadhero.h"
1414
15UINT16 *stadhero_pf1_data;
16static UINT16 *stadhero_pf2_data;
17UINT16 *stadhero_pf2_control_0;
18UINT16 *stadhero_pf2_control_1;
19static tilemap_t *pf1_tilemap,*pf2_tilemap;
20static int flipscreen;
2115
2216/******************************************************************************/
2317
2418static void draw_sprites(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int pri_mask,int pri_val)
2519{
20   stadhero_state *state = machine->driver_data<stadhero_state>();
2621   UINT16 *spriteram16 = machine->generic.spriteram.u16;
2722   int offs;
2823
r10427r10428
6358         inc = 1;
6459      }
6560
66      if (flipscreen) {
61      if (state->flipscreen) {
6762         y=240-y;
6863         x=240-x;
6964         if (fx) fx=0; else fx=1;
r10427r10428
8883
8984VIDEO_UPDATE( stadhero )
9085{
91   flipscreen=stadhero_pf2_control_0[0]&0x80;
92   tilemap_set_flip_all(screen->machine,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
93   tilemap_set_scrollx( pf2_tilemap,0, stadhero_pf2_control_1[0] );
94   tilemap_set_scrolly( pf2_tilemap,0, stadhero_pf2_control_1[1] );
86   stadhero_state *state = screen->machine->driver_data<stadhero_state>();
87   state->flipscreen=state->pf2_control_0[0]&0x80;
88   tilemap_set_flip_all(screen->machine,state->flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
89   tilemap_set_scrollx( state->pf2_tilemap,0, state->pf2_control_1[0] );
90   tilemap_set_scrolly( state->pf2_tilemap,0, state->pf2_control_1[1] );
9591
96   tilemap_draw(bitmap,cliprect,pf2_tilemap,0,0);
92   tilemap_draw(bitmap,cliprect,state->pf2_tilemap,0,0);
9793   draw_sprites(screen->machine, bitmap,cliprect,0x00,0x00);
98   tilemap_draw(bitmap,cliprect,pf1_tilemap,0,0);
94   tilemap_draw(bitmap,cliprect,state->pf1_tilemap,0,0);
9995   return 0;
10096}
10197
r10427r10428
10399
104100WRITE16_HANDLER( stadhero_pf1_data_w )
105101{
106   COMBINE_DATA(&stadhero_pf1_data[offset]);
107   tilemap_mark_tile_dirty(pf1_tilemap,offset);
102   stadhero_state *state = space->machine->driver_data<stadhero_state>();
103   COMBINE_DATA(&state->pf1_data[offset]);
104   tilemap_mark_tile_dirty(state->pf1_tilemap,offset);
108105}
109106
110107READ16_HANDLER( stadhero_pf2_data_r )
111108{
112   return stadhero_pf2_data[((stadhero_pf2_control_0[2] & 0x01) ? 0x1000 : 0) | offset];
109   stadhero_state *state = space->machine->driver_data<stadhero_state>();
110   return state->pf2_data[((state->pf2_control_0[2] & 0x01) ? 0x1000 : 0) | offset];
113111}
114112
115113WRITE16_HANDLER( stadhero_pf2_data_w )
116114{
117   COMBINE_DATA(&stadhero_pf2_data[((stadhero_pf2_control_0[2] & 0x01) ? 0x1000 : 0) | offset]);
118   tilemap_mark_tile_dirty(pf2_tilemap,offset);
115   stadhero_state *state = space->machine->driver_data<stadhero_state>();
116   COMBINE_DATA(&state->pf2_data[((state->pf2_control_0[2] & 0x01) ? 0x1000 : 0) | offset]);
117   tilemap_mark_tile_dirty(state->pf2_tilemap,offset);
119118}
120119
121120
r10427r10428
129128
130129static TILE_GET_INFO( get_pf2_tile_info )
131130{
131   stadhero_state *state = machine->driver_data<stadhero_state>();
132132   int tile,color;
133133
134   tile=stadhero_pf2_data[((stadhero_pf2_control_0[2] & 0x01) ? 0x1000 : 0) | tile_index];
134   tile=state->pf2_data[((state->pf2_control_0[2] & 0x01) ? 0x1000 : 0) | tile_index];
135135   color=tile >> 12;
136136   tile=tile&0xfff;
137137
r10427r10428
144144
145145static TILE_GET_INFO( get_pf1_tile_info )
146146{
147   int tile=stadhero_pf1_data[tile_index];
147   stadhero_state *state = machine->driver_data<stadhero_state>();
148   int tile=state->pf1_data[tile_index];
148149   int color=tile >> 12;
149150
150151   tile=tile&0xfff;
r10427r10428
157158
158159VIDEO_START( stadhero )
159160{
160   pf1_tilemap =     tilemap_create(machine, get_pf1_tile_info,tilemap_scan_rows, 8, 8,32,32);
161   pf2_tilemap =     tilemap_create(machine, get_pf2_tile_info,stadhero_scan,     16,16,64,64);
161   stadhero_state *state = machine->driver_data<stadhero_state>();
162   state->pf1_tilemap =     tilemap_create(machine, get_pf1_tile_info,tilemap_scan_rows, 8, 8,32,32);
163   state->pf2_tilemap =     tilemap_create(machine, get_pf2_tile_info,stadhero_scan,     16,16,64,64);
162164
163   stadhero_pf2_data = auto_alloc_array(machine, UINT16, 0x2000);
165   state->pf2_data = auto_alloc_array(machine, UINT16, 0x2000);
164166
165   tilemap_set_transparent_pen(pf1_tilemap,0);
167   tilemap_set_transparent_pen(state->pf1_tilemap,0);
166168}
167169
168170/******************************************************************************/
src/mame/video/model1.c
r10427r10428
77
88#define LOG_TGP(x)   do { if (LOG_TGP_VIDEO) logerror x; } while (0)
99
10UINT16 *model1_display_list0, *model1_display_list1;
11UINT16 *model1_color_xlat;
12static UINT16 listctl[2];
13static UINT16 *glist;
1410
1511// Model 1 geometrizer TGP and rasterizer simulation
1612enum { FRAC_SHIFT = 16 };
13enum { MOIRE = 0x00010000 };
1714
18static int render_done;
19static UINT16 *tgp_ram;
20static float trans_mat[12];
21static UINT16 *paletteram16;
2215
23static float vxx, vyy, vzz, ayy, ayyc, ayys;
2416
2517struct vector {
2618   float x, y, z;
2719};
2820
29static struct {
21struct lightparam {
22   float a;
23   float d;
24   float s;
25   int p;
26};
27
28struct view {
3029   int xc, yc, x1, y1, x2, y2;
3130   float zoomx, zoomy, transx, transy;
3231   float a_bottom, a_top, a_left, a_right;
32   float vxx, vyy, vzz, ayy, ayyc, ayys;
33   float trans_mat[12];
3334   struct vector light;
34} view;
35   struct lightparam lightparams[32];
36};
3537
3638struct spoint {
3739   INT32 x, y;
r10427r10428
4345   struct spoint s;
4446};
4547
46static struct lightparam
47{
48   float a;
49   float d;
50   float s;
51   int p;
52} lightparams[32];
5348
54enum { MOIRE = 0x00010000 };
55
5649struct quad_m1 {
5750   struct point *p[4];
5851   float z;
5952   int col;
6053};
6154
62static struct point *pointdb, *pointpt;
63static struct quad_m1 *quaddb, *quadpt;
64static struct quad_m1 **quadind;
6555
66static UINT32 *poly_rom,*poly_ram;
6756
6857static UINT32 readi(const UINT16 *adr)
6958{
r10427r10428
8069   return u2f(readi(adr));
8170}
8271
83static void transform_point(struct point *p)
72static void transform_point(struct view *view, struct point *p)
8473{
8574   struct point q = *p;
75   float *trans = view->trans_mat;
8676   float xx, zz;
87   xx = trans_mat[0]*q.x+trans_mat[3]*q.y+trans_mat[6]*q.z+trans_mat[9]+vxx;
88   p->y = trans_mat[1]*q.x+trans_mat[4]*q.y+trans_mat[7]*q.z+trans_mat[10]+vyy;
89   zz = trans_mat[2]*q.x+trans_mat[5]*q.y+trans_mat[8]*q.z+trans_mat[11]+vzz;
90   p->x = ayyc*xx-ayys*zz;
91   p->z = ayys*xx+ayyc*zz;
77   xx = trans[0]*q.x+trans[3]*q.y+trans[6]*q.z+trans[9]+view->vxx;
78   p->y = trans[1]*q.x+trans[4]*q.y+trans[7]*q.z+trans[10]+view->vyy;
79   zz = trans[2]*q.x+trans[5]*q.y+trans[8]*q.z+trans[11]+view->vzz;
80   p->x = view->ayyc*xx-view->ayys*zz;
81   p->z = view->ayys*xx+view->ayyc*zz;
9282}
9383
94static void transform_vector(struct vector *p)
84static void transform_vector(struct view *view, struct vector *p)
9585{
9686   struct vector q = *p;
97   p->x = trans_mat[0]*q.x+trans_mat[3]*q.y+trans_mat[6]*q.z;
98   p->y = trans_mat[1]*q.x+trans_mat[4]*q.y+trans_mat[7]*q.z;
99   p->z = trans_mat[2]*q.x+trans_mat[5]*q.y+trans_mat[8]*q.z;
87   float *trans = view->trans_mat;
88   p->x = trans[0]*q.x+trans[3]*q.y+trans[6]*q.z;
89   p->y = trans[1]*q.x+trans[4]*q.y+trans[7]*q.z;
90   p->z = trans[2]*q.x+trans[5]*q.y+trans[8]*q.z;
10091}
10192
10293static void normalize_vector(struct vector *p)
r10427r10428
127118}
128119
129120
130static void project_point(struct point *p)
121static void project_point(struct view *view, struct point *p)
131122{
132123   p->xx = p->x / p->z;
133124   p->yy = p->y / p->z;
134   p->s.x = view.xc+(p->xx*view.zoomx+view.transx);
135   p->s.y = view.yc-(p->yy*view.zoomy+view.transy);
125   p->s.x = view->xc+(p->xx*view->zoomx+view->transx);
126   p->s.y = view->yc-(p->yy*view->zoomy+view->transy);
136127}
137128
138static void project_point_direct(struct point *p)
129static void project_point_direct(struct view *view, struct point *p)
139130{
140131   p->xx = p->x /*/ p->z*/;
141132   p->yy = p->y /*/ p->z*/;
142   p->s.x = view.xc+(p->xx);
143   p->s.y = view.yc-(p->yy);
133   p->s.x = view->xc+(p->xx);
134   p->s.y = view->yc-(p->yy);
144135}
145136
146137
r10427r10428
163154   }
164155}
165156
166static void fill_slope(bitmap_t *bitmap, int color, INT32 x1, INT32 x2, INT32 sl1, INT32 sl2, INT32 y1, INT32 y2, INT32 *nx1, INT32 *nx2)
157static void fill_slope(bitmap_t *bitmap, struct view *view, int color, INT32 x1, INT32 x2, INT32 sl1, INT32 sl2, INT32 y1, INT32 y2, INT32 *nx1, INT32 *nx2)
167158{
168   if(y1 > view.y2)
159   if(y1 > view->y2)
169160      return;
170161
171   if(y2 <= view.y1) {
162   if(y2 <= view->y1) {
172163      int delta = y2-y1;
173164      *nx1 = x1+delta*sl1;
174165      *nx2 = x2+delta*sl2;
175166      return;
176167   }
177168
178   if(y2 > view.y2)
179      y2 = view.y2+1;
169   if(y2 > view->y2)
170      y2 = view->y2+1;
180171
181   if(y1 < view.y1) {
182      int delta = view.y1 - y1;
172   if(y1 < view->y1) {
173      int delta = view->y1 - y1;
183174      x1 += delta*sl1;
184175      x2 += delta*sl2;
185      y1 = view.y1;
176      y1 = view->y1;
186177   }
187178
188179   if(x1 > x2 || (x1==x2 && sl1 > sl2)) {
r10427r10428
199190   }
200191
201192   while(y1 < y2) {
202      if(y1 >= view.y1) {
193      if(y1 >= view->y1) {
203194         int xx1 = x1>>FRAC_SHIFT;
204195         int xx2 = x2>>FRAC_SHIFT;
205         if(xx1 <= view.x2 || xx2 >= view.x1) {
206            if(xx1 < view.x1)
207               xx1 = view.x1;
208            if(xx2 > view.x2)
209               xx2 = view.x2;
196         if(xx1 <= view->x2 || xx2 >= view->x1) {
197            if(xx1 < view->x1)
198               xx1 = view->x1;
199            if(xx2 > view->x2)
200               xx2 = view->x2;
210201
211202            if(color & MOIRE)
212203               draw_hline_moired(bitmap, xx1, xx2, y1, color);
r10427r10428
223214   *nx2 = x2;
224215}
225216
226static void fill_line(bitmap_t *bitmap, int color, INT32 y, INT32 x1, INT32 x2)
217static void fill_line(bitmap_t *bitmap, struct view *view, int color, INT32 y, INT32 x1, INT32 x2)
227218{
228219   int xx1 = x1>>FRAC_SHIFT;
229220   int xx2 = x2>>FRAC_SHIFT;
230221
231   if(y > view.y2 || y < view.y1)
222   if(y > view->y2 || y < view->y1)
232223      return;
233224
234   if(xx1 <= view.x2 || xx2 >= view.x1) {
235      if(xx1 < view.x1)
236         xx1 = view.x1;
237      if(xx2 > view.x2)
238         xx2 = view.x2;
225   if(xx1 <= view->x2 || xx2 >= view->x1) {
226      if(xx1 < view->x1)
227         xx1 = view->x1;
228      if(xx2 > view->x2)
229         xx2 = view->x2;
239230
240231      if(color & MOIRE)
241232         draw_hline_moired(bitmap, xx1, xx2, y, color);
r10427r10428
244235   }
245236}
246237
247static void fill_quad(bitmap_t *bitmap, const struct quad_m1 *q)
238static void fill_quad(bitmap_t *bitmap, struct view *view, const struct quad_m1 *q)
248239{
249240   INT32 sl1, sl2, cury, limy, x1, x2;
250241   int pmin, pmax, i, ps1, ps2;
r10427r10428
284275         if(p[i].x > x2)
285276            x2 = p[i].x;
286277      }
287      fill_line(bitmap, color, cury, x1, x2);
278      fill_line(bitmap, view, color, cury, x1, x2);
288279      return;
289280   }
290281
291   if(cury > view.y2)
282   if(cury > view->y2)
292283      return;
293   if(limy <= view.y1)
284   if(limy <= view->y1)
294285      return;
295286
296   if(limy > view.y2)
297      limy = view.y2;
287   if(limy > view->y2)
288      limy = view->y2;
298289
299290   ps1 = pmin+4;
300291   ps2 = pmin;
r10427r10428
303294
304295   for(;;) {
305296      if(p[ps1-1].y == p[ps2+1].y) {
306         fill_slope(bitmap, color, x1, x2, sl1, sl2, cury, p[ps1-1].y, &x1, &x2);
297         fill_slope(bitmap, view, color, x1, x2, sl1, sl2, cury, p[ps1-1].y, &x1, &x2);
307298         cury = p[ps1-1].y;
308299         if(cury >= limy)
309300            break;
r10427r10428
320311         sl1 = (x1-p[ps1-1].x)/(cury-p[ps1-1].y);
321312         sl2 = (x2-p[ps2+1].x)/(cury-p[ps2+1].y);
322313      } else if(p[ps1-1].y < p[ps2+1].y) {
323         fill_slope(bitmap, color, x1, x2, sl1, sl2, cury, p[ps1-1].y, &x1, &x2);
314         fill_slope(bitmap, view, color, x1, x2, sl1, sl2, cury, p[ps1-1].y, &x1, &x2);
324315         cury = p[ps1-1].y;
325316         if(cury >= limy)
326317            break;
r10427r10428
330321         x1 = p[ps1].x;
331322         sl1 = (x1-p[ps1-1].x)/(cury-p[ps1-1].y);
332323      } else {
333         fill_slope(bitmap, color, x1, x2, sl1, sl2, cury, p[ps2+1].y, &x1, &x2);
324         fill_slope(bitmap, view, color, x1, x2, sl1, sl2, cury, p[ps2+1].y, &x1, &x2);
334325         cury = p[ps2+1].y;
335326         if(cury >= limy)
336327            break;
r10427r10428
342333      }
343334   }
344335   if(cury == limy)
345      fill_line(bitmap, color, cury, x1, x2);
336      fill_line(bitmap, view, color, cury, x1, x2);
346337}
347338#if 0
348static void draw_line(bitmap_t *bitmap, int color, int x1, int y1, int x2, int y2)
339static void draw_line(bitmap_t *bitmap, struct view *view, int color, int x1, int y1, int x2, int y2)
349340{
350341   int s1x, s1y, s2x, s2y;
351342   int d1, d2;
352343   int cur;
353344   int x, y;
354345
355   if((x1 < view.x1 && x2 < view.x1) ||
356      (x1 > view.x2 && x2 > view.x2) ||
357      (y1 < view.y1 && y2 < view.y1) ||
358      (y1 > view.y2 && y2 > view.y2))
346   if((x1 < view->x1 && x2 < view->x1) ||
347      (x1 > view->x2 && x2 > view->x2) ||
348      (y1 < view->y1 && y2 < view->y1) ||
349      (y1 > view->y2 && y2 > view->y2))
359350      return;
360351
361352   x = x1;
r10427r10428
393384
394385   cur = 0;
395386   while(x != x2 || y != y2) {
396      if(x>=view.x1 && x<=view.x2 && y>=view.y1 && y<=view.y2)
387      if(x>=view->x1 && x<=view->x2 && y>=view->y1 && y<=view->y2)
397388         *BITMAP_ADDR16(bitmap, y, x) = color;
398389      x += s1x;
399390      y += s1y;
r10427r10428
404395         y += s2y;
405396      }
406397   }
407   if(x>=view.x1 && x<=view.x2 && y>=view.y1 && y<=view.y2)
398   if(x>=view->x1 && x<=view->x2 && y>=view->y1 && y<=view->y2)
408399      *BITMAP_ADDR16(bitmap, y, x) = color;
409400}
410401#endif
r10427r10428
418409   if(z1>z2)
419410      return -1;
420411
421   if (*(const struct quad_m1 **)q1 - quaddb < *(const struct quad_m1 **)q2 - quaddb)
412   if (*(const struct quad_m1 **)q1 - *(const struct quad_m1 **)q2 < 0)
422413      return -1;
423414
424415   return +1;
425416}
426417
427static void sort_quads(void)
418static void sort_quads(model1_state *state)
428419{
429   int count = quadpt - quaddb;
420   int count = state->quadpt - state->quaddb;
430421   int i;
431422   for(i=0; i<count; i++)
432      quadind[i] = quaddb+i;
433   qsort(quadind, count, sizeof(struct quad_m1 *), comp_quads);
423      state->quadind[i] = state->quaddb+i;
424   qsort(state->quadind, count, sizeof(struct quad_m1 *), comp_quads);
434425}
435426
436static void unsort_quads(void)
427static void unsort_quads(model1_state *state)
437428{
438   int count = quadpt - quaddb;
429   int count = state->quadpt - state->quaddb;
439430   int i;
440431   for(i=0; i<count; i++)
441      quadind[i] = quaddb+i;
432      state->quadind[i] = state->quaddb+i;
442433}
443434
444435
445static void draw_quads(bitmap_t *bitmap, const rectangle *cliprect)
436static void draw_quads(model1_state *state, bitmap_t *bitmap, const rectangle *cliprect)
446437{
447   int count = quadpt - quaddb;
438   struct view *view = state->view;
439   int count = state->quadpt - state->quaddb;
448440   int i;
449441
450442   /* clip to the cliprect */
451   int save_x1 = view.x1;
452   int save_x2 = view.x2;
453   int save_y1 = view.y1;
454   int save_y2 = view.y2;
455   view.x1 = MAX(view.x1, cliprect->min_x);
456   view.x2 = MIN(view.x2, cliprect->max_x);
457   view.y1 = MAX(view.y1, cliprect->min_y);
458   view.y2 = MIN(view.y2, cliprect->max_y);
443   int save_x1 = view->x1;
444   int save_x2 = view->x2;
445   int save_y1 = view->y1;
446   int save_y2 = view->y2;
447   view->x1 = MAX(view->x1, cliprect->min_x);
448   view->x2 = MIN(view->x2, cliprect->max_x);
449   view->y1 = MAX(view->y1, cliprect->min_y);
450   view->y2 = MIN(view->y2, cliprect->max_y);
459451
460452   for(i=0; i<count; i++) {
461      struct quad_m1 *q = quadind[i];
453      struct quad_m1 *q = state->quadind[i];
462454
463      fill_quad(bitmap, q);
455      fill_quad(bitmap, view, q);
464456#if 0
465457      draw_line(bitmap, get_black_pen(screen->machine), q->p[0]->s.x, q->p[0]->s.y, q->p[1]->s.x, q->p[1]->s.y);
466458      draw_line(bitmap, get_black_pen(screen->machine), q->p[1]->s.x, q->p[1]->s.y, q->p[2]->s.x, q->p[2]->s.y);
r10427r10428
469461#endif
470462   }
471463
472   view.x1 = save_x1;
473   view.x2 = save_x2;
474   view.y1 = save_y1;
475   view.y2 = save_y2;
464   view->x1 = save_x1;
465   view->x2 = save_x2;
466   view->y1 = save_y1;
467   view->y2 = save_y2;
476468}
477469#if 0
478470static UINT16 scale_color(UINT16 color, float level)
r10427r10428
500492// => t*(x1-x2+a*(z2-z1) = -x2+a*z2
501493// => t = (z2*a-x2)/((z2-z1)*a-(x2-x1))
502494
503static void recompute_frustrum(void)
495static void recompute_frustrum(struct view *view)
504496{
505   view.a_left   = ( view.x1-view.xc-view.transx)/view.zoomx;
506   view.a_right  = ( view.x2-view.xc-view.transx)/view.zoomx;
507   view.a_bottom = (-view.y1+view.yc-view.transy)/view.zoomy;
508   view.a_top    = (-view.y2+view.yc-view.transy)/view.zoomy;
497   view->a_left   = ( view->x1-view->xc-view->transx)/view->zoomx;
498   view->a_right  = ( view->x2-view->xc-view->transx)/view->zoomx;
499   view->a_bottom = (-view->y1+view->yc-view->transy)/view->zoomy;
500   view->a_top    = (-view->y2+view->yc-view->transy)/view->zoomy;
509501}
510502
511static int fclip_isc_bottom(struct point *p)
503static int fclip_isc_bottom(struct view *view, struct point *p)
512504{
513   return p->y > p->z*view.a_bottom;
505   return p->y > p->z*view->a_bottom;
514506}
515507
516static struct point *fclip_clip_bottom(struct point *p1, struct point *p2)
508static void fclip_clip_bottom(struct view *view, struct point *pt, struct point *p1, struct point *p2)
517509{
518   float t = (p2->z*view.a_bottom-p2->y)/((p2->z-p1->z)*view.a_bottom-(p2->y-p1->y));
519   pointpt->x = p1->x*t + p2->x*(1-t);
520   pointpt->y = p1->y*t + p2->y*(1-t);
521   pointpt->z = p1->z*t + p2->z*(1-t);
522   project_point(pointpt);
523   return pointpt++;
510   float t = (p2->z*view->a_bottom-p2->y)/((p2->z-p1->z)*view->a_bottom-(p2->y-p1->y));
511   pt->x = p1->x*t + p2->x*(1-t);
512   pt->y = p1->y*t + p2->y*(1-t);
513   pt->z = p1->z*t + p2->z*(1-t);
514   project_point(view, pt);
524515}
525516
526static int fclip_isc_top(struct point *p)
517static int fclip_isc_top(struct view *view, struct point *p)
527518{
528   return p->y < p->z*view.a_top;
519   return p->y < p->z*view->a_top;
529520}
530521
531static struct point *fclip_clip_top(struct point *p1, struct point *p2)
522static void fclip_clip_top(struct view *view, struct point *pt, struct point *p1, struct point *p2)
532523{
533   float t = (p2->z*view.a_top-p2->y)/((p2->z-p1->z)*view.a_top-(p2->y-p1->y));
534   pointpt->x = p1->x*t + p2->x*(1-t);
535   pointpt->y = p1->y*t + p2->y*(1-t);
536   pointpt->z = p1->z*t + p2->z*(1-t);
537   project_point(pointpt);
538   return pointpt++;
524   float t = (p2->z*view->a_top-p2->y)/((p2->z-p1->z)*view->a_top-(p2->y-p1->y));
525   pt->x = p1->x*t + p2->x*(1-t);
526   pt->y = p1->y*t + p2->y*(1-t);
527   pt->z = p1->z*t + p2->z*(1-t);
528   project_point(view, pt);
539529}
540530
541static int fclip_isc_left(struct point *p)
531static int fclip_isc_left(struct view *view, struct point *p)
542532{
543   return p->x < p->z*view.a_left;
533   return p->x < p->z*view->a_left;
544534}
545535
546static struct point *fclip_clip_left(struct point *p1, struct point *p2)
536static void fclip_clip_left(struct view *view, struct point *pt, struct point *p1, struct point *p2)
547537{
548   float t = (p2->z*view.a_left-p2->x)/((p2->z-p1->z)*view.a_left-(p2->x-p1->x));
549   pointpt->x = p1->x*t + p2->x*(1-t);
550   pointpt->y = p1->y*t + p2->y*(1-t);
551   pointpt->z = p1->z*t + p2->z*(1-t);
552   project_point(pointpt);
553   return pointpt++;
538   float t = (p2->z*view->a_left-p2->x)/((p2->z-p1->z)*view->a_left-(p2->x-p1->x));
539   pt->x = p1->x*t + p2->x*(1-t);
540   pt->y = p1->y*t + p2->y*(1-t);
541   pt->z = p1->z*t + p2->z*(1-t);
542   project_point(view, pt);
554543}
555544
556static int fclip_isc_right(struct point *p)
545static int fclip_isc_right(struct view *view, struct point *p)
557546{
558   return p->x > p->z*view.a_right;
547   return p->x > p->z*view->a_right;
559548}
560549
561static struct point *fclip_clip_right(struct point *p1, struct point *p2)
550static void fclip_clip_right(struct view *view, struct point *pt, struct point *p1, struct point *p2)
562551{
563   float t = (p2->z*view.a_right-p2->x)/((p2->z-p1->z)*view.a_right-(p2->x-p1->x));
564   pointpt->x = p1->x*t + p2->x*(1-t);
565   pointpt->y = p1->y*t + p2->y*(1-t);
566   pointpt->z = p1->z*t + p2->z*(1-t);
567   project_point(pointpt);
568   return pointpt++;
552   float t = (p2->z*view->a_right-p2->x)/((p2->z-p1->z)*view->a_right-(p2->x-p1->x));
553   pt->x = p1->x*t + p2->x*(1-t);
554   pt->y = p1->y*t + p2->y*(1-t);
555   pt->z = p1->z*t + p2->z*(1-t);
556   project_point(view, pt);
569557}
570558
571559static const struct {
572   int (*isclipped)(struct point *p);
573   struct point *(*clip)(struct point *p1, struct point *p2);
560   int (*isclipped)(struct view *view, struct point *p);
561   void (*clip)(struct view *view, struct point *pt, struct point *p1, struct point *p2);
574562} clipfn[4] = {
575563   { fclip_isc_bottom, fclip_clip_bottom },
576564   { fclip_isc_top,    fclip_clip_top },
r10427r10428
578566   { fclip_isc_right,  fclip_clip_right },
579567};
580568
581static void fclip_push_quad(int level, struct quad_m1 *q);
569static void fclip_push_quad(model1_state *state, int level, struct quad_m1 *q);
582570
583static void fclip_push_quad_next(int level, struct quad_m1 *q,
571static void fclip_push_quad_next(model1_state *state, int level, struct quad_m1 *q,
584572                         struct point *p1, struct point *p2, struct point *p3, struct point *p4)
585573{
586574   struct quad_m1 q2;
r10427r10428
591579   q2.p[2] = p3;
592580   q2.p[3] = p4;
593581
594   fclip_push_quad(level+1, &q2);
582   fclip_push_quad(state, level+1, &q2);
595583}
596584
597static void fclip_push_quad(int level, struct quad_m1 *q)
585static void fclip_push_quad(model1_state *state, int level, struct quad_m1 *q)
598586{
587   struct view *view = state->view;
599588   int i, j;
600589   struct point *pt[4], *pi1, *pi2;
601590   int is_out[4], is_out2[4];
602   struct point *(*fclip_point)(struct point *p1, struct point *p2);
591   void (*fclip_point)(struct view *view, struct point *pt, struct point *p1, struct point *p2);
603592
604593   if(level == 4) {
605594      LOG_TGP(("VIDEOCQ %d", level));
606595      for(i=0; i<4; i++)
607596         LOG_TGP((" (%f, %f, %f)", q->p[i]->x, q->p[i]->y, q->p[i]->z));
608597      LOG_TGP(("\n"));
609      *quadpt = *q;
610      quadpt++;
598      *state->quadpt = *q;
599      state->quadpt++;
611600      return;
612601   }
613602
614603   for(i=0; i<4; i++)
615      is_out[i] = clipfn[level].isclipped(q->p[i]);
604      is_out[i] = clipfn[level].isclipped(view, q->p[i]);
616605
617606   LOG_TGP(("VIDEOCQ %d", level));
618607   for(i=0; i<4; i++)
r10427r10428
621610
622611   // No clipping
623612   if(!is_out[0] && !is_out[1] && !is_out[2] && !is_out[3]) {
624      fclip_push_quad(level+1, q);
613      fclip_push_quad(state, level+1, q);
625614      return;
626615   }
627616
r10427r10428
645634   if(is_out2[1])
646635      if(is_out2[2]) {
647636         // pt 0,1,2 clipped out, one triangle left
648         pi1 = fclip_point(pt[2], pt[3]);
649         pi2 = fclip_point(pt[3], pt[0]);
650         fclip_push_quad_next(level, q, pi1, pt[3], pi2, pi2);
637         fclip_point(view, state->pointpt, pt[2], pt[3]);
638         pi1 = state->pointpt++;
639         fclip_point(view, state->pointpt, pt[3], pt[0]);
640         pi2 = state->pointpt++;
641         fclip_push_quad_next(state, level, q, pi1, pt[3], pi2, pi2);
651642      } else {
652643         // pt 0,1 clipped out, one quad left
653         pi1 = fclip_point(pt[1], pt[2]);
654         pi2 = fclip_point(pt[3], pt[0]);
655         fclip_push_quad_next(level, q, pi1, pt[2], pt[3], pi2);
644         fclip_point(view, state->pointpt, pt[1], pt[2]);
645         pi1 = state->pointpt++;
646         fclip_point(view, state->pointpt, pt[3], pt[0]);
647         pi2 = state->pointpt++;
648         fclip_push_quad_next(state, level, q, pi1, pt[2], pt[3], pi2);
656649      }
657650   else
658651      if(is_out2[2]) {
659652         // pt 0,2 clipped out, shouldn't happen, two triangles
660         pi1 = fclip_point(pt[0], pt[1]);
661         pi2 = fclip_point(pt[1], pt[2]);
662         fclip_push_quad_next(level, q, pi1, pt[1], pi2, pi2);
663         pi1 = fclip_point(pt[2], pt[3]);
664         pi2 = fclip_point(pt[3], pt[0]);
665         fclip_push_quad_next(level, q, pi1, pt[3], pi2, pi2);
653         fclip_point(view, state->pointpt, pt[0], pt[1]);
654         pi1 = state->pointpt++;
655         fclip_point(view, state->pointpt, pt[1], pt[2]);
656         pi2 = state->pointpt++;
657         fclip_push_quad_next(state, level, q, pi1, pt[1], pi2, pi2);
658         fclip_point(view, state->pointpt, pt[2], pt[3]);
659         pi1 = state->pointpt++;
660         fclip_point(view, state->pointpt, pt[3], pt[0]);
661         pi2 = state->pointpt++;
662         fclip_push_quad_next(state, level, q, pi1, pt[3], pi2, pi2);
666663      } else {
667664         // pt 0 clipped out, one decagon left, split in quad+tri
668         pi1 = fclip_point(pt[0], pt[1]);
669         pi2 = fclip_point(pt[3], pt[0]);
670         fclip_push_quad_next(level, q, pi1, pt[1], pt[2], pt[3]);
671         fclip_push_quad_next(level, q, pt[3], pi2, pi1, pi1);
665         fclip_point(view, state->pointpt, pt[0], pt[1]);
666         pi1 = state->pointpt++;
667         fclip_point(view, state->pointpt, pt[3], pt[0]);
668         pi2 = state->pointpt++;
669         fclip_push_quad_next(state, level, q, pi1, pt[1], pt[2], pt[3]);
670         fclip_push_quad_next(state, level, q, pt[3], pi2, pi1, pi1);
672671      }
673672}
674673
r10427r10428
703702{
704703#if 0
705704   float s;
706   int p=lightparams[lmode].p&7;
705   int p=view->lightparams[lmode].p&7;
707706   int i;
708   float sv=lightparams[lmode].s;
707   float sv=view->lightparams[lmode].s;
709708
710709   //This is how it should be according to model2 geo program, but doesn't work fine
711710   s=2*(diffuse*normal->z-light->z);
r10427r10428
727726
728727static void push_object(running_machine *machine, UINT32 tex_adr, UINT32 poly_adr, UINT32 size)
729728{
729   model1_state *state = machine->driver_data<model1_state>();
730   struct view *view = state->view;
730731   int i;
731732   UINT32 flags;
732733   struct point *old_p0, *old_p1, *p0, *p1;
r10427r10428
741742   float *poly_data;
742743
743744   if(poly_adr & 0x800000)
744      poly_data=(float *) poly_ram;
745      poly_data=(float *) state->poly_ram;
745746   else
746      poly_data=(float *) poly_rom;
747      poly_data=(float *) state->poly_rom;
747748
748749   poly_adr &= 0x7fffff;
749750#if 0
r10427r10428
772773   if(!size)
773774      size = 0xffffffff;
774775
775   old_p0 = pointpt++;
776   old_p1 = pointpt++;
776   old_p0 = state->pointpt++;
777   old_p1 = state->pointpt++;
777778
778779   old_p0->x = poly_data[poly_adr+0];
779780   old_p0->y = poly_data[poly_adr+1];
r10427r10428
781782   old_p1->x = poly_data[poly_adr+3];
782783   old_p1->y = poly_data[poly_adr+4];
783784   old_p1->z = poly_data[poly_adr+5];
784   transform_point(old_p0);
785   transform_point(old_p1);
785   transform_point(view, old_p0);
786   transform_point(view, old_p1);
786787   if(old_p0->z > 0)
787      project_point(old_p0);
788      project_point(view, old_p0);
788789   else
789790      old_p0->s.x = old_p0->s.y = 0;
790791   if(old_p1->z > 0)
791      project_point(old_p1);
792      project_point(view, old_p1);
792793   else
793794      old_p1->s.x = old_p1->s.y = 0;
794795
r10427r10428
814815         tex_adr ++;
815816      lightmode=(flags>>17)&15;
816817
817      p0 = pointpt++;
818      p1 = pointpt++;
818      p0 = state->pointpt++;
819      p1 = state->pointpt++;
819820
820821      vn.x = poly_data[poly_adr+1];
821822      vn.y = poly_data[poly_adr+2];
r10427r10428
829830
830831      link = (flags >> 8) & 3;
831832
832      transform_vector(&vn);
833      transform_vector(view, &vn);
833834
834      transform_point(p0);
835      transform_point(p1);
835      transform_point(view, p0);
836      transform_point(view, p1);
836837      if(p0->z > 0)
837         project_point(p0);
838         project_point(view, p0);
838839      else
839840         p0->s.x = p0->s.y = 0;
840841      if(p1->z > 0)
841         project_point(p1);
842         project_point(view, p1);
842843      else
843844         p1->s.x = p1->s.y = 0;
844845
r10427r10428
892893      }
893894
894895      {
895         /*float dif=mult_vector(&vn, &view.light);
896            float ln=lightparams[lightmode].a + lightparams[lightmode].d*MAX(0.0,dif);
897            cquad.col = scale_color(machine->pens[0x1000|(tgp_ram[tex_adr-0x40000] & 0x3ff)], MIN(1.0,ln));
898            cquad.col = scale_color(machine->pens[0x1000|(tgp_ram[tex_adr-0x40000] & 0x3ff)], MIN(1.0,ln));
899            */
900         float dif=mult_vector(&vn, &view.light);
901         float spec=compute_specular(&vn,&view.light,dif,lightmode);
902         float ln=lightparams[lightmode].a + lightparams[lightmode].d*MAX(0.0,dif) + spec;
896#if 0
897         float dif=mult_vector(&vn, &view->light);
898         float ln=view->lightparams[lightmode].a + view->lightparams[lightmode].d*MAX(0.0,dif);
899         cquad.col = scale_color(machine->pens[0x1000|(state->tgp_ram[tex_adr-0x40000] & 0x3ff)], MIN(1.0,ln));
900         cquad.col = scale_color(machine->pens[0x1000|(state->tgp_ram[tex_adr-0x40000] & 0x3ff)], MIN(1.0,ln));
901#endif
902         float dif=mult_vector(&vn, &view->light);
903         float spec=compute_specular(&vn,&view->light,dif,lightmode);
904         float ln=view->lightparams[lightmode].a + view->lightparams[lightmode].d*MAX(0.0,dif) + spec;
903905         int lumval=255.0*MIN(1.0,ln);
904         int color=paletteram16[0x1000|(tgp_ram[tex_adr-0x40000] & 0x3ff)];
906         int color=state->paletteram16[0x1000|(state->tgp_ram[tex_adr-0x40000] & 0x3ff)];
905907         int r=(color>>0x0)&0x1f;
906908         int g=(color>>0x5)&0x1f;
907909         int b=(color>>0xA)&0x1f;
908910         lumval>>=2;   //there must be a luma translation table somewhere
909911         if(lumval>0x3f) lumval=0x3f;
910912         else if(lumval<0) lumval=0;
911         r=(model1_color_xlat[(r<<8)|lumval|0x0]>>3)&0x1f;
912         g=(model1_color_xlat[(g<<8)|lumval|0x2000]>>3)&0x1f;
913         b=(model1_color_xlat[(b<<8)|lumval|0x4000]>>3)&0x1f;
913         r=(state->color_xlat[(r<<8)|lumval|0x0]>>3)&0x1f;
914         g=(state->color_xlat[(g<<8)|lumval|0x2000]>>3)&0x1f;
915         b=(state->color_xlat[(b<<8)|lumval|0x4000]>>3)&0x1f;
914916         cquad.col=(r<<10)|(g<<5)|(b<<0);
915917      }
916918
917919      if(flags & 0x00002000)
918920         cquad.col |= MOIRE;
919921
920      fclip_push_quad(0, &cquad);
922      fclip_push_quad(state, 0, &cquad);
921923
922924   next:
923925      poly_adr += 10;
r10427r10428
937939   }
938940}
939941
940static UINT16 *push_direct(UINT16 *list)
942static UINT16 *push_direct(model1_state *state, UINT16 *list)
941943{
944   struct view *view = state->view;
942945   UINT32 flags;
943946   UINT32 tex_adr, lum, v1, v2;
944947   struct point *old_p0, *old_p1, *p0, *p1;
r10427r10428
950953   v1      = readi(list+2);
951954   v2      = readi(list+10);
952955
953   old_p0 = pointpt++;
954   old_p1 = pointpt++;
956   old_p0 = state->pointpt++;
957   old_p1 = state->pointpt++;
955958
956959   old_p0->x = readf(list+4);
957960   old_p0->y = readf(list+6);
r10427r10428
965968          old_p0->x, old_p0->y, old_p0->z,
966969          old_p1->x, old_p1->y, old_p1->z));
967970
968//  transform_point(old_p0);
969//  transform_point(old_p1);
971   //transform_point(view, old_p0);
972   //transform_point(view, old_p1);
970973   if(old_p0->z > 0)
971      project_point_direct(old_p0);
974      project_point_direct(view, old_p0);
972975   else
973976      old_p0->s.x = old_p0->s.y = 0;
974977   if(old_p1->z > 0)
975      project_point_direct(old_p1);
978      project_point_direct(view, old_p1);
976979   else
977980      old_p1->s.x = old_p1->s.y = 0;
978981
r10427r10428
992995      // list+4 is 0?
993996      // list+12 is z?
994997
995      p0 = pointpt++;
996      p1 = pointpt++;
998      p0 = state->pointpt++;
999      p1 = state->pointpt++;
9971000
9981001      lum   = readi(list+2);
9991002      v1    = readi(list+4);
r10427r10428
10251028
10261029      link = (flags >> 8) & 3;
10271030
1028//      transform_point(p0);
1029//      transform_point(p1);
1031      //transform_point(view, p0);
1032      //transform_point(view, p1);
10301033      if(p0->z > 0)
1031         project_point_direct(p0);
1034         project_point_direct(view, p0);
10321035      if(p1->z > 0)
1033         project_point_direct(p1);
1036         project_point_direct(view, p1);
10341037
10351038#if 1
10361039      if(old_p0 && old_p1)
r10427r10428
10581061      cquad.z    = z;
10591062      {
10601063         int lumval=((float) (lum>>24)) * 2.0;
1061         int color=paletteram16[0x1000|(tgp_ram[tex_adr-0x40000] & 0x3ff)];
1064         int color=state->paletteram16[0x1000|(state->tgp_ram[tex_adr-0x40000] & 0x3ff)];
10621065         int r=(color>>0x0)&0x1f;
10631066         int g=(color>>0x5)&0x1f;
10641067         int b=(color>>0xA)&0x1f;
10651068         lumval>>=2;   //there must be a luma translation table somewhere
10661069         if(lumval>0x3f) lumval=0x3f;
10671070         else if(lumval<0) lumval=0;
1068         r=(model1_color_xlat[(r<<8)|lumval|0x0]>>3)&0x1f;
1069         g=(model1_color_xlat[(g<<8)|lumval|0x2000]>>3)&0x1f;
1070         b=(model1_color_xlat[(b<<8)|lumval|0x4000]>>3)&0x1f;
1071         r=(state->color_xlat[(r<<8)|lumval|0x0]>>3)&0x1f;
1072         g=(state->color_xlat[(g<<8)|lumval|0x2000]>>3)&0x1f;
1073         b=(state->color_xlat[(b<<8)|lumval|0x4000]>>3)&0x1f;
10711074         cquad.col=(r<<10)|(g<<5)|(b<<0);
10721075      }
1073      //cquad.col  = scale_color(machine->pens[0x1000|(tgp_ram[tex_adr-0x40000] & 0x3ff)],((float) (lum>>24)) / 128.0);
1076      //cquad.col  = scale_color(machine->pens[0x1000|(state->tgp_ram[tex_adr-0x40000] & 0x3ff)],((float) (lum>>24)) / 128.0);
10741077      if(flags & 0x00002000)
10751078         cquad.col |= MOIRE;
10761079
1077      fclip_push_quad(0, &cquad);
1080      fclip_push_quad(state, 0, &cquad);
10781081
10791082   next:
10801083      switch(link) {
r10427r10428
11161119   return list+2;
11171120}
11181121
1119static void draw_objects(bitmap_t *bitmap, const rectangle *cliprect)
1122static void draw_objects(model1_state *state, bitmap_t *bitmap, const rectangle *cliprect)
11201123{
1121   if(quadpt != quaddb) {
1124   if(state->quadpt != state->quaddb) {
11221125      LOG_TGP(("VIDEO: sort&draw\n"));
1123      sort_quads();
1124      draw_quads(bitmap, cliprect);
1126      sort_quads(state);
1127      draw_quads(state, bitmap, cliprect);
11251128   }
11261129
1127   quadpt = quaddb;
1128   pointpt = pointdb;
1130   state->quadpt = state->quaddb;
1131   state->pointpt = state->pointdb;
11291132}
11301133
1131static UINT16 *draw_direct(UINT16 *list, bitmap_t *bitmap, const rectangle *cliprect)
1134static UINT16 *draw_direct(model1_state *state, bitmap_t *bitmap, const rectangle *cliprect, UINT16 *list)
11321135{
11331136   UINT16 *res;
11341137
11351138   LOG_TGP(("VIDEO:   draw direct %x\n", readi(list)));
11361139
1137   draw_objects(bitmap, cliprect);
1138   res = push_direct(list);
1139   unsort_quads();
1140   draw_quads(bitmap, cliprect);
1140   draw_objects(state, bitmap, cliprect);
1141   res = push_direct(state, list);
1142   unsort_quads(state);
1143   draw_quads(state, bitmap, cliprect);
11411144
1142   quadpt = quaddb;
1143   pointpt = pointdb;
1145   state->quadpt = state->quaddb;
1146   state->pointpt = state->pointdb;
11441147   return res;
11451148}
11461149
1147static UINT16 *get_list(void)
1150static UINT16 *get_list(model1_state *state)
11481151{
1149   if(!(listctl[0] & 4))
1150      listctl[0] = (listctl[0] & ~0x40) | (listctl[0] & 8 ? 0x40 : 0);
1151   return listctl[0] & 0x40 ? model1_display_list1 : model1_display_list0;
1152   if(!(state->listctl[0] & 4))
1153      state->listctl[0] = (state->listctl[0] & ~0x40) | (state->listctl[0] & 8 ? 0x40 : 0);
1154   return state->listctl[0] & 0x40 ? state->display_list1 : state->display_list0;
11521155}
11531156
1154static int get_list_number(void)
1157static int get_list_number(model1_state *state)
11551158{
1156   if(!(listctl[0] & 4))
1157      listctl[0] = (listctl[0] & ~0x40) | (listctl[0] & 8 ? 0x40 : 0);
1158   return listctl[0] & 0x40 ? 0 : 1;
1159   if(!(state->listctl[0] & 4))
1160      state->listctl[0] = (state->listctl[0] & ~0x40) | (state->listctl[0] & 8 ? 0x40 : 0);
1161   return state->listctl[0] & 0x40 ? 0 : 1;
11591162}
11601163
11611164static void end_frame(running_machine *machine)
11621165{
1163   if((listctl[0] & 4) && (machine->primary_screen->frame_number() & 1))
1164      listctl[0] ^= 0x40;
1166   model1_state *state = machine->driver_data<model1_state>();
1167   if((state->listctl[0] & 4) && (machine->primary_screen->frame_number() & 1))
1168      state->listctl[0] ^= 0x40;
11651169}
11661170
11671171READ16_HANDLER( model1_listctl_r )
11681172{
1173   model1_state *state = space->machine->driver_data<model1_state>();
11691174   if(!offset)
1170      return listctl[0] | 0x30;
1175      return state->listctl[0] | 0x30;
11711176   else
1172      return listctl[1];
1177      return state->listctl[1];
11731178}
11741179
11751180WRITE16_HANDLER( model1_listctl_w )
11761181{
1177   COMBINE_DATA(listctl+offset);
1178   LOG_TGP(("VIDEO: control=%08x\n", (listctl[1]<<16)|listctl[0]));
1182   model1_state *state = space->machine->driver_data<model1_state>();
1183   COMBINE_DATA(state->listctl+offset);
1184   LOG_TGP(("VIDEO: control=%08x\n", (state->listctl[1]<<16)|state->listctl[0]));
11791185}
11801186
11811187static void tgp_render(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect)
11821188{
1183   render_done = 1;
1184   if((listctl[1] & 0x1f) == 0x1f) {
1185      UINT16 *list = get_list();
1189   model1_state *state = machine->driver_data<model1_state>();
1190   struct view *view = state->view;
1191   state->render_done = 1;
1192   if((state->listctl[1] & 0x1f) == 0x1f) {
1193      UINT16 *list = get_list(state);
11861194      int zz = 0;
1187      LOG_TGP(("VIDEO: render list %d\n", get_list_number()));
1195      LOG_TGP(("VIDEO: render list %d\n", get_list_number(state)));
11881196
1189      memset(trans_mat, 0, sizeof(trans_mat));
1190      trans_mat[0] = 1.0;
1191      trans_mat[4] = 1.0;
1192      trans_mat[8] = 1.0;
1197      memset(view->trans_mat, 0, sizeof(view->trans_mat));
1198      view->trans_mat[0] = 1.0;
1199      view->trans_mat[4] = 1.0;
1200      view->trans_mat[8] = 1.0;
11931201
11941202      for(;;) {
11951203         int type = (list[1]<<16)|list[0];
1196         glist=list;
1204         state->glist=list;
11971205         switch(type & 15) {
11981206         case 0:
11991207            list += 2;
r10427r10428
12111219            list += 8;
12121220            break;
12131221         case 2:
1214            list = draw_direct(list+2, bitmap, cliprect);
1222            list = draw_direct(state, bitmap, cliprect, list+2);
12151223            break;
12161224         case 3:
12171225            LOG_TGP(("VIDEO:   viewport (%d, %d, %d, %d, %d, %d, %d)\n",
r10427r10428
12191227                   readi16(list+4), readi16(list+6), readi16(list+8),
12201228                   readi16(list+10), readi16(list+12), readi16(list+14)));
12211229
1222            draw_objects(bitmap, cliprect);
1230            draw_objects(state, bitmap, cliprect);
12231231
1224            view.xc = readi16(list+4);
1225            view.yc = 383-(readi16(list+6)-39);
1226            view.x1 = readi16(list+8);
1227            view.y2 = 383-(readi16(list+10)-39);
1228            view.x2 = readi16(list+12);
1229            view.y1 = 383-(readi16(list+14)-39);
1232            view->xc = readi16(list+4);
1233            view->yc = 383-(readi16(list+6)-39);
1234            view->x1 = readi16(list+8);
1235            view->y2 = 383-(readi16(list+10)-39);
1236            view->x2 = readi16(list+12);
1237            view->y1 = 383-(readi16(list+14)-39);
12301238
1231            recompute_frustrum();
1239            recompute_frustrum(view);
12321240
12331241            list += 16;
12341242            break;
r10427r10428
12381246            int i;
12391247            LOG_TGP(("ZVIDEO:   color write, adr=%x, len=%x\n", adr, len));
12401248            for(i=0; i<len; i++)
1241               tgp_ram[adr-0x40000+i] = list[6+2*i];
1249               state->tgp_ram[adr-0x40000+i] = list[6+2*i];
12421250            list += 6+len*2;
12431251            break;
12441252         }
r10427r10428
12491257               int i;
12501258               for(i=0;i<len;++i)
12511259               {
1252                  poly_ram[adr-0x800000+i]=readi(list+2*i+6);
1260                  state->poly_ram[adr-0x800000+i]=readi(list+2*i+6);
12531261               }
12541262               list+=6+len*2;
12551263            }
r10427r10428
12621270            for(i=0;i<len;++i)
12631271            {
12641272               int v=readi(list+6+i*2);
1265               lightparams[i+adr].d=((float) (v&0xff))/255.0;
1266               lightparams[i+adr].a=((float) ((v>>8)&0xff))/255.0;
1267               lightparams[i+adr].s=((float) ((v>>16)&0xff))/255.0;
1268               lightparams[i+adr].p=(v>>24)&0xff;
1273               view->lightparams[i+adr].d=((float) (v&0xff))/255.0;
1274               view->lightparams[i+adr].a=((float) ((v>>8)&0xff))/255.0;
1275               view->lightparams[i+adr].s=((float) ((v>>16)&0xff))/255.0;
1276               view->lightparams[i+adr].p=(v>>24)&0xff;
12691277            }
12701278            list += 6+len*2;
12711279            break;
r10427r10428
12811289            break;
12821290         case 9:
12831291            LOG_TGP(("VIDEO:   zoom (%f, %f)\n", readf(list+2), readf(list+4)));
1284            view.zoomx = readf(list+2)*4;
1285            view.zoomy = readf(list+4)*4;
1292            view->zoomx = readf(list+2)*4;
1293            view->zoomy = readf(list+4)*4;
12861294
1287            recompute_frustrum();
1295            recompute_frustrum(view);
12881296
12891297            list += 6;
12901298            break;
12911299         case 0xa:
12921300            LOG_TGP(("VIDEO:   light vector (%f, %f, %f)\n", readf(list+2), readf(list+4), readf(list+6)));
1293            view.light.x = readf(list+2);
1294            view.light.y = readf(list+4);
1295            view.light.z = readf(list+6);
1296            normalize_vector(&view.light);
1301            view->light.x = readf(list+2);
1302            view->light.y = readf(list+4);
1303            view->light.z = readf(list+6);
1304            normalize_vector(&view->light);
12971305            list += 8;
12981306            break;
12991307         case 0xb: {
r10427r10428
13041312                   readf(list+14), readf(list+16), readf(list+18),
13051313                   readf(list+20), readf(list+22), readf(list+24)));
13061314            for(i=0; i<12; i++)
1307               trans_mat[i] = readf(list+2+2*i);
1315               view->trans_mat[i] = readf(list+2+2*i);
13081316            list += 26;
13091317            break;
13101318         }
13111319         case 0xc:
13121320            LOG_TGP(("VIDEO:   trans (%f, %f)\n", readf(list+2), readf(list+4)));
1313            view.transx = readf(list+2);
1314            view.transy = readf(list+4);
1321            view->transx = readf(list+2);
1322            view->transy = readf(list+4);
13151323
1316            recompute_frustrum();
1324            recompute_frustrum(view);
13171325
13181326            list += 6;
13191327            break;
r10427r10428
13261334         }
13271335      }
13281336   end:
1329      draw_objects(bitmap, cliprect);
1337      draw_objects(state, bitmap, cliprect);
13301338   }
13311339}
13321340
1333static void tgp_scan(void)
1341static void tgp_scan(running_machine *machine)
13341342{
1343   model1_state *state = machine->driver_data<model1_state>();
1344   struct view *view = state->view;
13351345#if 0
13361346   if (input_code_pressed_once(machine, KEYCODE_F))
13371347        {
1338         FILE *fp;
1339         fp=fopen("tgp-ram.bin", "w+b");
1340         if (fp)
1348      FILE *fp;
1349      fp=fopen("tgp-ram.bin", "w+b");
1350      if (fp)
13411351                {
1342               fwrite(tgp_ram, (0x100000-0x40000)*2, 1, fp);
1343               fclose(fp);
1352         fwrite(state->tgp_ram, (0x100000-0x40000)*2, 1, fp);
1353         fclose(fp);
13441354                }
1345         exit(0);
1355      exit(0);
13461356        }
13471357#endif
1348   if(!render_done && (listctl[1] & 0x1f) == 0x1f) {
1349      UINT16 *list = get_list();
1358   if(!state->render_done && (state->listctl[1] & 0x1f) == 0x1f) {
1359      UINT16 *list = get_list(state);
13501360      // Skip everything but the data uploads
1351      LOG_TGP(("VIDEO: scan list %d\n", get_list_number()));
1361      LOG_TGP(("VIDEO: scan list %d\n", get_list_number(state)));
13521362      for(;;) {
13531363         int type = (list[1]<<16)|list[0];
13541364         switch(type) {
r10427r10428
13701380            int i;
13711381            LOG_TGP(("ZVIDEO:   scan color write, adr=%x, len=%x\n", adr, len));
13721382            for(i=0; i<len; i++)
1373               tgp_ram[adr-0x40000+i] = list[6+2*i];
1383               state->tgp_ram[adr-0x40000+i] = list[6+2*i];
13741384            list += 6+len*2;
13751385            break;
13761386         }
r10427r10428
13811391               int i;
13821392               for(i=0;i<len;++i)
13831393               {
1384                  poly_ram[adr-0x800000+i]=readi(list+2*i+6);
1394                  state->poly_ram[adr-0x800000+i]=readi(list+2*i+6);
13851395               }
13861396               list+=6+len*2;
13871397            }
r10427r10428
13941404            for(i=0;i<len;++i)
13951405            {
13961406               int v=readi(list+6+i*2);
1397               lightparams[i+adr].d=((float) (v&0xff))/255.0;
1398               lightparams[i+adr].a=((float) ((v>>8)&0xff))/255.0;
1399               lightparams[i+adr].s=((float) ((v>>16)&0xff))/255.0;
1400               lightparams[i+adr].p=(v>>24)&0xff;
1407               view->lightparams[i+adr].d=((float) (v&0xff))/255.0;
1408               view->lightparams[i+adr].a=((float) ((v>>8)&0xff))/255.0;
1409               view->lightparams[i+adr].s=((float) ((v>>16)&0xff))/255.0;
1410               view->lightparams[i+adr].p=(v>>24)&0xff;
14011411               //LOG_TGP(("         %02X\n",v));
14021412            }
14031413            list += 6+len*2;
r10427r10428
14321442   end:
14331443      ;
14341444   }
1435   render_done = 0;
1445   state->render_done = 0;
14361446}
14371447
14381448VIDEO_START(model1)
14391449{
1440   paletteram16 = machine->generic.paletteram.u16;
1450   model1_state *state = machine->driver_data<model1_state>();
1451   state->paletteram16 = machine->generic.paletteram.u16;
14411452
1442   vxx=vyy=vzz=0;
1443   ayy = 0;
1453   state->view = auto_alloc_clear(machine, struct view);
14441454
14451455   sys24_tile_vh_start(machine, 0x3fff);
14461456
1447   poly_rom = (UINT32 *)machine->region("user1")->base();
1448   poly_ram = auto_alloc_array_clear(machine, UINT32, 0x400000);
1449   tgp_ram = auto_alloc_array_clear(machine, UINT16, 0x100000-0x40000);
1450   pointdb = auto_alloc_array_clear(machine, struct point, 1000000*2);
1451   quaddb  = auto_alloc_array_clear(machine, struct quad_m1, 1000000);
1452   quadind = auto_alloc_array_clear(machine, struct quad_m1 *, 1000000);
1457   state->poly_rom = (UINT32 *)machine->region("user1")->base();
1458   state->poly_ram = auto_alloc_array_clear(machine, UINT32, 0x400000);
1459   state->tgp_ram = auto_alloc_array_clear(machine, UINT16, 0x100000-0x40000);
1460   state->pointdb = auto_alloc_array_clear(machine, struct point, 1000000*2);
1461   state->quaddb  = auto_alloc_array_clear(machine, struct quad_m1, 1000000);
1462   state->quadind = auto_alloc_array_clear(machine, struct quad_m1 *, 1000000);
14531463
1454   pointpt = pointdb;
1455   quadpt = quaddb;
1456   listctl[0] = listctl[1] = 0;
1464   state->pointpt = state->pointdb;
1465   state->quadpt = state->quaddb;
1466   state->listctl[0] = state->listctl[1] = 0;
14571467
1458   state_save_register_global_pointer(machine, tgp_ram, 0x100000-0x40000);
1459   state_save_register_global_pointer(machine, poly_ram, 0x40000);
1460   state_save_register_global_array(machine, listctl);
1468   state_save_register_global_pointer(machine, state->tgp_ram, 0x100000-0x40000);
1469   state_save_register_global_pointer(machine, state->poly_ram, 0x40000);
1470   state_save_register_global_array(machine, state->listctl);
14611471}
14621472
14631473VIDEO_UPDATE(model1)
14641474{
1475   model1_state *state = screen->machine->driver_data<model1_state>();
1476   struct view *view = state->view;
14651477#if 0
14661478   {
14671479      int mod = 0;
r10427r10428
14701482
14711483      if(input_code_pressed(screen->machine, KEYCODE_F)) {
14721484         mod = 1;
1473         vxx -= delta;
1485         view->vxx -= delta;
14741486      }
14751487      if(input_code_pressed(screen->machine, KEYCODE_G)) {
14761488         mod = 1;
1477         vxx += delta;
1489         view->vxx += delta;
14781490      }
14791491      if(input_code_pressed(screen->machine, KEYCODE_H)) {
14801492         mod = 1;
1481         vyy -= delta;
1493         view->vyy -= delta;
14821494      }
14831495      if(input_code_pressed(screen->machine, KEYCODE_J)) {
14841496         mod = 1;
1485         vyy += delta;
1497         view->vyy += delta;
14861498      }
14871499      if(input_code_pressed(screen->machine, KEYCODE_K)) {
14881500         mod = 1;
1489         vzz -= delta;
1501         view->vzz -= delta;
14901502      }
14911503      if(input_code_pressed(screen->machine, KEYCODE_L)) {
14921504         mod = 1;
1493         vzz += delta;
1505         view->vzz += delta;
14941506      }
14951507      if(input_code_pressed(screen->machine, KEYCODE_U)) {
14961508         mod = 1;
1497         ayy -= 0.05;
1509         view->ayy -= 0.05;
14981510      }
14991511      if(input_code_pressed(screen->machine, KEYCODE_I)) {
15001512         mod = 1;
1501         ayy += 0.05;
1513         view->ayy += 0.05;
15021514      }
15031515      if(mod)
1504         popmessage("%g,%g,%g:%g", vxx, vyy, vzz, ayy);
1516         popmessage("%g,%g,%g:%g", view->vxx, view->vyy, view->vzz, view->ayy);
15051517   }
15061518#endif
15071519
1508   ayyc = cos(ayy);
1509   ayys = sin(ayy);
1520   view->ayyc = cos(view->ayy);
1521   view->ayys = sin(view->ayy);
15101522
15111523   bitmap_fill(screen->machine->priority_bitmap, NULL, 0);
15121524   bitmap_fill(bitmap, cliprect, screen->machine->pens[0]);
r10427r10428
15281540
15291541VIDEO_EOF(model1)
15301542{
1531   tgp_scan();
1543   tgp_scan(machine);
15321544   end_frame(machine);
15331545   LOG_TGP(("TGP: vsync\n"));
15341546}
src/mame/video/qdrmfgp.c
r10427r10428
1212
1313void qdrmfgp_tile_callback(running_machine *machine, int layer, int *code, int *color, int *flags)
1414{
15   *color = ((*color>>2) & 0x0f) | qdrmfgp_get_palette();
15   qdrmfgp_state *state = machine->driver_data<qdrmfgp_state>();
16   *color = ((*color>>2) & 0x0f) | state->pal;
1617}
1718
1819void qdrmfgp2_tile_callback(running_machine *machine, int layer, int *code, int *color, int *flags)
src/mame/video/model2.c
r10427r10428
9292
9393#define DEBUG 0
9494
95static poly_manager *poly;
9695
9796#define pz      p[0]
9897#define pu      p[1]
r10427r10428
141140typedef struct _poly_extra_data poly_extra_data;
142141struct _poly_extra_data
143142{
143   model2_state *   state;
144144   UINT32      lumabase;
145145   UINT32      colorbase;
146146   UINT32 *   texsheet;
r10427r10428
292292
293293/*******************************************
294294 *
295 *  Hardware 3D Rasterizer Interal State
295 *  Hardware 3D Rasterizer Internal State
296296 *
297297 *******************************************/
298298
299299#define MAX_TRIANGLES      32768
300300
301typedef struct
301struct _raster_state
302302{
303303   UINT32            mode;            /* bit 0 = Test Mode, bit 2 = Switch 60Hz(1)/30Hz(0) operation */
304304   UINT16 *         texture_rom;      /* Texture ROM pointer */
305   UINT16 *         texture_ram;      /* Texture RAM pointer */
306   UINT8 *            log_ram;         /* Log RAM pointer */
307305   INT16            viewport[4];      /* View port (startx,starty,endx,endy) */
308306   INT16            center[4][2];      /* Centers (eye 0[x,y],1[x,y],2[x,y],3[x,y]) */
309307   UINT16            center_sel;         /* Selected center */
r10427r10428
314312   UINT32            cur_command;      /* Current command */
315313   UINT32            command_buffer[32];   /* Command buffer */
316314   UINT32            command_index;      /* Command buffer index */
317   triangle *         tri_list;         /* Triangle list */
315   triangle         tri_list[MAX_TRIANGLES];         /* Triangle list */
318316   UINT32            tri_list_index;      /* Triangle list index */
319   triangle **         tri_sorted_list;   /* Sorted Triangle list */
317   triangle *         tri_sorted_list[0x10000];   /* Sorted Triangle list */
320318   UINT16            min_z;            /* Minimum sortable Z value */
321319   UINT16            max_z;            /* Maximum sortable Z value */
320   UINT16         texture_ram[0x10000];      /* Texture RAM pointer */
321   UINT8            log_ram[0x40000];         /* Log RAM pointer */
322};
322323
323} raster_state;
324324
325static raster_state raster;
326
327325/*******************************************
328326 *
329327 *  Hardware 3D Rasterizer Initialization
r10427r10428
332330
333331static void model2_3d_init( running_machine *machine, UINT16 *texture_rom )
334332{
335   memset( &raster, 0, sizeof( raster_state ) );
333   model2_state *state = machine->driver_data<model2_state>();
336334
337   raster.texture_rom = texture_rom;
338   raster.texture_ram = auto_alloc_array(machine, UINT16, 0x10000);
339   raster.log_ram = auto_alloc_array(machine, UINT8, 0x40000);
340   raster.tri_list = auto_alloc_array(machine, triangle, MAX_TRIANGLES);
341   raster.tri_sorted_list = auto_alloc_array(machine, triangle *, 0x10000);
335   state->raster = auto_alloc_clear( machine, raster_state );
336
337   state->raster->texture_rom = texture_rom;
342338}
343339
344340/*******************************************
r10427r10428
347343 *
348344 *******************************************/
349345
350void model2_3d_set_zclip( UINT8 clip )
346void model2_3d_set_zclip( running_machine *machine, UINT8 clip )
351347{
352   raster.master_z_clip = clip;
348   model2_state *state = machine->driver_data<model2_state>();
349   state->raster->master_z_clip = clip;
353350}
354351
355352/*******************************************
r10427r10428
358355 *
359356 *******************************************/
360357
361static void model2_3d_process_quad( UINT32 attr )
358static void model2_3d_process_quad( raster_state *raster, UINT32 attr )
362359{
363360   _quad_m2   object;
364361   UINT16      *th, *tp;
r10427r10428
368365   float      min_z, max_z;
369366
370367   /* extract P0(n-1) */
371   object.v[1].x = u2f( raster.command_buffer[2] << 8 );
372   object.v[1].y = u2f( raster.command_buffer[3] << 8 );
373   object.v[1].pz = u2f( raster.command_buffer[4] << 8 );
368   object.v[1].x = u2f( raster->command_buffer[2] << 8 );
369   object.v[1].y = u2f( raster->command_buffer[3] << 8 );
370   object.v[1].pz = u2f( raster->command_buffer[4] << 8 );
374371
375372   /* extract P1(n-1) */
376   object.v[0].x = u2f( raster.command_buffer[5] << 8 );
377   object.v[0].y = u2f( raster.command_buffer[6] << 8 );
378   object.v[0].pz = u2f( raster.command_buffer[7] << 8 );
373   object.v[0].x = u2f( raster->command_buffer[5] << 8 );
374   object.v[0].y = u2f( raster->command_buffer[6] << 8 );
375   object.v[0].pz = u2f( raster->command_buffer[7] << 8 );
379376
380377   /* extract P0(n) */
381   object.v[2].x = u2f( raster.command_buffer[11] << 8 );
382   object.v[2].y = u2f( raster.command_buffer[12] << 8 );
383   object.v[2].pz = u2f( raster.command_buffer[13] << 8 );
378   object.v[2].x = u2f( raster->command_buffer[11] << 8 );
379   object.v[2].y = u2f( raster->command_buffer[12] << 8 );
380   object.v[2].pz = u2f( raster->command_buffer[13] << 8 );
384381
385382   /* extract P1(n) */
386   object.v[3].x = u2f( raster.command_buffer[14] << 8 );
387   object.v[3].y = u2f( raster.command_buffer[15] << 8 );
388   object.v[3].pz = u2f( raster.command_buffer[16] << 8 );
383   object.v[3].x = u2f( raster->command_buffer[14] << 8 );
384   object.v[3].y = u2f( raster->command_buffer[15] << 8 );
385   object.v[3].pz = u2f( raster->command_buffer[16] << 8 );
389386
390387   /* always calculate the min z and max z value */
391388   min_z = object.v[0].pz;
r10427r10428
401398   /* read in the texture information */
402399
403400   /* texture point data */
404   if ( raster.command_buffer[0] & 0x800000 )
405      tp = &raster.texture_ram[raster.command_buffer[0] & 0xFFFF];
401   if ( raster->command_buffer[0] & 0x800000 )
402      tp = &raster->texture_ram[raster->command_buffer[0] & 0xFFFF];
406403   else
407      tp = &raster.texture_rom[raster.command_buffer[0] & 0x7FFFFF];
404      tp = &raster->texture_rom[raster->command_buffer[0] & 0x7FFFFF];
408405
409406   object.v[0].pv = *tp++;
410407   object.v[0].pu = *tp++;
r10427r10428
416413   object.v[3].pu = *tp++;
417414
418415   /* update the address */
419   raster.command_buffer[0] += 8;
416   raster->command_buffer[0] += 8;
420417
421418   /* texture header data */
422   if ( raster.command_buffer[1] & 0x800000 )
423      th = &raster.texture_ram[raster.command_buffer[1] & 0xFFFF];
419   if ( raster->command_buffer[1] & 0x800000 )
420      th = &raster->texture_ram[raster->command_buffer[1] & 0xFFFF];
424421   else
425      th = &raster.texture_rom[raster.command_buffer[1] & 0x7FFFFF];
422      th = &raster->texture_rom[raster->command_buffer[1] & 0x7FFFFF];
426423
427424   object.texheader[0] = *th++;
428425   object.texheader[1] = *th++;
r10427r10428
437434      tho |= -16;
438435
439436   /* update the address */
440   raster.command_buffer[1] += tho * 4;
437   raster->command_buffer[1] += tho * 4;
441438
442439   /* set the luma value of this quad */
443   object.luma = (raster.command_buffer[9] >> 15) & 0xFF;
440   object.luma = (raster->command_buffer[9] >> 15) & 0xFF;
444441
445442   /* determine wether we can cull this quad */
446443   cull = 0;
r10427r10428
449446   if ( ((attr >> 17) & 1) == 0 )
450447   {
451448      /* if it's the backface, cull it */
452      if ( raster.command_buffer[9] & 0x00800000 )
449      if ( raster->command_buffer[9] & 0x00800000 )
453450         cull = 1;
454451   }
455452
r10427r10428
458455      cull = 1;
459456
460457   /* if the minimum z value is bigger than the master z clip value, don't render */
461   if ( (INT32)(1.0/min_z) > raster.master_z_clip )
458   if ( (INT32)(1.0/min_z) > raster->master_z_clip )
462459      cull = 1;
463460
464461   /* if the maximum z value is < 0 then we can safely clip the entire polygon */
r10427r10428
466463      cull = 1;
467464
468465   /* set the object's z value */
469   zvalue = raster.triangle_z;
466   zvalue = raster->triangle_z;
470467
471468   /* see if we need to recompute min/max z */
472469   if ( (attr >> 10) & 3 )
r10427r10428
480477         zvalue = max_z;
481478      }
482479
483      raster.triangle_z = zvalue;
480      raster->triangle_z = zvalue;
484481   }
485482
486483   if ( cull == 0 )
r10427r10428
502499         triangle *ztri;
503500
504501         /* adjust and set the object z-sort value */
505         object.z = float_to_zval( zvalue + raster.z_adjust );
502         object.z = float_to_zval( zvalue + raster->z_adjust );
506503
507504         /* get our list read to add the triangles */
508         ztri = raster.tri_sorted_list[object.z];
505         ztri = raster->tri_sorted_list[object.z];
509506
510507         if ( ztri != NULL )
511508         {
r10427r10428
518515         {
519516            triangle   *tri;
520517
521            tri = &raster.tri_list[raster.tri_list_index++];
518            tri = &raster->tri_list[raster->tri_list_index++];
522519
523            if ( raster.tri_list_index >= MAX_TRIANGLES )
520            if ( raster->tri_list_index >= MAX_TRIANGLES )
524521            {
525522               fatalerror( "SEGA 3D: Max triangle limit exceeded\n" );
526523            }
r10427r10428
534531            tri->luma = object.luma;
535532
536533            /* set the viewport */
537            tri->viewport[0] = raster.viewport[0];
538            tri->viewport[1] = raster.viewport[1];
539            tri->viewport[2] = raster.viewport[2];
540            tri->viewport[3] = raster.viewport[3];
534            tri->viewport[0] = raster->viewport[0];
535            tri->viewport[1] = raster->viewport[1];
536            tri->viewport[2] = raster->viewport[2];
537            tri->viewport[3] = raster->viewport[3];
541538
542539            /* set the center */
543            tri->center[0] = raster.center[raster.center_sel][0];
544            tri->center[1] = raster.center[raster.center_sel][1];
540            tri->center[0] = raster->center[raster->center_sel][0];
541            tri->center[1] = raster->center[raster->center_sel][1];
545542
546543            memcpy( &tri->v[0], &verts[0], sizeof( poly_vertex ) );
547544            memcpy( &tri->v[1], &verts[i-1], sizeof( poly_vertex ) );
r10427r10428
552549
553550            if ( ztri == NULL )
554551            {
555               raster.tri_sorted_list[object.z] = tri;
552               raster->tri_sorted_list[object.z] = tri;
556553            }
557554            else
558555            {
r10427r10428
563560         }
564561
565562         /* keep around the min and max z values for this frame */
566         if ( object.z < raster.min_z ) raster.min_z = object.z;
567         if ( object.z > raster.max_z ) raster.max_z = object.z;
563         if ( object.z < raster->min_z ) raster->min_z = object.z;
564         if ( object.z > raster->max_z ) raster->max_z = object.z;
568565      }
569566   }
570567
r10427r10428
576573      {
577574         /* reuse P0(n) and P1(n) */
578575         for( i = 0; i < 6; i++ )                              /* P0(n) -> P0(n-1) */
579            raster.command_buffer[2+i] = raster.command_buffer[11+i];   /* P1(n) -> P1(n-1) */
576            raster->command_buffer[2+i] = raster->command_buffer[11+i];   /* P1(n) -> P1(n-1) */
580577      }
581578      break;
582579
r10427r10428
584581      {
585582         /* reuse P0(n-1) and P0(n) */
586583         for( i = 0; i < 3; i++ )
587            raster.command_buffer[5+i] = raster.command_buffer[11+i];   /* P0(n) -> P1(n-1) */
584            raster->command_buffer[5+i] = raster->command_buffer[11+i];   /* P0(n) -> P1(n-1) */
588585      }
589586      break;
590587
r10427r10428
592589      {
593590         /* reuse P1(n-1) and P1(n) */
594591         for( i = 0; i < 3; i++ )
595            raster.command_buffer[2+i] = raster.command_buffer[14+i];   /* P1(n) -> P1(n-1) */
592            raster->command_buffer[2+i] = raster->command_buffer[14+i];   /* P1(n) -> P1(n-1) */
596593      }
597594      break;
598595   }
599596}
600597
601static void model2_3d_process_triangle( UINT32 attr )
598static void model2_3d_process_triangle( raster_state *raster, UINT32 attr )
602599{
603600   triangle   object;
604601   UINT16      *th, *tp;
r10427r10428
608605   float      min_z, max_z;
609606
610607   /* extract P0(n-1) */
611   object.v[1].x = u2f( raster.command_buffer[2] << 8 );
612   object.v[1].y = u2f( raster.command_buffer[3] << 8 );
613   object.v[1].pz = u2f( raster.command_buffer[4] << 8 );
608   object.v[1].x = u2f( raster->command_buffer[2] << 8 );
609   object.v[1].y = u2f( raster->command_buffer[3] << 8 );
610   object.v[1].pz = u2f( raster->command_buffer[4] << 8 );
614611
615612   /* extract P1(n-1) */
616   object.v[0].x = u2f( raster.command_buffer[5] << 8 );
617   object.v[0].y = u2f( raster.command_buffer[6] << 8 );
618   object.v[0].pz = u2f( raster.command_buffer[7] << 8 );
613   object.v[0].x = u2f( raster->command_buffer[5] << 8 );
614   object.v[0].y = u2f( raster->command_buffer[6] << 8 );
615   object.v[0].pz = u2f( raster->command_buffer[7] << 8 );
619616
620617   /* extract P0(n) */
621   object.v[2].x = u2f( raster.command_buffer[11] << 8 );
622   object.v[2].y = u2f( raster.command_buffer[12] << 8 );
623   object.v[2].pz = u2f( raster.command_buffer[13] << 8 );
618   object.v[2].x = u2f( raster->command_buffer[11] << 8 );
619   object.v[2].y = u2f( raster->command_buffer[12] << 8 );
620   object.v[2].pz = u2f( raster->command_buffer[13] << 8 );
624621
625622   /* for triangles, the rope of P1(n) is achieved by P0(n-1) (linktype 3) */
626   raster.command_buffer[14] = raster.command_buffer[11];
627   raster.command_buffer[15] = raster.command_buffer[12];
628   raster.command_buffer[16] = raster.command_buffer[13];
623   raster->command_buffer[14] = raster->command_buffer[11];
624   raster->command_buffer[15] = raster->command_buffer[12];
625   raster->command_buffer[16] = raster->command_buffer[13];
629626
630627   /* always calculate the min z and max z values */
631628   min_z = object.v[0].pz;
r10427r10428
639636   /* read in the texture information */
640637
641638   /* texture point data */
642   if ( raster.command_buffer[0] & 0x800000 )
643      tp = &raster.texture_ram[raster.command_buffer[0] & 0xFFFF];
639   if ( raster->command_buffer[0] & 0x800000 )
640      tp = &raster->texture_ram[raster->command_buffer[0] & 0xFFFF];
644641   else
645      tp = &raster.texture_rom[raster.command_buffer[0] & 0x7FFFFF];
642      tp = &raster->texture_rom[raster->command_buffer[0] & 0x7FFFFF];
646643
647644   object.v[0].pv = *tp++;
648645   object.v[0].pu = *tp++;
r10427r10428
652649   object.v[2].pu = *tp++;
653650
654651   /* update the address */
655   raster.command_buffer[0] += 6;
652   raster->command_buffer[0] += 6;
656653
657654   /* texture header data */
658   if ( raster.command_buffer[1] & 0x800000 )
659      th = &raster.texture_ram[raster.command_buffer[1] & 0xFFFF];
655   if ( raster->command_buffer[1] & 0x800000 )
656      th = &raster->texture_ram[raster->command_buffer[1] & 0xFFFF];
660657   else
661      th = &raster.texture_rom[raster.command_buffer[1] & 0x7FFFFF];
658      th = &raster->texture_rom[raster->command_buffer[1] & 0x7FFFFF];
662659
663660   object.texheader[0] = *th++;
664661   object.texheader[1] = *th++;
r10427r10428
673670      tho |= -16;
674671
675672   /* update the address */
676   raster.command_buffer[1] += tho * 4;
673   raster->command_buffer[1] += tho * 4;
677674
678675   /* set the luma value of this quad */
679   object.luma = (raster.command_buffer[9] >> 15) & 0xFF;
676   object.luma = (raster->command_buffer[9] >> 15) & 0xFF;
680677
681678   /* determine wether we can cull this quad */
682679   cull = 0;
r10427r10428
685682   if ( ((attr >> 17) & 1) == 0 )
686683   {
687684      /* if it's the backface, cull it */
688      if ( raster.command_buffer[9] & 0x00800000 )
685      if ( raster->command_buffer[9] & 0x00800000 )
689686         cull = 1;
690687   }
691688
r10427r10428
694691      cull = 1;
695692
696693   /* if the minimum z value is bigger than the master z clip value, don't render */
697   if ( (INT32)(1.0/min_z) > raster.master_z_clip )
694   if ( (INT32)(1.0/min_z) > raster->master_z_clip )
698695      cull = 1;
699696
700697   /* if the maximum z value is < 0 then we can safely clip the entire polygon */
r10427r10428
702699      cull = 1;
703700
704701   /* set the object's z value */
705   zvalue = raster.triangle_z;
702   zvalue = raster->triangle_z;
706703
707704   /* see if we need to recompute min/max z */
708705   if ( (attr >> 10) & 3 )
r10427r10428
716713         zvalue = max_z;
717714      }
718715
719      raster.triangle_z = zvalue;
716      raster->triangle_z = zvalue;
720717   }
721718
722719   /* if we're not culling, do z-clip and add to out triangle list */
r10427r10428
739736         triangle *ztri;
740737
741738         /* adjust and set the object z-sort value */
742         object.z = float_to_zval( zvalue + raster.z_adjust );
739         object.z = float_to_zval( zvalue + raster->z_adjust );
743740
744741         /* get our list read to add the triangles */
745         ztri = raster.tri_sorted_list[object.z];
742         ztri = raster->tri_sorted_list[object.z];
746743
747744         if ( ztri != NULL )
748745         {
r10427r10428
755752         {
756753            triangle   *tri;
757754
758            tri = &raster.tri_list[raster.tri_list_index++];
755            tri = &raster->tri_list[raster->tri_list_index++];
759756
760            if ( raster.tri_list_index >= MAX_TRIANGLES )
757            if ( raster->tri_list_index >= MAX_TRIANGLES )
761758            {
762759               fatalerror( "SEGA 3D: Max triangle limit exceeded\n" );
763760            }
r10427r10428
771768            tri->luma = object.luma;
772769
773770            /* set the viewport */
774            tri->viewport[0] = raster.viewport[0];
775            tri->viewport[1] = raster.viewport[1];
776            tri->viewport[2] = raster.viewport[2];
777            tri->viewport[3] = raster.viewport[3];
771            tri->viewport[0] = raster->viewport[0];
772            tri->viewport[1] = raster->viewport[1];
773            tri->viewport[2] = raster->viewport[2];
774            tri->viewport[3] = raster->viewport[3];
778775
779776            /* set the center */
780            tri->center[0] = raster.center[raster.center_sel][0];
781            tri->center[1] = raster.center[raster.center_sel][1];
777            tri->center[0] = raster->center[raster->center_sel][0];
778            tri->center[1] = raster->center[raster->center_sel][1];
782779
783780            memcpy( &tri->v[0], &verts[0], sizeof( poly_vertex ) );
784781            memcpy( &tri->v[1], &verts[i-1], sizeof( poly_vertex ) );
r10427r10428
789786
790787            if ( ztri == NULL )
791788            {
792               raster.tri_sorted_list[object.z] = tri;
789               raster->tri_sorted_list[object.z] = tri;
793790            }
794791            else
795792            {
r10427r10428
800797         }
801798
802799         /* keep around the min and max z values for this frame */
803         if ( object.z < raster.min_z ) raster.min_z = object.z;
804         if ( object.z > raster.max_z ) raster.max_z = object.z;
800         if ( object.z < raster->min_z ) raster->min_z = object.z;
801         if ( object.z > raster->max_z ) raster->max_z = object.z;
805802      }
806803   }
807804
r10427r10428
813810      {
814811         /* reuse P0(n) and P1(n) */
815812         for( i = 0; i < 6; i++ )                              /* P0(n) -> P0(n-1) */
816            raster.command_buffer[2+i] = raster.command_buffer[11+i];   /* P1(n) -> P1(n-1) */
813            raster->command_buffer[2+i] = raster->command_buffer[11+i];   /* P1(n) -> P1(n-1) */
817814      }
818815      break;
819816
r10427r10428
821818      {
822819         /* reuse P0(n-1) and P0(n) */
823820         for( i = 0; i < 3; i++ )
824            raster.command_buffer[5+i] = raster.command_buffer[11+i];   /* P0(n) -> P1(n-1) */
821            raster->command_buffer[5+i] = raster->command_buffer[11+i];   /* P0(n) -> P1(n-1) */
825822      }
826823      break;
827824
r10427r10428
829826      {
830827         /* reuse P1(n-1) and P1(n) */
831828         for( i = 0; i < 3; i++ )
832            raster.command_buffer[2+i] = raster.command_buffer[14+i];   /* P1(n) -> P1(n-1) */
829            raster->command_buffer[2+i] = raster->command_buffer[14+i];   /* P1(n) -> P1(n-1) */
833830      }
834831      break;
835832   }
r10427r10428
926923   model2_3d_render_7   /* checker = 1, textured = 1, translucent = 1 */
927924};
928925
929static void model2_3d_render( bitmap_t *bitmap, triangle *tri, const rectangle *cliprect )
926static void model2_3d_render( model2_state *state, bitmap_t *bitmap, triangle *tri, const rectangle *cliprect )
930927{
928   poly_manager *poly = state->poly;
931929   poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly);
932930   UINT8      renderer;
933931   rectangle   vp;
r10427r10428
946944   if ( vp.min_y < cliprect->min_y ) vp.min_y = cliprect->min_y;
947945   if ( vp.max_y > cliprect->max_y ) vp.max_y = cliprect->max_y;
948946
947   extra->state = state;
949948   extra->lumabase = ((tri->texheader[1] & 0xFF) << 7) + ((tri->luma >> 5) ^ 0x7);
950949   extra->colorbase = (tri->texheader[3] >> 6) & 0x3FF;
951950
r10427r10428
957956      extra->texy = 32 * (((tri->texheader[2] >> 6) & 0x1f) + ( tri->texheader[2] & 0x20 ));
958957      extra->texmirrorx = (tri->texheader[0] >> 9) & 1;
959958      extra->texmirrory = (tri->texheader[0] >> 8) & 1;
960      extra->texsheet = (tri->texheader[2] & 0x1000) ? model2_textureram1 : model2_textureram0;
959      extra->texsheet = (tri->texheader[2] & 0x1000) ? state->textureram1 : state->textureram0;
961960
962961      tri->v[0].pz = 1.0f / (1.0f + tri->v[0].pz);
963962      tri->v[0].pu = tri->v[0].pu * tri->v[0].pz * (1.0f / 8.0f);
r10427r10428
10081007}
10091008
10101009/* 3D Rasterizer frame start: Resets frame variables */
1011static void model2_3d_frame_start( void )
1010static void model2_3d_frame_start( model2_state *state )
10121011{
1012   raster_state *raster = state->raster;
1013
10131014   /* reset the triangle list index */
1014   raster.tri_list_index = 0;
1015   raster->tri_list_index = 0;
10151016
10161017   /* reset the sorted z list */
1017   memset( raster.tri_sorted_list, 0, 0x10000 * sizeof( triangle * ) );
1018   memset( raster->tri_sorted_list, 0, 0x10000 * sizeof( triangle * ) );
10181019
10191020   /* reset the min-max sortable Z values */
1020   raster.min_z = 0xFFFF;
1021   raster.max_z = 0;
1021   raster->min_z = 0xFFFF;
1022   raster->max_z = 0;
10221023}
10231024
1024static void model2_3d_frame_end( bitmap_t *bitmap, const rectangle *cliprect )
1025static void model2_3d_frame_end( model2_state *state, bitmap_t *bitmap, const rectangle *cliprect )
10251026{
1027   raster_state *raster = state->raster;
10261028   INT32      z;
10271029
10281030   /* if we have nothing to render, bail */
1029   if ( raster.tri_list_index == 0 )
1031   if ( raster->tri_list_index == 0 )
10301032      return;
10311033
10321034#if DEBUG
r10427r10428
10381040
10391041      if ( f )
10401042      {
1041         for( i = 0; i < raster.tri_list_index; i++ )
1043         for( i = 0; i < raster->tri_list_index; i++ )
10421044         {
10431045
10441046            fprintf( f, "index: %d\n", i );
1045            fprintf( f, "v0.x = %f, v0.y = %f, v0.z = %f\n", raster.tri_list[i].v[0].x, raster.tri_list[i].v[0].y, raster.tri_list[i].v[0].pz );
1046            fprintf( f, "v1.x = %f, v1.y = %f, v1.z = %f\n", raster.tri_list[i].v[1].x, raster.tri_list[i].v[1].y, raster.tri_list[i].v[1].pz );
1047            fprintf( f, "v2.x = %f, v2.y = %f, v2.z = %f\n", raster.tri_list[i].v[2].x, raster.tri_list[i].v[2].y, raster.tri_list[i].v[2].pz );
1047            fprintf( f, "v0.x = %f, v0.y = %f, v0.z = %f\n", raster->tri_list[i].v[0].x, raster->tri_list[i].v[0].y, raster->tri_list[i].v[0].pz );
1048            fprintf( f, "v1.x = %f, v1.y = %f, v1.z = %f\n", raster->tri_list[i].v[1].x, raster->tri_list[i].v[1].y, raster->tri_list[i].v[1].pz );
1049            fprintf( f, "v2.x = %f, v2.y = %f, v2.z = %f\n", raster->tri_list[i].v[2].x, raster->tri_list[i].v[2].y, raster->tri_list[i].v[2].pz );
10481050
1049            fprintf( f, "tri z: %04x\n", raster.tri_list[i].pz );
1050            fprintf( f, "texheader - 0: %04x\n", raster.tri_list[i].texheader[0] );
1051            fprintf( f, "texheader - 1: %04x\n", raster.tri_list[i].texheader[1] );
1052            fprintf( f, "texheader - 2: %04x\n", raster.tri_list[i].texheader[2] );
1053            fprintf( f, "texheader - 3: %04x\n", raster.tri_list[i].texheader[3] );
1054            fprintf( f, "luma: %02x\n", raster.tri_list[i].luma );
1055            fprintf( f, "vp.sx: %04x\n", raster.tri_list[i].viewport[0] );
1056            fprintf( f, "vp.sy: %04x\n", raster.tri_list[i].viewport[1] );
1057            fprintf( f, "vp.ex: %04x\n", raster.tri_list[i].viewport[2] );
1058            fprintf( f, "vp.ey: %04x\n", raster.tri_list[i].viewport[3] );
1059            fprintf( f, "vp.swx: %04x\n", raster.tri_list[i].center[0] );
1060            fprintf( f, "vp.swy: %04x\n", raster.tri_list[i].center[1] );
1051            fprintf( f, "tri z: %04x\n", raster->tri_list[i].pz );
1052            fprintf( f, "texheader - 0: %04x\n", raster->tri_list[i].texheader[0] );
1053            fprintf( f, "texheader - 1: %04x\n", raster->tri_list[i].texheader[1] );
1054            fprintf( f, "texheader - 2: %04x\n", raster->tri_list[i].texheader[2] );
1055            fprintf( f, "texheader - 3: %04x\n", raster->tri_list[i].texheader[3] );
1056            fprintf( f, "luma: %02x\n", raster->tri_list[i].luma );
1057            fprintf( f, "vp.sx: %04x\n", raster->tri_list[i].viewport[0] );
1058            fprintf( f, "vp.sy: %04x\n", raster->tri_list[i].viewport[1] );
1059            fprintf( f, "vp.ex: %04x\n", raster->tri_list[i].viewport[2] );
1060            fprintf( f, "vp.ey: %04x\n", raster->tri_list[i].viewport[3] );
1061            fprintf( f, "vp.swx: %04x\n", raster->tri_list[i].center[0] );
1062            fprintf( f, "vp.swy: %04x\n", raster->tri_list[i].center[1] );
10611063            fprintf( f, "\n---\n\n" );
10621064         }
10631065
1064         fprintf( f, "min_z = %04x, max_z = %04x\n", raster.min_z, raster.max_z );
1066         fprintf( f, "min_z = %04x, max_z = %04x\n", raster->min_z, raster->max_z );
10651067
10661068         fclose( f );
10671069      }
r10427r10428
10691071#endif
10701072
10711073   /* go through the Z levels, and render each bucket */
1072   for( z = raster.max_z; z >= raster.min_z; z-- )
1074   for( z = raster->max_z; z >= raster->min_z; z-- )
10731075   {
10741076      /* see if we have items at this z level */
1075      if ( raster.tri_sorted_list[z] != NULL )
1077      if ( raster->tri_sorted_list[z] != NULL )
10761078      {
10771079         /* get a pointer to the first triangle */
1078         triangle *tri = raster.tri_sorted_list[z];
1080         triangle *tri = raster->tri_sorted_list[z];
10791081
10801082         /* and loop clipping and rendering each triangle */
10811083         while( tri != NULL )
10821084         {
10831085            /* project and render */
10841086            model2_3d_project( tri );
1085            model2_3d_render( bitmap, tri, cliprect );
1087            model2_3d_render( state, bitmap, tri, cliprect );
10861088
10871089            tri = (triangle *)tri->next;
10881090         }
10891091      }
10901092   }
1091   poly_wait(poly, "End of frame");
1093   poly_wait(state->poly, "End of frame");
10921094}
10931095
10941096/* 3D Rasterizer main data input port */
1095static void model2_3d_push( UINT32 input )
1097static void model2_3d_push( raster_state *raster, UINT32 input )
10961098{
10971099   /* see if we have a command in progress */
1098   if ( raster.cur_command != 0 )
1100   if ( raster->cur_command != 0 )
10991101   {
1100      raster.command_buffer[raster.command_index++] = input;
1102      raster->command_buffer[raster->command_index++] = input;
11011103
1102      switch( raster.cur_command )
1104      switch( raster->cur_command )
11031105      {
11041106         case 0x00:   /* NOP */
11051107         break;
r10427r10428
11091111            UINT32   attr;
11101112
11111113            /* start by looking if we have the basic input data */
1112            if ( raster.command_index < 9 )
1114            if ( raster->command_index < 9 )
11131115               return;
11141116
11151117            /* get the attributes */
1116            attr = raster.command_buffer[8];
1118            attr = raster->command_buffer[8];
11171119
11181120            /* see if we're done */
11191121            if ( (attr & 3) == 0 )
11201122            {
1121               raster.cur_command = 0;
1123               raster->cur_command = 0;
11221124               return;
11231125            }
11241126
r10427r10428
11261128            if ( attr & 1 )
11271129            {
11281130               /* it's a quad, wait for the rest of the points */
1129               if ( raster.command_index < 17 )
1131               if ( raster->command_index < 17 )
11301132                  return;
11311133
11321134               /* we have a full quad info, fill up our quad structure */
1133               model2_3d_process_quad( attr );
1135               model2_3d_process_quad( raster, attr );
11341136
11351137               /* back up and wait for more data */
1136               raster.command_index = 8;
1138               raster->command_index = 8;
11371139            }
11381140            else
11391141            {
11401142               /* it's a triangle, wait for the rest of the point */
1141               if ( raster.command_index < 14 )
1143               if ( raster->command_index < 14 )
11421144                  return;
11431145
11441146               /* we have a full quad info, fill up our quad structure */
1145               model2_3d_process_triangle( attr );
1147               model2_3d_process_triangle( raster, attr );
11461148
11471149               /* back up and wait for more data */
1148               raster.command_index = 8;
1150               raster->command_index = 8;
11491151            }
11501152         }
11511153         break;
r10427r10428
11551157            UINT32   i;
11561158
11571159            /* make sure we have all the data */
1158            if ( raster.command_index < 6 )
1160            if ( raster->command_index < 6 )
11591161               return;
11601162
11611163            /* coordinates are 12 bit signed */
11621164
11631165            /* extract the viewport start x */
1164            raster.viewport[0] = (raster.command_buffer[0] >> 12) & 0xFFF;
1166            raster->viewport[0] = (raster->command_buffer[0] >> 12) & 0xFFF;
11651167
1166            if ( raster.viewport[0] & 0x800 )
1167               raster.viewport[0] = -( 0x800 - (raster.viewport[0] & 0x7FF) );
1168            if ( raster->viewport[0] & 0x800 )
1169               raster->viewport[0] = -( 0x800 - (raster->viewport[0] & 0x7FF) );
11681170
11691171            /* extract the viewport start y */
1170            raster.viewport[1] = raster.command_buffer[0] & 0xFFF;
1172            raster->viewport[1] = raster->command_buffer[0] & 0xFFF;
11711173
1172            if ( raster.viewport[1] & 0x800 )
1173               raster.viewport[1] = -( 0x800 - (raster.viewport[1] & 0x7FF) );
1174            if ( raster->viewport[1] & 0x800 )
1175               raster->viewport[1] = -( 0x800 - (raster->viewport[1] & 0x7FF) );
11741176
11751177            /* extract the viewport end x */
1176            raster.viewport[2] = (raster.command_buffer[1] >> 12) & 0xFFF;
1178            raster->viewport[2] = (raster->command_buffer[1] >> 12) & 0xFFF;
11771179
1178            if ( raster.viewport[2] & 0x800 )
1179               raster.viewport[2] = -( 0x800 - (raster.viewport[2] & 0x7FF) );
1180            if ( raster->viewport[2] & 0x800 )
1181               raster->viewport[2] = -( 0x800 - (raster->viewport[2] & 0x7FF) );
11801182
11811183            /* extract the viewport end y */
1182            raster.viewport[3] = raster.command_buffer[1] & 0xFFF;
1184            raster->viewport[3] = raster->command_buffer[1] & 0xFFF;
11831185
1184            if ( raster.viewport[3] & 0x800 )
1185               raster.viewport[3] = -( 0x800 - (raster.viewport[3] & 0x7FF) );
1186            if ( raster->viewport[3] & 0x800 )
1187               raster->viewport[3] = -( 0x800 - (raster->viewport[3] & 0x7FF) );
11861188
11871189            /* extract the centers */
11881190            for( i = 0; i < 4; i++ )
11891191            {
11901192               /* center x */
1191               raster.center[i][0] = (raster.command_buffer[2+i] >> 12) & 0xFFF;
1193               raster->center[i][0] = (raster->command_buffer[2+i] >> 12) & 0xFFF;
11921194
1193               if ( raster.center[i][0] & 0x800 )
1194                  raster.center[i][0] = -( 0x800 - (raster.center[i][0] & 0x7FF) );
1195               if ( raster->center[i][0] & 0x800 )
1196                  raster->center[i][0] = -( 0x800 - (raster->center[i][0] & 0x7FF) );
11951197
11961198               /* center y */
1197               raster.center[i][1] = raster.command_buffer[2+i] & 0xFFF;
1199               raster->center[i][1] = raster->command_buffer[2+i] & 0xFFF;
11981200
1199               if ( raster.center[i][1] & 0x800 )
1200                  raster.center[i][1] = -( 0x800 - (raster.center[i][1] & 0x7FF) );
1201               if ( raster->center[i][1] & 0x800 )
1202                  raster->center[i][1] = -( 0x800 - (raster->center[i][1] & 0x7FF) );
12011203            }
12021204
12031205            /* done with this command */
1204            raster.cur_command = 0;
1206            raster->cur_command = 0;
12051207         }
12061208         break;
12071209
12081210         case 0x04:   /* Texture/Log Data write */
12091211         {
12101212            /* make sure we have enough data */
1211            if ( raster.command_index < 2 )
1213            if ( raster->command_index < 2 )
12121214               return;
12131215
12141216            /* see if the count is non-zero */
1215            if ( raster.command_buffer[1] > 0 )
1217            if ( raster->command_buffer[1] > 0 )
12161218            {
12171219               /* see if we have data available */
1218               if ( raster.command_index >= 3 )
1220               if ( raster->command_index >= 3 )
12191221               {
12201222                  /* get the address */
1221                  UINT32   address = raster.command_buffer[0];
1223                  UINT32   address = raster->command_buffer[0];
12221224
12231225                  /* do the write */
12241226                  if ( address & 0x800000 )
1225                     raster.texture_ram[address&0xFFFF] = raster.command_buffer[2];
1227                     raster->texture_ram[address&0xFFFF] = raster->command_buffer[2];
12261228                  else
1227                     raster.log_ram[address&0xFFFF] = raster.command_buffer[2];
1229                     raster->log_ram[address&0xFFFF] = raster->command_buffer[2];
12281230
12291231                  /* increment the address and decrease the count */
1230                  raster.command_buffer[0]++;
1231                  raster.command_buffer[1]--;
1232                  raster->command_buffer[0]++;
1233                  raster->command_buffer[1]--;
12321234
12331235                  /* decrease the index, so we keep placing data in the same slot */
1234                  raster.command_index--;
1236                  raster->command_index--;
12351237               }
12361238            }
12371239
12381240            /* see if we're done with this command */
1239            if ( raster.command_buffer[1] == 0 )
1240               raster.cur_command = 0;
1241            if ( raster->command_buffer[1] == 0 )
1242               raster->cur_command = 0;
12411243         }
12421244         break;
12431245
12441246         case 0x08:   /* ZSort mode */
12451247         {
12461248            /* save the zsort mode value */
1247            raster.z_adjust = u2f( raster.command_buffer[0] << 8 );
1249            raster->z_adjust = u2f( raster->command_buffer[0] << 8 );
12481250
12491251            /* done with this command */
1250            raster.cur_command = 0;
1252            raster->cur_command = 0;
12511253         }
12521254         break;
12531255
12541256         default:
12551257         {
1256            fatalerror( "SEGA 3D: Unknown rasterizer command %08x\n", raster.cur_command );
1258            fatalerror( "SEGA 3D: Unknown rasterizer command %08x\n", raster->cur_command );
12571259         }
12581260         break;
12591261      }
r10427r10428
12611263   else
12621264   {
12631265      /* new command */
1264      raster.cur_command = input & 0x0F;
1265      raster.command_index = 0;
1266      raster->cur_command = input & 0x0F;
1267      raster->command_index = 0;
12661268
12671269      /* see if it's object data */
1268      if ( raster.cur_command == 1 )
1270      if ( raster->cur_command == 1 )
12691271      {
12701272         /* extract reverse bit */
1271         raster.reverse = (input >> 4) & 1;
1273         raster->reverse = (input >> 4) & 1;
12721274
12731275         /* extract center select */
1274         raster.center_sel = ( input >> 6 ) & 3;
1276         raster->center_sel = ( input >> 6 ) & 3;
12751277
12761278         /* reset the triangle z value */
1277         raster.triangle_z = 0;
1279         raster->triangle_z = 0;
12781280      }
12791281   }
12801282}
r10427r10428
12891291 *
12901292 *******************************************/
12911293
1292typedef struct
1294struct _geo_state
12931295{
1296   raster_state *         raster;
12941297   UINT32            mode;               /* bit 0 = Enable Specular, bit 1 = Calculate Normals */
12951298   UINT32 *         polygon_rom;         /* Polygon ROM pointer */
1296   UINT32 *         polygon_ram0;         /* Fast Polygon RAM pointer */
1297   UINT32 *         polygon_ram1;         /* Slow Polygon RAM pointer */
12981299   float            matrix[12];            /* Current Transformation Matrix */
12991300   poly_vertex         focus;               /* Focus (x,y) */
13001301   poly_vertex         light;               /* Light Vector */
13011302   float            lod;               /* LOD */
13021303   float            coef_table[32];         /* Distane Coefficient table */
13031304   texture_parameter   texture_parameters[32];   /* Texture parameters */
1304} geo_state;
1305   UINT32         polygon_ram0[0x8000];         /* Fast Polygon RAM pointer */
1306   UINT32         polygon_ram1[0x8000];         /* Slow Polygon RAM pointer */
1307};
13051308
1306static geo_state geo;
13071309
13081310/*******************************************
13091311 *
r10427r10428
13131315
13141316static void geo_init( running_machine *machine, UINT32 *polygon_rom )
13151317{
1316   memset( &geo, 0, sizeof( geo_state ) );
1318   model2_state *state = machine->driver_data<model2_state>();
1319   state->geo = auto_alloc_clear(machine, geo_state);
13171320
1318   geo.polygon_rom = polygon_rom;
1319   geo.polygon_ram0 = auto_alloc_array(machine, UINT32, 0x8000);
1320   geo.polygon_ram1 = auto_alloc_array(machine, UINT32, 0x8000);
1321   state->geo->raster = state->raster;
1322   state->geo->polygon_rom = polygon_rom;
13211323}
13221324
13231325/*******************************************
r10427r10428
13271329 *******************************************/
13281330
13291331/* Parse Polygons: Normals Present, No Specular case */
1330static void geo_parse_np_ns( UINT32 *input, UINT32 count )
1332static void geo_parse_np_ns( geo_state *geo, UINT32 *input, UINT32 count )
13311333{
1334   raster_state *raster = geo->raster;
13321335   poly_vertex   point, normal;
13331336   UINT32   attr, i;
13341337
r10427r10428
13381341   point.pz = u2f( *input++ );
13391342
13401343   /* transform with the current matrix */
1341   transform_point( &point, geo.matrix );
1344   transform_point( &point, geo->matrix );
13421345
13431346   /* apply focus */
1344   point.x *= geo.focus.x;
1345   point.y *= geo.focus.y;
1347   point.x *= geo->focus.x;
1348   point.y *= geo->focus.y;
13461349
13471350   /* push it to the 3d rasterizer */
1348   model2_3d_push( f2u(point.x) >> 8 );
1349   model2_3d_push( f2u(point.y) >> 8 );
1350   model2_3d_push( f2u(point.pz) >> 8 );
1351   model2_3d_push( raster, f2u(point.x) >> 8 );
1352   model2_3d_push( raster, f2u(point.y) >> 8 );
1353   model2_3d_push( raster, f2u(point.pz) >> 8 );
13511354
13521355   /* read the 2nd point */
13531356   point.x = u2f( *input++ );
r10427r10428
13551358   point.pz = u2f( *input++ );
13561359
13571360   /* transform with the current matrix */
1358   transform_point( &point, geo.matrix );
1361   transform_point( &point, geo->matrix );
13591362
13601363   /* apply focus */
1361   point.x *= geo.focus.x;
1362   point.y *= geo.focus.y;
1364   point.x *= geo->focus.x;
1365   point.y *= geo->focus.y;
13631366
13641367   /* push it to the 3d rasterizer */
1365   model2_3d_push( f2u(point.x) >> 8 );
1366   model2_3d_push( f2u(point.y) >> 8 );
1367   model2_3d_push( f2u(point.pz) >> 8 );
1368   model2_3d_push( raster, f2u(point.x) >> 8 );
1369   model2_3d_push( raster, f2u(point.y) >> 8 );
1370   model2_3d_push( raster, f2u(point.pz) >> 8 );
13681371
13691372   /* loop through the following links */
13701373   for( i = 0; i < count; i++ )
r10427r10428
13731376      attr = *input++;
13741377
13751378      /* push to the 3d rasterizer */
1376      model2_3d_push( attr & 0x0003FFFF );
1379      model2_3d_push( raster, attr & 0x0003FFFF );
13771380
13781381      /* read in the normal */
13791382      normal.x = u2f(*input++);
r10427r10428
13811384      normal.pz = u2f(*input++);
13821385
13831386      /* transform with the current matrix */
1384      transform_vector( &normal, geo.matrix );
1387      transform_vector( &normal, geo->matrix );
13851388
13861389      if ( (attr & 3) != 0 ) /* quad or triangle */
13871390      {
r10427r10428
13961399         point.pz = u2f( *input++ );
13971400
13981401         /* transform with the current matrix */
1399         transform_point( &point, geo.matrix );
1402         transform_point( &point, geo->matrix );
14001403
14011404         /* calculate the dot product of the normal and the light vector */
1402         dotl = dot_product( &normal, &geo.light );
1405         dotl = dot_product( &normal, &geo->light );
14031406
14041407         /* calculate the dot product of the normal and the point */
14051408         dotp = dot_product( &normal, &point );
14061409
14071410         /* apply focus */
1408         point.x *= geo.focus.x;
1409         point.y *= geo.focus.y;
1411         point.x *= geo->focus.x;
1412         point.y *= geo->focus.y;
14101413
14111414         /* determine wether this is the front or the back of the polygon */
14121415         face = 0x100; /* rear */
14131416         if ( dotp >= 0 ) face = 0; /* front */
14141417
14151418         /* get the texture parameters */
1416         texparam = &geo.texture_parameters[(attr>>18) & 0x1f];
1419         texparam = &geo->texture_parameters[(attr>>18) & 0x1f];
14171420
14181421         /* calculate luminance */
14191422         if ( (dotl * dotp) < 0 ) luminance = 0;
r10427r10428
14291432         luma += face;
14301433
14311434         /* extract distance coefficient */
1432         coef = geo.coef_table[attr>>27];
1435         coef = geo->coef_table[attr>>27];
14331436
14341437         /* calculate texture level of detail */
1435         distance = coef * fabs( dotp ) * geo.lod;
1438         distance = coef * fabs( dotp ) * geo->lod;
14361439
14371440         /* push to the 3d rasterizer */
1438         model2_3d_push( luma << 15 );
1439         model2_3d_push( f2u(distance) >> 8 );
1440         model2_3d_push( f2u(point.x) >> 8 );
1441         model2_3d_push( f2u(point.y) >> 8 );
1442         model2_3d_push( f2u(point.pz) >> 8 );
1441         model2_3d_push( raster, luma << 15 );
1442         model2_3d_push( raster, f2u(distance) >> 8 );
1443         model2_3d_push( raster, f2u(point.x) >> 8 );
1444         model2_3d_push( raster, f2u(point.y) >> 8 );
1445         model2_3d_push( raster, f2u(point.pz) >> 8 );
14431446
14441447         /* if it's a quad, push one more point */
14451448         if ( attr & 1 )
r10427r10428
14501453            point.pz = u2f( *input++ );
14511454
14521455            /* transform with the current matrix */
1453            transform_point( &point, geo.matrix );
1456            transform_point( &point, geo->matrix );
14541457
14551458            /* apply focus */
1456            point.x *= geo.focus.x;
1457            point.y *= geo.focus.y;
1459            point.x *= geo->focus.x;
1460            point.y *= geo->focus.y;
14581461
14591462            /* push to the 3d rasterizer */
1460            model2_3d_push( f2u(point.x) >> 8 );
1461            model2_3d_push( f2u(point.y) >> 8 );
1462            model2_3d_push( f2u(point.pz) >> 8 );
1463            model2_3d_push( raster, f2u(point.x) >> 8 );
1464            model2_3d_push( raster, f2u(point.y) >> 8 );
1465            model2_3d_push( raster, f2u(point.pz) >> 8 );
14631466         }
14641467         else /* triangle */
14651468         {
r10427r10428
14741477   }
14751478
14761479   /* notify the 3d rasterizer we're done */
1477   model2_3d_push( 0 );
1480   model2_3d_push( raster, 0 );
14781481}
14791482
14801483/* Parse Polygons: Normals Present, Specular case */
1481static void geo_parse_np_s( UINT32 *input, UINT32 count )
1484static void geo_parse_np_s( geo_state *geo, UINT32 *input, UINT32 count )
14821485{
1486   raster_state *raster = geo->raster;
14831487   poly_vertex   point, normal;
14841488   UINT32   attr, i;
14851489
r10427r10428
14891493   point.pz = u2f( *input++ );
14901494
14911495   /* transform with the current matrix */
1492   transform_point( &point, geo.matrix );
1496   transform_point( &point, geo->matrix );
14931497
14941498   /* apply focus */
1495   point.x *= geo.focus.x;
1496   point.y *= geo.focus.y;
1499   point.x *= geo->focus.x;
1500   point.y *= geo->focus.y;
14971501
14981502   /* push it to the 3d rasterizer */
1499   model2_3d_push( f2u(point.x) >> 8 );
1500   model2_3d_push( f2u(point.y) >> 8 );
1501   model2_3d_push( f2u(point.pz) >> 8 );
1503   model2_3d_push( raster, f2u(point.x) >> 8 );
1504   model2_3d_push( raster, f2u(point.y) >> 8 );
1505   model2_3d_push( raster, f2u(point.pz) >> 8 );
15021506
15031507   /* read the 2nd point */
15041508   point.x = u2f( *input++ );
r10427r10428
15061510   point.pz = u2f( *input++ );
15071511
15081512   /* transform with the current matrix */
1509   transform_point( &point, geo.matrix );
1513   transform_point( &point, geo->matrix );
15101514
15111515   /* apply focus */
1512   point.x *= geo.focus.x;
1513   point.y *= geo.focus.y;
1516   point.x *= geo->focus.x;
1517   point.y *= geo->focus.y;
15141518
15151519   /* push it to the 3d rasterizer */
1516   model2_3d_push( f2u(point.x) >> 8 );
1517   model2_3d_push( f2u(point.y) >> 8 );
1518   model2_3d_push( f2u(point.pz) >> 8 );
1520   model2_3d_push( raster, f2u(point.x) >> 8 );
1521   model2_3d_push( raster, f2u(point.y) >> 8 );
1522   model2_3d_push( raster, f2u(point.pz) >> 8 );
15191523
15201524   /* loop through the following links */
15211525   for( i = 0; i < count; i++ )
r10427r10428
15241528      attr = *input++;
15251529
15261530      /* push to the 3d rasterizer */
1527      model2_3d_push( attr & 0x0003FFFF );
1531      model2_3d_push( raster, attr & 0x0003FFFF );
15281532
15291533      /* read in the normal */
15301534      normal.x = u2f(*input++);
r10427r10428
15321536      normal.pz = u2f(*input++);
15331537
15341538      /* transform with the current matrix */
1535      transform_vector( &normal, geo.matrix );
1539      transform_vector( &normal, geo->matrix );
15361540
15371541      if ( (attr & 3) != 0 ) /* quad or triangle */
15381542      {
r10427r10428
15471551         point.pz = u2f( *input++ );
15481552
15491553         /* transform with the current matrix */
1550         transform_point( &point, geo.matrix );
1554         transform_point( &point, geo->matrix );
15511555
15521556         /* calculate the dot product of the normal and the light vector */
1553         dotl = dot_product( &normal, &geo.light );
1557         dotl = dot_product( &normal, &geo->light );
15541558
15551559         /* calculate the dot product of the normal and the point */
15561560         dotp = dot_product( &normal, &point );
15571561
15581562         /* apply focus */
1559         point.x *= geo.focus.x;
1560         point.y *= geo.focus.y;
1563         point.x *= geo->focus.x;
1564         point.y *= geo->focus.y;
15611565
15621566         /* determine wether this is the front or the back of the polygon */
15631567         face = 0x100; /* rear */
15641568         if ( dotp >= 0 ) face = 0; /* front */
15651569
15661570         /* get the texture parameters */
1567         texparam = &geo.texture_parameters[(attr>>18) & 0x1f];
1571         texparam = &geo->texture_parameters[(attr>>18) & 0x1f];
15681572
15691573         /* calculate luminance and specular */
15701574         if ( (dotl * dotp) < 0 ) luminance = 0;
15711575         else luminance = fabs( dotl );
15721576
1573         specular = ((2*dotl) * normal.pz) - geo.light.pz;
1577         specular = ((2*dotl) * normal.pz) - geo->light.pz;
15741578         if ( specular < 0 )   specular = 0;
15751579         if ( texparam->specular_control == 0 ) specular = 0;
15761580         if ( (texparam->specular_control >> 1) != 0 ) specular *= specular;
r10427r10428
15891593         luma += face;
15901594
15911595         /* extract distance coefficient */
1592         coef = geo.coef_table[attr>>27];
1596         coef = geo->coef_table[attr>>27];
15931597
15941598         /* calculate texture level of detail */
1595         distance = coef * fabs( dotp ) * geo.lod;
1599         distance = coef * fabs( dotp ) * geo->lod;
15961600
15971601         /* push to the 3d rasterizer */
1598         model2_3d_push( luma << 15 );
1599         model2_3d_push( f2u(distance) >> 8 );
1600         model2_3d_push( f2u(point.x) >> 8 );
1601         model2_3d_push( f2u(point.y) >> 8 );
1602         model2_3d_push( f2u(point.pz) >> 8 );
1602         model2_3d_push( raster, luma << 15 );
1603         model2_3d_push( raster, f2u(distance) >> 8 );
1604         model2_3d_push( raster, f2u(point.x) >> 8 );
1605         model2_3d_push( raster, f2u(point.y) >> 8 );
1606         model2_3d_push( raster, f2u(point.pz) >> 8 );
16031607
16041608         /* if it's a quad, push one more point */
16051609         if ( attr & 1 )
r10427r10428
16101614            point.pz = u2f( *input++ );
16111615
16121616            /* transform with the current matrix */
1613            transform_point( &point, geo.matrix );
1617            transform_point( &point, geo->matrix );
16141618
16151619            /* apply focus */
1616            point.x *= geo.focus.x;
1617            point.y *= geo.focus.y;
1620            point.x *= geo->focus.x;
1621            point.y *= geo->focus.y;
16181622
16191623            /* push to the 3d rasterizer */
1620            model2_3d_push( f2u(point.x) >> 8 );
1621            model2_3d_push( f2u(point.y) >> 8 );
1622            model2_3d_push( f2u(point.pz) >> 8 );
1624            model2_3d_push( raster, f2u(point.x) >> 8 );
1625            model2_3d_push( raster, f2u(point.y) >> 8 );
1626            model2_3d_push( raster, f2u(point.pz) >> 8 );
16231627         }
16241628         else /* triangle */
16251629         {
r10427r10428
16341638   }
16351639
16361640   /* notify the 3d rasterizer we're done */
1637   model2_3d_push( 0 );
1641   model2_3d_push( raster, 0 );
16381642}
16391643
16401644/* Parse Polygons: No Normals, No Specular case */
1641static void geo_parse_nn_ns( UINT32 *input, UINT32 count )
1645static void geo_parse_nn_ns( geo_state *geo, UINT32 *input, UINT32 count )
16421646{
1647   raster_state *raster = geo->raster;
16431648   poly_vertex   point, normal, p0, p1, p2, p3;
16441649   UINT32   attr, i;
16451650
r10427r10428
16491654   point.pz = u2f( *input++ );
16501655
16511656   /* transform with the current matrix */
1652   transform_point( &point, geo.matrix );
1657   transform_point( &point, geo->matrix );
16531658
16541659   /* save for normal calculation */
16551660   p0.x = point.x; p0.y = point.y; p0.pz = point.pz;
16561661
16571662   /* apply focus */
1658   point.x *= geo.focus.x;
1659   point.y *= geo.focus.y;
1663   point.x *= geo->focus.x;
1664   point.y *= geo->focus.y;
16601665
16611666   /* push it to the 3d rasterizer */
1662   model2_3d_push( f2u(point.x) >> 8 );
1663   model2_3d_push( f2u(point.y) >> 8 );
1664   model2_3d_push( f2u(point.pz) >> 8 );
1667   model2_3d_push( raster, f2u(point.x) >> 8 );
1668   model2_3d_push( raster, f2u(point.y) >> 8 );
1669   model2_3d_push( raster, f2u(point.pz) >> 8 );
16651670
16661671   /* read the 2nd point */
16671672   point.x = u2f( *input++ );
r10427r10428
16691674   point.pz = u2f( *input++ );
16701675
16711676   /* transform with the current matrix */
1672   transform_point( &point, geo.matrix );
1677   transform_point( &point, geo->matrix );
16731678
16741679   /* save for normal calculation */
16751680   p1.x = point.x; p1.y = point.y; p1.pz = point.pz;
16761681
16771682   /* apply focus */
1678   point.x *= geo.focus.x;
1679   point.y *= geo.focus.y;
1683   point.x *= geo->focus.x;
1684   point.y *= geo->focus.y;
16801685
16811686   /* push it to the 3d rasterizer */
1682   model2_3d_push( f2u(point.x) >> 8 );
1683   model2_3d_push( f2u(point.y) >> 8 );
1684   model2_3d_push( f2u(point.pz) >> 8 );
1687   model2_3d_push( raster, f2u(point.x) >> 8 );
1688   model2_3d_push( raster, f2u(point.y) >> 8 );
1689   model2_3d_push( raster, f2u(point.pz) >> 8 );
16851690
16861691   /* skip 4 */
16871692   input += 4;
r10427r10428
16931698      attr = *input++;
16941699
16951700      /* push to the 3d rasterizer */
1696      model2_3d_push( attr & 0x0003FFFF );
1701      model2_3d_push( raster, attr & 0x0003FFFF );
16971702
16981703      if ( (attr & 3) != 0 ) /* quad or triangle */
16991704      {
r10427r10428
17081713         point.pz = u2f( *input++ );
17091714
17101715         /* transform with the current matrix */
1711         transform_point( &point, geo.matrix );
1716         transform_point( &point, geo->matrix );
17121717
17131718         /* save for normal calculation */
17141719         p2.x = point.x; p2.y = point.y; p2.pz = point.pz;
r10427r10428
17201725         normalize_vector( &normal );
17211726
17221727         /* calculate the dot product of the normal and the light vector */
1723         dotl = dot_product( &normal, &geo.light );
1728         dotl = dot_product( &normal, &geo->light );
17241729
17251730         /* calculate the dot product of the normal and the point */
17261731         dotp = dot_product( &normal, &point );
17271732
17281733         /* apply focus */
1729         point.x *= geo.focus.x;
1730         point.y *= geo.focus.y;
1734         point.x *= geo->focus.x;
1735         point.y *= geo->focus.y;
17311736
17321737         /* determine wether this is the front or the back of the polygon */
17331738         face = 0x100; /* rear */
17341739         if ( dotp >= 0 ) face = 0; /* front */
17351740
17361741         /* get the texture parameters */
1737         texparam = &geo.texture_parameters[(attr>>18) & 0x1f];
1742         texparam = &geo->texture_parameters[(attr>>18) & 0x1f];
17381743
17391744         /* calculate luminance */
17401745         if ( (dotl * dotp) < 0 ) luminance = 0;
r10427r10428
17501755         luma += face;
17511756
17521757         /* extract distance coefficient */
1753         coef = geo.coef_table[attr>>27];
1758         coef = geo->coef_table[attr>>27];
17541759
17551760         /* calculate texture level of detail */
1756         distance = coef * fabs( dotp ) * geo.lod;
1761         distance = coef * fabs( dotp ) * geo->lod;
17571762
17581763         /* push to the 3d rasterizer */
1759         model2_3d_push( luma << 15 );
1760         model2_3d_push( f2u(distance) >> 8 );
1761         model2_3d_push( f2u(point.x) >> 8 );
1762         model2_3d_push( f2u(point.y) >> 8 );
1763         model2_3d_push( f2u(point.pz) >> 8 );
1764         model2_3d_push( raster, luma << 15 );
1765         model2_3d_push( raster, f2u(distance) >> 8 );
1766         model2_3d_push( raster, f2u(point.x) >> 8 );
1767         model2_3d_push( raster, f2u(point.y) >> 8 );
1768         model2_3d_push( raster, f2u(point.pz) >> 8 );
17641769
17651770         /* if it's a quad, push one more point */
17661771         if ( attr & 1 )
r10427r10428
17711776            point.pz = u2f( *input++ );
17721777
17731778            /* transform with the current matrix */
1774            transform_point( &point, geo.matrix );
1779            transform_point( &point, geo->matrix );
17751780
17761781            /* save for normal calculation */
17771782            p3.x = point.x; p3.y = point.y; p3.pz = point.pz;
17781783
17791784            /* apply focus */
1780            point.x *= geo.focus.x;
1781            point.y *= geo.focus.y;
1785            point.x *= geo->focus.x;
1786            point.y *= geo->focus.y;
17821787
17831788            /* push to the 3d rasterizer */
1784            model2_3d_push( f2u(point.x) >> 8 );
1785            model2_3d_push( f2u(point.y) >> 8 );
1786            model2_3d_push( f2u(point.pz) >> 8 );
1789            model2_3d_push( raster, f2u(point.x) >> 8 );
1790            model2_3d_push( raster, f2u(point.y) >> 8 );
1791            model2_3d_push( raster, f2u(point.pz) >> 8 );
17871792         }
17881793         else
17891794         {
r10427r10428
18281833   }
18291834
18301835   /* notify the 3d rasterizer we're done */
1831   model2_3d_push( 0 );
1836   model2_3d_push( raster, 0 );
18321837}
18331838
18341839/* Parse Polygons: No Normals, Specular case */
1835static void geo_parse_nn_s( UINT32 *input, UINT32 count )
1840static void geo_parse_nn_s( geo_state *geo, UINT32 *input, UINT32 count )
18361841{
1842   raster_state *raster = geo->raster;
18371843   poly_vertex   point, normal, p0, p1, p2, p3;
18381844   UINT32   attr, i;
18391845
r10427r10428
18431849   point.pz = u2f( *input++ );
18441850
18451851   /* transform with the current matrix */
1846   transform_point( &point, geo.matrix );
1852   transform_point( &point, geo->matrix );
18471853
18481854   /* save for normal calculation */
18491855   p0.x = point.x; p0.y = point.y; p0.pz = point.pz;
18501856
18511857   /* apply focus */
1852   point.x *= geo.focus.x;
1853   point.y *= geo.focus.y;
1858   point.x *= geo->focus.x;
1859   point.y *= geo->focus.y;
18541860
18551861   /* push it to the 3d rasterizer */
1856   model2_3d_push( f2u(point.x) >> 8 );
1857   model2_3d_push( f2u(point.y) >> 8 );
1858   model2_3d_push( f2u(point.pz) >> 8 );
1862   model2_3d_push( raster, f2u(point.x) >> 8 );
1863   model2_3d_push( raster, f2u(point.y) >> 8 );
1864   model2_3d_push( raster, f2u(point.pz) >> 8 );
18591865
18601866   /* read the 2nd point */
18611867   point.x = u2f( *input++ );
r10427r10428
18631869   point.pz = u2f( *input++ );
18641870
18651871   /* transform with the current matrix */
1866   transform_point( &point, geo.matrix );
1872   transform_point( &point, geo->matrix );
18671873
18681874   /* save for normal calculation */
18691875   p1.x = point.x; p1.y = point.y; p1.pz = point.pz;
18701876
18711877   /* apply focus */
1872   point.x *= geo.focus.x;
1873   point.y *= geo.focus.y;
1878   point.x *= geo->focus.x;
1879   point.y *= geo->focus.y;
18741880
18751881   /* push it to the 3d rasterizer */
1876   model2_3d_push( f2u(point.x) >> 8 );
1877   model2_3d_push( f2u(point.y) >> 8 );
1878   model2_3d_push( f2u(point.pz) >> 8 );
1882   model2_3d_push( raster, f2u(point.x) >> 8 );
1883   model2_3d_push( raster, f2u(point.y) >> 8 );
1884   model2_3d_push( raster, f2u(point.pz) >> 8 );
18791885
18801886   /* skip 4 */
18811887   input += 4;
r10427r10428
18871893      attr = *input++;
18881894
18891895      /* push to the 3d rasterizer */
1890      model2_3d_push( attr & 0x0003FFFF );
1896      model2_3d_push( raster, attr & 0x0003FFFF );
18911897
18921898      if ( (attr & 3) != 0 ) /* quad or triangle */
18931899      {
r10427r10428
19021908         point.pz = u2f( *input++ );
19031909
19041910         /* transform with the current matrix */
1905         transform_point( &point, geo.matrix );
1911         transform_point( &point, geo->matrix );
19061912
19071913         /* save for normal calculation */
19081914         p2.x = point.x; p2.y = point.y; p2.pz = point.pz;
r10427r10428
19141920         normalize_vector( &normal );
19151921
19161922         /* calculate the dot product of the normal and the light vector */
1917         dotl = dot_product( &normal, &geo.light );
1923         dotl = dot_product( &normal, &geo->light );
19181924
19191925         /* calculate the dot product of the normal and the point */
19201926         dotp = dot_product( &normal, &point );
19211927
19221928         /* apply focus */
1923         point.x *= geo.focus.x;
1924         point.y *= geo.focus.y;
1929         point.x *= geo->focus.x;
1930         point.y *= geo->focus.y;
19251931
19261932         /* determine wether this is the front or the back of the polygon */
19271933         face = 0x100; /* rear */
19281934         if ( dotp >= 0 ) face = 0; /* front */
19291935
19301936         /* get the texture parameters */
1931         texparam = &geo.texture_parameters[(attr>>18) & 0x1f];
1937         texparam = &geo->texture_parameters[(attr>>18) & 0x1f];
19321938
19331939         /* calculate luminance and specular */
19341940         if ( (dotl * dotp) < 0 ) luminance = 0;
19351941         else luminance = fabs( dotl );
19361942
1937         specular = ((2*dotl) * normal.pz) - geo.light.pz;
1943         specular = ((2*dotl) * normal.pz) - geo->light.pz;
19381944         if ( specular < 0 )   specular = 0;
19391945         if ( texparam->specular_control == 0 ) specular = 0;
19401946         if ( (texparam->specular_control >> 1) != 0 ) specular *= specular;
r10427r10428
19531959         luma += face;
19541960
19551961         /* extract distance coefficient */
1956         coef = geo.coef_table[attr>>27];
1962         coef = geo->coef_table[attr>>27];
19571963
19581964         /* calculate texture level of detail */
1959         distance = coef * fabs( dotp ) * geo.lod;
1965         distance = coef * fabs( dotp ) * geo->lod;
19601966
19611967         /* push to the 3d rasterizer */
1962         model2_3d_push( luma << 15 );
1963         model2_3d_push( f2u(distance) >> 8 );
1964         model2_3d_push( f2u(point.x) >> 8 );
1965         model2_3d_push( f2u(point.y) >> 8 );
1966         model2_3d_push( f2u(point.pz) >> 8 );
1968         model2_3d_push( raster, luma << 15 );
1969         model2_3d_push( raster, f2u(distance) >> 8 );
1970         model2_3d_push( raster, f2u(point.x) >> 8 );
1971         model2_3d_push( raster, f2u(point.y) >> 8 );
1972         model2_3d_push( raster, f2u(point.pz) >> 8 );
19671973
19681974         /* if it's a quad, push one more point */
19691975         if ( attr & 1 )
r10427r10428
19741980            point.pz = u2f( *input++ );
19751981
19761982            /* transform with the current matrix */
1977            transform_point( &point, geo.matrix );
1983            transform_point( &point, geo->matrix );
19781984
19791985            /* save for normal calculation */
19801986            p3.x = point.x; p3.y = point.y; p3.pz = point.pz;
19811987
19821988            /* apply focus */
1983            point.x *= geo.focus.x;
1984            point.y *= geo.focus.y;
1989            point.x *= geo->focus.x;
1990            point.y *= geo->focus.y;
19851991
19861992            /* push to the 3d rasterizer */
1987            model2_3d_push( f2u(point.x) >> 8 );
1988            model2_3d_push( f2u(point.y) >> 8 );
1989            model2_3d_push( f2u(point.pz) >> 8 );
1993            model2_3d_push( raster, f2u(point.x) >> 8 );
1994            model2_3d_push( raster, f2u(point.y) >> 8 );
1995            model2_3d_push( raster, f2u(point.pz) >> 8 );
19901996         }
19911997         else
19921998         {
r10427r10428
20312037   }
20322038
20332039   /* notify the 3d rasterizer we're done */
2034   model2_3d_push( 0 );
2040   model2_3d_push( raster, 0 );
20352041}
20362042
20372043/*******************************************
r10427r10428
20412047 *******************************************/
20422048
20432049/* Command 00: NOP */
2044static UINT32 * geo_nop( UINT32 opcode, UINT32 *input )
2050static UINT32 * geo_nop( geo_state *geo, UINT32 opcode, UINT32 *input )
20452051{
2052   raster_state *raster = geo->raster;
2053
20462054   /* push the opcode to the 3d rasterizer */
2047   model2_3d_push( opcode >> 23 );
2055   model2_3d_push( raster, opcode >> 23 );
20482056
20492057   return input;
20502058}
20512059
20522060/* Command 01: Object Data */
2053static UINT32 * geo_object_data( UINT32 opcode, UINT32 *input )
2061static UINT32 * geo_object_data( geo_state *geo, UINT32 opcode, UINT32 *input )
20542062{
2063   raster_state *raster = geo->raster;
20552064   UINT32   tpa = *input++;      /* Texture Point Address */
20562065   UINT32   tha = *input++;      /* Texture Header Address */
20572066   UINT32   oba = *input++;      /* Object Address */
r10427r10428
20602069   UINT32 *obp;            /* Object Pointer */
20612070
20622071   /* push the initial set of data to the 3d rasterizer */
2063   model2_3d_push( opcode >> 23 );
2064   model2_3d_push( tpa );
2065   model2_3d_push( tha );
2072   model2_3d_push( raster, opcode >> 23 );
2073   model2_3d_push( raster, tpa );
2074   model2_3d_push( raster, tha );
20662075
20672076   /* select where we're reading polygon information from */
20682077   if ( oba & 0x01000000 )
20692078   {
20702079      /* Fast polygon RAM */
2071      obp = &geo.polygon_ram0[oba & 0x7FFF];
2080      obp = &geo->polygon_ram0[oba & 0x7FFF];
20722081   }
20732082   else if ( oba & 0x00800000 )
20742083   {
20752084      /* Polygon ROM */
2076      obp = &geo.polygon_rom[oba & 0x7FFFFF];
2085      obp = &geo->polygon_rom[oba & 0x7FFFFF];
20772086   }
20782087   else
20792088   {
20802089      /* Slow Polygon RAM */
2081      obp = &geo.polygon_ram1[oba & 0x7FFF];
2090      obp = &geo->polygon_ram1[oba & 0x7FFF];
20822091   }
20832092
2084   switch( geo.mode & 3 )
2093   switch( geo->mode & 3 )
20852094   {
20862095      /* Normals present, No Specular */
2087      case 0:   geo_parse_np_ns( obp, obc ); break;
2096      case 0:   geo_parse_np_ns( geo, obp, obc ); break;
20882097
20892098      /* Normals present, Specular */
2090      case 1: geo_parse_np_s( obp, obc ); break;
2099      case 1: geo_parse_np_s( geo, obp, obc ); break;
20912100
20922101      /* No Normals present, No Specular */
2093      case 2: geo_parse_nn_ns( obp, obc ); break;
2102      case 2: geo_parse_nn_ns( geo, obp, obc ); break;
20942103
20952104      /* No Normals present, Specular */
2096      case 3: geo_parse_nn_s( obp, obc ); break;
2105      case 3: geo_parse_nn_s( geo, obp, obc ); break;
20972106   }
20982107
20992108   /* move by 4 parameters */
r10427r10428
21012110}
21022111
21032112/* Command 02: Direct Data */
2104static UINT32 * geo_direct_data( UINT32 opcode, UINT32 *input )
2113static UINT32 * geo_direct_data( geo_state *geo, UINT32 opcode, UINT32 *input )
21052114{
2115   raster_state *raster = geo->raster;
21062116   UINT32   tpa = *input++;      /* Texture Point Address */
21072117   UINT32   tha = *input++;      /* Texture Header Address */
21082118   UINT32   attr;
21092119
21102120   /* push the initial set of data to the 3d rasterizer */
2111   model2_3d_push( (opcode >> 23) - 1 );
2112   model2_3d_push( tpa );
2113   model2_3d_push( tha );
2121   model2_3d_push( raster, (opcode >> 23) - 1 );
2122   model2_3d_push( raster, tpa );
2123   model2_3d_push( raster, tha );
21142124
21152125   /* push the initial points */
2116   model2_3d_push( (*input++) >> 8 ); /* x */
2117   model2_3d_push( (*input++) >> 8 ); /* y */
2118   model2_3d_push( (*input++) >> 8 ); /* z */
2126   model2_3d_push( raster, (*input++) >> 8 ); /* x */
2127   model2_3d_push( raster, (*input++) >> 8 ); /* y */
2128   model2_3d_push( raster, (*input++) >> 8 ); /* z */
21192129
2120   model2_3d_push( (*input++) >> 8 ); /* x */
2121   model2_3d_push( (*input++) >> 8 ); /* y */
2122   model2_3d_push( (*input++) >> 8 ); /* z */
2130   model2_3d_push( raster, (*input++) >> 8 ); /* x */
2131   model2_3d_push( raster, (*input++) >> 8 ); /* y */
2132   model2_3d_push( raster, (*input++) >> 8 ); /* z */
21232133
21242134   do
21252135   {
r10427r10428
21302140         break;
21312141
21322142      /* push attributes */
2133      model2_3d_push( attr & 0x00FFFFFF );
2143      model2_3d_push( raster, attr & 0x00FFFFFF );
21342144
21352145      /* push luma */
2136      model2_3d_push( (*input++) >> 8 );
2146      model2_3d_push( raster, (*input++) >> 8 );
21372147
21382148      /* push distance */
2139      model2_3d_push( (*input++) >> 8 );
2149      model2_3d_push( raster, (*input++) >> 8 );
21402150
21412151      /* push the next point */
2142      model2_3d_push( (*input++) >> 8 ); /* x */
2143      model2_3d_push( (*input++) >> 8 ); /* y */
2144      model2_3d_push( (*input++) >> 8 ); /* z */
2152      model2_3d_push( raster, (*input++) >> 8 ); /* x */
2153      model2_3d_push( raster, (*input++) >> 8 ); /* y */
2154      model2_3d_push( raster, (*input++) >> 8 ); /* z */
21452155
21462156      /* if it's a quad, output another point */
21472157      if ( attr & 1 )
21482158      {
2149         model2_3d_push( (*input++) >> 8 ); /* x */
2150         model2_3d_push( (*input++) >> 8 ); /* y */
2151         model2_3d_push( (*input++) >> 8 ); /* z */
2159         model2_3d_push( raster, (*input++) >> 8 ); /* x */
2160         model2_3d_push( raster, (*input++) >> 8 ); /* y */
2161         model2_3d_push( raster, (*input++) >> 8 ); /* z */
21522162      }
21532163   } while( 1 );
21542164
21552165   /* we're done */
2156   model2_3d_push( 0 );
2166   model2_3d_push( raster, 0 );
21572167
21582168   return input;
21592169}
21602170
21612171/* Command 03: Window Data */
2162static UINT32 * geo_window_data( UINT32 opcode, UINT32 *input )
2172static UINT32 * geo_window_data( geo_state *geo, UINT32 opcode, UINT32 *input )
21632173{
2174   raster_state *raster = geo->raster;
21642175   UINT32   x, y, i;
21652176
21662177   /* start by pushing the opcode */
2167   model2_3d_push( opcode >> 23 );
2178   model2_3d_push( raster, opcode >> 23 );
21682179
21692180   /*
21702181        we're going to move 6 coordinates to the 3d rasterizer:
r10427r10428
21862197      y &= 0xFFF;
21872198
21882199      /* push it */
2189      model2_3d_push( x | y );
2200      model2_3d_push( raster, x | y );
21902201   }
21912202
21922203   return input;
21932204}
21942205
21952206/* Command 04: Texture Data Write */
2196static UINT32 * geo_texture_data( UINT32 opcode, UINT32 *input )
2207static UINT32 * geo_texture_data( geo_state *geo, UINT32 opcode, UINT32 *input )
21972208{
2209   raster_state *raster = geo->raster;
21982210   UINT32   i, count;
21992211
22002212   /* start by pushing the opcode */
2201   model2_3d_push( opcode >> 23 );
2213   model2_3d_push( raster, opcode >> 23 );
22022214
22032215   /* push the starting address/dsp id */
2204   model2_3d_push( *input++ );
2216   model2_3d_push( raster, *input++ );
22052217
22062218   /* get the count */
22072219   count = *input++;
22082220
22092221   /* push the count */
2210   model2_3d_push( count );
2222   model2_3d_push( raster, count );
22112223
22122224   /* loop and send the data */
22132225   for( i = 0; i < count; i++ )
2214      model2_3d_push( *input++ );
2226      model2_3d_push( raster, *input++ );
22152227
22162228   return input;
22172229}
22182230
22192231/* Command 05: Polygon Data */
2220static UINT32 * geo_polygon_data( UINT32 opcode, UINT32 *input )
2232static UINT32 * geo_polygon_data( geo_state *geo, UINT32 opcode, UINT32 *input )
22212233{
22222234   UINT32   address, count, i;
22232235   UINT32 *p;
r10427r10428
22312243   if ( address & 0x01000000 )
22322244   {
22332245      /* Fast polygon RAM */
2234      p = &geo.polygon_ram0[address & 0x7FFF];
2246      p = &geo->polygon_ram0[address & 0x7FFF];
22352247   }
22362248   else
22372249   {
22382250      /* Slow Polygon RAM */
2239      p = &geo.polygon_ram1[address & 0x7FFF];
2251      p = &geo->polygon_ram1[address & 0x7FFF];
22402252   }
22412253
22422254   /* read the count */
r10427r10428
22502262}
22512263
22522264/* Command 06: Texture Parameters */
2253static UINT32 * geo_texture_parameters( UINT32 opcode, UINT32 *input )
2265static UINT32 * geo_texture_parameters( geo_state *geo, UINT32 opcode, UINT32 *input )
22542266{
22552267   UINT32   index, count, i, param;
22562268
r10427r10428
22672279      /* read in the texture parameters */
22682280      param = *input++;
22692281
2270      geo.texture_parameters[index].diffuse = (float)( param & 0xFF );
2271      geo.texture_parameters[index].ambient = (float)( (param >> 8) & 0xFF );
2272      geo.texture_parameters[index].specular_control = (param >> 24) & 0xFF;
2273      geo.texture_parameters[index].specular_scale = (float)( (param >> 16) & 0xFF );
2282      geo->texture_parameters[index].diffuse = (float)( param & 0xFF );
2283      geo->texture_parameters[index].ambient = (float)( (param >> 8) & 0xFF );
2284      geo->texture_parameters[index].specular_control = (param >> 24) & 0xFF;
2285      geo->texture_parameters[index].specular_scale = (float)( (param >> 16) & 0xFF );
22742286
22752287      /* read in the distance coefficient */
2276      geo.coef_table[index] = u2f(*input++);
2288      geo->coef_table[index] = u2f(*input++);
22772289
22782290      index = (index + 1) & 0x1F;
22792291   }
r10427r10428
22822294}
22832295
22842296/* Command 07: Geo Mode */
2285static UINT32 * geo_mode( UINT32 opcode, UINT32 *input )
2297static UINT32 * geo_mode( geo_state *geo, UINT32 opcode, UINT32 *input )
22862298{
22872299   (void)opcode;
22882300
22892301   /* read in the mode */
2290   geo.mode = *input++;
2302   geo->mode = *input++;
22912303
22922304   return input;
22932305}
22942306
22952307/* Command 08: ZSort Mode */
2296static UINT32 * geo_zsort_mode( UINT32 opcode, UINT32 *input )
2308static UINT32 * geo_zsort_mode( geo_state *geo, UINT32 opcode, UINT32 *input )
22972309{
2310   raster_state *raster = geo->raster;
2311
22982312   /* push the opcode */
2299   model2_3d_push( opcode >> 23 );
2313   model2_3d_push( raster, opcode >> 23 );
23002314
23012315   /* push the mode */
2302   model2_3d_push( (*input++) >> 8 );
2316   model2_3d_push( raster, (*input++) >> 8 );
23032317
23042318   return input;
23052319}
23062320
23072321/* Command 09: Focal Distance */
2308static UINT32 * geo_focal_distance( UINT32 opcode, UINT32 *input )
2322static UINT32 * geo_focal_distance( geo_state *geo, UINT32 opcode, UINT32 *input )
23092323{
23102324   (void)opcode;
23112325
23122326   /* read the x focus value */
2313   geo.focus.x = u2f( *input++ );
2327   geo->focus.x = u2f( *input++ );
23142328
23152329   /* read the y focus value */
2316   geo.focus.y = u2f( *input++ );
2330   geo->focus.y = u2f( *input++ );
23172331
23182332   return input;
23192333}
23202334
23212335/* Command 0A: Light Source Vector Write */
2322static UINT32 * geo_light_source( UINT32 opcode, UINT32 *input )
2336static UINT32 * geo_light_source( geo_state *geo, UINT32 opcode, UINT32 *input )
23232337{
23242338   (void)opcode;
23252339
23262340   /* read the x light value */
2327   geo.light.x = u2f( *input++ );
2341   geo->light.x = u2f( *input++ );
23282342
23292343   /* read the y light value */
2330   geo.light.y = u2f( *input++ );
2344   geo->light.y = u2f( *input++ );
23312345
23322346   /* read the z light value */
2333   geo.light.pz = u2f( *input++ );
2347   geo->light.pz = u2f( *input++ );
23342348
23352349   return input;
23362350}
23372351
23382352/* Command 0B: Transformation Matrix Write */
2339static UINT32 * geo_matrix_write( UINT32 opcode, UINT32 *input )
2353static UINT32 * geo_matrix_write( geo_state *geo, UINT32 opcode, UINT32 *input )
23402354{
23412355   UINT32   i;
23422356
r10427r10428
23442358
23452359   /* read in the transformation matrix */
23462360   for( i = 0; i < 12; i++ )
2347      geo.matrix[i] = u2f( *input++ );
2361      geo->matrix[i] = u2f( *input++ );
23482362
23492363   return input;
23502364}
23512365
23522366/* Command 0C: Parallel Transfer Vector Write */
2353static UINT32 * geo_translate_write( UINT32 opcode, UINT32 *input )
2367static UINT32 * geo_translate_write( geo_state *geo, UINT32 opcode, UINT32 *input )
23542368{
23552369   UINT32   i;
23562370
r10427r10428
23582372
23592373   /* read in the translation vector */
23602374   for( i = 0; i < 3; i++ )
2361      geo.matrix[i+9] = u2f( *input++ );
2375      geo->matrix[i+9] = u2f( *input++ );
23622376
23632377   return input;
23642378}
23652379
23662380/* Command 0D: Geo Data Memory Push (undocumented, unsupported) */
2367static UINT32 * geo_data_mem_push( UINT32 opcode, UINT32 *input )
2381static UINT32 * geo_data_mem_push( geo_state *geo, UINT32 opcode, UINT32 *input )
23682382{
23692383   UINT32   address, count, i;
23702384
r10427r10428
24012415}
24022416
24032417/* Command 0E: Geo Test */
2404static UINT32 * geo_test( UINT32 opcode, UINT32 *input )
2418static UINT32 * geo_test( geo_state *geo, UINT32 opcode, UINT32 *input )
24052419{
24062420   UINT32      data, blocks, address, count, checksum, i;
24072421
r10427r10428
24432457
24442458      for( j = 0; j < count; j++ )
24452459      {
2446         data = geo.polygon_rom[address++];
2460         data = geo->polygon_rom[address++];
24472461
24482462         address &= 0x7FFFFF;
24492463
r10427r10428
24712485}
24722486
24732487/* Command 0F: End */
2474static UINT32 * geo_end( UINT32 opcode, UINT32 *input )
2488static UINT32 * geo_end( geo_state *geo, UINT32 opcode, UINT32 *input )
24752489{
2490   raster_state *raster = geo->raster;
2491
24762492   (void)opcode;
24772493
24782494   /* signal the end of this data block the rasterizer */
2479   model2_3d_push( 0xFF000000 );
2495   model2_3d_push( raster, 0xFF000000 );
24802496
24812497   /* signal end by returning NULL */
24822498   return NULL;
24832499}
24842500
24852501/* Command 10: Dummy */
2486static UINT32 * geo_dummy( UINT32 opcode, UINT32 *input )
2502static UINT32 * geo_dummy( geo_state *geo, UINT32 opcode, UINT32 *input )
24872503{
24882504   UINT32   data;
24892505   (void)opcode;
r10427r10428
24952511}
24962512
24972513/* Command 14: Log Data Write */
2498static UINT32 * geo_log_data( UINT32 opcode, UINT32 *input )
2514static UINT32 * geo_log_data( geo_state *geo, UINT32 opcode, UINT32 *input )
24992515{
2516   raster_state *raster = geo->raster;
25002517   UINT32   i, count;
25012518
25022519   /* start by pushing the opcode */
2503   model2_3d_push( opcode >> 23 );
2520   model2_3d_push( raster, opcode >> 23 );
25042521
25052522   /* push the starting address/dsp id */
2506   model2_3d_push( *input++ );
2523   model2_3d_push( raster, *input++ );
25072524
25082525   /* get the count */
25092526   count = *input++;
25102527
25112528   /* push the count */
2512   model2_3d_push( count << 2 );
2529   model2_3d_push( raster, count << 2 );
25132530
25142531   /* loop and send the data */
25152532   for( i = 0; i < count; i++ )
25162533   {
25172534      UINT32   data = *input++;
25182535
2519      model2_3d_push( data & 0xff );
2520      model2_3d_push( (data >> 8) & 0xff );
2521      model2_3d_push( (data >> 16) & 0xff );
2522      model2_3d_push( (data >> 24) & 0xff );
2536      model2_3d_push( raster, data & 0xff );
2537      model2_3d_push( raster, (data >> 8) & 0xff );
2538      model2_3d_push( raster, (data >> 16) & 0xff );
2539      model2_3d_push( raster, (data >> 24) & 0xff );
25232540   }
25242541
25252542   return input;
25262543}
25272544
25282545/* Command 16: LOD */
2529static UINT32 * geo_lod( UINT32 opcode, UINT32 *input )
2546static UINT32 * geo_lod( geo_state *geo, UINT32 opcode, UINT32 *input )
25302547{
25312548   (void)opcode;
25322549
25332550   /* read in the LOD */
2534   geo.lod = u2f(*input++);
2551   geo->lod = u2f(*input++);
25352552
25362553   return input;
25372554}
25382555
25392556/* Command 1D: Code Upload  (undocumented, unsupported) */
2540static UINT32 * geo_code_upload( UINT32 opcode, UINT32 *input )
2557static UINT32 * geo_code_upload( geo_state *geo, UINT32 opcode, UINT32 *input )
25412558{
25422559   UINT32   flags, count, i;
25432560
r10427r10428
25852602}
25862603
25872604/* Command 1E: Code Jump (undocumented, unsupported) */
2588static UINT32 * geo_code_jump( UINT32 opcode, UINT32 *input )
2605static UINT32 * geo_code_jump( geo_state *geo, UINT32 opcode, UINT32 *input )
25892606{
25902607   UINT32   address;
25912608
r10427r10428
26092626   return input;
26102627}
26112628
2612static UINT32 * geo_process_command( UINT32 opcode, UINT32 *input )
2629static UINT32 * geo_process_command( geo_state *geo, UINT32 opcode, UINT32 *input )
26132630{
26142631   switch( opcode >> 23 )
26152632   {
2616      case 0x00: input = geo_nop( opcode, input );            break;
2617      case 0x01: input = geo_object_data( opcode, input );      break;
2618      case 0x02: input = geo_direct_data( opcode, input );      break;
2619      case 0x03: input = geo_window_data( opcode, input );      break;
2620      case 0x04: input = geo_texture_data( opcode, input );      break;
2621      case 0x05: input = geo_polygon_data( opcode, input );      break;
2622      case 0x06: input = geo_texture_parameters( opcode, input );   break;
2623      case 0x07: input = geo_mode( opcode, input );            break;
2624      case 0x08: input = geo_zsort_mode( opcode, input );         break;
2625      case 0x09: input = geo_focal_distance( opcode, input );      break;
2626      case 0x0A: input = geo_light_source( opcode, input );      break;
2627      case 0x0B: input = geo_matrix_write( opcode, input );      break;
2628      case 0x0C: input = geo_translate_write( opcode, input );   break;
2629      case 0x0D: input = geo_data_mem_push( opcode, input );      break;
2630      case 0x0E: input = geo_test( opcode, input );            break;
2631      case 0x0F: input = geo_end( opcode, input );            break;
2632      case 0x10: input = geo_dummy( opcode, input );            break;
2633      case 0x11: input = geo_object_data( opcode, input );      break;
2634      case 0x12: input = geo_direct_data( opcode, input );      break;
2635      case 0x13: input = geo_window_data( opcode, input );      break;
2636      case 0x14: input = geo_log_data( opcode, input );         break;
2637      case 0x15: input = geo_polygon_data( opcode, input );      break;
2638      case 0x16: input = geo_lod( opcode, input );            break;
2639      case 0x17: input = geo_mode( opcode, input );            break;
2640      case 0x18: input = geo_zsort_mode( opcode, input );         break;
2641      case 0x19: input = geo_focal_distance( opcode, input );      break;
2642      case 0x1A: input = geo_light_source( opcode, input );      break;
2643      case 0x1B: input = geo_matrix_write( opcode, input );      break;
2644      case 0x1C: input = geo_translate_write( opcode, input );   break;
2645      case 0x1D: input = geo_code_upload( opcode, input );      break;
2646      case 0x1E: input = geo_code_jump( opcode, input );         break;
2647      case 0x1F: input = geo_end( opcode, input );            break;
2633      case 0x00: input = geo_nop( geo, opcode, input );            break;
2634      case 0x01: input = geo_object_data( geo, opcode, input );      break;
2635      case 0x02: input = geo_direct_data( geo, opcode, input );      break;
2636      case 0x03: input = geo_window_data( geo, opcode, input );      break;
2637      case 0x04: input = geo_texture_data( geo, opcode, input );      break;
2638      case 0x05: input = geo_polygon_data( geo, opcode, input );      break;
2639      case 0x06: input = geo_texture_parameters( geo, opcode, input );   break;
2640      case 0x07: input = geo_mode( geo, opcode, input );            break;
2641      case 0x08: input = geo_zsort_mode( geo, opcode, input );         break;
2642      case 0x09: input = geo_focal_distance( geo, opcode, input );      break;
2643      case 0x0A: input = geo_light_source( geo, opcode, input );      break;
2644      case 0x0B: input = geo_matrix_write( geo, opcode, input );      break;
2645      case 0x0C: input = geo_translate_write( geo, opcode, input );   break;
2646      case 0x0D: input = geo_data_mem_push( geo, opcode, input );      break;
2647      case 0x0E: input = geo_test( geo, opcode, input );            break;
2648      case 0x0F: input = geo_end( geo, opcode, input );            break;
2649      case 0x10: input = geo_dummy( geo, opcode, input );            break;
2650      case 0x11: input = geo_object_data( geo, opcode, input );      break;
2651      case 0x12: input = geo_direct_data( geo, opcode, input );      break;
2652      case 0x13: input = geo_window_data( geo, opcode, input );      break;
2653      case 0x14: input = geo_log_data( geo, opcode, input );         break;
2654      case 0x15: input = geo_polygon_data( geo, opcode, input );      break;
2655      case 0x16: input = geo_lod( geo, opcode, input );            break;
2656      case 0x17: input = geo_mode( geo, opcode, input );            break;
2657      case 0x18: input = geo_zsort_mode( geo, opcode, input );         break;
2658      case 0x19: input = geo_focal_distance( geo, opcode, input );      break;
2659      case 0x1A: input = geo_light_source( geo, opcode, input );      break;
2660      case 0x1B: input = geo_matrix_write( geo, opcode, input );      break;
2661      case 0x1C: input = geo_translate_write( geo, opcode, input );   break;
2662      case 0x1D: input = geo_code_upload( geo, opcode, input );      break;
2663      case 0x1E: input = geo_code_jump( geo, opcode, input );         break;
2664      case 0x1F: input = geo_end( geo, opcode, input );            break;
26482665   }
26492666
26502667   return input;
26512668}
26522669
2653static void geo_parse( void )
2670static void geo_parse( model2_state *state )
26542671{
2655   UINT32   address = (geo_read_start_address/4);
2656   UINT32 *input = &model2_bufferram[address];
2672   UINT32   address = (state->geo_read_start_address/4);
2673   UINT32 *input = &state->bufferram[address];
26572674   UINT32   opcode;
26582675
2659   while( input != NULL && (input - model2_bufferram) < 0x20000  )
2676   while( input != NULL && (input - state->bufferram) < 0x20000  )
26602677   {
26612678      /* read in the opcode */
26622679      opcode = *input++;
r10427r10428
26682685         address = (opcode & 0x7FFFF) / 4;
26692686
26702687         /* update our pointer */
2671         input = &model2_bufferram[address];
2688         input = &state->bufferram[address];
26722689
26732690         /* go again */
26742691         continue;
26752692      }
26762693
26772694      /* process it */
2678      input = geo_process_command( opcode, input );
2695      input = geo_process_command( state->geo, opcode, input );
26792696   }
26802697}
26812698
26822699/***********************************************************************************************/
26832700
2684static bitmap_t *sys24_bitmap = NULL;
26852701
26862702static void model2_exit(running_machine &machine)
26872703{
2688   poly_free(poly);
2704   model2_state *state = machine.driver_data<model2_state>();
2705   poly_free(state->poly);
26892706}
26902707
26912708VIDEO_START(model2)
26922709{
2710   model2_state *state = machine->driver_data<model2_state>();
26932711   const rectangle &visarea = machine->primary_screen->visible_area();
26942712   int   width = visarea.max_x - visarea.min_x;
26952713   int   height = visarea.max_y - visarea.min_y;
26962714
26972715   sys24_tile_vh_start(machine, 0x3fff);
2698   sys24_bitmap = auto_alloc(machine, bitmap_t(width, height+4, BITMAP_FORMAT_INDEXED16));
2716   state->sys24_bitmap = auto_alloc(machine, bitmap_t(width, height+4, BITMAP_FORMAT_INDEXED16));
26992717
2700   poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), 0);
2718   state->poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), 0);
27012719   machine->add_notifier(MACHINE_NOTIFY_EXIT, model2_exit);
27022720
2721   /* initialize the hardware rasterizer */
2722   model2_3d_init( machine, (UINT16*)machine->region("user3")->base() );
2723
27032724   /* initialize the geometry engine */
27042725   geo_init( machine, (UINT32*)machine->region("user2")->base() );
2705
2706   /* initialize the hardware rasterizer */
2707   model2_3d_init( machine, (UINT16*)machine->region("user3")->base() );
27082726}
27092727
27102728static void convert_bitmap( running_machine *machine, bitmap_t *dst, bitmap_t *src, const rectangle *rect )
r10427r10428
27262744
27272745VIDEO_UPDATE(model2)
27282746{
2747   model2_state *state = screen->machine->driver_data<model2_state>();
27292748   logerror("--- frame ---\n");
27302749
27312750   bitmap_fill(bitmap, cliprect, screen->machine->pens[0]);
2732   bitmap_fill(sys24_bitmap, cliprect, 0);
2751   bitmap_fill(state->sys24_bitmap, cliprect, 0);
27332752
2734   sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 7, 0, 0);
2735   sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 6, 0, 0);
2736   sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 5, 0, 0);
2737   sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 4, 0, 0);
2753   sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 7, 0, 0);
2754   sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 6, 0, 0);
2755   sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 5, 0, 0);
2756   sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 4, 0, 0);
27382757
2739   convert_bitmap(screen->machine, bitmap, sys24_bitmap, cliprect);
2758   convert_bitmap(screen->machine, bitmap, state->sys24_bitmap, cliprect);
27402759
27412760   /* tell the rasterizer we're starting a frame */
2742   model2_3d_frame_start();
2761   model2_3d_frame_start(state);
27432762
27442763   /* let the geometry engine do it's thing */
2745   geo_parse();
2764   geo_parse(state);
27462765
27472766   /* have the rasterizer output the frame */
2748   model2_3d_frame_end( bitmap, cliprect );
2767   model2_3d_frame_end( state, bitmap, cliprect );
27492768
2750   bitmap_fill(sys24_bitmap, cliprect, 0);
2751   sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 3, 0, 0);
2752   sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 2, 0, 0);
2753   sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 1, 0, 0);
2754   sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 0, 0, 0);
2769   bitmap_fill(state->sys24_bitmap, cliprect, 0);
2770   sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 3, 0, 0);
2771   sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 2, 0, 0);
2772   sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 1, 0, 0);
2773   sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 0, 0, 0);
27552774
2756   convert_bitmap(screen->machine, bitmap, sys24_bitmap, cliprect);
2775   convert_bitmap(screen->machine, bitmap, state->sys24_bitmap, cliprect);
27572776
27582777   return 0;
27592778}
src/mame/video/sshangha.c
r10427r10428
88#include "emu.h"
99#include "includes/sshangha.h"
1010
11UINT16 *sshangha_pf2_data,*sshangha_pf1_data;
12UINT16 *sshangha_pf1_rowscroll,*sshangha_pf2_rowscroll;
13static UINT16 sshangha_control_0[8];
14static tilemap_t *pf1_8x8_tilemap,*pf1_16x16_tilemap,*pf2_tilemap;
15static int sshangha_pf1_bank,sshangha_pf2_bank,sshangha_video_control;
1611
1712/******************************************************************************/
1813
19static void sshangha_tilemap_draw(bitmap_t *bitmap, const rectangle *cliprect)
14static void sshangha_tilemap_draw(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect)
2015{
21   const bitmap_t *bitmap0 = tilemap_get_pixmap(pf1_16x16_tilemap);
22   const bitmap_t *bitmap1 = tilemap_get_pixmap(pf2_tilemap);
16   sshangha_state *state = machine->driver_data<sshangha_state>();
17   const bitmap_t *bitmap0 = tilemap_get_pixmap(state->pf1_16x16_tilemap);
18   const bitmap_t *bitmap1 = tilemap_get_pixmap(state->pf2_tilemap);
2319   int x,y,p;
2420
2521   for (y=0; y<240; y++) {
r10427r10428
3430
3531WRITE16_HANDLER (sshangha_video_w)
3632{
33   sshangha_state *state = space->machine->driver_data<sshangha_state>();
3734   /* 0x4: Special video mode, other bits unknown */
38   sshangha_video_control=data;
35   state->video_control=data;
3936//  popmessage("%04x",data);
4037}
4138
r10427r10428
112109
113110WRITE16_HANDLER( sshangha_pf2_data_w )
114111{
115   COMBINE_DATA(&sshangha_pf2_data[offset]);
116   tilemap_mark_tile_dirty(pf2_tilemap,offset);
112   sshangha_state *state = space->machine->driver_data<sshangha_state>();
113   COMBINE_DATA(&state->pf2_data[offset]);
114   tilemap_mark_tile_dirty(state->pf2_tilemap,offset);
117115}
118116
119117WRITE16_HANDLER( sshangha_pf1_data_w )
120118{
121   COMBINE_DATA(&sshangha_pf1_data[offset]);
122   tilemap_mark_tile_dirty(pf1_8x8_tilemap,offset);
123   tilemap_mark_tile_dirty(pf1_16x16_tilemap,offset);
119   sshangha_state *state = space->machine->driver_data<sshangha_state>();
120   COMBINE_DATA(&state->pf1_data[offset]);
121   tilemap_mark_tile_dirty(state->pf1_8x8_tilemap,offset);
122   tilemap_mark_tile_dirty(state->pf1_16x16_tilemap,offset);
124123}
125124
126125WRITE16_HANDLER( sshangha_control_0_w )
127126{
128   COMBINE_DATA(&sshangha_control_0[offset]);
127   sshangha_state *state = space->machine->driver_data<sshangha_state>();
128   COMBINE_DATA(&state->control_0[offset]);
129129}
130130
131131/******************************************************************************/
r10427r10428
140140
141141static TILE_GET_INFO( get_pf2_tile_info )
142142{
143   UINT16 tile=sshangha_pf2_data[tile_index];
144   SET_TILE_INFO(1,(tile&0xfff)|sshangha_pf2_bank,(tile>>12)|32,0);
143   sshangha_state *state = machine->driver_data<sshangha_state>();
144   UINT16 tile=state->pf2_data[tile_index];
145   SET_TILE_INFO(1,(tile&0xfff)|state->pf2_bank,(tile>>12)|32,0);
145146}
146147
147148static TILE_GET_INFO( get_pf1_16x16_tile_info )
148149{
149   UINT16 tile=sshangha_pf1_data[tile_index];
150   SET_TILE_INFO(1,(tile&0xfff)|sshangha_pf1_bank,tile>>12,0);
150   sshangha_state *state = machine->driver_data<sshangha_state>();
151   UINT16 tile=state->pf1_data[tile_index];
152   SET_TILE_INFO(1,(tile&0xfff)|state->pf1_bank,tile>>12,0);
151153}
152154
153155static TILE_GET_INFO( get_pf1_8x8_tile_info )
154156{
155   UINT16 tile=sshangha_pf1_data[tile_index];
156   SET_TILE_INFO(0,(tile&0xfff)|sshangha_pf1_bank,tile>>12,0);
157   sshangha_state *state = machine->driver_data<sshangha_state>();
158   UINT16 tile=state->pf1_data[tile_index];
159   SET_TILE_INFO(0,(tile&0xfff)|state->pf1_bank,tile>>12,0);
157160}
158161
159162VIDEO_START( sshangha )
160163{
161   pf1_8x8_tilemap   = tilemap_create(machine, get_pf1_8x8_tile_info,  tilemap_scan_rows, 8, 8,64,32);
162   pf1_16x16_tilemap = tilemap_create(machine, get_pf1_16x16_tile_info,tilemap_scan_rows,16,16,32,32);
163   pf2_tilemap = tilemap_create(machine, get_pf2_tile_info,tilemap_scan_rows,         16,16,32,32);
164   sshangha_state *state = machine->driver_data<sshangha_state>();
165   state->pf1_8x8_tilemap   = tilemap_create(machine, get_pf1_8x8_tile_info,  tilemap_scan_rows, 8, 8,64,32);
166   state->pf1_16x16_tilemap = tilemap_create(machine, get_pf1_16x16_tile_info,tilemap_scan_rows,16,16,32,32);
167   state->pf2_tilemap = tilemap_create(machine, get_pf2_tile_info,tilemap_scan_rows,         16,16,32,32);
164168
165   tilemap_set_transparent_pen(pf1_8x8_tilemap,0);
166   tilemap_set_transparent_pen(pf1_16x16_tilemap,0);
169   tilemap_set_transparent_pen(state->pf1_8x8_tilemap,0);
170   tilemap_set_transparent_pen(state->pf1_16x16_tilemap,0);
167171}
168172
169173/******************************************************************************/
170174
171175VIDEO_UPDATE( sshangha )
172176{
173   static int last_pf1_bank,last_pf2_bank;
177   sshangha_state *state = screen->machine->driver_data<sshangha_state>();
174178   int offs;
175179
176   flip_screen_set_no_update(screen->machine, sshangha_control_0[0]&0x80);
180   flip_screen_set_no_update(screen->machine, state->control_0[0]&0x80);
177181   tilemap_set_flip_all(screen->machine,flip_screen_x_get(screen->machine) ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
178182
179   tilemap_set_enable( pf2_tilemap, sshangha_control_0[5]&0x8000);
180   tilemap_set_enable( pf1_8x8_tilemap, sshangha_control_0[5]&0x0080);
181   tilemap_set_enable( pf1_16x16_tilemap, sshangha_control_0[5]&0x0080);
183   tilemap_set_enable( state->pf2_tilemap, state->control_0[5]&0x8000);
184   tilemap_set_enable( state->pf1_8x8_tilemap, state->control_0[5]&0x0080);
185   tilemap_set_enable( state->pf1_16x16_tilemap, state->control_0[5]&0x0080);
182186
183   sshangha_pf1_bank=((sshangha_control_0[7]>> 4)&0xf)*0x1000;
184   sshangha_pf2_bank=((sshangha_control_0[7]>>12)&0xf)*0x1000;
187   state->pf1_bank=((state->control_0[7]>> 4)&0xf)*0x1000;
188   state->pf2_bank=((state->control_0[7]>>12)&0xf)*0x1000;
185189
186   if (sshangha_pf1_bank!=last_pf1_bank) tilemap_mark_all_tiles_dirty(pf1_8x8_tilemap);
187   if (sshangha_pf1_bank!=last_pf1_bank) tilemap_mark_all_tiles_dirty(pf1_16x16_tilemap);
188   if (sshangha_pf2_bank!=last_pf2_bank) tilemap_mark_all_tiles_dirty(pf2_tilemap);
189   last_pf1_bank=sshangha_pf1_bank;
190   last_pf2_bank=sshangha_pf2_bank;
190   if (state->pf1_bank!=state->last_pf1_bank) tilemap_mark_all_tiles_dirty(state->pf1_8x8_tilemap);
191   if (state->pf1_bank!=state->last_pf1_bank) tilemap_mark_all_tiles_dirty(state->pf1_16x16_tilemap);
192   if (state->pf2_bank!=state->last_pf2_bank) tilemap_mark_all_tiles_dirty(state->pf2_tilemap);
193   state->last_pf1_bank=state->pf1_bank;
194   state->last_pf2_bank=state->pf2_bank;
191195
192196   /* Rowscroll - todo, this might actually be col scroll, or both row & col combined.  Check.. */
193   if (sshangha_control_0[6]&0x40) {
194      tilemap_set_scroll_rows(pf1_8x8_tilemap,256);
195      tilemap_set_scroll_rows(pf1_16x16_tilemap,256);
197   if (state->control_0[6]&0x40) {
198      tilemap_set_scroll_rows(state->pf1_8x8_tilemap,256);
199      tilemap_set_scroll_rows(state->pf1_16x16_tilemap,256);
196200      for (offs=0; offs<256; offs++) {
197         tilemap_set_scrollx( pf1_8x8_tilemap,0, sshangha_control_0[1] + sshangha_pf1_rowscroll[offs+0x200] );
198         tilemap_set_scrollx( pf1_16x16_tilemap,0, sshangha_control_0[1] + sshangha_pf1_rowscroll[offs+0x200] );
201         tilemap_set_scrollx( state->pf1_8x8_tilemap,0, state->control_0[1] + state->pf1_rowscroll[offs+0x200] );
202         tilemap_set_scrollx( state->pf1_16x16_tilemap,0, state->control_0[1] + state->pf1_rowscroll[offs+0x200] );
199203      }
200204   } else {
201      tilemap_set_scroll_rows(pf1_16x16_tilemap,1);
202      tilemap_set_scroll_rows(pf1_8x8_tilemap,1);
203      tilemap_set_scrollx( pf1_8x8_tilemap,0, sshangha_control_0[1] );
204      tilemap_set_scrollx( pf1_16x16_tilemap,0, sshangha_control_0[1] );
205      tilemap_set_scroll_rows(state->pf1_16x16_tilemap,1);
206      tilemap_set_scroll_rows(state->pf1_8x8_tilemap,1);
207      tilemap_set_scrollx( state->pf1_8x8_tilemap,0, state->control_0[1] );
208      tilemap_set_scrollx( state->pf1_16x16_tilemap,0, state->control_0[1] );
205209   }
206210
207   if (sshangha_control_0[6]&0x4000) {
208      tilemap_set_scroll_rows(pf2_tilemap,256);
211   if (state->control_0[6]&0x4000) {
212      tilemap_set_scroll_rows(state->pf2_tilemap,256);
209213      for (offs=0; offs<256; offs++) {
210         tilemap_set_scrollx( pf2_tilemap,0, sshangha_control_0[3] - 3 + sshangha_pf2_rowscroll[offs+0x200] );
214         tilemap_set_scrollx( state->pf2_tilemap,0, state->control_0[3] - 3 + state->pf2_rowscroll[offs+0x200] );
211215      }
212216   } else {
213      tilemap_set_scroll_rows(pf2_tilemap,1);
214      tilemap_set_scrollx( pf2_tilemap,0, sshangha_control_0[3] - 3 );
217      tilemap_set_scroll_rows(state->pf2_tilemap,1);
218      tilemap_set_scrollx( state->pf2_tilemap,0, state->control_0[3] - 3 );
215219   }
216220
217   tilemap_set_scrolly( pf2_tilemap,0, sshangha_control_0[4] );
218   tilemap_set_scrolly( pf1_8x8_tilemap,0, sshangha_control_0[2] );
219   tilemap_set_scrolly( pf1_16x16_tilemap,0, sshangha_control_0[2] );
221   tilemap_set_scrolly( state->pf2_tilemap,0, state->control_0[4] );
222   tilemap_set_scrolly( state->pf1_8x8_tilemap,0, state->control_0[2] );
223   tilemap_set_scrolly( state->pf1_16x16_tilemap,0, state->control_0[2] );
220224
221   //if ((sshangha_control_0[5]&0x8000)==0) /* <- used on hot-b logo and girl presentation screens */
225   //if ((state->control_0[5]&0x8000)==0) /* <- used on hot-b logo and girl presentation screens */
222226   bitmap_fill(bitmap,cliprect,get_black_pen(screen->machine));
223227
224228   /* Super Shanghai has a mode where the two tilemaps are combined to
225229    produce a 6bpp tilemap.  We can't precompute this as any tiles can be
226230    used in any tilemap, so we plot it on the fly */
227   if ((sshangha_video_control&4)==0) {
228      sshangha_tilemap_draw(bitmap, cliprect);
231   if ((state->video_control&4)==0) {
232      sshangha_tilemap_draw(screen->machine, bitmap, cliprect);
229233      draw_sprites(screen->machine, bitmap, cliprect, screen->machine->generic.spriteram.u16,0x4000,0x4000);
230234   }
231235   else {
232      tilemap_draw(bitmap,cliprect,pf2_tilemap,0,0);
236      tilemap_draw(bitmap,cliprect,state->pf2_tilemap,0,0);
233237      draw_sprites(screen->machine, bitmap, cliprect, screen->machine->generic.spriteram.u16,0x4000,0x4000);
234238
235      if (sshangha_control_0[6]&0x80)
236         tilemap_draw(bitmap,cliprect,pf1_8x8_tilemap,0,0);
239      if (state->control_0[6]&0x80)
240         tilemap_draw(bitmap,cliprect,state->pf1_8x8_tilemap,0,0);
237241      else
238         tilemap_draw(bitmap,cliprect,pf1_16x16_tilemap,0,0);
242         tilemap_draw(bitmap,cliprect,state->pf1_16x16_tilemap,0,0);
239243   }
240244
241245   draw_sprites(screen->machine, bitmap, cliprect, screen->machine->generic.spriteram2.u16,0x0000,0x0000);
src/mame/video/model3.c
r10427r10428
1010
1111
1212
13typedef float MATRIX[4][4];
14typedef float VECTOR[4];
15typedef float VECTOR3[3];
1613
17typedef struct {
18   float x,y,z,d;
19} PLANE;
2014
2115typedef struct
2216{
r10427r10428
2923   UINT32 color;
3024} TRIANGLE;
3125
32typedef struct _cached_texture cached_texture;
3326struct _cached_texture
3427{
3528   cached_texture *next;
r10427r10428
4437struct _poly_extra_data
4538{
4639   cached_texture *texture;
40   bitmap_t *zbuffer;
4741   UINT32 color;
4842   UINT8 texture_param;
4943   int polygon_transparency;
r10427r10428
6256/* forward declarations */
6357static void real3d_traverse_display_list(running_machine *machine);
6458static void draw_model(running_machine *machine, UINT32 addr);
65static void init_matrix_stack(void);
66static void get_top_matrix(MATRIX *out);
67static void push_matrix_stack(void);
68static void pop_matrix_stack(void);
69static void multiply_matrix_stack(MATRIX matrix);
70static void translate_matrix_stack(float x, float y, float z);
59static void init_matrix_stack(running_machine *machine);
60static void get_top_matrix(model3_state *state, MATRIX *out);
61static void push_matrix_stack(model3_state *state);
62static void pop_matrix_stack(model3_state *state);
63static void multiply_matrix_stack(model3_state *state, MATRIX matrix);
64static void translate_matrix_stack(model3_state *state, float x, float y, float z);
7165static void traverse_list(running_machine *machine, UINT32 address);
7266static void draw_block(running_machine *machine, UINT32 address);
7367static void draw_viewport(running_machine *machine, int pri, UINT32 address);
r10427r10428
7569
7670/*****************************************************************************/
7771
78UINT64 *paletteram64;
7972
80static UINT8 model3_layer_enable = 0;
81static UINT32 layer_modulate_r;
82static UINT32 layer_modulate_g;
83static UINT32 layer_modulate_b;
84static UINT32 model3_layer_modulate1;
85static UINT32 model3_layer_modulate2;
86static UINT64 layer_scroll[2];
8773
88static UINT64 *m3_char_ram;
89static UINT64 *m3_tile_ram;
9074
91static UINT32 *texture_fifo;
92static int texture_fifo_pos = 0;
9375
94static UINT16 *texture_ram[2];
95static UINT32 *display_list_ram;
96static UINT32 *culling_ram;
97static UINT32 *polygon_ram;
9876
99static UINT16 *pal_lookup;
10077
101static int real3d_display_list = 0;
10278
103static bitmap_t *bitmap3d;
104static bitmap_t *zbuffer;
105static rectangle clip3d;
106static rectangle *screen_clip;
10779
10880
109static VECTOR3 parallel_light;
110static float parallel_light_intensity;
111static float ambient_light_intensity;
11281
113static poly_manager *poly;
114static cached_texture *texcache[2][1024/32][2048/32];
11582
11683
117static int list_depth = 0;
11884
11985
120static int tick = 0;
121static int debug_layer_disable = 0;
12286
12387
124static UINT64 vid_reg0;
12588
12689/* matrix stack */
12790#define MATRIX_STACK_SIZE   256
12891
129static int matrix_stack_ptr = 0;
130static MATRIX matrix_stack[MATRIX_STACK_SIZE];
13192
13293#ifdef UNUSED_DEFINITION
13394static const int num_bits[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
13495#endif
13596
136static MATRIX coordinate_system;
137static float viewport_focal_length;
138static int viewport_region_x;
139static int viewport_region_y;
140static int viewport_region_width;
141static int viewport_region_height;
14297
143static PLANE clip_plane[5];
14498
145static UINT32 matrix_base_address;
14699
147100
148101#define BYTE_REVERSE32(x)      (((x >> 24) & 0xff) | \
r10427r10428
155108
156109static void model3_exit(running_machine &machine)
157110{
111   model3_state *state = machine.driver_data<model3_state>();
158112   invalidate_texture(&machine, 0, 0, 0, 6, 5);
159113   invalidate_texture(&machine, 1, 0, 0, 6, 5);
160   poly_free(poly);
114   poly_free(state->poly);
161115}
162116
163117VIDEO_START( model3 )
164118{
119   model3_state *state = machine->driver_data<model3_state>();
165120   int width, height;
166121
167   poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), 0);
122   state->poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), 0);
168123   machine->add_notifier(MACHINE_NOTIFY_EXIT, model3_exit);
169124
170125   width = machine->primary_screen->width();
171126   height = machine->primary_screen->height();
172   bitmap3d = machine->primary_screen->alloc_compatible_bitmap();
173   zbuffer = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED32);
127   state->bitmap3d = machine->primary_screen->alloc_compatible_bitmap();
128   state->zbuffer = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED32);
174129
175   m3_char_ram = auto_alloc_array_clear(machine, UINT64, 0x100000/8);
176   m3_tile_ram = auto_alloc_array_clear(machine, UINT64, 0x8000/8);
130   state->m3_char_ram = auto_alloc_array_clear(machine, UINT64, 0x100000/8);
131   state->m3_tile_ram = auto_alloc_array_clear(machine, UINT64, 0x8000/8);
177132
178   pal_lookup = auto_alloc_array_clear(machine, UINT16, 65536);
133   state->pal_lookup = auto_alloc_array_clear(machine, UINT16, 65536);
179134
180   texture_fifo = auto_alloc_array_clear(machine, UINT32, 0x100000/4);
135   state->texture_fifo = auto_alloc_array_clear(machine, UINT32, 0x100000/4);
181136
182137   /* 2x 4MB texture sheets */
183   texture_ram[0] = auto_alloc_array(machine, UINT16, 0x400000/2);
184   texture_ram[1] = auto_alloc_array(machine, UINT16, 0x400000/2);
138   state->texture_ram[0] = auto_alloc_array(machine, UINT16, 0x400000/2);
139   state->texture_ram[1] = auto_alloc_array(machine, UINT16, 0x400000/2);
185140
186141   /* 1MB Display List RAM */
187   display_list_ram = auto_alloc_array_clear(machine, UINT32, 0x100000/4);
142   state->display_list_ram = auto_alloc_array_clear(machine, UINT32, 0x100000/4);
188143   /* 4MB for nodes (< Step 2.0 have only 2MB) */
189   culling_ram = auto_alloc_array_clear(machine, UINT32, 0x400000/4);
144   state->culling_ram = auto_alloc_array_clear(machine, UINT32, 0x400000/4);
190145   /* 4MB Polygon RAM */
191   polygon_ram = auto_alloc_array_clear(machine, UINT32, 0x400000/4);
146   state->polygon_ram = auto_alloc_array_clear(machine, UINT32, 0x400000/4);
192147
193   tick = 0;
194   debug_layer_disable = 0;
195   vid_reg0 = 0;
148   state->tick = 0;
149   state->debug_layer_disable = 0;
150   state->vid_reg0 = 0;
196151
197   viewport_focal_length = 300.;
198   viewport_region_x = 0;
199   viewport_region_y = 0;
200   viewport_region_width = 496;
201   viewport_region_height = 384;
152   state->viewport_focal_length = 300.;
153   state->viewport_region_x = 0;
154   state->viewport_region_y = 0;
155   state->viewport_region_width = 496;
156   state->viewport_region_height = 384;
202157
203   init_matrix_stack();
158   init_matrix_stack(machine);
204159}
205160
206static void draw_tile_4bit(bitmap_t *bitmap, int tx, int ty, int tilenum)
161static void draw_tile_4bit(running_machine *machine, bitmap_t *bitmap, int tx, int ty, int tilenum)
207162{
163   model3_state *state = machine->driver_data<model3_state>();
208164   int x, y;
209   UINT8 *tile_base = (UINT8*)m3_char_ram;
165   UINT8 *tile_base = (UINT8*)state->m3_char_ram;
210166   UINT8 *tile;
211167
212168   int data = (BYTE_REVERSE16(tilenum));
r10427r10428
223179         UINT16 pix0, pix1;
224180         tile0 = *tile >> 4;
225181         tile1 = *tile & 0xf;
226         pix0 = pal_lookup[c + tile0];
227         pix1 = pal_lookup[c + tile1];
182         pix0 = state->pal_lookup[c + tile0];
183         pix1 = state->pal_lookup[c + tile1];
228184         if((pix0 & 0x8000) == 0)
229185         {
230186            d[x+0] = pix0;
r10427r10428
238194   }
239195}
240196
241static void draw_tile_8bit(bitmap_t *bitmap, int tx, int ty, int tilenum)
197static void draw_tile_8bit(running_machine *machine, bitmap_t *bitmap, int tx, int ty, int tilenum)
242198{
199   model3_state *state = machine->driver_data<model3_state>();
243200   int x, y;
244   UINT8 *tile_base = (UINT8*)m3_char_ram;
201   UINT8 *tile_base = (UINT8*)state->m3_char_ram;
245202   UINT8 *tile;
246203
247204   int data = (BYTE_REVERSE16(tilenum));
r10427r10428
258215         UINT8 tile0;
259216         UINT16 pix;
260217         tile0 = tile[xx^4];
261         pix = pal_lookup[c + tile0];
218         pix = state->pal_lookup[c + tile0];
262219         if((pix & 0x8000) == 0)
263220         {
264221            d[x] = pix;
r10427r10428
269226   }
270227}
271228#ifdef UNUSED_FUNCTION
272static void draw_texture_sheet(bitmap_t *bitmap, const rectangle *cliprect)
229static void draw_texture_sheet(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect)
273230{
231   model3_state *state = machine->driver_data<model3_state>();
274232   int x,y;
275233   for(y = cliprect->min_y; y <= cliprect->max_y; y++)
276234   {
277235      UINT16 *d = BITMAP_ADDR16(bitmap, y, 0);
278236      int index = (y*2)*2048;
279237      for(x = cliprect->min_x; x <= cliprect->max_x; x++) {
280         UINT16 pix = texture_ram[0][index];
238         UINT16 pix = state->texture_ram[0][index];
281239         index+=4;
282240         if(pix != 0) {
283241            d[x] = pix;
r10427r10428
287245}
288246#endif
289247
290static void draw_layer(bitmap_t *bitmap, const rectangle *cliprect, int layer, int bitdepth)
248static void draw_layer(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int layer, int bitdepth)
291249{
250   model3_state *state = machine->driver_data<model3_state>();
292251   int x, y;
293252   int tile_index = 0;
294   UINT16 *tiles = (UINT16*)&m3_tile_ram[layer * 0x400];
253   UINT16 *tiles = (UINT16*)&state->m3_tile_ram[layer * 0x400];
295254
296255   //logerror("Layer %d: X: %d, Y: %d\n", layer, x1, y1);
297256
298257   if(layer > 1) {
299      int modr = (model3_layer_modulate2 >> 8) & 0xff;
300      int modg = (model3_layer_modulate2 >> 16) & 0xff;
301      int modb = (model3_layer_modulate2 >> 24) & 0xff;
258      int modr = (state->layer_modulate2 >> 8) & 0xff;
259      int modg = (state->layer_modulate2 >> 16) & 0xff;
260      int modb = (state->layer_modulate2 >> 24) & 0xff;
302261      if(modr & 0x80) {
303         layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10;
262         state->layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10;
304263      } else {
305         layer_modulate_r = (modr & 0x7f) << 10;
264         state->layer_modulate_r = (modr & 0x7f) << 10;
306265      }
307266      if(modg & 0x80) {
308         layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5;
267         state->layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5;
309268      } else {
310         layer_modulate_g = (modr & 0x7f) << 5;
269         state->layer_modulate_g = (modr & 0x7f) << 5;
311270      }
312271      if(modb & 0x80) {
313         layer_modulate_b = -(0x7f - (modr & 0x7f));
272         state->layer_modulate_b = -(0x7f - (modr & 0x7f));
314273      } else {
315         layer_modulate_b = (modr & 0x7f);
274         state->layer_modulate_b = (modr & 0x7f);
316275      }
317276   } else {
318      int modr = (model3_layer_modulate1 >> 8) & 0xff;
319      int modg = (model3_layer_modulate1 >> 16) & 0xff;
320      int modb = (model3_layer_modulate1 >> 24) & 0xff;
277      int modr = (state->layer_modulate1 >> 8) & 0xff;
278      int modg = (state->layer_modulate1 >> 16) & 0xff;
279      int modb = (state->layer_modulate1 >> 24) & 0xff;
321280      if(modr & 0x80) {
322         layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10;
281         state->layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10;
323282      } else {
324         layer_modulate_r = (modr & 0x7f) << 10;
283         state->layer_modulate_r = (modr & 0x7f) << 10;
325284      }
326285      if(modg & 0x80) {
327         layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5;
286         state->layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5;
328287      } else {
329         layer_modulate_g = (modr & 0x7f) << 5;
288         state->layer_modulate_g = (modr & 0x7f) << 5;
330289      }
331290      if(modb & 0x80) {
332         layer_modulate_b = -(0x7f - (modr & 0x7f));
291         state->layer_modulate_b = -(0x7f - (modr & 0x7f));
333292      } else {
334         layer_modulate_b = (modr & 0x7f);
293         state->layer_modulate_b = (modr & 0x7f);
335294      }
336295   }
337296
r10427r10428
342301         tile_index = ((y/8) * 64);
343302         for (x = cliprect->min_x; x <= cliprect->max_x; x+=8) {
344303            UINT16 tile = tiles[tile_index ^ 0x2];
345            draw_tile_4bit(bitmap, x, y, tile);
304            draw_tile_4bit(machine, bitmap, x, y, tile);
346305            ++tile_index;
347306         }
348307      }
r10427r10428
354313         tile_index = ((y/8) * 64);
355314         for (x = cliprect->min_x; x <= cliprect->max_x; x+=8) {
356315            UINT16 tile = tiles[tile_index ^ 0x2];
357            draw_tile_8bit(bitmap, x, y, tile);
316            draw_tile_8bit(machine, bitmap, x, y, tile);
358317            ++tile_index;
359318         }
360319      }
r10427r10428
362321}
363322
364323#ifdef UNUSED_FUNCTION
365static void copy_screen(bitmap_t *bitmap, const rectangle *cliprect)
324static void copy_screen(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect)
366325{
326   model3_state *state = machine->driver_data<model3_state>();
367327   int x,y;
368328   for(y=cliprect->min_y; y <= cliprect->max_y; y++) {
369329      UINT16 *d = BITMAP_ADDR16(bitmap, y, 0);
370      UINT16 *s = BITMAP_ADDR16(bitmap3d, y, 0);
330      UINT16 *s = BITMAP_ADDR16(state->bitmap3d, y, 0);
371331      for(x=cliprect->min_x; x <= cliprect->max_x; x++) {
372332         UINT16 pix = s[x];
373333         if(!(pix & 0x8000)) {
r10427r10428
380340
381341VIDEO_UPDATE( model3 )
382342{
383/*
384    int layer_scroll_x[4], layer_scroll_y[4];
385    UINT32 layer_data[4];
343   model3_state *state = screen->machine->driver_data<model3_state>();
344#if 0
345   int layer_scroll_x[4], layer_scroll_y[4];
346   UINT32 layer_data[4];
386347
387    layer_data[0] = BYTE_REVERSE32((UINT32)(layer_scroll[0] >> 32));
388    layer_data[1] = BYTE_REVERSE32((UINT32)(layer_scroll[0] >> 0));
389    layer_data[2] = BYTE_REVERSE32((UINT32)(layer_scroll[1] >> 32));
390    layer_data[3] = BYTE_REVERSE32((UINT32)(layer_scroll[1] >> 0));
391    layer_scroll_x[0] = (layer_data[0] & 0x8000) ? (layer_data[0] & 0x1ff) : -(layer_data[0] & 0x1ff);
392    layer_scroll_y[0] = (layer_data[0] & 0x8000) ? (layer_data[0] & 0x1ff) : -(layer_data[0] & 0x1ff);
393    layer_scroll_x[1] = (layer_data[1] & 0x8000) ? (layer_data[1] & 0x1ff) : -(layer_data[1] & 0x1ff);
394    layer_scroll_y[1] = (layer_data[1] & 0x8000) ? (layer_data[1] & 0x1ff) : -(layer_data[1] & 0x1ff);
395    layer_scroll_x[2] = (layer_data[2] & 0x8000) ? (layer_data[2] & 0x1ff) : -(layer_data[2] & 0x1ff);
396    layer_scroll_y[2] = (layer_data[2] & 0x8000) ? (layer_data[2] & 0x1ff) : -(layer_data[2] & 0x1ff);
397    layer_scroll_x[3] = (layer_data[3] & 0x8000) ? (layer_data[3] & 0x1ff) : -(layer_data[3] & 0x1ff);
398    layer_scroll_y[3] = (layer_data[3] & 0x8000) ? (layer_data[3] & 0x1ff) : -(layer_data[3] & 0x1ff);
399*/
400   screen_clip = (rectangle*)cliprect;
348   layer_data[0] = BYTE_REVERSE32((UINT32)(state->layer_scroll[0] >> 32));
349   layer_data[1] = BYTE_REVERSE32((UINT32)(state->layer_scroll[0] >> 0));
350   layer_data[2] = BYTE_REVERSE32((UINT32)(state->layer_scroll[1] >> 32));
351   layer_data[3] = BYTE_REVERSE32((UINT32)(state->layer_scroll[1] >> 0));
352   layer_scroll_x[0] = (layer_data[0] & 0x8000) ? (layer_data[0] & 0x1ff) : -(layer_data[0] & 0x1ff);
353   layer_scroll_y[0] = (layer_data[0] & 0x8000) ? (layer_data[0] & 0x1ff) : -(layer_data[0] & 0x1ff);
354   layer_scroll_x[1] = (layer_data[1] & 0x8000) ? (layer_data[1] & 0x1ff) : -(layer_data[1] & 0x1ff);
355   layer_scroll_y[1] = (layer_data[1] & 0x8000) ? (layer_data[1] & 0x1ff) : -(layer_data[1] & 0x1ff);
356   layer_scroll_x[2] = (layer_data[2] & 0x8000) ? (layer_data[2] & 0x1ff) : -(layer_data[2] & 0x1ff);
357   layer_scroll_y[2] = (layer_data[2] & 0x8000) ? (layer_data[2] & 0x1ff) : -(layer_data[2] & 0x1ff);
358   layer_scroll_x[3] = (layer_data[3] & 0x8000) ? (layer_data[3] & 0x1ff) : -(layer_data[3] & 0x1ff);
359   layer_scroll_y[3] = (layer_data[3] & 0x8000) ? (layer_data[3] & 0x1ff) : -(layer_data[3] & 0x1ff);
360#endif
361   state->screen_clip = (rectangle*)cliprect;
401362
402   clip3d.min_x = cliprect->min_x;
403   clip3d.max_x = cliprect->max_x;
404   clip3d.min_y = cliprect->min_y;
405   clip3d.max_y = cliprect->max_y;
363   state->clip3d.min_x = cliprect->min_x;
364   state->clip3d.max_x = cliprect->max_x;
365   state->clip3d.min_y = cliprect->min_y;
366   state->clip3d.max_y = cliprect->max_y;
406367
407368   /* layer disable debug keys */
408   tick++;
409   if( tick >= 5 ) {
410      tick = 0;
369   state->tick++;
370   if( state->tick >= 5 ) {
371      state->tick = 0;
411372
412373      if( input_code_pressed(screen->machine, KEYCODE_Y) )
413         debug_layer_disable ^= 0x1;
374         state->debug_layer_disable ^= 0x1;
414375      if( input_code_pressed(screen->machine, KEYCODE_U) )
415         debug_layer_disable ^= 0x2;
376         state->debug_layer_disable ^= 0x2;
416377      if( input_code_pressed(screen->machine, KEYCODE_I) )
417         debug_layer_disable ^= 0x4;
378         state->debug_layer_disable ^= 0x4;
418379      if( input_code_pressed(screen->machine, KEYCODE_O) )
419         debug_layer_disable ^= 0x8;
380         state->debug_layer_disable ^= 0x8;
420381      if( input_code_pressed(screen->machine, KEYCODE_T) )
421         debug_layer_disable ^= 0x10;
382         state->debug_layer_disable ^= 0x10;
422383   }
423384
424385   bitmap_fill(bitmap, cliprect, 0);
425386
426   if (!(debug_layer_disable & 0x8))
427      draw_layer(bitmap, cliprect, 3, (model3_layer_enable >> 3) & 0x1);
387   if (!(state->debug_layer_disable & 0x8))
388      draw_layer(screen->machine, bitmap, cliprect, 3, (state->layer_enable >> 3) & 0x1);
428389
429   if (!(debug_layer_disable & 0x4))
430      draw_layer(bitmap, cliprect, 2, (model3_layer_enable >> 2) & 0x1);
390   if (!(state->debug_layer_disable & 0x4))
391      draw_layer(screen->machine, bitmap, cliprect, 2, (state->layer_enable >> 2) & 0x1);
431392
432   if( !(debug_layer_disable & 0x10) )
393   if( !(state->debug_layer_disable & 0x10) )
433394   {
434//      if(real3d_display_list) {
435//          bitmap_fill(zbuffer, cliprect, 0);
436//          bitmap_fill(bitmap3d, cliprect, 0x8000);
437//          real3d_traverse_display_list(screen->machine);
438//      }
439      copybitmap_trans(bitmap, bitmap3d, 0, 0, 0, 0, cliprect, 0x8000);
395#if 0
396      if(state->real3d_display_list) {
397         bitmap_fill(state->zbuffer, cliprect, 0);
398         bitmap_fill(state->bitmap3d, cliprect, 0x8000);
399         real3d_traverse_display_list(screen->machine);
400      }
401#endif
402      copybitmap_trans(bitmap, state->bitmap3d, 0, 0, 0, 0, cliprect, 0x8000);
440403   }
441404
442   if (!(debug_layer_disable & 0x2))
443      draw_layer(bitmap, cliprect, 1, (model3_layer_enable >> 1) & 0x1);
405   if (!(state->debug_layer_disable & 0x2))
406      draw_layer(screen->machine, bitmap, cliprect, 1, (state->layer_enable >> 1) & 0x1);
444407
445   if (!(debug_layer_disable & 0x1))
446      draw_layer(bitmap, cliprect, 0, (model3_layer_enable >> 0) & 0x1);
408   if (!(state->debug_layer_disable & 0x1))
409      draw_layer(screen->machine, bitmap, cliprect, 0, (state->layer_enable >> 0) & 0x1);
447410
448411   //copy_screen(bitmap, cliprect);
449412
450413   //draw_texture_sheet(bitmap, cliprect);
451414
452   real3d_display_list = 0;
415   state->real3d_display_list = 0;
453416   return 0;
454417}
455418
r10427r10428
457420
458421READ64_HANDLER(model3_char_r)
459422{
460   return m3_char_ram[offset];
423   model3_state *state = space->machine->driver_data<model3_state>();
424   return state->m3_char_ram[offset];
461425}
462426
463427WRITE64_HANDLER(model3_char_w)
464428{
465   COMBINE_DATA(&m3_char_ram[offset]);
429   model3_state *state = space->machine->driver_data<model3_state>();
430   COMBINE_DATA(&state->m3_char_ram[offset]);
466431}
467432
468433READ64_HANDLER(model3_tile_r)
469434{
470   return m3_tile_ram[offset];
435   model3_state *state = space->machine->driver_data<model3_state>();
436   return state->m3_tile_ram[offset];
471437}
472438
473439WRITE64_HANDLER(model3_tile_w)
474440{
475   COMBINE_DATA(&m3_tile_ram[offset]);
441   model3_state *state = space->machine->driver_data<model3_state>();
442   COMBINE_DATA(&state->m3_tile_ram[offset]);
476443}
477444
478445READ64_HANDLER(model3_vid_reg_r)
479446{
447   model3_state *state = space->machine->driver_data<model3_state>();
480448   switch(offset)
481449   {
482      case 0x00/8:   return vid_reg0;
450      case 0x00/8:   return state->vid_reg0;
483451      case 0x08/8:   return U64(0xffffffffffffffff);      /* ??? */
484      case 0x20/8:   return (UINT64)model3_layer_enable << 52;
485      case 0x40/8:   return ((UINT64)model3_layer_modulate1 << 32) | (UINT64)model3_layer_modulate2;
452      case 0x20/8:   return (UINT64)state->layer_enable << 52;
453      case 0x40/8:   return ((UINT64)state->layer_modulate1 << 32) | (UINT64)state->layer_modulate2;
486454      default:      logerror("read reg %02X\n", offset);break;
487455   }
488456   return 0;
r10427r10428
490458
491459WRITE64_HANDLER(model3_vid_reg_w)
492460{
461   model3_state *state = space->machine->driver_data<model3_state>();
493462   switch(offset)
494463   {
495      case 0x00/8:   logerror("vid_reg0: %08X%08X\n", (UINT32)(data>>32),(UINT32)(data)); vid_reg0 = data; break;
464      case 0x00/8:   logerror("vid_reg0: %08X%08X\n", (UINT32)(data>>32),(UINT32)(data)); state->vid_reg0 = data; break;
496465      case 0x08/8:   break;      /* ??? */
497466      case 0x10/8:   model3_set_irq_line(space->machine, (data >> 56) & 0x0f, CLEAR_LINE); break;      /* VBL IRQ Ack */
498467
499      case 0x20/8:   model3_layer_enable = (data >> 52);   break;
468      case 0x20/8:   state->layer_enable = (data >> 52);   break;
500469
501      case 0x40/8:   model3_layer_modulate1 = (UINT32)(data >> 32);
502                  model3_layer_modulate2 = (UINT32)(data);
470      case 0x40/8:   state->layer_modulate1 = (UINT32)(data >> 32);
471                  state->layer_modulate2 = (UINT32)(data);
503472                  break;
504      case 0x60/8:   COMBINE_DATA(&layer_scroll[0]); break;
505      case 0x68/8:   COMBINE_DATA(&layer_scroll[1]); break;
473      case 0x60/8:   COMBINE_DATA(&state->layer_scroll[0]); break;
474      case 0x68/8:   COMBINE_DATA(&state->layer_scroll[1]); break;
506475      default:      logerror("model3_vid_reg_w: %02X, %08X%08X\n", offset, (UINT32)(data >> 32), (UINT32)(data)); break;
507476   }
508477}
509478
510479WRITE64_HANDLER( model3_palette_w )
511480{
481   model3_state *state = space->machine->driver_data<model3_state>();
512482   int r1,g1,b1,r2,g2,b2;
513483   UINT32 data1,data2;
514484
515   COMBINE_DATA(&paletteram64[offset]);
516   data1 = BYTE_REVERSE32((UINT32)(paletteram64[offset] >> 32));
517   data2 = BYTE_REVERSE32((UINT32)(paletteram64[offset] >> 0));
485   COMBINE_DATA(&state->paletteram64[offset]);
486   data1 = BYTE_REVERSE32((UINT32)(state->paletteram64[offset] >> 32));
487   data2 = BYTE_REVERSE32((UINT32)(state->paletteram64[offset] >> 0));
518488
519489   r1 = ((data1 >> 0) & 0x1f);
520490   g1 = ((data1 >> 5) & 0x1f);
r10427r10428
523493   g2 = ((data2 >> 5) & 0x1f);
524494   b2 = ((data2 >> 10) & 0x1f);
525495
526   pal_lookup[(offset*2)+0] = (data1 & 0x8000) | (r1 << 10) | (g1 << 5) | b1;
527   pal_lookup[(offset*2)+1] = (data2 & 0x8000) | (r2 << 10) | (g2 << 5) | b2;
496   state->pal_lookup[(offset*2)+0] = (data1 & 0x8000) | (r1 << 10) | (g1 << 5) | b1;
497   state->pal_lookup[(offset*2)+1] = (data2 & 0x8000) | (r2 << 10) | (g2 << 5) | b2;
528498}
529499
530500READ64_HANDLER( model3_palette_r )
531501{
532   return paletteram64[offset];
502   model3_state *state = space->machine->driver_data<model3_state>();
503   return state->paletteram64[offset];
533504}
534505
535506
r10427r10428
545516*/
546517static void invalidate_texture(running_machine *machine, int page, int texx, int texy, int texwidth, int texheight)
547518{
519   model3_state *state = machine->driver_data<model3_state>();
548520   int wtiles = 1 << texwidth;
549521   int htiles = 1 << texheight;
550522   int x, y;
551523
552524   for (y = 0; y < htiles; y++)
553525      for (x = 0; x < wtiles; x++)
554         while (texcache[page][texy + y][texx + x] != NULL)
526         while (state->texcache[page][texy + y][texx + x] != NULL)
555527         {
556            cached_texture *freeme = texcache[page][texy + y][texx + x];
557            texcache[page][texy + y][texx + x] = freeme->next;
528            cached_texture *freeme = state->texcache[page][texy + y][texx + x];
529            state->texcache[page][texy + y][texx + x] = freeme->next;
558530            auto_free(machine, freeme);
559531         }
560532}
561533
562534static cached_texture *get_texture(running_machine *machine, int page, int texx, int texy, int texwidth, int texheight, int format)
563535{
564   cached_texture *tex = texcache[page][texy][texx];
536   model3_state *state = machine->driver_data<model3_state>();
537   cached_texture *tex = state->texcache[page][texy][texx];
565538   int pixheight = 32 << texheight;
566539   int pixwidth = 32 << texwidth;
567540   UINT32 alpha = ~0;
568541   int x, y;
569542
570543   /* if we have one already, validate it */
571   for (tex = texcache[page][texy][texx]; tex != NULL; tex = tex->next)
544   for (tex = state->texcache[page][texy][texx]; tex != NULL; tex = tex->next)
572545      if (tex->width == texwidth && tex->height == texheight && tex->format == format)
573546         return tex;
574547
r10427r10428
579552   tex->format = format;
580553
581554   /* set the new texture */
582   tex->next = texcache[page][texy][texx];
583   texcache[page][texy][texx] = tex;
555   tex->next = state->texcache[page][texy][texx];
556   state->texcache[page][texy][texx] = tex;
584557
585558   /* decode it */
586559   for (y = 0; y < pixheight; y++)
587560   {
588      const UINT16 *texsrc = &texture_ram[page][(texy * 32 + y) * 2048 + texx * 32];
561      const UINT16 *texsrc = &state->texture_ram[page][(texy * 32 + y) * 2048 + texx * 32];
589562      rgb_t *dest = tex->data + 2 * pixwidth * y;
590563
591564      switch (format)
r10427r10428
677650
678651WRITE64_HANDLER( real3d_display_list_w )
679652{
653   model3_state *state = space->machine->driver_data<model3_state>();
680654   if(ACCESSING_BITS_32_63) {
681      display_list_ram[offset*2] = BYTE_REVERSE32((UINT32)(data >> 32));
655      state->display_list_ram[offset*2] = BYTE_REVERSE32((UINT32)(data >> 32));
682656   }
683657   if(ACCESSING_BITS_0_31) {
684      display_list_ram[(offset*2)+1] = BYTE_REVERSE32((UINT32)(data));
658      state->display_list_ram[(offset*2)+1] = BYTE_REVERSE32((UINT32)(data));
685659   }
686660}
687661
688662WRITE64_HANDLER( real3d_polygon_ram_w )
689663{
664   model3_state *state = space->machine->driver_data<model3_state>();
690665   if(ACCESSING_BITS_32_63) {
691      polygon_ram[offset*2] = BYTE_REVERSE32((UINT32)(data >> 32));
666      state->polygon_ram[offset*2] = BYTE_REVERSE32((UINT32)(data >> 32));
692667   }
693668   if(ACCESSING_BITS_0_31) {
694      polygon_ram[(offset*2)+1] = BYTE_REVERSE32((UINT32)(data));
669      state->polygon_ram[(offset*2)+1] = BYTE_REVERSE32((UINT32)(data));
695670   }
696671}
697672
r10427r10428
707682   50, 51, 54, 55, 58, 59, 62, 63
708683};
709684
710INLINE void write_texture16(int xpos, int ypos, int width, int height, int page, UINT16 *data)
685INLINE void write_texture16(model3_state *state, int xpos, int ypos, int width, int height, int page, UINT16 *data)
711686{
712687   int x,y,i,j;
713688
r10427r10428
715690   {
716691      for(x=xpos; x < xpos+width; x+=8)
717692      {
718         UINT16 *texture = &texture_ram[page][y*2048+x];
693         UINT16 *texture = &state->texture_ram[page][y*2048+x];
719694         int b = 0;
720695         for(j=y; j < y+8; j++) {
721696            for(i=x; i < x+8; i++) {
r10427r10428
730705}
731706
732707#ifdef UNUSED_FUNCTION
733INLINE void write_texture8(int xpos, int ypos, int width, int height, int page, UINT16 *data)
708INLINE void write_texture8(model3_state *state, int xpos, int ypos, int width, int height, int page, UINT16 *data)
734709{
735710   int x,y,i,j;
736711   UINT16 color = 0x7c00;
r10427r10428
739714   {
740715      for(x=xpos; x < xpos+width; x+=8)
741716      {
742         UINT16 *texture = &texture_ram[page][y*2048+x];
717         UINT16 *texture = &state->texture_ram[page][y*2048+x];
743718         for(j=y; j < y+4; j++) {
744719            for(i=x; i < x+8; i++) {
745720               *texture = color;
r10427r10428
754729
755730static void real3d_upload_texture(running_machine *machine, UINT32 header, UINT32 *data)
756731{
732   model3_state *state = machine->driver_data<model3_state>();
757733   int width   = 32 << ((header >> 14) & 0x7);
758734   int height   = 32 << ((header >> 17) & 0x7);
759735   int xpos   = (header & 0x3f) * 32;
760736   int ypos   = ((header >> 7) & 0x1f) * 32;
761737   int page   = (header >> 20) & 0x1;
762//  int bitdepth = (header >> 23) & 0x1;
738   //int bitdepth = (header >> 23) & 0x1;
763739
764740   switch(header >> 24)
765741   {
766742      case 0x00:      /* Texture with mipmaps */
767//          if(bitdepth) {
768            write_texture16(xpos, ypos, width, height, page, (UINT16*)data);
743         //if(bitdepth) {
744            write_texture16(state, xpos, ypos, width, height, page, (UINT16*)data);
769745            invalidate_texture(machine, page, header & 0x3f, (header >> 7) & 0x1f, (header >> 14) & 0x7, (header >> 17) & 0x7);
770//          } else {
746         //} else {
771747            /* TODO: 8-bit textures are weird. need to figure out some additional bits */
772748            //logerror("W: %d, H: %d, X: %d, Y: %d, P: %d, Bit: %d, : %08X, %08X\n", width, height, xpos, ypos, page, bitdepth, header & 0x00681040, header);
773749            //write_texture8(xpos, ypos, width, height, page, (UINT16*)data);
774//          }
750         //}
775751         break;
776752      case 0x01:      /* Texture without mipmaps */
777//          if(bitdepth) {
778            write_texture16(xpos, ypos, width, height, page, (UINT16*)data);
753         //if(bitdepth) {
754            write_texture16(state, xpos, ypos, width, height, page, (UINT16*)data);
779755            invalidate_texture(machine, page, header & 0x3f, (header >> 7) & 0x1f, (header >> 14) & 0x7, (header >> 17) & 0x7);
780//          } else {
756         //} else {
781757            /* TODO: 8-bit textures are weird. need to figure out some additional bits */
782758            //logerror("W: %d, H: %d, X: %d, Y: %d, P: %d, Bit: %d, : %08X, %08X\n", width, height, xpos, ypos, page, bitdepth, header & 0x00681040, header);
783759            //write_texture8(xpos, ypos, width, height, page, (UINT16*)data);
784//          }
760         //}
785761         break;
786762      case 0x02:      /* Only mipmaps */
787763         break;
r10427r10428
795771
796772void real3d_display_list_end(running_machine *machine)
797773{
774   model3_state *state = machine->driver_data<model3_state>();
798775   /* upload textures if there are any in the FIFO */
799   if (texture_fifo_pos > 0)
776   if (state->texture_fifo_pos > 0)
800777   {
801778      int i = 0;
802      while(i < texture_fifo_pos)
779      while(i < state->texture_fifo_pos)
803780      {
804         int length = (texture_fifo[i] / 2) + 2;
805         UINT32 header = texture_fifo[i+1];
806         real3d_upload_texture(machine, header, &texture_fifo[i+2]);
781         int length = (state->texture_fifo[i] / 2) + 2;
782         UINT32 header = state->texture_fifo[i+1];
783         real3d_upload_texture(machine, header, &state->texture_fifo[i+2]);
807784         i += length;
808785      };
809786   }
810   texture_fifo_pos = 0;
811   bitmap_fill(zbuffer, NULL, 0);
812   bitmap_fill(bitmap3d, NULL, 0x8000);
787   state->texture_fifo_pos = 0;
788   bitmap_fill(state->zbuffer, NULL, 0);
789   bitmap_fill(state->bitmap3d, NULL, 0x8000);
813790   real3d_traverse_display_list(machine);
814//  real3d_display_list = 1;
791   //state->real3d_display_list = 1;
815792}
816793
817794void real3d_display_list1_dma(address_space *space, UINT32 src, UINT32 dst, int length, int byteswap)
818795{
796   model3_state *state = space->machine->driver_data<model3_state>();
819797   int i;
820798   int d = (dst & 0xffffff) / 4;
821799   for(i=0; i < length; i+=4) {
r10427r10428
825803      } else {
826804         w = space->read_dword(src);
827805      }
828      display_list_ram[d++] = w;
806      state->display_list_ram[d++] = w;
829807      src += 4;
830808   }
831809}
832810
833811void real3d_display_list2_dma(address_space *space, UINT32 src, UINT32 dst, int length, int byteswap)
834812{
813   model3_state *state = space->machine->driver_data<model3_state>();
835814   int i;
836815   int d = (dst & 0xffffff) / 4;
837816   for(i=0; i < length; i+=4) {
r10427r10428
841820      } else {
842821         w = space->read_dword(src);
843822      }
844      culling_ram[d++] = w;
823      state->culling_ram[d++] = w;
845824      src += 4;
846825   }
847826}
848827
849828void real3d_vrom_texture_dma(address_space *space, UINT32 src, UINT32 dst, int length, int byteswap)
850829{
830   model3_state *state = space->machine->driver_data<model3_state>();
851831   if((dst & 0xff) == 0) {
852832
853833      UINT32 address, header;
r10427r10428
859839         address = space->read_dword((src+0));
860840         header = space->read_dword((src+4));
861841      }
862      real3d_upload_texture(space->machine, header, (UINT32*)&model3_vrom[address]);
842      real3d_upload_texture(space->machine, header, (UINT32*)&state->vrom[address]);
863843   }
864844}
865845
866846void real3d_texture_fifo_dma(address_space *space, UINT32 src, int length, int byteswap)
867847{
848   model3_state *state = space->machine->driver_data<model3_state>();
868849   int i;
869850   for(i=0; i < length; i+=4) {
870851      UINT32 w;
r10427r10428
873854      } else {
874855         w = space->read_dword(src);
875856      }
876      texture_fifo[texture_fifo_pos] = w;
877      texture_fifo_pos++;
857      state->texture_fifo[state->texture_fifo_pos] = w;
858      state->texture_fifo_pos++;
878859      src += 4;
879860   }
880861}
881862
882863void real3d_polygon_ram_dma(address_space *space, UINT32 src, UINT32 dst, int length, int byteswap)
883864{
865   model3_state *state = space->machine->driver_data<model3_state>();
884866   int i;
885867   int d = (dst & 0xffffff) / 4;
886868   for(i=0; i < length; i+=4) {
r10427r10428
890872      } else {
891873         w = space->read_dword(src);
892874      }
893      polygon_ram[d++] = w;
875      state->polygon_ram[d++] = w;
894876      src += 4;
895877   }
896878}
r10427r10428
939921   memcpy(out, &tmp, sizeof(MATRIX));
940922}
941923
942static void init_matrix_stack(void)
924static void init_matrix_stack(running_machine *machine)
943925{
926   model3_state *state = machine->driver_data<model3_state>();
927   MATRIX *matrix_stack;
928   matrix_stack = state->matrix_stack = auto_alloc_array_clear(machine, MATRIX, MATRIX_STACK_SIZE);
929
944930   /* initialize the first matrix as identity */
945931   matrix_stack[0][0][0] = 1.0f;
946932   matrix_stack[0][0][1] = 0.0f;
r10427r10428
959945   matrix_stack[0][3][2] = 0.0f;
960946   matrix_stack[0][3][3] = 1.0f;
961947
962   matrix_stack_ptr = 0;
948   state->matrix_stack_ptr = 0;
963949}
964950
965static void get_top_matrix(MATRIX *out)
951static void get_top_matrix(model3_state *state, MATRIX *out)
966952{
967   memcpy( out, &matrix_stack[matrix_stack_ptr], sizeof(MATRIX));
953   memcpy( out, &state->matrix_stack[state->matrix_stack_ptr], sizeof(MATRIX));
968954}
969955
970static void push_matrix_stack(void)
956static void push_matrix_stack(model3_state *state)
971957{
972   matrix_stack_ptr++;
973   if (matrix_stack_ptr >= MATRIX_STACK_SIZE)
958   state->matrix_stack_ptr++;
959   if (state->matrix_stack_ptr >= MATRIX_STACK_SIZE)
974960      fatalerror("push_matrix_stack: matrix stack overflow");
975961
976   memcpy( &matrix_stack[matrix_stack_ptr], &matrix_stack[matrix_stack_ptr-1], sizeof(MATRIX));
962   memcpy( &state->matrix_stack[state->matrix_stack_ptr], &state->matrix_stack[state->matrix_stack_ptr-1], sizeof(MATRIX));
977963}
978964
979static void pop_matrix_stack(void)
965static void pop_matrix_stack(model3_state *state)
980966{
981   matrix_stack_ptr--;
982   if (matrix_stack_ptr < 0)
967   state->matrix_stack_ptr--;
968   if (state->matrix_stack_ptr < 0)
983969      fatalerror("pop_matrix_stack: matrix stack underflow");
984970}
985971
986static void multiply_matrix_stack(MATRIX matrix)
972static void multiply_matrix_stack(model3_state *state, MATRIX matrix)
987973{
988   matrix_multiply(matrix, matrix_stack[matrix_stack_ptr], &matrix_stack[matrix_stack_ptr]);
974   matrix_multiply(matrix, state->matrix_stack[state->matrix_stack_ptr], &state->matrix_stack[state->matrix_stack_ptr]);
989975}
990976
991static void translate_matrix_stack(float x, float y, float z)
977static void translate_matrix_stack(model3_state *state, float x, float y, float z)
992978{
993979   MATRIX tm;
994980
r10427r10428
997983   tm[2][0] = 0.0f;   tm[2][1] = 0.0f;   tm[2][2] = 1.0f;   tm[2][3] = 0.0f;
998984   tm[3][0] = x;      tm[3][1] = y;      tm[3][2] = z;      tm[3][3] = 1.0f;
999985
1000   matrix_multiply(tm, matrix_stack[matrix_stack_ptr], &matrix_stack[matrix_stack_ptr]);
986   matrix_multiply(tm, state->matrix_stack[state->matrix_stack_ptr], &state->matrix_stack[state->matrix_stack_ptr]);
1001987}
1002988
1003989/*****************************************************************************/
r10427r10428
10771063
10781064static void render_one(running_machine *machine, TRIANGLE *tri)
10791065{
1080   poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly);
1066   model3_state *state = machine->driver_data<model3_state>();
1067   poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(state->poly);
10811068   poly_draw_scanline_func callback = NULL;
10821069
10831070   tri->v[0].pz = 1.0f / tri->v[0].pz;
10841071   tri->v[1].pz = 1.0f / tri->v[1].pz;
10851072   tri->v[2].pz = 1.0f / tri->v[2].pz;
10861073
1074   extra->zbuffer = state->zbuffer;
10871075   if (tri->param & TRI_PARAM_TEXTURE_ENABLE)
10881076   {
10891077      tri->v[0].pu = tri->v[0].pu * tri->v[0].pz * 256.0f;
r10427r10428
11041092         callback = (tri->transparency >= 32) ? draw_scanline_normal : draw_scanline_trans;
11051093      else
11061094         callback = draw_scanline_alpha;
1107      poly_render_triangle(poly, bitmap3d, &clip3d, callback, 3, &tri->v[0], &tri->v[1], &tri->v[2]);
1095      poly_render_triangle(state->poly, state->bitmap3d, &state->clip3d, callback, 3, &tri->v[0], &tri->v[1], &tri->v[2]);
11081096   }
11091097   else
11101098   {
r10427r10428
11121100      extra->polygon_intensity   = tri->intensity;
11131101      extra->color                = tri->color;
11141102
1115      poly_render_triangle(poly, bitmap3d, &clip3d, draw_scanline_color, 1, &tri->v[0], &tri->v[1], &tri->v[2]);
1103      poly_render_triangle(state->poly, state->bitmap3d, &state->clip3d, draw_scanline_color, 1, &tri->v[0], &tri->v[1], &tri->v[2]);
11161104   }
11171105}
11181106
11191107static void draw_model(running_machine *machine, UINT32 addr)
11201108{
1121   UINT32 *model = (addr >= 0x100000) ? &model3_vrom[addr] :  &polygon_ram[addr];
1109   model3_state *state = machine->driver_data<model3_state>();
1110   UINT32 *model = (addr >= 0x100000) ? &state->vrom[addr] :  &state->polygon_ram[addr];
11221111   UINT32 header[7];
11231112   int index = 0;
11241113   int last_polygon = FALSE, back_face = FALSE;
r10427r10428
11321121   MATRIX transform_matrix;
11331122   float center_x, center_y;
11341123
1135   if(model3_step < 0x15) {   /* position coordinates are 17.15 fixed-point in Step 1.0 */
1124   if(state->step < 0x15) {   /* position coordinates are 17.15 fixed-point in Step 1.0 */
11361125      fixed_point_fraction = 1.0f / 32768.0f;
11371126   } else {               /* 13.19 fixed-point in other Steps */
11381127      fixed_point_fraction = 1.0f / 524288.0f;
11391128   }
11401129
1141   get_top_matrix(&transform_matrix);
1130   get_top_matrix(state, &transform_matrix);
11421131
11431132   /* current viewport center coordinates on screen */
1144   center_x = (float)(viewport_region_x + (viewport_region_width / 2));
1145   center_y = (float)(viewport_region_y + (viewport_region_height / 2));
1133   center_x = (float)(state->viewport_region_x + (state->viewport_region_width / 2));
1134   center_y = (float)(state->viewport_region_y + (state->viewport_region_height / 2));
11461135
11471136   memset(prev_vertex, 0, sizeof(prev_vertex));
11481137
r10427r10428
12101199            (normal[1] * transform_matrix[1][2]) +
12111200            (normal[2] * transform_matrix[2][2]);
12121201
1213      sn[0] *= coordinate_system[0][1];
1214      sn[1] *= coordinate_system[1][2];
1215      sn[2] *= coordinate_system[2][0];
1202      sn[0] *= state->coordinate_system[0][1];
1203      sn[1] *= state->coordinate_system[1][2];
1204      sn[2] *= state->coordinate_system[2][0];
12161205
12171206      /* TODO: depth bias */
12181207      /* transform vertices */
r10427r10428
12291218         matrix_multiply_vector(transform_matrix, vect, &p[i]);
12301219
12311220         /* apply coordinate system */
1232         clip_vert[i].x = p[i][0] * coordinate_system[0][1];
1233         clip_vert[i].y = p[i][1] * coordinate_system[1][2];
1234         clip_vert[i].pz = p[i][2] * coordinate_system[2][0];
1221         clip_vert[i].x = p[i][0] * state->coordinate_system[0][1];
1222         clip_vert[i].y = p[i][1] * state->coordinate_system[1][2];
1223         clip_vert[i].pz = p[i][2] * state->coordinate_system[2][0];
12351224         clip_vert[i].pu = vertex[i].pu * texture_coord_scale;
12361225         clip_vert[i].pv = vertex[i].pv * texture_coord_scale;
12371226      }
12381227
12391228      /* clip against view frustum */
1240      num_vertices = clip_polygon(clip_vert, num_vertices, clip_plane[0], clip_vert);
1241      num_vertices = clip_polygon(clip_vert, num_vertices, clip_plane[1], clip_vert);
1242      num_vertices = clip_polygon(clip_vert, num_vertices, clip_plane[2], clip_vert);
1243      num_vertices = clip_polygon(clip_vert, num_vertices, clip_plane[3], clip_vert);
1244      num_vertices = clip_polygon(clip_vert, num_vertices, clip_plane[4], clip_vert);
1229      num_vertices = clip_polygon(clip_vert, num_vertices, state->clip_plane[0], clip_vert);
1230      num_vertices = clip_polygon(clip_vert, num_vertices, state->clip_plane[1], clip_vert);
1231      num_vertices = clip_polygon(clip_vert, num_vertices, state->clip_plane[2], clip_vert);
1232      num_vertices = clip_polygon(clip_vert, num_vertices, state->clip_plane[3], clip_vert);
1233      num_vertices = clip_polygon(clip_vert, num_vertices, state->clip_plane[4], clip_vert);
12451234
12461235      /* backface culling */
12471236      if( (header[6] & 0x800000) && (!(header[1] & 0x0010)) )   {
r10427r10428
12571246         /* homogeneous Z-divide, screen-space transformation */
12581247         for(i=0; i < num_vertices; i++) {
12591248            float ooz = 1.0f / clip_vert[i].pz;
1260            clip_vert[i].x = ((clip_vert[i].x * ooz) * viewport_focal_length) + center_x;
1261            clip_vert[i].y = ((clip_vert[i].y * ooz) * viewport_focal_length) + center_y;
1249            clip_vert[i].x = ((clip_vert[i].x * ooz) * state->viewport_focal_length) + center_x;
1250            clip_vert[i].y = ((clip_vert[i].y * ooz) * state->viewport_focal_length) + center_y;
12621251         }
12631252
12641253         // lighting
12651254         if ((header[6] & 0x10000) == 0)
12661255         {
1267            dot = dot_product3(sn, parallel_light);
1268            intensity = ((dot * parallel_light_intensity) + ambient_light_intensity) * 256.0f;
1256            dot = dot_product3(sn, state->parallel_light);
1257            intensity = ((dot * state->parallel_light_intensity) + state->ambient_light_intensity) * 256.0f;
12691258            if (intensity > 256)
12701259            {
12711260               intensity = 256;
r10427r10428
13121301/*****************************************************************************/
13131302/* display list parser */
13141303
1315static UINT32 *get_memory_pointer(UINT32 address)
1304static UINT32 *get_memory_pointer(model3_state *state, UINT32 address)
13161305{
13171306   if (address & 0x800000)
13181307   {
13191308      if (address >= 0x840000) {
13201309         fatalerror("get_memory_pointer: invalid display list memory address %08X", address);
13211310      }
1322      return &display_list_ram[address & 0x7fffff];
1311      return &state->display_list_ram[address & 0x7fffff];
13231312   }
13241313   else
13251314   {
13261315      if (address >= 0x100000) {
13271316         fatalerror("get_memory_pointer: invalid node ram address %08X", address);
13281317      }
1329      return &culling_ram[address];
1318      return &state->culling_ram[address];
13301319   }
13311320}
13321321
1333static void load_matrix(int matrix_num, MATRIX *out)
1322static void load_matrix(model3_state *state, int matrix_num, MATRIX *out)
13341323{
1335   float *matrix = (float *)get_memory_pointer(matrix_base_address + matrix_num * 12);
1324   float *matrix = (float *)get_memory_pointer(state, state->matrix_base_address + matrix_num * 12);
13361325
13371326   (*out)[0][0] = matrix[3];   (*out)[0][1] = matrix[6];   (*out)[0][2] = matrix[9];   (*out)[0][3] = 0.0f;
13381327   (*out)[1][0] = matrix[4];   (*out)[1][1] = matrix[7];   (*out)[1][2] = matrix[10];   (*out)[1][3] = 0.0f;
r10427r10428
13421331
13431332static void traverse_list4(running_machine *machine, int lod_num, UINT32 address)
13441333{
1334   model3_state *state = machine->driver_data<model3_state>();
1335
13451336   /* does something with the LOD selection */
1346   UINT32 *list = get_memory_pointer(address);
1337   UINT32 *list = get_memory_pointer(state, address);
13471338   UINT32 link = list[0];
13481339
13491340   draw_model(machine, link & 0xffffff);
r10427r10428
13511342
13521343static void traverse_list(running_machine *machine, UINT32 address)
13531344{
1354   UINT32 *list = get_memory_pointer(address);
1345   model3_state *state = machine->driver_data<model3_state>();
1346   UINT32 *list = get_memory_pointer(state, address);
13551347   int list_ptr = 0;
13561348
1357   if (list_depth > 2)
1349   if (state->list_depth > 2)
13581350      return;
13591351
1360   list_depth++;
1352   state->list_depth++;
13611353
13621354   /* find the end of the list */
13631355   while (1)
r10427r10428
13771369   {
13781370      address = list[--list_ptr] & 0xffffff;
13791371      if (address != 0 && address != 0x800800)
1380//      if (address != 0)
1372      //if (address != 0)
13811373         draw_block(machine, address);
13821374   }
13831375
1384   list_depth--;
1376   state->list_depth--;
13851377}
13861378
13871379INLINE void process_link(running_machine *machine, UINT32 address, UINT32 link)
r10427r10428
14121404
14131405static void draw_block(running_machine *machine, UINT32 address)
14141406{
1415   const UINT32 *node = get_memory_pointer(address);
1407   model3_state *state = machine->driver_data<model3_state>();
1408   const UINT32 *node = get_memory_pointer(state, address);
14161409   UINT32 link;
14171410   int node_matrix;
14181411   float x, y, z;
14191412   MATRIX matrix;
14201413   int offset;
14211414
1422   offset = (model3_step < 0x15) ? 2 : 0;
1415   offset = (state->step < 0x15) ? 2 : 0;
14231416   link = node[7 - offset];
14241417
14251418   /* apply matrix and translation */
14261419   node_matrix = node[3 - offset] & 0xfff;
1427   load_matrix(node_matrix, &matrix);
1420   load_matrix(state, node_matrix, &matrix);
14281421
1429   push_matrix_stack();
1422   push_matrix_stack(state);
14301423
14311424   if (node[0] & 0x10)
14321425   {
14331426      x = *(float *)&node[4 - offset];
14341427      y = *(float *)&node[5 - offset];
14351428      z = *(float *)&node[6 - offset];
1436      translate_matrix_stack(x, y, z);
1429      translate_matrix_stack(state, x, y, z);
14371430   }
14381431   else if (node_matrix != 0)
1439      multiply_matrix_stack(matrix);
1432      multiply_matrix_stack(state, matrix);
14401433
14411434   /* bit 0x08 of word 0 indicates a pointer list */
14421435   if (node[0] & 0x08)
r10427r10428
14441437   else
14451438      process_link(machine, address, link);
14461439
1447   pop_matrix_stack();
1440   pop_matrix_stack(state);
14481441
14491442   /* handle the second link */
14501443   link = node[8 - offset];
r10427r10428
14531446
14541447static void draw_viewport(running_machine *machine, int pri, UINT32 address)
14551448{
1456   const UINT32 *node = get_memory_pointer(address);
1449   model3_state *state = machine->driver_data<model3_state>();
1450   const UINT32 *node = get_memory_pointer(state, address);
14571451   UINT32 link_address;
14581452   float /*viewport_left, viewport_right, */viewport_top, viewport_bottom;
14591453   float /*fov_x,*/ fov_y;
r10427r10428
14721466      return;
14731467
14741468   /* set viewport parameters */
1475   viewport_region_x      = (node[26] & 0xffff) >> 4;         /* 12.4 fixed point */
1476   viewport_region_y      = ((node[26] >> 16) & 0xffff) >> 4;
1477   viewport_region_width   = (node[20] & 0xffff) >> 2;         /* 14.2 fixed point */
1478   viewport_region_height   = ((node[20] >> 16) & 0xffff) >> 2;
1469   state->viewport_region_x      = (node[26] & 0xffff) >> 4;         /* 12.4 fixed point */
1470   state->viewport_region_y      = ((node[26] >> 16) & 0xffff) >> 4;
1471   state->viewport_region_width   = (node[20] & 0xffff) >> 2;         /* 14.2 fixed point */
1472   state->viewport_region_height   = ((node[20] >> 16) & 0xffff) >> 2;
14791473
14801474   /* frustum plane angles */
14811475   //viewport_left         = RADIAN_TO_DEGREE(asin(*(float *)&node[12]));
r10427r10428
14841478   viewport_bottom         = RADIAN_TO_DEGREE(asin(*(float *)&node[18]));
14851479
14861480   /* build clipping planes */
1487   clip_plane[0].x = *(float *)&node[13];   clip_plane[0].y = 0.0f;      clip_plane[0].z = *(float *)&node[12];   clip_plane[0].d = 0.0f;
1488   clip_plane[1].x = *(float *)&node[17];   clip_plane[1].y = 0.0f;      clip_plane[1].z = *(float *)&node[16];   clip_plane[1].d = 0.0f;
1489   clip_plane[2].x = 0.0f;      clip_plane[2].y = *(float *)&node[15];   clip_plane[2].z = *(float *)&node[14];   clip_plane[2].d = 0.0f;
1490   clip_plane[3].x = 0.0f;      clip_plane[3].y = *(float *)&node[19];   clip_plane[3].z = *(float *)&node[18];   clip_plane[3].d = 0.0f;
1491   clip_plane[4].x = 0.0f;      clip_plane[4].y = 0.0f;      clip_plane[4].z = 1.0f;      clip_plane[4].d = 1.0f;
1481   state->clip_plane[0].x = *(float *)&node[13];   state->clip_plane[0].y = 0.0f;      state->clip_plane[0].z = *(float *)&node[12];   state->clip_plane[0].d = 0.0f;
1482   state->clip_plane[1].x = *(float *)&node[17];   state->clip_plane[1].y = 0.0f;      state->clip_plane[1].z = *(float *)&node[16];   state->clip_plane[1].d = 0.0f;
1483   state->clip_plane[2].x = 0.0f;      state->clip_plane[2].y = *(float *)&node[15];   state->clip_plane[2].z = *(float *)&node[14];   state->clip_plane[2].d = 0.0f;
1484   state->clip_plane[3].x = 0.0f;      state->clip_plane[3].y = *(float *)&node[19];   state->clip_plane[3].z = *(float *)&node[18];   state->clip_plane[3].d = 0.0f;
1485   state->clip_plane[4].x = 0.0f;      state->clip_plane[4].y = 0.0f;      state->clip_plane[4].z = 1.0f;      state->clip_plane[4].d = 1.0f;
14921486
14931487   /* compute field of view */
14941488   //fov_x = viewport_left + viewport_right;
14951489   fov_y = viewport_top + viewport_bottom;
1496   viewport_focal_length = (viewport_region_height / 2) / tan( (fov_y * M_PI / 180.0f) / 2.0f );
1490   state->viewport_focal_length = (state->viewport_region_height / 2) / tan( (fov_y * M_PI / 180.0f) / 2.0f );
14971491
1498   matrix_base_address = node[22];
1492   state->matrix_base_address = node[22];
14991493   /* TODO: where does node[23] point to ? LOD table ? */
15001494
15011495   /* set lighting parameters */
1502   parallel_light[0] = -*(float *)&node[5];
1503   parallel_light[1] = *(float *)&node[6];
1504   parallel_light[2] = *(float *)&node[4];
1505   parallel_light_intensity = *(float *)&node[7];
1506   ambient_light_intensity = (UINT8)(node[36] >> 8) / 256.0f;
1496   state->parallel_light[0] = -*(float *)&node[5];
1497   state->parallel_light[1] = *(float *)&node[6];
1498   state->parallel_light[2] = *(float *)&node[4];
1499   state->parallel_light_intensity = *(float *)&node[7];
1500   state->ambient_light_intensity = (UINT8)(node[36] >> 8) / 256.0f;
15071501
15081502   /* set coordinate system matrix */
1509   load_matrix(0, &coordinate_system);
1503   load_matrix(state, 0, &state->coordinate_system);
15101504
15111505   /* process a link */
15121506   process_link(machine, link_address, node[2]);
r10427r10428
15151509
15161510static void real3d_traverse_display_list(running_machine *machine)
15171511{
1512   model3_state *state = machine->driver_data<model3_state>();
15181513   int pri;
15191514
1520   init_matrix_stack();
1515   init_matrix_stack(machine);
15211516
15221517   for (pri = 0; pri < 4; pri++)
15231518      draw_viewport(machine, pri, 0x800000);
15241519
1525   poly_wait(poly, "real3d_traverse_display_list");
1520   poly_wait(state->poly, "real3d_traverse_display_list");
15261521}
15271522
src/mame/video/cchasm.c
r10427r10428
1717#define POSX   6
1818#define LENGTH 7
1919
20UINT16 *cchasm_ram;
2120
22static int xcenter, ycenter;
2321
2422static TIMER_CALLBACK( cchasm_refresh_end )
2523{
r10427r10428
2826
2927static void cchasm_refresh (running_machine *machine)
3028{
29   cchasm_state *state = machine->driver_data<cchasm_state>();
3130
3231   int pc = 0;
3332    int done = 0;
r10427r10428
4241
4342   while (!done)
4443   {
45        data = cchasm_ram[pc];
44        data = state->ram[pc];
4645      opcode = data >> 12;
4746        data &= 0xfff;
4847        if ((opcode > COLOR) && (data & 0x800))
r10427r10428
6766            break;
6867        case POSY:
6968            move = 1;
70            currenty = ycenter + (data << 16);
69            currenty = state->ycenter + (data << 16);
7170            break;
7271        case SCALEX:
7372            scalex = data << 5;
7473            break;
7574        case POSX:
7675            move = 1;
77            currentx = xcenter - (data << 16);
76            currentx = state->xcenter - (data << 16);
7877            break;
7978        case LENGTH:
8079            if (move)
r10427r10428
122121
123122VIDEO_START( cchasm )
124123{
124   cchasm_state *state = machine->driver_data<cchasm_state>();
125125   const rectangle &visarea = machine->primary_screen->visible_area();
126126
127   xcenter=((visarea.max_x + visarea.min_x)/2) << 16;
128   ycenter=((visarea.max_y + visarea.min_y)/2) << 16;
127   state->xcenter=((visarea.max_x + visarea.min_x)/2) << 16;
128   state->ycenter=((visarea.max_y + visarea.min_y)/2) << 16;
129129
130130   VIDEO_START_CALL(vector);
131131}
src/mame/video/atarirle.c
r10427r10428
9696   UINT8         command;         /* current command */
9797   UINT8         is32bit;         /* 32-bit or 16-bit? */
9898   UINT16         checksums[256];      /* checksums for each 0x40000 bytes */
99   UINT16         ram[0x1000/2];
99100};
100101
101102
r10427r10428
108109#define EXTRACT_DATA(_input, _mask) (((_input)->data[(_mask).word] >> (_mask).shift) & (_mask).mask)
109110
110111
112enum { atarirle_hilite_index = -1 };
111113
112/***************************************************************************
113    GLOBAL VARIABLES
114***************************************************************************/
115114
116UINT16 *atarirle_0_spriteram;
117UINT32 *atarirle_0_spriteram32;
118115
119static int atarirle_hilite_index = -1;
120
121
122
123116/***************************************************************************
124117    STATIC VARIABLES
125118***************************************************************************/
126119
127static atarirle_data atarirle[ATARIRLE_MAX];
128
129120static UINT8 rle_bpp[8];
130121static UINT16 *rle_table[8];
131122
r10427r10428
155146    INLINE FUNCTIONS
156147***************************************************************************/
157148
149INLINE atarirle_data *get_safe_token(device_t *device)
150{
151   assert(device != NULL);
152   assert(device->type() == ATARIRLE);
153
154   return (atarirle_data *)downcast<legacy_device_base *>(device)->token();
155}
156
157
158158/*---------------------------------------------------------------
159159    compute_log: Computes the number of bits necessary to
160160    hold a given value. The input must be an even power of
r10427r10428
268268    the attribute lookup table.
269269---------------------------------------------------------------*/
270270
271void atarirle_init(running_machine *machine, int map, const atarirle_desc *desc)
271static DEVICE_START( atarirle )
272272{
273   atarirle_data *mo = get_safe_token(device);
274   running_machine *machine = device->machine;
275   const atarirle_desc *desc = (const atarirle_desc *)device->baseconfig().static_config();
273276   const UINT16 *base = (const UINT16 *)machine->region(desc->region)->base();
274   atarirle_data *mo = &atarirle[map];
275277   int i, width, height;
276278
277   /* verify the map index */
278   assert_always(map >= 0 && map < ATARIRLE_MAX, "Invalid map index");
279
280279   /* build and allocate the generic tables */
281280   build_rle_tables(machine);
282281
r10427r10428
356355   mo->partial_scanline = -1;
357356
358357   /* register for save states */
359   state_save_register_item_pointer(machine, "atarirle", NULL, map, mo->spriteram[0].data, ARRAY_LENGTH(mo->spriteram[0].data) * mo->spriteramsize);
360   state_save_register_item_bitmap(machine, "atarirle", NULL, map, mo->vram[0][0]);
361   state_save_register_item_bitmap(machine, "atarirle", NULL, map, mo->vram[0][1]);
358   device->save_pointer(NAME(mo->spriteram[0].data), ARRAY_LENGTH(mo->spriteram[0].data) * mo->spriteramsize);
359   device->save_item(NAME(*mo->vram[0][0]));
360   device->save_item(NAME(*mo->vram[0][1]));
362361   if (mo->vrammask.mask != 0)
363362   {
364      state_save_register_item_bitmap(machine, "atarirle", NULL, map, mo->vram[1][0]);
365      state_save_register_item_bitmap(machine, "atarirle", NULL, map, mo->vram[1][1]);
363      device->save_item(NAME(*mo->vram[1][0]));
364      device->save_item(NAME(*mo->vram[1][1]));
366365   }
367   state_save_register_item(machine, "atarirle", NULL, map, mo->partial_scanline);
368   state_save_register_item(machine, "atarirle", NULL, map, mo->control_bits);
369   state_save_register_item(machine, "atarirle", NULL, map, mo->command);
370   state_save_register_item(machine, "atarirle", NULL, map, mo->is32bit);
371   state_save_register_item_array(machine, "atarirle", NULL, map, mo->checksums);
366   device->save_item(NAME(mo->partial_scanline));
367   device->save_item(NAME(mo->control_bits));
368   device->save_item(NAME(mo->command));
369   device->save_item(NAME(mo->is32bit));
370   device->save_item(NAME(mo->checksums));
372371}
373372
374373
374DEVICE_GET_INFO( atarirle )
375{
376   switch (state)
377   {
378      /* --- the following bits of info are returned as 64-bit signed integers --- */
379      case DEVINFO_INT_TOKEN_BYTES:         info->i = sizeof(atarirle_data);               break;
375380
381      /* --- the following bits of info are returned as pointers to data or functions --- */
382      case DEVINFO_FCT_START:               info->start = DEVICE_START_NAME(atarirle);      break;
383
384      /* --- the following bits of info are returned as NULL-terminated strings --- */
385      case DEVINFO_STR_NAME:               strcpy(info->s, "Atari RLE");            break;
386      case DEVINFO_STR_FAMILY:            strcpy(info->s, "Atari RLE Video IC");               break;
387      case DEVINFO_STR_VERSION:            strcpy(info->s, "1.0");                     break;
388      case DEVINFO_STR_SOURCE_FILE:         strcpy(info->s, __FILE__);                  break;
389      case DEVINFO_STR_CREDITS:            strcpy(info->s, "Copyright MAME Team");         break;
390   }
391}
392
393DEFINE_LEGACY_DEVICE(ATARIRLE, atarirle);
394
376395/*---------------------------------------------------------------
377396    atarirle_control_w: Write handler for MO control bits.
378397---------------------------------------------------------------*/
379398
380void atarirle_control_w(running_machine *machine, int map, UINT8 bits)
399void atarirle_control_w(device_t *device, UINT8 bits)
381400{
382   atarirle_data *mo = &atarirle[map];
383   int scanline = machine->primary_screen->vpos();
401   atarirle_data *mo = get_safe_token(device);
402   int scanline = device->machine->primary_screen->vpos();
384403   int oldbits = mo->control_bits;
385404
386405//logerror("atarirle_control_w(%d)\n", bits);
r10427r10428
390409      return;
391410
392411   /* force a partial update first */
393   machine->primary_screen->update_partial(scanline);
412   device->machine->primary_screen->update_partial(scanline);
394413
395414   /* if the erase flag was set, erase the front map */
396415   if (oldbits & ATARIRLE_CONTROL_ERASE)
r10427r10428
418437   if (!(oldbits & ATARIRLE_CONTROL_MOGO) && (bits & ATARIRLE_CONTROL_MOGO))
419438   {
420439      if (mo->command == ATARIRLE_COMMAND_DRAW)
421         sort_and_render(machine, mo);
440         sort_and_render(device->machine, mo);
422441      else if (mo->command == ATARIRLE_COMMAND_CHECKSUM)
423442         compute_checksum(mo);
424443   }
r10427r10428
433452    atarirle_command_w: Write handler for MO command bits.
434453---------------------------------------------------------------*/
435454
436void atarirle_command_w(int map, UINT8 command)
455void atarirle_command_w(device_t *device, UINT8 command)
437456{
438   atarirle_data *mo = &atarirle[map];
457   atarirle_data *mo = get_safe_token(device);
439458   mo->command = command;
440459}
441460
442461
443462
444463/*---------------------------------------------------------------
445    VIDEO_EOF(atarirle): Flush remaining changes.
464    atarirle_eof: Flush remaining changes.
446465---------------------------------------------------------------*/
447466
448VIDEO_EOF( atarirle )
467void atarirle_eof(device_t *device)
449468{
450   int i;
451
452//logerror("VIDEO_EOF(atarirle)\n");
453
454   /* loop over all RLE handlers */
455   for (i = 0; i < ATARIRLE_MAX; i++)
456469   {
457      atarirle_data *mo = &atarirle[i];
470      atarirle_data *mo = get_safe_token(device);
458471
459472      /* if the erase flag is set, erase to the end of the screen */
460473      if (mo->control_bits & ATARIRLE_CONTROL_ERASE)
r10427r10428
481494
482495
483496/*---------------------------------------------------------------
484    atarirle_0_spriteram_w: Write handler for the spriteram.
497    atarirle_spriteram_r: Read handler for the spriteram.
485498---------------------------------------------------------------*/
486499
487WRITE16_HANDLER( atarirle_0_spriteram_w )
500READ16_DEVICE_HANDLER( atarirle_spriteram_r )
488501{
489   int entry = (offset >> 3) & atarirle[0].spriterammask;
502   atarirle_data *mo = get_safe_token(device);
503
504   return mo->ram[offset];
505}
506
507
508
509/*---------------------------------------------------------------
510    atarirle_spriteram_w: Write handler for the spriteram.
511---------------------------------------------------------------*/
512
513WRITE16_DEVICE_HANDLER( atarirle_spriteram_w )
514{
515   atarirle_data *mo = get_safe_token(device);
516   int entry = (offset >> 3) & mo->spriterammask;
490517   int idx = offset & 7;
491518
492519   /* combine raw data */
493   COMBINE_DATA(&atarirle_0_spriteram[offset]);
520   COMBINE_DATA(&mo->ram[offset]);
494521
495522   /* store a copy in our local spriteram */
496   atarirle[0].spriteram[entry].data[idx] = atarirle_0_spriteram[offset];
497   atarirle[0].is32bit = 0;
523   mo->spriteram[entry].data[idx] = mo->ram[offset];
524   mo->is32bit = 0;
498525}
499526
500527
501528
502529/*---------------------------------------------------------------
503    atarirle_0_spriteram32_w: Write handler for the spriteram.
530    atarirle_spriteram32_r: Read handler for the spriteram.
504531---------------------------------------------------------------*/
505532
506WRITE32_HANDLER( atarirle_0_spriteram32_w )
533READ32_DEVICE_HANDLER( atarirle_spriteram32_r )
507534{
508   int entry = (offset >> 2) & atarirle[0].spriterammask;
535   atarirle_data *mo = get_safe_token(device);
536   UINT32 *ram = (UINT32 *)mo->ram;
537
538   return ram[offset];
539}
540
541
542
543/*---------------------------------------------------------------
544    atarirle_spriteram32_w: Write handler for the spriteram.
545---------------------------------------------------------------*/
546
547WRITE32_DEVICE_HANDLER( atarirle_spriteram32_w )
548{
549   atarirle_data *mo = get_safe_token(device);
550   UINT32 *ram = (UINT32 *)mo->ram;
551   int entry = (offset >> 2) & mo->spriterammask;
509552   int idx = 2 * (offset & 3);
510553
511554   /* combine raw data */
512   COMBINE_DATA(&atarirle_0_spriteram32[offset]);
555   COMBINE_DATA(&ram[offset]);
513556
514557   /* store a copy in our local spriteram */
515   atarirle[0].spriteram[entry].data[idx+0] = atarirle_0_spriteram32[offset] >> 16;
516   atarirle[0].spriteram[entry].data[idx+1] = atarirle_0_spriteram32[offset];
517   atarirle[0].is32bit = 1;
558   mo->spriteram[entry].data[idx+0] = ram[offset] >> 16;
559   mo->spriteram[entry].data[idx+1] = ram[offset];
560   mo->is32bit = 1;
518561}
519562
520563
r10427r10428
523566    atarirle_get_vram: Return the VRAM bitmap.
524567---------------------------------------------------------------*/
525568
526bitmap_t *atarirle_get_vram(int map, int idx)
569bitmap_t *atarirle_get_vram(device_t *device, int idx)
527570{
528   atarirle_data *mo = &atarirle[map];
571   atarirle_data *mo = get_safe_token(device);
529572//logerror("atarirle_get_vram (frame %d)\n", (mo->control_bits & ATARIRLE_CONTROL_FRAME) >> 2);
530573   return mo->vram[idx][(mo->control_bits & ATARIRLE_CONTROL_FRAME) >> 2];
531574}
r10427r10428
712755   if (!mo->is32bit)
713756   {
714757      for (i = 0; i < reqsums; i++)
715         atarirle_0_spriteram[i] = mo->checksums[i];
758         mo->ram[i] = mo->checksums[i];
716759   }
717760   else
718761   {
762      UINT32 *ram = (UINT32 *)mo->ram;
719763      for (i = 0; i < reqsums; i++)
720764         if (i & 1)
721            atarirle_0_spriteram32[i/2] = (atarirle_0_spriteram32[i/2] & 0xffff0000) | mo->checksums[i];
765            ram[i/2] = (ram[i/2] & 0xffff0000) | mo->checksums[i];
722766         else
723            atarirle_0_spriteram32[i/2] = (atarirle_0_spriteram32[i/2] & 0x0000ffff) | (mo->checksums[i] << 16);
767            ram[i/2] = (ram[i/2] & 0x0000ffff) | (mo->checksums[i] << 16);
724768   }
725769}
726770
src/mame/video/atarirle.h
r10427r10428
1515    CONSTANTS
1616***************************************************************************/
1717
18/* maximum number of motion object processors */
19#define ATARIRLE_MAX            1
20
2118#define ATARIRLE_PRIORITY_SHIFT      12
2219#define ATARIRLE_BANK_SHIFT         15
2320#define ATARIRLE_PRIORITY_MASK      ((~0 << ATARIRLE_PRIORITY_SHIFT) & 0xffff)
r10427r10428
7370    FUNCTION PROTOTYPES
7471***************************************************************************/
7572
76/* setup/shutdown */
77void atarirle_init(running_machine *machine, int map, const atarirle_desc *desc);
73DECLARE_LEGACY_DEVICE(ATARIRLE, atarirle);
74#define MCFG_ATARIRLE_ADD(_tag, _interface) \
75   MCFG_DEVICE_ADD(_tag, ATARIRLE, 0) \
76   MCFG_DEVICE_CONFIG(_interface)
7877
78
7979/* control handlers */
80void atarirle_control_w(running_machine *machine, int map, UINT8 bits);
81void atarirle_command_w(int map, UINT8 command);
82VIDEO_EOF( atarirle );
80void atarirle_control_w(device_t *device, UINT8 bits);
81void atarirle_command_w(device_t *device, UINT8 command);
8382
84/* write handlers */
85WRITE16_HANDLER( atarirle_0_spriteram_w );
86WRITE32_HANDLER( atarirle_0_spriteram32_w );
83/* read/write handlers */
84READ16_DEVICE_HANDLER( atarirle_spriteram_r );
85READ32_DEVICE_HANDLER( atarirle_spriteram32_r );
86WRITE16_DEVICE_HANDLER( atarirle_spriteram_w );
87WRITE32_DEVICE_HANDLER( atarirle_spriteram32_w );
8788
8889/* render helpers */
89bitmap_t *atarirle_get_vram(int map, int idx);
90void atarirle_eof(device_t *device);
91bitmap_t *atarirle_get_vram(device_t *device, int idx);
9092
91
92
93/***************************************************************************
94    GLOBAL VARIABLES
95***************************************************************************/
96
97extern UINT16 *atarirle_0_spriteram;
98extern UINT32 *atarirle_0_spriteram32;
99
10093#endif
src/mame/video/cinemat.c
r10427r10428
2929
3030/*************************************
3131 *
32 *  Local variables
33 *
34 *************************************/
35
36static int color_mode;
37static rgb_t vector_color;
38static INT16 lastx, lasty;
39static UINT8 last_control;
40
41
42
43/*************************************
44 *
4532 *  Vector rendering
4633 *
4734 *************************************/
4835
4936void cinemat_vector_callback(device_t *device, INT16 sx, INT16 sy, INT16 ex, INT16 ey, UINT8 shift)
5037{
38   cinemat_state *state = device->machine->driver_data<cinemat_state>();
5139   const rectangle &visarea = device->machine->primary_screen->visible_area();
5240   int intensity = 0xff;
5341
r10427r10428
6250      intensity = 0x1ff * shift / 8;
6351
6452   /* move to the starting position if we're not there already */
65   if (sx != lastx || sy != lasty)
53   if (sx != state->lastx || sy != state->lasty)
6654      vector_add_point(device->machine, sx << 16, sy << 16, 0, 0);
6755
6856   /* draw the vector */
69   vector_add_point(device->machine, ex << 16, ey << 16, vector_color, intensity);
57   vector_add_point(device->machine, ex << 16, ey << 16, state->vector_color, intensity);
7058
7159   /* remember the last point */
72   lastx = ex;
73   lasty = ey;
60   state->lastx = ex;
61   state->lasty = ey;
7462}
7563
7664
r10427r10428
8371
8472WRITE8_HANDLER(cinemat_vector_control_w)
8573{
74   cinemat_state *state = space->machine->driver_data<cinemat_state>();
8675   int r, g, b, i;
8776   cpu_device *cpu = space->machine->device<cpu_device>("maincpu");
8877
89   switch (color_mode)
78   switch (state->color_mode)
9079   {
9180      case COLOR_BILEVEL:
9281         /* color is either bright or dim, selected by the value sent to the port */
93         vector_color = (data & 1) ? MAKE_RGB(0x80,0x80,0x80) : MAKE_RGB(0xff,0xff,0xff);
82         state->vector_color = (data & 1) ? MAKE_RGB(0x80,0x80,0x80) : MAKE_RGB(0xff,0xff,0xff);
9483         break;
9584
9685      case COLOR_16LEVEL:
9786         /* on the rising edge of the data value, latch bits 0-3 of the */
9887         /* X register as the intensity */
99         if (data != last_control && data)
88         if (data != state->last_control && data)
10089         {
10190            int xval = cpu->state(CCPU_X) & 0x0f;
10291            i = (xval + 1) * 255 / 16;
103            vector_color = MAKE_RGB(i,i,i);
92            state->vector_color = MAKE_RGB(i,i,i);
10493         }
10594         break;
10695
10796      case COLOR_64LEVEL:
10897         /* on the rising edge of the data value, latch bits 2-7 of the */
10998         /* X register as the intensity */
110         if (data != last_control && data)
99         if (data != state->last_control && data)
111100         {
112101            int xval = cpu->state(CCPU_X);
113102            xval = (~xval >> 2) & 0x3f;
114103            i = (xval + 1) * 255 / 64;
115            vector_color = MAKE_RGB(i,i,i);
104            state->vector_color = MAKE_RGB(i,i,i);
116105         }
117106         break;
118107
119108      case COLOR_RGB:
120109         /* on the rising edge of the data value, latch the X register */
121110         /* as 4-4-4 BGR values */
122         if (data != last_control && data)
111         if (data != state->last_control && data)
123112         {
124113            int xval = cpu->state(CCPU_X);
125114            r = (~xval >> 0) & 0x0f;
r10427r10428
128117            g = g * 255 / 15;
129118            b = (~xval >> 8) & 0x0f;
130119            b = b * 255 / 15;
131            vector_color = MAKE_RGB(r,g,b);
120            state->vector_color = MAKE_RGB(r,g,b);
132121         }
133122         break;
134123
135124      case COLOR_QB3:
136125         {
137            static int lastx, lasty;
138
139126            /* on the falling edge of the data value, remember the original X,Y values */
140127            /* they will be restored on the rising edge; this is to simulate the fact */
141128            /* that the Rockola color hardware did not overwrite the beam X,Y position */
142129            /* on an IV instruction if data == 0 here */
143            if (data != last_control && !data)
130            if (data != state->last_control && !data)
144131            {
145               lastx = cpu->state(CCPU_X);
146               lasty = cpu->state(CCPU_Y);
132               state->qb3_lastx = cpu->state(CCPU_X);
133               state->qb3_lasty = cpu->state(CCPU_Y);
147134            }
148135
149136            /* on the rising edge of the data value, latch the Y register */
150137            /* as 2-3-3 BGR values */
151            if (data != last_control && data)
138            if (data != state->last_control && data)
152139            {
153140               int yval = cpu->state(CCPU_Y);
154141               r = (~yval >> 0) & 0x07;
r10427r10428
157144               g = g * 255 / 7;
158145               b = (~yval >> 6) & 0x03;
159146               b = b * 255 / 3;
160               vector_color = MAKE_RGB(r,g,b);
147               state->vector_color = MAKE_RGB(r,g,b);
161148
162149               /* restore the original X,Y values */
163               cpu->set_state(CCPU_X, lastx);
164               cpu->set_state(CCPU_Y, lasty);
150               cpu->set_state(CCPU_X, state->qb3_lastx);
151               cpu->set_state(CCPU_Y, state->qb3_lasty);
165152            }
166153         }
167154         break;
168155   }
169156
170157   /* remember the last value */
171   last_control = data;
158   state->last_control = data;
172159}
173160
174161
r10427r10428
181168
182169VIDEO_START( cinemat_bilevel )
183170{
184   color_mode = COLOR_BILEVEL;
171   cinemat_state *state = machine->driver_data<cinemat_state>();
172   state->color_mode = COLOR_BILEVEL;
185173   VIDEO_START_CALL(vector);
186174}
187175
188176
189177VIDEO_START( cinemat_16level )
190178{
191   color_mode = COLOR_16LEVEL;
179   cinemat_state *state = machine->driver_data<cinemat_state>();
180   state->color_mode = COLOR_16LEVEL;
192181   VIDEO_START_CALL(vector);
193182}
194183
195184
196185VIDEO_START( cinemat_64level )
197186{
198   color_mode = COLOR_64LEVEL;
187   cinemat_state *state = machine->driver_data<cinemat_state>();
188   state->color_mode = COLOR_64LEVEL;
199189   VIDEO_START_CALL(vector);
200190}
201191
202192
203193VIDEO_START( cinemat_color )
204194{
205   color_mode = COLOR_RGB;
195   cinemat_state *state = machine->driver_data<cinemat_state>();
196   state->color_mode = COLOR_RGB;
206197   VIDEO_START_CALL(vector);
207198}
208199
209200
210201VIDEO_START( cinemat_qb3color )
211202{
212   color_mode = COLOR_QB3;
203   cinemat_state *state = machine->driver_data<cinemat_state>();
204   state->color_mode = COLOR_QB3;
213205   VIDEO_START_CALL(vector);
214206}
215207
src/mame/video/wecleman.c
r10427r10428
3737   int shadow_mode, flags;
3838};
3939
40/* Variables that driver has acces to: */
41UINT16 *wecleman_videostatus;
42UINT16 *wecleman_pageram, *wecleman_txtram, *wecleman_roadram;
43size_t wecleman_roadram_size;
44static int wecleman_bgpage[4], wecleman_fgpage[4];
45static const int *wecleman_gfx_bank;
4640
47/* Variables only used here: */
48static tilemap_t *bg_tilemap, *fg_tilemap, *txt_tilemap;
49
50static struct sprite *sprite_list;
51static struct sprite **spr_ptr_list;
52static int *spr_idx_list, *spr_pri_list, *t32x32pm;
53static int gameid, spr_offsx, spr_offsy, spr_count;
54static UINT16 *rgb_half;
55
56static int cloud_blend, cloud_ds, cloud_visible;
57static pen_t black_pen;
58
59
6041/***************************************************************************
6142
6243                        Sprite Description and Routines
r10427r10428
9475
9576static void get_sprite_info(running_machine *machine)
9677{
78   wecleman_state *state = machine->driver_data<wecleman_state>();
9779   const pen_t *base_pal = machine->pens;
9880   UINT8 *base_gfx = machine->region("gfx1")->base();
9981   int gfx_max     = machine->region("gfx1")->bytes();
10082
10183   UINT16 *source = machine->generic.spriteram.u16;
10284
103   struct sprite *sprite = sprite_list;
104   struct sprite *finish = sprite_list + NUM_SPRITES;
85   struct sprite *sprite = state->sprite_list;
86   struct sprite *finish = state->sprite_list + NUM_SPRITES;
10587
10688   int bank, code, gfx, zoom;
10789
108   for (spr_count=0; sprite<finish; source+=0x10/2, sprite++)
90   for (state->spr_count=0; sprite<finish; source+=0x10/2, sprite++)
10991   {
11092      if (source[0x00/2] == 0xffff) break;
11193
r10427r10428
128110      sprite->pal_base = (source[0x0e/2] & 0xff) << 4;
129111      sprite->pal_data = base_pal + sprite->pal_base;
130112
131      gfx = (wecleman_gfx_bank[bank] << 15) + (code & 0x7fff);
113      gfx = (state->gfx_bank[bank] << 15) + (code & 0x7fff);
132114
133115      sprite->flags = 0;
134116      if (code & 0x8000) { sprite->flags |= SPRITE_FLIPX; gfx += 1-sprite->tile_width; }
r10427r10428
144126      sprite->line_offset = sprite->tile_width;
145127      sprite->total_width = sprite->tile_width - (sprite->tile_width * (zoom & 0xff)) / 0x80;
146128      sprite->total_height += 1;
147      sprite->x += spr_offsx;
148      sprite->y += spr_offsy;
129      sprite->x += state->spr_offsx;
130      sprite->y += state->spr_offsy;
149131
150      if (gameid == 0)
132      if (state->gameid == 0)
151133      {
152         spr_idx_list[spr_count] = spr_count;
153         spr_pri_list[spr_count] = source[0x0e/2] >> 8;
134         state->spr_idx_list[state->spr_count] = state->spr_count;
135         state->spr_pri_list[state->spr_count] = source[0x0e/2] >> 8;
154136      }
155137
156      spr_ptr_list[spr_count] = sprite;
157      spr_count++;
138      state->spr_ptr_list[state->spr_count] = sprite;
139      state->spr_count++;
158140   }
159141}
160142
r10427r10428
187169}
188170
189171// draws a 8bpp palette sprites on a 16bpp direct RGB target (sub-par implementation)
190static void do_blit_zoom32(bitmap_t *bitmap, const rectangle *cliprect, struct sprite *sprite)
172static void do_blit_zoom32(wecleman_state *state, bitmap_t *bitmap, const rectangle *cliprect, struct sprite *sprite)
191173{
192174#define PRECISION_X 20
193175#define PRECISION_Y 20
r10427r10428
335317                     dst_ptr[sx] = base + pix;
336318                  else
337319                  {
338                     if (dst_ptr[sx] != black_pen)
320                     if (dst_ptr[sx] != state->black_pen)
339321                        dst_ptr[sx] |= 0x800;
340322                  }
341323               }
r10427r10428
348330   }
349331}
350332
351static void sprite_draw(bitmap_t *bitmap, const rectangle *cliprect)
333static void sprite_draw(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect)
352334{
335   wecleman_state *state = machine->driver_data<wecleman_state>();
353336   int i;
354337
355   if (gameid == 0)   // Wec Le Mans
338   if (state->gameid == 0)   // Wec Le Mans
356339   {
357      sortsprite(spr_idx_list, spr_pri_list, spr_count);
340      sortsprite(state->spr_idx_list, state->spr_pri_list, state->spr_count);
358341
359      for (i=0; i<spr_count; i++) do_blit_zoom32(bitmap, cliprect, spr_ptr_list[spr_idx_list[i]]);
342      for (i=0; i<state->spr_count; i++) do_blit_zoom32(state, bitmap, cliprect, state->spr_ptr_list[state->spr_idx_list[i]]);
360343   }
361344   else   // Hot Chase
362345   {
363      for (i=0; i<spr_count; i++) do_blit_zoom32(bitmap, cliprect, spr_ptr_list[i]);
346      for (i=0; i<state->spr_count; i++) do_blit_zoom32(state, bitmap, cliprect, state->spr_ptr_list[i]);
364347   }
365348}
366349
r10427r10428
436419
437420static TILE_GET_INFO( wecleman_get_txt_tile_info )
438421{
439   int code = wecleman_txtram[tile_index];
422   wecleman_state *state = machine->driver_data<wecleman_state>();
423   int code = state->txtram[tile_index];
440424   SET_TILE_INFO(PAGE_GFX, code&0xfff, (code>>5&0x78)+(code>>12), 0);
441425}
442426
443427WRITE16_HANDLER( wecleman_txtram_w )
444428{
445   UINT16 old_data = wecleman_txtram[offset];
446   UINT16 new_data = COMBINE_DATA(&wecleman_txtram[offset]);
429   wecleman_state *state = space->machine->driver_data<wecleman_state>();
430   UINT16 old_data = state->txtram[offset];
431   UINT16 new_data = COMBINE_DATA(&state->txtram[offset]);
447432
448433   if ( old_data != new_data )
449434   {
r10427r10428
452437         /* pages selector for the background */
453438         if (offset == 0xEFE/2)
454439         {
455            wecleman_bgpage[0] = (new_data >> 0x4) & 3;
456            wecleman_bgpage[1] = (new_data >> 0x0) & 3;
457            wecleman_bgpage[2] = (new_data >> 0xc) & 3;
458            wecleman_bgpage[3] = (new_data >> 0x8) & 3;
459            tilemap_mark_all_tiles_dirty(bg_tilemap);
440            state->bgpage[0] = (new_data >> 0x4) & 3;
441            state->bgpage[1] = (new_data >> 0x0) & 3;
442            state->bgpage[2] = (new_data >> 0xc) & 3;
443            state->bgpage[3] = (new_data >> 0x8) & 3;
444            tilemap_mark_all_tiles_dirty(state->bg_tilemap);
460445         }
461446
462447         /* pages selector for the foreground */
463448         if (offset == 0xEFC/2)
464449         {
465            wecleman_fgpage[0] = (new_data >> 0x4) & 3;
466            wecleman_fgpage[1] = (new_data >> 0x0) & 3;
467            wecleman_fgpage[2] = (new_data >> 0xc) & 3;
468            wecleman_fgpage[3] = (new_data >> 0x8) & 3;
469            tilemap_mark_all_tiles_dirty(fg_tilemap);
450            state->fgpage[0] = (new_data >> 0x4) & 3;
451            state->fgpage[1] = (new_data >> 0x0) & 3;
452            state->fgpage[2] = (new_data >> 0xc) & 3;
453            state->fgpage[3] = (new_data >> 0x8) & 3;
454            tilemap_mark_all_tiles_dirty(state->fg_tilemap);
470455         }
471456
472457         /* Parallactic horizontal scroll registers follow */
473458      }
474459      else
475         tilemap_mark_tile_dirty(txt_tilemap, offset);
460         tilemap_mark_tile_dirty(state->txt_tilemap, offset);
476461   }
477462}
478463
r10427r10428
482467
483468static TILE_GET_INFO( wecleman_get_bg_tile_info )
484469{
485   int page = wecleman_bgpage[((tile_index&0x7f)>>6) + ((tile_index>>12)<<1)];
486   int code = wecleman_pageram[(tile_index&0x3f) + ((tile_index>>7&0x1f)<<6) + (page<<11)];
470   wecleman_state *state = machine->driver_data<wecleman_state>();
471   int page = state->bgpage[((tile_index&0x7f)>>6) + ((tile_index>>12)<<1)];
472   int code = state->pageram[(tile_index&0x3f) + ((tile_index>>7&0x1f)<<6) + (page<<11)];
487473
488474   SET_TILE_INFO(PAGE_GFX, code&0xfff, (code>>5&0x78)+(code>>12), 0);
489475}
r10427r10428
494480
495481static TILE_GET_INFO( wecleman_get_fg_tile_info )
496482{
497   int page = wecleman_fgpage[((tile_index&0x7f)>>6) + ((tile_index>>12)<<1)];
498   int code = wecleman_pageram[(tile_index&0x3f) + ((tile_index>>7&0x1f)<<6) + (page<<11)];
483   wecleman_state *state = machine->driver_data<wecleman_state>();
484   int page = state->fgpage[((tile_index&0x7f)>>6) + ((tile_index>>12)<<1)];
485   int code = state->pageram[(tile_index&0x3f) + ((tile_index>>7&0x1f)<<6) + (page<<11)];
499486
500487   if (!code || code==0xffff) code = 0x20;
501488   SET_TILE_INFO(PAGE_GFX, code&0xfff, (code>>5&0x78)+(code>>12), 0);
r10427r10428
508495/* Pages that compose both the background and the foreground */
509496WRITE16_HANDLER( wecleman_pageram_w )
510497{
511   COMBINE_DATA(&wecleman_pageram[offset]);
498   wecleman_state *state = space->machine->driver_data<wecleman_state>();
499   COMBINE_DATA(&state->pageram[offset]);
512500
513501   {
514502      int page,col,row;
r10427r10428
518506      row  = ( offset / PAGE_NX ) % PAGE_NY;
519507
520508      /* background */
521      if (wecleman_bgpage[0] == page) tilemap_mark_tile_dirty(bg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*0)*PAGE_NX*2 );
522      if (wecleman_bgpage[1] == page) tilemap_mark_tile_dirty(bg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*0)*PAGE_NX*2 );
523      if (wecleman_bgpage[2] == page) tilemap_mark_tile_dirty(bg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*1)*PAGE_NX*2 );
524      if (wecleman_bgpage[3] == page) tilemap_mark_tile_dirty(bg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*1)*PAGE_NX*2 );
509      if (state->bgpage[0] == page) tilemap_mark_tile_dirty(state->bg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*0)*PAGE_NX*2 );
510      if (state->bgpage[1] == page) tilemap_mark_tile_dirty(state->bg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*0)*PAGE_NX*2 );
511      if (state->bgpage[2] == page) tilemap_mark_tile_dirty(state->bg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*1)*PAGE_NX*2 );
512      if (state->bgpage[3] == page) tilemap_mark_tile_dirty(state->bg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*1)*PAGE_NX*2 );
525513
526514      /* foreground */
527      if (wecleman_fgpage[0] == page) tilemap_mark_tile_dirty(fg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*0)*PAGE_NX*2 );
528      if (wecleman_fgpage[1] == page) tilemap_mark_tile_dirty(fg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*0)*PAGE_NX*2 );
529      if (wecleman_fgpage[2] == page) tilemap_mark_tile_dirty(fg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*1)*PAGE_NX*2 );
530      if (wecleman_fgpage[3] == page) tilemap_mark_tile_dirty(fg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*1)*PAGE_NX*2 );
515      if (state->fgpage[0] == page) tilemap_mark_tile_dirty(state->fg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*0)*PAGE_NX*2 );
516      if (state->fgpage[1] == page) tilemap_mark_tile_dirty(state->fg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*0)*PAGE_NX*2 );
517      if (state->fgpage[2] == page) tilemap_mark_tile_dirty(state->fg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*1)*PAGE_NX*2 );
518      if (state->fgpage[3] == page) tilemap_mark_tile_dirty(state->fg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*1)*PAGE_NX*2 );
531519   }
532520}
533521
r10427r10428
553541
554542static void wecleman_draw_road(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int priority)
555543{
544   wecleman_state *state = machine->driver_data<wecleman_state>();
556545// must be powers of 2
557546#define XSIZE 512
558547#define YSIZE 256
r10427r10428
593582         UINT32 pix;
594583         UINT16 road;
595584
596         road = wecleman_roadram[sy];
585         road = state->roadram[sy];
597586         if ((road>>8) != 0x02) continue;
598587
599         pix = rgb_ptr[(wecleman_roadram[sy+(YSIZE*2)] & 0xf) + 0x7f0];
588         pix = rgb_ptr[(state->roadram[sy+(YSIZE*2)] & 0xf) + 0x7f0];
600589
601590         for (sx = 0; sx < DST_WIDTH; sx++)
602591            dst[sx] = pix;
r10427r10428
619608         UINT32 pix;
620609         UINT16 road;
621610
622         road = wecleman_roadram[sy];
611         road = state->roadram[sy];
623612         if ((road>>8) != 0x04) continue;
624613         road &= YMASK;
625614
r10427r10428
634623         mdy = ((road * MIDCURB_DY) >> 8) * bitmap->rowpixels;
635624         tdy = ((road * TOPCURB_DY) >> 8) * bitmap->rowpixels;
636625
637         scrollx = wecleman_roadram[sy+YSIZE] + (0x18 - 0xe00);
626         scrollx = state->roadram[sy+YSIZE] + (0x18 - 0xe00);
638627
639         pal_ptr = road_rgb + ((wecleman_roadram[sy+(YSIZE*2)]<<3) & 8);
628         pal_ptr = road_rgb + ((state->roadram[sy+(YSIZE*2)]<<3) & 8);
640629
641630         for (sx = 0; sx < DST_WIDTH; sx++, scrollx++)
642631         {
r10427r10428
677666             int tmw_l2, int tmh_l2,      // tilemap width and height in log(2)
678667             int alpha, int pal_offset )   // alpha(0-3f), # of color codes to shift
679668{
669   wecleman_state *state = gfx->machine->driver_data<wecleman_state>();
680670   const UINT8 *src_ptr;
681671   UINT16 *tmap_ptr;
682672   UINT32 *dst_base, *dst_ptr;
r10427r10428
749739                  dg = (dstrgb >> 11) & 0x1f;
750740                  db = (dstrgb >> 19) & 0x1f;
751741
752                  dr = (t32x32pm[dr - sr + alpha] >> 5) + dr;
753                  dg = (t32x32pm[dg - sg + alpha] >> 5) + dg;
754                  db = (t32x32pm[db - sb + alpha] >> 5) + db;
742                  dr = (state->t32x32pm[dr - sr + alpha] >> 5) + dr;
743                  dg = (state->t32x32pm[dg - sg + alpha] >> 5) + dg;
744                  db = (state->t32x32pm[db - sb + alpha] >> 5) + db;
755745
756746                  dst_ptr[tx] = MAKE_RGB(pal5bit(db), pal5bit(dg), pal5bit(dr));
757747               }
r10427r10428
804794
805795static void hotchase_draw_road(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect)
806796{
797   wecleman_state *state = machine->driver_data<wecleman_state>();
807798/* Referred to what's in the ROMs */
808799#define XSIZE 512
809800#define YSIZE 512
r10427r10428
814805   /* Let's draw from the top to the bottom of the visible screen */
815806   for (sy = visarea.min_y;sy <= visarea.max_y;sy++)
816807   {
817      int code    = wecleman_roadram[sy*4/2+2/2] + (wecleman_roadram[sy*4/2+0/2] << 16);
808      int code    = state->roadram[sy*4/2+2/2] + (state->roadram[sy*4/2+0/2] << 16);
818809      int color   = ((code & 0x00f00000) >> 20) + 0x70;
819810      int scrollx = ((code & 0x0007fc00) >> 10) * 2;
820811
r10427r10428
845836// new video and palette code
846837WRITE16_HANDLER( wecleman_videostatus_w )
847838{
848   COMBINE_DATA(wecleman_videostatus);
839   wecleman_state *state = space->machine->driver_data<wecleman_state>();
840   COMBINE_DATA(state->videostatus);
849841
850842   // bit0-6: background transition, 0=off, 1=on
851843   // bit7: palette being changed, 0=no, 1=yes
852844   if (ACCESSING_BITS_0_7)
853845   {
854      if ((data & 0x7f) == 0 && !cloud_ds)
855         cloud_ds = BLEND_INC;
846      if ((data & 0x7f) == 0 && !state->cloud_ds)
847         state->cloud_ds = BLEND_INC;
856848      else
857      if ((data & 0x7f) == 1 && !cloud_visible)
849      if ((data & 0x7f) == 1 && !state->cloud_visible)
858850      {
859851         data ^= 1;
860         cloud_ds = BLEND_DEC;
861         cloud_visible = 1;
852         state->cloud_ds = BLEND_DEC;
853         state->cloud_visible = 1;
862854      }
863855   }
864856}
r10427r10428
894886
895887VIDEO_START( wecleman )
896888{
889   wecleman_state *state = machine->driver_data<wecleman_state>();
897890   /*
898891        Sprite banking - each bank is 0x20000 bytes (we support 0x40 bank codes)
899892        This game has ROMs for 16 banks
r10427r10428
912905   assert(machine->primary_screen->format() == BITMAP_FORMAT_RGB32);
913906   buffer = auto_alloc_array(machine, UINT8, 0x12c00);   // working buffer for sprite operations
914907
915   gameid = 0;
916   wecleman_gfx_bank = bank;
917   spr_offsx = -0xbc + BMP_PAD;
918   spr_offsy = 1 + BMP_PAD;
919   cloud_blend = BLEND_MAX;
920   cloud_ds = 0;
921   cloud_visible = 0;
922   black_pen = get_black_pen(machine);
908   state->gameid = 0;
909   state->gfx_bank = bank;
910   state->spr_offsx = -0xbc + BMP_PAD;
911   state->spr_offsy = 1 + BMP_PAD;
912   state->cloud_blend = BLEND_MAX;
913   state->cloud_ds = 0;
914   state->cloud_visible = 0;
915   state->black_pen = get_black_pen(machine);
923916
924   rgb_half     =          (UINT16*)(buffer + 0x00000);
925   t32x32pm     =             (int*)(buffer + 0x10020);
926   spr_ptr_list = (struct sprite **)(buffer + 0x12000);
927   spr_idx_list =            (int *)(buffer + 0x12400);
928   spr_pri_list =            (int *)(buffer + 0x12800);
917   state->rgb_half     =          (UINT16*)(buffer + 0x00000);
918   state->t32x32pm     =             (int*)(buffer + 0x10020);
919   state->spr_ptr_list = (struct sprite **)(buffer + 0x12000);
920   state->spr_idx_list =            (int *)(buffer + 0x12400);
921   state->spr_pri_list =            (int *)(buffer + 0x12800);
929922
930923   for (i=0; i<0x8000; i++)
931924   {
932925      j = i>>1;
933      rgb_half[i] = (j&0xf) | (j&0x1e0) | (j&0x3c00);
926      state->rgb_half[i] = (j&0xf) | (j&0x1e0) | (j&0x3c00);
934927   }
935928
936929   for (j=0; j<0x20; j++)
937930   {
938931      for (i=-0x1f; i<0x20; i++)
939932      {
940         *(t32x32pm + (j<<6) + i) = i * j;
933         *(state->t32x32pm + (j<<6) + i) = i * j;
941934      }
942935   }
943936
944   sprite_list = auto_alloc_array_clear(machine, struct sprite, NUM_SPRITES);
937   state->sprite_list = auto_alloc_array_clear(machine, struct sprite, NUM_SPRITES);
945938
946   bg_tilemap = tilemap_create(machine, wecleman_get_bg_tile_info,
939   state->bg_tilemap = tilemap_create(machine, wecleman_get_bg_tile_info,
947940                        tilemap_scan_rows,
948941                           /* We draw part of the road below */
949942                        8,8,
950943                        PAGE_NX * 2, PAGE_NY * 2 );
951944
952   fg_tilemap = tilemap_create(machine, wecleman_get_fg_tile_info,
945   state->fg_tilemap = tilemap_create(machine, wecleman_get_fg_tile_info,
953946                        tilemap_scan_rows,
954947
955948                        8,8,
956949                        PAGE_NX * 2, PAGE_NY * 2);
957950
958   txt_tilemap = tilemap_create(machine, wecleman_get_txt_tile_info,
951   state->txt_tilemap = tilemap_create(machine, wecleman_get_txt_tile_info,
959952                         tilemap_scan_rows,
960953
961954                         8,8,
962955                         PAGE_NX * 1, PAGE_NY * 1);
963956
964   tilemap_set_scroll_rows(bg_tilemap, TILEMAP_DIMY);   /* Screen-wise scrolling */
965   tilemap_set_scroll_cols(bg_tilemap, 1);
966   tilemap_set_transparent_pen(bg_tilemap,0);
957   tilemap_set_scroll_rows(state->bg_tilemap, TILEMAP_DIMY);   /* Screen-wise scrolling */
958   tilemap_set_scroll_cols(state->bg_tilemap, 1);
959   tilemap_set_transparent_pen(state->bg_tilemap,0);
967960
968   tilemap_set_scroll_rows(fg_tilemap, TILEMAP_DIMY);   /* Screen-wise scrolling */
969   tilemap_set_scroll_cols(fg_tilemap, 1);
970   tilemap_set_transparent_pen(fg_tilemap,0);
961   tilemap_set_scroll_rows(state->fg_tilemap, TILEMAP_DIMY);   /* Screen-wise scrolling */
962   tilemap_set_scroll_cols(state->fg_tilemap, 1);
963   tilemap_set_transparent_pen(state->fg_tilemap,0);
971964
972   tilemap_set_scroll_rows(txt_tilemap, 1);
973   tilemap_set_scroll_cols(txt_tilemap, 1);
974   tilemap_set_transparent_pen(txt_tilemap,0);
965   tilemap_set_scroll_rows(state->txt_tilemap, 1);
966   tilemap_set_scroll_cols(state->txt_tilemap, 1);
967   tilemap_set_transparent_pen(state->txt_tilemap,0);
975968
976   tilemap_set_scrollx(txt_tilemap, 0, 512-320-16 -BMP_PAD);
977   tilemap_set_scrolly(txt_tilemap, 0, -BMP_PAD );
969   tilemap_set_scrollx(state->txt_tilemap, 0, 512-320-16 -BMP_PAD);
970   tilemap_set_scrolly(state->txt_tilemap, 0, -BMP_PAD );
978971
979972   // patches out a mysterious pixel floating in the sky (tile decoding bug?)
980973   *(machine->gfx[0]->gfxdata + (machine->gfx[0]->char_modulo*0xaca+7)) = 0;
r10427r10428
996989
997990VIDEO_START( hotchase )
998991{
992   wecleman_state *state = machine->driver_data<wecleman_state>();
999993   /*
1000994        Sprite banking - each bank is 0x20000 bytes (we support 0x40 bank codes)
1001995        This game has ROMs for 0x30 banks
r10427r10428
10121006
10131007   buffer = auto_alloc_array(machine, UINT8, 0x400);   // reserve 1k for sprite list
10141008
1015   gameid = 1;
1016   wecleman_gfx_bank = bank;
1017   spr_offsx = -0xc0;
1018   spr_offsy = 0;
1019   black_pen = get_black_pen(machine);
1009   state->gameid = 1;
1010   state->gfx_bank = bank;
1011   state->spr_offsx = -0xc0;
1012   state->spr_offsy = 0;
1013   state->black_pen = get_black_pen(machine);
10201014
1021   spr_ptr_list = (struct sprite **)buffer;
1015   state->spr_ptr_list = (struct sprite **)buffer;
10221016
1023   sprite_list = auto_alloc_array_clear(machine, struct sprite, NUM_SPRITES);
1017   state->sprite_list = auto_alloc_array_clear(machine, struct sprite, NUM_SPRITES);
10241018}
10251019
10261020
r10427r10428
10301024
10311025VIDEO_UPDATE ( wecleman )
10321026{
1027   wecleman_state *state = screen->machine->driver_data<wecleman_state>();
10331028   const pen_t *mrct;
10341029   int video_on;
10351030   int fg_x, bg_x, fg_y, bg_y;
r10427r10428
10381033
10391034   mrct = screen->machine->pens;
10401035
1041   video_on = wecleman_irqctrl & 0x40;
1036   video_on = state->irqctrl & 0x40;
10421037
1043   set_led_status(screen->machine, 0, wecleman_selected_ip & 0x04);   // Start lamp
1038   set_led_status(screen->machine, 0, state->selected_ip & 0x04);   // Start lamp
10441039
1045   fg_y = (wecleman_txtram[0x0f24>>1] & (TILEMAP_DIMY - 1));
1046   bg_y = (wecleman_txtram[0x0f26>>1] & (TILEMAP_DIMY - 1));
1040   fg_y = (state->txtram[0x0f24>>1] & (TILEMAP_DIMY - 1));
1041   bg_y = (state->txtram[0x0f26>>1] & (TILEMAP_DIMY - 1));
10471042
1048   cloud_sx = wecleman_txtram[0xfee>>1] + 0xb0;
1043   cloud_sx = state->txtram[0xfee>>1] + 0xb0;
10491044   cloud_sy = bg_y;
10501045
1051   tilemap_set_scrolly(bg_tilemap, 0, bg_y -BMP_PAD);
1052   tilemap_set_scrolly(fg_tilemap, 0, fg_y -BMP_PAD);
1046   tilemap_set_scrolly(state->bg_tilemap, 0, bg_y -BMP_PAD);
1047   tilemap_set_scrolly(state->fg_tilemap, 0, fg_y -BMP_PAD);
10531048
10541049   for (i=0; i<(28<<2); i+=4)
10551050   {
1056      fg_x = wecleman_txtram[(i+0xf80)>>1] + (0xb0 -BMP_PAD);
1057      bg_x = wecleman_txtram[(i+0xf82)>>1] + (0xb0 -BMP_PAD);
1051      fg_x = state->txtram[(i+0xf80)>>1] + (0xb0 -BMP_PAD);
1052      bg_x = state->txtram[(i+0xf82)>>1] + (0xb0 -BMP_PAD);
10581053
10591054      k = i<<1;
10601055      for (j=0; j<8; j++)
10611056      {
1062         tilemap_set_scrollx(fg_tilemap, (fg_y + k + j) & (TILEMAP_DIMY - 1), fg_x);
1063         tilemap_set_scrollx(bg_tilemap, (bg_y + k + j) & (TILEMAP_DIMY - 1), bg_x);
1057         tilemap_set_scrollx(state->fg_tilemap, (fg_y + k + j) & (TILEMAP_DIMY - 1), fg_x);
1058         tilemap_set_scrollx(state->bg_tilemap, (bg_y + k + j) & (TILEMAP_DIMY - 1), bg_x);
10641059      }
10651060   }
10661061
r10427r10428
10701065
10711066   get_sprite_info(screen->machine);
10721067
1073   bitmap_fill(bitmap, cliprect, black_pen);
1068   bitmap_fill(bitmap, cliprect, state->black_pen);
10741069
10751070   /* Draw the road (lines which have priority 0x02) */
10761071   if (video_on) wecleman_draw_road(screen->machine, bitmap, cliprect, 0x02);
10771072
10781073   /* Draw the background */
1079   if (video_on) tilemap_draw(bitmap,cliprect, bg_tilemap, 0, 0);
1074   if (video_on) tilemap_draw(bitmap,cliprect, state->bg_tilemap, 0, 0);
10801075
10811076   // draws the cloud layer; needs work
1082   if (cloud_visible)
1077   if (state->cloud_visible)
10831078   {
10841079      /* palette hacks! */
10851080      ((pen_t *)mrct)[0] = ((pen_t *)mrct)[0x40] = ((pen_t *)mrct)[0x200] = ((pen_t *)mrct)[0x205];
r10427r10428
10881083         draw_cloud(
10891084         bitmap,
10901085         screen->machine->gfx[0],
1091         wecleman_pageram+0x1800,
1086         state->pageram+0x1800,
10921087         BMP_PAD, BMP_PAD,
10931088         41, 20,
10941089         cloud_sx, cloud_sy,
10951090         6, 5,
1096         cloud_blend/BLEND_STEPS, 0);
1091         state->cloud_blend/BLEND_STEPS, 0);
10971092
1098      cloud_blend += cloud_ds;
1093      state->cloud_blend += state->cloud_ds;
10991094
1100      if (cloud_blend < BLEND_MIN)
1101         { cloud_blend = BLEND_MIN; cloud_ds = 0; *wecleman_videostatus |= 1; }
1102      else if (cloud_blend > BLEND_MAX)
1103         { cloud_blend = BLEND_MAX; cloud_ds = 0; cloud_visible = 0; }
1095      if (state->cloud_blend < BLEND_MIN)
1096         { state->cloud_blend = BLEND_MIN; state->cloud_ds = 0; *state->videostatus |= 1; }
1097      else if (state->cloud_blend > BLEND_MAX)
1098         { state->cloud_blend = BLEND_MAX; state->cloud_ds = 0; state->cloud_visible = 0; }
11041099   }
11051100
11061101   /* Draw the foreground */
1107   if (video_on) tilemap_draw(bitmap,cliprect, fg_tilemap, 0, 0);
1102   if (video_on) tilemap_draw(bitmap,cliprect, state->fg_tilemap, 0, 0);
11081103
11091104   /* Draw the road (lines which have priority 0x04) */
11101105   if (video_on) wecleman_draw_road(screen->machine, bitmap,cliprect, 0x04);
11111106
11121107   /* Draw the sprites */
1113   if (video_on) sprite_draw(bitmap,cliprect);
1108   if (video_on) sprite_draw(screen->machine, bitmap,cliprect);
11141109
11151110   /* Draw the text layer */
1116   if (video_on) tilemap_draw(bitmap,cliprect, txt_tilemap, 0, 0);
1111   if (video_on) tilemap_draw(bitmap,cliprect, state->txt_tilemap, 0, 0);
11171112   return 0;
11181113}
11191114
r10427r10428
11231118
11241119VIDEO_UPDATE( hotchase )
11251120{
1121   wecleman_state *state = screen->machine->driver_data<wecleman_state>();
11261122   device_t *k051316_1 = screen->machine->device("k051316_1");
11271123   device_t *k051316_2 = screen->machine->device("k051316_2");
11281124   int video_on;
11291125
1130   video_on = wecleman_irqctrl & 0x40;
1126   video_on = state->irqctrl & 0x40;
11311127
1132   set_led_status(screen->machine, 0, wecleman_selected_ip & 0x04);   // Start lamp
1128   set_led_status(screen->machine, 0, state->selected_ip & 0x04);   // Start lamp
11331129
11341130   get_sprite_info(screen->machine);
11351131
1136   bitmap_fill(bitmap, cliprect, black_pen);
1132   bitmap_fill(bitmap, cliprect, state->black_pen);
11371133
11381134   /* Draw the background */
11391135   if (video_on)
r10427r10428
11451141
11461142   /* Draw the sprites */
11471143   if (video_on)
1148      sprite_draw(bitmap,cliprect);
1144      sprite_draw(screen->machine, bitmap,cliprect);
11491145
11501146   /* Draw the foreground (text) */
11511147   if (video_on)
src/mame/video/dec0.c
r10427r10428
9797#include "emu.h"
9898#include "includes/dec0.h"
9999
100static tilemap_t *pf1_tilemap_0,*pf1_tilemap_1,*pf1_tilemap_2;
101static tilemap_t *pf2_tilemap_0,*pf2_tilemap_1,*pf2_tilemap_2;
102static tilemap_t *pf3_tilemap_0,*pf3_tilemap_1,*pf3_tilemap_2;
103100
104UINT16 *dec0_pf1_data,*dec0_pf2_data,*dec0_pf3_data;
105UINT16 *dec0_pf1_rowscroll,*dec0_pf2_rowscroll,*dec0_pf3_rowscroll;
106UINT16 *dec0_pf1_colscroll,*dec0_pf2_colscroll,*dec0_pf3_colscroll;
107static UINT16 dec0_pf1_control_0[4];
108static UINT16 dec0_pf1_control_1[4];
109static UINT16 dec0_pf2_control_0[4];
110static UINT16 dec0_pf2_control_1[4];
111static UINT16 dec0_pf3_control_0[4];
112static UINT16 dec0_pf3_control_1[4];
113static UINT16 *dec0_spriteram;
114static UINT16 dec0_pri;
115101
116102/******************************************************************************/
117103
118104WRITE16_HANDLER( dec0_update_sprites_w )
119105{
120   memcpy(dec0_spriteram,space->machine->generic.spriteram.u16,0x800);
106   dec0_state *state = space->machine->driver_data<dec0_state>();
107   memcpy(state->spriteram,space->machine->generic.spriteram.u16,0x800);
121108}
122109
123110/******************************************************************************/
r10427r10428
149136
150137static void draw_sprites(running_machine* machine, bitmap_t *bitmap,const rectangle *cliprect,int pri_mask,int pri_val)
151138{
139   dec0_state *state = machine->driver_data<dec0_state>();
152140   int offs;
153141
154142   for (offs = 0;offs < 0x400;offs += 4)
155143   {
156144      int x,y,sprite,colour,multi,fx,fy,inc,flash,mult;
157145
158      y = dec0_spriteram[offs];
146      y = state->spriteram[offs];
159147      if ((y&0x8000) == 0) continue;
160148
161      x = dec0_spriteram[offs+2];
149      x = state->spriteram[offs+2];
162150      colour = x >> 12;
163151      if ((colour & pri_mask) != pri_val) continue;
164152
r10427r10428
170158      multi = (1 << ((y & 0x1800) >> 11)) - 1;   /* 1x, 2x, 4x, 8x height */
171159                                 /* multi = 0   1   3   7 */
172160
173      sprite = dec0_spriteram[offs+1] & 0x0fff;
161      sprite = state->spriteram[offs+1] & 0x0fff;
174162
175163      x = x & 0x01ff;
176164      y = y & 0x01ff;
r10427r10428
299287
300288static void dec0_pf1_draw(running_machine *machine,bitmap_t *bitmap,const rectangle *cliprect,int flags)
301289{
302   switch (dec0_pf1_control_0[3]&0x3) {
290   dec0_state *state = machine->driver_data<dec0_state>();
291   switch (state->pf1_control_0[3]&0x3) {
303292      case 0:   /* 4x1 */
304         custom_tilemap_draw(machine,bitmap,cliprect,pf1_tilemap_0,dec0_pf1_rowscroll,dec0_pf1_colscroll,dec0_pf1_control_0,dec0_pf1_control_1,flags);
293         custom_tilemap_draw(machine,bitmap,cliprect,state->pf1_tilemap_0,state->pf1_rowscroll,state->pf1_colscroll,state->pf1_control_0,state->pf1_control_1,flags);
305294         break;
306295      case 1:   /* 2x2 */
307296      default:
308         custom_tilemap_draw(machine,bitmap,cliprect,pf1_tilemap_1,dec0_pf1_rowscroll,dec0_pf1_colscroll,dec0_pf1_control_0,dec0_pf1_control_1,flags);
297         custom_tilemap_draw(machine,bitmap,cliprect,state->pf1_tilemap_1,state->pf1_rowscroll,state->pf1_colscroll,state->pf1_control_0,state->pf1_control_1,flags);
309298         break;
310299      case 2:   /* 1x4 */
311         custom_tilemap_draw(machine,bitmap,cliprect,pf1_tilemap_2,dec0_pf1_rowscroll,dec0_pf1_colscroll,dec0_pf1_control_0,dec0_pf1_control_1,flags);
300         custom_tilemap_draw(machine,bitmap,cliprect,state->pf1_tilemap_2,state->pf1_rowscroll,state->pf1_colscroll,state->pf1_control_0,state->pf1_control_1,flags);
312301         break;
313302   };
314303}
315304
316305static void dec0_pf2_draw(running_machine *machine,bitmap_t *bitmap,const rectangle *cliprect,int flags)
317306{
318   switch (dec0_pf2_control_0[3]&0x3) {
307   dec0_state *state = machine->driver_data<dec0_state>();
308   switch (state->pf2_control_0[3]&0x3) {
319309      case 0:   /* 4x1 */
320         custom_tilemap_draw(machine,bitmap,cliprect,pf2_tilemap_0,dec0_pf2_rowscroll,dec0_pf2_colscroll,dec0_pf2_control_0,dec0_pf2_control_1,flags);
310         custom_tilemap_draw(machine,bitmap,cliprect,state->pf2_tilemap_0,state->pf2_rowscroll,state->pf2_colscroll,state->pf2_control_0,state->pf2_control_1,flags);
321311         break;
322312      case 1:   /* 2x2 */
323313      default:
324         custom_tilemap_draw(machine,bitmap,cliprect,pf2_tilemap_1,dec0_pf2_rowscroll,dec0_pf2_colscroll,dec0_pf2_control_0,dec0_pf2_control_1,flags);
314         custom_tilemap_draw(machine,bitmap,cliprect,state->pf2_tilemap_1,state->pf2_rowscroll,state->pf2_colscroll,state->pf2_control_0,state->pf2_control_1,flags);
325315         break;
326316      case 2:   /* 1x4 */
327         custom_tilemap_draw(machine,bitmap,cliprect,pf2_tilemap_2,dec0_pf2_rowscroll,dec0_pf2_colscroll,dec0_pf2_control_0,dec0_pf2_control_1,flags);
317         custom_tilemap_draw(machine,bitmap,cliprect,state->pf2_tilemap_2,state->pf2_rowscroll,state->pf2_colscroll,state->pf2_control_0,state->pf2_control_1,flags);
328318         break;
329319   };
330320}
331321
332322static void dec0_pf3_draw(running_machine *machine,bitmap_t *bitmap,const rectangle *cliprect,int flags)
333323{
334   switch (dec0_pf3_control_0[3]&0x3) {
324   dec0_state *state = machine->driver_data<dec0_state>();
325   switch (state->pf3_control_0[3]&0x3) {
335326      case 0:   /* 4x1 */
336         custom_tilemap_draw(machine,bitmap,cliprect,pf3_tilemap_0,dec0_pf3_rowscroll,dec0_pf3_colscroll,dec0_pf3_control_0,dec0_pf3_control_1,flags);
327         custom_tilemap_draw(machine,bitmap,cliprect,state->pf3_tilemap_0,state->pf3_rowscroll,state->pf3_colscroll,state->pf3_control_0,state->pf3_control_1,flags);
337328         break;
338329      case 1:   /* 2x2 */
339330      default:
340         custom_tilemap_draw(machine,bitmap,cliprect,pf3_tilemap_1,dec0_pf3_rowscroll,dec0_pf3_colscroll,dec0_pf3_control_0,dec0_pf3_control_1,flags);
331         custom_tilemap_draw(machine,bitmap,cliprect,state->pf3_tilemap_1,state->pf3_rowscroll,state->pf3_colscroll,state->pf3_control_0,state->pf3_control_1,flags);
341332         break;
342333      case 2:   /* 1x4 */
343         custom_tilemap_draw(machine,bitmap,cliprect,pf3_tilemap_2,dec0_pf3_rowscroll,dec0_pf3_colscroll,dec0_pf3_control_0,dec0_pf3_control_1,flags);
334         custom_tilemap_draw(machine,bitmap,cliprect,state->pf3_tilemap_2,state->pf3_rowscroll,state->pf3_colscroll,state->pf3_control_0,state->pf3_control_1,flags);
344335         break;
345336   };
346337}
r10427r10428
349340
350341VIDEO_UPDATE( hbarrel )
351342{
352   flip_screen_set(screen->machine, dec0_pf1_control_0[0]&0x80);
343   dec0_state *state = screen->machine->driver_data<dec0_state>();
344   flip_screen_set(screen->machine, state->pf1_control_0[0]&0x80);
353345
354346   dec0_pf3_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_OPAQUE);
355347   draw_sprites(screen->machine,bitmap,cliprect,0x08,0x08);
r10427r10428
366358
367359VIDEO_UPDATE( baddudes )
368360{
369   flip_screen_set(screen->machine, dec0_pf1_control_0[0]&0x80);
361   dec0_state *state = screen->machine->driver_data<dec0_state>();
362   flip_screen_set(screen->machine, state->pf1_control_0[0]&0x80);
370363
371364   /* WARNING: inverted wrt Midnight Resistance */
372   if ((dec0_pri & 0x01) == 0)
365   if ((state->pri & 0x01) == 0)
373366   {
374367      dec0_pf2_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_OPAQUE);
375368      dec0_pf3_draw(screen->machine,bitmap,cliprect,0);
376369
377      if (dec0_pri & 2)
370      if (state->pri & 2)
378371         dec0_pf2_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_LAYER0); /* Foreground pens only */
379372
380373      draw_sprites(screen->machine,bitmap,cliprect,0x00,0x00);
381374
382      if (dec0_pri & 4)
375      if (state->pri & 4)
383376         dec0_pf3_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_LAYER0); /* Foreground pens only */
384377   }
385378   else
r10427r10428
387380      dec0_pf3_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_OPAQUE);
388381      dec0_pf2_draw(screen->machine,bitmap,cliprect,0);
389382
390      if (dec0_pri & 2)
383      if (state->pri & 2)
391384         dec0_pf3_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_LAYER0); /* Foreground pens only */
392385
393386      draw_sprites(screen->machine,bitmap,cliprect,0x00,0x00);
394387
395      if (dec0_pri & 4)
388      if (state->pri & 4)
396389         dec0_pf2_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_LAYER0); /* Foreground pens only */
397390   }
398391
r10427r10428
404397
405398VIDEO_UPDATE( robocop )
406399{
400   dec0_state *state = screen->machine->driver_data<dec0_state>();
407401   int trans;
408402
409   flip_screen_set(screen->machine, dec0_pf1_control_0[0]&0x80);
403   flip_screen_set(screen->machine, state->pf1_control_0[0]&0x80);
410404
411   if (dec0_pri & 0x04)
405   if (state->pri & 0x04)
412406      trans = 0x08;
413407   else
414408      trans = 0x00;
415409
416   if (dec0_pri & 0x01)
410   if (state->pri & 0x01)
417411   {
418412      /* WARNING: inverted wrt Midnight Resistance */
419413      /* Robocop uses it only for the title screen, so this might be just */
r10427r10428
421415      /* something (they are 0x80 in midres, 0x00 here) */
422416      dec0_pf2_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_LAYER1|TILEMAP_DRAW_OPAQUE);
423417
424      if (dec0_pri & 0x02)
418      if (state->pri & 0x02)
425419         draw_sprites(screen->machine,bitmap,cliprect,0x08,trans);
426420
427421      dec0_pf3_draw(screen->machine,bitmap,cliprect,0);
r10427r10428
430424   {
431425      dec0_pf3_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_OPAQUE);
432426
433      if (dec0_pri & 0x02)
427      if (state->pri & 0x02)
434428         draw_sprites(screen->machine,bitmap,cliprect,0x08,trans);
435429
436430      dec0_pf2_draw(screen->machine,bitmap,cliprect,0);
437431   }
438432
439   if (dec0_pri & 0x02)
433   if (state->pri & 0x02)
440434      draw_sprites(screen->machine,bitmap,cliprect,0x08,trans ^ 0x08);
441435   else
442436      draw_sprites(screen->machine,bitmap,cliprect,0x00,0x00);
r10427r10428
449443
450444VIDEO_UPDATE( birdtry )
451445{
452   flip_screen_set(screen->machine, dec0_pf1_control_0[0]&0x80);
446   dec0_state *state = screen->machine->driver_data<dec0_state>();
447   flip_screen_set(screen->machine, state->pf1_control_0[0]&0x80);
453448
454449   /* This game doesn't have the extra playfield chip on the game board, but
455450    the palette does show through. */
r10427r10428
464459
465460VIDEO_UPDATE( hippodrm )
466461{
467   flip_screen_set(screen->machine, dec0_pf1_control_0[0]&0x80);
462   dec0_state *state = screen->machine->driver_data<dec0_state>();
463   flip_screen_set(screen->machine, state->pf1_control_0[0]&0x80);
468464
469   if (dec0_pri & 0x01)
465   if (state->pri & 0x01)
470466   {
471467      dec0_pf2_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_OPAQUE);
472468      dec0_pf3_draw(screen->machine,bitmap,cliprect,0);
r10427r10428
486482
487483VIDEO_UPDATE( slyspy )
488484{
489   flip_screen_set(screen->machine, dec0_pf1_control_0[0]&0x80);
485   dec0_state *state = screen->machine->driver_data<dec0_state>();
486   flip_screen_set(screen->machine, state->pf1_control_0[0]&0x80);
490487
491488   dec0_pf3_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_OPAQUE);
492489   dec0_pf2_draw(screen->machine,bitmap,cliprect,0);
r10427r10428
494491   draw_sprites(screen->machine,bitmap,cliprect,0x00,0x00);
495492
496493   /* Redraw top 8 pens of top 8 palettes over sprites */
497   if (dec0_pri&0x80)
494   if (state->pri&0x80)
498495      dec0_pf2_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_LAYER0);
499496
500497   dec0_pf1_draw(screen->machine,bitmap,cliprect,0);
r10427r10428
505502
506503VIDEO_UPDATE( midres )
507504{
505   dec0_state *state = screen->machine->driver_data<dec0_state>();
508506   int trans;
509507
510   flip_screen_set(screen->machine, dec0_pf1_control_0[0]&0x80);
508   flip_screen_set(screen->machine, state->pf1_control_0[0]&0x80);
511509
512   if (dec0_pri & 0x04)
510   if (state->pri & 0x04)
513511      trans = 0x00;
514512   else trans = 0x08;
515513
516   if (dec0_pri & 0x01)
514   if (state->pri & 0x01)
517515   {
518516      dec0_pf2_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_OPAQUE);
519517
520      if (dec0_pri & 0x02)
518      if (state->pri & 0x02)
521519         draw_sprites(screen->machine,bitmap,cliprect,0x08,trans);
522520
523521      dec0_pf3_draw(screen->machine,bitmap,cliprect,0);
r10427r10428
526524   {
527525      dec0_pf3_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_OPAQUE);
528526
529      if (dec0_pri & 0x02)
527      if (state->pri & 0x02)
530528         draw_sprites(screen->machine,bitmap,cliprect,0x08,trans);
531529
532530      dec0_pf2_draw(screen->machine,bitmap,cliprect,0);
533531   }
534532
535   if (dec0_pri & 0x02)
533   if (state->pri & 0x02)
536534      draw_sprites(screen->machine,bitmap,cliprect,0x08,trans ^ 0x08);
537535   else
538536      draw_sprites(screen->machine,bitmap,cliprect,0x00,0x00);
r10427r10428
545543
546544WRITE16_HANDLER( dec0_pf1_control_0_w )
547545{
548   COMBINE_DATA(&dec0_pf1_control_0[offset]);
546   dec0_state *state = space->machine->driver_data<dec0_state>();
547   COMBINE_DATA(&state->pf1_control_0[offset]);
549548}
550549
551550WRITE16_HANDLER( dec0_pf1_control_1_w )
552551{
553   COMBINE_DATA(&dec0_pf1_control_1[offset]);
552   dec0_state *state = space->machine->driver_data<dec0_state>();
553   COMBINE_DATA(&state->pf1_control_1[offset]);
554554}
555555
556556WRITE16_HANDLER( dec0_pf1_data_w )
557557{
558   COMBINE_DATA(&dec0_pf1_data[offset]);
559   tilemap_mark_tile_dirty(pf1_tilemap_0,offset);
560   tilemap_mark_tile_dirty(pf1_tilemap_1,offset);
561   tilemap_mark_tile_dirty(pf1_tilemap_2,offset);
558   dec0_state *state = space->machine->driver_data<dec0_state>();
559   COMBINE_DATA(&state->pf1_data[offset]);
560   tilemap_mark_tile_dirty(state->pf1_tilemap_0,offset);
561   tilemap_mark_tile_dirty(state->pf1_tilemap_1,offset);
562   tilemap_mark_tile_dirty(state->pf1_tilemap_2,offset);
562563}
563564
564565WRITE16_HANDLER( dec0_pf2_control_0_w )
565566{
566   COMBINE_DATA(&dec0_pf2_control_0[offset]);
567   dec0_state *state = space->machine->driver_data<dec0_state>();
568   COMBINE_DATA(&state->pf2_control_0[offset]);
567569}
568570
569571WRITE16_HANDLER( dec0_pf2_control_1_w )
570572{
571   COMBINE_DATA(&dec0_pf2_control_1[offset]);
573   dec0_state *state = space->machine->driver_data<dec0_state>();
574   COMBINE_DATA(&state->pf2_control_1[offset]);
572575}
573576
574577WRITE16_HANDLER( dec0_pf2_data_w )
575578{
576   COMBINE_DATA(&dec0_pf2_data[offset]);
577   tilemap_mark_tile_dirty(pf2_tilemap_0,offset);
578   tilemap_mark_tile_dirty(pf2_tilemap_1,offset);
579   tilemap_mark_tile_dirty(pf2_tilemap_2,offset);
579   dec0_state *state = space->machine->driver_data<dec0_state>();
580   COMBINE_DATA(&state->pf2_data[offset]);
581   tilemap_mark_tile_dirty(state->pf2_tilemap_0,offset);
582   tilemap_mark_tile_dirty(state->pf2_tilemap_1,offset);
583   tilemap_mark_tile_dirty(state->pf2_tilemap_2,offset);
580584}
581585
582586WRITE16_HANDLER( dec0_pf3_control_0_w )
583587{
584   COMBINE_DATA(&dec0_pf3_control_0[offset]);
588   dec0_state *state = space->machine->driver_data<dec0_state>();
589   COMBINE_DATA(&state->pf3_control_0[offset]);
585590}
586591
587592WRITE16_HANDLER( dec0_pf3_control_1_w )
588593{
589   COMBINE_DATA(&dec0_pf3_control_1[offset]);
594   dec0_state *state = space->machine->driver_data<dec0_state>();
595   COMBINE_DATA(&state->pf3_control_1[offset]);
590596}
591597
592598WRITE16_HANDLER( dec0_pf3_data_w )
593599{
594   COMBINE_DATA(&dec0_pf3_data[offset]);
595   tilemap_mark_tile_dirty(pf3_tilemap_0,offset);
596   tilemap_mark_tile_dirty(pf3_tilemap_1,offset);
597   tilemap_mark_tile_dirty(pf3_tilemap_2,offset);
600   dec0_state *state = space->machine->driver_data<dec0_state>();
601   COMBINE_DATA(&state->pf3_data[offset]);
602   tilemap_mark_tile_dirty(state->pf3_tilemap_0,offset);
603   tilemap_mark_tile_dirty(state->pf3_tilemap_1,offset);
604   tilemap_mark_tile_dirty(state->pf3_tilemap_2,offset);
598605}
599606
600607WRITE16_HANDLER( dec0_priority_w )
601608{
602   COMBINE_DATA(&dec0_pri);
609   dec0_state *state = space->machine->driver_data<dec0_state>();
610   COMBINE_DATA(&state->pri);
603611}
604612
605613WRITE8_HANDLER( dec0_pf3_control_8bit_w )
606614{
607   static int buffer[0x20];
615   dec0_state *state = space->machine->driver_data<dec0_state>();
608616   UINT16 myword;
609617
610   buffer[offset]=data;
618   state->buffer[offset]=data;
611619
612620   /* Rearrange little endian bytes from H6280 into big endian words for 68k */
613621   offset&=0xffe;
614   myword=buffer[offset] + (buffer[offset+1]<<8);
622   myword=state->buffer[offset] + (state->buffer[offset+1]<<8);
615623
616624   if (offset<0x10) dec0_pf3_control_0_w(space,offset/2,myword,0xffff);
617625   else dec0_pf3_control_1_w(space,(offset-0x10)/2,myword,0xffff);
r10427r10428
619627
620628WRITE8_HANDLER( dec0_pf3_data_8bit_w )
621629{
630   dec0_state *state = space->machine->driver_data<dec0_state>();
622631   if (offset&1) { /* MSB has changed */
623      UINT16 lsb=dec0_pf3_data[offset>>1];
632      UINT16 lsb=state->pf3_data[offset>>1];
624633      UINT16 newword=(lsb&0xff) | (data<<8);
625      dec0_pf3_data[offset>>1]=newword;
634      state->pf3_data[offset>>1]=newword;
626635   }
627636   else { /* LSB has changed */
628      UINT16 msb=dec0_pf3_data[offset>>1];
637      UINT16 msb=state->pf3_data[offset>>1];
629638      UINT16 newword=(msb&0xff00) | data;
630      dec0_pf3_data[offset>>1]=newword;
639      state->pf3_data[offset>>1]=newword;
631640   }
632   tilemap_mark_tile_dirty(pf3_tilemap_0,offset>>1);
633   tilemap_mark_tile_dirty(pf3_tilemap_1,offset>>1);
634   tilemap_mark_tile_dirty(pf3_tilemap_2,offset>>1);
641   tilemap_mark_tile_dirty(state->pf3_tilemap_0,offset>>1);
642   tilemap_mark_tile_dirty(state->pf3_tilemap_1,offset>>1);
643   tilemap_mark_tile_dirty(state->pf3_tilemap_2,offset>>1);
635644}
636645
637646READ8_HANDLER( dec0_pf3_data_8bit_r )
638647{
648   dec0_state *state = space->machine->driver_data<dec0_state>();
639649   if (offset&1) /* MSB */
640      return dec0_pf3_data[offset>>1]>>8;
650      return state->pf3_data[offset>>1]>>8;
641651
642   return dec0_pf3_data[offset>>1]&0xff;
652   return state->pf3_data[offset>>1]&0xff;
643653}
644654
645655/******************************************************************************/
r10427r10428
676686
677687static TILE_GET_INFO( get_pf1_tile_info )
678688{
679   int tile=dec0_pf1_data[tile_index];
689   dec0_state *state = machine->driver_data<dec0_state>();
690   int tile=state->pf1_data[tile_index];
680691   SET_TILE_INFO(0,tile&0xfff,tile>>12,0);
681692}
682693
683694static TILE_GET_INFO( get_pf2_tile_info )
684695{
685   int tile=dec0_pf2_data[tile_index];
696   dec0_state *state = machine->driver_data<dec0_state>();
697   int tile=state->pf2_data[tile_index];
686698   int pri=((tile>>12)>7);
687699   SET_TILE_INFO(1,tile&0xfff,tile>>12,0);
688700   tileinfo->group = pri;
r10427r10428
690702
691703static TILE_GET_INFO( get_pf3_tile_info )
692704{
693   int tile=dec0_pf3_data[tile_index];
705   dec0_state *state = machine->driver_data<dec0_state>();
706   int tile=state->pf3_data[tile_index];
694707   int pri=((tile>>12)>7);
695708   SET_TILE_INFO(2,tile&0xfff,tile>>12,0);
696709   tileinfo->group = pri;
r10427r10428
698711
699712VIDEO_START( dec0_nodma )
700713{
701   pf1_tilemap_0 = tilemap_create(machine, get_pf1_tile_info,tile_shape0_8x8_scan, 8, 8,128, 32);
702   pf1_tilemap_1 = tilemap_create(machine, get_pf1_tile_info,tile_shape1_8x8_scan, 8, 8, 64, 64);
703   pf1_tilemap_2 = tilemap_create(machine, get_pf1_tile_info,tile_shape2_8x8_scan, 8, 8, 32,128);
704   pf2_tilemap_0 = tilemap_create(machine, get_pf2_tile_info,tile_shape0_scan,    16,16, 64, 16);
705   pf2_tilemap_1 = tilemap_create(machine, get_pf2_tile_info,tile_shape1_scan,    16,16, 32, 32);
706   pf2_tilemap_2 = tilemap_create(machine, get_pf2_tile_info,tile_shape2_scan,    16,16, 16, 64);
707   pf3_tilemap_0 = tilemap_create(machine, get_pf3_tile_info,tile_shape0_scan,    16,16, 64, 16);
708   pf3_tilemap_1 = tilemap_create(machine, get_pf3_tile_info,tile_shape1_scan,    16,16, 32, 32);
709   pf3_tilemap_2 = tilemap_create(machine, get_pf3_tile_info,tile_shape2_scan,    16,16, 16, 64);
714   dec0_state *state = machine->driver_data<dec0_state>();
715   state->pf1_tilemap_0 = tilemap_create(machine, get_pf1_tile_info,tile_shape0_8x8_scan, 8, 8,128, 32);
716   state->pf1_tilemap_1 = tilemap_create(machine, get_pf1_tile_info,tile_shape1_8x8_scan, 8, 8, 64, 64);
717   state->pf1_tilemap_2 = tilemap_create(machine, get_pf1_tile_info,tile_shape2_8x8_scan, 8, 8, 32,128);
718   state->pf2_tilemap_0 = tilemap_create(machine, get_pf2_tile_info,tile_shape0_scan,    16,16, 64, 16);
719   state->pf2_tilemap_1 = tilemap_create(machine, get_pf2_tile_info,tile_shape1_scan,    16,16, 32, 32);
720   state->pf2_tilemap_2 = tilemap_create(machine, get_pf2_tile_info,tile_shape2_scan,    16,16, 16, 64);
721   state->pf3_tilemap_0 = tilemap_create(machine, get_pf3_tile_info,tile_shape0_scan,    16,16, 64, 16);
722   state->pf3_tilemap_1 = tilemap_create(machine, get_pf3_tile_info,tile_shape1_scan,    16,16, 32, 32);
723   state->pf3_tilemap_2 = tilemap_create(machine, get_pf3_tile_info,tile_shape2_scan,    16,16, 16, 64);
710724
711   dec0_spriteram=machine->generic.spriteram.u16;
725   state->spriteram=machine->generic.spriteram.u16;
712726}
713727
714728VIDEO_START( dec0 )
715729{
730   dec0_state *state = machine->driver_data<dec0_state>();
716731   VIDEO_START_CALL(dec0_nodma);
717   dec0_spriteram=auto_alloc_array(machine, UINT16, 0x800/2);
732   state->spriteram=auto_alloc_array(machine, UINT16, 0x800/2);
718733}
719734
720735/******************************************************************************/
src/mame/video/atarig42.c
r10427r10428
2020
2121
2222#include "emu.h"
23#include "machine/atarigen.h"
23#include "video/atarirle.h"
2424#include "includes/atarig42.h"
2525
2626
r10427r10428
6969
7070VIDEO_START( atarig42 )
7171{
72   static const atarirle_desc modesc =
73   {
74      "gfx3",      /* region where the GFX data lives */
75      256,      /* number of entries in sprite RAM */
76      0,         /* left clip coordinate */
77      0,         /* right clip coordinate */
78
79      0x000,      /* base palette entry */
80      0x400,      /* maximum number of colors */
81
82      {{ 0x7fff,0,0,0,0,0,0,0 }},   /* mask for the code index */
83      {{ 0,0x03f0,0,0,0,0,0,0 }},   /* mask for the color */
84      {{ 0,0,0xffc0,0,0,0,0,0 }},   /* mask for the X position */
85      {{ 0,0,0,0xffc0,0,0,0,0 }},   /* mask for the Y position */
86      {{ 0,0,0,0,0xffff,0,0,0 }},   /* mask for the scale factor */
87      {{ 0x8000,0,0,0,0,0,0,0 }},   /* mask for the horizontal flip */
88      {{ 0,0,0,0,0,0,0x00ff,0 }},   /* mask for the order */
89      {{ 0,0x0e00,0,0,0,0,0,0 }},   /* mask for the priority */
90      {{ 0 }}                  /* mask for the VRAM target */
91   };
9272   atarig42_state *state = machine->driver_data<atarig42_state>();
93   atarirle_desc adjusted_modesc = modesc;
94   int i;
9573
9674   /* blend the playfields and free the temporary one */
9775   atarigen_blend_gfx(machine, 0, 2, 0x0f, 0x30);
r10427r10428
10078   state->playfield_tilemap = tilemap_create(machine, get_playfield_tile_info, atarig42_playfield_scan,  8,8, 128,64);
10179
10280   /* initialize the motion objects */
103   adjusted_modesc.palettebase = state->motion_object_base;
104   for (i = 0; i < 8; i++)
105      adjusted_modesc.colormask.data[i] &= state->motion_object_mask;
106   atarirle_init(machine, 0, &adjusted_modesc);
81   state->rle = machine->device("rle");
10782
10883   /* initialize the alphanumerics */
10984   state->alpha_tilemap = tilemap_create(machine, get_alpha_tile_info, tilemap_scan_rows,  8,8, 64,32);
r10427r10428
223198
224199   /* copy the motion objects on top */
225200   {
226      bitmap_t *mo_bitmap = atarirle_get_vram(0, 0);
201      bitmap_t *mo_bitmap = atarirle_get_vram(state->rle, 0);
227202      int left   = cliprect->min_x;
228203      int top      = cliprect->min_y;
229204      int right   = cliprect->max_x + 1;
r10427r10428
251226   tilemap_draw(bitmap, cliprect, state->alpha_tilemap, 0, 0);
252227   return 0;
253228}
229
230VIDEO_EOF( atarig42 )
231{
232   atarig42_state *state = machine->driver_data<atarig42_state>();
233
234   atarirle_eof(state->rle);
235}
src/mame/video/tp84.c
r10427r10428
1111#include "includes/tp84.h"
1212
1313
14UINT8 *tp84_bg_videoram;
15UINT8 *tp84_bg_colorram;
16UINT8 *tp84_fg_videoram;
17UINT8 *tp84_fg_colorram;
18UINT8 *tp84_spriteram;
19UINT8 *tp84_scroll_x;
20UINT8 *tp84_scroll_y;
21UINT8 *tp84_palette_bank;
22UINT8 *tp84_flipscreen_x;
23UINT8 *tp84_flipscreen_y;
2414
25static tilemap_t *bg_tilemap, *fg_tilemap;
2615
2716
2817/*
r10427r10428
116105
117106WRITE8_HANDLER( tp84_spriteram_w )
118107{
108   tp84_state *state = space->machine->driver_data<tp84_state>();
119109   /* the game multiplexes the sprites, so update now */
120110   space->machine->primary_screen->update_now();
121   tp84_spriteram[offset] = data;
111   state->spriteram[offset] = data;
122112}
123113
124114
r10427r10428
131121
132122static TILE_GET_INFO( get_bg_tile_info )
133123{
134   int code = ((tp84_bg_colorram[tile_index] & 0x30) << 4) | tp84_bg_videoram[tile_index];
135   int color = ((*tp84_palette_bank & 0x07) << 6) |
136            ((*tp84_palette_bank & 0x18) << 1) |
137            (tp84_bg_colorram[tile_index] & 0x0f);
138   int flags = TILE_FLIPYX(tp84_bg_colorram[tile_index] >> 6);
124   tp84_state *state = machine->driver_data<tp84_state>();
125   int code = ((state->bg_colorram[tile_index] & 0x30) << 4) | state->bg_videoram[tile_index];
126   int color = ((*state->palette_bank & 0x07) << 6) |
127            ((*state->palette_bank & 0x18) << 1) |
128            (state->bg_colorram[tile_index] & 0x0f);
129   int flags = TILE_FLIPYX(state->bg_colorram[tile_index] >> 6);
139130
140131   SET_TILE_INFO(0, code, color, flags);
141132}
142133
143134static TILE_GET_INFO( get_fg_tile_info )
144135{
145   int code = ((tp84_fg_colorram[tile_index] & 0x30) << 4) | tp84_fg_videoram[tile_index];
146   int color = ((*tp84_palette_bank & 0x07) << 6) |
147            ((*tp84_palette_bank & 0x18) << 1) |
148            (tp84_fg_colorram[tile_index] & 0x0f);
149   int flags = TILE_FLIPYX(tp84_fg_colorram[tile_index] >> 6);
136   tp84_state *state = machine->driver_data<tp84_state>();
137   int code = ((state->fg_colorram[tile_index] & 0x30) << 4) | state->fg_videoram[tile_index];
138   int color = ((*state->palette_bank & 0x07) << 6) |
139            ((*state->palette_bank & 0x18) << 1) |
140            (state->fg_colorram[tile_index] & 0x0f);
141   int flags = TILE_FLIPYX(state->fg_colorram[tile_index] >> 6);
150142
151143   SET_TILE_INFO(0, code, color, flags);
152144}
r10427r10428
154146
155147VIDEO_START( tp84 )
156148{
157   bg_tilemap = tilemap_create(machine, get_bg_tile_info, tilemap_scan_rows, 8, 8, 32, 32);
158   fg_tilemap = tilemap_create(machine, get_fg_tile_info, tilemap_scan_rows, 8, 8, 32, 32);
149   tp84_state *state = machine->driver_data<tp84_state>();
150   state->bg_tilemap = tilemap_create(machine, get_bg_tile_info, tilemap_scan_rows, 8, 8, 32, 32);
151   state->fg_tilemap = tilemap_create(machine, get_fg_tile_info, tilemap_scan_rows, 8, 8, 32, 32);
159152}
160153
161154
162155static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect)
163156{
157   tp84_state *state = machine->driver_data<tp84_state>();
164158   int offs;
165   int palette_base = ((*tp84_palette_bank & 0x07) << 4);
159   int palette_base = ((*state->palette_bank & 0x07) << 4);
166160
167161   for (offs = 0x5c; offs >= 0; offs -= 4)
168162   {
169      int x = tp84_spriteram[offs];
170      int y = 240 - tp84_spriteram[offs + 3];
163      int x = state->spriteram[offs];
164      int y = 240 - state->spriteram[offs + 3];
171165
172      int code = tp84_spriteram[offs + 1];
173      int color = palette_base | (tp84_spriteram[offs + 2] & 0x0f);
174      int flip_x = ~tp84_spriteram[offs + 2] & 0x40;
175      int flip_y =  tp84_spriteram[offs + 2] & 0x80;
166      int code = state->spriteram[offs + 1];
167      int color = palette_base | (state->spriteram[offs + 2] & 0x0f);
168      int flip_x = ~state->spriteram[offs + 2] & 0x40;
169      int flip_y =  state->spriteram[offs + 2] & 0x80;
176170
177171      drawgfx_transmask(bitmap, cliprect, machine->gfx[1], code, color, flip_x, flip_y, x, y,
178172            colortable_get_transpen_mask(machine->colortable, machine->gfx[1], color, palette_base));
r10427r10428
183177
184178VIDEO_UPDATE( tp84 )
185179{
180   tp84_state *state = screen->machine->driver_data<tp84_state>();
186181   rectangle clip = *cliprect;
187182   const rectangle &visarea = screen->visible_area();
188183
r10427r10428
190185   {
191186      tilemap_mark_all_tiles_dirty_all(screen->machine);
192187
193      tilemap_set_scrollx(bg_tilemap, 0, *tp84_scroll_x);
194      tilemap_set_scrolly(bg_tilemap, 0, *tp84_scroll_y);
188      tilemap_set_scrollx(state->bg_tilemap, 0, *state->scroll_x);
189      tilemap_set_scrolly(state->bg_tilemap, 0, *state->scroll_y);
195190
196      tilemap_set_flip_all(screen->machine, ((*tp84_flipscreen_x & 0x01) ? TILEMAP_FLIPX : 0) |
197                              ((*tp84_flipscreen_y & 0x01) ? TILEMAP_FLIPY : 0));
191      tilemap_set_flip_all(screen->machine, ((*state->flipscreen_x & 0x01) ? TILEMAP_FLIPX : 0) |
192                              ((*state->flipscreen_y & 0x01) ? TILEMAP_FLIPY : 0));
198193   }
199194
200   tilemap_draw(bitmap, cliprect, bg_tilemap, 0, 0);
195   tilemap_draw(bitmap, cliprect, state->bg_tilemap, 0, 0);
201196   draw_sprites(screen->machine, bitmap, cliprect);
202197
203198   /* draw top status region */
204199   clip.min_x = visarea.min_x;
205200   clip.max_x = visarea.min_x + 15;
206   tilemap_draw(bitmap, &clip, fg_tilemap, 0, 0);
201   tilemap_draw(bitmap, &clip, state->fg_tilemap, 0, 0);
207202
208203   /* draw bottom status region */
209204   clip.min_x = visarea.max_x - 15;
210205   clip.max_x = visarea.max_x;
211   tilemap_draw(bitmap, &clip, fg_tilemap, 0, 0);
206   tilemap_draw(bitmap, &clip, state->fg_tilemap, 0, 0);
212207
213208   return 0;
214209}
src/mame/video/segag80v.c
r10427r10428
1515#define IRQ_CLOCK         (U34_CLOCK/0x1f788)   /* 40Hz interrupt */
1616
1717
18UINT8 *segag80v_vectorram;
19size_t segag80v_vectorram_size;
20static int min_x, min_y;
2118
2219
2320/*
r10427r10428
7976*/
8077
8178
82INLINE int adjust_xy(int rawx, int rawy, int *outx, int *outy)
79INLINE int adjust_xy(segag80v_state *state, int rawx, int rawy, int *outx, int *outy)
8380{
8481   int clipped = FALSE;
8582
r10427r10428
104101      *outy &= 0x3ff;
105102
106103   /* convert into .16 values */
107   *outx = (*outx - (min_x - 512)) << 16;
108   *outy = (*outy - (min_y - 512)) << 16;
104   *outx = (*outx - (state->min_x - 512)) << 16;
105   *outy = (*outy - (state->min_y - 512)) << 16;
109106   return clipped;
110107}
111108
112109
113110static void sega_generate_vector_list(running_machine *machine)
114111{
112   segag80v_state *state = machine->driver_data<segag80v_state>();
115113   UINT8 *sintable = machine->region("proms")->base();
116114   double total_time = 1.0 / (double)IRQ_CLOCK;
117115   UINT16 symaddr = 0;
118   UINT8 *vectorram = segag80v_vectorram;
116   UINT8 *vectorram = state->vectorram;
119117
120118   vector_clear_list();
121119
r10427r10428
178176         int adjx, adjy, clipped;
179177
180178         /* Add a starting point to the vector list. */
181         clipped = adjust_xy(curx, cury, &adjx, &adjy);
179         clipped = adjust_xy(state, curx, cury, &adjx, &adjy);
182180         if (!clipped)
183181            vector_add_point(machine, adjx, adjy, 0, 0);
184182
r10427r10428
244242               intensity = 0;
245243
246244            /* Loop over the length of the vector. */
247            clipped = adjust_xy(curx, cury, &adjx, &adjy);
245            clipped = adjust_xy(state, curx, cury, &adjx, &adjy);
248246            xaccum = yaccum = 0;
249247            while (length-- != 0 && total_time > 0)
250248            {
r10427r10428
283281               /* Apply the clipping from the DAC circuit. If the values clip */
284282               /* the beam is turned off, but the computations continue right */
285283               /* on going. */
286               newclip = adjust_xy(curx, cury, &adjx, &adjy);
284               newclip = adjust_xy(state, curx, cury, &adjx, &adjy);
287285               if (newclip != clipped)
288286               {
289287                  /* if we're just becoming unclipped, add an empty point */
r10427r10428
327325
328326VIDEO_START( segag80v )
329327{
330   assert_always(segag80v_vectorram_size != 0, "segag80v_vectorram==0");
328   segag80v_state *state = machine->driver_data<segag80v_state>();
329   assert_always(state->vectorram_size != 0, "vectorram==0");
331330
332   min_x =machine->primary_screen->visible_area().min_x;
333   min_y =machine->primary_screen->visible_area().min_y;
331   state->min_x =machine->primary_screen->visible_area().min_x;
332   state->min_y =machine->primary_screen->visible_area().min_y;
334333
335334   VIDEO_START_CALL(vector);
336335}
src/mame/video/battlera.c
r10427r10428
1212#include "cpu/h6280/h6280.h"
1313#include "includes/battlera.h"
1414
15static int HuC6270_registers[20];
16static int VDC_register,vram_ptr;
17static UINT8 *HuC6270_vram,*vram_dirty;
18static bitmap_t *tile_bitmap,*front_bitmap;
19static UINT32 tile_dirtyseq;
2015
21static int current_scanline,inc_value;
22static int irq_enable,rcr_enable,sb_enable,bb_enable,bldwolf_vblank;
23
24static UINT8 blank_tile[32];
25
26
2716/******************************************************************************/
2817
2918VIDEO_START( battlera )
3019{
31   HuC6270_vram=auto_alloc_array(machine, UINT8, 0x20000);
32   vram_dirty=auto_alloc_array(machine, UINT8, 0x1000);
20   battlera_state *state = machine->driver_data<battlera_state>();
21   state->HuC6270_vram=auto_alloc_array(machine, UINT8, 0x20000);
22   state->vram_dirty=auto_alloc_array(machine, UINT8, 0x1000);
3323
34   memset(HuC6270_vram,0,0x20000);
35   memset(vram_dirty,1,0x1000);
24   memset(state->HuC6270_vram,0,0x20000);
25   memset(state->vram_dirty,1,0x1000);
3626
37   tile_bitmap=auto_bitmap_alloc(machine,512,512,machine->primary_screen->format());
38   front_bitmap=auto_bitmap_alloc(machine,512,512,machine->primary_screen->format());
27   state->tile_bitmap=auto_bitmap_alloc(machine,512,512,machine->primary_screen->format());
28   state->front_bitmap=auto_bitmap_alloc(machine,512,512,machine->primary_screen->format());
3929
40   vram_ptr=0;
41   inc_value=1;
42   current_scanline=0;
43   irq_enable=rcr_enable=sb_enable=bb_enable=0;
30   state->vram_ptr=0;
31   state->inc_value=1;
32   state->current_scanline=0;
33   state->irq_enable=state->rcr_enable=state->sb_enable=state->bb_enable=0;
4434
45   gfx_element_set_source(machine->gfx[0], HuC6270_vram);
46   gfx_element_set_source(machine->gfx[1], HuC6270_vram);
47   gfx_element_set_source(machine->gfx[2], blank_tile);
35   gfx_element_set_source(machine->gfx[0], state->HuC6270_vram);
36   gfx_element_set_source(machine->gfx[1], state->HuC6270_vram);
37   gfx_element_set_source(machine->gfx[2], state->blank_tile);
4838}
4939
5040/******************************************************************************/
r10427r10428
6454
6555READ8_HANDLER( HuC6270_debug_r )
6656{
67   return HuC6270_vram[offset];
57   battlera_state *state = space->machine->driver_data<battlera_state>();
58   return state->HuC6270_vram[offset];
6859}
6960
7061WRITE8_HANDLER( HuC6270_debug_w )
7162{
72   HuC6270_vram[offset]=data;
63   battlera_state *state = space->machine->driver_data<battlera_state>();
64   state->HuC6270_vram[offset]=data;
7365}
7466READ8_HANDLER( HuC6270_register_r )
7567{
68   battlera_state *state = space->machine->driver_data<battlera_state>();
7669   int rr;
7770
78   if ((current_scanline+56)==HuC6270_registers[6]) rr=1; else rr=0;
71   if ((state->current_scanline+56)==state->HuC6270_registers[6]) rr=1; else rr=0;
7972
8073   return 0      /* CR flag */
8174      | (0 << 1)   /* OR flag */
8275      | (rr << 2)   /* RR flag */
8376      | (0 << 3)   /* DS flag */
8477      | (0 << 4)   /* DV flag */
85      | (bldwolf_vblank << 5)   /* VD flag (1 when vblank else 0) */
78      | (state->bldwolf_vblank << 5)   /* VD flag (1 when vblank else 0) */
8679      | (0 << 6)   /* BSY flag (1 when dma active, else 0) */
8780      | (0 << 7);   /* Always zero */
8881}
8982
9083WRITE8_HANDLER( HuC6270_register_w )
9184{
85   battlera_state *state = space->machine->driver_data<battlera_state>();
9286   switch (offset) {
9387   case 0: /* Select data region */
94      VDC_register=data;
88      state->VDC_register=data;
9589      break;
9690   case 1: /* Unused */
9791      break;
r10427r10428
10397#ifdef UNUSED_FUNCTION
10498READ8_HANDLER( HuC6270_data_r )
10599{
100   battlera_state *state = space->machine->driver_data<battlera_state>();
106101   int result;
107102
108103   switch (offset) {
109104      case 0: /* LSB */
110         return HuC6270_vram[(HuC6270_registers[1]<<1)|1];
105         return state->HuC6270_vram[(state->HuC6270_registers[1]<<1)|1];
111106
112107      case 1:/* MSB */
113         result=HuC6270_vram[(HuC6270_registers[1]<<1)|0];
114         HuC6270_registers[1]=(HuC6270_registers[1]+inc_value)&0xffff;
108         result=state->HuC6270_vram[(state->HuC6270_registers[1]<<1)|0];
109         state->HuC6270_registers[1]=(state->HuC6270_registers[1]+state->inc_value)&0xffff;
115110         return result;
116111   }
117112
r10427r10428
121116
122117WRITE8_HANDLER( HuC6270_data_w )
123118{
119   battlera_state *state = space->machine->driver_data<battlera_state>();
124120   switch (offset) {
125121      case 0: /* LSB */
126         switch (VDC_register) {
122         switch (state->VDC_register) {
127123
128124         case 0: /* MAWR */
129            HuC6270_registers[0]=(HuC6270_registers[0]&0xff00) | (data);
125            state->HuC6270_registers[0]=(state->HuC6270_registers[0]&0xff00) | (data);
130126            return;
131127
132128         case 1: /* MARR */
133            HuC6270_registers[0]=(HuC6270_registers[1]&0xff00) | (data);
129            state->HuC6270_registers[0]=(state->HuC6270_registers[1]&0xff00) | (data);
134130            return;
135131
136132         case 2: /* VRAM */
137            if (HuC6270_vram[(HuC6270_registers[0]<<1)|1]!=data) {
138               HuC6270_vram[(HuC6270_registers[0]<<1)|1]=data;
139               gfx_element_mark_dirty(space->machine->gfx[0], HuC6270_registers[0]>>4);
140               gfx_element_mark_dirty(space->machine->gfx[1], HuC6270_registers[0]>>6);
133            if (state->HuC6270_vram[(state->HuC6270_registers[0]<<1)|1]!=data) {
134               state->HuC6270_vram[(state->HuC6270_registers[0]<<1)|1]=data;
135               gfx_element_mark_dirty(space->machine->gfx[0], state->HuC6270_registers[0]>>4);
136               gfx_element_mark_dirty(space->machine->gfx[1], state->HuC6270_registers[0]>>6);
141137            }
142            if (HuC6270_registers[0]<0x1000) vram_dirty[HuC6270_registers[0]]=1;
138            if (state->HuC6270_registers[0]<0x1000) state->vram_dirty[state->HuC6270_registers[0]]=1;
143139            return;
144140
145141         case 3: break; /* Unused */
r10427r10428
147143
148144         case 5: /* CR - Control register */
149145            /* Bits 0,1 unknown */
150            rcr_enable=data&0x4; /* Raster interrupt enable */
151            irq_enable=data&0x8; /* VBL interrupt enable */
146            state->rcr_enable=data&0x4; /* Raster interrupt enable */
147            state->irq_enable=data&0x8; /* VBL interrupt enable */
152148            /* Bits 4,5 unknown (EX) */
153            sb_enable=data&0x40; /* Sprites enable */
154            bb_enable=data&0x80; /* Background enable */
149            state->sb_enable=data&0x40; /* Sprites enable */
150            state->bb_enable=data&0x80; /* Background enable */
155151            return;
156152
157153         case 6: /* RCR - Raster counter register */
158            HuC6270_registers[6]=(HuC6270_registers[6]&0xff00) | (data);
154            state->HuC6270_registers[6]=(state->HuC6270_registers[6]&0xff00) | (data);
159155            return;
160156
161157         case 7: /* BXR - X scroll */
162            HuC6270_registers[7]=(HuC6270_registers[7]&0xff00) | (data);
158            state->HuC6270_registers[7]=(state->HuC6270_registers[7]&0xff00) | (data);
163159            return;
164160
165161         case 8: /* BYR - Y scroll */
166            HuC6270_registers[8]=(HuC6270_registers[8]&0xff00) | (data);
162            state->HuC6270_registers[8]=(state->HuC6270_registers[8]&0xff00) | (data);
167163            return;
168164
169165         case 15: /* DMA */
r10427r10428
174170            break;
175171
176172         case 19: /* SATB */
177            HuC6270_registers[19]=(HuC6270_registers[19]&0xff00) | (data);
173            state->HuC6270_registers[19]=(state->HuC6270_registers[19]&0xff00) | (data);
178174            return;
179175
180176         }
r10427r10428
183179      /*********************************************/
184180
185181      case 1: /* MSB (Autoincrement on this write) */
186         switch (VDC_register) {
182         switch (state->VDC_register) {
187183
188184         case 0: /* MAWR - Memory Address Write Register */
189            HuC6270_registers[0]=(HuC6270_registers[0]&0xff) | (data<<8);
185            state->HuC6270_registers[0]=(state->HuC6270_registers[0]&0xff) | (data<<8);
190186            return;
191187
192188         case 1: /* MARR */
193            HuC6270_registers[1]=(HuC6270_registers[1]&0xff) | (data<<8);
189            state->HuC6270_registers[1]=(state->HuC6270_registers[1]&0xff) | (data<<8);
194190            return;
195191
196192         case 2: /* VWR - VRAM */
197            if (HuC6270_vram[(HuC6270_registers[0]<<1)|0]!=data) {
198               HuC6270_vram[(HuC6270_registers[0]<<1)|0]=data;
199               gfx_element_mark_dirty(space->machine->gfx[0], HuC6270_registers[0]>>4);
200               gfx_element_mark_dirty(space->machine->gfx[1], HuC6270_registers[0]>>6);
201               if (HuC6270_registers[0]<0x1000) vram_dirty[HuC6270_registers[0]]=1;
193            if (state->HuC6270_vram[(state->HuC6270_registers[0]<<1)|0]!=data) {
194               state->HuC6270_vram[(state->HuC6270_registers[0]<<1)|0]=data;
195               gfx_element_mark_dirty(space->machine->gfx[0], state->HuC6270_registers[0]>>4);
196               gfx_element_mark_dirty(space->machine->gfx[1], state->HuC6270_registers[0]>>6);
197               if (state->HuC6270_registers[0]<0x1000) state->vram_dirty[state->HuC6270_registers[0]]=1;
202198            }
203            HuC6270_registers[0]+=inc_value;
204            HuC6270_registers[0]=HuC6270_registers[0]&0xffff;
199            state->HuC6270_registers[0]+=state->inc_value;
200            state->HuC6270_registers[0]=state->HuC6270_registers[0]&0xffff;
205201            return;
206202
207203         case 5: /* CR */
208204            /* IW - Auto-increment values */
209205            switch ((data>>3)&3) {
210               case 0: inc_value=1; break;
211               case 1: inc_value=32;break;
212               case 2: inc_value=64; break;
213               case 3: inc_value=128; break;
206               case 0: state->inc_value=1; break;
207               case 1: state->inc_value=32;break;
208               case 2: state->inc_value=64; break;
209               case 3: state->inc_value=128; break;
214210            }
215211
216212            /* DR, TE unknown */
217213            return;
218214
219215         case 6: /* RCR - Raster counter register */
220            HuC6270_registers[6]=(HuC6270_registers[6]&0xff) | (data<<8);
216            state->HuC6270_registers[6]=(state->HuC6270_registers[6]&0xff) | (data<<8);
221217            return;
222218
223219         case 7: /* BXR - X scroll */
224            HuC6270_registers[7]=(HuC6270_registers[7]&0xff) | (data<<8);
220            state->HuC6270_registers[7]=(state->HuC6270_registers[7]&0xff) | (data<<8);
225221                  return;
226222
227223         case 8: /* BYR - Y scroll */
228            HuC6270_registers[8]=(HuC6270_registers[8]&0xff) | (data<<8);
224            state->HuC6270_registers[8]=(state->HuC6270_registers[8]&0xff) | (data<<8);
229225            return;
230226
231227         case 15: /* DMA */
r10427r10428
236232            break;
237233
238234         case 19: /* SATB - Sprites */
239            HuC6270_registers[19]=(HuC6270_registers[19]&0xff) | (data<<8);
235            state->HuC6270_registers[19]=(state->HuC6270_registers[19]&0xff) | (data<<8);
240236            return;
241237         }
242238         break;
243239   }
244   logerror("%04x: unknown write to  VDC_register %02x (%02x) at %02x\n",cpu_get_pc(space->cpu),VDC_register,data,offset);
240   logerror("%04x: unknown write to  state->VDC_register %02x (%02x) at %02x\n",cpu_get_pc(space->cpu),state->VDC_register,data,offset);
245241}
246242
247243/******************************************************************************/
248244
249245static void draw_sprites(running_machine *machine, bitmap_t *bitmap,const rectangle *clip,int pri)
250246{
247   battlera_state *state = machine->driver_data<battlera_state>();
251248   int offs,my,mx,code,code2,fx,fy,cgy=0,cgx,colour,i,yinc;
252249
253250   /* Draw sprites, starting at SATB, draw in _reverse_ order */
254   for (offs=(HuC6270_registers[19]<<1)+0x200-8; offs>=(HuC6270_registers[19]<<1); offs-=8)
251   for (offs=(state->HuC6270_registers[19]<<1)+0x200-8; offs>=(state->HuC6270_registers[19]<<1); offs-=8)
255252   {
256      if ((HuC6270_vram[offs+7]&0x80) && !pri) continue;
257      if (!(HuC6270_vram[offs+7]&0x80) && pri) continue;
253      if ((state->HuC6270_vram[offs+7]&0x80) && !pri) continue;
254      if (!(state->HuC6270_vram[offs+7]&0x80) && pri) continue;
258255
259      code=HuC6270_vram[offs+5] + (HuC6270_vram[offs+4]<<8);
256      code=state->HuC6270_vram[offs+5] + (state->HuC6270_vram[offs+4]<<8);
260257      code=code>>1;
261258
262      my=HuC6270_vram[offs+1] + (HuC6270_vram[offs+0]<<8);
263      mx=HuC6270_vram[offs+3] + (HuC6270_vram[offs+2]<<8);
259      my=state->HuC6270_vram[offs+1] + (state->HuC6270_vram[offs+0]<<8);
260      mx=state->HuC6270_vram[offs+3] + (state->HuC6270_vram[offs+2]<<8);
264261
265262      mx-=32;
266263      my-=57;
267264
268      fx=HuC6270_vram[offs+6]&0x8;
269      fy=HuC6270_vram[offs+6]&0x80;
270      cgx=HuC6270_vram[offs+6]&1;
271      colour=HuC6270_vram[offs+7]&0xf;
265      fx=state->HuC6270_vram[offs+6]&0x8;
266      fy=state->HuC6270_vram[offs+6]&0x80;
267      cgx=state->HuC6270_vram[offs+6]&1;
268      colour=state->HuC6270_vram[offs+7]&0xf;
272269
273      switch ((HuC6270_vram[offs+6]>>4)&3) {
270      switch ((state->HuC6270_vram[offs+6]>>4)&3) {
274271      case 0: cgy=1; break;
275272      case 1: cgy=2; break;
276273      case 2: cgy=0; break; /* Illegal */
r10427r10428
312309
313310VIDEO_UPDATE( battlera )
314311{
312   battlera_state *state = screen->machine->driver_data<battlera_state>();
315313   int offs,code,scrollx,scrolly,mx,my;
316314
317315   /* if any tiles changed, redraw the VRAM */
318   if (screen->machine->gfx[0]->dirtyseq != tile_dirtyseq)
316   if (screen->machine->gfx[0]->dirtyseq != state->tile_dirtyseq)
319317   {
320      tile_dirtyseq = screen->machine->gfx[0]->dirtyseq;
321      memset(vram_dirty, 1, 0x1000);
318      state->tile_dirtyseq = screen->machine->gfx[0]->dirtyseq;
319      memset(state->vram_dirty, 1, 0x1000);
322320   }
323321
324322   mx=-1;
r10427r10428
327325   {
328326      mx++;
329327      if (mx==64) {mx=0; my++;}
330      code=HuC6270_vram[offs+1] + ((HuC6270_vram[offs] & 0x0f) << 8);
328      code=state->HuC6270_vram[offs+1] + ((state->HuC6270_vram[offs] & 0x0f) << 8);
331329
332330      /* If this tile was changed OR tilemap was changed, redraw */
333      if (vram_dirty[offs/2]) {
334         vram_dirty[offs/2]=0;
335         drawgfx_opaque(tile_bitmap,0,screen->machine->gfx[0],
331      if (state->vram_dirty[offs/2]) {
332         state->vram_dirty[offs/2]=0;
333         drawgfx_opaque(state->tile_bitmap,0,screen->machine->gfx[0],
336334               code,
337               HuC6270_vram[offs] >> 4,
335               state->HuC6270_vram[offs] >> 4,
338336               0,0,
339337               8*mx,8*my);
340         drawgfx_opaque(front_bitmap,0,screen->machine->gfx[2],
338         drawgfx_opaque(state->front_bitmap,0,screen->machine->gfx[2],
341339               0,
342340               0,   /* fill the spot with pen 256 */
343341               0,0,
344342               8*mx,8*my);
345         drawgfx_transmask(front_bitmap,0,screen->machine->gfx[0],
343         drawgfx_transmask(state->front_bitmap,0,screen->machine->gfx[0],
346344               code,
347               HuC6270_vram[offs] >> 4,
345               state->HuC6270_vram[offs] >> 4,
348346               0,0,
349347               8*mx,8*my,0x1);
350348      }
351349   }
352350
353351   /* Render bitmap */
354   scrollx=-HuC6270_registers[7];
355   scrolly=-HuC6270_registers[8]+cliprect->min_y-1;
352   scrollx=-state->HuC6270_registers[7];
353   scrolly=-state->HuC6270_registers[8]+cliprect->min_y-1;
356354
357   copyscrollbitmap(bitmap,tile_bitmap,1,&scrollx,1,&scrolly,cliprect);
355   copyscrollbitmap(bitmap,state->tile_bitmap,1,&scrollx,1,&scrolly,cliprect);
358356
359357   /* Todo:  Background enable (not used anyway) */
360358
361359   /* Render low priority sprites, if enabled */
362   if (sb_enable) draw_sprites(screen->machine,bitmap,cliprect,0);
360   if (state->sb_enable) draw_sprites(screen->machine,bitmap,cliprect,0);
363361
364362   /* Render background over sprites */
365   copyscrollbitmap_trans(bitmap,front_bitmap,1,&scrollx,1,&scrolly,cliprect,256);
363   copyscrollbitmap_trans(bitmap,state->front_bitmap,1,&scrollx,1,&scrolly,cliprect,256);
366364
367365   /* Render high priority sprites, if enabled */
368   if (sb_enable) draw_sprites(screen->machine,bitmap,cliprect,1);
366   if (state->sb_enable) draw_sprites(screen->machine,bitmap,cliprect,1);
369367
370368   return 0;
371369}
r10427r10428
374372
375373INTERRUPT_GEN( battlera_interrupt )
376374{
377   current_scanline=255-cpu_getiloops(device); /* 8 lines clipped at top */
375   battlera_state *state = device->machine->driver_data<battlera_state>();
376   state->current_scanline=255-cpu_getiloops(device); /* 8 lines clipped at top */
378377
379378   /* If raster interrupt occurs, refresh screen _up_ to this point */
380   if (rcr_enable && (current_scanline+56)==HuC6270_registers[6]) {
381      device->machine->primary_screen->update_partial(current_scanline);
379   if (state->rcr_enable && (state->current_scanline+56)==state->HuC6270_registers[6]) {
380      device->machine->primary_screen->update_partial(state->current_scanline);
382381      cpu_set_input_line(device, 0, HOLD_LINE); /* RCR interrupt */
383382   }
384383
385384   /* Start of vblank */
386   else if (current_scanline==240) {
387      bldwolf_vblank=1;
385   else if (state->current_scanline==240) {
386      state->bldwolf_vblank=1;
388387      device->machine->primary_screen->update_partial(240);
389      if (irq_enable)
388      if (state->irq_enable)
390389         cpu_set_input_line(device, 0, HOLD_LINE); /* VBL */
391390   }
392391
393392   /* End of vblank */
394   if (current_scanline==254) {
395      bldwolf_vblank=0;
393   if (state->current_scanline==254) {
394      state->bldwolf_vblank=0;
396395   }
397396}
src/mame/video/model2rd.c
r10427r10428
5858{
5959#if !defined( MODEL2_TRANSLUCENT)
6060   const poly_extra_data *extra = (const poly_extra_data *)extradata;
61   model2_state *state = extra->state;
6162   bitmap_t *destmap = (bitmap_t *)dest;
6263   UINT32 *p = BITMAP_ADDR32(destmap, scanline, 0);
6364
6465   /* extract color information */
65   const UINT16 *colortable_r = (const UINT16 *)&model2_colorxlat[0x0000/4];
66   const UINT16 *colortable_g = (const UINT16 *)&model2_colorxlat[0x4000/4];
67   const UINT16 *colortable_b = (const UINT16 *)&model2_colorxlat[0x8000/4];
68   const UINT16 *lumaram = (const UINT16 *)model2_lumaram;
69   const UINT16 *palram = (const UINT16 *)model2_paletteram32;
66   const UINT16 *colortable_r = (const UINT16 *)&state->colorxlat[0x0000/4];
67   const UINT16 *colortable_g = (const UINT16 *)&state->colorxlat[0x4000/4];
68   const UINT16 *colortable_b = (const UINT16 *)&state->colorxlat[0x8000/4];
69   const UINT16 *lumaram = (const UINT16 *)state->lumaram;
70   const UINT16 *palram = (const UINT16 *)state->paletteram32;
7071   UINT32   lumabase = extra->lumabase;
7172   UINT32   color = extra->colorbase;
7273   UINT8   luma;
r10427r10428
110111static void MODEL2_FUNC_NAME(void *dest, INT32 scanline, const poly_extent *extent, const void *extradata, int threadid)
111112{
112113   const poly_extra_data *extra = (const poly_extra_data *)extradata;
114   model2_state *state = extra->state;
113115   bitmap_t *destmap = (bitmap_t *)dest;
114116   UINT32 *p = BITMAP_ADDR32(destmap, scanline, 0);
115117
r10427r10428
117119   UINT32   tex_height = extra->texheight;
118120
119121   /* extract color information */
120   const UINT16 *colortable_r = (const UINT16 *)&model2_colorxlat[0x0000/4];
121   const UINT16 *colortable_g = (const UINT16 *)&model2_colorxlat[0x4000/4];
122   const UINT16 *colortable_b = (const UINT16 *)&model2_colorxlat[0x8000/4];
123   const UINT16 *lumaram = (const UINT16 *)model2_lumaram;
124   const UINT16 *palram = (const UINT16 *)model2_paletteram32;
122   const UINT16 *colortable_r = (const UINT16 *)&state->colorxlat[0x0000/4];
123   const UINT16 *colortable_g = (const UINT16 *)&state->colorxlat[0x4000/4];
124   const UINT16 *colortable_b = (const UINT16 *)&state->colorxlat[0x8000/4];
125   const UINT16 *lumaram = (const UINT16 *)state->lumaram;
126   const UINT16 *palram = (const UINT16 *)state->paletteram32;
125127   UINT32   colorbase = extra->colorbase;
126128   UINT32   lumabase = extra->lumabase;
127129   UINT32   tex_x = extra->texx;
src/mame/video/konamiic.c
r10427r10428
37213721static UINT16 K053247_regs[16];
37223722static UINT16 *K053247_ram=0;
37233723static gfx_element *K053247_gfx;
3724static void (*K053247_callback)(int *code,int *color,int *priority);
3724static void (*K053247_callback)(running_machine *machine, int *code,int *color,int *priority);
37253725static UINT8 K053246_OBJCHA_line;
37263726
3727void K053247_export_config(UINT16 **ram, gfx_element **gfx, void (**callback)(int *, int *, int *), int *dx, int *dy)
3727void K053247_export_config(UINT16 **ram, gfx_element **gfx, void (**callback)(running_machine *, int *, int *, int *), int *dx, int *dy)
37283728{
37293729   if(ram)
37303730      *ram = K053247_ram;
r10427r10428
38413841#endif
38423842
38433843/* K055673 used with the 54246 in PreGX/Run and Gun/System GX games */
3844void K055673_vh_start(running_machine *machine, const char *gfx_memory_region, int layout, int dx, int dy, void (*callback)(int *code,int *color,int *priority))
3844void K055673_vh_start(running_machine *machine, const char *gfx_memory_region, int layout, int dx, int dy, void (*callback)(running_machine *machine, int *code,int *color,int *priority))
38453845{
38463846   int gfx_index;
38473847   UINT32 total;
r10427r10428
55425542}
55435543#endif
55445544
5545static void (*K056832_callback)(int layer, int *code, int *color, int *flags);
5545static void (*K056832_callback)(running_machine *machine, int layer, int *code, int *color, int *flags);
55465546
55475547INLINE void K056832_get_tile_info( running_machine *machine, tile_data *tileinfo, int tile_index, int pageIndex )
55485548{
r10427r10428
55795579   color = (attr & smptr->palm1) | (attr>>smptr->pals2 & smptr->palm2);
55805580   flags = TILE_FLIPYX(flip);
55815581
5582   (*K056832_callback)(layer, &code, &color, &flags);
5582   (*K056832_callback)(machine, layer, &code, &color, &flags);
55835583
55845584   SET_TILE_INFO(K056832_gfxnum,
55855585         code,
r10427r10428
56785678
56795679void K056832_vh_start(running_machine *machine, const char *gfx_memory_region, int bpp, int big,
56805680   int (*scrolld)[4][2],
5681   void (*callback)(int layer, int *code, int *color, int *flags),
5681   void (*callback)(running_machine *machine, int layer, int *code, int *color, int *flags),
56825682   int djmain_hack)
56835683{
56845684   tilemap_t *tmap;
src/mame/video/konamiic.h
r10427r10428
144144#define K055673_LAYOUT_GX6 3
145145
146146void K055673_vh_start(running_machine *machine, const char *gfx_memory_region, int alt_layout, int dx, int dy,
147      void (*callback)(int *code,int *color,int *priority));
147      void (*callback)(running_machine *machine, int *code,int *color,int *priority));
148148READ16_HANDLER( K055673_rom_word_r );
149149READ16_HANDLER( K055673_GX6bpp_rom_word_r );
150150
r10427r10428
179179void K053247_wraparound_enable(int status);
180180void K05324x_set_z_rejection(int zcode); // common to K053245/6/7
181181#endif
182void K053247_export_config(UINT16 **ram, gfx_element **gfx, void (**callback)(int *, int *, int *), int *dx, int *dy);
182void K053247_export_config(UINT16 **ram, gfx_element **gfx, void (**callback)(running_machine *, int *, int *, int *), int *dx, int *dy);
183183
184184#ifdef UNUSED_FUNCTION
185185READ8_HANDLER( K053246_r );
r10427r10428
280280
281281void K056832_vh_start(running_machine *machine, const char *gfx_memory_region, int bpp, int big,
282282         int (*scrolld)[4][2],
283         void (*callback)(int layer, int *code, int *color, int *flags),
283         void (*callback)(running_machine *machine, int layer, int *code, int *color, int *flags),
284284         int djmain_hack);
285285READ16_HANDLER( K056832_ram_word_r );
286286WRITE16_HANDLER( K056832_ram_word_w );
src/mame/video/madalien.c
r10427r10428
1414#define PIXEL_CLOCK (MADALIEN_MAIN_CLOCK / 2)
1515
1616
17UINT8 *madalien_videoram;
18UINT8 *madalien_charram;
19
20UINT8 *madalien_video_flags;
21UINT8 *madalien_video_control;   /* bit #0 is set during player 2's turn, bit #3 is set during CRTC initialization */
22UINT8 *madalien_scroll;
23UINT8 *madalien_edge1_pos;
24UINT8 *madalien_edge2_pos;
25UINT8 *madalien_headlight_pos;
26
27static tilemap_t *tilemap_fg;
28
29static tilemap_t *tilemap_edge1[4];
30static tilemap_t *tilemap_edge2[4];
31
32static bitmap_t *headlight_bitmap;
33
34
3517static PALETTE_INIT( madalien )
3618{
3719   int i;
r10427r10428
10890
10991static TILE_GET_INFO( get_tile_info_BG_1 )
11092{
111   UINT8 *map = machine->region("user1")->base() + ((*madalien_video_flags & 0x08) << 6);
93   madalien_state *state = machine->driver_data<madalien_state>();
94   UINT8 *map = machine->region("user1")->base() + ((*state->video_flags & 0x08) << 6);
11295
113   SET_TILE_INFO(1, map[tile_index], BIT(*madalien_video_flags, 2) ? 2 : 0, 0);
96   SET_TILE_INFO(1, map[tile_index], BIT(*state->video_flags, 2) ? 2 : 0, 0);
11497}
11598
11699
117100static TILE_GET_INFO( get_tile_info_BG_2 )
118101{
119   UINT8 *map = machine->region("user1")->base() + ((*madalien_video_flags & 0x08) << 6) + 0x80;
102   madalien_state *state = machine->driver_data<madalien_state>();
103   UINT8 *map = machine->region("user1")->base() + ((*state->video_flags & 0x08) << 6) + 0x80;
120104
121   SET_TILE_INFO(1, map[tile_index], BIT(*madalien_video_flags, 2) ? 2 : 0, 0);
105   SET_TILE_INFO(1, map[tile_index], BIT(*state->video_flags, 2) ? 2 : 0, 0);
122106}
123107
124108
125109static TILE_GET_INFO( get_tile_info_FG )
126110{
127   SET_TILE_INFO(0, madalien_videoram[tile_index], 0, 0);
111   madalien_state *state = machine->driver_data<madalien_state>();
112   SET_TILE_INFO(0, state->videoram[tile_index], 0, 0);
128113}
129114
130115WRITE8_HANDLER( madalien_videoram_w )
131116{
132   madalien_videoram[offset] = data;
133   tilemap_mark_tile_dirty(tilemap_fg, offset);
117   madalien_state *state = space->machine->driver_data<madalien_state>();
118   state->videoram[offset] = data;
119   tilemap_mark_tile_dirty(state->tilemap_fg, offset);
134120}
135121
136122
137123static VIDEO_START( madalien )
138124{
125   madalien_state *state = machine->driver_data<madalien_state>();
139126   int i;
140127
141128   static const tilemap_mapper_func scan_functions[4] =
r10427r10428
148135      16, 16, 32, 32
149136   };
150137
151   tilemap_fg = tilemap_create(machine, get_tile_info_FG, tilemap_scan_cols_flip_x, 8, 8, 32, 32);
152   tilemap_set_transparent_pen(tilemap_fg, 0);
153   tilemap_set_scrolldx(tilemap_fg, 0, 0x50);
154   tilemap_set_scrolldy(tilemap_fg, 0, 0x20);
138   state->tilemap_fg = tilemap_create(machine, get_tile_info_FG, tilemap_scan_cols_flip_x, 8, 8, 32, 32);
139   tilemap_set_transparent_pen(state->tilemap_fg, 0);
140   tilemap_set_scrolldx(state->tilemap_fg, 0, 0x50);
141   tilemap_set_scrolldy(state->tilemap_fg, 0, 0x20);
155142
156143   for (i = 0; i < 4; i++)
157144   {
158      tilemap_edge1[i] = tilemap_create(machine, get_tile_info_BG_1, scan_functions[i], 16, 16, tilemap_cols[i], 8);
159      tilemap_set_scrolldx(tilemap_edge1[i], 0, 0x50);
160      tilemap_set_scrolldy(tilemap_edge1[i], 0, 0x20);
145      state->tilemap_edge1[i] = tilemap_create(machine, get_tile_info_BG_1, scan_functions[i], 16, 16, tilemap_cols[i], 8);
146      tilemap_set_scrolldx(state->tilemap_edge1[i], 0, 0x50);
147      tilemap_set_scrolldy(state->tilemap_edge1[i], 0, 0x20);
161148
162      tilemap_edge2[i] = tilemap_create(machine, get_tile_info_BG_2, scan_functions[i], 16, 16, tilemap_cols[i], 8);
163      tilemap_set_scrolldx(tilemap_edge2[i], 0, 0x50);
164      tilemap_set_scrolldy(tilemap_edge2[i], 0, machine->primary_screen->height() - 256);
149      state->tilemap_edge2[i] = tilemap_create(machine, get_tile_info_BG_2, scan_functions[i], 16, 16, tilemap_cols[i], 8);
150      tilemap_set_scrolldx(state->tilemap_edge2[i], 0, 0x50);
151      tilemap_set_scrolldy(state->tilemap_edge2[i], 0, machine->primary_screen->height() - 256);
165152   }
166153
167   headlight_bitmap = auto_bitmap_alloc(machine, 128, 128, BITMAP_FORMAT_INDEXED16);
154   state->headlight_bitmap = auto_bitmap_alloc(machine, 128, 128, BITMAP_FORMAT_INDEXED16);
168155
169   gfx_element_set_source(machine->gfx[0], madalien_charram);
156   gfx_element_set_source(machine->gfx[0], state->charram);
170157
171   drawgfx_opaque(headlight_bitmap, NULL, machine->gfx[2], 0, 0, 0, 0, 0x00, 0x00);
172   drawgfx_opaque(headlight_bitmap, NULL, machine->gfx[2], 0, 0, 0, 1, 0x00, 0x40);
158   drawgfx_opaque(state->headlight_bitmap, NULL, machine->gfx[2], 0, 0, 0, 0, 0x00, 0x00);
159   drawgfx_opaque(state->headlight_bitmap, NULL, machine->gfx[2], 0, 0, 0, 1, 0x00, 0x40);
173160}
174161
175162
176static void draw_edges(bitmap_t *bitmap, const rectangle *cliprect, int flip, int scroll_mode)
163static void draw_edges(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int flip, int scroll_mode)
177164{
165   madalien_state *state = machine->driver_data<madalien_state>();
178166   rectangle clip_edge1;
179167   rectangle clip_edge2;
180168
r10427r10428
183171
184172   if (flip)
185173   {
186      clip_edge1.min_y = *madalien_edge1_pos | 0x80;
187      clip_edge2.max_y = (*madalien_edge2_pos & 0x7f) ^ 0x7f;
174      clip_edge1.min_y = *state->edge1_pos | 0x80;
175      clip_edge2.max_y = (*state->edge2_pos & 0x7f) ^ 0x7f;
188176   }
189177   else
190178   {
191      clip_edge1.max_y = (*madalien_edge1_pos & 0x7f) ^ 0x7f;
192      clip_edge2.min_y = *madalien_edge2_pos | 0x80;
179      clip_edge1.max_y = (*state->edge1_pos & 0x7f) ^ 0x7f;
180      clip_edge2.min_y = *state->edge2_pos | 0x80;
193181   }
194182
195183   sect_rect(&clip_edge1, cliprect);
196184   sect_rect(&clip_edge2, cliprect);
197185
198   tilemap_mark_all_tiles_dirty(tilemap_edge1[scroll_mode]);
199   tilemap_mark_all_tiles_dirty(tilemap_edge2[scroll_mode]);
186   tilemap_mark_all_tiles_dirty(state->tilemap_edge1[scroll_mode]);
187   tilemap_mark_all_tiles_dirty(state->tilemap_edge2[scroll_mode]);
200188
201   tilemap_set_flip(tilemap_edge1[scroll_mode], flip ? TILEMAP_FLIPX | TILEMAP_FLIPY : 0);
202   tilemap_set_scrollx(tilemap_edge1[scroll_mode], 0, -(*madalien_scroll & 0xfc));
203   tilemap_set_scrolly(tilemap_edge1[scroll_mode], 0, *madalien_edge1_pos & 0x7f);
189   tilemap_set_flip(state->tilemap_edge1[scroll_mode], flip ? TILEMAP_FLIPX | TILEMAP_FLIPY : 0);
190   tilemap_set_scrollx(state->tilemap_edge1[scroll_mode], 0, -(*state->scroll & 0xfc));
191   tilemap_set_scrolly(state->tilemap_edge1[scroll_mode], 0, *state->edge1_pos & 0x7f);
204192
205   tilemap_set_flip(tilemap_edge2[scroll_mode], flip ? TILEMAP_FLIPX : TILEMAP_FLIPY);
206   tilemap_set_scrollx(tilemap_edge2[scroll_mode], 0, -(*madalien_scroll & 0xfc));
207   tilemap_set_scrolly(tilemap_edge2[scroll_mode], 0, *madalien_edge2_pos & 0x7f);
193   tilemap_set_flip(state->tilemap_edge2[scroll_mode], flip ? TILEMAP_FLIPX : TILEMAP_FLIPY);
194   tilemap_set_scrollx(state->tilemap_edge2[scroll_mode], 0, -(*state->scroll & 0xfc));
195   tilemap_set_scrolly(state->tilemap_edge2[scroll_mode], 0, *state->edge2_pos & 0x7f);
208196
209   tilemap_draw(bitmap, &clip_edge1, tilemap_edge1[scroll_mode], 0, 0);
210   tilemap_draw(bitmap, &clip_edge2, tilemap_edge2[scroll_mode], 0, 0);
197   tilemap_draw(bitmap, &clip_edge1, state->tilemap_edge1[scroll_mode], 0, 0);
198   tilemap_draw(bitmap, &clip_edge2, state->tilemap_edge2[scroll_mode], 0, 0);
211199}
212200
213201
214static void draw_headlight(bitmap_t *bitmap, const rectangle *cliprect, int flip)
202static void draw_headlight(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int flip)
215203{
216   if (BIT(*madalien_video_flags, 0))
204   madalien_state *state = machine->driver_data<madalien_state>();
205   if (BIT(*state->video_flags, 0))
217206   {
218207      UINT8 y;
219208
220209      for (y = 0; y < 0x80; y++)
221210      {
222211         UINT8 x;
223         UINT8 hy = y - *madalien_headlight_pos;
212         UINT8 hy = y - *state->headlight_pos;
224213
225214         if (flip)
226215            hy = ~hy;
r10427r10428
238227            if ((hx < cliprect->min_x) || (hx > cliprect->max_x))
239228               continue;
240229
241            if (*BITMAP_ADDR16(headlight_bitmap, y, x) != 0)
230            if (*BITMAP_ADDR16(state->headlight_bitmap, y, x) != 0)
242231               *BITMAP_ADDR16(bitmap, hy, hx) |= 8;
243232         }
244233      }
r10427r10428
248237
249238static void draw_foreground(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int flip)
250239{
251   tilemap_set_flip(tilemap_fg, flip ? TILEMAP_FLIPX | TILEMAP_FLIPY : 0);
252   tilemap_draw(bitmap, cliprect, tilemap_fg, 0, 0);
240   madalien_state *state = machine->driver_data<madalien_state>();
241   tilemap_set_flip(state->tilemap_fg, flip ? TILEMAP_FLIPX | TILEMAP_FLIPY : 0);
242   tilemap_draw(bitmap, cliprect, state->tilemap_fg, 0, 0);
253243}
254244
255245
256246WRITE8_HANDLER( madalien_charram_w )
257247{
258   madalien_charram[offset] = data;
248   madalien_state *state = space->machine->driver_data<madalien_state>();
249   state->charram[offset] = data;
259250   gfx_element_mark_dirty(space->machine->gfx[0], (offset/8) & 0xff);
260251}
261252
262253
263254static VIDEO_UPDATE( madalien )
264255{
265   int flip = BIT(input_port_read(screen->machine, "DSW"), 6) && BIT(*madalien_video_control, 0);
256   madalien_state *state = screen->machine->driver_data<madalien_state>();
257   int flip = BIT(input_port_read(screen->machine, "DSW"), 6) && BIT(*state->video_control, 0);
266258
267259   // bits #0 and #1 define scrolling mode
268260   //
r10427r10428
271263   //
272264   // mode 2 - transition from B to A
273265   // mode 3 - transition from A to B
274   int scroll_mode = *madalien_scroll & 3;
266   int scroll_mode = *state->scroll & 3;
275267
276268   bitmap_fill(bitmap, cliprect, 0);
277   draw_edges(bitmap, cliprect, flip, scroll_mode);
269   draw_edges(screen->machine, bitmap, cliprect, flip, scroll_mode);
278270   draw_foreground(screen->machine, bitmap, cliprect, flip);
279271
280272   /* highlight section A (outside of tunnels).
281     * also, bit 1 of the madalien_video_flags register (6A) is
273     * also, bit 1 of the state->video_flags register (6A) is
282274     * combined with the headlight signal through NOR gate 1A,
283275     * which is used to light up the tunnel when an alien explodes
284276    */
285   if (scroll_mode != 1 || *madalien_video_flags & 2)
277   if (scroll_mode != 1 || *state->video_flags & 2)
286278   {
287279      int x;
288280      int y;
r10427r10428
290282      int min_x = 0;
291283      int max_x = 0xff;
292284
293      if (!(*madalien_video_flags & 2))
285      if (!(*state->video_flags & 2))
294286      {
295         if (scroll_mode == 2) min_x = (*madalien_scroll & 0xfc);
296         else if (scroll_mode == 3) max_x = (*madalien_scroll & 0xfc) - 1;
287         if (scroll_mode == 2) min_x = (*state->scroll & 0xfc);
288         else if (scroll_mode == 3) max_x = (*state->scroll & 0xfc) - 1;
297289      }
298290
299291      if (flip)
r10427r10428
309301               *BITMAP_ADDR16(bitmap, y, x) |= 8;
310302   }
311303
312   draw_headlight(bitmap, cliprect, flip);
304   draw_headlight(screen->machine, bitmap, cliprect, flip);
313305
314306   return 0;
315307}
src/mame/video/atarig1.c
r10427r10428
55****************************************************************************/
66
77#include "emu.h"
8#include "machine/atarigen.h"
8#include "video/atarirle.h"
99#include "includes/atarig1.h"
1010
1111
r10427r10428
4646
4747VIDEO_START( atarig1 )
4848{
49   static const atarirle_desc modesc_hydra =
50   {
51      "gfx3",      /* region where the GFX data lives */
52      256,      /* number of entries in sprite RAM */
53      0,         /* left clip coordinate */
54      255,      /* right clip coordinate */
55
56      0x200,      /* base palette entry */
57      0x100,      /* maximum number of colors */
58
59      {{ 0x7fff,0,0,0,0,0,0,0 }},   /* mask for the code index */
60      {{ 0,0x00f0,0,0,0,0,0,0 }},   /* mask for the color */
61      {{ 0,0,0xffc0,0,0,0,0,0 }},   /* mask for the X position */
62      {{ 0,0,0,0xffc0,0,0,0,0 }},   /* mask for the Y position */
63      {{ 0,0,0,0,0xffff,0,0,0 }},   /* mask for the scale factor */
64      {{ 0x8000,0,0,0,0,0,0,0 }},   /* mask for the horizontal flip */
65      {{ 0,0,0,0,0,0x00ff,0,0 }},   /* mask for the order */
66      {{ 0 }},               /* mask for the priority */
67      {{ 0 }}                  /* mask for the VRAM target */
68   };
69
70   static const atarirle_desc modesc_pitfight =
71   {
72      "gfx3",      /* region where the GFX data lives */
73      256,      /* number of entries in sprite RAM */
74      40,         /* left clip coordinate */
75      295,      /* right clip coordinate */
76
77      0x200,      /* base palette entry */
78      0x100,      /* maximum number of colors */
79
80      {{ 0x7fff,0,0,0,0,0,0,0 }},   /* mask for the code index */
81      {{ 0,0x00f0,0,0,0,0,0,0 }},   /* mask for the color */
82      {{ 0,0,0xffc0,0,0,0,0,0 }},   /* mask for the X position */
83      {{ 0,0,0,0xffc0,0,0,0,0 }},   /* mask for the Y position */
84      {{ 0,0,0,0,0xffff,0,0,0 }},   /* mask for the scale factor */
85      {{ 0x8000,0,0,0,0,0,0,0 }},   /* mask for the horizontal flip */
86      {{ 0,0,0,0,0,0,0x00ff,0 }},   /* mask for the order */
87      {{ 0 }},               /* mask for the priority */
88      {{ 0 }}                  /* mask for the VRAM target */
89   };
9049   atarig1_state *state = machine->driver_data<atarig1_state>();
9150
9251   /* blend the playfields and free the temporary one */
r10427r10428
9655   state->playfield_tilemap = tilemap_create(machine, get_playfield_tile_info, tilemap_scan_rows,  8,8, 64,64);
9756
9857   /* initialize the motion objects */
99   atarirle_init(machine, 0, state->is_pitfight ? &modesc_pitfight : &modesc_hydra);
58   state->rle = machine->device("rle");
10059
10160   /* initialize the alphanumerics */
10261   state->alpha_tilemap = tilemap_create(machine, get_alpha_tile_info, tilemap_scan_rows,  8,8, 64,32);
r10427r10428
200159   tilemap_draw(bitmap, cliprect, state->playfield_tilemap, 0, 0);
201160
202161   /* copy the motion objects on top */
203   copybitmap_trans(bitmap, atarirle_get_vram(0, 0), 0, 0, 0, 0, cliprect, 0);
162   copybitmap_trans(bitmap, atarirle_get_vram(state->rle, 0), 0, 0, 0, 0, cliprect, 0);
204163
205164   /* add the alpha on top */
206165   tilemap_draw(bitmap, cliprect, state->alpha_tilemap, 0, 0);
207166   return 0;
208167}
168
169VIDEO_EOF( atarig1 )
170{
171   atarig1_state *state = machine->driver_data<atarig1_state>();
172
173   atarirle_eof(state->rle);
174}
src/mame/video/srumbler.c
r10427r10428
99#include "emu.h"
1010#include "includes/srumbler.h"
1111
12UINT8 *srumbler_backgroundram,*srumbler_foregroundram;
13static tilemap_t *bg_tilemap,*fg_tilemap;
1412
15
16
1713/***************************************************************************
1814
1915  Callbacks for the TileMap code
r10427r10428
2218
2319static TILE_GET_INFO( get_fg_tile_info )
2420{
25   UINT8 attr = srumbler_foregroundram[2*tile_index];
21   srumbler_state *state = machine->driver_data<srumbler_state>();
22   UINT8 attr = state->foregroundram[2*tile_index];
2623   SET_TILE_INFO(
2724         0,
28         srumbler_foregroundram[2*tile_index + 1] + ((attr & 0x03) << 8),
25         state->foregroundram[2*tile_index + 1] + ((attr & 0x03) << 8),
2926         (attr & 0x3c) >> 2,
3027         (attr & 0x40) ? TILE_FORCE_LAYER0 : 0);
3128}
3229
3330static TILE_GET_INFO( get_bg_tile_info )
3431{
35   UINT8 attr = srumbler_backgroundram[2*tile_index];
32   srumbler_state *state = machine->driver_data<srumbler_state>();
33   UINT8 attr = state->backgroundram[2*tile_index];
3634   SET_TILE_INFO(
3735         1,
38         srumbler_backgroundram[2*tile_index + 1] + ((attr & 0x07) << 8),
36         state->backgroundram[2*tile_index + 1] + ((attr & 0x07) << 8),
3937         (attr & 0xe0) >> 5,
4038         ((attr & 0x08) ? TILE_FLIPY : 0));
4139   tileinfo->group = (attr & 0x10) >> 4;
r10427r10428
5149
5250VIDEO_START( srumbler )
5351{
54   fg_tilemap = tilemap_create(machine, get_fg_tile_info,tilemap_scan_cols,8,8,64,32);
55   bg_tilemap = tilemap_create(machine, get_bg_tile_info,tilemap_scan_cols,    16,16,64,64);
52   srumbler_state *state = machine->driver_data<srumbler_state>();
53   state->fg_tilemap = tilemap_create(machine, get_fg_tile_info,tilemap_scan_cols,8,8,64,32);
54   state->bg_tilemap = tilemap_create(machine, get_bg_tile_info,tilemap_scan_cols,    16,16,64,64);
5655
57   tilemap_set_transparent_pen(fg_tilemap,3);
56   tilemap_set_transparent_pen(state->fg_tilemap,3);
5857
59   tilemap_set_transmask(bg_tilemap,0,0xffff,0x0000); /* split type 0 is totally transparent in front half */
60   tilemap_set_transmask(bg_tilemap,1,0x07ff,0xf800); /* split type 1 has pens 0-10 transparent in front half */
58   tilemap_set_transmask(state->bg_tilemap,0,0xffff,0x0000); /* split type 0 is totally transparent in front half */
59   tilemap_set_transmask(state->bg_tilemap,1,0x07ff,0xf800); /* split type 1 has pens 0-10 transparent in front half */
6160}
6261
6362
r10427r10428
7069
7170WRITE8_HANDLER( srumbler_foreground_w )
7271{
73   srumbler_foregroundram[offset] = data;
74   tilemap_mark_tile_dirty(fg_tilemap,offset/2);
72   srumbler_state *state = space->machine->driver_data<srumbler_state>();
73   state->foregroundram[offset] = data;
74   tilemap_mark_tile_dirty(state->fg_tilemap,offset/2);
7575}
7676
7777WRITE8_HANDLER( srumbler_background_w )
7878{
79   srumbler_backgroundram[offset] = data;
80   tilemap_mark_tile_dirty(bg_tilemap,offset/2);
79   srumbler_state *state = space->machine->driver_data<srumbler_state>();
80   state->backgroundram[offset] = data;
81   tilemap_mark_tile_dirty(state->bg_tilemap,offset/2);
8182}
8283
8384
r10427r10428
9697
9798WRITE8_HANDLER( srumbler_scroll_w )
9899{
99   static int scroll[4];
100   srumbler_state *state = space->machine->driver_data<srumbler_state>();
100101
101   scroll[offset] = data;
102   state->scroll[offset] = data;
102103
103   tilemap_set_scrollx(bg_tilemap,0,scroll[0] | (scroll[1] << 8));
104   tilemap_set_scrolly(bg_tilemap,0,scroll[2] | (scroll[3] << 8));
104   tilemap_set_scrollx(state->bg_tilemap,0,state->scroll[0] | (state->scroll[1] << 8));
105   tilemap_set_scrolly(state->bg_tilemap,0,state->scroll[2] | (state->scroll[3] << 8));
105106}
106107
107108
r10427r10428
161162
162163VIDEO_UPDATE( srumbler )
163164{
164   tilemap_draw(bitmap,cliprect,bg_tilemap,TILEMAP_DRAW_LAYER1,0);
165   srumbler_state *state = screen->machine->driver_data<srumbler_state>();
166   tilemap_draw(bitmap,cliprect,state->bg_tilemap,TILEMAP_DRAW_LAYER1,0);
165167   draw_sprites(screen->machine, bitmap,cliprect);
166   tilemap_draw(bitmap,cliprect,bg_tilemap,TILEMAP_DRAW_LAYER0,0);
167   tilemap_draw(bitmap,cliprect,fg_tilemap,0,0);
168   tilemap_draw(bitmap,cliprect,state->bg_tilemap,TILEMAP_DRAW_LAYER0,0);
169   tilemap_draw(bitmap,cliprect,state->fg_tilemap,0,0);
168170   return 0;
169171}
170172
src/mame/video/tigeroad.c
r10427r10428
11#include "emu.h"
22#include "includes/tigeroad.h"
33
4static int bgcharbank;
5static tilemap_t *bg_tilemap, *fg_tilemap;
64
75WRITE16_HANDLER( tigeroad_videoram_w )
86{
97   tigeroad_state *state = space->machine->driver_data<tigeroad_state>();
108   UINT16 *videoram = state->videoram;
119   COMBINE_DATA(&videoram[offset]);
12   tilemap_mark_tile_dirty(fg_tilemap, offset);
10   tilemap_mark_tile_dirty(state->fg_tilemap, offset);
1311}
1412
1513WRITE16_HANDLER( tigeroad_videoctrl_w )
1614{
15   tigeroad_state *state = space->machine->driver_data<tigeroad_state>();
1716   int bank;
1817
1918   if (ACCESSING_BITS_8_15)
r10427r10428
3231
3332      bank = (data & 0x04) >> 2;
3433
35      if (bgcharbank != bank)
34      if (state->bgcharbank != bank)
3635      {
37         bgcharbank = bank;
38         tilemap_mark_all_tiles_dirty(bg_tilemap);
36         state->bgcharbank = bank;
37         tilemap_mark_all_tiles_dirty(state->bg_tilemap);
3938      }
4039
4140      /* bits 4-5 are coin lockouts */
r10427r10428
5251
5352WRITE16_HANDLER( tigeroad_scroll_w )
5453{
54   tigeroad_state *state = space->machine->driver_data<tigeroad_state>();
5555   int scroll = 0;
5656
5757   COMBINE_DATA(&scroll);
r10427r10428
5959   switch (offset)
6060   {
6161   case 0:
62      tilemap_set_scrollx(bg_tilemap, 0, scroll);
62      tilemap_set_scrollx(state->bg_tilemap, 0, scroll);
6363      break;
6464   case 1:
65      tilemap_set_scrolly(bg_tilemap, 0, -scroll - 32 * 8);
65      tilemap_set_scrolly(state->bg_tilemap, 0, -scroll - 32 * 8);
6666      break;
6767   }
6868}
r10427r10428
113113
114114static TILE_GET_INFO( get_bg_tile_info )
115115{
116   tigeroad_state *state = machine->driver_data<tigeroad_state>();
116117   UINT8 *tilerom = machine->region("gfx4")->base();
117118
118119   int data = tilerom[tile_index];
119120   int attr = tilerom[tile_index + 1];
120   int code = data + ((attr & 0xc0) << 2) + (bgcharbank << 10);
121   int code = data + ((attr & 0xc0) << 2) + (state->bgcharbank << 10);
121122   int color = attr & 0x0f;
122123   int flags = (attr & 0x20) ? TILE_FLIPX : 0;
123124
r10427r10428
146147
147148VIDEO_START( tigeroad )
148149{
149   bg_tilemap = tilemap_create(machine, get_bg_tile_info, tigeroad_tilemap_scan,
150   tigeroad_state *state = machine->driver_data<tigeroad_state>();
151   state->bg_tilemap = tilemap_create(machine, get_bg_tile_info, tigeroad_tilemap_scan,
150152       32, 32, 128, 128);
151153
152   fg_tilemap = tilemap_create(machine, get_fg_tile_info, tilemap_scan_rows,
154   state->fg_tilemap = tilemap_create(machine, get_fg_tile_info, tilemap_scan_rows,
153155       8, 8, 32, 32);
154156
155   tilemap_set_transmask(bg_tilemap, 0, 0xffff, 0);
156   tilemap_set_transmask(bg_tilemap, 1, 0x1ff, 0xfe00);
157   tilemap_set_transmask(state->bg_tilemap, 0, 0xffff, 0);
158   tilemap_set_transmask(state->bg_tilemap, 1, 0x1ff, 0xfe00);
157159
158   tilemap_set_transparent_pen(fg_tilemap, 3);
160   tilemap_set_transparent_pen(state->fg_tilemap, 3);
159161}
160162
161163VIDEO_UPDATE( tigeroad )
162164{
163   tilemap_draw(bitmap, cliprect, bg_tilemap, TILEMAP_DRAW_LAYER1, 0);
165   tigeroad_state *state = screen->machine->driver_data<tigeroad_state>();
166   tilemap_draw(bitmap, cliprect, state->bg_tilemap, TILEMAP_DRAW_LAYER1, 0);
164167   draw_sprites(screen->machine, bitmap, cliprect, 0);
165   tilemap_draw(bitmap, cliprect, bg_tilemap, TILEMAP_DRAW_LAYER0, 1);
168   tilemap_draw(bitmap, cliprect, state->bg_tilemap, TILEMAP_DRAW_LAYER0, 1);
166169   //draw_sprites(screen->machine, bitmap, cliprect, 1); draw priority sprites?
167   tilemap_draw(bitmap, cliprect, fg_tilemap, 0, 2);
170   tilemap_draw(bitmap, cliprect, state->fg_tilemap, 0, 2);
168171   return 0;
169172}
170173
src/mame/video/segas32.c
r10427r10428
199199 *
200200 *************************************/
201201
202struct layer_info
203{
204   bitmap_t *   bitmap;
205   UINT8 *               transparent;
206};
207
208
209202struct extents_list
210203{
211204   UINT8               scan_extent[256];
r10427r10428
225218
226219/*************************************
227220 *
228 *  Globals
229 *
230 *************************************/
231
232UINT16 *system32_videoram;
233UINT16 *system32_spriteram;
234UINT16 *system32_paletteram[2];
235UINT16 system32_displayenable[2];
236UINT16 system32_tilebank_external;
237
238
239
240/*************************************
241 *
242 *  Statics
243 *
244 *************************************/
245
246static UINT8 is_multi32;
247
248/* tilemap cache */
249static struct cache_entry *cache_head;
250
251/* mixer data */
252static struct layer_info layer_data[11];
253static UINT16 mixer_control[2][0x40];
254static UINT16 *solid_0000;
255static UINT16 *solid_ffff;
256
257/* sprite data */
258static UINT8 sprite_render_count;
259static UINT8 sprite_control_latched[8];
260static UINT8 sprite_control[8];
261static UINT32 *spriteram_32bit;
262
263
264
265/*************************************
266 *
267221 *  Prototypes
268222 *
269223 *************************************/
270224
271225static TILE_GET_INFO( get_tile_info );
272static void sprite_erase_buffer(void);
273static void sprite_swap_buffers(void);
226static void sprite_erase_buffer(segas32_state *state);
227static void sprite_swap_buffers(segas32_state *state);
274228static void sprite_render_list(running_machine *machine);
275229
276230
r10427r10428
284238
285239static void common_start(running_machine *machine, int multi32)
286240{
241   segas32_state *state = machine->driver_data<segas32_state>();
287242   int tmap;
288243
289244   /* remember whether or not we are multi32 */
290   is_multi32 = multi32;
245   state->is_multi32 = multi32;
291246
292247   /* allocate a copy of spriteram in 32-bit format */
293   spriteram_32bit = auto_alloc_array(machine, UINT32, 0x20000/4);
248   state->spriteram_32bit = auto_alloc_array(machine, UINT32, 0x20000/4);
294249
295250   /* allocate the tilemap cache */
296   cache_head = NULL;
251   state->cache_head = NULL;
297252   for (tmap = 0; tmap < TILEMAP_CACHE_SIZE; tmap++)
298253   {
299254      struct cache_entry *entry = auto_alloc(machine, struct cache_entry);
r10427r10428
301256      entry->tmap = tilemap_create(machine, get_tile_info, tilemap_scan_rows,  16,16, 32,16);
302257      entry->page = 0xff;
303258      entry->bank = 0;
304      entry->next = cache_head;
259      entry->next = state->cache_head;
305260      tilemap_set_user_data(entry->tmap, entry);
306261
307      cache_head = entry;
262      state->cache_head = entry;
308263   }
309264
310265   /* allocate the bitmaps (a few extra for multi32) */
311266   for (tmap = 0; tmap < 9 + 2 * multi32; tmap++)
312267   {
313      layer_data[tmap].bitmap = auto_bitmap_alloc(machine, 416, 224, BITMAP_FORMAT_INDEXED16);
314      layer_data[tmap].transparent = auto_alloc_array_clear(machine, UINT8, 256);
268      state->layer_data[tmap].bitmap = auto_bitmap_alloc(machine, 416, 224, BITMAP_FORMAT_INDEXED16);
269      state->layer_data[tmap].transparent = auto_alloc_array_clear(machine, UINT8, 256);
315270   }
316271
317272   /* allocate pre-rendered solid lines of 0's and ffff's */
318   solid_0000 = auto_alloc_array(machine, UINT16, 512);
319   memset(solid_0000, 0x00, sizeof(solid_0000[0]) * 512);
320   solid_ffff = auto_alloc_array(machine, UINT16, 512);
321   memset(solid_ffff, 0xff, sizeof(solid_ffff[0]) * 512);
273   state->solid_0000 = auto_alloc_array(machine, UINT16, 512);
274   memset(state->solid_0000, 0x00, sizeof(state->solid_0000[0]) * 512);
275   state->solid_ffff = auto_alloc_array(machine, UINT16, 512);
276   memset(state->solid_ffff, 0xff, sizeof(state->solid_ffff[0]) * 512);
322277
323278   /* initialize videoram */
324   system32_videoram[0x1ff00/2] = 0x8000;
279   state->system32_videoram[0x1ff00/2] = 0x8000;
325280}
326281
327282
r10427r10428
346301
347302static TIMER_CALLBACK( update_sprites )
348303{
304   segas32_state *state = machine->driver_data<segas32_state>();
349305   /* if automatic mode is selected, do it every frame (0) or every other frame (1) */
350   if (!(sprite_control[3] & 2))
306   if (!(state->sprite_control[3] & 2))
351307   {
352308      /* if we count down to the start, process the automatic swapping, but only after a short delay */
353      if (sprite_render_count-- == 0)
309      if (state->sprite_render_count-- == 0)
354310      {
355         sprite_control[0] = 3;
356         sprite_render_count = sprite_control[3] & 1;
311         state->sprite_control[0] = 3;
312         state->sprite_render_count = state->sprite_control[3] & 1;
357313      }
358314   }
359315
360316   /* look for pending commands */
361   if (sprite_control[0] & 2)
362      sprite_erase_buffer();
363   if (sprite_control[0] & 1)
317   if (state->sprite_control[0] & 2)
318      sprite_erase_buffer(state);
319   if (state->sprite_control[0] & 1)
364320   {
365      sprite_swap_buffers();
321      sprite_swap_buffers(state);
366322      sprite_render_list(machine);
367323   }
368   sprite_control[0] = 0;
324   state->sprite_control[0] = 0;
369325}
370326
371327
r10427r10428
415371}
416372
417373
418INLINE UINT16 common_paletteram_r(int which, offs_t offset)
374INLINE UINT16 common_paletteram_r(address_space *space, int which, offs_t offset)
419375{
376   segas32_state *state = space->machine->driver_data<segas32_state>();
420377   int convert;
421378
422379   /* the lower half of palette RAM is formatted xBBBBBGGGGGRRRRR */
r10427r10428
427384   offset &= 0x3fff;
428385
429386   if (!convert)
430      return system32_paletteram[which][offset];
387      return state->system32_paletteram[which][offset];
431388   else
432      return xBBBBBGGGGGRRRRR_to_xBGRBBBBGGGGRRRR(system32_paletteram[which][offset]);
389      return xBBBBBGGGGGRRRRR_to_xBGRBBBBGGGGRRRR(state->system32_paletteram[which][offset]);
433390}
434391
435392
436393static void common_paletteram_w(address_space *space, int which, offs_t offset, UINT16 data, UINT16 mem_mask)
437394{
395   segas32_state *state = space->machine->driver_data<segas32_state>();
438396   UINT16 value;
439397   int convert;
440398
r10427r10428
446404   offset &= 0x3fff;
447405
448406   /* read, modify, and write the new value, updating the palette */
449   value = system32_paletteram[which][offset];
407   value = state->system32_paletteram[which][offset];
450408   if (convert) value = xBBBBBGGGGGRRRRR_to_xBGRBBBBGGGGRRRR(value);
451409   COMBINE_DATA(&value);
452410   if (convert) value = xBGRBBBBGGGGRRRR_to_xBBBBBGGGGGRRRRR(value);
453   system32_paletteram[which][offset] = value;
411   state->system32_paletteram[which][offset] = value;
454412   update_color(space->machine, 0x4000*which + offset, value);
455413
456414   /* if blending is enabled, writes go to both halves of palette RAM */
457   if (mixer_control[which][0x4e/2] & 0x0880)
415   if (state->mixer_control[which][0x4e/2] & 0x0880)
458416   {
459417      offset ^= 0x2000;
460418
461419      /* read, modify, and write the new value, updating the palette */
462      value = system32_paletteram[which][offset];
420      value = state->system32_paletteram[which][offset];
463421      if (convert) value = xBBBBBGGGGGRRRRR_to_xBGRBBBBGGGGRRRR(value);
464422      COMBINE_DATA(&value);
465423      if (convert) value = xBGRBBBBGGGGRRRR_to_xBBBBBGGGGGRRRRR(value);
466      system32_paletteram[which][offset] = value;
424      state->system32_paletteram[which][offset] = value;
467425      update_color(space->machine, 0x4000*which + offset, value);
468426   }
469427}
r10427r10428
478436
479437READ16_HANDLER( system32_paletteram_r )
480438{
481   return common_paletteram_r(0, offset);
439   return common_paletteram_r(space, 0, offset);
482440}
483441
484442
r10427r10428
490448
491449READ32_HANDLER( multi32_paletteram_0_r )
492450{
493   return common_paletteram_r(0, offset*2+0) |
494         (common_paletteram_r(0, offset*2+1) << 16);
451   return common_paletteram_r(space, 0, offset*2+0) |
452         (common_paletteram_r(space, 0, offset*2+1) << 16);
495453}
496454
497455
r10427r10428
506464
507465READ32_HANDLER( multi32_paletteram_1_r )
508466{
509   return common_paletteram_r(1, offset*2+0) |
510         (common_paletteram_r(1, offset*2+1) << 16);
467   return common_paletteram_r(space, 1, offset*2+0) |
468         (common_paletteram_r(space, 1, offset*2+1) << 16);
511469}
512470
513471
r10427r10428
529487
530488READ16_HANDLER( system32_videoram_r )
531489{
532   return system32_videoram[offset];
490   segas32_state *state = space->machine->driver_data<segas32_state>();
491   return state->system32_videoram[offset];
533492}
534493
535494
536495WRITE16_HANDLER( system32_videoram_w )
537496{
538   COMBINE_DATA(&system32_videoram[offset]);
497   segas32_state *state = space->machine->driver_data<segas32_state>();
498   COMBINE_DATA(&state->system32_videoram[offset]);
539499
540500   /* if we are not in the control area, just update any affected tilemaps */
541501   if (offset < 0x1ff00/2)
r10427r10428
545505      offset %= 0x200;
546506
547507      /* scan the cache for a matching pages */
548      for (entry = cache_head; entry != NULL; entry = entry->next)
508      for (entry = state->cache_head; entry != NULL; entry = entry->next)
549509         if (entry->page == page)
550510            tilemap_mark_tile_dirty(entry->tmap, offset);
551511   }
r10427r10428
554514
555515READ32_HANDLER( multi32_videoram_r )
556516{
557   return system32_videoram[offset*2+0] |
558         (system32_videoram[offset*2+1] << 16);
517   segas32_state *state = space->machine->driver_data<segas32_state>();
518   return state->system32_videoram[offset*2+0] |
519         (state->system32_videoram[offset*2+1] << 16);
559520}
560521
561522
r10427r10428
577538
578539READ16_HANDLER( system32_sprite_control_r )
579540{
541   segas32_state *state = space->machine->driver_data<segas32_state>();
580542   switch (offset)
581543   {
582544      case 0:
583545         /*  D1 : Seems to be '1' only during an erase in progress, this
584546                     occurs very briefly though.
585547                D0 : Selected frame buffer (0= A, 1= B) */
586         return 0xfffc | (int)(layer_data[MIXER_LAYER_SPRITES].bitmap < layer_data[MIXER_LAYER_SPRITES_2].bitmap);
548         return 0xfffc | (int)(state->layer_data[MIXER_LAYER_SPRITES].bitmap < state->layer_data[MIXER_LAYER_SPRITES_2].bitmap);
587549
588550      case 1:
589551         /*  D1 : ?
r10427r10428
602564      case 2:
603565         /*  D1 : 1= Vertical flip, 0= Normal orientation
604566                D0 : 1= Horizontal flip, 0= Normal orientation */
605         return 0xfffc | sprite_control_latched[2];
567         return 0xfffc | state->sprite_control_latched[2];
606568
607569      case 3:
608570         /*  D1 : 1= Manual mode, 0= Automatic mode
609571                D0 : 1= 30 Hz update, 0= 60 Hz update (automatic mode only) */
610         return 0xfffc | sprite_control_latched[3];
572         return 0xfffc | state->sprite_control_latched[3];
611573
612574      case 4:
613575         /*  D1 : ?
614576                D0 : ? */
615         return 0xfffc | sprite_control_latched[4];
577         return 0xfffc | state->sprite_control_latched[4];
616578
617579      case 5:
618580         /*  D1 : ?
619581                D0 : ? */
620         return 0xfffc | sprite_control_latched[5];
582         return 0xfffc | state->sprite_control_latched[5];
621583
622584      case 6:
623585         /*  D0 : 1= 416 pixels
624586                     0= 320 pixels */
625         return 0xfffc | (sprite_control_latched[6] & 1);
587         return 0xfffc | (state->sprite_control_latched[6] & 1);
626588
627589      case 7:
628590         /*  D1 : ?
r10427r10428
635597
636598WRITE16_HANDLER( system32_sprite_control_w )
637599{
600   segas32_state *state = space->machine->driver_data<segas32_state>();
638601   if (ACCESSING_BITS_0_7)
639      sprite_control[offset & 7] = data;
602      state->sprite_control[offset & 7] = data;
640603}
641604
642605
r10427r10428
665628
666629READ16_HANDLER( system32_spriteram_r )
667630{
668   return system32_spriteram[offset];
631   segas32_state *state = space->machine->driver_data<segas32_state>();
632   return state->system32_spriteram[offset];
669633}
670634
671635
672636WRITE16_HANDLER( system32_spriteram_w )
673637{
674   COMBINE_DATA(&system32_spriteram[offset]);
675   spriteram_32bit[offset/2] =
676      ((system32_spriteram[offset |  1] >> 8 ) & 0x000000ff) |
677      ((system32_spriteram[offset |  1] << 8 ) & 0x0000ff00) |
678      ((system32_spriteram[offset & ~1] << 8 ) & 0x00ff0000) |
679      ((system32_spriteram[offset & ~1] << 24) & 0xff000000);
638   segas32_state *state = space->machine->driver_data<segas32_state>();
639   COMBINE_DATA(&state->system32_spriteram[offset]);
640   state->spriteram_32bit[offset/2] =
641      ((state->system32_spriteram[offset |  1] >> 8 ) & 0x000000ff) |
642      ((state->system32_spriteram[offset |  1] << 8 ) & 0x0000ff00) |
643      ((state->system32_spriteram[offset & ~1] << 8 ) & 0x00ff0000) |
644      ((state->system32_spriteram[offset & ~1] << 24) & 0xff000000);
680645}
681646
682647
683648READ32_HANDLER( multi32_spriteram_r )
684649{
685   return system32_spriteram[offset*2+0] |
686         (system32_spriteram[offset*2+1] << 16);
650   segas32_state *state = space->machine->driver_data<segas32_state>();
651   return state->system32_spriteram[offset*2+0] |
652         (state->system32_spriteram[offset*2+1] << 16);
687653}
688654
689655
690656WRITE32_HANDLER( multi32_spriteram_w )
691657{
658   segas32_state *state = space->machine->driver_data<segas32_state>();
692659   data = SWAP_HALVES(data);
693660   mem_mask = SWAP_HALVES(mem_mask);
694   COMBINE_DATA((UINT32 *)&system32_spriteram[offset*2]);
695   spriteram_32bit[offset/2] =
696      ((system32_spriteram[offset |  1] >> 8 ) & 0x000000ff) |
697      ((system32_spriteram[offset |  1] << 8 ) & 0x0000ff00) |
698      ((system32_spriteram[offset & ~1] << 8 ) & 0x00ff0000) |
699      ((system32_spriteram[offset & ~1] << 24) & 0xff000000);
661   COMBINE_DATA((UINT32 *)&state->system32_spriteram[offset*2]);
662   state->spriteram_32bit[offset/2] =
663      ((state->system32_spriteram[offset |  1] >> 8 ) & 0x000000ff) |
664      ((state->system32_spriteram[offset |  1] << 8 ) & 0x0000ff00) |
665      ((state->system32_spriteram[offset & ~1] << 8 ) & 0x00ff0000) |
666      ((state->system32_spriteram[offset & ~1] << 24) & 0xff000000);
700667}
701668
702669
r10427r10428
709676
710677READ16_HANDLER( system32_mixer_r )
711678{
712   return mixer_control[0][offset];
679   segas32_state *state = space->machine->driver_data<segas32_state>();
680   return state->mixer_control[0][offset];
713681}
714682
715683WRITE16_HANDLER( system32_mixer_w )
716684{
717   COMBINE_DATA(&mixer_control[0][offset]);
685   segas32_state *state = space->machine->driver_data<segas32_state>();
686   COMBINE_DATA(&state->mixer_control[0][offset]);
718687}
719688
720689
721690WRITE32_HANDLER( multi32_mixer_0_w )
722691{
692   segas32_state *state = space->machine->driver_data<segas32_state>();
723693   data = SWAP_HALVES(data);
724694   mem_mask = SWAP_HALVES(mem_mask);
725   COMBINE_DATA((UINT32 *)&mixer_control[0][offset*2]);
695   COMBINE_DATA((UINT32 *)&state->mixer_control[0][offset*2]);
726696}
727697
728698
729699WRITE32_HANDLER( multi32_mixer_1_w )
730700{
701   segas32_state *state = space->machine->driver_data<segas32_state>();
731702   data = SWAP_HALVES(data);
732703   mem_mask = SWAP_HALVES(mem_mask);
733   COMBINE_DATA((UINT32 *)&mixer_control[1][offset*2]);
704   COMBINE_DATA((UINT32 *)&state->mixer_control[1][offset*2]);
734705}
735706
736707
r10427r10428
741712 *
742713 *************************************/
743714
744static tilemap_t *find_cache_entry(int page, int bank)
715static tilemap_t *find_cache_entry(segas32_state *state, int page, int bank)
745716{
746717   struct cache_entry *entry, *prev;
747718
748719   /* scan the list for a matching entry */
749720   prev = NULL;
750   entry = cache_head;
721   entry = state->cache_head;
751722   while (1)
752723   {
753724      if (entry->page == page && entry->bank == bank)
r10427r10428
756727         if (prev)
757728         {
758729            prev->next = entry->next;
759            entry->next = cache_head;
760            cache_head = entry;
730            entry->next = state->cache_head;
731            state->cache_head = entry;
761732         }
762733         return entry->tmap;
763734      }
r10427r10428
776747
777748   /* move it to the head */
778749   prev->next = entry->next;
779   entry->next = cache_head;
780   cache_head = entry;
750   entry->next = state->cache_head;
751   state->cache_head = entry;
781752
782753   return entry->tmap;
783754}
r10427r10428
792763
793764static TILE_GET_INFO( get_tile_info )
794765{
766   segas32_state *state = machine->driver_data<segas32_state>();
795767   struct cache_entry *entry = (struct cache_entry *)param;
796   UINT16 data = system32_videoram[(entry->page & 0x7f) * 0x200 + tile_index];
768   UINT16 data = state->system32_videoram[(entry->page & 0x7f) * 0x200 + tile_index];
797769   SET_TILE_INFO(0, (entry->bank << 13) + (data & 0x1fff), (data >> 4) & 0x1ff, (data >> 14) & 3);
798770}
799771
r10427r10428
807779
808780static int compute_clipping_extents(screen_device &screen, int enable, int clipout, int clipmask, const rectangle *cliprect, struct extents_list *list)
809781{
810   int flip = (system32_videoram[0x1ff00/2] >> 9) & 1;
782   segas32_state *state = screen.machine->driver_data<segas32_state>();
783   int flip = (state->system32_videoram[0x1ff00/2] >> 9) & 1;
811784   rectangle tempclip;
812785   rectangle clips[5];
813786   int sorted[5];
r10427r10428
834807   {
835808      if (!flip)
836809      {
837         clips[i].min_x = system32_videoram[0x1ff60/2 + i * 4] & 0x1ff;
838         clips[i].min_y = system32_videoram[0x1ff62/2 + i * 4] & 0x0ff;
839         clips[i].max_x = (system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1;
840         clips[i].max_y = (system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1;
810         clips[i].min_x = state->system32_videoram[0x1ff60/2 + i * 4] & 0x1ff;
811         clips[i].min_y = state->system32_videoram[0x1ff62/2 + i * 4] & 0x0ff;
812         clips[i].max_x = (state->system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1;
813         clips[i].max_y = (state->system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1;
841814      }
842815      else
843816      {
844817         const rectangle &visarea = screen.visible_area();
845818
846         clips[i].max_x = (visarea.max_x + 1) - (system32_videoram[0x1ff60/2 + i * 4] & 0x1ff);
847         clips[i].max_y = (visarea.max_y + 1) - (system32_videoram[0x1ff62/2 + i * 4] & 0x0ff);
848         clips[i].min_x = (visarea.max_x + 1) - ((system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1);
849         clips[i].min_y = (visarea.max_y + 1) - ((system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1);
819         clips[i].max_x = (visarea.max_x + 1) - (state->system32_videoram[0x1ff60/2 + i * 4] & 0x1ff);
820         clips[i].max_y = (visarea.max_y + 1) - (state->system32_videoram[0x1ff62/2 + i * 4] & 0x0ff);
821         clips[i].min_x = (visarea.max_x + 1) - ((state->system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1);
822         clips[i].min_y = (visarea.max_y + 1) - ((state->system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1);
850823      }
851824      sect_rect(&clips[i], &tempclip);
852825      sorted[i] = i;
r10427r10428
914887 *
915888 *************************************/
916889
917INLINE void get_tilemaps(int bgnum, tilemap_t **tilemaps)
890INLINE void get_tilemaps(segas32_state *state, int bgnum, tilemap_t **tilemaps)
918891{
919892   int tilebank, page;
920893
921894   /* determine the current tilebank */
922   if (is_multi32)
923      tilebank = (system32_tilebank_external >> (2*bgnum)) & 3;
895   if (state->is_multi32)
896      tilebank = (state->system32_tilebank_external >> (2*bgnum)) & 3;
924897   else
925      tilebank = ((system32_tilebank_external & 1) << 1) | ((system32_videoram[0x1ff00/2] & 0x400) >> 10);
898      tilebank = ((state->system32_tilebank_external & 1) << 1) | ((state->system32_videoram[0x1ff00/2] & 0x400) >> 10);
926899
927900   /* find the cache entries */
928   page = (system32_videoram[0x1ff40/2 + 2 * bgnum + 0] >> 0) & 0x7f;
929   tilemaps[0] = find_cache_entry(page, tilebank);
930   page = (system32_videoram[0x1ff40/2 + 2 * bgnum + 0] >> 8) & 0x7f;
931   tilemaps[1] = find_cache_entry(page, tilebank);
932   page = (system32_videoram[0x1ff40/2 + 2 * bgnum + 1] >> 0) & 0x7f;
933   tilemaps[2] = find_cache_entry(page, tilebank);
934   page = (system32_videoram[0x1ff40/2 + 2 * bgnum + 1] >> 8) & 0x7f;
935   tilemaps[3] = find_cache_entry(page, tilebank);
901   page = (state->system32_videoram[0x1ff40/2 + 2 * bgnum + 0] >> 0) & 0x7f;
902   tilemaps[0] = find_cache_entry(state, page, tilebank);
903   page = (state->system32_videoram[0x1ff40/2 + 2 * bgnum + 0] >> 8) & 0x7f;
904   tilemaps[1] = find_cache_entry(state, page, tilebank);
905   page = (state->system32_videoram[0x1ff40/2 + 2 * bgnum + 1] >> 0) & 0x7f;
906   tilemaps[2] = find_cache_entry(state, page, tilebank);
907   page = (state->system32_videoram[0x1ff40/2 + 2 * bgnum + 1] >> 8) & 0x7f;
908   tilemaps[3] = find_cache_entry(state, page, tilebank);
936909}
937910
938911
939912static void update_tilemap_zoom(screen_device &screen, struct layer_info *layer, const rectangle *cliprect, int bgnum)
940913{
914   segas32_state *state = screen.machine->driver_data<segas32_state>();
941915   int clipenable, clipout, clips, clipdraw_start;
942916   bitmap_t *bitmap = layer->bitmap;
943917   struct extents_list clip_extents;
r10427r10428
949923   int x, y;
950924
951925   /* get the tilemaps */
952   get_tilemaps(bgnum, tilemaps);
926   get_tilemaps(state, bgnum, tilemaps);
953927
954928   /* configure the layer */
955929   opaque = 0;
956//opaque = (system32_videoram[0x1ff8e/2] >> (8 + bgnum)) & 1;
930//opaque = (state->system32_videoram[0x1ff8e/2] >> (8 + bgnum)) & 1;
957931//if (input_code_pressed(screen.machine, KEYCODE_Z) && bgnum == 0) opaque = 1;
958932//if (input_code_pressed(screen.machine, KEYCODE_X) && bgnum == 1) opaque = 1;
959933
960934   /* determine if we're flipped */
961   flip = ((system32_videoram[0x1ff00/2] >> 9) ^ (system32_videoram[0x1ff00/2] >> bgnum)) & 1;
935   flip = ((state->system32_videoram[0x1ff00/2] >> 9) ^ (state->system32_videoram[0x1ff00/2] >> bgnum)) & 1;
962936
963937   /* determine the clipping */
964   clipenable = (system32_videoram[0x1ff02/2] >> (11 + bgnum)) & 1;
965   clipout = (system32_videoram[0x1ff02/2] >> (6 + bgnum)) & 1;
966   clips = (system32_videoram[0x1ff06/2] >> (4 * bgnum)) & 0x0f;
938   clipenable = (state->system32_videoram[0x1ff02/2] >> (11 + bgnum)) & 1;
939   clipout = (state->system32_videoram[0x1ff02/2] >> (6 + bgnum)) & 1;
940   clips = (state->system32_videoram[0x1ff06/2] >> (4 * bgnum)) & 0x0f;
967941   clipdraw_start = compute_clipping_extents(screen, clipenable, clipout, clips, cliprect, &clip_extents);
968942
969943   /* extract the X/Y step values (these are in destination space!) */
970   dstxstep = system32_videoram[0x1ff50/2 + 2 * bgnum] & 0xfff;
971   if (system32_videoram[0x1ff00/2] & 0x4000)
972      dstystep = system32_videoram[0x1ff52/2 + 2 * bgnum] & 0xfff;
944   dstxstep = state->system32_videoram[0x1ff50/2 + 2 * bgnum] & 0xfff;
945   if (state->system32_videoram[0x1ff00/2] & 0x4000)
946      dstystep = state->system32_videoram[0x1ff52/2 + 2 * bgnum] & 0xfff;
973947   else
974948      dstystep = dstxstep;
975949
r10427r10428
984958   srcystep = (0x200 << 20) / dstystep;
985959
986960   /* start with the fractional scroll offsets, in source coordinates */
987   srcx_start = (system32_videoram[0x1ff12/2 + 4 * bgnum] & 0x3ff) << 20;
988   srcx_start += (system32_videoram[0x1ff10/2 + 4 * bgnum] & 0xff00) << 4;
989   srcy = (system32_videoram[0x1ff16/2 + 4 * bgnum] & 0x1ff) << 20;
990   srcy += (system32_videoram[0x1ff14/2 + 4 * bgnum] & 0xfe00) << 4;
961   srcx_start = (state->system32_videoram[0x1ff12/2 + 4 * bgnum] & 0x3ff) << 20;
962   srcx_start += (state->system32_videoram[0x1ff10/2 + 4 * bgnum] & 0xff00) << 4;
963   srcy = (state->system32_videoram[0x1ff16/2 + 4 * bgnum] & 0x1ff) << 20;
964   srcy += (state->system32_videoram[0x1ff14/2 + 4 * bgnum] & 0xfe00) << 4;
991965
992966   /* then account for the destination center coordinates */
993   srcx_start -= ((INT16)(system32_videoram[0x1ff30/2 + 2 * bgnum] << 6) >> 6) * srcxstep;
994   srcy -= ((INT16)(system32_videoram[0x1ff32/2 + 2 * bgnum] << 7) >> 7) * srcystep;
967   srcx_start -= ((INT16)(state->system32_videoram[0x1ff30/2 + 2 * bgnum] << 6) >> 6) * srcxstep;
968   srcy -= ((INT16)(state->system32_videoram[0x1ff32/2 + 2 * bgnum] << 7) >> 7) * srcystep;
995969
996970   /* finally, account for destination top,left coordinates */
997971   srcx_start += cliprect->min_x * srcxstep;
r10427r10428
10761050#if 0
10771051   if (dstxstep != 0x200 || dstystep != 0x200)
10781052      popmessage("Zoom=%03X,%03X  Cent=%03X,%03X", dstxstep, dstystep,
1079         system32_videoram[0x1ff30/2 + 2 * bgnum],
1080         system32_videoram[0x1ff32/2 + 2 * bgnum]);
1053         state->system32_videoram[0x1ff30/2 + 2 * bgnum],
1054         state->system32_videoram[0x1ff32/2 + 2 * bgnum]);
10811055#endif
10821056}
10831057
r10427r10428
10911065
10921066static void update_tilemap_rowscroll(screen_device &screen, struct layer_info *layer, const rectangle *cliprect, int bgnum)
10931067{
1068   segas32_state *state = screen.machine->driver_data<segas32_state>();
10941069   int clipenable, clipout, clips, clipdraw_start;
10951070   bitmap_t *bitmap = layer->bitmap;
10961071   struct extents_list clip_extents;
r10427r10428
11031078   int x, y;
11041079
11051080   /* get the tilemaps */
1106   get_tilemaps(bgnum, tilemaps);
1081   get_tilemaps(state, bgnum, tilemaps);
11071082
11081083   /* configure the layer */
11091084   opaque = 0;
1110//opaque = (system32_videoram[0x1ff8e/2] >> (8 + bgnum)) & 1;
1085//opaque = (state->system32_videoram[0x1ff8e/2] >> (8 + bgnum)) & 1;
11111086//if (input_code_pressed(screen.machine, KEYCODE_C) && bgnum == 2) opaque = 1;
11121087//if (input_code_pressed(screen.machine, KEYCODE_V) && bgnum == 3) opaque = 1;
11131088
11141089   /* determine if we're flipped */
1115   flip = ((system32_videoram[0x1ff00/2] >> 9) ^ (system32_videoram[0x1ff00/2] >> bgnum)) & 1;
1090   flip = ((state->system32_videoram[0x1ff00/2] >> 9) ^ (state->system32_videoram[0x1ff00/2] >> bgnum)) & 1;
11161091
11171092   /* determine the clipping */
1118   clipenable = (system32_videoram[0x1ff02/2] >> (11 + bgnum)) & 1;
1119   clipout = (system32_videoram[0x1ff02/2] >> (6 + bgnum)) & 1;
1120   clips = (system32_videoram[0x1ff06/2] >> (4 * bgnum)) & 0x0f;
1093   clipenable = (state->system32_videoram[0x1ff02/2] >> (11 + bgnum)) & 1;
1094   clipout = (state->system32_videoram[0x1ff02/2] >> (6 + bgnum)) & 1;
1095   clips = (state->system32_videoram[0x1ff06/2] >> (4 * bgnum)) & 0x0f;
11211096   clipdraw_start = compute_clipping_extents(screen, clipenable, clipout, clips, cliprect, &clip_extents);
11221097
11231098   /* determine if row scroll and/or row select is enabled */
1124   rowscroll = (system32_videoram[0x1ff04/2] >> (bgnum - 2)) & 1;
1125   rowselect = (system32_videoram[0x1ff04/2] >> bgnum) & 1;
1126   if ((system32_videoram[0x1ff04/2] >> (bgnum + 2)) & 1)
1099   rowscroll = (state->system32_videoram[0x1ff04/2] >> (bgnum - 2)) & 1;
1100   rowselect = (state->system32_videoram[0x1ff04/2] >> bgnum) & 1;
1101   if ((state->system32_videoram[0x1ff04/2] >> (bgnum + 2)) & 1)
11271102      rowscroll = rowselect = 0;
11281103
11291104   /* get a pointer to the table */
1130   table = &system32_videoram[(system32_videoram[0x1ff04/2] >> 10) * 0x400];
1105   table = &state->system32_videoram[(state->system32_videoram[0x1ff04/2] >> 10) * 0x400];
11311106
11321107   /* start with screen-wide X and Y scrolls */
1133   xscroll = (system32_videoram[0x1ff12/2 + 4 * bgnum] & 0x3ff) - (system32_videoram[0x1ff30/2 + 2 * bgnum] & 0x1ff);
1134   yscroll = (system32_videoram[0x1ff16/2 + 4 * bgnum] & 0x1ff);
1108   xscroll = (state->system32_videoram[0x1ff12/2 + 4 * bgnum] & 0x3ff) - (state->system32_videoram[0x1ff30/2 + 2 * bgnum] & 0x1ff);
1109   yscroll = (state->system32_videoram[0x1ff16/2 + 4 * bgnum] & 0x1ff);
11351110
11361111   /* render the tilemap into its bitmap */
11371112   for (y = cliprect->min_y; y <= cliprect->max_y; y++)
r10427r10428
12291204#if 0
12301205   if (rowscroll || rowselect)
12311206      popmessage("Scroll=%d Select=%d  Table@%06X",
1232         rowscroll, rowselect, (system32_videoram[0x1ff04/2] >> 10) * 0x800);
1207         rowscroll, rowselect, (state->system32_videoram[0x1ff04/2] >> 10) * 0x800);
12331208#endif
12341209}
12351210
r10427r10428
12431218
12441219static void update_tilemap_text(screen_device &screen, struct layer_info *layer, const rectangle *cliprect)
12451220{
1221   segas32_state *state = screen.machine->driver_data<segas32_state>();
12461222   bitmap_t *bitmap = layer->bitmap;
12471223   UINT16 *tilebase;
12481224   UINT16 *gfxbase;
r10427r10428
12521228   int flip;
12531229
12541230   /* determine if we're flipped */
1255   flip = (system32_videoram[0x1ff00/2] >> 9) & 1;
1231   flip = (state->system32_videoram[0x1ff00/2] >> 9) & 1;
12561232
12571233   /* determine the base of the tilemap and graphics data */
1258   tilebase = &system32_videoram[((system32_videoram[0x1ff5c/2] >> 4) & 0x1f) * 0x800];
1259   gfxbase = &system32_videoram[(system32_videoram[0x1ff5c/2] & 7) * 0x2000];
1234   tilebase = &state->system32_videoram[((state->system32_videoram[0x1ff5c/2] >> 4) & 0x1f) * 0x800];
1235   gfxbase = &state->system32_videoram[(state->system32_videoram[0x1ff5c/2] & 7) * 0x2000];
12601236
12611237   /* compute start/end tile numbers */
12621238   startx = cliprect->min_x / 8;
r10427r10428
14021378
14031379static void update_bitmap(screen_device &screen, struct layer_info *layer, const rectangle *cliprect)
14041380{
1381   segas32_state *state = screen.machine->driver_data<segas32_state>();
14051382   int clipenable, clipout, clips, clipdraw_start;
14061383   bitmap_t *bitmap = layer->bitmap;
14071384   struct extents_list clip_extents;
r10427r10428
14111388   int bpp;
14121389
14131390   /* configure the layer */
1414   bpp = (system32_videoram[0x1ff00/2] & 0x0800) ? 8 : 4;
1391   bpp = (state->system32_videoram[0x1ff00/2] & 0x0800) ? 8 : 4;
14151392
14161393   /* determine the clipping */
1417   clipenable = (system32_videoram[0x1ff02/2] >> 15) & 1;
1418   clipout = (system32_videoram[0x1ff02/2] >> 10) & 1;
1394   clipenable = (state->system32_videoram[0x1ff02/2] >> 15) & 1;
1395   clipout = (state->system32_videoram[0x1ff02/2] >> 10) & 1;
14191396   clips = 0x10;
14201397   clipdraw_start = compute_clipping_extents(screen, clipenable, clipout, clips, cliprect, &clip_extents);
14211398
14221399   /* determine x/y scroll */
1423   xscroll = system32_videoram[0x1ff88/2] & 0x1ff;
1424   yscroll = system32_videoram[0x1ff8a/2] & 0x1ff;
1425   color = (system32_videoram[0x1ff8c/2] << 4) & 0x1fff0 & ~((1 << bpp) - 1);
1400   xscroll = state->system32_videoram[0x1ff88/2] & 0x1ff;
1401   yscroll = state->system32_videoram[0x1ff8a/2] & 0x1ff;
1402   color = (state->system32_videoram[0x1ff8c/2] << 4) & 0x1fff0 & ~((1 << bpp) - 1);
14261403
14271404   /* loop over target rows */
14281405   for (y = cliprect->min_y; y <= cliprect->max_y; y++)
r10427r10428
14451422               /* 8bpp mode case */
14461423               if (bpp == 8)
14471424               {
1448                  UINT8 *src = (UINT8 *)&system32_videoram[512/2 * ((y + yscroll) & 0xff)];
1425                  UINT8 *src = (UINT8 *)&state->system32_videoram[512/2 * ((y + yscroll) & 0xff)];
14491426                  for (x = extents[0]; x < extents[1]; x++)
14501427                  {
14511428                     int effx = (x + xscroll) & 0x1ff;
r10427r10428
14591436               /* 4bpp mode case */
14601437               else
14611438               {
1462                  UINT16 *src = &system32_videoram[512/4 * ((y + yscroll) & 0x1ff)];
1439                  UINT16 *src = &state->system32_videoram[512/4 * ((y + yscroll) & 0x1ff)];
14631440                  for (x = extents[0]; x < extents[1]; x++)
14641441                  {
14651442                     int effx = (x + xscroll) & 0x1ff;
r10427r10428
15031480 *
15041481 *************************************/
15051482
1506static void update_background(struct layer_info *layer, const rectangle *cliprect)
1483static void update_background(segas32_state *state, struct layer_info *layer, const rectangle *cliprect)
15071484{
15081485   bitmap_t *bitmap = layer->bitmap;
15091486   int x, y;
r10427r10428
15141491      int color;
15151492
15161493      /* determine the color */
1517      if (system32_videoram[0x1ff5e/2] & 0x8000)
1518         color = (system32_videoram[0x1ff5e/2] & 0x1fff) + y;
1494      if (state->system32_videoram[0x1ff5e/2] & 0x8000)
1495         color = (state->system32_videoram[0x1ff5e/2] & 0x1fff) + y;
15191496      else
1520         color = system32_videoram[0x1ff5e/2] & 0x1e00;
1497         color = state->system32_videoram[0x1ff5e/2] & 0x1e00;
15211498
15221499      /* if the color doesn't match, fill */
15231500      if (dst[cliprect->min_x] != color)
r10427r10428
15291506
15301507static UINT8 update_tilemaps(screen_device &screen, const rectangle *cliprect)
15311508{
1532   int enable0 = !(system32_videoram[0x1ff02/2] & 0x0001) && !(system32_videoram[0x1ff8e/2] & 0x0002);
1533   int enable1 = !(system32_videoram[0x1ff02/2] & 0x0002) && !(system32_videoram[0x1ff8e/2] & 0x0004);
1534   int enable2 = !(system32_videoram[0x1ff02/2] & 0x0004) && !(system32_videoram[0x1ff8e/2] & 0x0008) && !(system32_videoram[0x1ff00/2] & 0x1000);
1535   int enable3 = !(system32_videoram[0x1ff02/2] & 0x0008) && !(system32_videoram[0x1ff8e/2] & 0x0010) && !(system32_videoram[0x1ff00/2] & 0x2000);
1536   int enablet = !(system32_videoram[0x1ff02/2] & 0x0010) && !(system32_videoram[0x1ff8e/2] & 0x0001);
1537   int enableb = !(system32_videoram[0x1ff02/2] & 0x0020) && !(system32_videoram[0x1ff8e/2] & 0x0020);
1509   segas32_state *state = screen.machine->driver_data<segas32_state>();
1510   int enable0 = !(state->system32_videoram[0x1ff02/2] & 0x0001) && !(state->system32_videoram[0x1ff8e/2] & 0x0002);
1511   int enable1 = !(state->system32_videoram[0x1ff02/2] & 0x0002) && !(state->system32_videoram[0x1ff8e/2] & 0x0004);
1512   int enable2 = !(state->system32_videoram[0x1ff02/2] & 0x0004) && !(state->system32_videoram[0x1ff8e/2] & 0x0008) && !(state->system32_videoram[0x1ff00/2] & 0x1000);
1513   int enable3 = !(state->system32_videoram[0x1ff02/2] & 0x0008) && !(state->system32_videoram[0x1ff8e/2] & 0x0010) && !(state->system32_videoram[0x1ff00/2] & 0x2000);
1514   int enablet = !(state->system32_videoram[0x1ff02/2] & 0x0010) && !(state->system32_videoram[0x1ff8e/2] & 0x0001);
1515   int enableb = !(state->system32_videoram[0x1ff02/2] & 0x0020) && !(state->system32_videoram[0x1ff8e/2] & 0x0020);
15381516
15391517   /* update any tilemaps */
15401518   if (enable0)
1541      update_tilemap_zoom(screen, &layer_data[MIXER_LAYER_NBG0], cliprect, 0);
1519      update_tilemap_zoom(screen, &state->layer_data[MIXER_LAYER_NBG0], cliprect, 0);
15421520   if (enable1)
1543      update_tilemap_zoom(screen, &layer_data[MIXER_LAYER_NBG1], cliprect, 1);
1521      update_tilemap_zoom(screen, &state->layer_data[MIXER_LAYER_NBG1], cliprect, 1);
15441522   if (enable2)
1545      update_tilemap_rowscroll(screen, &layer_data[MIXER_LAYER_NBG2], cliprect, 2);
1523      update_tilemap_rowscroll(screen, &state->layer_data[MIXER_LAYER_NBG2], cliprect, 2);
15461524   if (enable3)
1547      update_tilemap_rowscroll(screen, &layer_data[MIXER_LAYER_NBG3], cliprect, 3);
1525      update_tilemap_rowscroll(screen, &state->layer_data[MIXER_LAYER_NBG3], cliprect, 3);
15481526   if (enablet)
1549      update_tilemap_text(screen, &layer_data[MIXER_LAYER_TEXT], cliprect);
1527      update_tilemap_text(screen, &state->layer_data[MIXER_LAYER_TEXT], cliprect);
15501528   if (enableb)
1551      update_bitmap(screen, &layer_data[MIXER_LAYER_BITMAP], cliprect);
1552   update_background(&layer_data[MIXER_LAYER_BACKGROUND], cliprect);
1529      update_bitmap(screen, &state->layer_data[MIXER_LAYER_BITMAP], cliprect);
1530   update_background(state, &state->layer_data[MIXER_LAYER_BACKGROUND], cliprect);
15531531
15541532   return (enablet << 0) | (enable0 << 1) | (enable1 << 2) | (enable2 << 3) | (enable3 << 4) | (enableb << 5);
15551533}
r10427r10428
15621540 *
15631541 *************************************/
15641542
1565static void sprite_erase_buffer(void)
1543static void sprite_erase_buffer(segas32_state *state)
15661544{
15671545   /* erase the visible sprite buffer and clear the checksums */
1568   bitmap_fill(layer_data[MIXER_LAYER_SPRITES].bitmap, NULL, 0xffff);
1546   bitmap_fill(state->layer_data[MIXER_LAYER_SPRITES].bitmap, NULL, 0xffff);
15691547
15701548   /* for multi32, erase the other buffer as well */
1571   if (is_multi32)
1572      bitmap_fill(layer_data[MIXER_LAYER_MULTISPR].bitmap, NULL, 0xffff);
1549   if (state->is_multi32)
1550      bitmap_fill(state->layer_data[MIXER_LAYER_MULTISPR].bitmap, NULL, 0xffff);
15731551}
15741552
15751553
1576static void sprite_swap_buffers(void)
1554static void sprite_swap_buffers(segas32_state *state)
15771555{
15781556   /* swap between the two sprite buffers */
15791557   struct layer_info temp;
1580   temp = layer_data[MIXER_LAYER_SPRITES];
1581   layer_data[MIXER_LAYER_SPRITES] = layer_data[MIXER_LAYER_SPRITES_2];
1582   layer_data[MIXER_LAYER_SPRITES_2] = temp;
1558   temp = state->layer_data[MIXER_LAYER_SPRITES];
1559   state->layer_data[MIXER_LAYER_SPRITES] = state->layer_data[MIXER_LAYER_SPRITES_2];
1560   state->layer_data[MIXER_LAYER_SPRITES_2] = temp;
15831561
15841562   /* for multi32, swap the other buffer as well */
1585   if (is_multi32)
1563   if (state->is_multi32)
15861564   {
1587      temp = layer_data[MIXER_LAYER_MULTISPR];
1588      layer_data[MIXER_LAYER_MULTISPR] = layer_data[MIXER_LAYER_MULTISPR_2];
1589      layer_data[MIXER_LAYER_MULTISPR_2] = temp;
1565      temp = state->layer_data[MIXER_LAYER_MULTISPR];
1566      state->layer_data[MIXER_LAYER_MULTISPR] = state->layer_data[MIXER_LAYER_MULTISPR_2];
1567      state->layer_data[MIXER_LAYER_MULTISPR_2] = temp;
15901568   }
15911569
15921570   /* latch any pending info */
1593   memcpy(sprite_control_latched, sprite_control, sizeof(sprite_control_latched));
1571   memcpy(state->sprite_control_latched, state->sprite_control, sizeof(state->sprite_control_latched));
15941572}
15951573
15961574
r10427r10428
16931671
16941672static int draw_one_sprite(running_machine *machine, UINT16 *data, int xoffs, int yoffs, const rectangle *clipin, const rectangle *clipout)
16951673{
1674   segas32_state *state = machine->driver_data<segas32_state>();
16961675   static const int transparency_masks[4][4] =
16971676   {
16981677      { 0x7fff, 0x3fff, 0x1fff, 0x0fff },
r10427r10428
17011680      { 0x1fff, 0x0fff, 0x07ff, 0x03ff }
17021681   };
17031682
1704   bitmap_t *bitmap = layer_data[(!is_multi32 || !(data[3] & 0x0800)) ? MIXER_LAYER_SPRITES_2 : MIXER_LAYER_MULTISPR_2].bitmap;
1683   bitmap_t *bitmap = state->layer_data[(!state->is_multi32 || !(data[3] & 0x0800)) ? MIXER_LAYER_SPRITES_2 : MIXER_LAYER_MULTISPR_2].bitmap;
17051684   UINT8 numbanks = machine->region("gfx2")->bytes() / 0x400000;
17061685   const UINT32 *spritebase = (const UINT32 *)machine->region("gfx2")->base();
17071686
17081687   int indirect = data[0] & 0x2000;
17091688   int indlocal = data[0] & 0x1000;
1710   int shadow   = (data[0] & 0x0800) && (sprite_control_latched[0x0a/2] & 1);
1689   int shadow   = (data[0] & 0x0800) && (state->sprite_control_latched[0x0a/2] & 1);
17111690   int fromram  = data[0] & 0x0400;
17121691   int bpp8     = data[0] & 0x0200;
17131692   int transp   = (data[0] & 0x0100) ? 0 : (bpp8 ? 0xff : 0x0f);
r10427r10428
17191698   int adjustx  = (data[0] >> 0) & 3;
17201699   int srch     = (data[1] >> 8);
17211700   int srcw     = bpp8 ? (data[1] & 0x3f) : ((data[1] >> 1) & 0x3f);
1722   int bank     = is_multi32 ?
1701   int bank     = state->is_multi32 ?
17231702               ((data[3] & 0x2000) >> 13) | ((data[3] & 0x8000) >> 14) :
17241703               ((data[3] & 0x0800) >> 11) | ((data[3] & 0x4000) >> 13);
17251704   int dsth     = data[2] & 0x3ff;
r10427r10428
17401719      goto bail;
17411720
17421721   /* determine the transparency mask for pixels */
1743   transmask = transparency_masks[sprite_control_latched[0x08/2] & 3][sprite_control_latched[0x0a/2] & 3];
1722   transmask = transparency_masks[state->sprite_control_latched[0x08/2] & 3][state->sprite_control_latched[0x0a/2] & 3];
17441723   if (bpp8)
17451724      transmask &= 0xfff0;
17461725
17471726   /* create the local palette for the indirect case */
17481727   if (indirect)
17491728   {
1750      UINT16 *src = indlocal ? &data[8] : &system32_spriteram[8 * (data[7] & 0x1fff)];
1729      UINT16 *src = indlocal ? &data[8] : &state->system32_spriteram[8 * (data[7] & 0x1fff)];
17511730      for (x = 0; x < 16; x++)
1752         indtable[x] = (src[x] & (bpp8 ? 0xfff0 : 0xffff)) | ((sprite_control_latched[0x0a/2] & 1) ? 0x8000 : 0x0000);
1731         indtable[x] = (src[x] & (bpp8 ? 0xfff0 : 0xffff)) | ((state->sprite_control_latched[0x0a/2] & 1) ? 0x8000 : 0x0000);
17531732   }
17541733
17551734   /* clamp to within the memory region size */
17561735   if (fromram)
17571736   {
1758      spritedata = spriteram_32bit;
1737      spritedata = state->spriteram_32bit;
17591738      addrmask = (0x20000 / 4) - 1;
17601739   }
17611740   else
r10427r10428
18941873
18951874static void sprite_render_list(running_machine *machine)
18961875{
1876   segas32_state *state = machine->driver_data<segas32_state>();
18971877   rectangle outerclip, clipin, clipout;
18981878   int xoffs = 0, yoffs = 0;
18991879   int numentries = 0;
r10427r10428
19061886
19071887   /* compute the outer clip */
19081888   outerclip.min_x = outerclip.min_y = 0;
1909   outerclip.max_x = (sprite_control_latched[0x0c/2] & 1) ? 415 : 319;
1889   outerclip.max_x = (state->sprite_control_latched[0x0c/2] & 1) ? 415 : 319;
19101890   outerclip.max_y = 223;
19111891
19121892   /* initialize the cliprects */
r10427r10428
19181898   while (numentries++ < 0x20000/16)
19191899   {
19201900      /* top two bits are a command */
1921      sprite = &system32_spriteram[8 * (spritenum & 0x1fff)];
1901      sprite = &state->system32_spriteram[8 * (spritenum & 0x1fff)];
19221902      switch (sprite[0] >> 14)
19231903      {
19241904         /* command 0 = draw sprite */
r10427r10428
19821962 *
19831963 *************************************/
19841964
1985INLINE UINT8 compute_color_offsets(int which, int layerbit, int layerflag)
1965INLINE UINT8 compute_color_offsets(segas32_state *state,int which, int layerbit, int layerflag)
19861966{
1987   int mode = ((mixer_control[which][0x3e/2] & 0x8000) >> 14) | (layerbit & 1);
1967   int mode = ((state->mixer_control[which][0x3e/2] & 0x8000) >> 14) | (layerbit & 1);
19881968
19891969   switch (mode)
19901970   {
r10427r10428
20232003   }
20242004}
20252005
2026INLINE UINT16 *get_layer_scanline(int layer, int scanline)
2006INLINE UINT16 *get_layer_scanline(segas32_state *state, int layer, int scanline)
20272007{
2028   if (layer_data[layer].transparent[scanline])
2029      return (layer == MIXER_LAYER_SPRITES) ? solid_ffff : solid_0000;
2030   return BITMAP_ADDR16(layer_data[layer].bitmap, scanline, 0);
2008   if (state->layer_data[layer].transparent[scanline])
2009      return (layer == MIXER_LAYER_SPRITES) ? state->solid_ffff : state->solid_0000;
2010   return BITMAP_ADDR16(state->layer_data[layer].bitmap, scanline, 0);
20312011}
20322012
2033static void mix_all_layers(int which, int xoffs, bitmap_t *bitmap, const rectangle *cliprect, UINT8 enablemask)
2013static void mix_all_layers(segas32_state *state, int which, int xoffs, bitmap_t *bitmap, const rectangle *cliprect, UINT8 enablemask)
20342014{
2035   int blendenable = mixer_control[which][0x4e/2] & 0x0800;
2036   int blendfactor = (mixer_control[which][0x4e/2] >> 8) & 7;
2015   int blendenable = state->mixer_control[which][0x4e/2] & 0x0800;
2016   int blendfactor = (state->mixer_control[which][0x4e/2] >> 8) & 7;
20372017   struct mixer_layer_info
20382018   {
20392019      UINT16      palbase;         /* palette base from control reg */
r10427r10428
20572037   /* if we are the second monitor on multi32, swap in the proper sprite bank */
20582038   if (which == 1)
20592039   {
2060      temp_sprite_save = layer_data[MIXER_LAYER_SPRITES];
2061      layer_data[MIXER_LAYER_SPRITES] = layer_data[MIXER_LAYER_MULTISPR];
2040      temp_sprite_save = state->layer_data[MIXER_LAYER_SPRITES];
2041      state->layer_data[MIXER_LAYER_SPRITES] = state->layer_data[MIXER_LAYER_MULTISPR];
20622042   }
20632043
20642044   /* extract the RGB offsets */
2065   rgboffs[0][0] = (INT8)(mixer_control[which][0x40/2] << 2) >> 2;
2066   rgboffs[0][1] = (INT8)(mixer_control[which][0x42/2] << 2) >> 2;
2067   rgboffs[0][2] = (INT8)(mixer_control[which][0x44/2] << 2) >> 2;
2068   rgboffs[1][0] = (INT8)(mixer_control[which][0x46/2] << 2) >> 2;
2069   rgboffs[1][1] = (INT8)(mixer_control[which][0x48/2] << 2) >> 2;
2070   rgboffs[1][2] = (INT8)(mixer_control[which][0x4a/2] << 2) >> 2;
2045   rgboffs[0][0] = (INT8)(state->mixer_control[which][0x40/2] << 2) >> 2;
2046   rgboffs[0][1] = (INT8)(state->mixer_control[which][0x42/2] << 2) >> 2;
2047   rgboffs[0][2] = (INT8)(state->mixer_control[which][0x44/2] << 2) >> 2;
2048   rgboffs[1][0] = (INT8)(state->mixer_control[which][0x46/2] << 2) >> 2;
2049   rgboffs[1][1] = (INT8)(state->mixer_control[which][0x48/2] << 2) >> 2;
2050   rgboffs[1][2] = (INT8)(state->mixer_control[which][0x4a/2] << 2) >> 2;
20712051   rgboffs[2][0] = 0;
20722052   rgboffs[2][1] = 0;
20732053   rgboffs[2][2] = 0;
20742054
20752055   /* determine the sprite grouping parameters first */
2076   switch (mixer_control[which][0x4c/2] & 0x0f)
2056   switch (state->mixer_control[which][0x4c/2] & 0x0f)
20772057   {
20782058      default:
20792059      case 0x0:   sprgroup_shift = 14;   sprgroup_mask = 0x00;   sprgroup_or = 0x01;   break;
r10427r10428
20962076      case 0xe:   sprgroup_shift = 11;   sprgroup_mask = 0x07;   sprgroup_or = 0x00;   break;
20972077      case 0xf:   sprgroup_shift = 10;   sprgroup_mask = 0x0f;   sprgroup_or = 0x00;   break;
20982078   }
2099   sprshadowmask = (mixer_control[which][0x4c/2] & 0x04) ? 0x8000 : 0x0000;
2079   sprshadowmask = (state->mixer_control[which][0x4c/2] & 0x04) ? 0x8000 : 0x0000;
21002080   sprpixmask = ((1 << sprgroup_shift) - 1) & 0x3fff;
21012081   sprshadow = 0x7ffe & sprpixmask;
21022082
r10427r10428
21042084   numlayers = 0;
21052085   for (laynum = MIXER_LAYER_TEXT; laynum <= MIXER_LAYER_BITMAP; laynum++)
21062086   {
2107      int priority = mixer_control[which][0x20/2 + laynum] & 0x0f;
2087      int priority = state->mixer_control[which][0x20/2 + laynum] & 0x0f;
21082088      if ((enablemask & (1 << laynum)) && priority != 0)
21092089      {
21102090         layersort[numlayers].index = laynum;
21112091         layersort[numlayers].effpri = (priority << 3) | (6 - laynum);
2112         layersort[numlayers].palbase = (mixer_control[which][0x20/2 + laynum] & 0x00f0) << 6;
2113         layersort[numlayers].mixshift = (mixer_control[which][0x20/2 + laynum] >> 8) & 3;
2114         layersort[numlayers].blendmask = blendenable ? ((mixer_control[which][0x30/2 + laynum] >> 6) & 0xff) : 0;
2115         layersort[numlayers].sprblendmask = compute_sprite_blend(mixer_control[which][0x30/2 + laynum] & 0x3f);
2116         layersort[numlayers].coloroffs = compute_color_offsets(which, (mixer_control[which][0x3e/2] >> laynum) & 1, (mixer_control[which][0x30/2 + laynum] >> 14) & 1);
2092         layersort[numlayers].palbase = (state->mixer_control[which][0x20/2 + laynum] & 0x00f0) << 6;
2093         layersort[numlayers].mixshift = (state->mixer_control[which][0x20/2 + laynum] >> 8) & 3;
2094         layersort[numlayers].blendmask = blendenable ? ((state->mixer_control[which][0x30/2 + laynum] >> 6) & 0xff) : 0;
2095         layersort[numlayers].sprblendmask = compute_sprite_blend(state->mixer_control[which][0x30/2 + laynum] & 0x3f);
2096         layersort[numlayers].coloroffs = compute_color_offsets(state, which, (state->mixer_control[which][0x3e/2] >> laynum) & 1, (state->mixer_control[which][0x30/2 + laynum] >> 14) & 1);
21172097         numlayers++;
21182098      }
21192099   }
r10427r10428
21212101   /* extract info about the BACKGROUND layer */
21222102   layersort[numlayers].index = MIXER_LAYER_BACKGROUND;
21232103   layersort[numlayers].effpri = (1 << 3) | 0;
2124   layersort[numlayers].palbase = (mixer_control[which][0x2c/2] & 0x00f0) << 6;
2125   layersort[numlayers].mixshift = (mixer_control[which][0x2c/2] >> 8) & 3;
2104   layersort[numlayers].palbase = (state->mixer_control[which][0x2c/2] & 0x00f0) << 6;
2105   layersort[numlayers].mixshift = (state->mixer_control[which][0x2c/2] >> 8) & 3;
21262106   layersort[numlayers].blendmask = 0;
21272107   layersort[numlayers].sprblendmask = 0;
2128   layersort[numlayers].coloroffs = compute_color_offsets(which, (mixer_control[which][0x3e/2] >> 8) & 1, (mixer_control[which][0x3e/2] >> 14) & 1);
2108   layersort[numlayers].coloroffs = compute_color_offsets(state, which, (state->mixer_control[which][0x3e/2] >> 8) & 1, (state->mixer_control[which][0x3e/2] >> 14) & 1);
21292109   numlayers++;
21302110
21312111   /* now bubble sort the list by effective priority */
r10427r10428
21422122   for (groupnum = 0; groupnum <= sprgroup_mask; groupnum++)
21432123   {
21442124      int effgroup = sprgroup_or | groupnum;
2145      int priority = mixer_control[which][0x00/2 + effgroup] & 0x0f;
2125      int priority = state->mixer_control[which][0x00/2 + effgroup] & 0x0f;
21462126      int effpri = (priority << 3) | 7;
21472127      int sprindex = numlayers;
21482128      int dstnum = 0;
r10427r10428
21582138      /* build the sprite entry */
21592139      layerorder[groupnum][sprindex].index = MIXER_LAYER_SPRITES;
21602140      layerorder[groupnum][sprindex].effpri = effpri;
2161      if ((mixer_control[which][0x4c/2] & 3) != 3)
2162         layerorder[groupnum][sprindex].palbase = (mixer_control[which][0x00/2 + effgroup] & 0x00f0) << 6;
2141      if ((state->mixer_control[which][0x4c/2] & 3) != 3)
2142         layerorder[groupnum][sprindex].palbase = (state->mixer_control[which][0x00/2 + effgroup] & 0x00f0) << 6;
21632143      else
2164         layerorder[groupnum][sprindex].palbase = (mixer_control[which][0x4c/2] & 0x00f0) << 6;
2165      layerorder[groupnum][sprindex].mixshift = (mixer_control[which][0x00/2 + effgroup] >> 8) & 3;
2144         layerorder[groupnum][sprindex].palbase = (state->mixer_control[which][0x4c/2] & 0x00f0) << 6;
2145      layerorder[groupnum][sprindex].mixshift = (state->mixer_control[which][0x00/2 + effgroup] >> 8) & 3;
21662146      layerorder[groupnum][sprindex].blendmask = 0;
21672147      layerorder[groupnum][sprindex].sprblendmask = 0;
2168      layerorder[groupnum][sprindex].coloroffs = compute_color_offsets(which, (mixer_control[which][0x3e/2] >> 6) & 1, (mixer_control[which][0x4c/2] >> 15) & 1);
2148      layerorder[groupnum][sprindex].coloroffs = compute_color_offsets(state, which, (state->mixer_control[which][0x3e/2] >> 6) & 1, (state->mixer_control[which][0x4c/2] >> 15) & 1);
21692149   }
21702150/*
21712151{
r10427r10428
21812161
21822162   /* based on the sprite controller flip bits, the data is scanned to us in different */
21832163   /* directions; account for this */
2184   if (sprite_control_latched[0x04/2] & 1)
2164   if (state->sprite_control_latched[0x04/2] & 1)
21852165   {
21862166      sprx_start = cliprect->max_x;
21872167      sprdx = -1;
r10427r10428
21922172      sprdx = 1;
21932173   }
21942174
2195   if (sprite_control_latched[0x04/2] & 2)
2175   if (state->sprite_control_latched[0x04/2] & 2)
21962176   {
21972177      spry = cliprect->max_y;
21982178      sprdy = -1;
r10427r10428
22102190      UINT16 *layerbase[8];
22112191
22122192      /* get the starting address for each layer */
2213      layerbase[MIXER_LAYER_TEXT] = get_layer_scanline(MIXER_LAYER_TEXT, y);
2214      layerbase[MIXER_LAYER_NBG0] = get_layer_scanline(MIXER_LAYER_NBG0, y);
2215      layerbase[MIXER_LAYER_NBG1] = get_layer_scanline(MIXER_LAYER_NBG1, y);
2216      layerbase[MIXER_LAYER_NBG2] = get_layer_scanline(MIXER_LAYER_NBG2, y);
2217      layerbase[MIXER_LAYER_NBG3] = get_layer_scanline(MIXER_LAYER_NBG3, y);
2218      layerbase[MIXER_LAYER_BITMAP] = get_layer_scanline(MIXER_LAYER_BITMAP, y);
2219      layerbase[MIXER_LAYER_SPRITES] = get_layer_scanline(MIXER_LAYER_SPRITES, spry);
2220      layerbase[MIXER_LAYER_BACKGROUND] = get_layer_scanline(MIXER_LAYER_BACKGROUND, y);
2193      layerbase[MIXER_LAYER_TEXT] = get_layer_scanline(state, MIXER_LAYER_TEXT, y);
2194      layerbase[MIXER_LAYER_NBG0] = get_layer_scanline(state, MIXER_LAYER_NBG0, y);
2195      layerbase[MIXER_LAYER_NBG1] = get_layer_scanline(state, MIXER_LAYER_NBG1, y);
2196      layerbase[MIXER_LAYER_NBG2] = get_layer_scanline(state, MIXER_LAYER_NBG2, y);
2197      layerbase[MIXER_LAYER_NBG3] = get_layer_scanline(state, MIXER_LAYER_NBG3, y);
2198      layerbase[MIXER_LAYER_BITMAP] = get_layer_scanline(state, MIXER_LAYER_BITMAP, y);
2199      layerbase[MIXER_LAYER_SPRITES] = get_layer_scanline(state, MIXER_LAYER_SPRITES, spry);
2200      layerbase[MIXER_LAYER_BACKGROUND] = get_layer_scanline(state, MIXER_LAYER_BACKGROUND, y);
22212201
22222202      /* loop over columns */
22232203      for (x = cliprect->min_x, sprx = sprx_start; x <= cliprect->max_x; x++, sprx += sprdx)
r10427r10428
22622242         }
22632243
22642244         /* adjust the first pixel */
2265         firstpix = system32_paletteram[which][(first->palbase + ((firstpix >> first->mixshift) & 0xfff0) + (firstpix & 0x0f)) & 0x3fff];
2245         firstpix = state->system32_paletteram[which][(first->palbase + ((firstpix >> first->mixshift) & 0xfff0) + (firstpix & 0x0f)) & 0x3fff];
22662246
22672247         /* compute R, G, B */
22682248         rgbdelta = &rgboffs[first->coloroffs][0];
r10427r10428
23092289               (laynum != MIXER_LAYER_SPRITES || (first->sprblendmask & (1 << sprgroup))))
23102290            {
23112291               /* adjust the second pixel */
2312               secondpix = system32_paletteram[which][(second->palbase + ((secondpix >> second->mixshift) & 0xfff0) + (secondpix & 0x0f)) & 0x3fff];
2292               secondpix = state->system32_paletteram[which][(second->palbase + ((secondpix >> second->mixshift) & 0xfff0) + (secondpix & 0x0f)) & 0x3fff];
23132293
23142294               /* compute first RGB */
23152295               r *= 7 - blendfactor;
r10427r10428
23602340
23612341   /* if we are the second monitor on multi32, swap back the sprite layer */
23622342   if (which == 1)
2363      layer_data[MIXER_LAYER_SPRITES] = temp_sprite_save;
2343      state->layer_data[MIXER_LAYER_SPRITES] = temp_sprite_save;
23642344}
23652345
23662346
r10427r10428
23712351 *
23722352 *************************************/
23732353
2374static void print_mixer_data(int which)
2354static void print_mixer_data(segas32_state *state, int which)
23752355{
23762356   static int count = 0;
23772357   if (++count > 60 * 5)
23782358   {
23792359      mame_printf_debug("\n");
2380      mame_printf_debug("OP: %04X\n", system32_videoram[0x1ff8e/2]);
2360      mame_printf_debug("OP: %04X\n", state->system32_videoram[0x1ff8e/2]);
23812361      mame_printf_debug("SC: %04X %04X %04X %04X - %04X %04X %04X %04X\n",
2382         sprite_control_latched[0x00],
2383         sprite_control_latched[0x01],
2384         sprite_control_latched[0x02],
2385         sprite_control_latched[0x03],
2386         sprite_control_latched[0x04],
2387         sprite_control_latched[0x05],
2388         sprite_control_latched[0x06],
2389         sprite_control_latched[0x07]);
2362         state->sprite_control_latched[0x00],
2363         state->sprite_control_latched[0x01],
2364         state->sprite_control_latched[0x02],
2365         state->sprite_control_latched[0x03],
2366         state->sprite_control_latched[0x04],
2367         state->sprite_control_latched[0x05],
2368         state->sprite_control_latched[0x06],
2369         state->sprite_control_latched[0x07]);
23902370      mame_printf_debug("00: %04X %04X %04X %04X - %04X %04X %04X %04X - %04X %04X %04X %04X - %04X %04X %04X %04X\n",
2391         mixer_control[which][0x00],
2392         mixer_control[which][0x01],
2393         mixer_control[which][0x02],
2394         mixer_control[which][0x03],
2395         mixer_control[which][0x04],
2396         mixer_control[which][0x05],
2397         mixer_control[which][0x06],
2398         mixer_control[which][0x07],
2399         mixer_control[which][0x08],
2400         mixer_control[which][0x09],
2401         mixer_control[which][0x0a],
2402         mixer_control[which][0x0b],
2403         mixer_control[which][0x0c],
2404         mixer_control[which][0x0d],
2405         mixer_control[which][0x0e],
2406         mixer_control[which][0x0f]);
2371         state->mixer_control[which][0x00],
2372         state->mixer_control[which][0x01],
2373         state->mixer_control[which][0x02],
2374         state->mixer_control[which][0x03],
2375         state->mixer_control[which][0x04],
2376         state->mixer_control[which][0x05],
2377         state->mixer_control[which][0x06],
2378         state->mixer_control[which][0x07],
2379         state->mixer_control[which][0x08],
2380         state->mixer_control[which][0x09],
2381         state->mixer_control[which][0x0a],
2382         state->mixer_control[which][0x0b],
2383         state->mixer_control[which][0x0c],
2384         state->mixer_control[which][0x0d],
2385         state->mixer_control[which][0x0e],
2386         state->mixer_control[which][0x0f]);
24072387      mame_printf_debug("20: %04X %04X %04X %04X - %04X %04X %04X %04X - %04X %04X %04X %04X - %04X %04X %04X %04X\n",
2408         mixer_control[which][0x10],
2409         mixer_control[which][0x11],
2410         mixer_control[which][0x12],
2411         mixer_control[which][0x13],
2412         mixer_control[which][0x14],
2413         mixer_control[which][0x15],
2414         mixer_control[which][0x16],
2415         mixer_control[which][0x17],
2416         mixer_control[which][0x18],
2417         mixer_control[which][0x19],
2418         mixer_control[which][0x1a],
2419         mixer_control[which][0x1b],
2420         mixer_control[which][0x1c],
2421         mixer_control[which][0x1d],
2422         mixer_control[which][0x1e],
2423         mixer_control[which][0x1f]);
2388         state->mixer_control[which][0x10],
2389         state->mixer_control[which][0x11],
2390         state->mixer_control[which][0x12],
2391         state->mixer_control[which][0x13],
2392         state->mixer_control[which][0x14],
2393         state->mixer_control[which][0x15],
2394         state->mixer_control[which][0x16],
2395         state->mixer_control[which][0x17],
2396         state->mixer_control[which][0x18],
2397         state->mixer_control[which][0x19],
2398         state->mixer_control[which][0x1a],
2399         state->mixer_control[which][0x1b],
2400         state->mixer_control[which][0x1c],
2401         state->mixer_control[which][0x1d],
2402         state->mixer_control[which][0x1e],
2403         state->mixer_control[which][0x1f]);
24242404      mame_printf_debug("40: %04X %04X %04X %04X - %04X %04X %04X %04X - %04X %04X %04X %04X - %04X %04X %04X %04X\n",
2425         mixer_control[which][0x20],
2426         mixer_control[which][0x21],
2427         mixer_control[which][0x22],
2428         mixer_control[which][0x23],
2429         mixer_control[which][0x24],
2430         mixer_control[which][0x25],
2431         mixer_control[which][0x26],
2432         mixer_control[which][0x27],
2433         mixer_control[which][0x28],
2434         mixer_control[which][0x29],
2435         mixer_control[which][0x2a],
2436         mixer_control[which][0x2b],
2437         mixer_control[which][0x2c],
2438         mixer_control[which][0x2d],
2439         mixer_control[which][0x2e],
2440         mixer_control[which][0x2f]);
2405         state->mixer_control[which][0x20],
2406         state->mixer_control[which][0x21],
2407         state->mixer_control[which][0x22],
2408         state->mixer_control[which][0x23],
2409         state->mixer_control[which][0x24],
2410         state->mixer_control[which][0x25],
2411         state->mixer_control[which][0x26],
2412         state->mixer_control[which][0x27],
2413         state->mixer_control[which][0x28],
2414         state->mixer_control[which][0x29],
2415         state->mixer_control[which][0x2a],
2416         state->mixer_control[which][0x2b],
2417         state->mixer_control[which][0x2c],
2418         state->mixer_control[which][0x2d],
2419         state->mixer_control[which][0x2e],
2420         state->mixer_control[which][0x2f]);
24412421      count = 0;
24422422   }
24432423}
24442424
24452425VIDEO_UPDATE( system32 )
24462426{
2427   segas32_state *state = screen->machine->driver_data<segas32_state>();
24472428   UINT8 enablemask;
24482429
24492430   /* update the visible area */
2450   if (system32_videoram[0x1ff00/2] & 0x8000)
2431   if (state->system32_videoram[0x1ff00/2] & 0x8000)
24512432      screen->set_visible_area(0, 52*8-1, 0, 28*8-1);
24522433   else
24532434      screen->set_visible_area(0, 40*8-1, 0, 28*8-1);
24542435
24552436   /* if the display is off, punt */
2456   if (!system32_displayenable[0])
2437   if (!state->system32_displayenable[0])
24572438   {
24582439      bitmap_fill(bitmap, cliprect, get_black_pen(screen->machine));
24592440      return 0;
r10427r10428
24762457
24772458   /* do the mixing */
24782459   g_profiler.start(PROFILER_USER3);
2479   mix_all_layers(0, 0, bitmap, cliprect, enablemask);
2460   mix_all_layers(state, 0, 0, bitmap, cliprect, enablemask);
24802461   g_profiler.stop();
24812462
24822463   if (LOG_SPRITES && input_code_pressed(screen->machine, KEYCODE_L))
r10427r10428
24872468
24882469      for (y = visarea.min_y; y <= visarea.max_y; y++)
24892470      {
2490         UINT16 *src = get_layer_scanline(MIXER_LAYER_SPRITES, y);
2471         UINT16 *src = get_layer_scanline(state, MIXER_LAYER_SPRITES, y);
24912472         for (x = visarea.min_x; x <= visarea.max_x; x++)
24922473            fprintf(f, "%04X ", *src++);
24932474         fprintf(f, "\n");
r10427r10428
24972478      f = fopen("nbg0.txt", "w");
24982479      for (y = visarea.min_y; y <= visarea.max_y; y++)
24992480      {
2500         UINT16 *src = get_layer_scanline(MIXER_LAYER_NBG0, y);
2481         UINT16 *src = get_layer_scanline(state, MIXER_LAYER_NBG0, y);
25012482         for (x = visarea.min_x; x <= visarea.max_x; x++)
25022483            fprintf(f, "%04X ", *src++);
25032484         fprintf(f, "\n");
r10427r10428
25072488      f = fopen("nbg1.txt", "w");
25082489      for (y = visarea.min_y; y <= visarea.max_y; y++)
25092490      {
2510         UINT16 *src = get_layer_scanline(MIXER_LAYER_NBG1, y);
2491         UINT16 *src = get_layer_scanline(state, MIXER_LAYER_NBG1, y);
25112492         for (x = visarea.min_x; x <= visarea.max_x; x++)
25122493            fprintf(f, "%04X ", *src++);
25132494         fprintf(f, "\n");
r10427r10428
25172498      f = fopen("nbg2.txt", "w");
25182499      for (y = visarea.min_y; y <= visarea.max_y; y++)
25192500      {
2520         UINT16 *src = get_layer_scanline(MIXER_LAYER_NBG2, y);
2501         UINT16 *src = get_layer_scanline(state, MIXER_LAYER_NBG2, y);
25212502         for (x = visarea.min_x; x <= visarea.max_x; x++)
25222503            fprintf(f, "%04X ", *src++);
25232504         fprintf(f, "\n");
r10427r10428
25272508      f = fopen("nbg3.txt", "w");
25282509      for (y = visarea.min_y; y <= visarea.max_y; y++)
25292510      {
2530         UINT16 *src = get_layer_scanline(MIXER_LAYER_NBG3, y);
2511         UINT16 *src = get_layer_scanline(state, MIXER_LAYER_NBG3, y);
25312512         for (x = visarea.min_x; x <= visarea.max_x; x++)
25322513            fprintf(f, "%04X ", *src++);
25332514         fprintf(f, "\n");
r10427r10428
25402521   static const char *const layername[] = { "TEXT ", "NBG0 ", "NBG1 ", "NBG2 ", "NBG3 ", "BITMAP " };
25412522   char temp[100];
25422523   int count = 0, i;
2543   sprintf(temp, "ALPHA(%d):", (mixer_control[which][0x4e/2] >> 8) & 7);
2524   sprintf(temp, "ALPHA(%d):", (state->mixer_control[which][0x4e/2] >> 8) & 7);
25442525   for (i = 0; i < 6; i++)
25452526      if (enablemask & (1 << i))
2546         if ((mixer_control[which][0x30/2 + i] & 0x1010) == 0x1010)
2527         if ((state->mixer_control[which][0x30/2 + i] & 0x1010) == 0x1010)
25472528         {
25482529            count++;
25492530            strcat(temp, layername[i]);
r10427r10428
25682549//  if (showclip != -1)
25692550for (showclip = 0; showclip < 4; showclip++)
25702551   {
2571      int flip = (system32_videoram[0x1ff00/2] >> 9) & 1;
2572      int clips = (system32_videoram[0x1ff06/2] >> (4 * showclip)) & 0x0f;
2573      if (((system32_videoram[0x1ff02/2] >> (11 + showclip)) & 1) && clips)
2552      int flip = (state->system32_videoram[0x1ff00/2] >> 9) & 1;
2553      int clips = (state->system32_videoram[0x1ff06/2] >> (4 * showclip)) & 0x0f;
2554      if (((state->system32_videoram[0x1ff02/2] >> (11 + showclip)) & 1) && clips)
25742555      {
25752556         int i, x, y;
25762557         for (i = 0; i < 4; i++)
r10427r10428
25822563               pen_t white = get_white_pen(screen->machine);
25832564               if (!flip)
25842565               {
2585                  rect.min_x = system32_videoram[0x1ff60/2 + i * 4] & 0x1ff;
2586                  rect.min_y = system32_videoram[0x1ff62/2 + i * 4] & 0x0ff;
2587                  rect.max_x = (system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1;
2588                  rect.max_y = (system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1;
2566                  rect.min_x = state->system32_videoram[0x1ff60/2 + i * 4] & 0x1ff;
2567                  rect.min_y = state->system32_videoram[0x1ff62/2 + i * 4] & 0x0ff;
2568                  rect.max_x = (state->system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1;
2569                  rect.max_y = (state->system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1;
25892570               }
25902571               else
25912572               {
2592                  rect.max_x = (visarea.max_x + 1) - (system32_videoram[0x1ff60/2 + i * 4] & 0x1ff);
2593                  rect.max_y = (visarea.max_y + 1) - (system32_videoram[0x1ff62/2 + i * 4] & 0x0ff);
2594                  rect.min_x = (visarea.max_x + 1) - ((system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1);
2595                  rect.min_y = (visarea.max_y + 1) - ((system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1);
2573                  rect.max_x = (visarea.max_x + 1) - (state->system32_videoram[0x1ff60/2 + i * 4] & 0x1ff);
2574                  rect.max_y = (visarea.max_y + 1) - (state->system32_videoram[0x1ff62/2 + i * 4] & 0x0ff);
2575                  rect.min_x = (visarea.max_x + 1) - ((state->system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1);
2576                  rect.min_y = (visarea.max_y + 1) - ((state->system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1);
25962577               }
25972578               sect_rect(&rect, &screen->visible_area());
25982579
r10427r10428
26152596}
26162597#endif
26172598
2618   if (PRINTF_MIXER_DATA) print_mixer_data(0);
2599   if (PRINTF_MIXER_DATA) print_mixer_data(state, 0);
26192600   return 0;
26202601}
26212602
26222603
26232604VIDEO_UPDATE( multi32 )
26242605{
2606   segas32_state *state = screen->machine->driver_data<segas32_state>();
26252607   UINT8 enablemask;
26262608
26272609   device_t *left_screen  = screen->machine->device("lscreen");
26282610
26292611   /* update the visible area */
2630   if (system32_videoram[0x1ff00/2] & 0x8000)
2612   if (state->system32_videoram[0x1ff00/2] & 0x8000)
26312613      screen->set_visible_area(0, 52*8-1, 0, 28*8-1);
26322614   else
26332615      screen->set_visible_area(0, 40*8-1, 0, 28*8-1);
26342616
26352617   /* if the display is off, punt */
2636   if (!system32_displayenable[(screen == left_screen) ? 0 : 1])
2618   if (!state->system32_displayenable[(screen == left_screen) ? 0 : 1])
26372619   {
26382620      bitmap_fill(bitmap, cliprect, get_black_pen(screen->machine));
26392621      return 0;
r10427r10428
26562638
26572639   /* do the mixing */
26582640   g_profiler.start(PROFILER_USER3);
2659   mix_all_layers(((screen == left_screen) ? 0 : 1), 0, bitmap, cliprect, enablemask);
2641   mix_all_layers(state, ((screen == left_screen) ? 0 : 1), 0, bitmap, cliprect, enablemask);
26602642   g_profiler.stop();
26612643
26622644if (PRINTF_MIXER_DATA)
26632645{
2664   if (!input_code_pressed(screen->machine, KEYCODE_M)) print_mixer_data(0);
2665   else print_mixer_data(1);
2646   if (!input_code_pressed(screen->machine, KEYCODE_M)) print_mixer_data(state, 0);
2647   else print_mixer_data(state, 1);
26662648}
26672649   if (LOG_SPRITES && input_code_pressed(screen->machine, KEYCODE_L))
26682650   {
r10427r10428
26722654
26732655      for (y = visarea.min_y; y <= visarea.max_y; y++)
26742656      {
2675         UINT16 *src = get_layer_scanline(MIXER_LAYER_SPRITES, y);
2657         UINT16 *src = get_layer_scanline(state, MIXER_LAYER_SPRITES, y);
26762658         for (x = visarea.min_x; x <= visarea.max_x; x++)
26772659            fprintf(f, "%04X ", *src++);
26782660         fprintf(f, "\n");
src/mame/video/bfm_dm01.c
r10427r10428
3838#include "bfm_dm01.h"
3939// local prototypes ///////////////////////////////////////////////////////
4040
41extern void Scorpion2_SetSwitchState(int strobe, int data, int state);
42extern int  Scorpion2_GetSwitchState(int strobe, int data);
41extern void Scorpion2_SetSwitchState(running_machine *machine, int strobe, int data, int state);
42extern int  Scorpion2_GetSwitchState(running_machine *machine, int strobe, int data);
4343
4444// local vars /////////////////////////////////////////////////////////////
4545
r10427r10428
110110      if ( data & 8 )     busy = 0;
111111      else           busy = 1;
112112
113      Scorpion2_SetSwitchState(FEEDBACK_STROBE,FEEDBACK_DATA, busy?0:1);
113      Scorpion2_SetSwitchState(space->machine, FEEDBACK_STROBE,FEEDBACK_DATA, busy?0:1);
114114   }
115115}
116116
r10427r10428
247247   return data_avail;
248248}
249249
250void BFM_dm01_reset(void)
250void BFM_dm01_reset(running_machine *machine)
251251{
252252   busy     = 0;
253253   control  = 0;
254254   xcounter = 0;
255255   data_avail = 0;
256256
257   Scorpion2_SetSwitchState(FEEDBACK_STROBE,FEEDBACK_DATA, busy?0:1);
257   Scorpion2_SetSwitchState(machine, FEEDBACK_STROBE,FEEDBACK_DATA, busy?0:1);
258258}
src/mame/video/mystwarr.c
r10427r10428
1010#include "includes/konamigx.h"
1111#include "includes/mystwarr.h"
1212
13static int layer_colorbase[6];
14static int oinprion, cbparam;
15static int sprite_colorbase, sub1_colorbase, last_psac_colorbase, gametype;
16static int roz_enable, roz_rombank;
17static tilemap_t *ult_936_tilemap;
1813
1914// create a decoding buffer to hold decodable tiles so that the ROM test will pass by
2015// reading the original raw data
r10427r10428
6560
6661
6762// Mystic Warriors requires tile based blending.
68static void mystwarr_tile_callback(int layer, int *code, int *color, int *flags)
63static void mystwarr_tile_callback(running_machine *machine, int layer, int *code, int *color, int *flags)
6964{
70   if (layer==1) {if ((*code&0xff00)+(*color)==0x4101) cbparam++; else cbparam--;} //* water hack (TEMPORARY)
65   mystwarr_state *state = machine->driver_data<mystwarr_state>();
66   if (layer==1) {if ((*code&0xff00)+(*color)==0x4101) state->cbparam++; else state->cbparam--;} //* water hack (TEMPORARY)
7167
72   *color = layer_colorbase[layer] | (*color>>1 & 0x1f);
68   *color = state->layer_colorbase[layer] | (*color>>1 & 0x1f);
7369}
7470
7571// for games with 5bpp tile data
76static void game5bpp_tile_callback(int layer, int *code, int *color, int *flags)
72static void game5bpp_tile_callback(running_machine *machine, int layer, int *code, int *color, int *flags)
7773{
78   *color = layer_colorbase[layer] | (*color>>1 & 0x1f);
74   mystwarr_state *state = machine->driver_data<mystwarr_state>();
75   *color = state->layer_colorbase[layer] | (*color>>1 & 0x1f);
7976}
8077
8178// for games with 4bpp tile data
82static void game4bpp_tile_callback(int layer, int *code, int *color, int *flags)
79static void game4bpp_tile_callback(running_machine *machine, int layer, int *code, int *color, int *flags)
8380{
84   *color = layer_colorbase[layer] | (*color>>2 & 0x0f);
81   mystwarr_state *state = machine->driver_data<mystwarr_state>();
82   *color = state->layer_colorbase[layer] | (*color>>2 & 0x0f);
8583}
8684
87static void mystwarr_sprite_callback(int *code, int *color, int *priority)
85static void mystwarr_sprite_callback(running_machine *machine, int *code, int *color, int *priority)
8886{
87   mystwarr_state *state = machine->driver_data<mystwarr_state>();
8988   int c = *color;
9089
91   *color = sprite_colorbase | (c & 0x001f);
90   *color = state->sprite_colorbase | (c & 0x001f);
9291   *priority = c & 0x00f0;
9392}
9493
95static void metamrph_sprite_callback(int *code, int *color, int *priority)
94static void metamrph_sprite_callback(running_machine *machine, int *code, int *color, int *priority)
9695{
96   mystwarr_state *state = machine->driver_data<mystwarr_state>();
9797   int c = *color;
9898   int attr = c;
9999
100   c = (c & 0x1f) | sprite_colorbase;
100   c = (c & 0x1f) | state->sprite_colorbase;
101101
102102   // Bit8 & 9 are effect attributes. It is not known whether the effects are generated by external logic.
103103   if ((attr & 0x300) != 0x300)
r10427r10428
112112   }
113113}
114114
115static void gaiapols_sprite_callback(int *code, int *color, int *priority)
115static void gaiapols_sprite_callback(running_machine *machine, int *code, int *color, int *priority)
116116{
117   mystwarr_state *state = machine->driver_data<mystwarr_state>();
117118   int c = *color;
118119
119   *color = sprite_colorbase | (c>>4 & 0x20) | (c & 0x001f);
120   *color = state->sprite_colorbase | (c>>4 & 0x20) | (c & 0x001f);
120121   *priority = c & 0x00e0;
121122}
122123
123static void martchmp_sprite_callback(int *code, int *color, int *priority)
124static void martchmp_sprite_callback(running_machine *machine, int *code, int *color, int *priority)
124125{
126   mystwarr_state *state = machine->driver_data<mystwarr_state>();
125127   int c = *color;
126128
127129   // Bit8 & 9 are effect attributes. It is not known whether the effects are generated by external logic.
128130   if ((c & 0x3ff) == 0x11f)
129131      *color = K055555_FULLSHADOW;
130132   else
131      *color = sprite_colorbase | (c & 0x1f);
133      *color = state->sprite_colorbase | (c & 0x1f);
132134
133   if (oinprion & 0xf0)
134      *priority = cbparam;  // use PCU2 internal priority
135   if (state->oinprion & 0xf0)
136      *priority = state->cbparam;  // use PCU2 internal priority
135137   else
136138      *priority = c & 0xf0; // use color implied priority
137139}
r10427r10428
140142
141143static TILE_GET_INFO( get_gai_936_tile_info )
142144{
145   mystwarr_state *state = machine->driver_data<mystwarr_state>();
143146   int tileno, colour;
144147   UINT8 *ROM = machine->region("gfx4")->base();
145148   UINT8 *dat1 = ROM, *dat2 = ROM + 0x20000, *dat3 = ROM + 0x60000;
r10427r10428
153156
154157   if (dat2[tile_index] & 0x80) colour |= 0x10;
155158
156   colour |= sub1_colorbase << 4;
159   colour |= state->sub1_colorbase << 4;
157160
158161   SET_TILE_INFO(0, tileno, colour, 0);
159162}
160163
161164VIDEO_START(gaiapols)
162165{
166   mystwarr_state *state = machine->driver_data<mystwarr_state>();
163167   K055555_vh_start(machine);
164168   K054338_vh_start(machine);
165169
166   gametype = 0;
170   state->gametype = 0;
167171
168172   K056832_vh_start(machine, "gfx1", K056832_BPP_5, 0, NULL, game4bpp_tile_callback, 0);
169173
r10427r10428
181185   K053936_wraparound_enable(0, 1);
182186   K053936GP_set_offset(0, -10,  0); // floor tiles in demo loop2 (Elaine vs. boss)
183187
184   ult_936_tilemap = tilemap_create(machine, get_gai_936_tile_info, tilemap_scan_rows,  16, 16, 512, 512);
185   tilemap_set_transparent_pen(ult_936_tilemap, 0);
188   state->ult_936_tilemap = tilemap_create(machine, get_gai_936_tile_info, tilemap_scan_rows,  16, 16, 512, 512);
189   tilemap_set_transparent_pen(state->ult_936_tilemap, 0);
186190}
187191
188192static TILE_GET_INFO( get_ult_936_tile_info )
189193{
194   mystwarr_state *state = machine->driver_data<mystwarr_state>();
190195   int tileno, colour;
191196   UINT8 *ROM = machine->region("gfx4")->base();
192197   UINT8 *dat1 = ROM, *dat2 = ROM + 0x40000;
193198
194199   tileno = dat2[tile_index] | ((dat1[tile_index]&0x1f)<<8);
195200
196   colour = sub1_colorbase;
201   colour = state->sub1_colorbase;
197202
198203   SET_TILE_INFO(0, tileno, colour, (dat1[tile_index]&0x40) ? TILE_FLIPX : 0);
199204}
200205
201206VIDEO_START(dadandrn)
202207{
208   mystwarr_state *state = machine->driver_data<mystwarr_state>();
203209   K055555_vh_start(machine);
204210   K054338_vh_start(machine);
205211
206   gametype = 1;
212   state->gametype = 1;
207213
208214   K056832_vh_start(machine, "gfx1", K056832_BPP_5, 0, NULL, game5bpp_tile_callback, 0);
209215
r10427r10428
223229   K053936_wraparound_enable(0, 1);
224230   K053936GP_set_offset(0, -8, 0); // Brainy's laser
225231
226   ult_936_tilemap = tilemap_create(machine, get_ult_936_tile_info, tilemap_scan_rows,  16, 16, 512, 512);
227   tilemap_set_transparent_pen(ult_936_tilemap, 0);
232   state->ult_936_tilemap = tilemap_create(machine, get_ult_936_tile_info, tilemap_scan_rows,  16, 16, 512, 512);
233   tilemap_set_transparent_pen(state->ult_936_tilemap, 0);
228234}
229235
230236VIDEO_START(mystwarr)
231237{
238   mystwarr_state *state = machine->driver_data<mystwarr_state>();
232239   K055555_vh_start(machine);
233240   K054338_vh_start(machine);
234241
235   gametype = 0;
242   state->gametype = 0;
236243
237244   K056832_vh_start(machine, "gfx1", K056832_BPP_5, 0, NULL, mystwarr_tile_callback, 0);
238245
r10427r10428
247254   K056832_set_LayerOffset(2,  2-3, 0);
248255   K056832_set_LayerOffset(3,  3-3, 0);
249256
250   cbparam = 0;
257   state->cbparam = 0;
251258}
252259
253260VIDEO_START(metamrph)
254261{
262   mystwarr_state *state = machine->driver_data<mystwarr_state>();
255263   const char * rgn_250 = "gfx3";
256264
257   gametype = 0;
265   state->gametype = 0;
258266
259267   K055555_vh_start(machine);
260268   K054338_vh_start(machine);
r10427r10428
279287
280288VIDEO_START(viostorm)
281289{
282   gametype = 0;
290   mystwarr_state *state = machine->driver_data<mystwarr_state>();
291   state->gametype = 0;
283292
284293   K055555_vh_start(machine);
285294   K054338_vh_start(machine);
r10427r10428
300309
301310VIDEO_START(martchmp)
302311{
303   gametype = 0;
312   mystwarr_state *state = machine->driver_data<mystwarr_state>();
313   state->gametype = 0;
304314
305315   K055555_vh_start(machine);
306316   K054338_vh_start(machine);
r10427r10428
325335
326336VIDEO_UPDATE(mystwarr)
327337{
338   mystwarr_state *state = screen->machine->driver_data<mystwarr_state>();
328339   int i, old, blendmode=0;
329340
330   if (cbparam<0) cbparam=0; else if (cbparam>=32) blendmode=(1<<16|GXMIX_BLEND_FORCE)<<2; //* water hack (TEMPORARY)
341   if (state->cbparam<0) state->cbparam=0; else if (state->cbparam>=32) blendmode=(1<<16|GXMIX_BLEND_FORCE)<<2; //* water hack (TEMPORARY)
331342
332343   for (i = 0; i < 4; i++)
333344   {
334      old = layer_colorbase[i];
335      layer_colorbase[i] = K055555_get_palette_index(i)<<4;
336      if( old != layer_colorbase[i] ) K056832_mark_plane_dirty(i);
345      old = state->layer_colorbase[i];
346      state->layer_colorbase[i] = K055555_get_palette_index(i)<<4;
347      if( old != state->layer_colorbase[i] ) K056832_mark_plane_dirty(i);
337348   }
338349
339   sprite_colorbase = K055555_get_palette_index(4)<<5;
350   state->sprite_colorbase = K055555_get_palette_index(4)<<5;
340351
341352   konamigx_mixer(screen->machine, bitmap, cliprect, 0, 0, 0, 0, blendmode, 0, 0);
342353   return 0;
r10427r10428
344355
345356VIDEO_UPDATE(metamrph)
346357{
358   mystwarr_state *state = screen->machine->driver_data<mystwarr_state>();
347359   int i, old;
348360
349361   for (i = 0; i < 4; i++)
350362   {
351      old = layer_colorbase[i];
352      layer_colorbase[i] = K055555_get_palette_index(i)<<4;
353      if (old != layer_colorbase[i]) K056832_mark_plane_dirty(i);
363      old = state->layer_colorbase[i];
364      state->layer_colorbase[i] = K055555_get_palette_index(i)<<4;
365      if (old != state->layer_colorbase[i]) K056832_mark_plane_dirty(i);
354366   }
355367
356   sprite_colorbase = K055555_get_palette_index(4)<<4;
368   state->sprite_colorbase = K055555_get_palette_index(4)<<4;
357369
358370   konamigx_mixer(screen->machine, bitmap, cliprect, 0, GXSUB_K053250 | GXSUB_4BPP, 0, 0, 0, 0, 0);
359371   return 0;
r10427r10428
361373
362374VIDEO_UPDATE(martchmp)
363375{
376   mystwarr_state *state = screen->machine->driver_data<mystwarr_state>();
364377   int i, old, blendmode;
365378
366379   for (i = 0; i < 4; i++)
367380   {
368      old = layer_colorbase[i];
369      layer_colorbase[i] = K055555_get_palette_index(i)<<4;
370      if (old != layer_colorbase[i]) K056832_mark_plane_dirty(i);
381      old = state->layer_colorbase[i];
382      state->layer_colorbase[i] = K055555_get_palette_index(i)<<4;
383      if (old != state->layer_colorbase[i]) K056832_mark_plane_dirty(i);
371384   }
372385
373   sprite_colorbase = K055555_get_palette_index(4)<<5;
386   state->sprite_colorbase = K055555_get_palette_index(4)<<5;
374387
375   cbparam = K055555_read_register(K55_PRIINP_8);
376   oinprion = K055555_read_register(K55_OINPRI_ON);
388   state->cbparam = K055555_read_register(K55_PRIINP_8);
389   state->oinprion = K055555_read_register(K55_OINPRI_ON);
377390
378391   // not quite right
379   blendmode = (oinprion==0xef && K054338_read_register(K338_REG_PBLEND)) ? ((1<<16|GXMIX_BLEND_FORCE)<<2) : 0;
392   blendmode = (state->oinprion==0xef && K054338_read_register(K338_REG_PBLEND)) ? ((1<<16|GXMIX_BLEND_FORCE)<<2) : 0;
380393
381394   konamigx_mixer(screen->machine, bitmap, cliprect, 0, 0, 0, 0, blendmode, 0, 0);
382395   return 0;
r10427r10428
386399
387400WRITE16_HANDLER(ddd_053936_enable_w)
388401{
402   mystwarr_state *state = space->machine->driver_data<mystwarr_state>();
389403   if (ACCESSING_BITS_8_15)
390404   {
391      roz_enable = data & 0x0100;
392      roz_rombank = (data & 0xc000)>>14;
405      state->roz_enable = data & 0x0100;
406      state->roz_rombank = (data & 0xc000)>>14;
393407   }
394408}
395409
396410WRITE16_HANDLER(ddd_053936_clip_w)
397411{
398   static UINT16 clip;
412   mystwarr_state *state = space->machine->driver_data<mystwarr_state>();
399413   int old, clip_x, clip_y, size_x, size_y;
400414   int minx, maxx, miny, maxy;
401415
r10427r10428
405419   }
406420   else
407421   {
408      old = clip;
409      COMBINE_DATA(&clip);
410      if (clip != old)
422      old = state->clip;
423      COMBINE_DATA(&state->clip);
424      if (state->clip != old)
411425      {
412         clip_x = (clip & 0x003f) >> 0;
413         clip_y = (clip & 0x0fc0) >> 6;
414         size_x = (clip & 0x3000) >> 12;
415         size_y = (clip & 0xc000) >> 14;
426         clip_x = (state->clip & 0x003f) >> 0;
427         clip_y = (state->clip & 0x0fc0) >> 6;
428         size_x = (state->clip & 0x3000) >> 12;
429         size_y = (state->clip & 0xc000) >> 14;
416430
417431         switch (size_x)
418432         {
r10427r10428
471485// reference: 223db0 in gaiapolis (ROMs 32n, 29n, 26n)
472486READ16_HANDLER(gai_053936_tilerom_2_r)
473487{
488   mystwarr_state *state = space->machine->driver_data<mystwarr_state>();
474489   UINT8 *ROM = (UINT8 *)space->machine->region("gfx3")->base();
475490
476   offset += (roz_rombank * 0x100000);
491   offset += (state->roz_rombank * 0x100000);
477492
478493   return ROM[offset/2]<<8;
479494}
480495
481496READ16_HANDLER(ddd_053936_tilerom_2_r)
482497{
498   mystwarr_state *state = space->machine->driver_data<mystwarr_state>();
483499   UINT8 *ROM = (UINT8 *)space->machine->region("gfx3")->base();
484500
485   offset += (roz_rombank * 0x100000);
501   offset += (state->roz_rombank * 0x100000);
486502
487503   return ROM[offset]<<8;
488504}
489505
490506VIDEO_UPDATE(dadandrn) /* and gaiapols */
491507{
508   mystwarr_state *state = screen->machine->driver_data<mystwarr_state>();
492509   int i, newbase, dirty, rozmode;
493510
494   if (gametype == 0)
511   if (state->gametype == 0)
495512   {
496      sprite_colorbase = (K055555_get_palette_index(4)<<4)&0x7f;
513      state->sprite_colorbase = (K055555_get_palette_index(4)<<4)&0x7f;
497514      rozmode = GXSUB_4BPP;
498515   }
499516   else
500517   {
501      sprite_colorbase = (K055555_get_palette_index(4)<<3)&0x7f;
518      state->sprite_colorbase = (K055555_get_palette_index(4)<<3)&0x7f;
502519      rozmode = GXSUB_8BPP;
503520   }
504521
r10427r10428
507524      for (i=0; i<4; i++)
508525      {
509526         newbase = K055555_get_palette_index(i)<<4;
510         if (layer_colorbase[i] != newbase)
527         if (state->layer_colorbase[i] != newbase)
511528         {
512            layer_colorbase[i] = newbase;
529            state->layer_colorbase[i] = newbase;
513530            K056832_mark_plane_dirty(i);
514531         }
515532      }
r10427r10428
519536      for (dirty=0, i=0; i<4; i++)
520537      {
521538         newbase = K055555_get_palette_index(i)<<4;
522         if (layer_colorbase[i] != newbase)
539         if (state->layer_colorbase[i] != newbase)
523540         {
524            layer_colorbase[i] = newbase;
541            state->layer_colorbase[i] = newbase;
525542            dirty = 1;
526543         }
527544      }
r10427r10428
529546
530547   }
531548
532   last_psac_colorbase = sub1_colorbase;
533   sub1_colorbase = K055555_get_palette_index(5);
549   state->last_psac_colorbase = state->sub1_colorbase;
550   state->sub1_colorbase = K055555_get_palette_index(5);
534551
535   if (last_psac_colorbase != sub1_colorbase)
552   if (state->last_psac_colorbase != state->sub1_colorbase)
536553   {
537      tilemap_mark_all_tiles_dirty(ult_936_tilemap);
554      tilemap_mark_all_tiles_dirty(state->ult_936_tilemap);
538555
539556      if (MW_VERBOSE)
540557         popmessage("K053936: PSAC colorbase changed");
541558   }
542559
543   konamigx_mixer(screen->machine, bitmap, cliprect, (roz_enable) ? ult_936_tilemap : 0, rozmode, 0, 0, 0, 0, 0);
560   konamigx_mixer(screen->machine, bitmap, cliprect, (state->roz_enable) ? state->ult_936_tilemap : 0, rozmode, 0, 0, 0, 0, 0);
544561   return 0;
545562}
src/mame/video/bfm_dm01.h
r10427r10428
1010
1111INTERRUPT_GEN( bfm_dm01_vbl );
1212
13void BFM_dm01_reset(void);
13void BFM_dm01_reset(running_machine *machine);
1414
1515void BFM_dm01_writedata(running_machine *machine,UINT8 data);
1616
src/mame/video/djmain.c
r10427r10428
1010#define NUM_SPRITES   (0x800 / 16)
1111#define NUM_LAYERS   2
1212
13UINT32 *djmain_obj_ram;
1413
1514
1615static void draw_sprites(running_machine* machine, bitmap_t *bitmap, const rectangle *cliprect)
1716{
17   djmain_state *state = machine->driver_data<djmain_state>();
1818   device_t *k055555 = machine->device("k055555");
1919   int offs, pri_code;
2020   int sortedlist[NUM_SPRITES];
r10427r10428
2727   /* prebuild a sorted table */
2828   for (offs = 0; offs < NUM_SPRITES * 4; offs += 4)
2929   {
30      if (djmain_obj_ram[offs] & 0x00008000)
30      if (state->obj_ram[offs] & 0x00008000)
3131      {
32         if (djmain_obj_ram[offs] & 0x80000000)
32         if (state->obj_ram[offs] & 0x80000000)
3333            continue;
3434
35         pri_code = djmain_obj_ram[offs] & (NUM_SPRITES - 1);
35         pri_code = state->obj_ram[offs] & (NUM_SPRITES - 1);
3636         sortedlist[pri_code] = offs;
3737      }
3838   }
r10427r10428
5353      offs = sortedlist[pri_code];
5454      if (offs == -1) continue;
5555
56      code = djmain_obj_ram[offs] >> 16;
57      flipx = (djmain_obj_ram[offs] >> 10) & 1;
58      flipy = (djmain_obj_ram[offs] >> 11) & 1;
59      size = sizetab[(djmain_obj_ram[offs] >> 8) & 3];
56      code = state->obj_ram[offs] >> 16;
57      flipx = (state->obj_ram[offs] >> 10) & 1;
58      flipy = (state->obj_ram[offs] >> 11) & 1;
59      size = sizetab[(state->obj_ram[offs] >> 8) & 3];
6060
61      ox = (INT16)(djmain_obj_ram[offs + 1] & 0xffff);
62      oy = (INT16)(djmain_obj_ram[offs + 1] >> 16);
61      ox = (INT16)(state->obj_ram[offs + 1] & 0xffff);
62      oy = (INT16)(state->obj_ram[offs + 1] >> 16);
6363
64      xscale = djmain_obj_ram[offs + 2] >> 16;
65      yscale = djmain_obj_ram[offs + 2] & 0xffff;
64      xscale = state->obj_ram[offs + 2] >> 16;
65      yscale = state->obj_ram[offs + 2] & 0xffff;
6666
6767      if (!xscale || !yscale)
6868         continue;
r10427r10428
7272      ox -= (size * xscale) >> 13;
7373      oy -= (size * yscale) >> 13;
7474
75      color = (djmain_obj_ram[offs + 3] >> 16) & 15;
75      color = (state->obj_ram[offs + 3] >> 16) & 15;
7676
7777      for (x = 0; x < size; x++)
7878         for (y = 0; y < size; y++)
src/mame/video/konamigx.c
r10427r10428
7272static bitmap_t *gxtype1_roz_dstbitmap2;
7373static rectangle gxtype1_roz_dstbitmapclip;
7474
75static void (*game_tile_callback)(int layer, int *code, int *color, int *flags);
75static void (*game_tile_callback)(running_machine *machine, int layer, int *code, int *color, int *flags);
7676
7777// Localized K053936/ROZ+
7878#define K053936_MAX_CHIPS 2
r10427r10428
923923   return(c18 | op);
924924}
925925
926static void konamigx_type2_sprite_callback(int *code, int *color, int *priority)
926static void konamigx_type2_sprite_callback(running_machine *machine, int *code, int *color, int *priority)
927927{
928928   int num = *code;
929929   int c18 = *color;
r10427r10428
934934   *priority = K055555GX_decode_inpri(c18);
935935}
936936
937static void konamigx_dragoonj_sprite_callback(int *code, int *color, int *priority)
937static void konamigx_dragoonj_sprite_callback(running_machine *machine, int *code, int *color, int *priority)
938938{
939939   int num, op, pri, c18;
940940
r10427r10428
952952   *color = K055555GX_decode_objcolor(c18);
953953}
954954
955static void konamigx_salmndr2_sprite_callback(int *code, int *color, int *priority)
955static void konamigx_salmndr2_sprite_callback(running_machine *machine, int *code, int *color, int *priority)
956956{
957957   int num, op, pri, c18;
958958
r10427r10428
970970   *color = K055555GX_decode_objcolor(c18);
971971}
972972
973static void konamigx_le2_sprite_callback(int *code, int *color, int *priority)
973static void konamigx_le2_sprite_callback(running_machine *machine, int *code, int *color, int *priority)
974974{
975975   int num, op, pri;
976976
r10427r10428
11161116// mirrored K053247 and K054338 settings
11171117UINT16 *K053247_ram;
11181118static gfx_element *K053247_gfx;
1119static void (*K053247_callback)(int *code,int *color,int *priority);
1119static void (*K053247_callback)(running_machine *machine, int *code,int *color,int *priority);
11201120static int K053247_dx, K053247_dy;
11211121
11221122static int *K054338_shdRGB;
r10427r10428
13621362      color = k = gx_spriteram[offs+6];
13631363      l     = gx_spriteram[offs+7];
13641364
1365      (*K053247_callback)(&code, &color, &pri);
1365      (*K053247_callback)(machine, &code, &color, &pri);
13661366
13671367      /*
13681368            shadow = shadow code
r10427r10428
19551955   SET_TILE_INFO(0, tileno, colour, flip);
19561956}
19571957
1958static void konamigx_type2_tile_callback(int layer, int *code, int *color, int *flags)
1958static void konamigx_type2_tile_callback(running_machine *machine, int layer, int *code, int *color, int *flags)
19591959{
19601960   int d = *code;
19611961
r10427r10428
19631963   K055555GX_decode_vmixcolor(layer, color);
19641964}
19651965
1966static void konamigx_alpha_tile_callback(int layer, int *code, int *color, int *flags)
1966static void konamigx_alpha_tile_callback(running_machine *machine, int layer, int *code, int *color, int *flags)
19671967{
19681968   int mixcode;
19691969   int d = *code;
src/mame/video/pcktgal.c
r10427r10428
11#include "emu.h"
22#include "includes/pcktgal.h"
33
4static tilemap_t *bg_tilemap;
54
65PALETTE_INIT( pcktgal )
76{
r10427r10428
3635   pcktgal_state *state = space->machine->driver_data<pcktgal_state>();
3736   UINT8 *videoram = state->videoram;
3837   videoram[offset] = data;
39   tilemap_mark_tile_dirty(bg_tilemap, offset / 2);
38   tilemap_mark_tile_dirty(state->bg_tilemap, offset / 2);
4039}
4140
4241WRITE8_HANDLER( pcktgal_flipscreen_w )
r10427r10428
6059
6160VIDEO_START( pcktgal )
6261{
63   bg_tilemap = tilemap_create(machine, get_bg_tile_info, tilemap_scan_rows,
62   pcktgal_state *state = machine->driver_data<pcktgal_state>();
63   state->bg_tilemap = tilemap_create(machine, get_bg_tile_info, tilemap_scan_rows,
6464       8, 8, 32, 32);
6565}
6666
r10427r10428
9999
100100VIDEO_UPDATE( pcktgal )
101101{
102   tilemap_draw(bitmap, cliprect, bg_tilemap, 0, 0);
102   pcktgal_state *state = screen->machine->driver_data<pcktgal_state>();
103   tilemap_draw(bitmap, cliprect, state->bg_tilemap, 0, 0);
103104   draw_sprites(screen->machine, bitmap, cliprect);
104105   return 0;
105106}
src/mame/video/suprloco.c
r10427r10428
99#include "emu.h"
1010#include "includes/suprloco.h"
1111
12UINT8 *suprloco_videoram;
13UINT8 *suprloco_scrollram;
1412
15static tilemap_t *bg_tilemap;
16static int control;
1713
1814#define SPR_Y_TOP      0
1915#define SPR_Y_BOTTOM   1
r10427r10428
8076
8177static TILE_GET_INFO( get_tile_info )
8278{
83   UINT8 attr = suprloco_videoram[2*tile_index+1];
79   suprloco_state *state = machine->driver_data<suprloco_state>();
80   UINT8 attr = state->videoram[2*tile_index+1];
8481   SET_TILE_INFO(
8582         0,
86         suprloco_videoram[2*tile_index] | ((attr & 0x03) << 8),
83         state->videoram[2*tile_index] | ((attr & 0x03) << 8),
8784         (attr & 0x1c) >> 2,
8885         0);
8986   tileinfo->category = (attr & 0x20) >> 5;
r10427r10428
9996
10097VIDEO_START( suprloco )
10198{
102   bg_tilemap = tilemap_create(machine, get_tile_info,tilemap_scan_rows,8,8,32,32);
99   suprloco_state *state = machine->driver_data<suprloco_state>();
100   state->bg_tilemap = tilemap_create(machine, get_tile_info,tilemap_scan_rows,8,8,32,32);
103101
104   tilemap_set_scroll_rows(bg_tilemap,32);
102   tilemap_set_scroll_rows(state->bg_tilemap,32);
105103}
106104
107105
r10427r10428
114112
115113WRITE8_HANDLER( suprloco_videoram_w )
116114{
117   suprloco_videoram[offset] = data;
118   tilemap_mark_tile_dirty(bg_tilemap,offset/2);
115   suprloco_state *state = space->machine->driver_data<suprloco_state>();
116   state->videoram[offset] = data;
117   tilemap_mark_tile_dirty(state->bg_tilemap,offset/2);
119118}
120119
121120WRITE8_HANDLER( suprloco_scrollram_w )
122121{
122   suprloco_state *state = space->machine->driver_data<suprloco_state>();
123123   int adj = flip_screen_get(space->machine) ? -8 : 8;
124124
125   suprloco_scrollram[offset] = data;
126   tilemap_set_scrollx(bg_tilemap,offset, data - adj);
125   state->scrollram[offset] = data;
126   tilemap_set_scrollx(state->bg_tilemap,offset, data - adj);
127127}
128128
129129WRITE8_HANDLER( suprloco_control_w )
130130{
131   suprloco_state *state = space->machine->driver_data<suprloco_state>();
131132   /* There is probably a palette select in here */
132133
133134   /* Bit 0   - coin counter A */
r10427r10428
138139   /* Bit 6   - probably unused */
139140   /* Bit 7   - flip screen */
140141
141   if ((control & 0x10) != (data & 0x10))
142   if ((state->control & 0x10) != (data & 0x10))
142143   {
143144      /*logerror("Bit 4 = %d\n", (data >> 4) & 1); */
144145   }
r10427r10428
148149
149150   flip_screen_set(space->machine, data & 0x80);
150151
151   control = data;
152   state->control = data;
152153}
153154
154155
155156READ8_HANDLER( suprloco_control_r )
156157{
157   return control;
158   suprloco_state *state = space->machine->driver_data<suprloco_state>();
159   return state->control;
158160}
159161
160162
r10427r10428
179181
180182static void draw_sprite(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int spr_number)
181183{
184   suprloco_state *state = machine->driver_data<suprloco_state>();
182185   int flip = flip_screen_get(machine);
183186   int sx,sy,col,row,height,src,adjy,dy;
184187   UINT8 *spr_reg;
r10427r10428
193196   skip = spr_reg[SPR_SKIP_LO] + (spr_reg[SPR_SKIP_HI] << 8);
194197
195198   height      = spr_reg[SPR_Y_BOTTOM] - spr_reg[SPR_Y_TOP];
196   pen_base = 0x100 + 0x10 * (spr_reg[SPR_COL]&0x03) + ((control & 0x20)?0x100:0);
199   pen_base = 0x100 + 0x10 * (spr_reg[SPR_COL]&0x03) + ((state->control & 0x20)?0x100:0);
197200   sx = spr_reg[SPR_X];
198201   sy = spr_reg[SPR_Y_TOP] + 1;
199202
r10427r10428
267270
268271VIDEO_UPDATE( suprloco )
269272{
270   tilemap_draw(bitmap,cliprect,bg_tilemap,0,0);
273   suprloco_state *state = screen->machine->driver_data<suprloco_state>();
274   tilemap_draw(bitmap,cliprect,state->bg_tilemap,0,0);
271275   draw_sprites(screen->machine,bitmap,cliprect);
272   tilemap_draw(bitmap,cliprect,bg_tilemap,1,0);
276   tilemap_draw(bitmap,cliprect,state->bg_tilemap,1,0);
273277   return 0;
274278}
src/mame/video/atarigx2.c
r10427r10428
2020
2121
2222#include "emu.h"
23#include "machine/atarigen.h"
23#include "video/atarirle.h"
2424#include "includes/atarigx2.h"
2525
2626
r10427r10428
6969
7070VIDEO_START( atarigx2 )
7171{
72   static const atarirle_desc modesc =
73   {
74      "gfx3",      /* region where the GFX data lives */
75      256,      /* number of entries in sprite RAM */
76      0,         /* left clip coordinate */
77      0,         /* right clip coordinate */
78
79      0x000,      /* base palette entry */
80      0x400,      /* maximum number of colors */
81
82      {{ 0x7fff,0,0,0,0,0,0,0 }},   /* mask for the code index */
83      {{ 0,0x03f0,0,0,0,0,0,0 }},   /* mask for the color */
84      {{ 0,0,0xffc0,0,0,0,0,0 }},   /* mask for the X position */
85      {{ 0,0,0,0xffc0,0,0,0,0 }},   /* mask for the Y position */
86      {{ 0,0,0,0,0xffff,0,0,0 }},   /* mask for the scale factor */
87      {{ 0x8000,0,0,0,0,0,0,0 }},   /* mask for the horizontal flip */
88      {{ 0,0,0,0,0,0,0x00ff,0 }},   /* mask for the order */
89      {{ 0,0x0e00,0,0,0,0,0,0 }},   /* mask for the priority */
90      {{ 0 }}                  /* mask for the VRAM target */
91   };
9272   atarigx2_state *state = machine->driver_data<atarigx2_state>();
93   atarirle_desc adjusted_modesc = modesc;
94   int i;
9573
9674   /* blend the playfields and free the temporary one */
9775   atarigen_blend_gfx(machine, 0, 2, 0x0f, 0x30);
r10427r10428
10078   state->playfield_tilemap = tilemap_create(machine, get_playfield_tile_info, atarigx2_playfield_scan,  8,8, 128,64);
10179
10280   /* initialize the motion objects */
103   adjusted_modesc.palettebase = state->motion_object_base;
104   for (i = 0; i < 8; i++)
105      adjusted_modesc.colormask.data[i] &= state->motion_object_mask;
106   atarirle_init(machine, 0, &adjusted_modesc);
81   state->rle = machine->device("rle");
10782
10883   /* initialize the alphanumerics */
10984   state->alpha_tilemap = tilemap_create(machine, get_alpha_tile_info, tilemap_scan_rows,  8,8, 64,32);
r10427r10428
221196
222197   /* copy the motion objects on top */
223198   {
224      bitmap_t *mo_bitmap = atarirle_get_vram(0, 0);
199      bitmap_t *mo_bitmap = atarirle_get_vram(state->rle, 0);
225200      int left   = cliprect->min_x;
226201      int top      = cliprect->min_y;
227202      int right   = cliprect->max_x + 1;
r10427r10428
244219   tilemap_draw(bitmap, cliprect, state->alpha_tilemap, 0, 0);
245220   return 0;
246221}
222
223VIDEO_EOF( atarigx2 )
224{
225   atarigx2_state *state = machine->driver_data<atarigx2_state>();
226
227   atarirle_eof(state->rle);
228}
src/mame/video/vulgus.c
r10427r10428
99#include "emu.h"
1010#include "includes/vulgus.h"
1111
12UINT8 *vulgus_fgvideoram,*vulgus_bgvideoram;
13UINT8 *vulgus_scroll_low,*vulgus_scroll_high;
1412
15static int vulgus_palette_bank;
16static tilemap_t *fg_tilemap, *bg_tilemap;
17
18
1913/***************************************************************************
2014
2115  Convert the color PROMs into a more useable format.
r10427r10428
8478
8579static TILE_GET_INFO( get_fg_tile_info )
8680{
81   vulgus_state *state = machine->driver_data<vulgus_state>();
8782   int code, color;
8883
89   code = vulgus_fgvideoram[tile_index];
90   color = vulgus_fgvideoram[tile_index + 0x400];
84   code = state->fgvideoram[tile_index];
85   color = state->fgvideoram[tile_index + 0x400];
9186   SET_TILE_INFO(
9287         0,
9388         code + ((color & 0x80) << 1),
r10427r10428
9893
9994static TILE_GET_INFO( get_bg_tile_info )
10095{
96   vulgus_state *state = machine->driver_data<vulgus_state>();
10197   int code, color;
10298
103   code = vulgus_bgvideoram[tile_index];
104   color = vulgus_bgvideoram[tile_index + 0x400];
99   code = state->bgvideoram[tile_index];
100   color = state->bgvideoram[tile_index + 0x400];
105101   SET_TILE_INFO(
106102         1,
107103         code + ((color & 0x80) << 1),
108         (color & 0x1f) + (0x20 * vulgus_palette_bank),
104         (color & 0x1f) + (0x20 * state->palette_bank),
109105         TILE_FLIPYX((color & 0x60) >> 5));
110106}
111107
r10427r10428
118114
119115VIDEO_START( vulgus )
120116{
121   fg_tilemap = tilemap_create(machine, get_fg_tile_info,tilemap_scan_rows, 8, 8,32,32);
122   bg_tilemap = tilemap_create(machine, get_bg_tile_info,tilemap_scan_cols,16,16,32,32);
117   vulgus_state *state = machine->driver_data<vulgus_state>();
118   state->fg_tilemap = tilemap_create(machine, get_fg_tile_info,tilemap_scan_rows, 8, 8,32,32);
119   state->bg_tilemap = tilemap_create(machine, get_bg_tile_info,tilemap_scan_cols,16,16,32,32);
123120
124   colortable_configure_tilemap_groups(machine->colortable, fg_tilemap, machine->gfx[0], 47);
121   colortable_configure_tilemap_groups(machine->colortable, state->fg_tilemap, machine->gfx[0], 47);
125122}
126123
127124
r10427r10428
133130
134131WRITE8_HANDLER( vulgus_fgvideoram_w )
135132{
136   vulgus_fgvideoram[offset] = data;
137   tilemap_mark_tile_dirty(fg_tilemap,offset & 0x3ff);
133   vulgus_state *state = space->machine->driver_data<vulgus_state>();
134   state->fgvideoram[offset] = data;
135   tilemap_mark_tile_dirty(state->fg_tilemap,offset & 0x3ff);
138136}
139137
140138WRITE8_HANDLER( vulgus_bgvideoram_w )
141139{
142   vulgus_bgvideoram[offset] = data;
143   tilemap_mark_tile_dirty(bg_tilemap,offset & 0x3ff);
140   vulgus_state *state = space->machine->driver_data<vulgus_state>();
141   state->bgvideoram[offset] = data;
142   tilemap_mark_tile_dirty(state->bg_tilemap,offset & 0x3ff);
144143}
145144
146145
r10427r10428
157156
158157WRITE8_HANDLER( vulgus_palette_bank_w )
159158{
160   if (vulgus_palette_bank != (data & 3))
159   vulgus_state *state = space->machine->driver_data<vulgus_state>();
160   if (state->palette_bank != (data & 3))
161161   {
162      vulgus_palette_bank = data & 3;
163      tilemap_mark_all_tiles_dirty(bg_tilemap);
162      state->palette_bank = data & 3;
163      tilemap_mark_all_tiles_dirty(state->bg_tilemap);
164164   }
165165}
166166
r10427r10428
218218
219219VIDEO_UPDATE( vulgus )
220220{
221   tilemap_set_scrollx(bg_tilemap, 0, vulgus_scroll_low[1] + 256 * vulgus_scroll_high[1]);
222   tilemap_set_scrolly(bg_tilemap, 0, vulgus_scroll_low[0] + 256 * vulgus_scroll_high[0]);
221   vulgus_state *state = screen->machine->driver_data<vulgus_state>();
222   tilemap_set_scrollx(state->bg_tilemap, 0, state->scroll_low[1] + 256 * state->scroll_high[1]);
223   tilemap_set_scrolly(state->bg_tilemap, 0, state->scroll_low[0] + 256 * state->scroll_high[0]);
223224
224   tilemap_draw(bitmap,cliprect,bg_tilemap,0,0);
225   tilemap_draw(bitmap,cliprect,state->bg_tilemap,0,0);
225226   draw_sprites(screen->machine, bitmap,cliprect);
226   tilemap_draw(bitmap,cliprect,fg_tilemap,0,0);
227   tilemap_draw(bitmap,cliprect,state->fg_tilemap,0,0);
227228   return 0;
228229}
src/mame/video/twin16.c
r10427r10428
1515#include "emu.h"
1616#include "includes/twin16.h"
1717
18static UINT16 twin16_sprite_buffer[0x800];
1918static TIMER_CALLBACK( twin16_sprite_tick );
20static emu_timer *twin16_sprite_timer;
21static int twin16_sprite_busy;
2219
23static int need_process_spriteram;
24static UINT16 gfx_bank;
25static UINT16 scrollx[3], scrolly[3];
26static UINT16 video_register;
2720
2821enum
2922{
r10427r10428
4639   TWIN16_SPRITE_CAST_SHADOW   = 0x20
4740};
4841
49static tilemap_t *text_tilemap;
5042
5143WRITE16_HANDLER( twin16_text_ram_w )
5244{
53   COMBINE_DATA(&twin16_text_ram[offset]);
54   tilemap_mark_tile_dirty(text_tilemap, offset);
45   twin16_state *state = space->machine->driver_data<twin16_state>();
46   COMBINE_DATA(&state->text_ram[offset]);
47   tilemap_mark_tile_dirty(state->text_tilemap, offset);
5548}
5649
5750WRITE16_HANDLER( twin16_paletteram_word_w )
r10427r10428
6558
6659WRITE16_HANDLER( fround_gfx_bank_w )
6760{
68   COMBINE_DATA(&gfx_bank);
61   twin16_state *state = space->machine->driver_data<twin16_state>();
62   COMBINE_DATA(&state->gfx_bank);
6963}
7064
7165WRITE16_HANDLER( twin16_video_register_w )
7266{
67   twin16_state *state = space->machine->driver_data<twin16_state>();
7368   switch (offset)
7469   {
7570      case 0:
76         COMBINE_DATA( &video_register );
71         COMBINE_DATA( &state->video_register );
7772
78         flip_screen_x_set(space->machine, video_register & TWIN16_SCREEN_FLIPX);
79         flip_screen_y_set(space->machine, video_register & TWIN16_SCREEN_FLIPY);
73         flip_screen_x_set(space->machine, state->video_register & TWIN16_SCREEN_FLIPX);
74         flip_screen_y_set(space->machine, state->video_register & TWIN16_SCREEN_FLIPY);
8075
8176         break;
8277
83      case 1: COMBINE_DATA( &scrollx[0] ); break;
84      case 2: COMBINE_DATA( &scrolly[0] ); break;
85      case 3: COMBINE_DATA( &scrollx[1] ); break;
86      case 4: COMBINE_DATA( &scrolly[1] ); break;
87      case 5: COMBINE_DATA( &scrollx[2] ); break;
88      case 6: COMBINE_DATA( &scrolly[2] ); break;
78      case 1: COMBINE_DATA( &state->scrollx[0] ); break;
79      case 2: COMBINE_DATA( &state->scrolly[0] ); break;
80      case 3: COMBINE_DATA( &state->scrollx[1] ); break;
81      case 4: COMBINE_DATA( &state->scrolly[1] ); break;
82      case 5: COMBINE_DATA( &state->scrollx[2] ); break;
83      case 6: COMBINE_DATA( &state->scrolly[2] ); break;
8984
9085      default:
91         logerror("unknown video_register write:%d", data );
86         logerror("unknown state->video_register write:%d", data );
9287         break;
9388   }
9489}
r10427r10428
141136
142137READ16_HANDLER( twin16_sprite_status_r )
143138{
139   twin16_state *state = space->machine->driver_data<twin16_state>();
144140   // bit 0: busy, other bits: dunno
145   return twin16_sprite_busy;
141   return state->sprite_busy;
146142}
147143
148144static TIMER_CALLBACK( twin16_sprite_tick )
149145{
150   twin16_sprite_busy = 0;
146   twin16_state *state = machine->driver_data<twin16_state>();
147   state->sprite_busy = 0;
151148}
152149
153150static int twin16_set_sprite_timer( running_machine *machine )
154151{
155   if (twin16_sprite_busy) return 1;
152   twin16_state *state = machine->driver_data<twin16_state>();
153   if (state->sprite_busy) return 1;
156154
157155   // sprite system busy, maybe a dma? time is guessed, assume 4 scanlines
158   twin16_sprite_busy = 1;
159   twin16_sprite_timer->adjust(machine->primary_screen->frame_period() / machine->primary_screen->height() * 4);
156   state->sprite_busy = 1;
157   state->sprite_timer->adjust(machine->primary_screen->frame_period() / machine->primary_screen->height() * 4);
160158
161159   return 0;
162160}
163161
164162void twin16_spriteram_process( running_machine *machine )
165163{
164   twin16_state *state = machine->driver_data<twin16_state>();
166165   UINT16 *spriteram16 = machine->generic.spriteram.u16;
167   UINT16 dx = scrollx[0];
168   UINT16 dy = scrolly[0];
166   UINT16 dx = state->scrollx[0];
167   UINT16 dy = state->scrolly[0];
169168
170169   const UINT16 *source = &spriteram16[0x0000];
171170   const UINT16 *finish = &spriteram16[0x1800];
r10427r10428
219218      }
220219      source += 0x50/2;
221220   }
222   need_process_spriteram = 0;
221   state->need_process_spriteram = 0;
223222}
224223
225224static void draw_sprites( running_machine *machine, bitmap_t *bitmap )
226225{
226   twin16_state *state = machine->driver_data<twin16_state>();
227227   const UINT16 *source = 0x1800+machine->generic.buffered_spriteram.u16 + 0x800 - 4;
228228   const UINT16 *finish = 0x1800+machine->generic.buffered_spriteram.u16;
229229
r10427r10428
246246         int flipx = attributes&0x0100;
247247         int priority = (attributes&0x4000)?TWIN16_SPRITE_PRI_L1:TWIN16_SPRITE_PRI_L2;
248248
249         if( twin16_custom_video ) {
249         if( state->custom_video ) {
250250            /* fround board */
251            pen_data = twin16_gfx_rom + 0x80000;
251            pen_data = state->gfx_rom + 0x80000;
252252         }
253253         else
254254         {
r10427r10428
256256            {
257257               /* bank select */
258258               case 0:
259                  pen_data = twin16_gfx_rom;
259                  pen_data = state->gfx_rom;
260260                  break;
261261
262262               case 1:
263                  pen_data = twin16_gfx_rom + 0x40000;
263                  pen_data = state->gfx_rom + 0x40000;
264264                  break;
265265
266266               case 2:
267                  pen_data = twin16_gfx_rom + 0x80000;
267                  pen_data = state->gfx_rom + 0x80000;
268268                  if( code&0x4000 ) pen_data += 0x40000;
269269                  break;
270270
271271               case 3:
272                  pen_data = twin16_sprite_gfx_ram;
272                  pen_data = state->sprite_gfx_ram;
273273                  break;
274274            }
275275            code &= 0xfff;
r10427r10428
282282
283283         pen_data += code*0x40;
284284
285         if( video_register&TWIN16_SCREEN_FLIPY )
285         if( state->video_register&TWIN16_SCREEN_FLIPY )
286286         {
287287            if (ypos>65000) ypos=ypos-65536; /* Bit hacky */
288288            ypos = 256-ypos-height;
289289            flipy = !flipy;
290290         }
291         if( video_register&TWIN16_SCREEN_FLIPX )
291         if( state->video_register&TWIN16_SCREEN_FLIPX )
292292         {
293293            if (xpos>65000) xpos=xpos-65536; /* Bit hacky */
294294            xpos = 320-xpos-width;
r10427r10428
353353   int i, xxor, yxor;
354354   int bank_table[4];
355355   int dx, dy, palette;
356   int tile_flipx = video_register&TWIN16_TILE_FLIPX;
357   int tile_flipy = video_register&TWIN16_TILE_FLIPY;
356   int tile_flipx = state->video_register&TWIN16_TILE_FLIPX;
357   int tile_flipy = state->video_register&TWIN16_TILE_FLIPY;
358358
359   if( ((video_register&TWIN16_PLANE_ORDER)?1:0) != opaque ) {
359   if( ((state->video_register&TWIN16_PLANE_ORDER)?1:0) != opaque ) {
360360      source += 0x1000;
361      dx = scrollx[2];
362      dy = scrolly[2];
361      dx = state->scrollx[2];
362      dy = state->scrolly[2];
363363      palette = 1;
364364   }
365365   else {
366366      source += 0x0000;
367      dx = scrollx[1];
368      dy = scrolly[1];
367      dx = state->scrollx[1];
368      dy = state->scrolly[1];
369369      palette = 0;
370370   }
371371
372   if( twin16_custom_video ) {
372   if( state->custom_video ) {
373373      /* fround board */
374      gfx_base = twin16_gfx_rom;
375      bank_table[3] = (gfx_bank>>(4*3))&0xf;
376      bank_table[2] = (gfx_bank>>(4*2))&0xf;
377      bank_table[1] = (gfx_bank>>(4*1))&0xf;
378      bank_table[0] = (gfx_bank>>(4*0))&0xf;
374      gfx_base = state->gfx_rom;
375      bank_table[3] = (state->gfx_bank>>(4*3))&0xf;
376      bank_table[2] = (state->gfx_bank>>(4*2))&0xf;
377      bank_table[1] = (state->gfx_bank>>(4*1))&0xf;
378      bank_table[0] = (state->gfx_bank>>(4*0))&0xf;
379379   }
380380   else {
381      gfx_base = twin16_tile_gfx_ram;
381      gfx_base = state->tile_gfx_ram;
382382      bank_table[0] = 0;
383383      bank_table[1] = 1;
384384      bank_table[2] = 2;
385385      bank_table[3] = 3;
386386   }
387387
388   if( video_register&TWIN16_SCREEN_FLIPX )
388   if( state->video_register&TWIN16_SCREEN_FLIPX )
389389   {
390390      dx = 256-dx-64;
391391      tile_flipx = !tile_flipx;
392392   }
393393
394   if( video_register&TWIN16_SCREEN_FLIPY )
394   if( state->video_register&TWIN16_SCREEN_FLIPY )
395395   {
396396      dy = 256-dy;
397397      tile_flipy = !tile_flipy;
r10427r10428
407407      int sy = (i/64)*8;
408408      int xpos,ypos;
409409
410      if( video_register&TWIN16_SCREEN_FLIPX ) sx = 63*8 - sx;
411      if( video_register&TWIN16_SCREEN_FLIPY ) sy = 63*8 - sy;
410      if( state->video_register&TWIN16_SCREEN_FLIPX ) sx = 63*8 - sx;
411      if( state->video_register&TWIN16_SCREEN_FLIPY ) sy = 63*8 - sy;
412412
413413      xpos = (sx-dx)&0x1ff;
414414      ypos = (sy-dy)&0x1ff;
r10427r10428
477477
478478static TILE_GET_INFO( get_text_tile_info )
479479{
480   const UINT16 *source = twin16_text_ram;
480   twin16_state *state = machine->driver_data<twin16_state>();
481   const UINT16 *source = state->text_ram;
481482   int attr = source[tile_index];
482483   /* fedcba9876543210
483484       -x-------------- yflip
r10427r10428
497498
498499VIDEO_START( twin16 )
499500{
500   text_tilemap = tilemap_create(machine, get_text_tile_info, tilemap_scan_rows, 8, 8, 64, 32);
501   tilemap_set_transparent_pen(text_tilemap, 0);
501   twin16_state *state = machine->driver_data<twin16_state>();
502   state->text_tilemap = tilemap_create(machine, get_text_tile_info, tilemap_scan_rows, 8, 8, 64, 32);
503   tilemap_set_transparent_pen(state->text_tilemap, 0);
502504
503505   palette_set_shadow_factor(machine,0.4); // screenshots estimate
504506
505   memset(twin16_sprite_buffer,0xff,0x800*sizeof(UINT16));
506   twin16_sprite_busy = 0;
507   twin16_sprite_timer = machine->scheduler().timer_alloc(FUNC(twin16_sprite_tick));
508   twin16_sprite_timer->adjust(attotime::never);
507   memset(state->sprite_buffer,0xff,0x800*sizeof(UINT16));
508   state->sprite_busy = 0;
509   state->sprite_timer = machine->scheduler().timer_alloc(FUNC(twin16_sprite_tick));
510   state->sprite_timer->adjust(attotime::never);
509511
510512   /* register for savestates */
511   state_save_register_global_array(machine, twin16_sprite_buffer);
512   state_save_register_global_array(machine, scrollx);
513   state_save_register_global_array(machine, scrolly);
513   state_save_register_global_array(machine, state->sprite_buffer);
514   state_save_register_global_array(machine, state->scrollx);
515   state_save_register_global_array(machine, state->scrolly);
514516
515   state_save_register_global(machine, need_process_spriteram);
516   state_save_register_global(machine, gfx_bank);
517   state_save_register_global(machine, video_register);
518   state_save_register_global(machine, twin16_sprite_busy);
517   state_save_register_global(machine, state->need_process_spriteram);
518   state_save_register_global(machine, state->gfx_bank);
519   state_save_register_global(machine, state->video_register);
520   state_save_register_global(machine, state->sprite_busy);
519521}
520522
521523VIDEO_UPDATE( twin16 )
522524{
525   twin16_state *state = screen->machine->driver_data<twin16_state>();
523526   int text_flip=0;
524   if (video_register&TWIN16_SCREEN_FLIPX) text_flip|=TILEMAP_FLIPX;
525   if (video_register&TWIN16_SCREEN_FLIPY) text_flip|=TILEMAP_FLIPY;
527   if (state->video_register&TWIN16_SCREEN_FLIPX) text_flip|=TILEMAP_FLIPX;
528   if (state->video_register&TWIN16_SCREEN_FLIPY) text_flip|=TILEMAP_FLIPY;
526529
527530   bitmap_fill(screen->machine->priority_bitmap,cliprect,0);
528531   draw_layer( screen->machine, bitmap, 1 );
529532   draw_layer( screen->machine, bitmap, 0 );
530533   draw_sprites( screen->machine, bitmap );
531534
532   if (text_flip) tilemap_set_flip(text_tilemap, text_flip);
533   tilemap_draw(bitmap, cliprect, text_tilemap, 0, 0);
535   if (text_flip) tilemap_set_flip(state->text_tilemap, text_flip);
536   tilemap_draw(bitmap, cliprect, state->text_tilemap, 0, 0);
534537   return 0;
535538}
536539
537540VIDEO_EOF( twin16 )
538541{
542   twin16_state *state = machine->driver_data<twin16_state>();
539543   twin16_set_sprite_timer(machine);
540544
541   if (twin16_spriteram_process_enable()) {
542      if (need_process_spriteram) twin16_spriteram_process(machine);
543      need_process_spriteram = 1;
545   if (twin16_spriteram_process_enable(machine)) {
546      if (state->need_process_spriteram) twin16_spriteram_process(machine);
547      state->need_process_spriteram = 1;
544548
545549      /* if the sprite preprocessor is used, sprite ram is copied to an external buffer first,
546550        as evidenced by 1-frame sprite lag in gradius2 and devilw otherwise, though there's probably
547551        more to it than that */
548      memcpy(&machine->generic.buffered_spriteram.u16[0x1800],twin16_sprite_buffer,0x800*sizeof(UINT16));
549      memcpy(twin16_sprite_buffer,&machine->generic.spriteram.u16[0x1800],0x800*sizeof(UINT16));
552      memcpy(&machine->generic.buffered_spriteram.u16[0x1800],state->sprite_buffer,0x800*sizeof(UINT16));
553      memcpy(state->sprite_buffer,&machine->generic.spriteram.u16[0x1800],0x800*sizeof(UINT16));
550554   }
551555   else {
552556      address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
src/mame/video/atarigt.c
r10427r10428
2020
2121
2222#include "emu.h"
23#include "machine/atarigen.h"
23#include "video/atarirle.h"
2424#include "includes/atarigt.h"
2525
2626
r10427r10428
7878
7979VIDEO_START( atarigt )
8080{
81   static const atarirle_desc modesc =
82   {
83      "gfx3",      /* region where the GFX data lives */
84      256,      /* number of entries in sprite RAM */
85      0,         /* left clip coordinate */
86      0,         /* right clip coordinate */
87
88      0x0000,      /* base palette entry */
89      0x1000,      /* maximum number of colors */
90
91      {{ 0x7fff,0,0,0,0,0,0,0 }},   /* mask for the code index */
92      {{ 0,0x0ff0,0,0,0,0,0,0 }},   /* mask for the color */
93      {{ 0,0,0xffc0,0,0,0,0,0 }},   /* mask for the X position */
94      {{ 0,0,0,0xffc0,0,0,0,0 }},   /* mask for the Y position */
95      {{ 0,0,0,0,0xffff,0,0,0 }},   /* mask for the scale factor */
96      {{ 0x8000,0,0,0,0,0,0,0 }},   /* mask for the horizontal flip */
97      {{ 0,0,0,0,0,0,0x00ff,0 }},   /* mask for the order */
98      {{ 0,0x0e00,0,0,0,0,0,0 }},   /* mask for the priority */
99      {{ 0,0x8000,0,0,0,0,0,0 }}   /* mask for the VRAM target */
100   };
10181   atarigt_state *state = machine->driver_data<atarigt_state>();
102   atarirle_desc adjusted_modesc = modesc;
10382   pen_t *substitute_pens;
10483   int i, width, height;
10584
r10427r10428
11089   state->playfield_tilemap = tilemap_create(machine, get_playfield_tile_info, atarigt_playfield_scan,  8,8, 128,64);
11190
11291   /* initialize the motion objects */
113   atarirle_init(machine, 0, &adjusted_modesc);
92   state->rle = machine->device("rle");
11493
11594   /* initialize the alphanumerics */
11695   state->alpha_tilemap = tilemap_create(machine, get_alpha_tile_info, tilemap_scan_rows,  8,8, 64,32);
r10427r10428
530509VIDEO_UPDATE( atarigt )
531510{
532511   atarigt_state *state = screen->machine->driver_data<atarigt_state>();
533   bitmap_t *mo_bitmap = atarirle_get_vram(0, 0);
534   bitmap_t *tm_bitmap = atarirle_get_vram(0, 1);
512   bitmap_t *mo_bitmap = atarirle_get_vram(state->rle, 0);
513   bitmap_t *tm_bitmap = atarirle_get_vram(state->rle, 1);
535514   UINT16 *cram, *tram;
536515   int color_latch;
537516   UINT32 *mram;
r10427r10428
652631   }
653632   return 0;
654633}
634
635VIDEO_EOF( atarigt )
636{
637   atarigt_state *state = machine->driver_data<atarigt_state>();
638
639   atarirle_eof(state->rle);
640}
src/mame/video/m3raster.c
r10427r10428
44   const cached_texture *texture = extra->texture;
55   bitmap_t *destmap = (bitmap_t *)dest;
66   UINT16 *p = BITMAP_ADDR16(destmap, scanline, 0);
7   UINT32 *d = BITMAP_ADDR32(zbuffer, scanline, 0);
7   UINT32 *d = BITMAP_ADDR32(extra->zbuffer, scanline, 0);
88   float ooz = extent->param[0].start;
99   float uoz = extent->param[1].start;
1010   float voz = extent->param[2].start;
r10427r10428
5353   const cached_texture *texture = extra->texture;
5454   bitmap_t *destmap = (bitmap_t *)dest;
5555   UINT16 *p = BITMAP_ADDR16(destmap, scanline, 0);
56   UINT32 *d = BITMAP_ADDR32(zbuffer, scanline, 0);
56   UINT32 *d = BITMAP_ADDR32(extra->zbuffer, scanline, 0);
5757   float ooz = extent->param[0].start;
5858   float uoz = extent->param[1].start;
5959   float voz = extent->param[2].start;
r10427r10428
108108   const cached_texture *texture = extra->texture;
109109   bitmap_t *destmap = (bitmap_t *)dest;
110110   UINT16 *p = BITMAP_ADDR16(destmap, scanline, 0);
111   UINT32 *d = BITMAP_ADDR32(zbuffer, scanline, 0);
111   UINT32 *d = BITMAP_ADDR32(extra->zbuffer, scanline, 0);
112112   float ooz = extent->param[0].start;
113113   float uoz = extent->param[1].start;
114114   float voz = extent->param[2].start;
r10427r10428
166166   const cached_texture *texture = extra->texture;
167167   bitmap_t *destmap = (bitmap_t *)dest;
168168   UINT16 *p = BITMAP_ADDR16(destmap, scanline, 0);
169   UINT32 *d = BITMAP_ADDR32(zbuffer, scanline, 0);
169   UINT32 *d = BITMAP_ADDR32(extra->zbuffer, scanline, 0);
170170   float ooz = extent->param[0].start;
171171   float uoz = extent->param[1].start;
172172   float voz = extent->param[2].start;
r10427r10428
225225   const poly_extra_data *extra = (const poly_extra_data *)extradata;
226226   bitmap_t *destmap = (bitmap_t *)dest;
227227   UINT16 *p = BITMAP_ADDR16(destmap, scanline, 0);
228   UINT32 *d = BITMAP_ADDR32(zbuffer, scanline, 0);
228   UINT32 *d = BITMAP_ADDR32(extra->zbuffer, scanline, 0);
229229   float ooz = extent->param[0].start;
230230   float doozdx = extent->param[0].dpdx;
231231   int fr = extra->color & 0x7c00;
src/mame/drivers/bfcobra.c
r10427r10428
8181#include "sound/ay8910.h"
8282#include "machine/nvram.h"
8383
84
85class bfcobra_state : public driver_device
86{
87public:
88   bfcobra_state(running_machine &machine, const driver_device_config_base &config)
89      : driver_device(machine, config) { }
90
91   UINT8 bank_data[4];
92   UINT8 *work_ram;
93   UINT8 *video_ram;
94   UINT8 h_scroll;
95   UINT8 v_scroll;
96   UINT8 flip_8;
97   UINT8 flip_22;
98   UINT8 videomode;
99   UINT8 z80_m6809_line;
100   UINT8 m6809_z80_line;
101   UINT8 data_r;
102   UINT8 data_t;
103   int irq_state;
104   int acia_irq;
105   int vblank_irq;
106   int blitter_irq;
107   UINT8 z80_int;
108   UINT8 z80_inten;
109   UINT32 meter_latch;
110   UINT32 mux_input;
111   UINT32 mux_outputlatch;
112   UINT8 col4bit[16];
113   UINT8 col3bit[16];
114   UINT8 col8bit[256];
115   UINT8 col7bit[256];
116   UINT8 col6bit[256];
117};
118
119
84120/*
85121    Defines
86122*/
r10427r10428
89125
90126
91127/*
92    Globals
93*/
94static UINT8 bank_data[4];
95static UINT8 *work_ram;
96static UINT8 *video_ram;
97static UINT8 h_scroll;
98static UINT8 v_scroll;
99static UINT8 flip_8;
100static UINT8 flip_22;
101static UINT8 videomode;
102
103/* UART source/sinks */
104static UINT8 z80_m6809_line;
105static UINT8 m6809_z80_line;
106static UINT8 data_r;
107static UINT8 data_t;
108
109static int irq_state;
110static int acia_irq;
111static int vblank_irq;
112static int blitter_irq;
113
114static UINT8 z80_int;
115static UINT8 z80_inten;
116
117/* EM and lamps stuff */
118static UINT32 meter_latch;
119static UINT32 mux_input;
120static UINT32 mux_outputlatch;
121
122/*
123128    Function prototypes
124129*/
125130INLINE void z80_bank(running_machine *machine, int num, int data);
r10427r10428
127132
128133static void update_irqs(running_machine *machine)
129134{
130   int newstate = blitter_irq || vblank_irq || acia_irq;
135   bfcobra_state *state = machine->driver_data<bfcobra_state>();
136   int newstate = state->blitter_irq || state->vblank_irq || state->acia_irq;
131137
132   if (newstate != irq_state)
138   if (newstate != state->irq_state)
133139   {
134      irq_state = newstate;
135      cputag_set_input_line(machine, "maincpu", 0, irq_state ? ASSERT_LINE : CLEAR_LINE);
140      state->irq_state = newstate;
141      cputag_set_input_line(machine, "maincpu", 0, state->irq_state ? ASSERT_LINE : CLEAR_LINE);
136142   }
137143}
138144
r10427r10428
292298   RED_7 | GREEN_7 | BLUE_3
293299};
294300
295static UINT8 col4bit[16];
296static UINT8 col3bit[16];
297static UINT8 col8bit[256];
298static UINT8 col7bit[256];
299static UINT8 col6bit[256];
300301static const UINT8 col76index[] = {0, 2, 4, 7};
301302
302303
303304static VIDEO_START( bfcobra )
304305{
306   bfcobra_state *state = machine->driver_data<bfcobra_state>();
305307   int i;
306308
307   memcpy(col4bit, col4bit_default, sizeof(col4bit));
308   memcpy(col3bit, col3bit_default, sizeof(col3bit));
309   memcpy(state->col4bit, col4bit_default, sizeof(state->col4bit));
310   memcpy(state->col3bit, col3bit_default, sizeof(state->col3bit));
309311   for (i = 0; i < 256; ++i)
310312   {
311313      UINT8 col;
312314
313      col8bit[i] = i;
315      state->col8bit[i] = i;
314316      col = i & 0x7f;
315317      col = (col & 0x1f) | (col76index[ ( (col & 0x60) >> 5 ) & 3] << 5);
316      col7bit[i] = col;
318      state->col7bit[i] = col;
317319
318320      col = (col & 3) | (col76index[( (col & 0x0c) >> 2) & 3] << 2 ) |
319321           (col76index[( (col & 0x30) >> 4) & 3] << 5 );
320      col6bit[i] = col;
322      state->col6bit[i] = col;
321323   }
322324}
323325
324326static VIDEO_UPDATE( bfcobra )
325327{
328   bfcobra_state *state = screen->machine->driver_data<bfcobra_state>();
326329   int x, y;
327330   UINT8  *src;
328331   UINT32 *dest;
r10427r10428
332335
333336   /* Select screen has to be programmed into two registers */
334337   /* No idea what happens if the registers are different */
335   if (flip_8 & 0x40 && flip_22 & 0x40)
338   if (state->flip_8 & 0x40 && state->flip_22 & 0x40)
336339      offset = 0x10000;
337340   else
338341      offset = 0;
339342
340   if(videomode & 0x20)
343   if(state->videomode & 0x20)
341344   {
342      hirescol = col3bit;
343      lorescol = col7bit;
345      hirescol = state->col3bit;
346      lorescol = state->col7bit;
344347   }
345   else if(videomode & 0x40)
348   else if(state->videomode & 0x40)
346349   {
347      hirescol = col4bit;
348      lorescol = col6bit;
350      hirescol = state->col4bit;
351      lorescol = state->col6bit;
349352   }
350353   else
351354   {
352      hirescol = col4bit;
353      lorescol = col8bit;
355      hirescol = state->col4bit;
356      lorescol = state->col8bit;
354357   }
355358
356359   for (y = cliprect->min_y; y <= cliprect->max_y; ++y)
357360   {
358      UINT16 y_offset = (y + v_scroll) * 256;
359      src = &video_ram[offset + y_offset];
361      UINT16 y_offset = (y + state->v_scroll) * 256;
362      src = &state->video_ram[offset + y_offset];
360363      dest = BITMAP_ADDR32(bitmap, y, 0);
361364
362365      for (x = cliprect->min_x; x <= cliprect->max_x / 2; ++x)
363366      {
364         UINT8 x_offset = x + h_scroll;
367         UINT8 x_offset = x + state->h_scroll;
365368         UINT8 pen = *(src + x_offset);
366369
367         if ( ( videomode & 0x81 ) == 1 || (videomode & 0x80 && pen & 0x80) )
370         if ( ( state->videomode & 0x81 ) == 1 || (state->videomode & 0x80 && pen & 0x80) )
368371         {
369372            *dest++ = screen->machine->pens[hirescol[pen & 0x0f]];
370373            *dest++ = screen->machine->pens[hirescol[(pen >> 4) & 0x0f]];
r10427r10428
382385
383386INLINE UINT8* blitter_get_addr(running_machine *machine, UINT32 addr)
384387{
388   bfcobra_state *state = machine->driver_data<bfcobra_state>();
385389   if (addr < 0x10000)
386390   {
387391      /* Is this region fixed? */
r10427r10428
390394   else if(addr < 0x20000)
391395   {
392396      addr &= 0xffff;
393      addr += (bank_data[0] & 1) ? 0x10000 : 0;
397      addr += (state->bank_data[0] & 1) ? 0x10000 : 0;
394398
395      return (UINT8*)(machine->region("user1")->base() + addr + ((bank_data[0] >> 1) * 0x20000));
399      return (UINT8*)(machine->region("user1")->base() + addr + ((state->bank_data[0] >> 1) * 0x20000));
396400   }
397401   else if (addr >= 0x20000 && addr < 0x40000)
398402   {
399      return (UINT8*)&video_ram[addr - 0x20000];
403      return (UINT8*)&state->video_ram[addr - 0x20000];
400404   }
401405   else
402406   {
403      return (UINT8*)&work_ram[addr - 0x40000];
407      return (UINT8*)&state->work_ram[addr - 0x40000];
404408   }
405409}
406410
r10427r10428
823827
824828static READ8_HANDLER( chipset_r )
825829{
830   bfcobra_state *state = space->machine->driver_data<bfcobra_state>();
826831   UINT8 val = 0xff;
827832
828833   switch(offset)
r10427r10428
831836      case 2:
832837      case 3:
833838      {
834         val = bank_data[offset];
839         val = state->bank_data[offset];
835840         break;
836841      }
837842      case 6:
838843      {
839844         /* TODO */
840         val = vblank_irq << 4;
845         val = state->vblank_irq << 4;
841846         break;
842847      }
843848      case 7:
844849      {
845         vblank_irq = 0;
850         state->vblank_irq = 0;
846851         val = 0x1;
847852
848853         /* TODO */
r10427r10428
877882
878883static WRITE8_HANDLER( chipset_w )
879884{
885   bfcobra_state *state = space->machine->driver_data<bfcobra_state>();
880886   switch (offset)
881887   {
882888      case 0x01:
r10427r10428
887893            popmessage("%x: Unusual bank access (%x)\n", cpu_get_previouspc(space->cpu), data);
888894
889895         data &= 0x3f;
890         bank_data[offset] = data;
896         state->bank_data[offset] = data;
891897         z80_bank(space->machine, offset, data);
892898         break;
893899      }
894900
895901      case 0x08:
896902      {
897         flip_8 = data;
903         state->flip_8 = data;
898904         break;
899905      }
900906      case 9:
901         videomode = data;
907         state->videomode = data;
902908         break;
903909
904910      case 0x0B:
905911      {
906         h_scroll = data;
912         state->h_scroll = data;
907913         break;
908914      }
909915      case 0x0C:
910916      {
911         v_scroll = data;
917         state->v_scroll = data;
912918         break;
913919      }
914920      case 0x0E:
915921      {
916         col4bit[5] = data;
917         col3bit[5] = data;
918         col3bit[5 + 8] = data;
922         state->col4bit[5] = data;
923         state->col3bit[5] = data;
924         state->col3bit[5 + 8] = data;
919925         break;
920926      }
921927      case 0x0f:
922928      {
923         col4bit[6] = data;
924         col3bit[6] = data;
925         col3bit[6 + 8] = data;
929         state->col4bit[6] = data;
930         state->col3bit[6] = data;
931         state->col3bit[6 + 8] = data;
926932         break;
927933      }
928934      case 0x18:
r10427r10428
953959      }
954960      case 0x22:
955961      {
956         flip_22 = data;
962         state->flip_22 = data;
957963         break;
958964      }
959965      default:
r10427r10428
965971
966972INLINE void z80_bank(running_machine *machine, int num, int data)
967973{
974   bfcobra_state *state = machine->driver_data<bfcobra_state>();
968975   static const char * const bank_names[] = { "bank1", "bank2", "bank3" };
969976
970977   if (data < 0x08)
971978   {
972      UINT32 offset = ((bank_data[0] >> 1) * 0x20000) + ((0x4000 * data) ^ ((bank_data[0] & 1) ? 0 : 0x10000));
979      UINT32 offset = ((state->bank_data[0] >> 1) * 0x20000) + ((0x4000 * data) ^ ((state->bank_data[0] & 1) ? 0 : 0x10000));
973980
974981      memory_set_bankptr(machine, bank_names[num - 1], machine->region("user1")->base() + offset);
975982   }
976983   else if (data < 0x10)
977984   {
978      memory_set_bankptr(machine, bank_names[num - 1], &video_ram[(data - 0x08) * 0x4000]);
985      memory_set_bankptr(machine, bank_names[num - 1], &state->video_ram[(data - 0x08) * 0x4000]);
979986   }
980987   else
981988   {
982      memory_set_bankptr(machine, bank_names[num - 1], &work_ram[(data - 0x10) * 0x4000]);
989      memory_set_bankptr(machine, bank_names[num - 1], &state->work_ram[(data - 0x10) * 0x4000]);
983990   }
984991}
985992
986993static WRITE8_HANDLER( rombank_w )
987994{
988   bank_data[0] = data;
989   z80_bank(space->machine, 1, bank_data[1]);
990   z80_bank(space->machine, 2, bank_data[2]);
991   z80_bank(space->machine, 3, bank_data[3]);
995   bfcobra_state *state = space->machine->driver_data<bfcobra_state>();
996   state->bank_data[0] = data;
997   z80_bank(space->machine, 1, state->bank_data[1]);
998   z80_bank(space->machine, 2, state->bank_data[2]);
999   z80_bank(space->machine, 3, state->bank_data[3]);
9921000}
9931001
9941002
r10427r10428
12811289
12821290static MACHINE_RESET( bfcobra )
12831291{
1292   bfcobra_state *state = machine->driver_data<bfcobra_state>();
12841293   unsigned int pal;
12851294
12861295   for (pal = 0; pal < 256; ++pal)
r10427r10428
12881297      palette_set_color_rgb(machine, pal, pal3bit((pal>>5)&7), pal3bit((pal>>2)&7), pal2bit(pal&3));
12891298   }
12901299
1291   bank_data[0] = 1;
1300   state->bank_data[0] = 1;
12921301   memset(&ramdac, 0, sizeof(ramdac));
12931302   reset_fdc();
12941303
1295   irq_state = blitter_irq = vblank_irq = acia_irq = 0;
1304   state->irq_state = state->blitter_irq = state->vblank_irq = state->acia_irq = 0;
12961305}
12971306
12981307/***************************************************************************
r10427r10428
13521361/* TODO */
13531362static READ8_HANDLER( meter_r )
13541363{
1355   return meter_latch;
1364   bfcobra_state *state = space->machine->driver_data<bfcobra_state>();
1365   return state->meter_latch;
13561366}
13571367
13581368/* TODO: This is borrowed from Scorpion 1 */
13591369static WRITE8_HANDLER( meter_w )
13601370{
1371   bfcobra_state *state = space->machine->driver_data<bfcobra_state>();
13611372   int i;
1362   int  changed = meter_latch ^ data;
1373   int  changed = state->meter_latch ^ data;
13631374
1364   meter_latch = data;
1375   state->meter_latch = data;
13651376
13661377   /*
13671378        When a meter is triggered, the current drawn is sensed. If a meter
r10427r10428
13801391/* TODO */
13811392static READ8_HANDLER( latch_r )
13821393{
1383   return mux_input;
1394   bfcobra_state *state = space->machine->driver_data<bfcobra_state>();
1395   return state->mux_input;
13841396}
13851397
13861398static WRITE8_HANDLER( latch_w )
13871399{
1400   bfcobra_state *state = space->machine->driver_data<bfcobra_state>();
13881401   /* TODO: This is borrowed from Scorpion 1 */
13891402   switch(offset)
13901403   {
13911404      case 0:
13921405      {
1393         int changed = mux_outputlatch ^ data;
1406         int changed = state->mux_outputlatch ^ data;
13941407         static const char *const port[] = { "STROBE0", "STROBE1", "STROBE2", "STROBE3", "STROBE4", "STROBE5", "STROBE6", "STROBE7" };
13951408
1396         mux_outputlatch = data;
1409         state->mux_outputlatch = data;
13971410
13981411         /* Clock has changed */
13991412         if (changed & 0x08)
r10427r10428
14021415
14031416            /* Clock is low */
14041417            if (!(data & 0x08))
1405               mux_input = input_port_read(space->machine, port[input_strobe]);
1418               state->mux_input = input_port_read(space->machine, port[input_strobe]);
14061419         }
14071420         break;
14081421      }
r10427r10428
15611574*/
15621575static void init_ram(running_machine *machine)
15631576{
1577   bfcobra_state *state = machine->driver_data<bfcobra_state>();
15641578   /* 768kB work RAM */
1565   work_ram = auto_alloc_array_clear(machine, UINT8, 0xC0000);
1579   state->work_ram = auto_alloc_array_clear(machine, UINT8, 0xC0000);
15661580
15671581   /* 128kB video RAM */
1568   video_ram = auto_alloc_array_clear(machine, UINT8, 0x20000);
1582   state->video_ram = auto_alloc_array_clear(machine, UINT8, 0x20000);
15691583}
15701584
15711585/*
r10427r10428
15741588
15751589static READ_LINE_DEVICE_HANDLER( z80_acia_rx_r )
15761590{
1577   return m6809_z80_line;
1591   bfcobra_state *state = device->machine->driver_data<bfcobra_state>();
1592   return state->m6809_z80_line;
15781593}
15791594
15801595static WRITE_LINE_DEVICE_HANDLER( z80_acia_tx_w )
15811596{
1582   z80_m6809_line = state;
1597   bfcobra_state *drvstate = device->machine->driver_data<bfcobra_state>();
1598   drvstate->z80_m6809_line = state;
15831599}
15841600
15851601static WRITE_LINE_DEVICE_HANDLER( z80_acia_irq )
15861602{
1587   acia_irq = state ? CLEAR_LINE : ASSERT_LINE;
1603   bfcobra_state *drvstate = device->machine->driver_data<bfcobra_state>();
1604   drvstate->acia_irq = state ? CLEAR_LINE : ASSERT_LINE;
15881605   update_irqs(device->machine);
15891606}
15901607
r10427r10428
16021619
16031620static READ_LINE_DEVICE_HANDLER( m6809_acia_rx_r )
16041621{
1605   return z80_m6809_line;
1622   bfcobra_state *state = device->machine->driver_data<bfcobra_state>();
1623   return state->z80_m6809_line;
16061624}
16071625
16081626static WRITE_LINE_DEVICE_HANDLER( m6809_acia_tx_w )
16091627{
1610   m6809_z80_line = state;
1628   bfcobra_state *drvstate = device->machine->driver_data<bfcobra_state>();
1629   drvstate->m6809_z80_line = state;
16111630}
16121631
16131632static WRITE_LINE_DEVICE_HANDLER( m6809_data_irq )
r10427r10428
16291648
16301649static READ_LINE_DEVICE_HANDLER( data_acia_rx_r )
16311650{
1632   return data_r;
1651   bfcobra_state *state = device->machine->driver_data<bfcobra_state>();
1652   return state->data_r;
16331653}
16341654
16351655static WRITE_LINE_DEVICE_HANDLER( data_acia_tx_w )
16361656{
1637    data_t = state;
1657   bfcobra_state *drvstate = device->machine->driver_data<bfcobra_state>();
1658    drvstate->data_t = state;
16381659}
16391660
16401661
r10427r10428
16541675/* TODO: Driver vs Machine Init */
16551676static DRIVER_INIT( bfcobra )
16561677{
1678   bfcobra_state *state = machine->driver_data<bfcobra_state>();
16571679   /*
16581680        6809 ROM address and data lines are scrambled.
16591681        This is the same scrambling as Scorpion 2.
r10427r10428
16891711
16901712   init_ram(machine);
16911713
1692   bank_data[0] = 1;
1693   bank_data[1] = 0;
1694   bank_data[2] = 0;
1695   bank_data[3] = 0;
1714   state->bank_data[0] = 1;
1715   state->bank_data[1] = 0;
1716   state->bank_data[2] = 0;
1717   state->bank_data[3] = 0;
16961718
16971719   /* Fixed 16kB ROM region */
16981720   memory_set_bankptr(machine, "bank4", machine->region("user1")->base());
16991721
17001722   /* TODO: Properly sort out the data ACIA */
1701   data_r = 1;
1723   state->data_r = 1;
17021724
17031725   /* Finish this */
1704   state_save_register_global(machine, z80_m6809_line);
1705   state_save_register_global(machine, m6809_z80_line);
1706   state_save_register_global(machine, data_r);
1707   state_save_register_global(machine, data_t);
1708   state_save_register_global(machine, h_scroll);
1709   state_save_register_global(machine, v_scroll);
1710   state_save_register_global(machine, flip_8);
1711   state_save_register_global(machine, flip_22);
1712   state_save_register_global(machine, z80_int);
1713   state_save_register_global(machine, z80_inten);
1714   state_save_register_global_array(machine, bank_data);
1715   state_save_register_global_pointer(machine, work_ram, 0xc0000);
1716   state_save_register_global_pointer(machine, video_ram, 0x20000);
1726   state_save_register_global(machine, state->z80_m6809_line);
1727   state_save_register_global(machine, state->m6809_z80_line);
1728   state_save_register_global(machine, state->data_r);
1729   state_save_register_global(machine, state->data_t);
1730   state_save_register_global(machine, state->h_scroll);
1731   state_save_register_global(machine, state->v_scroll);
1732   state_save_register_global(machine, state->flip_8);
1733   state_save_register_global(machine, state->flip_22);
1734   state_save_register_global(machine, state->z80_int);
1735   state_save_register_global(machine, state->z80_inten);
1736   state_save_register_global_array(machine, state->bank_data);
1737   state_save_register_global_pointer(machine, state->work_ram, 0xc0000);
1738   state_save_register_global_pointer(machine, state->video_ram, 0x20000);
17171739}
17181740
17191741/* TODO */
r10427r10428
17251747/* TODO */
17261748static INTERRUPT_GEN( vblank_gen )
17271749{
1728   vblank_irq = 1;
1750   bfcobra_state *state = device->machine->driver_data<bfcobra_state>();
1751   state->vblank_irq = 1;
17291752   update_irqs(device->machine);
17301753}
17311754
1732static MACHINE_CONFIG_START( bfcobra, driver_device )
1755static MACHINE_CONFIG_START( bfcobra, bfcobra_state )
17331756   MCFG_CPU_ADD("maincpu", Z80, Z80_XTAL)
17341757   MCFG_CPU_PROGRAM_MAP(z80_prog_map)
17351758   MCFG_CPU_IO_MAP(z80_io_map)
src/mame/drivers/mitchell.c
r10427r10428
9393   "0111"   /* erase command */
9494};
9595
96static UINT8 *nvram;
97static size_t nvram_size;
98
9996static NVRAM_HANDLER( mitchell )
10097{
98   mitchell_state *state = machine->driver_data<mitchell_state>();
10199   if (read_or_write)
102100   {
103      if (nvram_size)   /* Super Pang, Block Block */
104         file->write(nvram,nvram_size);   /* NVRAM */
101      if (state->nvram_size)   /* Super Pang, Block Block */
102         file->write(state->nvram,state->nvram_size);   /* NVRAM */
105103   }
106104   else
107105   {
108106      if (file)
109107      {
110         if (nvram_size)   /* Super Pang, Block Block */
111            file->read(nvram,nvram_size);   /* NVRAM */
108         if (state->nvram_size)   /* Super Pang, Block Block */
109            file->read(state->nvram,state->nvram_size);   /* NVRAM */
112110      }
113111   }
114112}
r10427r10428
21172115{
21182116   mitchell_state *state = machine->driver_data<mitchell_state>();
21192117   state->input_type = 0;
2120   nvram_size = 0;
2118   state->nvram_size = 0;
21212119   mgakuen2_decode(machine);
21222120   configure_banks(machine);
21232121}
r10427r10428
21252123{
21262124   mitchell_state *state = machine->driver_data<mitchell_state>();
21272125   state->input_type = 0;
2128   nvram_size = 0;
2126   state->nvram_size = 0;
21292127   pang_decode(machine);
21302128   configure_banks(machine);
21312129}
r10427r10428
21332131{
21342132   mitchell_state *state = machine->driver_data<mitchell_state>();
21352133   state->input_type = 0;
2136   nvram_size = 0;
2134   state->nvram_size = 0;
21372135   bootleg_decode(machine);
21382136   configure_banks(machine);
21392137}
r10427r10428
21412139{
21422140   mitchell_state *state = machine->driver_data<mitchell_state>();
21432141   state->input_type = 0;
2144   nvram_size = 0;
2142   state->nvram_size = 0;
21452143   cworld_decode(machine);
21462144   configure_banks(machine);
21472145}
r10427r10428
21492147{
21502148   mitchell_state *state = machine->driver_data<mitchell_state>();
21512149   state->input_type = 0;
2152   nvram_size = 0;
2150   state->nvram_size = 0;
21532151   hatena_decode(machine);
21542152   configure_banks(machine);
21552153}
r10427r10428
21572155{
21582156   mitchell_state *state = machine->driver_data<mitchell_state>();
21592157   state->input_type = 3;
2160   nvram_size = 0x80;
2161   nvram = &machine->region("maincpu")->base()[0xe000];   /* NVRAM */
2158   state->nvram_size = 0x80;
2159   state->nvram = &machine->region("maincpu")->base()[0xe000];   /* NVRAM */
21622160   spang_decode(machine);
21632161   configure_banks(machine);
21642162}
r10427r10428
21672165{
21682166   mitchell_state *state = machine->driver_data<mitchell_state>();
21692167   state->input_type = 3;
2170   nvram_size = 0x80;
2171   nvram = &machine->region("maincpu")->base()[0xe000];   /* NVRAM */
2168   state->nvram_size = 0x80;
2169   state->nvram = &machine->region("maincpu")->base()[0xe000];   /* NVRAM */
21722170   bootleg_decode(machine);
21732171   configure_banks(machine);
21742172}
r10427r10428
21772175{
21782176   mitchell_state *state = machine->driver_data<mitchell_state>();
21792177   state->input_type = 3;
2180   nvram_size = 0x80;
2181   nvram = &machine->region("maincpu")->base()[0xe000];   /* NVRAM */
2178   state->nvram_size = 0x80;
2179   state->nvram = &machine->region("maincpu")->base()[0xe000];   /* NVRAM */
21822180   spangj_decode(machine);
21832181   configure_banks(machine);
21842182}
r10427r10428
21862184{
21872185   mitchell_state *state = machine->driver_data<mitchell_state>();
21882186   state->input_type = 3;
2189   nvram_size = 0x80;
2190   nvram = &machine->region("maincpu")->base()[0xe000];   /* NVRAM */
2187   state->nvram_size = 0x80;
2188   state->nvram = &machine->region("maincpu")->base()[0xe000];   /* NVRAM */
21912189   sbbros_decode(machine);
21922190   configure_banks(machine);
21932191}
r10427r10428
21952193{
21962194   mitchell_state *state = machine->driver_data<mitchell_state>();
21972195   state->input_type = 0;
2198   nvram_size = 0;
2196   state->nvram_size = 0;
21992197   qtono1_decode(machine);
22002198   configure_banks(machine);
22012199}
r10427r10428
22032201{
22042202   mitchell_state *state = machine->driver_data<mitchell_state>();
22052203   state->input_type = 0;
2206   nvram_size = 0;
2204   state->nvram_size = 0;
22072205   qsangoku_decode(machine);
22082206   configure_banks(machine);
22092207}
r10427r10428
22192217{
22202218   mitchell_state *state = machine->driver_data<mitchell_state>();
22212219   state->input_type = 1;
2222   nvram_size = 0;
2220   state->nvram_size = 0;
22232221   mgakuen2_decode(machine);
22242222   configure_banks(machine);
22252223}
r10427r10428
22272225{
22282226   mitchell_state *state = machine->driver_data<mitchell_state>();
22292227   state->input_type = 1;
2230   nvram_size = 0;
2228   state->nvram_size = 0;
22312229   mgakuen2_decode(machine);
22322230   configure_banks(machine);
22332231}
r10427r10428
22352233{
22362234   mitchell_state *state = machine->driver_data<mitchell_state>();
22372235   state->input_type = 1;
2238   nvram_size = 0;
2236   state->nvram_size = 0;
22392237   bootleg_decode(machine);
22402238   configure_banks(machine);
22412239}
r10427r10428
22432241{
22442242   mitchell_state *state = machine->driver_data<mitchell_state>();
22452243   state->input_type = 1;
2246   nvram_size = 0;
2244   state->nvram_size = 0;
22472245   marukin_decode(machine);
22482246   configure_banks(machine);
22492247}
r10427r10428
22512249{
22522250   mitchell_state *state = machine->driver_data<mitchell_state>();
22532251   state->input_type = 2;
2254   nvram_size = 0x80;
2255   nvram = &machine->region("maincpu")->base()[0xff80];   /* NVRAM */
2252   state->nvram_size = 0x80;
2253   state->nvram = &machine->region("maincpu")->base()[0xff80];   /* NVRAM */
22562254   block_decode(machine);
22572255   configure_banks(machine);
22582256}
r10427r10428
22602258{
22612259   mitchell_state *state = machine->driver_data<mitchell_state>();
22622260   state->input_type = 2;
2263   nvram_size = 0x80;
2264   nvram = &machine->region("maincpu")->base()[0xff80];   /* NVRAM */
2261   state->nvram_size = 0x80;
2262   state->nvram = &machine->region("maincpu")->base()[0xff80];   /* NVRAM */
22652263   bootleg_decode(machine);
22662264   configure_banks(machine);
22672265}
src/mame/drivers/deco_mlc.c
r10427r10428
104104#include "cpu/sh2/sh2.h"
105105#include "includes/deco_mlc.h"
106106
107static UINT32 *mlc_ram, *irq_ram;
108static timer_device *raster_irq_timer;
109static int mainCpuIsArm;
110static int mlc_raster_table[9][256];
111static UINT32 vbl_i;
112107
113108/***************************************************************************/
114109
r10427r10428
158153
159154static READ32_HANDLER( decomlc_vbl_r )
160155{
161   vbl_i ^=0xffffffff;
156   deco_mlc_state *state = space->machine->driver_data<deco_mlc_state>();
157   state->vbl_i ^=0xffffffff;
162158//logerror("vbl r %08x\n", cpu_get_pc(space->cpu));
163159   // Todo: Vblank probably in $10
164   return vbl_i;
160   return state->vbl_i;
165161}
166162
167163static READ32_HANDLER( mlc_scanline_r )
r10427r10428
172168
173169static TIMER_DEVICE_CALLBACK( interrupt_gen )
174170{
171   deco_mlc_state *state = timer.machine->driver_data<deco_mlc_state>();
175172//  logerror("hit scanline IRQ %d (%08x)\n", machine->primary_screen->vpos(), info.i);
176   cputag_set_input_line(timer.machine, "maincpu", mainCpuIsArm ? ARM_IRQ_LINE : 1, HOLD_LINE);
173   cputag_set_input_line(timer.machine, "maincpu", state->mainCpuIsArm ? ARM_IRQ_LINE : 1, HOLD_LINE);
177174}
178175
179176static WRITE32_HANDLER( mlc_irq_w )
180177{
181   static int lastScanline[9]={ 0, 0, 0, 0, 0, 0, 0, 0, 0 };
178   deco_mlc_state *state = space->machine->driver_data<deco_mlc_state>();
182179   int scanline=space->machine->primary_screen->vpos();
183   irq_ram[offset]=data&0xffff;
180   state->irq_ram[offset]=data&0xffff;
184181
185182   switch (offset*4)
186183   {
187184   case 0x10: /* IRQ ack.  Value written doesn't matter */
188      cputag_set_input_line(space->machine, "maincpu", mainCpuIsArm ? ARM_IRQ_LINE : 1, CLEAR_LINE);
185      cputag_set_input_line(space->machine, "maincpu", state->mainCpuIsArm ? ARM_IRQ_LINE : 1, CLEAR_LINE);
189186      return;
190187   case 0x14: /* Prepare scanline interrupt */
191      raster_irq_timer->adjust(space->machine->primary_screen->time_until_pos(irq_ram[0x14/4]));
192      //logerror("prepare scanline to fire at %d (currently on %d)\n", irq_ram[0x14/4], space->machine->primary_screen->vpos());
188      state->raster_irq_timer->adjust(space->machine->primary_screen->time_until_pos(state->irq_ram[0x14/4]));
189      //logerror("prepare scanline to fire at %d (currently on %d)\n", state->irq_ram[0x14/4], space->machine->primary_screen->vpos());
193190      return;
194191   case 0x18:
195192   case 0x1c:
r10427r10428
203200      if (scanline > 255)
204201         scanline = 255;
205202      /* Update scanlines up to present line */
206      while (lastScanline[offset-6]<scanline)
203      while (state->lastScanline[offset-6]<scanline)
207204      {
208         mlc_raster_table[offset-6][lastScanline[offset-6]+1]=mlc_raster_table[offset-6][lastScanline[offset-6]];
209         lastScanline[offset-6]++;
205         state->mlc_raster_table[offset-6][state->lastScanline[offset-6]+1]=state->mlc_raster_table[offset-6][state->lastScanline[offset-6]];
206         state->lastScanline[offset-6]++;
210207      }
211208
212      if (lastScanline[offset-6] > scanline)
213         lastScanline[offset-6]=0;
209      if (state->lastScanline[offset-6] > scanline)
210         state->lastScanline[offset-6]=0;
214211
215212      /* Set current scanline value */
216      mlc_raster_table[offset-6][scanline]=data&0xffff;
213      state->mlc_raster_table[offset-6][scanline]=data&0xffff;
217214      break;
218215
219216   default:
r10427r10428
230227
231228static READ32_HANDLER(mlc_vram_r)
232229{
233   return mlc_vram[offset]&0xffff;
230   deco_mlc_state *state = space->machine->driver_data<deco_mlc_state>();
231   return state->mlc_vram[offset]&0xffff;
234232}
235233
236234static READ32_HANDLER(stadhr96_prot_146_r)
r10427r10428
262260
263261static ADDRESS_MAP_START( decomlc_map, ADDRESS_SPACE_PROGRAM, 32 )
264262   AM_RANGE(0x0000000, 0x00fffff) AM_ROM AM_MIRROR(0xff000000)
265   AM_RANGE(0x0100000, 0x011ffff) AM_RAM AM_BASE(&mlc_ram) AM_MIRROR(0xff000000)
263   AM_RANGE(0x0100000, 0x011ffff) AM_RAM AM_BASE_MEMBER(deco_mlc_state, mlc_ram) AM_MIRROR(0xff000000)
266264   AM_RANGE(0x0200000, 0x020000f) AM_READNOP AM_MIRROR(0xff000000)/* IRQ control? */
267265   AM_RANGE(0x0200070, 0x0200073) AM_READ(decomlc_vbl_r) AM_MIRROR(0xff000000)
268266   AM_RANGE(0x0200074, 0x0200077) AM_READ(mlc_scanline_r) AM_MIRROR(0xff000000)
269267   AM_RANGE(0x0200078, 0x020007f) AM_READ(test2_r)   AM_MIRROR(0xff000000)
270   AM_RANGE(0x0200000, 0x020007f) AM_WRITE(mlc_irq_w) AM_BASE(&irq_ram) AM_MIRROR(0xff000000)
271   AM_RANGE(0x0200080, 0x02000ff) AM_RAM AM_BASE(&mlc_clip_ram) AM_MIRROR(0xff000000)
268   AM_RANGE(0x0200000, 0x020007f) AM_WRITE(mlc_irq_w) AM_BASE_MEMBER(deco_mlc_state, irq_ram) AM_MIRROR(0xff000000)
269   AM_RANGE(0x0200080, 0x02000ff) AM_RAM AM_BASE_MEMBER(deco_mlc_state, mlc_clip_ram) AM_MIRROR(0xff000000)
272270   AM_RANGE(0x0204000, 0x0206fff) AM_RAM_READ(mlc_spriteram_r) AM_BASE_SIZE_GENERIC(spriteram) AM_MIRROR(0xff000000)
273   AM_RANGE(0x0280000, 0x029ffff) AM_RAM_READ(mlc_vram_r) AM_BASE(&mlc_vram) AM_MIRROR(0xff000000)
271   AM_RANGE(0x0280000, 0x029ffff) AM_RAM_READ(mlc_vram_r) AM_BASE_MEMBER(deco_mlc_state, mlc_vram) AM_MIRROR(0xff000000)
274272   AM_RANGE(0x0300000, 0x0307fff) AM_RAM_WRITE(avengrs_palette_w) AM_BASE_GENERIC(paletteram) AM_MIRROR(0xff000000)
275273   AM_RANGE(0x0400000, 0x0400003) AM_READ_PORT("INPUTS") AM_MIRROR(0xff000000)
276274   AM_RANGE(0x0440000, 0x044001f) AM_READ(test3_r)   AM_MIRROR(0xff000000)
r10427r10428
374372
375373static MACHINE_RESET( mlc )
376374{
377   vbl_i = 0xffffffff;
378   raster_irq_timer = machine->device<timer_device>("int_timer");
375   deco_mlc_state *state = machine->driver_data<deco_mlc_state>();
376   state->vbl_i = 0xffffffff;
377   state->raster_irq_timer = machine->device<timer_device>("int_timer");
379378}
380379
381static MACHINE_CONFIG_START( avengrgs, driver_device )
380static MACHINE_CONFIG_START( avengrgs, deco_mlc_state )
382381
383382   /* basic machine hardware */
384383   MCFG_CPU_ADD("maincpu", SH2,42000000/2) /* 21 MHz clock confirmed on real board */
r10427r10428
411410   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
412411MACHINE_CONFIG_END
413412
414static MACHINE_CONFIG_START( mlc, driver_device )
413static MACHINE_CONFIG_START( mlc, deco_mlc_state )
415414
416415   /* basic machine hardware */
417416   MCFG_CPU_ADD("maincpu", ARM,42000000/6) /* 42 MHz -> 7MHz clock confirmed on real board */
r10427r10428
725724
726725static READ32_HANDLER( avengrgs_speedup_r )
727726{
728   UINT32 a=mlc_ram[0x89a0/4];
727   deco_mlc_state *state = space->machine->driver_data<deco_mlc_state>();
728   UINT32 a=state->mlc_ram[0x89a0/4];
729729   UINT32 p=cpu_get_pc(space->cpu);
730730
731731   if ((p==0x3234 || p==0x32dc) && (a&1)) cpu_spinuntil_int(space->cpu);
r10427r10428
735735
736736static DRIVER_INIT( avengrgs )
737737{
738   deco_mlc_state *state = machine->driver_data<deco_mlc_state>();
738739   // init options
739740   sh2drc_set_options(machine->device("maincpu"), SH2DRC_FASTEST_OPTIONS);
740741
r10427r10428
742743   sh2drc_add_pcflush(machine->device("maincpu"), 0x3234);
743744   sh2drc_add_pcflush(machine->device("maincpu"), 0x32dc);
744745
745   mainCpuIsArm = 0;
746   state->mainCpuIsArm = 0;
746747   memory_install_read32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x01089a0, 0x01089a3, 0, 0, avengrgs_speedup_r );
747748   descramble_sound(machine);
748749}
749750
750751static DRIVER_INIT( mlc )
751752{
753   deco_mlc_state *state = machine->driver_data<deco_mlc_state>();
752754   /* The timing in the ARM core isn't as accurate as it should be, so bump up the
753755        effective clock rate here to compensate otherwise we have slowdowns in
754756        Skull Fung where there probably shouldn't be. */
755757   machine->device("maincpu")->set_clock_scale(2.0f);
756   mainCpuIsArm = 1;
758   state->mainCpuIsArm = 1;
757759   deco156_decrypt(machine);
758760   descramble_sound(machine);
759761}
src/mame/drivers/bfm_sc1.c
r10427r10428
9393#include "sound/upd7759.h"
9494#include "machine/nvram.h"
9595#include "bfm_sc1.lh"
96
97
98class bfm_sc1_state : public driver_device
99{
100public:
101   bfm_sc1_state(running_machine &machine, const driver_device_config_base &config)
102      : driver_device(machine, config) { }
103
104   int mmtr_latch;
105   int triac_latch;
106   int vfd_latch;
107   int irq_status;
108   int optic_pattern;
109   int acia_status;
110   int locked;
111   int is_timer_enabled;
112   int reel_changed;
113   int coin_inhibits;
114   int mux1_outputlatch;
115   int mux1_datalo;
116   int mux1_datahi;
117   int mux1_input;
118   int mux2_outputlatch;
119   int mux2_datalo;
120   int mux2_datahi;
121   int mux2_input;
122   int watchdog_cnt;
123   int watchdog_kicked;
124   UINT8 Lamps[256];
125   UINT8 sc1_Inputs[64];
126   UINT8 codec_data[256];
127};
128
96129#define VFD_RESET  0x20
97130#define VFD_CLOCK1 0x80
98131#define VFD_DATA   0x40
r10427r10428
102135
103136// local vars /////////////////////////////////////////////////////////////
104137
105static int mmtr_latch;        // mechanical meter latch
106static int triac_latch;        // payslide triac latch
107static int vfd_latch;        // vfd latch
108static int irq_status;        // custom chip IRQ status
109static int optic_pattern;     // reel optics
110static int acia_status;        // MC6850 status
111static int locked;           // hardware lock/unlock status (0=unlocked)
112static int is_timer_enabled;
113static int reel_changed;
114static int coin_inhibits;
115static int mux1_outputlatch;
116static int mux1_datalo;
117static int mux1_datahi;
118static int mux1_input;
119138
120static int mux2_outputlatch;
121static int mux2_datalo;
122static int mux2_datahi;
123static int mux2_input;
124139
125static int watchdog_cnt;
126static int watchdog_kicked;
127140
128141// user interface stuff ///////////////////////////////////////////////////
129142
130static UINT8 Lamps[256];        // 256 multiplexed lamps
131static UINT8 sc1_Inputs[64];        // 64? multiplexed inputs
132143
133144///////////////////////////////////////////////////////////////////////////
134145
135static void Scorpion1_SetSwitchState(int strobe, int data, int state)
146static void Scorpion1_SetSwitchState(bfm_sc1_state *drvstate, int strobe, int data, int state)
136147{
137   if ( state ) sc1_Inputs[strobe] |=  (1<<data);
138   else       sc1_Inputs[strobe] &= ~(1<<data);
148   if ( state ) drvstate->sc1_Inputs[strobe] |=  (1<<data);
149   else       drvstate->sc1_Inputs[strobe] &= ~(1<<data);
139150}
140151
141152///////////////////////////////////////////////////////////////////////////
142153#ifdef UNUSED_FUNCTION
143static int Scorpion1_GetSwitchState(int strobe, int data)
154static int Scorpion1_GetSwitchState(bfm_sc1_state *drvstate, int strobe, int data)
144155{
145156   int state = 0;
146157
147   if ( strobe < 7 && data < 8 ) state = (sc1_Inputs[strobe] & (1<<data))?1:0;
158   if ( strobe < 7 && data < 8 ) state = (drvstate->sc1_Inputs[strobe] & (1<<data))?1:0;
148159
149160   return state;
150161}
r10427r10428
160171
161172static INTERRUPT_GEN( timer_irq )
162173{
163   if ( watchdog_kicked )
174   bfm_sc1_state *state = device->machine->driver_data<bfm_sc1_state>();
175   if ( state->watchdog_kicked )
164176   {
165      watchdog_cnt    = 0;
166      watchdog_kicked = 0;
177      state->watchdog_cnt    = 0;
178      state->watchdog_kicked = 0;
167179   }
168180   else
169181   {
170      watchdog_cnt++;
171      if ( watchdog_cnt > 2 )   // this is a hack, i don't know what the watchdog timeout is, 3 IRQ's works fine
182      state->watchdog_cnt++;
183      if ( state->watchdog_cnt > 2 )   // this is a hack, i don't know what the watchdog timeout is, 3 IRQ's works fine
172184      {  // reset board
173185         device->machine->schedule_soft_reset();// reset entire machine. CPU 0 should be enough, but that doesn't seem to work !!
174186         return;
175187      }
176188   }
177189
178   if ( is_timer_enabled )
190   if ( state->is_timer_enabled )
179191   {
180      irq_status = 0x01 |0x02; //0xff;
192      state->irq_status = 0x01 |0x02; //0xff;
181193
182       sc1_Inputs[2] = input_port_read(device->machine,"STROBE0");
194       state->sc1_Inputs[2] = input_port_read(device->machine,"STROBE0");
183195
184196      generic_pulse_irq_line(device->machine->device("maincpu"), M6809_IRQ_LINE);
185197   }
r10427r10428
189201
190202static READ8_HANDLER( irqlatch_r )
191203{
192   int result = irq_status | 0x02;
204   bfm_sc1_state *state = space->machine->driver_data<bfm_sc1_state>();
205   int result = state->irq_status | 0x02;
193206
194   irq_status = 0;
207   state->irq_status = 0;
195208
196209   return result;
197210}
r10427r10428
200213
201214static WRITE8_HANDLER( reel12_w )
202215{
203   if ( locked & 0x01 )
204   {   // hardware is still locked,
205      if ( data == 0x46 ) locked &= ~0x01;
216   bfm_sc1_state *state = space->machine->driver_data<bfm_sc1_state>();
217   if ( state->locked & 0x01 )
218   {   // hardware is still state->locked,
219      if ( data == 0x46 ) state->locked &= ~0x01;
206220   }
207221   else
208222   {
209      if ( stepper_update(0, data>>4) ) reel_changed |= 0x01;
210      if ( stepper_update(1, data   ) ) reel_changed |= 0x02;
223      if ( stepper_update(0, data>>4) ) state->reel_changed |= 0x01;
224      if ( stepper_update(1, data   ) ) state->reel_changed |= 0x02;
211225
212      if ( stepper_optic_state(0) ) optic_pattern |=  0x01;
213      else                          optic_pattern &= ~0x01;
214      if ( stepper_optic_state(1) ) optic_pattern |=  0x02;
215      else                          optic_pattern &= ~0x02;
226      if ( stepper_optic_state(0) ) state->optic_pattern |=  0x01;
227      else                          state->optic_pattern &= ~0x01;
228      if ( stepper_optic_state(1) ) state->optic_pattern |=  0x02;
229      else                          state->optic_pattern &= ~0x02;
216230   }
217231   awp_draw_reel(0);
218232   awp_draw_reel(1);
r10427r10428
222236
223237static WRITE8_HANDLER( reel34_w )
224238{
225   if ( locked & 0x02 )
226   {   // hardware is still locked,
227      if ( data == 0x42 ) locked &= ~0x02;
239   bfm_sc1_state *state = space->machine->driver_data<bfm_sc1_state>();
240   if ( state->locked & 0x02 )
241   {   // hardware is still state->locked,
242      if ( data == 0x42 ) state->locked &= ~0x02;
228243   }
229244   else
230245   {
231      if ( stepper_update(2, data>>4) ) reel_changed |= 0x04;
232      if ( stepper_update(3, data   ) ) reel_changed |= 0x08;
246      if ( stepper_update(2, data>>4) ) state->reel_changed |= 0x04;
247      if ( stepper_update(3, data   ) ) state->reel_changed |= 0x08;
233248
234      if ( stepper_optic_state(2) ) optic_pattern |=  0x04;
235      else                          optic_pattern &= ~0x04;
236      if ( stepper_optic_state(3) ) optic_pattern |=  0x08;
237      else                          optic_pattern &= ~0x08;
249      if ( stepper_optic_state(2) ) state->optic_pattern |=  0x04;
250      else                          state->optic_pattern &= ~0x04;
251      if ( stepper_optic_state(3) ) state->optic_pattern |=  0x08;
252      else                          state->optic_pattern &= ~0x08;
238253   }
239254   awp_draw_reel(2);
240255   awp_draw_reel(3);
r10427r10428
244259
245260static WRITE8_HANDLER( reel56_w )
246261{
247   if ( stepper_update(4, data>>4) ) reel_changed |= 0x10;
248   if ( stepper_update(5, data   ) ) reel_changed |= 0x20;
262   bfm_sc1_state *state = space->machine->driver_data<bfm_sc1_state>();
263   if ( stepper_update(4, data>>4) ) state->reel_changed |= 0x10;
264   if ( stepper_update(5, data   ) ) state->reel_changed |= 0x20;
249265
250   if ( stepper_optic_state(4) ) optic_pattern |=  0x10;
251   else                          optic_pattern &= ~0x10;
252   if ( stepper_optic_state(5) ) optic_pattern |=  0x20;
253   else                          optic_pattern &= ~0x20;
266   if ( stepper_optic_state(4) ) state->optic_pattern |=  0x10;
267   else                          state->optic_pattern &= ~0x10;
268   if ( stepper_optic_state(5) ) state->optic_pattern |=  0x20;
269   else                          state->optic_pattern &= ~0x20;
254270   awp_draw_reel(5);
255271   awp_draw_reel(6);
256272}
r10427r10428
261277
262278static WRITE8_HANDLER( mmtr_w )
263279{
280   bfm_sc1_state *state = space->machine->driver_data<bfm_sc1_state>();
264281   int i;
265   if ( locked & 0x04 )
266   {   // hardware is still locked,
267      locked &= ~0x04;
282   if ( state->locked & 0x04 )
283   {   // hardware is still state->locked,
284      state->locked &= ~0x04;
268285   }
269286   else
270287   {
271      int  changed = mmtr_latch ^ data;
288      int  changed = state->mmtr_latch ^ data;
272289
273      mmtr_latch = data;
290      state->mmtr_latch = data;
274291
275292      for (i=0; i<8; i++)
276293      {
r10427r10428
287304
288305static READ8_HANDLER( mmtr_r )
289306{
290   return mmtr_latch;
307   bfm_sc1_state *state = space->machine->driver_data<bfm_sc1_state>();
308   return state->mmtr_latch;
291309}
292310
293311///////////////////////////////////////////////////////////////////////////
r10427r10428
308326
309327static WRITE8_HANDLER( vfd_w )
310328{
311   int changed = vfd_latch ^ data;
329   bfm_sc1_state *state = space->machine->driver_data<bfm_sc1_state>();
330   int changed = state->vfd_latch ^ data;
312331
313   vfd_latch = data;
332   state->vfd_latch = data;
314333
315334   if ( changed )
316335   {
r10427r10428
388407
389408static READ8_HANDLER( mux1latch_r )
390409{
391   return mux1_input;
410   bfm_sc1_state *state = space->machine->driver_data<bfm_sc1_state>();
411   return state->mux1_input;
392412}
393413
394414/////////////////////////////////////////////////////////////////////////////////////
r10427r10428
409429
410430static WRITE8_HANDLER( mux1latch_w )
411431{
412   int changed = mux1_outputlatch ^ data;
432   bfm_sc1_state *state = space->machine->driver_data<bfm_sc1_state>();
433   int changed = state->mux1_outputlatch ^ data;
413434   static const char *const portnames[] = { "STROBE0", "STROBE1", "STROBE2", "STROBE3", "STROBE4", "STROBE5", "STROBE6", "STROBE7" };
414   mux1_outputlatch = data;
435   state->mux1_outputlatch = data;
415436
416437   if ( changed & 0x08 )
417438   { // clock changed
r10427r10428
427448
428449         for ( i = 0; i < 8; i++ )
429450         {
430            Lamps[ BFM_strcnv[offset  ] ] = mux1_datalo & pattern?1:0;
431            Lamps[ BFM_strcnv[offset+8] ] = mux1_datahi & pattern?1:0;
451            state->Lamps[ BFM_strcnv[offset  ] ] = state->mux1_datalo & pattern?1:0;
452            state->Lamps[ BFM_strcnv[offset+8] ] = state->mux1_datahi & pattern?1:0;
432453            pattern<<=1;
433454            offset++;
434455         }
r10427r10428
437458         {
438459            for ( i = 0; i < 256; i++ )
439460            {
440               output_set_lamp_value(i, Lamps[i]);
461               output_set_lamp_value(i, state->Lamps[i]);
441462            }
442463         }
443464      }
444465
445466      if ( !(data & 0x08) )
446467      {
447         sc1_Inputs[ input_strobe ] = input_port_read(space->machine,portnames[input_strobe]);
468         state->sc1_Inputs[ input_strobe ] = input_port_read(space->machine,portnames[input_strobe]);
448469
449         mux1_input = sc1_Inputs[ input_strobe ];
470         state->mux1_input = state->sc1_Inputs[ input_strobe ];
450471      }
451472   }
452473}
r10427r10428
455476
456477static WRITE8_HANDLER( mux1datlo_w )
457478{
458   mux1_datalo = data;
479   bfm_sc1_state *state = space->machine->driver_data<bfm_sc1_state>();
480   state->mux1_datalo = data;
459481}
460482
461483/////////////////////////////////////////////////////////////////////////////////////
462484
463485static WRITE8_HANDLER( mux1dathi_w )
464486{
465   mux1_datahi = data;
487   bfm_sc1_state *state = space->machine->driver_data<bfm_sc1_state>();
488   state->mux1_datahi = data;
466489}
467490
468491/////////////////////////////////////////////////////////////////////////////////////
469492
470493static READ8_HANDLER( mux2latch_r )
471494{
472   return mux2_input;
495   bfm_sc1_state *state = space->machine->driver_data<bfm_sc1_state>();
496   return state->mux2_input;
473497}
474498
475499/////////////////////////////////////////////////////////////////////////////////////
r10427r10428
490514
491515static WRITE8_HANDLER( mux2latch_w )
492516{
493   int changed = mux2_outputlatch ^ data;
517   bfm_sc1_state *state = space->machine->driver_data<bfm_sc1_state>();
518   int changed = state->mux2_outputlatch ^ data;
494519
495   mux2_outputlatch = data;
520   state->mux2_outputlatch = data;
496521
497522   if ( changed & 0x08 )
498523   { // clock changed
r10427r10428
507532
508533         for ( i = 0; i < 8; i++ )
509534         {
510            Lamps[ BFM_strcnv[offset  ] ] = mux2_datalo & pattern?1:0;
511            Lamps[ BFM_strcnv[offset+8] ] = mux2_datahi & pattern?1:0;
535            state->Lamps[ BFM_strcnv[offset  ] ] = state->mux2_datalo & pattern?1:0;
536            state->Lamps[ BFM_strcnv[offset+8] ] = state->mux2_datahi & pattern?1:0;
512537            pattern<<=1;
513538            offset++;
514539         }
r10427r10428
516541
517542      if ( !(data & 0x08) )
518543      {
519         mux2_input = 0x3F ^ optic_pattern;
544         state->mux2_input = 0x3F ^ state->optic_pattern;
520545      }
521546   }
522547}
r10427r10428
525550
526551static WRITE8_HANDLER( mux2datlo_w )
527552{
528   mux2_datalo = data;
553   bfm_sc1_state *state = space->machine->driver_data<bfm_sc1_state>();
554   state->mux2_datalo = data;
529555}
530556
531557/////////////////////////////////////////////////////////////////////////////////////
532558
533559static WRITE8_HANDLER( mux2dathi_w )
534560{
535   mux2_datahi = data;
561   bfm_sc1_state *state = space->machine->driver_data<bfm_sc1_state>();
562   state->mux2_datahi = data;
536563}
537564
538565/////////////////////////////////////////////////////////////////////////////////////
539566
540567static WRITE8_HANDLER( watchdog_w )
541568{
542   watchdog_kicked = 1;
569   bfm_sc1_state *state = space->machine->driver_data<bfm_sc1_state>();
570   state->watchdog_kicked = 1;
543571}
544572
545573/////////////////////////////////////////////////////////////////////////////////////
r10427r10428
560588
561589static READ8_HANDLER( aciastat_r )
562590{
563   return acia_status;
591   bfm_sc1_state *state = space->machine->driver_data<bfm_sc1_state>();
592   return state->acia_status;
564593}
565594
566595/////////////////////////////////////////////////////////////////////////////////////
r10427r10428
576605
577606static WRITE8_HANDLER( triac_w )
578607{
579   triac_latch = data;
608   bfm_sc1_state *state = space->machine->driver_data<bfm_sc1_state>();
609   state->triac_latch = data;
580610}
581611
582612/////////////////////////////////////////////////////////////////////////////////////
583613
584614static READ8_HANDLER( triac_r )
585615{
586   return triac_latch;
616   bfm_sc1_state *state = space->machine->driver_data<bfm_sc1_state>();
617   return state->triac_latch;
587618}
588619
589620/////////////////////////////////////////////////////////////////////////////////////
r10427r10428
653684   0
654685};
655686
656static UINT8 codec_data[256];
657687
658688
659689static void decode_sc1(running_machine *machine,const char *rom_region)
660690{
691   bfm_sc1_state *state = machine->driver_data<bfm_sc1_state>();
661692   UINT8 *tmp, *rom;
662693
663694   rom = machine->region(rom_region)->base();
r10427r10428
685716            pattern <<= 1;
686717         } while ( *(++tab) );
687718
688      codec_data[i] = newdata;
719      state->codec_data[i] = newdata;
689720      }
690721
691722      for ( address = 0; address < 0x10000; address++)
r10427r10428
702733            pattern <<= 1;
703734         } while ( *(++tab) );
704735
705         rom[newaddress] = codec_data[ tmp[address] ];
736         rom[newaddress] = state->codec_data[ tmp[address] ];
706737      }
707738      auto_free( machine, tmp );
708739   }
r10427r10428
711742
712743static MACHINE_RESET( bfm_sc1 )
713744{
745   bfm_sc1_state *state = machine->driver_data<bfm_sc1_state>();
714746   BFM_BD1_init(0);
715   vfd_latch         = 0;
716   mmtr_latch        = 0;
717   triac_latch       = 0;
718   irq_status        = 0;
719   is_timer_enabled  = 1;
720   coin_inhibits     = 0;
721   mux1_outputlatch  = 0x08;   // clock HIGH
722   mux1_datalo       = 0;
723   mux1_datahi        = 0;
724   mux1_input        = 0;
725   mux2_outputlatch  = 0x08;   // clock HIGH
726   mux2_datalo       = 0;
727   mux2_datahi        = 0;
728   mux2_input        = 0;
747   state->vfd_latch         = 0;
748   state->mmtr_latch        = 0;
749   state->triac_latch       = 0;
750   state->irq_status        = 0;
751   state->is_timer_enabled  = 1;
752   state->coin_inhibits     = 0;
753   state->mux1_outputlatch  = 0x08;   // clock HIGH
754   state->mux1_datalo       = 0;
755   state->mux1_datahi        = 0;
756   state->mux1_input        = 0;
757   state->mux2_outputlatch  = 0x08;   // clock HIGH
758   state->mux2_datalo       = 0;
759   state->mux2_datahi        = 0;
760   state->mux2_input        = 0;
729761
730762   BFM_BD1_reset(0);   // reset display1
731763   BFM_BD1_reset(1);   // reset display2
r10427r10428
741773         if ( stepper_optic_state(i) ) pattern |= 1<<i;
742774      }
743775
744      optic_pattern = pattern;
776      state->optic_pattern = pattern;
745777
746778   }
747779
748   acia_status   = 0x02; // MC6850 transmit buffer empty !!!
749   locked        = 0x07; // hardware is locked
780   state->acia_status   = 0x02; // MC6850 transmit buffer empty !!!
781   state->locked        = 0x07; // hardware is state->locked
750782
751783// init rom bank ////////////////////////////////////////////////////////////////////
752784   {
r10427r10428
12401272// machine driver for scorpion1 board ///////////////////////////////////////////////
12411273/////////////////////////////////////////////////////////////////////////////////////
12421274
1243static MACHINE_CONFIG_START( scorpion1, driver_device )
1275static MACHINE_CONFIG_START( scorpion1, bfm_sc1_state )
12441276   MCFG_MACHINE_RESET(bfm_sc1)                     // main scorpion1 board initialisation
12451277   MCFG_CPU_ADD("maincpu", M6809, MASTER_CLOCK/4)         // 6809 CPU at 1 Mhz
12461278   MCFG_CPU_PROGRAM_MAP(memmap)                  // setup read and write memorymap
r10427r10428
13351367
13361368static void sc1_common_init(running_machine *machine, int reels, int decrypt)
13371369{
1370   bfm_sc1_state *state = machine->driver_data<bfm_sc1_state>();
13381371   UINT8 *rom, i;
13391372
13401373   rom = machine->region("maincpu")->base();
r10427r10428
13431376      memcpy(&rom[0x10000], &rom[0x00000], 0x2000);
13441377   }
13451378
1346   memset(sc1_Inputs, 0, sizeof(sc1_Inputs));
1379   memset(state->sc1_Inputs, 0, sizeof(state->sc1_Inputs));
13471380
13481381   // setup n default 96 half step reels ///////////////////////////////////////////
13491382   for ( i = 0; i < reels; i++ )
r10427r10428
13891422
13901423static DRIVER_INIT(clatt)
13911424{
1425   bfm_sc1_state *state = machine->driver_data<bfm_sc1_state>();
13921426   sc1_common_init(machine,6,1);
13931427   MechMtr_config(machine,8);
13941428
13951429   BFM_BD1_init(0);
13961430
1397   Scorpion1_SetSwitchState(3,2,1);
1398   Scorpion1_SetSwitchState(3,3,1);
1399   Scorpion1_SetSwitchState(3,6,1);
1400   Scorpion1_SetSwitchState(4,1,1);
1431   Scorpion1_SetSwitchState(state,3,2,1);
1432   Scorpion1_SetSwitchState(state,3,3,1);
1433   Scorpion1_SetSwitchState(state,3,6,1);
1434   Scorpion1_SetSwitchState(state,4,1,1);
14011435}
14021436
14031437/////////////////////////////////////////////////////////////////////////////////////
src/mame/drivers/hornet.c
r10427r10428
322322#include "video/konicdev.h"
323323#include "rendlay.h"
324324
325static UINT8 led_reg0, led_reg1;
326static UINT32 *workram;
327static UINT32 *sharc_dataram[2];
328static UINT8 *jvs_sdata;
329static UINT32 jvs_sdata_ptr = 0;
330325
331static emu_timer *sound_irq_timer;
326class hornet_state : public driver_device
327{
328public:
329   hornet_state(running_machine &machine, const driver_device_config_base &config)
330      : driver_device(machine, config) { }
332331
332   UINT8 led_reg0;
333   UINT8 led_reg1;
334   UINT32 *workram;
335   UINT32 *sharc_dataram[2];
336   UINT8 *jvs_sdata;
337   UINT32 jvs_sdata_ptr;
338   emu_timer *sound_irq_timer;
339   UINT16 gn680_latch;
340   UINT16 gn680_ret0;
341   UINT16 gn680_ret1;
342};
343
344
345
346
333347static READ32_HANDLER( hornet_k037122_sram_r )
334348{
335349   device_t *k037122 = space->machine->device(get_cgboard_id() ? "k037122_2" : "k037122_1");
r10427r10428
379393
380394static VIDEO_UPDATE( hornet )
381395{
396   hornet_state *state = screen->machine->driver_data<hornet_state>();
382397   device_t *voodoo = screen->machine->device("voodoo0");
383398   device_t *k037122 = screen->machine->device("k037122_1");
384399
r10427r10428
386401
387402   k037122_tile_draw(k037122, bitmap, cliprect);
388403
389   draw_7segment_led(bitmap, 3, 3, led_reg0);
390   draw_7segment_led(bitmap, 9, 3, led_reg1);
404   draw_7segment_led(bitmap, 3, 3, state->led_reg0);
405   draw_7segment_led(bitmap, 9, 3, state->led_reg1);
391406   return 0;
392407}
393408
394409static VIDEO_UPDATE( hornet_2board )
395410{
411   hornet_state *state = screen->machine->driver_data<hornet_state>();
396412   if (strcmp(screen->tag(), "lscreen") == 0)
397413   {
398414      device_t *k037122 = screen->machine->device("k037122_1");
r10427r10428
412428      k037122_tile_draw(k037122, bitmap, cliprect);
413429   }
414430
415   draw_7segment_led(bitmap, 3, 3, led_reg0);
416   draw_7segment_led(bitmap, 9, 3, led_reg1);
431   draw_7segment_led(bitmap, 3, 3, state->led_reg0);
432   draw_7segment_led(bitmap, 9, 3, state->led_reg1);
417433   return 0;
418434}
419435
r10427r10428
457473
458474static WRITE8_HANDLER( sysreg_w )
459475{
476   hornet_state *state = space->machine->driver_data<hornet_state>();
460477   device_t *adc12138 = space->machine->device("adc12138");
461478
462479   switch (offset)
463480   {
464481      case 0:   /* LED Register 0 */
465         led_reg0 = data;
482         state->led_reg0 = data;
466483         break;
467484
468485      case 1:   /* LED Register 1 */
469         led_reg1 = data;
486         state->led_reg1 = data;
470487         break;
471488
472489      case 2: /* Parallel data register */
r10427r10428
568585   return 0xffffffff;
569586}
570587
571static UINT16 gn680_latch, gn680_ret0, gn680_ret1;
572588
573589static READ32_HANDLER(gun_r)
574590{
575   return gn680_ret0<<16 | gn680_ret1;
591   hornet_state *state = space->machine->driver_data<hornet_state>();
592   return state->gn680_ret0<<16 | state->gn680_ret1;
576593}
577594
578595static WRITE32_HANDLER(gun_w)
579596{
597   hornet_state *state = space->machine->driver_data<hornet_state>();
580598   if (mem_mask == 0xffff0000)
581599   {
582      gn680_latch = data>>16;
600      state->gn680_latch = data>>16;
583601      cputag_set_input_line(space->machine, "gn680", M68K_IRQ_6, HOLD_LINE);
584602   }
585603}
r10427r10428
587605/*****************************************************************************/
588606
589607static ADDRESS_MAP_START( hornet_map, ADDRESS_SPACE_PROGRAM, 32 )
590   AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_BASE(&workram)      /* Work RAM */
608   AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_BASE_MEMBER(hornet_state, workram)      /* Work RAM */
591609   AM_RANGE(0x74000000, 0x740000ff) AM_READWRITE(hornet_k037122_reg_r, hornet_k037122_reg_w)
592610   AM_RANGE(0x74020000, 0x7403ffff) AM_READWRITE(hornet_k037122_sram_r, hornet_k037122_sram_w)
593611   AM_RANGE(0x74040000, 0x7407ffff) AM_READWRITE(hornet_k037122_char_r, hornet_k037122_char_w)
r10427r10428
631649
632650static READ16_HANDLER(gn680_latch_r)
633651{
652   hornet_state *state = space->machine->driver_data<hornet_state>();
634653   cputag_set_input_line(space->machine, "gn680", M68K_IRQ_6, CLEAR_LINE);
635654
636   return gn680_latch;
655   return state->gn680_latch;
637656}
638657
639658static WRITE16_HANDLER(gn680_latch_w)
640659{
660   hornet_state *state = space->machine->driver_data<hornet_state>();
641661   if (offset)
642662   {
643      gn680_ret1 = data;
663      state->gn680_ret1 = data;
644664   }
645665   else
646666   {
647      gn680_ret0 = data;
667      state->gn680_ret0 = data;
648668   }
649669}
650670
r10427r10428
664684
665685static READ32_HANDLER( dsp_dataram0_r )
666686{
667   return sharc_dataram[0][offset] & 0xffff;
687   hornet_state *state = space->machine->driver_data<hornet_state>();
688   return state->sharc_dataram[0][offset] & 0xffff;
668689}
669690
670691static WRITE32_HANDLER( dsp_dataram0_w )
671692{
672   sharc_dataram[0][offset] = data;
693   hornet_state *state = space->machine->driver_data<hornet_state>();
694   state->sharc_dataram[0][offset] = data;
673695}
674696
675697static READ32_HANDLER( dsp_dataram1_r )
676698{
677   return sharc_dataram[1][offset] & 0xffff;
699   hornet_state *state = space->machine->driver_data<hornet_state>();
700   return state->sharc_dataram[1][offset] & 0xffff;
678701}
679702
680703static WRITE32_HANDLER( dsp_dataram1_w )
681704{
682   sharc_dataram[1][offset] = data;
705   hornet_state *state = space->machine->driver_data<hornet_state>();
706   state->sharc_dataram[1][offset] = data;
683707}
684708
685709static ADDRESS_MAP_START( sharc0_map, ADDRESS_SPACE_DATA, 32 )
686710   AM_RANGE(0x0400000, 0x041ffff) AM_READWRITE(cgboard_0_shared_sharc_r, cgboard_0_shared_sharc_w)
687   AM_RANGE(0x0500000, 0x05fffff) AM_READWRITE(dsp_dataram0_r, dsp_dataram0_w) AM_BASE(&sharc_dataram[0])
711   AM_RANGE(0x0500000, 0x05fffff) AM_READWRITE(dsp_dataram0_r, dsp_dataram0_w) AM_BASE_MEMBER(hornet_state, sharc_dataram[0])
688712   AM_RANGE(0x1400000, 0x14fffff) AM_RAM
689713   AM_RANGE(0x2400000, 0x27fffff) AM_DEVREADWRITE("voodoo0", voodoo_r, voodoo_w)
690714   AM_RANGE(0x3400000, 0x34000ff) AM_READWRITE(cgboard_0_comm_sharc_r, cgboard_0_comm_sharc_w)
r10427r10428
694718
695719static ADDRESS_MAP_START( sharc1_map, ADDRESS_SPACE_DATA, 32 )
696720   AM_RANGE(0x0400000, 0x041ffff) AM_READWRITE(cgboard_1_shared_sharc_r, cgboard_1_shared_sharc_w)
697   AM_RANGE(0x0500000, 0x05fffff) AM_READWRITE(dsp_dataram1_r, dsp_dataram1_w) AM_BASE(&sharc_dataram[1])
721   AM_RANGE(0x0500000, 0x05fffff) AM_READWRITE(dsp_dataram1_r, dsp_dataram1_w) AM_BASE_MEMBER(hornet_state, sharc_dataram[1])
698722   AM_RANGE(0x1400000, 0x14fffff) AM_RAM
699723   AM_RANGE(0x2400000, 0x27fffff) AM_DEVREADWRITE("voodoo1", voodoo_r, voodoo_w)
700724   AM_RANGE(0x3400000, 0x34000ff) AM_READWRITE(cgboard_1_comm_sharc_r, cgboard_1_comm_sharc_w)
r10427r10428
834858
835859static MACHINE_START( hornet )
836860{
837   jvs_sdata_ptr = 0;
838   jvs_sdata = auto_alloc_array_clear(machine, UINT8, 1024);
861   hornet_state *state = machine->driver_data<hornet_state>();
862   state->jvs_sdata_ptr = 0;
863   state->jvs_sdata = auto_alloc_array_clear(machine, UINT8, 1024);
839864
840865   /* set conservative DRC options */
841866   ppcdrc_set_options(machine->device("maincpu"), PPCDRC_COMPATIBLE_OPTIONS);
842867
843868   /* configure fast RAM regions for DRC */
844   ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x003fffff, FALSE, workram);
869   ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x003fffff, FALSE, state->workram);
845870
846   state_save_register_global(machine, led_reg0);
847   state_save_register_global(machine, led_reg1);
848   state_save_register_global_pointer(machine, jvs_sdata, 1024);
849   state_save_register_global(machine, jvs_sdata_ptr);
871   state_save_register_global(machine, state->led_reg0);
872   state_save_register_global(machine, state->led_reg1);
873   state_save_register_global_pointer(machine, state->jvs_sdata, 1024);
874   state_save_register_global(machine, state->jvs_sdata_ptr);
850875
851    sound_irq_timer = machine->scheduler().timer_alloc(FUNC(irq_off));
876   state->sound_irq_timer = machine->scheduler().timer_alloc(FUNC(irq_off));
852877}
853878
854879static MACHINE_RESET( hornet )
r10427r10428
883908
884909static void sound_irq_callback( running_machine *machine, int irq )
885910{
911   hornet_state *state = machine->driver_data<hornet_state>();
886912   int line = (irq == 0) ? INPUT_LINE_IRQ1 : INPUT_LINE_IRQ2;
887913
888914   cputag_set_input_line(machine, "audiocpu", line, ASSERT_LINE);
889    sound_irq_timer->adjust(attotime::from_usec(1), line);
915    state->sound_irq_timer->adjust(attotime::from_usec(1), line);
890916}
891917
892918static const k056800_interface hornet_k056800_interface =
r10427r10428
919945   "rscreen", 1
920946};
921947
922static MACHINE_CONFIG_START( hornet, driver_device )
948static MACHINE_CONFIG_START( hornet, hornet_state )
923949
924950   /* basic machine hardware */
925951   MCFG_CPU_ADD("maincpu", PPC403GA, 64000000/2)   /* PowerPC 403GA 32MHz */
r10427r10428
10631089
10641090static void jamma_jvs_w(device_t *device, UINT8 data)
10651091{
1066   if (jvs_sdata_ptr == 0 && data != 0xe0)
1092   hornet_state *state = device->machine->driver_data<hornet_state>();
1093   if (state->jvs_sdata_ptr == 0 && data != 0xe0)
10671094      return;
1068   jvs_sdata[jvs_sdata_ptr] = data;
1069   jvs_sdata_ptr++;
1095   state->jvs_sdata[state->jvs_sdata_ptr] = data;
1096   state->jvs_sdata_ptr++;
10701097
1071   if (jvs_sdata_ptr >= 3 && jvs_sdata_ptr >= 3 + jvs_sdata[2])
1098   if (state->jvs_sdata_ptr >= 3 && state->jvs_sdata_ptr >= 3 + state->jvs_sdata[2])
10721099      jamma_jvs_cmd_exec(device->machine);
10731100}
10741101
r10427r10428
11251152
11261153static void jamma_jvs_cmd_exec(running_machine *machine)
11271154{
1155   hornet_state *state = machine->driver_data<hornet_state>();
11281156   UINT8 sync, node, byte_num;
11291157   UINT8 data[1024], rdata[1024];
11301158#if 0
r10427r10428
11331161   int rdata_ptr;
11341162   int sum;
11351163
1136   sync = jvs_sdata[0];
1137   node = jvs_sdata[1];
1138   byte_num = jvs_sdata[2];
1164   sync = state->jvs_sdata[0];
1165   node = state->jvs_sdata[1];
1166   byte_num = state->jvs_sdata[2];
11391167
11401168#if 0
11411169   length =
11421170#endif
1143      jvs_decode_data(&jvs_sdata[3], data, byte_num-1);
1171      jvs_decode_data(&state->jvs_sdata[3], data, byte_num-1);
11441172#if 0
11451173    printf("jvs input data:\n");
11461174    for (i=0; i < byte_num; i++)
11471175    {
1148        printf("%02X ", jvs_sdata[3+i]);
1176        printf("%02X ", state->jvs_sdata[3+i]);
11491177    }
11501178    printf("\n");
11511179
r10427r10428
11941222   sum += jvs_encode_data(machine, rdata, rdata_ptr);
11951223   ppc4xx_spu_receive_byte(machine->device("maincpu"), sum - 1);      // checksum
11961224
1197   jvs_sdata_ptr = 0;
1225   state->jvs_sdata_ptr = 0;
11981226}
11991227
12001228/*****************************************************************************/
r10427r10428
12021230
12031231static DRIVER_INIT(hornet)
12041232{
1233   hornet_state *state = machine->driver_data<hornet_state>();
12051234   init_konami_cgboard(machine, 1, CGBOARD_TYPE_HORNET);
12061235   set_cgboard_texture_bank(machine, 0, "bank5", machine->region("user5")->base());
12071236
1208   led_reg0 = led_reg1 = 0x7f;
1237   state->led_reg0 = state->led_reg1 = 0x7f;
12091238
12101239   ppc4xx_spu_set_tx_handler(machine->device("maincpu"), jamma_jvs_w);
12111240}
12121241
12131242static DRIVER_INIT(hornet_2board)
12141243{
1244   hornet_state *state = machine->driver_data<hornet_state>();
12151245   init_konami_cgboard(machine, 2, CGBOARD_TYPE_HORNET);
12161246   set_cgboard_texture_bank(machine, 0, "bank5", machine->region("user5")->base());
12171247   set_cgboard_texture_bank(machine, 1, "bank6", machine->region("user5")->base());
12181248
1219   led_reg0 = led_reg1 = 0x7f;
1249   state->led_reg0 = state->led_reg1 = 0x7f;
12201250
12211251   ppc4xx_spu_set_tx_handler(machine->device("maincpu"), jamma_jvs_w);
12221252}
src/mame/drivers/powerins.c
r10427r10428
4343
4444***************************************************************************/
4545
46static int oki_bank;
4746
4847static WRITE16_HANDLER( powerins_okibank_w )
4948{
49   powerins_state *state = space->machine->driver_data<powerins_state>();
5050   if (ACCESSING_BITS_0_7)
5151   {
5252      UINT8 *RAM = space->machine->region("oki1")->base();
5353      int new_bank = data & 0x7;
5454
55      if (new_bank != oki_bank)
55      if (new_bank != state->oki_bank)
5656      {
57         oki_bank = new_bank;
57         state->oki_bank = new_bank;
5858         memcpy(&RAM[0x30000],&RAM[0x40000 + 0x10000*new_bank],0x10000);
5959      }
6060   }
r10427r10428
8484   AM_RANGE(0x10001e, 0x10001f) AM_WRITE(powerins_soundlatch_w)                        // Sound Latch
8585   AM_RANGE(0x100030, 0x100031) AM_WRITE(powerins_okibank_w)                           // Sound
8686   AM_RANGE(0x120000, 0x120fff) AM_RAM_WRITE(powerins_paletteram16_w) AM_BASE_GENERIC(paletteram)   // Palette
87   AM_RANGE(0x130000, 0x130007) AM_RAM AM_BASE(&powerins_vctrl_0)                        // VRAM 0 Control
88   AM_RANGE(0x140000, 0x143fff) AM_RAM_WRITE(powerins_vram_0_w) AM_BASE(&powerins_vram_0)      // VRAM 0
89   AM_RANGE(0x170000, 0x170fff) AM_RAM_WRITE(powerins_vram_1_w) AM_BASE(&powerins_vram_1)      // VRAM 1
87   AM_RANGE(0x130000, 0x130007) AM_RAM AM_BASE_MEMBER(powerins_state, vctrl_0)                        // VRAM 0 Control
88   AM_RANGE(0x140000, 0x143fff) AM_RAM_WRITE(powerins_vram_0_w) AM_BASE_MEMBER(powerins_state, vram_0)      // VRAM 0
89   AM_RANGE(0x170000, 0x170fff) AM_RAM_WRITE(powerins_vram_1_w) AM_BASE_MEMBER(powerins_state, vram_1)      // VRAM 1
9090   AM_RANGE(0x171000, 0x171fff) AM_WRITE(powerins_vram_1_w)                           // Mirror of VRAM 1?
9191   AM_RANGE(0x180000, 0x18ffff) AM_RAM AM_BASE_GENERIC(spriteram)                           // RAM + Sprites
9292ADDRESS_MAP_END
r10427r10428
105105   AM_RANGE(0x100030, 0x100031) AM_WRITE(powerins_okibank_w)                           // Sound
106106   AM_RANGE(0x10003e, 0x10003f) AM_DEVREADWRITE8_MODERN("oki1", okim6295_device, read, write, 0x00ff)      // (used by powerina)
107107   AM_RANGE(0x120000, 0x120fff) AM_RAM_WRITE(powerins_paletteram16_w) AM_BASE_GENERIC(paletteram)   // Palette
108   AM_RANGE(0x130000, 0x130007) AM_RAM AM_BASE(&powerins_vctrl_0)                        // VRAM 0 Control
109   AM_RANGE(0x140000, 0x143fff) AM_RAM_WRITE(powerins_vram_0_w) AM_BASE(&powerins_vram_0)      // VRAM 0
110   AM_RANGE(0x170000, 0x170fff) AM_RAM_WRITE(powerins_vram_1_w) AM_BASE(&powerins_vram_1)      // VRAM 1
108   AM_RANGE(0x130000, 0x130007) AM_RAM AM_BASE_MEMBER(powerins_state, vctrl_0)                        // VRAM 0 Control
109   AM_RANGE(0x140000, 0x143fff) AM_RAM_WRITE(powerins_vram_0_w) AM_BASE_MEMBER(powerins_state, vram_0)      // VRAM 0
110   AM_RANGE(0x170000, 0x170fff) AM_RAM_WRITE(powerins_vram_1_w) AM_BASE_MEMBER(powerins_state, vram_1)      // VRAM 1
111111   AM_RANGE(0x171000, 0x171fff) AM_WRITE(powerins_vram_1_w)                           // Mirror of VRAM 1?
112112   AM_RANGE(0x180000, 0x18ffff) AM_RAM AM_BASE_GENERIC(spriteram)                           // RAM + Sprites
113113ADDRESS_MAP_END
r10427r10428
315315
316316static MACHINE_RESET( powerins )
317317{
318   oki_bank = -1;   // samples bank "unitialised"
318   powerins_state *state = machine->driver_data<powerins_state>();
319   state->oki_bank = -1;   // samples bank "unitialised"
319320}
320321
321322static void irqhandler(device_t *device, int irq)
r10427r10428
339340};
340341
341342
342static MACHINE_CONFIG_START( powerins, driver_device )
343static MACHINE_CONFIG_START( powerins, powerins_state )
343344
344345   /* basic machine hardware */
345346   MCFG_CPU_ADD("maincpu", M68000, 12000000)   /* 12MHz */
src/mame/drivers/zn.c
r10427r10428
2323#include "sound/2610intf.h"
2424#include "sound/ymz280b.h"
2525#include "sound/qsound.h"
26#include "sound/psx.h"
26#include "sound/spu.h"
2727#include "sound/ymf271.h"
2828#include "audio/taito_zm.h"
2929
r10427r10428
422422   AM_RANGE(0x1f800000, 0x1f8003ff) AM_RAM /* scratchpad */
423423   AM_RANGE(0x1f801000, 0x1f80100f) AM_RAM /* ?? */
424424   AM_RANGE(0x1f801010, 0x1f801013) AM_NOP
425   AM_RANGE(0x1f801014, 0x1f801017) AM_DEVREADWRITE("spu", psx_spu_delay_r, psx_spu_delay_w)
425   AM_RANGE(0x1f801014, 0x1f801017) AM_RAM
426426   AM_RANGE(0x1f801018, 0x1f80101f) AM_NOP
427427   AM_RANGE(0x1f801020, 0x1f801023) AM_READWRITE(psx_com_delay_r, psx_com_delay_w)
428428   AM_RANGE(0x1f801024, 0x1f80102f) AM_NOP
r10427r10428
433433   AM_RANGE(0x1f801100, 0x1f80112f) AM_READWRITE(psx_counter_r, psx_counter_w)
434434   AM_RANGE(0x1f801810, 0x1f801817) AM_READWRITE(psx_gpu_r, psx_gpu_w)
435435   AM_RANGE(0x1f801820, 0x1f801827) AM_READWRITE(psx_mdec_r, psx_mdec_w)
436   AM_RANGE(0x1f801c00, 0x1f801dff) AM_DEVREADWRITE("spu", psx_spu_r, psx_spu_w)
436   AM_RANGE(0x1f801c00, 0x1f801dff) AM_READWRITE16(spu_r, spu_w, 0xffffffff)
437437   AM_RANGE(0x1f802020, 0x1f802033) AM_RAM /* ?? */
438438   AM_RANGE(0x1f802040, 0x1f802043) AM_WRITENOP
439439   AM_RANGE(0x1fa00000, 0x1fa00003) AM_READ_PORT("P1")
r10427r10428
487487
488488static void psx_spu_irq(device_t *device, UINT32 data)
489489{
490   psx_irq_set(device->machine, data);
490   if (data)
491   {
492      psx_irq_set(device->machine, 1<<9);
493   }
491494}
492495
493static const psx_spu_interface psxspu_interface =
494{
495   psx_spu_irq,
496   psx_dma_install_read_handler,
497   psx_dma_install_write_handler
498};
499
500496static void zn_machine_init( running_machine *machine )
501497{
502498   zn_state *state = machine->driver_data<zn_state>();
r10427r10428
529525   /* sound hardware */
530526   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
531527
532   MCFG_SOUND_ADD( "spu", PSXSPU, 0 )
533   MCFG_SOUND_CONFIG( psxspu_interface )
528   MCFG_SPU_ADD( "spu", XTAL_67_7376MHz/2, &psx_spu_irq )
534529   MCFG_SOUND_ROUTE(0, "lspeaker", 0.35)
535530   MCFG_SOUND_ROUTE(1, "rspeaker", 0.35)
536531
r10427r10428
566561   /* sound hardware */
567562   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
568563
569   MCFG_SOUND_ADD( "spu", PSXSPU, 0 )
570   MCFG_SOUND_CONFIG( psxspu_interface )
564   MCFG_SPU_ADD( "spu", XTAL_67_7376MHz/2, &psx_spu_irq )
571565   MCFG_SOUND_ROUTE(0, "lspeaker", 0.35)
572566   MCFG_SOUND_ROUTE(1, "rspeaker", 0.35)
573567
r10427r10428
13181312   memory_install_read_bank     ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1f000000, 0x1f7fffff, 0, 0, "bank1" ); /* banked game rom */
13191313   memory_install_readwrite_bank( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fb00000, 0x1fb00000 + ( state->taitofx1_eeprom_size1 - 1 ), 0, 0, "bank2" );
13201314   memory_install_write32_handler    ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fb40000, 0x1fb40003, 0, 0, bank_coh1000t_w ); /* bankswitch */
1321   memory_install_write32_handler    ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fb80000, 0x1fb80003, 0, 0, taitofx1b_volume_w );
1322   memory_install_write32_handler    ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fba0000, 0x1fba0003, 0, 0, taitofx1b_sound_w );
1315   memory_install_write32_handler    ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fb80000, 0x1fb8ffff, 0, 0, taitofx1b_volume_w );
1316   memory_install_write32_handler    ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fba0000, 0x1fbaffff, 0, 0, taitofx1b_sound_w );
13231317   memory_install_read32_handler     ( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fbc0000, 0x1fbc0003, 0, 0, taitofx1b_sound_r );
13241318   memory_install_readwrite_bank( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x1fbe0000, 0x1fbe0000 + ( state->taitofx1_eeprom_size2 - 1 ), 0, 0, "bank3" );
13251319
src/mame/drivers/deco32.c
r10427r10428
237237#include "sound/okim6295.h"
238238#include "sound/bsmt2000.h"
239239
240static UINT32 *deco32_ram;
241static int raster_enable;
242static timer_device *raster_irq_timer;
243static UINT8 nslasher_sound_irq;
244240
245241/**********************************************************************************/
246242
247243
248244static WRITE32_HANDLER( deco32_pf12_control_w )
249245{
250   COMBINE_DATA(&deco32_pf12_control[offset]);
246   deco32_state *state = space->machine->driver_data<deco32_state>();
247   COMBINE_DATA(&state->pf12_control[offset]);
251248   space->machine->primary_screen->update_partial(space->machine->primary_screen->vpos());
252249}
253250
254251
255252static WRITE32_HANDLER( deco32_pf34_control_w )
256253{
257   COMBINE_DATA(&deco32_pf34_control[offset]);
254   deco32_state *state = space->machine->driver_data<deco32_state>();
255   COMBINE_DATA(&state->pf34_control[offset]);
258256   space->machine->primary_screen->update_partial(space->machine->primary_screen->vpos());
259257}
260258
r10427r10428
303301
304302static WRITE32_HANDLER( deco32_irq_controller_w )
305303{
304   deco32_state *state = space->machine->driver_data<deco32_state>();
306305   int scanline;
307306
308307   switch (offset) {
309308   case 0: /* IRQ enable - probably an irq mask, but only values used are 0xc8 and 0xca */
310309//      logerror("%08x:  IRQ write %d %08x\n",cpu_get_pc(space->cpu),offset,data);
311      raster_enable=(data&0xff)==0xc8; /* 0xca seems to be off */
310      state->raster_enable=(data&0xff)==0xc8; /* 0xca seems to be off */
312311      break;
313312
314313   case 1: /* Raster IRQ scanline position, only valid for values between 1 & 239 (0 and 240-256 do NOT generate IRQ's) */
315314      scanline=(data&0xff);
316      if (raster_enable && scanline>0 && scanline<240)
315      if (state->raster_enable && scanline>0 && scanline<240)
317316      {
318317         // needs +16 for the raster to align on captaven intro? (might just be our screen size / visible area / layer offsets need adjusting instead)
319         raster_irq_timer->adjust(space->machine->primary_screen->time_until_pos(scanline+16, 320));
318         state->raster_irq_timer->adjust(space->machine->primary_screen->time_until_pos(scanline+16, 320));
320319      }
321320      else
322         raster_irq_timer->reset();
321         state->raster_irq_timer->reset();
323322      break;
324323   case 2: /* VBL irq ack */
325324      break;
r10427r10428
404403
405404static READ32_HANDLER( dragngun_prot_r )
406405{
406   deco32_state *state = space->machine->driver_data<deco32_state>();
407407//  logerror("%08x:Read prot %08x (%08x)\n",cpu_get_pc(space->cpu),offset<<1,mem_mask);
408408
409   static int strobe=0;
410   if (!strobe) strobe=8;
411   else strobe=0;
409   if (!state->strobe) state->strobe=8;
410   else state->strobe=0;
412411
413412//definitely vblank in locked load
414413
415414   switch (offset<<1) {
416415   case 0x140/2: return 0xffff0000 | input_port_read(space->machine, "IN0"); /* IN0 */
417   case 0xadc/2: return 0xffff0000 | input_port_read(space->machine, "IN1") | strobe; /* IN1 */
416   case 0xadc/2: return 0xffff0000 | input_port_read(space->machine, "IN1") | state->strobe; /* IN1 */
418417   case 0x6a0/2: return 0xffff0000 | input_port_read(space->machine, "DSW"); /* IN2 (Dip switch) */
419418   }
420419   return 0xffffffff;
421420}
422421
423static int dragngun_lightgun_port;
424422
425423static READ32_HANDLER( dragngun_lightgun_r )
426424{
425   deco32_state *state = space->machine->driver_data<deco32_state>();
427426   /* Ports 0-3 are read, but seem unused */
428   switch (dragngun_lightgun_port) {
427   switch (state->dragngun_lightgun_port) {
429428   case 4: return input_port_read(space->machine, "LIGHT0_X");
430429   case 5: return input_port_read(space->machine, "LIGHT1_X");
431430   case 6: return input_port_read(space->machine, "LIGHT0_Y");
432431   case 7: return input_port_read(space->machine, "LIGHT1_Y");
433432   }
434433
435//  logerror("Illegal lightgun port %d read \n",dragngun_lightgun_port);
434//  logerror("Illegal lightgun port %d read \n",state->dragngun_lightgun_port);
436435   return 0;
437436}
438437
439438static WRITE32_HANDLER( dragngun_lightgun_w )
440439{
441//  logerror("Lightgun port %d\n",dragngun_lightgun_port);
442   dragngun_lightgun_port=offset;
440   deco32_state *state = space->machine->driver_data<deco32_state>();
441//  logerror("Lightgun port %d\n",state->dragngun_lightgun_port);
442   state->dragngun_lightgun_port=offset;
443443}
444444
445445static READ32_DEVICE_HANDLER( dragngun_eeprom_r )
r10427r10428
460460
461461/**********************************************************************************/
462462
463static int tattass_eprom_bit;
464463
465464static READ32_HANDLER( tattass_prot_r )
466465{
466   deco32_state *state = space->machine->driver_data<deco32_state>();
467467   switch (offset<<1) {
468468   case 0x280: return input_port_read(space->machine, "IN0") << 16;
469469   case 0x4c4: return input_port_read(space->machine, "IN1") << 16;
470   case 0x35a: return tattass_eprom_bit << 16;
470   case 0x35a: return state->tattass_eprom_bit << 16;
471471   }
472472
473473   logerror("%08x:Read prot %08x (%08x)\n",cpu_get_pc(space->cpu),offset<<1,mem_mask);
r10427r10428
488488
489489static WRITE32_HANDLER( tattass_control_w )
490490{
491   static int lastClock=0;
492   static char buffer[32];
493   static int bufPtr=0;
494   static int pendingCommand=0; /* 1 = read, 2 = write */
495   static int readBitCount=0;
496   static int byteAddr=0;
491   deco32_state *state = space->machine->driver_data<deco32_state>();
497492   eeprom_device *eeprom = space->machine->device<eeprom_device>("eeprom");
498493   address_space *eeprom_space = eeprom->space();
499494
r10427r10428
520515
521516        */
522517      if ((data&0x40)==0) {
523         if (bufPtr) {
518         if (state->bufPtr) {
524519            int i;
525            logerror("Eprom reset (bit count %d): ",readBitCount);
526            for (i=0; i<bufPtr; i++)
527               logerror("%s",buffer[i] ? "1" : "0");
520            logerror("Eprom reset (bit count %d): ",state->readBitCount);
521            for (i=0; i<state->bufPtr; i++)
522               logerror("%s",state->buffer[i] ? "1" : "0");
528523            logerror("\n");
529524
530525         }
531         bufPtr=0;
532         pendingCommand=0;
533         readBitCount=0;
526         state->bufPtr=0;
527         state->pendingCommand=0;
528         state->readBitCount=0;
534529      }
535530
536531      /* Eprom has been clocked */
537      if (lastClock==0 && data&0x20 && data&0x40) {
538         if (bufPtr>=32) {
532      if (state->lastClock==0 && data&0x20 && data&0x40) {
533         if (state->bufPtr>=32) {
539534            logerror("Eprom overflow!");
540            bufPtr=0;
535            state->bufPtr=0;
541536         }
542537
543538         /* Handle pending read */
544         if (pendingCommand==1) {
545            int d=readBitCount/8;
546            int m=7-(readBitCount%8);
547            int a=(byteAddr+d)%1024;
539         if (state->pendingCommand==1) {
540            int d=state->readBitCount/8;
541            int m=7-(state->readBitCount%8);
542            int a=(state->byteAddr+d)%1024;
548543            int b=eeprom_space->read_byte(a);
549544
550            tattass_eprom_bit=(b>>m)&1;
545            state->tattass_eprom_bit=(b>>m)&1;
551546
552            readBitCount++;
553            lastClock=data&0x20;
547            state->readBitCount++;
548            state->lastClock=data&0x20;
554549            return;
555550         }
556551
557552         /* Handle pending write */
558         if (pendingCommand==2) {
559            buffer[bufPtr++]=(data&0x10)>>4;
553         if (state->pendingCommand==2) {
554            state->buffer[state->bufPtr++]=(data&0x10)>>4;
560555
561            if (bufPtr==32) {
562               int b=(buffer[24]<<7)|(buffer[25]<<6)|(buffer[26]<<5)|(buffer[27]<<4)
563                  |(buffer[28]<<3)|(buffer[29]<<2)|(buffer[30]<<1)|(buffer[31]<<0);
556            if (state->bufPtr==32) {
557               int b=(state->buffer[24]<<7)|(state->buffer[25]<<6)|(state->buffer[26]<<5)|(state->buffer[27]<<4)
558                  |(state->buffer[28]<<3)|(state->buffer[29]<<2)|(state->buffer[30]<<1)|(state->buffer[31]<<0);
564559
565               eeprom_space->write_byte(byteAddr, b);
560               eeprom_space->write_byte(state->byteAddr, b);
566561            }
567            lastClock=data&0x20;
562            state->lastClock=data&0x20;
568563            return;
569564         }
570565
571         buffer[bufPtr++]=(data&0x10)>>4;
572         if (bufPtr==24) {
566         state->buffer[state->bufPtr++]=(data&0x10)>>4;
567         if (state->bufPtr==24) {
573568            /* Decode addr */
574            byteAddr=(buffer[3]<<9)|(buffer[4]<<8)
575                  |(buffer[16]<<7)|(buffer[17]<<6)|(buffer[18]<<5)|(buffer[19]<<4)
576                  |(buffer[20]<<3)|(buffer[21]<<2)|(buffer[22]<<1)|(buffer[23]<<0);
569            state->byteAddr=(state->buffer[3]<<9)|(state->buffer[4]<<8)
570                  |(state->buffer[16]<<7)|(state->buffer[17]<<6)|(state->buffer[18]<<5)|(state->buffer[19]<<4)
571                  |(state->buffer[20]<<3)|(state->buffer[21]<<2)|(state->buffer[22]<<1)|(state->buffer[23]<<0);
577572
578573            /* Check for read command */
579            if (buffer[0] && buffer[1]) {
580               tattass_eprom_bit=(eeprom_space->read_byte(byteAddr)>>7)&1;
581               readBitCount=1;
582               pendingCommand=1;
574            if (state->buffer[0] && state->buffer[1]) {
575               state->tattass_eprom_bit=(eeprom_space->read_byte(state->byteAddr)>>7)&1;
576               state->readBitCount=1;
577               state->pendingCommand=1;
583578            }
584579
585580            /* Check for write command */
586            else if (buffer[0]==0x0 && buffer[1]==0x0) {
587               pendingCommand=2;
581            else if (state->buffer[0]==0x0 && state->buffer[1]==0x0) {
582               state->pendingCommand=2;
588583            }
589584            else {
590585               logerror("Detected unknown eprom command\n");
r10427r10428
594589      } else {
595590         if (!(data&0x40)) {
596591            logerror("Cs set low\n");
597            bufPtr=0;
592            state->bufPtr=0;
598593         }
599594      }
600595
601      lastClock=data&0x20;
596      state->lastClock=data&0x20;
602597      return;
603598   }
604599
r10427r10428
655650
656651static WRITE32_HANDLER( nslasher_prot_w )
657652{
653   deco32_state *state = space->machine->driver_data<deco32_state>();
658654   //logerror("%08x:write prot %08x (%08x) %08x\n",cpu_get_pc(space->cpu),offset<<1,mem_mask,data);
659655
660656   /* Only sound port of chip is used - no protection */
r10427r10428
662658
663659      /* bit 1 of nslasher_sound_irq specifies IRQ command writes */
664660      soundlatch_w(space,0,(data>>16)&0xff);
665      nslasher_sound_irq |= 0x02;
666      cputag_set_input_line(space->machine, "audiocpu", 0, (nslasher_sound_irq != 0) ? ASSERT_LINE : CLEAR_LINE);
661      state->nslasher_sound_irq |= 0x02;
662      cputag_set_input_line(space->machine, "audiocpu", 0, (state->nslasher_sound_irq != 0) ? ASSERT_LINE : CLEAR_LINE);
667663   }
668664}
669665
r10427r10428
676672   AM_RANGE(0x100000, 0x100003) AM_WRITE(buffer_spriteram32_w)
677673   AM_RANGE(0x108000, 0x108003) AM_WRITENOP /* ? */
678674   AM_RANGE(0x110000, 0x110fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) /* Sprites */
679   AM_RANGE(0x120000, 0x127fff) AM_RAM AM_BASE(&deco32_ram) /* Main RAM */
675   AM_RANGE(0x120000, 0x127fff) AM_RAM AM_BASE_MEMBER(deco32_state, ram) /* Main RAM */
680676   AM_RANGE(0x128000, 0x128fff) AM_READ(captaven_prot_r)
681677   AM_RANGE(0x1280c8, 0x1280cb) AM_WRITE(deco32_sound_w)
682678   AM_RANGE(0x130000, 0x131fff) AM_RAM_WRITE(deco32_nonbuffered_palette_w) AM_BASE_GENERIC(paletteram) /* Palette RAM */
r10427r10428
686682
687683   AM_RANGE(0x178000, 0x178003) AM_WRITE(deco32_pri_w)
688684
689   AM_RANGE(0x180000, 0x18001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE(&deco32_pf12_control)
690   AM_RANGE(0x190000, 0x191fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE(&deco32_pf1_data)
685   AM_RANGE(0x180000, 0x18001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE_MEMBER(deco32_state, pf12_control)
686   AM_RANGE(0x190000, 0x191fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE_MEMBER(deco32_state, pf1_data)
691687   AM_RANGE(0x192000, 0x193fff) AM_WRITE(deco32_pf1_data_w) /* Mirror address - bug in program code */
692   AM_RANGE(0x194000, 0x195fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE(&deco32_pf2_data)
693   AM_RANGE(0x1a0000, 0x1a1fff) AM_RAM AM_BASE(&deco32_pf1_rowscroll)
694   AM_RANGE(0x1a4000, 0x1a5fff) AM_RAM AM_BASE(&deco32_pf2_rowscroll)
688   AM_RANGE(0x194000, 0x195fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE_MEMBER(deco32_state, pf2_data)
689   AM_RANGE(0x1a0000, 0x1a1fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf1_rowscroll)
690   AM_RANGE(0x1a4000, 0x1a5fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf2_rowscroll)
695691
696   AM_RANGE(0x1c0000, 0x1c001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE(&deco32_pf34_control)
697   AM_RANGE(0x1d0000, 0x1d1fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE(&deco32_pf3_data)
698   AM_RANGE(0x1e0000, 0x1e1fff) AM_RAM AM_BASE(&deco32_pf3_rowscroll)
692   AM_RANGE(0x1c0000, 0x1c001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE_MEMBER(deco32_state, pf34_control)
693   AM_RANGE(0x1d0000, 0x1d1fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE_MEMBER(deco32_state, pf3_data)
694   AM_RANGE(0x1e0000, 0x1e1fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf3_rowscroll)
699695ADDRESS_MAP_END
700696
701697static ADDRESS_MAP_START( fghthist_map, ADDRESS_SPACE_PROGRAM, 32 )
702698   AM_RANGE(0x000000, 0x001fff) AM_ROM AM_WRITE(deco32_pf1_data_w)
703699   AM_RANGE(0x000000, 0x0fffff) AM_ROM
704   AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE(&deco32_ram)
700   AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE_MEMBER(deco32_state, ram)
705701   AM_RANGE(0x120020, 0x12002f) AM_READ(fghthist_control_r)
706702   AM_RANGE(0x12002c, 0x12002f) AM_WRITE(fghthist_eeprom_w)
707703   AM_RANGE(0x1201fc, 0x1201ff) AM_WRITE(deco32_sound_w)
r10427r10428
715711   AM_RANGE(0x179000, 0x179fff) AM_RAM AM_BASE_GENERIC(spriteram2) // ?
716712   AM_RANGE(0x17c010, 0x17c013) AM_WRITE(buffer_spriteram32_w)
717713
718   AM_RANGE(0x182000, 0x183fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE(&deco32_pf1_data)
719   AM_RANGE(0x184000, 0x185fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE(&deco32_pf2_data)
720   AM_RANGE(0x192000, 0x192fff) AM_RAM AM_BASE(&deco32_pf1_rowscroll)
721   AM_RANGE(0x194000, 0x194fff) AM_RAM AM_BASE(&deco32_pf2_rowscroll)
722   AM_RANGE(0x1a0000, 0x1a001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE(&deco32_pf12_control)
714   AM_RANGE(0x182000, 0x183fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE_MEMBER(deco32_state, pf1_data)
715   AM_RANGE(0x184000, 0x185fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE_MEMBER(deco32_state, pf2_data)
716   AM_RANGE(0x192000, 0x192fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf1_rowscroll)
717   AM_RANGE(0x194000, 0x194fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf2_rowscroll)
718   AM_RANGE(0x1a0000, 0x1a001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE_MEMBER(deco32_state, pf12_control)
723719
724   AM_RANGE(0x1c2000, 0x1c3fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE(&deco32_pf3_data)
725   AM_RANGE(0x1c4000, 0x1c5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE(&deco32_pf4_data)
726   AM_RANGE(0x1d2000, 0x1d2fff) AM_RAM AM_BASE(&deco32_pf3_rowscroll)
727   AM_RANGE(0x1d4000, 0x1d4fff) AM_RAM AM_BASE(&deco32_pf4_rowscroll)
728   AM_RANGE(0x1e0000, 0x1e001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE(&deco32_pf34_control)
720   AM_RANGE(0x1c2000, 0x1c3fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE_MEMBER(deco32_state, pf3_data)
721   AM_RANGE(0x1c4000, 0x1c5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE_MEMBER(deco32_state, pf4_data)
722   AM_RANGE(0x1d2000, 0x1d2fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf3_rowscroll)
723   AM_RANGE(0x1d4000, 0x1d4fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf4_rowscroll)
724   AM_RANGE(0x1e0000, 0x1e001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE_MEMBER(deco32_state, pf34_control)
729725
730726   AM_RANGE(0x16c000, 0x16c01f) AM_READNOP
731727   AM_RANGE(0x17c000, 0x17c03f) AM_READNOP
r10427r10428
736732
737733static ADDRESS_MAP_START( fghthsta_memmap, ADDRESS_SPACE_PROGRAM, 32 )
738734   AM_RANGE(0x000000, 0x0fffff) AM_ROM
739   AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE(&deco32_ram)
735   AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE_MEMBER(deco32_state, ram)
740736   AM_RANGE(0x140000, 0x140003) AM_WRITENOP /* VBL irq ack */
741737   AM_RANGE(0x150000, 0x150003) AM_WRITE(fghthist_eeprom_w) /* Volume port/Eprom */
742738
r10427r10428
748744   AM_RANGE(0x17c010, 0x17c013) AM_WRITE(buffer_spriteram32_w)
749745   AM_RANGE(0x17c020, 0x17c023) AM_READNOP
750746
751   AM_RANGE(0x182000, 0x183fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE(&deco32_pf1_data)
752   AM_RANGE(0x184000, 0x185fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE(&deco32_pf2_data)
753   AM_RANGE(0x192000, 0x192fff) AM_RAM AM_BASE(&deco32_pf1_rowscroll)
754   AM_RANGE(0x194000, 0x194fff) AM_RAM AM_BASE(&deco32_pf2_rowscroll)
755   AM_RANGE(0x1a0000, 0x1a001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE(&deco32_pf12_control)
747   AM_RANGE(0x182000, 0x183fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE_MEMBER(deco32_state, pf1_data)
748   AM_RANGE(0x184000, 0x185fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE_MEMBER(deco32_state, pf2_data)
749   AM_RANGE(0x192000, 0x192fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf1_rowscroll)
750   AM_RANGE(0x194000, 0x194fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf2_rowscroll)
751   AM_RANGE(0x1a0000, 0x1a001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE_MEMBER(deco32_state, pf12_control)
756752
757   AM_RANGE(0x1c2000, 0x1c3fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE(&deco32_pf3_data)
758   AM_RANGE(0x1c4000, 0x1c5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE(&deco32_pf4_data)
759   AM_RANGE(0x1d2000, 0x1d2fff) AM_RAM AM_BASE(&deco32_pf3_rowscroll)
760   AM_RANGE(0x1d4000, 0x1d4fff) AM_RAM AM_BASE(&deco32_pf4_rowscroll)
761   AM_RANGE(0x1e0000, 0x1e001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE(&deco32_pf34_control)
753   AM_RANGE(0x1c2000, 0x1c3fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE_MEMBER(deco32_state, pf3_data)
754   AM_RANGE(0x1c4000, 0x1c5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE_MEMBER(deco32_state, pf4_data)
755   AM_RANGE(0x1d2000, 0x1d2fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf3_rowscroll)
756   AM_RANGE(0x1d4000, 0x1d4fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf4_rowscroll)
757   AM_RANGE(0x1e0000, 0x1e001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE_MEMBER(deco32_state, pf34_control)
762758
763759   AM_RANGE(0x200000, 0x200fff) AM_READWRITE(deco16_146_fghthist_prot_r, deco16_146_fghthist_prot_w) AM_BASE(&deco32_prot_ram)
764760ADDRESS_MAP_END
r10427r10428
767763// raster effects appear to need some work on it anyway?
768764static ADDRESS_MAP_START( dragngun_map, ADDRESS_SPACE_PROGRAM, 32 )
769765   AM_RANGE(0x000000, 0x0fffff) AM_ROM
770   AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE(&deco32_ram)
766   AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE_MEMBER(deco32_state, ram)
771767   AM_RANGE(0x120000, 0x120fff) AM_READ(dragngun_prot_r)
772768   AM_RANGE(0x1204c0, 0x1204c3) AM_WRITE(deco32_sound_w)
773769   AM_RANGE(0x128000, 0x12800f) AM_READWRITE(deco32_irq_controller_r, deco32_irq_controller_w)
r10427r10428
775771   AM_RANGE(0x138000, 0x138003) AM_NOP /* Palette dma complete in bit 0x8? ack?  return 0 else tight loop */
776772   AM_RANGE(0x138008, 0x13800b) AM_WRITE(deco32_palette_dma_w)
777773
778//  AM_RANGE(0x180000, 0x18001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE(&deco32_pf12_control)
779   AM_RANGE(0x180000, 0x18001f) AM_RAM AM_BASE(&deco32_pf12_control)
780   AM_RANGE(0x190000, 0x191fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE(&deco32_pf1_data)
781   AM_RANGE(0x194000, 0x195fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE(&deco32_pf2_data)
782   AM_RANGE(0x1a0000, 0x1a0fff) AM_RAM AM_BASE(&deco32_pf1_rowscroll)
783   AM_RANGE(0x1a4000, 0x1a4fff) AM_RAM AM_BASE(&deco32_pf2_rowscroll)
774//  AM_RANGE(0x180000, 0x18001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE_MEMBER(deco32_state, pf12_control)
775   AM_RANGE(0x180000, 0x18001f) AM_RAM AM_BASE_MEMBER(deco32_state, pf12_control)
776   AM_RANGE(0x190000, 0x191fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE_MEMBER(deco32_state, pf1_data)
777   AM_RANGE(0x194000, 0x195fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE_MEMBER(deco32_state, pf2_data)
778   AM_RANGE(0x1a0000, 0x1a0fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf1_rowscroll)
779   AM_RANGE(0x1a4000, 0x1a4fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf2_rowscroll)
784780
785//  AM_RANGE(0x1c0000, 0x1c001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE(&deco32_pf34_control)
786   AM_RANGE(0x1c0000, 0x1c001f) AM_RAM AM_BASE(&deco32_pf34_control)
787   AM_RANGE(0x1d0000, 0x1d1fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE(&deco32_pf3_data)
788   AM_RANGE(0x1d4000, 0x1d5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE(&deco32_pf4_data)
789   AM_RANGE(0x1e0000, 0x1e0fff) AM_RAM AM_BASE(&deco32_pf3_rowscroll)
790   AM_RANGE(0x1e4000, 0x1e4fff) AM_RAM AM_BASE(&deco32_pf4_rowscroll)
781//  AM_RANGE(0x1c0000, 0x1c001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE_MEMBER(deco32_state, pf34_control)
782   AM_RANGE(0x1c0000, 0x1c001f) AM_RAM AM_BASE_MEMBER(deco32_state, pf34_control)
783   AM_RANGE(0x1d0000, 0x1d1fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE_MEMBER(deco32_state, pf3_data)
784   AM_RANGE(0x1d4000, 0x1d5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE_MEMBER(deco32_state, pf4_data)
785   AM_RANGE(0x1e0000, 0x1e0fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf3_rowscroll)
786   AM_RANGE(0x1e4000, 0x1e4fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf4_rowscroll)
791787
792788   AM_RANGE(0x204800, 0x204fff) AM_RAM // ace? 0x10 byte increments only  // 13f ff stuff
793789
794790
795   AM_RANGE(0x208000, 0x208fff) AM_RAM AM_BASE(&dragngun_sprite_layout_0_ram)
796   AM_RANGE(0x20c000, 0x20cfff) AM_RAM AM_BASE(&dragngun_sprite_layout_1_ram)
797   AM_RANGE(0x210000, 0x217fff) AM_RAM AM_BASE(&dragngun_sprite_lookup_0_ram)
798   AM_RANGE(0x218000, 0x21ffff) AM_RAM AM_BASE(&dragngun_sprite_lookup_1_ram)
791   AM_RANGE(0x208000, 0x208fff) AM_RAM AM_BASE_MEMBER(deco32_state, dragngun_sprite_layout_0_ram)
792   AM_RANGE(0x20c000, 0x20cfff) AM_RAM AM_BASE_MEMBER(deco32_state, dragngun_sprite_layout_1_ram)
793   AM_RANGE(0x210000, 0x217fff) AM_RAM AM_BASE_MEMBER(deco32_state, dragngun_sprite_lookup_0_ram)
794   AM_RANGE(0x218000, 0x21ffff) AM_RAM AM_BASE_MEMBER(deco32_state, dragngun_sprite_lookup_1_ram)
799795   AM_RANGE(0x220000, 0x221fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) /* Main spriteram */
800796
801797   AM_RANGE(0x228000, 0x2283ff) AM_RAM //0x10 byte increments only
r10427r10428
816812
817813static ADDRESS_MAP_START( lockload_map, ADDRESS_SPACE_PROGRAM, 32 )
818814   AM_RANGE(0x000000, 0x0fffff) AM_ROM
819   AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE(&deco32_ram)
815   AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE_MEMBER(deco32_state, ram)
820816   AM_RANGE(0x120000, 0x120fff) AM_READ(dragngun_prot_r)
821817   AM_RANGE(0x1204c0, 0x1204c3) AM_WRITE(deco32_sound_w)
822818   AM_RANGE(0x128000, 0x12800f) AM_READWRITE(deco32_irq_controller_r, deco32_irq_controller_w)
r10427r10428
828824   AM_RANGE(0x170000, 0x170007) AM_READ(lockload_gun_mirror_r) /* Not on Dragongun */
829825   AM_RANGE(0x178008, 0x17800f) AM_WRITENOP /* Gun read ACK's */
830826
831//  AM_RANGE(0x180000, 0x18001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE(&deco32_pf12_control)
832   AM_RANGE(0x180000, 0x18001f) AM_RAM AM_BASE(&deco32_pf12_control)
833   AM_RANGE(0x190000, 0x191fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE(&deco32_pf1_data)
834   AM_RANGE(0x194000, 0x195fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE(&deco32_pf2_data)
835   AM_RANGE(0x1a0000, 0x1a0fff) AM_RAM AM_BASE(&deco32_pf1_rowscroll)
836   AM_RANGE(0x1a4000, 0x1a4fff) AM_RAM AM_BASE(&deco32_pf2_rowscroll)
827//  AM_RANGE(0x180000, 0x18001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE_MEMBER(deco32_state, pf12_control)
828   AM_RANGE(0x180000, 0x18001f) AM_RAM AM_BASE_MEMBER(deco32_state, pf12_control)
829   AM_RANGE(0x190000, 0x191fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE_MEMBER(deco32_state, pf1_data)
830   AM_RANGE(0x194000, 0x195fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE_MEMBER(deco32_state, pf2_data)
831   AM_RANGE(0x1a0000, 0x1a0fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf1_rowscroll)
832   AM_RANGE(0x1a4000, 0x1a4fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf2_rowscroll)
837833
838//  AM_RANGE(0x1c0000, 0x1c001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE(&deco32_pf34_control)
839   AM_RANGE(0x1c0000, 0x1c001f) AM_RAM AM_BASE(&deco32_pf34_control)
840   AM_RANGE(0x1d0000, 0x1d1fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE(&deco32_pf3_data)
841   AM_RANGE(0x1d4000, 0x1d5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE(&deco32_pf4_data)
842   AM_RANGE(0x1e0000, 0x1e0fff) AM_RAM AM_BASE(&deco32_pf3_rowscroll)
843   AM_RANGE(0x1e4000, 0x1e4fff) AM_RAM AM_BASE(&deco32_pf4_rowscroll)
834//  AM_RANGE(0x1c0000, 0x1c001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE_MEMBER(deco32_state, pf34_control)
835   AM_RANGE(0x1c0000, 0x1c001f) AM_RAM AM_BASE_MEMBER(deco32_state, pf34_control)
836   AM_RANGE(0x1d0000, 0x1d1fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE_MEMBER(deco32_state, pf3_data)
837   AM_RANGE(0x1d4000, 0x1d5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE_MEMBER(deco32_state, pf4_data)
838   AM_RANGE(0x1e0000, 0x1e0fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf3_rowscroll)
839   AM_RANGE(0x1e4000, 0x1e4fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf4_rowscroll)
844840
845841   AM_RANGE(0x204800, 0x204fff) AM_RAM            //0x10 byte increments only
846   AM_RANGE(0x208000, 0x208fff) AM_RAM AM_BASE(&dragngun_sprite_layout_0_ram)
847   AM_RANGE(0x20c000, 0x20cfff) AM_RAM AM_BASE(&dragngun_sprite_layout_1_ram)
848   AM_RANGE(0x210000, 0x217fff) AM_RAM AM_BASE(&dragngun_sprite_lookup_0_ram)
849   AM_RANGE(0x218000, 0x21ffff) AM_RAM AM_BASE(&dragngun_sprite_lookup_1_ram)
842   AM_RANGE(0x208000, 0x208fff) AM_RAM AM_BASE_MEMBER(deco32_state, dragngun_sprite_layout_0_ram)
843   AM_RANGE(0x20c000, 0x20cfff) AM_RAM AM_BASE_MEMBER(deco32_state, dragngun_sprite_layout_1_ram)
844   AM_RANGE(0x210000, 0x217fff) AM_RAM AM_BASE_MEMBER(deco32_state, dragngun_sprite_lookup_0_ram)
845   AM_RANGE(0x218000, 0x21ffff) AM_RAM AM_BASE_MEMBER(deco32_state, dragngun_sprite_lookup_1_ram)
850846   AM_RANGE(0x220000, 0x221fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) /* Main spriteram */
851847
852848   AM_RANGE(0x228000, 0x2283ff) AM_RAM            //0x10 byte increments only
r10427r10428
866862
867863   AM_RANGE(0x000000, 0x0f7fff) AM_ROM
868864   AM_RANGE(0x0f8000, 0x0fffff) AM_ROM AM_WRITENOP
869   AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE(&deco32_ram)
865   AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE_MEMBER(deco32_state, ram)
870866   AM_RANGE(0x120000, 0x120003) AM_NOP            /* ACIA (unused) */
871867   AM_RANGE(0x130000, 0x130003) AM_WRITENOP      /* Coin port (unused?) */
872868   AM_RANGE(0x140000, 0x140003) AM_WRITENOP      /* Vblank ack */
873869   AM_RANGE(0x150000, 0x150003) AM_WRITE(tattass_control_w) /* Volume port/Eprom/Priority */
874870
875871   AM_RANGE(0x162000, 0x162fff) AM_RAM            /* 'Jack' RAM!? */
876   AM_RANGE(0x163000, 0x16309f) AM_RAM_WRITE(deco32_ace_ram_w) AM_BASE(&deco32_ace_ram)
872   AM_RANGE(0x163000, 0x16309f) AM_RAM_WRITE(deco32_ace_ram_w) AM_BASE_MEMBER(deco32_state, ace_ram)
877873   AM_RANGE(0x164000, 0x164003) AM_WRITENOP /* Palette control BG2/3 ($1a constant) */
878874   AM_RANGE(0x164004, 0x164007) AM_WRITENOP /* Palette control Obj1 ($6 constant) */
879875   AM_RANGE(0x164008, 0x16400b) AM_WRITENOP /* Palette control Obj2 ($5 constant) */
r10427r10428
892888   AM_RANGE(0x17c010, 0x17c013) AM_WRITE(buffer_spriteram32_2_w)
893889   AM_RANGE(0x17c018, 0x17c01b) AM_WRITENOP /* Sprite 'CPU' (unused) */
894890
895   AM_RANGE(0x182000, 0x183fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE(&deco32_pf1_data)
896   AM_RANGE(0x184000, 0x185fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE(&deco32_pf2_data)
897   AM_RANGE(0x192000, 0x193fff) AM_RAM AM_BASE(&deco32_pf1_rowscroll)
898   AM_RANGE(0x194000, 0x195fff) AM_RAM AM_BASE(&deco32_pf2_rowscroll)
899   AM_RANGE(0x1a0000, 0x1a001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE(&deco32_pf12_control)
891   AM_RANGE(0x182000, 0x183fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE_MEMBER(deco32_state, pf1_data)
892   AM_RANGE(0x184000, 0x185fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE_MEMBER(deco32_state, pf2_data)
893   AM_RANGE(0x192000, 0x193fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf1_rowscroll)
894   AM_RANGE(0x194000, 0x195fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf2_rowscroll)
895   AM_RANGE(0x1a0000, 0x1a001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE_MEMBER(deco32_state, pf12_control)
900896
901   AM_RANGE(0x1c2000, 0x1c3fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE(&deco32_pf3_data)
902   AM_RANGE(0x1c4000, 0x1c5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE(&deco32_pf4_data)
903   AM_RANGE(0x1d2000, 0x1d3fff) AM_RAM AM_BASE(&deco32_pf3_rowscroll)
904   AM_RANGE(0x1d4000, 0x1d5fff) AM_RAM AM_BASE(&deco32_pf4_rowscroll)
905   AM_RANGE(0x1e0000, 0x1e001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE(&deco32_pf34_control)
897   AM_RANGE(0x1c2000, 0x1c3fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE_MEMBER(deco32_state, pf3_data)
898   AM_RANGE(0x1c4000, 0x1c5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE_MEMBER(deco32_state, pf4_data)
899   AM_RANGE(0x1d2000, 0x1d3fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf3_rowscroll)
900   AM_RANGE(0x1d4000, 0x1d5fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf4_rowscroll)
901   AM_RANGE(0x1e0000, 0x1e001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE_MEMBER(deco32_state, pf34_control)
906902
907903   AM_RANGE(0x200000, 0x200fff) AM_READWRITE(tattass_prot_r, tattass_prot_w) AM_BASE(&deco32_prot_ram)
908904ADDRESS_MAP_END
909905
910906static ADDRESS_MAP_START( nslasher_map, ADDRESS_SPACE_PROGRAM, 32 )
911907   AM_RANGE(0x000000, 0x0fffff) AM_ROM
912   AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE(&deco32_ram)
908   AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE_MEMBER(deco32_state, ram)
913909   AM_RANGE(0x120000, 0x1200ff) AM_NOP                     /* ACIA (unused) */
914910   AM_RANGE(0x140000, 0x140003) AM_WRITENOP               /* Vblank ack */
915911   AM_RANGE(0x150000, 0x150003) AM_WRITE(nslasher_eeprom_w)   /* Volume port/Eprom/Priority */
916912
917   AM_RANGE(0x163000, 0x16309f) AM_RAM_WRITE(deco32_ace_ram_w) AM_BASE(&deco32_ace_ram) /* 'Ace' RAM!? */
913   AM_RANGE(0x163000, 0x16309f) AM_RAM_WRITE(deco32_ace_ram_w) AM_BASE_MEMBER(deco32_state, ace_ram) /* 'Ace' RAM!? */
918914   AM_RANGE(0x164000, 0x164003) AM_WRITENOP /* Palette control BG2/3 ($1a constant) */
919915   AM_RANGE(0x164004, 0x164007) AM_WRITENOP /* Palette control Obj1 ($4 constant) */
920916   AM_RANGE(0x164008, 0x16400b) AM_WRITENOP /* Palette control Obj2 ($6 constant) */
r10427r10428
932928   AM_RANGE(0x17c010, 0x17c013) AM_WRITE(buffer_spriteram32_2_w)
933929   AM_RANGE(0x17c018, 0x17c01b) AM_WRITENOP /* Sprite 'CPU' (unused) */
934930
935   AM_RANGE(0x182000, 0x183fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE(&deco32_pf1_data)
936   AM_RANGE(0x184000, 0x185fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE(&deco32_pf2_data)
937   AM_RANGE(0x192000, 0x193fff) AM_RAM AM_BASE(&deco32_pf1_rowscroll)
938   AM_RANGE(0x194000, 0x195fff) AM_RAM AM_BASE(&deco32_pf2_rowscroll)
939   AM_RANGE(0x1a0000, 0x1a001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE(&deco32_pf12_control)
931   AM_RANGE(0x182000, 0x183fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE_MEMBER(deco32_state, pf1_data)
932   AM_RANGE(0x184000, 0x185fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE_MEMBER(deco32_state, pf2_data)
933   AM_RANGE(0x192000, 0x193fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf1_rowscroll)
934   AM_RANGE(0x194000, 0x195fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf2_rowscroll)
935   AM_RANGE(0x1a0000, 0x1a001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE_MEMBER(deco32_state, pf12_control)
940936
941   AM_RANGE(0x1c2000, 0x1c3fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE(&deco32_pf3_data)
942   AM_RANGE(0x1c4000, 0x1c5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE(&deco32_pf4_data)
943   AM_RANGE(0x1d2000, 0x1d3fff) AM_RAM AM_BASE(&deco32_pf3_rowscroll)
944   AM_RANGE(0x1d4000, 0x1d5fff) AM_RAM AM_BASE(&deco32_pf4_rowscroll)
945   AM_RANGE(0x1e0000, 0x1e001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE(&deco32_pf34_control)
937   AM_RANGE(0x1c2000, 0x1c3fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE_MEMBER(deco32_state, pf3_data)
938   AM_RANGE(0x1c4000, 0x1c5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE_MEMBER(deco32_state, pf4_data)
939   AM_RANGE(0x1d2000, 0x1d3fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf3_rowscroll)
940   AM_RANGE(0x1d4000, 0x1d5fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf4_rowscroll)
941   AM_RANGE(0x1e0000, 0x1e001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE_MEMBER(deco32_state, pf34_control)
946942
947943   AM_RANGE(0x200000, 0x200fff) AM_READWRITE(nslasher_prot_r, nslasher_prot_w) AM_BASE(&deco32_prot_ram)
948944ADDRESS_MAP_END
949945
950946/******************************************************************************/
951947
952static UINT8 bsmt_latch;
953static UINT8 bsmt_reset;
954948
955949static WRITE8_HANDLER(deco32_bsmt_reset_w)
956950{
957   UINT8 diff = data ^ bsmt_reset;
958   bsmt_reset = data;
951   deco32_state *state = space->machine->driver_data<deco32_state>();
952   UINT8 diff = data ^ state->bsmt_reset;
953   state->bsmt_reset = data;
959954   if ((diff & 0x80) && !(data & 0x80))
960955      devtag_reset(space->machine, "bsmt");
961956}
962957
963958static WRITE8_HANDLER(deco32_bsmt0_w)
964959{
965   bsmt_latch = data;
960   deco32_state *state = space->machine->driver_data<deco32_state>();
961   state->bsmt_latch = data;
966962}
967963
968964static void bsmt_ready_callback(bsmt2000_device &device)
r10427r10428
972968
973969static WRITE8_HANDLER(deco32_bsmt1_w)
974970{
971   deco32_state *state = space->machine->driver_data<deco32_state>();
975972   bsmt2000_device *bsmt = space->machine->device<bsmt2000_device>("bsmt");
976973   bsmt->write_reg(offset ^ 0xff);
977   bsmt->write_data((bsmt_latch << 8) | data);
974   bsmt->write_data((state->bsmt_latch << 8) | data);
978975   cputag_set_input_line(space->machine, "audiocpu", M6809_IRQ_LINE, CLEAR_LINE); /* BSMT is not ready */
979976}
980977
r10427r10428
10071004
10081005static READ8_HANDLER(latch_r)
10091006{
1007   deco32_state *state = space->machine->driver_data<deco32_state>();
10101008   /* bit 1 of nslasher_sound_irq specifies IRQ command writes */
1011   nslasher_sound_irq &= ~0x02;
1012   cputag_set_input_line(space->machine, "audiocpu", 0, (nslasher_sound_irq != 0) ? ASSERT_LINE : CLEAR_LINE);
1009   state->nslasher_sound_irq &= ~0x02;
1010   cputag_set_input_line(space->machine, "audiocpu", 0, (state->nslasher_sound_irq != 0) ? ASSERT_LINE : CLEAR_LINE);
10131011   return soundlatch_r(space,0);
10141012}
10151013
r10427r10428
16121610
16131611static void sound_irq_nslasher(device_t *device, int state)
16141612{
1613   deco32_state *drvstate = device->machine->driver_data<deco32_state>();
16151614   /* bit 0 of nslasher_sound_irq specifies IRQ from sound chip */
16161615   if (state)
1617      nslasher_sound_irq |= 0x01;
1616      drvstate->nslasher_sound_irq |= 0x01;
16181617   else
1619      nslasher_sound_irq &= ~0x01;
1620   cputag_set_input_line(device->machine, "audiocpu", 0, (nslasher_sound_irq != 0) ? ASSERT_LINE : CLEAR_LINE);
1618      drvstate->nslasher_sound_irq &= ~0x01;
1619   cputag_set_input_line(device->machine, "audiocpu", 0, (drvstate->nslasher_sound_irq != 0) ? ASSERT_LINE : CLEAR_LINE);
16211620}
16221621
16231622static WRITE8_DEVICE_HANDLER( sound_bankswitch_w )
r10427r10428
16501649
16511650static MACHINE_RESET( deco32 )
16521651{
1653   raster_irq_timer = machine->device<timer_device>("int_timer");
1652   deco32_state *state = machine->driver_data<deco32_state>();
1653   state->raster_irq_timer = machine->device<timer_device>("int_timer");
16541654}
16551655
16561656static INTERRUPT_GEN( deco32_vbl_interrupt )
r10427r10428
16631663   cpu_set_input_line(device, M6809_FIRQ_LINE, HOLD_LINE);
16641664}
16651665
1666static MACHINE_CONFIG_START( captaven, driver_device )
1666static MACHINE_CONFIG_START( captaven, deco32_state )
16671667
16681668   /* basic machine hardware */
16691669   MCFG_CPU_ADD("maincpu", ARM, XTAL_28MHz/4) /* verified on pcb (Data East 101 custom)*/
r10427r10428
17101710   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.35)
17111711MACHINE_CONFIG_END
17121712
1713static MACHINE_CONFIG_START( fghthist, driver_device )
1713static MACHINE_CONFIG_START( fghthist, deco32_state )
17141714
17151715   /* basic machine hardware */
17161716   MCFG_CPU_ADD("maincpu", ARM, 28000000/4)
r10427r10428
17541754   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.35)
17551755MACHINE_CONFIG_END
17561756
1757static MACHINE_CONFIG_START( fghthsta, driver_device )
1757static MACHINE_CONFIG_START( fghthsta, deco32_state )
17581758
17591759   /* basic machine hardware */
17601760   MCFG_CPU_ADD("maincpu", ARM, 28000000/4)
r10427r10428
17981798   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.35)
17991799MACHINE_CONFIG_END
18001800
1801static MACHINE_CONFIG_START( dragngun, driver_device )
1801static MACHINE_CONFIG_START( dragngun, deco32_state )
18021802
18031803   /* basic machine hardware */
18041804   MCFG_CPU_ADD("maincpu", ARM, 28000000/4)
r10427r10428
18501850   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 1.0)
18511851MACHINE_CONFIG_END
18521852
1853static MACHINE_CONFIG_START( lockload, driver_device )
1853static MACHINE_CONFIG_START( lockload, deco32_state )
18541854
18551855   /* basic machine hardware */
18561856   MCFG_CPU_ADD("maincpu", ARM, 28000000/4)
r10427r10428
19021902   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 1.0)
19031903MACHINE_CONFIG_END
19041904
1905static MACHINE_CONFIG_START( tattass, driver_device )
1905static MACHINE_CONFIG_START( tattass, deco32_state )
19061906
19071907   /* basic machine hardware */
19081908   MCFG_CPU_ADD("maincpu", ARM, 28000000/4) /* Unconfirmed */
r10427r10428
19391939   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
19401940MACHINE_CONFIG_END
19411941
1942static MACHINE_CONFIG_START( nslasher, driver_device )
1942static MACHINE_CONFIG_START( nslasher, deco32_state )
19431943
19441944   /* basic machine hardware */
19451945   MCFG_CPU_ADD("maincpu", ARM, 28322000/4)
src/mame/drivers/fastfred.c
r10427r10428
121121    Imago sprites DMA
122122*/
123123
124static UINT8 imago_sprites[0x800*3];
125static UINT16 imago_sprites_address;
126static UINT8 imago_sprites_bank = 0;
127124
128125static MACHINE_START( imago )
129126{
130   gfx_element_set_source(machine->gfx[1], imago_sprites);
127   fastfred_state *state = machine->driver_data<fastfred_state>();
128   gfx_element_set_source(machine->gfx[1], state->imago_sprites);
131129}
132130
133131static WRITE8_HANDLER( imago_dma_irq_w )
r10427r10428
137135
138136static WRITE8_HANDLER( imago_sprites_bank_w )
139137{
140   imago_sprites_bank = (data & 2) >> 1;
138   fastfred_state *state = space->machine->driver_data<fastfred_state>();
139   state->imago_sprites_bank = (data & 2) >> 1;
141140}
142141
143142static WRITE8_HANDLER( imago_sprites_dma_w )
144143{
144   fastfred_state *state = space->machine->driver_data<fastfred_state>();
145145   UINT8 *rom = (UINT8 *)space->machine->region("gfx2")->base();
146146   UINT8 sprites_data;
147147
148   sprites_data = rom[imago_sprites_address + 0x2000*0 + imago_sprites_bank * 0x1000];
149   imago_sprites[offset + 0x800*0] = sprites_data;
148   sprites_data = rom[state->imago_sprites_address + 0x2000*0 + state->imago_sprites_bank * 0x1000];
149   state->imago_sprites[offset + 0x800*0] = sprites_data;
150150
151   sprites_data = rom[imago_sprites_address + 0x2000*1 + imago_sprites_bank * 0x1000];
152   imago_sprites[offset + 0x800*1] = sprites_data;
151   sprites_data = rom[state->imago_sprites_address + 0x2000*1 + state->imago_sprites_bank * 0x1000];
152   state->imago_sprites[offset + 0x800*1] = sprites_data;
153153
154   sprites_data = rom[imago_sprites_address + 0x2000*2 + imago_sprites_bank * 0x1000];
155   imago_sprites[offset + 0x800*2] = sprites_data;
154   sprites_data = rom[state->imago_sprites_address + 0x2000*2 + state->imago_sprites_bank * 0x1000];
155   state->imago_sprites[offset + 0x800*2] = sprites_data;
156156
157157   gfx_element_mark_dirty(space->machine->gfx[1], offset/32);
158158}
159159
160160static READ8_HANDLER( imago_sprites_offset_r )
161161{
162   imago_sprites_address = offset;
162   fastfred_state *state = space->machine->driver_data<fastfred_state>();
163   state->imago_sprites_address = offset;
163164   return 0xff; //not really used
164165}
165166
166167static ADDRESS_MAP_START( fastfred_map, ADDRESS_SPACE_PROGRAM, 8 )
167168   AM_RANGE(0x0000, 0xbfff) AM_ROM
168169   AM_RANGE(0xc000, 0xc7ff) AM_RAM
169   AM_RANGE(0xd000, 0xd3ff) AM_MIRROR(0x400) AM_RAM_WRITE(fastfred_videoram_w) AM_BASE(&fastfred_videoram)
170   AM_RANGE(0xd800, 0xd83f) AM_RAM_WRITE(fastfred_attributes_w) AM_BASE(&fastfred_attributesram)
171   AM_RANGE(0xd840, 0xd85f) AM_RAM AM_BASE(&fastfred_spriteram) AM_SIZE(&fastfred_spriteram_size)
170   AM_RANGE(0xd000, 0xd3ff) AM_MIRROR(0x400) AM_RAM_WRITE(fastfred_videoram_w) AM_BASE_MEMBER(fastfred_state, videoram)
171   AM_RANGE(0xd800, 0xd83f) AM_RAM_WRITE(fastfred_attributes_w) AM_BASE_MEMBER(fastfred_state, attributesram)
172   AM_RANGE(0xd840, 0xd85f) AM_RAM AM_BASE_MEMBER(fastfred_state, spriteram) AM_SIZE_MEMBER(fastfred_state, spriteram_size)
172173   AM_RANGE(0xd860, 0xdbff) AM_RAM // Unused, but initialized
173   AM_RANGE(0xe000, 0xe000) AM_READ_PORT("BUTTONS") AM_WRITEONLY AM_BASE(&fastfred_background_color)
174   AM_RANGE(0xe000, 0xe000) AM_READ_PORT("BUTTONS") AM_WRITEONLY AM_BASE_MEMBER(fastfred_state, background_color)
174175   AM_RANGE(0xe800, 0xe800) AM_READ_PORT("JOYS")
175176   AM_RANGE(0xf000, 0xf000) AM_READ_PORT("DSW") AM_WRITENOP
176177   AM_RANGE(0xf001, 0xf001) AM_WRITE(interrupt_enable_w)
r10427r10428
189190static ADDRESS_MAP_START( jumpcoas_map, ADDRESS_SPACE_PROGRAM, 8 )
190191   AM_RANGE(0x0000, 0x7fff) AM_ROM
191192   AM_RANGE(0xc000, 0xc7ff) AM_RAM
192   AM_RANGE(0xd000, 0xd03f) AM_RAM_WRITE(fastfred_attributes_w) AM_BASE(&fastfred_attributesram)
193   AM_RANGE(0xd040, 0xd05f) AM_RAM AM_BASE(&fastfred_spriteram) AM_SIZE(&fastfred_spriteram_size)
193   AM_RANGE(0xd000, 0xd03f) AM_RAM_WRITE(fastfred_attributes_w) AM_BASE_MEMBER(fastfred_state, attributesram)
194   AM_RANGE(0xd040, 0xd05f) AM_RAM AM_BASE_MEMBER(fastfred_state, spriteram) AM_SIZE_MEMBER(fastfred_state, spriteram_size)
194195   AM_RANGE(0xd060, 0xd3ff) AM_RAM
195   AM_RANGE(0xd800, 0xdbff) AM_MIRROR(0x400) AM_RAM_WRITE(fastfred_videoram_w) AM_BASE(&fastfred_videoram)
196   AM_RANGE(0xe000, 0xe000) AM_WRITEONLY AM_BASE(&fastfred_background_color)
196   AM_RANGE(0xd800, 0xdbff) AM_MIRROR(0x400) AM_RAM_WRITE(fastfred_videoram_w) AM_BASE_MEMBER(fastfred_state, videoram)
197   AM_RANGE(0xe000, 0xe000) AM_WRITEONLY AM_BASE_MEMBER(fastfred_state, background_color)
197198   AM_RANGE(0xe800, 0xe800) AM_READ_PORT("DSW1")
198199   AM_RANGE(0xe801, 0xe801) AM_READ_PORT("DSW2")
199200   AM_RANGE(0xe802, 0xe802) AM_READ_PORT("BUTTONS")
r10427r10428
220221   AM_RANGE(0xb000, 0xb3ff) AM_RAM // same fg videoram (which one of the 2 is really used?)
221222   AM_RANGE(0xb800, 0xbfff) AM_RAM_WRITE(imago_sprites_dma_w)
222223   AM_RANGE(0xc000, 0xc7ff) AM_RAM
223   AM_RANGE(0xc800, 0xcbff) AM_RAM_WRITE(imago_fg_videoram_w) AM_BASE(&imago_fg_videoram)
224   AM_RANGE(0xd000, 0xd3ff) AM_RAM_WRITE(fastfred_videoram_w) AM_BASE(&fastfred_videoram)
225   AM_RANGE(0xd800, 0xd83f) AM_RAM_WRITE(fastfred_attributes_w) AM_BASE(&fastfred_attributesram)
226   AM_RANGE(0xd840, 0xd85f) AM_RAM AM_BASE(&fastfred_spriteram) AM_SIZE(&fastfred_spriteram_size)
224   AM_RANGE(0xc800, 0xcbff) AM_RAM_WRITE(imago_fg_videoram_w) AM_BASE_MEMBER(fastfred_state, imago_fg_videoram)
225   AM_RANGE(0xd000, 0xd3ff) AM_RAM_WRITE(fastfred_videoram_w) AM_BASE_MEMBER(fastfred_state, videoram)
226   AM_RANGE(0xd800, 0xd83f) AM_RAM_WRITE(fastfred_attributes_w) AM_BASE_MEMBER(fastfred_state, attributesram)
227   AM_RANGE(0xd840, 0xd85f) AM_RAM AM_BASE_MEMBER(fastfred_state, spriteram) AM_SIZE_MEMBER(fastfred_state, spriteram_size)
227228   AM_RANGE(0xd860, 0xd8ff) AM_RAM // Unused, but initialized
228229   AM_RANGE(0xe000, 0xe000) AM_READ_PORT("BUTTONS")
229230   AM_RANGE(0xe800, 0xe800) AM_READ_PORT("JOYS")
r10427r10428
616617#define CLOCK 18432000  /* The crystal is 18.432MHz */
617618
618619
619static MACHINE_CONFIG_START( fastfred, driver_device )
620static MACHINE_CONFIG_START( fastfred, fastfred_state )
620621
621622   /* basic machine hardware */
622623   MCFG_CPU_ADD("maincpu", Z80, CLOCK/6)     /* 3.072 MHz */
r10427r10428
976977
977978static DRIVER_INIT( flyboy )
978979{
980   fastfred_state *state = machine->driver_data<fastfred_state>();
979981   memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc085, 0xc099, 0, 0, flyboy_custom1_io_r);
980982   memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc8fb, 0xc900, 0, 0, flyboy_custom2_io_r);
981   fastfred_hardware_type = 1;
983   state->hardware_type = 1;
982984}
983985
984986static DRIVER_INIT( flyboyb )
985987{
986   fastfred_hardware_type = 1;
988   fastfred_state *state = machine->driver_data<fastfred_state>();
989   state->hardware_type = 1;
987990}
988991
989992static DRIVER_INIT( fastfred )
990993{
994   fastfred_state *state = machine->driver_data<fastfred_state>();
991995   memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc800, 0xcfff, 0, 0, fastfred_custom_io_r);
992996   memory_nop_write(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc800, 0xcfff, 0, 0);
993   fastfred_hardware_type = 1;
997   state->hardware_type = 1;
994998}
995999
9961000static DRIVER_INIT( jumpcoas )
9971001{
1002   fastfred_state *state = machine->driver_data<fastfred_state>();
9981003   memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc800, 0xcfff, 0, 0, jumpcoas_custom_io_r);
9991004   memory_nop_write(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc800, 0xcfff, 0, 0);
1000   fastfred_hardware_type = 0;
1005   state->hardware_type = 0;
10011006}
10021007
10031008static DRIVER_INIT( boggy84b )
10041009{
1010   fastfred_state *state = machine->driver_data<fastfred_state>();
10051011   memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc800, 0xcfff, 0, 0, jumpcoas_custom_io_r);
10061012   memory_nop_write(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc800, 0xcfff, 0, 0);
1007   fastfred_hardware_type = 2;
1013   state->hardware_type = 2;
10081014}
10091015
10101016static DRIVER_INIT( boggy84 )
10111017{
1018   fastfred_state *state = machine->driver_data<fastfred_state>();
10121019   memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc800, 0xcfff, 0, 0, boggy84_custom_io_r);
10131020   memory_nop_write(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc800, 0xcfff, 0, 0);
1014   fastfred_hardware_type = 2;
1021   state->hardware_type = 2;
10151022}
10161023
10171024
10181025static DRIVER_INIT( imago )
10191026{
1020   fastfred_hardware_type = 3;
1027   fastfred_state *state = machine->driver_data<fastfred_state>();
1028   state->hardware_type = 3;
10211029}
10221030
10231031GAME( 1982, flyboy,   0,        fastfred, flyboy,   flyboy,   ROT90, "Kaneko", "Fly-Boy", 0 )
src/mame/drivers/88games.c
r10427r10428
1414#include "includes/88games.h"
1515
1616
17static UINT8 *paletteram_1000;
1817
1918
2019/*************************************
r10427r10428
137136
138137static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 8 )
139138   AM_RANGE(0x0000, 0x0fff) AM_RAM AM_BASE_MEMBER(_88games_state, banked_rom) /* banked ROM + palette RAM */
140   AM_RANGE(0x1000, 0x1fff) AM_RAM_WRITE(paletteram_xBBBBBGGGGGRRRRR_be_w) AM_BASE(&paletteram_1000)   /* banked ROM + palette RAM */
139   AM_RANGE(0x1000, 0x1fff) AM_RAM_WRITE(paletteram_xBBBBBGGGGGRRRRR_be_w) AM_BASE_MEMBER(_88games_state, paletteram_1000)   /* banked ROM + palette RAM */
141140   AM_RANGE(0x2000, 0x2fff) AM_RAM
142141   AM_RANGE(0x3000, 0x37ff) AM_RAM AM_SHARE("nvram")
143142   AM_RANGE(0x3800, 0x3fff) AM_READWRITE(bankedram_r, bankedram_w) AM_BASE_MEMBER(_88games_state, ram)
r10427r10428
287286   memcpy(state->banked_rom, &RAM[offs], 0x1000);
288287   if (lines & 0x08)
289288   {
290      if (device->machine->generic.paletteram.u8 != paletteram_1000)
289      if (device->machine->generic.paletteram.u8 != state->paletteram_1000)
291290      {
292         memcpy(paletteram_1000, device->machine->generic.paletteram.u8, 0x1000);
293         device->machine->generic.paletteram.u8 = paletteram_1000;
291         memcpy(state->paletteram_1000, device->machine->generic.paletteram.u8, 0x1000);
292         device->machine->generic.paletteram.u8 = state->paletteram_1000;
294293      }
295294   }
296295   else
r10427r10428
300299         memcpy(&RAM[0x20000], device->machine->generic.paletteram.u8, 0x1000);
301300         device->machine->generic.paletteram.u8 = &RAM[0x20000];
302301      }
303      memcpy(paletteram_1000, &RAM[offs+0x1000], 0x1000);
302      memcpy(state->paletteram_1000, &RAM[offs+0x1000], 0x1000);
304303   }
305304
306305   state->videobank = lines & 0x10;
src/mame/drivers/beezer.c
r10427r10428
1313#include "sound/dac.h"
1414#include "includes/beezer.h"
1515
16extern const via6522_interface b_via_0_interface;
17extern const via6522_interface b_via_1_interface;
18
1916static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 8 )
2017   AM_RANGE(0x0000, 0xbfff) AM_RAM AM_BASE_MEMBER(beezer_state, videoram)
2118   AM_RANGE(0xc000, 0xcfff) AM_ROMBANK("bank1")
src/mame/drivers/darkseal.c
r10427r10428
2121#include "sound/okim6295.h"
2222#include "includes/darkseal.h"
2323
24static UINT16 *darkseal_ram;
2524
2625/******************************************************************************/
2726
r10427r10428
6160
6261static ADDRESS_MAP_START( darkseal_map, ADDRESS_SPACE_PROGRAM, 16 )
6362   AM_RANGE(0x000000, 0x07ffff) AM_ROM
64   AM_RANGE(0x100000, 0x103fff) AM_RAM AM_BASE(&darkseal_ram)
63   AM_RANGE(0x100000, 0x103fff) AM_RAM AM_BASE_MEMBER(darkseal_state, ram)
6564   AM_RANGE(0x120000, 0x1207ff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram)
6665   AM_RANGE(0x140000, 0x140fff) AM_RAM_WRITE(darkseal_palette_24bit_rg_w) AM_BASE_GENERIC(paletteram)
6766   AM_RANGE(0x141000, 0x141fff) AM_RAM_WRITE(darkseal_palette_24bit_b_w) AM_BASE_GENERIC(paletteram2)
6867   AM_RANGE(0x180000, 0x18000f) AM_READWRITE(darkseal_control_r, darkseal_control_w)
6968   AM_RANGE(0x200000, 0x200fff) AM_WRITE(darkseal_pf3b_data_w) /* 2nd half of pf3, only used on last level */
70   AM_RANGE(0x202000, 0x203fff) AM_WRITE(darkseal_pf3_data_w) AM_BASE(&darkseal_pf3_data)
71   AM_RANGE(0x220000, 0x220fff) AM_RAM AM_BASE(&darkseal_pf12_row)
72   AM_RANGE(0x222000, 0x222fff) AM_RAM AM_BASE(&darkseal_pf34_row)
69   AM_RANGE(0x202000, 0x203fff) AM_WRITE(darkseal_pf3_data_w) AM_BASE_MEMBER(darkseal_state, pf3_data)
70   AM_RANGE(0x220000, 0x220fff) AM_RAM AM_BASE_MEMBER(darkseal_state, pf12_row)
71   AM_RANGE(0x222000, 0x222fff) AM_RAM AM_BASE_MEMBER(darkseal_state, pf34_row)
7372   AM_RANGE(0x240000, 0x24000f) AM_WRITE(darkseal_control_0_w)
74   AM_RANGE(0x260000, 0x261fff) AM_WRITE(darkseal_pf2_data_w) AM_BASE(&darkseal_pf2_data)
75   AM_RANGE(0x262000, 0x263fff) AM_WRITE(darkseal_pf1_data_w) AM_BASE(&darkseal_pf1_data)
73   AM_RANGE(0x260000, 0x261fff) AM_WRITE(darkseal_pf2_data_w) AM_BASE_MEMBER(darkseal_state, pf2_data)
74   AM_RANGE(0x262000, 0x263fff) AM_WRITE(darkseal_pf1_data_w) AM_BASE_MEMBER(darkseal_state, pf1_data)
7675   AM_RANGE(0x2a0000, 0x2a000f) AM_WRITE(darkseal_control_1_w)
7776ADDRESS_MAP_END
7877
r10427r10428
227226   sound_irq
228227};
229228
230static MACHINE_CONFIG_START( darkseal, driver_device )
229static MACHINE_CONFIG_START( darkseal, darkseal_state )
231230
232231   /* basic machine hardware */
233232   MCFG_CPU_ADD("maincpu", M68000,12000000) /* Custom chip 59 */
src/mame/drivers/stadhero.c
r10427r10428
5555
5656static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 16 )
5757   AM_RANGE(0x000000, 0x01ffff) AM_ROM
58   AM_RANGE(0x200000, 0x2007ff) AM_RAM_WRITE(stadhero_pf1_data_w) AM_BASE(&stadhero_pf1_data)
59   AM_RANGE(0x240000, 0x240007) AM_RAM AM_BASE(&stadhero_pf2_control_0)
60   AM_RANGE(0x240010, 0x240017) AM_WRITEONLY AM_BASE(&stadhero_pf2_control_1)
58   AM_RANGE(0x200000, 0x2007ff) AM_RAM_WRITE(stadhero_pf1_data_w) AM_BASE_MEMBER(stadhero_state, pf1_data)
59   AM_RANGE(0x240000, 0x240007) AM_RAM AM_BASE_MEMBER(stadhero_state, pf2_control_0)
60   AM_RANGE(0x240010, 0x240017) AM_WRITEONLY AM_BASE_MEMBER(stadhero_state, pf2_control_1)
6161   AM_RANGE(0x260000, 0x261fff) AM_READWRITE(stadhero_pf2_data_r, stadhero_pf2_data_w)
6262   AM_RANGE(0x30c000, 0x30c00b) AM_READWRITE(stadhero_control_r, stadhero_control_w)
6363   AM_RANGE(0x310000, 0x3107ff) AM_RAM_WRITE(paletteram16_xxxxBBBBGGGGRRRR_word_w) AM_BASE_GENERIC(paletteram)
r10427r10428
208208
209209/******************************************************************************/
210210
211static MACHINE_CONFIG_START( stadhero, driver_device )
211static MACHINE_CONFIG_START( stadhero, stadhero_state )
212212
213213   /* basic machine hardware */
214214   MCFG_CPU_ADD("maincpu", M68000, 10000000)
src/mame/drivers/viper.c
r10427r10428
4545#include "machine/timekpr.h"
4646#include "video/voodoo.h"
4747
48
49class viper_state : public driver_device
50{
51public:
52   viper_state(running_machine &machine, const driver_device_config_base &config)
53      : driver_device(machine, config) { }
54
55   UINT32 mpc8240_regs[256/4];
56   UINT32 epic_iack;
57   int cf_card_ide;
58   int unk1_bit;
59   UINT32 voodoo3_pci_reg[0x100];
60};
61
62
4863//#define VIPER_DEBUG_LOG
4964
5065static VIDEO_UPDATE(viper)
r10427r10428
5671
5772/*****************************************************************************/
5873
59static UINT32 mpc8240_regs[256/4];
6074static UINT32 mpc8240_pci_r(device_t *busdevice, device_t *device, int function, int reg, UINT32 mem_mask)
6175{
76   viper_state *state = device->machine->driver_data<viper_state>();
6277   #ifdef VIPER_DEBUG_LOG
6378   printf("MPC8240: PCI read %d, %02X, %08X\n", function, reg, mem_mask);
6479   #endif
r10427r10428
6782   {
6883   }
6984
70   return mpc8240_regs[reg/4];
85   return state->mpc8240_regs[reg/4];
7186}
7287
7388static void mpc8240_pci_w(device_t *busdevice, device_t *device, int function, int reg, UINT32 data, UINT32 mem_mask)
7489{
90   viper_state *state = device->machine->driver_data<viper_state>();
7591   #ifdef VIPER_DEBUG_LOG
7692   printf("MPC8240: PCI write %d, %02X, %08X, %08X\n", function, reg, data, mem_mask);
7793   #endif
7894
79   COMBINE_DATA(mpc8240_regs + (reg/4));
95   COMBINE_DATA(state->mpc8240_regs + (reg/4));
8096}
8197
8298
r10427r10428
102118
103119
104120
105static UINT32 epic_iack;
106121
107122static READ32_HANDLER( epic_r )
108123{
124   viper_state *state = space->machine->driver_data<viper_state>();
109125   int reg;
110126   reg = offset * 4;
111127
r10427r10428
121137         switch (reg & 0xffff)
122138         {
123139            case 0x00a0:         // IACK
124               return epic_iack;
140               return state->epic_iack;
125141
126142         }
127143         break;
r10427r10428
133149
134150static WRITE32_HANDLER( epic_w )
135151{
152   viper_state *state = space->machine->driver_data<viper_state>();
136153   int reg;
137154   reg = offset * 4;
138155
r10427r10428
148165         switch (reg & 0xffff)
149166         {
150167            case 0x00b0:         // EOI
151               epic_iack = 0xff;
168               state->epic_iack = 0xff;
152169               break;
153170         }
154171         break;
r10427r10428
166183}
167184
168185
169static int cf_card_ide = 0;
170186
171187static const UINT8 cf_card_tuples[] =
172188{
r10427r10428
226242
227243static READ64_DEVICE_HANDLER(cf_card_r)
228244{
245   viper_state *state = device->machine->driver_data<viper_state>();
229246   UINT64 r = 0;
230247
231248   if (ACCESSING_BITS_16_31)
232249   {
233      if (cf_card_ide)
250      if (state->cf_card_ide)
234251      {
235252         switch (offset & 0xf)
236253         {
r10427r10428
289306
290307static WRITE64_DEVICE_HANDLER(cf_card_w)
291308{
309   viper_state *state = device->machine->driver_data<viper_state>();
292310   #ifdef VIPER_DEBUG_LOG
293311   printf("%s:compact_flash_w: %08X%08X, %08X, %08X%08X\n", device->machine->describe_context(), (UINT32)(data>>32), (UINT32)(data), offset, (UINT32)(mem_mask >> 32), (UINT32)(mem_mask));
294312   #endif
r10427r10428
341359            {
342360               if ((data >> 16) & 0x80)
343361               {
344                  cf_card_ide = 1;
362                  state->cf_card_ide = 1;
345363
346364                  // soft reset
347365                  // sector count register is set to 0x01
r10427r10428
364382
365383static WRITE64_HANDLER(unk2_w)
366384{
385   viper_state *state = space->machine->driver_data<viper_state>();
367386   if (ACCESSING_BITS_56_63)
368387   {
369      cf_card_ide = 0;
388      state->cf_card_ide = 0;
370389   }
371390}
372391
r10427r10428
397416   }
398417}
399418
400static int unk1_bit = 0;
401419static READ64_HANDLER(unk1_r)
402420{
421   viper_state *state = space->machine->driver_data<viper_state>();
403422   UINT64 r = 0;
404423   //return 0;//U64(0x0000400000000000);
405424
406425   if (ACCESSING_BITS_40_47)
407426   {
408      r |= (UINT64)(unk1_bit << 5) << 40;
427      r |= (UINT64)(state->unk1_bit << 5) << 40;
409428   }
410429
411430   return r;
r10427r10428
413432
414433static WRITE64_HANDLER(unk1a_w)
415434{
435   viper_state *state = space->machine->driver_data<viper_state>();
416436   if (ACCESSING_BITS_56_63)
417437   {
418      unk1_bit = 1;
438      state->unk1_bit = 1;
419439   }
420440}
421441
422442static WRITE64_HANDLER(unk1b_w)
423443{
444   viper_state *state = space->machine->driver_data<viper_state>();
424445   if (ACCESSING_BITS_56_63)
425446   {
426      unk1_bit = 0;
447      state->unk1_bit = 0;
427448   }
428449}
429450
430static UINT32 voodoo3_pci_reg[0x100];
431451static UINT32 voodoo3_pci_r(device_t *busdevice, device_t *device, int function, int reg, UINT32 mem_mask)
432452{
453   viper_state *state = device->machine->driver_data<viper_state>();
433454   switch (reg)
434455   {
435456      case 0x00:      // PCI Vendor ID (0x121a = 3dfx), Device ID (0x0005 = Voodoo 3)
r10427r10428
442463      }
443464      case 0x10:      // memBaseAddr0
444465      {
445         return voodoo3_pci_reg[0x10/4];
466         return state->voodoo3_pci_reg[0x10/4];
446467      }
447468      case 0x14:      // memBaseAddr1
448469      {
449         return voodoo3_pci_reg[0x14/4];
470         return state->voodoo3_pci_reg[0x14/4];
450471      }
451472      case 0x18:      // memBaseAddr1
452473      {
453         return voodoo3_pci_reg[0x18/4];
474         return state->voodoo3_pci_reg[0x18/4];
454475      }
455476      case 0x40:      // fabId
456477      {
457         return voodoo3_pci_reg[0x40/4];
478         return state->voodoo3_pci_reg[0x40/4];
458479      }
459480      case 0x50:      // cfgScratch
460481      {
461         return voodoo3_pci_reg[0x50/4];
482         return state->voodoo3_pci_reg[0x50/4];
462483      }
463484
464485      default:
r10427r10428
469490
470491static void voodoo3_pci_w(device_t *busdevice, device_t *device, int function, int reg, UINT32 data, UINT32 mem_mask)
471492{
493   viper_state *state = device->machine->driver_data<viper_state>();
472494//  printf("voodoo3_pci_w: %08X, %08X\n", reg, data);
473495
474496   switch (reg)
475497   {
476498      case 0x04:      // Command register
477499      {
478         voodoo3_pci_reg[0x04/4] = data;
500         state->voodoo3_pci_reg[0x04/4] = data;
479501         break;
480502      }
481503      case 0x10:      // memBaseAddr0
482504      {
483505         if (data == 0xffffffff)
484506         {
485            voodoo3_pci_reg[0x10/4] = 0xfe000000;
507            state->voodoo3_pci_reg[0x10/4] = 0xfe000000;
486508         }
487509         else
488510         {
489            voodoo3_pci_reg[0x10/4] = data;
511            state->voodoo3_pci_reg[0x10/4] = data;
490512         }
491513         break;
492514      }
r10427r10428
494516      {
495517         if (data == 0xffffffff)
496518         {
497            voodoo3_pci_reg[0x14/4] = 0xfe000008;
519            state->voodoo3_pci_reg[0x14/4] = 0xfe000008;
498520         }
499521         else
500522         {
501            voodoo3_pci_reg[0x14/4] = data;
523            state->voodoo3_pci_reg[0x14/4] = data;
502524         }
503525         break;
504526      }
r10427r10428
506528      {
507529         if (data == 0xffffffff)
508530         {
509            voodoo3_pci_reg[0x18/4] = 0xffffff01;
531            state->voodoo3_pci_reg[0x18/4] = 0xffffff01;
510532         }
511533         else
512534         {
513            voodoo3_pci_reg[0x18/4] = data;
535            state->voodoo3_pci_reg[0x18/4] = data;
514536         }
515537         break;
516538      }
r10427r10428
520542      }
521543      case 0x40:      // fabId
522544      {
523         voodoo3_pci_reg[0x40/4] = data;
545         state->voodoo3_pci_reg[0x40/4] = data;
524546         break;
525547      }
526548      case 0x50:      // cfgScratch
527549      {
528         voodoo3_pci_reg[0x50/4] = data;
550         state->voodoo3_pci_reg[0x50/4] = data;
529551         break;
530552      }
531553
r10427r10428
614636   devtag_reset(machine, "ide");
615637}
616638
617static MACHINE_CONFIG_START( viper, driver_device )
639static MACHINE_CONFIG_START( viper, viper_state )
618640
619641   /* basic machine hardware */
620642   MCFG_CPU_ADD("maincpu", MPC8240, 200000000)
src/mame/drivers/model2.c
r10427r10428
101101#include "sound/2612intf.h"
102102#include "includes/model2.h"
103103
104UINT32 *model2_bufferram, *model2_colorxlat;
105static UINT32 *model2_workram;
106UINT32 *model2_textureram0, *model2_textureram1, *model2_lumaram;
107UINT32 *model2_paletteram32;
108static UINT32 model2_intreq;
109static UINT32 model2_intena;
110static UINT32 model2_coproctl, model2_coprocnt, model2_geoctl, model2_geocnt;
111static UINT16 *model2_soundram = NULL;
112104
113static UINT32 model2_timervals[4], model2_timerorig[4];
114static int      model2_timerrun[4];
115static timer_device *model2_timers[4];
116static int model2_ctrlmode;
117static int analog_channel;
118
119static UINT32 *tgp_program;
120
121105enum {
122106   DSP_TYPE_TGP   = 1,
123107   DSP_TYPE_SHARC   = 2,
124108   DSP_TYPE_TGPX4   = 3,
125109};
126110
127static int dsp_type;
128111
129
130
131112#define COPRO_FIFOIN_SIZE   32000
132static int copro_fifoin_rpos, copro_fifoin_wpos;
133static UINT32 copro_fifoin_data[COPRO_FIFOIN_SIZE];
134static int copro_fifoin_num = 0;
135113static int copro_fifoin_pop(device_t *device, UINT32 *result)
136114{
115   model2_state *state = device->machine->driver_data<model2_state>();
137116   UINT32 r;
138117
139   if (copro_fifoin_num == 0)
118   if (state->copro_fifoin_num == 0)
140119   {
141      if (dsp_type == DSP_TYPE_TGP)
120      if (state->dsp_type == DSP_TYPE_TGP)
142121         return 0;
143122
144123      fatalerror("Copro FIFOIN underflow (at %08X)", cpu_get_pc(device));
145124      return 0;
146125   }
147126
148   r = copro_fifoin_data[copro_fifoin_rpos++];
127   r = state->copro_fifoin_data[state->copro_fifoin_rpos++];
149128
150   if (copro_fifoin_rpos == COPRO_FIFOIN_SIZE)
129   if (state->copro_fifoin_rpos == COPRO_FIFOIN_SIZE)
151130   {
152      copro_fifoin_rpos = 0;
131      state->copro_fifoin_rpos = 0;
153132   }
154133
155   copro_fifoin_num--;
156   if (dsp_type == DSP_TYPE_SHARC)
134   state->copro_fifoin_num--;
135   if (state->dsp_type == DSP_TYPE_SHARC)
157136   {
158      if (copro_fifoin_num == 0)
137      if (state->copro_fifoin_num == 0)
159138      {
160139         sharc_set_flag_input(device, 0, ASSERT_LINE);
161140      }
r10427r10428
172151
173152static void copro_fifoin_push(device_t *device, UINT32 data)
174153{
175   if (copro_fifoin_num == COPRO_FIFOIN_SIZE)
154   model2_state *state = device->machine->driver_data<model2_state>();
155   if (state->copro_fifoin_num == COPRO_FIFOIN_SIZE)
176156   {
177157      fatalerror("Copro FIFOIN overflow (at %08X)", cpu_get_pc(device));
178158      return;
r10427r10428
180160
181161   //mame_printf_debug("COPRO FIFOIN at %08X, %08X, %f\n", cpu_get_pc(device), data, *(float*)&data);
182162
183   copro_fifoin_data[copro_fifoin_wpos++] = data;
184   if (copro_fifoin_wpos == COPRO_FIFOIN_SIZE)
163   state->copro_fifoin_data[state->copro_fifoin_wpos++] = data;
164   if (state->copro_fifoin_wpos == COPRO_FIFOIN_SIZE)
185165   {
186      copro_fifoin_wpos = 0;
166      state->copro_fifoin_wpos = 0;
187167   }
188168
189   copro_fifoin_num++;
169   state->copro_fifoin_num++;
190170
191171   // clear FIFO empty flag on SHARC
192   if (dsp_type == DSP_TYPE_SHARC)
172   if (state->dsp_type == DSP_TYPE_SHARC)
193173   {
194174      sharc_set_flag_input(device, 0, CLEAR_LINE);
195175   }
r10427r10428
197177
198178
199179#define COPRO_FIFOOUT_SIZE   32000
200static int copro_fifoout_rpos, copro_fifoout_wpos;
201static UINT32 copro_fifoout_data[COPRO_FIFOOUT_SIZE];
202static int copro_fifoout_num = 0;
203180static UINT32 copro_fifoout_pop(address_space *space)
204181{
182   model2_state *state = space->machine->driver_data<model2_state>();
205183   UINT32 r;
206184
207   if (copro_fifoout_num == 0)
185   if (state->copro_fifoout_num == 0)
208186   {
209187      /* Reading from empty FIFO causes the i960 to enter wait state */
210188      i960_stall(space->cpu);
r10427r10428
215193      return 0;
216194   }
217195
218   r = copro_fifoout_data[copro_fifoout_rpos++];
196   r = state->copro_fifoout_data[state->copro_fifoout_rpos++];
219197
220   if (copro_fifoout_rpos == COPRO_FIFOOUT_SIZE)
198   if (state->copro_fifoout_rpos == COPRO_FIFOOUT_SIZE)
221199   {
222      copro_fifoout_rpos = 0;
200      state->copro_fifoout_rpos = 0;
223201   }
224202
225   copro_fifoout_num--;
203   state->copro_fifoout_num--;
226204
227//  logerror("COPRO FIFOOUT POP %08X, %f, %d\n", r, *(float*)&r,copro_fifoout_num);
205//  logerror("COPRO FIFOOUT POP %08X, %f, %d\n", r, *(float*)&r,state->copro_fifoout_num);
228206
229207   // set SHARC flag 1: 0 if space available, 1 if FIFO full
230   if (dsp_type == DSP_TYPE_SHARC)
208   if (state->dsp_type == DSP_TYPE_SHARC)
231209   {
232      if (copro_fifoout_num == COPRO_FIFOOUT_SIZE)
210      if (state->copro_fifoout_num == COPRO_FIFOOUT_SIZE)
233211      {
234212         sharc_set_flag_input(space->machine->device("dsp"), 1, ASSERT_LINE);
235213      }
r10427r10428
244222
245223static void copro_fifoout_push(device_t *device, UINT32 data)
246224{
247   //if (copro_fifoout_wpos == copro_fifoout_rpos)
248   if (copro_fifoout_num == COPRO_FIFOOUT_SIZE)
225   model2_state *state = device->machine->driver_data<model2_state>();
226   //if (state->copro_fifoout_wpos == state->copro_fifoout_rpos)
227   if (state->copro_fifoout_num == COPRO_FIFOOUT_SIZE)
249228   {
250229      fatalerror("Copro FIFOOUT overflow (at %08X)", cpu_get_pc(device));
251230      return;
252231   }
253232
254//  logerror("COPRO FIFOOUT PUSH %08X, %f, %d\n", data, *(float*)&data,copro_fifoout_num);
233//  logerror("COPRO FIFOOUT PUSH %08X, %f, %d\n", data, *(float*)&data,state->copro_fifoout_num);
255234
256   copro_fifoout_data[copro_fifoout_wpos++] = data;
257   if (copro_fifoout_wpos == COPRO_FIFOOUT_SIZE)
235   state->copro_fifoout_data[state->copro_fifoout_wpos++] = data;
236   if (state->copro_fifoout_wpos == COPRO_FIFOOUT_SIZE)
258237   {
259      copro_fifoout_wpos = 0;
238      state->copro_fifoout_wpos = 0;
260239   }
261240
262   copro_fifoout_num++;
241   state->copro_fifoout_num++;
263242
264243   // set SHARC flag 1: 0 if space available, 1 if FIFO full
265   if (dsp_type == DSP_TYPE_SHARC)
244   if (state->dsp_type == DSP_TYPE_SHARC)
266245   {
267      if (copro_fifoout_num == COPRO_FIFOOUT_SIZE)
246      if (state->copro_fifoout_num == COPRO_FIFOOUT_SIZE)
268247      {
269248         sharc_set_flag_input(device, 1, ASSERT_LINE);
270249
r10427r10428
282261/* Timers - these count down at 25 MHz and pull IRQ2 when they hit 0 */
283262static READ32_HANDLER( timers_r )
284263{
264   model2_state *state = space->machine->driver_data<model2_state>();
285265   i960_noburst(space->cpu);
286266
287267   // if timer is running, calculate current value
288   if (model2_timerrun[offset])
268   if (state->timerrun[offset])
289269   {
290270      // get elapsed time, convert to units of 25 MHz
291      UINT32 cur = (model2_timers[offset]->time_elapsed() * 25000000).as_double();
271      UINT32 cur = (state->timers[offset]->time_elapsed() * 25000000).as_double();
292272
293273      // subtract units from starting value
294      model2_timervals[offset] = model2_timerorig[offset] - cur;
274      state->timervals[offset] = state->timerorig[offset] - cur;
295275   }
296276
297   return model2_timervals[offset];
277   return state->timervals[offset];
298278}
299279
300280static WRITE32_HANDLER( timers_w )
301281{
282   model2_state *state = space->machine->driver_data<model2_state>();
302283   attotime period;
303284
304285   i960_noburst(space->cpu);
305   COMBINE_DATA(&model2_timervals[offset]);
286   COMBINE_DATA(&state->timervals[offset]);
306287
307   model2_timerorig[offset] = model2_timervals[offset];
308   period = attotime::from_hz(25000000) * model2_timerorig[offset];
309   model2_timers[offset]->adjust(period);
310   model2_timerrun[offset] = 1;
288   state->timerorig[offset] = state->timervals[offset];
289   period = attotime::from_hz(25000000) * state->timerorig[offset];
290   state->timers[offset]->adjust(period);
291   state->timerrun[offset] = 1;
311292}
312293
313294static TIMER_DEVICE_CALLBACK( model2_timer_cb )
314295{
296   model2_state *state = timer.machine->driver_data<model2_state>();
315297   int tnum = (int)(FPTR)ptr;
316298   int bit = tnum + 2;
317299
318   model2_timers[tnum]->reset();
300   state->timers[tnum]->reset();
319301
320   model2_intreq |= (1<<bit);
321   if (model2_intena & (1<<bit))
302   state->intreq |= (1<<bit);
303   if (state->intena & (1<<bit))
322304   {
323305      cputag_set_input_line(timer.machine, "maincpu", I960_IRQ2, ASSERT_LINE);
324306   }
325307
326   model2_timervals[tnum] = 0;
327   model2_timerrun[tnum] = 0;
308   state->timervals[tnum] = 0;
309   state->timerrun[tnum] = 0;
328310}
329311
312static MACHINE_START(model2)
313{
314   model2_state *state = machine->driver_data<model2_state>();
315   state->copro_fifoin_data = auto_alloc_array_clear(machine, UINT32, COPRO_FIFOIN_SIZE);
316   state->copro_fifoout_data = auto_alloc_array_clear(machine, UINT32, COPRO_FIFOOUT_SIZE);
317}
318
330319static MACHINE_RESET(model2_common)
331320{
321   model2_state *state = machine->driver_data<model2_state>();
332322   int i;
333323
334   model2_intreq = 0;
335   model2_intena = 0;
336   model2_coproctl = 0;
337   model2_coprocnt = 0;
338   model2_geoctl = 0;
339   model2_geocnt = 0;
340   model2_ctrlmode = 0;
341   analog_channel = 0;
324   state->intreq = 0;
325   state->intena = 0;
326   state->coproctl = 0;
327   state->coprocnt = 0;
328   state->geoctl = 0;
329   state->geocnt = 0;
330   state->ctrlmode = 0;
331   state->analog_channel = 0;
342332
343   model2_timervals[0] = 0xfffff;
344   model2_timervals[1] = 0xfffff;
345   model2_timervals[2] = 0xfffff;
346   model2_timervals[3] = 0xfffff;
333   state->timervals[0] = 0xfffff;
334   state->timervals[1] = 0xfffff;
335   state->timervals[2] = 0xfffff;
336   state->timervals[3] = 0xfffff;
347337
348   model2_timerrun[0] = model2_timerrun[1] = model2_timerrun[2] = model2_timerrun[3] = 0;
338   state->timerrun[0] = state->timerrun[1] = state->timerrun[2] = state->timerrun[3] = 0;
349339
350   model2_timers[0] = machine->device<timer_device>("timer0");
351   model2_timers[1] = machine->device<timer_device>("timer1");
352   model2_timers[2] = machine->device<timer_device>("timer2");
353   model2_timers[3] = machine->device<timer_device>("timer3");
340   state->timers[0] = machine->device<timer_device>("timer0");
341   state->timers[1] = machine->device<timer_device>("timer1");
342   state->timers[2] = machine->device<timer_device>("timer2");
343   state->timers[3] = machine->device<timer_device>("timer3");
354344   for (i=0; i<4; i++)
355      model2_timers[i]->reset();
345      state->timers[i]->reset();
356346}
357347
358348static MACHINE_RESET(model2o)
359349{
350   model2_state *state = machine->driver_data<model2_state>();
360351   MACHINE_RESET_CALL(model2_common);
361352
362353   // hold TGP in halt until we have code
363354   cputag_set_input_line(machine, "tgp", INPUT_LINE_HALT, ASSERT_LINE);
364355
365   dsp_type = DSP_TYPE_TGP;
356   state->dsp_type = DSP_TYPE_TGP;
366357}
367358
368359static MACHINE_RESET(model2_scsp)
369360{
361   model2_state *state = machine->driver_data<model2_state>();
370362   memory_set_bankptr(machine, "bank4", machine->region("scsp")->base() + 0x200000);
371363   memory_set_bankptr(machine, "bank5", machine->region("scsp")->base() + 0x600000);
372364
373365   // copy the 68k vector table into RAM
374   memcpy(model2_soundram, machine->region("audiocpu")->base() + 0x80000, 16);
366   memcpy(state->soundram, machine->region("audiocpu")->base() + 0x80000, 16);
375367   machine->device("audiocpu")->reset();
376368}
377369
378370static MACHINE_RESET(model2)
379371{
372   model2_state *state = machine->driver_data<model2_state>();
380373   MACHINE_RESET_CALL(model2_common);
381374   MACHINE_RESET_CALL(model2_scsp);
382375
383376   // hold TGP in halt until we have code
384377   cputag_set_input_line(machine, "tgp", INPUT_LINE_HALT, ASSERT_LINE);
385378
386   dsp_type = DSP_TYPE_TGP;
379   state->dsp_type = DSP_TYPE_TGP;
387380}
388381
389382static MACHINE_RESET(model2b)
390383{
384   model2_state *state = machine->driver_data<model2_state>();
391385   MACHINE_RESET_CALL(model2_common);
392386   MACHINE_RESET_CALL(model2_scsp);
393387
r10427r10428
398392   // clear FIFOOUT buffer full flag on SHARC
399393   cputag_set_input_line(machine, "dsp", SHARC_INPUT_FLAG1, CLEAR_LINE);
400394
401   dsp_type = DSP_TYPE_SHARC;
395   state->dsp_type = DSP_TYPE_SHARC;
402396}
403397
404398static MACHINE_RESET(model2c)
405399{
400   model2_state *state = machine->driver_data<model2_state>();
406401   MACHINE_RESET_CALL(model2_common);
407402   MACHINE_RESET_CALL(model2_scsp);
408403
409   dsp_type = DSP_TYPE_TGPX4;
404   state->dsp_type = DSP_TYPE_TGPX4;
410405}
411406
412407static void chcolor(running_machine *machine, pen_t color, UINT16 data)
r10427r10428
416411
417412static WRITE32_HANDLER( pal32_w )
418413{
419   COMBINE_DATA(model2_paletteram32 + offset);
414   model2_state *state = space->machine->driver_data<model2_state>();
415   COMBINE_DATA(state->paletteram32 + offset);
420416   if(ACCESSING_BITS_0_15)
421      chcolor(space->machine, offset * 2, model2_paletteram32[offset]);
417      chcolor(space->machine, offset * 2, state->paletteram32[offset]);
422418   if(ACCESSING_BITS_16_31)
423      chcolor(space->machine, offset * 2 + 1, model2_paletteram32[offset] >> 16);
419      chcolor(space->machine, offset * 2 + 1, state->paletteram32[offset] >> 16);
424420}
425421
426422static WRITE32_HANDLER( ctrl0_w )
427423{
424   model2_state *state = space->machine->driver_data<model2_state>();
428425   if(ACCESSING_BITS_0_7)
429426   {
430427      eeprom_device *device = space->machine->device<eeprom_device>("eeprom");
431      model2_ctrlmode = data & 0x01;
428      state->ctrlmode = data & 0x01;
432429      eeprom_write_bit(device, data & 0x20);
433430      eeprom_set_clock_line(device, (data & 0x80) ? ASSERT_LINE : CLEAR_LINE);
434431      eeprom_set_cs_line(device, (data & 0x40) ? CLEAR_LINE : ASSERT_LINE);
r10427r10428
437434
438435static WRITE32_HANDLER( analog_2b_w )
439436{
440   analog_channel = (data >> 16) & 0x07;
437   model2_state *state = space->machine->driver_data<model2_state>();
438   state->analog_channel = (data >> 16) & 0x07;
441439}
442440
443441
444442static READ32_HANDLER( fifoctl_r )
445443{
444   model2_state *state = space->machine->driver_data<model2_state>();
446445   UINT32 r = 0;
447446
448   if (copro_fifoout_num == 0)
447   if (state->copro_fifoout_num == 0)
449448   {
450449      r |= 1;
451450   }
r10427r10428
461460
462461static CUSTOM_INPUT( _1c00000_r )
463462{
463   model2_state *state = field->port->machine->driver_data<model2_state>();
464464   UINT32 ret = input_port_read(field->port->machine, "IN0");
465465
466   if(model2_ctrlmode == 0)
466   if(state->ctrlmode == 0)
467467   {
468468      return ret;
469469   }
r10427r10428
476476
477477static CUSTOM_INPUT( _1c0001c_r )
478478{
479   model2_state *state = field->port->machine->driver_data<model2_state>();
479480   UINT32 iptval = 0x00ff;
480   if(analog_channel < 4)
481   if(state->analog_channel < 4)
481482   {
482483      static const char *const ports[] = { "ANA0", "ANA1", "ANA2", "ANA3" };
483      iptval = input_port_read_safe(field->port->machine, ports[analog_channel], 0);
484      ++analog_channel;
484      iptval = input_port_read_safe(field->port->machine, ports[state->analog_channel], 0);
485      ++state->analog_channel;
485486   }
486487   return iptval;
487488}
r10427r10428
555556
556557*/
557558
558static UINT16 cmd_data;
559559
560560static CUSTOM_INPUT( rchase2_devices_r )
561561{
r10427r10428
564564
565565static WRITE32_HANDLER( rchase2_devices_w )
566566{
567   model2_state *state = space->machine->driver_data<model2_state>();
567568   /*
568569    0x00040000 start 1 lamp
569570    0x00080000 start 2 lamp
570571    */
571572
572573   if(mem_mask == 0x0000ffff)
573      cmd_data = data;
574      state->cmd_data = data;
574575}
575576
576static UINT8 driveio_comm_data;
577577
578578static WRITE32_HANDLER( srallyc_devices_w )
579579{
580   model2_state *state = space->machine->driver_data<model2_state>();
580581   /*
581582    0x00040000 start 1 lamp
582583    0x00200000 vr lamp
r10427r10428
585586
586587   if(mem_mask == 0x000000ff || mem_mask == 0x0000ffff)
587588   {
588      driveio_comm_data = data & 0xff;
589      state->driveio_comm_data = data & 0xff;
589590      cputag_set_input_line(space->machine, "drivecpu", 0, HOLD_LINE);
590591   }
591592}
r10427r10428
601602
602603static WRITE32_HANDLER(copro_prg_w)
603604{
604   if (model2_coproctl & 0x80000000)
605   model2_state *state = space->machine->driver_data<model2_state>();
606   if (state->coproctl & 0x80000000)
605607   {
606      logerror("copro_prg_w: %08X:   %08X\n", model2_coprocnt, data);
607      model2_coprocnt++;
608      logerror("copro_prg_w: %08X:   %08X\n", state->coprocnt, data);
609      state->coprocnt++;
608610   }
609611   else
610612   {
r10427r10428
614616
615617static WRITE32_HANDLER( copro_ctl1_w )
616618{
619   model2_state *state = space->machine->driver_data<model2_state>();
617620   // did hi bit change?
618   if ((data ^ model2_coproctl) == 0x80000000)
621   if ((data ^ state->coproctl) == 0x80000000)
619622   {
620623      if (data & 0x80000000)
621624      {
622625         logerror("Start copro upload\n");
623         model2_coprocnt = 0;
626         state->coprocnt = 0;
624627      }
625628      else
626629      {
627         logerror("Boot copro, %d dwords\n", model2_coprocnt);
628         if (dsp_type != DSP_TYPE_TGPX4)
630         logerror("Boot copro, %d dwords\n", state->coprocnt);
631         if (state->dsp_type != DSP_TYPE_TGPX4)
629632         {
630            if (dsp_type == DSP_TYPE_SHARC)
633            if (state->dsp_type == DSP_TYPE_SHARC)
631634               cputag_set_input_line(space->machine, "dsp", INPUT_LINE_HALT, CLEAR_LINE);
632635            else
633636               cputag_set_input_line(space->machine, "tgp", INPUT_LINE_HALT, CLEAR_LINE);
r10427r10428
635638      }
636639   }
637640
638   model2_coproctl = data;
641   state->coproctl = data;
639642}
640643
641644static WRITE32_HANDLER(copro_function_port_w)
642645{
646   model2_state *state = space->machine->driver_data<model2_state>();
643647   UINT32 d = data & 0x800fffff;
644648   UINT32 a = (offset >> 2) & 0xff;
645649   d |= a << 23;
646650
647651   //logerror("copro_function_port_w: %08X, %08X, %08X\n", data, offset, mem_mask);
648   if (dsp_type == DSP_TYPE_SHARC)
652   if (state->dsp_type == DSP_TYPE_SHARC)
649653      copro_fifoin_push(space->machine->device("dsp"), d);
650654   else
651655      copro_fifoin_push(space->machine->device("tgp"), d);
r10427r10428
659663
660664static WRITE32_HANDLER(copro_fifo_w)
661665{
662   if (model2_coproctl & 0x80000000)
666   model2_state *state = space->machine->driver_data<model2_state>();
667   if (state->coproctl & 0x80000000)
663668   {
664      if (dsp_type == DSP_TYPE_SHARC)
669      if (state->dsp_type == DSP_TYPE_SHARC)
665670      {
666         sharc_external_dma_write(space->machine->device("dsp"), model2_coprocnt, data & 0xffff);
671         sharc_external_dma_write(space->machine->device("dsp"), state->coprocnt, data & 0xffff);
667672      }
668      else if (dsp_type == DSP_TYPE_TGP)
673      else if (state->dsp_type == DSP_TYPE_TGP)
669674      {
670         tgp_program[model2_coprocnt] = data;
675         state->tgp_program[state->coprocnt] = data;
671676      }
672677
673      model2_coprocnt++;
678      state->coprocnt++;
674679   }
675680   else
676681   {
677682      //mame_printf_debug("copro_fifo_w: %08X, %08X, %08X at %08X\n", data, offset, mem_mask, cpu_get_pc(space->cpu));
678      if (dsp_type == DSP_TYPE_SHARC)
683      if (state->dsp_type == DSP_TYPE_SHARC)
679684         copro_fifoin_push(space->machine->device("dsp"), data);
680685      else
681686         copro_fifoin_push(space->machine->device("tgp"), data);
682687   }
683688}
684689
685static int iop_write_num = 0;
686static UINT32 iop_data = 0;
687690static WRITE32_HANDLER(copro_sharc_iop_w)
688691{
692   model2_state *state = space->machine->driver_data<model2_state>();
689693   /* FIXME: clean this up */
690694   if ((strcmp(space->machine->gamedrv->name, "schamp" ) == 0) ||
691695      (strcmp(space->machine->gamedrv->name, "sfight" ) == 0) ||
r10427r10428
701705   }
702706   else
703707   {
704      if ((iop_write_num & 1) == 0)
708      if ((state->iop_write_num & 1) == 0)
705709      {
706         iop_data = data & 0xffff;
710         state->iop_data = data & 0xffff;
707711      }
708712      else
709713      {
710         iop_data |= (data & 0xffff) << 16;
711         sharc_external_iop_write(space->machine->device("dsp"), offset, iop_data);
714         state->iop_data |= (data & 0xffff) << 16;
715         sharc_external_iop_write(space->machine->device("dsp"), offset, state->iop_data);
712716      }
713      iop_write_num++;
717      state->iop_write_num++;
714718   }
715719}
716720
r10427r10428
721725/*****************************************************************************/
722726/* GEO */
723727
724UINT32 geo_read_start_address = 0;
725UINT32 geo_write_start_address = 0;
726728
727729static WRITE32_HANDLER( geo_ctl1_w )
728730{
731   model2_state *state = space->machine->driver_data<model2_state>();
729732   // did hi bit change?
730   if ((data ^ model2_geoctl) == 0x80000000)
733   if ((data ^ state->geoctl) == 0x80000000)
731734   {
732735      if (data & 0x80000000)
733736      {
734         logerror("Start geo upload\n");
735         model2_geocnt = 0;
737         logerror("Start state->geo upload\n");
738         state->geocnt = 0;
736739      }
737740      else
738741      {
739         logerror("Boot geo, %d dwords\n", model2_geocnt);
742         logerror("Boot state->geo, %d dwords\n", state->geocnt);
740743      }
741744   }
742745
743   model2_geoctl = data;
746   state->geoctl = data;
744747}
745748
746749
747750#ifdef UNUSED_FUNCTION
748751static WRITE32_HANDLER( geo_sharc_ctl1_w )
749752{
753   model2_state *state = space->machine->driver_data<model2_state>();
750754    // did hi bit change?
751    if ((data ^ model2_geoctl) == 0x80000000)
755    if ((data ^ state->geoctl) == 0x80000000)
752756    {
753757        if (data & 0x80000000)
754758        {
755            logerror("Start geo upload\n");
756            model2_geocnt = 0;
759            logerror("Start state->geo upload\n");
760            state->geocnt = 0;
757761        }
758762        else
759763        {
760            logerror("Boot geo, %d dwords\n", model2_geocnt);
764            logerror("Boot state->geo, %d dwords\n", state->geocnt);
761765            cputag_set_input_line(space->machine, "dsp2", INPUT_LINE_HALT, CLEAR_LINE);
762766            //cpu_spinuntil_time(space->cpu, attotime::from_usec(1000));       // Give the SHARC enough time to boot itself
763767        }
764768    }
765769
766    model2_geoctl = data;
770    state->geoctl = data;
767771}
768772
769773static READ32_HANDLER(geo_sharc_fifo_r)
r10427r10428
781785
782786static WRITE32_HANDLER(geo_sharc_fifo_w)
783787{
784    if (model2_geoctl & 0x80000000)
788   model2_state *state = space->machine->driver_data<model2_state>();
789    if (state->geoctl & 0x80000000)
785790    {
786        sharc_external_dma_write(space->machine->device("dsp2"), model2_geocnt, data & 0xffff);
791        sharc_external_dma_write(space->machine->device("dsp2"), state->geocnt, data & 0xffff);
787792
788        model2_geocnt++;
793        state->geocnt++;
789794    }
790795    else
791796    {
r10427r10428
793798    }
794799}
795800
796static int geo_iop_write_num = 0;
797static UINT32 geo_iop_data = 0;
798801static WRITE32_HANDLER(geo_sharc_iop_w)
799802{
803   model2_state *state = space->machine->driver_data<model2_state>();
800804    if ((strcmp(space->machine->gamedrv->name, "schamp" ) == 0))
801805    {
802806        sharc_external_iop_write(space->machine->device("dsp2"), offset, data);
803807    }
804808    else
805809    {
806        if ((geo_iop_write_num & 1) == 0)
810        if ((state->geo_iop_write_num & 1) == 0)
807811        {
808            geo_iop_data = data & 0xffff;
812            state->geo_iop_data = data & 0xffff;
809813        }
810814        else
811815        {
812            geo_iop_data |= (data & 0xffff) << 16;
813            sharc_external_iop_write(space->machine->device("dsp2"), offset, geo_iop_data);
816            state->geo_iop_data |= (data & 0xffff) << 16;
817            sharc_external_iop_write(space->machine->device("dsp2"), offset, state->geo_iop_data);
814818        }
815        geo_iop_write_num++;
819        state->geo_iop_write_num++;
816820    }
817821}
818822#endif
819823
820824
821static void push_geo_data(UINT32 data)
825static void push_geo_data(model2_state *state, UINT32 data)
822826{
823   //mame_printf_debug("push_geo_data: %08X: %08X\n", 0x900000+geo_write_start_address, data);
824   model2_bufferram[geo_write_start_address/4] = data;
825   geo_write_start_address += 4;
827   //mame_printf_debug("push_geo_data: %08X: %08X\n", 0x900000+state->geo_write_start_address, data);
828   state->bufferram[state->geo_write_start_address/4] = data;
829   state->geo_write_start_address += 4;
826830}
827831
828832static READ32_HANDLER(geo_prg_r)
r10427r10428
832836
833837static WRITE32_HANDLER(geo_prg_w)
834838{
835   if (model2_geoctl & 0x80000000)
839   model2_state *state = space->machine->driver_data<model2_state>();
840   if (state->geoctl & 0x80000000)
836841   {
837      //logerror("geo_prg_w: %08X:   %08X\n", model2_geocnt, data);
838      model2_geocnt++;
842      //logerror("geo_prg_w: %08X:   %08X\n", state->geocnt, data);
843      state->geocnt++;
839844   }
840845   else
841846   {
842      //mame_printf_debug("GEO: %08X: push %08X\n", geo_write_start_address, data);
843      push_geo_data(data);
847      //mame_printf_debug("GEO: %08X: push %08X\n", state->geo_write_start_address, data);
848      push_geo_data(state, data);
844849   }
845850}
846851
847852static READ32_HANDLER( geo_r )
848853{
854   model2_state *state = space->machine->driver_data<model2_state>();
849855   int address = offset * 4;
850856   if (address == 0x2008)
851857   {
852      return geo_write_start_address;
858      return state->geo_write_start_address;
853859   }
854860   else if (address == 0x3008)
855861   {
856      return geo_read_start_address;
862      return state->geo_read_start_address;
857863   }
858864
859865//  fatalerror("geo_r: %08X, %08X\n", address, mem_mask);
r10427r10428
864870
865871static WRITE32_HANDLER( geo_w )
866872{
873   model2_state *state = space->machine->driver_data<model2_state>();
867874   int address = offset * 4;
868875
869876   if (address < 0x1000)
r10427r10428
877884            for (i=0; i < 4; i++)
878885            {
879886                mame_printf_debug("   %08X: %08X %08X %08X %08X\n", 0x900000+(a*4)+(i*16),
880                    model2_bufferram[a+(i*4)+0], model2_bufferram[a+(i*4)+1], model2_bufferram[a+(i*4)+2], model2_bufferram[a+(i*4)+3]);
887                    state->bufferram[a+(i*4)+0], state->bufferram[a+(i*4)+1], state->bufferram[a+(i*4)+2], state->bufferram[a+(i*4)+3]);
881888            }
882889        }
883890        else
r10427r10428
901908         UINT32 r = 0;
902909         r |= data & 0x800fffff;
903910         r |= ((address >> 4) & 0x3f) << 23;
904         push_geo_data(r);
911         push_geo_data(state, r);
905912      }
906913      else
907914      {
r10427r10428
910917            UINT32 r = 0;
911918            r |= data & 0x000fffff;
912919            r |= ((address >> 4) & 0x3f) << 23;
913            push_geo_data(r);
920            push_geo_data(state, r);
914921         }
915922      }
916923   }
917924   else if (address == 0x1008)
918925   {
919926      //mame_printf_debug("GEO: Write Start Address: %08X\n", data);
920      geo_write_start_address = data & 0xfffff;
927      state->geo_write_start_address = data & 0xfffff;
921928   }
922929   else if (address == 0x3008)
923930   {
924931      //mame_printf_debug("GEO: Read Start Address: %08X\n", data);
925      geo_read_start_address = data & 0xfffff;
932      state->geo_read_start_address = data & 0xfffff;
926933   }
927934   else
928935   {
r10427r10428
960967
961968static READ32_HANDLER(model2_irq_r)
962969{
970   model2_state *state = space->machine->driver_data<model2_state>();
963971   i960_noburst(space->cpu);
964972
965973   if (offset)
966974   {
967      return model2_intena;
975      return state->intena;
968976   }
969977
970   return model2_intreq;
978   return state->intreq;
971979}
972980
973981static WRITE32_HANDLER(model2_irq_w)
974982{
983   model2_state *state = space->machine->driver_data<model2_state>();
975984   i960_noburst(space->cpu);
976985
977986   if (offset)
978987   {
979      COMBINE_DATA(&model2_intena);
988      COMBINE_DATA(&state->intena);
980989      return;
981990   }
982991
983   model2_intreq &= data;
992   state->intreq &= data;
984993}
985994
986static int to_68k;
987995
988996static int snd_68k_ready_r(address_space *space)
989997{
r10427r10428
10001008
10011009static void snd_latch_to_68k_w(address_space *space, int data)
10021010{
1011   model2_state *state = space->machine->driver_data<model2_state>();
10031012   if (!snd_68k_ready_r(space))
10041013   {
10051014      cpu_spinuntil_time(space->cpu, attotime::from_usec(40));
10061015   }
10071016
1008   to_68k = data;
1017   state->to_68k = data;
10091018
10101019   cputag_set_input_line(space->machine, "audiocpu", 2, HOLD_LINE);
10111020
r10427r10428
10591068{
10601069   0x43,0x66,0x54,0x11,0x99,0xfe,0xcc,0x8e,0xdd,0x87,0x11,0x89,0x22,0xdf,0x44,0x09
10611070};
1062static int protstate, protpos;
1063static UINT8 protram[256];
10641071
10651072static READ32_HANDLER( model2_prot_r )
10661073{
1067   static int a = 0;
1074   model2_state *state = space->machine->driver_data<model2_state>();
10681075   UINT32 retval = 0;
10691076
10701077   if (offset == 0x10000/4)
r10427r10428
10741081   }
10751082   else if (offset == 0x1000e/4)
10761083   {
1077      retval = protram[protstate+1] | protram[protstate]<<8;
1084      retval = state->protram[state->protstate+1] | state->protram[state->protstate]<<8;
10781085      retval <<= 16;
1079      protstate+=2;
1086      state->protstate+=2;
10801087   }
10811088   else if (offset == 0x7ff8/4)
10821089   {
1083      retval = protram[protstate+1] | protram[protstate]<<8;
1084      protstate+=2;
1090      retval = state->protram[state->protstate+1] | state->protram[state->protstate]<<8;
1091      state->protstate+=2;
10851092   }
10861093   else if (offset == 0x400c/4)
10871094   {
1088      a = !a;
1089      if (a)
1095      state->prot_a = !state->prot_a;
1096      if (state->prot_a)
10901097         return 0xffff;
10911098      else
10921099         return 0xfff0;
r10427r10428
10981105
10991106static WRITE32_HANDLER( model2_prot_w )
11001107{
1108   model2_state *state = space->machine->driver_data<model2_state>();
11011109   if (mem_mask == 0xffff0000)
11021110   {
11031111      data >>= 16;
r10427r10428
11051113
11061114   if (offset == 0x10008/4)
11071115   {
1108      protpos = data;
1116      state->protpos = data;
11091117   }
11101118   else if (offset == 0x1000c/4)
11111119   {
r10427r10428
11131121      {
11141122         // dynamcop
11151123         case 0x7700:
1116            strcpy((char *)protram+2, "UCHIDA MOMOKA   ");
1124            strcpy((char *)state->protram+2, "UCHIDA MOMOKA   ");
11171125            break;
11181126
11191127         // dynamcop
11201128         case 0x1326:
1121            protstate = 0;
1122            memcpy(protram+2, DCOPKey1326, sizeof(DCOPKey1326));
1129            state->protstate = 0;
1130            memcpy(state->protram+2, DCOPKey1326, sizeof(DCOPKey1326));
11231131            break;
11241132
11251133         // zerogun
r10427r10428
11381146         case 0x98CC:
11391147         case 0x3422:
11401148         case 0x10:
1141            protstate = 0;
1142            memcpy(protram+2, ZGUNProt+((2*protpos)/12)*8, sizeof(ZGUNProt));
1149            state->protstate = 0;
1150            memcpy(state->protram+2, ZGUNProt+((2*state->protpos)/12)*8, sizeof(ZGUNProt));
11431151            break;
11441152
11451153         // pltkids
11461154         case 0x7140:
1147            protstate = 0;
1148            strcpy((char *)protram+2, "98-PILOT  ");
1155            state->protstate = 0;
1156            strcpy((char *)state->protram+2, "98-PILOT  ");
11491157            break;
11501158
11511159         default:
1152            protstate = 0;
1160            state->protstate = 0;
11531161            break;
11541162      }
11551163   }
r10427r10428
11571165   {
11581166      if (data == 0)
11591167      {
1160         protstate = 0;
1161         strcpy((char *)protram, "  TECMO LTD.  DEAD OR ALIVE  1996.10.22  VER. 1.00");
1168         state->protstate = 0;
1169         strcpy((char *)state->protram, "  TECMO LTD.  DEAD OR ALIVE  1996.10.22  VER. 1.00");
11621170      }
11631171   }
11641172   else logerror("Unhandled Protection WRITE %x @ %x mask %x (PC=%x)\n", data, offset, mem_mask, cpu_get_pc(space->cpu));
r10427r10428
11671175
11681176/* Daytona "To The MAXX" PIC protection simulation */
11691177
1170static int model2_maxxstate = 0;
11711178
11721179static READ32_HANDLER( maxx_r )
11731180{
1181   model2_state *state = space->machine->driver_data<model2_state>();
11741182   UINT32 *ROM = (UINT32 *)space->machine->region("maincpu")->base();
11751183
11761184   if (offset <= 0x1f/4)
r10427r10428
11791187      if (mem_mask == 0xffff0000)
11801188      {
11811189         // 16-bit protection reads
1182         model2_maxxstate++;
1183         model2_maxxstate &= 0xf;
1184         if (!model2_maxxstate)
1190         state->maxxstate++;
1191         state->maxxstate &= 0xf;
1192         if (!state->maxxstate)
11851193         {
11861194            return 0x00070000;
11871195         }
11881196         else
11891197         {
1190            if (model2_maxxstate & 0x2)
1198            if (state->maxxstate & 0x2)
11911199            {
11921200               return 0;
11931201            }
r10427r10428
12121220
12131221/* Network board emulation */
12141222
1215static UINT32 model2_netram[0x8000/4];
12161223
1217static int zflagi, zflag, sysres;
12181224
12191225static READ32_HANDLER( network_r )
12201226{
1227   model2_state *state = space->machine->driver_data<model2_state>();
12211228   if ((mem_mask == 0xffffffff) || (mem_mask == 0x0000ffff) || (mem_mask == 0xffff0000))
12221229   {
12231230      return 0xffffffff;
r10427r10428
12251232
12261233   if (offset < 0x4000/4)
12271234   {
1228      return model2_netram[offset];
1235      return state->netram[offset];
12291236   }
12301237
12311238   if (mem_mask == 0x00ff0000)
12321239   {
1233      return sysres<<16;
1240      return state->sysres<<16;
12341241   }
12351242   else if (mem_mask == 0x000000ff)
12361243   {
1237      return zflagi;
1244      return state->zflagi;
12381245   }
12391246
12401247   return 0xffffffff;
r10427r10428
12421249
12431250static WRITE32_HANDLER( network_w )
12441251{
1252   model2_state *state = space->machine->driver_data<model2_state>();
12451253   if ((mem_mask == 0xffffffff) || (mem_mask == 0x0000ffff) || (mem_mask == 0xffff0000))
12461254   {
1247      COMBINE_DATA(&model2_netram[offset+0x4000/4]);
1255      COMBINE_DATA(&state->netram[offset+0x4000/4]);
12481256      return;
12491257   }
12501258
12511259   if (offset < 0x4000/4)
12521260   {
1253      COMBINE_DATA(&model2_netram[offset]);
1261      COMBINE_DATA(&state->netram[offset]);
12541262      return;
12551263   }
12561264
12571265   if (mem_mask == 0x00ff0000)
12581266   {
1259      sysres = data>>16;
1267      state->sysres = data>>16;
12601268   }
12611269   else if (mem_mask == 0x000000ff)
12621270   {
1263      zflagi = data;
1264      zflag = 0;
1265      if (data & 0x01) zflag |= 0x80;
1266      if (data & 0x80) zflag |= 0x01;
1271      state->zflagi = data;
1272      state->zflag = 0;
1273      if (data & 0x01) state->zflag |= 0x80;
1274      if (data & 0x80) state->zflag |= 0x01;
12671275   }
12681276}
12691277
r10427r10428
12941302
12951303static WRITE32_HANDLER(model2o_tex_w0)
12961304{
1305   model2_state *state = space->machine->driver_data<model2_state>();
12971306   if ( (offset & 1) == 0 )
12981307   {
1299      model2_textureram0[offset>>1] &= 0xffff0000;
1300      model2_textureram0[offset>>1] |= data & 0xffff;
1308      state->textureram0[offset>>1] &= 0xffff0000;
1309      state->textureram0[offset>>1] |= data & 0xffff;
13011310   }
13021311   else
13031312   {
1304      model2_textureram0[offset>>1] &= 0x0000ffff;
1305      model2_textureram0[offset>>1] |= (data & 0xffff) << 16;
1313      state->textureram0[offset>>1] &= 0x0000ffff;
1314      state->textureram0[offset>>1] |= (data & 0xffff) << 16;
13061315   }
13071316}
13081317
13091318static WRITE32_HANDLER(model2o_tex_w1)
13101319{
1320   model2_state *state = space->machine->driver_data<model2_state>();
13111321   if ( (offset & 1) == 0 )
13121322   {
1313      model2_textureram1[offset>>1] &= 0xffff0000;
1314      model2_textureram1[offset>>1] |= data & 0xffff;
1323      state->textureram1[offset>>1] &= 0xffff0000;
1324      state->textureram1[offset>>1] |= data & 0xffff;
13151325   }
13161326   else
13171327   {
1318      model2_textureram1[offset>>1] &= 0x0000ffff;
1319      model2_textureram1[offset>>1] |= (data & 0xffff) << 16;
1328      state->textureram1[offset>>1] &= 0x0000ffff;
1329      state->textureram1[offset>>1] |= (data & 0xffff) << 16;
13201330   }
13211331}
13221332
13231333static WRITE32_HANDLER(model2o_luma_w)
13241334{
1335   model2_state *state = space->machine->driver_data<model2_state>();
13251336   if ( (offset & 1) == 0 )
13261337   {
1327      model2_lumaram[offset>>1] &= 0xffff0000;
1328      model2_lumaram[offset>>1] |= data & 0xffff;
1338      state->lumaram[offset>>1] &= 0xffff0000;
1339      state->lumaram[offset>>1] |= data & 0xffff;
13291340   }
13301341   else
13311342   {
1332      model2_lumaram[offset>>1] &= 0x0000ffff;
1333      model2_lumaram[offset>>1] |= (data & 0xffff) << 16;
1343      state->lumaram[offset>>1] &= 0x0000ffff;
1344      state->lumaram[offset>>1] |= (data & 0xffff) << 16;
13341345   }
13351346}
13361347
13371348static WRITE32_HANDLER(model2_3d_zclip_w)
13381349{
1339   model2_3d_set_zclip( data & 0xFF );
1350   model2_3d_set_zclip( space->machine, data & 0xFF );
13401351}
13411352
13421353/* common map for all Model 2 versions */
13431354static ADDRESS_MAP_START( model2_base_mem, ADDRESS_SPACE_PROGRAM, 32 )
13441355   AM_RANGE(0x00000000, 0x001fffff) AM_ROM AM_WRITENOP
13451356
1346   AM_RANGE(0x00500000, 0x005fffff) AM_RAM AM_BASE(&model2_workram)
1357   AM_RANGE(0x00500000, 0x005fffff) AM_RAM AM_BASE_MEMBER(model2_state, workram)
13471358
13481359   AM_RANGE(0x00800000, 0x00803fff) AM_READWRITE(geo_r, geo_w)
13491360   //AM_RANGE(0x00800010, 0x00800013) AM_WRITENOP
r10427r10428
13521363
13531364   //AM_RANGE(0x00880000, 0x00883fff) AM_WRITE(copro_w)
13541365
1355   AM_RANGE(0x00900000, 0x0097ffff) AM_RAM AM_BASE(&model2_bufferram)
1366   AM_RANGE(0x00900000, 0x0097ffff) AM_RAM AM_BASE_MEMBER(model2_state, bufferram)
13561367
13571368
13581369   AM_RANGE(0x00980004, 0x00980007) AM_READ(fifoctl_r)
r10427r10428
13711382   AM_RANGE(0x01100000, 0x0110ffff) AM_READWRITE(sys24_tile32_r, sys24_tile32_w) AM_MIRROR(0x10000)
13721383   AM_RANGE(0x01180000, 0x011fffff) AM_READWRITE(sys24_char32_r, sys24_char32_w) AM_MIRROR(0x100000)
13731384
1374   AM_RANGE(0x01800000, 0x01803fff) AM_RAM_WRITE(pal32_w) AM_BASE(&model2_paletteram32)
1375   AM_RANGE(0x01810000, 0x0181bfff) AM_RAM AM_BASE(&model2_colorxlat)
1385   AM_RANGE(0x01800000, 0x01803fff) AM_RAM_WRITE(pal32_w) AM_BASE_MEMBER(model2_state, paletteram32)
1386   AM_RANGE(0x01810000, 0x0181bfff) AM_RAM AM_BASE_MEMBER(model2_state, colorxlat)
13761387   AM_RANGE(0x0181c000, 0x0181c003) AM_WRITE(model2_3d_zclip_w)
13771388   AM_RANGE(0x01a10000, 0x01a1ffff) AM_READWRITE(network_r, network_w)
13781389   AM_RANGE(0x01d00000, 0x01d03fff) AM_RAM AM_SHARE("backup1") // Backup sram
r10427r10428
14021413   AM_RANGE(0x00980008, 0x0098000b) AM_WRITE( geo_ctl1_w )
14031414   AM_RANGE(0x009c0000, 0x009cffff) AM_READWRITE( model2_serial_r, model2o_serial_w )
14041415
1405   AM_RANGE(0x12000000, 0x121fffff) AM_RAM_WRITE(model2o_tex_w0) AM_MIRROR(0x200000) AM_BASE(&model2_textureram0)   // texture RAM 0
1406   AM_RANGE(0x12400000, 0x125fffff) AM_RAM_WRITE(model2o_tex_w1) AM_MIRROR(0x200000) AM_BASE(&model2_textureram1)   // texture RAM 1
1407   AM_RANGE(0x12800000, 0x1281ffff) AM_RAM_WRITE(model2o_luma_w) AM_BASE(&model2_lumaram) // polygon "luma" RAM
1416   AM_RANGE(0x12000000, 0x121fffff) AM_RAM_WRITE(model2o_tex_w0) AM_MIRROR(0x200000) AM_BASE_MEMBER(model2_state, textureram0)   // texture RAM 0
1417   AM_RANGE(0x12400000, 0x125fffff) AM_RAM_WRITE(model2o_tex_w1) AM_MIRROR(0x200000) AM_BASE_MEMBER(model2_state, textureram1)   // texture RAM 1
1418   AM_RANGE(0x12800000, 0x1281ffff) AM_RAM_WRITE(model2o_luma_w) AM_BASE_MEMBER(model2_state, lumaram) // polygon "luma" RAM
14081419
14091420   AM_RANGE(0x01c00000, 0x01c00003) AM_READ_PORT("1c00000")
14101421   AM_RANGE(0x01c00004, 0x01c00007) AM_READ_PORT("1c00004")
r10427r10428
14321443   AM_RANGE(0x00980008, 0x0098000b) AM_WRITE( geo_ctl1_w )
14331444   AM_RANGE(0x009c0000, 0x009cffff) AM_READWRITE( model2_serial_r, model2_serial_w )
14341445
1435   AM_RANGE(0x12000000, 0x121fffff) AM_RAM_WRITE(model2o_tex_w0) AM_MIRROR(0x200000) AM_BASE(&model2_textureram0)   // texture RAM 0
1436   AM_RANGE(0x12400000, 0x125fffff) AM_RAM_WRITE(model2o_tex_w1) AM_MIRROR(0x200000) AM_BASE(&model2_textureram1)   // texture RAM 1
1437   AM_RANGE(0x12800000, 0x1281ffff) AM_RAM_WRITE(model2o_luma_w) AM_BASE(&model2_lumaram) // polygon "luma" RAM
1446   AM_RANGE(0x12000000, 0x121fffff) AM_RAM_WRITE(model2o_tex_w0) AM_MIRROR(0x200000) AM_BASE_MEMBER(model2_state, textureram0)   // texture RAM 0
1447   AM_RANGE(0x12400000, 0x125fffff) AM_RAM_WRITE(model2o_tex_w1) AM_MIRROR(0x200000) AM_BASE_MEMBER(model2_state, textureram1)   // texture RAM 1
1448   AM_RANGE(0x12800000, 0x1281ffff) AM_RAM_WRITE(model2o_luma_w) AM_BASE_MEMBER(model2_state, lumaram) // polygon "luma" RAM
14381449
14391450   AM_RANGE(0x01c00000, 0x01c00003) AM_READ_PORT("1c00000") AM_WRITE( ctrl0_w )
14401451   AM_RANGE(0x01c00004, 0x01c00007) AM_READ_PORT("1c00004")
r10427r10428
14661477
14671478   AM_RANGE(0x009c0000, 0x009cffff) AM_READWRITE( model2_serial_r, model2_serial_w )
14681479
1469   AM_RANGE(0x11000000, 0x111fffff) AM_RAM   AM_BASE(&model2_textureram0)   // texture RAM 0 (2b/2c)
1470   AM_RANGE(0x11200000, 0x113fffff) AM_RAM   AM_BASE(&model2_textureram1)   // texture RAM 1 (2b/2c)
1471   AM_RANGE(0x11400000, 0x1140ffff) AM_RAM   AM_BASE(&model2_lumaram)      // polygon "luma" RAM (2b/2c)
1480   AM_RANGE(0x11000000, 0x111fffff) AM_RAM   AM_BASE_MEMBER(model2_state, textureram0)   // texture RAM 0 (2b/2c)
1481   AM_RANGE(0x11200000, 0x113fffff) AM_RAM   AM_BASE_MEMBER(model2_state, textureram1)   // texture RAM 1 (2b/2c)
1482   AM_RANGE(0x11400000, 0x1140ffff) AM_RAM   AM_BASE_MEMBER(model2_state, lumaram)      // polygon "luma" RAM (2b/2c)
14721483
14731484
14741485   AM_RANGE(0x01c00000, 0x01c00003) AM_READ_PORT("1c00000") AM_WRITE( ctrl0_w )
r10427r10428
14931504   AM_RANGE(0x00980008, 0x0098000b) AM_WRITE( geo_ctl1_w )
14941505   AM_RANGE(0x009c0000, 0x009cffff) AM_READWRITE( model2_serial_r, model2_serial_w )
14951506
1496   AM_RANGE(0x11000000, 0x111fffff) AM_RAM   AM_BASE(&model2_textureram0)   // texture RAM 0 (2b/2c)
1497   AM_RANGE(0x11200000, 0x113fffff) AM_RAM   AM_BASE(&model2_textureram1)   // texture RAM 1 (2b/2c)
1498   AM_RANGE(0x11400000, 0x1140ffff) AM_RAM   AM_BASE(&model2_lumaram)      // polygon "luma" RAM (2b/2c)
1507   AM_RANGE(0x11000000, 0x111fffff) AM_RAM   AM_BASE_MEMBER(model2_state, textureram0)   // texture RAM 0 (2b/2c)
1508   AM_RANGE(0x11200000, 0x113fffff) AM_RAM   AM_BASE_MEMBER(model2_state, textureram1)   // texture RAM 1 (2b/2c)
1509   AM_RANGE(0x11400000, 0x1140ffff) AM_RAM   AM_BASE_MEMBER(model2_state, lumaram)      // polygon "luma" RAM (2b/2c)
14991510
15001511   AM_RANGE(0x01c00000, 0x01c00003) AM_READ_PORT("1c00000") AM_WRITE( ctrl0_w )
15011512   AM_RANGE(0x01c00004, 0x01c00007) AM_READ_PORT("1c00004")
r10427r10428
17771788
17781789static INTERRUPT_GEN(model2_interrupt)
17791790{
1791   model2_state *state = device->machine->driver_data<model2_state>();
17801792   switch (cpu_getiloops(device))
17811793   {
17821794      case 0:
1783         model2_intreq |= (1<<10);
1784         if (model2_intena & (1<<10))
1795         state->intreq |= (1<<10);
1796         if (state->intena & (1<<10))
17851797         {
17861798            cpu_set_input_line(device, I960_IRQ3, ASSERT_LINE);
17871799         }
17881800         break;
17891801      case 1:
1790         model2_intreq |= (1<<0);
1791         if (model2_intena & (1<<0))
1802         state->intreq |= (1<<0);
1803         if (state->intena & (1<<0))
17921804         {
17931805            cpu_set_input_line(device, I960_IRQ0, ASSERT_LINE);
17941806         }
r10427r10428
17981810
17991811static INTERRUPT_GEN(model2c_interrupt)
18001812{
1813   model2_state *state = device->machine->driver_data<model2_state>();
18011814   switch (cpu_getiloops(device))
18021815   {
18031816      case 0:
1804         model2_intreq |= (1<<10);
1805         if (model2_intena & (1<<10))
1817         state->intreq |= (1<<10);
1818         if (state->intena & (1<<10))
18061819            cpu_set_input_line(device, I960_IRQ3, ASSERT_LINE);
18071820         break;
18081821      case 1:
1809         model2_intreq |= (1<<2);
1810         if (model2_intena & (1<<2))
1822         state->intreq |= (1<<2);
1823         if (state->intena & (1<<2))
18111824            cpu_set_input_line(device, I960_IRQ2, ASSERT_LINE);
18121825
18131826         break;
18141827      case 2:
1815         model2_intreq |= (1<<0);
1816         if (model2_intena & (1<<0))
1828         state->intreq |= (1<<0);
1829         if (state->intena & (1<<0))
18171830            cpu_set_input_line(device, I960_IRQ0, ASSERT_LINE);
18181831         break;
18191832   }
r10427r10428
18231836
18241837static READ16_HANDLER( m1_snd_68k_latch_r )
18251838{
1826   return to_68k;
1839   model2_state *state = space->machine->driver_data<model2_state>();
1840   return state->to_68k;
18271841}
18281842
18291843static READ16_HANDLER( m1_snd_v60_ready_r )
r10427r10428
18801894}
18811895
18821896static ADDRESS_MAP_START( model2_snd, ADDRESS_SPACE_PROGRAM, 16 )
1883   AM_RANGE(0x000000, 0x07ffff) AM_RAM AM_REGION("audiocpu", 0) AM_BASE(&model2_soundram)
1897   AM_RANGE(0x000000, 0x07ffff) AM_RAM AM_REGION("audiocpu", 0) AM_BASE_MEMBER(model2_state, soundram)
18841898   AM_RANGE(0x100000, 0x100fff) AM_DEVREADWRITE("scsp", scsp_r, scsp_w)
18851899   AM_RANGE(0x400000, 0x400001) AM_WRITE(model2snd_ctrl)
18861900   AM_RANGE(0x600000, 0x67ffff) AM_ROM AM_REGION("audiocpu", 0x80000)
r10427r10428
18891903   AM_RANGE(0xe00000, 0xffffff) AM_ROMBANK("bank5")
18901904ADDRESS_MAP_END
18911905
1892static int scsp_last_line = 0;
18931906
18941907static void scsp_irq(device_t *device, int irq)
18951908{
1909   model2_state *state = device->machine->driver_data<model2_state>();
18961910   if (irq > 0)
18971911   {
1898      scsp_last_line = irq;
1912      state->scsp_last_line = irq;
18991913      cputag_set_input_line(device->machine, "audiocpu", irq, ASSERT_LINE);
19001914   }
19011915   else
r10427r10428
19301944
19311945static READ32_HANDLER(copro_sharc_buffer_r)
19321946{
1933   return model2_bufferram[offset & 0x7fff];
1947   model2_state *state = space->machine->driver_data<model2_state>();
1948   return state->bufferram[offset & 0x7fff];
19341949}
19351950
19361951static WRITE32_HANDLER(copro_sharc_buffer_w)
19371952{
1953   model2_state *state = space->machine->driver_data<model2_state>();
19381954   //mame_printf_debug("sharc_buffer_w: %08X at %08X, %08X, %f\n", offset, cpu_get_pc(space->cpu), data, *(float*)&data);
1939   model2_bufferram[offset & 0x7fff] = data;
1955   state->bufferram[offset & 0x7fff] = data;
19401956}
19411957
19421958static ADDRESS_MAP_START( copro_sharc_map, ADDRESS_SPACE_DATA, 32 )
r10427r10428
19561972
19571973static READ32_HANDLER(copro_tgp_buffer_r)
19581974{
1959   return model2_bufferram[offset & 0x7fff];
1975   model2_state *state = space->machine->driver_data<model2_state>();
1976   return state->bufferram[offset & 0x7fff];
19601977}
19611978
19621979static WRITE32_HANDLER(copro_tgp_buffer_w)
19631980{
1964   model2_bufferram[offset&0x7fff] = data;
1981   model2_state *state = space->machine->driver_data<model2_state>();
1982   state->bufferram[offset&0x7fff] = data;
19651983}
19661984
19671985static ADDRESS_MAP_START( copro_tgp_map, ADDRESS_SPACE_PROGRAM, 32 )
1968   AM_RANGE(0x00000000, 0x00007fff) AM_RAM AM_BASE(&tgp_program)
1986   AM_RANGE(0x00000000, 0x00007fff) AM_RAM AM_BASE_MEMBER(model2_state, tgp_program)
19691987   AM_RANGE(0x00400000, 0x00407fff) AM_READWRITE(copro_tgp_buffer_r, copro_tgp_buffer_w)
19701988   AM_RANGE(0xff800000, 0xff9fffff) AM_ROM AM_REGION("tgp", 0)
19711989ADDRESS_MAP_END
r10427r10428
19822000
19832001
19842002/* original Model 2 */
1985static MACHINE_CONFIG_START( model2o, driver_device )
2003static MACHINE_CONFIG_START( model2o, model2_state )
19862004   MCFG_CPU_ADD("maincpu", I960, 25000000)
19872005   MCFG_CPU_PROGRAM_MAP(model2o_mem)
19882006   MCFG_CPU_VBLANK_INT_HACK(model2_interrupt,2)
r10427r10428
19942012   MCFG_CPU_CONFIG(tgp_config)
19952013   MCFG_CPU_PROGRAM_MAP(copro_tgp_map)
19962014
2015   MCFG_MACHINE_START(model2)
19972016   MCFG_MACHINE_RESET(model2o)
19982017
19992018   MCFG_EEPROM_93C46_ADD("eeprom")
r10427r10428
20392058MACHINE_CONFIG_END
20402059
20412060/* 2A-CRX */
2042static MACHINE_CONFIG_START( model2a, driver_device )
2061static MACHINE_CONFIG_START( model2a, model2_state )
20432062   MCFG_CPU_ADD("maincpu", I960, 25000000)
20442063   MCFG_CPU_PROGRAM_MAP(model2a_crx_mem)
20452064   MCFG_CPU_VBLANK_INT_HACK(model2_interrupt,2)
r10427r10428
20512070   MCFG_CPU_CONFIG(tgp_config)
20522071   MCFG_CPU_PROGRAM_MAP(copro_tgp_map)
20532072
2073   MCFG_MACHINE_START(model2)
20542074   MCFG_MACHINE_RESET(model2)
20552075
20562076   MCFG_EEPROM_93C46_ADD("eeprom")
r10427r10428
20892109
20902110static READ8_HANDLER( driveio_port_r )
20912111{
2092   return driveio_comm_data;
2112   model2_state *state = space->machine->driver_data<model2_state>();
2113   return state->driveio_comm_data;
20932114}
20942115
20952116static WRITE8_HANDLER( driveio_port_w )
r10427r10428
21342155};
21352156
21362157/* 2B-CRX */
2137static MACHINE_CONFIG_START( model2b, driver_device )
2158static MACHINE_CONFIG_START( model2b, model2_state )
21382159   MCFG_CPU_ADD("maincpu", I960, 25000000)
21392160   MCFG_CPU_PROGRAM_MAP(model2b_crx_mem)
21402161   MCFG_CPU_VBLANK_INT_HACK(model2_interrupt,2)
r10427r10428
21522173
21532174   MCFG_QUANTUM_TIME(attotime::from_hz(18000))
21542175
2176   MCFG_MACHINE_START(model2)
21552177   MCFG_MACHINE_RESET(model2b)
21562178
21572179   MCFG_EEPROM_93C46_ADD("eeprom")
r10427r10428
21892211MACHINE_CONFIG_END
21902212
21912213/* 2C-CRX */
2192static MACHINE_CONFIG_START( model2c, driver_device )
2214static MACHINE_CONFIG_START( model2c, model2_state )
21932215   MCFG_CPU_ADD("maincpu", I960, 25000000)
21942216   MCFG_CPU_PROGRAM_MAP(model2c_crx_mem)
21952217   MCFG_CPU_VBLANK_INT_HACK(model2c_interrupt,3)
r10427r10428
21972219   MCFG_CPU_ADD("audiocpu", M68000, 12000000)
21982220   MCFG_CPU_PROGRAM_MAP(model2_snd)
21992221
2222   MCFG_MACHINE_START(model2)
22002223   MCFG_MACHINE_RESET(model2c)
22012224
22022225   MCFG_EEPROM_93C46_ADD("eeprom")
r10427r10428
49714994
49724995static DRIVER_INIT( genprot )
49734996{
4997   model2_state *state = machine->driver_data<model2_state>();
49744998   memory_install_readwrite32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x01d80000, 0x01dfffff, 0, 0, model2_prot_r, model2_prot_w);
4975   protstate = protpos = 0;
4999   state->protstate = state->protpos = 0;
49765000}
49775001
49785002static DRIVER_INIT( pltkids )
49795003{
5004   model2_state *state = machine->driver_data<model2_state>();
49805005   UINT32 *ROM = (UINT32 *)machine->region("maincpu")->base();
49815006
49825007   memory_install_readwrite32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x01d80000, 0x01dfffff, 0, 0, model2_prot_r, model2_prot_w);
4983   protstate = protpos = 0;
5008   state->protstate = state->protpos = 0;
49845009
49855010   // fix bug in program: it destroys the interrupt table and never fixes it
49865011   ROM[0x730/4] = 0x08000004;
r10427r10428
49885013
49895014static DRIVER_INIT( zerogun )
49905015{
5016   model2_state *state = machine->driver_data<model2_state>();
49915017   UINT32 *ROM = (UINT32 *)machine->region("maincpu")->base();
49925018
49935019   memory_install_readwrite32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x01d80000, 0x01dfffff, 0, 0, model2_prot_r, model2_prot_w);
4994   protstate = protpos = 0;
5020   state->protstate = state->protpos = 0;
49955021
49965022   // fix bug in program: it destroys the interrupt table and never fixes it
49975023   ROM[0x700/4] = 0x08000004;
r10427r10428
50035029}
50045030
50055031/* very crude support for let the game set itself into stand-alone mode */
5006static int jnet_time_out;
50075032
50085033static READ32_HANDLER( jaleco_network_r )
50095034{
5035   model2_state *state = space->machine->driver_data<model2_state>();
50105036   if(offset == 0x4000/4)
50115037   {
5012      if(model2_netram[offset] == 0x00000000)
5013         jnet_time_out = 0;
5038      if(state->netram[offset] == 0x00000000)
5039         state->jnet_time_out = 0;
50145040
5015      if((model2_netram[offset] & 0xffff) == 0x0001)
5016         jnet_time_out++;
5041      if((state->netram[offset] & 0xffff) == 0x0001)
5042         state->jnet_time_out++;
50175043
5018      if(jnet_time_out > 0x80)
5019         model2_netram[offset]|= 0x00800000;
5044      if(state->jnet_time_out > 0x80)
5045         state->netram[offset]|= 0x00800000;
50205046
5021      return model2_netram[offset];
5047      return state->netram[offset];
50225048   }
50235049
5024   return model2_netram[offset];
5050   return state->netram[offset];
50255051}
50265052
50275053static WRITE32_HANDLER( jaleco_network_w )
50285054{
5029   COMBINE_DATA(&model2_netram[offset]);
5055   model2_state *state = space->machine->driver_data<model2_state>();
5056   COMBINE_DATA(&state->netram[offset]);
50305057}
50315058
50325059static DRIVER_INIT( sgt24h )
50335060{
5061   model2_state *state = machine->driver_data<model2_state>();
50345062   UINT32 *ROM = (UINT32 *)machine->region("maincpu")->base();
50355063
50365064   memory_install_readwrite32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x01d80000, 0x01dfffff, 0, 0, model2_prot_r, model2_prot_w);
50375065   memory_install_readwrite32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x01a10000, 0x01a1ffff, 0, 0, jaleco_network_r, jaleco_network_w);
50385066
5039   protstate = protpos = 0;
5067   state->protstate = state->protpos = 0;
50405068
50415069   ROM[0x56578/4] = 0x08000004;
50425070   ROM[0x5b3e8/4] = 0x08000004;
r10427r10428
50525080
50535081static DRIVER_INIT( doa )
50545082{
5083   model2_state *state = machine->driver_data<model2_state>();
50555084   UINT32 *ROM = (UINT32 *)machine->region("maincpu")->base();
50565085
50575086   memory_install_readwrite32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x01d80000, 0x01dfffff, 0, 0, model2_prot_r, model2_prot_w);
5058   protstate = protpos = 0;
5087   state->protstate = state->protpos = 0;
50595088
50605089   ROM[0x630/4] = 0x08000004;
50615090   ROM[0x808/4] = 0x08000004;
src/mame/drivers/sshangha.c
r10427r10428
6060
6161#define SSHANGHA_HACK   0
6262
63static UINT16 *sshangha_prot_data;
6463
65static UINT16 *sshangha_sound_shared_ram;
6664
6765/******************************************************************************/
6866
6967static WRITE16_HANDLER( sshangha_protection16_w )
7068{
71   COMBINE_DATA(&sshangha_prot_data[offset]);
69   sshangha_state *state = space->machine->driver_data<sshangha_state>();
70   COMBINE_DATA(&state->prot_data[offset]);
7271
7372   logerror("CPU #0 PC %06x: warning - write unmapped control address %06x %04x\n",cpu_get_pc(space->cpu),offset<<1,data);
7473}
r10427r10428
7675/* Protection/IO chip 146 */
7776static READ16_HANDLER( sshangha_protection16_r )
7877{
78   sshangha_state *state = space->machine->driver_data<sshangha_state>();
7979   switch (offset)
8080   {
8181      case 0x050 >> 1:
r10427r10428
8989   }
9090
9191   logerror("CPU #0 PC %06x: warning - read unmapped control address %06x\n",cpu_get_pc(space->cpu),offset<<1);
92   return sshangha_prot_data[offset];
92   return state->prot_data[offset];
9393}
9494
9595static READ16_HANDLER( sshanghb_protection16_r )
9696{
97   sshangha_state *state = space->machine->driver_data<sshangha_state>();
9798   switch (offset)
9899   {
99100      case 0x050 >> 1:
r10427r10428
104105         return input_port_read(space->machine, "DSW");
105106   }
106107
107   return sshangha_prot_data[offset];
108   return state->prot_data[offset];
108109}
109110
110111/* Probably returns 0xffff when sprite DMA is complete, the game waits on it */
r10427r10428
131132
132133static ADDRESS_MAP_START( sshangha_map, ADDRESS_SPACE_PROGRAM, 16 )
133134   AM_RANGE(0x000000, 0x03ffff) AM_ROM
134   AM_RANGE(0x100000, 0x10000f) AM_RAM AM_BASE(&sshangha_sound_shared_ram)
135   AM_RANGE(0x100000, 0x10000f) AM_RAM AM_BASE_MEMBER(sshangha_state, sound_shared_ram)
135136
136   AM_RANGE(0x200000, 0x201fff) AM_RAM_WRITE(sshangha_pf1_data_w) AM_BASE(&sshangha_pf1_data)
137   AM_RANGE(0x202000, 0x203fff) AM_RAM_WRITE(sshangha_pf2_data_w) AM_BASE(&sshangha_pf2_data)
138   AM_RANGE(0x204000, 0x2047ff) AM_RAM AM_BASE(&sshangha_pf1_rowscroll)
139   AM_RANGE(0x206000, 0x2067ff) AM_RAM AM_BASE(&sshangha_pf2_rowscroll)
137   AM_RANGE(0x200000, 0x201fff) AM_RAM_WRITE(sshangha_pf1_data_w) AM_BASE_MEMBER(sshangha_state, pf1_data)
138   AM_RANGE(0x202000, 0x203fff) AM_RAM_WRITE(sshangha_pf2_data_w) AM_BASE_MEMBER(sshangha_state, pf2_data)
139   AM_RANGE(0x204000, 0x2047ff) AM_RAM AM_BASE_MEMBER(sshangha_state, pf1_rowscroll)
140   AM_RANGE(0x206000, 0x2067ff) AM_RAM AM_BASE_MEMBER(sshangha_state, pf2_rowscroll)
140141   AM_RANGE(0x206800, 0x207fff) AM_RAM
141142   AM_RANGE(0x300000, 0x30000f) AM_WRITE(sshangha_control_0_w)
142143   AM_RANGE(0x320000, 0x320001) AM_WRITE(sshangha_video_w)
r10427r10428
152153   AM_RANGE(0x380000, 0x383fff) AM_RAM_WRITE(paletteram16_xbgr_word_be_w) AM_BASE_GENERIC(paletteram)
153154   AM_RANGE(0x3c0000, 0x3c0fff) AM_RAM   /* Sprite ram buffer on bootleg only?? */
154155   AM_RANGE(0xfec000, 0xff3fff) AM_RAM
155   AM_RANGE(0xff4000, 0xff47ff) AM_READWRITE(sshangha_protection16_r,sshangha_protection16_w) AM_BASE(&sshangha_prot_data)
156   AM_RANGE(0xff4000, 0xff47ff) AM_READWRITE(sshangha_protection16_r,sshangha_protection16_w) AM_BASE_MEMBER(sshangha_state, prot_data)
156157ADDRESS_MAP_END
157158
158159static ADDRESS_MAP_START( sshanghb_map, ADDRESS_SPACE_PROGRAM, 16 )
159160   AM_RANGE(0x000000, 0x03ffff) AM_ROM
160161   AM_RANGE(0x084000, 0x0847ff) AM_READ(sshanghb_protection16_r)
161   AM_RANGE(0x101000, 0x10100f) AM_RAM AM_BASE(&sshangha_sound_shared_ram) /* the bootleg writes here */
162   AM_RANGE(0x101000, 0x10100f) AM_RAM AM_BASE_MEMBER(sshangha_state, sound_shared_ram) /* the bootleg writes here */
162163
163   AM_RANGE(0x200000, 0x201fff) AM_RAM_WRITE(sshangha_pf1_data_w) AM_BASE(&sshangha_pf1_data)
164   AM_RANGE(0x202000, 0x203fff) AM_RAM_WRITE(sshangha_pf2_data_w) AM_BASE(&sshangha_pf2_data)
165   AM_RANGE(0x204000, 0x2047ff) AM_RAM AM_BASE(&sshangha_pf1_rowscroll)
166   AM_RANGE(0x206000, 0x2067ff) AM_RAM AM_BASE(&sshangha_pf2_rowscroll)
164   AM_RANGE(0x200000, 0x201fff) AM_RAM_WRITE(sshangha_pf1_data_w) AM_BASE_MEMBER(sshangha_state, pf1_data)
165   AM_RANGE(0x202000, 0x203fff) AM_RAM_WRITE(sshangha_pf2_data_w) AM_BASE_MEMBER(sshangha_state, pf2_data)
166   AM_RANGE(0x204000, 0x2047ff) AM_RAM AM_BASE_MEMBER(sshangha_state, pf1_rowscroll)
167   AM_RANGE(0x206000, 0x2067ff) AM_RAM AM_BASE_MEMBER(sshangha_state, pf2_rowscroll)
167168   AM_RANGE(0x206800, 0x207fff) AM_RAM
168169   AM_RANGE(0x300000, 0x30000f) AM_WRITE(sshangha_control_0_w)
169170   AM_RANGE(0x320000, 0x320001) AM_WRITE(sshangha_video_w)
r10427r10428
188189
189190static READ8_HANDLER(sshangha_sound_shared_r)
190191{
191   return sshangha_sound_shared_ram[offset] & 0xff;
192   sshangha_state *state = space->machine->driver_data<sshangha_state>();
193   return state->sound_shared_ram[offset] & 0xff;
192194}
193195
194196static WRITE8_HANDLER(sshangha_sound_shared_w)
195197{
196   sshangha_sound_shared_ram[offset] = data & 0xff;
198   sshangha_state *state = space->machine->driver_data<sshangha_state>();
199   state->sound_shared_ram[offset] = data & 0xff;
197200}
198201
199202/* Note: there's rom data after 0x8000 but the game never seem to call a rom bank, left-over? */
r10427r10428
342345   irqhandler
343346};
344347
345static MACHINE_CONFIG_START( sshangha, driver_device )
348static MACHINE_CONFIG_START( sshangha, sshangha_state )
346349
347350   /* basic machine hardware */
348351   MCFG_CPU_ADD("maincpu", M68000, 28000000/2)
src/mame/drivers/cchasm.c
r10427r10428
3838   AM_RANGE(0x060000, 0x060001) AM_READ_PORT("DSW") AM_WRITE(cchasm_led_w)
3939   AM_RANGE(0x070000, 0x070001) AM_WRITE(watchdog_reset16_w)
4040   AM_RANGE(0xf80000, 0xf800ff) AM_READWRITE(cchasm_io_r,cchasm_io_w)
41   AM_RANGE(0xffb000, 0xffffff) AM_RAM AM_BASE(&cchasm_ram)
41   AM_RANGE(0xffb000, 0xffffff) AM_RAM AM_BASE_MEMBER(cchasm_state, ram)
4242ADDRESS_MAP_END
4343
4444/*************************************
r10427r10428
153153 *
154154 *************************************/
155155
156static MACHINE_CONFIG_START( cchasm, driver_device )
156static MACHINE_CONFIG_START( cchasm, cchasm_state )
157157
158158   /* basic machine hardware */
159159   MCFG_CPU_ADD("maincpu", M68000,CCHASM_68K_CLOCK)   /* 8 MHz (from schematics) */
src/mame/drivers/cinemat.c
r10427r10428
4343#define MASTER_CLOCK         XTAL_19_923MHz
4444
4545
46
47static UINT16 *rambase;
48
49static UINT8 coin_detected;
50static UINT8 coin_last_reset;
51
52static UINT8 mux_select;
53static int gear;
54
55
56
5746/*************************************
5847 *
5948 *  General machine init
r10427r10428
6251
6352static MACHINE_START( cinemat )
6453{
65   state_save_register_global(machine, coin_detected);
66   state_save_register_global(machine, coin_last_reset);
67   state_save_register_global(machine, mux_select);
54   cinemat_state *state = machine->driver_data<cinemat_state>();
55   state_save_register_global(machine, state->coin_detected);
56   state_save_register_global(machine, state->coin_last_reset);
57   state_save_register_global(machine, state->mux_select);
6858}
6959
7060
7161MACHINE_RESET( cinemat )
7262{
63   cinemat_state *state = machine->driver_data<cinemat_state>();
7364   /* reset the coin states */
74   coin_detected = 0;
75   coin_last_reset = 0;
65   state->coin_detected = 0;
66   state->coin_last_reset = 0;
7667
7768   /* reset mux select */
78   mux_select = 0;
69   state->mux_select = 0;
7970}
8071
8172
r10427r10428
10899
109100static INPUT_CHANGED( coin_inserted )
110101{
102   cinemat_state *state = field->port->machine->driver_data<cinemat_state>();
111103   /* on the falling edge of a new coin, set the coin_detected flag */
112104   if (newval == 0)
113      coin_detected = 1;
105      state->coin_detected = 1;
114106}
115107
116108
117109static READ8_HANDLER( coin_input_r )
118110{
119   return !coin_detected;
111   cinemat_state *state = space->machine->driver_data<cinemat_state>();
112   return !state->coin_detected;
120113}
121114
122115
r10427r10428
129122
130123static WRITE8_HANDLER( coin_reset_w )
131124{
125   cinemat_state *state = space->machine->driver_data<cinemat_state>();
132126   /* on the rising edge of a coin reset, clear the coin_detected flag */
133   if (coin_last_reset != data && data != 0)
134      coin_detected = 0;
135   coin_last_reset = data;
127   if (state->coin_last_reset != data && data != 0)
128      state->coin_detected = 0;
129   state->coin_last_reset = data;
136130}
137131
138132
139133static WRITE8_HANDLER( mux_select_w )
140134{
141   mux_select = data;
135   cinemat_state *state = space->machine->driver_data<cinemat_state>();
136   state->mux_select = data;
142137   cinemat_sound_control_w(space, 0x07, data);
143138}
144139
r10427r10428
152147
153148static UINT8 joystick_read(device_t *device)
154149{
150   cinemat_state *state = device->machine->driver_data<cinemat_state>();
155151   if (device->machine->phase() != MACHINE_PHASE_RUNNING)
156152      return 0;
157153   else
158154   {
159155      int xval = (INT16)(cpu_get_reg(device, CCPU_X) << 4) >> 4;
160      return (input_port_read_safe(device->machine, mux_select ? "ANALOGX" : "ANALOGY", 0) - xval) < 0x800;
156      return (input_port_read_safe(device->machine, state->mux_select ? "ANALOGX" : "ANALOGY", 0) - xval) < 0x800;
161157   }
162158}
163159
r10427r10428
187183
188184static READ8_HANDLER( speedfrk_gear_r )
189185{
186   cinemat_state *state = space->machine->driver_data<cinemat_state>();
190187   int gearval = input_port_read(space->machine, "GEAR");
191188
192189   /* check the fake gear input port and determine the bit settings for the gear */
193190   if ((gearval & 0x0f) != 0x0f)
194        gear = gearval & 0x0f;
191        state->gear = gearval & 0x0f;
195192
196   /* add the start key into the mix -- note that it overlaps 4th gear */
193   /* add the start key into the mix -- note that it overlaps 4th state->gear */
197194   if (!(input_port_read(space->machine, "INPUTS") & 0x80))
198        gear &= ~0x08;
195        state->gear &= ~0x08;
199196
200   return (gear >> offset) & 1;
197   return (state->gear >> offset) & 1;
201198}
202199
203200
r10427r10428
255252
256253static READ8_HANDLER( boxingb_dial_r )
257254{
255   cinemat_state *state = space->machine->driver_data<cinemat_state>();
258256   int value = input_port_read(space->machine, "DIAL");
259   if (!mux_select) offset += 4;
257   if (!state->mux_select) offset += 4;
260258   return (value >> offset) & 1;
261259}
262260
r10427r10428
319317ADDRESS_MAP_END
320318
321319static ADDRESS_MAP_START( data_map_qb3, ADDRESS_SPACE_DATA, 16 )
322   AM_RANGE(0x0000, 0x03ff) AM_RAMBANK("bank1") AM_BASE(&rambase)
320   AM_RANGE(0x0000, 0x03ff) AM_RAMBANK("bank1") AM_BASE_MEMBER(cinemat_state, rambase)
323321ADDRESS_MAP_END
324322
325323
r10427r10428
992990 *
993991 *************************************/
994992
995static MACHINE_CONFIG_START( cinemat_nojmi_4k, driver_device )
993static MACHINE_CONFIG_START( cinemat_nojmi_4k, cinemat_state )
996994
997995   /* basic machine hardware */
998996   MCFG_CPU_ADD("maincpu", CCPU, MASTER_CLOCK/4)
r10427r10428
14591457
14601458static DRIVER_INIT( speedfrk )
14611459{
1462   gear = 0xe;
1460   cinemat_state *state = machine->driver_data<cinemat_state>();
1461   state->gear = 0xe;
14631462   memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_IO), 0x00, 0x03, 0, 0, speedfrk_wheel_r);
14641463   memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_IO), 0x04, 0x06, 0, 0, speedfrk_gear_r);
14651464}
r10427r10428
14861485
14871486static DRIVER_INIT( qb3 )
14881487{
1488   cinemat_state *state = machine->driver_data<cinemat_state>();
14891489   memory_install_read8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_IO), 0x0f, 0x0f, 0, 0, qb3_frame_r);
14901490   memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_IO), 0x00, 0x00, 0, 0, qb3_ram_bank_w);
14911491
1492   memory_configure_bank(machine, "bank1", 0, 4, rambase, 0x100*2);
1492   memory_configure_bank(machine, "bank1", 0, 4, state->rambase, 0x100*2);
14931493}
14941494
14951495
src/mame/drivers/wecleman.c
r10427r10428
280280#include "wecleman.lh"
281281#include "includes/wecleman.h"
282282
283/* Variables only used here: */
284static UINT16 *blitter_regs;
285static int multiply_reg[2];
286static UINT16 *wecleman_protection_ram;
287static int spr_color_offs;
288283
289/* Variables that video has acces to: */
290int wecleman_selected_ip, wecleman_irqctrl;
291
292284/***************************************************************************
293285                            Common Routines
294286***************************************************************************/
295287
296288static READ16_HANDLER( wecleman_protection_r )
297289{
290   wecleman_state *state = space->machine->driver_data<wecleman_state>();
298291   int blend, data0, data1, r0, g0, b0, r1, g1, b1;
299292
300   data0 = wecleman_protection_ram[0];
301   blend = wecleman_protection_ram[2];
302   data1 = wecleman_protection_ram[1];
293   data0 = state->protection_ram[0];
294   blend = state->protection_ram[2];
295   data1 = state->protection_ram[1];
303296   blend &= 0x3ff;
304297
305298   // a precalculated table will take an astronomical 4096^2(colors) x 1024(steps) x 2(word) bytes
r10427r10428
321314
322315static WRITE16_HANDLER( wecleman_protection_w )
323316{
324   static int state = 0;
325
326   if (offset == 2) state = data & 0x2000;
327   if (!state) COMBINE_DATA(wecleman_protection_ram + offset);
317   wecleman_state *state = space->machine->driver_data<wecleman_state>();
318   if (offset == 2) state->prot_state = data & 0x2000;
319   if (!state->prot_state) COMBINE_DATA(state->protection_ram + offset);
328320}
329321
330322
r10427r10428
350342*/
351343static WRITE16_HANDLER( irqctrl_w )
352344{
345   wecleman_state *state = space->machine->driver_data<wecleman_state>();
353346   if (ACCESSING_BITS_0_7)
354347   {
355348      // logerror("CPU #0 - PC = %06X - $140005 <- %02X (old value: %02X)\n",cpu_get_pc(space->cpu), data&0xFF, old_data&0xFF);
356349
357350      // Bit 0 : SUBINT
358      if ( (wecleman_irqctrl & 1) && (!(data & 1)) )   // 1->0 transition
351      if ( (state->irqctrl & 1) && (!(data & 1)) )   // 1->0 transition
359352         cputag_set_input_line(space->machine, "sub", 4, HOLD_LINE);
360353
361354      // Bit 1 : NSUBRST
r10427r10428
369362      // Bit 4 : SCR-HCNT
370363      // Bit 5 : SCR-VCNT
371364      // Bit 6 : TV-KILL
372      wecleman_irqctrl = data;   // latch the value
365      state->irqctrl = data;   // latch the value
373366   }
374367}
375368
r10427r10428
386379*/
387380static WRITE16_HANDLER( selected_ip_w )
388381{
389   if (ACCESSING_BITS_0_7) wecleman_selected_ip = data & 0xff;   // latch the value
382   wecleman_state *state = space->machine->driver_data<wecleman_state>();
383   if (ACCESSING_BITS_0_7) state->selected_ip = data & 0xff;   // latch the value
390384}
391385
392386/* $140021.b - Return the previously selected input port's value */
393387static READ16_HANDLER( selected_ip_r )
394388{
395   switch ( (wecleman_selected_ip >> 5) & 3 )
389   wecleman_state *state = space->machine->driver_data<wecleman_state>();
390   switch ( (state->selected_ip >> 5) & 3 )
396391   {                                                   // From WEC Le Mans Schems:
397392      case 0:  return input_port_read(space->machine, "ACCEL");      // Accel - Schems: Accelevr
398393      case 1:  return ~0;                                    // ????? - Schems: Not Used
r10427r10428
439434*/
440435static WRITE16_HANDLER( blitter_w )
441436{
442   COMBINE_DATA(&blitter_regs[offset]);
437   wecleman_state *state = space->machine->driver_data<wecleman_state>();
438   COMBINE_DATA(&state->blitter_regs[offset]);
443439
444440   /* do a blit if $80010.b has been written */
445441   if ( (offset == 0x10/2) && (ACCESSING_BITS_8_15) )
446442   {
447443      /* 80000.b = ?? usually 0 - other values: 02 ; 00 - ? logic function ? */
448444      /* 80001.b = ?? usually 0 - other values: 3f ; 01 - ? height ? */
449      int minterm  = ( blitter_regs[0x0/2] & 0xFF00 ) >> 8;
450      int list_len = ( blitter_regs[0x0/2] & 0x00FF ) >> 0;
445      int minterm  = ( state->blitter_regs[0x0/2] & 0xFF00 ) >> 8;
446      int list_len = ( state->blitter_regs[0x0/2] & 0x00FF ) >> 0;
451447
452448      /* 80002.w = ?? always 0 - ? increment per horizontal line ? */
453449      /* no proof at all, it's always 0 */
454      //int srcdisp = blitter_regs[0x2/2] & 0xFF00;
455      //int destdisp = blitter_regs[0x2/2] & 0x00FF;
450      //int srcdisp = state->blitter_regs[0x2/2] & 0xFF00;
451      //int destdisp = state->blitter_regs[0x2/2] & 0x00FF;
456452
457453      /* 80004.l = source data address */
458      int src  = ( blitter_regs[0x4/2] << 16 ) + blitter_regs[0x6/2];
454      int src  = ( state->blitter_regs[0x4/2] << 16 ) + state->blitter_regs[0x6/2];
459455
460456      /* 80008.l = list of blits address */
461      int list = ( blitter_regs[0x8/2] << 16 ) + blitter_regs[0xA/2];
457      int list = ( state->blitter_regs[0x8/2] << 16 ) + state->blitter_regs[0xA/2];
462458
463459      /* 8000C.l = destination address */
464      int dest = ( blitter_regs[0xC/2] << 16 ) + blitter_regs[0xE/2];
460      int dest = ( state->blitter_regs[0xC/2] << 16 ) + state->blitter_regs[0xE/2];
465461
466462      /* 80010.b = number of words to move */
467      int size = ( blitter_regs[0x10/2] ) & 0x00FF;
463      int size = ( state->blitter_regs[0x10/2] ) & 0x00FF;
468464
469465      /* Word aligned transfers only ?? */
470466      src  &= (~1);   list &= (~1);    dest &= (~1);
r10427r10428
497493               space->write_word(destptr, space->read_word(i));
498494
499495            destptr = dest + 14;
500            i = space->read_word(list) + spr_color_offs;
496            i = space->read_word(list) + state->spr_color_offs;
501497            space->write_word(destptr, i);
502498
503499            dest += 16;
r10427r10428
519515
520516static ADDRESS_MAP_START( wecleman_map, ADDRESS_SPACE_PROGRAM, 16 )
521517   AM_RANGE(0x000000, 0x03ffff) AM_ROM   // ROM (03c000-03ffff used as RAM sometimes!)
522   AM_RANGE(0x040494, 0x040495) AM_WRITE(wecleman_videostatus_w) AM_BASE(&wecleman_videostatus)   // cloud blending control (HACK)
518   AM_RANGE(0x040494, 0x040495) AM_WRITE(wecleman_videostatus_w) AM_BASE_MEMBER(wecleman_state, videostatus)   // cloud blending control (HACK)
523519   AM_RANGE(0x040000, 0x043fff) AM_RAM   // RAM
524   AM_RANGE(0x060000, 0x060005) AM_WRITE(wecleman_protection_w) AM_BASE(&wecleman_protection_ram)
520   AM_RANGE(0x060000, 0x060005) AM_WRITE(wecleman_protection_w) AM_BASE_MEMBER(wecleman_state, protection_ram)
525521   AM_RANGE(0x060006, 0x060007) AM_READ(wecleman_protection_r)   // MCU read
526   AM_RANGE(0x080000, 0x080011) AM_RAM_WRITE(blitter_w) AM_BASE(&blitter_regs)   // Blitter
527   AM_RANGE(0x100000, 0x103fff) AM_RAM_WRITE(wecleman_pageram_w) AM_BASE(&wecleman_pageram)   // Background Layers
528   AM_RANGE(0x108000, 0x108fff) AM_RAM_WRITE(wecleman_txtram_w) AM_BASE(&wecleman_txtram)   // Text Layer
522   AM_RANGE(0x080000, 0x080011) AM_RAM_WRITE(blitter_w) AM_BASE_MEMBER(wecleman_state, blitter_regs)   // Blitter
523   AM_RANGE(0x100000, 0x103fff) AM_RAM_WRITE(wecleman_pageram_w) AM_BASE_MEMBER(wecleman_state, pageram)   // Background Layers
524   AM_RANGE(0x108000, 0x108fff) AM_RAM_WRITE(wecleman_txtram_w) AM_BASE_MEMBER(wecleman_state, txtram)   // Text Layer
529525   AM_RANGE(0x110000, 0x110fff) AM_RAM_WRITE(wecleman_paletteram16_SSSSBBBBGGGGRRRR_word_w) AM_BASE_GENERIC(paletteram)
530526   AM_RANGE(0x124000, 0x127fff) AM_RAM AM_SHARE("share1")   // Shared with main CPU
531527   AM_RANGE(0x130000, 0x130fff) AM_RAM AM_BASE_GENERIC(spriteram)   // Sprites
r10427r10428
552548static ADDRESS_MAP_START( hotchase_map, ADDRESS_SPACE_PROGRAM, 16 )
553549   AM_RANGE(0x000000, 0x03ffff) AM_ROM
554550   AM_RANGE(0x040000, 0x063fff) AM_RAM                              // RAM (weird size!?)
555   AM_RANGE(0x080000, 0x080011) AM_RAM_WRITE(blitter_w) AM_BASE(&blitter_regs)   // Blitter
551   AM_RANGE(0x080000, 0x080011) AM_RAM_WRITE(blitter_w) AM_BASE_MEMBER(wecleman_state, blitter_regs)   // Blitter
556552   AM_RANGE(0x100000, 0x100fff) AM_DEVREADWRITE8("k051316_1", k051316_r, k051316_w, 0x00ff)   // Background
557553   AM_RANGE(0x101000, 0x10101f) AM_DEVWRITE8("k051316_1", k051316_ctrl_w, 0x00ff)   // Background Ctrl
558554   AM_RANGE(0x102000, 0x102fff) AM_DEVREADWRITE8("k051316_2", k051316_r, k051316_w, 0x00ff)   // Foreground
r10427r10428
581577
582578static ADDRESS_MAP_START( wecleman_sub_map, ADDRESS_SPACE_PROGRAM, 16 )
583579   AM_RANGE(0x000000, 0x00ffff) AM_ROM   // ROM
584   AM_RANGE(0x060000, 0x060fff) AM_RAM AM_BASE(&wecleman_roadram) AM_SIZE(&wecleman_roadram_size)   // Road
580   AM_RANGE(0x060000, 0x060fff) AM_RAM AM_BASE_MEMBER(wecleman_state, roadram) AM_SIZE_MEMBER(wecleman_state, roadram_size)   // Road
585581   AM_RANGE(0x070000, 0x073fff) AM_RAM AM_SHARE("share1")   // RAM (Shared with main CPU)
586582ADDRESS_MAP_END
587583
r10427r10428
592588
593589static ADDRESS_MAP_START( hotchase_sub_map, ADDRESS_SPACE_PROGRAM, 16 )
594590   AM_RANGE(0x000000, 0x01ffff) AM_ROM   // ROM
595   AM_RANGE(0x020000, 0x020fff) AM_RAM AM_BASE(&wecleman_roadram) AM_SIZE(&wecleman_roadram_size)   // Road
591   AM_RANGE(0x020000, 0x020fff) AM_RAM AM_BASE_MEMBER(wecleman_state, roadram) AM_SIZE_MEMBER(wecleman_state, roadram_size)   // Road
596592   AM_RANGE(0x040000, 0x043fff) AM_RAM AM_SHARE("share1")   // Shared with main CPU
597593   AM_RANGE(0x060000, 0x060fff) AM_RAM            // RAM
598594ADDRESS_MAP_END
r10427r10428
615611/* Protection - an external multiplyer connected to the sound CPU */
616612static READ8_HANDLER( multiply_r )
617613{
618   return (multiply_reg[0] * multiply_reg[1]) & 0xFF;
614   wecleman_state *state = space->machine->driver_data<wecleman_state>();
615   return (state->multiply_reg[0] * state->multiply_reg[1]) & 0xFF;
619616}
620617
621618static WRITE8_HANDLER( multiply_w )
622619{
623   multiply_reg[offset] = data;
620   wecleman_state *state = space->machine->driver_data<wecleman_state>();
621   state->multiply_reg[offset] = data;
624622}
625623
626624/*      K007232 registers reminder:
r10427r10428
10331031   k007232_set_bank( machine->device("konami"), 0, 1 );
10341032}
10351033
1036static MACHINE_CONFIG_START( wecleman, driver_device )
1034static MACHINE_CONFIG_START( wecleman, wecleman_state )
10371035
10381036   /* basic machine hardware */
10391037   MCFG_CPU_ADD("maincpu", M68000, 10000000)   /* Schems show 10MHz */
r10427r10428
11041102   hotchase_zoom_callback_1
11051103};
11061104
1107static MACHINE_CONFIG_START( hotchase, driver_device )
1105static MACHINE_CONFIG_START( hotchase, wecleman_state )
11081106
11091107   /* basic machine hardware */
11101108   MCFG_CPU_ADD("maincpu", M68000, 10000000)   /* 10 MHz - PCB is drawn in one set's readme */
r10427r10428
12451243/* Unpack sprites data and do some patching */
12461244static DRIVER_INIT( wecleman )
12471245{
1246   wecleman_state *state = machine->driver_data<wecleman_state>();
12481247   int i, len;
12491248   UINT8 *RAM;
12501249//  UINT16 *RAM1 = (UINT16 *) machine->region("maincpu")->base();   /* Main CPU patches */
r10427r10428
12811280   bitswap(machine, machine->region("gfx3")->base(), machine->region("gfx3")->bytes(),
12821281         20,19,18,17,16,15,14,7,12,4,2,5,6,13,8,9,11,3,10,1,0);
12831282
1284   spr_color_offs = 0x40;
1283   state->spr_color_offs = 0x40;
12851284}
12861285
12871286
r10427r10428
13881387/* Unpack sprites data and do some patching */
13891388static DRIVER_INIT( hotchase )
13901389{
1390   wecleman_state *state = machine->driver_data<wecleman_state>();
13911391//  UINT16 *RAM1 = (UINT16) machine->region("maincpu")->base(); /* Main CPU patches */
13921392//  RAM[0x1140/2] = 0x0015; RAM[0x195c/2] = 0x601A; // faster self test
13931393
r10427r10428
14051405   RAM = machine->region("gfx3")->base();
14061406   memcpy(&RAM[0], &RAM[0x10000/2], 0x10000/2);
14071407
1408   spr_color_offs = 0;
1408   state->spr_color_offs = 0;
14091409}
14101410
14111411
src/mame/drivers/tp84.c
r10427r10428
7272#include "includes/konamipt.h"
7373#include "includes/tp84.h"
7474
75static cpu_device *audiocpu;
7675
7776
7877static MACHINE_START( tp84 )
7978{
80   audiocpu = machine->device<cpu_device>("audiocpu");
79   tp84_state *state = machine->driver_data<tp84_state>();
80   state->audiocpu = machine->device<cpu_device>("audiocpu");
8181}
8282
8383
8484static READ8_HANDLER( tp84_sh_timer_r )
8585{
86   tp84_state *state = space->machine->driver_data<tp84_state>();
8687   /* main xtal 14.318MHz, divided by 4 to get the CPU clock, further */
8788   /* divided by 2048 to get this timer */
8889   /* (divide by (2048/2), and not 1024, because the CPU cycle counter is */
8990   /* incremented every other state change of the clock) */
90   return (audiocpu->total_cycles() / (2048/2)) & 0x0f;
91   return (state->audiocpu->total_cycles() / (2048/2)) & 0x0f;
9192}
9293
9394
r10427r10428
127128
128129static ADDRESS_MAP_START( tp84_cpu1_map, ADDRESS_SPACE_PROGRAM, 8 )
129130   AM_RANGE(0x2000, 0x2000) AM_WRITE(watchdog_reset_w)
130   AM_RANGE(0x2800, 0x2800) AM_READ_PORT("SYSTEM") AM_WRITEONLY AM_BASE(&tp84_palette_bank)
131   AM_RANGE(0x2800, 0x2800) AM_READ_PORT("SYSTEM") AM_WRITEONLY AM_BASE_MEMBER(tp84_state, palette_bank)
131132   AM_RANGE(0x2820, 0x2820) AM_READ_PORT("P1")
132133   AM_RANGE(0x2840, 0x2840) AM_READ_PORT("P2")
133134   AM_RANGE(0x2860, 0x2860) AM_READ_PORT("DSW1")
134135   AM_RANGE(0x3000, 0x3000) AM_READ_PORT("DSW2") AM_WRITEONLY
135   AM_RANGE(0x3004, 0x3004) AM_WRITEONLY AM_BASE(&tp84_flipscreen_x)
136   AM_RANGE(0x3005, 0x3005) AM_WRITEONLY AM_BASE(&tp84_flipscreen_y)
136   AM_RANGE(0x3004, 0x3004) AM_WRITEONLY AM_BASE_MEMBER(tp84_state, flipscreen_x)
137   AM_RANGE(0x3005, 0x3005) AM_WRITEONLY AM_BASE_MEMBER(tp84_state, flipscreen_y)
137138   AM_RANGE(0x3800, 0x3800) AM_WRITE(tp84_sh_irqtrigger_w)
138139   AM_RANGE(0x3a00, 0x3a00) AM_WRITE(soundlatch_w)
139   AM_RANGE(0x3c00, 0x3c00) AM_WRITEONLY AM_BASE(&tp84_scroll_x)
140   AM_RANGE(0x3e00, 0x3e00) AM_WRITEONLY AM_BASE(&tp84_scroll_y)
141   AM_RANGE(0x4000, 0x43ff) AM_RAM AM_BASE(&tp84_bg_videoram)
142   AM_RANGE(0x4400, 0x47ff) AM_RAM AM_BASE(&tp84_fg_videoram)
143   AM_RANGE(0x4800, 0x4bff) AM_RAM AM_BASE(&tp84_bg_colorram)
144   AM_RANGE(0x4c00, 0x4fff) AM_RAM AM_BASE(&tp84_fg_colorram)
140   AM_RANGE(0x3c00, 0x3c00) AM_WRITEONLY AM_BASE_MEMBER(tp84_state, scroll_x)
141   AM_RANGE(0x3e00, 0x3e00) AM_WRITEONLY AM_BASE_MEMBER(tp84_state, scroll_y)
142   AM_RANGE(0x4000, 0x43ff) AM_RAM AM_BASE_MEMBER(tp84_state, bg_videoram)
143   AM_RANGE(0x4400, 0x47ff) AM_RAM AM_BASE_MEMBER(tp84_state, fg_videoram)
144   AM_RANGE(0x4800, 0x4bff) AM_RAM AM_BASE_MEMBER(tp84_state, bg_colorram)
145   AM_RANGE(0x4c00, 0x4fff) AM_RAM AM_BASE_MEMBER(tp84_state, fg_colorram)
145146   AM_RANGE(0x5000, 0x57ff) AM_RAM AM_SHARE("share1")
146147   AM_RANGE(0x8000, 0xffff) AM_ROM
147148ADDRESS_MAP_END
148149
149150static ADDRESS_MAP_START( tp84b_cpu1_map, ADDRESS_SPACE_PROGRAM, 8 )
150   AM_RANGE(0x0000, 0x03ff) AM_RAM AM_BASE(&tp84_bg_videoram)
151   AM_RANGE(0x0400, 0x07ff) AM_RAM AM_BASE(&tp84_fg_videoram)
152   AM_RANGE(0x0800, 0x0bff) AM_RAM AM_BASE(&tp84_bg_colorram)
153   AM_RANGE(0x0c00, 0x0fff) AM_RAM AM_BASE(&tp84_fg_colorram)
151   AM_RANGE(0x0000, 0x03ff) AM_RAM AM_BASE_MEMBER(tp84_state, bg_videoram)
152   AM_RANGE(0x0400, 0x07ff) AM_RAM AM_BASE_MEMBER(tp84_state, fg_videoram)
153   AM_RANGE(0x0800, 0x0bff) AM_RAM AM_BASE_MEMBER(tp84_state, bg_colorram)
154   AM_RANGE(0x0c00, 0x0fff) AM_RAM AM_BASE_MEMBER(tp84_state, fg_colorram)
154155   AM_RANGE(0x1000, 0x17ff) AM_RAM AM_SHARE("share1")
155156   AM_RANGE(0x1800, 0x1800) AM_WRITE(watchdog_reset_w)
156   AM_RANGE(0x1a00, 0x1a00) AM_READ_PORT("SYSTEM") AM_WRITEONLY AM_BASE(&tp84_palette_bank)
157   AM_RANGE(0x1a00, 0x1a00) AM_READ_PORT("SYSTEM") AM_WRITEONLY AM_BASE_MEMBER(tp84_state, palette_bank)
157158   AM_RANGE(0x1a20, 0x1a20) AM_READ_PORT("P1")
158159   AM_RANGE(0x1a40, 0x1a40) AM_READ_PORT("P2")
159160   AM_RANGE(0x1a60, 0x1a60) AM_READ_PORT("DSW1")
160161   AM_RANGE(0x1c00, 0x1c00) AM_READ_PORT("DSW2") AM_WRITENOP
161   AM_RANGE(0x1c04, 0x1c04) AM_WRITEONLY AM_BASE(&tp84_flipscreen_x)
162   AM_RANGE(0x1c05, 0x1c05) AM_WRITEONLY AM_BASE(&tp84_flipscreen_y)
162   AM_RANGE(0x1c04, 0x1c04) AM_WRITEONLY AM_BASE_MEMBER(tp84_state, flipscreen_x)
163   AM_RANGE(0x1c05, 0x1c05) AM_WRITEONLY AM_BASE_MEMBER(tp84_state, flipscreen_y)
163164   AM_RANGE(0x1e00, 0x1e00) AM_WRITE(tp84_sh_irqtrigger_w)
164165   AM_RANGE(0x1e80, 0x1e80) AM_WRITE(soundlatch_w)
165   AM_RANGE(0x1f00, 0x1f00) AM_WRITEONLY AM_BASE(&tp84_scroll_x)
166   AM_RANGE(0x1f80, 0x1f80) AM_WRITEONLY AM_BASE(&tp84_scroll_y)
166   AM_RANGE(0x1f00, 0x1f00) AM_WRITEONLY AM_BASE_MEMBER(tp84_state, scroll_x)
167   AM_RANGE(0x1f80, 0x1f80) AM_WRITEONLY AM_BASE_MEMBER(tp84_state, scroll_y)
167168   AM_RANGE(0x8000, 0xffff) AM_ROM
168169ADDRESS_MAP_END
169170
r10427r10428
173174   AM_RANGE(0x2000, 0x2000) AM_READ(tp84_scanline_r) /* beam position */
174175   AM_RANGE(0x4000, 0x4000) AM_WRITE(interrupt_enable_w)
175176   AM_RANGE(0x6000, 0x679f) AM_RAM
176   AM_RANGE(0x67a0, 0x67ff) AM_RAM_WRITE(tp84_spriteram_w) AM_BASE(&tp84_spriteram)
177   AM_RANGE(0x67a0, 0x67ff) AM_RAM_WRITE(tp84_spriteram_w) AM_BASE_MEMBER(tp84_state, spriteram)
177178   AM_RANGE(0x8000, 0x87ff) AM_RAM AM_SHARE("share1")
178179   AM_RANGE(0xe000, 0xffff) AM_ROM
179180ADDRESS_MAP_END
r10427r10428
274275
275276
276277
277static MACHINE_CONFIG_START( tp84, driver_device )
278static MACHINE_CONFIG_START( tp84, tp84_state )
278279
279280   /* basic machine hardware */
280281   MCFG_CPU_ADD("cpu1",M6809, XTAL_18_432MHz/12) /* verified on pcb */
src/mame/drivers/battlera.c
r10427r10428
2828#include "sound/c6280.h"
2929#include "includes/battlera.h"
3030
31static int control_port_select;
3231
3332/******************************************************************************/
3433
r10427r10428
4544
4645static WRITE8_HANDLER( control_data_w )
4746{
48   control_port_select=data;
47   battlera_state *state = space->machine->driver_data<battlera_state>();
48   state->control_port_select=data;
4949}
5050
5151static READ8_HANDLER( control_data_r )
5252{
53   switch (control_port_select)
53   battlera_state *state = space->machine->driver_data<battlera_state>();
54   switch (state->control_port_select)
5455   {
5556      case 0xfe: return input_port_read(space->machine, "IN0"); /* Player 1 */
5657      case 0xfd: return input_port_read(space->machine, "IN1"); /* Player 2 */
r10427r10428
8384
8485/******************************************************************************/
8586
86static int msm5205next;
8787
8888static void battlera_adpcm_int(device_t *device)
8989{
90   static int toggle;
90   battlera_state *state = device->machine->driver_data<battlera_state>();
9191
92   msm5205_data_w(device,msm5205next >> 4);
93   msm5205next <<= 4;
92   msm5205_data_w(device,state->msm5205next >> 4);
93   state->msm5205next <<= 4;
9494
95   toggle = 1 - toggle;
96   if (toggle)
95   state->toggle = 1 - state->toggle;
96   if (state->toggle)
9797      cputag_set_input_line(device->machine, "audiocpu", 1, HOLD_LINE);
9898}
9999
100100static WRITE8_HANDLER( battlera_adpcm_data_w )
101101{
102   msm5205next = data;
102   battlera_state *state = space->machine->driver_data<battlera_state>();
103   state->msm5205next = data;
103104}
104105
105106static WRITE8_DEVICE_HANDLER( battlera_adpcm_reset_w )
r10427r10428
229230   "audiocpu"
230231};
231232
232static MACHINE_CONFIG_START( battlera, driver_device )
233static MACHINE_CONFIG_START( battlera, battlera_state )
233234
234235   /* basic machine hardware */
235236   MCFG_CPU_ADD("maincpu", H6280,21477200/3)
src/mame/drivers/caswin.c
r10427r10428
4646#include "sound/ay8910.h"
4747#include "machine/nvram.h"
4848
49static UINT8 *sc0_vram,*sc0_attr;
50static tilemap_t *sc0_tilemap;
5149
50class caswin_state : public driver_device
51{
52public:
53   caswin_state(running_machine &machine, const driver_device_config_base &config)
54      : driver_device(machine, config) { }
55
56   UINT8 *sc0_vram;
57   UINT8 *sc0_attr;
58   tilemap_t *sc0_tilemap;
59};
60
61
62
5263static TILE_GET_INFO( get_sc0_tile_info )
5364{
54   int tile = (sc0_vram[tile_index] | ((sc0_attr[tile_index] & 0x70)<<4)) & 0x7ff;
55   int colour = sc0_attr[tile_index] & 0xf;
65   caswin_state *state = machine->driver_data<caswin_state>();
66   int tile = (state->sc0_vram[tile_index] | ((state->sc0_attr[tile_index] & 0x70)<<4)) & 0x7ff;
67   int colour = state->sc0_attr[tile_index] & 0xf;
5668
5769   SET_TILE_INFO(
5870         0,
r10427r10428
6375
6476static VIDEO_START(vvillage)
6577{
66   sc0_tilemap = tilemap_create(machine, get_sc0_tile_info,tilemap_scan_rows,8,8,32,32);
78   caswin_state *state = machine->driver_data<caswin_state>();
79   state->sc0_tilemap = tilemap_create(machine, get_sc0_tile_info,tilemap_scan_rows,8,8,32,32);
6780}
6881
6982static VIDEO_UPDATE(vvillage)
7083{
71   tilemap_draw(bitmap,cliprect,sc0_tilemap,0,0);
84   caswin_state *state = screen->machine->driver_data<caswin_state>();
85   tilemap_draw(bitmap,cliprect,state->sc0_tilemap,0,0);
7286   return 0;
7387}
7488
7589static WRITE8_HANDLER( sc0_vram_w )
7690{
77   sc0_vram[offset] = data;
78   tilemap_mark_tile_dirty(sc0_tilemap,offset);
91   caswin_state *state = space->machine->driver_data<caswin_state>();
92   state->sc0_vram[offset] = data;
93   tilemap_mark_tile_dirty(state->sc0_tilemap,offset);
7994}
8095
8196static WRITE8_HANDLER( sc0_attr_w )
8297{
83   sc0_attr[offset] = data;
84   tilemap_mark_tile_dirty(sc0_tilemap,offset);
98   caswin_state *state = space->machine->driver_data<caswin_state>();
99   state->sc0_attr[offset] = data;
100   tilemap_mark_tile_dirty(state->sc0_tilemap,offset);
85101}
86102
87103/*These two are tested during the two cherry sub-games.I really don't know what is supposed to do...*/
r10427r10428
137153   AM_RANGE(0x0000, 0x7fff) AM_ROM
138154   AM_RANGE(0xa000, 0xa000) AM_READ(vvillage_rng_r) //accessed by caswin only
139155   AM_RANGE(0xe000, 0xe7ff) AM_RAM AM_SHARE("nvram")
140   AM_RANGE(0xf000, 0xf3ff) AM_RAM_WRITE(sc0_vram_w) AM_BASE(&sc0_vram)
141   AM_RANGE(0xf800, 0xfbff) AM_RAM_WRITE(sc0_attr_w) AM_BASE(&sc0_attr)
156   AM_RANGE(0xf000, 0xf3ff) AM_RAM_WRITE(sc0_vram_w) AM_BASE_MEMBER(caswin_state, sc0_vram)
157   AM_RANGE(0xf800, 0xfbff) AM_RAM_WRITE(sc0_attr_w) AM_BASE_MEMBER(caswin_state, sc0_attr)
142158ADDRESS_MAP_END
143159
144160static ADDRESS_MAP_START( vvillage_io, ADDRESS_SPACE_IO, 8 )
r10427r10428
275291}
276292
277293
278static MACHINE_CONFIG_START( vvillage, driver_device )
294static MACHINE_CONFIG_START( vvillage, caswin_state )
279295   /* basic machine hardware */
280296   MCFG_CPU_ADD("maincpu", Z80,4000000)       /* ? MHz */
281297   MCFG_CPU_PROGRAM_MAP(vvillage_mem)
src/mame/drivers/koftball.c
r10427r10428
3434#include "sound/okim6295.h"
3535
3636
37static UINT16 *bmc_1_videoram, *bmc_2_videoram,*main_ram;
38static tilemap_t *tilemap_1,*tilemap_2;
39static UINT8 *bmc_colorram;
40static int clr_offset=0;
37class koftball_state : public driver_device
38{
39public:
40   koftball_state(running_machine &machine, const driver_device_config_base &config)
41      : driver_device(machine, config) { }
4142
43   UINT16 *bmc_1_videoram;
44   UINT16 *bmc_2_videoram;
45   UINT16 *main_ram;
46   tilemap_t *tilemap_1;
47   tilemap_t *tilemap_2;
48   UINT8 *bmc_colorram;
49   int clr_offset;
50   UINT16 prot_data;
51};
52
53
4254static TILE_GET_INFO( get_t1_tile_info )
4355{
44   int data = bmc_1_videoram[tile_index];
56   koftball_state *state = machine->driver_data<koftball_state>();
57   int data = state->bmc_1_videoram[tile_index];
4558   SET_TILE_INFO(
4659         0,
4760         data,
r10427r10428
5164
5265static TILE_GET_INFO( get_t2_tile_info )
5366{
54   int data = bmc_2_videoram[tile_index];
67   koftball_state *state = machine->driver_data<koftball_state>();
68   int data = state->bmc_2_videoram[tile_index];
5569   SET_TILE_INFO(
5670         0,
5771         data,
r10427r10428
6175
6276static VIDEO_START( koftball )
6377{
64   tilemap_1 = tilemap_create(machine, get_t1_tile_info,tilemap_scan_rows,8,8,64,32);
65   tilemap_2 = tilemap_create(machine, get_t2_tile_info,tilemap_scan_rows,8,8,64,32);
78   koftball_state *state = machine->driver_data<koftball_state>();
79   state->tilemap_1 = tilemap_create(machine, get_t1_tile_info,tilemap_scan_rows,8,8,64,32);
80   state->tilemap_2 = tilemap_create(machine, get_t2_tile_info,tilemap_scan_rows,8,8,64,32);
6681
67   tilemap_set_transparent_pen(tilemap_1,0);
82   tilemap_set_transparent_pen(state->tilemap_1,0);
6883}
6984
7085static VIDEO_UPDATE( koftball )
7186{
72   tilemap_draw( bitmap, cliprect, tilemap_2, 0, 0);
73   tilemap_draw( bitmap, cliprect, tilemap_1, 0, 0);
87   koftball_state *state = screen->machine->driver_data<koftball_state>();
88   tilemap_draw( bitmap, cliprect, state->tilemap_2, 0, 0);
89   tilemap_draw( bitmap, cliprect, state->tilemap_1, 0, 0);
7490   return 0;
7591}
7692
7793static WRITE16_HANDLER( bmc_RAMDAC_offset_w )
7894{
79   clr_offset=data*3;
95   koftball_state *state = space->machine->driver_data<koftball_state>();
96   state->clr_offset=data*3;
8097}
8198
8299static WRITE16_HANDLER( bmc_RAMDAC_color_w )
83100{
84   bmc_colorram[clr_offset]=data;
85   palette_set_color_rgb(space->machine,clr_offset/3,pal6bit(bmc_colorram[(clr_offset/3)*3]),pal6bit(bmc_colorram[(clr_offset/3)*3+1]),pal6bit(bmc_colorram[(clr_offset/3)*3+2]));
86   clr_offset=(clr_offset+1)%768;
101   koftball_state *state = space->machine->driver_data<koftball_state>();
102   state->bmc_colorram[state->clr_offset]=data;
103   palette_set_color_rgb(space->machine,state->clr_offset/3,pal6bit(state->bmc_colorram[(state->clr_offset/3)*3]),pal6bit(state->bmc_colorram[(state->clr_offset/3)*3+1]),pal6bit(state->bmc_colorram[(state->clr_offset/3)*3+2]));
104   state->clr_offset=(state->clr_offset+1)%768;
87105}
88106
89107static READ16_HANDLER( bmc_RAMDAC_color_r )
90108{
91   return bmc_colorram[clr_offset];
109   koftball_state *state = space->machine->driver_data<koftball_state>();
110   return state->bmc_colorram[state->clr_offset];
92111}
93112
94113static READ16_HANDLER(random_number_r)
r10427r10428
96115   return space->machine->rand();
97116}
98117
99static UINT16 prot_data;
100118
101119static READ16_HANDLER(prot_r)
102120{
103   switch(prot_data)
121   koftball_state *state = space->machine->driver_data<koftball_state>();
122   switch(state->prot_data)
104123   {
105124      case 0x0000: return 0x0d00;
106125      case 0xff00: return 0x8d00;
r10427r10428
108127      case 0x8000: return 0x0f0f;
109128   }
110129
111   logerror("unk prot r %x %x\n",prot_data,   cpu_get_previouspc(space->cpu));
130   logerror("unk prot r %x %x\n",state->prot_data,   cpu_get_previouspc(space->cpu));
112131   return space->machine->rand();
113132}
114133
115134static WRITE16_HANDLER(prot_w)
116135{
117   COMBINE_DATA(&prot_data);
136   koftball_state *state = space->machine->driver_data<koftball_state>();
137   COMBINE_DATA(&state->prot_data);
118138}
119139
120140static WRITE16_HANDLER(bmc_1_videoram_w)
121141{
122   COMBINE_DATA(&bmc_1_videoram[offset]);
123   tilemap_mark_tile_dirty(tilemap_1, offset);
142   koftball_state *state = space->machine->driver_data<koftball_state>();
143   COMBINE_DATA(&state->bmc_1_videoram[offset]);
144   tilemap_mark_tile_dirty(state->tilemap_1, offset);
124145}
125146
126147static WRITE16_HANDLER(bmc_2_videoram_w)
127148{
128   COMBINE_DATA(&bmc_2_videoram[offset]);
129   tilemap_mark_tile_dirty(tilemap_2, offset);
149   koftball_state *state = space->machine->driver_data<koftball_state>();
150   COMBINE_DATA(&state->bmc_2_videoram[offset]);
151   tilemap_mark_tile_dirty(state->tilemap_2, offset);
130152}
131153
132154static ADDRESS_MAP_START( koftball_mem, ADDRESS_SPACE_PROGRAM, 16 )
133155   AM_RANGE(0x000000, 0x01ffff) AM_ROM
134   AM_RANGE(0x220000, 0x22ffff) AM_RAM AM_BASE(&main_ram)
156   AM_RANGE(0x220000, 0x22ffff) AM_RAM AM_BASE_MEMBER(koftball_state, main_ram)
135157
136   AM_RANGE(0x260000, 0x260fff) AM_WRITE(bmc_1_videoram_w) AM_BASE(&bmc_1_videoram)
137   AM_RANGE(0x261000, 0x261fff) AM_WRITE(bmc_2_videoram_w) AM_BASE(&bmc_2_videoram)
158   AM_RANGE(0x260000, 0x260fff) AM_WRITE(bmc_1_videoram_w) AM_BASE_MEMBER(koftball_state, bmc_1_videoram)
159   AM_RANGE(0x261000, 0x261fff) AM_WRITE(bmc_2_videoram_w) AM_BASE_MEMBER(koftball_state, bmc_2_videoram)
138160   AM_RANGE(0x262000, 0x26ffff) AM_RAM
139161
140162   AM_RANGE(0x280000, 0x28ffff) AM_RAM /* unused ? */
r10427r10428
202224GFXDECODE_END
203225
204226
205static MACHINE_CONFIG_START( koftball, driver_device )
227static MACHINE_CONFIG_START( koftball, koftball_state )
206228   MCFG_CPU_ADD("maincpu", M68000, 21477270/2 )
207229   MCFG_CPU_PROGRAM_MAP(koftball_mem)
208230   MCFG_CPU_VBLANK_INT_HACK(bmc_interrupt,3)
r10427r10428
271293#endif
272294static DRIVER_INIT(koftball)
273295{
274   bmc_colorram = auto_alloc_array(machine, UINT8, 768);
296   koftball_state *state = machine->driver_data<koftball_state>();
297   state->bmc_colorram = auto_alloc_array(machine, UINT8, 768);
275298
276299#if NVRAM_HACK
277300   {
278301      int offset=0;
279302      while(nvram[offset]!=0xffff)
280303      {
281         main_ram[offset]=nvram[offset];
304         state->main_ram[offset]=nvram[offset];
282305         ++offset;
283306      }
284307   }
src/mame/drivers/deshoros.c
r10427r10428
1515#include "emu.h"
1616#include "cpu/m6809/m6809.h"
1717
18static UINT8 *io_ram;
18
19class deshoros_state : public driver_device
20{
21public:
22   deshoros_state(running_machine &machine, const driver_device_config_base &config)
23      : driver_device(machine, config) { }
24
25   UINT8 *io_ram;
26   char led_array[21];
27   UINT8 bank;
28};
29
30
1931/*Temporary,to show something on screen...*/
20static char led_array[21];
2132
2233static VIDEO_START( deshoros )
2334{
24   static UINT8 i;
35   deshoros_state *state = machine->driver_data<deshoros_state>();
36   UINT8 i;
2537   for(i=0;i<20;i++)
26      led_array[i] = 0x20;
27   led_array[20] = 0;
38      state->led_array[i] = 0x20;
39   state->led_array[20] = 0;
2840}
2941
3042static VIDEO_UPDATE( deshoros )
3143{
32   popmessage("%s",led_array);
44   deshoros_state *state = screen->machine->driver_data<deshoros_state>();
45   popmessage("%s",state->led_array);
3346   return 0;
3447}
3548
3649/*I don't know it this is 100% correct,might be different...*/
37static void update_led_array(UINT8 new_data)
50static void update_led_array(deshoros_state *state, UINT8 new_data)
3851{
39   static UINT8 i;
52   UINT8 i;
4053   /*scroll the data*/
4154   for(i=0;i<19;i++)
42      led_array[i] = led_array[i+1];
55      state->led_array[i] = state->led_array[i+1];
4356   /*update the data*/
44   led_array[19] = new_data;
57   state->led_array[19] = new_data;
4558}
4659
47static UINT8 bank;
4860
4961static void answer_bankswitch(running_machine *machine,UINT8 new_bank)
5062{
51   if(bank!=new_bank)
63   deshoros_state *state = machine->driver_data<deshoros_state>();
64   if(state->bank!=new_bank)
5265   {
5366      UINT8 *ROM = machine->region("data")->base();
5467      UINT32 bankaddress;
5568
56      bank = new_bank;
57      bankaddress = 0 + 0x6000 * bank;
69      state->bank = new_bank;
70      bankaddress = 0 + 0x6000 * state->bank;
5871      memory_set_bankptr(machine, "bank1", &ROM[bankaddress]);
5972   }
6073}
6174
6275static READ8_HANDLER( io_r )
6376{
77   deshoros_state *state = space->machine->driver_data<deshoros_state>();
6478   switch(offset)
6579   {
6680      case 0x00: return 0xff; //printer read
6781      case 0x03: return input_port_read(space->machine, "KEY0" );
6882      case 0x04: return input_port_read(space->machine, "KEY1" );
6983      case 0x05: return input_port_read(space->machine, "SYSTEM" );
70      case 0x0a: return io_ram[offset]; //"buzzer" 0 read
71      case 0x0b: return io_ram[offset]; //"buzzer" 1 read
84      case 0x0a: return state->io_ram[offset]; //"buzzer" 0 read
85      case 0x0b: return state->io_ram[offset]; //"buzzer" 1 read
7286   }
7387//  printf("R -> [%02x]\n",offset);
7488
75   return io_ram[offset];
89   return state->io_ram[offset];
7690}
7791
7892static WRITE8_HANDLER( io_w )
7993{
94   deshoros_state *state = space->machine->driver_data<deshoros_state>();
8095   switch(offset)
8196   {
8297      case 0x00: /*Printer data*/                  return;
83      case 0x02: update_led_array(data);              return;
84      case 0x05: coin_lockout_w(space->machine, 0,io_ram[offset] & 1);return;
98      case 0x02: update_led_array(state, data);              return;
99      case 0x05: coin_lockout_w(space->machine, 0,state->io_ram[offset] & 1);return;
85100      case 0x06: /*Printer IRQ enable*/             return;
86101//      case 0x0a: "buzzer" 0 write
87102//      case 0x0b: "buzzer" 1 write
88103      case 0x0c: answer_bankswitch(space->machine,data&0x03); return; //data & 0x10 enabled too,dunno if it is worth to shift the data...
89104   }
90   io_ram[offset] = data;
105   state->io_ram[offset] = data;
91106//  printf("%02x -> [%02x]\n",data,offset);
92107}
93108
94109static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 8 )
95110   AM_RANGE(0x0000, 0x5fff) AM_ROMBANK("bank1")
96111   AM_RANGE(0x8000, 0x87ff) AM_RAM
97   AM_RANGE(0x9000, 0x900f) AM_READWRITE(io_r,io_w) AM_BASE(&io_ram) //i/o area
112   AM_RANGE(0x9000, 0x900f) AM_READWRITE(io_r,io_w) AM_BASE_MEMBER(deshoros_state, io_ram) //i/o area
98113   AM_RANGE(0xc000, 0xffff) AM_ROM
99114ADDRESS_MAP_END
100115
r10427r10428
151166
152167static MACHINE_RESET( deshoros )
153168{
154   bank = -1;
169   deshoros_state *state = machine->driver_data<deshoros_state>();
170   state->bank = -1;
155171}
156172
157static MACHINE_CONFIG_START( deshoros, driver_device )
173static MACHINE_CONFIG_START( deshoros, deshoros_state )
158174
159175   /* basic machine hardware */
160176   MCFG_CPU_ADD("maincpu",M6809,2000000)
src/mame/drivers/rmhaihai.c
r10427r10428
3333#include "sound/ay8910.h"
3434#include "sound/msm5205.h"
3535
36static int gfxbank;
37static UINT8 *videoram;
38static UINT8 *colorram;
39static tilemap_t *bg_tilemap;
4036
37class rmhaihai_state : public driver_device
38{
39public:
40   rmhaihai_state(running_machine &machine, const driver_device_config_base &config)
41      : driver_device(machine, config) { }
42
43   int gfxbank;
44   UINT8 *videoram;
45   UINT8 *colorram;
46   tilemap_t *bg_tilemap;
47   int keyboard_cmd;
48};
49
50
51
4152static WRITE8_HANDLER( rmhaihai_videoram_w )
4253{
43   videoram[offset] = data;
44   tilemap_mark_tile_dirty(bg_tilemap, offset);
54   rmhaihai_state *state = space->machine->driver_data<rmhaihai_state>();
55   state->videoram[offset] = data;
56   tilemap_mark_tile_dirty(state->bg_tilemap, offset);
4557}
4658
4759static WRITE8_HANDLER( rmhaihai_colorram_w )
4860{
49   colorram[offset] = data;
50   tilemap_mark_tile_dirty(bg_tilemap, offset);
61   rmhaihai_state *state = space->machine->driver_data<rmhaihai_state>();
62   state->colorram[offset] = data;
63   tilemap_mark_tile_dirty(state->bg_tilemap, offset);
5164}
5265
5366static TILE_GET_INFO( get_bg_tile_info )
5467{
55   int attr = colorram[tile_index];
56   int code = videoram[tile_index] + (gfxbank << 12) + ((attr & 0x07) << 8) + ((attr & 0x80) << 4);
57   int color = (gfxbank << 5) + (attr >> 3);
68   rmhaihai_state *state = machine->driver_data<rmhaihai_state>();
69   int attr = state->colorram[tile_index];
70   int code = state->videoram[tile_index] + (state->gfxbank << 12) + ((attr & 0x07) << 8) + ((attr & 0x80) << 4);
71   int color = (state->gfxbank << 5) + (attr >> 3);
5872
5973   SET_TILE_INFO(0, code, color, 0);
6074}
6175
6276static VIDEO_START( rmhaihai )
6377{
64   bg_tilemap = tilemap_create(machine, get_bg_tile_info, tilemap_scan_rows,
78   rmhaihai_state *state = machine->driver_data<rmhaihai_state>();
79   state->bg_tilemap = tilemap_create(machine, get_bg_tile_info, tilemap_scan_rows,
6580      8, 8, 64, 32);
6681}
6782
6883static VIDEO_UPDATE( rmhaihai )
6984{
70   tilemap_draw(bitmap, cliprect, bg_tilemap, 0, 0);
85   rmhaihai_state *state = screen->machine->driver_data<rmhaihai_state>();
86   tilemap_draw(bitmap, cliprect, state->bg_tilemap, 0, 0);
7187   return 0;
7288}
7389
7490
7591
76static int keyboard_cmd;
7792
7893static READ8_HANDLER( keyboard_r )
7994{
95   rmhaihai_state *state = space->machine->driver_data<rmhaihai_state>();
8096   static const char *const keynames[] = { "KEY0", "KEY1" };
8197
8298   logerror("%04x: keyboard_r\n",cpu_get_pc(space->cpu));
r10427r10428
100116      case 0x5c7b:   // rmhaihai, rmhaisei, rmhaijin
101117      case 0x5950:   // rmhaihib
102118      case 0x5bf3:   // themj, but the test is NOPed out!
103         return 0xcc;   /* keyboard_cmd = 0xcb */
119         return 0xcc;   /* state->keyboard_cmd = 0xcb */
104120
105121
106122      case 0x13a:   // additional checks done by rmhaijin
107         if (keyboard_cmd == 0x3b) return 0xdd;
108         if (keyboard_cmd == 0x85) return 0xdc;
109         if (keyboard_cmd == 0xf2) return 0xd6;
110         if (keyboard_cmd == 0xc1) return 0x8f;
111         if (keyboard_cmd == 0xd0) return 0x08;
123         if (state->keyboard_cmd == 0x3b) return 0xdd;
124         if (state->keyboard_cmd == 0x85) return 0xdc;
125         if (state->keyboard_cmd == 0xf2) return 0xd6;
126         if (state->keyboard_cmd == 0xc1) return 0x8f;
127         if (state->keyboard_cmd == 0xd0) return 0x08;
112128         return 0;
113129
114130      case 0x140:   // additional checks done by rmhaisei
115131      case 0x155:   // additional checks done by themj, but they are patched out!
116         if (keyboard_cmd == 0x11) return 0x57;
117         if (keyboard_cmd == 0x3e) return 0xda;
118         if (keyboard_cmd == 0x48) return 0x74;
119         if (keyboard_cmd == 0x5d) return 0x46;
120         if (keyboard_cmd == 0xd0) return 0x08;
132         if (state->keyboard_cmd == 0x11) return 0x57;
133         if (state->keyboard_cmd == 0x3e) return 0xda;
134         if (state->keyboard_cmd == 0x48) return 0x74;
135         if (state->keyboard_cmd == 0x5d) return 0x46;
136         if (state->keyboard_cmd == 0xd0) return 0x08;
121137         return 0;
122138   }
123139
r10427r10428
127143
128144static WRITE8_HANDLER( keyboard_w )
129145{
146   rmhaihai_state *state = space->machine->driver_data<rmhaihai_state>();
130147logerror("%04x: keyboard_w %02x\n",cpu_get_pc(space->cpu),data);
131   keyboard_cmd = data;
148   state->keyboard_cmd = data;
132149}
133150
134151static READ8_HANDLER( samples_r )
r10427r10428
145162
146163static WRITE8_HANDLER( ctrl_w )
147164{
165   rmhaihai_state *state = space->machine->driver_data<rmhaihai_state>();
148166   flip_screen_set(space->machine, data & 0x01);
149167
150168   // (data & 0x02) is switched on and off in service mode
r10427r10428
154172
155173   // (data & 0x10) is medal in service mode
156174
157   gfxbank = (data & 0x40) >> 6;   /* rmhaisei only */
175   state->gfxbank = (data & 0x40) >> 6;   /* rmhaisei only */
158176}
159177
160178static WRITE8_HANDLER( themj_rombank_w )
r10427r10428
176194static ADDRESS_MAP_START( rmhaihai_map, ADDRESS_SPACE_PROGRAM, 8 )
177195   AM_RANGE(0x0000, 0x9fff) AM_ROM
178196   AM_RANGE(0xa000, 0xa7ff) AM_RAM
179   AM_RANGE(0xa800, 0xafff) AM_RAM_WRITE(rmhaihai_colorram_w) AM_BASE(&colorram)
180   AM_RANGE(0xb000, 0xb7ff) AM_RAM_WRITE(rmhaihai_videoram_w) AM_BASE(&videoram)
197   AM_RANGE(0xa800, 0xafff) AM_RAM_WRITE(rmhaihai_colorram_w) AM_BASE_MEMBER(rmhaihai_state, colorram)
198   AM_RANGE(0xb000, 0xb7ff) AM_RAM_WRITE(rmhaihai_videoram_w) AM_BASE_MEMBER(rmhaihai_state, videoram)
181199   AM_RANGE(0xb83c, 0xb83c) AM_WRITENOP   // ??
182200   AM_RANGE(0xbc00, 0xbc00) AM_WRITENOP   // ??
183201   AM_RANGE(0xc000, 0xdfff) AM_ROM
r10427r10428
201219   AM_RANGE(0x0000, 0x7fff) AM_ROM
202220   AM_RANGE(0x8000, 0x9fff) AM_ROMBANK("bank1")
203221   AM_RANGE(0xa000, 0xa7ff) AM_RAM
204   AM_RANGE(0xa800, 0xafff) AM_RAM_WRITE(rmhaihai_colorram_w) AM_BASE(&colorram)
205   AM_RANGE(0xb000, 0xb7ff) AM_RAM_WRITE(rmhaihai_videoram_w) AM_BASE(&videoram)
222   AM_RANGE(0xa800, 0xafff) AM_RAM_WRITE(rmhaihai_colorram_w) AM_BASE_MEMBER(rmhaihai_state, colorram)
223   AM_RANGE(0xb000, 0xb7ff) AM_RAM_WRITE(rmhaihai_videoram_w) AM_BASE_MEMBER(rmhaihai_state, videoram)
206224   AM_RANGE(0xc000, 0xdfff) AM_ROMBANK("bank2")
207225   AM_RANGE(0xe000, 0xffff) AM_ROM
208226ADDRESS_MAP_END
r10427r10428
437455
438456
439457
440static MACHINE_CONFIG_START( rmhaihai, driver_device )
458static MACHINE_CONFIG_START( rmhaihai, rmhaihai_state )
441459
442460   /* basic machine hardware */
443461   MCFG_CPU_ADD("maincpu",Z80,20000000/4)   /* 5 MHz ??? */
src/mame/drivers/atarig1.c
r10427r10428
7070static WRITE16_HANDLER( mo_control_w )
7171{
7272   if (ACCESSING_BITS_0_7)
73      atarirle_control_w(space->machine, 0, data & 7);
73   {
74      atarig1_state *state = space->machine->driver_data<atarig1_state>();
75      atarirle_control_w(state->rle, data & 7);
76   }
7477}
7578
7679
r10427r10428
7881{
7982   atarig1_state *state = space->machine->driver_data<atarig1_state>();
8083   COMBINE_DATA(state->mo_command);
81   atarirle_command_w(0, (data == 0 && state->is_pitfight) ? ATARIRLE_COMMAND_CHECKSUM : ATARIRLE_COMMAND_DRAW);
84   atarirle_command_w(state->rle, (data == 0 && state->is_pitfight) ? ATARIRLE_COMMAND_CHECKSUM : ATARIRLE_COMMAND_DRAW);
8285}
8386
8487
r10427r10428
224227   AM_RANGE(0xfd8000, 0xfdffff) AM_READWRITE(atarigen_eeprom_r, atarigen_eeprom_w) AM_SHARE("eeprom")
225228/*  AM_RANGE(0xfe0000, 0xfe7fff) AM_READ(from_r)*/
226229   AM_RANGE(0xfe8000, 0xfe89ff) AM_RAM_WRITE(atarigen_666_paletteram_w) AM_BASE_GENERIC(paletteram)
227   AM_RANGE(0xff0000, 0xff0fff) AM_WRITE(atarirle_0_spriteram_w) AM_BASE(&atarirle_0_spriteram)
230   AM_RANGE(0xff0000, 0xff0fff) AM_DEVREADWRITE("rle", atarirle_spriteram_r, atarirle_spriteram_w)
228231   AM_RANGE(0xff2000, 0xff2001) AM_WRITE(mo_command_w) AM_BASE_MEMBER(atarig1_state, mo_command)
229232   AM_RANGE(0xff4000, 0xff5fff) AM_WRITE(atarigen_playfield_w) AM_BASE_MEMBER(atarig1_state, playfield)
230233   AM_RANGE(0xff6000, 0xff6fff) AM_WRITE(atarigen_alpha_w) AM_BASE_MEMBER(atarig1_state, alpha)
r10427r10428
401404
402405
403406
407static const atarirle_desc modesc_hydra =
408{
409   "gfx3",      /* region where the GFX data lives */
410   256,      /* number of entries in sprite RAM */
411   0,         /* left clip coordinate */
412   255,      /* right clip coordinate */
413
414   0x200,      /* base palette entry */
415   0x100,      /* maximum number of colors */
416
417   {{ 0x7fff,0,0,0,0,0,0,0 }},   /* mask for the code index */
418   {{ 0,0x00f0,0,0,0,0,0,0 }},   /* mask for the color */
419   {{ 0,0,0xffc0,0,0,0,0,0 }},   /* mask for the X position */
420   {{ 0,0,0,0xffc0,0,0,0,0 }},   /* mask for the Y position */
421   {{ 0,0,0,0,0xffff,0,0,0 }},   /* mask for the scale factor */
422   {{ 0x8000,0,0,0,0,0,0,0 }},   /* mask for the horizontal flip */
423   {{ 0,0,0,0,0,0x00ff,0,0 }},   /* mask for the order */
424   {{ 0 }},               /* mask for the priority */
425   {{ 0 }}                  /* mask for the VRAM target */
426};
427
428static const atarirle_desc modesc_pitfight =
429{
430   "gfx3",      /* region where the GFX data lives */
431   256,      /* number of entries in sprite RAM */
432   40,         /* left clip coordinate */
433   295,      /* right clip coordinate */
434
435   0x200,      /* base palette entry */
436   0x100,      /* maximum number of colors */
437
438   {{ 0x7fff,0,0,0,0,0,0,0 }},   /* mask for the code index */
439   {{ 0,0x00f0,0,0,0,0,0,0 }},   /* mask for the color */
440   {{ 0,0,0xffc0,0,0,0,0,0 }},   /* mask for the X position */
441   {{ 0,0,0,0xffc0,0,0,0,0 }},   /* mask for the Y position */
442   {{ 0,0,0,0,0xffff,0,0,0 }},   /* mask for the scale factor */
443   {{ 0x8000,0,0,0,0,0,0,0 }},   /* mask for the horizontal flip */
444   {{ 0,0,0,0,0,0,0x00ff,0 }},   /* mask for the order */
445   {{ 0 }},               /* mask for the priority */
446   {{ 0 }}                  /* mask for the VRAM target */
447};
448
404449/*************************************
405450 *
406451 *  Machine driver
r10427r10428
429474   MCFG_SCREEN_RAW_PARAMS(ATARI_CLOCK_14MHz/2, 456, 0, 336, 262, 0, 240)
430475
431476   MCFG_VIDEO_START(atarig1)
432   MCFG_VIDEO_EOF(atarirle)
477   MCFG_VIDEO_EOF(atarig1)
433478   MCFG_VIDEO_UPDATE(atarig1)
434479
435480   /* sound hardware */
436481   MCFG_FRAGMENT_ADD(jsa_ii_mono)
437482MACHINE_CONFIG_END
438483
484static MACHINE_CONFIG_DERIVED( hydra, atarig1 )
485   MCFG_ATARIRLE_ADD( "rle", modesc_hydra )
486MACHINE_CONFIG_END
439487
488static MACHINE_CONFIG_DERIVED( pitfight, atarig1 )
489   MCFG_ATARIRLE_ADD( "rle", modesc_pitfight )
490MACHINE_CONFIG_END
440491
492
441493/*************************************
442494 *
443495 *  ROM definition(s)
r10427r10428
12011253 *
12021254 *************************************/
12031255
1204GAME( 1990, hydra,    0,        atarig1, hydra,    hydra,    ROT0, "Atari Games", "Hydra", GAME_SUPPORTS_SAVE )
1205GAME( 1990, hydrap,   hydra,    atarig1, hydra,    hydrap,   ROT0, "Atari Games", "Hydra (prototype 5/14/90)", GAME_SUPPORTS_SAVE )
1206GAME( 1990, hydrap2,  hydra,    atarig1, hydra,    hydrap,   ROT0, "Atari Games", "Hydra (prototype 5/25/90)", GAME_SUPPORTS_SAVE )
1256GAME( 1990, hydra,    0,        hydra, hydra,    hydra,    ROT0, "Atari Games", "Hydra", GAME_SUPPORTS_SAVE )
1257GAME( 1990, hydrap,   hydra,    hydra, hydra,    hydrap,   ROT0, "Atari Games", "Hydra (prototype 5/14/90)", GAME_SUPPORTS_SAVE )
1258GAME( 1990, hydrap2,  hydra,    hydra, hydra,    hydrap,   ROT0, "Atari Games", "Hydra (prototype 5/25/90)", GAME_SUPPORTS_SAVE )
12071259
1208GAME( 1990, pitfight,  0,        atarig1, pitfight, pitfight9, ROT0, "Atari Games", "Pit Fighter (rev 9)", GAME_SUPPORTS_SAVE )
1209GAME( 1990, pitfight7, pitfight, atarig1, pitfight, pitfight7, ROT0, "Atari Games", "Pit Fighter (rev 7)", GAME_SUPPORTS_SAVE )
1210GAME( 1990, pitfight6, pitfight, atarig1, pitfight, pitfightj, ROT0, "Atari Games", "Pit Fighter (rev 6)", GAME_SUPPORTS_SAVE )
1211GAME( 1990, pitfight5, pitfight, atarig1, pitfight, pitfight7, ROT0, "Atari Games", "Pit Fighter (rev 5)", GAME_SUPPORTS_SAVE )
1212GAME( 1990, pitfight4, pitfight, atarig1, pitfight, pitfight,  ROT0, "Atari Games", "Pit Fighter (rev 4)", GAME_SUPPORTS_SAVE )
1213GAME( 1990, pitfight3, pitfight, atarig1, pitfight, pitfight,  ROT0, "Atari Games", "Pit Fighter (rev 3)", GAME_SUPPORTS_SAVE )
1214GAME( 1990, pitfightj, pitfight, atarig1, pitfightj,pitfightj, ROT0, "Atari Games", "Pit Fighter (Japan, 2 players)", GAME_SUPPORTS_SAVE )
1215GAME( 1990, pitfightb, pitfight, atarig1, pitfight, pitfightb, ROT0, "bootleg",     "Pit Fighter (bootleg)", GAME_SUPPORTS_SAVE )
1260GAME( 1990, pitfight,  0,        pitfight, pitfight, pitfight9, ROT0, "Atari Games", "Pit Fighter (rev 9)", GAME_SUPPORTS_SAVE )
1261GAME( 1990, pitfight7, pitfight, pitfight, pitfight, pitfight7, ROT0, "Atari Games", "Pit Fighter (rev 7)", GAME_SUPPORTS_SAVE )
1262GAME( 1990, pitfight6, pitfight, pitfight, pitfight, pitfightj, ROT0, "Atari Games", "Pit Fighter (rev 6)", GAME_SUPPORTS_SAVE )
1263GAME( 1990, pitfight5, pitfight, pitfight, pitfight, pitfight7, ROT0, "Atari Games", "Pit Fighter (rev 5)", GAME_SUPPORTS_SAVE )
1264GAME( 1990, pitfight4, pitfight, pitfight, pitfight, pitfight,  ROT0, "Atari Games", "Pit Fighter (rev 4)", GAME_SUPPORTS_SAVE )
1265GAME( 1990, pitfight3, pitfight, pitfight, pitfight, pitfight,  ROT0, "Atari Games", "Pit Fighter (rev 3)", GAME_SUPPORTS_SAVE )
1266GAME( 1990, pitfightj, pitfight, pitfight, pitfightj,pitfightj, ROT0, "Atari Games", "Pit Fighter (Japan, 2 players)", GAME_SUPPORTS_SAVE )
1267GAME( 1990, pitfightb, pitfight, pitfight, pitfight, pitfightb, ROT0, "bootleg",     "Pit Fighter (bootleg)", GAME_SUPPORTS_SAVE )
src/mame/drivers/aristmk4.c
r10427r10428
107107#include "machine/nvram.h"
108108
109109
110int rtc_address_strobe = 0;
111int rtc_data_strobe = 0;
110class aristmk4_state : public driver_device
111{
112public:
113   aristmk4_state(running_machine &machine, const driver_device_config_base &config)
114      : driver_device(machine, config) { }
112115
113device_t *samples;
114UINT8 *shapeRomPtr;     // pointer to tile_gfx shape roms
115UINT8 shapeRom[0xc000]; // shaperom restore array.
116   int rtc_address_strobe;
117   int rtc_data_strobe;
118   device_t *samples;
119   UINT8 *shapeRomPtr;
120   UINT8 shapeRom[0xc000];
121   UINT8 *mkiv_vram;
122   UINT8 *nvram;
123   UINT8 psg_data;
124   int ay8910_1;
125   int ay8910_2;
126   int u3_p0_w;
127   UINT8 cgdrsw;
128   UINT8 ripple;
129   int hopper_motor;
130   int inscrd;
131   int cashcade_c;
132};
116133
117static UINT8 *mkiv_vram;
118static UINT8 *nvram;    // backup
119static UINT8 psg_data;
120static int ay8910_1;
121static int ay8910_2;
122static int u3_p0_w;
123static UINT8 cgdrsw;
124static UINT8 ripple;
125static int hopper_motor;
126static int inscrd;
127134
135
136
137
138
128139/* Partial Caschcade protocol */
129static int cashcade_p[] ={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0};
130static int cashcade_c = 0;
140static const UINT8 cashcade_p[] ={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0};
131141
132142static VIDEO_START(aristmk4)
133143{
r10427r10428
140150
141151INLINE void uBackgroundColour(running_machine *machine)
142152{
153   aristmk4_state *state = machine->driver_data<aristmk4_state>();
143154    /* SW7 can be set when the main door is open, this allows the colours for the background
144155        to be adjusted whilst the machine is running.
145156
r10427r10428
150161   {
151162        case 0x00:
152163             // restore defaults
153             memcpy(shapeRomPtr,shapeRom, sizeof(shapeRom)); // restore defaults, both switches off
164             memcpy(state->shapeRomPtr,state->shapeRom, sizeof(state->shapeRom)); // restore defaults, both switches off
154165                                                             // OE enabled on both shapes
155166             break;
156167        case 0x01:
157168             // unselect U22 via SW7 . OE on U22 is low.
158             memset(&shapeRomPtr[0x4000],0xff,0x2000);               // fill unused space with 0xff
159             memcpy(&shapeRomPtr[0xa000],&shapeRom[0xa000], 0x2000); // restore defaults here
169             memset(&state->shapeRomPtr[0x4000],0xff,0x2000);               // fill unused space with 0xff
170             memcpy(&state->shapeRomPtr[0xa000],&state->shapeRom[0xa000], 0x2000); // restore defaults here
160171             break;
161172        case 0x02:
162173             // unselect U47 via SW7 . OE on U47 is low.
163             memcpy(&shapeRomPtr[0x4000],&shapeRom[0x4000], 0x2000);
164             memset(&shapeRomPtr[0xa000],0xff,0x2000);
174             memcpy(&state->shapeRomPtr[0x4000],&state->shapeRom[0x4000], 0x2000);
175             memset(&state->shapeRomPtr[0xa000],0xff,0x2000);
165176             break;
166177        case 0x03:
167178             // unselect U47 & u22 via SW7. both output enable low.
168             memset(&shapeRomPtr[0x4000],0xff,0x2000);
169             memset(&shapeRomPtr[0xa000],0xff,0x2000);
179             memset(&state->shapeRomPtr[0x4000],0xff,0x2000);
180             memset(&state->shapeRomPtr[0xa000],0xff,0x2000);
170181             break;
171182    }
172183}
173184
174185static VIDEO_UPDATE(aristmk4)
175186{
187   aristmk4_state *state = screen->machine->driver_data<aristmk4_state>();
176188   const gfx_element *gfx = screen->machine->gfx[0];
177189   int x,y;
178190   int count = 0;
r10427r10428
186198   {
187199      for (x=38;x--;)
188200      {
189            color = ((mkiv_vram[count]) & 0xe0) >> 5;
190         tile = (mkiv_vram[count+1]|mkiv_vram[count]<<8) & 0x3ff;
191         bgtile = (mkiv_vram[count+1]|mkiv_vram[count]<<8) & 0xff; // first 256 tiles
201            color = ((state->mkiv_vram[count]) & 0xe0) >> 5;
202         tile = (state->mkiv_vram[count+1]|state->mkiv_vram[count]<<8) & 0x3ff;
203         bgtile = (state->mkiv_vram[count+1]|state->mkiv_vram[count]<<8) & 0xff; // first 256 tiles
192204         uBackgroundColour(screen->machine); // read sw7
193205         gfx_element_decode(gfx, bgtile);    // force the machine to update only the first 256 tiles.
194206                                             // as we only update the background, not the entire display.
195         flipx = ((mkiv_vram[count]) & 0x04);
196         flipy = ((mkiv_vram[count]) & 0x08);
207         flipx = ((state->mkiv_vram[count]) & 0x04);
208         flipy = ((state->mkiv_vram[count]) & 0x08);
197209         drawgfx_opaque(bitmap,cliprect,gfx,tile,color,flipx,flipy,(38-x-1)<<3,(27-y-1)<<3);
198210         count+=2;
199211      }
r10427r10428
203215
204216static READ8_HANDLER(ldsw)
205217{
218   aristmk4_state *state = space->machine->driver_data<aristmk4_state>();
206219
207220   int U3_p2_ret= input_port_read(space->machine, "5002");
208221   if(U3_p2_ret & 0x1)
209222   {
210223        return 0;
211224   }
212   return cgdrsw = input_port_read(space->machine, "CGDRSW");
225   return state->cgdrsw = input_port_read(space->machine, "CGDRSW");
213226}
214227
215228static READ8_HANDLER(cgdrr)
216229{
230   aristmk4_state *state = space->machine->driver_data<aristmk4_state>();
217231
218   if(cgdrsw) // is the LC closed
232   if(state->cgdrsw) // is the LC closed
219233   {
220        return ripple; // return a positive value from the ripple counter
234        return state->ripple; // return a positive value from the state->ripple counter
221235   }
222236   return 0x0; // otherwise the counter outputs are set low.
223237}
224238
225239static WRITE8_HANDLER(cgdrw)
226240{
241   aristmk4_state *state = space->machine->driver_data<aristmk4_state>();
227242
228    ripple = data;
243    state->ripple = data;
229244
230245}
231246
232247static WRITE8_HANDLER(u3_p0)
233248{
249   aristmk4_state *state = space->machine->driver_data<aristmk4_state>();
234250
235   u3_p0_w = data;
236   //logerror("u3_p0_w: %02X\n",u3_p0_w);
251   state->u3_p0_w = data;
252   //logerror("u3_p0_w: %02X\n",state->u3_p0_w);
237253
238254}
239255
240256static READ8_HANDLER(u3_p2)
241257{
258   aristmk4_state *state = space->machine->driver_data<aristmk4_state>();
242259
243260    int u3_p2_ret= input_port_read(space->machine, "5002");
244261    int u3_p3_ret= input_port_read(space->machine, "5003");
r10427r10428
246263    output_set_lamp_value(19, (u3_p2_ret >> 4) & 1); //auditkey light
247264    output_set_lamp_value(20, (u3_p3_ret >> 2) & 1); //jackpotkey light
248265
249    if (u3_p0_w&0x20) // DOPTE on
266    if (state->u3_p0_w&0x20) // DOPTE on
250267    {
251268        if (u3_p3_ret&0x02) // door closed
252269         u3_p2_ret = u3_p2_ret^0x08; // DOPTI on
253270   }
254271
255    if (inscrd==0)
272    if (state->inscrd==0)
256273    {
257      inscrd=input_port_read(space->machine, "insertcoin");
274      state->inscrd=input_port_read(space->machine, "insertcoin");
258275   }
259276
260    if (inscrd==1)
277    if (state->inscrd==1)
261278      u3_p2_ret=u3_p2_ret^0x02;
262279
263280    return u3_p2_ret;
r10427r10428
297314
298315static WRITE8_HANDLER(mkiv_pia_outa)
299316{
317   aristmk4_state *state = space->machine->driver_data<aristmk4_state>();
300318   mc146818_device *mc = space->machine->device<mc146818_device>("rtc");
301    if(rtc_data_strobe)
319    if(state->rtc_data_strobe)
302320    {
303321        mc->write(*space,1,data);
304322        //logerror("rtc protocol write data: %02X\n",data);
r10427r10428
316334//output ca2
317335static WRITE8_DEVICE_HANDLER(mkiv_pia_ca2)
318336{
319     rtc_address_strobe = data;
337   aristmk4_state *state = device->machine->driver_data<aristmk4_state>();
338     state->rtc_address_strobe = data;
320339    // logerror("address strobe %02X\n", address_strobe);
321340}
322341
r10427r10428
324343//output cb2
325344static WRITE8_DEVICE_HANDLER(mkiv_pia_cb2)
326345{
327     rtc_data_strobe = data;
346   aristmk4_state *state = device->machine->driver_data<aristmk4_state>();
347     state->rtc_data_strobe = data;
328348     //logerror("data strobe: %02X\n", data);
329349}
330350
r10427r10428
333353//output b
334354static WRITE8_DEVICE_HANDLER(mkiv_pia_outb)
335355{
356   aristmk4_state *state = device->machine->driver_data<aristmk4_state>();
336357
337358     UINT8 emet[5];
338359     int i = 0;
r10427r10428
351372            if(emet[i])
352373            {
353374                //logerror("Mechanical meter %d pulse: %02d\n",i+1, emet[i]);
354                sample_start(samples,i,0, FALSE); // pulse sound for mechanical meters
375                sample_start(state->samples,i,0, FALSE); // pulse sound for mechanical meters
355376            }
356377     }
357378
r10427r10428
383404
384405static TIMER_CALLBACK(coin_input_reset)
385406{
407   aristmk4_state *state = machine->driver_data<aristmk4_state>();
386408
387   inscrd=0; //reset credit input after 150msec
409   state->inscrd=0; //reset credit input after 150msec
388410
389411}
390412
391413static TIMER_CALLBACK(hopper_reset)
392414{
415   aristmk4_state *state = machine->driver_data<aristmk4_state>();
393416
394   hopper_motor=0x01;
417   state->hopper_motor=0x01;
395418
396419}
397420
r10427r10428
400423
401424static READ8_DEVICE_HANDLER(via_a_r)
402425{
426   aristmk4_state *state = device->machine->driver_data<aristmk4_state>();
403427   int psg_ret=0;
404428
405    if (ay8910_1&0x03) // SW1 read.
429    if (state->ay8910_1&0x03) // SW1 read.
406430    {
407431       psg_ret = ay8910_r(device->machine->device("ay1"), 0);
408432       //logerror("PSG porta ay1 returned %02X\n",psg_ret);
409433    }
410434
411   else if (ay8910_2&0x03) //i don't think we read anything from Port A on ay2, Can be removed once game works ok.
435   else if (state->ay8910_2&0x03) //i don't think we read anything from Port A on ay2, Can be removed once game works ok.
412436   {
413437      psg_ret = ay8910_r(device->machine->device("ay2"), 0);
414438      //logerror("PSG porta ay2 returned %02X\n",psg_ret);
r10427r10428
420444
421445static READ8_DEVICE_HANDLER(via_b_r)
422446{
447   aristmk4_state *state = device->machine->driver_data<aristmk4_state>();
423448
424449    int ret=input_port_read(device->machine, "via_port_b");
425450
r10427r10428
432457/* Coin input... CBOPT2 goes LOW, then the optic detectors OPTA1 / OPTB1 detect the coin passing */
433458/* The timer causes one credit, per 150ms or so... */
434459
435    switch(inscrd)
460    switch(state->inscrd)
436461   {
437462
438463      case 0x00:
r10427r10428
440465
441466      case 0x01:
442467         ret=ret^0x10;
443         inscrd++;
468         state->inscrd++;
444469         break;
445470
446471      case 0x02:
447472         ret=ret^0x20;
448         inscrd++;
473         state->inscrd++;
449474         device->machine->scheduler().timer_set(attotime::from_msec(150), FUNC(coin_input_reset));
450475         break;
451476
r10427r10428
456481
457482// if user presses collect.. send coins to hopper.
458483
459    switch(hopper_motor)
484    switch(state->hopper_motor)
460485   {
461486      case 0x00:
462487         ret=ret^0x40;
463488         device->machine->scheduler().timer_set(attotime::from_msec(175), FUNC(hopper_reset));
464         hopper_motor=0x02;
489         state->hopper_motor=0x02;
465490         break;
466491      case 0x01:
467492         break; //default
r10427r10428
476501
477502
478503static WRITE8_DEVICE_HANDLER(via_a_w)
479{   //via_b_w will handle sending the data to the ay8910, so just write the data for it to use later
504{
505   aristmk4_state *state = device->machine->driver_data<aristmk4_state>();   //via_b_w will handle sending the data to the ay8910, so just write the data for it to use later
480506
481507   //logerror("VIA port A write %02X\n",data);
482   psg_data = data;
508   state->psg_data = data;
483509
484510}
485511
486512static WRITE8_DEVICE_HANDLER(via_b_w)
487513{
488   ay8910_1 = ( data & 0x0F ) ; //only need first 4 bits per schematics
514   aristmk4_state *state = device->machine->driver_data<aristmk4_state>();
515   state->ay8910_1 = ( data & 0x0F ) ; //only need first 4 bits per schematics
489516                                 //NOTE: when bit 4 is off, we write to AY1, when bit 4 is on, we write to AY2
490   ay8910_2 = ay8910_1;
517   state->ay8910_2 = state->ay8910_1;
491518
492   if ( ay8910_2 & 0x08 ) // is bit 4 on ?
519   if ( state->ay8910_2 & 0x08 ) // is bit 4 on ?
493520   {
494        ay8910_2  = (ay8910_2 | 0x02) ; // bit 2 is turned on as bit 4 hooks to bit 2 in the schematics
495        ay8910_1  = 0x00; // write only to ay2
521        state->ay8910_2  = (state->ay8910_2 | 0x02) ; // bit 2 is turned on as bit 4 hooks to bit 2 in the schematics
522        state->ay8910_1  = 0x00; // write only to ay2
496523   }
497524   else
498525   {
499      ay8910_2 = 0x00; // write only to ay1
526      state->ay8910_2 = 0x00; // write only to ay1
500527   }
501528
502529   //only need bc1/bc2 and bdir so drop bit 4.
503530
504   ay8910_1 = (ay8910_1 & 0x07);
505   ay8910_2 = (ay8910_2 & 0x07);
531   state->ay8910_1 = (state->ay8910_1 & 0x07);
532   state->ay8910_2 = (state->ay8910_2 & 0x07);
506533
507534   //PSG ay1
508535
509   switch(ay8910_1)
536   switch(state->ay8910_1)
510537   {
511538
512539      case 0x00:   //INACT -Nothing to do here. Inactive PSG
r10427r10428
517544
518545      case 0x06:  //WRITE
519546        {
520           ay8910_data_w( device->machine->device("ay1"), 0 , psg_data );
521           //logerror("VIA Port A write data ay1: %02X\n",psg_data);
547           ay8910_data_w( device->machine->device("ay1"), 0 , state->psg_data );
548           //logerror("VIA Port A write data ay1: %02X\n",state->psg_data);
522549           break;
523550        }
524551
525552      case 0x07:  //LATCH Address (set register)
526553        {
527           ay8910_address_w( device->machine->device("ay1"), 0 , psg_data );
528           //logerror("VIA Port B write register ay1: %02X\n",psg_data);
554           ay8910_address_w( device->machine->device("ay1"), 0 , state->psg_data );
555           //logerror("VIA Port B write register ay1: %02X\n",state->psg_data);
529556           break;
530557        }
531558
532559      default:
533         //logerror("Unknown PSG state on ay1: %02X\n",ay8910_1);
560         //logerror("Unknown PSG state on ay1: %02X\n",state->ay8910_1);
534561         break;
535562   }
536563
537564   //PSG ay2
538565
539   switch(ay8910_2)
566   switch(state->ay8910_2)
540567   {
541568
542569      case 0x00:   //INACT - Nothing to do here. Inactive PSG
r10427r10428
550577
551578      case 0x06:  //WRITE
552579        {
553           ay8910_data_w( device->machine->device("ay2"), 0 , psg_data );
554           //logerror("VIA Port A write data ay2: %02X\n",psg_data);
580           ay8910_data_w( device->machine->device("ay2"), 0 , state->psg_data );
581           //logerror("VIA Port A write data ay2: %02X\n",state->psg_data);
555582           break;
556583        }
557584
558585      case 0x07:  //LATCH Address (set register)
559586        {
560            ay8910_address_w( device->machine->device("ay2"), 0 , psg_data );
561            //logerror("VIA Port B write register ay2: %02X\n",psg_data);
587            ay8910_address_w( device->machine->device("ay2"), 0 , state->psg_data );
588            //logerror("VIA Port B write register ay2: %02X\n",state->psg_data);
562589            break;
563590        }
564591
565592      default:
566         //logerror("Unknown PSG state on ay2: %02X\n",ay8910_2);
593         //logerror("Unknown PSG state on ay2: %02X\n",state->ay8910_2);
567594         break;
568595
569596   }
r10427r10428
597624
598625static WRITE8_DEVICE_HANDLER(via_cb2_w)
599626{
627   aristmk4_state *state = device->machine->driver_data<aristmk4_state>();
600628// CB2 = hopper motor (HOPMO1). When it is 0x01, it is not running (active low)
601629   // when it goes to 0, we're expecting to coins to be paid out, handled in via_b_r
602630   // as soon as it is 1, HOPCO1 to remain 'ON'
603631
604632   if (data==0x01)
605      hopper_motor=data;
606   else if (hopper_motor<0x02)
607      hopper_motor=data;
633      state->hopper_motor=data;
634   else if (state->hopper_motor<0x02)
635      state->hopper_motor=data;
608636}
609637
610638
r10427r10428
658686
659687static READ8_HANDLER(cashcade_r)
660688{
689   aristmk4_state *state = space->machine->driver_data<aristmk4_state>();
661690   /* work around for cashcade games */
662   return cashcade_p[(cashcade_c++)%15];
691   return cashcade_p[(state->cashcade_c++)%15];
663692}
664693
665694static WRITE8_HANDLER(mk4_printer_w)
r10427r10428
673702}
674703
675704static ADDRESS_MAP_START( aristmk4_map, ADDRESS_SPACE_PROGRAM, 8 )
676   AM_RANGE(0x0000, 0x07ff) AM_RAM AM_BASE(&mkiv_vram) // video ram -  chips U49 / U50
705   AM_RANGE(0x0000, 0x07ff) AM_RAM AM_BASE_MEMBER(aristmk4_state, mkiv_vram) // video ram -  chips U49 / U50
677706   AM_RANGE(0x0800, 0x17ff) AM_RAM
678707   AM_RANGE(0x1800, 0x1800) AM_DEVWRITE("crtc", mc6845_address_w)
679708   AM_RANGE(0x1801, 0x1801) AM_DEVREADWRITE("crtc", mc6845_register_r, mc6845_register_w)
r10427r10428
11681197
11691198static DRIVER_INIT( aristmk4 )
11701199{
1171   shapeRomPtr = (UINT8 *)machine->region("tile_gfx")->base();
1172    memcpy(shapeRom,shapeRomPtr,sizeof(shapeRom)); // back up
1173   nvram = auto_alloc_array(machine, UINT8, 0x1000);
1200   aristmk4_state *state = machine->driver_data<aristmk4_state>();
1201   state->shapeRomPtr = (UINT8 *)machine->region("tile_gfx")->base();
1202    memcpy(state->shapeRom,state->shapeRomPtr,sizeof(state->shapeRom)); // back up
1203   state->nvram = auto_alloc_array(machine, UINT8, 0x1000);
11741204}
11751205
11761206static MACHINE_START( aristmk4 )
11771207{
1208   aristmk4_state *state = machine->driver_data<aristmk4_state>();
11781209
1179   samples = machine->device("samples");
1180    state_save_register_global_pointer(machine, nvram, 0x1000); // nvram
1210   state->samples = machine->device("samples");
1211    state_save_register_global_pointer(machine, state->nvram, 0x1000); // state->nvram
11811212}
11821213
11831214
r10427r10428
11971228}
11981229
11991230
1200static MACHINE_CONFIG_START( aristmk4, driver_device )
1231static MACHINE_CONFIG_START( aristmk4, aristmk4_state )
12011232
12021233   /* basic machine hardware */
12031234   MCFG_CPU_ADD("maincpu", M6809, MAIN_CLOCK/8) // 1.5mhz (goldenc needs a bit faster for some reason)
src/mame/drivers/tumbleb.c
r10427r10428
888888   return 0x00;
889889}
890890
891static UINT8 semicom_prot_offset = 0x00;
892static UINT16 protbase = 0x0000;
893891
894892// probably not endian safe
895893static WRITE8_HANDLER( prot_io_w )
r10427r10428
900898   {
901899      case 0x00:
902900      {
903         UINT16 word = state->mainram[(protbase/2) + semicom_prot_offset];
901         UINT16 word = state->mainram[(state->protbase/2) + state->semicom_prot_offset];
904902         word = (word & 0xff00) | (data << 0);
905         state->mainram[(protbase/2) + semicom_prot_offset] = word;
903         state->mainram[(state->protbase/2) + state->semicom_prot_offset] = word;
906904
907905         break;
908906      }
909907
910908      case 0x01:
911909      {
912         UINT16 word = state->mainram[(protbase/2) + semicom_prot_offset];
910         UINT16 word = state->mainram[(state->protbase/2) + state->semicom_prot_offset];
913911         word = (word & 0x00ff) | (data << 8);
914         state->mainram[(protbase/2) + semicom_prot_offset] = word;
912         state->mainram[(state->protbase/2) + state->semicom_prot_offset] = word;
915913
916914         break;
917915      }
918916
919917      case 0x02: // offset
920918      {
921         semicom_prot_offset = data;
919         state->semicom_prot_offset = data;
922920         break;
923921      }
924922
r10427r10428
34433441   int i, len = machine->region("user1")->bytes();
34443442   /* simulate RAM initialization done by the protection MCU */
34453443   /* verified on real hardware */
3446//  static UINT16 htchctch_mcu68k[] =
3444//  static const UINT16 htchctch_mcu68k[] =
34473445//  {
34483446//      /* moved to protdata.bin file .. */
34493447//  };
r10427r10428
37443742
37453743static DRIVER_INIT( wlstar )
37463744{
3745   tumbleb_state *state = machine->driver_data<tumbleb_state>();
37473746   tumblepb_gfx1_rearrange(machine);
37483747
37493748   /* slightly different banking */
37503749   memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x100002, 0x100003, 0, 0, wlstar_tilebank_w);
37513750
3752   protbase = 0x0000;
3751   state->protbase = 0x0000;
37533752}
37543753
37553754static DRIVER_INIT( wondl96 )
37563755{
3756   tumbleb_state *state = machine->driver_data<tumbleb_state>();
37573757   DRIVER_INIT_CALL( wlstar );
3758   protbase = 0x0200;
3758   state->protbase = 0x0200;
37593759}
37603760
37613761static DRIVER_INIT ( dquizgo )
src/mame/drivers/micro3d.c
r10427r10428
2626#include "cpu/am29000/am29000.h"
2727#include "cpu/mcs51/mcs51.h"
2828#include "machine/68681.h"
29#include "machine/mc68901.h"
2930#include "sound/2151intf.h"
3031#include "sound/upd7759.h"
3132#include "machine/nvram.h"
r10427r10428
206207   AM_RANGE(0x980000, 0x980001) AM_READWRITE(micro3d_adc_r, micro3d_adc_w)
207208   AM_RANGE(0x9a0000, 0x9a0007) AM_READWRITE(micro3d_tms_host_r, micro3d_tms_host_w)
208209   AM_RANGE(0x9c0000, 0x9c0001) AM_NOP               /* Lamps */
209   AM_RANGE(0x9e0000, 0x9e002f) AM_READWRITE(micro3d_mc68901_r, micro3d_mc68901_w)
210   AM_RANGE(0x9e0000, 0x9e002f) AM_DEVREADWRITE8_MODERN("mc68901", mc68901_device, read, write, 0xff00)
210211   AM_RANGE(0xa00000, 0xa0003f) AM_DEVREADWRITE8("duart68681", duart68681_r, duart68681_w, 0xff00)
211212   AM_RANGE(0xa20000, 0xa20001) AM_READ(micro3d_encoder_h_r)
212213   AM_RANGE(0xa40002, 0xa40003) AM_READ(micro3d_encoder_l_r)
r10427r10428
306307   micro3d_duart_output_w
307308};
308309
310static MC68901_INTERFACE( mfp_intf )
311{
312   4000000,                                 /* timer clock */
313   0,                                       /* receive clock */
314   0,                                       /* transmit clock */
315   DEVCB_CPU_INPUT_LINE("maincpu", M68K_IRQ_4),      /* interrupt */
316   DEVCB_NULL,                                 /* GPIO read */
317   DEVCB_NULL,                                 /* GPIO write */
318   DEVCB_NULL,                                 /* TAO */
319   DEVCB_NULL,                                 /* TBO */
320   DEVCB_NULL,                                 /* TCO */
321   DEVCB_NULL,                                 /* TDO */
322   DEVCB_NULL,                                 /* serial input */
323   DEVCB_NULL                                 /* serial output */
324};
309325
326
310327/*************************************
311328 *
312329 *  Machine driver
r10427r10428
332349   MCFG_CPU_IO_MAP(soundmem_io)
333350
334351   MCFG_DUART68681_ADD("duart68681", XTAL_3_6864MHz, micro3d_duart68681_config)
352   MCFG_MC68901_ADD("mc68901", 4000000, mfp_intf)
335353
336354   MCFG_MACHINE_RESET(micro3d)
337355   MCFG_NVRAM_ADD_0FILL("nvram")
src/mame/drivers/tigeroad.c
r10427r10428
2727#include "includes/tigeroad.h"
2828
2929
30static UINT16 *ram16;
3130
3231/*
3332 F1 Dream protection code written by Eric Hustvedt (hustvedt@ma.ultranet.com).
r10427r10428
8281
8382static void f1dream_protection_w(address_space *space)
8483{
84   tigeroad_state *state = space->machine->driver_data<tigeroad_state>();
8585   int indx;
8686   int value = 255;
8787   int prevpc = cpu_get_previouspc(space->cpu);
r10427r10428
8989   if (prevpc == 0x244c)
9090   {
9191      /* Called once, when a race is started.*/
92      indx = ram16[0x3ff0/2];
93      ram16[0x3fe6/2] = f1dream_2450_lookup[indx];
94      ram16[0x3fe8/2] = f1dream_2450_lookup[++indx];
95      ram16[0x3fea/2] = f1dream_2450_lookup[++indx];
96      ram16[0x3fec/2] = f1dream_2450_lookup[++indx];
92      indx = state->ram16[0x3ff0/2];
93      state->ram16[0x3fe6/2] = f1dream_2450_lookup[indx];
94      state->ram16[0x3fe8/2] = f1dream_2450_lookup[++indx];
95      state->ram16[0x3fea/2] = f1dream_2450_lookup[++indx];
96      state->ram16[0x3fec/2] = f1dream_2450_lookup[++indx];
9797   }
9898   else if (prevpc == 0x613a)
9999   {
100100      /* Called for every sprite on-screen.*/
101      if (ram16[0x3ff6/2] < 15)
101      if (state->ram16[0x3ff6/2] < 15)
102102      {
103         indx = f1dream_613ea_lookup[ram16[0x3ff6/2]] - ram16[0x3ff4/2];
103         indx = f1dream_613ea_lookup[state->ram16[0x3ff6/2]] - state->ram16[0x3ff4/2];
104104         if (indx > 255)
105105         {
106106            indx <<= 4;
107            indx += ram16[0x3ff6/2] & 0x00ff;
107            indx += state->ram16[0x3ff6/2] & 0x00ff;
108108            value = f1dream_613eb_lookup[indx];
109109         }
110110      }
111111
112      ram16[0x3ff2/2] = value;
112      state->ram16[0x3ff2/2] = value;
113113   }
114114   else if (prevpc == 0x17b70)
115115   {
116116      /* Called only before a real race, not a time trial.*/
117      if (ram16[0x3ff0/2] >= 0x04) indx = 128;
118      else if (ram16[0x3ff0/2] > 0x02) indx = 96;
119      else if (ram16[0x3ff0/2] == 0x02) indx = 64;
120      else if (ram16[0x3ff0/2] == 0x01) indx = 32;
117      if (state->ram16[0x3ff0/2] >= 0x04) indx = 128;
118      else if (state->ram16[0x3ff0/2] > 0x02) indx = 96;
119      else if (state->ram16[0x3ff0/2] == 0x02) indx = 64;
120      else if (state->ram16[0x3ff0/2] == 0x01) indx = 32;
121121      else indx = 0;
122122
123      indx += ram16[0x3fee/2];
123      indx += state->ram16[0x3fee/2];
124124      if (indx < 128)
125125      {
126         ram16[0x3fe6/2] = f1dream_17b74_lookup[indx];
127         ram16[0x3fe8/2] = f1dream_17b74_lookup[++indx];
128         ram16[0x3fea/2] = f1dream_17b74_lookup[++indx];
129         ram16[0x3fec/2] = f1dream_17b74_lookup[++indx];
126         state->ram16[0x3fe6/2] = f1dream_17b74_lookup[indx];
127         state->ram16[0x3fe8/2] = f1dream_17b74_lookup[++indx];
128         state->ram16[0x3fea/2] = f1dream_17b74_lookup[++indx];
129         state->ram16[0x3fec/2] = f1dream_17b74_lookup[++indx];
130130      }
131131      else
132132      {
133         ram16[0x3fe6/2] = 0x00ff;
134         ram16[0x3fe8/2] = 0x00ff;
135         ram16[0x3fea/2] = 0x00ff;
136         ram16[0x3fec/2] = 0x00ff;
133         state->ram16[0x3fe6/2] = 0x00ff;
134         state->ram16[0x3fe8/2] = 0x00ff;
135         state->ram16[0x3fea/2] = 0x00ff;
136         state->ram16[0x3fec/2] = 0x00ff;
137137      }
138138   }
139139   else if ((prevpc == 0x27f8) || (prevpc == 0x511a) || (prevpc == 0x5142) || (prevpc == 0x516a))
140140   {
141141      /* The main CPU stuffs the byte for the soundlatch into 0xfffffd.*/
142      soundlatch_w(space,2,ram16[0x3ffc/2]);
142      soundlatch_w(space,2,state->ram16[0x3ffc/2]);
143143   }
144144}
145145
146146static WRITE16_HANDLER( f1dream_control_w )
147147{
148   logerror("protection write, PC: %04x  FFE1 Value:%01x\n",cpu_get_pc(space->cpu), ram16[0x3fe0/2]);
148   tigeroad_state *state = space->machine->driver_data<tigeroad_state>();
149   logerror("protection write, PC: %04x  FFE1 Value:%01x\n",cpu_get_pc(space->cpu), state->ram16[0x3fe0/2]);
149150   f1dream_protection_w(space);
150151}
151152
r10427r10428
178179   AM_RANGE(0xfe8000, 0xfe8003) AM_WRITE(tigeroad_scroll_w)
179180   AM_RANGE(0xfe800e, 0xfe800f) AM_WRITEONLY    /* fe800e = watchdog or IRQ acknowledge */
180181   AM_RANGE(0xff8200, 0xff867f) AM_RAM_WRITE(paletteram16_xxxxRRRRGGGGBBBB_word_w) AM_BASE_GENERIC(paletteram)
181   AM_RANGE(0xffc000, 0xffffff) AM_RAM AM_BASE(&ram16)
182   AM_RANGE(0xffc000, 0xffffff) AM_RAM AM_BASE_MEMBER(tigeroad_state, ram16)
182183ADDRESS_MAP_END
183184
184185
src/mame/drivers/segas32.c
r10427r10428
373373 *
374374 *************************************/
375375
376UINT8 *ga2_dpram;
377UINT16 *system32_workram;
378UINT16 *system32_protram;
379376
380377
381378
r10427r10428
385382 *
386383 *************************************/
387384
388static UINT8 *z80_shared_ram;
389385
390386/* V60 interrupt controller */
391static UINT8 v60_irq_control[0x10];
392static timer_device *v60_irq_timer[2];
393387
394388/* sound interrupt controller */
395static UINT8 sound_irq_control[4];
396static UINT8 sound_irq_input;
397static UINT8 sound_dummy_value;
398static UINT16 sound_bank;
399389
400390
401391/* I/O chips and custom I/O */
402static UINT8 misc_io_data[2][0x10];
403static read16_space_func custom_io_r[2];
404static write16_space_func custom_io_w[2];
405static UINT8 analog_bank;
406static UINT8 analog_value[4];
407static UINT8 sonic_last[6];
408392
409393/* callbacks to handle output */
410typedef void (*sys32_output_callback)(int which, UINT16 data);
411static sys32_output_callback segas32_sw1_output, segas32_sw2_output, segas32_sw3_output;
412
413394static void (*system32_prot_vblank)(device_t *device);
414395
415396
r10427r10428
432413
433414static MACHINE_RESET( system32 )
434415{
416   segas32_state *state = machine->driver_data<segas32_state>();
435417   /* initialize the interrupt controller */
436   memset(v60_irq_control, 0xff, sizeof(v60_irq_control));
418   memset(state->v60_irq_control, 0xff, sizeof(state->v60_irq_control));
437419
438420   /* allocate timers */
439   v60_irq_timer[0] = machine->device<timer_device>("v60_irq0");
440   v60_irq_timer[1] = machine->device<timer_device>("v60_irq1");
421   state->v60_irq_timer[0] = machine->device<timer_device>("v60_irq0");
422   state->v60_irq_timer[1] = machine->device<timer_device>("v60_irq1");
441423
442424   /* clear IRQ lines */
443425   cputag_set_input_line(machine, "maincpu", 0, CLEAR_LINE);
r10427r10428
453435
454436static void update_irq_state(running_machine *machine)
455437{
456   UINT8 effirq = v60_irq_control[7] & ~v60_irq_control[6] & 0x1f;
438   segas32_state *state = machine->driver_data<segas32_state>();
439   UINT8 effirq = state->v60_irq_control[7] & ~state->v60_irq_control[6] & 0x1f;
457440   int vector;
458441
459442   /* loop over interrupt vectors, finding the highest priority one with */
r10427r10428
473456
474457static void signal_v60_irq(running_machine *machine, int which)
475458{
459   segas32_state *state = machine->driver_data<segas32_state>();
476460   int i;
477461
478462   /* see if this interrupt input is mapped to any vectors; if so, mark them */
479463   for (i = 0; i < 5; i++)
480      if (v60_irq_control[i] == which)
481         v60_irq_control[7] |= 1 << i;
464      if (state->v60_irq_control[i] == which)
465         state->v60_irq_control[7] |= 1 << i;
482466   update_irq_state(machine);
483467}
484468
r10427r10428
491475
492476static void int_control_w(address_space *space, int offset, UINT8 data)
493477{
478   segas32_state *state = space->machine->driver_data<segas32_state>();
494479   int duration;
495480
496481//  logerror("%06X:int_control_w(%X) = %02X\n", cpu_get_pc(space->cpu), offset, data);
r10427r10428
501486      case 2:
502487      case 3:
503488      case 4:         /* vectors */
504         v60_irq_control[offset] = data;
489         state->v60_irq_control[offset] = data;
505490         break;
506491
507492      case 5:         /* unknown */
508         v60_irq_control[offset] = data;
493         state->v60_irq_control[offset] = data;
509494         break;
510495
511496      case 6:         /* mask */
512         v60_irq_control[offset] = data;
497         state->v60_irq_control[offset] = data;
513498         update_irq_state(space->machine);
514499         break;
515500
516501      case 7:         /* acknowledge */
517         v60_irq_control[offset] &= data;
502         state->v60_irq_control[offset] &= data;
518503         update_irq_state(space->machine);
519504         break;
520505
521506      case 8:
522507      case 9:         /* timer 0 count */
523         v60_irq_control[offset] = data;
524         duration = v60_irq_control[8] + ((v60_irq_control[9] << 8) & 0xf00);
508         state->v60_irq_control[offset] = data;
509         duration = state->v60_irq_control[8] + ((state->v60_irq_control[9] << 8) & 0xf00);
525510         if (duration)
526511         {
527512            attotime period = attotime::from_hz(TIMER_0_CLOCK) * duration;
528            v60_irq_timer[0]->adjust(period, MAIN_IRQ_TIMER0);
513            state->v60_irq_timer[0]->adjust(period, MAIN_IRQ_TIMER0);
529514         }
530515         break;
531516
532517      case 10:
533518      case 11:      /* timer 1 count */
534         v60_irq_control[offset] = data;
535         duration = v60_irq_control[10] + ((v60_irq_control[11] << 8) & 0xf00);
519         state->v60_irq_control[offset] = data;
520         duration = state->v60_irq_control[10] + ((state->v60_irq_control[11] << 8) & 0xf00);
536521         if (duration)
537522         {
538523            attotime period = attotime::from_hz(TIMER_1_CLOCK) * duration;
539            v60_irq_timer[1]->adjust(period, MAIN_IRQ_TIMER1);
524            state->v60_irq_timer[1]->adjust(period, MAIN_IRQ_TIMER1);
540525         }
541526         break;
542527
r10427r10428
630615
631616static UINT16 common_io_chip_r(address_space *space, int which, offs_t offset, UINT16 mem_mask)
632617{
618   segas32_state *state = space->machine->driver_data<segas32_state>();
633619   static const char *const portnames[2][8] =
634620         {
635621            { "P1_A", "P2_A", "PORTC_A", "PORTD_A", "SERVICE12_A", "SERVICE34_A", "PORTG_A", "PORTH_A" },
r10427r10428
649635      case 0x0c/2:
650636      case 0x0e/2:
651637         /* if the port is configured as an output, return the last thing written */
652         if (misc_io_data[which][0x1e/2] & (1 << offset))
653            return misc_io_data[which][offset];
638         if (state->misc_io_data[which][0x1e/2] & (1 << offset))
639            return state->misc_io_data[which][offset];
654640
655641         /* otherwise, return an input port */
656642         return input_port_read_safe(space->machine, portnames[which][offset], 0xffff);
r10427r10428
668654      /* CNT register & mirror */
669655      case 0x18/2:
670656      case 0x1c/2:
671         return misc_io_data[which][0x1c/2];
657         return state->misc_io_data[which][0x1c/2];
672658
673659      /* port direction register & mirror */
674660      case 0x1a/2:
675661      case 0x1e/2:
676         return misc_io_data[which][0x1e/2];
662         return state->misc_io_data[which][0x1e/2];
677663   }
678664   return 0xffff;
679665}
r10427r10428
681667
682668static void common_io_chip_w(address_space *space, int which, offs_t offset, UINT16 data, UINT16 mem_mask)
683669{
670   segas32_state *state = space->machine->driver_data<segas32_state>();
684671   UINT8 old;
685672
686673   /* only LSB matters */
r10427r10428
689676
690677   /* generic implementation */
691678   offset &= 0x1f/2;
692   old = misc_io_data[which][offset];
693   misc_io_data[which][offset] = data;
679   old = state->misc_io_data[which][offset];
680   state->misc_io_data[which][offset] = data;
694681
695682   switch (offset)
696683   {
r10427r10428
701688      case 0x08/2:
702689      case 0x0a/2:
703690      case 0x0c/2:
704         if (segas32_sw2_output)
705            segas32_sw2_output(which, data);
691         if (state->sw2_output)
692            state->sw2_output(which, data);
706693         break;
707694
708695      /* miscellaneous output */
709696      case 0x06/2:
710         if (segas32_sw1_output)
711            segas32_sw1_output(which, data);
697         if (state->sw1_output)
698            state->sw1_output(which, data);
712699
713700         if (which == 0)
714701         {
r10427r10428
726713      /* tile banking */
727714      case 0x0e/2:
728715         if (which == 0)
729            system32_tilebank_external = data;
716            state->system32_tilebank_external = data;
730717         else
731718         {
732719            /* multi-32 EEPROM access */
r10427r10428
739726
740727      /* CNT register */
741728      case 0x1c/2:
742         system32_displayenable[which] = (data & 0x02);
729         state->system32_displayenable[which] = (data & 0x02);
743730         if (which == 0)
744731            cputag_set_input_line(space->machine, "soundcpu", INPUT_LINE_RESET, (data & 0x04) ? CLEAR_LINE : ASSERT_LINE);
745732         break;
r10427r10428
800787
801788static READ16_HANDLER( io_expansion_r )
802789{
803   if (custom_io_r[0])
804      return (*custom_io_r[0])(space, offset, mem_mask);
790   segas32_state *state = space->machine->driver_data<segas32_state>();
791   if (state->custom_io_r[0])
792      return (*state->custom_io_r[0])(space, offset, mem_mask);
805793   else
806794      logerror("%06X:io_expansion_r(%X)\n", cpu_get_pc(space->cpu), offset);
807795   return 0xffff;
r10427r10428
810798
811799static WRITE16_HANDLER( io_expansion_w )
812800{
801   segas32_state *state = space->machine->driver_data<segas32_state>();
813802   /* only LSB matters */
814803   if (!ACCESSING_BITS_0_7)
815804   return;
816805
817   if (custom_io_w[0])
818      (*custom_io_w[0])(space, offset, data, mem_mask);
806   if (state->custom_io_w[0])
807      (*state->custom_io_w[0])(space, offset, data, mem_mask);
819808   else
820809      logerror("%06X:io_expansion_w(%X) = %02X\n", cpu_get_pc(space->cpu), offset, data & 0xff);
821810}
r10427r10428
823812
824813static READ32_HANDLER( io_expansion_0_r )
825814{
826   if (custom_io_r[0])
827      return (*custom_io_r[0])(space, offset*2+0, mem_mask) |
828           ((*custom_io_r[0])(space, offset*2+1, mem_mask >> 16) << 16);
815   segas32_state *state = space->machine->driver_data<segas32_state>();
816   if (state->custom_io_r[0])
817      return (*state->custom_io_r[0])(space, offset*2+0, mem_mask) |
818           ((*state->custom_io_r[0])(space, offset*2+1, mem_mask >> 16) << 16);
829819   else
830820      logerror("%06X:io_expansion_r(%X)\n", cpu_get_pc(space->cpu), offset);
831821   return 0xffffffff;
r10427r10428
834824
835825static WRITE32_HANDLER( io_expansion_0_w )
836826{
827   segas32_state *state = space->machine->driver_data<segas32_state>();
837828   /* only LSB matters */
838829
839830
840831   if (ACCESSING_BITS_0_7)
841832   {
842833      /* harddunk uses bits 4,5 for output lamps */
843      if (segas32_sw3_output)
844         segas32_sw3_output(0, data & 0xff);
834      if (state->sw3_output)
835         state->sw3_output(0, data & 0xff);
845836
846      if (custom_io_w[0])
847         (*custom_io_w[0])(space, offset*2+0, data, mem_mask);
837      if (state->custom_io_w[0])
838         (*state->custom_io_w[0])(space, offset*2+0, data, mem_mask);
848839      else
849840         logerror("%06X:io_expansion_w(%X) = %02X\n", cpu_get_pc(space->cpu), offset, data & 0xff);
850841
851842   }
852843   if (ACCESSING_BITS_16_23)
853844   {
854      if (custom_io_w[0])
855         (*custom_io_w[0])(space, offset*2+1, data >> 16, mem_mask >> 16);
845      if (state->custom_io_w[0])
846         (*state->custom_io_w[0])(space, offset*2+1, data >> 16, mem_mask >> 16);
856847      else
857848         logerror("%06X:io_expansion_w(%X) = %02X\n", cpu_get_pc(space->cpu), offset, data & 0xff);
858849   }
r10427r10428
861852
862853static READ32_HANDLER( io_expansion_1_r )
863854{
864   if (custom_io_r[1])
865      return (*custom_io_r[1])(space, offset*2+0, mem_mask) |
866           ((*custom_io_r[1])(space, offset*2+1, mem_mask >> 16) << 16);
855   segas32_state *state = space->machine->driver_data<segas32_state>();
856   if (state->custom_io_r[1])
857      return (*state->custom_io_r[1])(space, offset*2+0, mem_mask) |
858           ((*state->custom_io_r[1])(space, offset*2+1, mem_mask >> 16) << 16);
867859   else
868860      logerror("%06X:io_expansion_r(%X)\n", cpu_get_pc(space->cpu), offset);
869861   return 0xffffffff;
r10427r10428
872864
873865static WRITE32_HANDLER( io_expansion_1_w )
874866{
867   segas32_state *state = space->machine->driver_data<segas32_state>();
875868   /* only LSB matters */
876869   if (ACCESSING_BITS_0_7)
877870   {
878      if (custom_io_w[1])
879         (*custom_io_w[1])(space, offset*2+0, data, mem_mask);
871      if (state->custom_io_w[1])
872         (*state->custom_io_w[1])(space, offset*2+0, data, mem_mask);
880873      else
881874         logerror("%06X:io_expansion_w(%X) = %02X\n", cpu_get_pc(space->cpu), offset, data & 0xff);
882875   }
883876   if (ACCESSING_BITS_16_23)
884877   {
885      if (custom_io_w[1])
886         (*custom_io_w[1])(space, offset*2+1, data >> 16, mem_mask >> 16);
878      if (state->custom_io_w[1])
879         (*state->custom_io_w[1])(space, offset*2+1, data >> 16, mem_mask >> 16);
887880      else
888881         logerror("%06X:io_expansion_w(%X) = %02X\n", cpu_get_pc(space->cpu), offset, data & 0xff);
889882   }
r10427r10428
899892
900893static READ16_HANDLER( analog_custom_io_r )
901894{
895   segas32_state *state = space->machine->driver_data<segas32_state>();
902896   UINT16 result;
903897   switch (offset)
904898   {
r10427r10428
906900      case 0x12/2:
907901      case 0x14/2:
908902      case 0x16/2:
909         result = analog_value[offset & 3] | 0x7f;
910         analog_value[offset & 3] <<= 1;
903         result = state->analog_value[offset & 3] | 0x7f;
904         state->analog_value[offset & 3] <<= 1;
911905         return result;
912906   }
913907   logerror("%06X:unknown analog_custom_io_r(%X) & %04X\n", cpu_get_pc(space->cpu), offset*2, mem_mask);
r10427r10428
917911
918912static WRITE16_HANDLER( analog_custom_io_w )
919913{
914   segas32_state *state = space->machine->driver_data<segas32_state>();
920915   static const char *const names[] = { "ANALOG1", "ANALOG2", "ANALOG3", "ANALOG4" };
921916   switch (offset)
922917   {
r10427r10428
924919      case 0x12/2:
925920      case 0x14/2:
926921      case 0x16/2:
927         analog_value[offset & 3] = input_port_read_safe(space->machine, names[offset & 3], 0);
922         state->analog_value[offset & 3] = input_port_read_safe(space->machine, names[offset & 3], 0);
928923         return;
929924   }
930925   logerror("%06X:unknown analog_custom_io_w(%X) = %04X & %04X\n", cpu_get_pc(space->cpu), offset*2, data, mem_mask);
r10427r10428
950945
951946static WRITE16_HANDLER( orunners_custom_io_w )
952947{
948   segas32_state *state = space->machine->driver_data<segas32_state>();
953949   static const char *const names[] = { "ANALOG1", "ANALOG2", "ANALOG3", "ANALOG4", "ANALOG5", "ANALOG6", "ANALOG7", "ANALOG8" };
954950   switch (offset)
955951   {
r10427r10428
957953      case 0x12/2:
958954      case 0x14/2:
959955      case 0x16/2:
960         analog_value[offset & 3] = input_port_read_safe(space->machine, names[analog_bank * 4 + (offset & 3)], 0);
956         state->analog_value[offset & 3] = input_port_read_safe(space->machine, names[state->analog_bank * 4 + (offset & 3)], 0);
961957         return;
962958
963959      case 0x20/2:
964         analog_bank = data & 1;
960         state->analog_bank = data & 1;
965961         return;
966962   }
967963   logerror("%06X:unknown orunners_custom_io_w(%X) = %04X & %04X\n", cpu_get_pc(space->cpu), offset*2, data, mem_mask);
r10427r10428
970966
971967static READ16_HANDLER( sonic_custom_io_r )
972968{
969   segas32_state *state = space->machine->driver_data<segas32_state>();
973970   static const char *const names[] = { "TRACKX1", "TRACKY1", "TRACKX2", "TRACKY2", "TRACKX3", "TRACKY3" };
974971
975972   switch (offset)
r10427r10428
980977      case 0x0c/2:
981978      case 0x10/2:
982979      case 0x14/2:
983         return (UINT8)(input_port_read(space->machine, names[offset/2]) - sonic_last[offset/2]);
980         return (UINT8)(input_port_read(space->machine, names[offset/2]) - state->sonic_last[offset/2]);
984981   }
985982
986983   logerror("%06X:unknown sonic_custom_io_r(%X) & %04X\n", cpu_get_pc(space->cpu), offset*2, mem_mask);
r10427r10428
990987
991988static WRITE16_HANDLER( sonic_custom_io_w )
992989{
990   segas32_state *state = space->machine->driver_data<segas32_state>();
993991   static const char *const names[] = { "TRACKX1", "TRACKY1", "TRACKX2", "TRACKY2", "TRACKX3", "TRACKY3" };
994992
995993   switch (offset)
r10427r10428
997995      case 0x00/2:
998996      case 0x08/2:
999997      case 0x10/2:
1000         sonic_last[offset/2 + 0] = input_port_read(space->machine, names[offset/2 + 0]);
1001         sonic_last[offset/2 + 1] = input_port_read(space->machine, names[offset/2 + 1]);
998         state->sonic_last[offset/2 + 0] = input_port_read(space->machine, names[offset/2 + 0]);
999         state->sonic_last[offset/2 + 1] = input_port_read(space->machine, names[offset/2 + 1]);
10021000         return;
10031001   }
10041002
r10427r10428
10431041
10441042static READ16_HANDLER( shared_ram_16_r )
10451043{
1046   return z80_shared_ram[offset*2+0] | (z80_shared_ram[offset*2+1] << 8);
1044   segas32_state *state = space->machine->driver_data<segas32_state>();
1045   return state->z80_shared_ram[offset*2+0] | (state->z80_shared_ram[offset*2+1] << 8);
10471046}
10481047
10491048
10501049static WRITE16_HANDLER( shared_ram_16_w )
10511050{
1051   segas32_state *state = space->machine->driver_data<segas32_state>();
10521052   if (ACCESSING_BITS_0_7)
1053      z80_shared_ram[offset*2+0] = data;
1053      state->z80_shared_ram[offset*2+0] = data;
10541054   if (ACCESSING_BITS_8_15)
1055      z80_shared_ram[offset*2+1] = data >> 8;
1055      state->z80_shared_ram[offset*2+1] = data >> 8;
10561056}
10571057
10581058
10591059static READ32_HANDLER( shared_ram_32_r )
10601060{
1061   return z80_shared_ram[offset*4+0] | (z80_shared_ram[offset*4+1] << 8) |
1062         (z80_shared_ram[offset*4+2] << 16) | (z80_shared_ram[offset*4+3] << 24);
1061   segas32_state *state = space->machine->driver_data<segas32_state>();
1062   return state->z80_shared_ram[offset*4+0] | (state->z80_shared_ram[offset*4+1] << 8) |
1063         (state->z80_shared_ram[offset*4+2] << 16) | (state->z80_shared_ram[offset*4+3] << 24);
10631064}
10641065
10651066
10661067static WRITE32_HANDLER( shared_ram_32_w )
10671068{
1069   segas32_state *state = space->machine->driver_data<segas32_state>();
10681070   if (ACCESSING_BITS_0_7)
1069      z80_shared_ram[offset*4+0] = data;
1071      state->z80_shared_ram[offset*4+0] = data;
10701072   if (ACCESSING_BITS_8_15)
1071      z80_shared_ram[offset*4+1] = data >> 8;
1073      state->z80_shared_ram[offset*4+1] = data >> 8;
10721074   if (ACCESSING_BITS_16_23)
1073      z80_shared_ram[offset*4+2] = data >> 16;
1075      state->z80_shared_ram[offset*4+2] = data >> 16;
10741076   if (ACCESSING_BITS_24_31)
1075      z80_shared_ram[offset*4+3] = data >> 24;
1077      state->z80_shared_ram[offset*4+3] = data >> 24;
10761078}
10771079
10781080
r10427r10428
10851087
10861088static void update_sound_irq_state(running_machine *machine)
10871089{
1088   UINT8 effirq = sound_irq_input & ~sound_irq_control[3] & 0x07;
1090   segas32_state *state = machine->driver_data<segas32_state>();
1091   UINT8 effirq = state->sound_irq_input & ~state->sound_irq_control[3] & 0x07;
10891092   int vector;
10901093
10911094   /* loop over interrupt vectors, finding the highest priority one with */
r10427r10428
11051108
11061109static void signal_sound_irq(running_machine *machine, int which)
11071110{
1111   segas32_state *state = machine->driver_data<segas32_state>();
11081112   int i;
11091113
11101114   /* see if this interrupt input is mapped to any vectors; if so, mark them */
11111115   for (i = 0; i < 3; i++)
1112      if (sound_irq_control[i] == which)
1113         sound_irq_input |= 1 << i;
1116      if (state->sound_irq_control[i] == which)
1117         state->sound_irq_input |= 1 << i;
11141118   update_sound_irq_state(machine);
11151119}
11161120
11171121
11181122static void clear_sound_irq(running_machine *machine, int which)
11191123{
1124   segas32_state *state = machine->driver_data<segas32_state>();
11201125   int i;
11211126   for (i = 0; i < 3; i++)
1122      if (sound_irq_control[i] == which)
1123         sound_irq_input &= ~(1 << i);
1127      if (state->sound_irq_control[i] == which)
1128         state->sound_irq_input &= ~(1 << i);
11241129   update_sound_irq_state(machine);
11251130}
11261131
11271132
11281133static WRITE8_HANDLER( sound_int_control_lo_w )
11291134{
1135   segas32_state *state = space->machine->driver_data<segas32_state>();
11301136   /* odd offsets are interrupt acks */
11311137   if (offset & 1)
11321138   {
1133      sound_irq_input &= data;
1139      state->sound_irq_input &= data;
11341140      update_sound_irq_state(space->machine);
11351141   }
11361142
r10427r10428
11421148
11431149static WRITE8_HANDLER( sound_int_control_hi_w )
11441150{
1145   sound_irq_control[offset] = data;
1151   segas32_state *state = space->machine->driver_data<segas32_state>();
1152   state->sound_irq_control[offset] = data;
11461153   update_sound_irq_state(space->machine);
11471154}
11481155
r10427r10428
11651172
11661173static WRITE8_HANDLER( sound_bank_lo_w )
11671174{
1168   sound_bank = (sound_bank & ~0x3f) | (data & 0x3f);
1169   memory_set_bankptr(space->machine, "bank1", space->machine->region("soundcpu")->base() + 0x100000 + 0x2000 * sound_bank);
1175   segas32_state *state = space->machine->driver_data<segas32_state>();
1176   state->sound_bank = (state->sound_bank & ~0x3f) | (data & 0x3f);
1177   memory_set_bankptr(space->machine, "bank1", space->machine->region("soundcpu")->base() + 0x100000 + 0x2000 * state->sound_bank);
11701178}
11711179
11721180
11731181static WRITE8_HANDLER( sound_bank_hi_w )
11741182{
1175   sound_bank = (sound_bank & 0x3f) | ((data & 0x04) << 4) | ((data & 0x03) << 7);
1176   memory_set_bankptr(space->machine, "bank1", space->machine->region("soundcpu")->base() + 0x100000 + 0x2000 * sound_bank);
1183   segas32_state *state = space->machine->driver_data<segas32_state>();
1184   state->sound_bank = (state->sound_bank & 0x3f) | ((data & 0x04) << 4) | ((data & 0x03) << 7);
1185   memory_set_bankptr(space->machine, "bank1", space->machine->region("soundcpu")->base() + 0x100000 + 0x2000 * state->sound_bank);
11771186}
11781187
11791188
r10427r10428
11981207
11991208static READ8_HANDLER( sound_dummy_r )
12001209{
1201   return sound_dummy_value;
1210   segas32_state *state = space->machine->driver_data<segas32_state>();
1211   return state->sound_dummy_value;
12021212}
12031213
12041214
12051215static WRITE8_HANDLER( sound_dummy_w )
12061216{
1207   sound_dummy_value = data;
1217   segas32_state *state = space->machine->driver_data<segas32_state>();
1218   state->sound_dummy_value = data;
12081219}
12091220
12101221
r10427r10428
12181229static ADDRESS_MAP_START( system32_map, ADDRESS_SPACE_PROGRAM, 16 )
12191230   ADDRESS_MAP_UNMAP_HIGH
12201231   AM_RANGE(0x000000, 0x1fffff) AM_ROM
1221   AM_RANGE(0x200000, 0x20ffff) AM_MIRROR(0x0f0000) AM_RAM   AM_BASE(&system32_workram)
1222   AM_RANGE(0x300000, 0x31ffff) AM_MIRROR(0x0e0000) AM_READWRITE(system32_videoram_r, system32_videoram_w) AM_BASE(&system32_videoram)
1223   AM_RANGE(0x400000, 0x41ffff) AM_MIRROR(0x0e0000) AM_READWRITE(system32_spriteram_r, system32_spriteram_w) AM_BASE(&system32_spriteram)
1232   AM_RANGE(0x200000, 0x20ffff) AM_MIRROR(0x0f0000) AM_RAM   AM_BASE_MEMBER(segas32_state, system32_workram)
1233   AM_RANGE(0x300000, 0x31ffff) AM_MIRROR(0x0e0000) AM_READWRITE(system32_videoram_r, system32_videoram_w) AM_BASE_MEMBER(segas32_state, system32_videoram)
1234   AM_RANGE(0x400000, 0x41ffff) AM_MIRROR(0x0e0000) AM_READWRITE(system32_spriteram_r, system32_spriteram_w) AM_BASE_MEMBER(segas32_state, system32_spriteram)
12241235   AM_RANGE(0x500000, 0x50000f) AM_MIRROR(0x0ffff0) AM_READWRITE(system32_sprite_control_r, system32_sprite_control_w)
1225   AM_RANGE(0x600000, 0x60ffff) AM_MIRROR(0x0e0000) AM_READWRITE(system32_paletteram_r, system32_paletteram_w) AM_BASE(&system32_paletteram[0])
1236   AM_RANGE(0x600000, 0x60ffff) AM_MIRROR(0x0e0000) AM_READWRITE(system32_paletteram_r, system32_paletteram_w) AM_BASE_MEMBER(segas32_state, system32_paletteram[0])
12261237   AM_RANGE(0x610000, 0x61007f) AM_MIRROR(0x0eff80) AM_READWRITE(system32_mixer_r, system32_mixer_w)
12271238   AM_RANGE(0x700000, 0x701fff) AM_MIRROR(0x0fe000) AM_READWRITE(shared_ram_16_r, shared_ram_16_w)
12281239   AM_RANGE(0xc00000, 0xc0001f) AM_MIRROR(0x0fff80) AM_READWRITE(io_chip_r, io_chip_w)
r10427r10428
12381249   ADDRESS_MAP_GLOBAL_MASK(0xffffff)
12391250   AM_RANGE(0x000000, 0x1fffff) AM_ROM
12401251   AM_RANGE(0x200000, 0x21ffff) AM_MIRROR(0x0e0000) AM_RAM
1241   AM_RANGE(0x300000, 0x31ffff) AM_MIRROR(0x0e0000) AM_READWRITE(multi32_videoram_r, multi32_videoram_w) AM_BASE((UINT32 **)&system32_videoram)
1242   AM_RANGE(0x400000, 0x41ffff) AM_MIRROR(0x0e0000) AM_READWRITE(multi32_spriteram_r, multi32_spriteram_w) AM_BASE((UINT32 **)&system32_spriteram)
1252   AM_RANGE(0x300000, 0x31ffff) AM_MIRROR(0x0e0000) AM_READWRITE(multi32_videoram_r, multi32_videoram_w) AM_BASE_MEMBER(segas32_state, system32_videoram)
1253   AM_RANGE(0x400000, 0x41ffff) AM_MIRROR(0x0e0000) AM_READWRITE(multi32_spriteram_r, multi32_spriteram_w) AM_BASE_MEMBER(segas32_state, system32_spriteram)
12431254   AM_RANGE(0x500000, 0x50000f) AM_MIRROR(0x0ffff0) AM_READWRITE(multi32_sprite_control_r, multi32_sprite_control_w)
1244   AM_RANGE(0x600000, 0x60ffff) AM_MIRROR(0x060000) AM_READWRITE(multi32_paletteram_0_r, multi32_paletteram_0_w) AM_BASE((UINT32 **)&system32_paletteram[0])
1255   AM_RANGE(0x600000, 0x60ffff) AM_MIRROR(0x060000) AM_READWRITE(multi32_paletteram_0_r, multi32_paletteram_0_w) AM_BASE_MEMBER(segas32_state, system32_paletteram[0])
12451256   AM_RANGE(0x610000, 0x61007f) AM_MIRROR(0x06ff80) AM_WRITE(multi32_mixer_0_w)
1246   AM_RANGE(0x680000, 0x68ffff) AM_MIRROR(0x060000) AM_READWRITE(multi32_paletteram_1_r, multi32_paletteram_1_w) AM_BASE((UINT32 **)&system32_paletteram[1])
1257   AM_RANGE(0x680000, 0x68ffff) AM_MIRROR(0x060000) AM_READWRITE(multi32_paletteram_1_r, multi32_paletteram_1_w) AM_BASE_MEMBER(segas32_state, system32_paletteram[1])
12471258   AM_RANGE(0x690000, 0x69007f) AM_MIRROR(0x06ff80) AM_WRITE(multi32_mixer_1_w)
12481259   AM_RANGE(0x700000, 0x701fff) AM_MIRROR(0x0fe000) AM_READWRITE(shared_ram_32_r, shared_ram_32_w)
12491260   AM_RANGE(0xc00000, 0xc0001f) AM_MIRROR(0x07ff80) AM_READWRITE(io_chip_0_r, io_chip_0_w)
r10427r10428
12681279   AM_RANGE(0xa000, 0xbfff) AM_ROMBANK("bank1")
12691280   AM_RANGE(0xc000, 0xc00f) AM_MIRROR(0x0ff0) AM_DEVWRITE("rfsnd", rf5c68_w)
12701281   AM_RANGE(0xd000, 0xdfff) AM_DEVREADWRITE("rfsnd", rf5c68_mem_r, rf5c68_mem_w)
1271   AM_RANGE(0xe000, 0xffff) AM_RAM AM_BASE(&z80_shared_ram)
1282   AM_RANGE(0xe000, 0xffff) AM_RAM AM_BASE_MEMBER(segas32_state, z80_shared_ram)
12721283ADDRESS_MAP_END
12731284
12741285static ADDRESS_MAP_START( system32_sound_portmap, ADDRESS_SPACE_IO, 8 )
r10427r10428
12881299   AM_RANGE(0x0000, 0x9fff) AM_ROM AM_REGION("soundcpu", 0x100000)
12891300   AM_RANGE(0xa000, 0xbfff) AM_ROMBANK("bank1")
12901301   AM_RANGE(0xc000, 0xdfff) AM_DEVREADWRITE("sega", multipcm_r, multipcm_w)
1291   AM_RANGE(0xe000, 0xffff) AM_RAM AM_BASE(&z80_shared_ram)
1302   AM_RANGE(0xe000, 0xffff) AM_RAM AM_BASE_MEMBER(segas32_state, z80_shared_ram)
12921303ADDRESS_MAP_END
12931304
12941305static ADDRESS_MAP_START( multi32_sound_portmap, ADDRESS_SPACE_IO, 8 )
r10427r10428
13121323
13131324static ADDRESS_MAP_START( ga2_v25_map, ADDRESS_SPACE_PROGRAM, 8 )
13141325   AM_RANGE(0x00000, 0x0ffff) AM_ROM AM_REGION("mcu", 0)
1315   AM_RANGE(0x10000, 0x1ffff) AM_RAM AM_BASE(&ga2_dpram)
1326   AM_RANGE(0x10000, 0x1ffff) AM_RAM AM_BASE_MEMBER(segas32_state, ga2_dpram)
13161327   AM_RANGE(0xf0000, 0xfffff) AM_ROM AM_REGION("mcu", 0)
13171328ADDRESS_MAP_END
13181329
r10427r10428
21532164
21542165// Both arescue and f1en appear to use an identical shared RAM system.
21552166
2156static UINT16* dual_pcb_comms;
21572167
21582168static WRITE16_HANDLER( dual_pcb_comms_w )
21592169{
2160   COMBINE_DATA(&dual_pcb_comms[offset]);
2170   segas32_state *state = space->machine->driver_data<segas32_state>();
2171   COMBINE_DATA(&state->dual_pcb_comms[offset]);
21612172}
21622173
21632174static READ16_HANDLER( dual_pcb_comms_r )
21642175{
2165   return dual_pcb_comms[offset];
2176   segas32_state *state = space->machine->driver_data<segas32_state>();
2177   return state->dual_pcb_comms[offset];
21662178}
21672179
21682180
r10427r10428
21832195 *
21842196 *************************************/
21852197
2186static MACHINE_CONFIG_START( system32, driver_device )
2198static MACHINE_CONFIG_START( system32, segas32_state )
21872199
21882200   /* basic machine hardware */
21892201   MCFG_CPU_ADD("maincpu", V60, MASTER_CLOCK/2)
r10427r10428
22432255MACHINE_CONFIG_END
22442256
22452257
2246static MACHINE_CONFIG_START( multi32, driver_device )
2258static MACHINE_CONFIG_START( multi32, segas32_state )
22472259
22482260   /* basic machine hardware */
22492261   MCFG_CPU_ADD("maincpu", V70, MULTI32_CLOCK/2)
r10427r10428
38073819 *
38083820 *************************************/
38093821
3810static void segas32_common_init(read16_space_func custom_r, write16_space_func custom_w)
3822static void segas32_common_init(running_machine *machine, read16_space_func custom_r, write16_space_func custom_w)
38113823{
3824   segas32_state *state = machine->driver_data<segas32_state>();
38123825   /* reset the custom handlers and other pointers */
3813   custom_io_r[0] = custom_r;
3814   custom_io_w[0] = custom_w;
3826   state->custom_io_r[0] = custom_r;
3827   state->custom_io_w[0] = custom_w;
38153828   system32_prot_vblank = NULL;
3816   segas32_sw1_output = NULL;
3817   segas32_sw2_output = NULL;
3818   segas32_sw3_output = NULL;
3829   state->sw1_output = NULL;
3830   state->sw2_output = NULL;
3831   state->sw3_output = NULL;
38193832}
38203833
38213834
r10427r10428
40034016
40044017static DRIVER_INIT( alien3 )
40054018{
4006   segas32_common_init(analog_custom_io_r, analog_custom_io_w);
4007   segas32_sw1_output = alien3_sw1_output;
4019   segas32_state *state = machine->driver_data<segas32_state>();
4020   segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w);
4021   state->sw1_output = alien3_sw1_output;
40084022}
40094023
40104024static READ16_HANDLER( arescue_handshake_r )
r10427r10428
40194033
40204034static DRIVER_INIT( arescue )
40214035{
4022   segas32_common_init(analog_custom_io_r, analog_custom_io_w);
4036   segas32_state *state = machine->driver_data<segas32_state>();
4037   segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w);
40234038   memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa00000, 0xa00007, 0, 0, arescue_dsp_r, arescue_dsp_w);
40244039
4025   dual_pcb_comms = auto_alloc_array(machine, UINT16, 0x1000/2);
4040   state->dual_pcb_comms = auto_alloc_array(machine, UINT16, 0x1000/2);
40264041   memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x810000, 0x810fff, 0, 0, dual_pcb_comms_r, dual_pcb_comms_w);
40274042   memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x818000, 0x818003, 0, 0, dual_pcb_masterslave);
40284043
40294044   memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x810000, 0x810001, 0, 0, arescue_handshake_r);
40304045   memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x81000e, 0x81000f, 0, 0, arescue_slavebusy_r);
40314046
4032   segas32_sw1_output = arescue_sw1_output;
4047   state->sw1_output = arescue_sw1_output;
40334048}
40344049
40354050
40364051static DRIVER_INIT( arabfgt )
40374052{
4038   segas32_common_init(extra_custom_io_r, NULL);
4053   segas32_common_init(machine, extra_custom_io_r, NULL);
40394054
40404055   /* install protection handlers */
40414056   memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa00100, 0xa0011f, 0, 0, arf_wakeup_protection_r);
r10427r10428
40454060
40464061static DRIVER_INIT( brival )
40474062{
4048   segas32_common_init(extra_custom_io_r, NULL);
4063   segas32_state *state = machine->driver_data<segas32_state>();
4064   segas32_common_init(machine, extra_custom_io_r, NULL);
40494065
40504066   /* install protection handlers */
4051   system32_protram = auto_alloc_array(machine, UINT16, 0x1000/2);
4067   state->system32_protram = auto_alloc_array(machine, UINT16, 0x1000/2);
40524068   memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x20ba00, 0x20ba07, 0, 0, brival_protection_r);
40534069   memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa00000, 0xa00fff, 0, 0, brival_protection_w);
40544070}
r10427r10428
40564072
40574073static DRIVER_INIT( darkedge )
40584074{
4059   segas32_common_init(extra_custom_io_r, NULL);
4075   segas32_common_init(machine, extra_custom_io_r, NULL);
40604076
40614077   /* install protection handlers */
40624078   memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa00000, 0xa7ffff, 0, 0, darkedge_protection_r, darkedge_protection_w);
r10427r10428
40654081
40664082static DRIVER_INIT( dbzvrvs )
40674083{
4068   segas32_common_init(NULL, NULL);
4084   segas32_common_init(machine, NULL, NULL);
40694085
40704086   /* install protection handlers */
40714087   memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa00000, 0xa7ffff, 0, 0, dbzvrvs_protection_r, dbzvrvs_protection_w);
r10427r10428
40804096
40814097static DRIVER_INIT( f1en )
40824098{
4083   segas32_common_init(analog_custom_io_r, analog_custom_io_w);
4099   segas32_state *state = machine->driver_data<segas32_state>();
4100   segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w);
40844101
4085   dual_pcb_comms = auto_alloc_array(machine, UINT16, 0x1000/2);
4102   state->dual_pcb_comms = auto_alloc_array(machine, UINT16, 0x1000/2);
40864103   memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x810000, 0x810fff, 0, 0, dual_pcb_comms_r, dual_pcb_comms_w);
40874104   memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x818000, 0x818003, 0, 0, dual_pcb_masterslave);
40884105
40894106   memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x810048, 0x810049, 0, 0, f1en_comms_echo_w);
40904107
4091   segas32_sw1_output = radm_sw1_output;
4108   state->sw1_output = radm_sw1_output;
40924109}
40934110
40944111
40954112static DRIVER_INIT( f1lap )
40964113{
4097   segas32_common_init(analog_custom_io_r, analog_custom_io_w);
4098   segas32_sw1_output = f1lap_sw1_output;
4114   segas32_state *state = machine->driver_data<segas32_state>();
4115   segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w);
4116   state->sw1_output = f1lap_sw1_output;
40994117}
41004118
41014119
41024120static DRIVER_INIT( ga2 )
41034121{
4104   segas32_common_init(extra_custom_io_r, NULL);
4122   segas32_common_init(machine, extra_custom_io_r, NULL);
41054123
41064124   decrypt_ga2_protrom(machine);
41074125   memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa00000, 0xa00fff, 0, 0, ga2_dpram_r, ga2_dpram_w);
r10427r10428
41104128
41114129static DRIVER_INIT( harddunk )
41124130{
4113   segas32_common_init(extra_custom_io_r, NULL);
4114   segas32_sw1_output = harddunk_sw1_output;
4115   segas32_sw2_output = harddunk_sw2_output;
4116   segas32_sw3_output = harddunk_sw3_output;
4131   segas32_state *state = machine->driver_data<segas32_state>();
4132   segas32_common_init(machine, extra_custom_io_r, NULL);
4133   state->sw1_output = harddunk_sw1_output;
4134   state->sw2_output = harddunk_sw2_output;
4135   state->sw3_output = harddunk_sw3_output;
41174136}
41184137
41194138
41204139static DRIVER_INIT( holo )
41214140{
4122   segas32_common_init(NULL, NULL);
4141   segas32_common_init(machine, NULL, NULL);
41234142}
41244143
41254144
41264145static DRIVER_INIT( jpark )
41274146{
4147   segas32_state *state = machine->driver_data<segas32_state>();
41284148   /* Temp. Patch until we emulate the 'Drive Board', thanks to Malice */
41294149   UINT16 *pROM = (UINT16 *)machine->region("maincpu")->base();
41304150
4131   segas32_common_init(analog_custom_io_r, analog_custom_io_w);
4151   segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w);
41324152
41334153   pROM[0xC15A8/2] = 0xCD70;
41344154   pROM[0xC15AA/2] = 0xD8CD;
41354155
4136   segas32_sw1_output = jpark_sw1_output;
4156   state->sw1_output = jpark_sw1_output;
41374157}
41384158
41394159
41404160static DRIVER_INIT( orunners )
41414161{
4142   segas32_common_init(analog_custom_io_r, orunners_custom_io_w);
4143   segas32_sw1_output = orunners_sw1_output;
4144   segas32_sw2_output = orunners_sw2_output;
4162   segas32_state *state = machine->driver_data<segas32_state>();
4163   segas32_common_init(machine, analog_custom_io_r, orunners_custom_io_w);
4164   state->sw1_output = orunners_sw1_output;
4165   state->sw2_output = orunners_sw2_output;
41454166}
41464167
41474168
41484169static DRIVER_INIT( radm )
41494170{
4150   segas32_common_init(analog_custom_io_r, analog_custom_io_w);
4151   segas32_sw1_output = radm_sw1_output;
4152   segas32_sw2_output = radm_sw2_output;
4171   segas32_state *state = machine->driver_data<segas32_state>();
4172   segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w);
4173   state->sw1_output = radm_sw1_output;
4174   state->sw2_output = radm_sw2_output;
41534175}
41544176
41554177
41564178static DRIVER_INIT( radr )
41574179{
4158   segas32_common_init(analog_custom_io_r, analog_custom_io_w);
4159   segas32_sw1_output = radm_sw1_output;
4160   segas32_sw2_output = radr_sw2_output;
4180   segas32_state *state = machine->driver_data<segas32_state>();
4181   segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w);
4182   state->sw1_output = radm_sw1_output;
4183   state->sw2_output = radr_sw2_output;
41614184}
41624185
41634186
41644187static DRIVER_INIT( scross )
41654188{
4189   segas32_state *state = machine->driver_data<segas32_state>();
41664190   multipcm_device *multipcm = machine->device<multipcm_device>("sega");
4167   segas32_common_init(analog_custom_io_r, analog_custom_io_w);
4191   segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w);
41684192   memory_install_write8_device_handler(cputag_get_address_space(machine, "soundcpu", ADDRESS_SPACE_PROGRAM), multipcm, 0xb0, 0xbf, 0, 0, scross_bank_w);
41694193
4170   segas32_sw1_output = scross_sw1_output;
4171   segas32_sw2_output = scross_sw2_output;
4194   state->sw1_output = scross_sw1_output;
4195   state->sw2_output = scross_sw2_output;
41724196}
41734197
41744198
41754199static DRIVER_INIT( slipstrm )
41764200{
4177   segas32_common_init(analog_custom_io_r, analog_custom_io_w);
4201   segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w);
41784202}
41794203
41804204
41814205static DRIVER_INIT( sonic )
41824206{
4183   segas32_common_init(sonic_custom_io_r, sonic_custom_io_w);
4207   segas32_common_init(machine, sonic_custom_io_r, sonic_custom_io_w);
41844208
41854209   /* install protection handlers */
41864210   memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x20E5C4, 0x20E5C5, 0, 0, sonic_level_load_protection);
r10427r10428
41894213
41904214static DRIVER_INIT( sonicp )
41914215{
4192   segas32_common_init(sonic_custom_io_r, sonic_custom_io_w);
4216   segas32_common_init(machine, sonic_custom_io_r, sonic_custom_io_w);
41934217}
41944218
41954219
41964220static DRIVER_INIT( spidman )
41974221{
4198   segas32_common_init(extra_custom_io_r, NULL);
4222   segas32_common_init(machine, extra_custom_io_r, NULL);
41994223}
42004224
42014225
42024226static DRIVER_INIT( svf )
42034227{
4204   segas32_common_init(NULL, NULL);
4228   segas32_common_init(machine, NULL, NULL);
42054229}
42064230
42074231
42084232static DRIVER_INIT( jleague )
42094233{
4210   segas32_common_init(NULL, NULL);
4234   segas32_common_init(machine, NULL, NULL);
42114235   memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x20F700, 0x20F705, 0, 0, jleague_protection_w);
42124236}
42134237
42144238
42154239static DRIVER_INIT( titlef )
42164240{
4217   segas32_common_init(NULL, NULL);
4218   segas32_sw1_output = titlef_sw1_output;
4219   segas32_sw2_output = titlef_sw2_output;
4241   segas32_state *state = machine->driver_data<segas32_state>();
4242   segas32_common_init(machine, NULL, NULL);
4243   state->sw1_output = titlef_sw1_output;
4244   state->sw2_output = titlef_sw2_output;
42204245}
42214246
42224247
src/mame/drivers/djmain.c
r10427r10428
7171#include "video/konicdev.h"
7272#include "includes/djmain.h"
7373
74static int sndram_bank;
75static UINT8 *sndram;
7674
77static int turntable_select;
78static UINT8 turntable_last_pos[2];
79static UINT16 turntable_pos[2];
8075
81static UINT8 pending_vb_int;
82static UINT16 v_ctrl;
83static UINT32 obj_regs[0xa0/4];
8476
85static const UINT8 *ide_user_password;
86static const UINT8 *ide_master_password;
8777
88#define DISABLE_VB_INT   (!(v_ctrl & 0x8000))
78#define DISABLE_VB_INT   (!(state->v_ctrl & 0x8000))
8979
9080
9181
r10427r10428
114104
115105static void sndram_set_bank(running_machine *machine)
116106{
117   sndram = machine->region("shared")->base() + 0x80000 * sndram_bank;
107   djmain_state *state = machine->driver_data<djmain_state>();
108   state->sndram = machine->region("shared")->base() + 0x80000 * state->sndram_bank;
118109}
119110
120111static WRITE32_HANDLER( sndram_bank_w )
121112{
113   djmain_state *state = space->machine->driver_data<djmain_state>();
122114   if (ACCESSING_BITS_16_31)
123115   {
124      sndram_bank = (data >> 16) & 0x1f;
116      state->sndram_bank = (data >> 16) & 0x1f;
125117      sndram_set_bank(space->machine);
126118   }
127119}
128120
129121static READ32_HANDLER( sndram_r )
130122{
123   djmain_state *state = space->machine->driver_data<djmain_state>();
131124   UINT32 data = 0;
132125
133126   if (ACCESSING_BITS_24_31)
134      data |= sndram[offset * 4] << 24;
127      data |= state->sndram[offset * 4] << 24;
135128
136129   if (ACCESSING_BITS_16_23)
137      data |= sndram[offset * 4 + 1] << 16;
130      data |= state->sndram[offset * 4 + 1] << 16;
138131
139132   if (ACCESSING_BITS_8_15)
140      data |= sndram[offset * 4 + 2] << 8;
133      data |= state->sndram[offset * 4 + 2] << 8;
141134
142135   if (ACCESSING_BITS_0_7)
143      data |= sndram[offset * 4 + 3];
136      data |= state->sndram[offset * 4 + 3];
144137
145138   return data;
146139}
147140
148141static WRITE32_HANDLER( sndram_w )
149142{
143   djmain_state *state = space->machine->driver_data<djmain_state>();
150144   if (ACCESSING_BITS_24_31)
151      sndram[offset * 4] = data >> 24;
145      state->sndram[offset * 4] = data >> 24;
152146
153147   if (ACCESSING_BITS_16_23)
154      sndram[offset * 4 + 1] = data >> 16;
148      state->sndram[offset * 4 + 1] = data >> 16;
155149
156150   if (ACCESSING_BITS_8_15)
157      sndram[offset * 4 + 2] = data >> 8;
151      state->sndram[offset * 4 + 2] = data >> 8;
158152
159153   if (ACCESSING_BITS_0_7)
160      sndram[offset * 4 + 3] = data;
154      state->sndram[offset * 4 + 3] = data;
161155}
162156
163157
r10427r10428
188182
189183static READ32_HANDLER( obj_ctrl_r )
190184{
191   // read obj_regs[0x0c/4]: unknown
192   // read obj_regs[0x24/4]: unknown
185   djmain_state *state = space->machine->driver_data<djmain_state>();
186   // read state->obj_regs[0x0c/4]: unknown
187   // read state->obj_regs[0x24/4]: unknown
193188
194   return obj_regs[offset];
189   return state->obj_regs[offset];
195190}
196191
197192static WRITE32_HANDLER( obj_ctrl_w )
198193{
199   // write obj_regs[0x28/4]: bank for rom readthrough
194   djmain_state *state = space->machine->driver_data<djmain_state>();
195   // write state->obj_regs[0x28/4]: bank for rom readthrough
200196
201   COMBINE_DATA(&obj_regs[offset]);
197   COMBINE_DATA(&state->obj_regs[offset]);
202198}
203199
204200static READ32_HANDLER( obj_rom_r )
205201{
202   djmain_state *state = space->machine->driver_data<djmain_state>();
206203   UINT8 *mem8 = space->machine->region("gfx1")->base();
207   int bank = obj_regs[0x28/4] >> 16;
204   int bank = state->obj_regs[0x28/4] >> 16;
208205
209206   offset += bank * 0x200;
210207   offset *= 4;
r10427r10428
223220
224221static WRITE32_HANDLER( v_ctrl_w )
225222{
223   djmain_state *state = space->machine->driver_data<djmain_state>();
226224   if (ACCESSING_BITS_16_31)
227225   {
228226      data >>= 16;
229227      mem_mask >>= 16;
230      COMBINE_DATA(&v_ctrl);
228      COMBINE_DATA(&state->v_ctrl);
231229
232      if (pending_vb_int && !DISABLE_VB_INT)
230      if (state->pending_vb_int && !DISABLE_VB_INT)
233231      {
234         pending_vb_int = 0;
232         state->pending_vb_int = 0;
235233         cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_4, HOLD_LINE);
236234      }
237235   }
r10427r10428
239237
240238static READ32_HANDLER( v_rom_r )
241239{
240   djmain_state *state = space->machine->driver_data<djmain_state>();
242241   device_t *k056832 = space->machine->device("k056832");
243242   UINT8 *mem8 = space->machine->region("gfx2")->base();
244243   int bank = k056832_word_r(k056832, 0x34/2, 0xffff);
r10427r10428
250249
251250   offset += bank * 0x800 * 4;
252251
253   if (v_ctrl & 0x020)
252   if (state->v_ctrl & 0x020)
254253      offset += 0x800 * 2;
255254
256255   return mem8[offset] * 0x01010000;
r10427r10428
273272
274273static READ32_HANDLER( turntable_r )
275274{
275   djmain_state *state = space->machine->driver_data<djmain_state>();
276276   UINT32 result = 0;
277277   static const char *const ttnames[] = { "TT1", "TT2" };
278278
r10427r10428
281281      UINT8 pos;
282282      int delta;
283283
284      pos = input_port_read_safe(space->machine, ttnames[turntable_select], 0);
285      delta = pos - turntable_last_pos[turntable_select];
284      pos = input_port_read_safe(space->machine, ttnames[state->turntable_select], 0);
285      delta = pos - state->turntable_last_pos[state->turntable_select];
286286      if (delta < -128)
287287         delta += 256;
288288      if (delta > 128)
289289         delta -= 256;
290290
291      turntable_pos[turntable_select] += delta * 70;
292      turntable_last_pos[turntable_select] = pos;
291      state->turntable_pos[state->turntable_select] += delta * 70;
292      state->turntable_last_pos[state->turntable_select] = pos;
293293
294      result |= turntable_pos[turntable_select] & 0xff00;
294      result |= state->turntable_pos[state->turntable_select] & 0xff00;
295295   }
296296
297297   return result;
r10427r10428
299299
300300static WRITE32_HANDLER( turntable_select_w )
301301{
302   djmain_state *state = space->machine->driver_data<djmain_state>();
302303   if (ACCESSING_BITS_16_23)
303      turntable_select = (data >> 19) & 1;
304      state->turntable_select = (data >> 19) & 1;
304305}
305306
306307
r10427r10428
427428
428429static INTERRUPT_GEN( vb_interrupt )
429430{
430   pending_vb_int = 0;
431   djmain_state *state = device->machine->driver_data<djmain_state>();
432   state->pending_vb_int = 0;
431433
432434   if (DISABLE_VB_INT)
433435   {
434      pending_vb_int = 1;
436      state->pending_vb_int = 1;
435437      return;
436438   }
437439
r10427r10428
481483   AM_RANGE(0x5d6000, 0x5d6003) AM_WRITE(sndram_bank_w)               // SOUND RAM bank
482484   AM_RANGE(0x5e0000, 0x5e0003) AM_READWRITE(turntable_r, turntable_select_w)      // input port control (turn tables)
483485   AM_RANGE(0x600000, 0x601fff) AM_READ(v_rom_r)                  // VIDEO ROM readthrough (for POST)
484   AM_RANGE(0x801000, 0x8017ff) AM_RAM AM_BASE(&djmain_obj_ram)            // OBJECT RAM
486   AM_RANGE(0x801000, 0x8017ff) AM_RAM AM_BASE_MEMBER(djmain_state, obj_ram)            // OBJECT RAM
485487   AM_RANGE(0x802000, 0x802fff) AM_WRITE(unknown802000_w)               // ??
486488   AM_RANGE(0x803000, 0x80309f) AM_READWRITE(obj_ctrl_r, obj_ctrl_w)         // OBJECT REGS
487489   AM_RANGE(0x803800, 0x803fff) AM_READ(obj_rom_r)                  // OBJECT ROM readthrough (for POST)
r10427r10428
14301432
14311433static MACHINE_START( djmain )
14321434{
1435   djmain_state *state = machine->driver_data<djmain_state>();
14331436   device_t *ide = machine->device("ide");
14341437
1435   if (ide != NULL && ide_master_password != NULL)
1436      ide_set_master_password(ide, ide_master_password);
1437   if (ide != NULL && ide_user_password != NULL)
1438      ide_set_user_password(ide, ide_user_password);
1438   if (ide != NULL && state->ide_master_password != NULL)
1439      ide_set_master_password(ide, state->ide_master_password);
1440   if (ide != NULL && state->ide_user_password != NULL)
1441      ide_set_user_password(ide, state->ide_user_password);
14391442
1440   state_save_register_global(machine, sndram_bank);
1441   state_save_register_global(machine, pending_vb_int);
1442   state_save_register_global(machine, v_ctrl);
1443   state_save_register_global_array(machine, obj_regs);
1443   state_save_register_global(machine, state->sndram_bank);
1444   state_save_register_global(machine, state->pending_vb_int);
1445   state_save_register_global(machine, state->v_ctrl);
1446   state_save_register_global_array(machine, state->obj_regs);
14441447
14451448   machine->state().register_postload(djmain_postload, NULL);
14461449}
r10427r10428
14481451
14491452static MACHINE_RESET( djmain )
14501453{
1454   djmain_state *state = machine->driver_data<djmain_state>();
14511455   /* reset sound ram bank */
1452   sndram_bank = 0;
1456   state->sndram_bank = 0;
14531457   sndram_set_bank(machine);
14541458
14551459   /* reset the IDE controller */
r10427r10428
14781482   djmain_tile_callback, "none"
14791483};
14801484
1481static MACHINE_CONFIG_START( djmain, driver_device )
1485static MACHINE_CONFIG_START( djmain, djmain_state )
14821486
14831487   /* basic machine hardware */
14841488   // popn3 works 9.6 MHz or slower in some songs */
r10427r10428
20322036
20332037static DRIVER_INIT( beatmania )
20342038{
2035   ide_master_password = NULL;
2036   ide_user_password = NULL;
2039   djmain_state *state = machine->driver_data<djmain_state>();
2040   state->ide_master_password = NULL;
2041   state->ide_user_password = NULL;
20372042}
20382043
20392044static const UINT8 beatmania_master_password[2 + 32] =
r10427r10428
20472052
20482053static DRIVER_INIT( hmcompmx )
20492054{
2055   djmain_state *state = machine->driver_data<djmain_state>();
20502056   static const UINT8 hmcompmx_user_password[2 + 32] =
20512057   {
20522058      0x00, 0x00,
r10427r10428
20582064
20592065   DRIVER_INIT_CALL(beatmania);
20602066
2061   ide_master_password = beatmania_master_password;
2062   ide_user_password = hmcompmx_user_password;
2067   state->ide_master_password = beatmania_master_password;
2068   state->ide_user_password = hmcompmx_user_password;
20632069}
20642070
20652071static DRIVER_INIT( bm4thmix )
20662072{
2073   djmain_state *state = machine->driver_data<djmain_state>();
20672074   static const UINT8 bm4thmix_user_password[2 + 32] =
20682075   {
20692076      0x00, 0x00,
r10427r10428
20752082
20762083   DRIVER_INIT_CALL(beatmania);
20772084
2078   ide_user_password = bm4thmix_user_password;
2085   state->ide_user_password = bm4thmix_user_password;
20792086}
20802087
20812088static DRIVER_INIT( bm5thmix )
20822089{
2090   djmain_state *state = machine->driver_data<djmain_state>();
20832091   static const UINT8 bm5thmix_user_password[2 + 32] =
20842092   {
20852093      0x00, 0x00,
r10427r10428
20912099
20922100   DRIVER_INIT_CALL(beatmania);
20932101
2094   ide_master_password = beatmania_master_password;
2095   ide_user_password = bm5thmix_user_password;
2102   state->ide_master_password = beatmania_master_password;
2103   state->ide_user_password = bm5thmix_user_password;
20962104}
20972105
20982106static DRIVER_INIT( bmclubmx )
20992107{
2108   djmain_state *state = machine->driver_data<djmain_state>();
21002109   static const UINT8 bmclubmx_user_password[2 + 32] =
21012110   {
21022111      0x00, 0x00,
r10427r10428
21082117
21092118   DRIVER_INIT_CALL(beatmania);
21102119
2111   ide_master_password = beatmania_master_password;
2112   ide_user_password = bmclubmx_user_password;
2120   state->ide_master_password = beatmania_master_password;
2121   state->ide_user_password = bmclubmx_user_password;
21132122}
21142123
21152124
21162125static DRIVER_INIT( bmcompm2 )
21172126{
2127   djmain_state *state = machine->driver_data<djmain_state>();
21182128   static const UINT8 bmcompm2_user_password[2 + 32] =
21192129   {
21202130      0x00, 0x00,
r10427r10428
21262136
21272137   DRIVER_INIT_CALL(beatmania);
21282138
2129   ide_master_password = beatmania_master_password;
2130   ide_user_password = bmcompm2_user_password;
2139   state->ide_master_password = beatmania_master_password;
2140   state->ide_user_password = bmcompm2_user_password;
21312141}
21322142
21332143static DRIVER_INIT( hmcompm2 )
21342144{
2145   djmain_state *state = machine->driver_data<djmain_state>();
21352146   static const UINT8 hmcompm2_user_password[2 + 32] =
21362147   {
21372148      0x00, 0x00,
r10427r10428
21432154
21442155   DRIVER_INIT_CALL(beatmania);
21452156
2146   ide_master_password = beatmania_master_password;
2147   ide_user_password = hmcompm2_user_password;
2157   state->ide_master_password = beatmania_master_password;
2158   state->ide_user_password = hmcompm2_user_password;
21482159}
21492160
21502161static DRIVER_INIT( bmdct )
21512162{
2163   djmain_state *state = machine->driver_data<djmain_state>();
21522164   static const UINT8 bmdct_user_password[2 + 32] =
21532165   {
21542166      0x00, 0x00,
r10427r10428
21602172
21612173   DRIVER_INIT_CALL(beatmania);
21622174
2163   ide_master_password = beatmania_master_password;
2164   ide_user_password = bmdct_user_password;
2175   state->ide_master_password = beatmania_master_password;
2176   state->ide_user_password = bmdct_user_password;
21652177}
21662178
21672179static DRIVER_INIT( bmcorerm )
21682180{
2181   djmain_state *state = machine->driver_data<djmain_state>();
21692182   static const UINT8 bmcorerm_user_password[2 + 32] =
21702183   {
21712184      0x00, 0x00,
r10427r10428
21772190
21782191   DRIVER_INIT_CALL(beatmania);
21792192
2180   ide_master_password = beatmania_master_password;
2181   ide_user_password = bmcorerm_user_password;
2193   state->ide_master_password = beatmania_master_password;
2194   state->ide_user_password = bmcorerm_user_password;
21822195}
21832196
21842197static DRIVER_INIT( bm6thmix )
21852198{
2199   djmain_state *state = machine->driver_data<djmain_state>();
21862200   static const UINT8 bm6thmix_user_password[2 + 32] =
21872201   {
21882202      0x00, 0x00,
r10427r10428
21942208
21952209   DRIVER_INIT_CALL(beatmania);
21962210
2197   ide_master_password = beatmania_master_password;
2198   ide_user_password = bm6thmix_user_password;
2211   state->ide_master_password = beatmania_master_password;
2212   state->ide_user_password = bm6thmix_user_password;
21992213}
22002214
22012215static DRIVER_INIT( bm7thmix )
22022216{
2217   djmain_state *state = machine->driver_data<djmain_state>();
22032218   static const UINT8 bm7thmix_user_password[2 + 32] =
22042219   {
22052220      0x00, 0x00,
r10427r10428
22112226
22122227   DRIVER_INIT_CALL(beatmania);
22132228
2214   ide_master_password = beatmania_master_password;
2215   ide_user_password = bm7thmix_user_password;
2229   state->ide_master_password = beatmania_master_password;
2230   state->ide_user_password = bm7thmix_user_password;
22162231}
22172232
22182233static DRIVER_INIT( bmfinal )
22192234{
2235   djmain_state *state = machine->driver_data<djmain_state>();
22202236   static const UINT8 bmfinal_user_password[2 + 32] =
22212237   {
22222238      0x00, 0x00,
r10427r10428
22282244
22292245   DRIVER_INIT_CALL(beatmania);
22302246
2231   ide_master_password = beatmania_master_password;
2232   ide_user_password = bmfinal_user_password;
2247   state->ide_master_password = beatmania_master_password;
2248   state->ide_user_password = bmfinal_user_password;
22332249}
22342250
22352251
src/mame/drivers/asterix.c
r10427r10428
134134}
135135#endif
136136
137static UINT16 prot[2];
138
139137static WRITE16_HANDLER( protection_w )
140138{
141   COMBINE_DATA(prot + offset);
139   asterix_state *state = space->machine->driver_data<asterix_state>();
140   COMBINE_DATA(state->prot + offset);
142141
143142   if (offset == 1)
144143   {
145      UINT32 cmd = (prot[0] << 16) | prot[1];
144      UINT32 cmd = (state->prot[0] << 16) | state->prot[1];
146145      switch (cmd >> 24)
147146      {
148147      case 0x64:
src/mame/drivers/suprloco.c
r10427r10428
3737   AM_RANGE(0xe001, 0xe001) AM_READ_PORT("DSW2")
3838   AM_RANGE(0xe800, 0xe800) AM_WRITE(suprloco_soundport_w)
3939   AM_RANGE(0xe801, 0xe801) AM_READWRITE(suprloco_control_r, suprloco_control_w)
40   AM_RANGE(0xf000, 0xf6ff) AM_RAM_WRITE(suprloco_videoram_w) AM_BASE(&suprloco_videoram)
40   AM_RANGE(0xf000, 0xf6ff) AM_RAM_WRITE(suprloco_videoram_w) AM_BASE_MEMBER(suprloco_state, videoram)
4141   AM_RANGE(0xf700, 0xf7df) AM_RAM /* unused */
42   AM_RANGE(0xf7e0, 0xf7ff) AM_RAM_WRITE(suprloco_scrollram_w) AM_BASE(&suprloco_scrollram)
42   AM_RANGE(0xf7e0, 0xf7ff) AM_RAM_WRITE(suprloco_scrollram_w) AM_BASE_MEMBER(suprloco_state, scrollram)
4343   AM_RANGE(0xf800, 0xffff) AM_RAM
4444ADDRESS_MAP_END
4545
r10427r10428
152152
153153
154154
155static MACHINE_CONFIG_START( suprloco, driver_device )
155static MACHINE_CONFIG_START( suprloco, suprloco_state )
156156
157157   /* basic machine hardware */
158158   MCFG_CPU_ADD("maincpu", Z80, 4000000)   /* 4 MHz (?) */
src/mame/drivers/destroyr.c
r10427r10428
188188
189189static WRITE8_HANDLER( destroyr_output_w )
190190{
191   offset &= 0x0f;
192
193   switch (offset)
191   if (offset & 8) destroyr_misc_w(space, 8, data);
192   
193   else switch (offset & 7)
194194   {
195195   case 0:
196196      set_led_status(space->machine, 0, data & 1);
r10427r10428
216216   case 7:
217217      /* bit 0 => low explosion */
218218      break;
219   case 8:
220      destroyr_misc_w(space, offset, data);
221      break;
222   default:
223      logerror("unmapped output port %d\n", offset);
224      break;
225219   }
226220}
227221
r10427r10428
262256   AM_RANGE(0x2000, 0x2fff) AM_READ_PORT("IN2")
263257   AM_RANGE(0x3000, 0x30ff) AM_MIRROR(0xf00) AM_WRITEONLY AM_BASE_MEMBER(destroyr_state, alpha_num_ram)
264258   AM_RANGE(0x4000, 0x401f) AM_MIRROR(0xfe0) AM_WRITEONLY AM_BASE_MEMBER(destroyr_state, major_obj_ram)
265   AM_RANGE(0x5000, 0x5000) AM_MIRROR(0xf80) AM_WRITE(destroyr_cursor_load_w)
266   AM_RANGE(0x5001, 0x5001) AM_MIRROR(0xf80) AM_WRITE(destroyr_interrupt_ack_w)
267   AM_RANGE(0x5002, 0x5007) AM_MIRROR(0xf80) AM_WRITEONLY AM_BASE_MEMBER(destroyr_state, minor_obj_ram)
259   AM_RANGE(0x5000, 0x5000) AM_MIRROR(0xff8) AM_WRITE(destroyr_cursor_load_w)
260   AM_RANGE(0x5001, 0x5001) AM_MIRROR(0xff8) AM_WRITE(destroyr_interrupt_ack_w)
261   AM_RANGE(0x5002, 0x5007) AM_MIRROR(0xff8) AM_WRITEONLY AM_BASE_MEMBER(destroyr_state, minor_obj_ram)
268262   AM_RANGE(0x6000, 0x6fff) AM_READ(destroyr_scanline_r)
269   AM_RANGE(0x7000, 0x77ff) AM_NOP            /* missing translation ROMs */
270   AM_RANGE(0x7800, 0x7fff) AM_ROM            /* program */
263   AM_RANGE(0x7000, 0x7fff) AM_ROM
271264ADDRESS_MAP_END
272265
273266
r10427r10428
306299   PORT_DIPSETTING( 0x04, "75 seconds" )
307300   PORT_DIPSETTING( 0x08, "100 seconds" )
308301   PORT_DIPSETTING( 0x0c, "125 seconds" )
309   PORT_DIPNAME( 0x30, 0x00, DEF_STR( Language ) ) PORT_DIPLOCATION("SW2:5,6") /* requires translation ROMs */
302   PORT_DIPNAME( 0x30, 0x00, DEF_STR( Language ) ) PORT_DIPLOCATION("SW2:5,6")
310303   PORT_DIPSETTING( 0x30, DEF_STR( German ) )
311304   PORT_DIPSETTING( 0x20, DEF_STR( French ) )
312305   PORT_DIPSETTING( 0x10, DEF_STR( Spanish ) )
r10427r10428
454447
455448   /* video hardware */
456449   MCFG_SCREEN_ADD("screen", RASTER)
457   MCFG_SCREEN_REFRESH_RATE(60)
450   MCFG_SCREEN_REFRESH_RATE(15750.0/262)
458451   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
459452   MCFG_SCREEN_SIZE(256, 262)
460453   MCFG_SCREEN_VISIBLE_AREA(0, 255, 0, 239)
r10427r10428
470463
471464ROM_START( destroyr )
472465   ROM_REGION( 0x8000, "maincpu", 0 )   /* program code */
466   ROM_LOAD( "language.rom",0x7000, 0x0800, NO_DUMP ) // optional add-on translation rom
473467   ROM_LOAD( "30146-01.c3", 0x7800, 0x0800, CRC(e560c712) SHA1(0505ab57eee5421b4ff4e87d14505e02b18fd54c) )
474468
475469   ROM_REGION( 0x0400, "gfx1", 0 )      /* alpha numerics */
r10427r10428
477471
478472   ROM_REGION( 0x0800, "gfx2", 0 )      /* minor objects */
479473   ROM_LOAD( "30132-01.f4", 0x0000, 0x0400, CRC(e09d3d55) SHA1(b26013397ef2cb32d0416ecb118387b9c2dffa9a) )
480   ROM_LOAD( "30132-01.k4", 0x0400, 0x0400, CRC(e09d3d55) SHA1(b26013397ef2cb32d0416ecb118387b9c2dffa9a) )
474   ROM_LOAD( "30132-01.k4", 0x0400, 0x0400, CRC(e09d3d55) SHA1(b26013397ef2cb32d0416ecb118387b9c2dffa9a) ) // identical to f4
481475
482476   ROM_REGION( 0x0400, "gfx3", 0 )      /* major objects */
483477   ROM_LOAD_NIB_HIGH( "30134-01.p8", 0x0000, 0x0400, CRC(6259e007) SHA1(049f5f7160305cb4f4b499dd113cb11eea73fc95) )
r10427r10428
486480   ROM_REGION( 0x0020, "gfx4", 0 )      /* waves */
487481   ROM_LOAD( "30136-01.k2", 0x0000, 0x0020, CRC(532c11b1) SHA1(18ab5369a3f2cfcc9a44f38fa8649524bea5b203) )
488482
489   ROM_REGION( 0x0100, "user1", 0 )   /* sync (unused) */
483   ROM_REGION( 0x0100, "user1", 0 )   /* sync (used for vsync/vblank signals, not hooked up yet) */
490484   ROM_LOAD( "30131-01.m1", 0x0000, 0x0100, CRC(b8094b4c) SHA1(82dc6799a19984f3b204ee3aeeb007e55afc8be3) )
491485ROM_END
492486
493487ROM_START( destroyr1 )
494488   ROM_REGION( 0x8000, "maincpu", 0 )   /* program code */
489   ROM_LOAD( "language.rom",0x7000, 0x0800, NO_DUMP ) // optional add-on translation rom
495490   ROM_LOAD_NIB_HIGH( "30142-01.f3", 0x7800, 0x0400, CRC(9e9a08d3) SHA1(eb31bab1537caf43ab8c3d23a6c9cc2009fcb98e) )
496491   ROM_LOAD_NIB_LOW ( "30141-01.e2", 0x7800, 0x0400, CRC(c924fbce) SHA1(53aa9a3c4c6e90fb94500ddfa6c2ae3076eee2ef) )
497492   ROM_LOAD_NIB_HIGH( "30144-01.j3", 0x7c00, 0x0400, CRC(0c7135c6) SHA1(6a0180353a0a6f34639dadc23179f6323aae8d62) )
r10427r10428
502497
503498   ROM_REGION( 0x0800, "gfx2", 0 )      /* minor objects */
504499   ROM_LOAD( "30132-01.f4", 0x0000, 0x0400, CRC(e09d3d55) SHA1(b26013397ef2cb32d0416ecb118387b9c2dffa9a) )
505   ROM_LOAD( "30132-01.k4", 0x0400, 0x0400, CRC(e09d3d55) SHA1(b26013397ef2cb32d0416ecb118387b9c2dffa9a) )
500   ROM_LOAD( "30132-01.k4", 0x0400, 0x0400, CRC(e09d3d55) SHA1(b26013397ef2cb32d0416ecb118387b9c2dffa9a) ) // identical to f4
506501
507502   ROM_REGION( 0x0400, "gfx3", 0 )      /* major objects */
508503   ROM_LOAD_NIB_HIGH( "30134-01.p8", 0x0000, 0x0400, CRC(6259e007) SHA1(049f5f7160305cb4f4b499dd113cb11eea73fc95) )
r10427r10428
511506   ROM_REGION( 0x0020, "gfx4", 0 )      /* waves */
512507   ROM_LOAD( "30136-01.k2", 0x0000, 0x0020, CRC(532c11b1) SHA1(18ab5369a3f2cfcc9a44f38fa8649524bea5b203) )
513508
514   ROM_REGION( 0x0100, "user1", 0 )   /* sync (unused) */
509   ROM_REGION( 0x0100, "user1", 0 )   /* sync (used for vsync/vblank signals, not hooked up yet) */
515510   ROM_LOAD( "30131-01.m1", 0x0000, 0x0100, CRC(b8094b4c) SHA1(82dc6799a19984f3b204ee3aeeb007e55afc8be3) )
516511ROM_END
517512
src/mame/drivers/vulgus.c
r10427r10428
6363   AM_RANGE(0xc003, 0xc003) AM_READ_PORT("DSW1")
6464   AM_RANGE(0xc004, 0xc004) AM_READ_PORT("DSW2")
6565   AM_RANGE(0xc800, 0xc800) AM_WRITE(soundlatch_w)
66   AM_RANGE(0xc802, 0xc803) AM_RAM AM_BASE(&vulgus_scroll_low)
66   AM_RANGE(0xc802, 0xc803) AM_RAM AM_BASE_MEMBER(vulgus_state, scroll_low)
6767   AM_RANGE(0xc804, 0xc804) AM_WRITE(vulgus_c804_w)
6868   AM_RANGE(0xc805, 0xc805) AM_WRITE(vulgus_palette_bank_w)
69   AM_RANGE(0xc902, 0xc903) AM_RAM AM_BASE(&vulgus_scroll_high)
69   AM_RANGE(0xc902, 0xc903) AM_RAM AM_BASE_MEMBER(vulgus_state, scroll_high)
7070   AM_RANGE(0xcc00, 0xcc7f) AM_RAM AM_BASE_SIZE_GENERIC(spriteram)
71   AM_RANGE(0xd000, 0xd7ff) AM_RAM_WRITE(vulgus_fgvideoram_w) AM_BASE(&vulgus_fgvideoram)
72   AM_RANGE(0xd800, 0xdfff) AM_RAM_WRITE(vulgus_bgvideoram_w) AM_BASE(&vulgus_bgvideoram)
71   AM_RANGE(0xd000, 0xd7ff) AM_RAM_WRITE(vulgus_fgvideoram_w) AM_BASE_MEMBER(vulgus_state, fgvideoram)
72   AM_RANGE(0xd800, 0xdfff) AM_RAM_WRITE(vulgus_bgvideoram_w) AM_BASE_MEMBER(vulgus_state, bgvideoram)
7373   AM_RANGE(0xe000, 0xefff) AM_RAM
7474ADDRESS_MAP_END
7575
r10427r10428
217217
218218
219219
220static MACHINE_CONFIG_START( vulgus, driver_device )
220static MACHINE_CONFIG_START( vulgus, vulgus_state )
221221
222222   /* basic machine hardware */
223223   MCFG_CPU_ADD("maincpu", Z80, 4000000)   /* 4 MHz (?) */
src/mame/drivers/bingoc.c
r10427r10428
3333#include "sound/2151intf.h"
3434#include "sound/upd7759.h"
3535
36
37class bingoc_state : public driver_device
38{
39public:
40   bingoc_state(running_machine &machine, const driver_device_config_base &config)
41      : driver_device(machine, config) { }
42
43   UINT8 x;
44};
45
46
3647#define SOUND_TEST 0
3748
3849static VIDEO_START(bingoc)
r10427r10428
5970*/
6071static READ8_HANDLER( sound_test_r )
6172{
62   static UINT8 x;
73   bingoc_state *state = space->machine->driver_data<bingoc_state>();
6374
6475   if(input_code_pressed_once(space->machine, KEYCODE_Z))
65      x++;
76      state->x++;
6677
6778   if(input_code_pressed_once(space->machine, KEYCODE_X))
68      x--;
79      state->x--;
6980
7081   if(input_code_pressed_once(space->machine, KEYCODE_A))
7182      return 0xff;
7283
73   popmessage("%02x",x);
74   return x;
84   popmessage("%02x",state->x);
85   return state->x;
7586}
7687#else
7788static WRITE16_HANDLER( main_sound_latch_w )
r10427r10428
125136INPUT_PORTS_END
126137
127138
128static MACHINE_CONFIG_START( bingoc, driver_device )
139static MACHINE_CONFIG_START( bingoc, bingoc_state )
129140
130141   MCFG_CPU_ADD("maincpu", M68000,8000000)       /* ? MHz */
131142   MCFG_CPU_PROGRAM_MAP(main_map)
src/mame/drivers/coolridr.c
r10427r10428
251251#include "deprecat.h"
252252#include "sound/scsp.h"
253253
254static UINT32* sysh1_workram_h,*framebuffer_vram, *h1_unk, *h1_charram, *h1_vram;
255static UINT32* sysh1_txt_blit;
256static UINT32* txt_vram;
257static bitmap_t* temp_bitmap_sprites;
258254
255class coolridr_state : public driver_device
256{
257public:
258   coolridr_state(running_machine &machine, const driver_device_config_base &config)
259      : driver_device(machine, config) { }
260
261   UINT32* sysh1_workram_h;
262   UINT32* framebuffer_vram;
263   UINT32* h1_unk;
264   UINT32* h1_charram;
265   UINT32* h1_vram;
266   UINT32* sysh1_txt_blit;
267   UINT32* txt_vram;
268   bitmap_t* temp_bitmap_sprites;
269   UINT32 test_offs;
270   int color;
271   UINT8 vblank;
272   UINT16 cmd;
273   UINT16 param;
274   UINT32 dst_addr;
275   UINT32 txt_buff[0x10];
276   UINT32 attr_buff[0x10];
277   UINT8 txt_index;
278   UINT8 attr_index;
279};
280
281
282
259283/* video */
260284
261285static VIDEO_START(coolridr)
262286{
287   coolridr_state *state = machine->driver_data<coolridr_state>();
263288   int width = machine->primary_screen->width();
264289   int height = machine->primary_screen->height();
265290
266   temp_bitmap_sprites  = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_RGB32);
291   state->temp_bitmap_sprites  = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_RGB32);
292   state->test_offs = 0x2000;
267293}
268294
269295static VIDEO_UPDATE(coolridr)
270296{
297   coolridr_state *state = screen->machine->driver_data<coolridr_state>();
271298   /* planes seems to basically be at 0x8000 and 0x28000... */
272299   const gfx_element *gfx = screen->machine->gfx[2];
273300   UINT32 count;
274301   int y,x;
275   static int color;
276   static UINT32 test_offs = 0x2000;
277302
278303
279304   if(input_code_pressed(screen->machine,KEYCODE_Z))
280      test_offs+=4;
305      state->test_offs+=4;
281306
282307   if(input_code_pressed(screen->machine,KEYCODE_X))
283      test_offs-=4;
308      state->test_offs-=4;
284309
285310   if(input_code_pressed(screen->machine,KEYCODE_C))
286      test_offs+=0x40;
311      state->test_offs+=0x40;
287312
288313   if(input_code_pressed(screen->machine,KEYCODE_V))
289      test_offs-=0x40;
314      state->test_offs-=0x40;
290315
291316   if(input_code_pressed(screen->machine,KEYCODE_B))
292      test_offs+=0x400;
317      state->test_offs+=0x400;
293318
294319   if(input_code_pressed(screen->machine,KEYCODE_N))
295      test_offs-=0x400;
320      state->test_offs-=0x400;
296321
297322   if(input_code_pressed_once(screen->machine,KEYCODE_A))
298      color++;
323      state->color++;
299324
300325   if(input_code_pressed_once(screen->machine,KEYCODE_S))
301      color--;
326      state->color--;
302327
303   if(test_offs > 0x100000*4)
304      test_offs = 0;
328   if(state->test_offs > 0x100000*4)
329      state->test_offs = 0;
305330
306   count = test_offs/4;
331   count = state->test_offs/4;
307332
308   popmessage("%08x %04x",test_offs,color);
333   popmessage("%08x %04x",state->test_offs,state->color);
309334
310335   for (y=0;y<64;y++)
311336   {
r10427r10428
313338      {
314339         int tile;
315340
316         tile = (h1_vram[count] & 0x0fff0000) >> 16;
317         drawgfx_opaque(bitmap,cliprect,gfx,tile,color,0,0,(x+0)*16,y*16);
341         tile = (state->h1_vram[count] & 0x0fff0000) >> 16;
342         drawgfx_opaque(bitmap,cliprect,gfx,tile,state->color,0,0,(x+0)*16,y*16);
318343
319         tile = (h1_vram[count] & 0x00000fff) >> 0;
320         drawgfx_opaque(bitmap,cliprect,gfx,tile,color,0,0,(x+1)*16,y*16);
344         tile = (state->h1_vram[count] & 0x00000fff) >> 0;
345         drawgfx_opaque(bitmap,cliprect,gfx,tile,state->color,0,0,(x+1)*16,y*16);
321346
322347         count++;
323348      }
324349   }
325350
326   copybitmap_trans(bitmap, temp_bitmap_sprites, 0, 0, 0, 0, cliprect, 0);
327   bitmap_fill(temp_bitmap_sprites, cliprect, 0);
351   copybitmap_trans(bitmap, state->temp_bitmap_sprites, 0, 0, 0, 0, cliprect, 0);
352   bitmap_fill(state->temp_bitmap_sprites, cliprect, 0);
328353
329354
330355   return 0;
r10427r10428
335360/* unknown purpose */
336361static READ32_HANDLER(sysh1_unk_r)
337362{
363   coolridr_state *state = space->machine->driver_data<coolridr_state>();
338364   switch(offset)
339365   {
340366      case 0x08/4:
341367      {
342         static UINT8 vblank = 0;
343368
344         vblank^=1;
369         state->vblank^=1;
345370
346         return (h1_unk[offset] & 0xfdffffff) | (vblank<<25);
371         return (state->h1_unk[offset] & 0xfdffffff) | (state->vblank<<25);
347372      }
348373      case 0x14/4:
349         return h1_unk[offset];
374         return state->h1_unk[offset];
350375      //case 0x20/4:
351376   }
352377
353   return 0xffffffff;//h1_unk[offset];
378   return 0xffffffff;//state->h1_unk[offset];
354379}
355380
356381static WRITE32_HANDLER(sysh1_unk_w)
357382{
358   COMBINE_DATA(&h1_unk[offset]);
383   coolridr_state *state = space->machine->driver_data<coolridr_state>();
384   COMBINE_DATA(&state->h1_unk[offset]);
359385}
360386
361387/* According to Guru, this is actually the same I/O chip of Sega Model 2 HW */
r10427r10428
403429/* this looks like an exotic I/O-based tilemap / sprite blitter, very unusual from Sega... */
404430static WRITE32_HANDLER( sysh1_txt_blit_w )
405431{
406   static UINT16 cmd,param;
407   static UINT32 dst_addr;
408   static UINT32 txt_buff[0x10],attr_buff[0x10];
409   static UINT8 txt_index,attr_index;
432   coolridr_state *state = space->machine->driver_data<coolridr_state>();
410433
411   COMBINE_DATA(&sysh1_txt_blit[offset]);
434   COMBINE_DATA(&state->sysh1_txt_blit[offset]);
412435
413436   switch(offset)
414437   {
415      case 0x10/4: //cmd + param?
416         cmd = (sysh1_txt_blit[offset] & 0xffff0000) >> 16;
417         param = (sysh1_txt_blit[offset] & 0x0000ffff) >> 0;
418         dst_addr = 0x3f40000;
419         txt_index = 0;
420         attr_index = 0;
438      case 0x10/4: //state->cmd + state->param?
439         state->cmd = (state->sysh1_txt_blit[offset] & 0xffff0000) >> 16;
440         state->param = (state->sysh1_txt_blit[offset] & 0x0000ffff) >> 0;
441         state->dst_addr = 0x3f40000;
442         state->txt_index = 0;
443         state->attr_index = 0;
421444         break;
422445      case 0x14/4: //data
423446         /*  "THIS MACHINE IS STAND-ALONE." / disclaimer written with this CMD */
424         if((cmd & 0xff) == 0xf4)
447         if((state->cmd & 0xff) == 0xf4)
425448         {
426            txt_buff[txt_index++] = data;
449            state->txt_buff[state->txt_index++] = data;
427450
428            //printf("CMD = %04x PARAM = %04x | %c%c%c%c\n",cmd,param,(data >> 24) & 0xff,(data >> 16) & 0xff,(data >> 8) & 0xff,(data >> 0) & 0xff);
451            //printf("CMD = %04x PARAM = %04x | %c%c%c%c\n",state->cmd,state->param,(data >> 24) & 0xff,(data >> 16) & 0xff,(data >> 8) & 0xff,(data >> 0) & 0xff);
429452         }
430         else if((cmd & 0xff) == 0x90 || (cmd & 0xff) == 0x30)
453         else if((state->cmd & 0xff) == 0x90 || (state->cmd & 0xff) == 0x30)
431454         {
432            attr_buff[attr_index++] = data;
455            state->attr_buff[state->attr_index++] = data;
433456
434            if(attr_index == 0xa)
457            if(state->attr_index == 0xa)
435458            {
436               static UINT16 x,y;
459               UINT16 x,y;
437460
438               y = (attr_buff[9] & 0x01f00000) >> 20;
439               x = (attr_buff[9] & 0x1f0) >> 4;
440               dst_addr = 0x3f40000 | y*0x40 | x;
461               y = (state->attr_buff[9] & 0x01f00000) >> 20;
462               x = (state->attr_buff[9] & 0x1f0) >> 4;
463               state->dst_addr = 0x3f40000 | y*0x40 | x;
441464
442465               {
443466                  int x2,y2;
444467                  const gfx_element *gfx = space->machine->gfx[1];
445468                  rectangle clip;
446469
447                  y2 = (attr_buff[9] & 0x01ff0000) >> 16;
448                  x2 = (attr_buff[9] & 0x000001ff);
470                  y2 = (state->attr_buff[9] & 0x01ff0000) >> 16;
471                  x2 = (state->attr_buff[9] & 0x000001ff);
449472                  clip.min_x = 0;
450                  clip.max_x =  temp_bitmap_sprites->width;
473                  clip.max_x =  state->temp_bitmap_sprites->width;
451474                  clip.min_y = 0;
452                  clip.max_y = temp_bitmap_sprites->height;
475                  clip.max_y = state->temp_bitmap_sprites->height;
453476
454                  drawgfx_opaque(temp_bitmap_sprites,&clip,gfx,1,1,0,0,x2,y2);
477                  drawgfx_opaque(state->temp_bitmap_sprites,&clip,gfx,1,1,0,0,x2,y2);
455478               }
456479            }
457            if(attr_index == 0xc)
480            if(state->attr_index == 0xc)
458481            {
459               static UINT8 size;
482               UINT8 size;
460483
461               size = (attr_buff[6] / 4)+1;
462               for(txt_index = 0;txt_index < size; txt_index++)
484               size = (state->attr_buff[6] / 4)+1;
485               for(state->txt_index = 0;state->txt_index < size; state->txt_index++)
463486               {
464                  space->write_dword((dst_addr),txt_buff[txt_index]);
465                  dst_addr+=4;
487                  space->write_dword((state->dst_addr),state->txt_buff[state->txt_index]);
488                  state->dst_addr+=4;
466489               }
467490            }
468491         }
469         else if((cmd & 0xff) == 0x10)
492         else if((state->cmd & 0xff) == 0x10)
470493         {
471            static UINT32 clear_vram;
494            UINT32 clear_vram;
472495            for(clear_vram=0x3f40000;clear_vram < 0x3f4ffff;clear_vram+=4)
473496               space->write_dword((clear_vram),0x00000000);
474497         }
475498         //else
476         //  printf("CMD = %04x PARAM = %04x DATA = %08x\n",cmd,param,data);
499         //  printf("CMD = %04x PARAM = %04x DATA = %08x\n",state->cmd,state->param,data);
477500         break;
478501   }
479502}
r10427r10428
498521/* FIXME: this seems to do a hell lot of stuff, it's not ST-V SCU but still somewhat complex :/ */
499522static void sysh1_dma_transfer( address_space *space, UINT16 dma_index )
500523{
501   static UINT32 src,dst,size,type,s_i;
502   static UINT8 end_dma_mark;
524   coolridr_state *state = space->machine->driver_data<coolridr_state>();
525   UINT32 src,dst,size,type,s_i;
526   UINT8 end_dma_mark;
503527
504528   end_dma_mark = 0;
505529
506530   do{
507      src = (framebuffer_vram[(0+dma_index)/4] & 0x0fffffff);
508      dst = (framebuffer_vram[(4+dma_index)/4]);
509      size = framebuffer_vram[(8+dma_index)/4];
510      type = (framebuffer_vram[(0+dma_index)/4] & 0xf0000000) >> 28;
531      src = (state->framebuffer_vram[(0+dma_index)/4] & 0x0fffffff);
532      dst = (state->framebuffer_vram[(4+dma_index)/4]);
533      size = state->framebuffer_vram[(8+dma_index)/4];
534      type = (state->framebuffer_vram[(0+dma_index)/4] & 0xf0000000) >> 28;
511535
512536      #if 0
513537      if(type == 0xc || type == 0xd || type == 0xe)
r10427r10428
518542
519543      if(type == 0x3 || type == 0x4)
520544      {
521         //type 3 sets a DMA param, type 4 sets some kind of table? Skip it for now
545         //type 3 sets a DMA state->param, type 4 sets some kind of table? Skip it for now
522546         dma_index+=4;
523547         continue;
524548      }
r10427r10428
573597
574598static WRITE32_HANDLER( sysh1_dma_w )
575599{
576   COMBINE_DATA(&framebuffer_vram[offset]);
600   coolridr_state *state = space->machine->driver_data<coolridr_state>();
601   COMBINE_DATA(&state->framebuffer_vram[offset]);
577602
578603   if(offset*4 == 0x000)
579604   {
580      if((framebuffer_vram[offset] & 0xff00000) == 0xfe00000)
581         sysh1_dma_transfer(space, framebuffer_vram[offset] & 0xffff);
605      if((state->framebuffer_vram[offset] & 0xff00000) == 0xfe00000)
606         sysh1_dma_transfer(space, state->framebuffer_vram[offset] & 0xffff);
582607   }
583608}
584609
585610static WRITE32_HANDLER( sysh1_char_w )
586611{
587   COMBINE_DATA(&h1_charram[offset]);
612   coolridr_state *state = space->machine->driver_data<coolridr_state>();
613   COMBINE_DATA(&state->h1_charram[offset]);
588614
589615   {
590616      UINT8 *gfx = space->machine->region("ram_gfx")->base();
591617
592      gfx[offset*4+0] = (h1_charram[offset] & 0xff000000) >> 24;
593      gfx[offset*4+1] = (h1_charram[offset] & 0x00ff0000) >> 16;
594      gfx[offset*4+2] = (h1_charram[offset] & 0x0000ff00) >> 8;
595      gfx[offset*4+3] = (h1_charram[offset] & 0x000000ff) >> 0;
618      gfx[offset*4+0] = (state->h1_charram[offset] & 0xff000000) >> 24;
619      gfx[offset*4+1] = (state->h1_charram[offset] & 0x00ff0000) >> 16;
620      gfx[offset*4+2] = (state->h1_charram[offset] & 0x0000ff00) >> 8;
621      gfx[offset*4+3] = (state->h1_charram[offset] & 0x000000ff) >> 0;
596622
597623      gfx_element_mark_dirty(space->machine->gfx[2], offset/64); //*4/256
598624   }
r10427r10428
602628   AM_RANGE(0x00000000, 0x001fffff) AM_ROM AM_SHARE("share1") AM_WRITENOP
603629   AM_RANGE(0x01000000, 0x01ffffff) AM_ROM AM_REGION("gfx_data",0x0000000)
604630
605   AM_RANGE(0x03000000, 0x030fffff) AM_RAM AM_BASE(&h1_vram)//bg vram
631   AM_RANGE(0x03000000, 0x030fffff) AM_RAM AM_BASE_MEMBER(coolridr_state, h1_vram)//bg vram
606632   AM_RANGE(0x03c00000, 0x03c0ffff) AM_RAM_WRITE(sysh1_pal_w) AM_BASE_GENERIC(paletteram)
607   AM_RANGE(0x03d00000, 0x03dfffff) AM_RAM_WRITE(sysh1_char_w) AM_BASE(&h1_charram) //FIXME: half size
608   AM_RANGE(0x03e00000, 0x03efffff) AM_RAM_WRITE(sysh1_dma_w) AM_BASE(&framebuffer_vram) //FIXME: not all of it
633   AM_RANGE(0x03d00000, 0x03dfffff) AM_RAM_WRITE(sysh1_char_w) AM_BASE_MEMBER(coolridr_state, h1_charram) //FIXME: half size
634   AM_RANGE(0x03e00000, 0x03efffff) AM_RAM_WRITE(sysh1_dma_w) AM_BASE_MEMBER(coolridr_state, framebuffer_vram) //FIXME: not all of it
609635
610636   AM_RANGE(0x03f00000, 0x03f0ffff) AM_RAM AM_SHARE("share3") /*Communication area RAM*/
611   AM_RANGE(0x03f40000, 0x03f4ffff) AM_RAM AM_BASE(&txt_vram)//text tilemap + "lineram"
612   AM_RANGE(0x04000000, 0x0400003f) AM_RAM_WRITE(sysh1_txt_blit_w) AM_BASE(&sysh1_txt_blit)
613   AM_RANGE(0x06000000, 0x060fffff) AM_RAM AM_BASE(&sysh1_workram_h)
637   AM_RANGE(0x03f40000, 0x03f4ffff) AM_RAM AM_BASE_MEMBER(coolridr_state, txt_vram)//text tilemap + "lineram"
638   AM_RANGE(0x04000000, 0x0400003f) AM_RAM_WRITE(sysh1_txt_blit_w) AM_BASE_MEMBER(coolridr_state, sysh1_txt_blit)
639   AM_RANGE(0x06000000, 0x060fffff) AM_RAM AM_BASE_MEMBER(coolridr_state, sysh1_workram_h)
614640   AM_RANGE(0x20000000, 0x201fffff) AM_ROM AM_SHARE("share1")
615641
616642   AM_RANGE(0x60000000, 0x600003ff) AM_WRITENOP
r10427r10428
628654   AM_RANGE(0x03208900, 0x03208903) AM_RAM /*???*/
629655   AM_RANGE(0x03300400, 0x03300403) AM_RAM /*irq enable?*/
630656
631   AM_RANGE(0x04000000, 0x0400003f) AM_READWRITE(sysh1_unk_r,sysh1_unk_w) AM_BASE(&h1_unk)
657   AM_RANGE(0x04000000, 0x0400003f) AM_READWRITE(sysh1_unk_r,sysh1_unk_w) AM_BASE_MEMBER(coolridr_state, h1_unk)
632658   AM_RANGE(0x04200000, 0x0420003f) AM_RAM /*???*/
633659
634660   AM_RANGE(0x05000000, 0x05000fff) AM_RAM
r10427r10428
10671093   cputag_set_input_line(machine, "soundcpu", INPUT_LINE_HALT, ASSERT_LINE);
10681094}
10691095
1070static MACHINE_CONFIG_START( coolridr, driver_device )
1096static MACHINE_CONFIG_START( coolridr, coolridr_state )
10711097   MCFG_CPU_ADD("maincpu", SH2, 28000000)   // 28 mhz
10721098   MCFG_CPU_PROGRAM_MAP(system_h1_map)
10731099   MCFG_CPU_VBLANK_INT("screen",system_h1)
r10427r10428
11401166#if 0
11411167static READ32_HANDLER( coolridr_hack1_r )
11421168{
1169   coolridr_state *state = space->machine->driver_data<coolridr_state>();
11431170   offs_t pc = downcast<cpu_device *>(space->cpu)->pc();
11441171   if(pc == 0x6012374 || pc == 0x6012392)
11451172      return 0;
11461173
1147   return sysh1_workram_h[0xd88a4/4];
1174   return state->sysh1_workram_h[0xd88a4/4];
11481175}
11491176#endif
11501177
11511178static READ32_HANDLER( coolridr_hack2_r )
11521179{
1180   coolridr_state *state = space->machine->driver_data<coolridr_state>();
11531181   offs_t pc = downcast<cpu_device *>(space->cpu)->pc();
11541182   if(pc == 0x6002cba || pc == 0x6002d42)
11551183      return 0;
11561184
1157   return sysh1_workram_h[0xd8894/4];
1185   return state->sysh1_workram_h[0xd8894/4];
11581186}
11591187
11601188static DRIVER_INIT( coolridr )
src/mame/drivers/tryout.c
r10427r10428
6767   AM_RANGE(0xe301, 0xe301) AM_WRITE(tryout_flipscreen_w)
6868   AM_RANGE(0xe302, 0xe302) AM_WRITE(tryout_bankswitch_w)
6969   AM_RANGE(0xe401, 0xe401) AM_WRITE(tryout_vram_bankswitch_w)
70   AM_RANGE(0xe402, 0xe404) AM_WRITEONLY AM_BASE(&tryout_gfx_control)
70   AM_RANGE(0xe402, 0xe404) AM_WRITEONLY AM_BASE_MEMBER(tryout_state, gfx_control)
7171   AM_RANGE(0xe414, 0xe414) AM_WRITE(tryout_sound_w)
7272   AM_RANGE(0xe417, 0xe417) AM_WRITE(tryout_nmi_ack_w)
7373   AM_RANGE(0xfff0, 0xffff) AM_ROM AM_REGION("maincpu", 0xbff0) /* reset vectors */
src/mame/drivers/ultrsprt.c
r10427r10428
1717#include "sound/k056800.h"
1818
1919
20static UINT32 *vram;
21static UINT32 *workram;
20class ultrsprt_state : public driver_device
21{
22public:
23   ultrsprt_state(running_machine &machine, const driver_device_config_base &config)
24      : driver_device(machine, config) { }
2225
26   UINT32 *vram;
27   UINT32 *workram;
28};
29
30
31
32
2333static VIDEO_UPDATE( ultrsprt )
2434{
35   ultrsprt_state *state = screen->machine->driver_data<ultrsprt_state>();
2536   int i, j;
2637
27   UINT8 *ram = (UINT8 *)vram;
38   UINT8 *ram = (UINT8 *)state->vram;
2839
2940   for (j=0; j < 400; j++)
3041   {
r10427r10428
8293
8394static MACHINE_START( ultrsprt )
8495{
96   ultrsprt_state *state = machine->driver_data<ultrsprt_state>();
8597   /* set conservative DRC options */
8698   ppcdrc_set_options(machine->device("maincpu"), PPCDRC_COMPATIBLE_OPTIONS);
8799
88100   /* configure fast RAM regions for DRC */
89   ppcdrc_add_fastram(machine->device("maincpu"), 0x80000000, 0x8007ffff, FALSE, vram);
90   ppcdrc_add_fastram(machine->device("maincpu"), 0xff000000, 0xff01ffff, FALSE, workram);
101   ppcdrc_add_fastram(machine->device("maincpu"), 0x80000000, 0x8007ffff, FALSE, state->vram);
102   ppcdrc_add_fastram(machine->device("maincpu"), 0xff000000, 0xff01ffff, FALSE, state->workram);
91103}
92104
93105
94106
95107static ADDRESS_MAP_START( ultrsprt_map, ADDRESS_SPACE_PROGRAM, 32 )
96   AM_RANGE(0x00000000, 0x0007ffff) AM_RAM AM_BASE(&vram)
108   AM_RANGE(0x00000000, 0x0007ffff) AM_RAM AM_BASE_MEMBER(ultrsprt_state, vram)
97109   AM_RANGE(0x70000000, 0x70000003) AM_READWRITE(eeprom_r, eeprom_w)
98110   AM_RANGE(0x70000020, 0x70000023) AM_READ_PORT("P1")
99111   AM_RANGE(0x70000040, 0x70000043) AM_READ_PORT("P2")
100112   AM_RANGE(0x70000080, 0x70000087) AM_DEVWRITE("k056800", k056800_host_w)
101113   AM_RANGE(0x70000088, 0x7000008f) AM_DEVREAD("k056800", k056800_host_r)
102114   AM_RANGE(0x700000e0, 0x700000e3) AM_WRITE(int_ack_w)
103   AM_RANGE(0x7f000000, 0x7f01ffff) AM_RAM AM_BASE(&workram)
115   AM_RANGE(0x7f000000, 0x7f01ffff) AM_RAM AM_BASE_MEMBER(ultrsprt_state, workram)
104116   AM_RANGE(0x7f700000, 0x7f703fff) AM_RAM_WRITE(palette_w) AM_BASE_GENERIC(paletteram)
105117   AM_RANGE(0x7f800000, 0x7f9fffff) AM_MIRROR(0x00600000) AM_ROM AM_REGION("user1", 0)
106118ADDRESS_MAP_END
r10427r10428
201213};
202214
203215
204static MACHINE_CONFIG_START( ultrsprt, driver_device )
216static MACHINE_CONFIG_START( ultrsprt, ultrsprt_state )
205217   /* basic machine hardware */
206218   MCFG_CPU_ADD("maincpu", PPC403GA, 25000000)      /* PowerPC 403GA 25MHz */
207219   MCFG_CPU_PROGRAM_MAP(ultrsprt_map)
src/mame/drivers/twinkle.c
r10427r10428
232232#include "machine/rtc65271.h"
233233#include "machine/i2cmem.h"
234234#include "machine/idectrl.h"
235#include "sound/psx.h"
235#include "sound/spu.h"
236236#include "sound/cdda.h"
237237#include "sound/rf5c400.h"
238238
r10427r10428
650650   AM_RANGE(0x1f801008, 0x1f80100b) AM_RAM /* ?? */
651651   AM_RANGE(0x1f80100c, 0x1f80100f) AM_WRITENOP
652652   AM_RANGE(0x1f801010, 0x1f801013) AM_READNOP
653   AM_RANGE(0x1f801014, 0x1f801017) AM_DEVREAD("spu", psx_spu_delay_r)
653   AM_RANGE(0x1f801014, 0x1f801017) AM_RAM
654654   AM_RANGE(0x1f801020, 0x1f801023) AM_READWRITE(twinkle_unknown_r, twinkle_unknown_w)
655655   AM_RANGE(0x1f801040, 0x1f80105f) AM_READWRITE(psx_sio_r, psx_sio_w)
656656   AM_RANGE(0x1f801060, 0x1f80106f) AM_WRITENOP
r10427r10428
659659   AM_RANGE(0x1f801100, 0x1f80112f) AM_READWRITE(psx_counter_r, psx_counter_w)
660660   AM_RANGE(0x1f801810, 0x1f801817) AM_READWRITE(psx_gpu_r, psx_gpu_w)
661661   AM_RANGE(0x1f801820, 0x1f801827) AM_READWRITE(psx_mdec_r, psx_mdec_w)
662   AM_RANGE(0x1f801c00, 0x1f801dff) AM_DEVREADWRITE("spu", psx_spu_r, psx_spu_w)
662   AM_RANGE(0x1f801c00, 0x1f801dff) AM_READWRITE16(spu_r, spu_w, 0xffffffff)
663663   AM_RANGE(0x1f802020, 0x1f802033) AM_RAM /* ?? */
664664   AM_RANGE(0x1f802040, 0x1f802043) AM_WRITENOP
665665   AM_RANGE(0x1fc00000, 0x1fc7ffff) AM_ROM AM_SHARE("share2") AM_REGION("user1", 0) /* bios */
r10427r10428
906906
907907static void spu_irq(device_t *device, UINT32 data)
908908{
909   psx_irq_set(device->machine, data);
909   if (data)
910   {
911      psx_irq_set(device->machine, 1<<9);
912   }
910913}
911914
912static const psx_spu_interface twinkle_psxspu_interface =
913{
914   spu_irq,
915   psx_dma_install_read_handler,
916   psx_dma_install_write_handler
917};
918
919915static const i2cmem_interface i2cmem_interface =
920916{
921917   I2CMEM_SLAVE_ADDRESS, 0, 0x100
r10427r10428
955951   /* sound hardware */
956952   MCFG_SPEAKER_STANDARD_STEREO("speakerleft", "speakerright")
957953
958   MCFG_SOUND_ADD( "spu", PSXSPU, 0 )
959   MCFG_SOUND_CONFIG( twinkle_psxspu_interface )
954   MCFG_SPU_ADD( "spu", XTAL_67_7376MHz/2, &spu_irq )
960955   MCFG_SOUND_ROUTE( 0, "speakerleft", 0.75 )
961956   MCFG_SOUND_ROUTE( 1, "speakerright", 0.75 )
962957
src/mame/drivers/hexion.c
r10427r10428
218218      cpu_set_input_line(device, 0, HOLD_LINE);
219219}
220220
221static MACHINE_CONFIG_START( hexion, driver_device )
221static MACHINE_CONFIG_START( hexion, hexion_state )
222222
223223   /* basic machine hardware */
224224   MCFG_CPU_ADD("maincpu", Z80,24000000/4)   /* Z80B 6 MHz */
src/mame/drivers/86lions.c
r10427r10428
3333#include "sound/ay8910.h"
3434#include "machine/6522via.h"
3535
36static UINT8 *lions_vram;
3736
37class _86lions_state : public driver_device
38{
39public:
40   _86lions_state(running_machine &machine, const driver_device_config_base &config)
41      : driver_device(machine, config) { }
42
43   UINT8 *lions_vram;
44};
45
46
47
3848static VIDEO_START(lions)
3949{
4050}
4151
4252static VIDEO_UPDATE(lions)
4353{
54   _86lions_state *state = screen->machine->driver_data<_86lions_state>();
4455   const gfx_element *gfx = screen->machine->gfx[0];
4556   int count = 0;
4657
r10427r10428
5061   {
5162      for (x=0;x<38;x++)
5263      {
53         int tile = lions_vram[count+1]|lions_vram[count]<<8;
64         int tile = state->lions_vram[count+1]|state->lions_vram[count]<<8;
5465         tile&=0x1ff;
5566         //int colour = tile>>12;
5667         drawgfx_opaque(bitmap,cliprect,gfx,tile,0,0,0,x*8,y*8);
r10427r10428
7586
7687
7788static ADDRESS_MAP_START( lions_map, ADDRESS_SPACE_PROGRAM, 8 )
78   AM_RANGE(0x0000, 0x07ff) AM_RAM AM_BASE(&lions_vram)
89   AM_RANGE(0x0000, 0x07ff) AM_RAM AM_BASE_MEMBER(_86lions_state, lions_vram)
7990   AM_RANGE(0x0800, 0x0fff) AM_RAM
8091   AM_RANGE(0x1800, 0x1800) AM_DEVWRITE("crtc", mc6845_address_w)
8192   AM_RANGE(0x1801, 0x1801) AM_DEVREADWRITE("crtc", mc6845_register_r, mc6845_register_w)
r10427r10428
340351   }
341352}
342353
343static MACHINE_CONFIG_START( lions, driver_device )
354static MACHINE_CONFIG_START( lions, _86lions_state )
344355   /* basic machine hardware */
345356   MCFG_CPU_ADD("maincpu", M6809, MAIN_CLOCK/4)       /* 3 MHz.(guess) */
346357   MCFG_CPU_PROGRAM_MAP(lions_map)
src/mame/drivers/timetrv.c
r10427r10428
2626#include "emu.h"
2727#include "cpu/i86/i86.h"
2828
29static UINT8 *led_vram_lo,*led_vram_hi;
3029
30class timetrv_state : public driver_device
31{
32public:
33   timetrv_state(running_machine &machine, const driver_device_config_base &config)
34      : driver_device(machine, config) { }
35
36   UINT8 *led_vram_lo;
37   UINT8 *led_vram_hi;
38};
39
40
41
3142static VIDEO_START( timetrv )
3243{
3344
r10427r10428
3546
3647static VIDEO_UPDATE( timetrv )
3748{
38   popmessage("%s%s",led_vram_lo,led_vram_hi);
49   timetrv_state *state = screen->machine->driver_data<timetrv_state>();
50   popmessage("%s%s",state->led_vram_lo,state->led_vram_hi);
3951   return 0;
4052}
4153
r10427r10428
7587   AM_RANGE(0x1080, 0x1082) AM_READ(in_r) //dsw
7688   AM_RANGE(0x1100, 0x1105) AM_WRITENOP //laserdisc write area
7789   AM_RANGE(0x1100, 0x1105) AM_READ(ld_r) //5 -> laserdisc read status
78   AM_RANGE(0x1180, 0x1187) AM_RAM AM_BASE(&led_vram_lo)//led string,part 1
79   AM_RANGE(0x1200, 0x1207) AM_RAM AM_BASE(&led_vram_hi)//led string,part 2
90   AM_RANGE(0x1180, 0x1187) AM_RAM AM_BASE_MEMBER(timetrv_state, led_vram_lo)//led string,part 1
91   AM_RANGE(0x1200, 0x1207) AM_RAM AM_BASE_MEMBER(timetrv_state, led_vram_hi)//led string,part 2
8092   AM_RANGE(0xff80, 0xffff) AM_RAM //am80188-em-like cpu internal regs?
8193ADDRESS_MAP_END
8294
r10427r10428
125137   cpu_set_input_line_and_vector(device,0,HOLD_LINE,0x48/4); //ld irq
126138}
127139
128static MACHINE_CONFIG_START( timetrv, driver_device )
140static MACHINE_CONFIG_START( timetrv, timetrv_state )
129141
130142   /* basic machine hardware */
131143   MCFG_CPU_ADD("maincpu",I80188,20000000) //???
src/mame/drivers/system1.c
r10427r10428
203203#define SOUND_CLOCK      XTAL_8MHz
204204
205205
206/* driver config */
207static void (*videomode_custom)(running_machine *machine, UINT8 data, UINT8 prevdata);
208static UINT8 mute_xor;
209
210static UINT8 *system1_ram;
211static UINT8 dakkochn_mux_data;
212static UINT8 videomode_prev;
213static UINT8 mcu_control;
214static UINT8 *nob_mcu_status;
215static UINT8 *nob_mcu_latch;
216static UINT8 nob_maincpu_latch;
217
218
219
220206/*************************************
221207 *
222208 *  Machine initialization
r10427r10428
355341
356342static MACHINE_START( system1 )
357343{
344   system1_state *state = machine->driver_data<system1_state>();
358345   UINT32 numbanks = (machine->region("maincpu")->bytes() - 0x10000) / 0x4000;
359346
360347   if (numbanks > 0)
r10427r10428
365352
366353   z80_set_cycle_tables(machine->device("maincpu"), cc_op, cc_cb, cc_ed, cc_xy, cc_xycb, cc_ex);
367354
368   mute_xor = 0x00;
355   state->mute_xor = 0x00;
369356
370   state_save_register_global(machine, dakkochn_mux_data);
371   state_save_register_global(machine, videomode_prev);
372   state_save_register_global(machine, mcu_control);
373   state_save_register_global(machine, nob_maincpu_latch);
357   state_save_register_global(machine, state->dakkochn_mux_data);
358   state_save_register_global(machine, state->videomode_prev);
359   state_save_register_global(machine, state->mcu_control);
360   state_save_register_global(machine, state->nob_maincpu_latch);
374361}
375362
376363
377364static MACHINE_START( system2 )
378365{
366   system1_state *state = machine->driver_data<system1_state>();
379367   MACHINE_START_CALL(system1);
380   mute_xor = 0x01;
368   state->mute_xor = 0x01;
381369}
382370
383371
384372static MACHINE_RESET( system1 )
385373{
386   dakkochn_mux_data = 0;
374   system1_state *state = machine->driver_data<system1_state>();
375   state->dakkochn_mux_data = 0;
387376}
388377
389378
r10427r10428
410399
411400static WRITE8_HANDLER( videomode_w )
412401{
402   system1_state *state = space->machine->driver_data<system1_state>();
413403   device_t *i8751 = space->machine->device("mcu");
414404
415405   /* bit 6 is connected to the 8751 IRQ */
r10427r10428
417407      cpu_set_input_line(i8751, MCS51_INT1_LINE, (data & 0x40) ? CLEAR_LINE : ASSERT_LINE);
418408
419409   /* handle any custom banking or other stuff */
420   if (videomode_custom != NULL)
421      (*videomode_custom)(space->machine, data, videomode_prev);
422   videomode_prev = data;
410   if (state->videomode_custom != NULL)
411      (*state->videomode_custom)(space->machine, data, state->videomode_prev);
412   state->videomode_prev = data;
423413
424414   /* bit 0 is for the coin counters */
425415   coin_counter_w(space->machine, 0, data & 1);
r10427r10428
438428
439429static CUSTOM_INPUT( dakkochn_mux_data_r )
440430{
431   system1_state *state = field->port->machine->driver_data<system1_state>();
441432   static const char *const ports[] = { "KEY0", "KEY1", "KEY2", "KEY3", "KEY4", "KEY5", "KEY6" };
442   return input_port_read(field->port->machine, ports[dakkochn_mux_data]);
433   return input_port_read(field->port->machine, ports[state->dakkochn_mux_data]);
443434}
444435
445436
446437static CUSTOM_INPUT( dakkochn_mux_status_r )
447438{
439   system1_state *state = field->port->machine->driver_data<system1_state>();
448440   /* reads from here indicate which mux port is selected */
449   return 1 << (dakkochn_mux_data);
441   return 1 << (state->dakkochn_mux_data);
450442}
451443
452444
453445static void dakkochn_custom_w(running_machine *machine, UINT8 data, UINT8 prevdata)
454446{
447   system1_state *state = machine->driver_data<system1_state>();
455448   /* bit 1 toggling on clocks the mux; we store the previous state in the high bit of dakkochn_mux_data */
456449   if ((data & 0x02) && !(prevdata & 0x02))
457      dakkochn_mux_data = (dakkochn_mux_data + 1) % 7;
450      state->dakkochn_mux_data = (state->dakkochn_mux_data + 1) % 7;
458451
459452   /* remaining stuff acts like bank0c */
460453   bank0c_custom_w(machine, data, prevdata);
r10427r10428
470463
471464static WRITE8_DEVICE_HANDLER( sound_control_w )
472465{
466   system1_state *state = device->machine->driver_data<system1_state>();
473467   /* bit 0 = MUTE (inverted sense on System 2) */
474   device->machine->sound().system_mute((data ^ mute_xor) & 1);
468   device->machine->sound().system_mute((data ^ state->mute_xor) & 1);
475469
476470   /* bit 6 = feedback from sound board that read occurrred */
477471
r10427r10428
534528
535529static WRITE8_HANDLER( mcu_control_w )
536530{
531   system1_state *state = space->machine->driver_data<system1_state>();
537532   /*
538533        Bit 7 -> connects to TD62003 pins 5 & 6 @ IC151
539534        Bit 6 -> via PLS153, when high, asserts the BUSREQ signal, halting the Z80
r10427r10428
544539        Bit 1 -> n/c
545540        Bit 0 -> Directly connected to Z80 /INT line
546541    */
547   mcu_control = data;
542   state->mcu_control = data;
548543   cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_HALT, (data & 0x40) ? ASSERT_LINE : CLEAR_LINE);
549544   cputag_set_input_line(space->machine, "maincpu", 0, (data & 0x01) ? CLEAR_LINE : ASSERT_LINE);
550545}
r10427r10428
552547
553548static WRITE8_HANDLER( mcu_io_w )
554549{
555   switch ((mcu_control >> 3) & 3)
550   system1_state *state = space->machine->driver_data<system1_state>();
551   switch ((state->mcu_control >> 3) & 3)
556552   {
557553      case 0:
558554         space->machine->device<z80_device>("maincpu")->space(AS_PROGRAM)->write_byte(offset, data);
r10427r10428
564560
565561      default:
566562         logerror("%03X: MCU movx write mode %02X offset %04X = %02X\n",
567                cpu_get_pc(space->cpu), mcu_control, offset, data);
563                cpu_get_pc(space->cpu), state->mcu_control, offset, data);
568564         break;
569565   }
570566}
r10427r10428
572568
573569static READ8_HANDLER( mcu_io_r )
574570{
575   switch ((mcu_control >> 3) & 3)
571   system1_state *state = space->machine->driver_data<system1_state>();
572   switch ((state->mcu_control >> 3) & 3)
576573   {
577574      case 0:
578575         return space->machine->device<z80_device>("maincpu")->space(AS_PROGRAM)->read_byte(offset);
r10427r10428
585582
586583      default:
587584         logerror("%03X: MCU movx read mode %02X offset %04X\n",
588                cpu_get_pc(space->cpu), mcu_control, offset);
585                cpu_get_pc(space->cpu), state->mcu_control, offset);
589586         return 0xff;
590587   }
591588}
r10427r10428
623620
624621static WRITE8_HANDLER( nob_mcu_control_p2_w )
625622{
623   system1_state *state = space->machine->driver_data<system1_state>();
626624   /* bit 0 triggers a read from MCU port 0 */
627   if (((mcu_control ^ data) & 0x01) && !(data & 0x01))
628      *nob_mcu_latch = nob_maincpu_latch;
625   if (((state->mcu_control ^ data) & 0x01) && !(data & 0x01))
626      *state->nob_mcu_latch = state->nob_maincpu_latch;
629627
630628   /* bit 1 triggers a write from MCU port 0 */
631   if (((mcu_control ^ data) & 0x02) && !(data & 0x02))
632      nob_maincpu_latch = *nob_mcu_latch;
629   if (((state->mcu_control ^ data) & 0x02) && !(data & 0x02))
630      state->nob_maincpu_latch = *state->nob_mcu_latch;
633631
634632   /* bit 2 is toggled once near the end of an IRQ */
635   if (((mcu_control ^ data) & 0x04) && !(data & 0x04))
633   if (((state->mcu_control ^ data) & 0x04) && !(data & 0x04))
636634      cpu_set_input_line(space->cpu, MCS51_INT0_LINE, CLEAR_LINE);
637635
638636   /* bit 3 is toggled once at the start of an IRQ, and again at the end */
639   if (((mcu_control ^ data) & 0x08) && !(data & 0x08))
637   if (((state->mcu_control ^ data) & 0x08) && !(data & 0x08))
640638   {
641639      //logerror("MCU IRQ(8) toggle\n");
642640   }
643641
644   mcu_control = data;
642   state->mcu_control = data;
645643}
646644
647645
648646static READ8_HANDLER( nob_maincpu_latch_r )
649647{
650   return nob_maincpu_latch;
648   system1_state *state = space->machine->driver_data<system1_state>();
649   return state->nob_maincpu_latch;
651650}
652651
653652
654653static WRITE8_HANDLER( nob_maincpu_latch_w )
655654{
656   nob_maincpu_latch = data;
655   system1_state *state = space->machine->driver_data<system1_state>();
656   state->nob_maincpu_latch = data;
657657   cputag_set_input_line(space->machine, "mcu", MCS51_INT0_LINE, ASSERT_LINE);
658658   space->machine->scheduler().boost_interleave(attotime::zero, attotime::from_usec(100));
659659}
r10427r10428
661661
662662static READ8_HANDLER( nob_mcu_status_r )
663663{
664   return *nob_mcu_status;
664   system1_state *state = space->machine->driver_data<system1_state>();
665   return *state->nob_mcu_status;
665666}
666667
667668
r10427r10428
673674 *************************************/
674675
675676// nobb - these ports are used for some kind of replacement protection system used by the bootleg
676static int nobb_inport23_step;
677677
678678static READ8_HANDLER( nobb_inport1c_r )
679679{
r10427r10428
689689
690690static READ8_HANDLER( nobb_inport23_r )
691691{
692//  logerror("IN  $23 : pc = %04x - step = %02x\n",cpu_get_pc(space->cpu),nobb_inport23_step);
693   return(nobb_inport23_step);
692   system1_state *state = space->machine->driver_data<system1_state>();
693//  logerror("IN  $23 : pc = %04x - step = %02x\n",cpu_get_pc(space->cpu),state->nobb_inport23_step);
694   return(state->nobb_inport23_step);
694695}
695696
696697static WRITE8_HANDLER( nobb_outport24_w )
697698{
699   system1_state *state = space->machine->driver_data<system1_state>();
698700//  logerror("OUT $24 : pc = %04x - data = %02x\n",cpu_get_pc(space->cpu),data);
699   nobb_inport23_step = data;
701   state->nobb_inport23_step = data;
700702}
701703
702704
r10427r10428
711713static ADDRESS_MAP_START( system1_map, ADDRESS_SPACE_PROGRAM, 8 )
712714   AM_RANGE(0x0000, 0x7fff) AM_ROM
713715   AM_RANGE(0x8000, 0xbfff) AM_ROMBANK("bank1")
714   AM_RANGE(0xc000, 0xcfff) AM_RAM AM_BASE(&system1_ram)
716   AM_RANGE(0xc000, 0xcfff) AM_RAM AM_BASE_MEMBER(system1_state, ram)
715717   AM_RANGE(0xd000, 0xd7ff) AM_RAM AM_BASE_GENERIC(spriteram)
716718   AM_RANGE(0xd800, 0xdfff) AM_RAM_WRITE(system1_paletteram_w) AM_BASE_GENERIC(paletteram)
717719   AM_RANGE(0xe000, 0xefff) AM_READWRITE(system1_videoram_r, system1_videoram_w)
r10427r10428
732734   AM_RANGE(0xd000, 0xd7ff) AM_RAM AM_BASE_GENERIC(spriteram)
733735   AM_RANGE(0xd800, 0xdfff) AM_RAM_WRITE(system1_paletteram_w) AM_BASE_GENERIC(paletteram)
734736   AM_RANGE(0xe000, 0xefff) AM_READWRITE(system1_videoram_r, system1_videoram_w)
735   AM_RANGE(0xf000, 0xffff) AM_RAM AM_BASE(&system1_ram)
737   AM_RANGE(0xf000, 0xffff) AM_RAM AM_BASE_MEMBER(system1_state, ram)
736738ADDRESS_MAP_END
737739
738740/* I/O map for systems with an 8255 PPI */
r10427r10428
792794
793795static ADDRESS_MAP_START( nob_mcu_io_map, ADDRESS_SPACE_IO, 8 )
794796   ADDRESS_MAP_UNMAP_HIGH
795   AM_RANGE(MCS51_PORT_P0, MCS51_PORT_P0) AM_RAM AM_BASE(&nob_mcu_latch)
796   AM_RANGE(MCS51_PORT_P1, MCS51_PORT_P1) AM_WRITEONLY AM_BASE(&nob_mcu_status)
797   AM_RANGE(MCS51_PORT_P0, MCS51_PORT_P0) AM_RAM AM_BASE_MEMBER(system1_state, nob_mcu_latch)
798   AM_RANGE(MCS51_PORT_P1, MCS51_PORT_P1) AM_WRITEONLY AM_BASE_MEMBER(system1_state, nob_mcu_status)
797799   AM_RANGE(MCS51_PORT_P2, MCS51_PORT_P2) AM_WRITE(nob_mcu_control_p2_w)
798800ADDRESS_MAP_END
799801
r10427r10428
44904492 *
44914493 *************************************/
44924494
4493static DRIVER_INIT( bank00 )   { videomode_custom = NULL; }
4494static DRIVER_INIT( bank44 )   { videomode_custom = bank44_custom_w; }
4495static DRIVER_INIT( bank0c )   { videomode_custom = bank0c_custom_w; }
4495static DRIVER_INIT( bank00 )
4496{
4497   system1_state *state = machine->driver_data<system1_state>();
4498   state->videomode_custom = NULL;
4499}
4500static DRIVER_INIT( bank44 )
4501{
4502   system1_state *state = machine->driver_data<system1_state>();
4503   state->videomode_custom = bank44_custom_w;
4504}
44964505
4506static DRIVER_INIT( bank0c )
4507{
4508   system1_state *state = machine->driver_data<system1_state>();
4509   state->videomode_custom = bank0c_custom_w;
4510}
4511
44974512static DRIVER_INIT( regulus )   { DRIVER_INIT_CALL(bank00); regulus_decode(machine, "maincpu"); }
44984513static DRIVER_INIT( mrviking )   { DRIVER_INIT_CALL(bank00); mrviking_decode(machine, "maincpu"); }
44994514static DRIVER_INIT( swat )      { DRIVER_INIT_CALL(bank00); swat_decode(machine, "maincpu"); }
r10427r10428
45244539
45254540static DRIVER_INIT( dakkochn )
45264541{
4527   DRIVER_INIT_CALL(bank0c);
4528   videomode_custom = dakkochn_custom_w;
4542   system1_state *state = machine->driver_data<system1_state>();
4543   state->videomode_custom = dakkochn_custom_w;
45294544
45304545   mc8123_decrypt_rom(machine, "maincpu", "key", "bank1", 4);
45314546
src/mame/drivers/bfm_sc2.c
r10427r10428
163163#include "sltblgtk.lh"
164164#include "slots.lh"
165165
166class bfm_sc2_state : public driver_device
167{
168public:
169   bfm_sc2_state(running_machine &machine, const driver_device_config_base &config)
170      : driver_device(machine, config) { }
171
172   int sc2gui_update_mmtr;
173   UINT8 *nvram;
174   UINT8 key[16];
175   UINT8 e2ram[1024];
176   int mmtr_latch;
177   int triac_latch;
178   int vfd1_latch;
179   int vfd2_latch;
180   int irq_status;
181   int optic_pattern;
182   int uart1_data;
183   int uart2_data;
184   int data_to_uart1;
185   int data_to_uart2;
186   int locked;
187   int is_timer_enabled;
188   int reel_changed;
189   int coin_inhibits;
190   int irq_timer_stat;
191   int expansion_latch;
192   int global_volume;
193   int volume_override;
194   int sc2_show_door;
195   int sc2_door_state;
196   int reel12_latch;
197   int reel34_latch;
198   int reel56_latch;
199   int pay_latch;
200   int slide_states[6];
201   int slide_pay_sensor[6];
202   int has_hopper;
203   int triac_select;
204   int hopper_running;
205   int hopper_coin_sense;
206   int timercnt;
207   int watchdog_cnt;
208   int watchdog_kicked;
209   UINT8 Lamps[256];
210   UINT8 sc2_Inputs[64];
211   UINT8 input_override[64];
212   int e2reg;
213   int e2state;
214   int e2cnt;
215   int e2data;
216   int e2address;
217   int e2rw;
218   int e2data_pin;
219   int e2dummywrite;
220   int e2data_to_read;
221   UINT8 codec_data[256];
222};
223
224
166225#ifdef MAME_DEBUG
167226#define VERBOSE 1
168227#else
r10427r10428
178237
179238// local prototypes ///////////////////////////////////////////////////////
180239
181static int  get_scorpion2_uart_status(void);   // retrieve status of uart on scorpion2 board
240static int  read_e2ram(running_machine *machine);
241static void e2ram_reset(running_machine *machine);
182242
183static int  read_e2ram(void);
184static void e2ram_reset(void);
243// global vars ////////////////////////////////////////////////////////////
185244
245
186246// local vars /////////////////////////////////////////////////////////////
187247
188static UINT8 key[16];      // security device on gamecard (video games only)
189248
190static UINT8 e2ram[1024];   // x24C08 e2ram
191249
192static int mmtr_latch;      // mechanical meter latch
193static int triac_latch;      // payslide triac latch
194static int vfd1_latch;      // vfd1 latch
195static int vfd2_latch;      // vfd2 latch
196static int irq_status;      // custom chip IRQ status
197static int optic_pattern;   // reel optics
198static int uart1_data;
199static int uart2_data;
200static int data_to_uart1;
201static int data_to_uart2;
202static int locked;         // hardware lock/unlock status (0=unlocked)
203static int is_timer_enabled;
204static int reel_changed;
205static int coin_inhibits;
206static int irq_timer_stat;
207static int expansion_latch;
208static int global_volume;   // 0-31
209static int volume_override;   // 0 / 1
210250
211static int sc2_show_door;   // flag <>0, show door state
212static int sc2_door_state;   // door switch strobe/data
213251
214static int reel12_latch;
215static int reel34_latch;
216static int reel56_latch;
217static int pay_latch;
218252
219static int slide_states[6];
220static int slide_pay_sensor[6];
221253
222static int has_hopper;      // flag <>0, scorpion2 board has hopper connected
223254
224static int triac_select;
225255
226static int hopper_running;   // flag <>0, hopper is running used in some scorpion2 videogames
227static int hopper_coin_sense;
228static int timercnt;      // timer counts up every IRQ (=1000 times a second)
229256
230static int watchdog_cnt;
231static int watchdog_kicked;
232257
233258// user interface stuff ///////////////////////////////////////////////////
234259
235static UINT8 Lamps[256];
236static UINT8 sc2_Inputs[64];
237260
238static UINT8 input_override[64];// bit pattern, bit set means this input is overriden and cannot be changed with switches
239261
240262/*      INPUTS layout
241263
r10427r10428
281303
282304///////////////////////////////////////////////////////////////////////////
283305
284static int get_scorpion2_uart_status(void)
306static int get_scorpion2_uart_status(running_machine *machine)
285307{
286308   int status = 0;
287309
r10427r10428
297319
298320static void on_scorpion2_reset(running_machine *machine)
299321{
300   vfd1_latch        = 0;
301   vfd2_latch        = 0;
302   mmtr_latch        = 0;
303   triac_latch       = 0;
304   irq_status        = 0;
305   is_timer_enabled  = 1;
306   coin_inhibits     = 0;
307   irq_timer_stat    = 0;
308   expansion_latch   = 0;
309   global_volume     = 0;
310   volume_override   = 0;
311   triac_select      = 0;
312   pay_latch         = 0;
322   bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>();
323   state->vfd1_latch        = 0;
324   state->vfd2_latch        = 0;
325   state->mmtr_latch        = 0;
326   state->triac_latch       = 0;
327   state->irq_status        = 0;
328   state->is_timer_enabled  = 1;
329   state->coin_inhibits     = 0;
330   state->irq_timer_stat    = 0;
331   state->expansion_latch   = 0;
332   state->global_volume     = 0;
333   state->volume_override   = 0;
334   state->triac_select      = 0;
335   state->pay_latch         = 0;
313336
314   reel12_latch      = 0;
315   reel34_latch      = 0;
316   reel56_latch      = 0;
337   state->reel12_latch      = 0;
338   state->reel34_latch      = 0;
339   state->reel56_latch      = 0;
317340
318   hopper_running    = 0;  // for video games
319   hopper_coin_sense = 0;
341   state->hopper_running    = 0;  // for video games
342   state->hopper_coin_sense = 0;
320343
321   slide_states[0] = 0;
322   slide_states[1] = 0;
323   slide_states[2] = 0;
324   slide_states[3] = 0;
325   slide_states[4] = 0;
326   slide_states[5] = 0;
344   state->slide_states[0] = 0;
345   state->slide_states[1] = 0;
346   state->slide_states[2] = 0;
347   state->slide_states[3] = 0;
348   state->slide_states[4] = 0;
349   state->slide_states[5] = 0;
327350
328   watchdog_cnt    = 0;
329   watchdog_kicked = 0;
351   state->watchdog_cnt    = 0;
352   state->watchdog_kicked = 0;
330353
331354
332355   BFM_BD1_reset(0);   // reset display1
333356   BFM_BD1_reset(1);   // reset display2
334357
335   e2ram_reset();
358   e2ram_reset(machine);
336359
337360   devtag_reset(machine, "ymsnd");
338361
r10427r10428
350373         if ( stepper_optic_state(i) ) pattern |= 1<<i;
351374      }
352375
353      optic_pattern = pattern;
376      state->optic_pattern = pattern;
354377
355378   }
356379
357   locked        = 0;
380   state->locked        = 0;
358381
359382   // make sure no inputs are overidden ////////////////////////////////////
360   memset(input_override, 0, sizeof(input_override));
383   memset(state->input_override, 0, sizeof(state->input_override));
361384
362385   // init rom bank ////////////////////////////////////////////////////////
363386
r10427r10428
373396
374397///////////////////////////////////////////////////////////////////////////
375398
376void Scorpion2_SetSwitchState(int strobe, int data, int state)
399void Scorpion2_SetSwitchState(running_machine *machine, int strobe, int data, int state)
377400{
401   bfm_sc2_state *drvstate = machine->driver_data<bfm_sc2_state>();
378402   if ( strobe < 11 && data < 8 )
379403   {
380404      if ( strobe < 8 )
381405      {
382         input_override[strobe] |= (1<<data);
406         drvstate->input_override[strobe] |= (1<<data);
383407
384         if ( state ) sc2_Inputs[strobe] |=  (1<<data);
385         else       sc2_Inputs[strobe] &= ~(1<<data);
408         if ( state ) drvstate->sc2_Inputs[strobe] |=  (1<<data);
409         else       drvstate->sc2_Inputs[strobe] &= ~(1<<data);
386410      }
387411      else
388412      {
389413         if ( data > 2 )
390414         {
391            input_override[strobe-8+4] |= (1<<(data+2));
415            drvstate->input_override[strobe-8+4] |= (1<<(data+2));
392416
393            if ( state ) sc2_Inputs[strobe-8+4] |=  (1<<(data+2));
394            else       sc2_Inputs[strobe-8+4] &= ~(1<<(data+2));
417            if ( state ) drvstate->sc2_Inputs[strobe-8+4] |=  (1<<(data+2));
418            else       drvstate->sc2_Inputs[strobe-8+4] &= ~(1<<(data+2));
395419         }
396420         else
397421         {
398            input_override[strobe-8] |= (1<<(data+5));
422            drvstate->input_override[strobe-8] |= (1<<(data+5));
399423
400            if ( state ) sc2_Inputs[strobe-8] |=  (1 << (data+5));
401            else       sc2_Inputs[strobe-8] &= ~(1 << (data+5));
424            if ( state ) drvstate->sc2_Inputs[strobe-8] |=  (1 << (data+5));
425            else       drvstate->sc2_Inputs[strobe-8] &= ~(1 << (data+5));
402426         }
403427      }
404428   }
r10427r10428
406430
407431///////////////////////////////////////////////////////////////////////////
408432
409int Scorpion2_GetSwitchState(int strobe, int data)
433int Scorpion2_GetSwitchState(running_machine *machine, int strobe, int data)
410434{
435   bfm_sc2_state *drvstate = machine->driver_data<bfm_sc2_state>();
411436   int state = 0;
412437
413438   if ( strobe < 11 && data < 8 )
414439   {
415440      if ( strobe < 8 )
416441      {
417         state = (sc2_Inputs[strobe] & (1<<data) ) ? 1 : 0;
442         state = (drvstate->sc2_Inputs[strobe] & (1<<data) ) ? 1 : 0;
418443      }
419444      else
420445      {
421446         if ( data > 2 )
422447         {
423            state = (sc2_Inputs[strobe-8+4] & (1<<(data+2)) ) ? 1 : 0;
448            state = (drvstate->sc2_Inputs[strobe-8+4] & (1<<(data+2)) ) ? 1 : 0;
424449         }
425450         else
426451         {
427            state = (sc2_Inputs[strobe-8] & (1 << (data+5)) ) ? 1 : 0;
452            state = (drvstate->sc2_Inputs[strobe-8] & (1 << (data+5)) ) ? 1 : 0;
428453         }
429454      }
430455   }
r10427r10428
435460
436461static NVRAM_HANDLER( bfm_sc2 )
437462{
463   bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>();
438464   static const UINT8 init_e2ram[10] = { 1, 4, 10, 20, 0, 1, 1, 4, 10, 20 };
439465   if ( read_or_write )
440466   {   // writing
441      file->write(e2ram,sizeof(e2ram));
467      file->write(state->e2ram,sizeof(state->e2ram));
442468   }
443469   else
444470   { // reading
445471      if ( file )
446472      {
447         file->read(e2ram,sizeof(e2ram));
473         file->read(state->e2ram,sizeof(state->e2ram));
448474      }
449475      else
450476      {
451         memset(e2ram,0x00,sizeof(e2ram));
452         memcpy(e2ram,init_e2ram,sizeof(init_e2ram));
477         memset(state->e2ram,0x00,sizeof(state->e2ram));
478         memcpy(state->e2ram,init_e2ram,sizeof(init_e2ram));
453479      }
454480   }
455481}
r10427r10428
458484
459485static WRITE8_HANDLER( watchdog_w )
460486{
461   watchdog_kicked = 1;
487   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
488   state->watchdog_kicked = 1;
462489}
463490
464491///////////////////////////////////////////////////////////////////////////
r10427r10428
472499
473500static INTERRUPT_GEN( timer_irq )
474501{
475   timercnt++;
502   bfm_sc2_state *state = device->machine->driver_data<bfm_sc2_state>();
503   state->timercnt++;
476504
477   if ( watchdog_kicked )
505   if ( state->watchdog_kicked )
478506   {
479      watchdog_cnt    = 0;
480      watchdog_kicked = 0;
507      state->watchdog_cnt    = 0;
508      state->watchdog_kicked = 0;
481509   }
482510   else
483511   {
484      watchdog_cnt++;
485      if ( watchdog_cnt > 2 )   // this is a hack, i don't know what the watchdog timeout is, 3 IRQ's works fine
512      state->watchdog_cnt++;
513      if ( state->watchdog_cnt > 2 )   // this is a hack, i don't know what the watchdog timeout is, 3 IRQ's works fine
486514      {  // reset board
487515         device->machine->schedule_soft_reset();      // reset entire machine. CPU 0 should be enough, but that doesn't seem to work !!
488516         on_scorpion2_reset(device->machine);
r10427r10428
490518      }
491519   }
492520
493   if ( is_timer_enabled )
521   if ( state->is_timer_enabled )
494522   {
495      irq_timer_stat = 0x01;
496      irq_status     = 0x02;
523      state->irq_timer_stat = 0x01;
524      state->irq_status     = 0x02;
497525
498526      generic_pulse_irq_line(device, M6809_IRQ_LINE);
499527   }
r10427r10428
503531
504532static WRITE8_HANDLER( reel12_vid_w )  // in a video cabinet this is used to drive a hopper
505533{
506   reel12_latch = data;
534   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
535   state->reel12_latch = data;
507536
508   if ( has_hopper )
537   if ( state->has_hopper )
509538   {
510      int oldhop = hopper_running;
539      int oldhop = state->hopper_running;
511540
512541      if ( data & 0x01 )
513542      { // hopper power
514543         if ( data & 0x02 )
515544         {
516            hopper_running    = 1;
545            state->hopper_running    = 1;
517546         }
518547         else
519548         {
520            hopper_running    = 0;
549            state->hopper_running    = 0;
521550         }
522551      }
523552      else
524553      {
525         //hopper_coin_sense = 0;
526         hopper_running    = 0;
554         //state->hopper_coin_sense = 0;
555         state->hopper_running    = 0;
527556      }
528557
529      if ( oldhop != hopper_running )
558      if ( oldhop != state->hopper_running )
530559      {
531         hopper_coin_sense = 0;
532         oldhop = hopper_running;
560         state->hopper_coin_sense = 0;
561         oldhop = state->hopper_running;
533562      }
534563   }
535564}
r10427r10428
538567
539568static WRITE8_HANDLER( reel34_w )
540569{
541   reel34_latch = data;
570   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
571   state->reel34_latch = data;
542572
543   if ( stepper_update(2, data   ) ) reel_changed |= 0x04;
544   if ( stepper_update(3, data>>4) ) reel_changed |= 0x08;
573   if ( stepper_update(2, data   ) ) state->reel_changed |= 0x04;
574   if ( stepper_update(3, data>>4) ) state->reel_changed |= 0x08;
545575
546   if ( stepper_optic_state(2) ) optic_pattern |=  0x04;
547   else                          optic_pattern &= ~0x04;
548   if ( stepper_optic_state(3) ) optic_pattern |=  0x08;
549   else                          optic_pattern &= ~0x08;
576   if ( stepper_optic_state(2) ) state->optic_pattern |=  0x04;
577   else                          state->optic_pattern &= ~0x04;
578   if ( stepper_optic_state(3) ) state->optic_pattern |=  0x08;
579   else                          state->optic_pattern &= ~0x08;
550580
551581   awp_draw_reel(2);
552582   awp_draw_reel(3);
r10427r10428
556586
557587static WRITE8_HANDLER( reel56_w )
558588{
559   reel56_latch = data;
589   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
590   state->reel56_latch = data;
560591
561   if ( stepper_update(4, data   ) ) reel_changed |= 0x10;
562   if ( stepper_update(5, data>>4) ) reel_changed |= 0x20;
592   if ( stepper_update(4, data   ) ) state->reel_changed |= 0x10;
593   if ( stepper_update(5, data>>4) ) state->reel_changed |= 0x20;
563594
564   if ( stepper_optic_state(4) ) optic_pattern |=  0x10;
565   else                          optic_pattern &= ~0x10;
566   if ( stepper_optic_state(5) ) optic_pattern |=  0x20;
567   else                          optic_pattern &= ~0x20;
595   if ( stepper_optic_state(4) ) state->optic_pattern |=  0x10;
596   else                          state->optic_pattern &= ~0x10;
597   if ( stepper_optic_state(5) ) state->optic_pattern |=  0x20;
598   else                          state->optic_pattern &= ~0x20;
568599
569600   awp_draw_reel(4);
570601   awp_draw_reel(5);
r10427r10428
576607
577608static WRITE8_HANDLER( mmtr_w )
578609{
610   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
579611   int i;
580   int  changed = mmtr_latch ^ data;
612   int  changed = state->mmtr_latch ^ data;
581613
582   mmtr_latch = data;
614   state->mmtr_latch = data;
583615
584616   for (i = 0; i<8; i++)
585617   {
r10427r10428
595627
596628static WRITE8_HANDLER( mux_output_w )
597629{
630   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
598631   int i;
599632   int off = offset<<3;
600633
601634   for (i=0; i<8; i++)
602635   {
603      Lamps[ off+i ] = (data & (1 << i)) != 0;
636      state->Lamps[ off+i ] = (data & (1 << i)) != 0;
604637   }
605638   if (offset == 0) // update all lamps after strobe 0 has been updated (HACK)
606639   {
607640      for ( i = 0; i < 256; i++ )
608641      {
609         output_set_lamp_value(i, Lamps[i]);
642         output_set_lamp_value(i, state->Lamps[i]);
610643      }
611644   }
612645}
r10427r10428
615648
616649static READ8_HANDLER( mux_input_r )
617650{
651   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
618652   int result = 0xFF,t1,t2;
619653   static const char *const port[] = { "STROBE0", "STROBE1", "STROBE2", "STROBE3", "STROBE4", "STROBE5", "STROBE6", "STROBE7", "STROBE8", "STROBE9", "STROBE10", "STROBE11" };
620654
621655   if (offset < 8)
622656   {
623657      int idx = (offset & 4) ? 4 : 8;
624      t1 = input_override[offset];   // strobe 0-7 data 0-4
625      t2 = input_override[offset+idx];   // strobe 8-B data 0-4
658      t1 = state->input_override[offset];   // strobe 0-7 data 0-4
659      t2 = state->input_override[offset+idx];   // strobe 8-B data 0-4
626660
627      t1 = (sc2_Inputs[offset]   & t1) | ( ( input_port_read(space->machine, port[offset])   & ~t1) & 0x1F);
661      t1 = (state->sc2_Inputs[offset]   & t1) | ( ( input_port_read(space->machine, port[offset])   & ~t1) & 0x1F);
628662      if (idx == 8)
629         t2 = (sc2_Inputs[offset+8] & t2) | ( ( input_port_read(space->machine, port[offset+8]) & ~t2) << 5);
663         t2 = (state->sc2_Inputs[offset+8] & t2) | ( ( input_port_read(space->machine, port[offset+8]) & ~t2) << 5);
630664      else
631         t2 =  (sc2_Inputs[offset+4] & t2) | ( ( ( input_port_read(space->machine, port[offset+4]) & ~t2) << 2) & 0x60);
665         t2 =  (state->sc2_Inputs[offset+4] & t2) | ( ( ( input_port_read(space->machine, port[offset+4]) & ~t2) << 2) & 0x60);
632666
633      sc2_Inputs[offset]   = (sc2_Inputs[offset]   & ~0x1F) | t1;
634      sc2_Inputs[offset+idx] = (sc2_Inputs[offset+idx] & ~0x60) | t2;
667      state->sc2_Inputs[offset]   = (state->sc2_Inputs[offset]   & ~0x1F) | t1;
668      state->sc2_Inputs[offset+idx] = (state->sc2_Inputs[offset+idx] & ~0x60) | t2;
635669      result = t1 | t2;
636670   }
637671
r10427r10428
666700
667701static WRITE8_HANDLER( volume_override_w )
668702{
669   int old = volume_override;
703   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
704   int old = state->volume_override;
670705
671   volume_override = data?1:0;
706   state->volume_override = data?1:0;
672707
673   if ( old != volume_override )
708   if ( old != state->volume_override )
674709   {
675710      ym2413_device *ym = space->machine->device<ym2413_device>("ymsnd");
676711      upd7759_device *upd = space->machine->device<upd7759_device>("upd");
677      float percent = volume_override? 1.0f : (32-global_volume)/32.0f;
712      float percent = state->volume_override? 1.0f : (32-state->global_volume)/32.0f;
678713
679714      ym->set_output_gain(0, percent);
680715      ym->set_output_gain(1, percent);
r10427r10428
694729
695730static WRITE8_DEVICE_HANDLER( nec_latch_w )
696731{
732   bfm_sc2_state *state = device->machine->driver_data<bfm_sc2_state>();
697733   int bank = 0;
698734
699735   if ( data & 0x80 )         bank |= 0x01;
700   if ( expansion_latch & 2 ) bank |= 0x02;
736   if ( state->expansion_latch & 2 ) bank |= 0x02;
701737
702738   upd7759_set_bank_base(device, bank*0x20000);
703739
r10427r10428
710746
711747static READ8_HANDLER( vfd_status_hop_r )   // on video games, hopper inputs are connected to this
712748{
749   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
713750   // b7 = NEC busy
714751   // b6 = alpha busy (also matrix board)
715752   // b5 - b0 = reel optics
716753
717754   int result = 0;
718755
719   if ( has_hopper )
756   if ( state->has_hopper )
720757   {
721758      result |= 0x04; // hopper high level
722759      result |= 0x08; // hopper low  level
723760
724761      result |= 0x01|0x02;
725762
726      if ( hopper_running )
763      if ( state->hopper_running )
727764      {
728765         result &= ~0x01;                          // set motor running input
729766
730         if ( timercnt & 0x04 ) hopper_coin_sense ^= 1;     // toggle coin seen
767         if ( state->timercnt & 0x04 ) state->hopper_coin_sense ^= 1;     // toggle coin seen
731768
732         if ( hopper_coin_sense ) result &= ~0x02;        // update coin seen input
769         if ( state->hopper_coin_sense ) result &= ~0x02;        // update coin seen input
733770      }
734771   }
735772
r10427r10428
742779
743780static WRITE8_HANDLER( expansion_latch_w )
744781{
745   int changed = expansion_latch^data;
782   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
783   int changed = state->expansion_latch^data;
746784
747   expansion_latch = data;
785   state->expansion_latch = data;
748786
749787   // bit0,  1 = lamp mux disabled, 0 = lamp mux enabled
750788   // bit1,  ? used in Del's millions
r10427r10428
761799      { // changed from high to low,
762800         if ( !(data & 0x08) )
763801         {
764            if ( global_volume < 31 ) global_volume++; //0-31 expressed as 1-32
802            if ( state->global_volume < 31 ) state->global_volume++; //0-31 expressed as 1-32
765803         }
766804         else
767805         {
768            if ( global_volume > 0  ) global_volume--;
806            if ( state->global_volume > 0  ) state->global_volume--;
769807         }
770808
771809         {
772810            ym2413_device *ym = space->machine->device<ym2413_device>("ymsnd");
773811            upd7759_device *upd = space->machine->device<upd7759_device>("upd");
774            float percent = volume_override ? 1.0f : (32-global_volume)/32.0f;
812            float percent = state->volume_override ? 1.0f : (32-state->global_volume)/32.0f;
775813
776814            ym->set_output_gain(0, percent);
777815            ym->set_output_gain(1, percent);
r10427r10428
798836
799837static WRITE8_HANDLER( timerirq_w )
800838{
801   is_timer_enabled = data & 1;
839   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
840   state->is_timer_enabled = data & 1;
802841}
803842
804843///////////////////////////////////////////////////////////////////////////
805844
806845static READ8_HANDLER( timerirqclr_r )
807846{
808   irq_timer_stat = 0;
809   irq_status     = 0;
847   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
848   state->irq_timer_stat = 0;
849   state->irq_status     = 0;
810850
811851   return 0;
812852}
r10427r10428
815855
816856static READ8_HANDLER( irqstatus_r )
817857{
818   int result = irq_status | irq_timer_stat | 0x80;   // 0x80 = ~MUXERROR
858   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
859   int result = state->irq_status | state->irq_timer_stat | 0x80;   // 0x80 = ~MUXERROR
819860
820   irq_timer_stat = 0;
861   state->irq_timer_stat = 0;
821862
822863   return result;
823864}
r10427r10428
826867
827868static WRITE8_HANDLER( coininhib_w )
828869{
829   int changed = coin_inhibits^data,i,p;
870   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
871   int changed = state->coin_inhibits^data,i,p;
830872
831   coin_inhibits = data;
873   state->coin_inhibits = data;
832874
833875   p = 0x01;
834876   i = 0;
r10427r10428
857899
858900static WRITE8_HANDLER( payout_latch_w )
859901{
860   pay_latch = data;
902   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
903   state->pay_latch = data;
861904}
862905
863906///////////////////////////////////////////////////////////////////////////
864907
865908static WRITE8_HANDLER( payout_triac_w )
866909{
867   if ( triac_select == 0x57 )
910   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
911   if ( state->triac_select == 0x57 )
868912   {
869913      int slide = 0;
870914
871      switch ( pay_latch )
915      switch ( state->pay_latch )
872916      {
873917         case 0x01: slide = 1;
874918            break;
r10427r10428
893937      {
894938         if ( data == 0x4D )
895939         {
896            if ( !slide_states[slide] )
940            if ( !state->slide_states[slide] )
897941            {
898               if ( slide_pay_sensor[slide] )
942               if ( state->slide_pay_sensor[slide] )
899943               {
900                  int strobe = slide_pay_sensor[slide]>>4, data = slide_pay_sensor[slide]&0x0F;
944                  int strobe = state->slide_pay_sensor[slide]>>4, data = state->slide_pay_sensor[slide]&0x0F;
901945
902                  Scorpion2_SetSwitchState(strobe, data, 0);
946                  Scorpion2_SetSwitchState(space->machine, strobe, data, 0);
903947               }
904               slide_states[slide] = 1;
948               state->slide_states[slide] = 1;
905949            }
906950         }
907951         else
908952         {
909            if ( slide_states[slide] )
953            if ( state->slide_states[slide] )
910954            {
911               if ( slide_pay_sensor[slide] )
955               if ( state->slide_pay_sensor[slide] )
912956               {
913                  int strobe = slide_pay_sensor[slide]>>4, data = slide_pay_sensor[slide]&0x0F;
957                  int strobe = state->slide_pay_sensor[slide]>>4, data = state->slide_pay_sensor[slide]&0x0F;
914958
915                  Scorpion2_SetSwitchState(strobe, data, 1);
959                  Scorpion2_SetSwitchState(space->machine, strobe, data, 1);
916960               }
917               slide_states[slide] = 0;
961               state->slide_states[slide] = 0;
918962            }
919963         }
920964      }
r10427r10428
925969
926970static WRITE8_HANDLER( payout_select_w )
927971{
928   triac_select = data;
972   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
973   state->triac_select = data;
929974}
930975
931976///////////////////////////////////////////////////////////////////////////
932977
933978static WRITE8_HANDLER( vfd1_data_w )
934979{
935   vfd1_latch = data;
980   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
981   state->vfd1_latch = data;
936982   BFM_BD1_newdata(0, data);
937983   BFM_BD1_draw(0);
938984}
r10427r10428
941987
942988static WRITE8_HANDLER( vfd2_data_w )
943989{
944   vfd2_latch = data;
990   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
991   state->vfd2_latch = data;
945992   BFM_BD1_newdata(1, data);
946993   BFM_BD1_draw(1);
947994}
r10427r10428
9621009
9631010static READ8_HANDLER( uart1stat_r )
9641011{
1012   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
9651013   int status = 0x06;
9661014
967   if ( data_to_uart1  ) status |= 0x01;
968   if ( !data_to_uart2 ) status |= 0x02;
1015   if ( state->data_to_uart1  ) status |= 0x01;
1016   if ( !state->data_to_uart2 ) status |= 0x02;
9691017
9701018   return status;
9711019}
r10427r10428
9731021
9741022static READ8_HANDLER( uart1data_r )
9751023{
976   return uart1_data;
1024   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
1025   return state->uart1_data;
9771026}
9781027
9791028//////////////////////////////////////////////////////////////////////////
r10427r10428
9861035
9871036static WRITE8_HANDLER( uart1data_w )
9881037{
989   data_to_uart2 = 1;
990   uart1_data    = data;
1038   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
1039   state->data_to_uart2 = 1;
1040   state->uart1_data    = data;
9911041   UART_LOG(("uart1:%x\n", data));
9921042}
9931043///////////////////////////////////////////////////////////////////////////
9941044
9951045static READ8_HANDLER( uart2stat_r )
9961046{
1047   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
9971048   int status = 0x06;
9981049
999   if ( data_to_uart2  ) status |= 0x01;
1000   if ( !data_to_uart1 ) status |= 0x02;
1050   if ( state->data_to_uart2  ) status |= 0x01;
1051   if ( !state->data_to_uart1 ) status |= 0x02;
10011052
10021053   return status;
10031054}
r10427r10428
10051056
10061057static READ8_HANDLER( uart2data_r )
10071058{
1008   return uart2_data;
1059   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
1060   return state->uart2_data;
10091061}
10101062
10111063///////////////////////////////////////////////////////////////////////////
r10427r10428
10191071
10201072static WRITE8_HANDLER( uart2data_w )
10211073{
1022   data_to_uart1 = 1;
1023   uart2_data    = data;
1074   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
1075   state->data_to_uart1 = 1;
1076   state->uart2_data    = data;
10241077   UART_LOG(("uart2:%x\n", data));
10251078}
10261079
r10427r10428
10481101
10491102static READ8_HANDLER( vid_uart_ctrl_r )
10501103{
1051   return get_scorpion2_uart_status();
1104   return get_scorpion2_uart_status(space->machine);
10521105}
10531106
10541107///////////////////////////////////////////////////////////////////////////
10551108
10561109static READ8_HANDLER( key_r )
10571110{
1058   int result = key[ offset ];
1111   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
1112   int result = state->key[ offset ];
10591113
10601114   if ( offset == 7 )
10611115   {
1062      result = (result & 0xFE) | read_e2ram();
1116      result = (result & 0xFE) | read_e2ram(space->machine);
10631117   }
10641118
10651119   return result;
r10427r10428
10761130*/
10771131
10781132
1079static int e2reg;
1080static int e2state;
1081static int e2cnt;
1082static int e2data;
1083static int e2address;
1084static int e2rw;
1085static int e2data_pin;
1086static int e2dummywrite;
10871133
1088static int e2data_to_read;
10891134
10901135#define SCL 0x01   //SCL pin (clock)
10911136#define SDA   0x02   //SDA pin (data)
10921137
10931138
1094static void e2ram_reset(void)
1139static void e2ram_reset(running_machine *machine)
10951140{
1096   e2reg   = 0;
1097   e2state = 0;
1098   e2address = 0;
1099   e2rw    = 0;
1100   e2data_pin = 0;
1101   e2data  = (SDA|SCL);
1102   e2dummywrite = 0;
1103   e2data_to_read = 0;
1141   bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>();
1142   state->e2reg   = 0;
1143   state->e2state = 0;
1144   state->e2address = 0;
1145   state->e2rw    = 0;
1146   state->e2data_pin = 0;
1147   state->e2data  = (SDA|SCL);
1148   state->e2dummywrite = 0;
1149   state->e2data_to_read = 0;
11041150}
11051151
1106static int recdata(int changed, int data)
1152static int recdata(bfm_sc2_state *state, int changed, int data)
11071153{
11081154   int res = 1;
11091155
1110   if ( e2cnt < 8 )
1156   if ( state->e2cnt < 8 )
11111157   {
11121158      res = 0;
11131159
11141160      if ( (changed & SCL) && (data & SCL) )
11151161      { // clocked in new data
1116         int pattern = 1 << (7-e2cnt);
1162         int pattern = 1 << (7-state->e2cnt);
11171163
1118         if ( data & SDA ) e2data |=  pattern;
1119         else              e2data &= ~pattern;
1164         if ( data & SDA ) state->e2data |=  pattern;
1165         else              state->e2data &= ~pattern;
11201166
1121         e2data_pin = e2data_to_read & 0x80 ? 1 : 0;
1167         state->e2data_pin = state->e2data_to_read & 0x80 ? 1 : 0;
11221168
1123         e2data_to_read <<= 1;
1169         state->e2data_to_read <<= 1;
11241170
1125         LOG(("e2d pin= %d\n", e2data_pin));
1171         LOG(("e2d pin= %d\n", state->e2data_pin));
11261172
1127         e2cnt++;
1128         if ( e2cnt >= 8 )
1173         state->e2cnt++;
1174         if ( state->e2cnt >= 8 )
11291175         {
11301176            res++;
11311177         }
r10427r10428
11551201
11561202//
11571203static WRITE8_HANDLER( e2ram_w )
1158{ // b0 = clock b1 = data
1204{
1205   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); // b0 = clock b1 = data
11591206
11601207   int changed, ack;
11611208
11621209   data ^= (SDA|SCL);  // invert signals
11631210
1164   changed  = (e2reg^data) & 0x03;
1211   changed  = (state->e2reg^data) & 0x03;
11651212
1166   e2reg = data;
1213   state->e2reg = data;
11671214
11681215   if ( changed )
11691216   {
r10427r10428
11731220            ( !(changed & SCL) && (data & SCL) )    // SCL=1 and not changed
11741221            )
11751222         {   // X24C08 Start condition (1->0 on SDA while SCL=1)
1176            e2dummywrite = ( e2state == 5 );
1223            state->e2dummywrite = ( state->e2state == 5 );
11771224
1178            LOG(("e2ram:   c:%d d:%d Start condition dummywrite=%d\n", (data & SCL)?1:0, (data&SDA)?1:0, e2dummywrite ));
1225            LOG(("e2ram:   c:%d d:%d Start condition dummywrite=%d\n", (data & SCL)?1:0, (data&SDA)?1:0, state->e2dummywrite ));
11791226
1180            e2state = 1; // ready for commands
1181            e2cnt   = 0;
1182            e2data  = 0;
1227            state->e2state = 1; // ready for commands
1228            state->e2cnt   = 0;
1229            state->e2data  = 0;
11831230            break;
11841231         }
11851232
r10427r10428
11881235            )
11891236         {   // X24C08 Stop condition (0->1 on SDA while SCL=1)
11901237            LOG(("e2ram:   c:%d d:%d Stop condition\n", (data & SCL)?1:0, (data&SDA)?1:0 ));
1191            e2state = 0;
1192            e2data  = 0;
1238            state->e2state = 0;
1239            state->e2data  = 0;
11931240            break;
11941241         }
11951242
1196         switch ( e2state )
1243         switch ( state->e2state )
11971244         {
11981245            case 1: // Receiving address + R/W bit
11991246
1200               if ( recdata(changed, data) )
1247               if ( recdata(state, changed, data) )
12011248               {
1202                  e2address = (e2address & 0x00FF) | ((e2data>>1) & 0x03) << 8;
1203                  e2cnt   = 0;
1204                  e2rw    = e2data & 1;
1249                  state->e2address = (state->e2address & 0x00FF) | ((state->e2data>>1) & 0x03) << 8;
1250                  state->e2cnt   = 0;
1251                  state->e2rw    = state->e2data & 1;
12051252
12061253                  LOG(("e2ram: Slave address received !!  device id=%01X device adr=%01d high order adr %0X RW=%d) %02X\n",
1207                     e2data>>4, (e2data & 0x08)?1:0, (e2data>>1) & 0x03, e2rw , e2data ));
1254                     state->e2data>>4, (state->e2data & 0x08)?1:0, (state->e2data>>1) & 0x03, state->e2rw , state->e2data ));
12081255
1209                  e2state = 2;
1256                  state->e2state = 2;
12101257               }
12111258               break;
12121259
r10427r10428
12151262               ack = recAck(changed,data);
12161263               if ( ack )
12171264               {
1218                  e2data_pin = 0;
1265                  state->e2data_pin = 0;
12191266
12201267                  if ( ack < 0 )
12211268                  {
12221269                     LOG(("ACK = 0\n"));
1223                     e2state = 0;
1270                     state->e2state = 0;
12241271                  }
12251272                  else
12261273                  {
12271274                     LOG(("ACK = 1\n"));
1228                     if ( e2dummywrite )
1275                     if ( state->e2dummywrite )
12291276                     {
1230                        e2dummywrite = 0;
1277                        state->e2dummywrite = 0;
12311278
1232                        e2data_to_read = e2ram[e2address];
1279                        state->e2data_to_read = state->e2ram[state->e2address];
12331280
1234                        if ( e2rw & 1 ) e2state = 7; // read data
1235                        else        e2state = 0; //?not sure
1281                        if ( state->e2rw & 1 ) state->e2state = 7; // read data
1282                        else        state->e2state = 0; //?not sure
12361283                     }
12371284                     else
12381285                     {
1239                        if ( e2rw & 1 ) e2state = 7; // reading
1240                        else            e2state = 3; // writing
1286                        if ( state->e2rw & 1 ) state->e2state = 7; // reading
1287                        else            state->e2state = 3; // writing
12411288                     }
1242                     switch ( e2state )
1289                     switch ( state->e2state )
12431290                     {
12441291                        case 7:
1245                           LOG(("read address %04X\n",e2address));
1246                           e2data_to_read = e2ram[e2address];
1292                           LOG(("read address %04X\n",state->e2address));
1293                           state->e2data_to_read = state->e2ram[state->e2address];
12471294                           break;
12481295                        case 3:
12491296                           LOG(("write, awaiting address\n"));
12501297                           break;
12511298                        default:
1252                           LOG(("?unknow action %04X\n",e2address));
1299                           LOG(("?unknow action %04X\n",state->e2address));
12531300                           break;
12541301                     }
12551302                  }
1256                  e2data = 0;
1303                  state->e2data = 0;
12571304               }
12581305               break;
12591306
12601307            case 3: // writing data, receiving address
12611308
1262               if ( recdata(changed, data) )
1309               if ( recdata(state, changed, data) )
12631310               {
1264                  e2data_pin = 0;
1265                  e2address = (e2address & 0xFF00) | e2data;
1311                  state->e2data_pin = 0;
1312                  state->e2address = (state->e2address & 0xFF00) | state->e2data;
12661313
1267                  LOG(("write address = %04X waiting for ACK\n", e2address));
1268                  e2state = 4;
1269                  e2cnt   = 0;
1270                  e2data  = 0;
1314                  LOG(("write address = %04X waiting for ACK\n", state->e2address));
1315                  state->e2state = 4;
1316                  state->e2cnt   = 0;
1317                  state->e2data  = 0;
12711318               }
12721319               break;
12731320
r10427r10428
12761323               ack = recAck(changed,data);
12771324               if ( ack )
12781325               {
1279                  e2data_pin = 0;   // pin=0, no error !!
1326                  state->e2data_pin = 0;   // pin=0, no error !!
12801327
12811328                  if ( ack < 0 )
12821329                  {
1283                     e2state = 0;
1330                     state->e2state = 0;
12841331                     LOG(("ACK = 0, cancel write\n" ));
12851332                  }
12861333                  else
12871334                  {
1288                     e2state = 5;
1335                     state->e2state = 5;
12891336                     LOG(("ACK = 1, awaiting data to write\n" ));
12901337                  }
12911338               }
12921339               break;
12931340
12941341            case 5: // receive data to write
1295               if ( recdata(changed, data) )
1342               if ( recdata(state, changed, data) )
12961343               {
1297                  LOG(("write data = %02X received, awaiting ACK\n", e2data));
1298                  e2cnt   = 0;
1299                  e2state = 6;  // wait ack
1344                  LOG(("write data = %02X received, awaiting ACK\n", state->e2data));
1345                  state->e2cnt   = 0;
1346                  state->e2state = 6;  // wait ack
13001347               }
13011348               break;
13021349
r10427r10428
13071354               {
13081355                  if ( ack < 0 )
13091356                  {
1310                     e2state = 0;
1357                     state->e2state = 0;
13111358                     LOG(("ACK=0, write canceled\n"));
13121359                  }
13131360                  else
13141361                  {
1315                     LOG(("ACK=1, writing %02X to %04X\n", e2data, e2address));
1362                     LOG(("ACK=1, writing %02X to %04X\n", state->e2data, state->e2address));
13161363
1317                     e2ram[e2address] = e2data;
1364                     state->e2ram[state->e2address] = state->e2data;
13181365
1319                     e2address = (e2address & ~0x000F) | ((e2address+1)&0x0F);
1366                     state->e2address = (state->e2address & ~0x000F) | ((state->e2address+1)&0x0F);
13201367
1321                     e2state = 5; // write next address
1368                     state->e2state = 5; // write next address
13221369                  }
13231370               }
13241371               break;
13251372
13261373            case 7: // receive address from read
13271374
1328               if ( recdata(changed, data) )
1375               if ( recdata(state, changed, data) )
13291376               {
1330                  //e2data_pin = 0;
1377                  //state->e2data_pin = 0;
13311378
1332                  LOG(("address read, data = %02X waiting for ACK\n", e2data ));
1379                  LOG(("address read, data = %02X waiting for ACK\n", state->e2data ));
13331380
1334                  e2state = 8;
1381                  state->e2state = 8;
13351382               }
13361383               break;
13371384
r10427r10428
13391386
13401387               if ( recAck(changed, data) )
13411388               {
1342                  e2state = 7;
1389                  state->e2state = 7;
13431390
1344                  e2address = (e2address & ~0x0F) | ((e2address+1)&0x0F); // lower 4 bits wrap around
1391                  state->e2address = (state->e2address & ~0x0F) | ((state->e2address+1)&0x0F); // lower 4 bits wrap around
13451392
1346                  e2data_to_read = e2ram[e2address];
1393                  state->e2data_to_read = state->e2ram[state->e2address];
13471394
1348                  LOG(("ready for next address %04X\n", e2address));
1395                  LOG(("ready for next address %04X\n", state->e2address));
13491396
1350                  e2cnt   = 0;
1351                  e2data  = 0;
1397                  state->e2cnt   = 0;
1398                  state->e2data  = 0;
13521399               }
13531400               break;
13541401
r10427r10428
13621409   }
13631410}
13641411
1365static int read_e2ram(void)
1412static int read_e2ram(running_machine *machine)
13661413{
1367   LOG(("e2ram: r %d (%02X) \n", e2data_pin, e2data_to_read ));
1414   bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>();
1415   LOG(("e2ram: r %d (%02X) \n", state->e2data_pin, state->e2data_to_read ));
13681416
1369   return e2data_pin;
1417   return state->e2data_pin;
13701418}
13711419
13721420static const UINT16 AddressDecode[]=
r10427r10428
13821430   0
13831431};
13841432
1385static UINT8 codec_data[256];
13861433
13871434///////////////////////////////////////////////////////////////////////////
13881435static void decode_mainrom(running_machine *machine, const char *rom_region)
13891436{
1437   bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>();
13901438   UINT8 *tmp, *rom;
13911439
13921440   rom = machine->region(rom_region)->base();
r10427r10428
14131461            pattern <<= 1;
14141462         } while ( *(++tab) );
14151463
1416         codec_data[i] = newdata;
1464         state->codec_data[i] = newdata;
14171465      }
14181466
14191467      for ( address = 0; address < 0x10000; address++)
r10427r10428
14301478            pattern <<= 1;
14311479         } while ( *(++tab) );
14321480
1433         rom[newaddress] = codec_data[ tmp[address] ];
1481         rom[newaddress] = state->codec_data[ tmp[address] ];
14341482      }
14351483      auto_free(machine, tmp);
14361484   }
r10427r10428
14481496   on_scorpion2_reset(machine);
14491497   BFM_BD1_init(0);
14501498   BFM_BD1_init(1);
1451   //BFM_dm01_reset(); No known video based game has a Matrix board
1499   //BFM_dm01_reset(machine); No known video based game has a Matrix board
14521500}
14531501
14541502static VIDEO_UPDATE( addersc2 )
14551503{
1456   if ( sc2_show_door )
1504   bfm_sc2_state *state = screen->machine->driver_data<bfm_sc2_state>();
1505   if ( state->sc2_show_door )
14571506   {
1458      output_set_value("door",( Scorpion2_GetSwitchState(sc2_door_state>>4, sc2_door_state & 0x0F) ) );
1507      output_set_value("door",( Scorpion2_GetSwitchState(screen->machine,state->sc2_door_state>>4, state->sc2_door_state & 0x0F) ) );
14591508   }
14601509
14611510   return VIDEO_UPDATE_CALL(adder2);
r10427r10428
21732222// machine driver for scorpion2 board + adder2 expansion //////////////////
21742223///////////////////////////////////////////////////////////////////////////
21752224
2176static MACHINE_CONFIG_START( scorpion2_vid, driver_device )
2225static MACHINE_CONFIG_START( scorpion2_vid, bfm_sc2_state )
21772226   MCFG_MACHINE_RESET( init )                     // main scorpion2 board initialisation
21782227   MCFG_QUANTUM_TIME(attotime::from_hz(960))                           // needed for serial communication !!
21792228   MCFG_CPU_ADD("maincpu", M6809, MASTER_CLOCK/4 )   // 6809 CPU at 2 Mhz
r10427r10428
22122261
22132262static void sc2_common_init(running_machine *machine, int decrypt)
22142263{
2264   bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>();
22152265   UINT8 *rom;
22162266
22172267   if (decrypt) decode_mainrom(machine, "maincpu");        // decode main rom
r10427r10428
22222272      memcpy(&rom[0x10000], &rom[0x00000], 0x2000);
22232273   }
22242274
2225   memset(sc2_Inputs, 0, sizeof(sc2_Inputs));  // clear all inputs
2275   memset(state->sc2_Inputs, 0, sizeof(state->sc2_Inputs));  // clear all inputs
22262276}
22272277
22282278static void adder2_common_init(running_machine *machine)
22292279{
2280   bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>();
22302281   UINT8 *pal;
22312282
22322283   pal = machine->region("proms")->base();
22332284   if ( pal )
22342285   {
2235      memcpy(key, pal, 8);
2286      memcpy(state->key, pal, 8);
22362287   }
22372288}
22382289
r10427r10428
22402291
22412292static DRIVER_INIT (quintoon)
22422293{
2294   bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>();
22432295   sc2_common_init(machine, 1);
22442296   adder2_decode_char_roms(machine);
22452297   MechMtr_config(machine,8);               // setup mech meters
22462298
2247   has_hopper = 0;
2299   state->has_hopper = 0;
22482300
2249   Scorpion2_SetSwitchState(3,0,1);   // tube1 level switch
2250   Scorpion2_SetSwitchState(3,1,1);   // tube2 level switch
2251   Scorpion2_SetSwitchState(3,2,1);   // tube3 level switch
2301   Scorpion2_SetSwitchState(machine,3,0,1);   // tube1 level switch
2302   Scorpion2_SetSwitchState(machine,3,1,1);   // tube2 level switch
2303   Scorpion2_SetSwitchState(machine,3,2,1);   // tube3 level switch
22522304
2253   Scorpion2_SetSwitchState(5,2,1);
2254   Scorpion2_SetSwitchState(6,4,1);
2305   Scorpion2_SetSwitchState(machine,5,2,1);
2306   Scorpion2_SetSwitchState(machine,6,4,1);
22552307
2256   sc2_show_door   = 1;
2257   sc2_door_state  = 0x41;
2308   state->sc2_show_door   = 1;
2309   state->sc2_door_state  = 0x41;
22582310}
22592311
22602312// dutch pyramid intialisation //////////////////////////////////////////////
22612313
22622314static DRIVER_INIT( pyramid )
22632315{
2316   bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>();
22642317   sc2_common_init(machine, 1);
22652318   adder2_decode_char_roms(machine);         // decode GFX roms
22662319   adder2_common_init(machine);
22672320
2268   has_hopper = 1;
2321   state->has_hopper = 1;
22692322
2270   Scorpion2_SetSwitchState(3,0,1);   // tube1 level switch
2271   Scorpion2_SetSwitchState(3,1,1);   // tube2 level switch
2272   Scorpion2_SetSwitchState(3,2,1);   // tube3 level switch
2323   Scorpion2_SetSwitchState(machine,3,0,1);   // tube1 level switch
2324   Scorpion2_SetSwitchState(machine,3,1,1);   // tube2 level switch
2325   Scorpion2_SetSwitchState(machine,3,2,1);   // tube3 level switch
22732326
2274   sc2_show_door   = 1;
2275   sc2_door_state  = 0x41;
2327   state->sc2_show_door   = 1;
2328   state->sc2_door_state  = 0x41;
22762329}
22772330// belgian slots initialisation /////////////////////////////////////////////
22782331
22792332static DRIVER_INIT( sltsbelg )
22802333{
2334   bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>();
22812335   sc2_common_init(machine, 1);
22822336   adder2_decode_char_roms(machine);         // decode GFX roms
22832337   adder2_common_init(machine);
22842338
2285   has_hopper = 1;
2339   state->has_hopper = 1;
22862340
2287   sc2_show_door   = 1;
2288   sc2_door_state  = 0x41;
2341   state->sc2_show_door   = 1;
2342   state->sc2_door_state  = 0x41;
22892343}
22902344
22912345// other dutch adder games ////////////////////////////////////////////////
22922346
22932347static DRIVER_INIT( adder_dutch )
22942348{
2349   bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>();
22952350   sc2_common_init(machine, 1);
22962351   adder2_decode_char_roms(machine);         // decode GFX roms
22972352   adder2_common_init(machine);
22982353
2299   has_hopper = 0;
2354   state->has_hopper = 0;
23002355
2301   Scorpion2_SetSwitchState(3,0,1);   // tube1 level switch
2302   Scorpion2_SetSwitchState(3,1,1);   // tube2 level switch
2303   Scorpion2_SetSwitchState(3,2,1);   // tube3 level switch
2356   Scorpion2_SetSwitchState(machine,3,0,1);   // tube1 level switch
2357   Scorpion2_SetSwitchState(machine,3,1,1);   // tube2 level switch
2358   Scorpion2_SetSwitchState(machine,3,2,1);   // tube3 level switch
23042359
2305   sc2_show_door   = 1;
2306   sc2_door_state  = 0x41;
2360   state->sc2_show_door   = 1;
2361   state->sc2_door_state  = 0x41;
23072362}
23082363
23092364// golden crown //////////////////////////////////////////////////////////
23102365
23112366static DRIVER_INIT( gldncrwn )
23122367{
2368   bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>();
23132369   sc2_common_init(machine, 1);
23142370   adder2_decode_char_roms(machine);         // decode GFX roms
23152371   adder2_common_init(machine);
23162372
2317   has_hopper = 0;
2373   state->has_hopper = 0;
23182374
2319   Scorpion2_SetSwitchState(3,0,1);   // tube1 level switch
2320   Scorpion2_SetSwitchState(3,1,1);   // tube2 level switch
2321   Scorpion2_SetSwitchState(3,2,1);   // tube3 level switch
2375   Scorpion2_SetSwitchState(machine,3,0,1);   // tube1 level switch
2376   Scorpion2_SetSwitchState(machine,3,1,1);   // tube2 level switch
2377   Scorpion2_SetSwitchState(machine,3,2,1);   // tube3 level switch
23222378
2323   sc2_show_door   = 0;
2324   sc2_door_state  = 0x41;
2379   state->sc2_show_door   = 0;
2380   state->sc2_door_state  = 0x41;
23252381}
23262382
23272383// ROM definition UK Quintoon ////////////////////////////////////////////
r10427r10428
25972653#include "awpvid14.lh"
25982654#include "awpvid16.lh"
25992655
2656
26002657/* Reels 1 and 2 */
26012658static WRITE8_HANDLER( reel12_w )
26022659{
2603   reel12_latch = data;
2660   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
2661   state->reel12_latch = data;
26042662
2605   if ( stepper_update(0, data   ) ) reel_changed |= 0x01;
2606   if ( stepper_update(1, data>>4) ) reel_changed |= 0x02;
2663   if ( stepper_update(0, data   ) ) state->reel_changed |= 0x01;
2664   if ( stepper_update(1, data>>4) ) state->reel_changed |= 0x02;
26072665
2608   if ( stepper_optic_state(0) ) optic_pattern |=  0x01;
2609   else                          optic_pattern &= ~0x01;
2610   if ( stepper_optic_state(1) ) optic_pattern |=  0x02;
2611   else                          optic_pattern &= ~0x02;
2666   if ( stepper_optic_state(0) ) state->optic_pattern |=  0x01;
2667   else                          state->optic_pattern &= ~0x01;
2668   if ( stepper_optic_state(1) ) state->optic_pattern |=  0x02;
2669   else                          state->optic_pattern &= ~0x02;
26122670
26132671   awp_draw_reel(0);
26142672   awp_draw_reel(1);
r10427r10428
26182676/* VFD Status */
26192677static READ8_HANDLER( vfd_status_r )
26202678{
2679   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
26212680   /* b7 = NEC busy */
26222681   /* b6 = alpha busy (also matrix board) */
26232682   /* b5 - b0 = reel optics */
26242683
2625   int result = optic_pattern;
2684   int result = state->optic_pattern;
26262685
26272686   if ( !upd7759_busy_r(space->machine->device("upd")) ) result |= 0x80;
26282687
r10427r10428
26322691/* VFD Status and data */
26332692static READ8_HANDLER( vfd_status_dm01_r )
26342693{
2694   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
26352695   /* b7 = NEC busy */
26362696   /* b6 = alpha busy (also matrix board) */
26372697   /* b5 - b0 = reel optics */
26382698
2639   int result = optic_pattern;
2699   int result = state->optic_pattern;
26402700
26412701   if ( !upd7759_busy_r(space->machine->device("upd")) ) result |= 0x80;
26422702
r10427r10428
26482708
26492709static WRITE8_HANDLER( vfd1_data_dm01_w )
26502710{
2651   vfd1_latch = data;
2711   bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>();
2712   state->vfd1_latch = data;
26522713   BFM_dm01_writedata(space->machine,data);
26532714}
26542715
r10427r10428
27012762static MACHINE_RESET( dm01_init )
27022763{
27032764   on_scorpion2_reset(machine);
2704   BFM_dm01_reset();
2765   BFM_dm01_reset(machine);
27052766}
27062767
27072768
r10427r10428
27552816
27562817/* memory map for scorpion3 board */
27572818static ADDRESS_MAP_START( sc3_memmap, ADDRESS_SPACE_PROGRAM, 8 )
2758   AM_RANGE(0x0000, 0x1fff) AM_RAM AM_SHARE("nvram")//8k
2819   AM_RANGE(0x0000, 0x1fff) AM_RAM AM_SHARE("nvram") //8k
27592820   AM_RANGE(0x2000, 0x2000) AM_READ(vfd_status_r)
27602821   AM_RANGE(0x2000, 0x20FF) AM_WRITE(reel12_w)
27612822   AM_RANGE(0x2100, 0x21FF) AM_WRITE(reel34_w)
r10427r10428
28042865
28052866/* memory map for scorpion2 board + dm01 dot matrix board */
28062867static ADDRESS_MAP_START( memmap_sc2_dm01, ADDRESS_SPACE_PROGRAM, 8 )
2807   AM_RANGE(0x0000, 0x1fff) AM_RAM AM_SHARE("nvram")//8k
2868   AM_RANGE(0x0000, 0x1fff) AM_RAM AM_SHARE("nvram") //8k
28082869   AM_RANGE(0x2000, 0x2000) AM_READ(vfd_status_dm01_r)
28092870   AM_RANGE(0x2000, 0x20FF) AM_WRITE(reel12_w)
28102871   AM_RANGE(0x2100, 0x21FF) AM_WRITE(reel34_w)
r10427r10428
39253986
39263987/* machine driver for scorpion2 board */
39273988
3928static MACHINE_CONFIG_START( scorpion2, driver_device )
3989static MACHINE_CONFIG_START( scorpion2, bfm_sc2_state )
39293990   MCFG_MACHINE_RESET(awp_init)
39303991   MCFG_CPU_ADD("maincpu", M6809, MASTER_CLOCK/4 )
39313992   MCFG_CPU_PROGRAM_MAP(sc2_memmap)
r10427r10428
39544015
39554016
39564017/* machine driver for scorpion2 board + matrix board */
3957static MACHINE_CONFIG_START( scorpion2_dm01, driver_device )
4018static MACHINE_CONFIG_START( scorpion2_dm01, bfm_sc2_state )
39584019   MCFG_MACHINE_RESET(dm01_init)
39594020   MCFG_QUANTUM_TIME(attotime::from_hz(960))                           // needed for serial communication !!
39604021   MCFG_CPU_ADD("maincpu", M6809, MASTER_CLOCK/4 )
r10427r10428
39954056
39964057static DRIVER_INIT (bbrkfst)
39974058{
4059   bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>();
39984060   sc2awp_common_init(machine,5, 1);
39994061   MechMtr_config(machine,8);
40004062
40014063   BFM_BD1_init(0);
40024064   BFM_BD1_init(1);
40034065
4004   has_hopper = 0;
4066   state->has_hopper = 0;
40054067
4006   Scorpion2_SetSwitchState(4,0, 1);     /* GBP1 Low Level Switch */
4007   Scorpion2_SetSwitchState(4,1, 1);     /* 20p Low Level Switch */
4008   Scorpion2_SetSwitchState(4,2, 1);     /* Token Front Low Level Switch */
4009   Scorpion2_SetSwitchState(4,3, 1);     /* Token Rear  Low Level Switch */
4010   Scorpion2_SetSwitchState(4,4, 1);
4011   Scorpion2_SetSwitchState(6,0, 0);
4012   Scorpion2_SetSwitchState(6,1, 1);
4013   Scorpion2_SetSwitchState(6,2, 0);
4014   Scorpion2_SetSwitchState(6,3, 1);
4068   Scorpion2_SetSwitchState(machine,4,0, 1);     /* GBP1 Low Level Switch */
4069   Scorpion2_SetSwitchState(machine,4,1, 1);     /* 20p Low Level Switch */
4070   Scorpion2_SetSwitchState(machine,4,2, 1);     /* Token Front Low Level Switch */
4071   Scorpion2_SetSwitchState(machine,4,3, 1);     /* Token Rear  Low Level Switch */
4072   Scorpion2_SetSwitchState(machine,4,4, 1);
4073   Scorpion2_SetSwitchState(machine,6,0, 0);
4074   Scorpion2_SetSwitchState(machine,6,1, 1);
4075   Scorpion2_SetSwitchState(machine,6,2, 0);
4076   Scorpion2_SetSwitchState(machine,6,3, 1);
40154077
40164078}
40174079
40184080static DRIVER_INIT (drwho)
40194081{
4082   bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>();
40204083   sc2awp_common_init(machine,4, 1);
40214084   MechMtr_config(machine,8);
40224085
40234086   BFM_BD1_init(0);
40244087   BFM_BD1_init(1);
40254088
4026   has_hopper = 0;
4089   state->has_hopper = 0;
40274090
4028   Scorpion2_SetSwitchState(4,0, 0);     /* GBP1 Low Level Switch */
4029   Scorpion2_SetSwitchState(4,1, 0);     /* 20p Low Level Switch */
4030   Scorpion2_SetSwitchState(4,2, 0);     /* Token Front Low Level Switch */
4031   Scorpion2_SetSwitchState(4,3, 0);     /* Token Rear  Low Level Switch */
4032   Scorpion2_SetSwitchState(7,0, 0);     /* GBP1 High Level Switch */
4033   Scorpion2_SetSwitchState(7,1, 0);     /* 20P High Level Switch */
4034   Scorpion2_SetSwitchState(7,2, 0);     /* Token Front High Level Switch */
4035   Scorpion2_SetSwitchState(7,3, 0);     /* Token Rear High Level Switch */
4091   Scorpion2_SetSwitchState(machine,4,0, 0);     /* GBP1 Low Level Switch */
4092   Scorpion2_SetSwitchState(machine,4,1, 0);     /* 20p Low Level Switch */
4093   Scorpion2_SetSwitchState(machine,4,2, 0);     /* Token Front Low Level Switch */
4094   Scorpion2_SetSwitchState(machine,4,3, 0);     /* Token Rear  Low Level Switch */
4095   Scorpion2_SetSwitchState(machine,7,0, 0);     /* GBP1 High Level Switch */
4096   Scorpion2_SetSwitchState(machine,7,1, 0);     /* 20P High Level Switch */
4097   Scorpion2_SetSwitchState(machine,7,2, 0);     /* Token Front High Level Switch */
4098   Scorpion2_SetSwitchState(machine,7,3, 0);     /* Token Rear High Level Switch */
40364099}
40374100
40384101static DRIVER_INIT (drwhon)
40394102{
4103   bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>();
40404104   sc2awp_common_init(machine,4, 0);
40414105   MechMtr_config(machine,8);
40424106
40434107   BFM_BD1_init(0);
40444108   BFM_BD1_init(1);
40454109
4046   has_hopper = 0;
4110   state->has_hopper = 0;
40474111
4048   Scorpion2_SetSwitchState(4,0, 0);     /* GBP1 Low Level Switch */
4049   Scorpion2_SetSwitchState(4,1, 0);     /* 20p Low Level Switch */
4050   Scorpion2_SetSwitchState(4,2, 0);     /* Token Front Low Level Switch */
4051   Scorpion2_SetSwitchState(4,3, 0);     /* Token Rear  Low Level Switch */
4052   Scorpion2_SetSwitchState(7,0, 0);     /* GBP1 High Level Switch */
4053   Scorpion2_SetSwitchState(7,1, 0);     /* 20P High Level Switch */
4054   Scorpion2_SetSwitchState(7,2, 0);     /* Token Front High Level Switch */
4055   Scorpion2_SetSwitchState(7,3, 0);     /* Token Rear High Level Switch */
4112   Scorpion2_SetSwitchState(machine,4,0, 0);     /* GBP1 Low Level Switch */
4113   Scorpion2_SetSwitchState(machine,4,1, 0);     /* 20p Low Level Switch */
4114   Scorpion2_SetSwitchState(machine,4,2, 0);     /* Token Front Low Level Switch */
4115   Scorpion2_SetSwitchState(machine,4,3, 0);     /* Token Rear  Low Level Switch */
4116   Scorpion2_SetSwitchState(machine,7,0, 0);     /* GBP1 High Level Switch */
4117   Scorpion2_SetSwitchState(machine,7,1, 0);     /* 20P High Level Switch */
4118   Scorpion2_SetSwitchState(machine,7,2, 0);     /* Token Front High Level Switch */
4119   Scorpion2_SetSwitchState(machine,7,3, 0);     /* Token Rear High Level Switch */
40564120}
40574121
40584122
r10427r10428
40664130
40674131static DRIVER_INIT (cpeno1)
40684132{
4133   bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>();
40694134   sc2awp_common_init(machine,6, 1);
40704135
40714136   MechMtr_config(machine,5);
40724137
4073   Scorpion2_SetSwitchState(3,3,1);   /*  5p play */
4074   Scorpion2_SetSwitchState(3,4,1);   /* 20p play */
4138   Scorpion2_SetSwitchState(machine,3,3,1);   /*  5p play */
4139   Scorpion2_SetSwitchState(machine,3,4,1);   /* 20p play */
40754140
4076   Scorpion2_SetSwitchState(4,0,1);   /* pay tube low (1 pound front) */
4077   Scorpion2_SetSwitchState(4,1,1);   /* pay tube low (20p) */
4078   Scorpion2_SetSwitchState(4,2,1);   /* pay tube low (?1 right) */
4079   Scorpion2_SetSwitchState(4,3,1);   /* pay tube low (?1 left) */
4141   Scorpion2_SetSwitchState(machine,4,0,1);   /* pay tube low (1 pound front) */
4142   Scorpion2_SetSwitchState(machine,4,1,1);   /* pay tube low (20p) */
4143   Scorpion2_SetSwitchState(machine,4,2,1);   /* pay tube low (?1 right) */
4144   Scorpion2_SetSwitchState(machine,4,3,1);   /* pay tube low (?1 left) */
40804145
4081   Scorpion2_SetSwitchState(5,0,1);   /* pay sensor (GBP1 front) */
4082   Scorpion2_SetSwitchState(5,1,1);   /* pay sensor (20 p) */
4083   Scorpion2_SetSwitchState(5,2,1);   /* pay sensor (1 right) */
4084   Scorpion2_SetSwitchState(5,3,1);   /* pay sensor (?1 left) */
4085   Scorpion2_SetSwitchState(5,4,1);   /* payout unit present */
4146   Scorpion2_SetSwitchState(machine,5,0,1);   /* pay sensor (GBP1 front) */
4147   Scorpion2_SetSwitchState(machine,5,1,1);   /* pay sensor (20 p) */
4148   Scorpion2_SetSwitchState(machine,5,2,1);   /* pay sensor (1 right) */
4149   Scorpion2_SetSwitchState(machine,5,3,1);   /* pay sensor (?1 left) */
4150   Scorpion2_SetSwitchState(machine,5,4,1);   /* payout unit present */
40864151
4087   slide_pay_sensor[0] = 0x50;
4088   slide_pay_sensor[1] = 0x51;
4089   slide_pay_sensor[2] = 0x52;
4090   slide_pay_sensor[3] = 0x53;
4091   slide_pay_sensor[4] = 0;
4092   slide_pay_sensor[5] = 0;
4152   state->slide_pay_sensor[0] = 0x50;
4153   state->slide_pay_sensor[1] = 0x51;
4154   state->slide_pay_sensor[2] = 0x52;
4155   state->slide_pay_sensor[3] = 0x53;
4156   state->slide_pay_sensor[4] = 0;
4157   state->slide_pay_sensor[5] = 0;
40934158
4094   Scorpion2_SetSwitchState(6,0,1);   /* ? percentage key */
4095   Scorpion2_SetSwitchState(6,1,1);
4096   Scorpion2_SetSwitchState(6,2,1);
4097   Scorpion2_SetSwitchState(6,3,1);
4098   Scorpion2_SetSwitchState(6,4,1);
4159   Scorpion2_SetSwitchState(machine,6,0,1);   /* ? percentage key */
4160   Scorpion2_SetSwitchState(machine,6,1,1);
4161   Scorpion2_SetSwitchState(machine,6,2,1);
4162   Scorpion2_SetSwitchState(machine,6,3,1);
4163   Scorpion2_SetSwitchState(machine,6,4,1);
40994164
4100   Scorpion2_SetSwitchState(7,0,0);   /* GBP1 High Level Switch  */
4101   Scorpion2_SetSwitchState(7,1,0);   /* 20P High Level Switch */
4102   Scorpion2_SetSwitchState(7,2,0);   /* Token Front High Level Switch */
4103   Scorpion2_SetSwitchState(7,3,0);   /* Token Rear High Level Switch */
4165   Scorpion2_SetSwitchState(machine,7,0,0);   /* GBP1 High Level Switch  */
4166   Scorpion2_SetSwitchState(machine,7,1,0);   /* 20P High Level Switch */
4167   Scorpion2_SetSwitchState(machine,7,2,0);   /* Token Front High Level Switch */
4168   Scorpion2_SetSwitchState(machine,7,3,0);   /* Token Rear High Level Switch */
41044169
4105   sc2_show_door   = 1;
4106   sc2_door_state  = 0x31;
4170   state->sc2_show_door   = 1;
4171   state->sc2_door_state  = 0x31;
41074172
4108   has_hopper = 0;
4173   state->has_hopper = 0;
41094174}
41104175
41114176static DRIVER_INIT (bfmcgslm)
41124177{
4178   bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>();
41134179   sc2awp_common_init(machine,6, 1);
41144180   MechMtr_config(machine,8);
41154181   BFM_BD1_init(0);
4116   has_hopper = 0;
4182   state->has_hopper = 0;
41174183}
41184184
41194185static DRIVER_INIT (luvjub)
41204186{
4187   bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>();
41214188   sc2awp_common_init(machine,6, 1);
41224189   MechMtr_config(machine,8);
4123   has_hopper = 0;
4190   state->has_hopper = 0;
41244191
4125   Scorpion2_SetSwitchState(3,0,1);
4126   Scorpion2_SetSwitchState(3,1,1);
4192   Scorpion2_SetSwitchState(machine,3,0,1);
4193   Scorpion2_SetSwitchState(machine,3,1,1);
41274194
4128   Scorpion2_SetSwitchState(4,0,1);
4129   Scorpion2_SetSwitchState(4,1,1);
4130   Scorpion2_SetSwitchState(4,2,1);
4131   Scorpion2_SetSwitchState(4,3,1);
4195   Scorpion2_SetSwitchState(machine,4,0,1);
4196   Scorpion2_SetSwitchState(machine,4,1,1);
4197   Scorpion2_SetSwitchState(machine,4,2,1);
4198   Scorpion2_SetSwitchState(machine,4,3,1);
41324199
4133   Scorpion2_SetSwitchState(6,0,1);
4134   Scorpion2_SetSwitchState(6,1,1);
4135   Scorpion2_SetSwitchState(6,2,1);
4136   Scorpion2_SetSwitchState(6,3,0);
4200   Scorpion2_SetSwitchState(machine,6,0,1);
4201   Scorpion2_SetSwitchState(machine,6,1,1);
4202   Scorpion2_SetSwitchState(machine,6,2,1);
4203   Scorpion2_SetSwitchState(machine,6,3,0);
41374204
4138   Scorpion2_SetSwitchState(7,0,0);
4139   Scorpion2_SetSwitchState(7,1,0);
4140   Scorpion2_SetSwitchState(7,2,0);
4141   Scorpion2_SetSwitchState(7,3,0);
4205   Scorpion2_SetSwitchState(machine,7,0,0);
4206   Scorpion2_SetSwitchState(machine,7,1,0);
4207   Scorpion2_SetSwitchState(machine,7,2,0);
4208   Scorpion2_SetSwitchState(machine,7,3,0);
41424209}
41434210
41444211/*********************************************
src/mame/drivers/sigmab98.c
r10427r10428
7474  to "coin" (it probably changes the number of reads from port $C0).
7575  I guess the reset_delay mechanism should be implemented with a timer in eeprom.c.
7676
77Notes:
78
79- "BACKUP RAM NG" error: in test mode, choose "SET MODE" -> "RAM CLEAR" and keep the button pressed for long.
80
7781*************************************************************************************************************/
7882
7983#include "emu.h"
8084#include "deprecat.h"
8185#include "cpu/z80/z80.h"
86#include "sound/okim9810.h"
8287#include "sound/ymz280b.h"
8388#include "machine/eeprom.h"
89#include "machine/nvram.h"
8490#include "machine/ticket.h"
85#include "machine/nvram.h"
8691
8792/***************************************************************************
8893
r10427r10428
102107                -6-- ----     256 Color Sprite
103108                --5- ----
104109                ---4 ----     Flip X
105                ---- 3---
110                ---- 3---     Flip Y
106111                ---- -2--     Draw Sprite
107112                ---- --10     Priority (0 = Front .. 3 = Back)
108113    2                         Tile Code (High)
r10427r10428
168173      dx      =   (dx & 0x1ff) - (dx & 0x200);
169174      dy      =   (dy & 0x1ff) - (dy & 0x200);
170175
171      // Add shift
172      sx      +=   dx;
173      sy      +=   dy;
176      // Add shift (negated, as it seems more correct in haekaka)
177      sx      -=   dx;
178      sy      -=   dy;
174179
175180      // Use fixed point values (16.16), for accuracy
176181      sx      <<=   16;
r10427r10428
185190      if (scale & 0xffff)   scale += (1<<16) / 0x10;
186191
187192      flipx   =   s[ 0x01 ] & 0x10;
188      flipy   =   0;   // ?
193      flipy   =   s[ 0x01 ] & 0x08;
189194
190195      if ( flipx )   {   x0 = nx - 1;   x1 = -1;   dx = -1;   }
191196      else         {   x0 = 0;         x1 = nx;   dx = +1;   }
r10427r10428
340345static void show_outputs()
341346{
342347#ifdef MAME_DEBUG
343   popmessage("0: %02X  4: %02X  6: %02X  8: %02X",c0,c4,c6,c8);
348//   popmessage("0: %02X  4: %02X  6: %02X  8: %02X",c0,c4,c6,c8);
344349#endif
345350}
346351
r10427r10428
593598static void show_3_outputs()
594599{
595600#ifdef MAME_DEBUG
596   popmessage("COIN: %02X  LED: %02X  HOP: %02X", out[0], out[1], out[2]);
601//   popmessage("COIN: %02X  LED: %02X  HOP: %02X", out[0], out[1], out[2]);
597602#endif
598603}
599604// Port 31
r10427r10428
603608   coin_counter_w(space->machine, 1,   data  & 0x02 );   // coin2 in
604609   coin_counter_w(space->machine, 2,   data  & 0x04 );   // medal in
605610
606   coin_lockout_w(space->machine, 1, (~data) & 0x08 );   // coin2 lockout?
607   coin_lockout_w(space->machine, 0, (~data) & 0x10 );   // coin1 lockout
608   coin_lockout_w(space->machine, 2, (~data) & 0x20 );   // medal lockout?
611//   coin_lockout_w(space->machine, 1, (~data) & 0x08 );   // coin2 lockout?
612//   coin_lockout_w(space->machine, 0, (~data) & 0x10 );   // coin1 lockout
613//   coin_lockout_w(space->machine, 2, (~data) & 0x20 );   // medal lockout?
609614
610615   out[0] = data;
611616   show_3_outputs();
r10427r10428
631636   show_3_outputs();
632637}
633638
634static WRITE8_HANDLER( sammymdl_sound_w )
635{
636}
637
638639static READ8_HANDLER( sammymdl_coin_hopper_r )
639640{
640641   UINT8 ret = input_port_read(space->machine, "COIN");
r10427r10428
645646   return ret;
646647}
647648
649// Sound
650static WRITE8_DEVICE_HANDLER( sammymdl_sound_w )
651{
652   if (offset)
653      downcast<okim9810_device *>(device)->write_TMP_register(data);
654    else
655      downcast<okim9810_device *>(device)->write_command(data);
656}
657static READ8_DEVICE_HANDLER( sammymdl_sound_r )
658{
659   // Needed for haekaka (Oki read status is not implemented yet)
660   return device->machine->rand();
661}
662
648663static UINT8 *nvram;
649664static ADDRESS_MAP_START( animalc_map, ADDRESS_SPACE_PROGRAM, 8 )
650665   AM_RANGE( 0x0000, 0x3fff ) AM_ROM
r10427r10428
656671   AM_RANGE( 0xb000, 0xbfff ) AM_RAMBANK("sprbank")
657672
658673   AM_RANGE( 0xd000, 0xd1ff ) AM_RAM_WRITE( paletteram_xRRRRRGGGGGBBBBB_be_w ) AM_BASE_GENERIC( paletteram )
659   AM_RANGE( 0xd800, 0xd87f ) AM_RAM   // ?
674   AM_RANGE( 0xd800, 0xd87f ) AM_RAM   // table?
660675
661676   AM_RANGE( 0xe011, 0xe011 ) AM_WRITENOP   // IRQ Enable? Screen disable?
662677   AM_RANGE( 0xe013, 0xe013 ) AM_READWRITE( vblank_r, vblank_w )   // IRQ Ack?
r10427r10428
675690   AM_RANGE( 0x31, 0x31 ) AM_WRITE( sammymdl_coin_w )
676691   AM_RANGE( 0x32, 0x32 ) AM_WRITE( sammymdl_leds_w )
677692   AM_RANGE( 0x34, 0x34 ) AM_READ( unk_34_r )
678   AM_RANGE( 0x90, 0x91 ) AM_WRITE( sammymdl_sound_w )
693   AM_RANGE( 0x90, 0x91 ) AM_DEVWRITE("oki", sammymdl_sound_w )
694   AM_RANGE( 0x92, 0x92 ) AM_DEVWRITE("oki", sammymdl_sound_r )
679695   AM_RANGE( 0xb0, 0xb0 ) AM_WRITE( sammymdl_hopper_w )
680696   AM_RANGE( 0xc0, 0xc0 ) AM_WRITE( watchdog_reset_w )   // 1
681697ADDRESS_MAP_END
682698
683699/***************************************************************************
700                             Hae Hae Ka Ka Ka
701***************************************************************************/
702
703// rombank
704static WRITE8_HANDLER( haekaka_rombank_w )
705{
706   if (offset == 0)
707   {
708      reg = data;
709      return;
710   }
711
712   switch ( reg )
713   {
714      case 0x2b:
715         rombank = data;
716         switch (data)
717         {
718            case 0x10:   // ROM
719            case 0x11:
720            case 0x12:
721            case 0x13:
722            case 0x14:
723            case 0x15:
724            case 0x16:
725            case 0x17:
726            case 0x18:
727            case 0x19:
728            case 0x1a:
729            case 0x1b:
730            case 0x1c:
731            case 0x1d:
732            case 0x1e:
733            case 0x1f:
734
735            case 0x65:   // SPRITERAM
736            case 0x67:   // PALETTE RAM + TABLE + REGS
737               break;
738
739            default:
740               logerror("%s: unknown rom bank = %02x, reg = %02x\n", space->machine->describe_context(), data, reg);
741         }
742         break;
743
744      default:
745         logerror("%s: unknown reg written: %02x = %02x\n", space->machine->describe_context(), reg, data);
746   }
747}
748static READ8_HANDLER( haekaka_rombank_r )
749{
750   if (offset == 0)
751      return reg;
752
753   switch ( reg )
754   {
755      case 0x2b:
756         return rombank;
757
758      default:
759         logerror("%s: unknown reg read: %02x\n", space->machine->describe_context(), reg);
760         return 0x00;
761   }
762}
763
764// rambank
765static WRITE8_HANDLER( haekaka_rambank_w )
766{
767   if (offset == 0)
768   {
769      reg2 = data;
770      return;
771   }
772
773   switch ( reg2 )
774   {
775      case 0x33:
776         rambank = data;
777         switch (data)
778         {
779            case 0x53:
780               break;
781
782            default:
783               logerror("%s: unknown ram bank = %02x, reg2 = %02x\n", space->machine->describe_context(), data, reg2);
784         }
785         break;
786
787      default:
788         logerror("%s: unknown reg2 written: %02x = %02x\n", space->machine->describe_context(), reg2, data);
789   }
790}
791static READ8_HANDLER( haekaka_rambank_r )
792{
793   if (offset == 0)
794      return reg2;
795
796   switch ( reg2 )
797   {
798      case 0x33:
799         return rambank;
800
801      default:
802         logerror("%s: unknown reg2 read: %02x\n", space->machine->describe_context(), reg2);
803         return 0x00;
804   }
805}
806
807static READ8_HANDLER( haekaka_vblank_r )
808{
809   return space->machine->primary_screen->vblank() ? 0 : 0x1c;
810}
811
812static READ8_HANDLER( haekaka_b000_r )
813{
814   switch (rombank)
815   {
816      case 0x10:   // ROM
817      case 0x11:
818      case 0x12:
819      case 0x13:
820      case 0x14:
821      case 0x15:
822      case 0x16:
823      case 0x17:
824      case 0x18:
825      case 0x19:
826      case 0x1a:
827      case 0x1b:
828      case 0x1c:
829      case 0x1d:
830      case 0x1e:
831      case 0x1f:
832         return space->machine->region("maincpu")->base()[offset + 0xb400 + 0x1000 * (rombank-0x10)];
833
834      case 0x65:   // SPRITERAM
835         if (offset < 0x1000)
836            return space->machine->generic.spriteram.u8[offset];
837         
838      case 0x67:   // PALETTERAM + TABLE? + REGS
839         if (offset < 0x200)
840            return space->machine->generic.paletteram.u8[offset];
841         else if (offset == (0xc013-0xb000))
842            return haekaka_vblank_r(space, offset);
843         break;
844   }
845
846   logerror("%s: unknown read from %02x with rombank = %02x\n", space->machine->describe_context(), offset+0xb000, rombank);
847   return 0x00;
848}
849
850static WRITE8_HANDLER( haekaka_b000_w )
851{
852   switch (rombank)
853   {
854      case 0x65:   // SPRITERAM
855         if (offset < 0x1000)
856         {
857            space->machine->generic.spriteram.u8[offset] = data;
858            return;
859         }
860         break;
861         
862      case 0x67:   // PALETTERAM + TABLE? + REGS
863         if (offset < 0x200)
864         {
865            paletteram_xRRRRRGGGGGBBBBB_be_w(space, offset, data);
866//            space->machine->generic.paletteram.u8[offset] = data;
867            return;
868         }
869         else if ((offset >= 0x800) && (offset < 0x880))
870         {
871            // table?
872            return;
873         }
874         break;
875   }
876
877   logerror("%s: unknown write to %02x = %02x with rombank = %02x\n", space->machine->describe_context(), offset+0xb000, data, rombank);
878}
879
880static WRITE8_HANDLER( haekaka_leds_w )
881{
882   // All used
883   set_led_status(space->machine, 0,   data & 0x01);
884   set_led_status(space->machine, 1,   data & 0x02);
885   set_led_status(space->machine, 2,   data & 0x04);
886   set_led_status(space->machine, 3,   data & 0x08);
887   set_led_status(space->machine, 4,   data & 0x10);
888   set_led_status(space->machine, 5,   data & 0x20);
889   set_led_status(space->machine, 6,   data & 0x40);
890   set_led_status(space->machine, 7,   data & 0x80);
891
892   out[1] = data;
893   show_3_outputs();
894}
895
896static WRITE8_HANDLER( haekaka_coin_w )
897{
898   coin_counter_w(space->machine, 0,   data & 0x01 );   // medal out
899//                              data & 0x02 ?
900//                              data & 0x04 ?
901//                              data & 0x10 ?
902
903   out[0] = data;
904   show_3_outputs();
905}
906
907static ADDRESS_MAP_START( haekaka_map, ADDRESS_SPACE_PROGRAM, 8 )
908   AM_RANGE( 0x0000, 0x7fff ) AM_ROM
909   AM_RANGE( 0xb000, 0xcfff ) AM_READWRITE( haekaka_b000_r, haekaka_b000_w )
910   AM_RANGE( 0xd000, 0xefff ) AM_RAM AM_SHARE( "nvram" ) AM_BASE( &nvram )
911   AM_RANGE( 0xfe00, 0xffff ) AM_RAM
912ADDRESS_MAP_END
913
914static ADDRESS_MAP_START( haekaka_io, ADDRESS_SPACE_IO, 8 )
915   ADDRESS_MAP_GLOBAL_MASK(0xff)
916   AM_RANGE( 0x02, 0x03 ) AM_READWRITE( haekaka_rombank_r, haekaka_rombank_w )
917   AM_RANGE( 0x04, 0x05 ) AM_READWRITE( haekaka_rambank_r, haekaka_rambank_w )
918
919   AM_RANGE( 0x2c, 0x2c ) AM_DEVREADWRITE( "eeprom", sammymdl_eeprom_r, sammymdl_eeprom_w )
920   AM_RANGE( 0x2e, 0x2e ) AM_READ( sammymdl_coin_hopper_r )
921   AM_RANGE( 0x30, 0x30 ) AM_READ_PORT( "BUTTON" )
922   AM_RANGE( 0x31, 0x31 ) AM_WRITE( haekaka_coin_w )
923   AM_RANGE( 0x32, 0x32 ) AM_WRITE( haekaka_leds_w )
924   AM_RANGE( 0x90, 0x91 ) AM_DEVWRITE("oki", sammymdl_sound_w )
925   AM_RANGE( 0x92, 0x92 ) AM_DEVWRITE("oki", sammymdl_sound_r )
926   AM_RANGE( 0xb0, 0xb0 ) AM_WRITE( sammymdl_hopper_w )
927   AM_RANGE( 0xc0, 0xc0 ) AM_WRITE( watchdog_reset_w )   // 1
928ADDRESS_MAP_END
929
930/***************************************************************************
684931                              Itazura Monkey
685932***************************************************************************/
686933
r10427r10428
8921139   AM_RANGE( 0x4800, 0x57ff ) AM_READ_BANK( "rombank1" ) AM_WRITE_BANK( "sprbank1" )
8931140
8941141   AM_RANGE( 0x5800, 0x59ff ) AM_READWRITE( itazuram_palette_r, itazuram_palette_w )
895   AM_RANGE( 0x6000, 0x607f ) AM_RAM   // ?
1142   AM_RANGE( 0x6000, 0x607f ) AM_RAM   // table?
8961143
8971144   AM_RANGE( 0x6811, 0x6811 ) AM_WRITENOP   // IRQ Enable? Screen disable?
8981145   AM_RANGE( 0x6813, 0x6813 ) AM_WRITENOP   // IRQ Ack?
r10427r10428
9111158   AM_RANGE( 0x30, 0x30 ) AM_READ_PORT( "BUTTON" )
9121159   AM_RANGE( 0x31, 0x31 ) AM_WRITE( sammymdl_coin_w )
9131160   AM_RANGE( 0x32, 0x32 ) AM_WRITE( sammymdl_leds_w )
914   AM_RANGE( 0x90, 0x91 ) AM_WRITE( sammymdl_sound_w )   // sound
1161   AM_RANGE( 0x90, 0x91 ) AM_DEVWRITE("oki", sammymdl_sound_w )
1162   AM_RANGE( 0x92, 0x92 ) AM_DEVWRITE("oki", sammymdl_sound_r )
9151163   AM_RANGE( 0xb0, 0xb0 ) AM_WRITE( sammymdl_hopper_w )
9161164   AM_RANGE( 0xc0, 0xc0 ) AM_WRITE( watchdog_reset_w )   // 1
9171165ADDRESS_MAP_END
9181166
9191167/***************************************************************************
1168                             Pye-nage Taikai
1169***************************************************************************/
9201170
1171static ADDRESS_MAP_START( pyenaget_io, ADDRESS_SPACE_IO, 8 )
1172   AM_RANGE( 0x31, 0x31 ) AM_WRITE( sammymdl_coin_w )
1173   AM_IMPORT_FROM( haekaka_io )
1174ADDRESS_MAP_END
1175
1176/***************************************************************************
1177                             Taihou de Doboon
1178***************************************************************************/
1179
1180// rombank
1181static WRITE8_HANDLER( tdoboon_rombank_w )
1182{
1183   if (offset == 0)
1184   {
1185      reg = data;
1186      return;
1187   }
1188
1189   switch ( reg )
1190   {
1191      case 0x2f:
1192         rombank = data;
1193         switch (data)
1194         {
1195            case 0x10:   // ROM
1196            case 0x11:
1197            case 0x12:
1198            case 0x13:
1199            case 0x14:
1200            case 0x15:
1201            case 0x16:
1202            case 0x17:
1203            case 0x18:
1204            case 0x19:
1205            case 0x1a:
1206            case 0x1b:
1207            case 0x1c:
1208            case 0x1d:
1209            case 0x1e:
1210            case 0x1f:
1211
1212            case 0x64:   // SPRITERAM
1213            case 0x66:   // PALETTE RAM + TABLE
1214            case 0x67:   // REGS
1215               break;
1216
1217            default:
1218               logerror("%s: unknown rom bank = %02x, reg = %02x\n", space->machine->describe_context(), data, reg);
1219         }
1220         break;
1221
1222      default:
1223         logerror("%s: unknown reg written: %02x = %02x\n", space->machine->describe_context(), reg, data);
1224   }
1225}
1226static READ8_HANDLER( tdoboon_rombank_r )
1227{
1228   if (offset == 0)
1229      return reg;
1230
1231   switch ( reg )
1232   {
1233      case 0x2f:
1234         return rombank;
1235
1236      default:
1237         logerror("%s: unknown reg read: %02x\n", space->machine->describe_context(), reg);
1238         return 0x00;
1239   }
1240}
1241
1242// rambank
1243static WRITE8_HANDLER( tdoboon_rambank_w )
1244{
1245   if (offset == 0)
1246   {
1247      reg2 = data;
1248      return;
1249   }
1250
1251   switch ( reg2 )
1252   {
1253      case 0x33:
1254         rambank = data;
1255         switch (data)
1256         {
1257            case 0x53:
1258               break;
1259
1260            default:
1261               logerror("%s: unknown ram bank = %02x, reg2 = %02x\n", space->machine->describe_context(), data, reg2);
1262         }
1263         break;
1264
1265      default:
1266         logerror("%s: unknown reg2 written: %02x = %02x\n", space->machine->describe_context(), reg2, data);
1267   }
1268}
1269static READ8_HANDLER( tdoboon_rambank_r )
1270{
1271   if (offset == 0)
1272      return reg2;
1273
1274   switch ( reg2 )
1275   {
1276      case 0x33:
1277         return rambank;
1278
1279      default:
1280         logerror("%s: unknown reg2 read: %02x\n", space->machine->describe_context(), reg2);
1281         return 0x00;
1282   }
1283}
1284
1285static READ8_HANDLER( tdoboon_c000_r )
1286{
1287   switch (rombank)
1288   {
1289      case 0x10:   // ROM
1290      case 0x11:
1291      case 0x12:
1292      case 0x13:
1293      case 0x14:
1294      case 0x15:
1295      case 0x16:
1296      case 0x17:
1297      case 0x18:
1298      case 0x19:
1299      case 0x1a:
1300      case 0x1b:
1301      case 0x1c:
1302      case 0x1d:
1303      case 0x1e:
1304      case 0x1f:
1305         return space->machine->region("maincpu")->base()[offset + 0xc400 + 0x1000 * (rombank-0x10)];
1306
1307      case 0x64:   // SPRITERAM
1308         if (offset < 0x1000)
1309            return space->machine->generic.spriteram.u8[offset];
1310         break;
1311
1312      case 0x66:   // PALETTERAM + TABLE?
1313         if (offset < 0x200)
1314            return space->machine->generic.paletteram.u8[offset];
1315         break;
1316
1317      case 0x67:   // REGS
1318         if (offset == (0xc013-0xc000))
1319            return haekaka_vblank_r(space, offset);
1320         break;
1321   }
1322
1323   logerror("%s: unknown read from %02x with rombank = %02x\n", space->machine->describe_context(), offset+0xc000, rombank);
1324   return 0x00;
1325}
1326
1327static WRITE8_HANDLER( tdoboon_c000_w )
1328{
1329   switch (rombank)
1330   {
1331      case 0x64:   // SPRITERAM
1332         if (offset < 0x1000)
1333         {
1334            space->machine->generic.spriteram.u8[offset] = data;
1335            return;
1336         }
1337         break;
1338         
1339      case 0x66:   // PALETTERAM + TABLE?
1340         if (offset < 0x200)
1341         {
1342            paletteram_xRRRRRGGGGGBBBBB_be_w(space, offset, data);
1343//            space->machine->generic.paletteram.u8[offset] = data;
1344            return;
1345         }
1346         else if ((offset >= 0x800) && (offset < 0x880))
1347         {
1348            // table?
1349            return;
1350         }
1351         break;
1352   }
1353
1354   logerror("%s: unknown write to %02x = %02x with rombank = %02x\n", space->machine->describe_context(), offset+0xc000, data, rombank);
1355}
1356
1357static ADDRESS_MAP_START( tdoboon_map, ADDRESS_SPACE_PROGRAM, 8 )
1358   AM_RANGE( 0x0000, 0xbfff ) AM_ROM
1359   AM_RANGE( 0xc000, 0xcfff ) AM_READWRITE( tdoboon_c000_r, tdoboon_c000_w )
1360   AM_RANGE( 0xd000, 0xefff ) AM_RAM AM_SHARE( "nvram" ) AM_BASE( &nvram )
1361   AM_RANGE( 0xfe00, 0xffff ) AM_RAM
1362ADDRESS_MAP_END
1363
1364static ADDRESS_MAP_START( tdoboon_io, ADDRESS_SPACE_IO, 8 )
1365   ADDRESS_MAP_GLOBAL_MASK(0xff)
1366   AM_RANGE( 0x02, 0x03 ) AM_READWRITE( tdoboon_rombank_r, tdoboon_rombank_w )
1367   AM_RANGE( 0x04, 0x05 ) AM_READWRITE( tdoboon_rambank_r, tdoboon_rambank_w )
1368
1369   AM_RANGE( 0x2c, 0x2c ) AM_DEVREADWRITE( "eeprom", sammymdl_eeprom_r, sammymdl_eeprom_w )
1370   AM_RANGE( 0x2e, 0x2e ) AM_READ( sammymdl_coin_hopper_r )
1371   AM_RANGE( 0x30, 0x30 ) AM_READ_PORT( "BUTTON" )
1372   AM_RANGE( 0x31, 0x31 ) AM_WRITE( sammymdl_coin_w )
1373   AM_RANGE( 0x32, 0x32 ) AM_WRITE( sammymdl_leds_w )
1374   AM_RANGE( 0x90, 0x91 ) AM_DEVWRITE("oki", sammymdl_sound_w )
1375   AM_RANGE( 0x92, 0x92 ) AM_DEVWRITE("oki", sammymdl_sound_r )
1376   AM_RANGE( 0xb0, 0xb0 ) AM_WRITE( sammymdl_hopper_w )
1377   AM_RANGE( 0xc0, 0xc0 ) AM_WRITE( watchdog_reset_w )   // 1
1378ADDRESS_MAP_END
1379
1380
1381/***************************************************************************
1382
9211383    Graphics Layout
9221384
9231385***************************************************************************/
r10427r10428
9741436
9751437   PORT_START("IN1")
9761438   PORT_BIT( 0x01, IP_ACTIVE_LOW,  IPT_COIN2   ) PORT_IMPULSE(5)   // ? (coin error, pulses mask 4 of port c6)
977   PORT_BIT( 0x02, IP_ACTIVE_LOW,  IPT_COIN1   ) PORT_IMPULSE(5)   // coin/medal in (coin error)
1439   PORT_BIT( 0x02, IP_ACTIVE_LOW,  IPT_COIN1   ) PORT_IMPULSE(5) PORT_NAME("Medal")   // coin/medal in (coin error)
9781440   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_READ_LINE_DEVICE("hopper", ticket_dispenser_line_r)
9791441   PORT_SERVICE( 0x08, IP_ACTIVE_LOW )
9801442   PORT_BIT( 0x10, IP_ACTIVE_LOW,  IPT_BUTTON2 ) PORT_NAME("Bet")   // bet / select in test menu
r10427r10428
10121474   PORT_START("COIN")
10131475   PORT_BIT( 0x01, IP_ACTIVE_LOW,  IPT_COIN1   ) PORT_IMPULSE(5)   // coin1 in
10141476   PORT_BIT( 0x02, IP_ACTIVE_LOW,  IPT_COIN2   ) PORT_IMPULSE(5)   // coin2 in
1015   PORT_BIT( 0x04, IP_ACTIVE_LOW,  IPT_COIN3   ) PORT_IMPULSE(5)   // medal in
1477   PORT_BIT( 0x04, IP_ACTIVE_LOW,  IPT_COIN3   ) PORT_IMPULSE(5) PORT_NAME("Medal")   // medal in
10161478   PORT_BIT( 0x08, IP_ACTIVE_LOW,  IPT_SERVICE )   // test sw
10171479   PORT_BIT( 0x10, IP_ACTIVE_LOW,  IPT_UNKNOWN )
10181480   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_READ_LINE_DEVICE("hopper", ticket_dispenser_line_r)
r10427r10428
10201482   PORT_BIT( 0x80, IP_ACTIVE_LOW,  IPT_UNKNOWN )
10211483INPUT_PORTS_END
10221484
1485static INPUT_PORTS_START( haekaka )
1486   PORT_START("BUTTON")
1487   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1   ) PORT_IMPULSE(5) PORT_NAME( "Medal" )   // medal in ("chacker")
1488   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNKNOWN )
1489   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )
1490   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )
1491   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
1492   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
1493   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
1494   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
10231495
1496   PORT_START("COIN")
1497   PORT_BIT( 0x01, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
1498   PORT_BIT( 0x02, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
1499   PORT_BIT( 0x04, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
1500   PORT_BIT( 0x08, IP_ACTIVE_LOW,  IPT_SERVICE  )   // test sw
1501   PORT_BIT( 0x10, IP_ACTIVE_LOW,  IPT_BUTTON1  )   // button
1502   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SPECIAL  ) PORT_READ_LINE_DEVICE("hopper", ticket_dispenser_line_r)
1503   PORT_BIT( 0x40, IP_ACTIVE_LOW,  IPT_SERVICE1 )   // service coin / set in test mode
1504   PORT_BIT( 0x80, IP_ACTIVE_LOW,  IPT_UNKNOWN  )
1505INPUT_PORTS_END
1506
1507
10241508/***************************************************************************
10251509
10261510    Machine Drivers
r10427r10428
10811565MACHINE_CONFIG_END
10821566
10831567/***************************************************************************
1084                                 Animal Catch
1568                             Sammy Medal Games
10851569***************************************************************************/
10861570
10871571static const eeprom_interface eeprom_interface_93C46_8bit =
r10427r10428
11041588   cpu_set_reg(machine->device("maincpu"), Z80_PC, 0x400);   // code starts at 400 ??? (000 = cart header)
11051589}
11061590
1591// Everything here is a guess:
1592static MACHINE_CONFIG_START( sammymdl, driver_device )
1593   MCFG_CPU_ADD("maincpu", Z80, 8000000)   // ???
1594
1595   MCFG_MACHINE_RESET( sammymdl )
1596
1597   MCFG_NVRAM_ADD_0FILL("nvram")   // battery
1598   MCFG_EEPROM_ADD("eeprom", eeprom_interface_93C46_8bit)
1599
1600   MCFG_TICKET_DISPENSER_ADD("hopper", 200, TICKET_MOTOR_ACTIVE_LOW, TICKET_STATUS_ACTIVE_LOW )
1601
1602   // video hardware
1603   MCFG_SCREEN_ADD("screen", RASTER)
1604   MCFG_SCREEN_REFRESH_RATE(60)
1605   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
1606   MCFG_SCREEN_SIZE(0x140, 0x100)
1607   MCFG_SCREEN_VISIBLE_AREA(0, 0x140-1, 0, 0xf0-1)
1608
1609   MCFG_GFXDECODE(sigmab98)
1610   MCFG_PALETTE_LENGTH(0x100)
1611
1612   MCFG_VIDEO_UPDATE(sigmab98)
1613   MCFG_VIDEO_EOF(sammymdl)
1614
1615   // sound hardware
1616   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
1617
1618   MCFG_OKIM9810_ADD("oki", 16000)   // OKI MSM981x? Clock?
1619   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 0.80)
1620   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.80)
1621MACHINE_CONFIG_END
1622
1623
1624/***************************************************************************
1625                                 Animal Catch
1626***************************************************************************/
1627
11071628static INTERRUPT_GEN( animalc )
11081629{
11091630   switch (cpu_getiloops(device))
r10427r10428
11221643   }
11231644}
11241645
1125// Everything here is a guess:
1126static MACHINE_CONFIG_START( animalc, driver_device )
1127   MCFG_CPU_ADD("maincpu", Z80, 8000000)   // ???
1646static MACHINE_CONFIG_DERIVED( animalc, sammymdl )
1647   MCFG_CPU_MODIFY("maincpu")
11281648   MCFG_CPU_PROGRAM_MAP( animalc_map )
11291649   MCFG_CPU_IO_MAP( animalc_io )
11301650   MCFG_CPU_VBLANK_INT_HACK(animalc, 3) // IM 2 needs a vector on the data bus
1651MACHINE_CONFIG_END
11311652
1132   MCFG_MACHINE_RESET( sammymdl )
1653/***************************************************************************
1654                             Hae Hae Ka Ka Ka
1655***************************************************************************/
11331656
1134   MCFG_NVRAM_ADD_0FILL("nvram")   // battery
1135   MCFG_EEPROM_ADD("eeprom", eeprom_interface_93C46_8bit)
1657static INTERRUPT_GEN( haekaka )
1658{
1659   switch (cpu_getiloops(device))
1660   {
1661      case 0:
1662         cpu_set_input_line_and_vector(device, 0, HOLD_LINE, 0x04);
1663         break;
11361664
1137   MCFG_TICKET_DISPENSER_ADD("hopper", 200, TICKET_MOTOR_ACTIVE_LOW, TICKET_STATUS_ACTIVE_LOW )
1665      case 1:
1666         cpu_set_input_line_and_vector(device, 0, HOLD_LINE, 0x1a);
1667         break;
11381668
1139   // video hardware
1140   MCFG_SCREEN_ADD("screen", RASTER)
1141   MCFG_SCREEN_REFRESH_RATE(60)
1142   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
1143   MCFG_SCREEN_SIZE(0x140, 0x100)
1144   MCFG_SCREEN_VISIBLE_AREA(0, 0x140-1, 0, 0xf0-1)
1669      case 2:
1670         cpu_set_input_line_and_vector(device, 0, HOLD_LINE, 0x1c);
1671         break;
1672   }
1673}
11451674
1146   MCFG_GFXDECODE(sigmab98)
1147   MCFG_PALETTE_LENGTH(0x100)
1148
1149   MCFG_VIDEO_UPDATE(sigmab98)
1150   MCFG_VIDEO_EOF(sammymdl)
1151
1152   // sound hardware
1153   // OKI MSM981x ?
1675static MACHINE_CONFIG_DERIVED( haekaka, sammymdl )
1676   MCFG_CPU_MODIFY("maincpu")
1677   MCFG_CPU_PROGRAM_MAP( haekaka_map )
1678   MCFG_CPU_IO_MAP( haekaka_io )
1679   MCFG_CPU_VBLANK_INT_HACK(haekaka, 3) // IM 2 needs a vector on the data bus
11541680MACHINE_CONFIG_END
11551681
11561682/***************************************************************************
r10427r10428
11751701   }
11761702}
11771703
1178// Everything here is a guess:
1179static MACHINE_CONFIG_START( itazuram, driver_device )
1180   MCFG_CPU_ADD("maincpu", Z80, 8000000)   // ???
1704static MACHINE_CONFIG_DERIVED( itazuram, sammymdl )
1705   MCFG_CPU_MODIFY("maincpu")
11811706   MCFG_CPU_PROGRAM_MAP( itazuram_map )
11821707   MCFG_CPU_IO_MAP( itazuram_io )
11831708   MCFG_CPU_VBLANK_INT_HACK(itazuram, 3) // IM 2 needs a vector on the data bus
1709MACHINE_CONFIG_END
11841710
1185   MCFG_MACHINE_RESET( sammymdl )
1711/***************************************************************************
1712                             Pye-nage Taikai
1713***************************************************************************/
11861714
1187   MCFG_NVRAM_ADD_0FILL("nvram")   // battery
1188   MCFG_EEPROM_ADD("eeprom", eeprom_interface_93C46_8bit)
1715static MACHINE_CONFIG_DERIVED( pyenaget, sammymdl )
1716   MCFG_CPU_MODIFY("maincpu")
1717   MCFG_CPU_PROGRAM_MAP( haekaka_map )
1718   MCFG_CPU_IO_MAP( pyenaget_io )
1719   MCFG_CPU_VBLANK_INT_HACK(haekaka, 3) // IM 2 needs a vector on the data bus
1720MACHINE_CONFIG_END
11891721
1190   MCFG_TICKET_DISPENSER_ADD("hopper", 200, TICKET_MOTOR_ACTIVE_LOW, TICKET_STATUS_ACTIVE_LOW )
1722/***************************************************************************
1723                             Taihou de Doboon
1724***************************************************************************/
11911725
1192   // video hardware
1193   MCFG_SCREEN_ADD("screen", RASTER)
1194   MCFG_SCREEN_REFRESH_RATE(60)
1195   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16)
1196   MCFG_SCREEN_SIZE(0x140, 0x100)
1197   MCFG_SCREEN_VISIBLE_AREA(0, 0x140-1, 0, 0xf0-1)
1726static MACHINE_CONFIG_DERIVED( tdoboon, sammymdl )
1727   MCFG_CPU_MODIFY("maincpu")
1728   MCFG_CPU_PROGRAM_MAP( tdoboon_map )
1729   MCFG_CPU_IO_MAP( tdoboon_io )
1730   MCFG_CPU_VBLANK_INT_HACK(haekaka, 3) // IM 2 needs a vector on the data bus
11981731
1199   MCFG_GFXDECODE(sigmab98)
1200   MCFG_PALETTE_LENGTH(0x100)
1201
1202   MCFG_VIDEO_UPDATE(sigmab98)
1203//  MCFG_VIDEO_EOF(sammymdl)
1204
1205   // sound hardware
1206   // OKI MSM981x ?
1732   MCFG_SCREEN_MODIFY("screen")
1733   MCFG_SCREEN_VISIBLE_AREA(0,0x140-1, 0+4,0xf0+4-1)
12071734MACHINE_CONFIG_END
12081735
12091736
r10427r10428
12981825***************************************************************************/
12991826
13001827ROM_START( animalc )
1301   ROM_REGION( 0x200000, "samples", 0 )
1828   ROM_REGION( 0x1000000, "oki", 0 )
13021829   ROM_LOAD( "vx2302l01.u021", 0x00000, 0x200000, CRC(84cf123b) SHA1(d8b425c93ff1a560e3f92c70d7eb93a05c3581af) )
13031830
13041831   ROM_REGION( 0x40000, "maincpu", 0 )
1305   ROM_COPY( "samples", 0x1c0000, 0x00000, 0x40000 )
1832   ROM_COPY( "oki", 0x1c0000, 0x00000, 0x40000 )
13061833
13071834   ROM_REGION( 0x200000, "sprites", 0 )
13081835   ROM_LOAD( "vx2301l01.u016", 0x00000, 0x200000, CRC(4ae14ff9) SHA1(1273d15ea642452fecacff572655cd3ab47a5884) )   // 1xxxxxxxxxxxxxxxxxxxx = 0x00
r10427r10428
13331860***************************************************************************/
13341861
13351862ROM_START( itazuram )
1336   ROM_REGION( 0x200000, "samples", 0 )
1863   ROM_REGION( 0x1000000, "oki", 0 )
13371864   ROM_LOAD( "vx2002l01.u021", 0x00000, 0x200000, CRC(ddbdd2f3) SHA1(91f67a938929be0261442e066e3d2c03b5e9f06a) )
13381865
13391866   ROM_REGION( 0x40000, "maincpu", 0 )
1340   ROM_COPY( "samples", 0x1c0000, 0x00000, 0x40000 )
1867   ROM_COPY( "oki", 0x1c0000, 0x00000, 0x40000 )
13411868
13421869   ROM_REGION( 0x200000, "sprites", 0 )
13431870   ROM_LOAD( "vx2001l01.u016", 0x00000, 0x200000, CRC(9ee95222) SHA1(7154d43ef312a48a882207ca37e1c61e8b215a9b) )
r10427r10428
13881915***************************************************************************/
13891916
13901917ROM_START( tdoboon )
1391   ROM_REGION( 0x200000, "samples", 0 )
1918   ROM_REGION( 0x1000000, "oki", 0 )
13921919   ROM_LOAD( "em4210l01.u021.bin", 0x00000, 0x200000, CRC(3523e314) SHA1(d07c5d17d3f285be4cde810547f427e84f98968f) )
13931920
13941921   ROM_REGION( 0x40000, "maincpu", 0 )
1395   ROM_COPY( "samples", 0x1c0000, 0x00000, 0x40000 )
1922   ROM_COPY( "oki", 0x1c0000, 0x00000, 0x40000 )
13961923
13971924   ROM_REGION( 0x200000, "sprites", 0 )
13981925   ROM_LOAD( "em4209l01.u016.bin", 0x00000, 0x200000, CRC(aca220fa) SHA1(7db441add16af554700e597fd9926b6ccd19d628) )   // 1xxxxxxxxxxxxxxxxxxxx = 0xFF
r10427r10428
14081935***************************************************************************/
14091936
14101937ROM_START( pyenaget )
1411   ROM_REGION( 0x200000, "samples", 0 )
1938   ROM_REGION( 0x1000000, "oki", 0 )
14121939   ROM_LOAD( "vx1802l01.u021", 0x00000, 0x200000, CRC(7a22a657) SHA1(2a98085862fd958209253c5401e41eae4f7c06ea) )
14131940
14141941   ROM_REGION( 0x40000, "maincpu", 0 )
1415   ROM_COPY( "samples", 0x1c0000, 0x00000, 0x40000 )
1942   ROM_COPY( "oki", 0x1c0000, 0x00000, 0x40000 )
14161943
14171944   ROM_REGION( 0x200000, "sprites", 0 )
14181945   ROM_LOAD( "vx1801l01.u016", 0x00000, 0x200000, CRC(c4607403) SHA1(f4f4699442afccc5ed4354447f91b1bee36ae3e5) )
r10427r10428
14421969***************************************************************************/
14431970
14441971ROM_START( haekaka )
1445   ROM_REGION( 0x200000, "samples", 0 )
1972   ROM_REGION( 0x1000000, "oki", 0 )
14461973   ROM_LOAD( "em4208l01.u021.bin", 0x00000, 0x200000, CRC(d23bb748) SHA1(38d5b6c4b2cd470b3a68574aeca3f9fa9032245e) )
14471974
14481975   ROM_REGION( 0x40000, "maincpu", 0 )
1449   ROM_COPY( "samples", 0x1c0000, 0x00000, 0x40000 )
1976   ROM_COPY( "oki", 0x1c0000, 0x00000, 0x40000 )
14501977
14511978   ROM_REGION( 0x200000, "sprites", 0 )
14521979   ROM_LOAD( "em4207l01.u016.bin", 0x00000, 0x200000, CRC(3876961c) SHA1(3d842c1f63ea5aa7e799967928b86c5fabb4e65e) )
14531980ROM_END
14541981
1982static DRIVER_INIT( haekaka )
1983{
1984   // RAM banks
1985   machine->generic.paletteram.u8 = auto_alloc_array(machine, UINT8, 0x200);
1986   memset(machine->generic.paletteram.u8, 0, 0x200);
1987
1988   machine->generic.spriteram.u8 = auto_alloc_array(machine, UINT8, 0x1000);
1989   memset(machine->generic.spriteram.u8, 0, 0x1000);
1990   machine->generic.spriteram_size = 0x1000;
1991
1992   rombank = 0x65;
1993   rambank = 0x53;
1994}
1995
1996
14551997/***************************************************************************
14561998
14571999    Game Drivers
14582000
14592001***************************************************************************/
14602002
1461GAME( 1997, gegege,   0, gegege,   gegege,   gegege,   ROT0, "Banpresto / Sigma", "GeGeGe no Kitarou Youkai Slot", 0             )
2003GAME( 1997, gegege,   0, gegege,   gegege,   gegege,   ROT0, "Banpresto / Sigma", "GeGeGe no Kitarou Youkai Slot", 0                    )
14622004// Sammy Medal Games:
1463GAME( 2000, animalc,  0, animalc,  sammymdl, animalc,  ROT0, "Sammy",             "Animal Catch",                  GAME_NO_SOUND )
1464GAME( 2000, itazuram, 0, itazuram, sammymdl, itazuram, ROT0, "Sammy",             "Itazura Monkey",                GAME_NO_SOUND )
1465GAME( 2000, pyenaget, 0, animalc,  sammymdl, 0,        ROT0, "Sammy",             "Pye-nage Taikai",               GAME_NO_SOUND | GAME_NOT_WORKING )
1466GAME( 2002, haekaka,  0, animalc,  sammymdl, 0,        ROT0, "Sammy",             "Hae Hae Ka Ka Ka",              GAME_NO_SOUND | GAME_NOT_WORKING )
1467GAME( 2002, tdoboon,  0, animalc,  sammymdl, 0,        ROT0, "Sammy",             "Taihou de Doboon",              GAME_NO_SOUND | GAME_NOT_WORKING )
2005GAME( 2000, animalc,  0, animalc,  sammymdl, animalc,  ROT0, "Sammy",             "Animal Catch",                  GAME_IMPERFECT_SOUND )
2006GAME( 2000, itazuram, 0, itazuram, sammymdl, itazuram, ROT0, "Sammy",             "Itazura Monkey",                GAME_IMPERFECT_SOUND )
2007GAME( 2000, pyenaget, 0, pyenaget, sammymdl, haekaka,  ROT0, "Sammy",             "Pye-nage Taikai",               GAME_IMPERFECT_SOUND )
2008GAME( 2000, tdoboon,  0, tdoboon,  haekaka,  haekaka,  ROT0, "Sammy",             "Taihou de Doboon",              GAME_IMPERFECT_SOUND )
2009GAME( 2001, haekaka,  0, haekaka,  haekaka,  haekaka,  ROT0, "Sammy",             "Hae Hae Ka Ka Ka",              GAME_IMPERFECT_SOUND )
src/mame/drivers/gticlub.c
r10427r10428
237237
238238static UINT32 *work_ram;
239239
240UINT8 gticlub_led_reg0;
241UINT8 gticlub_led_reg1;
242240
243
244241static WRITE32_HANDLER( paletteram32_w )
245242{
246243   COMBINE_DATA(&space->machine->generic.paletteram.u32[offset]);
r10427r10428
258255   cputag_set_input_line(device->machine, "maincpu", INPUT_LINE_IRQ1, param ? ASSERT_LINE : CLEAR_LINE);
259256}
260257
261static VIDEO_UPDATE( hangplt )
262{
263   bitmap_fill(bitmap, cliprect, screen->machine->pens[0]);
264
265   if (strcmp(screen->tag(), "lscreen") == 0)
266   {
267      device_t *k001604 = screen->machine->device("k001604_1");
268      device_t *voodoo = screen->machine->device("voodoo0");
269
270   //  k001604_draw_back_layer(k001604, bitmap, cliprect);
271
272      voodoo_update(voodoo, bitmap, cliprect);
273
274      k001604_draw_front_layer(k001604, bitmap, cliprect);
275   }
276   else if (strcmp(screen->tag(), "rscreen") == 0)
277   {
278      device_t *k001604 = screen->machine->device("k001604_2");
279      device_t *voodoo = screen->machine->device("voodoo1");
280
281   //  k001604_draw_back_layer(k001604, bitmap, cliprect);
282
283      voodoo_update(voodoo, bitmap, cliprect);
284
285      k001604_draw_front_layer(k001604, bitmap, cliprect);
286   }
287
288   draw_7segment_led(bitmap, 3, 3, gticlub_led_reg0);
289   draw_7segment_led(bitmap, 9, 3, gticlub_led_reg1);
290
291   return 0;
292}
293
294258static READ32_HANDLER( gticlub_k001604_tile_r )
295259{
296260   device_t *k001604 = space->machine->device(get_cgboard_id() ? "k001604_2" : "k001604_1");
r10427r10428
389353   switch (offset)
390354   {
391355      case 0:
392         gticlub_led_reg0 = data;
393         break;
394
395356      case 1:
396         gticlub_led_reg1 = data;
357         gticlub_led_setreg(offset, data);
397358         break;
398359
399360      case 3:
r10427r10428
11821143   init_konami_cgboard(machine, 1, CGBOARD_TYPE_GTICLUB);
11831144
11841145   sharc_dataram_0 = auto_alloc_array(machine, UINT32, 0x100000/4);
1185   gticlub_led_reg0 = gticlub_led_reg1 = 0x7f;
11861146
11871147   K001005_preprocess_texture_data(machine->region("gfx1")->base(), machine->region("gfx1")->bytes(), 1);
11881148}
r10427r10428
11951155
11961156   sharc_dataram_0 = auto_alloc_array(machine, UINT32, 0x100000/4);
11971157   sharc_dataram_1 = auto_alloc_array(machine, UINT32, 0x100000/4);
1198   gticlub_led_reg0 = gticlub_led_reg1 = 0x7f;
11991158}
12001159
12011160/*************************************************************************/
src/mame/drivers/model1.c
r10427r10428
627627#include "emu.h"
628628#include "cpu/v60/v60.h"
629629#include "deprecat.h"
630#include "includes/system16.h"
631630#include "video/segaic24.h"
632631#include "cpu/m68000/m68000.h"
633632#include "cpu/mb86233/mb86233.h"
r10427r10428
636635#include "machine/nvram.h"
637636#include "includes/model1.h"
638637
639static int model1_sound_irq;
640638
641#define FIFO_SIZE   (8)
642static int to_68k[FIFO_SIZE], fifo_wptr, fifo_rptr;
643639
644640static READ16_HANDLER( io_r )
645641{
r10427r10428
683679}
684680
685681
686static int last_irq;
687682
688683static void irq_raise(running_machine *machine, int level)
689684{
685   model1_state *state = machine->driver_data<model1_state>();
690686   //  logerror("irq: raising %d\n", level);
691687   //  irq_status |= (1 << level);
692   last_irq = level;
688   state->last_irq = level;
693689   cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE);
694690}
695691
696692static IRQ_CALLBACK(irq_callback)
697693{
698   return last_irq;
694   model1_state *state = device->machine->driver_data<model1_state>();
695   return state->last_irq;
699696}
700697// vf
701698// 1 = fe3ed4
r10427r10428
719716
720717static INTERRUPT_GEN(model1_interrupt)
721718{
719   model1_state *state = device->machine->driver_data<model1_state>();
722720   if (cpu_getiloops(device))
723721   {
724722      irq_raise(device->machine, 1);
725723   }
726724   else
727725   {
728      irq_raise(device->machine, model1_sound_irq);
726      irq_raise(device->machine, state->sound_irq);
729727
730728      // if the FIFO has something in it, signal the 68k too
731      if (fifo_rptr != fifo_wptr)
729      if (state->fifo_rptr != state->fifo_wptr)
732730      {
733731         cputag_set_input_line(device->machine, "audiocpu", 2, HOLD_LINE);
734732      }
r10427r10428
737735
738736static MACHINE_RESET(model1)
739737{
738   model1_state *state = machine->driver_data<model1_state>();
740739   memory_set_bankptr(machine, "bank1", machine->region("maincpu")->base() + 0x1000000);
741740   irq_init(machine);
742741   model1_tgp_reset(machine, !strcmp(machine->gamedrv->name, "swa") || !strcmp(machine->gamedrv->name, "wingwar") || !strcmp(machine->gamedrv->name, "wingwaru") || !strcmp(machine->gamedrv->name, "wingwarj"));
743742   if (!strcmp(machine->gamedrv->name, "swa"))
744743   {
745      model1_sound_irq = 0;
744      state->sound_irq = 0;
746745   }
747746   else
748747   {
749      model1_sound_irq = 3;
748      state->sound_irq = 3;
750749   }
751750
752751   // init the sound FIFO
753   fifo_rptr = fifo_wptr = 0;
754   memset(to_68k, 0, sizeof(to_68k));
752   state->fifo_rptr = state->fifo_wptr = 0;
753   memset(state->to_68k, 0, sizeof(state->to_68k));
755754}
756755
757756static MACHINE_RESET(model1_vr)
758757{
758   model1_state *state = machine->driver_data<model1_state>();
759759   memory_set_bankptr(machine, "bank1", machine->region("maincpu")->base() + 0x1000000);
760760   irq_init(machine);
761761   model1_vr_tgp_reset(machine);
762   model1_sound_irq = 3;
762   state->sound_irq = 3;
763763
764764   // init the sound FIFO
765   fifo_rptr = fifo_wptr = 0;
766   memset(to_68k, 0, sizeof(to_68k));
765   state->fifo_rptr = state->fifo_wptr = 0;
766   memset(state->to_68k, 0, sizeof(state->to_68k));
767767}
768768
769769static READ16_HANDLER( network_ctl_r )
r10427r10428
780780
781781static WRITE16_HANDLER(md1_w)
782782{
783   COMBINE_DATA(model1_display_list1+offset);
783   model1_state *state = space->machine->driver_data<model1_state>();
784   COMBINE_DATA(state->display_list1+offset);
784785   if(0 && offset)
785786      return;
786   if(1 && model1_dump)
787   if(1 && state->dump)
787788      logerror("TGP: md1_w %x, %04x @ %04x (%x)\n", offset, data, mem_mask, cpu_get_pc(space->cpu));
788789}
789790
790791static WRITE16_HANDLER(md0_w)
791792{
792   COMBINE_DATA(model1_display_list0+offset);
793   model1_state *state = space->machine->driver_data<model1_state>();
794   COMBINE_DATA(state->display_list0+offset);
793795   if(0 && offset)
794796      return;
795   if(1 && model1_dump)
797   if(1 && state->dump)
796798      logerror("TGP: md0_w %x, %04x @ %04x (%x)\n", offset, data, mem_mask, cpu_get_pc(space->cpu));
797799}
798800
r10427r10428
804806      logerror("XVIDEO: p_w %x, %04x @ %04x (%x)\n", offset, data, mem_mask, cpu_get_pc(space->cpu));
805807}
806808
807static UINT16 *mr;
808809static WRITE16_HANDLER(mr_w)
809810{
810   COMBINE_DATA(mr+offset);
811   model1_state *state = space->machine->driver_data<model1_state>();
812   COMBINE_DATA(state->mr+offset);
811813   if(0 && offset == 0x1138/2)
812814      logerror("MR.w %x, %04x @ %04x (%x)\n", offset*2+0x500000, data, mem_mask, cpu_get_pc(space->cpu));
813815}
814816
815static UINT16 *mr2;
816817static WRITE16_HANDLER(mr2_w)
817818{
818   COMBINE_DATA(mr2+offset);
819   model1_state *state = space->machine->driver_data<model1_state>();
820   COMBINE_DATA(state->mr2+offset);
819821#if 0
820822   if(0 && offset == 0x6e8/2) {
821823      logerror("MR.w %x, %04x @ %04x (%x)\n", offset*2+0x400000, data, mem_mask, cpu_get_pc(space->cpu));
822824   }
823825   if(offset/2 == 0x3680/4)
824      logerror("MW f80[r25], %04x%04x (%x)\n", mr2[0x3680/2+1], mr2[0x3680/2], cpu_get_pc(space->cpu));
826      logerror("MW f80[r25], %04x%04x (%x)\n", state->mr2[0x3680/2+1], state->mr2[0x3680/2], cpu_get_pc(space->cpu));
825827   if(offset/2 == 0x06ca/4)
826      logerror("MW fca[r19], %04x%04x (%x)\n", mr2[0x06ca/2+1], mr2[0x06ca/2], cpu_get_pc(space->cpu));
828      logerror("MW fca[r19], %04x%04x (%x)\n", state->mr2[0x06ca/2+1], state->mr2[0x06ca/2], cpu_get_pc(space->cpu));
827829   if(offset/2 == 0x1eca/4)
828      logerror("MW fca[r22], %04x%04x (%x)\n", mr2[0x1eca/2+1], mr2[0x1eca/2], cpu_get_pc(space->cpu));
830      logerror("MW fca[r22], %04x%04x (%x)\n", state->mr2[0x1eca/2+1], state->mr2[0x1eca/2], cpu_get_pc(space->cpu));
829831#endif
830832
831833   // wingwar scene position, pc=e1ce -> d735
832834   if(offset/2 == 0x1f08/4)
833      logerror("MW  8[r10], %f (%x)\n", *(float *)(mr2+0x1f08/2), cpu_get_pc(space->cpu));
835      logerror("MW  8[r10], %f (%x)\n", *(float *)(state->mr2+0x1f08/2), cpu_get_pc(space->cpu));
834836   if(offset/2 == 0x1f0c/4)
835      logerror("MW  c[r10], %f (%x)\n", *(float *)(mr2+0x1f0c/2), cpu_get_pc(space->cpu));
837      logerror("MW  c[r10], %f (%x)\n", *(float *)(state->mr2+0x1f0c/2), cpu_get_pc(space->cpu));
836838   if(offset/2 == 0x1f10/4)
837      logerror("MW 10[r10], %f (%x)\n", *(float *)(mr2+0x1f10/2), cpu_get_pc(space->cpu));
839      logerror("MW 10[r10], %f (%x)\n", *(float *)(state->mr2+0x1f10/2), cpu_get_pc(space->cpu));
838840}
839841
840842static READ16_HANDLER( snd_68k_ready_r )
r10427r10428
852854
853855static WRITE16_HANDLER( snd_latch_to_68k_w )
854856{
855   to_68k[fifo_wptr] = data;
856   fifo_wptr++;
857   if (fifo_wptr >= FIFO_SIZE) fifo_wptr = 0;
857   model1_state *state = space->machine->driver_data<model1_state>();
858   state->to_68k[state->fifo_wptr] = data;
859   state->fifo_wptr++;
860   if (state->fifo_wptr >= ARRAY_LENGTH(state->to_68k)) state->fifo_wptr = 0;
858861
859862   // signal the 68000 that there's data waiting
860863   cputag_set_input_line(space->machine, "audiocpu", 2, HOLD_LINE);
r10427r10428
867870   AM_RANGE(0x100000, 0x1fffff) AM_ROMBANK("bank1")
868871   AM_RANGE(0x200000, 0x2fffff) AM_ROM
869872
870   AM_RANGE(0x400000, 0x40ffff) AM_RAM_WRITE(mr2_w) AM_BASE(&mr2)
871   AM_RANGE(0x500000, 0x53ffff) AM_RAM_WRITE(mr_w)  AM_BASE(&mr)
873   AM_RANGE(0x400000, 0x40ffff) AM_RAM_WRITE(mr2_w) AM_BASE_MEMBER(model1_state, mr2)
874   AM_RANGE(0x500000, 0x53ffff) AM_RAM_WRITE(mr_w)  AM_BASE_MEMBER(model1_state, mr)
872875
873   AM_RANGE(0x600000, 0x60ffff) AM_RAM_WRITE(md0_w) AM_BASE(&model1_display_list0)
874   AM_RANGE(0x610000, 0x61ffff) AM_RAM_WRITE(md1_w) AM_BASE(&model1_display_list1)
876   AM_RANGE(0x600000, 0x60ffff) AM_RAM_WRITE(md0_w) AM_BASE_MEMBER(model1_state, display_list0)
877   AM_RANGE(0x610000, 0x61ffff) AM_RAM_WRITE(md1_w) AM_BASE_MEMBER(model1_state, display_list1)
875878   AM_RANGE(0x680000, 0x680003) AM_READWRITE(model1_listctl_r, model1_listctl_w)
876879
877880   AM_RANGE(0x700000, 0x70ffff) AM_READWRITE(sys24_tile_r, sys24_tile_w)
r10427r10428
882885   AM_RANGE(0x780000, 0x7fffff) AM_READWRITE(sys24_char_r, sys24_char_w)
883886
884887   AM_RANGE(0x900000, 0x903fff) AM_RAM_WRITE(p_w) AM_BASE_GENERIC(paletteram)
885   AM_RANGE(0x910000, 0x91bfff) AM_RAM  AM_BASE(&model1_color_xlat)
888   AM_RANGE(0x910000, 0x91bfff) AM_RAM  AM_BASE_MEMBER(model1_state, color_xlat)
886889
887890   AM_RANGE(0xc00000, 0xc0003f) AM_READ(io_r) AM_WRITENOP
888891
r10427r10428
915918   AM_RANGE(0x100000, 0x1fffff) AM_ROMBANK("bank1")
916919   AM_RANGE(0x200000, 0x2fffff) AM_ROM
917920
918   AM_RANGE(0x400000, 0x40ffff) AM_RAM_WRITE(mr2_w) AM_BASE(&mr2)
919   AM_RANGE(0x500000, 0x53ffff) AM_RAM_WRITE(mr_w)  AM_BASE(&mr)
921   AM_RANGE(0x400000, 0x40ffff) AM_RAM_WRITE(mr2_w) AM_BASE_MEMBER(model1_state, mr2)
922   AM_RANGE(0x500000, 0x53ffff) AM_RAM_WRITE(mr_w)  AM_BASE_MEMBER(model1_state, mr)
920923
921   AM_RANGE(0x600000, 0x60ffff) AM_RAM_WRITE(md0_w) AM_BASE(&model1_display_list0)
922   AM_RANGE(0x610000, 0x61ffff) AM_RAM_WRITE(md1_w) AM_BASE(&model1_display_list1)
924   AM_RANGE(0x600000, 0x60ffff) AM_RAM_WRITE(md0_w) AM_BASE_MEMBER(model1_state, display_list0)
925   AM_RANGE(0x610000, 0x61ffff) AM_RAM_WRITE(md1_w) AM_BASE_MEMBER(model1_state, display_list1)
923926   AM_RANGE(0x680000, 0x680003) AM_READWRITE(model1_listctl_r, model1_listctl_w)
924927
925928   AM_RANGE(0x700000, 0x70ffff) AM_READWRITE(sys24_tile_r, sys24_tile_w)
r10427r10428
930933   AM_RANGE(0x780000, 0x7fffff) AM_READWRITE(sys24_char_r, sys24_char_w)
931934
932935   AM_RANGE(0x900000, 0x903fff) AM_RAM_WRITE(p_w) AM_BASE_GENERIC(paletteram)
933   AM_RANGE(0x910000, 0x91bfff) AM_RAM  AM_BASE(&model1_color_xlat)
936   AM_RANGE(0x910000, 0x91bfff) AM_RAM  AM_BASE_MEMBER(model1_state, color_xlat)
934937
935938   AM_RANGE(0xc00000, 0xc0003f) AM_READ(io_r) AM_WRITENOP
936939
r10427r10428
960963
961964static READ16_HANDLER( m1_snd_68k_latch_r )
962965{
966   model1_state *state = space->machine->driver_data<model1_state>();
963967   UINT16 retval;
964968
965   retval = to_68k[fifo_rptr];
969   retval = state->to_68k[state->fifo_rptr];
966970
967   fifo_rptr++;
968   if (fifo_rptr >= FIFO_SIZE) fifo_rptr = 0;
971   state->fifo_rptr++;
972   if (state->fifo_rptr >= ARRAY_LENGTH(state->to_68k)) state->fifo_rptr = 0;
969973
970974   return retval;
971975}
r10427r10428
14971501ROM_END
14981502
14991503
1500static MACHINE_CONFIG_START( model1, driver_device )
1504static MACHINE_CONFIG_START( model1, model1_state )
15011505   MCFG_CPU_ADD("maincpu", V60, 16000000)
15021506   MCFG_CPU_PROGRAM_MAP(model1_mem)
15031507   MCFG_CPU_IO_MAP(model1_io)
r10427r10428
15371541   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
15381542MACHINE_CONFIG_END
15391543
1540static MACHINE_CONFIG_START( model1_vr, driver_device )
1544static MACHINE_CONFIG_START( model1_vr, model1_state )
15411545   MCFG_CPU_ADD("maincpu", V60, 16000000)
15421546   MCFG_CPU_PROGRAM_MAP(model1_vr_mem)
15431547   MCFG_CPU_IO_MAP(model1_vr_io)
src/mame/drivers/qdrmfgp.c
r10427r10428
2828#include "machine/nvram.h"
2929#include "includes/qdrmfgp.h"
3030
31static UINT8 *sndram;
32static UINT16 *workram;
33static UINT16 control;
34static INT32 qdrmfgp_pal;
35static INT32 gp2_irq_control;
3631
3732/*************************************
3833 *
r10427r10428
4237
4338static CUSTOM_INPUT( inputs_r )
4439{
40   qdrmfgp_state *state = field->port->machine->driver_data<qdrmfgp_state>();
4541   const char *tag1 = (const char *)param;
4642   const char *tag2 = tag1 + strlen(tag1) + 1;
47   return input_port_read(field->port->machine, (control & 0x0080) ? tag1 : tag2);
43   return input_port_read(field->port->machine, (state->control & 0x0080) ? tag1 : tag2);
4844}
4945
5046static CUSTOM_INPUT( battery_sensor_r )
r10427r10428
5450}
5551
5652
57int qdrmfgp_get_palette(void)
53static WRITE16_HANDLER( gp_control_w )
5854{
59   return qdrmfgp_pal;
60}
55   qdrmfgp_state *state = space->machine->driver_data<qdrmfgp_state>();
6156
62static WRITE16_HANDLER( gp_control_w )
63{
6457   /* bit 0        enable irq 1 (sound) */
6558   /* bit 1        enable irq 2 (not used) */
6659   /* bit 2        enable irq 3 (vblank) */
r10427r10428
7366   /* bit 11       headphone volume: 1=up, 0=down */
7467   /* bit 15       gfxrom bankswitch */
7568
76   COMBINE_DATA(&control);
77   qdrmfgp_pal = control & 0x70;
69   COMBINE_DATA(&state->control);
70   state->pal = state->control & 0x70;
7871
79   if (control & 0x0100)
72   if (state->control & 0x0100)
8073   {
8174      qdrmfgp_state *state = space->machine->driver_data<qdrmfgp_state>();
8275      int vol = state->m_nvram[0x10] & 0xff;
r10427r10428
9487
9588static WRITE16_HANDLER( gp2_control_w )
9689{
90   qdrmfgp_state *state = space->machine->driver_data<qdrmfgp_state>();
91
9792   /* bit 2        enable irq 3 (sound) */
9893   /* bit 3        enable irq 4 (vblank) */
9994   /* bit 4        enable irq 5 (hdd) */
r10427r10428
10499   /* bit 11       headphone volume: 1=up, 0=down */
105100   /* bit 15       gfxrom bankswitch */
106101
107   COMBINE_DATA(&control);
108   qdrmfgp_pal = 0;
102   COMBINE_DATA(&state->control);
103   state->pal = 0;
109104
110   if (control & 0x0100)
105   if (state->control & 0x0100)
111106   {
112107      qdrmfgp_state *state = space->machine->driver_data<qdrmfgp_state>();
113108      int vol = state->m_nvram[0x8] & 0xff;
r10427r10428
126121
127122static READ16_HANDLER( v_rom_r )
128123{
124   qdrmfgp_state *state = space->machine->driver_data<qdrmfgp_state>();
129125   device_t *k056832 = space->machine->device("k056832");
130126   UINT8 *mem8 = space->machine->region("gfx1")->base();
131127   int bank = k056832_word_r(k056832, 0x34/2, 0xffff);
132128
133129   offset += bank * 0x800 * 4;
134130
135   if (control & 0x8000)
131   if (state->control & 0x8000)
136132      offset += 0x800 * 2;
137133
138134   return (mem8[offset + 1] << 8) + mem8[offset];
r10427r10428
184180
185181static READ16_HANDLER( sndram_r )
186182{
183   qdrmfgp_state *state = space->machine->driver_data<qdrmfgp_state>();
187184   if (ACCESSING_BITS_0_7)
188      return sndram[offset];
185      return state->sndram[offset];
189186
190187   return 0;
191188}
192189
193190static WRITE16_HANDLER( sndram_w )
194191{
192   qdrmfgp_state *state = space->machine->driver_data<qdrmfgp_state>();
195193   if (ACCESSING_BITS_0_7)
196194   {
197      sndram[offset] = data & 0xff;
195      state->sndram[offset] = data & 0xff;
198196      if (offset >= 0x40000)
199         sndram[offset+0xc00000-0x900000] = data & 0xff;
197         state->sndram[offset+0xc00000-0x900000] = data & 0xff;
200198   }
201199}
202200
r10427r10428
238236
239237static READ16_HANDLER( gp2_ide_std_r )
240238{
239   qdrmfgp_state *state = space->machine->driver_data<qdrmfgp_state>();
241240   device_t *device = space->machine->device("ide");
242241   if (offset & 0x01)
243242   {
r10427r10428
246245         switch (cpu_get_previouspc(space->cpu))
247246         {
248247            case 0xdb4c:
249               if ((workram[0x5fa4/2] - cpu_get_reg(space->cpu, M68K_D0)) <= 0x10)
250                  gp2_irq_control = 1;
248               if ((state->workram[0x5fa4/2] - cpu_get_reg(space->cpu, M68K_D0)) <= 0x10)
249                  state->gp2_irq_control = 1;
251250               break;
252251            case 0xdec2:
253               gp2_irq_control = 1;
252               state->gp2_irq_control = 1;
254253            default:
255254               break;
256255         }
r10427r10428
270269
271270static INTERRUPT_GEN(qdrmfgp_interrupt)
272271{
272   qdrmfgp_state *state = device->machine->driver_data<qdrmfgp_state>();
273273   switch (cpu_getiloops(device))
274274   {
275275      case 0:
276         if (control & 0x0001)
276         if (state->control & 0x0001)
277277            cpu_set_input_line(device, 1, HOLD_LINE);
278278         break;
279279
280280      case 1:
281281         /* trigger V-blank interrupt */
282         if (control & 0x0004)
282         if (state->control & 0x0004)
283283            cpu_set_input_line(device, 3, HOLD_LINE);
284284         break;
285285   }
r10427r10428
287287
288288static void ide_interrupt(device_t *device, int state)
289289{
290   if (control & 0x0008)
290   qdrmfgp_state *drvstate = device->machine->driver_data<qdrmfgp_state>();
291   if (drvstate->control & 0x0008)
291292   {
292293      if (state != CLEAR_LINE)
293294         cputag_set_input_line(device->machine, "maincpu", 4, HOLD_LINE);
r10427r10428
300301
301302static TIMER_CALLBACK( gp2_timer_callback )
302303{
303   if (control & 0x0004)
304   qdrmfgp_state *state = machine->driver_data<qdrmfgp_state>();
305   if (state->control & 0x0004)
304306      cputag_set_input_line(machine, "maincpu", 3, HOLD_LINE);
305307}
306308
307309static INTERRUPT_GEN(qdrmfgp2_interrupt)
308310{
311   qdrmfgp_state *state = device->machine->driver_data<qdrmfgp_state>();
309312   /* trigger V-blank interrupt */
310   if (control & 0x0008)
313   if (state->control & 0x0008)
311314      cpu_set_input_line(device, 4, HOLD_LINE);
312315}
313316
314317static void gp2_ide_interrupt(device_t *device, int state)
315318{
316   if (control & 0x0010)
319   qdrmfgp_state *drvstate = device->machine->driver_data<qdrmfgp_state>();
320   if (drvstate->control & 0x0010)
317321   {
318322      if (state != CLEAR_LINE)
319323      {
320         if (gp2_irq_control)
321            gp2_irq_control = 0;
324         if (drvstate->gp2_irq_control)
325            drvstate->gp2_irq_control = 0;
322326         else
323327            cputag_set_input_line(device->machine, "maincpu", 5, HOLD_LINE);
324328      }
r10427r10428
338342
339343static ADDRESS_MAP_START( qdrmfgp_map, ADDRESS_SPACE_PROGRAM, 16 )
340344   AM_RANGE(0x000000, 0x0fffff) AM_ROM
341   AM_RANGE(0x100000, 0x10ffff) AM_RAM AM_BASE(&workram)                              /* work ram */
345   AM_RANGE(0x100000, 0x10ffff) AM_RAM AM_BASE_MEMBER(qdrmfgp_state, workram)                              /* work ram */
342346   AM_RANGE(0x180000, 0x183fff) AM_RAM AM_SHARE("nvram")   /* backup ram */
343347   AM_RANGE(0x280000, 0x280fff) AM_RAM_WRITE(paletteram16_xBBBBBGGGGGRRRRR_word_w) AM_BASE_GENERIC(paletteram)
344348   AM_RANGE(0x300000, 0x30003f) AM_DEVWRITE("k056832", k056832_word_w)                              /* video reg */
r10427r10428
361365
362366static ADDRESS_MAP_START( qdrmfgp2_map, ADDRESS_SPACE_PROGRAM, 16 )
363367   AM_RANGE(0x000000, 0x0fffff) AM_ROM
364   AM_RANGE(0x100000, 0x110fff) AM_RAM AM_BASE(&workram)                              /* work ram */
368   AM_RANGE(0x100000, 0x110fff) AM_RAM AM_BASE_MEMBER(qdrmfgp_state, workram)                              /* work ram */
365369   AM_RANGE(0x180000, 0x183fff) AM_RAM AM_SHARE("nvram")   /* backup ram */
366370   AM_RANGE(0x280000, 0x280fff) AM_RAM_WRITE(paletteram16_xBBBBBGGGGGRRRRR_word_w) AM_BASE_GENERIC(paletteram)
367371   AM_RANGE(0x300000, 0x30003f) AM_DEVWRITE("k056832", k056832_word_w)                              /* video reg */
r10427r10428
570574
571575static void sound_irq(device_t *device)
572576{
573   if (control & 0x0001)
577   qdrmfgp_state *state = device->machine->driver_data<qdrmfgp_state>();
578   if (state->control & 0x0001)
574579      cputag_set_input_line(device->machine, "maincpu", 1, HOLD_LINE);
575580}
576581
r10427r10428
608613
609614static MACHINE_START( qdrmfgp )
610615{
611   state_save_register_global(machine, control);
612   state_save_register_global(machine, qdrmfgp_pal);
613   state_save_register_global(machine, gp2_irq_control);
616   qdrmfgp_state *state = machine->driver_data<qdrmfgp_state>();
617   state_save_register_global(machine, state->control);
618   state_save_register_global(machine, state->pal);
619   state_save_register_global(machine, state->gp2_irq_control);
614620}
615621
616622static MACHINE_START( qdrmfgp2 )
r10427r10428
623629
624630static MACHINE_RESET( qdrmfgp )
625631{
626   sndram = machine->region("konami")->base() + 0x100000;
632   qdrmfgp_state *state = machine->driver_data<qdrmfgp_state>();
633   state->sndram = machine->region("konami")->base() + 0x100000;
627634
628635   /* reset the IDE controller */
629   gp2_irq_control = 0;
636   state->gp2_irq_control = 0;
630637   devtag_reset(machine, "ide");
631638}
632639
src/mame/drivers/scobra.c
r10427r10428
3939#include "includes/galaxold.h"
4040#include "sound/ay8910.h"
4141
42
43class scobra_state : public driver_device
44{
45public:
46   scobra_state(running_machine &machine, const driver_device_config_base &config)
47      : driver_device(machine, config) { }
48
49   UINT8 *soundram;
50};
51
52
4253static const gfx_layout scobra_charlayout =
4354{
4455   8,8,
r10427r10428
302313   AM_RANGE(0xfe00, 0xfe03) AM_DEVREADWRITE("ppi8255_1", ppi8255_r, ppi8255_w)
303314ADDRESS_MAP_END
304315
305static UINT8 *scobra_soundram;
306316
307317static READ8_HANDLER(scobra_soundram_r)
308318{
309   return scobra_soundram[offset & 0x03ff];
319   scobra_state *state = space->machine->driver_data<scobra_state>();
320   return state->soundram[offset & 0x03ff];
310321}
311322
312323static WRITE8_HANDLER(scobra_soundram_w)
313324{
314   scobra_soundram[offset & 0x03ff] = data;
325   scobra_state *state = space->machine->driver_data<scobra_state>();
326   state->soundram[offset & 0x03ff] = data;
315327}
316328
317329static ADDRESS_MAP_START( scobra_sound_map, ADDRESS_SPACE_PROGRAM, 8 )
318330   AM_RANGE(0x0000, 0x2fff) AM_ROM
319331   AM_RANGE(0x8000, 0x8fff) AM_READWRITE(scobra_soundram_r, scobra_soundram_w)
320   AM_RANGE(0x8000, 0x83ff) AM_WRITENOP AM_BASE(&scobra_soundram)  /* only here to initialize pointer */
332   AM_RANGE(0x8000, 0x83ff) AM_WRITENOP AM_BASE_MEMBER(scobra_state, soundram)  /* only here to initialize pointer */
321333   AM_RANGE(0x9000, 0x9fff) AM_WRITE(scramble_filter_w)
322334ADDRESS_MAP_END
323335
r10427r10428
325337static ADDRESS_MAP_START( hustlerb_sound_map, ADDRESS_SPACE_PROGRAM, 8 )
326338   AM_RANGE(0x0000, 0x2fff) AM_ROM
327339   AM_RANGE(0x6000, 0x6fff) AM_WRITE(frogger_filter_w)
328   AM_RANGE(0x8000, 0x8fff) AM_RAM_READ(scobra_soundram_r) AM_BASE(&scobra_soundram)  /* only here to initialize pointer */
340   AM_RANGE(0x8000, 0x8fff) AM_RAM_READ(scobra_soundram_r) AM_BASE_MEMBER(scobra_state, soundram)  /* only here to initialize pointer */
329341ADDRESS_MAP_END
330342
331343
r10427r10428
850862};
851863
852864
853static MACHINE_CONFIG_START( type1, driver_device )
865static MACHINE_CONFIG_START( type1, scobra_state )
854866
855867   /* basic machine hardware */
856868   MCFG_CPU_ADD("maincpu", Z80, 18432000/6)   /* 3.072 MHz */
r10427r10428
975987MACHINE_CONFIG_END
976988
977989
978static MACHINE_CONFIG_START( hustler, driver_device )
990static MACHINE_CONFIG_START( hustler, scobra_state )
979991
980992   /* basic machine hardware */
981993   MCFG_CPU_ADD("maincpu", Z80, 18432000/6)   /* 3.072 MHz */
src/mame/drivers/bmcbowl.c
r10427r10428
107107#include "sound/ay8910.h"
108108#include "sound/okim6295.h"
109109
110static UINT16 *bmcbowl_vid1;
111static UINT16 *bmcbowl_vid2;
112static UINT8 *bmc_colorram;
113110
114static UINT8 *stats_ram;
115static size_t   stats_ram_size;
116static int clr_offset=0;
117static int bmc_input=0;
111class bmcbowl_state : public driver_device
112{
113public:
114   bmcbowl_state(running_machine &machine, const driver_device_config_base &config)
115      : driver_device(machine, config) { }
118116
117   UINT16 *vid1;
118   UINT16 *vid2;
119   UINT8 *bmc_colorram;
120   UINT8 *stats_ram;
121   size_t stats_ram_size;
122   int clr_offset;
123   int bmc_input;
124};
125
126
127
128
119129#define NVRAM_HACK
120130
121131static VIDEO_START( bmcbowl )
r10427r10428
124134
125135static VIDEO_UPDATE( bmcbowl )
126136{
137   bmcbowl_state *state = screen->machine->driver_data<bmcbowl_state>();
127138/*
128139      280x230,4 bitmap layers, 8bpp,
129140        missing scroll and priorities   (maybe fixed ones)
r10427r10428
137148   {
138149      for (x=0;x<280;x+=2)
139150      {
140         pixdat = bmcbowl_vid2[0x8000+z];
151         pixdat = state->vid2[0x8000+z];
141152
142153         if(pixdat&0xff)
143154            *BITMAP_ADDR16(bitmap, y, x+1) = (pixdat&0xff);
144155         if(pixdat>>8)
145156            *BITMAP_ADDR16(bitmap, y, x) = (pixdat>>8);
146157
147         pixdat = bmcbowl_vid2[z];
158         pixdat = state->vid2[z];
148159
149160         if(pixdat&0xff)
150161            *BITMAP_ADDR16(bitmap, y, x+1) = (pixdat&0xff);
151162         if(pixdat>>8)
152163            *BITMAP_ADDR16(bitmap, y, x) = (pixdat>>8);
153164
154         pixdat = bmcbowl_vid1[0x8000+z];
165         pixdat = state->vid1[0x8000+z];
155166
156167         if(pixdat&0xff)
157168            *BITMAP_ADDR16(bitmap, y, x+1) = (pixdat&0xff);
158169         if(pixdat>>8)
159170            *BITMAP_ADDR16(bitmap, y, x) = (pixdat>>8);
160171
161         pixdat = bmcbowl_vid1[z];
172         pixdat = state->vid1[z];
162173
163174         if(pixdat&0xff)
164175            *BITMAP_ADDR16(bitmap, y, x+1) = (pixdat&0xff);
r10427r10428
195206
196207static WRITE16_HANDLER( bmc_RAMDAC_offset_w )
197208{
198   clr_offset=data*3;
209   bmcbowl_state *state = space->machine->driver_data<bmcbowl_state>();
210   state->clr_offset=data*3;
199211}
200212
201213static WRITE16_HANDLER( bmc_RAMDAC_color_w )
202214{
203   bmc_colorram[clr_offset]=data;
204   palette_set_color_rgb(space->machine,clr_offset/3,pal6bit(bmc_colorram[(clr_offset/3)*3]),pal6bit(bmc_colorram[(clr_offset/3)*3+1]),pal6bit(bmc_colorram[(clr_offset/3)*3+2]));
205   clr_offset=(clr_offset+1)%768;
215   bmcbowl_state *state = space->machine->driver_data<bmcbowl_state>();
216   state->bmc_colorram[state->clr_offset]=data;
217   palette_set_color_rgb(space->machine,state->clr_offset/3,pal6bit(state->bmc_colorram[(state->clr_offset/3)*3]),pal6bit(state->bmc_colorram[(state->clr_offset/3)*3+1]),pal6bit(state->bmc_colorram[(state->clr_offset/3)*3+2]));
218   state->clr_offset=(state->clr_offset+1)%768;
206219}
207220
208221static WRITE16_HANDLER( scroll_w )
r10427r10428
276289};
277290
278291
279static void init_stats(const UINT8 *table, int table_len, int address)
292static void init_stats(bmcbowl_state *state, const UINT8 *table, int table_len, int address)
280293{
281294   int i;
282295   for (i=0; i<table_len; i++)
283      stats_ram[address+2*i]=table[i];
296      state->stats_ram[address+2*i]=table[i];
284297}
285298#endif
286299
287300static NVRAM_HANDLER( bmcbowl )
288301{
302   bmcbowl_state *state = machine->driver_data<bmcbowl_state>();
289303   int i;
290304
291305   if (read_or_write)
292      file->write(stats_ram, stats_ram_size);
306      file->write(state->stats_ram, state->stats_ram_size);
293307   else
294308
295309#ifdef NVRAM_HACK
296   for (i = 0; i < stats_ram_size; i++)
297      stats_ram[i] = 0xff;
310   for (i = 0; i < state->stats_ram_size; i++)
311      state->stats_ram[i] = 0xff;
298312
299   init_stats(bmc_nv1,ARRAY_LENGTH(bmc_nv1),0);
300   init_stats(bmc_nv2,ARRAY_LENGTH(bmc_nv2),0x3b0);
301   init_stats(bmc_nv3,ARRAY_LENGTH(bmc_nv3),0xfe2);
313   init_stats(state,bmc_nv1,ARRAY_LENGTH(bmc_nv1),0);
314   init_stats(state,bmc_nv2,ARRAY_LENGTH(bmc_nv2),0x3b0);
315   init_stats(state,bmc_nv3,ARRAY_LENGTH(bmc_nv3),0xfe2);
302316#else
303317   if (file)
304      file->read(stats_ram, stats_ram_size);
318      file->read(state->stats_ram, state->stats_ram_size);
305319   else
306320
307      for (i = 0; i < stats_ram_size; i++)
308         stats_ram[i] = 0xff;
321      for (i = 0; i < state->stats_ram_size; i++)
322         state->stats_ram[i] = 0xff;
309323#endif
310324
311325}
r10427r10428
327341   AM_RANGE(0x092800, 0x092803) AM_DEVWRITE8("aysnd", ay8910_data_address_w, 0xff00)
328342   AM_RANGE(0x092802, 0x092803) AM_DEVREAD8("aysnd", ay8910_r, 0xff00)
329343   AM_RANGE(0x093802, 0x093803) AM_READ_PORT("IN0")
330   AM_RANGE(0x095000, 0x095fff) AM_RAM AM_BASE((UINT16 **)&stats_ram) AM_SIZE(&stats_ram_size) /* 8 bit */
344   AM_RANGE(0x095000, 0x095fff) AM_RAM AM_BASE_MEMBER(bmcbowl_state, stats_ram) AM_SIZE_MEMBER(bmcbowl_state, stats_ram_size) /* 8 bit */
331345   AM_RANGE(0x097000, 0x097001) AM_READNOP
332346   AM_RANGE(0x140000, 0x1bffff) AM_ROM
333   AM_RANGE(0x1c0000, 0x1effff) AM_RAM AM_BASE(&bmcbowl_vid1)
347   AM_RANGE(0x1c0000, 0x1effff) AM_RAM AM_BASE_MEMBER(bmcbowl_state, vid1)
334348   AM_RANGE(0x1f0000, 0x1fffff) AM_RAM
335   AM_RANGE(0x200000, 0x21ffff) AM_RAM AM_BASE(&bmcbowl_vid2)
349   AM_RANGE(0x200000, 0x21ffff) AM_RAM AM_BASE_MEMBER(bmcbowl_state, vid2)
336350
337351   AM_RANGE(0x28c000, 0x28c001) AM_DEVREADWRITE8_MODERN("oki", okim6295_device, read, write, 0xff00)
338352
r10427r10428
432446
433447static READ8_DEVICE_HANDLER(dips1_r)
434448{
435   switch(bmc_input)
449   bmcbowl_state *state = device->machine->driver_data<bmcbowl_state>();
450   switch(state->bmc_input)
436451   {
437452         case 0x00:   return  input_port_read(device->machine, "IN1");
438453         case 0x40:   return  input_port_read(device->machine, "IN2");
439454   }
440   logerror("%s:unknown input - %X\n",device->machine->describe_context(),bmc_input);
455   logerror("%s:unknown input - %X\n",device->machine->describe_context(),state->bmc_input);
441456   return 0xff;
442457}
443458
444459
445460static WRITE8_DEVICE_HANDLER(input_mux_w)
446461{
447   bmc_input=data;
462   bmcbowl_state *state = device->machine->driver_data<bmcbowl_state>();
463   state->bmc_input=data;
448464}
449465
450466
r10427r10428
480496      cpu_set_input_line(device, 2, HOLD_LINE);
481497}
482498
483static MACHINE_CONFIG_START( bmcbowl, driver_device )
499static MACHINE_CONFIG_START( bmcbowl, bmcbowl_state )
484500   MCFG_CPU_ADD("maincpu", M68000, 21477270/2 )
485501   MCFG_CPU_PROGRAM_MAP(bmcbowl_mem)
486502   MCFG_CPU_VBLANK_INT_HACK(bmc_interrupt,2)
r10427r10428
536552
537553static DRIVER_INIT(bmcbowl)
538554{
539   bmc_colorram = auto_alloc_array(machine, UINT8, 768);
555   bmcbowl_state *state = machine->driver_data<bmcbowl_state>();
556   state->bmc_colorram = auto_alloc_array(machine, UINT8, 768);
540557}
541558
542559GAME( 1994, bmcbowl,    0, bmcbowl,    bmcbowl,    bmcbowl, ROT0,  "BMC", "BMC Bowling", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
src/mame/drivers/model3.c
r10427r10428
607607#include "sound/scsp.h"
608608#include "includes/model3.h"
609609
610static UINT8 irq_enable;
611static UINT8 irq_state;
612static UINT8 scsi_irq_state;
613610
614int model3_step;
615UINT32 *model3_vrom;
616
617static UINT64 *work_ram;
618static int model3_crom_bank = 0;
619static int model3_controls_bank;
620static UINT32 real3d_device_id;
621
622611static void real3d_dma_callback(running_machine *machine, UINT32 src, UINT32 dst, int length, int byteswap);
623612
624static UINT16 *model3_soundram;
625613
626614
627615static void update_irq_state(running_machine *machine)
628616{
629   if ((irq_enable & irq_state) || scsi_irq_state)
617   model3_state *state = machine->driver_data<model3_state>();
618   if ((state->irq_enable & state->irq_state) || state->scsi_irq_state)
630619   {
631//      printf("IRQ set: state %x enable %x scsi %x\n", irq_state, irq_enable, scsi_irq_state);
620//      printf("IRQ set: state %x enable %x scsi %x\n", state->irq_state, state->irq_enable, state->scsi_irq_state);
632621      cputag_set_input_line(machine, "maincpu", PPC_IRQ, ASSERT_LINE);
633      scsi_irq_state = 0;
622      state->scsi_irq_state = 0;
634623   }
635624   else
636625   {
637//      printf("IRQ clear: state %x enable %x scsi %x\n", irq_state, irq_enable, scsi_irq_state);
626//      printf("IRQ clear: state %x enable %x scsi %x\n", state->irq_state, state->irq_enable, state->scsi_irq_state);
638627      cputag_set_input_line(machine, "maincpu", PPC_IRQ, CLEAR_LINE);
639628   }
640629}
641630
642void model3_set_irq_line(running_machine *machine, UINT8 bit, int state)
631void model3_set_irq_line(running_machine *machine, UINT8 bit, int line)
643632{
644   if (state != CLEAR_LINE)
645      irq_state |= bit;
633   model3_state *state = machine->driver_data<model3_state>();
634   if (line != CLEAR_LINE)
635      state->irq_state |= bit;
646636   else
647      irq_state &= ~bit;
637      state->irq_state &= ~bit;
648638   update_irq_state(machine);
649639}
650640
651641
652static UINT32 pci_device_get_reg(int device, int reg)
642/*****************************************************************************/
643/* Motorola MPC105 PCI Bridge/Memory Controller */
644
645
646static UINT32 pci_device_get_reg(model3_state *state)
653647{
648   int device = state->pci_device;
649   int reg = state->pci_reg;
650
654651   switch(device)
655652   {
656653      case 11:      /* ??? */
r10427r10428
665662      case 13:      /* Real3D Controller chip */
666663         switch(reg)
667664         {
668            case 0:      return real3d_device_id;   /* PCI Vendor ID & Device ID */
665            case 0:      return state->real3d_device_id;   /* PCI Vendor ID & Device ID */
669666            default:
670667               logerror("pci_device_get_reg: Real3D controller, unknown reg %02X", reg);
671668               break;
r10427r10428
699696   return 0;
700697}
701698
702static void pci_device_set_reg(int device, int reg, UINT32 value)
699static void pci_device_set_reg(model3_state *state, UINT32 value)
703700{
701   int device = state->pci_device;
702   int reg = state->pci_reg;
703
704704   switch(device)
705705   {
706706      case 11:      /* Unknown device for now !!! */
r10427r10428
769769   }
770770}
771771
772/*****************************************************************************/
773/* Motorola MPC105 PCI Bridge/Memory Controller */
774
775static UINT32 mpc105_regs[0x40];
776static UINT32 mpc105_addr;
777static int pci_bus;
778static int pci_device;
779static int pci_function;
780static int pci_reg;
781
782772static READ64_HANDLER( mpc105_addr_r )
783773{
774   model3_state *state = space->machine->driver_data<model3_state>();
784775   if (ACCESSING_BITS_32_63)
785776   {
786      return (UINT64)mpc105_addr << 32;
777      return (UINT64)state->mpc105_addr << 32;
787778   }
788779   return 0;
789780}
790781
791782static WRITE64_HANDLER( mpc105_addr_w )
792783{
784   model3_state *state = space->machine->driver_data<model3_state>();
793785   if (ACCESSING_BITS_32_63)
794786   {
795787      UINT32 d = FLIPENDIAN_INT32((UINT32)(data >> 32));
796      mpc105_addr = data >> 32;
788      state->mpc105_addr = data >> 32;
797789
798      pci_bus = (d >> 16) & 0xff;
799      pci_device = (d >> 11) & 0x1f;
800      pci_function = (d >> 8) & 0x7;
801      pci_reg = (d >> 2) & 0x3f;
790      state->pci_bus = (d >> 16) & 0xff;
791      state->pci_device = (d >> 11) & 0x1f;
792      state->pci_function = (d >> 8) & 0x7;
793      state->pci_reg = (d >> 2) & 0x3f;
802794   }
803795}
804796
805797static READ64_HANDLER( mpc105_data_r )
806798{
807   if(pci_device == 0) {
808      return ((UINT64)(FLIPENDIAN_INT32(mpc105_regs[(pci_reg/2)+1])) << 32) |
809            ((UINT64)(FLIPENDIAN_INT32(mpc105_regs[(pci_reg/2)+0])));
799   model3_state *state = space->machine->driver_data<model3_state>();
800   if(state->pci_device == 0) {
801      return ((UINT64)(FLIPENDIAN_INT32(state->mpc105_regs[(state->pci_reg/2)+1])) << 32) |
802            ((UINT64)(FLIPENDIAN_INT32(state->mpc105_regs[(state->pci_reg/2)+0])));
810803   }
811   return FLIPENDIAN_INT32(pci_device_get_reg(pci_device, pci_reg));
804   return FLIPENDIAN_INT32(pci_device_get_reg(state));
812805}
813806
814807static WRITE64_HANDLER( mpc105_data_w )
815808{
816   if(pci_device == 0) {
817      mpc105_regs[(pci_reg/2)+1] = FLIPENDIAN_INT32((UINT32)(data >> 32));
818      mpc105_regs[(pci_reg/2)+0] = FLIPENDIAN_INT32((UINT32)(data));
809   model3_state *state = space->machine->driver_data<model3_state>();
810   if(state->pci_device == 0) {
811      state->mpc105_regs[(state->pci_reg/2)+1] = FLIPENDIAN_INT32((UINT32)(data >> 32));
812      state->mpc105_regs[(state->pci_reg/2)+0] = FLIPENDIAN_INT32((UINT32)(data));
819813      return;
820814   }
821815   if (ACCESSING_BITS_0_31)
822816   {
823      pci_device_set_reg(pci_device, pci_reg, FLIPENDIAN_INT32((UINT32)data));
817      pci_device_set_reg(state, FLIPENDIAN_INT32((UINT32)data));
824818   }
825819}
826820
827821static READ64_HANDLER( mpc105_reg_r )
828822{
829   return ((UINT64)(mpc105_regs[(offset*2)+0]) << 32) |
830         (UINT64)(mpc105_regs[(offset*2)+1]);
823   model3_state *state = space->machine->driver_data<model3_state>();
824   return ((UINT64)(state->mpc105_regs[(offset*2)+0]) << 32) |
825         (UINT64)(state->mpc105_regs[(offset*2)+1]);
831826}
832827
833828static WRITE64_HANDLER( mpc105_reg_w )
834829{
835   mpc105_regs[(offset*2)+0] = (UINT32)(data >> 32);
836   mpc105_regs[(offset*2)+1] = (UINT32)data;
830   model3_state *state = space->machine->driver_data<model3_state>();
831   state->mpc105_regs[(offset*2)+0] = (UINT32)(data >> 32);
832   state->mpc105_regs[(offset*2)+1] = (UINT32)data;
837833}
838834
839static void mpc105_init(void)
835static void mpc105_init(running_machine *machine)
840836{
837   model3_state *state = machine->driver_data<model3_state>();
841838   /* set reset values */
842   memset(mpc105_regs, 0, sizeof(mpc105_regs));
843   mpc105_regs[0x00/4] = 0x00011057;      /* Vendor ID & Device ID */
844   mpc105_regs[0x04/4] = 0x00800006;      /* PCI Command & PCI Status */
845   mpc105_regs[0x08/4] = 0x00060000;      /* Class code */
846   mpc105_regs[0xa8/4] = 0x0010ff00;      /* Processor interface configuration 1 */
847   mpc105_regs[0xac/4] = 0x060c000c;      /* Processor interface configuration 2 */
848   mpc105_regs[0xb8/4] = 0x04000000;
849   mpc105_regs[0xf0/4] = 0x0000ff02;      /* Memory control configuration 1 */
850   mpc105_regs[0xf4/4] = 0x00030000;      /* Memory control configuration 2 */
851   mpc105_regs[0xfc/4] = 0x00000010;      /* Memory control configuration 4 */
839   memset(state->mpc105_regs, 0, sizeof(state->mpc105_regs));
840   state->mpc105_regs[0x00/4] = 0x00011057;      /* Vendor ID & Device ID */
841   state->mpc105_regs[0x04/4] = 0x00800006;      /* PCI Command & PCI Status */
842   state->mpc105_regs[0x08/4] = 0x00060000;      /* Class code */
843   state->mpc105_regs[0xa8/4] = 0x0010ff00;      /* Processor interface configuration 1 */
844   state->mpc105_regs[0xac/4] = 0x060c000c;      /* Processor interface configuration 2 */
845   state->mpc105_regs[0xb8/4] = 0x04000000;
846   state->mpc105_regs[0xf0/4] = 0x0000ff02;      /* Memory control configuration 1 */
847   state->mpc105_regs[0xf4/4] = 0x00030000;      /* Memory control configuration 2 */
848   state->mpc105_regs[0xfc/4] = 0x00000010;      /* Memory control configuration 4 */
852849}
853850
854851/*****************************************************************************/
855852/* Motorola MPC106 PCI Bridge/Memory Controller */
856853
857static UINT32 mpc106_regs[0x40];
858static UINT32 mpc106_addr;
859854
860855static READ64_HANDLER( mpc106_addr_r )
861856{
857   model3_state *state = space->machine->driver_data<model3_state>();
862858   if (ACCESSING_BITS_32_63)
863859   {
864      return (UINT64)mpc106_addr << 32;
860      return (UINT64)state->mpc106_addr << 32;
865861   }
866862   return 0;
867863}
868864
869865static WRITE64_HANDLER( mpc106_addr_w )
870866{
867   model3_state *state = space->machine->driver_data<model3_state>();
871868   if (ACCESSING_BITS_32_63)
872869   {
873870      UINT32 d = FLIPENDIAN_INT32((UINT32)(data >> 32));
874871
875872      if (((d >> 8) & 0xffffff) == 0x800000)
876873      {
877         mpc106_addr = d & 0xff;
874         state->mpc106_addr = d & 0xff;
878875      }
879876      else
880877      {
881         mpc106_addr = data >> 32;
878         state->mpc106_addr = data >> 32;
882879
883         pci_bus = (d >> 16) & 0xff;
884         pci_device = (d >> 11) & 0x1f;
885         pci_function = (d >> 8) & 0x7;
886         pci_reg = (d >> 2) & 0x3f;
880         state->pci_bus = (d >> 16) & 0xff;
881         state->pci_device = (d >> 11) & 0x1f;
882         state->pci_function = (d >> 8) & 0x7;
883         state->pci_reg = (d >> 2) & 0x3f;
887884      }
888885   }
889886}
890887
891888static READ64_HANDLER( mpc106_data_r )
892889{
893   if(pci_device == 0) {
894      return ((UINT64)(FLIPENDIAN_INT32(mpc106_regs[(pci_reg/2)+1])) << 32) |
895            ((UINT64)(FLIPENDIAN_INT32(mpc106_regs[(pci_reg/2)+0])));
890   model3_state *state = space->machine->driver_data<model3_state>();
891   if(state->pci_device == 0) {
892      return ((UINT64)(FLIPENDIAN_INT32(state->mpc106_regs[(state->pci_reg/2)+1])) << 32) |
893            ((UINT64)(FLIPENDIAN_INT32(state->mpc106_regs[(state->pci_reg/2)+0])));
896894   }
897895   if (ACCESSING_BITS_32_63)
898896   {
899      return (UINT64)(FLIPENDIAN_INT32(pci_device_get_reg(pci_device, pci_reg))) << 32;
897      return (UINT64)(FLIPENDIAN_INT32(pci_device_get_reg(state))) << 32;
900898   }
901899   else
902900   {
903      return (UINT64)(FLIPENDIAN_INT32(pci_device_get_reg(pci_device, pci_reg)));
901      return (UINT64)(FLIPENDIAN_INT32(pci_device_get_reg(state)));
904902   }
905903}
906904
907905static WRITE64_HANDLER( mpc106_data_w )
908906{
909   if(pci_device == 0) {
910      mpc106_regs[(pci_reg/2)+1] = FLIPENDIAN_INT32((UINT32)(data >> 32));
911      mpc106_regs[(pci_reg/2)+0] = FLIPENDIAN_INT32((UINT32)(data));
907   model3_state *state = space->machine->driver_data<model3_state>();
908   if(state->pci_device == 0) {
909      state->mpc106_regs[(state->pci_reg/2)+1] = FLIPENDIAN_INT32((UINT32)(data >> 32));
910      state->mpc106_regs[(state->pci_reg/2)+0] = FLIPENDIAN_INT32((UINT32)(data));
912911      return;
913912   }
914913   if (ACCESSING_BITS_0_31)
915914   {
916      pci_device_set_reg(pci_device, pci_reg, FLIPENDIAN_INT32((UINT32)data));
915      pci_device_set_reg(state, FLIPENDIAN_INT32((UINT32)data));
917916   }
918917}
919918
920919static READ64_HANDLER( mpc106_reg_r )
921920{
922   return ((UINT64)(mpc106_regs[(offset*2)+0]) << 32) |
923         (UINT64)(mpc106_regs[(offset*2)+1]);
921   model3_state *state = space->machine->driver_data<model3_state>();
922   return ((UINT64)(state->mpc106_regs[(offset*2)+0]) << 32) |
923         (UINT64)(state->mpc106_regs[(offset*2)+1]);
924924}
925925
926926static WRITE64_HANDLER( mpc106_reg_w )
927927{
928   mpc106_regs[(offset*2)+0] = (UINT32)(data >> 32);
929   mpc106_regs[(offset*2)+1] = (UINT32)data;
928   model3_state *state = space->machine->driver_data<model3_state>();
929   state->mpc106_regs[(offset*2)+0] = (UINT32)(data >> 32);
930   state->mpc106_regs[(offset*2)+1] = (UINT32)data;
930931}
931932
932static void mpc106_init(void)
933static void mpc106_init(running_machine *machine)
933934{
935   model3_state *state = machine->driver_data<model3_state>();
934936   /* set reset values */
935   memset(mpc106_regs, 0, sizeof(mpc106_regs));
936   mpc106_regs[0x00/4] = 0x00021057;      /* Vendor ID & Device ID */
937   mpc106_regs[0x04/4] = 0x00800006;      /* PCI Command & PCI Status */
938   mpc106_regs[0x08/4] = 0x00060000;      /* Class code */
939   mpc106_regs[0x0c/4] = 0x00000800;      /* Cache line size */
940   mpc106_regs[0x70/4] = 0x00cd0000;      /* Output driver control */
941   mpc106_regs[0xa8/4] = 0x0010ff00;      /* Processor interface configuration 1 */
942   mpc106_regs[0xac/4] = 0x060c000c;      /* Processor interface configuration 2 */
943   mpc106_regs[0xb8/4] = 0x04000000;
944   mpc106_regs[0xc0/4] = 0x00000100;      /* Error enabling 1 */
945   mpc106_regs[0xe0/4] = 0x00420fff;      /* Emulation support configuration 1 */
946   mpc106_regs[0xe8/4] = 0x00200000;      /* Emulation support configuration 2 */
947   mpc106_regs[0xf0/4] = 0x0000ff02;      /* Memory control configuration 1 */
948   mpc106_regs[0xf4/4] = 0x00030000;      /* Memory control configuration 2 */
949   mpc106_regs[0xfc/4] = 0x00000010;      /* Memory control configuration 4 */
937   memset(state->mpc106_regs, 0, sizeof(state->mpc106_regs));
938   state->mpc106_regs[0x00/4] = 0x00021057;      /* Vendor ID & Device ID */
939   state->mpc106_regs[0x04/4] = 0x00800006;      /* PCI Command & PCI Status */
940   state->mpc106_regs[0x08/4] = 0x00060000;      /* Class code */
941   state->mpc106_regs[0x0c/4] = 0x00000800;      /* Cache line size */
942   state->mpc106_regs[0x70/4] = 0x00cd0000;      /* Output driver control */
943   state->mpc106_regs[0xa8/4] = 0x0010ff00;      /* Processor interface configuration 1 */
944   state->mpc106_regs[0xac/4] = 0x060c000c;      /* Processor interface configuration 2 */
945   state->mpc106_regs[0xb8/4] = 0x04000000;
946   state->mpc106_regs[0xc0/4] = 0x00000100;      /* Error enabling 1 */
947   state->mpc106_regs[0xe0/4] = 0x00420fff;      /* Emulation support configuration 1 */
948   state->mpc106_regs[0xe8/4] = 0x00200000;      /* Emulation support configuration 2 */
949   state->mpc106_regs[0xf0/4] = 0x0000ff02;      /* Memory control configuration 1 */
950   state->mpc106_regs[0xf4/4] = 0x00030000;      /* Memory control configuration 2 */
951   state->mpc106_regs[0xfc/4] = 0x00000010;      /* Memory control configuration 4 */
950952}
951953
952954/*****************************************************************************/
r10427r10428
10221024
10231025static void scsi_irq_callback(running_machine *machine, int state)
10241026{
1025   scsi_irq_state = state;
1027   model3_state *drvstate = machine->driver_data<model3_state>();
1028   drvstate->scsi_irq_state = state;
10261029   update_irq_state(machine);
10271030}
10281031
10291032/*****************************************************************************/
10301033/* Real3D DMA */
10311034
1032static UINT32 dma_data;
1033static UINT32 dma_status;
1034static UINT32 dma_source;
1035static UINT32 dma_dest;
1036static UINT32 dma_endian;
1037static UINT32 dma_irq;
10381035
10391036static READ64_HANDLER( real3d_dma_r )
10401037{
1038   model3_state *state = space->machine->driver_data<model3_state>();
10411039   switch(offset)
10421040   {
10431041      case 1:
1044         return (dma_irq << 24) | (dma_endian << 8);
1042         return (state->dma_irq << 24) | (state->dma_endian << 8);
10451043      case 2:
10461044         if(ACCESSING_BITS_0_31) {
1047            return dma_data;
1045            return state->dma_data;
10481046         }
10491047         break;
10501048   }
r10427r10428
10541052
10551053static WRITE64_HANDLER( real3d_dma_w )
10561054{
1055   model3_state *state = space->machine->driver_data<model3_state>();
10571056   switch(offset)
10581057   {
10591058      case 0:
10601059         if(ACCESSING_BITS_32_63) {      /* DMA source address */
1061            dma_source = FLIPENDIAN_INT32((UINT32)(data >> 32));
1060            state->dma_source = FLIPENDIAN_INT32((UINT32)(data >> 32));
10621061            return;
10631062         }
10641063         if(ACCESSING_BITS_0_31) {      /* DMA destination address */
1065            dma_dest = FLIPENDIAN_INT32((UINT32)(data));
1064            state->dma_dest = FLIPENDIAN_INT32((UINT32)(data));
10661065            return;
10671066         }
10681067         break;
r10427r10428
10701069         if(ACCESSING_BITS_32_63)      /* DMA length */
10711070         {
10721071            int length = FLIPENDIAN_INT32((UINT32)(data >> 32)) * 4;
1073            if (dma_endian & 0x80)
1072            if (state->dma_endian & 0x80)
10741073            {
1075               real3d_dma_callback(space->machine, dma_source, dma_dest, length, 0);
1074               real3d_dma_callback(space->machine, state->dma_source, state->dma_dest, length, 0);
10761075            }
10771076            else
10781077            {
1079               real3d_dma_callback(space->machine, dma_source, dma_dest, length, 1);
1078               real3d_dma_callback(space->machine, state->dma_source, state->dma_dest, length, 1);
10801079            }
1081            dma_irq |= 0x01;
1080            state->dma_irq |= 0x01;
10821081            scsi_irq_callback(space->machine, 1);
10831082            return;
10841083         }
10851084         else if(ACCESSING_BITS_16_23)
10861085         {
10871086            if(data & 0x10000) {
1088               dma_irq &= ~0x1;
1087               state->dma_irq &= ~0x1;
10891088               scsi_irq_callback(space->machine, 0);
10901089            }
10911090            return;
10921091         }
10931092         else if(ACCESSING_BITS_8_15)
10941093         {
1095            dma_endian = (data >> 8) & 0xff;
1094            state->dma_endian = (data >> 8) & 0xff;
10961095            return;
10971096         }
10981097         break;
r10427r10428
11001099         if(ACCESSING_BITS_32_63) {      /* DMA command */
11011100            UINT32 cmd = FLIPENDIAN_INT32((UINT32)(data >> 32));
11021101            if(cmd & 0x20000000) {
1103               dma_data = FLIPENDIAN_INT32(real3d_device_id);   /* (PCI Vendor & Device ID) */
1102               state->dma_data = FLIPENDIAN_INT32(state->real3d_device_id);   /* (PCI Vendor & Device ID) */
11041103            }
11051104            else if(cmd & 0x80000000) {
1106               dma_status ^= 0xffffffff;
1107               dma_data = dma_status;
1105               state->dma_status ^= 0xffffffff;
1106               state->dma_data = state->dma_status;
11081107            }
11091108            return;
11101109         }
11111110         if(ACCESSING_BITS_0_31) {      /* ??? */
1112            dma_data = 0xffffffff;
1111            state->dma_data = 0xffffffff;
11131112            return;
11141113         }
11151114         return;
r10427r10428
11871186
11881187static void configure_fast_ram(running_machine *machine)
11891188{
1189   model3_state *state = machine->driver_data<model3_state>();
11901190   /* set conservative DRC options */
11911191   ppcdrc_set_options(machine->device("maincpu"), PPCDRC_COMPATIBLE_OPTIONS - PPCDRC_ACCURATE_SINGLES);
11921192
11931193   /* configure fast RAM regions for DRC */
1194   ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x007fffff, FALSE, work_ram);
1194   ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x007fffff, FALSE, state->work_ram);
11951195}
11961196
11971197static MACHINE_START(model3_10)
r10427r10428
12171217
12181218static void model3_init(running_machine *machine, int step)
12191219{
1220   model3_step = step;
1220   model3_state *state = machine->driver_data<model3_state>();
1221   state->step = step;
12211222   memory_set_bankptr(machine,  "bank1", machine->region( "user1" )->base() + 0x800000 ); /* banked CROM */
12221223
12231224   memory_set_bankptr(machine, "bank4", machine->region("samples")->base() + 0x200000);
12241225   memory_set_bankptr(machine, "bank5", machine->region("samples")->base() + 0x600000);
12251226
12261227   // copy the 68k vector table into RAM
1227   memcpy(model3_soundram, machine->region("audiocpu")->base()+0x80000, 16);
1228   memcpy(state->soundram, machine->region("audiocpu")->base()+0x80000, 16);
12281229   machine->device("audiocpu")->reset();
12291230
1230   model3_machine_init(step);   // step 1.5
1231   model3_tap_reset();
1231   model3_machine_init(machine, step);   // step 1.5
1232   model3_tap_reset(machine);
12321233
12331234   if(step < 0x20) {
12341235      if( mame_stricmp(machine->gamedrv->name, "vs215") == 0 ||
12351236         mame_stricmp(machine->gamedrv->name, "vs29815") == 0 ||
12361237         mame_stricmp(machine->gamedrv->name, "bass") == 0 )
12371238      {
1238         mpc106_init();
1239         mpc106_init(machine);
12391240      }
12401241      else
12411242      {
1242         mpc105_init();
1243         mpc105_init(machine);
12431244      }
1244      real3d_device_id = 0x16c311db;   /* PCI Vendor ID (11db = SEGA), Device ID (16c3 = 315-5827) */
1245      state->real3d_device_id = 0x16c311db;   /* PCI Vendor ID (11db = SEGA), Device ID (16c3 = 315-5827) */
12451246   }
12461247   else {
1247      mpc106_init();
1248      mpc106_init(machine);
12481249      // some step 2+ games need the older PCI ID (obvious symptom:
12491250      // vbl is enabled briefly then disabled so the game hangs)
12501251      if (mame_stricmp(machine->gamedrv->name, "magtruck") == 0 ||
12511252          mame_stricmp(machine->gamedrv->name, "von254g") == 0)
12521253      {
1253         real3d_device_id = 0x16c311db;   /* PCI Vendor ID (11db = SEGA), Device ID (16c3 = 315-5827) */
1254         state->real3d_device_id = 0x16c311db;   /* PCI Vendor ID (11db = SEGA), Device ID (16c3 = 315-5827) */
12541255      }
12551256      else
12561257      {
1257         real3d_device_id = 0x178611db;   /* PCI Vendor ID (11db = SEGA), Device ID (1786 = 315-6022) */
1258         state->real3d_device_id = 0x178611db;   /* PCI Vendor ID (11db = SEGA), Device ID (1786 = 315-6022) */
12581259      }
12591260   }
12601261}
r10427r10428
12641265static MACHINE_RESET(model3_20) { model3_init(machine, 0x20); }
12651266static MACHINE_RESET(model3_21) { model3_init(machine, 0x21); }
12661267
1267static UINT64 controls_2;
1268static UINT64 controls_3;
1269static UINT8 model3_serial_fifo1;
1270static UINT8 model3_serial_fifo2;
1271static int lightgun_reg_sel;
1272static int adc_channel;
12731268
12741269static READ64_HANDLER( model3_ctrl_r )
12751270{
1271   model3_state *state = space->machine->driver_data<model3_state>();
12761272   switch( offset )
12771273   {
12781274      case 0:
12791275         if (ACCESSING_BITS_56_63)
12801276         {
1281            return (UINT64)model3_controls_bank << 56;
1277            return (UINT64)state->controls_bank << 56;
12821278         }
12831279         else if (ACCESSING_BITS_24_31)
12841280         {
1285            if(model3_controls_bank & 0x1)
1281            if(state->controls_bank & 0x1)
12861282            {
12871283               return (input_port_read(space->machine, "IN1")) << 24;
12881284            }
r10427r10428
13161312      case 5:
13171313         if (ACCESSING_BITS_24_31)               /* Serial comm RX FIFO 1 */
13181314         {
1319            return (UINT64)model3_serial_fifo1 << 24;
1315            return (UINT64)state->serial_fifo1 << 24;
13201316         }
13211317         break;
13221318
13231319      case 6:
13241320         if (ACCESSING_BITS_56_63)      /* Serial comm RX FIFO 2 */
13251321         {
1326            return (UINT64)model3_serial_fifo2 << 56;
1322            return (UINT64)state->serial_fifo2 << 56;
13271323         }
13281324         else if (ACCESSING_BITS_24_31)            /* Serial comm full/empty flags */
13291325         {
r10427r10428
13351331         if (ACCESSING_BITS_24_31)      /* ADC Data read */
13361332         {
13371333            static const char *const adcnames[] = { "AN0", "AN1", "AN2", "AN3", "AN4", "AN5", "AN6", "AN7" };
1338            UINT8 adc_data = input_port_read_safe(space->machine, adcnames[adc_channel], 0);
1339            adc_channel++;
1340            adc_channel &= 0x7;
1334            UINT8 adc_data = input_port_read_safe(space->machine, adcnames[state->adc_channel], 0);
1335            state->adc_channel++;
1336            state->adc_channel &= 0x7;
13411337            return (UINT64)adc_data << 24;
13421338         }
13431339         break;
r10427r10428
13491345
13501346static WRITE64_HANDLER( model3_ctrl_w )
13511347{
1348   model3_state *state = space->machine->driver_data<model3_state>();
13521349   switch(offset)
13531350   {
13541351      case 0:
r10427r10428
13591356            eeprom_write_bit(device, (reg & 0x20) ? 1 : 0);
13601357            eeprom_set_clock_line(device, (reg & 0x80) ? ASSERT_LINE : CLEAR_LINE);
13611358            eeprom_set_cs_line(device, (reg & 0x40) ? CLEAR_LINE : ASSERT_LINE);
1362            model3_controls_bank = reg & 0xff;
1359            state->controls_bank = reg & 0xff;
13631360         }
13641361         return;
13651362
13661363      case 2:
1367         COMBINE_DATA(&controls_2);
1364         COMBINE_DATA(&state->controls_2);
13681365         return;
13691366
13701367      case 3:
1371         COMBINE_DATA(&controls_3);
1368         COMBINE_DATA(&state->controls_3);
13721369         return;
13731370
13741371      case 4:
r10427r10428
13811378            switch(data >> 24)
13821379            {
13831380               case 0x00:
1384                  lightgun_reg_sel = model3_serial_fifo2;
1381                  state->lightgun_reg_sel = state->serial_fifo2;
13851382                  break;
13861383               case 0x87:
1387                  model3_serial_fifo1 = 0;
1388                  switch(lightgun_reg_sel)      /* read lightrun register */
1384                  state->serial_fifo1 = 0;
1385                  switch(state->lightgun_reg_sel)      /* read lightrun register */
13891386                  {
13901387                     case 0:      /* player 1 gun X-position, lower 8-bits */
1391                        model3_serial_fifo2 = input_port_read(space->machine, "LIGHT0_Y") & 0xff;
1388                        state->serial_fifo2 = input_port_read(space->machine, "LIGHT0_Y") & 0xff;
13921389                        break;
13931390                     case 1:      /* player 1 gun X-position, upper 2-bits */
1394                        model3_serial_fifo2 = (input_port_read(space->machine, "LIGHT0_Y") >> 8) & 0x3;
1391                        state->serial_fifo2 = (input_port_read(space->machine, "LIGHT0_Y") >> 8) & 0x3;
13951392                        break;
13961393                     case 2:      /* player 1 gun Y-position, lower 8-bits */
1397                        model3_serial_fifo2 = input_port_read(space->machine, "LIGHT0_X") & 0xff;
1394                        state->serial_fifo2 = input_port_read(space->machine, "LIGHT0_X") & 0xff;
13981395                        break;
13991396                     case 3:      /* player 1 gun Y-position, upper 2-bits */
1400                        model3_serial_fifo2 = (input_port_read(space->machine, "LIGHT0_X") >> 8) & 0x3;
1397                        state->serial_fifo2 = (input_port_read(space->machine, "LIGHT0_X") >> 8) & 0x3;
14011398                        break;
14021399                     case 4:      /* player 2 gun X-position, lower 8-bits */
1403                        model3_serial_fifo2 = input_port_read(space->machine, "LIGHT1_Y") & 0xff;
1400                        state->serial_fifo2 = input_port_read(space->machine, "LIGHT1_Y") & 0xff;
14041401                        break;
14051402                     case 5:      /* player 2 gun X-position, upper 2-bits */
1406                        model3_serial_fifo2 = (input_port_read(space->machine, "LIGHT1_Y") >> 8) & 0x3;
1403                        state->serial_fifo2 = (input_port_read(space->machine, "LIGHT1_Y") >> 8) & 0x3;
14071404                        break;
14081405                     case 6:      /* player 2 gun Y-position, lower 8-bits */
1409                        model3_serial_fifo2 = input_port_read(space->machine, "LIGHT1_X") & 0xff;
1406                        state->serial_fifo2 = input_port_read(space->machine, "LIGHT1_X") & 0xff;
14101407                        break;
14111408                     case 7:      /* player 2 gun Y-position, upper 2-bits */
1412                        model3_serial_fifo2 = (input_port_read(space->machine, "LIGHT1_X") >> 8) & 0x3;
1409                        state->serial_fifo2 = (input_port_read(space->machine, "LIGHT1_X") >> 8) & 0x3;
14131410                        break;
14141411                     case 8:      /* gun offscreen (bit set = gun offscreen, bit clear = gun on screen) */
1415                        model3_serial_fifo2 = 0;   /* bit 0 = player 1, bit 1 = player 2 */
1412                        state->serial_fifo2 = 0;   /* bit 0 = player 1, bit 1 = player 2 */
14161413                        if(input_port_read(space->machine, "OFFSCREEN") & 0x1) {
1417                           model3_serial_fifo2 |= 0x01;
1414                           state->serial_fifo2 |= 0x01;
14181415                        }
14191416                        break;
14201417                  }
r10427r10428
14291426      case 5:
14301427         if (ACCESSING_BITS_56_63)   /* Serial comm TX FIFO 2 */
14311428         {
1432            model3_serial_fifo2 = data >> 56;
1429            state->serial_fifo2 = data >> 56;
14331430            return;
14341431         }
14351432         break;
r10427r10428
14371434      case 7:
14381435         if (ACCESSING_BITS_24_31)   /* ADC Channel selection */
14391436         {
1440            adc_channel = (data >> 24) & 0xf;
1437            state->adc_channel = (data >> 24) & 0xf;
14411438         }
14421439         return;
14431440   }
r10427r10428
14471444
14481445static READ64_HANDLER( model3_sys_r )
14491446{
1447   model3_state *state = space->machine->driver_data<model3_state>();
14501448//  printf("model3_sys_r: mask %llx @ %x (PC %x)\n", mem_mask, offset, cpu_get_pc(space->cpu));
14511449
14521450   switch (offset)
r10427r10428
14541452      case 0x08/8:
14551453         if (ACCESSING_BITS_56_63)
14561454         {
1457            return ((UINT64)model3_crom_bank << 56);
1455            return ((UINT64)state->crom_bank << 56);
14581456         }
14591457         break;
14601458
14611459      case 0x10/8:
14621460         if (ACCESSING_BITS_56_63)
14631461         {
1464            UINT64 res = model3_tap_read();
1462            UINT64 res = model3_tap_read(space->machine);
14651463
14661464            return res<<61;
14671465         }
14681466         else if (ACCESSING_BITS_24_31)
14691467         {
1470            return (irq_enable<<24);
1468            return (state->irq_enable<<24);
14711469         }
14721470         else logerror("m3_sys: Unk sys_r @ 0x10: mask = %x\n", (UINT32)mem_mask);
14731471         break;
14741472      case 0x18/8:
1475//          printf("read irq_state %x (PC %x)\n", irq_state, cpu_get_pc(space->cpu));
1476         return (UINT64)irq_state<<56 | 0xff000000;
1473//          printf("read state->irq_state %x (PC %x)\n", state->irq_state, cpu_get_pc(space->cpu));
1474         return (UINT64)state->irq_state<<56 | 0xff000000;
14771475         break;
14781476   }
14791477
r10427r10428
14831481
14841482static WRITE64_HANDLER( model3_sys_w )
14851483{
1484   model3_state *state = space->machine->driver_data<model3_state>();
14861485//  printf("model3_sys_w: %llx to %x mask %llx\n", data, offset, mem_mask);
14871486
14881487   switch (offset)
r10427r10428
14901489      case 0x10/8:
14911490         if (ACCESSING_BITS_24_31)
14921491         {
1493            irq_enable = (data>>24)&0xff;
1492            state->irq_enable = (data>>24)&0xff;
14941493         }
14951494         else logerror("m3_sys: unknown mask on IRQen write\n");
14961495         break;
14971496      case 0x18/8:
14981497         if ((mem_mask & 0xff000000) == 0xff000000)   // int ACK with bits in REVERSE ORDER from the other registers (Seeeee-gaaaa!)
14991498         {                  // may also be a secondary enable based on behavior of e.g. magtruck VBL handler
1500//              UINT32 old_irq = irq_state;
1499//              UINT32 old_irq = state->irq_state;
15011500            UINT8 ack = (data>>24)&0xff, realack;
15021501            int i;
15031502
r10427r10428
15191518
15201519//                      printf("%x to ack (realack %x)\n", ack, realack);
15211520
1522                  irq_state &= realack;
1521                  state->irq_state &= realack;
15231522                  break;
15241523            }
15251524         }
r10427r10428
15311530      case 0x08/8:
15321531         if (ACCESSING_BITS_56_63)
15331532         {
1534            model3_crom_bank = data >> 56;
1533            state->crom_bank = data >> 56;
15351534
15361535            data >>= 56;
15371536            data = (~data) & 0x7;
r10427r10428
15411540         if (ACCESSING_BITS_24_31)
15421541         {
15431542            data >>= 24;
1544            model3_tap_write(
1543            model3_tap_write(space->machine,
15451544               (data >> 6) & 1,// TCK
15461545               (data >> 2) & 1,// TMS
15471546               (data >> 5) & 1,// TDI
r10427r10428
15741573   }
15751574}
15761575
1577static UINT64 real3d_status = 0;
15781576static READ64_HANDLER(real3d_status_r)
15791577{
1580   real3d_status ^= U64(0xffffffffffffffff);
1578   model3_state *state = space->machine->driver_data<model3_state>();
1579   state->real3d_status ^= U64(0xffffffffffffffff);
15811580   if (offset == 0)
15821581   {
15831582      /* pretty sure this is VBLANK */
1584      real3d_status &= ~U64(0x0000000200000000);
1583      state->real3d_status &= ~U64(0x0000000200000000);
15851584      if (space->machine->primary_screen->vblank())
1586         real3d_status |= U64(0x0000000200000000);
1587      return real3d_status;
1585         state->real3d_status |= U64(0x0000000200000000);
1586      return state->real3d_status;
15881587   }
1589   return real3d_status;
1588   return state->real3d_status;
15901589}
15911590
15921591/* SCSP interface */
r10427r10428
16141613
16151614
16161615
1617static UINT64 network_ram[0x10000];
16181616static READ64_HANDLER(network_r)
16191617{
1618   model3_state *state = space->machine->driver_data<model3_state>();
16201619   mame_printf_debug("network_r: %02X at %08X\n", offset, cpu_get_pc(space->cpu));
1621   return network_ram[offset];
1620   return state->network_ram[offset];
16221621}
16231622
16241623static WRITE64_HANDLER(network_w)
16251624{
1626   COMBINE_DATA(network_ram + offset);
1625   model3_state *state = space->machine->driver_data<model3_state>();
1626   COMBINE_DATA(state->network_ram + offset);
16271627   mame_printf_debug("network_w: %02X, %08X%08X at %08X\n", offset, (UINT32)(data >> 32), (UINT32)(data), cpu_get_pc(space->cpu));
16281628}
16291629
1630static int prot_data_ptr = 0;
16311630
16321631static const UINT16 vs299_prot_data[] =
16331632{
r10427r10428
17011700
17021701static READ64_HANDLER(model3_security_r)
17031702{
1703   model3_state *state = space->machine->driver_data<model3_state>();
17041704   switch(offset)
17051705   {
17061706      case 0x00/8:   return 0;      /* status */
r10427r10428
17091709         if (mame_stricmp(space->machine->gamedrv->name, "vs299") == 0 ||
17101710            mame_stricmp(space->machine->gamedrv->name, "vs2v991") == 0)
17111711         {
1712            return (UINT64)vs299_prot_data[prot_data_ptr++] << 48;
1712            return (UINT64)vs299_prot_data[state->prot_data_ptr++] << 48;
17131713         }
17141714         else if (mame_stricmp(space->machine->gamedrv->name, "swtrilgy") == 0 ||
17151715                mame_stricmp(space->machine->gamedrv->name, "swtrilgya") == 0)
17161716         {
1717            UINT64 data = (UINT64)swt_prot_data[prot_data_ptr++] << 16;
1718            if (prot_data_ptr > 0x38)
1717            UINT64 data = (UINT64)swt_prot_data[state->prot_data_ptr++] << 16;
1718            if (state->prot_data_ptr > 0x38)
17191719            {
1720               prot_data_ptr = 0;
1720               state->prot_data_ptr = 0;
17211721            }
17221722            return data;
17231723         }
17241724         else if (mame_stricmp(space->machine->gamedrv->name, "fvipers2") == 0)
17251725         {
1726            UINT64 data = (UINT64)fvipers2_prot_data[prot_data_ptr++] << 16;
1727            if (prot_data_ptr >= 0x41)
1726            UINT64 data = (UINT64)fvipers2_prot_data[state->prot_data_ptr++] << 16;
1727            if (state->prot_data_ptr >= 0x41)
17281728            {
1729               prot_data_ptr = 0;
1729               state->prot_data_ptr = 0;
17301730            }
17311731            return data;
17321732         }
17331733         else if (mame_stricmp(space->machine->gamedrv->name, "spikeout") == 0 ||
17341734                mame_stricmp(space->machine->gamedrv->name, "spikeofe") == 0)
17351735         {
1736            UINT64 data = (UINT64)spikeout_prot_data[prot_data_ptr++] << 16;
1737            if (prot_data_ptr >= 0x55)
1736            UINT64 data = (UINT64)spikeout_prot_data[state->prot_data_ptr++] << 16;
1737            if (state->prot_data_ptr >= 0x55)
17381738            {
1739               prot_data_ptr = 0;
1739               state->prot_data_ptr = 0;
17401740            }
17411741            return data;
17421742         }
17431743         else if (mame_stricmp(space->machine->gamedrv->name, "eca") == 0 ||
17441744                mame_stricmp(space->machine->gamedrv->name, "ecax") == 0)
17451745         {
1746            UINT64 data = (UINT64)eca_prot_data[prot_data_ptr++] << 16;
1747            if (prot_data_ptr >= 0x31)
1746            UINT64 data = (UINT64)eca_prot_data[state->prot_data_ptr++] << 16;
1747            if (state->prot_data_ptr >= 0x31)
17481748            {
1749               prot_data_ptr = 0;
1749               state->prot_data_ptr = 0;
17501750            }
17511751            return data;
17521752         }
r10427r10428
17711771}
17721772
17731773static ADDRESS_MAP_START( model3_mem, ADDRESS_SPACE_PROGRAM, 64)
1774   AM_RANGE(0x00000000, 0x007fffff) AM_RAM   AM_BASE(&work_ram)   /* work RAM */
1774   AM_RANGE(0x00000000, 0x007fffff) AM_RAM   AM_BASE_MEMBER(model3_state, work_ram)   /* work RAM */
17751775
17761776   AM_RANGE(0x84000000, 0x8400003f) AM_READ( real3d_status_r )
17771777   AM_RANGE(0x88000000, 0x88000007) AM_WRITE( real3d_cmd_w )
r10427r10428
17881788
17891789   AM_RANGE(0xf1000000, 0xf10f7fff) AM_READWRITE( model3_char_r, model3_char_w )   /* character RAM */
17901790   AM_RANGE(0xf10f8000, 0xf10fffff) AM_READWRITE( model3_tile_r, model3_tile_w )   /* tilemaps */
1791   AM_RANGE(0xf1100000, 0xf111ffff) AM_READWRITE( model3_palette_r, model3_palette_w ) AM_BASE(&paletteram64) /* palette */
1791   AM_RANGE(0xf1100000, 0xf111ffff) AM_READWRITE( model3_palette_r, model3_palette_w ) AM_BASE_MEMBER(model3_state, paletteram64) /* palette */
17921792   AM_RANGE(0xf1180000, 0xf11800ff) AM_READWRITE( model3_vid_reg_r, model3_vid_reg_w )
17931793
17941794   AM_RANGE(0xff800000, 0xffffffff) AM_ROM AM_REGION("user1", 0)
r10427r10428
48914891}
48924892
48934893static ADDRESS_MAP_START( model3_snd, ADDRESS_SPACE_PROGRAM, 16 )
4894   AM_RANGE(0x000000, 0x07ffff) AM_RAM AM_REGION("scsp1", 0) AM_BASE(&model3_soundram)
4894   AM_RANGE(0x000000, 0x07ffff) AM_RAM AM_REGION("scsp1", 0) AM_BASE_MEMBER(model3_state, soundram)
48954895   AM_RANGE(0x100000, 0x100fff) AM_DEVREADWRITE("scsp1", scsp_r, scsp_w)
48964896   AM_RANGE(0x200000, 0x27ffff) AM_RAM AM_REGION("scsp2", 0)
48974897   AM_RANGE(0x300000, 0x300fff) AM_DEVREADWRITE("scsp2", scsp_r, scsp_w)
r10427r10428
49024902   AM_RANGE(0xe00000, 0xffffff) AM_ROMBANK("bank5")
49034903ADDRESS_MAP_END
49044904
4905static int scsp_last_line = 0;
49064905
49074906static void scsp_irq(device_t *device, int irq)
49084907{
4908   model3_state *state = device->machine->driver_data<model3_state>();
49094909   if (irq > 0)
49104910   {
4911      scsp_last_line = irq;
4911      state->scsp_last_line = irq;
49124912      cputag_set_input_line(device->machine, "audiocpu", irq, ASSERT_LINE);
49134913   }
49144914   else
r10427r10428
49384938    0x02: Video (VBLANK start?)
49394939    0x01: Video (unused?)
49404940*/
4941static int model3_vblank = 0;
49424941static INTERRUPT_GEN(model3_interrupt)
49434942{
4944   if (model3_vblank == 0) {
4943   model3_state *state = device->machine->driver_data<model3_state>();
4944   if (state->vblank == 0) {
49454945      model3_set_irq_line(device->machine, 0x02, ASSERT_LINE);
49464946   } else {
49474947      model3_set_irq_line(device->machine, 0x0d, ASSERT_LINE);
49484948   }
49494949
4950   model3_vblank++;
4951   model3_vblank &= 1;
4950   state->vblank++;
4951   state->vblank &= 1;
49524952}
49534953
49544954static const powerpc_config model3_10 =
r10427r10428
49694969   66000000      /* Multiplier 2.5, Bus = 66MHz, Core = 166MHz */
49704970};
49714971
4972static MACHINE_CONFIG_START( model3_10, driver_device )
4972static MACHINE_CONFIG_START( model3_10, model3_state )
49734973   MCFG_CPU_ADD("maincpu", PPC603E, 66000000)
49744974   MCFG_CPU_CONFIG(model3_10)
49754975   MCFG_CPU_PROGRAM_MAP(model3_mem)
r10427r10428
50115011   MCFG_SOUND_ROUTE(0, "rspeaker", 2.0)
50125012MACHINE_CONFIG_END
50135013
5014static MACHINE_CONFIG_START( model3_15, driver_device )
5014static MACHINE_CONFIG_START( model3_15, model3_state )
50155015   MCFG_CPU_ADD("maincpu", PPC603E, 100000000)
50165016   MCFG_CPU_CONFIG(model3_15)
50175017   MCFG_CPU_PROGRAM_MAP(model3_mem)
r10427r10428
50515051   MCFG_SOUND_ROUTE(0, "rspeaker", 2.0)
50525052MACHINE_CONFIG_END
50535053
5054static MACHINE_CONFIG_START( model3_20, driver_device )
5054static MACHINE_CONFIG_START( model3_20, model3_state )
50555055   MCFG_CPU_ADD("maincpu", PPC603R, 166000000)
50565056   MCFG_CPU_CONFIG(model3_2x)
50575057   MCFG_CPU_PROGRAM_MAP(model3_mem)
r10427r10428
50915091   MCFG_SOUND_ROUTE(0, "rspeaker", 2.0)
50925092MACHINE_CONFIG_END
50935093
5094static MACHINE_CONFIG_START( model3_21, driver_device )
5094static MACHINE_CONFIG_START( model3_21, model3_state )
50955095   MCFG_CPU_ADD("maincpu", PPC603R, 166000000)
50965096   MCFG_CPU_CONFIG(model3_2x)
50975097   MCFG_CPU_PROGRAM_MAP(model3_mem)
r10427r10428
51345134
51355135static void interleave_vroms(running_machine *machine)
51365136{
5137   model3_state *state = machine->driver_data<model3_state>();
51375138   int start;
51385139   int i,j,x;
51395140   UINT16 *vrom1 = (UINT16*)machine->region("user3")->base();
r10427r10428
51415142   int vrom_length = machine->region("user3")->bytes();
51425143   UINT16 *vrom;
51435144
5144   model3_vrom = auto_alloc_array(machine, UINT32, 0x4000000/4);
5145   vrom = (UINT16 *)model3_vrom;
5145   state->vrom = auto_alloc_array(machine, UINT32, 0x4000000/4);
5146   vrom = (UINT16 *)state->vrom;
51465147
51475148   if( vrom_length <= 0x1000000 ) {
51485149      start = 0x1000000;
r10427r10428
53975398
53985399static DRIVER_INIT( harley )
53995400{
5401   model3_state *state = machine->driver_data<model3_state>();
54005402   UINT32 *rom = (UINT32*)machine->region("user1")->base();
54015403   DRIVER_INIT_CALL(model3_20);
54025404
5405   state->network_ram = auto_alloc_array_clear(machine, UINT64, 0x10000);
54035406   memory_install_readwrite64_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc0000000, 0xc00fffff, 0, 0, network_r, network_w );
54045407
54055408   rom[(0x50e8d4^4)/4] = 0x60000000;
src/mame/drivers/cps3.c
r10427r10428
337337
338338#define DMA_XOR(a)      ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(1,2))
339339
340
341static fujitsu_29f016a_device *simm[7][8];
342
343static UINT32* decrypted_bios;
344
345static UINT32* decrypted_gamerom;
346static UINT32 cram_gfxflash_bank;
347static UINT32* cps3_nops;
348
349static UINT32* tilemap20_regs_base;
350static UINT32* tilemap30_regs_base;
351static UINT32* tilemap40_regs_base;
352static UINT32* tilemap50_regs_base;
353
354static UINT32* cps3_0xc0000000_ram;
355static UINT32* cps3_0xc0000000_ram_decrypted;
356
357static UINT32* cps3_char_ram;
358
359static UINT32* cps3_spriteram;
360static UINT32* cps3_eeprom;
361static UINT32* cps3_fullscreenzoom;
362
363static UINT32 cps3_ss_pal_base = 0;
364static UINT32* cps3_colourram;
365static UINT32 cps3_unk_vidregs[0x20/4];
366static UINT32 cps3_ss_bank_base = 0;
367
368static UINT32 cps3_screenwidth;
369//cdrom_file* cps3_cd;
370
371static UINT32* cps3_mame_colours;//[0x20000]; // actual values to write to 32-bit bitmap
372
373static bitmap_t *renderbuffer_bitmap;
374static rectangle renderbuffer_clip;
375
376static UINT8* cps3_user4region;
377UINT8* cps3_user5region;
378340#define USER4REGION_LENGTH 0x800000*2
379341#define USER5REGION_LENGTH 0x800000*10
380342
r10427r10428
390352      int transparency,int transparent_color,
391353      int scalex, int scaley,bitmap_t *pri_buffer,UINT32 pri_mask)
392354{
355   cps3_state *state = gfx->machine->driver_data<cps3_state>();
393356   rectangle myclip;
394357
395358//  UINT8 al;
r10427r10428
436399      {
437400//          const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)];
438401         UINT32 palbase = (gfx->color_granularity * color) & 0x1ffff;
439         const pen_t *pal = &cps3_mame_colours[palbase];
402         const pen_t *pal = &state->mame_colours[palbase];
440403         const UINT8 *source_base = gfx_element_get_data(gfx, code % gfx->total_elements);
441404
442405         int sprite_screen_height = (scaley*gfx->height+0x8000)>>16;
r10427r10428
616579
617580/* Encryption */
618581
619static UINT32 cps3_key1, cps3_key2;
620static int cps3_altEncryption; // sfiii2 has different encryption, data isn't encrypted outside of the bios
621582
622583static UINT16 rotate_left(UINT16 value, int n)
623584{
r10427r10428
657618
658619static void cps3_decrypt_bios(running_machine *machine)
659620{
621   cps3_state *state = machine->driver_data<cps3_state>();
660622   int i;
661623   UINT32 *coderegion = (UINT32*)machine->region("user1")->base();
662624
663   decrypted_bios = (UINT32*)machine->region("user1")->base();
625   state->decrypted_bios = (UINT32*)machine->region("user1")->base();
664626
665627   for (i=0;i<0x80000;i+=4)
666628   {
667629      UINT32 dword = coderegion[i/4];
668      UINT32 xormask = cps3_mask(i, cps3_key1, cps3_key2);
669      decrypted_bios[i/4] = dword ^ xormask;
630      UINT32 xormask = cps3_mask(i, state->key1, state->key2);
631      state->decrypted_bios[i/4] = dword ^ xormask;
670632   }
671633#if 0
672634   /* Dump to file */
r10427r10428
679641      fp=fopen(filename, "w+b");
680642      if (fp)
681643      {
682         fwrite(decrypted_bios, 0x080000, 1, fp);
644         fwrite(state->decrypted_bios, 0x080000, 1, fp);
683645         fclose(fp);
684646      }
685647   }
r10427r10428
687649}
688650
689651
690static DRIVER_INIT( cps3 )
652static void init_common(running_machine *machine, UINT32 key1, UINT32 key2, int altEncryption)
691653{
654   cps3_state *state = machine->driver_data<cps3_state>();
655
656   state->key1 = key1;
657   state->key2 = key2;
658   state->altEncryption = altEncryption;
659
692660   // cache pointers to regions
693   cps3_user4region = machine->region("user4")->base();
694   cps3_user5region = machine->region("user5")->base();
661   state->user4region = machine->region("user4")->base();
662   state->user5region = machine->region("user5")->base();
695663
696   if (!cps3_user4region) cps3_user4region = auto_alloc_array(machine, UINT8, USER4REGION_LENGTH);
697   if (!cps3_user5region) cps3_user5region = auto_alloc_array(machine, UINT8, USER5REGION_LENGTH);
664   if (!state->user4region) state->user4region = auto_alloc_array(machine, UINT8, USER4REGION_LENGTH);
665   if (!state->user5region) state->user5region = auto_alloc_array(machine, UINT8, USER5REGION_LENGTH);
698666
699667   // set strict verify
700668   sh2drc_set_options(machine->device("maincpu"), SH2DRC_STRICT_VERIFY);
701669
702670   cps3_decrypt_bios(machine);
703   decrypted_gamerom = auto_alloc_array(machine, UINT32, 0x1000000/4);
671   state->decrypted_gamerom = auto_alloc_array(machine, UINT32, 0x1000000/4);
704672
705673   /* just some NOPs for the game to execute if it crashes and starts executing unmapped addresses
706674     - this prevents MAME from crashing */
707   cps3_nops = auto_alloc(machine, UINT32);
708   cps3_nops[0] = 0x00090009;
675   state->nops = auto_alloc(machine, UINT32);
676   state->nops[0] = 0x00090009;
709677
710678
711   cps3_0xc0000000_ram_decrypted = auto_alloc_array(machine, UINT32, 0x400/4);
679   state->_0xc0000000_ram_decrypted = auto_alloc_array(machine, UINT32, 0x400/4);
712680
713681   address_space *main = machine->device<sh2_device>("maincpu")->space(AS_PROGRAM);
714682   main->set_direct_update_handler(direct_update_delegate_create_static(cps3_direct_handler, *machine));
r10427r10428
717685   astring tempstr;
718686   for (int simmnum = 0; simmnum < 7; simmnum++)
719687      for (int chipnum = 0; chipnum < 8; chipnum++)
720         simm[simmnum][chipnum] = machine->device<fujitsu_29f016a_device>(tempstr.format("simm%d.%d", simmnum + 1, chipnum));
688         state->simm[simmnum][chipnum] = machine->device<fujitsu_29f016a_device>(tempstr.format("simm%d.%d", simmnum + 1, chipnum));
721689
722   cps3_eeprom = auto_alloc_array(machine, UINT32, 0x400/4);
723   machine->device<nvram_device>("eeprom")->set_base(cps3_eeprom, 0x400);
690   state->eeprom = auto_alloc_array(machine, UINT32, 0x400/4);
691   machine->device<nvram_device>("eeprom")->set_base(state->eeprom, 0x400);
724692}
725693
726static DRIVER_INIT( jojo )    { cps3_key1 = 0x02203ee3; cps3_key2 = 0x01301972; cps3_altEncryption = 0; DRIVER_INIT_CALL(cps3); }
727static DRIVER_INIT( jojoba )  { cps3_key1 = 0x23323ee3; cps3_key2 = 0x03021972; cps3_altEncryption = 0; DRIVER_INIT_CALL(cps3); }
728static DRIVER_INIT( sfiii )   { cps3_key1 = 0xb5fe053e; cps3_key2 = 0xfc03925a; cps3_altEncryption = 0; DRIVER_INIT_CALL(cps3); }
729static DRIVER_INIT( sfiii2 )  { cps3_key1 = 0x00000000; cps3_key2 = 0x00000000; cps3_altEncryption = 1; DRIVER_INIT_CALL(cps3); }
730static DRIVER_INIT( sfiii3 )  { cps3_key1 = 0xa55432b4; cps3_key2 = 0x0c129981; cps3_altEncryption = 0; DRIVER_INIT_CALL(cps3); }
731static DRIVER_INIT( redearth ){ cps3_key1 = 0x9e300ab1; cps3_key2 = 0xa175b82c; cps3_altEncryption = 0; DRIVER_INIT_CALL(cps3); }
694static DRIVER_INIT( jojo )    { init_common(machine, 0x02203ee3, 0x01301972, 0); }
695static DRIVER_INIT( jojoba )  { init_common(machine, 0x23323ee3, 0x03021972, 0); }
696static DRIVER_INIT( sfiii )   { init_common(machine, 0xb5fe053e, 0xfc03925a, 0); }
697static DRIVER_INIT( sfiii2 )  { init_common(machine, 0x00000000, 0x00000000, 1); }
698static DRIVER_INIT( sfiii3 )  { init_common(machine, 0xa55432b4, 0x0c129981, 0); }
699static DRIVER_INIT( redearth ){ init_common(machine, 0x9e300ab1, 0xa175b82c, 0); }
732700
733701
734702/* GFX decodes */
r10427r10428
760728   64*8
761729};
762730
763static UINT32* cps3_ss_ram;
764731
765static void cps3_set_mame_colours(running_machine *machine, int colournum, UINT16 data, UINT32 fadeval )
732static void cps3_set_mame_colours(running_machine *machine, int colournum, UINT16 data, UINT32 fadeval)
766733{
734   cps3_state *state = machine->driver_data<cps3_state>();
767735   int r,g,b;
768   UINT16* dst = (UINT16*)cps3_colourram;
736   UINT16* dst = (UINT16*)state->colourram;
769737
770738
771739   r = (data >> 0) & 0x1f;
r10427r10428
795763
796764   dst[colournum] = data;
797765
798   cps3_mame_colours[colournum] = (r << (16+3)) | (g << (8+3)) | (b << (0+3));
766   state->mame_colours[colournum] = (r << (16+3)) | (g << (8+3)) | (b << (0+3));
799767
800   if (colournum<0x10000) palette_set_color(machine,colournum,cps3_mame_colours[colournum]/* MAKE_RGB(r<<3,g<<3,b<<3)*/);//cps3_mame_colours[colournum]);
768   if (colournum<0x10000) palette_set_color(machine,colournum,state->mame_colours[colournum]/* MAKE_RGB(r<<3,g<<3,b<<3)*/);//state->mame_colours[colournum]);
801769}
802770
803771
804772static VIDEO_START(cps3)
805773{
806   cps3_ss_ram       = auto_alloc_array(machine, UINT32, 0x10000/4);
807   memset(cps3_ss_ram, 0x00, 0x10000);
808   state_save_register_global_pointer(machine, cps3_ss_ram, 0x10000/4);
774   cps3_state *state = machine->driver_data<cps3_state>();
775   state->ss_ram       = auto_alloc_array(machine, UINT32, 0x10000/4);
776   memset(state->ss_ram, 0x00, 0x10000);
777   state_save_register_global_pointer(machine, state->ss_ram, 0x10000/4);
809778
810   cps3_char_ram = auto_alloc_array(machine, UINT32, 0x800000/4);
811   memset(cps3_char_ram, 0x00, 0x800000);
812   state_save_register_global_pointer(machine, cps3_char_ram, 0x800000 /4);
779   state->char_ram = auto_alloc_array(machine, UINT32, 0x800000/4);
780   memset(state->char_ram, 0x00, 0x800000);
781   state_save_register_global_pointer(machine, state->char_ram, 0x800000 /4);
813782
814783   /* create the char set (gfx will then be updated dynamically from RAM) */
815   machine->gfx[0] = gfx_element_alloc(machine, &cps3_tiles8x8_layout, (UINT8 *)cps3_ss_ram, machine->total_colors() / 16, 0);
784   machine->gfx[0] = gfx_element_alloc(machine, &cps3_tiles8x8_layout, (UINT8 *)state->ss_ram, machine->total_colors() / 16, 0);
816785
817786   //decode_ssram();
818787
819788   /* create the char set (gfx will then be updated dynamically from RAM) */
820   machine->gfx[1] = gfx_element_alloc(machine, &cps3_tiles16x16_layout, (UINT8 *)cps3_char_ram, machine->total_colors() / 64, 0);
789   machine->gfx[1] = gfx_element_alloc(machine, &cps3_tiles16x16_layout, (UINT8 *)state->char_ram, machine->total_colors() / 64, 0);
821790   machine->gfx[1]->color_granularity = 64;
822791
823792   //decode_charram();
824793
825   cps3_mame_colours = auto_alloc_array(machine, UINT32, 0x80000/4);
826   memset(cps3_mame_colours, 0x00, 0x80000);
794   state->mame_colours = auto_alloc_array(machine, UINT32, 0x80000/4);
795   memset(state->mame_colours, 0x00, 0x80000);
827796
828   cps3_screenwidth = 384;
797   state->screenwidth = 384;
829798
830799   // the renderbuffer can be twice the size of the screen, this allows us to handle framebuffer zoom values
831800   // between 0x00 and 0x80 (0x40 is normal, 0x80 would be 'view twice as much', 0x20 is 'view half as much')
832   renderbuffer_bitmap = auto_bitmap_alloc(machine,512*2,224*2,machine->primary_screen->format());
801   state->renderbuffer_bitmap = auto_bitmap_alloc(machine,512*2,224*2,machine->primary_screen->format());
833802
834   renderbuffer_clip.min_x = 0;
835   renderbuffer_clip.max_x = cps3_screenwidth-1;
836   renderbuffer_clip.min_y = 0;
837   renderbuffer_clip.max_y = 224-1;
803   state->renderbuffer_clip.min_x = 0;
804   state->renderbuffer_clip.max_x = state->screenwidth-1;
805   state->renderbuffer_clip.min_y = 0;
806   state->renderbuffer_clip.max_y = 224-1;
838807
839   bitmap_fill(renderbuffer_bitmap,&renderbuffer_clip,0x3f);
808   bitmap_fill(state->renderbuffer_bitmap,&state->renderbuffer_clip,0x3f);
840809
841810}
842811
r10427r10428
844813
845814static void cps3_draw_tilemapsprite_line(running_machine *machine, int tmnum, int drawline, bitmap_t *bitmap, const rectangle *cliprect )
846815{
847   UINT32* tmapregs[4] = { tilemap20_regs_base, tilemap30_regs_base, tilemap40_regs_base, tilemap50_regs_base };
816   cps3_state *state = machine->driver_data<cps3_state>();
817   UINT32* tmapregs[4] = { state->tilemap20_regs_base, state->tilemap30_regs_base, state->tilemap40_regs_base, state->tilemap50_regs_base };
848818   UINT32* regs;
849819   int line;
850820   int scrolly;
r10427r10428
885855      //  printf("linebase %08x\n", linebase);
886856
887857         scrollx =  (regs[0]&0xffff0000)>>16;
888         scrollx+= (cps3_spriteram[linebase+((line+16-4)&0x3ff)]>>16)&0x3ff;
858         scrollx+= (state->spriteram[linebase+((line+16-4)&0x3ff)]>>16)&0x3ff;
889859
890860      }
891861
r10427r10428
909879         int bpp;
910880         int xflip,yflip;
911881
912         dat = cps3_spriteram[mapbase+((tileline&63)*64)+((x+scrollx/16)&63)];
882         dat = state->spriteram[mapbase+((tileline&63)*64)+((x+scrollx/16)&63)];
913883         tileno = (dat & 0xffff0000)>>17;
914884         colour = (dat & 0x000001ff)>>0;
915885         bpp = (dat & 0x0000200)>>9;
r10427r10428
926896
927897static VIDEO_UPDATE(cps3)
928898{
899   cps3_state *state = screen->machine->driver_data<cps3_state>();
929900   int y,x, count;
930901   attoseconds_t period = screen->frame_period().attoseconds;
931902   rectangle visarea = screen->visible_area();
r10427r10428
941912   /* registers are normally 002a006f 01ef01c6
942913            widescreen mode = 00230076 026501c6
943914      only SFIII2 uses widescreen, I don't know exactly which register controls it */
944   if (((cps3_fullscreenzoom[1]&0xffff0000)>>16)==0x0265)
915   if (((state->fullscreenzoom[1]&0xffff0000)>>16)==0x0265)
945916   {
946      if (cps3_screenwidth!=496)
917      if (state->screenwidth!=496)
947918      {
948         cps3_screenwidth = 496;
919         state->screenwidth = 496;
949920         visarea.min_x = 0; visarea.max_x = 496-1;
950921         visarea.min_y = 0; visarea.max_y = 224-1;
951922         screen->configure(496, 224, visarea, period);
r10427r10428
953924   }
954925   else
955926   {
956      if (cps3_screenwidth!=384)
927      if (state->screenwidth!=384)
957928      {
958         cps3_screenwidth = 384;
929         state->screenwidth = 384;
959930         visarea.min_x = 0; visarea.max_x = 384-1;
960931         visarea.min_y = 0; visarea.max_y = 224-1;
961932         screen->configure(384, 224, visarea, period);
962933      }
963934   }
964935
965   fullscreenzoomx = cps3_fullscreenzoom[3] & 0x000000ff;
966   fullscreenzoomy = cps3_fullscreenzoom[3] & 0x000000ff;
936   fullscreenzoomx = state->fullscreenzoom[3] & 0x000000ff;
937   fullscreenzoomy = state->fullscreenzoom[3] & 0x000000ff;
967938   /* clamp at 0x80, I don't know if this is accurate */
968939   if (fullscreenzoomx>0x80) fullscreenzoomx = 0x80;
969940   if (fullscreenzoomy>0x80) fullscreenzoomy = 0x80;
r10427r10428
971942   fszx = (fullscreenzoomx<<16)/0x40;
972943   fszy = (fullscreenzoomy<<16)/0x40;
973944
974   renderbuffer_clip.min_x = 0;
975   renderbuffer_clip.max_x = ((cps3_screenwidth*fszx)>>16)-1;
976   renderbuffer_clip.min_y = 0;
977   renderbuffer_clip.max_y = ((224*fszx)>>16)-1;
945   state->renderbuffer_clip.min_x = 0;
946   state->renderbuffer_clip.max_x = ((state->screenwidth*fszx)>>16)-1;
947   state->renderbuffer_clip.min_y = 0;
948   state->renderbuffer_clip.max_y = ((224*fszx)>>16)-1;
978949
979   bitmap_fill(renderbuffer_bitmap,&renderbuffer_clip,0);
950   bitmap_fill(state->renderbuffer_bitmap,&state->renderbuffer_clip,0);
980951
981952   /* Sprites */
982953   {
r10427r10428
985956      //printf("Spritelist start:\n");
986957      for (i=0x00000/4;i<0x2000/4;i+=4)
987958      {
988         int xpos =     (cps3_spriteram[i+1]&0x03ff0000)>>16;
989         int ypos =     cps3_spriteram[i+1]&0x000003ff;
959         int xpos =     (state->spriteram[i+1]&0x03ff0000)>>16;
960         int ypos =     state->spriteram[i+1]&0x000003ff;
990961         int j;
991         int gscroll =      (cps3_spriteram[i+0]&0x70000000)>>28;
992         int length =    (cps3_spriteram[i+0]&0x01ff0000)>>16; // how many entries in the sprite table
993         UINT32 start  =    (cps3_spriteram[i+0]&0x00007ff0)>>4;
962         int gscroll =      (state->spriteram[i+0]&0x70000000)>>28;
963         int length =    (state->spriteram[i+0]&0x01ff0000)>>16; // how many entries in the sprite table
964         UINT32 start  =    (state->spriteram[i+0]&0x00007ff0)>>4;
994965
995         int whichbpp =     (cps3_spriteram[i+2]&0x40000000)>>30; // not 100% sure if this is right, jojo title / characters
996         int whichpal =     (cps3_spriteram[i+2]&0x20000000)>>29;
997         int global_xflip = (cps3_spriteram[i+2]&0x10000000)>>28;
998         int global_yflip = (cps3_spriteram[i+2]&0x08000000)>>27;
999         int global_alpha = (cps3_spriteram[i+2]&0x04000000)>>26; // alpha / shadow? set on sfiii2 shadows, and big black image in jojo intro
1000         int global_bpp =   (cps3_spriteram[i+2]&0x02000000)>>25;
1001         int global_pal =   (cps3_spriteram[i+2]&0x01ff0000)>>16;
966         int whichbpp =     (state->spriteram[i+2]&0x40000000)>>30; // not 100% sure if this is right, jojo title / characters
967         int whichpal =     (state->spriteram[i+2]&0x20000000)>>29;
968         int global_xflip = (state->spriteram[i+2]&0x10000000)>>28;
969         int global_yflip = (state->spriteram[i+2]&0x08000000)>>27;
970         int global_alpha = (state->spriteram[i+2]&0x04000000)>>26; // alpha / shadow? set on sfiii2 shadows, and big black image in jojo intro
971         int global_bpp =   (state->spriteram[i+2]&0x02000000)>>25;
972         int global_pal =   (state->spriteram[i+2]&0x01ff0000)>>16;
1002973
1003         int gscrollx = (cps3_unk_vidregs[gscroll]&0x03ff0000)>>16;
1004         int gscrolly = (cps3_unk_vidregs[gscroll]&0x000003ff)>>0;
974         int gscrollx = (state->unk_vidregs[gscroll]&0x03ff0000)>>16;
975         int gscrolly = (state->unk_vidregs[gscroll]&0x000003ff)>>0;
1005976         start = (start * 0x100) >> 2;
1006977
1007         if ((cps3_spriteram[i+0]&0xf0000000) == 0x80000000)
978         if ((state->spriteram[i+0]&0xf0000000) == 0x80000000)
1008979            break;
1009980
1010981         for (j=0;j<(length)*4;j+=4)
1011982         {
1012983
1013            UINT32 value1 =    (cps3_spriteram[start+j+0]);
1014            UINT32 value2 =    (cps3_spriteram[start+j+1]);
1015            UINT32 value3 =    (cps3_spriteram[start+j+2]);
984            UINT32 value1 =    (state->spriteram[start+j+0]);
985            UINT32 value2 =    (state->spriteram[start+j+1]);
986            UINT32 value3 =    (state->spriteram[start+j+2]);
1016987
1017988
1018            //UINT8* srcdata = (UINT8*)cps3_char_ram;
989            //UINT8* srcdata = (UINT8*)state->char_ram;
1019990            //UINT32 sourceoffset = (value1 >>14)&0x7fffff;
1020991            int count;
1021992
r10427r10428
10531024               //int endline;
10541025               //int height = (value3 & 0x7f000000)>>24;
10551026               int uu;
1056               UINT32* tmapregs[4] = { tilemap20_regs_base, tilemap30_regs_base, tilemap40_regs_base, tilemap50_regs_base };
1027               UINT32* tmapregs[4] = { state->tilemap20_regs_base, state->tilemap30_regs_base, state->tilemap40_regs_base, state->tilemap50_regs_base };
10571028               UINT32* regs;
10581029               regs = tmapregs[tilemapnum];
10591030               //endline = value2;
r10427r10428
10751046               {
10761047                  for (uu=0;uu<1023;uu++)
10771048                  {
1078                     cps3_draw_tilemapsprite_line(screen->machine, tilemapnum, uu, renderbuffer_bitmap, &renderbuffer_clip );
1049                     cps3_draw_tilemapsprite_line(screen->machine, tilemapnum, uu, state->renderbuffer_bitmap, &state->renderbuffer_clip );
10791050                  }
10801051               }
10811052               bg_drawn[tilemapnum] = 1;
r10427r10428
11621133
11631134                           if (global_alpha || alpha)
11641135                           {
1165                              cps3_drawgfxzoom(renderbuffer_bitmap,&renderbuffer_clip,screen->machine->gfx[1],realtileno,actualpal,0^flipx,0^flipy,current_xpos,current_ypos,CPS3_TRANSPARENCY_PEN_INDEX_BLEND,0,xinc,yinc, NULL, 0);
1136                              cps3_drawgfxzoom(state->renderbuffer_bitmap,&state->renderbuffer_clip,screen->machine->gfx[1],realtileno,actualpal,0^flipx,0^flipy,current_xpos,current_ypos,CPS3_TRANSPARENCY_PEN_INDEX_BLEND,0,xinc,yinc, NULL, 0);
11661137                           }
11671138                           else
11681139                           {
1169                              cps3_drawgfxzoom(renderbuffer_bitmap,&renderbuffer_clip,screen->machine->gfx[1],realtileno,actualpal,0^flipx,0^flipy,current_xpos,current_ypos,CPS3_TRANSPARENCY_PEN_INDEX,0,xinc,yinc, NULL, 0);
1140                              cps3_drawgfxzoom(state->renderbuffer_bitmap,&state->renderbuffer_clip,screen->machine->gfx[1],realtileno,actualpal,0^flipx,0^flipy,current_xpos,current_ypos,CPS3_TRANSPARENCY_PEN_INDEX,0,xinc,yinc, NULL, 0);
11701141                           }
11711142                           count++;
11721143                        }
r10427r10428
11931164      for (rendery=0;rendery<224;rendery++)
11941165      {
11951166         dstbitmap = BITMAP_ADDR32(bitmap, rendery, 0);
1196         srcbitmap = BITMAP_ADDR32(renderbuffer_bitmap, srcy>>16, 0);
1167         srcbitmap = BITMAP_ADDR32(state->renderbuffer_bitmap, srcy>>16, 0);
11971168         srcx=0;
11981169
1199         for (renderx=0;renderx<cps3_screenwidth;renderx++)
1170         for (renderx=0;renderx<state->screenwidth;renderx++)
12001171         {
1201            dstbitmap[renderx] = cps3_mame_colours[srcbitmap[srcx>>16]&0x1ffff];
1172            dstbitmap[renderx] = state->mame_colours[srcbitmap[srcx>>16]&0x1ffff];
12021173            srcx += fszx;
12031174         }
12041175
r10427r10428
12101181   /* Copy the first 0x800 colours to be used for fg layer rendering */
12111182//  for (offset=0;offset<0x200;offset++)
12121183//  {
1213//      int palreadbase = (cps3_ss_pal_base << 9);
1214//      palette_set_color(machine,offset,cps3_mame_colours[palreadbase+offset]);
1184//      int palreadbase = (state->ss_pal_base << 9);
1185//      palette_set_color(machine,offset,state->mame_colours[palreadbase+offset]);
12151186//  }
12161187
12171188   // fg layer
12181189   {
12191190      // bank select? (sfiii2 intro)
1220      if (cps3_ss_bank_base & 0x01000000) count = 0x000;
1191      if (state->ss_bank_base & 0x01000000) count = 0x000;
12211192      else count = 0x800;
12221193
12231194      for (y=0;y<32;y++)
12241195      {
12251196         for (x=0;x<64;x++)
12261197         {
1227            UINT32 data = cps3_ss_ram[count]; // +0x800 = 2nd bank, used on sfiii2 intro..
1198            UINT32 data = state->ss_ram[count]; // +0x800 = 2nd bank, used on sfiii2 intro..
12281199            UINT32 tile = (data >> 16) & 0x1ff;
12291200            int pal = (data&0x003f) >> 1;
12301201            int flipx = (data & 0x0080) >> 7;
12311202            int flipy = (data & 0x0040) >> 6;
1232            pal += cps3_ss_pal_base << 5;
1203            pal += state->ss_pal_base << 5;
12331204            tile+=0x200;
12341205
12351206            cps3_drawgfxzoom(bitmap, cliprect, screen->machine->gfx[0],tile,pal,flipx,flipy,x*8,y*8,CPS3_TRANSPARENCY_PEN,0,0x10000,0x10000,NULL,0);
r10427r10428
12421213
12431214static READ32_HANDLER( cps3_ssram_r )
12441215{
1216   cps3_state *state = space->machine->driver_data<cps3_state>();
12451217   if (offset>0x8000/4)
1246      return LITTLE_ENDIANIZE_INT32(cps3_ss_ram[offset]);
1218      return LITTLE_ENDIANIZE_INT32(state->ss_ram[offset]);
12471219   else
1248      return cps3_ss_ram[offset];
1220      return state->ss_ram[offset];
12491221}
12501222
12511223static WRITE32_HANDLER( cps3_ssram_w )
12521224{
1225   cps3_state *state = space->machine->driver_data<cps3_state>();
12531226   if (offset>0x8000/4)
12541227   {
12551228      // we only want to endian-flip the character data, the tilemap info is fine
r10427r10428
12581231      gfx_element_mark_dirty(space->machine->gfx[0], offset/16);
12591232   }
12601233
1261   COMBINE_DATA(&cps3_ss_ram[offset]);
1234   COMBINE_DATA(&state->ss_ram[offset]);
12621235}
12631236
12641237static WRITE32_HANDLER( cps3_0xc0000000_ram_w )
12651238{
1266   COMBINE_DATA( &cps3_0xc0000000_ram[offset] );
1239   cps3_state *state = space->machine->driver_data<cps3_state>();
1240   COMBINE_DATA( &state->_0xc0000000_ram[offset] );
12671241   // store a decrypted copy
1268   cps3_0xc0000000_ram_decrypted[offset] = cps3_0xc0000000_ram[offset]^cps3_mask(offset*4+0xc0000000, cps3_key1, cps3_key2);
1242   state->_0xc0000000_ram_decrypted[offset] = state->_0xc0000000_ram[offset]^cps3_mask(offset*4+0xc0000000, state->key1, state->key2);
12691243}
12701244
12711245
12721246
12731247DIRECT_UPDATE_HANDLER( cps3_direct_handler )
12741248{
1249   cps3_state *state = machine->driver_data<cps3_state>();
12751250//  if(DEBUG_PRINTF) printf("address %04x\n",address);
12761251
12771252   /* BIOS ROM */
r10427r10428
12831258   /* RAM */
12841259   else if (address >= 0x06000000 && address <= 0x06ffffff)
12851260   {
1286      UINT8 *decrypted = (UINT8*)decrypted_gamerom;
1261      UINT8 *decrypted = (UINT8*)state->decrypted_gamerom;
12871262      UINT8 *raw = decrypted;
12881263
1289      if (cps3_altEncryption) raw = (UINT8*) cps3_user4region;
1264      if (state->altEncryption) raw = (UINT8*) state->user4region;
12901265
12911266      direct.explicit_configure(0x06000000, 0x06ffffff, 0x00ffffff, raw, decrypted);
12921267
r10427r10428
12941269   }
12951270   else if (address >= 0xc0000000 && address <= 0xc00003ff)
12961271   {
1297      //direct->decrypted = (void*)cps3_0xc0000000_ram_decrypted;
1298      direct.explicit_configure(0xc0000000, 0xc00003ff, 0x3ff, (UINT8*)cps3_0xc0000000_ram, (UINT8*)cps3_0xc0000000_ram_decrypted);
1272      //direct->decrypted = (void*)state->_0xc0000000_ram_decrypted;
1273      direct.explicit_configure(0xc0000000, 0xc00003ff, 0x3ff, (UINT8*)state->_0xc0000000_ram, (UINT8*)state->_0xc0000000_ram_decrypted);
12991274      return ~0;
13001275   }
13011276
13021277   /* anything else falls through to NOPs */
1303   direct.explicit_configure(address, address, 0, (UINT8*)cps3_nops, (UINT8*)cps3_nops);
1278   direct.explicit_configure(address, address, 0, (UINT8*)state->nops, (UINT8*)state->nops);
13041279   return ~0;
13051280}
13061281
1307static UINT32 cram_bank = 0;
13081282
13091283static WRITE32_HANDLER( cram_bank_w )
13101284{
1285   cps3_state *state = space->machine->driver_data<cps3_state>();
13111286   if (ACCESSING_BITS_0_7)
13121287   {
13131288      // this seems to be related to accesses to the 0x04100000 region
1314      if (cram_bank != data)
1289      if (state->cram_bank != data)
13151290      {
1316         cram_bank = data;
1291         state->cram_bank = data;
13171292      //if(data&0xfffffff0)
13181293      //bank_w 00000000, ffff0000
13191294      //bank_w 00000001, ffff0000
r10427r10428
13371312
13381313static READ32_HANDLER( cram_data_r )
13391314{
1340   UINT32 fulloffset = (((cram_bank&0x7)*0x100000)/4) + offset;
1315   cps3_state *state = space->machine->driver_data<cps3_state>();
1316   UINT32 fulloffset = (((state->cram_bank&0x7)*0x100000)/4) + offset;
13411317
1342   return LITTLE_ENDIANIZE_INT32(cps3_char_ram[fulloffset]);
1318   return LITTLE_ENDIANIZE_INT32(state->char_ram[fulloffset]);
13431319}
13441320
13451321static WRITE32_HANDLER( cram_data_w )
13461322{
1347   UINT32 fulloffset = (((cram_bank&0x7)*0x100000)/4) + offset;
1323   cps3_state *state = space->machine->driver_data<cps3_state>();
1324   UINT32 fulloffset = (((state->cram_bank&0x7)*0x100000)/4) + offset;
13481325   mem_mask = LITTLE_ENDIANIZE_INT32(mem_mask);
13491326   data = LITTLE_ENDIANIZE_INT32(data);
1350   COMBINE_DATA(&cps3_char_ram[fulloffset]);
1327   COMBINE_DATA(&state->char_ram[fulloffset]);
13511328   gfx_element_mark_dirty(space->machine->gfx[1], fulloffset/0x40);
13521329}
13531330
r10427r10428
13551332
13561333static READ32_HANDLER( cps3_gfxflash_r )
13571334{
1335   cps3_state *state = space->machine->driver_data<cps3_state>();
13581336   UINT32 result = 0;
1359   if (cram_gfxflash_bank&1) offset += 0x200000/4;
1337   if (state->cram_gfxflash_bank&1) offset += 0x200000/4;
13601338
1361   fujitsu_29f016a_device *chip0 = simm[2 + cram_gfxflash_bank/8][(cram_gfxflash_bank % 8) & ~1];
1362   fujitsu_29f016a_device *chip1 = simm[2 + cram_gfxflash_bank/8][(cram_gfxflash_bank % 8) |  1];
1339   fujitsu_29f016a_device *chip0 = state->simm[2 + state->cram_gfxflash_bank/8][(state->cram_gfxflash_bank % 8) & ~1];
1340   fujitsu_29f016a_device *chip1 = state->simm[2 + state->cram_gfxflash_bank/8][(state->cram_gfxflash_bank % 8) |  1];
13631341   if (chip0 == NULL || chip1 == NULL)
13641342      return 0xffffffff;
13651343
r10427r10428
13861364      result |= chip1->read( (offset<<1)+0x1 ) << 0;
13871365   }
13881366
1389   //printf("read GFX flash chips addr %02x returning %08x mem_mask %08x crambank %08x gfxbank %08x\n", offset*2, result,mem_mask,  cram_bank, cram_gfxflash_bank  );
1367   //printf("read GFX flash chips addr %02x returning %08x mem_mask %08x crambank %08x gfxbank %08x\n", offset*2, result,mem_mask,  state->cram_bank, state->cram_gfxflash_bank  );
13901368
13911369   return result;
13921370}
13931371
13941372static WRITE32_HANDLER( cps3_gfxflash_w )
13951373{
1374   cps3_state *state = space->machine->driver_data<cps3_state>();
13961375   int command;
1397   if (cram_gfxflash_bank&1) offset += 0x200000/4;
1376   if (state->cram_gfxflash_bank&1) offset += 0x200000/4;
13981377
1399   fujitsu_29f016a_device *chip0 = simm[2 + cram_gfxflash_bank/8][(cram_gfxflash_bank % 8) & ~1];
1400   fujitsu_29f016a_device *chip1 = simm[2 + cram_gfxflash_bank/8][(cram_gfxflash_bank % 8) |  1];
1378   fujitsu_29f016a_device *chip0 = state->simm[2 + state->cram_gfxflash_bank/8][(state->cram_gfxflash_bank % 8) & ~1];
1379   fujitsu_29f016a_device *chip1 = state->simm[2 + state->cram_gfxflash_bank/8][(state->cram_gfxflash_bank % 8) |  1];
14011380   if (chip0 == NULL || chip1 == NULL)
14021381      return;
14031382
r10427r10428
14311410
14321411   /* make a copy in the linear memory region we actually use for drawing etc.  having it stored in interleaved flash roms isnt' very useful */
14331412   {
1434      UINT32* romdata = (UINT32*)cps3_user5region;
1413      UINT32* romdata = (UINT32*)state->user5region;
14351414      int real_offset = 0;
14361415      UINT32 newdata;
14371416
1438      real_offset = ((cram_gfxflash_bank&0x3e) * 0x200000) + offset*4;
1417      real_offset = ((state->cram_gfxflash_bank&0x3e) * 0x200000) + offset*4;
14391418
14401419      newdata =((chip0->read_raw(((offset*2)&0xfffffffe)+0)<<8) |
14411420               (chip0->read_raw(((offset*2)&0xfffffffe)+1)<<24) |
r10427r10428
14491428
14501429
14511430
1452static UINT32 cps3_flashmain_r(int which, UINT32 offset, UINT32 mem_mask)
1431static UINT32 cps3_flashmain_r(address_space *space, int which, UINT32 offset, UINT32 mem_mask)
14531432{
1433   cps3_state *state = space->machine->driver_data<cps3_state>();
14541434   UINT32 result = 0;
14551435
1456   if (simm[which][0] == NULL || simm[which][1] == NULL || simm[which][2] == NULL || simm[which][3] == NULL)
1436   if (state->simm[which][0] == NULL || state->simm[which][1] == NULL || state->simm[which][2] == NULL || state->simm[which][3] == NULL)
14571437      return 0xffffffff;
14581438
14591439   if (ACCESSING_BITS_24_31)   // Flash 1
14601440   {
14611441//      logerror("read flash chip %d addr %02x\n", base+0, offset*4 );
1462      result |= (simm[which][0]->read(offset)<<24);
1442      result |= (state->simm[which][0]->read(offset)<<24);
14631443   }
14641444   if (ACCESSING_BITS_16_23)   // Flash 1
14651445   {
14661446//      logerror("read flash chip %d addr %02x\n", base+1, offset*4 );
1467      result |= (simm[which][1]->read(offset)<<16);
1447      result |= (state->simm[which][1]->read(offset)<<16);
14681448   }
14691449   if (ACCESSING_BITS_8_15)   // Flash 1
14701450   {
14711451//      logerror("read flash chip %d addr %02x\n", base+2, offset*4 );
1472      result |= (simm[which][2]->read(offset)<<8);
1452      result |= (state->simm[which][2]->read(offset)<<8);
14731453   }
14741454   if (ACCESSING_BITS_0_7)   // Flash 1
14751455   {
14761456//      logerror("read flash chip %d addr %02x\n", base+3, offset*4 );
1477      result |= (simm[which][3]->read(offset)<<0);
1457      result |= (state->simm[which][3]->read(offset)<<0);
14781458   }
14791459
14801460//  if (base==4) logerror("read flash chips addr %02x returning %08x\n", offset*4, result );
r10427r10428
14861466
14871467static READ32_HANDLER( cps3_flash1_r )
14881468{
1489   UINT32 retvalue = cps3_flashmain_r(0, offset,mem_mask);
1469   cps3_state *state = space->machine->driver_data<cps3_state>();
1470   UINT32 retvalue = cps3_flashmain_r(space, 0, offset,mem_mask);
14901471
1491   if (cps3_altEncryption) return retvalue;
1472   if (state->altEncryption) return retvalue;
14921473
1493   retvalue = retvalue ^ cps3_mask(0x6000000+offset*4, cps3_key1, cps3_key2);
1474   retvalue = retvalue ^ cps3_mask(0x6000000+offset*4, state->key1, state->key2);
14941475   return retvalue;
14951476}
14961477
14971478static READ32_HANDLER( cps3_flash2_r )
14981479{
1499   UINT32 retvalue = cps3_flashmain_r(1, offset,mem_mask);
1480   cps3_state *state = space->machine->driver_data<cps3_state>();
1481   UINT32 retvalue = cps3_flashmain_r(space, 1, offset,mem_mask);
15001482
1501   if (cps3_altEncryption) return retvalue;
1483   if (state->altEncryption) return retvalue;
15021484
1503   retvalue = retvalue ^ cps3_mask(0x6800000+offset*4, cps3_key1, cps3_key2);
1485   retvalue = retvalue ^ cps3_mask(0x6800000+offset*4, state->key1, state->key2);
15041486   return retvalue;
15051487}
15061488
15071489static void cps3_flashmain_w(running_machine *machine, int which, UINT32 offset, UINT32 data, UINT32 mem_mask)
15081490{
1491   cps3_state *state = machine->driver_data<cps3_state>();
15091492   int command;
15101493
1511   if (simm[which][0] == NULL || simm[which][1] == NULL || simm[which][2] == NULL || simm[which][3] == NULL)
1494   if (state->simm[which][0] == NULL || state->simm[which][1] == NULL || state->simm[which][2] == NULL || state->simm[which][3] == NULL)
15121495      return;
15131496
15141497   if (ACCESSING_BITS_24_31)   // Flash 1
15151498   {
15161499      command = (data >> 24) & 0xff;
1517      logerror("write to flash chip %s addr %02x cmd %02x\n", simm[which][0]->tag(), offset, command);
1518      simm[which][0]->write(offset, command);
1500      logerror("write to flash chip %s addr %02x cmd %02x\n", state->simm[which][0]->tag(), offset, command);
1501      state->simm[which][0]->write(offset, command);
15191502   }
15201503   if (ACCESSING_BITS_16_23)   // Flash 2
15211504   {
15221505      command = (data >> 16) & 0xff;
1523      logerror("write to flash chip %s addr %02x cmd %02x\n", simm[which][1]->tag(), offset, command);
1524      simm[which][1]->write(offset, command);
1506      logerror("write to flash chip %s addr %02x cmd %02x\n", state->simm[which][1]->tag(), offset, command);
1507      state->simm[which][1]->write(offset, command);
15251508   }
15261509   if (ACCESSING_BITS_8_15)   // Flash 2
15271510   {
15281511      command = (data >> 8) & 0xff;
1529      logerror("write to flash chip %s addr %02x cmd %02x\n", simm[which][2]->tag(), offset, command);
1530      simm[which][2]->write(offset, command);
1512      logerror("write to flash chip %s addr %02x cmd %02x\n", state->simm[which][2]->tag(), offset, command);
1513      state->simm[which][2]->write(offset, command);
15311514   }
15321515   if (ACCESSING_BITS_0_7)   // Flash 2
15331516   {
15341517      command = (data >> 0) & 0xff;
1535      logerror("write to flash chip %s addr %02x cmd %02x\n", simm[which][3]->tag(), offset, command);
1536      simm[which][3]->write(offset, command);
1518      logerror("write to flash chip %s addr %02x cmd %02x\n", state->simm[which][3]->tag(), offset, command);
1519      state->simm[which][3]->write(offset, command);
15371520   }
15381521
15391522   /* copy data into regions to execute from */
15401523   {
1541      UINT32* romdata =  (UINT32*)cps3_user4region;
1542      UINT32* romdata2 = (UINT32*)decrypted_gamerom;
1524      UINT32* romdata =  (UINT32*)state->user4region;
1525      UINT32* romdata2 = (UINT32*)state->decrypted_gamerom;
15431526      int real_offset = 0;
15441527      UINT32 newdata;
15451528
r10427r10428
15521535         real_offset += 0x800000;
15531536      }
15541537
1555      newdata = (simm[which][0]->read_raw(offset)<<24) |
1556               (simm[which][1]->read_raw(offset)<<16) |
1557                  (simm[which][2]->read_raw(offset)<<8) |
1558                  (simm[which][3]->read_raw(offset)<<0);
1538      newdata = (state->simm[which][0]->read_raw(offset)<<24) |
1539               (state->simm[which][1]->read_raw(offset)<<16) |
1540                  (state->simm[which][2]->read_raw(offset)<<8) |
1541                  (state->simm[which][3]->read_raw(offset)<<0);
15591542
1560      //printf("%08x %08x %08x %08x %08x\n",offset, romdata2[offset], romdata[offset], newdata,  newdata^cps3_mask(0x6000000+real_offset, cps3_key1, cps3_key2)  );
1543      //printf("%08x %08x %08x %08x %08x\n",offset, romdata2[offset], romdata[offset], newdata,  newdata^cps3_mask(0x6000000+real_offset, state->key1, state->key2)  );
15611544
15621545      romdata[offset] = newdata;
1563      romdata2[offset] = newdata^cps3_mask(0x6000000+real_offset, cps3_key1, cps3_key2);
1546      romdata2[offset] = newdata^cps3_mask(0x6000000+real_offset, state->key1, state->key2);
15641547   }
15651548}
15661549
r10427r10428
15761559
15771560static WRITE32_HANDLER( cram_gfxflash_bank_w )
15781561{
1562   cps3_state *state = space->machine->driver_data<cps3_state>();
15791563   if (ACCESSING_BITS_24_31)
15801564   {
15811565      //printf("cram_gfxflash_bank_w MSB32 %08x\n",data);
r10427r10428
16191603    SIMM 7 (Rom 70/71) ** NOT USED (would follow on in sequence tho)
16201604
16211605    */
1622      cram_gfxflash_bank = (data & 0xffff0000) >> 16;
1623      cram_gfxflash_bank-= 0x0002;// as with sound access etc. first 4 meg is 'special' and skipped
1606      state->cram_gfxflash_bank = (data & 0xffff0000) >> 16;
1607      state->cram_gfxflash_bank-= 0x0002;// as with sound access etc. first 4 meg is 'special' and skipped
16241608   }
16251609
16261610   if (ACCESSING_BITS_0_7)
r10427r10428
16531637
16541638/* EEPROM access is a little odd, I think it accesses eeprom through some kind of
16551639   additional interface, as these writes aren't normal for the type of eeprom we have */
1656static UINT16 cps3_current_eeprom_read;
16571640
16581641static READ32_HANDLER( cps3_eeprom_r )
16591642{
1643   cps3_state *state = space->machine->driver_data<cps3_state>();
16601644   int addr = offset*4;
16611645
16621646   if (addr>=0x100 && addr<=0x17f)
16631647   {
1664      if (ACCESSING_BITS_24_31) cps3_current_eeprom_read = (cps3_eeprom[offset-0x100/4] & 0xffff0000)>>16;
1665      else cps3_current_eeprom_read = (cps3_eeprom[offset-0x100/4] & 0x0000ffff)>>0;
1648      if (ACCESSING_BITS_24_31) state->current_eeprom_read = (state->eeprom[offset-0x100/4] & 0xffff0000)>>16;
1649      else state->current_eeprom_read = (state->eeprom[offset-0x100/4] & 0x0000ffff)>>0;
16661650      // read word to latch...
16671651      return 0x00000000;
16681652   }
r10427r10428
16721656      if (ACCESSING_BITS_24_31) return 0;
16731657      else
16741658      {
1675         //if(DEBUG_PRINTF) printf("reading %04x from eeprom\n", cps3_current_eeprom_read);
1676         return cps3_current_eeprom_read;
1659         //if(DEBUG_PRINTF) printf("reading %04x from eeprom\n", state->current_eeprom_read);
1660         return state->current_eeprom_read;
16771661      }
16781662   }
16791663   else
r10427r10428
16861670
16871671static WRITE32_HANDLER( cps3_eeprom_w )
16881672{
1673   cps3_state *state = space->machine->driver_data<cps3_state>();
16891674   int addr = offset*4;
16901675
16911676   if (addr>=0x080 && addr<=0x0ff)
16921677   {
16931678      offset -= 0x80/4;
1694      COMBINE_DATA(&cps3_eeprom[offset]);
1679      COMBINE_DATA(&state->eeprom[offset]);
16951680      // write word to storage
16961681
16971682   }
r10427r10428
17381723
17391724static WRITE32_HANDLER( cps3_ss_bank_base_w )
17401725{
1726   cps3_state *state = space->machine->driver_data<cps3_state>();
17411727   // might be scroll registers or something else..
17421728   // used to display bank with 'insert coin' on during sfiii2 attract intro
1743   COMBINE_DATA(&cps3_ss_bank_base);
1729   COMBINE_DATA(&state->ss_bank_base);
17441730
17451731//  printf("cps3_ss_bank_base_w %08x %08x\n", data, mem_mask);
17461732}
17471733
17481734static WRITE32_HANDLER( cps3_ss_pal_base_w )
17491735{
1736   cps3_state *state = space->machine->driver_data<cps3_state>();
17501737    if(DEBUG_PRINTF) printf ("cps3_ss_pal_base_w %08x %08x\n", data, mem_mask);
17511738
17521739   if(ACCESSING_BITS_24_31)
17531740   {
1754      cps3_ss_pal_base = (data & 0x00ff0000)>>16;
1741      state->ss_pal_base = (data & 0x00ff0000)>>16;
17551742
1756      if (data & 0xff000000) printf("cps3_ss_pal_base MSB32 upper bits used %04x \n", data);
1743      if (data & 0xff000000) printf("ss_pal_base MSB32 upper bits used %04x \n", data);
17571744   }
17581745   else
17591746   {
1760   //  printf("cps3_ss_pal_base LSB32 used %04x \n", data);
1747   //  printf("ss_pal_base LSB32 used %04x \n", data);
17611748   }
17621749}
17631750
17641751//<ElSemi> +0 X  +2 Y +4 unknown +6 enable (&0x8000) +8 low part tilemap base, high part linescroll base
17651752//<ElSemi> (a word each)
17661753
1767static UINT32 paldma_source;
1768static UINT32 paldma_realsource;
1769static UINT32 paldma_dest;
1770static UINT32 paldma_fade;
1771static UINT32 paldma_other2;
1772static UINT32 paldma_length;
17731754
17741755static WRITE32_HANDLER( cps3_palettedma_w )
17751756{
1757   cps3_state *state = space->machine->driver_data<cps3_state>();
17761758   if (offset==0)
17771759   {
1778      COMBINE_DATA(&paldma_source);
1779      paldma_realsource = (paldma_source<<1)-0x400000;
1760      COMBINE_DATA(&state->paldma_source);
1761      state->paldma_realsource = (state->paldma_source<<1)-0x400000;
17801762   }
17811763   else if (offset==1)
17821764   {
1783      COMBINE_DATA(&paldma_dest);
1765      COMBINE_DATA(&state->paldma_dest);
17841766   }
17851767   else if (offset==2)
17861768   {
1787      COMBINE_DATA(&paldma_fade);
1769      COMBINE_DATA(&state->paldma_fade);
17881770   }
17891771   else if (offset==3)
17901772   {
1791      COMBINE_DATA(&paldma_other2);
1773      COMBINE_DATA(&state->paldma_other2);
17921774
17931775      if (ACCESSING_BITS_24_31)
17941776      {
1795         paldma_length = (data & 0xffff0000)>>16;
1777         state->paldma_length = (data & 0xffff0000)>>16;
17961778      }
17971779      if (ACCESSING_BITS_0_7)
17981780      {
17991781         if (data & 0x0002)
18001782         {
18011783            int i;
1802            UINT16* src = (UINT16*)cps3_user5region;
1803         //  if(DEBUG_PRINTF) printf("CPS3 pal dma start %08x (real: %08x) dest %08x fade %08x other2 %08x (length %04x)\n", paldma_source, paldma_realsource, paldma_dest, paldma_fade, paldma_other2, paldma_length);
1784            UINT16* src = (UINT16*)state->user5region;
1785         //  if(DEBUG_PRINTF) printf("CPS3 pal dma start %08x (real: %08x) dest %08x fade %08x other2 %08x (length %04x)\n", state->paldma_source, state->paldma_realsource, state->paldma_dest, state->paldma_fade, state->paldma_other2, state->paldma_length);
18041786
1805            for (i=0;i<paldma_length;i++)
1787            for (i=0;i<state->paldma_length;i++)
18061788            {
1807               UINT16 coldata = src[BYTE_XOR_BE(((paldma_realsource>>1)+i))];
1789               UINT16 coldata = src[BYTE_XOR_BE(((state->paldma_realsource>>1)+i))];
18081790
1809               //if (paldma_fade!=0) printf("%08x\n",paldma_fade);
1791               //if (state->paldma_fade!=0) printf("%08x\n",state->paldma_fade);
18101792
1811               cps3_set_mame_colours(space->machine, (paldma_dest+i)^1, coldata, paldma_fade);
1793               cps3_set_mame_colours(space->machine, (state->paldma_dest+i)^1, coldata, state->paldma_fade);
18121794            }
18131795
18141796
r10427r10428
18211803
18221804}
18231805
1824static UINT32 chardma_source;
1825static UINT32 chardma_other;
18261806
18271807//static UINT8* current_table;
1828static UINT32 current_table_address;
18291808
1830static int cps3_rle_length = 0;
18311809
1832static int last_normal_byte = 0;
18331810
18341811
18351812static UINT32 process_byte( running_machine *machine, UINT8 real_byte, UINT32 destination, int max_length )
18361813{
1837   UINT8* dest       = (UINT8*)cps3_char_ram;
1814   cps3_state *state = machine->driver_data<cps3_state>();
1815   UINT8* dest       = (UINT8*)state->char_ram;
18381816
18391817   //printf("process byte for destination %08x\n", destination);
18401818
r10427r10428
18451823      int tranfercount = 0;
18461824
18471825      //printf("Set RLE Mode\n");
1848      cps3_rle_length = (real_byte&0x3f)+1;
1826      state->rle_length = (real_byte&0x3f)+1;
18491827
1850      //printf("RLE Operation (length %08x\n", cps3_rle_length );
1828      //printf("RLE Operation (length %08x\n", state->rle_length );
18511829
1852      while (cps3_rle_length)
1830      while (state->rle_length)
18531831      {
1854         dest[((destination+tranfercount)&0x7fffff)^3] = (last_normal_byte&0x3f);
1832         dest[((destination+tranfercount)&0x7fffff)^3] = (state->last_normal_byte&0x3f);
18551833         gfx_element_mark_dirty(machine->gfx[1], ((destination+tranfercount)&0x7fffff)/0x100);
18561834         //printf("RLE WRite Byte %08x, %02x\n", destination+tranfercount, real_byte);
18571835
18581836         tranfercount++;
1859         cps3_rle_length--;
1837         state->rle_length--;
18601838         max_length--;
18611839
18621840         if ((destination+tranfercount) > 0x7fffff)  return max_length;
r10427r10428
18701848   {
18711849      //printf("Write Normal Data\n");
18721850      dest[(destination&0x7fffff)^3] = real_byte;
1873      last_normal_byte = real_byte;
1851      state->last_normal_byte = real_byte;
18741852      gfx_element_mark_dirty(machine->gfx[1], (destination&0x7fffff)/0x100);
18751853      return 1;
18761854   }
r10427r10428
18781856
18791857static void cps3_do_char_dma( running_machine *machine, UINT32 real_source, UINT32 real_destination, UINT32 real_length )
18801858{
1881   UINT8* sourcedata = (UINT8*)cps3_user5region;
1859   cps3_state *state = machine->driver_data<cps3_state>();
1860   UINT8* sourcedata = (UINT8*)state->user5region;
18821861   int length_remaining;
18831862
1884   last_normal_byte = 0;
1885   cps3_rle_length = 0;
1863   state->last_normal_byte = 0;
1864   state->rle_length = 0;
18861865   length_remaining = real_length;
18871866   while (length_remaining)
18881867   {
r10427r10428
18971876         UINT32 length_processed;
18981877         current_byte &= 0x7f;
18991878
1900         real_byte = sourcedata[DMA_XOR((current_table_address+current_byte*2+0))];
1879         real_byte = sourcedata[DMA_XOR((state->current_table_address+current_byte*2+0))];
19011880         //if (real_byte&0x80) return;
19021881         length_processed = process_byte( machine, real_byte, real_destination, length_remaining );
19031882         length_remaining-=length_processed; // subtract the number of bytes the operation has taken
r10427r10428
19051884         if (real_destination>0x7fffff) return;
19061885         if (length_remaining<=0) return; // if we've expired, exit
19071886
1908         real_byte = sourcedata[DMA_XOR((current_table_address+current_byte*2+1))];
1887         real_byte = sourcedata[DMA_XOR((state->current_table_address+current_byte*2+1))];
19091888         //if (real_byte&0x80) return;
19101889         length_processed = process_byte( machine, real_byte, real_destination, length_remaining );
19111890         length_remaining-=length_processed; // subtract the number of bytes the operation has taken
r10427r10428
19271906   }
19281907}
19291908
1930static unsigned short lastb;
1931static unsigned short lastb2;
19321909static UINT32 ProcessByte8(running_machine *machine,UINT8 b,UINT32 dst_offset)
19331910{
1934   UINT8* destRAM = (UINT8*)cps3_char_ram;
1911   cps3_state *state = machine->driver_data<cps3_state>();
1912   UINT8* destRAM = (UINT8*)state->char_ram;
19351913   int l=0;
19361914
1937   if(lastb==lastb2)   //rle
1915   if(state->lastb==state->lastb2)   //rle
19381916   {
19391917      int i;
19401918      int rle=(b+1)&0xff;
19411919
19421920      for(i=0;i<rle;++i)
19431921      {
1944         destRAM[(dst_offset&0x7fffff)^3] = lastb;
1922         destRAM[(dst_offset&0x7fffff)^3] = state->lastb;
19451923         gfx_element_mark_dirty(machine->gfx[1], (dst_offset&0x7fffff)/0x100);
19461924
19471925         dst_offset++;
19481926         ++l;
19491927      }
1950      lastb2=0xffff;
1928      state->lastb2=0xffff;
19511929
19521930      return l;
19531931   }
19541932   else
19551933   {
1956      lastb2=lastb;
1957      lastb=b;
1934      state->lastb2=state->lastb;
1935      state->lastb=b;
19581936      destRAM[(dst_offset&0x7fffff)^3] = b;
19591937      gfx_element_mark_dirty(machine->gfx[1], (dst_offset&0x7fffff)/0x100);
19601938      return 1;
r10427r10428
19631941
19641942static void cps3_do_alt_char_dma( running_machine *machine, UINT32 src, UINT32 real_dest, UINT32 real_length )
19651943{
1966   UINT8* px = (UINT8*)cps3_user5region;
1944   cps3_state *state = machine->driver_data<cps3_state>();
1945   UINT8* px = (UINT8*)state->user5region;
19671946   UINT32 start = real_dest;
19681947   UINT32 ds = real_dest;
19691948
1970   lastb=0xfffe;
1971   lastb2=0xffff;
1949   state->lastb=0xfffe;
1950   state->lastb2=0xffff;
19721951
19731952   while(1)
19741953   {
r10427r10428
19841963         {
19851964            UINT8 real_byte;
19861965            p&=0x7f;
1987            real_byte = px[DMA_XOR((current_table_address+p*2+0))];
1966            real_byte = px[DMA_XOR((state->current_table_address+p*2+0))];
19881967            ds+=ProcessByte8(machine,real_byte,ds);
1989            real_byte = px[DMA_XOR((current_table_address+p*2+1))];
1968            real_byte = px[DMA_XOR((state->current_table_address+p*2+1))];
19901969            ds+=ProcessByte8(machine,real_byte,ds);
19911970         }
19921971         else
r10427r10428
20041983
20051984static void cps3_process_character_dma(running_machine *machine, UINT32 address)
20061985{
1986   cps3_state *state = machine->driver_data<cps3_state>();
20071987   int i;
20081988
20091989   //printf("charDMA start:\n");
20101990
20111991   for (i = 0; i < 0x1000; i += 3)
20121992   {
2013      UINT32 dat1 = LITTLE_ENDIANIZE_INT32(cps3_char_ram[i + 0 + (address)]);
2014      UINT32 dat2 = LITTLE_ENDIANIZE_INT32(cps3_char_ram[i + 1 + (address)]);
2015      UINT32 dat3 = LITTLE_ENDIANIZE_INT32(cps3_char_ram[i + 2 + (address)]);
1993      UINT32 dat1 = LITTLE_ENDIANIZE_INT32(state->char_ram[i + 0 + (address)]);
1994      UINT32 dat2 = LITTLE_ENDIANIZE_INT32(state->char_ram[i + 1 + (address)]);
1995      UINT32 dat3 = LITTLE_ENDIANIZE_INT32(state->char_ram[i + 2 + (address)]);
20161996      UINT32 real_source      = (dat3 << 1) - 0x400000;
20171997      UINT32 real_destination =  dat2 << 3;
20181998      UINT32 real_length      = (((dat1 & 0x001fffff) + 1) << 3);
r10427r10428
20272007         /* Sets a table used by the decompression routines */
20282008         {
20292009            /* We should probably copy this, but a pointer to it is fine for our purposes as the data doesn't change */
2030            current_table_address = real_source;
2010            state->current_table_address = real_source;
20312011         }
20322012         cputag_set_input_line(machine, "maincpu", 10, ASSERT_LINE);
20332013      }
r10427r10428
20562036
20572037static WRITE32_HANDLER( cps3_characterdma_w )
20582038{
2039   cps3_state *state = space->machine->driver_data<cps3_state>();
20592040   if(DEBUG_PRINTF) printf("chardma_w %08x %08x %08x\n", offset, data, mem_mask);
20602041
20612042   if (offset==0)
20622043   {
2063      //COMBINE_DATA(&chardma_source);
2044      //COMBINE_DATA(&state->chardma_source);
20642045      if (ACCESSING_BITS_0_7)
20652046      {
2066         chardma_source = data & 0x0000ffff;
2047         state->chardma_source = data & 0x0000ffff;
20672048      }
20682049      if (ACCESSING_BITS_24_31)
20692050      {
r10427r10428
20722053   }
20732054   else if (offset==1)
20742055   {
2075      COMBINE_DATA(&chardma_other);
2056      COMBINE_DATA(&state->chardma_other);
20762057
20772058      if (ACCESSING_BITS_24_31)
20782059      {
20792060         if ((data>>16) & 0x0040)
20802061         {
20812062            UINT32 list_address;
2082            list_address = (chardma_source | ((chardma_other&0x003f0000)));
2063            list_address = (state->chardma_source | ((state->chardma_other&0x003f0000)));
20832064
2084            //printf("chardma_w activated %08x %08x (address = cram %08x)\n", chardma_source, chardma_other, list_address*4 );
2065            //printf("chardma_w activated %08x %08x (address = cram %08x)\n", state->chardma_source, state->chardma_other, list_address*4 );
20852066            cps3_process_character_dma(space->machine, list_address);
20862067         }
20872068         else
20882069         {
2089            if(DEBUG_PRINTF) printf("chardma_w NOT activated %08x %08x\n", chardma_source, chardma_other );
2070            if(DEBUG_PRINTF) printf("chardma_w NOT activated %08x %08x\n", state->chardma_source, state->chardma_other );
20902071         }
20912072
20922073         if ((data>>16) & 0xff80)
2093            if(DEBUG_PRINTF) printf("chardma_w unknown bits in activate command %08x %08x\n", chardma_source, chardma_other );
2074            if(DEBUG_PRINTF) printf("chardma_w unknown bits in activate command %08x %08x\n", state->chardma_source, state->chardma_other );
20942075      }
20952076      else
20962077      {
2097         if(DEBUG_PRINTF) printf("chardma_w LSB32 write to activate command %08x %08x\n", chardma_source, chardma_other );
2078         if(DEBUG_PRINTF) printf("chardma_w LSB32 write to activate command %08x %08x\n", state->chardma_source, state->chardma_other );
20982079      }
20992080   }
21002081}
r10427r10428
21112092
21122093static WRITE32_HANDLER( cps3_unk_vidregs_w )
21132094{
2114   COMBINE_DATA(&cps3_unk_vidregs[offset]);
2095   cps3_state *state = space->machine->driver_data<cps3_state>();
2096   COMBINE_DATA(&state->unk_vidregs[offset]);
21152097}
21162098
21172099static READ32_HANDLER( cps3_colourram_r )
21182100{
2119   UINT16* src = (UINT16*)cps3_colourram;
2101   cps3_state *state = space->machine->driver_data<cps3_state>();
2102   UINT16* src = (UINT16*)state->colourram;
21202103
21212104   return src[offset*2+1] | (src[offset*2+0]<<16);
21222105}
21232106
21242107static WRITE32_HANDLER( cps3_colourram_w )
21252108{
2126//  COMBINE_DATA(&cps3_colourram[offset]);
2109   //cps3_state *state = space->machine->driver_data<cps3_state>();
2110//  COMBINE_DATA(&state->colourram[offset]);
21272111
21282112   if (ACCESSING_BITS_24_31)
21292113   {
r10427r10428
21362120   }
21372121}
21382122
2139static UINT32* cps3_mainram;
21402123
21412124/* there are more unknown writes, but you get the idea */
21422125static ADDRESS_MAP_START( cps3_map, ADDRESS_SPACE_PROGRAM, 32 )
21432126   AM_RANGE(0x00000000, 0x0007ffff) AM_ROM AM_REGION("user1", 0) // Bios ROM
2144   AM_RANGE(0x02000000, 0x0207ffff) AM_RAM AM_BASE(&cps3_mainram) // Main RAM
2127   AM_RANGE(0x02000000, 0x0207ffff) AM_RAM AM_BASE_MEMBER(cps3_state, mainram) // Main RAM
21452128
21462129   AM_RANGE(0x03000000, 0x030003ff) AM_RAM // 'FRAM' (SFIII memory test mode ONLY)
21472130
2148//  AM_RANGE(0x04000000, 0x0407dfff) AM_RAM AM_BASE(&cps3_spriteram)//AM_WRITEONLY // Sprite RAM (jojoba tests this size)
2149   AM_RANGE(0x04000000, 0x0407ffff) AM_RAM AM_BASE(&cps3_spriteram)//AM_WRITEONLY // Sprite RAM
2131//  AM_RANGE(0x04000000, 0x0407dfff) AM_RAM AM_BASE_MEMBER(cps3_state, spriteram)//AM_WRITEONLY // Sprite RAM (jojoba tests this size)
2132   AM_RANGE(0x04000000, 0x0407ffff) AM_RAM AM_BASE_MEMBER(cps3_state, spriteram)//AM_WRITEONLY // Sprite RAM
21502133
2151   AM_RANGE(0x04080000, 0x040bffff) AM_READWRITE(cps3_colourram_r, cps3_colourram_w) AM_BASE(&cps3_colourram)  // Colour RAM (jojoba tests this size) 0x20000 colours?!
2134   AM_RANGE(0x04080000, 0x040bffff) AM_READWRITE(cps3_colourram_r, cps3_colourram_w) AM_BASE_MEMBER(cps3_state, colourram)  // Colour RAM (jojoba tests this size) 0x20000 colours?!
21522135
21532136   // video registers of some kind probably
21542137   AM_RANGE(0x040C0000, 0x040C0003) AM_READ(cps3_40C0000_r)//?? every frame
r10427r10428
21572140    AM_RANGE(0x040C000c, 0x040C000f) AM_READ(cps3_vbl_r)// AM_WRITENOP/
21582141
21592142   AM_RANGE(0x040C0000, 0x040C001f) AM_WRITE(cps3_unk_vidregs_w)
2160   AM_RANGE(0x040C0020, 0x040C002b) AM_WRITEONLY AM_BASE(&tilemap20_regs_base)
2161   AM_RANGE(0x040C0030, 0x040C003b) AM_WRITEONLY AM_BASE(&tilemap30_regs_base)
2162   AM_RANGE(0x040C0040, 0x040C004b) AM_WRITEONLY AM_BASE(&tilemap40_regs_base)
2163   AM_RANGE(0x040C0050, 0x040C005b) AM_WRITEONLY AM_BASE(&tilemap50_regs_base)
2143   AM_RANGE(0x040C0020, 0x040C002b) AM_WRITEONLY AM_BASE_MEMBER(cps3_state, tilemap20_regs_base)
2144   AM_RANGE(0x040C0030, 0x040C003b) AM_WRITEONLY AM_BASE_MEMBER(cps3_state, tilemap30_regs_base)
2145   AM_RANGE(0x040C0040, 0x040C004b) AM_WRITEONLY AM_BASE_MEMBER(cps3_state, tilemap40_regs_base)
2146   AM_RANGE(0x040C0050, 0x040C005b) AM_WRITEONLY AM_BASE_MEMBER(cps3_state, tilemap50_regs_base)
21642147
2165   AM_RANGE(0x040C0060, 0x040C007f) AM_RAM AM_BASE(&cps3_fullscreenzoom)
2148   AM_RANGE(0x040C0060, 0x040C007f) AM_RAM AM_BASE_MEMBER(cps3_state, fullscreenzoom)
21662149
21672150
21682151   AM_RANGE(0x040C0094, 0x040C009b) AM_WRITE(cps3_characterdma_w)
r10427r10428
22012184   AM_RANGE(0x06000000, 0x067fffff) AM_READWRITE( cps3_flash1_r, cps3_flash1_w ) /* Flash ROMs simm 1 */
22022185   AM_RANGE(0x06800000, 0x06ffffff) AM_READWRITE( cps3_flash2_r, cps3_flash2_w ) /* Flash ROMs simm 2 */
22032186
2204   AM_RANGE(0xc0000000, 0xc00003ff) AM_RAM_WRITE( cps3_0xc0000000_ram_w ) AM_BASE(&cps3_0xc0000000_ram) /* Executes code from here */
2187   AM_RANGE(0xc0000000, 0xc00003ff) AM_RAM_WRITE( cps3_0xc0000000_ram_w ) AM_BASE_MEMBER(cps3_state, _0xc0000000_ram) /* Executes code from here */
22052188ADDRESS_MAP_END
22062189
22072190
r10427r10428
22602243}
22612244
22622245
2263//static sh2_cpu_core sh2cp_conf_slave  = { 1 };
2246//static sh2_cpu_core sh2cp_conf_slave  = { 1, NULL };
22642247
22652248
22662249static const SCSIConfigTable dev_table =
r10427r10428
22882271
22892272static MACHINE_RESET( cps3 )
22902273{
2291   current_table_address = -1;
2274   cps3_state *state = machine->driver_data<cps3_state>();
2275   state->current_table_address = -1;
22922276
22932277   // copy data from flashroms back into user regions + decrypt into regions we execute/draw from.
22942278   copy_from_nvram(machine);
r10427r10428
22992283// make a copy in the regions we execute code / draw gfx from
23002284static void copy_from_nvram(running_machine *machine)
23012285{
2302   UINT32* romdata = (UINT32*)cps3_user4region;
2303   UINT32* romdata2 = (UINT32*)decrypted_gamerom;
2286   cps3_state *state = machine->driver_data<cps3_state>();
2287   UINT32* romdata = (UINT32*)state->user4region;
2288   UINT32* romdata2 = (UINT32*)state->decrypted_gamerom;
23042289   int i;
23052290   /* copy + decrypt program roms which have been loaded from flashroms/nvram */
23062291   for (i=0;i<0x800000;i+=4)
23072292   {
23082293      UINT32 data;
23092294
2310      data = ((simm[0][0]->read_raw(i/4)<<24) | (simm[0][1]->read_raw(i/4)<<16) | (simm[0][2]->read_raw(i/4)<<8) | (simm[0][3]->read_raw(i/4)<<0));
2295      data = ((state->simm[0][0]->read_raw(i/4)<<24) | (state->simm[0][1]->read_raw(i/4)<<16) | (state->simm[0][2]->read_raw(i/4)<<8) | (state->simm[0][3]->read_raw(i/4)<<0));
23112296
2312   //  printf("%08x %08x %08x %08x\n",romdata[i/4],data, romdata2[i/4], data ^ cps3_mask(i+0x6000000, cps3_key1, cps3_key2));
2297   //  printf("%08x %08x %08x %08x\n",romdata[i/4],data, romdata2[i/4], data ^ cps3_mask(i+0x6000000, state->key1, state->key2));
23132298      romdata[i/4] = data;
2314      romdata2[i/4] = data ^ cps3_mask(i+0x6000000, cps3_key1, cps3_key2);
2299      romdata2[i/4] = data ^ cps3_mask(i+0x6000000, state->key1, state->key2);
23152300
23162301   }
23172302
23182303   romdata  += 0x800000/4;
23192304   romdata2 += 0x800000/4;
23202305
2321   if (simm[1][0] != NULL)
2306   if (state->simm[1][0] != NULL)
23222307      for (i=0;i<0x800000;i+=4)
23232308      {
23242309         UINT32 data;
23252310
2326         data = ((simm[1][0]->read_raw(i/4)<<24) | (simm[1][1]->read_raw(i/4)<<16) | (simm[1][2]->read_raw(i/4)<<8) | (simm[1][3]->read_raw(i/4)<<0));
2311         data = ((state->simm[1][0]->read_raw(i/4)<<24) | (state->simm[1][1]->read_raw(i/4)<<16) | (state->simm[1][2]->read_raw(i/4)<<8) | (state->simm[1][3]->read_raw(i/4)<<0));
23272312
2328      //  printf("%08x %08x %08x %08x\n",romdata[i/4],data, romdata2[i/4],  data ^ cps3_mask(i+0x6800000, cps3_key1, cps3_key2) );
2313      //  printf("%08x %08x %08x %08x\n",romdata[i/4],data, romdata2[i/4],  data ^ cps3_mask(i+0x6800000, state->key1, state->key2) );
23292314         romdata[i/4] = data;
2330         romdata2[i/4] = data ^ cps3_mask(i+0x6800000, cps3_key1, cps3_key2);
2315         romdata2[i/4] = data ^ cps3_mask(i+0x6800000, state->key1, state->key2);
23312316      }
23322317
23332318   /* copy gfx from loaded flashroms to user reigon 5, where it's used */
r10427r10428
23362321      int flashnum = 0;
23372322      int countoffset = 0;
23382323
2339      romdata = (UINT32*)cps3_user5region;
2324      romdata = (UINT32*)state->user5region;
23402325      for (thebase = 0;thebase < len/2; thebase+=0x200000)
23412326      {
23422327      //  printf("flashnums %d. %d\n",flashnum, flashnum+1);
23432328
2344         fujitsu_29f016a_device *flash0 = simm[2 + flashnum/8][flashnum % 8 + 0];
2345         fujitsu_29f016a_device *flash1 = simm[2 + flashnum/8][flashnum % 8 + 1];
2329         fujitsu_29f016a_device *flash0 = state->simm[2 + flashnum/8][flashnum % 8 + 0];
2330         fujitsu_29f016a_device *flash1 = state->simm[2 + flashnum/8][flashnum % 8 + 1];
23462331         if (flash0 == NULL || flash1 == NULL)
23472332            continue;
23482333         if (flash0 != NULL && flash1 != NULL)
r10427r10428
23842369}
23852370
23862371
2387static int cps3_dma_callback(UINT32 src, UINT32 dst, UINT32 data, int size)
2372static int cps3_dma_callback(device_t *device, UINT32 src, UINT32 dst, UINT32 data, int size)
23882373{
2374   cps3_state *state = device->machine->driver_data<cps3_state>();
23892375   /*
23902376      on the actual CPS3 hardware the SH2 DMA bypasses the encryption.
23912377
r10427r10428
24082394   if (src<0x80000)
24092395   {
24102396      int offs = (src&0x07ffff)>>2;
2411      data = data ^ cps3_mask(offs*4, cps3_key1, cps3_key2);
2397      data = data ^ cps3_mask(offs*4, state->key1, state->key2);
24122398   }
24132399   else if (src>=0x6000000 && src<0x6800000)
24142400   {
24152401      int offs = (src&0x07fffff)>>2;
2416      if (!cps3_altEncryption) data = data ^ cps3_mask(0x6000000+offs*4, cps3_key1, cps3_key2);
2402      if (!state->altEncryption) data = data ^ cps3_mask(0x6000000+offs*4, state->key1, state->key2);
24172403   }
24182404   else if (src>=0x6800000 && src<0x7000000)
24192405   {
24202406      int offs = (src&0x07fffff)>>2;
2421      if (!cps3_altEncryption) data = data ^ cps3_mask(0x6800000+offs*4, cps3_key1, cps3_key2);
2407      if (!state->altEncryption) data = data ^ cps3_mask(0x6800000+offs*4, state->key1, state->key2);
24222408   }
24232409   else
24242410   {
r10427r10428
25092495   MCFG_FUJITSU_29F016A_ADD("simm6.7")
25102496MACHINE_CONFIG_END
25112497
2512static MACHINE_CONFIG_START( cps3, driver_device )
2498static MACHINE_CONFIG_START( cps3, cps3_state )
25132499   /* basic machine hardware */
25142500   MCFG_CPU_ADD("maincpu", SH2, 6250000*4) // external clock is 6.25 Mhz, it sets the intenral multiplier to 4x (this should probably be handled in the core..)
25152501   MCFG_CPU_PROGRAM_MAP(cps3_map)
src/mame/drivers/dec0.c
r10427r10428
162162#include "sound/msm5205.h"
163163
164164
165UINT16 *dec0_ram;
166UINT8 *robocop_shared_ram;
167165
168static UINT8 automat_adpcm_byte;
169static int automat_msm5205_vclk_toggle;
170166
171167/******************************************************************************/
172168
r10427r10428
205201         break;
206202
207203      case 0xe: /* Reset Intel 8751? - not sure, all the games write here at startup */
208         dec0_i8751_reset();
204         dec0_i8751_reset(space->machine);
209205         logerror("CPU #0 PC %06x: warning - write %02x to unmapped memory address %06x\n",cpu_get_pc(space->cpu),data,0x30c010+(offset<<1));
210206         break;
211207
r10427r10428
281277   AM_RANGE(0x000000, 0x05ffff) AM_ROM
282278   AM_RANGE(0x240000, 0x240007) AM_WRITE(dec0_pf1_control_0_w)                        /* text layer */
283279   AM_RANGE(0x240010, 0x240017) AM_WRITE(dec0_pf1_control_1_w)
284   AM_RANGE(0x242000, 0x24207f) AM_WRITEONLY AM_BASE(&dec0_pf1_colscroll)
285   AM_RANGE(0x242400, 0x2427ff) AM_WRITEONLY AM_BASE(&dec0_pf1_rowscroll)
280   AM_RANGE(0x242000, 0x24207f) AM_WRITEONLY AM_BASE_MEMBER(dec0_state, pf1_colscroll)
281   AM_RANGE(0x242400, 0x2427ff) AM_WRITEONLY AM_BASE_MEMBER(dec0_state, pf1_rowscroll)
286282   AM_RANGE(0x242800, 0x243fff) AM_RAM                                          /* Robocop only */
287   AM_RANGE(0x244000, 0x245fff) AM_RAM_WRITE(dec0_pf1_data_w) AM_BASE(&dec0_pf1_data)
283   AM_RANGE(0x244000, 0x245fff) AM_RAM_WRITE(dec0_pf1_data_w) AM_BASE_MEMBER(dec0_state, pf1_data)
288284   AM_RANGE(0x246000, 0x246007) AM_WRITE(dec0_pf2_control_0_w)                        /* first tile layer */
289285   AM_RANGE(0x246010, 0x246017) AM_WRITE(dec0_pf2_control_1_w)
290   AM_RANGE(0x248000, 0x24807f) AM_WRITEONLY AM_BASE(&dec0_pf2_colscroll)
291   AM_RANGE(0x248400, 0x2487ff) AM_WRITEONLY AM_BASE(&dec0_pf2_rowscroll)
292   AM_RANGE(0x24a000, 0x24a7ff) AM_RAM_WRITE(dec0_pf2_data_w) AM_BASE(&dec0_pf2_data)
286   AM_RANGE(0x248000, 0x24807f) AM_WRITEONLY AM_BASE_MEMBER(dec0_state, pf2_colscroll)
287   AM_RANGE(0x248400, 0x2487ff) AM_WRITEONLY AM_BASE_MEMBER(dec0_state, pf2_rowscroll)
288   AM_RANGE(0x24a000, 0x24a7ff) AM_RAM_WRITE(dec0_pf2_data_w) AM_BASE_MEMBER(dec0_state, pf2_data)
293289   AM_RANGE(0x24c000, 0x24c007) AM_WRITE(dec0_pf3_control_0_w)                        /* second tile layer */
294290   AM_RANGE(0x24c010, 0x24c017) AM_WRITE(dec0_pf3_control_1_w)
295   AM_RANGE(0x24c800, 0x24c87f) AM_RAM AM_BASE(&dec0_pf3_colscroll)
296   AM_RANGE(0x24cc00, 0x24cfff) AM_WRITEONLY AM_BASE(&dec0_pf3_rowscroll)
297   AM_RANGE(0x24d000, 0x24d7ff) AM_RAM_WRITE(dec0_pf3_data_w) AM_BASE(&dec0_pf3_data)
291   AM_RANGE(0x24c800, 0x24c87f) AM_RAM AM_BASE_MEMBER(dec0_state, pf3_colscroll)
292   AM_RANGE(0x24cc00, 0x24cfff) AM_WRITEONLY AM_BASE_MEMBER(dec0_state, pf3_rowscroll)
293   AM_RANGE(0x24d000, 0x24d7ff) AM_RAM_WRITE(dec0_pf3_data_w) AM_BASE_MEMBER(dec0_state, pf3_data)
298294   AM_RANGE(0x300000, 0x30001f) AM_READ(dec0_rotary_r)
299295   AM_RANGE(0x30c000, 0x30c00b) AM_READ(dec0_controls_r)
300296   AM_RANGE(0x30c010, 0x30c01f) AM_WRITE(dec0_control_w)                           /* Priority, sound, etc. */
301297   AM_RANGE(0x310000, 0x3107ff) AM_RAM_WRITE(dec0_paletteram_rg_w) AM_BASE_GENERIC(paletteram)
302298   AM_RANGE(0x314000, 0x3147ff) AM_RAM_WRITE(dec0_paletteram_b_w) AM_BASE_GENERIC(paletteram2)
303   AM_RANGE(0xff8000, 0xffbfff) AM_RAM AM_BASE(&dec0_ram)                           /* Main ram */
299   AM_RANGE(0xff8000, 0xffbfff) AM_RAM AM_BASE_MEMBER(dec0_state, ram)                           /* Main ram */
304300   AM_RANGE(0xffc000, 0xffc7ff) AM_RAM AM_BASE_GENERIC(spriteram)                        /* Sprites */
305301ADDRESS_MAP_END
306302
307303static ADDRESS_MAP_START( robocop_sub_map, ADDRESS_SPACE_PROGRAM, 8 )
308304   AM_RANGE(0x000000, 0x00ffff) AM_ROM
309305   AM_RANGE(0x1f0000, 0x1f1fff) AM_RAM                           /* Main ram */
310   AM_RANGE(0x1f2000, 0x1f3fff) AM_RAM AM_BASE(&robocop_shared_ram)   /* Shared ram */
306   AM_RANGE(0x1f2000, 0x1f3fff) AM_RAM AM_BASE_MEMBER(dec0_state, robocop_shared_ram)   /* Shared ram */
311307   AM_RANGE(0x1ff400, 0x1ff403) AM_WRITE(h6280_irq_status_w)
312308ADDRESS_MAP_END
313309
r10427r10428
326322   AM_RANGE(0x000000, 0x05ffff) AM_ROM
327323
328324   /* These locations aren't real!  They are just there so memory is allocated */
329   AM_RANGE(0x200000, 0x2007ff) AM_WRITENOP AM_BASE(&dec0_pf2_data)
330   AM_RANGE(0x202000, 0x203fff) AM_WRITENOP AM_BASE(&dec0_pf1_data)
331   AM_RANGE(0x232000, 0x23207f) AM_WRITENOP AM_BASE(&dec0_pf2_colscroll)
332   AM_RANGE(0x232400, 0x2327ff) AM_WRITENOP AM_BASE(&dec0_pf2_rowscroll)
333   AM_RANGE(0x23c000, 0x23c07f) AM_WRITENOP AM_BASE(&dec0_pf1_colscroll)
334   AM_RANGE(0x23c400, 0x23c7ff) AM_WRITENOP AM_BASE(&dec0_pf1_rowscroll)
325   AM_RANGE(0x200000, 0x2007ff) AM_WRITENOP AM_BASE_MEMBER(dec0_state, pf2_data)
326   AM_RANGE(0x202000, 0x203fff) AM_WRITENOP AM_BASE_MEMBER(dec0_state, pf1_data)
327   AM_RANGE(0x232000, 0x23207f) AM_WRITENOP AM_BASE_MEMBER(dec0_state, pf2_colscroll)
328   AM_RANGE(0x232400, 0x2327ff) AM_WRITENOP AM_BASE_MEMBER(dec0_state, pf2_rowscroll)
329   AM_RANGE(0x23c000, 0x23c07f) AM_WRITENOP AM_BASE_MEMBER(dec0_state, pf1_colscroll)
330   AM_RANGE(0x23c400, 0x23c7ff) AM_WRITENOP AM_BASE_MEMBER(dec0_state, pf1_rowscroll)
335331
336332   AM_RANGE(0x244000, 0x244001) AM_READ(slyspy_state_r) AM_WRITENOP /* protection */
337333
r10427r10428
347343   /* Pf3 is unaffected by protection */
348344   AM_RANGE(0x300000, 0x300007) AM_WRITE(dec0_pf3_control_0_w)
349345   AM_RANGE(0x300010, 0x300017) AM_WRITE(dec0_pf3_control_1_w)
350   AM_RANGE(0x300800, 0x30087f) AM_WRITEONLY AM_BASE(&dec0_pf3_colscroll)
351   AM_RANGE(0x300c00, 0x300fff) AM_WRITEONLY AM_BASE(&dec0_pf3_rowscroll)
352   AM_RANGE(0x301000, 0x3017ff) AM_WRITE(dec0_pf3_data_w) AM_BASE(&dec0_pf3_data)
346   AM_RANGE(0x300800, 0x30087f) AM_WRITEONLY AM_BASE_MEMBER(dec0_state, pf3_colscroll)
347   AM_RANGE(0x300c00, 0x300fff) AM_WRITEONLY AM_BASE_MEMBER(dec0_state, pf3_rowscroll)
348   AM_RANGE(0x301000, 0x3017ff) AM_WRITE(dec0_pf3_data_w) AM_BASE_MEMBER(dec0_state, pf3_data)
353349
354   AM_RANGE(0x304000, 0x307fff) AM_RAM AM_BASE(&dec0_ram)   /* Sly spy main ram */
350   AM_RANGE(0x304000, 0x307fff) AM_RAM AM_BASE_MEMBER(dec0_state, ram)   /* Sly spy main ram */
355351   AM_RANGE(0x308000, 0x3087ff) AM_RAM AM_BASE_GENERIC(spriteram)   /* Sprites */
356352   AM_RANGE(0x310000, 0x3107ff) AM_RAM_WRITE(paletteram16_xxxxBBBBGGGGRRRR_word_w) AM_BASE_GENERIC(paletteram)
357353   AM_RANGE(0x314000, 0x314003) AM_WRITE(slyspy_control_w)
r10427r10428
361357
362358static ADDRESS_MAP_START( midres_map, ADDRESS_SPACE_PROGRAM, 16 )
363359   AM_RANGE(0x000000, 0x07ffff) AM_ROM
364   AM_RANGE(0x100000, 0x103fff) AM_RAM AM_BASE(&dec0_ram)
360   AM_RANGE(0x100000, 0x103fff) AM_RAM AM_BASE_MEMBER(dec0_state, ram)
365361   AM_RANGE(0x120000, 0x1207ff) AM_RAM AM_BASE_GENERIC(spriteram)
366362   AM_RANGE(0x140000, 0x1407ff) AM_WRITE(paletteram16_xxxxBBBBGGGGRRRR_word_w) AM_BASE_GENERIC(paletteram)
367363   AM_RANGE(0x160000, 0x160001) AM_WRITE(dec0_priority_w)
r10427r10428
371367
372368   AM_RANGE(0x200000, 0x200007) AM_WRITE(dec0_pf2_control_0_w)
373369   AM_RANGE(0x200010, 0x200017) AM_WRITE(dec0_pf2_control_1_w)
374   AM_RANGE(0x220000, 0x2207ff) AM_WRITE(dec0_pf2_data_w) AM_BASE(&dec0_pf2_data)
370   AM_RANGE(0x220000, 0x2207ff) AM_WRITE(dec0_pf2_data_w) AM_BASE_MEMBER(dec0_state, pf2_data)
375371   AM_RANGE(0x220800, 0x220fff) AM_WRITE(dec0_pf2_data_w)   /* mirror address used in end sequence */
376   AM_RANGE(0x240000, 0x24007f) AM_RAM AM_BASE(&dec0_pf2_colscroll)
377   AM_RANGE(0x240400, 0x2407ff) AM_RAM AM_BASE(&dec0_pf2_rowscroll)
372   AM_RANGE(0x240000, 0x24007f) AM_RAM AM_BASE_MEMBER(dec0_state, pf2_colscroll)
373   AM_RANGE(0x240400, 0x2407ff) AM_RAM AM_BASE_MEMBER(dec0_state, pf2_rowscroll)
378374
379375   AM_RANGE(0x280000, 0x280007) AM_WRITE(dec0_pf3_control_0_w)
380376   AM_RANGE(0x280010, 0x280017) AM_WRITE(dec0_pf3_control_1_w)
381   AM_RANGE(0x2a0000, 0x2a07ff) AM_WRITE(dec0_pf3_data_w) AM_BASE(&dec0_pf3_data)
382   AM_RANGE(0x2c0000, 0x2c007f) AM_RAM AM_BASE(&dec0_pf3_colscroll)
383   AM_RANGE(0x2c0400, 0x2c07ff) AM_RAM AM_BASE(&dec0_pf3_rowscroll)
377   AM_RANGE(0x2a0000, 0x2a07ff) AM_WRITE(dec0_pf3_data_w) AM_BASE_MEMBER(dec0_state, pf3_data)
378   AM_RANGE(0x2c0000, 0x2c007f) AM_RAM AM_BASE_MEMBER(dec0_state, pf3_colscroll)
379   AM_RANGE(0x2c0400, 0x2c07ff) AM_RAM AM_BASE_MEMBER(dec0_state, pf3_rowscroll)
384380
385381   AM_RANGE(0x300000, 0x300007) AM_WRITE(dec0_pf1_control_0_w)
386382   AM_RANGE(0x300010, 0x300017) AM_WRITE(dec0_pf1_control_1_w)
387   AM_RANGE(0x320000, 0x321fff) AM_WRITE(dec0_pf1_data_w) AM_BASE(&dec0_pf1_data)
388   AM_RANGE(0x340000, 0x34007f) AM_RAM AM_BASE(&dec0_pf1_colscroll)
389   AM_RANGE(0x340400, 0x3407ff) AM_RAM AM_BASE(&dec0_pf1_rowscroll)
383   AM_RANGE(0x320000, 0x321fff) AM_WRITE(dec0_pf1_data_w) AM_BASE_MEMBER(dec0_state, pf1_data)
384   AM_RANGE(0x340000, 0x34007f) AM_RAM AM_BASE_MEMBER(dec0_state, pf1_colscroll)
385   AM_RANGE(0x340400, 0x3407ff) AM_RAM AM_BASE_MEMBER(dec0_state, pf1_rowscroll)
390386
391387   AM_RANGE(0x320000, 0x321fff) AM_RAM
392388ADDRESS_MAP_END
r10427r10428
429425   AM_RANGE(0x000000, 0x05ffff) AM_ROM
430426   AM_RANGE(0x240000, 0x240007) AM_WRITE(dec0_pf2_control_0_w)
431427   AM_RANGE(0x240010, 0x240017) AM_WRITE(dec0_pf2_control_1_w)
432   AM_RANGE(0x246000, 0x247fff) AM_RAM_WRITE(dec0_pf2_data_w) AM_BASE(&dec0_pf2_data)
433//  AM_RANGE(0x240000, 0x24007f) AM_RAM AM_BASE(&dec0_pf2_colscroll)
434//  AM_RANGE(0x240400, 0x2407ff) AM_RAM AM_BASE(&dec0_pf2_rowscroll)
428   AM_RANGE(0x246000, 0x247fff) AM_RAM_WRITE(dec0_pf2_data_w) AM_BASE_MEMBER(dec0_state, pf2_data)
429//  AM_RANGE(0x240000, 0x24007f) AM_RAM AM_BASE_MEMBER(dec0_state, pf2_colscroll)
430//  AM_RANGE(0x240400, 0x2407ff) AM_RAM AM_BASE_MEMBER(dec0_state, pf2_rowscroll)
435431
436432//  AM_RANGE(0x200000, 0x300007) AM_WRITE(dec0_pf1_control_0_w)
437433//  AM_RANGE(0x300010, 0x300017) AM_WRITE(dec0_pf1_control_1_w)
438   AM_RANGE(0x24e000, 0x24ffff) AM_RAM_WRITE(dec0_pf1_data_w) AM_BASE(&dec0_pf1_data)
439//  AM_RANGE(0x340000, 0x34007f) AM_RAM AM_BASE(&dec0_pf1_colscroll)
440//  AM_RANGE(0x340400, 0x3407ff) AM_RAM AM_BASE(&dec0_pf1_rowscroll)
434   AM_RANGE(0x24e000, 0x24ffff) AM_RAM_WRITE(dec0_pf1_data_w) AM_BASE_MEMBER(dec0_state, pf1_data)
435//  AM_RANGE(0x340000, 0x34007f) AM_RAM AM_BASE_MEMBER(dec0_state, pf1_colscroll)
436//  AM_RANGE(0x340400, 0x3407ff) AM_RAM AM_BASE_MEMBER(dec0_state, pf1_rowscroll)
441437
442438   AM_RANGE(0x314008, 0x31400f) AM_READ(slyspy_controls_r)
443439//  AM_RANGE(0x314000, 0x314003) AM_WRITE(slyspy_control_w)
444440
445441   AM_RANGE(0x300000, 0x300007) AM_WRITE(dec0_pf3_control_0_w)
446442   AM_RANGE(0x300010, 0x300017) AM_WRITE(dec0_pf3_control_1_w)
447   AM_RANGE(0x300800, 0x30087f) AM_RAM AM_BASE(&dec0_pf3_colscroll)
448   AM_RANGE(0x300c00, 0x300fff) AM_RAM AM_BASE(&dec0_pf3_rowscroll)
449   AM_RANGE(0x301000, 0x3017ff) AM_RAM_WRITE(dec0_pf3_data_w) AM_BASE(&dec0_pf3_data)
450   AM_RANGE(0x301800, 0x307fff) AM_RAM AM_BASE(&dec0_ram) /* Sly spy main ram */
443   AM_RANGE(0x300800, 0x30087f) AM_RAM AM_BASE_MEMBER(dec0_state, pf3_colscroll)
444   AM_RANGE(0x300c00, 0x300fff) AM_RAM AM_BASE_MEMBER(dec0_state, pf3_rowscroll)
445   AM_RANGE(0x301000, 0x3017ff) AM_RAM_WRITE(dec0_pf3_data_w) AM_BASE_MEMBER(dec0_state, pf3_data)
446   AM_RANGE(0x301800, 0x307fff) AM_RAM AM_BASE_MEMBER(dec0_state, ram) /* Sly spy main ram */
451447   AM_RANGE(0x310000, 0x3107ff) AM_RAM_WRITE(paletteram16_xxxxBBBBGGGGRRRR_word_w) AM_BASE_GENERIC(paletteram)
452448   AM_RANGE(0xb08000, 0xb087ff) AM_RAM AM_BASE_GENERIC(spriteram) /* Sprites */
453449ADDRESS_MAP_END
r10427r10428
457453
458454   AM_RANGE(0x240000, 0x240007) AM_WRITE(dec0_pf1_control_0_w)         /* text layer */
459455   AM_RANGE(0x240010, 0x240017) AM_WRITE(dec0_pf1_control_1_w)
460   AM_RANGE(0x242000, 0x24207f) AM_WRITEONLY AM_BASE(&dec0_pf1_colscroll)
461   AM_RANGE(0x242400, 0x2427ff) AM_WRITEONLY AM_BASE(&dec0_pf1_rowscroll)
456   AM_RANGE(0x242000, 0x24207f) AM_WRITEONLY AM_BASE_MEMBER(dec0_state, pf1_colscroll)
457   AM_RANGE(0x242400, 0x2427ff) AM_WRITEONLY AM_BASE_MEMBER(dec0_state, pf1_rowscroll)
462458
463459   AM_RANGE(0x242800, 0x243fff) AM_RAM                         /* Robocop only */
464   AM_RANGE(0x244000, 0x245fff) AM_RAM_WRITE(dec0_pf1_data_w) AM_BASE(&dec0_pf1_data)
460   AM_RANGE(0x244000, 0x245fff) AM_RAM_WRITE(dec0_pf1_data_w) AM_BASE_MEMBER(dec0_state, pf1_data)
465461
466462   AM_RANGE(0x246000, 0x246007) AM_WRITE(dec0_pf2_control_0_w)         /* first tile layer */
467463   AM_RANGE(0x246010, 0x246017) AM_WRITE(dec0_pf2_control_1_w)
468   AM_RANGE(0x248000, 0x24807f) AM_WRITEONLY AM_BASE(&dec0_pf2_colscroll)
469   AM_RANGE(0x248400, 0x2487ff) AM_WRITEONLY AM_BASE(&dec0_pf2_rowscroll)
464   AM_RANGE(0x248000, 0x24807f) AM_WRITEONLY AM_BASE_MEMBER(dec0_state, pf2_colscroll)
465   AM_RANGE(0x248400, 0x2487ff) AM_WRITEONLY AM_BASE_MEMBER(dec0_state, pf2_rowscroll)
470466
471   AM_RANGE(0x24a000, 0x24a7ff) AM_RAM_WRITE(dec0_pf2_data_w) AM_BASE(&dec0_pf2_data)
467   AM_RANGE(0x24a000, 0x24a7ff) AM_RAM_WRITE(dec0_pf2_data_w) AM_BASE_MEMBER(dec0_state, pf2_data)
472468   AM_RANGE(0x24c000, 0x24c007) AM_WRITE(dec0_pf3_control_0_w)         /* second tile layer */
473469   AM_RANGE(0x24c010, 0x24c017) AM_WRITE(dec0_pf3_control_1_w)
474   AM_RANGE(0x24c800, 0x24c87f) AM_RAM AM_BASE(&dec0_pf3_colscroll)
475   AM_RANGE(0x24cc00, 0x24cfff) AM_WRITEONLY AM_BASE(&dec0_pf3_rowscroll)
476   AM_RANGE(0x24d000, 0x24d7ff) AM_RAM_WRITE(dec0_pf3_data_w) AM_BASE(&dec0_pf3_data)
470   AM_RANGE(0x24c800, 0x24c87f) AM_RAM AM_BASE_MEMBER(dec0_state, pf3_colscroll)
471   AM_RANGE(0x24cc00, 0x24cfff) AM_WRITEONLY AM_BASE_MEMBER(dec0_state, pf3_rowscroll)
472   AM_RANGE(0x24d000, 0x24d7ff) AM_RAM_WRITE(dec0_pf3_data_w) AM_BASE_MEMBER(dec0_state, pf3_data)
477473   AM_RANGE(0x300000, 0x30001f) AM_READ(dec0_rotary_r)
478474   AM_RANGE(0x30c000, 0x30c00b) AM_READ(dec0_controls_r)
479475   AM_RANGE(0x30c000, 0x30c01f) AM_WRITE(automat_control_w)         /* Priority, sound, etc. */
480476   AM_RANGE(0x310000, 0x3107ff) AM_RAM_WRITE(paletteram16_xxxxBBBBGGGGRRRR_word_w) AM_BASE_GENERIC(paletteram)
481477   AM_RANGE(0x314000, 0x3147ff) AM_RAM
482478   AM_RANGE(0x400008, 0x400009) AM_WRITE(dec0_priority_w)            // NEW
483   AM_RANGE(0xff8000, 0xffbfff) AM_RAM AM_BASE(&dec0_ram)            /* Main ram */
479   AM_RANGE(0xff8000, 0xffbfff) AM_RAM AM_BASE_MEMBER(dec0_state, ram)            /* Main ram */
484480   AM_RANGE(0xffc000, 0xffc7ff) AM_RAM AM_BASE_GENERIC(spriteram)         /* Sprites */
485481ADDRESS_MAP_END
486482
487483static WRITE8_HANDLER( automat_adpcm_w )
488484{
489   automat_adpcm_byte = data;
485   dec0_state *state = space->machine->driver_data<dec0_state>();
486   state->automat_adpcm_byte = data;
490487}
491488
492489static ADDRESS_MAP_START( automat_s_map, ADDRESS_SPACE_PROGRAM, 8 )
r10427r10428
11221119
11231120static void automat_vclk_cb(device_t *device)
11241121{
1125   if (automat_msm5205_vclk_toggle == 0)
1122   dec0_state *state = device->machine->driver_data<dec0_state>();
1123   if (state->automat_msm5205_vclk_toggle == 0)
11261124   {
1127      msm5205_data_w(device, automat_adpcm_byte & 0xf);
1125      msm5205_data_w(device, state->automat_adpcm_byte & 0xf);
11281126   }
11291127   else
11301128   {
1131      msm5205_data_w(device, automat_adpcm_byte >> 4);
1129      msm5205_data_w(device, state->automat_adpcm_byte >> 4);
11321130      cputag_set_input_line(device->machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE);
11331131   }
11341132
1135   automat_msm5205_vclk_toggle ^= 1;
1133   state->automat_msm5205_vclk_toggle ^= 1;
11361134}
11371135
11381136static const msm5205_interface msm5205_config =
r10427r10428
11421140};
11431141
11441142
1145static MACHINE_CONFIG_START( automat, driver_device )
1143static MACHINE_CONFIG_START( automat, dec0_state )
11461144
11471145   /* basic machine hardware */
11481146   MCFG_CPU_ADD("maincpu", M68000, 10000000)
r10427r10428
11861184MACHINE_CONFIG_END
11871185
11881186
1189static MACHINE_CONFIG_START( hbarrel, driver_device )
1187static MACHINE_CONFIG_START( hbarrel, dec0_state )
11901188
11911189   /* basic machine hardware */
11921190   MCFG_CPU_ADD("maincpu", M68000, XTAL_20MHz / 2)
r10427r10428
12301228   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.80)
12311229MACHINE_CONFIG_END
12321230
1233static MACHINE_CONFIG_START( baddudes, driver_device )
1231static MACHINE_CONFIG_START( baddudes, dec0_state )
12341232
12351233   /* basic machine hardware */
12361234   MCFG_CPU_ADD("maincpu", M68000, XTAL_20MHz / 2)
r10427r10428
12711269   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.80)
12721270MACHINE_CONFIG_END
12731271
1274static MACHINE_CONFIG_START( birdtry, driver_device )
1272static MACHINE_CONFIG_START( birdtry, dec0_state )
12751273
12761274   /* basic machine hardware */
12771275   MCFG_CPU_ADD("maincpu", M68000, XTAL_20MHz / 2)
r10427r10428
13121310   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.80)
13131311MACHINE_CONFIG_END
13141312
1315static MACHINE_CONFIG_START( robocop, driver_device )
1313static MACHINE_CONFIG_START( robocop, dec0_state )
13161314
13171315   /* basic machine hardware */
13181316   MCFG_CPU_ADD("maincpu", M68000, XTAL_20MHz / 2)
r10427r10428
13581356   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.80)
13591357MACHINE_CONFIG_END
13601358
1361static MACHINE_CONFIG_START( robocopb, driver_device )
1359static MACHINE_CONFIG_START( robocopb, dec0_state )
13621360
13631361   /* basic machine hardware */
13641362   MCFG_CPU_ADD("maincpu", M68000, 10000000)
r10427r10428
13991397   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.80)
14001398MACHINE_CONFIG_END
14011399
1402static MACHINE_CONFIG_START( hippodrm, driver_device )
1400static MACHINE_CONFIG_START( hippodrm, dec0_state )
14031401
14041402   /* basic machine hardware */
14051403   MCFG_CPU_ADD("maincpu", M68000, XTAL_20MHz / 2)
r10427r10428
14451443   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.80)
14461444MACHINE_CONFIG_END
14471445
1448static MACHINE_CONFIG_START( slyspy, driver_device )
1446static MACHINE_CONFIG_START( slyspy, dec0_state )
14491447
14501448   /* basic machine hardware */
14511449   MCFG_CPU_ADD("maincpu", M68000, XTAL_20MHz/2) /* verified on pcb (20MHZ OSC) 68000P12 running at 10Mhz */
r10427r10428
14861484   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.80)
14871485MACHINE_CONFIG_END
14881486
1489static MACHINE_CONFIG_START( secretab, driver_device )
1487static MACHINE_CONFIG_START( secretab, dec0_state )
14901488
14911489   /* basic machine hardware */
14921490   MCFG_CPU_ADD("maincpu", M68000, XTAL_20MHz/2) /* verified on pcb (20MHZ OSC) 68000P12 running at 10Mhz */
r10427r10428
15281526   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.80)
15291527MACHINE_CONFIG_END
15301528
1531static MACHINE_CONFIG_START( midres, driver_device )
1529static MACHINE_CONFIG_START( midres, dec0_state )
15321530
15331531   /* basic machine hardware */
15341532   MCFG_CPU_ADD("maincpu", M68000, XTAL_20MHz/2) /* verified on pcb (20MHZ OSC) 68000P12 running at 10Mhz */
src/mame/drivers/atarig42.c
r10427r10428
102102   /* upper byte */
103103   if (ACCESSING_BITS_8_15)
104104   {
105      atarig42_state *state = space->machine->driver_data<atarig42_state>();
106
105107      /* bit 14 controls the ASIC65 reset line */
106108      asic65_reset(space->machine, (~data >> 14) & 1);
107109
108110      /* bits 13-11 are the MO control bits */
109      atarirle_control_w(space->machine, 0, (data >> 11) & 7);
111      atarirle_control_w(state->rle, (data >> 11) & 7);
110112   }
111113
112114   /* lower byte */
r10427r10428
127129{
128130   atarig42_state *state = space->machine->driver_data<atarig42_state>();
129131   COMBINE_DATA(state->mo_command);
130   atarirle_command_w(0, (data == 0) ? ATARIRLE_COMMAND_CHECKSUM : ATARIRLE_COMMAND_DRAW);
132   atarirle_command_w(state->rle, (data == 0) ? ATARIRLE_COMMAND_CHECKSUM : ATARIRLE_COMMAND_DRAW);
131133}
132134
133135
r10427r10428
365367   AM_RANGE(0xf80000, 0xf80003) AM_WRITE(asic65_data_w)
366368   AM_RANGE(0xfa0000, 0xfa0fff) AM_READWRITE(atarigen_eeprom_r, atarigen_eeprom_w) AM_SHARE("eeprom")
367369   AM_RANGE(0xfc0000, 0xfc0fff) AM_RAM_WRITE(atarigen_666_paletteram_w) AM_BASE_GENERIC(paletteram)
368   AM_RANGE(0xff0000, 0xff0fff) AM_WRITE(atarirle_0_spriteram_w) AM_BASE(&atarirle_0_spriteram)
370   AM_RANGE(0xff0000, 0xff0fff) AM_DEVREADWRITE("rle", atarirle_spriteram_r, atarirle_spriteram_w)
369371   AM_RANGE(0xff2000, 0xff5fff) AM_WRITE(atarigen_playfield_w) AM_BASE_MEMBER(atarig42_state, playfield)
370372   AM_RANGE(0xff6000, 0xff6fff) AM_WRITE(atarigen_alpha_w) AM_BASE_MEMBER(atarig42_state, alpha)
371373   AM_RANGE(0xff7000, 0xff7001) AM_WRITE(mo_command_w) AM_BASE_MEMBER(atarig42_state, mo_command)
r10427r10428
505507GFXDECODE_END
506508
507509
510static const atarirle_desc modesc_0x200 =
511{
512   "gfx3",      /* region where the GFX data lives */
513   256,      /* number of entries in sprite RAM */
514   0,         /* left clip coordinate */
515   0,         /* right clip coordinate */
508516
517   0x200,      /* base palette entry */
518   0x400,      /* maximum number of colors */
519
520   {{ 0x7fff,0,0,0,0,0,0,0 }},   /* mask for the code index */
521   {{ 0,0x01f0,0,0,0,0,0,0 }},   /* mask for the color */
522   {{ 0,0,0xffc0,0,0,0,0,0 }},   /* mask for the X position */
523   {{ 0,0,0,0xffc0,0,0,0,0 }},   /* mask for the Y position */
524   {{ 0,0,0,0,0xffff,0,0,0 }},   /* mask for the scale factor */
525   {{ 0x8000,0,0,0,0,0,0,0 }},   /* mask for the horizontal flip */
526   {{ 0,0,0,0,0,0,0x00ff,0 }},   /* mask for the order */
527   {{ 0,0x0e00,0,0,0,0,0,0 }},   /* mask for the priority */
528   {{ 0 }}                  /* mask for the VRAM target */
529};
530
531
532static const atarirle_desc modesc_0x400 =
533{
534   "gfx3",      /* region where the GFX data lives */
535   256,      /* number of entries in sprite RAM */
536   0,         /* left clip coordinate */
537   0,         /* right clip coordinate */
538
539   0x400,      /* base palette entry */
540   0x400,      /* maximum number of colors */
541
542   {{ 0x7fff,0,0,0,0,0,0,0 }},   /* mask for the code index */
543   {{ 0,0x03f0,0,0,0,0,0,0 }},   /* mask for the color */
544   {{ 0,0,0xffc0,0,0,0,0,0 }},   /* mask for the X position */
545   {{ 0,0,0,0xffc0,0,0,0,0 }},   /* mask for the Y position */
546   {{ 0,0,0,0,0xffff,0,0,0 }},   /* mask for the scale factor */
547   {{ 0x8000,0,0,0,0,0,0,0 }},   /* mask for the horizontal flip */
548   {{ 0,0,0,0,0,0,0x00ff,0 }},   /* mask for the order */
549   {{ 0,0x0e00,0,0,0,0,0,0 }},   /* mask for the priority */
550   {{ 0 }}                  /* mask for the VRAM target */
551};
552
553
554
509555/*************************************
510556 *
511557 *  Machine driver
r10427r10428
538584   MCFG_SCREEN_RAW_PARAMS(ATARI_CLOCK_14MHz/2, 456, 0, 336, 262, 0, 240)
539585
540586   MCFG_VIDEO_START(atarig42)
541   MCFG_VIDEO_EOF(atarirle)
587   MCFG_VIDEO_EOF(atarig42)
542588   MCFG_VIDEO_UPDATE(atarig42)
543589
544590   /* sound hardware */
545591   MCFG_FRAGMENT_ADD(jsa_iii_mono)
546592MACHINE_CONFIG_END
547593
594static MACHINE_CONFIG_DERIVED( atarig42_0x200, atarig42 )
595   MCFG_ATARIRLE_ADD( "rle", modesc_0x200 )
596MACHINE_CONFIG_END
548597
598static MACHINE_CONFIG_DERIVED( atarig42_0x400, atarig42 )
599   MCFG_ATARIRLE_ADD( "rle", modesc_0x400 )
600MACHINE_CONFIG_END
549601
602
603
604
550605/*************************************
551606 *
552607 *  ROM definition(s)
r10427r10428
744799   atarijsa_init(machine, "IN2", 0x0040);
745800
746801   state->playfield_base = 0x400;
747   state->motion_object_base = 0x200;
748   state->motion_object_mask = 0x1ff;
749802
750803   address_space *main = machine->device<m68000_device>("maincpu")->space(AS_PROGRAM);
751804   state->sloop_base = memory_install_readwrite16_handler(main, 0x000000, 0x07ffff, 0, 0, roadriot_sloop_data_r, roadriot_sloop_data_w);
r10427r10428
781834   atarijsa_init(machine, "IN2", 0x0040);
782835
783836   state->playfield_base = 0x000;
784   state->motion_object_base = 0x400;
785   state->motion_object_mask = 0x3ff;
786837
787838   /* it looks like they jsr to $80000 as some kind of protection */
788839   /* put an RTS there so we don't die */
r10427r10428
823874 *
824875 *************************************/
825876
826GAME( 1991, roadriot, 0,        atarig42, roadriot, roadriot, ROT0, "Atari Games", "Road Riot 4WD (set 1, 13 Nov 1991)", GAME_UNEMULATED_PROTECTION )
827GAME( 1991, roadrioto,roadriot, atarig42, roadriot, roadriot, ROT0, "Atari Games", "Road Riot 4WD (set 2, 04 Jun 1991)", GAME_UNEMULATED_PROTECTION )
828GAME( 1992, guardian, 0,        atarig42, guardian, guardian, ROT0, "Atari Games", "Guardians of the 'Hood", 0 )
877GAME( 1991, roadriot, 0,        atarig42_0x200, roadriot, roadriot, ROT0, "Atari Games", "Road Riot 4WD (set 1, 13 Nov 1991)", GAME_UNEMULATED_PROTECTION )
878GAME( 1991, roadrioto,roadriot, atarig42_0x200, roadriot, roadriot, ROT0, "Atari Games", "Road Riot 4WD (set 2, 04 Jun 1991)", GAME_UNEMULATED_PROTECTION )
879GAME( 1992, guardian, 0,        atarig42_0x400, guardian, guardian, ROT0, "Atari Games", "Guardians of the 'Hood", 0 )
src/mame/drivers/firebeat.c
r10427r10428
121121#include "firebeat.lh"
122122
123123
124
125124typedef struct
126125{
127126   UINT32 *vram;
r10427r10428
130129   UINT32 visible_area;
131130} GCU_REGS;
132131
133static UINT8 extend_board_irq_enable;
134static UINT8 extend_board_irq_active;
132typedef struct
133{
134   UINT8 identifier[8];
135   UINT8 password[8];
136   UINT8 data[0x30];
137} IBUTTON_SUBKEY;
135138
136static emu_timer *keyboard_timer;
139typedef struct
140{
141   IBUTTON_SUBKEY subkey[3];
142} IBUTTON;
137143
138static fujitsu_29f016a_device *flash[3];
139144
140static GCU_REGS gcu[2];
141145
146class firebeat_state : public driver_device
147{
148public:
149   firebeat_state(running_machine &machine, const driver_device_config_base &config)
150      : driver_device(machine, config) { }
151
152   UINT8 extend_board_irq_enable;
153   UINT8 extend_board_irq_active;
154   emu_timer *keyboard_timer;
155   fujitsu_29f016a_device *flash[3];
156   GCU_REGS gcu[2];
157   int tick;
158   int layer;
159   UINT8 atapi_regs[16];
160   SCSIInstance *atapi_device_data[2];
161   UINT16 atapi_data[32*1024];
162   UINT8 atapi_scsi_packet[32*1024];
163   int atapi_data_ptr;
164   int atapi_xferlen;
165   int atapi_xfermod;
166   int atapi_cdata_wait;
167   int atapi_drivesel;
168   UINT8 temp_data[64*1024];
169   int cab_data_ptr;
170   const int * cur_cab_data;
171   int keyboard_state[2];
172   UINT8 spu_shared_ram[0x400];
173   UINT32 *work_ram;
174   IBUTTON ibutton;
175   int ibutton_state;
176   int ibutton_read_subkey_ptr;
177   UINT8 ibutton_subkey_data[0x40];
178};
179
180
181
182
183
184
142185static VIDEO_START(firebeat)
143186{
144   gcu[0].vram = auto_alloc_array(machine, UINT32, 0x2000000/4);
145   gcu[1].vram = auto_alloc_array(machine, UINT32, 0x2000000/4);
146   memset(gcu[0].vram, 0, 0x2000000);
147   memset(gcu[1].vram, 0, 0x2000000);
187   firebeat_state *state = machine->driver_data<firebeat_state>();
188   state->gcu[0].vram = auto_alloc_array(machine, UINT32, 0x2000000/4);
189   state->gcu[1].vram = auto_alloc_array(machine, UINT32, 0x2000000/4);
190   memset(state->gcu[0].vram, 0, 0x2000000);
191   memset(state->gcu[1].vram, 0, 0x2000000);
148192}
149193
150194
151static void gcu_draw_object(int chip, bitmap_t *bitmap, const rectangle *cliprect, UINT32 *cmd)
195static void gcu_draw_object(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int chip, UINT32 *cmd)
152196{
197   firebeat_state *state = machine->driver_data<firebeat_state>();
153198   // 0x00: xxx----- -------- -------- --------   command type
154199   // 0x00: -------- xxxxxxxx xxxxxxxx xxxxxxxx   object data address in vram
155200
r10427r10428
179224
180225   int i, j;
181226   int u, v;
182   UINT16 *vr = (UINT16*)gcu[chip].vram;
227   UINT16 *vr = (UINT16*)state->gcu[chip].vram;
183228
184229   if (xscale == 0 || yscale == 0)
185230   {
r10427r10428
348393   }
349394}
350395
351static void gcu_draw_character(int chip, bitmap_t *bitmap, const rectangle *cliprect, UINT32 *cmd)
396static void gcu_draw_character(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int chip, UINT32 *cmd)
352397{
398   firebeat_state *state = machine->driver_data<firebeat_state>();
353399   // 0x00: xxx----- -------- -------- --------   command type
354400   // 0x00: -------- xxxxxxxx xxxxxxxx xxxxxxxx   character data address in vram
355401
r10427r10428
368414   UINT32 address      = cmd[0] & 0xffffff;
369415   UINT16 color[4];
370416
371   UINT16 *vr = (UINT16*)gcu[chip].vram;
417   UINT16 *vr = (UINT16*)state->gcu[chip].vram;
372418
373419   color[0] = (cmd[2] >> 16) & 0xffff;
374420   color[1] = (cmd[2] >>  0) & 0xffff;
r10427r10428
396442   }
397443}
398444
399static void gcu_exec_display_list(int chip, bitmap_t *bitmap, const rectangle *cliprect, UINT32 address)
445static void gcu_exec_display_list(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int chip, UINT32 address)
400446{
447   firebeat_state *state = machine->driver_data<firebeat_state>();
401448   int counter = 0;
402449   int end = 0;
403450
r10427r10428
407454   {
408455      int command;
409456      UINT32 cmd[4];
410      cmd[0] = gcu[chip].vram[i+0];
411      cmd[1] = gcu[chip].vram[i+1];
412      cmd[2] = gcu[chip].vram[i+2];
413      cmd[3] = gcu[chip].vram[i+3];
457      cmd[0] = state->gcu[chip].vram[i+0];
458      cmd[1] = state->gcu[chip].vram[i+1];
459      cmd[2] = state->gcu[chip].vram[i+2];
460      cmd[3] = state->gcu[chip].vram[i+3];
414461
415462      command = (cmd[0] >> 29) & 0x7;
416463
r10427r10428
423470
424471         case 0x1:      // Branch
425472         {
426            gcu_exec_display_list(chip, bitmap, cliprect, cmd[0] & 0xffffff);
473            gcu_exec_display_list(machine, bitmap, cliprect, chip, cmd[0] & 0xffffff);
427474            break;
428475         }
429476
r10427r10428
446493
447494         case 0x5:      // Draw object
448495         {
449            gcu_draw_object(chip, bitmap, cliprect, cmd);
496            gcu_draw_object(machine, bitmap, cliprect, chip, cmd);
450497            break;
451498         }
452499
453500         case 0x7:      // Draw 8x8 Character (2-bits per pixel)
454501         {
455            gcu_draw_character(chip, bitmap, cliprect, cmd);
502            gcu_draw_character(machine, bitmap, cliprect, chip, cmd);
456503            break;
457504         }
458505
r10427r10428
466513   };
467514}
468515
469static int tick = 0;
470static int layer = 0;
471516static VIDEO_UPDATE(firebeat)
472517{
518   firebeat_state *state = screen->machine->driver_data<firebeat_state>();
473519   int chip;
474520
475521   if (screen == screen->machine->m_devicelist.find(SCREEN, 0))
r10427r10428
481527
482528   if (mame_stricmp(screen->machine->gamedrv->name, "popn7") == 0)
483529   {
484      gcu_exec_display_list(chip, bitmap, cliprect, 0x1f80000);
530      gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x1f80000);
485531   }
486532   else
487533   {
488      if (layer >= 2)
534      if (state->layer >= 2)
489535      {
490         gcu_exec_display_list(chip, bitmap, cliprect, 0x8000);
491         gcu_exec_display_list(chip, bitmap, cliprect, 0x0000);
492         gcu_exec_display_list(chip, bitmap, cliprect, 0x10000);
536         gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x8000);
537         gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x0000);
538         gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x10000);
493539      }
494      else if (layer == 0)
540      else if (state->layer == 0)
495541      {
496         gcu_exec_display_list(chip, bitmap, cliprect, 0x200000);
542         gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x200000);
497543
498         //gcu_exec_display_list(chip, bitmap, cliprect, 0x186040);
544         //gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x186040);
499545      }
500      else if (layer == 1)
546      else if (state->layer == 1)
501547      {
502         gcu_exec_display_list(chip, bitmap, cliprect, 0x1d0800);
548         gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x1d0800);
503549
504         gcu_exec_display_list(chip, bitmap, cliprect, 0x1a9440);
550         gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x1a9440);
505551      }
506552   }
507553
508   tick++;
509   if (tick >= 5)
554   state->tick++;
555   if (state->tick >= 5)
510556   {
511      tick = 0;
557      state->tick = 0;
512558      if (input_code_pressed(screen->machine, KEYCODE_0))
513559      {
514         layer++;
515         if (layer > 2)
560         state->layer++;
561         if (state->layer > 2)
516562         {
517            layer = 0;
563            state->layer = 0;
518564         }
519565      }
520566
r10427r10428
526572
527573            for (i=0; i < 0x2000000/4; i++)
528574            {
529                fputc((gcu[0].vram[i] >> 24) & 0xff, file);
530                fputc((gcu[0].vram[i] >> 16) & 0xff, file);
531                fputc((gcu[0].vram[i] >> 8) & 0xff, file);
532                fputc((gcu[0].vram[i] >> 0) & 0xff, file);
575                fputc((state->gcu[0].vram[i] >> 24) & 0xff, file);
576                fputc((state->gcu[0].vram[i] >> 16) & 0xff, file);
577                fputc((state->gcu[0].vram[i] >> 8) & 0xff, file);
578                fputc((state->gcu[0].vram[i] >> 0) & 0xff, file);
533579            }
534580
535581            fclose(file);
r10427r10428
537583
538584            for (i=0; i < 0x2000000/4; i++)
539585            {
540                fputc((gcu[1].vram[i] >> 24) & 0xff, file);
541                fputc((gcu[1].vram[i] >> 16) & 0xff, file);
542                fputc((gcu[1].vram[i] >> 8) & 0xff, file);
543                fputc((gcu[1].vram[i] >> 0) & 0xff, file);
586                fputc((state->gcu[1].vram[i] >> 24) & 0xff, file);
587                fputc((state->gcu[1].vram[i] >> 16) & 0xff, file);
588                fputc((state->gcu[1].vram[i] >> 8) & 0xff, file);
589                fputc((state->gcu[1].vram[i] >> 0) & 0xff, file);
544590            }
545591
546592            fclose(file);
r10427r10428
551597   return 0;
552598}
553599
554static UINT32 GCU_r(int chip, UINT32 offset, UINT32 mem_mask)
600static UINT32 GCU_r(running_machine *machine, int chip, UINT32 offset, UINT32 mem_mask)
555601{
602   firebeat_state *state = machine->driver_data<firebeat_state>();
556603   int reg = offset * 4;
557604
558605   /* VRAM Read */
559606   if (reg >= 0x80 && reg < 0x100)
560607   {
561      return gcu[chip].vram[gcu[chip].vram_read_address + ((reg/4) - 0x20)];
608      return state->gcu[chip].vram[state->gcu[chip].vram_read_address + ((reg/4) - 0x20)];
562609   }
563610
564611   switch(reg)
r10427r10428
576623
577624static void GCU_w(running_machine *machine, int chip, UINT32 offset, UINT32 data, UINT32 mem_mask)
578625{
626   firebeat_state *state = machine->driver_data<firebeat_state>();
579627   int reg = offset * 4;
580628
581629   if (reg != 0x70 && chip == 0)
582630   {
583      //printf("%s:gcu%d_w: %08X, %08X, %08X at %08X\n", machine->describe_context(), chip, data, offset, mem_mask);
584      //logerror("%s:gcu%d_w: %08X, %08X, %08X at %08X\n", cmachine->describe_context(), hip, data, offset, mem_mask);
631      //printf("%s:state->gcu%d_w: %08X, %08X, %08X at %08X\n", machine->describe_context(), chip, data, offset, mem_mask);
632      //logerror("%s:state->gcu%d_w: %08X, %08X, %08X at %08X\n", cmachine->describe_context(), hip, data, offset, mem_mask);
585633   }
586634
587635   switch(reg)
r10427r10428
598646      //case 0x38:
599647      //case 0x3c:
600648      {
601         COMBINE_DATA( &gcu[chip].visible_area );
649         COMBINE_DATA( &state->gcu[chip].visible_area );
602650         if (ACCESSING_BITS_0_15)
603651         {
604652            screen_device *screen = downcast<screen_device *>(machine->m_devicelist.find(SCREEN, chip));
r10427r10428
608656               rectangle visarea = screen->visible_area();
609657               int width, height;
610658
611               width = (gcu[chip].visible_area & 0xffff);
612               height = (gcu[chip].visible_area >> 16) & 0xffff;
659               width = (state->gcu[chip].visible_area & 0xffff);
660               height = (state->gcu[chip].visible_area >> 16) & 0xffff;
613661
614662               visarea.max_x = width-1;
615663               visarea.max_y = height-1;
r10427r10428
627675      //  break;
628676
629677      case 0x5c:      /* VRAM Read Address */
630         gcu[chip].vram_read_address = (data & 0xffffff) / 2;
678         state->gcu[chip].vram_read_address = (data & 0xffffff) / 2;
631679         break;
632680
633681      case 0x60:      /* VRAM FIFO Write Address */
634         gcu[chip].vram_write_fifo_address = (data & 0xffffff) / 2;
682         state->gcu[chip].vram_write_fifo_address = (data & 0xffffff) / 2;
635683
636684   //      printf("gcu%d_w: %08X, %08X, %08X\n", chip, data, offset, mem_mask);
637685         break;
r10427r10428
642690      }
643691
644692      case 0x70:      /* VRAM FIFO Write */
645         gcu[chip].vram[gcu[chip].vram_write_fifo_address] = data;
646         gcu[chip].vram_write_fifo_address++;
693         state->gcu[chip].vram[state->gcu[chip].vram_write_fifo_address] = data;
694         state->gcu[chip].vram_write_fifo_address++;
647695         break;
648696
649697      default:
r10427r10428
654702
655703static READ32_HANDLER(gcu0_r)
656704{
657   return GCU_r(0, offset, mem_mask);
705   return GCU_r(space->machine, 0, offset, mem_mask);
658706}
659707
660708static WRITE32_HANDLER(gcu0_w)
r10427r10428
664712
665713static READ32_HANDLER(gcu1_r)
666714{
667   return GCU_r(1, offset, mem_mask);
715   return GCU_r(space->machine, 1, offset, mem_mask);
668716}
669717
670718static WRITE32_HANDLER(gcu1_w)
r10427r10428
708756
709757static READ32_HANDLER(flashram_r)
710758{
759   firebeat_state *state = space->machine->driver_data<firebeat_state>();
711760   UINT32 r = 0;
712761   if (ACCESSING_BITS_24_31)
713762   {
714      r |= (flash[0]->read((offset*4)+0) & 0xff) << 24;
763      r |= (state->flash[0]->read((offset*4)+0) & 0xff) << 24;
715764   }
716765   if (ACCESSING_BITS_16_23)
717766   {
718      r |= (flash[0]->read((offset*4)+1) & 0xff) << 16;
767      r |= (state->flash[0]->read((offset*4)+1) & 0xff) << 16;
719768   }
720769   if (ACCESSING_BITS_8_15)
721770   {
722      r |= (flash[0]->read((offset*4)+2) & 0xff) << 8;
771      r |= (state->flash[0]->read((offset*4)+2) & 0xff) << 8;
723772   }
724773   if (ACCESSING_BITS_0_7)
725774   {
726      r |= (flash[0]->read((offset*4)+3) & 0xff) << 0;
775      r |= (state->flash[0]->read((offset*4)+3) & 0xff) << 0;
727776   }
728777   return r;
729778}
730779
731780static WRITE32_HANDLER(flashram_w)
732781{
782   firebeat_state *state = space->machine->driver_data<firebeat_state>();
733783   if (ACCESSING_BITS_24_31)
734784   {
735      flash[0]->write((offset*4)+0, (data >> 24) & 0xff);
785      state->flash[0]->write((offset*4)+0, (data >> 24) & 0xff);
736786   }
737787   if (ACCESSING_BITS_16_23)
738788   {
739      flash[0]->write((offset*4)+1, (data >> 16) & 0xff);
789      state->flash[0]->write((offset*4)+1, (data >> 16) & 0xff);
740790   }
741791   if (ACCESSING_BITS_8_15)
742792   {
743      flash[0]->write((offset*4)+2, (data >> 8) & 0xff);
793      state->flash[0]->write((offset*4)+2, (data >> 8) & 0xff);
744794   }
745795   if (ACCESSING_BITS_0_7)
746796   {
747      flash[0]->write((offset*4)+3, (data >> 0) & 0xff);
797      state->flash[0]->write((offset*4)+3, (data >> 0) & 0xff);
748798   }
749799}
750800
751801static READ32_HANDLER(soundflash_r)
752802{
803   firebeat_state *state = space->machine->driver_data<firebeat_state>();
753804   UINT32 r = 0;
754805   fujitsu_29f016a_device *chip;
755806   if (offset >= 0 && offset < 0x200000/4)
756807   {
757      chip = flash[1];
808      chip = state->flash[1];
758809   }
759810   else
760811   {
761      chip = flash[2];
812      chip = state->flash[2];
762813   }
763814
764815   offset &= 0x7ffff;
r10427r10428
784835
785836static WRITE32_HANDLER(soundflash_w)
786837{
838   firebeat_state *state = space->machine->driver_data<firebeat_state>();
787839   fujitsu_29f016a_device *chip;
788840   if (offset >= 0 && offset < 0x200000/4)
789841   {
790      chip = flash[1];
842      chip = state->flash[1];
791843   }
792844   else
793845   {
794      chip = flash[2];
846      chip = state->flash[2];
795847   }
796848
797849   offset &= 0x7ffff;
r10427r10428
827879
828880#define ATAPI_CYCLES_PER_SECTOR (32000)   // plenty of time to allow DMA setup etc.  BIOS requires this be at least 2000, individual games may vary.
829881
830static UINT8 atapi_regs[16];
831static SCSIInstance *atapi_device_data[2];
832882
833883#define ATAPI_STAT_BSY      0x80
834884#define ATAPI_STAT_DRDY    0x40
r10427r10428
851901#define ATAPI_REG_DRIVESEL   6
852902#define ATAPI_REG_CMDSTATUS   7
853903
854static UINT16 atapi_data[32*1024];
855static UINT8  atapi_scsi_packet[32*1024];
856static int atapi_data_ptr, atapi_xferlen, atapi_xfermod, atapi_cdata_wait;
857static int atapi_drivesel;
858904
859905static void atapi_cause_irq(running_machine *machine)
860906{
r10427r10428
868914
869915static void atapi_exit(running_machine& machine)
870916{
871   SCSIDeleteInstance(atapi_device_data[1]);
872   SCSIDeleteInstance(atapi_device_data[0]);
917   firebeat_state *state = machine.driver_data<firebeat_state>();
918   SCSIDeleteInstance(state->atapi_device_data[1]);
919   SCSIDeleteInstance(state->atapi_device_data[0]);
873920}
874921
875922static void atapi_init(running_machine *machine)
876923{
877   memset(atapi_regs, 0, sizeof(atapi_regs));
924   firebeat_state *state = machine->driver_data<firebeat_state>();
925   memset(state->atapi_regs, 0, sizeof(state->atapi_regs));
878926
879   atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
880   atapi_regs[ATAPI_REG_ERRFEAT] = 1;
881   atapi_regs[ATAPI_REG_COUNTLOW] = 0x14;
882   atapi_regs[ATAPI_REG_COUNTHIGH] = 0xeb;
927   state->atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
928   state->atapi_regs[ATAPI_REG_ERRFEAT] = 1;
929   state->atapi_regs[ATAPI_REG_COUNTLOW] = 0x14;
930   state->atapi_regs[ATAPI_REG_COUNTHIGH] = 0xeb;
883931
884   atapi_data_ptr = 0;
885   atapi_cdata_wait = 0;
932   state->atapi_data_ptr = 0;
933   state->atapi_cdata_wait = 0;
886934
887935   // allocate two SCSI CD-ROM devices
888   SCSIAllocInstance( machine, SCSI_DEVICE_CDROM, &atapi_device_data[0], "scsi0" );
936   SCSIAllocInstance( machine, SCSI_DEVICE_CDROM, &state->atapi_device_data[0], "scsi0" );
889937   // TODO: the slave drive can be either CD-ROM, DVD-ROM or HDD
890   SCSIAllocInstance( machine, SCSI_DEVICE_CDROM, &atapi_device_data[1], "scsi1" );
938   SCSIAllocInstance( machine, SCSI_DEVICE_CDROM, &state->atapi_device_data[1], "scsi1" );
891939   machine->add_notifier(MACHINE_NOTIFY_EXIT, atapi_exit);
892940}
893941
894static void atapi_reset(void)
942static void atapi_reset(running_machine *machine)
895943{
944   firebeat_state *state = machine->driver_data<firebeat_state>();
896945   logerror("ATAPI reset\n");
897946
898   atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
899   atapi_regs[ATAPI_REG_ERRFEAT] = 1;
900   atapi_regs[ATAPI_REG_COUNTLOW] = 0x14;
901   atapi_regs[ATAPI_REG_COUNTHIGH] = 0xeb;
947   state->atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
948   state->atapi_regs[ATAPI_REG_ERRFEAT] = 1;
949   state->atapi_regs[ATAPI_REG_COUNTLOW] = 0x14;
950   state->atapi_regs[ATAPI_REG_COUNTHIGH] = 0xeb;
902951
903   atapi_data_ptr = 0;
904   atapi_cdata_wait = 0;
952   state->atapi_data_ptr = 0;
953   state->atapi_cdata_wait = 0;
905954}
906955
907956
908957
909958static UINT16 atapi_command_reg_r(running_machine *machine, int reg)
910959{
960   firebeat_state *state = machine->driver_data<firebeat_state>();
911961   int i, data;
912   static UINT8 temp_data[64*1024];
913962
914963//  printf("ATAPI: Command reg read %d\n", reg);
915964
916965   if (reg == ATAPI_REG_DATA)
917966   {
918967      // assert IRQ and drop DRQ
919      if (atapi_data_ptr == 0)
968      if (state->atapi_data_ptr == 0)
920969      {
921970         //printf("ATAPI: dropping DRQ\n");
922971         atapi_cause_irq(machine);
923         atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
972         state->atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
924973
925974         // get the data from the device
926         SCSIReadData( atapi_device_data[atapi_drivesel], temp_data, atapi_xferlen );
975         SCSIReadData( state->atapi_device_data[state->atapi_drivesel], state->temp_data, state->atapi_xferlen );
927976
928977         // fix it up in an endian-safe way
929         for (i = 0; i < atapi_xferlen; i += 2)
978         for (i = 0; i < state->atapi_xferlen; i += 2)
930979         {
931            atapi_data[i/2] = temp_data[i+0] | temp_data[i+1]<<8;
980            state->atapi_data[i/2] = state->temp_data[i+0] | state->temp_data[i+1]<<8;
932981         }
933982      }
934983
935      data = atapi_data[atapi_data_ptr];
936//      printf("ATAPI: %d, packet read = %04x\n", atapi_data_ptr, atapi_data[atapi_data_ptr]);
937      atapi_data_ptr++;
984      data = state->atapi_data[state->atapi_data_ptr];
985//      printf("ATAPI: %d, packet read = %04x\n", state->atapi_data_ptr, state->atapi_data[state->atapi_data_ptr]);
986      state->atapi_data_ptr++;
938987
939      if (atapi_xfermod && atapi_data_ptr == (atapi_xferlen/2))
988      if (state->atapi_xfermod && state->atapi_data_ptr == (state->atapi_xferlen/2))
940989      {
941990         //printf("ATAPI: DRQ interrupt\n");
942991         atapi_cause_irq(machine);
943         atapi_regs[ATAPI_REG_CMDSTATUS] |= ATAPI_STAT_DRQ;
944         atapi_data_ptr = 0;
992         state->atapi_regs[ATAPI_REG_CMDSTATUS] |= ATAPI_STAT_DRQ;
993         state->atapi_data_ptr = 0;
945994
946         if (atapi_xfermod > 63488)
995         if (state->atapi_xfermod > 63488)
947996         {
948            atapi_xfermod = atapi_xfermod - 63488;
949            atapi_xferlen = 63488;
997            state->atapi_xfermod = state->atapi_xfermod - 63488;
998            state->atapi_xferlen = 63488;
950999         }
9511000         else
9521001         {
953            atapi_xferlen = atapi_xfermod;
954            atapi_xfermod = 0;
1002            state->atapi_xferlen = state->atapi_xfermod;
1003            state->atapi_xfermod = 0;
9551004         }
9561005
957         //printf("ATAPI Transfer: %d, %d, %d\n", atapi_transfer_length, atapi_xfermod, atapi_xferlen);
1006         //printf("ATAPI Transfer: %d, %d, %d\n", atapi_transfer_length, state->atapi_xfermod, state->atapi_xferlen);
9581007
959         atapi_regs[ATAPI_REG_COUNTLOW] = atapi_xferlen & 0xff;
960         atapi_regs[ATAPI_REG_COUNTHIGH] = (atapi_xferlen>>8)&0xff;
1008         state->atapi_regs[ATAPI_REG_COUNTLOW] = state->atapi_xferlen & 0xff;
1009         state->atapi_regs[ATAPI_REG_COUNTHIGH] = (state->atapi_xferlen>>8)&0xff;
9611010      }
9621011      return data;
9631012   }
r10427r10428
9651014   {
9661015      if (reg == ATAPI_REG_CMDSTATUS)
9671016         atapi_clear_irq(machine);
968      return atapi_regs[reg];
1017      return state->atapi_regs[reg];
9691018   }
9701019}
9711020
9721021static void atapi_command_reg_w(running_machine *machine, int reg, UINT16 data)
9731022{
1023   firebeat_state *state = machine->driver_data<firebeat_state>();
9741024   int i;
9751025
9761026   if (reg == ATAPI_REG_DATA)
9771027   {
9781028//      printf("%s:ATAPI: packet write %04x\n", device->machine->describe_context(), data);
979      atapi_data[atapi_data_ptr] = data;
980      atapi_data_ptr++;
1029      state->atapi_data[state->atapi_data_ptr] = data;
1030      state->atapi_data_ptr++;
9811031
982      if (atapi_cdata_wait)
1032      if (state->atapi_cdata_wait)
9831033      {
984//          printf("ATAPI: waiting, ptr %d wait %d\n", atapi_data_ptr, atapi_cdata_wait);
985         if (atapi_data_ptr == atapi_cdata_wait)
1034//          printf("ATAPI: waiting, ptr %d wait %d\n", state->atapi_data_ptr, state->atapi_cdata_wait);
1035         if (state->atapi_data_ptr == state->atapi_cdata_wait)
9861036         {
9871037            // decompose SCSI packet into proper byte order
988            for (i = 0; i < atapi_cdata_wait; i += 2)
1038            for (i = 0; i < state->atapi_cdata_wait; i += 2)
9891039            {
990               atapi_scsi_packet[i] = atapi_data[i/2]&0xff;
991               atapi_scsi_packet[i+1] = atapi_data[i/2]>>8;
1040               state->atapi_scsi_packet[i] = state->atapi_data[i/2]&0xff;
1041               state->atapi_scsi_packet[i+1] = state->atapi_data[i/2]>>8;
9921042            }
9931043
9941044            // send it to the device
995            SCSIWriteData( atapi_device_data[atapi_drivesel], atapi_scsi_packet, atapi_cdata_wait );
1045            SCSIWriteData( state->atapi_device_data[state->atapi_drivesel], state->atapi_scsi_packet, state->atapi_cdata_wait );
9961046
9971047            // assert IRQ
9981048            atapi_cause_irq(machine);
9991049
10001050            // not sure here, but clear DRQ at least?
1001            atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
1051            state->atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
10021052         }
10031053      }
10041054
1005      if ((!atapi_cdata_wait) && (atapi_data_ptr == 6))
1055      if ((!state->atapi_cdata_wait) && (state->atapi_data_ptr == 6))
10061056      {
10071057         int phase;
10081058
10091059         // reset data pointer for reading SCSI results
1010         atapi_data_ptr = 0;
1060         state->atapi_data_ptr = 0;
10111061
1012         atapi_regs[ATAPI_REG_CMDSTATUS] |= ATAPI_STAT_BSY;
1062         state->atapi_regs[ATAPI_REG_CMDSTATUS] |= ATAPI_STAT_BSY;
10131063
10141064         // assert IRQ
10151065         atapi_cause_irq(machine);
r10427r10428
10171067         // decompose SCSI packet into proper byte order
10181068         for (i = 0; i < 16; i += 2)
10191069         {
1020            atapi_scsi_packet[i+0] = atapi_data[i/2]&0xff;
1021            atapi_scsi_packet[i+1] = atapi_data[i/2]>>8;
1070            state->atapi_scsi_packet[i+0] = state->atapi_data[i/2]&0xff;
1071            state->atapi_scsi_packet[i+1] = state->atapi_data[i/2]>>8;
10221072         }
10231073
10241074         // send it to the SCSI device
1025         SCSISetCommand( atapi_device_data[atapi_drivesel], atapi_scsi_packet, 12 );
1026         SCSIExecCommand( atapi_device_data[atapi_drivesel], &atapi_xferlen );
1027         SCSIGetPhase( atapi_device_data[atapi_drivesel], &phase );
1075         SCSISetCommand( state->atapi_device_data[state->atapi_drivesel], state->atapi_scsi_packet, 12 );
1076         SCSIExecCommand( state->atapi_device_data[state->atapi_drivesel], &state->atapi_xferlen );
1077         SCSIGetPhase( state->atapi_device_data[state->atapi_drivesel], &phase );
10281078
1029         if (atapi_xferlen != -1)
1079         if (state->atapi_xferlen != -1)
10301080         {
1031            logerror("ATAPI: SCSI command %02x returned %d bytes from the device\n", atapi_data[0]&0xff, atapi_xferlen);
1081            logerror("ATAPI: SCSI command %02x returned %d bytes from the device\n", state->atapi_data[0]&0xff, state->atapi_xferlen);
10321082
10331083            // store the returned command length in the ATAPI regs, splitting into
10341084            // multiple transfers if necessary
10351085
1036            atapi_xfermod = 0;
1037            if (atapi_xferlen > 63488)
1086            state->atapi_xfermod = 0;
1087            if (state->atapi_xferlen > 63488)
10381088            {
1039               atapi_xfermod = atapi_xferlen - 63488;
1040               atapi_xferlen = 63488;
1089               state->atapi_xfermod = state->atapi_xferlen - 63488;
1090               state->atapi_xferlen = 63488;
10411091            }
10421092
1043//              printf("ATAPI Transfer: %d, %d\n", atapi_xfermod, atapi_xferlen);
1093//              printf("ATAPI Transfer: %d, %d\n", state->atapi_xfermod, state->atapi_xferlen);
10441094
1045            atapi_regs[ATAPI_REG_COUNTLOW] = atapi_xferlen & 0xff;
1046            atapi_regs[ATAPI_REG_COUNTHIGH] = (atapi_xferlen>>8)&0xff;
1095            state->atapi_regs[ATAPI_REG_COUNTLOW] = state->atapi_xferlen & 0xff;
1096            state->atapi_regs[ATAPI_REG_COUNTHIGH] = (state->atapi_xferlen>>8)&0xff;
10471097
10481098            switch( phase )
10491099            {
10501100            case SCSI_PHASE_DATAOUT:
1051               atapi_data_ptr = 0;
1052               atapi_cdata_wait = atapi_xferlen;
1053               logerror("ATAPI: Waiting for %x bytes of data\n", atapi_cdata_wait);
1101               state->atapi_data_ptr = 0;
1102               state->atapi_cdata_wait = state->atapi_xferlen;
1103               logerror("ATAPI: Waiting for %x bytes of data\n", state->atapi_cdata_wait);
10541104               break;
10551105            }
10561106
10571107            // perform special ATAPI processing of certain commands
1058            switch (atapi_data[0]&0xff)
1108            switch (state->atapi_data[0]&0xff)
10591109            {
10601110               case 0xa8:   // READ (12)
10611111                  // indicate data ready: set DRQ and DMA ready, and IO in INTREASON
1062                  atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_SERVDSC;
1063                  atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO;
1112                  state->atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_SERVDSC;
1113                  state->atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO;
10641114
10651115                  fatalerror("ATAPI: DMA read command attempted\n");
10661116                  break;
r10427r10428
10701120               case 0xa5: // PLAY AUDIO
10711121               case 0x1b:
10721122               case 0x4e:
1073                  atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
1123                  state->atapi_regs[ATAPI_REG_CMDSTATUS] = 0;
10741124                  break;
10751125            }
10761126         }
r10427r10428
10781128         {
10791129//              printf("ATAPI: SCSI device returned error!\n");
10801130
1081            atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_CHECK;
1082            atapi_regs[ATAPI_REG_ERRFEAT] = 0x50;   // sense key = ILLEGAL REQUEST
1083            atapi_regs[ATAPI_REG_COUNTLOW] = 0;
1084            atapi_regs[ATAPI_REG_COUNTHIGH] = 0;
1131            state->atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_CHECK;
1132            state->atapi_regs[ATAPI_REG_ERRFEAT] = 0x50;   // sense key = ILLEGAL REQUEST
1133            state->atapi_regs[ATAPI_REG_COUNTLOW] = 0;
1134            state->atapi_regs[ATAPI_REG_COUNTHIGH] = 0;
10851135         }
10861136      }
10871137   }
10881138   else
10891139   {
10901140      data &= 0xff;
1091      atapi_regs[reg] = data;
1141      state->atapi_regs[reg] = data;
10921142//      printf("ATAPI: Command reg %d = %02X\n", reg, data);
10931143
10941144      switch(reg)
10951145      {
10961146         case ATAPI_REG_DRIVESEL:
1097            atapi_drivesel = (data >> 4) & 0x1;
1147            state->atapi_drivesel = (data >> 4) & 0x1;
10981148            break;
10991149
11001150         case ATAPI_REG_CMDSTATUS:
r10427r10428
11061156                  break;
11071157
11081158               case 0x08:      /* ATAPI Soft Reset */
1109                  atapi_reset();
1159                  atapi_reset(machine);
11101160                  break;
11111161
11121162               case 0xa0:      /* ATAPI Packet */
1113                  atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_BSY | ATAPI_STAT_DRQ;
1114                  atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_COMMAND;
1163                  state->atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_BSY | ATAPI_STAT_DRQ;
1164                  state->atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_COMMAND;
11151165
1116                  atapi_data_ptr = 0;
1117                  atapi_cdata_wait = 0;
1166                  state->atapi_data_ptr = 0;
1167                  state->atapi_cdata_wait = 0;
11181168                  break;
11191169
11201170               default:
r10427r10428
11251175   }
11261176}
11271177
1128static UINT16 atapi_control_reg_r(int reg)
1178static UINT16 atapi_control_reg_r(running_machine *machine, int reg)
11291179{
1180   firebeat_state *state = machine->driver_data<firebeat_state>();
11301181   UINT16 value;
11311182   switch(reg)
11321183   {
11331184      case 0x6:
11341185      {
1135         value = atapi_regs[ATAPI_REG_CMDSTATUS];
1136         if (atapi_regs[ATAPI_REG_CMDSTATUS] & ATAPI_STAT_BSY)
1186         value = state->atapi_regs[ATAPI_REG_CMDSTATUS];
1187         if (state->atapi_regs[ATAPI_REG_CMDSTATUS] & ATAPI_STAT_BSY)
11371188         {
1138            atapi_regs[ATAPI_REG_CMDSTATUS] ^= ATAPI_STAT_BSY;
1189            state->atapi_regs[ATAPI_REG_CMDSTATUS] ^= ATAPI_STAT_BSY;
11391190         }
11401191         return value;
11411192      }
r10427r10428
11481199   return 0;
11491200}
11501201
1151static void atapi_control_reg_w(int reg, UINT16 data)
1202static void atapi_control_reg_w(running_machine *machine, int reg, UINT16 data)
11521203{
11531204   switch(reg)
11541205   {
r10427r10428
11561207      {
11571208         if (data & 0x4)
11581209         {
1159            atapi_reset();
1210            atapi_reset(machine);
11601211         }
11611212         break;
11621213      }
r10427r10428
12061257
12071258   if (ACCESSING_BITS_16_31)
12081259   {
1209      r = atapi_control_reg_r(offset*2);
1260      r = atapi_control_reg_r(space->machine, offset*2);
12101261      return ATAPI_ENDIAN(r) << 16;
12111262   }
12121263   else
12131264   {
1214      r = atapi_control_reg_r((offset*2) + 1);
1265      r = atapi_control_reg_r(space->machine, (offset*2) + 1);
12151266      return ATAPI_ENDIAN(r) << 0;
12161267   }
12171268}
r10427r10428
12201271{
12211272   if (ACCESSING_BITS_16_31)
12221273   {
1223      atapi_control_reg_w(offset*2, ATAPI_ENDIAN(data >> 16) & 0xff);
1274      atapi_control_reg_w(space->machine, offset*2, ATAPI_ENDIAN(data >> 16) & 0xff);
12241275   }
12251276   else
12261277   {
1227      atapi_control_reg_w((offset*2) + 1, ATAPI_ENDIAN(data >> 0) & 0xff);
1278      atapi_control_reg_w(space->machine, (offset*2) + 1, ATAPI_ENDIAN(data >> 0) & 0xff);
12281279   }
12291280}
12301281
r10427r10428
12861337static const int cab_data[2] = { 0x0, 0x8 };
12871338static const int kbm_cab_data[2] = { 0x2, 0x8 };
12881339static const int ppd_cab_data[2] = { 0x1, 0x9 };
1289static int cab_data_ptr = 0;
1290static const int * cur_cab_data;
12911340
12921341static READ32_HANDLER( cabinet_r )
12931342{
1343   firebeat_state *state = space->machine->driver_data<firebeat_state>();
12941344   UINT32 r = 0;
12951345
12961346//  printf("cabinet_r: %08X, %08X\n", offset, mem_mask);
r10427r10428
12991349   {
13001350      case 0:
13011351      {
1302         r = cur_cab_data[cab_data_ptr & 1] << 28;
1303         cab_data_ptr++;
1352         r = state->cur_cab_data[state->cab_data_ptr & 1] << 28;
1353         state->cab_data_ptr++;
13041354         return r;
13051355      }
13061356      case 2:      return 0x00000000;
r10427r10428
13481398
13491399static void midi_uart_irq_callback(running_machine *machine, int channel, int value)
13501400{
1401   firebeat_state *state = machine->driver_data<firebeat_state>();
13511402   if (channel == 0)
13521403   {
1353      if ((extend_board_irq_enable & 0x02) == 0 && value != CLEAR_LINE)
1404      if ((state->extend_board_irq_enable & 0x02) == 0 && value != CLEAR_LINE)
13541405      {
1355         extend_board_irq_active |= 0x02;
1406         state->extend_board_irq_active |= 0x02;
13561407         cputag_set_input_line(machine, "maincpu", INPUT_LINE_IRQ1, ASSERT_LINE);
13571408      }
13581409      else
r10427r10428
13601411   }
13611412   else
13621413   {
1363      if ((extend_board_irq_enable & 0x01) == 0 && value != CLEAR_LINE)
1414      if ((state->extend_board_irq_enable & 0x01) == 0 && value != CLEAR_LINE)
13641415      {
1365         extend_board_irq_active |= 0x01;
1416         state->extend_board_irq_active |= 0x01;
13661417         cputag_set_input_line(machine, "maincpu", INPUT_LINE_IRQ1, ASSERT_LINE);
13671418      }
13681419      else
r10427r10428
13701421   }
13711422}
13721423
1373static int keyboard_state[2] = { 0, 0 };
13741424
13751425static const int keyboard_notes[24] =
13761426{
r10427r10428
14021452
14031453static TIMER_CALLBACK( keyboard_timer_callback )
14041454{
1455   firebeat_state *state = machine->driver_data<firebeat_state>();
14051456   static const int kb_uart_channel[2] = { 1, 0 };
14061457   static const char *const keynames[] = { "KEYBOARD_P1", "KEYBOARD_P2" };
14071458   int keyboard;
r10427r10428
14121463      UINT32 kbstate = input_port_read(machine, keynames[keyboard]);
14131464      int uart_channel = kb_uart_channel[keyboard];
14141465
1415      if (kbstate != keyboard_state[keyboard])
1466      if (kbstate != state->keyboard_state[keyboard])
14161467      {
14171468         for (i=0; i < 24; i++)
14181469         {
14191470            int kbnote = keyboard_notes[i];
14201471
1421            if ((keyboard_state[keyboard] & (1 << i)) != 0 && (kbstate & (1 << i)) == 0)
1472            if ((state->keyboard_state[keyboard] & (1 << i)) != 0 && (kbstate & (1 << i)) == 0)
14221473            {
14231474               // key was on, now off -> send Note Off message
14241475               pc16552d_rx_data(machine, 1, uart_channel, 0x80);
14251476               pc16552d_rx_data(machine, 1, uart_channel, kbnote);
14261477               pc16552d_rx_data(machine, 1, uart_channel, 0x7f);
14271478            }
1428            else if ((keyboard_state[keyboard] & (1 << i)) == 0 && (kbstate & (1 << i)) != 0)
1479            else if ((state->keyboard_state[keyboard] & (1 << i)) == 0 && (kbstate & (1 << i)) != 0)
14291480            {
14301481               // key was off, now on -> send Note On message
14311482               pc16552d_rx_data(machine, 1, uart_channel, 0x90);
r10427r10428
14401491         pc16552d_rx_data(machine, 1, uart_channel, 0xfe);
14411492      }
14421493
1443      keyboard_state[keyboard] = kbstate;
1494      state->keyboard_state[keyboard] = kbstate;
14441495   }
14451496}
14461497
r10427r10428
14541505
14551506static READ32_HANDLER( extend_board_irq_r)
14561507{
1508   firebeat_state *state = space->machine->driver_data<firebeat_state>();
14571509   UINT32 r = 0;
14581510
14591511   if (ACCESSING_BITS_24_31)
14601512   {
1461      r |= (~extend_board_irq_active) << 24;
1513      r |= (~state->extend_board_irq_active) << 24;
14621514   }
14631515
14641516   return r;
r10427r10428
14661518
14671519static WRITE32_HANDLER( extend_board_irq_w )
14681520{
1521   firebeat_state *state = space->machine->driver_data<firebeat_state>();
14691522//  printf("extend_board_irq_w: %08X, %08X, %08X\n", data, offset, mem_mask);
14701523
14711524   if (ACCESSING_BITS_24_31)
14721525   {
1473      extend_board_irq_active &= ~((data >> 24) & 0xff);
1526      state->extend_board_irq_active &= ~((data >> 24) & 0xff);
14741527
1475      extend_board_irq_enable = (data >> 24) & 0xff;
1528      state->extend_board_irq_enable = (data >> 24) & 0xff;
14761529   }
14771530}
14781531
r10427r10428
16161669
16171670/*****************************************************************************/
16181671
1619static UINT8 spu_shared_ram[0x400];
16201672
16211673static READ32_HANDLER(ppc_spu_share_r)
16221674{
1675   firebeat_state *state = space->machine->driver_data<firebeat_state>();
16231676   UINT32 r = 0;
16241677
16251678   if (ACCESSING_BITS_24_31)
16261679   {
1627      r |= spu_shared_ram[(offset * 4) + 0] << 24;
1680      r |= state->spu_shared_ram[(offset * 4) + 0] << 24;
16281681   }
16291682   if (ACCESSING_BITS_16_23)
16301683   {
1631      r |= spu_shared_ram[(offset * 4) + 1] << 16;
1684      r |= state->spu_shared_ram[(offset * 4) + 1] << 16;
16321685   }
16331686   if (ACCESSING_BITS_8_15)
16341687   {
1635      r |= spu_shared_ram[(offset * 4) + 2] <<  8;
1688      r |= state->spu_shared_ram[(offset * 4) + 2] <<  8;
16361689   }
16371690   if (ACCESSING_BITS_0_7)
16381691   {
1639      r |= spu_shared_ram[(offset * 4) + 3] <<  0;
1692      r |= state->spu_shared_ram[(offset * 4) + 3] <<  0;
16401693   }
16411694
16421695   return r;
r10427r10428
16441697
16451698static WRITE32_HANDLER(ppc_spu_share_w)
16461699{
1700   firebeat_state *state = space->machine->driver_data<firebeat_state>();
16471701   if (ACCESSING_BITS_24_31)
16481702   {
1649      spu_shared_ram[(offset * 4) + 0] = (data >> 24) & 0xff;
1703      state->spu_shared_ram[(offset * 4) + 0] = (data >> 24) & 0xff;
16501704   }
16511705   if (ACCESSING_BITS_16_23)
16521706   {
1653      spu_shared_ram[(offset * 4) + 1] = (data >> 16) & 0xff;
1707      state->spu_shared_ram[(offset * 4) + 1] = (data >> 16) & 0xff;
16541708   }
16551709   if (ACCESSING_BITS_8_15)
16561710   {
1657      spu_shared_ram[(offset * 4) + 2] = (data >>  8) & 0xff;
1711      state->spu_shared_ram[(offset * 4) + 2] = (data >>  8) & 0xff;
16581712   }
16591713   if (ACCESSING_BITS_0_7)
16601714   {
1661      spu_shared_ram[(offset * 4) + 3] = (data >>  0) & 0xff;
1715      state->spu_shared_ram[(offset * 4) + 3] = (data >>  0) & 0xff;
16621716   }
16631717}
16641718
16651719#ifdef UNUSED_FUNCTION
16661720static READ16_HANDLER(m68k_spu_share_r)
16671721{
1668   return spu_shared_ram[offset] << 8;
1722   firebeat_state *state = space->machine->driver_data<firebeat_state>();
1723   return state->spu_shared_ram[offset] << 8;
16691724}
16701725
16711726static WRITE16_HANDLER(m68k_spu_share_w)
16721727{
1673   spu_shared_ram[offset] = (data >> 8) & 0xff;
1728   firebeat_state *state = space->machine->driver_data<firebeat_state>();
1729   state->spu_shared_ram[offset] = (data >> 8) & 0xff;
16741730}
16751731#endif
16761732
r10427r10428
16811737
16821738/*****************************************************************************/
16831739
1684static UINT32 *work_ram;
16851740static MACHINE_START( firebeat )
16861741{
1742   firebeat_state *state = machine->driver_data<firebeat_state>();
16871743   /* set conservative DRC options */
16881744   ppcdrc_set_options(machine->device("maincpu"), PPCDRC_COMPATIBLE_OPTIONS);
16891745
16901746   /* configure fast RAM regions for DRC */
1691   ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x01ffffff, FALSE, work_ram);
1747   ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x01ffffff, FALSE, state->work_ram);
16921748
1693   flash[0] = machine->device<fujitsu_29f016a_device>("flash0");
1694   flash[1] = machine->device<fujitsu_29f016a_device>("flash1");
1695   flash[2] = machine->device<fujitsu_29f016a_device>("flash2");
1749   state->flash[0] = machine->device<fujitsu_29f016a_device>("flash0");
1750   state->flash[1] = machine->device<fujitsu_29f016a_device>("flash1");
1751   state->flash[2] = machine->device<fujitsu_29f016a_device>("flash2");
16961752}
16971753
16981754static ADDRESS_MAP_START( firebeat_map, ADDRESS_SPACE_PROGRAM, 32 )
1699   AM_RANGE(0x00000000, 0x01ffffff) AM_RAM AM_BASE(&work_ram)
1755   AM_RANGE(0x00000000, 0x01ffffff) AM_RAM AM_BASE_MEMBER(firebeat_state, work_ram)
17001756   AM_RANGE(0x70000000, 0x70000fff) AM_READWRITE(midi_uart_r, midi_uart_w)
17011757   AM_RANGE(0x70006000, 0x70006003) AM_WRITE(extend_board_irq_w)
17021758   AM_RANGE(0x70008000, 0x7000800f) AM_READ(keyboard_wheel_r)
r10427r10428
17281784
17291785static READ8_DEVICE_HANDLER( soundram_r )
17301786{
1787   firebeat_state *state = device->machine->driver_data<firebeat_state>();
17311788   if (offset >= 0 && offset < 0x200000)
17321789   {
1733      return flash[1]->read(offset & 0x1fffff);
1790      return state->flash[1]->read(offset & 0x1fffff);
17341791   }
17351792   else if (offset >= 0x200000 && offset < 0x400000)
17361793   {
1737      return flash[2]->read(offset & 0x1fffff);
1794      return state->flash[2]->read(offset & 0x1fffff);
17381795   }
17391796   return 0;
17401797}
r10427r10428
18971954
18981955static MACHINE_RESET( firebeat )
18991956{
1957   firebeat_state *state = machine->driver_data<firebeat_state>();
19001958   void *cd;
19011959   int i;
19021960   UINT8 *sound = machine->region("ymz")->base();
19031961
19041962   for (i=0; i < 0x200000; i++)
19051963   {
1906      sound[i] = flash[1]->read(i);
1907      sound[i+0x200000] = flash[2]->read(i);
1964      sound[i] = state->flash[1]->read(i);
1965      sound[i+0x200000] = state->flash[2]->read(i);
19081966   }
19091967
1910   SCSIGetDevice( atapi_device_data[1], &cd );
1968   SCSIGetDevice( state->atapi_device_data[1], &cd );
19111969   cdda_set_cdrom(machine->device("cdda"), cd);
19121970}
19131971
1914static MACHINE_CONFIG_START( firebeat, driver_device )
1972static MACHINE_CONFIG_START( firebeat, firebeat_state )
19151973
19161974   /* basic machine hardware */
19171975   MCFG_CPU_ADD("maincpu", PPC403GCX, 66000000)
r10427r10428
19552013
19562014MACHINE_CONFIG_END
19572015
1958static MACHINE_CONFIG_START( firebeat2, driver_device )
2016static MACHINE_CONFIG_START( firebeat2, firebeat_state )
19592017
19602018   /* basic machine hardware */
19612019   MCFG_CPU_ADD("maincpu", PPC403GCX, 66000000)
r10427r10428
20152073/*****************************************************************************/
20162074/* Security dongle is a Dallas DS1411 RS232 Adapter with a DS1991 Multikey iButton */
20172075
2018typedef struct
2019{
2020   UINT8 identifier[8];
2021   UINT8 password[8];
2022   UINT8 data[0x30];
2023} IBUTTON_SUBKEY;
2024
2025typedef struct
2026{
2027   IBUTTON_SUBKEY subkey[3];
2028} IBUTTON;
2029
20302076enum
20312077{
20322078   DS1991_STATE_NORMAL,
20332079   DS1991_STATE_READ_SUBKEY,
20342080};
20352081
2036static IBUTTON ibutton;
20372082
2038static int ibutton_state = DS1991_STATE_NORMAL;
2039static int ibutton_read_subkey_ptr = 0;
20402083
2041static UINT8 ibutton_subkey_data[0x40];
20422084
2043static void set_ibutton(UINT8 *data)
2085static void set_ibutton(firebeat_state *state, UINT8 *data)
20442086{
20452087   int i, j;
20462088
r10427r10428
20492091      // identifier
20502092      for (j=0; j < 8; j++)
20512093      {
2052         ibutton.subkey[i].identifier[j] = *data++;
2094         state->ibutton.subkey[i].identifier[j] = *data++;
20532095      }
20542096
20552097      // password
20562098      for (j=0; j < 8; j++)
20572099      {
2058         ibutton.subkey[i].password[j] = *data++;
2100         state->ibutton.subkey[i].password[j] = *data++;
20592101      }
20602102
20612103      // data
20622104      for (j=0; j < 48; j++)
20632105      {
2064         ibutton.subkey[i].data[j] = *data++;
2106         state->ibutton.subkey[i].data[j] = *data++;
20652107      }
20662108   }
20672109}
20682110
2069static int ibutton_w(UINT8 data)
2111static int ibutton_w(running_machine *machine, UINT8 data)
20702112{
2113   firebeat_state *state = machine->driver_data<firebeat_state>();
20712114   int r = -1;
20722115
2073   switch (ibutton_state)
2116   switch (state->ibutton_state)
20742117   {
20752118      case DS1991_STATE_NORMAL:
20762119      {
r10427r10428
20992142            case 0x66:         // DS1991 Read SubKey
21002143            {
21012144               r = 0x66;
2102               ibutton_state = DS1991_STATE_READ_SUBKEY;
2103               ibutton_read_subkey_ptr = 0;
2145               state->ibutton_state = DS1991_STATE_READ_SUBKEY;
2146               state->ibutton_read_subkey_ptr = 0;
21042147               break;
21052148            }
21062149            case 0xcc:         // DS1991 skip rom
21072150            {
21082151               r = 0xcc;
2109               ibutton_state = DS1991_STATE_NORMAL;
2152               state->ibutton_state = DS1991_STATE_NORMAL;
21102153               break;
21112154            }
21122155            default:
r10427r10428
21202163
21212164      case DS1991_STATE_READ_SUBKEY:
21222165      {
2123         if (ibutton_read_subkey_ptr == 0)      // Read SubKey, 2nd command byte
2166         if (state->ibutton_read_subkey_ptr == 0)      // Read SubKey, 2nd command byte
21242167         {
21252168            int subkey = (data >> 6) & 0x3;
21262169      //      printf("iButton SubKey %d\n", subkey);
r10427r10428
21282171
21292172            if (subkey < 3)
21302173            {
2131               memcpy(&ibutton_subkey_data[0],  ibutton.subkey[subkey].identifier, 8);
2132               memcpy(&ibutton_subkey_data[8],  ibutton.subkey[subkey].password, 8);
2133               memcpy(&ibutton_subkey_data[16], ibutton.subkey[subkey].data, 0x30);
2174               memcpy(&state->ibutton_subkey_data[0],  state->ibutton.subkey[subkey].identifier, 8);
2175               memcpy(&state->ibutton_subkey_data[8],  state->ibutton.subkey[subkey].password, 8);
2176               memcpy(&state->ibutton_subkey_data[16], state->ibutton.subkey[subkey].data, 0x30);
21342177            }
21352178            else
21362179            {
2137               memset(&ibutton_subkey_data[0], 0, 0x40);
2180               memset(&state->ibutton_subkey_data[0], 0, 0x40);
21382181            }
21392182         }
2140         else if (ibutton_read_subkey_ptr == 1)   // Read SubKey, 3rd command byte
2183         else if (state->ibutton_read_subkey_ptr == 1)   // Read SubKey, 3rd command byte
21412184         {
21422185            r = data;
21432186         }
21442187         else
21452188         {
2146            r = ibutton_subkey_data[ibutton_read_subkey_ptr-2];
2189            r = state->ibutton_subkey_data[state->ibutton_read_subkey_ptr-2];
21472190         }
2148         ibutton_read_subkey_ptr++;
2149         if (ibutton_read_subkey_ptr >= 0x42)
2191         state->ibutton_read_subkey_ptr++;
2192         if (state->ibutton_read_subkey_ptr >= 0x42)
21502193         {
2151            ibutton_state = DS1991_STATE_NORMAL;
2194            state->ibutton_state = DS1991_STATE_NORMAL;
21522195         }
21532196         break;
21542197      }
r10427r10428
21592202
21602203static void security_w(device_t *device, UINT8 data)
21612204{
2162   int r = ibutton_w(data);
2205   int r = ibutton_w(device->machine, data);
21632206   if (r >= 0)
21642207      ppc4xx_spu_receive_byte(device->machine->device("maincpu"), r);
21652208}
r10427r10428
21792222
21802223static void init_firebeat(running_machine *machine)
21812224{
2225   firebeat_state *state = machine->driver_data<firebeat_state>();
21822226   UINT8 *rom = machine->region("user2")->base();
21832227
21842228   atapi_init(machine);
r10427r10428
21862230   pc16552d_init(machine, 0, 19660800, comm_uart_irq_callback, 0);      // Network UART
21872231   pc16552d_init(machine, 1, 24000000, midi_uart_irq_callback, 0);      // MIDI UART
21882232
2189   extend_board_irq_enable = 0x3f;
2190   extend_board_irq_active = 0x00;
2233   state->extend_board_irq_enable = 0x3f;
2234   state->extend_board_irq_active = 0x00;
21912235
2192   cur_cab_data = cab_data;
2236   state->cur_cab_data = cab_data;
21932237
21942238   ppc4xx_spu_set_tx_handler(machine->device("maincpu"), security_w);
21952239
2196   set_ibutton(rom);
2240   set_ibutton(state, rom);
21972241
21982242   init_lights(machine, NULL, NULL, NULL);
21992243}
r10427r10428
22062250
22072251static DRIVER_INIT(ppd)
22082252{
2253   firebeat_state *state = machine->driver_data<firebeat_state>();
22092254   init_firebeat(machine);
22102255   init_lights(machine, lamp_output_ppp_w, lamp_output2_ppp_w, lamp_output3_ppp_w);
22112256
2212   cur_cab_data = ppd_cab_data;
2257   state->cur_cab_data = ppd_cab_data;
22132258}
22142259
22152260static void init_keyboard(running_machine *machine)
22162261{
2262   firebeat_state *state = machine->driver_data<firebeat_state>();
22172263   // set keyboard timer
2218   keyboard_timer = machine->scheduler().timer_alloc(FUNC(keyboard_timer_callback));
2219   keyboard_timer->adjust(attotime::from_msec(10), 0, attotime::from_msec(10));
2264   state->keyboard_timer = machine->scheduler().timer_alloc(FUNC(keyboard_timer_callback));
2265   state->keyboard_timer->adjust(attotime::from_msec(10), 0, attotime::from_msec(10));
22202266}
22212267
22222268static DRIVER_INIT(kbm)
22232269{
2270   firebeat_state *state = machine->driver_data<firebeat_state>();
22242271   init_firebeat(machine);
22252272   init_lights(machine, lamp_output_kbm_w, NULL, NULL);
22262273
22272274   init_keyboard(machine);
22282275
2229   cur_cab_data = kbm_cab_data;
2276   state->cur_cab_data = kbm_cab_data;
22302277}
22312278
22322279
src/mame/drivers/deco_ld.c
r10427r10428
114114      : driver_device(machine, config) { }
115115
116116   UINT8 *videoram;
117   UINT8 vram_bank;
118   device_t *laserdisc;
119   UINT8 laserdisc_data;
120   int nmimask;
117121};
118122
119123
120static UINT8 vram_bank;
121static device_t *laserdisc;
122static UINT8 laserdisc_data;
123124
124125static VIDEO_UPDATE( rblaster )
125126{
r10427r10428
135136      for (x=0;x<32;x++)
136137      {
137138         int tile = videoram[count];
138         int colour = (vram_bank & 0x7);
139         int colour = (state->vram_bank & 0x7);
139140         drawgfx_opaque(bitmap,cliprect,gfx,tile,colour,0,0,x*8,y*8);
140141
141142         count++;
r10427r10428
155156
156157static WRITE8_HANDLER( rblaster_vram_bank_w )
157158{
158   vram_bank = data;
159   deco_ld_state *state = space->machine->driver_data<deco_ld_state>();
160   state->vram_bank = data;
159161}
160162
161163static READ8_HANDLER( laserdisc_r )
162164{
163   UINT8 result = laserdisc_data_r(laserdisc);
165   deco_ld_state *state = space->machine->driver_data<deco_ld_state>();
166   UINT8 result = laserdisc_data_r(state->laserdisc);
164167   mame_printf_debug("laserdisc_r = %02X\n", result);
165168   return result;
166169}
r10427r10428
168171
169172static WRITE8_HANDLER( laserdisc_w )
170173{
171   laserdisc_data = data;
174   deco_ld_state *state = space->machine->driver_data<deco_ld_state>();
175   state->laserdisc_data = data;
172176}
173177
174178static READ8_HANDLER( test_r )
r10427r10428
229233ADDRESS_MAP_END
230234
231235/* sound arrangement is pratically identical to Zero Target. */
232static int nmimask;
233236
234//static WRITE8_HANDLER( nmimask_w ) { nmimask = data & 0x80; }
237#ifdef UNUSED_FUNCTION
238static WRITE8_HANDLER( nmimask_w )
239{
240   deco_ld_state *state = space->machine->driver_data<deco_ld_state>();
241   state->nmimask = data & 0x80;
242}
243#endif
235244
236static INTERRUPT_GEN ( sound_interrupt ) { if (!nmimask) cpu_set_input_line(device, INPUT_LINE_NMI, PULSE_LINE); }
245static INTERRUPT_GEN ( sound_interrupt ) {
246   deco_ld_state *state = device->machine->driver_data<deco_ld_state>(); if (!state->nmimask) cpu_set_input_line(device, INPUT_LINE_NMI, PULSE_LINE); }
237247
238248
239249static ADDRESS_MAP_START( rblaster_sound_map, ADDRESS_SPACE_PROGRAM, 8 )
r10427r10428
497507
498508static MACHINE_START( rblaster )
499509{
500   laserdisc = machine->device("laserdisc");
510   deco_ld_state *state = machine->driver_data<deco_ld_state>();
511   state->laserdisc = machine->device("laserdisc");
501512}
502513
503514static MACHINE_CONFIG_START( rblaster, deco_ld_state )
src/mame/drivers/progolf.c
r10427r10428
6363      : driver_device(machine, config) { }
6464
6565   UINT8 *videoram;
66   UINT8 char_pen;
67   UINT8 char_pen_vreg;
68   UINT8 *fg_fb;
69   UINT8 *fbram;
70   UINT8 scrollx_hi;
71   UINT8 scrollx_lo;
72   UINT8 gfx_switch;
73   UINT8 sound_cmd;
6674};
6775
6876
69static UINT8 char_pen,char_pen_vreg;
70static UINT8 *progolf_fg_fb;
71static UINT8 *progolf_fbram;
72static UINT8 scrollx_hi;
73static UINT8 scrollx_lo;
74static UINT8 progolf_gfx_switch;
7577
76static UINT8 sound_cmd;
7778
7879static VIDEO_START( progolf )
7980{
8081   progolf_state *state = machine->driver_data<progolf_state>();
81   scrollx_hi = 0;
82   scrollx_lo = 0;
82   state->scrollx_hi = 0;
83   state->scrollx_lo = 0;
8384
84   progolf_fg_fb = auto_alloc_array(machine, UINT8, 0x2000*8);
85   state->fg_fb = auto_alloc_array(machine, UINT8, 0x2000*8);
8586   state->videoram = auto_alloc_array(machine, UINT8, 0x1000);
8687}
8788
r10427r10428
9394   int count,color,x,y,xi,yi;
9495
9596   {
96      int scroll = (scrollx_lo | ((scrollx_hi & 0x03) << 8));
97      int scroll = (state->scrollx_lo | ((state->scrollx_hi & 0x03) << 8));
9798
9899      count = 0;
99100
r10427r10428
124125            {
125126               for (xi=0;xi<8;xi++)
126127               {
127                  color = progolf_fg_fb[(xi+yi*8)+count*0x40];
128                  color = state->fg_fb[(xi+yi*8)+count*0x40];
128129
129130                  if((x+yi) <= cliprect->max_x && (256-y+xi) <= cliprect->max_y && color != 0)
130131                     *BITMAP_ADDR16(bitmap, x+yi, 256-y+xi) = screen->machine->pens[(color & 0x7)];
r10427r10428
141142
142143static WRITE8_HANDLER( progolf_charram_w )
143144{
145   progolf_state *state = space->machine->driver_data<progolf_state>();
144146   int i;
145   progolf_fbram[offset] = data;
147   state->fbram[offset] = data;
146148
147   if(char_pen == 7)
149   if(state->char_pen == 7)
148150   {
149151      for(i=0;i<8;i++)
150         progolf_fg_fb[offset*8+i] = 0;
152         state->fg_fb[offset*8+i] = 0;
151153   }
152154   else
153155   {
154156      for(i=0;i<8;i++)
155157      {
156         if(progolf_fg_fb[offset*8+i] == char_pen)
157            progolf_fg_fb[offset*8+i] = data & (1<<(7-i)) ? char_pen : 0;
158         if(state->fg_fb[offset*8+i] == state->char_pen)
159            state->fg_fb[offset*8+i] = data & (1<<(7-i)) ? state->char_pen : 0;
158160         else
159            progolf_fg_fb[offset*8+i] = data & (1<<(7-i)) ? progolf_fg_fb[offset*8+i]|char_pen : progolf_fg_fb[offset*8+i];
161            state->fg_fb[offset*8+i] = data & (1<<(7-i)) ? state->fg_fb[offset*8+i]|state->char_pen : state->fg_fb[offset*8+i];
160162      }
161163   }
162164}
163165
164166static WRITE8_HANDLER( progolf_char_vregs_w )
165167{
166   char_pen = data & 0x07;
167   progolf_gfx_switch = data & 0xf0;
168   char_pen_vreg = data & 0x30;
168   progolf_state *state = space->machine->driver_data<progolf_state>();
169   state->char_pen = data & 0x07;
170   state->gfx_switch = data & 0xf0;
171   state->char_pen_vreg = data & 0x30;
169172}
170173
171174static WRITE8_HANDLER( progolf_scrollx_lo_w )
172175{
173   scrollx_lo = data;
176   progolf_state *state = space->machine->driver_data<progolf_state>();
177   state->scrollx_lo = data;
174178}
175179
176180static WRITE8_HANDLER( progolf_scrollx_hi_w )
177181{
178   scrollx_hi = data;
182   progolf_state *state = space->machine->driver_data<progolf_state>();
183   state->scrollx_hi = data;
179184}
180185
181186static WRITE8_HANDLER( progolf_flip_screen_w )
r10427r10428
187192
188193static WRITE8_HANDLER( audio_command_w )
189194{
190   sound_cmd = data;
195   progolf_state *state = space->machine->driver_data<progolf_state>();
196   state->sound_cmd = data;
191197   cputag_set_input_line(space->machine, "audiocpu", 0, ASSERT_LINE);
192198}
193199
194200static READ8_HANDLER( audio_command_r )
195201{
202   progolf_state *state = space->machine->driver_data<progolf_state>();
196203   cputag_set_input_line(space->machine, "audiocpu", 0, CLEAR_LINE);
197   return sound_cmd;
204   return state->sound_cmd;
198205}
199206
200207static READ8_HANDLER( progolf_videoram_r )
r10427r10428
205212
206213   if (offset >= 0x0800)
207214   {
208      if      (progolf_gfx_switch == 0x50)
215      if      (state->gfx_switch == 0x50)
209216         return gfx_rom[offset];
210      else if (progolf_gfx_switch == 0x60)
217      else if (state->gfx_switch == 0x60)
211218         return gfx_rom[offset + 0x1000];
212      else if (progolf_gfx_switch == 0x70)
219      else if (state->gfx_switch == 0x70)
213220         return gfx_rom[offset + 0x2000];
214221      else
215222         return videoram[offset];
216223   } else {
217      if      (progolf_gfx_switch == 0x10)
224      if      (state->gfx_switch == 0x10)
218225         return gfx_rom[offset];
219      else if (progolf_gfx_switch == 0x20)
226      else if (state->gfx_switch == 0x20)
220227         return gfx_rom[offset + 0x1000];
221      else if (progolf_gfx_switch == 0x30)
228      else if (state->gfx_switch == 0x30)
222229         return gfx_rom[offset + 0x2000];
223230      else
224231         return videoram[offset];
r10427r10428
229236{
230237   progolf_state *state = space->machine->driver_data<progolf_state>();
231238   UINT8 *videoram = state->videoram;
232   //if(progolf_gfx_switch & 0x40)
239   //if(state->gfx_switch & 0x40)
233240   videoram[offset] = data;
234241}
235242
236243static ADDRESS_MAP_START( main_cpu, ADDRESS_SPACE_PROGRAM, 8 )
237244   AM_RANGE(0x0000, 0x5fff) AM_RAM
238   AM_RANGE(0x6000, 0x7fff) AM_RAM_WRITE(progolf_charram_w) AM_BASE(&progolf_fbram)
245   AM_RANGE(0x6000, 0x7fff) AM_RAM_WRITE(progolf_charram_w) AM_BASE_MEMBER(progolf_state, fbram)
239246   AM_RANGE(0x8000, 0x8fff) AM_READWRITE(progolf_videoram_r,progolf_videoram_w)
240247   AM_RANGE(0x9000, 0x9000) AM_READ_PORT("IN2") AM_WRITE(progolf_char_vregs_w)
241248   AM_RANGE(0x9200, 0x9200) AM_READ_PORT("P1") AM_WRITE(progolf_scrollx_hi_w) //p1 inputs
src/mame/drivers/segag80v.c
r10427r10428
154154
155155/*************************************
156156 *
157 *  Global variables
158 *
159 *************************************/
160
161static UINT8 *mainram;
162static UINT8 has_usb;
163
164static UINT8 mult_data[2];
165static UINT16 mult_result;
166
167static UINT8 spinner_select;
168static UINT8 spinner_sign;
169static UINT8 spinner_count;
170
171
172
173/*************************************
174 *
175157 *  Machine setup and config
176158 *
177159 *************************************/
r10427r10428
186168
187169static MACHINE_START( g80v )
188170{
171   segag80v_state *state = machine->driver_data<segag80v_state>();
189172   /* register for save states */
190   state_save_register_global_array(machine, mult_data);
191   state_save_register_global(machine, mult_result);
192   state_save_register_global(machine, spinner_select);
193   state_save_register_global(machine, spinner_sign);
194   state_save_register_global(machine, spinner_count);
173   state_save_register_global_array(machine, state->mult_data);
174   state_save_register_global(machine, state->mult_result);
175   state_save_register_global(machine, state->spinner_select);
176   state_save_register_global(machine, state->spinner_sign);
177   state_save_register_global(machine, state->spinner_count);
195178}
196179
197180
198181static MACHINE_RESET( g80v )
199182{
183   segag80v_state *state = machine->driver_data<segag80v_state>();
200184   /* if we have a Universal Sound Board, reset it here */
201   if (has_usb)
185   if (state->has_usb)
202186      sega_usb_reset(machine, 0x10);
203187}
204188
r10427r10428
221205   return (offset & 0xff00) | (*sega_decrypt)(pc, space->read_byte(pc + 1));
222206}
223207
224static WRITE8_HANDLER( mainram_w ) { mainram[decrypt_offset(space, offset)] = data; }
208static WRITE8_HANDLER( mainram_w ) {
209   segag80v_state *state = space->machine->driver_data<segag80v_state>(); state->mainram[decrypt_offset(space, offset)] = data; }
225210static WRITE8_HANDLER( usb_ram_w ) { sega_usb_ram_w(space, decrypt_offset(space, offset), data); }
226static WRITE8_HANDLER( vectorram_w ) { segag80v_vectorram[decrypt_offset(space, offset)] = data; }
211static WRITE8_HANDLER( vectorram_w ) {
212   segag80v_state *state = space->machine->driver_data<segag80v_state>(); state->vectorram[decrypt_offset(space, offset)] = data; }
227213
228214
229215
r10427r10428
267253
268254static WRITE8_HANDLER( spinner_select_w )
269255{
270   spinner_select = data;
256   segag80v_state *state = space->machine->driver_data<segag80v_state>();
257   state->spinner_select = data;
271258}
272259
273260
274261static READ8_HANDLER( spinner_input_r )
275262{
263   segag80v_state *state = space->machine->driver_data<segag80v_state>();
276264   INT8 delta;
277265
278   if (spinner_select & 1)
266   if (state->spinner_select & 1)
279267      return input_port_read(space->machine, "FC");
280268
281269/*
r10427r10428
289277   delta = input_port_read(space->machine, "SPINNER");
290278   if (delta != 0)
291279   {
292      spinner_sign = (delta >> 7) & 1;
293      spinner_count += abs(delta);
280      state->spinner_sign = (delta >> 7) & 1;
281      state->spinner_count += abs(delta);
294282   }
295   return ~((spinner_count << 1) | spinner_sign);
283   return ~((state->spinner_count << 1) | state->spinner_sign);
296284}
297285
298286
r10427r10428
311299
312300static READ8_HANDLER( elim4_input_r )
313301{
302   segag80v_state *state = space->machine->driver_data<segag80v_state>();
314303   UINT8 result = 0;
315304
316305   /* bit 3 enables demux */
317   if (spinner_select & 8)
306   if (state->spinner_select & 8)
318307   {
319308      /* Demux bit 0-2. Only 6 and 7 are connected */
320      switch (spinner_select & 7)
309      switch (state->spinner_select & 7)
321310      {
322311         case 6:
323312            /* player 3 & 4 controls */
r10427r10428
344333
345334static WRITE8_HANDLER( multiply_w )
346335{
347   mult_data[offset] = data;
336   segag80v_state *state = space->machine->driver_data<segag80v_state>();
337   state->mult_data[offset] = data;
348338   if (offset == 1)
349      mult_result = mult_data[0] * mult_data[1];
339      state->mult_result = state->mult_data[0] * state->mult_data[1];
350340}
351341
352342
353343static READ8_HANDLER( multiply_r )
354344{
355   UINT8 result = mult_result;
356   mult_result >>= 8;
345   segag80v_state *state = space->machine->driver_data<segag80v_state>();
346   UINT8 result = state->mult_result;
347   state->mult_result >>= 8;
357348   return result;
358349}
359350
r10427r10428
392383static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 8 )
393384   AM_RANGE(0x0000, 0x07ff) AM_ROM      /* CPU board ROM */
394385   AM_RANGE(0x0800, 0xbfff) AM_ROM      /* PROM board ROM area */
395   AM_RANGE(0xc800, 0xcfff) AM_RAM_WRITE(mainram_w) AM_BASE(&mainram)
396   AM_RANGE(0xe000, 0xefff) AM_RAM_WRITE(vectorram_w) AM_BASE(&segag80v_vectorram) AM_SIZE(&segag80v_vectorram_size)
386   AM_RANGE(0xc800, 0xcfff) AM_RAM_WRITE(mainram_w) AM_BASE_MEMBER(segag80v_state, mainram)
387   AM_RANGE(0xe000, 0xefff) AM_RAM_WRITE(vectorram_w) AM_BASE_MEMBER(segag80v_state, vectorram) AM_SIZE_MEMBER(segag80v_state, vectorram_size)
397388ADDRESS_MAP_END
398389
399390
r10427r10428
909900 *
910901 *************************************/
911902
912static MACHINE_CONFIG_START( g80v_base, driver_device )
903static MACHINE_CONFIG_START( g80v_base, segag80v_state )
913904
914905   /* basic machine hardware */
915906   MCFG_CPU_ADD("maincpu", Z80, CPU_CLOCK/2)
r10427r10428
13101301
13111302static DRIVER_INIT( elim2 )
13121303{
1304   segag80v_state *state = machine->driver_data<segag80v_state>();
13131305   address_space *iospace = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_IO);
13141306
13151307   /* configure security */
13161308   sega_security(70);
13171309
13181310   /* configure sound */
1319   has_usb = FALSE;
1311   state->has_usb = FALSE;
13201312   memory_install_write8_handler(iospace, 0x3e, 0x3e, 0, 0, elim1_sh_w);
13211313   memory_install_write8_handler(iospace, 0x3f, 0x3f, 0, 0, elim2_sh_w);
13221314}
r10427r10428
13241316
13251317static DRIVER_INIT( elim4 )
13261318{
1319   segag80v_state *state = machine->driver_data<segag80v_state>();
13271320   address_space *iospace = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_IO);
13281321
13291322   /* configure security */
13301323   sega_security(76);
13311324
13321325   /* configure sound */
1333   has_usb = FALSE;
1326   state->has_usb = FALSE;
13341327   memory_install_write8_handler(iospace, 0x3e, 0x3e, 0, 0, elim1_sh_w);
13351328   memory_install_write8_handler(iospace, 0x3f, 0x3f, 0, 0, elim2_sh_w);
13361329
r10427r10428
13421335
13431336static DRIVER_INIT( spacfury )
13441337{
1338   segag80v_state *state = machine->driver_data<segag80v_state>();
13451339   address_space *iospace = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_IO);
13461340
13471341   /* configure security */
13481342   sega_security(64);
13491343
13501344   /* configure sound */
1351   has_usb = FALSE;
1345   state->has_usb = FALSE;
13521346   memory_install_write8_handler(iospace, 0x38, 0x38, 0, 0, sega_speech_data_w);
13531347   memory_install_write8_handler(iospace, 0x3b, 0x3b, 0, 0, sega_speech_control_w);
13541348   memory_install_write8_handler(iospace, 0x3e, 0x3e, 0, 0, spacfury1_sh_w);
r10427r10428
13581352
13591353static DRIVER_INIT( zektor )
13601354{
1355   segag80v_state *state = machine->driver_data<segag80v_state>();
13611356   address_space *iospace = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_IO);
13621357   device_t *ay = machine->device("aysnd");
13631358
r10427r10428
13651360   sega_security(82);
13661361
13671362   /* configure sound */
1368   has_usb = FALSE;
1363   state->has_usb = FALSE;
13691364   memory_install_write8_handler(iospace, 0x38, 0x38, 0, 0, sega_speech_data_w);
13701365   memory_install_write8_handler(iospace, 0x3b, 0x3b, 0, 0, sega_speech_control_w);
13711366   memory_install_write8_device_handler(iospace, ay, 0x3c, 0x3d, 0, 0, ay8910_address_data_w);
r10427r10428
13801375
13811376static DRIVER_INIT( tacscan )
13821377{
1378   segag80v_state *state = machine->driver_data<segag80v_state>();
13831379   address_space *pgmspace = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
13841380   address_space *iospace = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_IO);
13851381
r10427r10428
13871383   sega_security(76);
13881384
13891385   /* configure sound */
1390   has_usb = TRUE;
1386   state->has_usb = TRUE;
13911387   memory_install_readwrite8_handler(iospace, 0x3f, 0x3f, 0, 0, sega_usb_status_r, sega_usb_data_w);
13921388   memory_install_readwrite8_handler(pgmspace, 0xd000, 0xdfff, 0, 0, sega_usb_ram_r, usb_ram_w);
13931389
r10427r10428
13991395
14001396static DRIVER_INIT( startrek )
14011397{
1398   segag80v_state *state = machine->driver_data<segag80v_state>();
14021399   address_space *pgmspace = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
14031400   address_space *iospace = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_IO);
14041401
r10427r10428
14061403   sega_security(64);
14071404
14081405   /* configure sound */
1409   has_usb = TRUE;
1406   state->has_usb = TRUE;
14101407   memory_install_write8_handler(iospace, 0x38, 0x38, 0, 0, sega_speech_data_w);
14111408   memory_install_write8_handler(iospace, 0x3b, 0x3b, 0, 0, sega_speech_control_w);
14121409
src/mame/drivers/bfmsys85.c
r10427r10428
6767#include "sound/ay8910.h"
6868#include "machine/nvram.h"
6969
70
71class bfmsys85_state : public driver_device
72{
73public:
74   bfmsys85_state(running_machine &machine, const driver_device_config_base &config)
75      : driver_device(machine, config) { }
76
77   int mmtr_latch;
78   int triac_latch;
79   int vfd_latch;
80   int irq_status;
81   int optic_pattern;
82   int locked;
83   int is_timer_enabled;
84   int reel_changed;
85   int coin_inhibits;
86   int mux_output_strobe;
87   int mux_input_strobe;
88   int mux_input;
89   UINT8 Lamps[128];
90   UINT8 Inputs[64];
91   UINT8 sys85_data_line_r;
92   UINT8 sys85_data_line_t;
93};
94
95
7096#define VFD_RESET  0x20
7197#define VFD_CLOCK1 0x80
7298#define VFD_DATA   0x40
r10427r10428
78104
79105// local vars /////////////////////////////////////////////////////////////
80106
81static int mmtr_latch;        // mechanical meter latch
82static int triac_latch;        // payslide triac latch
83static int vfd_latch;        // vfd latch
84static int irq_status;        // custom chip IRQ status
85static int optic_pattern;     // reel optics
86static int locked;           // hardware lock/unlock status (0=unlocked)
87static int is_timer_enabled;
88static int reel_changed;
89static int coin_inhibits;
90static int mux_output_strobe;
91static int mux_input_strobe;
92static int mux_input;
93107
94108// user interface stuff ///////////////////////////////////////////////////
95109
96static UINT8 Lamps[128];        // 128 multiplexed lamps
97static UINT8 Inputs[64];        // ??  multiplexed inputs
98110
99111///////////////////////////////////////////////////////////////////////////
100112// Serial Communications (Where does this go?) ////////////////////////////
101113///////////////////////////////////////////////////////////////////////////
102114
103static UINT8 sys85_data_line_r;
104static UINT8 sys85_data_line_t;
105115
106116static READ_LINE_DEVICE_HANDLER( sys85_data_r )
107117{
108   return sys85_data_line_r;
118   bfmsys85_state *state = device->machine->driver_data<bfmsys85_state>();
119   return state->sys85_data_line_r;
109120}
110121
111122static WRITE_LINE_DEVICE_HANDLER( sys85_data_w )
112123{
113   sys85_data_line_t = state;
124   bfmsys85_state *drvstate = device->machine->driver_data<bfmsys85_state>();
125   drvstate->sys85_data_line_t = state;
114126}
115127
116128static ACIA6850_INTERFACE( m6809_acia_if )
r10427r10428
128140
129141static MACHINE_RESET( bfm_sys85 )
130142{
131   vfd_latch         = 0;
132   mmtr_latch        = 0;
133   triac_latch       = 0;
134   irq_status        = 0;
135   is_timer_enabled  = 1;
136   coin_inhibits     = 0;
137   mux_output_strobe = 0;
138   mux_input_strobe  = 0;
139   mux_input         = 0;
143   bfmsys85_state *state = machine->driver_data<bfmsys85_state>();
144   state->vfd_latch         = 0;
145   state->mmtr_latch        = 0;
146   state->triac_latch       = 0;
147   state->irq_status        = 0;
148   state->is_timer_enabled  = 1;
149   state->coin_inhibits     = 0;
150   state->mux_output_strobe = 0;
151   state->mux_input_strobe  = 0;
152   state->mux_input         = 0;
140153
141154   ROC10937_reset(0);   // reset display1
142155
r10427r10428
149162         stepper_reset_position(i);
150163         if ( stepper_optic_state(i) ) pattern |= 1<<i;
151164      }
152   optic_pattern = pattern;
165   state->optic_pattern = pattern;
153166   }
154   locked        = 0x00; // hardware is NOT locked
167   state->locked        = 0x00; // hardware is NOT state->locked
155168}
156169
157170///////////////////////////////////////////////////////////////////////////
r10427r10428
164177
165178static INTERRUPT_GEN( timer_irq )
166179{
167   if ( is_timer_enabled )
180   bfmsys85_state *state = device->machine->driver_data<bfmsys85_state>();
181   if ( state->is_timer_enabled )
168182   {
169      irq_status = 0x01 |0x02; //0xff;
183      state->irq_status = 0x01 |0x02; //0xff;
170184      generic_pulse_irq_line(device, M6809_IRQ_LINE);
171185   }
172186}
r10427r10428
175189
176190static READ8_HANDLER( irqlatch_r )
177191{
178   int result = irq_status | 0x02;
192   bfmsys85_state *state = space->machine->driver_data<bfmsys85_state>();
193   int result = state->irq_status | 0x02;
179194
180   irq_status = 0;
195   state->irq_status = 0;
181196
182197   return result;
183198}
r10427r10428
186201
187202static WRITE8_HANDLER( reel12_w )
188203{
189   if ( stepper_update(0, data>>4) ) reel_changed |= 0x01;
190   if ( stepper_update(1, data   ) ) reel_changed |= 0x02;
204   bfmsys85_state *state = space->machine->driver_data<bfmsys85_state>();
205   if ( stepper_update(0, data>>4) ) state->reel_changed |= 0x01;
206   if ( stepper_update(1, data   ) ) state->reel_changed |= 0x02;
191207
192   if ( stepper_optic_state(0) ) optic_pattern |=  0x01;
193   else                          optic_pattern &= ~0x01;
194   if ( stepper_optic_state(1) ) optic_pattern |=  0x02;
195   else                          optic_pattern &= ~0x02;
208   if ( stepper_optic_state(0) ) state->optic_pattern |=  0x01;
209   else                          state->optic_pattern &= ~0x01;
210   if ( stepper_optic_state(1) ) state->optic_pattern |=  0x02;
211   else                          state->optic_pattern &= ~0x02;
196212   awp_draw_reel(0);
197213   awp_draw_reel(1);
198214}
r10427r10428
201217
202218static WRITE8_HANDLER( reel34_w )
203219{
204   if ( stepper_update(2, data>>4) ) reel_changed |= 0x04;
205   if ( stepper_update(3, data   ) ) reel_changed |= 0x08;
220   bfmsys85_state *state = space->machine->driver_data<bfmsys85_state>();
221   if ( stepper_update(2, data>>4) ) state->reel_changed |= 0x04;
222   if ( stepper_update(3, data   ) ) state->reel_changed |= 0x08;
206223
207   if ( stepper_optic_state(2) ) optic_pattern |=  0x04;
208   else                          optic_pattern &= ~0x04;
209   if ( stepper_optic_state(3) ) optic_pattern |=  0x08;
210   else                          optic_pattern &= ~0x08;
224   if ( stepper_optic_state(2) ) state->optic_pattern |=  0x04;
225   else                          state->optic_pattern &= ~0x04;
226   if ( stepper_optic_state(3) ) state->optic_pattern |=  0x08;
227   else                          state->optic_pattern &= ~0x08;
211228   awp_draw_reel(2);
212229   awp_draw_reel(3);
213230}
r10427r10428
218235
219236static WRITE8_HANDLER( mmtr_w )
220237{
238   bfmsys85_state *state = space->machine->driver_data<bfmsys85_state>();
221239   int i;
222   int  changed = mmtr_latch ^ data;
240   int  changed = state->mmtr_latch ^ data;
223241
224   mmtr_latch = data;
242   state->mmtr_latch = data;
225243
226244   for (i=0; i<8; i++)
227245   if ( changed & (1 << i) )   MechMtr_update(i, data & (1 << i) );
r10427r10428
232250
233251static READ8_HANDLER( mmtr_r )
234252{
235   return mmtr_latch;
253   bfmsys85_state *state = space->machine->driver_data<bfmsys85_state>();
254   return state->mmtr_latch;
236255}
237256///////////////////////////////////////////////////////////////////////////
238257
239258static WRITE8_HANDLER( vfd_w )
240259{
241   int changed = vfd_latch ^ data;
260   bfmsys85_state *state = space->machine->driver_data<bfmsys85_state>();
261   int changed = state->vfd_latch ^ data;
242262
243   vfd_latch = data;
263   state->vfd_latch = data;
244264
245265   if ( changed )
246266   {
r10427r10428
294314
295315static WRITE8_HANDLER( mux_ctrl_w )
296316{
317   bfmsys85_state *state = space->machine->driver_data<bfmsys85_state>();
297318   switch ( data & 0xF0 )
298319   {
299320      case 0x10:
r10427r10428
306327
307328      case 0x40:
308329      //logerror(" sys85 mux: read strobe");
309      mux_input_strobe = data & 0x07;
330      state->mux_input_strobe = data & 0x07;
310331
311      if ( mux_input_strobe == 5 ) Inputs[5] = 0xFF ^ optic_pattern;
332      if ( state->mux_input_strobe == 5 ) state->Inputs[5] = 0xFF ^ state->optic_pattern;
312333
313      mux_input = ~Inputs[mux_input_strobe];
334      state->mux_input = ~state->Inputs[state->mux_input_strobe];
314335      break;
315336
316337      case 0x80:
317      mux_output_strobe = data & 0x0F;
338      state->mux_output_strobe = data & 0x0F;
318339      break;
319340
320341      case 0xC0:
r10427r10428
336357
337358static WRITE8_HANDLER( mux_data_w )
338359{
360   bfmsys85_state *state = space->machine->driver_data<bfmsys85_state>();
339361   int pattern = 0x01, i,
340   off = mux_output_strobe<<4;
362   off = state->mux_output_strobe<<4;
341363
342364   for ( i = 0; i < 8; i++ )
343365   {
344      Lamps[BFM_strcnv85[off]] = data & pattern ? 1 : 0;
366      state->Lamps[BFM_strcnv85[off]] = data & pattern ? 1 : 0;
345367      pattern <<= 1;
346368      off++;
347369   }
348370
349   if (mux_output_strobe == 0)
371   if (state->mux_output_strobe == 0)
350372   {
351373      for ( i = 0; i < 128; i++ )
352374      {
353         output_set_lamp_value(i, Lamps[i]);
375         output_set_lamp_value(i, state->Lamps[i]);
354376      }
355377   }
356378}
357379
358380static READ8_HANDLER( mux_data_r )
359381{
360   return mux_input;
382   bfmsys85_state *state = space->machine->driver_data<bfmsys85_state>();
383   return state->mux_input;
361384}
362385
363386///////////////////////////////////////////////////////////////////////////
r10427r10428
372395
373396static WRITE8_HANDLER( triac_w )
374397{
375   triac_latch = data;
398   bfmsys85_state *state = space->machine->driver_data<bfmsys85_state>();
399   state->triac_latch = data;
376400}
377401
378402///////////////////////////////////////////////////////////////////////////
379403
380404static READ8_HANDLER( triac_r )
381405{
382   return triac_latch;
406   bfmsys85_state *state = space->machine->driver_data<bfmsys85_state>();
407   return state->triac_latch;
383408}
384409
385410// machine start (called only once) ////////////////////////////////////////
r10427r10428
433458
434459// machine driver for system85 board //////////////////////////////////////
435460
436static MACHINE_CONFIG_START( bfmsys85, driver_device )
461static MACHINE_CONFIG_START( bfmsys85, bfmsys85_state )
437462   MCFG_MACHINE_START(bfm_sys85)                  // main system85 board initialisation
438463   MCFG_MACHINE_RESET(bfm_sys85)
439464   MCFG_CPU_ADD("maincpu", M6809, MASTER_CLOCK/4)         // 6809 CPU at 1 Mhz
src/mame/drivers/madalien.c
r10427r10428
1616#define SOUND_CLOCK XTAL_4MHz
1717
1818
19static UINT8 *shift_hi;
20static UINT8 *shift_lo;
21
22
2319static INPUT_CHANGED( coin_inserted )
2420{
2521   /* coin insertion causes an NMI */
r10427r10428
3632
3733static READ8_HANDLER( shift_r )
3834{
39   return shift_common(space->machine, *shift_hi, *shift_lo);
35   madalien_state *state = space->machine->driver_data<madalien_state>();
36   return shift_common(space->machine, *state->shift_hi, *state->shift_lo);
4037}
4138
4239static READ8_HANDLER( shift_rev_r )
4340{
44   UINT8 hi = *shift_hi ^ 0x07;
45   UINT8 lo = BITSWAP8(*shift_lo,0,1,2,3,4,5,6,7);
41   madalien_state *state = space->machine->driver_data<madalien_state>();
42   UINT8 hi = *state->shift_hi ^ 0x07;
43   UINT8 lo = BITSWAP8(*state->shift_lo,0,1,2,3,4,5,6,7);
4644
4745   UINT8 ret = shift_common(space->machine, hi, lo);
4846
r10427r10428
8381static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 8 )
8482   AM_RANGE(0x0000, 0x03ff) AM_RAM
8583
86   AM_RANGE(0x6000, 0x63ff) AM_RAM_WRITE(madalien_videoram_w) AM_BASE(&madalien_videoram)
84   AM_RANGE(0x6000, 0x63ff) AM_RAM_WRITE(madalien_videoram_w) AM_BASE_MEMBER(madalien_state, videoram)
8785   AM_RANGE(0x6400, 0x67ff) AM_RAM
88   AM_RANGE(0x6800, 0x7fff) AM_RAM_WRITE(madalien_charram_w) AM_BASE(&madalien_charram)
86   AM_RANGE(0x6800, 0x7fff) AM_RAM_WRITE(madalien_charram_w) AM_BASE_MEMBER(madalien_state, charram)
8987
9088   AM_RANGE(0x8000, 0x8000) AM_MIRROR(0x0ff0) AM_DEVWRITE("crtc", mc6845_address_w)
9189   AM_RANGE(0x8001, 0x8001) AM_MIRROR(0x0ff0) AM_DEVREADWRITE("crtc", mc6845_register_r, mc6845_register_w)
92   AM_RANGE(0x8004, 0x8004) AM_MIRROR(0x0ff0) AM_WRITEONLY AM_BASE(&madalien_video_control)
90   AM_RANGE(0x8004, 0x8004) AM_MIRROR(0x0ff0) AM_WRITEONLY AM_BASE_MEMBER(madalien_state, video_control)
9391   AM_RANGE(0x8005, 0x8005) AM_MIRROR(0x0ff0) AM_WRITE(madalien_output_w)
9492   AM_RANGE(0x8006, 0x8006) AM_MIRROR(0x0ff0) AM_READWRITE(soundlatch2_r, madalien_sound_command_w)
95   AM_RANGE(0x8008, 0x8008) AM_MIRROR(0x07f0) AM_RAM_READ(shift_r) AM_BASE(&shift_hi)
96   AM_RANGE(0x8009, 0x8009) AM_MIRROR(0x07f0) AM_RAM_READ(shift_rev_r) AM_BASE(&shift_lo)
97   AM_RANGE(0x800b, 0x800b) AM_MIRROR(0x07f0) AM_WRITEONLY AM_BASE(&madalien_video_flags)
98   AM_RANGE(0x800c, 0x800c) AM_MIRROR(0x07f0) AM_WRITEONLY AM_BASE(&madalien_headlight_pos)
99   AM_RANGE(0x800d, 0x800d) AM_MIRROR(0x07f0) AM_WRITEONLY AM_BASE(&madalien_edge1_pos)
100   AM_RANGE(0x800e, 0x800e) AM_MIRROR(0x07f0) AM_WRITEONLY AM_BASE(&madalien_edge2_pos)
101   AM_RANGE(0x800f, 0x800f) AM_MIRROR(0x07f0) AM_WRITEONLY AM_BASE(&madalien_scroll)
93   AM_RANGE(0x8008, 0x8008) AM_MIRROR(0x07f0) AM_RAM_READ(shift_r) AM_BASE_MEMBER(madalien_state, shift_hi)
94   AM_RANGE(0x8009, 0x8009) AM_MIRROR(0x07f0) AM_RAM_READ(shift_rev_r) AM_BASE_MEMBER(madalien_state, shift_lo)
95   AM_RANGE(0x800b, 0x800b) AM_MIRROR(0x07f0) AM_WRITEONLY AM_BASE_MEMBER(madalien_state, video_flags)
96   AM_RANGE(0x800c, 0x800c) AM_MIRROR(0x07f0) AM_WRITEONLY AM_BASE_MEMBER(madalien_state, headlight_pos)
97   AM_RANGE(0x800d, 0x800d) AM_MIRROR(0x07f0) AM_WRITEONLY AM_BASE_MEMBER(madalien_state, edge1_pos)
98   AM_RANGE(0x800e, 0x800e) AM_MIRROR(0x07f0) AM_WRITEONLY AM_BASE_MEMBER(madalien_state, edge2_pos)
99   AM_RANGE(0x800f, 0x800f) AM_MIRROR(0x07f0) AM_WRITEONLY AM_BASE_MEMBER(madalien_state, scroll)
102100
103101   AM_RANGE(0x9000, 0x9000) AM_MIRROR(0x0ff0) AM_READ_PORT("PLAYER1")
104102   AM_RANGE(0x9001, 0x9001) AM_MIRROR(0x0ff0) AM_READ_PORT("DSW")
r10427r10428
172170};
173171
174172
175static MACHINE_CONFIG_START( madalien, driver_device )
173static MACHINE_CONFIG_START( madalien, madalien_state )
176174
177175   /* main CPU */
178176   MCFG_CPU_ADD("maincpu", M6502, MADALIEN_MAIN_CLOCK / 8)   /* 1324kHz */
src/mame/drivers/konamigv.c
r10427r10428
119119#include "machine/eeprom.h"
120120#include "machine/intelfsh.h"
121121#include "machine/am53cf96.h"
122#include "sound/psx.h"
122#include "sound/spu.h"
123123#include "sound/cdda.h"
124124
125125class konamigv_state : public psx_state
r10427r10428
173173   AM_RANGE(0x1f801008, 0x1f80100b) AM_RAM /* ?? */
174174   AM_RANGE(0x1f80100c, 0x1f80102f) AM_WRITENOP
175175   AM_RANGE(0x1f801010, 0x1f801013) AM_READNOP
176   AM_RANGE(0x1f801014, 0x1f801017) AM_DEVREAD("spu", psx_spu_delay_r)
176   AM_RANGE(0x1f801014, 0x1f801017) AM_RAM
177177   AM_RANGE(0x1f801040, 0x1f80105f) AM_READWRITE(psx_sio_r, psx_sio_w)
178178   AM_RANGE(0x1f801060, 0x1f80106f) AM_WRITENOP
179179   AM_RANGE(0x1f801070, 0x1f801077) AM_READWRITE(psx_irq_r, psx_irq_w)
r10427r10428
181181   AM_RANGE(0x1f801100, 0x1f80112f) AM_READWRITE(psx_counter_r, psx_counter_w)
182182   AM_RANGE(0x1f801810, 0x1f801817) AM_READWRITE(psx_gpu_r, psx_gpu_w)
183183   AM_RANGE(0x1f801820, 0x1f801827) AM_READWRITE(psx_mdec_r, psx_mdec_w)
184   AM_RANGE(0x1f801c00, 0x1f801dff) AM_DEVREADWRITE("spu", psx_spu_r, psx_spu_w)
184   AM_RANGE(0x1f801c00, 0x1f801dff) AM_READWRITE16(spu_r, spu_w, 0xffffffff)
185185   AM_RANGE(0x1f802020, 0x1f802033) AM_RAM /* ?? */
186186   AM_RANGE(0x1f802040, 0x1f802043) AM_WRITENOP
187187   AM_RANGE(0x1fc00000, 0x1fc7ffff) AM_ROM AM_SHARE("share2") AM_REGION("user1", 0) /* bios */
r10427r10428
333333
334334static void spu_irq(device_t *device, UINT32 data)
335335{
336   psx_irq_set(device->machine, data);
336   if (data)
337   {
338      psx_irq_set(device->machine, 1<<9);
339   }
337340}
338341
339static const psx_spu_interface konamigv_psxspu_interface =
340{
341   spu_irq,
342   psx_dma_install_read_handler,
343   psx_dma_install_write_handler
344};
345
346342static MACHINE_CONFIG_START( konamigv, konamigv_state )
347343   /* basic machine hardware */
348344   MCFG_CPU_ADD( "maincpu", PSXCPU, XTAL_67_7376MHz )
r10427r10428
371367   /* sound hardware */
372368   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
373369
374   MCFG_SOUND_ADD( "spu", PSXSPU, 0 )
375   MCFG_SOUND_CONFIG( konamigv_psxspu_interface )
370   MCFG_SPU_ADD( "spu", XTAL_67_7376MHz/2, &spu_irq )
376371   MCFG_SOUND_ROUTE( 0, "lspeaker", 0.75 )
377372   MCFG_SOUND_ROUTE( 1, "rspeaker", 0.75 )
378373
src/mame/drivers/zr107.c
r10427r10428
176176#include "video/konicdev.h"
177177#include "video/gticlub.h"
178178
179static UINT8 led_reg0, led_reg1;
180179
180class zr107_state : public driver_device
181{
182public:
183   zr107_state(running_machine &machine, const driver_device_config_base &config)
184      : driver_device(machine, config) { }
181185
186   UINT8 led_reg0;
187   UINT8 led_reg1;
188   int ccu_vcth;
189   int ccu_vctl;
190   UINT32 *workram;
191   UINT32 *sharc_dataram;
192};
182193
194
195
196
197
183198static VIDEO_START( jetwave )
184199{
185200   K001005_init(machine);
r10427r10428
189204
190205static VIDEO_UPDATE( jetwave )
191206{
207   zr107_state *state = screen->machine->driver_data<zr107_state>();
192208   device_t *k001604 = screen->machine->device("k001604");
193209
194210   bitmap_fill(bitmap, cliprect, screen->machine->pens[0]);
r10427r10428
197213
198214   k001604_draw_front_layer(k001604, bitmap, cliprect);
199215
200   draw_7segment_led(bitmap, 3, 3, led_reg0);
201   draw_7segment_led(bitmap, 9, 3, led_reg1);
216   draw_7segment_led(bitmap, 3, 3, state->led_reg0);
217   draw_7segment_led(bitmap, 9, 3, state->led_reg1);
202218
203219   sharc_set_flag_input(screen->machine->device("dsp"), 1, ASSERT_LINE);
204220   return 0;
r10427r10428
241257
242258static VIDEO_UPDATE( zr107 )
243259{
260   zr107_state *state = screen->machine->driver_data<zr107_state>();
244261   device_t *k056832 = screen->machine->device("k056832");
245262   bitmap_fill(bitmap, cliprect, screen->machine->pens[0]);
246263
r10427r10428
248265   K001005_draw(bitmap, cliprect);
249266   k056832_tilemap_draw(k056832, bitmap, cliprect, 0, 0, 0);
250267
251   draw_7segment_led(bitmap, 3, 3, led_reg0);
252   draw_7segment_led(bitmap, 9, 3, led_reg1);
268   draw_7segment_led(bitmap, 3, 3, state->led_reg0);
269   draw_7segment_led(bitmap, 9, 3, state->led_reg1);
253270
254271   sharc_set_flag_input(screen->machine->device("dsp"), 1, ASSERT_LINE);
255272   return 0;
r10427r10428
280297
281298static WRITE8_HANDLER( sysreg_w )
282299{
300   zr107_state *state = space->machine->driver_data<zr107_state>();
283301   switch (offset)
284302   {
285303      case 0:   /* LED Register 0 */
286         led_reg0 = data;
304         state->led_reg0 = data;
287305         break;
288306
289307      case 1:   /* LED Register 1 */
290         led_reg1 = data;
308         state->led_reg1 = data;
291309         break;
292310
293311      case 2: /* Parallel data register */
r10427r10428
341359   }
342360}
343361
344static int ccu_vcth = 0;
345static int ccu_vctl = 0;
346362static READ32_HANDLER( ccu_r )
347363{
364   zr107_state *state = space->machine->driver_data<zr107_state>();
348365   UINT32 r = 0;
349366   switch (offset)
350367   {
r10427r10428
353370         // Midnight Run polls the vertical counter in vblank
354371         if (ACCESSING_BITS_24_31)
355372         {
356            ccu_vcth ^= 0xff;
357            r |= ccu_vcth << 24;
373            state->ccu_vcth ^= 0xff;
374            r |= state->ccu_vcth << 24;
358375         }
359376         if (ACCESSING_BITS_8_15)
360377         {
361            ccu_vctl++;
362            ccu_vctl &= 0x1ff;
363            r |= (ccu_vctl >> 2) << 8;
378            state->ccu_vctl++;
379            state->ccu_vctl &= 0x1ff;
380            r |= (state->ccu_vctl >> 2) << 8;
364381         }
365382      }
366383   }
r10427r10428
375392
376393/******************************************************************/
377394
378static UINT32 *workram;
379395static MACHINE_START( zr107 )
380396{
397   zr107_state *state = machine->driver_data<zr107_state>();
381398   /* set conservative DRC options */
382399   ppcdrc_set_options(machine->device("maincpu"), PPCDRC_COMPATIBLE_OPTIONS);
383400
384401   /* configure fast RAM regions for DRC */
385   ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x000fffff, FALSE, workram);
402   ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x000fffff, FALSE, state->workram);
386403}
387404
388405static ADDRESS_MAP_START( zr107_map, ADDRESS_SPACE_PROGRAM, 32 )
389   AM_RANGE(0x00000000, 0x000fffff) AM_RAM   AM_BASE(&workram)   /* Work RAM */
406   AM_RANGE(0x00000000, 0x000fffff) AM_RAM   AM_BASE_MEMBER(zr107_state, workram)   /* Work RAM */
390407   AM_RANGE(0x74000000, 0x74003fff) AM_DEVREADWRITE("k056832", k056832_ram_long_r, k056832_ram_long_w)
391408   AM_RANGE(0x74020000, 0x7402003f) AM_DEVREADWRITE("k056832", k056832_long_r, k056832_long_w)
392409   AM_RANGE(0x74060000, 0x7406003f) AM_READWRITE(ccu_r, ccu_w)
r10427r10428
474491
475492/*****************************************************************************/
476493
477static UINT32 *sharc_dataram;
478494
479495static READ32_HANDLER( dsp_dataram_r )
480496{
481   return sharc_dataram[offset] & 0xffff;
497   zr107_state *state = space->machine->driver_data<zr107_state>();
498   return state->sharc_dataram[offset] & 0xffff;
482499}
483500
484501static WRITE32_HANDLER( dsp_dataram_w )
485502{
486   sharc_dataram[offset] = data;
503   zr107_state *state = space->machine->driver_data<zr107_state>();
504   state->sharc_dataram[offset] = data;
487505}
488506
489507static ADDRESS_MAP_START( sharc_map, ADDRESS_SPACE_DATA, 32 )
r10427r10428
717735   cputag_set_input_line(machine, "dsp", INPUT_LINE_RESET, ASSERT_LINE);
718736}
719737
720static MACHINE_CONFIG_START( zr107, driver_device )
738static MACHINE_CONFIG_START( zr107, zr107_state )
721739
722740   /* basic machine hardware */
723741   MCFG_CPU_ADD("maincpu", PPC403GA, 64000000/2)   /* PowerPC 403GA 32MHz */
r10427r10428
778796   0      /* slrasslt hack */
779797};
780798
781static MACHINE_CONFIG_START( jetwave, driver_device )
799static MACHINE_CONFIG_START( jetwave, zr107_state )
782800
783801   /* basic machine hardware */
784802   MCFG_CPU_ADD("maincpu", PPC403GA, 64000000/2)   /* PowerPC 403GA 32MHz */
r10427r10428
835853
836854static void init_zr107(running_machine *machine)
837855{
838   sharc_dataram = auto_alloc_array(machine, UINT32, 0x100000/4);
839   led_reg0 = led_reg1 = 0x7f;
840   ccu_vcth = ccu_vctl = 0;
856   zr107_state *state = machine->driver_data<zr107_state>();
857   state->sharc_dataram = auto_alloc_array(machine, UINT32, 0x100000/4);
858   state->led_reg0 = state->led_reg1 = 0x7f;
859   state->ccu_vcth = state->ccu_vctl = 0;
841860
842861   K001005_preprocess_texture_data(machine->region("gfx1")->base(), machine->region("gfx1")->bytes(), 0);
843862}
src/mame/drivers/ksys573.c
r10427r10428
347347#include "machine/x76f041.h"
348348#include "machine/x76f100.h"
349349#include "machine/zs01.h"
350#include "sound/psx.h"
350#include "sound/spu.h"
351351#include "sound/cdda.h"
352352#include "sound/mas3507d.h"
353353
r10427r10428
14041404   AM_RANGE(0x1f801008, 0x1f80100b) AM_RAM /* ?? */
14051405   AM_RANGE(0x1f80100c, 0x1f80102f) AM_WRITENOP
14061406   AM_RANGE(0x1f801010, 0x1f801013) AM_READNOP
1407   AM_RANGE(0x1f801014, 0x1f801017) AM_DEVREAD("spu", psx_spu_delay_r)
1407   AM_RANGE(0x1f801014, 0x1f801017) AM_RAM
14081408   AM_RANGE(0x1f801040, 0x1f80105f) AM_READWRITE(psx_sio_r, psx_sio_w)
14091409   AM_RANGE(0x1f801060, 0x1f80106f) AM_WRITENOP
14101410   AM_RANGE(0x1f801070, 0x1f801077) AM_READWRITE(psx_irq_r, psx_irq_w)
r10427r10428
14121412   AM_RANGE(0x1f801100, 0x1f80112f) AM_READWRITE(k573_counter_r, k573_counter_w)
14131413   AM_RANGE(0x1f801810, 0x1f801817) AM_READWRITE(psx_gpu_r, psx_gpu_w)
14141414   AM_RANGE(0x1f801820, 0x1f801827) AM_READWRITE(psx_mdec_r, psx_mdec_w)
1415   AM_RANGE(0x1f801c00, 0x1f801dff) AM_DEVREADWRITE("spu", psx_spu_r, psx_spu_w)
1415   AM_RANGE(0x1f801c00, 0x1f801dff) AM_READWRITE16(spu_r, spu_w, 0xffffffff)
14161416   AM_RANGE(0x1f802020, 0x1f802033) AM_RAM /* ?? */
14171417   AM_RANGE(0x1f802040, 0x1f802043) AM_WRITENOP
14181418   AM_RANGE(0x1fc00000, 0x1fc7ffff) AM_ROM AM_SHARE("share2") AM_REGION("bios", 0)
r10427r10428
14921492
14931493static void spu_irq(device_t *device, UINT32 data)
14941494{
1495   psx_irq_set(device->machine, data);
1495   if (data)
1496   {
1497      psx_irq_set(device->machine, 1<<9);
1498   }
14961499}
14971500
1498static const psx_spu_interface konami573_psxspu_interface =
1499{
1500   spu_irq,
1501   psx_dma_install_read_handler,
1502   psx_dma_install_write_handler
1503};
1504
15051501static void update_mode( running_machine *machine )
15061502{
15071503   ksys573_state *state = machine->driver_data<ksys573_state>();
r10427r10428
28592855   /* sound hardware */
28602856   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
28612857
2862   MCFG_SOUND_ADD( "spu", PSXSPU, 0 )
2863   MCFG_SOUND_CONFIG( konami573_psxspu_interface )
2858   MCFG_SPU_ADD( "spu", XTAL_67_7376MHz/2, &spu_irq )
28642859   MCFG_SOUND_ROUTE( 0, "lspeaker", 1.0 )
28652860   MCFG_SOUND_ROUTE( 1, "rspeaker", 1.0 )
28662861
r10427r10428
45514546   ROM_LOAD( "gca18jaa.u6",  0x000000, 0x000008, CRC(ce84419e) SHA1(839e8ee080ecfc79021a06417d930e8b32dfc6a1) )
45524547
45534548   DISK_REGION( "cdrom0" )
4554   DISK_IMAGE_READONLY( "a18ja", 0, BAD_DUMP SHA1(bb147b9a4871f1ddd108e3e503479221d87ec545) )
4549   DISK_IMAGE_READONLY( "gca18jaa", 0, SHA1(8adcc8ef76cbfb9f47fec5702b0b200565b5c561) )
45554550ROM_END
45564551
45574552// System 573 BIOS (we're missing the later version that boots up with a pseudo-GUI)
src/mame/drivers/srumbler.c
r10427r10428
7272static ADDRESS_MAP_START( srumbler_map, ADDRESS_SPACE_PROGRAM, 8 )
7373   AM_RANGE(0x0000, 0x1dff) AM_RAM  /* RAM (of 1 sort or another) */
7474   AM_RANGE(0x1e00, 0x1fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram)
75   AM_RANGE(0x2000, 0x3fff) AM_RAM_WRITE(srumbler_background_w) AM_BASE(&srumbler_backgroundram)
75   AM_RANGE(0x2000, 0x3fff) AM_RAM_WRITE(srumbler_background_w) AM_BASE_MEMBER(srumbler_state, backgroundram)
7676   AM_RANGE(0x4008, 0x4008) AM_READ_PORT("SYSTEM") AM_WRITE(srumbler_bankswitch_w)
7777   AM_RANGE(0x4009, 0x4009) AM_READ_PORT("P1") AM_WRITE(srumbler_4009_w)
7878   AM_RANGE(0x400a, 0x400a) AM_READ_PORT("P2")
r10427r10428
8080   AM_RANGE(0x400c, 0x400c) AM_READ_PORT("DSW2")
8181   AM_RANGE(0x400a, 0x400d) AM_WRITE(srumbler_scroll_w)
8282   AM_RANGE(0x400e, 0x400e) AM_WRITE(soundlatch_w)
83   AM_RANGE(0x5000, 0x5fff) AM_ROMBANK("5000")   AM_WRITE(srumbler_foreground_w) AM_BASE(&srumbler_foregroundram) /* Banked ROM */
83   AM_RANGE(0x5000, 0x5fff) AM_ROMBANK("5000")   AM_WRITE(srumbler_foreground_w) AM_BASE_MEMBER(srumbler_state, foregroundram) /* Banked ROM */
8484   AM_RANGE(0x6000, 0x6fff) AM_ROMBANK("6000")   /* Banked ROM */
8585   AM_RANGE(0x6000, 0x6fff) AM_WRITENOP   /* Video RAM 2 ??? (not used) */
8686   AM_RANGE(0x7000, 0x7fff) AM_ROMBANK("7000")   /* Banked ROM */
r10427r10428
231231
232232
233233
234static MACHINE_CONFIG_START( srumbler, driver_device )
234static MACHINE_CONFIG_START( srumbler, srumbler_state )
235235
236236   /* basic machine hardware */
237237   MCFG_CPU_ADD("maincpu", M6809, 1500000)        /* 1.5 MHz (?) */
src/mame/drivers/taitogn.c
r10427r10428
325325#include "machine/znsec.h"
326326#include "machine/idectrl.h"
327327#include "machine/mb3773.h"
328#include "sound/psx.h"
328#include "sound/spu.h"
329329#include "audio/taito_zm.h"
330330
331331class taitogn_state : public psx_state
r10427r10428
921921   AM_RANGE(0x1f400000, 0x1f5fffff) AM_READWRITE(flash_s3_r, flash_s3_w)
922922   AM_RANGE(0x1f800000, 0x1f8003ff) AM_RAM /* scratchpad */
923923   AM_RANGE(0x1f801000, 0x1f80100f) AM_RAM /* ?? */
924   AM_RANGE(0x1f801014, 0x1f801017) AM_DEVREADWRITE("spu", psx_spu_delay_r, psx_spu_delay_w)
924   AM_RANGE(0x1f801014, 0x1f801017) AM_RAM
925925   AM_RANGE(0x1f801020, 0x1f801023) AM_READWRITE(psx_com_delay_r, psx_com_delay_w)
926926   AM_RANGE(0x1f801040, 0x1f80105f) AM_READWRITE(psx_sio_r, psx_sio_w)
927927   AM_RANGE(0x1f801070, 0x1f801077) AM_READWRITE(psx_irq_r, psx_irq_w)
r10427r10428
929929   AM_RANGE(0x1f801100, 0x1f80112f) AM_READWRITE(psx_counter_r, psx_counter_w)
930930   AM_RANGE(0x1f801810, 0x1f801817) AM_READWRITE(psx_gpu_r, psx_gpu_w)
931931   AM_RANGE(0x1f801820, 0x1f801827) AM_READWRITE(psx_mdec_r, psx_mdec_w)
932   AM_RANGE(0x1f801c00, 0x1f801dff) AM_DEVREADWRITE("spu", psx_spu_r, psx_spu_w)
932   AM_RANGE(0x1f801c00, 0x1f801dff) AM_READWRITE16(spu_r, spu_w, 0xffffffff)
933933   AM_RANGE(0x1fa00000, 0x1fa00003) AM_READ_PORT("P1")
934934   AM_RANGE(0x1fa00100, 0x1fa00103) AM_READ_PORT("P2")
935935   AM_RANGE(0x1fa00200, 0x1fa00203) AM_READ_PORT("SERVICE")
r10427r10428
940940   AM_RANGE(0x1fa10300, 0x1fa10303) AM_READWRITE(znsecsel_r, znsecsel_w)
941941   AM_RANGE(0x1fa20000, 0x1fa20003) AM_READWRITE(coin_r, coin_w)
942942   AM_RANGE(0x1fa30000, 0x1fa30003) AM_READWRITE(control3_r, control3_w)
943   AM_RANGE(0x1fa51c00, 0x1fa51dff) AM_DEVREADWRITE("spu", psx_spu_r, psx_spu_w) // systematic read at spu_address + 250000, result dropped, maybe other accesses
943   AM_RANGE(0x1fa51c00, 0x1fa51dff) AM_READWRITE16(spu_r, spu_w, 0xffffffff) // systematic read at spu_address + 250000, result dropped, maybe other accesses
944944   AM_RANGE(0x1fa60000, 0x1fa60003) AM_READ(hack1_r)
945945   AM_RANGE(0x1faf0000, 0x1faf07ff) AM_DEVREADWRITE8("at28c16", at28c16_r, at28c16_w, 0xffffffff) /* eeprom */
946946   AM_RANGE(0x1fb00000, 0x1fb0ffff) AM_READWRITE(rf5c296_io_r, rf5c296_io_w)
r10427r10428
958958ADDRESS_MAP_END
959959
960960
961static void psx_spu_irq(device_t *device, UINT32 data)
961static void spu_irq(device_t *device, UINT32 data)
962962{
963   psx_irq_set(device->machine, data);
963   if (data)
964   {
965      psx_irq_set(device->machine, 1<<9);
966   }
964967}
965968
966static const psx_spu_interface psxspu_interface =
967{
968   psx_spu_irq,
969   psx_dma_install_read_handler,
970   psx_dma_install_write_handler
971};
972
973969static MACHINE_CONFIG_START( coh3002t, taitogn_state )
974970   /* basic machine hardware */
975971   MCFG_CPU_ADD( "maincpu", PSXCPU, XTAL_100MHz )
r10427r10428
993989   /* sound hardware */
994990   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
995991
996   MCFG_SOUND_ADD( "spu", PSXSPU, 0 )
997   MCFG_SOUND_CONFIG( psxspu_interface )
992   MCFG_SPU_ADD( "spu", XTAL_67_7376MHz/2, &spu_irq )
998993   MCFG_SOUND_ROUTE(0, "lspeaker", 0.35)
999994   MCFG_SOUND_ROUTE(1, "rspeaker", 0.35)
1000995
src/mame/drivers/aristmk5.c
r10427r10428
6363#include "includes/archimds.h"
6464//#include "machine/i2cmem.h"
6565
66static emu_timer *mk5_2KHz_timer;
67static UINT8 ext_latch;
6866
67class aristmk5_state : public driver_device
68{
69public:
70   aristmk5_state(running_machine &machine, const driver_device_config_base &config)
71      : driver_device(machine, config) { }
72
73   emu_timer *mk5_2KHz_timer;
74   UINT8 ext_latch;
75   UINT8 flyback;
76};
77
78
79
6980static WRITE32_HANDLER( mk5_ext_latch_w )
7081{
82   aristmk5_state *state = space->machine->driver_data<aristmk5_state>();
7183   /* this banks "something" */
72   ext_latch = data & 1;
84   state->ext_latch = data & 1;
7385}
7486
7587static READ32_HANDLER( ext_timer_latch_r )
7688{
89   aristmk5_state *state = space->machine->driver_data<aristmk5_state>();
7790   /* reset 2KHz timer */
7891   ioc_regs[IRQ_STATUS_A] &= 0xfe;
79   mk5_2KHz_timer->adjust(attotime::from_hz(2000));
92   state->mk5_2KHz_timer->adjust(attotime::from_hz(2000));
8093
8194   return 0xffffffff; //value doesn't matter apparently
8295}
r10427r10428
8497/* same as plain AA but with the I2C unconnected */
8598static READ32_HANDLER( mk5_ioc_r )
8699{
87   static UINT32 ioc_addr;
100   aristmk5_state *state = space->machine->driver_data<aristmk5_state>();
101   UINT32 ioc_addr;
88102
89103   ioc_addr = offset*4;
90104   ioc_addr >>= 16;
r10427r10428
92106
93107   if(((ioc_addr == 0x20) || (ioc_addr == 0x30)) && (offset & 0x1f) == 0)
94108   {
95      static UINT8 flyback; //internal name for vblank here
96109      int vert_pos;
97110
98111      vert_pos = space->machine->primary_screen->vpos();
99      flyback = (vert_pos <= vidc_regs[VIDC_VDSR] || vert_pos >= vidc_regs[VIDC_VDER]) ? 0x80 : 0x00;
112      state->flyback = (vert_pos <= vidc_regs[VIDC_VDSR] || vert_pos >= vidc_regs[VIDC_VDER]) ? 0x80 : 0x00;
100113
101114      //i2c_data = (i2cmem_sda_read(space->machine->device("i2cmem")) & 1);
102115
103      return (flyback) | (ioc_regs[CONTROL] & 0x7c) | (1<<1) | 1;
116      return (state->flyback) | (ioc_regs[CONTROL] & 0x7c) | (1<<1) | 1;
104117   }
105118
106119   return archimedes_ioc_r(space,offset,mem_mask);
r10427r10428
108121
109122static WRITE32_HANDLER( mk5_ioc_w )
110123{
111   static UINT32 ioc_addr;
124   aristmk5_state *state = space->machine->driver_data<aristmk5_state>();
125   UINT32 ioc_addr;
112126
113127   ioc_addr = offset*4;
114128   ioc_addr >>= 16;
115129   ioc_addr &= 0x37;
116130
117   if(!ext_latch)
131   if(!state->ext_latch)
118132   {
119133      if(((ioc_addr == 0x20) || (ioc_addr == 0x30)) && (offset & 0x1f) == 0)
120134      {
r10427r10428
219233
220234static TIMER_CALLBACK( mk5_2KHz_callback )
221235{
236   aristmk5_state *state = machine->driver_data<aristmk5_state>();
222237   ioc_regs[4] |= 1;
223238
224   mk5_2KHz_timer->adjust(attotime::never);
239   state->mk5_2KHz_timer->adjust(attotime::never);
225240}
226241
227242static MACHINE_START( aristmk5 )
228243{
244   aristmk5_state *state = machine->driver_data<aristmk5_state>();
229245   archimedes_init(machine);
230246
231247   // reset the DAC to centerline
232248   //dac_signed_data_w(machine->device("dac"), 0x80);
233249
234   mk5_2KHz_timer = machine->scheduler().timer_alloc(FUNC(mk5_2KHz_callback));
250   state->mk5_2KHz_timer = machine->scheduler().timer_alloc(FUNC(mk5_2KHz_callback));
235251}
236252
237253static MACHINE_RESET( aristmk5 )
238254{
255   aristmk5_state *state = machine->driver_data<aristmk5_state>();
239256   archimedes_reset(machine);
240   mk5_2KHz_timer->adjust(attotime::from_hz(2000));
257   state->mk5_2KHz_timer->adjust(attotime::from_hz(2000));
241258
242259   ioc_regs[IRQ_STATUS_B] |= 0x40; //hack, set keyboard irq empty to be ON
243260
r10427r10428
273290};
274291#endif
275292
276static MACHINE_CONFIG_START( aristmk5, driver_device )
293static MACHINE_CONFIG_START( aristmk5, aristmk5_state )
277294   MCFG_CPU_ADD("maincpu", ARM, 10000000) // ?
278295   MCFG_CPU_PROGRAM_MAP(aristmk5_map)
279296
src/mame/drivers/mystwarr.c
r10427r10428
3333#include "includes/konamipt.h"
3434#include "includes/mystwarr.h"
3535
36static UINT16 *gx_workram;
3736
38static UINT8 mw_irq_control;
3937
4038static const eeprom_interface eeprom_intf =
4139{
r10427r10428
108106
109107static INTERRUPT_GEN(mystwarr_interrupt)
110108{
111   if (!(mw_irq_control & 0x01)) return;
109   mystwarr_state *state = device->machine->driver_data<mystwarr_state>();
110   if (!(state->mw_irq_control & 0x01)) return;
112111
113112   switch (cpu_getiloops(device))
114113   {
r10427r10428
146145
147146static INTERRUPT_GEN(mchamp_interrupt)
148147{
149   if (!(mw_irq_control & 0x02)) return;
148   mystwarr_state *state = device->machine->driver_data<mystwarr_state>();
149   if (!(state->mw_irq_control & 0x02)) return;
150150
151151   switch (cpu_getiloops(device))
152152   {
r10427r10428
215215
216216static WRITE16_HANDLER( irq_ack_w )
217217{
218   mystwarr_state *state = space->machine->driver_data<mystwarr_state>();
218219   K056832_b_word_w(space, offset, data, mem_mask);
219220
220221   if (offset == 3 && ACCESSING_BITS_0_7)
221222   {
222      mw_irq_control = data&0xff;
223      state->mw_irq_control = data&0xff;
223224
224225//      if ((data &0xf0) != 0xd0) logerror("Unknown write to IRQ reg: %x\n", data);
225226
r10427r10428
258259/* Mystic Warriors */
259260static ADDRESS_MAP_START( mystwarr_map, ADDRESS_SPACE_PROGRAM, 16 )
260261   AM_RANGE(0x000000, 0x1fffff) AM_ROM   // main program
261   AM_RANGE(0x200000, 0x20ffff) AM_RAM AM_BASE(&gx_workram)
262   AM_RANGE(0x200000, 0x20ffff) AM_RAM AM_BASE_MEMBER(mystwarr_state, gx_workram)
262263   AM_RANGE(0x400000, 0x40ffff) AM_READWRITE(K053247_scattered_word_r,K053247_scattered_word_w) AM_BASE_GENERIC(spriteram)
263264   AM_RANGE(0x480000, 0x4800ff) AM_WRITE(K055555_word_w)
264265   AM_RANGE(0x482000, 0x48200f) AM_READ(K055673_rom_word_r)
r10427r10428
296297/* Metamorphic Force */
297298static ADDRESS_MAP_START( metamrph_map, ADDRESS_SPACE_PROGRAM, 16 )
298299   AM_RANGE(0x000000, 0x1fffff) AM_ROM   // main program
299   AM_RANGE(0x200000, 0x20ffff) AM_RAM AM_BASE(&gx_workram)
300   AM_RANGE(0x200000, 0x20ffff) AM_RAM AM_BASE_MEMBER(mystwarr_state, gx_workram)
300301   AM_RANGE(0x210000, 0x210fff) AM_READWRITE(K053247_word_r,K053247_word_w)
301302   AM_RANGE(0x211000, 0x21ffff) AM_RAM
302303   AM_RANGE(0x240000, 0x240007) AM_WRITE(K053246_word_w)
r10427r10428
339340/* Violent Storm */
340341static ADDRESS_MAP_START( viostorm_map, ADDRESS_SPACE_PROGRAM, 16 )
341342   AM_RANGE(0x000000, 0x1fffff) AM_ROM      // main program
342   AM_RANGE(0x200000, 0x20ffff) AM_RAM AM_BASE(&gx_workram)
343   AM_RANGE(0x200000, 0x20ffff) AM_RAM AM_BASE_MEMBER(mystwarr_state, gx_workram)
343344   AM_RANGE(0x210000, 0x210fff) AM_READWRITE(K053247_word_r,K053247_word_w)
344345   AM_RANGE(0x211000, 0x21ffff) AM_RAM
345346   AM_RANGE(0x240000, 0x240007) AM_WRITE(K053246_word_w)
r10427r10428
408409
409410static READ16_HANDLER( mccontrol_r )
410411{
411   return mw_irq_control<<8;
412   mystwarr_state *state = space->machine->driver_data<mystwarr_state>();
413   return state->mw_irq_control<<8;
412414}
413415
414416static WRITE16_HANDLER( mccontrol_w )
415417{
418   mystwarr_state *state = space->machine->driver_data<mystwarr_state>();
416419   if (ACCESSING_BITS_8_15)
417420   {
418      mw_irq_control = data>>8;
421      state->mw_irq_control = data>>8;
419422      // bit 0 = watchdog
420423      // bit 1 = IRQ enable
421424      // bit 2 = OBJCHA
r10427r10428
433436/* Martial Champion */
434437static ADDRESS_MAP_START( martchmp_map, ADDRESS_SPACE_PROGRAM, 16 )
435438   AM_RANGE(0x000000, 0x0fffff) AM_ROM                           // main program
436   AM_RANGE(0x100000, 0x10ffff) AM_RAM AM_BASE(&gx_workram)         // work RAM
439   AM_RANGE(0x100000, 0x10ffff) AM_RAM AM_BASE_MEMBER(mystwarr_state, gx_workram)         // work RAM
437440   AM_RANGE(0x300000, 0x3fffff) AM_ROM                           // data ROM
438441   AM_RANGE(0x400000, 0x4000ff) AM_WRITE(K055555_word_w)            // PCU2
439442   AM_RANGE(0x402000, 0x40200f) AM_READ(K055673_rom_word_r)         // sprite ROM readback
r10427r10428
496499   AM_RANGE(0x48c000, 0x48c01f) AM_WRITE(K054338_word_w)
497500   AM_RANGE(0x48e000, 0x48e001) AM_READ_PORT("IN0_P1")   // bit 3 (0x8) is test switch
498501   AM_RANGE(0x48e020, 0x48e021) AM_READ(dddeeprom_r)
499   AM_RANGE(0x600000, 0x60ffff) AM_RAM AM_BASE(&gx_workram)
502   AM_RANGE(0x600000, 0x60ffff) AM_RAM AM_BASE_MEMBER(mystwarr_state, gx_workram)
500503   AM_RANGE(0x680000, 0x68003f) AM_READWRITE(K055550_word_r,K055550_word_w)
501504   AM_RANGE(0x6a0000, 0x6a0001) AM_WRITE(mmeeprom_w)
502505   AM_RANGE(0x6c0000, 0x6c0001) AM_WRITE(ddd_053936_enable_w)
r10427r10428
544547   AM_RANGE(0x48c000, 0x48c01f) AM_WRITE(K054338_word_w)
545548   AM_RANGE(0x48e000, 0x48e001) AM_READ_PORT("IN0_P1")            // bit 3 (0x8) is test switch
546549   AM_RANGE(0x48e020, 0x48e021) AM_READ(dddeeprom_r)
547   AM_RANGE(0x600000, 0x60ffff) AM_RAM AM_BASE(&gx_workram)
550   AM_RANGE(0x600000, 0x60ffff) AM_RAM AM_BASE_MEMBER(mystwarr_state, gx_workram)
548551   AM_RANGE(0x660000, 0x6600ff) AM_READWRITE(K054000_lsb_r,K054000_lsb_w)
549552   AM_RANGE(0x6a0000, 0x6a0001) AM_WRITE(mmeeprom_w)
550553   AM_RANGE(0x6c0000, 0x6c0001) AM_WRITE(ddd_053936_enable_w)
r10427r10428
566569
567570/**********************************************************************************/
568571
569static int cur_sound_region;
570572
571573static void reset_sound_region(running_machine *machine)
572574{
573   memory_set_bankptr(machine, "bank2", machine->region("soundcpu")->base() + 0x10000 + cur_sound_region*0x4000);
575   mystwarr_state *state = machine->driver_data<mystwarr_state>();
576   memory_set_bankptr(machine, "bank2", machine->region("soundcpu")->base() + 0x10000 + state->cur_sound_region*0x4000);
574577}
575578
576579static WRITE8_HANDLER( sound_bankswitch_w )
577580{
578   cur_sound_region = (data & 0xf);
581   mystwarr_state *state = space->machine->driver_data<mystwarr_state>();
582   state->cur_sound_region = (data & 0xf);
579583   reset_sound_region(space->machine);
580584}
581585
r10427r10428
857861
858862static MACHINE_START( mystwarr )
859863{
864   mystwarr_state *state = machine->driver_data<mystwarr_state>();
860865   /* set default bankswitch */
861   cur_sound_region = 2;
866   state->cur_sound_region = 2;
862867   reset_sound_region(machine);
863868
864   mw_irq_control = 0;
869   state->mw_irq_control = 0;
865870
866   state_save_register_global(machine, mw_irq_control);
867   state_save_register_global(machine, cur_sound_region);
871   state_save_register_global(machine, state->mw_irq_control);
872   state_save_register_global(machine, state->cur_sound_region);
868873   machine->state().register_postload(mystwarr_postload, NULL);
869874}
870875
r10427r10428
939944   for (i=5; i<=7; i++) k054539_set_gain(k054539_1, i, 2.0);
940945}
941946
942static MACHINE_CONFIG_START( mystwarr, driver_device )
947static MACHINE_CONFIG_START( mystwarr, mystwarr_state )
943948
944949   /* basic machine hardware */
945950   MCFG_CPU_ADD("maincpu", M68000, 16000000)   /* 16 MHz (confirmed) */
src/mame/drivers/dlair.c
r10427r10428
5151      : driver_device(machine, config) { }
5252
5353   UINT8 *videoram;
54   laserdisc_device *laserdisc;
55   UINT8 last_misc;
56   UINT8 laserdisc_type;
57   UINT8 laserdisc_data;
5458};
5559
5660
r10427r10428
7680 *
7781 *************************************/
7882
79static laserdisc_device *laserdisc;
80static UINT8 last_misc;
8183
82static UINT8 laserdisc_type;
83static UINT8 laserdisc_data;
8484
8585static const UINT8 led_map[16] =
8686   { 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,0x07,0x7f,0x67,0x77,0x7c,0x39,0x5e,0x79,0x00 };
r10427r10428
101101
102102static WRITE8_DEVICE_HANDLER( serial_transmit )
103103{
104   laserdisc_data_w(laserdisc, data);
104   dlair_state *state = device->machine->driver_data<dlair_state>();
105   laserdisc_data_w(state->laserdisc, data);
105106}
106107
107108
108109static int serial_receive(device_t *device, int channel)
109110{
111   dlair_state *state = device->machine->driver_data<dlair_state>();
110112   /* if we still have data to send, do it now */
111   if (channel == 0 && laserdisc_line_r(laserdisc, LASERDISC_LINE_DATA_AVAIL) == ASSERT_LINE)
112      return laserdisc_data_r(laserdisc);
113   if (channel == 0 && laserdisc_line_r(state->laserdisc, LASERDISC_LINE_DATA_AVAIL) == ASSERT_LINE)
114      return laserdisc_data_r(state->laserdisc);
113115
114116   return -1;
115117}
r10427r10428
197199
198200static MACHINE_START( dlair )
199201{
200   laserdisc = machine->device<laserdisc_device>("laserdisc");
202   dlair_state *state = machine->driver_data<dlair_state>();
203   state->laserdisc = machine->device<laserdisc_device>("laserdisc");
201204}
202205
203206
204207static MACHINE_RESET( dlair )
205208{
209   dlair_state *state = machine->driver_data<dlair_state>();
206210   /* determine the laserdisc player from the DIP switches */
207   if (laserdisc_type == LASERDISC_TYPE_VARIABLE)
211   if (state->laserdisc_type == LASERDISC_TYPE_VARIABLE)
208212   {
209213      int newtype = (input_port_read(machine, "DSW2") & 0x08) ? LASERDISC_TYPE_PIONEER_LDV1000 : LASERDISC_TYPE_PIONEER_PR7820;
210      laserdisc_set_type(laserdisc, newtype);
214      laserdisc_set_type(state->laserdisc, newtype);
211215   }
212216}
213217
r10427r10428
241245
242246static WRITE8_HANDLER( misc_w )
243247{
248   dlair_state *state = space->machine->driver_data<dlair_state>();
244249   /*
245250        D0-D3 = B0-B3
246251           D4 = coin counter
r10427r10428
248253           D6 = ENTER
249254           D7 = INT/EXT
250255    */
251   UINT8 diff = data ^ last_misc;
252   last_misc = data;
256   UINT8 diff = data ^ state->last_misc;
257   state->last_misc = data;
253258
254259   coin_counter_w(space->machine, 0, (~data >> 4) & 1);
255260
256261   /* on bit 5 going low, push the data out to the laserdisc player */
257262   if ((diff & 0x20) && !(data & 0x20))
258      laserdisc_data_w(laserdisc, laserdisc_data);
263      laserdisc_data_w(state->laserdisc, state->laserdisc_data);
259264
260265   /* on bit 6 going low, we need to signal enter */
261   laserdisc_line_w(laserdisc, LASERDISC_LINE_ENTER, (data & 0x40) ? CLEAR_LINE : ASSERT_LINE);
266   laserdisc_line_w(state->laserdisc, LASERDISC_LINE_ENTER, (data & 0x40) ? CLEAR_LINE : ASSERT_LINE);
262267}
263268
264269
265270static WRITE8_HANDLER( dleuro_misc_w )
266271{
272   dlair_state *state = space->machine->driver_data<dlair_state>();
267273   /*
268274           D0 = CHAR GEN ON+
269275           D1 = KILL VIDEO+
r10427r10428
274280           D6 = ENTER
275281           D7 = INT/EXT
276282    */
277   UINT8 diff = data ^ last_misc;
278   last_misc = data;
283   UINT8 diff = data ^ state->last_misc;
284   state->last_misc = data;
279285
280286   coin_counter_w(space->machine, 1, (~data >> 3) & 1);
281287   coin_counter_w(space->machine, 0, (~data >> 4) & 1);
282288
283289   /* on bit 5 going low, push the data out to the laserdisc player */
284290   if ((diff & 0x20) && !(data & 0x20))
285      laserdisc_data_w(laserdisc, laserdisc_data);
291      laserdisc_data_w(state->laserdisc, state->laserdisc_data);
286292
287293   /* on bit 6 going low, we need to signal enter */
288   laserdisc_line_w(laserdisc, LASERDISC_LINE_ENTER, (data & 0x40) ? CLEAR_LINE : ASSERT_LINE);
294   laserdisc_line_w(state->laserdisc, LASERDISC_LINE_ENTER, (data & 0x40) ? CLEAR_LINE : ASSERT_LINE);
289295}
290296
291297
r10427r10428
310316
311317static CUSTOM_INPUT( laserdisc_status_r )
312318{
313   switch (laserdisc_get_type(laserdisc))
319   dlair_state *state = field->port->machine->driver_data<dlair_state>();
320   switch (laserdisc_get_type(state->laserdisc))
314321   {
315322      case LASERDISC_TYPE_PIONEER_PR7820:
316323         return 0;
317324
318325      case LASERDISC_TYPE_PIONEER_LDV1000:
319         return (laserdisc_line_r(laserdisc, LASERDISC_LINE_STATUS) == ASSERT_LINE) ? 0 : 1;
326         return (laserdisc_line_r(state->laserdisc, LASERDISC_LINE_STATUS) == ASSERT_LINE) ? 0 : 1;
320327
321328      case LASERDISC_TYPE_PHILLIPS_22VP932:
322329         return 0;
r10427r10428
327334
328335static CUSTOM_INPUT( laserdisc_command_r )
329336{
330   switch (laserdisc_get_type(laserdisc))
337   dlair_state *state = field->port->machine->driver_data<dlair_state>();
338   switch (laserdisc_get_type(state->laserdisc))
331339   {
332340      case LASERDISC_TYPE_PIONEER_PR7820:
333         return (laserdisc_line_r(laserdisc, LASERDISC_LINE_READY) == ASSERT_LINE) ? 0 : 1;
341         return (laserdisc_line_r(state->laserdisc, LASERDISC_LINE_READY) == ASSERT_LINE) ? 0 : 1;
334342
335343      case LASERDISC_TYPE_PIONEER_LDV1000:
336         return (laserdisc_line_r(laserdisc, LASERDISC_LINE_COMMAND) == ASSERT_LINE) ? 0 : 1;
344         return (laserdisc_line_r(state->laserdisc, LASERDISC_LINE_COMMAND) == ASSERT_LINE) ? 0 : 1;
337345
338346      case LASERDISC_TYPE_PHILLIPS_22VP932:
339347         return 0;
r10427r10428
344352
345353static READ8_HANDLER( laserdisc_r )
346354{
347   UINT8 result = laserdisc_data_r(laserdisc);
355   dlair_state *state = space->machine->driver_data<dlair_state>();
356   UINT8 result = laserdisc_data_r(state->laserdisc);
348357   mame_printf_debug("laserdisc_r = %02X\n", result);
349358   return result;
350359}
r10427r10428
352361
353362static WRITE8_HANDLER( laserdisc_w )
354363{
355   laserdisc_data = data;
364   dlair_state *state = space->machine->driver_data<dlair_state>();
365   state->laserdisc_data = data;
356366}
357367
358368
r10427r10428
939949
940950static DRIVER_INIT( fixed )
941951{
942   laserdisc_type = LASERDISC_TYPE_FIXED;
952   dlair_state *state = machine->driver_data<dlair_state>();
953   state->laserdisc_type = LASERDISC_TYPE_FIXED;
943954}
944955
945956
946957static DRIVER_INIT( variable )
947958{
948   laserdisc_type = LASERDISC_TYPE_VARIABLE;
959   dlair_state *state = machine->driver_data<dlair_state>();
960   state->laserdisc_type = LASERDISC_TYPE_VARIABLE;
949961}
950962
951963
src/mame/drivers/gpworld.c
r10427r10428
4343#include "cpu/z80/z80.h"
4444#include "machine/laserdsc.h"
4545
46
47class gpworld_state : public driver_device
48{
49public:
50   gpworld_state(running_machine &machine, const driver_device_config_base &config)
51      : driver_device(machine, config) { }
52
53   UINT8 nmi_enable;
54   UINT8 start_lamp;
55   UINT8 ldp_read_latch;
56   UINT8 ldp_write_latch;
57   UINT8 brake_gas;
58   UINT8* tile_RAM;
59   UINT8* sprite_RAM;
60   UINT8* palette_RAM;
61   device_t *laserdisc;
62};
63
64
4665/* Assumed to be the same as segald hardware */
4766#define GUESSED_CLOCK (5000000)
4867
49static UINT8 nmi_enable;
50static UINT8 start_lamp;
51static UINT8 ldp_read_latch;
52static UINT8 ldp_write_latch;
53static UINT8 brake_gas;
5468
55static UINT8* tile_RAM;
56static UINT8* sprite_RAM;
57static UINT8* palette_RAM;
5869
59static device_t *laserdisc;
6070
6171
6272/* VIDEO GOODS */
6373static void gpworld_draw_tiles(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect)
6474{
75   gpworld_state *state = machine->driver_data<gpworld_state>();
6576   UINT8 characterX, characterY;
6677
6778   /* Temporarily set to 64 wide to accommodate two screens */
r10427r10428
7182      {
7283         int current_screen_character = (characterY*64) + characterX;
7384
74         drawgfx_transpen(bitmap, cliprect, machine->gfx[0], tile_RAM[current_screen_character],
85         drawgfx_transpen(bitmap, cliprect, machine->gfx[0], state->tile_RAM[current_screen_character],
7586               characterY, 0, 0, characterX*8, characterY*8, 0);
7687      }
7788   }
r10427r10428
96107
97108static void gpworld_draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect)
98109{
110   gpworld_state *state = machine->driver_data<gpworld_state>();
99111   const int SPR_Y_TOP     = 0;
100112   const int SPR_Y_BOTTOM  = 1;
101113   const int SPR_X_LO      = 2;
r10427r10428
113125   /* Heisted from Daphne which heisted it from MAME */
114126   for (i = 0; i < 0x800; i += 8)
115127   {
116      UINT8 *spr_reg = sprite_RAM + i;
128      UINT8 *spr_reg = state->sprite_RAM + i;
117129
118130      if (spr_reg[SPR_Y_BOTTOM] && spr_reg[SPR_X_LO] != 0xff)
119131      {
r10427r10428
217229
218230static MACHINE_START( gpworld )
219231{
220   laserdisc = machine->device("laserdisc");
232   gpworld_state *state = machine->driver_data<gpworld_state>();
233   state->laserdisc = machine->device("laserdisc");
221234}
222235
223236
r10427r10428
225238/* READS */
226239static READ8_HANDLER( ldp_read )
227240{
228   return ldp_read_latch;
241   gpworld_state *state = space->machine->driver_data<gpworld_state>();
242   return state->ldp_read_latch;
229243}
230244
231245static READ8_HANDLER( pedal_in )
232246{
233   if (brake_gas)
247   gpworld_state *state = space->machine->driver_data<gpworld_state>();
248   if (state->brake_gas)
234249      return   input_port_read(space->machine, "INACCEL");
235250
236251   return   input_port_read(space->machine, "INBRAKE");
r10427r10428
240255/* WRITES */
241256static WRITE8_HANDLER( ldp_write )
242257{
243   ldp_write_latch = data;
258   gpworld_state *state = space->machine->driver_data<gpworld_state>();
259   state->ldp_write_latch = data;
244260}
245261
246262static WRITE8_HANDLER( misc_io_write )
247263{
248   start_lamp = (data & 0x04) >> 1;
249   nmi_enable = (data & 0x40) >> 6;
264   gpworld_state *state = space->machine->driver_data<gpworld_state>();
265   state->start_lamp = (data & 0x04) >> 1;
266   state->nmi_enable = (data & 0x40) >> 6;
250267   /*  dunno      = (data & 0x80) >> 7; */ //coin counter???
251268
252   logerror("NMI : %x (0x%x)\n", nmi_enable, data);
269   logerror("NMI : %x (0x%x)\n", state->nmi_enable, data);
253270}
254271
255272static WRITE8_HANDLER( brake_gas_write )
256273{
257   brake_gas = data & 0x01;
274   gpworld_state *state = space->machine->driver_data<gpworld_state>();
275   state->brake_gas = data & 0x01;
258276}
259277
260278static WRITE8_HANDLER( palette_write )
261279{
280   gpworld_state *state = space->machine->driver_data<gpworld_state>();
262281   /* This is all just a (bad) guess */
263282   int pal_index, r, g, b, a;
264283
265   palette_RAM[offset] = data;
284   state->palette_RAM[offset] = data;
266285
267286   /* "Round down" to the nearest palette entry */
268287   pal_index = offset & 0xffe;
269288
270   g = (palette_RAM[pal_index]   & 0xf0) << 0;
271   b = (palette_RAM[pal_index]   & 0x0f) << 4;
272   r = (palette_RAM[pal_index+1] & 0x0f) << 4;
273   a = (palette_RAM[pal_index+1] & 0x80) ? 0 : 255;   /* guess */
289   g = (state->palette_RAM[pal_index]   & 0xf0) << 0;
290   b = (state->palette_RAM[pal_index]   & 0x0f) << 4;
291   r = (state->palette_RAM[pal_index+1] & 0x0f) << 4;
292   a = (state->palette_RAM[pal_index+1] & 0x80) ? 0 : 255;   /* guess */
274293
275294   /* logerror("PAL WRITE index : %x  rgb : %d %d %d (real %x) at %x\n", pal_index, r,g,b, data, offset); */
276295
r10427r10428
280299/* PROGRAM MAP */
281300static ADDRESS_MAP_START( mainmem, ADDRESS_SPACE_PROGRAM, 8 )
282301   AM_RANGE(0x0000,0xbfff) AM_ROM
283   AM_RANGE(0xc000,0xc7ff) AM_RAM AM_BASE(&sprite_RAM)
284   AM_RANGE(0xc800,0xcfff) AM_WRITE(palette_write) AM_BASE(&palette_RAM)   /* The memory test reads at 0xc800 */
285   AM_RANGE(0xd000,0xd7ff) AM_RAM AM_BASE(&tile_RAM)
302   AM_RANGE(0xc000,0xc7ff) AM_RAM AM_BASE_MEMBER(gpworld_state, sprite_RAM)
303   AM_RANGE(0xc800,0xcfff) AM_WRITE(palette_write) AM_BASE_MEMBER(gpworld_state, palette_RAM)   /* The memory test reads at 0xc800 */
304   AM_RANGE(0xd000,0xd7ff) AM_RAM AM_BASE_MEMBER(gpworld_state, tile_RAM)
286305   AM_RANGE(0xd800,0xd800) AM_READWRITE(ldp_read,ldp_write)
287306/*  AM_RANGE(0xd801,0xd801) AM_READ(???) */
288307   AM_RANGE(0xda00,0xda00) AM_READ_PORT("INWHEEL")   //8255 here....
r10427r10428
412431
413432static INTERRUPT_GEN( vblank_callback_gpworld )
414433{
434   gpworld_state *state = device->machine->driver_data<gpworld_state>();
415435   /* Do an NMI if the enabled bit is set */
416   if (nmi_enable)
436   if (state->nmi_enable)
417437   {
418      laserdisc_data_w(laserdisc,ldp_write_latch);
419      ldp_read_latch  = laserdisc_data_r(laserdisc);
438      laserdisc_data_w(state->laserdisc,state->ldp_write_latch);
439      state->ldp_read_latch  = laserdisc_data_r(state->laserdisc);
420440      cpu_set_input_line(device, INPUT_LINE_NMI, PULSE_LINE);
421441   }
422442
r10427r10428
441461GFXDECODE_END
442462
443463/* DRIVER */
444static MACHINE_CONFIG_START( gpworld, driver_device )
464static MACHINE_CONFIG_START( gpworld, gpworld_state )
445465
446466   /* main cpu */
447467   MCFG_CPU_ADD("maincpu", Z80, GUESSED_CLOCK)
r10427r10428
507527
508528static DRIVER_INIT( gpworld )
509529{
510   nmi_enable = 0;
511   start_lamp = 0;
512   brake_gas = 0;
513   ldp_write_latch = ldp_read_latch = 0;
530   gpworld_state *state = machine->driver_data<gpworld_state>();
531   state->nmi_enable = 0;
532   state->start_lamp = 0;
533   state->brake_gas = 0;
534   state->ldp_write_latch = state->ldp_read_latch = 0;
514535}
515536
516537
src/mame/drivers/pcktgal.c
r10427r10428
4343   cputag_set_input_line(space->machine, "audiocpu", INPUT_LINE_NMI, PULSE_LINE);
4444}
4545
46static int msm5205next;
4746
4847static void pcktgal_adpcm_int(device_t *device)
4948{
50   static int toggle;
49   pcktgal_state *state = device->machine->driver_data<pcktgal_state>();
5150
52   msm5205_data_w(device,msm5205next >> 4);
53   msm5205next<<=4;
51   msm5205_data_w(device,state->msm5205next >> 4);
52   state->msm5205next<<=4;
5453
55   toggle = 1 - toggle;
56   if (toggle)
54   state->toggle = 1 - state->toggle;
55   if (state->toggle)
5756      cputag_set_input_line(device->machine, "audiocpu", M6502_IRQ_LINE, HOLD_LINE);
5857}
5958
6059static WRITE8_HANDLER( pcktgal_adpcm_data_w )
6160{
62   msm5205next=data;
61   pcktgal_state *state = space->machine->driver_data<pcktgal_state>();
62   state->msm5205next=data;
6363}
6464
6565static READ8_DEVICE_HANDLER( pcktgal_adpcm_reset_r )
src/mame/drivers/atarigx2.c
r10427r10428
117117   /* upper byte */
118118   if (ACCESSING_BITS_24_31)
119119   {
120      atarigx2_state *state = space->machine->driver_data<atarigx2_state>();
121
120122      /* bits 13-11 are the MO control bits */
121      atarirle_control_w(space->machine,0, (data >> 27) & 7);
123      atarirle_control_w(state->rle, (data >> 27) & 7);
122124   }
123125
124126   /* lower byte */
r10427r10428
132134   atarigx2_state *state = space->machine->driver_data<atarigx2_state>();
133135   COMBINE_DATA(state->mo_command);
134136   if (ACCESSING_BITS_0_15)
135      atarirle_command_w(0, ((data & 0xffff) == 2) ? ATARIRLE_COMMAND_CHECKSUM : ATARIRLE_COMMAND_DRAW);
137      atarirle_command_w(state->rle, ((data & 0xffff) == 2) ? ATARIRLE_COMMAND_CHECKSUM : ATARIRLE_COMMAND_DRAW);
136138}
137139
138140
r10427r10428
11571159   AM_RANGE(0xd40000, 0xd40fff) AM_RAM_WRITE(atarigen_666_paletteram32_w) AM_BASE_GENERIC(paletteram)
11581160   AM_RANGE(0xd72000, 0xd75fff) AM_WRITE(atarigen_playfield32_w) AM_BASE_MEMBER(atarigx2_state, playfield32)
11591161   AM_RANGE(0xd76000, 0xd76fff) AM_WRITE(atarigen_alpha32_w) AM_BASE_MEMBER(atarigx2_state, alpha32)
1160   AM_RANGE(0xd78000, 0xd78fff) AM_WRITE(atarirle_0_spriteram32_w) AM_BASE(&atarirle_0_spriteram32)
1162   AM_RANGE(0xd78000, 0xd78fff) AM_DEVREADWRITE("rle", atarirle_spriteram32_r, atarirle_spriteram32_w)
11611163   AM_RANGE(0xd7a200, 0xd7a203) AM_WRITE(mo_command_w) AM_BASE_MEMBER(atarigx2_state, mo_command)
11621164   AM_RANGE(0xd70000, 0xd7ffff) AM_RAM
11631165   AM_RANGE(0xd80000, 0xd9ffff) AM_WRITE(atarigen_eeprom_enable32_w)
r10427r10428
13801382   GFXDECODE_ENTRY( "gfx1", 0, pftoplayout, 0x000, 64 )
13811383GFXDECODE_END
13821384
1385static const atarirle_desc modesc_0x200 =
1386{
1387   "gfx3",      /* region where the GFX data lives */
1388   256,      /* number of entries in sprite RAM */
1389   0,         /* left clip coordinate */
1390   0,         /* right clip coordinate */
13831391
1392   0x200,      /* base palette entry */
1393   0x400,      /* maximum number of colors */
13841394
1395   {{ 0x7fff,0,0,0,0,0,0,0 }},   /* mask for the code index */
1396   {{ 0,0x01f0,0,0,0,0,0,0 }},   /* mask for the color */
1397   {{ 0,0,0xffc0,0,0,0,0,0 }},   /* mask for the X position */
1398   {{ 0,0,0,0xffc0,0,0,0,0 }},   /* mask for the Y position */
1399   {{ 0,0,0,0,0xffff,0,0,0 }},   /* mask for the scale factor */
1400   {{ 0x8000,0,0,0,0,0,0,0 }},   /* mask for the horizontal flip */
1401   {{ 0,0,0,0,0,0,0x00ff,0 }},   /* mask for the order */
1402   {{ 0,0x0e00,0,0,0,0,0,0 }},   /* mask for the priority */
1403   {{ 0 }}                  /* mask for the VRAM target */
1404};
1405
1406static const atarirle_desc modesc_0x400 =
1407{
1408   "gfx3",      /* region where the GFX data lives */
1409   256,      /* number of entries in sprite RAM */
1410   0,         /* left clip coordinate */
1411   0,         /* right clip coordinate */
1412
1413   0x400,      /* base palette entry */
1414   0x400,      /* maximum number of colors */
1415
1416   {{ 0x7fff,0,0,0,0,0,0,0 }},   /* mask for the code index */
1417   {{ 0,0x03f0,0,0,0,0,0,0 }},   /* mask for the color */
1418   {{ 0,0,0xffc0,0,0,0,0,0 }},   /* mask for the X position */
1419   {{ 0,0,0,0xffc0,0,0,0,0 }},   /* mask for the Y position */
1420   {{ 0,0,0,0,0xffff,0,0,0 }},   /* mask for the scale factor */
1421   {{ 0x8000,0,0,0,0,0,0,0 }},   /* mask for the horizontal flip */
1422   {{ 0,0,0,0,0,0,0x00ff,0 }},   /* mask for the order */
1423   {{ 0,0x0e00,0,0,0,0,0,0 }},   /* mask for the priority */
1424   {{ 0 }}                  /* mask for the VRAM target */
1425};
1426
1427
1428
13851429/*************************************
13861430 *
13871431 *  Machine driver
r10427r10428
14111455   MCFG_SCREEN_RAW_PARAMS(ATARI_CLOCK_14MHz/2, 456, 0, 336, 262, 0, 240)
14121456
14131457   MCFG_VIDEO_START(atarigx2)
1414   MCFG_VIDEO_EOF(atarirle)
1458   MCFG_VIDEO_EOF(atarigx2)
14151459   MCFG_VIDEO_UPDATE(atarigx2)
14161460
14171461   /* sound hardware */
r10427r10428
14191463MACHINE_CONFIG_END
14201464
14211465
1466static MACHINE_CONFIG_DERIVED( atarigx2_0x200, atarigx2 )
1467   MCFG_ATARIRLE_ADD( "rle", modesc_0x200 )
1468MACHINE_CONFIG_END
14221469
1470static MACHINE_CONFIG_DERIVED( atarigx2_0x400, atarigx2 )
1471   MCFG_ATARIRLE_ADD( "rle", modesc_0x400 )
1472MACHINE_CONFIG_END
1473
14231474/*************************************
14241475 *
14251476 *  ROM definition(s)
r10427r10428
21482199   atarijsa_init(machine, "SERVICE", 0x0040);
21492200
21502201   state->playfield_base = 0x000;
2151   state->motion_object_base = 0x400;
2152   state->motion_object_mask = 0x3ff;
21532202}
21542203
21552204
r10427r10428
21602209   atarijsa_init(machine, "SERVICE", 0x0040);
21612210
21622211   state->playfield_base = 0x400;
2163   state->motion_object_base = 0x200;
2164   state->motion_object_mask = 0x1ff;
21652212/*
21662213L/W=!68.A23*!E.A22*!E.A21                                       = 000x xxxx = 000000-1fffff
21672214   +68.A23*E.A22*E.A21*68.A20*68.A19*68.A18*68.A17              = 1111 111x = fe0000-ffffff
r10427r10428
21982245   atarijsa_init(machine, "SERVICE", 0x0040);
21992246
22002247   state->playfield_base = 0x000;
2201   state->motion_object_base = 0x400;
2202   state->motion_object_mask = 0x3ff;
22032248
22042249   memory_install_read32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xca0fc0, 0xca0fc3, 0, 0, rrreveng_prot_r);
22052250}
r10427r10428
22122257 *
22132258 *************************************/
22142259
2215GAME( 1992, spclords,  0,        atarigx2, spclords, spclords, ROT0, "Atari Games", "Space Lords (rev C)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
2216GAME( 1992, spclordsb, spclords, atarigx2, spclords, spclords, ROT0, "Atari Games", "Space Lords (rev B)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
2217GAME( 1992, spclordsg, spclords, atarigx2, spclords, spclords, ROT0, "Atari Games", "Space Lords (rev A, German)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
2218GAME( 1992, spclordsa, spclords, atarigx2, spclords, spclords, ROT0, "Atari Games", "Space Lords (rev A)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
2260GAME( 1992, spclords,  0,        atarigx2_0x400, spclords, spclords, ROT0, "Atari Games", "Space Lords (rev C)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
2261GAME( 1992, spclordsb, spclords, atarigx2_0x400, spclords, spclords, ROT0, "Atari Games", "Space Lords (rev B)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
2262GAME( 1992, spclordsg, spclords, atarigx2_0x400, spclords, spclords, ROT0, "Atari Games", "Space Lords (rev A, German)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
2263GAME( 1992, spclordsa, spclords, atarigx2_0x400, spclords, spclords, ROT0, "Atari Games", "Space Lords (rev A)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
22192264
2220GAME( 1992, motofren,   0,        atarigx2, motofren, motofren, ROT0, "Atari Games", "Moto Frenzy", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
2221GAME( 1992, motofrenmd, motofren, atarigx2, motofren, motofren, ROT0, "Atari Games", "Moto Frenzy (Mini Deluxe)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
2222GAME( 1992, motofrenft, motofren, atarigx2, motofren, motofren, ROT0, "Atari Games", "Moto Frenzy (Field Test Version)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
2223GAME( 1992, motofrenmf, motofren, atarigx2, motofren, motofren, ROT0, "Atari Games", "Moto Frenzy (Mini Deluxe Field Test Version)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
2265GAME( 1992, motofren,   0,        atarigx2_0x200, motofren, motofren, ROT0, "Atari Games", "Moto Frenzy", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
2266GAME( 1992, motofrenmd, motofren, atarigx2_0x200, motofren, motofren, ROT0, "Atari Games", "Moto Frenzy (Mini Deluxe)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
2267GAME( 1992, motofrenft, motofren, atarigx2_0x200, motofren, motofren, ROT0, "Atari Games", "Moto Frenzy (Field Test Version)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
2268GAME( 1992, motofrenmf, motofren, atarigx2_0x200, motofren, motofren, ROT0, "Atari Games", "Moto Frenzy (Mini Deluxe Field Test Version)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
22242269
2225GAME( 1993, rrreveng,  0,        atarigx2, rrreveng, rrreveng, ROT0, "Atari Games", "Road Riot's Revenge (prototype, Sep 06, 1994)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
2226GAME( 1993, rrrevenga, rrreveng, atarigx2, rrreveng, rrreveng, ROT0, "Atari Games", "Road Riot's Revenge (prototype, Jan 27, 1994, set 1)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
2227GAME( 1993, rrrevengb, rrreveng, atarigx2, rrreveng, rrreveng, ROT0, "Atari Games", "Road Riot's Revenge (prototype, Jan 27, 1994, set 2)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
2270GAME( 1993, rrreveng,  0,        atarigx2_0x400, rrreveng, rrreveng, ROT0, "Atari Games", "Road Riot's Revenge (prototype, Sep 06, 1994)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
2271GAME( 1993, rrrevenga, rrreveng, atarigx2_0x400, rrreveng, rrreveng, ROT0, "Atari Games", "Road Riot's Revenge (prototype, Jan 27, 1994, set 1)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
2272GAME( 1993, rrrevengb, rrreveng, atarigx2_0x400, rrreveng, rrreveng, ROT0, "Atari Games", "Road Riot's Revenge (prototype, Jan 27, 1994, set 2)", GAME_UNEMULATED_PROTECTION | GAME_NOT_WORKING )
src/mame/drivers/nwk-tr.c
r10427r10428
225225#include "video/voodoo.h"
226226#include "video/konicdev.h"
227227
228static UINT8 led_reg0, led_reg1;
229228
230static UINT32 *work_ram;
229class nwktr_state : public driver_device
230{
231public:
232   nwktr_state(running_machine &machine, const driver_device_config_base &config)
233      : driver_device(machine, config) { }
231234
235   UINT8 led_reg0;
236   UINT8 led_reg1;
237   UINT32 *work_ram;
238   int fpga_uploaded;
239   int lanc2_ram_r;
240   int lanc2_ram_w;
241   UINT8 *lanc2_ram;
242   UINT32 *sharc_dataram;
243};
232244
245
246
247
248
233249static WRITE32_HANDLER( paletteram32_w )
234250{
235251   COMBINE_DATA(&space->machine->generic.paletteram.u32[offset]);
r10427r10428
245261
246262static VIDEO_UPDATE( nwktr )
247263{
264   nwktr_state *state = screen->machine->driver_data<nwktr_state>();
248265   device_t *voodoo = screen->machine->device("voodoo");
249266   device_t *k001604 = screen->machine->device("k001604");
250267
r10427r10428
254271
255272   k001604_draw_front_layer(k001604, bitmap, cliprect);
256273
257   draw_7segment_led(bitmap, 3, 3, led_reg0);
258   draw_7segment_led(bitmap, 9, 3, led_reg1);
274   draw_7segment_led(bitmap, 3, 3, state->led_reg0);
275   draw_7segment_led(bitmap, 9, 3, state->led_reg1);
259276   return 0;
260277}
261278
r10427r10428
296313
297314static WRITE32_HANDLER( sysreg_w )
298315{
316   nwktr_state *state = space->machine->driver_data<nwktr_state>();
299317   device_t *adc12138 = space->machine->device("adc12138");
300318   if( offset == 0 )
301319   {
302320      if (ACCESSING_BITS_24_31)
303321      {
304         led_reg0 = (data >> 24) & 0xff;
322         state->led_reg0 = (data >> 24) & 0xff;
305323      }
306324      if (ACCESSING_BITS_16_23)
307325      {
308         led_reg1 = (data >> 16) & 0xff;
326         state->led_reg1 = (data >> 16) & 0xff;
309327      }
310328      return;
311329   }
r10427r10428
338356   }
339357}
340358
341static int fpga_uploaded = 0;
342static int lanc2_ram_r = 0;
343static int lanc2_ram_w = 0;
344static UINT8 *lanc2_ram;
345359
346360static void lanc2_init(running_machine *machine)
347361{
348   fpga_uploaded = 0;
349   lanc2_ram_r = 0;
350   lanc2_ram_w = 0;
351   lanc2_ram = auto_alloc_array(machine, UINT8, 0x8000);
362   nwktr_state *state = machine->driver_data<nwktr_state>();
363   state->fpga_uploaded = 0;
364   state->lanc2_ram_r = 0;
365   state->lanc2_ram_w = 0;
366   state->lanc2_ram = auto_alloc_array(machine, UINT8, 0x8000);
352367}
353368
354369static READ32_HANDLER( lanc1_r )
355370{
371   nwktr_state *state = space->machine->driver_data<nwktr_state>();
356372   switch (offset)
357373   {
358374      case 0x40/4:
359375      {
360376         UINT32 r = 0;
361377
362         r |= (fpga_uploaded) ? (1 << 6) : 0;
378         r |= (state->fpga_uploaded) ? (1 << 6) : 0;
363379         r |= 1 << 5;
364380
365381         return (r) << 24;
r10427r10428
380396
381397static READ32_HANDLER( lanc2_r )
382398{
399   nwktr_state *state = space->machine->driver_data<nwktr_state>();
383400   UINT32 r = 0;
384401
385402   if (offset == 0)
386403   {
387404      if (ACCESSING_BITS_0_7)
388405      {
389         r |= lanc2_ram[lanc2_ram_r & 0x7fff];
390         lanc2_ram_r++;
406         r |= state->lanc2_ram[state->lanc2_ram_r & 0x7fff];
407         state->lanc2_ram_r++;
391408      }
392409      else
393410      {
r10427r10428
410427
411428static WRITE32_HANDLER( lanc2_w )
412429{
430   nwktr_state *state = space->machine->driver_data<nwktr_state>();
413431   if (offset == 0)
414432   {
415433      if (ACCESSING_BITS_24_31)
r10427r10428
425443               ((value << 5) & 0x40) |
426444               ((value << 7) & 0x80);
427445
428         fpga_uploaded = 1;
446         state->fpga_uploaded = 1;
429447
430448         //printf("lanc2_fpga_w: %02X at %08X\n", value, cpu_get_pc(space->cpu));
431449      }
432450      else if (ACCESSING_BITS_0_7)
433451      {
434         lanc2_ram[lanc2_ram_w & 0x7fff] = data & 0xff;
435         lanc2_ram_w++;
452         state->lanc2_ram[state->lanc2_ram_w & 0x7fff] = data & 0xff;
453         state->lanc2_ram_w++;
436454      }
437455      else
438456      {
r10427r10428
443461   {
444462      if (mame_stricmp(space->machine->gamedrv->name, "thrilld") == 0)
445463      {
446         work_ram[(0x3ffed0/4) + 0] = 0x472a3731;
447         work_ram[(0x3ffed0/4) + 1] = 0x33202020;
448         work_ram[(0x3ffed0/4) + 2] = 0x2d2d2a2a;
449         work_ram[(0x3ffed0/4) + 3] = 0x2a207878;
464         state->work_ram[(0x3ffed0/4) + 0] = 0x472a3731;
465         state->work_ram[(0x3ffed0/4) + 1] = 0x33202020;
466         state->work_ram[(0x3ffed0/4) + 2] = 0x2d2d2a2a;
467         state->work_ram[(0x3ffed0/4) + 3] = 0x2a207878;
450468
451         work_ram[(0x3fff40/4) + 0] = 0x47433731;
452         work_ram[(0x3fff40/4) + 1] = 0x33000000;
453         work_ram[(0x3fff40/4) + 2] = 0x19994a41;
454         work_ram[(0x3fff40/4) + 3] = 0x4100a9b1;
469         state->work_ram[(0x3fff40/4) + 0] = 0x47433731;
470         state->work_ram[(0x3fff40/4) + 1] = 0x33000000;
471         state->work_ram[(0x3fff40/4) + 2] = 0x19994a41;
472         state->work_ram[(0x3fff40/4) + 3] = 0x4100a9b1;
455473      }
456474   }
457475
r10427r10428
462480
463481static MACHINE_START( nwktr )
464482{
483   nwktr_state *state = machine->driver_data<nwktr_state>();
465484   /* set conservative DRC options */
466485   ppcdrc_set_options(machine->device("maincpu"), PPCDRC_COMPATIBLE_OPTIONS);
467486
468487   /* configure fast RAM regions for DRC */
469   ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x003fffff, FALSE, work_ram);
488   ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x003fffff, FALSE, state->work_ram);
470489}
471490
472491static ADDRESS_MAP_START( nwktr_map, ADDRESS_SPACE_PROGRAM, 32 )
473   AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_BASE(&work_ram)      /* Work RAM */
492   AM_RANGE(0x00000000, 0x003fffff) AM_RAM AM_BASE_MEMBER(nwktr_state, work_ram)      /* Work RAM */
474493   AM_RANGE(0x74000000, 0x740000ff) AM_DEVREADWRITE("k001604", k001604_reg_r, k001604_reg_w)
475494   AM_RANGE(0x74010000, 0x74017fff) AM_RAM_WRITE(paletteram32_w) AM_BASE_GENERIC(paletteram)
476495   AM_RANGE(0x74020000, 0x7403ffff) AM_DEVREADWRITE("k001604", k001604_tile_r, k001604_tile_w)
r10427r10428
502521
503522/*****************************************************************************/
504523
505static UINT32 *sharc_dataram;
506524
507525static READ32_HANDLER( dsp_dataram_r )
508526{
509   return sharc_dataram[offset] & 0xffff;
527   nwktr_state *state = space->machine->driver_data<nwktr_state>();
528   return state->sharc_dataram[offset] & 0xffff;
510529}
511530
512531static WRITE32_HANDLER( dsp_dataram_w )
513532{
514   sharc_dataram[offset] = data;
533   nwktr_state *state = space->machine->driver_data<nwktr_state>();
534   state->sharc_dataram[offset] = data;
515535}
516536
517537static ADDRESS_MAP_START( sharc_map, ADDRESS_SPACE_DATA, 32 )
r10427r10428
652672   cputag_set_input_line(machine, "dsp", INPUT_LINE_RESET, ASSERT_LINE);
653673}
654674
655static MACHINE_CONFIG_START( nwktr, driver_device )
675static MACHINE_CONFIG_START( nwktr, nwktr_state )
656676
657677   /* basic machine hardware */
658678   MCFG_CPU_ADD("maincpu", PPC403GA, 64000000/2)   /* PowerPC 403GA 32MHz */
r10427r10428
715735
716736static DRIVER_INIT(nwktr)
717737{
738   nwktr_state *state = machine->driver_data<nwktr_state>();
718739   init_konami_cgboard(machine, 1, CGBOARD_TYPE_NWKTR);
719740   set_cgboard_texture_bank(machine, 0, "bank5", machine->region("user5")->base());
720741
721   sharc_dataram = auto_alloc_array(machine, UINT32, 0x100000/4);
722   led_reg0 = led_reg1 = 0x7f;
742   state->sharc_dataram = auto_alloc_array(machine, UINT32, 0x100000/4);
743   state->led_reg0 = state->led_reg1 = 0x7f;
723744
724745   lanc2_init(machine);
725746}
src/mame/drivers/twin16.c
r10427r10428
5353#include "includes/twin16.h"
5454#include "includes/konamipt.h"
5555
56UINT16 twin16_custom_video;
57UINT16 *twin16_gfx_rom;
58UINT16 *twin16_sprite_gfx_ram;
59UINT16 *twin16_tile_gfx_ram;
60UINT16 *twin16_text_ram;
6156
62static UINT16 twin16_CPUA_register, twin16_CPUB_register;
6357
64#define CPUA_IRQ_ENABLE (twin16_CPUA_register & 0x20)
65#define CPUB_IRQ_ENABLE (twin16_CPUB_register & 0x02)
58#define CPUA_IRQ_ENABLE (state->CPUA_register & 0x20)
59#define CPUB_IRQ_ENABLE (state->CPUB_register & 0x02)
6660
67static UINT16 twin16_sound_command;
6861
69static int cuebrickj_nvram_bank;
70static UINT16 cuebrickj_nvram[0x400*0x20];   // 32k paged in a 1k window
7162
7263
73int twin16_spriteram_process_enable( void )
64int twin16_spriteram_process_enable( running_machine *machine )
7465{
75   return (twin16_CPUA_register & 0x40) == 0;
66   twin16_state *state = machine->driver_data<twin16_state>();
67   return (state->CPUA_register & 0x40) == 0;
7668}
7769
7870/******************************************************************************************/
r10427r10428
10395
10496static READ16_HANDLER( twin16_gfx_rom1_r )
10597{
106   return twin16_gfx_rom[offset + ((twin16_CPUB_register&0x04)?0x40000:0)];
98   twin16_state *state = space->machine->driver_data<twin16_state>();
99   return state->gfx_rom[offset + ((state->CPUB_register&0x04)?0x40000:0)];
107100}
108101
109102static READ16_HANDLER( twin16_gfx_rom2_r )
110103{
111   return twin16_gfx_rom[offset + 0x80000 + ((twin16_CPUB_register&0x04)?0x40000:0)];
104   twin16_state *state = space->machine->driver_data<twin16_state>();
105   return state->gfx_rom[offset + 0x80000 + ((state->CPUB_register&0x04)?0x40000:0)];
112106}
113107
114108static WRITE16_HANDLER( sound_command_w )
115109{
116   COMBINE_DATA(&twin16_sound_command);
117   soundlatch_w( space, 0, twin16_sound_command&0xff );
110   twin16_state *state = space->machine->driver_data<twin16_state>();
111   COMBINE_DATA(&state->sound_command);
112   soundlatch_w( space, 0, state->sound_command&0xff );
118113}
119114
120115static WRITE16_HANDLER( twin16_CPUA_register_w )
121116{
117   twin16_state *state = space->machine->driver_data<twin16_state>();
122118   /*
123119    7   6   5   4   3   2   1   0
124120        X                           sprite processing disable
r10427r10428
127123                    X               0->1 trigger IRQ on sound CPU
128124                        x   x   x   coin counters
129125    */
130   UINT16 old = twin16_CPUA_register;
131   COMBINE_DATA(&twin16_CPUA_register);
132   if (twin16_CPUA_register != old)
126   UINT16 old = state->CPUA_register;
127   COMBINE_DATA(&state->CPUA_register);
128   if (state->CPUA_register != old)
133129   {
134      if ((old & 0x08) == 0 && (twin16_CPUA_register & 0x08))
130      if ((old & 0x08) == 0 && (state->CPUA_register & 0x08))
135131         cputag_set_input_line_and_vector(space->machine, "audiocpu", 0, HOLD_LINE, 0xff);
136132
137      if ((old & 0x40) && (twin16_CPUA_register & 0x40) == 0)
133      if ((old & 0x40) && (state->CPUA_register & 0x40) == 0)
138134         twin16_spriteram_process(space->machine);
139135
140      if ((old & 0x10) == 0 && (twin16_CPUA_register & 0x10))
136      if ((old & 0x10) == 0 && (state->CPUA_register & 0x10))
141137         cputag_set_input_line(space->machine, "sub", M68K_IRQ_6, HOLD_LINE);
142138
143      coin_counter_w(space->machine, 0, twin16_CPUA_register & 0x01);
144      coin_counter_w(space->machine, 1, twin16_CPUA_register & 0x02);
145      coin_counter_w(space->machine, 2, twin16_CPUA_register & 0x04);
139      coin_counter_w(space->machine, 0, state->CPUA_register & 0x01);
140      coin_counter_w(space->machine, 1, state->CPUA_register & 0x02);
141      coin_counter_w(space->machine, 2, state->CPUA_register & 0x04);
146142   }
147143}
148144
149145static WRITE16_HANDLER( twin16_CPUB_register_w )
150146{
147   twin16_state *state = space->machine->driver_data<twin16_state>();
151148   /*
152149    7   6   5   4   3   2   1   0
153150                        X           gfx bank select
154151                            X       IRQ5 enable
155152                                X   0->1 trigger IRQ6 on CPUA
156153    */
157   UINT16 old = twin16_CPUB_register;
158   COMBINE_DATA(&twin16_CPUB_register);
159   if( twin16_CPUB_register!=old )
154   UINT16 old = state->CPUB_register;
155   COMBINE_DATA(&state->CPUB_register);
156   if( state->CPUB_register!=old )
160157   {
161      if ((old & 0x01) == 0 && (twin16_CPUB_register & 0x01))
158      if ((old & 0x01) == 0 && (state->CPUB_register & 0x01))
162159         cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_6, HOLD_LINE);
163160   }
164161}
165162
166163static WRITE16_HANDLER( fround_CPU_register_w )
167164{
165   twin16_state *state = space->machine->driver_data<twin16_state>();
168166   /*
169167    7   6   5   4   3   2   1   0
170168                    X               0->1 trigger IRQ on sound CPU
171169                            x   x   coin counters
172170    */
173   UINT16 old = twin16_CPUA_register;
174   COMBINE_DATA(&twin16_CPUA_register);
175   if (twin16_CPUA_register != old)
171   UINT16 old = state->CPUA_register;
172   COMBINE_DATA(&state->CPUA_register);
173   if (state->CPUA_register != old)
176174   {
177      if ((old & 0x08) == 0 && (twin16_CPUA_register & 0x08))
175      if ((old & 0x08) == 0 && (state->CPUA_register & 0x08))
178176         cputag_set_input_line_and_vector(space->machine, "audiocpu", 0, HOLD_LINE, 0xff);
179177
180      coin_counter_w(space->machine, 0, twin16_CPUA_register & 0x01);
181      coin_counter_w(space->machine, 1, twin16_CPUA_register & 0x02);
178      coin_counter_w(space->machine, 0, state->CPUA_register & 0x01);
179      coin_counter_w(space->machine, 1, state->CPUA_register & 0x02);
182180   }
183181}
184182
r10427r10428
215213
216214static READ16_HANDLER( cuebrickj_nvram_r )
217215{
218   return cuebrickj_nvram[offset + (cuebrickj_nvram_bank * 0x400 / 2)];
216   twin16_state *state = space->machine->driver_data<twin16_state>();
217   return state->cuebrickj_nvram[offset + (state->cuebrickj_nvram_bank * 0x400 / 2)];
219218}
220219
221220static WRITE16_HANDLER( cuebrickj_nvram_w )
222221{
223   COMBINE_DATA(&cuebrickj_nvram[offset + (cuebrickj_nvram_bank * 0x400 / 2)]);
222   twin16_state *state = space->machine->driver_data<twin16_state>();
223   COMBINE_DATA(&state->cuebrickj_nvram[offset + (state->cuebrickj_nvram_bank * 0x400 / 2)]);
224224}
225225
226226static WRITE16_HANDLER( cuebrickj_nvram_bank_w )
227227{
228   cuebrickj_nvram_bank = (data >> 8);
228   twin16_state *state = space->machine->driver_data<twin16_state>();
229   state->cuebrickj_nvram_bank = (data >> 8);
229230}
230231
231232/* Memory Maps */
r10427r10428
257258   AM_RANGE(0x0b0400, 0x0b0401) AM_WRITE(cuebrickj_nvram_bank_w)
258259   AM_RANGE(0x0c0000, 0x0c000f) AM_WRITE(twin16_video_register_w)
259260   AM_RANGE(0x0c000e, 0x0c000f) AM_READ(twin16_sprite_status_r)
260   AM_RANGE(0x100000, 0x103fff) AM_RAM_WRITE(twin16_text_ram_w) AM_BASE(&twin16_text_ram)
261   AM_RANGE(0x100000, 0x103fff) AM_RAM_WRITE(twin16_text_ram_w) AM_BASE_MEMBER(twin16_state, text_ram)
261262//  AM_RANGE(0x104000, 0x105fff) AM_NOP             // miaj
262263   AM_RANGE(0x120000, 0x123fff) AM_RAM AM_BASE_MEMBER(twin16_state, videoram)
263264   AM_RANGE(0x140000, 0x143fff) AM_RAM AM_SHARE("share1") AM_BASE_SIZE_GENERIC(spriteram)
r10427r10428
272273   AM_RANGE(0x0a0000, 0x0a0001) AM_WRITE(twin16_CPUB_register_w)
273274   AM_RANGE(0x400000, 0x403fff) AM_RAM AM_SHARE("share1")
274275   AM_RANGE(0x480000, 0x483fff) AM_READWRITE(videoram16_r, videoram16_w)
275   AM_RANGE(0x500000, 0x53ffff) AM_RAM AM_BASE(&twin16_tile_gfx_ram)
276   AM_RANGE(0x500000, 0x53ffff) AM_RAM AM_BASE_MEMBER(twin16_state, tile_gfx_ram)
276277   AM_RANGE(0x600000, 0x6fffff) AM_READ(twin16_gfx_rom1_r)
277278   AM_RANGE(0x700000, 0x77ffff) AM_READ(twin16_gfx_rom2_r)
278   AM_RANGE(0x780000, 0x79ffff) AM_RAM AM_BASE(&twin16_sprite_gfx_ram)
279   AM_RANGE(0x780000, 0x79ffff) AM_RAM AM_BASE_MEMBER(twin16_state, sprite_gfx_ram)
279280ADDRESS_MAP_END
280281
281282static ADDRESS_MAP_START( fround_map, ADDRESS_SPACE_PROGRAM, 16 )
r10427r10428
290291   AM_RANGE(0x0c0000, 0x0c000f) AM_WRITE(twin16_video_register_w)
291292   AM_RANGE(0x0c000e, 0x0c000f) AM_READ(twin16_sprite_status_r)
292293   AM_RANGE(0x0e0000, 0x0e0001) AM_WRITE(fround_gfx_bank_w)
293   AM_RANGE(0x100000, 0x103fff) AM_RAM_WRITE(twin16_text_ram_w) AM_BASE(&twin16_text_ram)
294   AM_RANGE(0x100000, 0x103fff) AM_RAM_WRITE(twin16_text_ram_w) AM_BASE_MEMBER(twin16_state, text_ram)
294295   AM_RANGE(0x120000, 0x123fff) AM_RAM AM_BASE_MEMBER(twin16_state, videoram)
295296   AM_RANGE(0x140000, 0x143fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram)
296297   AM_RANGE(0x500000, 0x6fffff) AM_READ(twin16_gfx_rom1_r)
r10427r10428
690691
691692static INTERRUPT_GEN( CPUA_interrupt )
692693{
694   twin16_state *state = device->machine->driver_data<twin16_state>();
693695   if (CPUA_IRQ_ENABLE) cpu_set_input_line(device, 5, HOLD_LINE);
694696}
695697
696698static INTERRUPT_GEN( CPUB_interrupt )
697699{
700   twin16_state *state = device->machine->driver_data<twin16_state>();
698701   if (CPUB_IRQ_ENABLE) cpu_set_input_line(device, 5, HOLD_LINE);
699702}
700703
r10427r10428
707710
708711static MACHINE_START( twin16 )
709712{
710   twin16_CPUA_register=0;
711   twin16_CPUB_register=0;
713   twin16_state *state = machine->driver_data<twin16_state>();
714   state->CPUA_register=0;
715   state->CPUB_register=0;
712716
713717   /* register for savestates */
714   state_save_register_global(machine, twin16_CPUA_register);
715   state_save_register_global(machine, twin16_CPUB_register);
718   state_save_register_global(machine, state->CPUA_register);
719   state_save_register_global(machine, state->CPUB_register);
716720
717   state_save_register_global(machine, twin16_sound_command);
718   state_save_register_global(machine, cuebrickj_nvram_bank);
719   state_save_register_global_array(machine, cuebrickj_nvram);
721   state_save_register_global(machine, state->sound_command);
722   state_save_register_global(machine, state->cuebrickj_nvram_bank);
723   state_save_register_global_array(machine, state->cuebrickj_nvram);
720724}
721725
722726static MACHINE_CONFIG_START( twin16, twin16_state )
r10427r10428
13031307
13041308static void gfx_untangle( running_machine *machine )
13051309{
1310   twin16_state *state = machine->driver_data<twin16_state>();
13061311   // sprite, tile data
13071312   int i;
13081313   UINT16 *temp = auto_alloc_array(machine, UINT16, 0x200000/2);
13091314
1310   twin16_gfx_rom = (UINT16 *)machine->region("gfx2")->base();
1311   memcpy( temp, twin16_gfx_rom, 0x200000 );
1315   state->gfx_rom = (UINT16 *)machine->region("gfx2")->base();
1316   memcpy( temp, state->gfx_rom, 0x200000 );
13121317
13131318   for( i=0; i<0x080000; i++ )
13141319   {
1315      twin16_gfx_rom[i*2+0] = temp[i+0x080000];
1316      twin16_gfx_rom[i*2+1] = temp[i];
1320      state->gfx_rom[i*2+0] = temp[i+0x080000];
1321      state->gfx_rom[i*2+1] = temp[i];
13171322   }
13181323   auto_free( machine, temp );
13191324}
13201325
13211326static DRIVER_INIT( twin16 )
13221327{
1328   twin16_state *state = machine->driver_data<twin16_state>();
13231329   gfx_untangle(machine);
1324   twin16_custom_video = 0;
1330   state->custom_video = 0;
13251331}
13261332
13271333static DRIVER_INIT( fround )
13281334{
1335   twin16_state *state = machine->driver_data<twin16_state>();
13291336   gfx_untangle(machine);
1330   twin16_custom_video = 1;
1337   state->custom_video = 1;
13311338}
13321339
13331340static DRIVER_INIT( cuebrickj )
13341341{
1342   twin16_state *state = machine->driver_data<twin16_state>();
13351343   gfx_untangle(machine);
13361344
1337   machine->device<nvram_device>("nvram")->set_base(cuebrickj_nvram, 0x400*0x20);
1345   machine->device<nvram_device>("nvram")->set_base(state->cuebrickj_nvram, 0x400*0x20);
13381346}
13391347
13401348/* Game Drivers */
src/mame/drivers/konamim2.c
r10427r10428
190190#include "cdrom.h"
191191#include "cpu/powerpc/ppc.h"
192192
193static UINT64 *main_ram;
194193
195static UINT32 vdl0_address;
196static UINT32 vdl1_address;
194typedef struct
195{
196   UINT32 dst_addr;
197   int length;
198   UINT32 next_dst_addr;
199   int next_length;
200   int dma_done;
201} CDE_DMA;
197202
198static UINT32 irq_enable;
199static UINT32 irq_active;
203class konamim2_state : public driver_device
204{
205public:
206   konamim2_state(running_machine &machine, const driver_device_config_base &config)
207      : driver_device(machine, config) { }
200208
209   UINT64 *main_ram;
210   UINT32 vdl0_address;
211   UINT32 vdl1_address;
212   UINT32 irq_enable;
213   UINT32 irq_active;
214   UINT64 unk3;
215   UINT32 unk20004;
216   int counter1;
217   int cde_num_status_bytes;
218   UINT32 cde_status_bytes[16];
219   int cde_status_byte_ptr;
220   UINT32 cde_command_bytes[16];
221   int cde_command_byte_ptr;
222   int cde_response;
223   int cde_drive_state;
224   int cde_enable_qchannel_reports;
225   int cde_enable_seek_reports;
226   int cde_qchannel_offset;
227   cdrom_toc cde_toc;
228   CDE_DMA cde_dma[2];
229};
230
231
201232static VIDEO_START( m2 )
202233{
203234}
204235
205236static VIDEO_UPDATE( m2 )
206237{
238   konamim2_state *state = screen->machine->driver_data<konamim2_state>();
207239   int i, j;
208240
209241   UINT32 fb_start = 0xffffffff;
210   if (vdl0_address != 0)
242   if (state->vdl0_address != 0)
211243   {
212      fb_start = *(UINT32*)&main_ram[(vdl0_address - 0x40000000) / 8] - 0x40000000;
244      fb_start = *(UINT32*)&state->main_ram[(state->vdl0_address - 0x40000000) / 8] - 0x40000000;
213245   }
214246
215247   if (fb_start <= 0x800000)
216248   {
217      UINT16 *frame = (UINT16*)&main_ram[fb_start/8];
249      UINT16 *frame = (UINT16*)&state->main_ram[fb_start/8];
218250      for (j=0; j < 384; j++)
219251      {
220252         UINT16 *fb = &frame[(j*512)];
r10427r10428
234266
235267static READ64_HANDLER(irq_enable_r)
236268{
269   konamim2_state *state = space->machine->driver_data<konamim2_state>();
237270   UINT64 r = 0;
238271
239272   if (ACCESSING_BITS_32_63)
240273   {
241      r |= (UINT64)(irq_enable) << 32;
274      r |= (UINT64)(state->irq_enable) << 32;
242275   }
243276
244277   return r;
r10427r10428
246279
247280static WRITE64_HANDLER(irq_enable_w)
248281{
282   konamim2_state *state = space->machine->driver_data<konamim2_state>();
249283   if (ACCESSING_BITS_32_63)
250284   {
251      irq_enable |= (UINT32)(data >> 32);
285      state->irq_enable |= (UINT32)(data >> 32);
252286   }
253287}
254288
255289static READ64_HANDLER(irq_active_r)
256290{
291   konamim2_state *state = space->machine->driver_data<konamim2_state>();
257292   UINT64 r = 0;
258293
259294   if (ACCESSING_BITS_32_63)
260295   {
261      r |= (UINT64)(irq_active) << 32;
296      r |= (UINT64)(state->irq_active) << 32;
262297   }
263298
264299   return r;
r10427r10428
283318}
284319#endif
285320
286static UINT64 unk3;
287321static READ64_HANDLER(unk3_r)
288322{
323   konamim2_state *state = space->machine->driver_data<konamim2_state>();
289324   //return U64(0xffffffffffffffff);
290   return unk3;
325   return state->unk3;
291326}
292327
293static UINT32 unk20004 = 0;
294328static READ64_HANDLER(unk4_r)
295329{
330   konamim2_state *state = space->machine->driver_data<konamim2_state>();
296331   UINT64 r = 0;
297332//  logerror("unk4_r: %08X, %08X%08X at %08X\n", offset, (UINT32)(mem_mask>>32), (UINT32)(mem_mask), cpu_get_pc(space->cpu));
298333
r10427r10428
303338   }
304339   if (ACCESSING_BITS_0_31)
305340   {
306      r |= unk20004 & ~0x800000;
341      r |= state->unk20004 & ~0x800000;
307342   }
308343   return r;
309344}
310345
311346static WRITE64_HANDLER(unk4_w)
312347{
348   konamim2_state *state = space->machine->driver_data<konamim2_state>();
313349//  logerror("unk4_w: %08X%08X, %08X, %08X%08X at %08X\n", (UINT32)(data >> 32), (UINT32)(data),
314350//      offset, (UINT32)(mem_mask>>32), (UINT32)(mem_mask), cpu_get_pc(space->cpu));
315351
r10427r10428
321357         cputag_set_input_line(space->machine, "sub", INPUT_LINE_IRQ0, ASSERT_LINE);
322358      }
323359
324      unk20004 = (UINT32)(data);
360      state->unk20004 = (UINT32)(data);
325361      return;
326362   }
327363}
328364
329static int counter1 = 0;
330365static READ64_HANDLER(unk30000_r)
331366{
332   counter1++;
333   return (UINT64)(counter1 & 0x7f) << 32;
367   konamim2_state *state = space->machine->driver_data<konamim2_state>();
368   state->counter1++;
369   return (UINT64)(state->counter1 & 0x7f) << 32;
334370}
335371
336372static READ64_HANDLER(unk30030_r)
r10427r10428
344380
345381static WRITE64_HANDLER(video_w)
346382{
383   konamim2_state *state = space->machine->driver_data<konamim2_state>();
347384   if (ACCESSING_BITS_32_63)
348385   {
349      vdl0_address = (UINT32)(data >> 32);
386      state->vdl0_address = (UINT32)(data >> 32);
350387   }
351388   if (ACCESSING_BITS_0_31)
352389   {
353      vdl1_address = (UINT32)(data);
390      state->vdl1_address = (UINT32)(data);
354391   }
355392}
356393
357394static WRITE64_HANDLER(video_irq_ack_w)
358395{
396   konamim2_state *state = space->machine->driver_data<konamim2_state>();
359397   if (ACCESSING_BITS_32_63)
360398   {
361399      if ((data >> 32) & 0x8000)
362400      {
363         irq_active &= ~0x800000;
401         state->irq_active &= ~0x800000;
364402      }
365403   }
366404}
r10427r10428
409447
410448static WRITE64_HANDLER(reset_w)
411449{
450   konamim2_state *state = space->machine->driver_data<konamim2_state>();
412451   if (ACCESSING_BITS_32_63)
413452   {
414453      if (data & U64(0x100000000))
415454      {
416455         cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_RESET, PULSE_LINE);
417         unk3 = 0;
456         state->unk3 = 0;
418457      }
419458   }
420459}
r10427r10428
423462/*****************************************************************************/
424463/* CDE */
425464
426typedef struct
427{
428   UINT32 dst_addr;
429   int length;
430   UINT32 next_dst_addr;
431   int next_length;
432   int dma_done;
433} CDE_DMA;
434
435465#define CDE_DRIVE_STATE_PAUSED         0x02
436466#define CDE_DRIVE_STATE_SEEK_DONE      0x03
437467
438static int cde_num_status_bytes = 0;
439static UINT32 cde_status_bytes[16];
440static int cde_status_byte_ptr = 0;
441468
442static UINT32 cde_command_bytes[16];
443static int cde_command_byte_ptr = 0;
444469
445static int cde_response = 0;
446static int cde_drive_state = 0;
447470
448static int cde_enable_qchannel_reports = 0;
449static int cde_enable_seek_reports = 0;
450471
451static int cde_qchannel_offset = 0;
452472
453static cdrom_toc cde_toc;
454473
455static CDE_DMA cde_dma[2];
456474
457475
458476static void cde_init(running_machine *machine)
459477{
478   konamim2_state *state = machine->driver_data<konamim2_state>();
460479   cdrom_file *cd = cdrom_open(get_disk_handle(machine, "cdrom"));
461480   const cdrom_toc *toc = cdrom_get_toc(cd);
462481
463482   if (cd)
464483   {
465      memcpy(&cde_toc, toc, sizeof(cdrom_toc));
484      memcpy(&state->cde_toc, toc, sizeof(cdrom_toc));
466485   }
467486
468487   /*
r10427r10428
480499      cdrom_close(cd);
481500   }
482501
483   cde_drive_state = CDE_DRIVE_STATE_PAUSED;
502   state->cde_drive_state = CDE_DRIVE_STATE_PAUSED;
484503
485   cde_num_status_bytes = 0;
486   cde_status_byte_ptr = 0;
487   cde_command_byte_ptr = 0;
504   state->cde_num_status_bytes = 0;
505   state->cde_status_byte_ptr = 0;
506   state->cde_command_byte_ptr = 0;
488507
489   cde_response = 0;
508   state->cde_response = 0;
490509
491   cde_enable_qchannel_reports = 0;
492   cde_enable_seek_reports = 0;
510   state->cde_enable_qchannel_reports = 0;
511   state->cde_enable_seek_reports = 0;
493512
494   cde_qchannel_offset = 0;
513   state->cde_qchannel_offset = 0;
495514}
496515
497static void cde_handle_command(void)
516static void cde_handle_command(running_machine *machine)
498517{
499   switch (cde_command_bytes[0])
518   konamim2_state *state = machine->driver_data<konamim2_state>();
519   switch (state->cde_command_bytes[0])
500520   {
501521      case 0x04:      // Set Speed
502522      {
503         cde_num_status_bytes = 1;
523         state->cde_num_status_bytes = 1;
504524
505         cde_status_bytes[0] = 0x04;
506         cde_status_byte_ptr = 0;
525         state->cde_status_bytes[0] = 0x04;
526         state->cde_status_byte_ptr = 0;
507527
508         mame_printf_debug("CDE: SET SPEED %02X, %02X\n", cde_command_bytes[1], cde_command_bytes[2]);
528         mame_printf_debug("CDE: SET SPEED %02X, %02X\n", state->cde_command_bytes[1], state->cde_command_bytes[2]);
509529         break;
510530      }
511531      case 0x06:      // Audio Format / Data Format
512532      {
513         cde_num_status_bytes = 1;
533         state->cde_num_status_bytes = 1;
514534
515         cde_status_bytes[0] = 0x06;
516         cde_status_byte_ptr = 0;
535         state->cde_status_bytes[0] = 0x06;
536         state->cde_status_byte_ptr = 0;
517537
518         if (cde_command_bytes[1] == 0x00)      // Audio Format
538         if (state->cde_command_bytes[1] == 0x00)      // Audio Format
519539         {
520540            mame_printf_debug("CDE: AUDIO FORMAT\n");
521541         }
522         else if (cde_command_bytes[1] == 0x78)   // Data Format
542         else if (state->cde_command_bytes[1] == 0x78)   // Data Format
523543         {
524544            mame_printf_debug("CDE: DATA FORMAT\n");
525545         }
526546         else
527547         {
528            fatalerror("CDE: unknown command %02X, %02X\n", cde_command_bytes[0], cde_command_bytes[1]);
548            fatalerror("CDE: unknown command %02X, %02X\n", state->cde_command_bytes[0], state->cde_command_bytes[1]);
529549         }
530550         break;
531551      }
532552      case 0x08:      // Pause / Eject / Play
533553      {
534         cde_num_status_bytes = 1;
554         state->cde_num_status_bytes = 1;
535555
536         cde_status_bytes[0] = 0x08;
537         cde_status_byte_ptr = 0;
556         state->cde_status_bytes[0] = 0x08;
557         state->cde_status_byte_ptr = 0;
538558
539         if (cde_command_bytes[1] == 0x00)      // Eject
559         if (state->cde_command_bytes[1] == 0x00)      // Eject
540560         {
541561            mame_printf_debug("CDE: EJECT command\n");
542562         }
543         else if (cde_command_bytes[1] == 0x02)   // Pause
563         else if (state->cde_command_bytes[1] == 0x02)   // Pause
544564         {
545565            mame_printf_debug("CDE: PAUSE command\n");
546            cde_drive_state = CDE_DRIVE_STATE_PAUSED;
566            state->cde_drive_state = CDE_DRIVE_STATE_PAUSED;
547567         }
548         else if (cde_command_bytes[1] == 0x03)   // Play
568         else if (state->cde_command_bytes[1] == 0x03)   // Play
549569         {
550570            mame_printf_debug("CDE: PLAY command\n");
551571         }
552572         else
553573         {
554            fatalerror("CDE: unknown command %02X, %02X\n", cde_command_bytes[0], cde_command_bytes[1]);
574            fatalerror("CDE: unknown command %02X, %02X\n", state->cde_command_bytes[0], state->cde_command_bytes[1]);
555575         }
556576         break;
557577      }
558578      case 0x09:      // Seek
559579      {
560         cde_num_status_bytes = 1;
580         state->cde_num_status_bytes = 1;
561581
562         cde_status_bytes[0] = 0x1b;
563         cde_status_byte_ptr = 0;
582         state->cde_status_bytes[0] = 0x1b;
583         state->cde_status_byte_ptr = 0;
564584
565         cde_drive_state = CDE_DRIVE_STATE_SEEK_DONE;
585         state->cde_drive_state = CDE_DRIVE_STATE_SEEK_DONE;
566586
567         mame_printf_debug("CDE: SEEK %08X\n", (cde_command_bytes[1] << 16) | (cde_command_bytes[2] << 8) | (cde_command_bytes[3]));
587         mame_printf_debug("CDE: SEEK %08X\n", (state->cde_command_bytes[1] << 16) | (state->cde_command_bytes[2] << 8) | (state->cde_command_bytes[3]));
568588         break;
569589      }
570590      case 0x0b:      // Get Drive State
571591      {
572         cde_num_status_bytes = 0x3;
592         state->cde_num_status_bytes = 0x3;
573593
574         cde_status_bytes[0] = 0x0b;
575         cde_status_bytes[1] = 0x1b;
576         cde_status_bytes[2] = cde_drive_state;
577         cde_status_byte_ptr = 0;
594         state->cde_status_bytes[0] = 0x0b;
595         state->cde_status_bytes[1] = 0x1b;
596         state->cde_status_bytes[2] = state->cde_drive_state;
597         state->cde_status_byte_ptr = 0;
578598
579         if (cde_command_bytes[1] & 0x02)
599         if (state->cde_command_bytes[1] & 0x02)
580600         {
581            cde_enable_seek_reports = 1;
601            state->cde_enable_seek_reports = 1;
582602         }
583603         else
584604         {
585            cde_enable_seek_reports = 0;
605            state->cde_enable_seek_reports = 0;
586606         }
587607
588         mame_printf_debug("CDE: GET DRIVE STATE %02X\n", cde_command_bytes[1]);
608         mame_printf_debug("CDE: GET DRIVE STATE %02X\n", state->cde_command_bytes[1]);
589609         break;
590610      }
591611      case 0x0c:      // ?
592612      {
593         cde_num_status_bytes = 1;
613         state->cde_num_status_bytes = 1;
594614
595         cde_status_bytes[0] = 0x0c;
596         cde_status_byte_ptr = 0;
615         state->cde_status_bytes[0] = 0x0c;
616         state->cde_status_byte_ptr = 0;
597617
598         if (cde_command_bytes[1] == 0x02)
618         if (state->cde_command_bytes[1] == 0x02)
599619         {
600            cde_enable_qchannel_reports = 1;
601            cde_drive_state = CDE_DRIVE_STATE_PAUSED;
620            state->cde_enable_qchannel_reports = 1;
621            state->cde_drive_state = CDE_DRIVE_STATE_PAUSED;
602622         }
603         else if (cde_command_bytes[0] == 0x00)
623         else if (state->cde_command_bytes[0] == 0x00)
604624         {
605            cde_enable_qchannel_reports = 0;
625            state->cde_enable_qchannel_reports = 0;
606626         }
607627
608         mame_printf_debug("CDE: UNKNOWN CMD 0x0c %02X\n", cde_command_bytes[1]);
628         mame_printf_debug("CDE: UNKNOWN CMD 0x0c %02X\n", state->cde_command_bytes[1]);
609629         break;
610630      }
611631      case 0x0d:      // Get Switch State
612632      {
613         cde_num_status_bytes = 0x4;
633         state->cde_num_status_bytes = 0x4;
614634
615         cde_status_bytes[0] = 0x0d;
616         cde_status_bytes[1] = 0x1d;
617         cde_status_bytes[2] = 0x02;
618         cde_status_byte_ptr = 0;
635         state->cde_status_bytes[0] = 0x0d;
636         state->cde_status_bytes[1] = 0x1d;
637         state->cde_status_bytes[2] = 0x02;
638         state->cde_status_byte_ptr = 0;
619639
620         mame_printf_debug("CDE: GET SWITCH STATE %02X\n", cde_command_bytes[1]);
640         mame_printf_debug("CDE: GET SWITCH STATE %02X\n", state->cde_command_bytes[1]);
621641         break;
622642      }
623643      case 0x21:      // Mech type
624644      {
625         cde_num_status_bytes = 0x8;
645         state->cde_num_status_bytes = 0x8;
626646
627         cde_status_bytes[0] = 0x21;
628         cde_status_bytes[1] = 0xff;
629         cde_status_bytes[2] = 0x08;      // Max Speed
630         cde_status_bytes[3] = 0xff;
631         cde_status_bytes[4] = 0xff;
632         cde_status_bytes[5] = 0xff;
633         cde_status_bytes[6] = 0xff;
634         cde_status_bytes[7] = 0xff;
647         state->cde_status_bytes[0] = 0x21;
648         state->cde_status_bytes[1] = 0xff;
649         state->cde_status_bytes[2] = 0x08;      // Max Speed
650         state->cde_status_bytes[3] = 0xff;
651         state->cde_status_bytes[4] = 0xff;
652         state->cde_status_bytes[5] = 0xff;
653         state->cde_status_bytes[6] = 0xff;
654         state->cde_status_bytes[7] = 0xff;
635655
636         cde_status_byte_ptr = 0;
656         state->cde_status_byte_ptr = 0;
637657
638         mame_printf_debug("CDE: MECH TYPE %02X, %02X, %02X\n", cde_command_bytes[1], cde_command_bytes[2], cde_command_bytes[3]);
658         mame_printf_debug("CDE: MECH TYPE %02X, %02X, %02X\n", state->cde_command_bytes[1], state->cde_command_bytes[2], state->cde_command_bytes[3]);
639659         break;
640660      }
641661      case 0x83:      // Read ID
642662      {
643         cde_num_status_bytes = 0xc;
663         state->cde_num_status_bytes = 0xc;
644664
645         cde_status_bytes[0] = 0x03;
646         cde_status_bytes[1] = 0xff;
647         cde_status_bytes[2] = 0xff;
648         cde_status_bytes[3] = 0xff;
649         cde_status_bytes[4] = 0xff;
650         cde_status_bytes[5] = 0xff;
651         cde_status_bytes[6] = 0xff;
652         cde_status_bytes[7] = 0xff;
653         cde_status_bytes[8] = 0xff;
654         cde_status_bytes[9] = 0xff;
655         cde_status_bytes[10] = 0xff;
656         cde_status_bytes[11] = 0xff;
665         state->cde_status_bytes[0] = 0x03;
666         state->cde_status_bytes[1] = 0xff;
667         state->cde_status_bytes[2] = 0xff;
668         state->cde_status_bytes[3] = 0xff;
669         state->cde_status_bytes[4] = 0xff;
670         state->cde_status_bytes[5] = 0xff;
671         state->cde_status_bytes[6] = 0xff;
672         state->cde_status_bytes[7] = 0xff;
673         state->cde_status_bytes[8] = 0xff;
674         state->cde_status_bytes[9] = 0xff;
675         state->cde_status_bytes[10] = 0xff;
676         state->cde_status_bytes[11] = 0xff;
657677
658         cde_status_byte_ptr = 0;
678         state->cde_status_byte_ptr = 0;
659679
660680         mame_printf_debug("CDE: READ ID\n");
661681         break;
662682      }
663683      default:
664684      {
665         fatalerror("CDE: unknown command %08X\n", cde_command_bytes[0]);
685         fatalerror("CDE: unknown command %08X\n", state->cde_command_bytes[0]);
666686         break;
667687      }
668688   }
669689}
670690
671static void cde_handle_reports(void)
691static void cde_handle_reports(running_machine *machine)
672692{
673   switch (cde_command_bytes[0])
693   konamim2_state *state = machine->driver_data<konamim2_state>();
694   switch (state->cde_command_bytes[0])
674695   {
675696      case 0x09:
676697      {
677         if (cde_enable_seek_reports)
698         if (state->cde_enable_seek_reports)
678699         {
679            cde_num_status_bytes = 0x2;
680            cde_status_bytes[0] = 0x02;
700            state->cde_num_status_bytes = 0x2;
701            state->cde_status_bytes[0] = 0x02;
681702
682            cde_status_byte_ptr = 0;
703            state->cde_status_byte_ptr = 0;
683704
684            cde_command_bytes[0] = 0x0c;
705            state->cde_command_bytes[0] = 0x0c;
685706
686707            mame_printf_debug("CDE: SEEK REPORT\n");
687708         }
r10427r10428
690711
691712      case 0x0b:
692713      {
693         if (cde_enable_qchannel_reports)
714         if (state->cde_enable_qchannel_reports)
694715         {
695716            int track, num_tracks;
696717
697            num_tracks = cde_toc.numtrks;
698            track = cde_qchannel_offset % (num_tracks+3);
718            num_tracks = state->cde_toc.numtrks;
719            track = state->cde_qchannel_offset % (num_tracks+3);
699720
700            cde_num_status_bytes = 0xb;
701            cde_status_bytes[0] = 0x1c;
721            state->cde_num_status_bytes = 0xb;
722            state->cde_status_bytes[0] = 0x1c;
702723
703724            /*
704                cde_status_bytes[1] = 0x0;      // q-Mode
705                cde_status_bytes[2] = 0x0;      // TNO
706                cde_status_bytes[3] = 0x0;      // Index / Pointer
707                cde_status_bytes[4] = 0x0;      // Min
708                cde_status_bytes[5] = 0x0;      // Sec
709                cde_status_bytes[6] = 0x0;      // Frac
710                cde_status_bytes[7] = 0x0;      // Zero
711                cde_status_bytes[8] = 0x0;      // A-Min
712                cde_status_bytes[9] = 0x0;      // A-Sec
713                cde_status_bytes[10] = 0x0;     // A-Frac
725                state->cde_status_bytes[1] = 0x0;      // q-Mode
726                state->cde_status_bytes[2] = 0x0;      // TNO
727                state->cde_status_bytes[3] = 0x0;      // Index / Pointer
728                state->cde_status_bytes[4] = 0x0;      // Min
729                state->cde_status_bytes[5] = 0x0;      // Sec
730                state->cde_status_bytes[6] = 0x0;      // Frac
731                state->cde_status_bytes[7] = 0x0;      // Zero
732                state->cde_status_bytes[8] = 0x0;      // A-Min
733                state->cde_status_bytes[9] = 0x0;      // A-Sec
734                state->cde_status_bytes[10] = 0x0;     // A-Frac
714735                */
715736
716737            if (track < num_tracks)
717738            {
718               int time = lba_to_msf(cde_toc.tracks[track].physframeofs);
739               int time = lba_to_msf(state->cde_toc.tracks[track].physframeofs);
719740
720               cde_status_bytes[1] = 0x41;               // q-Mode
721               cde_status_bytes[2] = 0x0;               // TNO (Lead-in track)
722               cde_status_bytes[3] = track+1;            // Pointer
723               cde_status_bytes[4] = 0x0;               // Min
724               cde_status_bytes[5] = 0x0;               // Sec
725               cde_status_bytes[6] = 0x0;               // Frac
726               cde_status_bytes[7] = 0x0;               // Zero
727               cde_status_bytes[8] = (time >> 16) & 0xff;   // P-Min
728               cde_status_bytes[9] = (time >>  8) & 0xff;   // P-Sec
729               cde_status_bytes[10] = time & 0xff;         // P-Frac
741               state->cde_status_bytes[1] = 0x41;               // q-Mode
742               state->cde_status_bytes[2] = 0x0;               // TNO (Lead-in track)
743               state->cde_status_bytes[3] = track+1;            // Pointer
744               state->cde_status_bytes[4] = 0x0;               // Min
745               state->cde_status_bytes[5] = 0x0;               // Sec
746               state->cde_status_bytes[6] = 0x0;               // Frac
747               state->cde_status_bytes[7] = 0x0;               // Zero
748               state->cde_status_bytes[8] = (time >> 16) & 0xff;   // P-Min
749               state->cde_status_bytes[9] = (time >>  8) & 0xff;   // P-Sec
750               state->cde_status_bytes[10] = time & 0xff;         // P-Frac
730751            }
731752            else
732753            {
733754               if (track == num_tracks+0)
734755               {
735                  cde_status_bytes[1] = 0x41;               // q-Mode / Control
736                  cde_status_bytes[2] = 0x0;               // TNO (Lead-in track)
737                  cde_status_bytes[3] = 0xa0;               // Pointer
738                  cde_status_bytes[4] = 0x0;               // Min
739                  cde_status_bytes[5] = 0x0;               // Sec
740                  cde_status_bytes[6] = 0x0;               // Frac
741                  cde_status_bytes[7] = 0x0;               // Zero
742                  cde_status_bytes[8] = 1;               // P-Min
743                  cde_status_bytes[9] = 0x0;               // P-Sec
744                  cde_status_bytes[10] = 0x0;               // P-Frac
756                  state->cde_status_bytes[1] = 0x41;               // q-Mode / Control
757                  state->cde_status_bytes[2] = 0x0;               // TNO (Lead-in track)
758                  state->cde_status_bytes[3] = 0xa0;               // Pointer
759                  state->cde_status_bytes[4] = 0x0;               // Min
760                  state->cde_status_bytes[5] = 0x0;               // Sec
761                  state->cde_status_bytes[6] = 0x0;               // Frac
762                  state->cde_status_bytes[7] = 0x0;               // Zero
763                  state->cde_status_bytes[8] = 1;               // P-Min
764                  state->cde_status_bytes[9] = 0x0;               // P-Sec
765                  state->cde_status_bytes[10] = 0x0;               // P-Frac
745766               }
746767               else if (track == num_tracks+1)
747768               {
748                  cde_status_bytes[1] = 0x41;               // q-Mode / Control
749                  cde_status_bytes[2] = 0x0;               // TNO (Lead-in track)
750                  cde_status_bytes[3] = 0xa1;               // Pointer
751                  cde_status_bytes[4] = 0x0;               // Min
752                  cde_status_bytes[5] = 0x0;               // Sec
753                  cde_status_bytes[6] = 0x0;               // Frac
754                  cde_status_bytes[7] = 0x0;               // Zero
755                  cde_status_bytes[8] = num_tracks;         // P-Min
756                  cde_status_bytes[9] = 0x0;               // P-Sec
757                  cde_status_bytes[10] = 0x0;               // P-Frac
769                  state->cde_status_bytes[1] = 0x41;               // q-Mode / Control
770                  state->cde_status_bytes[2] = 0x0;               // TNO (Lead-in track)
771                  state->cde_status_bytes[3] = 0xa1;               // Pointer
772                  state->cde_status_bytes[4] = 0x0;               // Min
773                  state->cde_status_bytes[5] = 0x0;               // Sec
774                  state->cde_status_bytes[6] = 0x0;               // Frac
775                  state->cde_status_bytes[7] = 0x0;               // Zero
776                  state->cde_status_bytes[8] = num_tracks;         // P-Min
777                  state->cde_status_bytes[9] = 0x0;               // P-Sec
778                  state->cde_status_bytes[10] = 0x0;               // P-Frac
758779               }
759780               else
760781               {
761                  int leadout_lba = cde_toc.tracks[num_tracks-1].physframeofs + cde_toc.tracks[num_tracks-1].frames;
782                  int leadout_lba = state->cde_toc.tracks[num_tracks-1].physframeofs + state->cde_toc.tracks[num_tracks-1].frames;
762783                  int leadout_time = lba_to_msf(leadout_lba);
763784
764                  cde_status_bytes[1] = 0x41;               // q-Mode / Control
765                  cde_status_bytes[2] = 0x0;               // TNO (Lead-in track)
766                  cde_status_bytes[3] = 0xa2;               // Pointer
767                  cde_status_bytes[4] = 0x0;               // Min
768                  cde_status_bytes[5] = 0x0;               // Sec
769                  cde_status_bytes[6] = 0x0;               // Frac
770                  cde_status_bytes[7] = 0x0;               // Zero
771                  cde_status_bytes[8] = (leadout_time >> 16) & 0xff;   // P-Min
772                  cde_status_bytes[9] = (leadout_time >>  8) & 0xff;   // P-Sec
773                  cde_status_bytes[10] = leadout_time & 0xff;         // P-Frac
785                  state->cde_status_bytes[1] = 0x41;               // q-Mode / Control
786                  state->cde_status_bytes[2] = 0x0;               // TNO (Lead-in track)
787                  state->cde_status_bytes[3] = 0xa2;               // Pointer
788                  state->cde_status_bytes[4] = 0x0;               // Min
789                  state->cde_status_bytes[5] = 0x0;               // Sec
790                  state->cde_status_bytes[6] = 0x0;               // Frac
791                  state->cde_status_bytes[7] = 0x0;               // Zero
792                  state->cde_status_bytes[8] = (leadout_time >> 16) & 0xff;   // P-Min
793                  state->cde_status_bytes[9] = (leadout_time >>  8) & 0xff;   // P-Sec
794                  state->cde_status_bytes[10] = leadout_time & 0xff;         // P-Frac
774795               }
775796            }
776797
777            cde_qchannel_offset++;
798            state->cde_qchannel_offset++;
778799
779            cde_status_byte_ptr = 0;
780            cde_command_bytes[0] = 0x0c;
800            state->cde_status_byte_ptr = 0;
801            state->cde_command_bytes[0] = 0x0c;
781802
782803            mame_printf_debug("CDE: QCHANNEL REPORT\n");
783804            break;
r10427r10428
788809
789810static void cde_dma_transfer(address_space *space, int channel, int next)
790811{
812   konamim2_state *state = space->machine->driver_data<konamim2_state>();
791813   UINT32 address;
792814   //int length;
793815   int i;
794816
795817   if (next)
796818   {
797      address = cde_dma[channel].next_dst_addr;
798      //length = cde_dma[channel].next_length;
819      address = state->cde_dma[channel].next_dst_addr;
820      //length = state->cde_dma[channel].next_length;
799821   }
800822   else
801823   {
802      address = cde_dma[channel].dst_addr;
803      //length = cde_dma[channel].length;
824      address = state->cde_dma[channel].dst_addr;
825      //length = state->cde_dma[channel].length;
804826   }
805827
806   for (i=0; i < cde_dma[channel].next_length; i++)
828   for (i=0; i < state->cde_dma[channel].next_length; i++)
807829   {
808830      space->write_byte(address, 0xff);      // TODO: do the real transfer...
809831      address++;
r10427r10428
812834
813835static READ64_HANDLER(cde_r)
814836{
837   konamim2_state *state = space->machine->driver_data<konamim2_state>();
815838   UINT32 r = 0;
816839   int reg = offset * 2;
817840
r10427r10428
829852      {
830853         r = 0x100038;
831854
832         r |= cde_dma[0].dma_done ? 0x400 : 0;
833         r |= cde_dma[1].dma_done ? 0x800 : 0;
855         r |= state->cde_dma[0].dma_done ? 0x400 : 0;
856         r |= state->cde_dma[1].dma_done ? 0x800 : 0;
834857         break;
835858      }
836859      case 0x02c/4:
837860      {
838         r = cde_status_bytes[cde_status_byte_ptr++];
861         r = state->cde_status_bytes[state->cde_status_byte_ptr++];
839862
840         if (cde_status_byte_ptr <= cde_num_status_bytes)
863         if (state->cde_status_byte_ptr <= state->cde_num_status_bytes)
841864         {
842865            r |= 0x100;
843866         }
844867         else
845868         {
846869            //if (cde_enable_reports &&
847            //  !cde_response &&
848            //  cde_command_bytes[0] != ((cde_report_type >> 8) & 0xff))
870            //  !state->cde_response &&
871            //  state->cde_command_bytes[0] != ((cde_report_type >> 8) & 0xff))
849872
850            if (!cde_response)
873            if (!state->cde_response)
851874            {
852               cde_handle_reports();
875               cde_handle_reports(space->machine);
853876
854         //      cde_command_byte_ptr = 0;
855         //      cde_command_bytes[cde_command_byte_ptr++] = 0x1c;
877         //      state->cde_command_byte_ptr = 0;
878         //      state->cde_command_bytes[state->cde_command_byte_ptr++] = 0x1c;
856879
857         //      cde_response = 1;
880         //      state->cde_response = 1;
858881            }
859882         }
860883
861   //      printf("status byte %d\n", cde_status_byte_ptr);
884   //      printf("status byte %d\n", state->cde_status_byte_ptr);
862885         break;
863886      }
864887
r10427r10428
887910
888911static WRITE64_HANDLER(cde_w)
889912{
913   konamim2_state *state = space->machine->driver_data<konamim2_state>();
890914   int reg = offset * 2;
891915   UINT32 d;
892916
r10427r10428
908932
909933         if (d == 0x0180)
910934         {
911            if (cde_response)
935            if (state->cde_response)
912936            {
913               cde_handle_command();
937               cde_handle_command(space->machine);
914938
915               cde_response = 0;
939               state->cde_response = 0;
916940            }
917941
918            cde_command_byte_ptr = 0;
942            state->cde_command_byte_ptr = 0;
919943         }
920         else if (cde_command_byte_ptr == 0)
944         else if (state->cde_command_byte_ptr == 0)
921945         {
922            cde_num_status_bytes = 1;
946            state->cde_num_status_bytes = 1;
923947
924            cde_status_bytes[0] = d & 0xff;
925            cde_status_byte_ptr = 0;
948            state->cde_status_bytes[0] = d & 0xff;
949            state->cde_status_byte_ptr = 0;
926950
927            cde_response = 1;
951            state->cde_response = 1;
928952         }
929953
930954         if (d != 0x180)
931955         {
932            cde_command_bytes[cde_command_byte_ptr++] = d;
956            state->cde_command_bytes[state->cde_command_byte_ptr++] = d;
933957         }
934958
935959         break;
r10427r10428
941965
942966         if (d & 0x20)
943967         {
944            cde_dma[0].dma_done = 1;
968            state->cde_dma[0].dma_done = 1;
945969
946970            cde_dma_transfer(space, 0, 0);
947971         }
948972         if (d & 0x40)
949973         {
950            cde_dma[0].dma_done = 1;
974            state->cde_dma[0].dma_done = 1;
951975
952976            cde_dma_transfer(space, 0, 1);
953977         }
r10427r10428
957981      {
958982         mame_printf_debug("CDE: DMA0 dst addr %08X\n", d);
959983
960         cde_dma[0].dst_addr = d;
984         state->cde_dma[0].dst_addr = d;
961985         break;
962986      }
963987      case 0x30c/4:      // DMA Channel 0 length?
964988      {
965989         mame_printf_debug("CDE: DMA0 length %08X\n", d);
966990
967         cde_dma[0].length = d;
991         state->cde_dma[0].length = d;
968992         break;
969993      }
970994      case 0x318/4:      // DMA Channel 0 next destination address
971995      {
972996         mame_printf_debug("CDE: DMA0 next dst addr %08X\n", d);
973997
974         cde_dma[0].next_dst_addr = d;
998         state->cde_dma[0].next_dst_addr = d;
975999         break;
9761000      }
9771001      case 0x31c/4:      // DMA Channel 0 next length?
9781002      {
9791003         mame_printf_debug("CDE: DMA0 next length %08X\n", d);
9801004
981         cde_dma[0].next_length = d;
1005         state->cde_dma[0].next_length = d;
9821006         break;
9831007      }
9841008
r10427r10428
9911015      {
9921016         mame_printf_debug("CDE: DMA1 dst addr %08X\n", d);
9931017
994         cde_dma[1].dst_addr = d;
1018         state->cde_dma[1].dst_addr = d;
9951019         break;
9961020      }
9971021      case 0x32c/4:      // DMA Channel 1 length?
9981022      {
9991023         mame_printf_debug("CDE: DMA1 length %08X\n", d);
10001024
1001         cde_dma[1].length = d;
1025         state->cde_dma[1].length = d;
10021026         break;
10031027      }
10041028      case 0x338/4:      // DMA Channel 1 next destination address
10051029      {
10061030         mame_printf_debug("CDE: DMA1 next dst addr %08X\n", d);
10071031
1008         cde_dma[1].next_dst_addr = d;
1032         state->cde_dma[1].next_dst_addr = d;
10091033         break;
10101034      }
10111035      case 0x33c/4:      // DMA Channel 1 next length?
10121036      {
10131037         mame_printf_debug("CDE: DMA1 next length %08X\n", d);
10141038
1015         cde_dma[1].next_length = d;
1039         state->cde_dma[1].next_length = d;
10161040         break;
10171041      }
10181042
r10427r10428
10201044      {
10211045         if (d & 0x80000000)
10221046         {
1023            irq_active &= ~0x8;
1047            state->irq_active &= ~0x8;
10241048         }
10251049         if (d & 0x60000000)
10261050         {
1027            cde_dma[0].dma_done = 0;
1028            cde_dma[1].dma_done = 0;
1051            state->cde_dma[0].dma_done = 0;
1052            state->cde_dma[1].dma_done = 0;
10291053         }
10301054         break;
10311055      }
r10427r10428
11021126   AM_RANGE(0x10000000, 0x10000007) AM_READ(cpu_r)
11031127   AM_RANGE(0x10000008, 0x10001007) AM_NOP      // ???
11041128   AM_RANGE(0x20000000, 0x201fffff) AM_ROM AM_SHARE("share2")
1105   AM_RANGE(0x40000000, 0x407fffff) AM_RAM AM_SHARE("share3") AM_BASE(&main_ram)
1129   AM_RANGE(0x40000000, 0x407fffff) AM_RAM AM_SHARE("share3") AM_BASE_MEMBER(konamim2_state, main_ram)
11061130   AM_RANGE(0xfff00000, 0xffffffff) AM_ROM AM_REGION("boot", 0) AM_SHARE("share2")
11071131ADDRESS_MAP_END
11081132
r10427r10428
11171141
11181142static INTERRUPT_GEN(m2)
11191143{
1120   if (irq_enable & 0x800000)
1144   konamim2_state *state = device->machine->driver_data<konamim2_state>();
1145   if (state->irq_enable & 0x800000)
11211146   {
1122      irq_active |= 0x800000;
1147      state->irq_active |= 0x800000;
11231148   }
11241149
1125   /*if (irq_enable & 0x8)
1150   /*if (state->irq_enable & 0x8)
11261151    {
1127        irq_active |= 0x8;
1152        state->irq_active |= 0x8;
11281153    }*/
11291154
11301155   cpu_set_input_line(device, INPUT_LINE_IRQ0, ASSERT_LINE);
11311156}
11321157
1133static MACHINE_CONFIG_START( m2, driver_device )
1158static MACHINE_CONFIG_START( m2, konamim2_state )
11341159
11351160   /* basic machine hardware */
11361161   MCFG_CPU_ADD("maincpu", PPC602, 33000000)   /* actually PPC602, 66MHz */
r10427r10428
12571282
12581283static DRIVER_INIT( m2 )
12591284{
1260   unk3 = U64(0xffffffffffffffff);
1261   unk20004 = 0;
1285   konamim2_state *state = machine->driver_data<konamim2_state>();
1286   state->unk3 = U64(0xffffffffffffffff);
1287   state->unk20004 = 0;
12621288   cde_init(machine);
12631289}
12641290
src/mame/drivers/atarigt.c
r10427r10428
196196   /* upper byte */
197197   if (ACCESSING_BITS_24_31)
198198   {
199      atarigt_state *state = space->machine->driver_data<atarigt_state>();
200
199201      /* bits 13-11 are the MO control bits */
200      atarirle_control_w(space->machine, 0, (data >> 27) & 7);
202      atarirle_control_w(state->rle, (data >> 27) & 7);
201203   }
202204
203205   if (ACCESSING_BITS_16_23)
r10427r10428
214216   atarigt_state *state = space->machine->driver_data<atarigt_state>();
215217   COMBINE_DATA(state->mo_command);
216218   if (ACCESSING_BITS_0_15)
217      atarirle_command_w(0, ((data & 0xffff) == 2) ? ATARIRLE_COMMAND_CHECKSUM : ATARIRLE_COMMAND_DRAW);
219      atarirle_command_w(state->rle, ((data & 0xffff) == 2) ? ATARIRLE_COMMAND_CHECKSUM : ATARIRLE_COMMAND_DRAW);
218220}
219221
220222
r10427r10428
610612   AM_RANGE(0xd40000, 0xd4ffff) AM_WRITE(atarigen_eeprom_enable32_w)
611613   AM_RANGE(0xd72000, 0xd75fff) AM_WRITE(atarigen_playfield32_w) AM_BASE_MEMBER(atarigt_state, playfield32)
612614   AM_RANGE(0xd76000, 0xd76fff) AM_WRITE(atarigen_alpha32_w) AM_BASE_MEMBER(atarigt_state, alpha32)
613   AM_RANGE(0xd78000, 0xd78fff) AM_WRITE(atarirle_0_spriteram32_w) AM_BASE(&atarirle_0_spriteram32)
615   AM_RANGE(0xd78000, 0xd78fff) AM_DEVREADWRITE("rle", atarirle_spriteram32_r, atarirle_spriteram32_w)
614616   AM_RANGE(0xd7a200, 0xd7a203) AM_WRITE(mo_command_w) AM_BASE_MEMBER(atarigt_state, mo_command)
615617   AM_RANGE(0xd70000, 0xd7ffff) AM_RAM
616618   AM_RANGE(0xd80000, 0xdfffff) AM_READWRITE(colorram_protection_r, colorram_protection_w) AM_BASE_MEMBER(atarigt_state, colorram)
r10427r10428
780782GFXDECODE_END
781783
782784
785static const atarirle_desc modesc =
786{
787   "gfx3",      /* region where the GFX data lives */
788   256,      /* number of entries in sprite RAM */
789   0,         /* left clip coordinate */
790   0,         /* right clip coordinate */
783791
792   0x0000,      /* base palette entry */
793   0x1000,      /* maximum number of colors */
794
795   {{ 0x7fff,0,0,0,0,0,0,0 }},   /* mask for the code index */
796   {{ 0,0x0ff0,0,0,0,0,0,0 }},   /* mask for the color */
797   {{ 0,0,0xffc0,0,0,0,0,0 }},   /* mask for the X position */
798   {{ 0,0,0,0xffc0,0,0,0,0 }},   /* mask for the Y position */
799   {{ 0,0,0,0,0xffff,0,0,0 }},   /* mask for the scale factor */
800   {{ 0x8000,0,0,0,0,0,0,0 }},   /* mask for the horizontal flip */
801   {{ 0,0,0,0,0,0,0x00ff,0 }},   /* mask for the order */
802   {{ 0,0x0e00,0,0,0,0,0,0 }},   /* mask for the priority */
803   {{ 0,0x8000,0,0,0,0,0,0 }}   /* mask for the VRAM target */
804};
805
806
807
784808/*************************************
785809 *
786810 *  Machine driver
r10427r10428
811835   MCFG_SCREEN_RAW_PARAMS(ATARI_CLOCK_14MHz/2, 456, 0, 336, 262, 0, 240)
812836
813837   MCFG_VIDEO_START(atarigt)
814   MCFG_VIDEO_EOF(atarirle)
838   MCFG_VIDEO_EOF(atarigt)
815839   MCFG_VIDEO_UPDATE(atarigt)
816840
841   MCFG_ATARIRLE_ADD("rle", modesc)
842
817843   /* sound hardware */
818844   MCFG_FRAGMENT_ADD(cage)
819845MACHINE_CONFIG_END
src/osd/winui/treeview.c
r10427r10428
12391239               if (ROMREGION_ISROMDATA(region) || ROMREGION_ISDISKDATA(region) )
12401240               {
12411241                  //name = ROM_GETNAME(rom);
1242                  if (hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_BAD_DUMP))           
1242                  hash_collection hashes(ROM_GETHASHDATA(rom));                 
1243                  if (hashes.flag(hash_collection::FLAG_BAD_DUMP))
12431244                     bBadDump = TRUE;
1244                  if (hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP))           
1245                  if (hashes.flag(hash_collection::FLAG_NO_DUMP))
12451246                     bNoDump = TRUE;
12461247               }
12471248            }
src/osd/winui/swconfig.c
r10427r10428
2727   driver = drivers[driver_index];
2828   while ((driver) && (!config->hashfile))
2929   {
30      config->hashfile = hashfile_open(*opts, driver->name, TRUE, error_proc);
30      //config->hashfile = hashfile_open(*opts, driver->name, TRUE, error_proc);
3131      driver = driver_get_compatible(driver);
3232   }
3333
src/osd/winui/softwarepicker.c
r10427r10428
4242   const device_config_image_interface *device;
4343
4444   // hash information
45   char hash_string[HASH_BUF_SIZE];
45   //hash_collection hashes;
4646   BOOL hash_realized;
4747   const hash_info *hashinfo;
4848
r10427r10428
216216static void ComputeFileHash(software_picker_info *pPickerInfo,
217217   file_info *pFileInfo, const unsigned char *pBuffer, unsigned int nLength)
218218{
219   unsigned int functions;
219   const char *functions;
220220
221221   // determine which functions to use
222222   functions = hashfile_functions_used(pPickerInfo->config->hashfile, pFileInfo->device->image_type());
223223
224224   // compute the hash
225   pFileInfo->device->device_compute_hash((char *)pFileInfo->hash_string, (const void *)pBuffer, (size_t)nLength, functions);
225   //pFileInfo->device->device_compute_hash(pFileInfo->hashes, (const void *)pBuffer, (size_t)nLength, functions);
226226}
227227
228228
r10427r10428
325325{
326326   software_picker_info *pPickerInfo;
327327   file_info *pFileInfo;
328   unsigned int nHashFunctionsUsed = 0;
329   unsigned int nCalculatedHashes = 0;
330   iodevice_t type;
328//   const char *nHashFunctionsUsed = NULL;
329   //unsigned int nCalculatedHashes = 0;
330//   iodevice_t type;
331331
332332   pPickerInfo = GetSoftwarePickerInfo(hwndPicker);
333333   assert((nIndex >= 0) && (nIndex < pPickerInfo->file_index_length));
r10427r10428
335335
336336   // Determine which hash functions we need to use for this file, and which hashes
337337   // have already been calculated
338   if ((pPickerInfo->config->hashfile != NULL) && (pFileInfo->device != NULL))
338   /*if ((pPickerInfo->config->hashfile != NULL) && (pFileInfo->device != NULL))
339339   {
340340      type = pFileInfo->device->image_type();
341341      if (type < IO_COUNT)
342342           nHashFunctionsUsed = hashfile_functions_used(pPickerInfo->config->hashfile, type);
343343      nCalculatedHashes = hash_data_used_functions(pFileInfo->hash_string);
344   }
344   }*/
345345
346346   // Did we fully compute all hashes?
347   if ((nHashFunctionsUsed & ~nCalculatedHashes) == 0)
347/*   if ((nHashFunctionsUsed & ~nCalculatedHashes) == 0)
348348   {
349349      // We have calculated all hashs for this file; mark it as realized
350350      pPickerInfo->file_index[nIndex]->hash_realized = TRUE;
r10427r10428
353353      if (pPickerInfo->config->hashfile)
354354      {
355355         pPickerInfo->file_index[nIndex]->hashinfo = hashfile_lookup(pPickerInfo->config->hashfile,
356            pPickerInfo->file_index[nIndex]->hash_string);
356            pPickerInfo->file_index[nIndex]->hashes);
357357      }
358   }
358   }*/
359359}
360360
361361
r10427r10428
407407   pInfo->device = device;
408408   if ((device != NULL) && (device->has_partial_hash() != 0))
409409      nCrc = 0;
410   if (nCrc != 0)
411      snprintf(pInfo->hash_string, ARRAY_LENGTH(pInfo->hash_string), "c:%08x#", nCrc);
410   //if (nCrc != 0)
411      //snprintf(pInfo->hash_string, ARRAY_LENGTH(pInfo->hash_string), "c:%08x#", nCrc);
412412
413413   // set up zip entry name length, if specified
414414   if (nZipEntryNameLength > 0)
r10427r10428
727727   LPCTSTR s = NULL;
728728   const char *pszUtf8 = NULL;
729729   unsigned int nHashFunction = 0;
730   char szBuffer[256];
730//   char szBuffer[256];
731731   TCHAR* t_buf;
732732
733733   pPickerInfo = GetSoftwarePickerInfo(hwndPicker);
r10427r10428
785785      case MESS_COLUMN_SHA1:
786786      switch (nColumn)
787787         {
788            case MESS_COLUMN_CRC:   nHashFunction = HASH_CRC;   break;
789            case MESS_COLUMN_MD5:   nHashFunction = HASH_MD5;   break;
790            case MESS_COLUMN_SHA1:   nHashFunction = HASH_SHA1;   break;
788            case MESS_COLUMN_CRC:   nHashFunction = hash_collection::HASH_CRC;   break;
789            case MESS_COLUMN_MD5:   nHashFunction = hash_collection::HASH_MD5;   break;
790            case MESS_COLUMN_SHA1:   nHashFunction = hash_collection::HASH_SHA1;   break;
791791         }
792         if (hash_data_extract_printable_checksum(pFileInfo->hash_string, nHashFunction, szBuffer))
792/*         if (hash_data_extract_printable_checksum(pFileInfo->hash_string, nHashFunction, szBuffer))
793793         {
794794            t_buf = tstring_from_utf8(szBuffer);
795795            if( !t_buf )
r10427r10428
797797            _sntprintf(pszBuffer, nBufferLength, TEXT("%s"), t_buf);
798798            s = pszBuffer;
799799            osd_free(t_buf);
800         }
800         }*/
801801         break;
802802   }
803803   return s;
src/emu/cpu/sh2/sh2comn.h
r10427r10428
148148   UINT32 active_dma_count[2];
149149
150150   int     is_slave, cpu_type;
151   int  (*dma_callback_kludge)(UINT32 src, UINT32 dst, UINT32 data, int size);
152   int  (*dma_callback_fifo_data_available)(UINT32 src, UINT32 dst, UINT32 data, int size);
151   int  (*dma_callback_kludge)(device_t *device, UINT32 src, UINT32 dst, UINT32 data, int size);
152   int  (*dma_callback_fifo_data_available)(device_t *device, UINT32 src, UINT32 dst, UINT32 data, int size);
153153
154154   void   (*ftcsr_read_callback)(UINT32 data);
155155
src/emu/cpu/sh2/sh2.h
r10427r10428
6161struct _sh2_cpu_core
6262{
6363   int is_slave;
64   int  (*dma_callback_kludge)(UINT32 src, UINT32 dst, UINT32 data, int size);
65   int  (*dma_callback_fifo_data_available)(UINT32 src, UINT32 dst, UINT32 data, int size);
64   int  (*dma_callback_kludge)(device_t *device, UINT32 src, UINT32 dst, UINT32 data, int size);
65   int  (*dma_callback_fifo_data_available)(device_t *device, UINT32 src, UINT32 dst, UINT32 data, int size);
6666};
6767
6868DECLARE_LEGACY_CPU_DEVICE(SH1, sh1);
src/emu/cpu/sh2/sh2comn.c
r10427r10428
209209
210210            if (sh2->dma_callback_fifo_data_available)
211211            {
212               int available = sh2->dma_callback_fifo_data_available(tempsrc, tempdst, 0, sh2->active_dma_size[dma]);
212               int available = sh2->dma_callback_fifo_data_available(sh2->device, tempsrc, tempdst, 0, sh2->active_dma_size[dma]);
213213
214214               if (!available)
215215               {
r10427r10428
226226
227227
228228            dmadata = sh2->program->read_byte(tempsrc);
229            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
229            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(sh2->device, tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
230230            sh2->program->write_byte(tempdst, dmadata);
231231
232232            if(sh2->active_dma_incs[dma] == 2)
r10427r10428
257257
258258            if (sh2->dma_callback_fifo_data_available)
259259            {
260               int available = sh2->dma_callback_fifo_data_available(tempsrc, tempdst, 0, sh2->active_dma_size[dma]);
260               int available = sh2->dma_callback_fifo_data_available(sh2->device, tempsrc, tempdst, 0, sh2->active_dma_size[dma]);
261261
262262               if (!available)
263263               {
r10427r10428
274274
275275            // check: should this really be using read_word_32 / write_word_32?
276276            dmadata   = sh2->program->read_word(tempsrc);
277            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
277            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(sh2->device, tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
278278            sh2->program->write_word(tempdst, dmadata);
279279
280280            if(sh2->active_dma_incs[dma] == 2)
r10427r10428
304304
305305            if (sh2->dma_callback_fifo_data_available)
306306            {
307               int available = sh2->dma_callback_fifo_data_available(tempsrc, tempdst, 0, sh2->active_dma_size[dma]);
307               int available = sh2->dma_callback_fifo_data_available(sh2->device, tempsrc, tempdst, 0, sh2->active_dma_size[dma]);
308308
309309               if (!available)
310310               {
r10427r10428
320320            #endif
321321
322322            dmadata   = sh2->program->read_dword(tempsrc);
323            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
323            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(sh2->device, tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
324324            sh2->program->write_dword(tempdst, dmadata);
325325
326326            if(sh2->active_dma_incs[dma] == 2)
r10427r10428
349349
350350            if (sh2->dma_callback_fifo_data_available)
351351            {
352               int available = sh2->dma_callback_fifo_data_available(tempsrc, tempdst, 0, sh2->active_dma_size[dma]);
352               int available = sh2->dma_callback_fifo_data_available(sh2->device, tempsrc, tempdst, 0, sh2->active_dma_size[dma]);
353353
354354               if (!available)
355355               {
r10427r10428
365365            #endif
366366
367367            dmadata = sh2->program->read_dword(tempsrc);
368            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
368            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(sh2->device, tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
369369            sh2->program->write_dword(tempdst, dmadata);
370370
371371            dmadata = sh2->program->read_dword(tempsrc+4);
372            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
372            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(sh2->device, tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
373373            sh2->program->write_dword(tempdst+4, dmadata);
374374
375375            dmadata = sh2->program->read_dword(tempsrc+8);
376            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
376            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(sh2->device, tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
377377            sh2->program->write_dword(tempdst+8, dmadata);
378378
379379            dmadata = sh2->program->read_dword(tempsrc+12);
380            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
380            if (sh2->dma_callback_kludge) dmadata = sh2->dma_callback_kludge(sh2->device, tempsrc, tempdst, dmadata, sh2->active_dma_size[dma]);
381381            sh2->program->write_dword(tempdst+12, dmadata);
382382
383383            if(sh2->active_dma_incd[dma] == 2)
src/emu/cpu/sh2/sh2.c
r10427r10428
21472147   sh2_state *sh2 = get_safe_token(device);
21482148   emu_timer *tsave, *tsaved0, *tsaved1;
21492149   UINT32 *m;
2150   int  (*dma_callback_kludge)(UINT32 src, UINT32 dst, UINT32 data, int size);
2151   int  (*dma_callback_fifo_data_available)(UINT32 src, UINT32 dst, UINT32 data, int size);
2150   int  (*dma_callback_kludge)(device_t *device, UINT32 src, UINT32 dst, UINT32 data, int size);
2151   int  (*dma_callback_fifo_data_available)(device_t *device, UINT32 src, UINT32 dst, UINT32 data, int size);
21522152   int save_is_slave;
21532153
21542154   void (*f)(UINT32 data);
src/emu/video/tms9928a.c
r10427r10428
596596         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+1) = fg;
597597         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+2) = fg;
598598         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+3) = fg;
599         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+4) = fg;
600         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+5) = fg;
601         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+6) = fg;
602         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+7) = fg;
599         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+4) = bg;
600         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+5) = bg;
601         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+6) = bg;
602         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+7) = bg;
603603                }
604604            }
605605        }
r10427r10428
627627         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+1) = fg;
628628         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+2) = fg;
629629         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+3) = fg;
630         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+4) = fg;
631         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+5) = fg;
632         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+6) = fg;
633         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+7) = fg;
630         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+4) = bg;
631         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+5) = bg;
632         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+6) = bg;
633         *BITMAP_ADDR16(bitmap, y*8+yy*4+yyy, x*8+7) = bg;
634634                }
635635            }
636636        }
src/emu/video.c
r10427r10428
12021202   {
12031203      // try until we succeed
12041204      astring seqtext;
1205      file.set_openflags(OPEN_FLAG_READ);
12051206      for (int seq = 0; ; seq++)
12061207      {
12071208         // build up the filename
12081209         fname.cpy(snapstr).replace(0, "%i", seqtext.format("%04d", seq).cstr());
12091210
12101211         // try to open the file; stop when we fail
1211         file.set_openflags(OPEN_FLAG_READ);
12121212         file_error filerr = file.open(fname);
12131213         if (filerr != FILERR_NONE)
12141214            break;
src/emu/hashfile.c
r10427r10428
1818{
1919   emu_file *file;
2020   object_pool *pool;
21   unsigned int functions[IO_COUNT];
21   astring functions[IO_COUNT];
2222
2323   hash_info **preloaded_hashes;
2424   int preloaded_hash_count;
r10427r10428
4343   hash_file *hashfile;
4444   int done;
4545
46   int (*selector_proc)(hash_file *hashfile, void *param, const char *name, const char *hash);
46   int (*selector_proc)(hash_file *hashfile, void *param, const char *name, const hash_collection &hashes);
4747   void (*use_proc)(hash_file *hashfile, void *param, hash_info *hi);
4848   void (*error_proc)(const char *message);
4949   void *param;
r10427r10428
142142   const char *name;
143143   hash_info *hi;
144144   char **text_dest;
145   char hash_string[HASH_BUF_SIZE];
146   unsigned int functions, all_functions;
145   hash_collection hashes;
146   astring all_functions;
147   char functions;
147148   iodevice_t device;
148149   int i;
149150
r10427r10428
164165         {
165166            // we are now examining a hash tag
166167            name = NULL;
167            memset(hash_string, 0, sizeof(hash_string));
168            all_functions = 0;
169168            device = IO_COUNT;
170169
171170            while(attributes[0])
r10427r10428
179178               else if (!strcmp(attributes[0], "crc32"))
180179               {
181180                  /* crc32 attribute */
182                  functions = HASH_CRC;
181                  functions = hash_collection::HASH_CRC;
183182               }
184183               else if (!strcmp(attributes[0], "md5"))
185184               {
186185                  /* md5 attribute */
187                  functions = HASH_MD5;
186                  functions = hash_collection::HASH_MD5;
188187               }
189188               else if (!strcmp(attributes[0], "sha1"))
190189               {
191190                  /* sha1 attribute */
192                  functions = HASH_SHA1;
191                  functions = hash_collection::HASH_SHA1;
193192               }
194193               else if (!strcmp(attributes[0], "type"))
195194               {
r10427r10428
208207
209208               if (functions)
210209               {
211                  hash_data_insert_printable_checksum(hash_string, functions, attributes[1]);
212                  all_functions |= functions;
210                  hashes.add_from_string(functions, attributes[1], strlen(attributes[1]));
211                  all_functions.cat(functions);
213212               }
214213
215214               attributes += 2;
216215            }
217216
218            if (device == IO_COUNT)
219            {
220               for (i = 0; i < IO_COUNT; i++)
221                  state->hashfile->functions[i] |= all_functions;
222            }
223            else
224               state->hashfile->functions[device] |= all_functions;
217            for (i = 0; i < IO_COUNT; i++)
218               if (i == device || device == IO_COUNT)
219                  state->hashfile->functions[i] = all_functions;
225220
226221            /* do we use this hash? */
227            if (!state->selector_proc || state->selector_proc(state->hashfile, state->param, name, hash_string))
222            if (!state->selector_proc || state->selector_proc(state->hashfile, state->param, name, hashes))
228223            {
229224               hi = (hash_info*)pool_malloc_lib(state->hashfile->pool, sizeof(hash_info));
230225               if (!hi)
r10427r10428
235230               if (!hi->longname)
236231                  return;
237232
238               strcpy(hi->hash, hash_string);
233               hi->hashes = hashes;
239234               state->hi = hi;
240235            }
241236         }
r10427r10428
331326-------------------------------------------------*/
332327
333328static void hashfile_parse(hash_file *hashfile,
334   int (*selector_proc)(hash_file *hashfile, void *param, const char *name, const char *hash),
329   int (*selector_proc)(hash_file *hashfile, void *param, const char *name, const hash_collection &hashes),
335330   void (*use_proc)(hash_file *hashfile, void *param, hash_info *hi),
336331   void (*error_proc)(const char *message),
337332   void *param)
r10427r10428
469464
470465struct hashlookup_params
471466{
472   const char *hash;
467   hash_collection hashes;
473468   hash_info *hi;
474469};
475470
476static int singular_selector_proc(hash_file *hashfile, void *param, const char *name, const char *hash)
471static int singular_selector_proc(hash_file *hashfile, void *param, const char *name, const hash_collection &hashes)
477472{
478473   struct hashlookup_params *hlparams = (struct hashlookup_params *) param;
479   return hash_data_is_equal(hash, hlparams->hash,
480      hash_data_used_functions(hash)) == 1;
474   return (hashes == hlparams->hashes);
481475}
482476
483477
r10427r10428
498492    hashfile_lookup
499493-------------------------------------------------*/
500494
501const hash_info *hashfile_lookup(hash_file *hashfile, const char *hash)
495const hash_info *hashfile_lookup(hash_file *hashfile, const hash_collection &hashes)
502496{
503497   struct hashlookup_params param;
504498   int i;
505499
506   param.hash = hash;
500   param.hashes = hashes;
507501   param.hi = NULL;
508502
509503   for (i = 0; i < hashfile->preloaded_hash_count; i++)
510504   {
511      if (singular_selector_proc(hashfile, &param, NULL, hashfile->preloaded_hashes[i]->hash))
505      if (singular_selector_proc(hashfile, &param, NULL, hashfile->preloaded_hashes[i]->hashes))
512506         return hashfile->preloaded_hashes[i];
513507   }
514508
r10427r10428
523517    hashfile_functions_used
524518-------------------------------------------------*/
525519
526unsigned int hashfile_functions_used(hash_file *hashfile, iodevice_t devtype)
520const char *hashfile_functions_used(hash_file *hashfile, iodevice_t devtype)
527521{
528522   assert(devtype >= 0);
529523   assert(devtype < IO_COUNT);
src/emu/hashfile.h
r10427r10428
2020typedef struct _hash_info hash_info;
2121struct _hash_info
2222{
23   char hash[HASH_BUF_SIZE];
23   hash_collection hashes;
2424   const char *longname;
2525   const char *manufacturer;
2626   const char *year;
r10427r10428
4646void hashfile_close(hash_file *hashfile);
4747
4848/* looks up information in a hash file */
49const hash_info *hashfile_lookup(hash_file *hashfile, const char *hash);
49const hash_info *hashfile_lookup(hash_file *hashfile, const hash_collection &hashes);
5050
5151/* performs a syntax check on a hash file */
5252int hashfile_verify(const char *sysname, void (*error_proc)(const char *message));
5353
5454/* returns the functions used in this hash file */
55unsigned int hashfile_functions_used(hash_file *hashfile, iodevice_t devtype);
55const char *hashfile_functions_used(hash_file *hashfile, iodevice_t devtype);
5656
5757
5858#endif /* __HASHFILE_H__ */
src/emu/emu.h
r10427r10428
6262
6363// emulator-specific utilities
6464#include "attotime.h"
65#include "hash.h"
6566#include "fileio.h" // remove me once NVRAM is implemented as device
6667#include "tokenize.h"
6768#include "delegate.h"
src/emu/diimage.c
r10427r10428
142142    using this device's partial hash if appropriate
143143-------------------------------------------------*/
144144
145void device_config_image_interface::device_compute_hash(char *dest, const void *data, size_t length, unsigned int functions) const
145void device_config_image_interface::device_compute_hash(hash_collection &hashes, const void *data, size_t length, const char *types) const
146146{
147147   /* retrieve the partial hash func */
148148   device_image_partialhash_func partialhash = get_partial_hash();
149149
150150   /* compute the hash */
151151   if (partialhash)
152      partialhash(dest, (const unsigned char*)data, length, functions);
152      partialhash(hashes, (const unsigned char*)data, length, types);
153153   else
154      hash_compute(dest, (const unsigned char*)data, length, functions);
154      hashes.compute(reinterpret_cast<const UINT8 *>(data), length, types);
155155}
156156
157157
r10427r10428
505505  to be loaded
506506****************************************************************************/
507507
508/*-------------------------------------------------
509    hash_data_extract_crc32 - extract crc32 value
510    from hash string
511-------------------------------------------------*/
512
513static UINT32 hash_data_extract_crc32(const char *d)
514{
515   UINT32 crc = 0;
516   UINT8 crc_bytes[4];
517
518   if (hash_data_extract_binary_checksum(d, HASH_CRC, crc_bytes) == 1)
519   {
520      crc = (((UINT32) crc_bytes[0]) << 24)
521         | (((UINT32) crc_bytes[1]) << 16)
522         | (((UINT32) crc_bytes[2]) << 8)
523         | (((UINT32) crc_bytes[3]) << 0);
524   }
525   return crc;
526}
527
528508int device_image_interface::read_hash_config(const char *sysname)
529509{
530510    hash_file *hashfile = NULL;
r10427r10428
536516        goto done;
537517
538518    /* look up this entry in the hash file */
539    info = hashfile_lookup(hashfile, m_hash.cstr());
519    info = hashfile_lookup(hashfile, m_hash);
540520
541521    if (!info)
542522        goto done;
r10427r10428
557537
558538
559539
560void device_image_interface::run_hash(void (*partialhash)(char *, const unsigned char *, unsigned long, unsigned int),
561    char *dest, unsigned int hash_functions)
540void device_image_interface::run_hash(void (*partialhash)(hash_collection &, const unsigned char *, unsigned long, const char *),
541    hash_collection &hashes, const char *types)
562542{
563543    UINT32 size;
564544    UINT8 *buf = NULL;
565545
566    *dest = '\0';
546    hashes.reset();
567547    size = (UINT32) length();
568548
569549    buf = (UINT8*)malloc(size);
r10427r10428
574554    fread(buf, size);
575555
576556    if (partialhash)
577        partialhash(dest, buf, size, hash_functions);
557        partialhash(hashes, buf, size, types);
578558    else
579        hash_compute(dest, buf, size, hash_functions);
559        hashes.compute(buf, size, types);
580560
581561    /* cleanup */
582562    free(buf);
r10427r10428
588568void device_image_interface::image_checkhash()
589569{
590570    const game_driver *drv;
591    char hash_string[HASH_BUF_SIZE];
592571    device_image_partialhash_func partialhash;
593572    int rc;
594573
595574    /* only calculate CRC if it hasn't been calculated, and the open_mode is read only */
596    if (!m_hash && !m_writeable && !m_created)
575    if (m_hash.first() == NULL && !m_writeable && !m_created)
597576    {
598577        /* do not cause a linear read of 600 megs please */
599578        /* TODO: use SHA/MD5 in the CHD header as the hash */
r10427r10428
607586        /* retrieve the partial hash func */
608587        partialhash = get_partial_hash();
609588
610        run_hash(partialhash, hash_string, HASH_CRC | HASH_MD5 | HASH_SHA1);
589        run_hash(partialhash, m_hash, hash_collection::HASH_TYPES_ALL);
611590
612        m_hash = hash_string;
613
614591        /* now read the hash file */
615592        drv = device().machine->gamedrv;
616593        do
r10427r10428
628605    UINT32 crc = 0;
629606
630607   image_checkhash();
631    if (m_hash)
632        crc = hash_data_extract_crc32(m_hash.cstr());
608    m_hash.crc(crc);
633609
634610    return crc;
635611}
src/emu/diimage.h
r10427r10428
113113typedef int (*device_image_create_func)(device_image_interface &image, int format_type, option_resolution *format_options);
114114typedef void (*device_image_unload_func)(device_image_interface &image);
115115typedef void (*device_image_display_func)(device_image_interface &image);
116typedef void (*device_image_partialhash_func)(char *, const unsigned char *, unsigned long, unsigned int);
116typedef void (*device_image_partialhash_func)(hash_collection &, const unsigned char *, unsigned long, const char *);
117117typedef void (*device_image_get_devices_func)(device_image_interface &device);
118118typedef bool (*device_image_softlist_load_func)(device_image_interface &image, char *swlist, char *swname, rom_entry *start_entry);
119119
r10427r10428
178178   static iodevice_t device_typeid(const char *name);
179179
180180   virtual device_image_partialhash_func get_partial_hash() const = 0;
181   virtual void device_compute_hash(char *dest, const void *data, size_t length, unsigned int functions) const;
181   virtual void device_compute_hash(hash_collection &hashes, const void *data, size_t length, const char *types) const;
182182protected:
183183   static const image_device_type_info *find_device_type(iodevice_t type);
184184   static const image_device_type_info m_device_info_array[];
r10427r10428
282282   bool try_change_working_directory(const char *subdir);
283283
284284   int read_hash_config(const char *sysname);
285   void run_hash(void (*partialhash)(char *, const unsigned char *, unsigned long, unsigned int), char *dest, unsigned int hash_functions);
285   void run_hash(void (*partialhash)(hash_collection &, const unsigned char *, unsigned long, const char *), hash_collection &hashes, const char *types);
286286   void image_checkhash();
287287   // derived class overrides
288288
r10427r10428
328328
329329   object_pool *m_mempool;
330330
331   astring m_hash;
331   hash_collection m_hash;
332332};
333333
334334
src/emu/sound/okim9810.c
r10427r10428
177177   
178178   // iterate over voices and accumulate sample data
179179   for (int voicenum = 0; voicenum < OKIM9810_VOICES; voicenum++)
180      m_voice[voicenum].generate_adpcm(*m_direct, outputs[0], samples);
180      m_voice[voicenum].generate_audio(*m_direct, outputs[0], samples);
181181}
182182
183183
r10427r10428
294294            endAddr |= m_direct->read_raw_byte(base + 6) << 8;
295295            endAddr |= m_direct->read_raw_byte(base + 7) << 0;
296296
297            // Note: flags might be (& 0x30 => voice synthesis algorithm) (& 0x0f => sampling frequency)
298297            mame_printf_verbose("FADR  channel %d phrase offset %02x => ", channel, m_TMP_register);
299298            mame_printf_verbose("\tstartFlags(%02x) startAddr(%06x) endFlags(%02x) endAddr(%06x) bytes(%d)\n", startFlags, startAddr, endFlags, endAddr, endAddr-startAddr);
299            m_voice[channel].m_sample = 0;
300300            m_voice[channel].m_startFlags = startFlags;
301301            m_voice[channel].m_base_offset = startAddr;
302302            m_voice[channel].m_endFlags = endFlags;
303            m_voice[channel].m_sample = 0;
304            // TODO: Sample count (m_count) changes based on decoding mode
305            m_voice[channel].m_count = 2 * ((endAddr-startAddr) + 1); // TODO: Explain the +1
303            m_voice[channel].m_playbackAlgo = (startFlags & 0x30) >> 4;     // Guess
304            // debug printf("%02x %d\n", startFlags, m_voice[channel].m_playbackAlgo);
305            // TODO: Sampling frequency is very likely : (startFlags & 0x0f)
306            m_voice[channel].m_count = (endAddr-startAddr) + 1;
307            if (m_voice[channel].m_playbackAlgo == OKIM9810_ADPCM_PLAYBACK ||
308                m_voice[channel].m_playbackAlgo == OKIM9810_ADPCM2_PLAYBACK)
309                m_voice[channel].m_count *= 2;
310            else
311                mame_printf_warning("UNIMPLEMENTED PLAYBACK METHOD %d\n", m_voice[channel].m_playbackAlgo);
306312            break;
307313        }
308314
r10427r10428
365371//-------------------------------------------------
366372
367373okim9810_device::okim_voice::okim_voice()
368   : m_playing(false),
374   : m_playbackAlgo(OKIM9810_ADPCM2_PLAYBACK),
375      m_playing(false),
369376     m_looping(false),
370377     m_startFlags(0),
371378     m_endFlags(0),
r10427r10428
377384}
378385
379386//-------------------------------------------------
380//  generate_adpcm - generate ADPCM samples and
387//  generate_audio - generate audio samples and
381388//  add them to an output stream
382389//-------------------------------------------------
383390
384void okim9810_device::okim_voice::generate_adpcm(direct_read_data &direct, stream_sample_t *buffer, int samples)
391void okim9810_device::okim_voice::generate_audio(direct_read_data &direct, stream_sample_t *buffer, int samples)
385392{
386393   // skip if not active
387394   if (!m_playing)
r10427r10428
395402
396403      // output to the buffer, scaling by the volume
397404      // signal in range -2048..2047, volume in range 2..128 => signal * volume / 8 in range -32768..32767
398      *buffer++ += (INT32)m_adpcm.clock(nibble) * (INT32)m_volume / 8;
399
405        switch (m_playbackAlgo)
406        {
407            case OKIM9810_ADPCM_PLAYBACK:
408              *buffer++ += (INT32)m_adpcm.clock(nibble) * (INT32)m_volume / 8;
409                break;
410            case OKIM9810_ADPCM2_PLAYBACK:
411              *buffer++ += (INT32)m_adpcm2.clock(nibble) * (INT32)m_volume / 8;
412                break;
413            default:
414                break;
415        }
416                   
400417      // next!
401418      if (++m_sample >= m_count)
402419      {
r10427r10428
408425      }
409426   }
410427}
411
412
413//**************************************************************************
414//  ADPCM STATE HELPER
415//**************************************************************************
416
417// ADPCM state and tables
418bool adpcm_stateCopy::s_tables_computed = false;
419const INT8 adpcm_stateCopy::s_index_shift[8] = { -1, -1, -1, -1, 2, 4, 6, 8 };
420int adpcm_stateCopy::s_diff_lookup[49*16];
421
422//-------------------------------------------------
423//  reset - reset the ADPCM state
424//-------------------------------------------------
425
426void adpcm_stateCopy::reset()
427{
428   // reset the signal/step
429   m_signal = -2;
430   m_step = 0;
431}
432
433
434//-------------------------------------------------
435//  device_clock_changed - called if the clock
436//  changes
437//-------------------------------------------------
438
439INT16 adpcm_stateCopy::clock(UINT8 nibble)
440{
441   // update the signal
442   m_signal += s_diff_lookup[m_step * 16 + (nibble & 15)];
443
444   // clamp to the maximum
445   if (m_signal > 2047)
446      m_signal = 2047;
447   else if (m_signal < -2048)
448      m_signal = -2048;
449
450   // adjust the step size and clamp
451   m_step += s_index_shift[nibble & 7];
452   if (m_step > 48)
453      m_step = 48;
454   else if (m_step < 0)
455      m_step = 0;
456
457   // return the signal
458   return m_signal;
459}
460
461
462//-------------------------------------------------
463//  compute_tables - precompute tables for faster
464//  sound generation
465//-------------------------------------------------
466
467void adpcm_stateCopy::compute_tables()
468{
469   // skip if we already did it
470   if (s_tables_computed)
471      return;
472   s_tables_computed = true;
473
474   // nibble to bit map
475   static const INT8 nbl2bit[16][4] =
476   {
477      { 1, 0, 0, 0}, { 1, 0, 0, 1}, { 1, 0, 1, 0}, { 1, 0, 1, 1},
478      { 1, 1, 0, 0}, { 1, 1, 0, 1}, { 1, 1, 1, 0}, { 1, 1, 1, 1},
479      {-1, 0, 0, 0}, {-1, 0, 0, 1}, {-1, 0, 1, 0}, {-1, 0, 1, 1},
480      {-1, 1, 0, 0}, {-1, 1, 0, 1}, {-1, 1, 1, 0}, {-1, 1, 1, 1}
481   };
482
483   // loop over all possible steps
484   for (int step = 0; step <= 48; step++)
485   {
486      // compute the step value
487      int stepval = floor(16.0 * pow(11.0 / 10.0, (double)step));
488
489      // loop over all nibbles and compute the difference
490      for (int nib = 0; nib < 16; nib++)
491      {
492         s_diff_lookup[step*16 + nib] = nbl2bit[nib][0] *
493            (stepval   * nbl2bit[nib][1] +
494             stepval/2 * nbl2bit[nib][2] +
495             stepval/4 * nbl2bit[nib][3] +
496             stepval/8);
497      }
498   }
499}
src/emu/sound/okim9810.h
r10427r10428
1111#ifndef __OKIM9810_H__
1212#define __OKIM9810_H__
1313
14#include "okiadpcm.h"
1415
16
1517//**************************************************************************
1618//  CONSTANTS
1719//**************************************************************************
r10427r10428
2325    // etc
2426};
2527
28enum
29{
30   OKIM9810_ADPCM_PLAYBACK = 0,
31   OKIM9810_ADPCM2_PLAYBACK = 1,
32   OKIM9810_STRAIGHT8_PLAYBACK = 2,
33    OKIM9810_NONLINEAR8_PLAYBACK = 3
34};
2635
2736
2837//**************************************************************************
r10427r10428
4150//  TYPE DEFINITIONS
4251//**************************************************************************
4352
44// ======================> adpcm_stateCopy
4553
46// Internal ADPCM state, used by external ADPCM generators with compatible specs to the OKIM 6295.
47class adpcm_stateCopy
48{
49public:
50   adpcm_stateCopy() { compute_tables(); reset(); }
51
52   void reset();
53   INT16 clock(UINT8 nibble);
54
55   INT32   m_signal;
56   INT32   m_step;
57
58private:
59   static const INT8 s_index_shift[8];
60   static int s_diff_lookup[49*16];
61
62   static void compute_tables();
63   static bool s_tables_computed;
64};
65
66
6754// ======================> okim9810_device_config
6855
6956class okim9810_device_config :   public device_config,
r10427r10428
126113   {
127114   public:
128115      okim_voice();
129      void generate_adpcm(direct_read_data &direct, stream_sample_t *buffer, int samples);
116      void generate_audio(direct_read_data &direct, stream_sample_t *buffer, int samples);
130117
131      adpcm_stateCopy m_adpcm;         // current ADPCM state
118      oki_adpcm_state m_adpcm;      // current ADPCM state
119      oki_adpcm2_state m_adpcm2;      // current ADPCM2 state
120      UINT8      m_playbackAlgo;      // current playback method
132121      bool      m_playing;
133122      bool      m_looping;
134123      UINT8      m_startFlags;
135124      UINT8      m_endFlags;
136125      offs_t      m_base_offset;      // pointer to the base memory location
137126      UINT32      m_sample;         // current sample number
138      UINT32      m_count;         // total bytes to play
127      UINT32      m_count;         // total samples to play
139128
140129      INT8      m_volume;         // output volume
141130      // TODO:   m_volume_left;      // stereo volume
src/emu/sound/sound.mak
r10427r10428
356356# OKI ADPCM sample players
357357#-------------------------------------------------
358358
359ifneq ($(filter OKIM6258 OKIM9810,$(SOUNDS)),)
360SOUNDOBJS += $(SOUNDOBJ)/okiadpcm.o
361endif
362
359363ifneq ($(filter MSM5205,$(SOUNDS)),)
360364SOUNDOBJS += $(SOUNDOBJ)/msm5205.o
361365endif
src/emu/sound/okiadpcm.c
r0r10428
1/***************************************************************************
2
3    okiadpcm.h
4
5    OKI ADCPM emulation.
6
7***************************************************************************/
8
9#include "emu.h"
10#include "okiadpcm.h"
11
12
13//**************************************************************************
14//  ADPCM STATE HELPER
15//**************************************************************************
16
17// ADPCM state and tables
18bool oki_adpcm_state::s_tables_computed = false;
19const INT8 oki_adpcm_state::s_index_shift[8] = { -1, -1, -1, -1, 2, 4, 6, 8 };
20int oki_adpcm_state::s_diff_lookup[49*16];
21
22//-------------------------------------------------
23//  reset - reset the ADPCM state
24//-------------------------------------------------
25
26void oki_adpcm_state::reset()
27{
28   // reset the signal/step
29   m_signal = -2;
30   m_step = 0;
31}
32
33
34//-------------------------------------------------
35//  device_clock_changed - called if the clock
36//  changes
37//-------------------------------------------------
38
39INT16 oki_adpcm_state::clock(UINT8 nibble)
40{
41   // update the signal
42   m_signal += s_diff_lookup[m_step * 16 + (nibble & 15)];
43
44   // clamp to the maximum
45   if (m_signal > 2047)
46      m_signal = 2047;
47   else if (m_signal < -2048)
48      m_signal = -2048;
49
50   // adjust the step size and clamp
51   m_step += s_index_shift[nibble & 7];
52   if (m_step > 48)
53      m_step = 48;
54   else if (m_step < 0)
55      m_step = 0;
56
57   // return the signal
58   return m_signal;
59}
60
61
62//-------------------------------------------------
63//  compute_tables - precompute tables for faster
64//  sound generation
65//-------------------------------------------------
66
67void oki_adpcm_state::compute_tables()
68{
69   // skip if we already did it
70   if (s_tables_computed)
71      return;
72   s_tables_computed = true;
73
74   // nibble to bit map
75   static const INT8 nbl2bit[16][4] =
76   {
77      { 1, 0, 0, 0}, { 1, 0, 0, 1}, { 1, 0, 1, 0}, { 1, 0, 1, 1},
78      { 1, 1, 0, 0}, { 1, 1, 0, 1}, { 1, 1, 1, 0}, { 1, 1, 1, 1},
79      {-1, 0, 0, 0}, {-1, 0, 0, 1}, {-1, 0, 1, 0}, {-1, 0, 1, 1},
80      {-1, 1, 0, 0}, {-1, 1, 0, 1}, {-1, 1, 1, 0}, {-1, 1, 1, 1}
81   };
82
83   // loop over all possible steps
84   for (int step = 0; step <= 48; step++)
85   {
86      // compute the step value
87      int stepval = floor(16.0 * pow(11.0 / 10.0, (double)step));
88
89      // loop over all nibbles and compute the difference
90      for (int nib = 0; nib < 16; nib++)
91      {
92         s_diff_lookup[step*16 + nib] = nbl2bit[nib][0] *
93            (stepval   * nbl2bit[nib][1] +
94             stepval/2 * nbl2bit[nib][2] +
95             stepval/4 * nbl2bit[nib][3] +
96             stepval/8);
97      }
98   }
99}
100
101
102//**************************************************************************
103//  ADPCM2 STATE HELPER
104//**************************************************************************
105
106// ADPCM state and tables
107bool oki_adpcm2_state::s_tables_computed = false;
108const INT8 oki_adpcm2_state::s_index_shift[8] = { -2, -2, -2, -2, 2, 6, 9, 11 };
109int oki_adpcm2_state::s_diff_lookup[49*16];
110
111//-------------------------------------------------
112//  reset - reset the ADPCM state
113//-------------------------------------------------
114
115void oki_adpcm2_state::reset()
116{
117   // reset the signal/step
118   m_signal = -2;
119   m_step = 0;
120}
121
122
123//-------------------------------------------------
124//  device_clock_changed - called if the clock
125//  changes
126//-------------------------------------------------
127
128INT16 oki_adpcm2_state::clock(UINT8 nibble)
129{
130   // update the signal
131   m_signal += s_diff_lookup[m_step * 16 + (nibble & 15)];
132
133   // clamp to the maximum
134   if (m_signal > 2047)
135      m_signal = 2047;
136   else if (m_signal < -2048)
137      m_signal = -2048;
138
139   // adjust the step size and clamp
140   m_step += s_index_shift[nibble & 7];
141   if (m_step > 48)
142      m_step = 48;
143   else if (m_step < 0)
144      m_step = 0;
145
146   // return the signal
147   return m_signal;
148}
149
150
151//-------------------------------------------------
152//  compute_tables - precompute tables for faster
153//  sound generation
154//-------------------------------------------------
155
156void oki_adpcm2_state::compute_tables()
157{
158   // skip if we already did it
159   if (s_tables_computed)
160      return;
161   s_tables_computed = true;
162
163   // nibble to bit map
164   static const INT8 nbl2bit[16][4] =
165   {
166      { 1, 0, 0, 0}, { 1, 0, 0, 1}, { 1, 0, 1, 0}, { 1, 0, 1, 1},
167      { 1, 1, 0, 0}, { 1, 1, 0, 1}, { 1, 1, 1, 0}, { 1, 1, 1, 1},
168      {-1, 0, 0, 0}, {-1, 0, 0, 1}, {-1, 0, 1, 0}, {-1, 0, 1, 1},
169      {-1, 1, 0, 0}, {-1, 1, 0, 1}, {-1, 1, 1, 0}, {-1, 1, 1, 1}
170   };
171
172   // loop over all possible steps
173    float floatstep = 64;
174   for (int step = 0; step <= 48; step++)
175   {
176      // compute the step value
177        int stepval = floor(floatstep * 1.08f);
178        floatstep = floatstep * 1.08f;
179       
180      // loop over all nibbles and compute the difference
181      for (int nib = 0; nib < 16; nib++)
182      {
183         s_diff_lookup[step*16 + nib] = nbl2bit[nib][0] *
184            (stepval   * nbl2bit[nib][1] +
185             stepval/2 * nbl2bit[nib][2] +
186             stepval/4 * nbl2bit[nib][3] +
187             stepval/8);
188      }
189   }
190}
src/emu/sound/okiadpcm.h
r0r10428
1/***************************************************************************
2
3    okiadpcm.h
4
5    OKI ADCPM emulation.
6
7***************************************************************************/
8
9#pragma once
10
11#ifndef __OKIADPCM_H__
12#define __OKIADPCM_H__
13
14
15// ======================> oki_adpcm_state
16
17// Internal ADPCM state, used by external ADPCM generators with compatible specs to the OKIM 6295.
18class oki_adpcm_state
19{
20public:
21   oki_adpcm_state() { compute_tables(); reset(); }
22
23   void reset();
24   INT16 clock(UINT8 nibble);
25
26   INT32   m_signal;
27   INT32   m_step;
28
29private:
30   static const INT8 s_index_shift[8];
31   static int s_diff_lookup[49*16];
32
33   static void compute_tables();
34   static bool s_tables_computed;
35};
36
37
38// ======================> oki_adpcm2_state
39
40// Internal ADPCM2 state, used by external ADPCM generators with compatible specs to the OKI MSM9810.
41class oki_adpcm2_state
42{
43public:
44   oki_adpcm2_state() { compute_tables(); reset(); }
45
46   void reset();
47   INT16 clock(UINT8 nibble);
48
49   INT32   m_signal;
50   INT32   m_step;
51
52private:
53   static const INT8 s_index_shift[8];
54   static int s_diff_lookup[49*16];
55
56   static void compute_tables();
57   static bool s_tables_computed;
58};
59
60
61#endif // __OKIADPCM_H__
src/emu/clifront.c
r10427r10428
6161static void romident(core_options *options, const char *filename, romident_status *status);
6262static void identify_file(core_options *options, const char *name, romident_status *status);
6363static void identify_data(core_options *options, const char *name, const UINT8 *data, int length, romident_status *status);
64static void match_roms(core_options *options, const char *hash, int length, int *found);
64static void match_roms(core_options *options, const hash_collection &hashes, int length, int *found);
6565static void display_suggestions(const char *gamename);
6666
6767
r10427r10428
535535            for (region = rom_first_region(*source); region; region = rom_next_region(region))
536536               for (rom = rom_first_file(region); rom; rom = rom_next_file(rom))
537537               {
538                  char hashbuf[HASH_BUF_SIZE];
539
540538                  /* if we have a CRC, display it */
541                  if (hash_data_extract_printable_checksum(ROM_GETHASHDATA(rom), HASH_CRC, hashbuf))
542                     mame_printf_info("%s %-12s %s\n", hashbuf, ROM_GETNAME(rom), drivers[drvindex]->description);
539                  UINT32 crc;
540                  if (hash_collection(ROM_GETHASHDATA(rom)).crc(crc))
541                     mame_printf_info("%08x %-12s %s\n", crc, ROM_GETNAME(rom), drivers[drvindex]->description);
543542               }
544543
545544         count++;
r10427r10428
558557int cli_info_listroms(core_options *options, const char *gamename)
559558{
560559   int drvindex, count = 0;
560   astring tempstr;
561561
562562   /* iterate over drivers */
563563   for (drvindex = 0; drivers[drvindex] != NULL; drvindex++)
564564      if (mame_strwildcmp(gamename, drivers[drvindex]->name) == 0)
565565      {
566566         machine_config config(*drivers[drvindex]);
567         const rom_entry *region, *rom;
568         const rom_source *source;
569567
570568         /* print the header */
571569         if (count > 0)
r10427r10428
574572               "Name            Size Checksum\n", drivers[drvindex]->name);
575573
576574         /* iterate over sources, regions and then ROMs within the region */
577         for (source = rom_first_source(config); source != NULL; source = rom_next_source(*source))
578            for (region = rom_first_region(*source); region != NULL; region = rom_next_region(region))
579               for (rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom))
575         for (const rom_source *source = rom_first_source(config); source != NULL; source = rom_next_source(*source))
576            for (const rom_entry *region = rom_first_region(*source); region != NULL; region = rom_next_region(region))
577               for (const rom_entry *rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom))
580578               {
581                  const char *name = ROM_GETNAME(rom);
582                  const char *hash = ROM_GETHASHDATA(rom);
583                  char hashbuf[HASH_BUF_SIZE];
584                  int length = -1;
585
586579                  /* accumulate the total length of all chunks */
580                  int length = -1;
587581                  if (ROMREGION_ISROMDATA(region))
588582                     length = rom_file_size(rom);
589583
590584                  /* start with the name */
585                  const char *name = ROM_GETNAME(rom);
591586                  mame_printf_info("%-12s ", name);
592587
593588                  /* output the length next */
r10427r10428
597592                     mame_printf_info("       ");
598593
599594                  /* output the hash data */
600                  if (!hash_data_has_info(hash, HASH_INFO_NO_DUMP))
595                  hash_collection hashes(ROM_GETHASHDATA(rom));
596                  if (!hashes.flag(hash_collection::FLAG_NO_DUMP))
601597                  {
602                     if (hash_data_has_info(hash, HASH_INFO_BAD_DUMP))
598                     if (hashes.flag(hash_collection::FLAG_BAD_DUMP))
603599                        mame_printf_info(" BAD");
604
605                     hash_data_print(hash, 0, hashbuf);
606                     mame_printf_info(" %s", hashbuf);
600                     mame_printf_info(" %s", hashes.macro_string(tempstr));
607601                  }
608602                  else
609603                     mame_printf_info(" NO GOOD DUMP KNOWN");
r10427r10428
975969                                          fprintf( out, "\t\t\t\t\t<disk name=\"%s\"", xml_normalize_string(ROM_GETNAME(rom)) );
976970
977971                                       /* dump checksum information only if there is a known dump */
978                                       if (!hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP))
972                                       hash_collection hashes(ROM_GETHASHDATA(rom));
973                                       if (!hashes.flag(hash_collection::FLAG_NO_DUMP))
979974                                       {
980                                          char checksum[HASH_BUF_SIZE];
981                                          int hashtype;
982
983                                          /* iterate over hash function types and print out their values */
984                                          for (hashtype = 0; hashtype < HASH_NUM_FUNCTIONS; hashtype++)
985                                             if (hash_data_extract_printable_checksum(ROM_GETHASHDATA(rom), 1 << hashtype, checksum))
986                                                fprintf(out, " %s=\"%s\"", hash_function_name(1 << hashtype), checksum);
975                                          astring tempstr;
976                                          for (hash_base *hash = hashes.first(); hash != NULL; hash = hash->next())
977                                             fprintf(out, " %s=\"%s\"", hash->name(), hash->string(tempstr));
987978                                       }
988979
989980                                       if (!is_disk)
990981                                          fprintf( out, " offset=\"0x%x\"", ROM_GETOFFSET(rom) );
991982
992                                       if ( hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_BAD_DUMP) )
983                                       if ( hashes.flag(hash_collection::FLAG_BAD_DUMP) )
993984                                          fprintf( out, " status=\"baddump\"" );
994                                       if ( hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP) )
985                                       if ( hashes.flag(hash_collection::FLAG_NO_DUMP) )
995986                                          fprintf( out, " status=\"nodump\"" );
996987
997988                                       if (is_disk)
r10427r10428
10811072    softlist_match_roms - scan for a matching
10821073    software ROM by hash
10831074-------------------------------------------------*/
1084static void softlist_match_roms(core_options *options, const char *hash, int length, int *found)
1075static void softlist_match_roms(core_options *options, const hash_collection &hashes, int length, int *found)
10851076{
10861077   int drvindex;
10871078
r10427r10428
11081099                     {
11091100                        for ( const rom_entry *rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom) )
11101101                        {
1111                           if ( hash_data_is_equal(hash, ROM_GETHASHDATA(rom), 0) )
1102                           hash_collection romhashes(ROM_GETHASHDATA(rom));
1103                           if ( hashes == romhashes )
11121104                           {
1113                              int baddump = hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_BAD_DUMP);
1105                              bool baddump = romhashes.flag(hash_collection::FLAG_BAD_DUMP);
11141106
11151107                              /* output information about the match */
11161108                              if (*found != 0)
r10427r10428
14161408         }
14171409         else
14181410         {
1419            static const UINT8 nullhash[HASH_BUF_SIZE] = { 0 };
1420            char         hash[HASH_BUF_SIZE];   /* actual hash information */
1411            static const UINT8 nullhash[20] = { 0 };
1412            hash_collection hashes;
14211413
1422            hash_data_clear(hash);
1423
14241414            /* if there's an MD5 or SHA1 hash, add them to the output hash */
14251415            if (memcmp(nullhash, header.md5, sizeof(header.md5)) != 0)
1426               hash_data_insert_binary_checksum(hash, HASH_MD5, header.md5);
1416               hashes.add_from_buffer(hash_collection::HASH_MD5, header.md5, sizeof(header.md5));
14271417            if (memcmp(nullhash, header.sha1, sizeof(header.sha1)) != 0)
1428               hash_data_insert_binary_checksum(hash, HASH_SHA1, header.sha1);
1418               hashes.add_from_buffer(hash_collection::HASH_SHA1, header.sha1, sizeof(header.sha1));
14291419
14301420            length = header.logicalbytes;
14311421
1432            match_roms(options, hash, length, &found);
1422            match_roms(options, hashes, length, &found);
14331423
14341424            if (found == 0)
14351425            {
r10427r10428
14751465
14761466static void identify_data(core_options *options, const char *name, const UINT8 *data, int length, romident_status *status)
14771467{
1478   char hash[HASH_BUF_SIZE];
14791468   UINT8 *tempjed = NULL;
14801469   astring basename;
14811470   int found = 0;
r10427r10428
14961485   }
14971486
14981487   /* compute the hash of the data */
1499   hash_data_clear(hash);
1500   hash_compute(hash, data, length, HASH_SHA1 | HASH_CRC);
1488   hash_collection hashes;
1489   hashes.compute(data, length, hash_collection::HASH_TYPES_CRC_SHA1);
15011490
15021491   /* output the name */
15031492   status->total++;
r10427r10428
15051494   mame_printf_info("%-20s", basename.cstr());
15061495
15071496   /* see if we can find a match in the ROMs */
1508   match_roms(options, hash, length, &found);
1497   match_roms(options, hashes, length, &found);
15091498
15101499   /* if we didn't find it, try to guess what it might be */
15111500   if (found == 0)
r10427r10428
15361525    match_roms - scan for a matching ROM by hash
15371526-------------------------------------------------*/
15381527
1539static void match_roms(core_options *options, const char *hash, int length, int *found)
1528static void match_roms(core_options *options, const hash_collection &hashes, int length, int *found)
15401529{
15411530   int drvindex;
15421531
r10427r10428
15511540      for (source = rom_first_source(config); source != NULL; source = rom_next_source(*source))
15521541         for (region = rom_first_region(*source); region; region = rom_next_region(region))
15531542            for (rom = rom_first_file(region); rom; rom = rom_next_file(rom))
1554               if (hash_data_is_equal(hash, ROM_GETHASHDATA(rom), 0))
1543            {
1544               hash_collection romhashes(ROM_GETHASHDATA(rom));
1545               if (hashes == romhashes)
15551546               {
1556                  int baddump = hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_BAD_DUMP);
1547                  bool baddump = romhashes.flag(hash_collection::FLAG_NO_DUMP);
15571548
15581549                  /* output information about the match */
15591550                  if (*found != 0)
r10427r10428
15611552                  mame_printf_info("= %s%-20s  %-10s %s\n", baddump ? "(BAD) " : "", ROM_GETNAME(rom), drivers[drvindex]->name, drivers[drvindex]->description);
15621553                  (*found)++;
15631554               }
1555            }
15641556   }
15651557
1566   softlist_match_roms( options, hash, length, found );
1558   softlist_match_roms( options, hashes, length, found );
15671559}
src/emu/validity.c
r10427r10428
523523         /* if this is a file, make sure it is properly formatted */
524524         else if (ROMENTRY_ISFILE(romp))
525525         {
526            const char *hash;
527526            const char *s;
528527
529528            items_since_region++;
r10427r10428
541540               }
542541
543542            /* make sure the hash is valid */
544            hash = ROM_GETHASHDATA(romp);
545            if (!hash_verify_string(hash))
543            hash_collection hashes;
544            if (!hashes.from_internal_string(ROM_GETHASHDATA(romp)))
546545            {
547               mame_printf_error("%s: rom '%s' has an invalid hash string '%s'\n", driver.name, last_name, hash);
546               mame_printf_error("%s: rom '%s' has an invalid hash string '%s'\n", driver.name, last_name, ROM_GETHASHDATA(romp));
548547               error = true;
549548            }
550549         }
src/emu/romload.c
r10427r10428
434434   }
435435
436436   /* no good dumps are okay */
437   else if (ROM_NOGOODDUMP(romp))
437   else if (hash_collection(ROM_GETHASHDATA(romp)).flag(hash_collection::FLAG_NO_DUMP))
438438   {
439439      romdata->errorstring.catprintf("%s NOT FOUND (NO GOOD DUMP KNOWN)\n", ROM_GETNAME(romp));
440440      romdata->knownbad++;
r10427r10428
455455    correct checksums for a given ROM
456456-------------------------------------------------*/
457457
458static void dump_wrong_and_correct_checksums(rom_load_data *romdata, const char *hash, const char *acthash)
458static void dump_wrong_and_correct_checksums(rom_load_data *romdata, const hash_collection &hashes, const hash_collection &acthashes)
459459{
460   unsigned i;
461   char chksum[256];
462   unsigned found_functions;
463   unsigned wrong_functions;
460   astring tempstr;
461   romdata->errorstring.catprintf("    EXPECTED: %s\n", hashes.macro_string(tempstr));
462   romdata->errorstring.catprintf("       FOUND: %s\n", acthashes.macro_string(tempstr));
464463
465   found_functions = hash_data_used_functions(hash) & hash_data_used_functions(acthash);
466
467   hash_data_print(hash, found_functions, chksum);
468   romdata->errorstring.catprintf("    EXPECTED: %s\n", chksum);
469
470   /* We dump informations only of the functions for which MAME provided
471        a correct checksum. Other functions we might have calculated are
472        useless here */
473   hash_data_print(acthash, found_functions, chksum);
474   romdata->errorstring.catprintf("       FOUND: %s\n", chksum);
475
476   /* For debugging purposes, we check if the checksums available in the
477       driver are correctly specified or not. This can be done by checking
478       the return value of one of the extract functions. Maybe we want to
479       activate this only in debug buils, but many developers only use
480       release builds, so I keep it as is for now. */
481   wrong_functions = 0;
482   for (i = 0; i < HASH_NUM_FUNCTIONS; i++)
483      if (hash_data_extract_printable_checksum(hash, 1 << i, chksum) == 2)
484         wrong_functions |= 1 << i;
485
486   if (wrong_functions)
487   {
488      for (i = 0; i < HASH_NUM_FUNCTIONS; i++)
489         if (wrong_functions & (1 << i))
490         {
491            romdata->errorstring.catprintf(
492               "\tInvalid %s checksum treated as 0 (check leading zeros)\n",
493               hash_function_name(1 << i));
494
495            romdata->warnings++;
496         }
497   }
464   // warn about any ill-formed hashes   
465   for (hash_base *hash = hashes.first(); hash != NULL; hash = hash->next())
466      if (hash->parse_error())
467      {
468         romdata->errorstring.catprintf("\tInvalid %s checksum treated as 0 (check leading zeros)\n", hash->name());
469         romdata->warnings++;
470      }
498471}
499472
500473
r10427r10428
503476    and hash signatures of a file
504477-------------------------------------------------*/
505478
506static void verify_length_and_hash(rom_load_data *romdata, const char *name, UINT32 explength, const char *hash)
479static void verify_length_and_hash(rom_load_data *romdata, const char *name, UINT32 explength, const hash_collection &hashes)
507480{
508   UINT32 actlength;
509   const char* acthash;
510
511481   /* we've already complained if there is no file */
512482   if (romdata->file == NULL)
513483      return;
514484
515   /* get the length and CRC from the file */
516   actlength = romdata->file->size();
517   acthash = romdata->file->hash_string(hash_data_used_functions(hash));
518
519485   /* verify length */
486   UINT32 actlength = romdata->file->size();
520487   if (explength != actlength)
521488   {
522489      romdata->errorstring.catprintf("%s WRONG LENGTH (expected: %08x found: %08x)\n", name, explength, actlength);
r10427r10428
524491   }
525492
526493   /* If there is no good dump known, write it */
527   if (hash_data_has_info(hash, HASH_INFO_NO_DUMP))
494   astring tempstr;
495   hash_collection &acthashes = romdata->file->hashes(hashes.hash_types(tempstr));
496   if (hashes.flag(hash_collection::FLAG_NO_DUMP))
528497   {
529498      romdata->errorstring.catprintf("%s NO GOOD DUMP KNOWN\n", name);
530499      romdata->knownbad++;
531500   }
532501   /* verify checksums */
533   else if (!hash_data_is_equal(hash, acthash, 0))
502   else if (hashes != acthashes)
534503   {
535504      /* otherwise, it's just bad */
536505      romdata->errorstring.catprintf("%s WRONG CHECKSUMS:\n", name);
537
538      dump_wrong_and_correct_checksums(romdata, hash, acthash);
539
506      dump_wrong_and_correct_checksums(romdata, hashes, acthashes);
540507      romdata->warnings++;
541508   }
542509   /* If it matches, but it is actually a bad dump, write it */
543   else if (hash_data_has_info(hash, HASH_INFO_BAD_DUMP))
510   else if (hashes.flag(hash_collection::FLAG_BAD_DUMP))
544511   {
545512      romdata->errorstring.catprintf("%s ROM NEEDS REDUMP\n",name);
546513      romdata->knownbad++;
r10427r10428
646613   file_error filerr = FILERR_NOT_FOUND;
647614   UINT32 romsize = rom_file_size(romp);
648615   const game_driver *drv;
649   int has_crc = FALSE;
650   UINT8 crcbytes[4];
651   UINT32 crc = 0;
652616
653617   /* update status display */
654618   display_loading_rom_message(romdata, ROM_GETNAME(romp));
655619
656620   /* extract CRC to use for searching */
657   has_crc = hash_data_extract_binary_checksum(ROM_GETHASHDATA(romp), HASH_CRC, crcbytes);
658   if (has_crc)
659      crc = (crcbytes[0] << 24) | (crcbytes[1] << 16) | (crcbytes[2] << 8) | crcbytes[3];
621   UINT32 crc = 0;
622   bool has_crc = hash_collection(ROM_GETHASHDATA(romp)).crc(crc);
660623
661624   /* attempt reading up the chain through the parents. It automatically also
662625     attempts any kind of load by checksum supported by the archives. */
r10427r10428
1006969            if (baserom)
1007970            {
1008971               LOG(("Verifying length (%X) and checksums\n", explength));
1009               verify_length_and_hash(romdata, ROM_GETNAME(baserom), explength, ROM_GETHASHDATA(baserom));
972               verify_length_and_hash(romdata, ROM_GETNAME(baserom), explength, hash_collection(ROM_GETHASHDATA(baserom)));
1010973               LOG(("Verify finished\n"));
1011974            }
1012975
r10427r10428
11481111
11491112   /* otherwise, look at our parents for a CHD with an identical checksum */
11501113   /* and try to open that */
1114   hash_collection romphashes(ROM_GETHASHDATA(romp));
11511115   for (drv = gamedrv; drv != NULL; drv = driver_get_clone(drv))
11521116   {
11531117      machine_config config(*drv);
r10427r10428
11581122
11591123                  /* look for a differing name but with the same hash data */
11601124                  if (strcmp(ROM_GETNAME(romp), ROM_GETNAME(rom)) != 0 &&
1161                     hash_data_is_equal(ROM_GETHASHDATA(romp), ROM_GETHASHDATA(rom), 0))
1125                     romphashes == hash_collection(ROM_GETHASHDATA(rom)))
11621126                  {
11631127                     /* attempt to open the properly named file, scanning up through parent directories */
11641128                     filerr = FILERR_NOT_FOUND;
r10427r10428
12491213      /* handle files */
12501214      if (ROMENTRY_ISFILE(romp))
12511215      {
1252         char acthash[HASH_BUF_SIZE];
1216         hash_collection hashes(ROM_GETHASHDATA(romp));
12531217         open_chd chd = { 0 };
12541218         chd_header header;
12551219         chd_error err;
r10427r10428
12711235               romdata->errorstring.catprintf("%s CHD ERROR: %s\n", filename.cstr(), chd_error_string(err));
12721236
12731237            /* if this is NO_DUMP, keep going, though the system may not be able to handle it */
1274            if (hash_data_has_info(ROM_GETHASHDATA(romp), HASH_INFO_NO_DUMP))
1238            if (hashes.flag(hash_collection::FLAG_NO_DUMP))
12751239               romdata->knownbad++;
12761240            else if (DISK_ISOPTIONAL(romp))
12771241               romdata->warnings++;
r10427r10428
12821246
12831247         /* get the header and extract the MD5/SHA1 */
12841248         header = *chd_get_header(chd.origchd);
1285         hash_data_clear(acthash);
1286         hash_data_insert_binary_checksum(acthash, HASH_SHA1, header.sha1);
1249         hash_collection acthashes;
1250         acthashes.add_from_buffer(hash_collection::HASH_SHA1, header.sha1, sizeof(header.sha1));
12871251
12881252         /* verify the hash */
1289         if (!hash_data_is_equal(ROM_GETHASHDATA(romp), acthash, 0))
1253         if (hashes != acthashes)
12901254         {
12911255            romdata->errorstring.catprintf("%s WRONG CHECKSUMS:\n", filename.cstr());
1292            dump_wrong_and_correct_checksums(romdata, ROM_GETHASHDATA(romp), acthash);
1256            dump_wrong_and_correct_checksums(romdata, hashes, acthashes);
12931257            romdata->warnings++;
12941258         }
1295         else if (hash_data_has_info(ROM_GETHASHDATA(romp), HASH_INFO_BAD_DUMP))
1259         else if (hashes.flag(hash_collection::FLAG_BAD_DUMP))
12961260         {
12971261            romdata->errorstring.catprintf("%s CHD NEEDS REDUMP\n", filename.cstr());
12981262            romdata->knownbad++;
src/emu/imagedev/multcart.c
r10427r10428
193193   /* check SHA1 now */
194194   if ((sha1 = xml_get_attribute_string(resource_node, "sha1", NULL)))
195195   {
196      char calc_sha[256];
196      hash_collection actual_hashes;
197      actual_hashes.compute((const UINT8 *)resource->ptr, resource->length, hash_collection::HASH_TYPES_CRC_SHA1);
198     
199      hash_collection expected_hashes;
200      expected_hashes.add_from_string(hash_collection::HASH_SHA1, sha1, strlen(sha1));
197201
198      memset(calc_sha, 0, sizeof(calc_sha));
199      hash_compute(&calc_sha[0], (const unsigned char*)resource->ptr, resource->length, HASH_SHA1);
200
201      if ((strncmp(sha1, &calc_sha[2], 20)))
202      if (actual_hashes != expected_hashes)
202203      {
203204         return MCERR_INVALID_FILE_REF;
204205      }
src/emu/romload.h
r10427r10428
189189#define ROM_GETBITSHIFT(r)         ((ROM_GETFLAGS(r) & ROM_BITSHIFTMASK) >> 20)
190190#define ROM_INHERITSFLAGS(r)      ((ROM_GETFLAGS(r) & ROM_INHERITFLAGSMASK) == ROM_INHERITFLAGS)
191191#define ROM_GETBIOSFLAGS(r)         ((ROM_GETFLAGS(r) & ROM_BIOSFLAGSMASK) >> 24)
192#define ROM_NOGOODDUMP(r)         (hash_data_has_info((r)->_hashdata, HASH_INFO_NO_DUMP))
193192
194193
195194/* ----- per-disk macros ----- */
r10427r10428
257256#define DISK_IMAGE_READONLY_OPTIONAL(name,idx,hash)   ROMX_LOAD(name, idx, 0, hash, DISK_READONLY | ROM_OPTIONAL)
258257
259258
260/* ----- hash macros ----- */
261#define CRC(x)                              "c:" #x "#"
262#define SHA1(x)                              "s:" #x "#"
263#define MD5(x)                              "m:" #x "#"
264#define NO_DUMP                              "$ND$"
265#define BAD_DUMP                           "$BD$"
266259
267
268
269260/***************************************************************************
270261    FUNCTION PROTOTYPES
271262***************************************************************************/
src/emu/softlist.c
r10427r10428
670670                           return;
671671
672672                        strcpy( s_name, str_name );
673                        sprintf( hashdata, "c:%s#s:%s#%s", str_crc, str_sha1, ( nodump ? NO_DUMP : ( baddump ? BAD_DUMP : "" ) ) );
673                        sprintf( hashdata, "%c%s%c%s%s", hash_collection::HASH_CRC, str_crc, hash_collection::HASH_SHA1, str_sha1, ( nodump ? NO_DUMP : ( baddump ? BAD_DUMP : "" ) ) );
674674
675675                        /* Handle loadflag attribute */
676676                        if ( str_loadflag && !strcmp(str_loadflag, "load16_word_swap") )
r10427r10428
16891689                        }
16901690
16911691                     /* make sure the hash is valid */
1692                     if (!hash_verify_string(data->_hashdata))
1692                     hash_collection hashes;
1693                     if (!hashes.from_internal_string(data->_hashdata))
16931694                     {
16941695                        mame_printf_error("%s: %s has rom '%s' with an invalid hash string '%s'\n", swlist->list_name[i], swinfo->shortname, data->_name, data->_hashdata);
16951696                        error = TRUE;
src/emu/devimage.c
r10427r10428
313313         /* handle files */
314314         if (ROMENTRY_ISFILE(romp))
315315         {
316            UINT32 crc = 0;
317            UINT8 crcbytes[4];
318316            file_error filerr = FILERR_NOT_FOUND;
319317
320            bool has_crc = hash_data_extract_binary_checksum(ROM_GETHASHDATA(romp), HASH_CRC, crcbytes);
321            if (has_crc)
322               crc = (crcbytes[0] << 24) | (crcbytes[1] << 16) | (crcbytes[2] << 8) | crcbytes[3];
318            UINT32 crc = 0;
319            bool has_crc = hash_collection(ROM_GETHASHDATA(romp)).crc(crc);
323320
324321            // attempt reading up the chain through the parents and create a locationtag astring in the format
325322            // " swlist % clonename % parentname "
src/emu/hash.c
r10427r10428
1/*********************************************************************
1/***************************************************************************
22
33    hash.c
44
55    Function to handle hash functions (checksums)
66
7    Copyright Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
7    Based on original idea by Farfetch'd
98
10    Started by Farfetch'd
9****************************************************************************
1110
12*********************************************************************/
11    Copyright Aaron Giles
12    All rights reserved.
1313
14/*
15 * Changelog:
16 *
17 * 20030314:  Farfetch'd
18 *    First release
19 *
20 */
14    Redistribution and use in source and binary forms, with or without
15    modification, are permitted provided that the following conditions are
16    met:
2117
22/*
23 * DONE:
24 *
25 * hash.c/h: New files, implement the new hashing engine with flexible
26 *    support for more functions (for now, CRC, SHA1 and MD5).
27 *
28 * common.h: transparently support the new RomModule structure through
29 *    ROM_* macros, so that old the legacy code still work
30 *
31 * common.c: updated ROM loading engine to support the new hash engine,
32 *    using it to verify ROM integrity at load-time. Updated printromlist()
33 *    (-listroms) to dump all the available checksums, and if a ROM is
34 *    known to be bad or not.
35 *
36 * info.c: -listinfo now supports any hashing function correctly
37 *    (both text and XML mode). Notice that XML header should be
38 *    rewritten to automatically define the new tags when new
39 *    functions are added, but I couldn't be bothered for now.
40 *    It also displays informations about baddump/nodump
41 *
42 * audit.c/h: Updated audit engine (-verifyroms) to use the new
43 *    hash functions.
44 *
45 * fileio.c/h: Updated file engine to use the new hash functions.
46 *    It is now possible to load by any specified checksum (in case
47 *    later we support other archivers with SHA1 signatures or
48 *    equivalent). If the file is open with flag VERIFY_ONLY and
49 *    the file is within an archive (zip), only the checksums
50 *    available in the archive header are used.
51 *
52 * windows/fronthlp.c:  Updated -identrom to the new hash engine, now
53 *    support any hash function available.
54 *    Added -listsha1 and -listmd5. It would be possible to add
55 *    also a -listbad now, to list bad dumps (ROMS we need a
56 *    redump for)
57 *    Updated -listdupcrc to check for all the available checksums.
58 *    The output is also a bit more useful and readable, even if it
59 *    is still not optimal.
60 *    Update -listwrongmerge to check for all the available checksums.
61 *
62 * windows/fileio.c: Removed check for FILE_TYPE_NOCRC (does not exist
63 *    anymore).
64 *
65 *
66 *
67 * Technical details:
68 *
69 * Checksum informations are now stored inside a string. They are
70 * stored in "printable hex format", which means that they use
71 * more memory than before (since a CRC needs 8 characters to
72 * be printed, instead of 4 bytes of raw information). In the
73 * driver, they are defined with handy macros which rely on
74 * automatic string pasting.
75 *
76 * Additional flags can also be stored in the string: for now we
77 * support NO_DUMP and BAD_DUMP, which replace, respectively,
78 * a CRC of 0 and a bit-inverted CRC.
79 *
80 * All the code that handles hash data is in hash.c. The rest of
81 * the core treats the data as an 'opaque type', so that the
82 * pointers are just passed along through functions but no
83 * operation is performed on the data outside hash.c. This
84 * is important in case we want to change the string
85 * representation later in the future.
86 *
87 * When loading a ROM, MAME will calculate and compare the
88 * checksum using any function for which the driver has declared
89 * an expected checksum. This happens because it would be useless
90 * to calculate a checksum if we cannot verify its correctness.
91 * For developers, it also means that MAME will not compute the
92 * SHA1 for you unless you specify a bogus one in the driver
93 * (like SHA1(0)).
94 *
95 * When verifying a ROM, MAME will use only the checksums available
96 * in the archive header (if zip, CRC). This is by design because
97 * -verifyroms has always been very fast. It is feasible to add
98 * a -fullverifyroms at a later moment, which will decompress the
99 * files and compute every checksum that has been declared in the
100 * driver.
101 *
102 * I have also prepared a little tool (SHA1Merger) which takes care
103 * of the following tasks:
104 *
105 * - Given an existing driver in old syntax (0.66 compatible), it will
106 *   convert all the existing ROM_LOAD entries in the new format, and
107 *   it will automatically compute and add SHA1 checksum for you if
108 *   it can find the romset.
109 *
110 * - Given a romset (ZIP file), it will prepare a ROM definition
111 *   skeleton for a driver, containing already rom names, lengths, and
112 *   checksums (both CRC and SHA1).
113 *
114 * The tool is available on www.mame.net as platform-independent source code
115 * (in Python), or win32 standalone executable.
116 *
117 */
18        * Redistributions of source code must retain the above copyright
19          notice, this list of conditions and the following disclaimer.
20        * Redistributions in binary form must reproduce the above copyright
21          notice, this list of conditions and the following disclaimer in
22          the documentation and/or other materials provided with the
23          distribution.
24        * Neither the name 'MAME' nor the names of its contributors may be
25          used to endorse or promote products derived from this software
26          without specific prior written permission.
11827
28    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
29    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
32    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
37    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38    POSSIBILITY OF SUCH DAMAGE.
39
40***************************************************************************/
41
11942#include "emu.h"
120#include "hash.h"
43#include "zlib.h"
12144#include "md5.h"
12245#include "sha1.h"
123
12446#include <ctype.h>
125#include <zlib.h>
12647
127#define ASSERT(x)
12848
129#ifndef TRUE
130#define TRUE    1
131#endif
49//**************************************************************************
50//  TYPE DEFINITIONS
51//**************************************************************************
13252
133#ifndef FALSE
134#define FALSE   0
135#endif
53// ======================> hash_crc
13654
137struct _hash_function_desc
55// CRC-32 hash implementation
56class hash_crc : public hash_base
13857{
139   const char* name;           // human-readable name
140   char code;                  // single-char code used within the hash string
141   unsigned int size;          // checksum size in bytes
58public:
59   // construction/destruction
60    hash_crc();
14261
143   // Functions used to calculate the hash of a memory block
144   void (*calculate_begin)(void);
145   void (*calculate_buffer)(const void* mem, unsigned long len);
146   void (*calculate_end)(UINT8* bin_chksum);
62   // operators   
63    operator UINT32() const { return (m_buffer[0] << 24) | (m_buffer[1] << 16) | (m_buffer[2] << 8) | m_buffer[3]; }
14764
65   // creation
66    virtual void begin();
67    virtual void buffer(const UINT8 *data, UINT32 length);
68    virtual void end();
69
70private:
71    // internal state
72    UINT8   m_buffer[4];
14873};
149typedef struct _hash_function_desc hash_function_desc;
15074
151static void h_crc_begin(void);
152static void h_crc_buffer(const void* mem, unsigned long len);
153static void h_crc_end(UINT8* chksum);
15475
155static void h_sha1_begin(void);
156static void h_sha1_buffer(const void* mem, unsigned long len);
157static void h_sha1_end(UINT8* chksum);
76// ======================> hash_md5
15877
159static void h_md5_begin(void);
160static void h_md5_buffer(const void* mem, unsigned long len);
161static void h_md5_end(UINT8* chksum);
162
163static const hash_function_desc hash_descs[HASH_NUM_FUNCTIONS] =
78// MD5 hash implementation
79class hash_md5 : public hash_base
16480{
165   {
166      "crc", 'c', 4,
167      h_crc_begin,
168      h_crc_buffer,
169      h_crc_end
170   },
81public:
82   // construction/destruction
83    hash_md5();
17184
172   {
173      "sha1", 's', 20,
174      h_sha1_begin,
175      h_sha1_buffer,
176      h_sha1_end
177   },
85   // creation
86    virtual void begin();
87    virtual void buffer(const UINT8 *data, UINT32 length);
88    virtual void end();
17889
179   {
180      "md5", 'm', 16,
181      h_md5_begin,
182      h_md5_buffer,
183      h_md5_end
184   },
90private:
91    // internal state
92    UINT8   m_buffer[16];
93    struct MD5Context m_context;
18594};
18695
187static const char *const info_strings[] =
96
97// ======================> hash_sha1
98
99// SHA1 hash implementation
100class hash_sha1 : public hash_base
188101{
189   "$ND$",       // No dump
190   "$BD$"        // Bad dump
102public:
103   // construction/destruction
104    hash_sha1();
105
106   // creation
107    virtual void begin();
108    virtual void buffer(const UINT8 *data, UINT32 length);
109    virtual void end();
110
111private:
112    // internal state
113    UINT8   m_buffer[20];
114    struct sha1_ctx m_context;
191115};
192116
193static const char binToStr[] = "0123456789abcdef";
194117
195118
196static const hash_function_desc* hash_get_function_desc(unsigned int function)
197{
198   unsigned int idx = 0;
119//**************************************************************************
120//  GLOBAL VARIABLES
121//**************************************************************************
199122
200   // Calling with zero in here is mostly an internal error
201   ASSERT(function != 0);
123const char *hash_collection::HASH_TYPES_CRC = "R";
124const char *hash_collection::HASH_TYPES_CRC_SHA1 = "RS";
125const char *hash_collection::HASH_TYPES_ALL = "RSM";
202126
203   // Compute the index of only one function
204   while (!(function & 1))
205   {
206      idx++;
207      function >>= 1;
208   }
209127
210   // Specify only one bit or die
211   ASSERT(function == 1);
212128
213   return &hash_descs[idx];
129//**************************************************************************
130//  HASH BASE
131//**************************************************************************
132
133//-------------------------------------------------
134//  hash_base - constructor
135//-------------------------------------------------
136
137hash_base::hash_base(char id, const char *name, UINT8 length, UINT8 *bufptr)
138   : m_next(NULL),
139     m_name(name),
140     m_in_progress(false),
141     m_parse_error(false),
142     m_id(id),
143     m_length(length),
144     m_bufptr(bufptr)
145{
146   memset(m_bufptr, 0, length);
214147}
215148
216const char* hash_function_name(unsigned int function)
149
150//-------------------------------------------------
151//  fromhex - convert a character to a hex value
152//-------------------------------------------------
153
154int hash_base::fromhex(char c)
217155{
218   const hash_function_desc* info = hash_get_function_desc(function);
219
220   return info->name;
156   if (c >= '0' && c <= '9')
157      return c - '0';
158   else if (c >= 'A' && c <= 'F')
159      return c - 'A' + 10;
160   else if (c >= 'a' && c <= 'f')
161      return (c - 'a' + 10);
162   else
163      return -1;
221164}
222165
223int hash_data_has_checksum(const char* data, unsigned int function)
166
167//-------------------------------------------------
168//  from_buffer - copy a raw buffer into the
169//  current hash
170//-------------------------------------------------
171
172bool hash_base::from_buffer(const UINT8 *buffer, int buflen)
224173{
225   const hash_function_desc* info = hash_get_function_desc(function);
226   char str[3];
227   const char* res;
174   // fail if we're too small
175   if (buflen < m_length)
176      return false;
177   memcpy(m_bufptr, buffer, m_length);
178   return true;
179}
228180
229   str[0] = info->code;
230   str[1] = ':';
231   str[2] = '\0';
232181
233   // Check if the specified hash function is used within this data
234   res = strstr(data, str);
182//-------------------------------------------------
183//  string - output a string for the current hash
184//-------------------------------------------------
235185
236   if (!res)
237      return 0;
238
239   // Return the offset within the string where the checksum begins
240   return (res - data + 2);
186const char *hash_base::string(astring &buffer)
187{
188   buffer.reset();
189   for (int index = 0; index < m_length; index++)
190      buffer.catprintf("%02x", m_bufptr[index]);
191   return buffer;
241192}
242193
243static int hash_data_add_binary_checksum(char* d, unsigned int function, const UINT8* checksum)
194
195//-------------------------------------------------
196//  from_string - parse a string into the current
197//   hash
198//-------------------------------------------------
199
200bool hash_base::from_string(const char *&string, int length)
244201{
245   const hash_function_desc* desc = hash_get_function_desc(function);
246   char* start = d;
247   unsigned i;
202   // fail if we're too short
203   if (length < 2 * m_length)
204      return false;
248205
249   *d++ = desc->code;
250   *d++ = ':';
251
252   for (i=0;i<desc->size;i++)
206   // loop over bytes
207   m_parse_error = false;
208   for (int index = 0; index < m_length; index++)
253209   {
254      UINT8 c = *checksum++;
210      // parse the upper digit
211      int upper = fromhex(string[0]);
212      if (upper == -1)
213      {
214         m_parse_error = true;
215         memset(m_bufptr, 0, m_length);
216         return false;
217      }
218     
219      // parse the lower digit
220      int lower = fromhex(string[1]);
221      if (lower == -1)
222      {
223         m_parse_error = true;
224         memset(m_bufptr, 0, m_length);
225         return false;
226      }
255227
256      *d++ = binToStr[(c >> 4) & 0xF];
257      *d++ = binToStr[(c >> 0) & 0xF];
228      // set the byte and advance     
229      m_bufptr[index] = (upper << 4) | lower;
230      string += 2;
258231   }
232   return true;
233}
259234
260   *d++ = '#';
235
261236
262   // Return the number of written bytes
263   return (d - start);
264}
237//**************************************************************************
238//  HASH CRC
239//**************************************************************************
265240
241//-------------------------------------------------
242//  hash_crc - constructor
243//-------------------------------------------------
266244
267static int hash_compare_checksum(const char* chk1, const char* chk2, int length)
245hash_crc::hash_crc()
246   : hash_base(hash_collection::HASH_CRC, "crc", sizeof(m_buffer), m_buffer)
268247{
269   char c1, c2;
248}
270249
271   // The printable format is twice as longer
272   length *= 2;
273250
274   // This is basically a case-insensitive string compare
275   while (length--)
276   {
277      c1 = *chk1++;
278      c2 = *chk2++;
251//-------------------------------------------------
252//  begin - initialize state for hash computation
253//-------------------------------------------------
279254
280      if (tolower((UINT8)c1) != tolower((UINT8)c2))
281         return 0;
282      if (!c1)
283         return 0;
284   }
285
286   return 1;
255void hash_crc::begin()
256{
257   m_in_progress = true;
258   memset(m_buffer, 0, sizeof(m_buffer));
287259}
288260
289261
290// Compare two hashdata
291int hash_data_is_equal(const char* d1, const char* d2, unsigned int functions)
262//-------------------------------------------------
263//  buffer - hash a buffer's worth of data
264//-------------------------------------------------
265
266void hash_crc::buffer(const UINT8 *data, UINT32 length)
292267{
293   int i;
294   char incomplete = 0;
295   char ok = 0;
268   UINT32 crc = crc32(*this, data, length);
269   m_buffer[0] = crc >> 24;
270   m_buffer[1] = crc >> 16;
271   m_buffer[2] = crc >> 8;
272   m_buffer[3] = crc >> 0;
273}
296274
297   // If no function is specified, it means we need to check for all
298   //  of them
299   if (!functions)
300      functions = ~functions;
301275
302   for (i=1; i != (1<<HASH_NUM_FUNCTIONS); i<<=1)
303      if (functions & i)
304      {
305         int offs1, offs2;
276//-------------------------------------------------
277//  end - finish hash computation
278//-------------------------------------------------
306279
307         // Check if both hashdata contain the current function's checksum
308         offs1 = hash_data_has_checksum(d1, i);
309         offs2 = hash_data_has_checksum(d2, i);
280void hash_crc::end()
281{
282   m_in_progress = false;
283}
310284
311         if (offs1 && offs2)
312         {
313            const hash_function_desc* info = hash_get_function_desc(i);
314285
315            if (!hash_compare_checksum(d1+offs1, d2+offs2, info->size))
316               return 0;
317286
318            ok = 1;
319         }
320         // If the function was contained only in one, remember that our comparison
321         //  is incomplete
322         else if (offs1 || offs2)
323         {
324            incomplete = 1;
325         }
326      }
287//**************************************************************************
288//  HASH MD5
289//**************************************************************************
327290
328   // If we could not compare any function, return error
329   if (!ok)
330      return 0;
291//-------------------------------------------------
292//  hash_md5 - constructor
293//-------------------------------------------------
331294
332   // Return success code
333   return (incomplete ? 2 : 1);
295hash_md5::hash_md5()
296   : hash_base(hash_collection::HASH_MD5, "md5", sizeof(m_buffer), m_buffer)
297{
334298}
335299
336300
337int hash_data_extract_printable_checksum(const char* data, unsigned int function, char* checksum)
301//-------------------------------------------------
302//  begin - initialize state for hash computation
303//-------------------------------------------------
304
305void hash_md5::begin()
338306{
339   unsigned int i;
340   const hash_function_desc* info;
341   int offs;
307   m_in_progress = true;
308   MD5Init(&m_context);
309}
342310
343   // Check if the hashdata contains the requested function
344   offs = hash_data_has_checksum(data, function);
345311
346   if (!offs)
347      return 0;
312//-------------------------------------------------
313//  buffer - hash a buffer's worth of data
314//-------------------------------------------------
348315
349   // Move to the beginning of the checksum
350   data += offs;
316void hash_md5::buffer(const UINT8 *data, UINT32 length)
317{
318   MD5Update(&m_context, (md5byte *)data, length);
319}
351320
352   info = hash_get_function_desc(function);
353321
354   // Return the number of required bytes
355   if (!checksum)
356      return info->size*2+1;
322//-------------------------------------------------
323//  end - finish hash computation
324//-------------------------------------------------
357325
358   // If the terminator is not found at the right position,
359   //  return a full-zero checksum and warn about it. This is mainly
360   //  for developers putting checksums of '0' or '1' to ask MAME
361   //  to compute the correct values for them.
362   if (data[info->size*2] != '#')
363   {
364      memset(checksum, '0', info->size*2);
365      checksum[info->size*2] = '\0';
366      return 2;
367   }
326void hash_md5::end()
327{
328   MD5Final(m_buffer, &m_context);
329   m_in_progress = false;
330}
368331
369   // If it contains invalid hexadecimal characters,
370   //  treat the checksum as zero and return warning
371   for (i=0;i<info->size*2;i++)
372      if (!(data[i]>='0' && data[i]<='9') &&
373         !(data[i]>='a' && data[i]<='f') &&
374         !(data[i]>='A' && data[i]<='F'))
375      {
376         memset(checksum, '0', info->size*2);
377         checksum[info->size*2] = '\0';
378         return 2;
379      }
380332
381   // Copy the checksum (and make it lowercase)
382   for (i=0;i<info->size*2;i++)
383      checksum[i] = tolower((UINT8)data[i]);
384333
385   checksum[info->size*2] = '\0';
334//**************************************************************************
335//  HASH SHA1
336//**************************************************************************
386337
387   return 1;
388}
338//-------------------------------------------------
339//  hash_sha1 - constructor
340//-------------------------------------------------
389341
390static int hex_string_to_binary(unsigned char* binary, const char* data, int size)
342hash_sha1::hash_sha1()
343   : hash_base(hash_collection::HASH_SHA1, "sha1", sizeof(m_buffer), m_buffer)
391344{
392   unsigned int i;
393   char c;
345}
394346
395   for (i = 0; i < size * 2; i++)
396   {
397      c = tolower((UINT8)*data++);
398347
399      if (c >= '0' && c <= '9')
400         c -= '0';
401      else if (c >= 'a' && c <= 'f')
402         c -= 'a' - 10;
403      else
404         return 1;
348//-------------------------------------------------
349//  begin - initialize state for hash computation
350//-------------------------------------------------
405351
406      if (i % 2 == 0)
407         binary[i / 2] = c * 16;
408      else
409         binary[i / 2] += c;
410   }
411   return 0;
352void hash_sha1::begin()
353{
354   m_in_progress = true;
355   sha1_init(&m_context);
412356}
413357
414int hash_data_extract_binary_checksum(const char* data, unsigned int function, unsigned char* checksum)
415{
416   const hash_function_desc* info;
417   int offs;
418358
419   // Check if the hashdata contains the requested function
420   offs = hash_data_has_checksum(data, function);
359//-------------------------------------------------
360//  buffer - hash a buffer's worth of data
361//-------------------------------------------------
421362
422   if (!offs)
423      return 0;
363void hash_sha1::buffer(const UINT8 *data, UINT32 length)
364{
365   sha1_update(&m_context, length, data);
366}
424367
425   // Move to the beginning of the checksum
426   data += offs;
427368
428   info = hash_get_function_desc(function);
369//-------------------------------------------------
370//  end - finish hash computation
371//-------------------------------------------------
429372
430   // Return the number of required bytes
431   if (!checksum)
432      return info->size;
373void hash_sha1::end()
374{
375   sha1_final(&m_context);
376   sha1_digest(&m_context, sizeof(m_buffer), m_buffer);
377   m_in_progress = false;
378}
433379
434   // Clear the checksum array
435   memset(checksum, 0, info->size);
436380
437   // If the terminator is not found at the right position,
438   //  return a full-zero checksum and warn about it. This is mainly
439   //  for developers putting checksums of '0' or '1' to ask MAME
440   //  to compute the correct values for them.
441   if (data[info->size*2] != '#')
442   {
443      memset(checksum, '\0', info->size);
444      return 2;
445   }
446381
447   // Convert hex string into binary
448   if (hex_string_to_binary(checksum, data, info->size))
449      {
450         // Invalid character: the checksum is treated as zero,
451         //  and a warning is returned
452         memset(checksum, '\0', info->size);
453         return 2;
454      }
382//**************************************************************************
383//  HASH COLLECTION
384//**************************************************************************
455385
456   return 1;
457}
386//-------------------------------------------------
387//  hash_collection - constructor
388//-------------------------------------------------
458389
459int hash_data_has_info(const char* data, unsigned int info)
390hash_collection::hash_collection()
460391{
461   char* res = (char*)strstr(data, info_strings[info]);
392}
462393
463   if (!res)
464      return 0;
465394
466   return 1;
395hash_collection::hash_collection(const char *string)
396{
397   from_internal_string(string);
467398}
468399
469void hash_data_copy(char* dst, const char* src)
400
401hash_collection::hash_collection(const hash_collection &src)
470402{
471   // Copying string is enough
472   strcpy(dst, src);
403   copyfrom(src);
473404}
474405
475void hash_data_clear(char* dst)
406
407//-------------------------------------------------
408//  ~hash_collection - destructor
409//-------------------------------------------------
410
411hash_collection::~hash_collection()
476412{
477   // Clear the buffer
478   memset(dst, 0, HASH_BUF_SIZE);
479413}
480414
481unsigned int hash_data_used_functions(const char* data)
415
416//-------------------------------------------------
417//  operator= - assignment operator
418//-------------------------------------------------
419
420hash_collection &hash_collection::operator=(const hash_collection &src)
482421{
483   int i;
484   unsigned int res = 0;
422   // ignore self-assignment
423   if (this != &src)
424      copyfrom(src);
425   return *this;
426}
485427
486   if (!data)
487      return 0;
488428
489   for (i=0;i<HASH_NUM_FUNCTIONS;i++)
490      if (hash_data_has_checksum(data, 1<<i))
491         res |= 1<<i;
429//-------------------------------------------------
430//  operator== - test for equality
431//-------------------------------------------------
492432
493   return res;
494}
495
496int hash_data_insert_printable_checksum(char* d, unsigned int function, const char* checksum)
433bool hash_collection::operator==(const hash_collection &rhs) const
497434{
498   const hash_function_desc* desc;
499   UINT8 binary_checksum[20];
435   // look for a mismatch in any hash; do not fail if one is missing
436   for (hash_base *hash = m_hashlist.first(); hash != NULL; hash = hash->next())
437   {
438      hash_base *rhs_hash = rhs.hash(hash->id());
439      if (hash != NULL && rhs_hash != NULL && *hash != *rhs_hash)
440         return false;
441   }
500442
501   desc = hash_get_function_desc(function);
443   // if all shared hashes match, return true
444   return true;
445}
502446
503   ASSERT(desc->size <= sizeof(binary_checksum));
504447
505   if (hex_string_to_binary(binary_checksum, checksum, desc->size))
506      return 2;
448//-------------------------------------------------
449//  hash - return a hash of the given type
450//-------------------------------------------------
507451
508   return hash_data_insert_binary_checksum(d, function, binary_checksum);
452hash_base *hash_collection::hash(char type) const
453{
454   // look for a mismatch in any hash; do not fail if one is missing
455   for (hash_base *hash = m_hashlist.first(); hash != NULL; hash = hash->next())
456      if (hash->id() == type)
457         return hash;
458   return NULL;
509459}
510460
511int hash_data_insert_binary_checksum(char* d, unsigned int function, const UINT8* checksum)
512{
513   int offset;
514461
515   offset = hash_data_has_checksum(d, function);
462//-------------------------------------------------
463//  hash_types - return a list of hash types as
464//  a string
465//-------------------------------------------------
516466
517   if (!offset)
518   {
519      d += strlen(d);
520      d += hash_data_add_binary_checksum(d, function, checksum);
521      *d = '\0';
467const char *hash_collection::hash_types(astring &buffer) const
468{
469   buffer.reset();
470   for (hash_base *hash = m_hashlist.first(); hash != NULL; hash = hash->next())
471      buffer.cat(hash->id());
472   return buffer;
473}
522474
523      return 1;
524   }
525   else
526   {
527      // Move to the start of the whole checksum signature, not only to the checksum
528      // itself
529      d += offset - 2;
530475
531      // Overwrite previous checksum with new one
532      hash_data_add_binary_checksum(d, function, checksum);
476//-------------------------------------------------
477//  reset - reset the hash collection to an empty
478//  set of hashes and flags
479//-------------------------------------------------
533480
534      return 2;
535   }
481bool hash_collection::parse_errors() const
482{
483   for (hash_base *hash = m_hashlist.first(); hash != NULL; hash = hash->next())
484      if (hash->parse_error())
485         return true;
486   return false;
536487}
537488
538void hash_compute(char* dst, const unsigned char* data, unsigned long length, unsigned int functions)
539{
540   int i;
541489
542   hash_data_clear(dst);
490//-------------------------------------------------
491//  reset - reset the hash collection to an empty
492//  set of hashes and flags
493//-------------------------------------------------
543494
544   // Zero means use all the functions
545   if (functions == 0)
546      functions = ~functions;
495void hash_collection::reset()
496{
497   m_hashlist.reset();
498   m_flags.reset();
499}
547500
548   for (i=0;i<HASH_NUM_FUNCTIONS;i++)
549   {
550      unsigned func = 1 << i;
551501
552      if (functions & func)
553      {
554         const hash_function_desc* desc = hash_get_function_desc(func);
555         UINT8 chksum[256];
502//-------------------------------------------------
503//  add_from_buffer - add a new hash, importing
504//  from a buffer
505//-------------------------------------------------
556506
557         desc->calculate_begin();
558         desc->calculate_buffer(data, length);
559         desc->calculate_end(chksum);
507hash_base *hash_collection::add_from_buffer(char type, const UINT8 *buffer, int bufflen)
508{
509   // nuke any existing hash with the same ID
510   hash_base *existing = hash(type);
511   if (existing != NULL)
512      m_hashlist.remove(*existing);
560513
561         dst += hash_data_add_binary_checksum(dst, func, chksum);
562      }
514   // first allocate by ID
515   hash_base *newhash = alloc_by_id(type);
516   if (newhash == NULL)
517      return NULL;
518   
519   // then import
520   if (!newhash->from_buffer(buffer, bufflen))
521   {
522      global_free(newhash);
523      return NULL;
563524   }
564
565   *dst = '\0';
525   
526   // and append to our list
527   return &m_hashlist.append(*newhash);
566528}
567529
568void hash_data_print(const char* data, unsigned int functions, char* buffer)
569{
570   int i, j;
571   char first = 1;
572530
573   if (functions == 0)
574      functions = ~functions;
531//-------------------------------------------------
532//  add_from_string - add a new hash, importing
533//  from a string
534//-------------------------------------------------
575535
576   buffer[0] = '\0';
536hash_base *hash_collection::add_from_string(char type, const char *buffer, int length)
537{
538   // nuke any existing hash with the same ID
539   hash_base *existing = hash(type);
540   if (existing != NULL)
541      m_hashlist.remove(*existing);
577542
578   for (i=0;i<HASH_NUM_FUNCTIONS;i++)
543   // first allocate by ID
544   hash_base *newhash = alloc_by_id(type);
545   if (newhash == NULL)
546      return NULL;
547   
548   // then import
549   if (!newhash->from_string(buffer, length))
579550   {
580      unsigned func = 1 << i;
581
582      if ((functions & func) && hash_data_has_checksum(data, func))
583      {
584         char temp[256];
585
586         if (!first)
587            strcat(buffer, " ");
588         first = 0;
589
590         strcpy(temp, hash_function_name(func));
591         for (j = 0; temp[j]; j++)
592            temp[j] = toupper((UINT8)temp[j]);
593         strcat(buffer, temp);
594         strcat(buffer, "(");
595
596         hash_data_extract_printable_checksum(data, func, temp);
597         strcat(buffer, temp);
598         strcat(buffer, ")");
599      }
551      global_free(newhash);
552      return NULL;
600553   }
554   
555   // and append to our list
556   return &m_hashlist.append(*newhash);
601557}
602558
603int hash_verify_string(const char *hash)
604{
605   int len, i;
606559
607   if (!hash)
608      return FALSE;
560//-------------------------------------------------
561//  remove - remove a hash of the given type
562//-------------------------------------------------
609563
610   while(*hash)
611   {
612      if (*hash == '$')
564bool hash_collection::remove(char type)
565{
566   // scan the list of hashes for a match
567   for (hash_base *hash = m_hashlist.first(); hash != NULL; hash = hash->next())
568      if (hash->id() == type)
613569      {
614         if (memcmp(hash, NO_DUMP, 4) && memcmp(hash, BAD_DUMP, 4))
615            return FALSE;
616         hash += 4;
570         m_hashlist.remove(*hash);
571         return true;
617572      }
618      else
619      {
620         /* first make sure that the next char is a colon */
621         if (hash[1] != ':')
622            return FALSE;
573   
574   // didn't find it
575   return false;
576}
623577
624         /* search for a hash function for this code */
625         for (i = 0; i < sizeof(hash_descs) / sizeof(hash_descs[0]); i++)
626         {
627            if (*hash == hash_descs[i].code)
628               break;
629         }
630         if (i >= sizeof(hash_descs) / sizeof(hash_descs[0]))
631            return FALSE;
632578
633         /* we have a proper code */
634         len = hash_descs[i].size * 2;
635         hash += 2;
579//-------------------------------------------------
580//  crc - return the CRC hash if present
581//-------------------------------------------------
636582
637         for (i = 0; (hash[i] != '#') && (i < len); i++)
638         {
639            if (!isxdigit((UINT8)hash[i]))
640               return FALSE;
641         }
642         if (hash[i] != '#')
643            return FALSE;
583bool hash_collection::crc(UINT32 &result)
584{
585   // attempt to find the CRC hash; if we fail, return false
586   hash_base *crchash = hash(HASH_CRC);
587   if (crchash == NULL)
588      return false;
644589
645         hash += i+1;
646      }
647   }
648   return TRUE;
590   // downcast to a hash_crc and convert to a UINT32
591   result = *downcast<hash_crc *>(crchash);
592   return true;
649593}
650594
651595
596//-------------------------------------------------
597//  add_crc - add a CRC hash
598//-------------------------------------------------
652599
653/*********************************************************************
654    Hash functions - Wrappers
655 *********************************************************************/
600hash_base *hash_collection::add_crc(UINT32 crc)
601{
602   // expand to a buffer
603   UINT8 buffer[4];
604   buffer[0] = crc >> 24;
605   buffer[1] = crc >> 16;
606   buffer[2] = crc >> 8;
607   buffer[3] = crc >> 0;
608   
609   // add it the standard way
610   return add_from_buffer(HASH_CRC, buffer, sizeof(buffer));
611}
656612
657static UINT32 crc;
658613
659static void h_crc_begin(void)
614//-------------------------------------------------
615//  internal_string - convert set of hashes and
616//  flags to a string in our internal compact
617//  format
618//-------------------------------------------------
619
620const char *hash_collection::internal_string(astring &buffer) const
660621{
661   crc = 0;
622   astring temp;
623   
624   // output hashes first
625   buffer.reset();
626   for (hash_base *hash = m_hashlist.first(); hash != NULL; hash = hash->next())
627      buffer.cat(hash->id()).cat(hash->string(temp));
628
629   // append flags
630   buffer.cat(m_flags);
631   return buffer;
662632}
663633
664static void h_crc_buffer(const void* mem, unsigned long len)
634
635//-------------------------------------------------
636//  macro_string - convert set of hashes and
637//  flags to a string in the macroized format
638//-------------------------------------------------
639
640const char *hash_collection::macro_string(astring &buffer) const
665641{
666   crc = crc32(crc, (UINT8*)mem, len);
667}
642   astring temp;
668643
669static void h_crc_end(UINT8* bin_chksum)
670{
671   bin_chksum[0] = (UINT8)(crc >> 24);
672   bin_chksum[1] = (UINT8)(crc >> 16);
673   bin_chksum[2] = (UINT8)(crc >> 8);
674   bin_chksum[3] = (UINT8)(crc >> 0);
644   // output hashes first
645   buffer.reset();
646   for (hash_base *hash = m_hashlist.first(); hash != NULL; hash = hash->next())
647   {
648      buffer.cat(temp.cpy(hash->name()).toupper());
649      buffer.cat("(").cat(hash->string(temp)).cat(") ");
650   }
651
652   // append flags
653   if (flag(FLAG_NO_DUMP))
654      buffer.cat("NO_DUMP ");
655   if (flag(FLAG_BAD_DUMP))
656      buffer.cat("BAD_DUMP ");
657   return buffer.trimspace();
675658}
676659
677660
678static struct sha1_ctx sha1ctx;
661//-------------------------------------------------
662//  from_internal_string - convert an internal
663//  compact string to set of hashes and flags
664//-------------------------------------------------
679665
680static void h_sha1_begin(void)
666bool hash_collection::from_internal_string(const char *string)
681667{
682   sha1_init(&sha1ctx);
668   // start fresh
669   reset();
670
671   // determine the end of the string
672   const char *stringend = string + strlen(string);
673   const char *ptr = string;
674   
675   // loop until we hit it
676   bool errors = false;
677   while (ptr < stringend)
678   {
679      char c = *ptr++;
680      char lc = tolower(c);
681     
682      // non-hex alpha values specify a hash type
683      if (lc >= 'g' && lc <= 'z')
684      {
685         hash_base *hash = alloc_by_id(c);
686         if (hash != NULL)
687         {
688            if (!hash->from_string(ptr, stringend - ptr))
689               errors = true;
690            m_hashlist.append(*hash);
691         }
692         else
693            errors = true;
694      }
695     
696      // hex values are ignored, though unexpected
697      else if ((lc >= '0' && lc <= '9') || (lc >= 'a' && lc <= 'f'))
698         errors = true;
699     
700      // anything else is a flag
701      else
702         m_flags.cat(c);
703   }
704   return !errors;
683705}
684706
685static void h_sha1_buffer(const void* mem, unsigned long len)
707
708//-------------------------------------------------
709//  begin - begin hashing
710//-------------------------------------------------
711
712void hash_collection::begin(const char *types)
686713{
687   sha1_update(&sha1ctx, len, (UINT8*)mem);
714   // by default use all types
715   if (types == NULL)
716   {
717      m_hashlist.append(*alloc_by_id(HASH_CRC)).begin();
718      m_hashlist.append(*alloc_by_id(HASH_MD5)).begin();
719      m_hashlist.append(*alloc_by_id(HASH_SHA1)).begin();
720   }
721   
722   // otherwise, just allocate the ones that are specified
723   else
724   {
725      for (const char *scan = types; *scan != 0; scan++)
726      {
727         // nuke any existing hash of this type
728         hash_base *existing = hash(*scan);
729         if (existing != NULL)
730            m_hashlist.remove(*existing);
731         
732         // append a new one
733         m_hashlist.append(*alloc_by_id(*scan)).begin();
734      }
735   }
688736}
689737
690static void h_sha1_end(UINT8* bin_chksum)
738
739//-------------------------------------------------
740//  buffer - add the given buffer to the hash
741//-------------------------------------------------
742
743void hash_collection::buffer(const UINT8 *data, UINT32 length)
691744{
692   sha1_final(&sha1ctx);
693   sha1_digest(&sha1ctx, 20, bin_chksum);
745   // buffer each hash appropriately
746   for (hash_base *hash = m_hashlist.first(); hash != NULL; hash = hash->next())
747      if (hash->in_progress())
748         hash->buffer(data, length);
694749}
695750
696751
697static struct MD5Context md5_ctx;
752//-------------------------------------------------
753//  end - stop hashing
754//-------------------------------------------------
698755
699static void h_md5_begin(void)
756void hash_collection::end()
700757{
701   MD5Init(&md5_ctx);
758   // end each hash
759   for (hash_base *hash = m_hashlist.first(); hash != NULL; hash = hash->next())
760      if (hash->in_progress())
761         hash->end();
702762}
703763
704static void h_md5_buffer(const void* mem, unsigned long len)
764
765//-------------------------------------------------
766//  alloc_by_id - based on the ID character,
767//  allocate a new hash
768//-------------------------------------------------
769
770hash_base *hash_collection::alloc_by_id(char id)
705771{
706   MD5Update(&md5_ctx, (md5byte*)mem, len);
772   switch (id)
773   {
774      case HASH_CRC:   return global_alloc(hash_crc);
775      case HASH_MD5:   return global_alloc(hash_md5);
776      case HASH_SHA1:   return global_alloc(hash_sha1);
777      default:      return NULL;
778   }
707779}
708780
709static void h_md5_end(UINT8* bin_chksum)
781
782//-------------------------------------------------
783//  copyfrom - copy everything from another
784//  collection
785//-------------------------------------------------
786
787void hash_collection::copyfrom(const hash_collection &src)
710788{
711   MD5Final(bin_chksum, &md5_ctx);
789   // copy flags directly
790   m_flags = src.m_flags;
791   
792   // rebuild the hashlist by copying from the source
793   m_hashlist.reset();
794   for (hash_base *hash = src.first(); hash != NULL; hash = hash->next())
795      add_from_buffer(hash->id(), hash->buffer(), hash->length());
712796}
src/emu/hash.h
r10427r10428
1/*********************************************************************
1/***************************************************************************
22
33    hash.h
44
55    Function to handle hash functions (checksums)
66
7    Copyright Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
7    Based on original idea by Farfetch'd
98
10*********************************************************************/
9****************************************************************************
1110
11    Copyright Aaron Giles
12    All rights reserved.
13
14    Redistribution and use in source and binary forms, with or without
15    modification, are permitted provided that the following conditions are
16    met:
17
18        * Redistributions of source code must retain the above copyright
19          notice, this list of conditions and the following disclaimer.
20        * Redistributions in binary form must reproduce the above copyright
21          notice, this list of conditions and the following disclaimer in
22          the documentation and/or other materials provided with the
23          distribution.
24        * Neither the name 'MAME' nor the names of its contributors may be
25          used to endorse or promote products derived from this software
26          without specific prior written permission.
27
28    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
29    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
32    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
37    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38    POSSIBILITY OF SUCH DAMAGE.
39
40***************************************************************************/
41
1242#pragma once
1343
1444#ifndef __HASH_H__
1545#define __HASH_H__
1646
17#define HASH_INFO_NO_DUMP   0
18#define HASH_INFO_BAD_DUMP   1
1947
20#define HASH_CRC    (1 << 0)
21#define HASH_SHA1   (1 << 1)
22#define HASH_MD5    (1 << 2)
48//**************************************************************************
49//  MACROS
50//**************************************************************************
2351
24#define HASH_NUM_FUNCTIONS  3
52// use these to define compile-time internal-format hash strings
53#define CRC(x)            "R" #x
54#define MD5(x)            "M" #x
55#define SHA1(x)            "S" #x
56#define NO_DUMP            "!"
57#define BAD_DUMP         "^"
2558
26// Standard size of a hash data buffer, all the manipulated buffers
27//  must respect this size
28#define HASH_BUF_SIZE       256
2959
30// Get function name of the specified function
31const char* hash_function_name(unsigned int function);
3260
33// Check if const char* contains the checksum for a specific function
34int hash_data_has_checksum(const char* d, unsigned int function);
61//**************************************************************************
62//  TYPE DEFINITIONS
63//**************************************************************************
3564
36// Extract the binary or printable checksum of a specific function from a hash data. If the checksum information
37//  is not available, the functions return 0. If the pointer to the output buffer is NULL, the function will
38//  return the minimum size of the output buffer required to store the informations. Otherwise, the buffer
39//  will be filled and the function will return 1 as success code.
40int hash_data_extract_binary_checksum(const char* d, unsigned int function, unsigned char* checksum);
41int hash_data_extract_printable_checksum(const char* d, unsigned int function, char* checksum);
4265
43// Insert an already computed binary checksum inside a hash data. This is useful when we already have
44//  checksum informations (e.g, from archive headers) and we want to prepare a hash data to compare
45//  with another const char* (e.g. the expected checksums). Returns 0 in case of error, 1 if the checksum
46//  was added correctly, 2 if the checksum was added overwriting a previously existing checksum for the
47//  the same function
48int hash_data_insert_binary_checksum(char* d, unsigned int function, const unsigned char* checksum);
49int hash_data_insert_printable_checksum(char* d, unsigned int function, const char* checksum);
66// ======================> hash_base
5067
51// Check if the hash data contains the requested info
52int hash_data_has_info(const char* d, unsigned int info);
68// base class for all hash types, which does most of the heavy lifting
69class hash_base
70{
71   friend class simple_list<hash_base>;
5372
54// Compare two hash data to check if they are the same. 'functions' can be either a combination of the
55//  hash function bits (HASH_CRC, etc) or zero to ask to check for all the available checksums
56int hash_data_is_equal(const char* d1, const char* d2, unsigned int functions);
73public:
74    // construction/destruction
75    hash_base(char id, const char *name, UINT8 length, UINT8 *bufptr);
76   
77    // operators
78    bool operator==(const hash_base &rhs) const { return (m_length == rhs.m_length && memcmp(m_bufptr, rhs.m_bufptr, m_length) == 0); }
79    bool operator!=(const hash_base &rhs) const { return (m_length != rhs.m_length || memcmp(m_bufptr, rhs.m_bufptr, m_length) != 0); }
80   
81    // getters
82    hash_base *next() const { return m_next; }
83    char id() const { return m_id; }
84    const char *name() const { return m_name; }
85    int length() const { return m_length; }
86    bool in_progress() const { return m_in_progress; }
87    bool parse_error() const { return m_parse_error; }
88    UINT8 byte(int index) const { return (index >= 0 && index < m_length) ? m_bufptr[index] : 0; }
89   
90    // buffer conversion
91    const UINT8 *buffer() { return m_bufptr; }
92    bool from_buffer(const UINT8 *buffer, int buflen);
93   
94    // string conversion
95    const char *string(astring &buffer);
96    bool from_string(const char *&string,  int length);
97   
98    // creation
99    virtual void begin() = 0;
100    virtual void buffer(const UINT8 *data, UINT32 length) = 0;
101    virtual void end() = 0;
102   
103protected:
104   // internal helpers
105    int fromhex(char c);
106   
107    // internal state
108    hash_base *      m_next;
109    const char *   m_name;
110    bool         m_in_progress;
111    bool         m_parse_error;
112    char         m_id;
113    UINT8         m_length;
114    UINT8 *        m_bufptr;
115};
57116
58// Print hash data informations in a standard format. 'functions' can be either a combination of the
59//  hash function bits (HASH_CRC, etc) or zero to ask to print all the available checksums
60void hash_data_print(const char* d, unsigned int functions, char* buffer);
61117
62// Copy hash data informations
63void hash_data_copy(char* dst, const char* src);
118// ======================> hash_collection
64119
65// Clear hash data informations
66void hash_data_clear(char* dst);
120// a collection of the various supported hashes and flags
121class hash_collection
122{
123public:
124   // hash types are identified by non-hex alpha values (G-Z)
125   static const char HASH_CRC = 'R';
126   static const char HASH_MD5 = 'M';
127   static const char HASH_SHA1 = 'S';
128   
129   // common combinations for requests
130   static const char *HASH_TYPES_CRC;
131   static const char *HASH_TYPES_CRC_SHA1;
132   static const char *HASH_TYPES_ALL;
133   
134   // flags are identified by punctuation marks
135   static const char FLAG_NO_DUMP = '!';
136   static const char FLAG_BAD_DUMP = '^';
67137
68// Check which functions we have a checksum of inside the data
69unsigned int hash_data_used_functions(const char* d);
138   // construction/destruction
139    hash_collection();
140    hash_collection(const char *string);
141    hash_collection(const hash_collection &src);
142    ~hash_collection();
143   
144    // operators
145    hash_collection &operator=(const hash_collection &src);
146    bool operator==(const hash_collection &rhs) const;
147    bool operator!=(const hash_collection &rhs) const { return !(*this == rhs); }
70148
71// Compute hash of a data chunk in memory. Parameter 'functions' specifies which hashing functions
72//  we want the checksum of.
73void hash_compute(char* dst, const unsigned char* data, unsigned long length, unsigned int functions);
149   // getters
150    bool flag(char flag) const { return (m_flags.chr(0, flag) != -1); }
151    hash_base *hash(char type) const;
152    hash_base *first() const { return m_hashlist.first(); }
153    const char *hash_types(astring &buffer) const;
154    bool parse_errors() const;
74155
75// Verifies that a hash string is valid
76int hash_verify_string(const char *hash);
156   // hash manipulators
157   void reset();
158   hash_base *add_from_buffer(char type, const UINT8 *buffer, int bufflen);
159   hash_base *add_from_string(char type, const char *buffer, int length);
160   bool remove(char type);
161   
162   // CRC-specific helpers
163   bool crc(UINT32 &result);
164   hash_base *add_crc(UINT32 crc);
77165
166   // string conversion   
167    const char *internal_string(astring &buffer) const;
168    const char *macro_string(astring &buffer) const;
169    bool from_internal_string(const char *string);
170   
171   // creation
172    void begin(const char *types = NULL);
173    void buffer(const UINT8 *data, UINT32 length);
174    void end();
175    void compute(const UINT8 *data, UINT32 length, const char *types = NULL) { begin(types); buffer(data, length); end(); }
78176
177private:
178   // internal helpers
179    static hash_base *alloc_by_id(char id);
180    void copyfrom(const hash_collection &src);
181
182   // internal state
183   astring               m_flags;
184    simple_list<hash_base>    m_hashlist;
185};
186
187
79188#endif   /* __HASH_H__ */
src/emu/info.c
r10427r10428
452452    parent set
453453-------------------------------------------------*/
454454
455static const char *get_merge_name(const rom_entry *rom, int parents, const parent_info **pinfoarray)
455static const char *get_merge_name(const hash_collection &romhashes, int parents, const parent_info **pinfoarray)
456456{
457457   int parent;
458458   const char *merge_name = NULL;
459
459   
460460   for (parent = 0; parent < parents; ++parent)
461461   {
462462      const machine_config *pconfig = &pinfoarray[parent]->mconfig;
r10427r10428
467467      for (psource = rom_first_source(*pconfig); psource != NULL; psource = rom_next_source(*psource))
468468         for (pregion = rom_first_region(*psource); pregion != NULL; pregion = rom_next_region(pregion))
469469            for (prom = rom_first_file(pregion); prom != NULL; prom = rom_next_file(prom))
470               if (hash_data_is_equal(ROM_GETHASHDATA(rom), ROM_GETHASHDATA(prom), 0))
470               if (romhashes == hash_collection(ROM_GETHASHDATA(prom)))
471471               {
472472                  merge_name = ROM_GETNAME(prom);
473473                  break;
r10427r10428
528528                  continue;
529529
530530               /* if we have a valid ROM and we are a clone, see if we can find the parent ROM */
531               if (!ROM_NOGOODDUMP(rom) && parents > 0)
531               hash_collection hashes(ROM_GETHASHDATA(rom));
532               if (!hashes.flag(hash_collection::FLAG_NO_DUMP) && parents > 0)
532533               {
533                  merge_name = get_merge_name(rom, parents, pinfoarray);
534                  merge_name = get_merge_name(hashes, parents, pinfoarray);
534535               }
535536
536537               /* scan for a BIOS name */
r10427r10428
565566                  fprintf(out, " size=\"%d\"", rom_file_size(rom));
566567
567568               /* dump checksum information only if there is a known dump */
568               if (!hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP))
569               if (!hashes.flag(hash_collection::FLAG_NO_DUMP))
569570               {
570                  char checksum[HASH_BUF_SIZE];
571                  int hashtype;
572
573571                  /* iterate over hash function types and print out their values */
574                  for (hashtype = 0; hashtype < HASH_NUM_FUNCTIONS; hashtype++)
575                     if (hash_data_extract_printable_checksum(ROM_GETHASHDATA(rom), 1 << hashtype, checksum))
576                        fprintf(out, " %s=\"%s\"", hash_function_name(1 << hashtype), checksum);
572                  astring tempstr;
573                  for (hash_base *hash = hashes.first(); hash != NULL; hash = hash->next())
574                     fprintf(out, " %s=\"%s\"", hash->name(), hash->string(tempstr));
577575               }
578576
579577               /* append a region name */
580578               fprintf(out, " region=\"%s\"", ROMREGION_GETTAG(region));
581579
582580               /* add nodump/baddump flags */
583               if (hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP))
581               if (hashes.flag(hash_collection::FLAG_NO_DUMP))
584582                  fprintf(out, " status=\"nodump\"");
585               if (hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_BAD_DUMP))
583               if (hashes.flag(hash_collection::FLAG_BAD_DUMP))
586584                  fprintf(out, " status=\"baddump\"");
587585
588586               /* for non-disk entries, print offset */
src/emu/audit.c
r10427r10428
2222    FUNCTION PROTOTYPES
2323***************************************************************************/
2424
25static void audit_one_rom(core_options *options, const rom_entry *rom, const char *regiontag, const game_driver *gamedrv, UINT32 validation, audit_record *record);
26static void audit_one_disk(core_options *options, const rom_entry *rom, const game_driver *gamedrv, UINT32 validation, audit_record *record);
27static int rom_used_by_parent(const game_driver *gamedrv, const rom_entry *romentry, const game_driver **parent);
25static void audit_one_rom(core_options *options, const rom_entry *rom, const char *regiontag, const game_driver *gamedrv, const char *validation, audit_record *record);
26static void audit_one_disk(core_options *options, const rom_entry *rom, const game_driver *gamedrv, const char *validation, audit_record *record);
27static int rom_used_by_parent(const game_driver *gamedrv, const hash_collection &romhashes, const game_driver **parent);
2828
2929
3030
r10427r10428
5454    images for a game
5555-------------------------------------------------*/
5656
57int audit_images(core_options *options, const game_driver *gamedrv, UINT32 validation, audit_record **audit)
57int audit_images(core_options *options, const game_driver *gamedrv, const char *validation, audit_record **audit)
5858{
5959   machine_config config(*gamedrv);
6060   const rom_entry *region, *rom;
r10427r10428
7474         for (rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom))
7575            if (ROMREGION_ISROMDATA(region) || ROMREGION_ISDISKDATA(region))
7676            {
77               if (source_is_gamedrv && !ROM_ISOPTIONAL(rom) && !ROM_NOGOODDUMP(rom))
77               if (source_is_gamedrv && !ROM_ISOPTIONAL(rom))
7878               {
79                  anyrequired = TRUE;
79                  hash_collection hashes(ROM_GETHASHDATA(rom));
80                  if (!hashes.flag(hash_collection::FLAG_NO_DUMP))
81                  {
82                     anyrequired = TRUE;
8083
81                  if (allshared && !rom_used_by_parent(gamedrv, rom, NULL))
82                     allshared = FALSE;
84                     if (allshared && !rom_used_by_parent(gamedrv, hashes, NULL))
85                        allshared = FALSE;
86                  }
8387               }
8488               records++;
8589            }
r10427r10428
119123                  continue;
120124               }
121125
122               if (source_is_gamedrv && record->status != AUDIT_STATUS_NOT_FOUND && (allshared || !rom_used_by_parent(gamedrv, rom, NULL)))
126               if (source_is_gamedrv && record->status != AUDIT_STATUS_NOT_FOUND && (allshared || !rom_used_by_parent(gamedrv, record->exphashes, NULL)))
123127                  anyfound = TRUE;
124128
125129               record++;
r10427r10428
265269         case SUBSTATUS_FOUND_BAD_CHECKSUM:
266270            if (output)
267271            {
268               char hashbuf[512];
269
272               astring tempstr;
270273               mame_printf_info("INCORRECT CHECKSUM:\n");
271               hash_data_print(record->exphash, 0, hashbuf);
272               mame_printf_info("EXPECTED: %s\n", hashbuf);
273               hash_data_print(record->hash, 0, hashbuf);
274               mame_printf_info("   FOUND: %s\n", hashbuf);
274               mame_printf_info("EXPECTED: %s\n", record->exphashes.macro_string(tempstr));
275               mame_printf_info("   FOUND: %s\n", record->hashes.macro_string(tempstr));
275276            }
276277            break;
277278
r10427r10428
319320    audit_one_rom - validate a single ROM entry
320321-------------------------------------------------*/
321322
322static void audit_one_rom(core_options *options, const rom_entry *rom, const char *regiontag, const game_driver *gamedrv, UINT32 validation, audit_record *record)
323static void audit_one_rom(core_options *options, const rom_entry *rom, const char *regiontag, const game_driver *gamedrv, const char *validation, audit_record *record)
323324{
324325   const game_driver *drv;
325326   UINT32 crc = 0;
326   UINT8 crcs[4];
327   int has_crc;
328327
329328   /* fill in the record basics */
330329   record->type = AUDIT_FILE_ROM;
331330   record->name = ROM_GETNAME(rom);
332   record->exphash = ROM_GETHASHDATA(rom);
331   record->exphashes.from_internal_string(ROM_GETHASHDATA(rom));
333332   record->length = 0;
334333   record->explength = rom_file_size(rom);
335334
336335   /* see if we have a CRC and extract it if so */
337   has_crc = hash_data_extract_binary_checksum(record->exphash, HASH_CRC, crcs);
338   if (has_crc)
339      crc = (crcs[0] << 24) | (crcs[1] << 16) | (crcs[2] << 8) | crcs[3];
336   bool has_crc = record->exphashes.crc(crc);
340337
341338   /* find the file and checksum it, getting the file length along the way */
342339   for (drv = gamedrv; drv != NULL; drv = driver_get_clone(drv))
r10427r10428
351348         filerr = file.open(drv->name, PATH_SEPARATOR, ROM_GETNAME(rom));
352349      if (filerr == FILERR_NONE)
353350      {
354         hash_data_copy(record->hash, file.hash_string(validation));
351         record->hashes = file.hashes(validation);
355352         record->length = (UINT32)file.size();
356353         break;
357354      }
r10427r10428
370367          filerr = file.open(regiontag, PATH_SEPARATOR, ROM_GETNAME(rom));
371368      if (filerr == FILERR_NONE)
372369      {
373         hash_data_copy(record->hash, file.hash_string(validation));
370         record->hashes = file.hashes(validation);
374371         record->length = (UINT32)file.size();
375372      }
376373   }
r10427r10428
381378      const game_driver *parent;
382379
383380      /* no good dump */
384      if (hash_data_has_info(record->exphash, HASH_INFO_NO_DUMP))
381      if (record->exphashes.flag(hash_collection::FLAG_NO_DUMP))
385382         set_status(record, AUDIT_STATUS_NOT_FOUND, SUBSTATUS_NOT_FOUND_NODUMP);
386383
387384      /* optional ROM */
r10427r10428
389386         set_status(record, AUDIT_STATUS_NOT_FOUND, SUBSTATUS_NOT_FOUND_OPTIONAL);
390387
391388      /* not found and used by parent */
392      else if (rom_used_by_parent(gamedrv, rom, &parent))
389      else if (rom_used_by_parent(gamedrv, record->exphashes, &parent))
393390         set_status(record, AUDIT_STATUS_NOT_FOUND, (parent->flags & GAME_IS_BIOS_ROOT) ? SUBSTATUS_NOT_FOUND_BIOS : SUBSTATUS_NOT_FOUND_PARENT);
394391
395392      /* just plain old not found */
r10427r10428
405402         set_status(record, AUDIT_STATUS_FOUND_INVALID, SUBSTATUS_FOUND_WRONG_LENGTH);
406403
407404      /* found but needs a dump */
408      else if (hash_data_has_info(record->exphash, HASH_INFO_NO_DUMP))
405      else if (record->exphashes.flag(hash_collection::FLAG_NO_DUMP))
409406         set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_FOUND_NODUMP);
410407
411408      /* incorrect hash */
412      else if (!hash_data_is_equal(record->exphash, record->hash, 0))
409      else if (record->exphashes != record->hashes)
413410         set_status(record, AUDIT_STATUS_FOUND_INVALID, SUBSTATUS_FOUND_BAD_CHECKSUM);
414411
415412      /* correct hash but needs a redump */
416      else if (hash_data_has_info(record->exphash, HASH_INFO_BAD_DUMP))
413      else if (record->exphashes.flag(hash_collection::FLAG_BAD_DUMP))
417414         set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_GOOD_NEEDS_REDUMP);
418415
419416      /* just plain old good */
r10427r10428
427424    audit_one_disk - validate a single disk entry
428425-------------------------------------------------*/
429426
430static void audit_one_disk(core_options *options, const rom_entry *rom, const game_driver *gamedrv, UINT32 validation, audit_record *record)
427static void audit_one_disk(core_options *options, const rom_entry *rom, const game_driver *gamedrv, const char *validation, audit_record *record)
431428{
432429   emu_file *source_file;
433430   chd_file *source;
r10427r10428
436433   /* fill in the record basics */
437434   record->type = AUDIT_FILE_DISK;
438435   record->name = ROM_GETNAME(rom);
439   record->exphash = ROM_GETHASHDATA(rom);
436   record->exphashes.from_internal_string(ROM_GETHASHDATA(rom));
440437
441438   /* open the disk */
442439   err = open_disk_image(*options, gamedrv, rom, &source_file, &source, NULL);
r10427r10428
449446         set_status(record, AUDIT_STATUS_ERROR, SUBSTATUS_ERROR);
450447
451448      /* not found but it's not good anyway */
452      else if (hash_data_has_info(record->exphash, HASH_INFO_NO_DUMP))
449      else if (record->exphashes.flag(hash_collection::FLAG_NO_DUMP))
453450         set_status(record, AUDIT_STATUS_NOT_FOUND, SUBSTATUS_NOT_FOUND_NODUMP);
454451
455452      /* not found but optional */
r10427r10428
464461   /* if we succeeded, validate it */
465462   else
466463   {
467      static const UINT8 nullhash[HASH_BUF_SIZE] = { 0 };
464      static const UINT8 nullhash[20] = { 0 };
468465      chd_header header = *chd_get_header(source);
469466
470467      /* if there's an MD5 or SHA1 hash, add them to the output hash */
471468      if (memcmp(nullhash, header.md5, sizeof(header.md5)) != 0)
472         hash_data_insert_binary_checksum(record->hash, HASH_MD5, header.md5);
469         record->hashes.add_from_buffer(hash_collection::HASH_MD5, header.md5, sizeof(header.md5));
473470      if (memcmp(nullhash, header.sha1, sizeof(header.sha1)) != 0)
474         hash_data_insert_binary_checksum(record->hash, HASH_SHA1, header.sha1);
471         record->hashes.add_from_buffer(hash_collection::HASH_SHA1, header.sha1, sizeof(header.sha1));
475472
476473      /* found but needs a dump */
477      if (hash_data_has_info(record->exphash, HASH_INFO_NO_DUMP))
474      if (record->exphashes.flag(hash_collection::FLAG_NO_DUMP))
478475         set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_FOUND_NODUMP);
479476
480477      /* incorrect hash */
481      else if (!hash_data_is_equal(record->exphash, record->hash, 0))
478      else if (record->exphashes != record->hashes)
482479         set_status(record, AUDIT_STATUS_FOUND_INVALID, SUBSTATUS_FOUND_BAD_CHECKSUM);
483480
484481      /* correct hash but needs a redump */
485      else if (hash_data_has_info(record->exphash, HASH_INFO_BAD_DUMP))
482      else if (record->exphashes.flag(hash_collection::FLAG_BAD_DUMP))
486483         set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_GOOD_NEEDS_REDUMP);
487484
488485      /* just plain good */
r10427r10428
500497    ROM is also used by the parent
501498-------------------------------------------------*/
502499
503static int rom_used_by_parent(const game_driver *gamedrv, const rom_entry *romentry, const game_driver **parent)
500static int rom_used_by_parent(const game_driver *gamedrv, const hash_collection &romhashes, const game_driver **parent)
504501{
505   const char *hash = ROM_GETHASHDATA(romentry);
506502   const game_driver *drv;
507503
508504   /* iterate up the parent chain */
r10427r10428
516512      for (const rom_source *source = rom_first_source(config); source != NULL; source = rom_next_source(*source))
517513         for (region = rom_first_region(*source); region; region = rom_next_region(region))
518514            for (rom = rom_first_file(region); rom; rom = rom_next_file(rom))
519               if (hash_data_is_equal(ROM_GETHASHDATA(rom), hash, 0))
515               if (hash_collection(ROM_GETHASHDATA(rom)) == romhashes)
520516               {
521517                  if (parent != NULL)
522518                     *parent = drv;
src/emu/audit.h
r10427r10428
2323***************************************************************************/
2424
2525/* hashes to use for validation */
26#define AUDIT_VALIDATE_FAST            (HASH_CRC)
27#define AUDIT_VALIDATE_FULL            (HASH_CRC | HASH_SHA)
26#define AUDIT_VALIDATE_FAST            "R"      /* CRC only */
27#define AUDIT_VALIDATE_FULL            "RS"   /* CRC + SHA1 */
2828
2929/* return values from audit_verify_roms and audit_verify_samples */
3030enum
r10427r10428
8383   const char *   name;               /* name of item */
8484   UINT32         explength;            /* expected length of item */
8585   UINT32         length;               /* actual length of item */
86   const char *   exphash;              /* expected hash data */
87   char         hash[HASH_BUF_SIZE];   /* actual hash information */
86   hash_collection   exphashes;              /* expected hash data */
87   hash_collection   hashes;               /* actual hash information */
8888};
8989
9090
r10427r10428
9393    FUNCTION PROTOTYPES
9494***************************************************************************/
9595
96int audit_images(core_options *options, const game_driver *gamedrv, UINT32 validation, audit_record **audit);
96int audit_images(core_options *options, const game_driver *gamedrv, const char *validation, audit_record **audit);
9797int audit_samples(core_options *options, const game_driver *gamedrv, audit_record **audit);
9898int audit_summary(const game_driver *gamedrv, int count, const audit_record *records, int output);
9999
src/emu/fileio.c
r10427r10428
206206//  hash - returns the hash for a file
207207//-------------------------------------------------
208208
209const char *emu_file::hash_string(UINT32 functions)
209hash_collection &emu_file::hashes(const char *types)
210210{
211   // if we already have the functions we need, just return
212   UINT32 wehave = hash_data_used_functions(m_hash);
213   if ((wehave & functions) == functions)
214      return m_hash;
215
216   // load the ZIP file now if we haven't yet
211   // determine which hashes we need
212   astring needed;
213   for (const char *scan = types; *scan != 0; scan++)
214      if (m_hashes.hash(*scan) == NULL)
215         needed.cat(*scan);
216   
217   // if we need nothing, skip it
218   if (!needed)
219      return m_hashes;
220   
221   // load the ZIP file if needed
217222   if (m_zipfile != NULL && load_zipped_file() != FILERR_NONE)
218      return m_hash;
223      return m_hashes;
219224   if (m_file == NULL)
220      return m_hash;
225      return m_hashes;
221226
227   // if we have ZIP data, just hash that directly
228   if (m_zipdata != NULL)
229   {
230      m_hashes.compute(m_zipdata, m_ziplength, needed);
231      return m_hashes;
232   }
233
222234   // read the data if we can
223235   const UINT8 *filedata = (const UINT8 *)core_fbuffer(m_file);
224236   if (filedata == NULL)
225      return m_hash;
237      return m_hashes;
226238
227239   // compute the hash
228   hash_compute(m_hash, filedata, core_fsize(m_file), wehave | functions);
229   return m_hash;
240   m_hashes.compute(filedata, core_fsize(m_file), needed);
241   return m_hashes;
230242}
231243
232244
r10427r10428
377389   if (m_remove_on_close)
378390      osd_rmfile(m_fullpath);
379391   m_remove_on_close = false;
392   
393   // reset our hashes and path as well
394   m_hashes.reset();
395   m_fullpath.reset();
380396}
381397
382398
r10427r10428
652668         m_ziplength = header->uncompressed_length;
653669
654670         // build a hash with just the CRC
655         hash_data_clear(m_hash);
656         UINT8 crcs[4];
657         crcs[0] = header->crc >> 24;
658         crcs[1] = header->crc >> 16;
659         crcs[2] = header->crc >> 8;
660         crcs[3] = header->crc >> 0;
661         hash_data_insert_binary_checksum(m_hash, HASH_CRC, crcs);
662
671         m_hashes.reset();
672         m_hashes.add_crc(header->crc);
663673         return (m_openflags & OPEN_FLAG_NO_PRELOAD) ? FILERR_NONE : load_zipped_file();
664674      }
665675
src/emu/fileio.h
r10427r10428
151151   const char *filename() const { return m_filename; }
152152   const char *fullpath() const { return m_fullpath; }
153153   UINT32 openflags() const { return m_openflags; }
154   const char *hash_string(UINT32 functions);
154   hash_collection &hashes(const char *types);
155155
156156   // setters
157157   void remove_on_close() { m_remove_on_close = true; }
r10427r10428
203203   path_iterator   m_iterator;                  // iterator for paths
204204   UINT32         m_crc;                     // iterator for paths
205205   UINT32         m_openflags;               // flags we used for the open
206   char         m_hash[HASH_BUF_SIZE];         // hash data for the file
206   hash_collection m_hashes;                  // collection of hashes
207207   zip_file *      m_zipfile;                  // ZIP file pointer
208208   UINT8 *         m_zipdata;                  // ZIP file data
209209   UINT64         m_ziplength;               // ZIP file length
src/mess/machine/a7800.c
r10427r10428
161161               Changed 53 bit 2, added bit 3
162162
163163*/
164
165void a7800_partialhash(char *dest, const unsigned char *data,
166   unsigned long length, unsigned int functions)
164void a7800_partialhash(hash_collection &dest, const unsigned char *data,
165   unsigned long length, const char *functions)
167166{
168167   if (length <= 128)
169168      return;
170   hash_compute(dest, &data[128], length - 128, functions);
169   dest.compute(&data[128], length - 128, functions);   
171170}
172171
173172
src/mess/machine/nes.c
r10427r10428
15151515
15161516
15171517
1518void nes_partialhash( char *dest, const unsigned char *data, unsigned long length, unsigned int functions )
1518void nes_partialhash(hash_collection &dest, const unsigned char *data,
1519   unsigned long length, const char *functions)
15191520{
15201521   if (length <= 16)
15211522      return;
1522   hash_compute(dest, &data[16], length - 16, functions);
1523   dest.compute(&data[16], length - 16, functions);   
15231524}
15241525
15251526/**************************
src/mess/machine/lynx.c
r10427r10428
18281828****************************************/
18291829
18301830
1831static void lynx_partialhash(char *dest, const unsigned char *data,
1832   unsigned long length, unsigned int functions)
1831static void lynx_partialhash(hash_collection &dest, const unsigned char *data,
1832   unsigned long length, const char *functions)
18331833{
18341834   if (length <= 64)
18351835      return;
1836   hash_compute(dest, &data[64], length - 64, functions);
1836   dest.compute(&data[64], length - 64, functions);
18371837}
18381838
18391839int lynx_verify_cart (char *header, int kind)
src/mess/includes/nes.h
r10427r10428
265265
266266int nes_ppu_vidaccess( device_t *device, int address, int data );
267267
268void nes_partialhash(char *dest, const unsigned char *data, unsigned long length, unsigned int functions);
268void nes_partialhash(hash_collection &dest, const unsigned char *data, unsigned long length, const char *functions);
269269
270270/*----------- defined in video/nes.c -----------*/
271271
src/mess/includes/a7800.h
r10427r10428
6565
6666MACHINE_RESET( a7800 );
6767
68void a7800_partialhash(char *dest, const unsigned char *data,
69   unsigned long length, unsigned int functions);
68void a7800_partialhash(hash_collection &dest, const unsigned char *data, unsigned long length, const char *functions);
7069
7170DEVICE_START( a7800_cart );
7271DEVICE_IMAGE_LOAD( a7800_cart );
src/mess/drivers/a7800.c
r10427r10428
286286   MCFG_CARTSLOT_NOT_MANDATORY
287287   MCFG_CARTSLOT_START(a7800_cart)
288288   MCFG_CARTSLOT_LOAD(a7800_cart)
289   MCFG_CARTSLOT_PARTIALHASH(a7800_partialhash)
289   MCFG_CARTSLOT_PARTIALHASH(a7800_partialhash)   
290290   MCFG_CARTSLOT_INTERFACE("a7800_cart")
291291
292292   /* software lists */
src/mess/drivers/nes.c
r10427r10428
555555   MCFG_CARTSLOT_EXTENSION_LIST("nes,unf")
556556   MCFG_CARTSLOT_NOT_MANDATORY
557557   MCFG_CARTSLOT_LOAD(nes_cart)
558   MCFG_CARTSLOT_PARTIALHASH(nes_partialhash)
558   MCFG_CARTSLOT_PARTIALHASH(nes_partialhash)   
559559
560560   MCFG_FLOPPY_DRIVE_ADD(FLOPPY_0, nes_floppy_config)
561561MACHINE_CONFIG_END
src/mess/drivers/pce.c
r10427r10428
287287INPUT_PORTS_END
288288
289289
290static void pce_partialhash(char *dest, const unsigned char *data,
291        unsigned long length, unsigned int functions)
290static void pce_partialhash(hash_collection &dest, const unsigned char *data,
291   unsigned long length, const char *functions)
292292{
293293   if ( ( length <= PCE_HEADER_SIZE ) || ( length & PCE_HEADER_SIZE ) ) {
294           hash_compute(dest, &data[PCE_HEADER_SIZE], length - PCE_HEADER_SIZE, functions);
295   } else {
296      hash_compute(dest, data, length, functions);
294         dest.compute(&data[PCE_HEADER_SIZE], length - PCE_HEADER_SIZE, functions);   
295   } else {     
296      dest.compute(data, length, functions);   
297297   }
298298}
299299

Previous 15994 Revisions Next


© 1998-2018 The MESS Team