[wrap]
MAME source file: / src / mame / drivers / seta.c [download] (view on mamedev.org)
/***************************************************************************

                            -= Seta Hardware =-

                    driver by   Luca Elia (l.elia@tin.it)


CPU    :    68000 + [65C02] (only in the earlier games)
Custom :    X1-001A  X1-002A (SDIP64)   Sprites
            X1-001
            X1-002
            X1-003
            X1-004           (SDIP52)   Inputs
            X1-005   X0-005
            X1-006   X0-006
            X1-007           (SDIP42)   Vide DAC
            X1-010           (QFP80)    Sound: 16 Bit PCM
            X1-011   X1-012  (QFP100)   Tilemaps
            X1-014                      Sprites?

-------------------------------------------------------------------------------
Ordered by Board        Year + Game                         Licensed To
-------------------------------------------------------------------------------
P0-029-A (M6100287A)    88 Thundercade / Twin Formation (1) Taito
?        (M6100326A)    88 Twin Eagle                       Taito
P0-045-A (M6100429A)    89 DownTown                         Taito / RomStar
?        (M6100430A)    89 U.S. Classic(2)                  Taito / RomStar
?                       88 Caliber 50                       Taito / RomStar
?                       89 Arbalester                       Taito / RomStar
P1-036-A + P0-045-A +
P1-049-A                89 Meta Fox                         Taito / RomStar
P0-053-1                89 Castle of Dragon/Dragon Unit     Taito / RomStar / Athena
P0-053-A                91 Strike Gunner S.T.G              Athena / Tecmo
P0-053-A                92 Quiz Kokology                    Tecmo
P0-055-B                89 Wit's                            Athena
P0-055-D                90 Thunder & Lightning              Romstar / Visco
Promat PCB              94 Wiggie Waggie(5)                 --
P0-058-C                98 Internation Toote (6)            Coinmaster
P0-063-A                91 Rezon                            Allumer
P0-068-B (M6100723A)    92 Block Carnival                   Visco
P0-072-2 (prototype)    92 Blandia (prototype)              Allumer
P0-077-A (BP922)        92 Ultraman Club                    Banpresto
PO-078-A                92 Blandia                          Allumer
P0-079-A                92 Zing Zing Zip                    Allumer + Tecmo
P0-079-A                94 Eight Forces                     Tecmo
PO-080-A (BP923)        92 SD Gundam Neo Battling (3)       Banpresto
?                       93 Athena no Hatena?                Athena
?                       93 J.J.Squawkers                    Athena / Able
?        (93111A)       93 War Of Aero                      Yang Cheng
P0-081-A                93 Mobile Suit Gundam               Banpresto
PO-083-A (BP931)        93 Ultra Toukon Densetsu            Banpresto + Tsuburaya Prod.
PO-092-A                93 Daioh                            Athena
PO-096-A (BP934KA)      93 Kamen Rider                      Banpresto
P0-097-A                93 Oishii Puzzle ..                 Sunsoft + Atlus
bootleg                 9? Triple Fun (4)                   bootleg (Comad?)
P0-100-A                93 Quiz Kokology 2                  Tecmo
P0-101-1                94 Pro Mahjong Kiwame               Athena
PO-102-A                93 Mad Shark                        Allumer
PO-107-A (prototype?)   94 Orbs (prototype?)                American Sammy
P0-114-A (SKB-001)      94 Krazy Bowl                       American Sammy
P0-117-A (DH-01)        95 Extreme Downhill                 Sammy Japan
P0-117-A?               95 Sokonuke Taisen Game             Sammy Industries
P0-120-A (BP954KA)      95 Gundhara                         Banpresto
PO-122-A (SZR-001)      95 Zombie Raid                      American Sammy
?                       96 Crazy Fight                      Subsino
-------------------------------------------------------------------------------
(1) YM2203 + YM3812 instead of X1-010
(2) wrong colors
(3) Same board as "Ultraman Club" despite the different PCB number
(4) this is a bootleg of Oishii Puzzle, in english, is there an official
    version?  the sound system has been replaced with an OKI M6295
    hardware is definitely bootleg. standard simple layout board with no
    custom chips and no manufacturer on the pcb.
(5) The game code is based on Thunder and Lightning but the PCB is custom
    there are a few gfx emulation bugs (flipping of some border tiles and
    sprites not leaving the screen correctly) its possible the custom hw
    doesn't behave *exactly* the same as the original seta hw
(6) To enter test mode press 9 (open door), then F2 (turn function key), then E (bet 3-4).

Notes:
- The NEC D4701 used by Caliber 50 is a mouse interface IC (uPD4701c).
  Of course it's used to control the spinner. DownTown probably has it as well.

DIP Locations verified from manuals for:
- Zing Zing Zip
- Extreme Downhill

TODO:
- I think the best way to correctly align tilemaps and sprites and account for
  both flipping and different visible areas is to have a table with per game
  vertical and horizontal offsets for sprites, tilemaps and possibly the "floating
  tilemaps" (made of sprites) for both the flipped and normal screen cases.
  Current issues: metafox test grid not aligned when screen flipped, madshark & utoukond
  ("floating tilemaps" sprites when flipped)
  krzybowl not aligned vertically when screen flipped
  zombraid not aligned when flipped vertically or horizantally

- bad sound in sokonuke?
- in msgunda1, colors for the score display screw up after the second animation
  in attract mode. The end of the animation also has garbled sprites.
  Note that the animation is not present in msgundam.
- Some games: battery backed portion of RAM (e.g. downtown, kiwame, zombraid)
- the zombraid crosshair hack can go if the nvram regions are figured out.
- Some games: programmable timer that generates IRQ. See e.g. gundhara:
  lev 4 is triggerd by writes at d00000-6 and drives the sound.
  See also msgundam.

- tndrcade: lots of flickering sprites
- drgnunit sprite/bg unaligned when screen flipped (check I/O test in service mode)
- extdwnhl has some wrong colored tiles in one of the attract mode images and in
  later tracks.
- oisipuzl doesn't support screen flip? tilemap flipping is also kludged in the video driver.
- eightfrc has alignment problems both flipped and not
- flip screen and mirror support not working correctly in zombraid
- gundhara visible area might be smaller (zombraid uses the same MachineDriver, and
  the current area is right for it)
- crazyfgt: emulate protection & tickets, fix graphics glitches, find correct clocks,
  level 2 interrupt should probably be triggered by the 3812 but sound tends to die that way.

***************************************************************************/

/***************************************************************************

Thundercade / Twin Formation
Taito America Corp./Romstar USA/Seta, 1987

PCB Layout
---------
M6100287A
P0-029-A
|------------------------------------------------------------------|
|M    L    K     J     H     G     F     E     D     C     B     A1|
|A UA0-4  UA0-3  4364  UA0-2  UA0-1  4364           16MHz          |
|                                         X1-001           X1-002 2|
|  68000                                                           |
|                                                                  |
|                                                                 3|
|                                                                  |
|                                                                  |
|                       4364 4364   UA0-9  UA0-8  UA0-7  UA0-6    4|
|                                                                  |
|                                                                  |
|                                                                 5|
|                            4584                                  |
|                                                                  |
|                        RESET_SW   UA0-13 UA0-12 UA0-11 UA0-10   6|
|                        4050  TL7705                              |
|                                                                  |
|                                                                 7|
|      X0-006                                                      |
|                                                                  |
|                            SW1                                  8|
| UA10-5 2016 YM3812 YM2203                                        |
|            YM3014          SW2                   X1-006         9|
|VOL   4558  YM3014 M54528            X1-004                       |
|                                                                10|
|                         X2-003 X2-003 X2-003     X1-003          |
|                                                                11|
|            |--|              JAMMA               |--|            |
|------------|  |----------------------------------|  |------------|
Notes:
      68000  - clock 8.000MHz [16/2]
      YM3812 - clock 4.000MHz [16/4]
      YM2203 - clock 4.000MHz [16/4]
      4364   - 8kx8 SRAM
      2016   - 2kx8 SRAM
      VSync  - 59.1845Hz
      HSync  - 15.21kHz

      Custom Chips -
                    X1-001 (SDIP64)
                    X1-002 (SDIP64)
                    X1-006 (SDIP64)
                    X0-006 (SDIP64), also marked 'RP5A10-0001'. This is a 65C02 in disguise,
                                     possibly with additional ROM or logic acting as a protection chip.
                                     clocks - pin1 16MHz, pin2 2MHz, pin3 59.1845Hz [VSYNC),
                                     pin63 2MHz, pin62 2MHz
                    X1-003 (SDIP42)
                    X1-004 (SDIP52)
                    X2-003 (DIP16) - Resistor network IC for inputs

      ROMs -
             UA0-6 to AU0-13 DIP42 maskROM, read as MX27C2100 (2 Meg)
             UA0-2 DIP32 27C1000 EPROM
             All other ROMs DIP32 read as 27C1000
             All ROMs have IC locations, but the PCB also has IC locations so components
             can be referenced with IC# or location. See above diagram for info.

***************************************************************************/

/***************************************************************************

                                Twin Eagle

M6100326A   Taito (Seta)

ua2-4              68000
ua2-3
ua2-6
ua2-5
ua2-8
ua2-10
ua2-7               ua2-1
ua2-9
ua2-12
ua2-11              ua2-2

***************************************************************************/

/***************************************************************************

                                U.S. Classic

M6100430A (Taito 1989)

       u7 119  u6 118   u5 117   u4 116
                                         68000-8
u13  120                                 000
u19  121                                 001
u21  122                                 002
u29  123                                 003
u33  124
u40  125
u44  126
u51  127
u58  128
u60  129                                 65c02
u68  130
u75  131                                 u61 004

                                         u83 132

***************************************************************************/
/***************************************************************************

                                Caliber 50

CPU:   TMP 68000N-8, 65C02
Other: NEC D4701

UH-001-006        SW2  SW1
UH-001-007
UH-001-008                    8464         68000-8
UH-001-009  X1-002A X1-001A   8464         Uh-002-001=T01
UH-001-010                    8464            51832
UH-001-011                    8464            51832
                                           UH-001-002
UH-001-012            X1-012               UH-001-003
UH-001-013                               UH-002-004-T02
                      X1-011               5116-10
                                           BAT
                         16MHz
             X1-010   65C02      X1-006
                      UH-001-005 X1-007
                      4701       X1-004

***************************************************************************/
/***************************************************************************

                                    Meta Fox

(Seta 1990)

P0-045A

P1-006-163                    8464   68000-8
P1-007-164    X1-002A X1-001A 8464
P1-008-165                    8464
P1-009-166                    8464     256K-12
                                       256K-12

                 X1-012
                 X1-011


   2063    X1-010     X1-006     X0-006
                      X1-007
                      X1-004     X1-004

----------------------
P1-036-A

UP-001-010
UP-001-011
UP-001-012
UP-001-013


UP-001-014
UP-001-015

-----------------------
P1-049-A

              UP-001-001
              UP-001-002
              P1-003-161
              P1-004-162


              UP-001-005
              x

***************************************************************************/


/***************************************************************************

                                Dragon Unit
                     [Prototype of "Castle Of Dragon"]

PCB:    P0-053-1
CPU:    68000-8
Sound:  X1-010
OSC:    16.0000MHz

Chips:  X1-001A, X1-002A, X1-004, X1-006, X1-007, X1-010, X1-011, X1-012

***************************************************************************/
/***************************************************************************

                                    Wit's

(c)1989 Athena (distributed by Visco)
P0-055B (board is made by Seta)

CPU  : TMP68000N-8
Sound: X1-010
OSC  : 16.000MHz

ROMs:
UN001001.U1 - Main program (27256)
UN001002.U4 - Main program (27256)

UN001003.10A - Samples (28pin mask)
UN001004.12A /

UN001005.2L - Graphics (28pin mask)
UN001006.4L |
UN001007.5L |
UN001008.7L /

Custom chips:   X1-001A     X1-002A
                X1-004 (x2)
                X1-006
                X1-007
                X1-010

***************************************************************************/
/***************************************************************************

                            Thunder & Lightning

Location      Device      File ID      Checksum
-----------------------------------------------
U1  1A        27C256        M4           C18C   [ MAIN PROG ] [ EVEN ]
U4  3A        27C256        M5           12E1   [ MAIN PROG ] [ ODD  ]
U29 10A      23C4001        R27          37F2   [   HIGH    ]
U39 12A      23C4001        R28          0070   [   LOW     ]
U6  2K       23C1000        T14          1F7D   [   C40     ]
U9  4K       23C1000        T15          7A15   [   C30     ]
U14 5K       23C1000        T16          BFFD   [   C20     ]
U20 7K       23C1000        T17          7AE7   [   C10     ]

PCB: PO055D

CPU: 68000 8MHz

Custom: X1-001A     X1-002A
        X1-004
        X1-006
        X1-007
        X1-010

***************************************************************************/



/***************************************************************************

                                Athena no Hatena?

CPU  : 68000-16
Sound: X1-010
OSC  : 16.0000MHz

ROMs:
fs001001.evn - Main programs (27c4001)
fs001002.odd /

fs001004.pcm - Samples (8M mask - read as 27c800)
fs001003.gfx - Graphics (16M mask - read as 27c160)

Chips:  X1-001A X1-002A
        X1-004
        X1-006
        X1-007
        X1-010

***************************************************************************/

/***************************************************************************

                                Blandia

Blandia by Allumer

This set is coming from an original Blandia PCB ref : PO-078A

As usually, it use a lot of customs allumer chips !

***************************************************************************/
/***************************************************************************

                                Blandia (prototype)

PCB:    P0-072-2
CPU:    68000-16
Sound:  X1-010
OSC:    16.0000MHz

Chips:  X1-001A     X1-002A
        X1-004
        X1-007
        X1-010
        X1-011 x2   X1-012 x2

***************************************************************************/

/***************************************************************************

                    Block Carnival / Thunder & Lightning 2

P0-068B, M6100723A

CPU  : MC68000B8
Sound: X1-010
OSC  : 16.000MHz

ROMs:
u1.a1 - Main programs (27c010)
u4.a3 /

bl-chr-0.j3 - Graphics (4M mask)
bl-chr-1.l3 /

bl-snd-0.a13 - Sound (4M mask)

Custom chips:   X1-001A X1-002A
                X1-004
                X1-006
                X1-007
                X1-009
                X1-010

Other:
Lithium battery x1

***************************************************************************/




/***************************************************************************

                            Daioh

DAIOH
Alumer 1993, Sammy license
PO-092A


FG-001-003
FG-001-004  X1-002A X1-001A             FG-001-001
                                        FG-001-002
FG-001-005   X1-11 X1-12
FG-001-006   X1-11 X1-12
                                       68000-16
FG-001-007

   X1-10                           16MHz

                            X1-007  X1-004

***************************************************************************/


/***************************************************************************

                                Eight Forces

PO-079A (Same board as ZingZingZip)

CPU  : MC68000B16
Sound: X1-010
OSC  : 16.000MHz

ROMs:
uy2-u4.u3 - Main program (even)(27c2001)
uy2-u3.u4 - Main program (odd) (27c2001)

u63.bin - Sprites (HN62434, read as 27c4200)
u64.bin /

u69.bin - Samples (HN62318, read as 27c8001)
u70.bin /

u66.bin - Layer 1 (HN62418, read as 27c800)
u68.bin - Layer 2 (HN62418, read as 27c800)

PALs (not dumped):
uy-012.206 (PAL16L8A)
uy-013.14  (PAL16L8A)
uy-014.35  (PAL16L8A)
uy-015.36  (PALCE16V8)
uy-016.76  (PAL16L8A)
uy-017.116 (PAL16L8A)

Custom:     X1-001A X1-002A
            X1-004
            X1-007
            X1-010
            X1-011 (x2)     X1-012 (x2)

***************************************************************************/

/***************************************************************************

                                Extreme Downhill

(c)1995 Sammy
DH-01
PO-117A (board is made by Seta/Allumer)

CPU  : MC68HC000B16
Sound: X1-010
OSC: 16.0000MHz (X1), 14.3180MHz (X2)

ROMs:
fw001002.201 - Main program (even) (Macronics 27c4000)
fw001001.200 - Main program (odd)  (Macronics 27c4000)

fw001005.205 - (32pin mask, read as 27c8001)
fw001007.026 /

fw001003.202 - (42pin mask, read as 27c160)
fw001004.206 |
fw001006.152 /

PALs (16L8ACN, not dumped):
FW-001
FW-002
FW-003
FW-005

Custom chips:   X1-001A     X1-002A
                X1-004
                X1-007
                X1-010
                X1-011 (x2) X1-012 (x2)

***************************************************************************/


/***************************************************************************

                                    GundHara

(C) 1995 Banpresto
Seta/Allumer Hardware

PCB: BP954KA
PCB: PO-120A
CPU: TMP68HC000N16 (68000, 64 pin DIP)
SND: ?
OSC: 16.000MHz
RAM: 6264 x 8, 62256 x 4
DIPS: 2 x 8 position
Other Chips:    PALs x 6 (not dumped)
                NEC 71054C
                X1-004
                X1-007
                X1-010
                X1-011 x2   X1-012 x2
                X1-001A     X1-002A

On PCB near JAMMA connector is a small push button to reset the PCB.

ROMS:
BPGH-001.102    27C040
BPGH-002.103    27C4000
BPGH-003.U3     27C4000
BPGH-004.U4     23C4000
BPGH-005.200    23C16000
BPGH-006.201    23C16000
BPGH-007.U63    23C16000
BPGH-008.U64    23C16000
BPGH-009.U65    27C4000
BPGH-010.U66    TC538200
BPGH-011.U67    TC538000
BPGH-012.U68    TC5316200
BPGH-013.U70    TC538000

***************************************************************************/

/***************************************************************************

Zombie Raid
Sammy, 1996

This is a gun shooting game using Seta/Allumer hardware.

PCB Layout
----------

SZR-001
PO-122A
------------------------------------------------------------------
        FY001012.12L*       FY001009.U67      FY001007.U65
   FY001011.13L*    FY001010.U68     FY001008.U66    FY001006.U200
   X1-010    6264

    CONN1          X1-011(x2)     X1-002A
                   X1-012(x2)     X1-001A

                                            3V_BATT
                                                    4464

X1-007   6264(x2)   6264(x2)    6264(x2)    6264(x2)

       16.000MHz                                 HM9253101(x2)

X1-004 DSW2        D71054C
       DSW1    TMP68HC000N-16  FY001004.U4     FY001001.U102
                                      FY001003.U3    FY001002.U103
------------------------------------------------------------------

Notes:
*     = These ROMs located on a small daughterboard. Main PCB locations used as filename extension.
CONN1 = 8 pin header for gun connection

***************************************************************************/


