Previous 15994 Revisions Next

r11293 Sunday 24th April, 2011 at 23:41:21 UTC by Angelo Salese
Celebrate marriage between ST-V and Saturn, nw
[src/mame/drivers]saturn.c* stv.c
[src/mess]mess.mak
[src/mess/drivers]saturn.c

src/mame/drivers/stv.c
r11292r11293
1/* Sega ST-V (Sega Titan Video)
2
3a.k.a. known as a Sega Saturn for the Arcades.
4
5Driver by David Haywood,Angelo Salese,Olivier Galibert & Mariusz Wojcieszek
6SCSP driver provided by R.Belmont,based on ElSemi's SCSP sound chip emulator
7CD Block driver provided by ANY,based on sthief original emulator
8Many thanks to Guru,Fabien & Runik for the help given.
9
10Hardware overview:
11------------------
12-two SH-2 CPUs,in a master/slave configuration.The master cpu is used to
13boot-up and to do the most of the work,the slave one does extra work that could be
14too much for a single cpu.They both shares all the existant devices;
15-a M68000 CPU,used to drive sound(the SCSP chip).The program is uploaded via the
16SH-2 cpus;
17-a SMPC (System Manager & Peripheral Control),used to drive all the
18devices on the board;
19-a SCU (System Control Unit),mainly used to do DMA operations and to drive interrupts,it
20also has a DSP;
21-an (optional for the ST-V) SH-1 CPU,used to be the CD driver;
22-An A-Bus,where the cart ROM area is located;
23-A B-Bus,where the Video Hardware & the SCU sections are located;
24-Two VDPs chips(named as 1 & 2),used for the video section:
25 -VDP1 is used to render sprites & polygons.
26 -VDP2 is for the tilemap system,there are:
27 4 effective normal layers;
28 2 roz layers;
29 1 back layer;
30 1 line layer;
31 The VDP2 is capable of the following things (in order):
32 -dynamic resolution (up to 704x512) & various interlacing modes;
33 -mosaic process;
34 -scrolling,scaling,horizontal & vertical cell scrolling & linescroll for the
35  normal planes, the roz ones can also rotate;
36 -versatile window system,used for various effects;
37 -alpha-blending,refered as Color Calculation in the docs;
38 -shadow effects;
39 -global rgb brightness control,separate for every plane;
40
41Memory map:
42-----------
43
440x00000000, 0x0007ffff  BIOS ROM
450x00080000, 0x000fffff  Unused
460x00100000, 0x0010007f  SMPC
470x00100080, 0x0017ffff  Unused
480x00180000, 0x0018ffff  Back Up Ram
490x00190000, 0x001fffff  Unused
500x00200000, 0x002fffff  Work Ram-L
510x00300000, 0x00ffffff  Unused
520x01000000, 0x01000003  MINIT
530x01000004, 0x017fffff  Unused
540x01800000, 0x01800003  SINIT
550x01800004, 0x01ffffff  Unused
560x02000000, 0x03ffffff  A-BUS CS0
570x04000000, 0x04ffffff  A-BUS CS1
580x05000000, 0x057fffff  A-BUS DUMMY
590x05800000, 0x058fffff  A-BUS CS2
600x05900000, 0x059fffff  Unused
610x05a00000, 0x05b00ee3  Sound Region
620x05b00ee4, 0x05bfffff  Unused
630x05c00000, 0x05cbffff  VDP 1
640x05cc0000, 0x05cfffff  Unused
650x05d00000, 0x05d00017  VDP 1 regs
660x05d00018, 0x05dfffff  Unused
670x05e00000, 0x05e7ffff  VDP2
680x05e80000, 0x05efffff  VDP2 Extra RAM,accessible thru the VRAMSZ register
690x05f00000, 0x05f00fff  VDP2 Color RAM
700x05f01000, 0x05f7ffff  Unused
710x05f80000  0x05f8011f  VDP2 regs
720x05f80120, 0x05fdffff  Unused
730x05fe0000, 0x05fe00cf  SCU regs
740x05fe00d0, 0x05ffffff  Unused
750x06000000, 0x060fffff  Work Ram-H
760x06100000, 0x07ffffff  Unused
77
78*the unused locations aren't known if they are really unused or not,needs verification,most
79of them seem just mirrors of the previous valid memory allocated.
80
81ToDo / Notes:
82-------------
83
84-To enter into an Advanced Test Mode,keep pressed the Test Button (F2) on the start-up.
85
86(Main issues)
87-IRQs: some games have some issues with timing accurate IRQs,check/fix all of them.
88-Clean-ups and split the various chips(SCU,SMPC)into their respective files.
89-CD block:complete it.
90-The Cart-Dev mode hangs even with the -dev bios,I would like to see what it does on the real HW.
91-IC13 games on the bios dev doesn't even load the cartridge / crashes the emulation at start-up,
92 rom rearrange needed?
93-finish the DSP core.
94-Add the RS232c interface (serial port),needed by fhboxers.
95-(PCB owners) check if the clocks documented in the manuals are really right for ST-V.
96-SCSP to master irq: see if there is a sound cpu mask bit.
97-Does the device_set_clock really works?Investigate.
98-We need to check every game if can be completed or there are any hanging/crash/protection
99 issues on them.
100-Memo: Some tests done on the original & working PCB,to be implemented:
101 -The AD-Stick returns 0x00 or a similar value.
102 -The Ports E,F & G must return 0xff
103 -The regular BIOS tests (Memory Test) changes his background color at some point to
104  several gradients of red,green and blue.Current implementation remains black.I dunno
105  if this is a framebuffer write or a funky transparency issue (i.e TRANSPARENT_NONE
106  should instead show the back layer).
107 -RBG0 rotating can be checked on the "Advanced Test" menu thru the VDP1/VDP2 check.
108  It rotates clockwise IIRC.Also the ST-V logo when the game is in Multi mode rotates too.
109 -The MIDI communication check fails even on a ST-V board,somebody needs to check if there
110  is a MIDI port on the real PCB...
111-All games except shienryu: add default eeprom if necessary (1P/3P games for example).
112-Video emulation bugs: check stvvdp2.c file.
113
114(per-game issues)
115-stress: accesses the Sound Memory Expansion Area (0x05a00000-0x05afffff), unknown purpose;
116-smleague / finlarch: it randomly hangs / crashes,it works if you use a ridiculous MCFG_INTERLEAVE number,might need strict
117 SH-2 synching.
118-various: find idle skip if possible.
119-suikoenb/shanhigw + others: why do we get 2 credits on startup? Cause might be by a communication with the M68k
120-colmns97/puyosun/mausuke/cotton2/cottonbm: interrupt issues? we can't check the SCU mask
121 on SMPC or controls fail
122-mausuke/bakubaku/grdforce: need to sort out transparency on the colour mapped sprites
123-bakubaku: sound part is largely incomplete,caused by a tight loop at location PC=1048 of the sound cpu part.
124-myfairld: Apparently this game gives a black screen (either test mode and in-game mode),but let it wait for about
125 10 seconds and the game will load everything.This is because of a hellishly slow m68k sub-routine located at 54c2.
126 Likely to not be a bug but an in-game design issue.
127-myfairld: Micronet programmers had the "great" idea to *not* use the ST-V input standards,infact
128 joystick panel is mapped with input_port(10) instead of input_port(2),so for now use
129 the mahjong panel instead.
130-danchih: hanafuda panel doesn't work.
131-decathlt: Is currently using a strange protection DMA abus control,and it uses some sort of RLE
132 compression/encryption that serves as a gfxdecode.
133-findlove: controls doesn't work? Playing with the debugger at location $6063720 it makes it get furter,but controls
134 still doesn't work,missing irq?
135-batmanfr: Missing sound,caused by an extra ADSP chip which is on the cart.The CPU is a
136 ADSP-2181,and it's the same used by NBA Jam Extreme (ZN game).
137-vfremix: when you play Akira, there is a problem with third match: game doesn't upload all textures
138 and tiles and doesn't enable display, although gameplay is normal - wait a while to get back
139 to title screen after losing a match
140-sokyugrt: gameplay seems to be not smooth, timing?
141-seabass: crashes in stvcd.c - there is no CD and we report than we have one, and game tries
142 to read something, however it doesn't do it after nvram is deleted?
143-Protection issues:
144 \-ffreveng: boot vectors;
145 \-decathlt: in-game graphics;
146 \-elandore: human / dragons textures;
147 \-twcup98: tecmo logo / sprite movements;
148 \-astrass: text layer (kludged for now);
149
150
151*/
152
153#include "emu.h"
154#include "cpu/m68000/m68000.h"
155#include "machine/eeprom.h"
156#include "cpu/sh2/sh2.h"
157#include "machine/stvcd.h"
158#include "machine/scudsp.h"
159#include "sound/scsp.h"
160#include "machine/stvprot.h"
161#include "includes/stv.h"
162
163#define USE_SLAVE 1
164
165#ifdef MAME_DEBUG
166#define LOG_CDB  0
167#define LOG_SMPC 1
168#define LOG_SCU  1
169#define LOG_IRQ  0
170#define LOG_IOGA 1
171#else
172#define LOG_CDB  0
173#define LOG_SMPC 0
174#define LOG_SCU  0
175#define LOG_IRQ  0
176#define LOG_IOGA 0
177#endif
178
179#define MASTER_CLOCK_352 57272800
180#define MASTER_CLOCK_320 53748200
181#define PIXEL_CLOCK 50160000/2/4 /*hand-tuned to match fps ~59.82*/
182
183/**************************************************************************************/
184/*to be added into a stv Header file,remember to remove all the static...*/
185
186static UINT8 *smpc_ram;
187//static void stv_dump_ram(void);
188
189UINT32* stv_workram_l;
190UINT32* stv_workram_h;
191cpu_device *stv_maincpu;
192cpu_device *stv_slave;
193cpu_device *stv_audiocpu;
194static UINT32* stv_backupram;
195static UINT32* ioga;
196static UINT16* scsp_regs;
197static UINT16* sound_ram;
198
199int stv_enable_slave_sh2;
200/*VDP2 stuff*/
201/*SMPC stuff*/
202static UINT8 NMI_reset;
203static void system_reset(void);
204static UINT8 en_68k;
205/*SCU stuff*/
206static int     timer_0;         /* Counter for Timer 0 irq*/
207static int    timer_1;          /* Counter for Timer 1 irq*/
208/*Maybe add these in a struct...*/
209static UINT32 scu_src_0,      /* Source DMA lv 0 address*/
210           scu_src_1,      /* lv 1*/
211           scu_src_2,      /* lv 2*/
212           scu_dst_0,      /* Destination DMA lv 0 address*/
213           scu_dst_1,      /* lv 1*/
214           scu_dst_2,      /* lv 2*/
215           scu_src_add_0,   /* Source Addition for DMA lv 0*/
216           scu_src_add_1,   /* lv 1*/
217           scu_src_add_2,   /* lv 2*/
218           scu_dst_add_0,   /* Destination Addition for DMA lv 0*/
219           scu_dst_add_1,   /* lv 1*/
220           scu_dst_add_2;   /* lv 2*/
221static INT32  scu_size_0,      /* Transfer DMA size lv 0*/
222           scu_size_1,      /* lv 1*/
223           scu_size_2;      /* lv 2*/
224
225static struct
226{
227   UINT8 vblank_out;
228   UINT8 vblank_in;
229   UINT8 hblank_in;
230   UINT8 timer_0;
231   UINT8 timer_1;
232   UINT8 dsp_end;
233   UINT8 sound_req;
234   UINT8 smpc;
235   UINT8 pad;
236   UINT8 dma_end[3];
237   UINT8 dma_ill;
238   UINT8 vdp1_end;
239   UINT8 abus;
240}stv_irq;
241
242static void dma_direct_lv0(address_space *space);   /*DMA level 0 direct transfer function*/
243static void dma_direct_lv1(address_space *space);   /*DMA level 1 direct transfer function*/
244static void dma_direct_lv2(address_space *space);   /*DMA level 2 direct transfer function*/
245static void dma_indirect_lv0(address_space *space); /*DMA level 0 indirect transfer function*/
246static void dma_indirect_lv1(address_space *space); /*DMA level 1 indirect transfer function*/
247static void dma_indirect_lv2(address_space *space); /*DMA level 2 indirect transfer function*/
248
249
250int minit_boost,sinit_boost;
251attotime minit_boost_timeslice, sinit_boost_timeslice;
252
253//static int scanline;
254
255static emu_timer *stv_rtc_timer;
256
257
258/*A-Bus IRQ checks,where they could be located these?*/
259#define ABUSIRQ(_irq_,_vector_) \
260   { cputag_set_input_line_and_vector(device->machine(), "maincpu", _irq_, HOLD_LINE , _vector_); }
261#if 0
262if(stv_scu[42] & 1)//IRQ ACK
263{
264   ABUSIRQ(7,0x50,0x00010000);
265   ABUSIRQ(7,0x51,0x00020000);
266   ABUSIRQ(7,0x52,0x00040000);
267   ABUSIRQ(7,0x53,0x00080000);
268   ABUSIRQ(4,0x54,0x00100000);
269   ABUSIRQ(4,0x55,0x00200000);
270   ABUSIRQ(4,0x56,0x00400000);
271   ABUSIRQ(4,0x57,0x00800000);
272   ABUSIRQ(1,0x58,0x01000000);
273   ABUSIRQ(1,0x59,0x02000000);
274   ABUSIRQ(1,0x5a,0x04000000);
275   ABUSIRQ(1,0x5b,0x08000000);
276   ABUSIRQ(1,0x5c,0x10000000);
277   ABUSIRQ(1,0x5d,0x20000000);
278   ABUSIRQ(1,0x5e,0x40000000);
279   ABUSIRQ(1,0x5f,0x80000000);
280}
281#endif
282
283/**************************************************************************************/
284
285static int DectoBCD(int num)
286{
287   int i, cnt = 0, tmp, res = 0;
288
289   while (num > 0) {
290      tmp = num;
291      while (tmp >= 10) tmp %= 10;
292      for (i=0; i<cnt; i++)
293         tmp *= 16;
294      res += tmp;
295      cnt++;
296      num /= 10;
297   }
298
299   return res;
300}
301
302
303/* SMPC
304 System Manager and Peripheral Control
305
306*/
307/* SMPC Addresses
308
30900
31001 -w  Input Register 0 (IREG)
31102
31203 -w  Input Register 1
31304
31405 -w  Input Register 2
31506
31607 -w  Input Register 3
31708
31809 -w  Input Register 4
3190a
3200b -w  Input Register 5
3210c
3220d -w  Input Register 6
3230e
3240f
32510
32611
32712
32813
32914
33015
33116
33217
33318
33419
3351a
3361b
3371c
3381d
3391e
3401f -w  Command Register (COMREG)
34120
34221 r-  Output Register 0 (OREG)
34322
34423 r-  Output Register 1
34524
34625 r-  Output Register 2
34726
34827 r-  Output Register 3
34928
35029 r-  Output Register 4
3512a
3522b r-  Output Register 5
3532c
3542d r-  Output Register 6
3552e
3562f r-  Output Register 7
35730
35831 r-  Output Register 8
35932
36033 r-  Output Register 9
36134
36235 r-  Output Register 10
36336
36437 r-  Output Register 11
36538
36639 r-  Output Register 12
3673a
3683b r-  Output Register 13
3693c
3703d r-  Output Register 14
3713e
3723f r-  Output Register 15
37340
37441 r-  Output Register 16
37542
37643 r-  Output Register 17
37744
37845 r-  Output Register 18
37946
38047 r-  Output Register 19
38148
38249 r-  Output Register 20
3834a
3844b r-  Output Register 21
3854c
3864d r-  Output Register 22
3874e
3884f r-  Output Register 23
38950
39051 r-  Output Register 24
39152
39253 r-  Output Register 25
39354
39455 r-  Output Register 26
39556
39657 r-  Output Register 27
39758
39859 r-  Output Register 28
3995a
4005b r-  Output Register 29
4015c
4025d r-  Output Register 30
4035e
4045f r-  Output Register 31
40560
40661 r-  SR
40762
40863 rw  SF
40964
41065
41166
41267
41368
41469
4156a
4166b
4176c
4186d
4196e
4206f
42170
42271
42372
42473
42574
42675 rw PDR1
42776
42877 rw PDR2
42978
43079 -w DDR1
4317a
4327b -w DDR2
4337c
4347d -w IOSEL2/1
4357e
4367f -w EXLE2/1
437*/
438static UINT8 IOSEL1;
439static UINT8 IOSEL2;
440static UINT8 EXLE1;
441static UINT8 EXLE2;
442static UINT8 PDR1;
443static UINT8 PDR2;
444
445#define SH2_DIRECT_MODE_PORT_1 IOSEL1 = 1
446#define SH2_DIRECT_MODE_PORT_2 IOSEL2 = 1
447#define SMPC_CONTROL_MODE_PORT_1 IOSEL1 = 0
448#define SMPC_CONTROL_MODE_PORT_2 IOSEL2 = 0
449
450static void system_reset()
451{
452   /*Only backup ram and SMPC ram are retained after that this command is issued.*/
453   memset(stv_scu      ,0x00,0x000100);
454   memset(scsp_regs    ,0x00,0x001000);
455   memset(sound_ram    ,0x00,0x080000);
456   memset(stv_workram_h,0x00,0x100000);
457   memset(stv_workram_l,0x00,0x100000);
458   memset(stv_vdp2_regs,0x00,0x040000);
459   memset(stv_vdp2_vram,0x00,0x100000);
460   memset(stv_vdp2_cram,0x00,0x080000);
461   //vdp1
462   //A-Bus
463   /*Order is surely wrong but whatever...*/
464}
465
466static UINT8 stv_SMPC_r8 (address_space *space, int offset)
467{
468   int return_data;
469
470
471   return_data = smpc_ram[offset];
472
473   if (offset == 0x61) // ?? many games need this or the controls don't work
474      return_data = 0x20 ^ 0xff;
475
476   if (offset == 0x75)//PDR1 read
477      return_data = input_port_read(space->machine(), "DSW1");
478
479   if (offset == 0x77)//PDR2 read
480      return_data=  (0xfe | eeprom_read_bit(space->machine().device("eeprom")));
481
482//  if (offset == 0x33) //country code
483//      return_data = input_port_read(machine, "FAKE");
484
485   if (cpu_get_pc(&space->device())==0x060020E6) return_data = 0x10;//???
486
487   //if(LOG_SMPC) logerror ("cpu %s (PC=%08X) SMPC: Read from Byte Offset %02x Returns %02x\n", space->device().tag(), cpu_get_pc(&space->device()), offset, return_data);
488
489
490   return return_data;
491}
492
493static void stv_SMPC_w8 (address_space *space, int offset, UINT8 data)
494{
495   system_time systime;
496
497   space->machine().base_datetime(systime);
498
499//  if(LOG_SMPC) logerror ("8-bit SMPC Write to Offset %02x with Data %02x\n", offset, data);
500   smpc_ram[offset] = data;
501
502   if(offset == 0x75)
503   {
504      eeprom_device *device = space->machine().device<eeprom_device>("eeprom");
505      eeprom_set_clock_line(device, (data & 0x08) ? ASSERT_LINE : CLEAR_LINE);
506      eeprom_write_bit(device, data & 0x10);
507      eeprom_set_cs_line(device, (data & 0x04) ? CLEAR_LINE : ASSERT_LINE);
508
509
510//      if (data & 0x01)
511//          if(LOG_SMPC) logerror("bit 0 active\n");
512//      if (data & 0x02)
513//          if(LOG_SMPC) logerror("bit 1 active\n");
514//      if (data & 0x10)
515         //if(LOG_SMPC) logerror("bit 4 active\n");//LOT
516      //if(LOG_SMPC) logerror("SMPC: ram [0x75] = %02x\n",smpc_ram[0x75]);
517      PDR1 = (data & 0x60);
518   }
519
520   if(offset == 0x77)
521   {
522      /*
523            ACTIVE LOW
524            bit 4(0x10) - Enable Sound System
525        */
526      //popmessage("PDR2 = %02x",smpc_ram[0x77]);
527      if(!(smpc_ram[0x77] & 0x10))
528      {
529         if(LOG_SMPC) logerror("SMPC: M68k on\n");
530         cputag_set_input_line(space->machine(), "audiocpu", INPUT_LINE_RESET, CLEAR_LINE);
531         en_68k = 1;
532      }
533      else
534      {
535         if(LOG_SMPC) logerror("SMPC: M68k off\n");
536         cputag_set_input_line(space->machine(), "audiocpu", INPUT_LINE_RESET, ASSERT_LINE);
537         en_68k = 0;
538      }
539      //if(LOG_SMPC) logerror("SMPC: ram [0x77] = %02x\n",smpc_ram[0x77]);
540      PDR2 = (data & 0x60);
541   }
542
543   if(offset == 0x7d)
544   {
545      if(smpc_ram[0x7d] & 1)
546         SH2_DIRECT_MODE_PORT_1;
547      else
548         SMPC_CONTROL_MODE_PORT_1;
549
550      if(smpc_ram[0x7d] & 2)
551         SH2_DIRECT_MODE_PORT_2;
552      else
553         SMPC_CONTROL_MODE_PORT_2;
554   }
555
556   /*TODO: probably this is wrong...*/
557   if(offset == 0x7f)
558   {
559      //enable PAD irq & VDP2 external latch for port 1/2
560      EXLE1 = smpc_ram[0x7f] & 1 ? 1 : 0;
561      EXLE2 = smpc_ram[0x7f] & 2 ? 1 : 0;
562      if(EXLE1 || EXLE2)
563      {
564         //if(LOG_SMPC) logerror ("Interrupt: PAD irq at scanline %04x, Vector 0x48 Level 0x08\n",scanline);
565         cputag_set_input_line_and_vector(space->machine(), "maincpu", 8, (stv_irq.pad) ? HOLD_LINE : CLEAR_LINE, 0x48);
566      }
567   }
568
569   if (offset == 0x1f)
570   {
571      switch (data)
572      {
573         case 0x00:
574            if(LOG_SMPC) logerror ("SMPC: Master ON\n");
575            smpc_ram[0x5f]=0x00;
576            break;
577         //in theory 0x01 is for Master OFF,but obviously is not used.
578         case 0x02:
579            if(LOG_SMPC) logerror ("SMPC: Slave ON\n");
580            smpc_ram[0x5f]=0x02;
581            #if USE_SLAVE
582            stv_enable_slave_sh2 = 1;
583            cputag_set_input_line(space->machine(), "slave", INPUT_LINE_RESET, CLEAR_LINE);
584            #endif
585            break;
586         case 0x03:
587            if(LOG_SMPC) logerror ("SMPC: Slave OFF\n");
588            smpc_ram[0x5f]=0x03;
589            stv_enable_slave_sh2 = 0;
590            space->machine().scheduler().trigger(1000);
591            cputag_set_input_line(space->machine(), "slave", INPUT_LINE_RESET, ASSERT_LINE);
592            break;
593         case 0x06:
594            if(LOG_SMPC) logerror ("SMPC: Sound ON\n");
595            /* wrong? */
596            smpc_ram[0x5f]=0x06;
597            cputag_set_input_line(space->machine(), "audiocpu", INPUT_LINE_RESET, CLEAR_LINE);
598            break;
599         case 0x07:
600            if(LOG_SMPC) logerror ("SMPC: Sound OFF\n");
601            smpc_ram[0x5f]=0x07;
602            break;
603         /*CD (SH-1) ON/OFF,guess that this is needed for Sports Fishing games...*/
604         //case 0x08:
605         //case 0x09:
606         case 0x0d:
607            if(LOG_SMPC) logerror ("SMPC: System Reset\n");
608            smpc_ram[0x5f]=0x0d;
609            cputag_set_input_line(space->machine(), "maincpu", INPUT_LINE_RESET, PULSE_LINE);
610            system_reset();
611            break;
612         case 0x0e:
613            if(LOG_SMPC) logerror ("SMPC: Change Clock to 352\n");
614            smpc_ram[0x5f]=0x0e;
615            space->machine().device("maincpu")->set_unscaled_clock(MASTER_CLOCK_352/2);
616            space->machine().device("slave")->set_unscaled_clock(MASTER_CLOCK_352/2);
617            space->machine().device("audiocpu")->set_unscaled_clock(MASTER_CLOCK_352/5);
618            cputag_set_input_line(space->machine(), "maincpu", INPUT_LINE_NMI, PULSE_LINE); // ff said this causes nmi, should we set a timer then nmi?
619            break;
620         case 0x0f:
621            if(LOG_SMPC) logerror ("SMPC: Change Clock to 320\n");
622            smpc_ram[0x5f]=0x0f;
623            space->machine().device("maincpu")->set_unscaled_clock(MASTER_CLOCK_320/2);
624            space->machine().device("slave")->set_unscaled_clock(MASTER_CLOCK_320/2);
625            space->machine().device("audiocpu")->set_unscaled_clock(MASTER_CLOCK_320/5);
626            cputag_set_input_line(space->machine(), "maincpu", INPUT_LINE_NMI, PULSE_LINE); // ff said this causes nmi, should we set a timer then nmi?
627            break;
628         /*"Interrupt Back"*/
629         case 0x10:
630            if(LOG_SMPC) logerror ("SMPC: Status Acquire\n");
631            smpc_ram[0x5f]=0x10;
632            smpc_ram[0x21] = (0x80) | ((NMI_reset & 1) << 6);
633            //smpc_ram[0x23] = DectoBCD(systime.local_time.year /100);
634            //smpc_ram[0x25] = DectoBCD(systime.local_time.year %100);
635            //smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month+1);
636            //smpc_ram[0x29] = DectoBCD(systime.local_time.mday);
637            //smpc_ram[0x2b] = DectoBCD(systime.local_time.hour);
638            //smpc_ram[0x2d] = DectoBCD(systime.local_time.minute);
639            //smpc_ram[0x2f] = DectoBCD(systime.local_time.second);
640
641            smpc_ram[0x31]=0x00;  //?
642
643            //smpc_ram[0x33]=input_port_read(space->machine(), "FAKE");
644
645            smpc_ram[0x35]=0x00;
646            smpc_ram[0x37]=0x00;
647
648            smpc_ram[0x39]=0xff;
649            smpc_ram[0x3b]=0xff;
650            smpc_ram[0x3d]=0xff;
651            smpc_ram[0x3f]=0xff;
652            smpc_ram[0x41]=0xff;
653            smpc_ram[0x43]=0xff;
654            smpc_ram[0x45]=0xff;
655            smpc_ram[0x47]=0xff;
656            smpc_ram[0x49]=0xff;
657            smpc_ram[0x4b]=0xff;
658            smpc_ram[0x4d]=0xff;
659            smpc_ram[0x4f]=0xff;
660            smpc_ram[0x51]=0xff;
661            smpc_ram[0x53]=0xff;
662            smpc_ram[0x55]=0xff;
663            smpc_ram[0x57]=0xff;
664            smpc_ram[0x59]=0xff;
665            smpc_ram[0x5b]=0xff;
666            smpc_ram[0x5d]=0xff;
667
668         //  /*This is for RTC,cartridge code and similar stuff...*/
669            /*System Manager(SMPC) irq*/
670            {
671               //if(LOG_SMPC) logerror ("Interrupt: System Manager (SMPC) at scanline %04x, Vector 0x47 Level 0x08\n",scanline);
672               cputag_set_input_line_and_vector(space->machine(), "maincpu", 8, (stv_irq.smpc) ? HOLD_LINE : CLEAR_LINE, 0x47);
673            }
674         break;
675         /* RTC write*/
676         case 0x16:
677            if(LOG_SMPC) logerror("SMPC: RTC write\n");
678            smpc_ram[0x2f] = smpc_ram[0x0d];
679            smpc_ram[0x2d] = smpc_ram[0x0b];
680            smpc_ram[0x2b] = smpc_ram[0x09];
681            smpc_ram[0x29] = smpc_ram[0x07];
682            smpc_ram[0x27] = smpc_ram[0x05];
683            smpc_ram[0x25] = smpc_ram[0x03];
684            smpc_ram[0x23] = smpc_ram[0x01];
685            smpc_ram[0x5f]=0x16;
686         break;
687         /* SMPC memory setting*/
688         case 0x17:
689            if(LOG_SMPC) logerror ("SMPC: memory setting\n");
690            smpc_ram[0x5f]=0x17;
691         break;
692         case 0x18:
693            if(LOG_SMPC) logerror ("SMPC: NMI request\n");
694            smpc_ram[0x5f]=0x18;
695            /*NMI is unconditionally requested?*/
696            cputag_set_input_line(space->machine(), "maincpu", INPUT_LINE_NMI, PULSE_LINE);
697            break;
698         case 0x19:
699            if(LOG_SMPC) logerror ("SMPC: NMI Enable\n");
700            smpc_ram[0x5f]=0x19;
701            NMI_reset = 0;
702            smpc_ram[0x21] = (0x80) | ((NMI_reset & 1) << 6);
703            break;
704         case 0x1a:
705            if(LOG_SMPC) logerror ("SMPC: NMI Disable\n");
706            smpc_ram[0x5f]=0x1a;
707            NMI_reset = 1;
708            smpc_ram[0x21] = (0x80) | ((NMI_reset & 1) << 6);
709            break;
710         default:
711            if(LOG_SMPC) logerror ("cpu '%s' (PC=%08X) SMPC: undocumented Command %02x\n", space->device().tag(), cpu_get_pc(&space->device()), data);
712      }
713
714      // we've processed the command, clear status flag
715      smpc_ram[0x63] = 0x00;
716      /*TODO:emulate the timing of each command...*/
717   }
718}
719
720
721static READ32_HANDLER ( stv_SMPC_r32 )
722{
723   int byte = 0;
724   int readdata = 0;
725   /* registers are all byte accesses, convert here */
726   offset = offset << 2; // multiply offset by 4
727
728   if (ACCESSING_BITS_24_31)   { byte = 0; readdata = stv_SMPC_r8(space, offset+byte) << 24; }
729   if (ACCESSING_BITS_16_23)   { byte = 1; readdata = stv_SMPC_r8(space, offset+byte) << 16; }
730   if (ACCESSING_BITS_8_15)   { byte = 2; readdata = stv_SMPC_r8(space, offset+byte) << 8;  }
731   if (ACCESSING_BITS_0_7)      { byte = 3; readdata = stv_SMPC_r8(space, offset+byte) << 0;  }
732
733   return readdata;
734}
735
736
737static WRITE32_HANDLER ( stv_SMPC_w32 )
738{
739   int byte = 0;
740   int writedata = 0;
741   /* registers are all byte accesses, convert here so we can use the data more easily later */
742   offset = offset << 2; // multiply offset by 4
743
744   if (ACCESSING_BITS_24_31)   { byte = 0; writedata = data >> 24; }
745   if (ACCESSING_BITS_16_23)   { byte = 1; writedata = data >> 16; }
746   if (ACCESSING_BITS_8_15)   { byte = 2; writedata = data >> 8;  }
747   if (ACCESSING_BITS_0_7)      { byte = 3; writedata = data >> 0;  }
748
749   writedata &= 0xff;
750
751   offset += byte;
752
753   stv_SMPC_w8(space, offset,writedata);
754}
755
756/*
757I/O overview:
758    PORT-A  1st player inputs
759    PORT-B  2nd player inputs
760    PORT-C  system input
761    PORT-D  system output
762    PORT-E  I/O 1
763    PORT-F  I/O 2
764    PORT-G  I/O 3
765    PORT-AD AD-Stick inputs?(Fake for now...)
766    SERIAL COM
767
768offsets:
769    0h PORT-A
770    0l PORT-B
771    1h PORT-C
772    1l PORT-D
773    2h PORT-E
774    2l PORT-F (extra button layout)
775    3h PORT-G
776    3l
777    4h PORT-SEL
778    4l
779    5h SERIAL COM WRITE
780    5l
781    6h SERIAL COM READ
782    6l
783    7h
784    7l PORT-AD
785*/
786static const UINT8 port_ad[] =
787{
788   0xcc,0xb2,0x99,0x7f,0x66,0x4c,0x33,0x19
789};
790
791static UINT8 port_sel,mux_data;
792static int port_i;
793
794static READ32_HANDLER ( stv_io_r32 )
795{
796//  if(LOG_IOGA) logerror("(PC=%08X): I/O r %08X & %08X\n", cpu_get_pc(&space->device()), offset*4, mem_mask);
797//  popmessage("SEL: %02x MUX: %02x OFF: %02x",port_sel,mux_data,offset*4);
798
799//  printf("(PC=%08X): I/O r %08X & %08X\n", cpu_get_pc(&space->device()), offset*4, mem_mask);
800
801   switch(offset)
802   {
803      case 0x00/4:
804      switch(port_sel)
805      {
806         case 0x77: return 0xff000000|(input_port_read(space->machine(), "P1") << 16) |0x0000ff00|(input_port_read(space->machine(), "P2"));
807         case 0x67:
808         {
809            switch(mux_data)
810            {
811               /*Mahjong panel interface,bit wise(ACTIVE LOW)*/
812               case 0xfe:   return 0xff000000 | (input_port_read_safe(space->machine(), "KEY0", 0)  << 16) | 0x0000ff00 | (input_port_read_safe(space->machine(), "KEY5", 0));
813               case 0xfd:  return 0xff000000 | (input_port_read_safe(space->machine(), "KEY1", 0)  << 16) | 0x0000ff00 | (input_port_read_safe(space->machine(), "KEY6", 0));
814               case 0xfb:   return 0xff000000 | (input_port_read_safe(space->machine(), "KEY2", 0)  << 16) | 0x0000ff00 | (input_port_read_safe(space->machine(), "KEY7", 0));
815               case 0xf7:   return 0xff000000 | (input_port_read_safe(space->machine(), "KEY3", 0) << 16) | 0x0000ff00 | (input_port_read_safe(space->machine(), "KEY8", 0));
816               case 0xef:  return 0xff000000 | (input_port_read_safe(space->machine(), "KEY4", 0) << 16) | 0x0000ff00 | (input_port_read_safe(space->machine(), "KEY9", 0));
817               /*Joystick panel*/
818               default:
819               //popmessage("%02x MUX DATA",mux_data);
820                return (input_port_read(space->machine(), "P1") << 16) | (input_port_read(space->machine(), "P2"));
821            }
822         }
823         case 0x47:
824         {
825            if ( strcmp(space->machine().system().name,"critcrsh") == 0 )
826            {
827               int data1 = 0, data2 = 0;
828
829               /* Critter Crusher */
830               data1 = input_port_read(space->machine(), "LIGHTX");
831               data1 = BITSWAP8(data1, 2, 3, 0, 1, 6, 7, 5, 4) & 0xf3;
832               data1 |= (input_port_read(space->machine(), "P1") & 1) ? 0x0 : 0x4;
833               data2 = input_port_read(space->machine(), "LIGHTY");
834               data2 = BITSWAP8(data2, 2, 3, 0, 1, 6, 7, 5, 4) & 0xf3;
835               data2 |= (input_port_read(space->machine(), "P1") & 1) ? 0x0 : 0x4;
836
837               return 0xff000000 | data1 << 16 | 0x0000ff00 | data2;
838            }
839         }
840         //default:
841         //case 0x40: return space->machine().rand();
842         default:
843         //popmessage("%02x PORT SEL",port_sel);
844         return (input_port_read(space->machine(), "P1") << 16) | (input_port_read(space->machine(), "P2"));
845      }
846      case 0x04/4:
847      if ( strcmp(space->machine().system().name,"critcrsh") == 0 )
848         return ((input_port_read(space->machine(), "SYSTEM") << 16) & ((input_port_read(space->machine(), "P1") & 1) ? 0xffef0000 : 0xffff0000)) | (ioga[1]);
849      else
850         return (input_port_read(space->machine(), "SYSTEM") << 16) | (ioga[1]);
851
852      case 0x08/4:
853      switch(port_sel)
854      {
855         case 0x77:   return (input_port_read(space->machine(), "UNUSED") << 16) | (input_port_read(space->machine(), "EXTRA"));
856         case 0x67:   return 0xffffffff;/**/
857         case 0x20:  return 0xffff0000 | (ioga[2] & 0xffff);
858         case 0x10:  return ((ioga[2] & 0xffff) << 16) | 0xffff;
859         case 0x60:  return 0xffffffff;/**/
860         default:
861         return 0xffffffff;
862      }
863      case 0x0c/4:
864      switch(port_sel)
865      {
866         case 0x60:  return ((ioga[2] & 0xffff) << 16) | 0xffff;
867         default:
868         //popmessage("offs: 3 %02x",port_sel);
869         return 0xffffffff;
870      }
871      //case 0x10/4:
872      case 0x14/4:
873      switch(port_sel)
874      {
875         case 0x77:
876         {
877            //popmessage("(PC=%06x) offs 5 %04x %02x",cpu_get_pc(&space->device()),port_sel,((ioga[5] & 0xff0000) >> 16));
878            logerror("(PC=%06x) offs 5 %04x %02x\n",cpu_get_pc(&space->device()),port_sel,((ioga[5] & 0xff0000) >> 16));
879
880            //stv_workram_h[0x8e830/4] = ((ioga[5] & 0xff0000) >> 16) ^ 0x3;
881            //stv_workram_h[0x8e834/4] = ((ioga[5] & 0xff0000) >> 16) ^ 0x3;
882            return (ioga[5] & 0xff0000) >> 16;//stv_workram_h[0x8e830/4];//sound board data
883         }
884         default: return 0xffffffff;
885      }
886      case 0x18/4:
887      switch(port_sel)
888      {
889         case 0x60:  return ioga[5];
890         case 0x77:
891         {
892            //popmessage("(PC=%06x) offs 6 %04x %02x",cpu_get_pc(&space->device()),port_sel,((ioga[5] & 0xff0000) >> 16));
893            logerror("(PC=%06x) offs 6 %04x %02x\n",cpu_get_pc(&space->device()),port_sel,((ioga[5] & 0xff0000) >> 16));
894            return 0;//sound board status,non-zero = processing
895         }
896         default:
897         //popmessage("offs: 6 %02x",port_sel);
898         return 0xffffffff;
899      }
900      case 0x1c/4:
901      if(LOG_IOGA) logerror("(PC %s=%06x) Warning: READ from PORT_AD\n", space->device().tag(), cpu_get_pc(&space->device()));
902      popmessage("Read from PORT_AD");
903      port_i++;
904      return port_ad[port_i & 7];
905      default:
906      return ioga[offset];
907   }
908}
909
910static WRITE32_HANDLER ( stv_io_w32 )
911{
912//  if(LOG_IOGA) logerror("(PC=%08X): I/O w %08X = %08X & %08X\n", cpu_get_pc(&space->device()), offset*4, data, mem_mask);
913
914//  printf("(PC=%08X): I/O w %08X = %08X & %08X\n", cpu_get_pc(&space->device()), offset*4, data, mem_mask);
915
916   switch(offset)
917   {
918      case 0x04/4:
919         if(ACCESSING_BITS_0_7)
920         {
921            /*Why does the BIOS tests these as ACTIVE HIGH? A program bug?*/
922            ioga[1] = (data) & 0xff;
923            coin_counter_w(space->machine(), 0,~data & 0x01);
924            coin_counter_w(space->machine(), 1,~data & 0x02);
925            coin_lockout_w(space->machine(), 0,~data & 0x04);
926            coin_lockout_w(space->machine(), 1,~data & 0x08);
927            /*
928                other bits reserved
929                */
930         }
931         break;
932      case 0x08/4:
933         if(ACCESSING_BITS_16_23)
934         {
935            ioga[2] = data >> 16;
936            mux_data = ioga[2];
937         }
938         else if(ACCESSING_BITS_0_7)
939            ioga[2] = data;
940         break;
941      case 0x0c/4:
942         if(ACCESSING_BITS_16_23)
943            ioga[3] = data;
944         break;
945      case 0x10/4:
946         if(ACCESSING_BITS_16_23)
947            port_sel = (data & 0xffff0000) >> 16;
948         break;
949      case 0x14/4:
950         if(ACCESSING_BITS_16_23)
951            ioga[5] = data;
952         break;
953      //case 0x18/4:
954      case 0x1c/4:
955         //technical bowling tests here
956         if(ACCESSING_BITS_16_23)
957            ioga[7] = data;
958         break;
959
960   }
961}
962
963/*
964
965SCU Handling
966
967*/
968
969/**********************************************************************************
970SCU Register Table
971offset,relative address
972Registers are in long words.
973===================================================================================
9740     0000  Level 0 DMA Set Register
9751     0004
9762     0008
9773     000c
9784     0010
9795     0014
9806     0018
9817     001c
9828     0020  Level 1 DMA Set Register
9839     0024
98410    0028
98511    002c
98612    0030
98713    0034
98814    0038
98915    003c
99016    0040  Level 2 DMA Set Register
99117    0044
99218    0048
99319    004c
99420    0050
99521    0054
99622    0058
99723    005c
99824    0060  DMA Forced Stop
99925    0064
100026    0068
100127    006c
100228    0070  <Free>
100329    0074
100430    0078
100531    007c  DMA Status Register
100632    0080  DSP Program Control Port
100733    0084  DSP Program RAM Data Port
100834    0088  DSP Data RAM Address Port
100935    008c  DSP Data RAM Data Port
101036    0090  Timer 0 Compare Register
101137    0094  Timer 1 Set Data Register
101238    0098  Timer 1 Mode Register
101339    009c  <Free>
101440    00a0  Interrupt Mask Register
101541    00a4  Interrupt Status Register
101642    00a8  A-Bus Interrupt Acknowledge
101743    00ac  <Free>
101844    00b0  A-Bus Set Register
101945    00b4
102046    00b8  A-Bus Refresh Register
102147    00bc  <Free>
102248    00c0
102349    00c4  SCU SDRAM Select Register
102450    00c8  SCU Version Register
102551    00cc  <Free>
102652    00cf
1027===================================================================================
1028DMA Status Register(32-bit):
1029xxxx xxxx x--- xx-- xx-- xx-- xx-- xx-- UNUSED
1030---- ---- -x-- ---- ---- ---- ---- ---- DMA DSP-Bus access
1031---- ---- --x- ---- ---- ---- ---- ---- DMA B-Bus access
1032---- ---- ---x ---- ---- ---- ---- ---- DMA A-Bus access
1033---- ---- ---- --x- ---- ---- ---- ---- DMA lv 1 interrupt
1034---- ---- ---- ---x ---- ---- ---- ---- DMA lv 0 interrupt
1035---- ---- ---- ---- --x- ---- ---- ---- DMA lv 2 in stand-by
1036---- ---- ---- ---- ---x ---- ---- ---- DMA lv 2 in operation
1037---- ---- ---- ---- ---- --x- ---- ---- DMA lv 1 in stand-by
1038---- ---- ---- ---- ---- ---x ---- ---- DMA lv 1 in operation
1039---- ---- ---- ---- ---- ---- --x- ---- DMA lv 0 in stand-by
1040---- ---- ---- ---- ---- ---- ---x ---- DMA lv 0 in operation
1041---- ---- ---- ---- ---- ---- ---- --x- DSP side DMA in stand-by
1042---- ---- ---- ---- ---- ---- ---- ---x DSP side DMA in operation
1043
1044**********************************************************************************/
1045/*
1046DMA TODO:
1047-Verify if there are any kind of bugs,do clean-ups,use better comments
1048 and macroize for better reading...
1049-Add timings(but how fast are each DMA?).
1050-Add level priority & DMA status register.
1051-Add DMA start factor conditions that are different than 7.
1052-Add byte data type transfer.
1053-Set boundaries.
1054*/
1055
1056#define DIRECT_MODE(_lv_)         (!(stv_scu[5+(_lv_*8)] & 0x01000000))
1057#define INDIRECT_MODE(_lv_)           (stv_scu[5+(_lv_*8)] & 0x01000000)
1058#define DRUP(_lv_)                 (stv_scu[5+(_lv_*8)] & 0x00010000)
1059#define DWUP(_lv_)                    (stv_scu[5+(_lv_*8)] & 0x00000100)
1060
1061#define DMA_STATUS            (stv_scu[31])
1062/*These macros sets the various DMA status flags.*/
1063#define D0MV_1   if(!(DMA_STATUS & 0x10))    DMA_STATUS^=0x10
1064#define D1MV_1   if(!(DMA_STATUS & 0x100))   DMA_STATUS^=0x100
1065#define D2MV_1   if(!(DMA_STATUS & 0x1000))  DMA_STATUS^=0x1000
1066#define D0MV_0   if(DMA_STATUS & 0x10)       DMA_STATUS^=0x10
1067#define D1MV_0   if(DMA_STATUS & 0x100)       DMA_STATUS^=0x100
1068#define D2MV_0   if(DMA_STATUS & 0x1000)     DMA_STATUS^=0x1000
1069
1070static UINT32 scu_index_0,scu_index_1,scu_index_2;
1071static UINT8 scsp_to_main_irq;
1072
1073static UINT32 scu_add_tmp;
1074
1075/*For area checking*/
1076#define ABUS(_lv_)       ((scu_##_lv_ & 0x07ffffff) >= 0x02000000) && ((scu_##_lv_ & 0x07ffffff) <= 0x04ffffff)
1077#define BBUS(_lv_)       ((scu_##_lv_ & 0x07ffffff) >= 0x05a00000) && ((scu_##_lv_ & 0x07ffffff) <= 0x05ffffff)
1078#define VDP1_REGS(_lv_)  ((scu_##_lv_ & 0x07ffffff) >= 0x05d00000) && ((scu_##_lv_ & 0x07ffffff) <= 0x05dfffff)
1079#define VDP2(_lv_)       ((scu_##_lv_ & 0x07ffffff) >= 0x05e00000) && ((scu_##_lv_ & 0x07ffffff) <= 0x05fdffff)
1080#define WORK_RAM_L(_lv_) ((scu_##_lv_ & 0x07ffffff) >= 0x00200000) && ((scu_##_lv_ & 0x07ffffff) <= 0x002fffff)
1081#define WORK_RAM_H(_lv_) ((scu_##_lv_ & 0x07ffffff) >= 0x06000000) && ((scu_##_lv_ & 0x07ffffff) <= 0x060fffff)
1082#define SOUND_RAM(_lv_)  ((scu_##_lv_ & 0x07ffffff) >= 0x05a00000) && ((scu_##_lv_ & 0x07ffffff) <= 0x05afffff)
1083
1084static READ32_HANDLER( stv_scu_r32 )
1085{
1086   /*TODO: write only registers must return 0...*/
1087   //popmessage("%02x",DMA_STATUS);
1088   //if (offset == 23)
1089   //{
1090      //Super Major League reads here???
1091   //}
1092   if (offset == 31)
1093   {
1094      if(LOG_SCU) logerror("(PC=%08x) DMA status reg read\n",cpu_get_pc(&space->device()));
1095      return stv_scu[offset];
1096   }
1097   else if ( offset == 35 )
1098   {
1099        if(LOG_SCU) logerror( "DSP mem read at %08X\n", stv_scu[34]);
1100        return dsp_ram_addr_r();
1101    }
1102    else if( offset == 41) /*IRQ reg status read*/
1103    {
1104      if(LOG_SCU) logerror("(PC=%08x) IRQ status reg read %08x\n",cpu_get_pc(&space->device()),mem_mask);
1105
1106      stv_scu[41] = (stv_irq.vblank_in & 1)<<0;
1107      stv_scu[41]|= (stv_irq.vblank_out & 1)<<1;
1108      stv_scu[41]|= (stv_irq.hblank_in & 1)<<2;
1109      stv_scu[41]|= (stv_irq.timer_0 & 1)<<3;
1110      stv_scu[41]|= (stv_irq.timer_1 & 1)<<4;
1111      stv_scu[41]|= (stv_irq.dsp_end & 1)<<5;
1112      stv_scu[41]|= (stv_irq.sound_req & 1)<<6;
1113      stv_scu[41]|= (stv_irq.smpc & 1)<<7;
1114      stv_scu[41]|= (stv_irq.pad & 1)<<8;
1115      stv_scu[41]|= (stv_irq.dma_end[0] & 1)<<9;
1116      stv_scu[41]|= (stv_irq.dma_end[1] & 1)<<10;
1117      stv_scu[41]|= (stv_irq.dma_end[2] & 1)<<11;
1118      stv_scu[41]|= (stv_irq.dma_ill & 1)<<12;
1119      stv_scu[41]|= (stv_irq.vdp1_end & 1)<<13;
1120      stv_scu[41]|= (stv_irq.abus & 1)<<15;
1121
1122      return stv_scu[41] ^ 0xffffffff;
1123   }
1124   else if( offset == 50 )
1125   {
1126      logerror("(PC=%08x) SCU version reg read\n",cpu_get_pc(&space->device()));
1127      return 0x00000000;/*SCU Version 0*/
1128   }
1129    else
1130    {
1131       if(LOG_SCU) logerror("(PC=%08x) SCU reg read at %d = %08x\n",cpu_get_pc(&space->device()),offset,stv_scu[offset]);
1132       return stv_scu[offset];
1133   }
1134}
1135
1136static WRITE32_HANDLER( stv_scu_w32 )
1137{
1138   COMBINE_DATA(&stv_scu[offset]);
1139
1140   switch(offset)
1141   {
1142      /*LV 0 DMA*/
1143      case 0:   scu_src_0  = ((stv_scu[0] & 0x07ffffff) >> 0); break;
1144      case 1:   scu_dst_0  = ((stv_scu[1] & 0x07ffffff) >> 0); break;
1145      case 2: scu_size_0 = ((stv_scu[2] & 0x000fffff) >> 0); break;
1146      case 3:
1147         /*Read address add value for DMA lv 0*/
1148         if(stv_scu[3] & 0x100)
1149            scu_src_add_0 = 4;
1150         else
1151            scu_src_add_0 = 1;
1152
1153         /*Write address add value for DMA lv 0*/
1154         switch(stv_scu[3] & 7)
1155         {
1156            case 0: scu_dst_add_0 = 2;   break;
1157            case 1: scu_dst_add_0 = 4;   break;
1158            case 2: scu_dst_add_0 = 8;   break;
1159            case 3: scu_dst_add_0 = 16;  break;
1160            case 4: scu_dst_add_0 = 32;  break;
1161            case 5: scu_dst_add_0 = 64;  break;
1162            case 6: scu_dst_add_0 = 128; break;
1163            case 7: scu_dst_add_0 = 256; break;
1164         }
1165         break;
1166      case 4:
1167/*
1168-stv_scu[4] bit 0 is DMA starting bit.
1169    Used when the start factor is 7.Toggle after execution.
1170-stv_scu[4] bit 8 is DMA Enable bit.
1171    This is an execution mask flag.
1172-stv_scu[5] bit 0,bit 1 and bit 2 is DMA starting factor.
1173    It must be 7 for this specific condition.
1174-stv_scu[5] bit 24 is Indirect Mode/Direct Mode (0/1).
1175*/
1176      if(stv_scu[4] & 1 && ((stv_scu[5] & 7) == 7) && stv_scu[4] & 0x100)
1177      {
1178         if(DIRECT_MODE(0)) { dma_direct_lv0(space); }
1179         else            { dma_indirect_lv0(space); }
1180
1181         stv_scu[4]^=1;//disable starting bit.
1182
1183         /*Sound IRQ*/
1184         if(/*(!(stv_scu[40] & 0x40)) &&*/ scsp_to_main_irq == 1)
1185         {
1186            //cputag_set_input_line_and_vector(space->machine(), "maincpu", 9, HOLD_LINE , 0x46);
1187            logerror("SCSP: Main CPU interrupt\n");
1188            #if 0
1189            if((scu_dst_0 & 0x7ffffff) != 0x05a00000)
1190            {
1191               if(!(stv_scu[40] & 0x1000))
1192               {
1193                  cputag_set_input_line_and_vector(space->machine(), "maincpu", 3, HOLD_LINE, 0x4c);
1194                  logerror("SCU: Illegal DMA interrupt\n");
1195               }
1196            }
1197            #endif
1198         }
1199      }
1200      break;
1201      case 5:
1202      if(INDIRECT_MODE(0))
1203      {
1204         if(LOG_SCU) logerror("Indirect Mode DMA lv 0 set\n");
1205         if(!DWUP(0)) scu_index_0 = scu_dst_0;
1206      }
1207
1208      /*Start factor enable bits,bit 2,bit 1 and bit 0*/
1209      if((stv_scu[5] & 7) != 7)
1210         if(LOG_SCU) logerror("Start factor chosen for lv 0 = %d\n",stv_scu[5] & 7);
1211      break;
1212      /*LV 1 DMA*/
1213      case 8:    scu_src_1  = ((stv_scu[8] &  0x07ffffff) >> 0);  break;
1214      case 9:    scu_dst_1  = ((stv_scu[9] &  0x07ffffff) >> 0);  break;
1215      case 10: scu_size_1 = ((stv_scu[10] & 0x00001fff) >> 0);  break;
1216      case 11:
1217      /*Read address add value for DMA lv 1*/
1218      if(stv_scu[11] & 0x100)
1219         scu_src_add_1 = 4;
1220      else
1221         scu_src_add_1 = 1;
1222
1223      /*Write address add value for DMA lv 1*/
1224      switch(stv_scu[11] & 7)
1225      {
1226         case 0: scu_dst_add_1 = 2;   break;
1227         case 1: scu_dst_add_1 = 4;   break;
1228         case 2: scu_dst_add_1 = 8;   break;
1229         case 3: scu_dst_add_1 = 16;  break;
1230         case 4: scu_dst_add_1 = 32;  break;
1231         case 5: scu_dst_add_1 = 64;  break;
1232         case 6: scu_dst_add_1 = 128; break;
1233         case 7: scu_dst_add_1 = 256; break;
1234      }
1235      break;
1236      case 12:
1237      if(stv_scu[12] & 1 && ((stv_scu[13] & 7) == 7) && stv_scu[12] & 0x100)
1238      {
1239         if(DIRECT_MODE(1)) { dma_direct_lv1(space); }
1240         else            { dma_indirect_lv1(space); }
1241
1242         stv_scu[12]^=1;
1243
1244         /*Sound IRQ*/
1245         if(/*(!(stv_scu[40] & 0x40)) &&*/ scsp_to_main_irq == 1)
1246         {
1247            //cputag_set_input_line_and_vector(space->machine(), "maincpu", 9, HOLD_LINE , 0x46);
1248            logerror("SCSP: Main CPU interrupt\n");
1249         }
1250      }
1251      break;
1252      case 13:
1253      if(INDIRECT_MODE(1))
1254      {
1255         if(LOG_SCU) logerror("Indirect Mode DMA lv 1 set\n");
1256         if(!DWUP(1)) scu_index_1 = scu_dst_1;
1257      }
1258
1259      if((stv_scu[13] & 7) != 7)
1260         if(LOG_SCU) logerror("Start factor chosen for lv 1 = %d\n",stv_scu[13] & 7);
1261      break;
1262      /*LV 2 DMA*/
1263      case 16: scu_src_2  = ((stv_scu[16] & 0x07ffffff) >> 0);  break;
1264      case 17: scu_dst_2  = ((stv_scu[17] & 0x07ffffff) >> 0);  break;
1265      case 18: scu_size_2 = ((stv_scu[18] & 0x00001fff) >> 0);  break;
1266      case 19:
1267      /*Read address add value for DMA lv 2*/
1268      if(stv_scu[19] & 0x100)
1269         scu_src_add_2 = 4;
1270      else
1271         scu_src_add_2 = 1;
1272
1273      /*Write address add value for DMA lv 2*/
1274      switch(stv_scu[19] & 7)
1275      {
1276         case 0: scu_dst_add_2 = 2;   break;
1277         case 1: scu_dst_add_2 = 4;   break;
1278         case 2: scu_dst_add_2 = 8;   break;
1279         case 3: scu_dst_add_2 = 16;  break;
1280         case 4: scu_dst_add_2 = 32;  break;
1281         case 5: scu_dst_add_2 = 64;  break;
1282         case 6: scu_dst_add_2 = 128; break;
1283         case 7: scu_dst_add_2 = 256; break;
1284      }
1285      break;
1286      case 20:
1287      if(stv_scu[20] & 1 && ((stv_scu[21] & 7) == 7) && stv_scu[20] & 0x100)
1288      {
1289         if(DIRECT_MODE(2)) { dma_direct_lv2(space); }
1290         else            { dma_indirect_lv2(space); }
1291
1292         stv_scu[20]^=1;
1293
1294         /*Sound IRQ*/
1295         if(/*(!(stv_scu[40] & 0x40)) &&*/ scsp_to_main_irq == 1)
1296         {
1297            //cputag_set_input_line_and_vector(space->machine(), "maincpu", 9, HOLD_LINE , 0x46);
1298            logerror("SCSP: Main CPU interrupt\n");
1299         }
1300      }
1301      break;
1302      case 21:
1303      if(INDIRECT_MODE(2))
1304      {
1305         if(LOG_SCU) logerror("Indirect Mode DMA lv 2 set\n");
1306         if(!DWUP(2)) scu_index_2 = scu_dst_2;
1307      }
1308
1309      if((stv_scu[21] & 7) != 7)
1310         if(LOG_SCU) logerror("Start factor chosen for lv 2 = %d\n",stv_scu[21] & 7);
1311      break;
1312      case 24:
1313      if(LOG_SCU) logerror("DMA Forced Stop Register set = %02x\n",stv_scu[24]);
1314      break;
1315      case 31: if(LOG_SCU) logerror("Warning: DMA status WRITE! Offset %02x(%d)\n",offset*4,offset); break;
1316      /*DSP section*/
1317      /*Use functions so it is easier to work out*/
1318      case 32:
1319      dsp_prg_ctrl(space, data);
1320      if(LOG_SCU) logerror("SCU DSP: Program Control Port Access %08x\n",data);
1321      break;
1322      case 33:
1323      dsp_prg_data(data);
1324      if(LOG_SCU) logerror("SCU DSP: Program RAM Data Port Access %08x\n",data);
1325      break;
1326      case 34:
1327      dsp_ram_addr_ctrl(data);
1328      if(LOG_SCU) logerror("SCU DSP: Data RAM Address Port Access %08x\n",data);
1329      break;
1330      case 35:
1331      dsp_ram_addr_w(data);
1332      if(LOG_SCU) logerror("SCU DSP: Data RAM Data Port Access %08x\n",data);
1333      break;
1334      case 36: if(LOG_SCU) logerror("timer 0 compare data = %03x\n",stv_scu[36]);break;
1335      case 37: if(LOG_SCU) logerror("timer 1 set data = %08x\n",stv_scu[37]); break;
1336      case 38: if(LOG_SCU) logerror("timer 1 mode data = %08x\n",stv_scu[38]); break;
1337      case 40:
1338      /*An interrupt is masked when his specific bit is 1.*/
1339      /*Are bit 16-bit 31 for External A-Bus irq mask like the status register?*/
1340
1341      stv_irq.vblank_in =  (((stv_scu[40] & 0x0001)>>0) ^ 1);
1342      stv_irq.vblank_out = (((stv_scu[40] & 0x0002)>>1) ^ 1);
1343      stv_irq.hblank_in =  (((stv_scu[40] & 0x0004)>>2) ^ 1);
1344      stv_irq.timer_0 =    (((stv_scu[40] & 0x0008)>>3) ^ 1);
1345      stv_irq.timer_1 =    (((stv_scu[40] & 0x0010)>>4) ^ 1);
1346      stv_irq.dsp_end =    (((stv_scu[40] & 0x0020)>>5) ^ 1);
1347      stv_irq.sound_req =  (((stv_scu[40] & 0x0040)>>6) ^ 1);
1348      stv_irq.smpc =       (((stv_scu[40] & 0x0080)>>7)); //NOTE: SCU bug
1349      stv_irq.pad =        (((stv_scu[40] & 0x0100)>>8) ^ 1);
1350      stv_irq.dma_end[2] = (((stv_scu[40] & 0x0200)>>9) ^ 1);
1351      stv_irq.dma_end[1] = (((stv_scu[40] & 0x0400)>>10) ^ 1);
1352      stv_irq.dma_end[0] = (((stv_scu[40] & 0x0800)>>11) ^ 1);
1353      stv_irq.dma_ill =    (((stv_scu[40] & 0x1000)>>12) ^ 1);
1354      stv_irq.vdp1_end =   (((stv_scu[40] & 0x2000)>>13) ^ 1);
1355      stv_irq.abus =       (((stv_scu[40] & 0x8000)>>15) ^ 1);
1356
1357      /*Take out the common settings to keep logging quiet.*/
1358      if(stv_scu[40] != 0xfffffffe &&
1359         stv_scu[40] != 0xfffffffc &&
1360         stv_scu[40] != 0xffffffff)
1361      {
1362         if(LOG_SCU) logerror("cpu %s (PC=%08X) IRQ mask reg set %08x = %d%d%d%d|%d%d%d%d|%d%d%d%d|%d%d%d%d\n",
1363         space->device().tag(), cpu_get_pc(&space->device()),
1364         stv_scu[offset],
1365         stv_scu[offset] & 0x8000 ? 1 : 0, /*A-Bus irq*/
1366         stv_scu[offset] & 0x4000 ? 1 : 0, /*<reserved>*/
1367         stv_scu[offset] & 0x2000 ? 1 : 0, /*Sprite draw end irq(VDP1)*/
1368         stv_scu[offset] & 0x1000 ? 1 : 0, /*Illegal DMA irq*/
1369         stv_scu[offset] & 0x0800 ? 1 : 0, /*Lv 0 DMA end irq*/
1370         stv_scu[offset] & 0x0400 ? 1 : 0, /*Lv 1 DMA end irq*/
1371         stv_scu[offset] & 0x0200 ? 1 : 0, /*Lv 2 DMA end irq*/
1372         stv_scu[offset] & 0x0100 ? 1 : 0, /*PAD irq*/
1373         stv_scu[offset] & 0x0080 ? 1 : 0, /*System Manager(SMPC) irq*/
1374         stv_scu[offset] & 0x0040 ? 1 : 0, /*Snd req*/
1375         stv_scu[offset] & 0x0020 ? 1 : 0, /*DSP irq end*/
1376         stv_scu[offset] & 0x0010 ? 1 : 0, /*Timer 1 irq*/
1377         stv_scu[offset] & 0x0008 ? 1 : 0, /*Timer 0 irq*/
1378         stv_scu[offset] & 0x0004 ? 1 : 0, /*HBlank-IN*/
1379         stv_scu[offset] & 0x0002 ? 1 : 0, /*VBlank-OUT*/
1380         stv_scu[offset] & 0x0001 ? 1 : 0);/*VBlank-IN*/
1381      }
1382      break;
1383      /*Interrupt Control reg Set*/
1384      case 41:
1385      /*This is r/w by introdon...*/
1386      if(LOG_SCU) logerror("IRQ status reg set:%08x %08x\n",stv_scu[41],mem_mask);
1387
1388      stv_irq.vblank_in =  ((stv_scu[41] & 0x0001)>>0);
1389      stv_irq.vblank_out = ((stv_scu[41] & 0x0002)>>1);
1390      stv_irq.hblank_in =  ((stv_scu[41] & 0x0004)>>2);
1391      stv_irq.timer_0 =    ((stv_scu[41] & 0x0008)>>3);
1392      stv_irq.timer_1 =    ((stv_scu[41] & 0x0010)>>4);
1393      stv_irq.dsp_end =    ((stv_scu[41] & 0x0020)>>5);
1394      stv_irq.sound_req =  ((stv_scu[41] & 0x0040)>>6);
1395      stv_irq.smpc =       ((stv_scu[41] & 0x0080)>>7);
1396      stv_irq.pad =        ((stv_scu[41] & 0x0100)>>8);
1397      stv_irq.dma_end[2] = ((stv_scu[41] & 0x0200)>>9);
1398      stv_irq.dma_end[1] = ((stv_scu[41] & 0x0400)>>10);
1399      stv_irq.dma_end[0] = ((stv_scu[41] & 0x0800)>>11);
1400      stv_irq.dma_ill =    ((stv_scu[41] & 0x1000)>>12);
1401      stv_irq.vdp1_end =   ((stv_scu[41] & 0x2000)>>13);
1402      stv_irq.abus =       ((stv_scu[41] & 0x8000)>>15);
1403
1404      break;
1405      case 42: if(LOG_SCU) logerror("A-Bus IRQ ACK %08x\n",stv_scu[42]); break;
1406      case 49: if(LOG_SCU) logerror("SCU SDRAM set: %02x\n",stv_scu[49]); break;
1407      default: if(LOG_SCU) logerror("Warning: unused SCU reg set %d = %08x\n",offset,data);
1408   }
1409}
1410
1411/*Lv 0 DMA end irq*/
1412static TIMER_CALLBACK( dma_lv0_ended )
1413{
1414   cputag_set_input_line_and_vector(machine, "maincpu", 5, (stv_irq.dma_end[0]) ? HOLD_LINE : CLEAR_LINE, 0x4b);
1415
1416   D0MV_0;
1417}
1418
1419/*Lv 1 DMA end irq*/
1420static TIMER_CALLBACK( dma_lv1_ended )
1421{
1422   cputag_set_input_line_and_vector(machine, "maincpu", 6, (stv_irq.dma_end[1]) ? HOLD_LINE : CLEAR_LINE, 0x4a);
1423
1424   D1MV_0;
1425}
1426
1427/*Lv 2 DMA end irq*/
1428static TIMER_CALLBACK( dma_lv2_ended )
1429{
1430   cputag_set_input_line_and_vector(machine, "maincpu", 6, (stv_irq.dma_end[2]) ? HOLD_LINE : CLEAR_LINE, 0x49);
1431
1432   D2MV_0;
1433}
1434
1435static void dma_direct_lv0(address_space *space)
1436{
1437   static UINT32 tmp_src,tmp_dst,tmp_size;
1438   if(LOG_SCU) logerror("DMA lv 0 transfer START\n"
1439                      "Start %08x End %08x Size %04x\n",scu_src_0,scu_dst_0,scu_size_0);
1440   if(LOG_SCU) logerror("Start Add %04x Destination Add %04x\n",scu_src_add_0,scu_dst_add_0);
1441
1442   D0MV_1;
1443
1444   if(scu_size_0 == 0) scu_size_0 = 0x00100000;
1445
1446   scsp_to_main_irq = 0;
1447
1448   /*set here the boundaries checks*/
1449   /*...*/
1450
1451   if(SOUND_RAM(dst_0))
1452   {
1453      logerror("Sound RAM DMA write\n");
1454      scsp_to_main_irq = 1;
1455   }
1456
1457   if((scu_dst_add_0 != scu_src_add_0) && (ABUS(src_0)))
1458   {
1459      logerror("A-Bus invalid transfer,sets to default\n");
1460      scu_add_tmp = (scu_dst_add_0*0x100) | (scu_src_add_0);
1461      scu_dst_add_0 = scu_src_add_0 = 4;
1462      scu_add_tmp |= 0x80000000;
1463   }
1464   /*Let me know if you encounter any of these three*/
1465   if(ABUS(dst_0))
1466   {
1467      logerror("A-Bus invalid write\n");
1468      /*...*/
1469   }
1470   if(WORK_RAM_L(dst_0))
1471   {
1472      logerror("WorkRam-L invalid write\n");
1473      /*...*/
1474   }
1475   if(VDP2(src_0))
1476   {
1477      logerror("VDP-2 invalid read\n");
1478      /*...*/
1479   }
1480   if(VDP1_REGS(dst_0))
1481   {
1482      logerror("VDP1 register access,must be in word units\n");
1483      scu_add_tmp = (scu_dst_add_0*0x100) | (scu_src_add_0);
1484      scu_dst_add_0 = scu_src_add_0 = 2;
1485      scu_add_tmp |= 0x80000000;
1486   }
1487   if(DRUP(0))
1488   {
1489      logerror("Data read update = 1,read address add value must be 1 too\n");
1490      scu_add_tmp = (scu_dst_add_0*0x100) | (scu_src_add_0);
1491      scu_src_add_0 = 4;
1492      scu_add_tmp |= 0x80000000;
1493   }
1494
1495   if (WORK_RAM_H(dst_0) && (scu_dst_add_0 != 4))
1496   {
1497      scu_add_tmp = (scu_dst_add_0*0x100) | (scu_src_add_0);
1498      scu_dst_add_0 = 4;
1499      scu_add_tmp |= 0x80000000;
1500   }
1501
1502   tmp_size = scu_size_0;
1503   if(!(DRUP(0))) tmp_src = scu_src_0;
1504   if(!(DWUP(0))) tmp_dst = scu_dst_0;
1505
1506   for (; scu_size_0 > 0; scu_size_0-=scu_dst_add_0)
1507   {
1508      if(scu_dst_add_0 == 2)
1509         space->write_word(scu_dst_0,space->read_word(scu_src_0));
1510      else if(scu_dst_add_0 == 8)
1511      {
1512         space->write_word(scu_dst_0,space->read_word(scu_src_0));
1513         space->write_word(scu_dst_0+2,space->read_word(scu_src_0));
1514         space->write_word(scu_dst_0+4,space->read_word(scu_src_0+2));
1515         space->write_word(scu_dst_0+6,space->read_word(scu_src_0+2));
1516      }
1517      else
1518      {
1519         space->write_word(scu_dst_0,space->read_word(scu_src_0));
1520         space->write_word(scu_dst_0+2,space->read_word(scu_src_0+2));
1521      }
1522
1523      scu_dst_0+=scu_dst_add_0;
1524      scu_src_0+=scu_src_add_0;
1525   }
1526
1527   scu_size_0 = tmp_size;
1528   if(!(DRUP(0))) scu_src_0 = tmp_src;
1529   if(!(DWUP(0))) scu_dst_0 = tmp_dst;
1530
1531   if(LOG_SCU) logerror("DMA transfer END\n");
1532
1533   /*TODO: timing of this*/
1534   space->machine().scheduler().timer_set(attotime::from_usec(300), FUNC(dma_lv0_ended));
1535
1536   if(scu_add_tmp & 0x80000000)
1537   {
1538      scu_dst_add_0 = (scu_add_tmp & 0xff00) >> 8;
1539      scu_src_add_0 = (scu_add_tmp & 0x00ff) >> 0;
1540      scu_add_tmp^=0x80000000;
1541   }
1542}
1543
1544static void dma_direct_lv1(address_space *space)
1545{
1546   static UINT32 tmp_src,tmp_dst,tmp_size;
1547   if(LOG_SCU) logerror("DMA lv 1 transfer START\n"
1548          "Start %08x End %08x Size %04x\n",scu_src_1,scu_dst_1,scu_size_1);
1549   if(LOG_SCU) logerror("Start Add %04x Destination Add %04x\n",scu_src_add_1,scu_dst_add_1);
1550
1551   D1MV_1;
1552
1553   if(scu_size_1 == 0) scu_size_1 = 0x00002000;
1554
1555   scsp_to_main_irq = 0;
1556
1557   /*set here the boundaries checks*/
1558   /*...*/
1559
1560   if(SOUND_RAM(dst_1))
1561   {
1562      logerror("Sound RAM DMA write\n");
1563      scsp_to_main_irq = 1;
1564   }
1565
1566   if((scu_dst_add_1 != scu_src_add_1) && (ABUS(src_1)))
1567   {
1568      logerror("A-Bus invalid transfer,sets to default\n");
1569      scu_add_tmp = (scu_dst_add_1*0x100) | (scu_src_add_1);
1570      scu_dst_add_1 = scu_src_add_1 = 4;
1571      scu_add_tmp |= 0x80000000;
1572   }
1573   /*Let me know if you encounter any of these ones*/
1574   if(ABUS(dst_1))
1575   {
1576      logerror("A-Bus invalid write\n");
1577      /*...*/
1578   }
1579   if(WORK_RAM_L(dst_1))
1580   {
1581      logerror("WorkRam-L invalid write\n");
1582      /*...*/
1583   }
1584   if(VDP1_REGS(dst_1))
1585   {
1586      logerror("VDP1 register access,must be in word units\n");
1587      scu_add_tmp = (scu_dst_add_1*0x100) | (scu_src_add_1);
1588      scu_dst_add_1 = scu_src_add_1 = 2;
1589      scu_add_tmp |= 0x80000000;
1590   }
1591   if(VDP2(src_1))
1592   {
1593      logerror("VDP-2 invalid read\n");
1594      /*...*/
1595   }
1596   if(DRUP(1))
1597   {
1598      logerror("Data read update = 1,read address add value must be 1 too\n");
1599      scu_add_tmp = (scu_dst_add_1*0x100) | (scu_src_add_1);
1600      scu_src_add_1 = 4;
1601      scu_add_tmp |= 0x80000000;
1602   }
1603
1604   if (WORK_RAM_H(dst_1) && (scu_dst_add_1 != 4))
1605   {
1606      scu_add_tmp = (scu_dst_add_1*0x100) | (scu_src_add_1);
1607      scu_src_add_1 = 4;
1608      scu_add_tmp |= 0x80000000;
1609   }
1610
1611   tmp_size = scu_size_1;
1612   if(!(DRUP(1))) tmp_src = scu_src_1;
1613   if(!(DWUP(1))) tmp_dst = scu_dst_1;
1614
1615   for (; scu_size_1 > 0; scu_size_1-=scu_dst_add_1)
1616   {
1617      if(scu_dst_add_1 == 2)
1618         space->write_word(scu_dst_1,space->read_word(scu_src_1));
1619      else
1620      {
1621         space->write_word(scu_dst_1,space->read_word(scu_src_1));
1622         space->write_word(scu_dst_1+2,space->read_word(scu_src_1+2));
1623      }
1624
1625      scu_dst_1+=scu_dst_add_1;
1626      scu_src_1+=scu_src_add_1;
1627   }
1628
1629   scu_size_1 = tmp_size;
1630   if(!(DRUP(1))) scu_src_1 = tmp_src;
1631   if(!(DWUP(1))) scu_dst_1 = tmp_dst;
1632
1633   if(LOG_SCU) logerror("DMA transfer END\n");
1634
1635   space->machine().scheduler().timer_set(attotime::from_usec(300), FUNC(dma_lv1_ended));
1636
1637   if(scu_add_tmp & 0x80000000)
1638   {
1639      scu_dst_add_1 = (scu_add_tmp & 0xff00) >> 8;
1640      scu_src_add_1 = (scu_add_tmp & 0x00ff) >> 0;
1641      scu_add_tmp^=0x80000000;
1642   }
1643}
1644
1645static void dma_direct_lv2(address_space *space)
1646{
1647   static UINT32 tmp_src,tmp_dst,tmp_size;
1648   if(LOG_SCU) logerror("DMA lv 2 transfer START\n"
1649          "Start %08x End %08x Size %04x\n",scu_src_2,scu_dst_2,scu_size_2);
1650   if(LOG_SCU) logerror("Start Add %04x Destination Add %04x\n",scu_src_add_2,scu_dst_add_2);
1651
1652   D2MV_1;
1653
1654   scsp_to_main_irq = 0;
1655
1656   if(scu_size_2 == 0) scu_size_2 = 0x00002000;
1657
1658   /*set here the boundaries checks*/
1659   /*...*/
1660
1661   if(SOUND_RAM(dst_2))
1662   {
1663      logerror("Sound RAM DMA write\n");
1664      scsp_to_main_irq = 1;
1665   }
1666
1667   if((scu_dst_add_2 != scu_src_add_2) && (ABUS(src_2)))
1668   {
1669      logerror("A-Bus invalid transfer,sets to default\n");
1670      scu_add_tmp = (scu_dst_add_2*0x100) | (scu_src_add_2);
1671      scu_dst_add_2 = scu_src_add_2 = 4;
1672      scu_add_tmp |= 0x80000000;
1673   }
1674   /*Let me know if you encounter any of these ones*/
1675   if(ABUS(dst_2))
1676   {
1677      logerror("A-Bus invalid write\n");
1678      /*...*/
1679   }
1680   if(WORK_RAM_L(dst_2))
1681   {
1682      logerror("WorkRam-L invalid write\n");
1683      /*...*/
1684   }
1685   if(VDP1_REGS(dst_2))
1686   {
1687      logerror("VDP1 register access,must be in word units\n");
1688      scu_add_tmp = (scu_dst_add_2*0x100) | (scu_src_add_2);
1689      scu_dst_add_2 = scu_src_add_2 = 2;
1690      scu_add_tmp |= 0x80000000;
1691   }
1692   if(VDP2(src_2))
1693   {
1694      logerror("VDP-2 invalid read\n");
1695      /*...*/
1696   }
1697   if(DRUP(2))
1698   {
1699      logerror("Data read update = 1,read address add value must be 1 too\n");
1700      scu_add_tmp = (scu_dst_add_2*0x100) | (scu_src_add_2);
1701      scu_src_add_2 = 4;
1702      scu_add_tmp |= 0x80000000;
1703   }
1704
1705   if (WORK_RAM_H(dst_2) && (scu_dst_add_2 != 4))
1706   {
1707      scu_add_tmp = (scu_dst_add_2*0x100) | (scu_src_add_2);
1708      scu_src_add_2 = 4;
1709      scu_add_tmp |= 0x80000000;
1710   }
1711
1712   tmp_size = scu_size_2;
1713   if(!(DRUP(2))) tmp_src = scu_src_2;
1714   if(!(DWUP(2))) tmp_dst = scu_dst_2;
1715
1716   for (; scu_size_2 > 0; scu_size_2-=scu_dst_add_2)
1717   {
1718      if(scu_dst_add_2 == 2)
1719         space->write_word(scu_dst_2,space->read_word(scu_src_2));
1720      else
1721      {
1722         space->write_word(scu_dst_2,space->read_word(scu_src_2));
1723         space->write_word(scu_dst_2+2,space->read_word(scu_src_2+2));
1724      }
1725
1726      scu_dst_2+=scu_dst_add_2;
1727      scu_src_2+=scu_src_add_2;
1728   }
1729
1730   scu_size_2 = tmp_size;
1731   if(!(DRUP(2))) scu_src_2 = tmp_src;
1732   if(!(DWUP(2))) scu_dst_2 = tmp_dst;
1733
1734   if(LOG_SCU) logerror("DMA transfer END\n");
1735
1736   space->machine().scheduler().timer_set(attotime::from_usec(300), FUNC(dma_lv2_ended));
1737
1738   if(scu_add_tmp & 0x80000000)
1739   {
1740      scu_dst_add_2 = (scu_add_tmp & 0xff00) >> 8;
1741      scu_src_add_2 = (scu_add_tmp & 0x00ff) >> 0;
1742      scu_add_tmp^=0x80000000;
1743   }
1744}
1745
1746static void dma_indirect_lv0(address_space *space)
1747{
1748   /*Helper to get out of the cycle*/
1749   UINT8 job_done = 0;
1750   /*temporary storage for the transfer data*/
1751   UINT32 tmp_src;
1752
1753   D0MV_1;
1754
1755   scsp_to_main_irq = 0;
1756
1757   if(scu_index_0 == 0) { scu_index_0 = scu_dst_0; }
1758
1759   do{
1760      tmp_src = scu_index_0;
1761
1762      /*Thanks for Runik of Saturnin for pointing this out...*/
1763      scu_size_0 = space->read_dword(scu_index_0);
1764      scu_src_0 =  space->read_dword(scu_index_0+8);
1765      scu_dst_0 =  space->read_dword(scu_index_0+4);
1766
1767      /*Indirect Mode end factor*/
1768      if(scu_src_0 & 0x80000000)
1769         job_done = 1;
1770
1771      if(SOUND_RAM(dst_0))
1772      {
1773         logerror("Sound RAM DMA write\n");
1774         scsp_to_main_irq = 1;
1775      }
1776
1777      if(LOG_SCU) logerror("DMA lv 0 indirect mode transfer START\n"
1778             "Start %08x End %08x Size %04x\n",scu_src_0,scu_dst_0,scu_size_0);
1779      if(LOG_SCU) logerror("Start Add %04x Destination Add %04x\n",scu_src_add_0,scu_dst_add_0);
1780
1781      //guess,but I believe it's right.
1782      scu_src_0 &=0x07ffffff;
1783      scu_dst_0 &=0x07ffffff;
1784      scu_size_0 &=0xfffff;
1785
1786      for (; scu_size_0 > 0; scu_size_0-=scu_dst_add_0)
1787      {
1788         if(scu_dst_add_0 == 2)
1789            space->write_word(scu_dst_0,space->read_word(scu_src_0));
1790         else
1791         {
1792            /* some games, eg columns97 are a bit weird, I'm not sure this is correct
1793                  they start a dma on a 2 byte boundary in 4 byte add mode, using the dword reads we
1794                  can't access 2 byte boundaries, and the end of the sprite list never gets marked,
1795                  the length of the transfer is also set to a 2 byte boundary, maybe the add values
1796                  should be different, I don't know */
1797            space->write_word(scu_dst_0,space->read_word(scu_src_0));
1798            space->write_word(scu_dst_0+2,space->read_word(scu_src_0+2));
1799         }
1800         scu_dst_0+=scu_dst_add_0;
1801         scu_src_0+=scu_src_add_0;
1802      }
1803
1804      //if(DRUP(0))   space->write_dword(tmp_src+8,scu_src_0|job_done ? 0x80000000 : 0);
1805      //if(DWUP(0)) space->write_dword(tmp_src+4,scu_dst_0);
1806
1807      scu_index_0 = tmp_src+0xc;
1808
1809   }while(job_done == 0);
1810
1811   space->machine().scheduler().timer_set(attotime::from_usec(300), FUNC(dma_lv0_ended));
1812}
1813
1814static void dma_indirect_lv1(address_space *space)
1815{
1816   /*Helper to get out of the cycle*/
1817   UINT8 job_done = 0;
1818   /*temporary storage for the transfer data*/
1819   UINT32 tmp_src;
1820
1821   D1MV_1;
1822
1823   scsp_to_main_irq = 0;
1824
1825   if(scu_index_1 == 0) { scu_index_1 = scu_dst_1; }
1826
1827   do{
1828      tmp_src = scu_index_1;
1829
1830      scu_size_1 = space->read_dword(scu_index_1);
1831      scu_src_1 =  space->read_dword(scu_index_1+8);
1832      scu_dst_1 =  space->read_dword(scu_index_1+4);
1833
1834      /*Indirect Mode end factor*/
1835      if(scu_src_1 & 0x80000000)
1836         job_done = 1;
1837
1838      if(SOUND_RAM(dst_1))
1839      {
1840         logerror("Sound RAM DMA write\n");
1841         scsp_to_main_irq = 1;
1842      }
1843
1844      if(LOG_SCU) logerror("DMA lv 1 indirect mode transfer START\n"
1845             "Start %08x End %08x Size %04x\n",scu_src_1,scu_dst_1,scu_size_1);
1846      if(LOG_SCU) logerror("Start Add %04x Destination Add %04x\n",scu_src_add_1,scu_dst_add_1);
1847
1848      //guess,but I believe it's right.
1849      scu_src_1 &=0x07ffffff;
1850      scu_dst_1 &=0x07ffffff;
1851      scu_size_1 &=0xffff;
1852
1853
1854      for (; scu_size_1 > 0; scu_size_1-=scu_dst_add_1)
1855      {
1856
1857         if(scu_dst_add_1 == 2)
1858            space->write_word(scu_dst_1,space->read_word(scu_src_1));
1859         else
1860         {
1861            /* some games, eg columns97 are a bit weird, I'm not sure this is correct
1862                  they start a dma on a 2 byte boundary in 4 byte add mode, using the dword reads we
1863                  can't access 2 byte boundaries, and the end of the sprite list never gets marked,
1864                  the length of the transfer is also set to a 2 byte boundary, maybe the add values
1865                  should be different, I don't know */
1866            space->write_word(scu_dst_1,space->read_word(scu_src_1));
1867            space->write_word(scu_dst_1+2,space->read_word(scu_src_1+2));
1868         }
1869         scu_dst_1+=scu_dst_add_1;
1870         scu_src_1+=scu_src_add_1;
1871      }
1872
1873      //if(DRUP(1))   space->write_dword(tmp_src+8,scu_src_1|job_done ? 0x80000000 : 0);
1874      //if(DWUP(1)) space->write_dword(tmp_src+4,scu_dst_1);
1875
1876      scu_index_1 = tmp_src+0xc;
1877
1878   }while(job_done == 0);
1879
1880   space->machine().scheduler().timer_set(attotime::from_usec(300), FUNC(dma_lv1_ended));
1881}
1882
1883static void dma_indirect_lv2(address_space *space)
1884{
1885   /*Helper to get out of the cycle*/
1886   UINT8 job_done = 0;
1887   /*temporary storage for the transfer data*/
1888   UINT32 tmp_src;
1889
1890   D2MV_1;
1891
1892   scsp_to_main_irq = 0;
1893
1894   if(scu_index_2 == 0) { scu_index_2 = scu_dst_2; }
1895
1896   do{
1897      tmp_src = scu_index_2;
1898
1899      scu_size_2 = space->read_dword(scu_index_2);
1900      scu_src_2 =  space->read_dword(scu_index_2+8);
1901      scu_dst_2 =  space->read_dword(scu_index_2+4);
1902
1903      /*Indirect Mode end factor*/
1904      if(scu_src_2 & 0x80000000)
1905         job_done = 1;
1906
1907      if(SOUND_RAM(dst_2))
1908      {
1909         logerror("Sound RAM DMA write\n");
1910         scsp_to_main_irq = 1;
1911      }
1912
1913      if(LOG_SCU) logerror("DMA lv 2 indirect mode transfer START\n"
1914             "Start %08x End %08x Size %04x\n",scu_src_2,scu_dst_2,scu_size_2);
1915      if(LOG_SCU) logerror("Start Add %04x Destination Add %04x\n",scu_src_add_2,scu_dst_add_2);
1916
1917      //guess,but I believe it's right.
1918      scu_src_2 &=0x07ffffff;
1919      scu_dst_2 &=0x07ffffff;
1920      scu_size_2 &=0xffff;
1921
1922      for (; scu_size_2 > 0; scu_size_2-=scu_dst_add_2)
1923      {
1924         if(scu_dst_add_2 == 2)
1925            space->write_word(scu_dst_2,space->read_word(scu_src_2));
1926         else
1927         {
1928            /* some games, eg columns97 are a bit weird, I'm not sure this is correct
1929                  they start a dma on a 2 byte boundary in 4 byte add mode, using the dword reads we
1930                  can't access 2 byte boundaries, and the end of the sprite list never gets marked,
1931                  the length of the transfer is also set to a 2 byte boundary, maybe the add values
1932                  should be different, I don't know */
1933            space->write_word(scu_dst_2,space->read_word(scu_src_2));
1934            space->write_word(scu_dst_2+2,space->read_word(scu_src_2+2));
1935         }
1936
1937         scu_dst_2+=scu_dst_add_2;
1938         scu_src_2+=scu_src_add_2;
1939      }
1940
1941      //if(DRUP(2))   space->write_dword(tmp_src+8,scu_src_2|job_done ? 0x80000000 : 0);
1942      //if(DWUP(2)) space->write_dword(tmp_src+4,scu_dst_2);
1943
1944      scu_index_2 = tmp_src+0xc;
1945
1946   }while(job_done == 0);
1947
1948   space->machine().scheduler().timer_set(attotime::from_usec(300), FUNC(dma_lv2_ended));
1949}
1950
1951
1952/**************************************************************************************/
1953
1954static WRITE32_HANDLER( stv_sh2_soundram_w )
1955{
1956   COMBINE_DATA(sound_ram+offset*2+1);
1957   data >>= 16;
1958   mem_mask >>= 16;
1959   COMBINE_DATA(sound_ram+offset*2);
1960}
1961
1962static READ32_HANDLER( stv_sh2_soundram_r )
1963{
1964   return (sound_ram[offset*2]<<16)|sound_ram[offset*2+1];
1965}
1966
1967/* communication,SLAVE CPU acquires data from the MASTER CPU and triggers an irq.  *
1968 * Enter into Radiant Silver Gun specific menu for a test...                       */
1969static WRITE32_HANDLER( minit_w )
1970{
1971   logerror("cpu %s (PC=%08X) MINIT write = %08x\n", space->device().tag(), cpu_get_pc(&space->device()),data);
1972   space->machine().scheduler().boost_interleave(minit_boost_timeslice, attotime::from_usec(minit_boost));
1973   space->machine().scheduler().trigger(1000);
1974   sh2_set_frt_input(space->machine().device("slave"), PULSE_LINE);
1975}
1976
1977static WRITE32_HANDLER( sinit_w )
1978{
1979   logerror("cpu %s (PC=%08X) SINIT write = %08x\n", space->device().tag(), cpu_get_pc(&space->device()),data);
1980   space->machine().scheduler().boost_interleave(sinit_boost_timeslice, attotime::from_usec(sinit_boost));
1981   sh2_set_frt_input(space->machine().device("maincpu"), PULSE_LINE);
1982}
1983
1984
1985#ifdef UNUSED_FUNCTION
1986static READ32_HANDLER( stv_sh2_random_r )
1987{
1988   return 0xffffffff;
1989}
1990#endif
1991
1992static ADDRESS_MAP_START( stv_mem, AS_PROGRAM, 32 )
1993   AM_RANGE(0x00000000, 0x0007ffff) AM_ROM AM_SHARE("share6")  // bios
1994   AM_RANGE(0x00100000, 0x0010007f) AM_READWRITE(stv_SMPC_r32, stv_SMPC_w32)
1995   AM_RANGE(0x00180000, 0x0018ffff) AM_RAM AM_SHARE("share1") AM_BASE(&stv_backupram)
1996   AM_RANGE(0x00200000, 0x002fffff) AM_RAM AM_MIRROR(0x100000) AM_SHARE("share2") AM_BASE(&stv_workram_l)
1997   AM_RANGE(0x00400000, 0x0040001f) AM_READWRITE(stv_io_r32, stv_io_w32) AM_BASE(&ioga) AM_SHARE("share4") AM_MIRROR(0x20)
1998   AM_RANGE(0x01000000, 0x01000003) AM_WRITE(minit_w)
1999   AM_RANGE(0x01406f40, 0x01406f43) AM_WRITE(minit_w) // prikura seems to write here ..
2000//  AM_RANGE(0x01000000, 0x01000003) AM_WRITE(minit_w) AM_MIRROR(0x00080000)
2001   AM_RANGE(0x01800000, 0x01800003) AM_WRITE(sinit_w)
2002   AM_RANGE(0x02000000, 0x04ffffff) AM_ROM AM_SHARE("share7") AM_REGION("user1", 0) // cartridge
2003   AM_RANGE(0x05800000, 0x0589ffff) AM_READWRITE(stvcd_r, stvcd_w)
2004   /* Sound */
2005   AM_RANGE(0x05a00000, 0x05afffff) AM_READWRITE(stv_sh2_soundram_r, stv_sh2_soundram_w)
2006   //AM_RANGE(0x05a80000, 0x05afffff) AM_READ(stv_sh2_random_r)
2007   AM_RANGE(0x05b00000, 0x05b00fff) AM_DEVREADWRITE16("scsp", scsp_r, scsp_w, 0xffffffff)
2008   /* VDP1 */
2009   AM_RANGE(0x05c00000, 0x05c7ffff) AM_READWRITE(stv_vdp1_vram_r, stv_vdp1_vram_w)
2010   AM_RANGE(0x05c80000, 0x05cbffff) AM_READWRITE(stv_vdp1_framebuffer0_r, stv_vdp1_framebuffer0_w)
2011   AM_RANGE(0x05d00000, 0x05d0001f) AM_READWRITE(stv_vdp1_regs_r, stv_vdp1_regs_w)
2012   AM_RANGE(0x05e00000, 0x05efffff) AM_READWRITE(stv_vdp2_vram_r, stv_vdp2_vram_w)
2013   AM_RANGE(0x05f00000, 0x05f7ffff) AM_READWRITE(stv_vdp2_cram_r, stv_vdp2_cram_w)
2014   AM_RANGE(0x05f80000, 0x05fbffff) AM_READWRITE(stv_vdp2_regs_r, stv_vdp2_regs_w)
2015   AM_RANGE(0x05fe0000, 0x05fe00cf) AM_READWRITE(stv_scu_r32, stv_scu_w32)
2016   AM_RANGE(0x06000000, 0x060fffff) AM_RAM AM_MIRROR(0x01f00000) AM_SHARE("share3") AM_BASE(&stv_workram_h)
2017   AM_RANGE(0x20000000, 0x2007ffff) AM_ROM AM_SHARE("share6")  // bios mirror
2018   AM_RANGE(0x22000000, 0x24ffffff) AM_ROM AM_SHARE("share7")  // cart mirror
2019ADDRESS_MAP_END
2020
2021static ADDRESS_MAP_START( sound_mem, AS_PROGRAM, 16 )
2022   AM_RANGE(0x000000, 0x0fffff) AM_RAM AM_BASE(&sound_ram)
2023   AM_RANGE(0x100000, 0x100fff) AM_DEVREADWRITE("scsp", scsp_r, scsp_w)
2024ADDRESS_MAP_END
2025
2026#define STV_PLAYER_INPUTS(_n_, _b1_, _b2_, _b3_)                     \
2027   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_##_b1_ ) PORT_PLAYER(_n_)         \
2028   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_##_b2_ ) PORT_PLAYER(_n_)         \
2029   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_##_b3_ ) PORT_PLAYER(_n_)         \
2030   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )                     \
2031   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(_n_)      \
2032   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(_n_)      \
2033   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(_n_)   \
2034   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(_n_)
2035
2036static INPUT_PORTS_START( stv )
2037   PORT_START("DSW1")
2038   PORT_DIPNAME( 0x01, 0x01, "PDR1" )
2039   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
2040   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2041   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
2042   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
2043   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2044   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
2045   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
2046   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2047   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
2048   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
2049   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2050   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
2051   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
2052   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2053   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
2054   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
2055   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2056   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
2057   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
2058   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2059   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
2060   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
2061   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2062
2063   PORT_START("DSW2")
2064   PORT_DIPNAME( 0x01, 0x01, "PDR2" )
2065   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
2066   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2067   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
2068   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
2069   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2070   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
2071   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
2072   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2073   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
2074   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
2075   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2076   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
2077   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
2078   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2079   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
2080   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
2081   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2082   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
2083   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
2084   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2085   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
2086   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
2087   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2088
2089   PORT_START("P1")
2090   STV_PLAYER_INPUTS(1, BUTTON1, BUTTON2, BUTTON3)
2091
2092   PORT_START("P2")
2093   STV_PLAYER_INPUTS(2, BUTTON1, BUTTON2, BUTTON3)
2094/*
2095    PORT_START("P3")
2096    STV_PLAYER_INPUTS(3, BUTTON1, BUTTON2, BUTTON3)
2097
2098    PORT_START("P4")
2099    STV_PLAYER_INPUTS(4, BUTTON1, BUTTON2, BUTTON3)
2100*/
2101
2102   PORT_START("SYSTEM")
2103   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
2104   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )
2105   PORT_SERVICE_NO_TOGGLE( 0x04, IP_ACTIVE_LOW )
2106   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_SERVICE1 )
2107   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_START1 )
2108   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START2 )
2109   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("1P Push Switch") PORT_CODE(KEYCODE_7)
2110   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("2P Push Switch") PORT_CODE(KEYCODE_8)
2111
2112   /* This *might* be unused... */
2113   PORT_START("UNUSED")
2114   PORT_BIT ( 0xff, IP_ACTIVE_LOW, IPT_UNUSED )
2115
2116   /* Extra button layout, used by Power Instinct 3, Suikoenbu, Elan Doree, Golden Axe Duel & Astra SuperStars */
2117   PORT_START("EXTRA")
2118   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1)
2119   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(1)
2120   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(1)
2121   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2122   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2)
2123   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(2)
2124   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(2)
2125   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
2126
2127   /* We don't need these, AFAIK the country code doesn't work either... */
2128   #if 0
2129   PORT_START("FAKE")   //7
2130   PORT_DIPNAME( 0x0f, 0x01, "Country" )
2131   PORT_DIPSETTING(    0x01, DEF_STR( Japan ) )
2132   PORT_DIPSETTING(    0x02, "Asia Ntsc" )
2133   PORT_DIPSETTING(    0x04, DEF_STR( USA ) )
2134   PORT_DIPSETTING(    0x08, "Sud America Ntsc" )
2135   PORT_DIPSETTING(    0x06, "Korea" )
2136   PORT_DIPSETTING(    0x0a, "Asia Pal" )
2137   PORT_DIPSETTING(    0x0c, "Europe/Other Pal" )
2138   PORT_DIPSETTING(    0x0d, "Sud America Pal" )
2139
2140   PORT_START("PAD1A")   /* Pad data 1a */
2141   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("B") PORT_CODE(KEYCODE_U)
2142   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("C") PORT_CODE(KEYCODE_Y)
2143   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("A") PORT_CODE(KEYCODE_T)
2144   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Start") PORT_CODE(KEYCODE_O)
2145   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Up") PORT_CODE(KEYCODE_I)
2146   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Down") PORT_CODE(KEYCODE_K)
2147   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Left") PORT_CODE(KEYCODE_J)
2148   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Right") PORT_CODE(KEYCODE_L)
2149
2150   PORT_START("PAD1B")   /* Pad data 1b */
2151   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("L trig") PORT_CODE(KEYCODE_A)
2152   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Z") PORT_CODE(KEYCODE_Q)
2153   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Y") PORT_CODE(KEYCODE_W)
2154   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("X") PORT_CODE(KEYCODE_E)
2155   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("R trig") PORT_CODE(KEYCODE_S)
2156   #endif
2157
2158   PORT_START("UNKNOWN")
2159   PORT_DIPNAME( 0x01, 0x01, "UNK" )
2160   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
2161   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2162   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
2163   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
2164   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2165   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
2166   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
2167   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2168   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
2169   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
2170   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2171   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
2172   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
2173   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2174   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
2175   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
2176   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2177   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
2178   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
2179   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2180   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
2181   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
2182   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2183INPUT_PORTS_END
2184
2185static INPUT_PORTS_START( critcrsh )
2186   PORT_INCLUDE( stv )
2187
2188   /* IN 7 */
2189   PORT_START("LIGHTX") /* mask default type                     sens delta min max */
2190   PORT_BIT( 0x3f, 0x00, IPT_LIGHTGUN_X ) PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_MINMAX(0,0x3f) PORT_SENSITIVITY(50) PORT_KEYDELTA(1) PORT_PLAYER(1)
2191
2192   /* IN 8 */
2193   PORT_START("LIGHTY")
2194   PORT_BIT( 0x3f, 0x00, IPT_LIGHTGUN_Y ) PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_MINMAX(0x0,0x3f) PORT_SENSITIVITY(50) PORT_KEYDELTA(1) PORT_PLAYER(1)
2195INPUT_PORTS_END
2196
2197static INPUT_PORTS_START( batmanfr )
2198   PORT_INCLUDE( stv )
2199
2200   PORT_MODIFY("P1")
2201   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1)
2202
2203   PORT_MODIFY("P2")
2204   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2)
2205
2206   PORT_MODIFY("EXTRA")
2207   PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNUSED )
2208INPUT_PORTS_END
2209
2210/* Same as the regular one, but with an additional & optional mahjong panel */
2211static INPUT_PORTS_START( stvmp )
2212   PORT_INCLUDE( stv )
2213
2214   /* Mahjong panel/player 1 side */
2215   PORT_START("KEY0")   /*7*/
2216   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_MAHJONG_KAN )
2217   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START1 )
2218   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2219   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2220   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_MAHJONG_E )
2221   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_MAHJONG_A )
2222   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_M )
2223   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_MAHJONG_I )
2224
2225   PORT_START("KEY1")   /*8*/
2226   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_MAHJONG_RON )
2227   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
2228   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2229   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2230   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_MAHJONG_F )
2231   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_MAHJONG_B )
2232   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_N )
2233   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_MAHJONG_J )
2234
2235   PORT_START("KEY2")   /*9*/
2236   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_MAHJONG_REACH )
2237   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
2238   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2239   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2240   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_MAHJONG_G )
2241   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_MAHJONG_C )
2242   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_CHI )
2243   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_MAHJONG_K )
2244
2245   PORT_START("KEY3")   /*10*/
2246   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
2247   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
2248   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2249   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2250   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_MAHJONG_H )
2251   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_MAHJONG_D )
2252   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_PON )
2253   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_MAHJONG_L )
2254
2255   PORT_START("KEY4")   /*11*/
2256   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
2257   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
2258   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2259   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2260   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNUSED )
2261   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
2262   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_FLIP_FLOP )
2263   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
2264
2265   /* Mahjong panel/player 2 side */
2266   PORT_START("KEY5")   /*12*/
2267   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_MAHJONG_KAN ) PORT_PLAYER(2)
2268   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START2 )
2269   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2270   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2271   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_MAHJONG_E ) PORT_PLAYER(2)
2272   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_MAHJONG_A ) PORT_PLAYER(2)
2273   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_M ) PORT_PLAYER(2)
2274   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_MAHJONG_I ) PORT_PLAYER(2)
2275
2276   PORT_START("KEY6")   /*13*/
2277   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_MAHJONG_RON ) PORT_PLAYER(2)
2278   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
2279   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2280   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2281   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_MAHJONG_F ) PORT_PLAYER(2)
2282   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_MAHJONG_B ) PORT_PLAYER(2)
2283   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_N ) PORT_PLAYER(2)
2284   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_MAHJONG_J ) PORT_PLAYER(2)
2285
2286   PORT_START("KEY7")   /*14*/
2287   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_MAHJONG_REACH ) PORT_PLAYER(2)
2288   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
2289   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2290   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2291   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_MAHJONG_G ) PORT_PLAYER(2)
2292   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_MAHJONG_C ) PORT_PLAYER(2)
2293   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_CHI ) PORT_PLAYER(2)
2294   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_MAHJONG_K ) PORT_PLAYER(2)
2295
2296   PORT_START("KEY8")   /*15*/
2297   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
2298   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
2299   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2300   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2301   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_MAHJONG_H ) PORT_PLAYER(2)
2302   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_MAHJONG_D ) PORT_PLAYER(2)
2303   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_PON ) PORT_PLAYER(2)
2304   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_MAHJONG_L ) PORT_PLAYER(2)
2305
2306   PORT_START("KEY9")   /*16*/
2307   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
2308   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
2309   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2310   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2311   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNUSED )
2312   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
2313   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_FLIP_FLOP ) PORT_PLAYER(2)
2314   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
2315INPUT_PORTS_END
2316
2317static WRITE32_HANDLER ( w60ffc44_write )
2318{
2319   COMBINE_DATA(&stv_workram_h[0xffc44/4]);
2320
2321   logerror("cpu %s (PC=%08X): 60ffc44_write write = %08X & %08X\n", space->device().tag(), cpu_get_pc(&space->device()), data, mem_mask);
2322   //sinit_w(offset,data,mem_mask);
2323}
2324
2325static WRITE32_HANDLER ( w60ffc48_write )
2326{
2327   COMBINE_DATA(&stv_workram_h[0xffc48/4]);
2328
2329   logerror("cpu %s (PC=%08X): 60ffc48_write write = %08X & %08X\n", space->device().tag(), cpu_get_pc(&space->device()), data, mem_mask);
2330   //minit_w(offset,data,mem_mask);
2331}
2332
2333#ifdef UNUSED_FUNCTION
2334static void print_game_info(void);
2335#endif
2336
2337DRIVER_INIT ( stv )
2338{
2339   system_time systime;
2340
2341   machine.base_datetime(systime);
2342
2343   /* amount of time to boost interleave for on MINIT / SINIT, needed for communication to work */
2344   minit_boost = 400;
2345   sinit_boost = 400;
2346   minit_boost_timeslice = attotime::zero;
2347   sinit_boost_timeslice = attotime::zero;
2348
2349   smpc_ram = auto_alloc_array(machine, UINT8, 0x80);
2350   stv_scu = auto_alloc_array(machine, UINT32, 0x100/4);
2351   scsp_regs = auto_alloc_array(machine, UINT16, 0x1000/2);
2352
2353   install_stvbios_speedups(machine);
2354
2355   // do strict overwrite verification - maruchan and rsgun crash after coinup without this.
2356   // cottonbm needs strict PCREL
2357   // todo: test what games need this and don't turn it on for them...
2358   sh2drc_set_options(machine.device("maincpu"), SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
2359   sh2drc_set_options(machine.device("slave"), SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
2360
2361   /* debug .. watch the command buffer rsgun, cottonbm etc. appear to use to communicate between cpus */
2362   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x60ffc44, 0x60ffc47, FUNC(w60ffc44_write) );
2363   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x60ffc48, 0x60ffc4b, FUNC(w60ffc48_write) );
2364   machine.device("slave")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x60ffc44, 0x60ffc47, FUNC(w60ffc44_write) );
2365   machine.device("slave")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x60ffc48, 0x60ffc4b, FUNC(w60ffc48_write) );
2366
2367    smpc_ram[0x31] = 0x00; //CTG1=0 CTG0=0 (correct??)
2368//  smpc_ram[0x33] = input_port_read(machine, "FAKE");
2369   smpc_ram[0x5f] = 0x10;
2370
2371   #ifdef MAME_DEBUG
2372   /*Uncomment this to enable header info*/
2373   //print_game_info();
2374   #endif
2375}
2376
2377#define DATA_TRANSFER(_max_) \
2378   for(dst_i=0;dst_i<_max_;dst_i++,src_i++)   \
2379      STR[(dst_i & 0xfc) | (~dst_i & 3)] = ROM[src_i];
2380
2381#define DATA_DELETE \
2382   for(dst_i=0;dst_i<0x100;dst_i++) \
2383      STR[dst_i] = 0x00;
2384
2385#ifdef UNUSED_FUNCTION
2386static void print_game_info(void)
2387{
2388   UINT8 *ROM = machine.region("user1")->base();
2389   static FILE *print_file = NULL;
2390   UINT8 STR[0x100];
2391   UINT32 src_i,dst_i;
2392
2393   if(print_file == NULL)
2394      print_file = fopen( "stvinfo.txt", "a" );
2395
2396   src_i = 0;
2397
2398   /*IC13?*/
2399   if(ROM[src_i] == 0x00)
2400      src_i+=0x200000;
2401
2402   DATA_TRANSFER(0x100);
2403   for(src_i=0;src_i<0x100;src_i++)
2404   {
2405      if((src_i % 0x10) == 0) fprintf( print_file, "\n");
2406      if(src_i < 0xc0)      fprintf( print_file, "%c",STR[src_i] );
2407      else                    fprintf( print_file, "%02x",STR[src_i] );
2408   }
2409   DATA_DELETE;
2410
2411   fclose(print_file);
2412   print_file = NULL;
2413}
2414#endif
2415
2416static const gfx_layout tiles8x8x4_layout =
2417{
2418   8,8,
2419   0x100000/(32*8/8),
2420   4,
2421   { 0, 1, 2, 3 },
2422   { 0, 4, 8, 12, 16, 20, 24, 28 },
2423   { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 },
2424   32*8
2425};
2426
2427static const gfx_layout tiles16x16x4_layout =
2428{
2429   16,16,
2430   0x100000/(32*32/8),
2431   4,
2432   { 0, 1, 2, 3 },
2433   { 0, 4, 8, 12, 16, 20, 24, 28,
2434     32*8+0, 32*8+4, 32*8+8, 32*8+12, 32*8+16, 32*8+20, 32*8+24, 32*8+28,
2435
2436     },
2437   { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32,
2438     32*16, 32*17,32*18, 32*19,32*20,32*21,32*22,32*23
2439
2440     },
2441   32*32
2442};
2443
2444static const gfx_layout tiles8x8x8_layout =
2445{
2446   8,8,
2447   0x100000/(32*8/8),
2448   8,
2449   { 0, 1, 2, 3, 4, 5, 6, 7 },
2450   { 0, 8, 16, 24, 32, 40, 48, 56 },
2451   { 0*64, 1*64, 2*64, 3*64, 4*64, 5*64, 6*64, 7*64 },
2452   32*8   /* really 64*8, but granularity is 32 bytes */
2453};
2454
2455static const gfx_layout tiles16x16x8_layout =
2456{
2457   16,16,
2458   0x100000/(64*16/8),
2459   8,
2460   { 0, 1, 2, 3, 4, 5, 6, 7 },
2461   { 0, 8, 16, 24, 32, 40, 48, 56,
2462   64*8+0, 65*8, 66*8, 67*8, 68*8, 69*8, 70*8, 71*8
2463
2464   },
2465   { 0*64, 1*64, 2*64, 3*64, 4*64, 5*64, 6*64, 7*64,
2466   64*16, 64*17, 64*18, 64*19, 64*20, 64*21, 64*22, 64*23
2467   },
2468   64*16   /* really 128*16, but granularity is 32 bytes */
2469};
2470
2471
2472
2473
2474static GFXDECODE_START( stv )
2475   GFXDECODE_ENTRY( NULL, 0, tiles8x8x4_layout,   0x00, (0x80*(2+1))  )
2476   GFXDECODE_ENTRY( NULL, 0, tiles16x16x4_layout, 0x00, (0x80*(2+1))  )
2477   GFXDECODE_ENTRY( NULL, 0, tiles8x8x8_layout,   0x00, (0x08*(2+1))  )
2478   GFXDECODE_ENTRY( NULL, 0, tiles16x16x8_layout, 0x00, (0x08*(2+1))  )
2479
2480   /* vdp1 .. pointless for drawing but can help us debug */
2481   GFXDECODE_ENTRY( NULL, 0, tiles8x8x4_layout,   0x00, 0x100  )
2482   GFXDECODE_ENTRY( NULL, 0, tiles16x16x4_layout, 0x00, 0x100  )
2483   GFXDECODE_ENTRY( NULL, 0, tiles8x8x8_layout,   0x00, 0x20  )
2484   GFXDECODE_ENTRY( NULL, 0, tiles16x16x8_layout, 0x00, 0x20  )
2485
2486GFXDECODE_END
2487
2488static const sh2_cpu_core sh2_conf_master = { 0, NULL };
2489static const sh2_cpu_core sh2_conf_slave  = { 1, NULL };
2490
2491static int scsp_last_line = 0;
2492
2493static void scsp_irq(device_t *device, int irq)
2494{
2495   // don't bother the 68k if it's off
2496   if (!en_68k)
2497   {
2498      return;
2499   }
2500
2501   if (irq > 0)
2502   {
2503      scsp_last_line = irq;
2504      cputag_set_input_line(device->machine(), "audiocpu", irq, ASSERT_LINE);
2505   }
2506   else if (irq < 0)
2507   {
2508      cputag_set_input_line(device->machine(), "audiocpu", -irq, CLEAR_LINE);
2509   }
2510   else
2511   {
2512      cputag_set_input_line(device->machine(), "audiocpu", scsp_last_line, CLEAR_LINE);
2513   }
2514}
2515
2516static const scsp_interface scsp_config =
2517{
2518   0,
2519   scsp_irq
2520};
2521
2522static TIMER_CALLBACK(stv_rtc_increment)
2523{
2524   static const UINT8 dpm[12] = { 0x31, 0x28, 0x31, 0x30, 0x31, 0x30, 0x31, 0x31, 0x30, 0x31, 0x30, 0x31 };
2525   static int year_num, year_count;
2526
2527   /*
2528        smpc_ram[0x23] = DectoBCD(systime.local_time.year /100);
2529        smpc_ram[0x25] = DectoBCD(systime.local_time.year %100);
2530        smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month+1);
2531        smpc_ram[0x29] = DectoBCD(systime.local_time.mday);
2532        smpc_ram[0x2b] = DectoBCD(systime.local_time.hour);
2533        smpc_ram[0x2d] = DectoBCD(systime.local_time.minute);
2534        smpc_ram[0x2f] = DectoBCD(systime.local_time.second);
2535    */
2536
2537   smpc_ram[0x2f]++;
2538
2539   /* seconds from 9 -> 10*/
2540   if((smpc_ram[0x2f] & 0x0f) >= 0x0a)          { smpc_ram[0x2f]+=0x10; smpc_ram[0x2f]&=0xf0; }
2541   /* seconds from 59 -> 0 */
2542   if((smpc_ram[0x2f] & 0xf0) >= 0x60)          { smpc_ram[0x2d]++;     smpc_ram[0x2f] = 0; }
2543   /* minutes from 9 -> 10 */
2544   if((smpc_ram[0x2d] & 0x0f) >= 0x0a)          { smpc_ram[0x2d]+=0x10; smpc_ram[0x2d]&=0xf0; }
2545   /* minutes from 59 -> 0 */
2546   if((smpc_ram[0x2d] & 0xf0) >= 0x60)          { smpc_ram[0x2b]++;     smpc_ram[0x2d] = 0; }
2547   /* hours from 9 -> 10 */
2548   if((smpc_ram[0x2b] & 0x0f) >= 0x0a)          { smpc_ram[0x2b]+=0x10; smpc_ram[0x2b]&=0xf0; }
2549   /* hours from 23 -> 0 */
2550   if((smpc_ram[0x2b] & 0xff) >= 0x24)            { smpc_ram[0x29]++; smpc_ram[0x27]+=0x10; smpc_ram[0x2b] = 0; }
2551   /* week day name sunday -> monday */
2552   if((smpc_ram[0x27] & 0xf0) >= 0x70)            { smpc_ram[0x27]&=0x0f; }
2553   /* day number 9 -> 10 */
2554   if((smpc_ram[0x29] & 0x0f) >= 0x0a)            { smpc_ram[0x29]+=0x10; smpc_ram[0x29]&=0xf0; }
2555
2556   // year BCD to dec conversion (for the leap year stuff)
2557   {
2558      year_num = (smpc_ram[0x25] & 0xf);
2559
2560      for(year_count = 0; year_count < (smpc_ram[0x25] & 0xf0); year_count += 0x10)
2561         year_num += 0xa;
2562
2563      year_num += (smpc_ram[0x23] & 0xf)*0x64;
2564
2565      for(year_count = 0; year_count < (smpc_ram[0x23] & 0xf0); year_count += 0x10)
2566         year_num += 0x3e8;
2567   }
2568
2569   /* month +1 check */
2570   /* the RTC have a range of 1980 - 2100, so we don't actually need to support the leap year special conditions */
2571   if(((year_num % 4) == 0) && (smpc_ram[0x27] & 0xf) == 2)
2572   {
2573      if((smpc_ram[0x29] & 0xff) >= dpm[(smpc_ram[0x27] & 0xf)-1]+1+1)
2574         { smpc_ram[0x27]++; smpc_ram[0x29] = 0x01; }
2575   }
2576   else if((smpc_ram[0x29] & 0xff) >= dpm[(smpc_ram[0x27] & 0xf)-1]+1){ smpc_ram[0x27]++; smpc_ram[0x29] = 0x01; }
2577   /* year +1 check */
2578   if((smpc_ram[0x27] & 0x0f) > 12)            { smpc_ram[0x25]++;  smpc_ram[0x27] = (smpc_ram[0x27] & 0xf0) | 0x01; }
2579   /* year from 9 -> 10 */
2580   if((smpc_ram[0x25] & 0x0f) >= 0x0a)            { smpc_ram[0x25]+=0x10; smpc_ram[0x25]&=0xf0; }
2581   /* year from 99 -> 100 */
2582   if((smpc_ram[0x25] & 0xf0) >= 0xa0)            { smpc_ram[0x23]++; smpc_ram[0x25] = 0; }
2583
2584   // probably not SO precise, here just for reference ...
2585   /* year from 999 -> 1000 */
2586   //if((smpc_ram[0x23] & 0x0f) >= 0x0a)               { smpc_ram[0x23]+=0x10; smpc_ram[0x23]&=0xf0; }
2587   /* year from 9999 -> 0 */
2588   //if((smpc_ram[0x23] & 0xf0) >= 0xa0)               { smpc_ram[0x23] = 0; } //roll over
2589}
2590
2591static MACHINE_START( stv )
2592{
2593   system_time systime;
2594   machine.base_datetime(systime);
2595
2596   stv_maincpu = machine.device<cpu_device>("maincpu");
2597   stv_slave = machine.device<cpu_device>("slave");
2598   stv_audiocpu = machine.device<cpu_device>("audiocpu");
2599
2600   scsp_set_ram_base(machine.device("scsp"), sound_ram);
2601
2602   // save states
2603   state_save_register_global_pointer(machine, smpc_ram, 0x80);
2604   state_save_register_global_pointer(machine, stv_scu, 0x100/4);
2605   state_save_register_global_pointer(machine, scsp_regs, 0x1000/2);
2606//  state_save_register_global(machine, stv_vblank);
2607//  state_save_register_global(machine, stv_hblank);
2608   state_save_register_global(machine, stv_enable_slave_sh2);
2609   state_save_register_global(machine, NMI_reset);
2610   state_save_register_global(machine, en_68k);
2611   state_save_register_global(machine, timer_0);
2612   state_save_register_global(machine, timer_1);
2613//  state_save_register_global(machine, scanline);
2614   state_save_register_global(machine, IOSEL1);
2615   state_save_register_global(machine, IOSEL2);
2616   state_save_register_global(machine, EXLE1);
2617   state_save_register_global(machine, EXLE2);
2618   state_save_register_global(machine, PDR1);
2619   state_save_register_global(machine, PDR2);
2620   state_save_register_global(machine, port_sel);
2621   state_save_register_global(machine, mux_data);
2622   state_save_register_global(machine, scsp_last_line);
2623
2624   stv_register_protection_savestates(machine); // machine/stvprot.c
2625
2626   machine.add_notifier(MACHINE_NOTIFY_EXIT, stvcd_exit);
2627
2628   smpc_ram[0x23] = DectoBCD(systime.local_time.year /100);
2629    smpc_ram[0x25] = DectoBCD(systime.local_time.year %100);
2630    smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month+1);
2631    smpc_ram[0x29] = DectoBCD(systime.local_time.mday);
2632    smpc_ram[0x2b] = DectoBCD(systime.local_time.hour);
2633    smpc_ram[0x2d] = DectoBCD(systime.local_time.minute);
2634    smpc_ram[0x2f] = DectoBCD(systime.local_time.second);
2635
2636   stv_rtc_timer = machine.scheduler().timer_alloc(FUNC(stv_rtc_increment));
2637}
2638
2639/*
2640(Preliminary) explaination about this:
2641VBLANK-OUT is used at the start of the vblank period.It also sets the timer zero
2642variable to 0.
2643If the Timer Compare register is zero too,the Timer 0 irq is triggered.
2644
2645HBLANK-IN is used at the end of each scanline except when in VBLANK-IN/OUT periods.
2646
2647The timer 0 is also incremented by one at each HBLANK and checked with the value
2648of the Timer Compare register;if equal,the timer 0 irq is triggered here too.
2649Notice that the timer 0 compare register can be more than the VBLANK maximum range,in
2650this case the timer 0 irq is simply never triggered.This is a known Sega Saturn/ST-V "bug".
2651
2652VBLANK-IN is used at the end of the vblank period.
2653
2654SCU register[36] is the timer zero compare register.
2655SCU register[40] is for IRQ masking.
2656*/
2657
2658#ifdef UNUSED_FUNCTION
2659
2660/* theoretical function about how this irq system should work, not yet implemented because the performance speed hits very very badly.
2661   It's not tested much either, but I'm aware that timer 1 doesn't work with this for whatever reason ... */
2662static TIMER_CALLBACK( stv_irq_callback )
2663{
2664   int hpos = machine.primary_screen->hpos();
2665   int vpos = machine.primary_screen->vpos();
2666   rectangle visarea = *machine.primary_screen->visible_area();
2667
2668   h_sync = visarea.max_x+1;//horz
2669   v_sync = visarea.max_y+1;//vert
2670
2671   if(vpos == v_sync && hpos == 0)
2672      VBLANK_IN_IRQ;
2673   if(hpos == 0 && vpos == 0)
2674      VBLANK_OUT_IRQ(timer->machine());
2675   if(hpos == h_sync)
2676      TIMER_0_IRQ(timer->machine());
2677   if(hpos == h_sync && (vpos != 0 && vpos != v_sync))
2678   {
2679      HBLANK_IN_IRQ(timer->machine());
2680      timer_0++;
2681   }
2682
2683   /*TODO: timing of this one (related to the VDP1 speed)*/
2684   /*      (NOTE: value shouldn't be at h_sync/v_sync position (will break shienryu))*/
2685   if(hpos == 40 && vpos == 0)
2686      VDP1_IRQ;
2687
2688   if(hpos == timer_1)
2689      TIMER_1_IRQ(timer->machine());
2690
2691   if(hpos <= h_sync)
2692      scan_timer->adjust(machine.primary_screen->time_until_pos(vpos, hpos+1));
2693   else if(vpos <= v_sync)
2694      scan_timer->adjust(machine.primary_screen->time_until_pos(vpos+1));
2695   else
2696      scan_timer->adjust(machine.primary_screen->time_until_pos(0));
2697}
2698
2699#endif
2700
2701
2702static timer_device *vblank_out_timer,*scan_timer,*t1_timer;
2703static int h_sync,v_sync;
2704static int cur_scan;
2705
2706#define VBLANK_OUT_IRQ(m)   \
2707timer_0 = 0; \
2708{ \
2709   /*if(LOG_IRQ) logerror ("Interrupt: VBlank-OUT Vector 0x41 Level 0x0e\n");*/ \
2710   cputag_set_input_line_and_vector(m, "maincpu", 0xe, (stv_irq.vblank_out) ? HOLD_LINE : CLEAR_LINE , 0x41); \
2711} \
2712
2713#define VBLANK_IN_IRQ \
2714{ \
2715   /*if(LOG_IRQ) logerror ("Interrupt: VBlank IN Vector 0x40 Level 0x0f\n");*/ \
2716   cputag_set_input_line_and_vector(device->machine(), "maincpu", 0xf, (stv_irq.vblank_in) ? HOLD_LINE : CLEAR_LINE , 0x40); \
2717} \
2718
2719#define HBLANK_IN_IRQ(m) \
2720timer_1 = stv_scu[37] & 0x1ff; \
2721{ \
2722   /*if(LOG_IRQ) logerror ("Interrupt: HBlank-In at scanline %04x, Vector 0x42 Level 0x0d\n",scanline);*/ \
2723   cputag_set_input_line_and_vector(m, "maincpu", 0xd, (stv_irq.hblank_in) ? HOLD_LINE : CLEAR_LINE, 0x42); \
2724} \
2725
2726#define TIMER_0_IRQ(m) \
2727if(timer_0 == (stv_scu[36] & 0x3ff)) \
2728{ \
2729   /*if(LOG_IRQ) logerror ("Interrupt: Timer 0 at scanline %04x, Vector 0x43 Level 0x0c\n",scanline);*/ \
2730   cputag_set_input_line_and_vector(m, "maincpu", 0xc, (stv_irq.timer_0) ? HOLD_LINE : CLEAR_LINE, 0x43 ); \
2731} \
2732
2733#define TIMER_1_IRQ(m)   \
2734if((stv_scu[38] & 1)) \
2735{ \
2736   if(!(stv_scu[38] & 0x80)) \
2737   { \
2738      /*if(LOG_IRQ) logerror ("Interrupt: Timer 1 at point %04x, Vector 0x44 Level 0x0b\n",point);*/ \
2739      cputag_set_input_line_and_vector(m, "maincpu", 0xb, (stv_irq.timer_1) ? HOLD_LINE : CLEAR_LINE, 0x44 ); \
2740   } \
2741   else \
2742   { \
2743      if((timer_0) == (stv_scu[36] & 0x3ff)) \
2744      { \
2745         /*if(LOG_IRQ) logerror ("Interrupt: Timer 1 at point %04x, Vector 0x44 Level 0x0b\n",point);*/ \
2746         cputag_set_input_line_and_vector(m, "maincpu", 0xb, (stv_irq.timer_1) ? HOLD_LINE : CLEAR_LINE, 0x44 ); \
2747      } \
2748   } \
2749} \
2750
2751#define VDP1_IRQ \
2752{ \
2753   cputag_set_input_line_and_vector(machine, "maincpu", 2, (stv_irq.vdp1_end) ? HOLD_LINE : CLEAR_LINE, 0x4d); \
2754} \
2755
2756static TIMER_DEVICE_CALLBACK( hblank_in_irq )
2757{
2758   int scanline = param;
2759
2760//  h = timer.machine().primary_screen->height();
2761//  w = timer.machine().primary_screen->width();
2762
2763   HBLANK_IN_IRQ(timer.machine());
2764   TIMER_0_IRQ(timer.machine());
2765
2766   if(scanline+1 < v_sync)
2767   {
2768      if(stv_irq.hblank_in || stv_irq.timer_0)
2769         scan_timer->adjust(timer.machine().primary_screen->time_until_pos(scanline+1, h_sync), scanline+1);
2770      /*set the first Timer-1 event*/
2771      cur_scan = scanline+1;
2772      if(stv_irq.timer_1)
2773         t1_timer->adjust(timer.machine().primary_screen->time_until_pos(scanline+1, timer_1), scanline+1);
2774   }
2775
2776   timer_0++;
2777}
2778
2779static TIMER_DEVICE_CALLBACK( timer1_irq )
2780{
2781   int scanline = param;
2782
2783   TIMER_1_IRQ(timer.machine());
2784
2785   if(stv_irq.timer_1)
2786      t1_timer->adjust(timer.machine().primary_screen->time_until_pos(scanline+1, timer_1), scanline+1);
2787}
2788
2789static TIMER_CALLBACK( vdp1_irq )
2790{
2791   VDP1_IRQ;
2792}
2793
2794static TIMER_DEVICE_CALLBACK( vblank_out_irq )
2795{
2796   VBLANK_OUT_IRQ(timer.machine());
2797}
2798
2799/*V-Blank-IN event*/
2800static INTERRUPT_GEN( stv_interrupt )
2801{
2802//  scanline = 0;
2803   rectangle visarea = device->machine().primary_screen->visible_area();
2804
2805   h_sync = visarea.max_x+1;//horz
2806   v_sync = visarea.max_y+1;//vert
2807
2808   VBLANK_IN_IRQ;
2809
2810   /*Next V-Blank-OUT event*/
2811   if(stv_irq.vblank_out)
2812      vblank_out_timer->adjust(device->machine().primary_screen->time_until_pos(0));
2813   /*Set the first Hblank-IN event*/
2814   if(stv_irq.hblank_in || stv_irq.timer_0 || stv_irq.timer_1)
2815      scan_timer->adjust(device->machine().primary_screen->time_until_pos(0, h_sync));
2816
2817   /*TODO: timing of this one (related to the VDP1 speed)*/
2818   /*      (NOTE: value shouldn't be at h_sync/v_sync position (will break shienryu))*/
2819   device->machine().scheduler().timer_set(device->machine().primary_screen->time_until_pos(0), FUNC(vdp1_irq));
2820}
2821
2822static MACHINE_RESET( stv )
2823{
2824   // don't let the slave cpu and the 68k go anywhere
2825   cputag_set_input_line(machine, "slave", INPUT_LINE_RESET, ASSERT_LINE);
2826   stv_enable_slave_sh2 = 0;
2827   cputag_set_input_line(machine, "audiocpu", INPUT_LINE_RESET, ASSERT_LINE);
2828
2829   timer_0 = 0;
2830   timer_1 = 0;
2831   en_68k = 0;
2832   NMI_reset = 1;
2833   smpc_ram[0x21] = (0x80) | ((NMI_reset & 1) << 6);
2834
2835   port_sel = mux_data = 0;
2836   port_i = -1;
2837
2838   machine.device("maincpu")->set_unscaled_clock(MASTER_CLOCK_320/2);
2839   machine.device("slave")->set_unscaled_clock(MASTER_CLOCK_320/2);
2840   machine.device("audiocpu")->set_unscaled_clock(MASTER_CLOCK_320/5);
2841
2842   stvcd_reset(machine);
2843
2844   /* set the first scanline 0 timer to go off */
2845   scan_timer = machine.device<timer_device>("scan_timer");
2846   t1_timer = machine.device<timer_device>("t1_timer");
2847   vblank_out_timer = machine.device<timer_device>("vbout_timer");
2848   vblank_out_timer->adjust(machine.primary_screen->time_until_pos(0));
2849   scan_timer->adjust(machine.primary_screen->time_until_pos(224, 352));
2850
2851   stv_rtc_timer->adjust(attotime::zero, 0, attotime::from_seconds(1));
2852}
2853
2854
2855static MACHINE_CONFIG_START( stv, driver_device )
2856
2857   /* basic machine hardware */
2858   MCFG_CPU_ADD("maincpu", SH2, MASTER_CLOCK_352/2) // 28.6364 MHz
2859   MCFG_CPU_PROGRAM_MAP(stv_mem)
2860   MCFG_CPU_VBLANK_INT("screen",stv_interrupt)
2861   MCFG_CPU_CONFIG(sh2_conf_master)
2862
2863   MCFG_CPU_ADD("slave", SH2, MASTER_CLOCK_352/2) // 28.6364 MHz
2864   MCFG_CPU_PROGRAM_MAP(stv_mem)
2865   MCFG_CPU_CONFIG(sh2_conf_slave)
2866
2867   MCFG_CPU_ADD("audiocpu", M68000, MASTER_CLOCK_352/5) //11.46 MHz
2868   MCFG_CPU_PROGRAM_MAP(sound_mem)
2869
2870   MCFG_MACHINE_START(stv)
2871   MCFG_MACHINE_RESET(stv)
2872
2873   MCFG_EEPROM_93C46_ADD("eeprom") /* Actually 93c45 */
2874
2875   MCFG_TIMER_ADD("scan_timer", hblank_in_irq)
2876   MCFG_TIMER_ADD("t1_timer", timer1_irq)
2877   MCFG_TIMER_ADD("vbout_timer", vblank_out_irq)
2878   MCFG_TIMER_ADD("sector_timer", stv_sector_cb)
2879
2880   /* video hardware */
2881   MCFG_VIDEO_ATTRIBUTES(VIDEO_UPDATE_AFTER_VBLANK)
2882
2883   MCFG_SCREEN_ADD("screen", RASTER)
2884   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB15)
2885   MCFG_SCREEN_RAW_PARAMS(PIXEL_CLOCK, 400, 0, 320, 262, 0, 224)
2886   MCFG_SCREEN_UPDATE(stv_vdp2)
2887
2888   MCFG_PALETTE_LENGTH(2048+(2048*2))//standard palette + extra memory for rgb brightness.
2889   MCFG_GFXDECODE(stv)
2890
2891   MCFG_VIDEO_START(stv_vdp2)
2892
2893   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
2894
2895   MCFG_SOUND_ADD("scsp", SCSP, 0)
2896   MCFG_SOUND_CONFIG(scsp_config)
2897   MCFG_SOUND_ROUTE(0, "lspeaker", 1.0)
2898   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
2899MACHINE_CONFIG_END
2900
2901#define ROM_LOAD16_WORD_SWAP_BIOS(bios,name,offset,length,hash) \
2902      ROMX_LOAD(name, offset, length, hash, ROM_GROUPWORD | ROM_REVERSE | ROM_BIOS(bios+1)) /* Note '+1' */
2903
2904/* BIOS rev info found at 0x800 (byte swapped):
2905
2906erp-17740  - Japan   STVB1.10J0950131  95/01/31 v1.10  - Found on a early board dated 02/1995
2907epr-17951a - Japan   STVB1.13J0950425  95/04/25 v1.13
2908epr-17952a - USA     STVB1.13U0950425  95/04/25 v1.13
2909epr-17953a - Taiwan  STVB1.13T0950425  95/04/25 v1.13
2910epr-17954a - Europe  STVB1.13E0950425  95/04/25 v1.13
2911
2912epr-18343  - ?????   STVB1.30S0950727  95/07/27 v1.30 - Special version used on Sports Fishing 2 (CD based)
2913epr-19730  - Japan   PCD11.13J0970217  97/02/17 v1.13 - Enhanced version for CD based units?
2914epr-20091  - Japan   PCS11.13J0970821  97/08/21 v1.13 - Enhanced version for ???
2915
2916stv110.bin  - Debug  STVB1.10D0950113  95/01/13 v1.10
2917stv1061.bin - ST-V Dev Bios (1.061) - Sega 1994, Noted "ST-V Ver 1.061 94/11/25" on EPROM sticker, Coming from a S-TV SG5001A dev board
2918
2919Regions found listed in the BIOS:
2920    Japan
2921    Taiwan and Philipines
2922    USA and Canada
2923    Brazil
2924    Korea
2925    Asia PAL area
2926    Europe
2927    Latin America
2928
2929ROM_SYSTEM_BIOS( x, "saturn",      "Saturn bios" ) \
2930ROM_LOAD16_WORD_SWAP_BIOS( x, "saturn.bin", 0x000000, 0x080000, CRC(653ff2d8) SHA1(20994ae7ee177ddaf3a430b010c7620dca000fb4) ) - Saturn Eu Bios
2931
2932*/
2933
2934#define STV_BIOS \
2935   ROM_REGION( 0x080000, "maincpu", 0 ) /* SH2 code */ \
2936   ROM_SYSTEM_BIOS( 0,  "jp",    "EPR-20091 (Japan 97/08/21)" ) \
2937   ROM_LOAD16_WORD_SWAP_BIOS( 0,  "epr-20091.ic8",   0x000000, 0x080000, CRC(59ed40f4) SHA1(eff0f54c70bce05ff3a289bf30b1027e1c8cd117) ) \
2938   ROM_SYSTEM_BIOS( 1,  "jp1",   "EPR-19730 (Japan 97/02/17)" ) \
2939   ROM_LOAD16_WORD_SWAP_BIOS( 1,  "epr-19730.ic8",   0x000000, 0x080000, CRC(d0e0889d) SHA1(fae53107c894e0c41c49e191dbe706c9cd6e50bd) ) \
2940   ROM_SYSTEM_BIOS( 2,  "jp2",   "EPR-17951A (Japan 95/04/25)" ) \
2941   ROM_LOAD16_WORD_SWAP_BIOS( 2,  "epr-17951a.ic8",  0x000000, 0x080000, CRC(2672f9d8) SHA1(63cf4a6432f6c87952f9cf3ab0f977aed2367303) ) \
2942   ROM_SYSTEM_BIOS( 3,  "jp3",   "STVB1.11J (Japan 95/02/20)" ) \
2943   ROM_LOAD16_WORD_SWAP_BIOS( 3,  "stvb111j.ic8",    0x000000, 0x080000, CRC(3e23c81f) SHA1(f9b282fd27693e9891843597b2e1823da3d23c7b) ) \
2944   ROM_SYSTEM_BIOS( 4,  "jp4",   "EPR-17740 (Japan 95/01/31)" ) \
2945   ROM_LOAD16_WORD_SWAP_BIOS( 4,  "epr-17740.ic8",   0x000000, 0x080000, CRC(5c5aa63d) SHA1(06860d96923b81afbc21e0ad32ee19487d8ff6e7) ) \
2946   ROM_SYSTEM_BIOS( 5,  "euro",  "EPR-17954A (Europe 95/04/25)" ) \
2947   ROM_LOAD16_WORD_SWAP_BIOS( 5,  "epr-17954a.ic8",  0x000000, 0x080000, CRC(f7722da3) SHA1(af79cff317e5b57d49e463af16a9f616ed1eee08) ) \
2948   ROM_SYSTEM_BIOS( 6,  "us",    "EPR-17952A (USA 95/04/25)" ) \
2949   ROM_LOAD16_WORD_SWAP_BIOS( 6,  "epr-17952a.ic8",  0x000000, 0x080000, CRC(d1be2adf) SHA1(eaf1c3e5d602e1139d2090a78d7e19f04f916794) ) \
2950   ROM_SYSTEM_BIOS( 7,  "tw",    "EPR-17953A (Taiwan 95/04/25)" ) \
2951   ROM_LOAD16_WORD_SWAP_BIOS( 7,  "epr-17953a.ic8",  0x000000, 0x080000, CRC(a4c47570) SHA1(9efc73717ec8a13417e65c54344ded9fc25bf5ef) ) \
2952   ROM_SYSTEM_BIOS( 8,  "tw1",   "STVB1.11T (Taiwan 95/02/20)" ) \
2953   ROM_LOAD16_WORD_SWAP_BIOS( 8,  "stvb111t.ic8",    0x000000, 0x080000, CRC(02daf123) SHA1(23185beb1ce9c09b8719e57d1adb7b28c8141fd5) ) \
2954   ROM_SYSTEM_BIOS( 9,  "debug", "Debug (95/01/13)" ) \
2955   ROM_LOAD16_WORD_SWAP_BIOS( 9,  "stv110.bin",      0x000000, 0x080000, CRC(3dfeda92) SHA1(8eb33192a57df5f3a1dfb57263054867c6b2db6d) ) \
2956   ROM_SYSTEM_BIOS( 10, "dev",   "Development (bios 1.061)" ) \
2957   ROM_LOAD16_WORD_SWAP_BIOS( 10, "stv1061.bin",     0x000000, 0x080000, CRC(728dbca3) SHA1(0ed2030177f0aa8285645c395ae9ad9f568ab1d6) ) \
2958   \
2959   ROM_REGION( 0x080000, "slave", 0 ) /* SH2 code */ \
2960   ROM_COPY( "maincpu",0,0,0x080000) \
2961
2962ROM_START( stvbios )
2963   STV_BIOS
2964   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
2965ROM_END
2966
2967/*
2968
2969there appears to only be one main cartridge layout, just some having different positions populated if you use the ic named in
2970the test mode you have the following
2971
2972some of the rom names were using something else and have been renamed to match test mode, old extension left in comments
2973
2974( add 0x2000000 for real memory map location )
2975
29760x0000000 - 0x01fffff IC13 Header can be read from here .. IC13 roms are loaded on ODD bytes only
29770x0200000 - 0x03fffff IC7  Header can also be read from here.  If No IC7 is present it seems to mirror IC13, but loaded normally (mausuke)
29780x0400000 - 0x07fffff IC2
29790x0800000 - 0x0bfffff IC3
29800x0c00000 - 0x0ffffff IC4
29810x1000000 - 0x13fffff IC5
29820x1400000 - 0x17fffff IC6
29830x1800000 - 0x1bfffff IC1
29840x1c00000 - 0x1ffffff IC8
29850x2000000 - 0x23fffff IC9
29860x2400000 - 0x27fffff IC10
29870x2800000 - 0x2bfffff IC11
29880x2c00000 - 0x2ffffff IC12
2989
2990Update:Issue fixed,see stvhacks.c for more details (TODO: Clean-up that)
2991*/
2992
2993
2994
2995
2996ROM_START( astrass )
2997   STV_BIOS
2998
2999   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3000
3001   ROM_LOAD16_BYTE( "epr20825.13",                0x0000001, 0x0100000, CRC(94a9ad8f) SHA1(861311c14cfa9f560752aa5b023c147a539cf135) )
3002
3003   ROM_LOAD16_WORD_SWAP( "mpr20827.2",     0x0400000, 0x0400000, CRC(65cabbb3) SHA1(5e7cb090101dc42207a4084465e419f4311b6baf) ) // good (was .12)
3004   ROM_LOAD16_WORD_SWAP( "mpr20828.3",     0x0800000, 0x0400000, CRC(3934d44a) SHA1(969406b8bfac43b30f4d732702ca8cffeeefffb9) ) // good (was .13)
3005   ROM_LOAD16_WORD_SWAP( "mpr20829.4",     0x0c00000, 0x0400000, CRC(814308c3) SHA1(45c3f551690224c95acd156ae8f8397667927a04) ) // good (was .14)
3006   ROM_LOAD16_WORD_SWAP( "mpr20830.5",     0x1000000, 0x0400000, CRC(ff97fd19) SHA1(f37bcdce5f3f522527a44d59f1b8184ef290f829) ) // good (was .15)
3007   ROM_LOAD16_WORD_SWAP( "mpr20831.6",     0x1400000, 0x0400000, CRC(4408e6fb) SHA1(d4228cad8a1128e9426dac9ac62e9513a7a0117b) ) // good (was .16)
3008   ROM_LOAD16_WORD_SWAP( "mpr20826.1",     0x1800000, 0x0400000, CRC(bdc4b941) SHA1(c5e8b1b186324c2ccab617915f7bdbfe6897ca9f) ) // good (was .17)
3009   ROM_LOAD16_WORD_SWAP( "mpr20832.8",     0x1c00000, 0x0400000, CRC(af1b0985) SHA1(d7a0e4e0a8b0556915f924bdde8c3d14e5b3423e) ) // good (was .18s)
3010   ROM_LOAD16_WORD_SWAP( "mpr20833.9",     0x2000000, 0x0400000, CRC(cb6af231) SHA1(4a2e5d7c2fd6179c19cdefa84a03f9a34fbb9e70) ) // good (was .19s)
3011
3012   ROM_REGION32_BE( 0x11ea0, "user2", 0 )
3013   // protection data (text layer tiles) extracted from Saturn version
3014   // stat_t.bin is name of the file from Saturn version CD
3015   ROM_LOAD( "stat_t.bin", 0x0000000, 0x11ea0,  BAD_DUMP CRC(52a0b542) SHA1(2b352dee919d7e7a5d338ece1691577d0b288eca) )
3016ROM_END
3017
3018ROM_START( bakubaku )
3019   STV_BIOS
3020
3021   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3022
3023   ROM_LOAD16_BYTE( "fpr17969.13",               0x0000001, 0x0100000, CRC(bee327e5) SHA1(1d226db72d6ef68fd294f60659df7f882b25def6) )
3024
3025   ROM_LOAD16_WORD_SWAP( "mpr17970.2",    0x0400000, 0x0400000, CRC(bc4d6f91) SHA1(dcc241dcabea59325decfba3fd5e113c07958422) ) // good
3026   ROM_LOAD16_WORD_SWAP( "mpr17971.3",    0x0800000, 0x0400000, CRC(c780a3b3) SHA1(99587eea528a6413cacc3e4d3d1dbfff57b03dca) ) // good
3027   ROM_LOAD16_WORD_SWAP( "mpr17972.4",    0x0c00000, 0x0400000, CRC(8f29815a) SHA1(e86acd8096f2aee5f5e3ddfd3abb4f5c2b11df66) ) // good
3028   ROM_LOAD16_WORD_SWAP( "mpr17973.5",    0x1000000, 0x0400000, CRC(5f6e0e8b) SHA1(eeb5efb5216ab8b8fdee4656774bbd5a2a5b2d42) ) // good
3029ROM_END
3030
3031ROM_START( colmns97 )
3032   STV_BIOS
3033
3034   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3035
3036   ROM_LOAD16_BYTE( "fpr19553.13",    0x000001, 0x100000, CRC(d4fb6a5e) SHA1(bd3cfb4f451b6c9612e42af5ddcbffa14f057329) )
3037
3038   ROM_LOAD16_WORD_SWAP( "mpr19554.2",     0x400000, 0x400000, CRC(5a3ebcac) SHA1(46e3d1cf515a7ff8a8f97e5050b29dbbeb5060c0) ) // good
3039   ROM_LOAD16_WORD_SWAP( "mpr19555.3",     0x800000, 0x400000, CRC(74f6e6b8) SHA1(8080860550eb770e04447e344fb337748a249761) ) // good
3040ROM_END
3041
3042ROM_START( cotton2 )
3043   STV_BIOS
3044
3045   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3046   ROM_LOAD16_WORD_SWAP( "mpr20122.7",    0x0200000, 0x0200000, CRC(d616f78a) SHA1(8039dcdfdafb8327a19a1da46a67c0b3f7eee53a) ) // good
3047   ROM_LOAD16_WORD_SWAP( "mpr20117.2",    0x0400000, 0x0400000, CRC(893656ea) SHA1(11e3160083ba018fbd588f07061a4e55c1efbebb) ) // good
3048   ROM_LOAD16_WORD_SWAP( "mpr20118.3",    0x0800000, 0x0400000, CRC(1b6a1d4c) SHA1(6b234d6b2d24df7f6d400a56698c0af2f78ce0e7) ) // good
3049   ROM_LOAD16_WORD_SWAP( "mpr20119.4",    0x0c00000, 0x0400000, CRC(5a76e72b) SHA1(0a058627ddf78a0bcdaba328a58712419f24e33b) ) // good
3050   ROM_LOAD16_WORD_SWAP( "mpr20120.5",    0x1000000, 0x0400000, CRC(7113dd7b) SHA1(f86add67c4e1349a9b9ebcd0145a30b1667df811) ) // good
3051   ROM_LOAD16_WORD_SWAP( "mpr20121.6",    0x1400000, 0x0400000, CRC(8c8fd521) SHA1(c715681330b5ed37a8506ac58ee2143baa721206) ) // good
3052   ROM_LOAD16_WORD_SWAP( "mpr20116.1",    0x1800000, 0x0400000, CRC(d30b0175) SHA1(2da5c3c02d68b8324948a8cdc93946d97fccdd8f) ) // good
3053   ROM_LOAD16_WORD_SWAP( "mpr20123.8",    0x1c00000, 0x0400000, CRC(35f1b89f) SHA1(1d6007c380f817def734fc3030d4fe56df4a15be) ) // good
3054ROM_END
3055
3056ROM_START( cottonbm )
3057   STV_BIOS
3058
3059   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3060   ROM_LOAD16_WORD_SWAP( "mpr21075.7",    0x0200000, 0x0200000, CRC(200b58ba) SHA1(6daad6d70a3a41172e8d9402af775c03e191232d) ) // good
3061   ROM_LOAD16_WORD_SWAP( "mpr21070.2",    0x0400000, 0x0400000, CRC(56c0bf1d) SHA1(c2b564ce536c637bb723ed96683b27596e87ebe7) ) // good
3062   ROM_LOAD16_WORD_SWAP( "mpr21071.3",    0x0800000, 0x0400000, CRC(2bb18df2) SHA1(e900adb94ad3f48be00a4ce33e915147dc6a8737) ) // good
3063   ROM_LOAD16_WORD_SWAP( "mpr21072.4",    0x0c00000, 0x0400000, CRC(7c7cb977) SHA1(376dfb8014050605b00b6545520bd544768f5828) ) // good
3064   ROM_LOAD16_WORD_SWAP( "mpr21073.5",    0x1000000, 0x0400000, CRC(f2e5a5b7) SHA1(9258d508ef6f6529efc4ad172fd29e69877a99eb) ) // good
3065   ROM_LOAD16_WORD_SWAP( "mpr21074.6",    0x1400000, 0x0400000, CRC(6a7e7a7b) SHA1(a0b1e7a85e623b59886b28797281df1d65b8a5aa) ) // good
3066   ROM_LOAD16_WORD_SWAP( "mpr21069.1",    0x1800000, 0x0400000, CRC(6a28e3c5) SHA1(60454b71db49b872e0cb89fae2259fed601588bd) ) // good
3067ROM_END
3068
3069ROM_START( decathlt )
3070   STV_BIOS
3071
3072   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3073
3074   ROM_LOAD16_BYTE( "epr18967a.13",               0x0000001, 0x0100000, CRC(ac59c186) SHA1(7d4924d1e4c1b9257b58a690de988b3f6486e86f) )
3075
3076   ROM_LOAD16_WORD_SWAP( "mpr18968.2",    0x0400000, 0x0400000, CRC(11a891de) SHA1(1a4fa8d7e07e1d8fdc8122ef8a5b93723c007cda) ) // good (was .1)
3077   ROM_LOAD16_WORD_SWAP( "mpr18969.3",    0x0800000, 0x0400000, CRC(199cc47d) SHA1(d78f7c6be7e9b43e208244c5c8722245f4c653e1) ) // good (was .2)
3078   ROM_LOAD16_WORD_SWAP( "mpr18970.4",    0x0c00000, 0x0400000, CRC(8b7a509e) SHA1(8f4d36a858231764ed09b26a1141d1f055eee092) ) // good (was .3)
3079   ROM_LOAD16_WORD_SWAP( "mpr18971.5",    0x1000000, 0x0400000, CRC(c87c443b) SHA1(f2fedb35c80e5c4855c7aebff88186397f4d51bc) ) // good (was .4)
3080   ROM_LOAD16_WORD_SWAP( "mpr18972.6",    0x1400000, 0x0400000, CRC(45c64fca) SHA1(ae2f678b9885426ce99b615b7f62a451f9ef83f9) ) // good (was .5)
3081ROM_END
3082
3083ROM_START( decathlto )
3084   STV_BIOS
3085
3086   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3087
3088   ROM_LOAD16_BYTE( "epr18967.13",               0x0000001, 0x0100000, CRC(c0446674) SHA1(4917089d95613c9d2a936ed9fe3ebd22f461aa4f) )
3089
3090   ROM_LOAD16_WORD_SWAP( "mpr18968.2",    0x0400000, 0x0400000, CRC(11a891de) SHA1(1a4fa8d7e07e1d8fdc8122ef8a5b93723c007cda) ) // good (was .1)
3091   ROM_LOAD16_WORD_SWAP( "mpr18969.3",    0x0800000, 0x0400000, CRC(199cc47d) SHA1(d78f7c6be7e9b43e208244c5c8722245f4c653e1) ) // good (was .2)
3092   ROM_LOAD16_WORD_SWAP( "mpr18970.4",    0x0c00000, 0x0400000, CRC(8b7a509e) SHA1(8f4d36a858231764ed09b26a1141d1f055eee092) ) // good (was .3)
3093   ROM_LOAD16_WORD_SWAP( "mpr18971.5",    0x1000000, 0x0400000, CRC(c87c443b) SHA1(f2fedb35c80e5c4855c7aebff88186397f4d51bc) ) // good (was .4)
3094   ROM_LOAD16_WORD_SWAP( "mpr18972.6",    0x1400000, 0x0400000, CRC(45c64fca) SHA1(ae2f678b9885426ce99b615b7f62a451f9ef83f9) ) // good (was .5)
3095ROM_END
3096
3097ROM_START( diehard ) /* must use USA, Europe or Taiwan BIOS */
3098   STV_BIOS
3099   ROM_DEFAULT_BIOS( "us" )
3100
3101   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3102
3103   ROM_LOAD16_BYTE( "fpr19119.13",               0x0000001, 0x0100000, CRC(de5c4f7c) SHA1(35f670a15e9c86edbe2fe718470f5a75b5b096ac) )
3104
3105   ROM_LOAD16_WORD_SWAP( "mpr19115.2",    0x0400000, 0x0400000, CRC(6fe06a30) SHA1(dedb90f800bae8fd9df1023eb5bec7fb6c9d0179) ) // good
3106   ROM_LOAD16_WORD_SWAP( "mpr19116.3",    0x0800000, 0x0400000, CRC(af9e627b) SHA1(a53921c3185a93ec95299bf1c29e744e2fa3b8c0) ) // good
3107   ROM_LOAD16_WORD_SWAP( "mpr19117.4",    0x0c00000, 0x0400000, CRC(74520ff1) SHA1(16c1acf878664b3bd866c9b94f3695ae892ac12f) ) // good
3108   ROM_LOAD16_WORD_SWAP( "mpr19118.5",    0x1000000, 0x0400000, CRC(2c9702f0) SHA1(5c2c66de83f2ccbe97d3b1e8c7e65999e1fa2de1) ) // good
3109ROM_END
3110
3111ROM_START( dnmtdeka )
3112   STV_BIOS
3113
3114   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3115
3116   ROM_LOAD16_BYTE( "fpr19114.13",               0x0000001, 0x0100000, CRC(1fd22a5f) SHA1(c3d9653b12354a73a3e15f23a2ab7992ffb83e46) )
3117
3118   ROM_LOAD16_WORD_SWAP( "mpr19115.2",    0x0400000, 0x0400000, CRC(6fe06a30) SHA1(dedb90f800bae8fd9df1023eb5bec7fb6c9d0179) ) // good
3119   ROM_LOAD16_WORD_SWAP( "mpr19116.3",    0x0800000, 0x0400000, CRC(af9e627b) SHA1(a53921c3185a93ec95299bf1c29e744e2fa3b8c0) ) // good
3120   ROM_LOAD16_WORD_SWAP( "mpr19117.4",    0x0c00000, 0x0400000, CRC(74520ff1) SHA1(16c1acf878664b3bd866c9b94f3695ae892ac12f) ) // good
3121   ROM_LOAD16_WORD_SWAP( "mpr19118.5",    0x1000000, 0x0400000, CRC(2c9702f0) SHA1(5c2c66de83f2ccbe97d3b1e8c7e65999e1fa2de1) ) // good
3122ROM_END
3123
3124ROM_START( ejihon )
3125   STV_BIOS
3126
3127   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3128   ROM_LOAD16_BYTE( "epr18137.13",               0x0000001, 0x0080000, CRC(151aa9bc) SHA1(0959c60f31634816825acb57413838dcddb17d31) )
3129   ROM_RELOAD( 0x100001, 0x0080000 )
3130
3131   ROM_LOAD16_WORD_SWAP( "mpr18138.2",    0x0400000, 0x0400000, CRC(f5567049) SHA1(6eb35e4b5fbda39cf7e8c42b6a568bd53a364d6d) ) // good
3132   ROM_LOAD16_WORD_SWAP( "mpr18139.3",    0x0800000, 0x0400000, CRC(f36b4878) SHA1(e3f63c0046bd37b7ab02fb3865b8ebcf4cf68e75) ) // good
3133   ROM_LOAD16_WORD_SWAP( "mpr18140.4",    0x0c00000, 0x0400000, CRC(228850a0) SHA1(d83f7fa7df08407fa45a13661393679b88800805) ) // good
3134   ROM_LOAD16_WORD_SWAP( "mpr18141.5",    0x1000000, 0x0400000, CRC(b51eef36) SHA1(2745cba48dc410d6d31327b956886ec284b9eac3) ) // good
3135   ROM_LOAD16_WORD_SWAP( "mpr18142.6",    0x1400000, 0x0400000, CRC(cf259541) SHA1(51e2c8d16506d6074f6511112ec4b6b44bed4886) ) // good
3136ROM_END
3137
3138ROM_START( elandore )
3139   STV_BIOS
3140
3141   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3142   ROM_LOAD16_WORD_SWAP( "mpr21307.7",    0x0200000, 0x0200000, CRC(966ad472) SHA1(d6db41d1c40d08eb6bce8a8a2f491e7533daf670) ) // good (was .11s)
3143   ROM_LOAD16_WORD_SWAP( "mpr21301.2",    0x0400000, 0x0400000, CRC(1a23b0a0) SHA1(f9dbc7ba96dadfb00e5827622b557080449acd83) ) // good (was .12)
3144   ROM_LOAD16_WORD_SWAP( "mpr21302.3",    0x0800000, 0x0400000, CRC(1c91ca33) SHA1(ae11209088e3bf8fc4a92dca850d7303ce949b29) ) // good (was .13)
3145   ROM_LOAD16_WORD_SWAP( "mpr21303.4",    0x0c00000, 0x0400000, CRC(07b2350e) SHA1(f32f63fd8bec4e667f61da203d63be9a27798dfe) ) // good (was .14)
3146   ROM_LOAD16_WORD_SWAP( "mpr21304.5",    0x1000000, 0x0400000, CRC(cfea52ae) SHA1(4b6d27e0b2a95300ee9e07ebcdc4953d77c4efbe) ) // good (was .15)
3147   ROM_LOAD16_WORD_SWAP( "mpr21305.6",    0x1400000, 0x0400000, CRC(46cfc2a2) SHA1(8ca26bf8fa5ced040e815c125c13dd06d599e189) ) // good (was .16)
3148   ROM_LOAD16_WORD_SWAP( "mpr21306.1",    0x1800000, 0x0400000, CRC(87a5929c) SHA1(b259341d7b0e1fa98959bf52d23db5c308a8efdd) ) // good (was .17)
3149   ROM_LOAD16_WORD_SWAP( "mpr21308.8",    0x1c00000, 0x0400000, CRC(336ec1a4) SHA1(20d1fce050cf6132d284b91853a4dd5626372ef0) ) // good (was .18s)
3150ROM_END
3151
3152ROM_START( ffreveng )
3153   STV_BIOS
3154
3155   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3156   ROM_LOAD16_WORD_SWAP( "opr21872.7",   0x0200000, 0x0200000, CRC(32d36fee) SHA1(441c4254ef2e9301e1006d69462a850ce339314b) ) // good (was .11s)
3157   ROM_LOAD16_WORD_SWAP( "mpr21873.2",   0x0400000, 0x0400000, CRC(dac5bd98) SHA1(6102035ce9eb2f83d7d9b20f989a151f45087c67) ) // good (was .12)
3158   ROM_LOAD16_WORD_SWAP( "mpr21874.3",   0x0800000, 0x0400000, CRC(0a7be2f1) SHA1(e2d13f36e54d1e2cb9d584db829c04a6ff65108c) ) // good (was .13)
3159   ROM_LOAD16_WORD_SWAP( "mpr21875.4",   0x0c00000, 0x0400000, CRC(ccb75029) SHA1(9611a08a2ad0e0e82137ded6205440a948a339a4) ) // good (was .14)
3160   ROM_LOAD16_WORD_SWAP( "mpr21876.5",   0x1000000, 0x0400000, CRC(bb92a7fc) SHA1(d9e0fab1104a46adeb0a0cfc0d070d4c63a28d55) ) // good (was .15)
3161   ROM_LOAD16_WORD_SWAP( "mpr21877.6",   0x1400000, 0x0400000, CRC(c22a4a75) SHA1(3276bc0628e71b432f21ba9a4f5ff7ccc8769cd9) ) // good (was .16)
3162   ROM_LOAD16_WORD_SWAP( "opr21878.1",   0x1800000, 0x0200000, CRC(2ea4a64d) SHA1(928a973dce5eba0a1628d61ba56a530de990a946) ) // good (was .17)
3163ROM_END
3164
3165/* set system to 1 player to test rom */
3166ROM_START( fhboxers )
3167   STV_BIOS
3168
3169   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3170   ROM_LOAD16_BYTE( "fr18541a.13",               0x0000001, 0x0100000, CRC(8c61a17c) SHA1(a8aef27b53482923a506f7daa4b7a38653b4d8a4) ) //(header is read from here, not ic7 even if both are populated on this board)
3171
3172   ROM_LOAD16_WORD_SWAP( "mpr18538.7",    0x0200000, 0x0200000, CRC(7b5230c5) SHA1(70cebc3281580b43adf42c37318e12159c28a13d) ) // good
3173   ROM_LOAD16_WORD_SWAP( "mpr18533.2",    0x0400000, 0x0400000, CRC(7181fe51) SHA1(646f95e1a5b64d721e961352cee6fd5adfd031ec) ) // good
3174   ROM_LOAD16_WORD_SWAP( "mpr18534.3",    0x0800000, 0x0400000, CRC(c87ef125) SHA1(c9ced130faf6dd9e626074b6519615654d8beb19) ) // good
3175   ROM_LOAD16_WORD_SWAP( "mpr18535.4",    0x0c00000, 0x0400000, CRC(929a64cf) SHA1(206dfc2a46befbcea974df1e27515c5759d88d00) ) // good
3176   ROM_LOAD16_WORD_SWAP( "mpr18536.5",    0x1000000, 0x0400000, CRC(51b9f64e) SHA1(bfbdfb73d24f26ce1cc5294c23a1712fb9631691) ) // good
3177   ROM_LOAD16_WORD_SWAP( "mpr18537.6",    0x1400000, 0x0400000, CRC(c364f6a7) SHA1(4db21bcf6ea3e75f9eb34f067b56a417589271c0) ) // good
3178   ROM_LOAD16_WORD_SWAP( "mpr18532.1",    0x1800000, 0x0400000, CRC(39528643) SHA1(e35f4c35c9eb13e1cdcc26cb2599bb846f2c1af7) ) // good
3179   ROM_LOAD16_WORD_SWAP( "mpr18539.8",    0x1c00000, 0x0400000, CRC(62b3908c) SHA1(3f00e49beb0e5575cc4250a25c41f04dc91d6ed0) ) // good
3180   ROM_LOAD16_WORD_SWAP( "mpr18540.9",    0x2000000, 0x0400000, CRC(4c2b59a4) SHA1(4d15503fcff0e9e0d1ed3bac724278102b506da0) ) // good
3181
3182   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
3183   ROM_LOAD( "fhboxers.nv", 0x0000, 0x0080, CRC(590fd6da) SHA1(1abe71c62c51a246d854f02cd4cb79fd0d427e88) )
3184ROM_END
3185
3186/* set system to 1 player to test rom */
3187ROM_START( findlove )
3188   STV_BIOS
3189
3190   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3191   ROM_LOAD16_BYTE( "epr20424.13",               0x0000001, 0x0100000, CRC(4e61fa46) SHA1(e34624d98cbdf2dd04d997167d3c4decd2f208f7) ) //(header is read from here, not ic7 even if both are populated on this board)
3192
3193   ROM_LOAD16_WORD_SWAP( "mpr20431.7",    0x0200000, 0x0200000, CRC(ea656ced) SHA1(b2d6286081bd46a89d1284a2757b87d0bca1bbde) ) // good
3194   ROM_LOAD16_WORD_SWAP( "mpr20426.2",    0x0400000, 0x0400000, CRC(897d1747) SHA1(f3fb2c4ef8bc2c1658907e822f2ee2b88582afdd) ) // good
3195   ROM_LOAD16_WORD_SWAP( "mpr20427.3",    0x0800000, 0x0400000, CRC(a488a694) SHA1(80ec81f32e4b5712a607208b2a45cfdf6d5e1849) ) // good
3196   ROM_LOAD16_WORD_SWAP( "mpr20428.4",    0x0c00000, 0x0400000, CRC(4353b3b6) SHA1(f5e56396b345ff65f57a23f391b77d401f1f58b5) ) // good
3197   ROM_LOAD16_WORD_SWAP( "mpr20429.5",    0x1000000, 0x0400000, CRC(4f566486) SHA1(5b449288e33f02f2362ebbd515c87ea11cc02633) ) // good
3198   ROM_LOAD16_WORD_SWAP( "mpr20430.6",    0x1400000, 0x0400000, CRC(d1e11979) SHA1(14405997eefac22c42f0c86dca9411ba1dee9bf9) ) // good
3199   ROM_LOAD16_WORD_SWAP( "mpr20425.1",    0x1800000, 0x0400000, CRC(67f104c4) SHA1(8e965d2ce554ba8d37254f6bf3931dff4bce1a43) ) // good
3200   ROM_LOAD16_WORD_SWAP( "mpr20432.8",    0x1c00000, 0x0400000, CRC(79fcdecd) SHA1(df8e7733a51e24196914fc66a024515ee1565599) ) // good
3201   ROM_LOAD16_WORD_SWAP( "mpr20433.9",    0x2000000, 0x0400000, CRC(82289f29) SHA1(fb6a1015621b1afa3913da162ae71ded6b674649) ) // good
3202   ROM_LOAD16_WORD_SWAP( "mpr20434.10",   0x2400000, 0x0400000, CRC(85c94afc) SHA1(dfc2f16614bc499747ea87567a21c86e7bddce45) ) // good
3203   ROM_LOAD16_WORD_SWAP( "mpr20435.11",   0x2800000, 0x0400000, CRC(263a2e48) SHA1(27ef4bf577d240e36dcb6e6a09b9c5f24e59ce8c) ) // good
3204   ROM_LOAD16_WORD_SWAP( "mpr20436.12",   0x2c00000, 0x0400000, CRC(e3823f49) SHA1(754d48635bd1d4fb01ff665bfe2a71593d92f688) ) // good
3205
3206   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
3207   ROM_LOAD( "findlove.nv", 0x0000, 0x0080, CRC(df2fa9f6) SHA1(f05450e1648eafd2ffb52e50769f07bdc75ffb95) )
3208ROM_END
3209
3210ROM_START( finlarch )
3211   STV_BIOS
3212
3213   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3214   ROM_LOAD16_BYTE( "finlarch.13",               0x0000001, 0x0100000, CRC(4505fa9e) SHA1(96c6399146cf9c8f1d27a8fb6a265f937258004a) )
3215   ROM_RELOAD ( 0x0100001, 0x0080000 )
3216
3217   ROM_LOAD16_WORD_SWAP( "mpr18257.2",    0x0400000, 0x0400000, CRC(137fdf55) SHA1(07a02fe531b3707e063498f5bc9749bd1b4cadb3) ) // good
3218   ROM_RELOAD(                            0x1400000, 0x0400000 )
3219   ROM_LOAD16_WORD_SWAP( "mpr18258.3",    0x0800000, 0x0400000, CRC(f519c505) SHA1(5cad39314e46b98c24a71f1c2c10c682ef3bdcf3) ) // good
3220   ROM_RELOAD(                            0x1800000, 0x0400000 )
3221   ROM_LOAD16_WORD_SWAP( "mpr18259.4",    0x0c00000, 0x0400000, CRC(5cabc775) SHA1(84383a4cbe3b1a9dcc6c140cff165425666dc780) ) // good
3222   ROM_RELOAD(                            0x1c00000, 0x0400000 )
3223   ROM_LOAD16_WORD_SWAP( "mpr18260.5",    0x1000000, 0x0400000, CRC(f5b92082) SHA1(806ad85a187a23a5cf867f2f3dea7d8150065b8e) ) // good
3224   ROM_RELOAD(                            0x2000000, 0x0400000 )
3225ROM_END
3226
3227
3228ROM_START( gaxeduel )
3229   STV_BIOS
3230
3231   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3232   ROM_LOAD16_BYTE( "epr17766.13",               0x0000001, 0x0080000, CRC(a83fcd62) SHA1(4ce77ebaa0e93c6553ad8f7fb87cbdc32433402b) )
3233   ROM_RELOAD( 0x0100001, 0x0080000 )
3234
3235   ROM_LOAD16_WORD_SWAP( "mpr17768.2",    0x0400000, 0x0400000, CRC(d6808a7d) SHA1(83a97bbe1160cb45b3bdcbde8adc0d9bae5ded60) ) // good
3236   ROM_LOAD16_WORD_SWAP( "mpr17769.3",    0x0800000, 0x0400000, CRC(3471dd35) SHA1(24febddfe70984cebc0e6948ad718e0e6957fa82) ) // good
3237   ROM_LOAD16_WORD_SWAP( "mpr17770.4",    0x0c00000, 0x0400000, CRC(06978a00) SHA1(a8d1333a9f4322e28b23724937f595805315b136) ) // good
3238   ROM_LOAD16_WORD_SWAP( "mpr17771.5",    0x1000000, 0x0400000, CRC(aea2ea3b) SHA1(2fbe3e10d3f5a3b3099a7ed5b38b93b6e22e19b8) ) // good
3239   ROM_LOAD16_WORD_SWAP( "mpr17772.6",    0x1400000, 0x0400000, CRC(b3dc0e75) SHA1(fbe2790c84466d186ea3e9d41edfcb7afaf54bea) ) // good
3240   ROM_LOAD16_WORD_SWAP( "mpr17767.1",    0x1800000, 0x0400000, CRC(9ba1e7b1) SHA1(f297c3697d2e8ba4476d672267163f91f371b362) ) // good
3241ROM_END
3242
3243ROM_START( grdforce )
3244   STV_BIOS
3245
3246   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3247   ROM_LOAD16_WORD_SWAP( "mpr20844.7",    0x0200000, 0x0200000, CRC(283e7587) SHA1(477fabc27cfe149ad17757e31f10665dcf8c0860) ) // good
3248   ROM_LOAD16_WORD_SWAP( "mpr20839.2",    0x0400000, 0x0400000, CRC(facd4dd8) SHA1(2582894c98b31ab719f1865d4623dad6736dc877) ) // good
3249   ROM_LOAD16_WORD_SWAP( "mpr20840.3",    0x0800000, 0x0400000, CRC(fe0158e6) SHA1(73460effe69fb8f16dd952271542b7803471a599) ) // good
3250   ROM_LOAD16_WORD_SWAP( "mpr20841.4",    0x0c00000, 0x0400000, CRC(d87ac873) SHA1(35b8fa3862e09dca530e9597f983f5a22919cf08) ) // good
3251   ROM_LOAD16_WORD_SWAP( "mpr20842.5",    0x1000000, 0x0400000, CRC(baebc506) SHA1(f5f59f9263956d0c49c729729cf6db31dc861d3b) ) // good
3252   ROM_LOAD16_WORD_SWAP( "mpr20843.6",    0x1400000, 0x0400000, CRC(263e49cc) SHA1(67979861ca2784b3ce39d87e7994e6e7351b40e5) ) // good
3253ROM_END
3254
3255ROM_START( groovef )
3256   STV_BIOS
3257
3258   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3259   ROM_LOAD16_WORD_SWAP( "mpr19820.7",    0x0200000, 0x0100000, CRC(e93c4513) SHA1(f9636529224880c49bd2cc5572bd5bf41dbf911a) ) // good
3260   ROM_LOAD16_WORD_SWAP( "mpr19815.2",    0x0400000, 0x0400000, CRC(1b9b14e6) SHA1(b1828c520cb108e2927a23273ebd2939dca52304) ) // good
3261   ROM_LOAD16_WORD_SWAP( "mpr19816.3",    0x0800000, 0x0400000, CRC(83f5731c) SHA1(2f645737f945c59a1a2fabf3b21a761be9e8c8a6) ) // good
3262   ROM_LOAD16_WORD_SWAP( "mpr19817.4",    0x0c00000, 0x0400000, CRC(525bd6c7) SHA1(2db2501177fb0b44d0fad2054eddf356c4ea08f2) ) // good
3263   ROM_LOAD16_WORD_SWAP( "mpr19818.5",    0x1000000, 0x0400000, CRC(66723ba8) SHA1(0a8379e46a8f8cab11befeadd9abdf59dba68e27) ) // good
3264   ROM_LOAD16_WORD_SWAP( "mpr19819.6",    0x1400000, 0x0400000, CRC(ee8c55f4) SHA1(f6d86b2c2ab43ec5baefb8ccc25e11af4d82712d) ) // good
3265   ROM_LOAD16_WORD_SWAP( "mpr19814.1",    0x1800000, 0x0400000, CRC(8f20e9f7) SHA1(30ff5ad0427208e7265cb996e870c4dc0fbbf7d2) ) // good
3266   ROM_LOAD16_WORD_SWAP( "mpr19821.8",    0x1c00000, 0x0400000, CRC(f69a76e6) SHA1(b7e41f34d8b787bf1b4d587e5d8bddb241c043a8) ) // good
3267   ROM_LOAD16_WORD_SWAP( "mpr19822.9",    0x2000000, 0x0200000, CRC(5e8c4b5f) SHA1(1d146fbe3d0bfa68993135ba94ef18081ab65d31) ) // good
3268ROM_END
3269
3270ROM_START( hanagumi )
3271   STV_BIOS
3272
3273   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3274   ROM_LOAD16_WORD_SWAP( "mpr20143.7",    0x0200000, 0x0100000, CRC(7bfc38d0) SHA1(66f223e7ff2b5456a6f4185b7ab36f9cd833351a) ) // good
3275   ROM_LOAD16_WORD_SWAP( "mpr20138.2",    0x0400000, 0x0400000, CRC(fdcf1046) SHA1(cbb1f03879833c17feffdd6f5a4fbff06e1059a2) ) // good
3276   ROM_LOAD16_WORD_SWAP( "mpr20139.3",    0x0800000, 0x0400000, CRC(7f0140e5) SHA1(f2f7de7620d66a596d552e1af491a0592ebc4e51) ) // good
3277   ROM_LOAD16_WORD_SWAP( "mpr20140.4",    0x0c00000, 0x0400000, CRC(2fa03852) SHA1(798ce008f6fc24a00f85298188c8d0d01933640d) ) // good
3278   ROM_LOAD16_WORD_SWAP( "mpr20141.5",    0x1000000, 0x0400000, CRC(45d6d21b) SHA1(fe0f0b2195b74e79b8efb6a7c0b7bedca7194c48) ) // good
3279   ROM_LOAD16_WORD_SWAP( "mpr20142.6",    0x1400000, 0x0400000, CRC(e38561ec) SHA1(c04c400be033bc74a7bb2a60f6ae00853a2220d4) ) // good
3280   ROM_LOAD16_WORD_SWAP( "mpr20137.1",    0x1800000, 0x0400000, CRC(181d2688) SHA1(950059f89eda30d8a5bce145421f507e226b8b3e) ) // good
3281   ROM_LOAD16_WORD_SWAP( "mpr20144.8",    0x1c00000, 0x0400000, CRC(235b43f6) SHA1(e35d9bf15ac805513ab3edeca4f264647a2dc0b0) ) // good
3282   ROM_LOAD16_WORD_SWAP( "mpr20145.9",    0x2000000, 0x0400000, CRC(aeaac7a1) SHA1(5c75ecce49a5c53dbb0b07e75f3a76e6db9976d0) ) // good
3283   ROM_LOAD16_WORD_SWAP( "mpr20146.10",   0x2400000, 0x0400000, CRC(39bab9a2) SHA1(077132e6a03afd181ee9ca9ca4f7c9cbf418e57e) ) // good
3284   ROM_LOAD16_WORD_SWAP( "mpr20147.11",   0x2800000, 0x0400000, CRC(294ab997) SHA1(aeba269ae7d056f07edecf96bc138231c66c3637) ) // good
3285   ROM_LOAD16_WORD_SWAP( "mpr20148.12",   0x2c00000, 0x0400000, CRC(5337ccb0) SHA1(a998bb116eb10c4044410f065c5ddeb845f9dab5) ) // good
3286ROM_END
3287
3288ROM_START( introdon )
3289   STV_BIOS
3290
3291   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3292   ROM_LOAD16_BYTE( "epr18937.13",               0x0000001, 0x0080000, CRC(1f40d766) SHA1(35d9751c1b23cfbf448f2a9e9cf3b121929368ae) )
3293   ROM_RELOAD( 0x0100001, 0x0080000)
3294
3295   ROM_LOAD16_WORD_SWAP( "mpr18944.7",    0x0200000, 0x0100000, CRC(f7f75ce5) SHA1(0787ece9f89cc1847889adbf08ba5d3ccbc405de) ) // good
3296   ROM_LOAD16_WORD_SWAP( "mpr18939.2",    0x0400000, 0x0400000, CRC(ef95a6e6) SHA1(3026c52ad542997d5b0e621b389c0e01240cb486) ) // good
3297   ROM_LOAD16_WORD_SWAP( "mpr18940.3",    0x0800000, 0x0400000, CRC(cabab4cd) SHA1(b251609573c4b0ccc933188f32226855b25fd9da) ) // good
3298   ROM_LOAD16_WORD_SWAP( "mpr18941.4",    0x0c00000, 0x0400000, CRC(f4a33a20) SHA1(bf0f33495fb5c9de4ae5036cedda65b3ece217e8) ) // good
3299   ROM_LOAD16_WORD_SWAP( "mpr18942.5",    0x1000000, 0x0400000, CRC(8dd0a446) SHA1(a75e3552b0fb99e0b253c0906f62fabcf204b735) ) // good
3300   ROM_LOAD16_WORD_SWAP( "mpr18943.6",    0x1400000, 0x0400000, CRC(d8702a9e) SHA1(960dd3cb0b9eb1f18b8d0bc0da532b600d583ceb) ) // good
3301   ROM_LOAD16_WORD_SWAP( "mpr18938.1",    0x1800000, 0x0400000, CRC(580ecb83) SHA1(6c59f7da408b53f9fa7aa32c1b53328b5fd6334d) ) // good
3302ROM_END
3303
3304/* set system to 1 player to test rom */
3305ROM_START( kiwames )
3306   STV_BIOS
3307
3308   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3309   ROM_LOAD16_BYTE( "epr18737.13",               0x0000001, 0x0080000, CRC(cfad6c49) SHA1(fc69980a351ed13307706db506c79c774eabeb66) ) // bad
3310   ROM_RELOAD( 0x0100001, 0x0080000)
3311
3312   ROM_LOAD16_WORD_SWAP( "mpr18738.2",    0x0400000, 0x0400000, CRC(4b3c175a) SHA1(b6d2438ae1d3d51950a7ed1eaadf2dae45c4e7b1) ) // good
3313   ROM_LOAD16_WORD_SWAP( "mpr18739.3",    0x0800000, 0x0400000, CRC(eb41fa67) SHA1(d12acebb1df9eafd17aff1841087f5017225e7e7) ) // good
3314   ROM_LOAD16_WORD_SWAP( "mpr18740.4",    0x0c00000, 0x0200000, CRC(9ca7962f) SHA1(a09e0db2246b34ca7efa3165afbc5ba292a95398) ) // good
3315
3316   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
3317   ROM_LOAD( "kiwames.nv", 0x0000, 0x0080, CRC(c7002732) SHA1(57395d256a58ddcedd354ce1f2c458321be40505) )
3318ROM_END
3319
3320ROM_START( maruchan )
3321   STV_BIOS
3322
3323   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3324   ROM_LOAD16_BYTE( "epr20416.13",               0x0000001, 0x0100000, CRC(8bf0176d) SHA1(5bd468e2ffed042ee84e2ceb8712ff5883a1d824) ) // bad
3325
3326   ROM_LOAD16_WORD_SWAP( "mpr20417.2",    0x0400000, 0x0400000, CRC(636c2a08) SHA1(47986b71d68f6a1852e4e2b03ca7b6e48e83718b) ) // good
3327   ROM_LOAD16_WORD_SWAP( "mpr20418.3",    0x0800000, 0x0400000, CRC(3f0d9e34) SHA1(2ec81e40ebf689d17b6421820bfb0a1280a8ef25) ) // good
3328   ROM_LOAD16_WORD_SWAP( "mpr20419.4",    0x0c00000, 0x0400000, CRC(ec969815) SHA1(b59782174051f5717b06f43e57dd8a2a6910d95f) ) // good
3329   ROM_LOAD16_WORD_SWAP( "mpr20420.5",    0x1000000, 0x0400000, CRC(f2902c88) SHA1(df81e137e8aa4bd37e1d14fce4d593cfd14608f0) ) // good
3330   ROM_LOAD16_WORD_SWAP( "mpr20421.6",    0x1400000, 0x0400000, CRC(cd0b477c) SHA1(5169cc47fae465b11bc50f5e8410d84c2b2eee42) ) // good
3331   ROM_LOAD16_WORD_SWAP( "mpr20422.1",    0x1800000, 0x0400000, CRC(66335049) SHA1(59f1968001d1e9fe30990a56309bae18033eee62) ) // good
3332   ROM_LOAD16_WORD_SWAP( "mpr20423.8",    0x1c00000, 0x0400000, CRC(2bd55832) SHA1(1a1a510f30882d4d726b594a6541a12c552fafb4) ) // good
3333   ROM_LOAD16_WORD_SWAP( "mpr20443.9",    0x2000000, 0x0400000, CRC(8ac288f5) SHA1(0c08874e6ab2b07b17438721fb535434a626115f) ) // good
3334ROM_END
3335
3336/* set system to 1 player to test rom */
3337ROM_START( myfairld )
3338   STV_BIOS
3339
3340   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3341   ROM_LOAD16_WORD_SWAP( "mpr21000.7",    0x0200000, 0x0200000, CRC(2581c560) SHA1(5fb64f0e09583d50dfea7ad613d45aad30b677a5) ) // good
3342   ROM_LOAD16_WORD_SWAP( "mpr20995.2",    0x0400000, 0x0400000, CRC(1bb73f24) SHA1(8773654810de760c5dffbb561f43e259b074a61b) ) // good
3343   ROM_LOAD16_WORD_SWAP( "mpr20996.3",    0x0800000, 0x0400000, CRC(993c3859) SHA1(93f95e3e080a08961784482607919c1ab3eeb5e5) ) // good
3344   ROM_LOAD16_WORD_SWAP( "mpr20997.4",    0x0c00000, 0x0400000, CRC(f0bf64a4) SHA1(f51431f1a736bbc498fa0baa1f8570f89984d9f9) ) // good
3345   ROM_LOAD16_WORD_SWAP( "mpr20998.5",    0x1000000, 0x0400000, CRC(d3b19786) SHA1(1933e57272cd68cc323922fa93a9af97dcef8450) ) // good
3346   ROM_LOAD16_WORD_SWAP( "mpr20999.6",    0x1400000, 0x0400000, CRC(82e31f25) SHA1(0cf74af14abb6ede21d19bc22041214232751594) ) // good
3347   ROM_LOAD16_WORD_SWAP( "mpr20994.1",    0x1800000, 0x0400000, CRC(a69243a0) SHA1(e5a1b6ec62bdd5b015ed6cf48f5a6aabaf4bd837) ) // good
3348   ROM_LOAD16_WORD_SWAP( "mpr21001.8",    0x1c00000, 0x0400000, CRC(95fbe549) SHA1(8cfb48f353b2849600373d66f293f103bca700df) ) // good
3349
3350   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
3351   ROM_LOAD( "myfairld.nv", 0x0000, 0x0080, CRC(c7cf3a5a) SHA1(5365f38047821305658f94395f03cf2c49c87576) )
3352ROM_END
3353
3354ROM_START( othellos )
3355   STV_BIOS
3356
3357   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3358   ROM_LOAD16_WORD_SWAP( "mpr20967.7",    0x0200000, 0x0200000, CRC(efc05b97) SHA1(a533366c3aaba90dcac8f3654db9ad902efca258) ) // good
3359   ROM_LOAD16_WORD_SWAP( "mpr20963.2",    0x0400000, 0x0400000, CRC(2cc4f141) SHA1(8bd1998aff8615b34d119fab3637a08ed6e8e1e4) ) // good
3360   ROM_LOAD16_WORD_SWAP( "mpr20964.3",    0x0800000, 0x0400000, CRC(5f5cda94) SHA1(616be219a2512e80c875eddf05137c23aedf6f65) ) // good
3361   ROM_LOAD16_WORD_SWAP( "mpr20965.4",    0x0c00000, 0x0400000, CRC(37044f3e) SHA1(cbc071554cfd8bb12a337c04b169de6c6309c3ab) ) // good
3362   ROM_LOAD16_WORD_SWAP( "mpr20966.5",    0x1000000, 0x0400000, CRC(b94b83de) SHA1(ba1b3135d0ad057f0786f94c9d06b5e347bedea8) ) // good
3363ROM_END
3364
3365ROM_START( pblbeach )
3366   STV_BIOS
3367
3368   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3369   ROM_LOAD16_BYTE( "epr18852.13",               0x0000001, 0x0080000, CRC(d12414ec) SHA1(0f42ec9e41983781b6892622b00398a102072aa7) ) // bad
3370   ROM_RELOAD ( 0x0100001, 0x0080000 )
3371
3372   ROM_LOAD16_WORD_SWAP( "mpr18853.2",    0x0400000, 0x0400000, CRC(b9268c97) SHA1(8734e3f0e6b2849d173e3acc9d0308084a4e84fd) ) // good
3373   ROM_LOAD16_WORD_SWAP( "mpr18854.3",    0x0800000, 0x0400000, CRC(3113c8bc) SHA1(4e4600646ddd1978988d27430ffdf0d1d405b804) ) // good
3374   ROM_LOAD16_WORD_SWAP( "mpr18855.4",    0x0c00000, 0x0400000, CRC(daf6ad0c) SHA1(2a14a6a42e4eb68abb7a427e43062dfde2d13c5c) ) // good
3375   ROM_LOAD16_WORD_SWAP( "mpr18856.5",    0x1000000, 0x0400000, CRC(214cef24) SHA1(f62b462170b377cff16bb6c6126cbba00b013a87) ) // good
3376ROM_END
3377
3378ROM_START( prikura )
3379   STV_BIOS
3380
3381   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3382   ROM_LOAD16_WORD_SWAP( "mpr19337.7",    0x0200000, 0x0200000, CRC(76f69ff3) SHA1(5af2e1eb3288d70c2a1c71d0b6370125d65c7757) ) // good
3383   ROM_LOAD16_WORD_SWAP( "mpr19333.2",    0x0400000, 0x0400000, CRC(eb57a6a6) SHA1(cdacaa7a2fb1a343195e2ac5fd02eabf27f89ccd) ) // good
3384   ROM_LOAD16_WORD_SWAP( "mpr19334.3",    0x0800000, 0x0400000, CRC(c9979981) SHA1(be491a4ac118d5025d6a6f2d9267a6d52f21d2b6) ) // good
3385   ROM_LOAD16_WORD_SWAP( "mpr19335.4",    0x0c00000, 0x0400000, CRC(9e000140) SHA1(9b7dc3dc7f9dc048d2fcbc2b44ae79a631ceb381) ) // good
3386   ROM_LOAD16_WORD_SWAP( "mpr19336.5",    0x1000000, 0x0400000, CRC(2363fa4b) SHA1(f45e53352520be4ea313eeab87bcab83f479d5a8) ) // good
3387ROM_END
3388
3389ROM_START( puyosun )
3390   STV_BIOS
3391
3392   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3393   ROM_LOAD16_BYTE( "epr19531.13",               0x0000001, 0x0080000, CRC(ac81024f) SHA1(b22c7c1798fade7ae992ff83b138dd23e6292d3f) ) // bad
3394   ROM_RELOAD ( 0x0100001, 0x0080000 )
3395
3396   ROM_LOAD16_WORD_SWAP( "mpr19533.2",    0x0400000, 0x0400000, CRC(17ec54ba) SHA1(d4cdc86926519291cc78980ec513e1cfc677e76e) ) // good
3397   ROM_LOAD16_WORD_SWAP( "mpr19534.3",    0x0800000, 0x0400000, CRC(820e4781) SHA1(7ea5626ad4e1929a5ec28a99ec12bc364df8f70d) ) // good
3398   ROM_LOAD16_WORD_SWAP( "mpr19535.4",    0x0c00000, 0x0400000, CRC(94fadfa4) SHA1(a7d0727cf601e00f1ea31e6bf3e591349c3f6030) ) // good
3399   ROM_LOAD16_WORD_SWAP( "mpr19536.5",    0x1000000, 0x0400000, CRC(5765bc9c) SHA1(b217c292e7cc8ed73a39a3ae7009bc9dd031e376) ) // good
3400   ROM_LOAD16_WORD_SWAP( "mpr19537.6",    0x1400000, 0x0400000, CRC(8b736686) SHA1(aec347c0f3e5dd8646e85f68d71ca9acc3bf62c3) ) // good
3401   ROM_LOAD16_WORD_SWAP( "mpr19532.1",    0x1800000, 0x0400000, CRC(985f0c9d) SHA1(de1ad42ef3cf3f4f071e9801696407be7ae29d21) ) // good
3402   ROM_LOAD16_WORD_SWAP( "mpr19538.8",    0x1c00000, 0x0400000, CRC(915a723e) SHA1(96480441a69d6aad3887ed6f46b0a6bebfb752aa) ) // good
3403   ROM_LOAD16_WORD_SWAP( "mpr19539.9",    0x2000000, 0x0400000, CRC(72a297e5) SHA1(679987e62118dd1bf7c074f4b88678e1a1187437) ) // good
3404ROM_END
3405
3406ROM_START( rsgun )
3407   STV_BIOS
3408
3409   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3410   ROM_LOAD16_WORD_SWAP( "mpr20958.7",   0x0200000, 0x0200000, CRC(cbe5a449) SHA1(b4744ab71ccbadda1921ba43dd1148e57c0f84c5) ) // good (was .11s)
3411   ROM_LOAD16_WORD_SWAP( "mpr20959.2",   0x0400000, 0x0400000, CRC(a953330b) SHA1(965274a7297cb88e281fcbdd3ec5025c6463cc7b) ) // good (was .12)
3412   ROM_LOAD16_WORD_SWAP( "mpr20960.3",   0x0800000, 0x0400000, CRC(b5ab9053) SHA1(87c5d077eb1219c35fa65b4e11d5b62e826f5236) ) // good (was .13)
3413   ROM_LOAD16_WORD_SWAP( "mpr20961.4",   0x0c00000, 0x0400000, CRC(0e06295c) SHA1(0ec2842622f3e9dc5689abd58aeddc7e5603b97a) ) // good (was .14)
3414   ROM_LOAD16_WORD_SWAP( "mpr20962.5",   0x1000000, 0x0400000, CRC(f1e6c7fc) SHA1(0ba0972f1bc7c56f4e0589d3e363523cea988bb0) ) // good (was .15)
3415   /*Without the following the game crashes,maybe we need to mirror the previous roms in this location?*/
3416   //ROM_FILL(                             0x1400000, 0x0c00000, 0x00 )
3417ROM_END
3418
3419ROM_START( sandor )
3420   STV_BIOS
3421
3422   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3423   ROM_LOAD16_BYTE( "sando-r.13",               0x0000001, 0x0100000, CRC(fe63a239) SHA1(01502d4494f968443581cd2c74f25967d41f775e) )
3424
3425   ROM_LOAD16_WORD_SWAP( "mpr18635.8",   0x1c00000, 0x0400000, CRC(441e1368) SHA1(acb2a7e8d44c2203b8d3c7a7b70e20ffb120bebf) ) // good
3426   ROM_RELOAD(                           0x0400000, 0x0400000 )
3427   ROM_LOAD16_WORD_SWAP( "mpr18636.9",   0x2000000, 0x0400000, CRC(fff1dd80) SHA1(36b8e1526a4370ae33fd4671850faf51c448bca4) ) // good
3428   ROM_RELOAD(                           0x0800000, 0x0400000 )
3429   ROM_LOAD16_WORD_SWAP( "mpr18637.10",  0x2400000, 0x0400000, CRC(83aced0f) SHA1(6cd1702b9c2655dc4f56c666607c333f62b09fc0) ) // good
3430   ROM_RELOAD(                           0x0c00000, 0x0400000 )
3431   ROM_LOAD16_WORD_SWAP( "mpr18638.11",  0x2800000, 0x0400000, CRC(caab531b) SHA1(a77bdcc27d183896c0ed576eeebcc1785d93669e) ) // good
3432   ROM_RELOAD(                           0x1000000, 0x0400000 )
3433ROM_END
3434
3435
3436/*
3437Treasure Hunt
3438Deniam (Licensed to Sega Enterprises, Ltd), 1997
3439
3440PCB Number: LEX-0704
3441
3442This is a non-Sega-manufactured STV cart which works with Japanese and USA bioses.
3443The cart is mostly the same as the Sega carts, containing not a lot except some ROMs
3444and logic chips.
3445
3446On the top side, there are two 27C040 EPROMs and positions for 5 maskROMs, but only 4 of
3447them are populated. In between the two eproms is an unpopulated position for a TSOP40 flashROM.
3448On the bottom are locations for 5 maskROMs (none are populated) and also some logic ICs.
3449*/
3450
3451ROM_START( thunt )
3452   STV_BIOS
3453
3454   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3455   ROM_LOAD16_BYTE( "th-ic7_2.stv",    0x0200000, 0x0080000, CRC(c4e993de) SHA1(7aa433bc2623cb19a09d4ef4c8233a2d29901020) )
3456   ROM_LOAD16_BYTE( "th-ic7_1.stv",    0x0200001, 0x0080000, CRC(1355cc18) SHA1(a9b731228a807b2b01f933fe0f7dcdbadaf89b7e) )
3457
3458   ROM_LOAD16_WORD_SWAP( "th-e-2.ic2",   0x0400000, 0x0400000, CRC(47315694) SHA1(4a7cc195b98dbca146f5efe3b5b35be0f13b2f4a) )
3459   ROM_LOAD16_WORD_SWAP( "th-e-3.ic3",   0x0800000, 0x0400000, CRC(c9290b44) SHA1(4e51e667edf330cc20e600cf1500f332cc533e20) )
3460   ROM_LOAD16_WORD_SWAP( "th-e-4.ic4",   0x0c00000, 0x0400000, CRC(c672e40b) SHA1(4ba189de7b8fb5ca45fb15c89cdaf0f860831d52) )
3461   ROM_LOAD16_WORD_SWAP( "th-e-5.ic5",   0x1000000, 0x0400000, CRC(3914b805) SHA1(1331ce82ba0bdfc76fe3456a5252e69c00e2cf1f) )
3462ROM_END
3463
3464ROM_START( thuntk )
3465   STV_BIOS
3466
3467   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3468   ROM_LOAD16_BYTE( "2.ic13_2",    0x0200000, 0x0080000, CRC(6cae2926) SHA1(e8d5745b4228de24672da5017cb3dab58344f59f) )
3469   ROM_LOAD16_BYTE( "1.ic13_1",    0x0200001, 0x0080000, CRC(460727c8) SHA1(da7171b65734264e10692e3408ac93beb374c65e) )
3470
3471   ROM_LOAD( "bom210-10.ic2",   0x1c00000, 0x0400000, CRC(f59d0827) SHA1(2bed4b2c78e9b4e9332f576e1b264a6343f4cfff) )
3472   ROM_RELOAD(                  0x0400000, 0x0400000 )
3473   ROM_LOAD( "bom210-11.ic3",   0x2000000, 0x0400000, CRC(44e5a13e) SHA1(aee3c06662a1d083f3bd01292cf2694132f63533) )
3474   ROM_RELOAD(                  0x0800000, 0x0400000 )
3475   ROM_LOAD( "bom210-12.ic4",   0x2400000, 0x0400000, CRC(deabc701) SHA1(cb313ae9bf6f115682fc76647a999e12c98f6120) )
3476   ROM_RELOAD(                  0x0c00000, 0x0400000 )
3477   ROM_LOAD( "bom210-13.ic5",   0x2800000, 0x0400000, CRC(5ece1d5c) SHA1(6d88f71b485bf2b3c164fa22f1c7ecaba4b3f5b1) )
3478   ROM_RELOAD(                  0x1000000, 0x0400000 )
3479ROM_END
3480
3481
3482ROM_START( sanjeon )
3483   STV_BIOS
3484
3485   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3486   ROM_LOAD16_BYTE( "ic11",               0x0000001, 0x0200000, CRC(9abae8d4) SHA1(ddbe4c8fff8fa59d63e278e95f245145d2da8aeb) )
3487
3488   ROM_LOAD( "ic13",    0x0400000, 0x0200000, CRC(f72c1d13) SHA1(a2b168d187034024b83fbbe2f5eec78816285da9) ) // ic2 good
3489   ROM_LOAD( "ic14",    0x0600000, 0x0200000, CRC(bcd72105) SHA1(fb88a1f2589fef5d9845027646259ec8e781771b) ) // ic2 good
3490   ROM_LOAD( "ic15",    0x0800000, 0x0200000, CRC(8c9c8352) SHA1(312e9e6435c6e9a4a19b72e234b087d4f5b069a5) ) // ic3 good
3491   ROM_LOAD( "ic16",    0x0a00000, 0x0200000, CRC(07e11512) SHA1(5fb5e93a167aae501bd799aba98f7dbc3762a795) ) // ic3 good
3492   ROM_LOAD( "ic17",    0x0c00000, 0x0200000, CRC(46b7b344) SHA1(a325b724e6346f585582bb2581d3063b1c8ddee9) ) // ic4 good
3493   ROM_LOAD( "ic18",    0x0e00000, 0x0200000, CRC(d48404e1) SHA1(e4927d17cb19f6825f41b41056b89de224cf97de) ) // ic4 good
3494   ROM_LOAD( "ic19",    0x1000000, 0x0200000, CRC(33d23bb9) SHA1(0179438a0b14ad7eb553a24d86fae778671fcc49) ) // ic5 good
3495   ROM_LOAD( "ic20",    0x1200000, 0x0200000, CRC(f8cc1038) SHA1(06bcb25eb5df77bd503b0692a96ec66c00976fe9) ) // ic5 good
3496   ROM_LOAD( "ic21",    0x1400000, 0x0200000, CRC(74ceb649) SHA1(91b7eb699b7167f890528149178644a74ef3ad17) ) // ic6 good
3497   ROM_LOAD( "ic22",    0x1600000, 0x0200000, CRC(85f31277) SHA1(277c28d44cabd9081a8151d6ec27d47b5606435a) ) // ic6 good
3498   ROM_LOAD( "ic12",    0x1800000, 0x0400000, CRC(d5ebc84e) SHA1(f990b793cdfadbbac69c680191660f4a2f282ba2) ) // ic1 good
3499ROM_END
3500
3501
3502ROM_START( sasissu )
3503   STV_BIOS
3504
3505   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3506   ROM_LOAD16_BYTE( "epr20542.13",               0x0000001, 0x0100000, CRC(0e632db5) SHA1(9bc52794892eec22d381387d13a0388042e30714) )
3507
3508   ROM_LOAD16_WORD_SWAP( "mpr20544.2",    0x0400000, 0x0400000, CRC(661fff5e) SHA1(41f4ddda7adf004b52cc9a076606a60f31947d19) ) // good
3509   ROM_LOAD16_WORD_SWAP( "mpr20545.3",    0x0800000, 0x0400000, CRC(8e3a37be) SHA1(a3227cdc4f03bb088e7f9aed225b238da3283e01) ) // good
3510   ROM_LOAD16_WORD_SWAP( "mpr20546.4",    0x0c00000, 0x0400000, CRC(72020886) SHA1(e80bdeb11b726eb23f2283950d65d55e31a5672e) ) // good
3511   ROM_LOAD16_WORD_SWAP( "mpr20547.5",    0x1000000, 0x0400000, CRC(8362e397) SHA1(71f13689a60572a04b91417a9a48adfd3bd0f5dc) ) // good
3512   ROM_LOAD16_WORD_SWAP( "mpr20548.6",    0x1400000, 0x0400000, CRC(e37534d9) SHA1(79988cbb1537ca99fdd0288a86564fe1f714d052) ) // good
3513   ROM_LOAD16_WORD_SWAP( "mpr20543.1",    0x1800000, 0x0400000, CRC(1f688cdf) SHA1(a90c1011119adb50e0d9d5cd3d7616a307b2d7e8) ) // good
3514ROM_END
3515
3516/* set to 1 player to test */
3517ROM_START( seabass )
3518   STV_BIOS
3519
3520   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3521   ROM_LOAD16_BYTE( "seabassf.13",               0x0000001, 0x0100000, CRC(6d7c39cc) SHA1(d9d1663134420b75c65ee07d7d547254785f2f83) )
3522
3523   ROM_LOAD16_WORD_SWAP( "mpr20551.2",    0x0400000, 0x0400000, CRC(9a0c6dd8) SHA1(26600372cc673ce3678945f4b5dc4e3ab31643a4) ) // good
3524   ROM_LOAD16_WORD_SWAP( "mpr20552.3",    0x0800000, 0x0400000, CRC(5f46b0aa) SHA1(1aa576b15971c0ffb4e08d4802246841b31b6f35) ) // good
3525   ROM_LOAD16_WORD_SWAP( "mpr20553.4",    0x0c00000, 0x0400000, CRC(c0f8a6b6) SHA1(2038b9231a950450267be0db24b31d8035db79ad) ) // good
3526   ROM_LOAD16_WORD_SWAP( "mpr20554.5",    0x1000000, 0x0400000, CRC(215fc1f9) SHA1(f042145622ba4bbbcce5f050a4c9eae42cb7adcd) ) // good
3527   ROM_LOAD16_WORD_SWAP( "mpr20555.6",    0x1400000, 0x0400000, CRC(3f5186a9) SHA1(d613f307ab150a7eae358aa449206af05db5f9d7) ) // good
3528   ROM_LOAD16_WORD_SWAP( "mpr20550.1",    0x1800000, 0x0400000, CRC(083e1ca8) SHA1(03944dd8fe86f305ca4bd2d71e2140e03798ffc9) ) // good
3529   ROM_LOAD16_WORD_SWAP( "mpr20556.8",    0x1c00000, 0x0400000, CRC(1fd70c6c) SHA1(d9d2e362d13238216f4f7e10095fb8383bbd91e8) ) // good
3530   ROM_LOAD16_WORD_SWAP( "mpr20557.9",    0x2000000, 0x0400000, CRC(3c9ba442) SHA1(2e5b795cf4cdc11ab3e4887b2f77c7147c6e3eec) ) // good
3531
3532   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
3533   ROM_LOAD( "seabass.nv", 0x0000, 0x0080, CRC(4e7c0944) SHA1(dbba78f6a7f3e7d12d5c4fff36117db82f5f9c01) )
3534ROM_END
3535
3536ROM_START( shanhigw )
3537   STV_BIOS
3538
3539   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3540   ROM_LOAD16_WORD_SWAP( "mpr18341.7",    0x0200000, 0x0200000, CRC(cc5e8646) SHA1(a733616c118140ff3887d30d595533f9a1beae06) ) // good
3541   ROM_LOAD16_WORD_SWAP( "mpr18340.2",    0x0400000, 0x0200000, CRC(8db23212) SHA1(85d604a5c6ab97188716dbcd77d365af12a238fe) ) // good
3542ROM_END
3543
3544ROM_START( shienryu )
3545   STV_BIOS
3546
3547   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3548   ROM_LOAD16_WORD_SWAP( "mpr19631.7",    0x0200000, 0x0200000, CRC(3a4b1abc) SHA1(3b14b7fdebd4817da32ea374c15a38c695ffeff1) ) // good
3549   ROM_LOAD16_WORD_SWAP( "mpr19632.2",    0x0400000, 0x0400000, CRC(985fae46) SHA1(f953bde91805b97b60d2ab9270f9d2933e064d95) ) // good
3550   ROM_LOAD16_WORD_SWAP( "mpr19633.3",    0x0800000, 0x0400000, CRC(e2f0b037) SHA1(97861d09e10ce5d2b10bf5559574b3f489e28077) ) // good
3551
3552   ROM_REGION16_BE( 0x80, "eeprom", 0 )
3553   ROM_LOAD( "eeprom-shienryu.bin", 0x0000, 0x0080, CRC(98db6925) SHA1(e78545e8f62d19f8e00197c62ff0e56f6c85e355) )
3554ROM_END
3555
3556ROM_START( smleague ) /* only runs with the USA bios */
3557   STV_BIOS
3558   ROM_DEFAULT_BIOS( "us" )
3559
3560   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3561   ROM_LOAD16_BYTE( "epr18777.13",               0x0000001, 0x0080000, CRC(8d180866) SHA1(d47ebabab6e06400312d39f68cd818852e496b96) )
3562   ROM_RELOAD ( 0x0100001, 0x0080000 )
3563
3564   ROM_LOAD16_WORD_SWAP( "mpr18778.8",    0x1c00000, 0x0400000, CRC(25e1300e) SHA1(64f3843f62cee34a47244ad5ee78fb2aa35289e3) ) // good
3565   ROM_LOAD16_WORD_SWAP( "mpr18779.9",    0x2000000, 0x0400000, CRC(51e2fabd) SHA1(3aa361149af516f16d7d422596ee82014a183c2b) ) // good
3566   ROM_LOAD16_WORD_SWAP( "mpr18780.10",   0x2400000, 0x0400000, CRC(8cd4dd74) SHA1(9ffec1280b3965d52f643894bdfecdd792028191) ) // good
3567   ROM_LOAD16_WORD_SWAP( "mpr18781.11",   0x2800000, 0x0400000, CRC(13ee41ae) SHA1(cdbaeac4c90b5ee84233c299612f7f28280a6ba6) ) // good
3568   ROM_LOAD16_WORD_SWAP( "mpr18782.12",   0x2c00000, 0x0200000, CRC(9be2270a) SHA1(f2de5cd6b269f123305e30bed2b474019e4f05b8) ) // good
3569ROM_END
3570
3571ROM_START( sokyugrt )
3572   STV_BIOS
3573
3574   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3575   ROM_LOAD16_BYTE( "fpr19188.13",               0x0000001, 0x0100000, CRC(45a27e32) SHA1(96e1bab8bdadf7071afac2a0a6dd8fd8989f12a6) )
3576
3577   ROM_LOAD16_WORD_SWAP( "mpr19189.2",    0x0400000, 0x0400000, CRC(0b202a3e) SHA1(6691b5af2cacd6092ec03886b78c2565953fa297) ) // good
3578   ROM_LOAD16_WORD_SWAP( "mpr19190.3",    0x0800000, 0x0400000, CRC(1777ded8) SHA1(dd332ac79f0a6d82b6bde35b795b2845003dd1a5) ) // good
3579   ROM_LOAD16_WORD_SWAP( "mpr19191.4",    0x0c00000, 0x0400000, CRC(ec6eb07b) SHA1(01fe4832ece8638ea6f4060099d9105fe8092c88) ) // good
3580   ROM_LOAD16_WORD_SWAP( "mpr19192.5",    0x1000000, 0x0200000, CRC(cb544a1e) SHA1(eb3ba9758487d0e8c4bbfc41453fe35b35cce3bf) ) // good
3581ROM_END
3582
3583/* set to 1 player to test */
3584ROM_START( sss )
3585   STV_BIOS
3586
3587   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3588   ROM_LOAD16_BYTE( "epr21488.13",               0x0000001, 0x0080000, CRC(71c9def1) SHA1(a544a0b4046307172d2c1bf426ed24845f87d894) )
3589   ROM_RELOAD ( 0x0100001, 0x0080000 )
3590
3591   ROM_LOAD16_WORD_SWAP( "mpr21489.2",    0x0400000, 0x0400000, CRC(4c85152b) SHA1(78f2f1c31718d5bf631d8813daf9a11ea2a0e451) ) // ic2 good (was .12)
3592   ROM_LOAD16_WORD_SWAP( "mpr21490.3",    0x0800000, 0x0400000, CRC(03da67f8) SHA1(02f9ba7549ca552291dc0ff1b631103015838bba) ) // ic3 good (was .13)
3593   ROM_LOAD16_WORD_SWAP( "mpr21491.4",    0x0c00000, 0x0400000, CRC(cf7ee784) SHA1(af823df2d60d8ef3d17628b95a04136b807ca095) ) // ic4 good (was .14)
3594   ROM_LOAD16_WORD_SWAP( "mpr21492.5",    0x1000000, 0x0400000, CRC(57753894) SHA1(5c51167c158443d02a53d724a5ceb73055876c06) ) // ic5 good (was .15)
3595   ROM_LOAD16_WORD_SWAP( "mpr21493.6",    0x1400000, 0x0400000, CRC(efb2d271) SHA1(a591e48206704fbda5fef3ce69ad279da1017ed6) ) // ic6 good (was .16)
3596
3597   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
3598   ROM_LOAD( "sss.nv", 0x0000, 0x0080, CRC(3473b2f3) SHA1(6480b4b321af8ee6e967710e74f2556c17bfca97) )
3599ROM_END
3600
3601ROM_START( suikoenb )
3602   STV_BIOS
3603
3604   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3605   ROM_LOAD16_BYTE( "fpr17834.13",               0x0000001, 0x0100000, CRC(746ef686) SHA1(e31c317991a687662a8a2a45aed411001e5f1941) )
3606
3607   ROM_LOAD16_WORD_SWAP( "mpr17836.2",    0x0400000, 0x0400000, CRC(55e9642d) SHA1(5198291cd1dce0398eb47760db2c19eae99273b0) ) // good
3608   ROM_LOAD16_WORD_SWAP( "mpr17837.3",    0x0800000, 0x0400000, CRC(13d1e667) SHA1(cd513ceb33cc20032090113b61227638cf3b3998) ) // good
3609   ROM_LOAD16_WORD_SWAP( "mpr17838.4",    0x0c00000, 0x0400000, CRC(f9e70032) SHA1(8efdbcce01bdf77acfdb293545c59bf224a9c7d2) ) // good
3610   ROM_LOAD16_WORD_SWAP( "mpr17839.5",    0x1000000, 0x0400000, CRC(1b2762c5) SHA1(5c7d5fc8a4705249a5b0ea64d51dc3dc95d723f5) ) // good
3611   ROM_LOAD16_WORD_SWAP( "mpr17840.6",    0x1400000, 0x0400000, CRC(0fd4c857) SHA1(42caf22716e834d59e60d45c24f51d95734e63ae) ) // good
3612   ROM_LOAD16_WORD_SWAP( "mpr17835.1",    0x1800000, 0x0400000, CRC(77f5cb43) SHA1(a4f54bc08d73a56caee5b26bea06360568655bd7) ) // good
3613   ROM_LOAD16_WORD_SWAP( "mpr17841.8",    0x1c00000, 0x0400000, CRC(f48beffc) SHA1(92f1730a206f4a0abf7fb0ee1210e083a464ad70) ) // good
3614   ROM_LOAD16_WORD_SWAP( "mpr17842.9",    0x2000000, 0x0400000, CRC(ac8deed7) SHA1(370eb2216b8080d3ddadbd32804db63c4ebac76f) ) // good
3615ROM_END
3616
3617ROM_START( twcup98 )
3618   STV_BIOS
3619
3620   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3621   ROM_LOAD16_BYTE( "epr20819.13",    0x0000001, 0x0100000, CRC(d930dfc8) SHA1(f66cc955181720661a0334fe67fa5750ddf9758b) )
3622
3623   ROM_LOAD16_WORD_SWAP( "mpr20821.2",    0x0400000, 0x0400000, CRC(2d930d23) SHA1(5fcaf4257f3639cb3aa407d2936f616499a09d97) ) // ic2 good (was .12)
3624   ROM_LOAD16_WORD_SWAP( "mpr20822.3",    0x0800000, 0x0400000, CRC(8b33a5e2) SHA1(d5689ac8aad63509febe9aa4077351be09b2d8d4) ) // ic3 good (was .13)
3625   ROM_LOAD16_WORD_SWAP( "mpr20823.4",    0x0c00000, 0x0400000, CRC(6e6d4e95) SHA1(c387d03ba27580c62ac0bf780915fdf41552df6f) ) // ic4 good (was .14)
3626   ROM_LOAD16_WORD_SWAP( "mpr20824.5",    0x1000000, 0x0400000, CRC(4cf18a25) SHA1(310961a5f114fea8938a3f514dffd5231e910a5a) ) // ic5 good (was .15)
3627ROM_END
3628
3629ROM_START( vfkids )
3630   STV_BIOS
3631
3632   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3633   ROM_LOAD16_BYTE( "fpr18914.13",               0x0000001, 0x0100000, CRC(cd35730a) SHA1(645b52b449766beb740ab8f99957f8f431351ceb) )
3634
3635   ROM_LOAD16_WORD_SWAP( "mpr18916.4",    0x0c00000, 0x0400000, CRC(4aae3ddb) SHA1(b75479e73f1bce3f0c27fbd90820fa51eb1914a6) ) // good
3636   ROM_LOAD16_WORD_SWAP( "mpr18917.5",    0x1000000, 0x0400000, CRC(edf6edc3) SHA1(478e958f4f10a8126a00c83feca4a55ad6c25503) ) // good
3637   ROM_LOAD16_WORD_SWAP( "mpr18918.6",    0x1400000, 0x0400000, CRC(d3a95036) SHA1(e300bbbb71fb06027dc539c9bbb12946770ffc95) ) // good
3638   ROM_LOAD16_WORD_SWAP( "mpr18915.1",    0x1800000, 0x0400000, CRC(09cc38e5) SHA1(4dfe0e2f21f746020ec557e62487aa7558cbc1fd) ) // good
3639   ROM_LOAD16_WORD_SWAP( "mpr18919.8",    0x1c00000, 0x0400000, CRC(4ac700de) SHA1(b1a8501f1683de380dfa49c9cabbe28bd70a5b26) ) // good
3640   ROM_LOAD16_WORD_SWAP( "mpr18920.9",    0x2000000, 0x0400000, CRC(0106e36c) SHA1(f7c30dc9fedb9da079dd7d52fdecbeb8721c5dee) ) // good
3641   ROM_LOAD16_WORD_SWAP( "mpr18921.10",   0x2400000, 0x0400000, CRC(c23d51ad) SHA1(0169b7e2df84e8caa2b349843bd0673f6de2195f) ) // good
3642   ROM_LOAD16_WORD_SWAP( "mpr18922.11",   0x2800000, 0x0400000, CRC(99d0ab90) SHA1(e9c82a826cc76ffbe2423913645cf5d5ba2506d6) ) // good
3643   ROM_LOAD16_WORD_SWAP( "mpr18923.12",   0x2c00000, 0x0400000, CRC(30a41ae9) SHA1(78a3d88b5e6cf669b660460ac967daf408038883) ) // good
3644ROM_END
3645
3646ROM_START( vfremix )
3647   STV_BIOS
3648
3649   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3650   ROM_LOAD16_BYTE( "epr17944.13",               0x0000001, 0x0100000, CRC(a5bdc560) SHA1(d3830480a611b7d88760c672ce46a2ea74076487) )
3651
3652   ROM_LOAD16_WORD_SWAP( "mpr17946.2",    0x0400000, 0x0400000, CRC(4cb245f7) SHA1(363d9936b27043b5858c956a45736ac05aefc54e) ) // good
3653   ROM_LOAD16_WORD_SWAP( "mpr17947.3",    0x0800000, 0x0400000, CRC(fef4a9fb) SHA1(1b4bd095962db769da17d3644df10f62d041e914) ) // good
3654   ROM_LOAD16_WORD_SWAP( "mpr17948.4",    0x0c00000, 0x0400000, CRC(3e2b251a) SHA1(be6191c18727d7cbc6399fd4c1aaae59304af30c) ) // good
3655   ROM_LOAD16_WORD_SWAP( "mpr17949.5",    0x1000000, 0x0400000, CRC(b2ecea25) SHA1(320c0e7ce34e81e2fe6400cbeb2cb3ca74426cc8) ) // good
3656   ROM_LOAD16_WORD_SWAP( "mpr17950.6",    0x1400000, 0x0400000, CRC(5b1f981d) SHA1(693b5744d210a2ac8b77e7c8c87f07ca859f8aed) ) // good
3657   ROM_LOAD16_WORD_SWAP( "mpr17945.1",    0x1800000, 0x0200000, CRC(03ede188) SHA1(849c7fab5b97e043fea3deb8df6cc195ccced0e0) ) // good
3658ROM_END
3659
3660/* set to 1 player to test */
3661ROM_START( vmahjong )
3662   STV_BIOS
3663
3664   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3665   ROM_LOAD16_WORD_SWAP( "mpr19620.7",    0x0200000, 0x0200000, CRC(c98de7e5) SHA1(5346f884793bcb080aa01967e91b54ced4a9802f) ) // good
3666   ROM_LOAD16_WORD_SWAP( "mpr19615.2",    0x0400000, 0x0400000, CRC(c62896da) SHA1(52a5b10ca8af31295d2d700349eca038c418b522) ) // good
3667   ROM_LOAD16_WORD_SWAP( "mpr19616.3",    0x0800000, 0x0400000, CRC(f62207c7) SHA1(87e60183365c6f7e62c7a0667f88df0c7f5457fd) ) // good
3668   ROM_LOAD16_WORD_SWAP( "mpr19617.4",    0x0c00000, 0x0400000, CRC(ab667e19) SHA1(2608a567888fe052753d0679d9a831d7706dbc86) ) // good
3669   ROM_LOAD16_WORD_SWAP( "mpr19618.5",    0x1000000, 0x0400000, CRC(9782ceee) SHA1(405dd42706416e128b1e2fde225b5343e9330092) ) // good
3670   ROM_LOAD16_WORD_SWAP( "mpr19619.6",    0x1400000, 0x0400000, CRC(0b76866c) SHA1(10add2993dfe9daf757ec2ff8675390081a93c0a) ) // good
3671   ROM_LOAD16_WORD_SWAP( "mpr19614.1",    0x1800000, 0x0400000, CRC(b83b3f03) SHA1(e5a5919ee74964633eaaf4af2fe04c38604ccf16) ) // good
3672   ROM_LOAD16_WORD_SWAP( "mpr19621.8",    0x1c00000, 0x0400000, CRC(f92616b3) SHA1(61a9dda92a86a02d027260e11b1bad3b0dda9f02) ) // good
3673
3674   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
3675   ROM_LOAD( "vmahjong.nv", 0x0000, 0x0080, CRC(4e6487f4) SHA1(d6d930ab5f21b8c4f42812d08b3ee90f2bc94081) )
3676ROM_END
3677
3678ROM_START( winterht )
3679   STV_BIOS
3680
3681   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3682   ROM_LOAD16_BYTE( "fpr20108.13",    0x0000001, 0x0100000, CRC(1ef9ced0) SHA1(abc90ce341cd17bb77349d611d6879389611f0bf) ) // bad
3683
3684   ROM_LOAD16_WORD_SWAP( "mpr20110.2",    0x0400000, 0x0400000, CRC(238ef832) SHA1(20fade5730ff8e249a1450c41bfdff6e133f4768) ) // good
3685   ROM_LOAD16_WORD_SWAP( "mpr20111.3",    0x0800000, 0x0400000, CRC(b0a86f69) SHA1(e66427f70413ad43fccc38423962c5eeda01094f) ) // good
3686   ROM_LOAD16_WORD_SWAP( "mpr20112.4",    0x0c00000, 0x0400000, CRC(3ba2b49b) SHA1(5ad154a8b774075479d791e29cbaf221d47557fc) ) // good
3687   ROM_LOAD16_WORD_SWAP( "mpr20113.5",    0x1000000, 0x0400000, CRC(8c858b41) SHA1(d05d2980363c8440863fe2fdb39274de246bd4b9) ) // good
3688   ROM_LOAD16_WORD_SWAP( "mpr20114.6",    0x1400000, 0x0400000, CRC(b723862c) SHA1(1e0a08669f16fc4cb647124e0c215233ccb98e5a) ) // good
3689   ROM_LOAD16_WORD_SWAP( "mpr20109.1",    0x1800000, 0x0400000, CRC(c1a713b8) SHA1(a7fefa6e9a1e3aecff5ead41da6fd3aec2ef502a) ) // good
3690   ROM_LOAD16_WORD_SWAP( "mpr20115.8",    0x1c00000, 0x0400000, CRC(dd01f2ad) SHA1(3bb48dc8670d9460fea2a67400ddb573472c2f4f) ) // good
3691ROM_END
3692
3693ROM_START( znpwfv )
3694   STV_BIOS
3695
3696   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3697   ROM_LOAD16_BYTE( "epr20398.13",    0x0000001, 0x0100000, CRC(3fb56a0b) SHA1(13c2fa2d94b106d39e46f71d15fbce3607a5965a) ) // bad
3698
3699   ROM_LOAD16_WORD_SWAP( "mpr20400.2",    0x0400000, 0x0400000, CRC(1edfbe05) SHA1(b0edd3f3d57408101ae6eb0aec742afbb4d289ca) ) // good
3700   ROM_LOAD16_WORD_SWAP( "mpr20401.3",    0x0800000, 0x0400000, CRC(99e98937) SHA1(e1b4d12a0b4d0fe97a62fcc085e19cce77657c99) ) // good
3701   ROM_LOAD16_WORD_SWAP( "mpr20402.4",    0x0c00000, 0x0400000, CRC(4572aa60) SHA1(8b2d76ea8c6e2f472c6ee7c9b6ad6e80e6a1a85a) ) // good
3702   ROM_LOAD16_WORD_SWAP( "mpr20403.5",    0x1000000, 0x0400000, CRC(26a8e13e) SHA1(07f5564b704598e3c3580d3d620ecc4f14549dbd) ) // good
3703   ROM_LOAD16_WORD_SWAP( "mpr20404.6",    0x1400000, 0x0400000, CRC(0b70275d) SHA1(47b8672e19c698dc948760f7091f4c6280e728d0) ) // good
3704   ROM_LOAD16_WORD_SWAP( "mpr20399.1",    0x1800000, 0x0400000, CRC(c178a96e) SHA1(65f4aa05187d48ba8ad4fe75ff6ffe1f8524831d) ) // good
3705   ROM_LOAD16_WORD_SWAP( "mpr20405.8",    0x1c00000, 0x0400000, CRC(f53337b7) SHA1(09a21f81016ee54f10554ae1f790415d7436afe0) ) // good
3706   ROM_LOAD16_WORD_SWAP( "mpr20406.9",    0x2000000, 0x0400000, CRC(b677c175) SHA1(d0de7b5a29928036df0bdfced5a8021c0999eb26) ) // good
3707   ROM_LOAD16_WORD_SWAP( "mpr20407.10",   0x2400000, 0x0400000, CRC(58356050) SHA1(f8fb5a14f4ec516093c785891b05d55ae345754e) ) // good
3708ROM_END
3709
3710ROM_START( danchih )
3711   STV_BIOS
3712
3713   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3714   ROM_LOAD16_WORD_SWAP( "mpr21974.7",    0x0200000, 0x0200000, CRC(e7472793) SHA1(11b7b11cf492eb9cf69b50e7cfac46a5b86849ac) )// good
3715   ROM_LOAD16_WORD_SWAP( "mpr21970.2",    0x0400000, 0x0400000, CRC(34dd7f4d) SHA1(d5c45da94ec5b6584049caf09516f1ad4ba3adb5) )// good
3716   ROM_LOAD16_WORD_SWAP( "mpr21971.3",    0x0800000, 0x0400000, CRC(8995158c) SHA1(fbbd171d67eebf43630d6054bc1b9132f6b38183) )// good
3717   ROM_LOAD16_WORD_SWAP( "mpr21972.4",    0x0c00000, 0x0400000, CRC(68a39090) SHA1(cff1b909c4191660570012eb5e4cb6a7467bc79e) )// good
3718   ROM_LOAD16_WORD_SWAP( "mpr21973.5",    0x1000000, 0x0400000, CRC(b0f23f14) SHA1(4e7076c29fd57bb3ef9af50a6104e39ecda94e06) )// good
3719ROM_END
3720
3721ROM_START( danchiq )
3722   STV_BIOS
3723
3724   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3725   ROM_LOAD16_WORD_SWAP( "ic22",    0x0200000, 0x0200000, CRC(e216bfc8) SHA1(7a08fa32281e272dbf5e7daea50a1800cc225c1b) )//ic 7
3726   ROM_LOAD16_WORD_SWAP( "ic24",    0x0400000, 0x0200000, CRC(b95aa5ac) SHA1(2766c5414643034a0f6d746050557516bd3753df) )//ic 2
3727   ROM_LOAD16_WORD_SWAP( "ic26",    0x0600000, 0x0200000, CRC(df6ebd48) SHA1(fcccafbee1b8b952b07ed0e7e86219eed9cf4a93) )
3728   ROM_LOAD16_WORD_SWAP( "ic28",    0x0800000, 0x0200000, CRC(cf6a2b76) SHA1(1f7522d446d57b78d099bae553133d5e7e54ff70) )//ic 3
3729   ROM_LOAD16_WORD_SWAP( "ic30",    0x0a00000, 0x0200000, CRC(0b6a9901) SHA1(b4c335199d3e49a9ae5d474b10130abc4718cdf9) )
3730   ROM_LOAD16_WORD_SWAP( "ic32",    0x0c00000, 0x0200000, CRC(0b4604f5) SHA1(547cba4a80baf126e87f87529aa933587643d359) )//ic 4
3731   ROM_LOAD16_WORD_SWAP( "ic34",    0x0e00000, 0x0200000, CRC(616e20fa) SHA1(45c175e79b5701db9726d157ff92eee368f4bbf9) )
3732   ROM_LOAD16_WORD_SWAP( "ic36",    0x1000000, 0x0200000, CRC(43474e08) SHA1(30b3ede287d5de93c6e0219bfd0a5d7ed5b6a958) )//ic 5
3733   ROM_LOAD16_WORD_SWAP( "ic23",    0x1200000, 0x0200000, CRC(d080eb71) SHA1(9c39b887697c8872f0cb655cff24282ad3b90e9b) )
3734   ROM_LOAD16_WORD_SWAP( "ic25",    0x1400000, 0x0200000, CRC(9a4109e5) SHA1(ba59caac5f5a80fc52c507d8a47f322a380aa9a1) )//(Untested)
3735ROM_END
3736
3737ROM_START( mausuke )
3738   STV_BIOS
3739
3740   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3741   ROM_LOAD16_BYTE(             "ic13.bin",      0x0000001, 0x0100000, CRC(b456f4cd) SHA1(91cbe703ec7c1dd45eb3b05bdfeb06e3570599d1) )
3742   ROM_RELOAD_PLAIN ( 0x0200000, 0x0100000 ) // needs the rom mapped here to appear 'normal'
3743   ROM_RELOAD_PLAIN ( 0x0300000, 0x0100000 )
3744
3745   ROM_LOAD16_WORD_SWAP( "mcj-00.2",      0x0400000, 0x0200000, CRC(4eeacd6f) SHA1(104ca230f22cd11cc536b34abd482e54791b4d0f) )// good
3746   ROM_LOAD16_WORD_SWAP( "mcj-01.3",      0x0800000, 0x0200000, CRC(365a494b) SHA1(29713dfc83a9ade63ebcc7994d14cd785c4500b9) )// good
3747   ROM_LOAD16_WORD_SWAP( "mcj-02.4",      0x0c00000, 0x0200000, CRC(8b8e4931) SHA1(0c94e2ccb72902d7786d1101a3958504f7151077) )// good
3748   ROM_LOAD16_WORD_SWAP( "mcj-03.5",      0x1000000, 0x0200000, CRC(9015a0e7) SHA1(8ba8a3723267e631169dc1e06620260fbccce4bd) )// good
3749   ROM_LOAD16_WORD_SWAP( "mcj-04.6",      0x1400000, 0x0200000, CRC(9d1beaee) SHA1(c63b61378860319fff2e605c7b9afaa5f1bc4cd2) )// good
3750   ROM_LOAD16_WORD_SWAP( "mcj-05.1",      0x1800000, 0x0200000, CRC(a7626a82) SHA1(c12a099132c5b9234a2de5674f3b8ba5fdd35289) )// good
3751   ROM_LOAD16_WORD_SWAP( "mcj-06.8",      0x1c00000, 0x0200000, CRC(1ab8e90e) SHA1(8e22f03c1791a983eb330b2a9199e5349a0b1baa) )// good
3752ROM_END
3753
3754/* acclaim game, not a standard cart ... */
3755ROM_START( batmanfr )
3756   STV_BIOS
3757
3758   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3759   /* Many thanks to Runik to point this out*/
3760   ROM_LOAD16_BYTE( "350-mpa1.u19",    0x0000000, 0x0100000, CRC(2a5a8c3a) SHA1(374ec55a39ea909cc672e4a629422681d1f2da05) )
3761   ROM_RELOAD(                         0x0200000, 0x0100000 )
3762   ROM_LOAD16_BYTE( "350-mpa1.u16",    0x0000001, 0x0100000, CRC(735e23ab) SHA1(133e2284a07a611aed8ada2707248f392f4509aa) )
3763   ROM_RELOAD(                         0x0200001, 0x0100000 )
3764   ROM_LOAD16_WORD_SWAP( "gfx0.u1",    0x0400000, 0x0400000, CRC(a82d0b7e) SHA1(37a7a177634d51620b1b43e58732987df166c7e6) )
3765   ROM_LOAD16_WORD_SWAP( "gfx1.u3",    0x0800000, 0x0400000, CRC(a41e55d9) SHA1(b896d3a6c36d325c3cece699da54f340a4512703) )
3766   ROM_LOAD16_WORD_SWAP( "gfx2.u5",    0x0c00000, 0x0400000, CRC(4c1ebeb7) SHA1(cdd139652d9484ae5837a39c2fd48d0a8d966d43) )
3767   ROM_LOAD16_WORD_SWAP( "gfx3.u8",    0x1000000, 0x0400000, CRC(f679a3e7) SHA1(db11b033b8bbdd80b81e3bc098bd40ad3a8784f2) )
3768   ROM_LOAD16_WORD_SWAP( "gfx4.u12",   0x1400000, 0x0400000, CRC(52d95242) SHA1(b554a95933c2be4c72fb4226d3bc4775695da2c1) )
3769   ROM_LOAD16_WORD_SWAP( "gfx5.u15",   0x1800000, 0x0400000, CRC(e201f830) SHA1(5aa22fcc8f2e153d1abc3aa4050c594b3942ee67) )
3770   ROM_LOAD16_WORD_SWAP( "gfx6.u18",   0x1c00000, 0x0400000, CRC(c6b381a3) SHA1(46431f1e47c084a0bf85535d35af27471653b008) )
3771
3772   /* it also has an extra adsp sound board, i guess this isn't tested */
3773   ROM_REGION( 0x080000, "wave", 0 ) /* Wave data */
3774   ROM_LOAD( "350snda1.u52",   0x000000, 0x080000, CRC(9027e7a0) SHA1(678df530838b078964a044ce734776f391654e6c) )
3775
3776   ROM_REGION( 0x800000, "adsp_code", 0 ) /* ADSP code */
3777   ROM_LOAD( "snd0.u48",   0x000000, 0x200000, CRC(02b1927c) SHA1(08b21d8b31b0f15c59fb5bb7eaf425e6fe04f7b5) )
3778   ROM_LOAD( "snd1.u49",   0x200000, 0x200000, CRC(58b18eda) SHA1(7f3105fe04d9c0cdfd76e3323f623a4d0f7dad06) )
3779   ROM_LOAD( "snd2.u50",   0x400000, 0x200000, CRC(51d626d6) SHA1(0e68b79dcb653dcba48121ca2d4f692f90afa85e) )
3780   ROM_LOAD( "snd3.u51",   0x600000, 0x200000, CRC(31af26ae) SHA1(2c9f4c078afec55964b5c2a4d00f5c43f2661a04) )
3781ROM_END
3782
3783/*
3784Critter Crusher EXP
3785Sega, 1995.
3786
3787This is a cart for Sega STV system. The game involves hitting 'critters' on
3788screen with a rubber/plastic hammer. The cab has a large LED display to show how many
3789'critters' were hit. The hammer positioning might work like a lightgun and the 'hitting'
3790may be like pulling the lightgun trigger?
3791
3792The ROM cart appears to be a re-used Virtua Fighter Remix cart??
3793On top there is one 27C040 EPROM, EPR-18821 @ IC13
37946 maskROMs, MPR-17945 to MPR-17950 (already dumped, known Virtua Fighter Remix ROMs)
3795On the other side of the PCB are 2 more maskROMs, MPR-18788 @ IC9 and MPR-18789 @ IC8
3796
3797*/
3798
3799ROM_START( critcrsh ) /* Must use Europe or Asia BIOS */
3800   STV_BIOS
3801   ROM_DEFAULT_BIOS( "euro" )
3802
3803   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3804   ROM_LOAD16_BYTE( "epr-18821.ic13",  0x0000001, 0x0080000, CRC(9a6658e2) SHA1(16dbae3d9ab584713afcb403f89fe71049609245) )
3805   ROM_RELOAD ( 0x0100001, 0x0080000 )
3806
3807//  ROM_LOAD16_WORD_SWAP( "mpr17946.2",    0x0400000, 0x0400000, CRC(4cb245f7) SHA1(363d9936b27043b5858c956a45736ac05aefc54e) ) // good
3808//  ROM_LOAD16_WORD_SWAP( "mpr17947.3",    0x0800000, 0x0400000, CRC(fef4a9fb) SHA1(1b4bd095962db769da17d3644df10f62d041e914) ) // good
3809//  ROM_LOAD16_WORD_SWAP( "mpr17948.4",    0x0c00000, 0x0400000, CRC(3e2b251a) SHA1(be6191c18727d7cbc6399fd4c1aaae59304af30c) ) // good
3810//  ROM_LOAD16_WORD_SWAP( "mpr17949.5",    0x1000000, 0x0400000, CRC(b2ecea25) SHA1(320c0e7ce34e81e2fe6400cbeb2cb3ca74426cc8) ) // good
3811//  ROM_LOAD16_WORD_SWAP( "mpr17950.6",    0x1400000, 0x0400000, CRC(5b1f981d) SHA1(693b5744d210a2ac8b77e7c8c87f07ca859f8aed) ) // good
3812//  ROM_LOAD16_WORD_SWAP( "mpr17945.1",    0x1800000, 0x0200000, CRC(03ede188) SHA1(849c7fab5b97e043fea3deb8df6cc195ccced0e0) ) // good
3813   ROM_LOAD16_WORD_SWAP( "mpr-18789.ic8", 0x1c00000, 0x0400000, CRC(b388616f) SHA1(0b2c5a547c3a6a8fb9f4ca54336cf6dc9adb8c6a) ) // good
3814   ROM_LOAD16_WORD_SWAP( "mpr-18788.ic9", 0x2000000, 0x0400000, CRC(feae5867) SHA1(7d2e47d5ab18700a246d53fdb7872a905cdac55a) ) // good
3815
3816   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
3817   ROM_LOAD( "critcrsh.nv", 0x0000, 0x0080, CRC(3da9860e) SHA1(05b315aa71fcfc4e617266e1c5e4954eccbf7854) )
3818ROM_END
3819
3820ROM_START( sfish2 )
3821//  STV_BIOS // - sports fishing 2 uses its own bios
3822
3823   ROM_REGION( 0x080000, "maincpu", 0 ) /* SH2 code */
3824   ROM_LOAD16_WORD_SWAP( "epr18343.bin",   0x000000, 0x080000, CRC(48e2eecf) SHA1(a38bfbd5f279525e413b18b5ed3f37f6e9e31cdc) ) /* sport fishing 2 bios */
3825   ROM_REGION( 0x080000, "slave", 0 ) /* SH2 code */
3826   ROM_COPY( "maincpu",0,0,0x080000)
3827
3828   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3829   ROM_LOAD(             "epr18427.bin",      0x0000000, 0x0100000, CRC(3f25bec8) SHA1(43a5342b882d5aec0f35a8777cb475659f43b1c4) )
3830   ROM_LOAD16_WORD_SWAP( "mpr18273.ic2",      0x0400000, 0x0200000, NO_DUMP )
3831   ROM_LOAD16_WORD_SWAP( "mpr18274.ic3",      0x0800000, 0x0200000, NO_DUMP )
3832   ROM_LOAD16_WORD_SWAP( "mpr18275.ic4",      0x0c00000, 0x0200000, NO_DUMP )
3833
3834   DISK_REGION( "cdrom" )
3835   DISK_IMAGE( "sfish2", 0, SHA1(a10073d83bbbe16e16f69ad48565821576557d61) )
3836ROM_END
3837
3838ROM_START( sfish2j )
3839//  STV_BIOS // - sports fishing 2 uses its own bios
3840
3841   ROM_REGION( 0x080000, "maincpu", 0 ) /* SH2 code */
3842   ROM_LOAD16_WORD_SWAP( "epr18343.bin",   0x000000, 0x080000, CRC(48e2eecf) SHA1(a38bfbd5f279525e413b18b5ed3f37f6e9e31cdc) ) /* sport fishing 2 bios */
3843   ROM_REGION( 0x080000, "slave", 0 ) /* SH2 code */
3844   ROM_COPY( "maincpu",0,0,0x080000)
3845
3846   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3847   ROM_LOAD16_BYTE(             "epr18344.a",      0x0000001, 0x0100000,  CRC(5a7de018) SHA1(88e0c2a9a9d4ebf699878c0aa9737af85f95ccf8) )
3848
3849   ROM_LOAD16_WORD_SWAP( "mpr18273.ic2",      0x0400000, 0x0200000, NO_DUMP )
3850   ROM_LOAD16_WORD_SWAP( "mpr18274.ic3",      0x0800000, 0x0200000, NO_DUMP )
3851
3852   DISK_REGION( "cdrom" )
3853   DISK_IMAGE( "sfish2", 0, SHA1(a10073d83bbbe16e16f69ad48565821576557d61) )
3854ROM_END
3855
3856
3857ROM_START( magzun )
3858   STV_BIOS
3859
3860   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3861   ROM_LOAD16_BYTE( "flash.ic13",               0x0000001, 0x0100000, CRC(e6f0aca0) SHA1(251d4d9c5a332d13af3a144c5eb9d8e7836bdd1b) ) // good
3862
3863   ROM_LOAD16_WORD_SWAP( "mpr-19354.ic2",    0x0400000, 0x0400000, CRC(a23822e7) SHA1(10ca5d39dcaaf35b80168a08d8a18d77fba1d2ce) ) // good
3864   ROM_LOAD16_WORD_SWAP( "mpr-19355.ic3",    0x0800000, 0x0400000, CRC(d70e5ebc) SHA1(2d560f6b6e693b2b91cf5ff5c4f0890cc2176f91) ) // good
3865   ROM_LOAD16_WORD_SWAP( "mpr-19356.ic4",    0x0c00000, 0x0400000, CRC(3bc43fe9) SHA1(f72b0f3208e2f411f4c9cc76c317a605acd32a67) ) // good
3866   ROM_LOAD16_WORD_SWAP( "mpr-19357.ic5",    0x1000000, 0x0400000, CRC(aa749370) SHA1(f09b0aa94fcc983419aaf2465dae5c9c64606158) ) // good
3867   ROM_LOAD16_WORD_SWAP( "mpr-19358.ic6",    0x1400000, 0x0400000, CRC(0969f1ec) SHA1(25b9671f0975172f283458d46e160080dd1d19e9) ) // good
3868   ROM_LOAD16_WORD_SWAP( "mpr-19359.ic1",    0x1800000, 0x0400000, CRC(b0d06f9c) SHA1(19e04c9c3a0bea5950aba8e1975962fa37722f32) ) // good
3869
3870   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 3 players
3871   ROM_LOAD( "magzun.nv", 0x0000, 0x0080, CRC(42700321) SHA1(1f2ba760c410312539c8677223edcd1cda3b51d4) )
3872ROM_END
3873
3874
3875ROM_START( stress )
3876   STV_BIOS
3877
3878   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3879   ROM_LOAD16_BYTE( "epr-21300a.ic13",    0x0000001, 0x0100000, CRC(899d829e) SHA1(b6c6da92dc108353998b29c0659d288645541519) ) // good
3880
3881   ROM_LOAD16_WORD_SWAP( "mpr-21290.ic2",    0x0400000, 0x0400000, CRC(a49d29f3) SHA1(8f6c26fd9e94a9e03dd0029026d205cf481fe151) ) // good
3882   ROM_LOAD16_WORD_SWAP( "mpr-21291.ic3",    0x0800000, 0x0400000, CRC(9452ba20) SHA1(8a9ff546901715f99bb911616c74ae30ebd7c6d7) ) // good
3883   ROM_LOAD16_WORD_SWAP( "mpr-21292.ic4",    0x0c00000, 0x0400000, CRC(f60268e2) SHA1(5c2febb94553a941a68e9611617750a89c82e783) ) // good
3884   ROM_LOAD16_WORD_SWAP( "mpr-21293.ic5",    0x1000000, 0x0400000, CRC(794946e0) SHA1(7881adb92fbf3efecb88f30834cdd1ed863b0b0e) ) // good
3885   ROM_LOAD16_WORD_SWAP( "mpr-21294.ic6",    0x1400000, 0x0400000, CRC(550843bb) SHA1(5e278a0ae60f7bee23b5f1ee10b8ce31effc9718) ) // good
3886   ROM_LOAD16_WORD_SWAP( "mpr-21289.ic1",    0x1800000, 0x0400000, CRC(c2ee8bea) SHA1(5fa0e6b492cc272c33b01adbef9233e6c8098827) ) // good
3887   ROM_LOAD16_WORD_SWAP( "mpr-21296.ic8",    0x1c00000, 0x0400000, CRC(b825c42a) SHA1(7c6f737b69b9283345f8fa23cb1d110b9b5f3d7e) ) // good
3888   ROM_LOAD16_WORD_SWAP( "mpr-21297.ic9",    0x2000000, 0x0400000, CRC(4bff7469) SHA1(8a36405a1a292d60b5918e604b460ed98740fae3) ) // good
3889   ROM_LOAD16_WORD_SWAP( "mpr-21298.ic10",   0x2400000, 0x0400000, CRC(68d07144) SHA1(5021f43d19105b484135ebddd3fa203233096c98) ) // good
3890   ROM_LOAD16_WORD_SWAP( "mpr-21299.ic11",   0x2800000, 0x0400000, CRC(ecc521c6) SHA1(f7ed4dd1cbe179652fdfdde34929b41a1fdcf9e2) ) // good
3891ROM_END
3892
3893/* the rom test for this is in 'each game test'  */
3894ROM_START( nclubv3 )
3895   STV_BIOS
3896
3897   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3898
3899   ROM_LOAD16_WORD_SWAP( "ic22",    0x0200000, 0x0200000, CRC(b4008ed0) SHA1(acb3784acad971eb5f4920760dc23a16330e7bad) ) // OK
3900   ROM_LOAD16_WORD_SWAP( "ic24",    0x0400000, 0x0200000, CRC(4e894850) SHA1(eb7c3399505a45816701197a45062b9f34e5a3e1) ) // OK
3901   ROM_LOAD16_WORD_SWAP( "ic26",    0x0600000, 0x0200000, CRC(5b6b023f) SHA1(cf17c5857d85d4326dfe2ce40cf96989f9f78ecd) ) // OK
3902   ROM_LOAD16_WORD_SWAP( "ic28",    0x0800000, 0x0200000, CRC(b7beab03) SHA1(de703e461a2bdd87b0695bd2f16e4c97d11bcf92) ) // OK
3903   ROM_LOAD16_WORD_SWAP( "ic30",    0x0a00000, 0x0200000, CRC(a9f81069) SHA1(60d88c7c20178a00d6927c37069ab0c374ebf51e) ) // OK
3904   ROM_LOAD16_WORD_SWAP( "ic32",    0x0c00000, 0x0200000, CRC(02708d66) SHA1(6881b0b05e55989953a16f6ba503ba891b849c07) ) // OK
3905   ROM_LOAD16_WORD_SWAP( "ic34",    0x0e00000, 0x0200000, CRC(c79d0537) SHA1(9d595f718ff8f8ff7ca88100f35c589d5f9b4216) ) // OK
3906   ROM_LOAD16_WORD_SWAP( "ic36",    0x1000000, 0x0200000, CRC(0c9df896) SHA1(4d8c18205e7aa90bfaa677ecff2b65128f2ad47c) ) // OK
3907   ROM_LOAD16_WORD_SWAP( "ic23",    0x1200000, 0x0200000, CRC(bd922829) SHA1(4c6f988173e439a05a77da043d856e142b0da831) ) // OK
3908   ROM_LOAD16_WORD_SWAP( "ic25",    0x1400000, 0x0200000, CRC(f77f9e24) SHA1(9a9636114e74c1fd7bd67db8005af02ef6a75ab1) ) // OK
3909
3910   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
3911   ROM_LOAD( "nclubv3.nv", 0x0000, 0x0080, CRC(9122a9e9) SHA1(5318994905e005567709c41449547c545182bece) )
3912ROM_END
3913
3914ROM_START( techbowl ) // set to 1p
3915   STV_BIOS
3916
3917   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3918
3919   ROM_LOAD16_WORD_SWAP( "ic22",    0x0200000, 0x0200000, CRC(5058db21) SHA1(eec908bbfb9ec0fdca0002e69f32c1c030086456) ) // OK
3920   ROM_LOAD16_WORD_SWAP( "ic24",    0x0400000, 0x0200000, CRC(34090f6d) SHA1(b8bc344ab826d5c9584afb01dba1c720b8dbc74d) ) // OK
3921   ROM_LOAD16_WORD_SWAP( "ic26",    0x0600000, 0x0200000, CRC(fb073352) SHA1(a5164aa5854ab3095f704ab73b6e4fb9ed0e0785) ) // OK
3922   ROM_LOAD16_WORD_SWAP( "ic28",    0x0800000, 0x0200000, CRC(530e0ceb) SHA1(8d14eb9dbf253a4563587d256a15492384e7ca5c) ) // OK
3923   ROM_LOAD16_WORD_SWAP( "ic30",    0x0a00000, 0x0200000, CRC(8d89877e) SHA1(7d76d48d64d7ac5411d714a4bb83f37e3e5b8df6) ) // OK
3924
3925   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
3926   ROM_LOAD( "techbowl.nv", 0x0000, 0x0080, CRC(5bebc2b7) SHA1(e189e891e1753059fbaad4ce82ddf191d5e8176a) )
3927ROM_END
3928
3929ROM_START( micrombc ) // set to 1p
3930   STV_BIOS
3931
3932   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3933
3934   ROM_LOAD16_WORD_SWAP( "ic22",    0x0200000, 0x0200000, CRC(8385bc45) SHA1(0bd60d7560cb2313d68470d0572850a7b8c501fd) ) // OK
3935   ROM_LOAD16_WORD_SWAP( "ic24",    0x0400000, 0x0200000, CRC(84ecb42f) SHA1(005dee9a0912d4b1b7f5157bc3cde96548c1e348) ) // OK
3936   ROM_LOAD16_WORD_SWAP( "ic26",    0x0600000, 0x0200000, CRC(869bc19c) SHA1(638125007d331beef567c976ea6f4e7a21acdb64) ) // OK
3937   ROM_LOAD16_WORD_SWAP( "ic28",    0x0800000, 0x0200000, CRC(0c3db354) SHA1(c4d43da7cea1b4d5ca3ac545afde10344a4a385b) ) // OK
3938   ROM_LOAD16_WORD_SWAP( "ic30",    0x0a00000, 0x0200000, CRC(03b9eacf) SHA1(d69c10f7613d9f52042dd6cce64e74e2b1ecc2d8) ) // OK
3939   ROM_LOAD16_WORD_SWAP( "ic32",    0x0c00000, 0x0200000, CRC(62c10626) SHA1(58cb0ca0330fa7a62b277ab0ff84bff65b81bb23) ) // OK
3940   ROM_LOAD16_WORD_SWAP( "ic34",    0x1000000, 0x0200000, CRC(8d89877e) SHA1(7d76d48d64d7ac5411d714a4bb83f37e3e5b8df6) ) // OK
3941   ROM_LOAD16_WORD_SWAP( "ic36",    0x1200000, 0x0200000, CRC(8d89877e) SHA1(7d76d48d64d7ac5411d714a4bb83f37e3e5b8df6) ) // OK
3942
3943   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
3944   ROM_LOAD( "micrombc.nv", 0x0000, 0x0080, CRC(6e89815f) SHA1(4478f614fb61859f4ee7bf55462f737387887e6f) )
3945ROM_END
3946
3947ROM_START( pclub2 ) // set to 1p / runs with the USA bios
3948   STV_BIOS
3949   ROM_DEFAULT_BIOS( "us" )
3950
3951   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3952
3953   ROM_LOAD16_WORD_SWAP( "ic22",    0x0200000, 0x0200000, CRC(d2ceade7) SHA1(a4300322e582f403d9207290f3900e1a72fcb9b9) ) // OK
3954   ROM_LOAD16_WORD_SWAP( "ic24",    0x0400000, 0x0200000, CRC(0e968c2d) SHA1(fbcc7533fcb6b87cd8255fc2d307ae618301ea64) ) // OK
3955   ROM_LOAD16_WORD_SWAP( "ic26",    0x0600000, 0x0200000, CRC(ab51da70) SHA1(85214aa805ffc9de59900dc0cd4e19e5ab756bf7) ) // OK
3956   ROM_LOAD16_WORD_SWAP( "ic28",    0x0800000, 0x0200000, CRC(3a654b2a) SHA1(7398e25836bfbdeab6350759f25c420c3b496172) ) // OK
3957   ROM_LOAD16_WORD_SWAP( "ic30",    0x0a00000, 0x0200000, CRC(8d89877e) SHA1(7d76d48d64d7ac5411d714a4bb83f37e3e5b8df6) ) // OK
3958
3959   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
3960   ROM_LOAD( "pclub2.nv", 0x0000, 0x0080, CRC(00d0f04e) SHA1(8b5a3e1c52e34443f83fd4a8948a00cacb5071d0) )
3961ROM_END
3962
3963ROM_START( pclub2v3 ) // set to 1p / runs with the USA bios
3964   STV_BIOS
3965   ROM_DEFAULT_BIOS( "us" )
3966
3967   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3968
3969   ROM_LOAD16_WORD_SWAP( "ic22",    0x0200000, 0x0200000, BAD_DUMP CRC(f88347aa) SHA1(3e9ca105edbd6ce11ea4194eb1733785e87f92b2) ) // BAD
3970   ROM_LOAD16_WORD_SWAP( "ic24",    0x0400000, 0x0200000, CRC(b5871198) SHA1(10d187eebcca5d70c5ae10d1a144685a96491126) ) // OK
3971   ROM_LOAD16_WORD_SWAP( "ic26",    0x0600000, 0x0200000, CRC(d97034ed) SHA1(a7a0f659eefd539b2a1fd70ef394eed30ea54c0c) ) // OK
3972   ROM_LOAD16_WORD_SWAP( "ic28",    0x0800000, 0x0200000, CRC(f1421506) SHA1(c384b695338144e5f051134bda73b059b678a7df) ) // OK
3973   ROM_LOAD16_WORD_SWAP( "ic30",    0x0a00000, 0x0200000, CRC(8d89877e) SHA1(7d76d48d64d7ac5411d714a4bb83f37e3e5b8df6) ) // OK (rom is blank?!)
3974
3975   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
3976   ROM_LOAD( "pclub2v3.nv", 0x0000, 0x0080, CRC(a8a2d30c) SHA1(bdde3d62ff21190a23698058ff66e476a75a09aa) )
3977ROM_END
3978
3979ROM_START( pclubpok ) // set to 1p / runs with the USA bios
3980   STV_BIOS
3981   ROM_DEFAULT_BIOS( "us" )
3982
3983   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3984
3985   ROM_LOAD16_WORD_SWAP( "ic22",    0x0200000, 0x0200000, CRC(48ab8371) SHA1(1c2124afad6bc1f4de2619e6b915f78e91addf05) ) // OK
3986   ROM_LOAD16_WORD_SWAP( "ic24",    0x0400000, 0x0200000, CRC(9915faea) SHA1(b96f64a8cbb1b9496bb566d0469975fddb4fbe98) ) // OK
3987   ROM_LOAD16_WORD_SWAP( "ic26",    0x0600000, 0x0200000, CRC(054ad120) SHA1(987e812af099bb0aa5d43a4c10ae8345370a2606) ) // OK
3988   ROM_LOAD16_WORD_SWAP( "ic28",    0x0800000, 0x0200000, CRC(3a654b2a) SHA1(7398e25836bfbdeab6350759f25c420c3b496172) ) // OK
3989   ROM_LOAD16_WORD_SWAP( "ic30",    0x0a00000, 0x0200000, CRC(98747bef) SHA1(8d452507a9842a48cd1a7db8fde11a070a6f068b) ) // OK
3990
3991   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
3992   ROM_LOAD( "pclubpok.nv", 0x0000, 0x0080, CRC(4ba3f21a) SHA1(898a393fb2fc1961b68b7d4f383d5447e6c010e8) )
3993ROM_END
3994
3995/*
3996country codes:
3997J = Japan
3998U = United States
3999E = Europe
4000T = Taiwan
4001B = Brazil
4002K = Korea
4003A = PAL Asia
4004L = Latin America
4005date codes:
4006(Original is yyyy/mm/dd,changed to reflect Capcom's one (yy/mm/dd))
4007Version codes:
4008V = Version(obviously ;)
4009(number before the dot) = game status (0=Sample,1=Master,2=Upgrade)
4010(number after the dot) = game version/release
4011There is also another internal code (called the "Product Number"),but AFAIK it's only used
4012by introdon in ST-V ("SG0000000"),and according to the manual it's even wrong! (SG is used
4013by Sega titles,and this is a Sunsoft game)It's likely to be a left-over...
4014*/
4015
4016static DRIVER_INIT( sanjeon )
4017{
4018   UINT8 *src    = machine.region       ( "user1" )->base();
4019   int x;
4020
4021   for (x=0;x<0x3000000;x++)
4022   {
4023      src[x] = src[x]^0xff;
4024
4025      src[x] = BITSWAP8(src[x],7,2,5,1,  3,6,4,0);
4026      src[x] = BITSWAP8(src[x],4,6,5,7,  3,2,1,0);
4027      src[x] = BITSWAP8(src[x],7,6,5,4,  2,3,1,0);
4028      src[x] = BITSWAP8(src[x],7,0,5,4,  3,2,1,6);
4029      src[x] = BITSWAP8(src[x],3,6,5,4,  7,2,1,0);
4030
4031   }
4032
4033
4034   DRIVER_INIT_CALL(sasissu);
4035}
4036
4037GAME( 1996, stvbios,   0, stv, stv,  stv,       ROT0,   "Sega",                      "ST-V Bios", GAME_IS_BIOS_ROOT )
4038
4039//GAME YEAR, NAME,     PARENT,  MACH, INP, INIT,      MONITOR
4040/* Playable */
4041GAME( 1998, astrass,   stvbios, stv, stv,      astrass,   ROT0,   "Sunsoft",                 "Astra SuperStars (J 980514 V1.002)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
4042GAME( 1995, bakubaku,  stvbios, stv, stv,      stv,       ROT0,   "Sega",                    "Baku Baku Animal (J 950407 V1.000)", GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
4043GAME( 1996, batmanfr,  stvbios, stv, batmanfr,   batmanfr,   ROT0,   "Acclaim",                 "Batman Forever (JUE 960507 V1.000)", GAME_NO_SOUND )
4044GAME( 1996, colmns97,  stvbios, stv, stv,      colmns97,   ROT0,   "Sega",                   "Columns '97 (JET 961209 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4045GAME( 1997, cotton2,   stvbios, stv, stv,      cotton2,   ROT0,   "Success",                 "Cotton 2 (JUET 970902 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4046GAME( 1998, cottonbm,  stvbios, stv, stv,      cottonbm,   ROT0,   "Success",                 "Cotton Boomerang (JUET 980709 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4047GAME( 1995, critcrsh,  stvbios, stv, critcrsh,   stv,      ROT0,   "Sega",                    "Critter Crusher (EA 951204 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4048GAME( 1999, danchih,   stvbios, stv, stvmp,      danchih,   ROT0,   "Altron (Tecmo license)",      "Danchi de Hanafuda (J 990607 V1.400)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4049GAME( 2000, danchiq,   stvbios, stv, stv,      danchih,   ROT0,   "Altron",                  "Danchi de Quiz Okusan Yontaku Desuyo! (J 001128 V1.200)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4050GAME( 1996, diehard,   stvbios, stv, stv,      diehard,   ROT0,   "Sega",                   "Die Hard Arcade (UET 960515 V1.000)", GAME_IMPERFECT_SOUND  )
4051GAME( 1996, dnmtdeka,  diehard, stv, stv,      dnmtdeka,   ROT0,   "Sega",                   "Dynamite Deka (J 960515 V1.000)", GAME_IMPERFECT_SOUND  )
4052GAME( 1995, ejihon,    stvbios, stv, stv,      stv,       ROT0,   "Sega",                   "Ejihon Tantei Jimusyo (J 950613 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4053GAME( 1995, fhboxers,  stvbios, stv, stv,      fhboxers,   ROT0,   "Sega",                   "Funky Head Boxers (JUETBKAL 951218 V1.000)", GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
4054GAME( 1994, gaxeduel,  stvbios, stv, stv,      gaxeduel,   ROT0,   "Sega",                    "Golden Axe - The Duel (JUETL 950117 V1.000)", GAME_IMPERFECT_SOUND )
4055GAME( 1998, grdforce,  stvbios, stv, stv,      grdforce,   ROT0,   "Success",                 "Guardian Force (JUET 980318 V0.105)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4056GAME( 1998, groovef,   stvbios, stv, stv,      groovef,   ROT0,   "Atlus",                   "Groove on Fight - Gouketsuji Ichizoku 3 (J 970416 V1.001)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4057GAME( 1997, hanagumi,  stvbios, stv, stv,      hanagumi,   ROT0,   "Sega",                    "Hanagumi Taisen Columns - Sakura Wars (J 971007 V1.010)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
4058GAME( 1996, introdon,  stvbios, stv, stv,      stv,       ROT0,   "Sunsoft / Success",         "Karaoke Quiz Intro Don Don! (J 960213 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4059GAME( 1995, kiwames,   stvbios, stv, stvmp,      stv,       ROT0,   "Athena",                  "Pro Mahjong Kiwame S (J 951020 V1.208)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4060GAME( 1997, maruchan,  stvbios, stv, stv,      maruchan,   ROT0,   "Sega / Toyosuisan",          "Maru-Chan de Goo! (J 971216 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4061GAME( 1996, mausuke,   stvbios, stv, stv,      mausuke,   ROT0,   "Data East",               "Mausuke no Ojama the World (J 960314 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4062GAME( 1998, myfairld,  stvbios, stv, stvmp,      stv,       ROT0,   "Micronet",                    "Virtual Mahjong 2 - My Fair Lady (J 980608 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4063GAME( 1998, othellos,  stvbios, stv, stv,      othellos,   ROT0,   "Success",                 "Othello Shiyouyo (J 980423 V1.002)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4064GAME( 1995, pblbeach,  stvbios, stv, stv,      pblbeach,   ROT0,   "T&E Soft",                    "Pebble Beach - The Great Shot (JUE 950913 V0.990)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4065GAME( 1996, prikura,   stvbios, stv, stv,      prikura,   ROT0,   "Atlus",                   "Princess Clara Daisakusen (J 960910 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4066GAME( 1996, puyosun,   stvbios, stv, stv,      puyosun,   ROT0,   "Compile",                 "Puyo Puyo Sun (J 961115 V0.001)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4067GAME( 1998, rsgun,     stvbios, stv, stv,      rsgun,     ROT0,   "Treasure",                "Radiant Silvergun (JUET 980523 V1.000)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
4068GAME( 1998, sasissu,   stvbios, stv, stv,      sasissu,   ROT0,   "Sega",                    "Taisen Tanto-R Sashissu!! (J 980216 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4069GAME( 1999, sanjeon,   sasissu, stv, stv,      sanjeon,   ROT0,   "Sega / Deniam",              "DaeJeon! SanJeon SuJeon (AJTUE 990412 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4070GAME( 1997, seabass,   stvbios, stv, stv,      seabass,   ROT0,   "A wave inc. (Able license)",   "Sea Bass Fishing (JUET 971110 V0.001)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4071GAME( 1995, shanhigw,  stvbios, stv, stv,      shanhigw,   ROT0,   "Sunsoft / Activision",       "Shanghai - The Great Wall / Shanghai Triple Threat (JUE 950623 V1.005)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4072GAME( 1997, shienryu,  stvbios, stv, stv,      shienryu,   ROT270, "Warashi",                 "Shienryu (JUET 961226 V1.000)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
4073GAME( 1998, sss,       stvbios, stv, stv,      sss,       ROT0,   "Capcom / Cave / Victor",      "Steep Slope Sliders (JUET 981110 V1.000)", GAME_IMPERFECT_SOUND )
4074GAME( 1995, sandor,    stvbios, stv, stv,      sandor,    ROT0,   "Sega",                    "Puzzle & Action: Sando-R (J 951114 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4075GAME( 1997, thunt,     sandor,  stv, stv,      thunt,     ROT0,   "Sega",                         "Puzzle & Action: Treasure Hunt (JUET 970901 V2.00E)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4076GAME( 1997, thuntk,    sandor,  stv, stv,      sandor,    ROT0,   "Sega / Deniam",              "Puzzle & Action: BoMulEul Chajara (JUET 970125 V2.00K)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4077GAME( 1996, sokyugrt,  stvbios, stv, stv,      sokyugrt,   ROT0,   "Raizing / Eighting",         "Soukyugurentai / Terra Diver (JUET 960821 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4078GAME( 1995, suikoenb,  stvbios, stv, stv,      suikoenb,   ROT0,   "Data East",                   "Suikoenbu / Outlaws of the Lost Dynasty (JUETL 950314 V2.001)", GAME_IMPERFECT_SOUND )
4079GAME( 1996, vfkids,    stvbios, stv, stv,      stv,       ROT0,   "Sega",                   "Virtua Fighter Kids (JUET 960319 V0.000)", GAME_IMPERFECT_SOUND )
4080GAME( 1997, winterht,  stvbios, stv, stv,      winterht,   ROT0,   "Sega",                   "Winter Heat (JUET 971012 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4081GAME( 1997, znpwfv,    stvbios, stv, stv,      znpwfv,    ROT0,   "Sega",                    "Zen Nippon Pro-Wrestling Featuring Virtua (J 971123 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4082
4083/* Almost */
4084GAME( 1997, vmahjong,  stvbios, stv, stvmp,      stv,       ROT0,   "Micronet",                    "Virtual Mahjong (J 961214 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4085GAME( 1998, twcup98,   stvbios, stv, stv,      twcup98,   ROT0,   "Tecmo",                       "Tecmo World Cup '98 (JUET 980410 V1.000)", GAME_UNEMULATED_PROTECTION | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS|GAME_NOT_WORKING ) // player movement
4086GAME( 1995, smleague,  stvbios, stv, stv,      smleague,   ROT0,   "Sega",                    "Super Major League (U 960108 V1.000)", GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4087GAME( 1995, finlarch,  smleague,stv, stv,      finlarch,   ROT0,   "Sega",                    "Final Arch (J 950714 V1.001)", GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4088GAME( 1998, elandore,  stvbios, stv, stv,      elandore,   ROT0,   "Sai-Mate",                "Touryuu Densetsu Elan-Doree / Elan Doree - Legend of Dragoon (JUET 980922 V1.006)", GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4089
4090/* Unemulated printer device */
4091GAME( 1998, stress,    stvbios, stv, stv,      stv,       ROT0,   "Sega",                    "Stress Busters (J 981020 V1.000)", GAME_NOT_WORKING | GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
4092GAME( 1997, nclubv3,   stvbios, stv, stv,      nameclv3,   ROT0,   "Sega",                    "Name Club Ver.3 (J 970723 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS | GAME_NOT_WORKING )
4093GAME( 1997, pclub2,    stvbios, stv, stv,      stv,       ROT0,   "Atlus",                   "Print Club 2 (U 970921 V1.000)", GAME_NOT_WORKING )
4094GAME( 1999, pclub2v3,  pclub2,  stv, stv,      stv,       ROT0,   "Atlus",                   "Print Club 2 Vol. 3 (U 990310 V1.000)", GAME_NOT_WORKING )
4095GAME( 1999, pclubpok,  stvbios, stv, stv,       stv,        ROT0,   "Atlus",                        "Print Club Pokemon B (U 991126 V1.000)", GAME_NOT_WORKING )
4096
4097/* Doing something.. but not enough yet */
4098GAME( 1995, vfremix,   stvbios, stv, stv,      vfremix,   ROT0,   "Sega",                    "Virtua Fighter Remix (JUETBKAL 950428 V1.000)", GAME_IMPERFECT_SOUND | GAME_NOT_WORKING )
4099GAME( 1997, findlove,  stvbios, stv, stv,      stv,      ROT0,   "Daiki / FCF",               "Find Love (J 971212 V1.000)", GAME_IMPERFECT_SOUND | GAME_NOT_WORKING )
4100GAME( 1996, decathlt,  stvbios, stv, stv,      decathlt,   ROT0,   "Sega",                    "Decathlete (JUET 960709 V1.001)", GAME_NO_SOUND | GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION )
4101GAME( 1996, decathlto, decathlt,stv, stv,      decathlt,   ROT0,   "Sega",                    "Decathlete (JUET 960424 V1.000)", GAME_NO_SOUND | GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION )
4102
4103/* Gives I/O errors */
4104GAME( 1996, magzun,    stvbios, stv, stv,      stv,       ROT0,   "Sega",                    "Magical Zunou Power (J 961031 V1.000)", GAME_NOT_WORKING )
4105GAME( 1997, techbowl,  stvbios, stv, stv,      stv,       ROT0,   "Sega",                    "Technical Bowling (J 971212 V1.000)", GAME_NOT_WORKING )
4106GAME( 1999, micrombc,  stvbios, stv, stv,      stv,       ROT0,   "Sega",                    "Microman Battle Charge (J 990326 V1.000)", GAME_NOT_WORKING )
4107
4108/* Black screen */
4109GAME( 1999, ffreveng,  stvbios, stv, stv,      ffreveng,   ROT0,   "Capcom",                  "Final Fight Revenge (JUET 990714 V1.000)", GAME_UNEMULATED_PROTECTION | GAME_NO_SOUND | GAME_NOT_WORKING )
4110
4111/* CD games */
4112GAME( 1995, sfish2,    0,      stv, stv,      stv,      ROT0,   "Sega",                      "Sport Fishing 2 (UET 951106 V1.10e)", GAME_NO_SOUND | GAME_NOT_WORKING )
4113GAME( 1995, sfish2j,   sfish2,   stv, stv,      stv,      ROT0,   "Sega",                      "Sport Fishing 2 (J 951201 V1.100)", GAME_NO_SOUND | GAME_NOT_WORKING )
4114
4115/*
4116This is the known list of undumped ST-V games:
4117    Kiss Off (US version of mausuke)
4118    Baku Baku (US version of Baku Baku Animal,dunno if it exists for the ST-V)
4119    Sport Fishing
4120    Aroma Club
4121    Movie Club
4122    Name Club (other versions)
4123    Print Club 2 (other versions)
4124    Youen Denshi Mahjong Yuugi Gal Jan
4125    Danchi de Quiz: Okusan 4taku Desu yo!
4126    NBA Action (?)
4127    Quiz Omaeni Pipon Cho! (?)
4128Others may exist as well...
4129*/
4130
src/mame/drivers/saturn.c
r0r11293
1/*
2   Sega Saturn & Sega ST-V (Sega Titan Video)
3
4Driver by David Haywood,Angelo Salese,Olivier Galibert & Mariusz Wojcieszek
5SCSP driver provided by R.Belmont,based on ElSemi's SCSP sound chip emulator
6CD Block driver provided by ANY,based on sthief original emulator
7Many thanks to Guru,Fabien & Runik for the help given.
8
9Hardware overview:
10------------------
11-two SH-2 CPUs,in a master/slave configuration.The master cpu is used to
12boot-up and to do the most of the work,the slave one does extra work that could be
13too much for a single cpu.They both shares all the existant devices;
14-a M68000 CPU,used to drive sound(the SCSP chip).The program is uploaded via the
15SH-2 cpus;
16-a SMPC (System Manager & Peripheral Control),used to drive all the
17devices on the board;
18-a SCU (System Control Unit),mainly used to do DMA operations and to drive interrupts,it
19also has a DSP;
20-an (optional for the ST-V) SH-1 CPU,used to be the CD driver;
21-An A-Bus,where the cart ROM area is located;
22-A B-Bus,where the Video Hardware & the SCU sections are located;
23-Two VDPs chips(named as 1 & 2),used for the video section:
24 -VDP1 is used to render sprites & polygons.
25 -VDP2 is for the tilemap system,there are:
26 4 effective normal layers;
27 2 roz layers;
28 1 back layer;
29 1 line layer;
30 The VDP2 is capable of the following things (in order):
31 -dynamic resolution (up to 704x512) & various interlacing modes;
32 -mosaic process;
33 -scrolling,scaling,horizontal & vertical cell scrolling & linescroll for the
34  normal planes, the roz ones can also rotate;
35 -versatile window system,used for various effects;
36 -alpha-blending,refered as Color Calculation in the docs;
37 -shadow effects;
38 -global rgb brightness control,separate for every plane;
39
40Memory map:
41-----------
42
430x00000000, 0x0007ffff  BIOS ROM
440x00080000, 0x000fffff  Unused
450x00100000, 0x0010007f  SMPC
460x00100080, 0x0017ffff  Unused
470x00180000, 0x0018ffff  Back Up Ram
480x00190000, 0x001fffff  Unused
490x00200000, 0x002fffff  Work Ram-L
500x00300000, 0x00ffffff  Unused
510x01000000, 0x01000003  MINIT
520x01000004, 0x017fffff  Unused
530x01800000, 0x01800003  SINIT
540x01800004, 0x01ffffff  Unused
550x02000000, 0x03ffffff  A-BUS CS0
560x04000000, 0x04ffffff  A-BUS CS1
570x05000000, 0x057fffff  A-BUS DUMMY
580x05800000, 0x058fffff  A-BUS CS2
590x05900000, 0x059fffff  Unused
600x05a00000, 0x05b00ee3  Sound Region
610x05b00ee4, 0x05bfffff  Unused
620x05c00000, 0x05cbffff  VDP 1
630x05cc0000, 0x05cfffff  Unused
640x05d00000, 0x05d00017  VDP 1 regs
650x05d00018, 0x05dfffff  Unused
660x05e00000, 0x05e7ffff  VDP2
670x05e80000, 0x05efffff  VDP2 Extra RAM,accessible thru the VRAMSZ register
680x05f00000, 0x05f00fff  VDP2 Color RAM
690x05f01000, 0x05f7ffff  Unused
700x05f80000  0x05f8011f  VDP2 regs
710x05f80120, 0x05fdffff  Unused
720x05fe0000, 0x05fe00cf  SCU regs
730x05fe00d0, 0x05ffffff  Unused
740x06000000, 0x060fffff  Work Ram-H
750x06100000, 0x07ffffff  Unused
76
77*the unused locations aren't known if they are really unused or not,needs verification,most
78of them seem just mirrors of the previous valid memory allocated.
79
80ToDo / Notes:
81-------------
82
83-To enter into an Advanced Test Mode,keep pressed the Test Button (F2) on the start-up.
84
85(Main issues)
86-IRQs: some games have some issues with timing accurate IRQs,check/fix all of them.
87-Clean-ups and split the various chips(SCU,SMPC)into their respective files.
88-CD block:complete it.
89-The Cart-Dev mode hangs even with the -dev bios,I would like to see what it does on the real HW.
90-IC13 games on the bios dev doesn't even load the cartridge / crashes the emulation at start-up,
91 rom rearrange needed?
92-finish the DSP core.
93-Add the RS232c interface (serial port),needed by fhboxers.
94-(PCB owners) check if the clocks documented in the manuals are really right for ST-V.
95-SCSP to master irq: see if there is a sound cpu mask bit.
96-Does the device_set_clock really works?Investigate.
97-We need to check every game if can be completed or there are any hanging/crash/protection
98 issues on them.
99-Memo: Some tests done on the original & working PCB,to be implemented:
100 -The AD-Stick returns 0x00 or a similar value.
101 -The Ports E,F & G must return 0xff
102 -The regular BIOS tests (Memory Test) changes his background color at some point to
103  several gradients of red,green and blue.Current implementation remains black.I dunno
104  if this is a framebuffer write or a funky transparency issue (i.e TRANSPARENT_NONE
105  should instead show the back layer).
106 -RBG0 rotating can be checked on the "Advanced Test" menu thru the VDP1/VDP2 check.
107  It rotates clockwise IIRC.Also the ST-V logo when the game is in Multi mode rotates too.
108 -The MIDI communication check fails even on a ST-V board,somebody needs to check if there
109  is a MIDI port on the real PCB...
110-All games except shienryu: add default eeprom if necessary (1P/3P games for example).
111-Video emulation bugs: check stvvdp2.c file.
112
113(per-game issues)
114-stress: accesses the Sound Memory Expansion Area (0x05a00000-0x05afffff), unknown purpose;
115-smleague / finlarch: it randomly hangs / crashes,it works if you use a ridiculous MCFG_INTERLEAVE number,might need strict
116 SH-2 synching.
117-various: find idle skip if possible.
118-suikoenb/shanhigw + others: why do we get 2 credits on startup? Cause might be by a communication with the M68k
119-colmns97/puyosun/mausuke/cotton2/cottonbm: interrupt issues? we can't check the SCU mask
120 on SMPC or controls fail
121-mausuke/bakubaku/grdforce: need to sort out transparency on the colour mapped sprites
122-bakubaku: sound part is largely incomplete,caused by a tight loop at location PC=1048 of the sound cpu part.
123-myfairld: Apparently this game gives a black screen (either test mode and in-game mode),but let it wait for about
124 10 seconds and the game will load everything.This is because of a hellishly slow m68k sub-routine located at 54c2.
125 Likely to not be a bug but an in-game design issue.
126-myfairld: Micronet programmers had the "great" idea to *not* use the ST-V input standards,infact
127 joystick panel is mapped with input_port(10) instead of input_port(2),so for now use
128 the mahjong panel instead.
129-danchih: hanafuda panel doesn't work.
130-decathlt: Is currently using a strange protection DMA abus control,and it uses some sort of RLE
131 compression/encryption that serves as a gfxdecode.
132-findlove: controls doesn't work? Playing with the debugger at location $6063720 it makes it get furter,but controls
133 still doesn't work,missing irq?
134-batmanfr: Missing sound,caused by an extra ADSP chip which is on the cart.The CPU is a
135 ADSP-2181,and it's the same used by NBA Jam Extreme (ZN game).
136-vfremix: when you play Akira, there is a problem with third match: game doesn't upload all textures
137 and tiles and doesn't enable display, although gameplay is normal - wait a while to get back
138 to title screen after losing a match
139-sokyugrt: gameplay seems to be not smooth, timing?
140-seabass: crashes in stvcd.c - there is no CD and we report than we have one, and game tries
141 to read something, however it doesn't do it after nvram is deleted?
142-Protection issues:
143 \-ffreveng: boot vectors;
144 \-decathlt: in-game graphics;
145 \-elandore: human / dragons textures;
146 \-twcup98: tecmo logo / sprite movements;
147 \-astrass: text layer (kludged for now);
148
149
150*/
151
152#include "emu.h"
153#include "cpu/m68000/m68000.h"
154#include "machine/eeprom.h"
155#include "cpu/sh2/sh2.h"
156#include "machine/stvcd.h"
157#include "machine/scudsp.h"
158#include "sound/scsp.h"
159#include "machine/stvprot.h"
160#include "includes/stv.h"
161#include "imagedev/chd_cd.h"
162#include "imagedev/cartslot.h"
163#include "coreutil.h"
164
165#define USE_SLAVE 1
166
167#ifdef MAME_DEBUG
168#define LOG_CDB  0
169#define LOG_SMPC 1
170#define LOG_SCU  1
171#define LOG_IRQ  0
172#define LOG_IOGA 1
173#else
174#define LOG_CDB  0
175#define LOG_SMPC 0
176#define LOG_SCU  0
177#define LOG_IRQ  0
178#define LOG_IOGA 0
179#endif
180
181#define MASTER_CLOCK_352 57272800
182#define MASTER_CLOCK_320 53748200
183#define PIXEL_CLOCK 50160000/2/4 /*hand-tuned to match fps ~59.82*/
184
185/**************************************************************************************/
186/*to be added into a stv Header file,remember to remove all the static...*/
187
188static UINT8 *smpc_ram;
189//static void stv_dump_ram(void);
190
191UINT32* stv_workram_l;
192UINT32* stv_workram_h;
193cpu_device *stv_maincpu;
194cpu_device *stv_slave;
195cpu_device *stv_audiocpu;
196static UINT32* stv_backupram;
197static UINT32* ioga;
198static UINT16* scsp_regs;
199static UINT16* sound_ram;
200static int saturn_region;
201
202int stv_enable_slave_sh2;
203/*VDP2 stuff*/
204/*SMPC stuff*/
205static UINT8 NMI_reset;
206static void system_reset(void);
207static UINT8 en_68k;
208/*SCU stuff*/
209static int     timer_0;         /* Counter for Timer 0 irq*/
210static int    timer_1;          /* Counter for Timer 1 irq*/
211/*Maybe add these in a struct...*/
212static UINT32 scu_src_0,      /* Source DMA lv 0 address*/
213           scu_src_1,      /* lv 1*/
214           scu_src_2,      /* lv 2*/
215           scu_dst_0,      /* Destination DMA lv 0 address*/
216           scu_dst_1,      /* lv 1*/
217           scu_dst_2,      /* lv 2*/
218           scu_src_add_0,   /* Source Addition for DMA lv 0*/
219           scu_src_add_1,   /* lv 1*/
220           scu_src_add_2,   /* lv 2*/
221           scu_dst_add_0,   /* Destination Addition for DMA lv 0*/
222           scu_dst_add_1,   /* lv 1*/
223           scu_dst_add_2;   /* lv 2*/
224static INT32  scu_size_0,      /* Transfer DMA size lv 0*/
225           scu_size_1,      /* lv 1*/
226           scu_size_2;      /* lv 2*/
227
228static struct
229{
230   UINT8 vblank_out;
231   UINT8 vblank_in;
232   UINT8 hblank_in;
233   UINT8 timer_0;
234   UINT8 timer_1;
235   UINT8 dsp_end;
236   UINT8 sound_req;
237   UINT8 smpc;
238   UINT8 pad;
239   UINT8 dma_end[3];
240   UINT8 dma_ill;
241   UINT8 vdp1_end;
242   UINT8 abus;
243}stv_irq;
244
245static void dma_direct_lv0(address_space *space);   /*DMA level 0 direct transfer function*/
246static void dma_direct_lv1(address_space *space);   /*DMA level 1 direct transfer function*/
247static void dma_direct_lv2(address_space *space);   /*DMA level 2 direct transfer function*/
248static void dma_indirect_lv0(address_space *space); /*DMA level 0 indirect transfer function*/
249static void dma_indirect_lv1(address_space *space); /*DMA level 1 indirect transfer function*/
250static void dma_indirect_lv2(address_space *space); /*DMA level 2 indirect transfer function*/
251
252
253int minit_boost,sinit_boost;
254attotime minit_boost_timeslice, sinit_boost_timeslice;
255
256//static int scanline;
257
258static emu_timer *stv_rtc_timer;
259
260
261/*A-Bus IRQ checks,where they could be located these?*/
262#define ABUSIRQ(_irq_,_vector_) \
263   { cputag_set_input_line_and_vector(device->machine(), "maincpu", _irq_, HOLD_LINE , _vector_); }
264#if 0
265if(stv_scu[42] & 1)//IRQ ACK
266{
267   ABUSIRQ(7,0x50,0x00010000);
268   ABUSIRQ(7,0x51,0x00020000);
269   ABUSIRQ(7,0x52,0x00040000);
270   ABUSIRQ(7,0x53,0x00080000);
271   ABUSIRQ(4,0x54,0x00100000);
272   ABUSIRQ(4,0x55,0x00200000);
273   ABUSIRQ(4,0x56,0x00400000);
274   ABUSIRQ(4,0x57,0x00800000);
275   ABUSIRQ(1,0x58,0x01000000);
276   ABUSIRQ(1,0x59,0x02000000);
277   ABUSIRQ(1,0x5a,0x04000000);
278   ABUSIRQ(1,0x5b,0x08000000);
279   ABUSIRQ(1,0x5c,0x10000000);
280   ABUSIRQ(1,0x5d,0x20000000);
281   ABUSIRQ(1,0x5e,0x40000000);
282   ABUSIRQ(1,0x5f,0x80000000);
283}
284#endif
285
286/**************************************************************************************/
287
288static int DectoBCD(int num)
289{
290   int i, cnt = 0, tmp, res = 0;
291
292   while (num > 0) {
293      tmp = num;
294      while (tmp >= 10) tmp %= 10;
295      for (i=0; i<cnt; i++)
296         tmp *= 16;
297      res += tmp;
298      cnt++;
299      num /= 10;
300   }
301
302   return res;
303}
304
305
306/* SMPC
307 System Manager and Peripheral Control
308
309*/
310/* SMPC Addresses
311
31200
31301 -w  Input Register 0 (IREG)
31402
31503 -w  Input Register 1
31604
31705 -w  Input Register 2
31806
31907 -w  Input Register 3
32008
32109 -w  Input Register 4
3220a
3230b -w  Input Register 5
3240c
3250d -w  Input Register 6
3260e
3270f
32810
32911
33012
33113
33214
33315
33416
33517
33618
33719
3381a
3391b
3401c
3411d
3421e
3431f -w  Command Register (COMREG)
34420
34521 r-  Output Register 0 (OREG)
34622
34723 r-  Output Register 1
34824
34925 r-  Output Register 2
35026
35127 r-  Output Register 3
35228
35329 r-  Output Register 4
3542a
3552b r-  Output Register 5
3562c
3572d r-  Output Register 6
3582e
3592f r-  Output Register 7
36030
36131 r-  Output Register 8
36232
36333 r-  Output Register 9
36434
36535 r-  Output Register 10
36636
36737 r-  Output Register 11
36838
36939 r-  Output Register 12
3703a
3713b r-  Output Register 13
3723c
3733d r-  Output Register 14
3743e
3753f r-  Output Register 15
37640
37741 r-  Output Register 16
37842
37943 r-  Output Register 17
38044
38145 r-  Output Register 18
38246
38347 r-  Output Register 19
38448
38549 r-  Output Register 20
3864a
3874b r-  Output Register 21
3884c
3894d r-  Output Register 22
3904e
3914f r-  Output Register 23
39250
39351 r-  Output Register 24
39452
39553 r-  Output Register 25
39654
39755 r-  Output Register 26
39856
39957 r-  Output Register 27
40058
40159 r-  Output Register 28
4025a
4035b r-  Output Register 29
4045c
4055d r-  Output Register 30
4065e
4075f r-  Output Register 31
40860
40961 r-  SR
41062
41163 rw  SF
41264
41365
41466
41567
41668
41769
4186a
4196b
4206c
4216d
4226e
4236f
42470
42571
42672
42773
42874
42975 rw PDR1
43076
43177 rw PDR2
43278
43379 -w DDR1
4347a
4357b -w DDR2
4367c
4377d -w IOSEL2/1
4387e
4397f -w EXLE2/1
440*/
441static UINT8 IOSEL1;
442static UINT8 IOSEL2;
443static UINT8 EXLE1;
444static UINT8 EXLE2;
445static UINT8 PDR1;
446static UINT8 PDR2;
447static int intback_stage = 0, smpcSR, pmode;
448static UINT8 SMEM[4];
449
450#define SH2_DIRECT_MODE_PORT_1 IOSEL1 = 1
451#define SH2_DIRECT_MODE_PORT_2 IOSEL2 = 1
452#define SMPC_CONTROL_MODE_PORT_1 IOSEL1 = 0
453#define SMPC_CONTROL_MODE_PORT_2 IOSEL2 = 0
454
455
456
457static void system_reset()
458{
459   /*Only backup ram and SMPC ram are retained after that this command is issued.*/
460   memset(stv_scu      ,0x00,0x000100);
461   memset(scsp_regs    ,0x00,0x001000);
462   memset(sound_ram    ,0x00,0x080000);
463   memset(stv_workram_h,0x00,0x100000);
464   memset(stv_workram_l,0x00,0x100000);
465   memset(stv_vdp2_regs,0x00,0x040000);
466   memset(stv_vdp2_vram,0x00,0x100000);
467   memset(stv_vdp2_cram,0x00,0x080000);
468   //vdp1
469   //A-Bus
470   /*Order is surely wrong but whatever...*/
471}
472
473static UINT8 stv_SMPC_r8 (address_space *space, int offset)
474{
475   int return_data;
476
477
478   return_data = smpc_ram[offset];
479
480   if (offset == 0x61) // ?? many games need this or the controls don't work
481      return_data = 0x20 ^ 0xff;
482
483   if (offset == 0x75)//PDR1 read
484      return_data = input_port_read(space->machine(), "DSW1");
485
486   if (offset == 0x77)//PDR2 read
487      return_data=  (0xfe | eeprom_read_bit(space->machine().device("eeprom")));
488
489//  if (offset == 0x33) //country code
490//      return_data = input_port_read(machine, "FAKE");
491
492   if (cpu_get_pc(&space->device())==0x060020E6) return_data = 0x10;//???
493
494   //if(LOG_SMPC) logerror ("cpu %s (PC=%08X) SMPC: Read from Byte Offset %02x Returns %02x\n", space->device().tag(), cpu_get_pc(&space->device()), offset, return_data);
495
496
497   return return_data;
498}
499
500static void stv_SMPC_w8 (address_space *space, int offset, UINT8 data)
501{
502   system_time systime;
503
504   space->machine().base_datetime(systime);
505
506//  if(LOG_SMPC) logerror ("8-bit SMPC Write to Offset %02x with Data %02x\n", offset, data);
507   smpc_ram[offset] = data;
508
509   if(offset == 0x75)
510   {
511      eeprom_device *device = space->machine().device<eeprom_device>("eeprom");
512      eeprom_set_clock_line(device, (data & 0x08) ? ASSERT_LINE : CLEAR_LINE);
513      eeprom_write_bit(device, data & 0x10);
514      eeprom_set_cs_line(device, (data & 0x04) ? CLEAR_LINE : ASSERT_LINE);
515
516
517//      if (data & 0x01)
518//          if(LOG_SMPC) logerror("bit 0 active\n");
519//      if (data & 0x02)
520//          if(LOG_SMPC) logerror("bit 1 active\n");
521//      if (data & 0x10)
522         //if(LOG_SMPC) logerror("bit 4 active\n");//LOT
523      //if(LOG_SMPC) logerror("SMPC: ram [0x75] = %02x\n",smpc_ram[0x75]);
524      PDR1 = (data & 0x60);
525   }
526
527   if(offset == 0x77)
528   {
529      /*
530            ACTIVE LOW
531            bit 4(0x10) - Enable Sound System
532        */
533      //popmessage("PDR2 = %02x",smpc_ram[0x77]);
534      if(!(smpc_ram[0x77] & 0x10))
535      {
536         if(LOG_SMPC) logerror("SMPC: M68k on\n");
537         cputag_set_input_line(space->machine(), "audiocpu", INPUT_LINE_RESET, CLEAR_LINE);
538         en_68k = 1;
539      }
540      else
541      {
542         if(LOG_SMPC) logerror("SMPC: M68k off\n");
543         cputag_set_input_line(space->machine(), "audiocpu", INPUT_LINE_RESET, ASSERT_LINE);
544         en_68k = 0;
545      }
546      //if(LOG_SMPC) logerror("SMPC: ram [0x77] = %02x\n",smpc_ram[0x77]);
547      PDR2 = (data & 0x60);
548   }
549
550   if(offset == 0x7d)
551   {
552      if(smpc_ram[0x7d] & 1)
553         SH2_DIRECT_MODE_PORT_1;
554      else
555         SMPC_CONTROL_MODE_PORT_1;
556
557      if(smpc_ram[0x7d] & 2)
558         SH2_DIRECT_MODE_PORT_2;
559      else
560         SMPC_CONTROL_MODE_PORT_2;
561   }
562
563   /*TODO: probably this is wrong...*/
564   if(offset == 0x7f)
565   {
566      //enable PAD irq & VDP2 external latch for port 1/2
567      EXLE1 = smpc_ram[0x7f] & 1 ? 1 : 0;
568      EXLE2 = smpc_ram[0x7f] & 2 ? 1 : 0;
569      if(EXLE1 || EXLE2)
570      {
571         //if(LOG_SMPC) logerror ("Interrupt: PAD irq at scanline %04x, Vector 0x48 Level 0x08\n",scanline);
572         cputag_set_input_line_and_vector(space->machine(), "maincpu", 8, (stv_irq.pad) ? HOLD_LINE : CLEAR_LINE, 0x48);
573      }
574   }
575
576   if (offset == 0x1f)
577   {
578      switch (data)
579      {
580         case 0x00:
581            if(LOG_SMPC) logerror ("SMPC: Master ON\n");
582            smpc_ram[0x5f]=0x00;
583            break;
584         //in theory 0x01 is for Master OFF,but obviously is not used.
585         case 0x02:
586            if(LOG_SMPC) logerror ("SMPC: Slave ON\n");
587            smpc_ram[0x5f]=0x02;
588            #if USE_SLAVE
589            stv_enable_slave_sh2 = 1;
590            cputag_set_input_line(space->machine(), "slave", INPUT_LINE_RESET, CLEAR_LINE);
591            #endif
592            break;
593         case 0x03:
594            if(LOG_SMPC) logerror ("SMPC: Slave OFF\n");
595            smpc_ram[0x5f]=0x03;
596            stv_enable_slave_sh2 = 0;
597            space->machine().scheduler().trigger(1000);
598            cputag_set_input_line(space->machine(), "slave", INPUT_LINE_RESET, ASSERT_LINE);
599            break;
600         case 0x06:
601            if(LOG_SMPC) logerror ("SMPC: Sound ON\n");
602            /* wrong? */
603            smpc_ram[0x5f]=0x06;
604            cputag_set_input_line(space->machine(), "audiocpu", INPUT_LINE_RESET, CLEAR_LINE);
605            break;
606         case 0x07:
607            if(LOG_SMPC) logerror ("SMPC: Sound OFF\n");
608            smpc_ram[0x5f]=0x07;
609            break;
610         /*CD (SH-1) ON/OFF,guess that this is needed for Sports Fishing games...*/
611         //case 0x08:
612         //case 0x09:
613         case 0x0d:
614            if(LOG_SMPC) logerror ("SMPC: System Reset\n");
615            smpc_ram[0x5f]=0x0d;
616            cputag_set_input_line(space->machine(), "maincpu", INPUT_LINE_RESET, PULSE_LINE);
617            system_reset();
618            break;
619         case 0x0e:
620            if(LOG_SMPC) logerror ("SMPC: Change Clock to 352\n");
621            smpc_ram[0x5f]=0x0e;
622            space->machine().device("maincpu")->set_unscaled_clock(MASTER_CLOCK_352/2);
623            space->machine().device("slave")->set_unscaled_clock(MASTER_CLOCK_352/2);
624            space->machine().device("audiocpu")->set_unscaled_clock(MASTER_CLOCK_352/5);
625            cputag_set_input_line(space->machine(), "maincpu", INPUT_LINE_NMI, PULSE_LINE); // ff said this causes nmi, should we set a timer then nmi?
626            break;
627         case 0x0f:
628            if(LOG_SMPC) logerror ("SMPC: Change Clock to 320\n");
629            smpc_ram[0x5f]=0x0f;
630            space->machine().device("maincpu")->set_unscaled_clock(MASTER_CLOCK_320/2);
631            space->machine().device("slave")->set_unscaled_clock(MASTER_CLOCK_320/2);
632            space->machine().device("audiocpu")->set_unscaled_clock(MASTER_CLOCK_320/5);
633            cputag_set_input_line(space->machine(), "maincpu", INPUT_LINE_NMI, PULSE_LINE); // ff said this causes nmi, should we set a timer then nmi?
634            break;
635         /*"Interrupt Back"*/
636         case 0x10:
637            if(LOG_SMPC) logerror ("SMPC: Status Acquire\n");
638            smpc_ram[0x5f]=0x10;
639            smpc_ram[0x21] = (0x80) | ((NMI_reset & 1) << 6);
640            //smpc_ram[0x23] = DectoBCD(systime.local_time.year /100);
641            //smpc_ram[0x25] = DectoBCD(systime.local_time.year %100);
642            //smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month+1);
643            //smpc_ram[0x29] = DectoBCD(systime.local_time.mday);
644            //smpc_ram[0x2b] = DectoBCD(systime.local_time.hour);
645            //smpc_ram[0x2d] = DectoBCD(systime.local_time.minute);
646            //smpc_ram[0x2f] = DectoBCD(systime.local_time.second);
647
648            smpc_ram[0x31]=0x00;  //?
649
650            //smpc_ram[0x33]=input_port_read(space->machine(), "FAKE");
651
652            smpc_ram[0x35]=0x00;
653            smpc_ram[0x37]=0x00;
654
655            smpc_ram[0x39]=0xff;
656            smpc_ram[0x3b]=0xff;
657            smpc_ram[0x3d]=0xff;
658            smpc_ram[0x3f]=0xff;
659            smpc_ram[0x41]=0xff;
660            smpc_ram[0x43]=0xff;
661            smpc_ram[0x45]=0xff;
662            smpc_ram[0x47]=0xff;
663            smpc_ram[0x49]=0xff;
664            smpc_ram[0x4b]=0xff;
665            smpc_ram[0x4d]=0xff;
666            smpc_ram[0x4f]=0xff;
667            smpc_ram[0x51]=0xff;
668            smpc_ram[0x53]=0xff;
669            smpc_ram[0x55]=0xff;
670            smpc_ram[0x57]=0xff;
671            smpc_ram[0x59]=0xff;
672            smpc_ram[0x5b]=0xff;
673            smpc_ram[0x5d]=0xff;
674
675         //  /*This is for RTC,cartridge code and similar stuff...*/
676            /*System Manager(SMPC) irq*/
677            {
678               //if(LOG_SMPC) logerror ("Interrupt: System Manager (SMPC) at scanline %04x, Vector 0x47 Level 0x08\n",scanline);
679               cputag_set_input_line_and_vector(space->machine(), "maincpu", 8, (stv_irq.smpc) ? HOLD_LINE : CLEAR_LINE, 0x47);
680            }
681         break;
682         /* RTC write*/
683         case 0x16:
684            if(LOG_SMPC) logerror("SMPC: RTC write\n");
685            smpc_ram[0x2f] = smpc_ram[0x0d];
686            smpc_ram[0x2d] = smpc_ram[0x0b];
687            smpc_ram[0x2b] = smpc_ram[0x09];
688            smpc_ram[0x29] = smpc_ram[0x07];
689            smpc_ram[0x27] = smpc_ram[0x05];
690            smpc_ram[0x25] = smpc_ram[0x03];
691            smpc_ram[0x23] = smpc_ram[0x01];
692            smpc_ram[0x5f]=0x16;
693         break;
694         /* SMPC memory setting*/
695         case 0x17:
696            if(LOG_SMPC) logerror ("SMPC: memory setting\n");
697            smpc_ram[0x5f]=0x17;
698         break;
699         case 0x18:
700            if(LOG_SMPC) logerror ("SMPC: NMI request\n");
701            smpc_ram[0x5f]=0x18;
702            /*NMI is unconditionally requested?*/
703            cputag_set_input_line(space->machine(), "maincpu", INPUT_LINE_NMI, PULSE_LINE);
704            break;
705         case 0x19:
706            if(LOG_SMPC) logerror ("SMPC: NMI Enable\n");
707            smpc_ram[0x5f]=0x19;
708            NMI_reset = 0;
709            smpc_ram[0x21] = (0x80) | ((NMI_reset & 1) << 6);
710            break;
711         case 0x1a:
712            if(LOG_SMPC) logerror ("SMPC: NMI Disable\n");
713            smpc_ram[0x5f]=0x1a;
714            NMI_reset = 1;
715            smpc_ram[0x21] = (0x80) | ((NMI_reset & 1) << 6);
716            break;
717         default:
718            if(LOG_SMPC) logerror ("cpu '%s' (PC=%08X) SMPC: undocumented Command %02x\n", space->device().tag(), cpu_get_pc(&space->device()), data);
719      }
720
721      // we've processed the command, clear status flag
722      smpc_ram[0x63] = 0x00;
723      /*TODO:emulate the timing of each command...*/
724   }
725}
726
727
728static void smpc_intbackhelper(running_machine &machine)
729{
730   int pad;
731   static const char *const padnames[] = { "JOY1", "JOY2" };
732
733   if (intback_stage == 1)
734   {
735      intback_stage++;
736      return;
737   }
738
739   pad = input_port_read(machine, padnames[intback_stage-2]);
740
741//  if (LOG_SMPC) logerror("SMPC: providing PAD data for intback, pad %d\n", intback_stage-2);
742   smpc_ram[33] = 0xf1;   // no tap, direct connect
743   smpc_ram[35] = 0x02;   // saturn pad
744   smpc_ram[37] = pad>>8;
745   smpc_ram[39] = pad & 0xff;
746
747   if (intback_stage == 3)
748   {
749      smpcSR = (0x80 | pmode);   // pad 2, no more data, echo back pad mode set by intback
750   }
751   else
752   {
753      smpcSR = (0xe0 | pmode);   // pad 1, more data, echo back pad mode set by intback
754   }
755
756   intback_stage++;
757}
758
759static UINT8 saturn_SMPC_r8(address_space *space, int offset)
760{
761   int return_data;
762
763   return_data = smpc_ram[offset];
764
765   if ((offset == 0x61))
766      return_data = smpcSR;
767
768   if (offset == 0x75)//PDR1 read
769   {
770      if (IOSEL1)
771      {
772         int hshake;
773
774         hshake = (PDR1>>5) & 3;
775
776         if (LOG_SMPC) logerror("SMPC: SH-2 direct mode, returning data for phase %d\n", hshake);
777
778         return_data = 0x9f;
779
780         switch (hshake)
781         {
782            case 0:
783               return_data = 0x90;
784//                  return_data = 0xf0 | ((input_port_read(space->machine(), "JOY1")>>4) & 0xf);
785               break;
786
787            case 1:
788//                  return_data = 0xf0 | ((input_port_read(space->machine(), "JOY1")>>12) & 0xf);
789               break;
790
791            case 2:
792//                  return_data = 0xf0 | ((input_port_read(space->machine(), "JOY1")>>8) & 0xf);
793               break;
794
795            case 3:
796               return_data = 0x94;
797//                  return_data = 0xf0 | (input_port_read(space->machine(), "JOY1")&0x8) | 0x4;
798               break;
799         }
800      }
801   }
802
803   if (offset == 0x77)//PDR2 read
804   {
805      return_data =  0xff; // | EEPROM_read_bit());
806   }
807
808   if (offset == 0x33) return_data = saturn_region;
809
810   if (LOG_SMPC) logerror ("cpu %s (PC=%08X) SMPC: Read from Byte Offset %02x (%d) Returns %02x\n", space->device().tag(), cpu_get_pc(&space->device()), offset, offset>>1, return_data);
811
812
813   return return_data;
814}
815
816static void saturn_SMPC_w8(address_space *space, int offset, UINT8 data)
817{
818   system_time systime;
819   UINT8 last;
820   running_machine &machine = space->machine();
821
822   /* get the current date/time from the core */
823   machine.current_datetime(systime);
824
825  if (LOG_SMPC) logerror ("8-bit SMPC Write to Offset %02x (reg %d) with Data %02x (prev %02x)\n", offset, offset>>1, data, smpc_ram[offset]);
826
827//  if (offset == 0x7d) printf("IOSEL2 %d IOSEL1 %d\n", (data>>1)&1, data&1);
828
829   last = smpc_ram[offset];
830
831   if ((intback_stage > 0) && (offset == 1) && (((data ^ 0x80)&0x80) == (last&0x80)))
832   {
833      if (LOG_SMPC) logerror("SMPC: CONTINUE request, stage %d\n", intback_stage);
834      if (intback_stage != 3)
835      {
836         intback_stage = 2;
837      }
838      smpc_intbackhelper(machine);
839      cputag_set_input_line_and_vector(machine, "maincpu", 8, HOLD_LINE , 0x47);
840   }
841
842   if ((offset == 1) && (data & 0x40))
843   {
844      if (LOG_SMPC) logerror("SMPC: BREAK request\n");
845      intback_stage = 0;
846   }
847
848   smpc_ram[offset] = data;
849
850   if (offset == 0x75)   // PDR1
851   {
852      PDR1 = (data & smpc_ram[0x79]);
853   }
854
855   if (offset == 0x77)   // PDR2
856   {
857      PDR2 = (data & smpc_ram[0x7b]);
858   }
859
860   if(offset == 0x7d)
861   {
862      if(smpc_ram[0x7d] & 1)
863         SH2_DIRECT_MODE_PORT_1;
864      else
865         SMPC_CONTROL_MODE_PORT_1;
866
867      if(smpc_ram[0x7d] & 2)
868         SH2_DIRECT_MODE_PORT_2;
869      else
870         SMPC_CONTROL_MODE_PORT_2;
871   }
872
873   if(offset == 0x7f)
874   {
875      //enable PAD irq & VDP2 external latch for port 1/2
876      EXLE1 = smpc_ram[0x7f] & 1 ? 1 : 0;
877      EXLE2 = smpc_ram[0x7f] & 2 ? 1 : 0;
878      if(EXLE1 || EXLE2)
879         if(!(stv_scu[40] & 0x0100)) /*Pad irq*/
880         {
881            if(LOG_SMPC) logerror ("Interrupt: PAD irq, Vector 0x48 Level 0x08\n");
882            cputag_set_input_line_and_vector(machine, "maincpu", 8, HOLD_LINE , 0x48);
883         }
884   }
885
886   if (offset == 0x1f)
887   {
888      switch (data)
889      {
890         case 0x00:
891            if(LOG_SMPC) logerror ("SMPC: Master ON\n");
892            smpc_ram[0x5f]=0x00;
893            break;
894         //in theory 0x01 is for Master OFF,but obviously is not used.
895         case 0x02:
896            if(LOG_SMPC) logerror ("SMPC: Slave ON\n");
897            smpc_ram[0x5f]=0x02;
898            stv_enable_slave_sh2 = 1;
899            cputag_set_input_line(machine, "slave", INPUT_LINE_RESET, CLEAR_LINE);
900            break;
901         case 0x03:
902            if(LOG_SMPC) logerror ("SMPC: Slave OFF\n");
903            smpc_ram[0x5f]=0x03;
904            stv_enable_slave_sh2 = 0;
905            machine.scheduler().trigger(1000);
906            cputag_set_input_line(machine, "slave", INPUT_LINE_RESET, ASSERT_LINE);
907            break;
908         case 0x06:
909            if(LOG_SMPC) logerror ("SMPC: Sound ON\n");
910            /* wrong? */
911            smpc_ram[0x5f]=0x06;
912            cputag_set_input_line(machine, "audiocpu", INPUT_LINE_RESET, CLEAR_LINE);
913            en_68k = 1;
914            break;
915         case 0x07:
916            if(LOG_SMPC) logerror ("SMPC: Sound OFF\n");
917            cputag_set_input_line(machine, "audiocpu", INPUT_LINE_RESET, ASSERT_LINE);
918            en_68k = 0;
919            smpc_ram[0x5f]=0x07;
920            break;
921         /*CD (SH-1) ON/OFF,guess that this is needed for Sports Fishing games...*/
922         //case 0x08:
923         //case 0x09:
924         case 0x0d:
925            if(LOG_SMPC) logerror ("SMPC: System Reset\n");
926            smpc_ram[0x5f]=0x0d;
927            cputag_set_input_line(machine, "maincpu", INPUT_LINE_RESET, PULSE_LINE);
928            system_reset();
929            break;
930         case 0x0e:
931            if(LOG_SMPC) logerror ("SMPC: Change Clock to 352\n");
932            smpc_ram[0x5f]=0x0e;
933            machine.device("maincpu")->set_unscaled_clock(MASTER_CLOCK_352/2);
934            machine.device("slave")->set_unscaled_clock(MASTER_CLOCK_352/2);
935            machine.device("audiocpu")->set_unscaled_clock(MASTER_CLOCK_352/5);
936            cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE); // ff said this causes nmi, should we set a timer then nmi?
937            break;
938         case 0x0f:
939            if(LOG_SMPC) logerror ("SMPC: Change Clock to 320\n");
940            smpc_ram[0x5f]=0x0f;
941            machine.device("maincpu")->set_unscaled_clock(MASTER_CLOCK_320/2);
942            machine.device("slave")->set_unscaled_clock(MASTER_CLOCK_320/2);
943            machine.device("audiocpu")->set_unscaled_clock(MASTER_CLOCK_320/5);
944            cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE); // ff said this causes nmi, should we set a timer then nmi?
945            break;
946         /*"Interrupt Back"*/
947         case 0x10:
948                      if(LOG_SMPC) logerror ("SMPC: Status Acquire (IntBack)\n");
949            smpc_ram[0x5f]=0x10;
950            smpc_ram[0x21] = (0x80) | ((NMI_reset & 1) << 6);
951            smpc_ram[0x23] = dec_2_bcd(systime.local_time.year / 100);
952                smpc_ram[0x25] = dec_2_bcd(systime.local_time.year % 100);
953                smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month + 1);
954                smpc_ram[0x29] = dec_2_bcd(systime.local_time.mday);
955                smpc_ram[0x2b] = dec_2_bcd(systime.local_time.hour);
956                smpc_ram[0x2d] = dec_2_bcd(systime.local_time.minute);
957                smpc_ram[0x2f] = dec_2_bcd(systime.local_time.second);
958
959            smpc_ram[0x31]=0x00;  //?
960
961
962            smpc_ram[0x35]=0x00;
963            smpc_ram[0x37]=0x00;
964
965            smpc_ram[0x39] = SMEM[0];
966            smpc_ram[0x3b] = SMEM[1];
967            smpc_ram[0x3d] = SMEM[2];
968            smpc_ram[0x3f] = SMEM[3];
969
970            smpc_ram[0x41]=0xff;
971            smpc_ram[0x43]=0xff;
972            smpc_ram[0x45]=0xff;
973            smpc_ram[0x47]=0xff;
974            smpc_ram[0x49]=0xff;
975            smpc_ram[0x4b]=0xff;
976            smpc_ram[0x4d]=0xff;
977            smpc_ram[0x4f]=0xff;
978            smpc_ram[0x51]=0xff;
979            smpc_ram[0x53]=0xff;
980            smpc_ram[0x55]=0xff;
981            smpc_ram[0x57]=0xff;
982            smpc_ram[0x59]=0xff;
983            smpc_ram[0x5b]=0xff;
984            smpc_ram[0x5d]=0xff;
985
986            smpcSR = 0x60;      // peripheral data ready, no reset, etc.
987            pmode = smpc_ram[1]>>4;
988
989            intback_stage = 1;
990
991         //  /*This is for RTC,cartridge code and similar stuff...*/
992         //  if(!(stv_scu[40] & 0x0080)) /*System Manager(SMPC) irq*/ /* we can't check this .. breaks controls .. probably issues elsewhere? */
993            {
994//                  if(LOG_SMPC) logerror ("Interrupt: System Manager (SMPC) at scanline %04x, Vector 0x47 Level 0x08\n",scanline);
995               smpc_intbackhelper(machine);
996               cputag_set_input_line_and_vector(machine, "maincpu", 8, HOLD_LINE , 0x47);
997            }
998         break;
999         /* RTC write*/
1000         case 0x16:
1001            if(LOG_SMPC) logerror("SMPC: RTC write\n");
1002            smpc_ram[0x2f] = smpc_ram[0x0d];
1003            smpc_ram[0x2d] = smpc_ram[0x0b];
1004            smpc_ram[0x2b] = smpc_ram[0x09];
1005            smpc_ram[0x29] = smpc_ram[0x07];
1006            smpc_ram[0x27] = smpc_ram[0x05];
1007            smpc_ram[0x25] = smpc_ram[0x03];
1008            smpc_ram[0x23] = smpc_ram[0x01];
1009            smpc_ram[0x5f]=0x16;
1010         break;
1011         /* SMPC memory setting*/
1012         case 0x17:
1013            if(LOG_SMPC) logerror ("SMPC: memory setting\n");
1014                SMEM[0] = smpc_ram[1];
1015                SMEM[1] = smpc_ram[3];
1016                SMEM[2] = smpc_ram[5];
1017                SMEM[3] = smpc_ram[7];
1018
1019            smpc_ram[0x5f]=0x17;
1020         break;
1021         case 0x18:
1022            if(LOG_SMPC) logerror ("SMPC: NMI request\n");
1023            smpc_ram[0x5f]=0x18;
1024            /*NMI is unconditionally requested?*/
1025            cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE);
1026            break;
1027         case 0x19:
1028            if(LOG_SMPC) logerror ("SMPC: NMI Enable\n");
1029            smpc_ram[0x5f]=0x19;
1030            NMI_reset = 0;
1031            smpc_ram[0x21] = (0x80) | ((NMI_reset & 1) << 6);
1032            break;
1033         case 0x1a:
1034            if(LOG_SMPC) logerror ("SMPC: NMI Disable\n");
1035            smpc_ram[0x5f]=0x1a;
1036            NMI_reset = 1;
1037            smpc_ram[0x21] = (0x80) | ((NMI_reset & 1) << 6);
1038
1039            break;
1040         default:
1041            if(LOG_SMPC) logerror ("cpu %s (PC=%08X) SMPC: undocumented Command %02x\n", space->device().tag(), cpu_get_pc(&space->device()), data);
1042      }
1043
1044      // we've processed the command, clear status flag
1045      smpc_ram[0x63] = 0x00;
1046      /*TODO:emulate the timing of each command...*/
1047   }
1048}
1049
1050
1051
1052static READ32_HANDLER ( stv_SMPC_r32 )
1053{
1054   int byte = 0;
1055   int readdata = 0;
1056   /* registers are all byte accesses, convert here */
1057   offset = offset << 2; // multiply offset by 4
1058
1059   if (ACCESSING_BITS_24_31)   { byte = 0; readdata = stv_SMPC_r8(space, offset+byte) << 24; }
1060   if (ACCESSING_BITS_16_23)   { byte = 1; readdata = stv_SMPC_r8(space, offset+byte) << 16; }
1061   if (ACCESSING_BITS_8_15)   { byte = 2; readdata = stv_SMPC_r8(space, offset+byte) << 8;  }
1062   if (ACCESSING_BITS_0_7)      { byte = 3; readdata = stv_SMPC_r8(space, offset+byte) << 0;  }
1063
1064   return readdata;
1065}
1066
1067
1068static WRITE32_HANDLER ( stv_SMPC_w32 )
1069{
1070   int byte = 0;
1071   int writedata = 0;
1072   /* registers are all byte accesses, convert here so we can use the data more easily later */
1073   offset = offset << 2; // multiply offset by 4
1074
1075   if (ACCESSING_BITS_24_31)   { byte = 0; writedata = data >> 24; }
1076   if (ACCESSING_BITS_16_23)   { byte = 1; writedata = data >> 16; }
1077   if (ACCESSING_BITS_8_15)   { byte = 2; writedata = data >> 8;  }
1078   if (ACCESSING_BITS_0_7)      { byte = 3; writedata = data >> 0;  }
1079
1080   writedata &= 0xff;
1081
1082   offset += byte;
1083
1084   stv_SMPC_w8(space, offset,writedata);
1085}
1086
1087
1088static READ32_HANDLER ( saturn_SMPC_r32 )
1089{
1090   int byte = 0;
1091   int readdata = 0;
1092   /* registers are all byte accesses, convert here */
1093   offset = offset << 2; // multiply offset by 4
1094
1095   if (ACCESSING_BITS_24_31)   { byte = 0; readdata = saturn_SMPC_r8(space, offset+byte) << 24; }
1096   if (ACCESSING_BITS_16_23)   { byte = 1; readdata = saturn_SMPC_r8(space, offset+byte) << 16; }
1097   if (ACCESSING_BITS_8_15)   { byte = 2; readdata = saturn_SMPC_r8(space, offset+byte) << 8;  }
1098   if (ACCESSING_BITS_0_7)      { byte = 3; readdata = saturn_SMPC_r8(space, offset+byte) << 0;  }
1099
1100   return readdata;
1101}
1102
1103
1104static WRITE32_HANDLER ( saturn_SMPC_w32 )
1105{
1106   int byte = 0;
1107   int writedata = 0;
1108   /* registers are all byte accesses, convert here so we can use the data more easily later */
1109   offset = offset << 2; // multiply offset by 4
1110
1111   if (ACCESSING_BITS_24_31)   { byte = 0; writedata = data >> 24; }
1112   if (ACCESSING_BITS_16_23)   { byte = 1; writedata = data >> 16; }
1113   if (ACCESSING_BITS_8_15)   { byte = 2; writedata = data >> 8;  }
1114   if (ACCESSING_BITS_0_7)      { byte = 3; writedata = data >> 0;  }
1115
1116   writedata &= 0xff;
1117
1118   offset += byte;
1119
1120   saturn_SMPC_w8(space, offset,writedata);
1121}
1122
1123/*
1124I/O overview:
1125    PORT-A  1st player inputs
1126    PORT-B  2nd player inputs
1127    PORT-C  system input
1128    PORT-D  system output
1129    PORT-E  I/O 1
1130    PORT-F  I/O 2
1131    PORT-G  I/O 3
1132    PORT-AD AD-Stick inputs?(Fake for now...)
1133    SERIAL COM
1134
1135offsets:
1136    0h PORT-A
1137    0l PORT-B
1138    1h PORT-C
1139    1l PORT-D
1140    2h PORT-E
1141    2l PORT-F (extra button layout)
1142    3h PORT-G
1143    3l
1144    4h PORT-SEL
1145    4l
1146    5h SERIAL COM WRITE
1147    5l
1148    6h SERIAL COM READ
1149    6l
1150    7h
1151    7l PORT-AD
1152*/
1153static const UINT8 port_ad[] =
1154{
1155   0xcc,0xb2,0x99,0x7f,0x66,0x4c,0x33,0x19
1156};
1157
1158static UINT8 port_sel,mux_data;
1159static int port_i;
1160
1161static READ32_HANDLER ( stv_io_r32 )
1162{
1163//  if(LOG_IOGA) logerror("(PC=%08X): I/O r %08X & %08X\n", cpu_get_pc(&space->device()), offset*4, mem_mask);
1164//  popmessage("SEL: %02x MUX: %02x OFF: %02x",port_sel,mux_data,offset*4);
1165
1166//  printf("(PC=%08X): I/O r %08X & %08X\n", cpu_get_pc(&space->device()), offset*4, mem_mask);
1167
1168   switch(offset)
1169   {
1170      case 0x00/4:
1171      switch(port_sel)
1172      {
1173         case 0x77: return 0xff000000|(input_port_read(space->machine(), "P1") << 16) |0x0000ff00|(input_port_read(space->machine(), "P2"));
1174         case 0x67:
1175         {
1176            switch(mux_data)
1177            {
1178               /*Mahjong panel interface,bit wise(ACTIVE LOW)*/
1179               case 0xfe:   return 0xff000000 | (input_port_read_safe(space->machine(), "KEY0", 0)  << 16) | 0x0000ff00 | (input_port_read_safe(space->machine(), "KEY5", 0));
1180               case 0xfd:  return 0xff000000 | (input_port_read_safe(space->machine(), "KEY1", 0)  << 16) | 0x0000ff00 | (input_port_read_safe(space->machine(), "KEY6", 0));
1181               case 0xfb:   return 0xff000000 | (input_port_read_safe(space->machine(), "KEY2", 0)  << 16) | 0x0000ff00 | (input_port_read_safe(space->machine(), "KEY7", 0));
1182               case 0xf7:   return 0xff000000 | (input_port_read_safe(space->machine(), "KEY3", 0) << 16) | 0x0000ff00 | (input_port_read_safe(space->machine(), "KEY8", 0));
1183               case 0xef:  return 0xff000000 | (input_port_read_safe(space->machine(), "KEY4", 0) << 16) | 0x0000ff00 | (input_port_read_safe(space->machine(), "KEY9", 0));
1184               /*Joystick panel*/
1185               default:
1186               //popmessage("%02x MUX DATA",mux_data);
1187                return (input_port_read(space->machine(), "P1") << 16) | (input_port_read(space->machine(), "P2"));
1188            }
1189         }
1190         case 0x47:
1191         {
1192            if ( strcmp(space->machine().system().name,"critcrsh") == 0 )
1193            {
1194               int data1 = 0, data2 = 0;
1195
1196               /* Critter Crusher */
1197               data1 = input_port_read(space->machine(), "LIGHTX");
1198               data1 = BITSWAP8(data1, 2, 3, 0, 1, 6, 7, 5, 4) & 0xf3;
1199               data1 |= (input_port_read(space->machine(), "P1") & 1) ? 0x0 : 0x4;
1200               data2 = input_port_read(space->machine(), "LIGHTY");
1201               data2 = BITSWAP8(data2, 2, 3, 0, 1, 6, 7, 5, 4) & 0xf3;
1202               data2 |= (input_port_read(space->machine(), "P1") & 1) ? 0x0 : 0x4;
1203
1204               return 0xff000000 | data1 << 16 | 0x0000ff00 | data2;
1205            }
1206         }
1207         //default:
1208         //case 0x40: return space->machine().rand();
1209         default:
1210         //popmessage("%02x PORT SEL",port_sel);
1211         return (input_port_read(space->machine(), "P1") << 16) | (input_port_read(space->machine(), "P2"));
1212      }
1213      case 0x04/4:
1214      if ( strcmp(space->machine().system().name,"critcrsh") == 0 )
1215         return ((input_port_read(space->machine(), "SYSTEM") << 16) & ((input_port_read(space->machine(), "P1") & 1) ? 0xffef0000 : 0xffff0000)) | (ioga[1]);
1216      else
1217         return (input_port_read(space->machine(), "SYSTEM") << 16) | (ioga[1]);
1218
1219      case 0x08/4:
1220      switch(port_sel)
1221      {
1222         case 0x77:   return (input_port_read(space->machine(), "UNUSED") << 16) | (input_port_read(space->machine(), "EXTRA"));
1223         case 0x67:   return 0xffffffff;/**/
1224         case 0x20:  return 0xffff0000 | (ioga[2] & 0xffff);
1225         case 0x10:  return ((ioga[2] & 0xffff) << 16) | 0xffff;
1226         case 0x60:  return 0xffffffff;/**/
1227         default:
1228         return 0xffffffff;
1229      }
1230      case 0x0c/4:
1231      switch(port_sel)
1232      {
1233         case 0x60:  return ((ioga[2] & 0xffff) << 16) | 0xffff;
1234         default:
1235         //popmessage("offs: 3 %02x",port_sel);
1236         return 0xffffffff;
1237      }
1238      //case 0x10/4:
1239      case 0x14/4:
1240      switch(port_sel)
1241      {
1242         case 0x77:
1243         {
1244            //popmessage("(PC=%06x) offs 5 %04x %02x",cpu_get_pc(&space->device()),port_sel,((ioga[5] & 0xff0000) >> 16));
1245            logerror("(PC=%06x) offs 5 %04x %02x\n",cpu_get_pc(&space->device()),port_sel,((ioga[5] & 0xff0000) >> 16));
1246
1247            //stv_workram_h[0x8e830/4] = ((ioga[5] & 0xff0000) >> 16) ^ 0x3;
1248            //stv_workram_h[0x8e834/4] = ((ioga[5] & 0xff0000) >> 16) ^ 0x3;
1249            return (ioga[5] & 0xff0000) >> 16;//stv_workram_h[0x8e830/4];//sound board data
1250         }
1251         default: return 0xffffffff;
1252      }
1253      case 0x18/4:
1254      switch(port_sel)
1255      {
1256         case 0x60:  return ioga[5];
1257         case 0x77:
1258         {
1259            //popmessage("(PC=%06x) offs 6 %04x %02x",cpu_get_pc(&space->device()),port_sel,((ioga[5] & 0xff0000) >> 16));
1260            logerror("(PC=%06x) offs 6 %04x %02x\n",cpu_get_pc(&space->device()),port_sel,((ioga[5] & 0xff0000) >> 16));
1261            return 0;//sound board status,non-zero = processing
1262         }
1263         default:
1264         //popmessage("offs: 6 %02x",port_sel);
1265         return 0xffffffff;
1266      }
1267      case 0x1c/4:
1268      if(LOG_IOGA) logerror("(PC %s=%06x) Warning: READ from PORT_AD\n", space->device().tag(), cpu_get_pc(&space->device()));
1269      popmessage("Read from PORT_AD");
1270      port_i++;
1271      return port_ad[port_i & 7];
1272      default:
1273      return ioga[offset];
1274   }
1275}
1276
1277static WRITE32_HANDLER ( stv_io_w32 )
1278{
1279//  if(LOG_IOGA) logerror("(PC=%08X): I/O w %08X = %08X & %08X\n", cpu_get_pc(&space->device()), offset*4, data, mem_mask);
1280
1281//  printf("(PC=%08X): I/O w %08X = %08X & %08X\n", cpu_get_pc(&space->device()), offset*4, data, mem_mask);
1282
1283   switch(offset)
1284   {
1285      case 0x04/4:
1286         if(ACCESSING_BITS_0_7)
1287         {
1288            /*Why does the BIOS tests these as ACTIVE HIGH? A program bug?*/
1289            ioga[1] = (data) & 0xff;
1290            coin_counter_w(space->machine(), 0,~data & 0x01);
1291            coin_counter_w(space->machine(), 1,~data & 0x02);
1292            coin_lockout_w(space->machine(), 0,~data & 0x04);
1293            coin_lockout_w(space->machine(), 1,~data & 0x08);
1294            /*
1295                other bits reserved
1296                */
1297         }
1298         break;
1299      case 0x08/4:
1300         if(ACCESSING_BITS_16_23)
1301         {
1302            ioga[2] = data >> 16;
1303            mux_data = ioga[2];
1304         }
1305         else if(ACCESSING_BITS_0_7)
1306            ioga[2] = data;
1307         break;
1308      case 0x0c/4:
1309         if(ACCESSING_BITS_16_23)
1310            ioga[3] = data;
1311         break;
1312      case 0x10/4:
1313         if(ACCESSING_BITS_16_23)
1314            port_sel = (data & 0xffff0000) >> 16;
1315         break;
1316      case 0x14/4:
1317         if(ACCESSING_BITS_16_23)
1318            ioga[5] = data;
1319         break;
1320      //case 0x18/4:
1321      case 0x1c/4:
1322         //technical bowling tests here
1323         if(ACCESSING_BITS_16_23)
1324            ioga[7] = data;
1325         break;
1326
1327   }
1328}
1329
1330/*
1331
1332SCU Handling
1333
1334*/
1335
1336/**********************************************************************************
1337SCU Register Table
1338offset,relative address
1339Registers are in long words.
1340===================================================================================
13410     0000  Level 0 DMA Set Register
13421     0004
13432     0008
13443     000c
13454     0010
13465     0014
13476     0018
13487     001c
13498     0020  Level 1 DMA Set Register
13509     0024
135110    0028
135211    002c
135312    0030
135413    0034
135514    0038
135615    003c
135716    0040  Level 2 DMA Set Register
135817    0044
135918    0048
136019    004c
136120    0050
136221    0054
136322    0058
136423    005c
136524    0060  DMA Forced Stop
136625    0064
136726    0068
136827    006c
136928    0070  <Free>
137029    0074
137130    0078
137231    007c  DMA Status Register
137332    0080  DSP Program Control Port
137433    0084  DSP Program RAM Data Port
137534    0088  DSP Data RAM Address Port
137635    008c  DSP Data RAM Data Port
137736    0090  Timer 0 Compare Register
137837    0094  Timer 1 Set Data Register
137938    0098  Timer 1 Mode Register
138039    009c  <Free>
138140    00a0  Interrupt Mask Register
138241    00a4  Interrupt Status Register
138342    00a8  A-Bus Interrupt Acknowledge
138443    00ac  <Free>
138544    00b0  A-Bus Set Register
138645    00b4
138746    00b8  A-Bus Refresh Register
138847    00bc  <Free>
138948    00c0
139049    00c4  SCU SDRAM Select Register
139150    00c8  SCU Version Register
139251    00cc  <Free>
139352    00cf
1394===================================================================================
1395DMA Status Register(32-bit):
1396xxxx xxxx x--- xx-- xx-- xx-- xx-- xx-- UNUSED
1397---- ---- -x-- ---- ---- ---- ---- ---- DMA DSP-Bus access
1398---- ---- --x- ---- ---- ---- ---- ---- DMA B-Bus access
1399---- ---- ---x ---- ---- ---- ---- ---- DMA A-Bus access
1400---- ---- ---- --x- ---- ---- ---- ---- DMA lv 1 interrupt
1401---- ---- ---- ---x ---- ---- ---- ---- DMA lv 0 interrupt
1402---- ---- ---- ---- --x- ---- ---- ---- DMA lv 2 in stand-by
1403---- ---- ---- ---- ---x ---- ---- ---- DMA lv 2 in operation
1404---- ---- ---- ---- ---- --x- ---- ---- DMA lv 1 in stand-by
1405---- ---- ---- ---- ---- ---x ---- ---- DMA lv 1 in operation
1406---- ---- ---- ---- ---- ---- --x- ---- DMA lv 0 in stand-by
1407---- ---- ---- ---- ---- ---- ---x ---- DMA lv 0 in operation
1408---- ---- ---- ---- ---- ---- ---- --x- DSP side DMA in stand-by
1409---- ---- ---- ---- ---- ---- ---- ---x DSP side DMA in operation
1410
1411**********************************************************************************/
1412/*
1413DMA TODO:
1414-Verify if there are any kind of bugs,do clean-ups,use better comments
1415 and macroize for better reading...
1416-Add timings(but how fast are each DMA?).
1417-Add level priority & DMA status register.
1418-Add DMA start factor conditions that are different than 7.
1419-Add byte data type transfer.
1420-Set boundaries.
1421*/
1422
1423#define DIRECT_MODE(_lv_)         (!(stv_scu[5+(_lv_*8)] & 0x01000000))
1424#define INDIRECT_MODE(_lv_)           (stv_scu[5+(_lv_*8)] & 0x01000000)
1425#define DRUP(_lv_)                 (stv_scu[5+(_lv_*8)] & 0x00010000)
1426#define DWUP(_lv_)                    (stv_scu[5+(_lv_*8)] & 0x00000100)
1427
1428#define DMA_STATUS            (stv_scu[31])
1429/*These macros sets the various DMA status flags.*/
1430#define D0MV_1   if(!(DMA_STATUS & 0x10))    DMA_STATUS^=0x10
1431#define D1MV_1   if(!(DMA_STATUS & 0x100))   DMA_STATUS^=0x100
1432#define D2MV_1   if(!(DMA_STATUS & 0x1000))  DMA_STATUS^=0x1000
1433#define D0MV_0   if(DMA_STATUS & 0x10)       DMA_STATUS^=0x10
1434#define D1MV_0   if(DMA_STATUS & 0x100)       DMA_STATUS^=0x100
1435#define D2MV_0   if(DMA_STATUS & 0x1000)     DMA_STATUS^=0x1000
1436
1437static UINT32 scu_index_0,scu_index_1,scu_index_2;
1438static UINT8 scsp_to_main_irq;
1439
1440static UINT32 scu_add_tmp;
1441
1442/*For area checking*/
1443#define ABUS(_lv_)       ((scu_##_lv_ & 0x07ffffff) >= 0x02000000) && ((scu_##_lv_ & 0x07ffffff) <= 0x04ffffff)
1444#define BBUS(_lv_)       ((scu_##_lv_ & 0x07ffffff) >= 0x05a00000) && ((scu_##_lv_ & 0x07ffffff) <= 0x05ffffff)
1445#define VDP1_REGS(_lv_)  ((scu_##_lv_ & 0x07ffffff) >= 0x05d00000) && ((scu_##_lv_ & 0x07ffffff) <= 0x05dfffff)
1446#define VDP2(_lv_)       ((scu_##_lv_ & 0x07ffffff) >= 0x05e00000) && ((scu_##_lv_ & 0x07ffffff) <= 0x05fdffff)
1447#define WORK_RAM_L(_lv_) ((scu_##_lv_ & 0x07ffffff) >= 0x00200000) && ((scu_##_lv_ & 0x07ffffff) <= 0x002fffff)
1448#define WORK_RAM_H(_lv_) ((scu_##_lv_ & 0x07ffffff) >= 0x06000000) && ((scu_##_lv_ & 0x07ffffff) <= 0x060fffff)
1449#define SOUND_RAM(_lv_)  ((scu_##_lv_ & 0x07ffffff) >= 0x05a00000) && ((scu_##_lv_ & 0x07ffffff) <= 0x05afffff)
1450
1451static READ32_HANDLER( stv_scu_r32 )
1452{
1453   /*TODO: write only registers must return 0...*/
1454   //popmessage("%02x",DMA_STATUS);
1455   //if (offset == 23)
1456   //{
1457      //Super Major League reads here???
1458   //}
1459   if (offset == 31)
1460   {
1461      if(LOG_SCU) logerror("(PC=%08x) DMA status reg read\n",cpu_get_pc(&space->device()));
1462      return stv_scu[offset];
1463   }
1464   else if ( offset == 35 )
1465   {
1466        if(LOG_SCU) logerror( "DSP mem read at %08X\n", stv_scu[34]);
1467        return dsp_ram_addr_r();
1468    }
1469    else if( offset == 41) /*IRQ reg status read*/
1470    {
1471      if(LOG_SCU) logerror("(PC=%08x) IRQ status reg read %08x\n",cpu_get_pc(&space->device()),mem_mask);
1472
1473      stv_scu[41] = (stv_irq.vblank_in & 1)<<0;
1474      stv_scu[41]|= (stv_irq.vblank_out & 1)<<1;
1475      stv_scu[41]|= (stv_irq.hblank_in & 1)<<2;
1476      stv_scu[41]|= (stv_irq.timer_0 & 1)<<3;
1477      stv_scu[41]|= (stv_irq.timer_1 & 1)<<4;
1478      stv_scu[41]|= (stv_irq.dsp_end & 1)<<5;
1479      stv_scu[41]|= (stv_irq.sound_req & 1)<<6;
1480      stv_scu[41]|= (stv_irq.smpc & 1)<<7;
1481      stv_scu[41]|= (stv_irq.pad & 1)<<8;
1482      stv_scu[41]|= (stv_irq.dma_end[0] & 1)<<9;
1483      stv_scu[41]|= (stv_irq.dma_end[1] & 1)<<10;
1484      stv_scu[41]|= (stv_irq.dma_end[2] & 1)<<11;
1485      stv_scu[41]|= (stv_irq.dma_ill & 1)<<12;
1486      stv_scu[41]|= (stv_irq.vdp1_end & 1)<<13;
1487      stv_scu[41]|= (stv_irq.abus & 1)<<15;
1488
1489      return stv_scu[41] ^ 0xffffffff;
1490   }
1491   else if( offset == 50 )
1492   {
1493      logerror("(PC=%08x) SCU version reg read\n",cpu_get_pc(&space->device()));
1494      return 0x00000000;/*SCU Version 0*/
1495   }
1496    else
1497    {
1498       if(LOG_SCU) logerror("(PC=%08x) SCU reg read at %d = %08x\n",cpu_get_pc(&space->device()),offset,stv_scu[offset]);
1499       return stv_scu[offset];
1500   }
1501}
1502
1503static WRITE32_HANDLER( stv_scu_w32 )
1504{
1505   COMBINE_DATA(&stv_scu[offset]);
1506
1507   switch(offset)
1508   {
1509      /*LV 0 DMA*/
1510      case 0:   scu_src_0  = ((stv_scu[0] & 0x07ffffff) >> 0); break;
1511      case 1:   scu_dst_0  = ((stv_scu[1] & 0x07ffffff) >> 0); break;
1512      case 2: scu_size_0 = ((stv_scu[2] & 0x000fffff) >> 0); break;
1513      case 3:
1514         /*Read address add value for DMA lv 0*/
1515         if(stv_scu[3] & 0x100)
1516            scu_src_add_0 = 4;
1517         else
1518            scu_src_add_0 = 1;
1519
1520         /*Write address add value for DMA lv 0*/
1521         switch(stv_scu[3] & 7)
1522         {
1523            case 0: scu_dst_add_0 = 2;   break;
1524            case 1: scu_dst_add_0 = 4;   break;
1525            case 2: scu_dst_add_0 = 8;   break;
1526            case 3: scu_dst_add_0 = 16;  break;
1527            case 4: scu_dst_add_0 = 32;  break;
1528            case 5: scu_dst_add_0 = 64;  break;
1529            case 6: scu_dst_add_0 = 128; break;
1530            case 7: scu_dst_add_0 = 256; break;
1531         }
1532         break;
1533      case 4:
1534/*
1535-stv_scu[4] bit 0 is DMA starting bit.
1536    Used when the start factor is 7.Toggle after execution.
1537-stv_scu[4] bit 8 is DMA Enable bit.
1538    This is an execution mask flag.
1539-stv_scu[5] bit 0,bit 1 and bit 2 is DMA starting factor.
1540    It must be 7 for this specific condition.
1541-stv_scu[5] bit 24 is Indirect Mode/Direct Mode (0/1).
1542*/
1543      if(stv_scu[4] & 1 && ((stv_scu[5] & 7) == 7) && stv_scu[4] & 0x100)
1544      {
1545         if(DIRECT_MODE(0)) { dma_direct_lv0(space); }
1546         else            { dma_indirect_lv0(space); }
1547
1548         stv_scu[4]^=1;//disable starting bit.
1549
1550         /*Sound IRQ*/
1551         if(/*(!(stv_scu[40] & 0x40)) &&*/ scsp_to_main_irq == 1)
1552         {
1553            //cputag_set_input_line_and_vector(space->machine(), "maincpu", 9, HOLD_LINE , 0x46);
1554            logerror("SCSP: Main CPU interrupt\n");
1555            #if 0
1556            if((scu_dst_0 & 0x7ffffff) != 0x05a00000)
1557            {
1558               if(!(stv_scu[40] & 0x1000))
1559               {
1560                  cputag_set_input_line_and_vector(space->machine(), "maincpu", 3, HOLD_LINE, 0x4c);
1561                  logerror("SCU: Illegal DMA interrupt\n");
1562               }
1563            }
1564            #endif
1565         }
1566      }
1567      break;
1568      case 5:
1569      if(INDIRECT_MODE(0))
1570      {
1571         if(LOG_SCU) logerror("Indirect Mode DMA lv 0 set\n");
1572         if(!DWUP(0)) scu_index_0 = scu_dst_0;
1573      }
1574
1575      /*Start factor enable bits,bit 2,bit 1 and bit 0*/
1576      if((stv_scu[5] & 7) != 7)
1577         if(LOG_SCU) logerror("Start factor chosen for lv 0 = %d\n",stv_scu[5] & 7);
1578      break;
1579      /*LV 1 DMA*/
1580      case 8:    scu_src_1  = ((stv_scu[8] &  0x07ffffff) >> 0);  break;
1581      case 9:    scu_dst_1  = ((stv_scu[9] &  0x07ffffff) >> 0);  break;
1582      case 10: scu_size_1 = ((stv_scu[10] & 0x00001fff) >> 0);  break;
1583      case 11:
1584      /*Read address add value for DMA lv 1*/
1585      if(stv_scu[11] & 0x100)
1586         scu_src_add_1 = 4;
1587      else
1588         scu_src_add_1 = 1;
1589
1590      /*Write address add value for DMA lv 1*/
1591      switch(stv_scu[11] & 7)
1592      {
1593         case 0: scu_dst_add_1 = 2;   break;
1594         case 1: scu_dst_add_1 = 4;   break;
1595         case 2: scu_dst_add_1 = 8;   break;
1596         case 3: scu_dst_add_1 = 16;  break;
1597         case 4: scu_dst_add_1 = 32;  break;
1598         case 5: scu_dst_add_1 = 64;  break;
1599         case 6: scu_dst_add_1 = 128; break;
1600         case 7: scu_dst_add_1 = 256; break;
1601      }
1602      break;
1603      case 12:
1604      if(stv_scu[12] & 1 && ((stv_scu[13] & 7) == 7) && stv_scu[12] & 0x100)
1605      {
1606         if(DIRECT_MODE(1)) { dma_direct_lv1(space); }
1607         else            { dma_indirect_lv1(space); }
1608
1609         stv_scu[12]^=1;
1610
1611         /*Sound IRQ*/
1612         if(/*(!(stv_scu[40] & 0x40)) &&*/ scsp_to_main_irq == 1)
1613         {
1614            //cputag_set_input_line_and_vector(space->machine(), "maincpu", 9, HOLD_LINE , 0x46);
1615            logerror("SCSP: Main CPU interrupt\n");
1616         }
1617      }
1618      break;
1619      case 13:
1620      if(INDIRECT_MODE(1))
1621      {
1622         if(LOG_SCU) logerror("Indirect Mode DMA lv 1 set\n");
1623         if(!DWUP(1)) scu_index_1 = scu_dst_1;
1624      }
1625
1626      if((stv_scu[13] & 7) != 7)
1627         if(LOG_SCU) logerror("Start factor chosen for lv 1 = %d\n",stv_scu[13] & 7);
1628      break;
1629      /*LV 2 DMA*/
1630      case 16: scu_src_2  = ((stv_scu[16] & 0x07ffffff) >> 0);  break;
1631      case 17: scu_dst_2  = ((stv_scu[17] & 0x07ffffff) >> 0);  break;
1632      case 18: scu_size_2 = ((stv_scu[18] & 0x00001fff) >> 0);  break;
1633      case 19:
1634      /*Read address add value for DMA lv 2*/
1635      if(stv_scu[19] & 0x100)
1636         scu_src_add_2 = 4;
1637      else
1638         scu_src_add_2 = 1;
1639
1640      /*Write address add value for DMA lv 2*/
1641      switch(stv_scu[19] & 7)
1642      {
1643         case 0: scu_dst_add_2 = 2;   break;
1644         case 1: scu_dst_add_2 = 4;   break;
1645         case 2: scu_dst_add_2 = 8;   break;
1646         case 3: scu_dst_add_2 = 16;  break;
1647         case 4: scu_dst_add_2 = 32;  break;
1648         case 5: scu_dst_add_2 = 64;  break;
1649         case 6: scu_dst_add_2 = 128; break;
1650         case 7: scu_dst_add_2 = 256; break;
1651      }
1652      break;
1653      case 20:
1654      if(stv_scu[20] & 1 && ((stv_scu[21] & 7) == 7) && stv_scu[20] & 0x100)
1655      {
1656         if(DIRECT_MODE(2)) { dma_direct_lv2(space); }
1657         else            { dma_indirect_lv2(space); }
1658
1659         stv_scu[20]^=1;
1660
1661         /*Sound IRQ*/
1662         if(/*(!(stv_scu[40] & 0x40)) &&*/ scsp_to_main_irq == 1)
1663         {
1664            //cputag_set_input_line_and_vector(space->machine(), "maincpu", 9, HOLD_LINE , 0x46);
1665            logerror("SCSP: Main CPU interrupt\n");
1666         }
1667      }
1668      break;
1669      case 21:
1670      if(INDIRECT_MODE(2))
1671      {
1672         if(LOG_SCU) logerror("Indirect Mode DMA lv 2 set\n");
1673         if(!DWUP(2)) scu_index_2 = scu_dst_2;
1674      }
1675
1676      if((stv_scu[21] & 7) != 7)
1677         if(LOG_SCU) logerror("Start factor chosen for lv 2 = %d\n",stv_scu[21] & 7);
1678      break;
1679      case 24:
1680      if(LOG_SCU) logerror("DMA Forced Stop Register set = %02x\n",stv_scu[24]);
1681      break;
1682      case 31: if(LOG_SCU) logerror("Warning: DMA status WRITE! Offset %02x(%d)\n",offset*4,offset); break;
1683      /*DSP section*/
1684      /*Use functions so it is easier to work out*/
1685      case 32:
1686      dsp_prg_ctrl(space, data);
1687      if(LOG_SCU) logerror("SCU DSP: Program Control Port Access %08x\n",data);
1688      break;
1689      case 33:
1690      dsp_prg_data(data);
1691      if(LOG_SCU) logerror("SCU DSP: Program RAM Data Port Access %08x\n",data);
1692      break;
1693      case 34:
1694      dsp_ram_addr_ctrl(data);
1695      if(LOG_SCU) logerror("SCU DSP: Data RAM Address Port Access %08x\n",data);
1696      break;
1697      case 35:
1698      dsp_ram_addr_w(data);
1699      if(LOG_SCU) logerror("SCU DSP: Data RAM Data Port Access %08x\n",data);
1700      break;
1701      case 36: if(LOG_SCU) logerror("timer 0 compare data = %03x\n",stv_scu[36]);break;
1702      case 37: if(LOG_SCU) logerror("timer 1 set data = %08x\n",stv_scu[37]); break;
1703      case 38: if(LOG_SCU) logerror("timer 1 mode data = %08x\n",stv_scu[38]); break;
1704      case 40:
1705      /*An interrupt is masked when his specific bit is 1.*/
1706      /*Are bit 16-bit 31 for External A-Bus irq mask like the status register?*/
1707
1708      stv_irq.vblank_in =  (((stv_scu[40] & 0x0001)>>0) ^ 1);
1709      stv_irq.vblank_out = (((stv_scu[40] & 0x0002)>>1) ^ 1);
1710      stv_irq.hblank_in =  (((stv_scu[40] & 0x0004)>>2) ^ 1);
1711      stv_irq.timer_0 =    (((stv_scu[40] & 0x0008)>>3) ^ 1);
1712      stv_irq.timer_1 =    (((stv_scu[40] & 0x0010)>>4) ^ 1);
1713      stv_irq.dsp_end =    (((stv_scu[40] & 0x0020)>>5) ^ 1);
1714      stv_irq.sound_req =  (((stv_scu[40] & 0x0040)>>6) ^ 1);
1715      stv_irq.smpc =       (((stv_scu[40] & 0x0080)>>7)); //NOTE: SCU bug
1716      stv_irq.pad =        (((stv_scu[40] & 0x0100)>>8) ^ 1);
1717      stv_irq.dma_end[2] = (((stv_scu[40] & 0x0200)>>9) ^ 1);
1718      stv_irq.dma_end[1] = (((stv_scu[40] & 0x0400)>>10) ^ 1);
1719      stv_irq.dma_end[0] = (((stv_scu[40] & 0x0800)>>11) ^ 1);
1720      stv_irq.dma_ill =    (((stv_scu[40] & 0x1000)>>12) ^ 1);
1721      stv_irq.vdp1_end =   (((stv_scu[40] & 0x2000)>>13) ^ 1);
1722      stv_irq.abus =       (((stv_scu[40] & 0x8000)>>15) ^ 1);
1723
1724      /*Take out the common settings to keep logging quiet.*/
1725      if(stv_scu[40] != 0xfffffffe &&
1726         stv_scu[40] != 0xfffffffc &&
1727         stv_scu[40] != 0xffffffff)
1728      {
1729         if(LOG_SCU) logerror("cpu %s (PC=%08X) IRQ mask reg set %08x = %d%d%d%d|%d%d%d%d|%d%d%d%d|%d%d%d%d\n",
1730         space->device().tag(), cpu_get_pc(&space->device()),
1731         stv_scu[offset],
1732         stv_scu[offset] & 0x8000 ? 1 : 0, /*A-Bus irq*/
1733         stv_scu[offset] & 0x4000 ? 1 : 0, /*<reserved>*/
1734         stv_scu[offset] & 0x2000 ? 1 : 0, /*Sprite draw end irq(VDP1)*/
1735         stv_scu[offset] & 0x1000 ? 1 : 0, /*Illegal DMA irq*/
1736         stv_scu[offset] & 0x0800 ? 1 : 0, /*Lv 0 DMA end irq*/
1737         stv_scu[offset] & 0x0400 ? 1 : 0, /*Lv 1 DMA end irq*/
1738         stv_scu[offset] & 0x0200 ? 1 : 0, /*Lv 2 DMA end irq*/
1739         stv_scu[offset] & 0x0100 ? 1 : 0, /*PAD irq*/
1740         stv_scu[offset] & 0x0080 ? 1 : 0, /*System Manager(SMPC) irq*/
1741         stv_scu[offset] & 0x0040 ? 1 : 0, /*Snd req*/
1742         stv_scu[offset] & 0x0020 ? 1 : 0, /*DSP irq end*/
1743         stv_scu[offset] & 0x0010 ? 1 : 0, /*Timer 1 irq*/
1744         stv_scu[offset] & 0x0008 ? 1 : 0, /*Timer 0 irq*/
1745         stv_scu[offset] & 0x0004 ? 1 : 0, /*HBlank-IN*/
1746         stv_scu[offset] & 0x0002 ? 1 : 0, /*VBlank-OUT*/
1747         stv_scu[offset] & 0x0001 ? 1 : 0);/*VBlank-IN*/
1748      }
1749      break;
1750      /*Interrupt Control reg Set*/
1751      case 41:
1752      /*This is r/w by introdon...*/
1753      if(LOG_SCU) logerror("IRQ status reg set:%08x %08x\n",stv_scu[41],mem_mask);
1754
1755      stv_irq.vblank_in =  ((stv_scu[41] & 0x0001)>>0);
1756      stv_irq.vblank_out = ((stv_scu[41] & 0x0002)>>1);
1757      stv_irq.hblank_in =  ((stv_scu[41] & 0x0004)>>2);
1758      stv_irq.timer_0 =    ((stv_scu[41] & 0x0008)>>3);
1759      stv_irq.timer_1 =    ((stv_scu[41] & 0x0010)>>4);
1760      stv_irq.dsp_end =    ((stv_scu[41] & 0x0020)>>5);
1761      stv_irq.sound_req =  ((stv_scu[41] & 0x0040)>>6);
1762      stv_irq.smpc =       ((stv_scu[41] & 0x0080)>>7);
1763      stv_irq.pad =        ((stv_scu[41] & 0x0100)>>8);
1764      stv_irq.dma_end[2] = ((stv_scu[41] & 0x0200)>>9);
1765      stv_irq.dma_end[1] = ((stv_scu[41] & 0x0400)>>10);
1766      stv_irq.dma_end[0] = ((stv_scu[41] & 0x0800)>>11);
1767      stv_irq.dma_ill =    ((stv_scu[41] & 0x1000)>>12);
1768      stv_irq.vdp1_end =   ((stv_scu[41] & 0x2000)>>13);
1769      stv_irq.abus =       ((stv_scu[41] & 0x8000)>>15);
1770
1771      break;
1772      case 42: if(LOG_SCU) logerror("A-Bus IRQ ACK %08x\n",stv_scu[42]); break;
1773      case 49: if(LOG_SCU) logerror("SCU SDRAM set: %02x\n",stv_scu[49]); break;
1774      default: if(LOG_SCU) logerror("Warning: unused SCU reg set %d = %08x\n",offset,data);
1775   }
1776}
1777
1778/*Lv 0 DMA end irq*/
1779static TIMER_CALLBACK( dma_lv0_ended )
1780{
1781   cputag_set_input_line_and_vector(machine, "maincpu", 5, (stv_irq.dma_end[0]) ? HOLD_LINE : CLEAR_LINE, 0x4b);
1782
1783   D0MV_0;
1784}
1785
1786/*Lv 1 DMA end irq*/
1787static TIMER_CALLBACK( dma_lv1_ended )
1788{
1789   cputag_set_input_line_and_vector(machine, "maincpu", 6, (stv_irq.dma_end[1]) ? HOLD_LINE : CLEAR_LINE, 0x4a);
1790
1791   D1MV_0;
1792}
1793
1794/*Lv 2 DMA end irq*/
1795static TIMER_CALLBACK( dma_lv2_ended )
1796{
1797   cputag_set_input_line_and_vector(machine, "maincpu", 6, (stv_irq.dma_end[2]) ? HOLD_LINE : CLEAR_LINE, 0x49);
1798
1799   D2MV_0;
1800}
1801
1802static void dma_direct_lv0(address_space *space)
1803{
1804   static UINT32 tmp_src,tmp_dst,tmp_size;
1805   if(LOG_SCU) logerror("DMA lv 0 transfer START\n"
1806                      "Start %08x End %08x Size %04x\n",scu_src_0,scu_dst_0,scu_size_0);
1807   if(LOG_SCU) logerror("Start Add %04x Destination Add %04x\n",scu_src_add_0,scu_dst_add_0);
1808
1809   D0MV_1;
1810
1811   if(scu_size_0 == 0) scu_size_0 = 0x00100000;
1812
1813   scsp_to_main_irq = 0;
1814
1815   /*set here the boundaries checks*/
1816   /*...*/
1817
1818   if(SOUND_RAM(dst_0))
1819   {
1820      logerror("Sound RAM DMA write\n");
1821      scsp_to_main_irq = 1;
1822   }
1823
1824   if((scu_dst_add_0 != scu_src_add_0) && (ABUS(src_0)))
1825   {
1826      logerror("A-Bus invalid transfer,sets to default\n");
1827      scu_add_tmp = (scu_dst_add_0*0x100) | (scu_src_add_0);
1828      scu_dst_add_0 = scu_src_add_0 = 4;
1829      scu_add_tmp |= 0x80000000;
1830   }
1831   /*Let me know if you encounter any of these three*/
1832   if(ABUS(dst_0))
1833   {
1834      logerror("A-Bus invalid write\n");
1835      /*...*/
1836   }
1837   if(WORK_RAM_L(dst_0))
1838   {
1839      logerror("WorkRam-L invalid write\n");
1840      /*...*/
1841   }
1842   if(VDP2(src_0))
1843   {
1844      logerror("VDP-2 invalid read\n");
1845      /*...*/
1846   }
1847   if(VDP1_REGS(dst_0))
1848   {
1849      logerror("VDP1 register access,must be in word units\n");
1850      scu_add_tmp = (scu_dst_add_0*0x100) | (scu_src_add_0);
1851      scu_dst_add_0 = scu_src_add_0 = 2;
1852      scu_add_tmp |= 0x80000000;
1853   }
1854   if(DRUP(0))
1855   {
1856      logerror("Data read update = 1,read address add value must be 1 too\n");
1857      scu_add_tmp = (scu_dst_add_0*0x100) | (scu_src_add_0);
1858      scu_src_add_0 = 4;
1859      scu_add_tmp |= 0x80000000;
1860   }
1861
1862   if (WORK_RAM_H(dst_0) && (scu_dst_add_0 != 4))
1863   {
1864      scu_add_tmp = (scu_dst_add_0*0x100) | (scu_src_add_0);
1865      scu_dst_add_0 = 4;
1866      scu_add_tmp |= 0x80000000;
1867   }
1868
1869   tmp_size = scu_size_0;
1870   if(!(DRUP(0))) tmp_src = scu_src_0;
1871   if(!(DWUP(0))) tmp_dst = scu_dst_0;
1872
1873   for (; scu_size_0 > 0; scu_size_0-=scu_dst_add_0)
1874   {
1875      if(scu_dst_add_0 == 2)
1876         space->write_word(scu_dst_0,space->read_word(scu_src_0));
1877      else if(scu_dst_add_0 == 8)
1878      {
1879         space->write_word(scu_dst_0,space->read_word(scu_src_0));
1880         space->write_word(scu_dst_0+2,space->read_word(scu_src_0));
1881         space->write_word(scu_dst_0+4,space->read_word(scu_src_0+2));
1882         space->write_word(scu_dst_0+6,space->read_word(scu_src_0+2));
1883      }
1884      else
1885      {
1886         space->write_word(scu_dst_0,space->read_word(scu_src_0));
1887         space->write_word(scu_dst_0+2,space->read_word(scu_src_0+2));
1888      }
1889
1890      scu_dst_0+=scu_dst_add_0;
1891      scu_src_0+=scu_src_add_0;
1892   }
1893
1894   scu_size_0 = tmp_size;
1895   if(!(DRUP(0))) scu_src_0 = tmp_src;
1896   if(!(DWUP(0))) scu_dst_0 = tmp_dst;
1897
1898   if(LOG_SCU) logerror("DMA transfer END\n");
1899
1900   /*TODO: timing of this*/
1901   space->machine().scheduler().timer_set(attotime::from_usec(300), FUNC(dma_lv0_ended));
1902
1903   if(scu_add_tmp & 0x80000000)
1904   {
1905      scu_dst_add_0 = (scu_add_tmp & 0xff00) >> 8;
1906      scu_src_add_0 = (scu_add_tmp & 0x00ff) >> 0;
1907      scu_add_tmp^=0x80000000;
1908   }
1909}
1910
1911static void dma_direct_lv1(address_space *space)
1912{
1913   static UINT32 tmp_src,tmp_dst,tmp_size;
1914   if(LOG_SCU) logerror("DMA lv 1 transfer START\n"
1915          "Start %08x End %08x Size %04x\n",scu_src_1,scu_dst_1,scu_size_1);
1916   if(LOG_SCU) logerror("Start Add %04x Destination Add %04x\n",scu_src_add_1,scu_dst_add_1);
1917
1918   D1MV_1;
1919
1920   if(scu_size_1 == 0) scu_size_1 = 0x00002000;
1921
1922   scsp_to_main_irq = 0;
1923
1924   /*set here the boundaries checks*/
1925   /*...*/
1926
1927   if(SOUND_RAM(dst_1))
1928   {
1929      logerror("Sound RAM DMA write\n");
1930      scsp_to_main_irq = 1;
1931   }
1932
1933   if((scu_dst_add_1 != scu_src_add_1) && (ABUS(src_1)))
1934   {
1935      logerror("A-Bus invalid transfer,sets to default\n");
1936      scu_add_tmp = (scu_dst_add_1*0x100) | (scu_src_add_1);
1937      scu_dst_add_1 = scu_src_add_1 = 4;
1938      scu_add_tmp |= 0x80000000;
1939   }
1940   /*Let me know if you encounter any of these ones*/
1941   if(ABUS(dst_1))
1942   {
1943      logerror("A-Bus invalid write\n");
1944      /*...*/
1945   }
1946   if(WORK_RAM_L(dst_1))
1947   {
1948      logerror("WorkRam-L invalid write\n");
1949      /*...*/
1950   }
1951   if(VDP1_REGS(dst_1))
1952   {
1953      logerror("VDP1 register access,must be in word units\n");
1954      scu_add_tmp = (scu_dst_add_1*0x100) | (scu_src_add_1);
1955      scu_dst_add_1 = scu_src_add_1 = 2;
1956      scu_add_tmp |= 0x80000000;
1957   }
1958   if(VDP2(src_1))
1959   {
1960      logerror("VDP-2 invalid read\n");
1961      /*...*/
1962   }
1963   if(DRUP(1))
1964   {
1965      logerror("Data read update = 1,read address add value must be 1 too\n");
1966      scu_add_tmp = (scu_dst_add_1*0x100) | (scu_src_add_1);
1967      scu_src_add_1 = 4;
1968      scu_add_tmp |= 0x80000000;
1969   }
1970
1971   if (WORK_RAM_H(dst_1) && (scu_dst_add_1 != 4))
1972   {
1973      scu_add_tmp = (scu_dst_add_1*0x100) | (scu_src_add_1);
1974      scu_src_add_1 = 4;
1975      scu_add_tmp |= 0x80000000;
1976   }
1977
1978   tmp_size = scu_size_1;
1979   if(!(DRUP(1))) tmp_src = scu_src_1;
1980   if(!(DWUP(1))) tmp_dst = scu_dst_1;
1981
1982   for (; scu_size_1 > 0; scu_size_1-=scu_dst_add_1)
1983   {
1984      if(scu_dst_add_1 == 2)
1985         space->write_word(scu_dst_1,space->read_word(scu_src_1));
1986      else
1987      {
1988         space->write_word(scu_dst_1,space->read_word(scu_src_1));
1989         space->write_word(scu_dst_1+2,space->read_word(scu_src_1+2));
1990      }
1991
1992      scu_dst_1+=scu_dst_add_1;
1993      scu_src_1+=scu_src_add_1;
1994   }
1995
1996   scu_size_1 = tmp_size;
1997   if(!(DRUP(1))) scu_src_1 = tmp_src;
1998   if(!(DWUP(1))) scu_dst_1 = tmp_dst;
1999
2000   if(LOG_SCU) logerror("DMA transfer END\n");
2001
2002   space->machine().scheduler().timer_set(attotime::from_usec(300), FUNC(dma_lv1_ended));
2003
2004   if(scu_add_tmp & 0x80000000)
2005   {
2006      scu_dst_add_1 = (scu_add_tmp & 0xff00) >> 8;
2007      scu_src_add_1 = (scu_add_tmp & 0x00ff) >> 0;
2008      scu_add_tmp^=0x80000000;
2009   }
2010}
2011
2012static void dma_direct_lv2(address_space *space)
2013{
2014   static UINT32 tmp_src,tmp_dst,tmp_size;
2015   if(LOG_SCU) logerror("DMA lv 2 transfer START\n"
2016          "Start %08x End %08x Size %04x\n",scu_src_2,scu_dst_2,scu_size_2);
2017   if(LOG_SCU) logerror("Start Add %04x Destination Add %04x\n",scu_src_add_2,scu_dst_add_2);
2018
2019   D2MV_1;
2020
2021   scsp_to_main_irq = 0;
2022
2023   if(scu_size_2 == 0) scu_size_2 = 0x00002000;
2024
2025   /*set here the boundaries checks*/
2026   /*...*/
2027
2028   if(SOUND_RAM(dst_2))
2029   {
2030      logerror("Sound RAM DMA write\n");
2031      scsp_to_main_irq = 1;
2032   }
2033
2034   if((scu_dst_add_2 != scu_src_add_2) && (ABUS(src_2)))
2035   {
2036      logerror("A-Bus invalid transfer,sets to default\n");
2037      scu_add_tmp = (scu_dst_add_2*0x100) | (scu_src_add_2);
2038      scu_dst_add_2 = scu_src_add_2 = 4;
2039      scu_add_tmp |= 0x80000000;
2040   }
2041   /*Let me know if you encounter any of these ones*/
2042   if(ABUS(dst_2))
2043   {
2044      logerror("A-Bus invalid write\n");
2045      /*...*/
2046   }
2047   if(WORK_RAM_L(dst_2))
2048   {
2049      logerror("WorkRam-L invalid write\n");
2050      /*...*/
2051   }
2052   if(VDP1_REGS(dst_2))
2053   {
2054      logerror("VDP1 register access,must be in word units\n");
2055      scu_add_tmp = (scu_dst_add_2*0x100) | (scu_src_add_2);
2056      scu_dst_add_2 = scu_src_add_2 = 2;
2057      scu_add_tmp |= 0x80000000;
2058   }
2059   if(VDP2(src_2))
2060   {
2061      logerror("VDP-2 invalid read\n");
2062      /*...*/
2063   }
2064   if(DRUP(2))
2065   {
2066      logerror("Data read update = 1,read address add value must be 1 too\n");
2067      scu_add_tmp = (scu_dst_add_2*0x100) | (scu_src_add_2);
2068      scu_src_add_2 = 4;
2069      scu_add_tmp |= 0x80000000;
2070   }
2071
2072   if (WORK_RAM_H(dst_2) && (scu_dst_add_2 != 4))
2073   {
2074      scu_add_tmp = (scu_dst_add_2*0x100) | (scu_src_add_2);
2075      scu_src_add_2 = 4;
2076      scu_add_tmp |= 0x80000000;
2077   }
2078
2079   tmp_size = scu_size_2;
2080   if(!(DRUP(2))) tmp_src = scu_src_2;
2081   if(!(DWUP(2))) tmp_dst = scu_dst_2;
2082
2083   for (; scu_size_2 > 0; scu_size_2-=scu_dst_add_2)
2084   {
2085      if(scu_dst_add_2 == 2)
2086         space->write_word(scu_dst_2,space->read_word(scu_src_2));
2087      else
2088      {
2089         space->write_word(scu_dst_2,space->read_word(scu_src_2));
2090         space->write_word(scu_dst_2+2,space->read_word(scu_src_2+2));
2091      }
2092
2093      scu_dst_2+=scu_dst_add_2;
2094      scu_src_2+=scu_src_add_2;
2095   }
2096
2097   scu_size_2 = tmp_size;
2098   if(!(DRUP(2))) scu_src_2 = tmp_src;
2099   if(!(DWUP(2))) scu_dst_2 = tmp_dst;
2100
2101   if(LOG_SCU) logerror("DMA transfer END\n");
2102
2103   space->machine().scheduler().timer_set(attotime::from_usec(300), FUNC(dma_lv2_ended));
2104
2105   if(scu_add_tmp & 0x80000000)
2106   {
2107      scu_dst_add_2 = (scu_add_tmp & 0xff00) >> 8;
2108      scu_src_add_2 = (scu_add_tmp & 0x00ff) >> 0;
2109      scu_add_tmp^=0x80000000;
2110   }
2111}
2112
2113static void dma_indirect_lv0(address_space *space)
2114{
2115   /*Helper to get out of the cycle*/
2116   UINT8 job_done = 0;
2117   /*temporary storage for the transfer data*/
2118   UINT32 tmp_src;
2119
2120   D0MV_1;
2121
2122   scsp_to_main_irq = 0;
2123
2124   if(scu_index_0 == 0) { scu_index_0 = scu_dst_0; }
2125
2126   do{
2127      tmp_src = scu_index_0;
2128
2129      /*Thanks for Runik of Saturnin for pointing this out...*/
2130      scu_size_0 = space->read_dword(scu_index_0);
2131      scu_src_0 =  space->read_dword(scu_index_0+8);
2132      scu_dst_0 =  space->read_dword(scu_index_0+4);
2133
2134      /*Indirect Mode end factor*/
2135      if(scu_src_0 & 0x80000000)
2136         job_done = 1;
2137
2138      if(SOUND_RAM(dst_0))
2139      {
2140         logerror("Sound RAM DMA write\n");
2141         scsp_to_main_irq = 1;
2142      }
2143
2144      if(LOG_SCU) logerror("DMA lv 0 indirect mode transfer START\n"
2145             "Start %08x End %08x Size %04x\n",scu_src_0,scu_dst_0,scu_size_0);
2146      if(LOG_SCU) logerror("Start Add %04x Destination Add %04x\n",scu_src_add_0,scu_dst_add_0);
2147
2148      //guess,but I believe it's right.
2149      scu_src_0 &=0x07ffffff;
2150      scu_dst_0 &=0x07ffffff;
2151      scu_size_0 &=0xfffff;
2152
2153      for (; scu_size_0 > 0; scu_size_0-=scu_dst_add_0)
2154      {
2155         if(scu_dst_add_0 == 2)
2156            space->write_word(scu_dst_0,space->read_word(scu_src_0));
2157         else
2158         {
2159            /* some games, eg columns97 are a bit weird, I'm not sure this is correct
2160                  they start a dma on a 2 byte boundary in 4 byte add mode, using the dword reads we
2161                  can't access 2 byte boundaries, and the end of the sprite list never gets marked,
2162                  the length of the transfer is also set to a 2 byte boundary, maybe the add values
2163                  should be different, I don't know */
2164            space->write_word(scu_dst_0,space->read_word(scu_src_0));
2165            space->write_word(scu_dst_0+2,space->read_word(scu_src_0+2));
2166         }
2167         scu_dst_0+=scu_dst_add_0;
2168         scu_src_0+=scu_src_add_0;
2169      }
2170
2171      //if(DRUP(0))   space->write_dword(tmp_src+8,scu_src_0|job_done ? 0x80000000 : 0);
2172      //if(DWUP(0)) space->write_dword(tmp_src+4,scu_dst_0);
2173
2174      scu_index_0 = tmp_src+0xc;
2175
2176   }while(job_done == 0);
2177
2178   space->machine().scheduler().timer_set(attotime::from_usec(300), FUNC(dma_lv0_ended));
2179}
2180
2181static void dma_indirect_lv1(address_space *space)
2182{
2183   /*Helper to get out of the cycle*/
2184   UINT8 job_done = 0;
2185   /*temporary storage for the transfer data*/
2186   UINT32 tmp_src;
2187
2188   D1MV_1;
2189
2190   scsp_to_main_irq = 0;
2191
2192   if(scu_index_1 == 0) { scu_index_1 = scu_dst_1; }
2193
2194   do{
2195      tmp_src = scu_index_1;
2196
2197      scu_size_1 = space->read_dword(scu_index_1);
2198      scu_src_1 =  space->read_dword(scu_index_1+8);
2199      scu_dst_1 =  space->read_dword(scu_index_1+4);
2200
2201      /*Indirect Mode end factor*/
2202      if(scu_src_1 & 0x80000000)
2203         job_done = 1;
2204
2205      if(SOUND_RAM(dst_1))
2206      {
2207         logerror("Sound RAM DMA write\n");
2208         scsp_to_main_irq = 1;
2209      }
2210
2211      if(LOG_SCU) logerror("DMA lv 1 indirect mode transfer START\n"
2212             "Start %08x End %08x Size %04x\n",scu_src_1,scu_dst_1,scu_size_1);
2213      if(LOG_SCU) logerror("Start Add %04x Destination Add %04x\n",scu_src_add_1,scu_dst_add_1);
2214
2215      //guess,but I believe it's right.
2216      scu_src_1 &=0x07ffffff;
2217      scu_dst_1 &=0x07ffffff;
2218      scu_size_1 &=0xffff;
2219
2220
2221      for (; scu_size_1 > 0; scu_size_1-=scu_dst_add_1)
2222      {
2223
2224         if(scu_dst_add_1 == 2)
2225            space->write_word(scu_dst_1,space->read_word(scu_src_1));
2226         else
2227         {
2228            /* some games, eg columns97 are a bit weird, I'm not sure this is correct
2229                  they start a dma on a 2 byte boundary in 4 byte add mode, using the dword reads we
2230                  can't access 2 byte boundaries, and the end of the sprite list never gets marked,
2231                  the length of the transfer is also set to a 2 byte boundary, maybe the add values
2232                  should be different, I don't know */
2233            space->write_word(scu_dst_1,space->read_word(scu_src_1));
2234            space->write_word(scu_dst_1+2,space->read_word(scu_src_1+2));
2235         }
2236         scu_dst_1+=scu_dst_add_1;
2237         scu_src_1+=scu_src_add_1;
2238      }
2239
2240      //if(DRUP(1))   space->write_dword(tmp_src+8,scu_src_1|job_done ? 0x80000000 : 0);
2241      //if(DWUP(1)) space->write_dword(tmp_src+4,scu_dst_1);
2242
2243      scu_index_1 = tmp_src+0xc;
2244
2245   }while(job_done == 0);
2246
2247   space->machine().scheduler().timer_set(attotime::from_usec(300), FUNC(dma_lv1_ended));
2248}
2249
2250static void dma_indirect_lv2(address_space *space)
2251{
2252   /*Helper to get out of the cycle*/
2253   UINT8 job_done = 0;
2254   /*temporary storage for the transfer data*/
2255   UINT32 tmp_src;
2256
2257   D2MV_1;
2258
2259   scsp_to_main_irq = 0;
2260
2261   if(scu_index_2 == 0) { scu_index_2 = scu_dst_2; }
2262
2263   do{
2264      tmp_src = scu_index_2;
2265
2266      scu_size_2 = space->read_dword(scu_index_2);
2267      scu_src_2 =  space->read_dword(scu_index_2+8);
2268      scu_dst_2 =  space->read_dword(scu_index_2+4);
2269
2270      /*Indirect Mode end factor*/
2271      if(scu_src_2 & 0x80000000)
2272         job_done = 1;
2273
2274      if(SOUND_RAM(dst_2))
2275      {
2276         logerror("Sound RAM DMA write\n");
2277         scsp_to_main_irq = 1;
2278      }
2279
2280      if(LOG_SCU) logerror("DMA lv 2 indirect mode transfer START\n"
2281             "Start %08x End %08x Size %04x\n",scu_src_2,scu_dst_2,scu_size_2);
2282      if(LOG_SCU) logerror("Start Add %04x Destination Add %04x\n",scu_src_add_2,scu_dst_add_2);
2283
2284      //guess,but I believe it's right.
2285      scu_src_2 &=0x07ffffff;
2286      scu_dst_2 &=0x07ffffff;
2287      scu_size_2 &=0xffff;
2288
2289      for (; scu_size_2 > 0; scu_size_2-=scu_dst_add_2)
2290      {
2291         if(scu_dst_add_2 == 2)
2292            space->write_word(scu_dst_2,space->read_word(scu_src_2));
2293         else
2294         {
2295            /* some games, eg columns97 are a bit weird, I'm not sure this is correct
2296                  they start a dma on a 2 byte boundary in 4 byte add mode, using the dword reads we
2297                  can't access 2 byte boundaries, and the end of the sprite list never gets marked,
2298                  the length of the transfer is also set to a 2 byte boundary, maybe the add values
2299                  should be different, I don't know */
2300            space->write_word(scu_dst_2,space->read_word(scu_src_2));
2301            space->write_word(scu_dst_2+2,space->read_word(scu_src_2+2));
2302         }
2303
2304         scu_dst_2+=scu_dst_add_2;
2305         scu_src_2+=scu_src_add_2;
2306      }
2307
2308      //if(DRUP(2))   space->write_dword(tmp_src+8,scu_src_2|job_done ? 0x80000000 : 0);
2309      //if(DWUP(2)) space->write_dword(tmp_src+4,scu_dst_2);
2310
2311      scu_index_2 = tmp_src+0xc;
2312
2313   }while(job_done == 0);
2314
2315   space->machine().scheduler().timer_set(attotime::from_usec(300), FUNC(dma_lv2_ended));
2316}
2317
2318
2319/**************************************************************************************/
2320
2321static WRITE32_HANDLER( stv_sh2_soundram_w )
2322{
2323   COMBINE_DATA(sound_ram+offset*2+1);
2324   data >>= 16;
2325   mem_mask >>= 16;
2326   COMBINE_DATA(sound_ram+offset*2);
2327}
2328
2329static READ32_HANDLER( stv_sh2_soundram_r )
2330{
2331   return (sound_ram[offset*2]<<16)|sound_ram[offset*2+1];
2332}
2333
2334/* communication,SLAVE CPU acquires data from the MASTER CPU and triggers an irq.  *
2335 * Enter into Radiant Silver Gun specific menu for a test...                       */
2336static WRITE32_HANDLER( minit_w )
2337{
2338   logerror("cpu %s (PC=%08X) MINIT write = %08x\n", space->device().tag(), cpu_get_pc(&space->device()),data);
2339   space->machine().scheduler().boost_interleave(minit_boost_timeslice, attotime::from_usec(minit_boost));
2340   space->machine().scheduler().trigger(1000);
2341   sh2_set_frt_input(space->machine().device("slave"), PULSE_LINE);
2342}
2343
2344static WRITE32_HANDLER( sinit_w )
2345{
2346   logerror("cpu %s (PC=%08X) SINIT write = %08x\n", space->device().tag(), cpu_get_pc(&space->device()),data);
2347   space->machine().scheduler().boost_interleave(sinit_boost_timeslice, attotime::from_usec(sinit_boost));
2348   sh2_set_frt_input(space->machine().device("maincpu"), PULSE_LINE);
2349}
2350
2351
2352#ifdef UNUSED_FUNCTION
2353static READ32_HANDLER( stv_sh2_random_r )
2354{
2355   return 0xffffffff;
2356}
2357#endif
2358
2359
2360static UINT32 backup[64*1024/4];
2361
2362static READ32_HANDLER(satram_r)
2363{
2364   return backup[offset] & 0x00ff00ff;   // yes, it makes sure the "holes" are there.
2365}
2366
2367static WRITE32_HANDLER(satram_w)
2368{
2369   COMBINE_DATA(&backup[offset]);
2370}
2371
2372static NVRAM_HANDLER(saturn)
2373{
2374   static const UINT32 init[8] =
2375   {
2376      0x420061, 0x63006b, 0x550070, 0x520061, 0x6d0020, 0x46006f, 0x72006d, 0x610074,
2377   };
2378   int i;
2379
2380   if (read_or_write)
2381      file->write(backup, 64*1024/4);
2382   else
2383   {
2384      if (file)
2385      {
2386         file->read(backup, 64*1024/4);
2387      }
2388      else
2389      {
2390         memset(backup, 0, 64*1024/4);
2391         for (i = 0; i < 8; i++)
2392         {
2393            backup[i] = init[i];
2394            backup[i+8] = init[i];
2395            backup[i+16] = init[i];
2396            backup[i+24] = init[i];
2397         }
2398      }
2399   }
2400}
2401
2402static ADDRESS_MAP_START( saturn_mem, AS_PROGRAM, 32 )
2403   AM_RANGE(0x00000000, 0x0007ffff) AM_ROM AM_SHARE("share6")  // bios
2404   AM_RANGE(0x00100000, 0x0010007f) AM_READWRITE(saturn_SMPC_r32, saturn_SMPC_w32)
2405   AM_RANGE(0x00180000, 0x0018ffff) AM_READWRITE(satram_r, satram_w)
2406   AM_RANGE(0x00200000, 0x002fffff) AM_RAM AM_MIRROR(0x100000) AM_SHARE("share2") AM_BASE(&stv_workram_l)
2407   AM_RANGE(0x01000000, 0x01000003) AM_WRITE(minit_w)
2408   AM_RANGE(0x01406f40, 0x01406f43) AM_WRITE(minit_w) // prikura seems to write here ..
2409   AM_RANGE(0x01800000, 0x01800003) AM_WRITE(sinit_w)
2410   AM_RANGE(0x02000000, 0x023fffff) AM_ROM AM_SHARE("share7") AM_REGION("maincpu", 0x80000)   // cartridge space
2411   AM_RANGE(0x05800000, 0x0589ffff) AM_READWRITE(stvcd_r, stvcd_w)
2412   /* Sound */
2413   AM_RANGE(0x05a00000, 0x05a7ffff) AM_READWRITE(stv_sh2_soundram_r, stv_sh2_soundram_w)
2414   AM_RANGE(0x05b00000, 0x05b00fff) AM_DEVREADWRITE16("scsp", scsp_r, scsp_w, 0xffffffff)
2415   /* VDP1 */
2416   /*0x05c00000-0x05c7ffff VRAM*/
2417   /*0x05c80000-0x05c9ffff Frame Buffer 0*/
2418   /*0x05ca0000-0x05cbffff Frame Buffer 1*/
2419   /*0x05d00000-0x05d7ffff VDP1 Regs */
2420   AM_RANGE(0x05c00000, 0x05c7ffff) AM_READWRITE(stv_vdp1_vram_r, stv_vdp1_vram_w)
2421   AM_RANGE(0x05c80000, 0x05cbffff) AM_READWRITE(stv_vdp1_framebuffer0_r, stv_vdp1_framebuffer0_w)
2422   AM_RANGE(0x05d00000, 0x05d0001f) AM_READWRITE(stv_vdp1_regs_r, stv_vdp1_regs_w)
2423   AM_RANGE(0x05e00000, 0x05efffff) AM_READWRITE(stv_vdp2_vram_r, stv_vdp2_vram_w)
2424   AM_RANGE(0x05f00000, 0x05f7ffff) AM_READWRITE(stv_vdp2_cram_r, stv_vdp2_cram_w)
2425   AM_RANGE(0x05f80000, 0x05fbffff) AM_READWRITE(stv_vdp2_regs_r, stv_vdp2_regs_w)
2426   AM_RANGE(0x05fe0000, 0x05fe00cf) AM_READWRITE(stv_scu_r32, stv_scu_w32)
2427   AM_RANGE(0x06000000, 0x060fffff) AM_RAM AM_MIRROR(0x01f00000) AM_SHARE("share3") AM_BASE(&stv_workram_h)
2428   AM_RANGE(0x20000000, 0x2007ffff) AM_ROM AM_SHARE("share6")  // bios mirror
2429   AM_RANGE(0x22000000, 0x24ffffff) AM_ROM AM_SHARE("share7")  // cart mirror
2430ADDRESS_MAP_END
2431
2432
2433static ADDRESS_MAP_START( stv_mem, AS_PROGRAM, 32 )
2434   AM_RANGE(0x00000000, 0x0007ffff) AM_ROM AM_SHARE("share6")  // bios
2435   AM_RANGE(0x00100000, 0x0010007f) AM_READWRITE(stv_SMPC_r32, stv_SMPC_w32)
2436   AM_RANGE(0x00180000, 0x0018ffff) AM_RAM AM_SHARE("share1") AM_BASE(&stv_backupram)
2437   AM_RANGE(0x00200000, 0x002fffff) AM_RAM AM_MIRROR(0x100000) AM_SHARE("share2") AM_BASE(&stv_workram_l)
2438   AM_RANGE(0x00400000, 0x0040001f) AM_READWRITE(stv_io_r32, stv_io_w32) AM_BASE(&ioga) AM_SHARE("share4") AM_MIRROR(0x20)
2439   AM_RANGE(0x01000000, 0x01000003) AM_WRITE(minit_w)
2440   AM_RANGE(0x01406f40, 0x01406f43) AM_WRITE(minit_w) // prikura seems to write here ..
2441//  AM_RANGE(0x01000000, 0x01000003) AM_WRITE(minit_w) AM_MIRROR(0x00080000)
2442   AM_RANGE(0x01800000, 0x01800003) AM_WRITE(sinit_w)
2443   AM_RANGE(0x02000000, 0x04ffffff) AM_ROM AM_SHARE("share7") AM_REGION("user1", 0) // cartridge
2444   AM_RANGE(0x05800000, 0x0589ffff) AM_READWRITE(stvcd_r, stvcd_w)
2445   /* Sound */
2446   AM_RANGE(0x05a00000, 0x05afffff) AM_READWRITE(stv_sh2_soundram_r, stv_sh2_soundram_w)
2447   //AM_RANGE(0x05a80000, 0x05afffff) AM_READ(stv_sh2_random_r)
2448   AM_RANGE(0x05b00000, 0x05b00fff) AM_DEVREADWRITE16("scsp", scsp_r, scsp_w, 0xffffffff)
2449   /* VDP1 */
2450   AM_RANGE(0x05c00000, 0x05c7ffff) AM_READWRITE(stv_vdp1_vram_r, stv_vdp1_vram_w)
2451   AM_RANGE(0x05c80000, 0x05cbffff) AM_READWRITE(stv_vdp1_framebuffer0_r, stv_vdp1_framebuffer0_w)
2452   AM_RANGE(0x05d00000, 0x05d0001f) AM_READWRITE(stv_vdp1_regs_r, stv_vdp1_regs_w)
2453   AM_RANGE(0x05e00000, 0x05efffff) AM_READWRITE(stv_vdp2_vram_r, stv_vdp2_vram_w)
2454   AM_RANGE(0x05f00000, 0x05f7ffff) AM_READWRITE(stv_vdp2_cram_r, stv_vdp2_cram_w)
2455   AM_RANGE(0x05f80000, 0x05fbffff) AM_READWRITE(stv_vdp2_regs_r, stv_vdp2_regs_w)
2456   AM_RANGE(0x05fe0000, 0x05fe00cf) AM_READWRITE(stv_scu_r32, stv_scu_w32)
2457   AM_RANGE(0x06000000, 0x060fffff) AM_RAM AM_MIRROR(0x01f00000) AM_SHARE("share3") AM_BASE(&stv_workram_h)
2458   AM_RANGE(0x20000000, 0x2007ffff) AM_ROM AM_SHARE("share6")  // bios mirror
2459   AM_RANGE(0x22000000, 0x24ffffff) AM_ROM AM_SHARE("share7")  // cart mirror
2460ADDRESS_MAP_END
2461
2462static ADDRESS_MAP_START( sound_mem, AS_PROGRAM, 16 )
2463   AM_RANGE(0x000000, 0x0fffff) AM_RAM AM_BASE(&sound_ram)
2464   AM_RANGE(0x100000, 0x100fff) AM_DEVREADWRITE("scsp", scsp_r, scsp_w)
2465ADDRESS_MAP_END
2466
2467
2468static INPUT_PORTS_START( saturn )
2469   PORT_START("PDR1")
2470   PORT_DIPNAME( 0x01, 0x01, "PDR1" )
2471   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
2472   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2473   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
2474   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
2475   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2476   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
2477   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
2478   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2479   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
2480   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
2481   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2482   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
2483   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
2484   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2485   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
2486   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
2487   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2488   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
2489   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
2490   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2491   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
2492   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
2493   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2494
2495   PORT_START("PDR2")
2496   PORT_DIPNAME( 0x01, 0x01, "PDR2" )
2497   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
2498   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2499   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
2500   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
2501   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2502   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
2503   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
2504   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2505   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
2506   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
2507   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2508   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
2509   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
2510   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2511   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
2512   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
2513   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2514   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
2515   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
2516   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2517   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
2518   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
2519   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2520
2521   PORT_START("JOY1")
2522   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1)
2523   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1)
2524   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1)
2525   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1)
2526   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_START ) PORT_PLAYER(1)   // START
2527   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P1 A") PORT_PLAYER(1)   // A
2528   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P1 B") PORT_PLAYER(1)   // B
2529   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("P1 C") PORT_PLAYER(1)   // C
2530   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("P1 X") PORT_PLAYER(1)   // X
2531   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("P1 Y") PORT_PLAYER(1)   // Y
2532   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("P1 Z") PORT_PLAYER(1)   // Z
2533   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_NAME("P1 L") PORT_PLAYER(1)   // L
2534   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("P1 R") PORT_PLAYER(1)   // R
2535
2536   PORT_START("JOY2")
2537   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
2538   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2)
2539   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2)
2540   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2)
2541   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_START ) PORT_PLAYER(2)   // START
2542   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P2 A") PORT_PLAYER(2)   // A
2543   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P2 B") PORT_PLAYER(2)   // B
2544   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("P2 C") PORT_PLAYER(2)   // C
2545   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("P2 X") PORT_PLAYER(2)   // X
2546   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("P2 Y") PORT_PLAYER(2)   // Y
2547   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("P2 Z") PORT_PLAYER(2)   // Z
2548   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_NAME("P2 L") PORT_PLAYER(2)   // L
2549   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("P2 R") PORT_PLAYER(2)   // R
2550INPUT_PORTS_END
2551
2552#define STV_PLAYER_INPUTS(_n_, _b1_, _b2_, _b3_)                     \
2553   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_##_b1_ ) PORT_PLAYER(_n_)         \
2554   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_##_b2_ ) PORT_PLAYER(_n_)         \
2555   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_##_b3_ ) PORT_PLAYER(_n_)         \
2556   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )                     \
2557   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(_n_)      \
2558   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(_n_)      \
2559   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(_n_)   \
2560   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(_n_)
2561
2562static INPUT_PORTS_START( stv )
2563   PORT_START("DSW1")
2564   PORT_DIPNAME( 0x01, 0x01, "PDR1" )
2565   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
2566   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2567   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
2568   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
2569   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2570   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
2571   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
2572   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2573   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
2574   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
2575   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2576   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
2577   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
2578   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2579   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
2580   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
2581   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2582   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
2583   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
2584   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2585   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
2586   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
2587   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2588
2589   PORT_START("DSW2")
2590   PORT_DIPNAME( 0x01, 0x01, "PDR2" )
2591   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
2592   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2593   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
2594   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
2595   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2596   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
2597   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
2598   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2599   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
2600   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
2601   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2602   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
2603   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
2604   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2605   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
2606   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
2607   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2608   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
2609   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
2610   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2611   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
2612   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
2613   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2614
2615   PORT_START("P1")
2616   STV_PLAYER_INPUTS(1, BUTTON1, BUTTON2, BUTTON3)
2617
2618   PORT_START("P2")
2619   STV_PLAYER_INPUTS(2, BUTTON1, BUTTON2, BUTTON3)
2620/*
2621    PORT_START("P3")
2622    STV_PLAYER_INPUTS(3, BUTTON1, BUTTON2, BUTTON3)
2623
2624    PORT_START("P4")
2625    STV_PLAYER_INPUTS(4, BUTTON1, BUTTON2, BUTTON3)
2626*/
2627
2628   PORT_START("SYSTEM")
2629   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
2630   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )
2631   PORT_SERVICE_NO_TOGGLE( 0x04, IP_ACTIVE_LOW )
2632   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_SERVICE1 )
2633   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_START1 )
2634   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START2 )
2635   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("1P Push Switch") PORT_CODE(KEYCODE_7)
2636   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("2P Push Switch") PORT_CODE(KEYCODE_8)
2637
2638   /* This *might* be unused... */
2639   PORT_START("UNUSED")
2640   PORT_BIT ( 0xff, IP_ACTIVE_LOW, IPT_UNUSED )
2641
2642   /* Extra button layout, used by Power Instinct 3, Suikoenbu, Elan Doree, Golden Axe Duel & Astra SuperStars */
2643   PORT_START("EXTRA")
2644   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1)
2645   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(1)
2646   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(1)
2647   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2648   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2)
2649   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(2)
2650   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(2)
2651   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
2652
2653   /* We don't need these, AFAIK the country code doesn't work either... */
2654   #if 0
2655   PORT_START("FAKE")   //7
2656   PORT_DIPNAME( 0x0f, 0x01, "Country" )
2657   PORT_DIPSETTING(    0x01, DEF_STR( Japan ) )
2658   PORT_DIPSETTING(    0x02, "Asia Ntsc" )
2659   PORT_DIPSETTING(    0x04, DEF_STR( USA ) )
2660   PORT_DIPSETTING(    0x08, "Sud America Ntsc" )
2661   PORT_DIPSETTING(    0x06, "Korea" )
2662   PORT_DIPSETTING(    0x0a, "Asia Pal" )
2663   PORT_DIPSETTING(    0x0c, "Europe/Other Pal" )
2664   PORT_DIPSETTING(    0x0d, "Sud America Pal" )
2665
2666   PORT_START("PAD1A")   /* Pad data 1a */
2667   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("B") PORT_CODE(KEYCODE_U)
2668   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("C") PORT_CODE(KEYCODE_Y)
2669   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("A") PORT_CODE(KEYCODE_T)
2670   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Start") PORT_CODE(KEYCODE_O)
2671   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Up") PORT_CODE(KEYCODE_I)
2672   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Down") PORT_CODE(KEYCODE_K)
2673   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Left") PORT_CODE(KEYCODE_J)
2674   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Right") PORT_CODE(KEYCODE_L)
2675
2676   PORT_START("PAD1B")   /* Pad data 1b */
2677   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("L trig") PORT_CODE(KEYCODE_A)
2678   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Z") PORT_CODE(KEYCODE_Q)
2679   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Y") PORT_CODE(KEYCODE_W)
2680   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("X") PORT_CODE(KEYCODE_E)
2681   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("R trig") PORT_CODE(KEYCODE_S)
2682   #endif
2683
2684   PORT_START("UNKNOWN")
2685   PORT_DIPNAME( 0x01, 0x01, "UNK" )
2686   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
2687   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2688   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
2689   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
2690   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2691   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
2692   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
2693   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2694   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
2695   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
2696   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2697   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
2698   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
2699   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2700   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
2701   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
2702   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2703   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
2704   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
2705   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2706   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
2707   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
2708   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
2709INPUT_PORTS_END
2710
2711static INPUT_PORTS_START( critcrsh )
2712   PORT_INCLUDE( stv )
2713
2714   /* IN 7 */
2715   PORT_START("LIGHTX") /* mask default type                     sens delta min max */
2716   PORT_BIT( 0x3f, 0x00, IPT_LIGHTGUN_X ) PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_MINMAX(0,0x3f) PORT_SENSITIVITY(50) PORT_KEYDELTA(1) PORT_PLAYER(1)
2717
2718   /* IN 8 */
2719   PORT_START("LIGHTY")
2720   PORT_BIT( 0x3f, 0x00, IPT_LIGHTGUN_Y ) PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_MINMAX(0x0,0x3f) PORT_SENSITIVITY(50) PORT_KEYDELTA(1) PORT_PLAYER(1)
2721INPUT_PORTS_END
2722
2723static INPUT_PORTS_START( batmanfr )
2724   PORT_INCLUDE( stv )
2725
2726   PORT_MODIFY("P1")
2727   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1)
2728
2729   PORT_MODIFY("P2")
2730   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2)
2731
2732   PORT_MODIFY("EXTRA")
2733   PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNUSED )
2734INPUT_PORTS_END
2735
2736/* Same as the regular one, but with an additional & optional mahjong panel */
2737static INPUT_PORTS_START( stvmp )
2738   PORT_INCLUDE( stv )
2739
2740   /* Mahjong panel/player 1 side */
2741   PORT_START("KEY0")   /*7*/
2742   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_MAHJONG_KAN )
2743   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START1 )
2744   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2745   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2746   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_MAHJONG_E )
2747   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_MAHJONG_A )
2748   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_M )
2749   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_MAHJONG_I )
2750
2751   PORT_START("KEY1")   /*8*/
2752   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_MAHJONG_RON )
2753   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
2754   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2755   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2756   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_MAHJONG_F )
2757   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_MAHJONG_B )
2758   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_N )
2759   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_MAHJONG_J )
2760
2761   PORT_START("KEY2")   /*9*/
2762   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_MAHJONG_REACH )
2763   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
2764   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2765   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2766   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_MAHJONG_G )
2767   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_MAHJONG_C )
2768   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_CHI )
2769   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_MAHJONG_K )
2770
2771   PORT_START("KEY3")   /*10*/
2772   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
2773   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
2774   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2775   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2776   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_MAHJONG_H )
2777   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_MAHJONG_D )
2778   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_PON )
2779   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_MAHJONG_L )
2780
2781   PORT_START("KEY4")   /*11*/
2782   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
2783   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
2784   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2785   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2786   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNUSED )
2787   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
2788   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_FLIP_FLOP )
2789   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
2790
2791   /* Mahjong panel/player 2 side */
2792   PORT_START("KEY5")   /*12*/
2793   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_MAHJONG_KAN ) PORT_PLAYER(2)
2794   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START2 )
2795   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2796   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2797   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_MAHJONG_E ) PORT_PLAYER(2)
2798   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_MAHJONG_A ) PORT_PLAYER(2)
2799   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_M ) PORT_PLAYER(2)
2800   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_MAHJONG_I ) PORT_PLAYER(2)
2801
2802   PORT_START("KEY6")   /*13*/
2803   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_MAHJONG_RON ) PORT_PLAYER(2)
2804   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
2805   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2806   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2807   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_MAHJONG_F ) PORT_PLAYER(2)
2808   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_MAHJONG_B ) PORT_PLAYER(2)
2809   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_N ) PORT_PLAYER(2)
2810   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_MAHJONG_J ) PORT_PLAYER(2)
2811
2812   PORT_START("KEY7")   /*14*/
2813   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_MAHJONG_REACH ) PORT_PLAYER(2)
2814   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
2815   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2816   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2817   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_MAHJONG_G ) PORT_PLAYER(2)
2818   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_MAHJONG_C ) PORT_PLAYER(2)
2819   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_CHI ) PORT_PLAYER(2)
2820   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_MAHJONG_K ) PORT_PLAYER(2)
2821
2822   PORT_START("KEY8")   /*15*/
2823   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
2824   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
2825   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2826   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2827   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_MAHJONG_H ) PORT_PLAYER(2)
2828   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_MAHJONG_D ) PORT_PLAYER(2)
2829   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_PON ) PORT_PLAYER(2)
2830   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_MAHJONG_L ) PORT_PLAYER(2)
2831
2832   PORT_START("KEY9")   /*16*/
2833   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
2834   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
2835   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2836   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2837   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNUSED )
2838   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
2839   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_MAHJONG_FLIP_FLOP ) PORT_PLAYER(2)
2840   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
2841INPUT_PORTS_END
2842
2843static WRITE32_HANDLER ( w60ffc44_write )
2844{
2845   COMBINE_DATA(&stv_workram_h[0xffc44/4]);
2846
2847   logerror("cpu %s (PC=%08X): 60ffc44_write write = %08X & %08X\n", space->device().tag(), cpu_get_pc(&space->device()), data, mem_mask);
2848   //sinit_w(offset,data,mem_mask);
2849}
2850
2851static WRITE32_HANDLER ( w60ffc48_write )
2852{
2853   COMBINE_DATA(&stv_workram_h[0xffc48/4]);
2854
2855   logerror("cpu %s (PC=%08X): 60ffc48_write write = %08X & %08X\n", space->device().tag(), cpu_get_pc(&space->device()), data, mem_mask);
2856   //minit_w(offset,data,mem_mask);
2857}
2858
2859#ifdef UNUSED_FUNCTION
2860static void print_game_info(void);
2861#endif
2862
2863DRIVER_INIT ( stv )
2864{
2865   system_time systime;
2866
2867   machine.base_datetime(systime);
2868
2869   /* amount of time to boost interleave for on MINIT / SINIT, needed for communication to work */
2870   minit_boost = 400;
2871   sinit_boost = 400;
2872   minit_boost_timeslice = attotime::zero;
2873   sinit_boost_timeslice = attotime::zero;
2874
2875   smpc_ram = auto_alloc_array(machine, UINT8, 0x80);
2876   stv_scu = auto_alloc_array(machine, UINT32, 0x100/4);
2877   scsp_regs = auto_alloc_array(machine, UINT16, 0x1000/2);
2878
2879   install_stvbios_speedups(machine);
2880
2881   // do strict overwrite verification - maruchan and rsgun crash after coinup without this.
2882   // cottonbm needs strict PCREL
2883   // todo: test what games need this and don't turn it on for them...
2884   sh2drc_set_options(machine.device("maincpu"), SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
2885   sh2drc_set_options(machine.device("slave"), SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
2886
2887   /* debug .. watch the command buffer rsgun, cottonbm etc. appear to use to communicate between cpus */
2888   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x60ffc44, 0x60ffc47, FUNC(w60ffc44_write) );
2889   machine.device("maincpu")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x60ffc48, 0x60ffc4b, FUNC(w60ffc48_write) );
2890   machine.device("slave")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x60ffc44, 0x60ffc47, FUNC(w60ffc44_write) );
2891   machine.device("slave")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x60ffc48, 0x60ffc4b, FUNC(w60ffc48_write) );
2892
2893    smpc_ram[0x31] = 0x00; //CTG1=0 CTG0=0 (correct??)
2894//  smpc_ram[0x33] = input_port_read(machine, "FAKE");
2895   smpc_ram[0x5f] = 0x10;
2896
2897   #ifdef MAME_DEBUG
2898   /*Uncomment this to enable header info*/
2899   //print_game_info();
2900   #endif
2901}
2902
2903#define DATA_TRANSFER(_max_) \
2904   for(dst_i=0;dst_i<_max_;dst_i++,src_i++)   \
2905      STR[(dst_i & 0xfc) | (~dst_i & 3)] = ROM[src_i];
2906
2907#define DATA_DELETE \
2908   for(dst_i=0;dst_i<0x100;dst_i++) \
2909      STR[dst_i] = 0x00;
2910
2911#ifdef UNUSED_FUNCTION
2912static void print_game_info(void)
2913{
2914   UINT8 *ROM = machine.region("user1")->base();
2915   static FILE *print_file = NULL;
2916   UINT8 STR[0x100];
2917   UINT32 src_i,dst_i;
2918
2919   if(print_file == NULL)
2920      print_file = fopen( "stvinfo.txt", "a" );
2921
2922   src_i = 0;
2923
2924   /*IC13?*/
2925   if(ROM[src_i] == 0x00)
2926      src_i+=0x200000;
2927
2928   DATA_TRANSFER(0x100);
2929   for(src_i=0;src_i<0x100;src_i++)
2930   {
2931      if((src_i % 0x10) == 0) fprintf( print_file, "\n");
2932      if(src_i < 0xc0)      fprintf( print_file, "%c",STR[src_i] );
2933      else                    fprintf( print_file, "%02x",STR[src_i] );
2934   }
2935   DATA_DELETE;
2936
2937   fclose(print_file);
2938   print_file = NULL;
2939}
2940#endif
2941
2942static const gfx_layout tiles8x8x4_layout =
2943{
2944   8,8,
2945   0x100000/(32*8/8),
2946   4,
2947   { 0, 1, 2, 3 },
2948   { 0, 4, 8, 12, 16, 20, 24, 28 },
2949   { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 },
2950   32*8
2951};
2952
2953static const gfx_layout tiles16x16x4_layout =
2954{
2955   16,16,
2956   0x100000/(32*32/8),
2957   4,
2958   { 0, 1, 2, 3 },
2959   { 0, 4, 8, 12, 16, 20, 24, 28,
2960     32*8+0, 32*8+4, 32*8+8, 32*8+12, 32*8+16, 32*8+20, 32*8+24, 32*8+28,
2961
2962     },
2963   { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32,
2964     32*16, 32*17,32*18, 32*19,32*20,32*21,32*22,32*23
2965
2966     },
2967   32*32
2968};
2969
2970static const gfx_layout tiles8x8x8_layout =
2971{
2972   8,8,
2973   0x100000/(32*8/8),
2974   8,
2975   { 0, 1, 2, 3, 4, 5, 6, 7 },
2976   { 0, 8, 16, 24, 32, 40, 48, 56 },
2977   { 0*64, 1*64, 2*64, 3*64, 4*64, 5*64, 6*64, 7*64 },
2978   32*8   /* really 64*8, but granularity is 32 bytes */
2979};
2980
2981static const gfx_layout tiles16x16x8_layout =
2982{
2983   16,16,
2984   0x100000/(64*16/8),
2985   8,
2986   { 0, 1, 2, 3, 4, 5, 6, 7 },
2987   { 0, 8, 16, 24, 32, 40, 48, 56,
2988   64*8+0, 65*8, 66*8, 67*8, 68*8, 69*8, 70*8, 71*8
2989
2990   },
2991   { 0*64, 1*64, 2*64, 3*64, 4*64, 5*64, 6*64, 7*64,
2992   64*16, 64*17, 64*18, 64*19, 64*20, 64*21, 64*22, 64*23
2993   },
2994   64*16   /* really 128*16, but granularity is 32 bytes */
2995};
2996
2997
2998
2999
3000static GFXDECODE_START( stv )
3001   GFXDECODE_ENTRY( NULL, 0, tiles8x8x4_layout,   0x00, (0x80*(2+1))  )
3002   GFXDECODE_ENTRY( NULL, 0, tiles16x16x4_layout, 0x00, (0x80*(2+1))  )
3003   GFXDECODE_ENTRY( NULL, 0, tiles8x8x8_layout,   0x00, (0x08*(2+1))  )
3004   GFXDECODE_ENTRY( NULL, 0, tiles16x16x8_layout, 0x00, (0x08*(2+1))  )
3005
3006   /* vdp1 .. pointless for drawing but can help us debug */
3007   GFXDECODE_ENTRY( NULL, 0, tiles8x8x4_layout,   0x00, 0x100  )
3008   GFXDECODE_ENTRY( NULL, 0, tiles16x16x4_layout, 0x00, 0x100  )
3009   GFXDECODE_ENTRY( NULL, 0, tiles8x8x8_layout,   0x00, 0x20  )
3010   GFXDECODE_ENTRY( NULL, 0, tiles16x16x8_layout, 0x00, 0x20  )
3011
3012GFXDECODE_END
3013
3014static const sh2_cpu_core sh2_conf_master = { 0, NULL };
3015static const sh2_cpu_core sh2_conf_slave  = { 1, NULL };
3016
3017static int scsp_last_line = 0;
3018
3019static void scsp_irq(device_t *device, int irq)
3020{
3021   // don't bother the 68k if it's off
3022   if (!en_68k)
3023   {
3024      return;
3025   }
3026
3027   if (irq > 0)
3028   {
3029      scsp_last_line = irq;
3030      cputag_set_input_line(device->machine(), "audiocpu", irq, ASSERT_LINE);
3031   }
3032   else if (irq < 0)
3033   {
3034      cputag_set_input_line(device->machine(), "audiocpu", -irq, CLEAR_LINE);
3035   }
3036   else
3037   {
3038      cputag_set_input_line(device->machine(), "audiocpu", scsp_last_line, CLEAR_LINE);
3039   }
3040}
3041
3042static const scsp_interface scsp_config =
3043{
3044   0,
3045   scsp_irq
3046};
3047
3048static TIMER_CALLBACK(stv_rtc_increment)
3049{
3050   static const UINT8 dpm[12] = { 0x31, 0x28, 0x31, 0x30, 0x31, 0x30, 0x31, 0x31, 0x30, 0x31, 0x30, 0x31 };
3051   static int year_num, year_count;
3052
3053   /*
3054        smpc_ram[0x23] = DectoBCD(systime.local_time.year /100);
3055        smpc_ram[0x25] = DectoBCD(systime.local_time.year %100);
3056        smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month+1);
3057        smpc_ram[0x29] = DectoBCD(systime.local_time.mday);
3058        smpc_ram[0x2b] = DectoBCD(systime.local_time.hour);
3059        smpc_ram[0x2d] = DectoBCD(systime.local_time.minute);
3060        smpc_ram[0x2f] = DectoBCD(systime.local_time.second);
3061    */
3062
3063   smpc_ram[0x2f]++;
3064
3065   /* seconds from 9 -> 10*/
3066   if((smpc_ram[0x2f] & 0x0f) >= 0x0a)          { smpc_ram[0x2f]+=0x10; smpc_ram[0x2f]&=0xf0; }
3067   /* seconds from 59 -> 0 */
3068   if((smpc_ram[0x2f] & 0xf0) >= 0x60)          { smpc_ram[0x2d]++;     smpc_ram[0x2f] = 0; }
3069   /* minutes from 9 -> 10 */
3070   if((smpc_ram[0x2d] & 0x0f) >= 0x0a)          { smpc_ram[0x2d]+=0x10; smpc_ram[0x2d]&=0xf0; }
3071   /* minutes from 59 -> 0 */
3072   if((smpc_ram[0x2d] & 0xf0) >= 0x60)          { smpc_ram[0x2b]++;     smpc_ram[0x2d] = 0; }
3073   /* hours from 9 -> 10 */
3074   if((smpc_ram[0x2b] & 0x0f) >= 0x0a)          { smpc_ram[0x2b]+=0x10; smpc_ram[0x2b]&=0xf0; }
3075   /* hours from 23 -> 0 */
3076   if((smpc_ram[0x2b] & 0xff) >= 0x24)            { smpc_ram[0x29]++; smpc_ram[0x27]+=0x10; smpc_ram[0x2b] = 0; }
3077   /* week day name sunday -> monday */
3078   if((smpc_ram[0x27] & 0xf0) >= 0x70)            { smpc_ram[0x27]&=0x0f; }
3079   /* day number 9 -> 10 */
3080   if((smpc_ram[0x29] & 0x0f) >= 0x0a)            { smpc_ram[0x29]+=0x10; smpc_ram[0x29]&=0xf0; }
3081
3082   // year BCD to dec conversion (for the leap year stuff)
3083   {
3084      year_num = (smpc_ram[0x25] & 0xf);
3085
3086      for(year_count = 0; year_count < (smpc_ram[0x25] & 0xf0); year_count += 0x10)
3087         year_num += 0xa;
3088
3089      year_num += (smpc_ram[0x23] & 0xf)*0x64;
3090
3091      for(year_count = 0; year_count < (smpc_ram[0x23] & 0xf0); year_count += 0x10)
3092         year_num += 0x3e8;
3093   }
3094
3095   /* month +1 check */
3096   /* the RTC have a range of 1980 - 2100, so we don't actually need to support the leap year special conditions */
3097   if(((year_num % 4) == 0) && (smpc_ram[0x27] & 0xf) == 2)
3098   {
3099      if((smpc_ram[0x29] & 0xff) >= dpm[(smpc_ram[0x27] & 0xf)-1]+1+1)
3100         { smpc_ram[0x27]++; smpc_ram[0x29] = 0x01; }
3101   }
3102   else if((smpc_ram[0x29] & 0xff) >= dpm[(smpc_ram[0x27] & 0xf)-1]+1){ smpc_ram[0x27]++; smpc_ram[0x29] = 0x01; }
3103   /* year +1 check */
3104   if((smpc_ram[0x27] & 0x0f) > 12)            { smpc_ram[0x25]++;  smpc_ram[0x27] = (smpc_ram[0x27] & 0xf0) | 0x01; }
3105   /* year from 9 -> 10 */
3106   if((smpc_ram[0x25] & 0x0f) >= 0x0a)            { smpc_ram[0x25]+=0x10; smpc_ram[0x25]&=0xf0; }
3107   /* year from 99 -> 100 */
3108   if((smpc_ram[0x25] & 0xf0) >= 0xa0)            { smpc_ram[0x23]++; smpc_ram[0x25] = 0; }
3109
3110   // probably not SO precise, here just for reference ...
3111   /* year from 999 -> 1000 */
3112   //if((smpc_ram[0x23] & 0x0f) >= 0x0a)               { smpc_ram[0x23]+=0x10; smpc_ram[0x23]&=0xf0; }
3113   /* year from 9999 -> 0 */
3114   //if((smpc_ram[0x23] & 0xf0) >= 0xa0)               { smpc_ram[0x23] = 0; } //roll over
3115}
3116
3117static MACHINE_START( stv )
3118{
3119   system_time systime;
3120   machine.base_datetime(systime);
3121
3122   stv_maincpu = machine.device<cpu_device>("maincpu");
3123   stv_slave = machine.device<cpu_device>("slave");
3124   stv_audiocpu = machine.device<cpu_device>("audiocpu");
3125
3126   scsp_set_ram_base(machine.device("scsp"), sound_ram);
3127
3128   // save states
3129   state_save_register_global_pointer(machine, smpc_ram, 0x80);
3130   state_save_register_global_pointer(machine, stv_scu, 0x100/4);
3131   state_save_register_global_pointer(machine, scsp_regs, 0x1000/2);
3132//  state_save_register_global(machine, stv_vblank);
3133//  state_save_register_global(machine, stv_hblank);
3134   state_save_register_global(machine, stv_enable_slave_sh2);
3135   state_save_register_global(machine, NMI_reset);
3136   state_save_register_global(machine, en_68k);
3137   state_save_register_global(machine, timer_0);
3138   state_save_register_global(machine, timer_1);
3139//  state_save_register_global(machine, scanline);
3140   state_save_register_global(machine, IOSEL1);
3141   state_save_register_global(machine, IOSEL2);
3142   state_save_register_global(machine, EXLE1);
3143   state_save_register_global(machine, EXLE2);
3144   state_save_register_global(machine, PDR1);
3145   state_save_register_global(machine, PDR2);
3146   state_save_register_global(machine, port_sel);
3147   state_save_register_global(machine, mux_data);
3148   state_save_register_global(machine, scsp_last_line);
3149
3150   stv_register_protection_savestates(machine); // machine/stvprot.c
3151
3152   machine.add_notifier(MACHINE_NOTIFY_EXIT, stvcd_exit);
3153
3154   smpc_ram[0x23] = DectoBCD(systime.local_time.year /100);
3155    smpc_ram[0x25] = DectoBCD(systime.local_time.year %100);
3156    smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month+1);
3157    smpc_ram[0x29] = DectoBCD(systime.local_time.mday);
3158    smpc_ram[0x2b] = DectoBCD(systime.local_time.hour);
3159    smpc_ram[0x2d] = DectoBCD(systime.local_time.minute);
3160    smpc_ram[0x2f] = DectoBCD(systime.local_time.second);
3161
3162   stv_rtc_timer = machine.scheduler().timer_alloc(FUNC(stv_rtc_increment));
3163}
3164
3165
3166static MACHINE_START( saturn )
3167{
3168   scsp_set_ram_base(machine.device("scsp"), sound_ram);
3169
3170   // save states
3171   state_save_register_global_pointer(machine, smpc_ram, 0x80);
3172   state_save_register_global_pointer(machine, stv_scu, 0x100/4);
3173   state_save_register_global_pointer(machine, scsp_regs, 0x1000/2);
3174   state_save_register_global(machine, stv_vblank);
3175   state_save_register_global(machine, stv_hblank);
3176   state_save_register_global(machine, stv_enable_slave_sh2);
3177   state_save_register_global(machine, NMI_reset);
3178   state_save_register_global(machine, en_68k);
3179   state_save_register_global(machine, timer_0);
3180   state_save_register_global(machine, timer_1);
3181   state_save_register_global(machine, IOSEL1);
3182   state_save_register_global(machine, IOSEL2);
3183   state_save_register_global(machine, EXLE1);
3184   state_save_register_global(machine, EXLE2);
3185   state_save_register_global(machine, PDR1);
3186   state_save_register_global(machine, PDR2);
3187//  state_save_register_global(machine, port_sel);
3188//  state_save_register_global(machine, mux_data);
3189   state_save_register_global(machine, scsp_last_line);
3190   state_save_register_global(machine, intback_stage);
3191   state_save_register_global(machine, pmode);
3192   state_save_register_global(machine, smpcSR);
3193   state_save_register_global_array(machine, SMEM);
3194
3195   machine.add_notifier(MACHINE_NOTIFY_EXIT, stvcd_exit);
3196}
3197
3198
3199/*
3200(Preliminary) explaination about this:
3201VBLANK-OUT is used at the start of the vblank period.It also sets the timer zero
3202variable to 0.
3203If the Timer Compare register is zero too,the Timer 0 irq is triggered.
3204
3205HBLANK-IN is used at the end of each scanline except when in VBLANK-IN/OUT periods.
3206
3207The timer 0 is also incremented by one at each HBLANK and checked with the value
3208of the Timer Compare register;if equal,the timer 0 irq is triggered here too.
3209Notice that the timer 0 compare register can be more than the VBLANK maximum range,in
3210this case the timer 0 irq is simply never triggered.This is a known Sega Saturn/ST-V "bug".
3211
3212VBLANK-IN is used at the end of the vblank period.
3213
3214SCU register[36] is the timer zero compare register.
3215SCU register[40] is for IRQ masking.
3216*/
3217
3218#ifdef UNUSED_FUNCTION
3219
3220/* theoretical function about how this irq system should work, not yet implemented because the performance speed hits very very badly.
3221   It's not tested much either, but I'm aware that timer 1 doesn't work with this for whatever reason ... */
3222static TIMER_CALLBACK( stv_irq_callback )
3223{
3224   int hpos = machine.primary_screen->hpos();
3225   int vpos = machine.primary_screen->vpos();
3226   rectangle visarea = *machine.primary_screen->visible_area();
3227
3228   h_sync = visarea.max_x+1;//horz
3229   v_sync = visarea.max_y+1;//vert
3230
3231   if(vpos == v_sync && hpos == 0)
3232      VBLANK_IN_IRQ;
3233   if(hpos == 0 && vpos == 0)
3234      VBLANK_OUT_IRQ(timer->machine());
3235   if(hpos == h_sync)
3236      TIMER_0_IRQ(timer->machine());
3237   if(hpos == h_sync && (vpos != 0 && vpos != v_sync))
3238   {
3239      HBLANK_IN_IRQ(timer->machine());
3240      timer_0++;
3241   }
3242
3243   /*TODO: timing of this one (related to the VDP1 speed)*/
3244   /*      (NOTE: value shouldn't be at h_sync/v_sync position (will break shienryu))*/
3245   if(hpos == 40 && vpos == 0)
3246      VDP1_IRQ;
3247
3248   if(hpos == timer_1)
3249      TIMER_1_IRQ(timer->machine());
3250
3251   if(hpos <= h_sync)
3252      scan_timer->adjust(machine.primary_screen->time_until_pos(vpos, hpos+1));
3253   else if(vpos <= v_sync)
3254      scan_timer->adjust(machine.primary_screen->time_until_pos(vpos+1));
3255   else
3256      scan_timer->adjust(machine.primary_screen->time_until_pos(0));
3257}
3258
3259#endif
3260
3261
3262static timer_device *vblank_out_timer,*scan_timer,*t1_timer;
3263static int h_sync,v_sync;
3264static int cur_scan;
3265
3266#define VBLANK_OUT_IRQ(m)   \
3267timer_0 = 0; \
3268{ \
3269   /*if(LOG_IRQ) logerror ("Interrupt: VBlank-OUT Vector 0x41 Level 0x0e\n");*/ \
3270   cputag_set_input_line_and_vector(m, "maincpu", 0xe, (stv_irq.vblank_out) ? HOLD_LINE : CLEAR_LINE , 0x41); \
3271} \
3272
3273#define VBLANK_IN_IRQ \
3274{ \
3275   /*if(LOG_IRQ) logerror ("Interrupt: VBlank IN Vector 0x40 Level 0x0f\n");*/ \
3276   cputag_set_input_line_and_vector(device->machine(), "maincpu", 0xf, (stv_irq.vblank_in) ? HOLD_LINE : CLEAR_LINE , 0x40); \
3277} \
3278
3279#define HBLANK_IN_IRQ(m) \
3280timer_1 = stv_scu[37] & 0x1ff; \
3281{ \
3282   /*if(LOG_IRQ) logerror ("Interrupt: HBlank-In at scanline %04x, Vector 0x42 Level 0x0d\n",scanline);*/ \
3283   cputag_set_input_line_and_vector(m, "maincpu", 0xd, (stv_irq.hblank_in) ? HOLD_LINE : CLEAR_LINE, 0x42); \
3284} \
3285
3286#define TIMER_0_IRQ(m) \
3287if(timer_0 == (stv_scu[36] & 0x3ff)) \
3288{ \
3289   /*if(LOG_IRQ) logerror ("Interrupt: Timer 0 at scanline %04x, Vector 0x43 Level 0x0c\n",scanline);*/ \
3290   cputag_set_input_line_and_vector(m, "maincpu", 0xc, (stv_irq.timer_0) ? HOLD_LINE : CLEAR_LINE, 0x43 ); \
3291} \
3292
3293#define TIMER_1_IRQ(m)   \
3294if((stv_scu[38] & 1)) \
3295{ \
3296   if(!(stv_scu[38] & 0x80)) \
3297   { \
3298      /*if(LOG_IRQ) logerror ("Interrupt: Timer 1 at point %04x, Vector 0x44 Level 0x0b\n",point);*/ \
3299      cputag_set_input_line_and_vector(m, "maincpu", 0xb, (stv_irq.timer_1) ? HOLD_LINE : CLEAR_LINE, 0x44 ); \
3300   } \
3301   else \
3302   { \
3303      if((timer_0) == (stv_scu[36] & 0x3ff)) \
3304      { \
3305         /*if(LOG_IRQ) logerror ("Interrupt: Timer 1 at point %04x, Vector 0x44 Level 0x0b\n",point);*/ \
3306         cputag_set_input_line_and_vector(m, "maincpu", 0xb, (stv_irq.timer_1) ? HOLD_LINE : CLEAR_LINE, 0x44 ); \
3307      } \
3308   } \
3309} \
3310
3311#define VDP1_IRQ \
3312{ \
3313   cputag_set_input_line_and_vector(machine, "maincpu", 2, (stv_irq.vdp1_end) ? HOLD_LINE : CLEAR_LINE, 0x4d); \
3314} \
3315
3316static TIMER_DEVICE_CALLBACK( hblank_in_irq )
3317{
3318   int scanline = param;
3319
3320//  h = timer.machine().primary_screen->height();
3321//  w = timer.machine().primary_screen->width();
3322
3323   HBLANK_IN_IRQ(timer.machine());
3324   TIMER_0_IRQ(timer.machine());
3325
3326   if(scanline+1 < v_sync)
3327   {
3328      if(stv_irq.hblank_in || stv_irq.timer_0)
3329         scan_timer->adjust(timer.machine().primary_screen->time_until_pos(scanline+1, h_sync), scanline+1);
3330      /*set the first Timer-1 event*/
3331      cur_scan = scanline+1;
3332      if(stv_irq.timer_1)
3333         t1_timer->adjust(timer.machine().primary_screen->time_until_pos(scanline+1, timer_1), scanline+1);
3334   }
3335
3336   timer_0++;
3337}
3338
3339static TIMER_DEVICE_CALLBACK( timer1_irq )
3340{
3341   int scanline = param;
3342
3343   TIMER_1_IRQ(timer.machine());
3344
3345   if(stv_irq.timer_1)
3346      t1_timer->adjust(timer.machine().primary_screen->time_until_pos(scanline+1, timer_1), scanline+1);
3347}
3348
3349static TIMER_CALLBACK( vdp1_irq )
3350{
3351   VDP1_IRQ;
3352}
3353
3354static TIMER_DEVICE_CALLBACK( vblank_out_irq )
3355{
3356   VBLANK_OUT_IRQ(timer.machine());
3357}
3358
3359/*V-Blank-IN event*/
3360static INTERRUPT_GEN( stv_interrupt )
3361{
3362//  scanline = 0;
3363   rectangle visarea = device->machine().primary_screen->visible_area();
3364
3365   h_sync = visarea.max_x+1;//horz
3366   v_sync = visarea.max_y+1;//vert
3367
3368   VBLANK_IN_IRQ;
3369
3370   /*Next V-Blank-OUT event*/
3371   if(stv_irq.vblank_out)
3372      vblank_out_timer->adjust(device->machine().primary_screen->time_until_pos(0));
3373   /*Set the first Hblank-IN event*/
3374   if(stv_irq.hblank_in || stv_irq.timer_0 || stv_irq.timer_1)
3375      scan_timer->adjust(device->machine().primary_screen->time_until_pos(0, h_sync));
3376
3377   /*TODO: timing of this one (related to the VDP1 speed)*/
3378   /*      (NOTE: value shouldn't be at h_sync/v_sync position (will break shienryu))*/
3379   device->machine().scheduler().timer_set(device->machine().primary_screen->time_until_pos(0), FUNC(vdp1_irq));
3380}
3381
3382
3383static MACHINE_RESET( saturn )
3384{
3385   // don't let the slave cpu and the 68k go anywhere
3386   cputag_set_input_line(machine, "slave", INPUT_LINE_RESET, ASSERT_LINE);
3387   stv_enable_slave_sh2 = 0;
3388   cputag_set_input_line(machine, "audiocpu", INPUT_LINE_RESET, ASSERT_LINE);
3389
3390   smpcSR = 0x40;   // this bit is always on according to docs
3391
3392   timer_0 = 0;
3393   timer_1 = 0;
3394   en_68k = 0;
3395   NMI_reset = 1;
3396   smpc_ram[0x21] = (0x80) | ((NMI_reset & 1) << 6);
3397
3398   DMA_STATUS = 0;
3399
3400   memset(stv_workram_l, 0, 0x100000);
3401   memset(stv_workram_h, 0, 0x100000);
3402
3403   machine.device("maincpu")->set_unscaled_clock(MASTER_CLOCK_320/2);
3404   machine.device("slave")->set_unscaled_clock(MASTER_CLOCK_320/2);
3405   machine.device("audiocpu")->set_unscaled_clock(MASTER_CLOCK_320/5);
3406
3407   stvcd_reset( machine );
3408
3409   /* set the first scanline 0 timer to go off */
3410   scan_timer = machine.device<timer_device>("scan_timer");
3411   t1_timer = machine.device<timer_device>("t1_timer");
3412   vblank_out_timer = machine.device<timer_device>("vbout_timer");
3413   vblank_out_timer->adjust(machine.primary_screen->time_until_pos(0));
3414   scan_timer->adjust(machine.primary_screen->time_until_pos(224, 352));
3415}
3416
3417
3418static MACHINE_RESET( stv )
3419{
3420   // don't let the slave cpu and the 68k go anywhere
3421   cputag_set_input_line(machine, "slave", INPUT_LINE_RESET, ASSERT_LINE);
3422   stv_enable_slave_sh2 = 0;
3423   cputag_set_input_line(machine, "audiocpu", INPUT_LINE_RESET, ASSERT_LINE);
3424
3425   timer_0 = 0;
3426   timer_1 = 0;
3427   en_68k = 0;
3428   NMI_reset = 1;
3429   smpc_ram[0x21] = (0x80) | ((NMI_reset & 1) << 6);
3430
3431   port_sel = mux_data = 0;
3432   port_i = -1;
3433
3434   machine.device("maincpu")->set_unscaled_clock(MASTER_CLOCK_320/2);
3435   machine.device("slave")->set_unscaled_clock(MASTER_CLOCK_320/2);
3436   machine.device("audiocpu")->set_unscaled_clock(MASTER_CLOCK_320/5);
3437
3438   stvcd_reset(machine);
3439
3440   /* set the first scanline 0 timer to go off */
3441   scan_timer = machine.device<timer_device>("scan_timer");
3442   t1_timer = machine.device<timer_device>("t1_timer");
3443   vblank_out_timer = machine.device<timer_device>("vbout_timer");
3444   vblank_out_timer->adjust(machine.primary_screen->time_until_pos(0));
3445   scan_timer->adjust(machine.primary_screen->time_until_pos(224, 352));
3446
3447   stv_rtc_timer->adjust(attotime::zero, 0, attotime::from_seconds(1));
3448}
3449
3450
3451
3452static MACHINE_CONFIG_START( saturn, driver_device )
3453
3454   /* basic machine hardware */
3455   MCFG_CPU_ADD("maincpu", SH2, MASTER_CLOCK_352/2) // 28.6364 MHz
3456   MCFG_CPU_PROGRAM_MAP(saturn_mem)
3457   MCFG_CPU_VBLANK_INT("screen",stv_interrupt)
3458   MCFG_CPU_CONFIG(sh2_conf_master)
3459
3460   MCFG_CPU_ADD("slave", SH2, MASTER_CLOCK_352/2) // 28.6364 MHz
3461   MCFG_CPU_PROGRAM_MAP(saturn_mem)
3462   MCFG_CPU_CONFIG(sh2_conf_slave)
3463
3464   MCFG_CPU_ADD("audiocpu", M68000, MASTER_CLOCK_352/5) //11.46 MHz
3465   MCFG_CPU_PROGRAM_MAP(sound_mem)
3466
3467   MCFG_MACHINE_START(saturn)
3468   MCFG_MACHINE_RESET(saturn)
3469
3470   MCFG_NVRAM_HANDLER(saturn)
3471
3472   MCFG_TIMER_ADD("scan_timer", hblank_in_irq)
3473   MCFG_TIMER_ADD("t1_timer", timer1_irq)
3474   MCFG_TIMER_ADD("vbout_timer", vblank_out_irq)
3475   MCFG_TIMER_ADD("sector_timer", stv_sector_cb)
3476
3477   /* video hardware */
3478   MCFG_SCREEN_ADD("screen", RASTER)
3479   MCFG_SCREEN_REFRESH_RATE(60)
3480   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(192))   // guess, needed to force video update after V-Blank OUT interrupt
3481   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB15)
3482   MCFG_SCREEN_SIZE(704*2, 512*2)
3483   MCFG_SCREEN_VISIBLE_AREA(0*8, 703, 0*8, 511) // we need to use a resolution as high as the max size it can change to
3484   MCFG_SCREEN_UPDATE(stv_vdp2)
3485
3486   MCFG_PALETTE_LENGTH(2048+(2048*2))//standard palette + extra memory for rgb brightness.
3487   MCFG_GFXDECODE(stv)
3488
3489   MCFG_VIDEO_START(stv_vdp2)
3490
3491   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
3492
3493   MCFG_SOUND_ADD("scsp", SCSP, 0)
3494   MCFG_SOUND_CONFIG(scsp_config)
3495   MCFG_SOUND_ROUTE(0, "lspeaker", 1.0)
3496   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
3497
3498   MCFG_CDROM_ADD( "cdrom" )
3499   MCFG_CARTSLOT_ADD("cart")
3500MACHINE_CONFIG_END
3501
3502
3503static MACHINE_CONFIG_START( stv, driver_device )
3504
3505   /* basic machine hardware */
3506   MCFG_CPU_ADD("maincpu", SH2, MASTER_CLOCK_352/2) // 28.6364 MHz
3507   MCFG_CPU_PROGRAM_MAP(stv_mem)
3508   MCFG_CPU_VBLANK_INT("screen",stv_interrupt)
3509   MCFG_CPU_CONFIG(sh2_conf_master)
3510
3511   MCFG_CPU_ADD("slave", SH2, MASTER_CLOCK_352/2) // 28.6364 MHz
3512   MCFG_CPU_PROGRAM_MAP(stv_mem)
3513   MCFG_CPU_CONFIG(sh2_conf_slave)
3514
3515   MCFG_CPU_ADD("audiocpu", M68000, MASTER_CLOCK_352/5) //11.46 MHz
3516   MCFG_CPU_PROGRAM_MAP(sound_mem)
3517
3518   MCFG_MACHINE_START(stv)
3519   MCFG_MACHINE_RESET(stv)
3520
3521   MCFG_EEPROM_93C46_ADD("eeprom") /* Actually 93c45 */
3522
3523   MCFG_TIMER_ADD("scan_timer", hblank_in_irq)
3524   MCFG_TIMER_ADD("t1_timer", timer1_irq)
3525   MCFG_TIMER_ADD("vbout_timer", vblank_out_irq)
3526   MCFG_TIMER_ADD("sector_timer", stv_sector_cb)
3527
3528   /* video hardware */
3529   MCFG_VIDEO_ATTRIBUTES(VIDEO_UPDATE_AFTER_VBLANK)
3530
3531   MCFG_SCREEN_ADD("screen", RASTER)
3532   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB15)
3533   MCFG_SCREEN_RAW_PARAMS(PIXEL_CLOCK, 400, 0, 320, 262, 0, 224)
3534   MCFG_SCREEN_UPDATE(stv_vdp2)
3535
3536   MCFG_PALETTE_LENGTH(2048+(2048*2))//standard palette + extra memory for rgb brightness.
3537   MCFG_GFXDECODE(stv)
3538
3539   MCFG_VIDEO_START(stv_vdp2)
3540
3541   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
3542
3543   MCFG_SOUND_ADD("scsp", SCSP, 0)
3544   MCFG_SOUND_CONFIG(scsp_config)
3545   MCFG_SOUND_ROUTE(0, "lspeaker", 1.0)
3546   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
3547MACHINE_CONFIG_END
3548
3549
3550
3551static void saturn_init_driver(running_machine &machine, int rgn)
3552{
3553   system_time systime;
3554
3555   saturn_region = rgn;
3556
3557   // set compatible options
3558   sh2drc_set_options(machine.device("maincpu"), SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
3559   sh2drc_set_options(machine.device("slave"), SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
3560
3561   /* get the current date/time from the core */
3562   machine.current_datetime(systime);
3563
3564   /* amount of time to boost interleave for on MINIT / SINIT, needed for communication to work */
3565   minit_boost = 400;
3566   sinit_boost = 400;
3567   minit_boost_timeslice = attotime::zero;
3568   sinit_boost_timeslice = attotime::zero;
3569
3570   smpc_ram = auto_alloc_array(machine, UINT8, 0x80);
3571   stv_scu = auto_alloc_array(machine, UINT32, 0x100/4);
3572   scsp_regs = auto_alloc_array(machine, UINT16, 0x1000/2);
3573
3574   smpc_ram[0x23] = dec_2_bcd(systime.local_time.year / 100);
3575   smpc_ram[0x25] = dec_2_bcd(systime.local_time.year % 100);
3576   smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month + 1);
3577   smpc_ram[0x29] = dec_2_bcd(systime.local_time.mday);
3578   smpc_ram[0x2b] = dec_2_bcd(systime.local_time.hour);
3579   smpc_ram[0x2d] = dec_2_bcd(systime.local_time.minute);
3580   smpc_ram[0x2f] = dec_2_bcd(systime.local_time.second);
3581   smpc_ram[0x31] = 0x00; //CTG1=0 CTG0=0 (correct??)
3582//  smpc_ram[0x33] = input_port_read(machine, "???");
3583   smpc_ram[0x5f] = 0x10;
3584}
3585
3586static DRIVER_INIT( saturnus )
3587{
3588   saturn_init_driver(machine, 4);
3589}
3590
3591static DRIVER_INIT( saturneu )
3592{
3593   saturn_init_driver(machine, 12);
3594}
3595
3596static DRIVER_INIT( saturnjp )
3597{
3598   saturn_init_driver(machine, 1);
3599}
3600
3601
3602/* Japanese Saturn */
3603ROM_START(saturnjp)
3604   ROM_REGION( 0x480000, "maincpu", ROMREGION_ERASEFF ) /* SH2 code */
3605   ROM_SYSTEM_BIOS(0, "101", "Japan v1.01 (941228)")
3606   ROMX_LOAD("sega_101.bin", 0x00000000, 0x00080000, CRC(224b752c) SHA1(df94c5b4d47eb3cc404d88b33a8fda237eaf4720), ROM_BIOS(1))
3607   ROM_SYSTEM_BIOS(1, "1003", "Japan v1.003 (941012)")
3608   ROMX_LOAD("sega1003.bin", 0x00000000, 0x00080000, CRC(b3c63c25) SHA1(7b23b53d62de0f29a23e423d0fe751dfb469c2fa), ROM_BIOS(2))
3609   ROM_SYSTEM_BIOS(2, "100", "Japan v1.00 (940921)")
3610   ROMX_LOAD("sega_100.bin", 0x00000000, 0x00080000, CRC(2aba43c2) SHA1(2b8cb4f87580683eb4d760e4ed210813d667f0a2), ROM_BIOS(3))
3611   ROM_CART_LOAD("cart", 0x080000, 0x400000, ROM_NOMIRROR | ROM_OPTIONAL)
3612   ROM_REGION( 0x080000, "slave", 0 ) /* SH2 code */
3613   ROM_COPY( "maincpu",0,0,0x080000)
3614ROM_END
3615
3616/* Overseas Saturn */
3617ROM_START(saturn)
3618   ROM_REGION( 0x480000, "maincpu", ROMREGION_ERASEFF ) /* SH2 code */
3619   ROM_SYSTEM_BIOS(0, "101a", "Overseas v1.01a (941115)")
3620   ROMX_LOAD("sega_101a.bin", 0x00000000, 0x00080000, CRC(4afcf0fa) SHA1(faa8ea183a6d7bbe5d4e03bb1332519800d3fbc3), ROM_BIOS(1))
3621   ROM_SYSTEM_BIOS(1, "100a", "Overseas v1.00a (941115)")
3622   ROMX_LOAD("sega_100a.bin", 0x00000000, 0x00080000, CRC(f90f0089) SHA1(3bb41feb82838ab9a35601ac666de5aacfd17a58), ROM_BIOS(2))
3623   ROM_CART_LOAD("cart", 0x080000, 0x400000, ROM_NOMIRROR | ROM_OPTIONAL)
3624   ROM_REGION( 0x080000, "slave", 0 ) /* SH2 code */
3625   ROM_COPY( "maincpu",0,0,0x080000)
3626ROM_END
3627
3628ROM_START(saturneu)
3629   ROM_REGION( 0x480000, "maincpu", ROMREGION_ERASEFF ) /* SH2 code */
3630   ROM_SYSTEM_BIOS(0, "101a", "Overseas v1.01a (941115)")
3631   ROMX_LOAD("sega_101a.bin", 0x00000000, 0x00080000, CRC(4afcf0fa) SHA1(faa8ea183a6d7bbe5d4e03bb1332519800d3fbc3), ROM_BIOS(1))
3632   ROM_SYSTEM_BIOS(1, "100a", "Overseas v1.00a (941115)")
3633   ROMX_LOAD("sega_100a.bin", 0x00000000, 0x00080000, CRC(f90f0089) SHA1(3bb41feb82838ab9a35601ac666de5aacfd17a58), ROM_BIOS(2))
3634   ROM_CART_LOAD("cart", 0x080000, 0x400000, ROM_NOMIRROR | ROM_OPTIONAL)
3635   ROM_REGION( 0x080000, "slave", 0 ) /* SH2 code */
3636   ROM_COPY( "maincpu",0,0,0x080000)
3637ROM_END
3638
3639ROM_START(vsaturn)
3640   ROM_REGION( 0x480000, "maincpu", ROMREGION_ERASEFF ) /* SH2 code */
3641   ROM_LOAD("vsaturn.bin", 0x00000000, 0x00080000, CRC(e4d61811) SHA1(4154e11959f3d5639b11d7902b3a393a99fb5776))
3642   ROM_CART_LOAD("cart", 0x080000, 0x400000, ROM_NOMIRROR | ROM_OPTIONAL)
3643   ROM_REGION( 0x080000, "slave", 0 ) /* SH2 code */
3644   ROM_COPY( "maincpu",0,0,0x080000)
3645ROM_END
3646
3647ROM_START(hisaturn)
3648   ROM_REGION( 0x480000, "maincpu", ROMREGION_ERASEFF ) /* SH2 code */
3649   ROM_LOAD("hisaturn.bin", 0x00000000, 0x00080000, CRC(721e1b60) SHA1(49d8493008fa715ca0c94d99817a5439d6f2c796))
3650   ROM_CART_LOAD("cart", 0x080000, 0x400000, ROM_NOMIRROR | ROM_OPTIONAL)
3651   ROM_REGION( 0x080000, "slave", 0 ) /* SH2 code */
3652   ROM_COPY( "maincpu",0,0,0x080000)
3653ROM_END
3654
3655#define ROM_LOAD16_WORD_SWAP_BIOS(bios,name,offset,length,hash) \
3656      ROMX_LOAD(name, offset, length, hash, ROM_GROUPWORD | ROM_REVERSE | ROM_BIOS(bios+1)) /* Note '+1' */
3657
3658/* BIOS rev info found at 0x800 (byte swapped):
3659
3660erp-17740  - Japan   STVB1.10J0950131  95/01/31 v1.10  - Found on a early board dated 02/1995
3661epr-17951a - Japan   STVB1.13J0950425  95/04/25 v1.13
3662epr-17952a - USA     STVB1.13U0950425  95/04/25 v1.13
3663epr-17953a - Taiwan  STVB1.13T0950425  95/04/25 v1.13
3664epr-17954a - Europe  STVB1.13E0950425  95/04/25 v1.13
3665
3666epr-18343  - ?????   STVB1.30S0950727  95/07/27 v1.30 - Special version used on Sports Fishing 2 (CD based)
3667epr-19730  - Japan   PCD11.13J0970217  97/02/17 v1.13 - Enhanced version for CD based units?
3668epr-20091  - Japan   PCS11.13J0970821  97/08/21 v1.13 - Enhanced version for ???
3669
3670stv110.bin  - Debug  STVB1.10D0950113  95/01/13 v1.10
3671stv1061.bin - ST-V Dev Bios (1.061) - Sega 1994, Noted "ST-V Ver 1.061 94/11/25" on EPROM sticker, Coming from a S-TV SG5001A dev board
3672
3673Regions found listed in the BIOS:
3674    Japan
3675    Taiwan and Philipines
3676    USA and Canada
3677    Brazil
3678    Korea
3679    Asia PAL area
3680    Europe
3681    Latin America
3682
3683ROM_SYSTEM_BIOS( x, "saturn",      "Saturn bios" ) \
3684ROM_LOAD16_WORD_SWAP_BIOS( x, "saturn.bin", 0x000000, 0x080000, CRC(653ff2d8) SHA1(20994ae7ee177ddaf3a430b010c7620dca000fb4) ) - Saturn Eu Bios
3685
3686*/
3687
3688#define STV_BIOS \
3689   ROM_REGION( 0x080000, "maincpu", 0 ) /* SH2 code */ \
3690   ROM_SYSTEM_BIOS( 0,  "jp",    "EPR-20091 (Japan 97/08/21)" ) \
3691   ROM_LOAD16_WORD_SWAP_BIOS( 0,  "epr-20091.ic8",   0x000000, 0x080000, CRC(59ed40f4) SHA1(eff0f54c70bce05ff3a289bf30b1027e1c8cd117) ) \
3692   ROM_SYSTEM_BIOS( 1,  "jp1",   "EPR-19730 (Japan 97/02/17)" ) \
3693   ROM_LOAD16_WORD_SWAP_BIOS( 1,  "epr-19730.ic8",   0x000000, 0x080000, CRC(d0e0889d) SHA1(fae53107c894e0c41c49e191dbe706c9cd6e50bd) ) \
3694   ROM_SYSTEM_BIOS( 2,  "jp2",   "EPR-17951A (Japan 95/04/25)" ) \
3695   ROM_LOAD16_WORD_SWAP_BIOS( 2,  "epr-17951a.ic8",  0x000000, 0x080000, CRC(2672f9d8) SHA1(63cf4a6432f6c87952f9cf3ab0f977aed2367303) ) \
3696   ROM_SYSTEM_BIOS( 3,  "jp3",   "STVB1.11J (Japan 95/02/20)" ) \
3697   ROM_LOAD16_WORD_SWAP_BIOS( 3,  "stvb111j.ic8",    0x000000, 0x080000, CRC(3e23c81f) SHA1(f9b282fd27693e9891843597b2e1823da3d23c7b) ) \
3698   ROM_SYSTEM_BIOS( 4,  "jp4",   "EPR-17740 (Japan 95/01/31)" ) \
3699   ROM_LOAD16_WORD_SWAP_BIOS( 4,  "epr-17740.ic8",   0x000000, 0x080000, CRC(5c5aa63d) SHA1(06860d96923b81afbc21e0ad32ee19487d8ff6e7) ) \
3700   ROM_SYSTEM_BIOS( 5,  "euro",  "EPR-17954A (Europe 95/04/25)" ) \
3701   ROM_LOAD16_WORD_SWAP_BIOS( 5,  "epr-17954a.ic8",  0x000000, 0x080000, CRC(f7722da3) SHA1(af79cff317e5b57d49e463af16a9f616ed1eee08) ) \
3702   ROM_SYSTEM_BIOS( 6,  "us",    "EPR-17952A (USA 95/04/25)" ) \
3703   ROM_LOAD16_WORD_SWAP_BIOS( 6,  "epr-17952a.ic8",  0x000000, 0x080000, CRC(d1be2adf) SHA1(eaf1c3e5d602e1139d2090a78d7e19f04f916794) ) \
3704   ROM_SYSTEM_BIOS( 7,  "tw",    "EPR-17953A (Taiwan 95/04/25)" ) \
3705   ROM_LOAD16_WORD_SWAP_BIOS( 7,  "epr-17953a.ic8",  0x000000, 0x080000, CRC(a4c47570) SHA1(9efc73717ec8a13417e65c54344ded9fc25bf5ef) ) \
3706   ROM_SYSTEM_BIOS( 8,  "tw1",   "STVB1.11T (Taiwan 95/02/20)" ) \
3707   ROM_LOAD16_WORD_SWAP_BIOS( 8,  "stvb111t.ic8",    0x000000, 0x080000, CRC(02daf123) SHA1(23185beb1ce9c09b8719e57d1adb7b28c8141fd5) ) \
3708   ROM_SYSTEM_BIOS( 9,  "debug", "Debug (95/01/13)" ) \
3709   ROM_LOAD16_WORD_SWAP_BIOS( 9,  "stv110.bin",      0x000000, 0x080000, CRC(3dfeda92) SHA1(8eb33192a57df5f3a1dfb57263054867c6b2db6d) ) \
3710   ROM_SYSTEM_BIOS( 10, "dev",   "Development (bios 1.061)" ) \
3711   ROM_LOAD16_WORD_SWAP_BIOS( 10, "stv1061.bin",     0x000000, 0x080000, CRC(728dbca3) SHA1(0ed2030177f0aa8285645c395ae9ad9f568ab1d6) ) \
3712   \
3713   ROM_REGION( 0x080000, "slave", 0 ) /* SH2 code */ \
3714   ROM_COPY( "maincpu",0,0,0x080000) \
3715
3716ROM_START( stvbios )
3717   STV_BIOS
3718   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3719ROM_END
3720
3721/*
3722
3723there appears to only be one main cartridge layout, just some having different positions populated if you use the ic named in
3724the test mode you have the following
3725
3726some of the rom names were using something else and have been renamed to match test mode, old extension left in comments
3727
3728( add 0x2000000 for real memory map location )
3729
37300x0000000 - 0x01fffff IC13 Header can be read from here .. IC13 roms are loaded on ODD bytes only
37310x0200000 - 0x03fffff IC7  Header can also be read from here.  If No IC7 is present it seems to mirror IC13, but loaded normally (mausuke)
37320x0400000 - 0x07fffff IC2
37330x0800000 - 0x0bfffff IC3
37340x0c00000 - 0x0ffffff IC4
37350x1000000 - 0x13fffff IC5
37360x1400000 - 0x17fffff IC6
37370x1800000 - 0x1bfffff IC1
37380x1c00000 - 0x1ffffff IC8
37390x2000000 - 0x23fffff IC9
37400x2400000 - 0x27fffff IC10
37410x2800000 - 0x2bfffff IC11
37420x2c00000 - 0x2ffffff IC12
3743
3744Update:Issue fixed,see stvhacks.c for more details (TODO: Clean-up that)
3745*/
3746
3747
3748
3749
3750ROM_START( astrass )
3751   STV_BIOS
3752
3753   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3754
3755   ROM_LOAD16_BYTE( "epr20825.13",                0x0000001, 0x0100000, CRC(94a9ad8f) SHA1(861311c14cfa9f560752aa5b023c147a539cf135) )
3756
3757   ROM_LOAD16_WORD_SWAP( "mpr20827.2",     0x0400000, 0x0400000, CRC(65cabbb3) SHA1(5e7cb090101dc42207a4084465e419f4311b6baf) ) // good (was .12)
3758   ROM_LOAD16_WORD_SWAP( "mpr20828.3",     0x0800000, 0x0400000, CRC(3934d44a) SHA1(969406b8bfac43b30f4d732702ca8cffeeefffb9) ) // good (was .13)
3759   ROM_LOAD16_WORD_SWAP( "mpr20829.4",     0x0c00000, 0x0400000, CRC(814308c3) SHA1(45c3f551690224c95acd156ae8f8397667927a04) ) // good (was .14)
3760   ROM_LOAD16_WORD_SWAP( "mpr20830.5",     0x1000000, 0x0400000, CRC(ff97fd19) SHA1(f37bcdce5f3f522527a44d59f1b8184ef290f829) ) // good (was .15)
3761   ROM_LOAD16_WORD_SWAP( "mpr20831.6",     0x1400000, 0x0400000, CRC(4408e6fb) SHA1(d4228cad8a1128e9426dac9ac62e9513a7a0117b) ) // good (was .16)
3762   ROM_LOAD16_WORD_SWAP( "mpr20826.1",     0x1800000, 0x0400000, CRC(bdc4b941) SHA1(c5e8b1b186324c2ccab617915f7bdbfe6897ca9f) ) // good (was .17)
3763   ROM_LOAD16_WORD_SWAP( "mpr20832.8",     0x1c00000, 0x0400000, CRC(af1b0985) SHA1(d7a0e4e0a8b0556915f924bdde8c3d14e5b3423e) ) // good (was .18s)
3764   ROM_LOAD16_WORD_SWAP( "mpr20833.9",     0x2000000, 0x0400000, CRC(cb6af231) SHA1(4a2e5d7c2fd6179c19cdefa84a03f9a34fbb9e70) ) // good (was .19s)
3765
3766   ROM_REGION32_BE( 0x11ea0, "user2", 0 )
3767   // protection data (text layer tiles) extracted from Saturn version
3768   // stat_t.bin is name of the file from Saturn version CD
3769   ROM_LOAD( "stat_t.bin", 0x0000000, 0x11ea0,  BAD_DUMP CRC(52a0b542) SHA1(2b352dee919d7e7a5d338ece1691577d0b288eca) )
3770ROM_END
3771
3772ROM_START( bakubaku )
3773   STV_BIOS
3774
3775   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3776
3777   ROM_LOAD16_BYTE( "fpr17969.13",               0x0000001, 0x0100000, CRC(bee327e5) SHA1(1d226db72d6ef68fd294f60659df7f882b25def6) )
3778
3779   ROM_LOAD16_WORD_SWAP( "mpr17970.2",    0x0400000, 0x0400000, CRC(bc4d6f91) SHA1(dcc241dcabea59325decfba3fd5e113c07958422) ) // good
3780   ROM_LOAD16_WORD_SWAP( "mpr17971.3",    0x0800000, 0x0400000, CRC(c780a3b3) SHA1(99587eea528a6413cacc3e4d3d1dbfff57b03dca) ) // good
3781   ROM_LOAD16_WORD_SWAP( "mpr17972.4",    0x0c00000, 0x0400000, CRC(8f29815a) SHA1(e86acd8096f2aee5f5e3ddfd3abb4f5c2b11df66) ) // good
3782   ROM_LOAD16_WORD_SWAP( "mpr17973.5",    0x1000000, 0x0400000, CRC(5f6e0e8b) SHA1(eeb5efb5216ab8b8fdee4656774bbd5a2a5b2d42) ) // good
3783ROM_END
3784
3785ROM_START( colmns97 )
3786   STV_BIOS
3787
3788   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3789
3790   ROM_LOAD16_BYTE( "fpr19553.13",    0x000001, 0x100000, CRC(d4fb6a5e) SHA1(bd3cfb4f451b6c9612e42af5ddcbffa14f057329) )
3791
3792   ROM_LOAD16_WORD_SWAP( "mpr19554.2",     0x400000, 0x400000, CRC(5a3ebcac) SHA1(46e3d1cf515a7ff8a8f97e5050b29dbbeb5060c0) ) // good
3793   ROM_LOAD16_WORD_SWAP( "mpr19555.3",     0x800000, 0x400000, CRC(74f6e6b8) SHA1(8080860550eb770e04447e344fb337748a249761) ) // good
3794ROM_END
3795
3796ROM_START( cotton2 )
3797   STV_BIOS
3798
3799   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3800   ROM_LOAD16_WORD_SWAP( "mpr20122.7",    0x0200000, 0x0200000, CRC(d616f78a) SHA1(8039dcdfdafb8327a19a1da46a67c0b3f7eee53a) ) // good
3801   ROM_LOAD16_WORD_SWAP( "mpr20117.2",    0x0400000, 0x0400000, CRC(893656ea) SHA1(11e3160083ba018fbd588f07061a4e55c1efbebb) ) // good
3802   ROM_LOAD16_WORD_SWAP( "mpr20118.3",    0x0800000, 0x0400000, CRC(1b6a1d4c) SHA1(6b234d6b2d24df7f6d400a56698c0af2f78ce0e7) ) // good
3803   ROM_LOAD16_WORD_SWAP( "mpr20119.4",    0x0c00000, 0x0400000, CRC(5a76e72b) SHA1(0a058627ddf78a0bcdaba328a58712419f24e33b) ) // good
3804   ROM_LOAD16_WORD_SWAP( "mpr20120.5",    0x1000000, 0x0400000, CRC(7113dd7b) SHA1(f86add67c4e1349a9b9ebcd0145a30b1667df811) ) // good
3805   ROM_LOAD16_WORD_SWAP( "mpr20121.6",    0x1400000, 0x0400000, CRC(8c8fd521) SHA1(c715681330b5ed37a8506ac58ee2143baa721206) ) // good
3806   ROM_LOAD16_WORD_SWAP( "mpr20116.1",    0x1800000, 0x0400000, CRC(d30b0175) SHA1(2da5c3c02d68b8324948a8cdc93946d97fccdd8f) ) // good
3807   ROM_LOAD16_WORD_SWAP( "mpr20123.8",    0x1c00000, 0x0400000, CRC(35f1b89f) SHA1(1d6007c380f817def734fc3030d4fe56df4a15be) ) // good
3808ROM_END
3809
3810ROM_START( cottonbm )
3811   STV_BIOS
3812
3813   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3814   ROM_LOAD16_WORD_SWAP( "mpr21075.7",    0x0200000, 0x0200000, CRC(200b58ba) SHA1(6daad6d70a3a41172e8d9402af775c03e191232d) ) // good
3815   ROM_LOAD16_WORD_SWAP( "mpr21070.2",    0x0400000, 0x0400000, CRC(56c0bf1d) SHA1(c2b564ce536c637bb723ed96683b27596e87ebe7) ) // good
3816   ROM_LOAD16_WORD_SWAP( "mpr21071.3",    0x0800000, 0x0400000, CRC(2bb18df2) SHA1(e900adb94ad3f48be00a4ce33e915147dc6a8737) ) // good
3817   ROM_LOAD16_WORD_SWAP( "mpr21072.4",    0x0c00000, 0x0400000, CRC(7c7cb977) SHA1(376dfb8014050605b00b6545520bd544768f5828) ) // good
3818   ROM_LOAD16_WORD_SWAP( "mpr21073.5",    0x1000000, 0x0400000, CRC(f2e5a5b7) SHA1(9258d508ef6f6529efc4ad172fd29e69877a99eb) ) // good
3819   ROM_LOAD16_WORD_SWAP( "mpr21074.6",    0x1400000, 0x0400000, CRC(6a7e7a7b) SHA1(a0b1e7a85e623b59886b28797281df1d65b8a5aa) ) // good
3820   ROM_LOAD16_WORD_SWAP( "mpr21069.1",    0x1800000, 0x0400000, CRC(6a28e3c5) SHA1(60454b71db49b872e0cb89fae2259fed601588bd) ) // good
3821ROM_END
3822
3823ROM_START( decathlt )
3824   STV_BIOS
3825
3826   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3827
3828   ROM_LOAD16_BYTE( "epr18967a.13",               0x0000001, 0x0100000, CRC(ac59c186) SHA1(7d4924d1e4c1b9257b58a690de988b3f6486e86f) )
3829
3830   ROM_LOAD16_WORD_SWAP( "mpr18968.2",    0x0400000, 0x0400000, CRC(11a891de) SHA1(1a4fa8d7e07e1d8fdc8122ef8a5b93723c007cda) ) // good (was .1)
3831   ROM_LOAD16_WORD_SWAP( "mpr18969.3",    0x0800000, 0x0400000, CRC(199cc47d) SHA1(d78f7c6be7e9b43e208244c5c8722245f4c653e1) ) // good (was .2)
3832   ROM_LOAD16_WORD_SWAP( "mpr18970.4",    0x0c00000, 0x0400000, CRC(8b7a509e) SHA1(8f4d36a858231764ed09b26a1141d1f055eee092) ) // good (was .3)
3833   ROM_LOAD16_WORD_SWAP( "mpr18971.5",    0x1000000, 0x0400000, CRC(c87c443b) SHA1(f2fedb35c80e5c4855c7aebff88186397f4d51bc) ) // good (was .4)
3834   ROM_LOAD16_WORD_SWAP( "mpr18972.6",    0x1400000, 0x0400000, CRC(45c64fca) SHA1(ae2f678b9885426ce99b615b7f62a451f9ef83f9) ) // good (was .5)
3835ROM_END
3836
3837ROM_START( decathlto )
3838   STV_BIOS
3839
3840   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3841
3842   ROM_LOAD16_BYTE( "epr18967.13",               0x0000001, 0x0100000, CRC(c0446674) SHA1(4917089d95613c9d2a936ed9fe3ebd22f461aa4f) )
3843
3844   ROM_LOAD16_WORD_SWAP( "mpr18968.2",    0x0400000, 0x0400000, CRC(11a891de) SHA1(1a4fa8d7e07e1d8fdc8122ef8a5b93723c007cda) ) // good (was .1)
3845   ROM_LOAD16_WORD_SWAP( "mpr18969.3",    0x0800000, 0x0400000, CRC(199cc47d) SHA1(d78f7c6be7e9b43e208244c5c8722245f4c653e1) ) // good (was .2)
3846   ROM_LOAD16_WORD_SWAP( "mpr18970.4",    0x0c00000, 0x0400000, CRC(8b7a509e) SHA1(8f4d36a858231764ed09b26a1141d1f055eee092) ) // good (was .3)
3847   ROM_LOAD16_WORD_SWAP( "mpr18971.5",    0x1000000, 0x0400000, CRC(c87c443b) SHA1(f2fedb35c80e5c4855c7aebff88186397f4d51bc) ) // good (was .4)
3848   ROM_LOAD16_WORD_SWAP( "mpr18972.6",    0x1400000, 0x0400000, CRC(45c64fca) SHA1(ae2f678b9885426ce99b615b7f62a451f9ef83f9) ) // good (was .5)
3849ROM_END
3850
3851ROM_START( diehard ) /* must use USA, Europe or Taiwan BIOS */
3852   STV_BIOS
3853   ROM_DEFAULT_BIOS( "us" )
3854
3855   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3856
3857   ROM_LOAD16_BYTE( "fpr19119.13",               0x0000001, 0x0100000, CRC(de5c4f7c) SHA1(35f670a15e9c86edbe2fe718470f5a75b5b096ac) )
3858
3859   ROM_LOAD16_WORD_SWAP( "mpr19115.2",    0x0400000, 0x0400000, CRC(6fe06a30) SHA1(dedb90f800bae8fd9df1023eb5bec7fb6c9d0179) ) // good
3860   ROM_LOAD16_WORD_SWAP( "mpr19116.3",    0x0800000, 0x0400000, CRC(af9e627b) SHA1(a53921c3185a93ec95299bf1c29e744e2fa3b8c0) ) // good
3861   ROM_LOAD16_WORD_SWAP( "mpr19117.4",    0x0c00000, 0x0400000, CRC(74520ff1) SHA1(16c1acf878664b3bd866c9b94f3695ae892ac12f) ) // good
3862   ROM_LOAD16_WORD_SWAP( "mpr19118.5",    0x1000000, 0x0400000, CRC(2c9702f0) SHA1(5c2c66de83f2ccbe97d3b1e8c7e65999e1fa2de1) ) // good
3863ROM_END
3864
3865ROM_START( dnmtdeka )
3866   STV_BIOS
3867
3868   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3869
3870   ROM_LOAD16_BYTE( "fpr19114.13",               0x0000001, 0x0100000, CRC(1fd22a5f) SHA1(c3d9653b12354a73a3e15f23a2ab7992ffb83e46) )
3871
3872   ROM_LOAD16_WORD_SWAP( "mpr19115.2",    0x0400000, 0x0400000, CRC(6fe06a30) SHA1(dedb90f800bae8fd9df1023eb5bec7fb6c9d0179) ) // good
3873   ROM_LOAD16_WORD_SWAP( "mpr19116.3",    0x0800000, 0x0400000, CRC(af9e627b) SHA1(a53921c3185a93ec95299bf1c29e744e2fa3b8c0) ) // good
3874   ROM_LOAD16_WORD_SWAP( "mpr19117.4",    0x0c00000, 0x0400000, CRC(74520ff1) SHA1(16c1acf878664b3bd866c9b94f3695ae892ac12f) ) // good
3875   ROM_LOAD16_WORD_SWAP( "mpr19118.5",    0x1000000, 0x0400000, CRC(2c9702f0) SHA1(5c2c66de83f2ccbe97d3b1e8c7e65999e1fa2de1) ) // good
3876ROM_END
3877
3878ROM_START( ejihon )
3879   STV_BIOS
3880
3881   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3882   ROM_LOAD16_BYTE( "epr18137.13",               0x0000001, 0x0080000, CRC(151aa9bc) SHA1(0959c60f31634816825acb57413838dcddb17d31) )
3883   ROM_RELOAD( 0x100001, 0x0080000 )
3884
3885   ROM_LOAD16_WORD_SWAP( "mpr18138.2",    0x0400000, 0x0400000, CRC(f5567049) SHA1(6eb35e4b5fbda39cf7e8c42b6a568bd53a364d6d) ) // good
3886   ROM_LOAD16_WORD_SWAP( "mpr18139.3",    0x0800000, 0x0400000, CRC(f36b4878) SHA1(e3f63c0046bd37b7ab02fb3865b8ebcf4cf68e75) ) // good
3887   ROM_LOAD16_WORD_SWAP( "mpr18140.4",    0x0c00000, 0x0400000, CRC(228850a0) SHA1(d83f7fa7df08407fa45a13661393679b88800805) ) // good
3888   ROM_LOAD16_WORD_SWAP( "mpr18141.5",    0x1000000, 0x0400000, CRC(b51eef36) SHA1(2745cba48dc410d6d31327b956886ec284b9eac3) ) // good
3889   ROM_LOAD16_WORD_SWAP( "mpr18142.6",    0x1400000, 0x0400000, CRC(cf259541) SHA1(51e2c8d16506d6074f6511112ec4b6b44bed4886) ) // good
3890ROM_END
3891
3892ROM_START( elandore )
3893   STV_BIOS
3894
3895   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3896   ROM_LOAD16_WORD_SWAP( "mpr21307.7",    0x0200000, 0x0200000, CRC(966ad472) SHA1(d6db41d1c40d08eb6bce8a8a2f491e7533daf670) ) // good (was .11s)
3897   ROM_LOAD16_WORD_SWAP( "mpr21301.2",    0x0400000, 0x0400000, CRC(1a23b0a0) SHA1(f9dbc7ba96dadfb00e5827622b557080449acd83) ) // good (was .12)
3898   ROM_LOAD16_WORD_SWAP( "mpr21302.3",    0x0800000, 0x0400000, CRC(1c91ca33) SHA1(ae11209088e3bf8fc4a92dca850d7303ce949b29) ) // good (was .13)
3899   ROM_LOAD16_WORD_SWAP( "mpr21303.4",    0x0c00000, 0x0400000, CRC(07b2350e) SHA1(f32f63fd8bec4e667f61da203d63be9a27798dfe) ) // good (was .14)
3900   ROM_LOAD16_WORD_SWAP( "mpr21304.5",    0x1000000, 0x0400000, CRC(cfea52ae) SHA1(4b6d27e0b2a95300ee9e07ebcdc4953d77c4efbe) ) // good (was .15)
3901   ROM_LOAD16_WORD_SWAP( "mpr21305.6",    0x1400000, 0x0400000, CRC(46cfc2a2) SHA1(8ca26bf8fa5ced040e815c125c13dd06d599e189) ) // good (was .16)
3902   ROM_LOAD16_WORD_SWAP( "mpr21306.1",    0x1800000, 0x0400000, CRC(87a5929c) SHA1(b259341d7b0e1fa98959bf52d23db5c308a8efdd) ) // good (was .17)
3903   ROM_LOAD16_WORD_SWAP( "mpr21308.8",    0x1c00000, 0x0400000, CRC(336ec1a4) SHA1(20d1fce050cf6132d284b91853a4dd5626372ef0) ) // good (was .18s)
3904ROM_END
3905
3906ROM_START( ffreveng )
3907   STV_BIOS
3908
3909   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3910   ROM_LOAD16_WORD_SWAP( "opr21872.7",   0x0200000, 0x0200000, CRC(32d36fee) SHA1(441c4254ef2e9301e1006d69462a850ce339314b) ) // good (was .11s)
3911   ROM_LOAD16_WORD_SWAP( "mpr21873.2",   0x0400000, 0x0400000, CRC(dac5bd98) SHA1(6102035ce9eb2f83d7d9b20f989a151f45087c67) ) // good (was .12)
3912   ROM_LOAD16_WORD_SWAP( "mpr21874.3",   0x0800000, 0x0400000, CRC(0a7be2f1) SHA1(e2d13f36e54d1e2cb9d584db829c04a6ff65108c) ) // good (was .13)
3913   ROM_LOAD16_WORD_SWAP( "mpr21875.4",   0x0c00000, 0x0400000, CRC(ccb75029) SHA1(9611a08a2ad0e0e82137ded6205440a948a339a4) ) // good (was .14)
3914   ROM_LOAD16_WORD_SWAP( "mpr21876.5",   0x1000000, 0x0400000, CRC(bb92a7fc) SHA1(d9e0fab1104a46adeb0a0cfc0d070d4c63a28d55) ) // good (was .15)
3915   ROM_LOAD16_WORD_SWAP( "mpr21877.6",   0x1400000, 0x0400000, CRC(c22a4a75) SHA1(3276bc0628e71b432f21ba9a4f5ff7ccc8769cd9) ) // good (was .16)
3916   ROM_LOAD16_WORD_SWAP( "opr21878.1",   0x1800000, 0x0200000, CRC(2ea4a64d) SHA1(928a973dce5eba0a1628d61ba56a530de990a946) ) // good (was .17)
3917ROM_END
3918
3919/* set system to 1 player to test rom */
3920ROM_START( fhboxers )
3921   STV_BIOS
3922
3923   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3924   ROM_LOAD16_BYTE( "fr18541a.13",               0x0000001, 0x0100000, CRC(8c61a17c) SHA1(a8aef27b53482923a506f7daa4b7a38653b4d8a4) ) //(header is read from here, not ic7 even if both are populated on this board)
3925
3926   ROM_LOAD16_WORD_SWAP( "mpr18538.7",    0x0200000, 0x0200000, CRC(7b5230c5) SHA1(70cebc3281580b43adf42c37318e12159c28a13d) ) // good
3927   ROM_LOAD16_WORD_SWAP( "mpr18533.2",    0x0400000, 0x0400000, CRC(7181fe51) SHA1(646f95e1a5b64d721e961352cee6fd5adfd031ec) ) // good
3928   ROM_LOAD16_WORD_SWAP( "mpr18534.3",    0x0800000, 0x0400000, CRC(c87ef125) SHA1(c9ced130faf6dd9e626074b6519615654d8beb19) ) // good
3929   ROM_LOAD16_WORD_SWAP( "mpr18535.4",    0x0c00000, 0x0400000, CRC(929a64cf) SHA1(206dfc2a46befbcea974df1e27515c5759d88d00) ) // good
3930   ROM_LOAD16_WORD_SWAP( "mpr18536.5",    0x1000000, 0x0400000, CRC(51b9f64e) SHA1(bfbdfb73d24f26ce1cc5294c23a1712fb9631691) ) // good
3931   ROM_LOAD16_WORD_SWAP( "mpr18537.6",    0x1400000, 0x0400000, CRC(c364f6a7) SHA1(4db21bcf6ea3e75f9eb34f067b56a417589271c0) ) // good
3932   ROM_LOAD16_WORD_SWAP( "mpr18532.1",    0x1800000, 0x0400000, CRC(39528643) SHA1(e35f4c35c9eb13e1cdcc26cb2599bb846f2c1af7) ) // good
3933   ROM_LOAD16_WORD_SWAP( "mpr18539.8",    0x1c00000, 0x0400000, CRC(62b3908c) SHA1(3f00e49beb0e5575cc4250a25c41f04dc91d6ed0) ) // good
3934   ROM_LOAD16_WORD_SWAP( "mpr18540.9",    0x2000000, 0x0400000, CRC(4c2b59a4) SHA1(4d15503fcff0e9e0d1ed3bac724278102b506da0) ) // good
3935
3936   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
3937   ROM_LOAD( "fhboxers.nv", 0x0000, 0x0080, CRC(590fd6da) SHA1(1abe71c62c51a246d854f02cd4cb79fd0d427e88) )
3938ROM_END
3939
3940/* set system to 1 player to test rom */
3941ROM_START( findlove )
3942   STV_BIOS
3943
3944   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3945   ROM_LOAD16_BYTE( "epr20424.13",               0x0000001, 0x0100000, CRC(4e61fa46) SHA1(e34624d98cbdf2dd04d997167d3c4decd2f208f7) ) //(header is read from here, not ic7 even if both are populated on this board)
3946
3947   ROM_LOAD16_WORD_SWAP( "mpr20431.7",    0x0200000, 0x0200000, CRC(ea656ced) SHA1(b2d6286081bd46a89d1284a2757b87d0bca1bbde) ) // good
3948   ROM_LOAD16_WORD_SWAP( "mpr20426.2",    0x0400000, 0x0400000, CRC(897d1747) SHA1(f3fb2c4ef8bc2c1658907e822f2ee2b88582afdd) ) // good
3949   ROM_LOAD16_WORD_SWAP( "mpr20427.3",    0x0800000, 0x0400000, CRC(a488a694) SHA1(80ec81f32e4b5712a607208b2a45cfdf6d5e1849) ) // good
3950   ROM_LOAD16_WORD_SWAP( "mpr20428.4",    0x0c00000, 0x0400000, CRC(4353b3b6) SHA1(f5e56396b345ff65f57a23f391b77d401f1f58b5) ) // good
3951   ROM_LOAD16_WORD_SWAP( "mpr20429.5",    0x1000000, 0x0400000, CRC(4f566486) SHA1(5b449288e33f02f2362ebbd515c87ea11cc02633) ) // good
3952   ROM_LOAD16_WORD_SWAP( "mpr20430.6",    0x1400000, 0x0400000, CRC(d1e11979) SHA1(14405997eefac22c42f0c86dca9411ba1dee9bf9) ) // good
3953   ROM_LOAD16_WORD_SWAP( "mpr20425.1",    0x1800000, 0x0400000, CRC(67f104c4) SHA1(8e965d2ce554ba8d37254f6bf3931dff4bce1a43) ) // good
3954   ROM_LOAD16_WORD_SWAP( "mpr20432.8",    0x1c00000, 0x0400000, CRC(79fcdecd) SHA1(df8e7733a51e24196914fc66a024515ee1565599) ) // good
3955   ROM_LOAD16_WORD_SWAP( "mpr20433.9",    0x2000000, 0x0400000, CRC(82289f29) SHA1(fb6a1015621b1afa3913da162ae71ded6b674649) ) // good
3956   ROM_LOAD16_WORD_SWAP( "mpr20434.10",   0x2400000, 0x0400000, CRC(85c94afc) SHA1(dfc2f16614bc499747ea87567a21c86e7bddce45) ) // good
3957   ROM_LOAD16_WORD_SWAP( "mpr20435.11",   0x2800000, 0x0400000, CRC(263a2e48) SHA1(27ef4bf577d240e36dcb6e6a09b9c5f24e59ce8c) ) // good
3958   ROM_LOAD16_WORD_SWAP( "mpr20436.12",   0x2c00000, 0x0400000, CRC(e3823f49) SHA1(754d48635bd1d4fb01ff665bfe2a71593d92f688) ) // good
3959
3960   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
3961   ROM_LOAD( "findlove.nv", 0x0000, 0x0080, CRC(df2fa9f6) SHA1(f05450e1648eafd2ffb52e50769f07bdc75ffb95) )
3962ROM_END
3963
3964ROM_START( finlarch )
3965   STV_BIOS
3966
3967   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3968   ROM_LOAD16_BYTE( "finlarch.13",               0x0000001, 0x0100000, CRC(4505fa9e) SHA1(96c6399146cf9c8f1d27a8fb6a265f937258004a) )
3969   ROM_RELOAD ( 0x0100001, 0x0080000 )
3970
3971   ROM_LOAD16_WORD_SWAP( "mpr18257.2",    0x0400000, 0x0400000, CRC(137fdf55) SHA1(07a02fe531b3707e063498f5bc9749bd1b4cadb3) ) // good
3972   ROM_RELOAD(                            0x1400000, 0x0400000 )
3973   ROM_LOAD16_WORD_SWAP( "mpr18258.3",    0x0800000, 0x0400000, CRC(f519c505) SHA1(5cad39314e46b98c24a71f1c2c10c682ef3bdcf3) ) // good
3974   ROM_RELOAD(                            0x1800000, 0x0400000 )
3975   ROM_LOAD16_WORD_SWAP( "mpr18259.4",    0x0c00000, 0x0400000, CRC(5cabc775) SHA1(84383a4cbe3b1a9dcc6c140cff165425666dc780) ) // good
3976   ROM_RELOAD(                            0x1c00000, 0x0400000 )
3977   ROM_LOAD16_WORD_SWAP( "mpr18260.5",    0x1000000, 0x0400000, CRC(f5b92082) SHA1(806ad85a187a23a5cf867f2f3dea7d8150065b8e) ) // good
3978   ROM_RELOAD(                            0x2000000, 0x0400000 )
3979ROM_END
3980
3981
3982ROM_START( gaxeduel )
3983   STV_BIOS
3984
3985   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
3986   ROM_LOAD16_BYTE( "epr17766.13",               0x0000001, 0x0080000, CRC(a83fcd62) SHA1(4ce77ebaa0e93c6553ad8f7fb87cbdc32433402b) )
3987   ROM_RELOAD( 0x0100001, 0x0080000 )
3988
3989   ROM_LOAD16_WORD_SWAP( "mpr17768.2",    0x0400000, 0x0400000, CRC(d6808a7d) SHA1(83a97bbe1160cb45b3bdcbde8adc0d9bae5ded60) ) // good
3990   ROM_LOAD16_WORD_SWAP( "mpr17769.3",    0x0800000, 0x0400000, CRC(3471dd35) SHA1(24febddfe70984cebc0e6948ad718e0e6957fa82) ) // good
3991   ROM_LOAD16_WORD_SWAP( "mpr17770.4",    0x0c00000, 0x0400000, CRC(06978a00) SHA1(a8d1333a9f4322e28b23724937f595805315b136) ) // good
3992   ROM_LOAD16_WORD_SWAP( "mpr17771.5",    0x1000000, 0x0400000, CRC(aea2ea3b) SHA1(2fbe3e10d3f5a3b3099a7ed5b38b93b6e22e19b8) ) // good
3993   ROM_LOAD16_WORD_SWAP( "mpr17772.6",    0x1400000, 0x0400000, CRC(b3dc0e75) SHA1(fbe2790c84466d186ea3e9d41edfcb7afaf54bea) ) // good
3994   ROM_LOAD16_WORD_SWAP( "mpr17767.1",    0x1800000, 0x0400000, CRC(9ba1e7b1) SHA1(f297c3697d2e8ba4476d672267163f91f371b362) ) // good
3995ROM_END
3996
3997ROM_START( grdforce )
3998   STV_BIOS
3999
4000   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4001   ROM_LOAD16_WORD_SWAP( "mpr20844.7",    0x0200000, 0x0200000, CRC(283e7587) SHA1(477fabc27cfe149ad17757e31f10665dcf8c0860) ) // good
4002   ROM_LOAD16_WORD_SWAP( "mpr20839.2",    0x0400000, 0x0400000, CRC(facd4dd8) SHA1(2582894c98b31ab719f1865d4623dad6736dc877) ) // good
4003   ROM_LOAD16_WORD_SWAP( "mpr20840.3",    0x0800000, 0x0400000, CRC(fe0158e6) SHA1(73460effe69fb8f16dd952271542b7803471a599) ) // good
4004   ROM_LOAD16_WORD_SWAP( "mpr20841.4",    0x0c00000, 0x0400000, CRC(d87ac873) SHA1(35b8fa3862e09dca530e9597f983f5a22919cf08) ) // good
4005   ROM_LOAD16_WORD_SWAP( "mpr20842.5",    0x1000000, 0x0400000, CRC(baebc506) SHA1(f5f59f9263956d0c49c729729cf6db31dc861d3b) ) // good
4006   ROM_LOAD16_WORD_SWAP( "mpr20843.6",    0x1400000, 0x0400000, CRC(263e49cc) SHA1(67979861ca2784b3ce39d87e7994e6e7351b40e5) ) // good
4007ROM_END
4008
4009ROM_START( groovef )
4010   STV_BIOS
4011
4012   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4013   ROM_LOAD16_WORD_SWAP( "mpr19820.7",    0x0200000, 0x0100000, CRC(e93c4513) SHA1(f9636529224880c49bd2cc5572bd5bf41dbf911a) ) // good
4014   ROM_LOAD16_WORD_SWAP( "mpr19815.2",    0x0400000, 0x0400000, CRC(1b9b14e6) SHA1(b1828c520cb108e2927a23273ebd2939dca52304) ) // good
4015   ROM_LOAD16_WORD_SWAP( "mpr19816.3",    0x0800000, 0x0400000, CRC(83f5731c) SHA1(2f645737f945c59a1a2fabf3b21a761be9e8c8a6) ) // good
4016   ROM_LOAD16_WORD_SWAP( "mpr19817.4",    0x0c00000, 0x0400000, CRC(525bd6c7) SHA1(2db2501177fb0b44d0fad2054eddf356c4ea08f2) ) // good
4017   ROM_LOAD16_WORD_SWAP( "mpr19818.5",    0x1000000, 0x0400000, CRC(66723ba8) SHA1(0a8379e46a8f8cab11befeadd9abdf59dba68e27) ) // good
4018   ROM_LOAD16_WORD_SWAP( "mpr19819.6",    0x1400000, 0x0400000, CRC(ee8c55f4) SHA1(f6d86b2c2ab43ec5baefb8ccc25e11af4d82712d) ) // good
4019   ROM_LOAD16_WORD_SWAP( "mpr19814.1",    0x1800000, 0x0400000, CRC(8f20e9f7) SHA1(30ff5ad0427208e7265cb996e870c4dc0fbbf7d2) ) // good
4020   ROM_LOAD16_WORD_SWAP( "mpr19821.8",    0x1c00000, 0x0400000, CRC(f69a76e6) SHA1(b7e41f34d8b787bf1b4d587e5d8bddb241c043a8) ) // good
4021   ROM_LOAD16_WORD_SWAP( "mpr19822.9",    0x2000000, 0x0200000, CRC(5e8c4b5f) SHA1(1d146fbe3d0bfa68993135ba94ef18081ab65d31) ) // good
4022ROM_END
4023
4024ROM_START( hanagumi )
4025   STV_BIOS
4026
4027   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4028   ROM_LOAD16_WORD_SWAP( "mpr20143.7",    0x0200000, 0x0100000, CRC(7bfc38d0) SHA1(66f223e7ff2b5456a6f4185b7ab36f9cd833351a) ) // good
4029   ROM_LOAD16_WORD_SWAP( "mpr20138.2",    0x0400000, 0x0400000, CRC(fdcf1046) SHA1(cbb1f03879833c17feffdd6f5a4fbff06e1059a2) ) // good
4030   ROM_LOAD16_WORD_SWAP( "mpr20139.3",    0x0800000, 0x0400000, CRC(7f0140e5) SHA1(f2f7de7620d66a596d552e1af491a0592ebc4e51) ) // good
4031   ROM_LOAD16_WORD_SWAP( "mpr20140.4",    0x0c00000, 0x0400000, CRC(2fa03852) SHA1(798ce008f6fc24a00f85298188c8d0d01933640d) ) // good
4032   ROM_LOAD16_WORD_SWAP( "mpr20141.5",    0x1000000, 0x0400000, CRC(45d6d21b) SHA1(fe0f0b2195b74e79b8efb6a7c0b7bedca7194c48) ) // good
4033   ROM_LOAD16_WORD_SWAP( "mpr20142.6",    0x1400000, 0x0400000, CRC(e38561ec) SHA1(c04c400be033bc74a7bb2a60f6ae00853a2220d4) ) // good
4034   ROM_LOAD16_WORD_SWAP( "mpr20137.1",    0x1800000, 0x0400000, CRC(181d2688) SHA1(950059f89eda30d8a5bce145421f507e226b8b3e) ) // good
4035   ROM_LOAD16_WORD_SWAP( "mpr20144.8",    0x1c00000, 0x0400000, CRC(235b43f6) SHA1(e35d9bf15ac805513ab3edeca4f264647a2dc0b0) ) // good
4036   ROM_LOAD16_WORD_SWAP( "mpr20145.9",    0x2000000, 0x0400000, CRC(aeaac7a1) SHA1(5c75ecce49a5c53dbb0b07e75f3a76e6db9976d0) ) // good
4037   ROM_LOAD16_WORD_SWAP( "mpr20146.10",   0x2400000, 0x0400000, CRC(39bab9a2) SHA1(077132e6a03afd181ee9ca9ca4f7c9cbf418e57e) ) // good
4038   ROM_LOAD16_WORD_SWAP( "mpr20147.11",   0x2800000, 0x0400000, CRC(294ab997) SHA1(aeba269ae7d056f07edecf96bc138231c66c3637) ) // good
4039   ROM_LOAD16_WORD_SWAP( "mpr20148.12",   0x2c00000, 0x0400000, CRC(5337ccb0) SHA1(a998bb116eb10c4044410f065c5ddeb845f9dab5) ) // good
4040ROM_END
4041
4042ROM_START( introdon )
4043   STV_BIOS
4044
4045   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4046   ROM_LOAD16_BYTE( "epr18937.13",               0x0000001, 0x0080000, CRC(1f40d766) SHA1(35d9751c1b23cfbf448f2a9e9cf3b121929368ae) )
4047   ROM_RELOAD( 0x0100001, 0x0080000)
4048
4049   ROM_LOAD16_WORD_SWAP( "mpr18944.7",    0x0200000, 0x0100000, CRC(f7f75ce5) SHA1(0787ece9f89cc1847889adbf08ba5d3ccbc405de) ) // good
4050   ROM_LOAD16_WORD_SWAP( "mpr18939.2",    0x0400000, 0x0400000, CRC(ef95a6e6) SHA1(3026c52ad542997d5b0e621b389c0e01240cb486) ) // good
4051   ROM_LOAD16_WORD_SWAP( "mpr18940.3",    0x0800000, 0x0400000, CRC(cabab4cd) SHA1(b251609573c4b0ccc933188f32226855b25fd9da) ) // good
4052   ROM_LOAD16_WORD_SWAP( "mpr18941.4",    0x0c00000, 0x0400000, CRC(f4a33a20) SHA1(bf0f33495fb5c9de4ae5036cedda65b3ece217e8) ) // good
4053   ROM_LOAD16_WORD_SWAP( "mpr18942.5",    0x1000000, 0x0400000, CRC(8dd0a446) SHA1(a75e3552b0fb99e0b253c0906f62fabcf204b735) ) // good
4054   ROM_LOAD16_WORD_SWAP( "mpr18943.6",    0x1400000, 0x0400000, CRC(d8702a9e) SHA1(960dd3cb0b9eb1f18b8d0bc0da532b600d583ceb) ) // good
4055   ROM_LOAD16_WORD_SWAP( "mpr18938.1",    0x1800000, 0x0400000, CRC(580ecb83) SHA1(6c59f7da408b53f9fa7aa32c1b53328b5fd6334d) ) // good
4056ROM_END
4057
4058/* set system to 1 player to test rom */
4059ROM_START( kiwames )
4060   STV_BIOS
4061
4062   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4063   ROM_LOAD16_BYTE( "epr18737.13",               0x0000001, 0x0080000, CRC(cfad6c49) SHA1(fc69980a351ed13307706db506c79c774eabeb66) ) // bad
4064   ROM_RELOAD( 0x0100001, 0x0080000)
4065
4066   ROM_LOAD16_WORD_SWAP( "mpr18738.2",    0x0400000, 0x0400000, CRC(4b3c175a) SHA1(b6d2438ae1d3d51950a7ed1eaadf2dae45c4e7b1) ) // good
4067   ROM_LOAD16_WORD_SWAP( "mpr18739.3",    0x0800000, 0x0400000, CRC(eb41fa67) SHA1(d12acebb1df9eafd17aff1841087f5017225e7e7) ) // good
4068   ROM_LOAD16_WORD_SWAP( "mpr18740.4",    0x0c00000, 0x0200000, CRC(9ca7962f) SHA1(a09e0db2246b34ca7efa3165afbc5ba292a95398) ) // good
4069
4070   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
4071   ROM_LOAD( "kiwames.nv", 0x0000, 0x0080, CRC(c7002732) SHA1(57395d256a58ddcedd354ce1f2c458321be40505) )
4072ROM_END
4073
4074ROM_START( maruchan )
4075   STV_BIOS
4076
4077   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4078   ROM_LOAD16_BYTE( "epr20416.13",               0x0000001, 0x0100000, CRC(8bf0176d) SHA1(5bd468e2ffed042ee84e2ceb8712ff5883a1d824) ) // bad
4079
4080   ROM_LOAD16_WORD_SWAP( "mpr20417.2",    0x0400000, 0x0400000, CRC(636c2a08) SHA1(47986b71d68f6a1852e4e2b03ca7b6e48e83718b) ) // good
4081   ROM_LOAD16_WORD_SWAP( "mpr20418.3",    0x0800000, 0x0400000, CRC(3f0d9e34) SHA1(2ec81e40ebf689d17b6421820bfb0a1280a8ef25) ) // good
4082   ROM_LOAD16_WORD_SWAP( "mpr20419.4",    0x0c00000, 0x0400000, CRC(ec969815) SHA1(b59782174051f5717b06f43e57dd8a2a6910d95f) ) // good
4083   ROM_LOAD16_WORD_SWAP( "mpr20420.5",    0x1000000, 0x0400000, CRC(f2902c88) SHA1(df81e137e8aa4bd37e1d14fce4d593cfd14608f0) ) // good
4084   ROM_LOAD16_WORD_SWAP( "mpr20421.6",    0x1400000, 0x0400000, CRC(cd0b477c) SHA1(5169cc47fae465b11bc50f5e8410d84c2b2eee42) ) // good
4085   ROM_LOAD16_WORD_SWAP( "mpr20422.1",    0x1800000, 0x0400000, CRC(66335049) SHA1(59f1968001d1e9fe30990a56309bae18033eee62) ) // good
4086   ROM_LOAD16_WORD_SWAP( "mpr20423.8",    0x1c00000, 0x0400000, CRC(2bd55832) SHA1(1a1a510f30882d4d726b594a6541a12c552fafb4) ) // good
4087   ROM_LOAD16_WORD_SWAP( "mpr20443.9",    0x2000000, 0x0400000, CRC(8ac288f5) SHA1(0c08874e6ab2b07b17438721fb535434a626115f) ) // good
4088ROM_END
4089
4090/* set system to 1 player to test rom */
4091ROM_START( myfairld )
4092   STV_BIOS
4093
4094   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4095   ROM_LOAD16_WORD_SWAP( "mpr21000.7",    0x0200000, 0x0200000, CRC(2581c560) SHA1(5fb64f0e09583d50dfea7ad613d45aad30b677a5) ) // good
4096   ROM_LOAD16_WORD_SWAP( "mpr20995.2",    0x0400000, 0x0400000, CRC(1bb73f24) SHA1(8773654810de760c5dffbb561f43e259b074a61b) ) // good
4097   ROM_LOAD16_WORD_SWAP( "mpr20996.3",    0x0800000, 0x0400000, CRC(993c3859) SHA1(93f95e3e080a08961784482607919c1ab3eeb5e5) ) // good
4098   ROM_LOAD16_WORD_SWAP( "mpr20997.4",    0x0c00000, 0x0400000, CRC(f0bf64a4) SHA1(f51431f1a736bbc498fa0baa1f8570f89984d9f9) ) // good
4099   ROM_LOAD16_WORD_SWAP( "mpr20998.5",    0x1000000, 0x0400000, CRC(d3b19786) SHA1(1933e57272cd68cc323922fa93a9af97dcef8450) ) // good
4100   ROM_LOAD16_WORD_SWAP( "mpr20999.6",    0x1400000, 0x0400000, CRC(82e31f25) SHA1(0cf74af14abb6ede21d19bc22041214232751594) ) // good
4101   ROM_LOAD16_WORD_SWAP( "mpr20994.1",    0x1800000, 0x0400000, CRC(a69243a0) SHA1(e5a1b6ec62bdd5b015ed6cf48f5a6aabaf4bd837) ) // good
4102   ROM_LOAD16_WORD_SWAP( "mpr21001.8",    0x1c00000, 0x0400000, CRC(95fbe549) SHA1(8cfb48f353b2849600373d66f293f103bca700df) ) // good
4103
4104   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
4105   ROM_LOAD( "myfairld.nv", 0x0000, 0x0080, CRC(c7cf3a5a) SHA1(5365f38047821305658f94395f03cf2c49c87576) )
4106ROM_END
4107
4108ROM_START( othellos )
4109   STV_BIOS
4110
4111   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4112   ROM_LOAD16_WORD_SWAP( "mpr20967.7",    0x0200000, 0x0200000, CRC(efc05b97) SHA1(a533366c3aaba90dcac8f3654db9ad902efca258) ) // good
4113   ROM_LOAD16_WORD_SWAP( "mpr20963.2",    0x0400000, 0x0400000, CRC(2cc4f141) SHA1(8bd1998aff8615b34d119fab3637a08ed6e8e1e4) ) // good
4114   ROM_LOAD16_WORD_SWAP( "mpr20964.3",    0x0800000, 0x0400000, CRC(5f5cda94) SHA1(616be219a2512e80c875eddf05137c23aedf6f65) ) // good
4115   ROM_LOAD16_WORD_SWAP( "mpr20965.4",    0x0c00000, 0x0400000, CRC(37044f3e) SHA1(cbc071554cfd8bb12a337c04b169de6c6309c3ab) ) // good
4116   ROM_LOAD16_WORD_SWAP( "mpr20966.5",    0x1000000, 0x0400000, CRC(b94b83de) SHA1(ba1b3135d0ad057f0786f94c9d06b5e347bedea8) ) // good
4117ROM_END
4118
4119ROM_START( pblbeach )
4120   STV_BIOS
4121
4122   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4123   ROM_LOAD16_BYTE( "epr18852.13",               0x0000001, 0x0080000, CRC(d12414ec) SHA1(0f42ec9e41983781b6892622b00398a102072aa7) ) // bad
4124   ROM_RELOAD ( 0x0100001, 0x0080000 )
4125
4126   ROM_LOAD16_WORD_SWAP( "mpr18853.2",    0x0400000, 0x0400000, CRC(b9268c97) SHA1(8734e3f0e6b2849d173e3acc9d0308084a4e84fd) ) // good
4127   ROM_LOAD16_WORD_SWAP( "mpr18854.3",    0x0800000, 0x0400000, CRC(3113c8bc) SHA1(4e4600646ddd1978988d27430ffdf0d1d405b804) ) // good
4128   ROM_LOAD16_WORD_SWAP( "mpr18855.4",    0x0c00000, 0x0400000, CRC(daf6ad0c) SHA1(2a14a6a42e4eb68abb7a427e43062dfde2d13c5c) ) // good
4129   ROM_LOAD16_WORD_SWAP( "mpr18856.5",    0x1000000, 0x0400000, CRC(214cef24) SHA1(f62b462170b377cff16bb6c6126cbba00b013a87) ) // good
4130ROM_END
4131
4132ROM_START( prikura )
4133   STV_BIOS
4134
4135   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4136   ROM_LOAD16_WORD_SWAP( "mpr19337.7",    0x0200000, 0x0200000, CRC(76f69ff3) SHA1(5af2e1eb3288d70c2a1c71d0b6370125d65c7757) ) // good
4137   ROM_LOAD16_WORD_SWAP( "mpr19333.2",    0x0400000, 0x0400000, CRC(eb57a6a6) SHA1(cdacaa7a2fb1a343195e2ac5fd02eabf27f89ccd) ) // good
4138   ROM_LOAD16_WORD_SWAP( "mpr19334.3",    0x0800000, 0x0400000, CRC(c9979981) SHA1(be491a4ac118d5025d6a6f2d9267a6d52f21d2b6) ) // good
4139   ROM_LOAD16_WORD_SWAP( "mpr19335.4",    0x0c00000, 0x0400000, CRC(9e000140) SHA1(9b7dc3dc7f9dc048d2fcbc2b44ae79a631ceb381) ) // good
4140   ROM_LOAD16_WORD_SWAP( "mpr19336.5",    0x1000000, 0x0400000, CRC(2363fa4b) SHA1(f45e53352520be4ea313eeab87bcab83f479d5a8) ) // good
4141ROM_END
4142
4143ROM_START( puyosun )
4144   STV_BIOS
4145
4146   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4147   ROM_LOAD16_BYTE( "epr19531.13",               0x0000001, 0x0080000, CRC(ac81024f) SHA1(b22c7c1798fade7ae992ff83b138dd23e6292d3f) ) // bad
4148   ROM_RELOAD ( 0x0100001, 0x0080000 )
4149
4150   ROM_LOAD16_WORD_SWAP( "mpr19533.2",    0x0400000, 0x0400000, CRC(17ec54ba) SHA1(d4cdc86926519291cc78980ec513e1cfc677e76e) ) // good
4151   ROM_LOAD16_WORD_SWAP( "mpr19534.3",    0x0800000, 0x0400000, CRC(820e4781) SHA1(7ea5626ad4e1929a5ec28a99ec12bc364df8f70d) ) // good
4152   ROM_LOAD16_WORD_SWAP( "mpr19535.4",    0x0c00000, 0x0400000, CRC(94fadfa4) SHA1(a7d0727cf601e00f1ea31e6bf3e591349c3f6030) ) // good
4153   ROM_LOAD16_WORD_SWAP( "mpr19536.5",    0x1000000, 0x0400000, CRC(5765bc9c) SHA1(b217c292e7cc8ed73a39a3ae7009bc9dd031e376) ) // good
4154   ROM_LOAD16_WORD_SWAP( "mpr19537.6",    0x1400000, 0x0400000, CRC(8b736686) SHA1(aec347c0f3e5dd8646e85f68d71ca9acc3bf62c3) ) // good
4155   ROM_LOAD16_WORD_SWAP( "mpr19532.1",    0x1800000, 0x0400000, CRC(985f0c9d) SHA1(de1ad42ef3cf3f4f071e9801696407be7ae29d21) ) // good
4156   ROM_LOAD16_WORD_SWAP( "mpr19538.8",    0x1c00000, 0x0400000, CRC(915a723e) SHA1(96480441a69d6aad3887ed6f46b0a6bebfb752aa) ) // good
4157   ROM_LOAD16_WORD_SWAP( "mpr19539.9",    0x2000000, 0x0400000, CRC(72a297e5) SHA1(679987e62118dd1bf7c074f4b88678e1a1187437) ) // good
4158ROM_END
4159
4160ROM_START( rsgun )
4161   STV_BIOS
4162
4163   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4164   ROM_LOAD16_WORD_SWAP( "mpr20958.7",   0x0200000, 0x0200000, CRC(cbe5a449) SHA1(b4744ab71ccbadda1921ba43dd1148e57c0f84c5) ) // good (was .11s)
4165   ROM_LOAD16_WORD_SWAP( "mpr20959.2",   0x0400000, 0x0400000, CRC(a953330b) SHA1(965274a7297cb88e281fcbdd3ec5025c6463cc7b) ) // good (was .12)
4166   ROM_LOAD16_WORD_SWAP( "mpr20960.3",   0x0800000, 0x0400000, CRC(b5ab9053) SHA1(87c5d077eb1219c35fa65b4e11d5b62e826f5236) ) // good (was .13)
4167   ROM_LOAD16_WORD_SWAP( "mpr20961.4",   0x0c00000, 0x0400000, CRC(0e06295c) SHA1(0ec2842622f3e9dc5689abd58aeddc7e5603b97a) ) // good (was .14)
4168   ROM_LOAD16_WORD_SWAP( "mpr20962.5",   0x1000000, 0x0400000, CRC(f1e6c7fc) SHA1(0ba0972f1bc7c56f4e0589d3e363523cea988bb0) ) // good (was .15)
4169   /*Without the following the game crashes,maybe we need to mirror the previous roms in this location?*/
4170   //ROM_FILL(                             0x1400000, 0x0c00000, 0x00 )
4171ROM_END
4172
4173ROM_START( sandor )
4174   STV_BIOS
4175
4176   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4177   ROM_LOAD16_BYTE( "sando-r.13",               0x0000001, 0x0100000, CRC(fe63a239) SHA1(01502d4494f968443581cd2c74f25967d41f775e) )
4178
4179   ROM_LOAD16_WORD_SWAP( "mpr18635.8",   0x1c00000, 0x0400000, CRC(441e1368) SHA1(acb2a7e8d44c2203b8d3c7a7b70e20ffb120bebf) ) // good
4180   ROM_RELOAD(                           0x0400000, 0x0400000 )
4181   ROM_LOAD16_WORD_SWAP( "mpr18636.9",   0x2000000, 0x0400000, CRC(fff1dd80) SHA1(36b8e1526a4370ae33fd4671850faf51c448bca4) ) // good
4182   ROM_RELOAD(                           0x0800000, 0x0400000 )
4183   ROM_LOAD16_WORD_SWAP( "mpr18637.10",  0x2400000, 0x0400000, CRC(83aced0f) SHA1(6cd1702b9c2655dc4f56c666607c333f62b09fc0) ) // good
4184   ROM_RELOAD(                           0x0c00000, 0x0400000 )
4185   ROM_LOAD16_WORD_SWAP( "mpr18638.11",  0x2800000, 0x0400000, CRC(caab531b) SHA1(a77bdcc27d183896c0ed576eeebcc1785d93669e) ) // good
4186   ROM_RELOAD(                           0x1000000, 0x0400000 )
4187ROM_END
4188
4189
4190/*
4191Treasure Hunt
4192Deniam (Licensed to Sega Enterprises, Ltd), 1997
4193
4194PCB Number: LEX-0704
4195
4196This is a non-Sega-manufactured STV cart which works with Japanese and USA bioses.
4197The cart is mostly the same as the Sega carts, containing not a lot except some ROMs
4198and logic chips.
4199
4200On the top side, there are two 27C040 EPROMs and positions for 5 maskROMs, but only 4 of
4201them are populated. In between the two eproms is an unpopulated position for a TSOP40 flashROM.
4202On the bottom are locations for 5 maskROMs (none are populated) and also some logic ICs.
4203*/
4204
4205ROM_START( thunt )
4206   STV_BIOS
4207
4208   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4209   ROM_LOAD16_BYTE( "th-ic7_2.stv",    0x0200000, 0x0080000, CRC(c4e993de) SHA1(7aa433bc2623cb19a09d4ef4c8233a2d29901020) )
4210   ROM_LOAD16_BYTE( "th-ic7_1.stv",    0x0200001, 0x0080000, CRC(1355cc18) SHA1(a9b731228a807b2b01f933fe0f7dcdbadaf89b7e) )
4211
4212   ROM_LOAD16_WORD_SWAP( "th-e-2.ic2",   0x0400000, 0x0400000, CRC(47315694) SHA1(4a7cc195b98dbca146f5efe3b5b35be0f13b2f4a) )
4213   ROM_LOAD16_WORD_SWAP( "th-e-3.ic3",   0x0800000, 0x0400000, CRC(c9290b44) SHA1(4e51e667edf330cc20e600cf1500f332cc533e20) )
4214   ROM_LOAD16_WORD_SWAP( "th-e-4.ic4",   0x0c00000, 0x0400000, CRC(c672e40b) SHA1(4ba189de7b8fb5ca45fb15c89cdaf0f860831d52) )
4215   ROM_LOAD16_WORD_SWAP( "th-e-5.ic5",   0x1000000, 0x0400000, CRC(3914b805) SHA1(1331ce82ba0bdfc76fe3456a5252e69c00e2cf1f) )
4216ROM_END
4217
4218ROM_START( thuntk )
4219   STV_BIOS
4220
4221   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4222   ROM_LOAD16_BYTE( "2.ic13_2",    0x0200000, 0x0080000, CRC(6cae2926) SHA1(e8d5745b4228de24672da5017cb3dab58344f59f) )
4223   ROM_LOAD16_BYTE( "1.ic13_1",    0x0200001, 0x0080000, CRC(460727c8) SHA1(da7171b65734264e10692e3408ac93beb374c65e) )
4224
4225   ROM_LOAD( "bom210-10.ic2",   0x1c00000, 0x0400000, CRC(f59d0827) SHA1(2bed4b2c78e9b4e9332f576e1b264a6343f4cfff) )
4226   ROM_RELOAD(                  0x0400000, 0x0400000 )
4227   ROM_LOAD( "bom210-11.ic3",   0x2000000, 0x0400000, CRC(44e5a13e) SHA1(aee3c06662a1d083f3bd01292cf2694132f63533) )
4228   ROM_RELOAD(                  0x0800000, 0x0400000 )
4229   ROM_LOAD( "bom210-12.ic4",   0x2400000, 0x0400000, CRC(deabc701) SHA1(cb313ae9bf6f115682fc76647a999e12c98f6120) )
4230   ROM_RELOAD(                  0x0c00000, 0x0400000 )
4231   ROM_LOAD( "bom210-13.ic5",   0x2800000, 0x0400000, CRC(5ece1d5c) SHA1(6d88f71b485bf2b3c164fa22f1c7ecaba4b3f5b1) )
4232   ROM_RELOAD(                  0x1000000, 0x0400000 )
4233ROM_END
4234
4235
4236ROM_START( sanjeon )
4237   STV_BIOS
4238
4239   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4240   ROM_LOAD16_BYTE( "ic11",               0x0000001, 0x0200000, CRC(9abae8d4) SHA1(ddbe4c8fff8fa59d63e278e95f245145d2da8aeb) )
4241
4242   ROM_LOAD( "ic13",    0x0400000, 0x0200000, CRC(f72c1d13) SHA1(a2b168d187034024b83fbbe2f5eec78816285da9) ) // ic2 good
4243   ROM_LOAD( "ic14",    0x0600000, 0x0200000, CRC(bcd72105) SHA1(fb88a1f2589fef5d9845027646259ec8e781771b) ) // ic2 good
4244   ROM_LOAD( "ic15",    0x0800000, 0x0200000, CRC(8c9c8352) SHA1(312e9e6435c6e9a4a19b72e234b087d4f5b069a5) ) // ic3 good
4245   ROM_LOAD( "ic16",    0x0a00000, 0x0200000, CRC(07e11512) SHA1(5fb5e93a167aae501bd799aba98f7dbc3762a795) ) // ic3 good
4246   ROM_LOAD( "ic17",    0x0c00000, 0x0200000, CRC(46b7b344) SHA1(a325b724e6346f585582bb2581d3063b1c8ddee9) ) // ic4 good
4247   ROM_LOAD( "ic18",    0x0e00000, 0x0200000, CRC(d48404e1) SHA1(e4927d17cb19f6825f41b41056b89de224cf97de) ) // ic4 good
4248   ROM_LOAD( "ic19",    0x1000000, 0x0200000, CRC(33d23bb9) SHA1(0179438a0b14ad7eb553a24d86fae778671fcc49) ) // ic5 good
4249   ROM_LOAD( "ic20",    0x1200000, 0x0200000, CRC(f8cc1038) SHA1(06bcb25eb5df77bd503b0692a96ec66c00976fe9) ) // ic5 good
4250   ROM_LOAD( "ic21",    0x1400000, 0x0200000, CRC(74ceb649) SHA1(91b7eb699b7167f890528149178644a74ef3ad17) ) // ic6 good
4251   ROM_LOAD( "ic22",    0x1600000, 0x0200000, CRC(85f31277) SHA1(277c28d44cabd9081a8151d6ec27d47b5606435a) ) // ic6 good
4252   ROM_LOAD( "ic12",    0x1800000, 0x0400000, CRC(d5ebc84e) SHA1(f990b793cdfadbbac69c680191660f4a2f282ba2) ) // ic1 good
4253ROM_END
4254
4255
4256ROM_START( sasissu )
4257   STV_BIOS
4258
4259   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4260   ROM_LOAD16_BYTE( "epr20542.13",               0x0000001, 0x0100000, CRC(0e632db5) SHA1(9bc52794892eec22d381387d13a0388042e30714) )
4261
4262   ROM_LOAD16_WORD_SWAP( "mpr20544.2",    0x0400000, 0x0400000, CRC(661fff5e) SHA1(41f4ddda7adf004b52cc9a076606a60f31947d19) ) // good
4263   ROM_LOAD16_WORD_SWAP( "mpr20545.3",    0x0800000, 0x0400000, CRC(8e3a37be) SHA1(a3227cdc4f03bb088e7f9aed225b238da3283e01) ) // good
4264   ROM_LOAD16_WORD_SWAP( "mpr20546.4",    0x0c00000, 0x0400000, CRC(72020886) SHA1(e80bdeb11b726eb23f2283950d65d55e31a5672e) ) // good
4265   ROM_LOAD16_WORD_SWAP( "mpr20547.5",    0x1000000, 0x0400000, CRC(8362e397) SHA1(71f13689a60572a04b91417a9a48adfd3bd0f5dc) ) // good
4266   ROM_LOAD16_WORD_SWAP( "mpr20548.6",    0x1400000, 0x0400000, CRC(e37534d9) SHA1(79988cbb1537ca99fdd0288a86564fe1f714d052) ) // good
4267   ROM_LOAD16_WORD_SWAP( "mpr20543.1",    0x1800000, 0x0400000, CRC(1f688cdf) SHA1(a90c1011119adb50e0d9d5cd3d7616a307b2d7e8) ) // good
4268ROM_END
4269
4270/* set to 1 player to test */
4271ROM_START( seabass )
4272   STV_BIOS
4273
4274   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4275   ROM_LOAD16_BYTE( "seabassf.13",               0x0000001, 0x0100000, CRC(6d7c39cc) SHA1(d9d1663134420b75c65ee07d7d547254785f2f83) )
4276
4277   ROM_LOAD16_WORD_SWAP( "mpr20551.2",    0x0400000, 0x0400000, CRC(9a0c6dd8) SHA1(26600372cc673ce3678945f4b5dc4e3ab31643a4) ) // good
4278   ROM_LOAD16_WORD_SWAP( "mpr20552.3",    0x0800000, 0x0400000, CRC(5f46b0aa) SHA1(1aa576b15971c0ffb4e08d4802246841b31b6f35) ) // good
4279   ROM_LOAD16_WORD_SWAP( "mpr20553.4",    0x0c00000, 0x0400000, CRC(c0f8a6b6) SHA1(2038b9231a950450267be0db24b31d8035db79ad) ) // good
4280   ROM_LOAD16_WORD_SWAP( "mpr20554.5",    0x1000000, 0x0400000, CRC(215fc1f9) SHA1(f042145622ba4bbbcce5f050a4c9eae42cb7adcd) ) // good
4281   ROM_LOAD16_WORD_SWAP( "mpr20555.6",    0x1400000, 0x0400000, CRC(3f5186a9) SHA1(d613f307ab150a7eae358aa449206af05db5f9d7) ) // good
4282   ROM_LOAD16_WORD_SWAP( "mpr20550.1",    0x1800000, 0x0400000, CRC(083e1ca8) SHA1(03944dd8fe86f305ca4bd2d71e2140e03798ffc9) ) // good
4283   ROM_LOAD16_WORD_SWAP( "mpr20556.8",    0x1c00000, 0x0400000, CRC(1fd70c6c) SHA1(d9d2e362d13238216f4f7e10095fb8383bbd91e8) ) // good
4284   ROM_LOAD16_WORD_SWAP( "mpr20557.9",    0x2000000, 0x0400000, CRC(3c9ba442) SHA1(2e5b795cf4cdc11ab3e4887b2f77c7147c6e3eec) ) // good
4285
4286   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
4287   ROM_LOAD( "seabass.nv", 0x0000, 0x0080, CRC(4e7c0944) SHA1(dbba78f6a7f3e7d12d5c4fff36117db82f5f9c01) )
4288ROM_END
4289
4290ROM_START( shanhigw )
4291   STV_BIOS
4292
4293   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4294   ROM_LOAD16_WORD_SWAP( "mpr18341.7",    0x0200000, 0x0200000, CRC(cc5e8646) SHA1(a733616c118140ff3887d30d595533f9a1beae06) ) // good
4295   ROM_LOAD16_WORD_SWAP( "mpr18340.2",    0x0400000, 0x0200000, CRC(8db23212) SHA1(85d604a5c6ab97188716dbcd77d365af12a238fe) ) // good
4296ROM_END
4297
4298ROM_START( shienryu )
4299   STV_BIOS
4300
4301   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4302   ROM_LOAD16_WORD_SWAP( "mpr19631.7",    0x0200000, 0x0200000, CRC(3a4b1abc) SHA1(3b14b7fdebd4817da32ea374c15a38c695ffeff1) ) // good
4303   ROM_LOAD16_WORD_SWAP( "mpr19632.2",    0x0400000, 0x0400000, CRC(985fae46) SHA1(f953bde91805b97b60d2ab9270f9d2933e064d95) ) // good
4304   ROM_LOAD16_WORD_SWAP( "mpr19633.3",    0x0800000, 0x0400000, CRC(e2f0b037) SHA1(97861d09e10ce5d2b10bf5559574b3f489e28077) ) // good
4305
4306   ROM_REGION16_BE( 0x80, "eeprom", 0 )
4307   ROM_LOAD( "eeprom-shienryu.bin", 0x0000, 0x0080, CRC(98db6925) SHA1(e78545e8f62d19f8e00197c62ff0e56f6c85e355) )
4308ROM_END
4309
4310ROM_START( smleague ) /* only runs with the USA bios */
4311   STV_BIOS
4312   ROM_DEFAULT_BIOS( "us" )
4313
4314   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4315   ROM_LOAD16_BYTE( "epr18777.13",               0x0000001, 0x0080000, CRC(8d180866) SHA1(d47ebabab6e06400312d39f68cd818852e496b96) )
4316   ROM_RELOAD ( 0x0100001, 0x0080000 )
4317
4318   ROM_LOAD16_WORD_SWAP( "mpr18778.8",    0x1c00000, 0x0400000, CRC(25e1300e) SHA1(64f3843f62cee34a47244ad5ee78fb2aa35289e3) ) // good
4319   ROM_LOAD16_WORD_SWAP( "mpr18779.9",    0x2000000, 0x0400000, CRC(51e2fabd) SHA1(3aa361149af516f16d7d422596ee82014a183c2b) ) // good
4320   ROM_LOAD16_WORD_SWAP( "mpr18780.10",   0x2400000, 0x0400000, CRC(8cd4dd74) SHA1(9ffec1280b3965d52f643894bdfecdd792028191) ) // good
4321   ROM_LOAD16_WORD_SWAP( "mpr18781.11",   0x2800000, 0x0400000, CRC(13ee41ae) SHA1(cdbaeac4c90b5ee84233c299612f7f28280a6ba6) ) // good
4322   ROM_LOAD16_WORD_SWAP( "mpr18782.12",   0x2c00000, 0x0200000, CRC(9be2270a) SHA1(f2de5cd6b269f123305e30bed2b474019e4f05b8) ) // good
4323ROM_END
4324
4325ROM_START( sokyugrt )
4326   STV_BIOS
4327
4328   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4329   ROM_LOAD16_BYTE( "fpr19188.13",               0x0000001, 0x0100000, CRC(45a27e32) SHA1(96e1bab8bdadf7071afac2a0a6dd8fd8989f12a6) )
4330
4331   ROM_LOAD16_WORD_SWAP( "mpr19189.2",    0x0400000, 0x0400000, CRC(0b202a3e) SHA1(6691b5af2cacd6092ec03886b78c2565953fa297) ) // good
4332   ROM_LOAD16_WORD_SWAP( "mpr19190.3",    0x0800000, 0x0400000, CRC(1777ded8) SHA1(dd332ac79f0a6d82b6bde35b795b2845003dd1a5) ) // good
4333   ROM_LOAD16_WORD_SWAP( "mpr19191.4",    0x0c00000, 0x0400000, CRC(ec6eb07b) SHA1(01fe4832ece8638ea6f4060099d9105fe8092c88) ) // good
4334   ROM_LOAD16_WORD_SWAP( "mpr19192.5",    0x1000000, 0x0200000, CRC(cb544a1e) SHA1(eb3ba9758487d0e8c4bbfc41453fe35b35cce3bf) ) // good
4335ROM_END
4336
4337/* set to 1 player to test */
4338ROM_START( sss )
4339   STV_BIOS
4340
4341   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4342   ROM_LOAD16_BYTE( "epr21488.13",               0x0000001, 0x0080000, CRC(71c9def1) SHA1(a544a0b4046307172d2c1bf426ed24845f87d894) )
4343   ROM_RELOAD ( 0x0100001, 0x0080000 )
4344
4345   ROM_LOAD16_WORD_SWAP( "mpr21489.2",    0x0400000, 0x0400000, CRC(4c85152b) SHA1(78f2f1c31718d5bf631d8813daf9a11ea2a0e451) ) // ic2 good (was .12)
4346   ROM_LOAD16_WORD_SWAP( "mpr21490.3",    0x0800000, 0x0400000, CRC(03da67f8) SHA1(02f9ba7549ca552291dc0ff1b631103015838bba) ) // ic3 good (was .13)
4347   ROM_LOAD16_WORD_SWAP( "mpr21491.4",    0x0c00000, 0x0400000, CRC(cf7ee784) SHA1(af823df2d60d8ef3d17628b95a04136b807ca095) ) // ic4 good (was .14)
4348   ROM_LOAD16_WORD_SWAP( "mpr21492.5",    0x1000000, 0x0400000, CRC(57753894) SHA1(5c51167c158443d02a53d724a5ceb73055876c06) ) // ic5 good (was .15)
4349   ROM_LOAD16_WORD_SWAP( "mpr21493.6",    0x1400000, 0x0400000, CRC(efb2d271) SHA1(a591e48206704fbda5fef3ce69ad279da1017ed6) ) // ic6 good (was .16)
4350
4351   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
4352   ROM_LOAD( "sss.nv", 0x0000, 0x0080, CRC(3473b2f3) SHA1(6480b4b321af8ee6e967710e74f2556c17bfca97) )
4353ROM_END
4354
4355ROM_START( suikoenb )
4356   STV_BIOS
4357
4358   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4359   ROM_LOAD16_BYTE( "fpr17834.13",               0x0000001, 0x0100000, CRC(746ef686) SHA1(e31c317991a687662a8a2a45aed411001e5f1941) )
4360
4361   ROM_LOAD16_WORD_SWAP( "mpr17836.2",    0x0400000, 0x0400000, CRC(55e9642d) SHA1(5198291cd1dce0398eb47760db2c19eae99273b0) ) // good
4362   ROM_LOAD16_WORD_SWAP( "mpr17837.3",    0x0800000, 0x0400000, CRC(13d1e667) SHA1(cd513ceb33cc20032090113b61227638cf3b3998) ) // good
4363   ROM_LOAD16_WORD_SWAP( "mpr17838.4",    0x0c00000, 0x0400000, CRC(f9e70032) SHA1(8efdbcce01bdf77acfdb293545c59bf224a9c7d2) ) // good
4364   ROM_LOAD16_WORD_SWAP( "mpr17839.5",    0x1000000, 0x0400000, CRC(1b2762c5) SHA1(5c7d5fc8a4705249a5b0ea64d51dc3dc95d723f5) ) // good
4365   ROM_LOAD16_WORD_SWAP( "mpr17840.6",    0x1400000, 0x0400000, CRC(0fd4c857) SHA1(42caf22716e834d59e60d45c24f51d95734e63ae) ) // good
4366   ROM_LOAD16_WORD_SWAP( "mpr17835.1",    0x1800000, 0x0400000, CRC(77f5cb43) SHA1(a4f54bc08d73a56caee5b26bea06360568655bd7) ) // good
4367   ROM_LOAD16_WORD_SWAP( "mpr17841.8",    0x1c00000, 0x0400000, CRC(f48beffc) SHA1(92f1730a206f4a0abf7fb0ee1210e083a464ad70) ) // good
4368   ROM_LOAD16_WORD_SWAP( "mpr17842.9",    0x2000000, 0x0400000, CRC(ac8deed7) SHA1(370eb2216b8080d3ddadbd32804db63c4ebac76f) ) // good
4369ROM_END
4370
4371ROM_START( twcup98 )
4372   STV_BIOS
4373
4374   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4375   ROM_LOAD16_BYTE( "epr20819.13",    0x0000001, 0x0100000, CRC(d930dfc8) SHA1(f66cc955181720661a0334fe67fa5750ddf9758b) )
4376
4377   ROM_LOAD16_WORD_SWAP( "mpr20821.2",    0x0400000, 0x0400000, CRC(2d930d23) SHA1(5fcaf4257f3639cb3aa407d2936f616499a09d97) ) // ic2 good (was .12)
4378   ROM_LOAD16_WORD_SWAP( "mpr20822.3",    0x0800000, 0x0400000, CRC(8b33a5e2) SHA1(d5689ac8aad63509febe9aa4077351be09b2d8d4) ) // ic3 good (was .13)
4379   ROM_LOAD16_WORD_SWAP( "mpr20823.4",    0x0c00000, 0x0400000, CRC(6e6d4e95) SHA1(c387d03ba27580c62ac0bf780915fdf41552df6f) ) // ic4 good (was .14)
4380   ROM_LOAD16_WORD_SWAP( "mpr20824.5",    0x1000000, 0x0400000, CRC(4cf18a25) SHA1(310961a5f114fea8938a3f514dffd5231e910a5a) ) // ic5 good (was .15)
4381ROM_END
4382
4383ROM_START( vfkids )
4384   STV_BIOS
4385
4386   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4387   ROM_LOAD16_BYTE( "fpr18914.13",               0x0000001, 0x0100000, CRC(cd35730a) SHA1(645b52b449766beb740ab8f99957f8f431351ceb) )
4388
4389   ROM_LOAD16_WORD_SWAP( "mpr18916.4",    0x0c00000, 0x0400000, CRC(4aae3ddb) SHA1(b75479e73f1bce3f0c27fbd90820fa51eb1914a6) ) // good
4390   ROM_LOAD16_WORD_SWAP( "mpr18917.5",    0x1000000, 0x0400000, CRC(edf6edc3) SHA1(478e958f4f10a8126a00c83feca4a55ad6c25503) ) // good
4391   ROM_LOAD16_WORD_SWAP( "mpr18918.6",    0x1400000, 0x0400000, CRC(d3a95036) SHA1(e300bbbb71fb06027dc539c9bbb12946770ffc95) ) // good
4392   ROM_LOAD16_WORD_SWAP( "mpr18915.1",    0x1800000, 0x0400000, CRC(09cc38e5) SHA1(4dfe0e2f21f746020ec557e62487aa7558cbc1fd) ) // good
4393   ROM_LOAD16_WORD_SWAP( "mpr18919.8",    0x1c00000, 0x0400000, CRC(4ac700de) SHA1(b1a8501f1683de380dfa49c9cabbe28bd70a5b26) ) // good
4394   ROM_LOAD16_WORD_SWAP( "mpr18920.9",    0x2000000, 0x0400000, CRC(0106e36c) SHA1(f7c30dc9fedb9da079dd7d52fdecbeb8721c5dee) ) // good
4395   ROM_LOAD16_WORD_SWAP( "mpr18921.10",   0x2400000, 0x0400000, CRC(c23d51ad) SHA1(0169b7e2df84e8caa2b349843bd0673f6de2195f) ) // good
4396   ROM_LOAD16_WORD_SWAP( "mpr18922.11",   0x2800000, 0x0400000, CRC(99d0ab90) SHA1(e9c82a826cc76ffbe2423913645cf5d5ba2506d6) ) // good
4397   ROM_LOAD16_WORD_SWAP( "mpr18923.12",   0x2c00000, 0x0400000, CRC(30a41ae9) SHA1(78a3d88b5e6cf669b660460ac967daf408038883) ) // good
4398ROM_END
4399
4400ROM_START( vfremix )
4401   STV_BIOS
4402
4403   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4404   ROM_LOAD16_BYTE( "epr17944.13",               0x0000001, 0x0100000, CRC(a5bdc560) SHA1(d3830480a611b7d88760c672ce46a2ea74076487) )
4405
4406   ROM_LOAD16_WORD_SWAP( "mpr17946.2",    0x0400000, 0x0400000, CRC(4cb245f7) SHA1(363d9936b27043b5858c956a45736ac05aefc54e) ) // good
4407   ROM_LOAD16_WORD_SWAP( "mpr17947.3",    0x0800000, 0x0400000, CRC(fef4a9fb) SHA1(1b4bd095962db769da17d3644df10f62d041e914) ) // good
4408   ROM_LOAD16_WORD_SWAP( "mpr17948.4",    0x0c00000, 0x0400000, CRC(3e2b251a) SHA1(be6191c18727d7cbc6399fd4c1aaae59304af30c) ) // good
4409   ROM_LOAD16_WORD_SWAP( "mpr17949.5",    0x1000000, 0x0400000, CRC(b2ecea25) SHA1(320c0e7ce34e81e2fe6400cbeb2cb3ca74426cc8) ) // good
4410   ROM_LOAD16_WORD_SWAP( "mpr17950.6",    0x1400000, 0x0400000, CRC(5b1f981d) SHA1(693b5744d210a2ac8b77e7c8c87f07ca859f8aed) ) // good
4411   ROM_LOAD16_WORD_SWAP( "mpr17945.1",    0x1800000, 0x0200000, CRC(03ede188) SHA1(849c7fab5b97e043fea3deb8df6cc195ccced0e0) ) // good
4412ROM_END
4413
4414/* set to 1 player to test */
4415ROM_START( vmahjong )
4416   STV_BIOS
4417
4418   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4419   ROM_LOAD16_WORD_SWAP( "mpr19620.7",    0x0200000, 0x0200000, CRC(c98de7e5) SHA1(5346f884793bcb080aa01967e91b54ced4a9802f) ) // good
4420   ROM_LOAD16_WORD_SWAP( "mpr19615.2",    0x0400000, 0x0400000, CRC(c62896da) SHA1(52a5b10ca8af31295d2d700349eca038c418b522) ) // good
4421   ROM_LOAD16_WORD_SWAP( "mpr19616.3",    0x0800000, 0x0400000, CRC(f62207c7) SHA1(87e60183365c6f7e62c7a0667f88df0c7f5457fd) ) // good
4422   ROM_LOAD16_WORD_SWAP( "mpr19617.4",    0x0c00000, 0x0400000, CRC(ab667e19) SHA1(2608a567888fe052753d0679d9a831d7706dbc86) ) // good
4423   ROM_LOAD16_WORD_SWAP( "mpr19618.5",    0x1000000, 0x0400000, CRC(9782ceee) SHA1(405dd42706416e128b1e2fde225b5343e9330092) ) // good
4424   ROM_LOAD16_WORD_SWAP( "mpr19619.6",    0x1400000, 0x0400000, CRC(0b76866c) SHA1(10add2993dfe9daf757ec2ff8675390081a93c0a) ) // good
4425   ROM_LOAD16_WORD_SWAP( "mpr19614.1",    0x1800000, 0x0400000, CRC(b83b3f03) SHA1(e5a5919ee74964633eaaf4af2fe04c38604ccf16) ) // good
4426   ROM_LOAD16_WORD_SWAP( "mpr19621.8",    0x1c00000, 0x0400000, CRC(f92616b3) SHA1(61a9dda92a86a02d027260e11b1bad3b0dda9f02) ) // good
4427
4428   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
4429   ROM_LOAD( "vmahjong.nv", 0x0000, 0x0080, CRC(4e6487f4) SHA1(d6d930ab5f21b8c4f42812d08b3ee90f2bc94081) )
4430ROM_END
4431
4432ROM_START( winterht )
4433   STV_BIOS
4434
4435   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4436   ROM_LOAD16_BYTE( "fpr20108.13",    0x0000001, 0x0100000, CRC(1ef9ced0) SHA1(abc90ce341cd17bb77349d611d6879389611f0bf) ) // bad
4437
4438   ROM_LOAD16_WORD_SWAP( "mpr20110.2",    0x0400000, 0x0400000, CRC(238ef832) SHA1(20fade5730ff8e249a1450c41bfdff6e133f4768) ) // good
4439   ROM_LOAD16_WORD_SWAP( "mpr20111.3",    0x0800000, 0x0400000, CRC(b0a86f69) SHA1(e66427f70413ad43fccc38423962c5eeda01094f) ) // good
4440   ROM_LOAD16_WORD_SWAP( "mpr20112.4",    0x0c00000, 0x0400000, CRC(3ba2b49b) SHA1(5ad154a8b774075479d791e29cbaf221d47557fc) ) // good
4441   ROM_LOAD16_WORD_SWAP( "mpr20113.5",    0x1000000, 0x0400000, CRC(8c858b41) SHA1(d05d2980363c8440863fe2fdb39274de246bd4b9) ) // good
4442   ROM_LOAD16_WORD_SWAP( "mpr20114.6",    0x1400000, 0x0400000, CRC(b723862c) SHA1(1e0a08669f16fc4cb647124e0c215233ccb98e5a) ) // good
4443   ROM_LOAD16_WORD_SWAP( "mpr20109.1",    0x1800000, 0x0400000, CRC(c1a713b8) SHA1(a7fefa6e9a1e3aecff5ead41da6fd3aec2ef502a) ) // good
4444   ROM_LOAD16_WORD_SWAP( "mpr20115.8",    0x1c00000, 0x0400000, CRC(dd01f2ad) SHA1(3bb48dc8670d9460fea2a67400ddb573472c2f4f) ) // good
4445ROM_END
4446
4447ROM_START( znpwfv )
4448   STV_BIOS
4449
4450   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4451   ROM_LOAD16_BYTE( "epr20398.13",    0x0000001, 0x0100000, CRC(3fb56a0b) SHA1(13c2fa2d94b106d39e46f71d15fbce3607a5965a) ) // bad
4452
4453   ROM_LOAD16_WORD_SWAP( "mpr20400.2",    0x0400000, 0x0400000, CRC(1edfbe05) SHA1(b0edd3f3d57408101ae6eb0aec742afbb4d289ca) ) // good
4454   ROM_LOAD16_WORD_SWAP( "mpr20401.3",    0x0800000, 0x0400000, CRC(99e98937) SHA1(e1b4d12a0b4d0fe97a62fcc085e19cce77657c99) ) // good
4455   ROM_LOAD16_WORD_SWAP( "mpr20402.4",    0x0c00000, 0x0400000, CRC(4572aa60) SHA1(8b2d76ea8c6e2f472c6ee7c9b6ad6e80e6a1a85a) ) // good
4456   ROM_LOAD16_WORD_SWAP( "mpr20403.5",    0x1000000, 0x0400000, CRC(26a8e13e) SHA1(07f5564b704598e3c3580d3d620ecc4f14549dbd) ) // good
4457   ROM_LOAD16_WORD_SWAP( "mpr20404.6",    0x1400000, 0x0400000, CRC(0b70275d) SHA1(47b8672e19c698dc948760f7091f4c6280e728d0) ) // good
4458   ROM_LOAD16_WORD_SWAP( "mpr20399.1",    0x1800000, 0x0400000, CRC(c178a96e) SHA1(65f4aa05187d48ba8ad4fe75ff6ffe1f8524831d) ) // good
4459   ROM_LOAD16_WORD_SWAP( "mpr20405.8",    0x1c00000, 0x0400000, CRC(f53337b7) SHA1(09a21f81016ee54f10554ae1f790415d7436afe0) ) // good
4460   ROM_LOAD16_WORD_SWAP( "mpr20406.9",    0x2000000, 0x0400000, CRC(b677c175) SHA1(d0de7b5a29928036df0bdfced5a8021c0999eb26) ) // good
4461   ROM_LOAD16_WORD_SWAP( "mpr20407.10",   0x2400000, 0x0400000, CRC(58356050) SHA1(f8fb5a14f4ec516093c785891b05d55ae345754e) ) // good
4462ROM_END
4463
4464ROM_START( danchih )
4465   STV_BIOS
4466
4467   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4468   ROM_LOAD16_WORD_SWAP( "mpr21974.7",    0x0200000, 0x0200000, CRC(e7472793) SHA1(11b7b11cf492eb9cf69b50e7cfac46a5b86849ac) )// good
4469   ROM_LOAD16_WORD_SWAP( "mpr21970.2",    0x0400000, 0x0400000, CRC(34dd7f4d) SHA1(d5c45da94ec5b6584049caf09516f1ad4ba3adb5) )// good
4470   ROM_LOAD16_WORD_SWAP( "mpr21971.3",    0x0800000, 0x0400000, CRC(8995158c) SHA1(fbbd171d67eebf43630d6054bc1b9132f6b38183) )// good
4471   ROM_LOAD16_WORD_SWAP( "mpr21972.4",    0x0c00000, 0x0400000, CRC(68a39090) SHA1(cff1b909c4191660570012eb5e4cb6a7467bc79e) )// good
4472   ROM_LOAD16_WORD_SWAP( "mpr21973.5",    0x1000000, 0x0400000, CRC(b0f23f14) SHA1(4e7076c29fd57bb3ef9af50a6104e39ecda94e06) )// good
4473ROM_END
4474
4475ROM_START( danchiq )
4476   STV_BIOS
4477
4478   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4479   ROM_LOAD16_WORD_SWAP( "ic22",    0x0200000, 0x0200000, CRC(e216bfc8) SHA1(7a08fa32281e272dbf5e7daea50a1800cc225c1b) )//ic 7
4480   ROM_LOAD16_WORD_SWAP( "ic24",    0x0400000, 0x0200000, CRC(b95aa5ac) SHA1(2766c5414643034a0f6d746050557516bd3753df) )//ic 2
4481   ROM_LOAD16_WORD_SWAP( "ic26",    0x0600000, 0x0200000, CRC(df6ebd48) SHA1(fcccafbee1b8b952b07ed0e7e86219eed9cf4a93) )
4482   ROM_LOAD16_WORD_SWAP( "ic28",    0x0800000, 0x0200000, CRC(cf6a2b76) SHA1(1f7522d446d57b78d099bae553133d5e7e54ff70) )//ic 3
4483   ROM_LOAD16_WORD_SWAP( "ic30",    0x0a00000, 0x0200000, CRC(0b6a9901) SHA1(b4c335199d3e49a9ae5d474b10130abc4718cdf9) )
4484   ROM_LOAD16_WORD_SWAP( "ic32",    0x0c00000, 0x0200000, CRC(0b4604f5) SHA1(547cba4a80baf126e87f87529aa933587643d359) )//ic 4
4485   ROM_LOAD16_WORD_SWAP( "ic34",    0x0e00000, 0x0200000, CRC(616e20fa) SHA1(45c175e79b5701db9726d157ff92eee368f4bbf9) )
4486   ROM_LOAD16_WORD_SWAP( "ic36",    0x1000000, 0x0200000, CRC(43474e08) SHA1(30b3ede287d5de93c6e0219bfd0a5d7ed5b6a958) )//ic 5
4487   ROM_LOAD16_WORD_SWAP( "ic23",    0x1200000, 0x0200000, CRC(d080eb71) SHA1(9c39b887697c8872f0cb655cff24282ad3b90e9b) )
4488   ROM_LOAD16_WORD_SWAP( "ic25",    0x1400000, 0x0200000, CRC(9a4109e5) SHA1(ba59caac5f5a80fc52c507d8a47f322a380aa9a1) )//(Untested)
4489ROM_END
4490
4491ROM_START( mausuke )
4492   STV_BIOS
4493
4494   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4495   ROM_LOAD16_BYTE(             "ic13.bin",      0x0000001, 0x0100000, CRC(b456f4cd) SHA1(91cbe703ec7c1dd45eb3b05bdfeb06e3570599d1) )
4496   ROM_RELOAD_PLAIN ( 0x0200000, 0x0100000 ) // needs the rom mapped here to appear 'normal'
4497   ROM_RELOAD_PLAIN ( 0x0300000, 0x0100000 )
4498
4499   ROM_LOAD16_WORD_SWAP( "mcj-00.2",      0x0400000, 0x0200000, CRC(4eeacd6f) SHA1(104ca230f22cd11cc536b34abd482e54791b4d0f) )// good
4500   ROM_LOAD16_WORD_SWAP( "mcj-01.3",      0x0800000, 0x0200000, CRC(365a494b) SHA1(29713dfc83a9ade63ebcc7994d14cd785c4500b9) )// good
4501   ROM_LOAD16_WORD_SWAP( "mcj-02.4",      0x0c00000, 0x0200000, CRC(8b8e4931) SHA1(0c94e2ccb72902d7786d1101a3958504f7151077) )// good
4502   ROM_LOAD16_WORD_SWAP( "mcj-03.5",      0x1000000, 0x0200000, CRC(9015a0e7) SHA1(8ba8a3723267e631169dc1e06620260fbccce4bd) )// good
4503   ROM_LOAD16_WORD_SWAP( "mcj-04.6",      0x1400000, 0x0200000, CRC(9d1beaee) SHA1(c63b61378860319fff2e605c7b9afaa5f1bc4cd2) )// good
4504   ROM_LOAD16_WORD_SWAP( "mcj-05.1",      0x1800000, 0x0200000, CRC(a7626a82) SHA1(c12a099132c5b9234a2de5674f3b8ba5fdd35289) )// good
4505   ROM_LOAD16_WORD_SWAP( "mcj-06.8",      0x1c00000, 0x0200000, CRC(1ab8e90e) SHA1(8e22f03c1791a983eb330b2a9199e5349a0b1baa) )// good
4506ROM_END
4507
4508/* acclaim game, not a standard cart ... */
4509ROM_START( batmanfr )
4510   STV_BIOS
4511
4512   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4513   /* Many thanks to Runik to point this out*/
4514   ROM_LOAD16_BYTE( "350-mpa1.u19",    0x0000000, 0x0100000, CRC(2a5a8c3a) SHA1(374ec55a39ea909cc672e4a629422681d1f2da05) )
4515   ROM_RELOAD(                         0x0200000, 0x0100000 )
4516   ROM_LOAD16_BYTE( "350-mpa1.u16",    0x0000001, 0x0100000, CRC(735e23ab) SHA1(133e2284a07a611aed8ada2707248f392f4509aa) )
4517   ROM_RELOAD(                         0x0200001, 0x0100000 )
4518   ROM_LOAD16_WORD_SWAP( "gfx0.u1",    0x0400000, 0x0400000, CRC(a82d0b7e) SHA1(37a7a177634d51620b1b43e58732987df166c7e6) )
4519   ROM_LOAD16_WORD_SWAP( "gfx1.u3",    0x0800000, 0x0400000, CRC(a41e55d9) SHA1(b896d3a6c36d325c3cece699da54f340a4512703) )
4520   ROM_LOAD16_WORD_SWAP( "gfx2.u5",    0x0c00000, 0x0400000, CRC(4c1ebeb7) SHA1(cdd139652d9484ae5837a39c2fd48d0a8d966d43) )
4521   ROM_LOAD16_WORD_SWAP( "gfx3.u8",    0x1000000, 0x0400000, CRC(f679a3e7) SHA1(db11b033b8bbdd80b81e3bc098bd40ad3a8784f2) )
4522   ROM_LOAD16_WORD_SWAP( "gfx4.u12",   0x1400000, 0x0400000, CRC(52d95242) SHA1(b554a95933c2be4c72fb4226d3bc4775695da2c1) )
4523   ROM_LOAD16_WORD_SWAP( "gfx5.u15",   0x1800000, 0x0400000, CRC(e201f830) SHA1(5aa22fcc8f2e153d1abc3aa4050c594b3942ee67) )
4524   ROM_LOAD16_WORD_SWAP( "gfx6.u18",   0x1c00000, 0x0400000, CRC(c6b381a3) SHA1(46431f1e47c084a0bf85535d35af27471653b008) )
4525
4526   /* it also has an extra adsp sound board, i guess this isn't tested */
4527   ROM_REGION( 0x080000, "wave", 0 ) /* Wave data */
4528   ROM_LOAD( "350snda1.u52",   0x000000, 0x080000, CRC(9027e7a0) SHA1(678df530838b078964a044ce734776f391654e6c) )
4529
4530   ROM_REGION( 0x800000, "adsp_code", 0 ) /* ADSP code */
4531   ROM_LOAD( "snd0.u48",   0x000000, 0x200000, CRC(02b1927c) SHA1(08b21d8b31b0f15c59fb5bb7eaf425e6fe04f7b5) )
4532   ROM_LOAD( "snd1.u49",   0x200000, 0x200000, CRC(58b18eda) SHA1(7f3105fe04d9c0cdfd76e3323f623a4d0f7dad06) )
4533   ROM_LOAD( "snd2.u50",   0x400000, 0x200000, CRC(51d626d6) SHA1(0e68b79dcb653dcba48121ca2d4f692f90afa85e) )
4534   ROM_LOAD( "snd3.u51",   0x600000, 0x200000, CRC(31af26ae) SHA1(2c9f4c078afec55964b5c2a4d00f5c43f2661a04) )
4535ROM_END
4536
4537/*
4538Critter Crusher EXP
4539Sega, 1995.
4540
4541This is a cart for Sega STV system. The game involves hitting 'critters' on
4542screen with a rubber/plastic hammer. The cab has a large LED display to show how many
4543'critters' were hit. The hammer positioning might work like a lightgun and the 'hitting'
4544may be like pulling the lightgun trigger?
4545
4546The ROM cart appears to be a re-used Virtua Fighter Remix cart??
4547On top there is one 27C040 EPROM, EPR-18821 @ IC13
45486 maskROMs, MPR-17945 to MPR-17950 (already dumped, known Virtua Fighter Remix ROMs)
4549On the other side of the PCB are 2 more maskROMs, MPR-18788 @ IC9 and MPR-18789 @ IC8
4550
4551*/
4552
4553ROM_START( critcrsh ) /* Must use Europe or Asia BIOS */
4554   STV_BIOS
4555   ROM_DEFAULT_BIOS( "euro" )
4556
4557   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4558   ROM_LOAD16_BYTE( "epr-18821.ic13",  0x0000001, 0x0080000, CRC(9a6658e2) SHA1(16dbae3d9ab584713afcb403f89fe71049609245) )
4559   ROM_RELOAD ( 0x0100001, 0x0080000 )
4560
4561//  ROM_LOAD16_WORD_SWAP( "mpr17946.2",    0x0400000, 0x0400000, CRC(4cb245f7) SHA1(363d9936b27043b5858c956a45736ac05aefc54e) ) // good
4562//  ROM_LOAD16_WORD_SWAP( "mpr17947.3",    0x0800000, 0x0400000, CRC(fef4a9fb) SHA1(1b4bd095962db769da17d3644df10f62d041e914) ) // good
4563//  ROM_LOAD16_WORD_SWAP( "mpr17948.4",    0x0c00000, 0x0400000, CRC(3e2b251a) SHA1(be6191c18727d7cbc6399fd4c1aaae59304af30c) ) // good
4564//  ROM_LOAD16_WORD_SWAP( "mpr17949.5",    0x1000000, 0x0400000, CRC(b2ecea25) SHA1(320c0e7ce34e81e2fe6400cbeb2cb3ca74426cc8) ) // good
4565//  ROM_LOAD16_WORD_SWAP( "mpr17950.6",    0x1400000, 0x0400000, CRC(5b1f981d) SHA1(693b5744d210a2ac8b77e7c8c87f07ca859f8aed) ) // good
4566//  ROM_LOAD16_WORD_SWAP( "mpr17945.1",    0x1800000, 0x0200000, CRC(03ede188) SHA1(849c7fab5b97e043fea3deb8df6cc195ccced0e0) ) // good
4567   ROM_LOAD16_WORD_SWAP( "mpr-18789.ic8", 0x1c00000, 0x0400000, CRC(b388616f) SHA1(0b2c5a547c3a6a8fb9f4ca54336cf6dc9adb8c6a) ) // good
4568   ROM_LOAD16_WORD_SWAP( "mpr-18788.ic9", 0x2000000, 0x0400000, CRC(feae5867) SHA1(7d2e47d5ab18700a246d53fdb7872a905cdac55a) ) // good
4569
4570   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
4571   ROM_LOAD( "critcrsh.nv", 0x0000, 0x0080, CRC(3da9860e) SHA1(05b315aa71fcfc4e617266e1c5e4954eccbf7854) )
4572ROM_END
4573
4574ROM_START( sfish2 )
4575//  STV_BIOS // - sports fishing 2 uses its own bios
4576
4577   ROM_REGION( 0x080000, "maincpu", 0 ) /* SH2 code */
4578   ROM_LOAD16_WORD_SWAP( "epr18343.bin",   0x000000, 0x080000, CRC(48e2eecf) SHA1(a38bfbd5f279525e413b18b5ed3f37f6e9e31cdc) ) /* sport fishing 2 bios */
4579   ROM_REGION( 0x080000, "slave", 0 ) /* SH2 code */
4580   ROM_COPY( "maincpu",0,0,0x080000)
4581
4582   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4583   ROM_LOAD(             "epr18427.bin",      0x0000000, 0x0100000, CRC(3f25bec8) SHA1(43a5342b882d5aec0f35a8777cb475659f43b1c4) )
4584   ROM_LOAD16_WORD_SWAP( "mpr18273.ic2",      0x0400000, 0x0200000, NO_DUMP )
4585   ROM_LOAD16_WORD_SWAP( "mpr18274.ic3",      0x0800000, 0x0200000, NO_DUMP )
4586   ROM_LOAD16_WORD_SWAP( "mpr18275.ic4",      0x0c00000, 0x0200000, NO_DUMP )
4587
4588   DISK_REGION( "cdrom" )
4589   DISK_IMAGE( "sfish2", 0, SHA1(a10073d83bbbe16e16f69ad48565821576557d61) )
4590ROM_END
4591
4592ROM_START( sfish2j )
4593//  STV_BIOS // - sports fishing 2 uses its own bios
4594
4595   ROM_REGION( 0x080000, "maincpu", 0 ) /* SH2 code */
4596   ROM_LOAD16_WORD_SWAP( "epr18343.bin",   0x000000, 0x080000, CRC(48e2eecf) SHA1(a38bfbd5f279525e413b18b5ed3f37f6e9e31cdc) ) /* sport fishing 2 bios */
4597   ROM_REGION( 0x080000, "slave", 0 ) /* SH2 code */
4598   ROM_COPY( "maincpu",0,0,0x080000)
4599
4600   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4601   ROM_LOAD16_BYTE(             "epr18344.a",      0x0000001, 0x0100000,  CRC(5a7de018) SHA1(88e0c2a9a9d4ebf699878c0aa9737af85f95ccf8) )
4602
4603   ROM_LOAD16_WORD_SWAP( "mpr18273.ic2",      0x0400000, 0x0200000, NO_DUMP )
4604   ROM_LOAD16_WORD_SWAP( "mpr18274.ic3",      0x0800000, 0x0200000, NO_DUMP )
4605
4606   DISK_REGION( "cdrom" )
4607   DISK_IMAGE( "sfish2", 0, SHA1(a10073d83bbbe16e16f69ad48565821576557d61) )
4608ROM_END
4609
4610
4611ROM_START( magzun )
4612   STV_BIOS
4613
4614   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4615   ROM_LOAD16_BYTE( "flash.ic13",               0x0000001, 0x0100000, CRC(e6f0aca0) SHA1(251d4d9c5a332d13af3a144c5eb9d8e7836bdd1b) ) // good
4616
4617   ROM_LOAD16_WORD_SWAP( "mpr-19354.ic2",    0x0400000, 0x0400000, CRC(a23822e7) SHA1(10ca5d39dcaaf35b80168a08d8a18d77fba1d2ce) ) // good
4618   ROM_LOAD16_WORD_SWAP( "mpr-19355.ic3",    0x0800000, 0x0400000, CRC(d70e5ebc) SHA1(2d560f6b6e693b2b91cf5ff5c4f0890cc2176f91) ) // good
4619   ROM_LOAD16_WORD_SWAP( "mpr-19356.ic4",    0x0c00000, 0x0400000, CRC(3bc43fe9) SHA1(f72b0f3208e2f411f4c9cc76c317a605acd32a67) ) // good
4620   ROM_LOAD16_WORD_SWAP( "mpr-19357.ic5",    0x1000000, 0x0400000, CRC(aa749370) SHA1(f09b0aa94fcc983419aaf2465dae5c9c64606158) ) // good
4621   ROM_LOAD16_WORD_SWAP( "mpr-19358.ic6",    0x1400000, 0x0400000, CRC(0969f1ec) SHA1(25b9671f0975172f283458d46e160080dd1d19e9) ) // good
4622   ROM_LOAD16_WORD_SWAP( "mpr-19359.ic1",    0x1800000, 0x0400000, CRC(b0d06f9c) SHA1(19e04c9c3a0bea5950aba8e1975962fa37722f32) ) // good
4623
4624   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 3 players
4625   ROM_LOAD( "magzun.nv", 0x0000, 0x0080, CRC(42700321) SHA1(1f2ba760c410312539c8677223edcd1cda3b51d4) )
4626ROM_END
4627
4628
4629ROM_START( stress )
4630   STV_BIOS
4631
4632   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4633   ROM_LOAD16_BYTE( "epr-21300a.ic13",    0x0000001, 0x0100000, CRC(899d829e) SHA1(b6c6da92dc108353998b29c0659d288645541519) ) // good
4634
4635   ROM_LOAD16_WORD_SWAP( "mpr-21290.ic2",    0x0400000, 0x0400000, CRC(a49d29f3) SHA1(8f6c26fd9e94a9e03dd0029026d205cf481fe151) ) // good
4636   ROM_LOAD16_WORD_SWAP( "mpr-21291.ic3",    0x0800000, 0x0400000, CRC(9452ba20) SHA1(8a9ff546901715f99bb911616c74ae30ebd7c6d7) ) // good
4637   ROM_LOAD16_WORD_SWAP( "mpr-21292.ic4",    0x0c00000, 0x0400000, CRC(f60268e2) SHA1(5c2febb94553a941a68e9611617750a89c82e783) ) // good
4638   ROM_LOAD16_WORD_SWAP( "mpr-21293.ic5",    0x1000000, 0x0400000, CRC(794946e0) SHA1(7881adb92fbf3efecb88f30834cdd1ed863b0b0e) ) // good
4639   ROM_LOAD16_WORD_SWAP( "mpr-21294.ic6",    0x1400000, 0x0400000, CRC(550843bb) SHA1(5e278a0ae60f7bee23b5f1ee10b8ce31effc9718) ) // good
4640   ROM_LOAD16_WORD_SWAP( "mpr-21289.ic1",    0x1800000, 0x0400000, CRC(c2ee8bea) SHA1(5fa0e6b492cc272c33b01adbef9233e6c8098827) ) // good
4641   ROM_LOAD16_WORD_SWAP( "mpr-21296.ic8",    0x1c00000, 0x0400000, CRC(b825c42a) SHA1(7c6f737b69b9283345f8fa23cb1d110b9b5f3d7e) ) // good
4642   ROM_LOAD16_WORD_SWAP( "mpr-21297.ic9",    0x2000000, 0x0400000, CRC(4bff7469) SHA1(8a36405a1a292d60b5918e604b460ed98740fae3) ) // good
4643   ROM_LOAD16_WORD_SWAP( "mpr-21298.ic10",   0x2400000, 0x0400000, CRC(68d07144) SHA1(5021f43d19105b484135ebddd3fa203233096c98) ) // good
4644   ROM_LOAD16_WORD_SWAP( "mpr-21299.ic11",   0x2800000, 0x0400000, CRC(ecc521c6) SHA1(f7ed4dd1cbe179652fdfdde34929b41a1fdcf9e2) ) // good
4645ROM_END
4646
4647/* the rom test for this is in 'each game test'  */
4648ROM_START( nclubv3 )
4649   STV_BIOS
4650
4651   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4652
4653   ROM_LOAD16_WORD_SWAP( "ic22",    0x0200000, 0x0200000, CRC(b4008ed0) SHA1(acb3784acad971eb5f4920760dc23a16330e7bad) ) // OK
4654   ROM_LOAD16_WORD_SWAP( "ic24",    0x0400000, 0x0200000, CRC(4e894850) SHA1(eb7c3399505a45816701197a45062b9f34e5a3e1) ) // OK
4655   ROM_LOAD16_WORD_SWAP( "ic26",    0x0600000, 0x0200000, CRC(5b6b023f) SHA1(cf17c5857d85d4326dfe2ce40cf96989f9f78ecd) ) // OK
4656   ROM_LOAD16_WORD_SWAP( "ic28",    0x0800000, 0x0200000, CRC(b7beab03) SHA1(de703e461a2bdd87b0695bd2f16e4c97d11bcf92) ) // OK
4657   ROM_LOAD16_WORD_SWAP( "ic30",    0x0a00000, 0x0200000, CRC(a9f81069) SHA1(60d88c7c20178a00d6927c37069ab0c374ebf51e) ) // OK
4658   ROM_LOAD16_WORD_SWAP( "ic32",    0x0c00000, 0x0200000, CRC(02708d66) SHA1(6881b0b05e55989953a16f6ba503ba891b849c07) ) // OK
4659   ROM_LOAD16_WORD_SWAP( "ic34",    0x0e00000, 0x0200000, CRC(c79d0537) SHA1(9d595f718ff8f8ff7ca88100f35c589d5f9b4216) ) // OK
4660   ROM_LOAD16_WORD_SWAP( "ic36",    0x1000000, 0x0200000, CRC(0c9df896) SHA1(4d8c18205e7aa90bfaa677ecff2b65128f2ad47c) ) // OK
4661   ROM_LOAD16_WORD_SWAP( "ic23",    0x1200000, 0x0200000, CRC(bd922829) SHA1(4c6f988173e439a05a77da043d856e142b0da831) ) // OK
4662   ROM_LOAD16_WORD_SWAP( "ic25",    0x1400000, 0x0200000, CRC(f77f9e24) SHA1(9a9636114e74c1fd7bd67db8005af02ef6a75ab1) ) // OK
4663
4664   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
4665   ROM_LOAD( "nclubv3.nv", 0x0000, 0x0080, CRC(9122a9e9) SHA1(5318994905e005567709c41449547c545182bece) )
4666ROM_END
4667
4668ROM_START( techbowl ) // set to 1p
4669   STV_BIOS
4670
4671   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4672
4673   ROM_LOAD16_WORD_SWAP( "ic22",    0x0200000, 0x0200000, CRC(5058db21) SHA1(eec908bbfb9ec0fdca0002e69f32c1c030086456) ) // OK
4674   ROM_LOAD16_WORD_SWAP( "ic24",    0x0400000, 0x0200000, CRC(34090f6d) SHA1(b8bc344ab826d5c9584afb01dba1c720b8dbc74d) ) // OK
4675   ROM_LOAD16_WORD_SWAP( "ic26",    0x0600000, 0x0200000, CRC(fb073352) SHA1(a5164aa5854ab3095f704ab73b6e4fb9ed0e0785) ) // OK
4676   ROM_LOAD16_WORD_SWAP( "ic28",    0x0800000, 0x0200000, CRC(530e0ceb) SHA1(8d14eb9dbf253a4563587d256a15492384e7ca5c) ) // OK
4677   ROM_LOAD16_WORD_SWAP( "ic30",    0x0a00000, 0x0200000, CRC(8d89877e) SHA1(7d76d48d64d7ac5411d714a4bb83f37e3e5b8df6) ) // OK
4678
4679   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
4680   ROM_LOAD( "techbowl.nv", 0x0000, 0x0080, CRC(5bebc2b7) SHA1(e189e891e1753059fbaad4ce82ddf191d5e8176a) )
4681ROM_END
4682
4683ROM_START( micrombc ) // set to 1p
4684   STV_BIOS
4685
4686   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4687
4688   ROM_LOAD16_WORD_SWAP( "ic22",    0x0200000, 0x0200000, CRC(8385bc45) SHA1(0bd60d7560cb2313d68470d0572850a7b8c501fd) ) // OK
4689   ROM_LOAD16_WORD_SWAP( "ic24",    0x0400000, 0x0200000, CRC(84ecb42f) SHA1(005dee9a0912d4b1b7f5157bc3cde96548c1e348) ) // OK
4690   ROM_LOAD16_WORD_SWAP( "ic26",    0x0600000, 0x0200000, CRC(869bc19c) SHA1(638125007d331beef567c976ea6f4e7a21acdb64) ) // OK
4691   ROM_LOAD16_WORD_SWAP( "ic28",    0x0800000, 0x0200000, CRC(0c3db354) SHA1(c4d43da7cea1b4d5ca3ac545afde10344a4a385b) ) // OK
4692   ROM_LOAD16_WORD_SWAP( "ic30",    0x0a00000, 0x0200000, CRC(03b9eacf) SHA1(d69c10f7613d9f52042dd6cce64e74e2b1ecc2d8) ) // OK
4693   ROM_LOAD16_WORD_SWAP( "ic32",    0x0c00000, 0x0200000, CRC(62c10626) SHA1(58cb0ca0330fa7a62b277ab0ff84bff65b81bb23) ) // OK
4694   ROM_LOAD16_WORD_SWAP( "ic34",    0x1000000, 0x0200000, CRC(8d89877e) SHA1(7d76d48d64d7ac5411d714a4bb83f37e3e5b8df6) ) // OK
4695   ROM_LOAD16_WORD_SWAP( "ic36",    0x1200000, 0x0200000, CRC(8d89877e) SHA1(7d76d48d64d7ac5411d714a4bb83f37e3e5b8df6) ) // OK
4696
4697   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
4698   ROM_LOAD( "micrombc.nv", 0x0000, 0x0080, CRC(6e89815f) SHA1(4478f614fb61859f4ee7bf55462f737387887e6f) )
4699ROM_END
4700
4701ROM_START( pclub2 ) // set to 1p / runs with the USA bios
4702   STV_BIOS
4703   ROM_DEFAULT_BIOS( "us" )
4704
4705   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4706
4707   ROM_LOAD16_WORD_SWAP( "ic22",    0x0200000, 0x0200000, CRC(d2ceade7) SHA1(a4300322e582f403d9207290f3900e1a72fcb9b9) ) // OK
4708   ROM_LOAD16_WORD_SWAP( "ic24",    0x0400000, 0x0200000, CRC(0e968c2d) SHA1(fbcc7533fcb6b87cd8255fc2d307ae618301ea64) ) // OK
4709   ROM_LOAD16_WORD_SWAP( "ic26",    0x0600000, 0x0200000, CRC(ab51da70) SHA1(85214aa805ffc9de59900dc0cd4e19e5ab756bf7) ) // OK
4710   ROM_LOAD16_WORD_SWAP( "ic28",    0x0800000, 0x0200000, CRC(3a654b2a) SHA1(7398e25836bfbdeab6350759f25c420c3b496172) ) // OK
4711   ROM_LOAD16_WORD_SWAP( "ic30",    0x0a00000, 0x0200000, CRC(8d89877e) SHA1(7d76d48d64d7ac5411d714a4bb83f37e3e5b8df6) ) // OK
4712
4713   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
4714   ROM_LOAD( "pclub2.nv", 0x0000, 0x0080, CRC(00d0f04e) SHA1(8b5a3e1c52e34443f83fd4a8948a00cacb5071d0) )
4715ROM_END
4716
4717ROM_START( pclub2v3 ) // set to 1p / runs with the USA bios
4718   STV_BIOS
4719   ROM_DEFAULT_BIOS( "us" )
4720
4721   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4722
4723   ROM_LOAD16_WORD_SWAP( "ic22",    0x0200000, 0x0200000, BAD_DUMP CRC(f88347aa) SHA1(3e9ca105edbd6ce11ea4194eb1733785e87f92b2) ) // BAD
4724   ROM_LOAD16_WORD_SWAP( "ic24",    0x0400000, 0x0200000, CRC(b5871198) SHA1(10d187eebcca5d70c5ae10d1a144685a96491126) ) // OK
4725   ROM_LOAD16_WORD_SWAP( "ic26",    0x0600000, 0x0200000, CRC(d97034ed) SHA1(a7a0f659eefd539b2a1fd70ef394eed30ea54c0c) ) // OK
4726   ROM_LOAD16_WORD_SWAP( "ic28",    0x0800000, 0x0200000, CRC(f1421506) SHA1(c384b695338144e5f051134bda73b059b678a7df) ) // OK
4727   ROM_LOAD16_WORD_SWAP( "ic30",    0x0a00000, 0x0200000, CRC(8d89877e) SHA1(7d76d48d64d7ac5411d714a4bb83f37e3e5b8df6) ) // OK (rom is blank?!)
4728
4729   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
4730   ROM_LOAD( "pclub2v3.nv", 0x0000, 0x0080, CRC(a8a2d30c) SHA1(bdde3d62ff21190a23698058ff66e476a75a09aa) )
4731ROM_END
4732
4733ROM_START( pclubpok ) // set to 1p / runs with the USA bios
4734   STV_BIOS
4735   ROM_DEFAULT_BIOS( "us" )
4736
4737   ROM_REGION32_BE( 0x3000000, "user1", ROMREGION_ERASE00 ) /* SH2 code */
4738
4739   ROM_LOAD16_WORD_SWAP( "ic22",    0x0200000, 0x0200000, CRC(48ab8371) SHA1(1c2124afad6bc1f4de2619e6b915f78e91addf05) ) // OK
4740   ROM_LOAD16_WORD_SWAP( "ic24",    0x0400000, 0x0200000, CRC(9915faea) SHA1(b96f64a8cbb1b9496bb566d0469975fddb4fbe98) ) // OK
4741   ROM_LOAD16_WORD_SWAP( "ic26",    0x0600000, 0x0200000, CRC(054ad120) SHA1(987e812af099bb0aa5d43a4c10ae8345370a2606) ) // OK
4742   ROM_LOAD16_WORD_SWAP( "ic28",    0x0800000, 0x0200000, CRC(3a654b2a) SHA1(7398e25836bfbdeab6350759f25c420c3b496172) ) // OK
4743   ROM_LOAD16_WORD_SWAP( "ic30",    0x0a00000, 0x0200000, CRC(98747bef) SHA1(8d452507a9842a48cd1a7db8fde11a070a6f068b) ) // OK
4744
4745   ROM_REGION16_BE( 0x80, "eeprom", 0 ) // preconfigured to 1 player
4746   ROM_LOAD( "pclubpok.nv", 0x0000, 0x0080, CRC(4ba3f21a) SHA1(898a393fb2fc1961b68b7d4f383d5447e6c010e8) )
4747ROM_END
4748
4749/*
4750country codes:
4751J = Japan
4752U = United States
4753E = Europe
4754T = Taiwan
4755B = Brazil
4756K = Korea
4757A = PAL Asia
4758L = Latin America
4759date codes:
4760(Original is yyyy/mm/dd,changed to reflect Capcom's one (yy/mm/dd))
4761Version codes:
4762V = Version(obviously ;)
4763(number before the dot) = game status (0=Sample,1=Master,2=Upgrade)
4764(number after the dot) = game version/release
4765There is also another internal code (called the "Product Number"),but AFAIK it's only used
4766by introdon in ST-V ("SG0000000"),and according to the manual it's even wrong! (SG is used
4767by Sega titles,and this is a Sunsoft game)It's likely to be a left-over...
4768*/
4769
4770static DRIVER_INIT( sanjeon )
4771{
4772   UINT8 *src    = machine.region       ( "user1" )->base();
4773   int x;
4774
4775   for (x=0;x<0x3000000;x++)
4776   {
4777      src[x] = src[x]^0xff;
4778
4779      src[x] = BITSWAP8(src[x],7,2,5,1,  3,6,4,0);
4780      src[x] = BITSWAP8(src[x],4,6,5,7,  3,2,1,0);
4781      src[x] = BITSWAP8(src[x],7,6,5,4,  2,3,1,0);
4782      src[x] = BITSWAP8(src[x],7,0,5,4,  3,2,1,6);
4783      src[x] = BITSWAP8(src[x],3,6,5,4,  7,2,1,0);
4784
4785   }
4786
4787
4788   DRIVER_INIT_CALL(sasissu);
4789}
4790
4791
4792
4793/*    YEAR  NAME        PARENT  COMPAT  MACHINE INPUT   INIT        COMPANY     FULLNAME            FLAGS */
4794CONS( 1994, saturn,     0,      0,      saturn, saturn, saturnus,   "Sega",     "Saturn (USA)",     GAME_NOT_WORKING )
4795CONS( 1994, saturnjp,   saturn, 0,      saturn, saturn, saturnjp,   "Sega",     "Saturn (Japan)",   GAME_NOT_WORKING )
4796CONS( 1994, saturneu,   saturn, 0,      saturn, saturn, saturneu,   "Sega",     "Saturn (PAL)",     GAME_NOT_WORKING )
4797CONS( 1995, vsaturn,    saturn, 0,      saturn, saturn, saturnjp,   "JVC",      "V-Saturn",         GAME_NOT_WORKING )
4798CONS( 1995, hisaturn,   saturn, 0,      saturn, saturn, saturnjp,   "Hitachi",  "HiSaturn",         GAME_NOT_WORKING )
4799
4800GAME( 1996, stvbios,   0, stv, stv,  stv,       ROT0,   "Sega",                      "ST-V Bios", GAME_IS_BIOS_ROOT )
4801
4802//GAME YEAR, NAME,     PARENT,  MACH, INP, INIT,      MONITOR
4803/* Playable */
4804GAME( 1998, astrass,   stvbios, stv, stv,      astrass,   ROT0,   "Sunsoft",                 "Astra SuperStars (J 980514 V1.002)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
4805GAME( 1995, bakubaku,  stvbios, stv, stv,      stv,       ROT0,   "Sega",                    "Baku Baku Animal (J 950407 V1.000)", GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
4806GAME( 1996, batmanfr,  stvbios, stv, batmanfr,   batmanfr,   ROT0,   "Acclaim",                 "Batman Forever (JUE 960507 V1.000)", GAME_NO_SOUND )
4807GAME( 1996, colmns97,  stvbios, stv, stv,      colmns97,   ROT0,   "Sega",                   "Columns '97 (JET 961209 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4808GAME( 1997, cotton2,   stvbios, stv, stv,      cotton2,   ROT0,   "Success",                 "Cotton 2 (JUET 970902 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4809GAME( 1998, cottonbm,  stvbios, stv, stv,      cottonbm,   ROT0,   "Success",                 "Cotton Boomerang (JUET 980709 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4810GAME( 1995, critcrsh,  stvbios, stv, critcrsh,   stv,      ROT0,   "Sega",                    "Critter Crusher (EA 951204 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4811GAME( 1999, danchih,   stvbios, stv, stvmp,      danchih,   ROT0,   "Altron (Tecmo license)",      "Danchi de Hanafuda (J 990607 V1.400)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4812GAME( 2000, danchiq,   stvbios, stv, stv,      danchih,   ROT0,   "Altron",                  "Danchi de Quiz Okusan Yontaku Desuyo! (J 001128 V1.200)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4813GAME( 1996, diehard,   stvbios, stv, stv,      diehard,   ROT0,   "Sega",                   "Die Hard Arcade (UET 960515 V1.000)", GAME_IMPERFECT_SOUND  )
4814GAME( 1996, dnmtdeka,  diehard, stv, stv,      dnmtdeka,   ROT0,   "Sega",                   "Dynamite Deka (J 960515 V1.000)", GAME_IMPERFECT_SOUND  )
4815GAME( 1995, ejihon,    stvbios, stv, stv,      stv,       ROT0,   "Sega",                   "Ejihon Tantei Jimusyo (J 950613 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4816GAME( 1995, fhboxers,  stvbios, stv, stv,      fhboxers,   ROT0,   "Sega",                   "Funky Head Boxers (JUETBKAL 951218 V1.000)", GAME_NO_SOUND | GAME_IMPERFECT_GRAPHICS )
4817GAME( 1994, gaxeduel,  stvbios, stv, stv,      gaxeduel,   ROT0,   "Sega",                    "Golden Axe - The Duel (JUETL 950117 V1.000)", GAME_IMPERFECT_SOUND )
4818GAME( 1998, grdforce,  stvbios, stv, stv,      grdforce,   ROT0,   "Success",                 "Guardian Force (JUET 980318 V0.105)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4819GAME( 1998, groovef,   stvbios, stv, stv,      groovef,   ROT0,   "Atlus",                   "Groove on Fight - Gouketsuji Ichizoku 3 (J 970416 V1.001)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4820GAME( 1997, hanagumi,  stvbios, stv, stv,      hanagumi,   ROT0,   "Sega",                    "Hanagumi Taisen Columns - Sakura Wars (J 971007 V1.010)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
4821GAME( 1996, introdon,  stvbios, stv, stv,      stv,       ROT0,   "Sunsoft / Success",         "Karaoke Quiz Intro Don Don! (J 960213 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4822GAME( 1995, kiwames,   stvbios, stv, stvmp,      stv,       ROT0,   "Athena",                  "Pro Mahjong Kiwame S (J 951020 V1.208)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4823GAME( 1997, maruchan,  stvbios, stv, stv,      maruchan,   ROT0,   "Sega / Toyosuisan",          "Maru-Chan de Goo! (J 971216 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4824GAME( 1996, mausuke,   stvbios, stv, stv,      mausuke,   ROT0,   "Data East",               "Mausuke no Ojama the World (J 960314 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4825GAME( 1998, myfairld,  stvbios, stv, stvmp,      stv,       ROT0,   "Micronet",                    "Virtual Mahjong 2 - My Fair Lady (J 980608 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4826GAME( 1998, othellos,  stvbios, stv, stv,      othellos,   ROT0,   "Success",                 "Othello Shiyouyo (J 980423 V1.002)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4827GAME( 1995, pblbeach,  stvbios, stv, stv,      pblbeach,   ROT0,   "T&E Soft",                    "Pebble Beach - The Great Shot (JUE 950913 V0.990)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4828GAME( 1996, prikura,   stvbios, stv, stv,      prikura,   ROT0,   "Atlus",                   "Princess Clara Daisakusen (J 960910 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4829GAME( 1996, puyosun,   stvbios, stv, stv,      puyosun,   ROT0,   "Compile",                 "Puyo Puyo Sun (J 961115 V0.001)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4830GAME( 1998, rsgun,     stvbios, stv, stv,      rsgun,     ROT0,   "Treasure",                "Radiant Silvergun (JUET 980523 V1.000)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
4831GAME( 1998, sasissu,   stvbios, stv, stv,      sasissu,   ROT0,   "Sega",                    "Taisen Tanto-R Sashissu!! (J 980216 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4832GAME( 1999, sanjeon,   sasissu, stv, stv,      sanjeon,   ROT0,   "Sega / Deniam",              "DaeJeon! SanJeon SuJeon (AJTUE 990412 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4833GAME( 1997, seabass,   stvbios, stv, stv,      seabass,   ROT0,   "A wave inc. (Able license)",   "Sea Bass Fishing (JUET 971110 V0.001)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4834GAME( 1995, shanhigw,  stvbios, stv, stv,      shanhigw,   ROT0,   "Sunsoft / Activision",       "Shanghai - The Great Wall / Shanghai Triple Threat (JUE 950623 V1.005)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4835GAME( 1997, shienryu,  stvbios, stv, stv,      shienryu,   ROT270, "Warashi",                 "Shienryu (JUET 961226 V1.000)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
4836GAME( 1998, sss,       stvbios, stv, stv,      sss,       ROT0,   "Capcom / Cave / Victor",      "Steep Slope Sliders (JUET 981110 V1.000)", GAME_IMPERFECT_SOUND )
4837GAME( 1995, sandor,    stvbios, stv, stv,      sandor,    ROT0,   "Sega",                    "Puzzle & Action: Sando-R (J 951114 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4838GAME( 1997, thunt,     sandor,  stv, stv,      thunt,     ROT0,   "Sega",                         "Puzzle & Action: Treasure Hunt (JUET 970901 V2.00E)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4839GAME( 1997, thuntk,    sandor,  stv, stv,      sandor,    ROT0,   "Sega / Deniam",              "Puzzle & Action: BoMulEul Chajara (JUET 970125 V2.00K)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4840GAME( 1996, sokyugrt,  stvbios, stv, stv,      sokyugrt,   ROT0,   "Raizing / Eighting",         "Soukyugurentai / Terra Diver (JUET 960821 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4841GAME( 1995, suikoenb,  stvbios, stv, stv,      suikoenb,   ROT0,   "Data East",                   "Suikoenbu / Outlaws of the Lost Dynasty (JUETL 950314 V2.001)", GAME_IMPERFECT_SOUND )
4842GAME( 1996, vfkids,    stvbios, stv, stv,      stv,       ROT0,   "Sega",                   "Virtua Fighter Kids (JUET 960319 V0.000)", GAME_IMPERFECT_SOUND )
4843GAME( 1997, winterht,  stvbios, stv, stv,      winterht,   ROT0,   "Sega",                   "Winter Heat (JUET 971012 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4844GAME( 1997, znpwfv,    stvbios, stv, stv,      znpwfv,    ROT0,   "Sega",                    "Zen Nippon Pro-Wrestling Featuring Virtua (J 971123 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4845
4846/* Almost */
4847GAME( 1997, vmahjong,  stvbios, stv, stvmp,      stv,       ROT0,   "Micronet",                    "Virtual Mahjong (J 961214 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4848GAME( 1998, twcup98,   stvbios, stv, stv,      twcup98,   ROT0,   "Tecmo",                       "Tecmo World Cup '98 (JUET 980410 V1.000)", GAME_UNEMULATED_PROTECTION | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS|GAME_NOT_WORKING ) // player movement
4849GAME( 1995, smleague,  stvbios, stv, stv,      smleague,   ROT0,   "Sega",                    "Super Major League (U 960108 V1.000)", GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4850GAME( 1995, finlarch,  smleague,stv, stv,      finlarch,   ROT0,   "Sega",                    "Final Arch (J 950714 V1.001)", GAME_NOT_WORKING | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4851GAME( 1998, elandore,  stvbios, stv, stv,      elandore,   ROT0,   "Sai-Mate",                "Touryuu Densetsu Elan-Doree / Elan Doree - Legend of Dragoon (JUET 980922 V1.006)", GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS )
4852
4853/* Unemulated printer device */
4854GAME( 1998, stress,    stvbios, stv, stv,      stv,       ROT0,   "Sega",                    "Stress Busters (J 981020 V1.000)", GAME_NOT_WORKING | GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND )
4855GAME( 1997, nclubv3,   stvbios, stv, stv,      nameclv3,   ROT0,   "Sega",                    "Name Club Ver.3 (J 970723 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS | GAME_NOT_WORKING )
4856GAME( 1997, pclub2,    stvbios, stv, stv,      stv,       ROT0,   "Atlus",                   "Print Club 2 (U 970921 V1.000)", GAME_NOT_WORKING )
4857GAME( 1999, pclub2v3,  pclub2,  stv, stv,      stv,       ROT0,   "Atlus",                   "Print Club 2 Vol. 3 (U 990310 V1.000)", GAME_NOT_WORKING )
4858GAME( 1999, pclubpok,  stvbios, stv, stv,       stv,        ROT0,   "Atlus",                        "Print Club Pokemon B (U 991126 V1.000)", GAME_NOT_WORKING )
4859
4860/* Doing something.. but not enough yet */
4861GAME( 1995, vfremix,   stvbios, stv, stv,      vfremix,   ROT0,   "Sega",                    "Virtua Fighter Remix (JUETBKAL 950428 V1.000)", GAME_IMPERFECT_SOUND | GAME_NOT_WORKING )
4862GAME( 1997, findlove,  stvbios, stv, stv,      stv,      ROT0,   "Daiki / FCF",               "Find Love (J 971212 V1.000)", GAME_IMPERFECT_SOUND | GAME_NOT_WORKING )
4863GAME( 1996, decathlt,  stvbios, stv, stv,      decathlt,   ROT0,   "Sega",                    "Decathlete (JUET 960709 V1.001)", GAME_NO_SOUND | GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION )
4864GAME( 1996, decathlto, decathlt,stv, stv,      decathlt,   ROT0,   "Sega",                    "Decathlete (JUET 960424 V1.000)", GAME_NO_SOUND | GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION )
4865
4866/* Gives I/O errors */
4867GAME( 1996, magzun,    stvbios, stv, stv,      stv,       ROT0,   "Sega",                    "Magical Zunou Power (J 961031 V1.000)", GAME_NOT_WORKING )
4868GAME( 1997, techbowl,  stvbios, stv, stv,      stv,       ROT0,   "Sega",                    "Technical Bowling (J 971212 V1.000)", GAME_NOT_WORKING )
4869GAME( 1999, micrombc,  stvbios, stv, stv,      stv,       ROT0,   "Sega",                    "Microman Battle Charge (J 990326 V1.000)", GAME_NOT_WORKING )
4870
4871/* Black screen */
4872GAME( 1999, ffreveng,  stvbios, stv, stv,      ffreveng,   ROT0,   "Capcom",                  "Final Fight Revenge (JUET 990714 V1.000)", GAME_UNEMULATED_PROTECTION | GAME_NO_SOUND | GAME_NOT_WORKING )
4873
4874/* CD games */
4875GAME( 1995, sfish2,    0,      stv, stv,      stv,      ROT0,   "Sega",                      "Sport Fishing 2 (UET 951106 V1.10e)", GAME_NO_SOUND | GAME_NOT_WORKING )
4876GAME( 1995, sfish2j,   sfish2,   stv, stv,      stv,      ROT0,   "Sega",                      "Sport Fishing 2 (J 951201 V1.100)", GAME_NO_SOUND | GAME_NOT_WORKING )
4877
4878/*
4879This is the known list of undumped ST-V games:
4880    Kiss Off (US version of mausuke)
4881    Baku Baku (US version of Baku Baku Animal,dunno if it exists for the ST-V)
4882    Sport Fishing
4883    Aroma Club
4884    Movie Club
4885    Name Club (other versions)
4886    Print Club 2 (other versions)
4887    Youen Denshi Mahjong Yuugi Gal Jan
4888    Danchi de Quiz: Okusan 4taku Desu yo!
4889    NBA Action (?)
4890    Quiz Omaeni Pipon Cho! (?)
4891Others may exist as well...
4892*/
4893
src/mess/mess.mak
r11292r11293
13541354   $(MESS_VIDEO)/mbc55x.o     \
13551355
13561356$(MESSOBJ)/sega.a:            \
1357   $(MESS_DRIVERS)/saturn.o   \
1357   $(MAME_DRIVERS)/saturn.o   \
13581358   $(MESS_VIDEO)/smsvdp.o      \
13591359   $(MESS_MACHINE)/sms.o      \
13601360   $(MESS_DRIVERS)/sms.o      \
src/mess/drivers/saturn.c
r11292r11293
1/* Sega Saturn
2
3Driver by David Haywood, Angelo Salese, Olivier Galibert & Mariusz Wojcieszek
4SCSP driver provided by R.Belmont,based on ElSemi's SCSP sound chip emulator
5CD Block driver provided by ANY, based on sthief original emulator
6Many thanks to Guru, Fabien & Runik for the help given.
7
8MESS conversion by R. Belmont
9
10Hardware overview:
11------------------
12-two SH-2 CPUs,in a master/slave configuration. The master cpu is used to
13boot-up and to do the most of the work,the slave one does extra work that could be
14too much for a single cpu. They both shares all the existent devices;
15-a M68000 CPU,used to drive sound(the SCSP chip).The program is uploaded via the
16SH-2 cpus;
17-a SMPC (System Manager & Peripheral Control),used to drive all the
18devices on the board;
19-a SCU (System Control Unit),mainly used to do DMA operations and to drive interrupts,it
20also has a DSP;
21-an (optional for the ST-V) SH-1 CPU,used to be the CD driver;
22-An A-Bus,where the cart ROM area is located;
23-A B-Bus,where the Video Hardware & the SCU sections are located;
24-Two VDPs chips(named as 1 & 2),used for the video section:
25 -VDP1 is used to render sprites & polygons.
26 -VDP2 is for the tilemap system,there are:
27 4 effective normal layers;
28 2 roz layers;
29 1 back layer;
30 1 line layer;
31 The VDP2 is capable of the following things (in order):
32 -dynamic resolution (up to 704x512) & various interlacing modes;
33 -mosaic process;
34 -scrolling,scaling,horizontal & vertical cell scrolling & linescroll for the
35  normal planes, the roz ones can also rotate;
36 -versatile window system,used for various effects;
37 -alpha-blending,refered as Color Calculation in the docs;
38 -shadow effects;
39 -global rgb brightness control,separate for every plane;
40
41Memory map:
42-----------
43
440x00000000, 0x0007ffff  BIOS ROM
450x00080000, 0x000fffff  Unused
460x00100000, 0x00100080  SMPC
470x00100080, 0x0017ffff  Unused
480x00180000, 0x0018ffff  Back Up Ram
490x00190000, 0x001fffff  Unused
500x00200000, 0x002fffff  Work Ram-L
510x00300000, 0x00ffffff  Unused
520x01000000, 0x01000003  MINIT
530x01000004, 0x017fffff  Unused
540x01800000, 0x01800003  SINIT
550x01800004, 0x01ffffff  Unused
560x02000000, 0x03ffffff  A-BUS CS0
570x04000000, 0x04ffffff  A-BUS CS1
580x05000000, 0x057fffff  A-BUS DUMMY
590x05800000, 0x058fffff  A-BUS CS2
600x05900000, 0x059fffff  Unused
610x05a00000, 0x05b00ee3  Sound Region
620x05b00ee4, 0x05bfffff  Unused
630x05c00000, 0x05cbffff  VDP 1
640x05cc0000, 0x05cfffff  Unused
650x05d00000, 0x05d00017  VDP 1 regs
660x05d00018, 0x05dfffff  Unused
670x05e00000, 0x05e7ffff  VDP2
680x05e80000, 0x05efffff  VDP2 Extra RAM,accessible thru the VRAMSZ register
690x05f00000, 0x05f00fff  VDP2 Color RAM
700x05f01000, 0x05f7ffff  Unused
710x05f80000  0x05f8011f  VDP2 regs
720x05f80120, 0x05fdffff  Unused
730x05fe0000, 0x05fe00cf  SCU regs
740x05fe00d0, 0x05ffffff  Unused
750x06000000, 0x060fffff  Work Ram-H
760x06100000, 0x07ffffff  Unused
77
78*the unused locations aren't known if they are really unused or not,needs verification,most
79of them seem just mirrors of the previous valid memory allocated.
80
81ToDo / Notes:
82-------------
83
84-To enter into an Advanced Test Mode,keep pressed the Test Button (F2) on the start-up.
85
86(Main issues)
87-complete the Master/Slave communication.
88-clean up the IC13 rom loading.
89-Clean-ups and split the various chips(SCU,SMPC)into their respective files.
90-CD block:complete it & add proper CD image support into MAME.
91-the Cart-Dev mode...we need the proper ST-V Cart-Dev bios to be dumped in order to
92 make this work,but probably this will never be done...
93-fix some strange sound cpu memory accesses,there are various issues about this.
94-finish the DSP core.
95-Complete the window system in VDP2 (Still in progress).
96-Add the RS232c interface (serial port),needed by fhboxers.
97-(PCB owners) check if the clocks documented in the manuals are really right for ST-V.
98-SCSP to master irq: see if there is a sound cpu mask bit.
99-Does the cpunum_set_clock really works?Investigate.
100-We need to check every game if can be completed or there are any hanging/crash/protection
101 issues on them.
102-Memo: Some tests done on the original & working PCB,to be implemented:
103 -The AD-Stick returns 0x00 or a similar value.
104 -The Ports E,F & G must return 0xff
105 -The regular BIOS tests (Memory Test) changes his background color at some point to
106  several gradients of red,green and blue.Current implementation remains black.I dunno
107  if this is a framebuffer write or a funky transparency issue (i.e TRANSPARENT_NONE
108  should instead show the back layer).
109 -RBG0 rotating can be checked on the "Advanced Test" menu thru the VDP1/VDP2 check.
110  It rotates clockwise IIRC.Also the ST-V logo when the game is in Multi mode rotates too.
111 -The MIDI communication check fails even on a ST-V board,somebody needs to check if there
112  is a MIDI port on the real PCB...
113
114(per-game issues)
115-groovef: hangs soon after loaded,caused by two memory addresses in the Work RAM-H range.
116 Kludged for now to work.
117-various: find idle skip if possible.
118-suikoenb/shanhigw + others: why do we get 2 credits on startup with sound enabled?
119-colmns97/puyosun/mausuke/cotton2/cottonbm: interrupt issues? we can't check the SCU mask
120 on SMPC or controls fail
121-mausuke/bakubaku/grdforce: need to sort out transparency on the colour mapped sprites
122-bakubaku/colmns97/vfkids: no sound? Caused by missing irq?
123-myfairld: Doesn't work with -sound enabled because of a sound ram check at relative
124 addresses of $700/$710/$720/$730,so I'm not removing the NOT_WORKING flag due of that.Also
125 Micronet programmers had the "great" idea to *not* use the ST-V input standards,infact
126 joystick panel is mapped with input_port(10) instead of input_port(2),so for now use
127 the mahjong panel instead.
128-kiwames: the VDP1 sprites refresh is too slow,causing the "Draw by request" mode to
129 flicker.Moved back to default ATM...
130-pblbeach: Sprites are offset, because it doesn't clear vdp1 local coordinates set by bios,
131 I guess that they are cleared when some vdp1 register is written (kludged for now)
132-decathlt: Is currently using a strange protection DMA abus control,and it uses some sort of RLE
133 compression/encryption that serves as a gfxdecode.
134-vmahjong: the vdp1 textures are too dark(women).
135-findlove: controls doesn't work?
136-Weird design choices:
137 introdon: has the working button as BUTTON2 and not BUTTON1
138 batmanfr: BUTTON1 isn't used at all.
139-seabass: Player sprite is corrupt/missing during movements,caused
140 by incomplete framebuffer switching.
141-sss: Missing backgrounds during gameplay. <- seems just too dark (night),probably
142 just the positioning isn't correct...
143-elandore: Polygons structures/textures aren't right in gameplay,known as protection
144 for the humans structures,imperfect VDP1 emulation for the dragons.
145-hanagumi: ending screens have corrupt graphics. (*untested*)
146-znpwfv: missing Gouraud shading on distorted sprites and polygons
147-znpwfv,twcup98: missing "two screens" mode in RBG emulation
148-batmanfr: Missing sound,caused by an extra ADSP chip which is on the cart.The CPU is a
149 ADSP-2181,and it's the same used by NBA Jam Extreme (ZN game).
150-twcup98: missing Tecmo logo
151-vfremix: hangs after second match
152-sokyugrt: gameplay seems to be not smooth, timing?
153-Here's the list of unmapped read/writes:
154*<all games>
155cpu #0 (PC=0000365C): unmapped program memory dword write to 057FFFFC = 000D0000 & FFFF0000
156cpu #0 (PC=00003654): unmapped program memory dword write to 057FFFFC = 000C0000 & FFFF0000
157*bakubaku:
158cpu #0 (PC=0601022E): unmapped program memory dword write to 02000000 = 00000000 & FFFFFFFF
159cpu #0 (PC=0601023A): unmapped program memory dword write to 02000000 = 00000000 & FFFFFFFF
160
161*/
162
163#include "emu.h"
164#include "cpu/m68000/m68000.h"
165#include "cpu/sh2/sh2.h"
166#include "machine/stvcd.h"
167#include "machine/scudsp.h"
168#include "sound/scsp.h"
169#include "imagedev/chd_cd.h"
170#include "imagedev/cartslot.h"
171#include "includes/stv.h"
172#include "coreutil.h"
173
174#define USE_SLAVE 1
175
176#ifdef MAME_DEBUG
177#define LOG_CDB  0
178#define LOG_SMPC 1
179#define LOG_SCU  0
180#define LOG_IRQ  0
181#else
182#define LOG_CDB  0
183#define LOG_SMPC 1
184#define LOG_SCU  0
185#define LOG_IRQ  0
186#endif
187
188#define MASTER_CLOCK_352 57272800
189#define MASTER_CLOCK_320 53748200
190
191/**************************************************************************************/
192/*to be added into a stv Header file,remember to remove all the static...*/
193#ifdef MESS
194UINT32* stv_workram_l;
195UINT32* stv_workram_h;
196int stv_enable_slave_sh2;
197int minit_boost,sinit_boost;
198attotime minit_boost_timeslice, sinit_boost_timeslice;
199#else
200extern UINT32* stv_workram_l;
201extern UINT32* stv_workram_h;
202extern int stv_enable_slave_sh2;
203extern int minit_boost,sinit_boost;
204extern attotime minit_boost_timeslice, sinit_boost_timeslice;
205#endif
206
207static UINT8 *smpc_ram;
208//static void stv_dump_ram(void);
209
210//UINT32* stv_backupram;
211static UINT16* scsp_regs;
212static UINT16* sound_ram;
213
214static int saturn_region;
215
216extern int stv_vblank,stv_hblank;
217/*SMPC stuff*/
218static UINT8 NMI_reset;
219static void system_reset(void);
220static UINT8 en_68k;
221/*SCU stuff*/
222static int     timer_0;         /* Counter for Timer 0 irq*/
223static int    timer_1;          /* Counter for Timer 1 irq*/
224/*Maybe add these in a struct...*/
225static UINT32 scu_src_0,      /* Source DMA lv 0 address*/
226           scu_src_1,      /* lv 1*/
227           scu_src_2,      /* lv 2*/
228           scu_dst_0,      /* Destination DMA lv 0 address*/
229           scu_dst_1,      /* lv 1*/
230           scu_dst_2,      /* lv 2*/
231           scu_src_add_0,   /* Source Addition for DMA lv 0*/
232           scu_src_add_1,   /* lv 1*/
233           scu_src_add_2,   /* lv 2*/
234           scu_dst_add_0,   /* Destination Addition for DMA lv 0*/
235           scu_dst_add_1,   /* lv 1*/
236           scu_dst_add_2;   /* lv 2*/
237static INT32  scu_size_0,      /* Transfer DMA size lv 0*/
238           scu_size_1,      /* lv 1*/
239           scu_size_2;      /* lv 2*/
240
241struct stv_irq_t
242{
243   UINT8 vblank_out;
244   UINT8 vblank_in;
245   UINT8 hblank_in;
246   UINT8 timer_0;
247   UINT8 timer_1;
248   UINT8 dsp_end;
249   UINT8 sound_req;
250   UINT8 smpc;
251   UINT8 pad;
252   UINT8 dma_end[3];
253   UINT8 dma_ill;
254   UINT8 vdp1_end;
255   UINT8 abus;
256}stv_irq;
257
258static void dma_direct_lv0(address_space *space);   /*DMA level 0 direct transfer function*/
259static void dma_direct_lv1(address_space *space);   /*DMA level 1 direct transfer function*/
260static void dma_direct_lv2(address_space *space);   /*DMA level 2 direct transfer function*/
261static void dma_indirect_lv0(address_space *space); /*DMA level 0 indirect transfer function*/
262static void dma_indirect_lv1(address_space *space); /*DMA level 1 indirect transfer function*/
263static void dma_indirect_lv2(address_space *space); /*DMA level 2 indirect transfer function*/
264
265//static int scanline;
266
267/*A-Bus IRQ checks,where they could be located these?*/
268#define ABUSIRQ(_irq_,_vector_) \
269   { cputag_set_input_line_and_vector(device->machine(), "maincpu", _irq_, HOLD_LINE , _vector_); }
270#if 0
271if(stv_scu[42] & 1)//IRQ ACK
272{
273   ABUSIRQ(7,0x50,0x00010000);
274   ABUSIRQ(7,0x51,0x00020000);
275   ABUSIRQ(7,0x52,0x00040000);
276   ABUSIRQ(7,0x53,0x00080000);
277   ABUSIRQ(4,0x54,0x00100000);
278   ABUSIRQ(4,0x55,0x00200000);
279   ABUSIRQ(4,0x56,0x00400000);
280   ABUSIRQ(4,0x57,0x00800000);
281   ABUSIRQ(1,0x58,0x01000000);
282   ABUSIRQ(1,0x59,0x02000000);
283   ABUSIRQ(1,0x5a,0x04000000);
284   ABUSIRQ(1,0x5b,0x08000000);
285   ABUSIRQ(1,0x5c,0x10000000);
286   ABUSIRQ(1,0x5d,0x20000000);
287   ABUSIRQ(1,0x5e,0x40000000);
288   ABUSIRQ(1,0x5f,0x80000000);
289}
290#endif
291
292/**************************************************************************************/
293
294/*
295
296CD Block / SH-1 Handling
297
298*/
299
300/* SMPC
301 System Manager and Peripheral Control
302
303*/
304/* SMPC Addresses
305
30600
30701 -w  Input Register 0 (IREG)
30802
30903 -w  Input Register 1
31004
31105 -w  Input Register 2
31206
31307 -w  Input Register 3
31408
31509 -w  Input Register 4
3160a
3170b -w  Input Register 5
3180c
3190d -w  Input Register 6
3200e
3210f
32210
32311
32412
32513
32614
32715
32816
32917
33018
33119
3321a
3331b
3341c
3351d
3361e
3371f -w  Command Register (COMREG)
33820
33921 r-  Output Register 0 (OREG)
34022
34123 r-  Output Register 1
34224
34325 r-  Output Register 2
34426
34527 r-  Output Register 3
34628
34729 r-  Output Register 4
3482a
3492b r-  Output Register 5
3502c
3512d r-  Output Register 6
3522e
3532f r-  Output Register 7
35430
35531 r-  Output Register 8
35632
35733 r-  Output Register 9
35834
35935 r-  Output Register 10
36036
36137 r-  Output Register 11
36238
36339 r-  Output Register 12
3643a
3653b r-  Output Register 13
3663c
3673d r-  Output Register 14
3683e
3693f r-  Output Register 15
37040
37141 r-  Output Register 16
37242
37343 r-  Output Register 17
37444
37545 r-  Output Register 18
37646
37747 r-  Output Register 19
37848
37949 r-  Output Register 20
3804a
3814b r-  Output Register 21
3824c
3834d r-  Output Register 22
3844e
3854f r-  Output Register 23
38650
38751 r-  Output Register 24
38852
38953 r-  Output Register 25
39054
39155 r-  Output Register 26
39256
39357 r-  Output Register 27
39458
39559 r-  Output Register 28
3965a
3975b r-  Output Register 29
3985c
3995d r-  Output Register 30
4005e
4015f r-  Output Register 31
40260
40361 r-  SR
40462
40563 rw  SF
40664
40765
40866
40967
41068
41169
4126a
4136b
4146c
4156d
4166e
4176f
41870
41971
42072
42173
42274
42375 rw PDR1
42476
42577 rw PDR2
42678
42779 -w DDR1
4287a
4297b -w DDR2
4307c
4317d -w IOSEL2/1
4327e
4337f -w EXLE2/1
434*/
435static UINT8 IOSEL1;
436static UINT8 IOSEL2;
437static UINT8 EXLE1;
438static UINT8 EXLE2;
439static UINT8 PDR1;
440static UINT8 PDR2;
441static int intback_stage = 0, smpcSR, pmode;
442static UINT8 SMEM[4];
443
444#define SH2_DIRECT_MODE_PORT_1 IOSEL1 = 1
445#define SH2_DIRECT_MODE_PORT_2 IOSEL2 = 1
446#define SMPC_CONTROL_MODE_PORT_1 IOSEL1 = 0
447#define SMPC_CONTROL_MODE_PORT_2 IOSEL2 = 0
448
449
450static void system_reset()
451{
452   /*Only backup ram and SMPC ram are retained after that this command is issued.*/
453   memset(stv_scu      ,0x00,0x000100);
454   memset(scsp_regs    ,0x00,0x001000);
455   memset(sound_ram    ,0x00,0x080000);
456   memset(stv_workram_h,0x00,0x100000);
457   memset(stv_workram_l,0x00,0x100000);
458   memset(stv_vdp2_regs,0x00,0x040000);
459   memset(stv_vdp2_vram,0x00,0x100000);
460   memset(stv_vdp2_cram,0x00,0x080000);
461   //vdp1
462   //A-Bus
463   /*Order is surely wrong but whatever...*/
464}
465
466static void smpc_intbackhelper(running_machine &machine)
467{
468   int pad;
469   static const char *const padnames[] = { "JOY1", "JOY2" };
470
471   if (intback_stage == 1)
472   {
473      intback_stage++;
474      return;
475   }
476
477   pad = input_port_read(machine, padnames[intback_stage-2]);
478
479//  if (LOG_SMPC) logerror("SMPC: providing PAD data for intback, pad %d\n", intback_stage-2);
480   smpc_ram[33] = 0xf1;   // no tap, direct connect
481   smpc_ram[35] = 0x02;   // saturn pad
482   smpc_ram[37] = pad>>8;
483   smpc_ram[39] = pad & 0xff;
484
485   if (intback_stage == 3)
486   {
487      smpcSR = (0x80 | pmode);   // pad 2, no more data, echo back pad mode set by intback
488   }
489   else
490   {
491      smpcSR = (0xe0 | pmode);   // pad 1, more data, echo back pad mode set by intback
492   }
493
494   intback_stage++;
495}
496
497static UINT8 stv_SMPC_r8(address_space *space, int offset)
498{
499   int return_data;
500
501   return_data = smpc_ram[offset];
502
503   if ((offset == 0x61))
504      return_data = smpcSR;
505
506   if (offset == 0x75)//PDR1 read
507   {
508      if (IOSEL1)
509      {
510         int hshake;
511
512         hshake = (PDR1>>5) & 3;
513
514         if (LOG_SMPC) logerror("SMPC: SH-2 direct mode, returning data for phase %d\n", hshake);
515
516         return_data = 0x9f;
517
518         switch (hshake)
519         {
520            case 0:
521               return_data = 0x90;
522//                  return_data = 0xf0 | ((input_port_read(space->machine(), "JOY1")>>4) & 0xf);
523               break;
524
525            case 1:
526//                  return_data = 0xf0 | ((input_port_read(space->machine(), "JOY1")>>12) & 0xf);
527               break;
528
529            case 2:
530//                  return_data = 0xf0 | ((input_port_read(space->machine(), "JOY1")>>8) & 0xf);
531               break;
532
533            case 3:
534               return_data = 0x94;
535//                  return_data = 0xf0 | (input_port_read(space->machine(), "JOY1")&0x8) | 0x4;
536               break;
537         }
538      }
539   }
540
541   if (offset == 0x77)//PDR2 read
542   {
543      return_data =  0xff; // | EEPROM_read_bit());
544   }
545
546   if (offset == 0x33) return_data = saturn_region;
547
548   if (LOG_SMPC) logerror ("cpu %s (PC=%08X) SMPC: Read from Byte Offset %02x (%d) Returns %02x\n", space->device().tag(), cpu_get_pc(&space->device()), offset, offset>>1, return_data);
549
550
551   return return_data;
552}
553
554static void stv_SMPC_w8(address_space *space, int offset, UINT8 data)
555{
556   system_time systime;
557   UINT8 last;
558   running_machine &machine = space->machine();
559
560   /* get the current date/time from the core */
561   machine.current_datetime(systime);
562
563  if (LOG_SMPC) logerror ("8-bit SMPC Write to Offset %02x (reg %d) with Data %02x (prev %02x)\n", offset, offset>>1, data, smpc_ram[offset]);
564
565//  if (offset == 0x7d) printf("IOSEL2 %d IOSEL1 %d\n", (data>>1)&1, data&1);
566
567   last = smpc_ram[offset];
568
569   if ((intback_stage > 0) && (offset == 1) && (((data ^ 0x80)&0x80) == (last&0x80)))
570   {
571      if (LOG_SMPC) logerror("SMPC: CONTINUE request, stage %d\n", intback_stage);
572      if (intback_stage != 3)
573      {
574         intback_stage = 2;
575      }
576      smpc_intbackhelper(machine);
577      cputag_set_input_line_and_vector(machine, "maincpu", 8, HOLD_LINE , 0x47);
578   }
579
580   if ((offset == 1) && (data & 0x40))
581   {
582      if (LOG_SMPC) logerror("SMPC: BREAK request\n");
583      intback_stage = 0;
584   }
585
586   smpc_ram[offset] = data;
587
588   if (offset == 0x75)   // PDR1
589   {
590      PDR1 = (data & smpc_ram[0x79]);
591   }
592
593   if (offset == 0x77)   // PDR2
594   {
595      PDR2 = (data & smpc_ram[0x7b]);
596   }
597
598   if(offset == 0x7d)
599   {
600      if(smpc_ram[0x7d] & 1)
601         SH2_DIRECT_MODE_PORT_1;
602      else
603         SMPC_CONTROL_MODE_PORT_1;
604
605      if(smpc_ram[0x7d] & 2)
606         SH2_DIRECT_MODE_PORT_2;
607      else
608         SMPC_CONTROL_MODE_PORT_2;
609   }
610
611   if(offset == 0x7f)
612   {
613      //enable PAD irq & VDP2 external latch for port 1/2
614      EXLE1 = smpc_ram[0x7f] & 1 ? 1 : 0;
615      EXLE2 = smpc_ram[0x7f] & 2 ? 1 : 0;
616      if(EXLE1 || EXLE2)
617         if(!(stv_scu[40] & 0x0100)) /*Pad irq*/
618         {
619            if(LOG_SMPC) logerror ("Interrupt: PAD irq, Vector 0x48 Level 0x08\n");
620            cputag_set_input_line_and_vector(machine, "maincpu", 8, HOLD_LINE , 0x48);
621         }
622   }
623
624   if (offset == 0x1f)
625   {
626      switch (data)
627      {
628         case 0x00:
629            if(LOG_SMPC) logerror ("SMPC: Master ON\n");
630            smpc_ram[0x5f]=0x00;
631            break;
632         //in theory 0x01 is for Master OFF,but obviously is not used.
633         case 0x02:
634            if(LOG_SMPC) logerror ("SMPC: Slave ON\n");
635            smpc_ram[0x5f]=0x02;
636            stv_enable_slave_sh2 = 1;
637            cputag_set_input_line(machine, "slave", INPUT_LINE_RESET, CLEAR_LINE);
638            break;
639         case 0x03:
640            if(LOG_SMPC) logerror ("SMPC: Slave OFF\n");
641            smpc_ram[0x5f]=0x03;
642            stv_enable_slave_sh2 = 0;
643            machine.scheduler().trigger(1000);
644            cputag_set_input_line(machine, "slave", INPUT_LINE_RESET, ASSERT_LINE);
645            break;
646         case 0x06:
647            if(LOG_SMPC) logerror ("SMPC: Sound ON\n");
648            /* wrong? */
649            smpc_ram[0x5f]=0x06;
650            cputag_set_input_line(machine, "audiocpu", INPUT_LINE_RESET, CLEAR_LINE);
651            en_68k = 1;
652            break;
653         case 0x07:
654            if(LOG_SMPC) logerror ("SMPC: Sound OFF\n");
655            cputag_set_input_line(machine, "audiocpu", INPUT_LINE_RESET, ASSERT_LINE);
656            en_68k = 0;
657            smpc_ram[0x5f]=0x07;
658            break;
659         /*CD (SH-1) ON/OFF,guess that this is needed for Sports Fishing games...*/
660         //case 0x08:
661         //case 0x09:
662         case 0x0d:
663            if(LOG_SMPC) logerror ("SMPC: System Reset\n");
664            smpc_ram[0x5f]=0x0d;
665            cputag_set_input_line(machine, "maincpu", INPUT_LINE_RESET, PULSE_LINE);
666            system_reset();
667            break;
668         case 0x0e:
669            if(LOG_SMPC) logerror ("SMPC: Change Clock to 352\n");
670            smpc_ram[0x5f]=0x0e;
671            machine.device("maincpu")->set_unscaled_clock(MASTER_CLOCK_352/2);
672            machine.device("slave")->set_unscaled_clock(MASTER_CLOCK_352/2);
673            machine.device("audiocpu")->set_unscaled_clock(MASTER_CLOCK_352/5);
674            cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE); // ff said this causes nmi, should we set a timer then nmi?
675            break;
676         case 0x0f:
677            if(LOG_SMPC) logerror ("SMPC: Change Clock to 320\n");
678            smpc_ram[0x5f]=0x0f;
679            machine.device("maincpu")->set_unscaled_clock(MASTER_CLOCK_320/2);
680            machine.device("slave")->set_unscaled_clock(MASTER_CLOCK_320/2);
681            machine.device("audiocpu")->set_unscaled_clock(MASTER_CLOCK_320/5);
682            cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE); // ff said this causes nmi, should we set a timer then nmi?
683            break;
684         /*"Interrupt Back"*/
685         case 0x10:
686                      if(LOG_SMPC) logerror ("SMPC: Status Acquire (IntBack)\n");
687            smpc_ram[0x5f]=0x10;
688            smpc_ram[0x21] = (0x80) | ((NMI_reset & 1) << 6);
689            smpc_ram[0x23] = dec_2_bcd(systime.local_time.year / 100);
690                smpc_ram[0x25] = dec_2_bcd(systime.local_time.year % 100);
691                smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month + 1);
692                smpc_ram[0x29] = dec_2_bcd(systime.local_time.mday);
693                smpc_ram[0x2b] = dec_2_bcd(systime.local_time.hour);
694                smpc_ram[0x2d] = dec_2_bcd(systime.local_time.minute);
695                smpc_ram[0x2f] = dec_2_bcd(systime.local_time.second);
696
697            smpc_ram[0x31]=0x00;  //?
698
699
700            smpc_ram[0x35]=0x00;
701            smpc_ram[0x37]=0x00;
702
703            smpc_ram[0x39] = SMEM[0];
704            smpc_ram[0x3b] = SMEM[1];
705            smpc_ram[0x3d] = SMEM[2];
706            smpc_ram[0x3f] = SMEM[3];
707
708            smpc_ram[0x41]=0xff;
709            smpc_ram[0x43]=0xff;
710            smpc_ram[0x45]=0xff;
711            smpc_ram[0x47]=0xff;
712            smpc_ram[0x49]=0xff;
713            smpc_ram[0x4b]=0xff;
714            smpc_ram[0x4d]=0xff;
715            smpc_ram[0x4f]=0xff;
716            smpc_ram[0x51]=0xff;
717            smpc_ram[0x53]=0xff;
718            smpc_ram[0x55]=0xff;
719            smpc_ram[0x57]=0xff;
720            smpc_ram[0x59]=0xff;
721            smpc_ram[0x5b]=0xff;
722            smpc_ram[0x5d]=0xff;
723
724            smpcSR = 0x60;      // peripheral data ready, no reset, etc.
725            pmode = smpc_ram[1]>>4;
726
727            intback_stage = 1;
728
729         //  /*This is for RTC,cartridge code and similar stuff...*/
730         //  if(!(stv_scu[40] & 0x0080)) /*System Manager(SMPC) irq*/ /* we can't check this .. breaks controls .. probably issues elsewhere? */
731            {
732//                  if(LOG_SMPC) logerror ("Interrupt: System Manager (SMPC) at scanline %04x, Vector 0x47 Level 0x08\n",scanline);
733               smpc_intbackhelper(machine);
734               cputag_set_input_line_and_vector(machine, "maincpu", 8, HOLD_LINE , 0x47);
735            }
736         break;
737         /* RTC write*/
738         case 0x16:
739            if(LOG_SMPC) logerror("SMPC: RTC write\n");
740            smpc_ram[0x2f] = smpc_ram[0x0d];
741            smpc_ram[0x2d] = smpc_ram[0x0b];
742            smpc_ram[0x2b] = smpc_ram[0x09];
743            smpc_ram[0x29] = smpc_ram[0x07];
744            smpc_ram[0x27] = smpc_ram[0x05];
745            smpc_ram[0x25] = smpc_ram[0x03];
746            smpc_ram[0x23] = smpc_ram[0x01];
747            smpc_ram[0x5f]=0x16;
748         break;
749         /* SMPC memory setting*/
750         case 0x17:
751            if(LOG_SMPC) logerror ("SMPC: memory setting\n");
752                SMEM[0] = smpc_ram[1];
753                SMEM[1] = smpc_ram[3];
754                SMEM[2] = smpc_ram[5];
755                SMEM[3] = smpc_ram[7];
756
757            smpc_ram[0x5f]=0x17;
758         break;
759         case 0x18:
760            if(LOG_SMPC) logerror ("SMPC: NMI request\n");
761            smpc_ram[0x5f]=0x18;
762            /*NMI is unconditionally requested?*/
763            cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE);
764            break;
765         case 0x19:
766            if(LOG_SMPC) logerror ("SMPC: NMI Enable\n");
767            smpc_ram[0x5f]=0x19;
768            NMI_reset = 0;
769            smpc_ram[0x21] = (0x80) | ((NMI_reset & 1) << 6);
770            break;
771         case 0x1a:
772            if(LOG_SMPC) logerror ("SMPC: NMI Disable\n");
773            smpc_ram[0x5f]=0x1a;
774            NMI_reset = 1;
775            smpc_ram[0x21] = (0x80) | ((NMI_reset & 1) << 6);
776
777            break;
778         default:
779            if(LOG_SMPC) logerror ("cpu %s (PC=%08X) SMPC: undocumented Command %02x\n", space->device().tag(), cpu_get_pc(&space->device()), data);
780      }
781
782      // we've processed the command, clear status flag
783      smpc_ram[0x63] = 0x00;
784      /*TODO:emulate the timing of each command...*/
785   }
786}
787
788
789static READ32_HANDLER ( stv_SMPC_r32 )
790{
791   int byte = 0;
792   int readdata = 0;
793   /* registers are all byte accesses, convert here */
794   offset = offset << 2; // multiply offset by 4
795
796   if (!(~mem_mask & 0xff000000))   { byte = 0; readdata = stv_SMPC_r8(space, offset+byte) << 24; }
797   if (!(~mem_mask & 0x00ff0000))   { byte = 1; readdata = stv_SMPC_r8(space, offset+byte) << 16; }
798   if (!(~mem_mask & 0x0000ff00))   { byte = 2; readdata = stv_SMPC_r8(space, offset+byte) << 8;  }
799   if (!(~mem_mask & 0x000000ff))   { byte = 3; readdata = stv_SMPC_r8(space, offset+byte) << 0;  }
800
801   return readdata;
802}
803
804
805static WRITE32_HANDLER ( stv_SMPC_w32 )
806{
807   int byte = 0;
808   int writedata = 0;
809   /* registers are all byte accesses, convert here so we can use the data more easily later */
810   offset = offset << 2; // multiply offset by 4
811
812   if (!(~mem_mask & 0xff000000))   { byte = 0; writedata = data >> 24; }
813   if (!(~mem_mask & 0x00ff0000))   { byte = 1; writedata = data >> 16; }
814   if (!(~mem_mask & 0x0000ff00))   { byte = 2; writedata = data >> 8;  }
815   if (!(~mem_mask & 0x000000ff))   { byte = 3; writedata = data >> 0;  }
816
817   writedata &= 0xff;
818
819   offset += byte;
820
821   stv_SMPC_w8(space, offset,writedata);
822}
823
824
825/*
826
827SCU Handling
828
829*/
830
831/**********************************************************************************
832SCU Register Table
833offset,relative address
834Registers are in long words.
835===================================================================================
8360     0000  Level 0 DMA Set Register
8371     0004
8382     0008
8393     000c
8404     0010
8415     0014
8426     0018
8437     001c
8448     0020  Level 1 DMA Set Register
8459     0024
84610    0028
84711    002c
84812    0030
84913    0034
85014    0038
85115    003c
85216    0040  Level 2 DMA Set Register
85317    0044
85418    0048
85519    004c
85620    0050
85721    0054
85822    0058
85923    005c
86024    0060  DMA Forced Stop
86125    0064
86226    0068
86327    006c
86428    0070  <Free>
86529    0074
86630    0078
86731    007c  DMA Status Register
86832    0080  DSP Program Control Port
86933    0084  DSP Program RAM Data Port
87034    0088  DSP Data RAM Address Port
87135    008c  DSP Data RAM Data Port
87236    0090  Timer 0 Compare Register
87337    0094  Timer 1 Set Data Register
87438    0098  Timer 1 Mode Register
87539    009c  <Free>
87640    00a0  Interrupt Mask Register
87741    00a4  Interrupt Status Register
87842    00a8  A-Bus Interrupt Acknowledge
87943    00ac  <Free>
88044    00b0  A-Bus Set Register
88145    00b4
88246    00b8  A-Bus Refresh Register
88347    00bc  <Free>
88448    00c0
88549    00c4  SCU SDRAM Select Register
88650    00c8  SCU Version Register
88751    00cc  <Free>
88852    00cf
889===================================================================================
890DMA Status Register(32-bit):
891xxxx xxxx x--- xx-- xx-- xx-- xx-- xx-- UNUSED
892---- ---- -x-- ---- ---- ---- ---- ---- DMA DSP-Bus access
893---- ---- --x- ---- ---- ---- ---- ---- DMA B-Bus access
894---- ---- ---x ---- ---- ---- ---- ---- DMA A-Bus access
895---- ---- ---- --x- ---- ---- ---- ---- DMA lv 1 interrupt
896---- ---- ---- ---x ---- ---- ---- ---- DMA lv 0 interrupt
897---- ---- ---- ---- --x- ---- ---- ---- DMA lv 2 in stand-by
898---- ---- ---- ---- ---x ---- ---- ---- DMA lv 2 in operation
899---- ---- ---- ---- ---- --x- ---- ---- DMA lv 1 in stand-by
900---- ---- ---- ---- ---- ---x ---- ---- DMA lv 1 in operation
901---- ---- ---- ---- ---- ---- --x- ---- DMA lv 0 in stand-by
902---- ---- ---- ---- ---- ---- ---x ---- DMA lv 0 in operation
903---- ---- ---- ---- ---- ---- ---- --x- DSP side DMA in stand-by
904---- ---- ---- ---- ---- ---- ---- ---x DSP side DMA in operation
905
906**********************************************************************************/
907/*
908DMA TODO:
909-Verify if there are any kind of bugs,do clean-ups,use better comments
910 and macroize for better reading...
911-Add timings(but how fast are each DMA?).
912-Add level priority & DMA status register.
913-Add DMA start factor conditions that are different than 7.
914-Add byte data type transfer.
915-Set boundaries.
916*/
917
918#define DIRECT_MODE(_lv_)         (!(stv_scu[5+(_lv_*8)] & 0x01000000))
919#define INDIRECT_MODE(_lv_)           (stv_scu[5+(_lv_*8)] & 0x01000000)
920#define DRUP(_lv_)                 (stv_scu[5+(_lv_*8)] & 0x00010000)
921#define DWUP(_lv_)                    (stv_scu[5+(_lv_*8)] & 0x00000100)
922
923#define DMA_STATUS            (stv_scu[31])
924/*These macros sets the various DMA status flags.*/
925#define D0MV_1   if(!(DMA_STATUS & 0x10))    DMA_STATUS^=0x10
926#define D1MV_1   if(!(DMA_STATUS & 0x100))   DMA_STATUS^=0x100
927#define D2MV_1   if(!(DMA_STATUS & 0x1000))  DMA_STATUS^=0x1000
928#define D0MV_0   if(DMA_STATUS & 0x10)       DMA_STATUS^=0x10
929#define D1MV_0   if(DMA_STATUS & 0x100)       DMA_STATUS^=0x100
930#define D2MV_0   if(DMA_STATUS & 0x1000)     DMA_STATUS^=0x1000
931
932static UINT32 scu_index_0,scu_index_1,scu_index_2;
933static UINT8 scsp_to_main_irq;
934
935static UINT32 scu_add_tmp;
936
937/*For area checking*/
938#define ABUS(_lv_)       ((scu_##_lv_ & 0x07ffffff) >= 0x02000000) && ((scu_##_lv_ & 0x07ffffff) <= 0x04ffffff)
939#define BBUS(_lv_)       ((scu_##_lv_ & 0x07ffffff) >= 0x05a00000) && ((scu_##_lv_ & 0x07ffffff) <= 0x05ffffff)
940#define VDP1_REGS(_lv_)  ((scu_##_lv_ & 0x07ffffff) >= 0x05d00000) && ((scu_##_lv_ & 0x07ffffff) <= 0x05dfffff)
941#define VDP2(_lv_)       ((scu_##_lv_ & 0x07ffffff) >= 0x05e00000) && ((scu_##_lv_ & 0x07ffffff) <= 0x05fdffff)
942#define WORK_RAM_L(_lv_) ((scu_##_lv_ & 0x07ffffff) >= 0x00200000) && ((scu_##_lv_ & 0x07ffffff) <= 0x002fffff)
943#define WORK_RAM_H(_lv_) ((scu_##_lv_ & 0x07ffffff) >= 0x06000000) && ((scu_##_lv_ & 0x07ffffff) <= 0x060fffff)
944#define SOUND_RAM(_lv_)  ((scu_##_lv_ & 0x07ffffff) >= 0x05a00000) && ((scu_##_lv_ & 0x07ffffff) <= 0x05afffff)
945
946static READ32_HANDLER( stv_scu_r32 )
947{
948   /*TODO: write only registers must return 0...*/
949   //popmessage("%02x",DMA_STATUS);
950   //if (offset == 23)
951   //{
952      //Super Major League reads here???
953   //}
954   if (offset == 31)
955   {
956      if(LOG_SCU) logerror("(PC=%08x) DMA status reg read\n",cpu_get_pc(&space->device()));
957      return stv_scu[offset];
958   }
959   // Saturn BIOS needs this (need to investigate further)
960   else if (offset == 32)
961   {
962      return 0x00100000;
963   }
964   else if ( offset == 35 )
965   {
966        if(LOG_SCU) logerror( "DSP mem read at %08X\n", stv_scu[34]);
967        return dsp_ram_addr_r();
968    }
969    else if( offset == 41) /*IRQ reg status read*/
970    {
971      if(LOG_SCU) logerror("(PC=%08x) IRQ status reg read %08x\n",cpu_get_pc(&space->device()),mem_mask);
972
973      stv_scu[41] = (stv_irq.vblank_in & 1)<<0;
974      stv_scu[41]|= (stv_irq.vblank_out & 1)<<1;
975      stv_scu[41]|= (stv_irq.hblank_in & 1)<<2;
976      stv_scu[41]|= (stv_irq.timer_0 & 1)<<3;
977      stv_scu[41]|= (stv_irq.timer_1 & 1)<<4;
978      stv_scu[41]|= (stv_irq.dsp_end & 1)<<5;
979      stv_scu[41]|= (stv_irq.sound_req & 1)<<6;
980      stv_scu[41]|= (stv_irq.smpc & 1)<<7;
981      stv_scu[41]|= (stv_irq.pad & 1)<<8;
982      stv_scu[41]|= (stv_irq.dma_end[0] & 1)<<9;
983      stv_scu[41]|= (stv_irq.dma_end[1] & 1)<<10;
984      stv_scu[41]|= (stv_irq.dma_end[2] & 1)<<11;
985      stv_scu[41]|= (stv_irq.dma_ill & 1)<<12;
986      stv_scu[41]|= (stv_irq.vdp1_end & 1)<<13;
987      stv_scu[41]|= (stv_irq.abus & 1)<<15;
988
989      return stv_scu[41] ^ 0xffffffff;
990   }
991   else if( offset == 50 )
992   {
993      logerror("(PC=%08x) SCU version reg read\n",cpu_get_pc(&space->device()));
994      return 0x00000000;/*SCU Version 0*/
995   }
996    else
997    {
998       if(LOG_SCU) logerror("(PC=%08x) SCU reg read at %d = %08x\n",cpu_get_pc(&space->device()),offset,stv_scu[offset]);
999       return stv_scu[offset];
1000   }
1001}
1002
1003static WRITE32_HANDLER( stv_scu_w32 )
1004{
1005   COMBINE_DATA(&stv_scu[offset]);
1006
1007   switch(offset)
1008   {
1009      /*LV 0 DMA*/
1010      case 0:   scu_src_0  = ((stv_scu[0] & 0x07ffffff) >> 0); break;
1011      case 1:   scu_dst_0  = ((stv_scu[1] & 0x07ffffff) >> 0); break;
1012      case 2: scu_size_0 = ((stv_scu[2] & 0x000fffff) >> 0); break;
1013      case 3:
1014         /*Read address add value for DMA lv 0*/
1015         if(stv_scu[3] & 0x100)
1016            scu_src_add_0 = 4;
1017         else
1018            scu_src_add_0 = 1;
1019
1020         /*Write address add value for DMA lv 0*/
1021         switch(stv_scu[3] & 7)
1022         {
1023            case 0: scu_dst_add_0 = 2;   break;
1024            case 1: scu_dst_add_0 = 4;   break;
1025            case 2: scu_dst_add_0 = 8;   break;
1026            case 3: scu_dst_add_0 = 16;  break;
1027            case 4: scu_dst_add_0 = 32;  break;
1028            case 5: scu_dst_add_0 = 64;  break;
1029            case 6: scu_dst_add_0 = 128; break;
1030            case 7: scu_dst_add_0 = 256; break;
1031         }
1032         break;
1033      case 4:
1034/*
1035-stv_scu[4] bit 0 is DMA starting bit.
1036    Used when the start factor is 7.Toggle after execution.
1037-stv_scu[4] bit 8 is DMA Enable bit.
1038    This is an execution mask flag.
1039-stv_scu[5] bit 0,bit 1 and bit 2 is DMA starting factor.
1040    It must be 7 for this specific condition.
1041-stv_scu[5] bit 24 is Indirect Mode/Direct Mode (0/1).
1042*/
1043      if(stv_scu[4] & 1 && ((stv_scu[5] & 7) == 7) && stv_scu[4] & 0x100)
1044      {
1045         if(DIRECT_MODE(0)) { dma_direct_lv0(space); }
1046         else            { dma_indirect_lv0(space); }
1047
1048         stv_scu[4]^=1;//disable starting bit.
1049
1050         /*Sound IRQ*/
1051         if(/*(!(stv_scu[40] & 0x40)) &&*/ scsp_to_main_irq == 1)
1052         {
1053            //cputag_set_input_line_and_vector(space->machine(), "maincpu", 9, HOLD_LINE , 0x46);
1054            logerror("SCSP: Main CPU interrupt\n");
1055            #if 0
1056            if((scu_dst_0 & 0x7ffffff) != 0x05a00000)
1057            {
1058               if(!(stv_scu[40] & 0x1000))
1059               {
1060                  cputag_set_input_line_and_vector(space->machine(), "maincpu", 3, HOLD_LINE, 0x4c);
1061                  logerror("SCU: Illegal DMA interrupt\n");
1062               }
1063            }
1064            #endif
1065         }
1066      }
1067      break;
1068      case 5:
1069      if(INDIRECT_MODE(0))
1070      {
1071         if(LOG_SCU) logerror("Indirect Mode DMA lv 0 set\n");
1072         if(!DWUP(0)) scu_index_0 = scu_dst_0;
1073      }
1074
1075      /*Start factor enable bits,bit 2,bit 1 and bit 0*/
1076      if((stv_scu[5] & 7) != 7)
1077         if(LOG_SCU) logerror("Start factor chosen for lv 0 = %d\n",stv_scu[5] & 7);
1078      break;
1079      /*LV 1 DMA*/
1080      case 8:    scu_src_1  = ((stv_scu[8] &  0x07ffffff) >> 0);  break;
1081      case 9:    scu_dst_1  = ((stv_scu[9] &  0x07ffffff) >> 0);  break;
1082      case 10: scu_size_1 = ((stv_scu[10] & 0x00001fff) >> 0);  break;
1083      case 11:
1084      /*Read address add value for DMA lv 1*/
1085      if(stv_scu[11] & 0x100)
1086         scu_src_add_1 = 4;
1087      else
1088         scu_src_add_1 = 1;
1089
1090      /*Write address add value for DMA lv 1*/
1091      switch(stv_scu[11] & 7)
1092      {
1093         case 0: scu_dst_add_1 = 2;   break;
1094         case 1: scu_dst_add_1 = 4;   break;
1095         case 2: scu_dst_add_1 = 8;   break;
1096         case 3: scu_dst_add_1 = 16;  break;
1097         case 4: scu_dst_add_1 = 32;  break;
1098         case 5: scu_dst_add_1 = 64;  break;
1099         case 6: scu_dst_add_1 = 128; break;
1100         case 7: scu_dst_add_1 = 256; break;
1101      }
1102      break;
1103      case 12:
1104      if(stv_scu[12] & 1 && ((stv_scu[13] & 7) == 7) && stv_scu[12] & 0x100)
1105      {
1106         if(DIRECT_MODE(1)) { dma_direct_lv1(space); }
1107         else            { dma_indirect_lv1(space); }
1108
1109         stv_scu[12]^=1;
1110
1111         /*Sound IRQ*/
1112         if(/*(!(stv_scu[40] & 0x40)) &&*/ scsp_to_main_irq == 1)
1113         {
1114            //cputag_set_input_line_and_vector(space->machine(), "maincpu", 9, HOLD_LINE , 0x46);
1115            logerror("SCSP: Main CPU interrupt\n");
1116         }
1117      }
1118      break;
1119      case 13:
1120      if(INDIRECT_MODE(1))
1121      {
1122         if(LOG_SCU) logerror("Indirect Mode DMA lv 1 set\n");
1123         if(!DWUP(1)) scu_index_1 = scu_dst_1;
1124      }
1125
1126      if((stv_scu[13] & 7) != 7)
1127         if(LOG_SCU) logerror("Start factor chosen for lv 1 = %d\n",stv_scu[13] & 7);
1128      break;
1129      /*LV 2 DMA*/
1130      case 16: scu_src_2  = ((stv_scu[16] & 0x07ffffff) >> 0);  break;
1131      case 17: scu_dst_2  = ((stv_scu[17] & 0x07ffffff) >> 0);  break;
1132      case 18: scu_size_2 = ((stv_scu[18] & 0x00001fff) >> 0);  break;
1133      case 19:
1134      /*Read address add value for DMA lv 2*/
1135      if(stv_scu[19] & 0x100)
1136         scu_src_add_2 = 4;
1137      else
1138         scu_src_add_2 = 1;
1139
1140      /*Write address add value for DMA lv 2*/
1141      switch(stv_scu[19] & 7)
1142      {
1143         case 0: scu_dst_add_2 = 2;   break;
1144         case 1: scu_dst_add_2 = 4;   break;
1145         case 2: scu_dst_add_2 = 8;   break;
1146         case 3: scu_dst_add_2 = 16;  break;
1147         case 4: scu_dst_add_2 = 32;  break;
1148         case 5: scu_dst_add_2 = 64;  break;
1149         case 6: scu_dst_add_2 = 128; break;
1150         case 7: scu_dst_add_2 = 256; break;
1151      }
1152      break;
1153      case 20:
1154      if(stv_scu[20] & 1 && ((stv_scu[21] & 7) == 7) && stv_scu[20] & 0x100)
1155      {
1156         if(DIRECT_MODE(2)) { dma_direct_lv2(space); }
1157         else            { dma_indirect_lv2(space); }
1158
1159         stv_scu[20]^=1;
1160
1161         /*Sound IRQ*/
1162         if(/*(!(stv_scu[40] & 0x40)) &&*/ scsp_to_main_irq == 1)
1163         {
1164            //cputag_set_input_line_and_vector(space->machine(), "maincpu", 9, HOLD_LINE , 0x46);
1165            logerror("SCSP: Main CPU interrupt\n");
1166         }
1167      }
1168      break;
1169      case 21:
1170      if(INDIRECT_MODE(2))
1171      {
1172         if(LOG_SCU) logerror("Indirect Mode DMA lv 2 set\n");
1173         if(!DWUP(2)) scu_index_2 = scu_dst_2;
1174      }
1175
1176      if((stv_scu[21] & 7) != 7)
1177         if(LOG_SCU) logerror("Start factor chosen for lv 2 = %d\n",stv_scu[21] & 7);
1178      break;
1179      case 24:
1180      if(LOG_SCU) logerror("DMA Forced Stop Register set = %02x\n",stv_scu[24]);
1181      break;
1182      case 31: if(LOG_SCU) logerror("Warning: DMA status WRITE! Offset %02x(%d)\n",offset*4,offset); break;
1183      /*DSP section*/
1184      /*Use functions so it is easier to work out*/
1185      case 32:
1186      dsp_prg_ctrl(space, data);
1187      if(LOG_SCU) logerror("SCU DSP: Program Control Port Access %08x\n",data);
1188      break;
1189      case 33:
1190      dsp_prg_data(data);
1191      if(LOG_SCU) logerror("SCU DSP: Program RAM Data Port Access %08x\n",data);
1192      break;
1193      case 34:
1194      dsp_ram_addr_ctrl(data);
1195      if(LOG_SCU) logerror("SCU DSP: Data RAM Address Port Access %08x\n",data);
1196      break;
1197      case 35:
1198      dsp_ram_addr_w(data);
1199      if(LOG_SCU) logerror("SCU DSP: Data RAM Data Port Access %08x\n",data);
1200      break;
1201      case 36: if(LOG_SCU) logerror("timer 0 compare data = %03x\n",stv_scu[36]);break;
1202      case 37: if(LOG_SCU) logerror("timer 1 set data = %08x\n",stv_scu[37]); break;
1203      case 38: if(LOG_SCU) logerror("timer 1 mode data = %08x\n",stv_scu[38]); break;
1204      case 40:
1205      /*An interrupt is masked when his specific bit is 1.*/
1206      /*Are bit 16-bit 31 for External A-Bus irq mask like the status register?*/
1207
1208      stv_irq.vblank_in =  (((stv_scu[40] & 0x0001)>>0) ^ 1);
1209      stv_irq.vblank_out = (((stv_scu[40] & 0x0002)>>1) ^ 1);
1210      stv_irq.hblank_in =  (((stv_scu[40] & 0x0004)>>2) ^ 1);
1211      stv_irq.timer_0 =    (((stv_scu[40] & 0x0008)>>3) ^ 1);
1212      stv_irq.timer_1 =    (((stv_scu[40] & 0x0010)>>4) ^ 1);
1213      stv_irq.dsp_end =    (((stv_scu[40] & 0x0020)>>5) ^ 1);
1214      stv_irq.sound_req =  (((stv_scu[40] & 0x0040)>>6) ^ 1);
1215      stv_irq.smpc =       (((stv_scu[40] & 0x0080)>>7)); //NOTE: SCU bug
1216      stv_irq.pad =        (((stv_scu[40] & 0x0100)>>8) ^ 1);
1217      stv_irq.dma_end[2] = (((stv_scu[40] & 0x0200)>>9) ^ 1);
1218      stv_irq.dma_end[1] = (((stv_scu[40] & 0x0400)>>10) ^ 1);
1219      stv_irq.dma_end[0] = (((stv_scu[40] & 0x0800)>>11) ^ 1);
1220      stv_irq.dma_ill =    (((stv_scu[40] & 0x1000)>>12) ^ 1);
1221      stv_irq.vdp1_end =   (((stv_scu[40] & 0x2000)>>13) ^ 1);
1222      stv_irq.abus =       (((stv_scu[40] & 0x8000)>>15) ^ 1);
1223
1224      /*Take out the common settings to keep logging quiet.*/
1225      if(stv_scu[40] != 0xfffffffe &&
1226         stv_scu[40] != 0xfffffffc &&
1227         stv_scu[40] != 0xffffffff)
1228      {
1229         if(LOG_SCU) logerror("cpu %s (PC=%08X) IRQ mask reg set %08x = %d%d%d%d|%d%d%d%d|%d%d%d%d|%d%d%d%d\n",
1230         space->device().tag(), cpu_get_pc(&space->device()),
1231         stv_scu[offset],
1232         stv_scu[offset] & 0x8000 ? 1 : 0, /*A-Bus irq*/
1233         stv_scu[offset] & 0x4000 ? 1 : 0, /*<reserved>*/
1234         stv_scu[offset] & 0x2000 ? 1 : 0, /*Sprite draw end irq(VDP1)*/
1235         stv_scu[offset] & 0x1000 ? 1 : 0, /*Illegal DMA irq*/
1236         stv_scu[offset] & 0x0800 ? 1 : 0, /*Lv 0 DMA end irq*/
1237         stv_scu[offset] & 0x0400 ? 1 : 0, /*Lv 1 DMA end irq*/
1238         stv_scu[offset] & 0x0200 ? 1 : 0, /*Lv 2 DMA end irq*/
1239         stv_scu[offset] & 0x0100 ? 1 : 0, /*PAD irq*/
1240         stv_scu[offset] & 0x0080 ? 1 : 0, /*System Manager(SMPC) irq*/
1241         stv_scu[offset] & 0x0040 ? 1 : 0, /*Snd req*/
1242         stv_scu[offset] & 0x0020 ? 1 : 0, /*DSP irq end*/
1243         stv_scu[offset] & 0x0010 ? 1 : 0, /*Timer 1 irq*/
1244         stv_scu[offset] & 0x0008 ? 1 : 0, /*Timer 0 irq*/
1245         stv_scu[offset] & 0x0004 ? 1 : 0, /*HBlank-IN*/
1246         stv_scu[offset] & 0x0002 ? 1 : 0, /*VBlank-OUT*/
1247         stv_scu[offset] & 0x0001 ? 1 : 0);/*VBlank-IN*/
1248      }
1249      break;
1250      /*Interrupt Control reg Set*/
1251      case 41:
1252      /*This is r/w by introdon...*/
1253      if(LOG_SCU) logerror("IRQ status reg set:%08x %08x\n",stv_scu[41],mem_mask);
1254
1255      stv_irq.vblank_in =  ((stv_scu[41] & 0x0001)>>0);
1256      stv_irq.vblank_out = ((stv_scu[41] & 0x0002)>>1);
1257      stv_irq.hblank_in =  ((stv_scu[41] & 0x0004)>>2);
1258      stv_irq.timer_0 =    ((stv_scu[41] & 0x0008)>>3);
1259      stv_irq.timer_1 =    ((stv_scu[41] & 0x0010)>>4);
1260      stv_irq.dsp_end =    ((stv_scu[41] & 0x0020)>>5);
1261      stv_irq.sound_req =  ((stv_scu[41] & 0x0040)>>6);
1262      stv_irq.smpc =       ((stv_scu[41] & 0x0080)>>7);
1263      stv_irq.pad =        ((stv_scu[41] & 0x0100)>>8);
1264      stv_irq.dma_end[2] = ((stv_scu[41] & 0x0200)>>9);
1265      stv_irq.dma_end[1] = ((stv_scu[41] & 0x0400)>>10);
1266      stv_irq.dma_end[0] = ((stv_scu[41] & 0x0800)>>11);
1267      stv_irq.dma_ill =    ((stv_scu[41] & 0x1000)>>12);
1268      stv_irq.vdp1_end =   ((stv_scu[41] & 0x2000)>>13);
1269      stv_irq.abus =       ((stv_scu[41] & 0x8000)>>15);
1270
1271      break;
1272      case 42: if(LOG_SCU) logerror("A-Bus IRQ ACK %08x\n",stv_scu[42]); break;
1273      case 49: if(LOG_SCU) logerror("SCU SDRAM set: %02x\n",stv_scu[49]); break;
1274      default: if(LOG_SCU) logerror("Warning: unused SCU reg set %d = %08x\n",offset,data);
1275   }
1276}
1277
1278/*Lv 0 DMA end irq*/
1279static TIMER_CALLBACK( dma_lv0_ended )
1280{
1281   cputag_set_input_line_and_vector(machine, "maincpu", 5, (stv_irq.dma_end[0]) ? HOLD_LINE : CLEAR_LINE, 0x4b);
1282
1283   D0MV_0;
1284}
1285
1286/*Lv 1 DMA end irq*/
1287static TIMER_CALLBACK( dma_lv1_ended )
1288{
1289   cputag_set_input_line_and_vector(machine, "maincpu", 6, (stv_irq.dma_end[1]) ? HOLD_LINE : CLEAR_LINE, 0x4a);
1290
1291   D1MV_0;
1292}
1293
1294/*Lv 2 DMA end irq*/
1295static TIMER_CALLBACK( dma_lv2_ended )
1296{
1297   cputag_set_input_line_and_vector(machine, "maincpu", 6, (stv_irq.dma_end[2]) ? HOLD_LINE : CLEAR_LINE, 0x49);
1298
1299   D2MV_0;
1300}
1301
1302static void dma_direct_lv0(address_space *space)
1303{
1304   static UINT32 tmp_src,tmp_dst,tmp_size;
1305   if(LOG_SCU) logerror("DMA lv 0 transfer START\n"
1306                      "Start %08x End %08x Size %04x\n",scu_src_0,scu_dst_0,scu_size_0);
1307   if(LOG_SCU) logerror("Start Add %04x Destination Add %04x\n",scu_src_add_0,scu_dst_add_0);
1308
1309   D0MV_1;
1310
1311   if(scu_size_0 == 0) scu_size_0 = 0x00100000;
1312
1313   scsp_to_main_irq = 0;
1314
1315   /*set here the boundaries checks*/
1316   /*...*/
1317
1318   if(SOUND_RAM(dst_0))
1319   {
1320      logerror("Sound RAM DMA write\n");
1321      scsp_to_main_irq = 1;
1322   }
1323
1324   if((scu_dst_add_0 != scu_src_add_0) && (ABUS(src_0)))
1325   {
1326      logerror("A-Bus invalid transfer,sets to default\n");
1327      scu_add_tmp = (scu_dst_add_0*0x100) | (scu_src_add_0);
1328      scu_dst_add_0 = scu_src_add_0 = 4;
1329      scu_add_tmp |= 0x80000000;
1330   }
1331   /*Let me know if you encounter any of these three*/
1332   if(ABUS(dst_0))
1333   {
1334      logerror("A-Bus invalid write\n");
1335      /*...*/
1336   }
1337   if(WORK_RAM_L(dst_0))
1338   {
1339      logerror("WorkRam-L invalid write\n");
1340      /*...*/
1341   }
1342   if(VDP2(src_0))
1343   {
1344      logerror("VDP-2 invalid read\n");
1345      /*...*/
1346   }
1347   if(VDP1_REGS(dst_0))
1348   {
1349      logerror("VDP1 register access,must be in word units\n");
1350      scu_add_tmp = (scu_dst_add_0*0x100) | (scu_src_add_0);
1351      scu_dst_add_0 = scu_src_add_0 = 2;
1352      scu_add_tmp |= 0x80000000;
1353   }
1354   if(DRUP(0))
1355   {
1356      logerror("Data read update = 1,read address add value must be 1 too\n");
1357      scu_add_tmp = (scu_dst_add_0*0x100) | (scu_src_add_0);
1358      scu_src_add_0 = 4;
1359      scu_add_tmp |= 0x80000000;
1360   }
1361
1362   if (WORK_RAM_H(dst_0) && (scu_dst_add_0 != 4))
1363   {
1364      scu_add_tmp = (scu_dst_add_0*0x100) | (scu_src_add_0);
1365      scu_dst_add_0 = 4;
1366      scu_add_tmp |= 0x80000000;
1367   }
1368
1369   tmp_size = scu_size_0;
1370   if(!(DRUP(0))) tmp_src = scu_src_0;
1371   if(!(DWUP(0))) tmp_dst = scu_dst_0;
1372
1373   for (; scu_size_0 > 0; scu_size_0-=scu_dst_add_0)
1374   {
1375      if(scu_dst_add_0 == 2)
1376         space->write_word(scu_dst_0,space->read_word(scu_src_0));
1377      else if(scu_dst_add_0 == 8)
1378      {
1379         space->write_word(scu_dst_0,space->read_word(scu_src_0));
1380         space->write_word(scu_dst_0+2,space->read_word(scu_src_0));
1381         space->write_word(scu_dst_0+4,space->read_word(scu_src_0+2));
1382         space->write_word(scu_dst_0+6,space->read_word(scu_src_0+2));
1383      }
1384      else
1385      {
1386         space->write_word(scu_dst_0,space->read_word(scu_src_0));
1387         space->write_word(scu_dst_0+2,space->read_word(scu_src_0+2));
1388      }
1389
1390      scu_dst_0+=scu_dst_add_0;
1391      scu_src_0+=scu_src_add_0;
1392   }
1393
1394   scu_size_0 = tmp_size;
1395   if(!(DRUP(0))) scu_src_0 = tmp_src;
1396   if(!(DWUP(0))) scu_dst_0 = tmp_dst;
1397
1398   if(LOG_SCU) logerror("DMA transfer END\n");
1399
1400   /*TODO: timing of this*/
1401   space->machine().scheduler().timer_set(attotime::from_usec(300), FUNC(dma_lv0_ended));
1402
1403   if(scu_add_tmp & 0x80000000)
1404   {
1405      scu_dst_add_0 = (scu_add_tmp & 0xff00) >> 8;
1406      scu_src_add_0 = (scu_add_tmp & 0x00ff) >> 0;
1407      scu_add_tmp^=0x80000000;
1408   }
1409}
1410
1411static void dma_direct_lv1(address_space *space)
1412{
1413   static UINT32 tmp_src,tmp_dst,tmp_size;
1414   if(LOG_SCU) logerror("DMA lv 1 transfer START\n"
1415          "Start %08x End %08x Size %04x\n",scu_src_1,scu_dst_1,scu_size_1);
1416   if(LOG_SCU) logerror("Start Add %04x Destination Add %04x\n",scu_src_add_1,scu_dst_add_1);
1417
1418   D1MV_1;
1419
1420   if(scu_size_1 == 0) scu_size_1 = 0x00002000;
1421
1422   scsp_to_main_irq = 0;
1423
1424   /*set here the boundaries checks*/
1425   /*...*/
1426
1427   if(SOUND_RAM(dst_1))
1428   {
1429      logerror("Sound RAM DMA write\n");
1430      scsp_to_main_irq = 1;
1431   }
1432
1433   if((scu_dst_add_1 != scu_src_add_1) && (ABUS(src_1)))
1434   {
1435      logerror("A-Bus invalid transfer,sets to default\n");
1436      scu_add_tmp = (scu_dst_add_1*0x100) | (scu_src_add_1);
1437      scu_dst_add_1 = scu_src_add_1 = 4;
1438      scu_add_tmp |= 0x80000000;
1439   }
1440   /*Let me know if you encounter any of these ones*/
1441   if(ABUS(dst_1))
1442   {
1443      logerror("A-Bus invalid write\n");
1444      /*...*/
1445   }
1446   if(WORK_RAM_L(dst_1))
1447   {
1448      logerror("WorkRam-L invalid write\n");
1449      /*...*/
1450   }
1451   if(VDP1_REGS(dst_1))
1452   {
1453      logerror("VDP1 register access,must be in word units\n");
1454      scu_add_tmp = (scu_dst_add_1*0x100) | (scu_src_add_1);
1455      scu_dst_add_1 = scu_src_add_1 = 2;
1456      scu_add_tmp |= 0x80000000;
1457   }
1458   if(VDP2(src_1))
1459   {
1460      logerror("VDP-2 invalid read\n");
1461      /*...*/
1462   }
1463   if(DRUP(1))
1464   {
1465      logerror("Data read update = 1,read address add value must be 1 too\n");
1466      scu_add_tmp = (scu_dst_add_1*0x100) | (scu_src_add_1);
1467      scu_src_add_1 = 4;
1468      scu_add_tmp |= 0x80000000;
1469   }
1470
1471   if (WORK_RAM_H(dst_1) && (scu_dst_add_1 != 4))
1472   {
1473      scu_add_tmp = (scu_dst_add_1*0x100) | (scu_src_add_1);
1474      scu_src_add_1 = 4;
1475      scu_add_tmp |= 0x80000000;
1476   }
1477
1478   tmp_size = scu_size_1;
1479   if(!(DRUP(1))) tmp_src = scu_src_1;
1480   if(!(DWUP(1))) tmp_dst = scu_dst_1;
1481
1482   for (; scu_size_1 > 0; scu_size_1-=scu_dst_add_1)
1483   {
1484      if(scu_dst_add_1 == 2)
1485         space->write_word(scu_dst_1,space->read_word(scu_src_1));
1486      else
1487      {
1488         space->write_word(scu_dst_1,space->read_word(scu_src_1));
1489         space->write_word(scu_dst_1+2,space->read_word(scu_src_1+2));
1490      }
1491
1492      scu_dst_1+=scu_dst_add_1;
1493      scu_src_1+=scu_src_add_1;
1494   }
1495
1496   scu_size_1 = tmp_size;
1497   if(!(DRUP(1))) scu_src_1 = tmp_src;
1498   if(!(DWUP(1))) scu_dst_1 = tmp_dst;
1499
1500   if(LOG_SCU) logerror("DMA transfer END\n");
1501
1502   space->machine().scheduler().timer_set(attotime::from_usec(300), FUNC(dma_lv1_ended));
1503
1504   if(scu_add_tmp & 0x80000000)
1505   {
1506      scu_dst_add_1 = (scu_add_tmp & 0xff00) >> 8;
1507      scu_src_add_1 = (scu_add_tmp & 0x00ff) >> 0;
1508      scu_add_tmp^=0x80000000;
1509   }
1510}
1511
1512static void dma_direct_lv2(address_space *space)
1513{
1514   static UINT32 tmp_src,tmp_dst,tmp_size;
1515   if(LOG_SCU) logerror("DMA lv 2 transfer START\n"
1516          "Start %08x End %08x Size %04x\n",scu_src_2,scu_dst_2,scu_size_2);
1517   if(LOG_SCU) logerror("Start Add %04x Destination Add %04x\n",scu_src_add_2,scu_dst_add_2);
1518
1519   D2MV_1;
1520
1521   scsp_to_main_irq = 0;
1522
1523   if(scu_size_2 == 0) scu_size_2 = 0x00002000;
1524
1525   /*set here the boundaries checks*/
1526   /*...*/
1527
1528   if(SOUND_RAM(dst_2))
1529   {
1530      logerror("Sound RAM DMA write\n");
1531      scsp_to_main_irq = 1;
1532   }
1533
1534   if((scu_dst_add_2 != scu_src_add_2) && (ABUS(src_2)))
1535   {
1536      logerror("A-Bus invalid transfer,sets to default\n");
1537      scu_add_tmp = (scu_dst_add_2*0x100) | (scu_src_add_2);
1538      scu_dst_add_2 = scu_src_add_2 = 4;
1539      scu_add_tmp |= 0x80000000;
1540   }
1541   /*Let me know if you encounter any of these ones*/
1542   if(ABUS(dst_2))
1543   {
1544      logerror("A-Bus invalid write\n");
1545      /*...*/
1546   }
1547   if(WORK_RAM_L(dst_2))
1548   {
1549      logerror("WorkRam-L invalid write\n");
1550      /*...*/
1551   }
1552   if(VDP1_REGS(dst_2))
1553   {
1554      logerror("VDP1 register access,must be in word units\n");
1555      scu_add_tmp = (scu_dst_add_2*0x100) | (scu_src_add_2);
1556      scu_dst_add_2 = scu_src_add_2 = 2;
1557      scu_add_tmp |= 0x80000000;
1558   }
1559   if(VDP2(src_2))
1560   {
1561      logerror("VDP-2 invalid read\n");
1562      /*...*/
1563   }
1564   if(DRUP(2))
1565   {
1566      logerror("Data read update = 1,read address add value must be 1 too\n");
1567      scu_add_tmp = (scu_dst_add_2*0x100) | (scu_src_add_2);
1568      scu_src_add_2 = 4;
1569      scu_add_tmp |= 0x80000000;
1570   }
1571
1572   if (WORK_RAM_H(dst_2) && (scu_dst_add_2 != 4))
1573   {
1574      scu_add_tmp = (scu_dst_add_2*0x100) | (scu_src_add_2);
1575      scu_src_add_2 = 4;
1576      scu_add_tmp |= 0x80000000;
1577   }
1578
1579   tmp_size = scu_size_2;
1580   if(!(DRUP(2))) tmp_src = scu_src_2;
1581   if(!(DWUP(2))) tmp_dst = scu_dst_2;
1582
1583   for (; scu_size_2 > 0; scu_size_2-=scu_dst_add_2)
1584   {
1585      if(scu_dst_add_2 == 2)
1586         space->write_word(scu_dst_2,space->read_word(scu_src_2));
1587      else
1588      {
1589         space->write_word(scu_dst_2,space->read_word(scu_src_2));
1590         space->write_word(scu_dst_2+2,space->read_word(scu_src_2+2));
1591      }
1592
1593      scu_dst_2+=scu_dst_add_2;
1594      scu_src_2+=scu_src_add_2;
1595   }
1596
1597   scu_size_2 = tmp_size;
1598   if(!(DRUP(2))) scu_src_2 = tmp_src;
1599   if(!(DWUP(2))) scu_dst_2 = tmp_dst;
1600
1601   if(LOG_SCU) logerror("DMA transfer END\n");
1602
1603   space->machine().scheduler().timer_set(attotime::from_usec(300), FUNC(dma_lv2_ended));
1604
1605   if(scu_add_tmp & 0x80000000)
1606   {
1607      scu_dst_add_2 = (scu_add_tmp & 0xff00) >> 8;
1608      scu_src_add_2 = (scu_add_tmp & 0x00ff) >> 0;
1609      scu_add_tmp^=0x80000000;
1610   }
1611}
1612
1613static void dma_indirect_lv0(address_space *space)
1614{
1615   /*Helper to get out of the cycle*/
1616   UINT8 job_done = 0;
1617   /*temporary storage for the transfer data*/
1618   UINT32 tmp_src;
1619
1620   D0MV_1;
1621
1622   scsp_to_main_irq = 0;
1623
1624   if(scu_index_0 == 0) { scu_index_0 = scu_dst_0; }
1625
1626   do{
1627      tmp_src = scu_index_0;
1628
1629      /*Thanks for Runik of Saturnin for pointing this out...*/
1630      scu_size_0 = space->read_dword(scu_index_0);
1631      scu_src_0 =  space->read_dword(scu_index_0+8);
1632      scu_dst_0 =  space->read_dword(scu_index_0+4);
1633
1634      /*Indirect Mode end factor*/
1635      if(scu_src_0 & 0x80000000)
1636         job_done = 1;
1637
1638      if(SOUND_RAM(dst_0))
1639      {
1640         logerror("Sound RAM DMA write\n");
1641         scsp_to_main_irq = 1;
1642      }
1643
1644      if(LOG_SCU) logerror("DMA lv 0 indirect mode transfer START\n"
1645             "Start %08x End %08x Size %04x\n",scu_src_0,scu_dst_0,scu_size_0);
1646      if(LOG_SCU) logerror("Start Add %04x Destination Add %04x\n",scu_src_add_0,scu_dst_add_0);
1647
1648      //guess,but I believe it's right.
1649      scu_src_0 &=0x07ffffff;
1650      scu_dst_0 &=0x07ffffff;
1651      scu_size_0 &=0xfffff;
1652
1653      for (; scu_size_0 > 0; scu_size_0-=scu_dst_add_0)
1654      {
1655         if(scu_dst_add_0 == 2)
1656            space->write_word(scu_dst_0,space->read_word(scu_src_0));
1657         else
1658         {
1659            /* some games, eg columns97 are a bit weird, I'm not sure this is correct
1660                  they start a dma on a 2 byte boundary in 4 byte add mode, using the dword reads we
1661                  can't access 2 byte boundaries, and the end of the sprite list never gets marked,
1662                  the length of the transfer is also set to a 2 byte boundary, maybe the add values
1663                  should be different, I don't know */
1664            space->write_word(scu_dst_0,space->read_word(scu_src_0));
1665            space->write_word(scu_dst_0+2,space->read_word(scu_src_0+2));
1666         }
1667         scu_dst_0+=scu_dst_add_0;
1668         scu_src_0+=scu_src_add_0;
1669      }
1670
1671      //if(DRUP(0))   space->write_dword(tmp_src+8,scu_src_0|job_done ? 0x80000000 : 0);
1672      //if(DWUP(0)) space->write_dword(tmp_src+4,scu_dst_0);
1673
1674      scu_index_0 = tmp_src+0xc;
1675
1676   }while(job_done == 0);
1677
1678   space->machine().scheduler().timer_set(attotime::from_usec(300), FUNC(dma_lv0_ended));
1679}
1680
1681static void dma_indirect_lv1(address_space *space)
1682{
1683   /*Helper to get out of the cycle*/
1684   UINT8 job_done = 0;
1685   /*temporary storage for the transfer data*/
1686   UINT32 tmp_src;
1687
1688   D1MV_1;
1689
1690   scsp_to_main_irq = 0;
1691
1692   if(scu_index_1 == 0) { scu_index_1 = scu_dst_1; }
1693
1694   do{
1695      tmp_src = scu_index_1;
1696
1697      scu_size_1 = space->read_dword(scu_index_1);
1698      scu_src_1 =  space->read_dword(scu_index_1+8);
1699      scu_dst_1 =  space->read_dword(scu_index_1+4);
1700
1701      /*Indirect Mode end factor*/
1702      if(scu_src_1 & 0x80000000)
1703         job_done = 1;
1704
1705      if(SOUND_RAM(dst_1))
1706      {
1707         logerror("Sound RAM DMA write\n");
1708         scsp_to_main_irq = 1;
1709      }
1710
1711      if(LOG_SCU) logerror("DMA lv 1 indirect mode transfer START\n"
1712             "Start %08x End %08x Size %04x\n",scu_src_1,scu_dst_1,scu_size_1);
1713      if(LOG_SCU) logerror("Start Add %04x Destination Add %04x\n",scu_src_add_1,scu_dst_add_1);
1714
1715      //guess,but I believe it's right.
1716      scu_src_1 &=0x07ffffff;
1717      scu_dst_1 &=0x07ffffff;
1718      scu_size_1 &=0xffff;
1719
1720
1721      for (; scu_size_1 > 0; scu_size_1-=scu_dst_add_1)
1722      {
1723
1724         if(scu_dst_add_1 == 2)
1725            space->write_word(scu_dst_1,space->read_word(scu_src_1));
1726         else
1727         {
1728            /* some games, eg columns97 are a bit weird, I'm not sure this is correct
1729                  they start a dma on a 2 byte boundary in 4 byte add mode, using the dword reads we
1730                  can't access 2 byte boundaries, and the end of the sprite list never gets marked,
1731                  the length of the transfer is also set to a 2 byte boundary, maybe the add values
1732                  should be different, I don't know */
1733            space->write_word(scu_dst_1,space->read_word(scu_src_1));
1734            space->write_word(scu_dst_1+2,space->read_word(scu_src_1+2));
1735         }
1736         scu_dst_1+=scu_dst_add_1;
1737         scu_src_1+=scu_src_add_1;
1738      }
1739
1740      //if(DRUP(1))   space->write_dword(tmp_src+8,scu_src_1|job_done ? 0x80000000 : 0);
1741      //if(DWUP(1)) space->write_dword(tmp_src+4,scu_dst_1);
1742
1743      scu_index_1 = tmp_src+0xc;
1744
1745   }while(job_done == 0);
1746
1747   space->machine().scheduler().timer_set(attotime::from_usec(300), FUNC(dma_lv1_ended));
1748}
1749
1750static void dma_indirect_lv2(address_space *space)
1751{
1752   /*Helper to get out of the cycle*/
1753   UINT8 job_done = 0;
1754   /*temporary storage for the transfer data*/
1755   UINT32 tmp_src;
1756
1757   D2MV_1;
1758
1759   scsp_to_main_irq = 0;
1760
1761   if(scu_index_2 == 0) { scu_index_2 = scu_dst_2; }
1762
1763   do{
1764      tmp_src = scu_index_2;
1765
1766      scu_size_2 = space->read_dword(scu_index_2);
1767      scu_src_2 =  space->read_dword(scu_index_2+8);
1768      scu_dst_2 =  space->read_dword(scu_index_2+4);
1769
1770      /*Indirect Mode end factor*/
1771      if(scu_src_2 & 0x80000000)
1772         job_done = 1;
1773
1774      if(SOUND_RAM(dst_2))
1775      {
1776         logerror("Sound RAM DMA write\n");
1777         scsp_to_main_irq = 1;
1778      }
1779
1780      if(LOG_SCU) logerror("DMA lv 2 indirect mode transfer START\n"
1781             "Start %08x End %08x Size %04x\n",scu_src_2,scu_dst_2,scu_size_2);
1782      if(LOG_SCU) logerror("Start Add %04x Destination Add %04x\n",scu_src_add_2,scu_dst_add_2);
1783
1784      //guess,but I believe it's right.
1785      scu_src_2 &=0x07ffffff;
1786      scu_dst_2 &=0x07ffffff;
1787      scu_size_2 &=0xffff;
1788
1789      for (; scu_size_2 > 0; scu_size_2-=scu_dst_add_2)
1790      {
1791         if(scu_dst_add_2 == 2)
1792            space->write_word(scu_dst_2,space->read_word(scu_src_2));
1793         else
1794         {
1795            /* some games, eg columns97 are a bit weird, I'm not sure this is correct
1796                  they start a dma on a 2 byte boundary in 4 byte add mode, using the dword reads we
1797                  can't access 2 byte boundaries, and the end of the sprite list never gets marked,
1798                  the length of the transfer is also set to a 2 byte boundary, maybe the add values
1799                  should be different, I don't know */
1800            space->write_word(scu_dst_2,space->read_word(scu_src_2));
1801            space->write_word(scu_dst_2+2,space->read_word(scu_src_2+2));
1802         }
1803
1804         scu_dst_2+=scu_dst_add_2;
1805         scu_src_2+=scu_src_add_2;
1806      }
1807
1808      //if(DRUP(2))   space->write_dword(tmp_src+8,scu_src_2|job_done ? 0x80000000 : 0);
1809      //if(DWUP(2)) space->write_dword(tmp_src+4,scu_dst_2);
1810
1811      scu_index_2 = tmp_src+0xc;
1812
1813   }while(job_done == 0);
1814
1815   space->machine().scheduler().timer_set(attotime::from_usec(300), FUNC(dma_lv2_ended));
1816}
1817
1818
1819/**************************************************************************************/
1820
1821static WRITE32_HANDLER( stv_sh2_soundram_w )
1822{
1823   COMBINE_DATA(sound_ram+offset*2+1);
1824   data >>= 16;
1825   mem_mask >>= 16;
1826   COMBINE_DATA(sound_ram+offset*2);
1827}
1828
1829static READ32_HANDLER( stv_sh2_soundram_r )
1830{
1831   return (sound_ram[offset*2]<<16)|sound_ram[offset*2+1];
1832}
1833
1834static READ32_HANDLER( stv_scsp_regs_r32 )
1835{
1836   device_t *scsp = space->machine().device("scsp");
1837
1838   offset <<= 1;
1839   return (scsp_r(scsp, offset+1, 0xffff) | (scsp_r(scsp, offset, 0xffff)<<16));
1840}
1841
1842static WRITE32_HANDLER( stv_scsp_regs_w32 )
1843{
1844   device_t *scsp = space->machine().device("scsp");
1845
1846   offset <<= 1;
1847   scsp_w(scsp, offset, data>>16, mem_mask >> 16);
1848   scsp_w(scsp, offset+1, data, mem_mask);
1849}
1850
1851/* communication,SLAVE CPU acquires data from the MASTER CPU and triggers an irq.  *
1852 * Enter into Radiant Silver Gun specific menu for a test...                       */
1853static WRITE32_HANDLER( minit_w )
1854{
1855   logerror("cpu %s (PC=%08X) MINIT write = %08x\n", space->device().tag(), cpu_get_pc(&space->device()),data);
1856   space->machine().scheduler().boost_interleave(minit_boost_timeslice, attotime::from_usec(minit_boost));
1857   space->machine().scheduler().trigger(1000);
1858   sh2_set_frt_input(space->machine().device("slave"), PULSE_LINE);
1859}
1860
1861static WRITE32_HANDLER( sinit_w )
1862{
1863   logerror("cpu %s (PC=%08X) SINIT write = %08x\n", space->device().tag(), cpu_get_pc(&space->device()),data);
1864   space->machine().scheduler().boost_interleave(sinit_boost_timeslice, attotime::from_usec(sinit_boost));
1865   sh2_set_frt_input(space->machine().device("maincpu"), PULSE_LINE);
1866}
1867
1868static UINT32 backup[64*1024/4];
1869
1870static READ32_HANDLER(satram_r)
1871{
1872   return backup[offset] & 0x00ff00ff;   // yes, it makes sure the "holes" are there.
1873}
1874
1875static WRITE32_HANDLER(satram_w)
1876{
1877   COMBINE_DATA(&backup[offset]);
1878}
1879
1880static NVRAM_HANDLER(saturn)
1881{
1882   static const UINT32 init[8] =
1883   {
1884      0x420061, 0x63006b, 0x550070, 0x520061, 0x6d0020, 0x46006f, 0x72006d, 0x610074,
1885   };
1886   int i;
1887
1888   if (read_or_write)
1889      file->write(backup, 64*1024/4);
1890   else
1891   {
1892      if (file)
1893      {
1894         file->read(backup, 64*1024/4);
1895      }
1896      else
1897      {
1898         memset(backup, 0, 64*1024/4);
1899         for (i = 0; i < 8; i++)
1900         {
1901            backup[i] = init[i];
1902            backup[i+8] = init[i];
1903            backup[i+16] = init[i];
1904            backup[i+24] = init[i];
1905         }
1906      }
1907   }
1908}
1909
1910static ADDRESS_MAP_START( saturn_mem, AS_PROGRAM, 32 )
1911   AM_RANGE(0x00000000, 0x0007ffff) AM_ROM AM_SHARE("share6")  // bios
1912   AM_RANGE(0x00100000, 0x0010007f) AM_READWRITE(stv_SMPC_r32, stv_SMPC_w32)
1913   AM_RANGE(0x00180000, 0x0018ffff) AM_READWRITE(satram_r, satram_w)
1914   AM_RANGE(0x00200000, 0x002fffff) AM_RAM AM_MIRROR(0x100000) AM_SHARE("share2") AM_BASE(&stv_workram_l)
1915   AM_RANGE(0x01000000, 0x01000003) AM_WRITE(minit_w)
1916   AM_RANGE(0x01406f40, 0x01406f43) AM_WRITE(minit_w) // prikura seems to write here ..
1917   AM_RANGE(0x01800000, 0x01800003) AM_WRITE(sinit_w)
1918   AM_RANGE(0x02000000, 0x023fffff) AM_ROM AM_SHARE("share7") AM_REGION("maincpu", 0x80000)   // cartridge space
1919   AM_RANGE(0x05800000, 0x0589ffff) AM_READWRITE(stvcd_r, stvcd_w)
1920   /* Sound */
1921   AM_RANGE(0x05a00000, 0x05a7ffff) AM_READWRITE(stv_sh2_soundram_r, stv_sh2_soundram_w)
1922   AM_RANGE(0x05b00000, 0x05b00fff) AM_READWRITE(stv_scsp_regs_r32, stv_scsp_regs_w32)
1923   /* VDP1 */
1924   /*0x05c00000-0x05c7ffff VRAM*/
1925   /*0x05c80000-0x05c9ffff Frame Buffer 0*/
1926   /*0x05ca0000-0x05cbffff Frame Buffer 1*/
1927   /*0x05d00000-0x05d7ffff VDP1 Regs */
1928   AM_RANGE(0x05c00000, 0x05c7ffff) AM_READWRITE(stv_vdp1_vram_r, stv_vdp1_vram_w)
1929   AM_RANGE(0x05c80000, 0x05cbffff) AM_READWRITE(stv_vdp1_framebuffer0_r, stv_vdp1_framebuffer0_w)
1930   AM_RANGE(0x05d00000, 0x05d0001f) AM_READWRITE(stv_vdp1_regs_r, stv_vdp1_regs_w)
1931   AM_RANGE(0x05e00000, 0x05efffff) AM_READWRITE(stv_vdp2_vram_r, stv_vdp2_vram_w)
1932   AM_RANGE(0x05f00000, 0x05f7ffff) AM_READWRITE(stv_vdp2_cram_r, stv_vdp2_cram_w)
1933   AM_RANGE(0x05f80000, 0x05fbffff) AM_READWRITE(stv_vdp2_regs_r, stv_vdp2_regs_w)
1934   AM_RANGE(0x05fe0000, 0x05fe00cf) AM_READWRITE(stv_scu_r32, stv_scu_w32)
1935   AM_RANGE(0x06000000, 0x060fffff) AM_RAM AM_MIRROR(0x01f00000) AM_SHARE("share3") AM_BASE(&stv_workram_h)
1936   AM_RANGE(0x20000000, 0x2007ffff) AM_ROM AM_SHARE("share6")  // bios mirror
1937   AM_RANGE(0x22000000, 0x24ffffff) AM_ROM AM_SHARE("share7")  // cart mirror
1938ADDRESS_MAP_END
1939
1940static ADDRESS_MAP_START( sound_mem, AS_PROGRAM, 16 )
1941   AM_RANGE(0x000000, 0x07ffff) AM_RAM AM_BASE(&sound_ram)
1942   AM_RANGE(0x100000, 0x100fff) AM_DEVREADWRITE("scsp", scsp_r, scsp_w)
1943ADDRESS_MAP_END
1944
1945static INPUT_PORTS_START( saturn )
1946   PORT_START("PDR1")
1947   PORT_DIPNAME( 0x01, 0x01, "PDR1" )
1948   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
1949   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1950   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
1951   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
1952   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1953   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
1954   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
1955   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1956   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
1957   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
1958   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1959   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
1960   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
1961   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1962   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
1963   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
1964   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1965   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
1966   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
1967   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1968   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
1969   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
1970   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1971
1972   PORT_START("PDR2")
1973   PORT_DIPNAME( 0x01, 0x01, "PDR2" )
1974   PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
1975   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1976   PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
1977   PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
1978   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1979   PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
1980   PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
1981   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1982   PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
1983   PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
1984   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1985   PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
1986   PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
1987   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1988   PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
1989   PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
1990   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1991   PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )
1992   PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
1993   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1994   PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
1995   PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
1996   PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1997
1998   PORT_START("JOY1")
1999   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1)
2000   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1)
2001   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1)
2002   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1)
2003   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_START ) PORT_PLAYER(1)   // START
2004   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P1 A") PORT_PLAYER(1)   // A
2005   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P1 B") PORT_PLAYER(1)   // B
2006   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("P1 C") PORT_PLAYER(1)   // C
2007   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("P1 X") PORT_PLAYER(1)   // X
2008   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("P1 Y") PORT_PLAYER(1)   // Y
2009   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("P1 Z") PORT_PLAYER(1)   // Z
2010   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_NAME("P1 L") PORT_PLAYER(1)   // L
2011   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("P1 R") PORT_PLAYER(1)   // R
2012
2013   PORT_START("JOY2")
2014   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
2015   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2)
2016   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2)
2017   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2)
2018   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_START ) PORT_PLAYER(2)   // START
2019   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P2 A") PORT_PLAYER(2)   // A
2020   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P2 B") PORT_PLAYER(2)   // B
2021   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("P2 C") PORT_PLAYER(2)   // C
2022   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("P2 X") PORT_PLAYER(2)   // X
2023   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("P2 Y") PORT_PLAYER(2)   // Y
2024   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("P2 Z") PORT_PLAYER(2)   // Z
2025   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_NAME("P2 L") PORT_PLAYER(2)   // L
2026   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("P2 R") PORT_PLAYER(2)   // R
2027INPUT_PORTS_END
2028
2029/*
2030(Preliminary) explaination about this:
2031VBLANK-OUT is used at the start of the vblank period.It also sets the timer zero
2032variable to 0.
2033If the Timer Compare register is zero too,the Timer 0 irq is triggered.
2034
2035HBLANK-IN is used at the end of each scanline except when in VBLANK-IN/OUT periods.
2036
2037The timer 0 is also incremented by one at each HBLANK and checked with the value
2038of the Timer Compare register;if equal,the timer 0 irq is triggered here too.
2039Notice that the timer 0 compare register can be more than the VBLANK maximum range,in
2040this case the timer 0 irq is simply never triggered.This is a known Sega Saturn/ST-V "bug".
2041
2042VBLANK-IN is used at the end of the vblank period.
2043
2044SCU register[36] is the timer zero compare register.
2045SCU register[40] is for IRQ masking.
2046*/
2047
2048/* to do, update bios idle skips so they work better with this arrangement.. */
2049
2050static timer_device *vblank_out_timer,*scan_timer,*t1_timer;
2051static int h_sync,v_sync;
2052static int cur_scan;
2053
2054#define VBLANK_OUT_IRQ   \
2055timer_0 = 0; \
2056{ \
2057   /*if(LOG_IRQ) logerror ("Interrupt: VBlank-OUT Vector 0x41 Level 0x0e\n");*/ \
2058   cputag_set_input_line_and_vector(timer.machine(), "maincpu", 0xe, (stv_irq.vblank_out) ? HOLD_LINE : CLEAR_LINE , 0x41); \
2059} \
2060
2061#define VBLANK_IN_IRQ \
2062{ \
2063   /*if(LOG_IRQ) logerror ("Interrupt: VBlank IN Vector 0x40 Level 0x0f\n");*/ \
2064   cputag_set_input_line_and_vector(device->machine(), "maincpu", 0xf, (stv_irq.vblank_in) ? HOLD_LINE : CLEAR_LINE , 0x40); \
2065} \
2066
2067#define HBLANK_IN_IRQ \
2068timer_1 = stv_scu[37] & 0x1ff; \
2069{ \
2070   /*if(LOG_IRQ) logerror ("Interrupt: HBlank-In at scanline %04x, Vector 0x42 Level 0x0d\n",scanline);*/ \
2071   cputag_set_input_line_and_vector(timer.machine(), "maincpu", 0xd, (stv_irq.hblank_in) ? HOLD_LINE : CLEAR_LINE, 0x42); \
2072} \
2073
2074#define TIMER_0_IRQ \
2075if(timer_0 == (stv_scu[36] & 0x3ff)) \
2076{ \
2077   /*if(LOG_IRQ) logerror ("Interrupt: Timer 0 at scanline %04x, Vector 0x43 Level 0x0c\n",scanline);*/ \
2078   cputag_set_input_line_and_vector(timer.machine(), "maincpu", 0xc, (stv_irq.timer_0) ? HOLD_LINE : CLEAR_LINE, 0x43 ); \
2079} \
2080
2081#define TIMER_1_IRQ   \
2082if((stv_scu[38] & 1)) \
2083{ \
2084   if(!(stv_scu[38] & 0x80)) \
2085   { \
2086      /*if(LOG_IRQ) logerror ("Interrupt: Timer 1 at point %04x, Vector 0x44 Level 0x0b\n",point);*/ \
2087      cputag_set_input_line_and_vector(timer.machine(), "maincpu", 0xb, (stv_irq.timer_1) ? HOLD_LINE : CLEAR_LINE, 0x44 ); \
2088   } \
2089   else \
2090   { \
2091      if((timer_0) == (stv_scu[36] & 0x3ff)) \
2092      { \
2093         /*if(LOG_IRQ) logerror ("Interrupt: Timer 1 at point %04x, Vector 0x44 Level 0x0b\n",point);*/ \
2094         cputag_set_input_line_and_vector(timer.machine(), "maincpu", 0xb, (stv_irq.timer_1) ? HOLD_LINE : CLEAR_LINE, 0x44 ); \
2095      } \
2096   } \
2097} \
2098
2099#define VDP1_IRQ \
2100{ \
2101   cputag_set_input_line_and_vector(machine, "maincpu", 2, (stv_irq.vdp1_end) ? HOLD_LINE : CLEAR_LINE, 0x4d); \
2102} \
2103
2104static TIMER_DEVICE_CALLBACK( hblank_in_irq )
2105{
2106   int scanline = param;
2107
2108//  h = timer.machine().primary_screen->height();
2109//  w = timer.machine().primary_screen->width();
2110
2111   HBLANK_IN_IRQ;
2112   TIMER_0_IRQ;
2113
2114   if(scanline+1 < v_sync)
2115   {
2116      if(stv_irq.hblank_in || stv_irq.timer_0)
2117         scan_timer->adjust(timer.machine().primary_screen->time_until_pos(scanline+1, h_sync), scanline+1);
2118      /*set the first Timer-1 event*/
2119      cur_scan = scanline+1;
2120      if(stv_irq.timer_1)
2121         t1_timer->adjust(timer.machine().primary_screen->time_until_pos(scanline+1));
2122   }
2123
2124   timer_0++;
2125}
2126
2127static TIMER_DEVICE_CALLBACK( timer1_irq )
2128{
2129   int cur_point = param;
2130
2131   TIMER_1_IRQ;
2132
2133   if((cur_point+1) < h_sync && stv_irq.timer_1)
2134   {
2135      t1_timer->adjust(timer.machine().primary_screen->time_until_pos(cur_scan, cur_point+1), cur_point+1);
2136   }
2137
2138   if(timer_1 > 0) timer_1--;
2139}
2140
2141static TIMER_CALLBACK( vdp1_irq )
2142{
2143   VDP1_IRQ;
2144}
2145
2146static TIMER_DEVICE_CALLBACK( vblank_out_irq )
2147{
2148   VBLANK_OUT_IRQ;
2149}
2150
2151/*V-Blank-IN event*/
2152static INTERRUPT_GEN( stv_interrupt )
2153{
2154//  scanline = 0;
2155   const rectangle &visarea = device->machine().primary_screen->visible_area();
2156
2157   h_sync = visarea.max_x+1;//horz
2158   v_sync = visarea.max_y+1;//vert
2159
2160   VBLANK_IN_IRQ;
2161
2162   /*Next V-Blank-OUT event*/
2163   if(stv_irq.vblank_out)
2164      vblank_out_timer->adjust(device->machine().primary_screen->time_until_pos(0));
2165   /*Set the first Hblank-IN event*/
2166   if(stv_irq.hblank_in || stv_irq.timer_0 || stv_irq.timer_1)
2167      scan_timer->adjust(device->machine().primary_screen->time_until_pos(0, h_sync));
2168
2169   /*TODO: timing of this one (related to the VDP1 speed)*/
2170   /*      (NOTE: value shouldn't be at h_sync/v_sync position (will break shienryu))*/
2171   device->machine().scheduler().timer_set(device->machine().primary_screen->time_until_pos(0,0), FUNC(vdp1_irq));
2172}
2173
2174static void saturn_init_driver(running_machine &machine, int rgn)
2175{
2176   system_time systime;
2177
2178   saturn_region = rgn;
2179
2180   // set compatible options
2181   sh2drc_set_options(machine.device("maincpu"), SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
2182   sh2drc_set_options(machine.device("slave"), SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
2183
2184   /* get the current date/time from the core */
2185   machine.current_datetime(systime);
2186
2187   /* amount of time to boost interleave for on MINIT / SINIT, needed for communication to work */
2188   minit_boost = 400;
2189   sinit_boost = 400;
2190   minit_boost_timeslice = attotime::zero;
2191   sinit_boost_timeslice = attotime::zero;
2192
2193   smpc_ram = auto_alloc_array(machine, UINT8, 0x80);
2194   stv_scu = auto_alloc_array(machine, UINT32, 0x100/4);
2195   scsp_regs = auto_alloc_array(machine, UINT16, 0x1000/2);
2196
2197   smpc_ram[0x23] = dec_2_bcd(systime.local_time.year / 100);
2198   smpc_ram[0x25] = dec_2_bcd(systime.local_time.year % 100);
2199   smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month + 1);
2200   smpc_ram[0x29] = dec_2_bcd(systime.local_time.mday);
2201   smpc_ram[0x2b] = dec_2_bcd(systime.local_time.hour);
2202   smpc_ram[0x2d] = dec_2_bcd(systime.local_time.minute);
2203   smpc_ram[0x2f] = dec_2_bcd(systime.local_time.second);
2204   smpc_ram[0x31] = 0x00; //CTG1=0 CTG0=0 (correct??)
2205//  smpc_ram[0x33] = input_port_read(machine, "???");
2206   smpc_ram[0x5f] = 0x10;
2207}
2208
2209static DRIVER_INIT( saturnus )
2210{
2211   saturn_init_driver(machine, 4);
2212}
2213
2214static DRIVER_INIT( saturneu )
2215{
2216   saturn_init_driver(machine, 12);
2217}
2218
2219static DRIVER_INIT( saturnjp )
2220{
2221   saturn_init_driver(machine, 1);
2222}
2223
2224
2225static int scsp_last_line = 0;
2226
2227static MACHINE_START( saturn )
2228{
2229   scsp_set_ram_base(machine.device("scsp"), sound_ram);
2230
2231   // save states
2232   state_save_register_global_pointer(machine, smpc_ram, 0x80);
2233   state_save_register_global_pointer(machine, stv_scu, 0x100/4);
2234   state_save_register_global_pointer(machine, scsp_regs, 0x1000/2);
2235   state_save_register_global(machine, stv_vblank);
2236   state_save_register_global(machine, stv_hblank);
2237   state_save_register_global(machine, stv_enable_slave_sh2);
2238   state_save_register_global(machine, NMI_reset);
2239   state_save_register_global(machine, en_68k);
2240   state_save_register_global(machine, timer_0);
2241   state_save_register_global(machine, timer_1);
2242   state_save_register_global(machine, IOSEL1);
2243   state_save_register_global(machine, IOSEL2);
2244   state_save_register_global(machine, EXLE1);
2245   state_save_register_global(machine, EXLE2);
2246   state_save_register_global(machine, PDR1);
2247   state_save_register_global(machine, PDR2);
2248//  state_save_register_global(machine, port_sel);
2249//  state_save_register_global(machine, mux_data);
2250   state_save_register_global(machine, scsp_last_line);
2251   state_save_register_global(machine, intback_stage);
2252   state_save_register_global(machine, pmode);
2253   state_save_register_global(machine, smpcSR);
2254   state_save_register_global_array(machine, SMEM);
2255
2256   machine.add_notifier(MACHINE_NOTIFY_EXIT, stvcd_exit);
2257}
2258
2259static MACHINE_RESET( saturn )
2260{
2261   // don't let the slave cpu and the 68k go anywhere
2262   cputag_set_input_line(machine, "slave", INPUT_LINE_RESET, ASSERT_LINE);
2263   stv_enable_slave_sh2 = 0;
2264   cputag_set_input_line(machine, "audiocpu", INPUT_LINE_RESET, ASSERT_LINE);
2265
2266   smpcSR = 0x40;   // this bit is always on according to docs
2267
2268   timer_0 = 0;
2269   timer_1 = 0;
2270   en_68k = 0;
2271   NMI_reset = 1;
2272   smpc_ram[0x21] = (0x80) | ((NMI_reset & 1) << 6);
2273
2274   DMA_STATUS = 0;
2275
2276   memset(stv_workram_l, 0, 0x100000);
2277   memset(stv_workram_h, 0, 0x100000);
2278
2279   machine.device("maincpu")->set_unscaled_clock(MASTER_CLOCK_320/2);
2280   machine.device("slave")->set_unscaled_clock(MASTER_CLOCK_320/2);
2281   machine.device("audiocpu")->set_unscaled_clock(MASTER_CLOCK_320/5);
2282
2283   stvcd_reset( machine );
2284
2285   /* set the first scanline 0 timer to go off */
2286   scan_timer = machine.device<timer_device>("scan_timer");
2287   t1_timer = machine.device<timer_device>("t1_timer");
2288   vblank_out_timer = machine.device<timer_device>("vbout_timer");
2289   vblank_out_timer->adjust(machine.primary_screen->time_until_pos(0));
2290   scan_timer->adjust(machine.primary_screen->time_until_pos(224, 352));
2291}
2292
2293static const gfx_layout tiles8x8x4_layout =
2294{
2295   8,8,
2296   0x100000/(32*8/8),
2297   4,
2298   { 0, 1, 2, 3 },
2299   { 0, 4, 8, 12, 16, 20, 24, 28 },
2300   { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 },
2301   32*8
2302};
2303
2304static const gfx_layout tiles16x16x4_layout =
2305{
2306   16,16,
2307   0x100000/(32*32/8),
2308   4,
2309   { 0, 1, 2, 3 },
2310   { 0, 4, 8, 12, 16, 20, 24, 28,
2311     32*8+0, 32*8+4, 32*8+8, 32*8+12, 32*8+16, 32*8+20, 32*8+24, 32*8+28,
2312   },
2313   { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32,
2314     32*16, 32*17,32*18, 32*19,32*20,32*21,32*22,32*23
2315   },
2316   32*32
2317};
2318
2319static const gfx_layout tiles8x8x8_layout =
2320{
2321   8,8,
2322   0x100000/(32*8/8),
2323   8,
2324   { 0, 1, 2, 3, 4, 5, 6, 7 },
2325   { 0, 8, 16, 24, 32, 40, 48, 56 },
2326   { 0*64, 1*64, 2*64, 3*64, 4*64, 5*64, 6*64, 7*64 },
2327   32*8   /* really 64*8, but granularity is 32 bytes */
2328};
2329
2330static const gfx_layout tiles16x16x8_layout =
2331{
2332   16,16,
2333   0x100000/(64*16/8),
2334   8,
2335   { 0, 1, 2, 3, 4, 5, 6, 7 },
2336   { 0, 8, 16, 24, 32, 40, 48, 56,
2337   64*8+0, 65*8, 66*8, 67*8, 68*8, 69*8, 70*8, 71*8
2338
2339   },
2340   { 0*64, 1*64, 2*64, 3*64, 4*64, 5*64, 6*64, 7*64,
2341   64*16, 64*17, 64*18, 64*19, 64*20, 64*21, 64*22, 64*23
2342   },
2343   64*16   /* really 128*16, but granularity is 32 bytes */
2344};
2345
2346static GFXDECODE_START( saturn )
2347   GFXDECODE_ENTRY( NULL, 0, tiles8x8x4_layout,   0x00, (0x80*(2+1))  )
2348   GFXDECODE_ENTRY( NULL, 0, tiles16x16x4_layout, 0x00, (0x80*(2+1))  )
2349   GFXDECODE_ENTRY( NULL, 0, tiles8x8x8_layout,   0x00, (0x08*(2+1))  )
2350   GFXDECODE_ENTRY( NULL, 0, tiles16x16x8_layout, 0x00, (0x08*(2+1))  )
2351
2352   /* vdp1 .. pointless for drawing but can help us debug */
2353   GFXDECODE_ENTRY( NULL, 0, tiles8x8x4_layout,   0x00, 0x100  )
2354   GFXDECODE_ENTRY( NULL, 0, tiles16x16x4_layout, 0x00, 0x100  )
2355   GFXDECODE_ENTRY( NULL, 0, tiles8x8x8_layout,   0x00, 0x20  )
2356   GFXDECODE_ENTRY( NULL, 0, tiles16x16x8_layout, 0x00, 0x20  )
2357GFXDECODE_END
2358
2359static const sh2_cpu_core sh2_conf_master = { 0 };
2360static const sh2_cpu_core sh2_conf_slave  = { 1 };
2361
2362static void scsp_irq(device_t *device, int irq)
2363{
2364   // don't bother the 68k if it's off
2365   if (!en_68k)
2366   {
2367      return;
2368   }
2369
2370   if (irq > 0)
2371   {
2372      scsp_last_line = irq;
2373      cputag_set_input_line(device->machine(), "audiocpu", irq, ASSERT_LINE);
2374   }
2375   else if (irq < 0)
2376   {
2377      cputag_set_input_line(device->machine(), "audiocpu", -irq, CLEAR_LINE);
2378   }
2379   else
2380   {
2381      cputag_set_input_line(device->machine(), "audiocpu", scsp_last_line, CLEAR_LINE);
2382   }
2383}
2384
2385static const scsp_interface saturn_scsp_interface =
2386{
2387   0,
2388   scsp_irq
2389};
2390
2391static MACHINE_CONFIG_START( saturn, driver_device )
2392
2393   /* basic machine hardware */
2394   MCFG_CPU_ADD("maincpu", SH2, MASTER_CLOCK_352/2) // 28.6364 MHz
2395   MCFG_CPU_PROGRAM_MAP(saturn_mem)
2396   MCFG_CPU_VBLANK_INT("screen",stv_interrupt)
2397   MCFG_CPU_CONFIG(sh2_conf_master)
2398
2399   MCFG_CPU_ADD("slave", SH2, MASTER_CLOCK_352/2) // 28.6364 MHz
2400   MCFG_CPU_PROGRAM_MAP(saturn_mem)
2401   MCFG_CPU_CONFIG(sh2_conf_slave)
2402
2403   MCFG_CPU_ADD("audiocpu", M68000, MASTER_CLOCK_352/5) //11.46 MHz
2404   MCFG_CPU_PROGRAM_MAP(sound_mem)
2405
2406   MCFG_MACHINE_START(saturn)
2407   MCFG_MACHINE_RESET(saturn)
2408
2409   MCFG_NVRAM_HANDLER(saturn)
2410
2411   MCFG_TIMER_ADD("scan_timer", hblank_in_irq)
2412   MCFG_TIMER_ADD("t1_timer", timer1_irq)
2413   MCFG_TIMER_ADD("vbout_timer", vblank_out_irq)
2414   MCFG_TIMER_ADD("sector_timer", stv_sector_cb)
2415
2416   /* video hardware */
2417   MCFG_SCREEN_ADD("screen", RASTER)
2418   MCFG_SCREEN_REFRESH_RATE(60)
2419   MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(192))   // guess, needed to force video update after V-Blank OUT interrupt
2420   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB15)
2421   MCFG_SCREEN_SIZE(704*2, 512*2)
2422   MCFG_SCREEN_VISIBLE_AREA(0*8, 703, 0*8, 511) // we need to use a resolution as high as the max size it can change to
2423   MCFG_SCREEN_UPDATE(stv_vdp2)
2424
2425   MCFG_PALETTE_LENGTH(2048+(2048*2))//standard palette + extra memory for rgb brightness.
2426   MCFG_GFXDECODE(saturn)
2427
2428   MCFG_VIDEO_START(stv_vdp2)
2429
2430   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
2431
2432   MCFG_SOUND_ADD("scsp", SCSP, 0)
2433   MCFG_SOUND_CONFIG(saturn_scsp_interface)
2434   MCFG_SOUND_ROUTE(0, "lspeaker", 1.0)
2435   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
2436
2437   MCFG_CDROM_ADD( "cdrom" )
2438   MCFG_CARTSLOT_ADD("cart")
2439MACHINE_CONFIG_END
2440
2441
2442/* Japanese Saturn */
2443ROM_START(saturnjp)
2444   ROM_REGION( 0x480000, "maincpu", ROMREGION_ERASEFF ) /* SH2 code */
2445   ROM_SYSTEM_BIOS(0, "101", "Japan v1.01 (941228)")
2446   ROMX_LOAD("sega_101.bin", 0x00000000, 0x00080000, CRC(224b752c) SHA1(df94c5b4d47eb3cc404d88b33a8fda237eaf4720), ROM_BIOS(1))
2447   ROM_SYSTEM_BIOS(1, "1003", "Japan v1.003 (941012)")
2448   ROMX_LOAD("sega1003.bin", 0x00000000, 0x00080000, CRC(b3c63c25) SHA1(7b23b53d62de0f29a23e423d0fe751dfb469c2fa), ROM_BIOS(2))
2449   ROM_SYSTEM_BIOS(2, "100", "Japan v1.00 (940921)")
2450   ROMX_LOAD("sega_100.bin", 0x00000000, 0x00080000, CRC(2aba43c2) SHA1(2b8cb4f87580683eb4d760e4ed210813d667f0a2), ROM_BIOS(3))
2451   ROM_CART_LOAD("cart", 0x080000, 0x400000, ROM_NOMIRROR | ROM_OPTIONAL)
2452   ROM_REGION( 0x080000, "slave", 0 ) /* SH2 code */
2453   ROM_COPY( "maincpu",0,0,0x080000)
2454ROM_END
2455
2456/* Overseas Saturn */
2457ROM_START(saturn)
2458   ROM_REGION( 0x480000, "maincpu", ROMREGION_ERASEFF ) /* SH2 code */
2459   ROM_SYSTEM_BIOS(0, "101a", "Overseas v1.01a (941115)")
2460   ROMX_LOAD("sega_101a.bin", 0x00000000, 0x00080000, CRC(4afcf0fa) SHA1(faa8ea183a6d7bbe5d4e03bb1332519800d3fbc3), ROM_BIOS(1))
2461   ROM_SYSTEM_BIOS(1, "100a", "Overseas v1.00a (941115)")
2462   ROMX_LOAD("sega_100a.bin", 0x00000000, 0x00080000, CRC(f90f0089) SHA1(3bb41feb82838ab9a35601ac666de5aacfd17a58), ROM_BIOS(2))
2463   ROM_CART_LOAD("cart", 0x080000, 0x400000, ROM_NOMIRROR | ROM_OPTIONAL)
2464   ROM_REGION( 0x080000, "slave", 0 ) /* SH2 code */
2465   ROM_COPY( "maincpu",0,0,0x080000)
2466ROM_END
2467
2468ROM_START(saturneu)
2469   ROM_REGION( 0x480000, "maincpu", ROMREGION_ERASEFF ) /* SH2 code */
2470   ROM_SYSTEM_BIOS(0, "101a", "Overseas v1.01a (941115)")
2471   ROMX_LOAD("sega_101a.bin", 0x00000000, 0x00080000, CRC(4afcf0fa) SHA1(faa8ea183a6d7bbe5d4e03bb1332519800d3fbc3), ROM_BIOS(1))
2472   ROM_SYSTEM_BIOS(1, "100a", "Overseas v1.00a (941115)")
2473   ROMX_LOAD("sega_100a.bin", 0x00000000, 0x00080000, CRC(f90f0089) SHA1(3bb41feb82838ab9a35601ac666de5aacfd17a58), ROM_BIOS(2))
2474   ROM_CART_LOAD("cart", 0x080000, 0x400000, ROM_NOMIRROR | ROM_OPTIONAL)
2475   ROM_REGION( 0x080000, "slave", 0 ) /* SH2 code */
2476   ROM_COPY( "maincpu",0,0,0x080000)
2477ROM_END
2478
2479ROM_START(vsaturn)
2480   ROM_REGION( 0x480000, "maincpu", ROMREGION_ERASEFF ) /* SH2 code */
2481   ROM_LOAD("vsaturn.bin", 0x00000000, 0x00080000, CRC(e4d61811) SHA1(4154e11959f3d5639b11d7902b3a393a99fb5776))
2482   ROM_CART_LOAD("cart", 0x080000, 0x400000, ROM_NOMIRROR | ROM_OPTIONAL)
2483   ROM_REGION( 0x080000, "slave", 0 ) /* SH2 code */
2484   ROM_COPY( "maincpu",0,0,0x080000)
2485ROM_END
2486
2487ROM_START(hisaturn)
2488   ROM_REGION( 0x480000, "maincpu", ROMREGION_ERASEFF ) /* SH2 code */
2489   ROM_LOAD("hisaturn.bin", 0x00000000, 0x00080000, CRC(721e1b60) SHA1(49d8493008fa715ca0c94d99817a5439d6f2c796))
2490   ROM_CART_LOAD("cart", 0x080000, 0x400000, ROM_NOMIRROR | ROM_OPTIONAL)
2491   ROM_REGION( 0x080000, "slave", 0 ) /* SH2 code */
2492   ROM_COPY( "maincpu",0,0,0x080000)
2493ROM_END
2494
2495/***************************************************************************
2496
2497  Game driver(s)
2498
2499***************************************************************************/
2500
2501/*    YEAR  NAME        PARENT  COMPAT  MACHINE INPUT   INIT        COMPANY     FULLNAME            FLAGS */
2502CONS( 1994, saturn,     0,      0,      saturn, saturn, saturnus,   "Sega",     "Saturn (USA)",     GAME_NOT_WORKING )
2503CONS( 1994, saturnjp,   saturn, 0,      saturn, saturn, saturnjp,   "Sega",     "Saturn (Japan)",   GAME_NOT_WORKING )
2504CONS( 1994, saturneu,   saturn, 0,      saturn, saturn, saturneu,   "Sega",     "Saturn (PAL)",     GAME_NOT_WORKING )
2505CONS( 1995, vsaturn,    saturn, 0,      saturn, saturn, saturnjp,   "JVC",      "V-Saturn",         GAME_NOT_WORKING )
2506CONS( 1995, hisaturn,   saturn, 0,      saturn, saturn, saturnjp,   "Hitachi",  "HiSaturn",         GAME_NOT_WORKING )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team