/***************************************************************************

                                J.J. Squawkers

68HC000N -16N

2)   Alumer  X1-012
2)   Alumer  X1-011
2)   Alumer  X1-014

X1-010
X1-007
X1-004
16.000MHz

NEC 71054C  ----???

***************************************************************************/

/***************************************************************************

                                Kamen Rider
Kamen Riderclub Battleracer
Banpresto, 1993

Runs on Seta/Allumer hardware

PCB No: BP934KA   PO-096A
CPU   : MC68HC000B16
OSC   : 16.000MHz
RAM   : LH5160D-10L (x9), CXK58257AP-10L (x2)
DIPSW : 8 position (x2)
CUSTOM: X1-010
        X1-007
        X1-004
        X1-011 (x2)
        X1-012 (x2)
        X1-002A
        X1-001A
OTHER : NEC71054C, some PALs

ROMs  :
        FJ001007.152    27c4096     near X1-011 & X1-010 (sound program?)
        FJ001008.26     8M Mask     connected to X1-010, near FJ001007
        FJ001003.25     27c4096     main program for 68k
        FJ001006.22     16M Mask    gfx
        FJ001005.21     16M Mask    gfx

***************************************************************************/

/***************************************************************************

                                Krazy Bowl

PCB:    SKB-001
        PO-114A

FV   FV                           2465
001  001                          2465           X1-005
004  003      X1-002A  X1-001A
                                       58257     FV
                                                 001
                                                 002 (even)
                                       58257
                  14.318MHz                      FV
                                                 001
FV 001 005                                       001 (odd)
FV 001 006
  2465                                      68HC000B16
                 NEC4701  NEC4701

X1-010           X1-006
                 X1-007      X1-004

***************************************************************************/


/***************************************************************************


                                    Mad Shark

Allumer, 1993
This game is a vertical shoot'em-up and runs on fairly standard Allumer hardware.

PCB Layout
----------

PO-102A
----------------------------------------------------
|     X1-010   FQ001007 FQ001006 FQ001005 FQ001004 |
|           LH5160                                 |
|                    X1-011  X1-011       X1-002A  |
|                                                  |
|J                   X1-012  X1-012       X1-001A  |
|A X1-007                                          |
|M   LH5160           LH5160 LH5160 LH5160         |
|M                                                 |
|A   LH5160           LH5160 LH5160 LH5160         |
|                                         FQ001002 |
|*           MC68HC000B16                          |
|  X1-004                                          |
|                                         FQ001001 |
|                        LH52250                   |
| DSW2(8) DSW1(8) 16MHz  LH52250    D71054         |
----------------------------------------------------

Notes:
      *: 4 jumper pads for region selection (hardwired)

***************************************************************************/

/***************************************************************************

                            Mobile Suit Gundam

Banpresto 1993
P0-081A
                               SW2  SW1

FA-001-008                          FA-001-001
FA-001-007    X1-002A X1-001A       FA-002-002
                              5160
                              5160
                                        71054
FA-001-006                    5160     62256
FA-001-005    X1-011  X1-012  5160     62256

FA-001-004    X1-011  X1-012  5160
5160                          5160

                                68000-16

                                         16MHz
  X1-010
                    X1-007   X1-004     X1-005

***************************************************************************/

/***************************************************************************

                            Oishii Puzzle Ha Irimasenka

PCB  : PO-097A
CPU  : 68000
Sound: X1-010
OSC  : 14.31818MHz

All ROMs are 23c4000

Custom chips:   X1-001A X1-002A
                X1-004
                X1-007
                X1-010
                X1-011 (x2) X1-012 (x2)

***************************************************************************/

/***************************************************************************

                            Triple Fun

Triple Fun
??, 19??


CPU   : TMP68HC000P-16 (68000)
SOUND : OKI M6295
DIPSW : 8 position (x2)
XTAL  : 16.000 MHz (8MHz written on PCB, located near OKI chip)
        14.31818MHz (near 68000)
RAM   : 62256 (x2), 6264 (x8), 2018 (x14)
PROMs : None
PALs  : PALCE16V8H (x13)
OTHER : TPC1020AFN-084C (84 pin PLCC)

ROMs  :

04.bin + 05.bin    Main Program
01.bin             Sound Program
02.bin + 03.bin    OKI Samples
06.bin to 11.bin   GFX



***************************************************************************/

/***************************************************************************

                            Pro Mahjong Kiwame

PCB  : PO-101-1 (the board is made by Allumer/Seta)
CPU  : TMP68301AF-16 (68000 core)
Sound: X1-010
OSC  : 20.0000MHz

ROMs:
fp001001.bin - Main program (27c2001, even)
fp001002.bin - Main program (27c2001, odd)
fp001003.bin - Graphics (23c4000)
fp001005.bin - Samples (27c4000, high)
fp001006.bin - Samples (27c4000, low)

Chips:  X1-001A
        X1-002A
        X1-004
        X1-006
        X1-007
        X1-010

- To initialize high scores, power-on holding start button in service mode

***************************************************************************/


/***************************************************************************

                                Quiz Kokology

(c)1992 Tecmo

PO-053A

CPU  : MC68000B8
Sound: X1-010
OSC  : 16.000MHz

Custom chips:   X1-001A X1-002A
                X1-004
                X1-006  X1-007
                X1-010
                X1-011  X1-012

***************************************************************************/


/***************************************************************************

                                Quiz Koko-logy 2

(c)1992 Tecmo

P0-100A

CPU  : MC68HC000B16
Sound: X1-010
OSC  : 16.000MHz

FN001001.106 - Main program (27C4096)
FN001003.107 / (40pin 2M mask)

FN001004.100 - OBJ chr. (42pin mask)
FN001005.104 - BG chr. (42pin mask)
FN001006.105 - Samples (32pin mask)

Custom chips:   X1-001A     X1-002A
                X1-004
                X1-006
                X1-007
                X1-010
                X1-011      X1-012

***************************************************************************/


/***************************************************************************

                                Rezon (Japan)

PCB     : PO-063A
CPU     : TOSHIBA TMP68HC000N-16
Sound   : X1-010
OSC     : 16.000MHz
Other   : Allumer
            X1-001A         X1-002A
            X1-004
            X1-007
            X1-011 x 2      X1-012 x 2

***************************************************************************/


/***************************************************************************

                            SD Gundam Neo Battling

Banpresto, 1992
This game runs on Seta/Allumer hardware

PCB Layout
----------

PO-080A
BP923
|----------------------------------------------
|DSW1  DSW2                   LH5168  62256   |
|                             LH5168  62256   |
|LH5168                                       |
|                                             |
|         BP923004                   BP923001 |
|BP923005 BP923003 X1-002A X1-001A   BP923002 |
|                                  16MHz      |
|                              TMP68HC000N-16 |
|X1-010                           PAL         |
|                                 PAL  X1-006 |
|                                             |
|                                             |
|                              X1-004  X1-007 |
|                                             |
|                                             |
|                                             |
|                                             |
|                 J A M M A                   |
-----------------------------------------------

Notes:
      68k clock: 16.000MHz
      VSync: 58Hz
      HSync: 15.22kHz


***************************************************************************/


/***************************************************************************

                            Sokonuke Taisen Game (Japan)

(c)1995 Sammy

CPU:    68HC000
Sound:  All PCM ?
OSC:    16MHz

***************************************************************************/


/***************************************************************************

                                Strike Gunner

(c)1991 Athena (distributed by Tecmo)

PO-053A

CPU  : TMP68000N-8
Sound: X1-010
OSC  : 16.000MHz

Custom chips:   X1-001A X1-002A
                X1-004
                X1-006  X1-007
                X1-010
                X1-011  X1-012

***************************************************************************/

/***************************************************************************

                                Ultraman Club

Banpresto, 1992
Board looks similar to Castle of Dragon PCB.

PCB No: PO-077A (Seta Number)
        BP922   (Banpresto Number)

CPU: MC68HC000B16
OSC: 16.000MHz
DIP SW x 2 (8 position)

RAM: Sharp LH5160D-10L x 3, Hitachi S256KLP-12 x 2
PALs (2 x PAL16L8, not dumped)
SETA Chips: X1-010
            X1-004
            X1-007
            X1-006
            X1-002A
            X1-001A

Controls are 8 way Joystick and 2 buttons.

ROMs:

UW001006.U48      27C010                                               \  Main Program
UW001007.U49      27C010                                               /

BP-U-001.U1       4M mask (40 pin, 512k x 8), read as MX27C4100        \  GFX
BP-U-002.U2       4M mask (40 pin, 512k x 8), read as MX27C4100        /

BP-U-003.U13      8M mask (32 pin, 1M x 8),   read as MX27C8000           Sound


***************************************************************************/

/***************************************************************************
Ultra Toukon Densetsu
Banpresto, 1993

This game runs on fairly standard Allumer hardware.

PCB Layout
----------

PO-083A
BP931
----------------------------------------------------
|     X1-010  93UTA08  93UTA06 93UTA04  93UTA02    |
|                93UTA07 93UTA05  93UTA03  93UTA01 |
|  YM3438   LH5116                                 |
|  LH5116            X1-011  X1-011       X1-002A  |
|  Z80 93UTA009                                    |
|J                   X1-012  X1-012       X1-001A  |
|A X1-007                                          |
|M   LH5116           LH5160 LH5160 LH5160         |
|M                                                 |
|A   LH5116           LH5160 LH5160 LH5160         |
|                                                  |
|*      16MHz                                      |
|  X1-004                                   62256  |
|                                           62256  |
| DSW1(8)               93UTA011  93UTA010         |
| DSW2(8)   68HC000N-16                            |
----------------------------------------------------

Notes:
      *: 4 jumper pads for region selection (hardwired)
      Z80 clock = 4.000MHz
      VSync: 60Hz
      HSync: 15.21kHz


1.048.576 93uta03.63
1.048.576 93uta04.64
1.048.576 93uta05.66
1.048.576 93uta06.67
1.048.576 93uta07.68
1.048.576 93uta08.69

***************************************************************************/

/***************************************************************************

                               War of Aero
                            Project M E I O U

93111A  YANG CHENG

CPU   : TOSHIBA TMP68HC000N-16
Sound : Allumer X1-010
OSC   : 16.000000MHz
Other : Allumer
            X1-001A  X1-002A
            X1-004
            X1-007
            X1-011 x 2
            X1-012 x 2
        NEC
            C324C
            D71054C

***************************************************************************/



/***************************************************************************

                                Zing Zing Zip

P0-079A

UY-001-005   X1-002A   X1-001A   5168-10      256k-12
UY-001-006                       5168-10      UY-001-001
UY-001-007                                    UY-001-002
UY-001-008   X1-011 X1-012                    58257-12
                                 5168-10
UY-001-010   X1-011 X1-012       5168-10
UY-001-017
UY-001-018
                                 5168-10
X1-010                           5168-10       68000-16


                           8464-80
                           8464-80       16MHz


                             X1-007    X1-004

***************************************************************************


Pairs Love
Allumer, 199x

PCB Layout
----------

PO-068B
|-----------------------------------------|
|             X1-007  X1-006   UT2-001-005|
|                                         |
|     4050                     UT2-001-004|
|                                         |
|                                         |
|                             X1-002A     |
|                                         |
|J                                        |
|A   X1-004                               |
|M                            X1-001A     |
|M           DSW1                         |
|A                                        |
|            DSW2                  6264   |
|                                  6264   |
|    X1-009                               |
|                      62256              |
|                                         |
|                    68000                |
|    UT2-001-003       62256  UT2-001-002 |
|                   6264                  |
|    X1-010  16MHz            UT2-001-001 |
|-----------------------------------------|
Notes:
      68000 clock: 8.000MHz
      VSync: 60Hz


***************************************************************************

Rezon (Taito License)
Allumer / Taito, 1992

This game runs on fairly standard Allumer hardware.

PCB Layout
----------

P0-063A (Allumer code printed on the PCB)
M6100627A REZON (Taito sticker)
|-----------------------------------------------------------|
|  VOL   3404   6264 US001009     US001007      US001005    |
| MB3730                    US001008      US001006          |
|                                                           |
|                                                           |
|                                                           |
|  PAL4           X1-010       X1-011       X1-011          |
|                                                           |
|                                                           |
|J                                                          |
|A                             X1-012       X1-012          |
|M                                                          |
|M  X1-007                                                  |
|A                                                          |
|        6116  6116                           PAL2   PAL3   |
|                                                           |
|                         62256       62256                 |
|  16MHZ                  62256       62256     6264  6264  |
|         DSW2(8)                                           |
|  X1-004                 PAL1                              |
|         DSW1(8)  |------------|US001004      REZON_1_P    |
|                  |   68000    |   US001003      REZON_0_P |
|  RESET_SW        |------------|       62256          62256|
|-----------------------------------------------------------|
Notes:
      68000 clock  - 16.000MHz
      X1-010 clocks - pin1 16.000MHz, pin2 8.000MHz, pin79 4.000MHz, pin80 2.000MHz
      VSync - 57.5Hz
      PAL1  - PAL16L8 labelled 'US-010'
      PAL2  - PAL16L8 labelled 'US-011'
      PAL3  - PAL16L8 labelled 'US-012'
      PAL4  - PAL16L8 labelled 'US-013'
      62256 - 32K x8 SRAM
      6264  - 8K x8 SRAM
      6116  - 2K x8 SRAM

      Custom IC's -
                    X1-001A (SDIP64)    \ Sprite Generators
                    X1-002A (SDIP64)    /
                    X1-004  (SDIP52)      Input Related Functions (connected to joystick/input controls)
                    X1-007  (SDIP42)      Video DAC? (connected to RGB output)
                    X1-010  (QFP80)       Sound Chip, 16Bit PCM
                    X1-011  (x2, QFP100)\ Tilemap Generators
                    X1-012  (x2, QFP100)/

      ROMs -
            Filename         Type               Use
            ---------------------------------------------------
            REZON_0_P.U3     27C1000 (DIP32)    \
            REZON_1_P.U4     27C1000 (DIP32)    | 68000 Program
            US001003.U102    27C1000 (DIP32)    |
            US001004.U103    27C1000 (DIP32)    /

            US001005.U63     4M MaskROM (DIP42) \ Sprites
            US001006.U64     4M MaskROM (DIP42) /

            US001007.U66     4M MaskROM (DIP42) \ Tiles
            US001008.U68     4M MaskROM (DIP42) /

            US001009.U70     4M MaskROM (DIP32)   PCM Samples

***************************************************************************/

/***************************************************************************

Crazy Fight

x1-11
x1-11
x1-12
x1-12
x1-001a
x1-002a
x1-007
Lattlice PLSI 1032 FPGA
oki 6295
ym3812
68000

***************************************************************************/

/***************************************************************************
                                Internation Toote

Main PCB (P0-058C):

    TOSHIBA TMP68HC000N-16
    X1-010
    X1-001A
    X1-002A
    X1-004 (x2)
    X1-007
    X1-011
    X1-012
    HD63B50P

Horse Race I/O Expansion (PCB-HRE-000):

    MC68B50CP (x2)
    EF68B21P  (x2)

Note: on screen copyright is (c)1998 Coinmaster.
      The I/O board has      (c)1993 Coinmaster.

***************************************************************************/

#include "driver.h"
#include "deprecat.h"
#include "seta.h"
#include "machine/6821pia.h"
#include "machine/6850acia.h"
#include "machine/msm6242.h"
#include "sound/2203intf.h"
#include "sound/2612intf.h"
#include "sound/3812intf.h"
#include "sound/okim6295.h"
#include "sound/x1_010.h"

/* Variables and functions only used here */

static UINT8 port_select;     /* for muxed controls in 'usclssic' */

static UINT8 *sharedram;


#if __uPD71054_TIMER

#define	USED_TIMER_NUM	1
/*------------------------------
    timer(uPD71054) struct
------------------------------*/
static struct st_chip {
	emu_timer *timer[3];			// Timer
	UINT16	max[3];				// Max counter
	UINT16	write_select;		// Max counter write select
	UINT8	reg[4];				//
} uPD71054;

/*------------------------------
    uppdate timer
------------------------------*/
static void uPD71054_update_timer( running_machine *machine, int no )
{
	UINT16 max = uPD71054.max[no]&0xffff;

	if( max != 0 ) {
		attotime period = attotime_mul(ATTOTIME_IN_HZ(cpu_get_clock(machine->cpu[0])), 16 * max);
		timer_adjust_oneshot( uPD71054.timer[no], period, no );
	} else {
		timer_adjust_oneshot( uPD71054.timer[no], attotime_never, no);
		logerror( "CPU #0 PC %06X: uPD71054 error, timer %d duration is 0\n",
				cpu_get_pc(machine->activecpu), no );
	}
}



/*------------------------------
    callback
------------------------------*/
static TIMER_CALLBACK( uPD71054_timer_callback )
{
	cpu_set_input_line(machine->cpu[0], 4, HOLD_LINE );
	uPD71054_update_timer( machine, param );
}



/*------------------------------
    initialize
------------------------------*/
static void uPD71054_timer_init( void )
{
	int no;

	uPD71054.write_select = 0;

	for( no = 0; no < USED_TIMER_NUM; no++ ) {
		uPD71054.max[no] = 0xffff;
	}
	for( no = 0; no < USED_TIMER_NUM; no++ ) {
		uPD71054.timer[no] = timer_alloc( uPD71054_timer_callback , NULL);
	}
}



/*------------------------------
    timer write handler
------------------------------*/
static WRITE16_HANDLER( timer_regs_w )
{
	data &= 0xff;

	uPD71054.reg[offset] = data;

	switch( offset ) {
	  case 0x0000:
	  case 0x0001:
	  case 0x0002:
		if( uPD71054.write_select == 0 ) {
			uPD71054.max[offset] = (uPD71054.max[offset]&0xff00)+data;
			if( ((uPD71054.reg[3]>>4)&3) == 3 ) {
				uPD71054.write_select = 1;
			}
		} else {
			uPD71054.max[offset] = (uPD71054.max[offset]&0x00ff)+(data<<8);
		}
		if( uPD71054.max[offset] != 0 ) {
			uPD71054_update_timer( space->machine, offset );
		}
		break;
	  case 0x0003:
		switch( (data>>4)&3 ) {
		  case 2: uPD71054.write_select = 1; break;
		  case 1:
		  case 3: uPD71054.write_select = 0; break;
		}
		break;
	}
}
#endif	// __uPD71054_TIMER




/***************************************************************************


                                    Sound


***************************************************************************/

static const x1_010_interface seta_sound_intf =
{
	0x0000,		/* address */
};
static const x1_010_interface seta_sound_intf2 =
{
	0x1000,		/* address */
};

static void utoukond_ym3438_interrupt(running_machine *machine, int linestate)
{
	cpu_set_input_line(machine->cpu[1], INPUT_LINE_NMI, linestate);
}

static const ym3438_interface utoukond_ym3438_intf =
{
	utoukond_ym3438_interrupt	// IRQ handler
};

/***************************************************************************


                                Common Routines


***************************************************************************/

/*

 Mirror RAM

*/
static UINT16 *mirror_ram;

static READ16_HANDLER( mirror_ram_r )
{
	return mirror_ram[offset];
}

static WRITE16_HANDLER( mirror_ram_w )
{
	COMBINE_DATA(&mirror_ram[offset]);
//  logerror("PC %06X - Mirror RAM Written: %04X <- %04X\n", cpu_get_pc(space->cpu), offset*2, data);
}



/*

 Shared RAM:

 The 65c02 sees a linear array of bytes that is mapped, for the 68000,
 to a linear array of words whose low order bytes hold the data

*/

static READ16_HANDLER( sharedram_68000_r )
{
	return ((UINT16) sharedram[offset]) & 0xff;
}

static WRITE16_HANDLER( sharedram_68000_w )
{
	if (ACCESSING_BITS_0_7)	sharedram[offset] = data & 0xff;
}




/*

 Sub CPU Control

*/

static WRITE16_HANDLER( sub_ctrl_w )
{
	static int old_data = 0;
	switch(offset)
	{
		case 0/2:	// bit 0: reset sub cpu?
			if (ACCESSING_BITS_0_7)
			{
				if ( !(old_data&1) && (data&1) )
					cpu_set_input_line(space->machine->cpu[1], INPUT_LINE_RESET, PULSE_LINE);
				old_data = data;
			}
			break;

		case 2/2:	// ?
			break;

		case 4/2:	// not sure
			if (ACCESSING_BITS_0_7)	soundlatch_w(space, 0, data & 0xff);
			break;

		case 6/2:	// not sure
			if (ACCESSING_BITS_0_7)	soundlatch2_w(space, 0, data & 0xff);
			break;
	}

}


/* DSW reading for 16 bit CPUs */
static READ16_HANDLER( seta_dsw_r )
{
	UINT16 dsw = input_port_read(space->machine, "DSW");
	if (offset == 0)	return (dsw >> 8) & 0xff;
	else				return (dsw >> 0) & 0xff;
}


/* DSW reading for 8 bit CPUs */

static READ8_HANDLER( dsw1_r )
{
	return (input_port_read(space->machine, "DSW") >> 8) & 0xff;
}

static READ8_HANDLER( dsw2_r )
{
	return (input_port_read(space->machine, "DSW") >> 0) & 0xff;
}


/*

 Sprites Buffering

*/
static VIDEO_EOF( seta_buffer_sprites )
{
	int ctrl2	=	spriteram16[ 0x602/2 ];
	if (~ctrl2 & 0x20)
	{
		if (ctrl2 & 0x40)
			memcpy(&spriteram16_2[0x0000/2],&spriteram16_2[0x2000/2],0x2000/2);
		else
			memcpy(&spriteram16_2[0x2000/2],&spriteram16_2[0x0000/2],0x2000/2);
	}
}


/***************************************************************************


                                    Main CPU

(for debugging it is useful to be able to peek at some memory regions that
 the game writes to but never reads from. I marked this regions with an empty
 comment to distinguish them, since there's always the possibility that some
 games actually read from this kind of regions, expecting some hardware
 register's value there, instead of the data they wrote)

***************************************************************************/


/***************************************************************************
                                Thundercade
***************************************************************************/

/* Mirror RAM seems necessary since the e00000-e03fff area is not cleared
   on startup. Level 2 int uses $e0000a as a counter that controls when
   to write a value to the sub cpu, and when to read the result back.
   If the check fails "error x0-006" is displayed. Hence if the counter
   is not cleared at startup the game could check for the result before
   writing to sharedram! */


static ADDRESS_MAP_START( tndrcade_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0x380000, 0x3803ff) AM_READ(SMH_RAM				)	// Palette
/**/AM_RANGE(0x400000, 0x400001) AM_READ(SMH_RAM				)	// ? $4000
/**/AM_RANGE(0x600000, 0x600607) AM_READ(SMH_RAM				)	// Sprites Y
	AM_RANGE(0xa00000, 0xa00fff) AM_READ(sharedram_68000_r		)	// Shared RAM
	AM_RANGE(0xc00000, 0xc03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
	AM_RANGE(0xe00000, 0xe03fff) AM_READ(SMH_RAM				)	// RAM (Mirrored?)
	AM_RANGE(0xffc000, 0xffffff) AM_READ(mirror_ram_r			)	// RAM (Mirrored?)
ADDRESS_MAP_END

static ADDRESS_MAP_START( tndrcade_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_WRITE(SMH_ROM						)	// ROM
	AM_RANGE(0x200000, 0x200001) AM_WRITE(SMH_NOP						)	// ? 0
	AM_RANGE(0x280000, 0x280001) AM_WRITE(SMH_NOP						)	// ? 0 / 1 (sub cpu related?)
	AM_RANGE(0x300000, 0x300001) AM_WRITE(SMH_NOP						)	// ? 0 / 1
	AM_RANGE(0x380000, 0x3803ff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0x400000, 0x400001) AM_WRITE(SMH_RAM						)	// ? $4000
	AM_RANGE(0x600000, 0x600607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16		)	// Sprites Y
	AM_RANGE(0x800000, 0x800007) AM_WRITE(sub_ctrl_w					)	// Sub CPU Control?
	AM_RANGE(0xa00000, 0xa00fff) AM_WRITE(sharedram_68000_w				)	// Shared RAM
	AM_RANGE(0xc00000, 0xc03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2		)	// Sprites Code + X + Attr
	AM_RANGE(0xe00000, 0xe03fff) AM_WRITE(SMH_RAM) AM_BASE(&mirror_ram		)	// RAM (Mirrored?)
	AM_RANGE(0xffc000, 0xffffff) AM_WRITE(mirror_ram_w					)	// RAM (Mirrored?)
ADDRESS_MAP_END


/***************************************************************************
                Twin Eagle, DownTown, Arbalester, Meta Fox
        (with slight variations, and Meta Fox protection hooked in)
***************************************************************************/

static ADDRESS_MAP_START( downtown_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x09ffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0x100000, 0x103fff) AM_READ(seta_sound_word_r		)	// Sound
	AM_RANGE(0x200000, 0x200001) AM_READ(SMH_NOP				)	// watchdog? (twineagl)
	AM_RANGE(0x600000, 0x600003) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x700000, 0x7003ff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0x900000, 0x901fff) AM_READ(SMH_RAM				)	// VRAM
	AM_RANGE(0x902000, 0x903fff) AM_READ(SMH_RAM				)	// VRAM
	AM_RANGE(0xb00000, 0xb00fff) AM_READ(sharedram_68000_r		)	// Shared RAM
	AM_RANGE(0xd00000, 0xd003ff) AM_READ(SMH_RAM				)	// Sprites Y
	AM_RANGE(0xe00000, 0xe03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
	AM_RANGE(0xf00000, 0xffffff) AM_READ(SMH_RAM				)	// RAM
ADDRESS_MAP_END

static ADDRESS_MAP_START( downtown_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x09ffff) AM_WRITE(SMH_ROM						)	// ROM
	AM_RANGE(0x100000, 0x103fff) AM_WRITE(seta_sound_word_w				)	// Sound
	AM_RANGE(0x200000, 0x200001) AM_WRITE(SMH_NOP						)	// watchdog?
	AM_RANGE(0x300000, 0x300001) AM_WRITE(SMH_NOP						)	// IRQ enable/acknowledge?
	AM_RANGE(0x400000, 0x400007) AM_WRITE(twineagl_tilebank_w			)	// special tile banking to animate water in twineagl
	AM_RANGE(0x500000, 0x500001) AM_WRITE(SMH_NOP						)	// ?
	AM_RANGE(0x700000, 0x7003ff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0x800000, 0x800005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_0		)	// VRAM Ctrl
	AM_RANGE(0x900000, 0x903fff) AM_WRITE(seta_vram_0_w) AM_BASE(&seta_vram_0	)	// VRAM
	AM_RANGE(0xa00000, 0xa00007) AM_WRITE(sub_ctrl_w					)	// Sub CPU Control?
	AM_RANGE(0xb00000, 0xb00fff) AM_WRITE(sharedram_68000_w				)	// Shared RAM
	AM_RANGE(0xc00000, 0xc00001) AM_WRITE(SMH_RAM						)	// ? $4000
	AM_RANGE(0xd00000, 0xd00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16		)	// Sprites Y
	AM_RANGE(0xe00000, 0xe03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2		)	// Sprites Code + X + Attr
	AM_RANGE(0xf00000, 0xffffff) AM_WRITE(SMH_RAM						)	// RAM
ADDRESS_MAP_END


/***************************************************************************
                                Caliber 50
***************************************************************************/

static READ16_HANDLER ( calibr50_ip_r )
{
	int dir1 = input_port_read(space->machine, "ROT1") & 0xfff;	// analog port
	int dir2 = input_port_read(space->machine, "ROT2") & 0xfff;	// analog port

	switch (offset)
	{
		case 0x00/2:	return input_port_read(space->machine, "P1");	// p1
		case 0x02/2:	return input_port_read(space->machine, "P2");	// p2

		case 0x08/2:	return input_port_read(space->machine, "COINS");	// Coins

		case 0x10/2:	return (dir1&0xff);			// lower 8 bits of p1 rotation
		case 0x12/2:	return (dir1>>8);			// upper 4 bits of p1 rotation
		case 0x14/2:	return (dir2&0xff);			// lower 8 bits of p2 rotation
		case 0x16/2:	return (dir2>>8);			// upper 4 bits of p2 rotation
		case 0x18/2:	return 0xffff;				// ? (value's read but not used)
		default:
			logerror("PC %06X - Read input %02X !\n", cpu_get_pc(space->cpu), offset*2);
			return 0;
	}
}

static WRITE16_HANDLER( calibr50_soundlatch_w )
{
	if (ACCESSING_BITS_0_7)
	{
		soundlatch_word_w(space,0,data,mem_mask);
		cpu_set_input_line(space->machine->cpu[1], INPUT_LINE_NMI, PULSE_LINE);
		cpu_spinuntil_time(space->cpu, ATTOTIME_IN_USEC(50));	// Allow the other cpu to reply
	}
}

static ADDRESS_MAP_START( calibr50_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x09ffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0xff0000, 0xffffff) AM_READ(SMH_RAM				)	// RAM
	AM_RANGE(0x100000, 0x100007) AM_READ(SMH_NOP				)	// ? (same as a00010-a00017?)
	AM_RANGE(0x200000, 0x200fff) AM_READ(SMH_RAM				)	// NVRAM
	AM_RANGE(0x300000, 0x300001) AM_READ(SMH_NOP				)	// ? (value's read but not used)
	AM_RANGE(0x400000, 0x400001) AM_READ(watchdog_reset16_r		)	// Watchdog
	AM_RANGE(0x600000, 0x600003) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x700000, 0x7003ff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0x900000, 0x901fff) AM_READ(SMH_RAM				)	// VRAM
	AM_RANGE(0x902000, 0x903fff) AM_READ(SMH_RAM				)	// VRAM
	AM_RANGE(0x904000, 0x904fff) AM_READ(SMH_RAM				)	//
	AM_RANGE(0xa00000, 0xa00019) AM_READ(calibr50_ip_r			)	// Input Ports
/**/AM_RANGE(0xd00000, 0xd00607) AM_READ(SMH_RAM				)	// Sprites Y
	AM_RANGE(0xe00000, 0xe03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
	AM_RANGE(0xb00000, 0xb00001) AM_READ(soundlatch2_word_r		)	// From Sub CPU
/**/AM_RANGE(0xc00000, 0xc00001) AM_READ(SMH_RAM				)	// ? $4000
ADDRESS_MAP_END

static ADDRESS_MAP_START( calibr50_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x09ffff) AM_WRITE(SMH_ROM						)	// ROM
	AM_RANGE(0xff0000, 0xffffff) AM_WRITE(SMH_RAM						)	// RAM
	AM_RANGE(0x200000, 0x200fff) AM_WRITE(SMH_RAM						)	// NVRAM
	AM_RANGE(0x300000, 0x300001) AM_WRITE(SMH_NOP						)	// ? (random value)
	AM_RANGE(0x500000, 0x500001) AM_WRITE(SMH_NOP						)	// ?
	AM_RANGE(0x700000, 0x7003ff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0x800000, 0x800005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_0		)	// VRAM Ctrl
	AM_RANGE(0x900000, 0x903fff) AM_WRITE(seta_vram_0_w) AM_BASE(&seta_vram_0	)	// VRAM
	AM_RANGE(0x904000, 0x904fff) AM_WRITE(SMH_RAM						)	//
	AM_RANGE(0xd00000, 0xd00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16		)	// Sprites Y
	AM_RANGE(0xe00000, 0xe03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2		)	// Sprites Code + X + Attr
	AM_RANGE(0xb00000, 0xb00001) AM_WRITE(calibr50_soundlatch_w			)	// To Sub CPU
	AM_RANGE(0xc00000, 0xc00001) AM_WRITE(SMH_RAM						)	// ? $4000
ADDRESS_MAP_END


/***************************************************************************
                                U.S. Classic
***************************************************************************/

static READ16_HANDLER( usclssic_dsw_r )
{
	switch (offset)
	{
		case 0/2:	return (input_port_read(space->machine, "DSW") >>  8) & 0xf;
		case 2/2:	return (input_port_read(space->machine, "DSW") >> 12) & 0xf;
		case 4/2:	return (input_port_read(space->machine, "DSW") >>  0) & 0xf;
		case 6/2:	return (input_port_read(space->machine, "DSW") >>  4) & 0xf;
	}
	return 0;
}

static READ16_HANDLER( usclssic_trackball_x_r )
{
	static const char *const portx_name[2] = { "P1X", "P2X" };
	switch (offset)
	{
		case 0/2:	return (input_port_read(space->machine, portx_name[port_select]) >> 0) & 0xff;
		case 2/2:	return (input_port_read(space->machine, portx_name[port_select]) >> 8) & 0xff;
	}
	return 0;
}

static READ16_HANDLER( usclssic_trackball_y_r )
{
	static const char *const porty_name[2] = { "P1Y", "P2Y" };
	switch (offset)
	{
		case 0/2:	return (input_port_read(space->machine, porty_name[port_select]) >> 0) & 0xff;
		case 2/2:	return (input_port_read(space->machine, porty_name[port_select]) >> 8) & 0xff;
	}
	return 0;
}


static WRITE16_HANDLER( usclssic_lockout_w )
{
	static int old_tiles_offset = 0;

	if (ACCESSING_BITS_0_7)
	{
		port_select = (data & 0x40) >> 6;

		seta_tiles_offset = (data & 0x10) ? 0x4000: 0;
		if (old_tiles_offset != seta_tiles_offset)	tilemap_mark_all_tiles_dirty(ALL_TILEMAPS);
		old_tiles_offset = seta_tiles_offset;

		seta_coin_lockout_w(space->machine, data);
	}
}


static ADDRESS_MAP_START( usclssic_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_READ(SMH_ROM					)	// ROM
	AM_RANGE(0xff0000, 0xffffff) AM_READ(SMH_RAM					)	// RAM
	AM_RANGE(0x800000, 0x800607) AM_READ(SMH_RAM					)	// Sprites Y
/**/AM_RANGE(0x900000, 0x900001) AM_READ(SMH_RAM					)	// ?
	AM_RANGE(0xa00000, 0xa00005) AM_READ(SMH_RAM					)	// VRAM Ctrl
/**/AM_RANGE(0xb00000, 0xb003ff) AM_READ(SMH_RAM					)	// Palette
	AM_RANGE(0xb40000, 0xb40003) AM_READ(usclssic_trackball_x_r		)	// TrackBall X
	AM_RANGE(0xb40004, 0xb40007) AM_READ(usclssic_trackball_y_r		)	// TrackBall Y + Buttons
	AM_RANGE(0xb40010, 0xb40011) AM_READ_PORT("COINS")					// Coins
	AM_RANGE(0xb40018, 0xb4001f) AM_READ(usclssic_dsw_r				)	// 2 DSWs
	AM_RANGE(0xb80000, 0xb80001) AM_READ(SMH_NOP					)	// watchdog (value is discarded)?
	AM_RANGE(0xc00000, 0xc03fff) AM_READ(SMH_RAM					)	// Sprites Code + X + Attr
	AM_RANGE(0xd00000, 0xd01fff) AM_READ(SMH_RAM					)	// VRAM
	AM_RANGE(0xd02000, 0xd03fff) AM_READ(SMH_RAM					)	// VRAM
	AM_RANGE(0xd04000, 0xd04fff) AM_READ(SMH_RAM					)	//
	AM_RANGE(0xe00000, 0xe00fff) AM_READ(SMH_RAM					)	// NVRAM? (odd bytes)
ADDRESS_MAP_END

static ADDRESS_MAP_START( usclssic_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_WRITE(SMH_ROM						)	// ROM
	AM_RANGE(0xff0000, 0xffffff) AM_WRITE(SMH_RAM						)	// RAM
	AM_RANGE(0x800000, 0x800607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16		)	// Sprites Y
	AM_RANGE(0x900000, 0x900001) AM_WRITE(SMH_RAM						)	// ? $4000
	AM_RANGE(0xa00000, 0xa00005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_0		)	// VRAM Ctrl
	AM_RANGE(0xb00000, 0xb003ff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0xb40000, 0xb40001) AM_WRITE(usclssic_lockout_w			)	// Coin Lockout + Tiles Banking
	AM_RANGE(0xb40010, 0xb40011) AM_WRITE(calibr50_soundlatch_w			)	// To Sub CPU
	AM_RANGE(0xb40018, 0xb40019) AM_WRITE(watchdog_reset16_w			)	// Watchdog
	AM_RANGE(0xb4000a, 0xb4000b) AM_WRITE(SMH_NOP						)	// ? (value's not important. In lev2&6)
	AM_RANGE(0xc00000, 0xc03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2	)	// Sprites Code + X + Attr
	AM_RANGE(0xd00000, 0xd03fff) AM_WRITE(seta_vram_0_w) AM_BASE(&seta_vram_0	)	// VRAM
	AM_RANGE(0xd04000, 0xd04fff) AM_WRITE(SMH_RAM						)	//
	AM_RANGE(0xe00000, 0xe00fff) AM_WRITE(SMH_RAM						)	// NVRAM? (odd bytes)
ADDRESS_MAP_END



/***************************************************************************
                                Athena no Hatena?
***************************************************************************/

static ADDRESS_MAP_START( atehate_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x0fffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0x900000, 0x9fffff) AM_READ(SMH_RAM				)	// RAM
	AM_RANGE(0x100000, 0x103fff) AM_READ(seta_sound_word_r		)	// Sound
	AM_RANGE(0x600000, 0x600003) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x700000, 0x7003ff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0xa00000, 0xa00607) AM_READ(SMH_RAM				)	// Sprites Y
	AM_RANGE(0xb00000, 0xb00001) AM_READ_PORT("P1")					// P1
	AM_RANGE(0xb00002, 0xb00003) AM_READ_PORT("P2")					// P2
	AM_RANGE(0xb00004, 0xb00005) AM_READ_PORT("COINS")				// Coins
/**/AM_RANGE(0xc00000, 0xc00001) AM_READ(SMH_RAM				)	// ? 0x4000
	AM_RANGE(0xe00000, 0xe03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
ADDRESS_MAP_END

static ADDRESS_MAP_START( atehate_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x0fffff) AM_WRITE(SMH_ROM					)	// ROM
	AM_RANGE(0x900000, 0x9fffff) AM_WRITE(SMH_RAM					)	// RAM
	AM_RANGE(0x100000, 0x103fff) AM_WRITE(seta_sound_word_w			)	// Sound
	AM_RANGE(0x200000, 0x200001) AM_WRITE(SMH_NOP					)	// ? watchdog ?
	AM_RANGE(0x300000, 0x300001) AM_WRITE(SMH_NOP					)	// ? 0 (irq ack lev 2?)
	AM_RANGE(0x500000, 0x500001) AM_WRITE(SMH_NOP					)	// ? (end of lev 1: bit 4 goes 1,0,1)
	AM_RANGE(0x700000, 0x7003ff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0xa00000, 0xa00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16	)	// Sprites Y
	AM_RANGE(0xc00000, 0xc00001) AM_WRITE(SMH_RAM					)	// ? 0x4000
	AM_RANGE(0xe00000, 0xe03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2	)	// Sprites Code + X + Attr
ADDRESS_MAP_END

/***************************************************************************
                        Blandia
***************************************************************************/

static ADDRESS_MAP_START( blandia_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x1fffff) AM_READ(SMH_ROM				)	// ROM (up to 2MB)
	AM_RANGE(0x200000, 0x20ffff) AM_READ(SMH_RAM				)	// RAM (main ram for zingzip, wrofaero writes to 20f000-20ffff)
	AM_RANGE(0x210000, 0x21ffff) AM_READ(SMH_RAM				)	// RAM (gundhara)
	AM_RANGE(0x300000, 0x30ffff) AM_READ(SMH_RAM				)	// RAM (wrofaero only?)
	AM_RANGE(0x500000, 0x500005) AM_READ(SMH_RAM				)	// (gundhara)
	AM_RANGE(0x400000, 0x400001) AM_READ_PORT("P1")					// P1
	AM_RANGE(0x400002, 0x400003) AM_READ_PORT("P2")					// P2
	AM_RANGE(0x400004, 0x400005) AM_READ_PORT("COINS")				// Coins
	AM_RANGE(0x600000, 0x600003) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x700000, 0x7003ff) AM_READ(SMH_RAM				)	// (rezon,jjsquawk)
	AM_RANGE(0x700400, 0x700fff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0x701000, 0x70ffff) AM_READ(SMH_RAM				)	//
/**/AM_RANGE(0x800000, 0x800607) AM_READ(SMH_RAM				)	// Sprites Y
	AM_RANGE(0x880000, 0x880001) AM_READ(SMH_RAM				)	// ? 0xc000
	AM_RANGE(0x900000, 0x903fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
/**/AM_RANGE(0xa00000, 0xa00005) AM_READ(SMH_RAM				)	// VRAM 0&1 Ctrl
/**/AM_RANGE(0xa80000, 0xa80005) AM_READ(SMH_RAM				)	// VRAM 2&3 Ctrl
	AM_RANGE(0xb00000, 0xb03fff) AM_READ(SMH_RAM				)	// VRAM 0&1
	AM_RANGE(0xb04000, 0xb0ffff) AM_READ(SMH_RAM				)	// (jjsquawk)
	AM_RANGE(0xb80000, 0xb83fff) AM_READ(SMH_RAM				)	// VRAM 2&3
	AM_RANGE(0xb84000, 0xb8ffff) AM_READ(SMH_RAM				)	// (jjsquawk)
	AM_RANGE(0xc00000, 0xc03fff) AM_READ(seta_sound_word_r		)	// Sound
ADDRESS_MAP_END

static ADDRESS_MAP_START( blandia_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x1fffff) AM_WRITE(SMH_ROM						)	// ROM (up to 2MB)
	AM_RANGE(0x200000, 0x20ffff) AM_WRITE(SMH_RAM						)	// RAM
	AM_RANGE(0x210000, 0x21ffff) AM_WRITE(SMH_RAM						)	// RAM (gundhara)
	AM_RANGE(0x300000, 0x30ffff) AM_WRITE(SMH_RAM						)	// RAM (wrofaero only?)
	AM_RANGE(0x500000, 0x500005) AM_WRITE(seta_vregs_w) AM_BASE(&seta_vregs		)	// Coin Lockout + Video Registers
	AM_RANGE(0x700000, 0x7003ff) AM_WRITE(SMH_RAM						)	// (rezon,jjsquawk)
	AM_RANGE(0x700400, 0x700fff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0x701000, 0x70ffff) AM_WRITE(SMH_RAM						)	//
	AM_RANGE(0x800000, 0x800607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16		)	// Sprites Y
	AM_RANGE(0x880000, 0x880001) AM_WRITE(SMH_RAM						)	// ? 0xc000
	AM_RANGE(0x900000, 0x903fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2		)	// Sprites Code + X + Attr
	AM_RANGE(0xa00000, 0xa00005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_0		)	// VRAM 0&1 Ctrl
	AM_RANGE(0xa80000, 0xa80005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_2		)	// VRAM 2&3 Ctrl
	AM_RANGE(0xb00000, 0xb03fff) AM_WRITE(seta_vram_0_w) AM_BASE(&seta_vram_0	)	// VRAM 0
	AM_RANGE(0xb04000, 0xb0ffff) AM_WRITE(SMH_RAM						)	// (jjsquawk)
	AM_RANGE(0xb80000, 0xb83fff) AM_WRITE(seta_vram_2_w) AM_BASE(&seta_vram_2	)	// VRAM 2
	AM_RANGE(0xb84000, 0xb8ffff) AM_WRITE(SMH_RAM						)	// (jjsquawk)
	AM_RANGE(0xc00000, 0xc03fff) AM_WRITE(seta_sound_word_w				)	// Sound
	AM_RANGE(0xd00000, 0xd00007) AM_WRITE(SMH_NOP						)	// ?
	AM_RANGE(0xe00000, 0xe00001) AM_WRITE(SMH_NOP						)	// ? VBlank IRQ Ack
	AM_RANGE(0xf00000, 0xf00001) AM_WRITE(SMH_NOP						)	// ? Sound  IRQ Ack
ADDRESS_MAP_END


/***************************************************************************
    Blandia (proto), Gundhara, J.J.Squawkers, Rezon, War of Aero, Zing Zing Zip
                        (with slight variations)
***************************************************************************/

static ADDRESS_MAP_START( blandiap_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x1fffff) AM_READ(SMH_ROM				)	// ROM (up to 2MB)
	AM_RANGE(0x200000, 0x20ffff) AM_READ(SMH_RAM				)	// RAM (main ram for zingzip, wrofaero writes to 20f000-20ffff)
	AM_RANGE(0x210000, 0x21ffff) AM_READ(SMH_RAM				)	// RAM (gundhara)
	AM_RANGE(0x300000, 0x30ffff) AM_READ(SMH_RAM				)	// RAM (wrofaero only?)
	AM_RANGE(0x500000, 0x500005) AM_READ(SMH_RAM				)	// (gundhara)
	AM_RANGE(0x400000, 0x400001) AM_READ_PORT("P1")					// P1
	AM_RANGE(0x400002, 0x400003) AM_READ_PORT("P2")					// P2
	AM_RANGE(0x400004, 0x400005) AM_READ_PORT("COINS")				// Coins
	AM_RANGE(0x600000, 0x600003) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x700000, 0x7003ff) AM_READ(SMH_RAM				)	// (rezon,jjsquawk)
	AM_RANGE(0x700400, 0x700fff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0x701000, 0x70ffff) AM_READ(SMH_RAM				)	//
	AM_RANGE(0x800000, 0x803fff) AM_READ(SMH_RAM				)	// VRAM 0&1
	AM_RANGE(0x804000, 0x80ffff) AM_READ(SMH_RAM				)	// (jjsquawk)
	AM_RANGE(0x880000, 0x883fff) AM_READ(SMH_RAM				)	// VRAM 2&3
	AM_RANGE(0x884000, 0x88ffff) AM_READ(SMH_RAM				)	// (jjsquawk)
/**/AM_RANGE(0x900000, 0x900005) AM_READ(SMH_RAM				)	// VRAM 0&1 Ctrl
/**/AM_RANGE(0x980000, 0x980005) AM_READ(SMH_RAM				)	// VRAM 2&3 Ctrl
/**/AM_RANGE(0xa00000, 0xa00607) AM_READ(SMH_RAM				)	// Sprites Y
/**/AM_RANGE(0xa80000, 0xa80001) AM_READ(SMH_RAM				)	// ? 0x4000
	AM_RANGE(0xb00000, 0xb03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
	AM_RANGE(0xc00000, 0xc03fff) AM_READ(seta_sound_word_r		)	// Sound
ADDRESS_MAP_END

static ADDRESS_MAP_START( blandiap_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x1fffff) AM_WRITE(SMH_ROM						)	// ROM (up to 2MB)
	AM_RANGE(0x200000, 0x20ffff) AM_WRITE(SMH_RAM						)	// RAM
	AM_RANGE(0x210000, 0x21ffff) AM_WRITE(SMH_RAM						)	// RAM (gundhara)
	AM_RANGE(0x300000, 0x30ffff) AM_WRITE(SMH_RAM						)	// RAM (wrofaero only?)
	AM_RANGE(0x500000, 0x500005) AM_WRITE(seta_vregs_w) AM_BASE(&seta_vregs		)	// Coin Lockout + Video Registers
	AM_RANGE(0x700000, 0x7003ff) AM_WRITE(SMH_RAM						)	// (rezon,jjsquawk)
	AM_RANGE(0x700400, 0x700fff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0x701000, 0x70ffff) AM_WRITE(SMH_RAM						)	//
	AM_RANGE(0x800000, 0x803fff) AM_WRITE(seta_vram_0_w) AM_BASE(&seta_vram_0	)	// VRAM 0
	AM_RANGE(0x804000, 0x80ffff) AM_WRITE(SMH_RAM						)	// (jjsquawk)
	AM_RANGE(0x880000, 0x883fff) AM_WRITE(seta_vram_2_w) AM_BASE(&seta_vram_2	)	// VRAM 2
	AM_RANGE(0x884000, 0x88ffff) AM_WRITE(SMH_RAM						)	// (jjsquawk)
	AM_RANGE(0x900000, 0x900005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_0		)	// VRAM 0&1 Ctrl
	AM_RANGE(0x980000, 0x980005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_2		)	// VRAM 2&3 Ctrl
	AM_RANGE(0xa00000, 0xa00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16		)	// Sprites Y
	AM_RANGE(0xa80000, 0xa80001) AM_WRITE(SMH_RAM						)	// ? 0x4000
	AM_RANGE(0xb00000, 0xb03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2		)	// Sprites Code + X + Attr
	AM_RANGE(0xc00000, 0xc03fff) AM_WRITE(seta_sound_word_w				)	// Sound
	AM_RANGE(0xd00000, 0xd00007) AM_WRITE(SMH_NOP						)	// ?
	AM_RANGE(0xe00000, 0xe00001) AM_WRITE(SMH_NOP						)	// ? VBlank IRQ Ack
	AM_RANGE(0xf00000, 0xf00001) AM_WRITE(SMH_NOP						)	// ? Sound  IRQ Ack
ADDRESS_MAP_END


/***************************************************************************
    Blandia, Gundhara, J.J.Squawkers, Rezon, War of Aero, Zing Zing Zip
                    and Zombie Raid (with slight variations)
***************************************************************************/

static int gun_input_bit = 0, gun_input_src = 0;

static READ16_HANDLER( zombraid_gun_r ) // Serial interface
{
	static const char *const portnames[] = { "GUNX1", "GUNY1", "GUNX2", "GUNY2" };

	int data = input_port_read(space->machine, portnames[gun_input_src]);	// Input Ports 5-8
	return (data >> gun_input_bit) & 1;
}

// Bit 0 is clock, 1 is data, 2 is reset
static WRITE16_HANDLER( zombraid_gun_w )
{
	static int bit_count = 0, old_clock = 0;

	if(data&4) { bit_count = 0; return; } // Reset

	if((data&1) == old_clock) return; // No change

	if(old_clock == 0) // Rising edge
	{
		switch (bit_count)
		{
			case 0:
			case 1: // Starting sequence 2,3,2,3. Other inputs?
				break;
			case 2: // First bit of source
				gun_input_src = (gun_input_src&2) | (data>>1);
				break;
			case 3: // Second bit of source
				gun_input_src = (gun_input_src&1) | (data&2);
				break;
			default:
				gun_input_bit = bit_count - 4;
				gun_input_bit = 8 - gun_input_bit; // Reverse order
				break;
		}
		bit_count++;
	}

	old_clock = data & 1;
}

static ADDRESS_MAP_START( wrofaero_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x1fffff) AM_READ(SMH_ROM				)	// ROM (up to 2MB)
	AM_RANGE(0x200000, 0x20ffff) AM_READ(SMH_RAM				)	// RAM (main ram for zingzip, wrofaero writes to 20f000-20ffff)
	AM_RANGE(0x210000, 0x21ffff) AM_READ(SMH_RAM				)	// RAM (gundhara)
	AM_RANGE(0x300000, 0x30ffff) AM_READ(SMH_RAM				)	// RAM (wrofaero only?)
	AM_RANGE(0x500000, 0x500005) AM_READ(SMH_RAM				)	// (gundhara)
	AM_RANGE(0x400000, 0x400001) AM_READ_PORT("P1")					// P1
	AM_RANGE(0x400002, 0x400003) AM_READ_PORT("P2")					// P2
	AM_RANGE(0x400004, 0x400005) AM_READ_PORT("COINS")				// Coins
	AM_RANGE(0x600000, 0x600003) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x700000, 0x7003ff) AM_READ(SMH_RAM				)	// (rezon,jjsquawk)
	AM_RANGE(0x700400, 0x700fff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0x701000, 0x70ffff) AM_READ(SMH_RAM				)	//
	AM_RANGE(0x800000, 0x803fff) AM_READ(SMH_RAM				)	// VRAM 0&1
	AM_RANGE(0x804000, 0x80ffff) AM_READ(SMH_RAM				)	// (jjsquawk)
	AM_RANGE(0x880000, 0x883fff) AM_READ(SMH_RAM				)	// VRAM 2&3
	AM_RANGE(0x884000, 0x88ffff) AM_READ(SMH_RAM				)	// (jjsquawk)
/**/AM_RANGE(0x900000, 0x900005) AM_READ(SMH_RAM				)	// VRAM 0&1 Ctrl
/**/AM_RANGE(0x980000, 0x980005) AM_READ(SMH_RAM				)	// VRAM 2&3 Ctrl
/**/AM_RANGE(0xa00000, 0xa00607) AM_READ(SMH_RAM				)	// Sprites Y
/**/AM_RANGE(0xa80000, 0xa80001) AM_READ(SMH_RAM				)	// ? 0x4000
	AM_RANGE(0xb00000, 0xb03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
	AM_RANGE(0xc00000, 0xc03fff) AM_READ(seta_sound_word_r		)	// Sound
ADDRESS_MAP_END

static ADDRESS_MAP_START( wrofaero_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x1fffff) AM_WRITE(SMH_ROM						)	// ROM (up to 2MB)
	AM_RANGE(0x200000, 0x20ffff) AM_WRITE(SMH_RAM) AM_BASE(&seta_workram		)	// RAM (pointer for zombraid crosshair hack)
	AM_RANGE(0x210000, 0x21ffff) AM_WRITE(SMH_RAM						)	// RAM (gundhara)
	AM_RANGE(0x300000, 0x30ffff) AM_WRITE(SMH_RAM						)	// RAM (wrofaero only?)
	AM_RANGE(0x500000, 0x500005) AM_WRITE(seta_vregs_w) AM_BASE(&seta_vregs		)	// Coin Lockout + Video Registers
	AM_RANGE(0x700000, 0x7003ff) AM_WRITE(SMH_RAM						)	// (rezon,jjsquawk)
	AM_RANGE(0x700400, 0x700fff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0x701000, 0x70ffff) AM_WRITE(SMH_RAM						)	//
	AM_RANGE(0x800000, 0x803fff) AM_WRITE(seta_vram_0_w) AM_BASE(&seta_vram_0	)	// VRAM 0
	AM_RANGE(0x804000, 0x80ffff) AM_WRITE(SMH_RAM						)	// (jjsquawk)
	AM_RANGE(0x880000, 0x883fff) AM_WRITE(seta_vram_2_w) AM_BASE(&seta_vram_2	)	// VRAM 2
	AM_RANGE(0x884000, 0x88ffff) AM_WRITE(SMH_RAM						)	// (jjsquawk)
	AM_RANGE(0x900000, 0x900005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_0		)	// VRAM 0&1 Ctrl
	AM_RANGE(0x980000, 0x980005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_2		)	// VRAM 2&3 Ctrl
	AM_RANGE(0xa00000, 0xa00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16		)	// Sprites Y
	AM_RANGE(0xa80000, 0xa80001) AM_WRITE(SMH_RAM						)	// ? 0x4000
	AM_RANGE(0xb00000, 0xb03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2		)	// Sprites Code + X + Attr
	AM_RANGE(0xc00000, 0xc03fff) AM_WRITE(seta_sound_word_w				)	// Sound
#if __uPD71054_TIMER
	AM_RANGE(0xd00000, 0xd00007) AM_WRITE(timer_regs_w					)	// ?
#else
	AM_RANGE(0xd00000, 0xd00007) AM_WRITE(SMH_NOP						)	// ?
#endif
	AM_RANGE(0xe00000, 0xe00001) AM_WRITE(SMH_NOP						)	// ? VBlank IRQ Ack
	AM_RANGE(0xf00000, 0xf00001) AM_WRITE(SMH_NOP						)	// ? Sound  IRQ Ack
ADDRESS_MAP_END

/***************************************************************************
        orbs
***************************************************************************/

static ADDRESS_MAP_START( orbs_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0xf00000, 0xf0ffff) AM_READ(SMH_RAM				)	// RAM
	AM_RANGE(0x100000, 0x100001) AM_READ(SMH_NOP				)	// ?
	AM_RANGE(0x200000, 0x200001) AM_READ(SMH_NOP				)	// ?
	AM_RANGE(0x300000, 0x300003) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x500000, 0x500001) AM_READ_PORT("P1")					// P1
	AM_RANGE(0x500002, 0x500003) AM_READ_PORT("P2")					// P2
	AM_RANGE(0x500004, 0x500005) AM_READ_PORT("COINS")				// Coins
	//AM_RANGE(0x600000, 0x60000f) AM_READ(krzybowl_input_r     )   // P1
	AM_RANGE(0x8000f0, 0x8000f1) AM_READ(SMH_RAM				)	// NVRAM
	AM_RANGE(0x800100, 0x8001ff) AM_READ(SMH_RAM				)	// NVRAM
	AM_RANGE(0xa00000, 0xa03fff) AM_READ(seta_sound_word_r		)	// Sound
	AM_RANGE(0xb00000, 0xb003ff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0xc00000, 0xc03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
/**/AM_RANGE(0xd00000, 0xd00001) AM_READ(SMH_RAM				)	// ? 0x4000
/**/AM_RANGE(0xe00000, 0xe00607) AM_READ(SMH_RAM				)	// Sprites Y
ADDRESS_MAP_END

static ADDRESS_MAP_START( orbs_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_WRITE(SMH_ROM					)	// ROM
	AM_RANGE(0xf00000, 0xf0ffff) AM_WRITE(SMH_RAM					)	// RAM
	AM_RANGE(0x400000, 0x400001) AM_WRITE(SMH_NOP					)	// ?
	AM_RANGE(0x8000f0, 0x8000f1) AM_WRITE(SMH_RAM					)	// NVRAM
	AM_RANGE(0x800100, 0x8001ff) AM_WRITE(SMH_RAM					)	// NVRAM
	AM_RANGE(0xa00000, 0xa03fff) AM_WRITE(seta_sound_word_w			)	// Sound
	AM_RANGE(0xb00000, 0xb003ff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0xc00000, 0xc03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2	)	// Sprites Code + X + Attr
	AM_RANGE(0xd00000, 0xd00001) AM_WRITE(SMH_RAM					)	// ? 0x4000
	AM_RANGE(0xe00000, 0xe00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16	)	// Sprites Y
ADDRESS_MAP_END


/***************************************************************************
                                Block Carnival
***************************************************************************/

/* similar to krzybowl */
static ADDRESS_MAP_START( blockcar_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x03ffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0xf00000, 0xf03fff) AM_READ(SMH_RAM				)	// RAM
	AM_RANGE(0xf04000, 0xf041ff) AM_READ(SMH_RAM				)	// Backup RAM?
	AM_RANGE(0xf05000, 0xf050ff) AM_READ(SMH_RAM				)	// Backup RAM?
	AM_RANGE(0x300000, 0x300003) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x500000, 0x500001) AM_READ_PORT("P1")					// P1
	AM_RANGE(0x500002, 0x500003) AM_READ_PORT("P2")					// P2
	AM_RANGE(0x500004, 0x500005) AM_READ_PORT("COINS")				// Coins
	AM_RANGE(0xa00000, 0xa03fff) AM_READ(seta_sound_word_r		)	// Sound
	AM_RANGE(0xb00000, 0xb003ff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0xc00000, 0xc03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
/**/AM_RANGE(0xd00000, 0xd00001) AM_READ(SMH_RAM				)	// ? 0x4000
/**/AM_RANGE(0xe00000, 0xe00607) AM_READ(SMH_RAM				)	// Sprites Y
ADDRESS_MAP_END

static ADDRESS_MAP_START( blockcar_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x03ffff) AM_WRITE(SMH_ROM					)	// ROM
	AM_RANGE(0xf00000, 0xf03fff) AM_WRITE(SMH_RAM					)	// RAM
	AM_RANGE(0xf04000, 0xf041ff) AM_WRITE(SMH_RAM					)	// Backup RAM?
	AM_RANGE(0xf05000, 0xf050ff) AM_WRITE(SMH_RAM					)	// Backup RAM?
	AM_RANGE(0x100000, 0x100001) AM_WRITE(SMH_NOP					)	// ? 1 (start of interrupts, main loop: watchdog?)
	AM_RANGE(0x200000, 0x200001) AM_WRITE(SMH_NOP					)	// ? 0/1 (IRQ acknowledge?)
	AM_RANGE(0x400000, 0x400001) AM_WRITE(seta_vregs_w) AM_BASE(&seta_vregs	)	// Coin Lockout + Sound Enable (bit 4?)
	AM_RANGE(0xa00000, 0xa03fff) AM_WRITE(seta_sound_word_w			)	// Sound
	AM_RANGE(0xb00000, 0xb003ff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0xc00000, 0xc03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2	)	// Sprites Code + X + Attr
	AM_RANGE(0xd00000, 0xd00001) AM_WRITE(SMH_RAM					)	// ? 0x4000
	AM_RANGE(0xe00000, 0xe00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16	)	// Sprites Y
ADDRESS_MAP_END



/***************************************************************************
                                Daioh
***************************************************************************/

static ADDRESS_MAP_START( daioh_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x0fffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0x100000, 0x10ffff) AM_READ(SMH_RAM				)	// RAM
	AM_RANGE(0x400000, 0x400001) AM_READ_PORT("P1")					// P1
	AM_RANGE(0x400002, 0x400003) AM_READ_PORT("P2")					// P2
	AM_RANGE(0x400004, 0x400005) AM_READ_PORT("COINS")				// Coins
	AM_RANGE(0x500006, 0x500007) AM_READ_PORT("EXTRA")				// Buttons 4,5,6
	AM_RANGE(0x600000, 0x600003) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x700000, 0x7003ff) AM_READ(SMH_RAM				)
	AM_RANGE(0x700400, 0x700fff) AM_READ(SMH_RAM				)  // Palette
	AM_RANGE(0x701000, 0x70ffff) AM_READ(SMH_RAM				)
	AM_RANGE(0x800000, 0x803fff) AM_READ(SMH_RAM				)	// VRAM 0&1
	AM_RANGE(0x804000, 0x80ffff) AM_READ(SMH_RAM				)	//
	AM_RANGE(0x880000, 0x883fff) AM_READ(SMH_RAM				)	// VRAM 2&3
	AM_RANGE(0x884000, 0x88ffff) AM_READ(SMH_RAM				)	//
	AM_RANGE(0x900000, 0x900005) AM_READ(SMH_RAM				)	// VRAM 0&1 Ctrl
	AM_RANGE(0x980000, 0x980005) AM_READ(SMH_RAM				)	// VRAM 2&3 Ctrl
	AM_RANGE(0xa00000, 0xa00607) AM_READ(SMH_RAM				)	// Sprites Y
	AM_RANGE(0xa80000, 0xa80001) AM_READ(SMH_RAM				)	// ? 0x4000
	AM_RANGE(0xb00000, 0xb03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
	AM_RANGE(0xb04000, 0xb13fff) AM_READ(SMH_RAM				)	//
	AM_RANGE(0xc00000, 0xc03fff) AM_READ(seta_sound_word_r		)	// Sound
ADDRESS_MAP_END

static ADDRESS_MAP_START( daioh_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x0fffff) AM_WRITE(SMH_ROM						)	// ROM
	AM_RANGE(0x100000, 0x10ffff) AM_WRITE(SMH_RAM						)	// RAM
	AM_RANGE(0x500000, 0x500005) AM_WRITE(seta_vregs_w) AM_BASE(&seta_vregs		)	// Coin Lockout + Video Registers
	AM_RANGE(0x700000, 0x7003ff) AM_WRITE(SMH_RAM						)
	AM_RANGE(0x700400, 0x700fff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0x701000, 0x70ffff) AM_WRITE(SMH_RAM						)	//
	AM_RANGE(0x800000, 0x803fff) AM_WRITE(seta_vram_0_w) AM_BASE(&seta_vram_0	)	// VRAM 0
	AM_RANGE(0x804000, 0x80ffff) AM_WRITE(SMH_RAM						)	//
	AM_RANGE(0x880000, 0x883fff) AM_WRITE(seta_vram_2_w) AM_BASE(&seta_vram_2	)	// VRAM 2
	AM_RANGE(0x884000, 0x88ffff) AM_WRITE(SMH_RAM						)	//
	AM_RANGE(0x900000, 0x900005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_0		)	// VRAM 0&1 Ctrl
	AM_RANGE(0x980000, 0x980005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_2		)	// VRAM 2&3 Ctrl
	AM_RANGE(0xa00000, 0xa00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16		)	// Sprites Y
	AM_RANGE(0xa80000, 0xa80001) AM_WRITE(SMH_RAM						)	// ? 0x4000
	AM_RANGE(0xb00000, 0xb03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2		)	// Sprites Code + X + Attr
	AM_RANGE(0xb04000, 0xb13fff) AM_WRITE(SMH_RAM						)	//
	AM_RANGE(0xc00000, 0xc03fff) AM_WRITE(seta_sound_word_w				)	// Sound
	AM_RANGE(0xe00000, 0xe00001) AM_WRITE(SMH_NOP						)	//
ADDRESS_MAP_END


/***************************************************************************
        Dragon Unit, Quiz Kokology, Quiz Kokology 2, Strike Gunner
***************************************************************************/

static ADDRESS_MAP_START( drgnunit_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x0bffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0xf00000, 0xf0ffff) AM_READ(SMH_RAM				)	// RAM (qzkklogy)
	AM_RANGE(0xffc000, 0xffffff) AM_READ(SMH_RAM				)	// RAM (drgnunit,stg)
	AM_RANGE(0x100000, 0x103fff) AM_READ(seta_sound_word_r		)	// Sound
	AM_RANGE(0x600000, 0x600003) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x700000, 0x7003ff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0x900000, 0x901fff) AM_READ(SMH_RAM				)	// VRAM
	AM_RANGE(0x902000, 0x903fff) AM_READ(SMH_RAM				)	// VRAM
	AM_RANGE(0xb00000, 0xb00001) AM_READ_PORT("P1")					// P1
	AM_RANGE(0xb00002, 0xb00003) AM_READ_PORT("P2")					// P2
	AM_RANGE(0xb00004, 0xb00005) AM_READ_PORT("COINS")				// Coins
	AM_RANGE(0xb00006, 0xb00007) AM_READ(SMH_NOP				)	// unused (qzkklogy)
/**/AM_RANGE(0xc00000, 0xc00001) AM_READ(SMH_RAM				)	// ? $4000
/**/AM_RANGE(0xd00000, 0xd00607) AM_READ(SMH_RAM				)	// Sprites Y
	AM_RANGE(0xe00000, 0xe03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
ADDRESS_MAP_END

static ADDRESS_MAP_START( drgnunit_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x0bffff) AM_WRITE(SMH_ROM						)	// ROM
	AM_RANGE(0xf00000, 0xf0ffff) AM_WRITE(SMH_RAM						)	// RAM (qzkklogy)
	AM_RANGE(0xffc000, 0xffffff) AM_WRITE(SMH_RAM						)	// RAM (drgnunit,stg)
	AM_RANGE(0x100000, 0x103fff) AM_WRITE(seta_sound_word_w				)	// Sound
	AM_RANGE(0x200000, 0x200001) AM_WRITE(SMH_NOP						)	// Watchdog
	AM_RANGE(0x300000, 0x300001) AM_WRITE(SMH_NOP						)	// ? IRQ Ack
	AM_RANGE(0x500000, 0x500001) AM_WRITE(seta_vregs_w) AM_BASE(&seta_vregs		)	// Coin Lockout + Video Registers
	AM_RANGE(0x700000, 0x7003ff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0x800000, 0x800005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_0		)	// VRAM Ctrl
	AM_RANGE(0x900000, 0x903fff) AM_WRITE(seta_vram_0_w) AM_BASE(&seta_vram_0	)	// VRAM
	AM_RANGE(0x904000, 0x90ffff) AM_WRITE(SMH_NOP						)	// unused (qzkklogy)
	AM_RANGE(0xc00000, 0xc00001) AM_WRITE(SMH_RAM						)	// ? $4000
	AM_RANGE(0xd00000, 0xd00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16		)	// Sprites Y
	AM_RANGE(0xe00000, 0xe03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2		)	// Sprites Code + X + Attr
ADDRESS_MAP_END


/***************************************************************************
                        Extreme Downhill / Sokonuke
***************************************************************************/

static ADDRESS_MAP_START( extdwnhl_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x0fffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0x200000, 0x20ffff) AM_READ(SMH_RAM				)	// RAM
	AM_RANGE(0x210000, 0x21ffff) AM_READ(SMH_RAM				)	// RAM
	AM_RANGE(0x220000, 0x23ffff) AM_READ(SMH_RAM				)	// RAM (sokonuke)
	AM_RANGE(0x400000, 0x400001) AM_READ_PORT("P1")					// P1
	AM_RANGE(0x400002, 0x400003) AM_READ_PORT("P2")					// P2
	AM_RANGE(0x400004, 0x400005) AM_READ_PORT("COINS")				// Coins
	AM_RANGE(0x400008, 0x40000b) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x40000c, 0x40000d) AM_READ(watchdog_reset16_r		)	// Watchdog (extdwnhl, MUST RETURN $FFFF)
	AM_RANGE(0x500004, 0x500007) AM_READ(SMH_NOP				)	// IRQ Ack  (extdwnhl)
	AM_RANGE(0x600400, 0x600fff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0x601000, 0x610bff) AM_READ(SMH_RAM				)	//
	AM_RANGE(0x800000, 0x803fff) AM_READ(SMH_RAM				)	// VRAM 0&1
	AM_RANGE(0x804000, 0x80ffff) AM_READ(SMH_RAM				)	//
	AM_RANGE(0x880000, 0x883fff) AM_READ(SMH_RAM				)	// VRAM 2&3
	AM_RANGE(0x884000, 0x88ffff) AM_READ(SMH_RAM				)	//
/**/AM_RANGE(0x900000, 0x900005) AM_READ(SMH_RAM				)	// VRAM 0&1 Ctrl
/**/AM_RANGE(0x980000, 0x980005) AM_READ(SMH_RAM				)	// VRAM 2&3 Ctrl
/**/AM_RANGE(0xa00000, 0xa00607) AM_READ(SMH_RAM				)	// Sprites Y
/**/AM_RANGE(0xa80000, 0xa80001) AM_READ(SMH_RAM				)	// ? 0x4000
	AM_RANGE(0xb00000, 0xb03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
	AM_RANGE(0xb04000, 0xb13fff) AM_READ(SMH_RAM				)	//
	AM_RANGE(0xe00000, 0xe03fff) AM_READ(seta_sound_word_r		)	// Sound
ADDRESS_MAP_END

static ADDRESS_MAP_START( extdwnhl_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x0fffff) AM_WRITE(SMH_ROM						)	// ROM
	AM_RANGE(0x200000, 0x20ffff) AM_WRITE(SMH_RAM						)	// RAM
	AM_RANGE(0x210000, 0x21ffff) AM_WRITE(SMH_RAM						)	// RAM
	AM_RANGE(0x220000, 0x23ffff) AM_WRITE(SMH_RAM						)	// RAM (sokonuke)
	AM_RANGE(0x40000c, 0x40000d) AM_WRITE(watchdog_reset16_w			)	// Watchdog (sokonuke)
	AM_RANGE(0x500000, 0x500003) AM_WRITE(seta_vregs_w) AM_BASE(&seta_vregs		)	// Coin Lockout + Video Registers
	AM_RANGE(0x500004, 0x500007) AM_WRITE(SMH_NOP						)	// IRQ Ack (sokonuke)
	AM_RANGE(0x600400, 0x600fff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0x601000, 0x610bff) AM_WRITE(SMH_RAM						)	//
	AM_RANGE(0x800000, 0x803fff) AM_WRITE(seta_vram_0_w) AM_BASE(&seta_vram_0	)	// VRAM 0
	AM_RANGE(0x804000, 0x80ffff) AM_WRITE(SMH_RAM						)	//
	AM_RANGE(0x880000, 0x883fff) AM_WRITE(seta_vram_2_w) AM_BASE(&seta_vram_2	)	// VRAM 2
	AM_RANGE(0x884000, 0x88ffff) AM_WRITE(SMH_RAM						)	//
	AM_RANGE(0x900000, 0x900005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_0		)	// VRAM 0&1 Ctrl
	AM_RANGE(0x980000, 0x980005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_2		)	// VRAM 2&3 Ctrl
	AM_RANGE(0xa00000, 0xa00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16		)	// Sprites Y
	AM_RANGE(0xa80000, 0xa80001) AM_WRITE(SMH_RAM						)	// ? 0x4000
	AM_RANGE(0xb00000, 0xb03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2		)	// Sprites Code + X + Attr
	AM_RANGE(0xb04000, 0xb13fff) AM_WRITE(SMH_RAM						)	//
	AM_RANGE(0xe00000, 0xe03fff) AM_WRITE(seta_sound_word_w				)	// Sound
ADDRESS_MAP_END

/***************************************************************************
        (Kamen) Masked Riders Club Battle Race / Mad Shark
***************************************************************************/

static ADDRESS_MAP_START( kamenrid_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0x200000, 0x20ffff) AM_READ(SMH_RAM				)	// ROM
	AM_RANGE(0x500000, 0x500001) AM_READ_PORT("P1")					// P1
	AM_RANGE(0x500002, 0x500003) AM_READ_PORT("P2")					// P2
	AM_RANGE(0x500004, 0x500007) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x500008, 0x500009) AM_READ_PORT("COINS")				// Coins
	AM_RANGE(0x50000c, 0x50000d) AM_READ(watchdog_reset16_r		)	// xx Watchdog?
	AM_RANGE(0x700000, 0x7003ff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0x700400, 0x700fff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0x701000, 0x703fff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0x800000, 0x801fff) AM_READ(SMH_RAM				)	// VRAM 0
	AM_RANGE(0x802000, 0x803fff) AM_READ(SMH_RAM				)	// VRAM 1
	AM_RANGE(0x804000, 0x807fff) AM_READ(SMH_RAM				)	// tested
	AM_RANGE(0x880000, 0x881fff) AM_READ(SMH_RAM				)	// VRAM 2
	AM_RANGE(0x882000, 0x883fff) AM_READ(SMH_RAM				)	// VRAM 3
	AM_RANGE(0x884000, 0x887fff) AM_READ(SMH_RAM				)	// tested
	AM_RANGE(0xa00000, 0xa00607) AM_READ(SMH_RAM			 	)	// Sprites Y
	AM_RANGE(0xb00000, 0xb03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
	AM_RANGE(0xb04000, 0xb07fff) AM_READ(SMH_RAM				)	// tested
	AM_RANGE(0xd00000, 0xd03fff) AM_READ(seta_sound_word_r		)	// Sound
ADDRESS_MAP_END

static ADDRESS_MAP_START( kamenrid_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_WRITE(SMH_ROM						)	// ROM
	AM_RANGE(0x200000, 0x20ffff) AM_WRITE(SMH_RAM						)	// ROM
	AM_RANGE(0x50000c, 0x50000d) AM_WRITE(watchdog_reset16_w			)	// Watchdog (sokonuke)
	AM_RANGE(0x600000, 0x600005) AM_WRITE(seta_vregs_w) AM_BASE(&seta_vregs		)	// ? Coin Lockout + Video Registers
	AM_RANGE(0x600006, 0x600007) AM_WRITE(SMH_NOP						)	// ?
	AM_RANGE(0x700000, 0x7003ff) AM_WRITE(SMH_RAM						)	// Palette RAM (tested)
	AM_RANGE(0x700400, 0x700fff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0x701000, 0x703fff) AM_WRITE(SMH_RAM	)	// Palette
	AM_RANGE(0x800000, 0x803fff) AM_WRITE(seta_vram_0_w) AM_BASE(&seta_vram_0	)	// VRAM 0
	AM_RANGE(0x804000, 0x807fff) AM_WRITE(SMH_RAM	)	// tested
	AM_RANGE(0x880000, 0x883fff) AM_WRITE(seta_vram_2_w) AM_BASE(&seta_vram_2	)	// VRAM 2
	AM_RANGE(0x884000, 0x887fff) AM_WRITE(SMH_RAM	)	// tested
	AM_RANGE(0x900000, 0x900005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_0		)	// VRAM 0&1 Ctrl
	AM_RANGE(0x980000, 0x980005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_2		)	// VRAM 2&3 Ctrl
	AM_RANGE(0xa00000, 0xa00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16		)	// Sprites Y
	AM_RANGE(0xa80000, 0xa80001) AM_WRITE(SMH_RAM						)	// ? $4000
	AM_RANGE(0xb00000, 0xb03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2	)	// Sprites Code + X + Attr
	AM_RANGE(0xb04000, 0xb07fff) AM_WRITE(SMH_RAM)	// tested
#if __uPD71054_TIMER
	AM_RANGE(0xc00000, 0xc00007) AM_WRITE(timer_regs_w					)	// ?
#else
	AM_RANGE(0xc00000, 0xc00007) AM_WRITE(SMH_NOP						)	// ?
#endif
	AM_RANGE(0xd00000, 0xd03fff) AM_WRITE(seta_sound_word_w				)	// Sound
ADDRESS_MAP_END

/* almast identical to kamenrid */
static ADDRESS_MAP_START( madshark_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x0fffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0x200000, 0x20ffff) AM_READ(SMH_RAM				)	// ROM
	AM_RANGE(0x500000, 0x500001) AM_READ_PORT("P1")					// P1
	AM_RANGE(0x500002, 0x500003) AM_READ_PORT("P2")					// P2
	AM_RANGE(0x500004, 0x500005) AM_READ_PORT("COINS")				// Coins
	AM_RANGE(0x500008, 0x50000b) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x700400, 0x700fff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0x800000, 0x801fff) AM_READ(SMH_RAM				)	// VRAM 0
	AM_RANGE(0x802000, 0x803fff) AM_READ(SMH_RAM				)	// VRAM 1
	AM_RANGE(0x880000, 0x881fff) AM_READ(SMH_RAM				)	// VRAM 2
	AM_RANGE(0x882000, 0x883fff) AM_READ(SMH_RAM				)	// VRAM 3
	AM_RANGE(0xa00000, 0xa00607) AM_READ(SMH_RAM			 	)	// Sprites Y
	AM_RANGE(0xb00000, 0xb03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
	AM_RANGE(0xd00000, 0xd03fff) AM_READ(seta_sound_word_r		)	// Sound
ADDRESS_MAP_END

static ADDRESS_MAP_START( madshark_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x0fffff) AM_WRITE(SMH_ROM						)	// ROM
	AM_RANGE(0x200000, 0x20ffff) AM_WRITE(SMH_RAM						)	// ROM
	AM_RANGE(0x50000c, 0x50000d) AM_WRITE(watchdog_reset16_w			)	// Watchdog
	AM_RANGE(0x600000, 0x600005) AM_WRITE(seta_vregs_w) AM_BASE(&seta_vregs		)	// ? Coin Lockout + Video Registers
	AM_RANGE(0x600006, 0x600007) AM_WRITE(SMH_NOP						)	// ?
	AM_RANGE(0x700400, 0x700fff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0x800000, 0x803fff) AM_WRITE(seta_vram_0_w) AM_BASE(&seta_vram_0	)	// VRAM 0
	AM_RANGE(0x880000, 0x883fff) AM_WRITE(seta_vram_2_w) AM_BASE(&seta_vram_2	)	// VRAM 2
	AM_RANGE(0x900000, 0x900005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_0		)	// VRAM 0&1 Ctrl
	AM_RANGE(0x980000, 0x980005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_2		)	// VRAM 2&3 Ctrl
	AM_RANGE(0xa00000, 0xa00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16		)	// Sprites Y
	AM_RANGE(0xa80000, 0xa80001) AM_WRITE(SMH_RAM						)	// ? $4000
	AM_RANGE(0xb00000, 0xb03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2	)	// Sprites Code + X + Attr
#if __uPD71054_TIMER
	AM_RANGE(0xc00000, 0xc00007) AM_WRITE(timer_regs_w					)	// ?
#else
	AM_RANGE(0xc00000, 0xc00007) AM_WRITE(SMH_NOP						)	// ?
#endif
	AM_RANGE(0xd00000, 0xd03fff) AM_WRITE(seta_sound_word_w				)	// Sound
ADDRESS_MAP_END



/***************************************************************************
                                Krazy Bowl
***************************************************************************/

static READ16_HANDLER( krzybowl_input_r )
{
	// analog ports
	int dir1x = input_port_read(space->machine, "TRACK1_X") & 0xfff;
	int dir1y = input_port_read(space->machine, "TRACK1_Y") & 0xfff;
	int dir2x = input_port_read(space->machine, "TRACK2_X") & 0xfff;
	int dir2y = input_port_read(space->machine, "TRACK2_Y") & 0xfff;

	switch (offset)
	{
		case 0x0/2:	return dir1x & 0xff;
		case 0x2/2:	return dir1x >> 8;
		case 0x4/2:	return dir1y & 0xff;
		case 0x6/2:	return dir1y >> 8;
		case 0x8/2:	return dir2x & 0xff;
		case 0xa/2:	return dir2x >> 8;
		case 0xc/2:	return dir2y & 0xff;
		case 0xe/2:	return dir2y >> 8;
		default:
			logerror("PC %06X - Read input %02X !\n", cpu_get_pc(space->cpu), offset*2);
			return 0;
	}
}

static ADDRESS_MAP_START( krzybowl_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0xf00000, 0xf0ffff) AM_READ(SMH_RAM				)	// RAM
	AM_RANGE(0x100000, 0x100001) AM_READ(SMH_NOP				)	// ?
	AM_RANGE(0x200000, 0x200001) AM_READ(SMH_NOP				)	// ?
	AM_RANGE(0x300000, 0x300003) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x500000, 0x500001) AM_READ_PORT("P1")					// P1
	AM_RANGE(0x500002, 0x500003) AM_READ_PORT("P2")					// P2
	AM_RANGE(0x500004, 0x500005) AM_READ_PORT("COINS")				// Coins
	AM_RANGE(0x600000, 0x60000f) AM_READ(krzybowl_input_r		)	// P1
	AM_RANGE(0x8000f0, 0x8000f1) AM_READ(SMH_RAM				)	// NVRAM
	AM_RANGE(0x800100, 0x8001ff) AM_READ(SMH_RAM				)	// NVRAM
	AM_RANGE(0xa00000, 0xa03fff) AM_READ(seta_sound_word_r		)	// Sound
	AM_RANGE(0xb00000, 0xb003ff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0xc00000, 0xc03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
/**/AM_RANGE(0xd00000, 0xd00001) AM_READ(SMH_RAM				)	// ? 0x4000
/**/AM_RANGE(0xe00000, 0xe00607) AM_READ(SMH_RAM				)	// Sprites Y
ADDRESS_MAP_END

static ADDRESS_MAP_START( krzybowl_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_WRITE(SMH_ROM					)	// ROM
	AM_RANGE(0xf00000, 0xf0ffff) AM_WRITE(SMH_RAM					)	// RAM
	AM_RANGE(0x400000, 0x400001) AM_WRITE(SMH_NOP					)	// ?
	AM_RANGE(0x8000f0, 0x8000f1) AM_WRITE(SMH_RAM					)	// NVRAM
	AM_RANGE(0x800100, 0x8001ff) AM_WRITE(SMH_RAM					)	// NVRAM
	AM_RANGE(0xa00000, 0xa03fff) AM_WRITE(seta_sound_word_w			)	// Sound
	AM_RANGE(0xb00000, 0xb003ff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0xc00000, 0xc03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2	)	// Sprites Code + X + Attr
	AM_RANGE(0xd00000, 0xd00001) AM_WRITE(SMH_RAM					)	// ? 0x4000
	AM_RANGE(0xe00000, 0xe00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16	)	// Sprites Y
ADDRESS_MAP_END


/***************************************************************************
                            Mobile Suit Gundam
***************************************************************************/

static WRITE16_HANDLER( msgundam_vregs_w )
{
	// swap $500002 with $500004
	switch( offset )
	{
		case 1:	offset = 2;	break;
		case 2:	offset = 1;	break;
	}
	seta_vregs_w(space,offset,data,mem_mask);
}

/* Mirror RAM is necessary or startup, to clear Work RAM after the test */

static ADDRESS_MAP_START( msgundam_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0x100000, 0x1fffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0x200000, 0x20ffff) AM_READ(SMH_RAM				)	// RAM
	AM_RANGE(0x400000, 0x400001) AM_READ_PORT("P1")					// P1
	AM_RANGE(0x400002, 0x400003) AM_READ_PORT("P2")					// P2
	AM_RANGE(0x400004, 0x400005) AM_READ_PORT("COINS")				// Coins
	AM_RANGE(0x600000, 0x600003) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x700400, 0x700fff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0x800000, 0x800607) AM_READ(SMH_RAM				)	// Sprites Y
	AM_RANGE(0x900000, 0x903fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
	AM_RANGE(0xa00000, 0xa03fff) AM_READ(SMH_RAM				)	// VRAM 0&1
	AM_RANGE(0xa80000, 0xa83fff) AM_READ(SMH_RAM				)	// VRAM 2&3
	AM_RANGE(0xb00000, 0xb00005) AM_READ(SMH_RAM				)	// VRAM 0&1 Ctrl
	AM_RANGE(0xb80000, 0xb80005) AM_READ(SMH_RAM				)	// VRAM 1&2 Ctrl
	AM_RANGE(0xc00000, 0xc03fff) AM_READ(seta_sound_word_r		)	// Sound
ADDRESS_MAP_END

static ADDRESS_MAP_START( msgundam_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_WRITE(SMH_ROM						)	// ROM
	AM_RANGE(0x100000, 0x1fffff) AM_WRITE(SMH_ROM						)	// ROM
	AM_RANGE(0x200000, 0x20ffff) AM_WRITE(SMH_RAM) AM_BASE(&mirror_ram		)	// RAM
	AM_RANGE(0x210000, 0x21ffff) AM_WRITE(mirror_ram_w					)	// Mirrored RAM
	AM_RANGE(0x220000, 0x22ffff) AM_WRITE(mirror_ram_w					)
	AM_RANGE(0x230000, 0x23ffff) AM_WRITE(mirror_ram_w					)
	AM_RANGE(0x240000, 0x24ffff) AM_WRITE(mirror_ram_w					)
	AM_RANGE(0x400000, 0x400001) AM_WRITE(SMH_NOP						)	// Lev 2 IRQ Ack
	AM_RANGE(0x400004, 0x400005) AM_WRITE(SMH_NOP						)	// Lev 4 IRQ Ack
	AM_RANGE(0x500000, 0x500005) AM_WRITE(msgundam_vregs_w) AM_BASE(&seta_vregs		)	// Coin Lockout + Video Registers
	AM_RANGE(0x700400, 0x700fff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0x800000, 0x800607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16		)	// Sprites Y
	AM_RANGE(0x880000, 0x880001) AM_WRITE(SMH_RAM						)	// ? 0x4000
	AM_RANGE(0x900000, 0x903fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2	)	// Sprites Code + X + Attr
	AM_RANGE(0xa00000, 0xa03fff) AM_WRITE(seta_vram_0_w) AM_BASE(&seta_vram_0	)	// VRAM 0
	AM_RANGE(0xa80000, 0xa83fff) AM_WRITE(seta_vram_2_w) AM_BASE(&seta_vram_2	)	// VRAM 2
	AM_RANGE(0xb00000, 0xb00005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_0		)	// VRAM 0&1 Ctrl
	AM_RANGE(0xb80000, 0xb80005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_2		)	// VRAM 2&3 Ctrl
	AM_RANGE(0xc00000, 0xc03fff) AM_WRITE(seta_sound_word_w				)	// Sound
#if __uPD71054_TIMER
	AM_RANGE(0xd00000, 0xd00007) AM_WRITE(timer_regs_w					)	// ?
#else
	AM_RANGE(0xd00000, 0xd00007) AM_WRITE(SMH_NOP						)	// ?
#endif
ADDRESS_MAP_END




/***************************************************************************
                                Oishii Puzzle
***************************************************************************/

/* similar to wrofaero */

static ADDRESS_MAP_START( oisipuzl_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0x100000, 0x17ffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0x200000, 0x20ffff) AM_READ(SMH_RAM				)	// RAM
	AM_RANGE(0x300000, 0x300003) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x400000, 0x400001) AM_READ_PORT("P1")					// P1
	AM_RANGE(0x400002, 0x400003) AM_READ_PORT("P2")					// P2
	AM_RANGE(0x400004, 0x400005) AM_READ_PORT("COINS")				// Coins
	AM_RANGE(0x700000, 0x703fff) AM_READ(seta_sound_word_r		)	// Sound
	AM_RANGE(0x800000, 0x803fff) AM_READ(SMH_RAM				)	// VRAM 0&1
	AM_RANGE(0x880000, 0x883fff) AM_READ(SMH_RAM				)	// VRAM 2&3
/**/AM_RANGE(0x900000, 0x900005) AM_READ(SMH_RAM				)	// VRAM 0&1 Ctrl
/**/AM_RANGE(0x980000, 0x980005) AM_READ(SMH_RAM				)	// VRAM 2&3 Ctrl
/**/AM_RANGE(0xa00000, 0xa00607) AM_READ(SMH_RAM				)	// Sprites Y
/**/AM_RANGE(0xa80000, 0xa80001) AM_READ(SMH_RAM				)	// ? 0x4000
	AM_RANGE(0xb00000, 0xb03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
	AM_RANGE(0xc00400, 0xc00fff) AM_READ(SMH_RAM				)	// Palette
ADDRESS_MAP_END

static ADDRESS_MAP_START( oisipuzl_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_WRITE(SMH_ROM						)	// ROM
	AM_RANGE(0x100000, 0x17ffff) AM_WRITE(SMH_ROM						)	// ROM
	AM_RANGE(0x200000, 0x20ffff) AM_WRITE(SMH_RAM						)	// RAM
	AM_RANGE(0x400000, 0x400001) AM_WRITE(SMH_NOP						)	// ? IRQ Ack
	AM_RANGE(0x500000, 0x500005) AM_WRITE(seta_vregs_w) AM_BASE(&seta_vregs		)	// Coin Lockout + Video Registers
	AM_RANGE(0x700000, 0x703fff) AM_WRITE(seta_sound_word_w				)	// Sound
	AM_RANGE(0x800000, 0x803fff) AM_WRITE(seta_vram_0_w) AM_BASE(&seta_vram_0	)	// VRAM 0
	AM_RANGE(0x880000, 0x883fff) AM_WRITE(seta_vram_2_w) AM_BASE(&seta_vram_2	)	// VRAM 2
	AM_RANGE(0x900000, 0x900005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_0		)	// VRAM 0&1 Ctrl
	AM_RANGE(0x980000, 0x980005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_2		)	// VRAM 2&3 Ctrl
	AM_RANGE(0xa00000, 0xa00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16		)	// Sprites Y
	AM_RANGE(0xa80000, 0xa80001) AM_WRITE(SMH_RAM						)	// ? 0x4000
	AM_RANGE(0xb00000, 0xb03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2		)	// Sprites Code + X + Attr
	AM_RANGE(0xc00400, 0xc00fff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
ADDRESS_MAP_END

/***************************************************************************
                                Triple Fun
***************************************************************************/

/* the same as oisipuzl with the sound system replaced */

static ADDRESS_MAP_START( triplfun_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0x100000, 0x17ffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0x200000, 0x20ffff) AM_READ(SMH_RAM				)	// RAM
	AM_RANGE(0x300000, 0x300003) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x400000, 0x400001) AM_READ_PORT("P1")					// P1
	AM_RANGE(0x400002, 0x400003) AM_READ_PORT("P2")					// P2
	AM_RANGE(0x400004, 0x400005) AM_READ_PORT("COINS")				// Coins
	AM_RANGE(0x500006, 0x500007) AM_READ(okim6295_status_0_lsb_r) // tfun sound
	AM_RANGE(0x700000, 0x703fff) AM_READ(SMH_RAM				)	// old sound
	AM_RANGE(0x800000, 0x803fff) AM_READ(SMH_RAM				)	// VRAM 0&1
	AM_RANGE(0x880000, 0x883fff) AM_READ(SMH_RAM				)	// VRAM 2&3
/**/AM_RANGE(0x900000, 0x900005) AM_READ(SMH_RAM				)	// VRAM 0&1 Ctrl
/**/AM_RANGE(0x980000, 0x980005) AM_READ(SMH_RAM				)	// VRAM 2&3 Ctrl
/**/AM_RANGE(0xa00000, 0xa00607) AM_READ(SMH_RAM				)	// Sprites Y
/**/AM_RANGE(0xa80000, 0xa80001) AM_READ(SMH_RAM				)	// ? 0x4000
	AM_RANGE(0xb00000, 0xb03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
	AM_RANGE(0xc00400, 0xc00fff) AM_READ(SMH_RAM				)	// Palette
ADDRESS_MAP_END

static ADDRESS_MAP_START( triplfun_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_WRITE(SMH_ROM						)	// ROM
	AM_RANGE(0x100000, 0x17ffff) AM_WRITE(SMH_ROM						)	// ROM
	AM_RANGE(0x200000, 0x20ffff) AM_WRITE(SMH_RAM						)	// RAM
	AM_RANGE(0x400000, 0x400001) AM_WRITE(SMH_NOP						)	// ? IRQ Ack
	AM_RANGE(0x500000, 0x500005) AM_WRITE(seta_vregs_w) AM_BASE(&seta_vregs		)	// Coin Lockout + Video Registers
	AM_RANGE(0x500006, 0x500007) AM_WRITE(okim6295_data_0_lsb_w)  // tfun sound
	AM_RANGE(0x700000, 0x703fff) AM_WRITE(SMH_RAM						)	// old sound
	AM_RANGE(0x800000, 0x803fff) AM_WRITE(seta_vram_0_w) AM_BASE(&seta_vram_0	)	// VRAM 0
	AM_RANGE(0x880000, 0x883fff) AM_WRITE(seta_vram_2_w) AM_BASE(&seta_vram_2	)	// VRAM 2
	AM_RANGE(0x900000, 0x900005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_0		)	// VRAM 0&1 Ctrl
	AM_RANGE(0x980000, 0x980005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_2		)	// VRAM 2&3 Ctrl
	AM_RANGE(0xa00000, 0xa00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16		)	// Sprites Y
	AM_RANGE(0xa80000, 0xa80001) AM_WRITE(SMH_RAM						)	// ? 0x4000
	AM_RANGE(0xb00000, 0xb03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2		)	// Sprites Code + X + Attr
	AM_RANGE(0xc00400, 0xc00fff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
ADDRESS_MAP_END

/***************************************************************************
                            Pro Mahjong Kiwame
***************************************************************************/

static UINT16 *kiwame_nvram;

static READ16_HANDLER( kiwame_nvram_r )
{
	return kiwame_nvram[offset] & 0xff;
}

static WRITE16_HANDLER( kiwame_nvram_w )
{
	if (ACCESSING_BITS_0_7)	COMBINE_DATA( &kiwame_nvram[offset] );
}

static READ16_HANDLER( kiwame_input_r )
{
	int row_select = kiwame_nvram_r( space, 0x10a/2,0x00ff ) & 0x1f;
	int i;
	static const char *const keynames[] = { "KEY0", "KEY1", "KEY2", "KEY3", "KEY4" };

	for(i = 0; i < 5; i++)
		if (row_select & (1<<i))	break;

	switch( offset )
	{
		case 0x00/2:	return input_port_read(space->machine, keynames[i]);
		case 0x02/2:	return 0xffff;
		case 0x04/2:	return input_port_read(space->machine, "COINS");
//      case 0x06/2:
		case 0x08/2:	return 0xffff;

		default:
			logerror("PC %06X - Read input %02X !\n", cpu_get_pc(space->cpu), offset*2);
			return 0x0000;
	}
}

static ADDRESS_MAP_START( kiwame_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0x200000, 0x20ffff) AM_READ(SMH_RAM				)	// RAM
	AM_RANGE(0xfffc00, 0xffffff) AM_READ(kiwame_nvram_r			)	// NVRAM + Regs ?
	AM_RANGE(0x800000, 0x803fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
/**/AM_RANGE(0x900000, 0x900001) AM_READ(SMH_RAM				)	// ? 0x4000
/**/AM_RANGE(0xa00000, 0xa00607) AM_READ(SMH_RAM				)	// Sprites Y
	AM_RANGE(0xb00000, 0xb003ff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0xc00000, 0xc03fff) AM_READ(seta_sound_word_r		)	// Sound
	AM_RANGE(0xd00000, 0xd00009) AM_READ(kiwame_input_r			)
	AM_RANGE(0xe00000, 0xe00003) AM_READ(seta_dsw_r				)	// DSW
ADDRESS_MAP_END

static ADDRESS_MAP_START( kiwame_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_WRITE(SMH_ROM						)	// ROM
	AM_RANGE(0x200000, 0x20ffff) AM_WRITE(SMH_RAM						)	// RAM
	AM_RANGE(0xfffc00, 0xffffff) AM_WRITE(kiwame_nvram_w) AM_BASE(&kiwame_nvram	)	// NVRAM + Regs ?
	AM_RANGE(0x800000, 0x803fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2		)	// Sprites Code + X + Attr
	AM_RANGE(0x900000, 0x900001) AM_WRITE(SMH_RAM						)	// ? 0x4000
	AM_RANGE(0xa00000, 0xa00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16		)	// Sprites Y
	AM_RANGE(0xb00000, 0xb003ff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0xc00000, 0xc03fff) AM_WRITE(seta_sound_word_w				)	// Sound
ADDRESS_MAP_END


/***************************************************************************
                        Thunder & Lightning / Wit's
***************************************************************************/

static READ16_HANDLER( thunderl_protection_r )
{
//  logerror("PC %06X - Protection Read\n", cpu_get_pc(space->cpu));
	return 0x00dd;
}
static WRITE16_HANDLER( thunderl_protection_w )
{
//  logerror("PC %06X - Protection Written: %04X <- %04X\n", cpu_get_pc(space->cpu), offset*2, data);
}

/* Similar to downtown etc. */

static ADDRESS_MAP_START( thunderl_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x00ffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0xffc000, 0xffffff) AM_READ(SMH_RAM				)	// RAM
	AM_RANGE(0x100000, 0x103fff) AM_READ(seta_sound_word_r		)	// Sound
	AM_RANGE(0x600000, 0x600003) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x700000, 0x7003ff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0xb00000, 0xb00001) AM_READ_PORT("P1")					// P1
	AM_RANGE(0xb00002, 0xb00003) AM_READ_PORT("P2")					// P2
	AM_RANGE(0xb00004, 0xb00005) AM_READ_PORT("COINS")				// Coins
	AM_RANGE(0xb0000c, 0xb0000d) AM_READ(thunderl_protection_r	)	// Protection (not in wits)
	AM_RANGE(0xb00008, 0xb00009) AM_READ_PORT("P3")					// P3 (wits)
	AM_RANGE(0xb0000a, 0xb0000b) AM_READ_PORT("P4")					// P4 (wits)
/**/AM_RANGE(0xc00000, 0xc00001) AM_READ(SMH_RAM				)	// ? 0x4000
/**/AM_RANGE(0xd00000, 0xd00607) AM_READ(SMH_RAM				)	// Sprites Y
	AM_RANGE(0xe00000, 0xe03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
	AM_RANGE(0xe04000, 0xe07fff) AM_READ(SMH_RAM				)	// (wits)
ADDRESS_MAP_END

static ADDRESS_MAP_START( thunderl_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x00ffff) AM_WRITE(SMH_ROM					)	// ROM
	AM_RANGE(0xffc000, 0xffffff) AM_WRITE(SMH_RAM					)	// RAM
	AM_RANGE(0x100000, 0x103fff) AM_WRITE(seta_sound_word_w			)	// Sound
	AM_RANGE(0x200000, 0x200001) AM_WRITE(SMH_NOP					)	// ?
	AM_RANGE(0x300000, 0x300001) AM_WRITE(SMH_NOP					)	// ?
	AM_RANGE(0x400000, 0x40ffff) AM_WRITE(thunderl_protection_w		)	// Protection (not in wits)
	AM_RANGE(0x500000, 0x500001) AM_WRITE(seta_vregs_w) AM_BASE(&seta_vregs	)	// Coin Lockout
	AM_RANGE(0x700000, 0x7003ff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0xc00000, 0xc00001) AM_WRITE(SMH_RAM					)	// ? 0x4000
	AM_RANGE(0xd00000, 0xd00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16	)	// Sprites Y
	AM_RANGE(0xe00000, 0xe03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2	)	// Sprites Code + X + Attr
	AM_RANGE(0xe04000, 0xe07fff) AM_WRITE(SMH_RAM					)	// (wits)
ADDRESS_MAP_END

/***************************************************************************
                    Wiggie Waggie
***************************************************************************/

static int wiggie_soundlatch;

static READ8_HANDLER( wiggie_soundlatch_r )
{
	return wiggie_soundlatch;
}

static WRITE16_HANDLER( wiggie_soundlatch_w )
{
	wiggie_soundlatch = data >> 8;
	cpu_set_input_line(space->machine->cpu[1],0, HOLD_LINE);
}


static ADDRESS_MAP_START( wiggie_sound_readmem, ADDRESS_SPACE_PROGRAM, 8 )
	AM_RANGE(0x0000, 0x7fff) AM_READ(SMH_ROM)
	AM_RANGE(0x8000, 0x87ff) AM_READ(SMH_RAM)
	AM_RANGE(0x9800, 0x9800) AM_READ(okim6295_status_0_r)
	AM_RANGE(0xa000, 0xa000) AM_READ(wiggie_soundlatch_r)
ADDRESS_MAP_END

static ADDRESS_MAP_START( wiggie_sound_writemem, ADDRESS_SPACE_PROGRAM, 8 )
	AM_RANGE(0x0000, 0x7fff) AM_WRITE(SMH_ROM)
	AM_RANGE(0x8000, 0x87ff) AM_WRITE(SMH_RAM)
	AM_RANGE(0x9800, 0x9800) AM_WRITE(okim6295_data_0_w)
ADDRESS_MAP_END

/***************************************************************************
                    Ultraman Club / SD Gundam Neo Battling
***************************************************************************/

static ADDRESS_MAP_START( umanclub_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x03ffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0x200000, 0x20ffff) AM_READ(SMH_RAM				)	// RAM
	AM_RANGE(0x300000, 0x3003ff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0x300400, 0x300fff) AM_READ(SMH_RAM				)	//
	AM_RANGE(0x400000, 0x400001) AM_READ_PORT("P1")					// P1
	AM_RANGE(0x400002, 0x400003) AM_READ_PORT("P2")					// P2
	AM_RANGE(0x400004, 0x400005) AM_READ_PORT("COINS")				// Coins
	AM_RANGE(0x600000, 0x600003) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0xa00000, 0xa00607) AM_READ(SMH_RAM				)	// Sprites Y
/**/AM_RANGE(0xa80000, 0xa80001) AM_READ(SMH_RAM				)	// ? 0x4000
	AM_RANGE(0xb00000, 0xb03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
	AM_RANGE(0xc00000, 0xc03fff) AM_READ(seta_sound_word_r		)	// Sound
ADDRESS_MAP_END

static ADDRESS_MAP_START( umanclub_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x03ffff) AM_WRITE(SMH_ROM					)	// ROM
	AM_RANGE(0x200000, 0x20ffff) AM_WRITE(SMH_RAM					)	// RAM
	AM_RANGE(0x300000, 0x3003ff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0x300400, 0x300fff) AM_WRITE(SMH_RAM					)	//
	AM_RANGE(0x400000, 0x400001) AM_WRITE(SMH_NOP					)	// ? (end of lev 2)
	AM_RANGE(0x400004, 0x400005) AM_WRITE(SMH_NOP					)	// ? (end of lev 2)
	AM_RANGE(0x500000, 0x500001) AM_WRITE(seta_vregs_w) AM_BASE(&seta_vregs	)	// Coin Lockout + Video Registers
	AM_RANGE(0xa00000, 0xa00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16	)	// Sprites Y
	AM_RANGE(0xa80000, 0xa80001) AM_WRITE(SMH_RAM					)	// ? 0x4000
	AM_RANGE(0xb00000, 0xb03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2	)	// Sprites Code + X + Attr
	AM_RANGE(0xc00000, 0xc03fff) AM_WRITE(seta_sound_word_w			)	// Sound
ADDRESS_MAP_END

/***************************************************************************
                            Ultra Toukond Densetsu
***************************************************************************/

static WRITE16_HANDLER( utoukond_soundlatch_w )
{
	if (ACCESSING_BITS_0_7)
	{
		cpu_set_input_line(space->machine->cpu[1],0,HOLD_LINE);
		soundlatch_w(space,0,data & 0xff);
	}
}

static ADDRESS_MAP_START( utoukond_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x0fffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0x200000, 0x20ffff) AM_READ(SMH_RAM				)	// ROM
	AM_RANGE(0x400000, 0x400001) AM_READ_PORT("P1")					// P1
	AM_RANGE(0x400002, 0x400003) AM_READ_PORT("P2")					// P2
	AM_RANGE(0x400004, 0x400005) AM_READ_PORT("COINS")				// Coins
	AM_RANGE(0x600000, 0x600003) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x700400, 0x700fff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0x800000, 0x801fff) AM_READ(SMH_RAM				)	// VRAM 0
	AM_RANGE(0x802000, 0x803fff) AM_READ(SMH_RAM				)	// VRAM 1
	AM_RANGE(0x880000, 0x881fff) AM_READ(SMH_RAM				)	// VRAM 2
	AM_RANGE(0x882000, 0x883fff) AM_READ(SMH_RAM				)	// VRAM 3
	AM_RANGE(0xa00000, 0xa00607) AM_READ(SMH_RAM			 	)	// Sprites Y
	AM_RANGE(0xb00000, 0xb03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
ADDRESS_MAP_END

static ADDRESS_MAP_START( utoukond_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x0fffff) AM_WRITE(SMH_ROM						)	// ROM
	AM_RANGE(0x200000, 0x20ffff) AM_WRITE(SMH_RAM						)	// ROM
	AM_RANGE(0x500000, 0x500005) AM_WRITE(seta_vregs_w) AM_BASE(&seta_vregs		)	// ? Coin Lockout + Video Registers
	AM_RANGE(0x700400, 0x700fff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0x800000, 0x803fff) AM_WRITE(seta_vram_0_w) AM_BASE(&seta_vram_0	)	// VRAM 0
	AM_RANGE(0x880000, 0x883fff) AM_WRITE(seta_vram_2_w) AM_BASE(&seta_vram_2	)	// VRAM 2
	AM_RANGE(0x900000, 0x900005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_0		)	// VRAM 0&1 Ctrl
	AM_RANGE(0x980000, 0x980005) AM_WRITE(SMH_RAM) AM_BASE(&seta_vctrl_2		)	// VRAM 2&3 Ctrl
	AM_RANGE(0xa00000, 0xa00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16		)	// Sprites Y
	AM_RANGE(0xb00000, 0xb03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2	)	// Sprites Code + X + Attr
	AM_RANGE(0xc00000, 0xc00001) AM_WRITE(utoukond_soundlatch_w			)	// To Sound CPU (cause an IRQ)
	AM_RANGE(0xe00000, 0xe00001) AM_WRITE(SMH_NOP						)	// ? ack
ADDRESS_MAP_END

/***************************************************************************


                                Sub / Sound CPU


***************************************************************************/

static WRITE8_HANDLER( sub_bankswitch_w )
{
	UINT8 *rom = memory_region(space->machine, "sub");
	int bank = data >> 4;

	memory_set_bankptr(space->machine, 1, &rom[bank * 0x4000 + 0xc000]);
}

static WRITE8_HANDLER( sub_bankswitch_lockout_w )
{
	sub_bankswitch_w(space,offset,data);
	seta_coin_lockout_w(space->machine, data);
}


/***************************************************************************
                                Thundercade
***************************************************************************/

static READ8_HANDLER( ff_r )	{return 0xff;}

static ADDRESS_MAP_START( tndrcade_sub_readmem, ADDRESS_SPACE_PROGRAM, 8 )
	AM_RANGE(0x0000, 0x01ff) AM_READ(SMH_RAM				)	// RAM
	AM_RANGE(0x0800, 0x0800) AM_READ(ff_r					)	// ? (bits 0/1/2/3: 1 -> do test 0-ff/100-1e0/5001-57ff/banked rom)
//  AM_RANGE(0x0800, 0x0800) AM_READ(soundlatch_r           )   //
//  AM_RANGE(0x0801, 0x0801) AM_READ(soundlatch2_r          )   //
	AM_RANGE(0x1000, 0x1000) AM_READ_PORT("P1")					// P1
	AM_RANGE(0x1001, 0x1001) AM_READ_PORT("P2")					// P2
	AM_RANGE(0x1002, 0x1002) AM_READ_PORT("COINS")				// Coins
	AM_RANGE(0x2001, 0x2001) AM_READ(ym2203_read_port_0_r	)
	AM_RANGE(0x5000, 0x57ff) AM_READ(SMH_RAM				)	// Shared RAM
	AM_RANGE(0x6000, 0x7fff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0x8000, 0xbfff) AM_READ(SMH_BANK1				)	// Banked ROM
	AM_RANGE(0xc000, 0xffff) AM_READ(SMH_ROM				)	// ROM
ADDRESS_MAP_END

static ADDRESS_MAP_START( tndrcade_sub_writemem, ADDRESS_SPACE_PROGRAM, 8 )
	AM_RANGE(0x0000, 0x01ff) AM_WRITE(SMH_RAM					)	// RAM
	AM_RANGE(0x1000, 0x1000) AM_WRITE(sub_bankswitch_lockout_w	)	// ROM Bank + Coin Lockout
	AM_RANGE(0x2000, 0x2000) AM_WRITE(ym2203_control_port_0_w	)
	AM_RANGE(0x2001, 0x2001) AM_WRITE(ym2203_write_port_0_w		)
	AM_RANGE(0x3000, 0x3000) AM_WRITE(ym3812_control_port_0_w	)
	AM_RANGE(0x3001, 0x3001) AM_WRITE(ym3812_write_port_0_w		)
	AM_RANGE(0x5000, 0x57ff) AM_WRITE(SMH_RAM) AM_BASE(&sharedram		)	// Shared RAM
	AM_RANGE(0x6000, 0xffff) AM_WRITE(SMH_ROM					)	// ROM
ADDRESS_MAP_END

/***************************************************************************
                                Twin Eagle
***************************************************************************/

static ADDRESS_MAP_START( twineagl_sub_readmem, ADDRESS_SPACE_PROGRAM, 8 )
	AM_RANGE(0x0000, 0x01ff) AM_READ(SMH_RAM			)	// RAM
	AM_RANGE(0x0800, 0x0800) AM_READ(soundlatch_r		)	//
	AM_RANGE(0x0801, 0x0801) AM_READ(soundlatch2_r		)	//
	AM_RANGE(0x1000, 0x1000) AM_READ_PORT("P1")				// P1
	AM_RANGE(0x1001, 0x1001) AM_READ_PORT("P2")				// P2
	AM_RANGE(0x1002, 0x1002) AM_READ_PORT("COINS")			// Coins
	AM_RANGE(0x5000, 0x57ff) AM_READ(SMH_RAM			)	// Shared RAM
	AM_RANGE(0x7000, 0x7fff) AM_READ(SMH_ROM			)	// ROM
	AM_RANGE(0x8000, 0xbfff) AM_READ(SMH_BANK1			)	// Banked ROM
	AM_RANGE(0xc000, 0xffff) AM_READ(SMH_ROM			)	// ROM
ADDRESS_MAP_END

static ADDRESS_MAP_START( twineagl_sub_writemem, ADDRESS_SPACE_PROGRAM, 8 )
	AM_RANGE(0x0000, 0x01ff) AM_WRITE(SMH_RAM				)	// RAM
	AM_RANGE(0x1000, 0x1000) AM_WRITE(sub_bankswitch_lockout_w	)	// ROM Bank + Coin Lockout
	AM_RANGE(0x5000, 0x57ff) AM_WRITE(SMH_RAM) AM_BASE(&sharedram	)	// Shared RAM
	AM_RANGE(0x7000, 0x7fff) AM_WRITE(SMH_ROM				)	// ROM
	AM_RANGE(0x8000, 0xbfff) AM_WRITE(SMH_ROM				)	// ROM
	AM_RANGE(0xc000, 0xffff) AM_WRITE(SMH_ROM				)	// ROM
ADDRESS_MAP_END

/***************************************************************************
                                DownTown
***************************************************************************/

static READ8_HANDLER( downtown_ip_r )
{
	int dir1 = input_port_read(space->machine, "ROT1");	// analog port
	int dir2 = input_port_read(space->machine, "ROT2");	// analog port

	dir1 = (~ (0x800 >> ((dir1 * 12)/0x100)) ) & 0xfff;
	dir2 = (~ (0x800 >> ((dir2 * 12)/0x100)) ) & 0xfff;

	switch (offset)
	{
		case 0:	return (input_port_read(space->machine, "COINS") & 0xf0) + (dir1 >> 8);	// upper 4 bits of p1 rotation + coins
		case 1:	return (dir1 & 0xff);					// lower 8 bits of p1 rotation
		case 2:	return input_port_read(space->machine, "P1");	// p1
		case 3:	return 0xff;							// ?
		case 4:	return (dir2 >> 8);						// upper 4 bits of p2 rotation + ?
		case 5:	return (dir2 & 0xff);					// lower 8 bits of p2 rotation
		case 6:	return input_port_read(space->machine, "P2");	// p2
		case 7:	return 0xff;							// ?
	}

	return 0;
}

static ADDRESS_MAP_START( downtown_sub_readmem, ADDRESS_SPACE_PROGRAM, 8 )
	AM_RANGE(0x0000, 0x01ff) AM_READ(SMH_RAM			)	// RAM
	AM_RANGE(0x0800, 0x0800) AM_READ(soundlatch_r		)	//
	AM_RANGE(0x0801, 0x0801) AM_READ(soundlatch2_r		)	//
	AM_RANGE(0x1000, 0x1007) AM_READ(downtown_ip_r		)	// Input Ports
	AM_RANGE(0x5000, 0x57ff) AM_READ(SMH_RAM			)	// Shared RAM
	AM_RANGE(0x7000, 0x7fff) AM_READ(SMH_ROM			)	// ROM
	AM_RANGE(0x8000, 0xbfff) AM_READ(SMH_BANK1			)	// Banked ROM
	AM_RANGE(0xc000, 0xffff) AM_READ(SMH_ROM			)	// ROM
ADDRESS_MAP_END

static ADDRESS_MAP_START( downtown_sub_writemem, ADDRESS_SPACE_PROGRAM, 8 )
	AM_RANGE(0x0000, 0x01ff) AM_WRITE(SMH_RAM				)	// RAM
	AM_RANGE(0x1000, 0x1000) AM_WRITE(sub_bankswitch_lockout_w		)	// ROM Bank + Coin Lockout
	AM_RANGE(0x5000, 0x57ff) AM_WRITE(SMH_RAM) AM_BASE(&sharedram	)	// Shared RAM
	AM_RANGE(0x7000, 0xffff) AM_WRITE(SMH_ROM				)	// ROM
ADDRESS_MAP_END

/***************************************************************************
                        Caliber 50 / U.S. Classic
***************************************************************************/

static MACHINE_RESET(calibr50)
{
	const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM);
	sub_bankswitch_w(space, 0, 0);
}

static WRITE8_HANDLER( calibr50_soundlatch2_w )
{
	soundlatch2_w(space,0,data);
	cpu_spinuntil_time(space->cpu, ATTOTIME_IN_USEC(50));	// Allow the other cpu to reply
}

static ADDRESS_MAP_START( calibr50_sub_readmem, ADDRESS_SPACE_PROGRAM, 8 )
	AM_RANGE(0x0000, 0x1fff) AM_READ(seta_sound_r		)	// Sound
	AM_RANGE(0x4000, 0x4000) AM_READ(soundlatch_r		)	// From Main CPU
	AM_RANGE(0x8000, 0xbfff) AM_READ(SMH_BANK1			)	// Banked ROM
	AM_RANGE(0xc000, 0xffff) AM_READ(SMH_ROM			)	// ROM
ADDRESS_MAP_END

static ADDRESS_MAP_START( calibr50_sub_writemem, ADDRESS_SPACE_PROGRAM, 8 )
	AM_RANGE(0x0000, 0x1fff) AM_WRITE(seta_sound_w				)	// Sound
	AM_RANGE(0x4000, 0x4000) AM_WRITE(sub_bankswitch_w			)	// Bankswitching
	AM_RANGE(0x8000, 0xbfff) AM_WRITE(SMH_ROM					)	// Banked ROM
	AM_RANGE(0xc000, 0xc000) AM_WRITE(calibr50_soundlatch2_w	)	// To Main CPU
	AM_RANGE(0xc000, 0xffff) AM_WRITE(SMH_ROM					)	// ROM
ADDRESS_MAP_END

/***************************************************************************
                                Meta Fox
***************************************************************************/

static ADDRESS_MAP_START( metafox_sub_readmem, ADDRESS_SPACE_PROGRAM, 8 )
	AM_RANGE(0x0000, 0x01ff) AM_READ(SMH_RAM			)	// RAM
	AM_RANGE(0x0800, 0x0800) AM_READ(soundlatch_r		)	//
	AM_RANGE(0x0801, 0x0801) AM_READ(soundlatch2_r		)	//
	AM_RANGE(0x1000, 0x1000) AM_READ_PORT("COINS")			// Coins
	AM_RANGE(0x1002, 0x1002) AM_READ_PORT("P1")				// P1
//  AM_RANGE(0x1004, 0x1004) AM_READ(SMH_NOP            )   // ?
	AM_RANGE(0x1006, 0x1006) AM_READ_PORT("P2")				// P2
	AM_RANGE(0x5000, 0x57ff) AM_READ(SMH_RAM			)	// Shared RAM
	AM_RANGE(0x7000, 0x7fff) AM_READ(SMH_ROM			)	// ROM
	AM_RANGE(0x8000, 0xbfff) AM_READ(SMH_BANK1			)	// Banked ROM
	AM_RANGE(0xc000, 0xffff) AM_READ(SMH_ROM			)	// ROM
ADDRESS_MAP_END

static ADDRESS_MAP_START( metafox_sub_writemem, ADDRESS_SPACE_PROGRAM, 8 )
	AM_RANGE(0x0000, 0x01ff) AM_WRITE(SMH_RAM				)	// RAM
	AM_RANGE(0x1000, 0x1000) AM_WRITE(sub_bankswitch_lockout_w		)	// ROM Bank + Coin Lockout
	AM_RANGE(0x5000, 0x57ff) AM_WRITE(SMH_RAM) AM_BASE(&sharedram	)	// Shared RAM
	AM_RANGE(0x7000, 0x7fff) AM_WRITE(SMH_ROM				)	// ROM
	AM_RANGE(0x8000, 0xbfff) AM_WRITE(SMH_ROM				)	// ROM
	AM_RANGE(0xc000, 0xffff) AM_WRITE(SMH_ROM				)	// ROM
ADDRESS_MAP_END


/***************************************************************************
                            Ultra Toukon Densetsu
***************************************************************************/

static ADDRESS_MAP_START( utoukond_sound_readmem, ADDRESS_SPACE_PROGRAM, 8 )
	AM_RANGE(0x0000, 0xdfff) AM_READ(SMH_ROM)
	AM_RANGE(0xe000, 0xefff) AM_READ(SMH_RAM)
	AM_RANGE(0xf000, 0xffff) AM_READ(seta_sound_r)
ADDRESS_MAP_END
static ADDRESS_MAP_START( utoukond_sound_writemem, ADDRESS_SPACE_PROGRAM, 8 )
	AM_RANGE(0x0000, 0xdfff) AM_WRITE(SMH_ROM)
	AM_RANGE(0xe000, 0xefff) AM_WRITE(SMH_RAM)
	AM_RANGE(0xf000, 0xffff) AM_WRITE(seta_sound_w)
ADDRESS_MAP_END

static ADDRESS_MAP_START( utoukond_sound_io_map, ADDRESS_SPACE_IO, 8 )
	ADDRESS_MAP_GLOBAL_MASK(0xff)
	AM_RANGE(0x00, 0x00) AM_READWRITE(ym3438_status_port_0_a_r, ym3438_control_port_0_a_w)
	AM_RANGE(0x01, 0x01) AM_WRITE(ym3438_data_port_0_a_w)
	AM_RANGE(0x02, 0x02) AM_WRITE(ym3438_control_port_0_b_w)
	AM_RANGE(0x03, 0x03) AM_WRITE(ym3438_data_port_0_b_w)
	AM_RANGE(0x80, 0x80) AM_WRITE(SMH_NOP) //?
	AM_RANGE(0xc0, 0xc0) AM_READ(soundlatch_r)
ADDRESS_MAP_END

static UINT16 pairslove_protram[0x200];
static UINT16 pairslove_protram_old[0x200];

static READ16_HANDLER( pairlove_prot_r )
{
	int retdata;
	retdata = pairslove_protram[offset];
	//mame_printf_debug("pairs love protection? read %06x %04x %04x\n",cpu_get_pc(space->cpu), offset,retdata);
	pairslove_protram[offset]=pairslove_protram_old[offset];
	return retdata;
}

static WRITE16_HANDLER( pairlove_prot_w )
{
//  mame_printf_debug("pairs love protection? write %06x %04x %04x\n",cpu_get_pc(space->cpu), offset,data);
	pairslove_protram_old[offset]=pairslove_protram[offset];
	pairslove_protram[offset]=data;
}

/***************************************************************************
                                Pairs Love
***************************************************************************/

static ADDRESS_MAP_START( pairlove_readmem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x03ffff) AM_READ(SMH_ROM				)	// ROM
	AM_RANGE(0x300000, 0x300003) AM_READ(seta_dsw_r				)	// DSW
	AM_RANGE(0x500000, 0x500001) AM_READ_PORT("P1")					// P1
	AM_RANGE(0x500002, 0x500003) AM_READ_PORT("P2")					// P2
	AM_RANGE(0x500004, 0x500005) AM_READ_PORT("COINS")				// Coins
	AM_RANGE(0x900000, 0x9001ff) AM_READ(pairlove_prot_r)
	AM_RANGE(0xa00000, 0xa03fff) AM_READ(seta_sound_word_r		)	// Sound
	AM_RANGE(0xb00000, 0xb00fff) AM_READ(SMH_RAM				)	// Palette
	AM_RANGE(0xc00000, 0xc03fff) AM_READ(SMH_RAM				)	// Sprites Code + X + Attr
	AM_RANGE(0xd00000, 0xd00001) AM_READ(SMH_RAM				)	// ? 0x4000
	AM_RANGE(0xe00000, 0xe00607) AM_READ(SMH_RAM				)	// Sprites Y
	AM_RANGE(0xf00000, 0xf0ffff) AM_READ(SMH_RAM				)	// RAM
ADDRESS_MAP_END

static ADDRESS_MAP_START( pairlove_writemem, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x03ffff) AM_WRITE(SMH_ROM					)	// ROM
	AM_RANGE(0x100000, 0x100001) AM_WRITE(SMH_NOP					)	// ? 1 (start of interrupts, main loop: watchdog?)
	AM_RANGE(0x200000, 0x200001) AM_WRITE(SMH_NOP					)	// ? 0/1 (IRQ acknowledge?)
	AM_RANGE(0x400000, 0x400001) AM_WRITE(seta_vregs_w) AM_BASE(&seta_vregs	)	// Coin Lockout + Sound Enable (bit 4?)
	AM_RANGE(0x900000, 0x9001ff) AM_WRITE(pairlove_prot_w)
	AM_RANGE(0xa00000, 0xa03fff) AM_WRITE(seta_sound_word_w			)	// Sound
	AM_RANGE(0xb00000, 0xb00fff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0xc00000, 0xc03fff) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16_2	)	// Sprites Code + X + Attr
	AM_RANGE(0xd00000, 0xd00001) AM_WRITE(SMH_RAM					)	// ? 0x4000
	AM_RANGE(0xe00000, 0xe00607) AM_WRITE(SMH_RAM) AM_BASE(&spriteram16	)	// Sprites Y
	AM_RANGE(0xf00000, 0xf0ffff) AM_WRITE(SMH_RAM					)	// RAM
ADDRESS_MAP_END


/***************************************************************************
                            Crazy Fight
***************************************************************************/

static WRITE16_HANDLER( YM3812_control_port_0_lsb_w )	{	if (ACCESSING_BITS_0_7)	ym3812_control_port_0_w(space, 0, data & 0xff);	}
static WRITE16_HANDLER( YM3812_write_port_0_lsb_w )		{	if (ACCESSING_BITS_0_7)	ym3812_write_port_0_w(space, 0, data & 0xff);		}

static ADDRESS_MAP_START( crazyfgt_map, ADDRESS_SPACE_PROGRAM, 16 )
	AM_RANGE(0x000000, 0x07ffff) AM_ROM
	AM_RANGE(0x400000, 0x40ffff) AM_RAM
	AM_RANGE(0x610000, 0x610001) AM_READ_PORT("COINS")
	AM_RANGE(0x610002, 0x610003) AM_READ_PORT("UNK")
	AM_RANGE(0x610004, 0x610005) AM_READ_PORT("INPUT")
	AM_RANGE(0x610006, 0x610007) AM_WRITENOP
	AM_RANGE(0x620000, 0x620003) AM_WRITENOP	// protection
	AM_RANGE(0x630000, 0x630003) AM_READ(seta_dsw_r)
	AM_RANGE(0x640400, 0x640fff) AM_WRITE(SMH_RAM) AM_BASE(&paletteram16	) AM_SIZE(&seta_paletteram_size)	// Palette
	AM_RANGE(0x650000, 0x650001) AM_WRITE(YM3812_control_port_0_lsb_w)
	AM_RANGE(0x650002, 0x650003) AM_WRITE(YM3812_write_port_0_lsb_w)
	AM_RANGE(0x658000, 0x658001) AM_WRITE(okim6295_data_0_lsb_w)
	AM_RANGE(0x670000, 0x670001) AM_READNOP		// watchdog?
	AM_RANGE(0x800000, 0x803fff) AM_WRITE(seta_vram_2_w) AM_BASE(&seta_vram_2) // VRAM 2
	AM_RANGE(0x880000, 0x883fff) AM_WRITE(seta_vram_0_w) AM_BASE(&seta_vram_0) // VRAM 0
	AM_RANGE(0x900000, 0x900005) AM_RAM AM_BASE(&seta_vctrl_2)	// VRAM 2&3 Ctrl
	AM_RANGE(0x980000, 0x980005) AM_RAM AM_BASE(&seta_vctrl_0)	// VRAM 0&1 Ctrl
	AM_RANGE(0xa00000, 0xa00607) AM_RA